Subject: Compiler bug?
To: None <port-pc532@netbsd.org>
From: Ian Dall <Ian.Dall@dsto.defence.gov.au>
List: port-pc532
Date: 04/28/1999 20:43:27
I have noticed that under egcs 1.0.2 I get a core dump with the following
small program.
#include <time.h>
int main(){
struct tm date = {tm_sec: 0, tm_min: 0, tm_hour: 0, tm_mday: 27, tm_mon: 9,
tm_year: 97, tm_wday: 0, tm_yday: 0, tm_isdst: 0, tm_gmtoff: 0,
tm_zone: 0x0};
char *p;
(void) mktime(&date);
p = asctime(&date);
printf("%s\n", p);
}
It appears that localtime.c has not been compiled correctly with the -fpic
option. This problem seems to have gone away with later versions of egcs
so I would be interested to see if we have it in the 1.4 beta build.
I haven't had time to upgrade, so I would be interested if someone could test
this for me.
An even simpler test to to compile
static int foo (void *p)
{
return p == foo;
}
with
cc -fpic -S
It should produce something like:
#NO_APP
gcc2_compiled.:
___gnu_compiled_c:
.text
.align 2
.type _foo,@function
_foo:
enter [],0
sprd sb,tos
addr __GLOBAL_OFFSET_TABLE_(pc),r0
lprd sb,r0
cmpd 8(fp),_foo(sb)
seqd r0
lprd sb,tos
exit []
ret 0
Lfe1:
.size _foo,Lfe1-_foo
If it produces
#NO_APP
gcc2_compiled.:
___gnu_compiled_c:
.text
.align 2
.type _foo,@function
_foo:
enter [],0
cmpd 8(fp),_foo(sb)
seqd r0
exit []
ret 0
Lfe1:
.size _foo,Lfe1-_foo
then there is a problem. It seems to be that the -fpic is handling ordinary
global symbols OK, but is not generating a global offset table or initializing
sb if the symbol happens to be a function entry point.
As far as I can tell, this has been fixed in later versions of egcs with
no changes to the MD code in the compiler, hence it may be a MI problem.
Ian