devel/lld: import lld-7.0.1

LLD is a linker from the LLVM project that is a drop-in replacement for system
linkers and runs much faster than them. It also provides features that are
useful for toolchain developers.
This commit is contained in:
mgorny 2019-02-01 16:30:00 +00:00
parent 6452c77bbf
commit ac9eb3e1ef
14 changed files with 544 additions and 0 deletions

11
devel/lld/DESCR Normal file
View file

@ -0,0 +1,11 @@
LLD is a linker from the LLVM project that is a drop-in replacement for system
linkers and runs much faster than them. It also provides features that are
useful for toolchain developers.
The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS) and
WebAssembly in descending order of completeness. Internally, LLD consists of
several different linkers. The ELF port is the one that will be described in
this document. The PE/COFF port is complete, including Windows debug info (PDB)
support. The WebAssembly port is still a work in progress (See WebAssembly lld
port). The Mach-O port is built based on a different architecture than
the others. For the details about Mach-O, please read ATOM-based lld.

34
devel/lld/Makefile Normal file
View file

@ -0,0 +1,34 @@
# $NetBSD: Makefile,v 1.1 2019/02/01 16:30:00 mgorny Exp $
PKGNAME= lld-7.0.1
DISTNAME= ${PKGNAME}.src
CATEGORIES= devel
MASTER_SITES= http://llvm.org/releases/${PKGVERSION_NOREV}/
EXTRACT_SUFX= .tar.xz
DISTFILES= ${DEFAULT_DISTFILES}
MAINTAINER= mgorny@NetBSD.org
HOMEPAGE= http://lld.llvm.org/
COMMENT= The LLVM Linker
LICENSE= modified-bsd
USE_LANGUAGES= c c++11
USE_CMAKE= yes
GCC_REQD+= 4.8
CONFIGURE_DIRS= ${WRKDIR}/build
CMAKE_ARG_PATH= ${WRKSRC}
CMAKE_ARGS+= -DCMAKE_BUILD_TYPE=Release
CMAKE_ARGS+= -DCMAKE_C_COMPILER=${CC:Q}
CMAKE_ARGS+= -DCMAKE_CXX_COMPILER=${CXX:Q}
PYTHON_FOR_BUILD_ONLY= yes
post-extract:
${MKDIR} ${WRKDIR}/build
.include "options.mk"
.include "../../lang/python/tool.mk"
.include "../../lang/llvm/buildlink3.mk"
.include "../../mk/bsd.pkg.mk"

49
devel/lld/PLIST Normal file
View file

@ -0,0 +1,49 @@
@comment $NetBSD: PLIST,v 1.1 2019/02/01 16:30:00 mgorny Exp $
bin/ld.lld
bin/ld64.lld
bin/lld
bin/lld-link
bin/wasm-ld
include/lld/Common/Args.h
include/lld/Common/Driver.h
include/lld/Common/ErrorHandler.h
include/lld/Common/LLVM.h
include/lld/Common/Memory.h
include/lld/Common/Reproduce.h
include/lld/Common/Strings.h
include/lld/Common/TargetOptionsCommandFlags.h
include/lld/Common/Threads.h
include/lld/Common/Timer.h
include/lld/Common/Version.h
include/lld/Core/AbsoluteAtom.h
include/lld/Core/ArchiveLibraryFile.h
include/lld/Core/Atom.h
include/lld/Core/DefinedAtom.h
include/lld/Core/Error.h
include/lld/Core/File.h
include/lld/Core/Instrumentation.h
include/lld/Core/LinkingContext.h
include/lld/Core/Node.h
include/lld/Core/Pass.h
include/lld/Core/PassManager.h
include/lld/Core/Reader.h
include/lld/Core/Reference.h
include/lld/Core/Resolver.h
include/lld/Core/SharedLibraryAtom.h
include/lld/Core/SharedLibraryFile.h
include/lld/Core/Simple.h
include/lld/Core/SymbolTable.h
include/lld/Core/UndefinedAtom.h
include/lld/Core/Writer.h
include/lld/ReaderWriter/MachOLinkingContext.h
include/lld/ReaderWriter/YamlContext.h
lib/liblldCOFF.a
lib/liblldCommon.a
lib/liblldCore.a
lib/liblldDriver.a
lib/liblldELF.a
lib/liblldMachO.a
lib/liblldMinGW.a
lib/liblldReaderWriter.a
lib/liblldWasm.a
lib/liblldYAML.a

