[lld] [LLD][ELF] Allow memory region in OVERLAY (PR #133540)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 29 12:16:13 PDT 2025


https://github.com/MaskRay approved this pull request.

Thanks! Code looks great. Consider renaming lastInOverlay to firstInOverlay and moving the code to `expand*` to place overlay code together.

```patch
diff --git i/lld/ELF/LinkerScript.cpp w/lld/ELF/LinkerScript.cpp
index 8437049a209d..58bea55e4e97 100644
--- i/lld/ELF/LinkerScript.cpp
+++ w/lld/ELF/LinkerScript.cpp
@@ -186,2 +186,4 @@ void LinkerScript::expandOutputSection(uint64_t size) {
   if (state->outSec->inOverlay) {
+    if (state->outSec->firstInOverlay)
+      state->overlaySize = 0;
     // Expand the overlay if necessary, and expand the region by the
@@ -1286,4 +1288,2 @@ bool LinkerScript::assignOffsets(OutputSection *sec) {
     dot = savedDot;
-  } else if (sec->lastInOverlay) {
-    state->overlaySize = 0;
   }
diff --git i/lld/ELF/ScriptParser.cpp w/lld/ELF/ScriptParser.cpp
index 09786aebaf33..555fceccc4a7 100644
--- i/lld/ELF/ScriptParser.cpp
+++ w/lld/ELF/ScriptParser.cpp
@@ -590,3 +590,3 @@ SmallVector<SectionCommand *, 0> ScriptParser::readOverlay() {
   if (!v.empty())
-    static_cast<OutputDesc *>(v.back())->osec.lastInOverlay = true;
+    static_cast<OutputDesc *>(v[0])->osec.firstInOverlay = true;
   if (consume(">")) {
```

https://github.com/llvm/llvm-project/pull/133540


More information about the llvm-commits mailing list