From eebb8001702fe5c1ce7bb36f024943985df54d75 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Tue, 28 Apr 2015 13:23:36 -0700 Subject: Make asan more closely match clang behavior. Always link libm with asan. Hasn't been a problem before because ASAN was only ever used when libc++ was as well, which already links libm. Pass --no-as-needed for host modules. These aren't needed for the target builds because the target uses the shared RTL. Change-Id: I3b95c8682c0f63bac6b726f8cd15c638aaa98311 --- core/config_sanitizers.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/config_sanitizers.mk b/core/config_sanitizers.mk index 210d442..6e3c0b8 100644 --- a/core/config_sanitizers.mk +++ b/core/config_sanitizers.mk @@ -78,7 +78,8 @@ ifneq ($(filter address,$(my_sanitize)),) ifdef LOCAL_IS_HOST_MODULE # -nodefaultlibs (provided with libc++) prevents the driver from linking # libraries needed with -fsanitize=address. http://b/18650275 (WAI) - my_ldlibs += -ldl -lpthread + my_ldlibs += -lm -ldl -lpthread + my_ldflags += --no-as-needed else my_shared_libraries += $(ADDRESS_SANITIZER_CONFIG_EXTRA_SHARED_LIBRARIES) my_static_libraries += $(ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES) -- cgit v1.1 From 6708b6c99cbc61c7fd2bdb51b7f1ddc5b53943ec Mon Sep 17 00:00:00 2001 From: Evgenii Stepanov Date: Fri, 24 Apr 2015 16:34:47 -0700 Subject: Fix AddressSanitizer link order and multilib setup. ASan runtime library (when using dynamic linking) must be the first dependency of the main executable to achieve correct symbol interposition. This matches how the clang driver works. In multilib setup, ASan-RT name depends on the target arch: /system/lib/libclang_rt.asan-arm-android.so /system/lib64/libclang_rt.asan-arm64-android.so We also set RPATH to /system/lib/asan or /system/lib64/asan to have a place for ASan-only versions of system libraries. Change-Id: I937d202077b6e433ba476c075d31be818b662d53 --- core/clang/TARGET_arm.mk | 4 ++++ core/clang/TARGET_arm64.mk | 4 ++++ core/clang/config.mk | 4 +--- core/config_sanitizers.mk | 6 +++++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/core/clang/TARGET_arm.mk b/core/clang/TARGET_arm.mk index 6f6d624..62ce242 100644 --- a/core/clang/TARGET_arm.mk +++ b/core/clang/TARGET_arm.mk @@ -66,3 +66,7 @@ $(clang_2nd_arch_prefix)RS_TRIPLE_CFLAGS := $(clang_2nd_arch_prefix)RS_COMPAT_TRIPLE := armv7-none-linux-gnueabi $(clang_2nd_arch_prefix)TARGET_LIBPROFILE_RT := $(LLVM_RTLIB_PATH)/libclang_rt.profile-arm-android.a + +# Address sanitizer clang config +$(clang_2nd_arch_prefix)ADDRESS_SANITIZER_RUNTIME_LIBRARY := libclang_rt.asan-arm-android +$(clang_2nd_arch_prefix)ADDRESS_SANITIZER_RPATH := /system/lib/asan diff --git a/core/clang/TARGET_arm64.mk b/core/clang/TARGET_arm64.mk index b67d458..ea4d937 100644 --- a/core/clang/TARGET_arm64.mk +++ b/core/clang/TARGET_arm64.mk @@ -64,3 +64,7 @@ RS_TRIPLE_CFLAGS := RS_COMPAT_TRIPLE := aarch64-linux-android TARGET_LIBPROFILE_RT := $(LLVM_RTLIB_PATH)/libclang_rt.profile-aarch64-android.a + +# Address sanitizer clang config +ADDRESS_SANITIZER_RUNTIME_LIBRARY := libclang_rt.asan-arm64-android +ADDRESS_SANITIZER_RPATH := /system/lib64/asan diff --git a/core/clang/config.mk b/core/clang/config.mk index 6da90ec..dfad7ec 100644 --- a/core/clang/config.mk +++ b/core/clang/config.mk @@ -149,12 +149,10 @@ clang_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX) include $(BUILD_SYSTEM)/clang/TARGET_$(TARGET_2ND_ARCH).mk endif -# Address sanitizer clang config -ADDRESS_SANITIZER_RUNTIME_LIBRARY := libclang_rt.asan_$(TARGET_ARCH)_android ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS := -fno-omit-frame-pointer ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS := -Wl,-u,__asan_preinit -ADDRESS_SANITIZER_CONFIG_EXTRA_SHARED_LIBRARIES := libdl $(ADDRESS_SANITIZER_RUNTIME_LIBRARY) +ADDRESS_SANITIZER_CONFIG_EXTRA_SHARED_LIBRARIES := libdl ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES := libasan # This allows us to use the superset of functionality that compiler-rt diff --git a/core/config_sanitizers.mk b/core/config_sanitizers.mk index 6e3c0b8..c3009eb 100644 --- a/core/config_sanitizers.mk +++ b/core/config_sanitizers.mk @@ -81,8 +81,12 @@ ifneq ($(filter address,$(my_sanitize)),) my_ldlibs += -lm -ldl -lpthread my_ldflags += --no-as-needed else - my_shared_libraries += $(ADDRESS_SANITIZER_CONFIG_EXTRA_SHARED_LIBRARIES) + # ASan runtime library must be the first in the link order. + my_shared_libraries := $($(LOCAL_2ND_ARCH_VAR_PREFIX)ADDRESS_SANITIZER_RUNTIME_LIBRARY) \ + $(my_shared_libraries) \ + $(ADDRESS_SANITIZER_CONFIG_EXTRA_SHARED_LIBRARIES) my_static_libraries += $(ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES) + my_ldflags += -Wl,-rpath,$($(LOCAL_2ND_ARCH_VAR_PREFIX)ADDRESS_SANITIZER_RPATH) endif endif -- cgit v1.1 From bdd8ca06044ebd31986cac62f18af42e87de3a54 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Tue, 28 Apr 2015 14:55:50 -0700 Subject: --no-as-needed needs -Wl. Not sure why my checkbuild passed. Change-Id: Idd0f477faebf0b7d79998c8a86610728c2c8cc5d --- core/config_sanitizers.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/config_sanitizers.mk b/core/config_sanitizers.mk index c3009eb..7eb1c89 100644 --- a/core/config_sanitizers.mk +++ b/core/config_sanitizers.mk @@ -79,7 +79,7 @@ ifneq ($(filter address,$(my_sanitize)),) # -nodefaultlibs (provided with libc++) prevents the driver from linking # libraries needed with -fsanitize=address. http://b/18650275 (WAI) my_ldlibs += -lm -ldl -lpthread - my_ldflags += --no-as-needed + my_ldflags += -Wl,--no-as-needed else # ASan runtime library must be the first in the link order. my_shared_libraries := $($(LOCAL_2ND_ARCH_VAR_PREFIX)ADDRESS_SANITIZER_RUNTIME_LIBRARY) \ -- cgit v1.1