A special linker for ASan executables.
Setup a /system/bin/linker_asan as a symlink to "linker".
Read the linker name from PT_INTERP, and if it is linker_asan,
switch default library lookup paths to the ASan set, which
starts with the path to the instrumented libraries
(/data/lib), followed by /system/lib as a fallback.
This ensures that ASan binaries prefer ASan libraries, when
available. This approach is way better then RPATH/RUNPATH and even
better than LD_LIBRARY_PATH:
- RUNPATH is per-DSO, while default paths are global.
- LD_LIBRARY_PATH is overwritten by android_update_LD_LIBRARY_PATH.
- neither RUNPATH nor LD_LIBRARY_PATH appear in
android_get_LD_LIBRARY_PATH which is used to build java.lang.path.
Having ASan libraries in java.lang.path is a good thing.
Bug: 22355945
Change-Id: I1d2791fbf5740618f18f71a3ae3d873714669d3f
diff --git a/linker/Android.mk b/linker/Android.mk
index 7a9b5d9..761ce8f 100644
--- a/linker/Android.mk
+++ b/linker/Android.mk
@@ -83,4 +83,26 @@
include $(BUILD_EXECUTABLE)
+
+ifeq (address, $(strip $(SANITIZE_TARGET)))
+
+define add-linker-symlink
+$(eval _from := $(TARGET_OUT)/bin/$(1))
+$(eval _to:=$(2))
+$(_from): $(LOCAL_MODULE_MAKEFILE)
+ @echo "Symlink: $$@ -> $(_to)"
+ @mkdir -p $$(dir $$@)
+ @rm -rf $$@
+ $(hide) ln -sf $(_to) $$@
+ALL_MODULES.linker.INSTALLED += $(_from)
+linker: $(_from)
+endef
+
+$(eval $(call add-linker-symlink,linker_asan,linker))
+ifeq ($(TARGET_IS_64_BIT),true)
+$(eval $(call add-linker-symlink,linker_asan64,linker64))
+endif
+ALL_MODULES += linker
+endif
+
include $(call first-makefiles-under,$(LOCAL_PATH))