Home | History | Annotate | Download | only in ld-elf
      1 # Expect script for binutils tests
      2 # Copyright (C) 2006-2014 Free Software Foundation, Inc.
      3 #
      4 # This file is part of the GNU Binutils.
      5 #
      6 # This program 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 H.J. Lu (hongjiu.lu (at) intel.com)
     22 #
     23 
     24 # Make sure that binutils can correctly handle ld output in ELF.
     25 
     26 if { ![istarget *-*-linux*]
     27      && ![istarget *-*-nacl*]
     28      && ![istarget *-*-gnu*]} {
     29     return
     30 }
     31 
     32 if { [istarget *-*-linux*aout*]
     33      || [istarget *-*-linux*oldld*] } {
     34     return
     35 }
     36 
     37 # The optional test_name argument provides a mechanism for the caller
     38 # to hardwire the test name. This is important if ld_options contains
     39 # absolute path names because the default test name is constructed
     40 # from the prog_name and ld_options and we do not want absolute paths
     41 # to appear in the test_name.
     42 proc binutils_test { prog_name ld_options test {test_name ""}} {
     43     global as
     44     global ld
     45     global READELF
     46     global objcopy
     47     global strip
     48     global srcdir
     49     global subdir
     50     global link_output
     51 
     52     eval set prog \$$prog_name
     53 
     54     if { "$test_name" == "" } {
     55       set test_name "$prog_name $ld_options ($test)"
     56     }
     57 
     58     if { ![ld_assemble $as $srcdir/$subdir/$test.s tmpdir/$test.o ] } {
     59 	unresolved "$test_name"
     60 	return
     61     }
     62 
     63     if { ![ld_simple_link $ld tmpdir/$test "$ld_options -z stack-size=0 tmpdir/$test.o"] } {
     64 	if { [string match "*not supported*" $link_output]
     65 	     || [string match "*unrecognized option*" $link_output]
     66 	     || [string match "*-z relro ignored*" $link_output] } {
     67 	    unsupported "$ld_options is not supported by this target"
     68 	} else {
     69 	    unresolved "$test_name"
     70 	}
     71 	return
     72     }
     73 
     74     send_log "$READELF -l --wide tmpdir/$test > tmpdir/$test.exp\n"
     75     set got [remote_exec host "$READELF -l --wide tmpdir/$test" "" "/dev/null" "tmpdir/$test.exp"]
     76     if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
     77 	send_log "$got\n"
     78 	unresolved "$test_name"
     79 	return
     80     }
     81 
     82     if [string match "*-z relro*" $ld_options] {
     83 	# Check if GNU_RELRO segment is generated.
     84 	set got [remote_exec host "grep GNU_RELRO tmpdir/$test.exp"]
     85 	if { ![string match "*GNU_RELRO*" $got] } then {
     86 	    set got [remote_exec host "cat tmpdir/$test.exp"]
     87 	    if { [string match "*.data.rel.ro*" $got]
     88 		 || [string match "*.dynamic*" $got]
     89 		 || [string match "*.got*" $got]
     90 		 || [string match "*.eh_frame*" $got]
     91 		 || [string match "*.gcc_except_table*" $got]
     92 		 || [string match "*.exception_ranges*" $got]
     93 		 || [string match "*.ctors*" $got]
     94 		 || [string match "*.dtors*" $got]
     95 		 || [string match "*.tdata*" $got]
     96 		 || [string match "*.preinit_array*" $got]
     97 		 || [string match "*.init_array*" $got]
     98 		 || [string match "*.fini_array*" $got] } then {
     99 		# Fail if GNU_RELRO segment isn't generated, but should.
    100 		fail "$test_name"
    101 		return
    102 	    }
    103 	}
    104     }
    105 
    106     send_log "$prog tmpdir/$test\n"
    107     set got [remote_exec host "$prog tmpdir/$test"]
    108     if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
    109 	send_log "$got\n"
    110 	fail "$test_name"
    111 	return
    112     }
    113 
    114     send_log "$READELF -l --wide tmpdir/$test > tmpdir/$test.out\n"
    115     set got [remote_exec host "$READELF -l --wide tmpdir/$test" "" "/dev/null" "tmpdir/$test.out"]
    116     if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
    117 	send_log "$got\n"
    118 	unresolved "$test_name"
    119 	return
    120     }
    121 
    122     if { [catch {exec cmp tmpdir/$test.exp tmpdir/$test.out}] } then {
    123 	send_log "tmpdir/$test.exp tmpdir/$test.out differ.\n"
    124 	fail "$test_name"
    125 	return
    126     }
    127 
    128     pass "$test_name"
    129 }
    130 
    131 binutils_test strip "-z max-page-size=0x200000" maxpage1
    132 binutils_test strip "-z max-page-size=0x200000 -z common-page-size=0x100000" maxpage1
    133 binutils_test strip "-z max-page-size=0x100000" maxpage1
    134 binutils_test strip "-z max-page-size=0x100000 -z common-page-size=0x1000" maxpage1
    135 
    136 binutils_test strip "" maxpage1
    137 binutils_test strip "-shared" maxpage1
    138 binutils_test objcopy "" maxpage1
    139 binutils_test objcopy "-shared" maxpage1
    140 
    141 binutils_test strip "-z relro" relro1
    142 binutils_test strip "-z relro -shared" relro1
    143 binutils_test objcopy "-z relro" relro1
    144 binutils_test objcopy "-z relro -shared" relro1
    145 if { ([istarget "i?86-*-elf*"]
    146       || (([istarget "i?86-*-linux*"]
    147 	   || [istarget "i?86-*-gnu*"])
    148 	  && ![istarget "*-*-*aout*"]
    149 	  && ![istarget "*-*-*oldld*"])
    150       || [istarget "x86_64-*-linux*"]
    151       || [istarget "amd64-*-linux*"]
    152       || [istarget "i?86-*nacl*"]
    153       || [istarget "x86_64-*nacl*"]) } {
    154     binutils_test strip "-z relro -shared" relro2
    155     binutils_test objcopy "-z relro -shared" relro2
    156 }
    157 
    158 binutils_test strip "-T ${srcdir}/${subdir}/lma.lnk" lma "strip -T lma.lnk"
    159 
    160 set tls_tests { "tdata1" "tdata2" }
    161 # hppa64 has its own .tbss section, with different flags.
    162 if { ![istarget "hppa64-*-*"] } {
    163     lappend tls_tests "tdata3" "tbss1" "tbss2" "tbss3"
    164 }
    165 set tls_opts {
    166     ""
    167     "-z relro"
    168     "-shared"
    169     "-shared -z relro"
    170     "-z max-page-size=0x100000"
    171     "-z max-page-size=0x100000 -z common-page-size=0x1000"
    172 }
    173 
    174 foreach testitem $tls_tests {
    175     foreach testopt $tls_opts {
    176 	binutils_test objcopy $testopt $testitem
    177     }
    178 }
    179