diff options
author | Peter S. Mazinger <ps.m@gmx.net> | 2005-10-27 22:58:52 +0000 |
---|---|---|
committer | Peter S. Mazinger <ps.m@gmx.net> | 2005-10-27 22:58:52 +0000 |
commit | 237277e9a8133c64026b736b1427141e71655330 (patch) | |
tree | 43d2f15804d486c56d7fba35c97b6d38ccc9fc6d /libc | |
parent | 6e3a0044cc3b4d6f3f13f2d9d1d0a83d60ca800f (diff) |
Moved guard_setup to dl-osinfo.h (used commonly by ldso and libc). Renamed to _dl_setup_stack_chk_guard, as in glibc. SSP requires now binutils-2.16.1 and newer. Add NOT_IN_libc/IS_IN_libc. Began using -DSHARED in uClibc_main.c, there are more candidates in there. Move back dl_protect_relro to it's earlier place.
Diffstat (limited to 'libc')
-rw-r--r-- | libc/Makefile.in | 14 | ||||
-rw-r--r-- | libc/misc/file/Makefile.in | 3 | ||||
-rw-r--r-- | libc/misc/internals/Makefile.in | 15 | ||||
-rw-r--r-- | libc/misc/internals/__uClibc_main.c | 57 | ||||
-rw-r--r-- | libc/stdlib/Makefile.in | 13 | ||||
-rw-r--r-- | libc/sysdeps/linux/common/Makefile | 1 | ||||
-rw-r--r-- | libc/sysdeps/linux/common/Makefile.in | 5 | ||||
-rw-r--r-- | libc/sysdeps/linux/common/dl-osinfo.h | 64 | ||||
-rw-r--r-- | libc/sysdeps/linux/common/ssp.c | 2 |
9 files changed, 104 insertions, 70 deletions
diff --git a/libc/Makefile.in b/libc/Makefile.in index 33a1070d9..62a522066 100644 --- a/libc/Makefile.in +++ b/libc/Makefile.in @@ -39,19 +39,7 @@ VERSION_SCRIPT:=${shell if [ -f $(libc_DIR)/sysdeps/linux/$(TARGET_ARCH)/libc.ma EXTRA_LINK_OPTS:=$(VERSION_SCRIPT) -init __uClibc_init EXTRA_LINK_LIBS:=$(libc_OUT)/misc/internals/interp.os $(top_builddir)lib/$(UCLIBC_LDSO) $(LIBGCC) # $(LDADD_LIBFLOAT) -ifeq ($(DOPIC),y) -libc-a-y: $(libc-a-pic-y) -else -libc-a-y: $(libc-a-y) -endif - -libc-so-y: $(libc-so-y) - -crt-y: $(crt-y) -other-y: $(other-y) - objclean-y+=libc_clean lib-a-y+=$(top_builddir)lib/libc.a -lib-a-pic-y+=$(top_builddir)lib/libc.a -lib-so-y+=$(top_builddir)lib/libc.so $(top_builddir)lib/$(NONSHARED_LIBNAME) crt-y +lib-so-y+=$(top_builddir)lib/libc.so $(top_builddir)lib/$(NONSHARED_LIBNAME) crt-y other-y diff --git a/libc/misc/file/Makefile.in b/libc/misc/file/Makefile.in index 76eff7868..58da3e2a3 100644 --- a/libc/misc/file/Makefile.in +++ b/libc/misc/file/Makefile.in @@ -19,7 +19,8 @@ libc-a-y+=$(MISC_FILE_OBJ) libc-a-pic-y+=$(MISC_FILE_OBJ:.o=.os) libc-so-y+=$(MISC_FILE_OBJ:.o=.os) -libc-multi-y+=$(MISC_FILE_SRC) +libc-multi-y+=$(MISC_FILE_DIR)/lockf.c +libc-nomulti-y+=$(MISC_FILE_OUT)/lockf64.o objclean-y+=misc_file_objclean diff --git a/libc/misc/internals/Makefile.in b/libc/misc/internals/Makefile.in index de611323e..a9dc2634f 100644 --- a/libc/misc/internals/Makefile.in +++ b/libc/misc/internals/Makefile.in @@ -8,7 +8,7 @@ CFLAGS-__uClibc_main.c=$(SSP_DISABLE_FLAGS) -CSRC:=__uClibc_main.c tempname.c errno.c __errno_location.c __h_errno_location.c +CSRC:=tempname.c errno.c __errno_location.c __h_errno_location.c MISC_INTERNALS_DIR:=$(top_srcdir)libc/misc/internals MISC_INTERNALS_OUT:=$(top_builddir)libc/misc/internals @@ -16,7 +16,7 @@ MISC_INTERNALS_OUT:=$(top_builddir)libc/misc/internals MISC_INTERNALS_SRC:=$(patsubst %.c,$(MISC_INTERNALS_DIR)/%.c,$(CSRC)) MISC_INTERNALS_OBJ:=$(patsubst %.c,$(MISC_INTERNALS_OUT)/%.o,$(CSRC)) -MISC_INTERNALS_OBJS:=$(MISC_INTERNALS_OBJ) $(MISC_INTERNALS_OUT)/static.o +STATIC_SRC:=__uClibc_main.c static.c $(MISC_INTERNALS_OUT)/interp.c: $(MISC_INTERNALS_DIR)/Makefile.in echo "/* Force shared libraries to know about the correct library loader */" > $@ @@ -26,16 +26,15 @@ $(MISC_INTERNALS_OUT)/interp.c: $(MISC_INTERNALS_DIR)/Makefile.in "(\".interp\"))) =\""$(SHARED_LIB_LOADER_PREFIX)/$(UCLIBC_LDSO)"\";" >> $@ echo "#endif" >> $@ -libc-a-y+=$(MISC_INTERNALS_OBJS) -libc-a-pic-y+=$(MISC_INTERNALS_OBJS:.o=.os) -# this is OBJ, not OBJS !!!, static does not go into .so +libc-a-y+=$(MISC_INTERNALS_OBJ) libc-so-y+=$(MISC_INTERNALS_OBJ:.o=.os) +libc-shared-y+=$(MISC_INTERNALS_OUT)/__uClibc_main.oS +libc-static-y+=$(patsubst %.c,$(MISC_INTERNALS_OUT)/%.o,$(STATIC_SRC)) other-y+=$(MISC_INTERNALS_OUT)/interp.os -libc-multi-y+=$(filter-out $(MISC_INTERNALS_DIR)/__uClibc_main.c,$(MISC_INTERNALS_SRC)) -libc-nomulti-y+=$(MISC_INTERNALS_OUT)/__uClibc_main.o +libc-multi-y+=$(MISC_INTERNALS_SRC) objclean-y+=misc_internals_objclean misc_internals_objclean: - $(RM) $(MISC_INTERNALS_OUT)/{*.{o,os},interp.c} + $(RM) $(MISC_INTERNALS_OUT)/{*.{o,os,oS},interp.c} diff --git a/libc/misc/internals/__uClibc_main.c b/libc/misc/internals/__uClibc_main.c index 1f2061e58..e7c2c4abf 100644 --- a/libc/misc/internals/__uClibc_main.c +++ b/libc/misc/internals/__uClibc_main.c @@ -25,15 +25,21 @@ #include <fcntl.h> #include <sys/stat.h> #include <sys/sysmacros.h> +#ifndef SHARED +/* probably all the weak_*function stuff below should be in here */ #ifdef __UCLIBC_HAS_SSP__ -#include <ssp-internal.h> +#include <dl-osinfo.h> +#ifndef THREAD_SET_STACK_GUARD +/* Only exported for architectures that don't store the stack guard canary + * in thread local area. */ #include <stdint.h> - /* for gcc-4.1 non-TLS */ uintptr_t __stack_chk_guard attribute_relro; /* for gcc-3.x + Etoh ssp */ strong_alias(__stack_chk_guard,__guard) #endif +#endif +#endif /* * Prototypes. @@ -49,10 +55,6 @@ extern void weak_function _locale_init(void); extern void weak_function __pthread_initialize_minimal(void); #endif - - - - /* * Declare the __environ global variable and create a weak alias environ. * Note: Apparently we must initialize __environ to ensure that the weak @@ -64,7 +66,6 @@ weak_alias(__environ, environ); size_t __pagesize = 0; const char *__progname = 0; - #ifndef O_NOFOLLOW # define O_NOFOLLOW 0 #endif @@ -110,36 +111,6 @@ static int __check_suid(void) return 1; } -#ifdef __UCLIBC_HAS_SSP__ -static __always_inline uintptr_t _dl_guard_setup(void) -{ - uintptr_t ret; -#ifndef __SSP_QUICK_CANARY__ - { - int fd = OPEN("/dev/urandom", O_RDONLY); - if (fd >= 0) { - size_t size = READ(fd, &ret, sizeof(ret)); - CLOSE(fd); - if (size == (size_t) sizeof(ret)) - return ret; - } - } -#endif /* ifndef __SSP_QUICK_CANARY__ */ - - /* Start with the "terminator canary". */ - ret = 0xFF0A0D00UL; - - /* Everything failed? Or we are using a weakened model of the - * terminator canary */ - { - struct timeval tv; - if (GETTIMEOFDAY(&tv, NULL) != (-1)) - ret ^= tv.tv_usec ^ tv.tv_sec; - } - return ret; -} -#endif /* __UCLIBC_HAS_SSP__ */ - /* __uClibc_init completely initialize uClibc so it is ready to use. * * On ELF systems (with a dynamic loader) this function must be called @@ -174,10 +145,16 @@ void __uClibc_init(void) __pthread_initialize_minimal(); #endif -#ifdef __UCLIBC_HAS_SSP__ - uintptr_t stack_chk_guard = _dl_guard_setup(); - /* for gcc-4.1 non-TLS */ +#ifndef SHARED +# ifdef __UCLIBC_HAS_SSP__ + /* Set up the stack checker's canary. */ + uintptr_t stack_chk_guard = _dl_setup_stack_chk_guard(); +# ifdef THREAD_SET_STACK_GUARD + THREAD_SET_STACK_GUARD (stack_chk_guard); +# else __stack_chk_guard = stack_chk_guard; +# endif +# endif #endif #ifdef __UCLIBC_HAS_LOCALE__ diff --git a/libc/stdlib/Makefile.in b/libc/stdlib/Makefile.in index 3b00c8115..236d20cda 100644 --- a/libc/stdlib/Makefile.in +++ b/libc/stdlib/Makefile.in @@ -106,15 +106,18 @@ $(STDLIB_MOBJ1x) $(STDLIB_MOBJ1x:.o=.os): $(STDLIB_MSRC1) $(STDLIB_MOBJ2x) $(STDLIB_MOBJ2x:.o=.os): $(STDLIB_MSRC2) $(compile.m) -D__UCLIBC_DO_XLOCALE -libc-a-y+=$(STDLIB_OBJS) $(STDLIB_OUT)/atexit.o -libc-a-pic-y+=$(STDLIB_OBJS:.o=.os) $(STDLIB_OUT)/atexit.os +libc-a-y+=$(STDLIB_OBJS) +libc-static-y+=$(STDLIB_OUT)/atexit.o libc-so-y+=$(STDLIB_OBJS:.o=.os) # this should always be the PIC version, because it could be used in shared libs libc-nonshared-y+=$(STDLIB_OUT)/atexit.os -CFLAGS-multi-y+=$(STDLIB_DEF) -libc-multi-y+=$(STDLIB_SRC) $(STDLIB_MSRC) -libc-nomulti-y+=$(STDLIB_MOBJx) +#CFLAGS-multi-y+=$(STDLIB_DEF) +#libc-multi-y+=$(STDLIB_SRC) $(STDLIB_MSRC) +#libc-nomulti-y+=$(STDLIB_MOBJx) +#libc-multi-y+=$(STDLIB_MSRC) +#libc-nomulti-y+=$(STDLIB_OBJ) $(STDLIB_MOBJx) +libc-nomulti-y+=$(STDLIB_OBJS) objclean-y+=stdlib_objclean diff --git a/libc/sysdeps/linux/common/Makefile b/libc/sysdeps/linux/common/Makefile index e45c58961..704f0350b 100644 --- a/libc/sysdeps/linux/common/Makefile +++ b/libc/sysdeps/linux/common/Makefile @@ -56,6 +56,7 @@ $(OBJS) $(NONSHARED_OBJS): %.o : %.c headers: $(LN) -fs ../libc/sysdeps/linux/common/fpu_control.h $(TOPDIR)/include/ + $(LN) -fs ../libc/sysdeps/linux/common/dl-osinfo.h $(TOPDIR)/include/ clean: $(RM) *.o *~ core diff --git a/libc/sysdeps/linux/common/Makefile.in b/libc/sysdeps/linux/common/Makefile.in index 85826913e..ce7d8f90d 100644 --- a/libc/sysdeps/linux/common/Makefile.in +++ b/libc/sysdeps/linux/common/Makefile.in @@ -31,9 +31,7 @@ COMMON_SRC:=$(patsubst %.c,$(COMMON_DIR)/%.c,$(CSRC)) COMMON_OBJ:=$(patsubst %.c,$(COMMON_OUT)/%.o,$(CSRC)) libc-a-y+=$(COMMON_OBJ) -libc-a-$(UCLIBC_HAS_SSP)+=$(COMMON_OUT)/ssp-local.o -libc-a-pic-y+=$(COMMON_OBJ:.o=.os) -libc-a-pic-$(UCLIBC_HAS_SSP)+=$(COMMON_OUT)/ssp-local.os +libc-a-static-$(UCLIBC_HAS_SSP)+=$(COMMON_OUT)/ssp-local.o libc-so-y+=$(COMMON_OBJ:.o=.os) libc-nonshared-$(UCLIBC_HAS_SSP)+=$(COMMON_OUT)/ssp-local.os @@ -50,3 +48,4 @@ headers-y+=common_headers common_headers: $(LN) -fs ../libc/sysdeps/linux/common/fpu_control.h $(top_builddir)include/ + $(LN) -fs ../libc/sysdeps/linux/common/dl-osinfo.h $(top_builddir)include/ diff --git a/libc/sysdeps/linux/common/dl-osinfo.h b/libc/sysdeps/linux/common/dl-osinfo.h new file mode 100644 index 000000000..ee3e2ce99 --- /dev/null +++ b/libc/sysdeps/linux/common/dl-osinfo.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org> + * + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +#ifndef _DL_OSINFO_H +#define _DL_OSINFO_H 1 + +#include <features.h> + +#ifdef __UCLIBC_HAS_SSP__ +#include <stdint.h> +#include <sys/time.h> + +#ifdef IS_IN_libc +#include <ssp-internal.h> +#if 0 +#ifndef __SSP_QUICK_CANARY__ +#define OPEN __libc_open +#define READ __libc_read +#define CLOSE __libc_close +#endif +#define GETTIMEOFDAY gettimeofday +#endif +#else +#ifndef __SSP_QUICK_CANARY__ +#define OPEN _dl_open +#define READ _dl_read +#define CLOSE _dl_close +#endif +#define GETTIMEOFDAY _dl_gettimeofday +#endif + +static __always_inline uintptr_t _dl_setup_stack_chk_guard(void) +{ + uintptr_t ret; +#ifndef __SSP_QUICK_CANARY__ + { + int fd = OPEN("/dev/urandom", O_RDONLY, 0); + if (fd >= 0) { + size_t size = READ(fd, &ret, sizeof(ret)); + CLOSE(fd); + if (size == (size_t) sizeof(ret)) + return ret; + } + } +#endif /* !__SSP_QUICK_CANARY__ */ + + /* Start with the "terminator canary". */ + ret = 0xFF0A0D00UL; + + /* Everything failed? Or we are using a weakened model of the + * terminator canary */ + { + struct timeval tv; + if (GETTIMEOFDAY(&tv, NULL) != (-1)) + ret ^= tv.tv_usec ^ tv.tv_sec; + } + return ret; +} +#endif /* __UCLIBC_HAS_SSP__ */ + +#endif /* _DL_OSINFO_H */ diff --git a/libc/sysdeps/linux/common/ssp.c b/libc/sysdeps/linux/common/ssp.c index 7791a0104..2f3a28ba4 100644 --- a/libc/sysdeps/linux/common/ssp.c +++ b/libc/sysdeps/linux/common/ssp.c @@ -87,6 +87,7 @@ void __attribute__ ((noreturn)) __stack_chk_fail(void) terminate(); } +#if 0 void __attribute__ ((noreturn)) __chk_fail(void) { extern char *__progname; @@ -101,3 +102,4 @@ void __attribute__ ((noreturn)) __chk_fail(void) while(1) terminate(); } +#endif |