MIPS embedded PIC bug.

Geoff Keating geoffk@geoffk.org
Thu Feb 8 11:09:00 GMT 2001


> From: cgd@sibyte.com (Chris G. Demetriou)
> Date: 07 Feb 2001 17:45:48 -0800
> 
> Hi,
> 
> It's come to my attention (internal problem report, and subsequent
> debugging), that the patches:
> 
>     http://sources.redhat.com/ml/binutils/2000-10/msg00042.html
>     http://sources.redhat.com/ml/binutils/2000-10/msg00043.html
> 
> are, in fact, incorrect.  (Only a portion of the latter patch is
> incorrect, though, and I don't completely understand _why_ the
> expected value is, in fact, to be expected.)  I'm kinda surprised that
> nobody noticed -- must be ~nobody using -membedded-pic in the current
> tools.
> 
> 
> The first patch changed the insn argument 'o' format code to modify
> the embedded-pic hack (in a way that I thought was correct, but is
> not).
> 
> Code for MIPS embedded pic switches looks like:
> 
> $LS20:
> 	...
>         lw      $3,$L20-$LS20($2)	# can be 'ld' for 64-bit GPRs.
> 	...
> $L20:
> 	... table ...
> 
> Where $LS20 is in the current section, but $L20 is undefined.  The
> change I made to the embedded PIC hack broke that.

How can $L20 be undefined?  It is defined by the line

$L20:

You're permitted to refer to symbols that appear later in the
assembler source.  The assembler is required to go back and fix up
previous references when it sees the symbol.

In fact, the code would still be valid even if $L20 was never defined,
because (IIRC) the right kind of 16-bit PC-relative reloc is available.

> The problem is, with the embedded PIC hack as general as it was,
> is that several cases in the MIPS 'empic' testcase (before I got to
> it, honest!!! 8-) would _fail_ because of the excessive generality of
> the test.  It was letting references to undefined symbols through,
> and gas couldn't properly emit relocations for them.  (To demonstrate
> this, unapply the first patch mentioned above, and make a mips-elf
> toolchain, and look at the errors generated by the MIPS empic test.)

The test didn't fail when I wrote it, did something break since and
no-one fix it?

Remember, people are permitted to write their own assembler, and many
do.  The assembler doesn't just handle compiler-generated output.  The
testcase was designed to try all the cases.

-- 
- Geoffrey Keating <geoffk@geoffk.org>


More information about the Binutils mailing list