File tree Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -250,9 +250,9 @@ template <class ELFT> void MarkLive<ELFT>::printWhyLive(Symbol *s) const {
250250 auto *d = dyn_cast<Defined>(s);
251251 if (!d)
252252 return ;
253- // TODO: Test both cases
254- auto *parent = dyn_cast <InputSectionBase>(d->section );
255- if (! parent || !parent->isLive ())
253+ // A defined symbol is only dead if it has a dead input section parent.
254+ auto *parent = dyn_cast_or_null <InputSectionBase>(d->section );
255+ if (parent && !parent->isLive ())
256256 return ;
257257 }
258258
@@ -266,14 +266,17 @@ template <class ELFT> void MarkLive<ELFT>::printWhyLive(Symbol *s) const {
266266 if (it != whyLive.end ()) {
267267 // The object may be a liveness root.
268268 if (!it->second )
269- break ;
269+ return ;
270270 cur = *it->second ;
271271 } else {
272+ auto *d = cast<Defined>(std::get<Symbol *>(cur));
273+ auto *parent = dyn_cast_or_null<InputSectionBase>(d->section );
274+ if (!parent)
275+ return ;
276+
272277 // This object made something else live, but it has no direct reason to be
273278 // live. That means it a symbol kept live only by being a member of its
274279 // parent section. Report that section as the symbol's parent.
275- auto *d = cast<Defined>(std::get<Symbol *>(cur));
276- auto *parent = cast<InputSectionBase>(d->section );
277280 cur = LiveObject{parent};
278281 }
279282
Original file line number Diff line number Diff line change @@ -46,3 +46,9 @@ jmp test_dead
4646## Undefined symbols are not considered live.
4747# RUN: ld.lld %t.o -o /dev/null --gc-sections --why-live=test_undef -u test_undef | count 0
4848
49+ ## Defined symbols without input section parents are considered directly live.
50+ # RUN: ld.lld %t.o -o /dev/null --gc-sections --why-live=test_absolute | FileCheck %s --check-prefix=ABSOLUTE
51+ # ABSOLUTE: live symbol: test_absolute
52+ # ABSOLUTE-NOT: >>>
53+ .globl test_absolute
54+ test_absolute = 1234
You can’t perform that action at this time.
0 commit comments