pkgsrc-WIP-changes archive

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

llvm-netbsd: Use JIT MPROTECT allocator



Module Name:	pkgsrc-wip
Committed By:	Kamil Rytarowski <n54%gmx.com@localhost>
Pushed By:	kamil
Date:		Mon Jul 17 19:21:35 2017 +0200
Changeset:	801a80973085d397ea0131da8ccba86df9ae0efa

Modified Files:
	llvm-netbsd/distinfo
Added 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-lib_ExecutionEngine_Orc_OrcABISupport.cpp
	llvm-netbsd/patches/patch-lib_ExecutionEngine_SectionMemoryManager.cpp
	llvm-netbsd/patches/patch-lib_Support_Unix_Signals.inc

Log Message:
llvm-netbsd: Use JIT MPROTECT allocator

Replace Memory::allocateMappedMemory with Memory::AllocateRWX.

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=801a80973085d397ea0131da8ccba86df9ae0efa

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

diffstat:
 llvm-netbsd/distinfo                               |  5 ++
 ...ude_llvm_ExecutionEngine_Orc_IndirectionUtils.h | 52 +++++++++++++++++
 ...lvm_ExecutionEngine_Orc_OrcRemoteTargetServer.h | 66 ++++++++++++++++++++++
 ...patch-lib_ExecutionEngine_Orc_OrcABISupport.cpp | 61 ++++++++++++++++++++
 ...ch-lib_ExecutionEngine_SectionMemoryManager.cpp | 28 +++++++++
 .../patches/patch-lib_Support_Unix_Signals.inc     | 15 +++++
 6 files changed, 227 insertions(+)

diffs:
diff --git a/llvm-netbsd/distinfo b/llvm-netbsd/distinfo
index b743693d4e..e176119211 100644
--- a/llvm-netbsd/distinfo
+++ b/llvm-netbsd/distinfo
@@ -12,6 +12,11 @@ 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) = 0834e9a010f37e7b33ebb1013b87997c3028aed8
+SHA1 (patch-include_llvm_ExecutionEngine_Orc_OrcRemoteTargetServer.h) = bec17a6bfc251d9600ce5d219b6c01b14db8449e
+SHA1 (patch-lib_ExecutionEngine_Orc_OrcABISupport.cpp) = 1a13d52f56d90a97bf5a1ecaeefee64ec4730300
+SHA1 (patch-lib_ExecutionEngine_SectionMemoryManager.cpp) = c534e7930de24c2058363c3888d7c68a40b36ca0
+SHA1 (patch-lib_Support_Unix_Signals.inc) = 7e3fa55c7e32171454a065c6e38d8189ffdfb6ca
 SHA1 (patch-lib_Transforms_Instrumentation_AddressSanitizer.cpp) = 67eee29c4d8525b603e6b7c0a52278bdf3353687
 SHA1 (patch-lib_Transforms_Instrumentation_InstrProfiling.cpp) = 871b474f415d9dc468cc07477101f88d7a20868b
 SHA1 (patch-lib_Transforms_Instrumentation_MemorySanitizer.cpp) = 64fdbb55c77d5f5f73152d2f8daa28adfc428e40
