diff options
author | Eric Andersen <andersen@codepoet.org> | 2002-11-27 23:34:07 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2002-11-27 23:34:07 +0000 |
commit | ae35d725cf586347b2adb1a6fe4216e70fce16cf (patch) | |
tree | 9fcdb86297695c3324e386e483e85db53133b412 /libc | |
parent | 44c91e654102116f99f80635c483db49126730e8 (diff) |
Make support for global constructors and global destructors be
configurable, so people who do not need or want ctor/dtor support
can disable it and make their binaries a little bit smaller.
-Erik
Diffstat (limited to 'libc')
-rw-r--r-- | libc/Makefile | 9 | ||||
-rw-r--r-- | libc/sysdeps/linux/arm/crt0.S | 4 | ||||
-rw-r--r-- | libc/sysdeps/linux/common/Makefile | 15 | ||||
-rw-r--r-- | libc/sysdeps/linux/i386/crt0.S | 9 | ||||
-rw-r--r-- | libc/sysdeps/linux/mips/crt0.S | 4 | ||||
-rw-r--r-- | libc/sysdeps/linux/sh/crt0.S | 38 |
6 files changed, 68 insertions, 11 deletions
diff --git a/libc/Makefile b/libc/Makefile index 595f69e4a..4a5110f0e 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -30,6 +30,12 @@ TOPDIR=../ include $(TOPDIR)Rules.mak +ifeq ($(strip $(UCLIBC_CTOR_DTOR)),y) +CRTOBJS="../../lib/crti.o ../../lib/crt0.o ../../lib/crtn.o" +else +CRTOBJS="../../lib/crt0.o" +endif + DIRS = misc pwd_grp stdio string termios inet signal stdlib sysdeps unistd # Check if the target architecture has a version script for @@ -49,7 +55,8 @@ shared: $(TOPDIR)lib/$(LIBNAME) @rm -rf tmp @mkdir tmp $(AR) rv ./tmp/libgcc-need.a - @(cd tmp && CC=$(CC) LD=$(LD) LDFLAGS=$(CPU_LDFLAGS-y) NM=$(NM) AR=$(AR) LIBGCC=$(LIBGCC) \ + @(cd tmp && CC=$(CC) LD=$(LD) LDFLAGS=$(CPU_LDFLAGS-y) NM=$(NM) AR=$(AR) \ + LIBGCC=$(LIBGCC) CRTOBJS=$(CRTOBJS) \ /bin/sh $(TOPDIR)../extra/scripts/get-needed-libgcc-objects.sh) $(LD) $(LDFLAGS) $(VERSION_SCRIPT) -soname=$(SHARED_MAJORNAME) -o $(SHARED_FULLNAME) \ --whole-archive ./tmp/libgcc-need.a $(LIBNAME) --no-whole-archive \ diff --git a/libc/sysdeps/linux/arm/crt0.S b/libc/sysdeps/linux/arm/crt0.S index ad4865cc1..a930ff3f2 100644 --- a/libc/sysdeps/linux/arm/crt0.S +++ b/libc/sysdeps/linux/arm/crt0.S @@ -80,6 +80,7 @@ _start: ldr r2,[sp, #8] #endif +#ifdef __UCLIBC_CTOR_DTOR__ /* Store the address of _init in r3 as an argument to main() */ ldr r3, =_init @@ -89,6 +90,9 @@ _start: /* Ok, now run uClibc's main() -- shouldn't return */ bl __uClibc_start_main +#else + bl __uClibc_main +#endif /* Crash if somehow `exit' returns anyways. */ bl abort diff --git a/libc/sysdeps/linux/common/Makefile b/libc/sysdeps/linux/common/Makefile index f66c09f31..8e0ed9485 100644 --- a/libc/sysdeps/linux/common/Makefile +++ b/libc/sysdeps/linux/common/Makefile @@ -24,11 +24,6 @@ TOPDIR=../../../../ include $(TOPDIR)Rules.mak -SAFECFLAGS=$(WARNINGS) $(CPU_CFLAGS-y) $(OPTIMIZATION) -fno-builtin -ifeq ($(strip $(DOPIC)),y) -SAFECFLAGS+=-fPIC -endif - CSRC= waitpid.c getdnnm.c gethstnm.c getcwd.c \ mkfifo.c setegid.c wait.c getpagesize.c seteuid.c \ wait3.c setpgrp.c getdtablesize.c create_module.c ptrace.c \ @@ -44,13 +39,21 @@ COBJS=$(patsubst %.c,%.o, $(CSRC)) MSRC=syscalls.c MOBJ=$(shell ./list_syscalls.sh) +ifeq ($(strip $(UCLIBC_CTOR_DTOR)),y) +CTOR_TARGETS=$(TOPDIR)lib/crti.o $(TOPDIR)lib/crtn.o +SAFECFLAGS=$(WARNINGS) $(CPU_CFLAGS-y) $(OPTIMIZATION) -fno-builtin +ifeq ($(strip $(DOPIC)),y) +SAFECFLAGS+=-fPIC +endif +endif + OBJ=$(COBJS) $(MOBJ) all: $(STR_SYSCALLS) $(OBJ) $(LIBC) $(LIBC): ar-target -ar-target: $(OBJ) $(TOPDIR)lib/crti.o $(TOPDIR)lib/crtn.o +ar-target: $(OBJ) $(CTOR_TARGETS) $(AR) $(ARFLAGS) $(LIBC) $(OBJ) (cd $(TOPDIR)lib/; ln -fs crt0.o crt1.o) diff --git a/libc/sysdeps/linux/i386/crt0.S b/libc/sysdeps/linux/i386/crt0.S index 97f1fde63..be66b9a2d 100644 --- a/libc/sysdeps/linux/i386/crt0.S +++ b/libc/sysdeps/linux/i386/crt0.S @@ -61,6 +61,7 @@ _start: pushl %ebp /* callers %ebp (frame pointer) */ movl %esp,%ebp /* mark callers stack frame as invalid */ +#ifdef __UCLIBC_CTOR_DTOR__ /* Push .init and .fini arguments to __uClibc_start_main() on the stack */ pushl $_fini pushl $_init @@ -72,6 +73,14 @@ _start: /* Ok, now run uClibc's main() -- shouldn't return */ call __uClibc_start_main +#else + /* Push envp, argc, and argc arguments to __uClibc_start_main() on the stack */ + pushl %eax /* Environment pointer */ + pushl %ebx /* Argument pointer */ + pushl %ecx /* And the argument count */ + + call __uClibc_main +#endif /* Crash if somehow `exit' returns anyways. */ hlt diff --git a/libc/sysdeps/linux/mips/crt0.S b/libc/sysdeps/linux/mips/crt0.S index fd1f4b9d4..052229819 100644 --- a/libc/sysdeps/linux/mips/crt0.S +++ b/libc/sysdeps/linux/mips/crt0.S @@ -30,6 +30,7 @@ __start: addu a2, a0, 1 /* argv[0] program name (ordinal->cardinal) */ sll a2, a2, 2 /* multiple by 4 */ add a2, a2, a1 /* a2 now points to start of envp */ +#ifdef __UCLIBC_CTOR_DTOR__ la a3, _init /* a3 is address of _init */ addiu sp, sp, -24 /* 16 + 4 rounded up to multiple of 8 */ /* multiple of 8 for longlong/double support */ @@ -38,6 +39,9 @@ __start: /* Ok, now run uClibc's main() -- shouldn't return */ jal __uClibc_start_main +#else + jal __uClibc_main +#endif addiu sp, sp, 24 /* undo stack argument */ diff --git a/libc/sysdeps/linux/sh/crt0.S b/libc/sysdeps/linux/sh/crt0.S index e74ae86c4..a27775ed0 100644 --- a/libc/sysdeps/linux/sh/crt0.S +++ b/libc/sysdeps/linux/sh/crt0.S @@ -48,6 +48,34 @@ _start: mov.l @r15+,r4 mov r15, r5 +#if ! defined __UCLIBC_CTOR_DTOR__ + /* + * Setup the value for the environment pointer: + * r6 = (argc + 1) * 4 + * r6 += argv (in delay slot) + */ + mov r4,r6 + add #1,r6 + shll2 r6 + add r5, r6 + + /* jump to __uClibc_main (argc, argv, envp) */ + mov.l L_main, r0 + jsr @r0 + nop /* delay slot */ + + /* We should not get here. */ + mov.l L_abort, r0 + jmp @r0 + nop + +_start_end: + .align 2 + +L_main: + .long __uClibc_main /* in libuClibc.*.so */ + +#else /* __UCLIBC_CTOR_DTOR__ */ /* Push the finip argument to __uClibc_start_main() onto the stack */ mov.l L_fini,r6 mov.l r6,@-r15 @@ -72,10 +100,12 @@ _start: mov.l L_abort, r0 jmp @r0 nop - _start_end: .align 2 +L_main: + .long __uClibc_start_main /* in libuClibc.*.so */ + .weak _init .type _init,@function _init: @@ -87,13 +117,13 @@ _init: .weak _fini .set _fini,_init -L_main: - .long __uClibc_start_main /* in libuClibc.*.so */ - L_init: .long _init L_fini: .long _fini + +#endif + L_abort: .long abort |