[lld] 94ca041 - [ELF] Move scanRelocations into Relocations.cpp. NFC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 4 21:31:25 PDT 2022


Author: Fangrui Song
Date: 2022-09-04T21:31:18-07:00
New Revision: 94ca04190573908a811248559668a9b42b537ec1

URL: https://github.com/llvm/llvm-project/commit/94ca04190573908a811248559668a9b42b537ec1
DIFF: https://github.com/llvm/llvm-project/commit/94ca04190573908a811248559668a9b42b537ec1.diff

LOG: [ELF] Move scanRelocations into Relocations.cpp. NFC

Added: 
    

Modified: 
    lld/ELF/Relocations.cpp
    lld/ELF/Relocations.h
    lld/ELF/Writer.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 4398c0df0b06..1e9f789e1669 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -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>();

diff  --git a/lld/ELF/Relocations.h b/lld/ELF/Relocations.h
index 6e427b355f7d..29e3edeca6be 100644
--- a/lld/ELF/Relocations.h
+++ b/lld/ELF/Relocations.h
@@ -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();
 

diff  --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 6ec9fc704093..de6c19863daf 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -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();
     }


        


More information about the llvm-commits mailing list