Skip to content

Conversation

@cjacek
Copy link
Contributor

@cjacek cjacek commented Feb 11, 2025

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Feb 11, 2025

@llvm/pr-subscribers-lld

@llvm/pr-subscribers-platform-windows

Author: Jacek Caban (cjacek)

Changes

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

2 Files Affected:

  • (modified) lld/COFF/Writer.cpp (+5-3)
  • (added) lld/test/COFF/arm64x-buildid.s (+14)
diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
index 484ac9cdcaf9e..b03a4eab16ce2 100644
--- a/lld/COFF/Writer.cpp
+++ b/lld/COFF/Writer.cpp
@@ -1215,9 +1215,11 @@ void Writer::createMiscChunks() {
     // if we're ultimately not going to write CodeView data to the PDB.
     buildId = make<CVDebugRecordChunk>(ctx);
     debugRecords.emplace_back(COFF::IMAGE_DEBUG_TYPE_CODEVIEW, buildId);
-    if (Symbol *buildidSym = ctx.symtab.findUnderscore("__buildid"))
-      replaceSymbol<DefinedSynthetic>(buildidSym, buildidSym->getName(),
-                                      buildId, 4);
+    ctx.forEachSymtab([&](SymbolTable &symtab) {
+      if (Symbol *buildidSym = symtab.findUnderscore("__buildid"))
+        replaceSymbol<DefinedSynthetic>(buildidSym, buildidSym->getName(),
+                                        buildId, 4);
+    });
   }
 
   if (config->cetCompat) {
diff --git a/lld/test/COFF/arm64x-buildid.s b/lld/test/COFF/arm64x-buildid.s
new file mode 100644
index 0000000000000..99f50073eaa69
--- /dev/null
+++ b/lld/test/COFF/arm64x-buildid.s
@@ -0,0 +1,14 @@
+# REQUIRES: aarch64
+# RUN: llvm-mc -triple=aarch64-windows -filetype=obj -o %t-arm64.obj %s
+# RUN: llvm-mc -triple=arm64ec-windows -filetype=obj -o %t-arm64ec.obj %s
+
+# RUN: lld-link -machine:arm64x -dll -noentry %t-arm64.obj %t-arm64ec.obj -debug -build-id -Brepro -out:%t.dll
+# RUN: llvm-readobj --hex-dump=.test %t.dll | FileCheck %s
+# CHECK: 0x180003000 3c100000 3c100000
+
+.section .test,"dr"
+.rva __buildid
+
+.section .bss,"bw",discard,__buildid
+.global __buildid
+__buildid:

@llvmbot
Copy link
Member

llvmbot commented Feb 11, 2025

@llvm/pr-subscribers-lld-coff

Author: Jacek Caban (cjacek)

Changes

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

2 Files Affected:

  • (modified) lld/COFF/Writer.cpp (+5-3)
  • (added) lld/test/COFF/arm64x-buildid.s (+14)
diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
index 484ac9cdcaf9e..b03a4eab16ce2 100644
--- a/lld/COFF/Writer.cpp
+++ b/lld/COFF/Writer.cpp
@@ -1215,9 +1215,11 @@ void Writer::createMiscChunks() {
     // if we're ultimately not going to write CodeView data to the PDB.
     buildId = make<CVDebugRecordChunk>(ctx);
     debugRecords.emplace_back(COFF::IMAGE_DEBUG_TYPE_CODEVIEW, buildId);
-    if (Symbol *buildidSym = ctx.symtab.findUnderscore("__buildid"))
-      replaceSymbol<DefinedSynthetic>(buildidSym, buildidSym->getName(),
-                                      buildId, 4);
+    ctx.forEachSymtab([&](SymbolTable &symtab) {
+      if (Symbol *buildidSym = symtab.findUnderscore("__buildid"))
+        replaceSymbol<DefinedSynthetic>(buildidSym, buildidSym->getName(),
+                                        buildId, 4);
+    });
   }
 
   if (config->cetCompat) {
diff --git a/lld/test/COFF/arm64x-buildid.s b/lld/test/COFF/arm64x-buildid.s
new file mode 100644
index 0000000000000..99f50073eaa69
--- /dev/null
+++ b/lld/test/COFF/arm64x-buildid.s
@@ -0,0 +1,14 @@
+# REQUIRES: aarch64
+# RUN: llvm-mc -triple=aarch64-windows -filetype=obj -o %t-arm64.obj %s
+# RUN: llvm-mc -triple=arm64ec-windows -filetype=obj -o %t-arm64ec.obj %s
+
+# RUN: lld-link -machine:arm64x -dll -noentry %t-arm64.obj %t-arm64ec.obj -debug -build-id -Brepro -out:%t.dll
+# RUN: llvm-readobj --hex-dump=.test %t.dll | FileCheck %s
+# CHECK: 0x180003000 3c100000 3c100000
+
+.section .test,"dr"
+.rva __buildid
+
+.section .bss,"bw",discard,__buildid
+.global __buildid
+__buildid:

Copy link
Member

@mstorsjo mstorsjo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cjacek cjacek merged commit c52fbab into llvm:main Feb 13, 2025
12 checks passed
@cjacek cjacek deleted the arm64x-buildid branch February 13, 2025 18:10
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
SquallATF pushed a commit to SquallATF/llvm-project that referenced this pull request Jun 13, 2025
SquallATF pushed a commit to SquallATF/llvm-project that referenced this pull request Jul 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants