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: I5c0cdb89e5e08a1950eb276e406da9f31a6e52dd
diff --git a/core/config_sanitizers.mk b/core/config_sanitizers.mk
index 210d442..6b0c6c8 100644
--- a/core/config_sanitizers.mk
+++ b/core/config_sanitizers.mk
@@ -80,8 +80,12 @@
     # libraries needed with -fsanitize=address. http://b/18650275 (WAI)
     my_ldlibs += -ldl -lpthread
   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