From d40369b0e09e4e2228ebff305067ec2d99220848 Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Sun, 14 Jan 2018 18:28:35 -0600 Subject: global: Format the code consistently * Apply clang-format. * Change all comments to the same style. * Add braces as dictated by the coding style guidelines. Signed-off-by: Samuel Holland --- libgcompat/math.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libgcompat/math.c') diff --git a/libgcompat/math.c b/libgcompat/math.c index 2c793e4..42ed032 100644 --- a/libgcompat/math.c +++ b/libgcompat/math.c @@ -1,4 +1,4 @@ -#include // isinf, isnan +#include /* isinf, isnan */ int __isinff(float number) { -- cgit v1.2.3-70-g09d2 From dfafb0735f09d65a392d03a2d1ad3d0b934981da Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Sun, 14 Jan 2018 18:40:59 -0600 Subject: libgcompat: Add and use a macro for defining symbol aliases * Prefer providing the underscore-prefixed symbol as the strong definition. * Do not use a weak alias if the alias is also underscore-prefixed. * Make libgcompat objects depend on the new header. [NOTE: I originally took the weak_alias macro from musl's libc.h, but it's trivial and the same pattern already in use. If desired, I can add the musl copyright notice.] Signed-off-by: Samuel Holland --- Makefile | 4 ++++ libgcompat/alias.h | 9 +++++++++ libgcompat/malloc.c | 14 ++++++-------- libgcompat/math.c | 11 ++++++----- libgcompat/pthread.c | 7 +++---- libgcompat/resolv.c | 13 ++++++------- libgcompat/string.c | 8 ++++---- 7 files changed, 38 insertions(+), 28 deletions(-) create mode 100644 libgcompat/alias.h (limited to 'libgcompat/math.c') diff --git a/Makefile b/Makefile index 6c532fd..b941dcf 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +LIBGCOMPAT_INCLUDE = \ + libgcompat/alias.h LIBGCOMPAT_SRC = \ libgcompat/backtrace.c \ libgcompat/dlmopen.c \ @@ -33,6 +35,8 @@ ${LIBGCOMPAT_NAME}: ${LIBGCOMPAT_OBJ} $(CC) -o ${LIBGCOMPAT_NAME} -Wl,-soname,${LIBGCOMPAT_NAME} \ -shared ${LIBGCOMPAT_OBJ} +${LIBGCOMPAT_OBJ}: ${LIBGCOMPAT_INCLUDE} + ${LOADER_NAME}: ${LOADER_OBJ} $(CC) -o ${LOADER_NAME} -fPIE -static ${LOADER_OBJ} diff --git a/libgcompat/alias.h b/libgcompat/alias.h new file mode 100644 index 0000000..3f54672 --- /dev/null +++ b/libgcompat/alias.h @@ -0,0 +1,9 @@ +#ifndef _ALIAS_H_ +#define _ALIAS_H_ + +#define alias(old, new) \ + extern __typeof(old) new __attribute__((__alias__(#old))) +#define weak_alias(old, new) \ + extern __typeof(old) new __attribute__((weak, __alias__(#old))) + +#endif /* _ALIAS_H_ */ diff --git a/libgcompat/malloc.c b/libgcompat/malloc.c index db85d8d..dc9d25e 100644 --- a/libgcompat/malloc.c +++ b/libgcompat/malloc.c @@ -27,6 +27,8 @@ #include /* {m,c,re}alloc, free */ #include /* memset */ +#include "alias.h" /* alias */ + struct mallinfo { int arena; /* Non-mmapped space allocated (bytes) */ int ordblks; /* Number of free chunks */ @@ -51,31 +53,27 @@ void *__libc_malloc(size_t size) { return malloc(size); } +alias(__libc_malloc, __malloc); void __libc_free(void *ptr) { return free(ptr); } +alias(__libc_free, __free); void *__libc_calloc(size_t nmemb, size_t size) { return calloc(nmemb, size); } +alias(__libc_calloc, __calloc); void *__libc_realloc(void *ptr, size_t size) { return realloc(ptr, size); } +alias(__libc_realloc, __realloc); void *__libc_memalign(size_t align, size_t len) { return memalign(align, len); } - -extern __typeof(__libc_malloc) __malloc - __attribute__((weak, alias("__libc_malloc"))); -extern __typeof(__libc_calloc) __calloc - __attribute__((weak, alias("__libc_calloc"))); -extern __typeof(__libc_realloc) __realloc - __attribute__((weak, alias("__libc_realloc"))); -extern __typeof(__libc_free) __free __attribute__((weak, alias("__libc_free"))); diff --git a/libgcompat/math.c b/libgcompat/math.c index 42ed032..2982116 100644 --- a/libgcompat/math.c +++ b/libgcompat/math.c @@ -1,26 +1,27 @@ #include /* isinf, isnan */ +#include "alias.h" /* weak_alias */ + int __isinff(float number) { return isinf(number); } +weak_alias(__isinff, isinff); int __isinf(double number) { return isinf(number); } +weak_alias(__isinf, isinf); int __isnanf(float number) { return isnan(number); } +weak_alias(__isnanf, isnanf); int __isnan(double number) { return isnan(number); } - -extern __typeof(__isnanf) isnanf __attribute__((weak, alias("__isnanf"))); -extern __typeof(__isnan) isnan __attribute__((weak, alias("__isnan"))); -extern __typeof(__isinff) isinff __attribute__((weak, alias("__isinff"))); -extern __typeof(__isinf) isinf __attribute__((weak, alias("__isinf"))); +weak_alias(__isnan, isnan); diff --git a/libgcompat/pthread.c b/libgcompat/pthread.c index 52daceb..9333554 100644 --- a/libgcompat/pthread.c +++ b/libgcompat/pthread.c @@ -1,14 +1,13 @@ #include +#include "alias.h" /* weak_alias */ + int __register_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void)) { return pthread_atfork(prepare, parent, child); } - -int register_atfork(void (*prepare)(void), void (*parent)(void), - void (*child)(void)) - __attribute__((weak, alias("__register_atfork"))); +weak_alias(__register_atfork, register_atfork); void __pthread_register_cancel(void *buf) { diff --git a/libgcompat/resolv.c b/libgcompat/resolv.c index 3566dcd..7ad984f 100644 --- a/libgcompat/resolv.c +++ b/libgcompat/resolv.c @@ -9,7 +9,9 @@ #include /* res_state */ #include /* memcpy, memset */ -static inline int res_ninit(res_state statp) +#include "alias.h" /* weak_alias */ + +static inline int __res_ninit(res_state statp) { int rc = res_init(); if (statp != &_res) { @@ -17,8 +19,9 @@ static inline int res_ninit(res_state statp) } return rc; } +weak_alias(__res_ninit, res_ninit); -static inline int res_nclose(res_state statp) +static inline int __res_nclose(res_state statp) { if (!statp) { return -1; @@ -28,8 +31,4 @@ static inline int res_nclose(res_state statp) } return 0; } - -extern __typeof(res_ninit) __res_ninit - __attribute__((weak, alias("res_ninit"))); -extern __typeof(res_nclose) __res_nclose - __attribute__((weak, alias("res_nclose"))); +weak_alias(__res_nclose, res_nclose); diff --git a/libgcompat/string.c b/libgcompat/string.c index 60f61fc..7ca0bf6 100644 --- a/libgcompat/string.c +++ b/libgcompat/string.c @@ -2,6 +2,8 @@ #include /* strto[u?]ll */ #include /* memcpy, strcpy, strncat, strndup */ +#include "alias.h" /* weak_alias */ + /* "Checked" memcpy */ void *__memcpy_chk(void *dest, const void *src, size_t len, size_t destlen) { @@ -60,7 +62,7 @@ char *__strndup(const char *str, size_t count) /* The existance of this method, and the fact it is used in real code, gives * me nightmares. */ -void *rawmemchr(const void *s, int c) +void *__rawmemchr(const void *s, int c) { const unsigned char *haystack = s; unsigned char needle = (unsigned char) c; @@ -68,9 +70,7 @@ void *rawmemchr(const void *s, int c) ; return (void *) haystack; } - -extern __typeof(rawmemchr) __rawmemchr - __attribute__((weak, alias("rawmemchr"))); +weak_alias(__rawmemchr, rawmemchr); /* Another useless __ alias */ char *__strtok_r(char *str, const char *delim, char **saveptr) -- cgit v1.2.3-70-g09d2 From ea0bbb48b37dc43c3a1cec4e87ed7049e13b4ff9 Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Sun, 14 Jan 2018 21:41:21 -0600 Subject: math: Clean up, add additional functions * Add finite() variants, needed by some applications. * Add remaining long double variants of existing functions. * Sort and document existing functions, including where referenced in the LSB standard. Signed-off-by: Samuel Holland --- libgcompat/math.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 80 insertions(+), 11 deletions(-) (limited to 'libgcompat/math.c') diff --git a/libgcompat/math.c b/libgcompat/math.c index 2982116..db123f8 100644 --- a/libgcompat/math.c +++ b/libgcompat/math.c @@ -1,27 +1,96 @@ -#include /* isinf, isnan */ +#include /* isfinite, isinf, isnan */ #include "alias.h" /* weak_alias */ -int __isinff(float number) +/** + * Test for finite value. + */ +int __finite(double arg) { - return isinf(number); + return isfinite(arg); } -weak_alias(__isinff, isinff); +weak_alias(__finite, finite); + +/** + * Test for finite value. + */ +int __finitef(float arg) +{ + return isfinite(arg); +} +weak_alias(__finitef, finitef); + +/** + * Test for finite value. + */ +int __finitel(long double arg) +{ + return isfinite(arg); +} +weak_alias(__finitel, finitel); -int __isinf(double number) +/** + * Test for infinity. + * + * LSB 5.0: LSB-Core-generic/baselib---isinf.html + */ +int __isinf(double arg) { - return isinf(number); + return isinf(arg); } weak_alias(__isinf, isinf); -int __isnanf(float number) +/** + * Test for infinity. + * + * LSB 5.0: LSB-Core-generic/baselib---isinff.html + */ +int __isinff(float arg) { - return isnan(number); + return isinf(arg); } -weak_alias(__isnanf, isnanf); +weak_alias(__isinff, isinff); -int __isnan(double number) +/** + * Test for infinity. + * + * LSB 5.0: LSB-Core-generic/baselib---isinfl.html + */ +int __isinfl(long double arg) { - return isnan(number); + return isinf(arg); +} +weak_alias(__isinfl, isinfl); + +/** + * Test for a NaN. + * + * LSB 5.0: LSB-Core-generic/baselib---isnan.html + */ +int __isnan(double arg) +{ + return isnan(arg); } weak_alias(__isnan, isnan); + +/** + * Test for a NaN. + * + * LSB 5.0: LSB-Core-generic/baselib---isnanf.html + */ +int __isnanf(float arg) +{ + return isnan(arg); +} +weak_alias(__isnanf, isnanf); + +/** + * Test for a NaN. + * + * LSB 5.0: LSB-Core-generic/baselib---isnanl.html + */ +int __isnanl(long double arg) +{ + return isnan(arg); +} +weak_alias(__isnanl, isnanl); -- cgit v1.2.3-70-g09d2