Skip to content

Commit 887f1e4

Browse files
committed
[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 962a247, 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.
1 parent e72fe65 commit 887f1e4

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

llvm/tools/llvm-jitlink/llvm-jitlink.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ class JITLinkSlabAllocator final : public JITLinkMemoryManager {
557557
<< "\n";
558558
});
559559
Seg.WorkingMem = SegAddr.toPtr<char *>();
560-
Seg.Addr = SegAddr + NextSlabDelta;
560+
Seg.Addr = SegAddr + SlabDelta;
561561

562562
SegAddr += alignTo(Seg.ContentSize + Seg.ZeroFillSize, PageSize);
563563

@@ -566,8 +566,6 @@ class JITLinkSlabAllocator final : public JITLinkMemoryManager {
566566
memset(Seg.WorkingMem + Seg.ContentSize, 0, Seg.ZeroFillSize);
567567
}
568568

569-
NextSlabDelta += SegsSizes->total();
570-
571569
if (auto Err = BL.apply()) {
572570
OnAllocated(std::move(Err));
573571
return;
@@ -637,7 +635,7 @@ class JITLinkSlabAllocator final : public JITLinkMemoryManager {
637635
// Calculate the target address delta to link as-if slab were at
638636
// SlabAddress.
639637
if (SlabAddress != ~0ULL)
640-
NextSlabDelta = ExecutorAddr(SlabAddress) -
638+
SlabDelta = ExecutorAddr(SlabAddress) -
641639
ExecutorAddr::fromPtr(SlabRemaining.base());
642640
}
643641

@@ -649,7 +647,7 @@ class JITLinkSlabAllocator final : public JITLinkMemoryManager {
649647
std::mutex SlabMutex;
650648
sys::MemoryBlock SlabRemaining;
651649
uint64_t PageSize = 0;
652-
int64_t NextSlabDelta = 0;
650+
int64_t SlabDelta = 0;
653651
};
654652

655653
Expected<uint64_t> getSlabAllocSize(StringRef SizeString) {

0 commit comments

Comments
 (0)