pkgsrc-WIP-changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

wip/llvm-project-netbsd: import llvm-project-10.0.0nb20191023



Module Name:	pkgsrc-wip
Committed By:	Kamil Rytarowski <n54%gmx.com@localhost>
Pushed By:	kamil
Date:		Wed Oct 23 22:28:37 2019 +0200
Changeset:	580e549f4574a4075b7fb32716dc064c49c2f2a7

Added Files:
	llvm-project-netbsd/DESCR
	llvm-project-netbsd/Makefile
	llvm-project-netbsd/PLIST
	llvm-project-netbsd/buildlink3.mk
	llvm-project-netbsd/distinfo
	llvm-project-netbsd/options.mk
	llvm-project-netbsd/patches/patch-clang_lib_Basic_Targets_OSTargets.h
	llvm-project-netbsd/patches/patch-clang_lib_Driver_ToolChains_NetBSD.cpp
	llvm-project-netbsd/patches/patch-clang_test_Sema_128bitfloat.cpp
	llvm-project-netbsd/patches/patch-clang_tools_clang-format_CMakeLists.txt
	llvm-project-netbsd/patches/patch-lld_CMakeLists.txt
	llvm-project-netbsd/patches/patch-lld_ELF_Arch_AArch64.cpp
	llvm-project-netbsd/patches/patch-lld_ELF_Config.h
	llvm-project-netbsd/patches/patch-lld_ELF_Driver.cpp
	llvm-project-netbsd/patches/patch-lld_ELF_Options.td
	llvm-project-netbsd/patches/patch-lld_ELF_Writer.cpp
	llvm-project-netbsd/patches/patch-lld_docs_ld.lld.1
	llvm-project-netbsd/patches/patch-lld_test_ELF_gnustack.s

Log Message:
wip/llvm-project-netbsd: import llvm-project-10.0.0nb20191023

The LLVM Compiler Infrastructure

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=580e549f4574a4075b7fb32716dc064c49c2f2a7

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 llvm-project-netbsd/DESCR                          |   1 +
 llvm-project-netbsd/Makefile                       |  38 ++++
 llvm-project-netbsd/PLIST                          |  49 +++++
 llvm-project-netbsd/buildlink3.mk                  |  14 ++
 llvm-project-netbsd/distinfo                       |  22 ++
 llvm-project-netbsd/options.mk                     |  20 ++
 .../patch-clang_lib_Basic_Targets_OSTargets.h      |  28 +++
 .../patch-clang_lib_Driver_ToolChains_NetBSD.cpp   |  22 ++
 .../patches/patch-clang_test_Sema_128bitfloat.cpp  |  13 ++
 .../patch-clang_tools_clang-format_CMakeLists.txt  |  11 +
 .../patches/patch-lld_CMakeLists.txt               |  12 ++
 .../patches/patch-lld_ELF_Arch_AArch64.cpp         |  20 ++
 llvm-project-netbsd/patches/patch-lld_ELF_Config.h |  57 +++++
 .../patches/patch-lld_ELF_Driver.cpp               | 237 +++++++++++++++++++++
 .../patches/patch-lld_ELF_Options.td               |  23 ++
 .../patches/patch-lld_ELF_Writer.cpp               |  29 +++
 .../patches/patch-lld_docs_ld.lld.1                |  15 ++
 .../patches/patch-lld_test_ELF_gnustack.s          |  22 ++
 18 files changed, 633 insertions(+)

