From 441898c285c4fb198eb088dbe284fa41087f6cc0 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 11 Feb 2022 13:44:48 -0800 Subject: [PATCH 1/2] Switch to libunwind to remove dependency on libgcc for musl The libgcc dependency is only used for _Unwind* symbols, remove it now that libc_musl.so embeds libunwind.a. Bug: 215802826 Test: m USE_HOST_MUSL=true host-native Change-Id: I1ad4c1435fc0090c6df2d50d542d2203dfb94d7b --- cc/config/x86_linux_host.go | 1 - rust/config/x86_linux_host.go | 2 -- 2 files changed, 3 deletions(-) diff --git a/cc/config/x86_linux_host.go b/cc/config/x86_linux_host.go index ce6836ba5..e1659d380 100644 --- a/cc/config/x86_linux_host.go +++ b/cc/config/x86_linux_host.go @@ -65,7 +65,6 @@ var ( linuxMuslLdflags = []string{ "-nostdlib", - "-lgcc", "-lgcc_eh", "--sysroot /dev/null", } diff --git a/rust/config/x86_linux_host.go b/rust/config/x86_linux_host.go index 760834929..4d7c42219 100644 --- a/rust/config/x86_linux_host.go +++ b/rust/config/x86_linux_host.go @@ -42,8 +42,6 @@ var ( "-nodefaultlibs", "-nostdlib", "-Wl,--no-dynamic-linker", - // for unwind - "-lgcc", "-lgcc_eh", } linuxX86Rustflags = []string{} linuxX86Linkflags = []string{} From ed12a04a3eaa59514a5dc43eedc48c39d0ddc1b3 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Mon, 7 Feb 2022 13:55:55 -0800 Subject: [PATCH 2/2] 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 --- cc/sanitize.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/cc/sanitize.go b/cc/sanitize.go index 3cf8b5832..814fef6a9 100644 --- a/cc/sanitize.go +++ b/cc/sanitize.go @@ -480,8 +480,8 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) { s.Diag.Cfi = nil } - // Disable sanitizers that depend on the UBSan runtime for windows/darwin/musl builds. - if !ctx.Os().Linux() || ctx.Os() == android.LinuxMusl { + // Disable sanitizers that depend on the UBSan runtime for windows/darwin builds. + if !ctx.Os().Linux() { s.Cfi = nil s.Diag.Cfi = nil s.Misc_undefined = nil @@ -490,6 +490,12 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) { 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 if ctx.isVndk() && ctx.useVndk() { 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.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. + if ctx.toolchain().Bionic() || ctx.toolchain().Musl() { + // 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" or "-musl" + // suffixes), 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 @@ -1217,7 +1223,7 @@ func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) { 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 // Adding dependency to the runtime library. We are using *FarVariation*