14
devel/lld/buildlink3.mk Normal file
View file

@ -0,0 +1,14 @@
# $NetBSD: buildlink3.mk,v 1.1 2019/02/01 16:30:00 mgorny Exp $
BUILDLINK_TREE+= lld
.if !defined(LLD_BUILDLINK3_MK)
LLD_BUILDLINK3_MK:=
BUILDLINK_API_DEPENDS.lld+= lld>=7.0.0
BUILDLINK_PKGSRCDIR.lld?= ../../devel/lld
.include "../../lang/llvm/buildlink3.mk"
.endif # LLD_BUILDLINK3_MK
BUILDLINK_TREE+= -lld

18
devel/lld/distinfo Normal file
View file

@ -0,0 +1,18 @@
$NetBSD: distinfo,v 1.1 2019/02/01 16:30:00 mgorny Exp $
SHA1 (lld-7.0.1.src.tar.xz) = 3b69e107f27d466488838d5fa65bdfd77b885007
RMD160 (lld-7.0.1.src.tar.xz) = 44e0e851b957fef86352ebe6c2a37096f8595dcb
SHA512 (lld-7.0.1.src.tar.xz) = e5d3ed280d8ac6014cd6bbe080b11e2c4ebbae81dc14b637e779ec027d818dbae91c6f0de9e94bcecd6bdaa37f12c35141b5d81f0a15251d27932aa9bebd4047
Size (lld-7.0.1.src.tar.xz) = 912812 bytes
SHA1 (llvm-7.0.1.src.tar.xz) = f97632fcc3186eb0d396492ef8acfc807648580f
RMD160 (llvm-7.0.1.src.tar.xz) = dae96c6f85afb60e73564dc40d02171d01ffdb8f
SHA512 (llvm-7.0.1.src.tar.xz) = ac43a3cb71a53deb55e3693653847cf20bf6f5d9056f224e6956c96d63bc59ebee9404f088eec9cabe65337b4607a905ef931354b373cf64e0004c6905a6b5df
Size (llvm-7.0.1.src.tar.xz) = 28311056 bytes
SHA1 (patch-CMakeLists.txt) = df8e32f5f23bf2f2615a891177f61dc65359e955
SHA1 (patch-ELF_Config.h) = 767eebd5787ae5351e3275f7d6666cd905f34f05
SHA1 (patch-ELF_Driver.cpp) = d3ba099bf4a72a90cb126a6da4af9bdc7b97ba70
SHA1 (patch-ELF_Driver.h) = e100fb0c86cc7d20b0f64919e73888a81a4836df
SHA1 (patch-ELF_Options.td) = c8107a2c599b2444e52bdefe5f2dc539d277a092
SHA1 (patch-ELF_Writer.cpp) = ab4ca25f832f20a5b4c80fe0f5f28822c09fb4ee
SHA1 (patch-docs_ld.lld.1) = d61a228b5eb760a0ac4f691b9001d5505ebfe6ed
SHA1 (patch-test_ELF_gnustack.s) = b3827436dcfc67d51b8d293b11538808537ddeec

20
devel/lld/options.mk Normal file
View file

