aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2022-10-03 19:28:56 -0700
committerLang Hames <lhames@gmail.com>2022-10-03 21:50:01 -0700
commit7ec6dde83ae66b7b3a01c69d619970cd3280dfca (patch)
treeba1db69cffba85838b26f6d2fe0a860084eb1620 /llvm/tools/llvm-jitlink/llvm-jitlink.cpp
parent3019f488f4479933fca18d6a44ddaa70f2fd56d8 (diff)
downloadllvm-7ec6dde83ae66b7b3a01c69d619970cd3280dfca.zip
llvm-7ec6dde83ae66b7b3a01c69d619970cd3280dfca.tar.gz
llvm-7ec6dde83ae66b7b3a01c69d619970cd3280dfca.tar.bz2
[llvm-jitlink] Teach InProcessDeltaMapper to honor -slab-page-size option.
The -slab-page-size option is used to set a simulated page size in -no-exec tests. In order for this to work we need to use read/write permissions only on all simulated pages in order to ensure that no simulated page is made read-only by a permission change to the underlying real page. The aim of this patch is to make it safe to enable ExecutionEngine regression tests on arm64. Those tests will be enabled in a follow-up patch.
Diffstat (limited to 'llvm/tools/llvm-jitlink/llvm-jitlink.cpp')
-rw-r--r--llvm/tools/llvm-jitlink/llvm-jitlink.cpp45
1 files changed, 31 insertions, 14 deletions
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
index 6c931d1..9184945 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
@@ -469,10 +469,19 @@ public:
DeltaAddr(0) {}
static Expected<std::unique_ptr<InProcessDeltaMapper>> Create() {
- auto PageSize = sys::Process::getPageSize();
- if (!PageSize)
- return PageSize.takeError();
- return std::make_unique<InProcessDeltaMapper>(*PageSize, SlabAddress);
+ size_t PageSize = SlabPageSize;
+ if (!PageSize) {
+ if (auto PageSizeOrErr = sys::Process::getPageSize())
+ PageSize = *PageSizeOrErr;
+ else
+ return PageSizeOrErr.takeError();
+ }
+
+ if (PageSize == 0)
+ return make_error<StringError>("Page size is zero",
+ inconvertibleErrorCode());
+
+ return std::make_unique<InProcessDeltaMapper>(PageSize, SlabAddress);
}
void reserve(size_t NumBytes, OnReservedFunction OnReserved) override {
@@ -497,8 +506,12 @@ public:
}
void initialize(AllocInfo &AI, OnInitializedFunction OnInitialized) override {
+ // Slide mapping based on delta and make all segments read-writable.
auto FixedAI = AI;
FixedAI.MappingBase -= DeltaAddr;
+ for (auto &Seg : FixedAI.Segments)
+ Seg.AG = AllocGroup(MemProt::Read | MemProt::Write,
+ Seg.AG.getMemDeallocPolicy());
InProcessMemoryMapper::initialize(
FixedAI, [this, OnInitialized = std::move(OnInitialized)](
Expected<ExecutorAddr> Result) mutable {
@@ -557,23 +570,27 @@ Expected<uint64_t> getSlabAllocSize(StringRef SizeString) {
}
static std::unique_ptr<JITLinkMemoryManager> createInProcessMemoryManager() {
- if (!SlabAllocateSizeString.empty()) {
- auto SlabSize = ExitOnErr(getSlabAllocSize(SlabAllocateSizeString));
+ uint64_t SlabSize;
+#ifdef _WIN32
+ SlabSize = 1024 * 1024;
+#else
+ SlabSize = 1024 * 1024 * 1024;
+#endif
+ if (!SlabAllocateSizeString.empty())
+ SlabSize = ExitOnErr(getSlabAllocSize(SlabAllocateSizeString));
+
+ // If this is a -no-exec case and we're tweaking the slab address or size then
+ // use the delta mapper.
+ if (NoExec && (SlabAddress || SlabPageSize))
return ExitOnErr(
MapperJITLinkMemoryManager::CreateWithMapper<InProcessDeltaMapper>(
SlabSize));
- }
-#ifdef _WIN32
+ // Otherwise use the standard in-process mapper.
return ExitOnErr(
MapperJITLinkMemoryManager::CreateWithMapper<InProcessMemoryMapper>(
- 1024 * 1024));
-#else
- return ExitOnErr(
- MapperJITLinkMemoryManager::CreateWithMapper<InProcessMemoryMapper>(
- 1024 * 1024 * 1024));
-#endif
+ SlabSize));
}
Expected<std::unique_ptr<jitlink::JITLinkMemoryManager>>