[lld] f4620e3 - [LLD][ELF] Skip symbols to dead mergeable section pieces for --why-live (#226238)

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 25 02:40:03 PDT 2026


Author: Andrew Ng
Date: 2026-09-25T10:39:56+01:00
New Revision: f4620e36f5d06df795fda3ef4fd421509609ca5a

URL: https://github.com/llvm/llvm-project/commit/f4620e36f5d06df795fda3ef4fd421509609ca5a
DIFF: https://github.com/llvm/llvm-project/commit/f4620e36f5d06df795fda3ef4fd421509609ca5a.diff

LOG: [LLD][ELF] Skip symbols to dead mergeable section pieces for --why-live (#226238)

Before this change, `--why-live=*` in "why-live.test" incorrectly prints
`live symbol: b.o:(dead)`.

Added: 
    

Modified: 
    lld/ELF/MarkLive.cpp
    lld/test/ELF/why-live.test

Removed: 
    


################################################################################
diff  --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp
index 8e5071cdc0073..f5179bb2c60d0 100644
--- a/lld/ELF/MarkLive.cpp
+++ b/lld/ELF/MarkLive.cpp
@@ -276,11 +276,18 @@ void MarkLive<ELFT, TrackWhyLive>::enqueue(InputSectionBase *sec,
 // Print the stack of reasons that the given symbol is live.
 template <class ELFT, bool TrackWhyLive>
 void MarkLive<ELFT, TrackWhyLive>::printWhyLive(Symbol *s) const {
-  // Skip dead symbols. A symbol is dead if it belongs to a dead section.
+  // Skip dead symbols. A symbol is dead if it belongs to a dead section or if
+  // it refers to a dead mergeable section piece.
   if (auto *d = dyn_cast<Defined>(s)) {
-    auto *sec = dyn_cast_or_null<InputSectionBase>(d->section);
-    if (sec && !sec->isLive())
-      return;
+    if (auto *sec = dyn_cast_or_null<InputSectionBase>(d->section)) {
+      if (!sec->isLive())
+        return;
+
+      if (!d->isSection())
+        if (auto *ms = dyn_cast<MergeInputSection>(sec);
+            ms && !ms->getSectionPiece(d->value).live)
+          return;
+    }
   }
 
   auto msg = Msg(ctx);

diff  --git a/lld/test/ELF/why-live.test b/lld/test/ELF/why-live.test
index 1b36d8562cf4b..6c9297b3c8b6b 100644
--- a/lld/test/ELF/why-live.test
+++ b/lld/test/ELF/why-live.test
@@ -273,3 +273,5 @@ __FRAME_END__:
 .section .rodata.str1.1,"aMS", at progbits,1
 str1:
   .asciz "str1"
+dead:
+  .asciz "dead"


        


More information about the llvm-commits mailing list