[lld] a248ec3 - Revert "[ELF] Move InStruct into Ctx. NFC"
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 15 18:22:54 PDT 2024
Author: Vitaly Buka
Date: 2024-09-15T18:22:42-07:00
New Revision: a248ec3178293d3df0ceb5c6501c2532a20339fd
URL: https://github.com/llvm/llvm-project/commit/a248ec3178293d3df0ceb5c6501c2532a20339fd
DIFF: https://github.com/llvm/llvm-project/commit/a248ec3178293d3df0ceb5c6501c2532a20339fd.diff
LOG: Revert "[ELF] Move InStruct into Ctx. NFC"
The define breaks `std::in`.
https://lab.llvm.org/buildbot/#/builders/169/builds/3253
This reverts commit 2531b46264cd066d51f2571d134a63998d13710f.
Added:
Modified:
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/OutputSections.cpp
lld/ELF/SyntheticSections.cpp
lld/ELF/SyntheticSections.h
Removed:
################################################################################
diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index c9d2ec1d60cbd7..639bf9a4f22840 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -51,26 +51,6 @@ class TargetInfo;
struct Partition;
struct PhdrEntry;
-class BssSection;
-class GdbIndexSection;
-class GotPltSection;
-class GotSection;
-class IBTPltSection;
-class IgotPltSection;
-class InputSection;
-class IpltSection;
-class MipsGotSection;
-class MipsRldMapSection;
-class PPC32Got2Section;
-class PPC64LongBranchTargetSection;
-class PltSection;
-class RelocationBaseSection;
-class RelroPaddingSection;
-class StringTableSection;
-class SymbolTableBaseSection;
-class SymtabShndxSection;
-class SyntheticSection;
-
enum ELFKind : uint8_t {
ELFNoneKind,
ELF32LEKind,
@@ -503,42 +483,6 @@ struct DuplicateSymbol {
uint64_t value;
};
-// Linker generated sections which can be used as inputs and are not specific to
-// a partition.
-struct InStruct {
- std::unique_ptr<InputSection> attributes;
- std::unique_ptr<SyntheticSection> riscvAttributes;
- std::unique_ptr<BssSection> bss;
- std::unique_ptr<BssSection> bssRelRo;
- std::unique_ptr<GotSection> got;
- std::unique_ptr<GotPltSection> gotPlt;
- std::unique_ptr<IgotPltSection> igotPlt;
- std::unique_ptr<RelroPaddingSection> relroPadding;
- std::unique_ptr<SyntheticSection> armCmseSGSection;
- std::unique_ptr<PPC64LongBranchTargetSection> ppc64LongBranchTarget;
- std::unique_ptr<SyntheticSection> mipsAbiFlags;
- std::unique_ptr<MipsGotSection> mipsGot;
- std::unique_ptr<SyntheticSection> mipsOptions;
- std::unique_ptr<SyntheticSection> mipsReginfo;
- std::unique_ptr<MipsRldMapSection> mipsRldMap;
- std::unique_ptr<SyntheticSection> partEnd;
- std::unique_ptr<SyntheticSection> partIndex;
- std::unique_ptr<PltSection> plt;
- std::unique_ptr<IpltSection> iplt;
- std::unique_ptr<PPC32Got2Section> ppc32Got2;
- std::unique_ptr<IBTPltSection> ibtPlt;
- std::unique_ptr<RelocationBaseSection> relaPlt;
- // Non-SHF_ALLOC sections
- std::unique_ptr<SyntheticSection> debugNames;
- std::unique_ptr<GdbIndexSection> gdbIndex;
- std::unique_ptr<StringTableSection> shStrTab;
- std::unique_ptr<StringTableSection> strTab;
- std::unique_ptr<SymbolTableBaseSection> symTab;
- std::unique_ptr<SymtabShndxSection> symTabShndx;
-
- void reset();
-};
-
struct Ctx {
LinkerDriver driver;
LinkerScript *script;
@@ -560,8 +504,6 @@ struct Ctx {
SmallVector<OutputSection *, 0> outputSections;
std::vector<Partition> partitions;
- InStruct sec;
-
// Some linker-generated symbols need to be created as
// Defined symbols.
struct ElfSym {
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 46670ce3db9994..54f9a7e02824f5 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -103,7 +103,6 @@ void Ctx::reset() {
outputSections.clear();
partitions.clear();
- in.reset();
sym = ElfSym{};
memoryBuffers.clear();
@@ -153,6 +152,8 @@ bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
elf::ctx.partitions.emplace_back();
symtab = SymbolTable();
+ in.reset();
+
SharedFile::vernauxNum = 0;
};
ctx->e.logName = args::getFilenameWithoutExe(args[0]);
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 2cbd5554106113..cb17e107d6dae2 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -22,7 +22,6 @@
#include "llvm/Support/Parallel.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/TimeProfiler.h"
-#undef in
#if LLVM_ENABLE_ZLIB
// Avoid introducing max as a macro from Windows headers.
#define NOMINMAX
@@ -585,7 +584,7 @@ void OutputSection::writeTo(uint8_t *buf, parallel::TaskGroup &tg) {
static void finalizeShtGroup(OutputSection *os, InputSection *section) {
// sh_link field for SHT_GROUP sections should contain the section index of
// the symbol table.
- os->link = ctx.sec.symTab->getParent()->sectionIndex;
+ os->link = in.symTab->getParent()->sectionIndex;
if (!section)
return;
@@ -593,7 +592,7 @@ static void finalizeShtGroup(OutputSection *os, InputSection *section) {
// sh_info then contain index of an entry in symbol table section which
// provides signature of the section group.
ArrayRef<Symbol *> symbols = section->file->getSymbols();
- os->info = ctx.sec.symTab->getSymbolIndex(*symbols[section->info]);
+ os->info = in.symTab->getSymbolIndex(*symbols[section->info]);
// Some group members may be combined or discarded, so we need to compute the
// 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,
uint offset, const Symbol &sym, uint32_t type, uint addend) {
const auto deltaOffset = static_cast<uint64_t>(offset - out.r_offset);
out.r_offset = offset;
- int64_t symidx = ctx.sec.symTab->getSymbolIndex(sym);
+ int64_t symidx = in.symTab->getSymbolIndex(sym);
if (sym.type == STT_SECTION) {
auto *d = dyn_cast<Defined>(&sym);
if (d) {
@@ -732,7 +731,7 @@ void OutputSection::finalize() {
if (!first || isa<SyntheticSection>(first))
return;
- link = ctx.sec.symTab->getParent()->sectionIndex;
+ link = in.symTab->getParent()->sectionIndex;
// sh_info for SHT_REL[A] sections should contain the section header index of
// the section to which the relocation applies.
InputSectionBase *s = first->getRelocatedSection();
@@ -882,8 +881,8 @@ void OutputSection::checkDynRelAddends(const uint8_t *bufStart) {
// Some targets have NOBITS synthetic sections with dynamic relocations
// with non-zero addends. Skip such sections.
if (is_contained({EM_PPC, EM_PPC64}, config->emachine) &&
- (rel.inputSec == ctx.sec.ppc64LongBranchTarget.get() ||
- rel.inputSec == ctx.sec.igotPlt.get()))
+ (rel.inputSec == in.ppc64LongBranchTarget.get() ||
+ rel.inputSec == in.igotPlt.get()))
continue;
const uint8_t *relocTarget =
bufStart + relOsec->offset + rel.inputSec->getOffset(rel.offsetInSec);
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 7b14be8c9473ac..3b75863ac67b01 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -4926,6 +4926,8 @@ template <class ELFT> void elf::createSyntheticSections() {
add(*in.strTab);
}
+InStruct elf::in;
+
template void elf::splitSections<ELF32LE>();
template void elf::splitSections<ELF32BE>();
template void elf::splitSections<ELF64LE>();
diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h
index b1ca264bac6943..4bfa5cd73d35ee 100644
--- a/lld/ELF/SyntheticSections.h
+++ b/lld/ELF/SyntheticSections.h
@@ -1479,7 +1479,43 @@ inline Partition &SectionBase::getPartition() const {
return ctx.partitions[partition - 1];
}
-#define in ctx.sec
+// Linker generated sections which can be used as inputs and are not specific to
+// a partition.
+struct InStruct {
+ std::unique_ptr<InputSection> attributes;
+ std::unique_ptr<SyntheticSection> riscvAttributes;
+ std::unique_ptr<BssSection> bss;
+ std::unique_ptr<BssSection> bssRelRo;
+ std::unique_ptr<GotSection> got;
+ std::unique_ptr<GotPltSection> gotPlt;
+ std::unique_ptr<IgotPltSection> igotPlt;
+ std::unique_ptr<RelroPaddingSection> relroPadding;
+ std::unique_ptr<SyntheticSection> armCmseSGSection;
+ std::unique_ptr<PPC64LongBranchTargetSection> ppc64LongBranchTarget;
+ std::unique_ptr<SyntheticSection> mipsAbiFlags;
+ std::unique_ptr<MipsGotSection> mipsGot;
+ std::unique_ptr<SyntheticSection> mipsOptions;
+ std::unique_ptr<SyntheticSection> mipsReginfo;
+ std::unique_ptr<MipsRldMapSection> mipsRldMap;
+ std::unique_ptr<SyntheticSection> partEnd;
+ std::unique_ptr<SyntheticSection> partIndex;
+ std::unique_ptr<PltSection> plt;
+ std::unique_ptr<IpltSection> iplt;
+ std::unique_ptr<PPC32Got2Section> ppc32Got2;
+ std::unique_ptr<IBTPltSection> ibtPlt;
+ std::unique_ptr<RelocationBaseSection> relaPlt;
+ // Non-SHF_ALLOC sections
+ std::unique_ptr<SyntheticSection> debugNames;
+ std::unique_ptr<GdbIndexSection> gdbIndex;
+ std::unique_ptr<StringTableSection> shStrTab;
+ std::unique_ptr<StringTableSection> strTab;
+ std::unique_ptr<SymbolTableBaseSection> symTab;
+ std::unique_ptr<SymtabShndxSection> symTabShndx;
+
+ void reset();
+};
+
+LLVM_LIBRARY_VISIBILITY extern InStruct in;
} // namespace lld::elf
More information about the llvm-commits
mailing list