Use static asan runtime for musl

Use static asan runtimes for musl binaries to match glibc binaries.
The static asan runtime also requires libclang_rt.asan_cxx.a.  Unlike
most other runtimes the asan runtimes need to expose the symbols
from the runtime to allow intercepting calls to malloc, new etc.

Test: m USE_HOST_MUSL=true aidl_unittests && out/host/linux-x86/testcases/aidl_unittests/x86_64/aidl_unittests
Test: sanitize_test.go
Change-Id: I93da03b1c447fbb01f37262e7a465f165c2d5a18
This commit is contained in:
Colin Cross
2023-02-15 12:40:20 -08:00
parent e323a793e2
commit b781d23575
3 changed files with 45 additions and 2 deletions

View File

@@ -1539,7 +1539,13 @@ func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) {
runtimeSharedLibrary := ""
toolchain := c.toolchain(mctx)
if Bool(sanProps.Address) {
runtimeSharedLibrary = config.AddressSanitizerRuntimeLibrary(toolchain)
if toolchain.Musl() || (c.staticBinary() && toolchain.Bionic()) {
// Use a static runtime for musl to match what clang does for glibc.
addStaticDeps(config.AddressSanitizerStaticRuntimeLibrary(toolchain), false)
addStaticDeps(config.AddressSanitizerCXXStaticRuntimeLibrary(toolchain), false)
} else {
runtimeSharedLibrary = config.AddressSanitizerRuntimeLibrary(toolchain)
}
} else if Bool(sanProps.Hwaddress) {
if c.staticBinary() {
addStaticDeps(config.HWAddressSanitizerStaticLibrary(toolchain), true)