[lld] e6625a2 - [ELF] Pass Ctx &

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 19 21:08:55 PDT 2024


Author: Fangrui Song
Date: 2024-10-19T21:08:50-07:00
New Revision: e6625a2c106f6af468a98323b08c7ce3cf273485

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

LOG: [ELF] Pass Ctx &

Added: 
    

Modified: 
    lld/ELF/Arch/RISCV.cpp
    lld/ELF/InputSection.cpp
    lld/ELF/MapFile.cpp
    lld/ELF/Symbols.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index 7ebb67c3612311..e80dfbd4351b1e 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -758,8 +758,8 @@ static void relaxCall(Ctx &ctx, const InputSection &sec, size_t i, uint64_t loc,
 }
 
 // Relax local-exec TLS when hi20 is zero.
-static void relaxTlsLe(const InputSection &sec, size_t i, uint64_t loc,
-                       Relocation &r, uint32_t &remove) {
+static void relaxTlsLe(Ctx &ctx, const InputSection &sec, size_t i,
+                       uint64_t loc, Relocation &r, uint32_t &remove) {
   uint64_t val = r.sym->getVA(ctx, r.addend);
   if (hi20(val) != 0)
     return;
@@ -852,7 +852,7 @@ static bool relax(Ctx &ctx, InputSection &sec) {
     case R_RISCV_TPREL_LO12_I:
     case R_RISCV_TPREL_LO12_S:
       if (relaxable(relocs, i))
-        relaxTlsLe(sec, i, loc, r, remove);
+        relaxTlsLe(ctx, sec, i, loc, r, remove);
       break;
     case R_RISCV_HI20:
     case R_RISCV_LO12_I:

diff  --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 6c34471a9e5022..3b48fbe07bb082 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -70,8 +70,10 @@ InputSectionBase::InputSectionBase(InputFile *file, uint64_t flags,
 
   // If SHF_COMPRESSED is set, parse the header. The legacy .zdebug format is no
   // longer supported.
-  if (flags & SHF_COMPRESSED)
+  if (flags & SHF_COMPRESSED) {
+    Ctx &ctx = file->ctx;
     invokeELFT(parseCompressedHeader,);
+  }
 }
 
 // SHF_INFO_LINK and SHF_GROUP are normally resolved and not copied to the

diff  --git a/lld/ELF/MapFile.cpp b/lld/ELF/MapFile.cpp
index 84bc95f9bd00ce..afaf04dc72fe6c 100644
--- a/lld/ELF/MapFile.cpp
+++ b/lld/ELF/MapFile.cpp
@@ -65,7 +65,7 @@ static std::vector<Defined *> getSymbols(Ctx &ctx) {
 }
 
 // Returns a map from sections to their symbols.
-static SymbolMapTy getSectionSyms(ArrayRef<Defined *> syms) {
+static SymbolMapTy getSectionSyms(Ctx &ctx, ArrayRef<Defined *> syms) {
   SymbolMapTy ret;
   for (Defined *dr : syms)
     ret[dr->section].emplace_back(dr, dr->getVA(ctx));
@@ -149,7 +149,7 @@ static void printEhFrame(Ctx &ctx, raw_ostream &os, const EhFrameSection *sec) {
 static void writeMapFile(Ctx &ctx, raw_fd_ostream &os) {
   // Collect symbol info that we want to print out.
   std::vector<Defined *> syms = getSymbols(ctx);
-  SymbolMapTy sectionSyms = getSectionSyms(syms);
+  SymbolMapTy sectionSyms = getSectionSyms(ctx, syms);
   DenseMap<Symbol *, std::string> symStr = getSymbolStrings(ctx, syms);
 
   // Print out the header line.

diff  --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index 6d9b3c839f86ae..da35bf858cb371 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -44,13 +44,13 @@ LLVM_ATTRIBUTE_UNUSED static inline void assertSymbols() {
 }
 
 // Returns a symbol for an error message.
-static std::string maybeDemangleSymbol(StringRef symName) {
-  return elf::ctx.arg.demangle ? demangle(symName.str()) : symName.str();
+static std::string maybeDemangleSymbol(Ctx &ctx, StringRef symName) {
+  return ctx.arg.demangle ? demangle(symName.str()) : symName.str();
 }
 
 std::string lld::toString(const elf::Symbol &sym) {
   StringRef name = sym.getName();
-  std::string ret = maybeDemangleSymbol(name);
+  std::string ret = maybeDemangleSymbol(ctx, name);
 
   const char *suffix = sym.getVersionSuffix();
   if (*suffix == '@')
@@ -617,7 +617,7 @@ void Symbol::resolve(Ctx &ctx, const LazySymbol &other) {
 
   // For common objects, we want to look for global or weak definitions that
   // should be extracted as the canonical definition instead.
-  if (LLVM_UNLIKELY(isCommon()) && elf::ctx.arg.fortranCommon &&
+  if (LLVM_UNLIKELY(isCommon()) && ctx.arg.fortranCommon &&
       other.file->shouldExtractForCommon(getName())) {
     ctx.backwardReferences.erase(this);
     other.overwrite(*this);


        


More information about the llvm-commits mailing list