[llvm] Implement reserveAllocationSpace for SectionMemoryManager (PR #71968)
Michael Smith via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 13 16:25:46 PST 2023
================
@@ -18,6 +18,63 @@
namespace llvm {
+static uint64_t requiredPageSize(uintptr_t Size, Align Alignment) {
+ static const size_t PageSize = sys::Process::getPageSizeEstimate();
+ // Use the same calculation as allocateSection because we need to be able to
+ // satisfy it.
+ uint64_t RequiredSize = alignTo(Size, Alignment);
+ // Round up to the nearest page size. Blocks must be page-aligned.
+ return PageSize * ((RequiredSize + PageSize - 1) / PageSize);
+}
+
+void SectionMemoryManager::reserveAllocationSpace(
+ uintptr_t CodeSize, Align CodeAlign, uintptr_t RODataSize,
+ Align RODataAlign, uintptr_t RWDataSize, Align RWDataAlign) {
+ if (CodeSize == 0 && RODataSize == 0 && RWDataSize == 0)
+ return;
+
+ // Get space required for each section.
+ uint64_t RequiredCodeSize = requiredPageSize(CodeSize, CodeAlign);
----------------
MikaelSmith wrote:
I have concerns about this and line 46:
```
uintptr_t RequiredSize = Alignment * ((Size + Alignment - 1) / Alignment + 1);
```
That calculation buffers by 1 Alignment, to ensure we always reserve enough space to align on address. It's inefficient, but not terribly.
If this sums up many calls to allocateCodeSection/allocateDataSection, does the caller also sum appropriately to cover those buffers?
https://github.com/llvm/llvm-project/pull/71968
More information about the llvm-commits
mailing list