sign extension break sleb128 tests on m68k

James E Wilson wilson@specifixinc.com
Mon Mar 7 19:01:00 GMT 2005


On Mon, 2005-02-28 at 20:25, Alan Modra wrote:
> When building with a 64-bit bfd, sleb128 and quad tests fail on m68k
> targets, because something like
>  .sleb128 0x80000000
> has the constant sign extendend due to a peculiarity of m68k gas (grep
> for TARGET_WORD_SIZE) as if you'd written
>  .sleb128 0xffffffff80000000

That reminds me of something I recently noticed in the h8300 port.  I
was investigating a compiler problem, and tried building the h8300 port
on a lark to see if it could reproduce it.  Unfortunately, I discovered
that the port does not work on a 64-bit host.

One of the problems is that the h8300 gas port uses internal masks like
0xffffff00 which is intended to be -256.  That works fine on a 32-bit
host, but not on a 64-bit host, where this is a large positive number
instead of a small negative one.

The other related problem is that the testsuite contains similar
numbers.  See for instance the file h8sx_mov_insn.s in the
gas/testsuite/gas/h8300 directory.  It contains
        mov.b   #foo,@0xffff8000
which is supposed to be assembled into a 16-bit immediate field, but on
a 64-bit host that is a large positive number which requires a 32-bit
immediate field.  This causes the test to fail.

Perhaps something similar happened with the m68k port.  The problem
isn't obvious, since the code will still assemble, it just gets
assembled into larger less efficient code.  You can't tell there is a
problem unless you look at the binary instruction encodings to see that
the wrong immediate form was used.

In fact, this does seem to be the case.  It was easy to generate an
example.  Follows is two typescripts, one generated from before updating
binutils, one generated from after updating binutils.  Note that the
first one assembles into a 32-bit instruction, but the second one
assembles into a 48-bit instruction.  This is on an x86-64 linux
machine.
-- 
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com

-------------- next part --------------
Script started on Mon 07 Mar 2005 10:49:54 AM PST
aretha$ more tmp.s
	move  %d0, 0xffffff00
aretha$ ./as-new tmp.s
aretha$ ../binutils/objdump -d a.out

a.out:     file format elf32-m68k

Disassembly of section .text:

00000000 <.text>:
   0:	31c0 ff00      	movew %d0,0xffffff00
aretha$ exit

Script done on Mon 07 Mar 2005 10:50:06 AM PST
-------------- next part --------------
Script started on Mon 07 Mar 2005 10:53:40 AM PST
aretha$ more tmp.s
	move  %d0, 0xffffff00
aretha$ ./as-new tmp.s
aretha$ ../binutils/objdump -d a.out

a.out:     file format elf32-m68k

Disassembly of section .text:

00000000 <.text>:
   0:	33c0 ffff ff00 	movew %d0,0xffffff00
aretha$ exit
exit

Script done on Mon 07 Mar 2005 10:53:54 AM PST


More information about the Binutils mailing list