I built a system image file with a new function printHello
function printHello()
println("Hello World!")
end
I used the --compile=all --output-bc
flags in the build_sysimg.jl
to generate the system image in llvm bitcode format sys-hello.bc
. I use this bitcode system image file to start julia and set compile to “no” julia -J sys-hello.bc --compile=no
(so that I am informed if any expression needs to be compiled from the REPL) and then run the printHello()
function in REPL. This works and I am under the impression that for running the printHello
function julia did not have to compile anything and used the bitcode of that function julia_printHello_<some numbers>
to get the native IR and run it.
However, even if I go ahead and remove everything from this function, I still get the correct output.
Is Julia still dynamically compiling the printHello function from the AST? Is the LLVM bitcode generated in sys-hello.bc
of any use, or only the binary blob containing the AST matters?
PS: This is in relation to my effort to get LLVM IR of my function in Julia and being able to make changes to it, which are eventually reflected in the output. A related topic is here
Update: April 14 2017 12:10pm CST: I see now that the command julia -J sys-hello.bc --compile=no
does not even look for the file sys-hello.bc. Instead it looks for sys-hello.so in its place and uses it. I am not sure how is this helpful. The application should be more transparent about this. Just display the error that this is not a sys image file if we cannot use it, rather than having the user believe that he/she is using a file which he/she is not.
Instead it looks for sys-hello.so in its place and uses it. I am not sure how is this helpful
I agree. We seem to have been looking at the same thing yesterday: make jl_init more friendly to embedded targets by vtjnash · Pull Request #21365 · JuliaLang/julia · GitHub
To address the question in the title, yes that’s the complete IR (intermediate representation). To actually use this, you need to finish compiling and linking it (to a shared library representation). I only mentioned this very briefly in a footnote of my on the rest of the process: https://juliacomputing.com/blog/2016/02/09/static-julia.html#supplemental-tools
In particular, you’ll want to pass the .bc
file to llc
or clang
to turn into a .so
file that the dynamic linker can load.
Thanks. Yes that looks like the the way forward. However, when using clang 3.7 to build a shared library it gives the error fatal error: error in backend: Cannot generate unaligned atomic store
This is generated by load/store atomic
statements on i128
types with byte alignment statements such as the one in the following code
define internal void @"julia_setindex!_53289"(%jl_value_t*, i128) #4 {
top:
call void @llvm.dbg.value(metadata %jl_value_t* null, i64 0, metadata !272997, metadata !846405), !dbg !918393
call void @llvm.dbg.value(metadata %jl_value_t* %0, i64 0, metadata !272997, metadata !846405), !dbg !918393
call void @llvm.dbg.value(metadata i128 %1, i64 0, metadata !272998, metadata !846354), !dbg !918393
%2 = bitcast %jl_value_t* %0 to i128*, !dbg !918393
store atomic i128 %1, i128* %2 release, align 8, !dbg !918393
ret void, !dbg !918393
}
Should I start this as a separate topic?
Are you on 0.5? This should be fixed by https://github.com/JuliaLang/julia/pull/19482 on 0.6. Also make sure that you use the same version of llc
as Julia does.
Yes, I am using the release-0.5 branch, and after fixing the alignment issues I am able to compile the bitcode to .so. But when I try to load it as a Julia system image file, it says System Image file not found
.
Here is the command
clang -fPIC -shared -o sys-hello.so sys-hello.bc -ljulia -L ~/Utilities/julia-src/install/release-0.5/lib
I am using llvm and clang 3.7
I can confirm that the same is true if I use the latest commit on master (eee75d1) and clang 3.9. If I try to compile the generated bitcode file of system image to .so with the above command, julia instance does not recognize it as a system image.