diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c558453d5..4b0798a0b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - mode: ["", tiny, rel, tinylinux, optlinux] + mode: ["", tiny, rel, nox87, aarch64, tinylinux, optlinux] steps: - uses: actions/checkout@v3 diff --git a/ape/ape.mk b/ape/ape.mk index 5d575aa38..8e8b2d1d0 100644 --- a/ape/ape.mk +++ b/ape/ape.mk @@ -86,6 +86,7 @@ APE_LOADER_FLAGS = \ -Os \ -ffreestanding \ -mgeneral-regs-only \ + -fno-stack-protector \ -fno-ident \ -fno-gnu-unique \ -c \ diff --git a/build/bootstrap/compile.com b/build/bootstrap/compile.com index 701b7570f..4bf5e30aa 100755 Binary files a/build/bootstrap/compile.com and b/build/bootstrap/compile.com differ diff --git a/build/config.mk b/build/config.mk index e19599baf..f36b6bb87 100644 --- a/build/config.mk +++ b/build/config.mk @@ -92,7 +92,6 @@ endif # - Turns off support for other operating systems # ifeq ($(MODE), optlinux) -ENABLE_FTRACE = 1 CONFIG_OFLAGS ?= -g CONFIG_CPPFLAGS += -DNDEBUG -DSYSDEBUG -DSUPPORT_VECTOR=1 CONFIG_CCFLAGS += -O3 -fmerge-all-constants @@ -388,7 +387,15 @@ TARGET_ARCH ?= -msse3 endif # LLVM Mode +# +# We aim to support: +# +# make -j8 m=llvm o/llvm/libc +# +# The rest of the monorepo may not work with llvm. +# ifeq ($(MODE), llvm) +.STRICT = 0 TARGET_ARCH ?= -msse3 CONFIG_CCFLAGS += $(BACKTRACES) -DSYSDEBUG -O2 AS = clang diff --git a/dsp/core/alaw.c b/dsp/core/alaw.c index de12c1d19..38fbf0f2f 100644 --- a/dsp/core/alaw.c +++ b/dsp/core/alaw.c @@ -26,7 +26,7 @@ * @see ITU G.711 */ int alaw(int x) { - int a, b, e, i; + int a, b, i; if ((a = x) < 0) a = ~a; a >>= 4; if (a > 15) { @@ -36,7 +36,6 @@ int alaw(int x) { a -= 16; a += (b + 1) << 4; } else { - e = 1; a -= 16; a += 16; } diff --git a/libc/calls/calls.mk b/libc/calls/calls.mk index d640c0be9..aa55d3b34 100644 --- a/libc/calls/calls.mk +++ b/libc/calls/calls.mk @@ -191,7 +191,8 @@ o/$(MODE)/libc/calls/pledge-linux.o \ o/$(MODE)/libc/calls/siginfo2cosmo.o: private \ CFLAGS += \ -ffreestanding \ - -fno-sanitize=all + -fno-sanitize=all \ + -fno-stack-protector o/$(MODE)/libc/calls/pledge-linux.o \ o/$(MODE)/libc/calls/unveil.o: private \ diff --git a/libc/calls/interrupts-nt.c b/libc/calls/interrupts-nt.c index e1a276168..147c089e6 100644 --- a/libc/calls/interrupts-nt.c +++ b/libc/calls/interrupts-nt.c @@ -23,6 +23,7 @@ #include "libc/calls/state.internal.h" #include "libc/calls/struct/fd.internal.h" #include "libc/calls/struct/sigaction.h" +#include "libc/calls/struct/sigaction.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/dce.h" #include "libc/errno.h" diff --git a/libc/calls/ioctl_siocgifconf.c b/libc/calls/ioctl_siocgifconf.c index d54acd1ba..cfa89e6a3 100644 --- a/libc/calls/ioctl_siocgifconf.c +++ b/libc/calls/ioctl_siocgifconf.c @@ -59,7 +59,6 @@ static int ioctl_siocgifconf_sysv(int fd, struct ifconf *ifc) { char *b, *p, *e; char ifcBsd[16]; struct ifreq *req; - struct ifreq *end; uint32_t bufLen, ip; size_t numReq, bufMax; if (IsLinux()) return sys_ioctl(fd, SIOCGIFCONF, ifc); @@ -77,7 +76,6 @@ static int ioctl_siocgifconf_sysv(int fd, struct ifconf *ifc) { */ memcpy(&bufLen, b, 4); req = ifc->ifc_req; - end = req + ifc->ifc_len / sizeof(*req); for (p = b, e = p + MIN(bufMax, READ32LE(ifcBsd)); p + 16 + 16 <= e; p += IsBsd() ? 16 + MAX(16, p[16] & 255) : 40) { fam = p[IsBsd() ? 17 : 16] & 255; diff --git a/libc/calls/pause-nt.c b/libc/calls/pause-nt.c index b30d032fe..b1b7d2300 100644 --- a/libc/calls/pause-nt.c +++ b/libc/calls/pause-nt.c @@ -26,9 +26,6 @@ #include "libc/sysv/errfuns.h" textwindows int sys_pause_nt(void) { - long ms, totoms; - ms = 0; - totoms = 0; for (;;) { if (_check_interrupts(false, g_fds.p)) { @@ -40,7 +37,8 @@ textwindows int sys_pause_nt(void) { continue; } -#if defined(SYSDEBUG) && defined(_POLLTRACE) +#if defined(SYSDEBUG) && _POLLTRACE + long ms = 0, totoms = 0; ms += __SIG_POLLING_INTERVAL_MS; if (ms >= __SIG_LOGGING_INTERVAL_MS) { totoms += ms, ms = 0; diff --git a/libc/calls/pledge-linux.c b/libc/calls/pledge-linux.c index a7dc77bf6..eaa98abcf 100644 --- a/libc/calls/pledge-linux.c +++ b/libc/calls/pledge-linux.c @@ -25,6 +25,7 @@ #include "libc/calls/struct/seccomp.internal.h" #include "libc/calls/struct/sigaction.h" #include "libc/calls/syscall_support-sysv.internal.h" +#include "libc/calls/ucontext.h" #include "libc/intrin/bsr.h" #include "libc/intrin/likely.h" #include "libc/intrin/promises.internal.h" diff --git a/libc/calls/sigaction.c b/libc/calls/sigaction.c index 30f0025a7..35920dc58 100644 --- a/libc/calls/sigaction.c +++ b/libc/calls/sigaction.c @@ -24,6 +24,7 @@ #include "libc/calls/internal.h" #include "libc/calls/sig.internal.h" #include "libc/calls/state.internal.h" +#include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/sigaction.internal.h" #include "libc/calls/struct/siginfo.internal.h" #include "libc/calls/struct/sigset.h" @@ -53,6 +54,12 @@ STATIC_YOINK("strsignal"); // for kprintf() #endif +#if SupportsWindows() +STATIC_YOINK("_init_onntconsoleevent"); +STATIC_YOINK("_check_sigwinch"); +STATIC_YOINK("_init_wincrash"); +#endif + #define SA_RESTORER 0x04000000 static void sigaction_cosmo2native(union metasigaction *sa) { diff --git a/libc/calls/sigenter-netbsd.c b/libc/calls/sigenter-netbsd.c index 17c3e003a..b52f19e95 100644 --- a/libc/calls/sigenter-netbsd.c +++ b/libc/calls/sigenter-netbsd.c @@ -74,7 +74,8 @@ privileged void __sigenter_netbsd(int sig, struct siginfo_netbsd *si, uc.uc_mcontext.err = ctx->uc_mcontext.err; uc.uc_mcontext.rip = ctx->uc_mcontext.rip; uc.uc_mcontext.rsp = ctx->uc_mcontext.rsp; - *uc.uc_mcontext.fpregs = ctx->uc_mcontext.__fpregs; + __repmovsb(uc.uc_mcontext.fpregs, &ctx->uc_mcontext.__fpregs, + sizeof(ctx->uc_mcontext.__fpregs)); ((sigaction_f)(__executable_start + rva))(sig, &si2, &uc); ctx->uc_stack.ss_sp = uc.uc_stack.ss_sp; ctx->uc_stack.ss_size = uc.uc_stack.ss_size; @@ -102,7 +103,8 @@ privileged void __sigenter_netbsd(int sig, struct siginfo_netbsd *si, ctx->uc_mcontext.err = uc.uc_mcontext.err; ctx->uc_mcontext.rip = uc.uc_mcontext.rip; ctx->uc_mcontext.rsp = uc.uc_mcontext.rsp; - ctx->uc_mcontext.__fpregs = *uc.uc_mcontext.fpregs; + __repmovsb(&ctx->uc_mcontext.__fpregs, uc.uc_mcontext.fpregs, + sizeof(ctx->uc_mcontext.__fpregs)); } } /* diff --git a/libc/calls/sigenter-openbsd.c b/libc/calls/sigenter-openbsd.c index 27c758670..6e0318919 100644 --- a/libc/calls/sigenter-openbsd.c +++ b/libc/calls/sigenter-openbsd.c @@ -74,7 +74,8 @@ privileged void __sigenter_openbsd(int sig, struct siginfo_openbsd *openbsdinfo, g.uc.uc_mcontext.rip = ctx->sc_rip; g.uc.uc_mcontext.rsp = ctx->sc_rsp; if (ctx->sc_fpstate) { - *g.uc.uc_mcontext.fpregs = *ctx->sc_fpstate; + __repmovsb(g.uc.uc_mcontext.fpregs, ctx->sc_fpstate, + sizeof(*ctx->sc_fpstate)); } ((sigaction_f)(__executable_start + rva))(sig, &g.si, &g.uc); ctx->sc_mask = g.uc.uc_sigmask.__bits[0]; @@ -100,7 +101,8 @@ privileged void __sigenter_openbsd(int sig, struct siginfo_openbsd *openbsdinfo, ctx->sc_rip = g.uc.uc_mcontext.rip; ctx->sc_rsp = g.uc.uc_mcontext.rsp; if (ctx->sc_fpstate) { - *ctx->sc_fpstate = *g.uc.uc_mcontext.fpregs; + __repmovsb(ctx->sc_fpstate, g.uc.uc_mcontext.fpregs, + sizeof(*ctx->sc_fpstate)); } } } diff --git a/libc/calls/sigignore.c b/libc/calls/sigignore.c index 2bfba2902..c8a7b3ee4 100644 --- a/libc/calls/sigignore.c +++ b/libc/calls/sigignore.c @@ -27,5 +27,5 @@ int sigignore(int sig) { struct sigaction sa; bzero(&sa, sizeof(sa)); sa.sa_handler = SIG_IGN; - return (sigaction)(sig, &sa, 0); + return sigaction(sig, &sa, 0); } diff --git a/libc/calls/siginfo2cosmo.c b/libc/calls/siginfo2cosmo.c index 30e621918..e3aa6ab9a 100644 --- a/libc/calls/siginfo2cosmo.c +++ b/libc/calls/siginfo2cosmo.c @@ -96,6 +96,8 @@ privileged void __siginfo2cosmo(struct siginfo *si, si_signo == SIGBUS || // si_signo == SIGTRAP) { si->si_addr = si_addr; + } else if (si_signo == SIGCHLD) { + si->si_status = si_status; } else if (si_signo == SIGALRM) { si->si_timerid = si_timerid; si->si_overrun = si_overrun; diff --git a/libc/calls/signal.c b/libc/calls/signal.c index a006e109d..b2785bc6e 100644 --- a/libc/calls/signal.c +++ b/libc/calls/signal.c @@ -30,9 +30,9 @@ * @note this function has BSD semantics, i.e. SA_RESTART * @see sigaction() which has more features and docs */ -sighandler_t(signal)(int sig, sighandler_t func) { +sighandler_t signal(int sig, sighandler_t func) { struct sigaction old, sa = {.sa_handler = func, .sa_flags = SA_RESTART}; - if ((sigaction)(sig, &sa, &old) != -1) { + if (sigaction(sig, &sa, &old) != -1) { return old.sa_handler; } else { return SIG_ERR; diff --git a/libc/calls/sigsuspend.c b/libc/calls/sigsuspend.c index 872b6d267..82457d0a5 100644 --- a/libc/calls/sigsuspend.c +++ b/libc/calls/sigsuspend.c @@ -47,7 +47,6 @@ */ int sigsuspend(const sigset_t *ignore) { int rc; - long ms, totoms; sigset_t save, *arg, mask = {0}; STRACE("sigsuspend(%s) → ...", DescribeSigset(0, ignore)); BEGIN_CANCELLATION_POINT; @@ -73,8 +72,10 @@ int sigsuspend(const sigset_t *ignore) { rc = sys_sigsuspend(arg, 8); } else { __sig_mask(SIG_SETMASK, arg, &save); - ms = 0; - totoms = 0; +#if defined(SYSDEBUG) && _POLLTRACE + long ms = 0; + long totoms = 0; +#endif do { if ((rc = _check_interrupts(false, g_fds.p))) { break; @@ -83,7 +84,7 @@ int sigsuspend(const sigset_t *ignore) { POLLTRACE("IOCP EINTR"); continue; } -#if defined(SYSDEBUG) && defined(_POLLTRACE) +#if defined(SYSDEBUG) && _POLLTRACE ms += __SIG_POLLING_INTERVAL_MS; if (ms >= __SIG_LOGGING_INTERVAL_MS) { totoms += ms, ms = 0; diff --git a/libc/calls/sigwinch-nt.c b/libc/calls/sigwinch-nt.c index b1d6ec731..5361e1b89 100644 --- a/libc/calls/sigwinch-nt.c +++ b/libc/calls/sigwinch-nt.c @@ -31,7 +31,6 @@ #include "libc/sysv/consts/sicode.h" #include "libc/sysv/consts/sig.h" #include "libc/thread/tls.h" - #ifdef __x86_64__ static struct winsize __ws; diff --git a/libc/calls/statfs2cosmo.c b/libc/calls/statfs2cosmo.c index 729fd7fc7..084417657 100644 --- a/libc/calls/statfs2cosmo.c +++ b/libc/calls/statfs2cosmo.c @@ -299,5 +299,6 @@ void statfs2cosmo(struct statfs *f, const union statfs_meta *m) { f->f_namelen = f_namelen; f->f_frsize = f_frsize; f->f_flags = f_flags; + f->f_owner = f_owner; memcpy(f->f_fstypename, f_fstypename, 16); } diff --git a/libc/calls/struct/sigaction.h b/libc/calls/struct/sigaction.h index b3105782d..552e21b47 100644 --- a/libc/calls/struct/sigaction.h +++ b/libc/calls/struct/sigaction.h @@ -2,15 +2,11 @@ #define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_H_ #include "libc/calls/struct/siginfo.h" #include "libc/calls/struct/sigset.h" -#include "libc/calls/ucontext.h" -#include "libc/dce.h" -#include "libc/sysv/consts/sig.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ typedef void (*sighandler_t)(int); -typedef void (*sigaction_f)(int, struct siginfo *, - void * /*struct ucontext **/); +typedef void (*sigaction_f)(int, struct siginfo *, void *); struct sigaction { /* cosmo abi */ union { @@ -25,60 +21,6 @@ struct sigaction { /* cosmo abi */ sighandler_t signal(int, sighandler_t); int sigaction(int, const struct sigaction *, struct sigaction *); -#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(COSMO) - -void _init_onntconsoleevent(void); -void _init_wincrash(void); -void _check_sigwinch(); - -#ifndef __SIGACTION_YOINK -#define __SIGACTION_YOINK(SIG) \ - do { \ - if (SupportsWindows()) { \ - if (__builtin_constant_p(SIG)) { \ - switch (SIG) { \ - case SIGINT: \ - case SIGQUIT: \ - case SIGHUP: \ - case SIGTERM: \ - YOINK(_init_onntconsoleevent); \ - break; \ - case SIGTRAP: \ - case SIGILL: \ - case SIGSEGV: \ - case SIGABRT: \ - case SIGFPE: \ - YOINK(_init_wincrash); \ - break; \ - case SIGWINCH: \ - YOINK(_check_sigwinch); \ - break; \ - default: \ - break; \ - } \ - } else { \ - YOINK(_init_onntconsoleevent); \ - YOINK(_init_wincrash); \ - YOINK(_check_sigwinch); \ - } \ - } \ - } while (0) -#endif - -#define sigaction(SIG, ACT, OLD) \ - ({ \ - __SIGACTION_YOINK(SIG); \ - sigaction(SIG, (ACT), OLD); \ - }) - -#define signal(SIG, HAND) \ - ({ \ - __SIGACTION_YOINK(SIG); \ - signal(SIG, HAND); \ - }) - -#endif /* GNU && !ANSI */ - COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_H_ */ diff --git a/libc/calls/struct/sigaction.internal.h b/libc/calls/struct/sigaction.internal.h index fbb10c14e..509769d8f 100644 --- a/libc/calls/struct/sigaction.internal.h +++ b/libc/calls/struct/sigaction.internal.h @@ -63,6 +63,10 @@ void __sigenter_openbsd(int, struct siginfo *, void *) _Hide; const char *DescribeSigaction(char[256], int, const struct sigaction *); #define DescribeSigaction(rc, sa) DescribeSigaction(alloca(256), rc, sa) +void _init_onntconsoleevent(void); +void _init_wincrash(void); +void _check_sigwinch(); + COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_INTERNAL_H_ */ diff --git a/libc/calls/tcsetattr-nt.c b/libc/calls/tcsetattr-nt.c index d52c24949..a1bd813d7 100644 --- a/libc/calls/tcsetattr-nt.c +++ b/libc/calls/tcsetattr-nt.c @@ -61,6 +61,7 @@ textwindows int tcsetattr_nt(int ignored, int opt, const struct termios *tio) { inmode |= kNtEnableVirtualTerminalInput; } ok = SetConsoleMode(in, inmode); + (void)ok; NTTRACE("SetConsoleMode(%p, %s) → %hhhd", in, DescribeNtConsoleInFlags(inmode), ok); } @@ -75,6 +76,7 @@ textwindows int tcsetattr_nt(int ignored, int opt, const struct termios *tio) { outmode |= kNtEnableVirtualTerminalProcessing; } ok = SetConsoleMode(out, outmode); + (void)ok; NTTRACE("SetConsoleMode(%p, %s) → %hhhd", out, DescribeNtConsoleOutFlags(outmode), ok); } diff --git a/libc/dns/resolvedns.c b/libc/dns/resolvedns.c index 66ecf6159..9c5c10181 100644 --- a/libc/dns/resolvedns.c +++ b/libc/dns/resolvedns.c @@ -52,7 +52,6 @@ */ int ResolveDns(const struct ResolvConf *resolvconf, int af, const char *name, struct sockaddr *addr, uint32_t addrsize) { - int32_t ttl; int rc, fd, n; struct DnsQuestion q; struct DnsHeader h, h2; @@ -94,7 +93,7 @@ int ResolveDns(const struct ResolvConf *resolvconf, int af, const char *name, if (p + 10 <= pe) { rtype = READ16BE(p); rclass = READ16BE(p + 2); - ttl = READ32BE(p + 4); + // ttl = READ32BE(p + 4); rdlength = READ16BE(p + 8); if (p + 10 + rdlength <= pe && rdlength == 4 && rclass == DNS_CLASS_IN && rtype == DNS_TYPE_A) { diff --git a/libc/integral/c.inc b/libc/integral/c.inc index 1901a009d..7be14c688 100644 --- a/libc/integral/c.inc +++ b/libc/integral/c.inc @@ -89,8 +89,10 @@ #endif #ifndef __cplusplus +#if defined(__GNUC__) && !defined(__llvm__) #pragma GCC push_options #pragma GCC diagnostic ignored "-Wc++-compat" +#endif #define HAVE_STDBOOL_H 1 #if __STDC_VERSION__ + 0 >= 201112 typedef _Bool bool; @@ -102,7 +104,9 @@ typedef _Bool bool; typedef __WCHAR_TYPE__ wchar_t; typedef __CHAR16_TYPE__ char16_t; typedef __CHAR32_TYPE__ char32_t; +#if defined(__GNUC__) && !defined(__llvm__) #pragma GCC pop_options +#endif #endif /* __cplusplus */ #define _LIBCPP_STDINT_H diff --git a/libc/x/xreadlink.c b/libc/intrin/getcpuidbrand.S similarity index 78% rename from libc/x/xreadlink.c rename to libc/intrin/getcpuidbrand.S index e63cd0c63..153ea7f22 100644 --- a/libc/x/xreadlink.c +++ b/libc/intrin/getcpuidbrand.S @@ -1,7 +1,7 @@ -/*-*- 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│ +/*-*- 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 │ +│ Copyright 2023 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 │ @@ -16,15 +16,18 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/sysv/consts/at.h" -#include "libc/x/x.h" +#include "libc/macros.internal.h" -/** - * Reads symbolic link. - * - * @return nul-terminated string, or null w/ errno - * @see readlink() - */ -char *xreadlink(const char *path) { - return xreadlinkat(AT_FDCWD, path); -} +GetCpuidBrand: + mov %esi,%eax + xor %ecx,%ecx + push %rbx + cpuid + mov %ebx,0(%rdi) + mov %ecx,4(%rdi) + mov %edx,8(%rdi) + movb $0,12(%rdi) + pop %rbx + movb $0,12(%rdi) + ret + .endfn GetCpuidBrand,globl diff --git a/libc/intrin/getcpuidbrand.c b/libc/intrin/getcpuidbrand.c deleted file mode 100644 index d2e2ccc16..000000000 --- a/libc/intrin/getcpuidbrand.c +++ /dev/null @@ -1,37 +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 2023 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/runtime/runtime.h" -#ifdef __x86_64__ - -void GetCpuidBrand(char s[13], uint32_t leaf) { - int ax, cx; - asm("push\t%%rbx\r\n" - "cpuid\r\n" - "mov\t%%ebx,0+%2\r\n" - "mov\t%%ecx,4+%2\r\n" - "mov\t%%edx,8+%2\r\n" - "movb\t$0,12+%2\r\n" - "pop\t%%rbx" - : "=a"(ax), "=c"(cx), "=o"(*(char(*)[13])s) - : "0"(leaf), "1"(0) - : "rdx"); - s[12] = 0; -} - -#endif /* __x86_64__ */ diff --git a/libc/intrin/memset.c b/libc/intrin/memset.c index c83141edd..f34aec2da 100644 --- a/libc/intrin/memset.c +++ b/libc/intrin/memset.c @@ -160,7 +160,7 @@ void *memset(void *p, int c, size_t n) { return b; #ifdef __x86__ } else if (IsTiny()) { - asm("rep stosb" : "+D"(b), "+c"(n), "=m"(*(char(*)[n])b) : "0"(p), "a"(c)); + asm("rep stosb" : "+D"(b), "+c"(n), "=m"(*(char(*)[n])b) : "a"(c)); return p; } else if (X86_HAVE(AVX)) { return memset_avx(b, c, n); diff --git a/libc/runtime/stackchkfail.c b/libc/intrin/stackchkfail.c similarity index 95% rename from libc/runtime/stackchkfail.c rename to libc/intrin/stackchkfail.c index 75a9fad59..5d485fd49 100644 --- a/libc/runtime/stackchkfail.c +++ b/libc/intrin/stackchkfail.c @@ -16,11 +16,11 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/calls.h" +#include "libc/intrin/kprintf.h" #include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" __attribute__((__weak__)) void __stack_chk_fail(void) { - tinyprint(2, program_invocation_name, ": stack smashed\n", NULL); + kprintf("%s: stack smashed\n", program_invocation_name); __builtin_trap(); } diff --git a/libc/runtime/stackchkfaillocal.c b/libc/intrin/stackchkfaillocal.c similarity index 100% rename from libc/runtime/stackchkfaillocal.c rename to libc/intrin/stackchkfaillocal.c diff --git a/third_party/compiler_rt/udivti3.c b/libc/intrin/udivti3.c similarity index 100% rename from third_party/compiler_rt/udivti3.c rename to libc/intrin/udivti3.c diff --git a/libc/isystem/signal.h b/libc/isystem/signal.h index 0342af9c6..db7928914 100644 --- a/libc/isystem/signal.h +++ b/libc/isystem/signal.h @@ -6,5 +6,6 @@ #include "libc/calls/struct/siginfo.h" #include "libc/sysv/consts/sa.h" #include "libc/sysv/consts/sicode.h" +#include "libc/sysv/consts/sig.h" #include "libc/sysv/consts/ss.h" #endif /* _SIGNAL_H */ diff --git a/libc/libc.mk b/libc/libc.mk index 1c6dbc7b8..ffa06e2a8 100644 --- a/libc/libc.mk +++ b/libc/libc.mk @@ -5,9 +5,14 @@ PKGS += LIBC LIBC_HDRS = $(filter %.h,$(LIBC_FILES)) LIBC_INCS = $(filter %.inc,$(LIBC_FILES)) -LIBC_FILES := $(wildcard libc/*) $(wildcard libc/isystem/*) LIBC_CHECKS = $(LIBC_HDRS:%=o/$(MODE)/%.ok) +ifneq ($(MODE), llvm) +LIBC_FILES := $(wildcard libc/*) $(wildcard libc/isystem/*) +else +LIBC_FILES := $(wildcard libc/*) +endif + .PHONY: o/$(MODE)/libc o/$(MODE)/libc: o/$(MODE)/libc/calls \ o/$(MODE)/libc/crt \ diff --git a/libc/log/checkfail.c b/libc/log/checkfail.c index 0a5b837f6..c2d04900b 100644 --- a/libc/log/checkfail.c +++ b/libc/log/checkfail.c @@ -46,14 +46,12 @@ relegated void __check_fail(const char *suffix, // int line, // const char *fmt, // ...) { - int e; char *p; size_t i; va_list va; char hostname[32]; strace_enabled(-1); ftrace_enabled(-1); - e = errno; __start_fatal(file, line); __stpcpy(hostname, "unknown"); gethostname(hostname, sizeof(hostname)); diff --git a/libc/log/gdbexec.c b/libc/log/gdbexec.c index c0f2673db..a7d25dc19 100644 --- a/libc/log/gdbexec.c +++ b/libc/log/gdbexec.c @@ -31,7 +31,6 @@ relegated int(gdbexec)(const char *cmd) { struct StackFrame *bp; int pid, ttyin, ttyout; - intptr_t continuetoaddr; const char *se, *elf, *gdb; char pidstr[11], breakcmd[40]; if (!(gdb = GetGdbPath())) return -1; @@ -43,7 +42,6 @@ relegated int(gdbexec)(const char *cmd) { elf = "-q"; } bp = __builtin_frame_address(0); - continuetoaddr = bp->addr; sprintf(breakcmd, "%s *%#p", "break", bp->addr); if (!(pid = vfork())) { execv(gdb, (char *const[]){ diff --git a/libc/log/memlog.c b/libc/log/memlog.c index 0acd37eed..fc0de9cbe 100644 --- a/libc/log/memlog.c +++ b/libc/log/memlog.c @@ -17,6 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" +#include "libc/atomic.h" #include "libc/intrin/atomic.h" #include "libc/intrin/kprintf.h" #include "libc/log/backtrace.internal.h" @@ -67,7 +68,7 @@ static struct Memlog { long size; } * p; } allocs; - long usage; + atomic_long usage; } __memlog; static pthread_mutex_t __memlog_lock_obj; diff --git a/libc/log/oncrash_amd64.c b/libc/log/oncrash_amd64.c index bbea0034b..803f7f46c 100644 --- a/libc/log/oncrash_amd64.c +++ b/libc/log/oncrash_amd64.c @@ -23,6 +23,7 @@ #include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/utsname.h" #include "libc/calls/syscall-sysv.internal.h" +#include "libc/calls/ucontext.h" #include "libc/dce.h" #include "libc/errno.h" #include "libc/fmt/itoa.h" @@ -44,6 +45,7 @@ #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" +#include "libc/sysv/consts/sig.h" #include "libc/thread/thread.h" #include "libc/thread/tls.h" #ifdef __x86_64__ @@ -292,7 +294,9 @@ static wontreturn relegated dontinstrument void __minicrash(int sig, */ relegated void __oncrash_amd64(int sig, struct siginfo *si, void *arg) { int bZero; +#ifdef ATTACH_GDB_ON_CRASH intptr_t rip; +#endif int me, owner; int gdbpid, err; ucontext_t *ctx = arg; @@ -307,13 +311,15 @@ relegated void __oncrash_amd64(int sig, struct siginfo *si, void *arg) { if (atomic_compare_exchange_strong_explicit( &once, &owner, me, memory_order_relaxed, memory_order_relaxed)) { if (!__vforked) { +#ifdef ATTACH_GDB_ON_CRASH rip = ctx ? ctx->uc_mcontext.rip : 0; +#endif err = errno; if ((gdbpid = IsDebuggerPresent(true))) { DebugBreak(); } else if (__nocolor || g_isrunningundermake) { gdbpid = -1; -#if 0 +#if ATTACH_GDB_ON_CRASH } else if (!IsTiny() && IsLinux() && FindDebugBinary() && !__isworker) { // RestoreDefaultCrashSignalHandlers(); gdbpid = AttachDebugger( diff --git a/libc/runtime/clone.c b/libc/runtime/clone.c index 05663adc4..03e01040c 100644 --- a/libc/runtime/clone.c +++ b/libc/runtime/clone.c @@ -169,7 +169,7 @@ asm("XnuThreadThunk:\n\t" "push\t%rax\n\t" "jmp\tXnuThreadMain\n\t" ".size\tXnuThreadThunk,.-XnuThreadThunk"); -__attribute__((__used__, __no_reorder__)) +__attribute__((__used__)) static wontreturn void XnuThreadMain(void *pthread, // rdi diff --git a/libc/runtime/enable_tls.c b/libc/runtime/enable_tls.c index d54c6ba0c..fd6f91157 100644 --- a/libc/runtime/enable_tls.c +++ b/libc/runtime/enable_tls.c @@ -121,7 +121,7 @@ textstartup void __enable_tls(void) { #ifdef __x86_64__ - siz = ROUNDUP(I(_tls_size) + sizeof(*tib), _Alignof(__static_tls)); + siz = ROUNDUP(I(_tls_size) + sizeof(*tib), TLS_ALIGNMENT); if (siz <= sizeof(__static_tls)) { // if tls requirement is small then use the static tls block // which helps avoid a system call for appes with little tls diff --git a/libc/runtime/ftrace-hook.S b/libc/runtime/ftrace-hook.S index d572254e4..af12bcc67 100644 --- a/libc/runtime/ftrace-hook.S +++ b/libc/runtime/ftrace-hook.S @@ -26,7 +26,7 @@ ftrace_hook: // like __errno_location which can be called from an inline asm() // statement. It's nice to have the flexibility anyway. - cmp $0,__ftrace(%rip) + cmpl $0,__ftrace(%rip) jle 1f push %rbp mov %rsp,%rbp diff --git a/libc/runtime/inflate.c b/libc/runtime/inflate.c index 7f887fcee..591c09e5c 100644 --- a/libc/runtime/inflate.c +++ b/libc/runtime/inflate.c @@ -54,8 +54,6 @@ int __inflate(void *out, size_t outsize, const void *in, size_t insize) { rc = 0; } else if (rc == Z_OK) { rc = Z_STREAM_END; // coerce to nonzero - } else { - rc = rc; } } else { rc = _puff(out, &outsize, in, &insize); diff --git a/libc/runtime/memtracknt.c b/libc/runtime/memtracknt.c index 80c0d6175..75c5a6ff3 100644 --- a/libc/runtime/memtracknt.c +++ b/libc/runtime/memtracknt.c @@ -31,13 +31,9 @@ static inline noasan void *GetFrameAddr(int f) { } noasan void ReleaseMemoryNt(struct MemoryIntervals *mm, int l, int r) { - int i, ok; - size_t size; - char *addr, *last; + int i; for (i = l; i <= r; ++i) { - addr = GetFrameAddr(mm->p[i].x); - last = GetFrameAddr(mm->p[i].y); - UnmapViewOfFile(addr); + UnmapViewOfFile(GetFrameAddr(mm->p[i].x)); CloseHandle(mm->p[i].h); } } diff --git a/libc/runtime/runtime.mk b/libc/runtime/runtime.mk index 1de311028..78fcef9e2 100644 --- a/libc/runtime/runtime.mk +++ b/libc/runtime/runtime.mk @@ -128,7 +128,8 @@ o/$(MODE)/libc/runtime/enable_threads.o \ o/$(MODE)/libc/runtime/morph_tls.o: private \ CFLAGS += \ -ffreestanding \ - -fno-sanitize=all + -fno-sanitize=all \ + -fno-stack-protector # TODO(jart): We need a way to avoid WinThreadEntry() being hooked. o/$(MODE)/libc/runtime/clone.o: private \ diff --git a/libc/runtime/winmain.greg.c b/libc/runtime/winmain.greg.c index fd24f698d..3ac00dff6 100644 --- a/libc/runtime/winmain.greg.c +++ b/libc/runtime/winmain.greg.c @@ -154,6 +154,7 @@ __msabi static textwindows wontreturn void WinMainNew(const char16_t *cmdline) { : (DescribeNtConsoleInFlags)(inflagsbuf, kConsoleModes[i]), rc); } + (void)rc; } _Static_assert(sizeof(struct WinArgs) % FRAMESIZE == 0, ""); _mmi.p = _mmi.s; diff --git a/libc/sock/kntwsadata.c b/libc/sock/kntwsadata.c index 9674e75c1..048d896ec 100644 --- a/libc/sock/kntwsadata.c +++ b/libc/sock/kntwsadata.c @@ -38,6 +38,7 @@ _Hide struct NtWsaData kNtWsaData; static textwindows void WinSockCleanup(void) { int i, rc; + (void)rc; rc = WSACleanup(); NTTRACE("WSACleanup() → %d% lm", rc); } diff --git a/libc/stdio/fmt.c b/libc/stdio/fmt.c index 7b62d1d98..f55619772 100644 --- a/libc/stdio/fmt.c +++ b/libc/stdio/fmt.c @@ -67,9 +67,6 @@ #define PRINTF_NTOA_BUFFER_SIZE 144 -#define __FMT_CONSUMED_DOUBLE 1 -#define __FMT_CONSUMED_LONG_DOUBLE 2 - #define FLAGS_ZEROPAD 0x01 #define FLAGS_LEFT 0x02 #define FLAGS_PLUS 0x04 @@ -423,7 +420,7 @@ static int __fmt_stoa(int out(const char *, void *, size_t), void *arg, } else { emit = __fmt_stoa_wide; } - } else if ((flags & FLAGS_HASH) && kCp437) { + } else if (flags & FLAGS_HASH) { justdobytes = true; emit = __fmt_stoa_bing; ignorenul = flags & FLAGS_PRECISION; @@ -796,7 +793,7 @@ _Hide int __fmt(void *fn, void *arg, const char *format, va_list va) { int (*out)(const char *, void *, size_t); char *se, *s0, *s, *q, qchar, special[8]; int d, w, n, sign, prec, flags, width, lasterr; - int c, k, i1, ui, bw, rc, bex, sgn, prec1, decpt, consumed; + int c, k, i1, ui, bw, rc, bex, sgn, prec1, decpt; x = 0; lasterr = errno; @@ -1069,7 +1066,6 @@ _Hide int __fmt(void *fn, void *arg, const char *format, va_list va) { if (!(flags & FLAGS_PRECISION)) prec = 6; if (!longdouble) { x = va_arg(va, double); - consumed = __FMT_CONSUMED_DOUBLE; s = s0 = dtoa(x, 3, prec, &decpt, &fpb.sign, &se); if (decpt == 9999) { if (s && s[0] == 'N') { @@ -1080,7 +1076,6 @@ _Hide int __fmt(void *fn, void *arg, const char *format, va_list va) { } } else { un.ld = va_arg(va, long double); - consumed = __FMT_CONSUMED_LONG_DOUBLE; __fmt_ldfpbits(&un, &fpb); s = s0 = gdtoa(fpb.fpi, fpb.ex, fpb.bits, &fpb.kind, 3, prec, &decpt, &se); @@ -1102,7 +1097,7 @@ _Hide int __fmt(void *fn, void *arg, const char *format, va_list va) { prec = 0; rc = __fmt_stoa(out, arg, s, flags, prec, width, signbit, qchar); if (rc == -1) return -1; - return consumed; + break; } FormatReal: if (fpb.sign /* && (x || sign) */) sign = '-'; @@ -1166,7 +1161,6 @@ _Hide int __fmt(void *fn, void *arg, const char *format, va_list va) { if (prec < 1) prec = 1; if (!longdouble) { x = va_arg(va, double); - consumed = __FMT_CONSUMED_DOUBLE; s = s0 = dtoa(x, 2, prec, &decpt, &fpb.sign, &se); if (decpt == 9999) { if (s && s[0] == 'N') { @@ -1177,7 +1171,6 @@ _Hide int __fmt(void *fn, void *arg, const char *format, va_list va) { } } else { un.ld = va_arg(va, long double); - consumed = __FMT_CONSUMED_LONG_DOUBLE; __fmt_ldfpbits(&un, &fpb); s = s0 = gdtoa(fpb.fpi, fpb.ex, fpb.bits, &fpb.kind, prec ? 2 : 0, prec, &decpt, &se); @@ -1209,7 +1202,6 @@ _Hide int __fmt(void *fn, void *arg, const char *format, va_list va) { if (prec < 0) prec = 0; if (!longdouble) { x = va_arg(va, double); - consumed = __FMT_CONSUMED_DOUBLE; s = s0 = dtoa(x, 2, prec + 1, &decpt, &fpb.sign, &se); if (decpt == 9999) { if (s && s[0] == 'N') { @@ -1220,7 +1212,6 @@ _Hide int __fmt(void *fn, void *arg, const char *format, va_list va) { } } else { un.ld = va_arg(va, long double); - consumed = __FMT_CONSUMED_LONG_DOUBLE; __fmt_ldfpbits(&un, &fpb); s = s0 = gdtoa(fpb.fpi, fpb.ex, fpb.bits, &fpb.kind, prec ? 2 : 0, prec, &decpt, &se); @@ -1289,11 +1280,9 @@ _Hide int __fmt(void *fn, void *arg, const char *format, va_list va) { FormatBinary: if (longdouble) { un.ld = va_arg(va, long double); - consumed = __FMT_CONSUMED_LONG_DOUBLE; __fmt_ldfpbits(&un, &fpb); } else { un.d = va_arg(va, double); - consumed = __FMT_CONSUMED_DOUBLE; __fmt_dfpbits(&un, &fpb); } if (fpb.kind == STRTOG_Infinite || fpb.kind == STRTOG_NaN) { @@ -1320,7 +1309,7 @@ _Hide int __fmt(void *fn, void *arg, const char *format, va_list va) { if (sign) --width; if (prec1 || (flags & FLAGS_HASH)) --width; } - if ((width -= prec1) > 0 && !(flags & FLAGS_LEFT) && + if ((width -= MAX(prec, prec1)) > 0 && !(flags & FLAGS_LEFT) && !(flags & FLAGS_ZEROPAD)) { do __FMT_PUT(' '); while (--width > 0); diff --git a/libc/stdio/posix_spawn.internal.h b/libc/stdio/posix_spawn.internal.h index dc274275a..103823917 100644 --- a/libc/stdio/posix_spawn.internal.h +++ b/libc/stdio/posix_spawn.internal.h @@ -25,10 +25,8 @@ struct _posix_spawna { struct _posix_faction { struct _posix_faction *next; int action; - union { - int fildes; - int oflag; - }; + int fildes; + int oflag; union { int newfildes; unsigned mode; diff --git a/libc/stdio/posix_spawn_file_actions.c b/libc/stdio/posix_spawn_file_actions.c index 914a0a12c..2efe41dad 100644 --- a/libc/stdio/posix_spawn_file_actions.c +++ b/libc/stdio/posix_spawn_file_actions.c @@ -105,6 +105,7 @@ int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *file_actions, int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *file_actions, int fildes, const char *path, int oflag, unsigned mode) { + if (fildes < 0) return EBADF; if (!(path = strdup(path))) return ENOMEM; return AddFileAction(file_actions, (struct _posix_faction){ .action = _POSIX_SPAWN_OPEN, diff --git a/libc/str/getzipeocd.c b/libc/str/getzipeocd.c index 052c6f28f..a6ae6069b 100644 --- a/libc/str/getzipeocd.c +++ b/libc/str/getzipeocd.c @@ -47,7 +47,8 @@ void *GetZipEocd(const void *f, size_t n, int *e) { i = n - 4; err = kZipErrorEocdNotFound; do { -#ifdef __x86_64__ +#if defined(__x86_64__) && defined(__GNUC__) && !defined(__llvm__) && \ + !defined(__chibicc__) v8hi pk = {READ16LE("PK"), READ16LE("PK"), READ16LE("PK"), READ16LE("PK"), READ16LE("PK"), READ16LE("PK"), READ16LE("PK"), READ16LE("PK")}; asm("" : "+x"(pk)); diff --git a/libc/sysv/errno_location.greg.c b/libc/sysv/errno_location.greg.c index e0dc52218..93246f2e5 100644 --- a/libc/sysv/errno_location.greg.c +++ b/libc/sysv/errno_location.greg.c @@ -16,9 +16,10 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/errno.h" #include "libc/thread/tls2.h" +extern errno_t __errno; + /** * Returns address of errno variable. */ diff --git a/libc/sysv/systemfive.S b/libc/sysv/systemfive.S index dad20dd1f..69bfa487e 100644 --- a/libc/sysv/systemfive.S +++ b/libc/sysv/systemfive.S @@ -121,7 +121,7 @@ systemfive_cancellable: // our pthread_cancel() miracle code testb $PT_INCANCEL,0x00(%r10) jz 5f #endif - cmp $0,0x04(%r10) // PosixThread::cancelled + cmpl $0,0x04(%r10) // PosixThread::cancelled jne systemfive_cancel // we will tail call below 1: mov %rcx,%r10 // move the fourth argument clc // no cancellable system calls exist @@ -144,7 +144,7 @@ systemfive_cancellable_end: // i/o calls park here for long time jz systemfive_errno // it's spawn() probably testb $PT_NOCANCEL,0x00(%rcx) // PosixThread::flags jnz systemfive_errno // cancellation is disabled - cmp $0,0x04(%rcx) // PosixThread::cancelled + cmpl $0,0x04(%rcx) // PosixThread::cancelled je systemfive_errno // we aren't actually cancelled jmp 4f // now we are in fact cancelled systemfive_cancel: // SIGTHR will jump here too diff --git a/libc/testlib/ezbench.h b/libc/testlib/ezbench.h index 9b444a752..1e60fdb1d 100644 --- a/libc/testlib/ezbench.h +++ b/libc/testlib/ezbench.h @@ -46,7 +46,6 @@ COSMOPOLITAN_C_START_ EXPR; \ MemoryStrict = BENCHLOOP(__startbench_m, __endbench_m, 32, ({ \ INIT; \ - thrashcodecache(); \ __polluteregisters(); \ }), \ (EXPR)); \ @@ -88,7 +87,6 @@ COSMOPOLITAN_C_START_ EXPR; \ MemoryStrict = BENCHLOOP(__startbench_m, __endbench_m, NUM, ({ \ INIT; \ - thrashcodecache(); \ __polluteregisters(); \ }), \ (EXPR)); \ @@ -101,53 +99,47 @@ COSMOPOLITAN_C_START_ MAX(.001, MemoryStrict - __testlib_ezbenchcontrol())); \ } while (0) -#define EZBENCH_C(NAME, CONTROL, EXPR) \ - do { \ - int Core, Tries, Interrupts; \ - double Control, Speculative, MemoryStrict; \ - Tries = 0; \ - do { \ - __testlib_yield(); \ - Core = __testlib_getcore(); \ - Interrupts = __testlib_getinterrupts(); \ - Control = BENCHLOOP(__startbench_m, __endbench_m, EZBENCH_COUNT, ({ \ - thrashcodecache(); \ - __polluteregisters(); \ - }), \ - (CONTROL)); \ - } while (++Tries < EZBENCH_TRIES && \ - (__testlib_getcore() != Core && \ - __testlib_getinterrupts() > Interrupts)); \ - if (Tries == EZBENCH_TRIES) __testlib_ezbenchwarn(" control"); \ - Tries = 0; \ - do { \ - __testlib_yield(); \ - Core = __testlib_getcore(); \ - Interrupts = __testlib_getinterrupts(); \ - EXPR; \ - Speculative = BENCHLOOP(__startbench, __endbench, EZBENCH_COUNT, \ - __polluteregisters(), (EXPR)); \ - } while (++Tries < EZBENCH_TRIES && \ - (__testlib_getcore() != Core && \ - __testlib_getinterrupts() > Interrupts)); \ - if (Tries == EZBENCH_TRIES) __testlib_ezbenchwarn(" speculative"); \ - Tries = 0; \ - do { \ - __testlib_yield(); \ - Core = __testlib_getcore(); \ - Interrupts = __testlib_getinterrupts(); \ - EXPR; \ - MemoryStrict = BENCHLOOP(__startbench_m, __endbench_m, 8, ({ \ - thrashcodecache(); \ - __polluteregisters(); \ - }), \ - (EXPR)); \ - } while (++Tries < EZBENCH_TRIES && \ - (__testlib_getcore() != Core && \ - __testlib_getinterrupts() > Interrupts)); \ - if (Tries == EZBENCH_TRIES) __testlib_ezbenchwarn(" memory strict"); \ - __testlib_ezbenchreport(NAME, MAX(.001, Speculative - Control), \ - MAX(.001, MemoryStrict - Control)); \ +#define EZBENCH_C(NAME, CONTROL, EXPR) \ + do { \ + int Core, Tries, Interrupts; \ + double Control, Speculative, MemoryStrict; \ + Tries = 0; \ + do { \ + __testlib_yield(); \ + Core = __testlib_getcore(); \ + Interrupts = __testlib_getinterrupts(); \ + Control = BENCHLOOP(__startbench_m, __endbench_m, EZBENCH_COUNT, \ + ({ __polluteregisters(); }), (CONTROL)); \ + } while (++Tries < EZBENCH_TRIES && \ + (__testlib_getcore() != Core && \ + __testlib_getinterrupts() > Interrupts)); \ + if (Tries == EZBENCH_TRIES) __testlib_ezbenchwarn(" control"); \ + Tries = 0; \ + do { \ + __testlib_yield(); \ + Core = __testlib_getcore(); \ + Interrupts = __testlib_getinterrupts(); \ + EXPR; \ + Speculative = BENCHLOOP(__startbench, __endbench, EZBENCH_COUNT, \ + __polluteregisters(), (EXPR)); \ + } while (++Tries < EZBENCH_TRIES && \ + (__testlib_getcore() != Core && \ + __testlib_getinterrupts() > Interrupts)); \ + if (Tries == EZBENCH_TRIES) __testlib_ezbenchwarn(" speculative"); \ + Tries = 0; \ + do { \ + __testlib_yield(); \ + Core = __testlib_getcore(); \ + Interrupts = __testlib_getinterrupts(); \ + EXPR; \ + MemoryStrict = BENCHLOOP(__startbench_m, __endbench_m, 8, \ + ({ __polluteregisters(); }), (EXPR)); \ + } while (++Tries < EZBENCH_TRIES && \ + (__testlib_getcore() != Core && \ + __testlib_getinterrupts() > Interrupts)); \ + if (Tries == EZBENCH_TRIES) __testlib_ezbenchwarn(" memory strict"); \ + __testlib_ezbenchreport(NAME, MAX(.001, Speculative - Control), \ + MAX(.001, MemoryStrict - Control)); \ } while (0) #define EZBENCH_N(NAME, N, EXPR) \ diff --git a/libc/testlib/memoryexists.c b/libc/testlib/memoryexists.c index a5c87833e..0db928464 100644 --- a/libc/testlib/memoryexists.c +++ b/libc/testlib/memoryexists.c @@ -63,6 +63,7 @@ noasan bool testlib_memoryexists(const void *p) { _npassert(!sigaction(SIGSEGV, &sa, old + 0)); _npassert(!sigaction(SIGBUS, &sa, old + 1)); c = atomic_load(mem); + (void)c; _npassert(!sigaction(SIGBUS, old + 1, 0)); _npassert(!sigaction(SIGSEGV, old + 0, 0)); return !gotsignal; diff --git a/libc/testlib/testlib.h b/libc/testlib/testlib.h index c474340da..371383704 100644 --- a/libc/testlib/testlib.h +++ b/libc/testlib/testlib.h @@ -382,8 +382,6 @@ void testlib_error_enter(const char *, const char *); void testlib_showerror(const char *, int, const char *, const char *, const char *, const char *, char *, char *); -void thrashcodecache(void); - void testlib_finish(void); int testlib_geterrno(void); void testlib_seterrno(int); diff --git a/libc/testlib/testlib.mk b/libc/testlib/testlib.mk index 562e14f41..2c35faf6a 100644 --- a/libc/testlib/testlib.mk +++ b/libc/testlib/testlib.mk @@ -38,7 +38,6 @@ LIBC_TESTLIB_A_SRCS_S = \ libc/testlib/moby.S \ libc/testlib/polluteregisters.S \ libc/testlib/testcase.S \ - libc/testlib/thrashcodecache.S \ libc/testlib/viewables.S LIBC_TESTLIB_A_SRCS_C = \ @@ -147,8 +146,6 @@ o/$(MODE)/libc/testlib/polluteregisters.o: libc/testlib/polluteregisters.S @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $< o/$(MODE)/libc/testlib/testcase.o: libc/testlib/testcase.S @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $< -o/$(MODE)/libc/testlib/thrashcodecache.o: libc/testlib/thrashcodecache.S - @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $< o/$(MODE)/libc/testlib/viewables.o: libc/testlib/viewables.S @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $< diff --git a/libc/testlib/thrashcodecache.S b/libc/testlib/thrashcodecache.S deleted file mode 100644 index 5fa61cc6f..000000000 --- a/libc/testlib/thrashcodecache.S +++ /dev/null @@ -1,49 +0,0 @@ -/*-*- 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 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/macros.internal.h" -.testonly - -// Empties L1 instruction cache. -thrashcodecache: -#ifdef __x86_64__ - .leafprologue - push %rbx - xor %eax,%eax - xor %ecx,%ecx - cpuid - add %r9,%r8 -// Generate 32kb of junk code clobbering r8,r9,r10,r11 - i = 0xdeadbeef -0: .rept 32768/(3+7) - rex.wrb - .byte 0001|(i&030) // ADD/OR/... Evqp Gvqp - .byte 0300|(i&033) // %r8-%r11 to %r8-%r11 - .byte 0x49,0x81,0360|(i&003) // XOR immed32,%r8-%r11 - .long i - i = ((i * 1103515245 + 12345) >> 16) & 0xffffffff - .endr - xor %eax,%eax - xor %ecx,%ecx - cpuid - pop %rbx - .leafepilogue -#else - ret -#endif - .endfn thrashcodecache,globl diff --git a/libc/thread/makecontext.c b/libc/thread/makecontext.c index ddb285df6..bd75b2418 100644 --- a/libc/thread/makecontext.c +++ b/libc/thread/makecontext.c @@ -101,7 +101,7 @@ void makecontext(ucontext_t *uc, void func(), int argc, ...) { sp += uc->uc_stack.ss_size; sp -= 16; // openbsd:stackbound sp -= sizeof(*call); - sp &= -alignof(*call); + sp &= -alignof(struct Gadget); call = (struct Gadget *)sp; // get arguments diff --git a/libc/thread/pthread_getaffinity_np.c b/libc/thread/pthread_getaffinity_np.c index 762907e66..1e5bda165 100644 --- a/libc/thread/pthread_getaffinity_np.c +++ b/libc/thread/pthread_getaffinity_np.c @@ -38,10 +38,9 @@ */ errno_t pthread_getaffinity_np(pthread_t thread, size_t size, cpu_set_t *bitset) { - int e, rc, tid; + int rc, tid; if (!(rc = pthread_getunique_np(thread, &tid))) { - e = errno; if (size != sizeof(cpu_set_t)) { rc = einval(); } else if (IsWindows() || IsMetal() || IsOpenbsd()) { diff --git a/libc/thread/sem_open.c b/libc/thread/sem_open.c index 1f90d4af2..efd32c5f0 100644 --- a/libc/thread/sem_open.c +++ b/libc/thread/sem_open.c @@ -253,7 +253,7 @@ sem_t *sem_open(const char *name, int oflag, ...) { * @return 0 on success, or -1 w/ errno */ int sem_close(sem_t *sem) { - int rc, prefs; + int prefs; bool unmap, delete; struct Semaphore *s, **p; _npassert(sem->sem_magic == SEM_MAGIC_NAMED); @@ -275,7 +275,7 @@ int sem_close(sem_t *sem) { _npassert(!munmap(sem, PAGESIZE)); } if (delete) { - rc = unlink(s->path); + unlink(s->path); } if (unmap) { free(s->path); diff --git a/libc/thread/spawn.c b/libc/thread/spawn.c index 97d463065..dc813776d 100644 --- a/libc/thread/spawn.c +++ b/libc/thread/spawn.c @@ -69,7 +69,7 @@ static int Spawner(void *arg, int tid) { rc = spawner->fun(spawner->arg, tid); _pthread_ungarbage(); free(spawner); - return 0; + return rc; } /** diff --git a/libc/tinymath/ceil.c b/libc/tinymath/ceil.c index d2cd35611..66dee5e66 100644 --- a/libc/tinymath/ceil.c +++ b/libc/tinymath/ceil.c @@ -28,7 +28,9 @@ #include "libc/math.h" #include "libc/runtime/fenv.h" #include "libc/tinymath/internal.h" +#ifndef __llvm__ #include "third_party/intel/smmintrin.internal.h" +#endif asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ @@ -63,7 +65,7 @@ double ceil(double x) asm("fidbra\t%0,6,%1,4" : "=f"(x) : "f"(x)); return x; -#elif defined(__x86_64__) && defined(__SSE4_1__) +#elif defined(__x86_64__) && defined(__SSE4_1__) && !defined(__llvm__) && !defined(__chibicc__) asm("roundsd\t%2,%1,%0" : "=x"(x) diff --git a/libc/tinymath/ceilf.c b/libc/tinymath/ceilf.c index d8ae80b52..470bdca8e 100644 --- a/libc/tinymath/ceilf.c +++ b/libc/tinymath/ceilf.c @@ -27,7 +27,9 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" #include "libc/tinymath/internal.h" +#ifndef __llvm__ #include "third_party/intel/smmintrin.internal.h" +#endif asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ @@ -55,7 +57,7 @@ float ceilf(float x) asm("fiebra\t%0,6,%1,4" : "=f"(x) : "f"(x)); return x; -#elif defined(__x86_64__) && defined(__SSE4_1__) +#elif defined(__x86_64__) && defined(__SSE4_1__) && !defined(__llvm__) && !defined(__chibicc__) asm("roundss\t%2,%1,%0" : "=x"(x) diff --git a/libc/tinymath/floor.c b/libc/tinymath/floor.c index ff1e1050c..48768bb92 100644 --- a/libc/tinymath/floor.c +++ b/libc/tinymath/floor.c @@ -28,7 +28,9 @@ #include "libc/math.h" #include "libc/runtime/fenv.h" #include "libc/tinymath/internal.h" +#ifndef __llvm__ #include "third_party/intel/smmintrin.internal.h" +#endif asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ @@ -63,7 +65,7 @@ double floor(double x) asm("fidbra\t%0,7,%1,4" : "=f"(x) : "f"(x)); return x; -#elif defined(__x86_64__) && defined(__SSE4_1__) +#elif defined(__x86_64__) && defined(__SSE4_1__) && !defined(__llvm__) && !defined(__chibicc__) asm("roundsd\t%2,%1,%0" : "=x"(x) diff --git a/libc/tinymath/floorf.c b/libc/tinymath/floorf.c index 0d470bed9..892354dbe 100644 --- a/libc/tinymath/floorf.c +++ b/libc/tinymath/floorf.c @@ -27,7 +27,9 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" #include "libc/tinymath/internal.h" +#ifndef __llvm__ #include "third_party/intel/smmintrin.internal.h" +#endif asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ @@ -55,7 +57,7 @@ float floorf(float x) asm("fiebra\t%0,7,%1,4" : "=f"(x) : "f"(x)); return x; -#elif defined(__x86_64__) && defined(__SSE4_1__) +#elif defined(__x86_64__) && defined(__SSE4_1__) && !defined(__llvm__) && !defined(__chibicc__) asm("roundss\t%2,%1,%0" : "=x"(x) diff --git a/libc/tinymath/internal.h b/libc/tinymath/internal.h index 0506c7a52..47a4b3bf8 100644 --- a/libc/tinymath/internal.h +++ b/libc/tinymath/internal.h @@ -29,16 +29,19 @@ static inline double eval_as_double(double x) { static inline void fp_force_evall(long double x) { volatile long double y; y = x; + (void)y; } static inline void fp_force_evalf(float x) { volatile float y; y = x; + (void)y; } static inline void fp_force_eval(double x) { volatile double y; y = x; + (void)y; } static inline double fp_barrier(double x) { diff --git a/libc/tinymath/trunc.c b/libc/tinymath/trunc.c index dcc7ac665..6103ddbea 100644 --- a/libc/tinymath/trunc.c +++ b/libc/tinymath/trunc.c @@ -27,7 +27,9 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" #include "libc/tinymath/internal.h" +#ifndef __llvm__ #include "third_party/intel/smmintrin.internal.h" +#endif asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ @@ -55,7 +57,7 @@ double trunc(double x) asm("fidbra\t%0,5,%1,4" : "=f"(x) : "f"(x)); return x; -#elif defined(__x86_64__) && defined(__SSE4_1__) +#elif defined(__x86_64__) && defined(__SSE4_1__) && !defined(__llvm__) && !defined(__chibicc__) asm("roundsd\t%2,%1,%0" : "=x"(x) diff --git a/libc/tinymath/truncf.c b/libc/tinymath/truncf.c index 1568798dd..b66f8f3e5 100644 --- a/libc/tinymath/truncf.c +++ b/libc/tinymath/truncf.c @@ -27,7 +27,9 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" #include "libc/tinymath/internal.h" +#ifndef __llvm__ #include "third_party/intel/smmintrin.internal.h" +#endif asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ @@ -55,7 +57,7 @@ float truncf(float x) asm("fiebra\t%0,5,%1,4" : "=f"(x) : "f"(x)); return x; -#elif defined(__x86_64__) && defined(__SSE4_1__) +#elif defined(__x86_64__) && defined(__SSE4_1__) && !defined(__llvm__) && !defined(__chibicc__) asm("roundss\t%2,%1,%0" : "=x"(x) diff --git a/libc/vga/rlinit-vesa.S b/libc/vga/rlinit-vesa.S index fbaf33860..8fe3a14de 100644 --- a/libc/vga/rlinit-vesa.S +++ b/libc/vga/rlinit-vesa.S @@ -435,7 +435,7 @@ _rlinit_vesa: mov $PC_VIDEO_TEXT,%al # if text mode, simply say so test $0b00010000,%cl jz .ok4 - cmp $6,%es:0x1b(%di) # if graphics mode, check if direct + cmpl $6,%es:0x1b(%di) # if graphics mode, check if direct jnz .fail4 # color; bail out if not mov %es:0x19(%di),%cl # check actual color fields & bits mov %es:0x1f(%di),%ax # per pixel, against a list diff --git a/libc/vga/tty-klog.greg.c b/libc/vga/tty-klog.greg.c index 01c60e156..5eafd84b1 100644 --- a/libc/vga/tty-klog.greg.c +++ b/libc/vga/tty-klog.greg.c @@ -39,7 +39,9 @@ * @see libc/vga/tty-graph.inc */ +#ifndef __llvm__ #pragma GCC optimize("s") +#endif #define KLOGTTY #define MAYUNROLLLOOPS /* do not unroll loops; keep the code small! */ diff --git a/libc/x/utf8to16.c b/libc/x/utf8to16.c index 98ab7fa98..81bf1809f 100644 --- a/libc/x/utf8to16.c +++ b/libc/x/utf8to16.c @@ -38,7 +38,8 @@ char16_t *utf8to16(const char *p, size_t n, size_t *z) { if (n == -1) n = p ? strlen(p) : 0; if ((q = r = malloc((n + 16) * sizeof(char16_t) * 2 + sizeof(char16_t)))) { for (i = 0; i < n;) { -#if defined(__SSE2__) && defined(__GNUC__) && !defined(__STRICT_ANSI__) +#if defined(__SSE2__) && defined(__GNUC__) && !defined(__STRICT_ANSI__) && \ + !defined(__llvm__) && !defined(__chibicc__) if (i + 16 < n) { typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(1))); xmm_t vi, vz = {0}; diff --git a/libc/x/x.h b/libc/x/x.h index 66dae189e..587f6c991 100644 --- a/libc/x/x.h +++ b/libc/x/x.h @@ -27,13 +27,10 @@ COSMOPOLITAN_C_START_ #define xstripext __xstripext #define xstripexts __xstripexts #define xload __xload -#define xloadzd __xloadzd #define rmrf __rmrf #define xbasename __xbasename #define xdirname __xdirname #define xjoinpaths __xjoinpaths -#define xreadlink __xreadlink -#define xreadlinkat __xreadlinkat #define xfixpath __xfixpath #define xslurp __xslurp #define xbarf __xbarf @@ -84,8 +81,6 @@ char *xhomedir(void) dontdiscard; char *xstripext(const char *) dontdiscard; char *xstripexts(const char *) dontdiscard; void *xload(_Atomic(void *) *, const void *, size_t, size_t); -void *xloadzd(_Atomic(void *) *, const void *, size_t, size_t, size_t, size_t, - uint32_t); int rmrf(const char *); char *xbasename(const char *) paramsnonnull() returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull; @@ -93,10 +88,6 @@ char *xdirname(const char *) paramsnonnull() returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull; char *xjoinpaths(const char *, const char *) paramsnonnull() returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull; -char *xreadlink(const char *) paramsnonnull() - returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull; -char *xreadlinkat(int, const char *) paramsnonnull() - returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull; void xfixpath(void); void *xslurp(const char *, size_t *) paramsnonnull((1)) returnspointerwithnoaliases diff --git a/libc/x/x.mk b/libc/x/x.mk index e1e814269..22f61df36 100644 --- a/libc/x/x.mk +++ b/libc/x/x.mk @@ -35,8 +35,7 @@ LIBC_X_A_DIRECTDEPS = \ LIBC_STR \ LIBC_SYSV \ THIRD_PARTY_GDTOA \ - THIRD_PARTY_MUSL \ - THIRD_PARTY_ZLIB + THIRD_PARTY_MUSL LIBC_X_A_DEPS := \ $(call uniq,$(foreach x,$(LIBC_X_A_DIRECTDEPS),$($(x)))) diff --git a/libc/x/xreadlinkat.c b/libc/x/xreadlinkat.c deleted file mode 100644 index e4005602e..000000000 --- a/libc/x/xreadlinkat.c +++ /dev/null @@ -1,47 +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 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/calls/calls.h" -#include "libc/mem/mem.h" -#include "libc/sysv/errfuns.h" -#include "libc/x/x.h" - -/** - * Reads symbolic link. - * - * @return nul-terminated string, or null w/ errno - * @see readlinkat() - */ -char *xreadlinkat(int dirfd, const char *path) { - ssize_t rc; - size_t n, c; - char *p, *q; - c = PAGESIZE; - p = xmalloc(c); - if ((rc = readlinkat(dirfd, path, p, c)) != -1) { - if ((n = rc) < c) { - p[n] = 0; - if ((q = realloc(p, n + 1))) p = q; - return p; - } else { - enametoolong(); - } - } - free(p); - return 0; -} diff --git a/libc/x/xsigaction.c b/libc/x/xsigaction.c index dfd4a3596..7a424492f 100644 --- a/libc/x/xsigaction.c +++ b/libc/x/xsigaction.c @@ -39,8 +39,8 @@ * @asyncsignalsafe * @vforksafe */ -int(xsigaction)(int sig, void *handler, uint64_t flags, uint64_t mask, - struct sigaction *old) { +int xsigaction(int sig, void *handler, uint64_t flags, uint64_t mask, + struct sigaction *old) { /* This API is superior to sigaction() because (1) it offers feature parity; (2) compiler emits 1/3rd as much binary code at call-site; and (3) it removes typing that just whines without added safety. */ diff --git a/libc/x/xsigaction.h b/libc/x/xsigaction.h index 806b99313..9b428bd38 100644 --- a/libc/x/xsigaction.h +++ b/libc/x/xsigaction.h @@ -6,14 +6,6 @@ COSMOPOLITAN_C_START_ int xsigaction(int, void *, uint64_t, uint64_t, struct sigaction *); -#if defined(__GNUC__) && !defined(__STRICT_ANSI__) -#define xsigaction(SIG, HANDLER, FLAGS, MASK, OLD) \ - ({ \ - __SIGACTION_YOINK(SIG); \ - xsigaction(SIG, HANDLER, FLAGS, MASK, OLD); \ - }) -#endif - COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_X_XSIGACTION_H_ */ diff --git a/test/libc/calls/signal_test.c b/test/libc/calls/signal_test.c index baeabc184..9b011849a 100644 --- a/test/libc/calls/signal_test.c +++ b/test/libc/calls/signal_test.c @@ -18,6 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/struct/sigaction.h" +#include "libc/calls/ucontext.h" #include "libc/dce.h" #include "libc/log/check.h" #include "libc/log/log.h" diff --git a/test/libc/calls/tkill_test.c b/test/libc/calls/tkill_test.c index b7f0be24d..58cd62781 100644 --- a/test/libc/calls/tkill_test.c +++ b/test/libc/calls/tkill_test.c @@ -19,6 +19,7 @@ #include "libc/calls/calls.h" #include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/sigset.h" +#include "libc/dce.h" #include "libc/errno.h" #include "libc/sysv/consts/sig.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/mem/qsort_test.c b/test/libc/mem/qsort_test.c index 6b451c639..24fc96e06 100644 --- a/test/libc/mem/qsort_test.c +++ b/test/libc/mem/qsort_test.c @@ -20,6 +20,7 @@ #include "libc/macros.internal.h" #include "libc/mem/alg.h" #include "libc/mem/gc.h" +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" #include "libc/stdio/rand.h" @@ -28,6 +29,47 @@ #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" +int CompareLow(const void *a, const void *b) { + const int *x = a; + const int *y = b; + if ((char)*x < (char)*y) return -1; + if ((char)*x > (char)*y) return +1; + return 0; +} + +void InsertionSortLow(int *A, int n) { + int i, j, t; + for (i = 1; i < n; i++) { + t = A[i]; + j = i - 1; + while (j >= 0 && (char)A[j] > (char)t) { + A[j + 1] = A[j]; + j = j - 1; + } + A[j + 1] = t; + } +} + +bool IsStableSort(void sort(void *, size_t, size_t, + int (*)(const void *, const void *))) { + int n = 256; + int *A = gc(malloc(n * sizeof(int))); + int *B = gc(malloc(n * sizeof(int))); + rngset(A, n * sizeof(int), 0, 0); + memcpy(B, A, n * sizeof(int)); + InsertionSortLow(A, n); + sort(B, n, sizeof(int), CompareLow); + return !memcmp(A, B, n * sizeof(int)); +} + +TEST(sort, stability) { + ASSERT_FALSE(IsStableSort(qsort)); + ASSERT_FALSE(IsStableSort(smoothsort)); + ASSERT_FALSE(IsStableSort((void *)qsort_r)); + ASSERT_FALSE(IsStableSort((void *)heapsort)); + ASSERT_TRUE(IsStableSort((void *)mergesort)); +} + int CompareInt(const void *a, const void *b) { const int *x = a; const int *y = b; @@ -44,7 +86,7 @@ int CompareLong(const void *a, const void *b) { return 0; } -TEST(qsort, test) { +TEST(qsort, words) { const int32_t A[][2] = {{4, 'a'}, {65, 'b'}, {2, 'c'}, {-31, 'd'}, {0, 'e'}, {99, 'f'}, {2, 'g'}, {83, 'h'}, {782, 'i'}, {1, 'j'}}; @@ -58,12 +100,38 @@ TEST(qsort, test) { free(M); } +struct Record { + int x; + int y; + int z; + int a[2]; + int b; +}; + +int CompareRecord(const void *a, const void *b) { + const struct Record *x = a; + const struct Record *y = b; + if (x->z > y->z) return -1; + if (x->z < y->z) return +1; + return 0; +} + +TEST(qsort, records) { + int i, n = 256; + struct Record *A = gc(calloc(n, sizeof(struct Record))); + struct Record *B = gc(calloc(n, sizeof(struct Record))); + for (i = 0; i < n; ++i) A[i].z = B[i].z = lemur64(); + qsort(A, n, sizeof(struct Record), CompareRecord); + mergesort(B, n, sizeof(struct Record), CompareRecord); + ASSERT_EQ(0, memcmp(A, B, n * sizeof(struct Record))); +} + TEST(qsort, equivalence_random) { size_t i; size_t n = 1000; - long *a = _gc(malloc(n * sizeof(long))); - long *b = _gc(malloc(n * sizeof(long))); - long *c = _gc(malloc(n * sizeof(long))); + long *a = gc(malloc(n * sizeof(long))); + long *b = gc(malloc(n * sizeof(long))); + long *c = gc(malloc(n * sizeof(long))); for (i = 0; i < n; ++i) a[i] = lemur64(); memcpy(b, a, n * sizeof(long)); memcpy(c, a, n * sizeof(long)); @@ -84,9 +152,9 @@ TEST(qsort, equivalence_random) { TEST(qsort, equivalence_reverse) { size_t i; size_t n = 1000; - long *a = _gc(malloc(n * sizeof(long))); - long *b = _gc(malloc(n * sizeof(long))); - long *c = _gc(malloc(n * sizeof(long))); + long *a = gc(malloc(n * sizeof(long))); + long *b = gc(malloc(n * sizeof(long))); + long *c = gc(malloc(n * sizeof(long))); for (i = 0; i < n; ++i) a[n - i - 1] = i; memcpy(b, a, n * sizeof(long)); memcpy(c, a, n * sizeof(long)); @@ -107,13 +175,15 @@ TEST(qsort, equivalence_reverse) { BENCH(qsort, bench) { size_t i; size_t n = 1000; - long *p1 = _gc(malloc(n * sizeof(long))); - long *p2 = _gc(malloc(n * sizeof(long))); + long *p1 = gc(malloc(n * sizeof(long))); + long *p2 = gc(malloc(n * sizeof(long))); printf("\n"); for (i = 0; i < n; ++i) p1[i] = i + ((lemur64() % 3) - 1); EZBENCH2("qsort nearly", memcpy(p2, p1, n * sizeof(long)), qsort(p2, n, sizeof(long), CompareLong)); + EZBENCH2("qsort_r nearly", memcpy(p2, p1, n * sizeof(long)), + qsort_r(p2, n, sizeof(long), (void *)CompareLong, 0)); EZBENCH2("heapsort nearly", memcpy(p2, p1, n * sizeof(long)), heapsort(p2, n, sizeof(long), CompareLong)); EZBENCH2("mergesort nearly", memcpy(p2, p1, n * sizeof(long)), @@ -127,6 +197,8 @@ BENCH(qsort, bench) { for (i = 0; i < n; ++i) p1[i] = n - i; EZBENCH2("qsort reverse", memcpy(p2, p1, n * sizeof(long)), qsort(p2, n, sizeof(long), CompareLong)); + EZBENCH2("qsort_r reverse", memcpy(p2, p1, n * sizeof(long)), + qsort_r(p2, n, sizeof(long), (void *)CompareLong, 0)); EZBENCH2("heapsort reverse", memcpy(p2, p1, n * sizeof(long)), heapsort(p2, n, sizeof(long), CompareLong)); EZBENCH2("mergesort reverse", memcpy(p2, p1, n * sizeof(long)), @@ -140,6 +212,8 @@ BENCH(qsort, bench) { rngset(p1, n * sizeof(long), 0, 0); EZBENCH2("qsort random", memcpy(p2, p1, n * sizeof(long)), qsort(p2, n, sizeof(long), CompareLong)); + EZBENCH2("qsort_r random", memcpy(p2, p1, n * sizeof(long)), + qsort_r(p2, n, sizeof(long), (void *)CompareLong, 0)); EZBENCH2("heapsort random", memcpy(p2, p1, n * sizeof(long)), heapsort(p2, n, sizeof(long), CompareLong)); EZBENCH2("mergesort random", memcpy(p2, p1, n * sizeof(long)), @@ -156,6 +230,8 @@ BENCH(qsort, bench) { } EZBENCH2("qsort 2n", memcpy(p2, p1, n * sizeof(long)), qsort(p2, n, sizeof(long), CompareLong)); + EZBENCH2("qsort_r 2n", memcpy(p2, p1, n * sizeof(long)), + qsort_r(p2, n, sizeof(long), (void *)CompareLong, 0)); EZBENCH2("heapsort 2n", memcpy(p2, p1, n * sizeof(long)), heapsort(p2, n, sizeof(long), CompareLong)); EZBENCH2("mergesort 2n", memcpy(p2, p1, n * sizeof(long)), diff --git a/test/libc/runtime/mprotect_test.c b/test/libc/runtime/mprotect_test.c index 69914f1c1..7a662097a 100644 --- a/test/libc/runtime/mprotect_test.c +++ b/test/libc/runtime/mprotect_test.c @@ -18,6 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/struct/sigaction.h" +#include "libc/calls/ucontext.h" #include "libc/dce.h" #include "libc/errno.h" #include "libc/fmt/fmt.h" @@ -31,6 +32,7 @@ #include "libc/sysv/consts/o.h" #include "libc/sysv/consts/prot.h" #include "libc/sysv/consts/sa.h" +#include "libc/sysv/consts/sig.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" #include "third_party/xed/x86.h" diff --git a/test/libc/stdio/fmt_test.c b/test/libc/stdio/fmt_test.c index 04e9c5824..2077056df 100644 --- a/test/libc/stdio/fmt_test.c +++ b/test/libc/stdio/fmt_test.c @@ -310,7 +310,14 @@ TEST(fmt, e) { TEST(fmt, a) { EXPECT_STREQ("0x0p+0", _gc(xasprintf("%a", 0.))); EXPECT_STREQ("0x0p+0", _gc(xasprintf("%.a", 0.))); + EXPECT_STREQ(" 0x0p+0", _gc(xasprintf("%7.a", 0.))); EXPECT_STREQ("0x0.000p+0", _gc(xasprintf("%.3a", 0.))); + // EXPECT_STREQ(" 0x0.000p+0\n", _gc(xasprintf("%11.3a\n", 0.))); // TODO + EXPECT_STREQ("inf\n", _gc(xasprintf("%g\n", INFINITY))); + EXPECT_STREQ(" inf\n", _gc(xasprintf("%5g\n", INFINITY))); + EXPECT_STREQ(" +inf\n", _gc(xasprintf("%+5g\n", INFINITY))); + EXPECT_STREQ(" inf\n", _gc(xasprintf("% g\n", INFINITY))); + EXPECT_STREQ("-inf\n", _gc(xasprintf("% g\n", -INFINITY))); EXPECT_STREQ("0x1.921fb54442d18p+1", _gc(xasprintf("%a", 0x1.921fb54442d1846ap+1))); EXPECT_STREQ("0X1.921FB54442D18P+1", diff --git a/third_party/awk/main.c b/third_party/awk/main.c index 0fa88c8cc..1ac4b710d 100644 --- a/third_party/awk/main.c +++ b/third_party/awk/main.c @@ -36,6 +36,7 @@ #include "libc/str/str.h" #include "libc/sysv/consts/sa.h" #include "libc/sysv/consts/sicode.h" +#include "libc/sysv/consts/sig.h" #include "third_party/awk/awk.h" // clang-format off diff --git a/third_party/lua/lrepl.c b/third_party/lua/lrepl.c index ecbc4f796..f7e63121b 100644 --- a/third_party/lua/lrepl.c +++ b/third_party/lua/lrepl.c @@ -40,6 +40,7 @@ #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/sysv/consts/sa.h" +#include "libc/sysv/consts/sig.h" #include "libc/thread/thread.h" #include "third_party/linenoise/linenoise.h" #include "third_party/lua/cosmo.h" diff --git a/third_party/make/commands.c b/third_party/make/commands.c index 33667bde1..595002b63 100644 --- a/third_party/make/commands.c +++ b/third_party/make/commands.c @@ -22,6 +22,7 @@ this program. If not, see . */ #include "third_party/make/variable.h" /**/ #include "libc/runtime/runtime.h" +#include "libc/sysv/consts/sig.h" #include "third_party/make/commands.h" /* clang-format off */ diff --git a/third_party/make/job.c b/third_party/make/job.c index b782890e1..34df3bf9e 100644 --- a/third_party/make/job.c +++ b/third_party/make/job.c @@ -57,6 +57,7 @@ this program. If not, see . */ #include "libc/sysv/consts/pr.h" #include "libc/sysv/consts/prot.h" #include "libc/sysv/consts/rlimit.h" +#include "libc/sysv/consts/sig.h" #include "libc/sysv/errfuns.h" #include "libc/time/time.h" #include "libc/x/x.h" diff --git a/third_party/musl/strfmon.c b/third_party/musl/strfmon.c index 6471dc632..e11e6c265 100644 --- a/third_party/musl/strfmon.c +++ b/third_party/musl/strfmon.c @@ -41,7 +41,7 @@ static ssize_t vstrfmon_l(char *s, size_t n, locale_t loc, const char *fmt, va_l { size_t l; double x; - int fill, nogrp, negpar, nosym, left, intl; + int left; int lp, rp, w, fw; char *s0=s; for (; n && *fmt; ) { @@ -54,25 +54,17 @@ static ssize_t vstrfmon_l(char *s, size_t n, locale_t loc, const char *fmt, va_l fmt++; if (*fmt == '%') goto literal; - fill = ' '; - nogrp = 0; - negpar = 0; - nosym = 0; left = 0; for (; ; fmt++) { switch (*fmt) { case '=': - fill = *++fmt; continue; case '^': - nogrp = 1; continue; case '(': - negpar = 1; case '+': continue; case '!': - nosym = 1; continue; case '-': left = 1; @@ -90,8 +82,6 @@ static ssize_t vstrfmon_l(char *s, size_t n, locale_t loc, const char *fmt, va_l if (*fmt=='.') for (rp=0, fmt++; isdigit(*fmt); fmt++) rp = 10*rp + (*fmt-'0'); - intl = *fmt++ == 'i'; - w = lp + 1 + rp; if (!left && fw>w) w = fw; diff --git a/third_party/python/Modules/cjkcodecs/__big5_decmap.c b/third_party/python/Modules/cjkcodecs/__big5_decmap.c index 3e379aba9..7d95bfb05 100644 --- a/third_party/python/Modules/cjkcodecs/__big5_decmap.c +++ b/third_party/python/Modules/cjkcodecs/__big5_decmap.c @@ -1,4 +1,5 @@ #include "libc/x/x.h" +#include "third_party/python/Modules/cjkcodecs/xloadzd.h" /* clang-format off */ static _Atomic(void *) __big5_decmap_ptr; diff --git a/third_party/python/Modules/cjkcodecs/__cp932ext_decmap.c b/third_party/python/Modules/cjkcodecs/__cp932ext_decmap.c index 04e9a9aee..5277cf29f 100644 --- a/third_party/python/Modules/cjkcodecs/__cp932ext_decmap.c +++ b/third_party/python/Modules/cjkcodecs/__cp932ext_decmap.c @@ -1,4 +1,5 @@ #include "libc/x/x.h" +#include "third_party/python/Modules/cjkcodecs/xloadzd.h" /* clang-format off */ static _Atomic(void *) __cp932ext_decmap_ptr; diff --git a/third_party/python/Modules/cjkcodecs/__cp949_encmap.c b/third_party/python/Modules/cjkcodecs/__cp949_encmap.c index 19533147c..1c5aca0f7 100644 --- a/third_party/python/Modules/cjkcodecs/__cp949_encmap.c +++ b/third_party/python/Modules/cjkcodecs/__cp949_encmap.c @@ -1,4 +1,5 @@ #include "libc/x/x.h" +#include "third_party/python/Modules/cjkcodecs/xloadzd.h" /* clang-format off */ static _Atomic(void *) __cp949_encmap_ptr; diff --git a/third_party/python/Modules/cjkcodecs/__cp949ext_decmap.c b/third_party/python/Modules/cjkcodecs/__cp949ext_decmap.c index 210167e54..9736b3a42 100644 --- a/third_party/python/Modules/cjkcodecs/__cp949ext_decmap.c +++ b/third_party/python/Modules/cjkcodecs/__cp949ext_decmap.c @@ -1,4 +1,5 @@ #include "libc/x/x.h" +#include "third_party/python/Modules/cjkcodecs/xloadzd.h" /* clang-format off */ static _Atomic(void *) __cp949ext_decmap_ptr; diff --git a/third_party/python/Modules/cjkcodecs/__cp950ext_decmap.c b/third_party/python/Modules/cjkcodecs/__cp950ext_decmap.c index 35810103e..0856106ce 100644 --- a/third_party/python/Modules/cjkcodecs/__cp950ext_decmap.c +++ b/third_party/python/Modules/cjkcodecs/__cp950ext_decmap.c @@ -1,4 +1,5 @@ #include "libc/x/x.h" +#include "third_party/python/Modules/cjkcodecs/xloadzd.h" /* clang-format off */ static _Atomic(void *) __cp950ext_decmap_ptr; diff --git a/third_party/python/Modules/cjkcodecs/__gb18030ext_decmap.c b/third_party/python/Modules/cjkcodecs/__gb18030ext_decmap.c index 288124f0a..d68c33e52 100644 --- a/third_party/python/Modules/cjkcodecs/__gb18030ext_decmap.c +++ b/third_party/python/Modules/cjkcodecs/__gb18030ext_decmap.c @@ -1,4 +1,5 @@ #include "libc/x/x.h" +#include "third_party/python/Modules/cjkcodecs/xloadzd.h" /* clang-format off */ static _Atomic(void *) __gb18030ext_decmap_ptr; diff --git a/third_party/python/Modules/cjkcodecs/__gb18030ext_encmap.c b/third_party/python/Modules/cjkcodecs/__gb18030ext_encmap.c index 29d4cef51..16fbefe2a 100644 --- a/third_party/python/Modules/cjkcodecs/__gb18030ext_encmap.c +++ b/third_party/python/Modules/cjkcodecs/__gb18030ext_encmap.c @@ -1,4 +1,5 @@ #include "libc/x/x.h" +#include "third_party/python/Modules/cjkcodecs/xloadzd.h" /* clang-format off */ static _Atomic(void *) __gb18030ext_encmap_ptr; diff --git a/third_party/python/Modules/cjkcodecs/__gb2312_decmap.c b/third_party/python/Modules/cjkcodecs/__gb2312_decmap.c index 0edab61e1..f1c87b138 100644 --- a/third_party/python/Modules/cjkcodecs/__gb2312_decmap.c +++ b/third_party/python/Modules/cjkcodecs/__gb2312_decmap.c @@ -1,4 +1,5 @@ #include "libc/x/x.h" +#include "third_party/python/Modules/cjkcodecs/xloadzd.h" /* clang-format off */ static _Atomic(void *) __gb2312_decmap_ptr; diff --git a/third_party/python/Modules/cjkcodecs/__gbcommon_encmap.c b/third_party/python/Modules/cjkcodecs/__gbcommon_encmap.c index 00aa441f7..9340d9b96 100644 --- a/third_party/python/Modules/cjkcodecs/__gbcommon_encmap.c +++ b/third_party/python/Modules/cjkcodecs/__gbcommon_encmap.c @@ -1,4 +1,5 @@ #include "libc/x/x.h" +#include "third_party/python/Modules/cjkcodecs/xloadzd.h" /* clang-format off */ static _Atomic(void *) __gbcommon_encmap_ptr; diff --git a/third_party/python/Modules/cjkcodecs/__gbkext_decmap.c b/third_party/python/Modules/cjkcodecs/__gbkext_decmap.c index 6e94a8dab..7c5042258 100644 --- a/third_party/python/Modules/cjkcodecs/__gbkext_decmap.c +++ b/third_party/python/Modules/cjkcodecs/__gbkext_decmap.c @@ -1,4 +1,5 @@ #include "libc/x/x.h" +#include "third_party/python/Modules/cjkcodecs/xloadzd.h" /* clang-format off */ static _Atomic(void *) __gbkext_decmap_ptr; diff --git a/third_party/python/Modules/cjkcodecs/__jisx0208_decmap.c b/third_party/python/Modules/cjkcodecs/__jisx0208_decmap.c index f14fa11c0..7ca761283 100644 --- a/third_party/python/Modules/cjkcodecs/__jisx0208_decmap.c +++ b/third_party/python/Modules/cjkcodecs/__jisx0208_decmap.c @@ -1,4 +1,5 @@ #include "libc/x/x.h" +#include "third_party/python/Modules/cjkcodecs/xloadzd.h" /* clang-format off */ static _Atomic(void *) __jisx0208_decmap_ptr; diff --git a/third_party/python/Modules/cjkcodecs/__jisx0212_decmap.c b/third_party/python/Modules/cjkcodecs/__jisx0212_decmap.c index b5a728644..5af83f027 100644 --- a/third_party/python/Modules/cjkcodecs/__jisx0212_decmap.c +++ b/third_party/python/Modules/cjkcodecs/__jisx0212_decmap.c @@ -1,4 +1,5 @@ #include "libc/x/x.h" +#include "third_party/python/Modules/cjkcodecs/xloadzd.h" /* clang-format off */ static _Atomic(void *) __jisx0212_decmap_ptr; diff --git a/third_party/python/Modules/cjkcodecs/__jisx0213_1_bmp_decmap.c b/third_party/python/Modules/cjkcodecs/__jisx0213_1_bmp_decmap.c index 60a711c59..fe62ff18a 100644 --- a/third_party/python/Modules/cjkcodecs/__jisx0213_1_bmp_decmap.c +++ b/third_party/python/Modules/cjkcodecs/__jisx0213_1_bmp_decmap.c @@ -1,4 +1,5 @@ #include "libc/x/x.h" +#include "third_party/python/Modules/cjkcodecs/xloadzd.h" /* clang-format off */ static _Atomic(void *) __jisx0213_1_bmp_decmap_ptr; diff --git a/third_party/python/Modules/cjkcodecs/__jisx0213_2_bmp_decmap.c b/third_party/python/Modules/cjkcodecs/__jisx0213_2_bmp_decmap.c index d924b316d..cf94cd71e 100644 --- a/third_party/python/Modules/cjkcodecs/__jisx0213_2_bmp_decmap.c +++ b/third_party/python/Modules/cjkcodecs/__jisx0213_2_bmp_decmap.c @@ -1,4 +1,5 @@ #include "libc/x/x.h" +#include "third_party/python/Modules/cjkcodecs/xloadzd.h" /* clang-format off */ static _Atomic(void *) __jisx0213_2_bmp_decmap_ptr; diff --git a/third_party/python/Modules/cjkcodecs/__jisx0213_pair_decmap.c b/third_party/python/Modules/cjkcodecs/__jisx0213_pair_decmap.c index 97fbad946..b0e6028c8 100644 --- a/third_party/python/Modules/cjkcodecs/__jisx0213_pair_decmap.c +++ b/third_party/python/Modules/cjkcodecs/__jisx0213_pair_decmap.c @@ -1,4 +1,5 @@ #include "libc/x/x.h" +#include "third_party/python/Modules/cjkcodecs/xloadzd.h" /* clang-format off */ static _Atomic(void *) __jisx0213_pair_decmap_ptr; diff --git a/third_party/python/Modules/cjkcodecs/__ksx1001_decmap.c b/third_party/python/Modules/cjkcodecs/__ksx1001_decmap.c index d0171c528..20cfe276a 100644 --- a/third_party/python/Modules/cjkcodecs/__ksx1001_decmap.c +++ b/third_party/python/Modules/cjkcodecs/__ksx1001_decmap.c @@ -1,4 +1,5 @@ #include "libc/x/x.h" +#include "third_party/python/Modules/cjkcodecs/xloadzd.h" /* clang-format off */ static _Atomic(void *) __ksx1001_decmap_ptr; diff --git a/libc/x/xloadzd.c b/third_party/python/Modules/cjkcodecs/xloadzd.c similarity index 100% rename from libc/x/xloadzd.c rename to third_party/python/Modules/cjkcodecs/xloadzd.c diff --git a/third_party/python/Modules/cjkcodecs/xloadzd.h b/third_party/python/Modules/cjkcodecs/xloadzd.h new file mode 100644 index 000000000..333382094 --- /dev/null +++ b/third_party/python/Modules/cjkcodecs/xloadzd.h @@ -0,0 +1,11 @@ +#ifndef COSMOPOLITAN_THIRD_PARTY_PYTHON_MODULES_CJKCODECS_XLOADZD_H_ +#define COSMOPOLITAN_THIRD_PARTY_PYTHON_MODULES_CJKCODECS_XLOADZD_H_ +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +void *xloadzd(_Atomic(void *) *, const void *, size_t, size_t, size_t, size_t, + uint32_t); + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_THIRD_PARTY_PYTHON_MODULES_CJKCODECS_XLOADZD_H_ */ diff --git a/third_party/python/Modules/faulthandler.c b/third_party/python/Modules/faulthandler.c index 3f566b2ed..427da6f97 100644 --- a/third_party/python/Modules/faulthandler.c +++ b/third_party/python/Modules/faulthandler.c @@ -6,6 +6,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/struct/sigaction.h" +#include "libc/calls/struct/sigaltstack.h" #include "libc/errno.h" #include "libc/sysv/consts/rlimit.h" #include "libc/sysv/consts/sa.h" diff --git a/third_party/python/python.mk b/third_party/python/python.mk index 216996f33..ffc9497f3 100644 --- a/third_party/python/python.mk +++ b/third_party/python/python.mk @@ -188,6 +188,7 @@ THIRD_PARTY_PYTHON_HDRS = \ third_party/python/Modules/_sqlite/row.h \ third_party/python/Modules/_sqlite/statement.h \ third_party/python/Modules/_sqlite/util.h \ + third_party/python/Modules/cjkcodecs/xloadzd.h \ third_party/python/Modules/cjkcodecs/cjkcodecs.h \ third_party/python/Modules/cjkcodecs/multibytecodec.h \ third_party/python/Modules/cjkcodecs/somanyencodings.h \ @@ -586,6 +587,7 @@ THIRD_PARTY_PYTHON_STAGE2_A_SRCS = \ third_party/python/Modules/atexitmodule.c \ third_party/python/Modules/audioop.c \ third_party/python/Modules/binascii.c \ + third_party/python/Modules/cjkcodecs/xloadzd.c \ third_party/python/Modules/cjkcodecs/_codecs_cn.c \ third_party/python/Modules/cjkcodecs/_codecs_hk.c \ third_party/python/Modules/cjkcodecs/_codecs_iso2022.c \ diff --git a/third_party/quickjs/quickjs-libc.c b/third_party/quickjs/quickjs-libc.c index 970cf507a..ecfa0245d 100644 --- a/third_party/quickjs/quickjs-libc.c +++ b/third_party/quickjs/quickjs-libc.c @@ -47,6 +47,7 @@ #include "libc/sysv/consts/clock.h" #include "libc/sysv/consts/o.h" #include "libc/sysv/consts/s.h" +#include "libc/sysv/consts/sig.h" #include "libc/sysv/consts/termios.h" #include "libc/sysv/consts/w.h" #include "libc/time/time.h" diff --git a/third_party/radpajama/main-redpajama-chat.cc b/third_party/radpajama/main-redpajama-chat.cc index 10e27e1a4..b56a183bb 100644 --- a/third_party/radpajama/main-redpajama-chat.cc +++ b/third_party/radpajama/main-redpajama-chat.cc @@ -41,6 +41,7 @@ #include "libc/sysv/consts/ok.h" #include "libc/sysv/consts/sa.h" #include "libc/sysv/consts/sicode.h" +#include "libc/sysv/consts/sig.h" #include "libc/sysv/consts/ss.h" #include "libc/time/time.h" #include "third_party/libcxx/algorithm" diff --git a/third_party/radpajama/main-redpajama.cc b/third_party/radpajama/main-redpajama.cc index 0e4a654c3..1cd9c82a4 100644 --- a/third_party/radpajama/main-redpajama.cc +++ b/third_party/radpajama/main-redpajama.cc @@ -41,6 +41,7 @@ #include "libc/sysv/consts/ok.h" #include "libc/sysv/consts/sa.h" #include "libc/sysv/consts/sicode.h" +#include "libc/sysv/consts/sig.h" #include "libc/sysv/consts/ss.h" #include "libc/time/time.h" #include "third_party/libcxx/cassert" diff --git a/third_party/sqlite3/shell.c b/third_party/sqlite3/shell.c index c1b8f2fc1..ce01c2686 100644 --- a/third_party/sqlite3/shell.c +++ b/third_party/sqlite3/shell.c @@ -31,6 +31,7 @@ ** This file contains code to implement the "sqlite" command line ** utility for accessing SQLite databases. */ +#include "libc/dce.h" #if (defined(_WIN32) || defined(WIN32)) && !defined(_CRT_SECURE_NO_WARNINGS) /* This needs to come before any includes for MSVC compiler */ #define _CRT_SECURE_NO_WARNINGS diff --git a/third_party/zip/zip.c b/third_party/zip/zip.c index 4b2b33ee1..1216e3d29 100644 --- a/third_party/zip/zip.c +++ b/third_party/zip/zip.c @@ -56,6 +56,7 @@ #include "third_party/zip/ttyio.h" #include "libc/str/str.h" #include "libc/errno.h" +#include "libc/sysv/consts/sig.h" #include "third_party/bzip2/bzlib.h" #ifdef VMS diff --git a/third_party/zip/zip.mk b/third_party/zip/zip.mk index bc92a2532..048d4c28c 100644 --- a/third_party/zip/zip.mk +++ b/third_party/zip/zip.mk @@ -91,7 +91,8 @@ THIRD_PARTY_ZIP_DIRECTDEPS = \ LIBC_SYSV \ LIBC_TIME \ LIBC_X \ - THIRD_PARTY_BZIP2 + THIRD_PARTY_BZIP2 \ + THIRD_PARTY_ZLIB THIRD_PARTY_ZIP_DEPS := \ $(call uniq,$(foreach x,$(THIRD_PARTY_ZIP_DIRECTDEPS),$($(x)))) diff --git a/third_party/zip/zipnote.c b/third_party/zip/zipnote.c index a3a339036..19ed23dcd 100644 --- a/third_party/zip/zipnote.c +++ b/third_party/zip/zipnote.c @@ -26,6 +26,7 @@ #include "libc/calls/struct/siginfo.h" #include "libc/sysv/consts/sa.h" #include "libc/sysv/consts/sicode.h" +#include "libc/sysv/consts/sig.h" #include "libc/sysv/consts/ss.h" /* Calculate size of static line buffer used in write (-w) mode. */ diff --git a/third_party/zip/zipsplit.c b/third_party/zip/zipsplit.c index 725407be9..399bf7f9f 100644 --- a/third_party/zip/zipsplit.c +++ b/third_party/zip/zipsplit.c @@ -26,6 +26,7 @@ #include "libc/calls/struct/siginfo.h" #include "libc/sysv/consts/sa.h" #include "libc/sysv/consts/sicode.h" +#include "libc/sysv/consts/sig.h" #include "libc/sysv/consts/ss.h" #define DEFSIZ 36000L /* Default split size (change in help() too) */ diff --git a/third_party/zstd/programs/fileio.c b/third_party/zstd/programs/fileio.c index 5182836d9..4c0312b38 100644 --- a/third_party/zstd/programs/fileio.c +++ b/third_party/zstd/programs/fileio.c @@ -85,6 +85,7 @@ #include "libc/sysv/consts/sa.h" #include "libc/sysv/consts/sicode.h" #include "libc/sysv/consts/ss.h" +#include "libc/sysv/consts/sig.h" #include "third_party/zstd/programs/timefn.h" /* UTIL_getTime, UTIL_clockSpanMicro */ #if defined (_MSC_VER) diff --git a/tool/build/compile.c b/tool/build/compile.c index e4f47f8fd..29eeaf6c1 100644 --- a/tool/build/compile.c +++ b/tool/build/compile.c @@ -227,6 +227,7 @@ const char *const kGccOnlyFlags[] = { "-fcx-limited-range", "-fdelete-dead-exceptions", "-femit-struct-debug-baseonly", + "-ffp-int-builtin-inexact", "-fipa-pta", "-fivopts", "-flimit-function-alignment", @@ -236,6 +237,7 @@ const char *const kGccOnlyFlags[] = { "-fno-align-jumps", "-fno-align-labels", "-fno-align-loops", + "-fno-cx-limited-range", "-fno-fp-int-builtin-inexact", "-fno-gnu-unique", "-fno-gnu-unique", @@ -1155,11 +1157,13 @@ int main(int argc, char *argv[]) { } else if (_startswith(argv[i], "-fsanitize=implicit") && strstr(argv[i], "integer")) { if (isgcc) AddArg(argv[i]); + } else if (strstr(argv[i], "stack-protector")) { + if (isclang || (isgcc && ccversion >= 6)) { + AddArg(argv[i]); + } } else if (_startswith(argv[i], "-fvect-cost") || _startswith(argv[i], "-mstringop") || - _startswith(argv[i], "-gz") || - strstr(argv[i], "stack-protector") || - strstr(argv[i], "sanitize") || + _startswith(argv[i], "-gz") || strstr(argv[i], "sanitize") || _startswith(argv[i], "-fvect-cost") || _startswith(argv[i], "-fvect-cost")) { if (isgcc && ccversion >= 6) { diff --git a/tool/emacs/cosmo-c-builtins.el b/tool/emacs/cosmo-c-builtins.el index d70bed890..14c9dbfc0 100644 --- a/tool/emacs/cosmo-c-builtins.el +++ b/tool/emacs/cosmo-c-builtins.el @@ -163,7 +163,8 @@ "__sync_lock_release")) (gcc-builtin-functions-ia32 - '("__builtin_ia32_pmovmskb128")) + '("__builtin_ia32_pmovmskb128" + "__builtin_ia32_pmovmskb256")) (gxx-builtin-type-traits '("__has_nothrow_assign" diff --git a/tool/scripts/cosmoc++ b/tool/scripts/cosmoc++ index b3d8e49c2..1dabd19ba 100755 --- a/tool/scripts/cosmoc++ +++ b/tool/scripts/cosmoc++ @@ -183,7 +183,7 @@ if [ $INTENT = cpp ]; then elif [ $INTENT = cc ]; then set -- $PLATFORM $PREDEF $CCFLAGS $CXXFLAGS $CPPFLAGS "$@" $FRAME else - set -- $PLATFORM $PREDEF $LDFLAGS $APEFLAGS $CXXFLAGS $CPPFLAGS "$@" \ + set -- $PLATFORM $PREDEF $CCFLAGS $CXXFLAGS $CPPFLAGS $LDFLAGS $APEFLAGS $CXXFLAGS $CPPFLAGS "$@" \ $LDLIBS -Wl,-z,common-page-size=4096 -Wl,-z,max-page-size=4096 $FRAME fi diff --git a/tool/scripts/cosmocc b/tool/scripts/cosmocc index 8a625add8..4315525d9 100755 --- a/tool/scripts/cosmocc +++ b/tool/scripts/cosmocc @@ -181,7 +181,7 @@ if [ $INTENT = cpp ]; then elif [ $INTENT = cc ]; then set -- $PLATFORM $PREDEF $CCFLAGS $CFLAGS $CPPFLAGS "$@" $FRAME else - set -- $PLATFORM $PREDEF $LDFLAGS $APEFLAGS $CFLAGS $CPPFLAGS "$@" \ + set -- $PLATFORM $PREDEF $CCFLAGS $CFLAGS $CPPFLAGS $LDFLAGS $APEFLAGS $CFLAGS $CPPFLAGS "$@" \ $LDLIBS -Wl,-z,common-page-size=4096 -Wl,-z,max-page-size=4096 $FRAME fi diff --git a/tool/viz/memzoom.c b/tool/viz/memzoom.c index 691ed5eb7..8210595ce 100644 --- a/tool/viz/memzoom.c +++ b/tool/viz/memzoom.c @@ -26,6 +26,7 @@ #include "libc/calls/struct/winsize.h" #include "libc/calls/termios.h" #include "libc/calls/ucontext.h" +#include "libc/dce.h" #include "libc/errno.h" #include "libc/fmt/conv.h" #include "libc/fmt/itoa.h"