Skip to content

Commit 1e24c2e

Browse files
committed
trimming: Add _uv_hook_close support (#58871)
Resolves #58862. Since this hook is called internally by the runtime, `--trim` was not aware of the callee edge required here.
1 parent c37ee51 commit 1e24c2e

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

base/libuv.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,15 @@ macro handle_as(hand, typ)
3939
end
4040
end
4141

42-
@nospecializeinfer associate_julia_struct(handle::Ptr{Cvoid}, @nospecialize(jlobj)) =
42+
function _uv_hook_close end
43+
44+
function associate_julia_struct(handle::Ptr{Cvoid}, jlobj::T) where T
45+
# This `cfunction` is not used anywhere, but it triggers compilation of this
46+
# MethodInstance for `--trim` so that it will be available when dispatched to
47+
# by `jl_uv_call_close_callback()`
48+
_ = @cfunction(Base._uv_hook_close, Cvoid, (Ref{T},))
4349
ccall(:jl_uv_associate_julia_struct, Cvoid, (Ptr{Cvoid}, Any), handle, jlobj)
50+
end
4451
disassociate_julia_struct(uv) = disassociate_julia_struct(uv.handle)
4552
disassociate_julia_struct(handle::Ptr{Cvoid}) =
4653
handle != C_NULL && ccall(:jl_uv_disassociate_julia_struct, Cvoid, (Ptr{Cvoid},), handle)

src/staticdata.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,8 @@ static void jl_queue_module_for_serialization(jl_serializer_state *s, jl_module_
732732
!strcmp(jl_symbol_name(b->globalref->name), "__init__") ||
733733
// ... or point to Base functions accessed by the runtime
734734
(m == jl_base_module && (!strcmp(jl_symbol_name(b->globalref->name), "wait") ||
735-
!strcmp(jl_symbol_name(b->globalref->name), "task_done_hook"))))) {
735+
!strcmp(jl_symbol_name(b->globalref->name), "task_done_hook") ||
736+
!strcmp(jl_symbol_name(b->globalref->name), "_uv_hook_close"))))) {
736737
jl_queue_for_serialization(s, b);
737738
}
738739
}

test/trimming/basic_jll.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ function @main(args::Vector{String})::Cint
1818
println(Core.stdout, ver)
1919
@assert ver == build_ver
2020

21+
sleep(0.01)
22+
2123
# Add an indirection via `@cfunction` / 1-arg ccall
2224
cfunc = @cfunction(print_string, Cvoid, (Ptr{Cvoid},))
2325
fptr = dlsym(Zstd_jll.libzstd_handle, :ZSTD_versionString)

0 commit comments

Comments
 (0)