[uClibc] SH4 with shared libraries

David McCullough davidm at snapgear.com
Sun Aug 15 22:45:35 UTC 2004


Jivin Carl SHAW lays it down ...
> Has anyone managed to get the uClibc shared library loader working on
> the SH4 platform recently?

Yes,  all the time.

> I've tried the uClibc gcc 3.3.x toolchain with latest uClibc snapshot,
> but when I try to run a shared app it seg faults (static compilation
> works).  I've switched on the ld debugging and it appears that the fault
> occurs at the end of dl-startup.c when the loader tries to transfer
> control to the application with the START() macro.  The
> _dl_get_ready_to_run() function is called and returns OK before that
> though.  The application is just
> 
> int main(int argc, char*argv[]) { int a; a++; return 1; }
> 
> Replacing the uClibc loader with the glibc one works.
> 
> Any ideas where I can go from here?  I haven't looked at loaders before,
> so simple steps or pointers to some reading material appreciated...

There's a bug in the SH asm,  it calls into 'C' code without preserving
all the important scratch registers.   I have been meaning to double
check the changes as I think more registers need to be saved,  then I
was going to send it back to uClibc.  From the sound of it this isn't
your problem,  but you never know.

Attached is the patch as it stands for the loader on SH,

Cheers,
Davidm

-- 
David McCullough, davidm at snapgear.com  Ph:+61 7 34352815 http://www.SnapGear.com
Custom Embedded Solutions + Security   Fx:+61 7 38913630 http://www.uCdot.org
-------------- next part --------------
Index: uClibc/ldso/ldso/sh/resolve.S
===================================================================
RCS file: /cvs/sw/uClibc/ldso/ldso/sh/resolve.S,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -u -r1.1.1.2 -r1.2
--- uClibc/ldso/ldso/sh/resolve.S	17 Dec 2002 23:05:08 -0000	1.1.1.2
+++ uClibc/ldso/ldso/sh/resolve.S	1 Jul 2004 04:42:57 -0000	1.2
@@ -8,6 +8,7 @@
 	.type	_dl_linux_resolve, @function
 	.balign	16
 _dl_linux_resolve:
+	mov.l	r2, @-r15	! see Note2 below
 	mov.l	r3, @-r15
 	mov.l	r4, @-r15
 	mov.l	r5, @-r15
@@ -42,6 +43,11 @@
    greater than or equal to 12.
 
    Found in binutils/bfd/elf32-sh.c by Stefan Allius <allius at atecom.com>
+
+   Note2 - we also have to preserve r2 on the stack as the call into
+   C code (_dl_linux_resolver) will use r2 as a scratch register and we
+   need it for the address for returning structures,
+   David McCullough <davidm at snapgear.com>.
  */
 	mov     #8 ,r5
 	cmp/gt  r5, r0
@@ -78,8 +84,9 @@
 	mov.l	@r15+, r6
 	mov.l	@r15+, r5
 	mov.l	@r15+, r4
+	mov.l	@r15+, r3
 	jmp	@r0		! Jump to function address
-	 mov.l	@r15+, r3
+	 mov.l	@r15+, r2	! see Note2 above
 
 	.balign	4
 


More information about the uClibc mailing list