[PATCH] D55423: [LLD][ELF] - A fix for "linker script assignment loses relative nature of section" bug.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 18 02:09:55 PDT 2019


grimar updated this revision to Diff 195688.
grimar added a comment.

- Remove @PLT suffixes from the calls in the test. I think I put them by mistake in the initial version of the patch.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55423/new/

https://reviews.llvm.org/D55423

Files:
  ELF/Relocations.cpp
  test/ELF/linkerscript/symbol-alias-relocation.s
  test/ELF/linkerscript/symbol-location.s


Index: test/ELF/linkerscript/symbol-location.s
===================================================================
--- test/ELF/linkerscript/symbol-location.s
+++ test/ELF/linkerscript/symbol-location.s
@@ -1,15 +0,0 @@
-# REQUIRES: x86
-# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
-# RUN: echo "foo = 1;" > %t.script
-# RUN: not ld.lld -pie -o %t --script %t.script %t.o 2>&1 | FileCheck %s
-
-## Here we check that symbol 'foo' location is reported properly.
-
-# CHECK: error: relocation R_X86_64_PLT32 cannot refer to absolute symbol: foo
-# CHECK: >>> defined in {{.*}}.script:1
-# CHECK: >>> referenced by {{.*}}.o:(.text+0x1)
-
-.text
-.globl _start
-_start:
- call foo at PLT
Index: test/ELF/linkerscript/symbol-alias-relocation.s
===================================================================
--- test/ELF/linkerscript/symbol-alias-relocation.s
+++ test/ELF/linkerscript/symbol-alias-relocation.s
@@ -0,0 +1,36 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: echo "aliasto__text = __text; SECTIONS { .text 0x1000 : { __text = . ; *(.text) } }" > %t.script
+# RUN: ld.lld -pie -o %t --script %t.script %t.o
+# RUN: llvm-readobj -symbols %t | FileCheck %s
+
+## Check that alias 'aliasto__text' has the correct value.
+## (It should belong to the section .text and point to it's start).
+
+# CHECK:      Symbol {
+# CHECK:        Name: __text
+# CHECK-NEXT:   Value: 0x1000
+# CHECK-NEXT:   Size: 0
+# CHECK-NEXT:   Binding: Global
+# CHECK-NEXT:   Type: None
+# CHECK-NEXT:   Other: 0
+# CHECK-NEXT:   Section: .text
+# CHECK-NEXT: }
+
+# CHECK:      Symbol {
+# CHECK:        Name: aliasto__text
+# CHECK-NEXT:   Value: 0x1000
+# CHECK-NEXT:   Size: 0
+# CHECK-NEXT:   Binding: Global
+# CHECK-NEXT:   Type: None
+# CHECK-NEXT:   Other: 0
+# CHECK-NEXT:   Section: .text
+# CHECK-NEXT: }
+
+.text
+.globl _start
+.type _start, %function
+_start:
+.globl aliasto__text
+   call __text
+   call aliasto__text
Index: ELF/Relocations.cpp
===================================================================
--- ELF/Relocations.cpp
+++ ELF/Relocations.cpp
@@ -421,6 +421,11 @@
   if (E == R_SIZE)
     return true;
 
+  // We set the final symbols values for linker script defined symbols later.
+  // They always can be computed as a link time constant.
+  if (Sym.ScriptDefined)
+    return true;
+
   // For the target and the relocation, we want to know if they are
   // absolute or relative.
   bool AbsVal = isAbsoluteValue(Sym);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55423.195688.patch
Type: text/x-patch
Size: 2579 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190418/962a4976/attachment.bin>


More information about the llvm-commits mailing list