Compiling Packages to Bitcode with PackageCompiler.jl

Hey everyone,

Am currently trying to compile a bunch of packages with PackageCompiler.jl into bitcode, using Gen.jl as a placeholder package from hereon out.

After looking at a bunch of the documentation, and the doctoring of the create_sysimage function in PackageCompiler.jl, i.e.

function create_sysimage(packages::Union{Symbol, Vector{String}, Vector{Symbol}}=String[];
                         sysimage_path::Union{String,Nothing}=nothing,
                         project::String=dirname(active_project()),
                         precompile_execution_file::Union{String, Vector{String}}=String[],
                         precompile_statements_file::Union{String, Vector{String}}=String[],
                         incremental::Bool=true,
                         filter_stdlibs=false,
                         replace_default::Bool=false,
                         cpu_target::String=NATIVE_CPU_TARGET,
                         script::Union{Nothing, String}=nothing,
                         sysimage_build_args::Cmd=``,
                         include_transitive_dependencies::Bool=true,
                         ...
)

and looking through a number of documentation pages in the Julia docs: Debugging LLVM Transformations in Isolation, as well as a number of past discourse posts 1 & 2, I arrived at

create_sysimage(["Gen"]; sysimage_path="GenSysImage.so", sysimage_build_args=`--output-bc opt.bc`)

after which I tried to verify the bitcode akin to what’s done in Debugging LLVM Transformations in Isolation with llc, i.e.

llc -o sys.o opt.bc

at which I hit the following error:

Error: expected integer
!<arch>

(I hit the same error when I tell PackageCompiler to emit unoptimized bc, and start earlier in the steps when calling opt and invoking the new pass manager)

This leaves me with multiple questions:

  • What am I missing to be able to apply llc as outlined above? Or opt for that matter?
  • Is there a better way to get PackageCompiler.jl to emit bitcode?

Thank you for your time reading this long question :slight_smile:

1 Like

Where did you get llc from?

There is a Julia fork of LLVM:

You can download a build from here:

Just built Julia’s 15.07 llvm-release and tried it with that llc, same error.

../llvm-15-julia/build/bin/llc error: ../llvm-15-julia/build/bin/llc: opt.bc:1:2: error: expected integer
!<arch>

Does anyone maybe have an end-to-end example for Debugging LLVM Transformations in Isolation, or knows of a place/blog/video where one was shown? That would already help a lot.

I.e.

  1. Dummy code
  2. Generating the unopt.bc
  3. Use opt, and use the old/new pass-manager to invoke the Julia-pass, and get the opt.bc
  4. Use llc to get the object-file

I think you need to run ar -x to unpack the bitcofe archive.

1 Like