Add -z {combreloc,copyreloc,noexecstack,lazy,relro,text}.

Differential Revision: https://reviews.llvm.org/D45902

llvm-svn: 330482
This commit is contained in:
Rui Ueyama 2018-04-20 21:24:08 +00:00
parent 71c7de5b77
commit 88fe5c9557
8 changed files with 45 additions and 12 deletions

View File

@ -163,9 +163,9 @@ struct Configuration {
bool WarnSymbolOrdering;
bool WriteAddends;
bool ZCombreloc;
bool ZCopyreloc;
bool ZExecstack;
bool ZHazardplt;
bool ZNocopyreloc;
bool ZNodelete;
bool ZNodlopen;
bool ZNow;

View File

@ -313,6 +313,17 @@ static bool hasZOption(opt::InputArgList &Args, StringRef Key) {
return false;
}
static bool getZFlag(opt::InputArgList &Args, StringRef K1, StringRef K2,
bool Default) {
for (auto *Arg : Args.filtered_reverse(OPT_z)) {
if (K1 == Arg->getValue())
return true;
if (K2 == Arg->getValue())
return false;
}
return Default;
}
void LinkerDriver::main(ArrayRef<const char *> ArgsArr) {
ELFOptTable Parser;
opt::InputArgList Args = Parser.parse(ArgsArr.slice(1));
@ -748,19 +759,19 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
Config->WarnCommon = Args.hasFlag(OPT_warn_common, OPT_no_warn_common, false);
Config->WarnSymbolOrdering =
Args.hasFlag(OPT_warn_symbol_ordering, OPT_no_warn_symbol_ordering, true);
Config->ZCombreloc = !hasZOption(Args, "nocombreloc");
Config->ZExecstack = hasZOption(Args, "execstack");
Config->ZCombreloc = getZFlag(Args, "combreloc", "nocombreloc", true);
Config->ZCopyreloc = getZFlag(Args, "copyreloc", "nocopyreloc", true);
Config->ZExecstack = getZFlag(Args, "execstack", "noexecstack", false);
Config->ZHazardplt = hasZOption(Args, "hazardplt");
Config->ZNocopyreloc = hasZOption(Args, "nocopyreloc");
Config->ZNodelete = hasZOption(Args, "nodelete");
Config->ZNodlopen = hasZOption(Args, "nodlopen");
Config->ZNow = hasZOption(Args, "now");
Config->ZNow = getZFlag(Args, "now", "lazy", false);
Config->ZOrigin = hasZOption(Args, "origin");
Config->ZRelro = !hasZOption(Args, "norelro");
Config->ZRelro = getZFlag(Args, "relro", "norelro", true);
Config->ZRetpolineplt = hasZOption(Args, "retpolineplt");
Config->ZRodynamic = hasZOption(Args, "rodynamic");
Config->ZStackSize = args::getZOptionValue(Args, OPT_z, "stack-size", 0);
Config->ZText = !hasZOption(Args, "notext");
Config->ZText = getZFlag(Args, "text", "notext", true);
Config->ZWxneeded = hasZOption(Args, "wxneeded");
// Parse LTO plugin-related options for compatibility with gold.

View File

@ -843,7 +843,7 @@ static RelExpr processRelocAux(InputSectionBase &Sec, RelExpr Expr,
// Produce a copy relocation.
auto &SS = cast<SharedSymbol>(Sym);
if (!SS.CopyRelSec) {
if (Config->ZNocopyreloc)
if (!Config->ZCopyreloc)
error("unresolvable relocation " + toString(Type) +
" against symbol '" + toString(SS) +
"'; recompile with -fPIC or remove '-z nocopyreloc'" +

View File

@ -4,6 +4,9 @@
# RUN: ld.lld -shared %t.o -o %t.out
# RUN: llvm-readobj -r --expand-relocs --dynamic-table %t.out | FileCheck %s
# RUN: ld.lld -shared %t.o -o %t.out -z combreloc
# RUN: llvm-readobj -r --expand-relocs --dynamic-table %t.out | FileCheck %s
# CHECK: Relocations [
# CHECK-NEXT: Section ({{.*}}) .rela.dyn {
# CHECK-NEXT: Relocation {

View File

@ -2,9 +2,14 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: ld.lld -shared %t -o %t.so
# RUN: ld.lld -z now -z nodelete -z nodlopen -z origin -Bsymbolic %t %t.so -o %t1
# RUN: ld.lld %t %t.so -o %t2
# RUN: llvm-readobj -dynamic-table %t1 | FileCheck -check-prefix=FLAGS %s
# RUN: ld.lld %t %t.so -o %t2
# RUN: llvm-readobj -dynamic-table %t2 | FileCheck %s
# RUN: ld.lld -z lazy %t %t.so -o %t2
# RUN: llvm-readobj -dynamic-table %t2 | FileCheck %s
# FLAGS: DynamicSection [

View File

@ -1,10 +1,15 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1
# RUN: ld.lld %t1 -z execstack -o %t
# RUN: llvm-readobj --program-headers -s %t | FileCheck --check-prefix=RWX %s
# RUN: ld.lld %t1 -o %t
# RUN: llvm-readobj --program-headers -s %t | FileCheck --check-prefix=RW %s
# RUN: ld.lld %t1 -o %t -z noexecstack
# RUN: llvm-readobj --program-headers -s %t | FileCheck --check-prefix=RW %s
# RW: Type: PT_GNU_STACK
# RW-NEXT: Offset: 0x0
# RW-NEXT: VirtualAddress: 0x0

View File

@ -1,13 +1,17 @@
// REQUIRES: x86
// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/shared.s -o %t2.o
// RUN: ld.lld -shared %t2.o -o %t2.so
// RUN: ld.lld %t.o %t2.so -z now -z relro -o %t
// RUN: ld.lld %t.o %t2.so -z now -z norelro -z relro -o %t
// RUN: llvm-readobj -l --elf-output-style=GNU %t | FileCheck --check-prefix=CHECK --check-prefix=FULLRELRO %s
// RUN: ld.lld %t.o %t2.so -z relro -o %t
// RUN: ld.lld %t.o %t2.so -z norelro -z relro -o %t
// RUN: llvm-readobj -l --elf-output-style=GNU %t | FileCheck --check-prefix=CHECK --check-prefix=PARTRELRO %s
// RUN: ld.lld %t.o %t2.so -z norelro -o %t
// RUN: llvm-readobj -l --elf-output-style=GNU %t | FileCheck --check-prefix=NORELRO %s
// REQUIRES: x86
// CHECK: Program Headers:
// CHECK-NEXT: Type

View File

@ -2,6 +2,7 @@
# 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/ztext.s -o %t2.o
# RUN: ld.lld %t2.o -o %t2.so -shared
# RUN: ld.lld -z notext %t.o %t2.so -o %t -shared
# RUN: llvm-readobj -dynamic-table -r %t | FileCheck %s
# RUN: ld.lld -z notext %t.o %t2.so -o %t2 -pie
@ -9,6 +10,10 @@
# RUN: ld.lld -z notext %t.o %t2.so -o %t3
# RUN: llvm-readobj -dynamic-table -r %t3 | FileCheck --check-prefix=STATIC %s
# RUN: not ld.lld %t.o %t2.so -o %t -shared 2>&1 | FileCheck --check-prefix=ERR %s
# RUN: not ld.lld -z text %t.o %t2.so -o %t -shared 2>&1 | FileCheck --check-prefix=ERR %s
# ERR: error: can't create dynamic relocation
# If the preference is to have text relocations, don't create plt of copy relocations.
# CHECK: Relocations [