Index: lib/scudo/CMakeLists.txt =================================================================== --- lib/scudo/CMakeLists.txt +++ lib/scudo/CMakeLists.txt @@ -17,6 +17,18 @@ # Use gc-sections by default to avoid unused code being pulled in. list(APPEND SCUDO_DYNAMIC_LINK_FLAGS -Wl,--gc-sections) +if(ANDROID) +# On Android, -z global does not do what it is documented to do. +# On Android, -z global moves the library ahead in the lookup order, placing it +# right after the LD_PRELOADs. This is used to compensate for the fact that +# Android linker does not look at the dependencies of the main executable that +# aren't dependencies of the current DSO when resolving symbols from said DSO. +# The above is applicable to L MR1 or newer. + if (COMPILER_RT_HAS_Z_GLOBAL) + list(APPEND ASAN_DYNAMIC_LINK_FLAGS -Wl,-z,global) + endif() +endif() + # The minimal Scudo runtime does not inlude the UBSan runtime. set(SCUDO_MINIMAL_OBJECT_LIBS RTSanitizerCommonNoTermination