Commit | Line | Data |
---|---|---|
09250cfe ILT |
1 | # Copyright (C) 1994 Free Software Foundation, Inc. |
2 | ||
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
5 | # the Free Software Foundation; either version 2 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
8 | # This program is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with this program; if not, write to the Free Software | |
15 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
16 | ||
17 | # Please email any bugs, comments, and/or additions to this file to: | |
18 | # bug-dejagnu@prep.ai.mit.edu | |
19 | ||
20 | # Written by Ian Lance Taylor <ian@cygnus.com> | |
21 | ||
22 | if {[which $OBJCOPY] == 0} then { | |
23 | perror "$OBJCOPY does not exist" | |
24 | return | |
25 | } | |
26 | ||
27 | send_user "Version [binutil_version $OBJCOPY]" | |
28 | ||
6273f92d | 29 | |
09250cfe ILT |
30 | if {![binutils_assemble $AS $srcdir$subdir/bintest.s tmpdir/bintest.o]} then { |
31 | return | |
32 | } | |
33 | ||
34 | # Test that objcopy does not modify a file when copying it. | |
35 | ||
36 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o"] | |
37 | ||
38 | if ![string match "" $got] then { | |
39 | fail "objcopy (simple copy)" | |
40 | } else { | |
41 | send_log "cmp tmpdir/bintest.o tmpdir/copy.o\n" | |
42 | verbose "cmp tmpdir/bintest.o tmpdir/copy.o" | |
43 | catch "exec cmp tmpdir/bintest.o tmpdir/copy.o" exec_output | |
44 | ||
45 | # On some systems the result of objcopy will not be identical. | |
8b550686 ILT |
46 | # Usually this is just because gas isn't using bfd to write the files |
47 | # in the first place, and may order things a little differently. | |
09250cfe ILT |
48 | # Those systems should use setup_xfail here. |
49 | ||
8b550686 ILT |
50 | setup_xfail "sh-*-coff" "sh-*-hms" |
51 | setup_xfail "m68*-*-hpux*" "m68*-*-sunos*" "m68*-*-coff" "m68*-*-vxworks*" | |
2e246dbd | 52 | setup_xfail "m68*-ericsson-ose" |
8b550686 ILT |
53 | setup_xfail "i*86-*-linux" |
54 | setup_xfail "a29k-*-udi" "a29k-*-coff" | |
55 | setup_xfail "i960-*-vxworks5.1" "i960-*-coff" | |
56 | setup_xfail "h8300-*-hms" "h8300-*-coff" | |
57 | setup_xfail "hppa*-*-*" | |
2e246dbd | 58 | setup_xfail "m88*-*-coff" |
6273f92d | 59 | |
09250cfe ILT |
60 | if [string match "" $exec_output] then { |
61 | pass "objcopy (simple copy)" | |
62 | } else { | |
63 | send_log "$exec_output\n" | |
64 | verbose "$exec_output" 1 | |
65 | ||
66 | fail "objcopy (simple copy)" | |
67 | } | |
68 | } | |
69 | ||
70 | # Test generating S records. | |
71 | ||
72 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec"] | |
73 | ||
74 | if ![string match "" $got] then { | |
75 | fail "objcopy -O srec" | |
76 | } else { | |
77 | set file [open tmpdir/copy.srec r] | |
78 | ||
79 | # The first S record is fixed by the file name we are using. | |
80 | gets $file line | |
81 | send_log "$line\n" | |
82 | verbose $line | |
83 | if ![string match $line "S0130000746D706469722F636F70792E7372656397\r"] { | |
84 | fail "objcopy -O srec (bad header)" | |
85 | } else { | |
86 | while {[gets $file line] != -1 \ | |
87 | && [regexp "^S\[123\]\[0-9a-fA-F\]+\r$" $line]} { | |
88 | send_log "$line\n" | |
89 | verbose $line | |
90 | set line "**EOF**" | |
91 | } | |
92 | send_log "$line\n" | |
93 | verbose $line | |
94 | if ![regexp "^S\[789\]\[0-9a-fA-F\]+\r$" $line] then { | |
95 | fail "objcopy -O srec (bad trailer)" | |
96 | } else { | |
97 | if {[gets $file line] != -1} then { | |
98 | send_log "$line\n" | |
99 | verbose $line | |
100 | fail "objcopy -O srec (garbage at end)" | |
101 | } else { | |
102 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/copy.srec"] | |
103 | if ![regexp "file format srec" $got] then { | |
104 | fail "objcopy -O srec (objdump failed)" | |
105 | } else { | |
106 | pass "objcopy -O srec" | |
107 | } | |
108 | } | |
109 | } | |
110 | } | |
111 | ||
112 | close $file | |
113 | } | |
114 | ||
115 | # Test setting and adjusting the start address. We only test this | |
116 | # while generating S records, because we may not be able to set the | |
117 | # start address for other object file formats, and the S record case | |
118 | # is the only useful one anyhow. | |
119 | ||
120 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/bintest.o"] | |
121 | if ![regexp "start address (\[0-9a-fA-FxX\]+)" $got all origstart] then { | |
122 | perror "objdump can not recognize bintest.o" | |
123 | set origstart "" | |
124 | } else { | |
125 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec --set-start 0x7654"] | |
126 | if ![string match "" $got] then { | |
127 | fail "objcopy --set-start" | |
128 | } else { | |
129 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/copy.srec"] | |
130 | if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then { | |
131 | fail "objcopy --set-start" | |
132 | } else { | |
133 | if {$srecstart != 0x7654} then { | |
134 | fail "objcopy --set-start ($srecstart != 0x7654)" | |
135 | } else { | |
136 | pass "objcopy --set-start" | |
137 | } | |
138 | } | |
139 | } | |
140 | ||
141 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec --adjust-start 0x123"] | |
142 | if ![string match "" $got] then { | |
143 | fail "objcopy --adjust-start" | |
144 | } else { | |
145 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/copy.srec"] | |
146 | if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then { | |
147 | fail "objcopy --adjust-start" | |
148 | } else { | |
149 | if {$srecstart != $origstart + 0x123} then { | |
150 | fail "objcopy --adjust-start ($srecstart != $origstart + 0x123)" | |
151 | } else { | |
152 | pass "objcopy --adjust-start" | |
153 | } | |
154 | } | |
155 | } | |
156 | } | |
157 | ||
158 | # Test adjusting the overall VMA, and adjusting the VMA of a | |
159 | # particular section. We again only test this when # generating S | |
160 | # records. | |
161 | ||
162 | set low "" | |
163 | set lowname "" | |
164 | ||
165 | set headers [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h tmpdir/bintest.o"] | |
166 | ||
167 | set headers_regexp "SECTION\[ 0-9\]+\\\[(\[^\]\]*)\\\]\[^\n\r\]*size\[ \]*(\[0-9a-fA-F\]+)\[ \]*vma\[ \]*(\[0-9a-fA-F\]+)(.*)" | |
168 | ||
169 | set got $headers | |
170 | while {[regexp $headers_regexp $got all name size vma rest]} { | |
171 | set vma 0x$vma | |
172 | if {$low == "" || $vma < $low} then { | |
173 | set low $vma | |
174 | set lowname $name | |
175 | } | |
176 | set got $rest | |
177 | } | |
178 | ||
179 | if {$low == "" || $origstart == ""} then { | |
180 | perror "objdump can not recognize bintest.o" | |
181 | } else { | |
182 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec --adjust-vma 0x123"] | |
183 | if ![string match "" $got] then { | |
184 | fail "objcopy --adjust-vma" | |
185 | } else { | |
186 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -fh tmpdir/copy.srec"] | |
187 | set want "file format srec.*start address\[ \]*(\[0-9a-fA-FxX\]+).*vma\[ \]*(\[0-9a-fA-F\]+)" | |
188 | if ![regexp $want $got all start vma] then { | |
189 | fail "objcopy --adjust-vma" | |
190 | } else { | |
191 | set vma 0x$vma | |
192 | if {$vma != $low + 0x123} then { | |
193 | fail "objcopy --adjust-vma ($vma != $low + 0x123)" | |
194 | } else { | |
195 | if {$start != $origstart + 0x123} then { | |
196 | fail "objcopy --adjust-vma ($start != $origstart + 0x123)" | |
197 | } else { | |
198 | pass "objcopy --adjust-vma" | |
199 | } | |
200 | } | |
201 | } | |
202 | } | |
203 | ||
204 | set arg "" | |
205 | set got $headers | |
206 | while {[regexp $headers_regexp $got all name size vma rest]} { | |
207 | set vma 0x$vma | |
208 | if {$vma == $low} then { | |
209 | set arg "$arg --adjust-section-vma $name+4" | |
210 | } | |
211 | set got $rest | |
212 | } | |
213 | ||
214 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec $arg"] | |
215 | if ![string match "" $got] then { | |
216 | fail "objcopy --adjust-section-vma +" | |
217 | } else { | |
218 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h tmpdir/copy.srec"] | |
ef1ad8ab | 219 | set want "file format srec.*SECTION\[ \]*0\[^\n\r\]*vma\[ \]*(\[0-9a-fA-F\]+)" |
09250cfe ILT |
220 | if ![regexp $want $got all vma] then { |
221 | fail "objcopy --adjust-section-vma +" | |
222 | } else { | |
223 | set vma 0x$vma | |
224 | if {$vma != $low + 4} then { | |
225 | fail "objcopy --adjust-section-vma + ($vma != $low + 4)" | |
226 | } else { | |
227 | pass "objcopy --adjust-section-vma +" | |
228 | } | |
229 | } | |
230 | } | |
231 | ||
232 | regsub -all "\\+4" $arg "=[expr $low + 4]" argeq | |
233 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec $argeq"] | |
234 | if ![string match "" $got] then { | |
235 | fail "objcopy --adjust-section-vma =" | |
236 | } else { | |
237 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h tmpdir/copy.srec"] | |
ef1ad8ab | 238 | set want "file format srec.*SECTION\[ \]*0\[^\n\r\]*vma\[ \]*(\[0-9a-fA-F\]+)" |
09250cfe ILT |
239 | if ![regexp $want $got all vma] then { |
240 | fail "objcopy --adjust-section-vma =" | |
241 | } else { | |
242 | set vma 0x$vma | |
243 | if {$vma != $low + 4} then { | |
244 | fail "objcopy --adjust-section-vma = ($vma != $low + 4)" | |
245 | } else { | |
246 | pass "objcopy --adjust-section-vma =" | |
247 | } | |
248 | } | |
249 | } | |
250 | } |