pkgsrc-WIP-changes archive

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

llvm-netbsd: Drop local patches for LLVM JIT



Module Name:	pkgsrc-wip
Committed By:	Kamil Rytarowski <n54%gmx.com@localhost>
Pushed By:	kamil
Date:		Mon Jul 31 15:08:23 2017 +0200
Changeset:	ad2e08a903d8e5dd97217eb3fc6f09c92c61ffcb

Modified Files:
	llvm-netbsd/distinfo
Removed Files:
	llvm-netbsd/patches/patch-include_llvm_ExecutionEngine_Orc_IndirectionUtils.h
	llvm-netbsd/patches/patch-include_llvm_ExecutionEngine_Orc_OrcRemoteTargetServer.h
	llvm-netbsd/patches/patch-include_llvm_ExecutionEngine_SectionMemoryManager.h
	llvm-netbsd/patches/patch-include_llvm_Support_Memory.h
	llvm-netbsd/patches/patch-lib_ExecutionEngine_Orc_OrcABISupport.cpp
	llvm-netbsd/patches/patch-lib_ExecutionEngine_SectionMemoryManager.cpp
	llvm-netbsd/patches/patch-lib_Support_Unix_Memory.inc
	llvm-netbsd/patches/patch-lib_Support_Unix_Signals.inc
	llvm-netbsd/patches/patch-tools_llvm-rtdyld_llvm-rtdyld.cpp
	llvm-netbsd/patches/patch-unittests_Support_MemoryTest.cpp

Log Message:
llvm-netbsd: Drop local patches for LLVM JIT

This code will be redone again to address upstream comments.

Sponsored by <The NetBSD Foundation>

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

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

diffstat:
 llvm-netbsd/distinfo                               |  10 -
 ...ude_llvm_ExecutionEngine_Orc_IndirectionUtils.h |  48 -----
 ...lvm_ExecutionEngine_Orc_OrcRemoteTargetServer.h |  59 ------
 ...ude_llvm_ExecutionEngine_SectionMemoryManager.h |  13 --
 .../patches/patch-include_llvm_Support_Memory.h    | 129 -------------
 ...patch-lib_ExecutionEngine_Orc_OrcABISupport.cpp |  70 -------
 ...ch-lib_ExecutionEngine_SectionMemoryManager.cpp |  51 -----
 .../patches/patch-lib_Support_Unix_Memory.inc      | 211 ---------------------
 .../patches/patch-lib_Support_Unix_Signals.inc     |  15 --
 .../patch-tools_llvm-rtdyld_llvm-rtdyld.cpp        |  58 ------
 .../patches/patch-unittests_Support_MemoryTest.cpp |  63 ------
 11 files changed, 727 deletions(-)

diffs:
diff --git a/llvm-netbsd/distinfo b/llvm-netbsd/distinfo
index 3ea6c02ab9..7931384fd5 100644
--- a/llvm-netbsd/distinfo
+++ b/llvm-netbsd/distinfo
@@ -12,13 +12,3 @@ Size (libcxx-3.6.2.src.tar.xz) = 944020 bytes
 SHA1 (llvm-3.6.2.src.tar.xz) = 7a00257eb2bc9431e4c77c3a36b033072c54bc7e
 RMD160 (llvm-3.6.2.src.tar.xz) = 521cbc5fe2925ea3c6e90c7a31f752a04045c972
 Size (llvm-3.6.2.src.tar.xz) = 12802380 bytes
