[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:50:49 PST 2024
carlocab wrote:
Tried this:
```diff
diff --git a/lld/MachO/SymbolTable.cpp b/lld/MachO/SymbolTable.cpp
index a61e60a944fb..4b6e462f6bdd 100644
--- a/lld/MachO/SymbolTable.cpp
+++ b/lld/MachO/SymbolTable.cpp
@@ -68,7 +68,7 @@ static void transplantSymbolsAtOffset(InputSection *fromIsec,
uint64_t fromOff, uint64_t toOff) {
// Ensure the symbols will still be in address order after our insertions.
auto symSucceedsOff = [](uint64_t off, const Symbol *s) {
- return cast<Defined>(s)->value > off;
+ return cast<Defined>(s)->value < off;
};
assert(std::is_partitioned(toIsec->symbols.begin(), toIsec->symbols.end(),
[symSucceedsOff, toOff](const Symbol *s) {
@@ -96,6 +96,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.");
}
Defined *SymbolTable::addDefined(StringRef name, InputFile *file,
diff --git a/lld/test/MachO/alias-symbols.s b/lld/test/MachO/alias-symbols.s
index 44a388c35722..231ada5aa4c8 100644
--- a/lld/test/MachO/alias-symbols.s
+++ b/lld/test/MachO/alias-symbols.s
@@ -124,7 +124,9 @@ _strong:
_weak_1:
.space 1
_weak_2:
- .space 1
+ .long 1
+_weak_3:
+ .long 1
_dead:
.space 1
_pext:
```
Still no failure from `lld/test/MachO/alias-symbols.s`. Given that the `is_partitioned` assertion isn't even firing here, I wonder if trying to modify `alias-symbols.s` is going to be a lot more complicated than working with the other tests that are failing.
https://github.com/llvm/llvm-project/pull/120737
More information about the llvm-commits
mailing list