Debian Codegraph @

gcc/testsuite/lib/obj-c++.exp

raw
1 # Copyright (C) 2004-2025 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
16
17 # This file was written by Rob Savoye ([email protected])
18 # Many modifications by Jeffrey Wheat ([email protected])
19 # With modifications by Mike Stump <[email protected]>.
20
21 #
22 # obj-c++ support library routines
23 #
24 load_lib prune.exp
25 load_lib gcc-defs.exp
26 load_lib timeout.exp
27 load_lib target-libpath.exp
28
29 #
30 # OBJCXX_UNDER_TEST is the compiler under test.
31 #
32
33
34 set gpp_compile_options ""
35
36 #
37 # obj-c++_version -- extract and print the version number of the compiler
38 #
39
40 proc obj-c++_version { } {
41 global OBJCXX_UNDER_TEST
42
43 obj-c++_init
44
45 # Ignore any arguments after the command.
46 set compiler [lindex $OBJCXX_UNDER_TEST 0]
47
48 # Verify that the compiler exists.
49 if { [is_remote host] || [which $compiler] != 0 } then {
50 set tmp [remote_exec host "$compiler -v"]
51 set status [lindex $tmp 0];
52 set output [lindex $tmp 1];
53 regexp " version \[^\n\r\]*" $output version
54 if { $status == 0 && [info exists version] } then {
55 if [is_remote host] {
56 clone_output "$compiler $version\n"
57 } else {
58 clone_output "[which $compiler] $version\n"
59 }
60 } else {
61 clone_output "Couldn't determine version of [which $compiler]\n"
62 }
63 } else {
64 # Compiler does not exist (this should have already been detected)
65 warning "$compiler does not exist"
66 }
67 }
68
69 #
70 # obj-c++_include_flags -- provide new version of obj-c++_include_flags
71 # (originally from libgloss.exp) which knows about the gcc tree structure
72 #
73 proc obj-c++_include_flags { paths } {
74 global srcdir
75 global HAVE_LIBSTDCXX_V3
76 global TESTING_IN_BUILD_TREE
77
78 set flags ""
79
80 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
81 return "${flags}"
82 }
83
84 set gccpath ${paths}
85
86 set odir [lookfor_file ${gccpath} libstdc++-v3]
87 if { ${odir} != "" } {
88 append flags [exec sh ${odir}/scripts/testsuite_flags --build-includes]
89 }
90
91 return "$flags"
92 }
93
94 #
95 # obj-c++_link_flags -- provide new version of obj-c++_link_flags
96 # (originally from libgloss.exp) which knows about the gcc tree structure.
97 #
98
99 proc obj-c++_link_flags { paths } {
100 global rootme
101 global srcdir
102 global ld_library_path
103 global OBJCXX_UNDER_TEST
104 global shlib_ext
105
106 set gccpath ${paths}
107 set libio_dir ""
108 set flags ""
109 set ld_library_path "."
110 set shlib_ext [get_shlib_extension]
111 verbose "shared lib extension: $shlib_ext"
112
113 # We need to add options to locate libobjc/libobjc-gnu and libstdc++
114 # Usually '-L' options are added to point to the relevant directories for
115 # the uninstalled libraries.
116
117 # In cases where libraries are available as both shared and convenience
118 # some additional checks are made.
119
120 # For some targets -static-xxxx options are handled by specs substitution
121 # and need a '-B' option rather than '-L'. For Darwin, when embedded
122 # runpaths are in use (the default for all versions after macOS 10.11),
123 # '-B' is also needed to provide the runpath.
124 # When '-B' is used, this results in a '-L' for each path that exists (so
125 # that appending a '-L' as well is a needless duplicate). There are also
126 # cases where tools warn for duplicates, leading to spurious fails.
127 # Therefore the objective of the code below is to add just one '-L' or
128 # '-B' for each of the libraries.
129
130 set target_wants_B_option 0
131 if { [istarget *-*-darwin9* ] || [istarget *-*-darwin\[12\]* ] } {
132 set target_wants_B_option 1
133 }
134
135 if { $gccpath != "" } {
136 if { [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] ||
137 [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.${shlib_ext}"] } {
138 if { $target_wants_B_option } {
139 append flags "-B${gccpath}/libstdc++-v3/src/.libs "
140 } else {
141 append flags "-L${gccpath}/libstdc++-v3/src/.libs "
142 }
143 append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
144 }
145
146 if [file exists "${gccpath}/libiberty/libiberty.a"] {
147 append flags " -L${gccpath}/libiberty "
148 }
149
150 if [file exists "${gccpath}/librx/librx.a"] {
151 append flags " -L${gccpath}/librx "
152 }
153
154 set objcpath "[get_multilibs]"
155 set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc.a]
156 if { $libobjc_dir == ""} {
157 set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc-gnu.a]
158 }
159 # Now check if we have a shared only build.
160 if { $libobjc_dir == ""} {
161 set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc.${shlib_ext}]
162 if { $libobjc_dir == ""} {
163 set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc-gnu.${shlib_ext}]
164 }
165 }
166
167 verbose "libobjc_dir: $libobjc_dir"
168
169 if { $libobjc_dir != "" } {
170 set libobjc_dir [file dirname ${libobjc_dir}]
171 if { $target_wants_B_option } {
172 append flags "-B${libobjc_dir} "
173 } else {
174 append flags "-L${libobjc_dir} "
175 }
176 append ld_library_path ":${libobjc_dir}"
177 }
178 append ld_library_path \
179 [gcc-set-multilib-library-path $OBJCXX_UNDER_TEST]
180 } else {
181 global tool_root_dir;
182
183 set libgpp [lookfor_file ${tool_root_dir} libg++];
184 if { $libgpp != "" } {
185 append flags "-L${libgpp} ";
186 append ld_library_path ":${libgpp}"
187 }
188 set libstdcpp [lookfor_file ${tool_root_dir} libstdc++];
189 if { $libstdcpp != "" } {
190 if { $target_wants_B_option } {
191 append flags "-B${libstdcpp} "
192 } else {
193 append flags "-L${libstdcpp} "
194 }
195 append ld_library_path ":${libstdcpp}"
196 }
197 set libiberty [lookfor_file ${tool_root_dir} libiberty];
198 if { $libiberty != "" } {
199 append flags "-L${libiberty} ";
200 }
201 set librx [lookfor_file ${tool_root_dir} librx];
202 if { $librx != "" } {
203 append flags "-L${librx} ";
204 }
205 }
206
207 set_ld_library_path_env_vars
208
209 return "$flags"
210 }
211
212 #
213 # obj-c++_init -- called at the start of each subdir of tests
214 #
215
216 proc obj-c++_init { args } {
217 global subdir
218 global gpp_initialized
219 global base_dir
220 global tmpdir
221 global libdir
222 global gluefile wrap_flags;
223 global objdir srcdir
224 global ALWAYS_OBJCXXFLAGS
225 global TOOL_EXECUTABLE TOOL_OPTIONS
226 global OBJCXX_UNDER_TEST
227 global TESTING_IN_BUILD_TREE
228 global gcc_warning_prefix
229 global gcc_error_prefix
230 global TEST_ALWAYS_FLAGS
231
232 if ![info exists OBJCXX_UNDER_TEST] then {
233 if [info exists TOOL_EXECUTABLE] {
234 set OBJCXX_UNDER_TEST $TOOL_EXECUTABLE;
235 } else {
236 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
237 set OBJCXX_UNDER_TEST [transform c++]
238 } else {
239 set OBJCXX_UNDER_TEST [findfile $base_dir/../../xg++ "$base_dir/../../xg++ -B$base_dir/../../" [findfile $base_dir/xg++ "$base_dir/xg++ -B$base_dir/" [transform c++]]]
240 }
241 }
242 }
243
244 # Bleah, nasty. Bad taste.
245 if [ishost "*-dos-*" ] {
246 regsub "c\\+\\+" "$OBJCXX_UNDER_TEST" "gcc" OBJCXX_UNDER_TEST
247 }
248
249 if ![is_remote host] {
250 if { [which $OBJCXX_UNDER_TEST] == 0 } then {
251 perror "OBJCXX_UNDER_TEST ($OBJCXX_UNDER_TEST) does not exist"
252 exit 1
253 }
254 }
255 if ![info exists tmpdir] {
256 set tmpdir "/tmp"
257 }
258
259 if [info exists gluefile] {
260 unset gluefile
261 }
262
263 obj-c++_maybe_build_wrapper "${tmpdir}/obj-c++-testglue.o" "-fexceptions"
264
265 set ALWAYS_OBJCXXFLAGS ""
266
267 # TEST_ALWAYS_FLAGS are flags that should be passed to every
268 # compilation. They are passed first to allow individual
269 # tests to override them.
270 if [info exists TEST_ALWAYS_FLAGS] {
271 lappend ALWAYS_OBJCXXFLAGS "additional_flags=$TEST_ALWAYS_FLAGS"
272 }
273
274 if ![is_remote host] {
275 if [info exists TOOL_OPTIONS] {
276 lappend ALWAYS_OBJCXXFLAGS "additional_flags=[obj-c++_include_flags [get_multilibs ${TOOL_OPTIONS}] ]";
277 lappend ALWAYS_OBJCXXFLAGS "ldflags=[obj-c++_link_flags [get_multilibs ${TOOL_OPTIONS}] ]";
278 } else {
279 lappend ALWAYS_OBJCXXFLAGS "additional_flags=[obj-c++_include_flags [get_multilibs] ]";
280 lappend ALWAYS_OBJCXXFLAGS "ldflags=[obj-c++_link_flags [get_multilibs] ]";
281 }
282 }
283
284 if [info exists TOOL_OPTIONS] {
285 lappend ALWAYS_OBJCXXFLAGS "additional_flags=$TOOL_OPTIONS";
286 }
287
288 # Make sure that lines are not wrapped. That can confuse the
289 # error-message parsing machinery.
290 lappend ALWAYS_OBJCXXFLAGS "additional_flags=-fmessage-length=0"
291
292 set gcc_warning_prefix "warning:"
293 set gcc_error_prefix "(fatal )?error:"
294
295 verbose -log "ALWAYS_OBJCXXFLAGS set to $ALWAYS_OBJCXXFLAGS"
296
297 verbose "obj-c++ is initialized" 3
298 }
299
300 #
301 # obj-c++_target_compile -- compile a source file
302 #
303
304 proc obj-c++_target_compile { source dest type options } {
305 global tmpdir
306 global srcdir
307 global gpp_compile_options
308 global gluefile wrap_flags
309 global ALWAYS_OBJCXXFLAGS
310 global OBJCXX_UNDER_TEST
311 global shlib_ext
312
313 set shlib_ext [get_shlib_extension]
314 verbose "input-options: $options" 4
315
316 # We have to figure out which runtime will be used on darwin because
317 # we need to add the include path for the gnu runtime if that is in
318 # use.
319 # First, set the default...
320 if { [istarget *-*-darwin*] } {
321 set nextruntime 1
322 } else {
323 set nextruntime 0
324 }
325 verbose "initial next runtime state : $nextruntime" 2
326 # Next, see if we define the option in dg-options...
327 foreach opt $options {
328 if [regexp ".*-fnext-runtime.*" $opt] {
329 set nextruntime 1
330 }
331 if [regexp ".*-fgnu-runtime.*" $opt] {
332 set nextruntime 0
333 }
334 }
335 verbose "next runtime state after dg opts: $nextruntime" 2
336
337 set tgt [target_info name]
338 if [board_info $tgt exists multilib_flags] {
339 set lb [board_info $tgt multilib_flags]
340 verbose "board multilib_flags $lb" 2
341 foreach opt $lb {
342 if [regexp ".*-fnext-runtime.*" $opt] {
343 set nextruntime 1
344 }
345 if [regexp ".*-fgnu-runtime.*" $opt] {
346 set nextruntime 0
347 }
348 }
349 }
350 verbose "next runtime state after any multilib opts: $nextruntime" 2
351
352 lappend options "libs=-lobjc"
353
354 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
355 lappend options "libs=${gluefile}"
356 lappend options "ldflags=${wrap_flags}"
357 }
358
359 # If we have built libobjc along with the compiler, point the test harness
360 # at it (and associated headers).
361
362 set objcpath "[get_multilibs]"
363
364 set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc.a]
365 if { $libobjc_dir == ""} {
366 set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc-gnu.a]
367 }
368 if { $libobjc_dir == ""} {
369 set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc.${shlib_ext}]
370 if { $libobjc_dir == ""} {
371 set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc-gnu.${shlib_ext}]
372 }
373 }
374
375 if { $libobjc_dir != "" } {
376 # If we are using the gnu runtime, add its includes.
377 if { $nextruntime == 0 } {
378 set objc_include_dir "${srcdir}/../../libobjc"
379 lappend options "additional_flags=-I${objc_include_dir}"
380 }
381 }
382
383 lappend options "additional_flags=[libio_include_flags]"
384 lappend options "compiler=$OBJCXX_UNDER_TEST";
385 lappend options "timeout=[timeout_value]"
386
387 set options [concat $gpp_compile_options $options]
388
389 set options [concat "$ALWAYS_OBJCXXFLAGS" $options];
390
391 set options [dg-additional-files-options $options $source $dest $type]
392
393 set result [target_compile $source $dest $type $options]
394
395 return $result
396 }
397
398 #
399 # ${tool}_option_help
400 #
401
402 proc ${tool}_option_help { } {
403 send_user " --additional_options,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated.\n"
404 }
405
406 #
407 # ${tool}_option_proc
408 #
409
410 proc ${tool}_option_proc { option } {
411 if [regexp "^--additional_options," $option] {
412 global gpp_compile_options
413 regsub "--additional_options," $option "" option
414 foreach x [split $option ","] {
415 lappend gpp_compile_options "additional_flags=$x"
416 }
417 return 1;
418 } else {
419 return 0
420 }
421 }