This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Detecting wrong linkage on mips PIC code
- From: Atsushi Nemoto <anemo at mba dot ocn dot ne dot jp>
- To: binutils at sources dot redhat dot com
- Date: Fri, 24 Jun 2005 01:32:44 +0900 (JST)
- Subject: Detecting wrong linkage on mips PIC code
This simple queer program does not work on mips-linux if compiled with
-O2 option. It works if compiled with -O. I'm using gcc 3.4.4 and
binutils 2.16.1.
int main(int argc, char **argv)
{
static long int random(void);
random();
return 0;
}
Declaring random() as a static function is definitely wrong, but I
wonder why none of gcc, as, or ld give me any error or warning.
With -O2, gcc outputs:
.set noreorder
...
lw $25,%got(random)($28)
nop
addiu $25,$25,%lo(random)
jalr $25
nop
This does not work.
With -O, gcc outputs:
.set reorder
...
la $25,random
jal $25
This works.
If I correctly declared random() as extern function, gcc -O2 outputs:
.set noreorder
...
lw $25,%call16(random)($28)
nop
jalr $25
This works (of course).
In first case, final output is:
4008c8: 8f998058 lw t9,-32680(gp)
4008cc: 00000000 nop
4008d0: 27390000 addiu t9,t9,0
4008d4: 0320f809 jalr t9
4008d8: 00000000 nop
where value in GOT (-32680(gp)) is 00000000.
Is it possible to detect this sort of error when compiling or linking?
---
Atsushi Nemoto
I'm not on this ML. Please CC to me. Thank you.