ld/
[platform/upstream/binutils.git] / ld / testsuite / ld-elf / sec64k.exp
1 # Expect script for tests for >64k sections
2 #   Copyright 2002, 2003 Free Software Foundation, Inc.
3 #
4 # This file is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
17 #
18 # Written by Hans-Peter Nilsson (hp@axis.com)
19 #
20
21 # Exclude non-ELF targets.
22
23 if ![is_elf_format] {
24     return
25 }
26
27 # Test >64k sections, with and without -r.  First, create the assembly
28 # files.  Have a relocation to another section and one within the local
29 # section.
30
31 set test1 "64ksec-r"
32 set test2 "64ksec"
33
34 if { ![runtest_file_p $runtests $test1] \
35         && ![runtest_file_p $runtests $test2] } {
36     return
37 }
38
39 set sfiles {}
40 set max_sec 66000
41 set secs_per_file 1000
42 set secn 0
43 for { set i 0 } { $i < $max_sec / $secs_per_file } { incr i } {
44     set sfile "$objdir/tmpdir/sec64-$i.s"
45     lappend sfiles $sfile
46     if [catch { set ofd [open $sfile w] } x] {
47         perror "$x"
48         unresolved $test1
49         unresolved $test2
50         return
51     }
52
53     if { $secn == 0 } {
54         puts $ofd " .global _start"
55         puts $ofd "_start:"
56         puts $ofd " .global foo_0"
57         puts $ofd "foo_0: .long 0"
58     }
59
60     # Make sure the used section is not covered by common linker scripts.
61     # They should get separate section entries even without -r.
62     for { set j 0 } { $j < $secs_per_file } { incr j } {
63         incr secn
64         puts $ofd " .section .foo.$secn,\"ax\""
65         puts $ofd " .global foo_$secn"
66         puts $ofd "foo_$secn:"
67         puts $ofd " .long foo_[expr $secn - 1]"
68         puts $ofd "bar_$secn:"
69         puts $ofd " .long bar_$secn"
70     }
71
72     close $ofd
73 }
74
75 if [catch { set ofd [open "tmpdir/$test1.d" w] } x] {
76     perror "$x"
77     unresolved $test1
78     unresolved $test2
79     return
80 }
81
82 # The ld-r linked file will contain relocation-sections too, so make it
83 # half the size in order to try and keep the test-time down.
84 foreach sfile [lrange $sfiles 0 [expr [llength $sfiles] / 2]] {
85     puts $ofd "#source: $sfile"
86 }
87 puts $ofd "#ld: -r"
88 puts $ofd "#readelf: -W -Ss"
89 puts $ofd "There are 680.. section headers.*:"
90 puts $ofd "#..."
91 puts $ofd "  \\\[ 0\\\] .* 682\[0-9\]\[0-9\]\[ \]+0\[ \]+0"
92 puts $ofd "#..."
93 puts $ofd "  \\\[ \[0-9\]\\\] \.foo\.1\[ \]+PROGBITS\[ \]+.*"
94 puts $ofd "#..."
95 puts $ofd "  \\\[65279\\\] (.rel\[a\]?)?\\.foo\\.\[0-9\]+ .*"
96 puts $ofd "  \\\[65536\\\] (.rel\[a\]?)?\\.foo\\.\[0-9\]+ .*"
97 puts $ofd "#..."
98 puts $ofd " 680..: 0+\[ \]+0\[ \]+SECTION\[ \]+LOCAL\[ \]+DEFAULT\[ \]+68... "
99 puts $ofd "#..."
100 puts $ofd " 680..: 0+4\[ \]+0\[ \]+NOTYPE\[ \]+LOCAL\[ \]+DEFAULT\[ \]+2 bar_1"
101 puts $ofd "#..."
102 puts $ofd ".* bar_34000"
103 puts $ofd "#..."
104 # Global symbols are not in "alphanumeric" order, so we just check
105 # that the first and the last are present in any order (assuming no
106 # duplicates).
107 puts $ofd ".* (\[0-9\] foo_1|68... foo_34000)"
108 puts $ofd "#..."
109 puts $ofd ".* (\[0-9\] foo_1|68... foo_34000)"
110 puts $ofd "#pass"
111 close $ofd
112 run_dump_test "tmpdir/$test1"
113
114 if [catch { set ofd [open "tmpdir/$test2.d" w] } x] {
115     perror "$x"
116     unresolved $test2
117     return
118 }
119 foreach sfile $sfiles { puts $ofd "#source: $sfile" }
120 puts $ofd "#ld:"
121 puts $ofd "#readelf: -W -Ss"
122 puts $ofd "There are 660.. section headers.*:"
123 puts $ofd "#..."
124 puts $ofd "  \\\[ 0\\\] .* 662..\[ \]+0\[ \]+0"
125 puts $ofd "#..."
126 puts $ofd "  \\\[65279\\\] \\.foo\\.\[0-9\]+ .*"
127 puts $ofd "  \\\[65536\\\] \\.foo\\.\[0-9\]+ .*"
128 puts $ofd "#..."
129 puts $ofd " 660..: 0+\[ \]+0\[ \]+SECTION\[ \]+LOCAL\[ \]+DEFAULT\[ \]+662.. "
130 puts $ofd "#..."
131 puts $ofd " 660..: \[0-9a-f\]+\[ \]+0\[ \]+NOTYPE\[ \]+LOCAL\[ \]+DEFAULT\[ \]+\[0-9\] bar_1"
132 puts $ofd "#..."
133 puts $ofd ".* bar_66000"
134 puts $ofd "#..."
135 # Global symbols are not in "alphanumeric" order, so we just check
136 # that the first and the last are present in any order (assuming no
137 # duplicates).
138 puts $ofd ".* (\[0-9\] foo_1|66... foo_66000)"
139 puts $ofd "#..."
140 puts $ofd ".* (\[0-9\] foo_1|66... foo_66000)"
141 puts $ofd "#pass"
142 close $ofd
143 run_dump_test "tmpdir/$test2"