Skip to content

Commit 5c9602e

Browse files
vchuravypchintalapudi
authored andcommitted
Don't mark nonlocal symbols as hidden (#51596)
Co-authored-by: Prem Chintalapudi <prem.chintalapudi@gmail.com> (cherry picked from commit 341e9d0)
1 parent 9f55128 commit 5c9602e

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 {
@@ -1569,6 +1573,16 @@ void jl_dump_native_impl(void *native_code,
15691573

15701574
Type *T_psize = dataM.getDataLayout().getIntPtrType(Context)->getPointerTo();
15711575

1576+
// This should really be in jl_create_native, but we haven't
1577+
// yet set the target triple binary format correctly at that
1578+
// point. This should be resolved when we start JITting for
1579+
// COFF when we switch over to JITLink.
1580+
for (auto &GA : dataM.aliases()) {
1581+
// Global aliases are only used for ccallable things, so we should
1582+
// mark them as dllexport
1583+
addComdat(&GA, TheTriple);
1584+
}
1585+
15721586
// add metadata information
15731587
if (imaging_mode) {
15741588
multiversioning_preannotate(dataM);

src/codegen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6797,6 +6797,10 @@ const char *jl_generate_ccallable(LLVMOrcThreadSafeModuleRef llvmmod, void *sysi
67976797
int found = jl_dlsym(sysimg_handle, name, &addr, 0);
67986798
if (found)
67996799
add_named_global(name, addr);
6800+
else {
6801+
err = jl_get_exceptionf(jl_errorexception_type, "%s not found in sysimg", name);
6802+
jl_throw(err);
6803+
}
68006804
}
68016805
else {
68026806
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
@@ -3372,7 +3372,7 @@ static jl_value_t *jl_validate_cache_file(ios_t *f, jl_array_t *depmods, uint64_
33723372
}
33733373

33743374
// TODO?: refactor to make it easier to create the "package inspector"
3375-
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)
3375+
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)
33763376
{
33773377
JL_TIMING(LOAD_IMAGE, LOAD_Pkgimg);
33783378
jl_timing_printf(JL_TIMING_DEFAULT_BLOCK, pkgname);
@@ -3427,7 +3427,7 @@ static jl_value_t *jl_restore_package_image_from_stream(ios_t *f, jl_image_t *im
34273427
size_t world = jl_atomic_load_acquire(&jl_world_counter);
34283428
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)
34293429
// reinit ccallables
3430-
jl_reinit_ccallable(&ccallable_list, base, NULL);
3430+
jl_reinit_ccallable(&ccallable_list, base, pkgimage_handle);
34313431
arraylist_free(&ccallable_list);
34323432

34333433
if (completeinfo) {
@@ -3458,11 +3458,11 @@ static void jl_restore_system_image_from_stream(ios_t *f, jl_image_t *image, uin
34583458
jl_restore_system_image_from_stream_(f, image, NULL, checksum | ((uint64_t)0xfdfcfbfa << 32), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
34593459
}
34603460

3461-
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)
3461+
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)
34623462
{
34633463
ios_t f;
34643464
ios_static_buffer(&f, (char*)buf, sz);
3465-
jl_value_t *ret = jl_restore_package_image_from_stream(&f, image, depmods, completeinfo, pkgname, needs_permalloc);
3465+
jl_value_t *ret = jl_restore_package_image_from_stream(pkgimage_handle, &f, image, depmods, completeinfo, pkgname, needs_permalloc);
34663466
ios_close(&f);
34673467
return ret;
34683468
}
@@ -3475,7 +3475,7 @@ JL_DLLEXPORT jl_value_t *jl_restore_incremental(const char *fname, jl_array_t *d
34753475
"Cache file \"%s\" not found.\n", fname);
34763476
}
34773477
jl_image_t pkgimage = {};
3478-
jl_value_t *ret = jl_restore_package_image_from_stream(&f, &pkgimage, depmods, completeinfo, pkgname, true);
3478+
jl_value_t *ret = jl_restore_package_image_from_stream(NULL, &f, &pkgimage, depmods, completeinfo, pkgname, true);
34793479
ios_close(&f);
34803480
return ret;
34813481
}
@@ -3546,7 +3546,7 @@ JL_DLLEXPORT jl_value_t *jl_restore_package_image_from_file(const char *fname, j
35463546

35473547
jl_image_t pkgimage = jl_init_processor_pkgimg(pkgimg_handle);
35483548

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

35513551
return mod;
35523552
}

0 commit comments

Comments
 (0)