diff options
| author | Rui Ueyama <ruiu@google.com> | 2016-08-03 23:25:15 +0000 |
|---|---|---|
| committer | Rui Ueyama <ruiu@google.com> | 2016-08-03 23:25:15 +0000 |
| commit | 965827d6742b5296cfbb247f88b2904dd75b9703 (patch) | |
| tree | fba3b2334d642cb929c5dac90b407a572a753f4d | |
| parent | 15a3ce0f59eaad29205279701c58b654343fba11 (diff) | |
| download | bcm5719-llvm-965827d6742b5296cfbb247f88b2904dd75b9703.tar.gz bcm5719-llvm-965827d6742b5296cfbb247f88b2904dd75b9703.zip | |
Make filler expression compatible with gold.
Previously, a decimal filler expression is interpreted as a byte value.
Gold on the other hand use it as a 32-bit big-endian value.
This patch fixes the compatibility issue.
Differential Revision: https://reviews.llvm.org/D23142
llvm-svn: 277680
| -rw-r--r-- | lld/ELF/LinkerScript.cpp | 15 | ||||
| -rw-r--r-- | lld/test/ELF/linkerscript/linkerscript-sections-padding.s | 4 |
2 files changed, 10 insertions, 9 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index e1342e2527a..808d62433e6 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -843,18 +843,19 @@ std::vector<uint8_t> ScriptParser::readOutputSectionFiller() { if (!Tok.startswith("=")) return {}; next(); + + // Read a hexstring of arbitrary length. if (Tok.startswith("=0x")) return parseHex(Tok.substr(3)); - // This must be a decimal. - unsigned int Value; - if (Tok.substr(1).getAsInteger(10, Value)) { - setError("filler should be a decimal/hexadecimal value"); + // Read a decimal or octal value as a big-endian 32 bit value. + // Why do this? I don't know, but that's what gold does. + uint32_t V; + if (Tok.substr(1).getAsInteger(0, V)) { + setError("invalid filler expression: " + Tok); return {}; } - if (Value > 255) - setError("only single bytes decimal are supported for the filler now"); - return {static_cast<unsigned char>(Value)}; + return { uint8_t(V >> 24), uint8_t(V >> 16), uint8_t(V >> 8), uint8_t(V) }; } void ScriptParser::readProvide(bool Hidden) { diff --git a/lld/test/ELF/linkerscript/linkerscript-sections-padding.s b/lld/test/ELF/linkerscript/linkerscript-sections-padding.s index aadd5e82976..78d1ffc14f5 100644 --- a/lld/test/ELF/linkerscript/linkerscript-sections-padding.s +++ b/lld/test/ELF/linkerscript/linkerscript-sections-padding.s @@ -20,10 +20,10 @@ # NO: 00000120 66 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ## Decimal value. -# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =99 }" > %t.script +# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =777 }" > %t.script # 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 +# DEC: 00000120 66 00 03 09 00 00 03 09 00 00 03 09 00 00 03 09 ## Invalid hex value: # RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =0x99XX }" > %t.script |

