Don't try to preempt protected symbols with -z notext.

I will send a followup patch removing the FIXME this patch adds.

llvm-svn: 321499
This commit is contained in:
Rafael Espindola 2017-12-27 20:53:13 +00:00
parent ad6f457c39
commit e2e070c6c4
3 changed files with 26 additions and 10 deletions

View File

@ -598,19 +598,19 @@ static RelExpr adjustExpr(Symbol &Sym, RelExpr Expr, RelType Type,
return Expr;
}
// 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))
return getPltExpr(Sym, Expr, IsConstant);
// We can create any dynamic relocation supported by the dynamic linker if a
// section is writable or we are passed -z notext.
bool CanWrite = (S.Flags & SHF_WRITE) || !Config->ZText;
if (CanWrite && Target->isPicRel(Type))
return Expr;
}
// If we got here we know that this relocation would require the dynamic
// linker to write a value to read only memory.
// linker to write a value to read only memory or use an unsupported
// relocation.
// FIXME: This is a hack to avoid changing error messages for now.
if (CanWrite && !Sym.isFunc())
return Expr;
// We can hack around it if we are producing an executable and
// the refered symbol can be preemepted to refer to the executable.

View File

@ -0,0 +1,5 @@
.global foo
.type foo,@function
.protected foo
foo:
nop

View File

@ -0,0 +1,11 @@
# 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/znotext-plt-relocations-protected.s -o %t2.o
# RUN: ld.lld %t2.o -o %t2.so -shared
# RUN: not ld.lld -z notext %t.o %t2.so -o %t 2>&1 | FileCheck %s
# CHECK: error: cannot preempt symbol: foo
.global _start
_start:
callq foo