From a355403080167056d2af4ccee8eadfffd8fce97f Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Thu, 31 Aug 2023 06:41:11 +0000 Subject: [PATCH 1/2] Annotate fieldnames for default cgparams [NFC] --- src/codegen.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index a582a1e7aeaa4..b2950f7f18557 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -1351,17 +1351,22 @@ static const auto jl_new_opaque_closure_jlcall_func = new JuliaFunction<>{XSTR(j static _Atomic(uint64_t) globalUniqueGeneratedNames{1}; // --- code generation --- + extern "C" { - jl_cgparams_t jl_default_cgparams = {1, 1, 0, + jl_cgparams_t jl_default_cgparams = { + /* track_allocations */ 1, + /* code_coverage */ 1, + /* prefer_specsig */ 0, #ifdef _OS_WINDOWS_ - 0, + /* gnu_pubnames */ 0, #else - 1, + /* gnu_pubnames */ 1, #endif - (int) DICompileUnit::DebugEmissionKind::FullDebug, - 1, - 1, - jl_rettype_inferred_addr, NULL }; + /* debug_info_kind */ (int) DICompileUnit::DebugEmissionKind::FullDebug, + /* safepoint_on_entry */ 1, + /* gcstack_arg */ 1, + /* lookup */ jl_rettype_inferred_addr, + /* generic_context */ NULL }; } From e118207d2fa6717bae37dc8090f561c64af296d5 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Thu, 31 Aug 2023 07:08:32 +0000 Subject: [PATCH 2/2] Add a codegen option to disable use of jlplts Alternative to #51108. --- base/reflection.jl | 5 +++-- src/ccall.cpp | 8 ++++++++ src/codegen.cpp | 1 + src/julia.h | 2 ++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/base/reflection.jl b/base/reflection.jl index ffd3882bf74ab..62e77fe3fb630 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -1219,6 +1219,7 @@ struct CodegenParams debug_info_kind::Cint safepoint_on_entry::Cint gcstack_arg::Cint + use_jlplt::Cint lookup::Ptr{Cvoid} @@ -1228,7 +1229,7 @@ struct CodegenParams prefer_specsig::Bool=false, gnu_pubnames=true, debug_info_kind::Cint = default_debug_info_kind(), safepoint_on_entry::Bool=true, - gcstack_arg::Bool=true, + gcstack_arg::Bool=true, use_jlplt::Bool=true, lookup::Ptr{Cvoid}=unsafe_load(cglobal(:jl_rettype_inferred_addr, Ptr{Cvoid})), generic_context = nothing) return new( @@ -1236,7 +1237,7 @@ struct CodegenParams Cint(prefer_specsig), Cint(gnu_pubnames), debug_info_kind, Cint(safepoint_on_entry), - Cint(gcstack_arg), + Cint(gcstack_arg), Cint(use_jlplt), lookup, generic_context) end end diff --git a/src/ccall.cpp b/src/ccall.cpp index 8c1cd132d06f5..1add621edde28 100644 --- a/src/ccall.cpp +++ b/src/ccall.cpp @@ -2077,6 +2077,14 @@ jl_cgval_t function_sig_t::emit_a_ccall( if (ctx.emission_context.imaging_mode) jl_printf(JL_STDERR,"WARNING: literal address used in ccall for %s; code cannot be statically compiled\n", symarg.f_name); } + else if (!ctx.params->use_jlplt) { + if ((symarg.f_lib && !((symarg.f_lib == JL_EXE_LIBNAME) || + (symarg.f_lib == JL_LIBJULIA_INTERNAL_DL_LIBNAME) || + (symarg.f_lib == JL_LIBJULIA_DL_LIBNAME))) || symarg.lib_expr) { + emit_error(ctx, "ccall: Had library expression, but symbol lookup was disabled"); + } + llvmf = jl_Module->getOrInsertFunction(symarg.f_name, functype).getCallee(); + } else { assert(symarg.f_name != NULL); PointerType *funcptype = PointerType::get(functype, 0); diff --git a/src/codegen.cpp b/src/codegen.cpp index b2950f7f18557..53b28340fcdee 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -1365,6 +1365,7 @@ extern "C" { /* debug_info_kind */ (int) DICompileUnit::DebugEmissionKind::FullDebug, /* safepoint_on_entry */ 1, /* gcstack_arg */ 1, + /* use_jlplt*/ 1, /* lookup */ jl_rettype_inferred_addr, /* generic_context */ NULL }; } diff --git a/src/julia.h b/src/julia.h index a96b4a1f5e562..b6b4525c5d412 100644 --- a/src/julia.h +++ b/src/julia.h @@ -2354,6 +2354,8 @@ typedef struct { int safepoint_on_entry; // Emit a safepoint on entry to each function int gcstack_arg; // Pass the ptls value as an argument with swiftself + int use_jlplt; // Whether to use the Julia PLT mechanism or emit symbols directly + // Cache access. Default: jl_rettype_inferred. jl_codeinstance_lookup_t lookup;