Skip to content

Commit

Permalink
Revert "Switch to LLVM ORC v2" #38008 (#38785)
Browse files Browse the repository at this point in the history
* Revert "Let Orc handle JITEventListerners"

This reverts commit ef84df1.

* Revert "ExecutionSession no longer takes VModuleKey"

This reverts commit b8c5da1.

* Revert "LLVM: switch to Orc v2 API"

This reverts commit 2d178e4.
  • Loading branch information
vtjnash authored Dec 9, 2020
1 parent 0c10641 commit 599d329
Show file tree
Hide file tree
Showing 11 changed files with 258 additions and 265 deletions.
5 changes: 5 additions & 0 deletions deps/llvm.mk
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ LLVM_CMAKE += -DLLVM_BINDINGS_LIST="" -DLLVM_INCLUDE_DOCS=Off -DLLVM_ENABLE_TERM
ifeq ($(LLVM_ASSERTIONS), 1)
LLVM_CMAKE += -DLLVM_ENABLE_ASSERTIONS:BOOL=ON
endif # LLVM_ASSERTIONS
ifeq ($(LLVM_DEBUG), 1)
ifeq ($(OS), WINNT)
LLVM_CXXFLAGS += -Wa,-mbig-obj
endif # OS == WINNT
endif # LLVM_DEBUG
ifeq ($(OS), WINNT)
LLVM_CPPFLAGS += -D__USING_SJLJ_EXCEPTIONS__ -D__CRT__NO_INLINE
endif # OS == WINNT
Expand Down
2 changes: 1 addition & 1 deletion src/anticodegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void jl_write_malloc_log(void) UNAVAILABLE
void jl_write_coverage_data(void) UNAVAILABLE

JL_DLLEXPORT void jl_clear_malloc_data(void) UNAVAILABLE
JL_DLLEXPORT int jl_extern_c(jl_function_t *f, jl_value_t *rt, jl_value_t *argt, char *name) UNAVAILABLE
JL_DLLEXPORT void jl_extern_c(jl_function_t *f, jl_value_t *rt, jl_value_t *argt, char *name) UNAVAILABLE
JL_DLLEXPORT void *jl_function_ptr(jl_function_t *f, jl_value_t *rt, jl_value_t *argt) UNAVAILABLE
JL_DLLEXPORT jl_value_t *jl_dump_method_asm(jl_method_instance_t *linfo, size_t world, int raw_mc, char getwrapper, const char* asm_variant, const char *debuginfo) UNAVAILABLE
JL_DLLEXPORT const jl_value_t *jl_dump_function_ir(void *f, uint8_t strip_ir_metadata, uint8_t dump_module, const char *debuginfo) UNAVAILABLE
Expand Down
8 changes: 5 additions & 3 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5396,7 +5396,7 @@ static jl_cgval_t emit_cfunction(jl_codectx_t &ctx, jl_value_t *output_type, con

// do codegen to create a C-callable alias/wrapper, or if sysimg_handle is set,
// restore one from a loaded system image.
const char *jl_generate_ccallable(void *llvmmod, void *sysimg_handle, jl_value_t *declrt, jl_value_t *sigt, jl_codegen_params_t &params)
void jl_generate_ccallable(void *llvmmod, void *sysimg_handle, jl_value_t *declrt, jl_value_t *sigt, jl_codegen_params_t &params)
{
jl_datatype_t *ft = (jl_datatype_t*)jl_tparam0(sigt);
jl_value_t *ff = ft->instance;
Expand Down Expand Up @@ -5438,7 +5438,7 @@ const char *jl_generate_ccallable(void *llvmmod, void *sysimg_handle, jl_value_t
gen_cfun_wrapper((Module*)llvmmod, params, sig, ff, name, declrt, lam, NULL, NULL, NULL);
}
JL_GC_POP();
return name;
return;
}
err = jl_get_exceptionf(jl_errorexception_type, "%s", sig.err_msg.c_str());
}
Expand Down Expand Up @@ -7595,6 +7595,7 @@ static void init_jit_functions(void)
add_named_global(except_enter_func, (void*)NULL);

#ifdef _OS_WINDOWS_
#ifndef FORCE_ELF
#if defined(_CPU_X86_64_)
#if defined(_COMPILER_GCC_)
add_named_global("___chkstk_ms", &___chkstk_ms);
Expand All @@ -7609,6 +7610,7 @@ static void init_jit_functions(void)
#endif
#endif
#endif
#endif

#define BOX_F(ct) add_named_global("jl_box_"#ct, &jl_box_##ct);
BOX_F(int8); BOX_F(uint8);
Expand Down Expand Up @@ -7757,7 +7759,7 @@ extern "C" void jl_init_llvm(void)
#endif

init_julia_llvm_meta();
jl_ExecutionEngine = new JuliaOJIT(*jl_TargetMachine, &jl_LLVMContext);
jl_ExecutionEngine = new JuliaOJIT(*jl_TargetMachine);

// Mark our address spaces as non-integral
jl_data_layout = jl_ExecutionEngine->getDataLayout();
Expand Down
67 changes: 34 additions & 33 deletions src/debuginfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,10 @@ class JuliaJITEventListener: public JITEventListener
#endif

