Author: Fangrui Song
Date: 2022-08-08T12:39:51-07:00
New Revision: 4acca1b014ece0073fd33c384b86b7a29dd3df9d

URL: 
https://github.com/llvm/llvm-project/commit/4acca1b014ece0073fd33c384b86b7a29dd3df9d
DIFF: 
https://github.com/llvm/llvm-project/commit/4acca1b014ece0073fd33c384b86b7a29dd3df9d.diff

LOG: [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)

Added: 
    

Modified: 
    lld/ELF/Relocations.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index e54e1ebd41bb8..53af34ef20855 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -1705,7 +1705,8 @@ static bool mergeCmp(const InputSection *a, const 
InputSection *b) {
   if (a->outSecOff < b->outSecOff)
     return true;
 
-  if (a->outSecOff == b->outSecOff) {
+  // FIXME dyn_cast<ThunkSection> is non-null for any SyntheticSection.
+  if (a->outSecOff == b->outSecOff && a != b) {
     auto *ta = dyn_cast<ThunkSection>(a);
     auto *tb = dyn_cast<ThunkSection>(b);
 


        
_______________________________________________
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to