[lld] [LLD] Implement --enable-non-contiguous-regions (PR #90007)
Peter Smith via llvm-commits
llvm-commits at lists.llvm.org
Wed May 1 02:46:06 PDT 2024
================
@@ -1364,6 +1432,107 @@ const Defined *LinkerScript::assignAddresses() {
return getChangedSymbolAssignment(oldValues);
}
+static bool isRegionOverflowed(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)
+ continue;
+
+ DenseSet<InputSection *> spills;
+ for (SectionCommand *cmd : reverse(osec->commands)) {
+ if (!isRegionOverflowed(osec->memRegion) &&
+ !isRegionOverflowed(osec->lmaRegion))
+ break;
+
+ auto *is = dyn_cast<InputSectionDescription>(cmd);
+ if (!is)
+ continue;
+ for (InputSection *isec : reverse(is->sections)) {
+ // Potential spill locations cannot be spilled.
+ if (isa<SpillInputSection>(isec))
+ continue;
+
+ // Find the next spill location.
+ auto it = spillLists.find(isec);
+ if (it == spillLists.end())
+ continue;
+
+ spilled = true;
+ SpillList &list = it->second;
----------------
smithp35 wrote:
It was a similar situation to a previous comment, there were several other lists, spills and spilllist and I found myself having to double check which was which.
I don't have a particularly strong opinion though, so feel free to ignore me here.
https://github.com/llvm/llvm-project/pull/90007
More information about the llvm-commits
mailing list