illegal instruction on Sparc with __builtin_apply
Matthias Klose
Matthias.Klose@cs.tu-berlin.de
Sat Nov 8 17:09:00 GMT 1997
On Solaris2.5 and Solaris 2.4, egcs-971105 generates an illegal
instruction, when using __builtin_apply; these __builtin functions are
heavily used for method forwarding in Objective-C; appended is a small
test programm with assembler output and a diff to the assembler output
of gcc-2.7.2.3. The error does not show up in
gcc-2.7.2.3, but it shows up in a gcc-2.7.2.3 with g77 patches
applied.
Matthias
#include <stdio.h>
int f(int x, char *s)
{
printf("x=%d; s=%s\n", x, s);
return 5;
}
/* void (*func)(void); */
int (*func)(int, char *);
int apply(int x, char *s)
{
void *args, *rv;
args = __builtin_apply_args();
rv = __builtin_apply(func, args, 8);
return 0;
}
int main()
{
func = f;
apply(42, "foo");
return 0;
}
.file "builtin.c"
! GNU C version egcs-2.90.16 971105 (gcc2-970802 experimental) (sparc-sun-solaris2.6) compiled by GNU C version egcs-2.90.16 971105 (gcc2-970802 experimental).
! options passed:
! options enabled: -fpeephole -ffunction-cse -fkeep-static-consts
! -fpcc-struct-return -fcommon -fverbose-asm -fgnu-linker -fargument-alias
! -mepilogue -mapp-regs
gcc2_compiled.:
.section ".rodata"
.align 8
.LLC0:
.asciz "x=%d; s=%s\n"
.section ".text"
.align 4
.global f
.type f,#function
.proc 04
f:
!#PROLOGUE# 0
save %sp,-112,%sp
!#PROLOGUE# 1
st %i0,[%fp+68]
st %i1,[%fp+72]
sethi %hi(.LLC0),%o1
or %o1,%lo(.LLC0),%o0
ld [%fp+68],%o1
ld [%fp+72],%o2
call printf,0
nop
mov 5,%i0
b .LL1
nop
.LL1:
ret
restore
.LLfe1:
.size f,.LLfe1-f
.align 4
.global apply
.type apply,#function
.proc 04
apply:
!#PROLOGUE# 0
save %sp,-168,%sp
!#PROLOGUE# 1
st %i0,[%fp-48]
st %i1,[%fp-44]
st %i2,[%fp-40]
st %i3,[%fp-36]
st %i4,[%fp-32]
st %i5,[%fp-28]
add %fp,68,%o0
st %o0,[%fp-56]
ld [%fp+64],%o0
st %o0,[%fp-52]
add %fp,-56,%o0
st %i0,[%fp+68]
st %i1,[%fp+72]
st %o0,[%fp-20]
sethi %hi(func),%g2
ld [%fp-20],%o1
ld [%o1],%o0
mov %sp,%l0
add %sp,-8,%sp
add %sp,68,%o1
ld [%o0],%o2
st %o2,[%o1]
ld [%o0+4],%o0
st %o0,[%o1+4]
mov 8,%o0
ld [%fp-20],%o2
add %o0,%o2,%o1
ld [%o1],%o0
mov 12,%o1
ld [%fp-20],%o3
add %o1,%o3,%o2
ld [%o2],%o1
mov 16,%o2
ld [%fp-20],%o4
add %o2,%o4,%o3
ld [%o3],%o2
mov 20,%o3
ld [%fp-20],%o5
add %o3,%o5,%o4
ld [%o4],%o3
mov 24,%o4
ld [%fp-20],%g3
add %o4,%g3,%o5
ld [%o5],%o4
mov 28,%o5
ld [%fp-20],%o7
add %o5,%o7,%g3
ld [%g3],%o5
mov 4,%g3
ld [%fp-20],%l1
add %g3,%l1,%o7
ld [%o7],%g3
st %g3,[%sp+64]
ld [%g2+%lo(func)],%l1
call %l1,0
nop
unimp 4095
std %o0,[%fp-72]
std %f0,[%fp-64]
mov %l0,%sp
add %fp,-72,%o0
st %o0,[%fp-24]
mov 0,%i0
b .LL2
nop
.LL2:
ret
restore
.LLfe2:
.size apply,.LLfe2-apply
.section ".rodata"
.align 8
.LLC1:
.asciz "foo"
.section ".text"
.align 4
.global main
.type main,#function
.proc 04
main:
!#PROLOGUE# 0
save %sp,-112,%sp
!#PROLOGUE# 1
sethi %hi(func),%o0
sethi %hi(f),%o2
or %o2,%lo(f),%o1
st %o1,[%o0+%lo(func)]
mov 42,%o0
sethi %hi(.LLC1),%o2
or %o2,%lo(.LLC1),%o1
call apply,0
nop
mov 0,%i0
b .LL3
nop
.LL3:
ret
restore
.LLfe3:
.size main,.LLfe3-main
.common func,4,4
.ident "GCC: (GNU) egcs-2.90.16 971105 (gcc2-970802 experimental)"
2,7d1
< ! GNU C version egcs-2.90.16 971105 (gcc2-970802 experimental) (sparc-sun-solaris2.6) compiled by GNU C version egcs-2.90.16 971105 (gcc2-970802 experimental).
< ! options passed:
< ! options enabled: -fpeephole -ffunction-cse -fkeep-static-consts
< ! -fpcc-struct-return -fcommon -fverbose-asm -fgnu-linker -fargument-alias
< ! -mepilogue -mapp-regs
<
102c96
< unimp 4095
---
> nop
146,147c140,141
< .common func,4,4
< .ident "GCC: (GNU) egcs-2.90.16 971105 (gcc2-970802 experimental)"
---
> .common func,4,4
> .ident "GCC: (GNU) 2.7.2.3 (patched)"
More information about the Gcc-bugs
mailing list