[lld] c62fa63 - [ELF] Move mainPart to Ctx. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 21 20:08:16 PDT 2024
Author: Fangrui Song
Date: 2024-08-21T20:08:11-07:00
New Revision: c62fa63ff1a043dc62b88270680657483f307fae
URL: https://github.com/llvm/llvm-project/commit/c62fa63ff1a043dc62b88270680657483f307fae
DIFF: https://github.com/llvm/llvm-project/commit/c62fa63ff1a043dc62b88270680657483f307fae.diff
LOG: [ELF] Move mainPart to Ctx. NFC
Ctx was introduced in March 2022 as a more suitable place for such
singletons.
Added:
Modified:
lld/ELF/Arch/PPC.cpp
lld/ELF/Arch/RISCV.cpp
lld/ELF/Arch/SystemZ.cpp
lld/ELF/Arch/X86.cpp
lld/ELF/Arch/X86_64.cpp
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/Relocations.cpp
lld/ELF/SyntheticSections.cpp
lld/ELF/SyntheticSections.h
lld/ELF/Thunks.cpp
lld/ELF/Writer.cpp
Removed:
################################################################################
diff --git a/lld/ELF/Arch/PPC.cpp b/lld/ELF/Arch/PPC.cpp
index 1b0838456428f1..186dcf229b6f6d 100644
--- a/lld/ELF/Arch/PPC.cpp
+++ b/lld/ELF/Arch/PPC.cpp
@@ -187,7 +187,7 @@ void PPC::writeGotHeader(uint8_t *buf) const {
// _GLOBAL_OFFSET_TABLE_[0] = _DYNAMIC
// glibc stores _dl_runtime_resolve in _GLOBAL_OFFSET_TABLE_[1],
// link_map in _GLOBAL_OFFSET_TABLE_[2].
- write32(buf, mainPart->dynamic->getVA());
+ write32(buf, ctx.mainPart->dynamic->getVA());
}
void PPC::writeGotPlt(uint8_t *buf, const Symbol &s) const {
diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index 1e939caf591cef..dc9e541d5d8bef 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -200,9 +200,9 @@ int64_t RISCV::getImplicitAddend(const uint8_t *buf, RelType type) const {
void RISCV::writeGotHeader(uint8_t *buf) const {
if (config->is64)
- write64le(buf, mainPart->dynamic->getVA());
+ write64le(buf, ctx.mainPart->dynamic->getVA());
else
- write32le(buf, mainPart->dynamic->getVA());
+ write32le(buf, ctx.mainPart->dynamic->getVA());
}
void RISCV::writeGotPlt(uint8_t *buf, const Symbol &s) const {
diff --git a/lld/ELF/Arch/SystemZ.cpp b/lld/ELF/Arch/SystemZ.cpp
index 0921bc11925189..293df50708952b 100644
--- a/lld/ELF/Arch/SystemZ.cpp
+++ b/lld/ELF/Arch/SystemZ.cpp
@@ -179,7 +179,7 @@ RelExpr SystemZ::getRelExpr(RelType type, const Symbol &s,
void SystemZ::writeGotHeader(uint8_t *buf) const {
// _GLOBAL_OFFSET_TABLE_[0] holds the value of _DYNAMIC.
// _GLOBAL_OFFSET_TABLE_[1] and [2] are reserved.
- write64be(buf, mainPart->dynamic->getVA());
+ write64be(buf, ctx.mainPart->dynamic->getVA());
}
void SystemZ::writeGotPlt(uint8_t *buf, const Symbol &s) const {
diff --git a/lld/ELF/Arch/X86.cpp b/lld/ELF/Arch/X86.cpp
index 8d4f258e2cf24e..20b69adc12bc05 100644
--- a/lld/ELF/Arch/X86.cpp
+++ b/lld/ELF/Arch/X86.cpp
@@ -164,7 +164,7 @@ RelExpr X86::adjustTlsExpr(RelType type, RelExpr expr) const {
}
void X86::writeGotPltHeader(uint8_t *buf) const {
- write32le(buf, mainPart->dynamic->getVA());
+ write32le(buf, ctx.mainPart->dynamic->getVA());
}
void X86::writeGotPlt(uint8_t *buf, const Symbol &s) const {
diff --git a/lld/ELF/Arch/X86_64.cpp b/lld/ELF/Arch/X86_64.cpp
index 3f95247e0035c3..65a81fe12f8709 100644
--- a/lld/ELF/Arch/X86_64.cpp
+++ b/lld/ELF/Arch/X86_64.cpp
@@ -411,7 +411,7 @@ void X86_64::writeGotPltHeader(uint8_t *buf) const {
// in the psABI and glibc before Aug 2021 used the entry to compute run-time
// load address of the shared object (note that this is relevant for linking
// ld.so, not any other program).
- write64le(buf, mainPart->dynamic->getVA());
+ write64le(buf, ctx.mainPart->dynamic->getVA());
}
void X86_64::writeGotPlt(uint8_t *buf, const Symbol &s) const {
diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index 035b385ba37ec3..0c7bfe1bef7e59 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -46,6 +46,7 @@ class Defined;
class Symbol;
class BitcodeCompiler;
class OutputSection;
+struct Partition;
struct PhdrEntry;
enum ELFKind : uint8_t {
@@ -486,6 +487,7 @@ struct Ctx {
// These variables are initialized by Writer and should not be used before
// Writer is initialized.
uint8_t *bufferStart;
+ Partition *mainPart;
PhdrEntry *tlsPhdr;
struct OutSections {
OutputSection *elfHeader;
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 36552e4bb035af..ced06a1c46a826 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -95,6 +95,7 @@ void Ctx::reset() {
driver = LinkerDriver();
bufferStart = nullptr;
+ mainPart = nullptr;
tlsPhdr = nullptr;
out = OutSections{};
outputSections.clear();
@@ -3094,7 +3095,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
// Now that the number of partitions is fixed, save a pointer to the main
// partition.
- mainPart = &partitions[0];
+ ctx.mainPart = &partitions[0];
// Read .note.gnu.property sections from input object files which
// contain a hint to tweak linker's and loader's behaviors.
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 9dbb4567495a81..9ccef389d48e38 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -399,7 +399,7 @@ template <class ELFT> static void addCopyRelSymbol(SharedSymbol &ss) {
for (SharedSymbol *sym : getSymbolsAt<ELFT>(ss))
replaceWithDefined(*sym, *sec, 0, sym->size);
- mainPart->relaDyn->addSymbolReloc(target->copyRel, *sec, 0, ss);
+ ctx.mainPart->relaDyn->addSymbolReloc(target->copyRel, *sec, 0, ss);
}
// .eh_frame sections are mergeable input sections, so their input
@@ -927,8 +927,9 @@ void elf::addGotEntry(Symbol &sym) {
// If preemptible, emit a GLOB_DAT relocation.
if (sym.isPreemptible) {
- mainPart->relaDyn->addReloc({target->gotRel, in.got.get(), off,
- DynamicReloc::AgainstSymbol, sym, 0, R_ABS});
+ ctx.mainPart->relaDyn->addReloc({target->gotRel, in.got.get(), off,
+ DynamicReloc::AgainstSymbol, sym, 0,
+ R_ABS});
return;
}
@@ -947,7 +948,7 @@ static void addTpOffsetGotEntry(Symbol &sym) {
in.got->addConstant({R_TPREL, target->symbolicRel, off, 0, &sym});
return;
}
- mainPart->relaDyn->addAddendOnlyRelocIfNonPreemptible(
+ ctx.mainPart->relaDyn->addAddendOnlyRelocIfNonPreemptible(
target->tlsGotRel, *in.got, off, sym, target->symbolicRel);
}
@@ -1085,7 +1086,8 @@ void RelocationScanner::processAux(RelExpr expr, RelType type, uint64_t offset,
if (LLVM_UNLIKELY(isIfunc) && config->zIfuncNoplt) {
std::lock_guard<std::mutex> lock(relocMutex);
sym.exportDynamic = true;
- mainPart->relaDyn->addSymbolReloc(type, *sec, offset, sym, addend, type);
+ ctx.mainPart->relaDyn->addSymbolReloc(type, *sec, offset, sym, addend,
+ type);
return;
}
@@ -1727,7 +1729,8 @@ static bool handleNonPreemptibleIfunc(Symbol &sym, uint16_t flags) {
// IRELATIVE in .rela.plt.
auto *directSym = makeDefined(cast<Defined>(sym));
directSym->allocateAux();
- auto &dyn = config->androidPackDynRelocs ? *in.relaPlt : *mainPart->relaDyn;
+ auto &dyn =
+ config->androidPackDynRelocs ? *in.relaPlt : *ctx.mainPart->relaDyn;
addPltEntry(*in.iplt, *in.igotPlt, dyn, target->iRelativeRel, *directSym);
sym.allocateAux();
ctx.symAux.back().pltIdx = ctx.symAux[directSym->auxIdx].pltIdx;
@@ -1758,7 +1761,7 @@ void elf::postScanRelocations() {
return;
if (sym.isTagged() && sym.isDefined())
- mainPart->memtagGlobalDescriptors->addSymbol(sym);
+ ctx.mainPart->memtagGlobalDescriptors->addSymbol(sym);
if (!sym.needsDynReloc())
return;
@@ -1799,7 +1802,7 @@ void elf::postScanRelocations() {
if (flags & NEEDS_TLSDESC) {
got->addTlsDescEntry(sym);
- mainPart->relaDyn->addAddendOnlyRelocIfNonPreemptible(
+ ctx.mainPart->relaDyn->addAddendOnlyRelocIfNonPreemptible(
target->tlsDescRel, *got, got->getTlsDescOffset(sym), sym,
target->tlsDescRel);
}
@@ -1810,22 +1813,22 @@ void elf::postScanRelocations() {
// Write one to the GOT slot.
got->addConstant({R_ADDEND, target->symbolicRel, off, 1, &sym});
else
- mainPart->relaDyn->addSymbolReloc(target->tlsModuleIndexRel, *got, off,
- sym);
+ ctx.mainPart->relaDyn->addSymbolReloc(target->tlsModuleIndexRel, *got,
+ off, sym);
// If the symbol is preemptible we need the dynamic linker to write
// the offset too.
uint64_t offsetOff = off + config->wordsize;
if (sym.isPreemptible)
- mainPart->relaDyn->addSymbolReloc(target->tlsOffsetRel, *got, offsetOff,
- sym);
+ ctx.mainPart->relaDyn->addSymbolReloc(target->tlsOffsetRel, *got,
+ offsetOff, sym);
else
got->addConstant({R_ABS, target->tlsOffsetRel, offsetOff, 0, &sym});
}
if (flags & NEEDS_TLSGD_TO_IE) {
got->addEntry(sym);
- mainPart->relaDyn->addSymbolReloc(target->tlsGotRel, *got,
- sym.getGotOffset(), sym);
+ ctx.mainPart->relaDyn->addSymbolReloc(target->tlsGotRel, *got,
+ sym.getGotOffset(), sym);
}
if (flags & NEEDS_GOT_DTPREL) {
got->addEntry(sym);
@@ -1841,7 +1844,7 @@ void elf::postScanRelocations() {
if (ctx.needsTlsLd.load(std::memory_order_relaxed) && got->addTlsIndex()) {
static Undefined dummy(ctx.internalFile, "", STB_LOCAL, 0, 0);
if (config->shared)
- mainPart->relaDyn->addReloc(
+ ctx.mainPart->relaDyn->addReloc(
{target->tlsModuleIndexRel, got, got->getTlsIndexOff()});
else
got->addConstant(
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 7d26fa9aea74ab..1dbbd117290a4d 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1017,9 +1017,9 @@ void MipsGotSection::build() {
// for the TP-relative offset as we don't know how much other data will
// be allocated before us in the static TLS block.
if (s->isPreemptible || config->shared)
- mainPart->relaDyn->addReloc({target->tlsGotRel, this, offset,
- DynamicReloc::AgainstSymbolWithTargetVA,
- *s, 0, R_ABS});
+ ctx.mainPart->relaDyn->addReloc(
+ {target->tlsGotRel, this, offset,
+ DynamicReloc::AgainstSymbolWithTargetVA, *s, 0, R_ABS});
}
for (std::pair<Symbol *, size_t> &p : got.dynTlsSymbols) {
Symbol *s = p.first;
@@ -1027,7 +1027,8 @@ void MipsGotSection::build() {
if (s == nullptr) {
if (!config->shared)
continue;
- mainPart->relaDyn->addReloc({target->tlsModuleIndexRel, this, offset});
+ ctx.mainPart->relaDyn->addReloc(
+ {target->tlsModuleIndexRel, this, offset});
} else {
// When building a shared library we still need a dynamic relocation
// for the module index. Therefore only checking for
@@ -1035,15 +1036,15 @@ void MipsGotSection::build() {
// thread-locals that have been marked as local through a linker script)
if (!s->isPreemptible && !config->shared)
continue;
- mainPart->relaDyn->addSymbolReloc(target->tlsModuleIndexRel, *this,
- offset, *s);
+ ctx.mainPart->relaDyn->addSymbolReloc(target->tlsModuleIndexRel, *this,
+ offset, *s);
// However, we can skip writing the TLS offset reloc for non-preemptible
// symbols since it is known even in shared libraries
if (!s->isPreemptible)
continue;
offset += config->wordsize;
- mainPart->relaDyn->addSymbolReloc(target->tlsOffsetRel, *this, offset,
- *s);
+ ctx.mainPart->relaDyn->addSymbolReloc(target->tlsOffsetRel, *this,
+ offset, *s);
}
}
@@ -1055,8 +1056,8 @@ void MipsGotSection::build() {
// Dynamic relocations for "global" entries.
for (const std::pair<Symbol *, size_t> &p : got.global) {
uint64_t offset = p.second * config->wordsize;
- mainPart->relaDyn->addSymbolReloc(target->relativeRel, *this, offset,
- *p.first);
+ ctx.mainPart->relaDyn->addSymbolReloc(target->relativeRel, *this, offset,
+ *p.first);
}
if (!config->isPic)
continue;
@@ -1066,15 +1067,15 @@ void MipsGotSection::build() {
size_t pageCount = l.second.count;
for (size_t pi = 0; pi < pageCount; ++pi) {
uint64_t offset = (l.second.firstIndex + pi) * config->wordsize;
- mainPart->relaDyn->addReloc({target->relativeRel, this, offset, l.first,
- int64_t(pi * 0x10000)});
+ ctx.mainPart->relaDyn->addReloc({target->relativeRel, this, offset,
+ l.first, int64_t(pi * 0x10000)});
}
}
for (const std::pair<GotEntry, size_t> &p : got.local16) {
uint64_t offset = p.second * config->wordsize;
- mainPart->relaDyn->addReloc({target->relativeRel, this, offset,
- DynamicReloc::AddendOnlyWithTargetVA,
- *p.first.first, p.first.second, R_ABS});
+ ctx.mainPart->relaDyn->addReloc({target->relativeRel, this, offset,
+ DynamicReloc::AddendOnlyWithTargetVA,
+ *p.first.first, p.first.second, R_ABS});
}
}
}
@@ -1473,10 +1474,11 @@ DynamicSection<ELFT>::computeContents() {
addInt(DT_AARCH64_MEMTAG_MODE, config->androidMemtagMode == NT_MEMTAG_LEVEL_ASYNC);
addInt(DT_AARCH64_MEMTAG_HEAP, config->androidMemtagHeap);
addInt(DT_AARCH64_MEMTAG_STACK, config->androidMemtagStack);
- if (mainPart->memtagGlobalDescriptors->isNeeded()) {
- addInSec(DT_AARCH64_MEMTAG_GLOBALS, *mainPart->memtagGlobalDescriptors);
+ if (ctx.mainPart->memtagGlobalDescriptors->isNeeded()) {
+ addInSec(DT_AARCH64_MEMTAG_GLOBALS,
+ *ctx.mainPart->memtagGlobalDescriptors);
addInt(DT_AARCH64_MEMTAG_GLOBALSSZ,
- mainPart->memtagGlobalDescriptors->getSize());
+ ctx.mainPart->memtagGlobalDescriptors->getSize());
}
}
}
@@ -1617,7 +1619,7 @@ uint32_t DynamicReloc::getSymIndex(SymbolTableBaseSection *symTab) const {
size_t index = symTab->getSymbolIndex(*sym);
assert((index != 0 || (type != target->gotRel && type != target->pltRel) ||
- !mainPart->dynSymTab->getParent()) &&
+ !ctx.mainPart->dynSymTab->getParent()) &&
"GOT or PLT relocation must refer to symbol in dynamic symbol table");
return index;
}
@@ -2149,7 +2151,7 @@ void SymbolTableBaseSection::finalizeContents() {
// Only the main partition's dynsym indexes are stored in the symbols
// themselves. All other partitions use a lookup table.
- if (this == mainPart->dynSymTab.get()) {
+ if (this == ctx.mainPart->dynSymTab.get()) {
size_t i = 0;
for (const SymbolTableEntry &s : symbols)
s.sym->dynsymIndex = ++i;
@@ -2193,7 +2195,7 @@ void SymbolTableBaseSection::addSymbol(Symbol *b) {
}
size_t SymbolTableBaseSection::getSymbolIndex(const Symbol &sym) {
- if (this == mainPart->dynSymTab.get())
+ if (this == ctx.mainPart->dynSymTab.get())
return sym.dynsymIndex;
// Initializes symbol lookup tables lazily. This is used only for -r,
@@ -3968,7 +3970,7 @@ void elf::combineEhSections() {
llvm::append_range(eh.dependentSections, sec->dependentSections);
}
- if (!mainPart->armExidx)
+ if (!ctx.mainPart->armExidx)
return;
llvm::erase_if(ctx.inputSections, [](InputSectionBase *s) {
// Ignore dead sections and the partition end marker (.part.end),
@@ -4439,13 +4441,15 @@ size_t PartitionIndexSection::getSize() const {
void PartitionIndexSection::finalizeContents() {
for (size_t i = 1; i != partitions.size(); ++i)
- partitions[i].nameStrTab = mainPart->dynStrTab->addString(partitions[i].name);
+ partitions[i].nameStrTab =
+ ctx.mainPart->dynStrTab->addString(partitions[i].name);
}
void PartitionIndexSection::writeTo(uint8_t *buf) {
uint64_t va = getVA();
for (size_t i = 1; i != partitions.size(); ++i) {
- write32(buf, mainPart->dynStrTab->getVA() + partitions[i].nameStrTab - va);
+ write32(buf,
+ ctx.mainPart->dynStrTab->getVA() + partitions[i].nameStrTab - va);
write32(buf + 4, partitions[i].elfHeader->getVA() - (va + 4));
SyntheticSection *next = i == partitions.size() - 1
@@ -4922,7 +4926,6 @@ template <class ELFT> void elf::createSyntheticSections() {
InStruct elf::in;
std::vector<Partition> elf::partitions;
-Partition *elf::mainPart;
template void elf::splitSections<ELF32LE>();
template void elf::splitSections<ELF32BE>();
diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h
index 43eb82cbb3e28b..56647f46b5fc41 100644
--- a/lld/ELF/SyntheticSections.h
+++ b/lld/ELF/SyntheticSections.h
@@ -1474,8 +1474,6 @@ struct Partition {
unsigned getNumber() const { return this - &partitions[0] + 1; }
};
-LLVM_LIBRARY_VISIBILITY extern Partition *mainPart;
-
inline Partition &SectionBase::getPartition() const {
assert(isLive());
return partitions[partition - 1];
diff --git a/lld/ELF/Thunks.cpp b/lld/ELF/Thunks.cpp
index f912f61e372943..478d956f43d9b1 100644
--- a/lld/ELF/Thunks.cpp
+++ b/lld/ELF/Thunks.cpp
@@ -474,7 +474,7 @@ class PPC64PILongBranchThunk final : public PPC64LongBranchThunk {
assert(!dest.isPreemptible);
if (std::optional<uint32_t> index =
in.ppc64LongBranchTarget->addEntry(&dest, addend)) {
- mainPart->relaDyn->addRelativeReloc(
+ ctx.mainPart->relaDyn->addRelativeReloc(
target->relativeRel, *in.ppc64LongBranchTarget, *index * UINT64_C(8),
dest, addend + getPPC64GlobalEntryToLocalEntryOffset(dest.stOther),
target->symbolicRel, R_ABS);
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 82d9ea24d9bd3f..2091058c9c8874 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -315,7 +315,7 @@ template <class ELFT> void Writer<ELFT>::run() {
sec->maybeCompress<ELFT>();
if (script->hasSectionsCommand)
- script->allocateHeaders(mainPart->phdrs);
+ script->allocateHeaders(ctx.mainPart->phdrs);
// Remove empty PT_LOAD to avoid causing the dynamic linker to try to mmap a
// 0 sized region. This has to be done late since only after assignAddresses
@@ -833,10 +833,10 @@ template <class ELFT> void Writer<ELFT>::setReservedSymbolSections() {
}
// .rela_iplt_{start,end} mark the start and the end of .rel[a].dyn.
- if (ctx.sym.relaIpltStart && mainPart->relaDyn->isNeeded()) {
- ctx.sym.relaIpltStart->section = mainPart->relaDyn.get();
- ctx.sym.relaIpltEnd->section = mainPart->relaDyn.get();
- ctx.sym.relaIpltEnd->value = mainPart->relaDyn->getSize();
+ if (ctx.sym.relaIpltStart && ctx.mainPart->relaDyn->isNeeded()) {
+ ctx.sym.relaIpltStart->section = ctx.mainPart->relaDyn.get();
+ ctx.sym.relaIpltEnd->section = ctx.mainPart->relaDyn.get();
+ ctx.sym.relaIpltEnd->value = ctx.mainPart->relaDyn->getSize();
}
PhdrEntry *last = nullptr;
@@ -1681,7 +1681,7 @@ static void removeUnusedSyntheticSections() {
// we would fail to remove it here.
if (config->emachine == EM_AARCH64 && config->relrPackDynRelocs)
if (auto *relSec = dyn_cast<RelocationBaseSection>(sec))
- if (relSec == mainPart->relaDyn.get())
+ if (relSec == ctx.mainPart->relaDyn.get())
return false;
unused.insert(sec);
return true;
@@ -1721,10 +1721,10 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
// It should be okay as no one seems to care about the type.
// Even the author of gold doesn't remember why gold behaves that way.
// https://sourceware.org/ml/binutils/2002-03/msg00360.html
- if (mainPart->dynamic->parent) {
+ if (ctx.mainPart->dynamic->parent) {
Symbol *s = symtab.addSymbol(Defined{
ctx.internalFile, "_DYNAMIC", STB_WEAK, STV_HIDDEN, STT_NOTYPE,
- /*value=*/0, /*size=*/0, mainPart->dynamic.get()});
+ /*value=*/0, /*size=*/0, ctx.mainPart->dynamic.get()});
s->isUsedInRegularObj = true;
}
@@ -1951,13 +1951,14 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
addPhdrForSection(part, SHT_RISCV_ATTRIBUTES, PT_RISCV_ATTRIBUTES,
PF_R);
}
- ctx.out.programHeaders->size = sizeof(Elf_Phdr) * mainPart->phdrs.size();
+ ctx.out.programHeaders->size =
+ sizeof(Elf_Phdr) * ctx.mainPart->phdrs.size();
// Find the TLS segment. This happens before the section layout loop so that
// Android relocation packing can look up TLS symbol addresses. We only need
// to care about the main partition here because all TLS symbols were moved
// to the main partition (see MarkLive.cpp).
- for (PhdrEntry *p : mainPart->phdrs)
+ for (PhdrEntry *p : ctx.mainPart->phdrs)
if (p->p_type == PT_TLS)
ctx.tlsPhdr = p;
}
@@ -2720,8 +2721,8 @@ static uint16_t getELFType() {
}
template <class ELFT> void Writer<ELFT>::writeHeader() {
- writeEhdr<ELFT>(ctx.bufferStart, *mainPart);
- writePhdrs<ELFT>(ctx.bufferStart + sizeof(Elf_Ehdr), *mainPart);
+ writeEhdr<ELFT>(ctx.bufferStart, *ctx.mainPart);
+ writePhdrs<ELFT>(ctx.bufferStart + sizeof(Elf_Ehdr), *ctx.mainPart);
auto *eHdr = reinterpret_cast<Elf_Ehdr *>(ctx.bufferStart);
eHdr->e_type = getELFType();
@@ -2884,7 +2885,7 @@ computeHash(llvm::MutableArrayRef<uint8_t> hashBuf,
}
template <class ELFT> void Writer<ELFT>::writeBuildId() {
- if (!mainPart->buildId || !mainPart->buildId->getParent())
+ if (!ctx.mainPart->buildId || !ctx.mainPart->buildId->getParent())
return;
if (config->buildId == BuildIdKind::Hexstring) {
@@ -2894,7 +2895,7 @@ template <class ELFT> void Writer<ELFT>::writeBuildId() {
}
// Compute a hash of all sections of the output file.
- size_t hashSize = mainPart->buildId->hashSize;
+ size_t hashSize = ctx.mainPart->buildId->hashSize;
std::unique_ptr<uint8_t[]> buildId(new uint8_t[hashSize]);
MutableArrayRef<uint8_t> output(buildId.get(), hashSize);
llvm::ArrayRef<uint8_t> input{ctx.bufferStart, size_t(fileSize)};
More information about the llvm-commits
mailing list