[PATCH] D120045: [lld][ELF] support nested special directives in output sections
Luca Boccassi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 17 05:03:13 PST 2022
bluca created this revision.
Herald added subscribers: arichardson, emaste.
Herald added a reviewer: MaskRay.
bluca requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
bfd recently added support for nesting special directives as:
(FOO (BAR = BAZ)). Support this syntax in lld too for source input
compatibility, and simply skip over unknown directives.
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=c212f39d9a82c6c09f4a1447d9d2ff09843827c5
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D120045
Files:
lld/ELF/ScriptParser.cpp
lld/test/ELF/linkerscript/custom-section-type.s
Index: lld/test/ELF/linkerscript/custom-section-type.s
===================================================================
--- lld/test/ELF/linkerscript/custom-section-type.s
+++ lld/test/ELF/linkerscript/custom-section-type.s
@@ -61,7 +61,7 @@
#--- a.lds
SECTIONS {
progbits (TYPE=SHT_PROGBITS) : { BYTE(1) }
- note (TYPE = SHT_NOTE) : { BYTE(7) *(note) }
+ note (FOOBAR (TYPE = SHT_NOTE)) : { BYTE(7) *(note) }
nobits ( TYPE=SHT_NOBITS) : { BYTE(8) }
init_array (TYPE=SHT_INIT_ARRAY ) : { QUAD(myinit) }
fini_array (TYPE=SHT_FINI_ARRAY) : { QUAD(15) }
Index: lld/ELF/ScriptParser.cpp
===================================================================
--- lld/ELF/ScriptParser.cpp
+++ lld/ELF/ScriptParser.cpp
@@ -798,14 +798,13 @@
// Tries to read the special directive for an output section definition which
// can be one of following: "(NOLOAD)", "(COPY)", "(INFO)", "(OVERLAY)", and
// "(TYPE=<value>)".
+// Also supports nesting special directives as (FOO (BAR)), as ld.bfd does.
+// Unknown directives are simply skipped over.
// Tok1 and Tok2 are next 2 tokens peeked. See comment for
// readSectionAddressType below.
bool ScriptParser::readSectionDirective(OutputSection *cmd, StringRef tok1, StringRef tok2) {
if (tok1 != "(")
return false;
- if (tok2 != "NOLOAD" && tok2 != "COPY" && tok2 != "INFO" &&
- tok2 != "OVERLAY" && tok2 != "TYPE")
- return false;
expect("(");
if (consume("NOLOAD")) {
@@ -826,10 +825,15 @@
cmd->type = readExpr()().getValue();
}
cmd->typeIsSet = true;
- } else {
- skip(); // This is "COPY", "INFO" or "OVERLAY".
+ } else if (consume("COPY") || consume("INFO") || consume("OVERLAY")) {
cmd->nonAlloc = true;
+ } else {
+ skip();
}
+
+ if (peek() == "(" && !readSectionDirective(cmd, "(", peek2()))
+ return false;
+
expect(")");
return true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120045.409596.patch
Type: text/x-patch
Size: 1875 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220217/a1fc26be/attachment.bin>
More information about the llvm-commits
mailing list