diff --git a/llvm-netbsd/patches/patch-include_llvm_ExecutionEngine_Orc_IndirectionUtils.h b/llvm-netbsd/patches/patch-include_llvm_ExecutionEngine_Orc_IndirectionUtils.h
new file mode 100644
index 0000000000..81adddca1b
--- /dev/null
+++ b/llvm-netbsd/patches/patch-include_llvm_ExecutionEngine_Orc_IndirectionUtils.h
@@ -0,0 +1,52 @@
+$NetBSD$
+
+--- include/llvm/ExecutionEngine/Orc/IndirectionUtils.h.orig	2017-07-05 18:41:32.000000000 +0000
++++ include/llvm/ExecutionEngine/Orc/IndirectionUtils.h
+@@ -164,15 +164,16 @@ public:
+   LocalJITCompileCallbackManager(JITTargetAddress ErrorHandlerAddress)
+       : 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));
+-    assert(!EC && "Failed to allocate resolver block");
++    std::string Err;
++    ResolverBlock = sys::OwningMemoryBlock(sys::Memory::AllocateRWX(
++        TargetT::ResolverCodeSize, nullptr, &Err));
++    if (!ResolverBlock.base())
++      report_fatal_error("Can't allocate enough memory: " + Err);
+ 
+     TargetT::writeResolverCode(static_cast<uint8_t *>(ResolverBlock.base()),
+                                &reenter, this);
+ 
++    std::error_code EC;
+     EC = sys::Memory::protectMappedMemory(ResolverBlock.getMemoryBlock(),
+                                           sys::Memory::MF_READ |
+                                               sys::Memory::MF_EXEC);
+@@ -191,12 +192,12 @@ private:
+   void grow() override {
+     assert(this->AvailableTrampolines.empty() && "Growing prematurely?");
+ 
+-    std::error_code EC;
++    std::string Err;
+     auto TrampolineBlock =
+-        sys::OwningMemoryBlock(sys::Memory::allocateMappedMemory(
+-            sys::Process::getPageSize(), nullptr,
+-            sys::Memory::MF_READ | sys::Memory::MF_WRITE, EC));
+-    assert(!EC && "Failed to allocate trampoline block");
++        sys::OwningMemoryBlock(sys::Memory::AllocateRWX(
++            sys::Process::getPageSize(), nullptr, &Err));
++    if (!TrampolineBlock.base())
++      report_fatal_error("Can't allocate enough memory: " + Err);
+ 
+     unsigned NumTrampolines =
+         (sys::Process::getPageSize() - TargetT::PointerSize) /
+@@ -211,6 +212,7 @@ private:
+           static_cast<JITTargetAddress>(reinterpret_cast<uintptr_t>(
+               TrampolineMem + (I * TargetT::TrampolineSize))));
+ 
++    std::error_code EC;
+     EC = sys::Memory::protectMappedMemory(TrampolineBlock.getMemoryBlock(),
+                                           sys::Memory::MF_READ |
+                                               sys::Memory::MF_EXEC);
diff --git a/llvm-netbsd/patches/patch-include_llvm_ExecutionEngine_Orc_OrcRemoteTargetServer.h b/llvm-netbsd/patches/patch-include_llvm_ExecutionEngine_Orc_OrcRemoteTargetServer.h
new file mode 100644
index 0000000000..380dc91009
--- /dev/null
+++ b/llvm-netbsd/patches/patch-include_llvm_ExecutionEngine_Orc_OrcRemoteTargetServer.h
@@ -0,0 +1,66 @@
+$NetBSD$
+
+--- include/llvm/ExecutionEngine/Orc/OrcRemoteTargetServer.h.orig	2017-07-05 18:41:32.000000000 +0000
++++ include/llvm/ExecutionEngine/Orc/OrcRemoteTargetServer.h
+@@ -115,11 +115,11 @@ 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);
+-      if (EC)
+-        return errorCodeToError(EC);
++      std::string Err;
++      sys::MemoryBlock MB = sys::Memory::AllocateRWX(
++          Size, nullptr, &Err);
++      if (!MB.base())
++        report_fatal_error("Can't allocate enough memory: " + Err);
+ 
+       Addr = MB.base();
+       assert(Allocs.find(MB.base()) == Allocs.end() && "Duplicate alloc");
+@@ -277,12 +277,11 @@ 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));
+-    if (EC)
+-      return errorCodeToError(EC);
++    std::string Err;
++    ResolverBlock = sys::OwningMemoryBlock(sys::Memory::AllocateRWX(
++        TargetT::ResolverCodeSize, nullptr, &Err));
++    if (!ResolverBlock.base())
++      report_fatal_error("Can't allocate enough memory: " + Err);
+ 
+     TargetT::writeResolverCode(static_cast<uint8_t *>(ResolverBlock.base()),
+                                &reenter, this);
+@@ -293,13 +292,12 @@ private:
+   }
+ 
+   Expected<std::tuple<JITTargetAddress, uint32_t>> handleEmitTrampolineBlock() {
+-    std::error_code EC;
++    std::string Err;
+     auto TrampolineBlock =
+-        sys::OwningMemoryBlock(sys::Memory::allocateMappedMemory(
+-            sys::Process::getPageSize(), nullptr,
+-            sys::Memory::MF_READ | sys::Memory::MF_WRITE, EC));
+-    if (EC)
+-      return errorCodeToError(EC);
++        sys::OwningMemoryBlock(sys::Memory::AllocateRWX(
++            sys::Process::getPageSize(), nullptr, &Err));
++    if (!TrampolineBlock.base())
++      report_fatal_error("Can't allocate enough memory: " + Err);
+ 
+     uint32_t NumTrampolines =
+         (sys::Process::getPageSize() - TargetT::PointerSize) /
+@@ -309,6 +307,7 @@ private:
+     TargetT::writeTrampolines(TrampolineMem, ResolverBlock.base(),
+                               NumTrampolines);
+ 
++    std::error_code EC;
+     EC = sys::Memory::protectMappedMemory(TrampolineBlock.getMemoryBlock(),
+                                           sys::Memory::MF_READ |
+                                               sys::Memory::MF_EXEC);
diff --git a/llvm-netbsd/patches/patch-lib_ExecutionEngine_Orc_OrcABISupport.cpp b/llvm-netbsd/patches/patch-lib_ExecutionEngine_Orc_OrcABISupport.cpp
new file mode 100644
index 0000000000..d1ff2df2fb
--- /dev/null
+++ b/llvm-netbsd/patches/patch-lib_ExecutionEngine_Orc_OrcABISupport.cpp
@@ -0,0 +1,61 @@
+$NetBSD$
+
+--- lib/ExecutionEngine/Orc/OrcABISupport.cpp.orig	2017-07-05 18:38:00.000000000 +0000
++++ lib/ExecutionEngine/Orc/OrcABISupport.cpp
+@@ -154,13 +154,11 @@ Error OrcAArch64::emitIndirectStubsBlock
+   unsigned NumStubs = (NumPages * PageSize) / StubSize;
+ 
+   // 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));
+-
+-  if (EC)
+-    return errorCodeToError(EC);
++  std::string Err;
++  auto StubsMem = sys::OwningMemoryBlock(sys::Memory::AllocateRWX(
++      2 * NumPages * PageSize, nullptr, &Err));
++  if (!StubsMem.base())
++    report_fatal_error("Can't allocate enough memory: " + Err);
+ 
+   // Create separate MemoryBlocks representing the stubs and pointers.
+   sys::MemoryBlock StubsBlock(StubsMem.base(), NumPages * PageSize);
+@@ -236,13 +234,11 @@ Error OrcX86_64_Base::emitIndirectStubsB
+   unsigned NumStubs = (NumPages * PageSize) / StubSize;
+ 
+   // 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));
+-
+-  if (EC)
+-    return errorCodeToError(EC);
++  std::string Err;
++  auto StubsMem = sys::OwningMemoryBlock(sys::Memory::AllocateRWX(
++      2 * NumPages * PageSize, nullptr, &Err));
++  if (!StubsMem.base())
++    report_fatal_error("Can't allocate enough memory: " + Err);
+ 
+   // Create separate MemoryBlocks representing the stubs and pointers.
+   sys::MemoryBlock StubsBlock(StubsMem.base(), NumPages * PageSize);
+@@ -504,13 +500,11 @@ Error OrcI386::emitIndirectStubsBlock(In
+   unsigned NumStubs = (NumPages * PageSize) / StubSize;
+ 
+   // 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));
+-
+-  if (EC)
+-    return errorCodeToError(EC);
++  std::string Err;
++  auto StubsMem = sys::OwningMemoryBlock(sys::Memory::AllocateRWX(
++      2 * NumPages * PageSize, nullptr, &Err));
++  if (!StubsMem.base())
++    report_fatal_error("Can't allocate enough memory: " + Err);
+ 
+   // Create separate MemoryBlocks representing the stubs and pointers.
+   sys::MemoryBlock StubsBlock(StubsMem.base(), NumPages * PageSize);
diff --git a/llvm-netbsd/patches/patch-lib_ExecutionEngine_SectionMemoryManager.cpp b/llvm-netbsd/patches/patch-lib_ExecutionEngine_SectionMemoryManager.cpp
new file mode 100644
index 0000000000..ee715fad45
--- /dev/null
+++ b/llvm-netbsd/patches/patch-lib_ExecutionEngine_SectionMemoryManager.cpp
@@ -0,0 +1,28 @@
+$NetBSD$
+
+--- lib/ExecutionEngine/SectionMemoryManager.cpp.orig	2017-07-05 18:38:00.000000000 +0000
++++ lib/ExecutionEngine/SectionMemoryManager.cpp
+@@ -83,16 +83,13 @@ 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);
+-  if (ec) {
+-    // FIXME: Add error propagation to the interface.
+-    return nullptr;
+-  }
++  std::string Err;
++  sys::MemoryBlock MB = sys::Memory::AllocateRWX(RequiredSize,
++                                                 &MemGroup.Near,
++                                                 &Err);
++  if (!MB.base())
++    report_fatal_error("Can't allocate enough memory: " + Err);
++
+ 
+   // Save this address as the basis for our next request
+   MemGroup.Near = MB;
diff --git a/llvm-netbsd/patches/patch-lib_Support_Unix_Signals.inc b/llvm-netbsd/patches/patch-lib_Support_Unix_Signals.inc
new file mode 100644
index 0000000000..1f7c52f6b3
--- /dev/null
+++ b/llvm-netbsd/patches/patch-lib_Support_Unix_Signals.inc
@@ -0,0 +1,15 @@
+$NetBSD$
+
+--- lib/Support/Unix/Signals.inc.orig	2017-07-17 14:09:08.907201312 +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() {


Home | Main Index | Thread Index | Old Index