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

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:

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:

using SimplePkg

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

I then create a sysimage using the following commands

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

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 suggesting that --compile=all should be present, but that did not work either.

Thanks!

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

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…

1 Like

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.

1 Like