Debian Codegraph @

gcc/testsuite/lib/gm2.exp

raw
1 # Copyright (C) 2003-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 Gaius Mulley ([email protected])
18 # for GNU Modula-2.
19
20 # we want to use libgloss so we can get find_gcc.
21 load_lib libgloss.exp
22 load_lib prune.exp
23 load_lib gcc-defs.exp
24 load_lib target-libpath.exp
25 load_lib timeout.exp
26
27 #
28 # GCC_UNDER_TEST is the compiler under test.
29 #
30
31 #
32 # default_gcc_version -- extract and print the version number of the compiler
33 #
34
35 proc default_gcc_version { } {
36 global GCC_UNDER_TEST
37
38 gm2_init
39
40 # ignore any arguments after the command
41 set compiler [lindex $GCC_UNDER_TEST 0]
42
43 if ![is_remote host] {
44 set compiler_name [which $compiler]
45 } else {
46 set compiler_name $compiler
47 }
48
49 # verify that the compiler exists
50 if { $compiler_name != 0 } then {
51 set tmp [remote_exec host "$compiler --version"]
52 set status [lindex $tmp 0]
53 set output [lindex $tmp 1]
54 regexp "version.*$" $output version
55 if { $status == 0 && [info exists version] } then {
56 clone_output "$compiler_name $version\n"
57 } else {
58 clone_output "Couldn't determine version of $compiler_name: $output\n"
59 }
60 } else {
61 # compiler does not exist (this should have already been detected)
62 warning "$compiler does not exist"
63 }
64 }
65
66 #
67 # gcc_version -- Call default_gcc_version, so we can override it if needed.
68 #
69
70 proc gcc_version { } {
71 default_gcc_version
72 }
73
74 #
75 # gm2_init -- called at the start of each .exp script.
76 #
77 # There currently isn't much to do, but always using it allows us to
78 # make some enhancements without having to go back and rewrite the scripts.
79 #
80
81 set gm2_initialized 0
82 set gm2_compile_method "default"
83 set gm2_link_path ""
84 set gm2_link_libraries "m2pim m2iso"
85 set gm2_link_objects ""
86
87 proc gm2_set_compile_method { arg } {
88 global gm2_compile_method
89
90 send_log "********************************************\n"
91 send_log "**** setting gm2_compile_method to $arg ****\n"
92 send_log "********************************************\n"
93 set gm2_compile_method $arg
94 }
95
96
97 proc gm2_init { args } {
98 global tmpdir
99 global objdir
100 global rootme
101 global base_dir
102 global tool_root_dir
103 global gluefile wrap_flags
104 global gm2_initialized
105 global GCC_UNDER_TEST
106 global TOOL_EXECUTABLE
107 global gm2_link_libraries
108 global gm2_link_objects
109 global gm2_link_path
110 global HAVE_LIBSTDCXX_V3
111
112 if { $gm2_initialized == 1 } { return }
113
114 set gm2_link_objects ""
115 set GCC_UNDER_TEST [lookfor_file $rootme gm2]
116 append GCC_UNDER_TEST " " -B[file dirname $rootme]/gcc " " ${args}
117 append GCC_UNDER_TEST " " -fno-diagnostics-show-caret
118 append GCC_UNDER_TEST " " -fno-diagnostics-show-line-numbers
119 append GCC_UNDER_TEST " " -fdiagnostics-color=never
120 send_log "GCC_UNDER_TEST is ${GCC_UNDER_TEST}\n"
121
122 if ![info exists tmpdir] then {
123 set tmpdir /tmp
124 }
125 if {[target_info needs_status_wrapper] != "" && \
126 [target_info needs_status_wrapper] != "0" && \
127 ![info exists gluefile]} {
128 set gluefile ${tmpdir}/gcc-testglue.o
129 set result [build_wrapper $gluefile]
130 if { $result != "" } {
131 set gluefile [lindex $result 0]
132 set wrap_flags [lindex $result 1]
133 } else {
134 unset gluefile
135 }
136 }
137
138 set gm2_link_path "[gm2_link_flags [get_multilibs]]"
139 verbose $gm2_link_path 1
140 }
141
142
143 #
144 # gm2_target_compile_default -- compile a source file
145 #
146
147 proc gm2_target_compile_default { source dest type options } {
148 global gluefile wrap_flags
149 global GCC_UNDER_TEST
150 global TOOL_OPTIONS
151 global TEST_ALWAYS_FLAGS
152 global gm2_link_objects
153 global gm2_link_libraries
154 global gm2_link_path
155
156 if {[target_info needs_status_wrapper] != "" && \
157 [target_info needs_status_wrapper] != "0" && \
158 [info exists gluefile] } {
159 lappend options "libs=${gluefile}"
160 lappend options "ldflags=$wrap_flags"
161 }
162
163 # TEST_ALWAYS_FLAGS are flags that should be passed to every
164 # compilation. They are passed first to allow individual
165 # tests to override them.
166 if [info exists TEST_ALWAYS_FLAGS] {
167 set options [concat "{additional_flags=$TEST_ALWAYS_FLAGS}" $options]
168 }
169
170 global TEST_EXTRA_LIBS
171 if [info exists TEST_EXTRA_LIBS] {
172 lappend options "ldflags=$TEST_EXTRA_LIBS"
173 }
174
175 if [target_info exists gcc,stack_size] {
176 lappend options "additional_flags=-DSTACK_SIZE=[target_info gcc,stack_size]"
177 }
178 if [target_info exists gcc,no_trampolines] {
179 lappend options "additional_flags=-DNO_TRAMPOLINES"
180 }
181 if [target_info exists gcc,no_label_values] {
182 lappend options "additional_flags=-DNO_LABEL_VALUES"
183 }
184 if [info exists TOOL_OPTIONS] {
185 lappend options "additional_flags=$TOOL_OPTIONS"
186 }
187 if [istarget *-*-solaris2*] {
188 lappend options "ldflags=-lnsl -lsocket"
189 }
190 if [istarget "powerpc-*-*"] {
191 lappend options "-mabi=ieeelongdouble"
192 }
193
194 lappend options "timeout=[timeout_value]"
195 lappend options "compiler=$GCC_UNDER_TEST"
196 # puts stderr "options = $options\n"
197 # puts stderr "***** target_compile: $source $dest $type $options\n"
198 return [target_compile $source $dest $type $options]
199 }
200
201
202 #
203 # gm2_target_compile -- compile a source file
204 #
205
206 proc gm2_target_compile { source dest type options } {
207 global gm2_compile_method
208
209 return [gm2_target_compile_${gm2_compile_method} $source $dest $type $options]
210 }
211
212
213 #
214 # gm2_link_lib - allows tests to specify link libraries.
215 # This _must_ be called before gm2_init.
216 #
217
218 proc gm2_link_lib { libraries } {
219 global gm2_link_libraries
220
221 set gm2_link_libraries $libraries
222 }
223
224
225 #
226 # gm2_link_obj - allows tests to specify link with objects.
227 #
228
229 proc gm2_link_obj { objects } {
230 global gm2_link_objects
231
232 set gm2_link_objects $objects
233 }
234
235
236 #
237 # gm2_link_flags - detects the whereabouts of libraries (-lstdc++).
238 #
239
240 proc gm2_link_flags { paths } {
241 global srcdir
242 global ld_library_path
243 global gccpath
244 global gm2_link_libraries
245
246 set gccpath ${paths}
247 set libio_dir ""
248 set flags ""
249 set ld_library_path "."
250
251 set shlib_ext [get_shlib_extension]
252 verbose "shared lib extension: $shlib_ext"
253
254 if [istarget "powerpc-*-*"] {
255 lappend flags "-mabi=ieeelongdouble"
256 }
257
258 # We need to add options to locate gm2 libs and libstdc++
259 # Usually '-L' options are added to point to the relevant directories for
260 # the uninstalled libraries.
261
262 # In cases where libraries are available as both shared and convenience
263 # some additional checks are made.
264
265 # For some targets -static-xxxx options are handled by specs substitution
266 # and need a '-B' option rather than '-L'. For Darwin, when embedded
267 # runpaths are in use (the default for all versions after macOS 10.11),
268 # '-B' is also needed to provide the runpath.
269 # When '-B' is used, this results in a '-L' for each path that exists (so
270 # that appending a '-L' as well is a needless duplicate). There are also
271 # cases where tools warn for duplicates, leading to spurious fails.
272 # Therefore the objective of the code below is to add just one '-L' or
273 # '-B' for each of the libraries.
274
275 set target_wants_B_option 0
276 if { [istarget *-*-darwin9* ] || [istarget *-*-darwin\[12\]* ] } {
277 set target_wants_B_option 1
278 }
279
280 if { $gccpath == "" } {
281 global tool_root_dir
282
283 set libstdcpp [lookfor_file ${tool_root_dir} libstdc++]
284 if { $libstdcpp != "" } {
285 append flags " -L${libstdcpp} "
286 append ld_library_path ":${libstdcpp}"
287 }
288 } else {
289 if [file exists "${gccpath}/lib/libstdc++.a"] {
290 append ld_library_path ":${gccpath}/lib"
291 }
292 if [file exists "${gccpath}/libstdc++/libstdc++.a"] {
293 append flags " -L${gccpath}/libstdc++ "
294 append ld_library_path ":${gccpath}/libstdc++"
295 }
296 # Look for libstdc++.<a,${shlib_ext}>.
297 if { [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] \
298 || [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.${shlib_ext}"] } {
299 if { $target_wants_B_option } {
300 append flags " -B${gccpath}/libstdc++-v3/src/.libs "
301 } else {
302 append flags " -L${gccpath}/libstdc++-v3/src/.libs "
303 }
304 append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
305 }
306
307 # Here we are forcing the static libraries, with complete paths so
308 # there's no -L/-B logic needed
309 # puts stderr "${gm2_link_libraries} before foreach"
310 foreach d [list {*}${gm2_link_libraries}] {
311 # puts stderr "${d} XXXX"
312 send_log "ld_library_path was ${ld_library_path}\n"
313 send_log "looking for ${gccpath}/lib${d}/.libs/lib${d}.a\n"
314 if [file exists "${gccpath}/libgm2/lib${d}/.libs/lib${d}.a"] {
315 send_log "good found ${gccpath}/libgm2/lib${d}/.libs/lib${d}.a\n"
316 # append flags " -L${gccpath}/libgm2/lib${d}/.libs -l${d}"
317 append flags " ${gccpath}/libgm2/lib${d}/.libs/lib${d}.a "
318 append ld_library_path ":${gccpath}/libgm2/lib${d}/.libs"
319 }
320 send_log "ld_library_path is ${ld_library_path}\n"
321 }
322
323 global GCC_UNDER_TEST
324 append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
325 }
326
327 set_ld_library_path_env_vars
328 return "$flags"
329 }
330
331
332 #
333 # gm2_init_pimx - set the default libraries to choose PIM and then ISO.
334 # choose Modula-2, dialect.
335 #
336 #
337
338 proc gm2_init_pimx { dialect paths args } {
339 global srcdir
340 global gccpath
341
342 set gm2src ${srcdir}/../m2
343
344
345 send_log "srcdir is $srcdir\n"
346 send_log "gccpath is $gccpath\n"
347 send_log "gm2src is $gm2src\n"
348
349 set theIpath -fm2-pathname=m2pim
350 lappend theIpath -I${gccpath}/libgm2/libm2pim
351 lappend theIpath -fm2-pathname=m2log
352 lappend theIpath -I${gm2src}/gm2-libs-log
353
354 # NOTE:
355 lappend theIpath -fm2-pathname=m2pim
356 lappend theIpath -I${gm2src}/gm2-libs
357
358 set theLpath -L${gccpath}/libgm2/libm2pim/.libs
359
360 lappend theIpath -fm2-pathname=m2iso
361 lappend theIpath -I${gccpath}/libgm2/libm2iso
362 lappend theIpath -I${gm2src}/gm2-libs-iso
363
364 lappend theLpath -L${gccpath}/libgm2/libm2iso/.libs
365
366 lappend theIpath -fm2-pathname=-
367 foreach p $paths {
368 lappend theIpath -I$p
369 }
370 lappend theIpath -fm2-pathname=-
371
372 gm2_link_lib "m2pim m2iso"
373 lappend args -fno-libs=-
374 gm2_init {*}${theIpath} {*}${dialect} {*}${theLpath} {*}${args}
375 }
376
377 #
378 # gm2_init_pim - set the default libraries to choose PIM and then ISO.
379 #
380 #
381
382 proc gm2_init_pim { paths args } {
383 gm2_init_pimx -fpim $paths {*}${args}
384 }
385
386
387 #
388 # gm2_init_pim2 - set the default libraries to choose PIM and then ISO.
389 # It uses the PIM2 dialect.
390 #
391
392 proc gm2_init_pim2 { paths args } {
393 gm2_init_pimx -fpim2 $paths {*}${args}
394 }
395
396
397 #
398 # gm2_init_pim3 - set the default libraries to choose PIM and then ISO.
399 # It uses the PIM3 dialect.
400 #
401
402 proc gm2_init_pim3 { paths args } {
403 gm2_init_pimx -fpim3 $paths {*}${args}
404 }
405
406
407 #
408 # gm2_init_pim4 - set the default libraries to choose PIM and then ISO.
409 # It uses the PIM4 dialect.
410 #
411
412 proc gm2_init_pim4 { paths args } {
413 gm2_init_pimx -fpim4 $paths {*}${args}
414 }
415
416
417 #
418 # gm2_init_iso - set the default libraries to choose ISO and then PIM.
419 #
420
421 proc gm2_init_iso { paths args } {
422 global srcdir
423 global gccpath
424
425 set gm2src ${srcdir}/../m2
426
427 set theIpath -fm2-pathname=m2iso
428 lappend theIpath -I${gccpath}/libgm2/libm2iso
429 lappend theIpath -I${gm2src}/gm2-libs-iso
430
431 set theLpath -L${gccpath}/libgm2/libm2iso/.libs
432
433 lappend theIpath -fm2-pathname=m2pim
434 lappend theIpath -I${gccpath}/libgm2/libm2pim
435
436 lappend theIpath -fm2-pathname=m2log
437 lappend theIpath -I${gm2src}/gm2-libs-log
438
439 # NOTE:
440 lappend theIpath -fm2-pathname=m2pim
441 lappend theIpath -I${gm2src}/gm2-libs
442
443 lappend theLpath -L${gccpath}/libgm2/libm2pim/.libs
444
445 lappend theIpath -fm2-pathname=m2cor
446 lappend theIpath -I${gccpath}/libgm2/libm2cor
447 lappend theIpath -I${gm2src}/gm2-libs-coroutines
448
449 lappend theLpath -L${gccpath}/libgm2/libm2cor/.libs
450
451 lappend theIpath -fm2-pathname=-
452 foreach p $paths {
453 lappend theIpath -I$p
454 }
455 lappend theIpath -fm2-pathname=-
456
457 gm2_link_lib "m2iso m2pim m2cor"
458 lappend args -fno-libs=-
459 gm2_init {*}${theIpath} -fiso {*}${theLpath} {*}${args}
460 }
461
462 #
463 # gm2_init_ulm - set the default libraries to choose the ULM and PIM libraries.
464 #
465
466 proc gm2_init_ulm { paths args } {
467 global srcdir
468 global gccpath
469
470 set gm2src ${srcdir}/../m2
471
472 set theIpath -fm2-pathname=m2ulm
473 lappend theIpath -I${gccpath}/libgm2/libm2ulm
474 lappend theIpath -I${gm2src}/ulm-lib-gm2/std
475 lappend theIpath -I${gm2src}/ulm-lib-gm2/sys
476
477 set theLpath -L${gccpath}/libgm2/libm2ulm/.libs
478
479 lappend theIpath -fm2-pathname=m2pim
480 lappend theIpath -I${gccpath}/libgm2/libm2pim
481 lappend theIpath -fm2-pathname=m2log
482 lappend theIpath -I${gm2src}/gm2-libs-log
483
484 # NOTE:
485 lappend theIpath -fm2-pathname=m2pim
486 lappend theIpath -I${gm2src}/gm2-libs
487
488 lappend theLpath -L${gccpath}/libgm2/libm2pim/.libs
489
490 lappend theIpath -fm2-pathname=-
491 foreach p $paths {
492 lappend theIpath -I$p
493 }
494 lappend theIpath -fm2-pathname=-
495
496 gm2_link_lib "m2ulm m2pim"
497 lappend args -fno-libs=-
498 gm2_init {*}${theIpath} -fpim {*}${theLpath} {*}${args}
499 }
500
501
502 #
503 # gm2_init_log - set the default libraries to choose LOG and then PIM.
504 #
505 #
506
507 proc gm2_init_log { paths args } {
508 global srcdir
509 global gccpath
510
511 set gm2src ${srcdir}/../m2
512
513 send_log "srcdir is $srcdir\n"
514 send_log "gccpath is $gccpath\n"
515 send_log "gm2src is $gm2src\n"
516
517 # FIXME: this seems to interleave the library defs.
518 set theIpath -fm2-pathname=m2log
519 lappend theIpath -I${gccpath}/libgm2/libm2log
520 lappend theIpath -I${gm2src}/gm2-libs-log
521
522 set theLpath -L${gccpath}/libgm2/libm2log/.libs
523
524 lappend theIpath -fm2-pathname=m2pim
525 lappend theIpath -I${gccpath}/libgm2/libm2pim
526 lappend theIpath -I${gm2src}/gm2-libs
527
528 lappend theLpath -L${gccpath}/libgm2/libm2pim/.libs
529
530 lappend theIpath -fm2-pathname=m2iso
531 lappend theIpath -I${gccpath}/libgm2/libm2iso
532 lappend theIpath -I${gm2src}/gm2-libs-iso
533 # ??? lappend theIpath -I${gm2src}/gm2-libs
534
535 lappend theLpath -L${gccpath}/libgm2/libm2iso/.libs
536
537 lappend theIpath -fm2-pathname=-
538 foreach p $paths {
539 lappend theIpath -I$p
540 }
541 lappend theIpath -fm2-pathname=-
542
543 gm2_link_lib "m2log m2pim m2iso"
544 lappend args -fno-libs=-
545 gm2_init {*}${theIpath} -fpim {*}${theLpath} {*}${args}
546 }
547
548 #
549 # gm2_init_cor - set the default libraries to choose COR and then PIM.
550 #
551 #
552
553 proc gm2_init_cor { paths args } {
554 global srcdir
555 global gccpath
556 global gm2_link_libraries
557
558 set gm2src ${srcdir}/../m2
559
560 send_log "srcdir is $srcdir\n"
561 send_log "gccpath is $gccpath\n"
562 send_log "gm2src is $gm2src\n"
563
564 set theIpath -fm2-pathname=m2cor
565 lappend theIpath -I${gccpath}/libgm2/libm2cor
566 lappend theIpath -I${gm2src}/gm2-libs-coroutines
567
568 set theLpath -L${gccpath}/libgm2/libm2cor/.libs
569
570 lappend theIpath -fm2-pathname=m2pim
571 lappend theIpath -I${gccpath}/libgm2/libm2pim
572
573 lappend theIpath -fm2-pathname=m2log
574 lappend theIpath -I${gm2src}/gm2-libs-log
575
576 lappend theIpath -fm2-pathname=m2pim
577 lappend theLpath -L${gccpath}/libgm2/libm2pim/.libs
578
579 lappend theIpath -fm2-pathname=m2log
580 lappend theIpath -I${gccpath}/libgm2/libm2log
581
582 lappend theIpath -fm2-pathname=m2pim
583 lappend theIpath -I${gm2src}/gm2-libs
584
585 lappend theIpath -fm2-pathname=m2log
586 lappend theLpath -L${gccpath}/libgm2/libm2log/.libs
587
588 lappend theIpath -fm2-pathname=m2iso
589 lappend theIpath -I${gccpath}/libgm2/libm2iso
590 lappend theIpath -I${gm2src}/gm2-libs-iso
591
592 lappend theLpath -L${gccpath}/libgm2/libm2iso/.libs
593
594 lappend theIpath -fm2-pathname=-
595 foreach p $paths {
596 lappend theIpath -I$p
597 }
598 lappend theIpath -fm2-pathname=-
599
600 gm2_link_lib "m2cor m2pim m2log m2iso"
601 append args " -fno-libs=- "
602 gm2_init {*}${theIpath} -fpim {*}${theLpath} {*}${args}
603 }
604
605
606 #
607 # gm2_init_minx - set the default libraries to choose MIN library and
608 # choose Modula-2, dialect.
609 #
610 #
611
612 proc gm2_init_minx { dialect paths args } {
613 global srcdir
614 global gccpath
615 set gm2src ${srcdir}/../m2
616
617 send_log "srcdir is $srcdir\n"
618 send_log "gccpath is $gccpath\n"
619 send_log "gm2src is $gm2src\n"
620
621 set theIpath -fm2-pathname=m2min
622 lappend theIpath -I${gccpath}/libgm2/libm2min
623 lappend theIpath -I${gm2src}/gm2-libs-min
624
625 set theLpath -L${gccpath}/libgm2/libm2min/.libs
626
627 lappend theIpath -fm2-pathname=-
628 foreach p $paths {
629 lappend theIpath -I$p
630 }
631 lappend theIpath -fm2-pathname=-
632
633 gm2_link_lib "m2min"
634 lappend args -fno-exceptions
635 lappend args -fno-libs=-
636 gm2_init {*}${theIpath} {*}${dialect} {*}${theLpath} {*}${args}
637 }
638
639 #
640 # gm2_init_min - set the default libraries to choose MIN libraries
641 # and pim dialect.
642 #
643
644 proc gm2_init_min { paths args } {
645 gm2_init_minx -fpim $paths {*}${args}
646 }