pkgsrc-WIP-changes archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
wip/lld-netbsd: import lld-9.0.0nb20190201
Module Name: pkgsrc-wip
Committed By: Kamil Rytarowski <n54%gmx.com@localhost>
Pushed By: kamil
Date: Sat Feb 2 00:27:50 2019 +0100
Changeset: 178812758a2dbcaf643c43742291fc389d01d079
Added Files:
lld-netbsd/DESCR
lld-netbsd/Makefile
lld-netbsd/PLIST
lld-netbsd/buildlink3.mk
lld-netbsd/distinfo
lld-netbsd/options.mk
lld-netbsd/patches/patch-CMakeLists.txt
lld-netbsd/patches/patch-ELF_Config.h
lld-netbsd/patches/patch-ELF_Driver.cpp
lld-netbsd/patches/patch-ELF_Driver.h
lld-netbsd/patches/patch-ELF_Options.td
lld-netbsd/patches/patch-ELF_Writer.cpp
lld-netbsd/patches/patch-docs_ld.lld.1
lld-netbsd/patches/patch-test_ELF_gnustack.s
Log Message:
wip/lld-netbsd: import lld-9.0.0nb20190201
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.
To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=178812758a2dbcaf643c43742291fc389d01d079
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
diffstat:
lld-netbsd/DESCR | 11 ++
lld-netbsd/Makefile | 40 +++++
lld-netbsd/PLIST | 49 ++++++
lld-netbsd/buildlink3.mk | 14 ++
lld-netbsd/distinfo | 18 +++
lld-netbsd/options.mk | 20 +++
lld-netbsd/patches/patch-CMakeLists.txt | 16 ++
lld-netbsd/patches/patch-ELF_Config.h | 37 +++++
lld-netbsd/patches/patch-ELF_Driver.cpp | 228 +++++++++++++++++++++++++++
lld-netbsd/patches/patch-ELF_Driver.h | 20 +++
lld-netbsd/patches/patch-ELF_Options.td | 16 ++
lld-netbsd/patches/patch-ELF_Writer.cpp | 35 ++++
lld-netbsd/patches/patch-docs_ld.lld.1 | 18 +++
lld-netbsd/patches/patch-test_ELF_gnustack.s | 25 +++
14 files changed, 547 insertions(+)
diffs:
diff --git a/lld-netbsd/DESCR b/lld-netbsd/DESCR
new file mode 100644
index 0000000000..4b5b6daa5b
--- /dev/null
+++ b/lld-netbsd/DESCR
@@ -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.
diff --git a/lld-netbsd/Makefile b/lld-netbsd/Makefile
new file mode 100644
index 0000000000..e924b3dc92
--- /dev/null
+++ b/lld-netbsd/Makefile
@@ -0,0 +1,40 @@
+# $NetBSD: Makefile,v 1.1 2019/02/01 16:30:00 mgorny Exp $
+
+SVN_REPOSITORIES= lld
+SVN_REPO.lld= http://llvm.org/svn/llvm-project/lld/trunk
+SVN_REVISION.lld= 352933
+
+PKGNAME= lld-9.0.0
+#DISTNAME= ${PKGNAME}.src
+CATEGORIES= devel
+#MASTER_SITES= http://llvm.org/releases/${PKGVERSION_NOREV}/
+#EXTRACT_SUFX= .tar.xz
+#DISTFILES= ${DEFAULT_DISTFILES}
+
+MAINTAINER= pkgsrc-users%NetBSD.org@localhost
+HOMEPAGE= http://lld.llvm.org/
+COMMENT= The LLVM Linker
+LICENSE= modified-bsd
+
+USE_LANGUAGES= c c++11
+USE_CMAKE= yes
+GCC_REQD+= 4.8
+
+WRKSRC= ${WRKDIR}/${PKGBASE}
+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 "../../wip/mk/svn-package.mk"
+.include "../../lang/python/tool.mk"
+#.include "../../lang/llvm/buildlink3.mk"
+.include "../../mk/bsd.pkg.mk"
diff --git a/lld-netbsd/PLIST b/lld-netbsd/PLIST
new file mode 100644
index 0000000000..5b294f225a
--- /dev/null
+++ b/lld-netbsd/PLIST
@@ -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
diff --git a/lld-netbsd/buildlink3.mk b/lld-netbsd/buildlink3.mk
new file mode 100644
index 0000000000..7cb1f29bb0
--- /dev/null
+++ b/lld-netbsd/buildlink3.mk
@@ -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
diff --git a/lld-netbsd/distinfo b/lld-netbsd/distinfo
new file mode 100644
index 0000000000..5321b695fe
--- /dev/null
+++ b/lld-netbsd/distinfo
@@ -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) = bade1445bbe11d881881dfd1164529e508913b5b
+SHA1 (patch-ELF_Driver.cpp) = 323ec3ceb6d9baea6296fc2472c03c2e89ac5c2b
+SHA1 (patch-ELF_Driver.h) = e100fb0c86cc7d20b0f64919e73888a81a4836df
+SHA1 (patch-ELF_Options.td) = c8107a2c599b2444e52bdefe5f2dc539d277a092
+SHA1 (patch-ELF_Writer.cpp) = ab4ca25f832f20a5b4c80fe0f5f28822c09fb4ee
+SHA1 (patch-docs_ld.lld.1) = 204ea3263b6ac9de92a60bfec3a4fc5add9f3046
+SHA1 (patch-test_ELF_gnustack.s) = b3827436dcfc67d51b8d293b11538808537ddeec
diff --git a/lld-netbsd/options.mk b/lld-netbsd/options.mk
new file mode 100644
index 0000000000..ceaf154539
--- /dev/null
+++ b/lld-netbsd/options.mk
@@ -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
diff --git a/lld-netbsd/patches/patch-CMakeLists.txt b/lld-netbsd/patches/patch-CMakeLists.txt
new file mode 100644
index 0000000000..211f3f1cfa
--- /dev/null
+++ b/lld-netbsd/patches/patch-CMakeLists.txt
@@ -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()
diff --git a/lld-netbsd/patches/patch-ELF_Config.h b/lld-netbsd/patches/patch-ELF_Config.h
new file mode 100644
index 0000000000..f047cfe4cd
--- /dev/null
+++ b/lld-netbsd/patches/patch-ELF_Config.h
@@ -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 2019-02-01 23:06:35.000000000 +0000
++++ ELF/Config.h
+@@ -13,6 +13,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"
+@@ -194,6 +195,7 @@ struct Configuration {
+ bool ZNodefaultlib;
+ bool ZNodelete;
+ bool ZNodlopen;
++ bool ZNognustack;
+ bool ZNow;
+ bool ZOrigin;
+ bool ZRelro;
+@@ -277,6 +279,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.
diff --git a/lld-netbsd/patches/patch-ELF_Driver.cpp b/lld-netbsd/patches/patch-ELF_Driver.cpp
new file mode 100644
index 0000000000..1e9c933552
--- /dev/null
+++ b/lld-netbsd/patches/patch-ELF_Driver.cpp
@@ -0,0 +1,228 @@
+$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 2019-02-01 23:06:35.000000000 +0000
++++ ELF/Driver.cpp
+@@ -53,6 +53,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>
+@@ -317,6 +318,9 @@ static void checkOptions() {
+
+ 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;
+ }
+ }
+
+@@ -350,7 +354,7 @@ static bool isKnownZFlag(StringRef S) {
+ S == "initfirst" || S == "interpose" ||
+ S == "keep-text-section-prefix" || S == "lazy" || S == "muldefs" ||
+ S == "nocombreloc" || S == "nocopyreloc" || S == "nodefaultlib" ||
+- S == "nodelete" || S == "nodlopen" || S == "noexecstack" ||
++ S == "nodelete" || 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" ||
+@@ -364,6 +368,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));
+@@ -377,6 +431,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
+@@ -392,26 +469,11 @@ 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)");
+-
+- 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 = std::move(*ErrOrWriter);
+- Tar->append("response.txt", createResponseFile(Args));
+- Tar->append("version.txt", getLLDVersion() + "\n");
+- } else {
+- error("--reproduce: " + toString(ErrOrWriter.takeError()));
+- }
++ message("Target: " + Config->TargetTriple.str());
+ }
+
+- readConfigs(Args);
+- checkZOptions(Args);
+-
+ // The behavior of -v or --version is a bit strange, but this is
+ // needed for compatibility with GNU linkers.
+ if (Args.hasArg(OPT_v) && !Args.hasArg(OPT_INPUT))
+@@ -419,7 +481,6 @@ void LinkerDriver::main(ArrayRef<const c
+ if (Args.hasArg(OPT_version))
+ return;
+
+- initLLVM();
+ createFiles(Args);
+ if (errorCount())
+ return;
+@@ -745,6 +806,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);
+@@ -780,7 +869,7 @@ void LinkerDriver::readConfigs(opt::Inpu
+ Config->CallGraphProfileSort = Args.hasFlag(
+ OPT_call_graph_profile_sort, OPT_no_call_graph_profile_sort, true);
+ 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);
+@@ -870,6 +959,7 @@ 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->ZGlobal = hasZOption(Args, "global");
+ Config->ZHazardplt = hasZOption(Args, "hazardplt");
+ Config->ZInitfirst = hasZOption(Args, "initfirst");
+@@ -1174,7 +1264,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;
diff --git a/lld-netbsd/patches/patch-ELF_Driver.h b/lld-netbsd/patches/patch-ELF_Driver.h
new file mode 100644
index 0000000000..560609c3f9
--- /dev/null
+++ b/lld-netbsd/patches/patch-ELF_Driver.h
@@ -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);
diff --git a/lld-netbsd/patches/patch-ELF_Options.td b/lld-netbsd/patches/patch-ELF_Options.td
new file mode 100644
index 0000000000..e7dd202bb8
--- /dev/null
+++ b/lld-netbsd/patches/patch-ELF_Options.td
@@ -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)">;
diff --git a/lld-netbsd/patches/patch-ELF_Writer.cpp b/lld-netbsd/patches/patch-ELF_Writer.cpp
new file mode 100644
index 0000000000..469e4d3fcf
--- /dev/null
+++ b/lld-netbsd/patches/patch-ELF_Writer.cpp
@@ -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
diff --git a/lld-netbsd/patches/patch-docs_ld.lld.1 b/lld-netbsd/patches/patch-docs_ld.lld.1
new file mode 100644
index 0000000000..449cb574b9
--- /dev/null
+++ b/lld-netbsd/patches/patch-docs_ld.lld.1
@@ -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 2019-02-01 23:06:51.000000000 +0000
++++ docs/ld.lld.1
+@@ -512,6 +512,10 @@ Set the
+ .Dv DF_1_NOOPEN
+ flag to indicate 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.
diff --git a/lld-netbsd/patches/patch-test_ELF_gnustack.s b/lld-netbsd/patches/patch-test_ELF_gnustack.s
new file mode 100644
index 0000000000..9b697c2705
--- /dev/null
+++ b/lld-netbsd/patches/patch-test_ELF_gnustack.s
@@ -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:
Home |
Main Index |
Thread Index |
Old Index