Browse Source

General arch cleanup and prepare support for standalone
execution of ldso.
Added new asm for MIPS to be tested.
All arches should retest.

Joakim Tjernlund 19 years ago
parent
commit
2331c7f052

+ 1 - 1
ldso/ldso/Makefile

@@ -73,7 +73,7 @@ XXFLAGS := $(XXFLAGS:-fomit-frame-pointer=)
 all: $(LDSO_FULLNAME)
 
 $(LDSO_FULLNAME): $(OBJS) $(DLINK_OBJS)
-	$(LD) $(LDFLAGS) -e _dl_boot -soname=$(UCLIBC_LDSO) \
+	$(LD) $(LDFLAGS) -soname=$(UCLIBC_LDSO) \
 		-o $(LDSO_FULLNAME) $(OBJS) $(LIBGCC)
 	$(INSTALL) -d $(TOPDIR)lib
 	$(INSTALL) -m 755 $(LDSO_FULLNAME) $(TOPDIR)lib

+ 15 - 20
ldso/ldso/arm/dl-startup.h

@@ -4,29 +4,26 @@
  * Copyright (C) 2000-2004 by Erik Andersen <andersen@codepoet.org>
  */
 
-void* _dl_boot(void);
-/* Overrive the default _dl_boot function, and replace it with a bit of asm.
- * Then call the real _dl_boot function, which is now named _dl_boot2. */
-asm(""						\
-"	.text\n"				\
-"	.globl	_dl_boot\n"		\
-"_dl_boot:\n"				\
-"	mov	r7, sp\n"			\
-"	@ldr	r0, [sp], #4\n"	\
-"	mov	r0, sp\n"			\
-"	bl	_dl_boot2\n"		\
-"	mov	r6, r0\n"			\
-"	mov	r0, r7\n"			\
-"	mov	pc, r6\n"			\
+asm(
+    "	.text\n"
+    "	.globl	_start\n"
+    "	.type	_start,%function\n"
+    "_start:\n"
+    "	mov	r7, sp\n"
+    "	@ldr	r0, [sp], #4\n"
+    "	mov	r0, sp\n"
+    "	bl	_dl_start\n"
+    "	mov	r6, r0\n"
+    "	mov	r0, r7\n"
+    "	mov	pc, r6\n"
+    "	.size	_start,.-_start\n"
+    "	.previous\n"
 );
 
-#define DL_BOOT(X)   static __attribute_used__ void* _dl_boot2 (X)
-
-
 /* Get a pointer to the argv array.  On many platforms this can be just
  * the address if the first argument, on other platforms we need to
  * do something a little more subtle here.  */
-#define GET_ARGV(ARGVP, ARGS) ARGVP = ((unsigned long*)   ARGS)
+#define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long*)ARGS)+1)
 
 /* Handle relocation of the symbols in the dynamic loader. */
 static inline
@@ -91,5 +88,3 @@ void PERFORM_BOOTSTRAP_RELOC(ELF_RELOC *rpnt, unsigned long *reloc_addr,
  * done.  This routine has to exit the current function, then call the
  * _dl_elf_main function.  */
 #define START()   return _dl_elf_main;
-
-

+ 3 - 3
ldso/ldso/arm/dl-sysdep.h

@@ -82,10 +82,10 @@ elf_machine_dynamic (void)
 static inline Elf32_Addr __attribute__ ((unused))
 elf_machine_load_address (void)
 {
-	extern void __dl_boot asm ("_dl_boot");
-	Elf32_Addr got_addr = (Elf32_Addr) &__dl_boot;
+	extern void __dl_start asm ("_dl_start");
+	Elf32_Addr got_addr = (Elf32_Addr) &__dl_start;
 	Elf32_Addr pcrel_addr;
-	asm ("adr %0, _dl_boot" : "=r" (pcrel_addr));
+	asm ("adr %0, _dl_start" : "=r" (pcrel_addr));
 	return pcrel_addr - got_addr;
 }
 

+ 11 - 14
ldso/ldso/cris/dl-startup.h

@@ -6,22 +6,25 @@
  * can find argc, argv and auxvt (Auxillary Vector Table).  */
 asm(""					\
 "	.text\n"			\
-"	.globl _dl_boot\n"		\
-"	.type _dl_boot,@function\n"	\
-"_dl_boot:\n"				\
+"	.globl _start\n"		\
+"	.type _start,@function\n"	\
+"_start:\n"				\
 "	move.d $sp,$r10\n"		\
 "	move.d $pc,$r9\n"		\
-"	add.d _dl_boot2 - ., $r9\n"	\
+"	add.d _dl_start - ., $r9\n"	\
 "	jsr $r9\n"			\
+"	moveq 0,$r8\n"			\
+"	move $r8,$srp\n"		\
+"	jump $r10\n"			\
+"	.size _start,.-_start\n"	\
+"	.previous\n"			\
 );
 
-#define DL_BOOT(X) static void __attribute_used__ _dl_boot2 (X)
-
 
 /* Get a pointer to the argv array.  On many platforms this can be just
  * the address if the first argument, on other platforms we need to
  * do something a little more subtle here.  */
-#define GET_ARGV(ARGVP, ARGS) ARGVP = ((unsigned long *) ARGS)
+#define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long *) ARGS)+1)
 
 /* Handle relocation of the symbols in the dynamic loader. */
 static inline
@@ -54,10 +57,4 @@ void PERFORM_BOOTSTRAP_RELOC(ELF_RELOC *rpnt, unsigned long *reloc_addr,
 /* Transfer control to the user's application, once the dynamic loader is
  * done.  This routine has to exit the current function, then call the
  * _dl_elf_main function.  */
-#define START() __asm__ volatile ("moveq 0,$r8\n\t" \
-				  "move $r8,$srp\n\t" \
-				  "move.d %1,$sp\n\t" \
-				  "jump %0\n\t" \
-				  : : "r" (_dl_elf_main), "r" (args))
-
-
+#define START()     return _dl_elf_main

+ 2 - 2
ldso/ldso/cris/dl-sysdep.h

@@ -105,8 +105,8 @@ elf_machine_load_address(void)
 {
 	Elf32_Addr gotaddr_diff;
 
-	__asm__ ("sub.d [$r0+_dl_parse:GOT16],$r0,%0\n\t"
-	         "add.d _dl_parse:GOTOFF,%0" : "=r" (gotaddr_diff));
+	__asm__ ("sub.d [$r0+_dl_start:GOT16],$r0,%0\n\t"
+	         "add.d _dl_start:GOTOFF,%0" : "=r" (gotaddr_diff));
 	return gotaddr_diff;
 }
 

+ 5 - 12
ldso/ldso/dl-startup.c

@@ -3,6 +3,7 @@
  * Program to load an ELF binary on a linux system, and run it
  * after resolving ELF shared library symbols
  *
+ * Copyright (C) 2005 by Joakim Tjernlund
  * Copyright (C) 2000-2004 by Erik Andersen <andersen@codepoet.org>
  * Copyright (c) 1994-2000 Eric Youngdale, Peter MacDonald,
  *				David Engel, Hongjiu Lu and Mitch D'Souza
@@ -109,7 +110,7 @@ int (*_dl_elf_main) (int, char **, char **);
         NULL
 		auxvt[0...N]   Auxiliary Vector Table elements (mixed types)
 */
-DL_BOOT(unsigned long args)
+static void * __attribute_used__ _dl_start(unsigned long args)
 {
 	unsigned int argc;
 	char **argv, **envp;
@@ -123,11 +124,6 @@ DL_BOOT(unsigned long args)
 	Elf32_auxv_t auxvt[AT_EGID + 1];
 	Elf32_Dyn *dpnt;
 	int indx;
-#if defined(__i386__)
-	int status = 0;
-#endif
-
-
 
 	/* WARNING! -- we cannot make _any_ funtion calls until we have
 	 * taken care of fixing up our own relocations.  Making static
@@ -137,9 +133,6 @@ DL_BOOT(unsigned long args)
 	/* First obtain the information on the stack that tells us more about
 	   what binary is loaded, where it is loaded, etc, etc */
 	GET_ARGV(aux_dat, args);
-#if defined (__arm__) || defined (__mips__) || defined (__cris__)
-	aux_dat += 1;
-#endif
 	argc = *(aux_dat - 1);
 	argv = (char **) aux_dat;
 	aux_dat += argc;			/* Skip over the argv pointers */
@@ -327,12 +320,12 @@ found_got:
 		}
 	}
 #endif
-#if defined(__mips__)
+#ifdef PERFORM_BOOTSTRAP_GOT
 #ifdef __SUPPORT_LD_DEBUG_EARLY__
-	SEND_STDERR("About to do MIPS specific GOT bootstrap\n");
+	SEND_STDERR("About to do specific GOT bootstrap\n");
 #endif
 	/* For MIPS we have to do stuff to the GOT before we do relocations.  */
-	PERFORM_BOOTSTRAP_GOT(got, tpnt);
+	PERFORM_BOOTSTRAP_GOT(tpnt);
 #endif
 
 	/* OK, now do the relocations.  We do not do a lazy binding here, so

+ 15 - 6
ldso/ldso/i386/dl-startup.h

@@ -4,8 +4,15 @@
  * Copyright (C) 2000-2004 by Erik Andersen <andersen@codepoet.org>
  */
 
-/* For x86 we do not need any special setup so go right to _dl_boot() */
-#define DL_BOOT(X) __attribute_used__ void _dl_boot (X)
+asm(
+    "	.text\n"
+    "	.globl	_start\n"
+    "	.type	_start,@function\n"
+    "_start:\n"
+    "	.set	_start,_dl_start\n"
+    "	.size	_start,.-_start\n"
+    "	.previous\n"
+);
 
 /* Get a pointer to the argv array.  On many platforms this can be just
  * the address if the first argument, on other platforms we need to
@@ -40,7 +47,9 @@ void PERFORM_BOOTSTRAP_RELOC(ELF_RELOC *rpnt, unsigned long *reloc_addr,
 /* Transfer control to the user's application, once the dynamic loader is
  * done.  This routine has to exit the current function, then call the
  * _dl_elf_main function.  */
-#define START()											\
-	__asm__ volatile ("leave\n\t"						\
-		    "jmp *%%eax\n\t"							\
-		    : "=a" (status) :	"a" (_dl_elf_main))
+#define START() {							\
+	int status = 0;							\
+	__asm__ volatile ("leave\n\t"					\
+		    "jmp *%%eax\n\t"					\
+		    : "=a" (status) :	"a" (_dl_elf_main));		\
+}

