[PATCH] D118491: [lld][ELF] support READONLY in linker script section
Luca Boccassi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 28 10:01:39 PST 2022
bluca created this revision.
bluca added reviewers: ruiu, MaskRay.
Herald added subscribers: arichardson, emaste.
bluca requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
bfd recently added a READONLY attribute for sections, as they
are created writable by default. Support the keyword in lld too,
but note that it's a no-op here, as sections are already read-only
by default, but it's needed to allow the same linker scripts to be
used.
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=6b86da53d5ee2022b9065f445d23356190380746
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D118491
Files:
lld/ELF/ScriptParser.cpp
lld/test/ELF/linkerscript/note-section.test
Index: lld/test/ELF/linkerscript/note-section.test
===================================================================
--- lld/test/ELF/linkerscript/note-section.test
+++ lld/test/ELF/linkerscript/note-section.test
@@ -5,7 +5,7 @@
SECTIONS
{
- .note.package : ALIGN(4) {
+ .note.package (READONLY) : ALIGN(4) {
BYTE(0x04) BYTE(0x00) BYTE(0x00) BYTE(0x00) /* Length of Owner including NUL */
BYTE(0x0e) BYTE(0x00) BYTE(0x00) BYTE(0x00) /* Length of Value including NUL */
BYTE(0xaa) BYTE(0xaa) BYTE(0xaa) BYTE(0xaa) /* Note ID */
Index: lld/ELF/ScriptParser.cpp
===================================================================
--- lld/ELF/ScriptParser.cpp
+++ lld/ELF/ScriptParser.cpp
@@ -788,19 +788,23 @@
}
// Tries to read the special directive for an output section definition which
-// can be one of following: "(NOLOAD)", "(COPY)", "(INFO)" or "(OVERLAY)".
-// Tok1 and Tok2 are next 2 tokens peeked. See comment for readSectionAddressType below.
+// can be one of following: "(NOLOAD)", "(COPY)", "(INFO)", "(OVERLAY)" or
+// "(READONLY)". 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")
+ if (tok2 != "NOLOAD" && tok2 != "COPY" && tok2 != "INFO" &&
+ tok2 != "OVERLAY" && tok2 != "READONLY")
return false;
expect("(");
if (consume("NOLOAD")) {
cmd->noload = true;
cmd->type = SHT_NOBITS;
- } else {
+ } else if (!consume("READONLY")) {
+ // READONLY is supported by bfd, but we add sections as RO by default, so
+ // it's a no-op needed to let users run the same linker scripts
skip(); // This is "COPY", "INFO" or "OVERLAY".
cmd->nonAlloc = true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118491.404067.patch
Type: text/x-patch
Size: 1909 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220128/48ade3cb/attachment.bin>
More information about the llvm-commits
mailing list