1 # Basic expect script for LD Regression Tests
2 # Copyright (C) 1993-2015 Free Software Foundation, Inc.
4 # This file is part of the GNU Binutils.
6 # This file is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 # Written by Jeffrey Wheat (cassidy@cygnus.com)
24 if ![info exists ld] then {
25 set ld [findfile $base_dir/ld-new $base_dir/ld-new [transform ld]]
28 if ![info exists as] then {
29 set as [findfile $base_dir/../gas/as-new $base_dir/../gas/as-new [transform as]]
32 if ![info exists nm] then {
33 set nm [findfile $base_dir/../binutils/nm-new $base_dir/../binutils/nm-new [transform nm]]
36 if ![info exists objdump] then {
37 set objdump [findfile $base_dir/../binutils/objdump]
40 if ![info exists objcopy] then {
41 set objcopy [findfile $base_dir/../binutils/objcopy]
44 if ![info exists ar] then {
45 set ar [findfile $base_dir/../binutils/ar]
48 if ![info exists strip] then {
49 set strip [findfile $base_dir/../binutils/strip-new $base_dir/../binutils/strip-new [transform strip]]
52 remote_exec host "mkdir -p tmpdir"
54 # Make symlinks from tmpdir/ld to the linker and assembler in the
55 # build tree, so that we can use a -B option to gcc to force it to use
56 # the newly built linker and assembler.
57 if {![file isdirectory tmpdir/ld]} then {
58 catch "exec mkdir tmpdir/ld" status
59 catch "exec ln -s ../../ld-new tmpdir/ld/ld" status
60 catch "exec ln -s ld tmpdir/ld/collect-ld" status
61 catch "exec ln -s ../../../gas/as-new tmpdir/ld/as" status
63 set gcc_B_opt "-B[pwd]/tmpdir/ld/"
65 # load the linker path
67 if {[file exists tmpdir/libpath.exp]} {
68 load_lib tmpdir/libpath.exp
70 foreach dir $libpath {
71 append ld_L_opt " -L$dir"
75 # The "make check" target in the Makefile passes in
76 # "CC=$(CC_FOR_TARGET)". But, if the user invokes runtest directly
77 # (as when testing an installed linker), these flags may not be set.
78 if {![info exists CC]} {
81 if {![info exists CFLAGS]} {
84 if {![info exists CXX]} {
87 if {![info exists CXXFLAGS]} {
91 # The mips64-*-linux-gnu compiler defaults to the N32 ABI after
92 # installed, but to the O32 ABI in the build tree, because of some
93 # specs-file hacks. Make sure we use an ABI that is compatible with
95 if {[istarget mips64*-*-linux*] &&
96 (![board_info [target_info name] exists multilib_flags] ||
97 ![string match "*-mabi" [board_info [target_info name] multilib_flags]])
99 append gcc_B_opt " -mabi=n32"
102 if { [istarget rx-*-*] } {
104 set ASFLAGS "-muse-conventional-section-names"
107 # load the utility procedures
110 proc get_link_files {varname} {
112 global target_triplet
115 if ![info exists $varname] {
116 #configure.host returns variables that can be substituted into
117 #makefile rules, with embedded shell variable expansions.
118 #make wants $$shell_var, we want $shell_var ...
119 set cmd "host='$target_triplet' && . $srcdir/../configure.host && sed -e 's,\\\$\\\$,\$,g' <<EOF\n\$$varname\nEOF"
120 set status [catch "exec sh -c [list $cmd]" result]
121 if $status { error "Error getting native link files: $result" }
122 set cmd "CC='$CC' && eval echo \"$result\""
123 set status [catch "exec sh -c [list $cmd]" result]
124 if $status { error "Error getting native link files: $result" }
126 send_log "$varname = $result\n"
130 proc get_target_emul {} {
131 global target_triplet
133 set status [catch "exec sh -c \"targ='$target_triplet' && . $srcdir/../configure.tgt && echo \\\$targ_emul\"" result]
134 if $status { error "Error getting emulation name: $result" }
139 foreach x {HOSTING_CRT0 HOSTING_SCRT0 HOSTING_LIBS HOSTING_SLIBS} {
143 foreach x {HOSTING_CRT0 HOSTING_SCRT0 HOSTING_LIBS HOSTING_SLIBS} { set $x "" }
145 if ![info exists HOSTING_EMU] { set HOSTING_EMU "-m [get_target_emul]" }
148 # ld_version -- extract and print the version number of ld compiler (GCC)
152 default_ld_version $ld
156 # ld_exit -- just a stub for ld
165 proc ld_start { ld target } {
171 # link an object using relocation
173 proc ld_relocate { ld target objects } {
174 default_ld_relocate $ld $target $objects
179 # link a program using ld
181 proc ld_link { ld target objects } {
182 default_ld_link $ld $target $objects
187 # link a program using ld, without including any libraries
189 proc ld_simple_link { ld target objects } {
190 default_ld_simple_link $ld $target $objects
195 # compile an object using $cc
197 proc ld_compile { cc source object } {
198 default_ld_compile $cc $source $object
205 proc ld_assemble { as source object } {
206 default_ld_assemble $as "" $source $object
211 # assemble a file with extra flags
213 proc ld_assemble_flags { as flags source object } {
214 default_ld_assemble $as $flags $source $object
221 proc ld_nm { nm nmflags object } {
222 default_ld_nm $nm $nmflags $object
227 # execute ithe target
229 proc ld_exec { target output } {
230 default_ld_exec $target $output
233 # From gas-defs.exp, to support run_dump_test.
234 if ![info exists AS] then {
238 if ![info exists ASFLAGS] then {
242 if ![info exists OBJDUMP] then {
246 if ![info exists OBJDUMPFLAGS] then {
250 if ![info exists NM] then {
254 if ![info exists NMFLAGS] then {
258 if ![info exists OBJCOPY] then {
262 if ![info exists OBJCOPYFLAGS] then {
266 if ![info exists READELF] then {
267 set READELF [findfile $base_dir/../binutils/readelf]
270 if ![info exists READELFFLAGS] then {
274 if ![info exists LD] then {
275 set LD [findfile $base_dir/ld-new ./ld-new [transform ld]]
278 if ![info exists LDFLAGS] then {
282 # Set PLT_CFLAGS to "-fplt" if target compiler supports it.
284 if { ![info exists PLT_CFLAGS] } then {
285 if { [which $CC] != 0 } {
286 # Check if gcc supports -fplt
288 if [board_info [target_info name] exists cflags] {
289 append flags " [board_info [target_info name] cflags]"
291 if [board_info [target_info name] exists ldflags] {
292 append flags " [board_info [target_info name] ldflags]"
295 set basename "tmpdir/plt[pid]"
296 set src ${basename}.c
297 set output ${basename}.o
298 set f [open $src "w"]
301 remote_download host $src
302 set plt_available [run_host_cmd_yesno "$CC" "$flags -c -fplt $src -o $output"]
303 remote_file host delete $src
304 remote_file host delete $output
307 if { $plt_available == 1 } then {
308 set PLT_CFLAGS "-fplt"