Skip to content

Commit

Permalink
[lld][MachO] Fix symbol insertion in transplantSymbolsAtOffset (#12…
Browse files Browse the repository at this point in the history
…0737)

The existing comparison does not insert symbols in the intended place.

Closes #120559.

---------

Co-authored-by: Bjorn Pettersson <[email protected]>
  • Loading branch information
carlocab and bjope authored Dec 22, 2024
1 parent d486b76 commit a0f0a69
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lld/MachO/SymbolTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,15 @@ static void transplantSymbolsAtOffset(InputSection *fromIsec,
InputSection *toIsec, Defined *skip,
uint64_t fromOff, uint64_t toOff) {
// Ensure the symbols will still be in address order after our insertions.
auto insertIt = llvm::upper_bound(toIsec->symbols, toOff,
[](uint64_t off, const Symbol *s) {
return cast<Defined>(s)->value < off;
});
auto symSucceedsOff = [](uint64_t off, const Symbol *s) {
return cast<Defined>(s)->value > off;
};
assert(std::is_partitioned(toIsec->symbols.begin(), toIsec->symbols.end(),
[symSucceedsOff, toOff](const Symbol *s) {
return !symSucceedsOff(toOff, s);
}) &&
"Symbols in toIsec must be partitioned by toOff.");
auto insertIt = llvm::upper_bound(toIsec->symbols, toOff, symSucceedsOff);
llvm::erase_if(fromIsec->symbols, [&](Symbol *s) {
auto *d = cast<Defined>(s);
if (d->value != fromOff)
Expand Down

0 comments on commit a0f0a69

Please sign in to comment.