-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
check.jl
executable file
·87 lines (78 loc) · 2.35 KB
/
check.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
# -*- mode: julia -*-
# This file is a part of Julia. License is MIT: https://julialang.org/license
#
# Usage:
# contrib/asan/check.jl <julia>
#
# Check that <julia> is built with ASAN.
#
#=
JULIA="${JULIA:-julia}"
exec "$JULIA" --startup-file=no --compile=min "${BASH_SOURCE[0]}" "$@"
=#
function main(args = ARGS)::Int
if length(args) != 1
@error "Expect a single argument" args
return 2
end
julia, = args
# It looks like double-free is easy to robustly trigger.
code = """
@info "Testing a pattern that would trigger ASAN"
write(ARGS[1], "started")
ptr = ccall(:malloc, Ptr{UInt}, (Csize_t,), 256)
ccall(:free, Cvoid, (Ptr{UInt},), ptr)
ccall(:free, Cvoid, (Ptr{UInt},), ptr)
@error "Failed to trigger ASAN"
"""
local proc
timeout = Threads.Atomic{Bool}(false)
isstarted = false
mktemp() do tmppath, tmpio
cmd = `$julia -e $code $tmppath`
# Note: Ideally, we set ASAN_SYMBOLIZER_PATH here. But there is no easy
# way to find out the path from just a Julia binary.
@debug "Starting a process" cmd
proc = run(pipeline(cmd; stdout, stderr); wait = false)
timer = Timer(10)
@sync try
@async begin
try
wait(timer)
true
catch err
err isa EOFError || rethrow()
false
end && begin
timeout[] = true
kill(proc)
end
end
wait(proc)
finally
close(timer)
end
# At the very beginning of the process, the `julia` subprocess put a
# marker that it is successfully started. This is to avoid mixing
# non-functional `julia` binary (or even non-`julia` command) and
# correctly working `julia` with ASAN:
isstarted = read(tmpio, String) == "started"
end
if timeout[]
@error "Timeout waiting for the subprocess"
return 1
elseif success(proc)
@error "ASAN was not triggered"
return 1
elseif !isstarted
@error "Failed to start the process"
return 1
else
@info "ASAN is functional in the Julia binary `$julia`"
return 0
end
end
if abspath(PROGRAM_FILE) == @__FILE__
exit(main())
end