Home | History | Annotate | Download | only in config
      1 # Basic expect script for LD Regression Tests
      2 #   Copyright (C) 1993-2016 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 if ![info exists size] then {
     53     set size [findfile $base_dir/../binutils/size]
     54 }
     55 
     56 remote_exec host "mkdir -p tmpdir"
     57 
     58 # Make symlinks from tmpdir/ld to the linker and assembler in the
     59 # build tree, so that we can use a -B option to gcc to force it to use
     60 # the newly built linker and assembler.
     61 if {![file isdirectory tmpdir/ld]} then {
     62     catch "exec mkdir tmpdir/ld" status
     63     catch "exec ln -s ../../ld-new tmpdir/ld/ld" status
     64     catch "exec ln -s ld tmpdir/ld/collect-ld" status
     65     catch "exec ln -s ../../../gas/as-new tmpdir/ld/as" status
     66 }
     67 set gcc_B_opt "-B[pwd]/tmpdir/ld/"
     68 
     69 # load the linker path
     70 set ld_L_opt ""
     71 if {[file exists tmpdir/libpath.exp]} {
     72     load_lib tmpdir/libpath.exp
     73 
     74     foreach dir $libpath {
     75 	append ld_L_opt " -L$dir"
     76     }
     77 }
     78 
     79 # Many ELF testcases expect that "-z relro" is off.
     80 set ld_elf_shared_opt "-z norelro"
     81 
     82 # The "make check" target in the Makefile passes in
     83 # "CC=$(CC_FOR_TARGET)".  But, if the user invokes runtest directly
     84 # (as when testing an installed linker), these flags may not be set.
     85 if {![info exists CC]} {
     86     set CC [find_gcc]
     87 }
     88 if {![info exists CFLAGS]} {
     89     set CFLAGS "-g -O2"
     90 }
     91 if {![info exists CXX]} {
     92     set CXX [find_g++]
     93 }
     94 if {![info exists CXXFLAGS]} {
     95     set CXXFLAGS ""
     96 }
     97 
     98 # The mips64-*-linux-gnu compiler defaults to the N32 ABI after
     99 # installed, but to the O32 ABI in the build tree, because of some
    100 # specs-file hacks.  Make sure we use an ABI that is compatible with
    101 # the one we expect.
    102 if {[istarget mips64*-*-linux*] &&
    103     (![board_info [target_info name] exists multilib_flags] ||
    104      ![string match "*-mabi" [board_info [target_info name] multilib_flags]])
    105    } {
    106     append gcc_B_opt " -mabi=n32"
    107 }
    108 
    109 if { [istarget rx-*-*] } {
    110     global ASFLAGS
    111     set ASFLAGS "-muse-conventional-section-names"
    112 }
    113 
    114 # load the utility procedures
    115 load_lib ld-lib.exp
    116 
    117 proc get_link_files {varname} {
    118     global $varname
    119     global target_triplet
    120     global srcdir
    121     global CC
    122     if ![info exists $varname] {
    123 	#configure.host returns variables that can be substituted into
    124 	#makefile rules, with embedded shell variable expansions.
    125 	#make wants $$shell_var, we want $shell_var ...
    126 	set cmd "host='$target_triplet' && . $srcdir/../configure.host && sed -e 's,\\\$\\\$,\$,g' <<EOF\n\$$varname\nEOF"
    127 	set status [catch "exec sh -c [list $cmd]" result]
    128 	if $status { error "Error getting native link files: $result" }
    129 	set cmd "CC='$CC' && eval echo \"$result\""
    130 	set status [catch "exec sh -c [list $cmd]" result]
    131 	if $status { error "Error getting native link files: $result" }
    132 	set $varname $result
    133 	send_log "$varname = $result\n"
    134     }
    135 }
    136 
    137 proc get_target_emul {} {
    138     global target_triplet
    139     global srcdir
    140     set status [catch "exec sh -c \"targ='$target_triplet' && . $srcdir/../configure.tgt && echo \\\$targ_emul\"" result]
    141     if $status { error "Error getting emulation name: $result" }
    142     return $result
    143 }
    144 
    145 if [isnative] {
    146     foreach x {HOSTING_CRT0 HOSTING_SCRT0 HOSTING_LIBS HOSTING_SLIBS} {
    147 	get_link_files $x
    148     }
    149 } else {
    150     foreach x {HOSTING_CRT0 HOSTING_SCRT0 HOSTING_LIBS HOSTING_SLIBS} { set $x "" }
    151 }
    152 if ![info exists HOSTING_EMU] { set HOSTING_EMU "-m [get_target_emul]" }
    153 
    154 #
    155 # ld_version -- extract and print the version number of ld compiler (GCC)
    156 #
    157 proc ld_version {} {
    158     global ld
    159     default_ld_version $ld
    160 }
    161 
    162 #
    163 # ld_exit -- just a stub for ld
    164 #
    165 proc ld_exit {} {
    166 }
    167 
    168 #
    169 # ld_start
    170 #	relink the linker
    171 #
    172 proc ld_start { ld target } {
    173 	#
    174 }
    175 
    176 #
    177 # ld_relocate
    178 #	link an object using relocation
    179 #
    180 proc ld_relocate { ld target objects } {
    181 	default_ld_relocate $ld $target $objects
    182 }
    183 
    184 #
    185 # ld_link
    186 #	link a program using ld
    187 #
    188 proc ld_link { ld target objects } {
    189 	default_ld_link $ld $target $objects
    190 }
    191 
    192 #
    193 # ld_simple_link
    194 #	link a program using ld, without including any libraries
    195 #
    196 proc ld_simple_link { ld target objects } {
    197 	default_ld_simple_link $ld $target $objects
    198 }
    199 
    200 #
    201 # ld_compile
    202 #	compile an object using $cc
    203 #
    204 proc ld_compile { cc source object } {
    205 	default_ld_compile $cc $source $object
    206 }
    207 
    208 #
    209 # ld_assemble
    210 #	assemble a file
    211 #
    212 proc ld_assemble { as source object } {
    213 	default_ld_assemble $as "" $source $object
    214 }
    215 
    216 #
    217 # ld_assemble_flags
    218 #	assemble a file with extra flags
    219 #
    220 proc ld_assemble_flags { as flags source object } {
    221 	default_ld_assemble $as $flags $source $object
    222 }
    223 
    224 #
    225 # ld_nm
    226 #	run nm on a file
    227 #
    228 proc ld_nm { nm nmflags object } {
    229 	default_ld_nm $nm $nmflags $object
    230 }
    231 
    232 #
    233 # ld_exec
    234 #	execute ithe target
    235 #
    236 proc ld_exec { target output } {
    237 	default_ld_exec $target $output
    238 }
    239 
    240 # From gas-defs.exp, to support run_dump_test.
    241 if ![info exists AS] then {
    242     set AS $as
    243 }
    244 
    245 if ![info exists ASFLAGS] then {
    246     set ASFLAGS ""
    247 }
    248 
    249 if ![info exists OBJDUMP] then {
    250     set OBJDUMP $objdump
    251 }
    252 
    253 if ![info exists OBJDUMPFLAGS] then {
    254     set OBJDUMPFLAGS {}
    255 }
    256 
    257 if ![info exists NM] then {
    258     set NM $nm
    259 }
    260 
    261 if ![info exists NMFLAGS] then {
    262     set NMFLAGS {}
    263 }
    264 
    265 if ![info exists OBJCOPY] then {
    266     set OBJCOPY $objcopy
    267 }
    268 
    269 if ![info exists OBJCOPYFLAGS] then {
    270     set OBJCOPYFLAGS {}
    271 }
    272 
    273 if ![info exists READELF] then {
    274     set READELF [findfile $base_dir/../binutils/readelf]
    275 }
    276 
    277 if ![info exists READELFFLAGS] then {
    278     set READELFFLAGS {}
    279 }
    280 
    281 if ![info exists LD] then {
    282     set LD [findfile $base_dir/ld-new ./ld-new [transform ld]]
    283 }
    284 
    285 if ![info exists LDFLAGS] then {
    286     set LDFLAGS {}
    287 }
    288 
    289 # Set PLT_CFLAGS to "-fplt" if target compiler supports it.
    290 
    291 if { ![info exists PLT_CFLAGS] } then {
    292     if { [which $CC] != 0 } {
    293 	# Check if gcc supports -fplt
    294 	set flags ""
    295 	if [board_info [target_info name] exists cflags] {
    296 	    append flags " [board_info [target_info name] cflags]"
    297 	}
    298 	if [board_info [target_info name] exists ldflags] {
    299 	    append flags " [board_info [target_info name] ldflags]"
    300 	}
    301 
    302 	set basename "tmpdir/plt[pid]"
    303 	set src ${basename}.c
    304 	set output ${basename}.o
    305 	set f [open $src "w"]
    306 	puts $f ""
    307 	close $f
    308 	if [is_remote host] {
    309 	    set src [remote_download host $src]
    310 	}
    311 	set plt_available [run_host_cmd_yesno "$CC" "$flags -c -fplt $src -o $output"]
    312 	remote_file host delete $src
    313 	remote_file host delete $output
    314 	file delete $src
    315 
    316 	if { $plt_available == 1 } then {
    317 	    set PLT_CFLAGS "-fplt"
    318 	} else {
    319 	    set PLT_CFLAGS ""
    320 	}
    321     } else {
    322 	set PLT_CFLAGS ""
    323     }
    324 }
    325 
    326 # Set NOPIE_CFLAGS to "-fno-PIE" and NOPIE_LDFLAGS to "-no-pie" if
    327 # target compiler supports them.
    328 
    329 if { ![info exists NOPIE_CFLAGS] || ![info exists NOPIE_LDFLAGS] } then {
    330     if { [which $CC] != 0 } {
    331 	# Check if gcc supports -fno-PIE -no-pie.
    332 	set flags ""
    333 	if [board_info [target_info name] exists cflags] {
    334 	    append flags " [board_info [target_info name] cflags]"
    335 	}
    336 	if [board_info [target_info name] exists ldflags] {
    337 	    append flags " [board_info [target_info name] ldflags]"
    338 	}
    339 
    340 	set basename "tmpdir/nopie[pid]"
    341 	set src ${basename}.c
    342 	set output ${basename}
    343 	set f [open $src "w"]
    344 	puts $f "int main (void) { return 0; }"
    345 	close $f
    346 	if [is_remote host] {
    347 	    set src [remote_download host $src]
    348 	}
    349 	set nopie_available [run_host_cmd_yesno "$CC" "$flags -fno-PIE -no-pie $src -o $output"]
    350 	remote_file host delete $src
    351 	remote_file host delete $output
    352 	file delete $src
    353 
    354 	if { $nopie_available == 1 } then {
    355 	    set NOPIE_CFLAGS "-fno-PIE"
    356 	    set NOPIE_LDFLAGS "-no-pie"
    357 	} else {
    358 	    set NOPIE_CFLAGS ""
    359 	    set NOPIE_LDFLAGS ""
    360 	}
    361     } else {
    362 	set NOPIE_CFLAGS ""
    363 	set NOPIE_LDFLAGS ""
    364     }
    365 }
    366