Skip to content

Commit fad55ab

Browse files
authored
Switch back to LLVM ORC v2, take two (#38804)
Refs #38008 & #38785 (This reverts commit 599d329, and fixes a load ordering issue with our JuliaOJIT::addModule)
1 parent 996dd55 commit fad55ab

File tree

11 files changed

+272
-265
lines changed

11 files changed

+272
-265
lines changed

deps/llvm.mk

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,6 @@ LLVM_CMAKE += -DLLVM_BINDINGS_LIST="" -DLLVM_INCLUDE_DOCS=Off -DLLVM_ENABLE_TERM
129129
ifeq ($(LLVM_ASSERTIONS), 1)
130130
LLVM_CMAKE += -DLLVM_ENABLE_ASSERTIONS:BOOL=ON
131131
endif # LLVM_ASSERTIONS
132-
ifeq ($(LLVM_DEBUG), 1)
133-
ifeq ($(OS), WINNT)
134-
LLVM_CXXFLAGS += -Wa,-mbig-obj
135-
endif # OS == WINNT
136-
endif # LLVM_DEBUG
137132
ifeq ($(OS), WINNT)
138133
LLVM_CPPFLAGS += -D__USING_SJLJ_EXCEPTIONS__ -D__CRT__NO_INLINE
139134
endif # OS == WINNT

src/anticodegen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void jl_write_malloc_log(void) UNAVAILABLE
1313
void jl_write_coverage_data(void) UNAVAILABLE
1414

1515
JL_DLLEXPORT void jl_clear_malloc_data(void) UNAVAILABLE
16-
JL_DLLEXPORT void jl_extern_c(jl_function_t *f, jl_value_t *rt, jl_value_t *argt, char *name) UNAVAILABLE
16+
JL_DLLEXPORT int jl_extern_c(jl_function_t *f, jl_value_t *rt, jl_value_t *argt, char *name) UNAVAILABLE
1717
JL_DLLEXPORT void *jl_function_ptr(jl_function_t *f, jl_value_t *rt, jl_value_t *argt) UNAVAILABLE
1818
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
1919
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

src/codegen.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <llvm/IR/DIBuilder.h>
4545
#include <llvm/AsmParser/Parser.h>
4646
#include <llvm/DebugInfo/DIContext.h>
47+
#include "llvm/IR/DebugInfoMetadata.h"
4748
#include <llvm/IR/DerivedTypes.h>
4849
#include <llvm/IR/Intrinsics.h>
4950
#include <llvm/IR/Attributes.h>
@@ -5396,7 +5397,7 @@ static jl_cgval_t emit_cfunction(jl_codectx_t &ctx, jl_value_t *output_type, con
53965397

53975398
// do codegen to create a C-callable alias/wrapper, or if sysimg_handle is set,
53985399
// restore one from a loaded system image.
5399-
void jl_generate_ccallable(void *llvmmod, void *sysimg_handle, jl_value_t *declrt, jl_value_t *sigt, jl_codegen_params_t &params)
5400+
const char *jl_generate_ccallable(void *llvmmod, void *sysimg_handle, jl_value_t *declrt, jl_value_t *sigt, jl_codegen_params_t &params)
54005401
{
54015402
jl_datatype_t *ft = (jl_datatype_t*)jl_tparam0(sigt);
54025403
jl_value_t *ff = ft->instance;
@@ -5438,7 +5439,7 @@ void jl_generate_ccallable(void *llvmmod, void *sysimg_handle, jl_value_t *declr
54385439
gen_cfun_wrapper((Module*)llvmmod, params, sig, ff, name, declrt, lam, NULL, NULL, NULL);
54395440
}
54405441
JL_GC_POP();
5441-
return;
5442+
return name;
54425443
}
54435444
err = jl_get_exceptionf(jl_errorexception_type, "%s", sig.err_msg.c_str());
54445445
}
@@ -6009,7 +6010,7 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
60096010
,nullptr // Template Declaration
60106011
,nullptr // ThrownTypes
60116012
);
6012-
topdebugloc = DebugLoc::get(toplineno, 0, SP, NULL);
6013+
topdebugloc = DILocation::get(jl_LLVMContext, toplineno, 0, SP, NULL);
60136014
f->setSubprogram(SP);
60146015
if (jl_options.debug_level >= 2) {
60156016
const bool AlwaysPreserve = true;
@@ -6427,7 +6428,7 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
64276428
if (fname.empty())
64286429
fname = "macro expansion";
64296430
if (info.inlined_at == 0 && info.file == ctx.file) { // if everything matches, emit a toplevel line number
6430-
info.loc = DebugLoc::get(info.line, 0, SP, NULL);
6431+
info.loc = DILocation::get(jl_LLVMContext, info.line, 0, SP, NULL);
64316432
}
64326433
else { // otherwise, describe this as an inlining frame
64336434
DISubprogram *&inl_SP = subprograms[std::make_tuple(fname, info.file)];
@@ -6447,8 +6448,8 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
64476448
,nullptr // ThrownTypes
64486449
);
64496450
}
6450-
DebugLoc inl_loc = (info.inlined_at == 0) ? DebugLoc::get(0, 0, SP, NULL) : linetable.at(info.inlined_at).loc;
6451-
info.loc = DebugLoc::get(info.line, 0, inl_SP, inl_loc);
6451+
DebugLoc inl_loc = (info.inlined_at == 0) ? DebugLoc(DILocation::get(jl_LLVMContext, 0, 0, SP, NULL)) : linetable.at(info.inlined_at).loc;
6452+
info.loc = DILocation::get(jl_LLVMContext, info.line, 0, inl_SP, inl_loc);
64526453
}
64536454
}
64546455
}
@@ -7595,7 +7596,6 @@ static void init_jit_functions(void)
75957596
add_named_global(except_enter_func, (void*)NULL);
75967597