diffs:
diff --git a/llvm-project-netbsd/DESCR b/llvm-project-netbsd/DESCR
new file mode 100644
index 0000000000..18b3e52fe4
--- /dev/null
+++ b/llvm-project-netbsd/DESCR
@@ -0,0 +1 @@
+The LLVM Compiler Infrastructure
diff --git a/llvm-project-netbsd/Makefile b/llvm-project-netbsd/Makefile
new file mode 100644
index 0000000000..53185f696a
--- /dev/null
+++ b/llvm-project-netbsd/Makefile
@@ -0,0 +1,38 @@
+# $NetBSD: Makefile,v 1.1 2019/02/01 16:30:00 mgorny Exp $
+
+GIT_REPOSITORIES=	llvm-project
+GIT_REPO.llvm-project=	https://github.com/llvm/llvm-project
+
+PKGNAME=		llvm-project-10.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://llvm.org/
+COMMENT=		The LLVM Compiler Infrastructure
+LICENSE=		apache2
+
+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/git-package.mk"
+.include "../../lang/python/tool.mk"
+.include "../../mk/bsd.pkg.mk"
diff --git a/llvm-project-netbsd/PLIST b/llvm-project-netbsd/PLIST
new file mode 100644
index 0000000000..5b294f225a
--- /dev/null
+++ b/llvm-project-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/llvm-project-netbsd/buildlink3.mk b/llvm-project-netbsd/buildlink3.mk
new file mode 100644
index 0000000000..7cb1f29bb0
--- /dev/null
+++ b/llvm-project-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/llvm-project-netbsd/distinfo b/llvm-project-netbsd/distinfo
new file mode 100644
index 0000000000..5330d4b030
--- /dev/null
+++ b/llvm-project-netbsd/distinfo
@@ -0,0 +1,22 @@
+$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-clang_lib_Basic_Targets_OSTargets.h) = f4544fe5daf2febad4b5e9ff6b5d84a2d90b3c1e
+SHA1 (patch-clang_lib_Driver_ToolChains_NetBSD.cpp) = 1a85c66c8b3aa5b467c41c0f98efeaf55865a06f
+SHA1 (patch-clang_test_Sema_128bitfloat.cpp) = b3bd2d7cbb07a2d3c2ad14e75b3f91e0f5be43fc
+SHA1 (patch-clang_tools_clang-format_CMakeLists.txt) = 3c9d9f1d5c7b6d9ec68ea537f4c4c3ec2e4899ca
+SHA1 (patch-lld_CMakeLists.txt) = 3add301b0d0264622265b1f3c18eaed0665b11a6
+SHA1 (patch-lld_ELF_Arch_AArch64.cpp) = 193e9d26cd8b5720465891e1b548e09be08b9eae
+SHA1 (patch-lld_ELF_Config.h) = f625727b7b0ee4a7a60f5c7431ef15e533f56d5e
+SHA1 (patch-lld_ELF_Driver.cpp) = abf9a12f3caa1d7134692d34540c6cef327072c0
+SHA1 (patch-lld_ELF_Options.td) = 98c36caa39c5b207068aad2796e65b49dca52e13
+SHA1 (patch-lld_ELF_Writer.cpp) = bf668a5f54b0d95b80c1c3bc3c99557d18c7e022
+SHA1 (patch-lld_docs_ld.lld.1) = 3e7c0913b3f0f5c2a8539d17dfe383788710ffa1
+SHA1 (patch-lld_test_ELF_gnustack.s) = 8410db9a2c57c53ac62453d533e4a17b250cfd07
diff --git a/llvm-project-netbsd/options.mk b/llvm-project-netbsd/options.mk
new file mode 100644
index 0000000000..ceaf154539
--- /dev/null
+++ b/llvm-project-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/llvm-project-netbsd/patches/patch-clang_lib_Basic_Targets_OSTargets.h b/llvm-project-netbsd/patches/patch-clang_lib_Basic_Targets_OSTargets.h
new file mode 100644
index 0000000000..0c6eb98980
--- /dev/null
+++ b/llvm-project-netbsd/patches/patch-clang_lib_Basic_Targets_OSTargets.h
@@ -0,0 +1,28 @@
+$NetBSD$
+
+--- clang/lib/Basic/Targets/OSTargets.h.orig	2019-10-23 20:24:27.393021814 +0000
++++ clang/lib/Basic/Targets/OSTargets.h
+@@ -436,12 +436,23 @@ protected:
+     Builder.defineMacro("__ELF__");
+     if (Opts.POSIXThreads)
+       Builder.defineMacro("_REENTRANT");
++    if (this->HasFloat128)
++      Builder.defineMacro("__FLOAT128__");
+   }
+ 
+ public:
+   NetBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
+       : OSTargetInfo<Target>(Triple, Opts) {
+     this->MCountName = "__mcount";
++
++    switch (Triple.getArch()) {
++    default:
++      break;
++    case llvm::Triple::x86:
++    case llvm::Triple::x86_64:
++      this->HasFloat128 = true;
++      break;
++    }
+   }
+ };
+ 
diff --git a/llvm-project-netbsd/patches/patch-clang_lib_Driver_ToolChains_NetBSD.cpp b/llvm-project-netbsd/patches/patch-clang_lib_Driver_ToolChains_NetBSD.cpp
new file mode 100644
index 0000000000..12cff69d70
--- /dev/null
+++ b/llvm-project-netbsd/patches/patch-clang_lib_Driver_ToolChains_NetBSD.cpp
@@ -0,0 +1,22 @@
+$NetBSD$
+
+--- clang/lib/Driver/ToolChains/NetBSD.cpp.orig	2019-10-23 20:24:27.467144768 +0000
++++ clang/lib/Driver/ToolChains/NetBSD.cpp
+@@ -266,7 +266,7 @@ void netbsd::Linker::ConstructJob(Compil
+   unsigned Major, Minor, Micro;
+   ToolChain.getTriple().getOSVersion(Major, Minor, Micro);
+   bool useLibgcc = true;
+-  if (Major >= 7 || Major == 0) {
++  if (false) {
+     switch (ToolChain.getArch()) {
+     case llvm::Triple::aarch64:
+     case llvm::Triple::aarch64_be:
+@@ -402,7 +402,7 @@ Tool *NetBSD::buildLinker() const { retu
+ ToolChain::CXXStdlibType NetBSD::GetDefaultCXXStdlibType() const {
+   unsigned Major, Minor, Micro;
+   getTriple().getOSVersion(Major, Minor, Micro);
+-  if (Major >= 7 || Major == 0) {
++  if (false) {
+     switch (getArch()) {
+     case llvm::Triple::aarch64:
+     case llvm::Triple::aarch64_be:
diff --git a/llvm-project-netbsd/patches/patch-clang_test_Sema_128bitfloat.cpp b/llvm-project-netbsd/patches/patch-clang_test_Sema_128bitfloat.cpp
new file mode 100644
index 0000000000..445dcc6a5d
--- /dev/null
+++ b/llvm-project-netbsd/patches/patch-clang_test_Sema_128bitfloat.cpp
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- clang/test/Sema/128bitfloat.cpp.orig	2019-10-23 20:24:29.833664183 +0000
++++ clang/test/Sema/128bitfloat.cpp
+@@ -4,6 +4,8 @@
+ // RUN: %clang_cc1 -triple i686-windows-gnu -verify -std=c++11 %s
+ // RUN: %clang_cc1 -triple x86_64-windows-gnu -verify -std=c++11 %s
+ // RUN: %clang_cc1 -triple x86_64-windows-msvc -verify -std=c++11 %s
++// RUN: %clang_cc1 -triple i386--netbsd -verify -std=c++11 %s
++// RUN: %clang_cc1 -triple x86_64--netbsd -verify -std=c++11 %s
+ 
+ #if defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)
+ __float128 f;
diff --git a/llvm-project-netbsd/patches/patch-clang_tools_clang-format_CMakeLists.txt b/llvm-project-netbsd/patches/patch-clang_tools_clang-format_CMakeLists.txt
new file mode 100644
index 0000000000..ecb3c4fe00
--- /dev/null
+++ b/llvm-project-netbsd/patches/patch-clang_tools_clang-format_CMakeLists.txt
@@ -0,0 +1,11 @@
+$NetBSD$
+
+--- clang/tools/clang-format/CMakeLists.txt.orig	2019-10-23 20:24:30.090438326 +0000
++++ clang/tools/clang-format/CMakeLists.txt
+@@ -37,5 +37,5 @@ install(PROGRAMS clang-format.py
+   DESTINATION share/clang
+   COMPONENT clang-format)
+ install(PROGRAMS git-clang-format
+-  DESTINATION bin
++  DESTINATION share/clang
+   COMPONENT clang-format)
diff --git a/llvm-project-netbsd/patches/patch-lld_CMakeLists.txt b/llvm-project-netbsd/patches/patch-lld_CMakeLists.txt
new file mode 100644
index 0000000000..c60871d193
--- /dev/null
+++ b/llvm-project-netbsd/patches/patch-lld_CMakeLists.txt
@@ -0,0 +1,12 @@
+$NetBSD$
+
+--- lld/CMakeLists.txt.orig	2019-10-23 20:24:31.965882195 +0000
++++ lld/CMakeLists.txt
+@@ -85,7 +85,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/llvm-project-netbsd/patches/patch-lld_ELF_Arch_AArch64.cpp b/llvm-project-netbsd/patches/patch-lld_ELF_Arch_AArch64.cpp
new file mode 100644
index 0000000000..1dd9538532
--- /dev/null
+++ b/llvm-project-netbsd/patches/patch-lld_ELF_Arch_AArch64.cpp
@@ -0,0 +1,20 @@
+$NetBSD$
+
+--- lld/ELF/Arch/AArch64.cpp.orig	2019-10-23 20:24:31.973047369 +0000
++++ lld/ELF/Arch/AArch64.cpp
+@@ -67,9 +67,12 @@ AArch64::AArch64() {
+   pltHeaderSize = 32;
+   defaultMaxPageSize = 65536;
+ 
+-  // Align to the 2 MiB page size (known as a superpage or huge page).
+-  // FreeBSD automatically promotes 2 MiB-aligned allocations.
+-  defaultImageBase = 0x200000;
++  if (config->targetTriple.isOSNetBSD())
++    defaultImageBase = 0x200100000;
++  else
++    // Align to the 2 MiB page size (known as a superpage or huge page).
++    // FreeBSD automatically promotes 2 MiB-aligned allocations.
++    defaultImageBase = 0x200000;
+ 
+   needsThunks = true;
+ }
diff --git a/llvm-project-netbsd/patches/patch-lld_ELF_Config.h b/llvm-project-netbsd/patches/patch-lld_ELF_Config.h
new file mode 100644
index 0000000000..c582f4b340
--- /dev/null
+++ b/llvm-project-netbsd/patches/patch-lld_ELF_Config.h
@@ -0,0 +1,57 @@
+$NetBSD$
+
+--- lld/ELF/Config.h.orig	2019-10-23 20:24:31.975278079 +0000
++++ lld/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"
+@@ -64,6 +65,9 @@ enum class ARMVFPArgKind { Default, Base
+ // For -z noseparate-code, -z separate-code and -z separate-loadable-segments.
+ enum class SeparateSegmentKind { None, Code, Loadable };
+ 
++// For -z *stack
++enum class GnuStackKind { None, Exec, NoExec };
++
+ struct SymbolVersion {
+   llvm::StringRef name;
+   bool isExternCpp;
+@@ -147,6 +151,7 @@ struct Configuration {
+   bool enableNewDtags;
+   bool executeOnly;
+   bool exportDynamic;
++  bool fixCortexA53Errata835769;
+   bool fixCortexA53Errata843419;
+   bool fixCortexA8;
+   bool forceBTI;
+@@ -208,6 +213,7 @@ struct Configuration {
+   bool zNodefaultlib;
+   bool zNodelete;
+   bool zNodlopen;
++  bool zNognustack;
+   bool zNow;
+   bool zOrigin;
+   bool zRelro;
+@@ -216,6 +222,7 @@ struct Configuration {
+   bool zRetpolineplt;
+   bool zWxneeded;
+   DiscardPolicy discard;
++  GnuStackKind zGnustack;
+   ICFLevel icf;
+   OrphanHandlingPolicy orphanHandling;
+   SortSectionPolicy sortSection;
+@@ -306,6 +313,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/llvm-project-netbsd/patches/patch-lld_ELF_Driver.cpp b/llvm-project-netbsd/patches/patch-lld_ELF_Driver.cpp
new file mode 100644
index 0000000000..0f95151563
--- /dev/null
+++ b/llvm-project-netbsd/patches/patch-lld_ELF_Driver.cpp
@@ -0,0 +1,237 @@
+$NetBSD$
+
+--- lld/ELF/Driver.cpp.orig	2019-10-23 20:24:31.976090112 +0000
++++ lld/ELF/Driver.cpp
+@@ -55,6 +55,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>
+@@ -74,6 +75,8 @@ LinkerDriver *driver;
+ 
+ static void setConfigs(opt::InputArgList &args);
+ static void readConfigs(opt::InputArgList &args);
++static void appendDefaultSearchPaths(void);
++static void setTargetTriple(StringRef argv0, opt::InputArgList &args);
+ 
+ bool link(ArrayRef<const char *> args, bool canExitEarly, raw_ostream &error) {
+   errorHandler().logName = args::getFilenameWithoutExe(args[0]);
+@@ -129,7 +132,7 @@ static std::tuple<ELFKind, uint16_t, uin
+   std::pair<ELFKind, uint16_t> ret =
+       StringSwitch<std::pair<ELFKind, uint16_t>>(s)
+           .Cases("aarch64elf", "aarch64linux", "aarch64_elf64_le_vec",
+-                 {ELF64LEKind, EM_AARCH64})
++		 "aarch64nbsd", {ELF64LEKind, EM_AARCH64})
+           .Cases("armelf", "armelf_linux_eabi", {ELF32LEKind, EM_ARM})
+           .Case("elf32_x86_64", {ELF32LEKind, EM_X86_64})
+           .Cases("elf32btsmip", "elf32btsmipn32", {ELF32BEKind, EM_MIPS})
+@@ -296,6 +299,9 @@ static void checkOptions() {
+   if (config->emachine == EM_MIPS && config->gnuHash)
+     error("the .gnu.hash section is not compatible with the MIPS target");
+ 
++  if (config->fixCortexA53Errata835769 && config->emachine != EM_AARCH64)
++    error("--fix-cortex-a53-835769 is only supported on AArch64 targets");
++
+   if (config->fixCortexA53Errata843419 && config->emachine != EM_AARCH64)
+     error("--fix-cortex-a53-843419 is only supported on AArch64 targets");
+ 
+@@ -344,6 +350,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;
+   }
+ 
+   if (config->zRetpolineplt && config->requireCET)
+@@ -394,6 +403,20 @@ static SeparateSegmentKind getZSeparate(
+   return SeparateSegmentKind::None;
+ }
+ 
++static GnuStackKind getZGnuStack(opt::InputArgList &args) {
++  for (auto *arg : args.filtered_reverse(OPT_z)) {
++    if (StringRef("execstack") == arg->getValue())
++      return GnuStackKind::Exec;
++    if (StringRef("noexecstack") == arg->getValue())
++      return GnuStackKind::NoExec;
++    if (StringRef("nognustack") == arg->getValue())
++      return GnuStackKind::None;
++  }
++
++  // default
++  return GnuStackKind::NoExec;
++}
++
+ static bool isKnownZFlag(StringRef s) {
+   return s == "combreloc" || s == "copyreloc" || s == "defs" ||
+          s == "execstack" || s == "global" || s == "hazardplt" ||
+@@ -401,7 +424,7 @@ static bool isKnownZFlag(StringRef s) {
+          s == "keep-text-section-prefix" || s == "lazy" || s == "muldefs" ||
+          s == "separate-code" || s == "separate-loadable-segments" ||
+          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 == "noseparate-code" || s == "notext" || s == "now" ||
+          s == "origin" || s == "relro" || s == "retpolineplt" ||
+@@ -417,6 +440,56 @@ static void checkZOptions(opt::InputArgL
+       error("unknown -z value: " + StringRef(arg->getValue()));
+ }
+ 
++static void 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));
+@@ -431,6 +504,8 @@ void LinkerDriver::main(ArrayRef<const c
+     return;
+   }
+ 
++  setTargetTriple(argsArr[0], args);
++
+   // Handle -v or -version.
+   //
+   // A note about "compatible with GNU linkers" message: this is a hack for
+@@ -446,8 +521,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());
++  }
+ 
+   if (const char *path = getReproduceOption(args)) {
+     // Note that --reproduce is a debug option so you can ignore it
+@@ -465,6 +542,8 @@ void LinkerDriver::main(ArrayRef<const c
+ 
+   readConfigs(args);
+ 
++  appendDefaultSearchPaths();
++
+   // 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))
+@@ -812,6 +891,34 @@ static void parseClangOption(StringRef o
+   error(msg + ": " + StringRef(err).trim());
+ }
+ 
++static void 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.
+ static void readConfigs(opt::InputArgList &args) {
+   errorHandler().verbose = args.hasArg(OPT_verbose);
+@@ -851,7 +958,8 @@ static void readConfigs(opt::InputArgLis
+   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);
+@@ -859,6 +967,7 @@ static void readConfigs(opt::InputArgLis
+       args.hasFlag(OPT_export_dynamic, OPT_no_export_dynamic, false);
+   config->filterList = args::getStrings(args, OPT_filter);
+   config->fini = args.getLastArgValue(OPT_fini, "_fini");
++  config->fixCortexA53Errata835769 = args.hasArg(OPT_fix_cortex_a53_843419);
+   config->fixCortexA53Errata843419 = args.hasArg(OPT_fix_cortex_a53_843419);
+   config->fixCortexA8 = args.hasArg(OPT_fix_cortex_a8);
+   config->forceBTI = args.hasArg(OPT_force_bti);
+@@ -951,6 +1060,7 @@ static void readConfigs(opt::InputArgLis
+   config->zCopyreloc = getZFlag(args, "copyreloc", "nocopyreloc", true);
+   config->zExecstack = getZFlag(args, "execstack", "noexecstack", false);
+   config->zGlobal = hasZOption(args, "global");
++  config->zGnustack = getZGnuStack(args);
+   config->zHazardplt = hasZOption(args, "hazardplt");
+   config->zIfuncNoplt = hasZOption(args, "ifunc-noplt");
+   config->zInitfirst = hasZOption(args, "initfirst");
+@@ -1269,7 +1379,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");
+   if (config->nmagic || config->omagic) {
diff --git a/llvm-project-netbsd/patches/patch-lld_ELF_Options.td b/llvm-project-netbsd/patches/patch-lld_ELF_Options.td
new file mode 100644
index 0000000000..e807b36932
--- /dev/null
+++ b/llvm-project-netbsd/patches/patch-lld_ELF_Options.td
@@ -0,0 +1,23 @@
+$NetBSD$
+
+--- lld/ELF/Options.td.orig	2019-10-23 20:24:31.979154507 +0000
++++ lld/ELF/Options.td
+@@ -168,6 +168,9 @@ defm filter: Eq<"filter", "Set DT_FILTER
+ 
+ defm fini: Eq<"fini", "Specify a finalizer function">, MetaVarName<"<symbol>">;
+ 
++def fix_cortex_a53_835769: F<"fix-cortex-a53-835769">,
++  HelpText<"Apply fixes for AArch64 Cortex-A53 erratum 835769">;
++
+ def fix_cortex_a53_843419: F<"fix-cortex-a53-843419">,
+   HelpText<"Apply fixes for AArch64 Cortex-A53 erratum 843419">;
+ 
+@@ -346,6 +349,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/llvm-project-netbsd/patches/patch-lld_ELF_Writer.cpp b/llvm-project-netbsd/patches/patch-lld_ELF_Writer.cpp
new file mode 100644
index 0000000000..e56b37e01d
--- /dev/null
+++ b/llvm-project-netbsd/patches/patch-lld_ELF_Writer.cpp
@@ -0,0 +1,29 @@
+$NetBSD$
+
+--- lld/ELF/Writer.cpp.orig	2019-10-23 20:24:31.984556869 +0000
++++ lld/ELF/Writer.cpp
+@@ -2172,14 +2172,16 @@ std::vector<PhdrEntry *> Writer<ELFT>::c
+   if (OutputSection *cmd = findSection(".openbsd.randomdata", partNo))
+     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->zGnustack != GnuStackKind::None) {
++    // 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->zGnustack == GnuStackKind::Exec)
++      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/llvm-project-netbsd/patches/patch-lld_docs_ld.lld.1 b/llvm-project-netbsd/patches/patch-lld_docs_ld.lld.1
new file mode 100644
index 0000000000..c3a11c822e
--- /dev/null
+++ b/llvm-project-netbsd/patches/patch-lld_docs_ld.lld.1
@@ -0,0 +1,15 @@
+$NetBSD$
+
+--- lld/docs/ld.lld.1.orig	2019-10-23 20:24:36.059771858 +0000
++++ lld/docs/ld.lld.1
+@@ -654,6 +654,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.
+ .Pp
+ .It Cm norelro
+ Do not indicate that portions of the object shold be mapped read-only
diff --git a/llvm-project-netbsd/patches/patch-lld_test_ELF_gnustack.s b/llvm-project-netbsd/patches/patch-lld_test_ELF_gnustack.s
new file mode 100644
index 0000000000..8c852609b0
--- /dev/null
+++ b/llvm-project-netbsd/patches/patch-lld_test_ELF_gnustack.s
@@ -0,0 +1,22 @@
+$NetBSD$
+
+--- lld/test/ELF/gnustack.s.orig	2019-10-23 20:24:36.334197305 +0000
++++ lld/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 noexecstack
++# 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