Skip to content

Commit 8c2134b

Browse files
committed
[Auditor] Use executables from Binutils_jll when possible
1 parent 4538e89 commit 8c2134b

File tree

5 files changed

+43
-27
lines changed

5 files changed

+43
-27
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ version = "0.6.4"
66
[deps]
77
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
88
BinaryBuilderBase = "7f725544-6523-48cd-82d1-3fa08ff4056e"
9+
Binutils_jll = "489e263e-5428-50b0-a723-147a141b401e"
910
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
1011
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
1112
GitHub = "bc5e4493-9b4d-5f90-b8aa-2b2bcaad7a26"
@@ -34,6 +35,7 @@ ghr_jll = "07c12ed4-43bc-5495-8a2a-d5838ef8d533"
3435

3536
[compat]
3637
ArgParse = "1.1"
38+
Binutils_jll = "2"
3739
BinaryBuilderBase = "1.35.2"
3840
Downloads = "1"
3941
GitHub = "5.1"

src/Auditor.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ const AUDITOR_LOGGING_LOCK = ReentrantLock()
1818

1919
# Helper function to run a command and print to `io` its invocation and full
2020
# output (mimim what the sandbox does normally, but outside of it).
21-
function run_with_io(io::IO, cmd::Cmd)
21+
function run_with_io(io::IO, cmd::Cmd; wait::Bool=true)
2222
println(io, "---> $(join(cmd.exec, " "))")
23-
run(pipeline(cmd; stdout=io, stderr=io))
23+
run(pipeline(cmd; stdout=io, stderr=io); wait)
2424
end
2525

2626
include("auditor/instruction_set.jl")

src/auditor/compiler_abi.jl

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Base.BinaryPlatforms: detect_libstdcxx_version, detect_cxxstring_abi
22
using ObjectFile
3+
using Binutils_jll: Binutils_jll
34

45
csl_warning(lib) = @lock AUDITOR_LOGGING_LOCK @warn(
56
"""
@@ -171,15 +172,24 @@ function cppfilt(symbol_names::Vector, platform::AbstractPlatform; strip_undersc
171172
seekstart(input)
172173

173174
output = IOBuffer()
174-
mktempdir() do dir
175-
# No need to acquire a sandbox lock here because we use a (hopefully)
176-
# different temporary directory for each run.
177-
ur = preferred_runner()(dir; cwd="/workspace/", platform=platform)
178-
cmd = Cmd(`/opt/bin/$(triplet(ur.platform))/c++filt`; ignorestatus=true)
179-
if strip_underscore
180-
cmd = `$(cmd) --strip-underscore`
175+
cmd = if Binutils_jll.is_available()
176+
ignorestatus(Binutils_jll.cxxfilt())
177+
else
178+
Cmd(`/opt/bin/$(triplet(platform))/c++filt`; ignorestatus=true)
179+
end
180+
if strip_underscore
181+
cmd = `$(cmd) --strip-underscore`
182+
end
183+
184+
if Binutils_jll.is_available()
185+
run(pipeline(cmd; stdin=input, stdout=output))
186+
else
187+
mktempdir() do dir
188+
# No need to acquire a sandbox lock here because we use a (hopefully)
189+
# different temporary directory for each run.
190+
ur = preferred_runner()(dir; cwd="/workspace/", platform=platform)
191+
run_interactive(ur, cmd; stdin=input, stdout=output)
181192
end
182-
run_interactive(ur, cmd; stdin=input, stdout=output)
183193
end
184194

185195
return filter!(s -> !isempty(s), split(String(take!(output)), "\n"))

src/auditor/instruction_set.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using JSON
2+
using Binutils_jll: Binutils_jll
23

34
## We start with definitions of instruction mnemonics, broken down by category:
45
const instruction_categories = JSON.parsefile(joinpath(@__DIR__, "instructions.json");
@@ -36,12 +37,17 @@ function instruction_mnemonics(path::AbstractString, platform::AbstractPlatform)
3637
output = IOBuffer()
3738

3839
# Run objdump to disassemble the input binary
39-
if Sys.isbsd(platform)
40-
objdump_cmd = "llvm-objdump -d $(basename(path))"
40+
objdump_args = `-d $(basename(path))`
41+
if Binutils_jll.is_available() && (Sys.islinux(platform) || Sys.isfreebsd(platform))
42+
run(pipeline(ignorestatus(`$(Binutils_jll.objdump()) $(objdump_args)`); stdout=output, stderr=devnull))
4143
else
42-
objdump_cmd = "\${target}-objdump -d $(basename(path))"
44+
if Sys.isbsd(platform)
45+
objdump_cmd = "llvm-objdump $(objdump_args)"
46+
else
47+
objdump_cmd = "\${target}-objdump $(objdump_args)"
48+
end
49+
@lock AUDITOR_SANDBOX_LOCK run_interactive(ur, Cmd(`/bin/bash -c "$(objdump_cmd)"`; ignorestatus=true); stdout=output, stderr=devnull)
4350
end
44-
@lock AUDITOR_SANDBOX_LOCK run_interactive(ur, Cmd(`/bin/bash -c "$(objdump_cmd)"`; ignorestatus=true); stdout=output, stderr=devnull)
4551
seekstart(output)
4652

4753
for line in eachline(output)

src/auditor/soname_matching.jl

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using Patchelf_jll: patchelf
2+
13
# Not everything has an SONAME
24
get_soname(oh::ObjectHandle) = nothing
35

@@ -63,20 +65,16 @@ function ensure_soname(prefix::Prefix, path::AbstractString, platform::AbstractP
6365
end
6466

6567
# Otherwise, set the SONAME
66-
ur = preferred_runner()(prefix.path; cwd="/workspace/", platform=platform)
67-
set_soname_cmd = ``
68-
69-
if Sys.isapple(platform)
70-
install_name_tool = "/opt/bin/$(triplet(ur.platform))/install_name_tool"
71-
set_soname_cmd = `$install_name_tool -id $(soname) $(rel_path)`
72-
elseif Sys.islinux(platform) || Sys.isbsd(platform)
73-
patchelf = "/usr/bin/patchelf"
74-
set_soname_cmd = `$patchelf $(patchelf_flags(platform)) --set-soname $(soname) $(rel_path)`
75-
end
76-
77-
# Create a new linkage that looks like @rpath/$lib on OSX,
68+
# Create a new linkage that looks like @rpath/$lib on OSX,
7869
retval = with_logfile(prefix, "set_soname_$(basename(rel_path))_$(soname).log"; subdir) do io
79-
@lock AUDITOR_SANDBOX_LOCK run(ur, set_soname_cmd, io; verbose=verbose)
70+
if Sys.isapple(platform)
71+
ur = preferred_runner()(prefix.path; cwd="/workspace/", platform=platform)
72+
install_name_tool = "/opt/bin/$(triplet(ur.platform))/install_name_tool"
73+
set_soname_cmd = `$install_name_tool -id $(soname) $(rel_path)`
74+
@lock AUDITOR_SANDBOX_LOCK run(ur, set_soname_cmd, io; verbose=verbose)
75+
elseif Sys.islinux(platform) || Sys.isbsd(platform)
76+
success(run_with_io(io, `$(patchelf()) $(patchelf_flags(platform)) --set-soname $(soname) $(realpath(path))`; wait=false))
77+
end
8078
end
8179

8280
if !retval

0 commit comments

Comments
 (0)