[lld] r319449 - Handle copy relocations in symbol assignments.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 30 09:51:10 PST 2017
Author: rafael
Date: Thu Nov 30 09:51:10 2017
New Revision: 319449
URL: http://llvm.org/viewvc/llvm-project?rev=319449&view=rev
Log:
Handle copy relocations in symbol assignments.
When a linker script has "foo = bar" and bar is the result of a copy
relocation foo should point to the same location in .bss.
This is part of a growing evidence that copy relocations should be
implemented by using replaceSymbol to replace the SharedSymbol with a
Defined.
Added:
lld/trunk/test/ELF/linkerscript/Inputs/copy-rel-symbol-value.s
lld/trunk/test/ELF/linkerscript/copy-rel-symbol-value-err.s
lld/trunk/test/ELF/linkerscript/copy-rel-symbol-value.s
Modified:
lld/trunk/ELF/LinkerScript.cpp
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=319449&r1=319448&r2=319449&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Thu Nov 30 09:51:10 2017
@@ -976,8 +976,13 @@ ExprValue LinkerScript::getSymbolValue(S
return 0;
}
- if (auto *Sym = dyn_cast_or_null<Defined>(Symtab->find(Name)))
- return {Sym->Section, false, Sym->Value, Loc};
+ if (Symbol *Sym = Symtab->find(Name)) {
+ if (auto *DS = dyn_cast<Defined>(Sym))
+ return {DS->Section, false, DS->Value, Loc};
+ if (auto *SS = dyn_cast<SharedSymbol>(Sym))
+ if (!ErrorOnMissingSection || SS->CopyRelSec)
+ return {SS->CopyRelSec, false, 0, Loc};
+ }
error(Loc + ": symbol not found: " + Name);
return 0;
Added: lld/trunk/test/ELF/linkerscript/Inputs/copy-rel-symbol-value.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/Inputs/copy-rel-symbol-value.s?rev=319449&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/Inputs/copy-rel-symbol-value.s (added)
+++ lld/trunk/test/ELF/linkerscript/Inputs/copy-rel-symbol-value.s Thu Nov 30 09:51:10 2017
@@ -0,0 +1,5 @@
+ .global bar
+ .type bar, @object
+ .size bar, 8
+bar:
+ .quad 0
Added: lld/trunk/test/ELF/linkerscript/copy-rel-symbol-value-err.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/copy-rel-symbol-value-err.s?rev=319449&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/copy-rel-symbol-value-err.s (added)
+++ lld/trunk/test/ELF/linkerscript/copy-rel-symbol-value-err.s Thu Nov 30 09:51:10 2017
@@ -0,0 +1,12 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/copy-rel-symbol-value.s -o %t2.o
+# RUN: ld.lld %t2.o -o %t2.so -shared
+# RUN: echo "SECTIONS { . = . + SIZEOF_HEADERS; foo = bar; }" > %t.script
+# RUN: not ld.lld %t.o %t2.so --script %t.script -o %t 2>&1 | FileCheck %s
+
+# CHECK: symbol not found: bar
+
+.global _start
+_start:
+.quad bar at got
Added: lld/trunk/test/ELF/linkerscript/copy-rel-symbol-value.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/copy-rel-symbol-value.s?rev=319449&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/copy-rel-symbol-value.s (added)
+++ lld/trunk/test/ELF/linkerscript/copy-rel-symbol-value.s Thu Nov 30 09:51:10 2017
@@ -0,0 +1,27 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/copy-rel-symbol-value.s -o %t2.o
+# RUN: ld.lld %t2.o -o %t2.so -shared
+# RUN: echo "SECTIONS { . = . + SIZEOF_HEADERS; foo = bar; }" > %t.script
+# RUN: ld.lld %t.o %t2.so --script %t.script -o %t
+# RUN: llvm-readobj -t %t | FileCheck %s
+
+# CHECK: Name: bar
+# CHECK-NEXT: Value: 0x[[VAL:.*]]
+# CHECK-NEXT: Size: 8
+# CHECK-NEXT: Binding: Global
+# CHECK-NEXT: Type: Object
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: .bss.rel.ro
+
+# CHECK: Name: foo
+# CHECK-NEXT: Value: 0x[[VAL]]
+# CHECK-NEXT: Size:
+# CHECK-NEXT: Binding: Global
+# CHECK-NEXT: Type:
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: .bss.rel.ro
+
+.global _start
+_start:
+.quad bar
More information about the llvm-commits
mailing list