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
diff --git a/cc/sanitize.go b/cc/sanitize.go
index 72c09fb..d8635e0 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -1539,7 +1539,13 @@
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)