glibc on kfreebsd-amd64 (was: Re: segfaults on amd64, one more update)

Petr Salinger Petr.Salinger at t-systems.cz
Tue Feb 28 15:04:11 UTC 2006


Changes for 2nd variant are really small, could you please test them.

Thanks

	Petr

> The definition of argument passing into _startup is in ABI
> since draft 0.94 (January 2005).
> 
> %rsp - 16-byte aligned pointer to stack, on top of stack is argc
> %rdx - destructor function or zero for none
> 
> It was probably too late for FreeBSD to conform :-(
> 
> It uses 8-byte aligned %rdi for argc, %rsp is aligned %rdi.
> All other registers are cleared, but without PCB_FULLCTX,
> some are used internally for context switch.
> 
> Other solution without changing FreeBSD sources is to use %rsi 
> instead of %rdx. It is cleared also without PCB_FULLCTX.
> It might be better - non-threaded application will work also on stock 
> FreeBSD.
-------------- next part --------------
Index: sysdeps/kfreebsd/x86_64/dl-machine.h
===================================================================
--- sysdeps/kfreebsd/x86_64/dl-machine.h	(revision 1272)
+++ sysdeps/kfreebsd/x86_64/dl-machine.h	(working copy)
@@ -70,6 +70,8 @@
 	leaq _dl_fini(%rip), %rdx\n\
 	# And make sure %rdi points to argc stored on the stack.\n\
 	movq %r13, %rdi\n\
+	# put finalizer function also to %rsi\n\
+	movq %rdx, %rsi\n\
 	# Jump to the user's entry point.\n\
 	jmp *%r12\n\
 .previous\n\
Index: sysdeps/kfreebsd/x86_64/elf/start.S
===================================================================
--- sysdeps/kfreebsd/x86_64/elf/start.S	(revision 1272)
+++ sysdeps/kfreebsd/x86_64/elf/start.S	(working copy)
@@ -59,6 +59,9 @@
    FreeBSD decided to use %edi as pointer to stack and align %rsp,
    therefore on entry from system, %rsp=%rdi or %rsp=%rdi-8.
    on entry from ld.so glibc might set up it slightly differently 
+
+   %rdx is sometimes not cleared from kernel, we use %rsi instead
+   on entry from ld.so glibc sets both %rsi and %rdx   
 */
 
 #include "bp-sym.h"
@@ -85,7 +88,7 @@
 	rtld_fini:	%r9
 	stack_end:	stack.	*/
 
-	movq %rdx, %r9		/* Address of the shared library termination
+	movq %rsi, %r9		/* Address of the shared library termination
 				   function.  */
 	movq 0(%rdi), %rsi	/* argument count.  */
 	leaq 8(%rdi), %rdx      /* argv starts just at above argc.  */


More information about the Glibc-bsd-devel mailing list