[lld] r330482 - Add -z {combreloc, copyreloc, noexecstack, lazy, relro, text}.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 20 14:24:08 PDT 2018
Author: ruiu
Date: Fri Apr 20 14:24:08 2018
New Revision: 330482
URL: http://llvm.org/viewvc/llvm-project?rev=330482&view=rev
Log:
Add -z {combreloc,copyreloc,noexecstack,lazy,relro,text}.
Differential Revision: https://reviews.llvm.org/D45902
Modified:
lld/trunk/ELF/Config.h
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/Relocations.cpp
lld/trunk/test/ELF/combrelocs.s
lld/trunk/test/ELF/dt_flags.s
lld/trunk/test/ELF/gnustack.s
lld/trunk/test/ELF/relro.s
lld/trunk/test/ELF/ztext.s
Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=330482&r1=330481&r2=330482&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Fri Apr 20 14:24:08 2018
@@ -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;
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=330482&r1=330481&r2=330482&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Fri Apr 20 14:24:08 2018
@@ -313,6 +313,17 @@ static bool hasZOption(opt::InputArgList
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::Inpu
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.
Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=330482&r1=330481&r2=330482&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Fri Apr 20 14:24:08 2018
@@ -843,7 +843,7 @@ static RelExpr processRelocAux(InputSect
// 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'" +
Modified: lld/trunk/test/ELF/combrelocs.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/combrelocs.s?rev=330482&r1=330481&r2=330482&view=diff
==============================================================================
--- lld/trunk/test/ELF/combrelocs.s (original)
+++ lld/trunk/test/ELF/combrelocs.s Fri Apr 20 14:24:08 2018
@@ -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 {
Modified: lld/trunk/test/ELF/dt_flags.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/dt_flags.s?rev=330482&r1=330481&r2=330482&view=diff
==============================================================================
--- lld/trunk/test/ELF/dt_flags.s (original)
+++ lld/trunk/test/ELF/dt_flags.s Fri Apr 20 14:24:08 2018
@@ -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 [
Modified: lld/trunk/test/ELF/gnustack.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/gnustack.s?rev=330482&r1=330481&r2=330482&view=diff
==============================================================================
--- lld/trunk/test/ELF/gnustack.s (original)
+++ lld/trunk/test/ELF/gnustack.s Fri Apr 20 14:24:08 2018
@@ -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
Modified: lld/trunk/test/ELF/relro.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/relro.s?rev=330482&r1=330481&r2=330482&view=diff
==============================================================================
--- lld/trunk/test/ELF/relro.s (original)
+++ lld/trunk/test/ELF/relro.s Fri Apr 20 14:24:08 2018
@@ -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
Modified: lld/trunk/test/ELF/ztext.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/ztext.s?rev=330482&r1=330481&r2=330482&view=diff
==============================================================================
--- lld/trunk/test/ELF/ztext.s (original)
+++ lld/trunk/test/ELF/ztext.s Fri Apr 20 14:24:08 2018
@@ -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 [
More information about the llvm-commits
mailing list