1 # Copyright 2004-2019 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 this program. If not, see <http://www.gnu.org/licenses/>.
18 # FIXME:brobecker/2004-03-31:
19 # The following functions should eventually be part of dejagnu. Even after
20 # these functions becomes available in dejagnu, we will keep for a while
21 # a copy here in order to avoid increasing the dejagnu version
24 proc gdb_find_gnatmake {} {
27 set root "$tool_root_dir/gcc"
30 if ![is_remote host] {
31 set file [lookfor_file $root gnatmake]
33 set GM "$file -I$root/ada/rts --GCC=$root/xgcc --GNATBIND=$root/gnatbind --GNATLINK=$root/gnatlink -cargs -B$root -largs --GCC=$root/xgcc -margs";
38 set GM [transform gnatmake]
44 proc gdb_find_gdc {} {
46 print "Tool Root: $tool_root_dir"
48 if {![is_remote host]} {
49 set file [lookfor_file $tool_root_dir gdc]
51 set file [lookfor_file $tool_root_dir gcc/gdc]
54 set CC "$file -B[file dirname $file]/"
56 set CC [transform gdc]
59 set CC [transform gdc]
65 proc gdb_find_gfortran {} {
68 if {![is_remote host]} {
69 set file [lookfor_file $tool_root_dir gfortran]
71 set file [lookfor_file $tool_root_dir gcc/gfortran]
74 set CC "$file -B[file dirname $file]/"
76 set CC [transform gfortran]
79 set CC [transform gfortran]
89 if {![is_remote host]} {
90 set file [lookfor_file $tool_root_dir gccgo]
92 set root [file dirname $file]
93 set GO "$file -B$root/gcc/"
98 set GO [transform gccgo]
104 proc gdb_find_go_linker {} {
108 proc gdb_find_rustc {} {
110 if {![is_remote host]} {
111 set rustc [lookfor_file $tool_root_dir rustc]
119 append rustc " --color never"
124 proc gdb_find_hipcc {} {
126 if {![is_remote host]} {
127 set hipcc [lookfor_file $tool_root_dir hipcc]
129 set hipcc [lookfor_file /opt/rocm/bin hipcc]
137 proc gdb_find_ldd {} {
138 global LDD_FOR_TARGET
139 if [info exists LDD_FOR_TARGET] {
140 set ldd $LDD_FOR_TARGET
147 proc gdb_find_objcopy {} {
148 global OBJCOPY_FOR_TARGET
149 if [info exists OBJCOPY_FOR_TARGET] {
150 set objcopy $OBJCOPY_FOR_TARGET
152 set objcopy [transform objcopy]
157 # find target objdump
158 proc gdb_find_objdump {} {
159 global OBJDUMP_FOR_TARGET
160 if [info exists OBJDUMP_FOR_TARGET] {
161 set objdump $OBJDUMP_FOR_TARGET
163 set objdump [transform objdump]
168 proc gdb_find_readelf {} {
169 global READELF_FOR_TARGET
170 if [info exists READELF_FOR_TARGET] {
171 set readelf $READELF_FOR_TARGET
173 set readelf [transform readelf]
178 proc gdb_find_eu-unstrip {} {
179 global EU_UNSTRIP_FOR_TARGET
180 if [info exists EU_UNSTRIP_FOR_TARGET] {
181 set eu_unstrip $EU_UNSTRIP_FOR_TARGET
183 set eu_unstrip [transform eu-unstrip]
188 proc gdb_default_target_compile {source destfile type options} {
189 global target_triplet
191 global CFLAGS_FOR_TARGET
192 global compiler_flags
194 if { $destfile == "" && $type != "preprocess" && $type != "none" } {
195 error "Must supply an output filename for the compile to default_target_compile"
201 set compiler_type "c"
204 # linker_opts_order is one of "sources-then-flags", "flags-then-sources".
205 # The order matters for things like -Wl,--as-needed. The default is to
206 # preserve existing behavior.
207 set linker_opts_order "sources-then-flags"
209 set dest [target_info name]
211 if {[info exists CFLAGS_FOR_TARGET]} {
212 append add_flags " $CFLAGS_FOR_TARGET"
215 if {[info exists target_info(host,name)]} {
216 set host [host_info name]
224 set compiler_type "ada"
225 if {[board_info $dest exists adaflags]} {
226 append add_flags " [target_info adaflags]"
228 if {[board_info $dest exists gnatmake]} {
229 set compiler [target_info gnatmake]
231 set compiler [find_gnatmake]
236 set compiler_type "c++"
237 if {[board_info $dest exists cxxflags]} {
238 append add_flags " [target_info cxxflags]"
240 append add_flags " [g++_include_flags]"
241 if {[board_info $dest exists c++compiler]} {
242 set compiler [target_info c++compiler]
244 set compiler [find_g++]
249 set compiler_type "d"
250 if {[board_info $dest exists dflags]} {
251 append add_flags " [target_info dflags]"
253 if {[board_info $dest exists dcompiler]} {
254 set compiler [target_info dcompiler]
256 set compiler [find_gdc]
261 set compiler_type "f77"
262 if {[board_info $dest exists f77flags]} {
263 append add_flags " [target_info f77flags]"
265 if {[board_info $dest exists f77compiler]} {
266 set compiler [target_info f77compiler]
268 set compiler [find_g77]
273 set compiler_type "f90"
274 if {[board_info $dest exists f90flags]} {
275 append add_flags " [target_info f90flags]"
277 if {[board_info $dest exists f90compiler]} {
278 set compiler [target_info f90compiler]
280 set compiler [find_gfortran]
285 set compiler_type "go"
286 if {[board_info $dest exists goflags]} {
287 append add_flags " [target_info goflags]"
289 if {[board_info $dest exists gocompiler]} {
290 set compiler [target_info gocompiler]
292 set compiler [find_go]
294 if {[board_info $dest exists golinker]} {
295 set linker [target_info golinker]
297 set linker [find_go_linker]
299 if {[board_info $dest exists golinker_opts_order]} {
300 set linker_opts_order [target_info golinker_opts_order]
304 if { $i == "rust" } {
305 set compiler_type "rust"
306 if {[board_info $dest exists rustflags]} {
307 append add_flags " [target_info rustflags]"
309 if {[board_info $dest exists rustflags]} {
310 set compiler [target_info rustflags]
312 set compiler [find_rustc]
317 set compiler_type "hip"
318 if {[board_info $dest exists hipflags]} {
319 append add_flags " [target_info hipflags]"
321 if {[board_info $dest exists hipcompiler]} {
322 set compiler [target_info hipcompiler]
324 set compiler [find_hipcc]
328 if {[regexp "^dest=" $i]} {
329 regsub "^dest=" $i "" tmp
330 if {[board_info $tmp exists name]} {
331 set dest [board_info $tmp name]
336 if {[regexp "^compiler=" $i]} {
337 regsub "^compiler=" $i "" tmp
340 if {[regexp "^early_flags=" $i]} {
341 regsub "^early_flags=" $i "" tmp
342 append early_flags " $tmp"
344 if {[regexp "^additional_flags=" $i]} {
345 regsub "^additional_flags=" $i "" tmp
346 append add_flags " $tmp"
348 if {[regexp "^ldflags=" $i]} {
349 regsub "^ldflags=" $i "" tmp
350 append ldflags " $tmp"
352 if {[regexp "^libs=" $i]} {
353 regsub "^libs=" $i "" tmp
356 if {[regexp "^incdir=" $i]} {
357 regsub "^incdir=" $i "-I" tmp
358 append add_flags " $tmp"
360 if {[regexp "^libdir=" $i]} {
361 regsub "^libdir=" $i "-L" tmp
362 append add_flags " $tmp"
364 if {[regexp "^ldscript=" $i]} {
365 regsub "^ldscript=" $i "" ldscript
367 if {[regexp "^redirect=" $i]} {
368 regsub "^redirect=" $i "" redirect
370 if {[regexp "^optimize=" $i]} {
371 regsub "^optimize=" $i "" optimize
373 if {[regexp "^timeout=" $i]} {
374 regsub "^timeout=" $i "" timeout
378 if {[board_info $host exists cflags_for_target]} {
379 append add_flags " [board_info $host cflags_for_target]"
383 global CXX_FOR_TARGET
385 global F77_FOR_TARGET
386 global F90_FOR_TARGET
387 global GNATMAKE_FOR_TARGET
389 global GO_LD_FOR_TARGET
390 global RUSTC_FOR_TARGET
391 global HIPCC_FOR_TARGET
393 if {[info exists GNATMAKE_FOR_TARGET]} {
394 if { $compiler_type == "ada" } {
395 set compiler $GNATMAKE_FOR_TARGET
399 if {[info exists CC_FOR_TARGET]} {
400 if { $compiler == "" } {
401 set compiler $CC_FOR_TARGET
405 if {[info exists CXX_FOR_TARGET]} {
406 if { $compiler_type == "c++" } {
407 set compiler $CXX_FOR_TARGET
411 if {[info exists D_FOR_TARGET]} {
412 if { $compiler_type == "d" } {
413 set compiler $D_FOR_TARGET
417 if {[info exists F77_FOR_TARGET]} {
418 if { $compiler_type == "f77" } {
419 set compiler $F77_FOR_TARGET
423 if {[info exists F90_FOR_TARGET]} {
424 if { $compiler_type == "f90" } {
425 set compiler $F90_FOR_TARGET
429 if { $compiler_type == "go" } {
430 if {[info exists GO_FOR_TARGET]} {
431 set compiler $GO_FOR_TARGET
433 if {[info exists GO_LD_FOR_TARGET]} {
434 set linker $GO_LD_FOR_TARGET
438 if {[info exists RUSTC_FOR_TARGET]} {
439 if {$compiler_type == "rust"} {
440 set compiler $RUSTC_FOR_TARGET
444 if {[info exists HIPCC_FOR_TARGET]} {
445 if {$compiler_type == "hip"} {
446 set compiler $HIPCC_FOR_TARGET
450 if { $type == "executable" && $linker != "" } {
454 if { $compiler == "" } {
455 set compiler [board_info $dest compiler]
456 if { $compiler == "" } {
457 return "default_target_compile: No compiler to compile with"
461 if {![is_remote host]} {
462 if { [which $compiler] == 0 } {
463 return "default_target_compile: Can't find $compiler."
467 if {$type == "object"} {
468 if {$compiler_type == "rust"} {
469 append add_flags "--emit obj"
471 append add_flags " -c"
475 if { $type == "preprocess" } {
476 append add_flags " -E"
479 if { $type == "assembly" } {
480 append add_flags " -S"
483 if {[board_info $dest exists cflags]} {
484 append add_flags " [board_info $dest cflags]"
487 if { $type == "executable" } {
488 if {[board_info $dest exists ldflags]} {
489 append add_flags " [board_info $dest ldflags]"
491 if { $compiler_type == "c++" } {
492 append add_flags " [g++_link_flags]"
496 catch "glob -nocomplain $tool_root_dir/libstdc++/libstdc++.so* $tool_root_dir/libstdc++/libstdc++.sl" tmp
497 if { ${tmp} != "" } {
498 if {[regexp ".*solaris2.*" $target_triplet]} {
500 append add_flags " -R$tool_root_dir/libstdc++"
501 } elseif {[regexp ".*(osf|irix5|linux).*" $target_triplet]} {
503 append add_flags " -Wl,-rpath,$tool_root_dir/libstdc++"
509 if {![info exists ldscript]} {
510 set ldscript [board_info $dest ldscript]
514 if { $i == "debug" } {
515 if {[board_info $dest exists debug_flags]} {
516 append add_flags " [board_info $dest debug_flags]"
518 append add_flags " -g"
523 if {[info exists optimize]} {
524 append add_flags " $optimize"
527 if { $type == "executable" } {
528 append add_flags " $ldflags"
530 if {[file exists $x]} {
533 append add_flags " $x"
537 if {[board_info $dest exists libs]} {
538 append add_flags " [board_info $dest libs]"
541 # This probably isn't such a good idea, but it avoids nasty
542 # hackiness in the testsuites.
543 # The math library must be linked in before the C library. The C
544 # library is linked in by the linker script, so this must be before
546 if {[board_info $dest exists mathlib]} {
547 append add_flags " [board_info $dest mathlib]"
549 append add_flags " -lm"
552 # This must be added here.
553 append add_flags " $ldscript"
555 if {[board_info $dest exists remote_link]} {
557 append add_flags " -Wl,-r"
559 if {[board_info $dest exists output_format]} {
560 append add_flags " -Wl,-oformat,[board_info $dest output_format]"
564 if {[board_info $dest exists multilib_flags]} {
565 append add_flags " [board_info $dest multilib_flags]"
568 verbose "doing compile"
571 if {[is_remote host]} {
573 set file [remote_download host $x]
575 warning "Unable to download $x to host."
576 return "Unable to download $x to host."
578 append sources " $file"
585 if {[is_remote host]} {
586 append add_flags " -o " [file tail $destfile]
587 remote_file host delete [file tail $destfile]
589 if { $destfile != "" } {
590 append add_flags " -o $destfile"
594 # This is obscure: we put SOURCES at the end when building an
595 # object, because otherwise, in some situations, libtool will
596 # become confused about the name of the actual source file.
599 set opts "$early_flags $add_flags $sources"
602 switch $linker_opts_order {
603 "flags-then-sources" {
604 set opts "$early_flags $add_flags $sources"
606 "sources-then-flags" {
607 set opts "$early_flags $sources $add_flags"
610 error "Invalid value for board_info linker_opts_order"
615 set opts "$early_flags $sources $add_flags"
619 if {[is_remote host]} {
620 if {[host_info exists use_at]} {
621 set fid [open "atfile" "w"]
624 set opts "@[remote_download host atfile]"
625 remote_file build delete atfile
629 verbose "Invoking the compiler as $compiler $opts" 2
631 if {[info exists redirect]} {
632 verbose "Redirecting output to $redirect" 2
633 set status [remote_exec host "$compiler $opts" "" "" $redirect]
635 if {[info exists timeout]} {
636 verbose "Setting timeout to $timeout" 2
637 set status [remote_exec host "$compiler $opts" "" "" "" $timeout]
639 set status [remote_exec host "$compiler $opts"]
643 set compiler_flags $opts
644 if {[is_remote host]} {
645 remote_upload host [file tail $destfile] $destfile
646 remote_file host delete [file tail $destfile]
648 set comp_output [prune_warnings [lindex $status 1]]
649 regsub "^\[\r\n\]+" $comp_output "" comp_output
650 if { [lindex $status 0] != 0 } {
651 verbose -log "compiler exited with status [lindex $status 0]"
653 if { [lindex $status 1] != "" } {
654 verbose -log "output is:\n[lindex $status 1]" 2
656 if { [lindex $status 0] != 0 && "${comp_output}" == "" } {
657 set comp_output "exit status is [lindex $status 0]"
659 return ${comp_output}
662 # See if the version of dejaGNU being used to run the testsuite is
663 # recent enough to contain support for building Ada programs or not.
664 # If not, then use the functions above in place of the ones provided
665 # by dejaGNU. This is only temporary (brobecker/2004-03-31).
667 set use_gdb_compile 0
668 if {[info procs find_gnatmake] == ""} {
669 rename gdb_find_gnatmake find_gnatmake
670 set use_gdb_compile 1
673 if {[info procs find_gfortran] == ""} {
674 rename gdb_find_gfortran find_gfortran
675 set use_gdb_compile 1
678 if {[info procs find_go_linker] == ""} {
679 rename gdb_find_go find_go
680 rename gdb_find_go_linker find_go_linker
681 set use_gdb_compile 1
684 if {[info procs find_gdc] == ""} {
685 rename gdb_find_gdc find_gdc
686 set use_gdb_compile 1
689 if {[info procs find_rustc] == ""} {
690 rename gdb_find_rustc find_rustc
691 set use_gdb_compile 1
694 if {[info procs find_hipcc] == ""} {
695 rename gdb_find_hipcc find_hipcc
696 set use_gdb_compile 1
699 if {$use_gdb_compile} {
700 catch {rename default_target_compile {}}
701 rename gdb_default_target_compile default_target_compile
705 # Provide 'lreverse' missing in Tcl before 7.5.
707 if {[info procs lreverse] == ""} {
708 proc lreverse { arg } {
710 while { [llength $retval] < [llength $arg] } {
711 lappend retval [lindex $arg end-[llength $retval]]
717 # Various ccache versions provide incorrect debug info such as ignoring
718 # different current directory, breaking GDB testsuite.
719 set env(CCACHE_DISABLE) 1
720 unset -nocomplain env(CCACHE_NODISABLE)