[ELF] Move scanRelocations into Relocations.cpp. NFC

This commit is contained in:
Fangrui Song 2022-09-04 21:31:18 -07:00
parent c8d9d0000b
commit 94ca041905
3 changed files with 24 additions and 21 deletions

View File

@ -1516,7 +1516,7 @@ void RelocationScanner::scan(ArrayRef<RelTy> rels) {
});
}
template <class ELFT> void elf::scanRelocations(InputSectionBase &s) {
template <class ELFT> static void scanSection(InputSectionBase &s) {
RelocationScanner scanner(s);
const RelsOrRelas<ELFT> rels = s.template relsOrRelas<ELFT>();
if (rels.areRelocsRel())
@ -1525,6 +1525,23 @@ template <class ELFT> void elf::scanRelocations(InputSectionBase &s) {
scanner.template scan<ELFT>(rels.relas);
}
template <class ELFT> void elf::scanRelocations() {
// Scan all relocations. Each relocation goes through a series of tests to
// determine if it needs special treatment, such as creating GOT, PLT,
// copy relocations, etc. Note that relocations for non-alloc sections are
// directly processed by InputSection::relocateNonAlloc.
for (InputSectionBase *sec : inputSections)
if (sec->isLive() && (sec->flags & SHF_ALLOC))
scanSection<ELFT>(*sec);
for (Partition &part : partitions) {
for (EhInputSection *sec : part.ehFrame->sections)
scanSection<ELFT>(*sec);
if (part.armExidx && part.armExidx->isLive())
for (InputSection *sec : part.armExidx->exidxSections)
scanSection<ELFT>(*sec);
}
}
static bool handleNonPreemptibleIfunc(Symbol &sym) {
// Handle a reference to a non-preemptible ifunc. These are special in a
// few ways:
@ -2232,7 +2249,7 @@ void elf::hexagonTLSSymbolUpdate(ArrayRef<OutputSection *> outputSections) {
});
}
template void elf::scanRelocations<ELF32LE>(InputSectionBase &);
template void elf::scanRelocations<ELF32BE>(InputSectionBase &);
template void elf::scanRelocations<ELF64LE>(InputSectionBase &);
template void elf::scanRelocations<ELF64BE>(InputSectionBase &);
template void elf::scanRelocations<ELF32LE>();
template void elf::scanRelocations<ELF32BE>();
template void elf::scanRelocations<ELF64LE>();
template void elf::scanRelocations<ELF64BE>();

View File

@ -125,7 +125,7 @@ struct JumpInstrMod {
// This function writes undefined symbol diagnostics to an internal buffer.
// Call reportUndefinedSymbols() after calling scanRelocations() to emit
// the diagnostics.
template <class ELFT> void scanRelocations(InputSectionBase &);
template <class ELFT> void scanRelocations();
void reportUndefinedSymbols();
void postScanRelocations();

View File

@ -1908,21 +1908,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
// a linker-script-defined symbol is absolute.
ppc64noTocRelax.clear();
if (!config->relocatable) {
// Scan all relocations. Each relocation goes through a series of tests to
// determine if it needs special treatment, such as creating GOT, PLT,
// copy relocations, etc. Note that relocations for non-alloc sections are
// directly processed by InputSection::relocateNonAlloc.
for (InputSectionBase *sec : inputSections)
if (sec->isLive() && (sec->flags & SHF_ALLOC))
scanRelocations<ELFT>(*sec);
for (Partition &part : partitions) {
for (EhInputSection *sec : part.ehFrame->sections)
scanRelocations<ELFT>(*sec);
if (part.armExidx && part.armExidx->isLive())
for (InputSection *sec : part.armExidx->exidxSections)
scanRelocations<ELFT>(*sec);
}
scanRelocations<ELFT>();
reportUndefinedSymbols();
postScanRelocations();
}