diff options
Diffstat (limited to 'libc')
37 files changed, 387 insertions, 403 deletions
diff --git a/libc/Makefile b/libc/Makefile index 56669dd64..231c8112e 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -39,7 +39,7 @@ VERSION_SCRIPT:=${shell if [ -f sysdeps/linux/$(TARGET_ARCH)/libc.map ] ; then \ LIBNAME_TARGET:=$(TOPDIR)lib/$(LIBNAME) -all: halfclean $(LIBNAME_TARGET) $(DO_SHARED) +all: halfclean $(LIBNAME_TARGET) # Some functions are duplicated across subdirs, and when you pass $(AR) # the same object file more than once, it'll add it to the archive multiple @@ -85,7 +85,6 @@ shared: shared_$(LIBNAME) --whole-archive shared_$(LIBNAME) \ $(TOPDIR)libc/misc/internals/interp.o --no-whole-archive \ -init __uClibc_init $(TOPDIR)lib/$(UCLIBC_LDSO) $(LIBGCC) $(LDADD_LIBFLOAT) - @true #$(RM) -r tmp $(INSTALL) -d $(TOPDIR)lib $(RM) $(TOPDIR)lib/$(SHARED_FULLNAME) $(INSTALL) -m 644 $(SHARED_FULLNAME) $(TOPDIR)lib @@ -93,15 +92,12 @@ shared: shared_$(LIBNAME) $(LN) -sf $(SHARED_FULLNAME) $(TOPDIR)lib/$(SHARED_MAJORNAME) halfclean: - @$(RM) $(LIBNAME) shared_$(LIBNAME) uClibc_config.h - @$(RM) $(SHARED_FULLNAME) $(SHARED_MAJORNAME) uClibc-0.* libc.so* + $(RM) $(LIBNAME) shared_$(LIBNAME) $(SHARED_FULLNAME) tags: ctags -R clean: subdirs_clean halfclean - @$(RM) -r tmp - $(RM) include/asm include/linux include/bits $(RM) obj.* obj-* subdirs: $(patsubst %, _dir_%, $(DIRS)) diff --git a/libc/misc/internals/Makefile b/libc/misc/internals/Makefile index 803181a8f..fee3eca70 100644 --- a/libc/misc/internals/Makefile +++ b/libc/misc/internals/Makefile @@ -27,6 +27,8 @@ include $(TOPDIR)Rules.mak CSRC=__uClibc_main.c tempname.c errno.c __errno_location.c __h_errno_location.c COBJS=$(patsubst %.c,%.o, $(CSRC)) +__uClibc_main.o: CFLAGS += $(SSP_DISABLE_FLAGS) + OBJS=$(COBJS) OBJ_LIST=../../obj.misc.internals diff --git a/libc/misc/internals/__uClibc_main.c b/libc/misc/internals/__uClibc_main.c index c9f3d0e40..1ed05c6b2 100644 --- a/libc/misc/internals/__uClibc_main.c +++ b/libc/misc/internals/__uClibc_main.c @@ -3,7 +3,7 @@ * Erik Andersen 2002-2004 * * __uClibc_main is the routine to be called by all the arch-specific - * versions of crt0.S in uClibc. + * versions of crt1.S in uClibc. * * It is meant to handle any special initialization needed by the library * such as setting the global variable(s) __environ (environ) and @@ -26,9 +26,10 @@ #include <sys/stat.h> #include <sys/sysmacros.h> #ifdef __UCLIBC_HAS_SSP__ -extern void __guard_setup(void); -#endif +#include <ssp-internal.h> +unsigned long __guard = 0UL; +#endif /* * Prototypes. @@ -106,6 +107,62 @@ static int __check_suid(void) return 1; } +#ifdef __UCLIBC_HAS_SSP__ +static __always_inline void __guard_setup(void) +{ + if (__guard != 0UL) + return; + +#ifndef __SSP_QUICK_CANARY__ + + size_t size; + +# ifdef __SSP_USE_ERANDOM__ + { + int mib[3]; + /* Random is another depth in Linux, hence an array of 3. */ + mib[0] = CTL_KERN; + mib[1] = KERN_RANDOM; + mib[2] = RANDOM_ERANDOM; + + size = sizeof(unsigned long); + if (SYSCTL(mib, 3, &__guard, &size, NULL, 0) != (-1)) + if (__guard != 0UL) + return; + } +# endif /* ifdef __SSP_USE_ERANDOM__ */ + { + int fd; + +# ifdef __SSP_USE_ERANDOM__ + /* + * Attempt to open kernel pseudo random device if one exists before + * opening urandom to avoid system entropy depletion. + */ + if ((fd = OPEN("/dev/erandom", O_RDONLY)) == (-1)) +# endif + fd = OPEN("/dev/urandom", O_RDONLY); + if (fd != (-1)) { + size = READ(fd, (char *) &__guard, sizeof(__guard)); + CLOSE(fd); + if (size == sizeof(__guard)) + return; + } + } +#endif /* ifndef __SSP_QUICK_CANARY__ */ + + /* Start with the "terminator canary". */ + __guard = 0xFF0A0D00UL; + + /* Everything failed? Or we are using a weakened model of the + * terminator canary */ + { + struct timeval tv; + GETTIMEOFDAY(&tv, NULL); + __guard ^= tv.tv_usec ^ tv.tv_sec; + } +} +#endif /* __UCLIBC_HAS_SSP__ */ /* __uClibc_init completely initialize uClibc so it is ready to use. * @@ -117,7 +174,7 @@ static int __check_suid(void) * uClibc is the address of __uClibc_init * * In all other cases we call it from the main stub - * __uClibc_start_main. + * __uClibc_main. */ void __uClibc_init(void) @@ -133,7 +190,7 @@ void __uClibc_init(void) __pagesize = PAGE_SIZE; #ifdef __UCLIBC_HAS_THREADS__ - /* Before we start initialzing uClibc we have to call + /* Before we start initializing uClibc we have to call * __pthread_initialize_minimal so we can use pthread_locks * whenever they are needed. */ @@ -141,6 +198,10 @@ void __uClibc_init(void) __pthread_initialize_minimal(); #endif +#ifdef __UCLIBC_HAS_SSP__ + __guard_setup (); +#endif + #ifdef __UCLIBC_HAS_LOCALE__ /* Initialize the global locale structure. */ if (likely(_locale_init!=NULL)) @@ -162,8 +223,8 @@ void attribute_hidden (*__app_fini)(void) = NULL; void attribute_hidden (*__rtld_fini)(void) = NULL; -/* __uClibc_start_main is the new main stub for uClibc. This function is - * called from crt0 (version 0.9.16 or newer), after ALL shared libraries +/* __uClibc_main is the new main stub for uClibc. This function is + * called from crt1 (version 0.9.28 or newer), after ALL shared libraries * are initialized, just before we call the application's main function. */ void __attribute__ ((__noreturn__)) @@ -246,10 +307,6 @@ __uClibc_main(int (*main)(int, char **, char **), int argc, } #endif -#ifdef __UCLIBC_HAS_SSP__ - __guard_setup (); -#endif - /* Note: It is possible that any initialization done above could * have resulted in errno being set nonzero, so set it to 0 before * we call main. diff --git a/libc/misc/pthread/weaks.c b/libc/misc/pthread/weaks.c index 8486dc203..6767cfffb 100644 --- a/libc/misc/pthread/weaks.c +++ b/libc/misc/pthread/weaks.c @@ -24,6 +24,18 @@ static int __pthread_return_0 __P ((void)); static int __pthread_return_1 __P ((void)); +static int +__pthread_return_0 (void) +{ + return 0; +} + +static int +__pthread_return_1 (void) +{ + return 1; +} + /**********************************************************************/ /* Weaks for application/library use. * @@ -105,15 +117,3 @@ weak_alias (__pthread_return_0, __pthread_mutex_trylock) weak_alias (__pthread_return_0, __pthread_mutex_unlock) /**********************************************************************/ - -static int -__pthread_return_0 (void) -{ - return 0; -} - -static int -__pthread_return_1 (void) -{ - return 1; -} diff --git a/libc/misc/time/time.c b/libc/misc/time/time.c index 57ef2217a..914277698 100644 --- a/libc/misc/time/time.c +++ b/libc/misc/time/time.c @@ -713,15 +713,15 @@ struct tm *__time_localtime_tzi(register const time_t *__restrict timer, /**********************************************************************/ #ifdef L_mktime -/* Another name for `mktime'. */ -/* time_t timelocal(struct tm *tp) */ -weak_alias(mktime,timelocal); - time_t mktime(struct tm *timeptr) { return _time_mktime(timeptr, 1); } +/* Another name for `mktime'. */ +/* time_t timelocal(struct tm *tp) */ +weak_alias(mktime,timelocal); + #endif /**********************************************************************/ #ifdef L_timegm diff --git a/libc/misc/wchar/wchar.c b/libc/misc/wchar/wchar.c index d1383c99f..e3553166d 100644 --- a/libc/misc/wchar/wchar.c +++ b/libc/misc/wchar/wchar.c @@ -261,9 +261,6 @@ int mbsinit(const mbstate_t *ps) /**********************************************************************/ #ifdef L_mbrlen -size_t mbrlen(const char *__restrict s, size_t n, mbstate_t *__restrict ps) - __attribute__ ((__weak__, __alias__("__mbrlen"))); - size_t __mbrlen(const char *__restrict s, size_t n, mbstate_t *__restrict ps) { static mbstate_t mbstate; /* Rely on bss 0-init. */ @@ -271,6 +268,9 @@ size_t __mbrlen(const char *__restrict s, size_t n, mbstate_t *__restrict ps) return mbrtowc(NULL, s, n, (ps != NULL) ? ps : &mbstate); } +size_t mbrlen(const char *__restrict s, size_t n, mbstate_t *__restrict ps) + __attribute__ ((__weak__, __alias__("__mbrlen"))); + #endif /**********************************************************************/ #ifdef L_mbrtowc @@ -679,10 +679,6 @@ size_t _wchar_wcsntoutf8s(char *__restrict s, size_t n, /* WARNING: We treat len as SIZE_MAX when dst is NULL! */ -size_t mbsnrtowcs(wchar_t *__restrict dst, const char **__restrict src, - size_t NMC, size_t len, mbstate_t *__restrict ps) - __attribute__ ((__weak__, __alias__("__mbsnrtowcs"))); - size_t __mbsnrtowcs(wchar_t *__restrict dst, const char **__restrict src, size_t NMC, size_t len, mbstate_t *__restrict ps) { @@ -782,6 +778,10 @@ size_t __mbsnrtowcs(wchar_t *__restrict dst, const char **__restrict src, return len - count; } +size_t mbsnrtowcs(wchar_t *__restrict dst, const char **__restrict src, + size_t NMC, size_t len, mbstate_t *__restrict ps) + __attribute__ ((__weak__, __alias__("__mbsnrtowcs"))); + #endif /**********************************************************************/ #ifdef L___wcsnrtombs @@ -791,10 +791,6 @@ size_t __mbsnrtowcs(wchar_t *__restrict dst, const char **__restrict src, /* Note: We completely ignore ps in all currently supported conversions. * TODO: Check for valid state anyway? */ -size_t wcsnrtombs(char *__restrict dst, const wchar_t **__restrict src, - size_t NWC, size_t len, mbstate_t *__restrict ps) - __attribute__ ((__weak__, __alias__("__wcsnrtombs"))); - size_t __wcsnrtombs(char *__restrict dst, const wchar_t **__restrict src, size_t NWC, size_t len, mbstate_t *__restrict ps) { @@ -904,6 +900,10 @@ size_t __wcsnrtombs(char *__restrict dst, const wchar_t **__restrict src, return len - count; } +size_t wcsnrtombs(char *__restrict dst, const wchar_t **__restrict src, + size_t NWC, size_t len, mbstate_t *__restrict ps) + __attribute__ ((__weak__, __alias__("__wcsnrtombs"))); + #endif /**********************************************************************/ #ifdef L_wcswidth diff --git a/libc/pwd_grp/pwd_grp.c b/libc/pwd_grp/pwd_grp.c index 91c0d83f5..e56b545d6 100644 --- a/libc/pwd_grp/pwd_grp.c +++ b/libc/pwd_grp/pwd_grp.c @@ -41,7 +41,10 @@ #include <ctype.h> #include <pwd.h> #include <grp.h> +#include <paths.h> +#ifdef __HAS_SHADOW__ #include <shadow.h> +#endif #ifdef __UCLIBC_HAS_THREADS__ #include <pthread.h> #endif diff --git a/libc/stdio/Makefile b/libc/stdio/Makefile index 684380ef0..6e1a95f2f 100644 --- a/libc/stdio/Makefile +++ b/libc/stdio/Makefile @@ -58,9 +58,7 @@ CSRC += fopencookie.c fmemopen.c open_memstream.c endif # pthread functions -ifeq ($(strip $(UCLIBC_HAS_THREADS)),y) CSRC += flockfile.c ftrylockfile.c funlockfile.c -endif ifeq ($(strip $(PTHREADS_NATIVE)),y) CSRC += fatal.c endif diff --git a/libc/stdio/asprintf.c b/libc/stdio/asprintf.c index 54998fa1d..36ed807a4 100644 --- a/libc/stdio/asprintf.c +++ b/libc/stdio/asprintf.c @@ -12,8 +12,6 @@ #warning Skipping asprintf and __asprintf since no vsnprintf! #else -weak_alias(__asprintf,asprintf) - int __asprintf(char **__restrict buf, const char * __restrict format, ...) { va_list arg; @@ -26,4 +24,6 @@ int __asprintf(char **__restrict buf, const char * __restrict format, ...) return rv; } +weak_alias(__asprintf,asprintf) + #endif diff --git a/libc/stdio/clearerr.c b/libc/stdio/clearerr.c index 177088a77..2772bed3c 100644 --- a/libc/stdio/clearerr.c +++ b/libc/stdio/clearerr.c @@ -9,11 +9,6 @@ #ifdef __DO_UNLOCKED -weak_alias(__clearerr_unlocked,clearerr_unlocked); -#ifndef __UCLIBC_HAS_THREADS__ -weak_alias(__clearerr_unlocked,clearerr); -#endif - void __clearerr_unlocked(register FILE *stream) { __STDIO_STREAM_VALIDATE(stream); @@ -21,6 +16,11 @@ void __clearerr_unlocked(register FILE *stream) __CLEARERR_UNLOCKED(stream); } +weak_alias(__clearerr_unlocked,clearerr_unlocked); +#ifndef __UCLIBC_HAS_THREADS__ +weak_alias(__clearerr_unlocked,clearerr); +#endif + #elif defined __UCLIBC_HAS_THREADS__ void clearerr(register FILE *stream) diff --git a/libc/stdio/feof.c b/libc/stdio/feof.c index e98e7e1c2..907872f7f 100644 --- a/libc/stdio/feof.c +++ b/libc/stdio/feof.c @@ -9,11 +9,6 @@ #ifdef __DO_UNLOCKED -weak_alias(__feof_unlocked,feof_unlocked); -#ifndef __UCLIBC_HAS_THREADS__ -weak_alias(__feof_unlocked,feof); -#endif - int __feof_unlocked(register FILE *stream) { __STDIO_STREAM_VALIDATE(stream); @@ -21,6 +16,11 @@ int __feof_unlocked(register FILE *stream) return __FEOF_UNLOCKED(stream); } +weak_alias(__feof_unlocked,feof_unlocked); +#ifndef __UCLIBC_HAS_THREADS__ +weak_alias(__feof_unlocked,feof); +#endif + #elif defined __UCLIBC_HAS_THREADS__ int feof(register FILE *stream) diff --git a/libc/stdio/ferror.c b/libc/stdio/ferror.c index 3bfaf68ee..95014d3b0 100644 --- a/libc/stdio/ferror.c +++ b/libc/stdio/ferror.c @@ -9,11 +9,6 @@ #ifdef __DO_UNLOCKED -weak_alias(__ferror_unlocked,ferror_unlocked); -#ifndef __UCLIBC_HAS_THREADS__ -weak_alias(__ferror_unlocked,ferror); -#endif - int __ferror_unlocked(register FILE *stream) { __STDIO_STREAM_VALIDATE(stream); @@ -21,6 +16,11 @@ int __ferror_unlocked(register FILE *stream) return __FERROR_UNLOCKED(stream); } +weak_alias(__ferror_unlocked,ferror_unlocked); +#ifndef __UCLIBC_HAS_THREADS__ +weak_alias(__ferror_unlocked,ferror); +#endif + #elif defined __UCLIBC_HAS_THREADS__ int ferror(register FILE *stream) diff --git a/libc/stdio/fflush.c b/libc/stdio/fflush.c index 6baa0ec82..fa50db15a 100644 --- a/libc/stdio/fflush.c +++ b/libc/stdio/fflush.c @@ -7,19 +7,12 @@ #include "_stdio.h" -extern int __fflush_unlocked(register FILE *stream); - #ifdef __DO_UNLOCKED #ifdef __UCLIBC_MJN3_ONLY__ #warning WISHLIST: Add option to test for undefined behavior of fflush. #endif /* __UCLIBC_MJN3_ONLY__ */ -weak_alias(__fflush_unlocked,fflush_unlocked); -#ifndef __UCLIBC_HAS_THREADS__ -weak_alias(__fflush_unlocked,fflush); -#endif - #ifdef __UCLIBC_HAS_THREADS__ /* Even if the stream is set to user-locking, we still need to lock * when all (lbf) writing streams are flushed. */ @@ -133,6 +126,11 @@ int __fflush_unlocked(register FILE *stream) #endif /* __STDIO_BUFFERS */ } +weak_alias(__fflush_unlocked,fflush_unlocked); +#ifndef __UCLIBC_HAS_THREADS__ +weak_alias(__fflush_unlocked,fflush); +#endif + #elif defined __UCLIBC_HAS_THREADS__ int fflush(register FILE *stream) diff --git a/libc/stdio/fgetc.c b/libc/stdio/fgetc.c index c672d9fe9..c68c1fdb5 100644 --- a/libc/stdio/fgetc.c +++ b/libc/stdio/fgetc.c @@ -12,17 +12,8 @@ #undef getc #undef getc_unlocked -extern int __fgetc_unlocked(FILE *stream); - #ifdef __DO_UNLOCKED -weak_alias(__fgetc_unlocked,fgetc_unlocked); -weak_alias(__fgetc_unlocked,getc_unlocked); -#ifndef __UCLIBC_HAS_THREADS__ -weak_alias(__fgetc_unlocked,fgetc); -weak_alias(__fgetc_unlocked,getc); -#endif - int __fgetc_unlocked(FILE *stream) { __STDIO_STREAM_VALIDATE(stream); @@ -78,9 +69,14 @@ int __fgetc_unlocked(FILE *stream) return EOF; } -#elif defined __UCLIBC_HAS_THREADS__ +weak_alias(__fgetc_unlocked,fgetc_unlocked); +weak_alias(__fgetc_unlocked,getc_unlocked); +#ifndef __UCLIBC_HAS_THREADS__ +weak_alias(__fgetc_unlocked,fgetc); +weak_alias(__fgetc_unlocked,getc); +#endif -weak_alias(fgetc,getc); +#elif defined __UCLIBC_HAS_THREADS__ int fgetc(register FILE *stream) { @@ -95,4 +91,6 @@ int fgetc(register FILE *stream) } } +weak_alias(fgetc,getc); + #endif diff --git a/libc/stdio/fgets.c b/libc/stdio/fgets.c index 6bcfc2957..4b32ad612 100644 --- a/libc/stdio/fgets.c +++ b/libc/stdio/fgets.c @@ -9,12 +9,6 @@ #ifdef __DO_UNLOCKED -weak_alias(__fgets_unlocked,fgets_unlocked); -#ifndef __UCLIBC_HAS_THREADS__ -weak_alias(__fgets_unlocked,fgets); -#endif - - char *__fgets_unlocked(char *__restrict s, int n, register FILE * __restrict stream) { @@ -64,6 +58,12 @@ char *__fgets_unlocked(char *__restrict s, int n, return NULL; } +weak_alias(__fgets_unlocked,fgets_unlocked); + +#ifndef __UCLIBC_HAS_THREADS__ +weak_alias(__fgets_unlocked,fgets); +#endif + #elif defined __UCLIBC_HAS_THREADS__ char *fgets(char *__restrict s, int n, diff --git a/libc/stdio/fgetwc.c b/libc/stdio/fgetwc.c index 9f1f9c481..a78f52212 100644 --- a/libc/stdio/fgetwc.c +++ b/libc/stdio/fgetwc.c @@ -9,13 +9,6 @@ #ifdef __DO_UNLOCKED -weak_alias(__fgetwc_unlocked,fgetwc_unlocked); -weak_alias(__fgetwc_unlocked,getwc_unlocked); -#ifndef __UCLIBC_HAS_THREADS__ -weak_alias(__fgetwc_unlocked,fgetwc); -weak_alias(__fgetwc_unlocked,getwc); -#endif - static void munge_stream(register FILE *stream, unsigned char *buf) { stream->__bufend = stream->__bufstart = buf; @@ -113,9 +106,14 @@ wint_t __fgetwc_unlocked(register FILE *stream) return wi; } -#elif defined __UCLIBC_HAS_THREADS__ +weak_alias(__fgetwc_unlocked,fgetwc_unlocked); +weak_alias(__fgetwc_unlocked,getwc_unlocked); +#ifndef __UCLIBC_HAS_THREADS__ +weak_alias(__fgetwc_unlocked,fgetwc); +weak_alias(__fgetwc_unlocked,getwc); +#endif -weak_alias(fgetwc,getwc); +#elif defined __UCLIBC_HAS_THREADS__ wint_t fgetwc(register FILE *stream) { @@ -131,4 +129,6 @@ wint_t fgetwc(register FILE *stream) return retval; } +weak_alias(fgetwc,getwc); + #endif diff --git a/libc/stdio/fgetws.c b/libc/stdio/fgetws.c index ec8547e25..16f8873b3 100644 --- a/libc/stdio/fgetws.c +++ b/libc/stdio/fgetws.c @@ -12,11 +12,6 @@ extern wchar_t *__fgetws_unlocked(wchar_t *__restrict ws, int n, #ifdef __DO_UNLOCKED -weak_alias(__fgetws_unlocked,fgetws_unlocked); -#ifndef __UCLIBC_HAS_THREADS__ -weak_alias(__fgetws_unlocked,fgetws); -#endif - wchar_t *__fgetws_unlocked(wchar_t *__restrict ws, int n, FILE *__restrict stream) { @@ -42,6 +37,11 @@ wchar_t *__fgetws_unlocked(wchar_t *__restrict ws, int n, return ws; } +weak_alias(__fgetws_unlocked,fgetws_unlocked); +#ifndef __UCLIBC_HAS_THREADS__ +weak_alias(__fgetws_unlocked,fgetws); +#endif + #elif defined __UCLIBC_HAS_THREADS__ wchar_t *fgetws(wchar_t *__restrict ws, int n, FILE *__restrict stream) diff --git a/libc/stdio/fileno.c b/libc/stdio/fileno.c index fbfa66551..30ae90ad3 100644 --- a/libc/stdio/fileno.c +++ b/libc/stdio/fileno.c @@ -9,11 +9,6 @@ #ifdef __DO_UNLOCKED -weak_alias(__fileno_unlocked,fileno_unlocked); -#ifndef __UCLIBC_HAS_THREADS__ -weak_alias(__fileno_unlocked,fileno); -#endif - int __fileno_unlocked(register FILE *stream) { __STDIO_STREAM_VALIDATE(stream); @@ -26,6 +21,11 @@ int __fileno_unlocked(register FILE *stream) return -1; } +weak_alias(__fileno_unlocked,fileno_unlocked); +#ifndef __UCLIBC_HAS_THREADS__ +weak_alias(__fileno_unlocked,fileno); +#endif + #elif defined __UCLIBC_HAS_THREADS__ int fileno(register FILE *stream) diff --git a/libc/stdio/fputc.c b/libc/stdio/fputc.c index 0cfb4f943..ad3c95517 100644 --- a/libc/stdio/fputc.c +++ b/libc/stdio/fputc.c @@ -14,13 +14,6 @@ #ifdef __DO_UNLOCKED -weak_alias(__fputc_unlocked,fputc_unlocked); -weak_alias(__fputc_unlocked,putc_unlocked); -#ifndef __UCLIBC_HAS_THREADS__ -weak_alias(__fputc_unlocked,fputc); -weak_alias(__fputc_unlocked,putc); -#endif - int __fputc_unlocked(int c, register FILE *stream) { __STDIO_STREAM_VALIDATE(stream); @@ -76,9 +69,14 @@ int __fputc_unlocked(int c, register FILE *stream) return EOF; } -#elif defined __UCLIBC_HAS_THREADS__ +weak_alias(__fputc_unlocked,fputc_unlocked); +weak_alias(__fputc_unlocked,putc_unlocked); +#ifndef __UCLIBC_HAS_THREADS__ +weak_alias(__fputc_unlocked,fputc); +weak_alias(__fputc_unlocked,putc); +#endif -weak_alias(fputc,putc); +#elif defined __UCLIBC_HAS_THREADS__ int fputc(int c, register FILE *stream) { @@ -93,4 +91,6 @@ int fputc(int c, register FILE *stream) } } +weak_alias(fputc,putc); + #endif diff --git a/libc/stdio/fputs.c b/libc/stdio/fputs.c index b3d77fa46..e4d10659f 100644 --- a/libc/stdio/fputs.c +++ b/libc/stdio/fputs.c @@ -14,11 +14,6 @@ #ifdef __DO_UNLOCKED -weak_alias(__fputs_unlocked,fputs_unlocked); -#ifndef __UCLIBC_HAS_THREADS__ -weak_alias(__fputs_unlocked,fputs); -#endif - int __fputs_unlocked(register const char * __restrict s, FILE * __restrict stream) { @@ -27,6 +22,11 @@ int __fputs_unlocked(register const char * __restrict s, return ((__fwrite_unlocked(s, 1, n, stream) == n) ? n : EOF); } +weak_alias(__fputs_unlocked,fputs_unlocked); +#ifndef __UCLIBC_HAS_THREADS__ +weak_alias(__fputs_unlocked,fputs); +#endif + #elif defined __UCLIBC_HAS_THREADS__ int fputs(const char * __restrict s, register FILE * __restrict stream) diff --git a/libc/stdio/fputwc.c b/libc/stdio/fputwc.c index fc980dcef..ef7a6d627 100644 --- a/libc/stdio/fputwc.c +++ b/libc/stdio/fputwc.c @@ -9,6 +9,11 @@ #ifdef __DO_UNLOCKED +wint_t __fputwc_unlocked(wchar_t wc, FILE *stream) +{ + return _wstdio_fwrite(&wc, 1, stream) ? wc : WEOF; +} + weak_alias(__fputwc_unlocked,fputwc_unlocked); weak_alias(__fputwc_unlocked,putwc_unlocked); #ifndef __UCLIBC_HAS_THREADS__ @@ -16,15 +21,8 @@ weak_alias(__fputwc_unlocked,fputwc); weak_alias(__fputwc_unlocked,putwc); #endif -wint_t __fputwc_unlocked(wchar_t wc, FILE *stream) -{ - return _wstdio_fwrite(&wc, 1, stream) ? wc : WEOF; -} - #elif defined __UCLIBC_HAS_THREADS__ -weak_alias(fputwc,putwc); - wint_t fputwc(wchar_t wc, register FILE *stream) { wint_t retval; @@ -39,4 +37,6 @@ wint_t fputwc(wchar_t wc, register FILE *stream) return retval; } +weak_alias(fputwc,putwc); + #endif diff --git a/libc/stdio/fputws.c b/libc/stdio/fputws.c index 7b6456a09..f3270fde8 100644 --- a/libc/stdio/fputws.c +++ b/libc/stdio/fputws.c @@ -12,11 +12,6 @@ extern int __fputws_unlocked(const wchar_t *__restrict ws, #ifdef __DO_UNLOCKED -weak_alias(__fputws_unlocked,fputws_unlocked); -#ifndef __UCLIBC_HAS_THREADS__ -weak_alias(__fputws_unlocked,fputws); -#endif - int __fputws_unlocked(const wchar_t *__restrict ws, register FILE *__restrict stream) { @@ -25,6 +20,11 @@ int __fputws_unlocked(const wchar_t *__restrict ws, return (_wstdio_fwrite(ws, n, stream) == n) ? 0 : -1; } +weak_alias(__fputws_unlocked,fputws_unlocked); +#ifndef __UCLIBC_HAS_THREADS__ +weak_alias(__fputws_unlocked,fputws); +#endif + #elif defined __UCLIBC_HAS_THREADS__ int fputws(const wchar_t *__restrict ws, register FILE *__restrict stream) diff --git a/libc/stdio/fread.c b/libc/stdio/fread.c index 875c82616..73414e26c 100644 --- a/libc/stdio/fread.c +++ b/libc/stdio/fread.c @@ -9,11 +9,6 @@ #ifdef __DO_UNLOCKED -weak_alias(__fread_unlocked,fread_unlocked); -#ifndef __UCLIBC_HAS_THREADS__ -weak_alias(__fread_unlocked,fread); -#endif - size_t __fread_unlocked(void * __restrict ptr, size_t size, size_t nmemb, FILE * __restrict stream) { @@ -88,6 +83,11 @@ size_t __fread_unlocked(void * __restrict ptr, size_t size, size_t nmemb, return 0; } +weak_alias(__fread_unlocked,fread_unlocked); +#ifndef __UCLIBC_HAS_THREADS__ +weak_alias(__fread_unlocked,fread); +#endif + #elif defined __UCLIBC_HAS_THREADS__ size_t fread(void * __restrict ptr, size_t size, size_t nmemb, diff --git a/libc/stdio/fseeko.c b/libc/stdio/fseeko.c index fed425730..48979a06b 100644 --- a/libc/stdio/fseeko.c +++ b/libc/stdio/fseeko.c @@ -19,15 +19,11 @@ # define FSEEK __fseeko64 # define OFFSET_TYPE __off64_t -weak_alias(__fseeko64,fseeko64); - #else # define FSEEK fseek # define OFFSET_TYPE long int -weak_alias(fseek,fseeko); - #endif @@ -87,3 +83,9 @@ int FSEEK(register FILE *stream, OFFSET_TYPE offset, int whence) #endif } + +#ifdef __DO_LARGEFILE +weak_alias(__fseeko64,fseeko64); +#else +weak_alias(fseek,fseeko); +#endif diff --git a/libc/stdio/ftello.c b/libc/stdio/ftello.c index 7092f34cf..38517acbd 100644 --- a/libc/stdio/ftello.c +++ b/libc/stdio/ftello.c @@ -15,15 +15,11 @@ # define FTELL __ftello64 # define OFFSET_TYPE __off64_t -weak_alias(__ftello64,ftello64); - #else # define FTELL ftell # define OFFSET_TYPE long int -weak_alias(ftell,ftello); - #endif OFFSET_TYPE FTELL(register FILE *stream) @@ -59,3 +55,9 @@ OFFSET_TYPE FTELL(register FILE *stream) #endif } + +#ifdef __DO_LARGEFILE +weak_alias(__ftello64,ftello64); +#else +weak_alias(ftell,ftello); +#endif diff --git a/libc/stdio/fwrite.c b/libc/stdio/fwrite.c index a5e8fd6bf..7bb0a8022 100644 --- a/libc/stdio/fwrite.c +++ b/libc/stdio/fwrite.c @@ -9,11 +9,6 @@ #ifdef __DO_UNLOCKED -weak_alias(__fwrite_unlocked,fwrite_unlocked); -#ifndef __UCLIBC_HAS_THREADS__ -weak_alias(__fwrite_unlocked,fwrite); -#endif - size_t __fwrite_unlocked(const void * __restrict ptr, size_t size, size_t nmemb, register FILE * __restrict stream) { @@ -39,6 +34,11 @@ size_t __fwrite_unlocked(const void * __restrict ptr, size_t size, return 0; } +weak_alias(__fwrite_unlocked,fwrite_unlocked); +#ifndef __UCLIBC_HAS_THREADS__ +weak_alias(__fwrite_unlocked,fwrite); +#endif + #elif defined __UCLIBC_HAS_THREADS__ size_t fwrite(const void * __restrict ptr, size_t size, diff --git a/libc/stdio/getchar.c b/libc/stdio/getchar.c index 49414eb70..902cec16e 100644 --- a/libc/stdio/getchar.c +++ b/libc/stdio/getchar.c @@ -12,11 +12,6 @@ #ifdef __DO_UNLOCKED -weak_alias(__getchar_unlocked,getchar_unlocked); -#ifndef __UCLIBC_HAS_THREADS__ -weak_alias(__getchar_unlocked,getchar); -#endif - int __getchar_unlocked(void) { register FILE *stream = stdin; @@ -24,6 +19,11 @@ int __getchar_unlocked(void) return __GETC_UNLOCKED_MACRO(stream); } +weak_alias(__getchar_unlocked,getchar_unlocked); +#ifndef __UCLIBC_HAS_THREADS__ +weak_alias(__getchar_unlocked,getchar); +#endif + #elif defined __UCLIBC_HAS_THREADS__ int getchar(void) diff --git a/libc/stdio/getdelim.c b/libc/stdio/getdelim.c index fe388ee11..cf3cf4c10 100644 --- a/libc/stdio/getdelim.c +++ b/libc/stdio/getdelim.c @@ -18,8 +18,6 @@ * a reading. So space may be allocated even if initially at EOF. */ -weak_alias(__getdelim,getdelim); - #define GETDELIM_GROWBY 64 ssize_t __getdelim(char **__restrict lineptr, size_t *__restrict n, @@ -75,3 +73,5 @@ ssize_t __getdelim(char **__restrict lineptr, size_t *__restrict n, return pos; } + +weak_alias(__getdelim,getdelim); diff --git a/libc/stdio/getwchar.c b/libc/stdio/getwchar.c index 98d9fcba0..642162fed 100644 --- a/libc/stdio/getwchar.c +++ b/libc/stdio/getwchar.c @@ -7,20 +7,18 @@ #include "_stdio.h" -wint_t __getwchar_unlocked(void); - #ifdef __DO_UNLOCKED -weak_alias(__getwchar_unlocked,getwchar_unlocked); -#ifndef __UCLIBC_HAS_THREADS__ -weak_alias(__getwchar_unlocked,getwchar); -#endif - wint_t __getwchar_unlocked(void) { return __fgetwc_unlocked(stdin); } +weak_alias(__getwchar_unlocked,getwchar_unlocked); +#ifndef __UCLIBC_HAS_THREADS__ +weak_alias(__getwchar_unlocked,getwchar); +#endif + #elif defined __UCLIBC_HAS_THREADS__ wint_t getwchar(void) diff --git a/libc/stdio/putchar.c b/libc/stdio/putchar.c index 20f5aadcc..fa6d6c372 100644 --- a/libc/stdio/putchar.c +++ b/libc/stdio/putchar.c @@ -12,11 +12,6 @@ #ifdef __DO_UNLOCKED -weak_alias(__putchar_unlocked,putchar_unlocked); -#ifndef __UCLIBC_HAS_THREADS__ -weak_alias(__putchar_unlocked,putchar); -#endif - int __putchar_unlocked(int c) { register FILE *stream = stdout; @@ -24,6 +19,11 @@ int __putchar_unlocked(int c) return __PUTC_UNLOCKED_MACRO(c, stream); } +weak_alias(__putchar_unlocked,putchar_unlocked); +#ifndef __UCLIBC_HAS_THREADS__ +weak_alias(__putchar_unlocked,putchar); +#endif + #elif defined __UCLIBC_HAS_THREADS__ int putchar(int c) diff --git a/libc/stdio/putwchar.c b/libc/stdio/putwchar.c index 9a563dcf0..47bc173e1 100644 --- a/libc/stdio/putwchar.c +++ b/libc/stdio/putwchar.c @@ -7,20 +7,18 @@ #include "_stdio.h" -extern wint_t __putwchar_unlocked(wchar_t wc); - #ifdef __DO_UNLOCKED -weak_alias(__putwchar_unlocked,putwchar_unlocked); -#ifndef __UCLIBC_HAS_THREADS__ -weak_alias(__putwchar_unlocked,putwchar); -#endif - wint_t __putwchar_unlocked(wchar_t wc) { return __fputwc_unlocked(wc, stdout); } +weak_alias(__putwchar_unlocked,putwchar_unlocked); +#ifndef __UCLIBC_HAS_THREADS__ +weak_alias(__putwchar_unlocked,putwchar); +#endif + #elif defined __UCLIBC_HAS_THREADS__ wint_t putwchar(wchar_t wc) diff --git a/libc/stdlib/stdlib.c b/libc/stdlib/stdlib.c index 9e78fb24e..a749955e2 100644 --- a/libc/stdlib/stdlib.c +++ b/libc/stdlib/stdlib.c @@ -207,6 +207,11 @@ int abs(int j) /**********************************************************************/ #ifdef L_labs +long int labs(long int j) +{ + return (j >= 0) ? j : -j; +} + #if UINT_MAX == ULONG_MAX strong_alias(labs,abs) #endif @@ -219,26 +224,21 @@ strong_alias(labs,llabs) strong_alias(labs,imaxabs) #endif -long int labs(long int j) -{ - return (j >= 0) ? j : -j; -} - #endif /**********************************************************************/ #ifdef L_llabs #if defined(ULLONG_MAX) && (LLONG_MAX > LONG_MAX) -#if (ULLONG_MAX == UINTMAX_MAX) -strong_alias(llabs,imaxabs) -#endif - long long int llabs(long long int j) { return (j >= 0) ? j : -j; } +#if (ULLONG_MAX == UINTMAX_MAX) +strong_alias(llabs,imaxabs) +#endif + #endif /* defined(ULLONG_MAX) && (LLONG_MAX > LONG_MAX) */ #endif @@ -258,6 +258,11 @@ int atoi(const char *nptr) /**********************************************************************/ #ifdef L_atol +long atol(const char *nptr) +{ + return strtol(nptr, (char **) NULL, 10); +} + #if UINT_MAX == ULONG_MAX strong_alias(atol,atoi) #endif @@ -266,11 +271,6 @@ strong_alias(atol,atoi) strong_alias(atol,atoll) #endif -long atol(const char *nptr) -{ - return strtol(nptr, (char **) NULL, 10); -} - #endif /**********************************************************************/ #ifdef L_atoll @@ -288,6 +288,12 @@ long long atoll(const char *nptr) /**********************************************************************/ #if defined(L_strtol) || defined(L_strtol_l) +long __XL(strtol)(const char * __restrict str, char ** __restrict endptr, + int base __LOCALE_PARAM ) +{ + return __XL_NPP(_stdlib_strto_l)(str, endptr, base, 1 __LOCALE_ARG ); +} + #if (ULONG_MAX == UINTMAX_MAX) && !defined(L_strtol_l) strong_alias(strtol,strtoimax) #endif @@ -296,12 +302,6 @@ strong_alias(strtol,strtoimax) strong_alias(__XL(strtol),__XL(strtoll)) #endif -long __XL(strtol)(const char * __restrict str, char ** __restrict endptr, - int base __LOCALE_PARAM ) -{ - return __XL_NPP(_stdlib_strto_l)(str, endptr, base, 1 __LOCALE_ARG ); -} - __XL_ALIAS(strtol) #endif @@ -310,13 +310,6 @@ __XL_ALIAS(strtol) #if defined(ULLONG_MAX) && (LLONG_MAX > LONG_MAX) -#if !defined(L_strtoll_l) -#if (ULLONG_MAX == UINTMAX_MAX) -strong_alias(strtoll,strtoimax) -#endif -strong_alias(strtoll,strtoq) -#endif - long long __XL(strtoll)(const char * __restrict str, char ** __restrict endptr, int base __LOCALE_PARAM ) @@ -325,6 +318,13 @@ long long __XL(strtoll)(const char * __restrict str, __LOCALE_ARG ); } +#if !defined(L_strtoll_l) +#if (ULLONG_MAX == UINTMAX_MAX) +strong_alias(strtoll,strtoimax) +#endif +strong_alias(strtoll,strtoq) +#endif + __XL_ALIAS(strtoll) #endif /* defined(ULLONG_MAX) && (LLONG_MAX > LONG_MAX) */ @@ -333,6 +333,13 @@ __XL_ALIAS(strtoll) /**********************************************************************/ #if defined(L_strtoul) || defined(L_strtoul_l) +unsigned long __XL(strtoul)(const char * __restrict str, + char ** __restrict endptr, int base + __LOCALE_PARAM ) +{ + return __XL_NPP(_stdlib_strto_l)(str, endptr, base, 0 __LOCALE_ARG ); +} + #if (ULONG_MAX == UINTMAX_MAX) && !defined(L_strtoul_l) strong_alias(strtoul,strtoumax) #endif @@ -341,13 +348,6 @@ strong_alias(strtoul,strtoumax) strong_alias(__XL(strtoul),__XL(strtoull)) #endif -unsigned long __XL(strtoul)(const char * __restrict str, - char ** __restrict endptr, int base - __LOCALE_PARAM ) -{ - return __XL_NPP(_stdlib_strto_l)(str, endptr, base, 0 __LOCALE_ARG ); -} - __XL_ALIAS(strtoul) #endif @@ -356,13 +356,6 @@ __XL_ALIAS(strtoul) #if defined(ULLONG_MAX) && (LLONG_MAX > LONG_MAX) -#if !defined(L_strtoull_l) -#if (ULLONG_MAX == UINTMAX_MAX) -strong_alias(strtoull,strtoumax) -#endif -strong_alias(strtoull,strtouq) -#endif - unsigned long long __XL(strtoull)(const char * __restrict str, char ** __restrict endptr, int base __LOCALE_PARAM ) @@ -370,6 +363,13 @@ unsigned long long __XL(strtoull)(const char * __restrict str, return __XL_NPP(_stdlib_strto_ll)(str, endptr, base, 0 __LOCALE_ARG ); } +#if !defined(L_strtoull_l) +#if (ULLONG_MAX == UINTMAX_MAX) +strong_alias(strtoull,strtoumax) +#endif +strong_alias(strtoull,strtouq) +#endif + __XL_ALIAS(strtoull) #endif /* defined(ULLONG_MAX) && (LLONG_MAX > LONG_MAX) */ @@ -953,6 +953,12 @@ size_t wcstombs(char * __restrict s, const wchar_t * __restrict pwcs, size_t n) /**********************************************************************/ #if defined(L_wcstol) || defined(L_wcstol_l) +long __XL(wcstol)(const wchar_t * __restrict str, + wchar_t ** __restrict endptr, int base __LOCALE_PARAM ) +{ + return __XL_NPP(_stdlib_wcsto_l)(str, endptr, base, 1 __LOCALE_ARG ); +} + #if (ULONG_MAX == UINTMAX_MAX) && !defined(L_wcstol_l) strong_alias(wcstol,wcstoimax) #endif @@ -961,12 +967,6 @@ strong_alias(wcstol,wcstoimax) strong_alias(__XL(wcstol),__XL(wcstoll)) #endif -long __XL(wcstol)(const wchar_t * __restrict str, - wchar_t ** __restrict endptr, int base __LOCALE_PARAM ) -{ - return __XL_NPP(_stdlib_wcsto_l)(str, endptr, base, 1 __LOCALE_ARG ); -} - __XL_ALIAS(wcstol) #endif @@ -975,13 +975,6 @@ __XL_ALIAS(wcstol) #if defined(ULLONG_MAX) && (LLONG_MAX > LONG_MAX) -#if !defined(L_wcstoll_l) -#if (ULLONG_MAX == UINTMAX_MAX) -strong_alias(wcstoll,wcstoimax) -#endif -strong_alias(wcstoll,wcstoq) -#endif - long long __XL(wcstoll)(const wchar_t * __restrict str, wchar_t ** __restrict endptr, int base __LOCALE_PARAM ) @@ -990,6 +983,13 @@ long long __XL(wcstoll)(const wchar_t * __restrict str, __LOCALE_ARG ); } +#if !defined(L_wcstoll_l) +#if (ULLONG_MAX == UINTMAX_MAX) +strong_alias(wcstoll,wcstoimax) +#endif +strong_alias(wcstoll,wcstoq) +#endif + __XL_ALIAS(wcstoll) #endif /* defined(ULLONG_MAX) && (LLONG_MAX > LONG_MAX) */ @@ -998,6 +998,13 @@ __XL_ALIAS(wcstoll) /**********************************************************************/ #if defined(L_wcstoul) || defined(L_wcstoul_l) +unsigned long __XL(wcstoul)(const wchar_t * __restrict str, + wchar_t ** __restrict endptr, int base + __LOCALE_PARAM ) +{ + return __XL_NPP(_stdlib_wcsto_l)(str, endptr, base, 0 __LOCALE_ARG ); +} + #if (ULONG_MAX == UINTMAX_MAX) && !defined(L_wcstoul_l) strong_alias(wcstoul,wcstoumax) #endif @@ -1006,13 +1013,6 @@ strong_alias(wcstoul,wcstoumax) strong_alias(__XL(wcstoul),__XL(wcstoull)) #endif -unsigned long __XL(wcstoul)(const wchar_t * __restrict str, - wchar_t ** __restrict endptr, int base - __LOCALE_PARAM ) -{ - return __XL_NPP(_stdlib_wcsto_l)(str, endptr, base, 0 __LOCALE_ARG ); -} - __XL_ALIAS(wcstoul) #endif @@ -1021,13 +1021,6 @@ __XL_ALIAS(wcstoul) #if defined(ULLONG_MAX) && (LLONG_MAX > LONG_MAX) -#if !defined(L_wcstoull_l) -#if (ULLONG_MAX == UINTMAX_MAX) -strong_alias(wcstoull,wcstoumax) -#endif -strong_alias(wcstoull,wcstouq) -#endif - unsigned long long __XL(wcstoull)(const wchar_t * __restrict str, wchar_t ** __restrict endptr, int base __LOCALE_PARAM ) @@ -1035,6 +1028,13 @@ unsigned long long __XL(wcstoull)(const wchar_t * __restrict str, return __XL_NPP(_stdlib_wcsto_ll)(str, endptr, base, 0 __LOCALE_ARG ); } +#if !defined(L_wcstoull_l) +#if (ULLONG_MAX == UINTMAX_MAX) +strong_alias(wcstoull,wcstoumax) +#endif +strong_alias(wcstoull,wcstouq) +#endif + __XL_ALIAS(wcstoull) #endif /* defined(ULLONG_MAX) && (LLONG_MAX > LONG_MAX) */ diff --git a/libc/string/generic/strcmp.c b/libc/string/generic/strcmp.c index 2af550d81..c8212f04b 100644 --- a/libc/string/generic/strcmp.c +++ b/libc/string/generic/strcmp.c @@ -23,10 +23,6 @@ #undef strcmp -#ifdef __LOCALE_C_ONLY -weak_alias(strcmp,strcoll); -#endif /* __LOCALE_C_ONLY */ - /* Compare S1 and S2, returning less than, equal to or greater than zero if S1 is lexicographically less than, equal to or greater than S2. */ @@ -50,3 +46,7 @@ strcmp (p1, p2) return c1 - c2; } + +#ifdef __LOCALE_C_ONLY +weak_alias(strcmp,strcoll); +#endif /* __LOCALE_C_ONLY */ diff --git a/libc/string/wstring.c b/libc/string/wstring.c index 6f54ae615..c9c8548fb 100644 --- a/libc/string/wstring.c +++ b/libc/string/wstring.c @@ -612,10 +612,6 @@ Wchar *Wstrncat(Wchar * __restrict s1, register const Wchar * __restrict s2, #ifdef L_memcmp -#ifndef L_wmemcmp -weak_alias(memcmp,bcmp); -#endif - int Wmemcmp(const Wvoid *s1, const Wvoid *s2, size_t n) { register const Wuchar *r1 = (const Wuchar *) s1; @@ -638,6 +634,10 @@ int Wmemcmp(const Wvoid *s1, const Wvoid *s2, size_t n) #endif } +#ifndef L_wmemcmp +weak_alias(memcmp,bcmp); +#endif + #endif /**********************************************************************/ #ifdef L_wcscmp @@ -649,14 +649,6 @@ int Wmemcmp(const Wvoid *s1, const Wvoid *s2, size_t n) #ifdef L_strcmp -#ifdef __LOCALE_C_ONLY -#ifdef L_wcscmp -weak_alias(wcscmp,wcscoll); -#else /* L_wcscmp */ -weak_alias(strcmp,strcoll); -#endif /* L_wcscmp */ -#endif /* __LOCALE_C_ONLY */ - int Wstrcmp(register const Wchar *s1, register const Wchar *s2) { #ifdef WANT_WIDE @@ -677,6 +669,15 @@ int Wstrcmp(register const Wchar *s1, register const Wchar *s2) return r; #endif } + +#ifdef __LOCALE_C_ONLY +#ifdef L_wcscmp +weak_alias(wcscmp,wcscoll); +#else /* L_wcscmp */ +weak_alias(strcmp,strcoll); +#endif /* L_wcscmp */ +#endif /* __LOCALE_C_ONLY */ + #endif /**********************************************************************/ #ifdef L_wcsncmp @@ -756,10 +757,6 @@ Wvoid *Wmemchr(const Wvoid *s, Wint c, size_t n) #ifdef L_strchr -#ifndef L_wcschr -weak_alias(strchr,index); -#endif - Wchar *Wstrchr(register const Wchar *s, Wint c) { do { @@ -771,6 +768,10 @@ Wchar *Wstrchr(register const Wchar *s, Wint c) return NULL; } +#ifndef L_wcschr +weak_alias(strchr,index); +#endif + #endif /**********************************************************************/ #ifdef L_wcscspn @@ -830,10 +831,6 @@ Wchar *Wstrpbrk(const Wchar *s1, const Wchar *s2) #ifdef L_strrchr -#ifndef L_wcsrchr -weak_alias(strrchr,rindex); -#endif - Wchar *Wstrrchr(register const Wchar *s, Wint c) { register const Wchar *p; @@ -848,6 +845,10 @@ Wchar *Wstrrchr(register const Wchar *s, Wint c) return (Wchar *) p; /* silence the warning */ } +#ifndef L_wcsrchr +weak_alias(strrchr,rindex); +#endif + #endif /**********************************************************************/ #ifdef L_wcsspn @@ -886,10 +887,6 @@ size_t Wstrspn(const Wchar *s1, const Wchar *s2) /* NOTE: This is the simple-minded O(len(s1) * len(s2)) worst-case approach. */ -#ifdef L_wcsstr -weak_alias(wcsstr,wcswcs); -#endif - Wchar *Wstrstr(const Wchar *s1, const Wchar *s2) { register const Wchar *s = s1; @@ -912,6 +909,10 @@ Wchar *Wstrstr(const Wchar *s1, const Wchar *s2) } while (1); } +#ifdef L_wcsstr +weak_alias(wcsstr,wcswcs); +#endif + #endif /**********************************************************************/ #undef Wstrspn @@ -930,10 +931,6 @@ Wchar *Wstrstr(const Wchar *s1, const Wchar *s2) #ifdef L_strtok_r -#ifndef L_wcstok -weak_alias(__strtok_r,strtok_r); -#endif - Wchar *Wstrtok_r(Wchar * __restrict s1, const Wchar * __restrict s2, Wchar ** __restrict next_start) { @@ -967,6 +964,10 @@ Wchar *Wstrtok_r(Wchar * __restrict s1, const Wchar * __restrict s2, #endif } +#ifndef L_wcstok +weak_alias(__strtok_r,strtok_r); +#endif + #endif /**********************************************************************/ /* #ifdef L_wcstok */ @@ -1571,8 +1572,6 @@ int __xpg_strerror_r(int errnum, char *strerrbuf, size_t buflen) /**********************************************************************/ #ifdef L___glibc_strerror_r -weak_alias(__glibc_strerror_r,__strerror_r); - char *__glibc_strerror_r(int errnum, char *strerrbuf, size_t buflen) { __xpg_strerror_r(errnum, strerrbuf, buflen); @@ -1580,6 +1579,7 @@ char *__glibc_strerror_r(int errnum, char *strerrbuf, size_t buflen) return strerrbuf; } +weak_alias(__glibc_strerror_r,__strerror_r); #endif /**********************************************************************/ #ifdef L_memmem @@ -1625,10 +1625,6 @@ void *memmem(const void *haystack, size_t haystacklen, #ifdef L_mempcpy -#ifndef L_wmempcpy -weak_alias(__mempcpy,mempcpy); -#endif - Wvoid *Wmempcpy(Wvoid * __restrict s1, const Wvoid * __restrict s2, size_t n) { register Wchar *r1 = s1; @@ -1648,6 +1644,10 @@ Wvoid *Wmempcpy(Wvoid * __restrict s1, const Wvoid * __restrict s2, size_t n) return r1; } +#ifndef L_wmempcpy +weak_alias(__mempcpy,mempcpy); +#endif + #endif /**********************************************************************/ #ifdef L_memrchr @@ -1737,7 +1737,6 @@ Wchar *Wstpncpy(register Wchar * __restrict s1, /**********************************************************************/ #ifdef L_bzero -weak_alias(__bzero,bzero); void __bzero(void *s, size_t n) { register unsigned char *p = s; @@ -1753,6 +1752,7 @@ void __bzero(void *s, size_t n) --np; } } +weak_alias(__bzero,bzero); #undef np #endif @@ -1902,15 +1902,13 @@ char *strsep(char ** __restrict s1, const char * __restrict s2) #ifdef L_strchrnul -extern Wchar *__Wstrchrnul(register const Wchar *s, Wint c); -weak_alias(__Wstrchrnul, Wstrchrnul); - Wchar *__Wstrchrnul(register const Wchar *s, Wint c) { --s; while (*++s && (*s != ((Wchar)c))); return (Wchar *) s; } +weak_alias(__Wstrchrnul, Wstrchrnul); #endif /**********************************************************************/ @@ -2069,18 +2067,12 @@ extern size_t __wcslcpy(wchar_t *__restrict dst, #ifdef L___wcslcpy #define L_strlcpy #define Wstrlcpy __wcslcpy -#ifdef __LOCALE_C_ONLY -weak_alias(__wcslcpy,wcsxfrm); -#endif #endif #ifdef L_strlcpy #ifndef L___wcslcpy #define Wstrlcpy strlcpy -#ifdef __LOCALE_C_ONLY -weak_alias(strlcpy,strxfrm); -#endif #endif /* OpenBSD function: @@ -2111,6 +2103,14 @@ size_t Wstrlcpy(register Wchar *__restrict dst, return src - src0; } +#ifdef __LOCALE_C_ONLY +#ifdef L___wcslcpy +weak_alias(__wcslcpy,wcsxfrm); +#else +weak_alias(strlcpy,strxfrm); +#endif +#endif + #endif /**********************************************************************/ #if defined(L__string_syssigmsgs) && defined(__UCLIBC_HAS_SIGNUM_MESSAGES__) diff --git a/libc/sysdeps/linux/common/ssp.c b/libc/sysdeps/linux/common/ssp.c index 31833cbb9..899910c96 100644 --- a/libc/sysdeps/linux/common/ssp.c +++ b/libc/sysdeps/linux/common/ssp.c @@ -1,6 +1,6 @@ /* - * Distributed under the terms of the GNU General Public License v2 - * $Header: /var/cvs/uClibc/libc/sysdeps/linux/common/ssp.c,v 1.6 2005/01/11 17:01:53 vapier Exp $ + * Distributed under the terms of the GNU Lesser General Public License + * $Header: $ * * This is a modified version of Hiroaki Etoh's stack smashing routines * implemented for glibc. @@ -12,134 +12,61 @@ * Peter S. Mazinger - <ps.m[@]gmx.net> * Yoann Vandoorselaere - <yoann[@]prelude-ids.org> * Robert Connolly - <robert[@]linuxfromscratch.org> - * Cory Visi <cory@visi.name> - * + * Cory Visi <cory[@]visi.name> + * Mike Frysinger <vapier[@]gentoo.org> */ -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#ifdef __SSP__ -# error ssp.c has to be built w/ -fno-stack-protector -#endif - -#include <stdio.h> #include <string.h> -#include <fcntl.h> #include <unistd.h> -#include <signal.h> -#include <sys/types.h> -#include <sys/un.h> #include <sys/syslog.h> -#include <sys/time.h> -#ifdef __SSP_USE_ERANDOM__ -# include <sys/sysctl.h> -#endif - -#ifdef __PROPOLICE_BLOCK_SEGV__ -# define SSP_SIGTYPE SIGSEGV -#elif __PROPOLICE_BLOCK_KILL__ -# define SSP_SIGTYPE SIGKILL -#else -# define SSP_SIGTYPE SIGABRT -#endif -unsigned long __guard = 0UL; +#include <ssp-internal.h> -/* Use of __* functions from the rest of glibc here avoids - * initialisation problems for executables preloaded with - * libraries that overload the associated standard library - * functions. - */ -#ifdef __UCLIBC__ -extern int __libc_open(__const char *file, int flags, ...); -extern ssize_t __libc_read(int fd, void *buf, size_t count); -extern int __libc_close(int fd); -#else -# define __libc_open(file, flags) __open(file, flags) -# define __libc_read(fd, buf, count) __read(fd, buf, count) -# define __libc_close(fd) __close(fd) -#endif - -void __guard_setup(void) __attribute__ ((constructor)); -void __guard_setup(void) +static __always_inline void block_signals(void) { - size_t size; - - if (__guard != 0UL) - return; + struct sigaction sa; + sigset_t mask; - /* Start with the "terminator canary". */ - __guard = 0xFF0A0D00UL; + sigfillset(&mask); -#ifndef __SSP_QUICK_CANARY__ -# ifdef __SSP_USE_ERANDOM__ - { - int mib[3]; - /* Random is another depth in Linux, hence an array of 3. */ - mib[0] = CTL_KERN; - mib[1] = KERN_RANDOM; - mib[2] = RANDOM_ERANDOM; + sigdelset(&mask, SSP_SIGTYPE); /* Block all signal handlers */ + SIGPROCMASK(SIG_BLOCK, &mask, NULL); /* except SSP_SIGTYPE */ - size = sizeof(unsigned long); - if (__sysctl(mib, 3, &__guard, &size, NULL, 0) != (-1)) - if (__guard != 0UL) - return; - } -# endif /* ifdef __SSP_USE_ERANDOM__ */ - /* - * Attempt to open kernel pseudo random device if one exists before - * opening urandom to avoid system entropy depletion. - */ - { - int fd; + /* Make the default handler associated with the signal handler */ + memset(&sa, 0, sizeof(struct sigaction)); + sigfillset(&sa.sa_mask); /* Block all signals */ + sa.sa_flags = 0; + sa.sa_handler = SIG_DFL; + SIGACTION(SSP_SIGTYPE, &sa, NULL); +} -# ifdef __SSP_USE_ERANDOM__ - if ((fd = __libc_open("/dev/erandom", O_RDONLY)) == (-1)) -# endif - fd = __libc_open("/dev/urandom", O_RDONLY); - if (fd != (-1)) { - size = __libc_read(fd, (char *) &__guard, sizeof(__guard)); - __libc_close(fd); - if (size == sizeof(__guard)) - return; - } - } -#endif /* ifndef __SSP_QUICK_CANARY__ */ +static __always_inline void ssp_write(int fd, const char *msg1, const char *msg2, const char *msg3) +{ + WRITE(fd, msg1, strlen(msg1)); + WRITE(fd, msg2, strlen(msg2)); + WRITE(fd, msg3, strlen(msg3)); + WRITE(fd, "()\n", 3); + openlog("ssp", LOG_CONS | LOG_PID, LOG_USER); + syslog(LOG_INFO, "%s%s%s()", msg1, msg2, msg3); + closelog(); +} - /* Everything failed? Or we are using a weakened model of the - * terminator canary */ - { - struct timeval tv; - gettimeofday(&tv, NULL); - __guard ^= tv.tv_usec ^ tv.tv_sec; - } +static __always_inline void terminate(void) +{ + (void) KILL(GETPID(), SSP_SIGTYPE); + EXIT(127); } -void __stack_smash_handler(char func[], int damaged __attribute__ ((unused))); -void __stack_smash_handler(char func[], int damaged) +void __attribute__ ((noreturn)) __stack_smash_handler(char func[], int damaged __attribute__ ((unused))); +void __attribute__ ((noreturn)) __stack_smash_handler(char func[], int damaged) { extern char *__progname; const char message[] = ": stack smashing attack in function "; - struct sigaction sa; - sigset_t mask; - sigfillset(&mask); + block_signals(); - sigdelset(&mask, SSP_SIGTYPE); /* Block all signal handlers */ - sigprocmask(SIG_BLOCK, &mask, NULL); /* except SSP_SIGTYPE */ - - /* Print error message to stderr and syslog */ - fprintf(stderr, "%s%s%s()\n", __progname, message, func); - syslog(LOG_INFO, "%s%s%s()", __progname, message, func); + ssp_write(STDERR_FILENO, __progname, message, func); - /* Make the default handler associated with the signal handler */ - memset(&sa, 0, sizeof(struct sigaction)); - sigfillset(&sa.sa_mask); /* Block all signals */ - sa.sa_flags = 0; - sa.sa_handler = SIG_DFL; - sigaction(SSP_SIGTYPE, &sa, NULL); - (void) kill(getpid(), SSP_SIGTYPE); - _exit(127); + while(1) + terminate(); } diff --git a/libc/unistd/getopt.c b/libc/unistd/getopt.c index 504f3764c..0dc0e0509 100644 --- a/libc/unistd/getopt.c +++ b/libc/unistd/getopt.c @@ -26,10 +26,13 @@ * Modified once again for uClibc by Erik Andersen 8/7/02 */ +#include <features.h> #include <stdio.h> #include <string.h> #include <stdlib.h> +#ifdef __UCLIBC_HAS_GETTEXT_AWARENESS__ #include <libintl.h> +#endif #ifdef __UCLIBC_MJN3_ONLY__ #warning TODO: Enable gettext awareness. diff --git a/libc/unistd/sysconf.c b/libc/unistd/sysconf.c index f5b49a10f..902697b45 100644 --- a/libc/unistd/sysconf.c +++ b/libc/unistd/sysconf.c @@ -29,7 +29,9 @@ #include <unistd.h> #include <sys/sysinfo.h> #include <sys/types.h> +#ifdef __UCLIBC_HAS_REGEX__ #include <regex.h> +#endif #ifndef __UCLIBC_CLK_TCK_CONST #error __UCLIBC_CLK_TCK_CONST not defined! |