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

add --trim option for generating smaller binaries #55047

Merged
merged 37 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2cfe2c9
Implement changes to the runtime that allow for building small binaries,
gbaraldi Jun 11, 2024
dd182ef
Implement example driver and simple tests
gbaraldi Jun 12, 2024
70f8ae6
Less invasive changes to base to make hello world work
gbaraldi Jun 12, 2024
195ab72
Fix some typos and refactor cli usage to only use static-call-graph. …
gbaraldi Jun 13, 2024
49fa149
make argument to --static-call-graph optional, improve help text
JeffBezanson Jun 18, 2024
b1cc0f3
misc formatting and cleanup
JeffBezanson Jun 20, 2024
c574946
Check all builtins for potential dynamic dispatches
gbaraldi Jun 25, 2024
274f0fa
Fix typos in the driver and exit with exit(1)
gbaraldi Jun 27, 2024
1f339ba
Make stacktrace printing robust and add overload to init_project to a…
gbaraldi Jun 27, 2024
82dd4e1
fix warning for print_retainers by ifdef'ing it out
JeffBezanson Jun 27, 2024
381f1d9
Save current state of the branch.
gbaraldi Jul 1, 2024
a4279c4
WIP
JeffBezanson Jul 2, 2024
7d7e37b
Add default --static-call-graph option
gbaraldi Jul 2, 2024
cb97113
don't compile for typeinf world with static-call-graph
JeffBezanson Jul 5, 2024
8a8253f
rename option to --trim
JeffBezanson Jul 5, 2024
4eaff42
wip
JeffBezanson Jul 10, 2024
a2cff4c
fixes for threads and tasks with trimming
JeffBezanson Jul 13, 2024
f4c1f2b
Fix unsafe-warn mutiple stacktrace output
gbaraldi Jul 12, 2024
f5eedf9
Get lib example working, create build script (#55104)
timholy Jul 15, 2024
2679dab
fix whitespace
JeffBezanson Jul 18, 2024
2d01d26
convert build scripts to a test case for now
JeffBezanson Aug 2, 2024
c50e8c9
fix warning printing in LinearAlgebra
JeffBezanson Aug 7, 2024
bb87171
fix _reinit_stdio needed for codegen error printing
JeffBezanson Aug 8, 2024
dcc69a1
rename --static-call-graph to --trim
JeffBezanson Aug 8, 2024
bec43b8
fix analyzegc
JeffBezanson Aug 8, 2024
b02e2f2
fixes
JeffBezanson Aug 9, 2024
9458c52
fix for warning test
JeffBezanson Aug 9, 2024
4c17659
Update doc/src/devdocs/sysimg.md
JeffBezanson Aug 12, 2024
e85edad
Update doc/src/devdocs/sysimg.md
JeffBezanson Aug 12, 2024
72682de
Update doc/src/manual/command-line-interface.md
JeffBezanson Aug 12, 2024
63385d1
Update test/trimming/buildscript.jl
JeffBezanson Aug 12, 2024
0aad918
trimming doc clarifications
JeffBezanson Aug 12, 2024
b770ee8
rm print_retainers debug code
JeffBezanson Aug 12, 2024
5e31a07
hook up CI for trimming
JeffBezanson Aug 13, 2024
75dcd78
allow single non-concrete method match in static call graph
JeffBezanson Aug 16, 2024
cdacfb2
Add missing `jl_emit_codeinst` failure check
topolarity Aug 19, 2024
5a95814
add juliac.jl to contrib and install it
JeffBezanson Aug 27, 2024
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ julia-deps: | $(DIRS) $(build_datarootdir)/julia/base $(build_datarootdir)/julia
julia-stdlib: | $(DIRS) julia-deps
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/stdlib

julia-base: julia-deps $(build_sysconfdir)/julia/startup.jl $(build_man1dir)/julia.1 $(build_datarootdir)/julia/julia-config.jl
julia-base: julia-deps $(build_sysconfdir)/julia/startup.jl $(build_man1dir)/julia.1 $(build_datarootdir)/julia/julia-config.jl $(build_datarootdir)/julia/juliac.jl $(build_datarootdir)/julia/juliac-buildscript.jl
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/base

julia-libccalltest: julia-deps
Expand Down Expand Up @@ -181,7 +181,7 @@ $(build_sysconfdir)/julia/startup.jl: $(JULIAHOME)/etc/startup.jl | $(build_sysc
@echo Creating usr/etc/julia/startup.jl
@cp $< $@

$(build_datarootdir)/julia/julia-config.jl: $(JULIAHOME)/contrib/julia-config.jl | $(build_datarootdir)/julia
$(build_datarootdir)/julia/%: $(JULIAHOME)/contrib/% | $(build_datarootdir)/julia
$(INSTALL_M) $< $(dir $@)

$(build_depsbindir)/stringreplace: $(JULIAHOME)/contrib/stringreplace.c | $(build_depsbindir)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Julia v1.12 Release Notes
New language features
---------------------

- New option `--trim` for building "trimmed" binaries, where code not provably reachable from entry points
is removed. Entry points can be marked using `Base.Experimental.entrypoint` ([#55047]).
- A new keyword argument `usings::Bool` has been added to `names`. By using this, we can now
find all the names available in module `A` by `names(A; all=true, imported=true, usings=true)`. ([#54609])
- the `@atomic(...)` macro family supports now the reference assignment syntax, e.g.
Expand Down
14 changes: 14 additions & 0 deletions base/experimental.jl
Original file line number Diff line number Diff line change
Expand Up @@ -457,4 +457,18 @@ without adding them to the global method table.
"""
:@MethodTable

"""
Base.Experimental.entrypoint(f, argtypes::Tuple)
JeffBezanson marked this conversation as resolved.
Show resolved Hide resolved

Mark a method for inclusion when the `--trim` option is specified.
"""
function entrypoint(@nospecialize(f), @nospecialize(argtypes::Tuple))
entrypoint(Tuple{Core.Typeof(f), argtypes...})
end

function entrypoint(@nospecialize(argt::Type))
ccall(:jl_add_entrypoint, Int32, (Any,), argt)
nothing
end

end
5 changes: 4 additions & 1 deletion base/libuv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ function uv_return_spawn end
function uv_asynccb end
function uv_timercb end

function reinit_stdio()
reinit_stdio() = _reinit_stdio()
# we need this so it can be called by codegen to print errors, even after
# reinit_stdio has been redefined by the juliac build script.
function _reinit_stdio()
global stdin = init_stdio(ccall(:jl_stdin_stream, Ptr{Cvoid}, ()))::IO
global stdout = init_stdio(ccall(:jl_stdout_stream, Ptr{Cvoid}, ()))::IO
global stderr = init_stdio(ccall(:jl_stderr_stream, Ptr{Cvoid}, ()))::IO
Expand Down
1 change: 1 addition & 0 deletions base/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct JLOptions
permalloc_pkgimg::Int8
heap_size_hint::UInt64
trace_compile_timing::Int8
trim::Int8
end

# This runs early in the sysimage != is not defined yet
Expand Down
11 changes: 9 additions & 2 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,13 @@ struct CodegenParams
"""
use_jlplt::Cint

"""
If enabled, only provably reachable code (from functions marked with `entrypoint`) is included
in the output system image. Errors or warnings can be given for call sites too dynamic to handle.
The option is disabled by default. (0=>disabled, 1=>safe (static errors), 2=>unsafe, 3=>unsafe plus warnings)
"""
trim::Cint

"""
A pointer of type

Expand All @@ -1519,14 +1526,14 @@ struct CodegenParams
prefer_specsig::Bool=false,
gnu_pubnames::Bool=true, debug_info_kind::Cint = default_debug_info_kind(),
debug_info_level::Cint = Cint(JLOptions().debug_level), safepoint_on_entry::Bool=true,
gcstack_arg::Bool=true, use_jlplt::Bool=true,
gcstack_arg::Bool=true, use_jlplt::Bool=true, trim::Cint=Cint(0),
lookup::Ptr{Cvoid}=unsafe_load(cglobal(:jl_rettype_inferred_addr, Ptr{Cvoid})))
return new(
Cint(track_allocations), Cint(code_coverage),
Cint(prefer_specsig),
Cint(gnu_pubnames), debug_info_kind,
debug_info_level, Cint(safepoint_on_entry),
Cint(gcstack_arg), Cint(use_jlplt),
Cint(gcstack_arg), Cint(use_jlplt), Cint(trim),
lookup)
end
end
Expand Down
4 changes: 4 additions & 0 deletions base/strings/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ function print(io::IO, xs...)
return nothing
end

setfield!(typeof(print).name.mt, :max_args, 10, :monotonic)

"""
println([io::IO], xs...)

Expand All @@ -74,6 +76,7 @@ julia> String(take!(io))
"""
println(io::IO, xs...) = print(io, xs..., "\n")

setfield!(typeof(println).name.mt, :max_args, 10, :monotonic)
## conversion of general objects to strings ##

"""
Expand Down Expand Up @@ -149,6 +152,7 @@ function print_to_string(xs...)
end
String(_unsafe_take!(s))
end
setfield!(typeof(print_to_string).name.mt, :max_args, 10, :monotonic)

function string_with_env(env, xs...)
if isempty(xs)
Expand Down
2 changes: 1 addition & 1 deletion contrib/julia-config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function ldlibs(doframework)
"julia"
end
if Sys.isunix()
return "-Wl,-rpath,$(shell_escape(libDir())) -Wl,-rpath,$(shell_escape(private_libDir())) -l$libname"
return "-L$(shell_escape(private_libDir())) -Wl,-rpath,$(shell_escape(libDir())) -Wl,-rpath,$(shell_escape(private_libDir())) -l$libname"
else
return "-l$libname -lopenlibm"
end
Expand Down
Loading