Skip to content

Commit 4a547fb

Browse files
author
Kostya Kortchinsky
committedJul 13, 2018
[sanitizer] Use -Wl,-z,global on Android
Summary: Use `-Wl,-z,global` for all Sanitizer shared libraries on Android. We want them to be in the global group (https://android.googlesource.com/platform/bionic/+/master/android-changes-for-ndk-developers.md#changes-to-library-search-order) to avoid any alloc/dealloc mismatch between the libc allocator & said library. `audioserver` was one of the binary that exhibited the problem with Scudo, this seems to fix it. [edited for accuracy] Reviewers: eugenis, alekseyshl Reviewed By: eugenis Subscribers: kubamracek, srhines, mgorny, delcypher, #sanitizers, llvm-commits Differential Revision: https://reviews.llvm.org/D49198 llvm-svn: 337010
1 parent ceabd50 commit 4a547fb

File tree

3 files changed

+8
-28
lines changed

3 files changed

+8
-28
lines changed
 

‎compiler-rt/CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,14 @@ endif()
333333

334334
append_list_if(COMPILER_RT_HAS_LIBC c SANITIZER_COMMON_LINK_LIBS)
335335

336+
if(ANDROID)
337+
# Put the Sanitizer shared libraries in the global group. For more details, see
338+
# android-changes-for-ndk-developers.md#changes-to-library-search-order
339+
if (COMPILER_RT_HAS_Z_GLOBAL)
340+
list(APPEND SANITIZER_COMMON_LINK_FLAGS -Wl,-z,global)
341+
endif()
342+
endif()
343+
336344
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Fuchsia")
337345
list(APPEND SANITIZER_COMMON_LINK_FLAGS -Wl,-z,defs,-z,now,-z,relro)
338346
list(APPEND SANITIZER_COMMON_LINK_LIBS zircon)

‎compiler-rt/lib/asan/CMakeLists.txt

-14
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,6 @@ append_rtti_flag(OFF ASAN_CFLAGS)
7575

7676
set(ASAN_DYNAMIC_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS})
7777

78-
if(ANDROID)
79-
# On Android, -z global does not do what it is documented to do.
80-
# On Android, -z global moves the library ahead in the lookup order,
81-
# placing it right after the LD_PRELOADs. This is used to compensate for the fact
82-
# that Android linker does not look at the dependencies of the main executable
83-
# that aren't dependencies of the current DSO when resolving symbols from said DSO.
84-
# As a net result, this allows running ASan executables without LD_PRELOAD-ing the
85-
# ASan runtime library.
86-
# The above is applicable to L MR1 or newer.
87-
if (COMPILER_RT_HAS_Z_GLOBAL)
88-
list(APPEND ASAN_DYNAMIC_LINK_FLAGS -Wl,-z,global)
89-
endif()
90-
endif()
91-
9278
set(ASAN_DYNAMIC_DEFINITIONS
9379
${ASAN_COMMON_DEFINITIONS} ASAN_DYNAMIC=1)
9480
append_list_if(WIN32 INTERCEPTION_DYNAMIC_CRT ASAN_DYNAMIC_DEFINITIONS)

‎compiler-rt/lib/hwasan/CMakeLists.txt

-14
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,6 @@ append_list_if(COMPILER_RT_HAS_FFREESTANDING_FLAG -ffreestanding HWASAN_RTL_CFLA
3636

3737
set(HWASAN_DYNAMIC_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS})
3838

39-
if(ANDROID)
40-
# On Android, -z global does not do what it is documented to do.
41-
# On Android, -z global moves the library ahead in the lookup order,
42-
# placing it right after the LD_PRELOADs. This is used to compensate for the fact
43-
# that Android linker does not look at the dependencies of the main executable
44-
# that aren't dependencies of the current DSO when resolving symbols from said DSO.
45-
# As a net result, this allows running ASan executables without LD_PRELOAD-ing the
46-
# ASan runtime library.
47-
# The above is applicable to L MR1 or newer.
48-
if (COMPILER_RT_HAS_Z_GLOBAL)
49-
list(APPEND HWASAN_DYNAMIC_LINK_FLAGS -Wl,-z,global)
50-
endif()
51-
endif()
52-
5339
set(HWASAN_DYNAMIC_CFLAGS ${HWASAN_RTL_CFLAGS})
5440
append_list_if(COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC
5541
-ftls-model=initial-exec HWASAN_DYNAMIC_CFLAGS)

0 commit comments

Comments
 (0)