From acf8b0ff009def3466cad8d4244a04bab15e8bcd Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Mon, 21 Oct 2019 20:47:53 -0700 Subject: [PATCH] Stop linking libdl.a into static bins libdl.a has a no-op dlopen, which breaks static libraries that need a real dlopen. Instead of automatically linking libdl.a into static executables, make it optional. Until recently, the libunwind_llvm.a unwinder, used on arm32, needed the no-op dladdr, but it's now built using -D_LIBUNWIND_USE_DLADDR=0. The HWASan run-time uses dlsym and dladdr, so add a libdl dependency for HWASan-built static binaries. We could also remove the dependency from libclang_rt.hwasan_static-*.a, but this is also easy to do. Bug: http://b/141485154 Test: bionic unit tests, device boots, verify that static and dynamic executables can throw/catch an exception Test: verify that a static executable using dlopen doesn't link (unless it adds an explicit dependency on libdl) Change-Id: Id26741f79dca50256a2dc23453af3026a6c88dca --- core/config_sanitizers.mk | 4 +++- core/cxx_stl_setup.mk | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/config_sanitizers.mk b/core/config_sanitizers.mk index 2439f7962..efb21e7c6 100644 --- a/core/config_sanitizers.mk +++ b/core/config_sanitizers.mk @@ -182,7 +182,9 @@ ifneq ($(filter hwaddress,$(my_sanitize)),) my_shared_libraries += $($(LOCAL_2ND_ARCH_VAR_PREFIX)HWADDRESS_SANITIZER_RUNTIME_LIBRARY) ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),) ifeq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true) - my_static_libraries := $(my_static_libraries) $($(LOCAL_2ND_ARCH_VAR_PREFIX)HWADDRESS_SANITIZER_STATIC_LIBRARY) + my_static_libraries := $(my_static_libraries) \ + $($(LOCAL_2ND_ARCH_VAR_PREFIX)HWADDRESS_SANITIZER_STATIC_LIBRARY) \ + libdl endif endif endif diff --git a/core/cxx_stl_setup.mk b/core/cxx_stl_setup.mk index 95b109081..6571d99be 100644 --- a/core/cxx_stl_setup.mk +++ b/core/cxx_stl_setup.mk @@ -82,7 +82,7 @@ ifneq ($(filter $(my_cxx_stl),libc++ libc++_static),) endif ifeq ($(my_link_type),static) - my_static_libraries += libm libc libdl + my_static_libraries += libm libc endif endif else ifeq ($(my_cxx_stl),ndk)