Skip to content

release/21.x: [LLD][COFF] Allow symbols with empty chunks to have no associated output section in the PDB writer (#149523) #150969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2025

Conversation

llvmbot
Copy link
Member

@llvmbot llvmbot commented Jul 28, 2025

Backport 1ab04fc

Requested by: @cjacek

@llvmbot
Copy link
Member Author

llvmbot commented Jul 28, 2025

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

@llvmbot
Copy link
Member Author

llvmbot commented Jul 28, 2025

@llvm/pr-subscribers-platform-windows
@llvm/pr-subscribers-lld-coff

@llvm/pr-subscribers-lld

Author: None (llvmbot)

Changes

Backport 1ab04fc

Requested by: @cjacek


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

2 Files Affected:

  • (modified) lld/COFF/PDB.cpp (+6-3)
  • (added) lld/test/COFF/pdb-empty-sec.s (+19)
diff --git a/lld/COFF/PDB.cpp b/lld/COFF/PDB.cpp
index a54ea403ba2ec..94eeae2797971 100644
--- a/lld/COFF/PDB.cpp
+++ b/lld/COFF/PDB.cpp
@@ -1135,9 +1135,12 @@ static pdb::BulkPublic createPublic(COFFLinkerContext &ctx, Defined *def) {
   pub.setFlags(flags);
 
   OutputSection *os = ctx.getOutputSection(def->getChunk());
-  assert(os && "all publics should be in final image");
-  pub.Offset = def->getRVA() - os->getRVA();
-  pub.Segment = os->sectionIndex;
+  assert((os || !def->getChunk()->getSize()) &&
+         "all publics should be in final image");
+  if (os) {
+    pub.Offset = def->getRVA() - os->getRVA();
+    pub.Segment = os->sectionIndex;
+  }
   return pub;
 }
 
diff --git a/lld/test/COFF/pdb-empty-sec.s b/lld/test/COFF/pdb-empty-sec.s
new file mode 100644
index 0000000000000..0d61447b76651
--- /dev/null
+++ b/lld/test/COFF/pdb-empty-sec.s
@@ -0,0 +1,19 @@
+// REQUIRES: x86
+
+// RUN: llvm-mc -filetype=obj -triple=x86_64-windows %s -o %t.obj
+// RUN: lld-link -dll -noentry -debug %t.obj -out:%t.dll
+// RUN: llvm-pdbutil dump -publics %t.pdb | FileCheck %s
+
+// CHECK:       Records
+// CHECK-NEXT:       0 | S_PUB32 [size = 20] `func`
+// CHECK-NEXT:           flags = none, addr = 0001:0000
+// CHECK-NEXT:      20 | S_PUB32 [size = 20] `sym`
+// CHECK-NEXT:           flags = none, addr = 0000:0000
+
+        .globl sym
+        .data
+sym:
+        .text
+        .globl func
+func:
+        ret

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

@github-project-automation github-project-automation bot moved this from Needs Triage to Needs Merge in LLVM Release Status Jul 28, 2025
@mstorsjo
Copy link
Member

It's unlucky that this one missed the RC2 (even though it was ready to merge 2 days ago), as it fixes a bug a user of mine reported on RC1. I'll ask them to use nightlies in the meantime.

@tru
Copy link
Collaborator

tru commented Jul 30, 2025

Sorry, I think it failed in the CI because of a bug in the ci scrips (which is why I rebased), then it timed out for some reason and I ran out of time before I had to cut the release. So it was definitely bad luck and not me missing it unfortunately

@mstorsjo
Copy link
Member

Fair enough, and no worries. I guess issues with the CI are getting fixed, so it gets smoother and smoother.

…put section in the PDB writer (llvm#149523)

If a chunk is empty and there are no other non-empty chunks in the same
section, `removeEmptySections()` will remove the entire section. In this
case, use a section index of 0, as the MSVC linker does, instead of
asserting.

(cherry picked from commit 1ab04fc)
@tru tru merged commit 7e51c08 into llvm:release/21.x Aug 1, 2025
1 check was pending
@github-project-automation github-project-automation bot moved this from Needs Merge to Done in LLVM Release Status Aug 1, 2025
Copy link

github-actions bot commented Aug 1, 2025

@cjacek (or anyone else). If you would like to add a note about this fix in the release notes (completely optional). Please reply to this comment with a one or two sentence description of the fix. When you are done, please add the release:note label to this PR.

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.

4 participants