forked from OSchip/llvm-project
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. llvm-svn: 319449
This commit is contained in:
parent
fc473dee98
commit
de38b3d22f
|
@ -976,8 +976,13 @@ ExprValue LinkerScript::getSymbolValue(StringRef Name, const Twine &Loc) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto *Sym = dyn_cast_or_null<Defined>(Symtab->find(Name)))
|
if (Symbol *Sym = Symtab->find(Name)) {
|
||||||
return {Sym->Section, false, Sym->Value, Loc};
|
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);
|
error(Loc + ": symbol not found: " + Name);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
.global bar
|
||||||
|
.type bar, @object
|
||||||
|
.size bar, 8
|
||||||
|
bar:
|
||||||
|
.quad 0
|
|
@ -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@got
|
|
@ -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
|
Loading…
Reference in New Issue