busybox segfault in __uClibc_main
Joakim Tjernlund
joakim.tjernlund at transmode.se
Tue Dec 13 08:37:00 UTC 2005
> -----Original Message-----
> From: uclibc-bounces at uclibc.org
> [mailto:uclibc-bounces at uclibc.org] On Behalf Of Linh Dang
> Sent: 10 December 2005 01:29
> To: uclibc at uclibc.org
> Subject: Re: busybox segfault in __uClibc_main
>
> Joakim Tjernlund <joakim.tjernlund at transmode.se> wrote:
> >
> > Curious, does replacing r7 with r9 in
> > lwz r7,_NIP(r1)
> > lwz r8,_MSR(r1)
> > FIX_SRR1(r8, r0)
> > lwz r2,GPR2(r1)
> > lwz r1,GPR1(r1)
> > mtspr SPRN_SRR0,r7
> > mtspr SPRN_SRR1,r8
> > SYNC
> > RFI
> > work for you?
>
> I'm at home atm, but I'm damned sure it would work.
Paulus doesn't think its safe and dosn't want to add extra code to the
syscall path.
Anyhow after a long discussion on IRC, the answer was that linux will
not
change(damn, I was so close :).
Paulus did help me to find a solution though, r3 is the return value
from exec and
that is always zero iff successful.
Note: changing to the glibc way would break compatibility and I know
that some
gentoo people would not like that :)
Here is a patch that should fix this problem and maintain backwards
compat.
Please test and report back, I have not tested this myself yet due to
lack
of time.
Jocke
Index: libc/sysdeps/linux/powerpc/crt1.S
===================================================================
--- libc/sysdeps/linux/powerpc/crt1.S (revision 12856)
+++ libc/sysdeps/linux/powerpc/crt1.S (working copy)
@@ -60,7 +60,8 @@
lwz r4,0(r9)
/* find argv one word offset from the stack pointer */
addi r5,r9,4
- mr r8,r7 /* Pass _dl_fini from ldso or NULL if statically
linked */
+ mr r8,r3 /* Pass _dl_fini from ldso or NULL if statically
linked
+ Note: using r3 instead if r7, since linux 2.6
clobbers r7 */
/* Ok, now run uClibc's main() -- shouldn't return */
#ifdef __PIC__
lwz r6,_init at got(r31)
Index: ldso/ldso/powerpc/dl-startup.h
===================================================================
--- ldso/ldso/powerpc/dl-startup.h (revision 12856)
+++ ldso/ldso/powerpc/dl-startup.h (working copy)
@@ -42,8 +42,10 @@
" bne 2b\n"
" addi 6,6,4\n"
#endif
- /* Pass a termination function pointer (in this case _dl_fini) in
r7. */
- " lwz 7,_dl_fini at got(31)\n"
+ /* Pass a termination function pointer (in this case _dl_fini) in
r3. */
+ /* Paulus promized he would keep r3 zero in the exec ABI. */
+ " lwz 3,_dl_fini at got(31)\n"
+ " mr 7,3\n" /* Pass _dl_fini in r7 to maintain
compat */
" bctr\n" /* Jump to entry point */
" .size _start,.-_start\n"
" .previous\n"
More information about the uClibc
mailing list