[lld] 89b1468 - [ELF] Move ppc64noTocRelax to Ctx. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 21 00:10:36 PDT 2024
Author: Fangrui Song
Date: 2024-08-21T00:10:31-07:00
New Revision: 89b1468345a74d2095616a8be2306cf0b08fa43a
URL: https://github.com/llvm/llvm-project/commit/89b1468345a74d2095616a8be2306cf0b08fa43a
DIFF: https://github.com/llvm/llvm-project/commit/89b1468345a74d2095616a8be2306cf0b08fa43a.diff
LOG: [ELF] Move ppc64noTocRelax to Ctx. NFC
Ctx was introduced in March 2022 as a more suitable place for such
singletons.
Added:
Modified:
lld/ELF/Arch/PPC64.cpp
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/InputSection.cpp
lld/ELF/InputSection.h
lld/ELF/Relocations.cpp
lld/ELF/Writer.cpp
Removed:
################################################################################
diff --git a/lld/ELF/Arch/PPC64.cpp b/lld/ELF/Arch/PPC64.cpp
index 3188772f7c4904..753ced698a05c0 100644
--- a/lld/ELF/Arch/PPC64.cpp
+++ b/lld/ELF/Arch/PPC64.cpp
@@ -1593,7 +1593,7 @@ void PPC64::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const {
// entry, there may be R_PPC64_TOC16_HA not paired with
// R_PPC64_TOC16_LO_DS. Don't relax. This loses some relaxation
// opportunities but is safe.
- if (ppc64noTocRelax.count({rel.sym, rel.addend}) ||
+ if (ctx.ppc64noTocRelax.count({rel.sym, rel.addend}) ||
!tryRelaxPPC64TocIndirection(rel, loc))
relocate(loc, rel, val);
break;
diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index 0ddac5f6358781..035b385ba37ec3 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -582,6 +582,11 @@ struct Ctx {
unsigned scriptSymOrderCounter = 1;
llvm::DenseMap<const Symbol *, unsigned> scriptSymOrder;
+ // The set of TOC entries (.toc + addend) for which we should not apply
+ // toc-indirect to toc-relative relaxation. const Symbol * refers to the
+ // STT_SECTION symbol associated to the .toc input section.
+ llvm::DenseSet<std::pair<const Symbol *, uint64_t>> ppc64noTocRelax;
+
void reset();
llvm::raw_fd_ostream openAuxiliaryFile(llvm::StringRef, std::error_code &);
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 8aa2380ba3a177..36552e4bb035af 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -123,6 +123,7 @@ void Ctx::reset() {
needsTlsLd.store(false, std::memory_order_relaxed);
scriptSymOrderCounter = 1;
scriptSymOrder.clear();
+ ppc64noTocRelax.clear();
ltoAllVtablesHaveTypeInfos = false;
}
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index a7bb9bd47299e2..fd3e947428388b 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -34,8 +34,6 @@ using namespace llvm::sys;
using namespace lld;
using namespace lld::elf;
-DenseSet<std::pair<const Symbol *, uint64_t>> elf::ppc64noTocRelax;
-
// Returns a string to construct an error message.
std::string lld::toString(const InputSectionBase *sec) {
return (toString(sec->file) + ":(" + sec->name + ")").str();
diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h
index e3b7af13d066da..60c8d57b8db86a 100644
--- a/lld/ELF/InputSection.h
+++ b/lld/ELF/InputSection.h
@@ -498,12 +498,6 @@ inline bool isDebugSection(const InputSectionBase &sec) {
return (sec.flags & llvm::ELF::SHF_ALLOC) == 0 &&
sec.name.starts_with(".debug");
}
-
-// The set of TOC entries (.toc + addend) for which we should not apply
-// toc-indirect to toc-relative relaxation. const Symbol * refers to the
-// STT_SECTION symbol associated to the .toc input section.
-extern llvm::DenseSet<std::pair<const Symbol *, uint64_t>> ppc64noTocRelax;
-
} // namespace elf
std::string toString(const elf::InputSectionBase *);
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index b60b00cee4a602..9dbb4567495a81 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -1495,7 +1495,7 @@ void RelocationScanner::scanOne(typename Relocs<RelTy>::const_iterator &i) {
// InputSectionBase::relocateAlloc().
if (type == R_PPC64_TOC16_LO && sym.isSection() && isa<Defined>(sym) &&
cast<Defined>(sym).section->name == ".toc")
- ppc64noTocRelax.insert({&sym, addend});
+ ctx.ppc64noTocRelax.insert({&sym, addend});
if ((type == R_PPC64_TLSGD && expr == R_TLSDESC_CALL) ||
(type == R_PPC64_TLSLD && expr == R_TLSLD_HINT)) {
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 4c0b4df5bea170..82d9ea24d9bd3f 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -1800,7 +1800,6 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
// that we can correctly decide if a dynamic relocation is needed. This is
// called after processSymbolAssignments() because it needs to know whether
// a linker-script-defined symbol is absolute.
- ppc64noTocRelax.clear();
scanRelocations<ELFT>();
reportUndefinedSymbols();
postScanRelocations();
More information about the llvm-commits
mailing list