Skip to content

release/22.x: [sanitizer_common] [Darwin] Adopt _dyld_get_dyld_header (#182943)#188913

Merged
c-rhodes merged 1 commit intollvm:release/22.xfrom
llvmbot:issue182943
Mar 31, 2026
Merged

release/22.x: [sanitizer_common] [Darwin] Adopt _dyld_get_dyld_header (#182943)#188913
c-rhodes merged 1 commit intollvm:release/22.xfrom
llvmbot:issue182943

Conversation

@llvmbot
Copy link
Copy Markdown
Member

@llvmbot llvmbot commented Mar 27, 2026

Backport 2e7d07a

Requested by: @ndrewh

@llvmbot
Copy link
Copy Markdown
Member Author

llvmbot commented Mar 27, 2026

@DanBlackwell What do you think about merging this PR to the release branch?

@llvmbot
Copy link
Copy Markdown
Member Author

llvmbot commented Mar 27, 2026

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: llvmbot

Changes

Backport 2e7d07a

Requested by: @ndrewh


Full diff: https://github.com/llvm/llvm-project/pull/188913.diff

3 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_procmaps_mac.cpp (+6-2)
  • (modified) compiler-rt/lib/sanitizer_common/weak_symbols.txt (+1)
  • (modified) compiler-rt/lib/tsan/go/buildgo.sh (+1-1)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_mac.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_mac.cpp
index 979729f15aa16..93d3929033a86 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_mac.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_mac.cpp
@@ -176,7 +176,7 @@ void MemoryMappingLayout::Reset() {
 // The dyld load address should be unchanged throughout process execution,
 // and it is expensive to compute once many libraries have been loaded,
 // so cache it here and do not reset.
-static mach_header *dyld_hdr = 0;
+static const mach_header* dyld_hdr = 0;
 static const char kDyldPath[] = "/usr/lib/dyld";
 static const int kDyldImageIdx = -1;
 
@@ -244,14 +244,18 @@ extern intptr_t _dyld_get_image_slide(const struct mach_header* mh);
 extern int dyld_shared_cache_iterate_text(
     const uuid_t cacheUuid,
     void (^callback)(const dyld_shared_cache_dylib_text_info *info));
+SANITIZER_WEAK_IMPORT const struct mach_header* _dyld_get_dyld_header(void);
 }  // extern "C"
 
-static mach_header *GetDyldImageHeaderViaSharedCache() {
+static const mach_header* GetDyldImageHeaderViaSharedCache() {
   uuid_t uuid;
   bool hasCache = _dyld_get_shared_cache_uuid(uuid);
   if (!hasCache)
     return nullptr;
 
+  if (&_dyld_get_dyld_header != nullptr)
+    return _dyld_get_dyld_header();
+
   size_t cacheLength;
   __block uptr cacheStart = (uptr)_dyld_get_shared_cache_range(&cacheLength);
   CHECK(cacheStart && cacheLength);
diff --git a/compiler-rt/lib/sanitizer_common/weak_symbols.txt b/compiler-rt/lib/sanitizer_common/weak_symbols.txt
index 77e7b5d9f702e..600ab8a7c649c 100644
--- a/compiler-rt/lib/sanitizer_common/weak_symbols.txt
+++ b/compiler-rt/lib/sanitizer_common/weak_symbols.txt
@@ -10,3 +10,4 @@ ___sanitizer_symbolize_demangle
 ___sanitizer_symbolize_flush
 ___sanitizer_symbolize_set_demangle
 ___sanitizer_symbolize_set_inline_frames
+__dyld_get_dyld_header
diff --git a/compiler-rt/lib/tsan/go/buildgo.sh b/compiler-rt/lib/tsan/go/buildgo.sh
index d9e56402ad48f..1340071819fcb 100755
--- a/compiler-rt/lib/tsan/go/buildgo.sh
+++ b/compiler-rt/lib/tsan/go/buildgo.sh
@@ -165,7 +165,7 @@ elif [ "$GOOS" = "netbsd" ]; then
 	"
 elif [ "$GOOS" = "darwin" ]; then
 	OSCFLAGS="-fPIC -Wno-unused-const-variable -Wno-unknown-warning-option -mmacosx-version-min=10.7"
-	OSLDFLAGS="-lpthread -fPIC -fpie -mmacosx-version-min=10.7"
+	OSLDFLAGS="-lpthread -fPIC -fpie -mmacosx-version-min=10.7 -Wl,-U,__dyld_get_dyld_header"
 	SRCS="
 		$SRCS
 		../rtl/tsan_platform_mac.cpp

@ndrewh
Copy link
Copy Markdown
Contributor

ndrewh commented Mar 27, 2026

I think we should cherry-pick this to make sure that clang 22 supports ASAN on macOS 26.4.

@dyung
Copy link
Copy Markdown
Collaborator

dyung commented Mar 27, 2026

Is this a regression? If so, when was the regression introduced?

@dyung dyung moved this from Needs Triage to Needs Review in LLVM Release Status Mar 27, 2026
@DanBlackwell
Copy link
Copy Markdown
Contributor

Is this a regression? If so, when was the regression introduced?

This is a regression caused by an OS change in macOS 26.4; any runtimes without this change will not run on macOS 26.4+. Any runtimes built with this patch can run on both pre- and post-macOS 26.4 OSes.

@c-rhodes
Copy link
Copy Markdown
Collaborator

@DanBlackwell sounds reasonable, please accept if you're happy. Also adding sanitizer maintainer for visibility.

@c-rhodes c-rhodes requested a review from vitalybuka March 30, 2026 14:06
@github-project-automation github-project-automation bot moved this from Needs Review to Needs Merge in LLVM Release Status Mar 30, 2026
@c-rhodes c-rhodes merged commit 7b6514c into llvm:release/22.x Mar 31, 2026
1 check was pending
@github-project-automation github-project-automation bot moved this from Needs Merge to Done in LLVM Release Status Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

6 participants