[llvm] 7ec6dde - [llvm-jitlink] Teach InProcessDeltaMapper to honor -slab-page-size option.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 3 21:50:11 PDT 2022
Author: Lang Hames
Date: 2022-10-03T21:50:01-07:00
New Revision: 7ec6dde83ae66b7b3a01c69d619970cd3280dfca
URL: https://github.com/llvm/llvm-project/commit/7ec6dde83ae66b7b3a01c69d619970cd3280dfca
DIFF: https://github.com/llvm/llvm-project/commit/7ec6dde83ae66b7b3a01c69d619970cd3280dfca.diff
LOG: [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.
Added:
Modified:
llvm/tools/llvm-jitlink/llvm-jitlink.cpp
Removed:
################################################################################
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
index 6c931d1156994..9184945b4e2a6 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
@@ -469,10 +469,19 @@ class InProcessDeltaMapper final : public InProcessMemoryMapper {
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 @@ class InProcessDeltaMapper final : public InProcessMemoryMapper {
}
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>>
More information about the llvm-commits
mailing list