objcopy to binary versus linking to binary

Diego 'Flameeyes' Pettenò flameeyes@gmail.com
Wed Mar 14 17:33:00 GMT 2007


Hi,

I've been working on a way to streamline the building of a stripped down 
firmware object for h8300, which is required to be in binary format (as the 
loader can only run bare code).

If I link the object files in an ELF file and then use objcopy to output them 
to binary, the code is correct and work sfine.
If I link the object files directly in a binary file through the linker 
script, some bytes are off, for instance the branch instructions points to an 
address 1 byte off the correct one (and so aren't even disasembled correctly 
by objdump later on).

I'm not sure if I'm missing something, or if it's some kind of bug, I don't 
see why the two methods results in two different binaries, but I might have 
misunderstood something, so if someone can point me to some manual, I'd 
gladly RTFM, but as far as I can see on the ld manual there should be no 
reason for the results to be any different.

I'm attaching the output from objdump for the two files, if someone has an 
idea how to handle them.

-- 
Diego "Flameeyes" Pettenò
http://farragut.flameeyes.is-a-geek.org/

-------------- next part --------------

test_fibonacci.blx:     file format binary

Disassembly of section .data:

0000000000000000 <.data>:
   0:	01 00 6d f6 	mov.l	er6,@-er7
   4:	0f f6       	mov.l	er7,er6
   6:	6a 2a 00 2b 	mov.b	@0x2b0000:32,r2l
   a:	00 00 
   c:	46 37       	.word	H'46,H'37
   e:	01 00 6b 23 	mov.l	@0x2b0000:32,er3
  12:	00 2b 00 00 
  16:	01 00 6b 22 	mov.l	@0x2b0000:32,er2
  1a:	00 2b 00 00 
  1e:	1a b2       	sub.l	er3,er2
  20:	01 00 6d f2 	mov.l	er2,@-er7
  24:	01 00 6b 22 	mov.l	@0xb00a4:32,er2
  28:	00 0b 00 a4 
  2c:	01 10 6d f2 	stm.l	er2-er3,@-sp
  30:	5e 00 0b 00 	jsr	@0xb00:24
  34:	78 01 6a aa 	mov.b	r2l,@(0x2b0000:32,r0l.b)
  38:	00 2b 00 00 
  3c:	7a 17 00 00 	add.l	#0xc,er7
  40:	00 0c 
  42:	40 05       	bra/s	.+4 (0x48)
  44:	5e 00 0b 00 	jsr	@0xb00:24
  48:	4e 00       	bgt	.0 (0x4a)
  4a:	6d 76       	mov.w	@er7+,r6
  4c:	54 70       	rts	
  4e:	01 00 6d f6 	mov.l	er6,@-er7
  52:	0f f6       	mov.l	er7,er6
  54:	6b 23 00 24 	mov.w	@0x24c1a6:32,r3
  58:	c1 a6 
  5a:	6b 22 00 24 	mov.w	@0x24c1a4:32,r2
  5e:	c1 a4 
  60:	09 32       	add.w	r3,r2
  62:	46 03       	.word	H'46,H'3
  64:	0b 02       	adds	#1,er2
  66:	6b a3 00 24 	mov.w	r3,@0x24c1a4:32
  6a:	c1 a4 
  6c:	6b a2 00 24 	mov.w	r2,@0x24c1a6:32
  70:	c1 a6 
  72:	01 00 6d 76 	mov.l	@er7+,er6
  76:	54 70       	rts	
  78:	0f 83       	mov.l	er0,er3
  7a:	0a a0       	add.l	er2,er0
  7c:	1f 83       	cmp.l	er0,er3
  7e:	47 23       	.word	H'47,H'23
  80:	0a a1       	add.l	er2,er1
  82:	14 8a       	or.b	r0l,r2l
  84:	14 ba       	or.b	r3l,r2l
  86:	14 9a       	or.b	r1l,r2l
  88:	73 0a       	btst	#0x0,r2l
  8a:	46 0d       	.word	H'46,H'd
  8c:	1b 81       	subs	#2,er1
  8e:	69 12       	mov.w	@er1,r2
  90:	6d 82       	mov.w	r2,@-er0
  92:	1f 83       	cmp.l	er0,er3
  94:	46 f7       	.word	H'46,H'f7
  96:	54 70       	rts	
  98:	1b 01       	subs	#1,er1
  9a:	68 1a       	mov.b	@er1,r2l
  9c:	6c 8a       	mov.b	r2l,@-er0
  9e:	1f 83       	cmp.l	er0,er3
  a0:	46 f7       	.word	H'46,H'f7
  a2:	54 70       	rts	
