Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 234b01de authored by Colin Cross's avatar Colin Cross
Browse files

Use -fno-sanitize-link-runtime for bionic sanitizers

Currently when using sanitizers and building for the device
the -fsanitize= argument is not passed to the linker so that the
linker won't add the runtimes, which have already been added
as explicit dependencies.  Pass -fno-sanitize-link-runtime instead
in case the linker has other behaviors when passed -fsanitize=
besides adding the runtimes.  Also check for bionic instead of host
so that linux bionic gets the same linker behavior as bionic for
the device.

Test: m USE_HOST_MUSL=true host-native
Test: m checkbuild
Change-Id: I0f2966e2fd4ae8adc5cb21eb116c349bcc0c668f
parent 472be14f
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -705,20 +705,23 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags {

	if len(sanitize.Properties.Sanitizers) > 0 {
		sanitizeArg := "-fsanitize=" + strings.Join(sanitize.Properties.Sanitizers, ",")

		flags.Local.CFlags = append(flags.Local.CFlags, sanitizeArg)
		flags.Local.AsFlags = append(flags.Local.AsFlags, sanitizeArg)
		if ctx.Host() {
		flags.Local.LdFlags = append(flags.Local.LdFlags, sanitizeArg)

		if ctx.toolchain().Bionic() {
			// Bionic sanitizer runtimes have already been added as dependencies so that
			// the right variant of the runtime will be used (with the "-android"
			// suffix), so don't let clang the runtime library.
			flags.Local.LdFlags = append(flags.Local.LdFlags, "-fno-sanitize-link-runtime")
		} else {
			// Host sanitizers only link symbols in the final executable, so
			// there will always be undefined symbols in intermediate libraries.
			_, flags.Global.LdFlags = removeFromList("-Wl,--no-undefined", flags.Global.LdFlags)
			flags.Local.LdFlags = append(flags.Local.LdFlags, sanitizeArg)

			// non-Bionic toolchain prebuilts are missing UBSan's vptr and function sanitizers
			if !ctx.toolchain().Bionic() {
			// non-Bionic toolchain prebuilts are missing UBSan's vptr and function san
			flags.Local.CFlags = append(flags.Local.CFlags, "-fno-sanitize=vptr,function")
		}
		}

		if enableMinimalRuntime(sanitize) {
			flags.Local.CFlags = append(flags.Local.CFlags, strings.Join(minimalRuntimeFlags, " "))