Clemapfel / jluna

Julia Wrapper for C++ with Focus on Safety, Elegance, and Ease of Use
https://clemens-cords.com/jluna
MIT License
250 stars 13 forks source link

Warnings generated #40

Closed jkammerland closed 1 year ago

jkammerland commented 1 year ago

with GCC 12 and clang 15 the code

initialize();
Base["println"]("hello julia");

/// declare function
Main.safe_eval("f(x) = x^x");

// bind function to C++-side variable
auto f = Main.safe_eval("return f");

// call function
Int64 result = f(3);

// print result
std::cout << result << std::endl;

return 0;

Produce these warnings before program output:

warning: copy relocation against non-copyable protected symbol `jl_int32_type' in `/home/jonkam/Programmering/julia/julia-1.8.5-linux-x86_64/julia-1.8.5/lib/libjulia.so.1'
warning: copy relocation against non-copyable protected symbol `jl_float32_type' in `/home/jonkam/Programmering/julia/julia-1.8.5-linux-x86_64/julia-1.8.5/lib/libjulia.so.1'
warning: copy relocation against non-copyable protected symbol `jl_float64_type' in `/home/jonkam/Programmering/julia/julia-1.8.5-linux-x86_64/julia-1.8.5/lib/libjulia.so.1'
warning: copy relocation against non-copyable protected symbol `jl_int64_type' in `/home/jonkam/Programmering/julia/julia-1.8.5-linux-x86_64/julia-1.8.5/lib/libjulia.so.1'
warning: copy relocation against non-copyable protected symbol `jl_base_module' in `/home/jonkam/Programmering/julia/julia-1.8.5-linux-x86_64/julia-1.8.5/lib/libjulia.so.1'
warning: copy relocation against non-copyable protected symbol `jl_bool_type' in `/home/jonkam/Programmering/julia/julia-1.8.5-linux-x86_64/julia-1.8.5/lib/libjulia.so.1'
warning: copy relocation against non-copyable protected symbol `jl_uint64_type' in `/home/jonkam/Programmering/julia/julia-1.8.5-linux-x86_64/julia-1.8.5/lib/libjulia.so.1'
warning: copy relocation against non-copyable protected symbol `jl_uint16_type' in `/home/jonkam/Programmering/julia/julia-1.8.5-linux-x86_64/julia-1.8.5/lib/libjulia.so.1'
warning: copy relocation against non-copyable protected symbol `jl_int16_type' in `/home/jonkam/Programmering/julia/julia-1.8.5-linux-x86_64/julia-1.8.5/lib/libjulia.so.1'
warning: copy relocation against non-copyable protected symbol `jl_float16_type' in `/home/jonkam/Programmering/julia/julia-1.8.5-linux-x86_64/julia-1.8.5/lib/libjulia.so.1'
warning: copy relocation against non-copyable protected symbol `jl_uint32_type' in `/home/jonkam/Programmering/julia/julia-1.8.5-linux-x86_64/julia-1.8.5/lib/libjulia.so.1'
warning: copy relocation against non-copyable protected symbol `jl_int8_type' in `/home/jonkam/Programmering/julia/julia-1.8.5-linux-x86_64/julia-1.8.5/lib/libjulia.so.1'
warning: copy relocation against non-copyable protected symbol `jl_uint8_type' in `/home/jonkam/Programmering/julia/julia-1.8.5-linux-x86_64/julia-1.8.5/lib/libjulia.so.1'
warning: copy relocation against non-copyable protected symbol `jl_char_type' in `/home/jonkam/Programmering/julia/julia-1.8.5-linux-x86_64/julia-1.8.5/lib/libjulia.so.1'
[JULIA][LOG] initialization successful (1 thread(s)).
hello julia
27

Process finished with exit code 0

Do I need to add some compiler flags ?

Clemapfel commented 1 year ago

I can reproduce this on master, this is related to a C-API change in Julia 1.8+, warning does not appear with the 1.7.x releases.

I'll investigate but I don't think this hints at an actual bug, it's just bad practice to force the copy of the isbitstype types, which I assume are statically allocated and shouldn't be copied

Clemapfel commented 1 year ago

MWE:

int main()
{
    jl_init();
    jl_value_t* proxy = jl_nothing;
    return 0;
}
warning: copy relocation against non-copyable protected symbol `jl_nothing' in `/lib64/libjulia.so.1'
Process finished with exit code 0

This has nothing to do with jluna, I'll open an issue on the Julia GitHub on how to avoid this, this assignment doesn't feel like it should cause a warning.

Clemapfel commented 1 year ago

c.f. https://github.com/JuliaLang/julia/issues/48699

Clemapfel commented 1 year ago

Adding

target_compile_options(<your_executable> PRIVATE "-fpic")

Fixed it for me. Can you confirm this? <your_executable> is your library or executable in your own CMakeLists.txt, not jluna.

Clemapfel commented 1 year ago

Fixed by https://github.com/Clemapfel/jluna/pull/39/commits/4c21434b965567223687585e0c9839d521a8a92a

I merged it into the 1.0.0 PR because I want to test this on another machine, I'm not positive that -fpic is supported by all compiler versions

jkammerland commented 1 year ago

Indeed it resolves the warning output, only tested for gcc 12.2 and clang 15. I think the support for this flag go back quite far for gcc, clang and icc. Not sure about msvc though. Doesn't seem like code is generated the same way for windows "shared libraries", so there may not be an equivalent flag.

Thanks for help and great library btw!

Clemapfel commented 1 year ago

Thank you for confirming, I added a section to the troubleshooting section, c.f. https://github.com/Clemapfel/jluna/commit/e55427170f5e3a695669926895753600bdaaeef2