[lld] [LLD] Allow all output-section-commands in OVERLAYS. (PR #203524)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 12 06:22:47 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lld-elf
Author: Peter Smith (smithp35)
<details>
<summary>Changes</summary>
The GNU ld grammar for overlays is:
secname1
{
output-section-command
output-section-command
...
}
secname2
...
The output-section-commands are the same as in an OutputSection. At present we have a stripped down parser that only supports InputSectionDescriptions, this does not permit other useful commands such as defining symbols.
Due to recent refactoring it is now simple to reuse the parser for an Output Section command rather than using a custom one.
I came to this via a comment in #<!-- -->202266. There looks to have been an attempt to fix this in #<!-- -->159895, but it looks abandoned after review comments.
Fixes #<!-- -->158569.
---
Full diff: https://github.com/llvm/llvm-project/pull/203524.diff
2 Files Affected:
- (modified) lld/ELF/ScriptParser.cpp (+1-1)
- (added) lld/test/ELF/linkerscript/overlay-symbols.test (+49)
``````````diff
diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index 5383f3eed3f8b..0c54fde488292 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -1027,7 +1027,7 @@ OutputDesc *ScriptParser::readOverlaySectionDescription() {
osd->osec.inOverlay = true;
expect("{");
while (auto tok = till("}"))
- osd->osec.commands.push_back(readInputSectionDescription(tok));
+ readOutputSectionStmt(osd->osec, tok);
osd->osec.phdrs = readOutputSectionPhdrs();
return osd;
}
diff --git a/lld/test/ELF/linkerscript/overlay-symbols.test b/lld/test/ELF/linkerscript/overlay-symbols.test
new file mode 100644
index 0000000000000..69475afdee57b
--- /dev/null
+++ b/lld/test/ELF/linkerscript/overlay-symbols.test
@@ -0,0 +1,49 @@
+# REQUIRES: x86
+# RUN: rm -rf %t && split-file %s %t && cd %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o
+# RUN: ld.lld a.o --script overlay.lds -o a
+# RUN: llvm-readelf --symbols a | FileCheck %s
+
+CHECK: {{[0-9]+}}: 0000000000001000 0 NOTYPE GLOBAL DEFAULT 2 __data_start
+CHECK-NEXT: {{[0-9]+}}: 0000000000001017 0 NOTYPE GLOBAL DEFAULT 2 __data_end
+CHECK-NEXT: {{[0-9]+}}: 0000000000001000 0 NOTYPE GLOBAL DEFAULT 3 __bss_start
+CHECK-NEXT: {{[0-9]+}}: 0000000000001008 0 NOTYPE GLOBAL DEFAULT 3 __bss_end
+CHECK-NEXT: {{[0-9]+}}: 0000000000001017 0 NOTYPE GLOBAL DEFAULT 3 __end
+
+
+#--- overlay.lds
+
+SECTIONS {
+ .text : { *(.text) }
+ OVERLAY 0x1000 : {
+ .data {
+ __data_start = .;
+ *(.data)
+ QUAD(1)
+ LONG(1)
+ SHORT(1)
+ BYTE(1)
+ __data_end = .;
+ }
+ .bss {
+ __bss_start = .;
+ *(.bss)
+ . += 0x4;
+ __bss_end = .;
+ }
+ }
+ __end = .;
+}
+
+#--- a.s
+
+ .globl __start
+ .text
+__start:
+ nop
+
+ .data
+ .space 0x8
+
+ .bss
+ .space 0x4
``````````
</details>
https://github.com/llvm/llvm-project/pull/203524
More information about the llvm-commits
mailing list