From c3ddc18409b71db9e2fc863a7ff94a89b3c316ce Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Wed, 11 Mar 2015 22:58:32 +0100 Subject: spawn.h: Fix !_GNU_SOURCE compilation Signed-off-by: Bernhard Reutner-Fischer --- include/spawn.h | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/include/spawn.h b/include/spawn.h index 95fff356f..3de375b41 100644 --- a/include/spawn.h +++ b/include/spawn.h @@ -66,15 +66,6 @@ typedef struct # define POSIX_SPAWN_USEVFORK 0x40 #endif - -#define __POSIX_SPAWN_MASK (POSIX_SPAWN_RESETIDS \ - | POSIX_SPAWN_SETPGROUP \ - | POSIX_SPAWN_SETSIGDEF \ - | POSIX_SPAWN_SETSIGMASK \ - | POSIX_SPAWN_SETSCHEDPARAM \ - | POSIX_SPAWN_SETSCHEDULER \ - | POSIX_SPAWN_USEVFORK) - __BEGIN_DECLS /* Spawn a new process executing PATH with the attributes describes in *ATTRP. @@ -170,12 +161,27 @@ static inline int posix_spawnattr_setflags (posix_spawnattr_t *_attr, short int __flags) { +#ifdef POSIX_SPAWN_USEVFORK +# define __POSIX_SPAWN_USEVFORK POSIX_SPAWN_USEVFORK +#else +# define __POSIX_SPAWN_USEVFORK 0 +#endif +#define __POSIX_SPAWN_MASK (POSIX_SPAWN_RESETIDS \ + | POSIX_SPAWN_SETPGROUP \ + | POSIX_SPAWN_SETSIGDEF \ + | POSIX_SPAWN_SETSIGMASK \ + | POSIX_SPAWN_SETSCHEDPARAM \ + | POSIX_SPAWN_SETSCHEDULER \ + | __POSIX_SPAWN_USEVFORK) + /* Check no invalid bits are set. */ if (__flags & ~__POSIX_SPAWN_MASK) return EINVAL; _attr->__flags = __flags; return 0; +#undef __POSIX_SPAWN_USEVFORK +#undef __POSIX_SPAWN_MASK } /* Get process group ID from the attribute structure. */ -- cgit v1.2.3 From 8c66e0a6c7987cda9df8c88e84b3d50d573c1dbb Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Wed, 11 Mar 2015 22:59:51 +0100 Subject: buildsys: create linker script with proper flags We were not passing the correct use-ld and -m{32,64,...} when creating the linker script. Revisit for gold later on anyway. Signed-off-by: Bernhard Reutner-Fischer --- Makerules | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Makerules b/Makerules index 1596988d2..cc543889c 100644 --- a/Makerules +++ b/Makerules @@ -326,9 +326,10 @@ cmd_hcompile.o = $(HOSTCC) $(filter-out $(PHONY),$<) $(DEPS-$(notdir $@)) -c -o define create-lds $(Q)$(RM) $@.lds - $(Q)$(CC) -nostdlib -nostartfiles -shared -Wl,-z,combreloc \ - -Wl,-z,relro -Wl,--hash-style=gnu -Wl,-z,defs \ - -Wl,--verbose 2>&1 | LC_ALL=C \ + $(Q)$(CC) $(LDFLAG-fuse-ld) $(CPU_LDFLAGS-y) \ + -nostdlib -nostartfiles -shared -Wl,-z,combreloc \ + -Wl,-z,relro $(CFLAG_-Wl--hash-style=gnu) -Wl,-z,defs \ + -x c /dev/null -Wl,--verbose 2>&1 | LC_ALL=C \ $(SED) -e '/^=========/,/^=========/!d;/^=========/d' \ -e 's/^\([ ]*\)\. = .* + SIZEOF_HEADERS;/&\n\1$(SYMBOL_PREFIX)_begin = . - SIZEOF_HEADERS;/' > $@.lds endef -- cgit v1.2.3 From 21cbb6fe887a30f0777521ec10f0d0d9c2a7da7e Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Fri, 13 Mar 2015 21:03:10 +0100 Subject: unistd.h: put getppid under XOPEN2K8 Add __LEAF to all __THROW, introduce non-leaf __THROWNL Adjust affected spots accordingly. Signed-off-by: Bernhard Reutner-Fischer --- include/dlfcn.h | 6 +- include/fcntl.h | 2 +- include/iconv.h | 4 +- include/setjmp.h | 19 +++--- include/stdio.h | 51 ++++++++------- include/stdlib.h | 2 +- include/sys/cdefs.h | 24 ++++++- include/sys/wait.h | 18 ++++-- include/ucontext.h | 6 +- include/unistd.h | 75 ++++++++++++---------- include/wchar.h | 8 +-- libc/sysdeps/linux/common/getrusage.c | 1 + libpthread/linuxthreads.old/semaphore.h | 4 +- .../linuxthreads.old/sysdeps/pthread/pthread.h | 36 +++++------ libpthread/linuxthreads/semaphore.h | 4 +- libpthread/linuxthreads/sysdeps/pthread/pthread.h | 36 +++++------ libpthread/nptl/semaphore.h | 4 +- libpthread/nptl/sysdeps/pthread/pthread.h | 64 +++++++++--------- 18 files changed, 202 insertions(+), 162 deletions(-) diff --git a/include/dlfcn.h b/include/dlfcn.h index 41d0d6fa4..241ec5480 100644 --- a/include/dlfcn.h +++ b/include/dlfcn.h @@ -55,11 +55,11 @@ __BEGIN_DECLS /* Open the shared object FILE and map it in; return a handle that can be passed to `dlsym' to get symbol values from it. */ -extern void *dlopen (const char *__file, int __mode) __THROW; +extern void *dlopen (const char *__file, int __mode) __THROWNL; /* Unmap and close a shared object opened by `dlopen'. The handle cannot be used again after calling `dlclose'. */ -extern int dlclose (void *__handle) __THROW __nonnull ((1)); +extern int dlclose (void *__handle) __THROWNL __nonnull ((1)); /* Find the run-time address in the shared object HANDLE refers to of the symbol called NAME. */ @@ -68,7 +68,7 @@ extern void *dlsym (void *__restrict __handle, #if 0 /*def __USE_GNU*/ /* Like `dlopen', but request object to be allocated in a new namespace. */ -extern void *dlmopen (Lmid_t __nsid, const char *__file, int __mode) __THROW; +extern void *dlmopen (Lmid_t __nsid, const char *__file, int __mode) __THROWNL; /* Find the run-time address in the shared object HANDLE refers to of the symbol called NAME with VERSION. */ diff --git a/include/fcntl.h b/include/fcntl.h index 04fc2c06d..11000ddb5 100644 --- a/include/fcntl.h +++ b/include/fcntl.h @@ -221,7 +221,7 @@ extern int posix_fadvise64 (int __fd, __off64_t __offset, __off64_t __len, /* Reserve storage for the data of the file associated with FD. - This function is a possible cancellation points and therefore not + This function is a possible cancellation point and therefore not marked with __THROW. */ # ifndef __USE_FILE_OFFSET64 extern int posix_fallocate (int __fd, __off_t __offset, __off_t __len); diff --git a/include/iconv.h b/include/iconv.h index d850de56e..5ab4c6cb9 100644 --- a/include/iconv.h +++ b/include/iconv.h @@ -36,7 +36,7 @@ typedef void *iconv_t; /* Allocate descriptor for code conversion from codeset FROMCODE to codeset TOCODE. - This function is a possible cancellation points and therefore not + This function is a possible cancellation point and therefore not marked with __THROW. */ extern iconv_t iconv_open (const char *__tocode, const char *__fromcode); @@ -50,7 +50,7 @@ extern size_t iconv (iconv_t __cd, char **__restrict __inbuf, /* Free resources allocated for descriptor CD for code conversion. - This function is a possible cancellation points and therefore not + This function is a possible cancellation point and therefore not marked with __THROW. */ extern int iconv_close (iconv_t __cd); diff --git a/include/setjmp.h b/include/setjmp.h index c9501379e..71c1d35cb 100644 --- a/include/setjmp.h +++ b/include/setjmp.h @@ -49,19 +49,20 @@ typedef struct __jmp_buf_tag jmp_buf[1]; /* Store the calling environment in ENV, also saving the signal mask. Return 0. */ -extern int setjmp (jmp_buf __env) __THROW; +extern int setjmp (jmp_buf __env) __THROWNL; __END_NAMESPACE_STD /* Store the calling environment in ENV, also saving the signal mask if SAVEMASK is nonzero. Return 0. This is the internal name for `sigsetjmp'. */ -extern int __sigsetjmp (struct __jmp_buf_tag __env[1], int __savemask) __THROW; +extern int __sigsetjmp (struct __jmp_buf_tag __env[1], int __savemask) + __THROWNL; #ifndef __FAVOR_BSD /* Store the calling environment in ENV, not saving the signal mask. Return 0. */ -extern int _setjmp (struct __jmp_buf_tag __env[1]) __THROW; +extern int _setjmp (struct __jmp_buf_tag __env[1]) __THROWNL; /* Do not save the signal mask. This is equivalent to the `_setjmp' BSD function. */ @@ -79,7 +80,7 @@ __BEGIN_NAMESPACE_STD /* Jump to the environment saved in ENV, making the `setjmp' call there return VAL, or 1 if VAL is 0. */ extern void longjmp (struct __jmp_buf_tag __env[1], int __val) - __THROW __attribute__ ((__noreturn__)); + __THROWNL __attribute__ ((__noreturn__)); __END_NAMESPACE_STD @@ -88,7 +89,7 @@ __END_NAMESPACE_STD the signal mask. But it is how ENV was saved that determines whether `longjmp' restores the mask; `_longjmp' is just an alias. */ extern void _longjmp (struct __jmp_buf_tag __env[1], int __val) - __THROW __attribute__ ((__noreturn__)); + __THROWNL __attribute__ ((__noreturn__)); #endif @@ -107,16 +108,16 @@ typedef struct __jmp_buf_tag sigjmp_buf[1]; Restore the signal mask if that sigsetjmp call saved it. This is just an alias `longjmp'. */ extern void siglongjmp (sigjmp_buf __env, int __val) - __THROW __attribute__ ((__noreturn__)); + __THROWNL __attribute__ ((__noreturn__)); #endif /* Use POSIX. */ __END_DECLS #ifdef _LIBC -extern void __longjmp(__jmp_buf __env, int __val) attribute_noreturn; +extern void __longjmp(__jmp_buf __env, int __val) __THROWNL attribute_noreturn; libc_hidden_proto(__longjmp) -extern __typeof(longjmp) __libc_longjmp attribute_noreturn; -extern __typeof(siglongjmp) __libc_siglongjmp attribute_noreturn; +extern __typeof(longjmp) __libc_longjmp __THROWNL attribute_noreturn; +extern __typeof(siglongjmp) __libc_siglongjmp __THROWNL attribute_noreturn; extern void _longjmp_unwind(jmp_buf __env, int __val); libc_hidden_proto(_longjmp_unwind) extern int __sigjmp_save(sigjmp_buf __env, int __savemask) attribute_hidden; diff --git a/include/stdio.h b/include/stdio.h index 75c146482..9aae5abf4 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -157,7 +157,7 @@ libc_hidden_proto(renameat) __BEGIN_NAMESPACE_STD /* Create a temporary file and open it read/write. - This function is a possible cancellation points and therefore not + This function is a possible cancellation point and therefore not marked with __THROW. */ #ifndef __USE_FILE_OFFSET64 extern FILE *tmpfile (void) __wur; @@ -345,8 +345,8 @@ extern int printf (const char *__restrict __format, ...); libc_hidden_proto(printf) /* Write formatted output to S. */ extern int sprintf (char *__restrict __s, - const char *__restrict __format, ...) - __THROW __attribute__ ((__format__ (__printf__, 2, 3))); + const char *__restrict __format, ...) __THROWNL + __attribute__ ((__format__ (__printf__, 2, 3))); libc_hidden_proto(sprintf) /* Write formatted output to S from argument list ARG. @@ -363,8 +363,8 @@ libc_hidden_proto(vfprintf) extern int vprintf (const char *__restrict __format, __gnuc_va_list __arg); /* Write formatted output to S from argument list ARG. */ extern int vsprintf (char *__restrict __s, const char *__restrict __format, - __gnuc_va_list __arg) - __THROW __attribute__ ((__format__ (__printf__, 2, 0))); + __gnuc_va_list __arg) __THROWNL + __attribute__ ((__format__ (__printf__, 2, 0))); __END_NAMESPACE_STD #if defined __USE_BSD || defined __USE_ISOC99 || defined __USE_UNIX98 @@ -372,12 +372,12 @@ __BEGIN_NAMESPACE_C99 /* Maximum chars of output to write in MAXLEN. */ extern int snprintf (char *__restrict __s, size_t __maxlen, const char *__restrict __format, ...) - __THROW __attribute__ ((__format__ (__printf__, 3, 4))); + __THROWNL __attribute__ ((__format__ (__printf__, 3, 4))); libc_hidden_proto(snprintf) extern int vsnprintf (char *__restrict __s, size_t __maxlen, const char *__restrict __format, __gnuc_va_list __arg) - __THROW __attribute__ ((__format__ (__printf__, 3, 0))); + __THROWNL __attribute__ ((__format__ (__printf__, 3, 0))); libc_hidden_proto(vsnprintf) __END_NAMESPACE_C99 #endif @@ -387,26 +387,24 @@ __END_NAMESPACE_C99 Store the address of the string in *PTR. */ extern int vasprintf (char **__restrict __ptr, const char *__restrict __f, __gnuc_va_list __arg) - __THROW __attribute__ ((__format__ (__printf__, 2, 0))) __wur; + __THROWNL __attribute__ ((__format__ (__printf__, 2, 0))) __wur; libc_hidden_proto(vasprintf) #if 0 /* uClibc: disabled */ extern int __asprintf (char **__restrict __ptr, const char *__restrict __fmt, ...) - __THROW __attribute__ ((__format__ (__printf__, 2, 3))) __wur; + __THROWNL __attribute__ ((__format__ (__printf__, 2, 3))) __wur; #endif extern int asprintf (char **__restrict __ptr, const char *__restrict __fmt, ...) - __THROW __attribute__ ((__format__ (__printf__, 2, 3))) __wur; + __THROWNL __attribute__ ((__format__ (__printf__, 2, 3))) __wur; libc_hidden_proto(asprintf) #endif #ifdef __USE_XOPEN2K8 /* Write formatted output to a file descriptor. - These functions are not part of POSIX and therefore no official - cancellation point. But due to similarity with an POSIX interface - or due to the implementation they are cancellation points and - therefore not marked with __THROW. */ + This function is a possible cancellation point and therefore not + marked with __THROW. */ extern int vdprintf (int __fd, const char *__restrict __fmt, __gnuc_va_list __arg) __attribute__ ((__format__ (__printf__, 2, 0))); @@ -570,12 +568,21 @@ extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream) __wur; libc_hidden_proto(fgets) +#if !defined __USE_ISOC11 \ + || (defined __cplusplus && __cplusplus <= 201103L) /* Get a newline-terminated string from stdin, removing the newline. DO NOT USE THIS FUNCTION!! There is no limit on how much it will read. + The function has been officially removed in ISO C11. This opportunity + is used to also remove it from the GNU feature list. It is now only + available when explicitly using an old ISO C, Unix, or POSIX standard. + GCC defines _GNU_SOURCE when building C++ code and the function is still + in C++11, so it is also available for C++. + This function is a possible cancellation point and therefore not marked with __THROW. */ -extern char *gets (char *__s) __wur; +extern char *gets (char *__s) __wur __attribute_deprecated__; +#endif __END_NAMESPACE_STD #ifdef __USE_GNU @@ -628,21 +635,21 @@ libc_hidden_proto(getline) __BEGIN_NAMESPACE_STD /* Write a string to STREAM. - This function is a possible cancellation points and therefore not + This function is a possible cancellation point and therefore not marked with __THROW. */ extern int fputs (const char *__restrict __s, FILE *__restrict __stream); libc_hidden_proto(fputs) /* Write a string, followed by a newline, to stdout. - This function is a possible cancellation points and therefore not + This function is a possible cancellation point and therefore not marked with __THROW. */ extern int puts (const char *__s); /* Push a character back onto the input buffer of STREAM. - This function is a possible cancellation points and therefore not + This function is a possible cancellation point and therefore not marked with __THROW. */ extern int ungetc (int __c, FILE *__stream); libc_hidden_proto(ungetc) @@ -650,14 +657,14 @@ libc_hidden_proto(ungetc) /* Read chunks of generic data from STREAM. - This function is a possible cancellation points and therefore not + This function is a possible cancellation point and therefore not marked with __THROW. */ extern size_t fread (void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __stream) __wur; libc_hidden_proto(fread) /* Write chunks of generic data to STREAM. - This function is a possible cancellation points and therefore not + This function is a possible cancellation point and therefore not marked with __THROW. */ extern size_t fwrite (const void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __s) __wur; @@ -860,11 +867,11 @@ struct obstack; /* See . */ /* Write formatted output to an obstack. */ extern int obstack_printf (struct obstack *__restrict __obstack, const char *__restrict __format, ...) - __THROW __attribute__ ((__format__ (__printf__, 2, 3))); + __THROWNL __attribute__ ((__format__ (__printf__, 2, 3))); extern int obstack_vprintf (struct obstack *__restrict __obstack, const char *__restrict __format, __gnuc_va_list __args) - __THROW __attribute__ ((__format__ (__printf__, 2, 0))); + __THROWNL __attribute__ ((__format__ (__printf__, 2, 0))); libc_hidden_proto(obstack_vprintf) #endif /* USE_GNU && UCLIBC_HAS_OBSTACK. */ diff --git a/include/stdlib.h b/include/stdlib.h index b2d70204e..2065dfa2d 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -38,7 +38,7 @@ __BEGIN_DECLS #ifndef __need_malloc_and_calloc #define _STDLIB_H 1 -#if defined __USE_XOPEN && !defined _SYS_WAIT_H +#if (defined __USE_XOPEN || defined __USE_XOPEN2K8) && !defined _SYS_WAIT_H /* XPG requires a few symbols from being defined. */ # include # include diff --git a/include/sys/cdefs.h b/include/sys/cdefs.h index 6f81b6a7c..4da981f9a 100644 --- a/include/sys/cdefs.h +++ b/include/sys/cdefs.h @@ -37,20 +37,33 @@ #ifdef __GNUC__ +/* All functions, except those with callbacks or those that + synchronize memory, are leaf functions. */ +# if __GNUC_PREREQ (4, 6) && !defined _LIBC +# define __LEAF , __leaf__ +# define __LEAF_ATTR __attribute__ ((__leaf__)) +# else +# define __LEAF +# define __LEAF_ATTR +# endif + /* GCC can always grok prototypes. For C++ programs we add throw() to help it optimize the function calls. But this works only with gcc 2.8.x and egcs. For gcc 3.2 and up we even mark C functions as non-throwing using a function attribute since programs can use the -fexceptions options for C code as well. */ # if !defined __cplusplus && __GNUC_PREREQ (3, 3) -# define __THROW __attribute__ ((__nothrow__)) -# define __NTH(fct) __attribute__ ((__nothrow__)) fct +# define __THROW __attribute__ ((__nothrow__ __LEAF)) +# define __THROWNL __attribute__ ((__nothrow__)) +# define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct # else # if defined __cplusplus && __GNUC_PREREQ (2,8) # define __THROW throw () -# define __NTH(fct) fct throw () +# define __THROWNL throw () +# define __NTH(fct) __LEAF_ATTR fct throw () # else # define __THROW +# define __THROWNL # define __NTH(fct) fct # endif # endif @@ -60,6 +73,7 @@ # define __inline /* No inline functions. */ # define __THROW +# define __THROWNL # define __NTH(fct) fct #endif /* GCC. */ @@ -165,9 +179,13 @@ # ifdef __cplusplus # define __REDIRECT_NTH(name, proto, alias) \ name proto __THROW __asm__ (__ASMNAME (#alias)) +# define __REDIRECT_NTHNL(name, proto, alias) \ + name proto __THROWNL __asm__ (__ASMNAME (#alias)) # else # define __REDIRECT_NTH(name, proto, alias) \ name proto __asm__ (__ASMNAME (#alias)) __THROW +# define __REDIRECT_NTHNL(name, proto, alias) \ + name proto __asm__ (__ASMNAME (#alias)) __THROWNL # endif # define __ASMNAME(cname) __ASMNAME2 (__USER_LABEL_PREFIX__, cname) # define __ASMNAME2(prefix, cname) __STRING (prefix) cname diff --git a/include/sys/wait.h b/include/sys/wait.h index b3c2b973a..f7a420b93 100644 --- a/include/sys/wait.h +++ b/include/sys/wait.h @@ -28,10 +28,9 @@ __BEGIN_DECLS #include -#include /* These macros could also be defined in . */ -#if !defined _STDLIB_H || !defined __USE_XOPEN +#if !defined _STDLIB_H || (!defined __USE_XOPEN && !defined __USE_XOPEN2K8) /* This will define the `W*' macros for the flag bits to `waitpid', `wait3', and `wait4'. */ # include @@ -97,7 +96,7 @@ typedef union #endif /* The following values are used by the `waitid' function. */ -#if defined __USE_SVID || defined __USE_XOPEN +#if defined __USE_SVID || defined __USE_XOPEN || defined __USE_XOPEN2K8 typedef enum { P_ALL, /* Wait for any child. */ @@ -141,9 +140,15 @@ extern __typeof(waitpid) __waitpid_nocancel attribute_hidden; libc_hidden_proto(waitpid) #endif -#if defined __USE_SVID || defined __USE_XOPEN +#if defined __USE_SVID || defined __USE_XOPEN || defined __USE_XOPEN2K8 +# ifndef __id_t_defined +# include + typedef __id_t id_t; +# define __id_t_defined +# endif # define __need_siginfo_t # include + /* Wait for a childing matching IDTYPE and ID to change the status and place appropriate information in *INFOP. If IDTYPE is P_PID, match any process whose process ID is ID. @@ -160,19 +165,20 @@ extern int waitid (idtype_t __idtype, __id_t __id, siginfo_t *__infop, #endif #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED +struct rusage; /* Wait for a child to exit. When one does, put its status in *STAT_LOC and return its process ID. For errors return (pid_t) -1. If USAGE is not nil, store information about the child's resource usage there. If the WUNTRACED bit is set in OPTIONS, return status for stopped children; otherwise don't. */ extern __pid_t wait3 (__WAIT_STATUS __stat_loc, int __options, - struct rusage * __usage) __THROW; + struct rusage * __usage) __THROWNL; #endif #ifdef __USE_BSD /* PID is like waitpid. Other args are like wait3. */ extern __pid_t wait4 (__pid_t __pid, __WAIT_STATUS __stat_loc, int __options, - struct rusage *__usage) __THROW; + struct rusage *__usage) __THROWNL; #endif /* Use BSD. */ #ifdef _LIBC diff --git a/include/ucontext.h b/include/ucontext.h index f11db7794..4ce114ef1 100644 --- a/include/ucontext.h +++ b/include/ucontext.h @@ -31,15 +31,15 @@ __BEGIN_DECLS /* Get user context and store it in variable pointed to by UCP. */ -extern int getcontext (ucontext_t *__ucp) __THROW; +extern int getcontext (ucontext_t *__ucp) __THROWNL; /* Set user context from information of variable pointed to by UCP. */ -extern int setcontext (const ucontext_t *__ucp) __THROW; +extern int setcontext (const ucontext_t *__ucp) __THROWNL; /* Save current context in context variable pointed to by OUCP and set context from variable pointed to by UCP. */ extern int swapcontext (ucontext_t *__restrict __oucp, - const ucontext_t *__restrict __ucp) __THROW; + const ucontext_t *__restrict __ucp) __THROWNL; /* Manipulate user context UCP to continue with calling functions FUNC and the ARGC-1 parameters following ARGC when the context is used diff --git a/include/unistd.h b/include/unistd.h index 967e058a3..3793d2d3e 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -206,7 +206,7 @@ __BEGIN_DECLS #include /* Get the environment definitions from Unix98. */ -#ifdef __USE_UNIX98 +#if defined __USE_UNIX98 || defined __USE_XOPEN2K # include #endif @@ -266,7 +266,7 @@ typedef __pid_t pid_t; # endif #endif /* X/Open */ -#if defined __USE_MISC || defined __USE_XOPEN_EXTENDED +#if defined __USE_MISC || defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K # ifndef __intptr_t_defined typedef __intptr_t intptr_t; # define __intptr_t_defined @@ -387,7 +387,7 @@ extern __typeof(write) __write_nocancel attribute_hidden; libc_hidden_proto(write) #endif -#ifdef __USE_UNIX98 +#if defined __USE_UNIX98 || defined __USE_XOPEN2K8 # ifndef __USE_FILE_OFFSET64 /* Read NBYTES into BUF from FD at the given position OFFSET without changing the file pointer. Return the number read, -1 for errors @@ -469,8 +469,9 @@ libc_hidden_proto(alarm) extern unsigned int sleep (unsigned int __seconds); libc_hidden_proto(sleep) -#if (defined __USE_BSD || defined __USE_XOPEN_EXTENDED) \ - && defined __UCLIBC_SUSV3_LEGACY__ +#if (defined __USE_BSD \ + || (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8) \ + ) && defined __UCLIBC_SUSV3_LEGACY__ /* Set an alarm to go off (generating a SIGALRM signal) in VALUE microseconds. If INTERVAL is nonzero, when the alarm goes off, the timer is reset to go off every INTERVAL microseconds thereafter. @@ -500,7 +501,7 @@ extern int chown (const char *__file, __uid_t __owner, __gid_t __group) __THROW __nonnull ((1)) __wur; libc_hidden_proto(chown) -#if defined __USE_BSD || defined __USE_XOPEN_EXTENDED +#if defined __USE_BSD || defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8 /* Change the owner and group of the file that FD is open on. */ extern int fchown (int __fd, __uid_t __owner, __gid_t __group) __THROW __wur; @@ -525,7 +526,7 @@ libc_hidden_proto(fchownat) extern int chdir (const char *__path) __THROW __nonnull ((1)) __wur; libc_hidden_proto(chdir) -#if defined __USE_BSD || defined __USE_XOPEN_EXTENDED +#if defined __USE_BSD || defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8 /* Change the process's working directory to the one FD is open on. */ extern int fchdir (int __fd) __THROW __wur; libc_hidden_proto(fchdir) @@ -548,7 +549,7 @@ libc_hidden_proto(getcwd) extern char *get_current_dir_name (void) __THROW; #endif -#if 0 /*defined __USE_BSD || defined __USE_XOPEN_EXTENDED*/ +#if 0 /*defined __USE_BSD || (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8)*/ /* Put the absolute pathname of the current working directory in BUF. If successful, return BUF. If not, put an error message in BUF and return NULL. BUF should be at least PATH_MAX bytes long. */ @@ -581,52 +582,53 @@ extern char **environ; /* Replace the current process, executing PATH with arguments ARGV and environment ENVP. ARGV and ENVP are terminated by NULL pointers. */ extern int execve (const char *__path, char *const __argv[], - char *const __envp[]) __THROW __nonnull ((1)); + char *const __envp[]) __THROW __nonnull ((1, 2)); libc_hidden_proto(execve) #if 0 /*def __USE_XOPEN2K8*/ /* Execute the file FD refers to, overlaying the running program image. ARGV and ENVP are passed to the new program, as for `execve'. */ extern int fexecve (int __fd, char *const __argv[], char *const __envp[]) - __THROW; + __THROW __nonnull ((2)); #endif /* Execute PATH with arguments ARGV and environment from `environ'. */ extern int execv (const char *__path, char *const __argv[]) - __THROW __nonnull ((1)); + __THROW __nonnull ((1, 2)); libc_hidden_proto(execv) /* Execute PATH with all arguments after PATH until a NULL pointer, and the argument after that for environment. */ extern int execle (const char *__path, const char *__arg, ...) - __THROW __nonnull ((1)); + __THROW __nonnull ((1, 2)); libc_hidden_proto(execle) /* Execute PATH with all arguments after PATH until a NULL pointer and environment from `environ'. */ extern int execl (const char *__path, const char *__arg, ...) - __THROW __nonnull ((1)); + __THROW __nonnull ((1, 2)); libc_hidden_proto(execl) /* Execute FILE, searching in the `PATH' environment variable if it contains no slashes, with arguments ARGV and environment from `environ'. */ extern int execvp (const char *__file, char *const __argv[]) - __THROW __nonnull ((1)); + __THROW __nonnull ((1, 2)); libc_hidden_proto(execvp) /* Execute FILE, searching in the `PATH' environment variable if it contains no slashes, with all arguments after FILE until a NULL pointer and environment from `environ'. */ extern int execlp (const char *__file, const char *__arg, ...) - __THROW __nonnull ((1)); + __THROW __nonnull ((1, 2)); libc_hidden_proto(execlp) #ifdef __USE_GNU /* Execute FILE, searching in the `PATH' environment variable if it contains no slashes, with arguments ARGV and environment from a pointer */ -extern int execvpe (__const char *__file, char *__const __argv[], char *__const __envp[]) - __THROW __nonnull ((1)); +extern int execvpe (const char *__file, char *const __argv[], + char *const __envp[]) + __THROW __nonnull ((1, 2)); libc_hidden_proto(execvpe) #endif @@ -685,7 +687,7 @@ extern __pid_t __REDIRECT_NTH (getpgrp, (__pid_t __pid), __getpgid); /* Get the process group ID of process PID. */ extern __pid_t __getpgid (__pid_t __pid) __THROW; -#ifdef __USE_XOPEN_EXTENDED +#if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8 extern __pid_t getpgid (__pid_t __pid) __THROW; #endif @@ -731,7 +733,7 @@ extern int __REDIRECT_NTH (setpgrp, (__pid_t __pid, __pid_t __pgrp), setpgid); extern __pid_t setsid (void) __THROW; libc_hidden_proto(setsid) -#ifdef __USE_XOPEN_EXTENDED +#if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8 /* Return the session ID of the given process. */ extern __pid_t getsid (__pid_t __pid) __THROW; libc_hidden_proto(getsid) @@ -768,37 +770,37 @@ extern int group_member (__gid_t __gid) __THROW; If the calling process is the super-user, set the real and effective user IDs, and the saved set-user-ID to UID; if not, the effective user ID is set to UID. */ -extern int setuid (__uid_t __uid) __THROW; +extern int setuid (__uid_t __uid) __THROW __wur; #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED /* Set the real user ID of the calling process to RUID, and the effective user ID of the calling process to EUID. */ -extern int setreuid (__uid_t __ruid, __uid_t __euid) __THROW; +extern int setreuid (__uid_t __ruid, __uid_t __euid) __THROW __wur; libc_hidden_proto(setreuid) #endif #if defined __USE_BSD || defined __USE_XOPEN2K /* Set the effective user ID of the calling process to UID. */ -extern int seteuid (__uid_t __uid) __THROW; +extern int seteuid (__uid_t __uid) __THROW __wur; libc_hidden_proto(seteuid) -#endif /* Use BSD. */ +#endif /* Set the group ID of the calling process to GID. If the calling process is the super-user, set the real and effective group IDs, and the saved set-group-ID to GID; if not, the effective group ID is set to GID. */ -extern int setgid (__gid_t __gid) __THROW; +extern int setgid (__gid_t __gid) __THROW __wur; #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED /* Set the real group ID of the calling process to RGID, and the effective group ID of the calling process to EGID. */ -extern int setregid (__gid_t __rgid, __gid_t __egid) __THROW; +extern int setregid (__gid_t __rgid, __gid_t __egid) __THROW __wur; libc_hidden_proto(setregid) #endif #if defined __USE_BSD || defined __USE_XOPEN2K /* Set the effective group ID of the calling process to GID. */ -extern int setegid (__gid_t __gid) __THROW; +extern int setegid (__gid_t __gid) __THROW __wur; #endif /* Use BSD. */ #ifdef __USE_GNU @@ -816,14 +818,14 @@ extern int getresgid (__gid_t *__rgid, __gid_t *__egid, __gid_t *__sgid) /* Set the real user ID, effective user ID, and saved-set user ID, of the calling process to RUID, EUID, and SUID, respectively. */ extern int setresuid (__uid_t __ruid, __uid_t __euid, __uid_t __suid) - __THROW; + __THROW __wur; libc_hidden_proto(setresuid) #endif /* Set the real group ID, effective group ID, and saved-set group ID, of the calling process to RGID, EGID, and SGID, respectively. */ extern int setresgid (__gid_t __rgid, __gid_t __egid, __gid_t __sgid) - __THROW; + __THROW __wur; libc_hidden_proto(setresgid) #endif @@ -832,7 +834,7 @@ libc_hidden_proto(setresgid) /* Clone the calling process, creating an exact copy. Return -1 for errors, 0 to the new process, and the process ID of the new process to the old process. */ -extern __pid_t fork (void) __THROW; +extern __pid_t fork (void) __THROWNL; # ifdef _LIBC # ifdef __UCLIBC_HAS_THREADS__ extern __typeof(fork) __libc_fork; @@ -903,7 +905,7 @@ extern ssize_t readlink (const char *__restrict __path, char *__restrict __buf, size_t __len) __THROW __nonnull ((1, 2)) __wur; libc_hidden_proto(readlink) -#endif /* Use BSD. */ +#endif /* Use POSIX.1-2001. */ #ifdef __USE_ATFILE /* Like symlink but a relative path in TO is interpreted relative to TOFD. */ @@ -944,7 +946,7 @@ extern int tcsetpgrp (int __fd, __pid_t __pgrp_id) __THROW; /* Return the login name of the user. - This function is a possible cancellation points and therefore not + This function is a possible cancellation point and therefore not marked with __THROW. */ extern char *getlogin (void); libc_hidden_proto(getlogin) @@ -953,7 +955,7 @@ libc_hidden_proto(getlogin) If it cannot be determined or some other error occurred, return the error code. Otherwise return 0. - This function is a possible cancellation points and therefore not + This function is a possible cancellation point and therefore not marked with __THROW. */ extern int getlogin_r (char *__name, size_t __name_len) __nonnull ((1)); #endif @@ -974,7 +976,7 @@ extern int setlogin (const char *__name) __THROW __nonnull ((1)); #endif -#if defined __USE_BSD || defined __USE_UNIX98 +#if defined __USE_BSD || defined __USE_UNIX98 || defined __USE_XOPEN2K /* Put the name of the current host in no more than LEN bytes of NAME. The result is null-terminated if LEN is large enough for the full name and the terminator. */ @@ -1071,6 +1073,11 @@ extern char *getpass (const char *__prompt) __nonnull ((1)); extern int fsync (int __fd); #endif /* Use BSD || X/Open || Unix98. */ +#if 0 /*def __USE_GNU */ +/* Make all changes done to all files on the file system associated + * with FD actually appear on disk. */ +extern int syncfs (int __fd) __THROW; +#endif #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED @@ -1263,7 +1270,7 @@ extern void swab (const void *__restrict __from, void *__restrict __to, /* The Single Unix specification demands this prototype to be here. It is also found in . */ -#ifdef __USE_XOPEN +#if defined __USE_XOPEN && !defined __USE_XOPEN2K /* Return the name of the controlling terminal. */ extern char *ctermid (char *__s) __THROW; #endif diff --git a/include/wchar.h b/include/wchar.h index 4ddd258f0..67f44b763 100644 --- a/include/wchar.h +++ b/include/wchar.h @@ -660,7 +660,7 @@ extern wint_t putwc (wchar_t __wc, __FILE *__stream); /* Write a character to stdout. - This function is a possible cancellation points and therefore not + This function is a possible cancellation point and therefore not marked with __THROW. */ extern wint_t putwchar (wchar_t __wc); @@ -668,14 +668,14 @@ extern wint_t putwchar (wchar_t __wc); /* Get a newline-terminated wide character string of finite length from STREAM. - This function is a possible cancellation points and therefore not + This function is a possible cancellation point and therefore not marked with __THROW. */ extern wchar_t *fgetws (wchar_t *__restrict __ws, int __n, __FILE *__restrict __stream); /* Write a string to STREAM. - This function is a possible cancellation points and therefore not + This function is a possible cancellation point and therefore not marked with __THROW. */ extern int fputws (const wchar_t *__restrict __ws, __FILE *__restrict __stream); @@ -684,7 +684,7 @@ libc_hidden_proto(fputws) /* Push a character back onto the input buffer of STREAM. - This function is a possible cancellation points and therefore not + This function is a possible cancellation point and therefore not marked with __THROW. */ extern wint_t ungetwc (wint_t __wc, __FILE *__stream); libc_hidden_proto(ungetwc) diff --git a/libc/sysdeps/linux/common/getrusage.c b/libc/sysdeps/linux/common/getrusage.c index 3e719f294..fb7614be8 100644 --- a/libc/sysdeps/linux/common/getrusage.c +++ b/libc/sysdeps/linux/common/getrusage.c @@ -10,4 +10,5 @@ #include #include #include +#include _syscall2(int, getrusage, __rusage_who_t, who, struct rusage *, usage) diff --git a/libpthread/linuxthreads.old/semaphore.h b/libpthread/linuxthreads.old/semaphore.h index 9a9b72c9e..3924a471d 100644 --- a/libpthread/linuxthreads.old/semaphore.h +++ b/libpthread/linuxthreads.old/semaphore.h @@ -82,10 +82,10 @@ extern int sem_timedwait (sem_t *__restrict __sem, #endif /* Test whether SEM is posted. */ -extern int sem_trywait (sem_t *__sem) __THROW; +extern int sem_trywait (sem_t *__sem) __THROWNL; /* Post SEM. */ -extern int sem_post (sem_t *__sem) __THROW; +extern int sem_post (sem_t *__sem) __THROWNL; /* Get current value of SEM and store it in *SVAL. */ extern int sem_getvalue (sem_t *__restrict __sem, int *__restrict __sval) diff --git a/libpthread/linuxthreads.old/sysdeps/pthread/pthread.h b/libpthread/linuxthreads.old/sysdeps/pthread/pthread.h index 46c1010c6..879bcea4e 100644 --- a/libpthread/linuxthreads.old/sysdeps/pthread/pthread.h +++ b/libpthread/linuxthreads.old/sysdeps/pthread/pthread.h @@ -163,7 +163,7 @@ enum extern int pthread_create (pthread_t *__restrict __threadp, const pthread_attr_t *__restrict __attr, void *(*__start_routine) (void *), - void *__restrict __arg) __THROW; + void *__restrict __arg) __THROWNL; /* Obtain the identifier of the current thread. */ extern pthread_t pthread_self (void) __THROW; @@ -340,20 +340,20 @@ extern int pthread_mutex_init (pthread_mutex_t *__restrict __mutex, extern int pthread_mutex_destroy (pthread_mutex_t *__mutex) __THROW; /* Try to lock MUTEX. */ -extern int pthread_mutex_trylock (pthread_mutex_t *__mutex) __THROW; +extern int pthread_mutex_trylock (pthread_mutex_t *__mutex) __THROWNL; /* Wait until lock for MUTEX becomes available and lock it. */ -extern int pthread_mutex_lock (pthread_mutex_t *__mutex) __THROW; +extern int pthread_mutex_lock (pthread_mutex_t *__mutex) __THROWNL; #ifdef __USE_XOPEN2K /* Wait until lock becomes available, or specified time passes. */ extern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex, const struct timespec *__restrict - __abstime) __THROW; + __abstime) __THROWNL; #endif /* Unlock MUTEX. */ -extern int pthread_mutex_unlock (pthread_mutex_t *__mutex) __THROW; +extern int pthread_mutex_unlock (pthread_mutex_t *__mutex) __THROWNL; /* Functions for handling mutex attributes. */ @@ -401,11 +401,11 @@ extern int pthread_cond_destroy (pthread_cond_t *__cond) __THROW; libpthread_hidden_proto(pthread_cond_destroy) /* Wake up one thread waiting for condition variable COND. */ -extern int pthread_cond_signal (pthread_cond_t *__cond) __THROW; +extern int pthread_cond_signal (pthread_cond_t *__cond) __THROWNL; libpthread_hidden_proto(pthread_cond_signal) /* Wake up all threads waiting for condition variables COND. */ -extern int pthread_cond_broadcast (pthread_cond_t *__cond) __THROW; +extern int pthread_cond_broadcast (pthread_cond_t *__cond) __THROWNL; libpthread_hidden_proto(pthread_cond_broadcast) /* Wait for condition variable COND to be signaled or broadcast. @@ -457,33 +457,33 @@ extern int pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock, extern int pthread_rwlock_destroy (pthread_rwlock_t *__rwlock) __THROW; /* Acquire read lock for RWLOCK. */ -extern int pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock) __THROW; +extern int pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock) __THROWNL; /* Try to acquire read lock for RWLOCK. */ -extern int pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock) __THROW; +extern int pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock) __THROWNL; # ifdef __USE_XOPEN2K /* Try to acquire read lock for RWLOCK or return after specfied time. */ extern int pthread_rwlock_timedrdlock (pthread_rwlock_t *__restrict __rwlock, const struct timespec *__restrict - __abstime) __THROW; + __abstime) __THROWNL; # endif /* Acquire write lock for RWLOCK. */ -extern int pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock) __THROW; +extern int pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock) __THROWNL; /* Try to acquire write lock for RWLOCK. */ -extern int pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock) __THROW; +extern int pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock) __THROWNL; # ifdef __USE_XOPEN2K /* Try to acquire write lock for RWLOCK or return after specfied time. */ extern int pthread_rwlock_timedwrlock (pthread_rwlock_t *__restrict __rwlock, const struct timespec *__restrict - __abstime) __THROW; + __abstime) __THROWNL; # endif /* Unlock RWLOCK. */ -extern int pthread_rwlock_unlock (pthread_rwlock_t *__rwlock) __THROW; +extern int pthread_rwlock_unlock (pthread_rwlock_t *__rwlock) __THROWNL; /* Functions for handling read-write lock attributes. */ @@ -528,13 +528,13 @@ extern int pthread_spin_init (pthread_spinlock_t *__lock, int __pshared) extern int pthread_spin_destroy (pthread_spinlock_t *__lock) __THROW; /* Wait until spinlock LOCK is retrieved. */ -extern int pthread_spin_lock (pthread_spinlock_t *__lock) __THROW; +extern int pthread_spin_lock (pthread_spinlock_t *__lock) __THROWNL; /* Try to lock spinlock LOCK. */ -extern int pthread_spin_trylock (pthread_spinlock_t *__lock) __THROW; +extern int pthread_spin_trylock (pthread_spinlock_t *__lock) __THROWNL; /* Release spinlock LOCK. */ -extern int pthread_spin_unlock (pthread_spinlock_t *__lock) __THROW; +extern int pthread_spin_unlock (pthread_spinlock_t *__lock) __THROWNL; /* Barriers are a also a new feature in 1003.1j-2000. */ @@ -556,7 +556,7 @@ extern int pthread_barrierattr_getpshared (const pthread_barrierattr_t * extern int pthread_barrierattr_setpshared (pthread_barrierattr_t *__attr, int __pshared) __THROW; -extern int pthread_barrier_wait (pthread_barrier_t *__barrier) __THROW; +extern int pthread_barrier_wait (pthread_barrier_t *__barrier) __THROWNL; #endif #endif diff --git a/libpthread/linuxthreads/semaphore.h b/libpthread/linuxthreads/semaphore.h index 7f3dbadfb..7ab772bfa 100644 --- a/libpthread/linuxthreads/semaphore.h +++ b/libpthread/linuxthreads/semaphore.h @@ -82,10 +82,10 @@ extern int sem_timedwait (sem_t *__restrict __sem, #endif /* Test whether SEM is posted. */ -extern int sem_trywait (sem_t *__sem) __THROW; +extern int sem_trywait (sem_t *__sem) __THROWNL; /* Post SEM. */ -extern int sem_post (sem_t *__sem) __THROW; +extern int sem_post (sem_t *__sem) __THROWNL; /* Get current value of SEM and store it in *SVAL. */ extern int sem_getvalue (sem_t *__restrict __sem, int *__restrict __sval) diff --git a/libpthread/linuxthreads/sysdeps/pthread/pthread.h b/libpthread/linuxthreads/sysdeps/pthread/pthread.h index 94ed95c99..df01c111f 100644 --- a/libpthread/linuxthreads/sysdeps/pthread/pthread.h +++ b/libpthread/linuxthreads/sysdeps/pthread/pthread.h @@ -163,7 +163,7 @@ enum extern int pthread_create (pthread_t *__restrict __threadp, const pthread_attr_t *__restrict __attr, void *(*__start_routine) (void *), - void *__restrict __arg) __THROW; + void *__restrict __arg) __THROWNL; /* Obtain the identifier of the current thread. */ extern pthread_t pthread_self (void) __THROW; @@ -331,20 +331,20 @@ extern int pthread_mutex_init (pthread_mutex_t *__restrict __mutex, extern int pthread_mutex_destroy (pthread_mutex_t *__mutex) __THROW; /* Try to lock MUTEX. */ -extern int pthread_mutex_trylock (pthread_mutex_t *__mutex) __THROW; +extern int pthread_mutex_trylock (pthread_mutex_t *__mutex) __THROWNL; /* Wait until lock for MUTEX becomes available and lock it. */ -extern int pthread_mutex_lock (pthread_mutex_t *__mutex) __THROW; +extern int pthread_mutex_lock (pthread_mutex_t *__mutex) __THROWNL; #ifdef __USE_XOPEN2K /* Wait until lock becomes available, or specified time passes. */ extern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex, const struct timespec *__restrict - __abstime) __THROW; + __abstime) __THROWNL; #endif /* Unlock MUTEX. */ -extern int pthread_mutex_unlock (pthread_mutex_t *__mutex) __THROW; +extern int pthread_mutex_unlock (pthread_mutex_t *__mutex) __THROWNL; /* Functions for handling mutex attributes. */ @@ -390,10 +390,10 @@ extern int pthread_cond_init (pthread_cond_t *__restrict __cond, extern int pthread_cond_destroy (pthread_cond_t *__cond) __THROW; /* Wake up one thread waiting for condition variable COND. */ -extern int pthread_cond_signal (pthread_cond_t *__cond) __THROW; +extern int pthread_cond_signal (pthread_cond_t *__cond) __THROWNL; /* Wake up all threads waiting for condition variables COND. */ -extern int pthread_cond_broadcast (pthread_cond_t *__cond) __THROW; +extern int pthread_cond_broadcast (pthread_cond_t *__cond) __THROWNL; /* Wait for condition variable COND to be signaled or broadcast. MUTEX is assumed to be locked before. */ @@ -440,33 +440,33 @@ extern int pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock, extern int pthread_rwlock_destroy (pthread_rwlock_t *__rwlock) __THROW; /* Acquire read lock for RWLOCK. */ -extern int pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock) __THROW; +extern int pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock) __THROWNL; /* Try to acquire read lock for RWLOCK. */ -extern int pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock) __THROW; +extern int pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock) __THROWNL; # ifdef __USE_XOPEN2K /* Try to acquire read lock for RWLOCK or return after specfied time. */ extern int pthread_rwlock_timedrdlock (pthread_rwlock_t *__restrict __rwlock, const struct timespec *__restrict - __abstime) __THROW; + __abstime) __THROWNL; # endif /* Acquire write lock for RWLOCK. */ -extern int pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock) __THROW; +extern int pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock) __THROWNL; /* Try to acquire write lock for RWLOCK. */ -extern int pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock) __THROW; +extern int pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock) __THROWNL; # ifdef __USE_XOPEN2K /* Try to acquire write lock for RWLOCK or return after specfied time. */ extern int pthread_rwlock_timedwrlock (pthread_rwlock_t *__restrict __rwlock, const struct timespec *__restrict - __abstime) __THROW; + __abstime) __THROWNL; # endif /* Unlock RWLOCK. */ -extern int pthread_rwlock_unlock (pthread_rwlock_t *__rwlock) __THROW; +extern int pthread_rwlock_unlock (pthread_rwlock_t *__rwlock) __THROWNL; /* Functions for handling read-write lock attributes. */ @@ -508,13 +508,13 @@ extern int pthread_spin_init (pthread_spinlock_t *__lock, int __pshared) extern int pthread_spin_destroy (pthread_spinlock_t *__lock) __THROW; /* Wait until spinlock LOCK is retrieved. */ -extern int pthread_spin_lock (pthread_spinlock_t *__lock) __THROW; +extern int pthread_spin_lock (pthread_spinlock_t *__lock) __THROWNL; /* Try to lock spinlock LOCK. */ -extern int pthread_spin_trylock (pthread_spinlock_t *__lock) __THROW; +extern int pthread_spin_trylock (pthread_spinlock_t *__lock) __THROWNL; /* Release spinlock LOCK. */ -extern int pthread_spin_unlock (pthread_spinlock_t *__lock) __THROW; +extern int pthread_spin_unlock (pthread_spinlock_t *__lock) __THROWNL; /* Barriers are a also a new feature in 1003.1j-2000. */ @@ -536,7 +536,7 @@ extern int pthread_barrierattr_getpshared (const pthread_barrierattr_t * extern int pthread_barrierattr_setpshared (pthread_barrierattr_t *__attr, int __pshared) __THROW; -extern int pthread_barrier_wait (pthread_barrier_t *__barrier) __THROW; +extern int pthread_barrier_wait (pthread_barrier_t *__barrier) __THROWNL; #endif diff --git a/libpthread/nptl/semaphore.h b/libpthread/nptl/semaphore.h index aa0f9294e..c7f195bdf 100644 --- a/libpthread/nptl/semaphore.h +++ b/libpthread/nptl/semaphore.h @@ -63,10 +63,10 @@ extern int sem_timedwait (sem_t *__restrict __sem, #endif /* Test whether SEM is posted. */ -extern int sem_trywait (sem_t *__sem) __THROW; +extern int sem_trywait (sem_t *__sem) __THROWNL; /* Post SEM. */ -extern int sem_post (sem_t *__sem) __THROW; +extern int sem_post (sem_t *__sem) __THROWNL; /* Get current value of SEM and store it in *SVAL. */ extern int sem_getvalue (sem_t *__restrict __sem, int *__restrict __sval) diff --git a/libpthread/nptl/sysdeps/pthread/pthread.h b/libpthread/nptl/sysdeps/pthread/pthread.h index 896fb1bf5..4103a06ad 100644 --- a/libpthread/nptl/sysdeps/pthread/pthread.h +++ b/libpthread/nptl/sysdeps/pthread/pthread.h @@ -229,7 +229,7 @@ __BEGIN_DECLS extern int pthread_create (pthread_t *__restrict __newthread, const pthread_attr_t *__restrict __attr, void *(*__start_routine) (void *), - void *__restrict __arg) __THROW __nonnull ((1, 3)); + void *__restrict __arg) __THROWNL __nonnull ((1, 3)); /* Terminate calling thread. @@ -271,7 +271,8 @@ extern int pthread_detach (pthread_t __th) __THROW; extern pthread_t pthread_self (void) __THROW __attribute__ ((__const__)); /* Compare two thread identifiers. */ -extern int pthread_equal (pthread_t __thread1, pthread_t __thread2) __THROW; +extern int pthread_equal (pthread_t __thread1, pthread_t __thread2) + __THROW __attribute__ ((__const__)); /* Thread attribute handling. */ @@ -308,8 +309,7 @@ extern int pthread_attr_setguardsize (pthread_attr_t *__attr, /* Return in *PARAM the scheduling parameters of *ATTR. */ -extern int pthread_attr_getschedparam (const pthread_attr_t *__restrict - __attr, +extern int pthread_attr_getschedparam (const pthread_attr_t *__restrict __attr, struct sched_param *__restrict __param) __THROW __nonnull ((1, 2)); @@ -643,9 +643,9 @@ __pthread_cleanup_routine (struct __pthread_cleanup_frame *__frame) __pthread_unwind_buf_t __cancel_buf; \ void (*__cancel_routine) (void *) = (routine); \ void *__cancel_arg = (arg); \ - int not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \ + int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \ __cancel_buf.__cancel_jmp_buf, 0); \ - if (__builtin_expect (not_first_call, 0)) \ + if (__builtin_expect (__not_first_call, 0)) \ { \ __cancel_routine (__cancel_arg); \ __pthread_unwind_next (&__cancel_buf); \ @@ -678,9 +678,9 @@ extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf) __pthread_unwind_buf_t __cancel_buf; \ void (*__cancel_routine) (void *) = (routine); \ void *__cancel_arg = (arg); \ - int not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \ + int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \ __cancel_buf.__cancel_jmp_buf, 0); \ - if (__builtin_expect (not_first_call, 0)) \ + if (__builtin_expect (__not_first_call, 0)) \ { \ __cancel_routine (__cancel_arg); \ __pthread_unwind_next (&__cancel_buf); \ @@ -717,7 +717,7 @@ extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf) /* Function used in the macros. */ struct __jmp_buf_tag; -extern int __sigsetjmp (struct __jmp_buf_tag *__env, int __savemask) __THROW; +extern int __sigsetjmp (struct __jmp_buf_tag *__env, int __savemask) __THROWNL; /* Mutex handling. */ @@ -733,22 +733,22 @@ extern int pthread_mutex_destroy (pthread_mutex_t *__mutex) /* Try locking a mutex. */ extern int pthread_mutex_trylock (pthread_mutex_t *__mutex) - __THROW __nonnull ((1)); + __THROWNL __nonnull ((1)); /* Lock a mutex. */ extern int pthread_mutex_lock (pthread_mutex_t *__mutex) - __THROW __nonnull ((1)); + __THROWNL __nonnull ((1)); #ifdef __USE_XOPEN2K /* Wait until lock becomes available, or specified time passes. */ extern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex, const struct timespec *__restrict - __abstime) __THROW __nonnull ((1, 2)); + __abstime) __THROWNL __nonnull ((1, 2)); #endif /* Unlock a mutex. */ extern int pthread_mutex_unlock (pthread_mutex_t *__mutex) - __THROW __nonnull ((1)); + __THROWNL __nonnull ((1)); /* Get the priority ceiling of MUTEX. */ @@ -872,37 +872,37 @@ extern int pthread_rwlock_destroy (pthread_rwlock_t *__rwlock) /* Acquire read lock for RWLOCK. */ extern int pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock) - __THROW __nonnull ((1)); + __THROWNL __nonnull ((1)); /* Try to acquire read lock for RWLOCK. */ extern int pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock) - __THROW __nonnull ((1)); + __THROWNL __nonnull ((1)); # ifdef __USE_XOPEN2K /* Try to acquire read lock for RWLOCK or return after specfied time. */ extern int pthread_rwlock_timedrdlock (pthread_rwlock_t *__restrict __rwlock, const struct timespec *__restrict - __abstime) __THROW __nonnull ((1, 2)); + __abstime) __THROWNL __nonnull ((1, 2)); # endif /* Acquire write lock for RWLOCK. */ extern int pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock) - __THROW __nonnull ((1)); + __THROWNL __nonnull ((1)); /* Try to acquire write lock for RWLOCK. */ extern int pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock) - __THROW __nonnull ((1)); + __THROWNL __nonnull ((1)); # ifdef __USE_XOPEN2K /* Try to acquire write lock for RWLOCK or return after specfied time. */ extern int pthread_rwlock_timedwrlock (pthread_rwlock_t *__restrict __rwlock, const struct timespec *__restrict - __abstime) __THROW __nonnull ((1, 2)); + __abstime) __THROWNL __nonnull ((1, 2)); # endif /* Unlock RWLOCK. */ extern int pthread_rwlock_unlock (pthread_rwlock_t *__rwlock) - __THROW __nonnull ((1)); + __THROWNL __nonnull ((1)); /* Functions for handling read-write lock attributes. */ @@ -943,8 +943,8 @@ extern int pthread_rwlockattr_setkind_np (pthread_rwlockattr_t *__attr, /* Initialize condition variable COND using attributes ATTR, or use the default values if later is NULL. */ extern int pthread_cond_init (pthread_cond_t *__restrict __cond, - const pthread_condattr_t *__restrict - __cond_attr) __THROW __nonnull ((1)); + const pthread_condattr_t *__restrict __cond_attr) + __THROW __nonnull ((1)); /* Destroy condition variable COND. */ extern int pthread_cond_destroy (pthread_cond_t *__cond) @@ -952,11 +952,11 @@ extern int pthread_cond_destroy (pthread_cond_t *__cond) /* Wake up one thread waiting for condition variable COND. */ extern int pthread_cond_signal (pthread_cond_t *__cond) - __THROW __nonnull ((1)); + __THROWNL __nonnull ((1)); /* Wake up all threads waiting for condition variables COND. */ extern int pthread_cond_broadcast (pthread_cond_t *__cond) - __THROW __nonnull ((1)); + __THROWNL __nonnull ((1)); /* Wait for condition variable COND to be signaled or broadcast. MUTEX is assumed to be locked before. @@ -976,8 +976,8 @@ extern int pthread_cond_wait (pthread_cond_t *__restrict __cond, __THROW. */ extern int pthread_cond_timedwait (pthread_cond_t *__restrict __cond, pthread_mutex_t *__restrict __mutex, - const struct timespec *__restrict - __abstime) __nonnull ((1, 2, 3)); + const struct timespec *__restrict __abstime) + __nonnull ((1, 2, 3)); /* Functions for handling condition variable attributes. */ @@ -1000,13 +1000,13 @@ extern int pthread_condattr_setpshared (pthread_condattr_t *__attr, int __pshared) __THROW __nonnull ((1)); #ifdef __USE_XOPEN2K -/* Get the clock selected for the conditon variable attribute ATTR. */ +/* Get the clock selected for the condition variable attribute ATTR. */ extern int pthread_condattr_getclock (const pthread_condattr_t * __restrict __attr, __clockid_t *__restrict __clock_id) __THROW __nonnull ((1, 2)); -/* Set the clock selected for the conditon variable attribute ATTR. */ +/* Set the clock selected for the condition variable attribute ATTR. */ extern int pthread_condattr_setclock (pthread_condattr_t *__attr, __clockid_t __clock_id) __THROW __nonnull ((1)); @@ -1027,15 +1027,15 @@ extern int pthread_spin_destroy (pthread_spinlock_t *__lock) /* Wait until spinlock LOCK is retrieved. */ extern int pthread_spin_lock (pthread_spinlock_t *__lock) - __THROW __nonnull ((1)); + __THROWNL __nonnull ((1)); /* Try to lock spinlock LOCK. */ extern int pthread_spin_trylock (pthread_spinlock_t *__lock) - __THROW __nonnull ((1)); + __THROWNL __nonnull ((1)); /* Release spinlock LOCK. */ extern int pthread_spin_unlock (pthread_spinlock_t *__lock) - __THROW __nonnull ((1)); + __THROWNL __nonnull ((1)); /* Functions to handle barriers. */ @@ -1053,7 +1053,7 @@ extern int pthread_barrier_destroy (pthread_barrier_t *__barrier) /* Wait on barrier BARRIER. */ extern int pthread_barrier_wait (pthread_barrier_t *__barrier) - __THROW __nonnull ((1)); + __THROWNL __nonnull ((1)); /* Initialize barrier attribute ATTR. */ -- cgit v1.2.3 From 8ee422cffbfd3e2a16265fe6680a8dde2f5e58fe Mon Sep 17 00:00:00 2001 From: Alexey Brodkin Date: Thu, 12 Mar 2015 02:21:12 +0300 Subject: resolv: fix unaligned tmp buffer corner-case On execution of "inet/gethost_r-align" test I noticed failure due to unaligned access (instaed of 4-byte aligned 1-byte aligned address was attempted to be accessed). Further investigation confirmed this nice and helpful test failure. Following commit removed usage of ALIGN_BUFFER_OFFSET on entry to __read_etc_hosts_r(): http://git.uclibc.org/uClibc/commit/?id=f65e66078b9f4d2d7f0fc336dee36e78fc467c0f So indeed if target architecture doesn't allow unaligned access and provided tmp buffer is not word aligned (and we will deal with pointers which means word-sized data units), then CPU will fail during execution. In case of ARC we'll see "Unaligned access" exception like this: --->8--- # potentially unexpected fatal signal 7. Path: /root/uClibc/test/inet/gethost_r-align CPU: 0 PID: 5514 Comm: gethost_r-align Not tainted 3.13.11 #2 task: 8f42a580 ti: 8f40e000 task.ti: 8f40e000 [ECR ]: 0x00230400 => Misaligned r/w from 0x5fdab341 [EFA ]: 0x5fdab341 [BLINK ]: 0x20032a18 [ERET ]: 0x20032a3c @off 0x12a3c in [/lib/libuClibc-0.9.34-git.so] VMA: 0x20020000 to 0x20062000 [STAT32]: 0x00000086 : U E2 E1 BTA: 0x20046014 SP: 0x5fdab260 FP: 0x00000000 LPS: 0x20046064 LPE: 0x20046068 LPC: 0x00000000 r00: 0x5fdab341 r01: 0x00000005 r02: 0x00000015 r03: 0x00000000 r04: 0x5fdab358 r05: 0x00000000 r06: 0x0a0a0a00 r07: 0x00000000 r08: 0x0000003f r09: 0x20067050 r10: 0x00000000 r11: 0x00000014 r12: 0x00000001 r13: 0x00000000 r14: 0x20060660 r15: 0x20060661 r16: 0x00000006 r17: 0x5fdab371 r18: 0x00000018 r19: 0x5fdab2b4 r20: 0x00020000 r21: 0x00000000 r22: 0x00029068 r23: 0x5fdab371 r24: 0x00010000 r25: 0x00000000 --->8--- To fix this problem we'll re-introduce tmp buffer force alignment before config parser invocation. Signed-off-by: Alexey Brodkin Cc: Vineet Gupta Cc: Waldemar Brodkorb Signed-off-by: Bernhard Reutner-Fischer --- libc/inet/resolv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c index cfc1eee9b..31e63810b 100644 --- a/libc/inet/resolv.c +++ b/libc/inet/resolv.c @@ -1615,9 +1615,13 @@ int __read_etc_hosts_r( #endif ; int ret = HOST_NOT_FOUND; + /* make sure pointer is aligned */ + int i = ALIGN_BUFFER_OFFSET(buf); + buf += i; + buflen -= i; *h_errnop = NETDB_INTERNAL; - if (buflen < aliaslen + if (/* (ssize_t)buflen < 0 || */ buflen < aliaslen || (buflen - aliaslen) < BUFSZ + 1) return ERANGE; if (parser == NULL) -- cgit v1.2.3 From f334556476cd9c33d3a9d8df9af0dfae798dc9ae Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 17 Mar 2015 20:54:38 +0100 Subject: test: Tweak arc4random exclusion Signed-off-by: Bernhard Reutner-Fischer --- test/stdlib/Makefile.in | 4 +++- test/stdlib/testarc4random.c | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/stdlib/Makefile.in b/test/stdlib/Makefile.in index 53e5a7280..f39941dc2 100644 --- a/test/stdlib/Makefile.in +++ b/test/stdlib/Makefile.in @@ -10,4 +10,6 @@ TESTS_DISABLED := ifeq ($(UCLIBC_HAS_PTY),) TESTS_DISABLED += ptytest endif - +ifeq ($(UCLIBC_HAS_ARC4RANDOM),) +TESTS_DISABLED += testarc4random +endif diff --git a/test/stdlib/testarc4random.c b/test/stdlib/testarc4random.c index 4d773aa4b..14ff1cc36 100644 --- a/test/stdlib/testarc4random.c +++ b/test/stdlib/testarc4random.c @@ -3,10 +3,8 @@ int main(void) { -#ifdef __UCLIBC_HAS_ARC4RANDOM__ int random_number; random_number = arc4random() % 65536; printf("%d\n", random_number); -#endif return 0; } -- cgit v1.2.3 From 75d9bf2dc57f89532a25ab9942b8bea468585199 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 17 Mar 2015 20:54:58 +0100 Subject: include: silence __leaf warning Signed-off-by: Bernhard Reutner-Fischer --- include/sys/sysmacros.h | 29 +++++++++++++------------ libc/sysdeps/linux/common/makedev.c | 42 +++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 libc/sysdeps/linux/common/makedev.c diff --git a/include/sys/sysmacros.h b/include/sys/sysmacros.h index 7a5635edd..3addb7500 100644 --- a/include/sys/sysmacros.h +++ b/include/sys/sysmacros.h @@ -21,35 +21,39 @@ #include +__BEGIN_DECLS + /* If the compiler does not know long long it is out of luck. We are not going to hack weird hacks to support the dev_t representation they need. */ -#if 1 /*def __GLIBC_HAVE_LONG_LONG uClibc note: always enable */ + __extension__ -static __inline unsigned int gnu_dev_major (unsigned long long int __dev) - __THROW; +extern unsigned int gnu_dev_major (unsigned long long int __dev) + __THROW __attribute__ ((__const__)); +libc_hidden_proto(gnu_dev_major) __extension__ -static __inline unsigned int gnu_dev_minor (unsigned long long int __dev) - __THROW; +extern unsigned int gnu_dev_minor (unsigned long long int __dev) + __THROW __attribute__ ((__const__)); +libc_hidden_proto(gnu_dev_minor) __extension__ -static __inline unsigned long long int gnu_dev_makedev (unsigned int __major, +extern unsigned long long int gnu_dev_makedev (unsigned int __major, unsigned int __minor) - __THROW; + __THROW __attribute__ ((__const__)); -# if defined __GNUC__ && __GNUC__ >= 2 -__extension__ static __inline unsigned int +# ifdef __USE_EXTERN_INLINES +__extension__ __extern_inline __attribute__ ((__const__)) unsigned int __NTH (gnu_dev_major (unsigned long long int __dev)) { return ((__dev >> 8) & 0xfff) | ((unsigned int) (__dev >> 32) & ~0xfff); } -__extension__ static __inline unsigned int +__extension__ __extern_inline __attribute__ ((__const__)) unsigned int __NTH (gnu_dev_minor (unsigned long long int __dev)) { return (__dev & 0xff) | ((unsigned int) (__dev >> 12) & ~0xff); } -__extension__ static __inline unsigned long long int +__extension__ __extern_inline __attribute__ ((__const__)) unsigned long long int __NTH (gnu_dev_makedev (unsigned int __major, unsigned int __minor)) { return ((__minor & 0xff) | ((__major & 0xfff) << 8) @@ -57,12 +61,11 @@ __NTH (gnu_dev_makedev (unsigned int __major, unsigned int __minor)) | (((unsigned long long int) (__major & ~0xfff)) << 32)); } # endif - +__END_DECLS /* Access the functions with their traditional names. */ # define major(dev) gnu_dev_major (dev) # define minor(dev) gnu_dev_minor (dev) # define makedev(maj, min) gnu_dev_makedev (maj, min) -#endif #endif /* sys/sysmacros.h */ diff --git a/libc/sysdeps/linux/common/makedev.c b/libc/sysdeps/linux/common/makedev.c new file mode 100644 index 000000000..d7761671b --- /dev/null +++ b/libc/sysdeps/linux/common/makedev.c @@ -0,0 +1,42 @@ +/* Definitions of functions to access `dev_t' values. + Copyright (C) 2003-2015 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, see + . */ + +#include +#include + +unsigned int +gnu_dev_major (unsigned long long int dev) +{ + return ((dev >> 8) & 0xfff) | ((unsigned int) (dev >> 32) & ~0xfff); +} +libc_hidden_def(gnu_dev_major) + +unsigned int +gnu_dev_minor (unsigned long long int dev) +{ + return (dev & 0xff) | ((unsigned int) (dev >> 12) & ~0xff); +} +libc_hidden_def(gnu_dev_minor) + +unsigned long long int +gnu_dev_makedev (unsigned int major, unsigned int minor) +{ + return ((minor & 0xff) | ((major & 0xfff) << 8) + | (((unsigned long long int) (minor & ~0xff)) << 12) + | (((unsigned long long int) (major & ~0xfff)) << 32)); +} -- cgit v1.2.3 From 8d15cd677df7e5bc6a1a01e482a33ecc2d271337 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 17 Mar 2015 20:56:17 +0100 Subject: nptl: fix exclusion of pthread_setconcurrency.c Signed-off-by: Bernhard Reutner-Fischer --- libpthread/nptl/Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libpthread/nptl/Makefile.in b/libpthread/nptl/Makefile.in index cdf07cf45..0a981cde3 100644 --- a/libpthread/nptl/Makefile.in +++ b/libpthread/nptl/Makefile.in @@ -21,7 +21,7 @@ libpthread-routines- += allocatestack.c # dummy included by pthread_create.c libpthread-routines- += pthread_mutex_getprioceiling.c pthread_mutex_setprioceiling.c # XXX: delete those or use them! libpthread-routines-$(UCLIBC_HAS_RESOLVER_SUPPORT) += res.c libpthread-routines-$(UCLIBC_SUSV4_LEGACY) += pthread_getconcurrency.c \ - pthread_setconcurrency + pthread_setconcurrency.c libpthread_CSRC = $(filter-out $(libpthread-routines-) \ $(libc-shared-routines-y) \ $(libc-static-routines-y) \ -- cgit v1.2.3 From 6f4d5a7f53ee7f277b31bbff638bbccecf22f66f Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 17 Mar 2015 21:19:10 +0100 Subject: libc: update strverscmp Closes bugzilla #7936 Signed-off-by: Bernhard Reutner-Fischer --- libc/string/strverscmp.c | 69 ++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 40 deletions(-) diff --git a/libc/string/strverscmp.c b/libc/string/strverscmp.c index 714f4ed67..7818a9186 100644 --- a/libc/string/strverscmp.c +++ b/libc/string/strverscmp.c @@ -1,13 +1,8 @@ -/* GNU's strverscmp() function, taken from glibc 2.3.2 sources - */ - /* Compare strings while treating digits characters numerically. - Copyright (C) 1997, 2002 Free Software Foundation, Inc. + Copyright (C) 1997-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Jean-François Bignolles , 1997. - Derived work for uClibc by Hai Zaar, Codefidence Ltd - 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 @@ -22,63 +17,54 @@ License along with the GNU C Library; if not, see . */ +#include #include #include -#include - /* states: S_N: normal, S_I: comparing integral part, S_F: comparing - fractional parts, S_Z: idem but with leading Zeroes only */ + fractionnal parts, S_Z: idem but with leading Zeroes only */ #define S_N 0x0 -#define S_I 0x4 -#define S_F 0x8 -#define S_Z 0xC +#define S_I 0x3 +#define S_F 0x6 +#define S_Z 0x9 /* result_type: CMP: return diff; LEN: compare using len_diff/diff */ #define CMP 2 #define LEN 3 -/* using more efficient isdigit() */ -#undef isdigit -#define isdigit(a) ((unsigned)((a) - '0') <= 9) /* Compare S1 and S2 as strings holding indices/version numbers, returning less than, equal to or greater than zero if S1 is less than, equal to or greater than S2 (for more info, see the texinfo doc). */ + int strverscmp (const char *s1, const char *s2) { const unsigned char *p1 = (const unsigned char *) s1; const unsigned char *p2 = (const unsigned char *) s2; - unsigned char c1, c2; - int state; - int diff; - /* Symbol(s) 0 [1-9] others (padding) - Transition (10) 0 (01) d (00) x (11) - */ + /* Symbol(s) 0 [1-9] others + Transition (10) 0 (01) d (00) x */ static const uint8_t next_state[] = { - /* state x d 0 - */ - /* S_N */ S_N, S_I, S_Z, S_N, - /* S_I */ S_N, S_I, S_I, S_I, - /* S_F */ S_N, S_F, S_F, S_F, - /* S_Z */ S_N, S_F, S_Z, S_Z + /* state x d 0 */ + /* S_N */ S_N, S_I, S_Z, + /* S_I */ S_N, S_I, S_I, + /* S_F */ S_N, S_F, S_F, + /* S_Z */ S_N, S_F, S_Z }; static const int8_t result_type[] = { - /* state x/x x/d x/0 x/- d/x d/d d/0 d/- - 0/x 0/d 0/0 0/- -/x -/d -/0 -/- */ - - /* S_N */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP, - CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP, - /* S_I */ CMP, -1, -1, CMP, +1, LEN, LEN, CMP, - +1, LEN, LEN, CMP, CMP, CMP, CMP, CMP, - /* S_F */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP, - CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP, - /* S_Z */ CMP, +1, +1, CMP, -1, CMP, CMP, CMP, - -1, CMP, CMP, CMP + /* state x/x x/d x/0 d/x d/d d/0 0/x 0/d 0/0 */ + + /* S_N */ CMP, CMP, CMP, CMP, LEN, CMP, CMP, CMP, CMP, + /* S_I */ CMP, -1, -1, +1, LEN, LEN, +1, LEN, LEN, + /* S_F */ CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP, + /* S_Z */ CMP, +1, +1, -1, CMP, CMP, -1, CMP, CMP }; + unsigned char c1, c2; + int state, diff; if (p1 == p2) return 0; @@ -86,17 +72,20 @@ int strverscmp (const char *s1, const char *s2) c1 = *p1++; c2 = *p2++; /* Hint: '0' is a digit too. */ - state = S_N | ((c1 == '0') + (isdigit (c1) != 0)); + state = S_N + ((c1 == '0') + (isdigit (c1) != 0)); - while ((diff = c1 - c2) == 0 && c1 != '\0') + while ((diff = c1 - c2) == 0) { + if (c1 == '\0') + return diff; + state = next_state[state]; c1 = *p1++; c2 = *p2++; - state |= (c1 == '0') + (isdigit (c1) != 0); + state += (c1 == '0') + (isdigit (c1) != 0); } - state = result_type[state << 2 | (((c2 == '0') + (isdigit (c2) != 0)))]; + state = result_type[state * 3 + (((c2 == '0') + (isdigit (c2) != 0)))]; switch (state) { -- cgit v1.2.3 From 5d3c0cc2aa60da804c9c981ffd5edcd2f02f1977 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Wed, 18 Mar 2015 22:31:53 +0100 Subject: buildsys: fix IS_IN_lib* for .i Signed-off-by: Bernhard Reutner-Fischer --- Makerules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makerules b/Makerules index cc543889c..a60338a87 100644 --- a/Makerules +++ b/Makerules @@ -29,7 +29,7 @@ objs: all_objs # apply unconditional per-directory flags define add_IS_IN_lib ifneq ($(strip $(2)),) -__add_IS_IN_lib := $(2) +__add_IS_IN_lib := $(2) $(2:.o=.i) $(2:.os=.i) $(2:.oS=.i) $$(__add_IS_IN_lib): CFLAGS-for-library-members:=$(CFLAGS-$(1)) -DIN_LIB=$(word 1,$(subst /, ,$(1))) endif endef -- cgit v1.2.3 From 78e6494c2cf677d170a5c4ce0f46d152d478abc0 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Wed, 18 Mar 2015 22:32:13 +0100 Subject: test: skip arc4random on glibc Signed-off-by: Bernhard Reutner-Fischer --- test/stdlib/Makefile.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/stdlib/Makefile.in b/test/stdlib/Makefile.in index f39941dc2..df3440a39 100644 --- a/test/stdlib/Makefile.in +++ b/test/stdlib/Makefile.in @@ -7,9 +7,12 @@ DODIFF_teston_exit := 1 DODIFF_teststrtol := 1 TESTS_DISABLED := +GLIBC_TESTS_DISABLED := ifeq ($(UCLIBC_HAS_PTY),) TESTS_DISABLED += ptytest endif ifeq ($(UCLIBC_HAS_ARC4RANDOM),) TESTS_DISABLED += testarc4random +else +GLIBC_TESTS_DISABLED += testarc4random endif -- cgit v1.2.3 From 6c4538905e65ceb203f59aaa9a61728e81c6bc0a Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Wed, 18 Mar 2015 22:32:22 +0100 Subject: libm: Add missing C99 float/ld wrappers Signed-off-by: Bernhard Reutner-Fischer --- TODO | 1 + include/complex.h | 2 + include/math.h | 2 + libc/sysdeps/linux/common/bits/mathcalls.h | 23 +++++++++++ libm/Makefile.in | 41 +++++++++++++++++--- libm/float_wrappers.c | 62 ++++++++++++++++++++---------- libm/ldouble_wrappers.c | 58 ++++++++++++++++++++++++++-- libm/s_fdim.c | 17 ++++++-- libm/s_fmax.c | 6 +-- libm/s_fmin.c | 6 +-- libm/s_nextafter.c | 4 +- test/math/compile_test.c | 20 +++++----- test/math/libm-test.inc | 56 ++++++++++++--------------- 13 files changed, 216 insertions(+), 82 deletions(-) diff --git a/TODO b/TODO index c6ad7bfb5..5f897b74f 100644 --- a/TODO +++ b/TODO @@ -93,6 +93,7 @@ TODO list for the uClibc 1.0.0 release: ugetrlimit, it seems, else use the modern variant) *) simplify exec*() in the light of execvpe (perhaps single internal impl); USE_GNU for execvpe (and other GNU extensions, see psm). + *) Remove unused math complex hidden protos throughout TODO list for AFTER the uClibc 1.0.0 release: diff --git a/include/complex.h b/include/complex.h index 91efc0d2b..ed7e502b7 100644 --- a/include/complex.h +++ b/include/complex.h @@ -79,6 +79,7 @@ __BEGIN_DECLS #endif #include #undef _Mdouble_ +#undef _Mfloat_ #undef __MATH_PRECNAME /* And the long double versions. It is non-critical to define them @@ -97,6 +98,7 @@ __BEGIN_DECLS # include #endif #undef _Mdouble_ +#undef _Mlong_double_ #undef __MATH_PRECNAME #undef __MATHDECL_1 #undef __MATHDECL diff --git a/include/math.h b/include/math.h index ecb9aa6f6..1b54c9ee9 100644 --- a/include/math.h +++ b/include/math.h @@ -129,6 +129,7 @@ __BEGIN_DECLS # undef _Mdouble_ # undef _Mdouble_BEGIN_NAMESPACE # undef _Mdouble_END_NAMESPACE +# undef _Mfloat_ # undef __MATH_PRECNAME # undef __MATH_maybe_libm_hidden_proto @@ -176,6 +177,7 @@ extern long double __REDIRECT_NTH (nexttowardl, (long double __x, long double __ # undef _Mdouble_ # undef _Mdouble_BEGIN_NAMESPACE # undef _Mdouble_END_NAMESPACE +# undef _Mlong_double_ # undef __MATH_PRECNAME # undef __MATH_maybe_libm_hidden_proto diff --git a/libc/sysdeps/linux/common/bits/mathcalls.h b/libc/sysdeps/linux/common/bits/mathcalls.h index 84b793c96..9bebb5190 100644 --- a/libc/sysdeps/linux/common/bits/mathcalls.h +++ b/libc/sysdeps/linux/common/bits/mathcalls.h @@ -74,8 +74,22 @@ __MATHCALLI (atan2,, (_Mdouble_ __y, _Mdouble_ __x)) /* Cosine of X. */ __MATHCALLI (cos,, (_Mdouble_ __x)) +# if defined _LIBC && defined _Mlong_double_ +libm_hidden_proto(cosl) +# endif +# if defined _LIBC && defined _Mfloat_ +libm_hidden_proto(cosf) +# endif + /* Sine of X. */ __MATHCALLI (sin,, (_Mdouble_ __x)) +# if defined _LIBC && defined _Mlong_double_ +libm_hidden_proto(sinl) +# endif +# if defined _LIBC && defined _Mfloat_ +libm_hidden_proto(sinf) +# endif + /* Tangent of X. */ __MATHCALLI (tan,, (_Mdouble_ __x)) @@ -111,6 +125,9 @@ __END_NAMESPACE_C99 _Mdouble_BEGIN_NAMESPACE /* Exponential function of X. */ __MATHCALLI (exp,, (_Mdouble_ __x)) +# if defined _LIBC && defined _Mlong_double_ +libm_hidden_proto(expl) +# endif /* Break VALUE into a normalized fraction and an integral power of 2. */ __MATHCALLI (frexp,, (_Mdouble_ __x, int *__exponent)) @@ -173,6 +190,9 @@ _Mdouble_END_NAMESPACE __BEGIN_NAMESPACE_C99 /* Return `sqrt(X*X + Y*Y)'. */ __MATHCALLI (hypot,, (_Mdouble_ __x, _Mdouble_ __y)) +# if defined _LIBC && defined _Mlong_double_ +libm_hidden_proto(hypotl) +# endif __END_NAMESPACE_C99 #endif @@ -298,6 +318,9 @@ __MATHCALLI (rint,, (_Mdouble_ __x)) /* Return X + epsilon if X < Y, X - epsilon if X > Y. */ __MATHCALLX (nextafter,, (_Mdouble_ __x, _Mdouble_ __y), (__const__)) +# if defined _LIBC && defined _Mlong_double_ +libm_hidden_proto(nextafterl) +# endif # if defined __USE_ISOC99 && !defined __LDBL_COMPAT __MATHCALLX (nexttoward,, (_Mdouble_ __x, long double __y), (__const__)) # endif diff --git a/libm/Makefile.in b/libm/Makefile.in index 751170678..d886cdbc5 100644 --- a/libm/Makefile.in +++ b/libm/Makefile.in @@ -75,9 +75,6 @@ libm_CSRC := \ s_remquo.c w_exp2.c \ cexp.c sincos.c -# Not implemented [yet?], see comment in float_wrappers.c: -# fdimf.o fmaf.o fmaxf.o fminf.o -# nearbyintf.o remquof.o scalblnf.o tgammaf.o FL_MOBJ := \ acosf.o \ acoshf.o \ @@ -98,7 +95,11 @@ FL_MOBJ := \ expf.o \ expm1f.o \ fabsf.o \ + fdimf.o \ floorf.o \ + fmaf.o \ + fmaxf.o \ + fminf.o \ fmodf.o \ frexpf.o \ gammaf.o \ @@ -116,11 +117,14 @@ FL_MOBJ := \ lrintf.o \ lroundf.o \ modff.o \ + nearbyintf.o \ + nexttowardf.o \ powf.o \ remainderf.o \ + remquof.o \ rintf.o \ roundf.o \ - scalbf.o \ + scalblnf.o \ scalbnf.o \ significandf.o \ sinf.o \ @@ -128,9 +132,24 @@ FL_MOBJ := \ sqrtf.o \ tanf.o \ tanhf.o \ + tgammaf.o \ truncf.o \ -# Not implemented [yet?]: nexttowardl.o +ifeq ($(UCLIBC_SUSV3_LEGACY),y) +FL_MOBJ += scalbf.o +endif + +# Do not (yet?) implement the float variants of bessel functions +ifeq (not-yet-implemented-$(DO_XSI_MATH),y) +FL_MOBJ += \ + j0f.o \ + j1f.o \ + jnf.o \ + y0f.o \ + y1f.o \ + ynf.o +endif + LD_MOBJ := \ __finitel.o \ __fpclassifyl.o \ @@ -180,6 +199,7 @@ LD_MOBJ := \ modfl.o \ nearbyintl.o \ nextafterl.o \ + nexttowardl.o \ powl.o \ remainderl.o \ remquol.o \ @@ -196,6 +216,17 @@ LD_MOBJ := \ tgammal.o \ truncl.o \ +# Do not (yet?) implement the long double variants of bessel functions +ifeq (not-yet-implemented-$(DO_XSI_MATH),y) +LD_MOBJ += \ + j0l.o \ + j1l.o \ + jnl.o \ + y0l.o \ + y1l.o \ + ynl.o +endif + else # This list of math functions was taken from POSIX/IEEE 1003.1b-1993 diff --git a/libm/float_wrappers.c b/libm/float_wrappers.c index 82b7963e1..105486e46 100644 --- a/libm/float_wrappers.c +++ b/libm/float_wrappers.c @@ -38,19 +38,14 @@ long long func##f (float x) \ return func((double)x); \ } - -/* For the time being, do _NOT_ implement these functions - * that are defined by SuSv3 [because we don't need them - * and nobody asked to include them] */ -#undef L_fdimf /*float fdimf(float, float);*/ -#undef L_fmaf /*float fmaf(float, float, float);*/ -#undef L_fmaxf /*float fmaxf(float, float);*/ -#undef L_fminf /*float fminf(float, float);*/ -#undef L_nearbyintf /*float nearbyintf(float);*/ -#undef L_nexttowardf /*float nexttowardf(float, long double);*/ -#undef L_remquof /*float remquof(float, float, int *);*/ -#undef L_scalblnf /*float scalblnf(float, long);*/ -#undef L_tgammaf /*float tgammaf(float);*/ +#ifndef __DO_XSI_MATH__ +# undef L_j0f /* float j0f(float x); */ +# undef L_j1f /* float j1f(float x); */ +# undef L_jnf /* float jnf(int n, float x); */ +# undef L_y0f /* float y0f(float x); */ +# undef L_y1f /* float y1f(float x); */ +# undef L_ynf /* float ynf(int n, float x); */ +#endif /* Implement the following, as defined by SuSv3 */ #if 0 @@ -155,6 +150,7 @@ float copysignf (float x, float y) #ifdef L_cosf WRAPPER1(cos) +libm_hidden_def(cosf) #endif #ifdef L_coshf @@ -242,6 +238,21 @@ float hypotf (float x, float y) int_WRAPPER1(ilogb) #endif +#ifdef L_j0f +WRAPPER1(j0) +#endif + +#ifdef L_j1f +WRAPPER1(j1) +#endif + +#ifdef L_jnf +float jnf(int n, float x) +{ + return (float) jn(n, (double)x); +} +#endif + #ifdef L_ldexpf float ldexpf (float x, int _exp) { @@ -306,7 +317,7 @@ WRAPPER1(nearbyint) #ifdef L_nexttowardf float nexttowardf (float x, long double y) { - return (float) nexttoward( (double)x, (double)y ); + return (float) nexttoward( (double)x, (long double)y ); } #endif @@ -355,6 +366,7 @@ float scalbnf (float x, int _exp) #ifdef L_sinf WRAPPER1(sin) +libm_hidden_def(sinf) #endif #ifdef L_sinhf @@ -381,13 +393,6 @@ WRAPPER1(tgamma) WRAPPER1(trunc) #endif -#ifdef L_fmaf -float fmaf (float x, float y, float z) -{ - return (float) fma( (double)x, (double)y, (double)z ); -} -#endif - #if defined L_scalbf && defined __UCLIBC_SUSV3_LEGACY__ float scalbf (float x, float y) { @@ -402,3 +407,18 @@ WRAPPER1(gamma) #ifdef L_significandf WRAPPER1(significand) #endif + +#ifdef L_y0f +WRAPPER1(y0) +#endif + +#ifdef L_y1f +WRAPPER1(y1) +#endif + +#ifdef L_ynf +float ynf(int n, float x) +{ + return (float) yn(n, (double)x); +} +#endif diff --git a/libm/ldouble_wrappers.c b/libm/ldouble_wrappers.c index 118a78f64..b4215cbf3 100644 --- a/libm/ldouble_wrappers.c +++ b/libm/ldouble_wrappers.c @@ -42,6 +42,15 @@ long long func##l(long double x) \ return func((double) x); \ } +#ifndef __DO_XSI_MATH__ +# undef L_j0l /* long double j0l(long double x); */ +# undef L_j1l /* long double j1l(long double x); */ +# undef L_jnl /* long double jnl(int n, long double x); */ +# undef L_y0l /* long double y0l(long double x); */ +# undef L_y1l /* long double y1l(long double x); */ +# undef L_ynl /* long double ynl(int n, long double x); */ +#endif + /* Implement the following, as defined by SuSv3 */ #if 0 long double acoshl(long double); @@ -156,6 +165,7 @@ WRAPPER1(cosh) #ifdef L_cosl WRAPPER1(cos) +libm_hidden_def(cosl) #endif #ifdef L_erfcl @@ -172,6 +182,7 @@ WRAPPER1(exp2) #ifdef L_expl WRAPPER1(exp) +libm_hidden_def(expl) #endif #ifdef L_expm1l @@ -222,12 +233,28 @@ WRAPPER1(gamma) #ifdef L_hypotl WRAPPER2(hypot) +libm_hidden_def(hypotl) #endif #ifdef L_ilogbl int_WRAPPER1(ilogb) #endif +#ifdef L_j0l + WRAPPER1(j0) +#endif + +#ifdef L_j1l + WRAPPER1(j1) +#endif + +#ifdef L_jnl +long double jnl(int n, long double x) +{ + return (long double) jn(n, (double)x); +} +#endif + #ifdef L_ldexpl long double ldexpl (long double x, int ex) { @@ -291,12 +318,18 @@ WRAPPER1(nearbyint) #ifdef L_nextafterl WRAPPER2(nextafter) +libm_hidden_def(nextafterl) #endif -/* Disabled in Makefile.in */ -#if 0 /* def L_nexttowardl */ -WRAPPER2(nexttoward) -libm_hidden_def(nexttowardl) +#ifdef L_nexttowardl +# if 0 /* TODO */ +strong_alias(nextafterl, nexttowardl) +# else +long double nexttowardl(long double x, long double y) +{ + return nextafterl(x, y); +} +#endif #endif #ifdef L_powl @@ -344,6 +377,7 @@ WRAPPER1(sinh) #ifdef L_sinl WRAPPER1(sin) +libm_hidden_def(sinl) #endif #ifdef L_sqrtl @@ -370,6 +404,22 @@ WRAPPER1(trunc) WRAPPER1(significand) #endif +#ifdef L_y0l +WRAPPER1(y0) +#endif + +#ifdef L_y1l +WRAPPER1(y1) +#endif + +#ifdef L_ynl +long double ynl(int n, long double x) +{ + return (long double) yn(n, (double)x); +} +#endif + + #if defined __DO_C99_MATH__ && !defined __NO_LONG_DOUBLE_MATH # ifdef L___fpclassifyl diff --git a/libm/s_fdim.c b/libm/s_fdim.c index 6249219c8..6ed695c3d 100644 --- a/libm/s_fdim.c +++ b/libm/s_fdim.c @@ -6,13 +6,22 @@ #include "math.h" #include "math_private.h" +#include double fdim(double x, double y) { - int c = __fpclassify(x); - if (c == FP_NAN || c == FP_INFINITE) - return HUGE_VAL; + int cx = __fpclassify(x); /* need both NAN and INF */ + int cy = __fpclassify(y); /* need both NAN and INF */ + if (cx == FP_NAN || cy == NAN) + return x - y; - return x > y ? x - y : 0.0; + if (x <= y) + return .0; + + double z = x - y; + if (isinf(z) && cx != FP_INFINITE && cy != FP_INFINITE) + __set_errno(ERANGE); + + return z; } libm_hidden_def(fdim) diff --git a/libm/s_fmax.c b/libm/s_fmax.c index 21dfaa981..5f29ad8e3 100644 --- a/libm/s_fmax.c +++ b/libm/s_fmax.c @@ -9,10 +9,10 @@ double fmax(double x, double y) { - if (__fpclassify(x) == FP_NAN) - return x; - if (__fpclassify(y) == FP_NAN) + if (isnan(x)) return y; + if (isnan(y)) + return x; return x > y ? x : y; } diff --git a/libm/s_fmin.c b/libm/s_fmin.c index 674d9a56b..a549678ee 100644 --- a/libm/s_fmin.c +++ b/libm/s_fmin.c @@ -9,10 +9,10 @@ double fmin(double x, double y) { - if (__fpclassify(x) == FP_NAN) - return x; - if (__fpclassify(y) == FP_NAN) + if (isnan(x)) return y; + if (isnan(y)) + return x; return x < y ? x : y; } diff --git a/libm/s_nextafter.c b/libm/s_nextafter.c index ee4621cc7..73a8ab2be 100644 --- a/libm/s_nextafter.c +++ b/libm/s_nextafter.c @@ -32,7 +32,7 @@ double nextafter(double x, double y) if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) || /* x is nan */ ((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0)) /* y is nan */ return x+y; - if(x==y) return x; /* x=y, return x */ + if(x==y) return y; /* x=y, return y */ if((ix|lx)==0) { /* x == 0 */ INSERT_WORDS(x,hy&0x80000000,1); /* return +-minsubnormal */ y = x*x; @@ -68,3 +68,5 @@ double nextafter(double x, double y) return x; } libm_hidden_def(nextafter) +strong_alias_untyped(nextafter, nexttoward) +libm_hidden_def(nexttoward) diff --git a/test/math/compile_test.c b/test/math/compile_test.c index ab8c40c48..aedfde601 100644 --- a/test/math/compile_test.c +++ b/test/math/compile_test.c @@ -22,11 +22,11 @@ r += exp2f(float_x); r += expf(float_x); r += expm1f(float_x); r += fabsf(float_x); -/*r += fdimf(float_x, float_x); - uclibc does not have it (yet?) */ +r += fdimf(float_x, float_x); r += floorf(float_x); -/*r += fmaf(float_x, float_x, float_x); - uclibc does not have it (yet?) */ -/*r += fmaxf(float_x, float_x); - uclibc does not have it (yet?) */ -/*r += fminf(float_x, float_x); - uclibc does not have it (yet?) */ +r += fmaf(float_x, float_x, float_x); +r += fmaxf(float_x, float_x); +r += fminf(float_x, float_x); r += fmodf(float_x, float_x); r += frexpf(float_x, &int_x); r += gammaf(float_x); @@ -44,17 +44,17 @@ r += logf(float_x); r += lrintf(float_x); r += lroundf(float_x); r += modff(float_x, &float_x); -/*r += nearbyintf(float_x); - uclibc does not have it (yet?) */ -/*r += nexttowardf(float_x, long_double_x); - uclibc does not have it (yet?) */ +r += nearbyintf(float_x); +r += nexttowardf(float_x, long_double_x); r += powf(float_x, float_x); r += remainderf(float_x, float_x); -/*r += remquof(float_x, float_x, &int_x); - uclibc does not have it (yet?) */ +r += remquof(float_x, float_x, &int_x); r += rintf(float_x); r += roundf(float_x); #ifdef __UCLIBC_SUSV3_LEGACY__ r += scalbf(float_x, float_x); #endif -/*r += scalblnf(float_x, long_x); - uclibc does not have it (yet?) */ +r += scalblnf(float_x, long_x); r += scalbnf(float_x, int_x); r += significandf(float_x); r += sinf(float_x); @@ -62,7 +62,7 @@ r += sinhf(float_x); r += sqrtf(float_x); r += tanf(float_x); r += tanhf(float_x); -/*r += tgammaf(float_x); - uclibc does not have it (yet?) */ +r += tgammaf(float_x); r += truncf(float_x); return r; } @@ -116,7 +116,7 @@ r += lroundl(long_double_x); r += modfl(long_double_x, &long_double_x); r += nearbyintl(long_double_x); r += nextafterl(long_double_x, long_double_x); -/* r += nexttowardl(long_double_x, long_double_x); - uclibc doesn't provide this [yet?] */ +r += nexttowardl(long_double_x, long_double_x); r += powl(long_double_x, long_double_x); r += remainderl(long_double_x, long_double_x); r += remquol(long_double_x, long_double_x, &int_x); diff --git a/test/math/libm-test.inc b/test/math/libm-test.inc index d0f0a0c30..8f0db3c88 100644 --- a/test/math/libm-test.inc +++ b/test/math/libm-test.inc @@ -115,6 +115,9 @@ # define _GNU_SOURCE #endif +#undef __CHK_COMPLEX_STUFF +#define __CHK_COMPLEX_STUFF 0 + #include "libm-test-ulps.h" #include #include @@ -1120,8 +1123,10 @@ cacosh_test (void) END (cacosh, complex); } +#endif +#if __CHK_COMPLEX_STUFF static void carg_test (void) { @@ -1188,7 +1193,9 @@ carg_test (void) END (carg); } +#endif /* __CHK_COMPLEX_STUFF */ +#if 0 static void casin_test (void) { @@ -1683,7 +1690,7 @@ ceil_test (void) } -#if 0 +#if __CHK_COMPLEX_STUFF static void cexp_test (void) { @@ -1746,8 +1753,9 @@ cexp_test (void) END (cexp, complex); } +#endif /* __CHK_COMPLEX_STUFF */ - +#if 0 static void cimag_test (void) { @@ -2588,7 +2596,6 @@ fabs_test (void) } -#if 0 static void fdim_test (void) { @@ -2624,7 +2631,6 @@ fdim_test (void) END (fdim); } -#endif static void @@ -2694,7 +2700,6 @@ floor_test (void) } -#if 0 static void fma_test (void) { @@ -2797,7 +2802,6 @@ fmin_test (void) END (fmin); } -#endif static void @@ -3002,7 +3006,7 @@ isnormal_test (void) END (isnormal); } -#if defined __DO_XSI_MATH__ +#if defined __DO_XSI_MATH__ && !(defined TEST_LDOUBLE || defined TEST_FLOAT) static void j0_test (void) { @@ -3629,7 +3633,6 @@ modf_test (void) } -#if 0 static void nearbyint_test (void) { @@ -3710,7 +3713,6 @@ nexttoward_test (void) END (nexttoward); } -#endif static void @@ -3950,7 +3952,6 @@ remainder_test (void) END (remainder); } -#if 0 static void remquo_test (void) { @@ -3981,7 +3982,6 @@ remquo_test (void) END (remquo); } -#endif static void rint_test (void) @@ -4229,12 +4229,12 @@ round_test (void) #endif +#ifdef __UCLIBC_SUSV3_LEGACY__ static void scalb_test (void) { START (scalb); #ifndef TEST_LDOUBLE /* uclibc doesn't have scalbl */ -#ifdef __UCLIBC_SUSV3_LEGACY__ /* scalbf is susv3 legacy */ TEST_ff_f (scalb, 2.0, 0.5, nan_value, INVALID_EXCEPTION); TEST_ff_f (scalb, 3.0, -2.5, nan_value, INVALID_EXCEPTION); @@ -4285,11 +4285,10 @@ scalb_test (void) TEST_ff_f (scalb, 0.8L, 4, 12.8L); TEST_ff_f (scalb, -0.854375L, 5, -27.34L); -#endif /* __UCLIBC_SUSV3_LEGACY__ */ #endif /* TEST_LDOUBLE */ END (scalb); } - +#endif static void scalbn_test (void) @@ -4313,7 +4312,6 @@ scalbn_test (void) } -#if 0 static void scalbln_test (void) { @@ -4334,7 +4332,6 @@ scalbln_test (void) END (scalbn); } -#endif static void @@ -4539,7 +4536,6 @@ tanh_test (void) END (tanh); } -#if 0 static void tgamma_test (void) { @@ -4571,7 +4567,6 @@ tgamma_test (void) END (tgamma); } -#endif #if 0 @@ -4651,7 +4646,7 @@ trunc_test (void) } #endif -#if defined __DO_XSI_MATH__ +#if defined __DO_XSI_MATH__ && !(defined TEST_LDOUBLE || defined TEST_FLOAT) static void y0_test (void) { @@ -4979,11 +4974,11 @@ main (int argc, char **argv) logb_test (); modf_test (); ilogb_test (); +#ifdef __UCLIBC_SUSV3_LEGACY__ scalb_test (); +#endif scalbn_test (); -#if 0 scalbln_test (); -#endif significand_test (); /* Power and absolute value functions: */ @@ -4998,16 +4993,12 @@ main (int argc, char **argv) erfc_test (); gamma_test (); lgamma_test (); -#if 0 tgamma_test (); -#endif /* Nearest integer functions: */ ceil_test (); floor_test (); -#if 0 nearbyint_test (); -#endif rint_test (); #if 0 rint_test_tonearest (); @@ -5025,13 +5016,10 @@ main (int argc, char **argv) /* Remainder functions: */ fmod_test (); remainder_test (); -#if 0 remquo_test (); -#endif /* Manipulation functions: */ copysign_test (); -#if 0 nextafter_test (); nexttoward_test (); @@ -5043,24 +5031,29 @@ main (int argc, char **argv) /* Multiply and add: */ fma_test (); + /* Complex functions: */ cabs_test (); +#if __CHK_COMPLEX_STUFF +#if 0 cacos_test (); cacosh_test (); +#endif carg_test (); +#if 0 casin_test (); casinh_test (); catan_test (); catanh_test (); ccos_test (); ccosh_test (); +#endif cexp_test (); +#if 0 cimag_test (); clog10_test (); clog_test (); -#if 0 conj_test (); -#endif cpow_test (); cproj_test (); creal_test (); @@ -5070,9 +5063,10 @@ main (int argc, char **argv) ctan_test (); ctanh_test (); #endif +#endif /* __CHK_COMPLEX_STUFF */ /* Bessel functions: */ -#if defined __DO_XSI_MATH__ +#if defined __DO_XSI_MATH__ && !(defined TEST_LDOUBLE || defined TEST_FLOAT) j0_test (); j1_test (); jn_test (); -- cgit v1.2.3 From 85cfbc035370d2a3715ea9de3e590ba83fae52d1 Mon Sep 17 00:00:00 2001 From: Zhiqiang Zhang Date: Wed, 18 Mar 2015 18:44:50 +0800 Subject: malloc: checked_request2size failure deadlocks For some rarely cases(almost App bugs), calling malloc with a very largre size, checked_request2size check will fail,set ENOMEM, and return 0 to caller. But this will let __malloc_lock futex locked and owned by the caller. In multithread circumstance, other thread calling malloc/calloc will NOT succeed and get locked. Signed-off-by: Zhiqiang Zhang Signed-off-by: Bernhard Reutner-Fischer --- libc/stdlib/malloc-standard/malloc.c | 5 +++-- libc/stdlib/malloc-standard/memalign.c | 2 +- libc/stdlib/malloc-standard/realloc.c | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libc/stdlib/malloc-standard/malloc.c b/libc/stdlib/malloc-standard/malloc.c index 2abb5bbdd..fd33b50c7 100644 --- a/libc/stdlib/malloc-standard/malloc.c +++ b/libc/stdlib/malloc-standard/malloc.c @@ -832,8 +832,6 @@ void* malloc(size_t bytes) } #endif - __MALLOC_LOCK; - av = get_malloc_state(); /* Convert request size to internal form by adding (sizeof(size_t)) bytes overhead plus possibly more to obtain necessary alignment and/or @@ -845,6 +843,9 @@ void* malloc(size_t bytes) checked_request2size(bytes, nb); + __MALLOC_LOCK; + av = get_malloc_state(); + /* Bypass search if no frees yet */ diff --git a/libc/stdlib/malloc-standard/memalign.c b/libc/stdlib/malloc-standard/memalign.c index 6303c1dd9..e9ae5a7b9 100644 --- a/libc/stdlib/malloc-standard/memalign.c +++ b/libc/stdlib/malloc-standard/memalign.c @@ -52,8 +52,8 @@ void* memalign(size_t alignment, size_t bytes) alignment = a; } - __MALLOC_LOCK; checked_request2size(bytes, nb); + __MALLOC_LOCK; /* Strategy: find a spot within that chunk that meets the alignment * request, and then possibly free the leading and trailing space. */ diff --git a/libc/stdlib/malloc-standard/realloc.c b/libc/stdlib/malloc-standard/realloc.c index e060b70ea..e49d11125 100644 --- a/libc/stdlib/malloc-standard/realloc.c +++ b/libc/stdlib/malloc-standard/realloc.c @@ -54,9 +54,9 @@ void* realloc(void* oldmem, size_t bytes) return NULL; } + checked_request2size(bytes, nb); __MALLOC_LOCK; av = get_malloc_state(); - checked_request2size(bytes, nb); oldp = mem2chunk(oldmem); oldsize = chunksize(oldp); -- cgit v1.2.3 From be61486447ab447ac24892845af92489fe0b7148 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Wed, 18 Mar 2015 23:11:39 +0100 Subject: malloc-standard: Add locking to malloc_trim Closes bugzilla #4586 Signed-off-by: Bernhard Reutner-Fischer --- libc/stdlib/malloc-standard/free.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libc/stdlib/malloc-standard/free.c b/libc/stdlib/malloc-standard/free.c index 39e54d635..8b7a81fca 100644 --- a/libc/stdlib/malloc-standard/free.c +++ b/libc/stdlib/malloc-standard/free.c @@ -104,9 +104,13 @@ static int __malloc_trim(size_t pad, mstate av) */ int malloc_trim(size_t pad) { + int r; + __MALLOC_LOCK; mstate av = get_malloc_state(); __malloc_consolidate(av); - return __malloc_trim(pad, av); + r = __malloc_trim(pad, av); + __MALLOC_UNLOCK; + return r; } /* -- cgit v1.2.3 From 39206e01eb5d27b61410a05f2ccf6051a305db02 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Wed, 18 Mar 2015 23:12:58 +0100 Subject: malloc.h: Add missing feature guard Signed-off-by: Bernhard Reutner-Fischer --- include/malloc.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/malloc.h b/include/malloc.h index 3209fb070..a289c9317 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -132,6 +132,7 @@ extern __malloc_ptr_t valloc __MALLOC_P ((size_t __size)) __attribute_malloc__; #ifdef __MALLOC_STANDARD__ +# ifdef __USE_SVID /* SVID2/XPG mallinfo structure */ struct mallinfo { int arena; /* total space allocated from system */ @@ -149,10 +150,13 @@ struct mallinfo { /* Returns a copy of the updated current mallinfo. */ extern struct mallinfo mallinfo __MALLOC_P ((void)); libc_hidden_proto(mallinfo) +# endif /* __USE_SVID */ +# ifdef __USE_GNU /* Release all but __pad bytes of freed top-most memory back to the system. Return 1 if successful, else 0. */ extern int malloc_trim(size_t pad); +# endif /* __USE_GNU */ #include /* Prints brief summary statistics to the specified file. -- cgit v1.2.3 From 74e49a5e545576f1436a510495e2e8a682b0db4d Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Sun, 22 Mar 2015 14:47:29 +0100 Subject: extra: add clang flags for gen_bits_syscall_h Closes bugzilla #6008 Signed-off-by: Bernhard Reutner-Fischer --- extra/scripts/gen_bits_syscall_h.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/extra/scripts/gen_bits_syscall_h.sh b/extra/scripts/gen_bits_syscall_h.sh index c44cd8fa4..bfd06b832 100755 --- a/extra/scripts/gen_bits_syscall_h.sh +++ b/extra/scripts/gen_bits_syscall_h.sh @@ -23,6 +23,7 @@ fi case $CC in *icc*) CC_SYSNUM_ARGS="-dM" ;; +*clang*) CC_SYSNUM_ARGS="-dM" ;; *) CC_SYSNUM_ARGS="-dN" ;; esac -- cgit v1.2.3 From fdebbe2044653c5c84172524ed6e036d38716d88 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Sun, 22 Mar 2015 14:47:29 +0100 Subject: test: enable libm test log2 Signed-off-by: Bernhard Reutner-Fischer --- test/math/libm-test.inc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/test/math/libm-test.inc b/test/math/libm-test.inc index 8f0db3c88..f50b48b81 100644 --- a/test/math/libm-test.inc +++ b/test/math/libm-test.inc @@ -3418,8 +3418,6 @@ log1p_test (void) END (log1p); } - -#if 0 static void log2_test (void) { @@ -3449,8 +3447,6 @@ log2_test (void) END (log2); } -#endif - static void logb_test (void) @@ -4968,9 +4964,7 @@ main (int argc, char **argv) log_test (); log10_test (); log1p_test (); -#if 0 log2_test (); -#endif logb_test (); modf_test (); ilogb_test (); -- cgit v1.2.3 From 9faa7e94b824e1dc5fd9ce1b6f16c1b3f13c601a Mon Sep 17 00:00:00 2001 From: Khem Raj Date: Sat, 23 Jun 2012 13:26:30 -0700 Subject: atexit_old: Do not add it to shared libc atexit should only be in either uclibc_nonshared.a shared libc case or libc.a in static build case Signed-off-by: Khem Raj Signed-off-by: Bernhard Reutner-Fischer --- libc/stdlib/Makefile.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libc/stdlib/Makefile.in b/libc/stdlib/Makefile.in index 880de78d8..071f91119 100644 --- a/libc/stdlib/Makefile.in +++ b/libc/stdlib/Makefile.in @@ -61,7 +61,6 @@ CSRC-$(if $(findstring yyy,$(UCLIBC_HAS_FLOATS)$(UCLIBC_HAS_WCHAR)$(UCLIBC_HAS_X # multi source _atexit.c CSRC-y += __cxa_atexit.c __cxa_finalize.c __exit_handler.c exit.c on_exit.c -CSRC-$(COMPAT_ATEXIT) += old_atexit.c STDLIB_DIR := $(top_srcdir)libc/stdlib STDLIB_OUT := $(top_builddir)libc/stdlib @@ -71,11 +70,12 @@ STDLIB_OBJ := $(patsubst %.c,$(STDLIB_OUT)/%.o,$(CSRC-y)) libc-y += $(STDLIB_OBJ) libc-static-y += $(STDLIB_OUT)/atexit.o $(STDLIB_OUT)/system.o +libc-static-$(COMPAT_ATEXIT) += $(STDLIB_OUT)/old_atexit.o libc-shared-y += $(STDLIB_OUT)/system.oS # this should always be the PIC version, because it could be used in shared libs libc-nonshared-y += $(STDLIB_OUT)/atexit.os - +libc-nonshared-$(COMPAT_ATEXIT) += $(STDLIB_OUT)/old_atexit.os libc-nomulti-y += $(STDLIB_OUT)/labs.o $(STDLIB_OUT)/atol.o $(STDLIB_OUT)/_stdlib_strto_l.o $(STDLIB_OUT)/_stdlib_strto_ll.o libc-nomulti-$(UCLIBC_HAS_XLOCALE) += $(STDLIB_OUT)/_stdlib_strto_l_l.o $(STDLIB_OUT)/_stdlib_strto_ll_l.o -- cgit v1.2.3 From bfb988452cc66ddf93f69a199c50ea1c14e9ccb7 Mon Sep 17 00:00:00 2001 From: Khem Raj Date: Sat, 23 Jun 2012 14:21:17 -0700 Subject: nptl/arm: Move aeabi_read_tp to uclibc_nonshared.a Otherwise it creates wrong references from shared libs Signed-off-by: Khem Raj Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/arm/Makefile.arch | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libc/sysdeps/linux/arm/Makefile.arch b/libc/sysdeps/linux/arm/Makefile.arch index 3054273df..cda3db206 100644 --- a/libc/sysdeps/linux/arm/Makefile.arch +++ b/libc/sysdeps/linux/arm/Makefile.arch @@ -13,7 +13,9 @@ SSRC-y := \ vfork.S clone.S SSRC-$(UCLIBC_HAS_LFS) += mmap64.S -SSRC-$(UCLIBC_HAS_THREADS_NATIVE) += libc-aeabi_read_tp.S libc-thumb_atomics.S +SSRC-$(UCLIBC_HAS_THREADS_NATIVE) += libc-thumb_atomics.S +libc-nonshared-$(UCLIBC_HAS_THREADS_NATIVE) += $(ARCH_OUT)/libc-aeabi_read_tp.os +libc-static-$(UCLIBC_HAS_THREADS_NATIVE) += $(ARCH_OUT)/libc-aeabi_read_tp.o CSRC-$(UCLIBC_HAS_CONTEXT_FUNCS) += makecontext.c SSRC-$(UCLIBC_HAS_CONTEXT_FUNCS) += getcontext.S setcontext.S swapcontext.S -- cgit v1.2.3 From 5c3661fda947c1bc5e597be081c355b51c595794 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Sun, 22 Mar 2015 14:47:29 +0100 Subject: libc: Fix vfprintf compilation without HAS_FLOATS Signed-off-by: Bernhard Reutner-Fischer --- libc/stdio/_fpmaxtostr.h | 22 +++++++++++----------- libc/stdio/_vfprintf.c | 15 --------------- 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/libc/stdio/_fpmaxtostr.h b/libc/stdio/_fpmaxtostr.h index b4e7321c2..7694629ec 100644 --- a/libc/stdio/_fpmaxtostr.h +++ b/libc/stdio/_fpmaxtostr.h @@ -11,39 +11,39 @@ #define _FPMAXTOSTR_H 1 #include -#ifdef __UCLIBC_HAS_FLOATS__ - #define __need_size_t #include #include #include #include #include -#include -#include + +#ifdef __UCLIBC_HAS_FLOATS__ +# include +# include /* WARNING: Adjust _fp_out_wide() in _vfprintf.c if this changes! */ /* With 32 bit ints, we can get 9 decimal digits per block. */ -#define DIGITS_PER_BLOCK 9 +# define DIGITS_PER_BLOCK 9 -#define NUM_DIGIT_BLOCKS ((DECIMAL_DIG+DIGITS_PER_BLOCK-1)/DIGITS_PER_BLOCK) +# define NUM_DIGIT_BLOCKS ((DECIMAL_DIG+DIGITS_PER_BLOCK-1)/DIGITS_PER_BLOCK) /* WARNING: Adjust _fp_out_wide() in _vfprintf.c if this changes! */ /* extra space for '-', '.', 'e+###', and nul */ -#define BUF_SIZE ( 3 + NUM_DIGIT_BLOCKS * DIGITS_PER_BLOCK ) +# define BUF_SIZE ( 3 + NUM_DIGIT_BLOCKS * DIGITS_PER_BLOCK ) /* psm: why do these internals differ? */ -#ifdef __USE_OLD_VFPRINTF__ +# ifdef __USE_OLD_VFPRINTF__ typedef void (__fp_outfunc_t)(FILE *fp, intptr_t type, intptr_t len, intptr_t buf); extern size_t _fpmaxtostr(FILE * fp, __fpmax_t x, struct printf_info *info, __fp_outfunc_t fp_outfunc) attribute_hidden; -#else +# else typedef size_t (__fp_outfunc_t)(FILE *fp, intptr_t type, intptr_t len, intptr_t buf); extern ssize_t _fpmaxtostr(FILE * fp, __fpmax_t x, struct printf_info *info, __fp_outfunc_t fp_outfunc) attribute_hidden; -#endif +# endif -#endif /* __UCLIBC_HAS_FLOATS__ */ +# endif /* __UCLIBC_HAS_FLOATS__ */ #endif /* _FPMAXTOSTR_H */ diff --git a/libc/stdio/_vfprintf.c b/libc/stdio/_vfprintf.c index 01ee218e5..a795f4979 100644 --- a/libc/stdio/_vfprintf.c +++ b/libc/stdio/_vfprintf.c @@ -121,18 +121,6 @@ #error Apparently, LONG_LONG_MAX is defined but LLONG_MAX is not. You need to fix your toolchain headers to support the standard macros for (unsigned) long long. #endif -/**********************************************************************/ -/* These provide some control over printf's feature set */ - -/* Now controlled by uClibc_config.h. */ -/* #define __UCLIBC_HAS_FLOATS__ 1 */ - -/* Now controlled by uClibc_config.h. */ -/* #define __UCLIBC_HAS_PRINTF_M_SPEC__ */ - - -/**********************************************************************/ - #include "_fpmaxtostr.h" #undef __STDIO_HAS_VSNPRINTF @@ -142,9 +130,6 @@ /**********************************************************************/ -/* Now controlled by uClibc_config.h. */ -/* #define __UCLIBC_HAS_GLIBC_CUSTOM_PRINTF__ */ - #ifdef __UCLIBC_MJN3_ONLY__ # ifdef L_register_printf_function /* emit only once */ -- cgit v1.2.3 From bf6f1313132a3d99d645ea8b6661c23d68235278 Mon Sep 17 00:00:00 2001 From: Khem Raj Date: Sat, 23 Jun 2012 15:59:01 -0700 Subject: nptl/atfork: Hide pthread_atfork in shared versions Signed-off-by: Khem Raj Signed-off-by: Bernhard Reutner-Fischer --- libpthread/nptl/pthread_atfork.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libpthread/nptl/pthread_atfork.c b/libpthread/nptl/pthread_atfork.c index 3c12cd470..39ac3e262 100644 --- a/libpthread/nptl/pthread_atfork.c +++ b/libpthread/nptl/pthread_atfork.c @@ -37,13 +37,17 @@ #include /* This is defined by newer gcc version unique for each module. */ -extern void *__dso_handle __attribute__ ((__weak__)); - //,__visibility__ ("hidden"))); +extern void *__dso_handle __attribute__ ((__weak__, + __visibility__ ("hidden"))); /* Hide the symbol so that no definition but the one locally in the executable or DSO is used. */ int +#ifndef __pthread_atfork +/* Don't mark the compatibility function as hidden. */ +attribute_hidden +#endif __pthread_atfork ( void (*prepare) (void), void (*parent) (void), @@ -52,4 +56,8 @@ __pthread_atfork ( return __register_atfork (prepare, parent, child, &__dso_handle == NULL ? NULL : __dso_handle); } +#ifndef __pthread_atfork +extern int pthread_atfork (void (*prepare) (void), void (*parent) (void), + void (*child) (void)) attribute_hidden; strong_alias (__pthread_atfork, pthread_atfork) +#endif -- cgit v1.2.3 From 534f44d53146457b3ca686c47efb9207543b88e1 Mon Sep 17 00:00:00 2001 From: Khem Raj Date: Sat, 23 Jun 2012 16:51:52 -0700 Subject: librt: Use -nodefaultlibs instead of -nostdlib nostdlib disables linking in startup files too which is not what we want here since it needs to resolve __dso_handle which comes from crtbeginS.o, otherwise librt has this undefined reference to a weak undefined __dso_handle that shows up as error (with gold linker) when shared libraries are being built which are linking in librt Signed-off-by: Khem Raj Signed-off-by: Bernhard Reutner-Fischer --- librt/Makefile.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/librt/Makefile.in b/librt/Makefile.in index 8555e94db..fbbf5b447 100644 --- a/librt/Makefile.in +++ b/librt/Makefile.in @@ -15,6 +15,9 @@ LIBS-librt.so := $(LIBS) ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y) LIBS-librt.so += $(top_builddir)lib/libdl.so $(top_builddir)lib/libpthread.so endif +START_FILE-librt.so := $(SHARED_START_FILES) +END_FILE-librt.so := $(SHARED_END_FILES) + librt_FULL_NAME := librt-$(VERSION).so -- cgit v1.2.3 From 09ff424905d5de0b2a21a3960d9756a90b07ba26 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Sun, 22 Mar 2015 14:47:29 +0100 Subject: libc: add getrandom(2) Introduce a for it. /* FIXME: aren't there a couple of __restrict and const missing ? */ extern int getrandom(void *__buf, size_t count, unsigned int flags) __nonnull ((1)) __wur; Signed-off-by: Bernhard Reutner-Fischer --- Makefile.in | 1 + extra/Configs/Config.in | 2 +- libc/sysdeps/linux/common/Makefile.in | 1 + libc/sysdeps/linux/common/bits/kernel-features.h | 5 ++++ libc/sysdeps/linux/common/getrandom.c | 14 ++++++++++ libc/sysdeps/linux/common/stubs.c | 4 +++ libc/sysdeps/linux/common/sys/random.h | 33 ++++++++++++++++++++++++ 7 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 libc/sysdeps/linux/common/getrandom.c create mode 100644 libc/sysdeps/linux/common/sys/random.h diff --git a/Makefile.in b/Makefile.in index 5d60ddaba..a64fec956 100644 --- a/Makefile.in +++ b/Makefile.in @@ -310,6 +310,7 @@ HEADERS_RM-$(UCLIBC_LINUX_SPECIFIC) += \ sys/perm.h \ sys/personality.h \ sys/prctl.h \ + sys/random.h \ sys/reboot.h \ sys/sendfile.h \ bits/signalfd.h \ diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in index f5210cdf9..35c1cee9a 100644 --- a/extra/Configs/Config.in +++ b/extra/Configs/Config.in @@ -1025,7 +1025,7 @@ config UCLIBC_LINUX_SPECIFIC help accept4(), bdflush(), capget(), capset(), eventfd(), fallocate(), - fstatfs(), inotify_*(), ioperm(), iopl(), + fstatfs(), getrandom(), inotify_*(), ioperm(), iopl(), madvise(), modify_ldt(), pipe2(), personality(), prctl()/arch_prctl(), pivot_root(), modify_ldt(), ppoll(), readahead(), reboot(), remap_file_pages(), diff --git a/libc/sysdeps/linux/common/Makefile.in b/libc/sysdeps/linux/common/Makefile.in index 8ee956b6b..82525984a 100644 --- a/libc/sysdeps/linux/common/Makefile.in +++ b/libc/sysdeps/linux/common/Makefile.in @@ -27,6 +27,7 @@ CSRC-$(UCLIBC_LINUX_SPECIFIC) += \ eventfd.c \ eventfd_read.c \ eventfd_write.c \ + getrandom.c \ inotify.c \ ioperm.c \ iopl.c \ diff --git a/libc/sysdeps/linux/common/bits/kernel-features.h b/libc/sysdeps/linux/common/bits/kernel-features.h index 6184c2b9d..708bb4906 100644 --- a/libc/sysdeps/linux/common/bits/kernel-features.h +++ b/libc/sysdeps/linux/common/bits/kernel-features.h @@ -507,3 +507,8 @@ #if defined __x86_64__ && __LINUX_KERNEL_VERSION >= 0x030100 # define __ASSUME_GETCPU_SYSCALL 1 #endif + +/* getrandom syscall (widely) appeared around 4.0.0 */ +#if __LINUX_KERNEL_VERSION >= 0x040000 +# define __ASSUME_GETRANDOM_SYSCALL 1 +#endif diff --git a/libc/sysdeps/linux/common/getrandom.c b/libc/sysdeps/linux/common/getrandom.c new file mode 100644 index 000000000..d33d5224a --- /dev/null +++ b/libc/sysdeps/linux/common/getrandom.c @@ -0,0 +1,14 @@ +/* vi: set sw=4 ts=4: */ +/* + * getrandom() for uClibc + * + * Copyright (C) 2015 Bernhard Reutner-Fischer + * + * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball. + */ + +#include +#include +#ifdef __NR_getrandom +_syscall3(int, getrandom, void *, buf, size_t, buflen, unsigned int, flags) +#endif diff --git a/libc/sysdeps/linux/common/stubs.c b/libc/sysdeps/linux/common/stubs.c index 2c50307aa..19a33714a 100644 --- a/libc/sysdeps/linux/common/stubs.c +++ b/libc/sysdeps/linux/common/stubs.c @@ -157,6 +157,10 @@ make_stub(getpeername) make_stub(getpgrp) #endif +#if !defined __NR_getrandom && defined __UCLIBC_LINUX_SPECIFIC__ +make_stub(getrandom) +#endif + #if !defined __NR_getsockname && !defined __NR_socketcall && defined __UCLIBC_HAS_SOCKET__ make_stub(getsockname) #endif diff --git a/libc/sysdeps/linux/common/sys/random.h b/libc/sysdeps/linux/common/sys/random.h new file mode 100644 index 000000000..42f802576 --- /dev/null +++ b/libc/sysdeps/linux/common/sys/random.h @@ -0,0 +1,33 @@ +/* Copyright (C) 2015 Bernhard Reutner-Fischer + * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball. +*/ + +#ifndef _SYS_RANDOM_H +#define _SYS_RANDOM_H 1 +#include + +__BEGIN_DECLS + +#if defined __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU +# if 0 /*def __ASSUME_GETRANDOM_SYSCALL */ +# include +# else +# undef GRND_NONBLOCK +# undef GRND_RANDOM +/* + * Flags for getrandom(2) + * + * GRND_NONBLOCK Don't block and return EAGAIN instead + * GRND_RANDOM Use the /dev/random pool instead of /dev/urandom + */ +# define GRND_NONBLOCK 0x0001 +# define GRND_RANDOM 0x0002 +# endif +/* FIXME: aren't there a couple of __restrict and const missing ? */ +extern int getrandom(void *__buf, size_t count, unsigned int flags) + __nonnull ((1)) __wur; +#endif + +__END_DECLS + +#endif /* sys/random.h */ -- cgit v1.2.3 From 63729418992d5f63965a88fa2ac3570e3d270479 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Sun, 22 Mar 2015 14:47:29 +0100 Subject: test: add utmpx test Signed-off-by: Bernhard Reutner-Fischer --- test/.gitignore | 1 + test/misc/Makefile.in | 4 ++++ test/misc/tst-utmp.c | 15 +++++++++++++++ test/misc/tst-utmpx.c | 2 ++ 4 files changed, 22 insertions(+) create mode 100644 test/misc/tst-utmpx.c diff --git a/test/.gitignore b/test/.gitignore index 5944f0a0f..beb50958d 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -163,6 +163,7 @@ misc/tst-seekdir misc/tst-statfs misc/tst-statvfs misc/tst-utmp +misc/tst-utmpx mmap/mmap mmap/mmap2 mmap/mmap64 diff --git a/test/misc/Makefile.in b/test/misc/Makefile.in index 1e0da6f43..2fb9652fd 100644 --- a/test/misc/Makefile.in +++ b/test/misc/Makefile.in @@ -16,6 +16,10 @@ ifeq ($(UCLIBC_HAS_GLOB),) TESTS_DISABLED += bug-glob2 endif +ifeq ($(UCLIBC_HAS_UTMPX),) +TESTS_DISABLED += tst-utmpx +endif + DODIFF_dirent := 1 DODIFF_dirent64 := 1 DODIFF_tst-statfs := 1 diff --git a/test/misc/tst-utmp.c b/test/misc/tst-utmp.c index 08a6f8ea3..1b0333a32 100644 --- a/test/misc/tst-utmp.c +++ b/test/misc/tst-utmp.c @@ -37,6 +37,21 @@ # include #endif +#ifndef _HAVE_UT_TYPE +# define _HAVE_UT_TYPE 0 +#endif +#ifndef _HAVE_UT_PID +# define _HAVE_UT_PID 0 +#endif +#ifndef _HAVE_UT_ID +# define _HAVE_UT_ID 0 +#endif +#ifndef _HAVE_UT_TV +# define _HAVE_UT_TV 0 +#endif +#ifndef _HAVE_UT_HOST +# define _HAVE_UT_HOST 0 +#endif #if _HAVE_UT_TYPE || defined UTMPX diff --git a/test/misc/tst-utmpx.c b/test/misc/tst-utmpx.c new file mode 100644 index 000000000..edb5551d7 --- /dev/null +++ b/test/misc/tst-utmpx.c @@ -0,0 +1,2 @@ +#define UTMPX +#include "tst-utmp.c" -- cgit v1.2.3 From 9277fe13156a6ff2b055fe8a58d2863115c36b6a Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 24 Mar 2015 00:09:45 +0100 Subject: Revert "utent.c, wtent.c: move functions from utxent.c" This reverts commit 84135275cfeebc0b233c1c96eeada4d4178a0b18. This change is said to make systemd deadlock (cannot reproduce this) Signed-off-by: Bernhard Reutner-Fischer Conflicts: include/utmp.h --- include/utmp.h | 8 +++++ libc/misc/utmp/utent.c | 80 ++++++++++++------------------------------------- libc/misc/utmp/utxent.c | 4 +-- libc/misc/utmp/wtent.c | 14 ++------- 4 files changed, 30 insertions(+), 76 deletions(-) diff --git a/include/utmp.h b/include/utmp.h index 2908e3386..754f76781 100644 --- a/include/utmp.h +++ b/include/utmp.h @@ -56,29 +56,37 @@ extern void logwtmp (const char *__ut_line, const char *__ut_name, /* Append entry UTMP to the wtmp-like file WTMP_FILE. */ extern void updwtmp (const char *__wtmp_file, const struct utmp *__utmp) __THROW; +libc_hidden_proto(updwtmp) /* Change name of the utmp file to be examined. */ extern int utmpname (const char *__file) __THROW; +libc_hidden_proto(utmpname) /* Read next entry from a utmp-like file. */ extern struct utmp *getutent (void) __THROW; +libc_hidden_proto(getutent) /* Reset the input stream to the beginning of the file. */ extern void setutent (void) __THROW; +libc_hidden_proto(setutent) /* Close the current open file. */ extern void endutent (void) __THROW; +libc_hidden_proto(endutent) /* Search forward from the current point in the utmp file until the next entry with a ut_type matching ID->ut_type. */ extern struct utmp *getutid (const struct utmp *__id) __THROW; +libc_hidden_proto(getutid) /* Search forward from the current point in the utmp file until the next entry with a ut_line matching LINE->ut_line. */ extern struct utmp *getutline (const struct utmp *__line) __THROW; +libc_hidden_proto(getutline) /* Write out entry pointed to by UTMP_PTR into the utmp file. */ extern struct utmp *pututline (const struct utmp *__utmp_ptr) __THROW; +libc_hidden_proto(pututline) #if 0 /* def __USE_MISC */ diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c index a35bb2b84..07ca44eb2 100644 --- a/libc/misc/utmp/utent.c +++ b/libc/misc/utmp/utent.c @@ -19,9 +19,6 @@ #include #include #include -#ifdef __UCLIBC_HAS_UTMPX__ -# include -#endif #include #include @@ -34,7 +31,7 @@ static const char default_file_name[] = _PATH_UTMP; static const char *static_ut_name = default_file_name; /* This function must be called with the LOCK held */ -static void __setutent_unlocked(void) +static void __setutent(void) { if (static_fd < 0) { static_fd = open_not_cancel_2(static_ut_name, O_RDWR | O_CLOEXEC); @@ -53,24 +50,19 @@ static void __setutent_unlocked(void) lseek(static_fd, 0, SEEK_SET); } #if defined __UCLIBC_HAS_THREADS__ -static void __setutent(void) +void setutent(void) { __UCLIBC_MUTEX_LOCK(utmplock); - __setutent_unlocked(); + __setutent(); __UCLIBC_MUTEX_UNLOCK(utmplock); } #else -static void __setutent(void); -strong_alias(__setutent_unlocked,__setutent) -#endif strong_alias(__setutent,setutent) - -#ifdef __UCLIBC_HAS_UTMPX__ -strong_alias(__setutent,setutxent) #endif +libc_hidden_def(setutent) /* This function must be called with the LOCK held */ -static struct utmp *__getutent_unlocked(void) +static struct utmp *__getutent(void) { if (static_fd < 0) { __setutent(); @@ -86,27 +78,19 @@ static struct utmp *__getutent_unlocked(void) return NULL; } #if defined __UCLIBC_HAS_THREADS__ -static struct utmp *__getutent(void) +struct utmp *getutent(void) { struct utmp *ret; __UCLIBC_MUTEX_LOCK(utmplock); - ret = __getutent_unlocked(); + ret = __getutent(); __UCLIBC_MUTEX_UNLOCK(utmplock); return ret; } #else -static struct utmp *__getutent(void); -strong_alias(__getutent_unlocked,__getutent) -#endif strong_alias(__getutent,getutent) - -#ifdef __UCLIBC_HAS_UTMPX__ -struct utmpx *getutxent(void) -{ - return (struct utmpx *) __getutent (); -} #endif +libc_hidden_def(getutent) static void __endutent(void) { @@ -117,13 +101,10 @@ static void __endutent(void) __UCLIBC_MUTEX_UNLOCK(utmplock); } strong_alias(__endutent,endutent) - -#ifdef __UCLIBC_HAS_UTMPX__ -strong_alias(__endutent,endutxent) -#endif +libc_hidden_def(endutent) /* This function must be called with the LOCK held */ -static struct utmp *__getutid_unlocked(const struct utmp *utmp_entry) +static struct utmp *__getutid(const struct utmp *utmp_entry) { struct utmp *lutmp; unsigned type; @@ -133,7 +114,7 @@ static struct utmp *__getutid_unlocked(const struct utmp *utmp_entry) type = utmp_entry->ut_type - 1; type /= 4; - while ((lutmp = __getutent_unlocked()) != NULL) { + while ((lutmp = __getutent()) != NULL) { if (type == 0 && lutmp->ut_type == utmp_entry->ut_type) { /* one of RUN_LVL, BOOT_TIME, NEW_TIME, OLD_TIME */ return lutmp; @@ -147,34 +128,26 @@ static struct utmp *__getutid_unlocked(const struct utmp *utmp_entry) return NULL; } #if defined __UCLIBC_HAS_THREADS__ -static struct utmp *__getutid(const struct utmp *utmp_entry) +struct utmp *getutid(const struct utmp *utmp_entry) { struct utmp *ret; __UCLIBC_MUTEX_LOCK(utmplock); - ret = __getutid_unlocked(utmp_entry); + ret = __getutid(utmp_entry); __UCLIBC_MUTEX_UNLOCK(utmplock); return ret; } #else -static struct utmp *__getutid(const struct utmp *utmp_entry); -strong_alias(__getutid_unlocked,__getutid) -#endif strong_alias(__getutid,getutid) - -#ifdef __UCLIBC_HAS_UTMPX__ -struct utmpx *getutxid(const struct utmpx *utmp_entry) -{ - return (struct utmpx *) __getutid ((const struct utmp *) utmp_entry); -} #endif +libc_hidden_def(getutid) static struct utmp *__getutline(const struct utmp *utmp_entry) { struct utmp *lutmp; __UCLIBC_MUTEX_LOCK(utmplock); - while ((lutmp = __getutent_unlocked()) != NULL) { + while ((lutmp = __getutent()) != NULL) { if (lutmp->ut_type == USER_PROCESS || lutmp->ut_type == LOGIN_PROCESS) { if (strncmp(lutmp->ut_line, utmp_entry->ut_line, sizeof(lutmp->ut_line)) == 0) { break; @@ -185,13 +158,7 @@ static struct utmp *__getutline(const struct utmp *utmp_entry) return lutmp; } strong_alias(__getutline,getutline) - -#ifdef __UCLIBC_HAS_UTMPX__ -struct utmpx *getutxline(const struct utmpx *utmp_entry) -{ - return (struct utmpx *) __getutline ((const struct utmp *) utmp_entry); -} -#endif +libc_hidden_def(getutline) static struct utmp *__pututline(const struct utmp *utmp_entry) { @@ -200,7 +167,7 @@ static struct utmp *__pututline(const struct utmp *utmp_entry) the file pointer where they want it, everything will work out. */ lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR); - if (__getutid_unlocked(utmp_entry) != NULL) + if (__getutid(utmp_entry) != NULL) lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR); else lseek(static_fd, (off_t) 0, SEEK_END); @@ -211,13 +178,7 @@ static struct utmp *__pututline(const struct utmp *utmp_entry) return (struct utmp *)utmp_entry; } strong_alias(__pututline,pututline) - -#ifdef __UCLIBC_HAS_UTMPX__ -struct utmpx *pututxline (const struct utmpx *utmp_entry) -{ - return (struct utmpx *) __pututline ((const struct utmp *) utmp_entry); -} -#endif +libc_hidden_def(pututline) static int __utmpname(const char *new_ut_name) { @@ -241,7 +202,4 @@ static int __utmpname(const char *new_ut_name) return 0; /* or maybe return -(static_ut_name != new_ut_name)? */ } strong_alias(__utmpname,utmpname) - -#ifdef __UCLIBC_HAS_UTMPX__ -strong_alias(__utmpname,utmpxname) -#endif +libc_hidden_def(utmpname) diff --git a/libc/misc/utmp/utxent.c b/libc/misc/utmp/utxent.c index 71157ccd8..a0e80a662 100644 --- a/libc/misc/utmp/utxent.c +++ b/libc/misc/utmp/utxent.c @@ -13,7 +13,6 @@ #include #include -#if 0 /* moved to utent.c */ void setutxent(void) { setutent (); @@ -49,12 +48,10 @@ int utmpxname (const char *new_ut_name) return utmpname (new_ut_name); } -/* moved to wtent.c */ void updwtmpx (const char *wtmpx_file, const struct utmpx *utmpx) { updwtmp (wtmpx_file, (const struct utmp *) utmpx); } -#endif /* Copy the information in UTMPX to UTMP. */ void getutmp (const struct utmpx *utmpx, struct utmp *utmp) @@ -107,3 +104,4 @@ void getutmpx (const struct utmp *utmp, struct utmpx *utmpx) utmpx->ut_time = utmp->ut_time; #endif } + diff --git a/libc/misc/utmp/wtent.c b/libc/misc/utmp/wtent.c index 9b3ad5084..b5e4ee576 100644 --- a/libc/misc/utmp/wtent.c +++ b/libc/misc/utmp/wtent.c @@ -11,9 +11,6 @@ #include #include #include -#ifdef __UCLIBC_HAS_UTMPX__ -# include -#endif #include #include #include @@ -36,7 +33,7 @@ void logwtmp (const char *line, const char *name, const char *host) } #endif -static void __updwtmp(const char *wtmp_file, const struct utmp *lutmp) +void updwtmp(const char *wtmp_file, const struct utmp *lutmp) { int fd; @@ -49,11 +46,4 @@ static void __updwtmp(const char *wtmp_file, const struct utmp *lutmp) } } } -strong_alias(__updwtmp,updwtmp) - -#ifdef __UCLIBC_HAS_UTMPX__ -void updwtmpx (const char *wtmpx_file, const struct utmpx *utmpx) -{ - __updwtmp (wtmpx_file, (const struct utmp *) utmpx); -} -#endif +libc_hidden_def(updwtmp) -- cgit v1.2.3 From eee76e42f32f90af4e64a254810fcb767297fecf Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 24 Mar 2015 00:11:15 +0100 Subject: libc: TIME64_COMPAT32 for sparc, mips Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/common/bits/utmp.h | 4 ++-- libc/sysdeps/linux/common/bits/utmpx.h | 2 +- libc/sysdeps/linux/mips/bits/wordsize.h | 3 +++ libc/sysdeps/linux/powerpc/bits/wordsize.h | 2 +- libc/sysdeps/linux/sparc/bits/wordsize.h | 1 + libc/sysdeps/linux/x86_64/bits/wordsize.h | 9 ++++++--- libutil/logout.c | 2 +- libutil/logwtmp.c | 2 +- 8 files changed, 16 insertions(+), 9 deletions(-) diff --git a/libc/sysdeps/linux/common/bits/utmp.h b/libc/sysdeps/linux/common/bits/utmp.h index c13380ab8..6ece31e34 100644 --- a/libc/sysdeps/linux/common/bits/utmp.h +++ b/libc/sysdeps/linux/common/bits/utmp.h @@ -36,7 +36,7 @@ previous logins. */ struct lastlog { -#if __WORDSIZE == 64 && defined __WORDSIZE_COMPAT32 +#ifdef __WORDSIZE_TIME64_COMPAT32 int32_t ll_time; #else __time_t ll_time; @@ -69,7 +69,7 @@ struct utmp /* The ut_session and ut_tv fields must be the same size when compiled 32- and 64-bit. This allows data files and shared memory to be shared between 32- and 64-bit applications. */ -#if __WORDSIZE == 64 && defined __WORDSIZE_COMPAT32 +#ifdef __WORDSIZE_TIME64_COMPAT32 int32_t ut_session; /* Session ID, used for windowing. */ struct { diff --git a/libc/sysdeps/linux/common/bits/utmpx.h b/libc/sysdeps/linux/common/bits/utmpx.h index 87626f085..815fc90b8 100644 --- a/libc/sysdeps/linux/common/bits/utmpx.h +++ b/libc/sysdeps/linux/common/bits/utmpx.h @@ -66,7 +66,7 @@ struct utmpx /* The fields ut_session and ut_tv must be the same size when compiled 32- and 64-bit. This allows files and shared memory to be shared between 32- and 64-bit applications. */ -#if __WORDSIZE == 64 && defined __WORDSIZE_COMPAT32 +#ifdef __WORDSIZE_TIME64_COMPAT32 __int32_t ut_session; /* Session ID, used for windowing. */ struct { diff --git a/libc/sysdeps/linux/mips/bits/wordsize.h b/libc/sysdeps/linux/mips/bits/wordsize.h index 39e15062c..fe130806c 100644 --- a/libc/sysdeps/linux/mips/bits/wordsize.h +++ b/libc/sysdeps/linux/mips/bits/wordsize.h @@ -16,3 +16,6 @@ . */ #define __WORDSIZE _MIPS_SZPTR +#if _MIPS_SIM == _ABI64 +# define __WORDSIZE_TIME64_COMPAT32 1 +#endif diff --git a/libc/sysdeps/linux/powerpc/bits/wordsize.h b/libc/sysdeps/linux/powerpc/bits/wordsize.h index cf934234f..3e8a1e0a1 100644 --- a/libc/sysdeps/linux/powerpc/bits/wordsize.h +++ b/libc/sysdeps/linux/powerpc/bits/wordsize.h @@ -2,7 +2,7 @@ #if defined __powerpc64__ # define __WORDSIZE 64 -# define __WORDSIZE_COMPAT32 1 +# define __WORDSIZE_TIME64_COMPAT32 1 #else # define __WORDSIZE 32 #endif diff --git a/libc/sysdeps/linux/sparc/bits/wordsize.h b/libc/sysdeps/linux/sparc/bits/wordsize.h index c0e600ed5..aa15dbc7a 100644 --- a/libc/sysdeps/linux/sparc/bits/wordsize.h +++ b/libc/sysdeps/linux/sparc/bits/wordsize.h @@ -2,6 +2,7 @@ #if defined __arch64__ || defined __sparcv9 # define __WORDSIZE 64 +# define __WORDSIZE_TIME64_COMPAT32 1 #else # define __WORDSIZE 32 #endif diff --git a/libc/sysdeps/linux/x86_64/bits/wordsize.h b/libc/sysdeps/linux/x86_64/bits/wordsize.h index e55524100..9db982c90 100644 --- a/libc/sysdeps/linux/x86_64/bits/wordsize.h +++ b/libc/sysdeps/linux/x86_64/bits/wordsize.h @@ -1,9 +1,12 @@ /* Determine the wordsize from the preprocessor defines. */ -#if defined __x86_64__ +#if defined __x86_64__ && !defined __ILP32__ # define __WORDSIZE 64 -/* This makes /var/run/utmp compatible with 32-bit environment: */ -# define __WORDSIZE_COMPAT32 1 #else # define __WORDSIZE 32 #endif + +#ifdef __x86_64__ +/* This makes /var/run/utmp compatible with 32-bit environment: */ +# define __WORDSIZE_TIME64_COMPAT32 1 +#endif diff --git a/libutil/logout.c b/libutil/logout.c index 9c7440b19..45804552d 100644 --- a/libutil/logout.c +++ b/libutil/logout.c @@ -50,7 +50,7 @@ logout (const char *line) memset (ut->ut_host, 0, sizeof ut->ut_host); #endif #if _HAVE_UT_TV - 0 -# if !defined __WORDSIZE_COMPAT32 || __WORDSIZE_COMPAT32 == 0 +# if !defined __WORDSIZE_TIME64_COMPAT32 gettimeofday (&ut->ut_tv, NULL); # else { diff --git a/libutil/logwtmp.c b/libutil/logwtmp.c index 2a6f28a48..6a53b5ff1 100644 --- a/libutil/logwtmp.c +++ b/libutil/logwtmp.c @@ -23,7 +23,7 @@ void logwtmp(const char *line, const char *name, const char *host) strncpy(lutmp.ut_line, line, sizeof(lutmp.ut_line)-1); strncpy(lutmp.ut_name, name, sizeof(lutmp.ut_name)-1); strncpy(lutmp.ut_host, host, sizeof(lutmp.ut_host)-1); -#if !defined __WORDSIZE_COMPAT32 || __WORDSIZE_COMPAT32 == 0 +#if !defined __WORDSIZE_TIME64_COMPAT32 gettimeofday(&lutmp.ut_tv, NULL); #else { -- cgit v1.2.3 From 4da43e9f2e4f2f7593427003e37b87287c7b16cf Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 24 Mar 2015 00:11:21 +0100 Subject: buildsys: HAS_UTMP (XPG2, SVr4 compat) knob Signed-off-by: Bernhard Reutner-Fischer --- Makefile.in | 1 + extra/Configs/Config.in | 27 +++++++++++++++++++-------- libc/misc/utmp/Makefile.in | 4 +++- libc/misc/utmp/utent.c | 1 + libc/misc/utmp/utxent.c | 1 + libc/misc/utmp/wtent.c | 1 + libutil/Makefile.in | 8 ++++++++ 7 files changed, 34 insertions(+), 9 deletions(-) diff --git a/Makefile.in b/Makefile.in index a64fec956..2233be8b2 100644 --- a/Makefile.in +++ b/Makefile.in @@ -294,6 +294,7 @@ HEADERS_RM-$(UCLIBC_HAS_THREADS) += *thread*.h semaphore.h \ bits/initspin.h HEADERS_RM-$(UCLIBC_HAS_THREADS_NATIVE) += atomic.h bits/atomic.h HEADERS_RM-$(UCLIBC_HAS_OBSTACK) += obstack.h +HEADERS_RM-$(UCLIBC_HAS_UTMP) += bits/utmp.h utmp.h HEADERS_RM-$(UCLIBC_HAS_UTMPX) += bits/utmpx.h utmpx.h HEADERS_RM-$(UCLIBC_HAS_WCHAR) += wchar.h wctype.h HEADERS_RM-$(UCLIBC_HAS_WORDEXP) += wordexp.h diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in index 35c1cee9a..7546e96ea 100644 --- a/extra/Configs/Config.in +++ b/extra/Configs/Config.in @@ -700,6 +700,25 @@ config COMPAT_ATEXIT Enable this option if you want to update from 0.9.28 to git/0.9.29, else you will be missing atexit() until you rebuild all apps. +config UCLIBC_HAS_UTMPX + bool "utmpx based support for tracking login/logouts to/from the system" + depends on UCLIBC_HAS_UTMP # TODO, remove this, it's backward + help + Answer y to enable support for accessing user accounting database. + It can be used to track all login/logout to the system. + +config UCLIBC_HAS_UTMP + bool "utmp support (XPG2, SVr4 compat)" + help + Answer y to enable legacy SVID support for accessing + user accounting database: + getutent(), getutid(), getutline(), pututline(), + setutent(), endutent(), utmpname() in utmp.h + It can be used to track all login/logout to the system. + + If unsure, just answer N and use utmpx.h and corresponding + POSIX functions. + config UCLIBC_SUSV2_LEGACY bool "Enable SuSv2 LEGACY functions" help @@ -2042,14 +2061,6 @@ config UCLIBC_HAS_GNU_GLOB Most people will answer N. -config UCLIBC_HAS_UTMPX - bool "utmpx based support for tracking login/logouts to/from the system" - help - Answer y to enable support for accessing user accounting database. - It can be used to track all login/logout to the system. - - If unsure, just answer N. - endmenu diff --git a/libc/misc/utmp/Makefile.in b/libc/misc/utmp/Makefile.in index 535efb150..715341c85 100644 --- a/libc/misc/utmp/Makefile.in +++ b/libc/misc/utmp/Makefile.in @@ -7,7 +7,9 @@ subdirs += libc/misc/utmp -CSRC-y := utent.c wtent.c +CSRC-y := +CSRC-$(if $(findstring y,$(UCLIBC_HAS_UTMP)$(UCLIBC_HAS_UTMPX)),y) += wtent.c +CSRC-$(UCLIBC_HAS_UTMP) += utent.c CSRC-$(UCLIBC_HAS_UTMPX) += utxent.c MISC_UTMP_DIR := $(top_srcdir)libc/misc/utmp diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c index 07ca44eb2..6e1567865 100644 --- a/libc/misc/utmp/utent.c +++ b/libc/misc/utmp/utent.c @@ -1,3 +1,4 @@ +/* vi: set sw=4 ts=4: */ /* utent.c */ /* Let it be known that this is very possibly the worst standard ever. HP-UX does one thing, someone else does another, linux another... If anyone diff --git a/libc/misc/utmp/utxent.c b/libc/misc/utmp/utxent.c index a0e80a662..c32e4da49 100644 --- a/libc/misc/utmp/utxent.c +++ b/libc/misc/utmp/utxent.c @@ -1,3 +1,4 @@ +/* vi: set sw=4 ts=4: */ /* * utexent.c : Support for accessing user accounting database. * Copyright (C) 2010 STMicroelectronics Ltd. diff --git a/libc/misc/utmp/wtent.c b/libc/misc/utmp/wtent.c index b5e4ee576..30939ea43 100644 --- a/libc/misc/utmp/wtent.c +++ b/libc/misc/utmp/wtent.c @@ -1,3 +1,4 @@ +/* vi: set sw=4 ts=4: */ /* * Copyright (C) 2000-2006 Erik Andersen * diff --git a/libutil/Makefile.in b/libutil/Makefile.in index f904fc7e1..98b178ef9 100644 --- a/libutil/Makefile.in +++ b/libutil/Makefile.in @@ -27,6 +27,14 @@ ifneq ($(UCLIBC_HAS_PTY),y) libutil_SRC := $(filter-out $(libutil_DIR)/openpty.c $(libutil_DIR)/forkpty.c \ ,$(libutil_SRC)) endif +ifeq ($(UCLIBC_HAS_UTMP)$(UCLIBC_HAS_UTMPX),) +libutil_SRC := $(filter-out \ + $(libutil_DIR)/logwtmp.c \ + $(libutil_DIR)/login.c \ + $(libutil_DIR)/logout.c \ + ,$(libutil_SRC)) +endif + libutil_OBJ := $(patsubst $(libutil_DIR)/%.c,$(libutil_OUT)/%.o,$(libutil_SRC)) ifeq ($(DOPIC),y) -- cgit v1.2.3 From d0f60a600bafc3f6dfc844418d310cf6a4e38c92 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 24 Mar 2015 00:11:24 +0100 Subject: utmp: add _unlocked suffix to internal helpers Signed-off-by: Bernhard Reutner-Fischer --- libc/misc/utmp/utent.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c index 6e1567865..87fe42b16 100644 --- a/libc/misc/utmp/utent.c +++ b/libc/misc/utmp/utent.c @@ -21,8 +21,8 @@ #include #include #include - #include + __UCLIBC_MUTEX_STATIC(utmplock, PTHREAD_MUTEX_INITIALIZER); /* Some global crap */ @@ -32,7 +32,7 @@ static const char default_file_name[] = _PATH_UTMP; static const char *static_ut_name = default_file_name; /* This function must be called with the LOCK held */ -static void __setutent(void) +static void __setutent_unlocked(void) { if (static_fd < 0) { static_fd = open_not_cancel_2(static_ut_name, O_RDWR | O_CLOEXEC); @@ -54,19 +54,19 @@ static void __setutent(void) void setutent(void) { __UCLIBC_MUTEX_LOCK(utmplock); - __setutent(); + __setutent_unlocked(); __UCLIBC_MUTEX_UNLOCK(utmplock); } #else -strong_alias(__setutent,setutent) +strong_alias(__setutent_unlocked,setutent) #endif libc_hidden_def(setutent) /* This function must be called with the LOCK held */ -static struct utmp *__getutent(void) +static struct utmp *__getutent_unlocked(void) { if (static_fd < 0) { - __setutent(); + __setutent_unlocked(); if (static_fd < 0) { return NULL; } @@ -84,12 +84,12 @@ struct utmp *getutent(void) struct utmp *ret; __UCLIBC_MUTEX_LOCK(utmplock); - ret = __getutent(); + ret = __getutent_unlocked(); __UCLIBC_MUTEX_UNLOCK(utmplock); return ret; } #else -strong_alias(__getutent,getutent) +strong_alias(__getutent_unlocked,getutent) #endif libc_hidden_def(getutent) @@ -105,7 +105,7 @@ strong_alias(__endutent,endutent) libc_hidden_def(endutent) /* This function must be called with the LOCK held */ -static struct utmp *__getutid(const struct utmp *utmp_entry) +static struct utmp *__getutid_unlocked(const struct utmp *utmp_entry) { struct utmp *lutmp; unsigned type; @@ -115,7 +115,7 @@ static struct utmp *__getutid(const struct utmp *utmp_entry) type = utmp_entry->ut_type - 1; type /= 4; - while ((lutmp = __getutent()) != NULL) { + while ((lutmp = __getutent_unlocked()) != NULL) { if (type == 0 && lutmp->ut_type == utmp_entry->ut_type) { /* one of RUN_LVL, BOOT_TIME, NEW_TIME, OLD_TIME */ return lutmp; @@ -134,12 +134,12 @@ struct utmp *getutid(const struct utmp *utmp_entry) struct utmp *ret; __UCLIBC_MUTEX_LOCK(utmplock); - ret = __getutid(utmp_entry); + ret = __getutid_unlocked(utmp_entry); __UCLIBC_MUTEX_UNLOCK(utmplock); return ret; } #else -strong_alias(__getutid,getutid) +strong_alias(__getutid_unlocked,getutid) #endif libc_hidden_def(getutid) @@ -148,7 +148,7 @@ static struct utmp *__getutline(const struct utmp *utmp_entry) struct utmp *lutmp; __UCLIBC_MUTEX_LOCK(utmplock); - while ((lutmp = __getutent()) != NULL) { + while ((lutmp = __getutent_unlocked()) != NULL) { if (lutmp->ut_type == USER_PROCESS || lutmp->ut_type == LOGIN_PROCESS) { if (strncmp(lutmp->ut_line, utmp_entry->ut_line, sizeof(lutmp->ut_line)) == 0) { break; @@ -168,7 +168,7 @@ static struct utmp *__pututline(const struct utmp *utmp_entry) the file pointer where they want it, everything will work out. */ lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR); - if (__getutid(utmp_entry) != NULL) + if (__getutid_unlocked(utmp_entry) != NULL) lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR); else lseek(static_fd, (off_t) 0, SEEK_END); -- cgit v1.2.3 From 97c9f52239301c81c021b8be187ac07ddf33496d Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 24 Mar 2015 00:11:28 +0100 Subject: utmp: Remove unneeded aliases Signed-off-by: Bernhard Reutner-Fischer --- libc/misc/utmp/utent.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c index 87fe42b16..c45820e3a 100644 --- a/libc/misc/utmp/utent.c +++ b/libc/misc/utmp/utent.c @@ -143,7 +143,7 @@ strong_alias(__getutid_unlocked,getutid) #endif libc_hidden_def(getutid) -static struct utmp *__getutline(const struct utmp *utmp_entry) +struct utmp *getutline(const struct utmp *utmp_entry) { struct utmp *lutmp; @@ -158,10 +158,9 @@ static struct utmp *__getutline(const struct utmp *utmp_entry) __UCLIBC_MUTEX_UNLOCK(utmplock); return lutmp; } -strong_alias(__getutline,getutline) libc_hidden_def(getutline) -static struct utmp *__pututline(const struct utmp *utmp_entry) +struct utmp *pututline(const struct utmp *utmp_entry) { __UCLIBC_MUTEX_LOCK(utmplock); /* Ignore the return value. That way, if they've already positioned @@ -178,10 +177,9 @@ static struct utmp *__pututline(const struct utmp *utmp_entry) __UCLIBC_MUTEX_UNLOCK(utmplock); return (struct utmp *)utmp_entry; } -strong_alias(__pututline,pututline) libc_hidden_def(pututline) -static int __utmpname(const char *new_ut_name) +int utmpname(const char *new_ut_name) { __UCLIBC_MUTEX_LOCK(utmplock); if (new_ut_name != NULL) { @@ -202,5 +200,4 @@ static int __utmpname(const char *new_ut_name) __UCLIBC_MUTEX_UNLOCK(utmplock); return 0; /* or maybe return -(static_ut_name != new_ut_name)? */ } -strong_alias(__utmpname,utmpname) libc_hidden_def(utmpname) -- cgit v1.2.3 From 6cba32e6e9a1910ea0a5277fd39484047094e478 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 24 Mar 2015 00:11:38 +0100 Subject: utmp: indent indent only, no code changes Signed-off-by: Bernhard Reutner-Fischer --- libc/misc/utmp/utent.c | 194 +++++++++++++++++++++++++------------------------ 1 file changed, 99 insertions(+), 95 deletions(-) diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c index c45820e3a..4d71f5e29 100644 --- a/libc/misc/utmp/utent.c +++ b/libc/misc/utmp/utent.c @@ -34,28 +34,28 @@ static const char *static_ut_name = default_file_name; /* This function must be called with the LOCK held */ static void __setutent_unlocked(void) { - if (static_fd < 0) { - static_fd = open_not_cancel_2(static_ut_name, O_RDWR | O_CLOEXEC); if (static_fd < 0) { - static_fd = open_not_cancel_2(static_ut_name, O_RDONLY | O_CLOEXEC); - if (static_fd < 0) { - return; /* static_fd remains < 0 */ - } - } + static_fd = open_not_cancel_2(static_ut_name, O_RDWR | O_CLOEXEC); + if (static_fd < 0) { + static_fd = open_not_cancel_2(static_ut_name, O_RDONLY | O_CLOEXEC); + if (static_fd < 0) { + return; /* static_fd remains < 0 */ + } + } #ifndef __ASSUME_O_CLOEXEC - /* Make sure the file will be closed on exec() */ - fcntl_not_cancel(static_fd, F_SETFD, FD_CLOEXEC); + /* Make sure the file will be closed on exec() */ + fcntl_not_cancel(static_fd, F_SETFD, FD_CLOEXEC); #endif - return; - } - lseek(static_fd, 0, SEEK_SET); + return; + } + lseek(static_fd, 0, SEEK_SET); } #if defined __UCLIBC_HAS_THREADS__ void setutent(void) { - __UCLIBC_MUTEX_LOCK(utmplock); - __setutent_unlocked(); - __UCLIBC_MUTEX_UNLOCK(utmplock); + __UCLIBC_MUTEX_LOCK(utmplock); + __setutent_unlocked(); + __UCLIBC_MUTEX_UNLOCK(utmplock); } #else strong_alias(__setutent_unlocked,setutent) @@ -65,28 +65,28 @@ libc_hidden_def(setutent) /* This function must be called with the LOCK held */ static struct utmp *__getutent_unlocked(void) { - if (static_fd < 0) { - __setutent_unlocked(); if (static_fd < 0) { - return NULL; + __setutent_unlocked(); + if (static_fd < 0) + return NULL; } - } - if (read_not_cancel(static_fd, &static_utmp, sizeof(static_utmp)) == sizeof(static_utmp)) { - return &static_utmp; - } + if (read_not_cancel(static_fd, &static_utmp, + sizeof(static_utmp)) == sizeof(static_utmp)) { + return &static_utmp; + } - return NULL; + return NULL; } #if defined __UCLIBC_HAS_THREADS__ struct utmp *getutent(void) { - struct utmp *ret; + struct utmp *ret; - __UCLIBC_MUTEX_LOCK(utmplock); - ret = __getutent_unlocked(); - __UCLIBC_MUTEX_UNLOCK(utmplock); - return ret; + __UCLIBC_MUTEX_LOCK(utmplock); + ret = __getutent_unlocked(); + __UCLIBC_MUTEX_UNLOCK(utmplock); + return ret; } #else strong_alias(__getutent_unlocked,getutent) @@ -95,11 +95,11 @@ libc_hidden_def(getutent) static void __endutent(void) { - __UCLIBC_MUTEX_LOCK(utmplock); - if (static_fd >= 0) - close_not_cancel_no_status(static_fd); - static_fd = -1; - __UCLIBC_MUTEX_UNLOCK(utmplock); + __UCLIBC_MUTEX_LOCK(utmplock); + if (static_fd >= 0) + close_not_cancel_no_status(static_fd); + static_fd = -1; + __UCLIBC_MUTEX_UNLOCK(utmplock); } strong_alias(__endutent,endutent) libc_hidden_def(endutent) @@ -107,36 +107,38 @@ libc_hidden_def(endutent) /* This function must be called with the LOCK held */ static struct utmp *__getutid_unlocked(const struct utmp *utmp_entry) { - struct utmp *lutmp; - unsigned type; - - /* We use the fact that constants we are interested in are: */ - /* RUN_LVL=1, ... OLD_TIME=4; INIT_PROCESS=5, ... USER_PROCESS=8 */ - type = utmp_entry->ut_type - 1; - type /= 4; - - while ((lutmp = __getutent_unlocked()) != NULL) { - if (type == 0 && lutmp->ut_type == utmp_entry->ut_type) { - /* one of RUN_LVL, BOOT_TIME, NEW_TIME, OLD_TIME */ - return lutmp; + struct utmp *lutmp; + unsigned type; + + /* We use the fact that constants we are interested in are: */ + /* RUN_LVL=1, ... OLD_TIME=4; INIT_PROCESS=5, ... USER_PROCESS=8 */ + type = utmp_entry->ut_type - 1; + type /= 4; + + while ((lutmp = __getutent_unlocked()) != NULL) { + if (type == 0 && lutmp->ut_type == utmp_entry->ut_type) { + /* one of RUN_LVL, BOOT_TIME, NEW_TIME, OLD_TIME */ + return lutmp; + } + if (type == 1 + && strncmp(lutmp->ut_id, utmp_entry->ut_id, + sizeof(lutmp->ut_id)) == 0) { + /* INIT_PROCESS, LOGIN_PROCESS, USER_PROCESS, DEAD_PROCESS */ + return lutmp; + } } - if (type == 1 && strncmp(lutmp->ut_id, utmp_entry->ut_id, sizeof(lutmp->ut_id)) == 0) { - /* INIT_PROCESS, LOGIN_PROCESS, USER_PROCESS, DEAD_PROCESS */ - return lutmp; - } - } - return NULL; + return NULL; } #if defined __UCLIBC_HAS_THREADS__ struct utmp *getutid(const struct utmp *utmp_entry) { - struct utmp *ret; + struct utmp *ret; - __UCLIBC_MUTEX_LOCK(utmplock); - ret = __getutid_unlocked(utmp_entry); - __UCLIBC_MUTEX_UNLOCK(utmplock); - return ret; + __UCLIBC_MUTEX_LOCK(utmplock); + ret = __getutid_unlocked(utmp_entry); + __UCLIBC_MUTEX_UNLOCK(utmplock); + return ret; } #else strong_alias(__getutid_unlocked,getutid) @@ -145,59 +147,61 @@ libc_hidden_def(getutid) struct utmp *getutline(const struct utmp *utmp_entry) { - struct utmp *lutmp; - - __UCLIBC_MUTEX_LOCK(utmplock); - while ((lutmp = __getutent_unlocked()) != NULL) { - if (lutmp->ut_type == USER_PROCESS || lutmp->ut_type == LOGIN_PROCESS) { - if (strncmp(lutmp->ut_line, utmp_entry->ut_line, sizeof(lutmp->ut_line)) == 0) { - break; - } + struct utmp *lutmp; + + __UCLIBC_MUTEX_LOCK(utmplock); + while ((lutmp = __getutent_unlocked()) != NULL) { + if (lutmp->ut_type == USER_PROCESS || lutmp->ut_type == LOGIN_PROCESS) { + if (strncmp(lutmp->ut_line, utmp_entry->ut_line, + sizeof(lutmp->ut_line)) == 0) { + break; + } + } } - } - __UCLIBC_MUTEX_UNLOCK(utmplock); - return lutmp; + __UCLIBC_MUTEX_UNLOCK(utmplock); + return lutmp; } libc_hidden_def(getutline) struct utmp *pututline(const struct utmp *utmp_entry) { - __UCLIBC_MUTEX_LOCK(utmplock); - /* Ignore the return value. That way, if they've already positioned - the file pointer where they want it, everything will work out. */ - lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR); - - if (__getutid_unlocked(utmp_entry) != NULL) + __UCLIBC_MUTEX_LOCK(utmplock); + /* Ignore the return value. That way, if they've already positioned + the file pointer where they want it, everything will work out. */ lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR); - else - lseek(static_fd, (off_t) 0, SEEK_END); - if (write(static_fd, utmp_entry, sizeof(struct utmp)) != sizeof(struct utmp)) - utmp_entry = NULL; - __UCLIBC_MUTEX_UNLOCK(utmplock); - return (struct utmp *)utmp_entry; + if (__getutid_unlocked(utmp_entry) != NULL) + lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR); + else + lseek(static_fd, (off_t) 0, SEEK_END); + if (write(static_fd, utmp_entry, sizeof(struct utmp)) + != sizeof(struct utmp)) + utmp_entry = NULL; + + __UCLIBC_MUTEX_UNLOCK(utmplock); + return (struct utmp *)utmp_entry; } libc_hidden_def(pututline) int utmpname(const char *new_ut_name) { - __UCLIBC_MUTEX_LOCK(utmplock); - if (new_ut_name != NULL) { - if (static_ut_name != default_file_name) - free((char *)static_ut_name); - static_ut_name = strdup(new_ut_name); - if (static_ut_name == NULL) { - /* We should probably whine about out-of-memory - * errors here... Instead just reset to the default */ - static_ut_name = default_file_name; + __UCLIBC_MUTEX_LOCK(utmplock); + if (new_ut_name != NULL) { + if (static_ut_name != default_file_name) + free((char *)static_ut_name); + static_ut_name = strdup(new_ut_name); + if (static_ut_name == NULL) { + /* We should probably whine about out-of-memory + * errors here... Instead just reset to the default */ + static_ut_name = default_file_name; + } } - } - if (static_fd >= 0) { - close_not_cancel_no_status(static_fd); - static_fd = -1; - } - __UCLIBC_MUTEX_UNLOCK(utmplock); - return 0; /* or maybe return -(static_ut_name != new_ut_name)? */ + if (static_fd >= 0) { + close_not_cancel_no_status(static_fd); + static_fd = -1; + } + __UCLIBC_MUTEX_UNLOCK(utmplock); + return 0; /* or maybe return -(static_ut_name != new_ut_name)? */ } libc_hidden_def(utmpname) -- cgit v1.2.3 From c846358a61434e6cb9b1f73bc35df0e5404f52d2 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 24 Mar 2015 00:11:41 +0100 Subject: buildsys: fix IS_IN_lib* for .s Signed-off-by: Bernhard Reutner-Fischer --- Makerules | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makerules b/Makerules index a60338a87..fd6bb190d 100644 --- a/Makerules +++ b/Makerules @@ -29,7 +29,9 @@ objs: all_objs # apply unconditional per-directory flags define add_IS_IN_lib ifneq ($(strip $(2)),) -__add_IS_IN_lib := $(2) $(2:.o=.i) $(2:.os=.i) $(2:.oS=.i) +__add_IS_IN_lib := $(2) +__add_IS_IN_lib += $(2:.o=.i) $(2:.os=.i) $(2:.oS=.i) +__add_IS_IN_lib += $(2:.o=.s) $(2:.os=.s) $(2:.oS=.s) $$(__add_IS_IN_lib): CFLAGS-for-library-members:=$(CFLAGS-$(1)) -DIN_LIB=$(word 1,$(subst /, ,$(1))) endif endef -- cgit v1.2.3 From 272e4fa4d38440d5c01259fce7d74f8c0a9d300f Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 24 Mar 2015 00:11:44 +0100 Subject: libcrypt: Rename some internal macros to avoid clashes Signed-off-by: Bernhard Reutner-Fischer --- libcrypt/sha256.c | 18 +++++++++--------- libcrypt/sha512.c | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/libcrypt/sha256.c b/libcrypt/sha256.c index 6bc2d8b2b..3e12b5ce4 100644 --- a/libcrypt/sha256.c +++ b/libcrypt/sha256.c @@ -108,12 +108,12 @@ sha256_process_block (const void *buffer, size_t len, struct sha256_ctx *ctx) uint32_t h_save = h; /* Operators defined in FIPS 180-2:4.1.2. */ -#define Ch(x, y, z) ((x & y) ^ (~x & z)) -#define Maj(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) -#define S0(x) (CYCLIC (x, 2) ^ CYCLIC (x, 13) ^ CYCLIC (x, 22)) -#define S1(x) (CYCLIC (x, 6) ^ CYCLIC (x, 11) ^ CYCLIC (x, 25)) -#define R0(x) (CYCLIC (x, 7) ^ CYCLIC (x, 18) ^ (x >> 3)) -#define R1(x) (CYCLIC (x, 17) ^ CYCLIC (x, 19) ^ (x >> 10)) +#define _Ch(x, y, z) ((x & y) ^ (~x & z)) +#define _Maj(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) +#define _S0(x) (CYCLIC (x, 2) ^ CYCLIC (x, 13) ^ CYCLIC (x, 22)) +#define _S1(x) (CYCLIC (x, 6) ^ CYCLIC (x, 11) ^ CYCLIC (x, 25)) +#define _R0(x) (CYCLIC (x, 7) ^ CYCLIC (x, 18) ^ (x >> 3)) +#define _R1(x) (CYCLIC (x, 17) ^ CYCLIC (x, 19) ^ (x >> 10)) /* It is unfortunate that C does not provide an operator for cyclic rotation. Hope the C compiler is smart enough. */ @@ -126,13 +126,13 @@ sha256_process_block (const void *buffer, size_t len, struct sha256_ctx *ctx) ++words; } for (unsigned int t = 16; t < 64; ++t) - W[t] = R1 (W[t - 2]) + W[t - 7] + R0 (W[t - 15]) + W[t - 16]; + W[t] = _R1 (W[t - 2]) + W[t - 7] + _R0 (W[t - 15]) + W[t - 16]; /* The actual computation according to FIPS 180-2:6.2.2 step 3. */ for (unsigned int t = 0; t < 64; ++t) { - uint32_t T1 = h + S1 (e) + Ch (e, f, g) + K[t] + W[t]; - uint32_t T2 = S0 (a) + Maj (a, b, c); + uint32_t T1 = h + _S1 (e) + _Ch (e, f, g) + K[t] + W[t]; + uint32_t T2 = _S0 (a) + _Maj (a, b, c); h = g; g = f; f = e; diff --git a/libcrypt/sha512.c b/libcrypt/sha512.c index 079caee0a..b2e36a3b3 100644 --- a/libcrypt/sha512.c +++ b/libcrypt/sha512.c @@ -139,12 +139,12 @@ sha512_process_block (const void *buffer, size_t len, struct sha512_ctx *ctx) uint64_t h_save = h; /* Operators defined in FIPS 180-2:4.1.2. */ -#define Ch(x, y, z) ((x & y) ^ (~x & z)) -#define Maj(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) -#define S0(x) (CYCLIC (x, 28) ^ CYCLIC (x, 34) ^ CYCLIC (x, 39)) -#define S1(x) (CYCLIC (x, 14) ^ CYCLIC (x, 18) ^ CYCLIC (x, 41)) -#define R0(x) (CYCLIC (x, 1) ^ CYCLIC (x, 8) ^ (x >> 7)) -#define R1(x) (CYCLIC (x, 19) ^ CYCLIC (x, 61) ^ (x >> 6)) +#define _Ch(x, y, z) ((x & y) ^ (~x & z)) +#define _Maj(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) +#define _S0(x) (CYCLIC (x, 28) ^ CYCLIC (x, 34) ^ CYCLIC (x, 39)) +#define _S1(x) (CYCLIC (x, 14) ^ CYCLIC (x, 18) ^ CYCLIC (x, 41)) +#define _R0(x) (CYCLIC (x, 1) ^ CYCLIC (x, 8) ^ (x >> 7)) +#define _R1(x) (CYCLIC (x, 19) ^ CYCLIC (x, 61) ^ (x >> 6)) /* It is unfortunate that C does not provide an operator for cyclic rotation. Hope the C compiler is smart enough. */ @@ -157,13 +157,13 @@ sha512_process_block (const void *buffer, size_t len, struct sha512_ctx *ctx) ++words; } for (unsigned int t = 16; t < 80; ++t) - W[t] = R1 (W[t - 2]) + W[t - 7] + R0 (W[t - 15]) + W[t - 16]; + W[t] = _R1 (W[t - 2]) + W[t - 7] + _R0 (W[t - 15]) + W[t - 16]; /* The actual computation according to FIPS 180-2:6.3.2 step 3. */ for (unsigned int t = 0; t < 80; ++t) { - uint64_t T1 = h + S1 (e) + Ch (e, f, g) + K[t] + W[t]; - uint64_t T2 = S0 (a) + Maj (a, b, c); + uint64_t T1 = h + _S1 (e) + _Ch (e, f, g) + K[t] + W[t]; + uint64_t T2 = _S0 (a) + _Maj (a, b, c); h = g; g = f; f = e; -- cgit v1.2.3 From 730db44f0824f505a31822e250b9f04b9f8e7a1b Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 24 Mar 2015 00:11:47 +0100 Subject: libm: honor NO_LONG_DOUBLE in ldouble_wrappers Fixes SH build breakage due to attempts to define hidden defs for unavailable long double functions. Signed-off-by: Bernhard Reutner-Fischer --- extra/Configs/Config.in.arch | 2 +- ldso/ldso/sh/dl-syscalls.h | 2 +- libm/ldouble_wrappers.c | 15 +++++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/extra/Configs/Config.in.arch b/extra/Configs/Config.in.arch index 68e03bf9e..0dae84b06 100644 --- a/extra/Configs/Config.in.arch +++ b/extra/Configs/Config.in.arch @@ -191,7 +191,7 @@ config UCLIBC_HAS_FENV config UCLIBC_HAS_LONG_DOUBLE_MATH bool "Enable long double support" depends on DO_C99_MATH - depends on TARGET_i386 || TARGET_m68k || TARGET_sparc || TARGET_x86_64 || TARGET_powerpc || TARGET_sh || TARGET_microblaze || TARGET_xtensa + depends on TARGET_aarch64 || TARGET_alpha || TARGET_i386 || TARGET_ia64 || TARGET_m68k || TARGET_powerpc || TARGET_s390 || TARGET_sparc || TARGET_tile || TARGET_x86_64 default y help If you want the uClibc math library to contain the full set of C99 diff --git a/ldso/ldso/sh/dl-syscalls.h b/ldso/ldso/sh/dl-syscalls.h index f9f13c7fa..b99a9b5a0 100644 --- a/ldso/ldso/sh/dl-syscalls.h +++ b/ldso/ldso/sh/dl-syscalls.h @@ -1,4 +1,4 @@ -#if __GNUC_PREREQ (4, 1) +#if __GNUC_PREREQ (4, 1) && !__GNUC_PREREQ (4, 9) #warning !!! gcc 4.1 and later have problems with __always_inline so redefined as inline # ifdef __always_inline # undef __always_inline diff --git a/libm/ldouble_wrappers.c b/libm/ldouble_wrappers.c index b4215cbf3..840293fe6 100644 --- a/libm/ldouble_wrappers.c +++ b/libm/ldouble_wrappers.c @@ -16,27 +16,28 @@ #include "math.h" #include -#define WRAPPER1(func) \ +#if !defined __NO_LONG_DOUBLE_MATH +# define WRAPPER1(func) \ long double func##l(long double x) \ { \ return (long double) func((double) x); \ } -#define WRAPPER2(func) \ +# define WRAPPER2(func) \ long double func##l(long double x, long double y) \ { \ return (long double) func((double) x, (double) y); \ } -#define int_WRAPPER1(func) \ +# define int_WRAPPER1(func) \ int func##l(long double x) \ { \ return func((double) x); \ } -#define long_WRAPPER1(func) \ +# define long_WRAPPER1(func) \ long func##l(long double x) \ { \ return func((double) x); \ } -#define long_long_WRAPPER1(func) \ +# define long_long_WRAPPER1(func) \ long long func##l(long double x) \ { \ return func((double) x); \ @@ -447,4 +448,6 @@ int_WRAPPER1(__isinf) libm_hidden_def(__isinfl) # endif -#endif +#endif /* __DO_C99_MATH__ */ + +#endif /* __NO_LONG_DOUBLE_MATH */ -- cgit v1.2.3 From 40effcf4c1e9a2fb9169d9189bdc9b1c888f9345 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 24 Mar 2015 00:11:49 +0100 Subject: mips: switch float_t to float Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/mips/bits/mathdef.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libc/sysdeps/linux/mips/bits/mathdef.h b/libc/sysdeps/linux/mips/bits/mathdef.h index 1c636a199..6afe20d8a 100644 --- a/libc/sysdeps/linux/mips/bits/mathdef.h +++ b/libc/sysdeps/linux/mips/bits/mathdef.h @@ -25,10 +25,9 @@ #if defined __USE_ISOC99 && defined _MATH_H && !defined _MATH_H_MATHDEF # define _MATH_H_MATHDEF 1 -/* Normally, there is no long double type and the `float' and `double' - expressions are evaluated as `double'. */ -typedef double float_t; /* `float' expressions are evaluated as - `double'. */ +/* MIPS has both `float' and `double' arithmetic. */ +typedef float float_t; /* `float' expressions are evaluated as + `float'. */ typedef double double_t; /* `double' expressions are evaluated as `double'. */ -- cgit v1.2.3 From 2b33716c08cc506e57115e34b5fe11d8d5477398 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Wed, 25 Mar 2015 23:59:37 +0100 Subject: utmp: Remove unneeded alias Signed-off-by: Bernhard Reutner-Fischer --- libc/misc/utmp/utent.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c index 4d71f5e29..a258cb46d 100644 --- a/libc/misc/utmp/utent.c +++ b/libc/misc/utmp/utent.c @@ -93,7 +93,7 @@ strong_alias(__getutent_unlocked,getutent) #endif libc_hidden_def(getutent) -static void __endutent(void) +void endutent(void) { __UCLIBC_MUTEX_LOCK(utmplock); if (static_fd >= 0) @@ -101,7 +101,6 @@ static void __endutent(void) static_fd = -1; __UCLIBC_MUTEX_UNLOCK(utmplock); } -strong_alias(__endutent,endutent) libc_hidden_def(endutent) /* This function must be called with the LOCK held */ -- cgit v1.2.3 From 6ff9c31abc14f207265ab214370982ecb3bfe428 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Wed, 25 Mar 2015 23:59:45 +0100 Subject: utmp: favour POSIX utmpx over SVID utmp Note: _PATH_UTMPX == _PATH_UTMP and the utmp struct is identical to the utmpx struct so this only changes the external API entrypoints and NOT the underlying data source. This saves about 500b (~1300b from previously ~1950) while at it. Signed-off-by: Bernhard Reutner-Fischer --- extra/Configs/Config.in | 24 +++---- include/internal/utmp.h | 92 +++++++++++++++++++++++++++ include/pty.h | 1 + include/utmp.h | 10 +-- libc/misc/utmp/Makefile.in | 4 +- libc/misc/utmp/utent.c | 121 +++++++++++++++++++++--------------- libc/misc/utmp/utxent.c | 108 -------------------------------- libc/misc/utmp/wtent.c | 50 --------------- libc/sysdeps/linux/sh/bits/atomic.h | 12 +++- libutil/forkpty.c | 3 - libutil/login.c | 6 +- libutil/login_tty.c | 1 - libutil/logout.c | 6 +- libutil/logwtmp.c | 21 +------ libutil/openpty.c | 1 - test/misc/Makefile.in | 4 ++ 16 files changed, 200 insertions(+), 264 deletions(-) create mode 100644 include/internal/utmp.h delete mode 100644 libc/misc/utmp/utxent.c delete mode 100644 libc/misc/utmp/wtent.c diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in index 7546e96ea..1ef13667f 100644 --- a/extra/Configs/Config.in +++ b/extra/Configs/Config.in @@ -701,23 +701,23 @@ config COMPAT_ATEXIT else you will be missing atexit() until you rebuild all apps. config UCLIBC_HAS_UTMPX - bool "utmpx based support for tracking login/logouts to/from the system" - depends on UCLIBC_HAS_UTMP # TODO, remove this, it's backward - help - Answer y to enable support for accessing user accounting database. - It can be used to track all login/logout to the system. + bool "utmpx based support for tracking login/logouts to/from the system" + help + Answer y to enable support for accessing user accounting database. + It can be used to track all login/logout to the system. config UCLIBC_HAS_UTMP - bool "utmp support (XPG2, SVr4 compat)" - help - Answer y to enable legacy SVID support for accessing - user accounting database: + bool "utmp support (XPG2 compat, SVr4 compat)" + #depends on UCLIBC_HAS_UTMPX # for educational purposes.. + help + Answer y to enable legacy SVID support for accessing + user accounting database: getutent(), getutid(), getutline(), pututline(), setutent(), endutent(), utmpname() in utmp.h - It can be used to track all login/logout to the system. + It can be used to track all login/logout to the system. - If unsure, just answer N and use utmpx.h and corresponding - POSIX functions. + If unsure, answer N and use corresponding POSIX functions + from utmpx.h config UCLIBC_SUSV2_LEGACY bool "Enable SuSv2 LEGACY functions" diff --git a/include/internal/utmp.h b/include/internal/utmp.h new file mode 100644 index 000000000..49f96b4d8 --- /dev/null +++ b/include/internal/utmp.h @@ -0,0 +1,92 @@ +/* vi: set sw=4 ts=4: */ +/* + * internal helper for utmp and utmpx handling + * + * Copyright (C) 2015 by Bernhard Reutner-Fischer + * + * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. + */ +#ifndef __INTERNAL_UTMP_H +#define __INTERNAL_UTMP_H + +#include +#include + +/* Note: _PATH_UTMPX == _PATH_UTMP */ + +#if (defined __UCLIBC_HAS_UTMPX__ && defined __UCLIBC_HAS_UTMP__) \ + || !defined __UCLIBC_HAS_UTMP__ +/* implement the X and alias the non-X */ +# define __set_unlocked __setutxent_unlocked +# define set setutxent +# define __get_unlocked __getutxent_unlocked +# define get getutxent +# define end endutxent +# define __getid_unlocked __getutxid_unlocked +# define getid getutxid +# define getline getutxline +# define putline pututxline +# define name utmpxname +# define updw updwtmpx +# define UT utmpx +# ifndef __DEFAULT_PATH_UTMP +# define __DEFAULT_PATH_UTMP _PATH_UTMPX +# endif +# if defined __UCLIBC_HAS_UTMP__ +# define other(n,a) strong_alias_untyped(n,a) +# else +# define other(n,a) /* nothing */ +# endif +#elif defined __UCLIBC_HAS_UTMP__ +# define __set_unlocked __setutent_unlocked +# define set setutent +# define __get_unlocked __getutent_unlocked +# define get getutent +# define end endutent +# define __getid_unlocked __getutid_unlocked +# define getid getutid +# define getline getutline +# define putline pututline +# define name utmpname +# define updw updwtmp +# define UT utmp +# ifndef __DEFAULT_PATH_UTMP +# define __DEFAULT_PATH_UTMP _PATH_UTMP +# endif +# define other(n,a) /* nothing */ +#else +#error You are supposed to either have UTMP or UTMPX or both here +#endif + +/* not used in libc_hidden_proto(setutxent) */ +/* not used in libc_hidden_proto(endutxent) */ +/* not used in libc_hidden_proto(getutxent) */ +/* not used in libc_hidden_proto(getutxid) */ +/* not used in libc_hidden_proto(getutxline) */ +/* not used in libc_hidden_proto(pututxline) */ +/* not used in libc_hidden_proto(utmpxname) */ +/* not used in libc_hidden_proto(updwtmpx) */ + +/* not used in libc_hidden_proto(setutent) */ +/* not used in libc_hidden_proto(endutent) */ +/* not used in libc_hidden_proto(getutent) */ +/* not used in libc_hidden_proto(getutid) */ +/* not used in libc_hidden_proto(getutline) */ +/* not used in libc_hidden_proto(pututline) */ +/* not used in libc_hidden_proto(utmpname) */ +/* not used in libc_hidden_proto(updwtmp) */ + +#ifdef IS_IN_libutil +# if (defined __UCLIBC_HAS_UTMPX__ && defined __UCLIBC_HAS_UTMP__) \ + || !defined __UCLIBC_HAS_UTMP__ + /* monkey-patch to use the POSIX interface */ +# define setutent setutxent +# define getutline getutxline +# define pututline pututxline +# define endutent endutxent +# define updwtmp updwtmpx +# endif +#endif /* IS_IN_libutil */ + +#endif /* __INTERNAL_UTMP_H */ + diff --git a/include/pty.h b/include/pty.h index 26c3011c6..f23a260ae 100644 --- a/include/pty.h +++ b/include/pty.h @@ -32,6 +32,7 @@ __BEGIN_DECLS ends in AMASTER and ASLAVE. */ extern int openpty (int *__amaster, int *__aslave, char *__name, struct termios *__termp, struct winsize *__winp) __THROW; +libutil_hidden_proto(openpty) /* Create child process and establish the slave pseudo terminal as the child's controlling terminal. */ diff --git a/include/utmp.h b/include/utmp.h index 754f76781..8ecbb54e7 100644 --- a/include/utmp.h +++ b/include/utmp.h @@ -40,7 +40,7 @@ __BEGIN_DECLS /* Make FD be the controlling terminal, stdin, stdout, and stderr; then close FD. Returns 0 on success, nonzero on error. */ extern int login_tty (int __fd) __THROW; - +libutil_hidden_proto(login_tty) /* Write the given entry into utmp and wtmp. */ extern void login (const struct utmp *__entry) __THROW; @@ -56,37 +56,29 @@ extern void logwtmp (const char *__ut_line, const char *__ut_name, /* Append entry UTMP to the wtmp-like file WTMP_FILE. */ extern void updwtmp (const char *__wtmp_file, const struct utmp *__utmp) __THROW; -libc_hidden_proto(updwtmp) /* Change name of the utmp file to be examined. */ extern int utmpname (const char *__file) __THROW; -libc_hidden_proto(utmpname) /* Read next entry from a utmp-like file. */ extern struct utmp *getutent (void) __THROW; -libc_hidden_proto(getutent) /* Reset the input stream to the beginning of the file. */ extern void setutent (void) __THROW; -libc_hidden_proto(setutent) /* Close the current open file. */ extern void endutent (void) __THROW; -libc_hidden_proto(endutent) /* Search forward from the current point in the utmp file until the next entry with a ut_type matching ID->ut_type. */ extern struct utmp *getutid (const struct utmp *__id) __THROW; -libc_hidden_proto(getutid) /* Search forward from the current point in the utmp file until the next entry with a ut_line matching LINE->ut_line. */ extern struct utmp *getutline (const struct utmp *__line) __THROW; -libc_hidden_proto(getutline) /* Write out entry pointed to by UTMP_PTR into the utmp file. */ extern struct utmp *pututline (const struct utmp *__utmp_ptr) __THROW; -libc_hidden_proto(pututline) #if 0 /* def __USE_MISC */ diff --git a/libc/misc/utmp/Makefile.in b/libc/misc/utmp/Makefile.in index 715341c85..6c54ade96 100644 --- a/libc/misc/utmp/Makefile.in +++ b/libc/misc/utmp/Makefile.in @@ -8,9 +8,7 @@ subdirs += libc/misc/utmp CSRC-y := -CSRC-$(if $(findstring y,$(UCLIBC_HAS_UTMP)$(UCLIBC_HAS_UTMPX)),y) += wtent.c -CSRC-$(UCLIBC_HAS_UTMP) += utent.c -CSRC-$(UCLIBC_HAS_UTMPX) += utxent.c +CSRC-$(if $(findstring y,$(UCLIBC_HAS_UTMP)$(UCLIBC_HAS_UTMPX)),y) += utent.c MISC_UTMP_DIR := $(top_srcdir)libc/misc/utmp MISC_UTMP_OUT := $(top_builddir)libc/misc/utmp diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c index a258cb46d..3671bb05c 100644 --- a/libc/misc/utmp/utent.c +++ b/libc/misc/utmp/utent.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include "internal/utmp.h" #include #include @@ -27,17 +27,17 @@ __UCLIBC_MUTEX_STATIC(utmplock, PTHREAD_MUTEX_INITIALIZER); /* Some global crap */ static int static_fd = -1; -static struct utmp static_utmp; -static const char default_file_name[] = _PATH_UTMP; -static const char *static_ut_name = default_file_name; +static struct UT static_utmp; +static const char default_file[] = __DEFAULT_PATH_UTMP; +static const char *current_file = default_file; /* This function must be called with the LOCK held */ -static void __setutent_unlocked(void) +static void __set_unlocked(void) { if (static_fd < 0) { - static_fd = open_not_cancel_2(static_ut_name, O_RDWR | O_CLOEXEC); + static_fd = open_not_cancel_2(current_file, O_RDWR | O_CLOEXEC); if (static_fd < 0) { - static_fd = open_not_cancel_2(static_ut_name, O_RDONLY | O_CLOEXEC); + static_fd = open_not_cancel_2(current_file, O_RDONLY | O_CLOEXEC); if (static_fd < 0) { return; /* static_fd remains < 0 */ } @@ -51,22 +51,23 @@ static void __setutent_unlocked(void) lseek(static_fd, 0, SEEK_SET); } #if defined __UCLIBC_HAS_THREADS__ -void setutent(void) +void set(void) { __UCLIBC_MUTEX_LOCK(utmplock); - __setutent_unlocked(); + __set_unlocked(); __UCLIBC_MUTEX_UNLOCK(utmplock); } #else -strong_alias(__setutent_unlocked,setutent) +strong_alias(__set_unlocked,set) #endif -libc_hidden_def(setutent) +/* not used in libc_hidden_def(set) */ +other(setutxent,setutent) /* This function must be called with the LOCK held */ -static struct utmp *__getutent_unlocked(void) +static struct UT *__get_unlocked(void) { if (static_fd < 0) { - __setutent_unlocked(); + __set_unlocked(); if (static_fd < 0) return NULL; } @@ -79,21 +80,22 @@ static struct utmp *__getutent_unlocked(void) return NULL; } #if defined __UCLIBC_HAS_THREADS__ -struct utmp *getutent(void) +struct UT *get(void) { - struct utmp *ret; + struct UT *ret; __UCLIBC_MUTEX_LOCK(utmplock); - ret = __getutent_unlocked(); + ret = __get_unlocked(); __UCLIBC_MUTEX_UNLOCK(utmplock); return ret; } #else -strong_alias(__getutent_unlocked,getutent) +strong_alias(__get_unlocked,get) #endif -libc_hidden_def(getutent) +/* not used in libc_hidden_def(get) */ +other(getutxent,getutent) -void endutent(void) +void end(void) { __UCLIBC_MUTEX_LOCK(utmplock); if (static_fd >= 0) @@ -101,12 +103,13 @@ void endutent(void) static_fd = -1; __UCLIBC_MUTEX_UNLOCK(utmplock); } -libc_hidden_def(endutent) +/* not used in libc_hidden_def(end) */ +other(endutxent,endutent) /* This function must be called with the LOCK held */ -static struct utmp *__getutid_unlocked(const struct utmp *utmp_entry) +static struct UT *__getid_unlocked(const struct UT *utmp_entry) { - struct utmp *lutmp; + struct UT *lutmp; unsigned type; /* We use the fact that constants we are interested in are: */ @@ -114,7 +117,7 @@ static struct utmp *__getutid_unlocked(const struct utmp *utmp_entry) type = utmp_entry->ut_type - 1; type /= 4; - while ((lutmp = __getutent_unlocked()) != NULL) { + while ((lutmp = __get_unlocked()) != NULL) { if (type == 0 && lutmp->ut_type == utmp_entry->ut_type) { /* one of RUN_LVL, BOOT_TIME, NEW_TIME, OLD_TIME */ return lutmp; @@ -130,26 +133,27 @@ static struct utmp *__getutid_unlocked(const struct utmp *utmp_entry) return NULL; } #if defined __UCLIBC_HAS_THREADS__ -struct utmp *getutid(const struct utmp *utmp_entry) +struct UT *getid(const struct UT *utmp_entry) { - struct utmp *ret; + struct UT *ret; __UCLIBC_MUTEX_LOCK(utmplock); - ret = __getutid_unlocked(utmp_entry); + ret = __getid_unlocked(utmp_entry); __UCLIBC_MUTEX_UNLOCK(utmplock); return ret; } #else -strong_alias(__getutid_unlocked,getutid) +strong_alias(__getid_unlocked,getid) #endif -libc_hidden_def(getutid) +/* not used in libc_hidden_def(getid) */ +other(getutxid,getutid) -struct utmp *getutline(const struct utmp *utmp_entry) +struct UT *getline(const struct UT *utmp_entry) { - struct utmp *lutmp; + struct UT *lutmp; __UCLIBC_MUTEX_LOCK(utmplock); - while ((lutmp = __getutent_unlocked()) != NULL) { + while ((lutmp = __get_unlocked()) != NULL) { if (lutmp->ut_type == USER_PROCESS || lutmp->ut_type == LOGIN_PROCESS) { if (strncmp(lutmp->ut_line, utmp_entry->ut_line, sizeof(lutmp->ut_line)) == 0) { @@ -160,39 +164,41 @@ struct utmp *getutline(const struct utmp *utmp_entry) __UCLIBC_MUTEX_UNLOCK(utmplock); return lutmp; } -libc_hidden_def(getutline) +/* libc_hidden_def(getline) */ +other(getutxline,getutline) -struct utmp *pututline(const struct utmp *utmp_entry) +struct UT *putline(const struct UT *utmp_entry) { __UCLIBC_MUTEX_LOCK(utmplock); /* Ignore the return value. That way, if they've already positioned the file pointer where they want it, everything will work out. */ - lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR); + lseek(static_fd, (off_t) - sizeof(struct UT), SEEK_CUR); - if (__getutid_unlocked(utmp_entry) != NULL) - lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR); + if (__getid_unlocked(utmp_entry) != NULL) + lseek(static_fd, (off_t) - sizeof(struct UT), SEEK_CUR); else lseek(static_fd, (off_t) 0, SEEK_END); - if (write(static_fd, utmp_entry, sizeof(struct utmp)) - != sizeof(struct utmp)) + if (write(static_fd, utmp_entry, sizeof(struct UT)) + != sizeof(struct UT)) utmp_entry = NULL; __UCLIBC_MUTEX_UNLOCK(utmplock); - return (struct utmp *)utmp_entry; + return (struct UT *)utmp_entry; } -libc_hidden_def(pututline) +/* not used in libc_hidden_def(putline) */ +other(pututxline,pututline) -int utmpname(const char *new_ut_name) +int name(const char *new_file) { __UCLIBC_MUTEX_LOCK(utmplock); - if (new_ut_name != NULL) { - if (static_ut_name != default_file_name) - free((char *)static_ut_name); - static_ut_name = strdup(new_ut_name); - if (static_ut_name == NULL) { + if (new_file != NULL) { + if (current_file != default_file) + free((char *)current_file); + current_file = strdup(new_file); + if (current_file == NULL) { /* We should probably whine about out-of-memory * errors here... Instead just reset to the default */ - static_ut_name = default_file_name; + current_file = default_file; } } @@ -201,6 +207,23 @@ int utmpname(const char *new_ut_name) static_fd = -1; } __UCLIBC_MUTEX_UNLOCK(utmplock); - return 0; /* or maybe return -(static_ut_name != new_ut_name)? */ + return 0; /* or maybe return -(current_file != new_file)? */ } -libc_hidden_def(utmpname) +/* not used in libc_hidden_def(name) */ +other(utmpxname,utmpname) + +void updw(const char *wtmp_file, const struct UT *lutmp) +{ + int fd; + + fd = open_not_cancel_2(wtmp_file, O_APPEND | O_WRONLY); + if (fd >= 0) { + if (lockf(fd, F_LOCK, 0) == 0) { + write_not_cancel(fd, lutmp, sizeof(struct UT)); + lockf(fd, F_ULOCK, 0); + close_not_cancel_no_status(fd); + } + } +} +/* not used in libc_hidden_def(updw) */ +other(updwtmpx,updwtmp) diff --git a/libc/misc/utmp/utxent.c b/libc/misc/utmp/utxent.c deleted file mode 100644 index c32e4da49..000000000 --- a/libc/misc/utmp/utxent.c +++ /dev/null @@ -1,108 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * utexent.c : Support for accessing user accounting database. - * Copyright (C) 2010 STMicroelectronics Ltd. - * - * Author: Salvatore Cro - * - * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. - * - */ - -#include -#include -#include -#include - -void setutxent(void) -{ - setutent (); -} - -void endutxent(void) -{ - endutent (); -} - -struct utmpx *getutxent(void) -{ - return (struct utmpx *) getutent (); -} - -struct utmpx *getutxid(const struct utmpx *utmp_entry) -{ - return (struct utmpx *) getutid ((const struct utmp *) utmp_entry); -} - -struct utmpx *getutxline(const struct utmpx *utmp_entry) -{ - return (struct utmpx *) getutline ((const struct utmp *) utmp_entry); -} - -struct utmpx *pututxline (const struct utmpx *utmp_entry) -{ - return (struct utmpx *) pututline ((const struct utmp *) utmp_entry); -} - -int utmpxname (const char *new_ut_name) -{ - return utmpname (new_ut_name); -} - -void updwtmpx (const char *wtmpx_file, const struct utmpx *utmpx) -{ - updwtmp (wtmpx_file, (const struct utmp *) utmpx); -} - -/* Copy the information in UTMPX to UTMP. */ -void getutmp (const struct utmpx *utmpx, struct utmp *utmp) -{ -#if _HAVE_UT_TYPE - 0 - utmp->ut_type = utmpx->ut_type; -#endif -#if _HAVE_UT_PID - 0 - utmp->ut_pid = utmpx->ut_pid; -#endif - memcpy (utmp->ut_line, utmpx->ut_line, sizeof (utmp->ut_line)); - memcpy (utmp->ut_user, utmpx->ut_user, sizeof (utmp->ut_user)); -#if _HAVE_UT_ID - 0 - memcpy (utmp->ut_id, utmpx->ut_id, sizeof (utmp->ut_id)); -#endif -#if _HAVE_UT_HOST - 0 - memcpy (utmp->ut_host, utmpx->ut_host, sizeof (utmp->ut_host)); -#endif -#if _HAVE_UT_TV - 0 - utmp->ut_tv.tv_sec = utmpx->ut_tv.tv_sec; - utmp->ut_tv.tv_usec = utmpx->ut_tv.tv_usec; -#else - utmp->ut_time = utmpx->ut_time; -#endif -} - -/* Copy the information in UTMP to UTMPX. */ -void getutmpx (const struct utmp *utmp, struct utmpx *utmpx) -{ - memset (utmpx, 0, sizeof (struct utmpx)); - -#if _HAVE_UT_TYPE - 0 - utmpx->ut_type = utmp->ut_type; -#endif -#if _HAVE_UT_PID - 0 - utmpx->ut_pid = utmp->ut_pid; -#endif - memcpy (utmpx->ut_line, utmp->ut_line, sizeof (utmp->ut_line)); - memcpy (utmpx->ut_user, utmp->ut_user, sizeof (utmp->ut_user)); -#if _HAVE_UT_ID - 0 - memcpy (utmpx->ut_id, utmp->ut_id, sizeof (utmp->ut_id)); -#endif -#if _HAVE_UT_HOST - 0 - memcpy (utmpx->ut_host, utmp->ut_host, sizeof (utmp->ut_host)); -#endif -#if _HAVE_UT_TV - 0 - utmpx->ut_tv.tv_sec = utmp->ut_tv.tv_sec; - utmpx->ut_tv.tv_usec = utmp->ut_tv.tv_usec; -#else - utmpx->ut_time = utmp->ut_time; -#endif -} - diff --git a/libc/misc/utmp/wtent.c b/libc/misc/utmp/wtent.c deleted file mode 100644 index 30939ea43..000000000 --- a/libc/misc/utmp/wtent.c +++ /dev/null @@ -1,50 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * Copyright (C) 2000-2006 Erik Andersen - * - * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. - */ - -/* wtmp support rubbish (i.e. complete crap) */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#if 0 -/* This is enabled in uClibc/libutil/logwtmp.c */ -void logwtmp (const char *line, const char *name, const char *host) -{ - struct utmp lutmp; - memset(&lutmp, 0, sizeof(lutmp)); - - lutmp.ut_type = (name && *name) ? USER_PROCESS : DEAD_PROCESS; - lutmp.ut_pid = getpid(); - strncpy(lutmp.ut_line, line, sizeof(lutmp.ut_line)-1); - strncpy(lutmp.ut_name, name, sizeof(lutmp.ut_name)-1); - strncpy(lutmp.ut_host, host, sizeof(lutmp.ut_host)-1); - gettimeofday(&(lutmp.ut_tv), NULL); - - updwtmp(_PATH_WTMP, &lutmp); -} -#endif - -void updwtmp(const char *wtmp_file, const struct utmp *lutmp) -{ - int fd; - - fd = open_not_cancel_2(wtmp_file, O_APPEND | O_WRONLY); - if (fd >= 0) { - if (lockf(fd, F_LOCK, 0) == 0) { - write_not_cancel(fd, lutmp, sizeof(struct utmp)); - lockf(fd, F_ULOCK, 0); - close_not_cancel_no_status(fd); - } - } -} -libc_hidden_def(updwtmp) diff --git a/libc/sysdeps/linux/sh/bits/atomic.h b/libc/sysdeps/linux/sh/bits/atomic.h index 745c85c1d..18ae9ea77 100644 --- a/libc/sysdeps/linux/sh/bits/atomic.h +++ b/libc/sysdeps/linux/sh/bits/atomic.h @@ -68,6 +68,12 @@ typedef uintmax_t uatomic_max_t; r1: saved stack pointer */ +#if __GNUC_PREREQ (4, 7) +# define rNOSP "u" +#else +# define rNOSP "r" +#endif + /* Avoid having lots of different versions of compare and exchange, by having this one complicated version. Parameters: bwl: b, w or l for 8, 16 and 32 bit versions. @@ -94,7 +100,7 @@ typedef uintmax_t uatomic_max_t; movt %0\n\ .endif\n" \ : "=&r" (__arch_result) \ - : "r" (mem), "r" (newval), "r" (oldval) \ + : rNOSP (mem), rNOSP (newval), rNOSP (oldval) \ : "r0", "r1", "t", "memory"); \ __arch_result; }) @@ -150,7 +156,7 @@ typedef uintmax_t uatomic_max_t; mov." #bwl " %1,@%2\n\ 1: mov r1,r15" \ : "=&r" (old), "=&r"(new) \ - : "r" (mem), "r" (value) \ + : rNOSP (mem), rNOSP (value) \ : "r0", "r1", "memory"); \ }) @@ -194,7 +200,7 @@ typedef uintmax_t uatomic_max_t; mov." #bwl " %0,@%1\n\ 1: mov r1,r15" \ : "=&r" (__new) \ - : "r" (mem), "r" (__value) \ + : rNOSP (mem), rNOSP (__value) \ : "r0", "r1", "memory"); \ __new; \ }) diff --git a/libutil/forkpty.c b/libutil/forkpty.c index ec490f053..24643330c 100644 --- a/libutil/forkpty.c +++ b/libutil/forkpty.c @@ -22,9 +22,6 @@ #include #include -libutil_hidden_proto(openpty) -libutil_hidden_proto(login_tty) - int forkpty (int *amaster, char *name, struct termios *termp, struct winsize *winp) { diff --git a/libutil/login.c b/libutil/login.c index 4007e4c7e..971997d4a 100644 --- a/libutil/login.c +++ b/libutil/login.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include "internal/utmp.h" /* Write the given entry into utmp and wtmp. * Note: the match in utmp is done against ut_id field, @@ -11,7 +11,7 @@ */ void login(const struct utmp *entry) { - struct utmp copy; + struct UT copy; char tty_name[sizeof(copy.ut_line) + 6]; int fd; @@ -20,7 +20,7 @@ void login(const struct utmp *entry) // (if there is such a field) with the value USER_PROCESS, // and fills the field ut->ut_pid (if there is such a field) // with the process ID of the calling process. - copy = *entry; + copy = *((const struct UT *)(entry)); #if _HAVE_UT_TYPE - 0 copy.ut_type = USER_PROCESS; #endif diff --git a/libutil/login_tty.c b/libutil/login_tty.c index 3979adcec..366585834 100644 --- a/libutil/login_tty.c +++ b/libutil/login_tty.c @@ -36,7 +36,6 @@ #include #include -libutil_hidden_proto(login_tty) int login_tty(int fd) { (void) setsid(); diff --git a/libutil/logout.c b/libutil/logout.c index 45804552d..0181e23aa 100644 --- a/libutil/logout.c +++ b/libutil/logout.c @@ -18,14 +18,14 @@ #include #include -#include #include +#include "internal/utmp.h" int logout (const char *line) { - struct utmp tmp; - struct utmp *ut; + struct UT tmp; + struct UT *ut; int result = 0; /* if (utmpname (_PATH_UTMP) == -1) return 0; - why? diff --git a/libutil/logwtmp.c b/libutil/logwtmp.c index 6a53b5ff1..99b772fc4 100644 --- a/libutil/logwtmp.c +++ b/libutil/logwtmp.c @@ -9,13 +9,13 @@ #include #include #include -#include #include #include +#include "internal/utmp.h" void logwtmp(const char *line, const char *name, const char *host) { - struct utmp lutmp; + struct UT lutmp; memset(&lutmp, 0, sizeof(lutmp)); lutmp.ut_type = (name && *name) ? USER_PROCESS : DEAD_PROCESS; @@ -36,20 +36,3 @@ void logwtmp(const char *line, const char *name, const char *host) updwtmp(_PATH_WTMP, &lutmp); } - -#if 0 -/* This is enabled in uClibc/libc/misc/utmp/wtent.c */ -void updwtmp(const char *wtmp_file, const struct utmp *lutmp) -{ - int fd; - - fd = open(wtmp_file, O_APPEND | O_WRONLY); - if (fd >= 0) { - if (lockf(fd, F_LOCK, 0) == 0) { - write(fd, lutmp, sizeof(*lutmp)); - lockf(fd, F_ULOCK, 0); - close(fd); - } - } -} -#endif diff --git a/libutil/openpty.c b/libutil/openpty.c index bd8b8d9a4..848dc8d38 100644 --- a/libutil/openpty.c +++ b/libutil/openpty.c @@ -84,7 +84,6 @@ pts_name (int fd, char **pts, size_t buf_len) /* Create pseudo tty master slave pair and set terminal attributes according to TERMP and WINP. Return handles for both ends in AMASTER and ASLAVE, and return the name of the slave end in NAME. */ -libutil_hidden_proto(openpty) int openpty (int *amaster, int *aslave, char *name, struct termios *termp, struct winsize *winp) diff --git a/test/misc/Makefile.in b/test/misc/Makefile.in index 2fb9652fd..09f631fe3 100644 --- a/test/misc/Makefile.in +++ b/test/misc/Makefile.in @@ -20,6 +20,10 @@ ifeq ($(UCLIBC_HAS_UTMPX),) TESTS_DISABLED += tst-utmpx endif +ifeq ($(UCLIBC_HAS_UTMP),) +TESTS_DISABLED += tst-utmp +endif + DODIFF_dirent := 1 DODIFF_dirent64 := 1 DODIFF_tst-statfs := 1 -- cgit v1.2.3 From 6f363f69221a6b40ef0f88631cd8d675465eb63d Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Wed, 25 Mar 2015 23:59:49 +0100 Subject: include: Expand malloc-family comments Signed-off-by: Bernhard Reutner-Fischer --- include/stdlib.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/stdlib.h b/include/stdlib.h index 2065dfa2d..809256d0c 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -486,11 +486,11 @@ extern int lcong48_r (unsigned short int __param[7], __BEGIN_NAMESPACE_STD /* Allocate SIZE bytes of memory. */ extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur; -/* We want the malloc symbols overridable at runtime - * libc_hidden_proto(malloc) */ +/* We want the malloc symbol overridable at runtime, do not hide it! */ /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */ extern void *calloc (size_t __nmemb, size_t __size) __THROW __attribute_malloc__ __wur; +/* We want the calloc symbol overridable at runtime, do not hide it! */ __END_NAMESPACE_STD #endif @@ -503,8 +503,10 @@ __BEGIN_NAMESPACE_STD between objects pointed by the old and new pointers. */ extern void *realloc (void *__ptr, size_t __size) __THROW __wur; +/* We want the realloc symbol overridable at runtime, do not hide it! */ /* Free a block allocated by `malloc', `realloc' or `calloc'. */ extern void free (void *__ptr) __THROW; +/* We want the free symbol overridable at runtime, do not hide it! */ __END_NAMESPACE_STD #if 0 /*def __USE_MISC*/ -- cgit v1.2.3 From 9e552e6a2d836698834d2bf887dbf1806172729f Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Wed, 25 Mar 2015 23:59:52 +0100 Subject: test: tweaks Fix arc4random exclusion for real. Silence warning about missing prototype for external helper-function in tst-scandir Signed-off-by: Bernhard Reutner-Fischer --- test/misc/tst-scandir.c | 2 +- test/stdlib/Makefile.in | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/test/misc/tst-scandir.c b/test/misc/tst-scandir.c index df62a40d4..e1c72e3c9 100644 --- a/test/misc/tst-scandir.c +++ b/test/misc/tst-scandir.c @@ -3,7 +3,7 @@ #include /* perror() */ #include -int skip_all(const struct dirent *dirbuf) +static int skip_all(const struct dirent *dirbuf) { errno = EBADF; return 0; diff --git a/test/stdlib/Makefile.in b/test/stdlib/Makefile.in index df3440a39..e1cbccfca 100644 --- a/test/stdlib/Makefile.in +++ b/test/stdlib/Makefile.in @@ -11,8 +11,9 @@ GLIBC_TESTS_DISABLED := ifeq ($(UCLIBC_HAS_PTY),) TESTS_DISABLED += ptytest endif + ifeq ($(UCLIBC_HAS_ARC4RANDOM),) TESTS_DISABLED += testarc4random else -GLIBC_TESTS_DISABLED += testarc4random +GLIBC_TESTS_DISABLED += testarc4random_glibc endif -- cgit v1.2.3 From 2c8a7766681b704e710f51c0817534e3f9a952d1 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Thu, 26 Mar 2015 00:02:58 +0100 Subject: ldso: mark _dl_exit as noreturn Otherwise gcc might not understand that oom() ended control-flow and might emit an (untaken) reference to abort() in _dl_update_slotinfo() on e.g. SH4 which breaks linking ld-uClibc.so. Arguably -ffreestanding should prevent GCC from emitting this '.global abort' but alas, it does not, which is another bug.. Also mark the function cold to further lower the incoming frequency and branch probability. Signed-off-by: Bernhard Reutner-Fischer --- ldso/include/dl-syscall.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ldso/include/dl-syscall.h b/ldso/include/dl-syscall.h index 675b93ae8..e556f7b56 100644 --- a/ldso/include/dl-syscall.h +++ b/ldso/include/dl-syscall.h @@ -52,7 +52,15 @@ extern int _dl_errno; dynamic linking at all, so we cannot return any error codes. We just punt if there is an error. */ #define __NR__dl_exit __NR_exit -static __always_inline _syscall1(void, _dl_exit, int, status) +static __always_inline attribute_noreturn __cold void _dl_exit(int status) +{ + INLINE_SYSCALL(_dl_exit, 1, status); +#if defined __GNUC__ + __builtin_unreachable(); /* shut up warning: 'noreturn' function does return*/ +#else + while (1); +#endif +} #define __NR__dl_close __NR_close static __always_inline _syscall1(int, _dl_close, int, fd) -- cgit v1.2.3 From fc673e14203e1c9aea353d99ff89a17d46b2ad93 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Thu, 26 Mar 2015 00:03:05 +0100 Subject: SH: add 't' to syscall clobber list Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/sh/bits/syscalls.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/sysdeps/linux/sh/bits/syscalls.h b/libc/sysdeps/linux/sh/bits/syscalls.h index b308276c5..efd423ed3 100644 --- a/libc/sysdeps/linux/sh/bits/syscalls.h +++ b/libc/sysdeps/linux/sh/bits/syscalls.h @@ -122,7 +122,7 @@ __asm__ __volatile__ (SYSCALL_INST_STR##nr SYSCALL_INST_PAD \ : "=z" (resultvar) \ : "r" (r3) ASMFMT_##nr \ - : "memory" \ + : "memory", "t" \ ); \ (int) resultvar; \ }) \ -- cgit v1.2.3 From 8836d184d4da65e8959210bc7b768e628b0273fb Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Thu, 26 Mar 2015 00:03:09 +0100 Subject: NPTL: SH: silence warning Signed-off-by: Bernhard Reutner-Fischer --- libpthread/nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libpthread/nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.h b/libpthread/nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.h index 0b635d361..a9652bbb1 100644 --- a/libpthread/nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.h +++ b/libpthread/nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.h @@ -358,7 +358,7 @@ extern int __lll_unlock_wake (int *__futex, int private) attribute_hidden; register unsigned long __r5 __asm__ ("r5") \ = __lll_private_flag (FUTEX_WAIT, private); \ register unsigned long __r6 __asm__ ("r6") = (unsigned long) (val); \ - register unsigned long __r7 __asm__ ("r7") = (timeout); \ + register unsigned long __r7 __asm__ ("r7") = (unsigned long) (timeout); \ __asm__ __volatile__ (SYSCALL_WITH_INST_PAD \ : "=z" (__status) \ : "r" (__r3), "r" (__r4), "r" (__r5), \ -- cgit v1.2.3 From cf80a7fc2db30364ac98be40483e599c2c243e87 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Thu, 26 Mar 2015 00:50:17 +0100 Subject: utmp: always have at least utmpx Signed-off-by: Bernhard Reutner-Fischer --- extra/Configs/Config.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in index 1ef13667f..1fd686052 100644 --- a/extra/Configs/Config.in +++ b/extra/Configs/Config.in @@ -708,7 +708,7 @@ config UCLIBC_HAS_UTMPX config UCLIBC_HAS_UTMP bool "utmp support (XPG2 compat, SVr4 compat)" - #depends on UCLIBC_HAS_UTMPX # for educational purposes.. + depends on UCLIBC_HAS_UTMPX help Answer y to enable legacy SVID support for accessing user accounting database: -- cgit v1.2.3 From 560f416794403be952e850756d7e8b23e8fa92ac Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Thu, 26 Mar 2015 22:51:16 +0100 Subject: test: Add SIMULATOR_uclibc and SIMULATOR_glibc where SIMULATOR_glibc is an optional simulator to run host binaries and SIMULATOR_uclibc is an optional simulator to run target (uClibc) binaries. Signed-off-by: Bernhard Reutner-Fischer --- test/README | 3 +++ test/Test.mak | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/test/README b/test/README index 28225b063..723ce6e43 100644 --- a/test/README +++ b/test/README @@ -29,6 +29,9 @@ The following make variables may help you in testing: So, to just run the uClibc tests, try this: make check UCLIBC_ONLY=1 +You can pass the following 2 environment variables to "make run": + - make run SIMULATOR_uclibc=qemu-sh4 SIMULATOR_glibc=qemu-x86_64 + If you need to test just a subset of all test, delete subdirectories you do not need. diff --git a/test/Test.mak b/test/Test.mak index ee43a0fcd..a56a20165 100644 --- a/test/Test.mak +++ b/test/Test.mak @@ -69,7 +69,7 @@ endef define exec_test $(showtest) $(Q)\ - $(WRAPPER) $(WRAPPER_$(tst_src_name)) \ + $(SIMULATOR) $(WRAPPER) $(WRAPPER_$(tst_src_name)) \ ./$(binary_name) $(OPTS) $(OPTS_$(tst_src_name)) > "$(binary_name).out" 2>&1 ; \ ret=$$? ; \ expected_ret="$(RET_$(tst_src_name))" ; \ @@ -85,6 +85,9 @@ endef test check all: run run: $(RUN_TARGETS) + +$(addsuffix .exe,$(U_TARGETS)): SIMULATOR:=$(SIMULATOR_uclibc) +$(addsuffix .exe,$(G_TARGETS)): SIMULATOR:=$(SIMULATOR_glibc) $(RUN_TARGETS): $(exec_test) $(diff_test) -- cgit v1.2.3 From cc8d7d062e2db0a1ed3973e6af38cd1938ba74d7 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Thu, 26 Mar 2015 23:12:38 +0100 Subject: include: update atomic.h from glibc Signed-off-by: Bernhard Reutner-Fischer --- include/atomic.h | 235 +++++++++++++++++- test/.gitignore | 2 + test/silly/Makefile.in | 3 + test/silly/hello.c | 2 +- test/silly/tst-atomic-long.c | 27 ++ test/silly/tst-atomic.c | 573 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 837 insertions(+), 5 deletions(-) create mode 100644 test/silly/tst-atomic-long.c create mode 100644 test/silly/tst-atomic.c diff --git a/include/atomic.h b/include/atomic.h index 307704cba..3680d8714 100644 --- a/include/atomic.h +++ b/include/atomic.h @@ -1,5 +1,5 @@ /* Internal macros for atomic operations for GNU C Library. - Copyright (C) 2002-2006, 2009 Free Software Foundation, Inc. + Copyright (C) 2002-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 2002. @@ -32,7 +32,7 @@ the multi-thread case. The interfaces have the prefix "catomic_". - - support functions like barriers. They also have the preifx + - support functions like barriers. They also have the prefix "atomic_". Architectures must provide a few lowlevel macros (the compare @@ -198,8 +198,12 @@ /* Add VALUE to *MEM and return the old value of *MEM. */ -#ifndef atomic_exchange_and_add -# define atomic_exchange_and_add(mem, value) \ +#ifndef atomic_exchange_and_add_acq +# ifdef atomic_exchange_and_add +# define atomic_exchange_and_add_acq(mem, value) \ + atomic_exchange_and_add (mem, value) +# else +# define atomic_exchange_and_add_acq(mem, value) \ ({ __typeof (*(mem)) __atg6_oldval; \ __typeof (mem) __atg6_memp = (mem); \ __typeof (*(mem)) __atg6_value = (value); \ @@ -213,8 +217,18 @@ __atg6_oldval), 0)); \ \ __atg6_oldval; }) +# endif #endif +#ifndef atomic_exchange_and_add_rel +# define atomic_exchange_and_add_rel(mem, value) \ + atomic_exchange_and_add_acq(mem, value) +#endif + +#ifndef atomic_exchange_and_add +# define atomic_exchange_and_add(mem, value) \ + atomic_exchange_and_add_acq(mem, value) +#endif #ifndef catomic_exchange_and_add # define catomic_exchange_and_add(mem, value) \ @@ -528,6 +542,219 @@ ({ __typeof (x) __x; __asm__ ("" : "=r" (__x) : "0" (x)); __x; }) #endif +/* This is equal to 1 iff the architecture supports 64b atomic operations. */ +#define __HAVE_64B_ATOMICS 0 /* TODO: not yet used - Add these to arch bits! */ +#ifndef __HAVE_64B_ATOMICS +#error Unable to determine if 64-bit atomics are present. +#endif + +/* The following functions are a subset of the atomic operations provided by + C11. Usually, a function named atomic_OP_MO(args) is equivalent to C11's + atomic_OP_explicit(args, memory_order_MO); exceptions noted below. */ + +/* Each arch can request to use compiler built-ins for C11 atomics. If it + does, all atomics will be based on these. */ +#if 0 /* not yet used USE_ATOMIC_COMPILER_BUILTINS */ + +/* We require 32b atomic operations; some archs also support 64b atomic + operations. */ +void __atomic_link_error (void); +# if __HAVE_64B_ATOMICS == 1 +# define __atomic_check_size(mem) \ + if ((sizeof (*mem) != 4) && (sizeof (*mem) != 8)) \ + __atomic_link_error (); +# else +# define __atomic_check_size(mem) \ + if (sizeof (*mem) != 4) \ + __atomic_link_error (); +# endif + +# define atomic_thread_fence_acquire() \ + __atomic_thread_fence (__ATOMIC_ACQUIRE) +# define atomic_thread_fence_release() \ + __atomic_thread_fence (__ATOMIC_RELEASE) +# define atomic_thread_fence_seq_cst() \ + __atomic_thread_fence (__ATOMIC_SEQ_CST) + +# define atomic_load_relaxed(mem) \ + ({ __atomic_check_size((mem)); __atomic_load_n ((mem), __ATOMIC_RELAXED); }) +# define atomic_load_acquire(mem) \ + ({ __atomic_check_size((mem)); __atomic_load_n ((mem), __ATOMIC_ACQUIRE); }) + +# define atomic_store_relaxed(mem, val) \ + do { \ + __atomic_check_size((mem)); \ + __atomic_store_n ((mem), (val), __ATOMIC_RELAXED); \ + } while (0) +# define atomic_store_release(mem, val) \ + do { \ + __atomic_check_size((mem)); \ + __atomic_store_n ((mem), (val), __ATOMIC_RELEASE); \ + } while (0) + +/* On failure, this CAS has memory_order_relaxed semantics. */ +# define atomic_compare_exchange_weak_relaxed(mem, expected, desired) \ + ({ __atomic_check_size((mem)); \ + __atomic_compare_exchange_n ((mem), (expected), (desired), 1, \ + __ATOMIC_RELAXED, __ATOMIC_RELAXED); }) +# define atomic_compare_exchange_weak_acquire(mem, expected, desired) \ + ({ __atomic_check_size((mem)); \ + __atomic_compare_exchange_n ((mem), (expected), (desired), 1, \ + __ATOMIC_ACQUIRE, __ATOMIC_RELAXED); }) +# define atomic_compare_exchange_weak_release(mem, expected, desired) \ + ({ __atomic_check_size((mem)); \ + __atomic_compare_exchange_n ((mem), (expected), (desired), 1, \ + __ATOMIC_RELEASE, __ATOMIC_RELAXED); }) + +# define atomic_exchange_acquire(mem, desired) \ + ({ __atomic_check_size((mem)); \ + __atomic_exchange_n ((mem), (desired), __ATOMIC_ACQUIRE); }) +# define atomic_exchange_release(mem, desired) \ + ({ __atomic_check_size((mem)); \ + __atomic_exchange_n ((mem), (desired), __ATOMIC_RELEASE); }) + +# define atomic_fetch_add_relaxed(mem, operand) \ + ({ __atomic_check_size((mem)); \ + __atomic_fetch_add ((mem), (operand), __ATOMIC_RELAXED); }) +# define atomic_fetch_add_acquire(mem, operand) \ + ({ __atomic_check_size((mem)); \ + __atomic_fetch_add ((mem), (operand), __ATOMIC_ACQUIRE); }) +# define atomic_fetch_add_release(mem, operand) \ + ({ __atomic_check_size((mem)); \ + __atomic_fetch_add ((mem), (operand), __ATOMIC_RELEASE); }) +# define atomic_fetch_add_acq_rel(mem, operand) \ + ({ __atomic_check_size((mem)); \ + __atomic_fetch_add ((mem), (operand), __ATOMIC_ACQ_REL); }) + +# define atomic_fetch_and_acquire(mem, operand) \ + ({ __atomic_check_size((mem)); \ + __atomic_fetch_and ((mem), (operand), __ATOMIC_ACQUIRE); }) + +# define atomic_fetch_or_relaxed(mem, operand) \ + ({ __atomic_check_size((mem)); \ + __atomic_fetch_or ((mem), (operand), __ATOMIC_RELAXED); }) +# define atomic_fetch_or_acquire(mem, operand) \ + ({ __atomic_check_size((mem)); \ + __atomic_fetch_or ((mem), (operand), __ATOMIC_ACQUIRE); }) + +#else /* !USE_ATOMIC_COMPILER_BUILTINS */ + +/* By default, we assume that read, write, and full barriers are equivalent + to acquire, release, and seq_cst barriers. Archs for which this does not + hold have to provide custom definitions of the fences. */ +# ifndef atomic_thread_fence_acquire +# define atomic_thread_fence_acquire() atomic_read_barrier () +# endif +# ifndef atomic_thread_fence_release +# define atomic_thread_fence_release() atomic_write_barrier () +# endif +# ifndef atomic_thread_fence_seq_cst +# define atomic_thread_fence_seq_cst() atomic_full_barrier () +# endif + +# ifndef atomic_load_relaxed +# define atomic_load_relaxed(mem) \ + ({ __typeof (*(mem)) __atg100_val; \ + __asm__ ("" : "=r" (__atg100_val) : "0" (*(mem))); \ + __atg100_val; }) +# endif +# ifndef atomic_load_acquire +# define atomic_load_acquire(mem) \ + ({ __typeof (*(mem)) __atg101_val = atomic_load_relaxed (mem); \ + atomic_thread_fence_acquire (); \ + __atg101_val; }) +# endif + +# ifndef atomic_store_relaxed +/* XXX Use inline asm here? */ +# define atomic_store_relaxed(mem, val) do { *(mem) = (val); } while (0) +# endif +# ifndef atomic_store_release +# define atomic_store_release(mem, val) \ + do { \ + atomic_thread_fence_release (); \ + atomic_store_relaxed ((mem), (val)); \ + } while (0) +# endif + +/* On failure, this CAS has memory_order_relaxed semantics. */ +/* XXX This potentially has one branch more than necessary, but archs + currently do not define a CAS that returns both the previous value and + the success flag. */ +# ifndef atomic_compare_exchange_weak_acquire +# define atomic_compare_exchange_weak_acquire(mem, expected, desired) \ + ({ __typeof (*(expected)) __atg102_expected = *(expected); \ + *(expected) = \ + atomic_compare_and_exchange_val_acq ((mem), (desired), *(expected)); \ + *(expected) == __atg102_expected; }) +# endif +# ifndef atomic_compare_exchange_weak_relaxed +/* XXX Fall back to CAS with acquire MO because archs do not define a weaker + CAS. */ +# define atomic_compare_exchange_weak_relaxed(mem, expected, desired) \ + atomic_compare_exchange_weak_acquire ((mem), (expected), (desired)) +# endif +# ifndef atomic_compare_exchange_weak_release +# define atomic_compare_exchange_weak_release(mem, expected, desired) \ + ({ __typeof (*(expected)) __atg103_expected = *(expected); \ + *(expected) = \ + atomic_compare_and_exchange_val_rel ((mem), (desired), *(expected)); \ + *(expected) == __atg103_expected; }) +# endif + +# ifndef atomic_exchange_acquire +# define atomic_exchange_acquire(mem, val) \ + atomic_exchange_acq ((mem), (val)) +# endif +# ifndef atomic_exchange_release +# define atomic_exchange_release(mem, val) \ + atomic_exchange_rel ((mem), (val)) +# endif + +# ifndef atomic_fetch_add_acquire +# define atomic_fetch_add_acquire(mem, operand) \ + atomic_exchange_and_add_acq ((mem), (operand)) +# endif +# ifndef atomic_fetch_add_relaxed +/* XXX Fall back to acquire MO because the MO semantics of + atomic_exchange_and_add are not documented; the generic version falls back + to atomic_exchange_and_add_acq if atomic_exchange_and_add is not defined, + and vice versa. */ +# define atomic_fetch_add_relaxed(mem, operand) \ + atomic_fetch_add_acquire ((mem), (operand)) +# endif +# ifndef atomic_fetch_add_release +# define atomic_fetch_add_release(mem, operand) \ + atomic_exchange_and_add_rel ((mem), (operand)) +# endif +# ifndef atomic_fetch_add_acq_rel +# define atomic_fetch_add_acq_rel(mem, operand) \ + ({ atomic_thread_fence_release (); \ + atomic_exchange_and_add_acq ((mem), (operand)); }) +# endif + +/* XXX The default for atomic_and_val has acquire semantics, but this is not + documented. */ +# ifndef atomic_fetch_and_acquire +# define atomic_fetch_and_acquire(mem, operand) \ + atomic_and_val ((mem), (operand)) +# endif + +/* XXX The default for atomic_or_val has acquire semantics, but this is not + documented. */ +# ifndef atomic_fetch_or_acquire +# define atomic_fetch_or_acquire(mem, operand) \ + atomic_or_val ((mem), (operand)) +# endif +/* XXX Fall back to acquire MO because archs do not define a weaker + atomic_or_val. */ +# ifndef atomic_fetch_or_relaxed +# define atomic_fetch_or_relaxed(mem, operand) \ + atomic_fetch_or_acquire ((mem), (operand)) +# endif + +#endif /* !USE_ATOMIC_COMPILER_BUILTINS */ + #ifndef atomic_delay # define atomic_delay() do { /* nothing */ } while (0) diff --git a/test/.gitignore b/test/.gitignore index beb50958d..0d19285e9 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -263,6 +263,8 @@ signal/tst-sigset signal/tst-sigsimple silly/hello silly/tiny +silly/tst-atomic +silly/tst-atomic-long stat/memcmp-stat stat/stat stat/stat64 diff --git a/test/silly/Makefile.in b/test/silly/Makefile.in index bb08e0db9..9bb4032b5 100644 --- a/test/silly/Makefile.in +++ b/test/silly/Makefile.in @@ -3,3 +3,6 @@ RET_hello := 42 RET_tiny := 42 + +# missing internal headers, disable these +GLIBC_TESTS_DISABLED := tst-atomic_glibc tst-atomic-long_glibc diff --git a/test/silly/hello.c b/test/silly/hello.c index 4aba926e6..d330597ab 100644 --- a/test/silly/hello.c +++ b/test/silly/hello.c @@ -1,4 +1,4 @@ -#include +#include #include int main(void) diff --git a/test/silly/tst-atomic-long.c b/test/silly/tst-atomic-long.c new file mode 100644 index 000000000..d13fb074c --- /dev/null +++ b/test/silly/tst-atomic-long.c @@ -0,0 +1,27 @@ +/* Tests for atomic.h macros. + Copyright (C) 2003-2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Jakub Jelinek , 2003. + + 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, see + . */ + +#include + +#define atomic_t long +#if __WORDSIZE == 64 +# define TEST_ATOMIC64 1 +#endif + +#include "tst-atomic.c" diff --git a/test/silly/tst-atomic.c b/test/silly/tst-atomic.c new file mode 100644 index 000000000..fc773b231 --- /dev/null +++ b/test/silly/tst-atomic.c @@ -0,0 +1,573 @@ +/* Tests for atomic.h macros. + Copyright (C) 2003-2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Jakub Jelinek , 2003. + + 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, see + . */ + +#include +#include + +#ifndef atomic_t +# define atomic_t int +#endif + +#define CHK2(f,a1,a2,rv,new_mem) \ + retval = f(&mem, a1, a2); \ + if (retval != rv) { \ + printf("%s(mem, %lu, %lu): retval %lu != expected %lu\n", \ + #f, a1, a2, retval, rv); \ + ret = 1; \ + } \ + if (mem != new_mem) { \ + printf("%s(mem, %lu, %lu): mem %lu != expected %lu\n", \ + #f, a1, a2, mem, new_mem); \ + ret = 1; \ + } +#define CHK1(f,a1,rv,new_mem) \ + retval = f(&mem, a1); \ + if (retval != rv) { \ + printf("%s(mem, %lu): retval %lu != expected %lu\n", \ + #f, a1, retval, rv); \ + ret = 1; \ + } \ + if (mem != new_mem) { \ + printf("%s(mem, %lu): mem %lu != expected %lu\n", \ + #f, a1, mem, new_mem); \ + ret = 1; \ + } +#define CHK0(f,rv,new_mem) \ + retval = f(&mem); \ + if (retval != rv) { \ + printf("%s(mem): retval %lu != expected %lu\n", \ + #f, retval, rv); \ + ret = 1; \ + } \ + if (mem != new_mem) { \ + printf("%s(mem): mem %lu != expected %lu\n", \ + #f, mem, new_mem); \ + ret = 1; \ + } + +/* Test various atomic.h macros. */ +static int +do_test (void) +{ + atomic_t mem, expected, retval; + int ret = 0; + +#ifdef atomic_compare_and_exchange_val_acq + mem = 24; + CHK2(atomic_compare_and_exchange_val_acq, 35, 24, 24, 35); + mem = 12; + CHK2(atomic_compare_and_exchange_val_acq, 10, 15, 12, 12); + mem = -15; + CHK2(atomic_compare_and_exchange_val_acq, -56, -15, -15, -56); + mem = -1; + CHK2(atomic_compare_and_exchange_val_acq, 17, 0, -1, -1); +#endif + + mem = 24; + CHK2(atomic_compare_and_exchange_bool_acq, 35, 24, 0, 35); + mem = 12; + CHK2(atomic_compare_and_exchange_bool_acq, 10, 15, 1, 12); + mem = -15; + CHK2(atomic_compare_and_exchange_bool_acq, -56, -15, 0, -56); + mem = -1; + CHK2(atomic_compare_and_exchange_bool_acq, 17, 0, 1, -1); + + mem = 64; + CHK1(atomic_exchange_acq, 31, 64, 31); + mem = 2; + CHK1(atomic_exchange_and_add, 11, 2, 13); + mem = 2; + CHK1(atomic_exchange_and_add_acq, 11, 2, 13); + mem = 2; + CHK1(atomic_exchange_and_add_rel, 11, 2, 13); + + mem = -21; + atomic_add (&mem, 22); + if (mem != 1) + { + printf ("atomic_add(mem, 22): mem %lu != expected 1\n", mem); + ret = 1; + } + + mem = -1; + atomic_increment (&mem); + if (mem != 0) + { + printf ("atomic_increment(mem): mem %lu != expected 0\n", mem); + ret = 1; + } + + mem = 2; + if ((retval = atomic_increment_val (&mem)) != 3) + { + printf ("atomic_increment_val(mem): retval %lu != expected 3\n", retval); + ret = 1; + } + + mem = 0; + CHK0(atomic_increment_and_test, 0, 1); + mem = 35; + CHK0(atomic_increment_and_test, 0, 36); + mem = -1; + CHK0(atomic_increment_and_test, 1, 0); + mem = 17; + atomic_decrement (&mem); + if (mem != 16) + { + printf ("atomic_increment(mem): mem %lu != expected 16\n", mem); + ret = 1; + } + + if ((retval = atomic_decrement_val (&mem)) != 15) + { + printf ("atomic_decrement_val(mem): retval %lu != expected 15\n", retval); + ret = 1; + } + + mem = 0; + CHK0(atomic_decrement_and_test, 0, -1); + + mem = 15; + CHK0(atomic_decrement_and_test, 0, 14); + mem = 1; + CHK0(atomic_decrement_and_test, 1, 0); + mem = 1; + if (atomic_decrement_if_positive (&mem) != 1 + || mem != 0) + { + puts ("atomic_decrement_if_positive test 1 failed"); + ret = 1; + } + + mem = 0; + if (atomic_decrement_if_positive (&mem) != 0 + || mem != 0) + { + puts ("atomic_decrement_if_positive test 2 failed"); + ret = 1; + } + + mem = -1; + if (atomic_decrement_if_positive (&mem) != -1 + || mem != -1) + { + puts ("atomic_decrement_if_positive test 3 failed"); + ret = 1; + } + + mem = -12; + if (! atomic_add_negative (&mem, 10) + || mem != -2) + { + puts ("atomic_add_negative test 1 failed"); + ret = 1; + } + + mem = 0; + if (atomic_add_negative (&mem, 100) + || mem != 100) + { + puts ("atomic_add_negative test 2 failed"); + ret = 1; + } + + mem = 15; + if (atomic_add_negative (&mem, -10) + || mem != 5) + { + puts ("atomic_add_negative test 3 failed"); + ret = 1; + } + + mem = -12; + if (atomic_add_negative (&mem, 14) + || mem != 2) + { + puts ("atomic_add_negative test 4 failed"); + ret = 1; + } + + mem = 0; + if (! atomic_add_negative (&mem, -1) + || mem != -1) + { + puts ("atomic_add_negative test 5 failed"); + ret = 1; + } + + mem = -31; + if (atomic_add_negative (&mem, 31) + || mem != 0) + { + puts ("atomic_add_negative test 6 failed"); + ret = 1; + } + + mem = -34; + if (atomic_add_zero (&mem, 31) + || mem != -3) + { + puts ("atomic_add_zero test 1 failed"); + ret = 1; + } + + mem = -36; + if (! atomic_add_zero (&mem, 36) + || mem != 0) + { + puts ("atomic_add_zero test 2 failed"); + ret = 1; + } + + mem = 113; + if (atomic_add_zero (&mem, -13) + || mem != 100) + { + puts ("atomic_add_zero test 3 failed"); + ret = 1; + } + + mem = -18; + if (atomic_add_zero (&mem, 20) + || mem != 2) + { + puts ("atomic_add_zero test 4 failed"); + ret = 1; + } + + mem = 10; + if (atomic_add_zero (&mem, -20) + || mem != -10) + { + puts ("atomic_add_zero test 5 failed"); + ret = 1; + } + + mem = 10; + if (! atomic_add_zero (&mem, -10) + || mem != 0) + { + puts ("atomic_add_zero test 6 failed"); + ret = 1; + } + + mem = 0; + atomic_bit_set (&mem, 1); + if (mem != 2) + { + puts ("atomic_bit_set test 1 failed"); + ret = 1; + } + + mem = 8; + atomic_bit_set (&mem, 3); + if (mem != 8) + { + puts ("atomic_bit_set test 2 failed"); + ret = 1; + } + +#ifdef TEST_ATOMIC64 + mem = 16; + atomic_bit_set (&mem, 35); + if (mem != 0x800000010LL) + { + puts ("atomic_bit_set test 3 failed"); + ret = 1; + } +#endif + + mem = 0; + if (atomic_bit_test_set (&mem, 1) + || mem != 2) + { + puts ("atomic_bit_test_set test 1 failed"); + ret = 1; + } + + mem = 8; + if (! atomic_bit_test_set (&mem, 3) + || mem != 8) + { + puts ("atomic_bit_test_set test 2 failed"); + ret = 1; + } + +#ifdef TEST_ATOMIC64 + mem = 16; + if (atomic_bit_test_set (&mem, 35) + || mem != 0x800000010LL) + { + puts ("atomic_bit_test_set test 3 failed"); + ret = 1; + } + + mem = 0x100000000LL; + if (! atomic_bit_test_set (&mem, 32) + || mem != 0x100000000LL) + { + puts ("atomic_bit_test_set test 4 failed"); + ret = 1; + } +#endif + +#ifdef catomic_compare_and_exchange_val_acq + mem = 24; + if (catomic_compare_and_exchange_val_acq (&mem, 35, 24) != 24 + || mem != 35) + { + puts ("catomic_compare_and_exchange_val_acq test 1 failed"); + ret = 1; + } + + mem = 12; + if (catomic_compare_and_exchange_val_acq (&mem, 10, 15) != 12 + || mem != 12) + { + puts ("catomic_compare_and_exchange_val_acq test 2 failed"); + ret = 1; + } + + mem = -15; + if (catomic_compare_and_exchange_val_acq (&mem, -56, -15) != -15 + || mem != -56) + { + puts ("catomic_compare_and_exchange_val_acq test 3 failed"); + ret = 1; + } + + mem = -1; + if (catomic_compare_and_exchange_val_acq (&mem, 17, 0) != -1 + || mem != -1) + { + puts ("catomic_compare_and_exchange_val_acq test 4 failed"); + ret = 1; + } +#endif + + mem = 24; + if (catomic_compare_and_exchange_bool_acq (&mem, 35, 24) + || mem != 35) + { + puts ("catomic_compare_and_exchange_bool_acq test 1 failed"); + ret = 1; + } + + mem = 12; + if (! catomic_compare_and_exchange_bool_acq (&mem, 10, 15) + || mem != 12) + { + puts ("catomic_compare_and_exchange_bool_acq test 2 failed"); + ret = 1; + } + + mem = -15; + if (catomic_compare_and_exchange_bool_acq (&mem, -56, -15) + || mem != -56) + { + puts ("catomic_compare_and_exchange_bool_acq test 3 failed"); + ret = 1; + } + + mem = -1; + if (! catomic_compare_and_exchange_bool_acq (&mem, 17, 0) + || mem != -1) + { + puts ("catomic_compare_and_exchange_bool_acq test 4 failed"); + ret = 1; + } + + mem = 2; + if (catomic_exchange_and_add (&mem, 11) != 2 + || mem != 13) + { + puts ("catomic_exchange_and_add test failed"); + ret = 1; + } + + mem = -21; + catomic_add (&mem, 22); + if (mem != 1) + { + puts ("catomic_add test failed"); + ret = 1; + } + + mem = -1; + catomic_increment (&mem); + if (mem != 0) + { + puts ("catomic_increment test failed"); + ret = 1; + } + + mem = 2; + if (catomic_increment_val (&mem) != 3) + { + puts ("catomic_increment_val test failed"); + ret = 1; + } + + mem = 17; + catomic_decrement (&mem); + if (mem != 16) + { + puts ("catomic_decrement test failed"); + ret = 1; + } + + if (catomic_decrement_val (&mem) != 15) + { + puts ("catomic_decrement_val test failed"); + ret = 1; + } + + /* Tests for C11-like atomics. */ + mem = 11; + if (atomic_load_relaxed (&mem) != 11 || atomic_load_acquire (&mem) != 11) + { + puts ("atomic_load_{relaxed,acquire} test failed"); + ret = 1; + } + + atomic_store_relaxed (&mem, 12); + if (mem != 12) + { + puts ("atomic_store_relaxed test failed"); + ret = 1; + } + atomic_store_release (&mem, 13); + if (mem != 13) + { + puts ("atomic_store_release test failed"); + ret = 1; + } + + mem = 14; + expected = 14; + if (!atomic_compare_exchange_weak_relaxed (&mem, &expected, 25) + || mem != 25 || expected != 14) + { + puts ("atomic_compare_exchange_weak_relaxed test 1 failed"); + ret = 1; + } + if (atomic_compare_exchange_weak_relaxed (&mem, &expected, 14) + || mem != 25 || expected != 25) + { + puts ("atomic_compare_exchange_weak_relaxed test 2 failed"); + ret = 1; + } + mem = 14; + expected = 14; + if (!atomic_compare_exchange_weak_acquire (&mem, &expected, 25) + || mem != 25 || expected != 14) + { + puts ("atomic_compare_exchange_weak_acquire test 1 failed"); + ret = 1; + } + if (atomic_compare_exchange_weak_acquire (&mem, &expected, 14) + || mem != 25 || expected != 25) + { + puts ("atomic_compare_exchange_weak_acquire test 2 failed"); + ret = 1; + } + mem = 14; + expected = 14; + if (!atomic_compare_exchange_weak_release (&mem, &expected, 25) + || mem != 25 || expected != 14) + { + puts ("atomic_compare_exchange_weak_release test 1 failed"); + ret = 1; + } + if (atomic_compare_exchange_weak_release (&mem, &expected, 14) + || mem != 25 || expected != 25) + { + puts ("atomic_compare_exchange_weak_release test 2 failed"); + ret = 1; + } + + mem = 23; + if (atomic_exchange_acquire (&mem, 42) != 23 || mem != 42) + { + puts ("atomic_exchange_acquire test failed"); + ret = 1; + } + mem = 23; + if (atomic_exchange_release (&mem, 42) != 23 || mem != 42) + { + puts ("atomic_exchange_release test failed"); + ret = 1; + } + + mem = 23; + if (atomic_fetch_add_relaxed (&mem, 1) != 23 || mem != 24) + { + puts ("atomic_fetch_add_relaxed test failed"); + ret = 1; + } + mem = 23; + if (atomic_fetch_add_acquire (&mem, 1) != 23 || mem != 24) + { + puts ("atomic_fetch_add_acquire test failed"); + ret = 1; + } + mem = 23; + if (atomic_fetch_add_release (&mem, 1) != 23 || mem != 24) + { + puts ("atomic_fetch_add_release test failed"); + ret = 1; + } + mem = 23; + if (atomic_fetch_add_acq_rel (&mem, 1) != 23 || mem != 24) + { + puts ("atomic_fetch_add_acq_rel test failed"); + ret = 1; + } + + mem = 3; + if (atomic_fetch_and_acquire (&mem, 2) != 3 || mem != 2) + { + puts ("atomic_fetch_and_acquire test failed"); + ret = 1; + } + + mem = 4; + if (atomic_fetch_or_relaxed (&mem, 2) != 4 || mem != 6) + { + puts ("atomic_fetch_or_relaxed test failed"); + ret = 1; + } + mem = 4; + if (atomic_fetch_or_acquire (&mem, 2) != 4 || mem != 6) + { + puts ("atomic_fetch_or_acquire test failed"); + ret = 1; + } + + /* This is a single-threaded test, so we can't test the effects of the + fences. */ + atomic_thread_fence_acquire (); + atomic_thread_fence_release (); + atomic_thread_fence_seq_cst (); + + return ret; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" -- cgit v1.2.3 From 8fde02feb2f8a36934308012d89fa6614967b2dc Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Thu, 26 Mar 2015 14:25:34 +0530 Subject: Add support for R_ARC_NONE relocations. The R_ARC_NONE relocation is generated when --gc-sections, used by the compile time linker, removes some sections. This is completely normal, and we can see that all other targets (based on random sampling) have support for R_*_NONE relocations (named for each target). Handling R_ARC_NONE involves doing nothing with it, which is nice and easy. Signed-off-by: Andrew Burgess Signed-off-by: Vineet Gupta Signed-off-by: Bernhard Reutner-Fischer --- ldso/ldso/arc/elfinterp.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ldso/ldso/arc/elfinterp.c b/ldso/ldso/arc/elfinterp.c index 7c31d3ac7..2f0cf7f66 100644 --- a/ldso/ldso/arc/elfinterp.c +++ b/ldso/ldso/arc/elfinterp.c @@ -144,6 +144,8 @@ _dl_do_reloc(struct elf_resolve *tpnt, struct r_scope_elem *scope, #endif switch (reloc_type) { + case R_ARC_NONE: + break; case R_ARC_32: *reloc_addr += symbol_addr + rpnt->r_addend; break; @@ -202,6 +204,8 @@ _dl_do_lazy_reloc(struct elf_resolve *tpnt, struct r_scope_elem *scope, #endif switch (reloc_type) { + case R_ARC_NONE: + break; case R_ARC_JMP_SLOT: *reloc_addr += tpnt->loadaddr; break; -- cgit v1.2.3 From 70bafe7e4d52f6dafbb5888009c9b601cdbc3743 Mon Sep 17 00:00:00 2001 From: Vineet Gupta Date: Thu, 26 Mar 2015 14:25:35 +0530 Subject: ARC: switch to NPTL Signed-off-by: Vineet Gupta Signed-off-by: Bernhard Reutner-Fischer --- extra/Configs/defconfigs/arc/arcv2_defconfig | 2 +- extra/Configs/defconfigs/arc/defconfig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extra/Configs/defconfigs/arc/arcv2_defconfig b/extra/Configs/defconfigs/arc/arcv2_defconfig index d3a7dc7b2..7c4694eb1 100644 --- a/extra/Configs/defconfigs/arc/arcv2_defconfig +++ b/extra/Configs/defconfigs/arc/arcv2_defconfig @@ -7,7 +7,7 @@ KERNEL_HEADERS="%KERNEL_HEADERS%" # LDSO_CACHE_SUPPORT is not set LDSO_RUNPATH=y # LDSO_SAFE_RUNPATH is not set -LINUXTHREADS_OLD=y +UCLIBC_HAS_THREADS_NATIVE=y PTHREADS_DEBUG_SUPPORT=y UCLIBC_HAS_OBSTACK=y UCLIBC_SUSV2_LEGACY=y diff --git a/extra/Configs/defconfigs/arc/defconfig b/extra/Configs/defconfigs/arc/defconfig index 490bc2267..eebb11521 100644 --- a/extra/Configs/defconfigs/arc/defconfig +++ b/extra/Configs/defconfigs/arc/defconfig @@ -6,7 +6,7 @@ KERNEL_HEADERS="%KERNEL_HEADERS%" # LDSO_CACHE_SUPPORT is not set LDSO_RUNPATH=y # LDSO_SAFE_RUNPATH is not set -LINUXTHREADS_OLD=y +UCLIBC_HAS_THREADS_NATIVE=y PTHREADS_DEBUG_SUPPORT=y UCLIBC_HAS_OBSTACK=y UCLIBC_SUSV2_LEGACY=y -- cgit v1.2.3 From d3c60fc490d714d7610a91555cec67952409b189 Mon Sep 17 00:00:00 2001 From: Vineet Gupta Date: Thu, 26 Mar 2015 18:07:04 +0530 Subject: ARC/signal: shield sa_restorer from compiler toggle side-effects when building uClibc with -O0 (DODEBUG build) the default sigrestorer had some extra glue code generated for stack manipulation which was messing up resume from signal path. So annotate the function with -Os so that gcc would only generate the bare min 2 instruction TRAP sequence Reported-and-Debugged-by: Alexey Brodkin Signed-off-by: Vineet Gupta Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/arc/sigaction.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libc/sysdeps/linux/arc/sigaction.c b/libc/sysdeps/linux/arc/sigaction.c index 4a4c9e2d0..67ca38aca 100644 --- a/libc/sysdeps/linux/arc/sigaction.c +++ b/libc/sysdeps/linux/arc/sigaction.c @@ -13,7 +13,8 @@ /* * Default sigretrun stub if user doesn't specify SA_RESTORER */ -static void __default_rt_sa_restorer(void) +static void attribute_optimize("Os") __attribute_noinline__ +__default_rt_sa_restorer(void) { INTERNAL_SYSCALL_NCS(__NR_rt_sigreturn, , 0); } -- cgit v1.2.3 From 24946289317ea23bb0d1814cca0a499a905f7d6f Mon Sep 17 00:00:00 2001 From: Alexey Brodkin Date: Thu, 26 Mar 2015 14:25:37 +0530 Subject: ARC: don't hard-code ELF_NGREG Signed-off-by: Alexey Brodkin Signed-off-by: Vineet Gupta [updated changelog] Signed-off-by: Vineet Gupta Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/arc/sys/procfs.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/libc/sysdeps/linux/arc/sys/procfs.h b/libc/sysdeps/linux/arc/sys/procfs.h index a9e375b33..a47430340 100755 --- a/libc/sysdeps/linux/arc/sys/procfs.h +++ b/libc/sysdeps/linux/arc/sys/procfs.h @@ -20,17 +20,14 @@ #include #include #include +#include __BEGIN_DECLS /* Type for a general-purpose register. */ typedef unsigned long elf_greg_t; -/* And the whole bunch of them. We could have used `struct - user_regs' directly in the typedef, but tradition says that - the register set is an array, which does have some peculiar - semantics, so leave it that way. */ -#define ELF_NGREG 40 +#define ELF_NGREG (sizeof (struct user_regs_struct) / sizeof(elf_greg_t)) typedef elf_greg_t elf_gregset_t[ELF_NGREG]; typedef struct { } elf_fpregset_t; -- cgit v1.2.3