#if defined(_OS_WINDOWS_)
uint64_t SectionAddrCheck = 0;
uint64_t SectionLoadCheck = 0;
uint64_t SectionWriteCheck = 0;
uint64_t SectionAddrCheck = 0; // assert that all of the Sections are at the same location
uint8_t *UnwindData = NULL;
#if defined(_CPU_X86_64_)
uint64_t SectionLoadOffset = 1; // The real offset shouldn't be 1.
uint8_t *catchjmp = NULL;
for (const object::SymbolRef &sym_iter : debugObj.symbols()) {
StringRef sName = cantFail(sym_iter.getName());
Expand All @@ -339,38 +338,41 @@ class JuliaJITEventListener: public JITEventListener
Section->getName(sName);
#endif
uint64_t SectionLoadAddr = getLoadAddress(sName);
assert(SectionLoadAddr);
if (SectionAddrCheck) // assert that all of the Sections are at the same location
assert(SectionAddrCheck == SectionAddr &&
SectionLoadCheck == SectionLoadAddr);
SectionAddrCheck = SectionAddr;
SectionLoadCheck = SectionLoadAddr;
SectionWriteCheck = SectionLoadAddr;
if (memmgr)
SectionWriteCheck = (uintptr_t)lookupWriteAddressFor(memmgr,
(void*)SectionLoadAddr);
Addr += SectionWriteCheck - SectionLoadAddr;
Addr -= SectionAddr - SectionLoadAddr;
*pAddr = (uint8_t*)Addr;
if (SectionAddrCheck)
assert(SectionAddrCheck == SectionLoadAddr);
else
SectionAddrCheck = SectionLoadAddr;
if (memmgr)
SectionAddr =
(uintptr_t)lookupWriteAddressFor(memmgr,
(void*)SectionLoadAddr);
if (SectionLoadOffset != 1)
assert(SectionLoadOffset == SectionAddr - SectionLoadAddr);
else
SectionLoadOffset = SectionAddr - SectionLoadAddr;
}
}
assert(catchjmp);
assert(UnwindData);
assert(SectionAddrCheck);
assert(SectionLoadCheck);
catchjmp[0] = 0x48;
catchjmp[1] = 0xb8; // mov RAX, QWORD PTR [&__julia_personality]
*(uint64_t*)(&catchjmp[2]) = (uint64_t)&__julia_personality;
catchjmp[10] = 0xff;
catchjmp[11] = 0xe0; // jmp RAX
UnwindData[0] = 0x09; // version info, UNW_FLAG_EHANDLER
UnwindData[1] = 4; // size of prolog (bytes)
UnwindData[2] = 2; // count of unwind codes (slots)
UnwindData[3] = 0x05; // frame register (rbp) = rsp
UnwindData[4] = 4; // second instruction
UnwindData[5] = 0x03; // mov RBP, RSP
UnwindData[6] = 1; // first instruction
UnwindData[7] = 0x50; // push RBP
*(DWORD*)&UnwindData[8] = (DWORD)(catchjmp - (uint8_t*)SectionWriteCheck); // relative location of catchjmp
assert(SectionLoadOffset != 1);
catchjmp[SectionLoadOffset] = 0x48;
catchjmp[SectionLoadOffset + 1] = 0xb8; // mov RAX, QWORD PTR [&__julia_personality]
*(uint64_t*)(&catchjmp[SectionLoadOffset + 2]) =
(uint64_t)&__julia_personality;
catchjmp[SectionLoadOffset + 10] = 0xff;
catchjmp[SectionLoadOffset + 11] = 0xe0; // jmp RAX
UnwindData[SectionLoadOffset] = 0x09; // version info, UNW_FLAG_EHANDLER
UnwindData[SectionLoadOffset + 1] = 4; // size of prolog (bytes)
UnwindData[SectionLoadOffset + 2] = 2; // count of unwind codes (slots)
UnwindData[SectionLoadOffset + 3] = 0x05; // frame register (rbp) = rsp
UnwindData[SectionLoadOffset + 4] = 4; // second instruction
UnwindData[SectionLoadOffset + 5] = 0x03; // mov RBP, RSP
UnwindData[SectionLoadOffset + 6] = 1; // first instruction
UnwindData[SectionLoadOffset + 7] = 0x50; // push RBP
*(DWORD*)&UnwindData[SectionLoadOffset + 8] = (DWORD)(catchjmp - (uint8_t*)SectionAddrCheck); // relative location of catchjmp
#endif // defined(_OS_X86_64_)
#endif // defined(_OS_WINDOWS_)

Expand Down Expand Up @@ -398,10 +400,9 @@ class JuliaJITEventListener: public JITEventListener
size_t Size = sym_size.second;
#if defined(_OS_WINDOWS_)
if (SectionAddrCheck)
assert(SectionAddrCheck == SectionAddr &&
SectionLoadCheck == SectionLoadAddr);
SectionAddrCheck = SectionAddr;
SectionLoadCheck = SectionLoadAddr;
assert(SectionAddrCheck == SectionLoadAddr);
else
SectionAddrCheck = SectionLoadAddr;
create_PRUNTIME_FUNCTION(
(uint8_t*)(uintptr_t)Addr, (size_t)Size, sName,
(uint8_t*)(uintptr_t)SectionLoadAddr, (size_t)SectionSize, UnwindData);
Expand Down
4 changes: 1 addition & 3 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -2576,9 +2576,7 @@ static jl_value_t *_jl_restore_incremental(ios_t *f, jl_array_t *mod_array)
for (int i = 0; i < ccallable_list.len; i++) {
jl_svec_t *item = (jl_svec_t*)ccallable_list.items[i];
JL_GC_PROMISE_ROOTED(item);
int success = jl_compile_extern_c(NULL, NULL, NULL, jl_svecref(item, 0), jl_svecref(item, 1));
if (!success)
jl_safe_printf("@ccallable was already defined for this method name\n");
jl_compile_extern_c(NULL, NULL, NULL, jl_svecref(item, 0), jl_svecref(item, 1));
}
arraylist_free(&ccallable_list);
jl_value_t *ret = (jl_value_t*)jl_svec(2, restored, init_order);
Expand Down
Loading

0 comments on commit 599d329

Please sign in to comment.