[lld] [lld][MachO] Fix symbol insertion in `transplantSymbolsAtOffset` (PR #120737)

Carlo Cabrera via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 21 07:20:30 PST 2024


================
@@ -91,6 +97,11 @@ static void transplantSymbolsAtOffset(InputSection *fromIsec,
     }
     return true;
   });
+  assert(llvm::is_sorted(toIsec->symbols,
+                         [](const Defined *s, const Defined *t) {
+                           return s->value < t->value;
+                         }) &&
+         "Symbols should still be sorted at exit.");
----------------
carlocab wrote:

Verified with Clang _without_ expensive checks and the comparison in `symSucceedsOff` reversed:
```
Failed Tests (3):
  lld :: MachO/local-alias-to-weak.s
  lld :: MachO/symtab.s
  lld :: MachO/weak-definition-gc.s
```
To be sure, all errors are of the form
```
Assertion failed: (std::is_partitioned(toIsec->symbols.begin(), toIsec->symbols.end(), [toOff, symSucceedsOff](const Symbol *s) { return !symSucceedsOff(toOff, s); }) && "Symbols in toIsec must be partitioned by toOff."), function transplantSymbolsAtOffset, file SymbolTable.cpp, line 78.
```

https://github.com/llvm/llvm-project/pull/120737


More information about the llvm-commits mailing list