1 # Basic expect script for LD Regression Tests 2 # Copyright (C) 1993-2014 Free Software Foundation, Inc. 3 # 4 # This file is part of the GNU Binutils. 5 # 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. 10 # 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. 15 # 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, 19 # MA 02110-1301, USA. 20 # 21 # Written by Jeffrey Wheat (cassidy (at) cygnus.com) 22 # 23 24 if ![info exists ld] then { 25 set ld [findfile $base_dir/ld-new $base_dir/ld-new [transform ld]] 26 } 27 28 if ![info exists as] then { 29 set as [findfile $base_dir/../gas/as-new $base_dir/../gas/as-new [transform as]] 30 } 31 32 if ![info exists nm] then { 33 set nm [findfile $base_dir/../binutils/nm-new $base_dir/../binutils/nm-new [transform nm]] 34 } 35 36 if ![info exists objdump] then { 37 set objdump [findfile $base_dir/../binutils/objdump] 38 } 39 40 if ![info exists objcopy] then { 41 set objcopy [findfile $base_dir/../binutils/objcopy] 42 } 43 44 if ![info exists ar] then { 45 set ar [findfile $base_dir/../binutils/ar] 46 } 47 48 if ![info exists strip] then { 49 set strip [findfile $base_dir/../binutils/strip-new $base_dir/../binutils/strip-new [transform strip]] 50 } 51 52 remote_exec host "mkdir -p tmpdir" 53 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 62 } 63 set gcc_B_opt "-B[pwd]/tmpdir/ld/" 64 65 # load the linker path 66 set ld_L_opt "" 67 if {[file exists tmpdir/libpath.exp]} { 68 load_lib tmpdir/libpath.exp 69 70 foreach dir $libpath { 71 append ld_L_opt " -L$dir" 72 } 73 } 74 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]} { 79 set CC [find_gcc] 80 } 81 if {![info exists CFLAGS]} { 82 set CFLAGS "-g -O2" 83 } 84 if {![info exists CXX]} { 85 set CXX [find_g++] 86 } 87 if {![info exists CXXFLAGS]} { 88 set CXXFLAGS "" 89 } 90 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 94 # the one we expect. 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]]) 98 } { 99 append gcc_B_opt " -mabi=n32" 100 } 101 102 if { [istarget rx-*-*] } { 103 global ASFLAGS 104 set ASFLAGS "-muse-conventional-section-names" 105 } 106 107 # load the utility procedures 108 load_lib ld-lib.exp 109 110 proc get_link_files {varname} { 111 global $varname 112 global target_triplet 113 global srcdir 114 global CC 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" } 125 set $varname $result 126 send_log "$varname = $result\n" 127 } 128 } 129 130 proc get_target_emul {} { 131 global target_triplet 132 global srcdir 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" } 135 return $result 136 } 137 138 if [isnative] { 139 foreach x {HOSTING_CRT0 HOSTING_SCRT0 HOSTING_LIBS HOSTING_SLIBS} { 140 get_link_files $x 141 } 142 } else { 143 foreach x {HOSTING_CRT0 HOSTING_SCRT0 HOSTING_LIBS HOSTING_SLIBS} { set $x "" } 144 } 145 if ![info exists HOSTING_EMU] { set HOSTING_EMU "-m [get_target_emul]" } 146 147 # 148 # ld_version -- extract and print the version number of ld compiler (GCC) 149 # 150 proc ld_version {} { 151 global ld 152 default_ld_version $ld 153 } 154 155 # 156 # ld_exit -- just a stub for ld 157 # 158 proc ld_exit {} { 159 } 160 161 # 162 # ld_start 163 # relink the linker 164 # 165 proc ld_start { ld target } { 166 # 167 } 168 169 # 170 # ld_relocate 171 # link an object using relocation 172 # 173 proc ld_relocate { ld target objects } { 174 default_ld_relocate $ld $target $objects 175 } 176 177 # 178 # ld_link 179 # link a program using ld 180 # 181 proc ld_link { ld target objects } { 182 default_ld_link $ld $target $objects 183 } 184 185 # 186 # ld_simple_link 187 # link a program using ld, without including any libraries 188 # 189 proc ld_simple_link { ld target objects } { 190 default_ld_simple_link $ld $target $objects 191 } 192 193 # 194 # ld_compile 195 # compile an object using $cc 196 # 197 proc ld_compile { cc source object } { 198 default_ld_compile $cc $source $object 199 } 200 201 # 202 # ld_assemble 203 # assemble a file 204 # 205 proc ld_assemble { as source object } { 206 default_ld_assemble $as "" $source $object 207 } 208 209 # 210 # ld_assemble_flags 211 # assemble a file with extra flags 212 # 213 proc ld_assemble_flags { as flags source object } { 214 default_ld_assemble $as $flags $source $object 215 } 216 217 # 218 # ld_nm 219 # run nm on a file 220 # 221 proc ld_nm { nm nmflags object } { 222 default_ld_nm $nm $nmflags $object 223 } 224 225 # 226 # ld_exec 227 # execute ithe target 228 # 229 proc ld_exec { target output } { 230 default_ld_exec $target $output 231 } 232 233 # From gas-defs.exp, to support run_dump_test. 234 if ![info exists AS] then { 235 set AS $as 236 } 237 238 if ![info exists ASFLAGS] then { 239 set ASFLAGS "" 240 } 241 242 if ![info exists OBJDUMP] then { 243 set OBJDUMP $objdump 244 } 245 246 if ![info exists OBJDUMPFLAGS] then { 247 set OBJDUMPFLAGS {} 248 } 249 250 if ![info exists NM] then { 251 set NM $nm 252 } 253 254 if ![info exists NMFLAGS] then { 255 set NMFLAGS {} 256 } 257 258 if ![info exists OBJCOPY] then { 259 set OBJCOPY $objcopy 260 } 261 262 if ![info exists OBJCOPYFLAGS] then { 263 set OBJCOPYFLAGS {} 264 } 265 266 if ![info exists READELF] then { 267 set READELF [findfile $base_dir/../binutils/readelf] 268 } 269 270 if ![info exists READELFFLAGS] then { 271 set READELFFLAGS {} 272 } 273 274 if ![info exists LD] then { 275 set LD [findfile $base_dir/ld-new ./ld-new [transform ld]] 276 } 277 278 if ![info exists LDFLAGS] then { 279 set LDFLAGS {} 280 } 281