* elf/Makefile (tests): Uncomment tst-array[123].

* Makeconfig (CPPFLAGS-.oS): Add -DLIBC_NONSHARED=1.
	* csu/elf-init.c: New file.
	* csu/Makefile (routines, static-only-routines): Add elf-init.
	* sysdeps/alpha/elf/start.S: Use __libc_csu_init in place of _init
	and __libc_csu_fini in place of _fini.
	* sysdeps/arm/elf/start.S: Likewise.
	* sysdeps/cris/elf/start.S: Likewise.
	* sysdeps/hppa/elf/start.S: Likewise.
	* sysdeps/i386/elf/start.S: Likewise.
	* sysdeps/ia64/elf/start.S: Likewise.
	* sysdeps/m68k/elf/start.S: Likewise.
	* sysdeps/mach/hurd/powerpc/static-start.S: Likewise.
	* sysdeps/mips/elf/start.S: Likewise.
	* sysdeps/powerpc/powerpc32/elf/start.S: Likewise.
	* sysdeps/powerpc/powerpc64/elf/start.S: Likewise.
	* sysdeps/s390/s390-32/elf/start.S: Likewise.
	* sysdeps/s390/s390-64/elf/start.S: Likewise.
	* sysdeps/sh/elf/start.S: Likewise.
	* sysdeps/sparc/sparc32/elf/start.S: Likewise.
	* sysdeps/sparc/sparc64/elf/start.S: Likewise.
	* sysdeps/x86_64/elf/start.S: Likewise.
This commit is contained in:
Roland McGrath 2002-12-09 20:37:37 +00:00
parent 58a851f108
commit 06b31ad3ef
22 changed files with 193 additions and 78 deletions

View File

@ -1,5 +1,28 @@
2002-12-08 Roland McGrath <roland@redhat.com>
* elf/Makefile (tests): Uncomment tst-array[123].
* Makeconfig (CPPFLAGS-.oS): Add -DLIBC_NONSHARED=1.
* csu/elf-init.c: New file.
* csu/Makefile (routines, static-only-routines): Add elf-init.
* sysdeps/alpha/elf/start.S: Use __libc_csu_init in place of _init
and __libc_csu_fini in place of _fini.
* sysdeps/arm/elf/start.S: Likewise.
* sysdeps/cris/elf/start.S: Likewise.
* sysdeps/hppa/elf/start.S: Likewise.
* sysdeps/i386/elf/start.S: Likewise.
* sysdeps/ia64/elf/start.S: Likewise.
* sysdeps/m68k/elf/start.S: Likewise.
* sysdeps/mach/hurd/powerpc/static-start.S: Likewise.
* sysdeps/mips/elf/start.S: Likewise.
* sysdeps/powerpc/powerpc32/elf/start.S: Likewise.
* sysdeps/powerpc/powerpc64/elf/start.S: Likewise.
* sysdeps/s390/s390-32/elf/start.S: Likewise.
* sysdeps/s390/s390-64/elf/start.S: Likewise.
* sysdeps/sh/elf/start.S: Likewise.
* sysdeps/sparc/sparc32/elf/start.S: Likewise.
* sysdeps/sparc/sparc64/elf/start.S: Likewise.
* sysdeps/x86_64/elf/start.S: Likewise.
* sysdeps/pthread/aio_notify.c (notify_func_wrapper): Take a malloc'd
struct containing function ptr and value, free it.
(__aio_notify_only): Allocate that and copy values from SIGEV into it.

View File

@ -711,7 +711,7 @@ object-suffixes-for-libc += .oS
# shared objects. We don't want to use CFLAGS-os because users may, for
# example, make that processor-specific.
CFLAGS-.oS = $(CFLAGS-.o) $(pic-ccflag)
CPPFLAGS-.oS = $(CPPFLAGS-.o) -DPIC
CPPFLAGS-.oS = $(CPPFLAGS-.o) -DPIC -DLIBC_NONSHARED=1
libtype.oS = lib%_nonshared.a
endif

View File

@ -27,9 +27,10 @@
subdir := csu
routines = init-first libc-start $(libc-init) sysdep version check_fds \
libc-tls
libc-tls elf-init
aux = errno
elide-routines.os = libc-tls
static-only-routines = elf-init
csu-dummies = $(filter-out $(start-installed-name),crt1.o Mcrt1.o)
extra-objs = start.o gmon-start.o \
$(start-installed-name) g$(start-installed-name) $(csu-dummies)

82
csu/elf-init.c Normal file
View File