-SHA1 (patch-include_llvm_ExecutionEngine_Orc_IndirectionUtils.h) = f106d7e0b95c498c34dc087d72027e19c7342224
-SHA1 (patch-include_llvm_ExecutionEngine_Orc_OrcRemoteTargetServer.h) = 6bec3a8920d3d73363d353c05ce40ff33b0a4193
-SHA1 (patch-include_llvm_ExecutionEngine_SectionMemoryManager.h) = b781ebf238540554b4e10d1616d63497c1e3ef24
-SHA1 (patch-include_llvm_Support_Memory.h) = 9d8e48e3f5054dc1a6a2db6e7f99162e058c7c0e
-SHA1 (patch-lib_ExecutionEngine_Orc_OrcABISupport.cpp) = 3fc562d8e3c3dd7ca28121bf1bd03d1275d3d1c2
-SHA1 (patch-lib_ExecutionEngine_SectionMemoryManager.cpp) = 799faee5f01a87a435da7e745ec552ff6faeacbd
-SHA1 (patch-lib_Support_Unix_Memory.inc) = 2a5f9cc066590e3044d1cf1cfd8f31d144518c0c
-SHA1 (patch-lib_Support_Unix_Signals.inc) = adcc104a0a9917a385a05cb9f19a69d6bbaec31e
-SHA1 (patch-tools_llvm-rtdyld_llvm-rtdyld.cpp) = 98c44df7b016f311e2553a75458175a7d5216279
-SHA1 (patch-unittests_Support_MemoryTest.cpp) = cd7bfc8053ceca839993e70e147cf803bac7eaae
diff --git a/llvm-netbsd/patches/patch-include_llvm_ExecutionEngine_Orc_IndirectionUtils.h b/llvm-netbsd/patches/patch-include_llvm_ExecutionEngine_Orc_IndirectionUtils.h
deleted file mode 100644
index e40820b007..0000000000
--- a/llvm-netbsd/patches/patch-include_llvm_ExecutionEngine_Orc_IndirectionUtils.h
+++ /dev/null
@@ -1,48 +0,0 @@
-$NetBSD$
-
---- include/llvm/ExecutionEngine/Orc/IndirectionUtils.h.orig	2017-07-05 18:41:32.000000000 +0000
-+++ include/llvm/ExecutionEngine/Orc/IndirectionUtils.h
-@@ -165,17 +165,14 @@ public:
-       : JITCompileCallbackManager(ErrorHandlerAddress) {
-     /// Set up the resolver block.
-     std::error_code EC;
--    ResolverBlock = sys::OwningMemoryBlock(sys::Memory::allocateMappedMemory(
--        TargetT::ResolverCodeSize, nullptr,
--        sys::Memory::MF_READ | sys::Memory::MF_WRITE, EC));
-+    ResolverBlock = sys::OwningMemoryBlock(sys::Memory::AllocateJIT(
-+        TargetT::ResolverCodeSize, nullptr, EC));
-     assert(!EC && "Failed to allocate resolver block");
- 
-     TargetT::writeResolverCode(static_cast<uint8_t *>(ResolverBlock.base()),
-                                &reenter, this);
- 
--    EC = sys::Memory::protectMappedMemory(ResolverBlock.getMemoryBlock(),
--                                          sys::Memory::MF_READ |
--                                              sys::Memory::MF_EXEC);
-+    EC = sys::Memory::setExecutable(ResolverBlock.getMemoryBlock());
-     assert(!EC && "Failed to mprotect resolver block");
-   }
- 
-@@ -193,9 +190,8 @@ private:
- 
-     std::error_code EC;
-     auto TrampolineBlock =
--        sys::OwningMemoryBlock(sys::Memory::allocateMappedMemory(
--            sys::Process::getPageSize(), nullptr,
--            sys::Memory::MF_READ | sys::Memory::MF_WRITE, EC));
-+        sys::OwningMemoryBlock(sys::Memory::AllocateJIT(
-+            sys::Process::getPageSize(), nullptr, EC));
-     assert(!EC && "Failed to allocate trampoline block");
- 
-     unsigned NumTrampolines =
-@@ -211,9 +207,7 @@ private:
-           static_cast<JITTargetAddress>(reinterpret_cast<uintptr_t>(
-               TrampolineMem + (I * TargetT::TrampolineSize))));
- 
--    EC = sys::Memory::protectMappedMemory(TrampolineBlock.getMemoryBlock(),
--                                          sys::Memory::MF_READ |
--                                              sys::Memory::MF_EXEC);
-+    EC = sys::Memory::setExecutable(TrampolineBlock.getMemoryBlock());
-     assert(!EC && "Failed to mprotect trampoline block");
- 
-     TrampolineBlocks.push_back(std::move(TrampolineBlock));
diff --git a/llvm-netbsd/patches/patch-include_llvm_ExecutionEngine_Orc_OrcRemoteTargetServer.h b/llvm-netbsd/patches/patch-include_llvm_ExecutionEngine_Orc_OrcRemoteTargetServer.h
deleted file mode 100644
index 9f83381164..0000000000
--- a/llvm-netbsd/patches/patch-include_llvm_ExecutionEngine_Orc_OrcRemoteTargetServer.h
+++ /dev/null
@@ -1,59 +0,0 @@
-$NetBSD$
-
---- include/llvm/ExecutionEngine/Orc/OrcRemoteTargetServer.h.orig	2017-07-05 18:41:32.000000000 +0000
-+++ include/llvm/ExecutionEngine/Orc/OrcRemoteTargetServer.h
-@@ -116,8 +116,8 @@ private:
- 
-     Error allocate(void *&Addr, size_t Size, uint32_t Align) {
-       std::error_code EC;
--      sys::MemoryBlock MB = sys::Memory::allocateMappedMemory(
--          Size, nullptr, sys::Memory::MF_READ | sys::Memory::MF_WRITE, EC);
-+      sys::MemoryBlock MB = sys::Memory::AllocateJIT(
-+          Size, nullptr, EC);
-       if (EC)
-         return errorCodeToError(EC);
- 
-@@ -278,26 +278,23 @@ private:
- 
-   Error handleEmitResolverBlock() {
-     std::error_code EC;
--    ResolverBlock = sys::OwningMemoryBlock(sys::Memory::allocateMappedMemory(
--        TargetT::ResolverCodeSize, nullptr,
--        sys::Memory::MF_READ | sys::Memory::MF_WRITE, EC));
-+    ResolverBlock = sys::OwningMemoryBlock(sys::Memory::AllocateJIT(
-+        TargetT::ResolverCodeSize, nullptr, EC));
-     if (EC)
-       return errorCodeToError(EC);
- 
-     TargetT::writeResolverCode(static_cast<uint8_t *>(ResolverBlock.base()),
-                                &reenter, this);
- 
--    return errorCodeToError(sys::Memory::protectMappedMemory(
--        ResolverBlock.getMemoryBlock(),
--        sys::Memory::MF_READ | sys::Memory::MF_EXEC));
-+    return errorCodeToError(sys::Memory::setExecutable(
-+        ResolverBlock.getMemoryBlock()));
-   }
- 
-   Expected<std::tuple<JITTargetAddress, uint32_t>> handleEmitTrampolineBlock() {
-     std::error_code EC;
-     auto TrampolineBlock =
--        sys::OwningMemoryBlock(sys::Memory::allocateMappedMemory(
--            sys::Process::getPageSize(), nullptr,
--            sys::Memory::MF_READ | sys::Memory::MF_WRITE, EC));
-+        sys::OwningMemoryBlock(sys::Memory::AllocateJIT(
-+            sys::Process::getPageSize(), nullptr, EC));
-     if (EC)
-       return errorCodeToError(EC);
- 
-@@ -309,9 +306,7 @@ private:
-     TargetT::writeTrampolines(TrampolineMem, ResolverBlock.base(),
-                               NumTrampolines);
- 
--    EC = sys::Memory::protectMappedMemory(TrampolineBlock.getMemoryBlock(),
--                                          sys::Memory::MF_READ |
--                                              sys::Memory::MF_EXEC);
-+    EC = sys::Memory::setExecutable(TrampolineBlock.getMemoryBlock());
- 
-     TrampolineBlocks.push_back(std::move(TrampolineBlock));
- 
diff --git a/llvm-netbsd/patches/patch-include_llvm_ExecutionEngine_SectionMemoryManager.h b/llvm-netbsd/patches/patch-include_llvm_ExecutionEngine_SectionMemoryManager.h
deleted file mode 100644
index 28f8be9074..0000000000
--- a/llvm-netbsd/patches/patch-include_llvm_ExecutionEngine_SectionMemoryManager.h
+++ /dev/null
@@ -1,13 +0,0 @@
-$NetBSD$
-
---- include/llvm/ExecutionEngine/SectionMemoryManager.h.orig	2017-07-05 18:41:32.000000000 +0000
-+++ include/llvm/ExecutionEngine/SectionMemoryManager.h
-@@ -114,7 +114,7 @@ private:
-                            unsigned Alignment);
- 
-   std::error_code applyMemoryGroupPermissions(MemoryGroup &MemGroup,
--                                              unsigned Permissions);
-+                                              std::error_code (*fn)(const llvm::sys::MemoryBlock &));
- 
-   MemoryGroup CodeMem;
-   MemoryGroup RWDataMem;
diff --git a/llvm-netbsd/patches/patch-include_llvm_Support_Memory.h b/llvm-netbsd/patches/patch-include_llvm_Support_Memory.h
deleted file mode 100644
index fb08b8d4fb..0000000000
--- a/llvm-netbsd/patches/patch-include_llvm_Support_Memory.h
+++ /dev/null
@@ -1,129 +0,0 @@
-$NetBSD$
-
---- include/llvm/Support/Memory.h.orig	2017-07-05 18:41:26.000000000 +0000
-+++ include/llvm/Support/Memory.h
-@@ -36,6 +36,7 @@ namespace sys {
-   private:
-     void *Address;    ///< Address of first byte of memory area
-     size_t Size;      ///< Size, in bytes of the memory area
-+    int MaxProtection;///< Maximum allowable Protection, of memory area
-     friend class Memory;
-   };
- 
-@@ -61,16 +62,20 @@ namespace sys {
-     /// \p Flags is used to set the initial protection flags for the block
-     /// of the memory.
-     /// \p EC [out] returns an object describing any error that occurs.
-+    /// \p MaxFlags is used to set the maximal protection flags for the block
-+    /// of the memory. This value is OR'ed with \p Flags.
-     ///
-     /// This method may allocate more than the number of bytes requested.  The
-     /// actual number of bytes allocated is indicated in the returned
-     /// MemoryBlock.
-     ///
-     /// The start of the allocated block must be aligned with the
--    /// system allocation granularity (64K on Windows, page size on Linux).
-+    /// system allocation granularity (64K on Windows, page size on Linux, etc).
-     /// If the address following \p NearBlock is not so aligned, it will be
-     /// rounded up to the next allocation granularity boundary.
-     ///
-+    /// For security reasons MF_WRITE | MF_EXEC mapping is prohibited.
-+    ///
-     /// \r a non-null MemoryBlock if the function was successful,
-     /// otherwise a null MemoryBlock is with \p EC describing the error.
-     ///
-@@ -78,7 +83,7 @@ namespace sys {
-     static MemoryBlock allocateMappedMemory(size_t NumBytes,
-                                             const MemoryBlock *const NearBlock,
-                                             unsigned Flags,
--                                            std::error_code &EC);
-+                                            std::error_code &EC, unsigned MaxFlags = 0);
- 
-     /// This method releases a block of memory that was allocated with the
-     /// allocateMappedMemory method. It should not be used to release any
-@@ -102,6 +107,11 @@ namespace sys {
-     /// with the operating system (i.e. MF_READ | MF_WRITE on Windows) and the
-     /// target architecture (i.e. MF_WRITE -> MF_READ | MF_WRITE on i386).
-     ///
-+    /// The specified \p Flags parameter must by allowed by maximal protection
-+    /// block of the memory.
-+    ///
-+    /// For security reasons MF_WRITE | MF_EXEC mapping is prohibited.
-+    ///
-     /// \r error_success if the function was successful, or an error_code
-     /// describing the failure if an error occurred.
-     ///
-@@ -109,51 +119,42 @@ namespace sys {
-     static std::error_code protectMappedMemory(const MemoryBlock &Block,
-                                                unsigned Flags);
- 
--    /// This method allocates a block of Read/Write/Execute memory that is
-+    /// This method allocates a block of memory that is
-     /// suitable for executing dynamically generated code (e.g. JIT). An
-     /// attempt to allocate \p NumBytes bytes of virtual memory is made.
-     /// \p NearBlock may point to an existing allocation in which case
-     /// an attempt is made to allocate more memory near the existing block.
-     ///
--    /// On success, this returns a non-null memory block, otherwise it returns
--    /// a null memory block and fills in *ErrMsg.
-+    /// The reserved memory block is Writable (MF_READ | MF_WRITE). In
-+    /// order to toggle it between writable and executable, one has to use
-+    /// setWritable and setExecutable methods.
-     ///
--    /// @brief Allocate Read/Write/Execute memory.
--    static MemoryBlock AllocateRWX(size_t NumBytes,
-+    /// This function is a utility wrapper for allocateMappedMemory.
-+    ///
-+    /// \r a non-null MemoryBlock if the function was successful,
-+    /// otherwise a null MemoryBlock is with \p EC describing the error.
-+    ///
-+    /// @brief Allocate mapped memory suitable for JIT code.
-+    static MemoryBlock AllocateJIT(size_t NumBytes,
-                                    const MemoryBlock *NearBlock,
--                                   std::string *ErrMsg = nullptr);
--
--    /// This method releases a block of Read/Write/Execute memory that was
--    /// allocated with the AllocateRWX method. It should not be used to
--    /// release any memory block allocated any other way.
--    ///
--    /// On success, this returns false, otherwise it returns true and fills
--    /// in *ErrMsg.
--    /// @brief Release Read/Write/Execute memory.
--    static bool ReleaseRWX(MemoryBlock &block, std::string *ErrMsg = nullptr);
-+                                   std::error_code &EC);
- 
-     /// InvalidateInstructionCache - Before the JIT can run a block of code
-     /// that has been emitted it must invalidate the instruction cache on some
-     /// platforms.
-     static void InvalidateInstructionCache(const void *Addr, size_t Len);
- 
-+    /// setReadable - Before the JIT can write a block of code, it has to be
-+    /// given read and write privilege.
-+    static std::error_code setReadable(const MemoryBlock &M);
-+
-+    /// setWritable - Before the JIT can write a block of code, it has to be
-+    /// given read and write privilege.
-+    static std::error_code setWritable(const MemoryBlock &M);
-+
-     /// setExecutable - Before the JIT can run a block of code, it has to be
--    /// given read and executable privilege. Return true if it is already r-x
--    /// or the system is able to change its previlege.
--    static bool setExecutable(MemoryBlock &M, std::string *ErrMsg = nullptr);
--
--    /// setWritable - When adding to a block of code, the JIT may need
--    /// to mark a block of code as RW since the protections are on page
--    /// boundaries, and the JIT internal allocations are not page aligned.
--    static bool setWritable(MemoryBlock &M, std::string *ErrMsg = nullptr);
--
--    /// setRangeExecutable - Mark the page containing a range of addresses
--    /// as executable.
--    static bool setRangeExecutable(const void *Addr, size_t Size);
--
--    /// setRangeWritable - Mark the page containing a range of addresses
--    /// as writable.
--    static bool setRangeWritable(const void *Addr, size_t Size);
-+    /// given read and executable privilege.
-+    static std::error_code setExecutable(const MemoryBlock &M);
-   };
- 
-   /// Owning version of MemoryBlock.
diff --git a/llvm-netbsd/patches/patch-lib_ExecutionEngine_Orc_OrcABISupport.cpp b/llvm-netbsd/patches/patch-lib_ExecutionEngine_Orc_OrcABISupport.cpp
deleted file mode 100644
index 0a71fe416f..0000000000
--- a/llvm-netbsd/patches/patch-lib_ExecutionEngine_Orc_OrcABISupport.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-$NetBSD$
-
---- lib/ExecutionEngine/Orc/OrcABISupport.cpp.orig	2017-07-05 18:38:00.000000000 +0000
-+++ lib/ExecutionEngine/Orc/OrcABISupport.cpp
-@@ -155,9 +155,8 @@ Error OrcAArch64::emitIndirectStubsBlock
- 
-   // Allocate memory for stubs and pointers in one call.
-   std::error_code EC;
--  auto StubsMem = sys::OwningMemoryBlock(sys::Memory::allocateMappedMemory(
--      2 * NumPages * PageSize, nullptr,
--      sys::Memory::MF_READ | sys::Memory::MF_WRITE, EC));
-+  auto StubsMem = sys::OwningMemoryBlock(sys::Memory::AllocateJIT(
-+      2 * NumPages * PageSize, nullptr, EC));
- 
-   if (EC)
-     return errorCodeToError(EC);
-@@ -176,8 +175,7 @@ Error OrcAArch64::emitIndirectStubsBlock
-   for (unsigned I = 0; I < NumStubs; ++I)
-     Stub[I] = 0xd61f020058000010 | PtrOffsetField;
- 
--  if (auto EC = sys::Memory::protectMappedMemory(
--          StubsBlock, sys::Memory::MF_READ | sys::Memory::MF_EXEC))
-+  if (auto EC = sys::Memory::setExecutable(StubsBlock))
-     return errorCodeToError(EC);
- 
-   // Initialize all pointers to point at FailureAddress.
-@@ -237,9 +235,8 @@ Error OrcX86_64_Base::emitIndirectStubsB
- 
-   // Allocate memory for stubs and pointers in one call.
-   std::error_code EC;
--  auto StubsMem = sys::OwningMemoryBlock(sys::Memory::allocateMappedMemory(
--      2 * NumPages * PageSize, nullptr,
--      sys::Memory::MF_READ | sys::Memory::MF_WRITE, EC));
-+  auto StubsMem = sys::OwningMemoryBlock(sys::Memory::AllocateJIT(
-+      2 * NumPages * PageSize, nullptr, EC));
- 
-   if (EC)
-     return errorCodeToError(EC);
-@@ -257,8 +254,7 @@ Error OrcX86_64_Base::emitIndirectStubsB
-   for (unsigned I = 0; I < NumStubs; ++I)
-     Stub[I] = 0xF1C40000000025ff | PtrOffsetField;
- 
--  if (auto EC = sys::Memory::protectMappedMemory(
--          StubsBlock, sys::Memory::MF_READ | sys::Memory::MF_EXEC))
-+  if (auto EC = sys::Memory::setExecutable(StubsBlock))
-     return errorCodeToError(EC);
- 
-   // Initialize all pointers to point at FailureAddress.
-@@ -505,9 +501,8 @@ Error OrcI386::emitIndirectStubsBlock(In
- 
-   // Allocate memory for stubs and pointers in one call.
-   std::error_code EC;
--  auto StubsMem = sys::OwningMemoryBlock(sys::Memory::allocateMappedMemory(
--      2 * NumPages * PageSize, nullptr,
--      sys::Memory::MF_READ | sys::Memory::MF_WRITE, EC));
-+  auto StubsMem = sys::OwningMemoryBlock(sys::Memory::AllocateJIT(
-+      2 * NumPages * PageSize, nullptr, EC));
- 
-   if (EC)
-     return errorCodeToError(EC);
-@@ -524,8 +519,7 @@ Error OrcI386::emitIndirectStubsBlock(In
-   for (unsigned I = 0; I < NumStubs; ++I, PtrAddr += 4)
-     Stub[I] = 0xF1C40000000025ff | (PtrAddr << 16);
- 
--  if (auto EC = sys::Memory::protectMappedMemory(
--          StubsBlock, sys::Memory::MF_READ | sys::Memory::MF_EXEC))
-+  if (auto EC = sys::Memory::setExecutable(StubsBlock))
-     return errorCodeToError(EC);
- 
-   // Initialize all pointers to point at FailureAddress.
diff --git a/llvm-netbsd/patches/patch-lib_ExecutionEngine_SectionMemoryManager.cpp b/llvm-netbsd/patches/patch-lib_ExecutionEngine_SectionMemoryManager.cpp
deleted file mode 100644
index 8f13254066..0000000000
--- a/llvm-netbsd/patches/patch-lib_ExecutionEngine_SectionMemoryManager.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-$NetBSD$
-
---- lib/ExecutionEngine/SectionMemoryManager.cpp.orig	2017-07-05 18:38:00.000000000 +0000
-+++ lib/ExecutionEngine/SectionMemoryManager.cpp
-@@ -84,11 +84,9 @@ uint8_t *SectionMemoryManager::allocateS
-   // FIXME: Initialize the Near member for each memory group to avoid
-   // interleaving.
-   std::error_code ec;
--  sys::MemoryBlock MB = sys::Memory::allocateMappedMemory(RequiredSize,
--                                                          &MemGroup.Near,
--                                                          sys::Memory::MF_READ |
--                                                            sys::Memory::MF_WRITE,
--                                                          ec);
-+  sys::MemoryBlock MB = sys::Memory::AllocateJIT(RequiredSize,
-+                                                 &MemGroup.Near,
-+                                                 ec);
-   if (ec) {
-     // FIXME: Add error propagation to the interface.
-     return nullptr;
-@@ -128,8 +126,7 @@ bool SectionMemoryManager::finalizeMemor
-   std::error_code ec;
- 
-   // Make code memory executable.
--  ec = applyMemoryGroupPermissions(CodeMem,
--                                   sys::Memory::MF_READ | sys::Memory::MF_EXEC);
-+  ec = applyMemoryGroupPermissions(CodeMem, sys::Memory::setExecutable);
-   if (ec) {
-     if (ErrMsg) {
-       *ErrMsg = ec.message();
-@@ -138,8 +135,7 @@ bool SectionMemoryManager::finalizeMemor
-   }
- 
-   // Make read-only data memory read-only.
--  ec = applyMemoryGroupPermissions(RODataMem,
--                                   sys::Memory::MF_READ | sys::Memory::MF_EXEC);
-+  ec = applyMemoryGroupPermissions(RODataMem, sys::Memory::setReadable);
-   if (ec) {
-     if (ErrMsg) {
-       *ErrMsg = ec.message();
-@@ -179,9 +175,9 @@ static sys::MemoryBlock trimBlockToPageS
- 
- std::error_code
- SectionMemoryManager::applyMemoryGroupPermissions(MemoryGroup &MemGroup,
--                                                  unsigned Permissions) {
-+                                                  std::error_code (*fn)(const llvm::sys::MemoryBlock &)) {
-   for (sys::MemoryBlock &MB : MemGroup.PendingMem)
--    if (std::error_code EC = sys::Memory::protectMappedMemory(MB, Permissions))
-+    if (std::error_code EC = fn(MB))
-       return EC;
- 
-   MemGroup.PendingMem.clear();
diff --git a/llvm-netbsd/patches/patch-lib_Support_Unix_Memory.inc b/llvm-netbsd/patches/patch-lib_Support_Unix_Memory.inc
deleted file mode 100644
index 5656e80243..0000000000
--- a/llvm-netbsd/patches/patch-lib_Support_Unix_Memory.inc
+++ /dev/null
@@ -1,211 +0,0 @@
-$NetBSD$
-
---- lib/Support/Unix/Memory.inc.orig	2017-07-05 18:38:14.000000000 +0000
-+++ lib/Support/Unix/Memory.inc
-@@ -82,8 +82,16 @@ MemoryBlock
- Memory::allocateMappedMemory(size_t NumBytes,
-                              const MemoryBlock *const NearBlock,
-                              unsigned PFlags,
--                             std::error_code &EC) {
-+                             std::error_code &EC,
-+                             unsigned MaxPFlags) {
-   EC = std::error_code();
-+
-+  // W^X restriction
-+  if ((PFlags & (MF_WRITE | MF_EXEC)) == (MF_WRITE | MF_EXEC)) {
-+    EC = std::error_code(EACCES, std::generic_category());
-+    return MemoryBlock();
-+  }
-+
-   if (NumBytes == 0)
-     return MemoryBlock();
- 
-@@ -102,6 +110,13 @@ Memory::allocateMappedMemory(size_t NumB
- 
-   int Protect = getPosixProtectionFlags(PFlags);
- 
-+  MaxPFlags |= PFlags;
-+
-+  // NetBSD with PaX MPROTECT must reserve additional allowable protection bits
-+#if defined(__NetBSD__) && defined(PROT_MPROTECT)
-+  Protect |= PROT_MPROTECT(getPosixProtectionFlags(MaxPFlags & (~PFlags)));
-+#endif
-+
-   // Use any near hint and the page size to set a page-aligned starting address
-   uintptr_t Start = NearBlock ? reinterpret_cast<uintptr_t>(NearBlock->base()) +
-                                       NearBlock->size() : 0;
-@@ -112,7 +127,7 @@ Memory::allocateMappedMemory(size_t NumB
-                       Protect, MMFlags, fd, 0);
-   if (Addr == MAP_FAILED) {
-     if (NearBlock) //Try again without a near hint
--      return allocateMappedMemory(NumBytes, nullptr, PFlags, EC);
-+      return allocateMappedMemory(NumBytes, nullptr, PFlags, EC, MaxPFlags);
- 
-     EC = std::error_code(errno, std::generic_category());
-     return MemoryBlock();
-@@ -121,6 +136,7 @@ Memory::allocateMappedMemory(size_t NumB
-   MemoryBlock Result;
-   Result.Address = Addr;
-   Result.Size = NumPages*PageSize;
-+  Result.MaxProtection = MaxPFlags;
- 
-   if (PFlags & MF_EXEC)
-     Memory::InvalidateInstructionCache(Result.Address, Result.Size);
-@@ -144,6 +160,14 @@ Memory::releaseMappedMemory(MemoryBlock 
- 
- std::error_code
- Memory::protectMappedMemory(const MemoryBlock &M, unsigned Flags) {
-+  // W^X restriction
-+  if ((Flags & (MF_WRITE | MF_EXEC)) == (MF_WRITE | MF_EXEC))
-+    return std::error_code(EACCES, std::generic_category());
-+
-+  // Check whether new protection bits are allowed
-+  if ((~M.MaxProtection) & Flags)
-+    return std::error_code(EACCES, std::generic_category());
-+
-   static const size_t PageSize = Process::getPageSize();
-   if (M.Address == nullptr || M.Size == 0)
-     return std::error_code();
-@@ -166,128 +190,29 @@ Memory::protectMappedMemory(const Memory
-   return std::error_code();
- }
- 
--/// AllocateRWX - Allocate a slab of memory with read/write/execute
--/// permissions.  This is typically used for JIT applications where we want
--/// to emit code to the memory then jump to it.  Getting this type of memory
--/// is very OS specific.
--///
- MemoryBlock
--Memory::AllocateRWX(size_t NumBytes, const MemoryBlock* NearBlock,
--                    std::string *ErrMsg) {
--  if (NumBytes == 0) return MemoryBlock();
--
--  static const size_t PageSize = Process::getPageSize();
--  size_t NumPages = (NumBytes+PageSize-1)/PageSize;
--
--  int fd = -1;
--
--  int flags = MAP_PRIVATE |
--#ifdef MAP_ANONYMOUS
--  MAP_ANONYMOUS
--#else
--  MAP_ANON
--#endif
--  ;
--
--  void* start = NearBlock ? (unsigned char*)NearBlock->base() +
--                            NearBlock->size() : nullptr;
--
--#if defined(__APPLE__) && (defined(__arm__) || defined(__arm64__))
--  void *pa = ::mmap(start, PageSize*NumPages, PROT_READ|PROT_EXEC,
--                    flags, fd, 0);
--#elif defined(__NetBSD__) && defined(PROT_MPROTECT)
--  void *pa =
--      ::mmap(start, PageSize * NumPages,
--             PROT_READ | PROT_WRITE | PROT_MPROTECT(PROT_EXEC), flags, fd, 0);
--#else
--  void *pa = ::mmap(start, PageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC,
--                    flags, fd, 0);
--#endif
--  if (pa == MAP_FAILED) {
--    if (NearBlock) //Try again without a near hint
--      return AllocateRWX(NumBytes, nullptr);
--
--    MakeErrMsg(ErrMsg, "Can't allocate RWX Memory");
--    return MemoryBlock();
--  }
--
--#if defined(__APPLE__) && (defined(__arm__) || defined(__arm64__))
--  kern_return_t kr = vm_protect(mach_task_self(), (vm_address_t)pa,
--                                (vm_size_t)(PageSize*NumPages), 0,
--                                VM_PROT_READ | VM_PROT_EXECUTE | VM_PROT_COPY);
--  if (KERN_SUCCESS != kr) {
--    MakeErrMsg(ErrMsg, "vm_protect max RX failed");
--    return MemoryBlock();
--  }
--
--  kr = vm_protect(mach_task_self(), (vm_address_t)pa,
--                  (vm_size_t)(PageSize*NumPages), 0,
--                  VM_PROT_READ | VM_PROT_WRITE);
--  if (KERN_SUCCESS != kr) {
--    MakeErrMsg(ErrMsg, "vm_protect RW failed");
--    return MemoryBlock();
--  }
--#endif
--
--  MemoryBlock result;
--  result.Address = pa;
--  result.Size = NumPages*PageSize;
--
--  return result;
--}
--
--bool Memory::ReleaseRWX(MemoryBlock &M, std::string *ErrMsg) {
--  if (M.Address == nullptr || M.Size == 0) return false;
--  if (0 != ::munmap(M.Address, M.Size))
--    return MakeErrMsg(ErrMsg, "Can't release RWX Memory");
--  return false;
-+Memory::AllocateJIT(size_t NumBytes, const MemoryBlock* NearBlock,
-+                    std::error_code &EC) {
-+  return allocateMappedMemory(NumBytes, NearBlock, MF_READ | MF_WRITE, EC, MF_EXEC);
- }
- 
--bool Memory::setWritable (MemoryBlock &M, std::string *ErrMsg) {
--#if defined(__APPLE__) && (defined(__arm__) || defined(__arm64__))
--  if (M.Address == 0 || M.Size == 0) return false;
--  Memory::InvalidateInstructionCache(M.Address, M.Size);
--  kern_return_t kr = vm_protect(mach_task_self(), (vm_address_t)M.Address,
--    (vm_size_t)M.Size, 0, VM_PROT_READ | VM_PROT_WRITE);
--  return KERN_SUCCESS == kr;
--#else
--  return true;
--#endif
-+std::error_code
-+Memory::setReadable (const MemoryBlock &M) {
-+  return protectMappedMemory(M, MF_READ);
- }
- 
--bool Memory::setExecutable (MemoryBlock &M, std::string *ErrMsg) {
--  if (M.Address == nullptr || M.Size == 0) return false;
--  Memory::InvalidateInstructionCache(M.Address, M.Size);
--#if defined(__APPLE__) && (defined(__arm__) || defined(__arm64__))
--  kern_return_t kr = vm_protect(mach_task_self(), (vm_address_t)M.Address,
--    (vm_size_t)M.Size, 0, VM_PROT_READ | VM_PROT_EXECUTE | VM_PROT_COPY);
--  return KERN_SUCCESS == kr;
--#else
--  return true;
--#endif
-+std::error_code
-+Memory::setWritable (const MemoryBlock &M) {
-+  return protectMappedMemory(M, MF_READ | MF_WRITE);
- }
- 
--bool Memory::setRangeWritable(const void *Addr, size_t Size) {
--#if defined(__APPLE__) && (defined(__arm__) || defined(__arm64__))
--  kern_return_t kr = vm_protect(mach_task_self(), (vm_address_t)Addr,
--                                (vm_size_t)Size, 0,
--                                VM_PROT_READ | VM_PROT_WRITE);
--  return KERN_SUCCESS == kr;
--#else
--  return true;
--#endif
-+std::error_code
-+Memory::setExecutable (const MemoryBlock &M) {
-+  if (M.Address != nullptr && M.Size != 0)
-+    Memory::InvalidateInstructionCache(M.Address, M.Size);
-+  return protectMappedMemory(M, MF_READ | MF_EXEC);
- }
- 
--bool Memory::setRangeExecutable(const void *Addr, size_t Size) {
--#if defined(__APPLE__) && (defined(__arm__) || defined(__arm64__))
--  kern_return_t kr = vm_protect(mach_task_self(), (vm_address_t)Addr,
--                                (vm_size_t)Size, 0,
--                                VM_PROT_READ | VM_PROT_EXECUTE | VM_PROT_COPY);
--  return KERN_SUCCESS == kr;
--#else
--  return true;
--#endif
--}
- 
- /// InvalidateInstructionCache - Before the JIT can run a block of code
- /// that has been emitted it must invalidate the instruction cache on some
diff --git a/llvm-netbsd/patches/patch-lib_Support_Unix_Signals.inc b/llvm-netbsd/patches/patch-lib_Support_Unix_Signals.inc
deleted file mode 100644
index f3a51a410f..0000000000
--- a/llvm-netbsd/patches/patch-lib_Support_Unix_Signals.inc
+++ /dev/null
@@ -1,15 +0,0 @@
-$NetBSD$
-
---- lib/Support/Unix/Signals.inc.orig	2017-07-05 18:38:14.000000000 +0000
-+++ lib/Support/Unix/Signals.inc
-@@ -158,8 +158,8 @@ static void RegisterHandlers() {
-   // be able to reliably handle signals due to stack overflow.
-   CreateSigAltStack();
- 
--  for (auto S : IntSigs) RegisterHandler(S);
--  for (auto S : KillSigs) RegisterHandler(S);
-+//  for (auto S : IntSigs) RegisterHandler(S);
-+//  for (auto S : KillSigs) RegisterHandler(S);
- }
- 
- static void UnregisterHandlers() {
diff --git a/llvm-netbsd/patches/patch-tools_llvm-rtdyld_llvm-rtdyld.cpp b/llvm-netbsd/patches/patch-tools_llvm-rtdyld_llvm-rtdyld.cpp
deleted file mode 100644
index 750bb72330..0000000000
--- a/llvm-netbsd/patches/patch-tools_llvm-rtdyld_llvm-rtdyld.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-$NetBSD$
-
---- tools/llvm-rtdyld/llvm-rtdyld.cpp.orig	2017-07-20 19:13:57.000000000 +0000
-+++ tools/llvm-rtdyld/llvm-rtdyld.cpp
-@@ -178,10 +178,10 @@ public:
-   void deregisterEHFrames() override {}
- 
-   void preallocateSlab(uint64_t Size) {
--    std::string Err;
--    sys::MemoryBlock MB = sys::Memory::AllocateRWX(Size, nullptr, &Err);
-+    std::error_code EC;
-+    sys::MemoryBlock MB = sys::Memory::AllocateJIT(Size, nullptr, EC);
-     if (!MB.base())
--      report_fatal_error("Can't allocate enough memory: " + Err);
-+      report_fatal_error("Can't allocate enough memory");
- 
-     PreallocSlab = MB;
-     UsePreallocation = true;
-@@ -222,10 +222,10 @@ uint8_t *TrivialMemoryManager::allocateC
-   if (UsePreallocation)
-     return allocateFromSlab(Size, Alignment, true /* isCode */);
- 
--  std::string Err;
--  sys::MemoryBlock MB = sys::Memory::AllocateRWX(Size, nullptr, &Err);
-+  std::error_code EC;
-+  sys::MemoryBlock MB = sys::Memory::AllocateJIT(Size, nullptr, EC);
-   if (!MB.base())
--    report_fatal_error("MemoryManager allocation failed: " + Err);
-+    report_fatal_error("MemoryManager allocation failed");
-   FunctionMemory.push_back(MB);
-   return (uint8_t*)MB.base();
- }
-@@ -242,10 +242,10 @@ uint8_t *TrivialMemoryManager::allocateD
-   if (UsePreallocation)
-     return allocateFromSlab(Size, Alignment, false /* isCode */);
- 
--  std::string Err;
--  sys::MemoryBlock MB = sys::Memory::AllocateRWX(Size, nullptr, &Err);
-+  std::error_code EC;
-+  sys::MemoryBlock MB = sys::Memory::AllocateJIT(Size, nullptr, EC);
-   if (!MB.base())
--    report_fatal_error("MemoryManager allocation failed: " + Err);
-+    report_fatal_error("MemoryManager allocation failed");
-   DataMemory.push_back(MB);
-   return (uint8_t*)MB.base();
- }
-@@ -453,9 +453,8 @@ static int executeInput() {
- 
-     // Make sure the memory is executable.
-     // setExecutable will call InvalidateInstructionCache.
--    std::string ErrorStr;
--    if (!sys::Memory::setExecutable(FM, &ErrorStr))
--      ErrorAndExit("unable to mark function executable: '" + ErrorStr + "'");
-+    if (sys::Memory::setExecutable(FM))
-+      ErrorAndExit("unable to mark function executable");
-   }
- 
-   // Dispatch to _main().
diff --git a/llvm-netbsd/patches/patch-unittests_Support_MemoryTest.cpp b/llvm-netbsd/patches/patch-unittests_Support_MemoryTest.cpp
deleted file mode 100644
index c7ce025a70..0000000000
--- a/llvm-netbsd/patches/patch-unittests_Support_MemoryTest.cpp
+++ /dev/null
@@ -1,63 +0,0 @@
-$NetBSD$
-
---- unittests/Support/MemoryTest.cpp.orig	2017-07-05 18:41:47.000000000 +0000
-+++ unittests/Support/MemoryTest.cpp
-@@ -33,9 +33,8 @@ protected:
-     case Memory::MF_READ|Memory::MF_WRITE:
-       return Memory::MF_READ|Memory::MF_WRITE;
-     case Memory::MF_READ|Memory::MF_EXEC:
--    case Memory::MF_READ|Memory::MF_WRITE|Memory::MF_EXEC:
-     case Memory::MF_EXEC:
--      return Memory::MF_READ|Memory::MF_WRITE|Memory::MF_EXEC;
-+      return Memory::MF_READ|Memory::MF_EXEC;
-     }
-     // Default in case values are added to the enum, as required by some compilers
-     return Memory::MF_READ|Memory::MF_WRITE;
-@@ -181,14 +180,19 @@ TEST_P(MappedMemoryTest, MultipleWrite) 
- 
- TEST_P(MappedMemoryTest, EnabledWrite) {
-   std::error_code EC;
-+
-+  // W^R restriction
-+  if (Flags & Memory::MF_EXEC)
-+    return;
-+
-   MemoryBlock M1 = Memory::allocateMappedMemory(2 * sizeof(int), nullptr, Flags,
--                                                EC);
-+                                                EC, getTestableEquivalent(Flags));
-   EXPECT_EQ(std::error_code(), EC);
-   MemoryBlock M2 = Memory::allocateMappedMemory(8 * sizeof(int), nullptr, Flags,
--                                                EC);
-+                                                EC, getTestableEquivalent(Flags));
-   EXPECT_EQ(std::error_code(), EC);
-   MemoryBlock M3 = Memory::allocateMappedMemory(4 * sizeof(int), nullptr, Flags,
--                                                EC);
-+                                                EC, getTestableEquivalent(Flags));
-   EXPECT_EQ(std::error_code(), EC);
- 
-   EXPECT_NE((void*)nullptr, M1.base());
-@@ -223,7 +227,7 @@ TEST_P(MappedMemoryTest, EnabledWrite) {
-   EXPECT_FALSE(Memory::releaseMappedMemory(M3));
-   EXPECT_EQ(6, y[6]);
- 
--  MemoryBlock M4 = Memory::allocateMappedMemory(16, nullptr, Flags, EC);
-+  MemoryBlock M4 = Memory::allocateMappedMemory(16, nullptr, Flags, EC, getTestableEquivalent(Flags));
-   EXPECT_EQ(std::error_code(), EC);
-   EXPECT_NE((void*)nullptr, M4.base());
-   EXPECT_LE(16U, M4.size());
-@@ -349,13 +353,13 @@ TEST_P(MappedMemoryTest, UnalignedNear) 
- 
- // Note that Memory::MF_WRITE is not supported exclusively across
- // operating systems and architectures and can imply MF_READ|MF_WRITE
-+// RWX mapping is not allowed (W^X restrictions)
- unsigned MemoryFlags[] = {
- 			   Memory::MF_READ,
- 			   Memory::MF_WRITE,
- 			   Memory::MF_READ|Memory::MF_WRITE,
- 			   Memory::MF_EXEC,
--			   Memory::MF_READ|Memory::MF_EXEC,
--			   Memory::MF_READ|Memory::MF_WRITE|Memory::MF_EXEC
-+			   Memory::MF_READ|Memory::MF_EXEC
- 			 };
- 
- INSTANTIATE_TEST_CASE_P(AllocationTests,


Home | Main Index | Thread Index | Old Index