-------------- next part --------------

test_fibonacci.elf.blx:     file format binary

Disassembly of section .data:

0000000000000000 <.data>:
   0:	01 00 6d f6 	mov.l	er6,@-er7
   4:	0f f6       	mov.l	er7,er6
   6:	6a 2a 00 2b 	mov.b	@0x2b0000:32,r2l
   a:	00 00 
   c:	46 36       	bne	.+54 (0x44)
   e:	01 00 6b 23 	mov.l	@0x2b0000:32,er3
  12:	00 2b 00 00 
  16:	01 00 6b 22 	mov.l	@0x2b0000:32,er2
  1a:	00 2b 00 00 
  1e:	1a b2       	sub.l	er3,er2
  20:	01 00 6d f2 	mov.l	er2,@-er7
  24:	01 00 6b 22 	mov.l	@0xb00a4:32,er2
  28:	00 0b 00 a4 
  2c:	01 10 6d f2 	stm.l	er2-er3,@-sp
  30:	5e 0b 00 78 	jsr	@0xb0078:24
  34:	fa 01       	mov.b	#0x1,r2l
  36:	6a aa 00 2b 	mov.b	r2l,@0x2b0000:32
  3a:	00 00 
  3c:	7a 17 00 00 	add.l	#0xc,er7
  40:	00 0c 
  42:	40 04       	bra	.+4 (0x48)
  44:	5e 0b 00 4e 	jsr	@0xb004e:24
  48:	01 00 6d 76 	mov.l	@er7+,er6
  4c:	54 70       	rts	
  4e:	01 00 6d f6 	mov.l	er6,@-er7
  52:	0f f6       	mov.l	er7,er6
  54:	6b 23 00 24 	mov.w	@0x24c1a6:32,r3
  58:	c1 a6 
  5a:	6b 22 00 24 	mov.w	@0x24c1a4:32,r2
  5e:	c1 a4 
  60:	09 32       	add.w	r3,r2
  62:	46 02       	bne	.+2 (0x66)
  64:	0b 02       	adds	#1,er2
  66:	6b a3 00 24 	mov.w	r3,@0x24c1a4:32
  6a:	c1 a4 
  6c:	6b a2 00 24 	mov.w	r2,@0x24c1a6:32
  70:	c1 a6 
  72:	01 00 6d 76 	mov.l	@er7+,er6
  76:	54 70       	rts	
  78:	0f 83       	mov.l	er0,er3
  7a:	0a a0       	add.l	er2,er0
  7c:	1f 83       	cmp.l	er0,er3
  7e:	47 22       	beq	.+34 (0xa2)
  80:	0a a1       	add.l	er2,er1
  82:	14 8a       	or.b	r0l,r2l
  84:	14 ba       	or.b	r3l,r2l
  86:	14 9a       	or.b	r1l,r2l
  88:	73 0a       	btst	#0x0,r2l
  8a:	46 0c       	bne	.+12 (0x98)
  8c:	1b 81       	subs	#2,er1
  8e:	69 12       	mov.w	@er1,r2
  90:	6d 82       	mov.w	r2,@-er0
  92:	1f 83       	cmp.l	er0,er3
  94:	46 f6       	bne	.-10 (0x8c)
  96:	54 70       	rts	
  98:	1b 01       	subs	#1,er1
  9a:	68 1a       	mov.b	@er1,r2l
  9c:	6c 8a       	mov.b	r2l,@-er0
  9e:	1f 83       	cmp.l	er0,er3
  a0:	46 f6       	bne	.-10 (0x98)
  a2:	54 70       	rts	
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20070314/901428bb/attachment.sig>


More information about the Binutils mailing list