[PATCH] D22977: [LinkerScript] Support decimal values for filler
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 29 14:41:29 PDT 2016
davide created this revision.
davide added a reviewer: ruiu.
davide added a subscriber: llvm-commits.
Discussed with Rui on IRC
https://reviews.llvm.org/D22977
Files:
ELF/LinkerScript.cpp
test/ELF/linkerscript/linkerscript-sections-padding.s
Index: test/ELF/linkerscript/linkerscript-sections-padding.s
===================================================================
--- test/ELF/linkerscript/linkerscript-sections-padding.s
+++ test/ELF/linkerscript/linkerscript-sections-padding.s
@@ -19,13 +19,13 @@
# RUN: hexdump -C %t.out | FileCheck -check-prefix=NO %s
# NO: 00000120 66 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
-## Filler should be a hex value (1):
+## Decimal value.
# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =99 }" > %t.script
-# RUN: not ld.lld -o %t.out --script %t.script %t 2>&1 \
-# RUN: | FileCheck --check-prefix=ERR %s
-# ERR: filler should be a hexadecimal value
+# RUN: ld.lld -o %t.out --script %t.script %t
+# RUN: hexdump -C %t.out | FileCheck -check-prefix=DEC %s
+# DEC: 00000120 66 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63
-## Filler should be a hex value (2):
+## Invalid hex value:
# 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
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -35,6 +35,8 @@
#include "llvm/Support/Path.h"
#include "llvm/Support/StringSaver.h"
+#include <sstream>
+
using namespace llvm;
using namespace llvm::ELF;
using namespace llvm::object;
@@ -797,13 +799,27 @@
std::vector<uint8_t> ScriptParser::readOutputSectionFiller() {
StringRef Tok = peek();
+ std::string HexStr;
if (!Tok.startswith("="))
return {};
if (!Tok.startswith("=0x")) {
- setError("filler should be a hexadecimal value");
- return {};
+ // This must be a decimal.
+ Tok = Tok.substr(1);
+ unsigned int Value;
+ if (Tok.getAsInteger(10, Value)) {
+ setError("filler should be a decimal/hexadecimal value");
+ return {};
+ }
+ if (Value > 255)
+ setError("only single bytes decimal are supported for the filler now");
+ raw_string_ostream SO(HexStr);
+ SO.write_hex(Value);
+ SO.flush();
+ Tok = HexStr;
+ }
+ else {
+ Tok = Tok.substr(3);
}
- Tok = Tok.substr(3);
next();
return parseHex(Tok);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22977.66176.patch
Type: text/x-patch
Size: 2223 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160729/aaa889da/attachment.bin>
More information about the llvm-commits
mailing list