Skip to content

Commit a0f0a69

Browse files
carlocabbjope
andauthored
[lld][MachO] Fix symbol insertion in transplantSymbolsAtOffset (#120737)
The existing comparison does not insert symbols in the intended place. Closes #120559. --------- Co-authored-by: Bjorn Pettersson <[email protected]>
1 parent d486b76 commit a0f0a69

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lld/MachO/SymbolTable.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,15 @@ static void transplantSymbolsAtOffset(InputSection *fromIsec,
6767
InputSection *toIsec, Defined *skip,
6868
uint64_t fromOff, uint64_t toOff) {
6969
// Ensure the symbols will still be in address order after our insertions.
70-
auto insertIt = llvm::upper_bound(toIsec->symbols, toOff,
71-
[](uint64_t off, const Symbol *s) {
72-
return cast<Defined>(s)->value < off;
73-
});
70+
auto symSucceedsOff = [](uint64_t off, const Symbol *s) {
71+
return cast<Defined>(s)->value > off;
72+
};
73+
assert(std::is_partitioned(toIsec->symbols.begin(), toIsec->symbols.end(),
74+
[symSucceedsOff, toOff](const Symbol *s) {
75+
return !symSucceedsOff(toOff, s);
76+
}) &&
77+
"Symbols in toIsec must be partitioned by toOff.");
78+
auto insertIt = llvm::upper_bound(toIsec->symbols, toOff, symSucceedsOff);
7479
llvm::erase_if(fromIsec->symbols, [&](Symbol *s) {
7580
auto *d = cast<Defined>(s);
7681
if (d->value != fromOff)

0 commit comments

Comments
 (0)