[PATCH] D23181: Make lld actually compatible with gold in terms of filler handling.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 4 14:56:23 PDT 2016


ruiu updated this revision to Diff 66862.
ruiu added a comment.

- Update comments.


https://reviews.llvm.org/D23181

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
@@ -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
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -855,24 +855,24 @@
   return Cmd;
 }
 
+// Read "=<number>" where <number> 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<uint8_t> 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::readProvide(bool Hidden) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23181.66862.patch
Type: text/x-patch
Size: 2964 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160804/7c8c93e1/attachment.bin>


More information about the llvm-commits mailing list