[lld] dd6aea9 - [ELF] Rename LinkerScript::ctx to state. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 1 15:27:47 PDT 2022
Author: Fangrui Song
Date: 2022-10-01T15:27:39-07:00
New Revision: dd6aea9582c1031717a778e711900d6723c795fb
URL: https://github.com/llvm/llvm-project/commit/dd6aea9582c1031717a778e711900d6723c795fb
DIFF: https://github.com/llvm/llvm-project/commit/dd6aea9582c1031717a778e711900d6723c795fb.diff
LOG: [ELF] Rename LinkerScript::ctx to state. NFC
To avoid name conflict with `elf::ctx`.
Added:
Modified:
lld/ELF/LinkerScript.cpp
lld/ELF/LinkerScript.h
Removed:
################################################################################
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index c9ead13eba90..e19da00fbde6 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -166,15 +166,15 @@ static void expandMemoryRegion(MemoryRegion *memRegion, uint64_t size,
}
void LinkerScript::expandMemoryRegions(uint64_t size) {
- if (ctx->memRegion)
- expandMemoryRegion(ctx->memRegion, size, ctx->outSec->name);
+ if (state->memRegion)
+ expandMemoryRegion(state->memRegion, size, state->outSec->name);
// Only expand the LMARegion if it is
diff erent from memRegion.
- if (ctx->lmaRegion && ctx->memRegion != ctx->lmaRegion)
- expandMemoryRegion(ctx->lmaRegion, size, ctx->outSec->name);
+ if (state->lmaRegion && state->memRegion != state->lmaRegion)
+ expandMemoryRegion(state->lmaRegion, size, state->outSec->name);
}
void LinkerScript::expandOutputSection(uint64_t size) {
- ctx->outSec->size += size;
+ state->outSec->size += size;
expandMemoryRegions(size);
}
@@ -182,7 +182,7 @@ void LinkerScript::setDot(Expr e, const Twine &loc, bool inSec) {
uint64_t val = e().getValue();
if (val < dot && inSec)
error(loc + ": unable to move location counter backward for: " +
- ctx->outSec->name);
+ state->outSec->name);
// Update to location counter means update to section size.
if (inSec)
@@ -341,7 +341,7 @@ void LinkerScript::processInsertCommands() {
// we don't know their final values until late stages of link. Here we scan
// over symbol assignment commands and create placeholder symbols if needed.
void LinkerScript::declareSymbols() {
- assert(!ctx);
+ assert(!state);
for (SectionCommand *cmd : sectionCommands) {
if (auto *assign = dyn_cast<SymbolAssignment>(cmd)) {
declareSymbol(assign);
@@ -681,12 +681,12 @@ void LinkerScript::processSymbolAssignments() {
aether = make<OutputSection>("", 0, SHF_ALLOC);
aether->sectionIndex = 1;
- // ctx captures the local AddressState and makes it accessible deliberately.
+ // `st` captures the local AddressState and makes it accessible deliberately.
// This is needed as there are some cases where we cannot just thread the
// current state through to a lambda function created by the script parser.
- AddressState state;
- ctx = &state;
- ctx->outSec = aether;
+ AddressState st;
+ state = &st;
+ st.outSec = aether;
for (SectionCommand *cmd : sectionCommands) {
if (auto *assign = dyn_cast<SymbolAssignment>(cmd))
@@ -697,7 +697,7 @@ void LinkerScript::processSymbolAssignments() {
addSymbol(assign);
}
- ctx = nullptr;
+ state = nullptr;
}
static OutputSection *findByName(ArrayRef<SectionCommand *> vec,
@@ -957,11 +957,11 @@ static OutputSection *findFirstSection(PhdrEntry *load) {
// for a single sections command (e.g. ".text { *(.text); }").
void LinkerScript::assignOffsets(OutputSection *sec) {
const bool isTbss = (sec->flags & SHF_TLS) && sec->type == SHT_NOBITS;
- const bool sameMemRegion = ctx->memRegion == sec->memRegion;
- const bool prevLMARegionIsDefault = ctx->lmaRegion == nullptr;
+ const bool sameMemRegion = state->memRegion == sec->memRegion;
+ const bool prevLMARegionIsDefault = state->lmaRegion == nullptr;
const uint64_t savedDot = dot;
- ctx->memRegion = sec->memRegion;
- ctx->lmaRegion = sec->lmaRegion;
+ state->memRegion = sec->memRegion;
+ state->lmaRegion = sec->lmaRegion;
if (!(sec->flags & SHF_ALLOC)) {
// Non-SHF_ALLOC sections have zero addresses.
@@ -969,13 +969,13 @@ void LinkerScript::assignOffsets(OutputSection *sec) {
} else if (isTbss) {
// Allow consecutive SHF_TLS SHT_NOBITS output sections. The address range
// starts from the end address of the previous tbss section.
- if (ctx->tbssAddr == 0)
- ctx->tbssAddr = dot;
+ if (state->tbssAddr == 0)
+ state->tbssAddr = dot;
else
- dot = ctx->tbssAddr;
+ dot = state->tbssAddr;
} else {
- if (ctx->memRegion)
- dot = ctx->memRegion->curPos;
+ if (state->memRegion)
+ dot = state->memRegion->curPos;
if (sec->addrExpr)
setDot(sec->addrExpr, sec->location, false);
@@ -983,12 +983,12 @@ void LinkerScript::assignOffsets(OutputSection *sec) {
// expression so that it now starts past the current curPos of the enclosing
// region, we need to expand the current region to account for the space
// between the previous section, if any, and the start of this section.
- if (ctx->memRegion && ctx->memRegion->curPos < dot)
- expandMemoryRegion(ctx->memRegion, dot - ctx->memRegion->curPos,
+ if (state->memRegion && state->memRegion->curPos < dot)
+ expandMemoryRegion(state->memRegion, dot - state->memRegion->curPos,
sec->name);
}
- ctx->outSec = sec;
+ state->outSec = sec;
if (sec->addrExpr && script->hasSectionsCommand) {
// The alignment is ignored.
sec->addr = dot;
@@ -1001,27 +1001,27 @@ void LinkerScript::assignOffsets(OutputSection *sec) {
expandMemoryRegions(dot - pos);
}
- // ctx->lmaOffset is LMA minus VMA. If LMA is explicitly specified via AT() or
- // AT>, recompute ctx->lmaOffset; otherwise, if both previous/current LMA
+ // state->lmaOffset is LMA minus VMA. If LMA is explicitly specified via AT()
+ // or AT>, recompute state->lmaOffset; otherwise, if both previous/current LMA
// region is the default, and the two sections are in the same memory region,
// reuse previous lmaOffset; otherwise, reset lmaOffset to 0. This emulates
// heuristics described in
// https://sourceware.org/binutils/docs/ld/Output-Section-LMA.html
if (sec->lmaExpr) {
- ctx->lmaOffset = sec->lmaExpr().getValue() - dot;
+ state->lmaOffset = sec->lmaExpr().getValue() - dot;
} else if (MemoryRegion *mr = sec->lmaRegion) {
uint64_t lmaStart = alignToPowerOf2(mr->curPos, sec->alignment);
if (mr->curPos < lmaStart)
expandMemoryRegion(mr, lmaStart - mr->curPos, sec->name);
- ctx->lmaOffset = lmaStart - dot;
+ state->lmaOffset = lmaStart - dot;
} else if (!sameMemRegion || !prevLMARegionIsDefault) {
- ctx->lmaOffset = 0;
+ state->lmaOffset = 0;
}
- // Propagate ctx->lmaOffset to the first "non-header" section.
+ // Propagate state->lmaOffset to the first "non-header" section.
if (PhdrEntry *l = sec->ptLoad)
if (sec == findFirstSection(l))
- l->lmaOffset = ctx->lmaOffset;
+ l->lmaOffset = state->lmaOffset;
// We can call this method multiple times during the creation of
// thunks and want to start over calculation each time.
@@ -1070,7 +1070,7 @@ void LinkerScript::assignOffsets(OutputSection *sec) {
dot = savedDot;
} else if (isTbss) {
// NOBITS TLS sections are similar. Additionally save the end address.
- ctx->tbssAddr = dot;
+ state->tbssAddr = dot;
dot = savedDot;
}
}
@@ -1311,10 +1311,10 @@ const Defined *LinkerScript::assignAddresses() {
dot += getHeaderSize();
}
- AddressState state;
- ctx = &state;
+ AddressState st;
+ state = &st;
errorOnMissingSection = true;
- ctx->outSec = aether;
+ st.outSec = aether;
SymbolAssignmentMap oldValues = getSymbolAssignmentValues(sectionCommands);
for (SectionCommand *cmd : sectionCommands) {
@@ -1327,7 +1327,7 @@ const Defined *LinkerScript::assignAddresses() {
assignOffsets(&cast<OutputDesc>(cmd)->osec);
}
- ctx = nullptr;
+ state = nullptr;
return getChangedSymbolAssignment(oldValues);
}
@@ -1380,8 +1380,8 @@ bool LinkerScript::needsInterpSection() {
ExprValue LinkerScript::getSymbolValue(StringRef name, const Twine &loc) {
if (name == ".") {
- if (ctx)
- return {ctx->outSec, false, dot - ctx->outSec->addr, loc};
+ if (state)
+ return {state->outSec, false, dot - state->outSec->addr, loc};
error(loc + ": unable to get location counter value");
return 0;
}
diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h
index dc3d32e50ce0..614e8680f22a 100644
--- a/lld/ELF/LinkerScript.h
+++ b/lld/ELF/LinkerScript.h
@@ -290,13 +290,13 @@ class LinkerScript final {
void assignOffsets(OutputSection *sec);
- // Ctx captures the local AddressState and makes it accessible
+ // This captures the local AddressState and makes it accessible
// deliberately. This is needed as there are some cases where we cannot just
// thread the current state through to a lambda function created by the
// script parser.
// This should remain a plain pointer as its lifetime is smaller than
// LinkerScript.
- AddressState *ctx = nullptr;
+ AddressState *state = nullptr;
OutputSection *aether;
More information about the llvm-commits
mailing list