75977598
#ifdef _OS_WINDOWS_
7598-
#ifndef FORCE_ELF
75997599
#if defined(_CPU_X86_64_)
76007600
#if defined(_COMPILER_GCC_)
76017601
add_named_global("___chkstk_ms", &___chkstk_ms);
@@ -7610,7 +7610,6 @@ static void init_jit_functions(void)
76107610
#endif
76117611
#endif
76127612
#endif
7613-
#endif
76147613

76157614
#define BOX_F(ct) add_named_global("jl_box_"#ct, &jl_box_##ct);
76167615
BOX_F(int8); BOX_F(uint8);
@@ -7759,7 +7758,7 @@ extern "C" void jl_init_llvm(void)
77597758
#endif
77607759

77617760
init_julia_llvm_meta();
7762-
jl_ExecutionEngine = new JuliaOJIT(*jl_TargetMachine);
7761+
jl_ExecutionEngine = new JuliaOJIT(*jl_TargetMachine, &jl_LLVMContext);
77637762

77647763
// Mark our address spaces as non-integral
77657764
jl_data_layout = jl_ExecutionEngine->getDataLayout();

src/debuginfo.cpp

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,11 @@ class JuliaJITEventListener: public JITEventListener
313313
#endif
314314

315315
#if defined(_OS_WINDOWS_)
316-
uint64_t SectionAddrCheck = 0; // assert that all of the Sections are at the same location
316+
uint64_t SectionAddrCheck = 0;
317+
uint64_t SectionLoadCheck = 0;
318+
uint64_t SectionWriteCheck = 0;
317319
uint8_t *UnwindData = NULL;
318320
#if defined(_CPU_X86_64_)
319-
uint64_t SectionLoadOffset = 1; // The real offset shouldn't be 1.
320321
uint8_t *catchjmp = NULL;
321322
for (const object::SymbolRef &sym_iter : debugObj.symbols()) {
322323
StringRef sName = cantFail(sym_iter.getName());
@@ -338,41 +339,40 @@ class JuliaJITEventListener: public JITEventListener
338339
Section->getName(sName);
339340
#endif
340341
uint64_t SectionLoadAddr = getLoadAddress(sName);
341-
Addr -= SectionAddr - SectionLoadAddr;
342-
*pAddr = (uint8_t*)Addr;
343-
if (SectionAddrCheck)
344-
assert(SectionAddrCheck == SectionLoadAddr);
345-
else
346-
SectionAddrCheck = SectionLoadAddr;
342+
assert(SectionLoadAddr);
343+
if (SectionAddrCheck) // assert that all of the Sections are at the same location
344+
assert(SectionAddrCheck == SectionAddr &&
345+
SectionLoadCheck == SectionLoadAddr);
346+
SectionAddrCheck = SectionAddr;
347+
SectionLoadCheck = SectionLoadAddr;
348+
SectionWriteCheck = SectionLoadAddr;
347349
if (memmgr)
348-
SectionAddr =
349-
(uintptr_t)lookupWriteAddressFor(memmgr,
350-
(void*)SectionLoadAddr);
351-
if (SectionLoadOffset != 1)
352-
assert(SectionLoadOffset == SectionAddr - SectionLoadAddr);
353-
else
354-
SectionLoadOffset = SectionAddr - SectionLoadAddr;
350+
SectionWriteCheck = (uintptr_t)lookupWriteAddressFor(memmgr,
351+
(void*)SectionLoadAddr);
352+
Addr += SectionWriteCheck - SectionLoadAddr;
353+
*pAddr = (uint8_t*)Addr;
355354
}
356355
}
357356
assert(catchjmp);
358357
assert(UnwindData);
359358
assert(SectionAddrCheck);
360-
assert(SectionLoadOffset != 1);
361-
catchjmp[SectionLoadOffset] = 0x48;
362-
catchjmp[SectionLoadOffset + 1] = 0xb8; // mov RAX, QWORD PTR [&__julia_personality]
363-
*(uint64_t*)(&catchjmp[SectionLoadOffset + 2]) =
364-
(uint64_t)&__julia_personality;
365-
catchjmp[SectionLoadOffset + 10] = 0xff;
366-
catchjmp[SectionLoadOffset + 11] = 0xe0; // jmp RAX
367-
UnwindData[SectionLoadOffset] = 0x09; // version info, UNW_FLAG_EHANDLER
368-
UnwindData[SectionLoadOffset + 1] = 4; // size of prolog (bytes)
369-
UnwindData[SectionLoadOffset + 2] = 2; // count of unwind codes (slots)
370-
UnwindData[SectionLoadOffset + 3] = 0x05; // frame register (rbp) = rsp
371-
UnwindData[SectionLoadOffset + 4] = 4; // second instruction
372-
UnwindData[SectionLoadOffset + 5] = 0x03; // mov RBP, RSP
373-
UnwindData[SectionLoadOffset + 6] = 1; // first instruction
374-
UnwindData[SectionLoadOffset + 7] = 0x50; // push RBP
375-
*(DWORD*)&UnwindData[SectionLoadOffset + 8] = (DWORD)(catchjmp - (uint8_t*)SectionAddrCheck); // relative location of catchjmp
359+
assert(SectionLoadCheck);
360+
assert(!memcmp(catchjmp, "\0\0\0\0\0\0\0\0\0\0\0\0", 12) &&
361+
!memcmp(UnwindData, "\0\0\0\0\0\0\0\0\0\0\0\0", 12));
362+
catchjmp[0] = 0x48;
363+
catchjmp[1] = 0xb8; // mov RAX, QWORD PTR [&__julia_personality]
364+
*(uint64_t*)(&catchjmp[2]) = (uint64_t)&__julia_personality;
365+
catchjmp[10] = 0xff;
366+
catchjmp[11] = 0xe0; // jmp RAX
367+
UnwindData[0] = 0x09; // version info, UNW_FLAG_EHANDLER
368+
UnwindData[1] = 4; // size of prolog (bytes)
369+
UnwindData[2] = 2; // count of unwind codes (slots)
370+
UnwindData[3] = 0x05; // frame register (rbp) = rsp
371+
UnwindData[4] = 4; // second instruction
372+
UnwindData[5] = 0x03; // mov RBP, RSP
373+
UnwindData[6] = 1; // first instruction
374+
UnwindData[7] = 0x50; // push RBP
375+
*(DWORD*)&UnwindData[8] = (DWORD)(catchjmp - (uint8_t*)SectionWriteCheck); // relative location of catchjmp
376376
#endif // defined(_OS_X86_64_)
377377
#endif // defined(_OS_WINDOWS_)
378378