+ 2 - 2
ldso/ldso/i386/dl-sysdep.h

@@ -61,8 +61,8 @@ elf_machine_load_address (void)
 	   via the GOT to make sure the compiler initialized %ebx in time.  */
 	extern int _dl_errno;
 	Elf32_Addr addr;
-	asm ("leal _dl_boot@GOTOFF(%%ebx), %0\n"
-	     "subl _dl_boot@GOT(%%ebx), %0"
+	asm ("leal _dl_start@GOTOFF(%%ebx), %0\n"
+	     "subl _dl_start@GOT(%%ebx), %0"
 	     : "=r" (addr) : "m" (_dl_errno) : "cc");
 	return addr;
 }

+ 8 - 0
ldso/ldso/ldso.c

@@ -3,6 +3,7 @@
  * Program to load an ELF binary on a linux system, and run it
  * after resolving ELF shared library symbols
  *
+ * Copyright (C) 2005 by Joakim Tjernlund
  * Copyright (C) 2000-2004 by Erik Andersen <andersen@codepoet.org>
  * Copyright (c) 1994-2000 Eric Youngdale, Peter MacDonald,
  *				David Engel, Hongjiu Lu and Mitch D'Souza
@@ -82,6 +83,8 @@ static void debug_fini (int status, void *arg)
 }
 #endif
 
