Skip to content

Commit 7b6514c

Browse files
ndrewhc-rhodes
authored andcommitted
[sanitizer_common] [Darwin] Adopt _dyld_get_dyld_header (#182943)
(cherry picked from commit 2e7d07a)
1 parent 24b53fb commit 7b6514c

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

compiler-rt/lib/sanitizer_common/sanitizer_procmaps_mac.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void MemoryMappingLayout::Reset() {
176176
// The dyld load address should be unchanged throughout process execution,
177177
// and it is expensive to compute once many libraries have been loaded,
178178
// so cache it here and do not reset.
179-
static mach_header *dyld_hdr = 0;
179+
static const mach_header* dyld_hdr = 0;
180180
static const char kDyldPath[] = "/usr/lib/dyld";
181181
static const int kDyldImageIdx = -1;
182182

@@ -244,14 +244,18 @@ extern intptr_t _dyld_get_image_slide(const struct mach_header* mh);
244244
extern int dyld_shared_cache_iterate_text(
245245
const uuid_t cacheUuid,
246246
void (^callback)(const dyld_shared_cache_dylib_text_info *info));
247+
SANITIZER_WEAK_IMPORT const struct mach_header* _dyld_get_dyld_header(void);
247248
} // extern "C"
248249

249-
static mach_header *GetDyldImageHeaderViaSharedCache() {
250+
static const mach_header* GetDyldImageHeaderViaSharedCache() {
250251
uuid_t uuid;
251252
bool hasCache = _dyld_get_shared_cache_uuid(uuid);
252253
if (!hasCache)
253254
return nullptr;
254255

256+
if (&_dyld_get_dyld_header != nullptr)
257+
return _dyld_get_dyld_header();
258+
255259
size_t cacheLength;
256260
__block uptr cacheStart = (uptr)_dyld_get_shared_cache_range(&cacheLength);
257261
CHECK(cacheStart && cacheLength);

compiler-rt/lib/sanitizer_common/weak_symbols.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ ___sanitizer_symbolize_demangle
1010
___sanitizer_symbolize_flush
1111
___sanitizer_symbolize_set_demangle
1212
___sanitizer_symbolize_set_inline_frames
13+
__dyld_get_dyld_header

compiler-rt/lib/tsan/go/buildgo.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ elif [ "$GOOS" = "netbsd" ]; then
165165
"
166166
elif [ "$GOOS" = "darwin" ]; then
167167
OSCFLAGS="-fPIC -Wno-unused-const-variable -Wno-unknown-warning-option -mmacosx-version-min=10.7"
168-
OSLDFLAGS="-lpthread -fPIC -fpie -mmacosx-version-min=10.7"
168+
OSLDFLAGS="-lpthread -fPIC -fpie -mmacosx-version-min=10.7 -Wl,-U,__dyld_get_dyld_header"
169169
SRCS="
170170
$SRCS
171171
../rtl/tsan_platform_mac.cpp

0 commit comments

Comments
 (0)