Clean up some code

- Use good ELF technique in cosmo_dlopen()
- Make strerror() conform more to other libc impls
- Introduce __clear_cache() and use it in cosmo_dlopen()
- Remove libc/fmt/fmt.h header (trying to kill off LIBC_FMT)
This commit is contained in:
Justine Tunney 2023-11-16 16:34:53 -08:00
parent 7010a8081e
commit 68c7c9c1e0
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
244 changed files with 378 additions and 588 deletions

View file

@ -16,9 +16,9 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/fmt.h"
#include "libc/str/str.h"
int __xpg_strerror_r(int a, char *b, size_t c) {
return strerror_r(a, b, c);
char *__xpg_strerror_r(int a, char *b, size_t c) {
strerror_r(a, b, c);
return b;
}

View file

@ -41,9 +41,8 @@
*/
int atoi(const char *s) {
int x, c, d;
do {
c = *s++;
} while (c == ' ' || c == '\t');
do c = *s++;
while (c == ' ' || c == '\t');
d = c == '-' ? -1 : 1;
if (c == '-' || c == '+') c = *s++;
for (x = 0; isdigit(c); c = *s++) {

View file

@ -31,9 +31,8 @@
long atol(const char *s) {
long x;
int c, d;
do {
c = *s++;
} while (c == ' ' || c == '\t');
do c = *s++;
while (c == ' ' || c == '\t');
d = c == '-' ? -1 : 1;
if (c == '-' || c == '+') c = *s++;
for (x = 0; isdigit(c); c = *s++) {

View file

@ -72,17 +72,6 @@ imaxdiv_t imaxdiv(intmax_t, intmax_t) pureconst;
#define lldiv(num, den) ((lldiv_t){(num) / (den), (num) % (den)})
#endif
#if (__GNUC__ * 100 + __GNUC_MINOR__ >= 406 || defined(__llvm__)) && \
!defined(__STRICT_ANSI__) && defined(_COSMO_SOURCE) && \
!defined(__COSMOCC__)
int128_t i128abs(int128_t)
libcesque pureconst;
int128_t strtoi128(const char *, char **, int) paramsnonnull((1));
uint128_t strtou128(const char *, char **, int) paramsnonnull((1));
int128_t wcstoi128(const wchar_t *, wchar_t **, int);
uint128_t wcstou128(const wchar_t *, wchar_t **, int);
#endif /* gcc 4.6+ */
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_FMT_CONV_H_ */

View file

@ -8,7 +8,7 @@ forceinline uint64_t __divmod10(uint64_t __x, unsigned *__r) {
*__r = __x % 10;
return __x / 10;
#else
uint128_t __dw;
unsigned __int128 __dw;
unsigned long long __hi, __rm;
__dw = __x;
__dw *= 0xcccccccccccccccdull;

View file

@ -1,25 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_FMT_FMT_H_
#define COSMOPOLITAN_LIBC_FMT_FMT_H_
#if __SIZEOF_POINTER__ == 8
#define POINTER_XDIGITS 12 /* math.log(2**48-1,16) */
#else
#define POINTER_XDIGITS 8
#endif
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
char *fcvt(double, int, int *, int *);
char *ecvt(double, int, int *, int *);
char *gcvt(double, int, char *);
#ifdef _COSMO_SOURCE
int __vcscanf(int (*)(void *), int (*)(int, void *), void *, const char *,
va_list);
int __fmt(void *, void *, const char *, va_list);
#endif
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_FMT_FMT_H_ */

View file

@ -76,17 +76,6 @@ o/$(MODE)/libc/fmt/wcstoumax.o: private \
CFLAGS += \
-Os
# we can't use compiler magic because:
# kprintf() depends on these functions
o/$(MODE)/libc/fmt/strerrno.greg.o \
o/$(MODE)/libc/fmt/strerrdoc.greg.o \
o/$(MODE)/libc/fmt/strerror_wr.greg.o: private \
COPTS += \
-fpie \
-fno-sanitize=all \
-fno-stack-protector \
-fpatchable-function-entry=0,0
LIBC_FMT_LIBS = $(foreach x,$(LIBC_FMT_ARTIFACTS),$($(x)))
LIBC_FMT_SRCS = $(foreach x,$(LIBC_FMT_ARTIFACTS),$($(x)_SRCS))
LIBC_FMT_HDRS = $(foreach x,$(LIBC_FMT_ARTIFACTS),$($(x)_HDRS))

View file

@ -41,4 +41,8 @@
} \
}
int __vcscanf(int (*)(void *), int (*)(int, void *), void *, const char *,
va_list);
int __fmt(void *, void *, const char *, va_list);
#endif /* COSMOPOLITAN_LIBC_FMT_STRTOL_H_ */

View file

@ -1,41 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/conv.h"
#include "libc/fmt/itoa.h"
#include "libc/mem/reverse.internal.h"
dontinline size_t uint64toarray(uint64_t i, char *a, int r) {
size_t j;
j = 0;
do {
a[j++] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i % r];
i /= r;
} while (i > 0);
a[j] = '\0';
reverse(a, j);
return j;
}
size_t int64toarray(int64_t i, char *a, int r) {
if (i < 0) {
*a++ = '-';
i = -(uint64_t)i;
}
return uint64toarray(i, a, r);
}

View file

@ -1,39 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/conv.h"
#include "libc/fmt/itoa.h"
#include "libc/limits.h"
#include "libc/mem/reverse.internal.h"
/**
* Converts unsigned 64-bit integer to octal string.
* @param a needs at least 24 bytes
* @return bytes written w/o nul
*/
dontinline size_t uint64toarray_radix8(uint64_t i, char a[hasatleast 24]) {
size_t j;
j = 0;
do {
a[j++] = i % 8 + '0';
i /= 8;
} while (i > 0);
a[j] = '\0';
reverse(a, j);
return j;
}

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/conv.h"
#include "libc/fmt/fmt.h"
#include "libc/stdckdint.h"
#include "libc/str/str.h"
#include "libc/sysv/errfuns.h"

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/fmt.h"
#include "libc/str/str.h"
/**

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/fmt.h"
#include "libc/str/str.h"
/**

View file

@ -18,7 +18,7 @@
*/
#include "libc/errno.h"
#include "libc/fmt/conv.h"
#include "libc/fmt/strtol.internal.h"
#include "libc/fmt/internal.h"
#include "libc/limits.h"
#include "libc/stdckdint.h"
#include "libc/str/str.h"

View file

@ -18,7 +18,7 @@
*/
#include "libc/errno.h"
#include "libc/fmt/conv.h"
#include "libc/fmt/strtol.internal.h"
#include "libc/fmt/internal.h"
#include "libc/limits.h"
#include "libc/stdckdint.h"
#include "libc/str/str.h"

View file

@ -18,7 +18,7 @@
*/
#include "libc/errno.h"
#include "libc/fmt/conv.h"
#include "libc/fmt/strtol.internal.h"
#include "libc/fmt/internal.h"
#include "libc/limits.h"
#include "libc/stdckdint.h"
#include "libc/str/str.h"

View file

@ -18,7 +18,7 @@
*/
#include "libc/errno.h"
#include "libc/fmt/conv.h"
#include "libc/fmt/strtol.internal.h"
#include "libc/fmt/internal.h"
#include "libc/limits.h"
#include "libc/stdckdint.h"
#include "libc/str/str.h"