Skip to content

Commit 341e9d0

Browse files
Don't mark nonlocal symbols as hidden (#51596)
Co-authored-by: Prem Chintalapudi <prem.chintalapudi@gmail.com>
1 parent aa42963 commit 341e9d0

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

src/aotcompile.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,8 +835,12 @@ static SmallVector<Partition, 32> partitionModule(Module &M, unsigned threads) {
835835
continue;
836836
if (!canPartition(G))
837837
continue;
838-
G.setLinkage(GlobalValue::ExternalLinkage);
839-
G.setVisibility(GlobalValue::HiddenVisibility);
838+
// Currently ccallable global aliases have extern linkage, we only want to make the
839+
// internally linked functions/global variables extern+hidden
840+
if (G.hasLocalLinkage()) {
841+
G.setLinkage(GlobalValue::ExternalLinkage);
842+
G.setVisibility(GlobalValue::HiddenVisibility);
843+
}
840844
if (auto F = dyn_cast<Function>(&G)) {
841845
partitioner.make(&G, getFunctionWeight(*F).weight);
842846
} else {
@@ -1581,6 +1585,16 @@ void jl_dump_native_impl(void *native_code,
15811585

15821586
Type *T_psize = dataM.getDataLayout().getIntPtrType(Context)->getPointerTo();
15831587

1588+
// This should really be in jl_create_native, but we haven't
1589+
// yet set the target triple binary format correctly at that
1590+
// point. This should be resolved when we start JITting for
1591+
// COFF when we switch over to JITLink.
1592+
for (auto &GA : dataM.aliases()) {
1593+
// Global aliases are only used for ccallable things, so we should
1594+
// mark them as dllexport
1595+
addComdat(&GA, TheTriple);
1596+
}
1597+
15841598
// Wipe the global initializers, we'll reset them at load time
15851599
for (auto gv : data->jl_sysimg_gvars) {
15861600
cast<GlobalVariable>(gv)->setInitializer(Constant::getNullValue(gv->getValueType()));

src/codegen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6858,6 +6858,10 @@ const char *jl_generate_ccallable(LLVMOrcThreadSafeModuleRef llvmmod, void *sysi
68586858
int found = jl_dlsym(sysimg_handle, name, &addr, 0);
68596859
if (found)
68606860
add_named_global(name, addr);
6861+
else {
6862+
err = jl_get_exceptionf(jl_errorexception_type, "%s not found in sysimg", name);
6863+
jl_throw(err);
6864+
}
68616865
}
68626866
else {
68636867
jl_method_instance_t *lam = jl_get_specialization1((jl_tupletype_t*)sigt, world, &min_valid, &max_valid, 0);

src/staticdata.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3386,7 +3386,7 @@ static jl_value_t *jl_validate_cache_file(ios_t *f, jl_array_t *depmods, uint64_
33863386
}
33873387

33883388
// TODO?: refactor to make it easier to create the "package inspector"
3389-
static jl_value_t *jl_restore_package_image_from_stream(ios_t *f, jl_image_t *image, jl_array_t *depmods, int completeinfo, const char *pkgname, bool needs_permalloc)
3389+
static jl_value_t *jl_restore_package_image_from_stream(void* pkgimage_handle, ios_t *f, jl_image_t *image, jl_array_t *depmods, int completeinfo, const char *pkgname, bool needs_permalloc)
33903390
{
33913391
JL_TIMING(LOAD_IMAGE, LOAD_Pkgimg);
33923392
jl_timing_printf(JL_TIMING_DEFAULT_BLOCK, pkgname);
@@ -3441,7 +3441,7 @@ static jl_value_t *jl_restore_package_image_from_stream(ios_t *f, jl_image_t *im
34413441
size_t world = jl_atomic_load_acquire(&jl_world_counter);
34423442
jl_insert_backedges((jl_array_t*)edges, (jl_array_t*)ext_targets, (jl_array_t*)new_specializations, world); // restore external backedges (needs to be last)
34433443
// reinit ccallables
3444-
jl_reinit_ccallable(&ccallable_list, base, NULL);
3444+
jl_reinit_ccallable(&ccallable_list, base, pkgimage_handle);
34453445
arraylist_free(&ccallable_list);
34463446

34473447
if (completeinfo) {
@@ -3472,11 +3472,11 @@ static void jl_restore_system_image_from_stream(ios_t *f, jl_image_t *image, uin
34723472
jl_restore_system_image_from_stream_(f, image, NULL, checksum | ((uint64_t)0xfdfcfbfa << 32), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
34733473
}
34743474

3475-
JL_DLLEXPORT jl_value_t *jl_restore_incremental_from_buf(const char *buf, jl_image_t *image, size_t sz, jl_array_t *depmods, int completeinfo, const char *pkgname, bool needs_permalloc)
3475+
JL_DLLEXPORT jl_value_t *jl_restore_incremental_from_buf(void* pkgimage_handle, const char *buf, jl_image_t *image, size_t sz, jl_array_t *depmods, int completeinfo, const char *pkgname, bool needs_permalloc)
34763476
{
34773477
ios_t f;
34783478
ios_static_buffer(&f, (char*)buf, sz);
3479-
jl_value_t *ret = jl_restore_package_image_from_stream(&f, image, depmods, completeinfo, pkgname, needs_permalloc);
3479+
jl_value_t *ret = jl_restore_package_image_from_stream(pkgimage_handle, &f, image, depmods, completeinfo, pkgname, needs_permalloc);
34803480
ios_close(&f);
34813481
return ret;
34823482
}
@@ -3489,7 +3489,7 @@ JL_DLLEXPORT jl_value_t *jl_restore_incremental(const char *fname, jl_array_t *d
34893489
"Cache file \"%s\" not found.\n", fname);
34903490
}
34913491
jl_image_t pkgimage = {};
3492-
jl_value_t *ret = jl_restore_package_image_from_stream(&f, &pkgimage, depmods, completeinfo, pkgname, true);
3492+
jl_value_t *ret = jl_restore_package_image_from_stream(NULL, &f, &pkgimage, depmods, completeinfo, pkgname, true);
34933493
ios_close(&f);
34943494
return ret;
34953495
}
@@ -3560,7 +3560,7 @@ JL_DLLEXPORT jl_value_t *jl_restore_package_image_from_file(const char *fname, j
35603560

35613561
jl_image_t pkgimage = jl_init_processor_pkgimg(pkgimg_handle);
35623562

3563-
jl_value_t* mod = jl_restore_incremental_from_buf(pkgimg_data, &pkgimage, *plen, depmods, completeinfo, pkgname, false);
3563+
jl_value_t* mod = jl_restore_incremental_from_buf(pkgimg_handle, pkgimg_data, &pkgimage, *plen, depmods, completeinfo, pkgname, false);
35643564

35653565
return mod;
35663566
}

0 commit comments

Comments
 (0)