Skip to content

Commit a248ec3

Browse files
committed
Revert "[ELF] Move InStruct into Ctx. NFC"
The define breaks `std::in`. https://lab.llvm.org/buildbot/#/builders/169/builds/3253 This reverts commit 2531b46.
1 parent ffc80de commit a248ec3

File tree

5 files changed

+47
-67
lines changed

5 files changed

+47
-67
lines changed

lld/ELF/Config.h

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,6 @@ class TargetInfo;
5151
struct Partition;
5252
struct PhdrEntry;
5353

54-
class BssSection;
55-
class GdbIndexSection;
56-
class GotPltSection;
57-
class GotSection;
58-
class IBTPltSection;
59-
class IgotPltSection;
60-
class InputSection;
61-
class IpltSection;
62-
class MipsGotSection;
63-
class MipsRldMapSection;
64-
class PPC32Got2Section;
65-
class PPC64LongBranchTargetSection;
66-
class PltSection;
67-
class RelocationBaseSection;
68-
class RelroPaddingSection;
69-
class StringTableSection;
70-
class SymbolTableBaseSection;
71-
class SymtabShndxSection;
72-
class SyntheticSection;
73-
7454
enum ELFKind : uint8_t {
7555
ELFNoneKind,
7656
ELF32LEKind,
@@ -503,42 +483,6 @@ struct DuplicateSymbol {
503483
uint64_t value;
504484
};
505485

506-
// Linker generated sections which can be used as inputs and are not specific to
507-
// a partition.
508-
struct InStruct {
509-
std::unique_ptr<InputSection> attributes;
510-
std::unique_ptr<SyntheticSection> riscvAttributes;
511-
std::unique_ptr<BssSection> bss;
512-
std::unique_ptr<BssSection> bssRelRo;
513-
std::unique_ptr<GotSection> got;
514-
std::unique_ptr<GotPltSection> gotPlt;
515-
std::unique_ptr<IgotPltSection> igotPlt;
516-
std::unique_ptr<RelroPaddingSection> relroPadding;
517-
std::unique_ptr<SyntheticSection> armCmseSGSection;
518-
std::unique_ptr<PPC64LongBranchTargetSection> ppc64LongBranchTarget;
519-
std::unique_ptr<SyntheticSection> mipsAbiFlags;
520-
std::unique_ptr<MipsGotSection> mipsGot;
521-
std::unique_ptr<SyntheticSection> mipsOptions;
522-
std::unique_ptr<SyntheticSection> mipsReginfo;
523-
std::unique_ptr<MipsRldMapSection> mipsRldMap;
524-
std::unique_ptr<SyntheticSection> partEnd;
525-
std::unique_ptr<SyntheticSection> partIndex;
526-
std::unique_ptr<PltSection> plt;
527-
std::unique_ptr<IpltSection> iplt;
528-
std::unique_ptr<PPC32Got2Section> ppc32Got2;
529-
std::unique_ptr<IBTPltSection> ibtPlt;
530-
std::unique_ptr<RelocationBaseSection> relaPlt;
531-
// Non-SHF_ALLOC sections
532-
std::unique_ptr<SyntheticSection> debugNames;
533-
std::unique_ptr<GdbIndexSection> gdbIndex;
534-
std::unique_ptr<StringTableSection> shStrTab;
535-
std::unique_ptr<StringTableSection> strTab;
536-
std::unique_ptr<SymbolTableBaseSection> symTab;
537-
std::unique_ptr<SymtabShndxSection> symTabShndx;
538-
539-
void reset();
540-
};
541-
542486
struct Ctx {
543487
LinkerDriver driver;
544488
LinkerScript *script;
@@ -560,8 +504,6 @@ struct Ctx {
560504
SmallVector<OutputSection *, 0> outputSections;
561505
std::vector<Partition> partitions;
562506

563-
InStruct sec;
564-
565507
// Some linker-generated symbols need to be created as
566508
// Defined symbols.
567509
struct ElfSym {

lld/ELF/Driver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ void Ctx::reset() {
103103
outputSections.clear();
104104
partitions.clear();
105105

106-
in.reset();
107106
sym = ElfSym{};
108107

109108
memoryBuffers.clear();
@@ -153,6 +152,8 @@ bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
153152
elf::ctx.partitions.emplace_back();
154153
symtab = SymbolTable();
155154

155+
in.reset();
156+
156157
SharedFile::vernauxNum = 0;
157158
};
158159
ctx->e.logName = args::getFilenameWithoutExe(args[0]);

lld/ELF/OutputSections.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "llvm/Support/Parallel.h"
2323
#include "llvm/Support/Path.h"
2424
#include "llvm/Support/TimeProfiler.h"
25-
#undef in
2625
#if LLVM_ENABLE_ZLIB
2726
// Avoid introducing max as a macro from Windows headers.
2827
#define NOMINMAX
@@ -585,15 +584,15 @@ void OutputSection::writeTo(uint8_t *buf, parallel::TaskGroup &tg) {
585584
static void finalizeShtGroup(OutputSection *os, InputSection *section) {
586585
// sh_link field for SHT_GROUP sections should contain the section index of
587586
// the symbol table.
588-
os->link = ctx.sec.symTab->getParent()->sectionIndex;
587+
os->link = in.symTab->getParent()->sectionIndex;
589588

590589
if (!section)
591590
return;
592591

593592
// sh_info then contain index of an entry in symbol table section which
594593
// provides signature of the section group.
595594
ArrayRef<Symbol *> symbols = section->file->getSymbols();
596-
os->info = ctx.sec.symTab->getSymbolIndex(*symbols[section->info]);
595+
os->info = in.symTab->getSymbolIndex(*symbols[section->info]);
597596

598597
// Some group members may be combined or discarded, so we need to compute the
599598
// new size. The content will be rewritten in InputSection::copyShtGroup.
@@ -611,7 +610,7 @@ encodeOneCrel(raw_svector_ostream &os, Elf_Crel<sizeof(uint) == 8> &out,
611610
uint offset, const Symbol &sym, uint32_t type, uint addend) {
612611
const auto deltaOffset = static_cast<uint64_t>(offset - out.r_offset);
613612
out.r_offset = offset;
614-
int64_t symidx = ctx.sec.symTab->getSymbolIndex(sym);
613+
int64_t symidx = in.symTab->getSymbolIndex(sym);
615614
if (sym.type == STT_SECTION) {
616615
auto *d = dyn_cast<Defined>(&sym);
617616
if (d) {
@@ -732,7 +731,7 @@ void OutputSection::finalize() {
732731
if (!first || isa<SyntheticSection>(first))
733732
return;
734733

735-
link = ctx.sec.symTab->getParent()->sectionIndex;
734+
link = in.symTab->getParent()->sectionIndex;
736735
// sh_info for SHT_REL[A] sections should contain the section header index of
737736
// the section to which the relocation applies.
738737
InputSectionBase *s = first->getRelocatedSection();
@@ -882,8 +881,8 @@ void OutputSection::checkDynRelAddends(const uint8_t *bufStart) {
882881
// Some targets have NOBITS synthetic sections with dynamic relocations
883882
// with non-zero addends. Skip such sections.
884883
if (is_contained({EM_PPC, EM_PPC64}, config->emachine) &&
885-
(rel.inputSec == ctx.sec.ppc64LongBranchTarget.get() ||
886-
rel.inputSec == ctx.sec.igotPlt.get()))
884+
(rel.inputSec == in.ppc64LongBranchTarget.get() ||
885+
rel.inputSec == in.igotPlt.get()))
887886
continue;
888887
const uint8_t *relocTarget =
889888
bufStart + relOsec->offset + rel.inputSec->getOffset(rel.offsetInSec);

lld/ELF/SyntheticSections.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4926,6 +4926,8 @@ template <class ELFT> void elf::createSyntheticSections() {
49264926
add(*in.strTab);
49274927
}
49284928

4929+
InStruct elf::in;
4930+
49294931
template void elf::splitSections<ELF32LE>();
49304932
template void elf::splitSections<ELF32BE>();
49314933
template void elf::splitSections<ELF64LE>();

lld/ELF/SyntheticSections.h

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1479,7 +1479,43 @@ inline Partition &SectionBase::getPartition() const {
14791479
return ctx.partitions[partition - 1];
14801480
}
14811481

1482-
#define in ctx.sec
1482+
// Linker generated sections which can be used as inputs and are not specific to
1483+
// a partition.
1484+
struct InStruct {
1485+
std::unique_ptr<InputSection> attributes;
1486+
std::unique_ptr<SyntheticSection> riscvAttributes;
1487+
std::unique_ptr<BssSection> bss;
1488+
std::unique_ptr<BssSection> bssRelRo;
1489+
std::unique_ptr<GotSection> got;
1490+
std::unique_ptr<GotPltSection> gotPlt;
1491+
std::unique_ptr<IgotPltSection> igotPlt;
1492+
std::unique_ptr<RelroPaddingSection> relroPadding;
1493+
std::unique_ptr<SyntheticSection> armCmseSGSection;
1494+
std::unique_ptr<PPC64LongBranchTargetSection> ppc64LongBranchTarget;
1495+
std::unique_ptr<SyntheticSection> mipsAbiFlags;
1496+
std::unique_ptr<MipsGotSection> mipsGot;
1497+
std::unique_ptr<SyntheticSection> mipsOptions;
1498+
std::unique_ptr<SyntheticSection> mipsReginfo;
1499+
std::unique_ptr<MipsRldMapSection> mipsRldMap;
1500+
std::unique_ptr<SyntheticSection> partEnd;
1501+
std::unique_ptr<SyntheticSection> partIndex;
1502+
std::unique_ptr<PltSection> plt;
1503+
std::unique_ptr<IpltSection> iplt;
1504+
std::unique_ptr<PPC32Got2Section> ppc32Got2;
1505+
std::unique_ptr<IBTPltSection> ibtPlt;
1506+
std::unique_ptr<RelocationBaseSection> relaPlt;
1507+
// Non-SHF_ALLOC sections
1508+
std::unique_ptr<SyntheticSection> debugNames;
1509+
std::unique_ptr<GdbIndexSection> gdbIndex;
1510+
std::unique_ptr<StringTableSection> shStrTab;
1511+
std::unique_ptr<StringTableSection> strTab;
1512+
std::unique_ptr<SymbolTableBaseSection> symTab;
1513+
std::unique_ptr<SymtabShndxSection> symTabShndx;
1514+
1515+
void reset();
1516+
};
1517+
1518+
LLVM_LIBRARY_VISIBILITY extern InStruct in;
14831519

14841520
} // namespace lld::elf
14851521

0 commit comments

Comments
 (0)