From 887f1e49d0629fe870361b00d3cb8fb07374873f Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Thu, 10 Feb 2022 23:45:45 -0800 Subject: [PATCH] [llvm-jitlink] Fix a bug in llvm-jitlink's Slab allocator. The slab delta (used to link as if allocated at a specified address) should remain constant.The update to the delta was accidentally introduced in 962a2479b57f5, but hasn't caused any failures as it only breaks in an obvious way for multi-file exec uses (our regression tests are all -noexec, and tend to be single-file). No testcase here: this is an obscure utility for testing support, and an uncommon use-case. If the slab allocator is ever moved into LLVM we could add a unit test to catch this. --- llvm/tools/llvm-jitlink/llvm-jitlink.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp index 580ebda..f3443fa 100644 --- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp +++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp @@ -557,7 +557,7 @@ public: << "\n"; }); Seg.WorkingMem = SegAddr.toPtr(); - Seg.Addr = SegAddr + NextSlabDelta; + Seg.Addr = SegAddr + SlabDelta; SegAddr += alignTo(Seg.ContentSize + Seg.ZeroFillSize, PageSize); @@ -566,8 +566,6 @@ public: memset(Seg.WorkingMem + Seg.ContentSize, 0, Seg.ZeroFillSize); } - NextSlabDelta += SegsSizes->total(); - if (auto Err = BL.apply()) { OnAllocated(std::move(Err)); return; @@ -637,7 +635,7 @@ private: // Calculate the target address delta to link as-if slab were at // SlabAddress. if (SlabAddress != ~0ULL) - NextSlabDelta = ExecutorAddr(SlabAddress) - + SlabDelta = ExecutorAddr(SlabAddress) - ExecutorAddr::fromPtr(SlabRemaining.base()); } @@ -649,7 +647,7 @@ private: std::mutex SlabMutex; sys::MemoryBlock SlabRemaining; uint64_t PageSize = 0; - int64_t NextSlabDelta = 0; + int64_t SlabDelta = 0; }; Expected getSlabAllocSize(StringRef SizeString) { -- 2.7.4