[PATCH] Re-add calling emit_clobber in lower-subreg.cc's resolve_simple_move.
[official-gcc.git] / gcc / testsuite / lib / target-libpath.exp
blob61408434145d1cac7f1b3920d159f40e279ee974
1 # Copyright (C) 2004-2024 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with GCC; see the file COPYING3. If not see
15 # <http://www.gnu.org/licenses/>.
17 # This file was contributed by John David Anglin (dave.anglin@nrc-cnrc.gc.ca)
19 set orig_environment_saved 0
20 set orig_ld_library_path_saved 0
21 set orig_ld_run_path_saved 0
22 set orig_shlib_path_saved 0
23 set orig_ld_library_path_32_saved 0
24 set orig_ld_library_path_64_saved 0
25 set orig_dyld_library_path_saved 0
26 set orig_path_saved 0
27 set orig_gcc_exec_prefix_saved 0
28 set orig_gcc_exec_prefix_checked 0
31 #######################################
32 # proc set_gcc_exec_prefix_env_var { }
33 #######################################
35 proc set_gcc_exec_prefix_env_var { } {
36 global TEST_GCC_EXEC_PREFIX
37 global env
39 # Set GCC_EXEC_PREFIX for the compiler under test to pick up files not in
40 # the build tree from a specified location (normally the install tree).
41 if [info exists TEST_GCC_EXEC_PREFIX] {
42 setenv GCC_EXEC_PREFIX "$TEST_GCC_EXEC_PREFIX"
46 #######################################
47 # proc set_ld_library_path_env_vars { }
48 #######################################
50 proc set_ld_library_path_env_vars { } {
51 global ld_library_path
52 global orig_environment_saved
53 global orig_ld_library_path_saved
54 global orig_ld_run_path_saved
55 global orig_shlib_path_saved
56 global orig_ld_library_path_32_saved
57 global orig_ld_library_path_64_saved
58 global orig_dyld_library_path_saved
59 global orig_path_saved
60 global orig_gcc_exec_prefix_saved
61 global orig_gcc_exec_prefix_checked
62 global orig_ld_library_path
63 global orig_ld_run_path
64 global orig_shlib_path
65 global orig_ld_library_path_32
66 global orig_ld_library_path_64
67 global orig_dyld_library_path
68 global orig_path
69 global orig_gcc_exec_prefix
70 global ENABLE_DARWIN_AT_RPATH
71 global env
73 # Save the original GCC_EXEC_PREFIX.
74 if { $orig_gcc_exec_prefix_checked == 0 } {
75 if [info exists env(GCC_EXEC_PREFIX)] {
76 set orig_gcc_exec_prefix "$env(GCC_EXEC_PREFIX)"
77 set orig_gcc_exec_prefix_saved 1
79 set orig_gcc_exec_prefix_checked 1
82 set_gcc_exec_prefix_env_var
84 # Setting the ld library path causes trouble when testing cross-compilers.
85 if { [is_remote target] } {
86 return
89 if { $orig_environment_saved == 0 } {
90 set orig_environment_saved 1
92 # Save the original environment.
93 if [info exists env(LD_LIBRARY_PATH)] {
94 set orig_ld_library_path "$env(LD_LIBRARY_PATH)"
95 set orig_ld_library_path_saved 1
97 if [info exists env(LD_RUN_PATH)] {
98 set orig_ld_run_path "$env(LD_RUN_PATH)"
99 set orig_ld_run_path_saved 1
101 if [info exists env(SHLIB_PATH)] {
102 set orig_shlib_path "$env(SHLIB_PATH)"
103 set orig_shlib_path_saved 1
105 if [info exists env(LD_LIBRARY_PATH_32)] {
106 set orig_ld_library_path_32 "$env(LD_LIBRARY_PATH_32)"
107 set orig_ld_library_path_32_saved 1
109 if [info exists env(LD_LIBRARY_PATH_64)] {
110 set orig_ld_library_path_64 "$env(LD_LIBRARY_PATH_64)"
111 set orig_ld_library_path_64_saved 1
113 if [info exists env(DYLD_LIBRARY_PATH)] {
114 set orig_dyld_library_path "$env(DYLD_LIBRARY_PATH)"
115 set orig_dyld_library_path_saved 1
117 if [info exists env(PATH)] {
118 set orig_path "$env(PATH)"
119 set orig_path_saved 1
123 # We need to set ld library path in the environment. Currently,
124 # unix.exp doesn't set the environment correctly for all systems.
125 # It only sets SHLIB_PATH and LD_LIBRARY_PATH when it executes a
126 # program. We also need the environment set for compilations, etc.
128 # On Darwin, we have to set variables akin to LD_LIBRARY_PATH, but called
129 # DYLD_LIBRARY_PATH. The same applies to Solaris 32 bit
130 # (LD_LIBRARY_PATH_32), Solaris 64 bit (LD_LIBRARY_PATH_64), and HP-UX
131 # (SHLIB_PATH). In some cases, the variables are independent of
132 # LD_LIBRARY_PATH, and in other cases LD_LIBRARY_PATH is used if the
133 # variable is not defined.
135 # Doing this is somewhat of a hack as ld_library_path gets repeated in
136 # SHLIB_PATH and LD_LIBRARY_PATH when unix_load sets these variables.
137 if { ![istarget *-*-darwin*] } {
138 if { $orig_ld_library_path_saved } {
139 setenv LD_LIBRARY_PATH "$ld_library_path:$orig_ld_library_path"
140 } else {
141 setenv LD_LIBRARY_PATH "$ld_library_path"
143 if { $orig_ld_run_path_saved } {
144 setenv LD_RUN_PATH "$ld_library_path:$orig_ld_run_path"
145 } else {
146 setenv LD_RUN_PATH "$ld_library_path"
148 # The default shared library dynamic path search for 64-bit
149 # HP-UX executables searches LD_LIBRARY_PATH before SHLIB_PATH.
150 # LD_LIBRARY_PATH isn't used for 32-bit executables. Thus, we
151 # set LD_LIBRARY_PATH and SHLIB_PATH as if they were independent.
152 if { $orig_shlib_path_saved } {
153 setenv SHLIB_PATH "$ld_library_path:$orig_shlib_path"
154 } else {
155 setenv SHLIB_PATH "$ld_library_path"
157 if { $orig_ld_library_path_32_saved } {
158 setenv LD_LIBRARY_PATH_32 "$ld_library_path:$orig_ld_library_path_32"
159 } elseif { $orig_ld_library_path_saved } {
160 setenv LD_LIBRARY_PATH_32 "$ld_library_path:$orig_ld_library_path"
161 } else {
162 setenv LD_LIBRARY_PATH_32 "$ld_library_path"
164 if { $orig_ld_library_path_64_saved } {
165 setenv LD_LIBRARY_PATH_64 "$ld_library_path:$orig_ld_library_path_64"
166 } elseif { $orig_ld_library_path_saved } {
167 setenv LD_LIBRARY_PATH_64 "$ld_library_path:$orig_ld_library_path"
168 } else {
169 setenv LD_LIBRARY_PATH_64 "$ld_library_path"
172 if { [istarget *-*-darwin*] } {
173 if { [info exists ENABLE_DARWIN_AT_RPATH] || [istarget *-*-darwin1\[5-9\]*]
174 || [istarget *-*-darwin2*] } {
175 # Either we are not using DYLD_LIBRARY_PATH or we're on a version of the
176 # OS for which it is not passed through system exes.
177 if [info exists env(DYLD_LIBRARY_PATH)] {
178 unsetenv DYLD_LIBRARY_PATH
180 } else {
181 if { $orig_dyld_library_path_saved } {
182 setenv DYLD_LIBRARY_PATH "$ld_library_path:$orig_dyld_library_path"
183 } else {
184 setenv DYLD_LIBRARY_PATH "$ld_library_path"
188 if { [istarget *-*-cygwin*] || [istarget *-*-mingw*] } {
189 if { $orig_path_saved } {
190 setenv PATH "$ld_library_path:$orig_path"
191 } else {
192 setenv PATH "$ld_library_path"
196 verbose -log "set paths"
197 verbose -log "LD_LIBRARY_PATH=[getenv LD_LIBRARY_PATH]"
198 verbose -log "LD_RUN_PATH=[getenv LD_RUN_PATH]"
199 verbose -log "SHLIB_PATH=[getenv SHLIB_PATH]"
200 verbose -log "LD_LIBRARY_PATH_32=[getenv LD_LIBRARY_PATH_32]"
201 verbose -log "LD_LIBRARY_PATH_64=[getenv LD_LIBRARY_PATH_64]"
202 verbose -log "DYLD_LIBRARY_PATH=[getenv DYLD_LIBRARY_PATH]"
205 #######################################
206 # proc restore_gcc_exec_prefix_env_var { }
207 #######################################
209 proc restore_gcc_exec_prefix_env_var { } {
210 global orig_gcc_exec_prefix_saved
211 global orig_gcc_exec_prefix
212 global env
214 if { $orig_gcc_exec_prefix_saved } {
215 setenv GCC_EXEC_PREFIX "$orig_gcc_exec_prefix"
216 } elseif [info exists env(GCC_EXEC_PREFIX)] {
217 unsetenv GCC_EXEC_PREFIX
221 #######################################
222 # proc restore_ld_library_path_env_vars { }
223 #######################################
225 proc restore_ld_library_path_env_vars { } {
226 global orig_environment_saved
227 global orig_ld_library_path_saved
228 global orig_ld_run_path_saved
229 global orig_shlib_path_saved
230 global orig_ld_library_path_32_saved
231 global orig_ld_library_path_64_saved
232 global orig_dyld_library_path_saved
233 global orig_path_saved
234 global orig_ld_library_path
235 global orig_ld_run_path
236 global orig_shlib_path
237 global orig_ld_library_path_32
238 global orig_ld_library_path_64
239 global orig_dyld_library_path
240 global orig_path
241 global env
243 restore_gcc_exec_prefix_env_var
245 if { $orig_environment_saved == 0 } {
246 return
249 if { $orig_ld_library_path_saved } {
250 setenv LD_LIBRARY_PATH "$orig_ld_library_path"
251 } elseif [info exists env(LD_LIBRARY_PATH)] {
252 unsetenv LD_LIBRARY_PATH
254 if { $orig_ld_run_path_saved } {
255 setenv LD_RUN_PATH "$orig_ld_run_path"
256 } elseif [info exists env(LD_RUN_PATH)] {
257 unsetenv LD_RUN_PATH
259 if { $orig_shlib_path_saved } {
260 setenv SHLIB_PATH "$orig_shlib_path"
261 } elseif [info exists env(SHLIB_PATH)] {
262 unsetenv SHLIB_PATH
264 if { $orig_ld_library_path_32_saved } {
265 setenv LD_LIBRARY_PATH_32 "$orig_ld_library_path_32"
266 } elseif [info exists env(LD_LIBRARY_PATH_32)] {
267 unsetenv LD_LIBRARY_PATH_32
269 if { $orig_ld_library_path_64_saved } {
270 setenv LD_LIBRARY_PATH_64 "$orig_ld_library_path_64"
271 } elseif [info exists env(LD_LIBRARY_PATH_64)] {
272 unsetenv LD_LIBRARY_PATH_64
274 if { $orig_dyld_library_path_saved } {
275 setenv DYLD_LIBRARY_PATH "$orig_dyld_library_path"
276 } elseif [info exists env(DYLD_LIBRARY_PATH)] {
277 unsetenv DYLD_LIBRARY_PATH
279 if { $orig_path_saved } {
280 setenv PATH "$orig_path"
281 } elseif [info exists env(PATH)] {
282 unsetenv PATH
286 #######################################
287 # proc get_shlib_extension { }
288 #######################################
290 proc get_shlib_extension { } {
291 global shlib_ext
293 if { [istarget *-*-darwin*] } {
294 set shlib_ext "dylib"
295 } elseif { [istarget *-*-cygwin*] || [istarget *-*-mingw*] } {
296 set shlib_ext "dll"
297 } elseif { [istarget hppa*-*-hpux*] } {
298 set shlib_ext "sl"
299 } else {
300 set shlib_ext "so"
302 return $shlib_ext