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