[lld] r307794 - [ELF] - Allow moving location counter backward in some cases.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 12 07:50:25 PDT 2017


Author: grimar
Date: Wed Jul 12 07:50:25 2017
New Revision: 307794

URL: http://llvm.org/viewvc/llvm-project?rev=307794&view=rev
Log:
[ELF] - Allow moving location counter backward in some cases.

Patch removes restriction about moving location counter
backwards outside of output sections declarations.

That may be useful for some apps relying on such scripts, 
known example is linux kernel.

Differential revision: https://reviews.llvm.org/D34977

Modified:
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/test/ELF/linkerscript/locationcountererr2.s
    lld/trunk/test/ELF/linkerscript/out-of-order.s

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=307794&r1=307793&r2=307794&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Wed Jul 12 07:50:25 2017
@@ -111,13 +111,9 @@ LinkerScript::getOrCreateOutputSectionCo
 
 void LinkerScript::setDot(Expr E, const Twine &Loc, bool InSec) {
   uint64_t Val = E().getValue();
-  if (Val < Dot) {
-    if (InSec)
-      error(Loc + ": unable to move location counter backward for: " +
-            CurAddressState->OutSec->Name);
-    else
-      error(Loc + ": unable to move location counter backward");
-  }
+  if (Val < Dot && InSec)
+    error(Loc + ": unable to move location counter backward for: " +
+          CurAddressState->OutSec->Name);
   Dot = Val;
   // Update to location counter means update to section size.
   if (InSec)

Modified: lld/trunk/test/ELF/linkerscript/locationcountererr2.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/locationcountererr2.s?rev=307794&r1=307793&r2=307794&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/locationcountererr2.s (original)
+++ lld/trunk/test/ELF/linkerscript/locationcountererr2.s Wed Jul 12 07:50:25 2017
@@ -2,8 +2,10 @@
 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
 # RUN: echo "SECTIONS {" > %t.script
 # RUN: echo ". = 0x20; . = 0x10; .text : {} }" >> %t.script
-# RUN: not ld.lld %t.o --script %t.script -o %t -shared 2>&1 | FileCheck %s
-# CHECK: {{.*}}.script:2: unable to move location counter backward
+# RUN: ld.lld %t.o --script %t.script -o %t -shared
+# RUN: llvm-objdump -section-headers %t | FileCheck %s
+# CHECK: Idx Name   Size      Address
+# CHECK:  1 .text 00000000 0000000000000010
 
 # RUN: echo "SECTIONS { . = 0x20; . = ASSERT(0x1, "foo"); }" > %t2.script
 # RUN: ld.lld %t.o --script %t2.script -o %t -shared

Modified: lld/trunk/test/ELF/linkerscript/out-of-order.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/out-of-order.s?rev=307794&r1=307793&r2=307794&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/out-of-order.s (original)
+++ lld/trunk/test/ELF/linkerscript/out-of-order.s Wed Jul 12 07:50:25 2017
@@ -1,9 +1,18 @@
 # REQUIRES: x86
 # RUN: llvm-mc -filetype=obj -triple=x86_64-linux %s -o %t.o
 # RUN: echo "SECTIONS { .data 0x4000 : { *(.data) } .text 0x2000 : { *(.text) } }" > %t.script
-# RUN: not ld.lld -o %t.so --script %t.script %t.o -shared 2>&1 | FileCheck %s
+# RUN: ld.lld -o %t.so --script %t.script %t.o -shared
+# RUN: llvm-objdump -section-headers %t.so | FileCheck %s
 
-# CHECK:  error: {{.*}}.script:1: unable to move location counter backward
+# CHECK:      Sections:
+# CHECK-NEXT: Idx Name          Size      Address          Type
+# CHECK-NEXT:   0               00000000 0000000000000000
+# CHECK-NEXT:   1 .data         00000008 0000000000004000  DATA
+# CHECK-NEXT:   2 .dynamic      00000060 0000000000004008
+# CHECK-NEXT:   3 .text         00000008 0000000000002000  TEXT DATA
+# CHECK-NEXT:   4 .dynsym       00000018 0000000000002008
+# CHECK-NEXT:   5 .hash         00000010 0000000000002020
+# CHECK-NEXT:   6 .dynstr       00000001 0000000000002030
 
 .quad 0
 .data




More information about the llvm-commits mailing list