# Code obfuscation | Using the \`--strip-ir\` option in PackageCompiler.jl

**URL:** <https://discourse.julialang.org/t/code-obfuscation-using-the-strip-ir-option-in-packagecompiler-jl/91426>\
**Category:** General Usage\
**Tags:** package-compiler\
**Created:** [December 8, 2022, 2:21pm UTC](https://discourse.julialang.org/t/code-obfuscation-using-the-strip-ir-option-in-packagecompiler-jl/91426 "2022-12-08T14:21:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hayk](https://avatars.discourse-cdn.com/v4/letter/h/3ab097/32.png) [@hayk](https://discourse.julialang.org/u/hayk)\
**Post date:** [December 8, 2022, 2:21pm UTC](https://discourse.julialang.org/t/code-obfuscation-using-the-strip-ir-option-in-packagecompiler-jl/91426/1 "2022-12-08T14:21:38Z")

</div>

I would like to distribute my package while hiding the source code. I came across PackageCompiler.jl and julia’s `--strip-ir` option to help, but when I load a sysimage generated using that option, I get an error that some source code is not available. Here is an example on a simple package with detailed steps:

I have a module `SimplePkg`:

```julia
module SimplePkg

export nodoc

nodoc(x) = sin(sqrt(x))

"""
Returns sin(sqrt(x))
"""
withdoc(x) = nodoc(x)

end # module

```

and a script “scratch.jl” that uses the package:

```julia
using SimplePkg

nodoc(100)
SimplePkg.withdoc(100)
nodoc(100.0)

```

I then create a sysimage using the following commands

```julia
using PackageCompiler
create_sysimage(:SimplePkg, sysimage_path="SimplePkg_StripIR.so", precompile_execution_file="scratch.jl", sysimage_build_args=`--strip-ir`)

```

If I open julia using `julia -J SimplePkg_StripIR.so`, I get the following

```julia
source not available for activate(REPL.LineEdit.TextInterface, REPL.LineEdit.MIState, REPL.Terminals.AbstractTerminal, REPL.Terminals.TextTerminal) from activate(REPL.LineEdit.TextInterface, REPL.LineEdit.MIState, REPL.Terminals.AbstractTerminal, REPL.Terminals.TextTerminal)
source not available for (::Type{NamedTuple{(:exception, :backtrace), T} where T<:Tuple})(Tuple{ErrorException, Array{Union{Ptr{Nothing}, Base.InterpreterIP}, 1}}) from (::Type{NamedTuple{names, T} where T<:Tuple})(Tuple) where {names}
source not available for (::Type{NamedTuple{(:exception, :backtrace), T} where T<:Tuple})(Tuple{ErrorException, Array{Union{Ptr{Nothing}, Base.InterpreterIP}, 1}}) from (::Type{NamedTuple{names, T} where T<:Tuple})(Tuple) where {names}

SYSTEM: caught exception of type source not available for show(Core.CoreSTDERR, Any) from show(IO, Any)
source not available for (::REPL.var"#48#53"{REPL.REPLBackendRef})() from (::REPL.var"#48#53"{backend_ref})()

```

It looks to me not something related to my code. Would be great to hear from someone who has managed to make this option work. I came across this post [Obfuscate Julia module and import it Python - #10 by Palli](https://discourse.julialang.org/t/obfuscate-julia-module-and-import-it-python/73026/10) suggesting that `--compile=all` should be present, but that did not work either.

Thanks!

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [January 12, 2023, 10:28pm UTC](https://discourse.julialang.org/t/code-obfuscation-using-the-strip-ir-option-in-packagecompiler-jl/91426/2 "2023-01-12T22:28:26Z")

</div>

Note, this was broken until fixed, then backported to 1.8.4, in case you used an older version:

> <https://github.com/JuliaLang/julia/pull/47678>
>
> fix #47662

I didn’t even recall suggesting `--compile=all`, since I’ve never used it (only `--compile=min` which is occupationally useful), but I see it’s just mention in the NEWS, as necessary, for the options I was suggesting (that I’ve never tried personally either).

I’m not sure it’s enough to start Julia with `--compile=all`, maybe you need to pass that option in some way to PackageCompiler.jl when you use it, or is that default behavior? I would even try in 1.9 (the beta2, or upcoming beta3), or even 1.10-DEV/master, those are rather new options, but of course should work in the older versions they are documented to support…

---

<div class="post-metadata">

**Author:** ![hayk](https://avatars.discourse-cdn.com/v4/letter/h/3ab097/32.png) [@hayk](https://discourse.julialang.org/u/hayk)\
**Post date:** [January 16, 2023, 2:09pm UTC](https://discourse.julialang.org/t/code-obfuscation-using-the-strip-ir-option-in-packagecompiler-jl/91426/3 "2023-01-16T14:09:24Z")

</div>

Thanks for the response.

I just used Julia 1.9-beta2 and it worked, but only with `--compile=all` option. Couldn’t do it with julia-1.8.5 or `--compile=min`, but looks like I have a version which works.
