Skip to content

Commit 2383294

Browse files
committed
[jit] Use the symbolpool from the es in the memory manager
1 parent a52db68 commit 2383294

File tree

8 files changed

+38
-29
lines changed

8 files changed

+38
-29
lines changed

llvm/include/llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/ExecutionEngine/Orc/Shared/AllocationActions.h"
2020
#include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
2121
#include "llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h"
22+
#include "llvm/ExecutionEngine/Orc/SymbolStringPool.h"
2223
#include "llvm/Support/Allocator.h"
2324
#include "llvm/Support/Error.h"
2425
#include "llvm/Support/MSVCErrorWorkarounds.h"
@@ -320,12 +321,15 @@ class SimpleSegmentAlloc {
320321
using OnFinalizedFunction =
321322
JITLinkMemoryManager::InFlightAlloc::OnFinalizedFunction;
322323

323-
static void Create(JITLinkMemoryManager &MemMgr, const JITLinkDylib *JD,
324-
SegmentMap Segments, OnCreatedFunction OnCreated);
324+
static void Create(JITLinkMemoryManager &MemMgr,
325+
std::shared_ptr<orc::SymbolStringPool> SSP,
326+
const JITLinkDylib *JD, SegmentMap Segments,
327+
OnCreatedFunction OnCreated);
325328

326-
static Expected<SimpleSegmentAlloc> Create(JITLinkMemoryManager &MemMgr,
327-
const JITLinkDylib *JD,
328-
SegmentMap Segments);
329+
static Expected<SimpleSegmentAlloc>
330+
Create(JITLinkMemoryManager &MemMgr,
331+
std::shared_ptr<orc::SymbolStringPool> SSP, const JITLinkDylib *JD,
332+
SegmentMap Segments);
329333

330334
SimpleSegmentAlloc(SimpleSegmentAlloc &&);
331335
SimpleSegmentAlloc &operator=(SimpleSegmentAlloc &&);

llvm/lib/ExecutionEngine/JITLink/JITLink.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ raw_ostream &operator<<(raw_ostream &OS, const Symbol &Sym) {
125125
<< ", linkage: " << formatv("{0:6}", getLinkageName(Sym.getLinkage()))
126126
<< ", scope: " << formatv("{0:8}", getScopeName(Sym.getScope())) << ", "
127127
<< (Sym.isLive() ? "live" : "dead") << " - "
128-
<< (Sym.hasName() ? Sym.getName() : "<anonymous symbol>");
128+
<< (Sym.hasName() ? *Sym.getName() : "<anonymous symbol>");
129129
return OS;
130130
}
131131

llvm/lib/ExecutionEngine/JITLink/JITLinkMemoryManager.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ orc::shared::AllocActions &BasicLayout::graphAllocActions() {
144144
}
145145

146146
void SimpleSegmentAlloc::Create(JITLinkMemoryManager &MemMgr,
147+
std::shared_ptr<orc::SymbolStringPool> SSP,
147148
const JITLinkDylib *JD, SegmentMap Segments,
148149
OnCreatedFunction OnCreated) {
149150

@@ -155,9 +156,8 @@ void SimpleSegmentAlloc::Create(JITLinkMemoryManager &MemMgr,
155156
"__---.finalize", "__R--.finalize", "__-W-.finalize", "__RW-.finalize",
156157
"__--X.finalize", "__R-X.finalize", "__-WX.finalize", "__RWX.finalize"};
157158

158-
auto G = std::make_unique<LinkGraph>(
159-
"", std::shared_ptr<orc::SymbolStringPool>(), Triple(), 0,
160-
llvm::endianness::native, nullptr);
159+
auto G = std::make_unique<LinkGraph>("", std::move(SSP), Triple(), 0,
160+
llvm::endianness::native, nullptr);
161161
orc::AllocGroupSmallMap<Block *> ContentBlocks;
162162

163163
orc::ExecutorAddr NextAddr(0x100000);
@@ -202,11 +202,12 @@ void SimpleSegmentAlloc::Create(JITLinkMemoryManager &MemMgr,
202202
}
203203

204204
Expected<SimpleSegmentAlloc>
205-
SimpleSegmentAlloc::Create(JITLinkMemoryManager &MemMgr, const JITLinkDylib *JD,
206-
SegmentMap Segments) {
205+
SimpleSegmentAlloc::Create(JITLinkMemoryManager &MemMgr,
206+
std::shared_ptr<orc::SymbolStringPool> SSP,
207+
const JITLinkDylib *JD, SegmentMap Segments) {
207208
std::promise<MSVCPExpected<SimpleSegmentAlloc>> AllocP;
208209
auto AllocF = AllocP.get_future();
209-
Create(MemMgr, JD, std::move(Segments),
210+
Create(MemMgr, std::move(SSP), JD, std::move(Segments),
210211
[&](Expected<SimpleSegmentAlloc> Result) {
211212
AllocP.set_value(std::move(Result));
212213
});

llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ Error CompactUnwindSplitter::operator()(LinkGraph &G) {
836836
return make_error<JITLinkError>(
837837
"Error adding keep-alive edge for compact unwind record at " +
838838
formatv("{0:x}", CURec->getAddress()) + ": target " +
839-
E.getTarget().getName() + " is an external symbol");
839+
*E.getTarget().getName() + " is an external symbol");
840840
auto &TgtBlock = E.getTarget().getBlock();
841841
auto &CURecSym =
842842
G.addAnonymousSymbol(*CURec, 0, CURecordSize, false, false);

llvm/lib/ExecutionEngine/Orc/DebugObjectManagerPlugin.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ class DebugObject {
149149

150150
JITLinkMemoryManager &MemMgr;
151151
const JITLinkDylib *JD = nullptr;
152+
ExecutionSession &ES;
152153

153154
private:
154-
ExecutionSession &ES;
155155
DebugObjectFlags Flags;
156156
FinalizedAlloc Alloc;
157157
};
@@ -331,8 +331,9 @@ Expected<SimpleSegmentAlloc> ELFDebugObject::finalizeWorkingMemory() {
331331
size_t Size = Buffer->getBufferSize();
332332

333333
// Allocate working memory for debug object in read-only segment.
334-
auto Alloc = SimpleSegmentAlloc::Create(
335-
MemMgr, JD, {{MemProt::Read, {Size, Align(PageSize)}}});
334+
auto Alloc =
335+
SimpleSegmentAlloc::Create(MemMgr, ES.getSymbolStringPool(), JD,
336+
{{MemProt::Read, {Size, Align(PageSize)}}});
336337
if (!Alloc)
337338
return Alloc;
338339

llvm/lib/ExecutionEngine/Orc/EPCIndirectionUtils.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Error EPCTrampolinePool::grow() {
110110
auto &EPC = EPCIU.getExecutorProcessControl();
111111
auto PageSize = EPC.getPageSize();
112112
auto Alloc = SimpleSegmentAlloc::Create(
113-
EPC.getMemMgr(), nullptr,
113+
EPC.getMemMgr(), EPC.getSymbolStringPool(), nullptr,
114114
{{MemProt::Read | MemProt::Exec, {PageSize, Align(PageSize)}}});
115115
if (!Alloc)
116116
return Alloc.takeError();
@@ -294,10 +294,10 @@ EPCIndirectionUtils::writeResolverBlock(ExecutorAddr ReentryFnAddr,
294294
assert(ABI && "ABI can not be null");
295295
auto ResolverSize = ABI->getResolverCodeSize();
296296

297-
auto Alloc =
298-
SimpleSegmentAlloc::Create(EPC.getMemMgr(), nullptr,
299-
{{MemProt::Read | MemProt::Exec,
300-
{ResolverSize, Align(EPC.getPageSize())}}});
297+
auto Alloc = SimpleSegmentAlloc::Create(
298+
EPC.getMemMgr(), EPC.getSymbolStringPool(), nullptr,
299+
{{MemProt::Read | MemProt::Exec,
300+
{ResolverSize, Align(EPC.getPageSize())}}});
301301

302302
if (!Alloc)
303303
return Alloc.takeError();
@@ -363,7 +363,7 @@ EPCIndirectionUtils::getIndirectStubs(unsigned NumStubs) {
363363
auto PtrProt = MemProt::Read | MemProt::Write;
364364

365365
auto Alloc = SimpleSegmentAlloc::Create(
366-
EPC.getMemMgr(), nullptr,
366+
EPC.getMemMgr(), EPC.getSymbolStringPool(), nullptr,
367367
{{StubProt, {static_cast<size_t>(StubBytes), Align(PageSize)}},
368368
{PtrProt, {static_cast<size_t>(PtrBytes), Align(PageSize)}}});
369369

llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ TEST(EPCGenericJITLinkMemoryManagerTest, AllocFinalizeFree) {
114114
SAs.Deallocate = ExecutorAddr::fromPtr(&testDeallocate);
115115

116116
auto MemMgr = std::make_unique<EPCGenericJITLinkMemoryManager>(*SelfEPC, SAs);
117-
118117
StringRef Hello = "hello";
119118
auto SSA = jitlink::SimpleSegmentAlloc::Create(
120-
*MemMgr, nullptr, {{MemProt::Read, {Hello.size(), Align(1)}}});
119+
*MemMgr, std::make_shared<orc::SymbolStringPool>(), nullptr,
120+
{{MemProt::Read, {Hello.size(), Align(1)}}});
121121
EXPECT_THAT_EXPECTED(SSA, Succeeded());
122122
auto SegInfo = SSA->getSegInfo(MemProt::Read);
123123
memcpy(SegInfo.WorkingMem.data(), Hello.data(), Hello.size());

llvm/unittests/ExecutionEngine/Orc/MapperJITLinkMemoryManagerTest.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ TEST(MapperJITLinkMemoryManagerTest, InProcess) {
7676

7777
StringRef Hello = "hello";
7878
auto SSA1 = jitlink::SimpleSegmentAlloc::Create(
79-
*MemMgr, nullptr, {{MemProt::Read, {Hello.size(), Align(1)}}});
79+
*MemMgr, std::make_shared<orc::SymbolStringPool>(), nullptr,
80+
{{MemProt::Read, {Hello.size(), Align(1)}}});
8081
EXPECT_THAT_EXPECTED(SSA1, Succeeded());
8182

8283
EXPECT_EQ(Counter->ReserveCount, 1);
@@ -92,7 +93,8 @@ TEST(MapperJITLinkMemoryManagerTest, InProcess) {
9293
EXPECT_EQ(Counter->InitCount, 1);
9394

9495
auto SSA2 = jitlink::SimpleSegmentAlloc::Create(
95-
*MemMgr, nullptr, {{MemProt::Read, {Hello.size(), Align(1)}}});
96+
*MemMgr, std::make_shared<orc::SymbolStringPool>(), nullptr,
97+
{{MemProt::Read, {Hello.size(), Align(1)}}});
9698
EXPECT_THAT_EXPECTED(SSA2, Succeeded());
9799

98100
// last reservation should be reused
@@ -135,17 +137,18 @@ TEST(MapperJITLinkMemoryManagerTest, Coalescing) {
135137
auto Mapper = cantFail(InProcessMemoryMapper::Create());
136138
auto MemMgr = std::make_unique<MapperJITLinkMemoryManager>(16 * 1024 * 1024,
137139
std::move(Mapper));
140+
auto SSP = std::make_shared<orc::SymbolStringPool>();
138141

139142
auto SSA1 = jitlink::SimpleSegmentAlloc::Create(
140-
*MemMgr, nullptr, {{MemProt::Read, {1024, Align(1)}}});
143+
*MemMgr, SSP, nullptr, {{MemProt::Read, {1024, Align(1)}}});
141144
EXPECT_THAT_EXPECTED(SSA1, Succeeded());
142145
auto SegInfo1 = SSA1->getSegInfo(MemProt::Read);
143146
ExecutorAddr TargetAddr1(SegInfo1.Addr);
144147
auto FA1 = SSA1->finalize();
145148
EXPECT_THAT_EXPECTED(FA1, Succeeded());
146149

147150
auto SSA2 = jitlink::SimpleSegmentAlloc::Create(
148-
*MemMgr, nullptr, {{MemProt::Read, {1024, Align(1)}}});
151+
*MemMgr, SSP, nullptr, {{MemProt::Read, {1024, Align(1)}}});
149152
EXPECT_THAT_EXPECTED(SSA2, Succeeded());
150153
auto FA2 = SSA2->finalize();
151154
EXPECT_THAT_EXPECTED(FA2, Succeeded());
@@ -157,7 +160,7 @@ TEST(MapperJITLinkMemoryManagerTest, Coalescing) {
157160
EXPECT_THAT_ERROR(std::move(Err3), Succeeded());
158161

159162
auto SSA3 = jitlink::SimpleSegmentAlloc::Create(
160-
*MemMgr, nullptr, {{MemProt::Read, {2048, Align(1)}}});
163+
*MemMgr, SSP, nullptr, {{MemProt::Read, {2048, Align(1)}}});
161164
EXPECT_THAT_EXPECTED(SSA3, Succeeded());
162165

163166
auto SegInfo3 = SSA3->getSegInfo(MemProt::Read);

0 commit comments

Comments
 (0)