From 37b20cbf828c15834b49f67f00a671a976e82451 Mon Sep 17 00:00:00 2001 From: Ian Date: Tue, 14 Jun 2022 17:39:14 -0400 Subject: [PATCH 1/5] audit sysimage for relocatability --- src/PackageCompiler.jl | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/PackageCompiler.jl b/src/PackageCompiler.jl index 5e0c895f..6b008055 100644 --- a/src/PackageCompiler.jl +++ b/src/PackageCompiler.jl @@ -425,6 +425,7 @@ function create_sysimage(packages::Union{Nothing, Symbol, Vector{String}, Vector soname=nothing, compat_level::String="major", extra_precompiles::String = "", + audit_relocatability::Bool = true ) if filter_stdlibs && incremental @@ -536,6 +537,13 @@ function create_sysimage(packages::Union{Nothing, Symbol, Vector{String}, Vector end end + if audit_relocatability + @info "Auditing sysimage relocatability" + if audit_sysimage_relocatability(sysimage_path) + @info "No issues found" + end + end + return nothing end @@ -1156,4 +1164,23 @@ function bundle_headers(dest_dir, header_files) return end +function audit_sysimage_relocatability(sysimg_path::String; paths::Vector{String} = [homedir(), DEPOT_PATH...]) + + none_found = true + sysimg_contents = open(io -> String(read(io)), sysimg_path, read=true) + + for path in paths + found = String[] + for m in eachmatch(Regex("$(path)[^\0]+"), sysimg_contents) + push!(found, "[$(m.offset)] $(m.match)") + end + if !isempty(found) + @warn "absolute path `$path` found in $(length(found)) places:" found + none_found = false + end + end + + return none_found +end + end # module From 65f395ee3dbb151b683f487c9629c8a06dd771d1 Mon Sep 17 00:00:00 2001 From: Ian Date: Tue, 14 Jun 2022 17:58:14 -0400 Subject: [PATCH 2/5] intentionally include an abs path for testing --- test/precompile_execution.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/precompile_execution.jl b/test/precompile_execution.jl index 786fde11..e5084333 100644 --- a/test/precompile_execution.jl +++ b/test/precompile_execution.jl @@ -1,3 +1,6 @@ using Example Example.domath(5) + +# intentionally put an abspath in to test the relocatability audit +test_abspath = homedir() From 6e6dec0b6c948e0c3a0fc975686d9f098c537851 Mon Sep 17 00:00:00 2001 From: Ian Date: Tue, 14 Jun 2022 18:18:07 -0400 Subject: [PATCH 3/5] force print all paths --- src/PackageCompiler.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PackageCompiler.jl b/src/PackageCompiler.jl index 6b008055..5cf36611 100644 --- a/src/PackageCompiler.jl +++ b/src/PackageCompiler.jl @@ -1175,7 +1175,7 @@ function audit_sysimage_relocatability(sysimg_path::String; paths::Vector{String push!(found, "[$(m.offset)] $(m.match)") end if !isempty(found) - @warn "absolute path `$path` found in $(length(found)) places:" found + @warn """absolute path `$path` found in $(length(found)) places:\n$(join(found, "\n"))""" none_found = false end end From 0e6471cf05632c1d03b9bd46ad6c447d8b004d19 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Thu, 17 Oct 2024 21:41:17 -0400 Subject: [PATCH 4/5] Update PackageCompiler.jl Co-authored-by: Dilum Aluthge --- src/PackageCompiler.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PackageCompiler.jl b/src/PackageCompiler.jl index 2b1348be..780f0ab1 100644 --- a/src/PackageCompiler.jl +++ b/src/PackageCompiler.jl @@ -1614,7 +1614,7 @@ function audit_sysimage_relocatability(sysimg_path::String; paths::Vector{String for path in paths found = String[] - for m in eachmatch(Regex("$(path)[^\0]+"), sysimg_contents) + for m in eachmatch(Regex("\Q$(path)\E[^\0]+"), sysimg_contents) push!(found, "[$(m.offset)] $(m.match)") end if !isempty(found) From 78bd67a967ddbcc474ecea6b2ef10a3d36b7982e Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Thu, 17 Oct 2024 21:49:39 -0400 Subject: [PATCH 5/5] Update PackageCompiler.jl Co-authored-by: Dilum Aluthge --- src/PackageCompiler.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PackageCompiler.jl b/src/PackageCompiler.jl index 780f0ab1..25254595 100644 --- a/src/PackageCompiler.jl +++ b/src/PackageCompiler.jl @@ -1614,7 +1614,7 @@ function audit_sysimage_relocatability(sysimg_path::String; paths::Vector{String for path in paths found = String[] - for m in eachmatch(Regex("\Q$(path)\E[^\0]+"), sysimg_contents) + for m in eachmatch(Regex("\\Q$(path)\\E[^\0]+"), sysimg_contents) push!(found, "[$(m.offset)] $(m.match)") end if !isempty(found)