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

Commit ed12a04a authored by Colin Cross's avatar Colin Cross
Browse files

Enable sanitizers for musl

Now that we provide runtimes built for musl, enable the sanitizers
when targeting musl.

Bug: 215802826
Test: m USE_HOST_MUSL=true host-native
Change-Id: Id17513ee305274874c31e9c99ce4faeff4a1c057
parent 441898c2
Loading
Loading
Loading
Loading
+13 −7
Original line number Original line Diff line number Diff line
@@ -480,8 +480,8 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) {
		s.Diag.Cfi = nil
		s.Diag.Cfi = nil
	}
	}


	// Disable sanitizers that depend on the UBSan runtime for windows/darwin/musl builds.
	// Disable sanitizers that depend on the UBSan runtime for windows/darwin builds.
	if !ctx.Os().Linux() || ctx.Os() == android.LinuxMusl {
	if !ctx.Os().Linux() {
		s.Cfi = nil
		s.Cfi = nil
		s.Diag.Cfi = nil
		s.Diag.Cfi = nil
		s.Misc_undefined = nil
		s.Misc_undefined = nil
@@ -490,6 +490,12 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) {
		s.Integer_overflow = nil
		s.Integer_overflow = nil
	}
	}


	// Disable CFI for musl
	if ctx.toolchain().Musl() {
		s.Cfi = nil
		s.Diag.Cfi = nil
	}

	// Also disable CFI for VNDK variants of components
	// Also disable CFI for VNDK variants of components
	if ctx.isVndk() && ctx.useVndk() {
	if ctx.isVndk() && ctx.useVndk() {
		if ctx.static() {
		if ctx.static() {
@@ -702,10 +708,10 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags {
		flags.Local.AsFlags = append(flags.Local.AsFlags, sanitizeArg)
		flags.Local.AsFlags = append(flags.Local.AsFlags, sanitizeArg)
		flags.Local.LdFlags = append(flags.Local.LdFlags, sanitizeArg)
		flags.Local.LdFlags = append(flags.Local.LdFlags, sanitizeArg)


		if ctx.toolchain().Bionic() {
		if ctx.toolchain().Bionic() || ctx.toolchain().Musl() {
			// Bionic sanitizer runtimes have already been added as dependencies so that
			// Bionic and musl sanitizer runtimes have already been added as dependencies so that
			// the right variant of the runtime will be used (with the "-android"
			// the right variant of the runtime will be used (with the "-android" or "-musl"
			// suffix), so don't let clang the runtime library.
			// suffixes), so don't let clang the runtime library.
			flags.Local.LdFlags = append(flags.Local.LdFlags, "-fno-sanitize-link-runtime")
			flags.Local.LdFlags = append(flags.Local.LdFlags, "-fno-sanitize-link-runtime")
		} else {
		} else {
			// Host sanitizers only link symbols in the final executable, so
			// Host sanitizers only link symbols in the final executable, so
@@ -1217,7 +1223,7 @@ func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) {
			addStaticDeps(config.BuiltinsRuntimeLibrary(toolchain))
			addStaticDeps(config.BuiltinsRuntimeLibrary(toolchain))
		}
		}


		if runtimeLibrary != "" && (toolchain.Bionic() || c.sanitize.Properties.UbsanRuntimeDep) {
		if runtimeLibrary != "" && (toolchain.Bionic() || toolchain.Musl() || c.sanitize.Properties.UbsanRuntimeDep) {
			// UBSan is supported on non-bionic linux host builds as well
			// UBSan is supported on non-bionic linux host builds as well


			// Adding dependency to the runtime library. We are using *FarVariation*
			// Adding dependency to the runtime library. We are using *FarVariation*