Skip to content

Commit e77e289

Browse files
committed
Add assert to transplantSymbolsAtOffset
This should help catch problems with symbol insertion.
1 parent 7353c9b commit e77e289

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)