[lld] 53a1fb0 - [ELF] Pass Ctx &

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 5 09:37:34 PDT 2024


Author: Fangrui Song
Date: 2024-10-05T09:37:27-07:00
New Revision: 53a1fb0cd73382498fe79f95521c350409fd40b9

URL: https://github.com/llvm/llvm-project/commit/53a1fb0cd73382498fe79f95521c350409fd40b9
DIFF: https://github.com/llvm/llvm-project/commit/53a1fb0cd73382498fe79f95521c350409fd40b9.diff

LOG: [ELF] Pass Ctx &

Added: 
    

Modified: 
    lld/ELF/AArch64ErrataFix.h
    lld/ELF/InputSection.cpp
    lld/ELF/Writer.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/AArch64ErrataFix.h b/lld/ELF/AArch64ErrataFix.h
index fa34beb5d7a84c..cab0b043369828 100644
--- a/lld/ELF/AArch64ErrataFix.h
+++ b/lld/ELF/AArch64ErrataFix.h
@@ -14,7 +14,7 @@
 #include <vector>
 
 namespace lld::elf {
-
+struct Ctx;
 class Defined;
 class InputSection;
 class InputSectionDescription;
@@ -22,6 +22,7 @@ class Patch843419Section;
 
 class AArch64Err843419Patcher {
 public:
+  AArch64Err843419Patcher(Ctx &ctx) : ctx(ctx) {}
   // return true if Patches have been added to the OutputSections.
   bool createFixes();
 
@@ -34,6 +35,7 @@ class AArch64Err843419Patcher {
 
   void init();
 
+  Ctx &ctx;
   // A cache of the mapping symbols defined by the InputSection sorted in order
   // of ascending value with redundant symbols removed. These describe
   // the ranges of code and data in an executable InputSection.

diff  --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 7c8da8944e502e..eb6de90a02f661 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -77,7 +77,7 @@ InputSectionBase::InputSectionBase(InputFile *file, uint64_t flags,
 // SHF_INFO_LINK and SHF_GROUP are normally resolved and not copied to the
 // output section. However, for relocatable linking without
 // --force-group-allocation, the SHF_GROUP flag and section groups are retained.
-static uint64_t getFlags(uint64_t flags) {
+static uint64_t getFlags(Ctx &ctx, uint64_t flags) {
   flags &= ~(uint64_t)SHF_INFO_LINK;
   if (ctx.arg.resolveGroups)
     flags &= ~(uint64_t)SHF_GROUP;
@@ -88,7 +88,7 @@ template <class ELFT>
 InputSectionBase::InputSectionBase(ObjFile<ELFT> &file,
                                    const typename ELFT::Shdr &hdr,
                                    StringRef name, Kind sectionKind)
-    : InputSectionBase(&file, getFlags(hdr.sh_flags), hdr.sh_type,
+    : InputSectionBase(&file, getFlags(ctx, hdr.sh_flags), hdr.sh_type,
                        hdr.sh_entsize, hdr.sh_link, hdr.sh_info,
                        hdr.sh_addralign, getSectionContents(file, hdr), name,
                        sectionKind) {

diff  --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index c413ebd349e6d3..c922d0366ae660 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -1424,7 +1424,7 @@ template <class ELFT> void Writer<ELFT>::resolveShfLinkOrder() {
   }
 }
 
-static void finalizeSynthetic(SyntheticSection *sec) {
+static void finalizeSynthetic(Ctx &ctx, SyntheticSection *sec) {
   if (sec && sec->isNeeded() && sec->getParent()) {
     llvm::TimeTraceScope timeScope("Finalize synthetic sections", sec->name);
     sec->finalizeContents(ctx);
@@ -1438,7 +1438,7 @@ static void finalizeSynthetic(SyntheticSection *sec) {
 template <class ELFT> void Writer<ELFT>::finalizeAddressDependentContent() {
   llvm::TimeTraceScope timeScope("Finalize address dependent content");
   ThunkCreator tc(ctx);
-  AArch64Err843419Patcher a64p;
+  AArch64Err843419Patcher a64p(ctx);
   ARMErr657417Patcher a32p;
   ctx.script->assignAddresses();
 
@@ -1449,7 +1449,7 @@ template <class ELFT> void Writer<ELFT>::finalizeAddressDependentContent() {
   // section order.
   const auto finalizeOrderDependentContent = [this] {
     for (Partition &part : ctx.partitions)
-      finalizeSynthetic(part.armExidx.get());
+      finalizeSynthetic(ctx, part.armExidx.get());
     resolveShfLinkOrder();
   };
   finalizeOrderDependentContent();
@@ -1486,7 +1486,7 @@ template <class ELFT> void Writer<ELFT>::finalizeAddressDependentContent() {
       changed |= a32p.createFixes();
     }
 
-    finalizeSynthetic(ctx.in.got.get());
+    finalizeSynthetic(ctx, ctx.in.got.get());
     if (ctx.in.mipsGot)
       ctx.in.mipsGot->updateAllocSize();
 
@@ -1783,7 +1783,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
     {
       llvm::TimeTraceScope timeScope("Finalize .eh_frame");
       for (Partition &part : ctx.partitions)
-        finalizeSynthetic(part.ehFrame.get());
+        finalizeSynthetic(ctx, part.ehFrame.get());
     }
   }
 
@@ -1983,20 +1983,20 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
   {
     llvm::TimeTraceScope timeScope("Finalize synthetic sections");
 
-    finalizeSynthetic(ctx.in.bss.get());
-    finalizeSynthetic(ctx.in.bssRelRo.get());
-    finalizeSynthetic(ctx.in.symTabShndx.get());
-    finalizeSynthetic(ctx.in.shStrTab.get());
-    finalizeSynthetic(ctx.in.strTab.get());
-    finalizeSynthetic(ctx.in.got.get());
-    finalizeSynthetic(ctx.in.mipsGot.get());
-    finalizeSynthetic(ctx.in.igotPlt.get());
-    finalizeSynthetic(ctx.in.gotPlt.get());
-    finalizeSynthetic(ctx.in.relaPlt.get());
-    finalizeSynthetic(ctx.in.plt.get());
-    finalizeSynthetic(ctx.in.iplt.get());
-    finalizeSynthetic(ctx.in.ppc32Got2.get());
-    finalizeSynthetic(ctx.in.partIndex.get());
+    finalizeSynthetic(ctx, ctx.in.bss.get());
+    finalizeSynthetic(ctx, ctx.in.bssRelRo.get());
+    finalizeSynthetic(ctx, ctx.in.symTabShndx.get());
+    finalizeSynthetic(ctx, ctx.in.shStrTab.get());
+    finalizeSynthetic(ctx, ctx.in.strTab.get());
+    finalizeSynthetic(ctx, ctx.in.got.get());
+    finalizeSynthetic(ctx, ctx.in.mipsGot.get());
+    finalizeSynthetic(ctx, ctx.in.igotPlt.get());
+    finalizeSynthetic(ctx, ctx.in.gotPlt.get());
+    finalizeSynthetic(ctx, ctx.in.relaPlt.get());
+    finalizeSynthetic(ctx, ctx.in.plt.get());
+    finalizeSynthetic(ctx, ctx.in.iplt.get());
+    finalizeSynthetic(ctx, ctx.in.ppc32Got2.get());
+    finalizeSynthetic(ctx, ctx.in.partIndex.get());
 
     // Dynamic section must be the last one in this list and dynamic
     // symbol table section (dynSymTab) must be the first one.
@@ -2005,25 +2005,25 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
         part.relaDyn->mergeRels();
         // Compute DT_RELACOUNT to be used by part.dynamic.
         part.relaDyn->partitionRels();
-        finalizeSynthetic(part.relaDyn.get());
+        finalizeSynthetic(ctx, part.relaDyn.get());
       }
       if (part.relrDyn) {
         part.relrDyn->mergeRels();
-        finalizeSynthetic(part.relrDyn.get());
+        finalizeSynthetic(ctx, part.relrDyn.get());
       }
       if (part.relrAuthDyn) {
         part.relrAuthDyn->mergeRels();
-        finalizeSynthetic(part.relrAuthDyn.get());
+        finalizeSynthetic(ctx, part.relrAuthDyn.get());
       }
 
-      finalizeSynthetic(part.dynSymTab.get());
-      finalizeSynthetic(part.gnuHashTab.get());
-      finalizeSynthetic(part.hashTab.get());
-      finalizeSynthetic(part.verDef.get());
-      finalizeSynthetic(part.ehFrameHdr.get());
-      finalizeSynthetic(part.verSym.get());
-      finalizeSynthetic(part.verNeed.get());
-      finalizeSynthetic(part.dynamic.get());
+      finalizeSynthetic(ctx, part.dynSymTab.get());
+      finalizeSynthetic(ctx, part.gnuHashTab.get());
+      finalizeSynthetic(ctx, part.hashTab.get());
+      finalizeSynthetic(ctx, part.verDef.get());
+      finalizeSynthetic(ctx, part.ehFrameHdr.get());
+      finalizeSynthetic(ctx, part.verSym.get());
+      finalizeSynthetic(ctx, part.verNeed.get());
+      finalizeSynthetic(ctx, part.dynamic.get());
     }
   }
 
@@ -2061,10 +2061,10 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
     llvm::TimeTraceScope timeScope("Finalize synthetic sections");
     // finalizeAddressDependentContent may have added local symbols to the
     // static symbol table.
-    finalizeSynthetic(ctx.in.symTab.get());
-    finalizeSynthetic(ctx.in.debugNames.get());
-    finalizeSynthetic(ctx.in.ppc64LongBranchTarget.get());
-    finalizeSynthetic(ctx.in.armCmseSGSection.get());
+    finalizeSynthetic(ctx, ctx.in.symTab.get());
+    finalizeSynthetic(ctx, ctx.in.debugNames.get());
+    finalizeSynthetic(ctx, ctx.in.ppc64LongBranchTarget.get());
+    finalizeSynthetic(ctx, ctx.in.armCmseSGSection.get());
   }
 
   // Relaxation to delete inter-basic block jumps created by basic block


        


More information about the llvm-commits mailing list