@ -0,0 +1,20 @@
# $NetBSD: options.mk,v 1.1 2019/02/01 16:30:00 mgorny Exp $
PKG_OPTIONS_VAR= PKG_OPTIONS.lld
PKG_SUPPORTED_OPTIONS= tests
.include "../../mk/bsd.options.mk"
.if !empty(PKG_OPTIONS:Mtests)
DISTFILES+= llvm-${PKGVERSION_NOREV}.src${EXTRACT_SUFX}
CMAKE_ARGS+= -DLLVM_CONFIG_PATH=${LLVM_CONFIG_PATH:Q}
CMAKE_ARGS+= -DLLVM_INCLUDE_TESTS=ON
CMAKE_ARGS+= -DLLVM_BUILD_TESTS=ON
CMAKE_ARGS+= -DLLVM_MAIN_SRC_DIR=${WRKDIR}/llvm-${PKGVERSION_NOREV}.src
CMAKE_ARGS+= -DLLVM_EXTERNAL_LIT=${WRKDIR}/llvm-${PKGVERSION_NOREV}.src/utils/lit/lit.py
REPLACE_PYTHON+= ${WRKDIR}/llvm-${PKGVERSION_NOREV}.src/utils/lit/lit.py
TEST_TARGET= check-lld # failing tests fixed in 8.0
TEST_ENV+= LD_LIBRARY_PATH=${WRKDIR}/build/lib
.else
CMAKE_ARGS+= -DLLVM_INCLUDE_TESTS=OFF
.endif

View file

@ -0,0 +1,16 @@
$NetBSD: patch-CMakeLists.txt,v 1.1 2019/02/01 16:30:00 mgorny Exp $
LLD 7.0.1 is incompatible with gtest version in pkgsrc. Remove
the condition that prevents it from building its own copy when system
version is installed.
--- CMakeLists.txt.orig 2017-11-17 18:14:09.000000000 +0000
+++ CMakeLists.txt
@@ -86,7 +86,6 @@ Please install Python or specify the PYT
endif()
set(UNITTEST_DIR ${LLVM_MAIN_SRC_DIR}/utils/unittest)
if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h
- AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt)
add_subdirectory(${UNITTEST_DIR} utils/unittest)
endif()

View file

