Commit | Line | Data |
---|---|---|
252b5132 RH |
1 | # Test basic linker script functionality |
2 | # By Ian Lance Taylor, Cygnus Support | |
b90efa5b | 3 | # Copyright (C) 1999-2015 Free Software Foundation, Inc. |
a2b64bed | 4 | # |
f96b4a7b NC |
5 | # This file is part of the GNU Binutils. |
6 | # | |
7 | # This program is free software; you can redistribute it and/or modify | |
a2b64bed | 8 | # it under the terms of the GNU General Public License as published by |
f96b4a7b | 9 | # the Free Software Foundation; either version 3 of the License, or |
a2b64bed | 10 | # (at your option) any later version. |
f96b4a7b | 11 | # |
a2b64bed NC |
12 | # This program is distributed in the hope that it will be useful, |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | # GNU General Public License for more details. | |
f96b4a7b | 16 | # |
a2b64bed NC |
17 | # You should have received a copy of the GNU General Public License |
18 | # along with this program; if not, write to the Free Software | |
f96b4a7b NC |
19 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
20 | # MA 02110-1301, USA. | |
252b5132 RH |
21 | |
22 | set testname "script" | |
23 | ||
24 | if ![ld_assemble $as $srcdir/$subdir/script.s tmpdir/script.o] { | |
25 | unresolved $testname | |
26 | return | |
27 | } | |
28 | ||
29 | proc check_script { } { | |
30 | global nm | |
31 | global testname | |
32 | global nm_output | |
33 | ||
992c450d | 34 | if ![ld_nm $nm "" tmpdir/script] { |
252b5132 | 35 | unresolved $testname |
3ec57632 NC |
36 | return |
37 | } | |
38 | ||
39 | if {![info exists nm_output(text_start)] \ | |
40 | || ![info exists nm_output(text_end)] \ | |
41 | || ![info exists nm_output(data_start)] \ | |
42 | || ![info exists nm_output(data_end)]} { | |
43 | send_log "bad output from nm\n" | |
44 | verbose "bad output from nm" | |
45 | fail $testname | |
46 | return | |
47 | } | |
48 | ||
49 | set passes 1 | |
50 | set text_end 0x104 | |
51 | set data_end 0x1004 | |
52 | ||
53 | if [istarget *c4x*-*-*] then { | |
54 | set text_end 0x101 | |
55 | set data_end 0x1001 | |
56 | } | |
57 | ||
58 | if [istarget *c54x*-*-*] then { | |
59 | set text_end 0x102 | |
60 | set data_end 0x1002 | |
61 | } | |
62 | ||
63 | if {$nm_output(text_start) != 0x100} { | |
64 | send_log "text_start == $nm_output(text_start)\n" | |
65 | verbose "text_start == $nm_output(text_start)" | |
66 | set passes 0 | |
67 | } | |
68 | ||
cc9ad334 SKS |
69 | if {[info exists nm_output(tred)] \ |
70 | && $nm_output(tred) != (0x100 + 0x8000)} { | |
71 | send_log "tred == $nm_output(tred)\n" | |
72 | verbose "tred == $nm_output(tred)" | |
73 | set passes 0 | |
74 | } | |
75 | ||
3ec57632 NC |
76 | if {$nm_output(text_end) < $text_end \ |
77 | || $nm_output(text_end) > 0x110} { | |
78 | send_log "text_end == $nm_output(text_end)\n" | |
79 | verbose "text_end == $nm_output(text_end)" | |
80 | set passes 0 | |
81 | } | |
82 | ||
83 | if {$nm_output(data_start) != 0x1000} { | |
84 | send_log "data_start == $nm_output(data_start)\n" | |
85 | verbose "data_start == $nm_output(data_start)" | |
86 | set passes 0 | |
87 | } | |
88 | ||
cc9ad334 SKS |
89 | if {[info exists nm_output(fred)] \ |
90 | && $nm_output(fred) != (0x1000 + 0x10000)} { | |
91 | send_log "fred == $nm_output(fred)\n" | |
92 | verbose "fred == $nm_output(fred)" | |
93 | set passes 0 | |
94 | } | |
95 | ||
3ec57632 NC |
96 | if {$nm_output(data_end) < $data_end \ |
97 | || $nm_output(data_end) > 0x1010} { | |
98 | send_log "data_end == $nm_output(data_end)\n" | |
99 | verbose "data_end == $nm_output(data_end)" | |
100 | set passes 0 | |
101 | } | |
102 | ||
103 | if { $passes } { | |
104 | pass $testname | |
252b5132 | 105 | } else { |
3ec57632 | 106 | fail $testname |
252b5132 RH |
107 | } |
108 | } | |
109 | ||
7b19bec2 AM |
110 | proc extract_symbol_test { testfile testname } { |
111 | global objcopy | |
112 | global nm | |
113 | global size | |
114 | ||
115 | set copyfile tmpdir/extract | |
116 | set args "--extract-symbol $testfile $copyfile" | |
117 | set exec_output [run_host_cmd $objcopy $args] | |
118 | if ![string equal "" $exec_output] { | |
119 | fail $testname | |
120 | return | |
121 | } | |
122 | ||
123 | set orig_syms [run_host_cmd $nm $testfile] | |
124 | set extract_syms [run_host_cmd $nm $copyfile] | |
125 | if ![string equal $orig_syms $extract_syms] { | |
126 | fail $testname | |
127 | return | |
128 | } | |
129 | ||
130 | set exec_output [run_host_cmd $size $copyfile] | |
131 | if ![regexp ".* 0\[ \]+0\[ \]+0\[ \]+0\[ \]+0\[ \]+.*" $exec_output] { | |
132 | fail $testname | |
133 | return | |
134 | } | |
135 | ||
136 | pass $testname | |
137 | } | |
138 | ||
777690b6 ILT |
139 | # PE targets need to set the image base to 0 to avoid complications from nm. |
140 | set flags "" | |
141 | if {[istarget "*-*-pe*"] \ | |
142 | || [istarget "*-*-cygwin*"] \ | |
99ad8390 | 143 | || [istarget "*-*-mingw*"] \ |
777690b6 | 144 | || [istarget "*-*-winnt*"] \ |
3ec57632 | 145 | || [istarget "*-*-nt"] \ |
777690b6 ILT |
146 | || [istarget "*-*-interix*"] } then { |
147 | set flags "--image-base 0" | |
148 | } | |
149 | ||
150 | if ![ld_simple_link $ld tmpdir/script "$flags -T $srcdir/$subdir/script.t tmpdir/script.o"] { | |
252b5132 RH |
151 | fail $testname |
152 | } else { | |
153 | check_script | |
154 | } | |
155 | ||
156 | set testname "MRI script" | |
157 | ||
777690b6 | 158 | if ![ld_simple_link $ld tmpdir/script "$flags -c $srcdir/$subdir/scriptm.t"] { |
252b5132 RH |
159 | fail $testname |
160 | } else { | |
161 | check_script | |
162 | } | |
3ec57632 NC |
163 | |
164 | set testname "MEMORY" | |
165 | ||
166 | if ![ld_simple_link $ld tmpdir/script "$flags -T $srcdir/$subdir/memory.t tmpdir/script.o"] { | |
167 | fail $testname | |
168 | } else { | |
169 | check_script | |
170 | } | |
4a93e180 | 171 | |
cc9ad334 SKS |
172 | set testname "MEMORY with symbols" |
173 | if ![ld_simple_link $ld tmpdir/script "$flags -defsym DATA_ORIGIN=0x1000 -defsym DATA_LENGTH=0x10000 -T $srcdir/$subdir/memory_sym.t tmpdir/script.o"] { | |
174 | fail $testname | |
7b19bec2 | 175 | untested "extract symbols" |
cc9ad334 SKS |
176 | } else { |
177 | check_script | |
7b19bec2 | 178 | extract_symbol_test tmpdir/script "extract symbols" |
cc9ad334 SKS |
179 | } |
180 | ||
4287f8de | 181 | set test_script_list [lsort [glob $srcdir/$subdir/region-alias-*.t]] |
4a93e180 NC |
182 | |
183 | foreach test_script $test_script_list { | |
9933d191 | 184 | run_dump_test [string range $test_script 0 end-2] |
4a93e180 | 185 | } |
1eec346e | 186 | |
9933d191 | 187 | run_dump_test "align-with-input" |