Skip to content

Commit b9add2b

Browse files
authored
Merge pull request GaijinEntertainment#2811 from GaijinEntertainment/bbatkin/jit-dll-cache-export-fix
llvm_jit: DLLExport storage on jit_table_at globals (GaijinEntertainment#2802 cache-hit fix)
2 parents 1e079ed + 054e9ba commit b9add2b

3 files changed

Lines changed: 16 additions & 14 deletions

File tree

modules/dasLLVM/daslib/llvm_jit_common.das

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,10 @@ def public FN_JIT_TABLE_FIND(t : Type) {
222222
}
223223

224224
def private add_table_linkage(val : LLVMOpaqueValue?) {
225-
// windows crashes with weak linkage
226-
LLVMSetLinkage(val, LLVMLinkage.LLVMExternalLinkage)
225+
// DLLExport storage so ResolveExternVisitor's set_glob_address (GetProcAddress
226+
// on Windows) can find the slot on cache-hit reload; otherwise #2802 stale-addr.
227+
LLVMSetLinkage(val, LLVMLinkage.LLVMDLLExportLinkage)
228+
LLVMSetDLLStorageClass(val, LLVMDLLStorageClass.LLVMDLLExportStorageClass)
227229
}
228230

229231
def private get_or_create_table_fn(llvm_module : LLVMOpaqueModule?; var types : PrimitiveTypes?; fn_name : DllName; at_type : LLVMOpaqueType?; fn_ptr : void?) {

modules/dasLLVM/daslib/llvm_macro.das

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var LINK_WHOLE_LIB = false // when true, standalone exe links against the whole
2626
// invalidates cached DLLs (e.g. edits to llvm_jit.das, llvm_macro.das, llvm_jit_common.das,
2727
// runtime helper ABI, default target triple). Cache filenames fold this in, so a bump
2828
// makes every previously written DLL miss the cache on the next run and get GC'd.
29-
let LLVM_JIT_CODEGEN_VERSION : uint64 = 0x09ul
29+
let LLVM_JIT_CODEGEN_VERSION : uint64 = 0x0aul
3030

3131
let JIT_FNV_PRIME : uint64 = 1099511628211ul
3232

tests/jit_tests/dll_cache.das

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ require dastest/testing_boost
1313
let OUTPUT_DIR = "{get_das_root()}/build/tests"
1414
let PROBE_PATH = "{OUTPUT_DIR}/dll_cache_probe.das"
1515

16-
def write_probe(body_expr : string) : bool {
16+
def write_probe(table_value : int) : bool {
17+
// Probe uses table[k] so jit_table_at_tString lands in the emitted globals,
18+
// exercising the codegen path that #2802 fixed (DLLExport linkage on the
19+
// table accessor slots so ResolveExternVisitor can fix them up on reload).
1720
mkdir_rec(OUTPUT_DIR)
1821
var ok = false
1922
fopen(PROBE_PATH, "w") $(f) {
@@ -22,7 +25,9 @@ def write_probe(body_expr : string) : bool {
2225
fprint(f, "require daslib/just_in_time\n\n")
2326
fprint(f, "[jit, sideeffects, export]\n")
2427
fprint(f, "def probe(x : int) : int \{\n")
25-
fprint(f, " return {body_expr}\n")
28+
fprint(f, " var tab : table<string; int>\n")
29+
fprint(f, " tab[\"a\"] = {table_value}\n")
30+
fprint(f, " return x + tab[\"a\"]\n")
2631
fprint(f, "\}\n")
2732
fprint(f, "\n[export]\ndef main() \{\n let _ = probe(0)\n\}\n")
2833
ok = true
@@ -62,20 +67,15 @@ def list_dlls(subdir : string) : array<string> {
6267

6368
def clear_subdir(subdir : string) {
6469
dir(subdir) $(fname) {
65-
if (fname == "." || fname == "..") {
66-
return
67-
}
70+
return if (fname == "." || fname == "..")
6871
var err : string
6972
remove("{subdir}/{fname}", err)
7073
}
7174
}
7275

7376
def test_dll_cache(t : T?) {
74-
if (!jit_enabled() || !das_is_dll_build()) {
75-
return
76-
}
77-
// first compile seeds the namespace so we can locate the per-script subdir
78-
t |> equal(write_probe("x + 1"), true)
77+
return if (!jit_enabled() || !das_is_dll_build())
78+
t |> equal(write_probe(1), true)
7979
let ns = compile_probe()
8080
t |> equal(empty(ns), false)
8181
let subdir = ".jitted_scripts/{ns}"
@@ -94,7 +94,7 @@ def test_dll_cache(t : T?) {
9494
t |> strictEqual(dlls2[0], first_dll, "cache hit keeps same DLL filename")
9595

9696
// compile 3 with different body: miss, new DLL, old artifacts GC'd
97-
t |> equal(write_probe("x + 2"), true)
97+
t |> equal(write_probe(2), true)
9898
compile_probe()
9999
let dlls3 <- list_dlls(subdir)
100100
t |> equal(length(dlls3), 1)

0 commit comments

Comments
 (0)