Skip to content

Commit e47b5de

Browse files
committed
Test live symbol without parent
1 parent fc0007d commit e47b5de

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

lld/ELF/MarkLive.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff 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

lld/test/ELF/why-live.s

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)