Index: lld/trunk/ELF/LinkerScript.cpp =================================================================== --- lld/trunk/ELF/LinkerScript.cpp +++ lld/trunk/ELF/LinkerScript.cpp @@ -956,24 +956,24 @@ return Cmd; } +// Read "=" where is an octal/decimal/hexadecimal number. +// https://sourceware.org/binutils/docs/ld/Output-Section-Fill.html +// +// ld.gold is not fully compatible with ld.bfd. ld.bfd handles +// 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 ScriptParser::readOutputSectionFiller() { - StringRef Tok = peek(); - if (!Tok.startswith("=")) + if (!peek().startswith("=")) return {}; - next(); - // Read a hexstring of arbitrary length. - if (Tok.startswith("=0x")) - return parseHex(Tok.substr(3)); - - // 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. + StringRef Tok = next(); uint32_t V; if (Tok.substr(1).getAsInteger(0, V)) { setError("invalid filler expression: " + Tok); return {}; } - return { uint8_t(V >> 24), uint8_t(V >> 16), uint8_t(V >> 8), uint8_t(V) }; + return {uint8_t(V >> 24), uint8_t(V >> 16), uint8_t(V >> 8), uint8_t(V)}; } SymbolAssignment *ScriptParser::readProvideHidden(bool Provide, bool Hidden) { Index: lld/trunk/test/ELF/linkerscript/linkerscript-sections-padding.s =================================================================== --- lld/trunk/test/ELF/linkerscript/linkerscript-sections-padding.s +++ lld/trunk/test/ELF/linkerscript/linkerscript-sections-padding.s @@ -2,16 +2,16 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t ## Check that padding value works: -# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =0x112233445566778899 }" > %t.script +# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =0x1122 }" > %t.script # RUN: ld.lld -o %t.out --script %t.script %t # RUN: llvm-objdump -s %t.out | FileCheck -check-prefix=YES %s -# YES: 0120 66223344 55667788 99112233 44556677 +# YES: 0120 66001122 00001122 00001122 00001122 ## Confirming that address was correct: -# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =0x998877665544332211 }" > %t.script +# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =0x99887766 }" > %t.script # RUN: ld.lld -o %t.out --script %t.script %t # RUN: llvm-objdump -s %t.out | FileCheck -check-prefix=YES2 %s -# YES2: 0120 66887766 55443322 11998877 66554433 +# YES2: 0120 66887766 99887766 99887766 99887766 ## Default padding value is 0x00: # RUN: echo "SECTIONS { .mysec : { *(.mysec*) } }" > %t.script @@ -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: not a hexadecimal value: XX +# ERR2: invalid filler expression: =0x99XX .section .mysec.1,"a" .align 16