+extern void _start(void);
+
 void _dl_get_ready_to_run(struct elf_resolve *tpnt, unsigned long load_addr,
 			  Elf32_auxv_t auxvt[AT_EGID + 1], char **envp,
 			  char **argv)
@@ -129,6 +132,11 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, unsigned long load_addr,
 		_dl_progname = argv[0];
 	}
 
+	if (_start == (void *) auxvt[AT_ENTRY].a_un.a_fcn) {
+		_dl_dprintf(2, "Standalone exection is not supported yet\n");
+		_dl_exit(1);
+	}
+
 	/* Start to build the tables of the modules that are required for
 	 * this beast to run.  We start with the basic executable, and then
 	 * go from there.  Eventually we will run across ourself, and we

+ 2 - 2
ldso/ldso/m68k/dl-sysdep.h

@@ -58,8 +58,8 @@ static inline Elf32_Addr
 elf_machine_load_address (void)
 {
 	Elf32_Addr addr;
-	asm ("lea _dl_boot(%%pc), %0\n\t"
-	     "sub.l _dl_boot@GOT.w(%%a5), %0"
+	asm ("lea _dl_start(%%pc), %0\n\t"
+	     "sub.l _dl_start@GOT.w(%%a5), %0"
 	     : "=a" (addr));
 	return addr;
 }

+ 106 - 37
ldso/ldso/mips/dl-startup.h

@@ -1,54 +1,126 @@
 /* Any assmbly language/system dependent hacks needed to setup boot1.c so it
  * will work as expected and cope with whatever platform specific wierdness is
  * needed for this architecture.
+ * Copyright (C) 2005 by Joakim Tjernlund
  */
 
