1 # Expect script for tests for >64k sections 2 # Copyright (C) 2002-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 Hans-Peter Nilsson (hp (at) axis.com) 22 # 23 24 # Exclude non-ELF targets. 25 26 if ![is_elf_format] { 27 return 28 } 29 30 # Targets using the generic linker backend don't sort section symbols 31 # before local symbols, so don't bother testing them. 32 if { [istarget "arc-*-*"] 33 || [istarget "d30v-*-*"] 34 || [istarget "dlx-*-*"] 35 || [istarget "i960-*-*"] 36 || [istarget "msp430*-*-*"] 37 || [istarget "or1k*-*-*"] 38 || [istarget "pj*-*-*"] 39 || [istarget "m32r-*-*"] } { 40 return 41 } 42 43 # Test >64k sections, with and without -r. First, create the assembly 44 # files. Have a relocation to another section and one within the local 45 # section. 46 47 set test1 "64ksec-r" 48 set test2 "64ksec" 49 50 if { ![runtest_file_p $runtests $test1] \ 51 && ![runtest_file_p $runtests $test2] } { 52 return 53 } 54 55 set sfiles {} 56 set max_sec 66000 57 set secs_per_file 1000 58 for { set i 0 } { $i < $max_sec / $secs_per_file } { incr i } { 59 set sfile "$objdir/tmpdir/sec64-$i.s" 60 lappend sfiles $sfile 61 if [catch { set ofd [open $sfile w] } x] { 62 perror "$x" 63 unresolved $test1 64 unresolved $test2 65 return 66 } 67 68 if { $i == 0 } { 69 puts $ofd " .global start" 70 puts $ofd "start:" 71 puts $ofd " .global _start" 72 puts $ofd "_start:" 73 puts $ofd " .global __start" 74 puts $ofd "__start:" 75 puts $ofd " .global main" 76 puts $ofd "main:" 77 puts $ofd " .global foo_0" 78 puts $ofd "foo_0: .dc.a 0" 79 } 80 81 # Make sure the used section is not covered by common linker scripts. 82 # They should get separate section entries even without -r. 83 puts $ofd " .altmacro" 84 puts $ofd " .macro sec secn, secp" 85 if {![istarget "frv-*-*linux*"]} then { 86 puts $ofd " .section .foo.\\secn,\"ax\"" 87 } else { 88 puts $ofd " .section .foo.\\secn,\"aw\"" 89 } 90 puts $ofd " .global foo_\\secn" 91 puts $ofd "foo_\\secn:" 92 puts $ofd " .dc.a foo_\\secp" 93 puts $ofd "bar_\\secn:" 94 puts $ofd " .dc.a bar_\\secn" 95 puts $ofd " .endm" 96 if {![istarget "bfin-*-*"]} then { 97 puts $ofd " secn = [expr $i * $secs_per_file]" 98 } else { 99 puts $ofd " .set secn, [expr $i * $secs_per_file]" 100 } 101 puts $ofd " .rept $secs_per_file" 102 if {![istarget "bfin-*-*"]} then { 103 puts $ofd " secn = secn + 1" 104 } else { 105 puts $ofd " .set secn, secn + 1" 106 } 107 puts $ofd " sec %(secn), %(secn-1)" 108 puts $ofd " .endr" 109 110 close $ofd 111 } 112 113 if [catch { set ofd [open "tmpdir/$test1.d" w] } x] { 114 perror "$x" 115 unresolved $test1 116 unresolved $test2 117 return 118 } 119 120 # The ld-r linked file will contain relocation-sections too, so make it 121 # half the size in order to try and keep the test-time down. 122 123 # The m32r target generates both REL and RELA relocs (for historical 124 # reasons) so the expected number of sections will be much more than 125 # 68000, which throws this particular test right off. 126 if { ![istarget "m32r-*-*"] } then { 127 foreach sfile [lrange $sfiles 0 [expr [llength $sfiles] / 2]] { 128 puts $ofd "#source: $sfile" 129 } 130 puts $ofd "#ld: -r" 131 puts $ofd "#readelf: -W -Ss" 132 puts $ofd "There are 680.. section headers.*:" 133 puts $ofd "#..." 134 puts $ofd " \\\[ 0\\\] .* 680\[0-9\]\[0-9\]\[ \]+0\[ \]+0" 135 puts $ofd "#..." 136 puts $ofd " \\\[ \[0-9\]\\\] \.foo\.1\[ \]+PROGBITS\[ \]+.*" 137 puts $ofd "#..." 138 puts $ofd " \\\[65279\\\] (.rel\[a\]?)?\\.foo\\.\[0-9\]+ .*" 139 puts $ofd " \\\[65280\\\] (.rel\[a\]?)?\\.foo\\.\[0-9\]+ .*" 140 puts $ofd "#..." 141 puts $ofd " 340..: 0+\[ \]+0\[ \]+SECTION\[ \]+LOCAL\[ \]+DEFAULT\[ \]+68... " 142 puts $ofd "#..." 143 puts $ofd " 340..: 0+(2|4|8)\[ \]+0\[ \]+NOTYPE\[ \]+LOCAL\[ \]+DEFAULT\[ \]+\[2-5\] bar_1$" 144 puts $ofd "#..." 145 puts $ofd ".* bar_34000$" 146 puts $ofd "#..." 147 # Global symbols are not in "alphanumeric" order, so we just check 148 # that the first and the last are present in any order (assuming no 149 # duplicates). 150 puts $ofd ".* (\[0-9\] foo_1|68... foo_34000)$" 151 puts $ofd "#..." 152 puts $ofd ".* (\[0-9\] foo_1|68... foo_34000)$" 153 puts $ofd "#pass" 154 close $ofd 155 run_dump_test "tmpdir/$test1" 156 } 157 158 if [catch { set ofd [open "tmpdir/$test2.d" w] } x] { 159 perror "$x" 160 unresolved $test2 161 return 162 } 163 164 # too big for d10v and msp 165 # lack of fancy orphan section handling causes overlap on fr30 and iq2000 166 if { ![istarget "d10v-*-*"] 167 && ![istarget "msp*-*-*"] 168 && ![istarget "fr30-*-*"] 169 && ![istarget "iq2000-*-*"] } { 170 foreach sfile $sfiles { puts $ofd "#source: $sfile" } 171 if { [istarget "avr-*-*"] } then { 172 puts $ofd "#as: -mmcu=avr6" 173 puts $ofd "#ld: -mavr6" 174 } elseif { [istarget spu*-*-*] } { 175 puts $ofd "#ld: --local-store 0:0" 176 } else { 177 puts $ofd "#ld:" 178 } 179 puts $ofd "#readelf: -W -Ss" 180 puts $ofd "There are 660.. section headers.*:" 181 puts $ofd "#..." 182 puts $ofd " \\\[ 0\\\] .* 660..\[ \]+0\[ \]+0" 183 puts $ofd "#..." 184 puts $ofd " \\\[65279\\\] \\.foo\\.\[0-9\]+ .*" 185 puts $ofd " \\\[65280\\\] \\.foo\\.\[0-9\]+ .*" 186 puts $ofd "#..." 187 puts $ofd " 660..: \[0-9a-f\]+\[ \]+0\[ \]+SECTION\[ \]+LOCAL\[ \]+DEFAULT\[ \]+660.. " 188 puts $ofd "#..." 189 puts $ofd " 660..: \[0-9a-f\]+\[ \]+0\[ \]+NOTYPE\[ \]+LOCAL\[ \]+DEFAULT\[ \]+\[0-9\] bar_1$" 190 puts $ofd "#..." 191 puts $ofd ".* bar_66000$" 192 puts $ofd "#..." 193 # Global symbols are not in "alphanumeric" order, so we just check 194 # that the first and the last are present in any order (assuming no 195 # duplicates). 196 puts $ofd ".* (\[0-9\] foo_1|66... foo_66000)$" 197 puts $ofd "#..." 198 puts $ofd ".* (\[0-9\] foo_1|66... foo_66000)$" 199 puts $ofd "#pass" 200 close $ofd 201 run_dump_test "tmpdir/$test2" 202 } 203 204 for { set i 1 } { $i < $max_sec / $secs_per_file } { incr i } { 205 catch "exec rm -f tmpdir/dump$i.o" status 206 } 207