# Compiling Packages to Bitcode with PackageCompiler.jl

**URL:** https://discourse.julialang.org/t/compiling-packages-to-bitcode-with-packagecompiler-jl/101376
**Category:** General Usage
**Tags:** compilation, package-compiler, bitcode
**Created:** [July 9, 2023, 5:53am UTC](https://discourse.julialang.org/t/compiling-packages-to-bitcode-with-packagecompiler-jl/101376 "2023-07-09T05:53:52Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![ludgerpaehler](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ludgerpaehler/32/32672_2.png) [@ludgerpaehler](https://discourse.julialang.org/u/ludgerpaehler)
#### Post date: [July 9, 2023, 5:53am UTC](https://discourse.julialang.org/t/compiling-packages-to-bitcode-with-packagecompiler-jl/101376/1 "2023-07-09T05:53:52Z")

</div>

Hey everyone,

Am currently trying to compile a bunch of packages with [PackageCompiler.jl](https://github.com/JuliaLang/PackageCompiler.jl) into bitcode, using [Gen.jl](https://github.com/probcomp/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.

```plaintext
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](https://docs.julialang.org/en/v1/devdocs/llvm/#Debugging-LLVM-transformations-in-isolation), as well as a number of past discourse posts [1](https://discourse.julialang.org/t/getting-llvm-bitcode-from-julia-script/15249/3) & [2](https://discourse.julialang.org/t/does-julia-bitcode-system-image-file-generated-with-compile-all-output-bc-flags-actually-use-llvm-ir-representation/3219), I arrived at

```plaintext
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](https://docs.julialang.org/en/v1/devdocs/llvm/#Debugging-LLVM-transformations-in-isolation) with `llc`, i.e.

```bash
llc -o sys.o opt.bc

```

at which I hit the following error:

```bash
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 🙂

---

<div class="post-metadata">

### Author: ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)
#### Post date: [July 9, 2023, 7:30am UTC](https://discourse.julialang.org/t/compiling-packages-to-bitcode-with-packagecompiler-jl/101376/2 "2023-07-09T07:30:27Z")

</div>

Where did you get `llc` from?

There is a Julia fork of LLVM:

> **[GitHub - JuliaLang/llvm-project at julia-release/16.x](https://github.com/JuliaLang/llvm-project/tree/julia-release/16.x)**
>
> julia-release/16.x

You can download a build from here:

> **[GitHub - JuliaBinaryWrappers/LLVM\_full\_jll.jl](https://github.com/JuliaBinaryWrappers/LLVM_full_jll.jl)**
>
> Contribute to JuliaBinaryWrappers/LLVM\_full\_jll.jl development by creating an account on GitHub.

---

<div class="post-metadata">

### Author: ![ludgerpaehler](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ludgerpaehler/32/32672_2.png) [@ludgerpaehler](https://discourse.julialang.org/u/ludgerpaehler)
#### Post date: [July 9, 2023, 8:29pm UTC](https://discourse.julialang.org/t/compiling-packages-to-bitcode-with-packagecompiler-jl/101376/3 "2023-07-09T20:29:04Z")

</div>

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

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

```

---

<div class="post-metadata">

### Author: ![ludgerpaehler](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ludgerpaehler/32/32672_2.png) [@ludgerpaehler](https://discourse.julialang.org/u/ludgerpaehler)
#### Post date: [July 10, 2023, 7:58pm UTC](https://discourse.julialang.org/t/compiling-packages-to-bitcode-with-packagecompiler-jl/101376/4 "2023-07-10T19:58:01Z")

</div>

Does anyone maybe have an end-to-end example for [Debugging LLVM Transformations in Isolation](https://docs.julialang.org/en/v1/devdocs/llvm/#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

---

<div class="post-metadata">

### Author: ![vchuravy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vchuravy/32/8_2.png) [@vchuravy](https://discourse.julialang.org/u/vchuravy)
#### Post date: [July 11, 2023, 8:16am UTC](https://discourse.julialang.org/t/compiling-packages-to-bitcode-with-packagecompiler-jl/101376/5 "2023-07-11T08:16:38Z")

</div>

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