summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/Config.h2
-rw-r--r--lld/ELF/Driver.cpp23
-rw-r--r--lld/ELF/Relocations.cpp2
-rw-r--r--lld/test/ELF/combrelocs.s3
-rw-r--r--lld/test/ELF/dt_flags.s7
-rw-r--r--lld/test/ELF/gnustack.s5
-rw-r--r--lld/test/ELF/relro.s10
-rw-r--r--lld/test/ELF/ztext.s5
8 files changed, 45 insertions, 12 deletions
diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index e4974d3afba..f58931a84a6 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -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;
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index ab3ab26a821..4bfef2f4f8e 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -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.
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index e7c1c522cb9..5722f208fa1 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -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'" +
diff --git a/lld/test/ELF/combrelocs.s b/lld/test/ELF/combrelocs.s
index 3c8be807053..595f6049f5f 100644
--- a/lld/test/ELF/combrelocs.s
+++ b/lld/test/ELF/combrelocs.s
@@ -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 {
diff --git a/lld/test/ELF/dt_flags.s b/lld/test/ELF/dt_flags.s
index 431f83df7ab..dffaec8c27e 100644
--- a/lld/test/ELF/dt_flags.s
+++ b/lld/test/ELF/dt_flags.s
@@ -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 [
diff --git a/lld/test/ELF/gnustack.s b/lld/test/ELF/gnustack.s
index c506fb807c6..3ab6f16ac7b 100644
--- a/lld/test/ELF/gnustack.s
+++ b/lld/test/ELF/gnustack.s
@@ -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
diff --git a/lld/test/ELF/relro.s b/lld/test/ELF/relro.s
index b21e514303a..0f721318c78 100644
--- a/lld/test/ELF/relro.s
+++ b/lld/test/ELF/relro.s
@@ -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
diff --git a/lld/test/ELF/ztext.s b/lld/test/ELF/ztext.s
index 1ce19cfc0a6..1757769b29a 100644
--- a/lld/test/ELF/ztext.s
+++ b/lld/test/ELF/ztext.s
@@ -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 [
OpenPOWER on IntegriCloud