@ -0,0 +1,37 @@
$NetBSD: patch-ELF_Config.h,v 1.1 2019/02/01 16:30:00 mgorny Exp $
Add support for customizing LLD behavior on target triple.
https://reviews.llvm.org/D56650
Add '-z nognustack' option to disable emitting PT_GNU_STACK.
https://reviews.llvm.org/D56554
--- ELF/Config.h.orig 2018-07-31 13:41:59.000000000 +0000
+++ ELF/Config.h
@@ -14,6 +14,7 @@
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
+#include "llvm/ADT/Triple.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/Support/CachePruning.h"
#include "llvm/Support/CodeGen.h"
@@ -185,6 +186,7 @@ struct Configuration {
bool ZKeepTextSectionPrefix;
bool ZNodelete;
bool ZNodlopen;
+ bool ZNognustack;
bool ZNow;
bool ZOrigin;
bool ZRelro;
@@ -267,6 +269,10 @@ struct Configuration {
// 4 for ELF32, 8 for ELF64.
int Wordsize;
+
+ // Target triple, inferred from program name or defaulted to LLVM
+ // default target.
+ llvm::Triple TargetTriple;
};
// The only instance of Configuration struct.

View file

@ -0,0 +1,231 @@
$NetBSD: patch-ELF_Driver.cpp,v 1.1 2019/02/01 16:30:00 mgorny Exp $
Add support for customizing LLD behavior on target triple.
https://reviews.llvm.org/D56650
Add '-z nognustack' option to disable emitting PT_GNU_STACK.
https://reviews.llvm.org/D56554
Alter defaults for NetBSD targets:
* add default library search paths
* force combined RO+RW segment due to ld.elf_so limitations
* disable PT_GNU_STACK (meaningless on NetBSD)
* disable 'new dtags', i.e. force RPATH instead of RUNPATH
--- ELF/Driver.cpp.orig 2018-07-31 21:58:26.000000000 +0000
+++ ELF/Driver.cpp
@@ -54,6 +54,7 @@
#include "llvm/Support/LEB128.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/TarWriter.h"
+#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/raw_ostream.h"
#include <cstdlib>
@@ -309,6 +310,9 @@ static void checkOptions(opt::InputArgLi
if (Config->SingleRoRx && !Script->HasSectionsCommand)
error("-execute-only and -no-rosegment cannot be used together");
+ } else if (Config->TargetTriple.isOSNetBSD()) {
+ // force-disable RO segment on NetBSD due to ld.elf_so limitations
+ Config->SingleRoRx = true;
}
}
@@ -341,7 +345,7 @@ static bool isKnown(StringRef S) {
S == "execstack" || S == "hazardplt" || S == "initfirst" ||
S == "keep-text-section-prefix" || S == "lazy" || S == "muldefs" ||
S == "nocombreloc" || S == "nocopyreloc" || S == "nodelete" ||
- S == "nodlopen" || S == "noexecstack" ||
+ S == "nodlopen" || S == "noexecstack" || S == "nognustack" ||
S == "nokeep-text-section-prefix" || S == "norelro" || S == "notext" ||
S == "now" || S == "origin" || S == "relro" || S == "retpolineplt" ||
S == "rodynamic" || S == "text" || S == "wxneeded" ||
@@ -355,6 +359,56 @@ static void checkZOptions(opt::InputArgL
error("unknown -z value: " + StringRef(Arg->getValue()));
}
+void LinkerDriver::appendDefaultSearchPaths() {
+ if (Config->TargetTriple.isOSNetBSD()) {
+ // NetBSD driver relies on the linker knowing the default search paths.
+ // Please keep this in sync with clang/lib/Driver/ToolChains/NetBSD.cpp
+ // (NetBSD::NetBSD constructor)
+ switch (Config->TargetTriple.getArch()) {
+ case llvm::Triple::x86:
+ Config->SearchPaths.push_back("=/usr/lib/i386");
+ break;
+ case llvm::Triple::arm:
+ case llvm::Triple::armeb:
+ case llvm::Triple::thumb:
+ case llvm::Triple::thumbeb:
+ switch (Config->TargetTriple.getEnvironment()) {
+ case llvm::Triple::EABI:
+ case llvm::Triple::GNUEABI:
+ Config->SearchPaths.push_back("=/usr/lib/eabi");
+ break;
+ case llvm::Triple::EABIHF:
+ case llvm::Triple::GNUEABIHF:
+ Config->SearchPaths.push_back("=/usr/lib/eabihf");
+ break;
+ default:
+ Config->SearchPaths.push_back("=/usr/lib/oabi");
+ break;
+ }
+ break;
+#if 0 // TODO
+ case llvm::Triple::mips64:
+ case llvm::Triple::mips64el:
+ if (tools::mips::hasMipsAbiArg(Args, "o32"))
+ Config->SearchPaths.push_back("=/usr/lib/o32");
+ else if (tools::mips::hasMipsAbiArg(Args, "64"))
+ Config->SearchPaths.push_back("=/usr/lib/64");
+ break;
+#endif
+ case llvm::Triple::ppc:
+ Config->SearchPaths.push_back("=/usr/lib/powerpc");
+ break;
+ case llvm::Triple::sparc:
+ Config->SearchPaths.push_back("=/usr/lib/sparc");
+ break;
+ default:
+ break;
+ }
+
+ Config->SearchPaths.push_back("=/usr/lib");
+ }
+}
+
void LinkerDriver::main(ArrayRef<const char *> ArgsArr) {
ELFOptTable Parser;
opt::InputArgList Args = Parser.parse(ArgsArr.slice(1));
@@ -368,6 +422,29 @@ void LinkerDriver::main(ArrayRef<const c
return;
}
+ if (const char *Path = getReproduceOption(Args)) {
+ // Note that --reproduce is a debug option so you can ignore it
+ // if you are trying to understand the whole picture of the code.
+ Expected<std::unique_ptr<TarWriter>> ErrOrWriter =
+ TarWriter::create(Path, path::stem(Path));
+ if (ErrOrWriter) {
+ Tar = ErrOrWriter->get();
+ Tar->append("response.txt", createResponseFile(Args));
+ Tar->append("version.txt", getLLDVersion() + "\n");
+ make<std::unique_ptr<TarWriter>>(std::move(*ErrOrWriter));
+ } else {
+ error(Twine("--reproduce: failed to open ") + Path + ": " +
+ toString(ErrOrWriter.takeError()));
+ }
+ }
+
+
+ initLLVM();
+ setTargetTriple(ArgsArr[0], Args);
+ readConfigs(Args);
+ checkZOptions(Args);
+ appendDefaultSearchPaths();
+
// Handle -v or -version.
//
// A note about "compatible with GNU linkers" message: this is a hack for
@@ -383,8 +460,10 @@ void LinkerDriver::main(ArrayRef<const c
// lot of "configure" scripts out there that are generated by old version
// of Libtool. We cannot convince every software developer to migrate to
// the latest version and re-generate scripts. So we have this hack.
- if (Args.hasArg(OPT_v) || Args.hasArg(OPT_version))
+ if (Args.hasArg(OPT_v) || Args.hasArg(OPT_version)) {
message(getLLDVersion() + " (compatible with GNU linkers)");
+ message("Target: " + Config->TargetTriple.str());
+ }
// The behavior of -v or --version is a bit strange, but this is
// needed for compatibility with GNU linkers.
@@ -393,25 +472,6 @@ void LinkerDriver::main(ArrayRef<const c
if (Args.hasArg(OPT_version))
return;
- if (const char *Path = getReproduceOption(Args)) {
- // Note that --reproduce is a debug option so you can ignore it
- // if you are trying to understand the whole picture of the code.
- Expected<std::unique_ptr<TarWriter>> ErrOrWriter =
- TarWriter::create(Path, path::stem(Path));
- if (ErrOrWriter) {
- Tar = ErrOrWriter->get();
- Tar->append("response.txt", createResponseFile(Args));
- Tar->append("version.txt", getLLDVersion() + "\n");
- make<std::unique_ptr<TarWriter>>(std::move(*ErrOrWriter));
- } else {
- error(Twine("--reproduce: failed to open ") + Path + ": " +
- toString(ErrOrWriter.takeError()));
- }
- }
-
- readConfigs(Args);
- checkZOptions(Args);
- initLLVM();
createFiles(Args);
if (errorCount())
return;
@@ -725,6 +785,34 @@ static void parseClangOption(StringRef O
error(Msg + ": " + StringRef(Err).trim());
}
+void LinkerDriver::setTargetTriple(StringRef argv0, opt::InputArgList &Args) {
+ std::string TargetError;
+
+ // Firstly, see if user specified explicit --target
+ StringRef TargetOpt = Args.getLastArgValue(OPT_target);
+ if (!TargetOpt.empty()) {
+ if (llvm::TargetRegistry::lookupTarget(TargetOpt, TargetError)) {
+ Config->TargetTriple = llvm::Triple(TargetOpt);
+ return;
+ } else
+ error("Unsupported --target=" + TargetOpt + ": " + TargetError);
+ }
+
+ // Secondly, try to get it from program name prefix
+ std::string ProgName = llvm::sys::path::stem(argv0);
+ size_t LastComponent = ProgName.rfind('-');
+ if (LastComponent != std::string::npos) {
+ std::string Prefix = ProgName.substr(0, LastComponent);
+ if (llvm::TargetRegistry::lookupTarget(Prefix, TargetError)) {
+ Config->TargetTriple = llvm::Triple(Prefix);
+ return;
+ }
+ }
+
+ // Finally, use the default target triple
+ Config->TargetTriple = llvm::Triple(getDefaultTargetTriple());
+}
+
// Initializes Config members by the command line options.
void LinkerDriver::readConfigs(opt::InputArgList &Args) {
errorHandler().Verbose = Args.hasArg(OPT_verbose);
@@ -755,7 +843,8 @@ void LinkerDriver::readConfigs(opt::Inpu
Args.hasFlag(OPT_eh_frame_hdr, OPT_no_eh_frame_hdr, false);
Config->EmitRelocs = Args.hasArg(OPT_emit_relocs);
Config->EnableNewDtags =
- Args.hasFlag(OPT_enable_new_dtags, OPT_disable_new_dtags, true);
+ Args.hasFlag(OPT_enable_new_dtags, OPT_disable_new_dtags,
+ !Config->TargetTriple.isOSNetBSD());
Config->Entry = Args.getLastArgValue(OPT_entry);
Config->ExecuteOnly =
Args.hasFlag(OPT_execute_only, OPT_no_execute_only, false);
@@ -842,6 +931,8 @@ void LinkerDriver::readConfigs(opt::Inpu
Config->ZCombreloc = getZFlag(Args, "combreloc", "nocombreloc", true);
Config->ZCopyreloc = getZFlag(Args, "copyreloc", "nocopyreloc", true);
Config->ZExecstack = getZFlag(Args, "execstack", "noexecstack", false);
+ Config->ZNognustack = hasZOption(Args, "nognustack") ||
+ Config->TargetTriple.isOSNetBSD();
Config->ZHazardplt = hasZOption(Args, "hazardplt");
Config->ZInitfirst = hasZOption(Args, "initfirst");
Config->ZKeepTextSectionPrefix = getZFlag(
@@ -1137,7 +1228,7 @@ void LinkerDriver::inferMachineType() {
// each target.
static uint64_t getMaxPageSize(opt::InputArgList &Args) {
uint64_t Val = args::getZOptionValue(Args, OPT_z, "max-page-size",
- Target->DefaultMaxPageSize);
+ lld::elf::Target->DefaultMaxPageSize);
if (!isPowerOf2_64(Val))
error("max-page-size: value isn't a power of 2");
return Val;

View file

@ -0,0 +1,20 @@
$NetBSD: patch-ELF_Driver.h,v 1.1 2019/02/01 16:30:00 mgorny Exp $
Add support for customizing LLD behavior on target triple.
https://reviews.llvm.org/D56650
Alter defaults for NetBSD targets:
* add default library search paths
--- ELF/Driver.h.orig 2018-07-25 21:53:18.000000000 +0000
+++ ELF/Driver.h
@@ -31,7 +31,9 @@ public:
void addLibrary(StringRef Name);
private:
+ void setTargetTriple(StringRef argv0, llvm::opt::InputArgList &Args);
void readConfigs(llvm::opt::InputArgList &Args);
+ void appendDefaultSearchPaths();
void createFiles(llvm::opt::InputArgList &Args);
void inferMachineType();
template <class ELFT> void link(llvm::opt::InputArgList &Args);

View file

@ -0,0 +1,16 @@
$NetBSD: patch-ELF_Options.td,v 1.1 2019/02/01 16:30:00 mgorny Exp $
Add support for customizing LLD behavior on target triple.
https://reviews.llvm.org/D56650
--- ELF/Options.td.orig 2018-07-30 17:36:38.000000000 +0000
+++ ELF/Options.td
@@ -303,6 +303,8 @@ defm symbol_ordering_file:
defm sysroot: Eq<"sysroot", "Set the system root">;
+defm target: Eq<"target", "Apply configuration defaults for a given target">;
+
def target1_rel: F<"target1-rel">, HelpText<"Interpret R_ARM_TARGET1 as R_ARM_REL32">;
def target1_abs: F<"target1-abs">, HelpText<"Interpret R_ARM_TARGET1 as R_ARM_ABS32 (default)">;

View file

@ -0,0 +1,35 @@
$NetBSD: patch-ELF_Writer.cpp,v 1.1 2019/02/01 16:30:00 mgorny Exp $
Add '-z nognustack' option to disable emitting PT_GNU_STACK.
https://reviews.llvm.org/D56554
Alter defaults for NetBSD targets:
* disable PT_GNU_STACK (meaningless on NetBSD)
--- ELF/Writer.cpp.orig 2018-10-31 17:14:17.000000000 +0000
+++ ELF/Writer.cpp
@@ -1881,14 +1881,16 @@ template <class ELFT> std::vector<PhdrEn
if (OutputSection *Cmd = findSection(".openbsd.randomdata"))
AddHdr(PT_OPENBSD_RANDOMIZE, Cmd->getPhdrFlags())->add(Cmd);
- // PT_GNU_STACK is a special section to tell the loader to make the
- // pages for the stack non-executable. If you really want an executable
- // stack, you can pass -z execstack, but that's not recommended for
- // security reasons.
- unsigned Perm = PF_R | PF_W;
- if (Config->ZExecstack)
- Perm |= PF_X;
- AddHdr(PT_GNU_STACK, Perm)->p_memsz = Config->ZStackSize;
+ if (!Config->ZNognustack) {
+ // PT_GNU_STACK is a special section to tell the loader to make the
+ // pages for the stack non-executable. If you really want an executable
+ // stack, you can pass -z execstack, but that's not recommended for
+ // security reasons.
+ unsigned Perm = PF_R | PF_W;
+ if (Config->ZExecstack)
+ Perm |= PF_X;
+ AddHdr(PT_GNU_STACK, Perm)->p_memsz = Config->ZStackSize;
+ }
// PT_OPENBSD_WXNEEDED is a OpenBSD-specific header to mark the executable
// is expected to perform W^X violations, such as calling mprotect(2) or

View file

@ -0,0 +1,18 @@
$NetBSD: patch-docs_ld.lld.1,v 1.1 2019/02/01 16:30:00 mgorny Exp $
Add '-z nognustack' option to disable emitting PT_GNU_STACK.
https://reviews.llvm.org/D56554
--- docs/ld.lld.1.orig 2018-07-30 23:07:44.000000000 +0000
+++ docs/ld.lld.1
@@ -462,6 +462,10 @@ Set the
.Dv DF_1_NOOPEN
flag to indcate that the object may not be opened by
.Xr dlopen 3 .
+.It Cm nognustack
+Do not emit the
+.Dv PT_GNU_STACK
+segment.
.It Cm norelro
Do not indicate that portions of the object shold be mapped read-only
after initial relocation processing.

View file

@ -0,0 +1,25 @@
$NetBSD: patch-test_ELF_gnustack.s,v 1.1 2019/02/01 16:30:00 mgorny Exp $
Add '-z nognustack' option to disable emitting PT_GNU_STACK.
https://reviews.llvm.org/D56554
--- test/ELF/gnustack.s.orig 2018-04-20 21:24:08.000000000 +0000
+++ test/ELF/gnustack.s
@@ -10,6 +10,9 @@
# RUN: ld.lld %t1 -o %t -z noexecstack
# RUN: llvm-readobj --program-headers -s %t | FileCheck --check-prefix=RW %s
+# RUN: ld.lld %t1 -o %t -z nognustack
+# RUN: llvm-readobj --program-headers -s %t | FileCheck --check-prefix=NOGNUSTACK %s
+
# RW: Type: PT_GNU_STACK
# RW-NEXT: Offset: 0x0
# RW-NEXT: VirtualAddress: 0x0
@@ -35,5 +38,7 @@
# RWX-NEXT: ]
# RWX-NEXT: Alignment: 0
+# NOGNUSTACK-NOT: Type: PT_GNU_STACK
+
.globl _start
_start: