[lld] r305006 - Fix a bug in output section directive.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 8 12:47:17 PDT 2017
Author: ruiu
Date: Thu Jun 8 14:47:16 2017
New Revision: 305006
URL: http://llvm.org/viewvc/llvm-project?rev=305006&view=rev
Log:
Fix a bug in output section directive.
Previously, it couldn't parse
SECTIONS .text (0x1000) : { *(.text) }
because "(" was interpreted as the begining of the "(NOLOAD)" directive.
Modified:
lld/trunk/ELF/ScriptParser.cpp
lld/trunk/test/ELF/linkerscript/noload.s
Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=305006&r1=305005&r2=305006&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Thu Jun 8 14:47:16 2017
@@ -76,6 +76,7 @@ private:
BytesDataCommand *readBytesDataCommand(StringRef Tok);
uint32_t readFill();
uint32_t parseFill(StringRef Tok);
+ void readSectionAddressType(OutputSectionCommand *Cmd);
OutputSectionCommand *readOutputSectionDescription(StringRef OutSec);
std::vector<StringRef> readOutputSectionPhdrs();
InputSectionDescription *readInputSectionDescription(StringRef Tok);
@@ -563,26 +564,42 @@ uint32_t ScriptParser::readFill() {
return V;
}
-OutputSectionCommand *
-ScriptParser::readOutputSectionDescription(StringRef OutSec) {
- OutputSectionCommand *Cmd =
- Script->createOutputSectionCommand(OutSec, getCurrentLocation());
-
- if (peek() != ":") {
- // Read an address expression.
- // https://sourceware.org/binutils/docs/ld/Output-Section-Address.html
- if (peek() != "(")
- Cmd->AddrExpr = readExpr();
-
- // Read a section type. Currently, only NOLOAD is supported.
- // https://sourceware.org/binutils/docs/ld/Output-Section-Type.html
- if (consume("(")) {
- expect("NOLOAD");
+// Reads an expression and/or the special directive "(NOLOAD)" for an
+// output section definition.
+//
+// An output section name can be followed by an address expression
+// and/or by "(NOLOAD)". This grammar is not LL(1) because "(" can be
+// interpreted as either the beginning of some expression or "(NOLOAD)".
+//
+// https://sourceware.org/binutils/docs/ld/Output-Section-Address.html
+// https://sourceware.org/binutils/docs/ld/Output-Section-Type.html
+void ScriptParser::readSectionAddressType(OutputSectionCommand *Cmd) {
+ if (consume("(")) {
+ if (consume("NOLOAD")) {
expect(")");
Cmd->Noload = true;
+ return;
}
+ Cmd->AddrExpr = readExpr();
+ expect(")");
+ } else {
+ Cmd->AddrExpr = readExpr();
}
+ if (consume("(")) {
+ expect("NOLOAD");
+ expect(")");
+ Cmd->Noload = true;
+ }
+}
+
+OutputSectionCommand *
+ScriptParser::readOutputSectionDescription(StringRef OutSec) {
+ OutputSectionCommand *Cmd =
+ Script->createOutputSectionCommand(OutSec, getCurrentLocation());
+
+ if (peek() != ":")
+ readSectionAddressType(Cmd);
expect(":");
if (consume("AT"))
Modified: lld/trunk/test/ELF/linkerscript/noload.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/noload.s?rev=305006&r1=305005&r2=305006&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/noload.s (original)
+++ lld/trunk/test/ELF/linkerscript/noload.s Thu Jun 8 14:47:16 2017
@@ -2,7 +2,7 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
# RUN: echo "SECTIONS { \
# RUN: .data_noload_a (NOLOAD) : { *(.data_noload_a) } \
-# RUN: .data_noload_b 0x10000 (NOLOAD) : { *(.data_noload_b) } };" > %t.script
+# RUN: .data_noload_b (0x10000) (NOLOAD) : { *(.data_noload_b) } };" > %t.script
# RUN: ld.lld -o %t --script %t.script %t.o
# RUN: llvm-readobj --symbols -sections %t
More information about the llvm-commits
mailing list