Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defining non-existent function in another module via GlobalRef segfaults code loading #40698

Closed
simeonschaub opened this issue May 3, 2021 · 2 comments
Labels
bug Indicates an unexpected problem or unintended behavior compiler:precompilation Precompilation of modules

Comments

@simeonschaub
Copy link
Member

MWE is two packages Foo and Bar, with Bar depending on Foo.

in src/Foo.jl:

module Foo

macro foo()
    return :($(GlobalRef(Foo, :bar))() = 1)
end

end

in src/Bar.jl:

module Bar

using Foo: @foo

@foo

end

Precompiling and then loading Bar results in a segfault:

(Bar) pkg> precompile
Precompiling project...
  2 dependencies successfully precompiled in 2 seconds

julia> using Bar

signal (11): Segmentation fault
in expression starting at REPL[9]:1
jl_unwrap_unionall at /buildworker/worker/package_linux64/build/src/jltypes.c:959
jl_deserialize_datatype at /buildworker/worker/package_linux64/build/src/dump.c:1241 [inlined]
jl_deserialize_value at /buildworker/worker/package_linux64/build/src/dump.c:1885
jl_deserialize_value_svec at /buildworker/worker/package_linux64/build/src/dump.c:1354 [inlined]
jl_deserialize_value at /buildworker/worker/package_linux64/build/src/dump.c:1793
jl_deserialize_datatype at /buildworker/worker/package_linux64/build/src/dump.c:1243 [inlined]
jl_deserialize_value at /buildworker/worker/package_linux64/build/src/dump.c:1885
jl_deserialize_value_method at /buildworker/worker/package_linux64/build/src/dump.c:1457 [inlined]
jl_deserialize_value at /buildworker/worker/package_linux64/build/src/dump.c:1830
jl_deserialize_value_array at /buildworker/worker/package_linux64/build/src/dump.c:1411
jl_deserialize_value at /buildworker/worker/package_linux64/build/src/dump.c:1799
_jl_restore_incremental at /buildworker/worker/package_linux64/build/src/dump.c:2590
jl_restore_incremental at /buildworker/worker/package_linux64/build/src/dump.c:2655
_include_from_serialized at ./loading.jl:658
_require_search_from_serialized at ./loading.jl:760
_require at ./loading.jl:998
require at ./loading.jl:914
require at ./loading.jl:901
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2243 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2425
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1764 [inlined]
call_require at /buildworker/worker/package_linux64/build/src/toplevel.c:425 [inlined]
eval_import_path at /buildworker/worker/package_linux64/build/src/toplevel.c:462
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:688
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:829
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:829
jl_toplevel_eval_in at /buildworker/worker/package_linux64/build/src/toplevel.c:936
eval at ./boot.jl:369 [inlined]
eval_user_input at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:139
repl_backend_loop at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:200
start_repl_backend at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:185
#run_repl#43 at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:318
run_repl at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:305
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2243 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2425
#892 at ./client.jl:394
jfptr_YY.892_24947.clone_1 at /home/simeon/packages/julias/julia-latest/lib/julia/sys.so (unknown line)
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2243 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2425
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1764 [inlined]
jl_f__call_latest at /buildworker/worker/package_linux64/build/src/builtins.c:751
#invokelatest#2 at ./essentials.jl:726 [inlined]
invokelatest at ./essentials.jl:724 [inlined]
run_main_repl at ./client.jl:379
exec_options at ./client.jl:309
_start at ./client.jl:495
jfptr__start_34359.clone_1 at /home/simeon/packages/julias/julia-latest/lib/julia/sys.so (unknown line)
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2243 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2425
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1764 [inlined]
true_main at /buildworker/worker/package_linux64/build/src/jlapi.c:560
repl_entrypoint at /buildworker/worker/package_linux64/build/src/jlapi.c:702
main at julia-latest (unknown line)
__libc_start_main at /usr/lib/libc.so.6 (unknown line)
unknown function (ip: 0x4007d8)
Allocations: 8185298 (Pool: 8182846; Big: 2452); GC: 10
zsh: segmentation fault (core dumped)  julia-latest --project

This is fixed by defining function bar end in the module Foo. Is there any way to at least make this not segfault? In general, defining non-existent functions in other modules via GlobalRef seems to work just fine, it's only serialization that's not happy:

julia> module Foo end
Main.Foo

julia> @eval $(GlobalRef(Foo, :bar))() = 1
bar (generic function with 1 method)

julia> Foo.bar()
1
@simeonschaub simeonschaub added bug Indicates an unexpected problem or unintended behavior compiler:precompilation Precompilation of modules labels May 3, 2021
@timholy
Copy link
Member

timholy commented Mar 3, 2022

Now we need the analog of #43990 for types.

@vtjnash
Copy link
Member

vtjnash commented Jan 24, 2023

dump.c is gone

@vtjnash vtjnash closed this as completed Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior compiler:precompilation Precompilation of modules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants