[PATCH] D51027: [LLD][ELD] - Do not reject INFO output section type when used with a start address.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 21 00:53:40 PDT 2018
grimar created this revision.
grimar added a reviewer: ruiu.
Herald added subscribers: arichardson, emaste.
Herald added a reviewer: espindola.
This is https://bugs.llvm.org/show_bug.cgi?id=38625
LLD accept this:
.stack (INFO) :
{
but not this:
.stack address_expression (INFO) :
{
The patch fixes it.
https://reviews.llvm.org/D51027
Files:
ELF/ScriptParser.cpp
test/ELF/linkerscript/info-section-type.s
Index: test/ELF/linkerscript/info-section-type.s
===================================================================
--- test/ELF/linkerscript/info-section-type.s
+++ test/ELF/linkerscript/info-section-type.s
@@ -29,5 +29,14 @@
# RUN: ld.lld -o %t --script %t.script %t.o
# RUN: llvm-readobj -sections %t | FileCheck %s --check-prefix=NONALLOC
+# RUN: echo "SECTIONS { .bar 0x20000 (INFO) : { *(.foo) } };" > %t.script
+# RUN: ld.lld -o %t --script %t.script %t.o
+# RUN: llvm-readobj -sections %t | FileCheck %s --check-prefix=NONALLOC
+
+# RUN: echo "SECTIONS { .bar 0x20000 (BAR) : { *(.foo) } };" > %t.script
+# RUN: not ld.lld -o %t --script %t.script %t.o 2>&1 |\
+# RUN: FileCheck %s --check-prefix=UNKNOWN
+# UNKNOWN: unknown section directive: BAR
+
.section .foo,"a", at progbits
.zero 1
Index: ELF/ScriptParser.cpp
===================================================================
--- ELF/ScriptParser.cpp
+++ ELF/ScriptParser.cpp
@@ -80,6 +80,7 @@
ByteCommand *readByteCommand(StringRef Tok);
uint32_t readFill();
uint32_t parseFill(StringRef Tok);
+ bool readOutputSectionType(OutputSection *Cmd);
void readSectionAddressType(OutputSection *Cmd);
OutputSection *readOverlaySectionDescription();
OutputSection *readOutputSectionDescription(StringRef OutSec);
@@ -699,6 +700,18 @@
return V;
}
+bool ScriptParser::readOutputSectionType(OutputSection *Cmd) {
+ if (consume("NOLOAD")) {
+ Cmd->Noload = true;
+ return true;
+ }
+ if (consume("COPY") || consume("INFO") || consume("OVERLAY")) {
+ Cmd->NonAlloc = true;
+ return true;
+ }
+ return false;
+}
+
// Reads an expression and/or the special directive for an output
// section definition. Directive is one of following: "(NOLOAD)",
// "(COPY)", "(INFO)" or "(OVERLAY)".
@@ -712,26 +725,21 @@
// https://sourceware.org/binutils/docs/ld/Output-Section-Type.html
void ScriptParser::readSectionAddressType(OutputSection *Cmd) {
if (consume("(")) {
- if (consume("NOLOAD")) {
+ if (readOutputSectionType(Cmd)) {
expect(")");
- Cmd->Noload = true;
- return;
- }
- if (consume("COPY") || consume("INFO") || consume("OVERLAY")) {
- expect(")");
- Cmd->NonAlloc = true;
return;
}
+
Cmd->AddrExpr = readExpr();
expect(")");
} else {
Cmd->AddrExpr = readExpr();
}
if (consume("(")) {
- expect("NOLOAD");
+ if (!readOutputSectionType(Cmd))
+ setError("unknown section directive: " + peek());
expect(")");
- Cmd->Noload = true;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51027.161656.patch
Type: text/x-patch
Size: 2544 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180821/44bf584c/attachment.bin>
More information about the llvm-commits
mailing list