@@ -815,7 +815,7 @@ static jl_cgval_t emit_cglobal(jl_value_t **args, size_t nargs, jl_codectx_t *ct
815
815
msg << sym.f_name ;
816
816
if (sym.f_lib != NULL ) {
817
817
#ifdef _OS_WINDOWS_
818
- assert (( intptr_t ) sym.f_lib != 1 && ( intptr_t ) sym.f_lib != 2 );
818
+ assert (sym.f_lib != JL_EXE_LIBNAME && sym.f_lib != JL_DL_LIBNAME );
819
819
#endif
820
820
msg << " in library " ;
821
821
msg << sym.f_lib ;
@@ -1584,10 +1584,24 @@ static jl_cgval_t emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
1584
1584
if (rt != args[2 ] && rt != (jl_value_t *)jl_any_type)
1585
1585
jl_add_method_root (ctx, rt);
1586
1586
1587
+ auto _is_libjulia_func = [&] (uintptr_t ptr, const char *name) {
1588
+ if ((uintptr_t )fptr == ptr)
1589
+ return true ;
1590
+ return (!f_lib || f_lib == JL_DL_LIBNAME) && f_name && !strcmp (f_name, name);
1591
+ };
1592
+ #define is_libjulia_func (name ) _is_libjulia_func((uintptr_t )&(name), #name)
1593
+
1594
+ #ifdef _OS_LINUX_
1595
+ // directly accessing the address of an ifunc can cause linker issue on
1596
+ // some configurations (e.g. AArch64 + -Bsymbolic-functions).
1597
+ static const auto ptls_getter = jl_dlsym_e (jl_dlopen (nullptr , 0 ),
1598
+ " jl_get_ptls_states" );
1599
+ #else
1600
+ static const auto ptls_getter = &jl_get_ptls_states;
1601
+ #endif
1602
+
1587
1603
// some special functions
1588
- if (fptr == (void (*)(void ))&jl_array_ptr ||
1589
- ((f_lib==NULL || (intptr_t )f_lib==2 )
1590
- && f_name && !strcmp (f_name," jl_array_ptr" ))) {
1604
+ if (is_libjulia_func (jl_array_ptr)) {
1591
1605
assert (lrt->isPointerTy ());
1592
1606
assert (!isVa && !llvmcall);
1593
1607
assert (nargt==1 );
@@ -1598,9 +1612,7 @@ static jl_cgval_t emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
1598
1612
return mark_or_box_ccall_result (emit_bitcast (emit_arrayptr (ary, ctx), lrt),
1599
1613
retboxed, rt, unionall, static_rt, ctx);
1600
1614
}
1601
- if (fptr == (void (*)(void ))&jl_value_ptr ||
1602
- ((f_lib==NULL || (intptr_t )f_lib==2 )
1603
- && f_name && !strcmp (f_name," jl_value_ptr" ))) {
1615
+ else if (is_libjulia_func (jl_value_ptr)) {
1604
1616
assert (lrt->isPointerTy ());
1605
1617
assert (!isVa && !llvmcall);
1606
1618
assert (nargt==1 );
@@ -1635,18 +1647,14 @@ static jl_cgval_t emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
1635
1647
return mark_or_box_ccall_result (emit_bitcast (ary, lrt),
1636
1648
retboxed, rt, unionall, static_rt, ctx);
1637
1649
}
1638
- if (JL_CPU_WAKE_NOOP &&
1639
- (fptr == &jl_cpu_wake || ((!f_lib || (intptr_t )f_lib == 2 ) &&
1640
- f_name && !strcmp (f_name, " jl_cpu_wake" )))) {
1650
+ else if (JL_CPU_WAKE_NOOP && is_libjulia_func (jl_cpu_wake)) {
1641
1651
assert (lrt == T_void);
1642
1652
assert (!isVa && !llvmcall);
1643
1653
assert (nargt == 0 );
1644
1654
JL_GC_POP ();
1645
1655
return ghostValue (jl_void_type);
1646
1656
}
1647
- if (fptr == &jl_gc_safepoint ||
1648
- ((!f_lib || (intptr_t )f_lib == 2 ) && f_name &&
1649
- strcmp (f_name, " jl_gc_safepoint" ) == 0 )) {
1657
+ else if (is_libjulia_func (jl_gc_safepoint)) {
1650
1658
assert (lrt == T_void);
1651
1659
assert (!isVa && !llvmcall);
1652
1660
assert (nargt == 0 );
@@ -1657,17 +1665,7 @@ static jl_cgval_t emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
1657
1665
emit_signal_fence ();
1658
1666
return ghostValue (jl_void_type);
1659
1667
}
1660
- #ifdef _OS_LINUX_
1661
- // directly access the address of a ifunc can cause linker issue on
1662
- // some configurations (e.g. AArch64 + -Bsymbolic-functions).
1663
- static const auto ptls_getter = jl_dlsym_e (jl_dlopen (nullptr , 0 ),
1664
- " jl_get_ptls_states" );
1665
- #else
1666
- static const auto ptls_getter = &jl_get_ptls_states;
1667
- #endif
1668
- if (fptr == (void (*)(void ))(uintptr_t )ptls_getter ||
1669
- ((!f_lib || (intptr_t )f_lib == 2 ) && f_name &&
1670
- strcmp (f_name, " jl_get_ptls_states" ) == 0 )) {
1668
+ else if (_is_libjulia_func ((uintptr_t )ptls_getter, " jl_get_ptls_states" )) {
1671
1669
assert (lrt == T_pint8);
1672
1670
assert (!isVa && !llvmcall);
1673
1671
assert (nargt == 0 );
@@ -1676,9 +1674,7 @@ static jl_cgval_t emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
1676
1674
emit_bitcast (ctx->ptlsStates , lrt),
1677
1675
retboxed, rt, unionall, static_rt, ctx);
1678
1676
}
1679
- if (fptr == (void (*)(void ))&jl_threadid ||
1680
- ((!f_lib || (intptr_t )f_lib == 2 ) && f_name &&
1681
- strcmp (f_name, " jl_threadid" ) == 0 )) {
1677
+ else if (is_libjulia_func (jl_threadid)) {
1682
1678
assert (lrt == T_int16);
1683
1679
assert (!isVa && !llvmcall);
1684
1680
assert (nargt == 0 );
@@ -1690,9 +1686,7 @@ static jl_cgval_t emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
1690
1686
tbaa_decorate (tbaa_const, builder.CreateLoad (ptid)),
1691
1687
retboxed, rt, unionall, static_rt, ctx);
1692
1688
}
1693
- if (fptr == &jl_sigatomic_begin ||
1694
- ((!f_lib || (intptr_t )f_lib == 2 ) && f_name &&
1695
- strcmp (f_name, " jl_sigatomic_begin" ) == 0 )) {
1689
+ else if (is_libjulia_func (jl_sigatomic_begin)) {
1696
1690
assert (lrt == T_void);
1697
1691
assert (!isVa && !llvmcall);
1698
1692
assert (nargt == 0 );
@@ -1706,9 +1700,7 @@ static jl_cgval_t emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
1706
1700
emit_signal_fence ();
1707
1701
return ghostValue (jl_void_type);
1708
1702
}
1709
- if (fptr == &jl_sigatomic_end ||
1710
- ((!f_lib || (intptr_t )f_lib == 2 ) && f_name &&
1711
- strcmp (f_name, " jl_sigatomic_end" ) == 0 )) {
1703
+ else if (is_libjulia_func (jl_sigatomic_end)) {
1712
1704
assert (lrt == T_void);
1713
1705
assert (!isVa && !llvmcall);
1714
1706
assert (nargt == 0 );
@@ -1737,9 +1729,7 @@ static jl_cgval_t emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
1737
1729
builder.SetInsertPoint (contBB);
1738
1730
return ghostValue (jl_void_type);
1739
1731
}
1740
- if (fptr == (void (*)(void ))&jl_is_leaf_type ||
1741
- ((f_lib==NULL || (intptr_t )f_lib==2 )
1742
- && f_name && !strcmp (f_name, " jl_is_leaf_type" ))) {
1732
+ else if (is_libjulia_func (jl_is_leaf_type)) {
1743
1733
assert (nargt == 1 );
1744
1734
assert (!isVa && !llvmcall);
1745
1735
jl_value_t *arg = args[4 ];
@@ -1751,9 +1741,7 @@ static jl_cgval_t emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
1751
1741
false , rt, unionall, static_rt, ctx);
1752
1742
}
1753
1743
}
1754
- if (fptr == (void (*)(void ))&jl_function_ptr ||
1755
- ((f_lib==NULL || (intptr_t )f_lib==2 )
1756
- && f_name && !strcmp (f_name, " jl_function_ptr" ))) {
1744
+ else if (is_libjulia_func (jl_function_ptr)) {
1757
1745
assert (nargt == 3 );
1758
1746
assert (!isVa && !llvmcall);
1759
1747
jl_value_t *f = static_eval (args[4 ], ctx, false , false );
@@ -1797,10 +1785,8 @@ static jl_cgval_t emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
1797
1785
}
1798
1786
JL_GC_POP ();
1799
1787
}
1800
- if ((fptr == (void (*)(void ))&jl_array_isassigned ||
1801
- ((f_lib==NULL || (intptr_t )f_lib==2 )
1802
- && f_name && !strcmp (f_name, " jl_array_isassigned" ))) &&
1803
- expr_type (args[6 ], ctx) == (jl_value_t *)jl_ulong_type) {
1788
+ else if (is_libjulia_func (jl_array_isassigned) &&
1789
+ expr_type (args[6 ], ctx) == (jl_value_t *)jl_ulong_type) {
1804
1790
assert (nargt == 2 );
1805
1791
jl_value_t *aryex = args[4 ];
1806
1792
jl_value_t *idxex = args[6 ];
@@ -2053,7 +2039,7 @@ jl_cgval_t function_sig_t::emit_a_ccall(
2053
2039
msg << symarg.f_name ;
2054
2040
if (symarg.f_lib != NULL ) {
2055
2041
#ifdef _OS_WINDOWS_
2056
- assert (( intptr_t ) symarg.f_lib != 1 && ( intptr_t ) symarg.f_lib != 2 );
2042
+ assert (symarg.f_lib != JL_EXE_LIBNAME && symarg.f_lib != JL_DL_LIBNAME );
2057
2043
#endif
2058
2044
msg << " in library " ;
2059
2045
msg << symarg.f_lib ;
0 commit comments