[ELF] mergeCmp: work around irreflexivity bug
authorFangrui Song <i@maskray.me>
Sat, 6 Aug 2022 00:08:37 +0000 (17:08 -0700)
committerTom Stellard <tstellar@redhat.com>
Mon, 8 Aug 2022 19:39:51 +0000 (12:39 -0700)
commit4acca1b014ece0073fd33c384b86b7a29dd3df9d
tree4bee26a1da82d51864dd5f1b37264eddd7c21af5
parent8160d4a2a9518696ca151fd0315769fceb022e0d
[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 abd9807590fc10eb92eb22aea7b50dbf08db7e9d)
lld/ELF/Relocations.cpp