Skip to content

Commit 2fe3bbd

Browse files
committed
[ELF] Move outputSections into Ctx. NFC
Ctx was introduced in March 2022 as a more suitable place for such singletons.
1 parent 03be619 commit 2fe3bbd

13 files changed

+62
-64
lines changed

lld/ELF/AArch64ErrataFix.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ bool AArch64Err843419Patcher::createFixes() {
625625
init();
626626

627627
bool addressesChanged = false;
628-
for (OutputSection *os : outputSections) {
628+
for (OutputSection *os : ctx.outputSections) {
629629
if (!(os->flags & SHF_ALLOC) || !(os->flags & SHF_EXECINSTR))
630630
continue;
631631
for (SectionCommand *cmd : os->commands)

lld/ELF/ARMErrataFix.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ bool ARMErr657417Patcher::createFixes() {
518518
init();
519519

520520
bool addressesChanged = false;
521-
for (OutputSection *os : outputSections) {
521+
for (OutputSection *os : ctx.outputSections) {
522522
if (!(os->flags & SHF_ALLOC) || !(os->flags & SHF_EXECINSTR))
523523
continue;
524524
for (SectionCommand *cmd : os->commands)

lld/ELF/Arch/LoongArch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ bool LoongArch::relaxOnce(int pass) const {
828828

829829
SmallVector<InputSection *, 0> storage;
830830
bool changed = false;
831-
for (OutputSection *osec : outputSections) {
831+
for (OutputSection *osec : ctx.outputSections) {
832832
if (!(osec->flags & SHF_EXECINSTR))
833833
continue;
834834
for (InputSection *sec : getInputSections(*osec, storage))
@@ -840,7 +840,7 @@ bool LoongArch::relaxOnce(int pass) const {
840840
void LoongArch::finalizeRelax(int passes) const {
841841
log("relaxation passes: " + Twine(passes));
842842
SmallVector<InputSection *, 0> storage;
843-
for (OutputSection *osec : outputSections) {
843+
for (OutputSection *osec : ctx.outputSections) {
844844
if (!(osec->flags & SHF_EXECINSTR))
845845
continue;
846846
for (InputSection *sec : getInputSections(*osec, storage)) {

lld/ELF/Arch/RISCV.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ void RISCV::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const {
680680

681681
void elf::initSymbolAnchors() {
682682
SmallVector<InputSection *, 0> storage;
683-
for (OutputSection *osec : outputSections) {
683+
for (OutputSection *osec : ctx.outputSections) {
684684
if (!(osec->flags & SHF_EXECINSTR))
685685
continue;
686686
for (InputSection *sec : getInputSections(*osec, storage)) {
@@ -719,7 +719,7 @@ void elf::initSymbolAnchors() {
719719
// efficiently. For a zero size symbol, ensure that its start anchor precedes
720720
// its end anchor. For two symbols with anchors at the same offset, their
721721
// order does not matter.
722-
for (OutputSection *osec : outputSections) {
722+
for (OutputSection *osec : ctx.outputSections) {
723723
if (!(osec->flags & SHF_EXECINSTR))
724724
continue;
725725
for (InputSection *sec : getInputSections(*osec, storage)) {
@@ -922,7 +922,7 @@ bool RISCV::relaxOnce(int pass) const {
922922

923923
SmallVector<InputSection *, 0> storage;
924924
bool changed = false;
925-
for (OutputSection *osec : outputSections) {
925+
for (OutputSection *osec : ctx.outputSections) {
926926
if (!(osec->flags & SHF_EXECINSTR))
927927
continue;
928928
for (InputSection *sec : getInputSections(*osec, storage))
@@ -935,7 +935,7 @@ void RISCV::finalizeRelax(int passes) const {
935935
llvm::TimeTraceScope timeScope("Finalize RISC-V relaxation");
936936
log("relaxation passes: " + Twine(passes));
937937
SmallVector<InputSection *, 0> storage;
938-
for (OutputSection *osec : outputSections) {
938+
for (OutputSection *osec : ctx.outputSections) {
939939
if (!(osec->flags & SHF_EXECINSTR))
940940
continue;
941941
for (InputSection *sec : getInputSections(*osec, storage)) {

lld/ELF/Arch/SystemZ.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ bool SystemZ::relaxOnce(int pass) const {
438438
// we need to validate the target symbol is in-range and aligned.
439439
SmallVector<InputSection *, 0> storage;
440440
bool changed = false;
441-
for (OutputSection *osec : outputSections) {
441+
for (OutputSection *osec : ctx.outputSections) {
442442
if (!(osec->flags & SHF_EXECINSTR))
443443
continue;
444444
for (InputSection *sec : getInputSections(*osec, storage)) {

lld/ELF/Arch/X86_64.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ bool X86_64::deleteFallThruJmpInsn(InputSection &is, InputFile *file,
310310

311311
bool X86_64::relaxOnce(int pass) const {
312312
uint64_t minVA = UINT64_MAX, maxVA = 0;
313-
for (OutputSection *osec : outputSections) {
313+
for (OutputSection *osec : ctx.outputSections) {
314314
minVA = std::min(minVA, osec->addr);
315315
maxVA = std::max(maxVA, osec->addr + osec->size);
316316
}
@@ -322,7 +322,7 @@ bool X86_64::relaxOnce(int pass) const {
322322

323323
SmallVector<InputSection *, 0> storage;
324324
bool changed = false;
325-
for (OutputSection *osec : outputSections) {
325+
for (OutputSection *osec : ctx.outputSections) {
326326
if (!(osec->flags & SHF_EXECINSTR))
327327
continue;
328328
for (InputSection *sec : getInputSections(*osec, storage)) {

lld/ELF/Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ struct Ctx {
494494
OutputSection *finiArray;
495495
};
496496
OutSections out;
497+
SmallVector<OutputSection *, 0> outputSections;
497498

498499
// Some linker-generated symbols need to be created as
499500
// Defined symbols.

lld/ELF/Driver.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ void Ctx::reset() {
9797
bufferStart = nullptr;
9898
tlsPhdr = nullptr;
9999
out = OutSections{};
100+
outputSections.clear();
100101

101102
sym = ElfSym{};
102103

@@ -145,8 +146,6 @@ bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
145146
elf::ctx.reset();
146147
symtab = SymbolTable();
147148

148-
outputSections.clear();
149-
150149
in.reset();
151150

152151
partitions.clear();

lld/ELF/LinkerScript.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ LinkerScript::findMemoryRegion(OutputSection *sec, MemoryRegion *hint) {
10201020
}
10211021

10221022
static OutputSection *findFirstSection(PhdrEntry *load) {
1023-
for (OutputSection *sec : outputSections)
1023+
for (OutputSection *sec : ctx.outputSections)
10241024
if (sec->ptLoad == load)
10251025
return sec;
10261026
return nullptr;
@@ -1340,7 +1340,7 @@ static uint64_t computeBase(uint64_t min, bool allocateHeaders) {
13401340
// and we'll also remove the PT_PHDR segment.
13411341
void LinkerScript::allocateHeaders(SmallVector<PhdrEntry *, 0> &phdrs) {
13421342
uint64_t min = std::numeric_limits<uint64_t>::max();
1343-
for (OutputSection *sec : outputSections)
1343+
for (OutputSection *sec : ctx.outputSections)
13441344
if (sec->flags & SHF_ALLOC)
13451345
min = std::min<uint64_t>(min, sec->addr);
13461346

@@ -1555,7 +1555,7 @@ SmallVector<PhdrEntry *, 0> LinkerScript::createPhdrs() {
15551555
}
15561556

15571557
// Add output sections to program headers.
1558-
for (OutputSection *sec : outputSections) {
1558+
for (OutputSection *sec : ctx.outputSections) {
15591559
// Assign headers specified by linker script
15601560
for (size_t id : getPhdrIndices(sec)) {
15611561
ret[id]->add(sec);
@@ -1676,7 +1676,7 @@ static void checkMemoryRegion(const MemoryRegion *region,
16761676
void LinkerScript::checkFinalScriptConditions() const {
16771677
for (StringRef err : recordedErrors)
16781678
errorOrWarn(err);
1679-
for (const OutputSection *sec : outputSections) {
1679+
for (const OutputSection *sec : ctx.outputSections) {
16801680
if (const MemoryRegion *memoryRegion = sec->memRegion)
16811681
checkMemoryRegion(memoryRegion, sec, sec->addr);
16821682
if (const MemoryRegion *lmaRegion = sec->lmaRegion)

lld/ELF/OutputSections.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ using namespace llvm::ELF;
3939
using namespace lld;
4040
using namespace lld::elf;
4141

42-
SmallVector<OutputSection *, 0> elf::outputSections;
43-
4442
uint32_t OutputSection::getPhdrFlags() const {
4543
uint32_t ret = 0;
4644
if (config->emachine != EM_ARM || !(flags & SHF_ARM_PURECODE))

lld/ELF/OutputSections.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,6 @@ getInputSections(const OutputSection &os,
151151
SmallVector<InputSection *, 0> &storage);
152152

153153
uint64_t getHeaderSize();
154-
155-
LLVM_LIBRARY_VISIBILITY extern llvm::SmallVector<OutputSection *, 0>
156-
outputSections;
157154
} // namespace lld::elf
158155

159156
#endif

lld/ELF/Relocations.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2414,7 +2414,7 @@ static void scanCrossRefs(const NoCrossRefCommand &cmd, OutputSection *osec,
24142414
// For each output section described by at least one NOCROSSREFS(_TO) command,
24152415
// scan relocations from its input sections for prohibited cross references.
24162416
template <class ELFT> void elf::checkNoCrossRefs() {
2417-
for (OutputSection *osec : outputSections) {
2417+
for (OutputSection *osec : ctx.outputSections) {
24182418
for (const NoCrossRefCommand &noxref : script->noCrossRefs) {
24192419
if (!llvm::is_contained(noxref.outputSections, osec->name) ||
24202420
(noxref.toFirst && noxref.outputSections[0] == osec->name))

0 commit comments

Comments
 (0)