ELF: Make .note.GNU-stack more compatible with traditional linkers.
With this patch, lld creates PT_GNU_STACK segments only when all input
files have .note.GNU-stack sections. This is in line with other linkers
with a minor difference (we don't care about .note.GNU-stack rwx bits as
you can always remove .note.GNU-stack sections instead of setting x bit.)
At least, NetBSD loader does not understand PT_GNU_STACK segments and
reject any executables that have the section. This patch makes lld
compatible with such operating systems.
llvm-svn: 253797
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index f1aaa5b..c76aa86 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -173,7 +173,6 @@
Config->SoName = getString(Args, OPT_soname);
Config->Sysroot = getString(Args, OPT_sysroot);
- Config->ZExecStack = hasZOption(Args, "execstack");
Config->ZNodelete = hasZOption(Args, "nodelete");
Config->ZNow = hasZOption(Args, "now");
Config->ZOrigin = hasZOption(Args, "origin");
@@ -277,6 +276,14 @@
for (StringRef S : Config->Undefined)
Symtab.addUndefinedOpt(S);
+ // "-z execstack" value is inferred from input object files (it's false
+ // if all input files have .note.GNU-stack section). Explicit options
+ // override the inferred default value.
+ if (hasZOption(Args, "execstack"))
+ Config->ZExecStack = true;
+ if (hasZOption(Args, "noexecstack"))
+ Config->ZExecStack = false;
+
if (Config->OutputFile.empty())
Config->OutputFile = "a.out";