forked from OSchip/llvm-project
Reject zero-sized symbols when creating copy relocations.
Copy relocations are relocations to copy data from DSOs to executable's .bss segment at runtime. It doesn't make sense to create such relocations for zero-sized symbols. GNU linkers don't agree with each other. ld rejects such relocation/symbol pair. gold don't reject that but do not create copy relocations as well. I took the former approach because I don't think the latter is what user wants. llvm-svn: 270525
This commit is contained in:
parent
41518945e3
commit
98843087cb
|
@ -1055,10 +1055,15 @@ template <class ELFT> static uint32_t getAlignment(SharedSymbol<ELFT> *SS) {
|
|||
// Reserve space in .bss for copy relocation.
|
||||
template <class ELFT>
|
||||
void Writer<ELFT>::addCopyRelSymbol(SharedSymbol<ELFT> *SS) {
|
||||
// Copy relocation against zero-sized symbol doesn't make sense.
|
||||
uintX_t SymSize = SS->template getSize<ELFT>();
|
||||
if (SymSize == 0)
|
||||
fatal("cannot create a copy relocation for " + SS->getName());
|
||||
|
||||
ensureBss();
|
||||
uintX_t Align = getAlignment(SS);
|
||||
uintX_t Off = alignTo(Out<ELFT>::Bss->getSize(), Align);
|
||||
Out<ELFT>::Bss->setSize(Off + SS->template getSize<ELFT>());
|
||||
Out<ELFT>::Bss->setSize(Off + SymSize);
|
||||
Out<ELFT>::Bss->updateAlign(Align);
|
||||
uintX_t Shndx = SS->Sym.st_shndx;
|
||||
uintX_t Value = SS->Sym.st_value;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
.type foo, @object
|
||||
.global foo
|
||||
foo:
|
||||
.size foo, 4
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
.type x,@object
|
||||
.globl x
|
||||
x:
|
||||
.size x, 0
|
|
@ -17,10 +17,12 @@ foo1:
|
|||
.data
|
||||
.globl data0
|
||||
.type data0, @object
|
||||
.size data0, 4
|
||||
data0:
|
||||
.word 0
|
||||
|
||||
.globl data1
|
||||
.type data1, @object
|
||||
.size data1, 4
|
||||
data1:
|
||||
.word 0
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
// RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux
|
||||
// RUN: llvm-mc %p/Inputs/copy-rel-corrupted.s -o %t2.o -filetype=obj -triple=x86_64-pc-linux
|
||||
// RUN: ld.lld %t2.o -o %t2.so -shared
|
||||
// RUN: not ld.lld %t.o %t2.so -o %t.exe 2>&1 | FileCheck %s
|
||||
|
||||
// CHECK: cannot create a copy relocation for x
|
||||
|
||||
.global _start
|
||||
_start:
|
||||
call x
|
|
@ -33,8 +33,8 @@
|
|||
# CHECK-NEXT: Entry {
|
||||
# CHECK-NEXT: Address: 0x3000C
|
||||
# CHECK-NEXT: Access: -32740
|
||||
# CHECK-NEXT: Initial: 0x40010
|
||||
# CHECK-NEXT: Value: 0x40010
|
||||
# CHECK-NEXT: Initial: 0x40014
|
||||
# CHECK-NEXT: Value: 0x40014
|
||||
# CHECK-NEXT: Type: Object (0x1)
|
||||
# CHECK-NEXT: Section: .bss (0xC)
|
||||
# CHECK-NEXT: Name: data1@ (7)
|
||||
|
|
Loading…
Reference in New Issue