[PATCH] D42911: [ELF] - Make defsym to work correctly with reserved symbols.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 7 01:02:31 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rLLD324461: [ELF] - Make defsym to work correctly with reserved symbols. (authored by grimar, committed by ).

Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D42911

Files:
  ELF/LinkerScript.cpp
  test/ELF/defsym-reserved-syms.s


Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -74,7 +74,7 @@
   // If the alignment is trivial, we don't have to compute the full
   // value to know the offset. This allows this function to succeed in
   // cases where the output section is not yet known.
-  if (Alignment == 1)
+  if (Alignment == 1 && (!Sec || !Sec->getOutputSection()))
     return Val;
   return getValue() - getSecAddr();
 }
Index: test/ELF/defsym-reserved-syms.s
===================================================================
--- test/ELF/defsym-reserved-syms.s
+++ test/ELF/defsym-reserved-syms.s
@@ -0,0 +1,30 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld -o %t %t.o --defsym=foo2=etext
+# RUN: llvm-readobj -t -s %t | FileCheck %s
+
+## Check 'foo2' value is equal to value of 'etext'.
+# CHECK:     Symbol {
+# CHECK:      Name: foo2
+# CHECK-NEXT:  Value: 0x[[VAL:.*]]
+# CHECK:     Symbol {
+# CHECK:      Name: etext
+# CHECK-NEXT:  Value: 0x[[VAL]]
+
+## Check 'foo2' value set correctly when using
+## reserved symbol 'etext' in expression.
+# RUN: ld.lld -o %t %t.o --defsym=foo2=etext+2
+# RUN: llvm-readobj -t -s %t | FileCheck %s --check-prefix=EXPR
+# EXPR:     Symbol {
+# EXPR:      Name: foo2
+# EXPR-NEXT:  Value: 0x201007
+# EXPR:     Symbol {
+# EXPR:      Name: etext
+# EXPR-NEXT:  Value: 0x201005
+
+.globl foo1
+ foo1 = 0x123
+
+.global _start
+_start:
+  movl $foo2, %edx


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42911.133168.patch
Type: text/x-patch
Size: 1533 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180207/c10bdf87/attachment.bin>


More information about the llvm-commits mailing list