-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[LLD][ELF] Support OVERLAY symbol assignments #159895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[LLD][ELF] Support OVERLAY symbol assignments #159895
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-lld @llvm/pr-subscribers-lld-elf Author: None (CompilerWang) ChangesThis enables symbol assignment within OVERLAY linker script descriptions. This is a valuable addition to the OVERLAY syntax, as it allows defining symbols that can be used for alignment within overlay sections. Full diff: https://github.com/llvm/llvm-project/pull/159895.diff 2 Files Affected:
diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index ddfa24d9cacf5..babc5cfbf43ae 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -996,8 +996,13 @@ OutputDesc *ScriptParser::readOverlaySectionDescription() {
ctx.script->createOutputSection(readName(), getCurrentLocation());
osd->osec.inOverlay = true;
expect("{");
- while (auto tok = till("}"))
- osd->osec.commands.push_back(readInputSectionDescription(tok));
+ while (auto tok = till("}")) {
+ if (SymbolAssignment *assign = readAssignment(tok)) {
+ osd->osec.commands.push_back(assign);
+ } else {
+ osd->osec.commands.push_back(readInputSectionDescription(tok));
+ }
+ }
osd->osec.phdrs = readOutputSectionPhdrs();
return osd;
}
diff --git a/lld/test/ELF/linkerscript/overlay-symbol-assign.test b/lld/test/ELF/linkerscript/overlay-symbol-assign.test
new file mode 100644
index 0000000000000..b48385cf22358
--- /dev/null
+++ b/lld/test/ELF/linkerscript/overlay-symbol-assign.test
@@ -0,0 +1,31 @@
+# REQUIRES: x86
+# RUN: echo 'nop; .section .small, "a"; .long 0; .section .big1, "a"; .quad 1; .section .big2, "a"; .quad 2;' \
+# RUN: | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t.o
+# RUN: ld.lld %t.o --script %s -o %t
+
+SECTIONS {
+ OVERLAY 0x1000 : AT ( 0x4000 ) {
+ .out.big {
+ *(.big1)
+ . = ALIGN(0x100);
+ *(.big2)
+ }
+ .out.small { *(.small) }
+ }
+}
+
+## A variant of overlay.test with explicit program header assingment.
+## Check that we generate two program headers consistent with the overlay
+
+# RUN: llvm-readelf --sections -l %t | FileCheck %s
+
+# CHECK: Section Headers:
+# CHECK: Name Type Address Off Size
+# CHECK: .out.big PROGBITS 0000000000001000 001000 000108
+# CHECK-NEXT: .out.small PROGBITS 0000000000001000 002000 000004
+
+
+# CHECK: Program Headers:
+# CHECK: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
+# CHECK-NEXT: LOAD 0x001000 0x0000000000001000 0x0000000000004000 0x000108 0x000108 R 0x1000
+# CHECK-NEXT: LOAD 0x002000 0x0000000000001000 0x0000000000004108 0x000004 0x000004 R 0x1000
\ No newline at end of file
|
@EugeneZelenko Could you please be a reviewer or add other reviewer to this PR? Thank you! |
@MaskRay Could you please be a reviewer or add other reviewer to this PR? Thank you! |
This enables symbol assignment within OVERLAY linker script descriptions. This is a valuable addition to the OVERLAY syntax, as it allows defining symbols that can be used for alignment within overlay sections.
64eb239
to
68e8da8
Compare
# CHECK: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align | ||
# CHECK-NEXT: LOAD 0x001000 0x0000000000001000 0x0000000000004000 0x000108 0x000108 R 0x1000 | ||
# CHECK-NEXT: LOAD 0x002000 0x0000000000001000 0x0000000000004108 0x000004 0x000004 R 0x1000 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete blank lines at the end
# CHECK: Name Type Address Off Size | ||
# CHECK: .out.big PROGBITS 0000000000001000 001000 000108 | ||
# CHECK-NEXT: .out.small PROGBITS 0000000000001000 002000 000004 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just one blank line
@@ -0,0 +1,32 @@ | |||
# REQUIRES: x86 | |||
# RUN: echo 'nop; .section .small, "a"; .long 0; .section .big1, "a"; .quad 1; .section .big2, "a"; .quad 2;' \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use RUN: rm -rf %t && split-file %s %t && cd %t
pattern to prepare the input assembly file.
You can use #--- a.s
for assembly and #--- 1.lds
for the linker script.
.out.big { | ||
*(.big1) | ||
. = ALIGN(0x100); | ||
*(.big2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also define a symbol sym = .
? Does GNU ld accept it?
This enables symbol assignment within OVERLAY linker script descriptions. This is a valuable addition to the OVERLAY syntax, as it allows defining symbols that can be used for alignment within overlay sections.
#158569