[lld] 796787d - [ELF] Remove unneeded script->. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 21 20:27:50 PDT 2024
Author: Fangrui Song
Date: 2024-08-21T20:27:44-07:00
New Revision: 796787d07c30cb9448e1f9ff3f3da06c2fc96ccd
URL: https://github.com/llvm/llvm-project/commit/796787d07c30cb9448e1f9ff3f3da06c2fc96ccd
DIFF: https://github.com/llvm/llvm-project/commit/796787d07c30cb9448e1f9ff3f3da06c2fc96ccd.diff
LOG: [ELF] Remove unneeded script->. NFC
Added:
Modified:
lld/ELF/LinkerScript.cpp
lld/ELF/LinkerScript.h
Removed:
################################################################################
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 01c15d79e748ae..2f781379a27243 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -50,7 +50,7 @@ static bool isSectionPrefix(StringRef prefix, StringRef name) {
return name.consume_front(prefix) && (name.empty() || name[0] == '.');
}
-static StringRef getOutputSectionName(const InputSectionBase *s) {
+StringRef LinkerScript::getOutputSectionName(const InputSectionBase *s) const {
// This is for --emit-relocs and -r. If .text.foo is emitted as .text.bar, we
// want to emit .rela.text.foo as .rela.text.bar for consistency (this is not
// technically required, but not doing it is odd). This code guarantees that.
@@ -77,7 +77,7 @@ static StringRef getOutputSectionName(const InputSectionBase *s) {
if (s->name == "COMMON")
return ".bss";
- if (script->hasSectionsCommand)
+ if (hasSectionsCommand)
return s->name;
// When no SECTIONS is specified, emulate GNU ld's internal linker scripts
@@ -596,7 +596,7 @@ LinkerScript::computeInputSections(const InputSectionDescription *cmd,
sortByPositionThenCommandLine(sizeAfterPrevSort, ret.size());
} else {
SectionClassDesc *scd =
- script->sectionClasses.lookup(CachedHashStringRef(cmd->classRef));
+ sectionClasses.lookup(CachedHashStringRef(cmd->classRef));
if (!scd) {
errorOrWarn("undefined section class '" + cmd->classRef + "'");
return ret;
@@ -1160,7 +1160,7 @@ bool LinkerScript::assignOffsets(OutputSection *sec) {
}
state->outSec = sec;
- if (!(sec->addrExpr && script->hasSectionsCommand)) {
+ if (!(sec->addrExpr && hasSectionsCommand)) {
// ALIGN is respected. sec->alignment is the max of ALIGN and the maximum of
// input section alignments.
const uint64_t pos = dot;
@@ -1419,15 +1419,6 @@ void LinkerScript::adjustSectionsAfterSorting() {
maybePropagatePhdrs(osd->osec, defPhdrs);
}
-static uint64_t computeBase(uint64_t min, bool allocateHeaders) {
- // If there is no SECTIONS or if the linkerscript is explicit about program
- // headers, do our best to allocate them.
- if (!script->hasSectionsCommand || allocateHeaders)
- return 0;
- // Otherwise only allocate program headers if that would not add a page.
- return alignDown(min, config->maxPageSize);
-}
-
// When the SECTIONS command is used, try to find an address for the file and
// program headers output sections, which can be added to the first PT_LOAD
// segment when program headers are created.
@@ -1453,8 +1444,13 @@ void LinkerScript::allocateHeaders(SmallVector<PhdrEntry *, 0> &phdrs) {
});
bool paged = !config->omagic && !config->nmagic;
uint64_t headerSize = getHeaderSize();
- if ((paged || hasExplicitHeaders) &&
- headerSize <= min - computeBase(min, hasExplicitHeaders)) {
+
+ uint64_t base = 0;
+ // If SECTIONS is present and the linkerscript is not explicit about program
+ // headers, only allocate program headers if that would not add a page.
+ if (hasSectionsCommand && !hasExplicitHeaders)
+ base = alignDown(min, config->maxPageSize);
+ if ((paged || hasExplicitHeaders) && headerSize <= min - base) {
min = alignDown(min - headerSize, config->maxPageSize);
ctx.out.elfHeader->addr = min;
ctx.out.programHeaders->addr = min + ctx.out.elfHeader->size;
@@ -1487,7 +1483,7 @@ LinkerScript::AddressState::AddressState() {
// that has changed its section or value (or nullptr if no symbol has changed).
std::pair<const OutputSection *, const Defined *>
LinkerScript::assignAddresses() {
- if (script->hasSectionsCommand) {
+ if (hasSectionsCommand) {
// With a linker script, assignment of addresses to headers is covered by
// allocateHeaders().
dot = config->imageBase.value_or(0);
@@ -1805,10 +1801,9 @@ void LinkerScript::addScriptReferencedSymbolsToSymTable() {
for (StringRef name : *symRefsVec.pop_back_val()) {
reference(name);
// Prevent the symbol from being discarded by --gc-sections.
- script->referencedSymbols.push_back(name);
- auto it = script->provideMap.find(name);
- if (it != script->provideMap.end() &&
- LinkerScript::shouldAddProvideSym(name) &&
+ referencedSymbols.push_back(name);
+ auto it = provideMap.find(name);
+ if (it != provideMap.end() && shouldAddProvideSym(name) &&
added.insert(name).second) {
symRefsVec.push_back(&it->second);
}
diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h
index 90090ce16de547..b057051f772bf8 100644
--- a/lld/ELF/LinkerScript.h
+++ b/lld/ELF/LinkerScript.h
@@ -300,6 +300,7 @@ class LinkerScript final {
llvm::DenseMap<llvm::CachedHashStringRef, OutputDesc *> nameToOutputSection;
+ StringRef getOutputSectionName(const InputSectionBase *s) const;
void addSymbol(SymbolAssignment *cmd);
void assignSymbol(SymbolAssignment *cmd, bool inSec);
void setDot(Expr e, const Twine &loc, bool inSec);
More information about the llvm-commits
mailing list