forked from OSchip/llvm-project
Allow relocations in rw sections to create plt entries.
If a relocation cannot be implemented by the dynamic linker and the section is rw, allow creating a plt entry to use as the function address as if the section was ro. This matches bfd and gold. It also matches our behavior with -z notext. llvm-svn: 321430
This commit is contained in:
parent
0742090e3d
commit
a9c490b71d
|
@ -585,14 +585,10 @@ template <class ELFT>
|
|||
static RelExpr adjustExpr(Symbol &Sym, RelExpr Expr, RelType Type,
|
||||
InputSectionBase &S, uint64_t RelOff,
|
||||
bool &IsConstant) {
|
||||
// We can create any dynamic relocation if a section is simply writable.
|
||||
if (S.Flags & SHF_WRITE)
|
||||
return Expr;
|
||||
|
||||
// Or, if we are allowed to create dynamic relocations against
|
||||
// read-only sections (i.e. when "-z notext" is given),
|
||||
// we can create a dynamic relocation as we want, too.
|
||||
if (!Config->ZText) {
|
||||
// If a section writable or if we are allowed to create dynamic relocations
|
||||
// against read-only sections (i.e. when "-z notext" is given), we can create
|
||||
// any dynamic relocation the dynamic linker knows how to handle.
|
||||
if ((S.Flags & SHF_WRITE) || !Config->ZText) {
|
||||
// We use PLT for relocations that may overflow in runtime,
|
||||
// see comment for getPltExpr().
|
||||
if (Sym.isFunc() && !Target->isPicRel(Type))
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
.global foo
|
||||
.type foo, @function
|
||||
foo:
|
||||
retq
|
|
@ -0,0 +1,14 @@
|
|||
# REQUIRES: x86
|
||||
# RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux
|
||||
# RUN: llvm-mc %p/Inputs/writable-sec-plt-reloc.s -o %t2.o -filetype=obj -triple=x86_64-pc-linux
|
||||
# RUN: ld.lld %t2.o -o %t2.so -shared
|
||||
# RUN: ld.lld %t.o %t2.so -o %t
|
||||
# RUN: llvm-readelf --symbols -r %t | FileCheck %s
|
||||
|
||||
# CHECK: R_X86_64_JUMP_SLOT {{.*}} foo + 0
|
||||
# CHECK: 0000000000201010 0 FUNC GLOBAL DEFAULT UND foo
|
||||
|
||||
.section .bar,"awx"
|
||||
.global _start
|
||||
_start:
|
||||
call foo
|
|
@ -7,7 +7,7 @@
|
|||
.global _start
|
||||
_start:
|
||||
.data
|
||||
.long bar
|
||||
.long zed
|
||||
|
||||
// CHECK: relocation R_X86_64_32 cannot be used against shared object; recompile with -fPIC
|
||||
|
||||
|
|
|
@ -11,4 +11,4 @@
|
|||
.global _start
|
||||
_start:
|
||||
.data
|
||||
.long bar - .
|
||||
.long zed - .
|
||||
|
|
Loading…
Reference in New Issue