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

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 8 10:26:34 PST 2024


================
@@ -531,13 +531,15 @@ void ScriptParser::readSearchDir() {
 // linker's sections sanity check failures.
 // https://sourceware.org/binutils/docs/ld/Overlay-Description.html#Overlay-Description
 SmallVector<SectionCommand *, 0> ScriptParser::readOverlay() {
-  // VA and LMA expressions are optional, though for simplicity of
-  // implementation we assume they are not. That is what OVERLAY was designed
-  // for first of all: to allow sections with overlapping VAs at different LMAs.
-  Expr addrExpr = readExpr();
-  expect(":");
-  expect("AT");
-  Expr lmaExpr = readParenExpr();
+  Expr addrExpr;
+  if (consume(":")) {
+    addrExpr = [] { return script->getDot(); };
+  } else {
+    addrExpr = readExpr();
+    expect(":");
+  }
+  Expr lmaExpr =
+      consume("AT") ? readParenExpr() : [] { return script->getDot(); };
----------------
smithp35 wrote:

When I first read this I thought we might have a bug when the VMA is set but the LMA defaults to DOT. However as shown in one of the test cases, it looks like when VMA is set then when script->getDot() is read then DOT will be the same as the VMA.

Perhaps worth a comment above lmaExpr
```
// When no AT, then lmaExpr should be the same as addrExpr
// script->getDot() will read correctly for addrExpr() = readExpr()
```

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


More information about the llvm-commits mailing list