| 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 | |
| 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. |
| 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. |
| 48 | # Those systems should use setup_xfail here. |
| 49 | |
| 50 | setup_xfail "sh-*-coff" "sh-*-hms" |
| 51 | setup_xfail "arm-*-pe" |
| 52 | setup_xfail "m68*-*-hpux*" "m68*-*-sunos*" "m68*-*-coff" "m68*-*-vxworks*" |
| 53 | setup_xfail "m68*-ericsson-ose" |
| 54 | setup_xfail "i*86-*-linux" |
| 55 | setup_xfail "a29k-*-udi" "a29k-*-coff" |
| 56 | setup_xfail "i960-*-vxworks5.1" "i960-*-coff" |
| 57 | setup_xfail "h8300-*-hms" "h8300-*-coff" |
| 58 | setup_xfail "h8500-*-hms" "h8500-*-coff" |
| 59 | setup_xfail "hppa*-*-*" |
| 60 | clear_xfail "hppa*-*-*elf*" |
| 61 | setup_xfail "m88*-*-coff" |
| 62 | |
| 63 | if [string match "" $exec_output] then { |
| 64 | pass "objcopy (simple copy)" |
| 65 | } else { |
| 66 | send_log "$exec_output\n" |
| 67 | verbose "$exec_output" 1 |
| 68 | |
| 69 | fail "objcopy (simple copy)" |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | # Test generating S records. |
| 74 | |
| 75 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec"] |
| 76 | |
| 77 | if ![string match "" $got] then { |
| 78 | fail "objcopy -O srec" |
| 79 | } else { |
| 80 | set file [open tmpdir/copy.srec r] |
| 81 | |
| 82 | # The first S record is fixed by the file name we are using. |
| 83 | gets $file line |
| 84 | send_log "$line\n" |
| 85 | verbose $line |
| 86 | if ![string match $line "S0130000746D706469722F636F70792E7372656397\r"] { |
| 87 | fail "objcopy -O srec (bad header)" |
| 88 | } else { |
| 89 | while {[gets $file line] != -1 \ |
| 90 | && [regexp "^S\[123\]\[0-9a-fA-F\]+\r$" $line]} { |
| 91 | send_log "$line\n" |
| 92 | verbose $line |
| 93 | set line "**EOF**" |
| 94 | } |
| 95 | send_log "$line\n" |
| 96 | verbose $line |
| 97 | if ![regexp "^S\[789\]\[0-9a-fA-F\]+\r$" $line] then { |
| 98 | fail "objcopy -O srec (bad trailer)" |
| 99 | } else { |
| 100 | if {[gets $file line] != -1} then { |
| 101 | send_log "$line\n" |
| 102 | verbose $line |
| 103 | fail "objcopy -O srec (garbage at end)" |
| 104 | } else { |
| 105 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/copy.srec"] |
| 106 | if ![regexp "file format srec" $got] then { |
| 107 | fail "objcopy -O srec (objdump failed)" |
| 108 | } else { |
| 109 | pass "objcopy -O srec" |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | close $file |
| 116 | } |
| 117 | |
| 118 | # Test setting and adjusting the start address. We only test this |
| 119 | # while generating S records, because we may not be able to set the |
| 120 | # start address for other object file formats, and the S record case |
| 121 | # is the only useful one anyhow. |
| 122 | |
| 123 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/bintest.o"] |
| 124 | if ![regexp "start address (\[0-9a-fA-FxX\]+)" $got all origstart] then { |
| 125 | perror "objdump can not recognize bintest.o" |
| 126 | set origstart "" |
| 127 | } else { |
| 128 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec --set-start 0x7654"] |
| 129 | if ![string match "" $got] then { |
| 130 | fail "objcopy --set-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 --set-start" |
| 135 | } else { |
| 136 | if {$srecstart != 0x7654} then { |
| 137 | fail "objcopy --set-start ($srecstart != 0x7654)" |
| 138 | } else { |
| 139 | pass "objcopy --set-start" |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec --adjust-start 0x123"] |
| 145 | if ![string match "" $got] then { |
| 146 | fail "objcopy --adjust-start" |
| 147 | } else { |
| 148 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/copy.srec"] |
| 149 | if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then { |
| 150 | fail "objcopy --adjust-start" |
| 151 | } else { |
| 152 | if {$srecstart != $origstart + 0x123} then { |
| 153 | fail "objcopy --adjust-start ($srecstart != $origstart + 0x123)" |
| 154 | } else { |
| 155 | pass "objcopy --adjust-start" |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | # Test adjusting the overall VMA, and adjusting the VMA of a |
| 162 | # particular section. We again only test this when # generating S |
| 163 | # records. |
| 164 | |
| 165 | set low "" |
| 166 | set lowname "" |
| 167 | |
| 168 | set headers [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h tmpdir/bintest.o"] |
| 169 | |
| 170 | set headers_regexp "SECTION\[ 0-9\]+\\\[(\[^\]\]*)\\\]\[^\n\r\]*size\[ \]*(\[0-9a-fA-F\]+)\[ \]*vma\[ \]*(\[0-9a-fA-F\]+)(.*)" |
| 171 | |
| 172 | set got $headers |
| 173 | while {[regexp $headers_regexp $got all name size vma rest]} { |
| 174 | set vma 0x$vma |
| 175 | if {$low == "" || $vma < $low} then { |
| 176 | set low $vma |
| 177 | set lowname $name |
| 178 | } |
| 179 | set got $rest |
| 180 | } |
| 181 | |
| 182 | if {$low == "" || $origstart == ""} then { |
| 183 | perror "objdump can not recognize bintest.o" |
| 184 | } else { |
| 185 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec --adjust-vma 0x123"] |
| 186 | if ![string match "" $got] then { |
| 187 | fail "objcopy --adjust-vma" |
| 188 | } else { |
| 189 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -fh tmpdir/copy.srec"] |
| 190 | set want "file format srec.*start address\[ \]*(\[0-9a-fA-FxX\]+).*vma\[ \]*(\[0-9a-fA-F\]+)" |
| 191 | if ![regexp $want $got all start vma] then { |
| 192 | fail "objcopy --adjust-vma" |
| 193 | } else { |
| 194 | set vma 0x$vma |
| 195 | if {$vma != $low + 0x123} then { |
| 196 | fail "objcopy --adjust-vma ($vma != $low + 0x123)" |
| 197 | } else { |
| 198 | if {$start != $origstart + 0x123} then { |
| 199 | fail "objcopy --adjust-vma ($start != $origstart + 0x123)" |
| 200 | } else { |
| 201 | pass "objcopy --adjust-vma" |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | set arg "" |
| 208 | set got $headers |
| 209 | while {[regexp $headers_regexp $got all name size vma rest]} { |
| 210 | set vma 0x$vma |
| 211 | if {$vma == $low} then { |
| 212 | set arg "$arg --adjust-section-vma $name+4" |
| 213 | } |
| 214 | set got $rest |
| 215 | } |
| 216 | |
| 217 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec $arg"] |
| 218 | if ![string match "" $got] then { |
| 219 | fail "objcopy --adjust-section-vma +" |
| 220 | } else { |
| 221 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h tmpdir/copy.srec"] |
| 222 | set want "file format srec.*SECTION\[ \]*0\[^\n\r\]*vma\[ \]*(\[0-9a-fA-F\]+)" |
| 223 | if ![regexp $want $got all vma] then { |
| 224 | fail "objcopy --adjust-section-vma +" |
| 225 | } else { |
| 226 | set vma 0x$vma |
| 227 | if {$vma != $low + 4} then { |
| 228 | fail "objcopy --adjust-section-vma + ($vma != $low + 4)" |
| 229 | } else { |
| 230 | pass "objcopy --adjust-section-vma +" |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | regsub -all "\\+4" $arg "=[expr $low + 4]" argeq |
| 236 | set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec $argeq"] |
| 237 | if ![string match "" $got] then { |
| 238 | fail "objcopy --adjust-section-vma =" |
| 239 | } else { |
| 240 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h tmpdir/copy.srec"] |
| 241 | set want "file format srec.*SECTION\[ \]*0\[^\n\r\]*vma\[ \]*(\[0-9a-fA-F\]+)" |
| 242 | if ![regexp $want $got all vma] then { |
| 243 | fail "objcopy --adjust-section-vma =" |
| 244 | } else { |
| 245 | set vma 0x$vma |
| 246 | if {$vma != $low + 4} then { |
| 247 | fail "objcopy --adjust-section-vma = ($vma != $low + 4)" |
| 248 | } else { |
| 249 | pass "objcopy --adjust-section-vma =" |
| 250 | } |
| 251 | } |
| 252 | } |
| 253 | } |