This repository was archived by the owner on Jul 3, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed
Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,10 @@ target_compile_definitions(JitFromScratch PRIVATE ${LLVM_DEFINITIONS})
9393target_link_libraries (JitFromScratch PRIVATE ${llvm_libs} )
9494target_compile_options (JitFromScratch PRIVATE ${rtti_flags} )
9595
96+ # Allow dlopen() to access exported symbols.
97+ # This will add linker flags like -Wl,--export-dynamic -rdynamic
98+ export_executable_symbols(JitFromScratch)
99+
96100function (dump_target_properties target property)
97101 get_target_property (values ${target} ${property} )
98102 if (values)
Original file line number Diff line number Diff line change @@ -13,6 +13,30 @@ JitFromScratch::JitFromScratch(ExitOnError ExitOnErr) {
1313 ExitOnErr (Builder.prepareForConstruction ());
1414 TT = Builder.JTMB ->getTargetTriple ();
1515 LLJIT = ExitOnErr (Builder.create ());
16+
17+ if (auto R = createHostProcessResolver (LLJIT->getDataLayout ()))
18+ LLJIT->getMainJITDylib ().setGenerator (std::move (R));
19+ }
20+
21+ JITDylib::GeneratorFunction
22+ JitFromScratch::createHostProcessResolver (DataLayout DL) {
23+ char Prefix = DL.getGlobalPrefix ();
24+ Expected<JITDylib::GeneratorFunction> R =
25+ DynamicLibrarySearchGenerator::GetForCurrentProcess (Prefix);
26+
27+ if (!R) {
28+ LLJIT->getExecutionSession ().reportError (R.takeError ());
29+ return nullptr ;
30+ }
31+
32+ if (!*R) {
33+ LLJIT->getExecutionSession ().reportError (createStringError (
34+ inconvertibleErrorCode (),
35+ " Generator function for host process symbols must not be null" ));
36+ return nullptr ;
37+ }
38+
39+ return *R;
1640}
1741
1842Error JitFromScratch::submitModule (std::unique_ptr<Module> M,
Original file line number Diff line number Diff line change @@ -46,5 +46,8 @@ class JitFromScratch {
4646 std::unique_ptr<llvm::orc::LLJIT> LLJIT;
4747 llvm::Triple TT;
4848
49+ llvm::orc::JITDylib::GeneratorFunction
50+ createHostProcessResolver (llvm::DataLayout DL);
51+
4952 llvm::Expected<llvm::JITTargetAddress> getFunctionAddr (llvm::StringRef Name);
5053};
You can’t perform that action at this time.
0 commit comments