Skip to content

Commit 91b8c9b

Browse files
authored
Add JL_DLLIMPORT to small_typeof declaration (#50892)
Resolves #50714
1 parent 631b5c3 commit 91b8c9b

File tree

14 files changed

+61
-45
lines changed

14 files changed

+61
-45
lines changed

cli/jl_exports.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ JL_EXPORTED_DATA_SYMBOLS(XX)
1818

1919
// define a copy of exported data
2020
#define jl_max_tags 64
21-
JL_DLLEXPORT void *small_typeof[(jl_max_tags << 4) / sizeof(void*)]; // 16-bit aligned, like the GC
21+
JL_DLLEXPORT void *jl_small_typeof[(jl_max_tags << 4) / sizeof(void*)]; // 16-bit aligned, like the GC
2222

2323
// Declare list of exported functions (sans type)
2424
#define XX(name) JL_DLLEXPORT void name(void);

src/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,12 @@ clang-tidy-%: $(SRCDIR)/%.cpp $(build_shlibdir)/libImplicitAtomicsPlugin.$(SHLIB
528528
-- $(CLANGSA_FLAGS) $(CLANGSA_CXXFLAGS) $(LLVM_CXXFLAGS) $(JCPPFLAGS_CLANG) $(JCXXFLAGS_CLANG) $(JL_CXXFLAGS) $(DEBUGFLAGS_CLANG) -fcolor-diagnostics --system-header-prefix=llvm -Wno-deprecated-declarations -fno-caret-diagnostics -x c++)
529529

530530
# set the exports for the source files based on where they are getting linked
531-
clang-sa-% clang-sagc-% clang-tidy-%: DEBUGFLAGS_CLANG += -DJL_LIBRARY_EXPORTS
531+
$(addprefix clang-sa-,$(SRCS)): DEBUGFLAGS_CLANG += -DJL_LIBRARY_EXPORTS_INTERNAL
532+
$(addprefix clang-sagc-,$(SRCS)): DEBUGFLAGS_CLANG += -DJL_LIBRARY_EXPORTS_INTERNAL
533+
$(addprefix clang-tidy-,$(SRCS)): DEBUGFLAGS_CLANG += -DJL_LIBRARY_EXPORTS_INTERNAL
534+
$(addprefix clang-sa-,$(CODEGEN_SRCS)): DEBUGFLAGS_CLANG += -DJL_LIBRARY_EXPORTS_CODEGEN
535+
$(addprefix clang-sagc-,$(CODEGEN_SRCS)): DEBUGFLAGS_CLANG += -DJL_LIBRARY_EXPORTS_CODEGEN
536+
$(addprefix clang-tidy-,$(CODEGEN_SRCS)): DEBUGFLAGS_CLANG += -DJL_LIBRARY_EXPORTS_CODEGEN
532537

533538
# Add C files as a target of `analyzesrc` and `analyzegc` and `tidysrc`
534539
tidysrc: $(addprefix clang-tidy-,$(filter-out $(basename $(SKIP_IMPLICIT_ATOMICS)),$(CODEGEN_SRCS) $(SRCS)))

src/aotcompile.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,10 +1642,10 @@ void jl_dump_native_impl(void *native_code,
16421642

16431643
// let the compiler know we are going to internalize a copy of this,
16441644
// if it has a current usage with ExternalLinkage
1645-
auto small_typeof_copy = dataM.getGlobalVariable("small_typeof");
1646-
if (small_typeof_copy) {
1647-
small_typeof_copy->setVisibility(GlobalValue::HiddenVisibility);
1648-
small_typeof_copy->setDSOLocal(true);
1645+
auto jl_small_typeof_copy = dataM.getGlobalVariable("jl_small_typeof");
1646+
if (jl_small_typeof_copy) {
1647+
jl_small_typeof_copy->setVisibility(GlobalValue::HiddenVisibility);
1648+
jl_small_typeof_copy->setDSOLocal(true);
16491649
}
16501650
}
16511651

@@ -1721,21 +1721,21 @@ void jl_dump_native_impl(void *native_code,
17211721
auto shards = emit_shard_table(metadataM, T_size, T_psize, threads);
17221722
auto ptls = emit_ptls_table(metadataM, T_size, T_psize);
17231723
auto header = emit_image_header(metadataM, threads, nfvars, ngvars);
1724-
auto AT = ArrayType::get(T_size, sizeof(small_typeof) / sizeof(void*));
1725-
auto small_typeof_copy = new GlobalVariable(metadataM, AT, false,
1724+
auto AT = ArrayType::get(T_size, sizeof(jl_small_typeof) / sizeof(void*));
1725+
auto jl_small_typeof_copy = new GlobalVariable(metadataM, AT, false,
17261726
GlobalVariable::ExternalLinkage,
17271727
Constant::getNullValue(AT),
1728-
"small_typeof");
1729-
small_typeof_copy->setVisibility(GlobalValue::HiddenVisibility);
1730-
small_typeof_copy->setDSOLocal(true);
1728+
"jl_small_typeof");
1729+
jl_small_typeof_copy->setVisibility(GlobalValue::HiddenVisibility);
1730+
jl_small_typeof_copy->setDSOLocal(true);
17311731
AT = ArrayType::get(T_psize, 5);
17321732
auto pointers = new GlobalVariable(metadataM, AT, false,
17331733
GlobalVariable::ExternalLinkage,
17341734
ConstantArray::get(AT, {
17351735
ConstantExpr::getBitCast(header, T_psize),
17361736
ConstantExpr::getBitCast(shards, T_psize),
17371737
ConstantExpr::getBitCast(ptls, T_psize),
1738-
ConstantExpr::getBitCast(small_typeof_copy, T_psize),
1738+
ConstantExpr::getBitCast(jl_small_typeof_copy, T_psize),
17391739
ConstantExpr::getBitCast(target_ids, T_psize)
17401740
}),
17411741
"jl_image_pointers");

src/builtins.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ JL_DLLEXPORT int jl_egal__unboxed(const jl_value_t *a JL_MAYBE_UNROOTED, const j
222222
JL_DLLEXPORT int jl_egal__bitstag(const jl_value_t *a JL_MAYBE_UNROOTED, const jl_value_t *b JL_MAYBE_UNROOTED, uintptr_t dtag) JL_NOTSAFEPOINT
223223
{
224224
if (dtag < jl_max_tags << 4) {
225-
switch ((enum jlsmall_typeof_tags)(dtag >> 4)) {
225+
switch ((enum jl_small_typeof_tags)(dtag >> 4)) {
226226
case jl_int8_tag:
227227
case jl_uint8_tag:
228228
return *(uint8_t*)a == *(uint8_t*)b;

src/cgutils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ static Constant *literal_pointer_val_slot(jl_codectx_t &ctx, jl_value_t *p)
410410
if (addr->smalltag) {
411411
// some common builtin datatypes have a special pool for accessing them by smalltag id
412412
Constant *tag = ConstantInt::get(getInt32Ty(ctx.builder.getContext()), addr->smalltag << 4);
413-
Constant *smallp = ConstantExpr::getInBoundsGetElementPtr(getInt8Ty(ctx.builder.getContext()), prepare_global_in(jl_Module, jlsmall_typeof_var), tag);
413+
Constant *smallp = ConstantExpr::getInBoundsGetElementPtr(getInt8Ty(ctx.builder.getContext()), prepare_global_in(jl_Module, jl_small_typeof_var), tag);
414414
return ConstantExpr::getBitCast(smallp, ctx.types().T_ppjlvalue);
415415
}
416416
// DataTypes are prefixed with a +
@@ -1086,7 +1086,7 @@ static Value *emit_typeof(jl_codectx_t &ctx, const jl_cgval_t &p, bool maybenull
10861086
if (jl_has_intersect_type_not_kind(typ))
10871087
return false;
10881088
for (size_t i = 0; i < jl_tags_count; i++) {
1089-
jl_datatype_t *dt = small_typeof[(i << 4) / sizeof(*small_typeof)];
1089+
jl_datatype_t *dt = jl_small_typeof[(i << 4) / sizeof(*jl_small_typeof)];
10901090
if (dt && !jl_has_empty_intersection((jl_value_t*)dt, typ))
10911091
return false;
10921092
}
@@ -1439,7 +1439,7 @@ static Value *emit_typeof(jl_codectx_t &ctx, Value *v, bool maybenull, bool just
14391439
// we lied a bit: this wasn't really an object (though it was valid for GC rooting)
14401440
// and we need to use it as an index to get the real object now
14411441
Module *M = jl_Module;
1442-
Value *smallp = ctx.builder.CreateInBoundsGEP(getInt8Ty(ctx.builder.getContext()), prepare_global_in(M, jlsmall_typeof_var), tag);
1442+
Value *smallp = ctx.builder.CreateInBoundsGEP(getInt8Ty(ctx.builder.getContext()), prepare_global_in(M, jl_small_typeof_var), tag);
14431443
smallp = ctx.builder.CreateBitCast(smallp, typetag->getType()->getPointerTo(0));
14441444
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_const);
14451445
auto small = ctx.builder.CreateAlignedLoad(typetag->getType(), smallp, M->getDataLayout().getPointerABIAlignment(0));

src/codegen.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,8 @@ static const auto jldlli_var = new JuliaVariable{
691691
true,
692692
[](Type *T_size) -> Type * { return getInt8PtrTy(T_size->getContext()); },
693693
};
694-
static const auto jlsmall_typeof_var = new JuliaVariable{
695-
XSTR(small_typeof),
694+
static const auto jl_small_typeof_var = new JuliaVariable{
695+
XSTR(jl_small_typeof),
696696
true,
697697
[](Type *T_size) -> Type * { return getInt8Ty(T_size->getContext()); },
698698
};
@@ -9184,7 +9184,7 @@ static void init_f16_funcs(void)
91849184

91859185
static void init_jit_functions(void)
91869186
{
9187-
add_named_global(jlsmall_typeof_var, &small_typeof);
9187+
add_named_global(jl_small_typeof_var, &jl_small_typeof);
91889188
add_named_global(jlstack_chk_guard_var, &__stack_chk_guard);
91899189
add_named_global(jlRTLD_DEFAULT_var, &jl_RTLD_DEFAULT_handle);
91909190
add_named_global(jlexe_var, &jl_exe_handle);

src/gc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,7 +2427,7 @@ FORCE_INLINE void gc_mark_outrefs(jl_ptls_t ptls, jl_gc_markqueue_t *mq, void *_
24272427
vtag == (jl_vararg_tag << 4)) {
24282428
// these objects have pointers in them, but no other special handling
24292429
// so we want these to fall through to the end
2430-
vtag = (uintptr_t)small_typeof[vtag / sizeof(*small_typeof)];
2430+
vtag = (uintptr_t)ijl_small_typeof[vtag / sizeof(*ijl_small_typeof)];
24312431
}
24322432
else if (vtag < jl_max_tags << 4) {
24332433
// these objects either have specialing handling
@@ -2532,7 +2532,7 @@ FORCE_INLINE void gc_mark_outrefs(jl_ptls_t ptls, jl_gc_markqueue_t *mq, void *_
25322532
objprofile_count(jl_string_type, bits == GC_OLD_MARKED, dtsz);
25332533
}
25342534
else {
2535-
jl_datatype_t *vt = small_typeof[vtag / sizeof(*small_typeof)];
2535+
jl_datatype_t *vt = ijl_small_typeof[vtag / sizeof(*ijl_small_typeof)];
25362536
size_t dtsz = jl_datatype_size(vt);
25372537
if (update_meta)
25382538
gc_setmark(ptls, o, bits, dtsz);

src/jltypes.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extern "C" {
2020
#endif
2121

2222
_Atomic(jl_value_t*) cmpswap_names JL_GLOBALLY_ROOTED;
23-
jl_datatype_t *small_typeof[(jl_max_tags << 4) / sizeof(*small_typeof)]; // 16-bit aligned, like the GC
23+
jl_datatype_t *ijl_small_typeof[(jl_max_tags << 4) / sizeof(*ijl_small_typeof)]; // 16-bit aligned, like the GC
2424

2525
// compute empirical max-probe for a given size
2626
#define max_probe(size) ((size) <= 1024 ? 16 : (size) >> 6)
@@ -2529,19 +2529,13 @@ static jl_tvar_t *tvar(const char *name)
25292529
(jl_value_t*)jl_any_type);
25302530
}
25312531

2532-
void export_small_typeof(void)
2532+
void export_jl_small_typeof(void)
25332533
{
2534-
void *copy;
2535-
#ifdef _OS_WINDOWS_
2536-
jl_dlsym(jl_libjulia_handle, "small_typeof", &copy, 1);
2537-
#else
2538-
jl_dlsym(jl_libjulia_internal_handle, "small_typeof", &copy, 1);
2539-
#endif
2540-
memcpy(copy, &small_typeof, sizeof(small_typeof));
2534+
memcpy(&jl_small_typeof, &ijl_small_typeof, sizeof(jl_small_typeof));
25412535
}
25422536

25432537
#define XX(name) \
2544-
small_typeof[(jl_##name##_tag << 4) / sizeof(*small_typeof)] = jl_##name##_type; \
2538+
ijl_small_typeof[(jl_##name##_tag << 4) / sizeof(*ijl_small_typeof)] = jl_##name##_type; \
25452539
jl_##name##_type->smalltag = jl_##name##_tag;
25462540
void jl_init_types(void) JL_GC_DISABLED
25472541
{
@@ -3363,7 +3357,8 @@ void jl_init_types(void) JL_GC_DISABLED
33633357

33643358
// override the preferred layout for a couple types
33653359
jl_lineinfonode_type->name->mayinlinealloc = 0; // FIXME: assumed to be a pointer by codegen
3366-
export_small_typeof();
3360+
3361+
export_jl_small_typeof();
33673362
}
33683363

33693364
static jl_value_t *core(const char *name)
@@ -3444,7 +3439,8 @@ void post_boot_hooks(void)
34443439
}
34453440
}
34463441
}
3447-
export_small_typeof();
3442+
3443+
export_jl_small_typeof();
34483444
}
34493445

34503446
void post_image_load_hooks(void) {

src/julia.expmap.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
ios_*;
88
arraylist_grow;
99
small_arraylist_grow;
10-
small_typeof;
1110
jl_*;
1211
ijl_*;
1312
_jl_mutex_*;

src/julia.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ typedef struct {
741741
/* XX(slotnumber) */ \
742742
/* XX(ssavalue) */ \
743743
/* end of JL_SMALL_TYPEOF */
744-
enum jlsmall_typeof_tags {
744+
enum jl_small_typeof_tags {
745745
jl_null_tag = 0,
746746
#define XX(name) jl_##name##_tag,
747747
JL_SMALL_TYPEOF(XX)
@@ -750,13 +750,23 @@ enum jlsmall_typeof_tags {
750750
jl_bitstags_first = jl_char_tag, // n.b. bool is not considered a bitstype, since it can be compared by pointer
751751
jl_max_tags = 64
752752
};
753-
extern jl_datatype_t *small_typeof[(jl_max_tags << 4) / sizeof(jl_datatype_t*)];
753+
extern JL_DLLIMPORT jl_datatype_t *jl_small_typeof[(jl_max_tags << 4) / sizeof(jl_datatype_t*)];
754+
#ifndef JL_LIBRARY_EXPORTS_INTERNAL
754755
static inline jl_value_t *jl_to_typeof(uintptr_t t)
755756
{
756757
if (t < (jl_max_tags << 4))
757-
return (jl_value_t*)small_typeof[t / sizeof(*small_typeof)];
758+
return (jl_value_t*)jl_small_typeof[t / sizeof(*jl_small_typeof)];
758759
return (jl_value_t*)t;
759760
}
761+
#else
762+
extern JL_HIDDEN jl_datatype_t *ijl_small_typeof[(jl_max_tags << 4) / sizeof(jl_datatype_t*)];
763+
static inline jl_value_t *jl_to_typeof(uintptr_t t)
764+
{
765+
if (t < (jl_max_tags << 4))
766+
return (jl_value_t*)ijl_small_typeof[t / sizeof(*ijl_small_typeof)];
767+
return (jl_value_t*)t;
768+
}
769+
#endif
760770

761771

762772
// kinds

src/processor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ static inline jl_image_t parse_sysimg(void *hdl, F &&callback)
812812
*tls_offset_idx = (uintptr_t)(jl_tls_offset == -1 ? 0 : jl_tls_offset);
813813
}
814814

815-
res.small_typeof = pointers->small_typeof;
815+
res.jl_small_typeof = pointers->jl_small_typeof;
816816

817817
return res;
818818
}

src/processor.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ typedef struct {
8888
const int32_t *gvars_offsets;
8989
uint32_t ngvars;
9090
jl_image_fptrs_t fptrs;
91-
void **small_typeof;
91+
void **jl_small_typeof;
9292
} jl_image_t;
9393

9494
// The header for each image
@@ -197,8 +197,8 @@ typedef struct {
197197
const jl_image_shard_t *shards; // points to header->nshards length array
198198
// The TLS data pointer
199199
const jl_image_ptls_t *ptls;
200-
// A copy of small_typeof[]
201-
void **small_typeof;
200+
// A copy of jl_small_typeof[]
201+
void **jl_small_typeof;
202202

203203
// serialized target data
204204
// This contains the number of targets

src/staticdata.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,7 +1985,7 @@ static void jl_update_all_fptrs(jl_serializer_state *s, jl_image_t *image)
19851985
if (fvars.base == NULL)
19861986
return;
19871987

1988-
memcpy(image->small_typeof, &small_typeof, sizeof(small_typeof));
1988+
memcpy(image->jl_small_typeof, &jl_small_typeof, sizeof(jl_small_typeof));
19891989

19901990
int img_fvars_max = s->fptr_record->size / sizeof(void*);
19911991
size_t i;
@@ -2839,7 +2839,7 @@ JL_DLLEXPORT void jl_set_sysimg_so(void *handle)
28392839
#endif
28402840

28412841
extern void rebuild_image_blob_tree(void);
2842-
extern void export_small_typeof(void);
2842+
extern void export_jl_small_typeof(void);
28432843

28442844
static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl_array_t *depmods, uint64_t checksum,
28452845
/* outputs */ jl_array_t **restored, jl_array_t **init_order,
@@ -2915,10 +2915,10 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl
29152915
*tag = jl_read_value(&s);
29162916
}
29172917
#define XX(name) \
2918-
small_typeof[(jl_##name##_tag << 4) / sizeof(*small_typeof)] = jl_##name##_type;
2918+
ijl_small_typeof[(jl_##name##_tag << 4) / sizeof(*ijl_small_typeof)] = jl_##name##_type;
29192919
JL_SMALL_TYPEOF(XX)
29202920
#undef XX
2921-
export_small_typeof();
2921+
export_jl_small_typeof();
29222922
jl_global_roots_table = (jl_array_t*)jl_read_value(&s);
29232923
// set typeof extra-special values now that we have the type set by tags above
29242924
jl_astaggedvalue(jl_nothing)->header = (uintptr_t)jl_nothing_type | jl_astaggedvalue(jl_nothing)->header;

test/embedding/embedding.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ int main()
192192
checked_eval_string("f28825()");
193193
}
194194

195+
{
196+
// jl_typeof works (#50714)
197+
jl_value_t *v = checked_eval_string("sqrt(2.0)");
198+
jl_value_t *t = jl_typeof(v);
199+
}
200+
195201
JL_TRY {
196202
jl_error("exception thrown");
197203
}

0 commit comments

Comments
 (0)