[lld] [LLD] Implement --enable-non-contiguous-regions (PR #90007)
Daniel Thornburgh via llvm-commits
llvm-commits at lists.llvm.org
Fri May 10 16:32:12 PDT 2024
================
@@ -1364,6 +1436,117 @@ const Defined *LinkerScript::assignAddresses() {
return getChangedSymbolAssignment(oldValues);
}
+static bool hasRegionOverflowed(MemoryRegion *mr) {
+ if (!mr)
+ return false;
+ return mr->curPos - mr->getOrigin() > mr->getLength();
+}
+
+// Spill input sections in reverse order of address assignment to (potentially)
+// bring memory regions out of overflow. The size savings of a spill can only be
+// estimated, since general linker script arithmetic may occur afterwards.
+// Under-estimates may cause unnecessary spills, but over-estimates can always
+// be corrected on the next pass.
+bool LinkerScript::spillSections() {
+ if (!config->enableNonContiguousRegions)
+ return false;
+
+ bool spilled = false;
+ for (SectionCommand *cmd : reverse(sectionCommands)) {
+ auto *od = dyn_cast<OutputDesc>(cmd);
+ if (!od)
+ continue;
+ OutputSection *osec = &od->osec;
+ if (!osec->size || !osec->memRegion)
----------------
mysterymath wrote:
I was split on this for semantic reasons, but looking at it again, I think you're right. Spill decisions should be contiguous; one wouldn't want to reason about holes in the list of spillable sections contributing to a memory region. So one would expect zero size sections to spill until enough actual content is spilled to bring the region is back down to size, even though spilling the zero size sections doesn't really help.
Done.
https://github.com/llvm/llvm-project/pull/90007
More information about the llvm-commits
mailing list