@@ -400,9 +400,10 @@ class JuliaJITEventListener: public JITEventListener
400400
size_t Size = sym_size.second;
401401
#if defined(_OS_WINDOWS_)
402402
if (SectionAddrCheck)
403-
assert(SectionAddrCheck == SectionLoadAddr);
404-
else
405-
SectionAddrCheck = SectionLoadAddr;
403+
assert(SectionAddrCheck == SectionAddr &&
404+
SectionLoadCheck == SectionLoadAddr);
405+
SectionAddrCheck = SectionAddr;
406+
SectionLoadCheck = SectionLoadAddr;
406407
create_PRUNTIME_FUNCTION(
407408
(uint8_t*)(uintptr_t)Addr, (size_t)Size, sName,
408409
(uint8_t*)(uintptr_t)SectionLoadAddr, (size_t)SectionSize, UnwindData);

src/dump.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2576,7 +2576,9 @@ static jl_value_t *_jl_restore_incremental(ios_t *f, jl_array_t *mod_array)
25762576
for (int i = 0; i < ccallable_list.len; i++) {
25772577
jl_svec_t *item = (jl_svec_t*)ccallable_list.items[i];
25782578
JL_GC_PROMISE_ROOTED(item);
2579-
jl_compile_extern_c(NULL, NULL, NULL, jl_svecref(item, 0), jl_svecref(item, 1));
2579+
int success = jl_compile_extern_c(NULL, NULL, NULL, jl_svecref(item, 0), jl_svecref(item, 1));
2580+
if (!success)
2581+
jl_safe_printf("@ccallable was already defined for this method name\n");
25802582
}
25812583
arraylist_free(&ccallable_list);
25822584
jl_value_t *ret = (jl_value_t*)jl_svec(2, restored, init_order);

0 commit comments

Comments
 (0)