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 | ||
29 | if {![binutils_assemble $AS $srcdir$subdir/bintest.s tmpdir/bintest.o]} then { | |
30 | return | |
31 | } | |
32 | ||
33 | # Test that objcopy does not modify a file when copying it. | |
34 | ||
35 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o"] | |
36 | ||
37 | if ![string match "" $got] then { | |
38 | fail "objcopy (simple copy)" | |
39 | } else { | |
40 | send_log "cmp tmpdir/bintest.o tmpdir/copy.o\n" | |
41 | verbose "cmp tmpdir/bintest.o tmpdir/copy.o" | |
42 | catch "exec cmp tmpdir/bintest.o tmpdir/copy.o" exec_output | |
43 | ||
44 | # On some systems the result of objcopy will not be identical. | |
45 | # Those systems should use setup_xfail here. | |
46 | ||
47 | if [string match "" $exec_output] then { | |
48 | pass "objcopy (simple copy)" | |
49 | } else { | |
50 | send_log "$exec_output\n" | |
51 | verbose "$exec_output" 1 | |
52 | ||
53 | fail "objcopy (simple copy)" | |
54 | } | |
55 | } | |
56 | ||
57 | # Test generating S records. | |
58 | ||
59 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec"] | |
60 | ||
61 | if ![string match "" $got] then { | |
62 | fail "objcopy -O srec" | |
63 | } else { | |
64 | set file [open tmpdir/copy.srec r] | |
65 | ||
66 | # The first S record is fixed by the file name we are using. | |
67 | gets $file line | |
68 | send_log "$line\n" | |
69 | verbose $line | |
70 | if ![string match $line "S0130000746D706469722F636F70792E7372656397\r"] { | |
71 | fail "objcopy -O srec (bad header)" | |
72 | } else { | |
73 | while {[gets $file line] != -1 \ | |
74 | && [regexp "^S\[123\]\[0-9a-fA-F\]+\r$" $line]} { | |
75 | send_log "$line\n" | |
76 | verbose $line | |
77 | set line "**EOF**" | |
78 | } | |
79 | send_log "$line\n" | |
80 | verbose $line | |
81 | if ![regexp "^S\[789\]\[0-9a-fA-F\]+\r$" $line] then { | |
82 | fail "objcopy -O srec (bad trailer)" | |
83 | } else { | |
84 | if {[gets $file line] != -1} then { | |
85 | send_log "$line\n" | |
86 | verbose $line | |
87 | fail "objcopy -O srec (garbage at end)" | |
88 | } else { | |
89 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/copy.srec"] | |
90 | if ![regexp "file format srec" $got] then { | |
91 | fail "objcopy -O srec (objdump failed)" | |
92 | } else { | |
93 | pass "objcopy -O srec" | |
94 | } | |
95 | } | |
96 | } | |
97 | } | |
98 | ||
99 | close $file | |
100 | } | |
101 | ||
102 | # Test setting and adjusting the start address. We only test this | |
103 | # while generating S records, because we may not be able to set the | |
104 | # start address for other object file formats, and the S record case | |
105 | # is the only useful one anyhow. | |
106 | ||
107 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/bintest.o"] | |
108 | if ![regexp "start address (\[0-9a-fA-FxX\]+)" $got all origstart] then { | |
109 | perror "objdump can not recognize bintest.o" | |
110 | set origstart "" | |
111 | } else { | |
112 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec --set-start 0x7654"] | |
113 | if ![string match "" $got] then { | |
114 | fail "objcopy --set-start" | |
115 | } else { | |
116 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/copy.srec"] | |
117 | if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then { | |
118 | fail "objcopy --set-start" | |
119 | } else { | |
120 | if {$srecstart != 0x7654} then { | |
121 | fail "objcopy --set-start ($srecstart != 0x7654)" | |
122 | } else { | |
123 | pass "objcopy --set-start" | |
124 | } | |
125 | } | |
126 | } | |
127 | ||
128 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec --adjust-start 0x123"] | |
129 | if ![string match "" $got] then { | |
130 | fail "objcopy --adjust-start" | |
131 | } else { | |
132 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/copy.srec"] | |
133 | if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then { | |
134 | fail "objcopy --adjust-start" | |
135 | } else { | |
136 | if {$srecstart != $origstart + 0x123} then { | |
137 | fail "objcopy --adjust-start ($srecstart != $origstart + 0x123)" | |
138 | } else { | |
139 | pass "objcopy --adjust-start" | |
140 | } | |
141 | } | |
142 | } | |
143 | } | |
144 | ||
145 | # Test adjusting the overall VMA, and adjusting the VMA of a | |
146 | # particular section. We again only test this when # generating S | |
147 | # records. | |
148 | ||
149 | set low "" | |
150 | set lowname "" | |
151 | ||
152 | set headers [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h tmpdir/bintest.o"] | |
153 | ||
154 | set headers_regexp "SECTION\[ 0-9\]+\\\[(\[^\]\]*)\\\]\[^\n\r\]*size\[ \]*(\[0-9a-fA-F\]+)\[ \]*vma\[ \]*(\[0-9a-fA-F\]+)(.*)" | |
155 | ||
156 | set got $headers | |
157 | while {[regexp $headers_regexp $got all name size vma rest]} { | |
158 | set vma 0x$vma | |
159 | if {$low == "" || $vma < $low} then { | |
160 | set low $vma | |
161 | set lowname $name | |
162 | } | |
163 | set got $rest | |
164 | } | |
165 | ||
166 | if {$low == "" || $origstart == ""} then { | |
167 | perror "objdump can not recognize bintest.o" | |
168 | } else { | |
169 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec --adjust-vma 0x123"] | |
170 | if ![string match "" $got] then { | |
171 | fail "objcopy --adjust-vma" | |
172 | } else { | |
173 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -fh tmpdir/copy.srec"] | |
174 | set want "file format srec.*start address\[ \]*(\[0-9a-fA-FxX\]+).*vma\[ \]*(\[0-9a-fA-F\]+)" | |
175 | if ![regexp $want $got all start vma] then { | |
176 | fail "objcopy --adjust-vma" | |
177 | } else { | |
178 | set vma 0x$vma | |
179 | if {$vma != $low + 0x123} then { | |
180 | fail "objcopy --adjust-vma ($vma != $low + 0x123)" | |
181 | } else { | |
182 | if {$start != $origstart + 0x123} then { | |
183 | fail "objcopy --adjust-vma ($start != $origstart + 0x123)" | |
184 | } else { | |
185 | pass "objcopy --adjust-vma" | |
186 | } | |
187 | } | |
188 | } | |
189 | } | |
190 | ||
191 | set arg "" | |
192 | set got $headers | |
193 | while {[regexp $headers_regexp $got all name size vma rest]} { | |
194 | set vma 0x$vma | |
195 | if {$vma == $low} then { | |
196 | set arg "$arg --adjust-section-vma $name+4" | |
197 | } | |
198 | set got $rest | |
199 | } | |
200 | ||
201 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec $arg"] | |
202 | if ![string match "" $got] then { | |
203 | fail "objcopy --adjust-section-vma +" | |
204 | } else { | |
205 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h tmpdir/copy.srec"] | |
206 | set want "file format srec.*vma\[ \]*(\[0-9a-fA-F\]+)" | |
207 | if ![regexp $want $got all vma] then { | |
208 | fail "objcopy --adjust-section-vma +" | |
209 | } else { | |
210 | set vma 0x$vma | |
211 | if {$vma != $low + 4} then { | |
212 | fail "objcopy --adjust-section-vma + ($vma != $low + 4)" | |
213 | } else { | |
214 | pass "objcopy --adjust-section-vma +" | |
215 | } | |
216 | } | |
217 | } | |
218 | ||
219 | regsub -all "\\+4" $arg "=[expr $low + 4]" argeq | |
220 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec $argeq"] | |
221 | if ![string match "" $got] then { | |
222 | fail "objcopy --adjust-section-vma =" | |
223 | } else { | |
224 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h tmpdir/copy.srec"] | |
225 | set want "file format srec.*vma\[ \]*(\[0-9a-fA-F\]+)" | |
226 | if ![regexp $want $got all vma] then { | |
227 | fail "objcopy --adjust-section-vma =" | |
228 | } else { | |
229 | set vma 0x$vma | |
230 | if {$vma != $low + 4} then { | |
231 | fail "objcopy --adjust-section-vma = ($vma != $low + 4)" | |
232 | } else { | |
233 | pass "objcopy --adjust-section-vma =" | |
234 | } | |
235 | } | |
236 | } | |
237 | } |