| 1 |
135 |
khays |
# Support routines for LD testsuite.
|
| 2 |
|
|
# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
|
| 3 |
|
|
# 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
|
| 4 |
|
|
# Free Software Foundation, Inc.
|
| 5 |
|
|
#
|
| 6 |
|
|
# This file is part of the GNU Binutils.
|
| 7 |
|
|
#
|
| 8 |
|
|
# This file is free software; you can redistribute it and/or modify
|
| 9 |
|
|
# it under the terms of the GNU General Public License as published by
|
| 10 |
|
|
# the Free Software Foundation; either version 3 of the License, or
|
| 11 |
|
|
# (at your option) any later version.
|
| 12 |
|
|
#
|
| 13 |
|
|
# This program is distributed in the hope that it will be useful,
|
| 14 |
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 16 |
|
|
# GNU General Public License for more details.
|
| 17 |
|
|
#
|
| 18 |
|
|
# You should have received a copy of the GNU General Public License
|
| 19 |
|
|
# along with this program; if not, write to the Free Software
|
| 20 |
|
|
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
|
| 21 |
|
|
# MA 02110-1301, USA.
|
| 22 |
|
|
|
| 23 |
|
|
proc load_common_lib { name } {
|
| 24 |
|
|
global srcdir
|
| 25 |
|
|
load_file $srcdir/../../binutils/testsuite/lib/$name
|
| 26 |
|
|
}
|
| 27 |
|
|
|
| 28 |
|
|
load_common_lib binutils-common.exp
|
| 29 |
|
|
|
| 30 |
166 |
khays |
# Returns 1 if the gcc for the target is at least version MAJOR.MINOR
|
| 31 |
|
|
# Returns 0 otherwise.
|
| 32 |
|
|
#
|
| 33 |
|
|
proc at_least_gcc_version { major minor } {
|
| 34 |
|
|
|
| 35 |
|
|
if {![info exists CC]} {
|
| 36 |
|
|
set CC [find_gcc]
|
| 37 |
|
|
}
|
| 38 |
|
|
if { $CC == "" } {
|
| 39 |
|
|
return 0
|
| 40 |
|
|
}
|
| 41 |
|
|
set state [remote_exec host $CC --version]
|
| 42 |
|
|
set tmp "[lindex $state 1]\n"
|
| 43 |
|
|
# Look for (eg) 4.6.1 in the version output.
|
| 44 |
|
|
regexp " .* (\[1-9\])\\.(\[0-9\])\\.\[0-9\]* .*" "$tmp" fred maj min
|
| 45 |
|
|
verbose "gcc version: $tmp"
|
| 46 |
|
|
verbose "major gcc version is $maj, want at least $major"
|
| 47 |
|
|
if { $maj == $major } then {
|
| 48 |
|
|
verbose "minor gcc version is $min, want at least $minor"
|
| 49 |
|
|
return [expr $min >= $minor ]
|
| 50 |
|
|
} else {
|
| 51 |
|
|
return [expr $maj > $major ]
|
| 52 |
|
|
}
|
| 53 |
|
|
}
|
| 54 |
|
|
|
| 55 |
135 |
khays |
# Extract and print the version number of ld.
|
| 56 |
|
|
#
|
| 57 |
|
|
proc default_ld_version { ld } {
|
| 58 |
|
|
global host_triplet
|
| 59 |
|
|
|
| 60 |
|
|
if { ![is_remote host] && [which $ld] == 0 } then {
|
| 61 |
|
|
perror "$ld does not exist"
|
| 62 |
|
|
exit 1
|
| 63 |
|
|
}
|
| 64 |
|
|
|
| 65 |
|
|
remote_exec host "$ld --version" "" "/dev/null" "ld.version"
|
| 66 |
|
|
remote_upload host "ld.version"
|
| 67 |
|
|
set tmp [prune_warnings [file_contents "ld.version"]]
|
| 68 |
|
|
remote_file build delete "ld.version"
|
| 69 |
|
|
remote_file host delete "ld.version"
|
| 70 |
|
|
|
| 71 |
|
|
regexp "\[^\n\]* (cygnus-|)(\[-0-9.a-zA-Z-\]+)\[\r\n\].*" $tmp version cyg number
|
| 72 |
|
|
if [info exists number] then {
|
| 73 |
|
|
clone_output "$ld $number\n"
|
| 74 |
|
|
}
|
| 75 |
|
|
}
|
| 76 |
|
|
|
| 77 |
|
|
proc run_host_cmd { prog command } {
|
| 78 |
|
|
global link_output
|
| 79 |
|
|
|
| 80 |
|
|
if { ![is_remote host] && [which "$prog"] == 0 } then {
|
| 81 |
|
|
perror "$prog does not exist"
|
| 82 |
|
|
return 0
|
| 83 |
|
|
}
|
| 84 |
|
|
|
| 85 |
|
|
verbose -log "$prog $command"
|
| 86 |
|
|
set status [remote_exec host [concat sh -c [list "$prog $command 2>&1"]] "" "/dev/null" "ld.tmp"]
|
| 87 |
|
|
remote_upload host "ld.tmp"
|
| 88 |
|
|
set link_output [file_contents "ld.tmp"]
|
| 89 |
|
|
regsub "\n$" $link_output "" link_output
|
| 90 |
|
|
if { [lindex $status 0] != 0 && [string match "" $link_output] } then {
|
| 91 |
|
|
append link_output "child process exited abnormally"
|
| 92 |
|
|
}
|
| 93 |
|
|
remote_file build delete ld.tmp
|
| 94 |
|
|
remote_file host delete ld.tmp
|
| 95 |
|
|
|
| 96 |
|
|
if [string match "" $link_output] then {
|
| 97 |
|
|
return ""
|
| 98 |
|
|
}
|
| 99 |
|
|
|
| 100 |
|
|
verbose -log "$link_output"
|
| 101 |
|
|
return "$link_output"
|
| 102 |
|
|
}
|
| 103 |
|
|
|
| 104 |
|
|
proc run_host_cmd_yesno { prog command } {
|
| 105 |
|
|
global exec_output
|
| 106 |
|
|
|
| 107 |
|
|
set exec_output [prune_warnings [run_host_cmd "$prog" "$command"]]
|
| 108 |
|
|
if [string match "" $exec_output] then {
|
| 109 |
|
|
return 1;
|
| 110 |
|
|
}
|
| 111 |
|
|
return 0;
|
| 112 |
|
|
}
|
| 113 |
|
|
|
| 114 |
|
|
# Link an object using relocation.
|
| 115 |
|
|
#
|
| 116 |
|
|
proc default_ld_relocate { ld target objects } {
|
| 117 |
|
|
global HOSTING_EMU
|
| 118 |
|
|
|
| 119 |
|
|
remote_file host delete $target
|
| 120 |
|
|
return [run_host_cmd_yesno "$ld" "$HOSTING_EMU -o $target -r $objects"]
|
| 121 |
|
|
}
|
| 122 |
|
|
|
| 123 |
|
|
# Check to see if ld is being invoked with a non-endian output format
|
| 124 |
|
|
#
|
| 125 |
|
|
proc is_endian_output_format { object_flags } {
|
| 126 |
|
|
|
| 127 |
|
|
if {[string match "*-oformat binary*" $object_flags] || \
|
| 128 |
|
|
[string match "*-oformat ieee*" $object_flags] || \
|
| 129 |
|
|
[string match "*-oformat ihex*" $object_flags] || \
|
| 130 |
|
|
[string match "*-oformat netbsd-core*" $object_flags] || \
|
| 131 |
|
|
[string match "*-oformat srec*" $object_flags] || \
|
| 132 |
|
|
[string match "*-oformat tekhex*" $object_flags] || \
|
| 133 |
|
|
[string match "*-oformat trad-core*" $object_flags] } then {
|
| 134 |
|
|
return 0
|
| 135 |
|
|
} else {
|
| 136 |
|
|
return 1
|
| 137 |
|
|
}
|
| 138 |
|
|
}
|
| 139 |
|
|
|
| 140 |
|
|
# Look for big-endian or little-endian switches in the multlib
|
| 141 |
|
|
# options and translate these into a -EB or -EL switch. Note
|
| 142 |
|
|
# we cannot rely upon proc process_multilib_options to do this
|
| 143 |
|
|
# for us because for some targets the compiler does not support
|
| 144 |
|
|
# -EB/-EL but it does support -mbig-endian/-mlittle-endian, and
|
| 145 |
|
|
# the site.exp file will include the switch "-mbig-endian"
|
| 146 |
|
|
# (rather than "big-endian") which is not detected by proc
|
| 147 |
|
|
# process_multilib_options.
|
| 148 |
|
|
#
|
| 149 |
|
|
proc big_or_little_endian {} {
|
| 150 |
|
|
|
| 151 |
|
|
if [board_info [target_info name] exists multilib_flags] {
|
| 152 |
|
|
set tmp_flags " [board_info [target_info name] multilib_flags]"
|
| 153 |
|
|
|
| 154 |
|
|
foreach x $tmp_flags {
|
| 155 |
|
|
case $x in {
|
| 156 |
|
|
{*big*endian eb EB -eb -EB -mb -meb} {
|
| 157 |
|
|
set flags " -EB"
|
| 158 |
|
|
return $flags
|
| 159 |
|
|
}
|
| 160 |
|
|
{*little*endian el EL -el -EL -ml -mel} {
|
| 161 |
|
|
set flags " -EL"
|
| 162 |
|
|
return $flags
|
| 163 |
|
|
}
|
| 164 |
|
|
}
|
| 165 |
|
|
}
|
| 166 |
|
|
}
|
| 167 |
|
|
|
| 168 |
|
|
set flags ""
|
| 169 |
|
|
return $flags
|
| 170 |
|
|
}
|
| 171 |
|
|
|
| 172 |
|
|
# Link a program using ld.
|
| 173 |
|
|
#
|
| 174 |
|
|
proc default_ld_link { ld target objects } {
|
| 175 |
|
|
global HOSTING_EMU
|
| 176 |
|
|
global HOSTING_CRT0
|
| 177 |
|
|
global HOSTING_LIBS
|
| 178 |
|
|
global LIBS
|
| 179 |
|
|
global host_triplet
|
| 180 |
|
|
global link_output
|
| 181 |
|
|
global exec_output
|
| 182 |
|
|
|
| 183 |
|
|
set objs "$HOSTING_CRT0 $objects"
|
| 184 |
|
|
set libs "$LIBS $HOSTING_LIBS"
|
| 185 |
|
|
|
| 186 |
|
|
if [is_endian_output_format $objects] then {
|
| 187 |
|
|
set flags [big_or_little_endian]
|
| 188 |
|
|
} else {
|
| 189 |
|
|
set flags ""
|
| 190 |
|
|
}
|
| 191 |
|
|
|
| 192 |
|
|
remote_file host delete $target
|
| 193 |
|
|
|
| 194 |
|
|
return [run_host_cmd_yesno "$ld" "$HOSTING_EMU $flags -o $target $objs $libs"]
|
| 195 |
|
|
}
|
| 196 |
|
|
|
| 197 |
|
|
# Link a program using ld, without including any libraries.
|
| 198 |
|
|
#
|
| 199 |
|
|
proc default_ld_simple_link { ld target objects } {
|
| 200 |
|
|
global host_triplet
|
| 201 |
|
|
global gcc_ld_flag
|
| 202 |
|
|
global exec_output
|
| 203 |
|
|
|
| 204 |
|
|
if [is_endian_output_format $objects] then {
|
| 205 |
|
|
set flags [big_or_little_endian]
|
| 206 |
|
|
} else {
|
| 207 |
|
|
set flags ""
|
| 208 |
|
|
}
|
| 209 |
|
|
|
| 210 |
|
|
# If we are compiling with gcc, we want to add gcc_ld_flag to
|
| 211 |
|
|
# flags. Rather than determine this in some complex way, we guess
|
| 212 |
|
|
# based on the name of the compiler.
|
| 213 |
|
|
set ldexe $ld
|
| 214 |
|
|
set ldparm [string first " " $ld]
|
| 215 |
|
|
set ldflags ""
|
| 216 |
|
|
if { $ldparm > 0 } then {
|
| 217 |
|
|
set ldflags [string range $ld $ldparm end]
|
| 218 |
|
|
set ldexe [string range $ld 0 $ldparm]
|
| 219 |
|
|
set ld $ldexe
|
| 220 |
|
|
}
|
| 221 |
|
|
set ldexe [string replace $ldexe 0 [string last "/" $ldexe] ""]
|
| 222 |
|
|
if {[string match "*gcc*" $ldexe] || [string match "*++*" $ldexe]} then {
|
| 223 |
|
|
set ldflags "$gcc_ld_flag $ldflags"
|
| 224 |
|
|
}
|
| 225 |
|
|
|
| 226 |
|
|
remote_file host delete $target
|
| 227 |
|
|
|
| 228 |
|
|
set exec_output [run_host_cmd "$ld" "$ldflags $flags -o $target $objects"]
|
| 229 |
|
|
set exec_output [prune_warnings $exec_output]
|
| 230 |
|
|
|
| 231 |
|
|
# We don't care if we get a warning about a non-existent start
|
| 232 |
|
|
# symbol, since the default linker script might use ENTRY.
|
| 233 |
|
|
regsub -all "(^|\n)(\[^\n\]*: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
|
| 234 |
|
|
|
| 235 |
|
|
if [string match "" $exec_output] then {
|
| 236 |
|
|
return 1
|
| 237 |
|
|
} else {
|
| 238 |
|
|
return 0
|
| 239 |
|
|
}
|
| 240 |
|
|
}
|
| 241 |
|
|
|
| 242 |
|
|
# Compile an object using cc.
|
| 243 |
|
|
#
|
| 244 |
|
|
proc default_ld_compile { cc source object } {
|
| 245 |
|
|
global CFLAGS
|
| 246 |
|
|
global CXXFLAGS
|
| 247 |
|
|
global srcdir
|
| 248 |
|
|
global subdir
|
| 249 |
|
|
global host_triplet
|
| 250 |
|
|
global gcc_gas_flag
|
| 251 |
|
|
|
| 252 |
|
|
set cc_prog $cc
|
| 253 |
|
|
if {[llength $cc_prog] > 1} then {
|
| 254 |
|
|
set cc_prog [lindex $cc_prog 0]
|
| 255 |
|
|
}
|
| 256 |
|
|
if {![is_remote host] && [which $cc_prog] == 0} then {
|
| 257 |
|
|
perror "$cc_prog does not exist"
|
| 258 |
|
|
return 0
|
| 259 |
|
|
}
|
| 260 |
|
|
|
| 261 |
|
|
remote_file build delete "$object"
|
| 262 |
|
|
remote_file host delete "$object"
|
| 263 |
|
|
|
| 264 |
|
|
set flags "-I$srcdir/$subdir"
|
| 265 |
|
|
|
| 266 |
|
|
# If we are compiling with gcc, we want to add gcc_gas_flag to
|
| 267 |
|
|
# flags. Rather than determine this in some complex way, we guess
|
| 268 |
|
|
# based on the name of the compiler.
|
| 269 |
|
|
set ccexe $cc
|
| 270 |
|
|
set ccparm [string first " " $cc]
|
| 271 |
|
|
set ccflags ""
|
| 272 |
|
|
if { $ccparm > 0 } then {
|
| 273 |
|
|
set ccflags [string range $cc $ccparm end]
|
| 274 |
|
|
set ccexe [string range $cc 0 $ccparm]
|
| 275 |
|
|
set cc $ccexe
|
| 276 |
|
|
}
|
| 277 |
|
|
set ccexe [string replace $ccexe 0 [string last "/" $ccexe] ""]
|
| 278 |
|
|
if {[string match "*gcc*" $ccexe] || [string match "*++*" $ccexe]} then {
|
| 279 |
|
|
set flags "$gcc_gas_flag $flags"
|
| 280 |
|
|
}
|
| 281 |
|
|
|
| 282 |
|
|
if {[string match "*++*" $ccexe]} {
|
| 283 |
|
|
set flags "$flags $CXXFLAGS"
|
| 284 |
|
|
} else {
|
| 285 |
|
|
set flags "$flags $CFLAGS"
|
| 286 |
|
|
}
|
| 287 |
|
|
|
| 288 |
|
|
if [board_info [target_info name] exists multilib_flags] {
|
| 289 |
|
|
append flags " [board_info [target_info name] multilib_flags]"
|
| 290 |
|
|
}
|
| 291 |
|
|
|
| 292 |
|
|
verbose -log "$cc $flags $ccflags -c $source -o $object"
|
| 293 |
|
|
|
| 294 |
|
|
set status [remote_exec host [concat sh -c [list "$cc $flags $ccflags -c $source -o $object 2>&1"]] "" "/dev/null" "ld.tmp"]
|
| 295 |
|
|
remote_upload host "ld.tmp"
|
| 296 |
|
|
set exec_output [file_contents "ld.tmp"]
|
| 297 |
|
|
remote_file build delete "ld.tmp"
|
| 298 |
|
|
remote_file host delete "ld.tmp"
|
| 299 |
|
|
set exec_output [prune_warnings $exec_output]
|
| 300 |
|
|
if [string match "" $exec_output] then {
|
| 301 |
|
|
if {![file exists $object]} then {
|
| 302 |
|
|
regexp ".*/(\[^/\]*)$" $source all dobj
|
| 303 |
|
|
regsub "\\.c" $dobj ".o" realobj
|
| 304 |
|
|
verbose "looking for $realobj"
|
| 305 |
|
|
if {[remote_file host exists $realobj]} then {
|
| 306 |
|
|
verbose -log "mv $realobj $object"
|
| 307 |
|
|
remote_upload "$realobj" "$object"
|
| 308 |
|
|
} else {
|
| 309 |
|
|
perror "$object not found after compilation"
|
| 310 |
|
|
return 0
|
| 311 |
|
|
}
|
| 312 |
|
|
}
|
| 313 |
|
|
return 1
|
| 314 |
|
|
} else {
|
| 315 |
|
|
verbose -log "$exec_output"
|
| 316 |
|
|
perror "$source: compilation failed"
|
| 317 |
|
|
return 0
|
| 318 |
|
|
}
|
| 319 |
|
|
}
|
| 320 |
|
|
|
| 321 |
|
|
# Assemble a file.
|
| 322 |
|
|
#
|
| 323 |
|
|
proc default_ld_assemble { as in_flags source object } {
|
| 324 |
|
|
global ASFLAGS
|
| 325 |
|
|
global host_triplet
|
| 326 |
|
|
|
| 327 |
|
|
if ![info exists ASFLAGS] { set ASFLAGS "" }
|
| 328 |
|
|
|
| 329 |
|
|
set flags [big_or_little_endian]
|
| 330 |
|
|
set exec_output [run_host_cmd "$as" "$flags $in_flags $ASFLAGS -o $object $source"]
|
| 331 |
|
|
set exec_output [prune_warnings $exec_output]
|
| 332 |
|
|
if [string match "" $exec_output] then {
|
| 333 |
|
|
return 1
|
| 334 |
|
|
} else {
|
| 335 |
|
|
perror "$source: assembly failed"
|
| 336 |
|
|
return 0
|
| 337 |
|
|
}
|
| 338 |
|
|
}
|
| 339 |
|
|
|
| 340 |
|
|
# Run nm on a file, putting the result in the array nm_output.
|
| 341 |
|
|
#
|
| 342 |
|
|
proc default_ld_nm { nm nmflags object } {
|
| 343 |
|
|
global NMFLAGS
|
| 344 |
|
|
global nm_output
|
| 345 |
|
|
global host_triplet
|
| 346 |
|
|
|
| 347 |
|
|
if {[info exists nm_output]} {
|
| 348 |
|
|
unset nm_output
|
| 349 |
|
|
}
|
| 350 |
|
|
|
| 351 |
|
|
if ![info exists NMFLAGS] { set NMFLAGS "" }
|
| 352 |
|
|
|
| 353 |
|
|
# Ensure consistent sorting of symbols
|
| 354 |
|
|
if {[info exists env(LC_ALL)]} {
|
| 355 |
|
|
set old_lc_all $env(LC_ALL)
|
| 356 |
|
|
}
|
| 357 |
|
|
set env(LC_ALL) "C"
|
| 358 |
|
|
|
| 359 |
|
|
verbose -log "$nm $NMFLAGS $nmflags $object >tmpdir/nm.out"
|
| 360 |
|
|
|
| 361 |
|
|
set status [remote_exec host [concat sh -c [list "$nm $NMFLAGS $nmflags $object 2>ld.stderr"]] "" "/dev/null" "tmpdir/nm.out"]
|
| 362 |
|
|
if {[info exists old_lc_all]} {
|
| 363 |
|
|
set env(LC_ALL) $old_lc_all
|
| 364 |
|
|
} else {
|
| 365 |
|
|
unset env(LC_ALL)
|
| 366 |
|
|
}
|
| 367 |
|
|
remote_upload host "ld.stderr"
|
| 368 |
|
|
remote_upload host "tmpdir/nm.out" "tmpdir/nm.out"
|
| 369 |
|
|
set exec_output [prune_warnings [file_contents "ld.stderr"]]
|
| 370 |
|
|
remote_file host delete "ld.stderr"
|
| 371 |
|
|
remote_file build delete "ld.stderr"
|
| 372 |
|
|
if [string match "" $exec_output] then {
|
| 373 |
|
|
set file [open tmpdir/nm.out r]
|
| 374 |
|
|
while { [gets $file line] != -1 } {
|
| 375 |
|
|
verbose "$line" 2
|
| 376 |
|
|
if [regexp "^(\[0-9a-fA-F\]+) \[a-zA-Z0-9\] \\.*(.+)$" $line whole value name] {
|
| 377 |
|
|
set name [string trimleft $name "_"]
|
| 378 |
|
|
verbose "Setting nm_output($name) to 0x$value" 2
|
| 379 |
|
|
set nm_output($name) 0x$value
|
| 380 |
|
|
}
|
| 381 |
|
|
}
|
| 382 |
|
|
close $file
|
| 383 |
|
|
return 1
|
| 384 |
|
|
} else {
|
| 385 |
|
|
verbose -log "$exec_output"
|
| 386 |
|
|
perror "$object: nm failed"
|
| 387 |
|
|
return 0
|
| 388 |
|
|
}
|
| 389 |
|
|
}
|
| 390 |
|
|
|
| 391 |
|
|
# Define various symbols needed when not linking against all
|
| 392 |
|
|
# target libs.
|
| 393 |
|
|
proc ld_simple_link_defsyms {} {
|
| 394 |
|
|
|
| 395 |
|
|
set flags "--defsym __stack_chk_fail=0"
|
| 396 |
|
|
|
| 397 |
|
|
# ARM targets call __gccmain
|
| 398 |
|
|
if {[istarget arm*-*-*]} {
|
| 399 |
|
|
append flags " --defsym __gccmain=0"
|
| 400 |
|
|
}
|
| 401 |
|
|
|
| 402 |
|
|
# Windows targets need __main, prefixed with underscore.
|
| 403 |
|
|
if {[istarget *-*-cygwin* ] || [istarget *-*-mingw*]} {
|
| 404 |
|
|
append flags " --defsym ___main=0"
|
| 405 |
|
|
}
|
| 406 |
|
|
|
| 407 |
|
|
# PowerPC EABI code calls __eabi.
|
| 408 |
|
|
if {[istarget powerpc*-*-eabi*] || [istarget powerpc*-*-rtems*]} {
|
| 409 |
|
|
append flags " --defsym __eabi=0"
|
| 410 |
|
|
}
|
| 411 |
|
|
|
| 412 |
|
|
# mn10200 code calls __truncsipsi2_d0_d2.
|
| 413 |
|
|
if {[istarget mn10200*-*-*]} then {
|
| 414 |
|
|
append flags " --defsym __truncsipsi2_d0_d2=0"
|
| 415 |
|
|
}
|
| 416 |
|
|
|
| 417 |
|
|
# m6811/m6812 code has references to soft registers.
|
| 418 |
166 |
khays |
if {[istarget m6811-*-*] || [istarget m6812-*-*] || [istarget m68hc1*-*-*]} {
|
| 419 |
135 |
khays |
append flags " --defsym _.frame=0 --defsym _.d1=0 --defsym _.d2=0"
|
| 420 |
|
|
append flags " --defsym _.d3=0 --defsym _.d4=0"
|
| 421 |
|
|
append flags " --defsym _.tmp=0 --defsym _.xy=0 --defsym _.z=0"
|
| 422 |
|
|
}
|
| 423 |
|
|
|
| 424 |
|
|
# Some OpenBSD targets have ProPolice and reference __guard and
|
| 425 |
|
|
# __stack_smash_handler.
|
| 426 |
|
|
if [istarget *-*-openbsd*] {
|
| 427 |
|
|
append flags " --defsym __guard=0"
|
| 428 |
|
|
append flags " --defsym __stack_smash_handler=0"
|
| 429 |
|
|
}
|
| 430 |
|
|
|
| 431 |
|
|
return $flags
|
| 432 |
|
|
}
|
| 433 |
|
|
|
| 434 |
|
|
# run_dump_test FILE
|
| 435 |
|
|
# Copied from gas testsuite, tweaked and further extended.
|
| 436 |
|
|
#
|
| 437 |
|
|
# Assemble a .s file, then run some utility on it and check the output.
|
| 438 |
|
|
#
|
| 439 |
|
|
# There should be an assembly language file named FILE.s in the test
|
| 440 |
|
|
# suite directory, and a pattern file called FILE.d. `run_dump_test'
|
| 441 |
|
|
# will assemble FILE.s, run some tool like `objdump', `objcopy', or
|
| 442 |
|
|
# `nm' on the .o file to produce textual output, and then analyze that
|
| 443 |
|
|
# with regexps. The FILE.d file specifies what program to run, and
|
| 444 |
|
|
# what to expect in its output.
|
| 445 |
|
|
#
|
| 446 |
|
|
# The FILE.d file begins with zero or more option lines, which specify
|
| 447 |
|
|
# flags to pass to the assembler, the program to run to dump the
|
| 448 |
|
|
# assembler's output, and the options it wants. The option lines have
|
| 449 |
|
|
# the syntax:
|
| 450 |
|
|
#
|
| 451 |
|
|
# # OPTION: VALUE
|
| 452 |
|
|
#
|
| 453 |
|
|
# OPTION is the name of some option, like "name" or "objdump", and
|
| 454 |
|
|
# VALUE is OPTION's value. The valid options are described below.
|
| 455 |
|
|
# Whitespace is ignored everywhere, except within VALUE. The option
|
| 456 |
|
|
# list ends with the first line that doesn't match the above syntax
|
| 457 |
|
|
# (hmm, not great for error detection).
|
| 458 |
|
|
#
|
| 459 |
|
|
# The interesting options are:
|
| 460 |
|
|
#
|
| 461 |
|
|
# name: TEST-NAME
|
| 462 |
|
|
# The name of this test, passed to DejaGNU's `pass' and `fail'
|
| 463 |
|
|
# commands. If omitted, this defaults to FILE, the root of the
|
| 464 |
|
|
# .s and .d files' names.
|
| 465 |
|
|
#
|
| 466 |
|
|
# as: FLAGS
|
| 467 |
|
|
# When assembling, pass FLAGS to the assembler.
|
| 468 |
|
|
# If assembling several files, you can pass different assembler
|
| 469 |
|
|
# options in the "source" directives. See below.
|
| 470 |
|
|
#
|
| 471 |
|
|
# ld: FLAGS
|
| 472 |
|
|
# Link assembled files using FLAGS, in the order of the "source"
|
| 473 |
|
|
# directives, when using multiple files.
|
| 474 |
|
|
#
|
| 475 |
|
|
# ld_after_inputfiles: FLAGS
|
| 476 |
|
|
# Similar to "ld", but put after all input files.
|
| 477 |
|
|
#
|
| 478 |
|
|
# objcopy_linked_file: FLAGS
|
| 479 |
|
|
# Run objcopy on the linked file with the specified flags.
|
| 480 |
|
|
# This lets you transform the linked file using objcopy, before the
|
| 481 |
|
|
# result is analyzed by an analyzer program specified below (which
|
| 482 |
|
|
# may in turn *also* be objcopy).
|
| 483 |
|
|
#
|
| 484 |
|
|
# PROG: PROGRAM-NAME
|
| 485 |
|
|
# The name of the program to run to analyze the .o file produced
|
| 486 |
|
|
# by the assembler or the linker output. This can be omitted;
|
| 487 |
|
|
# run_dump_test will guess which program to run by seeing which of
|
| 488 |
|
|
# the flags options below is present.
|
| 489 |
|
|
#
|
| 490 |
|
|
# objdump: FLAGS
|
| 491 |
|
|
# nm: FLAGS
|
| 492 |
|
|
# objcopy: FLAGS
|
| 493 |
|
|
# Use the specified program to analyze the assembler or linker
|
| 494 |
|
|
# output file, and pass it FLAGS, in addition to the output name.
|
| 495 |
|
|
# Note that they are run with LC_ALL=C in the environment to give
|
| 496 |
|
|
# consistent sorting of symbols.
|
| 497 |
|
|
#
|
| 498 |
|
|
# source: SOURCE [FLAGS]
|
| 499 |
|
|
# Assemble the file SOURCE.s using the flags in the "as" directive
|
| 500 |
|
|
# and the (optional) FLAGS. If omitted, the source defaults to
|
| 501 |
|
|
# FILE.s.
|
| 502 |
|
|
# This is useful if several .d files want to share a .s file.
|
| 503 |
|
|
# More than one "source" directive can be given, which is useful
|
| 504 |
|
|
# when testing linking.
|
| 505 |
|
|
#
|
| 506 |
|
|
# xfail: TARGET
|
| 507 |
|
|
# The test is expected to fail on TARGET. This may occur more than
|
| 508 |
|
|
# once.
|
| 509 |
|
|
#
|
| 510 |
|
|
# target: TARGET
|
| 511 |
|
|
# Only run the test for TARGET. This may occur more than once; the
|
| 512 |
|
|
# target being tested must match at least one. You may provide target
|
| 513 |
|
|
# name "cfi" for any target supporting the CFI statements.
|
| 514 |
|
|
#
|
| 515 |
|
|
# notarget: TARGET
|
| 516 |
|
|
# Do not run the test for TARGET. This may occur more than once;
|
| 517 |
|
|
# the target being tested must not match any of them.
|
| 518 |
|
|
#
|
| 519 |
|
|
# error: REGEX
|
| 520 |
|
|
# An error with message matching REGEX must be emitted for the test
|
| 521 |
|
|
# to pass. The PROG, objdump, nm and objcopy options have no
|
| 522 |
|
|
# meaning and need not supplied if this is present. Multiple "error"
|
| 523 |
|
|
# directives append to the expected linker error message.
|
| 524 |
|
|
#
|
| 525 |
|
|
# warning: REGEX
|
| 526 |
|
|
# Expect a linker warning matching REGEX. It is an error to issue
|
| 527 |
|
|
# both "error" and "warning". Multiple "warning" directives
|
| 528 |
|
|
# append to the expected linker warning message.
|
| 529 |
|
|
#
|
| 530 |
|
|
# Each option may occur at most once unless otherwise mentioned.
|
| 531 |
|
|
#
|
| 532 |
|
|
# After the option lines come regexp lines. `run_dump_test' calls
|
| 533 |
|
|
# `regexp_diff' to compare the output of the dumping tool against the
|
| 534 |
|
|
# regexps in FILE.d. `regexp_diff' is defined in binutils-common.exp;
|
| 535 |
|
|
# see further comments there.
|
| 536 |
|
|
#
|
| 537 |
|
|
proc run_dump_test { name } {
|
| 538 |
|
|
global subdir srcdir
|
| 539 |
|
|
global OBJDUMP NM AS OBJCOPY READELF LD
|
| 540 |
|
|
global OBJDUMPFLAGS NMFLAGS ASFLAGS OBJCOPYFLAGS READELFFLAGS LDFLAGS
|
| 541 |
|
|
global host_triplet runtests
|
| 542 |
|
|
global env verbose
|
| 543 |
|
|
|
| 544 |
|
|
if [string match "*/*" $name] {
|
| 545 |
|
|
set file $name
|
| 546 |
|
|
set name [file tail $name]
|
| 547 |
|
|
} else {
|
| 548 |
|
|
set file "$srcdir/$subdir/$name"
|
| 549 |
|
|
}
|
| 550 |
|
|
|
| 551 |
|
|
if ![runtest_file_p $runtests $name] then {
|
| 552 |
|
|
return
|
| 553 |
|
|
}
|
| 554 |
|
|
|
| 555 |
|
|
set opt_array [slurp_options "${file}.d"]
|
| 556 |
|
|
if { $opt_array == -1 } {
|
| 557 |
|
|
perror "error reading options from $file.d"
|
| 558 |
|
|
unresolved $subdir/$name
|
| 559 |
|
|
return
|
| 560 |
|
|
}
|
| 561 |
|
|
set dumpfile tmpdir/dump.out
|
| 562 |
|
|
set run_ld 0
|
| 563 |
|
|
set run_objcopy 0
|
| 564 |
|
|
set opts(as) {}
|
| 565 |
|
|
set opts(ld) {}
|
| 566 |
|
|
set opts(ld_after_inputfiles) {}
|
| 567 |
|
|
set opts(xfail) {}
|
| 568 |
|
|
set opts(target) {}
|
| 569 |
|
|
set opts(notarget) {}
|
| 570 |
|
|
set opts(objdump) {}
|
| 571 |
|
|
set opts(nm) {}
|
| 572 |
|
|
set opts(objcopy) {}
|
| 573 |
|
|
set opts(readelf) {}
|
| 574 |
|
|
set opts(name) {}
|
| 575 |
|
|
set opts(PROG) {}
|
| 576 |
|
|
set opts(source) {}
|
| 577 |
|
|
set opts(error) {}
|
| 578 |
|
|
set opts(warning) {}
|
| 579 |
|
|
set opts(objcopy_linked_file) {}
|
| 580 |
|
|
|
| 581 |
|
|
foreach i $opt_array {
|
| 582 |
|
|
set opt_name [lindex $i 0]
|
| 583 |
|
|
set opt_val [lindex $i 1]
|
| 584 |
|
|
if ![info exists opts($opt_name)] {
|
| 585 |
|
|
perror "unknown option $opt_name in file $file.d"
|
| 586 |
|
|
unresolved $subdir/$name
|
| 587 |
|
|
return
|
| 588 |
|
|
}
|
| 589 |
|
|
|
| 590 |
|
|
switch -- $opt_name {
|
| 591 |
|
|
xfail {}
|
| 592 |
|
|
target {}
|
| 593 |
|
|
notarget {}
|
| 594 |
|
|
warning {}
|
| 595 |
|
|
error {}
|
| 596 |
|
|
source {
|
| 597 |
157 |
khays |
# Move any source-specific as-flags to a separate list to
|
| 598 |
135 |
khays |
# simplify processing.
|
| 599 |
|
|
if { [llength $opt_val] > 1 } {
|
| 600 |
157 |
khays |
lappend asflags [lrange $opt_val 1 end]
|
| 601 |
135 |
khays |
set opt_val [lindex $opt_val 0]
|
| 602 |
|
|
} else {
|
| 603 |
157 |
khays |
lappend asflags {}
|
| 604 |
135 |
khays |
}
|
| 605 |
|
|
}
|
| 606 |
|
|
default {
|
| 607 |
|
|
if [string length $opts($opt_name)] {
|
| 608 |
|
|
perror "option $opt_name multiply set in $file.d"
|
| 609 |
|
|
unresolved $subdir/$name
|
| 610 |
|
|
return
|
| 611 |
|
|
}
|
| 612 |
|
|
|
| 613 |
|
|
# A single "# ld:" with no options should do the right thing.
|
| 614 |
|
|
if { $opt_name == "ld" } {
|
| 615 |
|
|
set run_ld 1
|
| 616 |
|
|
}
|
| 617 |
|
|
# Likewise objcopy_linked_file.
|
| 618 |
|
|
if { $opt_name == "objcopy_linked_file" } {
|
| 619 |
|
|
set run_objcopy 1
|
| 620 |
|
|
}
|
| 621 |
|
|
}
|
| 622 |
|
|
}
|
| 623 |
|
|
if { $opt_name == "as" || $opt_name == "ld" } {
|
| 624 |
|
|
set opt_val [subst $opt_val]
|
| 625 |
|
|
}
|
| 626 |
|
|
set opts($opt_name) [concat $opts($opt_name) $opt_val]
|
| 627 |
|
|
}
|
| 628 |
|
|
foreach opt { as ld } {
|
| 629 |
|
|
regsub {\[big_or_little_endian\]} $opts($opt) \
|
| 630 |
|
|
[big_or_little_endian] opts($opt)
|
| 631 |
|
|
}
|
| 632 |
|
|
|
| 633 |
|
|
# Decide early whether we should run the test for this target.
|
| 634 |
|
|
if { [llength $opts(target)] > 0 } {
|
| 635 |
|
|
set targmatch 0
|
| 636 |
|
|
foreach targ $opts(target) {
|
| 637 |
|
|
if [istarget $targ] {
|
| 638 |
|
|
set targmatch 1
|
| 639 |
|
|
break
|
| 640 |
|
|
}
|
| 641 |
|
|
}
|
| 642 |
|
|
if { $targmatch == 0 } {
|
| 643 |
|
|
return
|
| 644 |
|
|
}
|
| 645 |
|
|
}
|
| 646 |
|
|
foreach targ $opts(notarget) {
|
| 647 |
|
|
if [istarget $targ] {
|
| 648 |
|
|
return
|
| 649 |
|
|
}
|
| 650 |
|
|
}
|
| 651 |
|
|
|
| 652 |
|
|
set program ""
|
| 653 |
|
|
# It's meaningless to require an output-testing method when we
|
| 654 |
|
|
# expect an error.
|
| 655 |
|
|
if { $opts(error) == "" } {
|
| 656 |
|
|
if {$opts(PROG) != ""} {
|
| 657 |
|
|
switch -- $opts(PROG) {
|
| 658 |
|
|
objdump { set program objdump }
|
| 659 |
|
|
nm { set program nm }
|
| 660 |
|
|
objcopy { set program objcopy }
|
| 661 |
|
|
readelf { set program readelf }
|
| 662 |
|
|
default
|
| 663 |
|
|
{ perror "unrecognized program option $opts(PROG) in $file.d"
|
| 664 |
|
|
unresolved $subdir/$name
|
| 665 |
|
|
return }
|
| 666 |
|
|
}
|
| 667 |
|
|
} else {
|
| 668 |
|
|
# Guess which program to run, by seeing which option was specified.
|
| 669 |
|
|
foreach p {objdump objcopy nm readelf} {
|
| 670 |
|
|
if {$opts($p) != ""} {
|
| 671 |
|
|
if {$program != ""} {
|
| 672 |
|
|
perror "ambiguous dump program in $file.d"
|
| 673 |
|
|
unresolved $subdir/$name
|
| 674 |
|
|
return
|
| 675 |
|
|
} else {
|
| 676 |
|
|
set program $p
|
| 677 |
|
|
}
|
| 678 |
|
|
}
|
| 679 |
|
|
}
|
| 680 |
|
|
}
|
| 681 |
|
|
if { $program == "" && $opts(warning) == "" } {
|
| 682 |
|
|
perror "dump program unspecified in $file.d"
|
| 683 |
|
|
unresolved $subdir/$name
|
| 684 |
|
|
return
|
| 685 |
|
|
}
|
| 686 |
|
|
}
|
| 687 |
|
|
|
| 688 |
|
|
if { $opts(name) == "" } {
|
| 689 |
|
|
set testname "$subdir/$name"
|
| 690 |
|
|
} else {
|
| 691 |
|
|
set testname $opts(name)
|
| 692 |
|
|
}
|
| 693 |
|
|
|
| 694 |
|
|
if { $opts(source) == "" } {
|
| 695 |
|
|
set sourcefiles [list ${file}.s]
|
| 696 |
157 |
khays |
set asflags [list ""]
|
| 697 |
135 |
khays |
} else {
|
| 698 |
|
|
set sourcefiles {}
|
| 699 |
|
|
foreach sf $opts(source) {
|
| 700 |
|
|
if { [string match "/*" $sf] } {
|
| 701 |
|
|
lappend sourcefiles "$sf"
|
| 702 |
|
|
} else {
|
| 703 |
|
|
lappend sourcefiles "$srcdir/$subdir/$sf"
|
| 704 |
|
|
}
|
| 705 |
|
|
}
|
| 706 |
|
|
}
|
| 707 |
|
|
|
| 708 |
|
|
# Time to setup xfailures.
|
| 709 |
|
|
foreach targ $opts(xfail) {
|
| 710 |
|
|
setup_xfail $targ
|
| 711 |
|
|
}
|
| 712 |
|
|
|
| 713 |
|
|
# Assemble each file.
|
| 714 |
|
|
set objfiles {}
|
| 715 |
|
|
for { set i 0 } { $i < [llength $sourcefiles] } { incr i } {
|
| 716 |
|
|
set sourcefile [lindex $sourcefiles $i]
|
| 717 |
157 |
khays |
set sourceasflags [lindex $asflags $i]
|
| 718 |
135 |
khays |
|
| 719 |
|
|
set objfile "tmpdir/dump$i.o"
|
| 720 |
|
|
catch "exec rm -f $objfile" exec_output
|
| 721 |
|
|
lappend objfiles $objfile
|
| 722 |
157 |
khays |
set cmd "$AS $ASFLAGS $opts(as) $sourceasflags -o $objfile $sourcefile"
|
| 723 |
135 |
khays |
|
| 724 |
|
|
send_log "$cmd\n"
|
| 725 |
|
|
set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "ld.tmp"]
|
| 726 |
|
|
remote_upload host "ld.tmp"
|
| 727 |
|
|
set comp_output [prune_warnings [file_contents "ld.tmp"]]
|
| 728 |
|
|
remote_file host delete "ld.tmp"
|
| 729 |
|
|
remote_file build delete "ld.tmp"
|
| 730 |
|
|
|
| 731 |
|
|
if { [lindex $cmdret 0] != 0 || ![string match "" $comp_output] } then {
|
| 732 |
|
|
send_log "$comp_output\n"
|
| 733 |
|
|
verbose "$comp_output" 3
|
| 734 |
|
|
|
| 735 |
|
|
set exitstat "succeeded"
|
| 736 |
|
|
if { $cmdret != 0 } { set exitstat "failed" }
|
| 737 |
|
|
verbose -log "$exitstat with: <$comp_output>"
|
| 738 |
|
|
fail $testname
|
| 739 |
|
|
return
|
| 740 |
|
|
}
|
| 741 |
|
|
}
|
| 742 |
|
|
|
| 743 |
|
|
set expmsg $opts(error)
|
| 744 |
|
|
if { $opts(warning) != "" } {
|
| 745 |
|
|
if { $expmsg != "" } {
|
| 746 |
|
|
perror "$testname: mixing error and warning test-directives"
|
| 747 |
|
|
return
|
| 748 |
|
|
}
|
| 749 |
|
|
set expmsg $opts(warning)
|
| 750 |
|
|
}
|
| 751 |
|
|
|
| 752 |
|
|
# Perhaps link the file(s).
|
| 753 |
|
|
if { $run_ld } {
|
| 754 |
|
|
set objfile "tmpdir/dump"
|
| 755 |
|
|
catch "exec rm -f $objfile" exec_output
|
| 756 |
|
|
|
| 757 |
|
|
# Add -L$srcdir/$subdir so that the linker command can use
|
| 758 |
|
|
# linker scripts in the source directory.
|
| 759 |
|
|
set cmd "$LD $LDFLAGS -L$srcdir/$subdir \
|
| 760 |
|
|
$opts(ld) -o $objfile $objfiles $opts(ld_after_inputfiles)"
|
| 761 |
|
|
|
| 762 |
|
|
send_log "$cmd\n"
|
| 763 |
|
|
set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "ld.tmp"]
|
| 764 |
|
|
remote_upload host "ld.tmp"
|
| 765 |
|
|
set comp_output [file_contents "ld.tmp"]
|
| 766 |
|
|
remote_file host delete "ld.tmp"
|
| 767 |
|
|
remote_file build delete "ld.tmp"
|
| 768 |
|
|
set cmdret [lindex $cmdret 0]
|
| 769 |
|
|
|
| 770 |
|
|
if { $cmdret == 0 && $run_objcopy } {
|
| 771 |
|
|
set infile $objfile
|
| 772 |
|
|
set objfile "tmpdir/dump1"
|
| 773 |
|
|
remote_file host delete $objfile
|
| 774 |
|
|
|
| 775 |
|
|
# Note that we don't use OBJCOPYFLAGS here; any flags must be
|
| 776 |
|
|
# explicitly specified.
|
| 777 |
|
|
set cmd "$OBJCOPY $opts(objcopy_linked_file) $infile $objfile"
|
| 778 |
|
|
|
| 779 |
|
|
send_log "$cmd\n"
|
| 780 |
|
|
set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "ld.tmp"]
|
| 781 |
|
|
remote_upload host "ld.tmp"
|
| 782 |
|
|
append comp_output [file_contents "ld.tmp"]
|
| 783 |
|
|
remote_file host delete "ld.tmp"
|
| 784 |
|
|
remote_file build delete "ld.tmp"
|
| 785 |
|
|
set cmdret [lindex $cmdret 0]
|
| 786 |
|
|
}
|
| 787 |
|
|
|
| 788 |
|
|
regsub "\n$" $comp_output "" comp_output
|
| 789 |
|
|
if { $cmdret != 0 || $comp_output != "" || $expmsg != "" } then {
|
| 790 |
|
|
set exitstat "succeeded"
|
| 791 |
|
|
if { $cmdret != 0 } { set exitstat "failed" }
|
| 792 |
|
|
verbose -log "$exitstat with: <$comp_output>, expected: <$expmsg>"
|
| 793 |
|
|
send_log "$comp_output\n"
|
| 794 |
|
|
verbose "$comp_output" 3
|
| 795 |
|
|
|
| 796 |
|
|
if { ($expmsg == "") == ($comp_output == "") \
|
| 797 |
|
|
&& [regexp $expmsg $comp_output] \
|
| 798 |
|
|
&& (($cmdret == 0) == ($opts(error) == "")) } {
|
| 799 |
|
|
# We have the expected output from ld.
|
| 800 |
|
|
if { $opts(error) != "" || $program == "" } {
|
| 801 |
|
|
pass $testname
|
| 802 |
|
|
return
|
| 803 |
|
|
}
|
| 804 |
|
|
} else {
|
| 805 |
|
|
verbose -log "$exitstat with: <$comp_output>, expected: <$expmsg>"
|
| 806 |
|
|
fail $testname
|
| 807 |
|
|
return
|
| 808 |
|
|
}
|
| 809 |
|
|
}
|
| 810 |
|
|
} else {
|
| 811 |
|
|
set objfile "tmpdir/dump0.o"
|
| 812 |
|
|
}
|
| 813 |
|
|
|
| 814 |
|
|
# We must not have expected failure if we get here.
|
| 815 |
|
|
if { $opts(error) != "" } {
|
| 816 |
|
|
fail $testname
|
| 817 |
|
|
return
|
| 818 |
|
|
}
|
| 819 |
|
|
|
| 820 |
|
|
set progopts1 $opts($program)
|
| 821 |
|
|
eval set progopts \$[string toupper $program]FLAGS
|
| 822 |
|
|
eval set binary \$[string toupper $program]
|
| 823 |
|
|
|
| 824 |
|
|
if { ![is_remote host] && [which $binary] == 0 } {
|
| 825 |
|
|
untested $testname
|
| 826 |
|
|
return
|
| 827 |
|
|
}
|
| 828 |
|
|
|
| 829 |
|
|
if { $progopts1 == "" } { set $progopts1 "-r" }
|
| 830 |
|
|
verbose "running $binary $progopts $progopts1" 3
|
| 831 |
|
|
|
| 832 |
|
|
# Objcopy, unlike the other two, won't send its output to stdout,
|
| 833 |
|
|
# so we have to run it specially.
|
| 834 |
|
|
set cmd "$binary $progopts $progopts1 $objfile > $dumpfile"
|
| 835 |
|
|
if { $program == "objcopy" } {
|
| 836 |
|
|
set cmd "$binary $progopts $progopts1 $objfile $dumpfile"
|
| 837 |
|
|
}
|
| 838 |
|
|
|
| 839 |
|
|
# Ensure consistent sorting of symbols
|
| 840 |
|
|
if {[info exists env(LC_ALL)]} {
|
| 841 |
|
|
set old_lc_all $env(LC_ALL)
|
| 842 |
|
|
}
|
| 843 |
|
|
set env(LC_ALL) "C"
|
| 844 |
|
|
send_log "$cmd\n"
|
| 845 |
|
|
set cmdret [remote_exec host [concat sh -c [list "$cmd 2>ld.tmp"]] "" "/dev/null"]
|
| 846 |
|
|
set cmdret [lindex $cmdret 0]
|
| 847 |
|
|
remote_upload host "ld.tmp"
|
| 848 |
|
|
set comp_output [prune_warnings [file_contents "ld.tmp"]]
|
| 849 |
|
|
remote_file host delete "ld.tmp"
|
| 850 |
|
|
remote_file build delete "ld.tmp"
|
| 851 |
|
|
if {[info exists old_lc_all]} {
|
| 852 |
|
|
set env(LC_ALL) $old_lc_all
|
| 853 |
|
|
} else {
|
| 854 |
|
|
unset env(LC_ALL)
|
| 855 |
|
|
}
|
| 856 |
|
|
if { $cmdret != 0 || $comp_output != "" } {
|
| 857 |
|
|
send_log "exited abnormally with $cmdret, output:$comp_output\n"
|
| 858 |
|
|
fail $testname
|
| 859 |
|
|
return
|
| 860 |
|
|
}
|
| 861 |
|
|
|
| 862 |
|
|
if { $verbose > 2 } then { verbose "output is [file_contents $dumpfile]" 3 }
|
| 863 |
|
|
if { [regexp_diff $dumpfile "${file}.d"] } then {
|
| 864 |
|
|
fail $testname
|
| 865 |
|
|
if { $verbose == 2 } then { verbose "output is [file_contents $dumpfile]" 2 }
|
| 866 |
|
|
return
|
| 867 |
|
|
}
|
| 868 |
|
|
|
| 869 |
|
|
pass $testname
|
| 870 |
|
|
}
|
| 871 |
|
|
|
| 872 |
|
|
proc slurp_options { file } {
|
| 873 |
|
|
if [catch { set f [open $file r] } x] {
|
| 874 |
|
|
#perror "couldn't open `$file': $x"
|
| 875 |
|
|
perror "$x"
|
| 876 |
|
|
return -1
|
| 877 |
|
|
}
|
| 878 |
|
|
set opt_array {}
|
| 879 |
|
|
# whitespace expression
|
| 880 |
|
|
set ws {[ ]*}
|
| 881 |
|
|
set nws {[^ ]*}
|
| 882 |
|
|
# whitespace is ignored anywhere except within the options list;
|
| 883 |
|
|
# option names are alphabetic plus underscore only.
|
| 884 |
|
|
set pat "^#${ws}(\[a-zA-Z_\]*)$ws:${ws}(.*)$ws\$"
|
| 885 |
|
|
while { [gets $f line] != -1 } {
|
| 886 |
|
|
set line [string trim $line]
|
| 887 |
|
|
# Whitespace here is space-tab.
|
| 888 |
|
|
if [regexp $pat $line xxx opt_name opt_val] {
|
| 889 |
|
|
# match!
|
| 890 |
|
|
lappend opt_array [list $opt_name $opt_val]
|
| 891 |
|
|
} else {
|
| 892 |
|
|
break
|
| 893 |
|
|
}
|
| 894 |
|
|
}
|
| 895 |
|
|
close $f
|
| 896 |
|
|
return $opt_array
|
| 897 |
|
|
}
|
| 898 |
|
|
|
| 899 |
|
|
proc file_contents { filename } {
|
| 900 |
|
|
set file [open $filename r]
|
| 901 |
|
|
set contents [read $file]
|
| 902 |
|
|
close $file
|
| 903 |
|
|
return $contents
|
| 904 |
|
|
}
|
| 905 |
|
|
|
| 906 |
|
|
proc set_file_contents { filename contents } {
|
| 907 |
|
|
set file [open $filename w]
|
| 908 |
|
|
puts $file "$contents"
|
| 909 |
|
|
close $file
|
| 910 |
|
|
}
|
| 911 |
|
|
|
| 912 |
|
|
# Create an archive using ar
|
| 913 |
|
|
#
|
| 914 |
|
|
proc ar_simple_create { ar aropts target objects } {
|
| 915 |
|
|
remote_file host delete $target
|
| 916 |
|
|
|
| 917 |
|
|
set exec_output [run_host_cmd "$ar" "$aropts rc $target $objects"]
|
| 918 |
|
|
set exec_output [prune_warnings $exec_output]
|
| 919 |
|
|
|
| 920 |
|
|
if [string match "" $exec_output] then {
|
| 921 |
|
|
send_log "$exec_output\n"
|
| 922 |
|
|
return 1
|
| 923 |
|
|
} else {
|
| 924 |
|
|
return 0
|
| 925 |
|
|
}
|
| 926 |
|
|
}
|
| 927 |
|
|
|
| 928 |
|
|
# List contains test-items with 3 items followed by 2 lists, one item and
|
| 929 |
|
|
# one optional item:
|
| 930 |
148 |
khays |
# 0:name
|
| 931 |
|
|
# 1:ld/ar options
|
| 932 |
|
|
# 2:assembler options
|
| 933 |
|
|
# 3:filenames of assembler files
|
| 934 |
|
|
# 4:list of actions, options and expected outputs.
|
| 935 |
|
|
# 5:name of output file
|
| 936 |
|
|
# 6:compiler flags (optional)
|
| 937 |
135 |
khays |
#
|
| 938 |
148 |
khays |
# Actions: { command command-line-options file-containg-expected-output-regexps }
|
| 939 |
|
|
# Commands:
|
| 940 |
|
|
# objdump: Apply objdump options on result.
|
| 941 |
|
|
# nm: Apply nm options on result.
|
| 942 |
|
|
# readelf: Apply readelf options on result.
|
| 943 |
|
|
# ld: Don't apply anything on result. Compare output during linking with
|
| 944 |
|
|
# the file containing regexps (which is the second arg, not the third).
|
| 945 |
|
|
# Note that this *must* be the first action if it is to be used at all;
|
| 946 |
|
|
# in all other cases, any output from the linker during linking is
|
| 947 |
|
|
# treated as a sign of an error and FAILs the test.
|
| 948 |
135 |
khays |
#
|
| 949 |
|
|
proc run_ld_link_tests { ldtests } {
|
| 950 |
|
|
global ld
|
| 951 |
|
|
global as
|
| 952 |
|
|
global nm
|
| 953 |
|
|
global ar
|
| 954 |
|
|
global objdump
|
| 955 |
|
|
global READELF
|
| 956 |
|
|
global srcdir
|
| 957 |
|
|
global subdir
|
| 958 |
|
|
global env
|
| 959 |
|
|
global CC
|
| 960 |
|
|
global CFLAGS
|
| 961 |
|
|
global runtests
|
| 962 |
|
|
global exec_output
|
| 963 |
|
|
|
| 964 |
|
|
foreach testitem $ldtests {
|
| 965 |
|
|
set testname [lindex $testitem 0]
|
| 966 |
|
|
|
| 967 |
|
|
if ![runtest_file_p $runtests $testname] then {
|
| 968 |
|
|
continue
|
| 969 |
|
|
}
|
| 970 |
|
|
|
| 971 |
|
|
set ld_options [lindex $testitem 1]
|
| 972 |
|
|
set as_options [lindex $testitem 2]
|
| 973 |
|
|
set src_files [lindex $testitem 3]
|
| 974 |
|
|
set actions [lindex $testitem 4]
|
| 975 |
|
|
set binfile tmpdir/[lindex $testitem 5]
|
| 976 |
|
|
set cflags [lindex $testitem 6]
|
| 977 |
|
|
set objfiles {}
|
| 978 |
|
|
set is_unresolved 0
|
| 979 |
|
|
set failed 0
|
| 980 |
|
|
set maybe_failed 0
|
| 981 |
|
|
set ld_output ""
|
| 982 |
|
|
|
| 983 |
|
|
# verbose -log "Testname is $testname"
|
| 984 |
|
|
# verbose -log "ld_options is $ld_options"
|
| 985 |
|
|
# verbose -log "as_options is $as_options"
|
| 986 |
|
|
# verbose -log "src_files is $src_files"
|
| 987 |
|
|
# verbose -log "actions is $actions"
|
| 988 |
|
|
# verbose -log "binfile is $binfile"
|
| 989 |
|
|
|
| 990 |
|
|
# Assemble each file in the test.
|
| 991 |
|
|
foreach src_file $src_files {
|
| 992 |
166 |
khays |
set fileroot "[file rootname [file tail $src_file]]"
|
| 993 |
|
|
set objfile "tmpdir/$fileroot.o"
|
| 994 |
135 |
khays |
lappend objfiles $objfile
|
| 995 |
|
|
|
| 996 |
|
|
if { [file extension $src_file] == ".c" } {
|
| 997 |
166 |
khays |
set as_file "tmpdir/$fileroot.s"
|
| 998 |
135 |
khays |
if ![ld_compile "$CC -S $CFLAGS $cflags" $srcdir/$subdir/$src_file $as_file] {
|
| 999 |
|
|
set is_unresolved 1
|
| 1000 |
|
|
break
|
| 1001 |
|
|
}
|
| 1002 |
|
|
} else {
|
| 1003 |
|
|
set as_file "$srcdir/$subdir/$src_file"
|
| 1004 |
|
|
}
|
| 1005 |
|
|
if ![ld_assemble $as "$as_options $as_file" $objfile] {
|
| 1006 |
|
|
set is_unresolved 1
|
| 1007 |
|
|
break
|
| 1008 |
|
|
}
|
| 1009 |
|
|
}
|
| 1010 |
|
|
|
| 1011 |
|
|
# Catch assembler errors.
|
| 1012 |
|
|
if { $is_unresolved } {
|
| 1013 |
|
|
unresolved $testname
|
| 1014 |
|
|
continue
|
| 1015 |
|
|
}
|
| 1016 |
|
|
|
| 1017 |
|
|
if { [regexp ".*\\.a$" $binfile] } {
|
| 1018 |
|
|
if { ![ar_simple_create $ar $ld_options $binfile "$objfiles"] } {
|
| 1019 |
|
|
set failed 1
|
| 1020 |
|
|
}
|
| 1021 |
|
|
} elseif { ![ld_simple_link $ld $binfile "-L$srcdir/$subdir $ld_options $objfiles"] } {
|
| 1022 |
|
|
set maybe_failed 1
|
| 1023 |
|
|
set ld_output "$exec_output"
|
| 1024 |
|
|
}
|
| 1025 |
|
|
|
| 1026 |
|
|
if { !$failed } {
|
| 1027 |
|
|
foreach actionlist $actions {
|
| 1028 |
|
|
set action [lindex $actionlist 0]
|
| 1029 |
|
|
set progopts [lindex $actionlist 1]
|
| 1030 |
|
|
|
| 1031 |
|
|
# There are actions where we run regexp_diff on the
|
| 1032 |
|
|
# output, and there are other actions (presumably).
|
| 1033 |
|
|
# Handling of the former look the same.
|
| 1034 |
|
|
set dump_prog ""
|
| 1035 |
|
|
switch -- $action {
|
| 1036 |
|
|
objdump
|
| 1037 |
|
|
{ set dump_prog $objdump }
|
| 1038 |
|
|
nm
|
| 1039 |
|
|
{ set dump_prog $nm }
|
| 1040 |
|
|
readelf
|
| 1041 |
|
|
{ set dump_prog $READELF }
|
| 1042 |
|
|
ld
|
| 1043 |
|
|
{ set dump_prog "ld" }
|
| 1044 |
|
|
default
|
| 1045 |
|
|
{
|
| 1046 |
|
|
perror "Unrecognized action $action"
|
| 1047 |
|
|
set is_unresolved 1
|
| 1048 |
|
|
break
|
| 1049 |
|
|
}
|
| 1050 |
|
|
}
|
| 1051 |
|
|
|
| 1052 |
|
|
if { $action == "ld" } {
|
| 1053 |
148 |
khays |
set regexpfile $progopts
|
| 1054 |
|
|
verbose "regexpfile is $srcdir/$subdir/$regexpfile"
|
| 1055 |
135 |
khays |
set_file_contents "tmpdir/ld.messages" "$ld_output"
|
| 1056 |
|
|
verbose "ld.messages has '[file_contents tmpdir/ld.messages]'"
|
| 1057 |
148 |
khays |
if { [regexp_diff "tmpdir/ld.messages" "$srcdir/$subdir/$regexpfile"] } then {
|
| 1058 |
135 |
khays |
verbose "output is $ld_output" 2
|
| 1059 |
|
|
set failed 1
|
| 1060 |
|
|
break
|
| 1061 |
|
|
}
|
| 1062 |
|
|
set maybe_failed 0
|
| 1063 |
|
|
} elseif { !$maybe_failed && $dump_prog != "" } {
|
| 1064 |
|
|
set dumpfile [lindex $actionlist 2]
|
| 1065 |
|
|
set binary $dump_prog
|
| 1066 |
|
|
|
| 1067 |
|
|
# Ensure consistent sorting of symbols
|
| 1068 |
|
|
if {[info exists env(LC_ALL)]} {
|
| 1069 |
|
|
set old_lc_all $env(LC_ALL)
|
| 1070 |
|
|
}
|
| 1071 |
|
|
set env(LC_ALL) "C"
|
| 1072 |
|
|
set cmd "$binary $progopts $binfile"
|
| 1073 |
|
|
set status [remote_exec host [concat sh -c [list "$cmd >dump.out 2>ld.stderr"]] "" "/dev/null"]
|
| 1074 |
|
|
send_log "$cmd\n"
|
| 1075 |
|
|
remote_upload host "ld.stderr"
|
| 1076 |
|
|
set comp_output [prune_warnings [file_contents "ld.stderr"]]
|
| 1077 |
|
|
remote_file host delete "ld.stderr"
|
| 1078 |
|
|
remote_file build delete "ld.stderr"
|
| 1079 |
|
|
|
| 1080 |
|
|
if {[info exists old_lc_all]} {
|
| 1081 |
|
|
set env(LC_ALL) $old_lc_all
|
| 1082 |
|
|
} else {
|
| 1083 |
|
|
unset env(LC_ALL)
|
| 1084 |
|
|
}
|
| 1085 |
|
|
|
| 1086 |
|
|
if ![string match "" $comp_output] then {
|
| 1087 |
|
|
send_log "$comp_output\n"
|
| 1088 |
|
|
set failed 1
|
| 1089 |
|
|
break
|
| 1090 |
|
|
}
|
| 1091 |
|
|
|
| 1092 |
|
|
remote_upload host "dump.out"
|
| 1093 |
|
|
|
| 1094 |
|
|
if { [regexp_diff "dump.out" "$srcdir/$subdir/$dumpfile"] } then {
|
| 1095 |
|
|
verbose "output is [file_contents "dump.out"]" 2
|
| 1096 |
|
|
set failed 1
|
| 1097 |
|
|
remote_file build delete "dump.out"
|
| 1098 |
|
|
remote_file host delete "dump.out"
|
| 1099 |
|
|
break
|
| 1100 |
|
|
}
|
| 1101 |
|
|
remote_file build delete "dump.out"
|
| 1102 |
|
|
remote_file host delete "dump.out"
|
| 1103 |
|
|
}
|
| 1104 |
|
|
}
|
| 1105 |
|
|
}
|
| 1106 |
|
|
|
| 1107 |
|
|
if { $is_unresolved } {
|
| 1108 |
|
|
unresolved $testname
|
| 1109 |
|
|
} elseif { $maybe_failed || $failed } {
|
| 1110 |
|
|
fail $testname
|
| 1111 |
|
|
} else {
|
| 1112 |
|
|
pass $testname
|
| 1113 |
|
|
}
|
| 1114 |
|
|
}
|
| 1115 |
|
|
}
|
| 1116 |
|
|
|
| 1117 |
|
|
# This definition is taken from an unreleased version of DejaGnu. Once
|
| 1118 |
|
|
# that version gets released, and has been out in the world for a few
|
| 1119 |
|
|
# months at least, it may be safe to delete this copy.
|
| 1120 |
|
|
if ![string length [info proc prune_warnings]] {
|
| 1121 |
|
|
#
|
| 1122 |
|
|
# prune_warnings -- delete various system verbosities from TEXT
|
| 1123 |
|
|
#
|
| 1124 |
|
|
# An example is:
|
| 1125 |
|
|
# ld.so: warning: /usr/lib/libc.so.1.8.1 has older revision than expected 9
|
| 1126 |
|
|
#
|
| 1127 |
|
|
# Sites with particular verbose os's may wish to override this in site.exp.
|
| 1128 |
|
|
#
|
| 1129 |
|
|
proc prune_warnings { text } {
|
| 1130 |
|
|
# This is from sun4's. Do it for all machines for now.
|
| 1131 |
|
|
# The "\\1" is to try to preserve a "\n" but only if necessary.
|
| 1132 |
|
|
regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text
|
| 1133 |
|
|
|
| 1134 |
|
|
# It might be tempting to get carried away and delete blank lines, etc.
|
| 1135 |
|
|
# Just delete *exactly* what we're ask to, and that's it.
|
| 1136 |
|
|
return $text
|
| 1137 |
|
|
}
|
| 1138 |
|
|
}
|
| 1139 |
|
|
|
| 1140 |
|
|
# targets_to_xfail is a list of target triplets to be xfailed.
|
| 1141 |
|
|
# ldtests contains test-items with 3 items followed by 1 lists, 2 items
|
| 1142 |
|
|
# and 3 optional items:
|
| 1143 |
|
|
# 0:name
|
| 1144 |
|
|
# 1:ld options
|
| 1145 |
|
|
# 2:assembler options
|
| 1146 |
|
|
# 3:filenames of source files
|
| 1147 |
|
|
# 4:name of output file
|
| 1148 |
|
|
# 5:expected output
|
| 1149 |
|
|
# 6:compiler flags (optional)
|
| 1150 |
|
|
# 7:language (optional)
|
| 1151 |
|
|
# 8:linker warning (optional)
|
| 1152 |
|
|
|
| 1153 |
|
|
proc run_ld_link_exec_tests { targets_to_xfail ldtests } {
|
| 1154 |
|
|
global ld
|
| 1155 |
|
|
global as
|
| 1156 |
|
|
global srcdir
|
| 1157 |
|
|
global subdir
|
| 1158 |
|
|
global env
|
| 1159 |
|
|
global CC
|
| 1160 |
|
|
global CXX
|
| 1161 |
|
|
global CFLAGS
|
| 1162 |
|
|
global CXXFLAGS
|
| 1163 |
|
|
global errcnt
|
| 1164 |
|
|
global exec_output
|
| 1165 |
|
|
|
| 1166 |
|
|
foreach testitem $ldtests {
|
| 1167 |
|
|
foreach target $targets_to_xfail {
|
| 1168 |
|
|
setup_xfail $target
|
| 1169 |
|
|
}
|
| 1170 |
|
|
set testname [lindex $testitem 0]
|
| 1171 |
|
|
set ld_options [lindex $testitem 1]
|
| 1172 |
|
|
set as_options [lindex $testitem 2]
|
| 1173 |
|
|
set src_files [lindex $testitem 3]
|
| 1174 |
|
|
set binfile tmpdir/[lindex $testitem 4]
|
| 1175 |
|
|
set expfile [lindex $testitem 5]
|
| 1176 |
|
|
set cflags [lindex $testitem 6]
|
| 1177 |
|
|
set lang [lindex $testitem 7]
|
| 1178 |
|
|
set warning [lindex $testitem 8]
|
| 1179 |
|
|
set objfiles {}
|
| 1180 |
|
|
set failed 0
|
| 1181 |
|
|
|
| 1182 |
|
|
# verbose -log "Testname is $testname"
|
| 1183 |
|
|
# verbose -log "ld_options is $ld_options"
|
| 1184 |
|
|
# verbose -log "as_options is $as_options"
|
| 1185 |
|
|
# verbose -log "src_files is $src_files"
|
| 1186 |
|
|
# verbose -log "actions is $actions"
|
| 1187 |
|
|
# verbose -log "binfile is $binfile"
|
| 1188 |
|
|
|
| 1189 |
|
|
# Assemble each file in the test.
|
| 1190 |
|
|
foreach src_file $src_files {
|
| 1191 |
166 |
khays |
set fileroot "[file rootname [file tail $src_file]]"
|
| 1192 |
|
|
set objfile "tmpdir/$fileroot.o"
|
| 1193 |
135 |
khays |
lappend objfiles $objfile
|
| 1194 |
|
|
|
| 1195 |
|
|
# We ignore warnings since some compilers may generate
|
| 1196 |
|
|
# incorrect section attributes and the assembler will warn
|
| 1197 |
|
|
# them.
|
| 1198 |
|
|
if { [ string match "c++" $lang ] } {
|
| 1199 |
|
|
ld_compile "$CXX -c $CXXFLAGS $cflags" $srcdir/$subdir/$src_file $objfile
|
| 1200 |
|
|
} else {
|
| 1201 |
|
|
ld_compile "$CC -c $CFLAGS $cflags" $srcdir/$subdir/$src_file $objfile
|
| 1202 |
|
|
}
|
| 1203 |
|
|
|
| 1204 |
|
|
# We have to use $CC to build PIE and shared library.
|
| 1205 |
|
|
if { [ string match "c" $lang ] } {
|
| 1206 |
|
|
set link_proc ld_simple_link
|
| 1207 |
|
|
set link_cmd $CC
|
| 1208 |
|
|
} elseif { [ string match "c++" $lang ] } {
|
| 1209 |
|
|
set link_proc ld_simple_link
|
| 1210 |
|
|
set link_cmd $CXX
|
| 1211 |
|
|
} elseif { [ string match "-shared" $ld_options ] \
|
| 1212 |
|
|
|| [ string match "-pie" $ld_options ] } {
|
| 1213 |
|
|
set link_proc ld_simple_link
|
| 1214 |
|
|
set link_cmd $CC
|
| 1215 |
|
|
} else {
|
| 1216 |
|
|
set link_proc ld_link
|
| 1217 |
|
|
set link_cmd $ld
|
| 1218 |
|
|
}
|
| 1219 |
|
|
|
| 1220 |
|
|
if ![$link_proc $link_cmd $binfile "-L$srcdir/$subdir $ld_options $objfiles"] {
|
| 1221 |
|
|
set failed 1
|
| 1222 |
|
|
} else {
|
| 1223 |
|
|
set failed 0
|
| 1224 |
|
|
}
|
| 1225 |
|
|
|
| 1226 |
|
|
# Check if exec_output is expected.
|
| 1227 |
|
|
if { $warning != "" } then {
|
| 1228 |
|
|
verbose -log "returned with: <$exec_output>, expected: <$warning>"
|
| 1229 |
|
|
if { [regexp $warning $exec_output] } then {
|
| 1230 |
|
|
set failed 0
|
| 1231 |
|
|
} else {
|
| 1232 |
|
|
set failed 1
|
| 1233 |
|
|
}
|
| 1234 |
|
|
}
|
| 1235 |
|
|
|
| 1236 |
|
|
if { $failed == 0 } {
|
| 1237 |
|
|
send_log "Running: $binfile > $binfile.out\n"
|
| 1238 |
|
|
verbose "Running: $binfile > $binfile.out"
|
| 1239 |
|
|
catch "exec $binfile > $binfile.out" exec_output
|
| 1240 |
|
|
|
| 1241 |
|
|
if ![string match "" $exec_output] then {
|
| 1242 |
|
|
send_log "$exec_output\n"
|
| 1243 |
|
|
verbose "$exec_output" 1
|
| 1244 |
|
|
set failed 1
|
| 1245 |
|
|
} else {
|
| 1246 |
|
|
send_log "diff $binfile.out $srcdir/$subdir/$expfile\n"
|
| 1247 |
|
|
verbose "diff $binfile.out $srcdir/$subdir/$expfile"
|
| 1248 |
|
|
catch "exec diff $binfile.out $srcdir/$subdir/$expfile" exec_output
|
| 1249 |
|
|
set exec_output [prune_warnings $exec_output]
|
| 1250 |
|
|
|
| 1251 |
|
|
if ![string match "" $exec_output] then {
|
| 1252 |
|
|
send_log "$exec_output\n"
|
| 1253 |
|
|
verbose "$exec_output" 1
|
| 1254 |
|
|
set failed 1
|
| 1255 |
|
|
}
|
| 1256 |
|
|
}
|
| 1257 |
|
|
}
|
| 1258 |
|
|
|
| 1259 |
|
|
if { $failed != 0 } {
|
| 1260 |
|
|
fail $testname
|
| 1261 |
|
|
} else {
|
| 1262 |
|
|
set errcnt 0
|
| 1263 |
|
|
pass $testname
|
| 1264 |
|
|
}
|
| 1265 |
|
|
}
|
| 1266 |
|
|
}
|
| 1267 |
|
|
}
|
| 1268 |
|
|
|
| 1269 |
|
|
# List contains test-items with 3 items followed by 2 lists, one item and
|
| 1270 |
|
|
# one optional item:
|
| 1271 |
|
|
# 0:name
|
| 1272 |
|
|
# 1:ld or ar options
|
| 1273 |
|
|
# 2:compile options
|
| 1274 |
|
|
# 3:filenames of source files
|
| 1275 |
|
|
# 4:action and options.
|
| 1276 |
|
|
# 5:name of output file
|
| 1277 |
|
|
# 6:language (optional)
|
| 1278 |
|
|
# 7:linker warnings (optional)
|
| 1279 |
|
|
#
|
| 1280 |
|
|
# Actions:
|
| 1281 |
|
|
# objdump: Apply objdump options on result. Compare with regex (last arg).
|
| 1282 |
|
|
# nm: Apply nm options on result. Compare with regex (last arg).
|
| 1283 |
|
|
# readelf: Apply readelf options on result. Compare with regex (last arg).
|
| 1284 |
|
|
#
|
| 1285 |
|
|
proc run_cc_link_tests { ldtests } {
|
| 1286 |
|
|
global nm
|
| 1287 |
|
|
global objdump
|
| 1288 |
|
|
global READELF
|
| 1289 |
|
|
global srcdir
|
| 1290 |
|
|
global subdir
|
| 1291 |
|
|
global env
|
| 1292 |
|
|
global CC
|
| 1293 |
|
|
global CXX
|
| 1294 |
|
|
global CFLAGS
|
| 1295 |
|
|
global CXXFLAGS
|
| 1296 |
|
|
global ar
|
| 1297 |
|
|
global exec_output
|
| 1298 |
|
|
|
| 1299 |
|
|
foreach testitem $ldtests {
|
| 1300 |
|
|
set testname [lindex $testitem 0]
|
| 1301 |
|
|
set ldflags [lindex $testitem 1]
|
| 1302 |
|
|
set cflags [lindex $testitem 2]
|
| 1303 |
|
|
set src_files [lindex $testitem 3]
|
| 1304 |
|
|
set actions [lindex $testitem 4]
|
| 1305 |
|
|
set binfile tmpdir/[lindex $testitem 5]
|
| 1306 |
|
|
set lang [lindex $testitem 6]
|
| 1307 |
|
|
set warnings [lindex $testitem 7]
|
| 1308 |
|
|
set objfiles {}
|
| 1309 |
|
|
set is_unresolved 0
|
| 1310 |
|
|
set failed 0
|
| 1311 |
|
|
|
| 1312 |
|
|
# Compile each file in the test.
|
| 1313 |
|
|
foreach src_file $src_files {
|
| 1314 |
166 |
khays |
set fileroot "[file rootname [file tail $src_file]]"
|
| 1315 |
|
|
set objfile "tmpdir/$fileroot.o"
|
| 1316 |
135 |
khays |
lappend objfiles $objfile
|
| 1317 |
|
|
|
| 1318 |
|
|
# We ignore warnings since some compilers may generate
|
| 1319 |
|
|
# incorrect section attributes and the assembler will warn
|
| 1320 |
|
|
# them.
|
| 1321 |
|
|
if { [ string match "c++" $lang ] } {
|
| 1322 |
|
|
ld_compile "$CXX -c $CXXFLAGS $cflags" $srcdir/$subdir/$src_file $objfile
|
| 1323 |
|
|
} else {
|
| 1324 |
|
|
ld_compile "$CC -c $CFLAGS $cflags" $srcdir/$subdir/$src_file $objfile
|
| 1325 |
|
|
}
|
| 1326 |
|
|
}
|
| 1327 |
|
|
|
| 1328 |
|
|
# Clear error and warning counts.
|
| 1329 |
|
|
reset_vars
|
| 1330 |
|
|
|
| 1331 |
|
|
if { [ string match "c++" $lang ] } {
|
| 1332 |
|
|
set cc_cmd $CXX
|
| 1333 |
|
|
} else {
|
| 1334 |
|
|
set cc_cmd $CC
|
| 1335 |
|
|
}
|
| 1336 |
|
|
|
| 1337 |
|
|
if { [regexp ".*\\.a$" $binfile] } {
|
| 1338 |
|
|
if { ![ar_simple_create $ar $ldflags $binfile "$objfiles"] } {
|
| 1339 |
|
|
fail $testname
|
| 1340 |
|
|
set failed 1
|
| 1341 |
|
|
} else {
|
| 1342 |
|
|
set failed 0
|
| 1343 |
|
|
}
|
| 1344 |
|
|
} elseif { ![ld_simple_link $cc_cmd $binfile "-L$srcdir/$subdir $ldflags $objfiles"] } {
|
| 1345 |
|
|
# Check if exec_output is expected.
|
| 1346 |
|
|
if { $warnings != "" } then {
|
| 1347 |
|
|
verbose -log "returned with: <$exec_output>, expected: <$warnings>"
|
| 1348 |
|
|
if { [regexp $warnings $exec_output] } then {
|
| 1349 |
|
|
set failed 0
|
| 1350 |
|
|
} else {
|
| 1351 |
|
|
set failed 1
|
| 1352 |
|
|
}
|
| 1353 |
|
|
} else {
|
| 1354 |
|
|
fail $testname
|
| 1355 |
|
|
set failed 1
|
| 1356 |
|
|
}
|
| 1357 |
|
|
} else {
|
| 1358 |
|
|
set failed 0
|
| 1359 |
|
|
}
|
| 1360 |
|
|
|
| 1361 |
|
|
if { $failed == 0 } {
|
| 1362 |
|
|
foreach actionlist $actions {
|
| 1363 |
|
|
set action [lindex $actionlist 0]
|
| 1364 |
|
|
set progopts [lindex $actionlist 1]
|
| 1365 |
|
|
|
| 1366 |
|
|
# There are actions where we run regexp_diff on the
|
| 1367 |
|
|
# output, and there are other actions (presumably).
|
| 1368 |
|
|
# Handling of the former look the same.
|
| 1369 |
|
|
set dump_prog ""
|
| 1370 |
|
|
switch -- $action {
|
| 1371 |
|
|
objdump
|
| 1372 |
|
|
{ set dump_prog $objdump }
|
| 1373 |
|
|
nm
|
| 1374 |
|
|
{ set dump_prog $nm }
|
| 1375 |
|
|
readelf
|
| 1376 |
|
|
{ set dump_prog $READELF }
|
| 1377 |
|
|
default
|
| 1378 |
|
|
{
|
| 1379 |
|
|
perror "Unrecognized action $action"
|
| 1380 |
|
|
set is_unresolved 1
|
| 1381 |
|
|
break
|
| 1382 |
|
|
}
|
| 1383 |
|
|
}
|
| 1384 |
|
|
|
| 1385 |
|
|
if { $dump_prog != "" } {
|
| 1386 |
|
|
set dumpfile [lindex $actionlist 2]
|
| 1387 |
|
|
set binary $dump_prog
|
| 1388 |
|
|
|
| 1389 |
|
|
# Ensure consistent sorting of symbols
|
| 1390 |
|
|
if {[info exists env(LC_ALL)]} {
|
| 1391 |
|
|
set old_lc_all $env(LC_ALL)
|
| 1392 |
|
|
}
|
| 1393 |
|
|
set env(LC_ALL) "C"
|
| 1394 |
|
|
set cmd "$binary $progopts $binfile > dump.out"
|
| 1395 |
|
|
send_log "$cmd\n"
|
| 1396 |
|
|
catch "exec $cmd" comp_output
|
| 1397 |
|
|
if {[info exists old_lc_all]} {
|
| 1398 |
|
|
set env(LC_ALL) $old_lc_all
|
| 1399 |
|
|
} else {
|
| 1400 |
|
|
unset env(LC_ALL)
|
| 1401 |
|
|
}
|
| 1402 |
|
|
set comp_output [prune_warnings $comp_output]
|
| 1403 |
|
|
|
| 1404 |
|
|
if ![string match "" $comp_output] then {
|
| 1405 |
|
|
send_log "$comp_output\n"
|
| 1406 |
|
|
set failed 1
|
| 1407 |
|
|
break
|
| 1408 |
|
|
}
|
| 1409 |
|
|
|
| 1410 |
|
|
if { [regexp_diff "dump.out" "$srcdir/$subdir/$dumpfile"] } then {
|
| 1411 |
|
|
verbose "output is [file_contents "dump.out"]" 2
|
| 1412 |
|
|
set failed 1
|
| 1413 |
|
|
break
|
| 1414 |
|
|
}
|
| 1415 |
|
|
}
|
| 1416 |
|
|
}
|
| 1417 |
|
|
|
| 1418 |
|
|
if { $failed != 0 } {
|
| 1419 |
|
|
fail $testname
|
| 1420 |
|
|
} else { if { $is_unresolved == 0 } {
|
| 1421 |
|
|
pass $testname
|
| 1422 |
|
|
} }
|
| 1423 |
|
|
}
|
| 1424 |
|
|
|
| 1425 |
|
|
# Catch action errors.
|
| 1426 |
|
|
if { $is_unresolved != 0 } {
|
| 1427 |
|
|
unresolved $testname
|
| 1428 |
|
|
continue
|
| 1429 |
|
|
}
|
| 1430 |
|
|
}
|
| 1431 |
|
|
}
|
| 1432 |
|
|
|
| 1433 |
|
|
# Returns true if --gc-sections is supported on the target.
|
| 1434 |
|
|
|
| 1435 |
|
|
proc check_gc_sections_available { } {
|
| 1436 |
|
|
global gc_sections_available_saved
|
| 1437 |
|
|
global ld
|
| 1438 |
|
|
|
| 1439 |
|
|
if {![info exists gc_sections_available_saved]} {
|
| 1440 |
|
|
# Some targets don't support gc-sections despite whatever's
|
| 1441 |
|
|
# advertised by ld's options.
|
| 1442 |
|
|
if {[istarget arc-*-*]
|
| 1443 |
|
|
|| [istarget d30v-*-*]
|
| 1444 |
|
|
|| [istarget dlx-*-*]
|
| 1445 |
|
|
|| [istarget i960-*-*]
|
| 1446 |
|
|
|| [istarget or32-*-*]
|
| 1447 |
|
|
|| [istarget pj*-*-*]
|
| 1448 |
|
|
|| [istarget alpha-*-*]
|
| 1449 |
163 |
khays |
|| [istarget hppa*64-*-*]
|
| 1450 |
135 |
khays |
|| [istarget i370-*-*]
|
| 1451 |
|
|
|| [istarget i860-*-*]
|
| 1452 |
|
|
|| [istarget ia64-*-*]
|
| 1453 |
|
|
|| [istarget mep-*-*]
|
| 1454 |
|
|
|| [istarget mn10200-*-*]
|
| 1455 |
|
|
|| [istarget *-*-cygwin]
|
| 1456 |
|
|
|| [istarget *-*-mingw*] } {
|
| 1457 |
|
|
set gc_sections_available_saved 0
|
| 1458 |
|
|
return 0
|
| 1459 |
|
|
}
|
| 1460 |
|
|
|
| 1461 |
|
|
# elf2flt uses -q (--emit-relocs), which is incompatible with
|
| 1462 |
|
|
# --gc-sections.
|
| 1463 |
|
|
if { [board_info target exists ldflags]
|
| 1464 |
|
|
&& [regexp " -elf2flt\[ =\]" " [board_info target ldflags] "] } {
|
| 1465 |
|
|
set gc_sections_available_saved 0
|
| 1466 |
|
|
return 0
|
| 1467 |
|
|
}
|
| 1468 |
|
|
|
| 1469 |
|
|
# Check if the ld used by gcc supports --gc-sections.
|
| 1470 |
163 |
khays |
# FIXME: this test is useless since ld --help always says
|
| 1471 |
|
|
# --gc-sections is available
|
| 1472 |
135 |
khays |
set ld_output [remote_exec host $ld "--help"]
|
| 1473 |
|
|
if { [ string first "--gc-sections" $ld_output ] >= 0 } {
|
| 1474 |
|
|
set gc_sections_available_saved 1
|
| 1475 |
|
|
} else {
|
| 1476 |
|
|
set gc_sections_available_saved 0
|
| 1477 |
|
|
}
|
| 1478 |
|
|
}
|
| 1479 |
|
|
return $gc_sections_available_saved
|
| 1480 |
|
|
}
|
| 1481 |
|
|
|
| 1482 |
163 |
khays |
# Returns true if -shared is supported on the target
|
| 1483 |
|
|
# Only used and accurate for ELF targets at the moment
|
| 1484 |
|
|
|
| 1485 |
|
|
proc check_shared_lib_support { } {
|
| 1486 |
|
|
if {![istarget arc-*-*]
|
| 1487 |
|
|
&& ![istarget avr-*-*]
|
| 1488 |
|
|
&& ![istarget cr16-*-*]
|
| 1489 |
|
|
&& ![istarget cris*-*-*]
|
| 1490 |
|
|
&& ![istarget crx-*-*]
|
| 1491 |
|
|
&& ![istarget d10v-*-*]
|
| 1492 |
|
|
&& ![istarget d30v-*-*]
|
| 1493 |
|
|
&& ![istarget dlx-*-*]
|
| 1494 |
|
|
&& ![istarget epiphany-*-*]
|
| 1495 |
|
|
&& ![istarget fr30-*-*]
|
| 1496 |
|
|
&& ![istarget frv-*-*]
|
| 1497 |
|
|
&& ![istarget h8300-*-*]
|
| 1498 |
|
|
&& ![istarget i860-*-*]
|
| 1499 |
|
|
&& ![istarget i960-*-*]
|
| 1500 |
|
|
&& ![istarget ip2k-*-*]
|
| 1501 |
|
|
&& ![istarget iq2000-*-*]
|
| 1502 |
|
|
&& ![istarget lm32-*-*]
|
| 1503 |
|
|
&& ![istarget m32c-*-*]
|
| 1504 |
|
|
&& ![istarget m32r-*-*]
|
| 1505 |
166 |
khays |
&& ![istarget m6811-*-*]
|
| 1506 |
|
|
&& ![istarget m6812-*-*]
|
| 1507 |
163 |
khays |
&& ![istarget m68hc1*-*-*]
|
| 1508 |
|
|
&& ![istarget mcore*-*-*]
|
| 1509 |
|
|
&& ![istarget mep-*-*]
|
| 1510 |
|
|
&& ![istarget microblaze-*-*]
|
| 1511 |
|
|
&& ![istarget mn10200-*-*]
|
| 1512 |
|
|
&& ![istarget moxie-*-*]
|
| 1513 |
|
|
&& ![istarget msp430-*-*]
|
| 1514 |
|
|
&& ![istarget mt-*-*]
|
| 1515 |
|
|
&& ![istarget openrisc-*-*]
|
| 1516 |
|
|
&& ![istarget or32-*-*]
|
| 1517 |
|
|
&& ![istarget pj-*-*]
|
| 1518 |
|
|
&& ![istarget rx-*-*]
|
| 1519 |
|
|
&& ![istarget spu-*-*]
|
| 1520 |
|
|
&& ![istarget v850*-*-*]
|
| 1521 |
|
|
&& ![istarget xstormy16-*-*]
|
| 1522 |
|
|
&& ![istarget *-*-irix*]
|
| 1523 |
|
|
&& ![istarget *-*-rtems] } {
|
| 1524 |
|
|
return 1
|
| 1525 |
|
|
}
|
| 1526 |
|
|
return 0
|
| 1527 |
|
|
}
|
| 1528 |
|
|
|
| 1529 |
135 |
khays |
# Returns true if the target ld supports the plugin API.
|
| 1530 |
|
|
proc check_plugin_api_available { } {
|
| 1531 |
|
|
global plugin_api_available_saved
|
| 1532 |
|
|
global ld
|
| 1533 |
|
|
if {![info exists plugin_api_available_saved]} {
|
| 1534 |
|
|
# Check if the ld used by gcc supports --plugin.
|
| 1535 |
|
|
set ld_output [remote_exec host $ld "--help"]
|
| 1536 |
|
|
if { [ string first "-plugin" $ld_output ] >= 0 } {
|
| 1537 |
|
|
set plugin_api_available_saved 1
|
| 1538 |
|
|
} else {
|
| 1539 |
|
|
set plugin_api_available_saved 0
|
| 1540 |
|
|
}
|
| 1541 |
|
|
}
|
| 1542 |
|
|
return $plugin_api_available_saved
|
| 1543 |
|
|
}
|
| 1544 |
|
|
|
| 1545 |
|
|
# Check if the assembler supports CFI statements.
|
| 1546 |
|
|
|
| 1547 |
|
|
proc check_as_cfi { } {
|
| 1548 |
|
|
global check_as_cfi_result
|
| 1549 |
|
|
global as
|
| 1550 |
|
|
if [info exists check_as_cfi_result] {
|
| 1551 |
|
|
return $check_as_cfi_result
|
| 1552 |
|
|
}
|
| 1553 |
|
|
set as_file "tmpdir/check_as_cfi.s"
|
| 1554 |
|
|
set as_fh [open $as_file w 0666]
|
| 1555 |
|
|
puts $as_fh "# Generated file. DO NOT EDIT"
|
| 1556 |
|
|
puts $as_fh "\t.cfi_startproc"
|
| 1557 |
|
|
puts $as_fh "\t.cfi_endproc"
|
| 1558 |
|
|
close $as_fh
|
| 1559 |
|
|
remote_download host $as_file
|
| 1560 |
|
|
verbose -log "Checking CFI support:"
|
| 1561 |
|
|
rename "perror" "check_as_cfi_perror"
|
| 1562 |
|
|
proc perror { args } { }
|
| 1563 |
|
|
set success [ld_assemble $as $as_file "/dev/null"]
|
| 1564 |
|
|
rename "perror" ""
|
| 1565 |
|
|
rename "check_as_cfi_perror" "perror"
|
| 1566 |
|
|
#remote_file host delete $as_file
|
| 1567 |
|
|
set check_as_cfi_result $success
|
| 1568 |
|
|
return $success
|
| 1569 |
|
|
}
|
| 1570 |
|
|
|
| 1571 |
|
|
# Provide virtual target "cfi" for targets supporting CFI.
|
| 1572 |
|
|
|
| 1573 |
|
|
rename "istarget" "istarget_ld"
|
| 1574 |
|
|
proc istarget { target } {
|
| 1575 |
|
|
if {$target == "cfi"} {
|
| 1576 |
|
|
return [check_as_cfi]
|
| 1577 |
|
|
}
|
| 1578 |
|
|
return [istarget_ld $target]
|
| 1579 |
|
|
}
|