-asm("" \
-"	.text\n"			\
-"	.globl	_dl_boot\n"		\
-"_dl_boot:\n"				\
-"	.set noreorder\n"		\
-"	bltzal $0, 0f\n"		\
-"	nop\n"				\
-"0:	.cpload $31\n"			\
-"	.set reorder\n"			\
-"	la $4, _DYNAMIC\n"		\
-"	sw $4, -0x7ff0($28)\n"	        \
-"	move $4, $29\n"			\
-"	la $8, coff\n"			\
-"	.set noreorder\n"		\
-"	bltzal $0, coff\n"		\
-"	nop\n"				\
-"coff:	subu $8, $31, $8\n"		\
-"	.set reorder\n"			\
-"	la $25, _dl_boot2\n"	        \
-"	addu $25, $8\n"			\
-"	jalr $25\n"			\
-"	lw $4, 0($29)\n"		\
-"	la $5, 4($29)\n"		\
-"	sll $6, $4, 2\n"		\
-"	addu $6, $6, $5\n"		\
-"	addu $6, $6, 4\n"		\
-"	la $7, _dl_elf_main\n"		\
-"	lw $25, 0($7)\n"		\
-"	jr $25\n"			\
+#if 0
+asm(""
+    "	.text\n"
+    "	.globl	_start\n"
+    "	.type	_start,@function\n"
+    "_start:\n"
+    "	.set noreorder\n"
+    "	bltzal $0, 0f\n"
+    "	nop\n"
+    "0:	.cpload $31\n"
+    "	.set reorder\n"
+    "	la $4, _DYNAMIC\n"
+    "	sw $4, -0x7ff0($28)\n"
+    "	move $4, $29\n"
+    "	la $8, coff\n"
+    "	.set noreorder\n"
+    "	bltzal $0, coff\n"
+    "	nop\n"
+    "coff:	subu $8, $31, $8\n"
+    "	.set reorder\n"
+    "	la $25, _dl_start\n"
+    "	addu $25, $8\n"
+    "	jalr $25\n"
+    "	lw $4, 0($29)\n"
+    "	la $5, 4($29)\n"
+    "	sll $6, $4, 2\n"
+    "	addu $6, $6, $5\n"
+    "	addu $6, $6, 4\n"
+    "	la $7, _dl_elf_main\n"
+    "	lw $25, 0($7)\n"
+    "	jr $25\n"
+    "	.size	_start,.-_start\n"
+    "	.previous\n"
+);
+#endif
+#if 0
+asm(""
+    "	.text\n"
+    "	.globl	_start\n"
+    "	.type	_start,@function\n"
+    "_start:\n"
+    "	.set noreorder\n"
+    "	bltzal $0, 0f\n"
+    "	nop\n"
+    "0:	.cpload $31\n"
+    "	.set reorder\n"
+    "	la $4, _DYNAMIC\n"
+    "	sw $4, -0x7ff0($28)\n"
+    "	move $4, $29\n"
+    "	la $8, coff\n"
+    "	.set noreorder\n"
+    "	bltzal $0, coff\n"
+    "	nop\n"
+    "coff:	subu $8, $31, $8\n"
+    "	.set reorder\n"
+    "	la $25, _dl_start\n"
+    "	addu $25, $8\n"
+    "	jalr $25\n"
+    "	move $17, $2\n"
+    "	lw $4, 0($29)\n"
+    "	la $5, 4($29)\n"
+    "	sll $6, $4, 2\n"
+    "	addu $6, $6, $5\n"
+    "	addu $6, $6, 4\n"
+    "	move $25, $17\n"
+    "	jr $25\n"
+    "	.size	_start,.-_start\n"
+    "	.previous\n"
+);
+#endif
+asm(""
+    "	.text\n"
+    "	.globl	_start\n"
+    "	.type	_start,@function\n"
+    "_start:\n"
+    "	.set noreorder\n"
+    "	bltzal $0, 0f\n"
+    "	nop\n"
+    "0:	.cpload $31\n"
+    "	.set reorder\n"
+    "	la $4, _DYNAMIC\n"
+    "	sw $4, -0x7ff0($28)\n"
+    "	move $4, $29\n"
+    "	subu $29, 16\n"
+    "	la $8, coff\n"
+    "	.set noreorder\n"
+    "	bltzal $8, coff\n"
+    "coff:	subu $8, $31, $8\n"
+    "	.set reorder\n"
+    "	la $25, _dl_start\n"
+    "	addu $25, $8\n"
+    "	jalr $25\n"
+    "	move $17, $2\n"
+    "	lw $4, 0($29)\n"
+    "	la $5, 4($29)\n"
+    "	sll $6, $4, 2\n"
+    "	addu $6, $6, $5\n"
+    "	addu $6, $6, 4\n"
+    "	move $25, $17\n"
+    "	jr $25\n"
+    "	.size	_start,.-_start\n"
+    "	.previous\n"
 );
-
-#define DL_BOOT(X)   static void __attribute_used__ _dl_boot2 (X)
 
 /*
  * Get a pointer to the argv array.  On many platforms this can be just
  * the address if the first argument, on other platforms we need to
  * do something a little more subtle here.
  */
-#define GET_ARGV(ARGVP, ARGS) ARGVP = ((unsigned long *) ARGS)
+#define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long *) ARGS)+1)
 
 
 /*
  * Here is a macro to perform the GOT relocation. This is only
  * used when bootstrapping the dynamic loader.
  */
-#define PERFORM_BOOTSTRAP_GOT(got, tpnt)					\
+#define PERFORM_BOOTSTRAP_GOT(tpnt)						\
 do {										\
 	Elf32_Sym *sym;								\
 	Elf32_Addr i;								\
@@ -115,7 +187,4 @@ do {										\
  * because the stack doesn't get properly restored otherwise. Got look
  * at boot1_arch.h
  */
-#define START()
-
-
-
+#define START() return _dl_elf_main

+ 10 - 13
ldso/ldso/powerpc/dl-startup.h

@@ -1,29 +1,26 @@
 /* Any assmbly language/system dependent hacks needed to setup boot1.c so it
  * will work as expected and cope with whatever platform specific wierdness is
- * needed for this architecture.  */
+ * needed for this architecture.
+ * Copyright (C) 2005 by Joakim Tjernlund
+ */
 
-/* Overrive the default _dl_boot function, and replace it with a bit of asm.
- * Then call the real _dl_boot function, which is now named _dl_boot2. */
 asm(
     "	.text\n"
-    "	.globl	_dl_boot\n"
-    "	.type	_dl_boot,@function\n"
-    "_dl_boot:\n"
-    "	mr	3,1\n" /* Pass SP to _dl_boot2 in r3 */
-    "	addi	1,1,-16\n" /* Make room on stack for _dl_boot2 to store LR */
+    "	.globl	_start\n"
+    "	.type	_start,@function\n"
+    "_start:\n"
+    "	mr	3,1\n" /* Pass SP to _dl_start in r3 */
+    "	addi	1,1,-16\n" /* Make room on stack for _dl_start to store LR */
     "	li	4,0\n"
     "	stw	4,0(1)\n" /* Clear Stack frame */
-    "	bl	_dl_boot2@local\n" /* Perform relocation */
+    "	bl	_dl_start@local\n" /* Perform relocation */
     "	addi	1,1,16\n" /* Restore SP */
     "	mtctr	3\n" /* Load applications entry point */
     "	bctr\n" /* Jump to entry point */
-    "	.size	_dl_boot,.-_dl_boot\n"
+    "	.size	_start,.-_start\n"
     "	.previous\n"
 );
 
-
-#define DL_BOOT(X) static void* __attribute_used__ _dl_boot2(X)
-
 /*
  * Get a pointer to the argv array.  On many platforms this can be just
  * the address if the first argument, on other platforms we need to

+ 15 - 16
ldso/ldso/sh/dl-startup.h

@@ -2,24 +2,23 @@
  * will work as expected and cope with whatever platform specific wierdness is
  * needed for this architecture.  */
 
-asm("" \
-"	.text\n"			\
-"	.globl	_dl_boot\n"		\
-"_dl_boot:\n"				\
-"	mov	r15, r4\n"		\
-"	mov.l   .L_dl_boot2, r0\n"	\
-"	bsrf    r0\n"			\
-"	add	#4, r4\n"		\
-".jmp_loc:\n"				\
-"	jmp	@r0\n"			\
-"	 mov    #0, r4 	!call _start with arg == 0\n" \
-".L_dl_boot2:\n"			\
-"	.long   _dl_boot2-.jmp_loc\n"	\
-"	.previous\n"			\
+asm(
+    "	.globl	_start\n"
+    "	.type	_start,@function\n"
+    "_start:\n"
+    "	mov	r15, r4\n"
+    "	mov.l   .L_dl_start, r0\n"
+    "	bsrf    r0\n"
+    "	add	#4, r4\n"
+    ".jmp_loc:\n"
+    "	jmp	@r0\n"
+    "	mov    #0, r4 	!call _start with arg == 0\n"
+    ".L_dl_start:\n"
+    "	.long   _dl_start-.jmp_loc\n"
+    "	.size	_start,.-_start\n"
+    "	.previous\n"
 );
 
-#define DL_BOOT(X)   static void* __attribute_used__ _dl_boot2 (X)
-
 /*
  * Get a pointer to the argv array.  On many platforms this can be just
  * the address if the first argument, on other platforms we need to

+ 2 - 2
ldso/ldso/sh/dl-sysdep.h

@@ -120,8 +120,8 @@ elf_machine_load_address (void)
         bra 2f\n\
          sub r0,r2\n\
         .align 2\n\
-        1: .long _dl_boot@GOT\n\
-        3: .long _dl_boot@GOTOFF\n\
+        1: .long _dl_start@GOT\n\
+        3: .long _dl_start@GOTOFF\n\
         2: mov r2,%0"
 	     : "=r" (addr) : : "r0", "r1", "r2");
 	return addr;

+ 9 - 7
ldso/ldso/sparc/dl-startup.h

@@ -3,9 +3,15 @@
  * needed for this architecture.  See arm/boot1_arch.h for an example of what
  * can be done.
  */
-
-#define DL_BOOT(X) __attribute_used__ void _dl_boot (X)
-
+asm(
+    "	.text\n"
+    "	.globl	_start\n"
+    "	.type	_start,@function\n"
+    "_start:\n"
+    "	.set	_start,_dl_start\n"
+    "	.size	_start,.-_start\n"
+    "	.previous\n"
+);
 
 /*
  * Get a pointer to the argv array.  On many platforms this can be just
@@ -56,7 +62,3 @@
 			   "restore %%g0,%%g0,%%g0\n\t" \
 		    	: /*"=r" (status) */ :	\
 		    	  "r" (_dl_elf_main): "g1", "o0", "o1")
-
-
-
-