Skip to content

Commit 59f826b

Browse files
committed
Consider all symbols that are not parts of dead sections alive
1 parent e47b5de commit 59f826b

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

lld/ELF/MarkLive.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,8 @@ void MarkLive<ELFT>::enqueue(InputSectionBase *sec, uint64_t offset,
245245
}
246246

247247
template <class ELFT> void MarkLive<ELFT>::printWhyLive(Symbol *s) const {
248-
// If the symbol isn't live, return.
249-
if (!whyLive.contains(s)) {
250-
auto *d = dyn_cast<Defined>(s);
251-
if (!d)
252-
return;
253-
// A defined symbol is only dead if it has a dead input section parent.
248+
// Skip dead symbols. A symbol is dead if it belongs to a dead section.
249+
if (auto *d = dyn_cast<Defined>(s)) {
254250
auto *parent = dyn_cast_or_null<InputSectionBase>(d->section);
255251
if (parent && !parent->isLive())
256252
return;
@@ -269,11 +265,17 @@ template <class ELFT> void MarkLive<ELFT>::printWhyLive(Symbol *s) const {
269265
return;
270266
cur = *it->second;
271267
} else {
272-
auto *d = cast<Defined>(std::get<Symbol *>(cur));
268+
// TODO: Some sections are enqueued without symbols, so maybe cur could be a section?
269+
auto *d = dyn_cast<Defined>(std::get<Symbol *>(cur));
270+
if (!d)
271+
return;
273272
auto *parent = dyn_cast_or_null<InputSectionBase>(d->section);
274273
if (!parent)
275274
return;
276275

276+
// TODO: This comment below seems vaguely wrong given the changes to the
277+
// logic above.
278+
277279
// This object made something else live, but it has no direct reason to be
278280
// live. That means it a symbol kept live only by being a member of its
279281
// parent section. Report that section as the symbol's parent.

lld/test/ELF/why-live.s

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ jmp test_from_unsized
4343
test_dead:
4444
jmp test_dead
4545

46-
## Undefined symbols are not considered live.
47-
# RUN: ld.lld %t.o -o /dev/null --gc-sections --why-live=test_undef -u test_undef | count 0
46+
## Undefined symbols are considered live, since they are not attached to dead sections.
47+
# RUN: ld.lld %t.o -o /dev/null --gc-sections --why-live=test_undef -u test_undef | FileCheck %s --check-prefix=UNDEFINED
48+
# UNDEFINED: live symbol: test_undef
49+
# UNDEFINED-NOT: >>>
4850

4951
## Defined symbols without input section parents are considered directly live.
5052
# RUN: ld.lld %t.o -o /dev/null --gc-sections --why-live=test_absolute | FileCheck %s --check-prefix=ABSOLUTE

0 commit comments

Comments
 (0)