[lld] [ELF] OVERLAY: support optional start address and LMA (PR #77272)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 8 16:12:01 PST 2024


================
@@ -547,10 +549,15 @@ SmallVector<SectionCommand *, 0> ScriptParser::readOverlay() {
     // starting from the base load address specified.
     OutputDesc *osd = readOverlaySectionDescription();
     osd->osec.addrExpr = addrExpr;
-    if (prev)
+    if (prev) {
       osd->osec.lmaExpr = [=] { return prev->getLMA() + prev->size; };
-    else
+    } else {
       osd->osec.lmaExpr = lmaExpr;
+      // Ensure that the first section, even if empty, is not discarded.
+      // Subsequent sections share its address.
+      osd->osec.usedInExpression = true;
+      addrExpr = [=]() -> ExprValue { return {&osd->osec, false, 0, ""}; };
----------------
MaskRay wrote:

Thanks for the suggestion. I reworded it a bit.
```
+  // When AT is omitted, LMA should equal VMA. script->getDot() when evaluating
+  // lmaExpr will ensure this, even if the start address is specified.
```

Setting `lmaExpr` to `script->getDot()` ensures that LMA propagation in `LinkerScript::assignOffsets` is disabled and `state->lmaOffset = sec->lmaExpr().getValue() - dot;` evaluates to 0.

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


More information about the llvm-commits mailing list