Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get trimming test working again #56689

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions contrib/juliac.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
cmd = Base.julia_cmd()
cmd = `$cmd --startup-file=no --history-file=no`
output_type = nothing # exe, sharedlib, sysimage
trim = nothing
outname = nothing
file = nothing
add_ccallables = false
Expand All @@ -15,13 +14,16 @@ if help !== nothing
println(
"""
Usage: julia juliac.jl [--output-exe | --output-lib | --output-sysimage] <name> [options] <file.jl>
--trim=<no,safe,unsafe,unsafe-warn> Only output code statically determined to be reachable
--experimental --trim=<no,safe,unsafe,unsafe-warn> Only output code statically determined to be reachable
--compile-ccallable Include all methods marked `@ccallable` in output
--verbose Request verbose output
""")
exit(0)
end

# arguments to forward to julia compilation process
julia_args = []

let i = 1
while i <= length(ARGS)
arg = ARGS[i]
Expand All @@ -31,17 +33,13 @@ let i = 1
i == length(ARGS) && error("Output specifier requires an argument")
global outname = ARGS[i+1]
i += 1
elseif startswith(arg, "--trim")
arg = split(arg, '=')
if length(arg) == 1
global trim = "safe"
else
global trim = arg[2]
end
elseif arg == "--compile-ccallable"
global add_ccallables = true
elseif arg == "--verbose"
global verbose = true
elseif startswith(arg, "--trim") || arg == "--experimental"
# forwarded args
push!(julia_args, arg)
else
if arg[1] == '-' || !isnothing(file)
println("Unexpected argument `$arg`")
Expand Down Expand Up @@ -79,8 +77,7 @@ open(initsrc_path, "w") do io
""")
end

static_call_graph_arg() = isnothing(trim) ? `` : `--trim=$(trim)`
cmd = addenv(`$cmd --project=$(Base.active_project()) --output-o $img_path --output-incremental=no --strip-ir --strip-metadata $(static_call_graph_arg()) $(joinpath(@__DIR__,"juliac-buildscript.jl")) $absfile $output_type $add_ccallables`, "OPENBLAS_NUM_THREADS" => 1, "JULIA_NUM_THREADS" => 1)
cmd = addenv(`$cmd --project=$(Base.active_project()) --output-o $img_path --output-incremental=no --strip-ir --strip-metadata $julia_args $(joinpath(@__DIR__,"juliac-buildscript.jl")) $absfile $output_type $add_ccallables`, "OPENBLAS_NUM_THREADS" => 1, "JULIA_NUM_THREADS" => 1)
verbose && println("Running: $cmd")
if !success(pipeline(cmd; stdout, stderr))
println(stderr, "\nFailed to compile $file")
Expand Down
1 change: 1 addition & 0 deletions src/staticdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -2577,6 +2577,7 @@ static void strip_specializations_(jl_method_instance_t *mi)
if (inferred && inferred != jl_nothing) {
if (jl_options.strip_ir) {
record_field_change((jl_value_t**)&codeinst->inferred, jl_nothing);
record_field_change((jl_value_t**)&codeinst->edges, (jl_value_t*)jl_emptysvec);
}
else if (jl_options.strip_metadata) {
jl_value_t *stripped = strip_codeinfo_meta(mi->def.method, inferred, codeinst);
Expand Down
2 changes: 1 addition & 1 deletion test/trimming/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ LDFLAGS_ADD = -lm $(shell $(JULIA_CONFIG) --ldflags --ldlibs) -ljulia-internal
release: hello$(EXE)

hello.o: $(SRCDIR)/hello.jl $(BUILDSCRIPT)
$(JULIA) -t 1 -J $(BIN)/../lib/julia/sys.so --startup-file=no --history-file=no --output-o $@ --output-incremental=no --strip-ir --strip-metadata --trim $(BUILDSCRIPT) $(SRCDIR)/hello.jl --output-exe true
$(JULIA) -t 1 -J $(BIN)/../lib/julia/sys.so --startup-file=no --history-file=no --output-o $@ --output-incremental=no --strip-ir --strip-metadata --experimental --trim $(BUILDSCRIPT) $(SRCDIR)/hello.jl --output-exe true

init.o: $(SRCDIR)/init.c
$(CC) -c -o $@ $< $(CPPFLAGS_ADD) $(CPPFLAGS) $(CFLAGS_ADD) $(CFLAGS)
Expand Down