@@ -3,15 +3,8 @@ module Linking
33
44import Base. Libc: Libdl
55
6- # inlined LLD_jll
7- # These get calculated in __init__()
8- const PATH = Ref (" " )
9- const LIBPATH = Ref (" " )
10- const PATH_list = String[]
11- const LIBPATH_list = String[]
12- const lld_path = Ref {String} ()
6+ # from LLD_jll
137const lld_exe = Sys. iswindows () ? " lld.exe" : " lld"
14- const dsymutil_path = Ref {String} ()
158const dsymutil_exe = Sys. iswindows () ? " dsymutil.exe" : " dsymutil"
169
1710if Sys. iswindows ()
@@ -47,61 +40,51 @@ function adjust_ENV!(env::Dict, PATH::String, LIBPATH::String, adjust_PATH::Bool
4740 return env
4841end
4942
50- function __init_lld_path ()
43+ const lld_path = OncePerProcess {String} () do
5144 # Prefer our own bundled lld, but if we don't have one, pick it up off of the PATH
5245 # If this is an in-tree build, `lld` will live in `tools`. Otherwise, it'll be in `private_libexecdir`
5346 for bundled_lld_path in (joinpath (Sys. BINDIR, Base. PRIVATE_LIBEXECDIR, lld_exe),
5447 joinpath (Sys. BINDIR, " .." , " tools" , lld_exe),
5548 joinpath (Sys. BINDIR, lld_exe))
5649 if isfile (bundled_lld_path)
57- lld_path[] = abspath (bundled_lld_path)
58- return
50+ return abspath (bundled_lld_path)
5951 end
6052 end
61- lld_path[] = something (Sys. which (lld_exe), lld_exe)
62- return
53+ return something (Sys. which (lld_exe), lld_exe)
6354end
6455
65- function __init_dsymutil_path ()
66- # Same as with lld but for dsymutil
56+ const dsymutil_path = OncePerProcess {String} () do
57+ # Same as with lld but for dsymutil
6758 for bundled_dsymutil_path in (joinpath (Sys. BINDIR, Base. PRIVATE_LIBEXECDIR, dsymutil_exe),
6859 joinpath (Sys. BINDIR, " .." , " tools" , dsymutil_exe),
6960 joinpath (Sys. BINDIR, dsymutil_exe))
7061 if isfile (bundled_dsymutil_path)
71- dsymutil_path[] = abspath (bundled_dsymutil_path)
72- return
62+ return abspath (bundled_dsymutil_path)
7363 end
7464 end
75- dsymutil_path[] = something (Sys. which (dsymutil_exe), dsymutil_exe)
76- return
65+ return something (Sys. which (dsymutil_exe), dsymutil_exe)
7766end
7867
79- const VERBOSE = Ref {Bool} ( false )
68+ PATH () = dirname ( lld_path () )
8069
81- function __init__ ()
82- VERBOSE[] = something (Base. get_bool_env (" JULIA_VERBOSE_LINKING" , false ), false )
83-
84- __init_lld_path ()
85- __init_dsymutil_path ()
86- PATH[] = dirname (lld_path[])
70+ const LIBPATH = OncePerProcess {String} () do
8771 if Sys. iswindows ()
8872 # On windows, the dynamic libraries (.dll) are in Sys.BINDIR ("usr\\bin")
89- append! ( LIBPATH_list, [abspath (Sys. BINDIR, Base. LIBDIR, " julia" ), Sys. BINDIR])
73+ LIBPATH_list = [abspath (Sys. BINDIR, Base. LIBDIR, " julia" ), Sys. BINDIR]
9074 else
91- append! ( LIBPATH_list, [abspath (Sys. BINDIR, Base. LIBDIR, " julia" ), abspath (Sys. BINDIR, Base. LIBDIR)])
75+ LIBPATH_list = [abspath (Sys. BINDIR, Base. LIBDIR, " julia" ), abspath (Sys. BINDIR, Base. LIBDIR)]
9276 end
93- LIBPATH[] = join (LIBPATH_list, pathsep)
94- return
77+ return join (LIBPATH_list, pathsep)
9578end
9679
9780function lld (; adjust_PATH:: Bool = true , adjust_LIBPATH:: Bool = true )
98- env = adjust_ENV! (copy (ENV ), PATH[] , LIBPATH[] , adjust_PATH, adjust_LIBPATH)
99- return Cmd (Cmd ([lld_path[] ]); env)
81+ env = adjust_ENV! (copy (ENV ), PATH () , LIBPATH () , adjust_PATH, adjust_LIBPATH)
82+ return Cmd (Cmd ([lld_path () ]); env)
10083end
10184
10285function dsymutil (; adjust_PATH:: Bool = true , adjust_LIBPATH:: Bool = true )
103- env = adjust_ENV! (copy (ENV ), PATH[] , LIBPATH[] , adjust_PATH, adjust_LIBPATH)
104- return Cmd (Cmd ([dsymutil_path[] ]); env)
86+ env = adjust_ENV! (copy (ENV ), PATH () , LIBPATH () , adjust_PATH, adjust_LIBPATH)
87+ return Cmd (Cmd ([dsymutil_path () ]); env)
10588end
10689
10790function ld ()
149132 shlibdir () = libdir ()
150133end
151134
135+ verbose_linking () = something (Base. get_bool_env (" JULIA_VERBOSE_LINKING" , false ), false )
136+
152137function link_image_cmd (path, out)
153138 PRIVATE_LIBDIR = " -L$(private_libdir ()) "
154139 SHLIBDIR = " -L$(shlibdir ()) "
@@ -158,7 +143,7 @@ function link_image_cmd(path, out)
158143 LIBS = (LIBS... , " -lopenlibm" , " -lssp" , " -lgcc_s" , " -lgcc" , " -lmsvcrt" )
159144 end
160145
161- V = VERBOSE[] ? " --verbose" : " "
146+ V = verbose_linking () ? " --verbose" : " "
162147 ` $(ld ()) $V $SHARED -o $out $WHOLE_ARCHIVE $path $NO_WHOLE_ARCHIVE $PRIVATE_LIBDIR $SHLIBDIR $LIBS `
163148end
164149
0 commit comments