summaryrefslogtreecommitdiff
path: root/extra
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2002-11-27 23:34:07 +0000
committerEric Andersen <andersen@codepoet.org>2002-11-27 23:34:07 +0000
commitae35d725cf586347b2adb1a6fe4216e70fce16cf (patch)
tree9fcdb86297695c3324e386e483e85db53133b412 /extra
parent44c91e654102116f99f80635c483db49126730e8 (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 'extra')
-rw-r--r--extra/Configs/Config.in17
-rw-r--r--extra/gcc-uClibc/Makefile17
-rw-r--r--extra/gcc-uClibc/gcc-uClibc.c38
-rwxr-xr-xextra/scripts/get-needed-libgcc-objects.sh2
4 files changed, 62 insertions, 12 deletions
diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in
index 089c1b40b..95c5ba7c2 100644
--- a/extra/Configs/Config.in
+++ b/extra/Configs/Config.in
@@ -60,6 +60,23 @@ config LDSO_LDD_SUPPORT
application to function. Disabling this option will makes uClibc's
shared library loader a little bit smaller. Most people will answer Y.
+config UCLIBC_CTOR_DTOR
+ bool "Support global constructors and destructos"
+ default y
+ help
+ If you wish to build uClibc with support for global constructor
+ (ctor) and global destructor (dtor) support, then answer Y here.
+ When ctor/dtor support is enabled, binaries linked with uClibc must
+ also be linked with crtbegin.o and crtend.o which are provided by gcc
+ (the "*startfile:" and "*endfile:" settings in your gcc specs file
+ may need to be adjusted to include these files). This support will
+ also add a small amount of additional size to each binary compiled vs
+ uClibc. If you will be using uClibc with C++, or if you need the gcc
+ __attribute__((constructor)) and __attribute__((destructor)) to work,
+ then you definately want to answer Y here. If you don't need ctors
+ or dtors and want your binaries to be as small as possible, then
+ answer N.
+
config UCLIBC_HAS_THREADS
bool "POSIX Threading Support"
default y
diff --git a/extra/gcc-uClibc/Makefile b/extra/gcc-uClibc/Makefile
index 677b10f3a..1c64f856a 100644
--- a/extra/gcc-uClibc/Makefile
+++ b/extra/gcc-uClibc/Makefile
@@ -1,7 +1,7 @@
# Makefile for building a fake gcc/binutils toolchain
# that simply spoofs the location of the C library
#
-# Copyright (C) 2000,2001 Erik Andersen <andersen@uclibc.org>
+# Copyright (C) 2000-2002 Erik Andersen <andersen@uclibc.org>
#
TOPDIR = ../../
@@ -34,6 +34,11 @@ ifeq ($(strip $(HAS_ELF)),y)
else
@echo "#undef __HAS_ELF__" >> gcc-uClibc.h
endif
+ifeq ($(strip $(UCLIBC_CTOR_DTOR)),y)
+ @echo "#define __UCLIBC_CTOR_DTOR__ 1" >> gcc-uClibc.h
+else
+ @echo "#undef __UCLIBC_CTOR_DTOR__" >> gcc-uClibc.h
+endif
gcc-uClibc: gcc-uClibc.h gcc-uClibc.c
$(NATIVE_CC) $(NATIVE_CFLAGS) -Wl,-s gcc-uClibc.c -o $(TARGET_ARCH)-uclibc-gcc
@@ -50,14 +55,16 @@ install: all
install -d $(PREFIX)$(SYSTEM_DEVEL_PREFIX)/bin;
install -m 755 $(TARGET_ARCH)-uclibc-gcc $(PREFIX)$(SYSTEM_DEVEL_PREFIX)/bin/
install -m 755 $(TARGET_ARCH)-uclibc-ld $(PREFIX)$(SYSTEM_DEVEL_PREFIX)/bin/
- ln -fs $(TARGET_ARCH)-uclibc-gcc $(PREFIX)$(SYSTEM_DEVEL_PREFIX)/bin/$(TARGET_ARCH)-uclibc-g++
- ln -fs $(TARGET_ARCH)-uclibc-gcc $(PREFIX)$(SYSTEM_DEVEL_PREFIX)/bin/$(TARGET_ARCH)-uclibc-c++
ln -fs $(TARGET_ARCH)-uclibc-gcc $(PREFIX)$(SYSTEM_DEVEL_PREFIX)/bin/$(TARGET_ARCH)-uclibc-cc
- ln -fs $(SYSTEM_DEVEL_PREFIX)/bin/$(TARGET_ARCH)-uclibc-gcc $(PREFIX)$(DEVEL_TOOL_PREFIX)/bin/c++
- ln -fs $(SYSTEM_DEVEL_PREFIX)/bin/$(TARGET_ARCH)-uclibc-gcc $(PREFIX)$(DEVEL_TOOL_PREFIX)/bin/g++
ln -fs $(SYSTEM_DEVEL_PREFIX)/bin/$(TARGET_ARCH)-uclibc-gcc $(PREFIX)$(DEVEL_TOOL_PREFIX)/bin/gcc
ln -fs $(SYSTEM_DEVEL_PREFIX)/bin/$(TARGET_ARCH)-uclibc-gcc $(PREFIX)$(DEVEL_TOOL_PREFIX)/bin/cc
ln -fs $(SYSTEM_DEVEL_PREFIX)/bin/$(TARGET_ARCH)-uclibc-ld $(PREFIX)$(DEVEL_TOOL_PREFIX)/bin/ld
+ifeq ($(strip $(UCLIBC_CTOR_DTOR)),y)
+ ln -fs $(TARGET_ARCH)-uclibc-gcc $(PREFIX)$(SYSTEM_DEVEL_PREFIX)/bin/$(TARGET_ARCH)-uclibc-g++
+ ln -fs $(TARGET_ARCH)-uclibc-gcc $(PREFIX)$(SYSTEM_DEVEL_PREFIX)/bin/$(TARGET_ARCH)-uclibc-c++
+ ln -fs $(SYSTEM_DEVEL_PREFIX)/bin/$(TARGET_ARCH)-uclibc-gcc $(PREFIX)$(DEVEL_TOOL_PREFIX)/bin/c++
+ ln -fs $(SYSTEM_DEVEL_PREFIX)/bin/$(TARGET_ARCH)-uclibc-gcc $(PREFIX)$(DEVEL_TOOL_PREFIX)/bin/g++
+endif
for app in addr2line ar as cpp gasp nm objcopy \
objdump ranlib size strings strip; do \
APPNAME=`which $(CROSS)$${app}`; \
diff --git a/extra/gcc-uClibc/gcc-uClibc.c b/extra/gcc-uClibc/gcc-uClibc.c
index 8b7f53e7d..765521eae 100644
--- a/extra/gcc-uClibc/gcc-uClibc.c
+++ b/extra/gcc-uClibc/gcc-uClibc.c
@@ -83,10 +83,12 @@ static char *our_usr_lib_path = "-L"UCLIBC_DEVEL_PREFIX"/lib";
static char static_linking[] = "-static";
static char nostdinc[] = "-nostdinc";
-static char nostdinc_plus[] = "-nostdinc++";
static char nostartfiles[] = "-nostartfiles";
static char nodefaultlibs[] = "-nodefaultlibs";
static char nostdlib[] = "-nostdlib";
+#ifdef __UCLIBC_CTOR_DTOR__
+static char nostdinc_plus[] = "-nostdinc++";
+#endif
extern void *xmalloc(size_t size)
@@ -120,9 +122,8 @@ void xstrcat(char **string, ...)
int main(int argc, char **argv)
{
int use_build_dir = 0, linking = 1, use_static_linking = 0;
- int use_stdinc = 1, use_nostdinc_plus = 0, use_start = 1, use_stdlib = 1, use_pic = 0;
+ int use_stdinc = 1, use_start = 1, use_stdlib = 1, use_pic = 0;
int source_count = 0, use_rpath = 0, verbose = 0;
- int ctor_dtor = 1, cplusplus = 0;
int i, j, k, l, m, n;
char ** gcc_argv;
char ** gcc_argument;
@@ -141,15 +142,19 @@ int main(int argc, char **argv)
char *our_lib_path[2];
char *crt0_path[2];
const char *application_name;
+#ifdef __UCLIBC_CTOR_DTOR__
char *crti_path[2];
char *crtn_path[2];
- char *GPLUSPLUS_BIN = NULL;
int len;
+ int ctor_dtor = 1, cplusplus = 0, use_nostdinc_plus = 0;
+ char *GPLUSPLUS_BIN = NULL;
+#endif
application_name = basename(argv[0]);
if (application_name[0] == '-')
application_name++;
+#ifdef __UCLIBC_CTOR_DTOR__
/* We must use strstr since g++ might be named like a
* cross compiler (i.e. arm-linux-g++). We must also
* search carefully, in case we are searching something
@@ -168,6 +173,7 @@ int main(int argc, char **argv)
cplusplus = 1;
use_nostdinc_plus = 1;
}
+#endif
devprefix = getenv("UCLIBC_DEVEL_PREFIX");
if (!devprefix) {
@@ -193,10 +199,12 @@ int main(int argc, char **argv)
xstrcat(&(crt0_path[0]), devprefix, "/lib/crt0.o", NULL);
xstrcat(&(crt0_path[1]), builddir, "/lib/crt0.o", NULL);
+#ifdef __UCLIBC_CTOR_DTOR__
xstrcat(&(crti_path[0]), devprefix, "/lib/crti.o", NULL);
xstrcat(&(crti_path[1]), builddir, "/lib/crti.o", NULL);
xstrcat(&(crtn_path[0]), devprefix, "/lib/crtn.o", NULL);
xstrcat(&(crtn_path[1]), builddir, "/lib/crtn.o", NULL);
+#endif
xstrcat(&(our_lib_path[0]), "-L", devprefix, "/lib", NULL);
xstrcat(&(our_lib_path[1]), "-L", builddir, "/lib", NULL);
@@ -267,11 +275,14 @@ int main(int argc, char **argv)
} else if (strcmp(nostdlib,argv[i]) == 0) {
use_start = 0;
use_stdlib = 0;
- } else if (strcmp(nostdinc_plus,argv[i]) == 0) {
+ }
+#ifdef __UCLIBC_CTOR_DTOR__
+ else if (strcmp(nostdinc_plus,argv[i]) == 0) {
if (cplusplus==1) {
use_nostdinc_plus = 0;
}
}
+#endif
break;
case 's':
if (strstr(argv[i],static_linking) != NULL) {
@@ -310,10 +321,13 @@ int main(int argc, char **argv)
} else if (strcmp("--uclibc-use-rpath",argv[i]) == 0) {
use_rpath = 1;
argv[i]='\0';
- } else if (strcmp("--uclibc-no-ctors",argv[i]) == 0) {
+ }
+#ifdef __UCLIBC_CTOR_DTOR__
+ else if (strcmp("--uclibc-no-ctors",argv[i]) == 0) {
ctor_dtor = 0;
argv[i]='\0';
}
+#endif
break;
}
} else { /* assume it is an existing source file */
@@ -325,9 +339,11 @@ int main(int argc, char **argv)
gcc_argument = __builtin_alloca(sizeof(char*) * (argc + 20));
i = 0; k = 0;
+#ifdef __UCLIBC_CTOR_DTOR__
if (cplusplus && GPLUSPLUS_BIN)
gcc_argv[i++] = GPLUSPLUS_BIN;
else
+#endif
gcc_argv[i++] = GCC_BIN;
for ( j = 1 ; j < argc ; j++ ) {
@@ -370,6 +386,7 @@ int main(int argc, char **argv)
}
if (use_stdinc && source_count) {
gcc_argv[i++] = nostdinc;
+#ifdef __UCLIBC_CTOR_DTOR__
if (cplusplus) {
char *cppinc;
if (use_nostdinc_plus) {
@@ -382,6 +399,7 @@ int main(int argc, char **argv)
gcc_argv[i++] = "-isystem";
gcc_argv[i++] = cppinc;
}
+#endif
gcc_argv[i++] = "-isystem";
gcc_argv[i++] = uClibc_inc[use_build_dir];
gcc_argv[i++] = "-iwithprefix";
@@ -392,6 +410,7 @@ int main(int argc, char **argv)
if (linking && source_count) {
if (use_start) {
+#ifdef __UCLIBC_CTOR_DTOR__
if (ctor_dtor) {
gcc_argv[i++] = crti_path[use_build_dir];
if (use_pic) {
@@ -400,6 +419,7 @@ int main(int argc, char **argv)
gcc_argv[i++] = LIBGCC_DIR "crtbegin.o" ;
}
}
+#endif
gcc_argv[i++] = crt0_path[use_build_dir];
}
for ( l = 0 ; l < k ; l++ ) {
@@ -413,14 +433,17 @@ int main(int argc, char **argv)
if (libraries[l]) gcc_argv[i++] = libraries[l];
}
if (use_stdlib) {
+#ifdef __UCLIBC_CTOR_DTOR__
if (cplusplus) {
gcc_argv[ i++ ] = "-lstdc++";
gcc_argv[ i++ ] = "-lm";
}
+#endif
gcc_argv[i++] = "-lc";
gcc_argv[i++] = "-lgcc";
//gcc_argv[i++] = "-Wl,--end-group";
}
+#ifdef __UCLIBC_CTOR_DTOR__
if (ctor_dtor) {
if (use_pic) {
gcc_argv[i++] = LIBGCC_DIR "crtendS.o" ;
@@ -429,6 +452,7 @@ int main(int argc, char **argv)
}
gcc_argv[i++] = crtn_path[use_build_dir];
}
+#endif
} else {
for ( l = 0 ; l < k ; l++ ) {
if (gcc_argument[l]) gcc_argv[i++] = gcc_argument[l];
@@ -443,8 +467,10 @@ int main(int argc, char **argv)
fflush(stdout);
}
//no need to free memory from xstrcat because we never return...
+#ifdef __UCLIBC_CTOR_DTOR__
if (cplusplus && GPLUSPLUS_BIN)
return execvp(GPLUSPLUS_BIN, gcc_argv);
else
+#endif
return execvp(GCC_BIN, gcc_argv);
}
diff --git a/extra/scripts/get-needed-libgcc-objects.sh b/extra/scripts/get-needed-libgcc-objects.sh
index 588634c8d..04e6737f9 100755
--- a/extra/scripts/get-needed-libgcc-objects.sh
+++ b/extra/scripts/get-needed-libgcc-objects.sh
@@ -18,7 +18,7 @@
echo Finding missing symbols in libc.a ...
echo " partial linking..."
rm -f libc.ldr
-$LD $LDFLAGS -r -o libc.ldr ../../lib/crt0.o ../../lib/crti.o ../../lib/crtn.o --whole-archive ../libc.a
+$LD $LDFLAGS -r -o libc.ldr $CRTOBJS --whole-archive ../libc.a
if $NM --undefined-only libc.ldr 2>&1 | grep -v "^main$" | grep -v "^_GLOBAL_OFFSET_TABLE_$" | grep -v "_gp_disp" > sym.need ; then
EXIT_WITH_ERROR=0