[PATCH] D23142: Make filler expression compatible with gold.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 3 15:43:33 PDT 2016


ruiu created this revision.
ruiu added a reviewer: davide.
ruiu added a subscriber: llvm-commits.

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.

https://reviews.llvm.org/D23142

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
@@ -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
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -38,6 +38,7 @@
 using namespace llvm;
 using namespace llvm::ELF;
 using namespace llvm::object;
+using namespace llvm::support::endian;
 using namespace lld;
 using namespace lld::elf;
 
@@ -843,18 +844,21 @@
   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 Val;
+  if (Tok.substr(1).getAsInteger(0, Val)) {
+    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)};
+  std::vector<uint8_t> V(4);
+  write32be(V.data(), Val);
+  return V;
 }
 
 void ScriptParser::readProvide(bool Hidden) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23142.66726.patch
Type: text/x-patch
Size: 2047 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160803/03da5ad3/attachment.bin>


More information about the llvm-commits mailing list