[lld] r280708 - [ELF] - Linkerscript: implemented FILL command as alias for =fillexpr
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 6 06:51:58 PDT 2016
Author: grimar
Date: Tue Sep 6 08:51:57 2016
New Revision: 280708
URL: http://llvm.org/viewvc/llvm-project?rev=280708&view=rev
Log:
[ELF] - Linkerscript: implemented FILL command as alias for =fillexpr
Patch implements FILL just as alias for =fillexpr.
This allows to make implementation much shorted and simpler than D24186.
Differential revision: https://reviews.llvm.org/D24227
Added:
lld/trunk/test/ELF/linkerscript/linkerscript-fill.s
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/test/ELF/linkerscript/sections-padding.s
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=280708&r1=280707&r2=280708&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Tue Sep 6 08:51:57 2016
@@ -621,8 +621,9 @@ private:
void readVersionScriptCommand();
SymbolAssignment *readAssignment(StringRef Name);
+ std::vector<uint8_t> readFill();
OutputSectionCommand *readOutputSectionDescription(StringRef OutSec);
- std::vector<uint8_t> readOutputSectionFiller();
+ std::vector<uint8_t> readOutputSectionFiller(StringRef Tok);
std::vector<StringRef> readOutputSectionPhdrs();
InputSectionDescription *readInputSectionDescription(StringRef Tok);
Regex readFilePatterns();
@@ -980,6 +981,14 @@ Expr ScriptParser::readAssert() {
};
}
+std::vector<uint8_t> ScriptParser::readFill() {
+ expect("(");
+ std::vector<uint8_t> V = readOutputSectionFiller(next());
+ expect(")");
+ expect(";");
+ return V;
+}
+
OutputSectionCommand *
ScriptParser::readOutputSectionDescription(StringRef OutSec) {
OutputSectionCommand *Cmd = new OutputSectionCommand(OutSec);
@@ -1009,6 +1018,8 @@ ScriptParser::readOutputSectionDescripti
StringRef Tok = next();
if (SymbolAssignment *Assignment = readProvideOrAssignment(Tok))
Cmd->Commands.emplace_back(Assignment);
+ else if (Tok == "FILL")
+ Cmd->Filler = readFill();
else if (Tok == "SORT")
readSort();
else if (peek() == "(")
@@ -1017,7 +1028,8 @@ ScriptParser::readOutputSectionDescripti
setError("unknown command " + Tok);
}
Cmd->Phdrs = readOutputSectionPhdrs();
- Cmd->Filler = readOutputSectionFiller();
+ if (peek().startswith("="))
+ Cmd->Filler = readOutputSectionFiller(next().drop_front());
return Cmd;
}
@@ -1028,13 +1040,9 @@ ScriptParser::readOutputSectionDescripti
// hexstrings as blobs of arbitrary sizes, while ld.gold handles them
// as 32-bit big-endian values. We will do the same as ld.gold does
// because it's simpler than what ld.bfd does.
-std::vector<uint8_t> ScriptParser::readOutputSectionFiller() {
- if (!peek().startswith("="))
- return {};
-
- StringRef Tok = next();
+std::vector<uint8_t> ScriptParser::readOutputSectionFiller(StringRef Tok) {
uint32_t V;
- if (Tok.substr(1).getAsInteger(0, V)) {
+ if (Tok.getAsInteger(0, V)) {
setError("invalid filler expression: " + Tok);
return {};
}
Added: lld/trunk/test/ELF/linkerscript/linkerscript-fill.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/linkerscript-fill.s?rev=280708&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/linkerscript-fill.s (added)
+++ lld/trunk/test/ELF/linkerscript/linkerscript-fill.s Tue Sep 6 08:51:57 2016
@@ -0,0 +1,30 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: echo "SECTIONS { \
+# RUN: .out : { \
+# RUN: FILL(0x11111111); \
+# RUN: *(.aaa) \
+# RUN: . += 4; \
+# RUN: *(.bbb) \
+# RUN: . += 4; \
+# RUN: FILL(0x22222222); \
+# RUN: . += 4; \
+# RUN: } \
+# RUN: }; " > %t.script
+# RUN: ld.lld -o %t --script %t.script %t.o
+# RUN: llvm-objdump -s %t | FileCheck %s
+
+# CHECK: Contents of section .out:
+# CHECK-NEXT: 0120 aa222222 22bb2222 22222222 2222
+
+.text
+.globl _start
+_start:
+
+.section .aaa, "a"
+.align 1
+.byte 0xAA
+
+.section .bbb, "a"
+.align 1
+.byte 0xBB
Modified: lld/trunk/test/ELF/linkerscript/sections-padding.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/sections-padding.s?rev=280708&r1=280707&r2=280708&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/sections-padding.s (original)
+++ lld/trunk/test/ELF/linkerscript/sections-padding.s Tue Sep 6 08:51:57 2016
@@ -29,7 +29,7 @@
# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =0x99XX }" > %t.script
# RUN: not ld.lld -o %t.out --script %t.script %t 2>&1 \
# RUN: | FileCheck --check-prefix=ERR2 %s
-# ERR2: invalid filler expression: =0x99XX
+# ERR2: invalid filler expression: 0x99XX
.section .mysec.1,"a"
.align 16
More information about the llvm-commits
mailing list