[lld] 1164c4b - [ELF] Simplify/remove LinkerScript::output and advance. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 28 16:58:12 PST 2021
Author: Fangrui Song
Date: 2021-11-28T16:58:06-08:00
New Revision: 1164c4b37583eca98866853ed22149f1a1b55a3d
URL: https://github.com/llvm/llvm-project/commit/1164c4b37583eca98866853ed22149f1a1b55a3d
DIFF: https://github.com/llvm/llvm-project/commit/1164c4b37583eca98866853ed22149f1a1b55a3d.diff
LOG: [ELF] Simplify/remove LinkerScript::output and advance. 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 054944e76e9e..f497506d4750 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -900,35 +900,19 @@ void LinkerScript::diagnoseOrphanHandling() const {
}
}
-uint64_t LinkerScript::advance(uint64_t size, unsigned alignment) {
- dot = alignTo(dot, alignment) + size;
- return dot;
-}
-
-void LinkerScript::output(InputSection *s) {
- assert(ctx->outSec == s->getParent());
- uint64_t before = advance(0, 1);
- uint64_t pos = advance(s->getSize(), s->alignment);
- s->outSecOff = pos - s->getSize() - ctx->outSec->addr;
-
- // Update output section size after adding each section. This is so that
- // SIZEOF works correctly in the case below:
- // .foo { *(.aaa) a = SIZEOF(.foo); *(.bbb) }
- expandOutputSection(pos - before);
-}
-
void LinkerScript::switchTo(OutputSection *sec) {
ctx->outSec = sec;
- uint64_t pos = advance(0, 1);
+ const uint64_t pos = dot;
if (sec->addrExpr && script->hasSectionsCommand) {
// The alignment is ignored.
ctx->outSec->addr = pos;
} else {
// ctx->outSec->alignment is the max of ALIGN and the maximum of input
// section alignments.
- ctx->outSec->addr = advance(0, ctx->outSec->alignment);
- expandMemoryRegions(ctx->outSec->addr - pos);
+ dot = alignTo(dot, ctx->outSec->alignment);
+ ctx->outSec->addr = dot;
+ expandMemoryRegions(dot - pos);
}
}
@@ -1071,8 +1055,18 @@ void LinkerScript::assignOffsets(OutputSection *sec) {
// Handle a single input section description command.
// It calculates and assigns the offsets for each section and also
// updates the output section size.
- for (InputSection *sec : cast<InputSectionDescription>(cmd)->sections)
- output(sec);
+ for (InputSection *isec : cast<InputSectionDescription>(cmd)->sections) {
+ assert(ctx->outSec == isec->getParent());
+ const uint64_t pos = dot;
+ dot = alignTo(dot, isec->alignment);
+ isec->outSecOff = dot - ctx->outSec->addr;
+ dot += isec->getSize();
+
+ // Update output section size after adding each section. This is so that
+ // SIZEOF works correctly in the case below:
+ // .foo { *(.aaa) a = SIZEOF(.foo); *(.bbb) }
+ expandOutputSection(dot - pos);
+ }
}
// Non-SHF_ALLOC sections do not affect the addresses of other OutputSections
diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h
index f9db8f61a9e3..614ecb9f21be 100644
--- a/lld/ELF/LinkerScript.h
+++ b/lld/ELF/LinkerScript.h
@@ -293,8 +293,6 @@ class LinkerScript final {
findMemoryRegion(OutputSection *sec, MemoryRegion *hint);
void switchTo(OutputSection *sec);
- uint64_t advance(uint64_t size, unsigned align);
- void output(InputSection *sec);
void assignOffsets(OutputSection *sec);
More information about the llvm-commits
mailing list