Skip to content

Commit 5ed881d

Browse files
authored
Discard invalid "DW.ref.__gxx_personality_v0" pieces in rela.eh_frame
When the "DW.ref.__gxx_personality_v0" section is invalid, the generated relocation may overlap the FDE length. Discard such relocation entries to avoid corrupting the .eh_frame data.
1 parent 50bcf68 commit 5ed881d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

lld/ELF/InputSection.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,33 @@ void InputSection::copyRelocations(Ctx &ctx, uint8_t *buf,
491491
p->setSymbolAndType(ctx.in.symTab->getSymbolIndex(sym), type,
492492
ctx.arg.isMips64EL);
493493

494+
// Discard the invalid pieces among those named "DW.ref.__gxx_personality_v0".
495+
StringRef symName = sym.getName();
496+
if (symName == "DW.ref.__gxx_personality_v0") {
497+
if (auto *es = dyn_cast<EhInputSection>(sec)) {
498+
auto it = partition_point(es->fdes, [=](EhSectionPiece p) {
499+
return p.inputOff <= rel.offset;
500+
});
501+
502+
if (it == es->fdes.begin() ||
503+
it[-1].inputOff + it[-1].size <= rel.offset) {
504+
it = partition_point(es->cies, [=](EhSectionPiece p) {
505+
return p.inputOff <= rel.offset;
506+
});
507+
if (it == es->cies.begin()) {
508+
// invalid piece
509+
p->setSymbolAndType(0, 0, false);
510+
continue;
511+
}
512+
}
513+
514+
if (it[-1].outputOff == -1) {
515+
p->setSymbolAndType(0, 0, false);
516+
continue;
517+
}
518+
}
519+
}
520+
494521
if (sym.type == STT_SECTION) {
495522
// We combine multiple section symbols into only one per
496523
// section. This means we have to update the addend. That is

0 commit comments

Comments
 (0)