From 61257d48d4b04cc18e72fb9df23a4a494d8f873f Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Sun, 26 Jun 2022 02:58:36 -0700 Subject: [PATCH] Make some quick fixes and cleanup --- .github/workflows/build.yml | 2 +- examples/rlimit.c | 6 +- libc/calls/state.internal.h | 4 +- libc/elf/def.h | 2 +- libc/fmt/magnumstrs.internal.h | 2 + libc/intrin/asan.c | 17 ++++-- libc/intrin/cxaatexit.c | 2 +- libc/{runtime => intrin}/cxaatexit.internal.h | 2 +- libc/intrin/cxablocks.c | 2 +- libc/intrin/cxafinalize.c | 2 +- libc/intrin/cxalock.c | 2 +- libc/intrin/describeclockname.c | 29 +--------- libc/intrin/describeflags.internal.h | 4 +- libc/intrin/describemagnums.c | 32 +++++++++++ ...riberlimit_name.c => describerlimitname.c} | 34 +++--------- libc/intrin/describesockettype.c | 23 +++----- libc/intrin/describesockoptname.c | 11 +--- libc/intrin/krlimitnames.S | 55 +++++++++++++++++++ libc/intrin/nopl.h | 5 +- libc/{str => intrin}/stpcpy.c | 15 +++-- libc/{str => intrin}/strcpy.c | 17 +++--- libc/intrin/ubsan.c | 43 +++++++++------ libc/intrin/x86gradenames.c | 15 +++-- libc/intrin/x86marchnames.c | 46 ++++++++-------- libc/log/cxaprintexits.c | 2 +- libc/runtime/memtrack.internal.h | 2 +- libc/runtime/printargs.c | 2 +- libc/stdio/fflush.internal.h | 2 +- libc/stdio/stdio.h | 2 +- libc/sysv/consts.sh | 30 ---------- .../consts/PTHREAD_BARRIER_SERIAL_THREAD.S | 2 - .../sysv/consts/PTHREAD_CANCEL_ASYNCHRONOUS.S | 2 - libc/sysv/consts/PTHREAD_CANCEL_DEFERRED.S | 2 - libc/sysv/consts/PTHREAD_CANCEL_DISABLE.S | 2 - libc/sysv/consts/PTHREAD_CANCEL_ENABLE.S | 2 - libc/sysv/consts/PTHREAD_CREATE_DETACHED.S | 2 - libc/sysv/consts/PTHREAD_CREATE_JOINABLE.S | 2 - .../consts/PTHREAD_DESTRUCTOR_ITERATIONS.S | 2 - libc/sysv/consts/PTHREAD_EXPLICIT_SCHED.S | 2 - libc/sysv/consts/PTHREAD_INHERIT_SCHED.S | 2 - libc/sysv/consts/PTHREAD_KEYS_MAX.S | 2 - libc/sysv/consts/PTHREAD_MUTEX_DEFAULT.S | 2 - libc/sysv/consts/PTHREAD_MUTEX_ERRORCHECK.S | 2 - libc/sysv/consts/PTHREAD_MUTEX_NORMAL.S | 2 - libc/sysv/consts/PTHREAD_MUTEX_RECURSIVE.S | 2 - libc/sysv/consts/PTHREAD_MUTEX_ROBUST.S | 2 - libc/sysv/consts/PTHREAD_MUTEX_STALLED.S | 2 - libc/sysv/consts/PTHREAD_PRIO_INHERIT.S | 2 - libc/sysv/consts/PTHREAD_PRIO_NONE.S | 2 - libc/sysv/consts/PTHREAD_PRIO_PROTECT.S | 2 - libc/sysv/consts/PTHREAD_PROCESS_PRIVATE.S | 2 - libc/sysv/consts/PTHREAD_PROCESS_SHARED.S | 2 - libc/sysv/consts/PTHREAD_SCOPE_PROCESS.S | 2 - libc/sysv/consts/PTHREAD_SCOPE_SYSTEM.S | 2 - libc/sysv/consts/PTHREAD_STACK_MIN.S | 2 - libc/thread/wait.c | 4 +- libc/time/localtime.c | 2 +- libc/zipos/zipos.internal.h | 2 +- test/libc/mem/malloc_test.c | 2 +- third_party/chibicc/as.c | 17 ++++-- third_party/gdtoa/lock.h | 2 +- third_party/sqlite3/sqliteInt.inc | 2 +- tool/decode/elf.c | 39 +++++++++++++ 63 files changed, 275 insertions(+), 257 deletions(-) rename libc/{runtime => intrin}/cxaatexit.internal.h (92%) create mode 100644 libc/intrin/describemagnums.c rename libc/intrin/{describerlimit_name.c => describerlimitname.c} (58%) create mode 100644 libc/intrin/krlimitnames.S rename libc/{str => intrin}/stpcpy.c (90%) rename libc/{str => intrin}/strcpy.c (87%) delete mode 100644 libc/sysv/consts/PTHREAD_BARRIER_SERIAL_THREAD.S delete mode 100644 libc/sysv/consts/PTHREAD_CANCEL_ASYNCHRONOUS.S delete mode 100644 libc/sysv/consts/PTHREAD_CANCEL_DEFERRED.S delete mode 100644 libc/sysv/consts/PTHREAD_CANCEL_DISABLE.S delete mode 100644 libc/sysv/consts/PTHREAD_CANCEL_ENABLE.S delete mode 100644 libc/sysv/consts/PTHREAD_CREATE_DETACHED.S delete mode 100644 libc/sysv/consts/PTHREAD_CREATE_JOINABLE.S delete mode 100644 libc/sysv/consts/PTHREAD_DESTRUCTOR_ITERATIONS.S delete mode 100644 libc/sysv/consts/PTHREAD_EXPLICIT_SCHED.S delete mode 100644 libc/sysv/consts/PTHREAD_INHERIT_SCHED.S delete mode 100644 libc/sysv/consts/PTHREAD_KEYS_MAX.S delete mode 100644 libc/sysv/consts/PTHREAD_MUTEX_DEFAULT.S delete mode 100644 libc/sysv/consts/PTHREAD_MUTEX_ERRORCHECK.S delete mode 100644 libc/sysv/consts/PTHREAD_MUTEX_NORMAL.S delete mode 100644 libc/sysv/consts/PTHREAD_MUTEX_RECURSIVE.S delete mode 100644 libc/sysv/consts/PTHREAD_MUTEX_ROBUST.S delete mode 100644 libc/sysv/consts/PTHREAD_MUTEX_STALLED.S delete mode 100644 libc/sysv/consts/PTHREAD_PRIO_INHERIT.S delete mode 100644 libc/sysv/consts/PTHREAD_PRIO_NONE.S delete mode 100644 libc/sysv/consts/PTHREAD_PRIO_PROTECT.S delete mode 100644 libc/sysv/consts/PTHREAD_PROCESS_PRIVATE.S delete mode 100644 libc/sysv/consts/PTHREAD_PROCESS_SHARED.S delete mode 100644 libc/sysv/consts/PTHREAD_SCOPE_PROCESS.S delete mode 100644 libc/sysv/consts/PTHREAD_SCOPE_SYSTEM.S delete mode 100644 libc/sysv/consts/PTHREAD_STACK_MIN.S diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e06681895..909a0303f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - mode: ["", tiny, opt] + mode: ["", tiny, opt, rel] steps: - uses: actions/checkout@v3 diff --git a/examples/rlimit.c b/examples/rlimit.c index 95cdcbda5..fefa9f43f 100644 --- a/examples/rlimit.c +++ b/examples/rlimit.c @@ -50,6 +50,7 @@ static void SetLimit(int resource, uint64_t soft, uint64_t hard) { int main(int argc, char *argv[]) { int i, rc; + char rlnbuf[20]; struct rlimit rlim; // // example of how you might change the limits @@ -64,8 +65,9 @@ int main(int argc, char *argv[]) { for (i = 0; i < RLIM_NLIMITS; ++i) { rc = getrlimit(i, &rlim); - printf("SETRLIMIT(%-20s, %,16ld, %,16ld) → %d %s\n", DescribeRlimitName(i), - rlim.rlim_cur, rlim.rlim_max, rc, !rc ? "" : strerror(errno)); + printf("SETRLIMIT(%-20s, %,16ld, %,16ld) → %d %s\n", + (DescribeRlimitName)(rlnbuf, i), rlim.rlim_cur, rlim.rlim_max, rc, + !rc ? "" : strerror(errno)); } return 0; diff --git a/libc/calls/state.internal.h b/libc/calls/state.internal.h index b07c40f16..0759ad91c 100644 --- a/libc/calls/state.internal.h +++ b/libc/calls/state.internal.h @@ -16,7 +16,7 @@ void __fds_unlock(void); void __sig_lock(void); void __sig_unlock(void); -#if defined(__GNUC__) && !defined(__llvm__) && !defined(__STRICT_ANSI__) +#ifdef _NOPL0 #define __fds_lock() _NOPL0("__threadcalls", __fds_lock) #define __fds_unlock() _NOPL0("__threadcalls", __fds_unlock) #else @@ -24,7 +24,7 @@ void __sig_unlock(void); #define __fds_unlock() (__threaded ? __fds_unlock() : 0) #endif -#if defined(__GNUC__) && !defined(__llvm__) && !defined(__STRICT_ANSI__) +#ifdef _NOPL0 #define __sig_lock() _NOPL0("__threadcalls", __sig_lock) #define __sig_unlock() _NOPL0("__threadcalls", __sig_unlock) #else diff --git a/libc/elf/def.h b/libc/elf/def.h index 0578d108b..311618ee7 100644 --- a/libc/elf/def.h +++ b/libc/elf/def.h @@ -84,7 +84,7 @@ #define EM_RISCV 243 #define EM_BPF 247 -#define GRP_COMDAT 0x1 +#define GRP_COMDAT 1 #define STN_UNDEF 0 #define EV_NONE 0 diff --git a/libc/fmt/magnumstrs.internal.h b/libc/fmt/magnumstrs.internal.h index 7283f010d..3c29ef5f7 100644 --- a/libc/fmt/magnumstrs.internal.h +++ b/libc/fmt/magnumstrs.internal.h @@ -21,11 +21,13 @@ hidden extern const struct MagnumStr kErrnoDocs[]; hidden extern const struct MagnumStr kErrnoNames[]; hidden extern const struct MagnumStr kIpOptnames[]; hidden extern const struct MagnumStr kOpenFlags[]; +hidden extern const struct MagnumStr kRlimitNames[]; hidden extern const struct MagnumStr kSignalNames[]; hidden extern const struct MagnumStr kSockOptnames[]; hidden extern const struct MagnumStr kTcpOptnames[]; char *GetMagnumStr(const struct MagnumStr *, int); +char *DescribeMagnum(char *, const struct MagnumStr *, const char *, int); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/intrin/asan.c b/libc/intrin/asan.c index 16045e9fe..6bd69346d 100644 --- a/libc/intrin/asan.c +++ b/libc/intrin/asan.c @@ -200,6 +200,15 @@ static char *__asan_utf8cpy(char *p, unsigned c) { return p; } +static char *__asan_stpcpy(char *d, const char *s) { + size_t i; + for (i = 0;; ++i) { + if (!(d[i] = s[i])) { + return d + i; + } + } +} + static void __asan_memset(void *p, char c, size_t n) { char *b; size_t i; @@ -645,9 +654,9 @@ static char *__asan_format_section(char *p, const void *p1, const void *p2, intptr_t a, b; if ((a = (intptr_t)p1) < (b = (intptr_t)p2)) { p = __asan_format_interval(p, a, b), *p++ = ' '; - p = __stpcpy(p, name); + p = __asan_stpcpy(p, name); if (a <= (intptr_t)addr && (intptr_t)addr <= b) { - p = __stpcpy(p, " ←address"); + p = __asan_stpcpy(p, " ←address"); } *p++ = '\n'; } @@ -822,9 +831,9 @@ dontdiscard static __asan_die_f *__asan_report(const void *addr, int size, y = m->p[i].y; p = __asan_format_interval(p, x << 16, (y << 16) + (FRAMESIZE - 1)); z = (intptr_t)addr >> 16; - if (x <= z && z <= y) p = __stpcpy(p, " ←address"); + if (x <= z && z <= y) p = __asan_stpcpy(p, " ←address"); z = (((intptr_t)addr >> 3) + 0x7fff8000) >> 16; - if (x <= z && z <= y) p = __stpcpy(p, " ←shadow"); + if (x <= z && z <= y) p = __asan_stpcpy(p, " ←shadow"); *p++ = '\n'; } __mmi_unlock(); diff --git a/libc/intrin/cxaatexit.c b/libc/intrin/cxaatexit.c index 061a38d9f..bfd2a18d9 100644 --- a/libc/intrin/cxaatexit.c +++ b/libc/intrin/cxaatexit.c @@ -19,10 +19,10 @@ #include "libc/assert.h" #include "libc/bits/weaken.h" #include "libc/calls/strace.internal.h" +#include "libc/intrin/cxaatexit.internal.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/bsr.h" -#include "libc/runtime/cxaatexit.internal.h" #include "libc/runtime/runtime.h" #include "libc/sysv/errfuns.h" diff --git a/libc/runtime/cxaatexit.internal.h b/libc/intrin/cxaatexit.internal.h similarity index 92% rename from libc/runtime/cxaatexit.internal.h rename to libc/intrin/cxaatexit.internal.h index d8727f2eb..99e1e9036 100644 --- a/libc/runtime/cxaatexit.internal.h +++ b/libc/intrin/cxaatexit.internal.h @@ -24,7 +24,7 @@ void __cxa_lock(void); void __cxa_unlock(void); void __cxa_printexits(FILE *, void *); -#if defined(__GNUC__) && !defined(__llvm__) && !defined(__STRICT_ANSI__) +#ifdef _NOPL0 #define __cxa_lock() _NOPL0("__threadcalls", __cxa_lock) #define __cxa_unlock() _NOPL0("__threadcalls", __cxa_unlock) #else diff --git a/libc/intrin/cxablocks.c b/libc/intrin/cxablocks.c index df3a8dc7e..cbeba7d28 100644 --- a/libc/intrin/cxablocks.c +++ b/libc/intrin/cxablocks.c @@ -16,6 +16,6 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/runtime/cxaatexit.internal.h" +#include "libc/intrin/cxaatexit.internal.h" struct CxaAtexitBlocks __cxa_blocks; diff --git a/libc/intrin/cxafinalize.c b/libc/intrin/cxafinalize.c index 9ffea93f2..b7f76c4c6 100644 --- a/libc/intrin/cxafinalize.c +++ b/libc/intrin/cxafinalize.c @@ -19,9 +19,9 @@ #include "libc/assert.h" #include "libc/bits/weaken.h" #include "libc/calls/strace.internal.h" +#include "libc/intrin/cxaatexit.internal.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/bsf.h" -#include "libc/runtime/cxaatexit.internal.h" #include "libc/runtime/runtime.h" /** diff --git a/libc/intrin/cxalock.c b/libc/intrin/cxalock.c index d78cef33d..49b2d96b6 100644 --- a/libc/intrin/cxalock.c +++ b/libc/intrin/cxalock.c @@ -16,8 +16,8 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/intrin/cxaatexit.internal.h" #include "libc/intrin/pthread.h" -#include "libc/runtime/cxaatexit.internal.h" static pthread_mutex_t __cxa_lock_obj; diff --git a/libc/intrin/describeclockname.c b/libc/intrin/describeclockname.c index 0590921f0..817c5d92f 100644 --- a/libc/intrin/describeclockname.c +++ b/libc/intrin/describeclockname.c @@ -16,39 +16,12 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/fmt/itoa.h" #include "libc/fmt/magnumstrs.internal.h" #include "libc/intrin/describeflags.internal.h" -#include "libc/str/str.h" -#include "libc/sysv/consts/sol.h" - -static inline char *StpCpy(char *d, const char *s) { - size_t i; - for (i = 0;; ++i) { - if (!(d[i] = s[i])) { - return d + i; - } - } -} /** * Describes clock_gettime() clock argument. */ const char *(DescribeClockName)(char buf[32], int x) { - int i; - char *s, *p; - if ((s = GetMagnumStr(kClockNames, x))) { - p = buf; - *p++ = 'C'; - *p++ = 'L'; - *p++ = 'O'; - *p++ = 'C'; - *p++ = 'K'; - *p++ = '_'; - StpCpy(p, s); - return buf; - } else { - FormatInt32(buf, x); - return buf; - } + return DescribeMagnum(buf, kClockNames, "CLOCK_", x); } diff --git a/libc/intrin/describeflags.internal.h b/libc/intrin/describeflags.internal.h index c0b688406..7f7130c68 100644 --- a/libc/intrin/describeflags.internal.h +++ b/libc/intrin/describeflags.internal.h @@ -51,7 +51,7 @@ const char *DescribePrctlOperation(int); const char *DescribeProtFlags(char[48], int); const char *DescribeRemapFlags(char[48], int); const char *DescribeRlimit(char[64], int, const struct rlimit *); -const char *DescribeRlimitName(char[12], int); +const char *DescribeRlimitName(char[20], int); const char *DescribeSeccompOperation(int); const char *DescribeSigaction(char[128], int, const struct sigaction *); const char *DescribeSigaltstk(char[128], int, const struct sigaltstack *); @@ -94,7 +94,7 @@ void DescribeIovNt(const struct NtIovec *, uint32_t, ssize_t); #define DescribeProtFlags(dirfd) DescribeProtFlags(alloca(48), dirfd) #define DescribeRemapFlags(dirfd) DescribeRemapFlags(alloca(48), dirfd) #define DescribeRlimit(rc, rl) DescribeRlimit(alloca(64), rc, rl) -#define DescribeRlimitName(rl) DescribeRlimitName(alloca(12), rl) +#define DescribeRlimitName(rl) DescribeRlimitName(alloca(20), rl) #define DescribeSigaction(rc, sa) DescribeSigaction(alloca(128), rc, sa) #define DescribeSigaltstk(rc, ss) DescribeSigaltstk(alloca(128), rc, ss) #define DescribeSigset(rc, ss) DescribeSigset(alloca(64), rc, ss) diff --git a/libc/intrin/describemagnums.c b/libc/intrin/describemagnums.c new file mode 100644 index 000000000..0474405fa --- /dev/null +++ b/libc/intrin/describemagnums.c @@ -0,0 +1,32 @@ +/*-*- 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 2022 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/itoa.h" +#include "libc/fmt/magnumstrs.internal.h" +#include "libc/str/str.h" + +char *DescribeMagnum(char *b, const struct MagnumStr *m, const char *p, int x) { + char *s; + if ((s = GetMagnumStr(m, x))) { + stpcpy(stpcpy(b, p), s); + return b; + } else { + FormatInt32(b, x); + return b; + } +} diff --git a/libc/intrin/describerlimit_name.c b/libc/intrin/describerlimitname.c similarity index 58% rename from libc/intrin/describerlimit_name.c rename to libc/intrin/describerlimitname.c index 61ec49245..1c2d9e5ac 100644 --- a/libc/intrin/describerlimit_name.c +++ b/libc/intrin/describerlimitname.c @@ -16,31 +16,13 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/strace.internal.h" -#include "libc/fmt/itoa.h" -#include "libc/sysv/consts/rlimit.h" +#include "libc/fmt/magnumstrs.internal.h" +#include "libc/intrin/describeflags.internal.h" -const char *(DescribeRlimitName)(char buf[12], int resource) { - if (resource == 127) return "n/a"; - if (resource == RLIMIT_AS) return "RLIMIT_AS"; - if (resource == RLIMIT_CPU) return "RLIMIT_CPU"; - if (resource == RLIMIT_FSIZE) return "RLIMIT_FSIZE"; - if (resource == RLIMIT_NPROC) return "RLIMIT_NPROC"; - if (resource == RLIMIT_NOFILE) return "RLIMIT_NOFILE"; - if (resource == RLIMIT_RSS) return "RLIMIT_RSS"; - if (resource == RLIMIT_DATA) return "RLIMIT_DATA"; - if (resource == RLIMIT_CORE) return "RLIMIT_CORE"; - if (resource == RLIMIT_STACK) return "RLIMIT_STACK"; - if (resource == RLIMIT_SIGPENDING) return "RLIMIT_SIGPENDING"; - if (resource == RLIMIT_MEMLOCK) return "RLIMIT_MEMLOCK"; - if (resource == RLIMIT_LOCKS) return "RLIMIT_LOCKS"; - if (resource == RLIMIT_MSGQUEUE) return "RLIMIT_MSGQUEUE"; - if (resource == RLIMIT_NICE) return "RLIMIT_NICE"; - if (resource == RLIMIT_RTPRIO) return "RLIMIT_RTPRIO"; - if (resource == RLIMIT_RTTIME) return "RLIMIT_RTTIME"; - if (resource == RLIMIT_SWAP) return "RLIMIT_SWAP"; - if (resource == RLIMIT_SBSIZE) return "RLIMIT_SBSIZE"; - if (resource == RLIMIT_NPTS) return "RLIMIT_NPTS"; - FormatInt32(buf, resource); - return buf; +/** + * Describes setrlimit() / getrlimit() argument. + */ +const char *(DescribeRlimitName)(char buf[20], int x) { + if (x == 127) return "n/a"; + return DescribeMagnum(buf, kRlimitNames, "RLIMIT_", x); } diff --git a/libc/intrin/describesockettype.c b/libc/intrin/describesockettype.c index ec144b4b9..0a4a05a0d 100644 --- a/libc/intrin/describesockettype.c +++ b/libc/intrin/describesockettype.c @@ -21,34 +21,25 @@ #include "libc/str/str.h" #include "libc/sysv/consts/sock.h" -static char *StpCpy(char *d, const char *s) { - size_t i; - for (i = 0;; ++i) { - if (!(d[i] = s[i])) { - return d + i; - } - } -} - const char *(DescribeSocketType)(char buf[64], int type) { int x; char *p; p = buf; x = type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK); if (x == SOCK_STREAM) { - p = StpCpy(p, "SOCK_STREAM"); + p = stpcpy(p, "SOCK_STREAM"); } else if (x == SOCK_DGRAM) { - p = StpCpy(p, "SOCK_DGRAM"); + p = stpcpy(p, "SOCK_DGRAM"); } else if (x == SOCK_RAW) { - p = StpCpy(p, "SOCK_RAW"); + p = stpcpy(p, "SOCK_RAW"); } else if (x == SOCK_RDM) { - p = StpCpy(p, "SOCK_RDM"); + p = stpcpy(p, "SOCK_RDM"); } else if (x == SOCK_SEQPACKET) { - p = StpCpy(p, "SOCK_SEQPACKET"); + p = stpcpy(p, "SOCK_SEQPACKET"); } else { p = FormatInt32(p, x); } - if (type & SOCK_CLOEXEC) p = StpCpy(p, "|SOCK_CLOEXEC"); - if (type & SOCK_NONBLOCK) p = StpCpy(p, "|SOCK_NONBLOCK"); + if (type & SOCK_CLOEXEC) p = stpcpy(p, "|SOCK_CLOEXEC"); + if (type & SOCK_NONBLOCK) p = stpcpy(p, "|SOCK_NONBLOCK"); return buf; } diff --git a/libc/intrin/describesockoptname.c b/libc/intrin/describesockoptname.c index 94e726f0b..8215fb0c3 100644 --- a/libc/intrin/describesockoptname.c +++ b/libc/intrin/describesockoptname.c @@ -22,15 +22,6 @@ #include "libc/str/str.h" #include "libc/sysv/consts/sol.h" -static inline char *StpCpy(char *d, const char *s) { - size_t i; - for (i = 0;; ++i) { - if (!(d[i] = s[i])) { - return d + i; - } - } -} - /** * Describes setsockopt() optname arguments. */ @@ -65,7 +56,7 @@ const char *(DescribeSockOptname)(char buf[32], int l, int x) { ms = 0; } if (ms && (s = GetMagnumStr(ms, x))) { - StpCpy(p, s); + stpcpy(p, s); } else { FormatInt32(p, x); } diff --git a/libc/intrin/krlimitnames.S b/libc/intrin/krlimitnames.S new file mode 100644 index 000000000..30874a1a3 --- /dev/null +++ b/libc/intrin/krlimitnames.S @@ -0,0 +1,55 @@ +/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ +│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 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/magnumstrs.internal.h" +#include "libc/macros.internal.h" + + .macro .e e s + .long \e - kRlimitNames + .long 1f - kRlimitNames + .rodata.str1.1 +1: .string "\s" + .previous + .endm + + .section .rodata + .align 4 + .underrun +kRlimitNames: + .e RLIMIT_AS,"AS" + .e RLIMIT_CPU,"CPU" + .e RLIMIT_FSIZE,"FSIZE" + .e RLIMIT_NPROC,"NPROC" + .e RLIMIT_NOFILE,"NOFILE" + .e RLIMIT_RSS,"RSS" + .e RLIMIT_DATA,"DATA" + .e RLIMIT_CORE,"CORE" + .e RLIMIT_STACK,"STACK" + .e RLIMIT_SIGPENDING,"SIGPENDING" + .e RLIMIT_MEMLOCK,"MEMLOCK" + .e RLIMIT_LOCKS,"LOCKS" + .e RLIMIT_MSGQUEUE,"MSGQUEUE" + .e RLIMIT_NICE,"NICE" + .e RLIMIT_RTPRIO,"RTPRIO" + .e RLIMIT_RTTIME,"RTTIME" + .e RLIMIT_SWAP,"SWAP" + .e RLIMIT_SBSIZE,"SBSIZE" + .e RLIMIT_NPTS,"NPTS" + .long MAGNUM_TERMINATOR + .endobj kRlimitNames,globl,hidden + .overrun diff --git a/libc/intrin/nopl.h b/libc/intrin/nopl.h index 600fd2b02..85312506b 100644 --- a/libc/intrin/nopl.h +++ b/libc/intrin/nopl.h @@ -1,6 +1,7 @@ #ifndef COSMOPOLITAN_LIBC_INTRIN_NOPL_H_ #define COSMOPOLITAN_LIBC_INTRIN_NOPL_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) +#if !(__ASSEMBLER__ + __LINKER__ + 0) && defined(__GNUC__) && \ + !defined(__llvm__) && !defined(__chibicc__) && !defined(__STRICT_ANSI__) /** * @fileoverview Turns CALLs into NOPs that are fixupable at runtime. @@ -66,5 +67,5 @@ 0; \ }) -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* !ASSEMBLER && !LINKER && GNUC && !CHIBICC && !LLVM && !ANSI */ #endif /* COSMOPOLITAN_LIBC_INTRIN_NOPL_H_ */ diff --git a/libc/str/stpcpy.c b/libc/intrin/stpcpy.c similarity index 90% rename from libc/str/stpcpy.c rename to libc/intrin/stpcpy.c index 26808b692..144bebd47 100644 --- a/libc/str/stpcpy.c +++ b/libc/intrin/stpcpy.c @@ -16,18 +16,17 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pcmpeqb.h" -#include "libc/intrin/pmovmskb.h" #include "libc/str/str.h" +typedef char xmm_u __attribute__((__vector_size__(16), __aligned__(1))); +typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16))); + static inline noasan size_t stpcpy_sse2(char *d, const char *s, size_t i) { - uint8_t v1[16], v2[16], vz[16]; + xmm_t v, z = {0}; for (;;) { - __builtin_memset(vz, 0, 16); - __builtin_memcpy(v1, s + i, 16); - pcmpeqb(v2, v1, vz); - if (!pmovmskb(v2)) { - __builtin_memcpy(d + i, v1, 16); + v = *(xmm_t *)(s + i); + if (!__builtin_ia32_pmovmskb128(v == z)) { + *(xmm_u *)(d + i) = v; i += 16; } else { break; diff --git a/libc/str/strcpy.c b/libc/intrin/strcpy.c similarity index 87% rename from libc/str/strcpy.c rename to libc/intrin/strcpy.c index 73347dce8..eccdfb00f 100644 --- a/libc/str/strcpy.c +++ b/libc/intrin/strcpy.c @@ -16,18 +16,17 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pcmpeqb.h" -#include "libc/intrin/pmovmskb.h" #include "libc/str/str.h" -static noasan size_t strcpy_sse2(char *d, const char *s, size_t i) { - uint8_t v1[16], v2[16], vz[16]; +typedef char xmm_u __attribute__((__vector_size__(16), __aligned__(1))); +typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16))); + +static inline noasan size_t strcpy_sse2(char *d, const char *s, size_t i) { + xmm_t v, z = {0}; for (;;) { - __builtin_memset(vz, 0, 16); - __builtin_memcpy(v1, s + i, 16); - pcmpeqb(v2, v1, vz); - if (!pmovmskb(v2)) { - __builtin_memcpy(d + i, v1, 16); + v = *(xmm_t *)(s + i); + if (!__builtin_ia32_pmovmskb128(v == z)) { + *(xmm_u *)(d + i) = v; i += 16; } else { break; diff --git a/libc/intrin/ubsan.c b/libc/intrin/ubsan.c index ec357de0f..6917922c1 100644 --- a/libc/intrin/ubsan.c +++ b/libc/intrin/ubsan.c @@ -204,6 +204,15 @@ static void __ubsan_exit(void) { _Exit(99); } +static char *__ubsan_stpcpy(char *d, const char *s) { + size_t i; + for (i = 0;; ++i) { + if (!(d[i] = s[i])) { + return d + i; + } + } +} + dontdiscard static __ubsan_die_f *__ubsan_die(void) { if (weaken(__die)) { return weaken(__die); @@ -246,11 +255,11 @@ static char *__ubsan_describe_shift_out_of_bounds( char *p = buf; lhs = __ubsan_extend(info->lhs_type, lhs); rhs = __ubsan_extend(info->rhs_type, rhs); - p = __stpcpy(p, __ubsan_describe_shift(info, lhs, rhs)), *p++ = ' '; + p = __ubsan_stpcpy(p, __ubsan_describe_shift(info, lhs, rhs)), *p++ = ' '; p = __ubsan_itpcpy(p, info->lhs_type, lhs), *p++ = ' '; - p = __stpcpy(p, info->lhs_type->name), *p++ = ' '; + p = __ubsan_stpcpy(p, info->lhs_type->name), *p++ = ' '; p = __ubsan_itpcpy(p, info->rhs_type, rhs), *p++ = ' '; - p = __stpcpy(p, info->rhs_type->name); + p = __ubsan_stpcpy(p, info->rhs_type->name); return buf; } @@ -272,12 +281,12 @@ void __ubsan_handle_shift_out_of_bounds_abort( void __ubsan_handle_out_of_bounds(struct UbsanOutOfBoundsInfo *info, uintptr_t index) { char buf[512], *p = buf; - p = __stpcpy(p, info->index_type->name); - p = __stpcpy(p, " index "); + p = __ubsan_stpcpy(p, info->index_type->name); + p = __ubsan_stpcpy(p, " index "); p = __ubsan_itpcpy(p, info->index_type, index); - p = __stpcpy(p, " into "); - p = __stpcpy(p, info->array_type->name); - p = __stpcpy(p, " out of bounds"); + p = __ubsan_stpcpy(p, " into "); + p = __ubsan_stpcpy(p, info->array_type->name); + p = __ubsan_stpcpy(p, " out of bounds"); __ubsan_abort(&info->location, buf)(); __ubsan_unreachable(); } @@ -294,19 +303,19 @@ static __ubsan_die_f *__ubsan_type_mismatch_handler( if (!pointer) return __ubsan_abort(&info->location, "null pointer access"); kind = __ubsan_dubnul(kUbsanTypeCheckKinds, info->type_check_kind); if (info->alignment && (pointer & (info->alignment - 1))) { - p = __stpcpy(p, "unaligned "); - p = __stpcpy(p, kind), *p++ = ' '; - p = __stpcpy(p, info->type->name), *p++ = ' ', *p++ = '@'; + p = __ubsan_stpcpy(p, "unaligned "); + p = __ubsan_stpcpy(p, kind), *p++ = ' '; + p = __ubsan_stpcpy(p, info->type->name), *p++ = ' ', *p++ = '@'; p = __ubsan_itpcpy(p, info->type, pointer); - p = __stpcpy(p, " align "); + p = __ubsan_stpcpy(p, " align "); p = __intcpy(p, info->alignment); } else { - p = __stpcpy(p, "insufficient size "); - p = __stpcpy(p, kind); - p = __stpcpy(p, " address 0x"); + p = __ubsan_stpcpy(p, "insufficient size "); + p = __ubsan_stpcpy(p, kind); + p = __ubsan_stpcpy(p, " address 0x"); p = __fixcpy(p, pointer, sizeof(pointer) * CHAR_BIT); - p = __stpcpy(p, " with insufficient space for object of type "); - p = __stpcpy(p, info->type->name); + p = __ubsan_stpcpy(p, " with insufficient space for object of type "); + p = __ubsan_stpcpy(p, info->type->name); } return __ubsan_abort(&info->location, buf); } diff --git a/libc/intrin/x86gradenames.c b/libc/intrin/x86gradenames.c index 9fd730026..98d012df5 100644 --- a/libc/intrin/x86gradenames.c +++ b/libc/intrin/x86gradenames.c @@ -20,9 +20,14 @@ #include "tool/decode/lib/x86idnames.h" const struct IdName kX86GradeNames[] = { - {X86_GRADE_UNKNOWN, "Unknown"}, {X86_GRADE_APPLIANCE, "Appliance"}, - {X86_GRADE_MOBILE, "Mobile"}, {X86_GRADE_TABLET, "Tablet"}, - {X86_GRADE_DESKTOP, "Desktop"}, {X86_GRADE_CLIENT, "Client"}, - {X86_GRADE_DENSITY, "Density"}, {X86_GRADE_SERVER, "Server"}, - {X86_GRADE_SCIENCE, "Science"}, {0, 0}, + {X86_GRADE_UNKNOWN, "Unknown"}, // + {X86_GRADE_APPLIANCE, "Appliance"}, // + {X86_GRADE_MOBILE, "Mobile"}, // + {X86_GRADE_TABLET, "Tablet"}, // + {X86_GRADE_DESKTOP, "Desktop"}, // + {X86_GRADE_CLIENT, "Client"}, // + {X86_GRADE_DENSITY, "Density"}, // + {X86_GRADE_SERVER, "Server"}, // + {X86_GRADE_SCIENCE, "Science"}, // + {0}, // }; diff --git a/libc/intrin/x86marchnames.c b/libc/intrin/x86marchnames.c index 7a507797e..42b29fb45 100644 --- a/libc/intrin/x86marchnames.c +++ b/libc/intrin/x86marchnames.c @@ -20,27 +20,27 @@ #include "tool/decode/lib/x86idnames.h" const struct IdName kX86MarchNames[] = { - {X86_MARCH_UNKNOWN, "Unknown"}, - {X86_MARCH_CORE2, "Core 2"}, - {X86_MARCH_NEHALEM, "Nehalem"}, - {X86_MARCH_WESTMERE, "Westmere"}, - {X86_MARCH_SANDYBRIDGE, "Sandybridge"}, - {X86_MARCH_IVYBRIDGE, "Ivybridge"}, - {X86_MARCH_HASWELL, "Haswell"}, - {X86_MARCH_BROADWELL, "Broadwell"}, - {X86_MARCH_SKYLAKE, "Skylake"}, - {X86_MARCH_KABYLAKE, "Kabylake"}, - {X86_MARCH_CANNONLAKE, "Cannonlake"}, - {X86_MARCH_ICELAKE, "Icelake"}, - {X86_MARCH_TIGERLAKE, "Tigerlake"}, - {X86_MARCH_BONNELL, "Bonnell"}, - {X86_MARCH_SALTWELL, "Saltwell"}, - {X86_MARCH_SILVERMONT, "Silvermont"}, - {X86_MARCH_AIRMONT, "Airmont"}, - {X86_MARCH_GOLDMONT, "Goldmont"}, - {X86_MARCH_GOLDMONTPLUS, "Goldmont Plus"}, - {X86_MARCH_TREMONT, "Tremont"}, - {X86_MARCH_KNIGHTSLANDING, "Knights Landing"}, - {X86_MARCH_KNIGHTSMILL, "Knights Mill"}, - {0, 0}, + {X86_MARCH_UNKNOWN, "Unknown"}, // + {X86_MARCH_CORE2, "Core 2"}, // + {X86_MARCH_NEHALEM, "Nehalem"}, // + {X86_MARCH_WESTMERE, "Westmere"}, // + {X86_MARCH_SANDYBRIDGE, "Sandybridge"}, // + {X86_MARCH_IVYBRIDGE, "Ivybridge"}, // + {X86_MARCH_HASWELL, "Haswell"}, // + {X86_MARCH_BROADWELL, "Broadwell"}, // + {X86_MARCH_SKYLAKE, "Skylake"}, // + {X86_MARCH_KABYLAKE, "Kabylake"}, // + {X86_MARCH_CANNONLAKE, "Cannonlake"}, // + {X86_MARCH_ICELAKE, "Icelake"}, // + {X86_MARCH_TIGERLAKE, "Tigerlake"}, // + {X86_MARCH_BONNELL, "Bonnell"}, // + {X86_MARCH_SALTWELL, "Saltwell"}, // + {X86_MARCH_SILVERMONT, "Silvermont"}, // + {X86_MARCH_AIRMONT, "Airmont"}, // + {X86_MARCH_GOLDMONT, "Goldmont"}, // + {X86_MARCH_GOLDMONTPLUS, "Goldmont Plus"}, // + {X86_MARCH_TREMONT, "Tremont"}, // + {X86_MARCH_KNIGHTSLANDING, "Knights Landing"}, // + {X86_MARCH_KNIGHTSMILL, "Knights Mill"}, // + {0}, // }; diff --git a/libc/log/cxaprintexits.c b/libc/log/cxaprintexits.c index 54bae4ee2..f7659801d 100644 --- a/libc/log/cxaprintexits.c +++ b/libc/log/cxaprintexits.c @@ -17,9 +17,9 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/fmt/fmt.h" +#include "libc/intrin/cxaatexit.internal.h" #include "libc/log/log.h" #include "libc/nexgen32e/bsf.h" -#include "libc/runtime/cxaatexit.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" diff --git a/libc/runtime/memtrack.internal.h b/libc/runtime/memtrack.internal.h index 183ce51a7..f7d17bc77 100644 --- a/libc/runtime/memtrack.internal.h +++ b/libc/runtime/memtrack.internal.h @@ -72,7 +72,7 @@ void ReleaseMemoryNt(struct MemoryIntervals *, int, int) hidden; int UntrackMemoryIntervals(void *, size_t) hidden; size_t GetMemtrackSize(struct MemoryIntervals *); -#if defined(__GNUC__) && !defined(__llvm__) && !defined(__STRICT_ANSI__) +#ifdef _NOPL0 #define __mmi_lock() _NOPL0("__threadcalls", __mmi_lock) #define __mmi_unlock() _NOPL0("__threadcalls", __mmi_unlock) #else diff --git a/libc/runtime/printargs.c b/libc/runtime/printargs.c index 8b93874a5..18fe28317 100644 --- a/libc/runtime/printargs.c +++ b/libc/runtime/printargs.c @@ -294,7 +294,7 @@ textstartup void __printargs(const char *prologue) { PRINT("RESOURCE LIMITS"); for (i = 0; i < RLIM_NLIMITS; ++i) { if (!getrlimit(i, &rlim)) { - char buf[12]; + char buf[20]; if (rlim.rlim_cur == RLIM_INFINITY) rlim.rlim_cur = -1; if (rlim.rlim_max == RLIM_INFINITY) rlim.rlim_max = -1; PRINT(" ☼ %-20s %,16ld %,16ld", (DescribeRlimitName)(buf, i), diff --git a/libc/stdio/fflush.internal.h b/libc/stdio/fflush.internal.h index 78cd050c0..a00e504fb 100644 --- a/libc/stdio/fflush.internal.h +++ b/libc/stdio/fflush.internal.h @@ -21,7 +21,7 @@ hidden extern struct StdioFlush __fflush; void __fflush_lock(void); void __fflush_unlock(void); -#if defined(__GNUC__) && !defined(__llvm__) && !defined(__STRICT_ANSI__) +#ifdef _NOPL0 #define __fflush_lock() _NOPL0("__threadcalls", __fflush_lock) #define __fflush_unlock() _NOPL0("__threadcalls", __fflush_unlock) #else diff --git a/libc/stdio/stdio.h b/libc/stdio/stdio.h index c2699225c..3998bcee7 100644 --- a/libc/stdio/stdio.h +++ b/libc/stdio/stdio.h @@ -173,7 +173,7 @@ int vfprintf_unlocked(FILE *, const char *, va_list) #define putc_unlocked(c, f) fputc_unlocked(c, f) #define putwc_unlocked(c, f) fputwc_unlocked(c, f) -#if defined(__GNUC__) && !defined(__llvm__) && !defined(__STRICT_ANSI__) +#ifdef _NOPL1 #define flockfile(f) _NOPL1("__threadcalls", flockfile, f) #define funlockfile(f) _NOPL1("__threadcalls", funlockfile, f) #define ftrylockfile(f) _NOPL1("__threadcalls", ftrylockfile, f) diff --git a/libc/sysv/consts.sh b/libc/sysv/consts.sh index 658a5eee7..239bc38d3 100755 --- a/libc/sysv/consts.sh +++ b/libc/sysv/consts.sh @@ -2789,36 +2789,6 @@ syscon icmp6 ICMP6_ROUTER_RENUMBERING 138 138 138 138 138 0 # unix syscon icmp6 ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0100 0x0100 0x0100 0x0100 0x0100 0 # unix consensus syscon icmp6 ICMP6_RR_RESULT_FLAGS_OOB 0x0200 0x0200 0x0200 0x0200 0x0200 0 # unix consensus -# java's computational model -# solves the sharing problem by defining everything as shared -# -# group name GNU/Systemd XNU's Not UNIX! FreeBSD OpenBSD NetBSD The New Technology Commentary -syscon misc PTHREAD_MUTEX_STALLED 0 0 0 0 0 0 # consensus -syscon misc PTHREAD_PRIO_NONE 0 0 0 0 0 0 # consensus -syscon misc PTHREAD_PRIO_INHERIT 0 1 1 1 1 0 # bsd consensus -syscon misc PTHREAD_PRIO_PROTECT 0 2 2 2 2 0 # bsd consensus -syscon misc PTHREAD_DESTRUCTOR_ITERATIONS 4 4 4 4 4 0 # unix consensus -syscon misc PTHREAD_PROCESS_SHARED 1 1 1 1 1 0 # unix consensus -syscon misc PTHREAD_CREATE_DETACHED 1 2 1 1 1 0 -syscon misc PTHREAD_KEYS_MAX 0x0400 0x0200 0x0100 0x0100 0x0100 0 -syscon misc PTHREAD_STACK_MIN 0x4000 0x2000 0x0800 0x1000 0x1000 0 -syscon misc PTHREAD_BARRIER_SERIAL_THREAD -1 0 -1 -1 -1 0 -syscon misc PTHREAD_CANCEL_ASYNCHRONOUS 1 0 2 2 2 0 -syscon misc PTHREAD_CANCEL_DISABLE 1 0 1 1 1 0 -syscon misc PTHREAD_INHERIT_SCHED 0 1 4 4 4 0 -syscon misc PTHREAD_SCOPE_SYSTEM 0 1 2 2 2 0 -syscon misc PTHREAD_EXPLICIT_SCHED 1 2 0 0 0 0 -syscon misc PTHREAD_MUTEX_DEFAULT 0 0 1 4 4 0 -syscon misc PTHREAD_MUTEX_ERRORCHECK 0 1 0 1 1 0 -syscon misc PTHREAD_MUTEX_RECURSIVE 0 2 0 2 2 0 -syscon misc PTHREAD_SCOPE_PROCESS 1 2 0 0 0 0 -syscon misc PTHREAD_CANCEL_DEFERRED 0 2 0 0 0 0 -syscon misc PTHREAD_CANCEL_ENABLE 0 1 0 0 0 0 -syscon misc PTHREAD_CREATE_JOINABLE 0 1 0 0 0 0 -syscon misc PTHREAD_MUTEX_NORMAL 0 0 0 3 3 0 -syscon misc PTHREAD_MUTEX_ROBUST 0 0 1 0 0 0 -syscon misc PTHREAD_PROCESS_PRIVATE 0 2 0 0 0 0 - # man fanotify(7) syscon fan FAN_CLASS_NOTIF 0 0 0 0 0 0 # consensus syscon fan FAN_ACCESS 1 0 0 0 0 0 diff --git a/libc/sysv/consts/PTHREAD_BARRIER_SERIAL_THREAD.S b/libc/sysv/consts/PTHREAD_BARRIER_SERIAL_THREAD.S deleted file mode 100644 index f67a3f1b1..000000000 --- a/libc/sysv/consts/PTHREAD_BARRIER_SERIAL_THREAD.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon misc,PTHREAD_BARRIER_SERIAL_THREAD,-1,0,-1,-1,-1,0 diff --git a/libc/sysv/consts/PTHREAD_CANCEL_ASYNCHRONOUS.S b/libc/sysv/consts/PTHREAD_CANCEL_ASYNCHRONOUS.S deleted file mode 100644 index 5b17c407c..000000000 --- a/libc/sysv/consts/PTHREAD_CANCEL_ASYNCHRONOUS.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon misc,PTHREAD_CANCEL_ASYNCHRONOUS,1,0,2,2,2,0 diff --git a/libc/sysv/consts/PTHREAD_CANCEL_DEFERRED.S b/libc/sysv/consts/PTHREAD_CANCEL_DEFERRED.S deleted file mode 100644 index 4b9377263..000000000 --- a/libc/sysv/consts/PTHREAD_CANCEL_DEFERRED.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon misc,PTHREAD_CANCEL_DEFERRED,0,2,0,0,0,0 diff --git a/libc/sysv/consts/PTHREAD_CANCEL_DISABLE.S b/libc/sysv/consts/PTHREAD_CANCEL_DISABLE.S deleted file mode 100644 index ab090e4f5..000000000 --- a/libc/sysv/consts/PTHREAD_CANCEL_DISABLE.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon misc,PTHREAD_CANCEL_DISABLE,1,0,1,1,1,0 diff --git a/libc/sysv/consts/PTHREAD_CANCEL_ENABLE.S b/libc/sysv/consts/PTHREAD_CANCEL_ENABLE.S deleted file mode 100644 index c38d1778d..000000000 --- a/libc/sysv/consts/PTHREAD_CANCEL_ENABLE.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon misc,PTHREAD_CANCEL_ENABLE,0,1,0,0,0,0 diff --git a/libc/sysv/consts/PTHREAD_CREATE_DETACHED.S b/libc/sysv/consts/PTHREAD_CREATE_DETACHED.S deleted file mode 100644 index 0c83a7e79..000000000 --- a/libc/sysv/consts/PTHREAD_CREATE_DETACHED.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon misc,PTHREAD_CREATE_DETACHED,1,2,1,1,1,0 diff --git a/libc/sysv/consts/PTHREAD_CREATE_JOINABLE.S b/libc/sysv/consts/PTHREAD_CREATE_JOINABLE.S deleted file mode 100644 index e7498b24e..000000000 --- a/libc/sysv/consts/PTHREAD_CREATE_JOINABLE.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon misc,PTHREAD_CREATE_JOINABLE,0,1,0,0,0,0 diff --git a/libc/sysv/consts/PTHREAD_DESTRUCTOR_ITERATIONS.S b/libc/sysv/consts/PTHREAD_DESTRUCTOR_ITERATIONS.S deleted file mode 100644 index 47c4d50a8..000000000 --- a/libc/sysv/consts/PTHREAD_DESTRUCTOR_ITERATIONS.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon misc,PTHREAD_DESTRUCTOR_ITERATIONS,4,4,4,4,4,0 diff --git a/libc/sysv/consts/PTHREAD_EXPLICIT_SCHED.S b/libc/sysv/consts/PTHREAD_EXPLICIT_SCHED.S deleted file mode 100644 index 55f4f19b0..000000000 --- a/libc/sysv/consts/PTHREAD_EXPLICIT_SCHED.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon misc,PTHREAD_EXPLICIT_SCHED,1,2,0,0,0,0 diff --git a/libc/sysv/consts/PTHREAD_INHERIT_SCHED.S b/libc/sysv/consts/PTHREAD_INHERIT_SCHED.S deleted file mode 100644 index b14177617..000000000 --- a/libc/sysv/consts/PTHREAD_INHERIT_SCHED.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon misc,PTHREAD_INHERIT_SCHED,0,1,4,4,4,0 diff --git a/libc/sysv/consts/PTHREAD_KEYS_MAX.S b/libc/sysv/consts/PTHREAD_KEYS_MAX.S deleted file mode 100644 index 8ede0fc8f..000000000 --- a/libc/sysv/consts/PTHREAD_KEYS_MAX.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon misc,PTHREAD_KEYS_MAX,0x0400,0x0200,0x0100,0x0100,0x0100,0 diff --git a/libc/sysv/consts/PTHREAD_MUTEX_DEFAULT.S b/libc/sysv/consts/PTHREAD_MUTEX_DEFAULT.S deleted file mode 100644 index f4dd0a2db..000000000 --- a/libc/sysv/consts/PTHREAD_MUTEX_DEFAULT.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon misc,PTHREAD_MUTEX_DEFAULT,0,0,1,4,4,0 diff --git a/libc/sysv/consts/PTHREAD_MUTEX_ERRORCHECK.S b/libc/sysv/consts/PTHREAD_MUTEX_ERRORCHECK.S deleted file mode 100644 index 4f41faf04..000000000 --- a/libc/sysv/consts/PTHREAD_MUTEX_ERRORCHECK.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon misc,PTHREAD_MUTEX_ERRORCHECK,0,1,0,1,1,0 diff --git a/libc/sysv/consts/PTHREAD_MUTEX_NORMAL.S b/libc/sysv/consts/PTHREAD_MUTEX_NORMAL.S deleted file mode 100644 index 4c6431cb6..000000000 --- a/libc/sysv/consts/PTHREAD_MUTEX_NORMAL.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon misc,PTHREAD_MUTEX_NORMAL,0,0,0,3,3,0 diff --git a/libc/sysv/consts/PTHREAD_MUTEX_RECURSIVE.S b/libc/sysv/consts/PTHREAD_MUTEX_RECURSIVE.S deleted file mode 100644 index b92773860..000000000 --- a/libc/sysv/consts/PTHREAD_MUTEX_RECURSIVE.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon misc,PTHREAD_MUTEX_RECURSIVE,0,2,0,2,2,0 diff --git a/libc/sysv/consts/PTHREAD_MUTEX_ROBUST.S b/libc/sysv/consts/PTHREAD_MUTEX_ROBUST.S deleted file mode 100644 index 8f5ad859a..000000000 --- a/libc/sysv/consts/PTHREAD_MUTEX_ROBUST.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon misc,PTHREAD_MUTEX_ROBUST,0,0,1,0,0,0 diff --git a/libc/sysv/consts/PTHREAD_MUTEX_STALLED.S b/libc/sysv/consts/PTHREAD_MUTEX_STALLED.S deleted file mode 100644 index 606087973..000000000 --- a/libc/sysv/consts/PTHREAD_MUTEX_STALLED.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon misc,PTHREAD_MUTEX_STALLED,0,0,0,0,0,0 diff --git a/libc/sysv/consts/PTHREAD_PRIO_INHERIT.S b/libc/sysv/consts/PTHREAD_PRIO_INHERIT.S deleted file mode 100644 index 488f01fb4..000000000 --- a/libc/sysv/consts/PTHREAD_PRIO_INHERIT.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon misc,PTHREAD_PRIO_INHERIT,0,1,1,1,1,0 diff --git a/libc/sysv/consts/PTHREAD_PRIO_NONE.S b/libc/sysv/consts/PTHREAD_PRIO_NONE.S deleted file mode 100644 index 3431c1e88..000000000 --- a/libc/sysv/consts/PTHREAD_PRIO_NONE.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon misc,PTHREAD_PRIO_NONE,0,0,0,0,0,0 diff --git a/libc/sysv/consts/PTHREAD_PRIO_PROTECT.S b/libc/sysv/consts/PTHREAD_PRIO_PROTECT.S deleted file mode 100644 index 9ce2c81cf..000000000 --- a/libc/sysv/consts/PTHREAD_PRIO_PROTECT.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon misc,PTHREAD_PRIO_PROTECT,0,2,2,2,2,0 diff --git a/libc/sysv/consts/PTHREAD_PROCESS_PRIVATE.S b/libc/sysv/consts/PTHREAD_PROCESS_PRIVATE.S deleted file mode 100644 index f9d71e1d2..000000000 --- a/libc/sysv/consts/PTHREAD_PROCESS_PRIVATE.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon misc,PTHREAD_PROCESS_PRIVATE,0,2,0,0,0,0 diff --git a/libc/sysv/consts/PTHREAD_PROCESS_SHARED.S b/libc/sysv/consts/PTHREAD_PROCESS_SHARED.S deleted file mode 100644 index b1d40da34..000000000 --- a/libc/sysv/consts/PTHREAD_PROCESS_SHARED.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon misc,PTHREAD_PROCESS_SHARED,1,1,1,1,1,0 diff --git a/libc/sysv/consts/PTHREAD_SCOPE_PROCESS.S b/libc/sysv/consts/PTHREAD_SCOPE_PROCESS.S deleted file mode 100644 index d240adf0e..000000000 --- a/libc/sysv/consts/PTHREAD_SCOPE_PROCESS.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon misc,PTHREAD_SCOPE_PROCESS,1,2,0,0,0,0 diff --git a/libc/sysv/consts/PTHREAD_SCOPE_SYSTEM.S b/libc/sysv/consts/PTHREAD_SCOPE_SYSTEM.S deleted file mode 100644 index 30238cab9..000000000 --- a/libc/sysv/consts/PTHREAD_SCOPE_SYSTEM.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon misc,PTHREAD_SCOPE_SYSTEM,0,1,2,2,2,0 diff --git a/libc/sysv/consts/PTHREAD_STACK_MIN.S b/libc/sysv/consts/PTHREAD_STACK_MIN.S deleted file mode 100644 index 891bf11ba..000000000 --- a/libc/sysv/consts/PTHREAD_STACK_MIN.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon misc,PTHREAD_STACK_MIN,0x4000,0x2000,0x0800,0x1000,0x1000,0 diff --git a/libc/thread/wait.c b/libc/thread/wait.c index 567839695..756cd7d1a 100644 --- a/libc/thread/wait.c +++ b/libc/thread/wait.c @@ -26,7 +26,7 @@ int cthread_memory_wait32(int* addr, int val, const struct timespec* timeout) { size_t size; - if (IsLinux() || IsOpenbsd()) { + if (IsLinux() /* || IsOpenbsd() */) { return _futex_wait(addr, val, timeout); } else { return sched_yield(); @@ -34,7 +34,7 @@ int cthread_memory_wait32(int* addr, int val, const struct timespec* timeout) { } int cthread_memory_wake32(int* addr, int n) { - if (IsLinux() || IsOpenbsd()) { + if (IsLinux() /* || IsOpenbsd() */) { return _futex_wake(addr, n); } else { return 0; diff --git a/libc/time/localtime.c b/libc/time/localtime.c index 008effdc5..ad7ecd568 100644 --- a/libc/time/localtime.c +++ b/libc/time/localtime.c @@ -56,7 +56,7 @@ void localtime_unlock(void) { pthread_mutex_unlock(&locallock); } -#if defined(__GNUC__) && !defined(__llvm__) && !defined(__STRICT_ANSI__) +#ifdef _NOPL0 #define localtime_lock() _NOPL0("__threadcalls", localtime_lock) #define localtime_unlock() _NOPL0("__threadcalls", localtime_unlock) #else diff --git a/libc/zipos/zipos.internal.h b/libc/zipos/zipos.internal.h index 035b17355..6fb612e6a 100644 --- a/libc/zipos/zipos.internal.h +++ b/libc/zipos/zipos.internal.h @@ -49,7 +49,7 @@ int64_t __zipos_lseek(struct ZiposHandle *, int64_t, unsigned) hidden; int __zipos_fcntl(int, int, uintptr_t) hidden; int __zipos_notat(int, const char *) hidden; -#if defined(__GNUC__) && !defined(__llvm__) && !defined(__STRICT_ANSI__) +#ifdef _NOPL0 #define __zipos_lock() _NOPL0("__threadcalls", __zipos_lock) #define __zipos_unlock() _NOPL0("__threadcalls", __zipos_unlock) #else diff --git a/test/libc/mem/malloc_test.c b/test/libc/mem/malloc_test.c index 835c7bae9..5471c08ca 100644 --- a/test/libc/mem/malloc_test.c +++ b/test/libc/mem/malloc_test.c @@ -21,11 +21,11 @@ #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/dce.h" +#include "libc/intrin/cxaatexit.internal.h" #include "libc/intrin/kprintf.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" #include "libc/rand/rand.h" -#include "libc/runtime/cxaatexit.internal.h" #include "libc/runtime/gc.internal.h" #include "libc/runtime/memtrack.internal.h" #include "libc/runtime/runtime.h" diff --git a/third_party/chibicc/as.c b/third_party/chibicc/as.c index bb36992bc..aee654401 100644 --- a/third_party/chibicc/as.c +++ b/third_party/chibicc/as.c @@ -1653,7 +1653,8 @@ static int SymbolType(struct As *a, struct Slice s) { } } -static int GrabSection(struct As *a, int name, int flags, int type) { +static int GrabSection(struct As *a, int name, int flags, int type, int group, + int comdat) { int i; for (i = 0; i < a->sections.n; ++i) { if (!strcmp(a->strings.p[name], a->strings.p[a->sections.p[i].name])) { @@ -1664,7 +1665,7 @@ static int GrabSection(struct As *a, int name, int flags, int type) { } static void OnSection(struct As *a, struct Slice s) { - int name, flags, type; + int name, flags, type, group = -1, comdat = -1; name = SliceDup(a, GetSlice(a)); if (startswith(a->strings.p[name], ".text")) { flags = SHF_ALLOC | SHF_EXECINSTR; @@ -1685,9 +1686,17 @@ static void OnSection(struct As *a, struct Slice s) { if (IsComma(a)) { ++a->i; type = SectionType(a, GetSlice(a)); + if (IsComma(a)) { + ++a->i; + group = SectionType(a, GetSlice(a)); + if (IsComma(a)) { + ++a->i; + comdat = SectionType(a, GetSlice(a)); + } + } } } - SetSection(a, GrabSection(a, name, flags, type)); + SetSection(a, GrabSection(a, name, flags, type, group, comdat)); } static void OnPushsection(struct As *a, struct Slice s) { @@ -1705,7 +1714,7 @@ static void OnIdent(struct As *a, struct Slice s) { struct Slice arg; int comment, oldsection; comment = GrabSection(a, StrDup(a, ".comment"), SHF_MERGE | SHF_STRINGS, - SHT_PROGBITS); + SHT_PROGBITS, -1, -1); oldsection = a->section; a->section = comment; arg = GetSlice(a); diff --git a/third_party/gdtoa/lock.h b/third_party/gdtoa/lock.h index 83095ae05..e3b281f0c 100644 --- a/third_party/gdtoa/lock.h +++ b/third_party/gdtoa/lock.h @@ -10,7 +10,7 @@ int __gdtoa_unlock(void); int __gdtoa_lock1(void); int __gdtoa_unlock1(void); -#if defined(__GNUC__) && !defined(__llvm__) && !defined(__STRICT_ANSI__) +#ifdef _NOPL0 #define __gdtoa_lock() _NOPL0("__threadcalls", __gdtoa_lock) #define __gdtoa_unlock() _NOPL0("__threadcalls", __gdtoa_unlock) #define __gdtoa_lock1() _NOPL0("__threadcalls", __gdtoa_lock1) diff --git a/third_party/sqlite3/sqliteInt.inc b/third_party/sqlite3/sqliteInt.inc index 092529e43..5a2aee3a4 100644 --- a/third_party/sqlite3/sqliteInt.inc +++ b/third_party/sqlite3/sqliteInt.inc @@ -144,7 +144,7 @@ /* ** Macro to disable warnings about missing "break" at the end of a "case". */ -#if GCC_VERSION>=7000000 +#if GCC_VERSION>=7000000 && !defined(__chibicc__) # define deliberate_fall_through __attribute__((fallthrough)); #else # define deliberate_fall_through diff --git a/tool/decode/elf.c b/tool/decode/elf.c index 82262c124..0c29166c9 100644 --- a/tool/decode/elf.c +++ b/tool/decode/elf.c @@ -16,9 +16,11 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/bits/bits.h" #include "libc/bits/safemacros.internal.h" #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" +#include "libc/elf/def.h" #include "libc/elf/elf.h" #include "libc/elf/struct/rela.h" #include "libc/elf/struct/shdr.h" @@ -177,6 +179,42 @@ static void printelfsectionheaders(void) { } } +static void printelfgroups(void) { + for (int i = 0; i < elf->e_shnum; ++i) { + Elf64_Shdr *shdr = GetElfSectionHeaderAddress(elf, st->st_size, i); + if (shdr->sh_type == SHT_GROUP) { + const Elf64_Shdr *symhdr = + GetElfSectionHeaderAddress(elf, st->st_size, shdr->sh_link); + const Elf64_Shdr *strhdr = + GetElfSectionHeaderAddress(elf, st->st_size, symhdr->sh_link); + Elf64_Sym *syms = GetElfSectionAddress(elf, st->st_size, symhdr); + char *strs = GetElfSectionAddress(elf, st->st_size, strhdr); + printf("\n"); + printf("//\t%s group\n", + GetElfString(elf, st->st_size, strs, syms[shdr->sh_info].st_name)); + printf("\t.org\t%#x\n", shdr->sh_offset); + bool first = true; + for (char *p = (char *)elf + shdr->sh_offset; + p < (char *)elf + shdr->sh_offset + shdr->sh_size; p += 4) { + if (first) { + first = false; + if (READ32LE(p) == GRP_COMDAT) { + printf("\t.long\tGRP_COMDAT\n"); + continue; + } + } + const Elf64_Shdr *section = + GetElfSectionHeaderAddress(elf, st->st_size, READ32LE(p)); + printf("\t.long\t%#x\t\t\t# %s\n", READ32LE(p), + GetElfString(elf, st->st_size, + GetElfSectionNameStringTable(elf, st->st_size), + section->sh_name)); + } + shdr->sh_offset; + } + } +} + static void printelfsymbolinfo(Elf64_Sym *sym) { int bind = (sym->st_info >> 4) & 0xf; const char *bindname = findnamebyid(kElfSymbolBindNames, bind); @@ -346,6 +384,7 @@ int main(int argc, char *argv[]) { printelfehdr(); printelfsegmentheaders(); printelfsectionheaders(); + printelfgroups(); printelfrelocations(); printelfsymboltable(); printelfdynsymboltable();