[uClibc] RE: [uClibc-cvs] svn commit: trunk/uClibc/ldso/ldso: arm cris i386 m68k mips powerpc sh sh64 etc...
Joakim Tjernlund
joakim.tjernlund at lumentis.se
Tue Mar 15 22:57:32 UTC 2005
>
> On Tue Mar 15, 2005 at 07:26:08PM +0100, Joakim Tjernlund wrote:
> > > On Tue Mar 15, 2005 at 09:40:43AM +0100, Joakim Tjernlund wrote:
> > > > >
> > > > > On Mon Mar 14, 2005 at 06:25:10AM -0700, jocke at uclibc.org wrote:
> > > > > > I probably broke one or two archs(only tested PPC) so please
> > > > > > try and report problems. For a report to be useful you need
> > > > > > to enable __SUPPORT_LD_DEBUG_EARLY__ and __SUPPORT_LD_DEBUG__
> > > > >
> > > > > I can confirm that at least mips and x86 are broken...
> > > > [SNIP]
> > > >
> > > > x86, MIPS and PPC should be OK now. No reports on the other
> > > > arches CRIS, ARM, SPARC, M68K, SH and SH64 (Hint hint :)
> > >
> > > With last nights fix, arm works.
> >
> > hmm, ARM works for you but not for Peter Mazinger?
>
> I used gcc 3.3.5. I rebuilt with gcc 3.4.3 and saw the same
> failure on arm that psm reported.
>
> > Can both of you try the latest path I sent? I belive that
> > is the way to move forward and the other arches should follow.
>
> arm does indeed compiles and run, even with gcc 3.4.3 when
> built with your latest patch.
OK, now I have adapted the rest and made some more cleanups. Need some help with
asm for x86, SPARC and M68K. Replace jmp dl_start with correct asm.
Can I commit this and fix problems as they gets reported(pretty please :) or
should I wait for feedback first?
Index: arm/dl-startup.h
===================================================================
--- arm/dl-startup.h (revision 10012)
+++ arm/dl-startup.h (working copy)
@@ -2,31 +2,29 @@
/*
* Architecture specific code used by dl-startup.c
* Copyright (C) 2000-2004 by Erik Andersen <andersen at codepoet.org>
+ * Copyright (C) 2005 by Joakim Tjernlund
*/
-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, at 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
Index: arm/dl-sysdep.h
===================================================================
--- arm/dl-sysdep.h (revision 10012)
+++ arm/dl-sysdep.h (working copy)
@@ -3,6 +3,7 @@
* Various assmbly language/system dependent hacks that are required
* so that we can minimize the amount of platform specific code.
* Copyright (C) 2000-2004 by Erik Andersen <andersen at codepoet.org>
+ * Copyright (C) 2005 by Joakim Tjernlund
*/
/* Define this if the system uses RELOCA. */
@@ -82,10 +83,10 @@
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;
}
Index: powerpc/dl-startup.h
===================================================================
--- powerpc/dl-startup.h (revision 10012)
+++ powerpc/dl-startup.h (working copy)
@@ -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, at 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, at 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 at local\n" /* Perform relocation */
+ " bl _dl_start at 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
Index: dl-startup.c
===================================================================
--- dl-startup.c (revision 10012)
+++ dl-startup.c (working copy)
@@ -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 at codepoet.org>
* Copyright (c) 1994-2000 Eric Youngdale, Peter MacDonald,
* David Engel, Hongjiu Lu and Mitch D'Souza
@@ -109,7 +110,7 @@
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,12 +124,7 @@
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
* inline calls is ok, but _no_ function calls. Not yet
@@ -137,9 +133,6 @@
/* 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 @@
}
}
#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
Index: ldso.c
===================================================================
--- ldso.c (revision 10012)
+++ ldso.c (working copy)
@@ -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 at codepoet.org>
* Copyright (c) 1994-2000 Eric Youngdale, Peter MacDonald,
* David Engel, Hongjiu Lu and Mitch D'Souza
@@ -128,6 +129,11 @@
if (argv[0]) {
_dl_progname = argv[0];
}
+ extern void _start(void);
+ 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
Index: m68k/dl-startup.h
===================================================================
--- m68k/dl-startup.h (revision 10012)
+++ m68k/dl-startup.h (working copy)
@@ -1,9 +1,17 @@
/*
* Architecture specific code used by dl-startup.c
+ * Copyright (C) 2005 by Joakim Tjernlund
*/
-/* For m68k 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, at function\n"
+ "_start:\n"
+jmp _dl_start
+ " .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
@@ -60,6 +68,3 @@
__asm__ volatile ("unlk %%a6\n\t" \
"jmp %0@" \
: : "a" (_dl_elf_main));
-
-
-
Index: m68k/dl-sysdep.h
===================================================================
--- m68k/dl-sysdep.h (revision 10012)
+++ m68k/dl-sysdep.h (working copy)
@@ -1,6 +1,8 @@
/* Various assmbly language/system dependent hacks that are required
- so that we can minimize the amount of platform specific code. */
+ so that we can minimize the amount of platform specific code.
+ * Copyright (C) 2005 by Joakim Tjernlund
+ */
/* Define this if the system uses RELOCA. */
#define ELF_USES_RELOCA
@@ -54,8 +56,8 @@
elf_machine_load_address (void)
{
Elf32_Addr addr;
- asm ("lea _dl_boot(%%pc), %0\n\t"
- "sub.l _dl_boot at GOT.w(%%a5), %0"
+ asm ("lea _dl_start(%%pc), %0\n\t"
+ "sub.l _dl_start at GOT.w(%%a5), %0"
: "=a" (addr));
return addr;
}
Index: i386/dl-startup.h
===================================================================
--- i386/dl-startup.h (revision 10012)
+++ i386/dl-startup.h (working copy)
@@ -2,10 +2,18 @@
/*
* Architecture specific code used by dl-startup.c
* Copyright (C) 2000-2004 by Erik Andersen <andersen at codepoet.org>
+ * Copyright (C) 2005 by Joakim Tjernlund
*/
-/* 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, at function\n"
+ "_start:\n"
+jmp _dl_start
+ " .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
@@ -41,11 +49,9 @@
/* 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)) \
+}
Index: i386/dl-sysdep.h
===================================================================
--- i386/dl-sysdep.h (revision 10012)
+++ i386/dl-sysdep.h (working copy)
@@ -3,6 +3,7 @@
* Various assmbly language/system dependent hacks that are required
* so that we can minimize the amount of platform specific code.
* Copyright (C) 2000-2004 by Erik Andersen <andersen at codepoet.org>
+ * Copyright (C) 2005 by Joakim Tjernlund
*/
/* Define this if the system uses RELOCA. */
@@ -61,8 +62,8 @@
via the GOT to make sure the compiler initialized %ebx in time. */
extern int _dl_errno;
Elf32_Addr addr;
- asm ("leal _dl_boot at GOTOFF(%%ebx), %0\n"
- "subl _dl_boot at GOT(%%ebx), %0"
+ asm ("leal _dl_start at GOTOFF(%%ebx), %0\n"
+ "subl _dl_start at GOT(%%ebx), %0"
: "=r" (addr) : "m" (_dl_errno) : "cc");
return addr;
}
Index: cris/dl-startup.h
===================================================================
--- cris/dl-startup.h (revision 10012)
+++ cris/dl-startup.h (working copy)
@@ -1,27 +1,26 @@
/*
* Architecture specific code used by dl-startup.c
+ * Copyright (C) 2005 by Joakim Tjernlund
*/
/* This code fixes the stack pointer so that the dynamic linker
* can find argc, argv and auxvt (Auxillary Vector Table). */
asm("" \
" .text\n" \
-" .globl _dl_boot\n" \
-" .type _dl_boot, at function\n" \
-"_dl_boot:\n" \
+" .globl _start\n" \
+" .type _start, at 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" \
);
-#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
Index: cris/dl-sysdep.h
===================================================================
--- cris/dl-sysdep.h (revision 10012)
+++ cris/dl-sysdep.h (working copy)
@@ -1,4 +1,6 @@
-/* CRIS can never use Elf32_Rel relocations. */
+/* CRIS can never use Elf32_Rel relocations.
+ * Copyright (C) 2005 by Joakim Tjernlund
+ */
#define ELF_USES_RELOCA
#include <elf.h>
@@ -105,8 +107,8 @@
{
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;
}
Index: mips/dl-startup.h
===================================================================
--- mips/dl-startup.h (revision 10012)
+++ mips/dl-startup.h (working copy)
@@ -1,54 +1,56 @@
/* 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" \
+asm(""
+ " .text\n"
+ " .globl _start\n"
+ " .type _start, at 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"
);
-#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; \
@@ -116,6 +118,3 @@
* at boot1_arch.h
*/
#define START()
-
-
-
Index: sparc/dl-startup.h
===================================================================
--- sparc/dl-startup.h (revision 10012)
+++ sparc/dl-startup.h (working copy)
@@ -2,9 +2,18 @@
* will work as expected and cope with whatever platform specific wierdness is
* needed for this architecture. See arm/boot1_arch.h for an example of what
* can be done.
+ * Copyright (C) 2005 by Joakim Tjernlund
*/
-#define DL_BOOT(X) __attribute_used__ void _dl_boot (X)
+asm(
+ " .text\n"
+ " .globl _start\n"
+ " .type _start, at function\n"
+ "_start:\n"
+jmp _dl_start
+ " .size _start,.-_start\n"
+ " .previous\n"
+);
/*
@@ -56,7 +65,3 @@
"restore %%g0,%%g0,%%g0\n\t" \
: /*"=r" (status) */ : \
"r" (_dl_elf_main): "g1", "o0", "o1")
-
-
-
-
Index: sh/dl-startup.h
===================================================================
--- sh/dl-startup.h (revision 10012)
+++ sh/dl-startup.h (working copy)
@@ -1,25 +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
+ */
-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, at 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
Index: sh/dl-sysdep.h
===================================================================
--- sh/dl-sysdep.h (revision 10012)
+++ sh/dl-sysdep.h (working copy)
@@ -1,6 +1,7 @@
/*
* Various assmbly language/system dependent hacks that are required
* so that we can minimize the amount of platform specific code.
+ * Copyright (C) 2005 by Joakim Tjernlund
*/
/* Define this if the system uses RELOCA. */
@@ -120,8 +121,8 @@
bra 2f\n\
sub r0,r2\n\
.align 2\n\
- 1: .long _dl_boot at GOT\n\
- 3: .long _dl_boot at GOTOFF\n\
+ 1: .long _dl_start at GOT\n\
+ 3: .long _dl_start at GOTOFF\n\
2: mov r2,%0"
: "=r" (addr) : : "r0", "r1", "r2");
return addr;
Index: Makefile
===================================================================
--- Makefile (revision 10012)
+++ Makefile (working copy)
@@ -73,7 +73,7 @@
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
More information about the uClibc
mailing list