Skip to content

Commit 7ef180e

Browse files
IanButterworthKristofferC
authored andcommitted
protect against PkgId and UUID being imported and losing Base prefix in create_expr_cache (#53387)
Fixes #53381 (cherry picked from commit a1db8da)
1 parent 0f0f8eb commit 7ef180e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

base/loading.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,6 +2701,7 @@ function create_expr_cache(pkg::PkgId, input::String, output::String, output_o::
27012701
error("LOAD_PATH entries cannot contain $(repr(path_sep))")
27022702

27032703
deps_strs = String[]
2704+
# protects against PkgId and UUID being imported and losing Base prefix
27042705
function pkg_str(_pkg::PkgId)
27052706
if _pkg.uuid === nothing
27062707
"Base.PkgId($(repr(_pkg.name)))"
@@ -2711,6 +2712,9 @@ function create_expr_cache(pkg::PkgId, input::String, output::String, output_o::
27112712
for (pkg, build_id) in concrete_deps
27122713
push!(deps_strs, "$(pkg_str(pkg)) => $(repr(build_id))")
27132714
end
2715+
deps_eltype = sprint(show, eltype(concrete_deps); context = :module=>nothing)
2716+
deps = deps_eltype * "[" * join(deps_strs, ",") * "]"
2717+
precomp_stack = "Base.PkgId[$(join(map(pkg_str, vcat(Base.precompilation_stack, pkg)), ", "))]"
27142718

27152719
if output_o !== nothing
27162720
@debug "Generating object cache file for $(repr("text/plain", pkg))"
@@ -2722,8 +2726,6 @@ function create_expr_cache(pkg::PkgId, input::String, output::String, output_o::
27222726
opts = `-O0 --output-ji $(output) --output-incremental=yes`
27232727
end
27242728

2725-
deps_eltype = sprint(show, eltype(concrete_deps); context = :module=>nothing)
2726-
deps = deps_eltype * "[" * join(deps_strs, ",") * "]"
27272729
trace = isassigned(PRECOMPILE_TRACE_COMPILE) ? `--trace-compile=$(PRECOMPILE_TRACE_COMPILE[])` : ``
27282730
io = open(pipeline(addenv(`$(julia_cmd(;cpu_target)::Cmd)
27292731
$(flags)
@@ -2739,7 +2741,7 @@ function create_expr_cache(pkg::PkgId, input::String, output::String, output_o::
27392741
# write data over stdin to avoid the (unlikely) case of exceeding max command line size
27402742
write(io.in, """
27412743
empty!(Base.EXT_DORMITORY) # If we have a custom sysimage with `EXT_DORMITORY` prepopulated
2742-
Base.track_nested_precomp($(vcat(Base.precompilation_stack, pkg)))
2744+
Base.track_nested_precomp($precomp_stack)
27432745
Base.precompiling_extension = $(loading_extension)
27442746
Base.include_package_for_output($(pkg_str(pkg)), $(repr(abspath(input))), $(repr(depot_path)), $(repr(dl_load_path)),
27452747
$(repr(load_path)), $deps, $(repr(source_path(nothing))))

0 commit comments

Comments
 (0)