[ELF] Simplify addCopyRelSymbol with invokeELFT. NFC

This commit is contained in:
Fangrui Song 2022-03-12 14:08:10 -08:00
parent 9106a07f1f
commit 7b8fbb796c

View File

@ -351,7 +351,7 @@ static void replaceWithDefined(Symbol &sym, SectionBase &sec, uint64_t value,
// to the variable in .bss. This kind of issue is sometimes very hard to
// debug. What's a solution? Instead of exporting a variable V from a DSO,
// define an accessor getV().
template <class ELFT> static void addCopyRelSymbolImpl(SharedSymbol &ss) {
template <class ELFT> static void addCopyRelSymbol(SharedSymbol &ss) {
// Copy relocation against zero-sized symbol doesn't make sense.
uint64_t symSize = ss.getSize();
if (symSize == 0 || ss.alignment == 0)
@ -382,26 +382,6 @@ template <class ELFT> static void addCopyRelSymbolImpl(SharedSymbol &ss) {
mainPart->relaDyn->addSymbolReloc(target->copyRel, *sec, 0, ss);
}
static void addCopyRelSymbol(SharedSymbol &ss) {
const auto &file = cast<SharedFile>(*ss.file);
switch (file.ekind) {
case ELF32LEKind:
addCopyRelSymbolImpl<ELF32LE>(ss);
break;
case ELF32BEKind:
addCopyRelSymbolImpl<ELF32BE>(ss);
break;
case ELF64LEKind:
addCopyRelSymbolImpl<ELF64LE>(ss);
break;
case ELF64BEKind:
addCopyRelSymbolImpl<ELF64BE>(ss);
break;
default:
llvm_unreachable("");
}
}
// .eh_frame sections are mergeable input sections, so their input
// offsets are not linearly mapped to output section. For each input
// offset, we need to find a section piece containing the offset and
@ -1622,7 +1602,7 @@ void elf::postScanRelocations() {
addPltEntry(*in.plt, *in.gotPlt, *in.relaPlt, target->pltRel, sym);
if (sym.needsCopy) {
if (sym.isObject()) {
addCopyRelSymbol(cast<SharedSymbol>(sym));
invokeELFT(addCopyRelSymbol, cast<SharedSymbol>(sym));
// needsCopy is cleared for sym and its aliases so that in later
// iterations aliases won't cause redundant copies.
assert(!sym.needsCopy);