[lld] [LLD][ELF] Skip symbols to dead mergeable section pieces for --why-live (PR #226238)
Andrew Ng via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 25 02:05:43 PDT 2026
https://github.com/nga888 updated https://github.com/llvm/llvm-project/pull/226238
>From 819791c5c098073e33ccb3d975b9227d8aeb8d1b Mon Sep 17 00:00:00 2001
From: Andrew Ng <andrew.ng at sony.com>
Date: Thu, 24 Sep 2026 15:06:18 +0100
Subject: [PATCH] [LLD][ELF] Skip symbols to dead mergeable section pieces for
--why-live
Before this change, `--why-live=*` in "why-live.test" incorrectly prints
`live symbol: b.o:(dead)`.
---
lld/ELF/MarkLive.cpp | 15 +++++++++++----
lld/test/ELF/why-live.test | 2 ++
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp
index 8e5071cdc0073a..f5179bb2c60d00 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 1b36d8562cf4bd..6c9297b3c8b6b0 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