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

precompile shouldn't try opening dylibs #34061

Closed
KristofferC opened this issue Dec 9, 2019 · 4 comments · Fixed by #34062
Closed

precompile shouldn't try opening dylibs #34061

KristofferC opened this issue Dec 9, 2019 · 4 comments · Fixed by #34062
Labels
compiler:precompilation Precompilation of modules

Comments

@KristofferC
Copy link
Member

KristofferC commented Dec 9, 2019

Running the following:

❯ julia --project -J"/home/kc/Applications/julia-1.3.0/lib/julia/sys.so"  --output-o=sys.o \
 -e 'Base.reinit_stdio(); Base.init_depot_path(); Base.init_load_path(); using Plots'

error with

ERROR: LoadError: error compiling gr_draw_marker: could not load library "libGR.so"
libGR.so: cannot open shared object file: No such file or directory
Stacktrace:
 [1] precompile at ./essentials.jl:463 [inlined]
 [2] _precompile_() at /home/kc/.julia/packages/Plots/2KhB2/src/precompile.jl:3
 [3] top-level scope at /home/kc/.julia/packages/Plots/2KhB2/src/Plots.jl:226

when Plots tries to execute one of the precompile statements in https://github.com/JuliaPlots/Plots.jl/blob/master/src/precompile.jl. The reason it can't find it is because with --output-o the __init__ function doesn't run and GR makes its library availably to Base.DL_LOAD_PATH using that function.

It doesn't seem like precompile should go and try open dynamic libraries at least not in --output-o mode.

@KristofferC KristofferC added the compiler:precompilation Precompilation of modules label Dec 9, 2019
@JeffBezanson
Copy link
Member

I fear we might need to start running __init__ functions during precompile. Otherwise code basically needs to work in two different contexts, which is always going to be brittle.

@StefanKarpinski
Copy link
Member

Can you explain the thumbs down, @vtjnash?

@vtjnash
Copy link
Member

vtjnash commented Dec 9, 2019

It's only thought to be brittle because we don't test this part of codegen well. This bug nothing to do with __init__ or even packages. It's just another instance of this old bug:

bash$ ./julia --output-o=x.o -J usr/lib/julia/sys.dylib -e 'Base.reinit_stdio(); ccall(:does_not_exist, Cvoid, ())'

current result:

signal (11): Segmentation fault: 11
in expression starting at none:1
unknown function (ip: 0x0)
Allocations: 2491 (Pool: 2482; Big: 9); GC: 0
Segmentation fault: 11

expected result:

ERROR: could not load symbol "does_not_exist":
dlsym(RTLD_DEFAULT, does_not_exist): symbol not found
Stacktrace:
 [1] top-level scope at ./none:1

@vchuravy is fixing part of this aspect of codegen in #33820, I'll make a PR shortly to fix this bug.

(I think that reinit_stdio hack there is only needed because we have been forcibly calling __init__ and then not resetting state properly. I'm hoping to get rid of that at some point too.)

@JeffBezanson
Copy link
Member

Yes, it's fine to fix the library lookup part of this independently. The issue with __init__ is more general; people might try to run various top-level expressions that depend on init having run for various reasons. Of course, that might just trade one problem for another, which is that __init__ then needs to be written to handle re-initializing as well as initializing.

KristofferC pushed a commit that referenced this issue Dec 12, 2019
* ccall: report static compile-time load issues correctly

fix #34061

* add a test

* Update ccall.jl
KristofferC pushed a commit that referenced this issue Dec 17, 2019
* ccall: report static compile-time load issues correctly

fix #34061

* add a test

* Update ccall.jl

(cherry picked from commit 8a47793)
KristofferC pushed a commit that referenced this issue Apr 11, 2020
* ccall: report static compile-time load issues correctly

fix #34061

* add a test

* Update ccall.jl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:precompilation Precompilation of modules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants