Add `-z nocopyreloc` option.

This option disable creating copy relocations. ld.bfd and ld.gold
have the same option.

llvm-svn: 295772
This commit is contained in:
Rui Ueyama 2017-02-21 21:41:50 +00:00
parent 5d6631d8b4
commit f9e8034c9c
4 changed files with 28 additions and 1 deletions

View File

@ -136,6 +136,7 @@ struct Configuration {
bool WarnMissingEntry;
bool ZCombreloc;
bool ZExecstack;
bool ZNocopyreloc;
bool ZNodelete;
bool ZNow;
bool ZOrigin;

View File

@ -574,6 +574,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
Config->ZCombreloc = !hasZOption(Args, "nocombreloc");
Config->ZExecstack = hasZOption(Args, "execstack");
Config->ZNocopyreloc = hasZOption(Args, "nocopyreloc");
Config->ZNodelete = hasZOption(Args, "nodelete");
Config->ZNow = hasZOption(Args, "now");
Config->ZOrigin = hasZOption(Args, "origin");

View File

@ -543,8 +543,14 @@ static RelExpr adjustExpr(const elf::ObjectFile<ELFT> &File, SymbolBody &Body,
if (Body.isObject()) {
// Produce a copy relocation.
auto *B = cast<SharedSymbol<ELFT>>(&Body);
if (!B->NeedsCopy)
if (!B->NeedsCopy) {
if (Config->ZNocopyreloc)
error(S.getLocation(RelOff) + ": unresolvable relocation " + toString(Type)
+ " against symbol '" + toString(*B) +
"'; recompile with -fPIC or remove '-z nocopyreloc'");
addCopyRelSymbol(B);
}
return Expr;
}
if (Body.isFunc()) {

View File

@ -0,0 +1,19 @@
// 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/relocation-copy.s -o %t2.o
// RUN: ld.lld -shared %t2.o -o %t.so
// RUN: not ld.lld -z nocopyreloc %t.o %t.so -o %t3 2>&1 | FileCheck %s
// CHECK: unresolvable relocation R_X86_64_32S against symbol 'x'
// CHECK: unresolvable relocation R_X86_64_32S against symbol 'y'
// CHECK: unresolvable relocation R_X86_64_32S against symbol 'z'
.text
.global _start
_start:
movl $5, x
movl $7, y
movl $9, z
movl $x, %edx
movl $y, %edx
movl $z, %edx