Skip to content

Commit 4acca1b

Browse files
MaskRaytstellar
authored andcommitted
[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. (cherry picked from commit abd9807)
1 parent 8160d4a commit 4acca1b

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
@@ -1705,7 +1705,8 @@ static bool mergeCmp(const InputSection *a, const InputSection *b) {
17051705
if (a->outSecOff < b->outSecOff)
17061706
return true;
17071707

1708-
if (a->outSecOff == b->outSecOff) {
1708+
// FIXME dyn_cast<ThunkSection> is non-null for any SyntheticSection.
1709+
if (a->outSecOff == b->outSecOff && a != b) {
17091710
auto *ta = dyn_cast<ThunkSection>(a);
17101711
auto *tb = dyn_cast<ThunkSection>(b);
17111712

0 commit comments

Comments
 (0)