@ -0,0 +1,82 @@
/* Startup support for ELF initializers/finalizers in the main executable.
Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <stddef.h>
#ifdef HAVE_INITFINI_ARRAY
/* These magic symbols are provided by the linker. */
extern void (*__preinit_array_start []) (void);
extern void (*__preinit_array_end []) (void);
extern void (*__init_array_start []) (void);
extern void (*__init_array_end []) (void);
extern void (*__fini_array_start []) (void);
extern void (*__fini_array_end []) (void);
#endif
/* These function symbols are provided for the .init/.fini section entry
points automagically by the linker. */
extern void _init (void);
extern void _fini (void);
/* These functions are passed to __libc_start_main by the startup code.
These get statically linked into each program. For dynamically linked
programs, this module will come from libc_nonshared.a and differs from
the libc.a module in that it doesn't call the preinit array. */
void
__libc_csu_init (void)
{
#ifdef HAVE_INITFINI_ARRAY
/* For dynamically linked executables the preinit array is executed by
the dynamic linker (before initializing any shared object. */
# ifndef LIBC_NONSHARED
/* For static executables, preinit happens rights before init. */
{
const size_t size = __preinit_array_end - __preinit_array_start;
size_t i;
for (i = 0; i < size; i++)
(*__preinit_array_start [i]) ();
}
# endif
#endif
_init ();
#ifdef HAVE_INITFINI_ARRAY
{
const size_t size = __init_array_end - __init_array_start;
size_t i;
for (i = 0; i < size; i++)
(*__init_array_start [i]) ();
}
#endif
}
void
__libc_csu_fini (void)
{
#ifdef HAVE_INITFINI_ARRAY
size_t i = __fini_array_end - __fini_array_start;
while (i-- > 0)
(*__fini_array_start [i]) ();
#endif
_fini ();
}

View File

@ -118,7 +118,7 @@ endif
tests = tst-tls1 tst-tls2 tst-tls9
ifeq (yes,$(have-initfini-array))
#tests += tst-array1 tst-array2 tst-array3
tests += tst-array1 tst-array2 tst-array3
endif
ifeq (yes,$(build-static))
tests-static = tst-tls1-static tst-tls2-static

View File

@ -1,5 +1,5 @@
/* Startup code for Alpha/ELF.
Copyright (C) 1993,1995,1996,1997,1998,2000,2001 Free Software Foundation, Inc.
Copyright (C) 1993,1995,1996,1997,1998,2000,2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Richard Henderson <rth@tamu.edu>
@ -40,8 +40,8 @@ _start:
lda a2, 24(sp) /* get argv */
/* Load address of our own entry points to .fini and .init. */
lda a3, _init
lda a4, _fini
lda a3, __libc_csu_init
lda a4, __libc_csu_fini
/* Store address of the shared library termination function. */
mov v0, a5

View File

@ -1,5 +1,5 @@
/* Startup code for ARM & ELF
Copyright (C) 1995, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
Copyright (C) 1995, 1996, 1997, 1998, 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@ -54,12 +54,12 @@ _start:
/* Push the last arguments to main() onto the stack */
stmfd sp!, {a1}
ldr a1, =_fini
ldr a1, =__libc_csu_fini
stmfd sp!, {a1}
/* Set up the other arguments for main() that go in registers */
ldr a1, =main
ldr a4, =_init
ldr a4, =__libc_csu_init
/* __libc_start_main (main, argc, argv, init, fini, rtld_fini) */

View File

@ -1,5 +1,5 @@
/* Startup code compliant to the ELF CRIS ABI (to-be-written).
Copyright (C) 2001 Free Software Foundation, Inc.
Copyright (C) 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@ -89,15 +89,15 @@ _start:
move.d pc,r0
sub.d .:GOTOFF,r0
move.d _init:PLTG,r13
move.d __libc_csu_init:PLTG,r13
add.d r0,r13
move.d _fini:PLTG,r9
move.d __libc_csu_fini:PLTG,r9
add.d r0,r9
move.d main:PLTG,r10
add.d r0,r10
#else
move.d _init,r13
move.d _fini,r9
move.d __libc_csu_init,r13
move.d __libc_csu_fini,r9
move.d main,r10
#endif
push r9

View File

@ -1,3 +1,21 @@
/* ELF startup code for HPPA.
Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
.text
@ -6,11 +24,8 @@
.import main, code
.import $global$, data
.import __libc_start_main, code
.import _fini, code
.import _init, code
.import __libc_csu_fini, code
.import __libc_csu_init, code
.globl _start
.export _start, ENTRY
@ -33,12 +48,12 @@ _start:
stw %r23, -56(%sp)
/* void (*init) (void) */
ldil LP%_init, %r23
ldo RP%_init(%r23), %r23
ldil LP%__libc_csu_init, %r23
ldo RP%__libc_csu_init(%r23), %r23
/* void (*fini) (void) */
ldil LP%_fini, %r22
ldo RP%_fini(%r22), %r22
ldil LP%__libc_csu_fini, %r22
ldo RP%__libc_csu_fini(%r22), %r22
stw %r22, -52(%sp)
/* void *stack_end */

