Skip to content

Commit abd9807

Browse files
committed
[ELF] mergeCmp: work around irreflexivity bug
Some tests (e.g. aarch64-feature-pac.s) segfault in libstdc++ _GLIBCXX_DEBUG builds (enabled by LLVM_ENABLE_EXPENSIVE_CHECKS). dyn_cast<ThunkSection> is incorrectly true for any SyntheticSection. std::merge transitively calls mergeCmp(x, x) (due to __glibcxx_requires_irreflexive_pred) and will segfault in `ta->getTargetInputSection()`. The dyn_cast<ThunkSection> issue should be eventually fixed properly, bug `a != b` is robust enough for now.
1 parent 3fbbf28 commit abd9807

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lld/ELF/Relocations.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,8 @@ static bool mergeCmp(const InputSection *a, const InputSection *b) {
17121712
if (a->outSecOff < b->outSecOff)
17131713
return true;
17141714

1715-
if (a->outSecOff == b->outSecOff) {
1715+
// FIXME dyn_cast<ThunkSection> is non-null for any SyntheticSection.
1716+
if (a->outSecOff == b->outSecOff && a != b) {
17161717
auto *ta = dyn_cast<ThunkSection>(a);
17171718
auto *tb = dyn_cast<ThunkSection>(b);
17181719

0 commit comments

Comments
 (0)