[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
962a2479b5, 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.
This commit is contained in:
Lang Hames 2022-02-10 23:45:45 -08:00
parent e72fe654b7
commit 887f1e49d0
1 changed files with 3 additions and 5 deletions

View File

@ -557,7 +557,7 @@ public:
<< "\n";
});
Seg.WorkingMem = SegAddr.toPtr<char *>();
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<uint64_t> getSlabAllocSize(StringRef SizeString) {