View File

@ -1,5 +1,5 @@
/* Startup code compliant to the ELF i386 ABI.
Copyright (C) 1995,1996,1997,1998,2000,2001 Free Software Foundation, Inc.
Copyright (C) 1995,1996,1997,1998,2000,2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@ -68,8 +68,8 @@ _start:
termination function. */
/* Push address of our own entry points to .fini and .init. */
pushl $_fini
pushl $_init
pushl $__libc_csu_fini
pushl $__libc_csu_init
pushl %ecx /* Push second argument: argv. */
pushl %esi /* Push first argument: argc. */

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
/* Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Written by Jes Sorensen, <Jes.Sorensen@cern.ch>, April 1999.
@ -64,13 +64,13 @@ _start:
{
addl r11 = @ltoff(__libc_ia64_register_backing_store_base), gp
addl out0 = @ltoff(@fptr(main)), gp
addl out3 = @ltoff(@fptr(_init)), gp
addl out3 = @ltoff(@fptr(__libc_csu_init)), gp
;;
}
{ .mmi
ld8 r3 = [r11] /* pointer to __libc_ia64_register_backing_store_base */
ld8 out0 = [out0] /* pointer to `main' function descriptor */
addl out4 = @ltoff(@fptr(_fini)), gp
addl out4 = @ltoff(@fptr(__libc_csu_fini)), gp
;;
}
{ .mmi

View File

@ -1,5 +1,5 @@
/* Startup code compliant to the ELF m68k ABI.
Copyright (C) 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
Copyright (C) 1996, 1997, 1998, 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@ -60,8 +60,8 @@ _start:
/* Push the address of our own entry points to `.fini' and
`.init'. */
pea _fini
pea _init
pea __libc_csu_fini
pea __libc_csu_init
pea (%a0) /* Push second argument: argv. */
move.l %d0, -(%sp) /* Push first argument: argc. */

View File

@ -1,5 +1,5 @@
/* Startup code for statically linked Hurd/PowerPC binaries.
Copyright (C) 1998,2001 Free Software Foundation, Inc.
Copyright (C) 1998,2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@ -22,13 +22,13 @@
/* These are the various addresses we require. */
.section ".rodata"
.align 2
weak_extern(_init)
weak_extern(_fini)
weak_extern(__libc_csu_init)
weak_extern(__libc_csu_fini)
L(start_addresses):
.long _SDA_BASE_
.long JUMPTARGET(main)
.long JUMPTARGET(_init)
.long JUMPTARGET(_fini)
.long JUMPTARGET(__libc_csu_init)
.long JUMPTARGET(__libc_csu_fini)
ASM_SIZE_DIRECTIVE(L(start_addresses))
.section ".text"

View File

@ -83,8 +83,8 @@ ENTRY_POINT:
the stack is aligned to double words (8 bytes). */
and $29, 0xfffffff8
subu $29, 32
la $7, _init /* init */
la $8, _fini
la $7, __libc_csu_init /* init */
la $8, __libc_csu_fini
sw $8, 16($29) /* fini */
sw $2, 20($29) /* rtld_fini */
sw $29, 24($29) /* stack_end */

View File

@ -1,5 +1,5 @@
/* Startup code for programs linked with GNU libc.
Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@ -23,13 +23,11 @@
/* These are the various addresses we require. */
.section ".rodata"
.align 2
weak_extern(_init)
weak_extern(_fini)
L(start_addresses):
.long _SDA_BASE_
.long JUMPTARGET(BP_SYM (main))
.long JUMPTARGET(_init)
.long JUMPTARGET(_fini)
.long JUMPTARGET(__libc_csu_init)
.long JUMPTARGET(__libc_csu_fini)
ASM_SIZE_DIRECTIVE(L(start_addresses))
.section ".text"

View File

@ -23,16 +23,12 @@
/* These are the various addresses we require. */
.section ".rodata"
.align 3
weak_extern(_init)
weak_extern(_fini)
weak_extern(._init)
weak_extern(._fini)
L(start_addresses):
.quad 0 /* was _SDA_BASE_ but not in 64-bit ABI*/
/* function descriptors so don't need JUMPTARGET */
.quad BP_SYM(main)
.quad _init
.quad _fini
.quad __libc_csu_init
.quad __libc_csu_fini
ASM_SIZE_DIRECTIVE(L(start_addresses))

View File

@ -1,5 +1,5 @@
/* Startup code compliant to the ELF s390 ABI.
Copyright (C) 2000, 2001 Free Software Foundation, Inc.
Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
This file is part of the GNU C Library.
@ -63,8 +63,8 @@ _start:
*/
stm %r14,%r15,96(%r15) # store rtld_fini/stack_end to parameter area
la %r7,96(%r15)
l %r6,.L2-.Llit(%r13) # load pointer to _fini
l %r5,.L1-.Llit(%r13) # load pointer to _init
l %r6,.L2-.Llit(%r13) # load pointer to __libc_csu_fini
l %r5,.L1-.Llit(%r13) # load pointer to __libc_csu_init
l %r2,.L3-.Llit(%r13) # load pointer to main
/* ok, now branch to the libc main routine */
@ -75,8 +75,8 @@ _start:
.word 0
.Llit:
.L1: .long _init
.L2: .long _fini
.L1: .long __libc_csu_init
.L2: .long __libc_csu_fini
.L3: .long main
.L4: .long __libc_start_main

View File

@ -1,5 +1,5 @@
/* Startup code compliant to the 64 bit S/390 ELF ABI.
Copyright (C) 2001 Free Software Foundation, Inc.
Copyright (C) 2001, 2002 Free Software Foundation, Inc.
Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
This file is part of the GNU C Library.
@ -59,8 +59,8 @@ _start:
*/
stmg %r14,%r15,160(%r15) # store rtld_fini/stack_end to parameter area
la %r7,160(%r15)
larl %r6,_fini # load pointer to _fini
larl %r5,_init # load pointer to _init
larl %r6,__libc_csu_fini # load pointer to __libc_csu_fini
larl %r5,__libc_csu_init # load pointer to __libc_csu_init
larl %r2,main # load pointer to main
/* Ok, now branch to the libc main routine. */

View File

@ -1,5 +1,5 @@
/* Startup code for SH & ELF.
Copyright (C) 1999, 2001 Free Software Foundation, Inc.
Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@ -75,9 +75,9 @@ _start:
L_main:
.long main
L_init:
.long _init
.long __libc_csu_init
L_fini:
.long _fini
.long __libc_csu_fini
L_libc_start_main:
.long __libc_start_main
L_abort:

View File

@ -1,5 +1,5 @@
/* Startup code for elf32-sparc
Copyright (C) 1997, 1998 Free Software Foundation, Inc.
Copyright (C) 1997, 1998, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Richard Henderson <richard@gnu.ai.mit.edu>, 1997.
@ -39,11 +39,11 @@ _start:
/* Load the addresses of the user entry points. */
sethi %hi(main), %o0
sethi %hi(_init), %o3
sethi %hi(_fini), %o4
sethi %hi(__libc_csu_init), %o3
sethi %hi(__libc_csu_fini), %o4
or %o0, %lo(main), %o0
or %o3, %lo(_init), %o3
or %o4, %lo(_fini), %o4
or %o3, %lo(__libc_csu_init), %o3
or %o4, %lo(__libc_csu_fini), %o4
/* When starting a binary via the dynamic linker, %g1 contains the
address of the shared library termination function, which will be

View File

@ -1,5 +1,5 @@
/* Startup code for elf64-sparc
Copyright (C) 1997, 1998 Free Software Foundation, Inc.
Copyright (C) 1997, 1998, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Richard Henderson <richard@gnu.ai.mit.edu>, 1997.
@ -40,11 +40,11 @@ _start:
/* Load the addresses of the user entry points. */
sethi %hi(main), %o0
sethi %hi(_init), %o3
sethi %hi(_fini), %o4
sethi %hi(__libc_csu_init), %o3
sethi %hi(__libc_csu_fini), %o4
or %o0, %lo(main), %o0
or %o3, %lo(_init), %o3
or %o4, %lo(_fini), %o4
or %o3, %lo(__libc_csu_init), %o3
or %o4, %lo(__libc_csu_fini), %o4
/* When starting a binary via the dynamic linker, %g1 contains the
address of the shared library termination function, which will be

View File

@ -1,5 +1,5 @@
/* Startup code compliant to the ELF x86-64 ABI.
Copyright (C) 2001 Free Software Foundation, Inc.
Copyright (C) 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Andreas Jaeger <aj@suse.de>, 2001.
@ -75,8 +75,8 @@ _start:
pushq %rsp
/* Pass address of our own entry points to .fini and .init. */
movq $_fini, %r8
movq $_init, %rcx
movq $__libc_csu_fini, %r8
movq $__libc_csu_init, %rcx
movq $BP_SYM (main), %rdi