From c3440d040c57316b91632d3c3b4fb1316b2fa87c Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Thu, 15 Jun 2023 13:50:42 -0700 Subject: [PATCH] Make improvements - More timspec_*() and timeval_*() APIs have been introduced. - The copyfd() function is now simplified thanks to POSIX rules. - More Cosmo-specific APIs have been moved behind the COSMO define. - The setitimer() polyfill for Windows NT is now much higher quality. - Fixed build error for MODE=aarch64 due to -mstringop-strategy=loop. - This change introduces `make MODE=nox87 toolchain` which makes it possible to build programs using your cosmocc toolchain that don't have legacy fpu instructions. This is useful, for example, if you want to have a ~22kb tinier blink virtual machine. --- build/config.mk | 22 ++++ libc/calls/__sig2.c | 1 - libc/calls/calls.h | 70 ++++------ libc/calls/calls.mk | 2 + libc/calls/clock_gettime.c | 1 - libc/{mem/copyfd.c => calls/copy.c} | 73 ++++------- libc/calls/futimes.c | 2 +- libc/calls/getitimer.c | 10 +- libc/calls/gettimeofday.c | 4 +- libc/calls/setitimer-nt.c | 123 ++++-------------- libc/calls/setitimer.c | 27 +--- libc/calls/struct/itimerval.internal.h | 4 +- libc/calls/struct/timespec.h | 11 +- libc/calls/struct/timeval.h | 10 ++ libc/calls/struct/timeval.internal.h | 4 + libc/calls/{fmodl.S => timespec_subz.c} | 45 +++---- libc/calls/timeval_real.c | 31 +++++ libc/calls/timeval_subz.c | 30 +++++ libc/calls/utimes.c | 2 +- libc/intrin/asan.c | 6 +- libc/intrin/describearchprctlcode.c | 1 + libc/intrin/describeflags.internal.h | 2 + libc/intrin/describeitimer.c | 29 +++++ .../intrin/describeitimerval.c | 79 +++-------- libc/intrin/describemapflags.c | 1 - libc/intrin/describeopenflags.c | 43 ++++-- libc/intrin/describetimeval.c | 2 +- libc/intrin/fenv.S | 19 ++- libc/intrin/fmax.c | 2 +- libc/intrin/scalbn.c | 4 +- libc/mem/copyfd.internal.h | 10 -- libc/runtime/cosmo.S | 2 + libc/runtime/runtime.h | 36 ++--- libc/runtime/set_tls.c | 5 +- libc/sysv/consts.sh | 3 - libc/sysv/consts/MAP_HUGETLB.S | 2 - libc/sysv/consts/MAP_HUGE_MASK.S | 2 - libc/sysv/consts/MAP_HUGE_SHIFT.S | 2 - libc/sysv/consts/arch.h | 9 ++ libc/sysv/consts/map.h | 3 - libc/testlib/extract.c | 3 +- libc/tinymath/acos.c | 2 +- libc/tinymath/acosh.c | 2 +- libc/tinymath/asin.c | 2 +- libc/tinymath/asinh.c | 2 +- libc/tinymath/atan.c | 2 +- libc/tinymath/atan2.c | 2 +- libc/tinymath/atanh.c | 2 +- libc/tinymath/cabs.c | 2 +- libc/tinymath/cacosh.c | 2 +- libc/tinymath/carg.c | 2 +- libc/tinymath/casin.c | 2 +- libc/tinymath/catan.c | 2 +- libc/tinymath/copysign.c | 2 +- libc/tinymath/cos.c | 2 +- libc/tinymath/cosh.c | 4 + libc/tinymath/coshl.c | 3 + libc/tinymath/exp.c | 2 +- libc/tinymath/exp10.c | 3 +- libc/tinymath/exp10l.c | 2 +- libc/tinymath/exp2.c | 2 +- libc/tinymath/expm1.c | 2 +- libc/tinymath/fabs.c | 2 +- libc/tinymath/fdim.c | 2 +- libc/tinymath/floor.c | 2 +- libc/tinymath/fmin.c | 2 +- libc/tinymath/fmod.c | 4 + libc/tinymath/fmodl.c | 12 +- libc/tinymath/frexp.c | 2 +- libc/tinymath/hypot.c | 2 +- libc/tinymath/ilogb.c | 2 +- libc/tinymath/ilogbl.c | 88 ------------- libc/tinymath/ktanl.c | 3 + libc/tinymath/log.c | 2 +- libc/tinymath/log10.c | 2 +- libc/tinymath/log1p.c | 2 +- libc/tinymath/log2.c | 2 +- libc/tinymath/logb.c | 4 + libc/tinymath/lrint.c | 4 +- libc/tinymath/lround.c | 2 +- libc/tinymath/modf.c | 7 + libc/tinymath/modfl.c | 20 +-- libc/tinymath/nearbyint.c | 2 +- libc/tinymath/nextafter.c | 2 +- libc/tinymath/pow.c | 2 +- libc/tinymath/remainder.c | 2 +- libc/tinymath/rempio2.c | 4 + libc/tinymath/rempio2l.c | 3 + libc/tinymath/remquo.c | 2 +- libc/tinymath/rint.c | 2 +- libc/tinymath/round.c | 2 +- libc/tinymath/scalbln.c | 2 +- libc/tinymath/significand.c | 2 +- libc/tinymath/sin.c | 2 +- libc/tinymath/sincos.c | 2 +- libc/tinymath/sinh.c | 4 + libc/tinymath/sinhl.c | 3 + libc/tinymath/sqrt.c | 2 +- libc/tinymath/tan.c | 2 +- libc/tinymath/tanh.c | 4 + libc/tinymath/tanhl.c | 3 + libc/tinymath/tinymath.h | 0 libc/tinymath/trunc.c | 2 +- libc/x/x.h | 3 - libc/x/xdtoa.c | 4 + libc/x/xdtoal.c | 7 +- test/libc/calls/pledge_test.c | 1 - test/libc/calls/unveil_test.c | 1 - test/libc/log/backtrace_test.c | 1 - test/libc/stdio/system_test.c | 1 - test/tool/plinko/plinko_test.c | 5 +- third_party/compiler_rt/addtf3.c | 4 + third_party/compiler_rt/divtc3.c | 4 + third_party/compiler_rt/divxc3.c | 4 + third_party/compiler_rt/fixunsxfdi.c | 4 + third_party/compiler_rt/fixunsxfsi.c | 4 + third_party/compiler_rt/fixunsxfti.c | 4 + third_party/compiler_rt/fixxfdi.c | 4 + third_party/compiler_rt/fixxfti.c | 4 + third_party/compiler_rt/ilogbl.c | 24 ++-- third_party/compiler_rt/logbl.c | 12 +- third_party/nsync/compat.S | 4 - third_party/nsync/futex.c | 6 +- tool/build/ar.c | 5 +- tool/build/compile.c | 3 +- tool/build/cp.c | 3 +- tool/build/ocat.c | 1 - tool/build/pledge.c | 3 +- tool/plinko/lib/plinko.c | 1 + tool/scripts/cosmoc++ | 4 + tool/scripts/cosmocc | 4 + tool/viz/printpeb.c | 3 +- 132 files changed, 539 insertions(+), 587 deletions(-) rename libc/{mem/copyfd.c => calls/copy.c} (60%) rename libc/calls/{fmodl.S => timespec_subz.c} (67%) create mode 100644 libc/calls/timeval_real.c create mode 100644 libc/calls/timeval_subz.c create mode 100644 libc/intrin/describeitimer.c rename tool/viz/int2float.c => libc/intrin/describeitimerval.c (51%) delete mode 100644 libc/mem/copyfd.internal.h delete mode 100644 libc/sysv/consts/MAP_HUGETLB.S delete mode 100644 libc/sysv/consts/MAP_HUGE_MASK.S delete mode 100644 libc/sysv/consts/MAP_HUGE_SHIFT.S create mode 100644 libc/sysv/consts/arch.h delete mode 100644 libc/tinymath/ilogbl.c delete mode 100755 libc/tinymath/tinymath.h diff --git a/build/config.mk b/build/config.mk index db149cd81..4339931aa 100644 --- a/build/config.mk +++ b/build/config.mk @@ -364,6 +364,28 @@ TARGET_ARCH ?= \ -msse3 endif +# no x87 instructions mode +# +# export MODE=nox87 +# make -j8 toolchain +# cosmocc -o /tmp/hello.com hello.c +# +# lets you shave ~23kb off blink +# +# git clone https://github.com/jart/blink +# cd blink +# ./configure --disable-x87 +# make -j8 +# o//blink/blink /tmp/hello.com +# +ifeq ($(MODE), nox87) +ENABLE_FTRACE = 1 +CONFIG_COPTS += -mlong-double-64 +CONFIG_CCFLAGS += $(BACKTRACES) -O2 +CONFIG_CPPFLAGS += -DSYSDEBUG -DNOX87 +TARGET_ARCH ?= -msse3 +endif + # LLVM Mode ifeq ($(MODE), llvm) TARGET_ARCH ?= -msse3 diff --git a/libc/calls/__sig2.c b/libc/calls/__sig2.c index 2085d09c3..1b6439665 100644 --- a/libc/calls/__sig2.c +++ b/libc/calls/__sig2.c @@ -33,7 +33,6 @@ #include "libc/sysv/consts/sig.h" #include "libc/sysv/errfuns.h" #include "libc/thread/tls.h" - #ifdef __x86_64__ /** diff --git a/libc/calls/calls.h b/libc/calls/calls.h index 02a835df9..8c772f93a 100644 --- a/libc/calls/calls.h +++ b/libc/calls/calls.h @@ -42,14 +42,6 @@ #define MAP_FAILED ((void *)-1) -#define ARCH_SET_GS 0x1001 -#define ARCH_SET_FS 0x1002 -#define ARCH_GET_FS 0x1003 -#define ARCH_GET_GS 0x1004 - -#define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT) -#define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT) - #define WCOREDUMP(s) (128 & (s)) #define WEXITSTATUS(s) ((0xff00 & (s)) >> 8) #define WIFCONTINUED(s) ((s) == 0xffff) @@ -69,11 +61,9 @@ COSMOPOLITAN_C_START_ typedef int sig_atomic_t; bool32 isatty(int) nosideeffect; -char *commandv(const char *, char *, size_t); char *get_current_dir_name(void) dontdiscard; char *getcwd(char *, size_t); char *realpath(const char *, char *); -char *replaceuser(const char *) dontdiscard; char *ttyname(int); int access(const char *, int) dontthrow; int chdir(const char *); @@ -122,7 +112,6 @@ int getpriority(int, unsigned); int getresgid(unsigned *, unsigned *, unsigned *); int getresuid(unsigned *, unsigned *, unsigned *); int getsid(int) nosideeffect libcesque; -int gettid(void) libcesque; int ioprio_get(int, int); int ioprio_set(int, int, int); int issetugid(void); @@ -133,8 +122,6 @@ int lchown(const char *, unsigned, unsigned); int link(const char *, const char *) dontthrow; int linkat(int, const char *, int, const char *, int); int madvise(void *, uint64_t, int); -int makedirs(const char *, unsigned); -int memfd_create(const char *, unsigned int); int mincore(void *, size_t, unsigned char *); int mkdir(const char *, unsigned); int mkdirat(int, const char *, unsigned); @@ -146,14 +133,10 @@ int nice(int); int open(const char *, int, ...); int openat(int, const char *, int, ...); int pause(void); -int personality(uint64_t); int pipe(int[hasatleast 2]); int pipe2(int[hasatleast 2], int); -int pivot_root(const char *, const char *); -int pledge(const char *, const char *); int posix_fadvise(int, int64_t, int64_t, int); int posix_madvise(void *, uint64_t, int); -int prctl(int, ...); int raise(int); int reboot(int); int remove(const char *); @@ -161,7 +144,6 @@ int rename(const char *, const char *); int renameat(int, const char *, int, const char *); int rmdir(const char *); int sched_yield(void); -int seccomp(unsigned, unsigned, void *); int setegid(unsigned); int seteuid(unsigned); int setfsgid(unsigned); @@ -182,37 +164,21 @@ int siginterrupt(int, int); int symlink(const char *, const char *); int symlinkat(const char *, int, const char *); int sync_file_range(int, int64_t, int64_t, unsigned); -int sys_iopl(int); -int sys_mlock(const void *, size_t); -int sys_mlock2(const void *, size_t, int); -int sys_mlockall(int); -int sys_munlock(const void *, size_t); -int sys_munlockall(void); -int sys_ptrace(int, ...); -int sys_sysctl(const int *, unsigned, void *, size_t *, void *, size_t); int tcgetpgrp(int); int tcsetpgrp(int, int); -int tgkill(int, int, int); -int tkill(int, int); -int tmpfd(void); -int touch(const char *, unsigned); int truncate(const char *, int64_t); int ttyname_r(int, char *, size_t); int unlink(const char *); -int unlink_s(const char **); int unlinkat(int, const char *, int); -int unveil(const char *, const char *); int usleep(unsigned); int vfork(void) returnstwice; int wait(int *); int waitpid(int, int *, int); -long ptrace(int, ...); ssize_t copy_file_range(int, long *, int, long *, size_t, unsigned); ssize_t lseek(int, int64_t, int); ssize_t pread(int, void *, size_t, int64_t); ssize_t pwrite(int, const void *, size_t, int64_t); ssize_t read(int, void *, size_t); -ssize_t readansi(int, char *, size_t); ssize_t readlink(const char *, char *, size_t); ssize_t readlinkat(int, const char *, char *, size_t); ssize_t splice(int, int64_t *, int, int64_t *, size_t, unsigned); @@ -225,20 +191,38 @@ unsigned umask(unsigned); void sync(void); #ifdef COSMO -#define fileexists __fileexists -#define isdirectory __isdirectory -#define isexecutable __isexecutable -#define isregularfile __isregularfile -#define issymlink __issymlink -#define ischardev __ischardev -#define copyfd __copyfd bool fileexists(const char *); bool isdirectory(const char *); bool isexecutable(const char *); bool isregularfile(const char *); bool issymlink(const char *); -bool32 ischardev(int) nosideeffect; -ssize_t copyfd(int, int64_t *, int, int64_t *, size_t, unsigned); +bool32 ischardev(int); +char *commandv(const char *, char *, size_t); +char *replaceuser(const char *) dontdiscard; +int gettid(void) libcesque; +int makedirs(const char *, unsigned); +int memfd_create(const char *, unsigned int); +int personality(uint64_t); +int pivot_root(const char *, const char *); +int pledge(const char *, const char *); +int prctl(int, ...); +int seccomp(unsigned, unsigned, void *); +int sys_iopl(int); +int sys_mlock(const void *, size_t); +int sys_mlock2(const void *, size_t, int); +int sys_mlockall(int); +int sys_munlock(const void *, size_t); +int sys_munlockall(void); +int sys_ptrace(int, ...); +int sys_sysctl(const int *, unsigned, void *, size_t *, void *, size_t); +int tgkill(int, int, int); +int tkill(int, int); +int tmpfd(void); +int touch(const char *, unsigned); +int unveil(const char *, const char *); +long ptrace(int, ...); +ssize_t copyfd(int, int, size_t); +ssize_t readansi(int, char *, size_t); #endif COSMOPOLITAN_C_END_ diff --git a/libc/calls/calls.mk b/libc/calls/calls.mk index 2cb92d6cf..dbe7e7633 100644 --- a/libc/calls/calls.mk +++ b/libc/calls/calls.mk @@ -103,6 +103,7 @@ o/$(MODE)/libc/calls/ntcontext2linux.o: private \ COPTS += \ -fno-sanitize=all +ifneq ($(ARCH), aarch64) # we always want -O3 because: # it makes the code size smaller too # we need -mstringop-strategy=loop because: @@ -116,6 +117,7 @@ o/$(MODE)/libc/calls/ntcontext2linux.o: private \ COPTS += \ -O3 \ -mstringop-strategy=loop +endif # we must disable static stack safety because: # these functions use alloca(n) diff --git a/libc/calls/clock_gettime.c b/libc/calls/clock_gettime.c index 5e0cced34..09b18ca7a 100644 --- a/libc/calls/clock_gettime.c +++ b/libc/calls/clock_gettime.c @@ -42,7 +42,6 @@ * time. Among the more popular is CLOCK_MONOTONIC. This function has a * zero syscall implementation of that on modern x86. * - * nowl l: 45𝑐 15𝑛𝑠 * rdtsc l: 13𝑐 4𝑛𝑠 * gettimeofday l: 44𝑐 14𝑛𝑠 * clock_gettime l: 40𝑐 13𝑛𝑠 diff --git a/libc/mem/copyfd.c b/libc/calls/copy.c similarity index 60% rename from libc/mem/copyfd.c rename to libc/calls/copy.c index 2ac7f7fd2..3eff499c4 100644 --- a/libc/mem/copyfd.c +++ b/libc/calls/copy.c @@ -17,59 +17,34 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/errno.h" -#include "libc/mem/mem.h" - -#define CHUNK 32768 +#include "libc/macros.internal.h" /** - * Copies data between fds the old fashioned way. + * Copies data between file descriptors the old fashioned way. * - * @return bytes successfully exchanged + * This function is intended for simple programs without signals. If + * signals are in play, then `SA_RESTART` needs to be used. + * + * @param in is input file descriptor + * @param out is input file descriptor + * @param n is number of bytes to exchange, or -1 for until eof + * @return bytes successfully exchanged, or -1 w/ errno */ -ssize_t _copyfd(int infd, int outfd, size_t n) { - int e; - char *buf; - ssize_t rc; - size_t i, j, got, sent; - rc = 0; - if (n) { - if ((buf = malloc(CHUNK))) { - for (e = errno, i = 0; i < n; i += j) { - rc = read(infd, buf, CHUNK); - if (rc == -1) { - // eintr may interrupt the read operation - if (i && errno == EINTR) { - // suppress error if partially completed - errno = e; - rc = i; - } - break; - } - got = rc; - if (!got) { - rc = i; - break; - } - // write operation must complete - for (j = 0; j < got; j += sent) { - rc = write(outfd, buf + j, got - j); - if (rc != -1) { - sent = rc; - } else if (errno == EINTR) { - // write operation must be uninterruptible - errno = e; - sent = 0; - } else { - break; - } - } - if (rc == -1) break; - } - free(buf); - } else { - rc = -1; +ssize_t copyfd(int in, int out, size_t n) { + size_t i; + char buf[512]; + ssize_t dr, dw; + for (i = 0; i < n; i += dr) { + dr = read(in, buf, MIN(n - i, sizeof(buf))); + if (dr == -1) return -1; + if (!dr) break; + dw = write(out, buf, dr); + if (dw == -1) return -1; + if (dw != dr) { + // POSIX requires atomic IO up to PIPE_BUF + // The minimum permissible PIPE_BUF is 512 + __builtin_trap(); } } - return rc; + return i; } diff --git a/libc/calls/futimes.c b/libc/calls/futimes.c index 83547baee..bb0436617 100644 --- a/libc/calls/futimes.c +++ b/libc/calls/futimes.c @@ -17,10 +17,10 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/asan.internal.h" -#include "libc/calls/struct/itimerval.internal.h" #include "libc/calls/struct/timespec.h" #include "libc/calls/struct/timespec.internal.h" #include "libc/calls/struct/timeval.h" +#include "libc/calls/struct/timeval.internal.h" #include "libc/dce.h" #include "libc/intrin/strace.internal.h" #include "libc/sysv/errfuns.h" diff --git a/libc/calls/getitimer.c b/libc/calls/getitimer.c index 56422ac39..e2c3be1a1 100644 --- a/libc/calls/getitimer.c +++ b/libc/calls/getitimer.c @@ -21,6 +21,7 @@ #include "libc/calls/struct/itimerval.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" +#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/sysv/errfuns.h" @@ -41,12 +42,7 @@ int getitimer(int which, struct itimerval *curvalue) { } else { rc = sys_setitimer_nt(which, 0, curvalue); } - if (curvalue) { - STRACE("getitimer(%d, [{{%'ld, %'ld}, {%'ld, %'ld}}]) → %d% m", which, - curvalue->it_interval.tv_sec, curvalue->it_interval.tv_usec, - curvalue->it_value.tv_sec, curvalue->it_value.tv_usec, rc); - } else { - STRACE("getitimer(%d, 0) → %d% m", which, rc); - } + STRACE("getitimer(%s, [%s]) → %d% m", DescribeItimer(which), + DescribeItimerval(rc, curvalue), rc); return rc; } diff --git a/libc/calls/gettimeofday.c b/libc/calls/gettimeofday.c index 77b165a09..11c401bdd 100644 --- a/libc/calls/gettimeofday.c +++ b/libc/calls/gettimeofday.c @@ -38,13 +38,13 @@ static gettimeofday_f *__gettimeofday = __gettimeofday_init; * Returns system wall time in microseconds, e.g. * * int64_t t; - * char p[30]; + * char p[20]; * struct tm tm; * struct timeval tv; * gettimeofday(&tv, 0); * t = tv.tv_sec; * gmtime_r(&t, &tm); - * FormatHttpDateTime(p, &tm); + * iso8601(p, &tm); * printf("%s\n", p); * * @param tv points to timeval that receives result if non-NULL diff --git a/libc/calls/setitimer-nt.c b/libc/calls/setitimer-nt.c index 15620e889..597033585 100644 --- a/libc/calls/setitimer-nt.c +++ b/libc/calls/setitimer-nt.c @@ -16,120 +16,49 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/assert.h" -#include "libc/calls/calls.h" #include "libc/calls/sig.internal.h" #include "libc/calls/struct/itimerval.h" -#include "libc/calls/struct/siginfo.h" -#include "libc/dce.h" -#include "libc/errno.h" -#include "libc/fmt/conv.h" -#include "libc/intrin/bits.h" -#include "libc/intrin/strace.internal.h" -#include "libc/log/check.h" -#include "libc/math.h" -#include "libc/nexgen32e/nexgen32e.h" -#include "libc/nexgen32e/nt2sysv.h" -#include "libc/nt/files.h" -#include "libc/nt/runtime.h" -#include "libc/nt/synchronization.h" -#include "libc/nt/thread.h" -#include "libc/str/str.h" +#include "libc/calls/struct/timeval.h" #include "libc/sysv/consts/itimer.h" #include "libc/sysv/consts/sicode.h" #include "libc/sysv/consts/sig.h" #include "libc/sysv/errfuns.h" -#include "libc/time/time.h" - #ifdef __x86_64__ -/** - * @fileoverview Heartbreaking polyfill for SIGALRM on NT. - * - * Threads are used to trigger the SIGALRM handler, which should - * hopefully be an unfancy function like this: - * - * void OnAlarm(int sig, struct siginfo *si, struct ucontext *uc) { - * g_alarmed = true; - * } - * - * This is needed because WIN32 provides no obvious solutions for - * interrupting i/o operations on the standard input handle. - */ - -static bool __hastimer; -static bool __singleshot; -static long double __lastalrm; -static long double __interval; +static struct itimerval g_setitimer; textwindows void _check_sigalrm(void) { - // TODO(jart): use a different timing source - // TODO(jart): synchronize across intervals? - long double now, elapsed; - if (!__hastimer) return; - now = nowl(); - elapsed = now - __lastalrm; - if (elapsed > __interval) { - __sig_add(0, SIGALRM, SI_TIMER); - if (__singleshot) { - __hastimer = false; - } else { - __lastalrm = now; - } + struct timeval now; + if (timeval_iszero(g_setitimer.it_value)) return; + now = timeval_real(); + if (timeval_cmp(now, g_setitimer.it_value) < 0) return; + if (timeval_iszero(g_setitimer.it_interval)) { + g_setitimer.it_value = timeval_zero; + } else { + do { + g_setitimer.it_value = + timeval_add(g_setitimer.it_value, g_setitimer.it_interval); + } while (timeval_cmp(now, g_setitimer.it_value) > 0); } + __sig_add(0, SIGALRM, SI_TIMER); } -textwindows int sys_setitimer_nt(int which, const struct itimerval *newvalue, - struct itimerval *out_opt_oldvalue) { - long double elapsed, untilnext; - - if (which != ITIMER_REAL || - (newvalue && (!(0 <= newvalue->it_value.tv_usec && - newvalue->it_value.tv_usec < 1000000) || - !(0 <= newvalue->it_interval.tv_usec && - newvalue->it_interval.tv_usec < 1000000)))) { +textwindows int sys_setitimer_nt(int which, const struct itimerval *neu, + struct itimerval *old) { + if (which != ITIMER_REAL || (neu && (!timeval_isvalid(neu->it_value) || + !timeval_isvalid(neu->it_interval)))) { return einval(); } - - if (out_opt_oldvalue) { - if (__hastimer) { - elapsed = nowl() - __lastalrm; - if (elapsed > __interval) { - untilnext = 0; - } else { - untilnext = __interval - elapsed; - } - out_opt_oldvalue->it_interval.tv_sec = __interval; - out_opt_oldvalue->it_interval.tv_usec = 1 / 1e6 * fmodl(__interval, 1); - out_opt_oldvalue->it_value.tv_sec = untilnext; - out_opt_oldvalue->it_value.tv_usec = 1 / 1e6 * fmodl(untilnext, 1); - } else { - out_opt_oldvalue->it_interval.tv_sec = 0; - out_opt_oldvalue->it_interval.tv_usec = 0; - out_opt_oldvalue->it_value.tv_sec = 0; - out_opt_oldvalue->it_value.tv_usec = 0; - } + if (old) { + old->it_interval = g_setitimer.it_interval; + old->it_value = timeval_subz(g_setitimer.it_value, timeval_real()); } - - if (newvalue) { - if (newvalue->it_interval.tv_sec || newvalue->it_interval.tv_usec || - newvalue->it_value.tv_sec || newvalue->it_value.tv_usec) { - __hastimer = true; - if (newvalue->it_interval.tv_sec || newvalue->it_interval.tv_usec) { - __singleshot = false; - __interval = newvalue->it_interval.tv_sec + - 1 / 1e6 * newvalue->it_interval.tv_usec; - } else { - __singleshot = true; - __interval = - newvalue->it_value.tv_sec + 1 / 1e6 * newvalue->it_value.tv_usec; - } - __lastalrm = nowl(); - } else { - __hastimer = false; - } + if (neu) { + g_setitimer.it_interval = neu->it_interval; + g_setitimer.it_value = timeval_iszero(neu->it_value) + ? timeval_zero + : timeval_add(timeval_real(), neu->it_value); } - return 0; } diff --git a/libc/calls/setitimer.c b/libc/calls/setitimer.c index 725ad24c8..e7decb065 100644 --- a/libc/calls/setitimer.c +++ b/libc/calls/setitimer.c @@ -20,6 +20,7 @@ #include "libc/calls/struct/itimerval.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" +#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/sysv/errfuns.h" #include "libc/time/time.h" @@ -66,7 +67,6 @@ int setitimer(int which, const struct itimerval *newvalue, struct itimerval *oldvalue) { int rc; - if (IsAsan() && ((newvalue && !__asan_is_valid(newvalue, sizeof(*newvalue))) || (oldvalue && !__asan_is_valid(oldvalue, sizeof(*oldvalue))))) { @@ -80,28 +80,7 @@ int setitimer(int which, const struct itimerval *newvalue, } else { rc = sys_setitimer_nt(which, newvalue, oldvalue); } - -#ifdef SYSDEBUG - if (newvalue && oldvalue) { - STRACE("setitimer(%d, " - "{{%'ld, %'ld}, {%'ld, %'ld}}, " - "[{{%'ld, %'ld}, {%'ld, %'ld}}]) → %d% m", - which, newvalue->it_interval.tv_sec, newvalue->it_interval.tv_usec, - newvalue->it_value.tv_sec, newvalue->it_value.tv_usec, - oldvalue->it_interval.tv_sec, oldvalue->it_interval.tv_usec, - oldvalue->it_value.tv_sec, oldvalue->it_value.tv_usec, rc); - } else if (newvalue) { - STRACE("setitimer(%d, {{%'ld, %'ld}, {%'ld, %'ld}}, NULL) → %d% m", which, - newvalue->it_interval.tv_sec, newvalue->it_interval.tv_usec, - newvalue->it_value.tv_sec, newvalue->it_value.tv_usec, rc); - } else if (oldvalue) { - STRACE("setitimer(%d, NULL, [{{%'ld, %'ld}, {%'ld, %'ld}}]) → %d% m", which, - oldvalue->it_interval.tv_sec, oldvalue->it_interval.tv_usec, - oldvalue->it_value.tv_sec, oldvalue->it_value.tv_usec, rc); - } else { - STRACE("setitimer(%d, NULL, NULL) → %d% m", which, rc); - } -#endif - + STRACE("setitimer(%s, %s, [%s]) → %d% m", DescribeItimer(which), + DescribeItimerval(0, newvalue), DescribeItimerval(rc, oldvalue), rc); return rc; } diff --git a/libc/calls/struct/itimerval.internal.h b/libc/calls/struct/itimerval.internal.h index 3a1437a20..b3a50084c 100644 --- a/libc/calls/struct/itimerval.internal.h +++ b/libc/calls/struct/itimerval.internal.h @@ -9,8 +9,8 @@ int sys_getitimer(int, struct itimerval *) _Hide; int sys_setitimer(int, const struct itimerval *, struct itimerval *) _Hide; int sys_setitimer_nt(int, const struct itimerval *, struct itimerval *) _Hide; -const char *DescribeTimeval(char[45], int, const struct timeval *); -#define DescribeTimeval(rc, ts) DescribeTimeval(alloca(45), rc, ts) +const char *DescribeItimerval(char[90], int, const struct itimerval *); +#define DescribeItimerval(rc, ts) DescribeItimerval(alloca(90), rc, ts) COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/calls/struct/timespec.h b/libc/calls/struct/timespec.h index 357f995ab..d78260c1c 100644 --- a/libc/calls/struct/timespec.h +++ b/libc/calls/struct/timespec.h @@ -14,14 +14,14 @@ int clock_nanosleep(int, int, const struct timespec *, struct timespec *); int futimens(int, const struct timespec[2]); int nanosleep(const struct timespec *, struct timespec *); int utimensat(int, const char *, const struct timespec[2], int); +int timespec_getres(struct timespec *, int); +int timespec_get(struct timespec *, int); #ifdef COSMO /* cosmopolitan libc's non-posix timespec library removed by default due to emacs codebase clash */ #define timespec_zero ((struct timespec){0}) #define timespec_max ((struct timespec){0x7fffffffffffffff, 999999999}) -int timespec_get(struct timespec *, int); -int timespec_getres(struct timespec *, int); int timespec_cmp(struct timespec, struct timespec) pureconst; int64_t timespec_tomicros(struct timespec) pureconst; int64_t timespec_tomillis(struct timespec) pureconst; @@ -35,7 +35,14 @@ struct timespec timespec_mono(void); struct timespec timespec_sleep(struct timespec); int timespec_sleep_until(struct timespec); struct timespec timespec_sub(struct timespec, struct timespec) pureconst; +struct timespec timespec_subz(struct timespec, struct timespec) pureconst; int sys_futex(int *, int, int, const struct timespec *, int *); +static inline bool timespec_iszero(struct timespec __ts) { + return !(__ts.tv_sec | __ts.tv_nsec); +} +static inline bool timespec_isvalid(struct timespec __ts) { + return __ts.tv_sec >= 0 && __ts.tv_nsec < 1000000000ull; +} #endif /* COSMO */ COSMOPOLITAN_C_END_ diff --git a/libc/calls/struct/timeval.h b/libc/calls/struct/timeval.h index 6fe993db1..bcbaf6040 100644 --- a/libc/calls/struct/timeval.h +++ b/libc/calls/struct/timeval.h @@ -19,13 +19,23 @@ int utimes(const char *, const struct timeval[2]); #ifdef COSMO /* cosmopolitan libc's non-posix timevals library removed by default due to emacs codebase clash */ +#define timeval_zero ((struct timeval){0}) +#define timeval_max ((struct timeval){0x7fffffffffffffff, 999999}) int timeval_cmp(struct timeval, struct timeval) pureconst; +struct timeval timeval_real(void); struct timeval timeval_frommicros(int64_t) pureconst; struct timeval timeval_frommillis(int64_t) pureconst; struct timeval timeval_add(struct timeval, struct timeval) pureconst; struct timeval timeval_sub(struct timeval, struct timeval) pureconst; +struct timeval timeval_subz(struct timeval, struct timeval) pureconst; struct timeval timespec_totimeval(struct timespec) pureconst; struct timespec timeval_totimespec(struct timeval) pureconst; +static inline bool timeval_iszero(struct timeval __tv) { + return !(__tv.tv_sec | __tv.tv_usec); +} +static inline bool timeval_isvalid(struct timeval __tv) { + return __tv.tv_sec >= 0 && __tv.tv_usec < 1000000ull; +} #endif /* COSMO */ COSMOPOLITAN_C_END_ diff --git a/libc/calls/struct/timeval.internal.h b/libc/calls/struct/timeval.internal.h index 0f821506e..ce1971bf6 100644 --- a/libc/calls/struct/timeval.internal.h +++ b/libc/calls/struct/timeval.internal.h @@ -1,6 +1,7 @@ #ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMEVAL_INTERNAL_H_ #define COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMEVAL_INTERNAL_H_ #include "libc/calls/struct/timeval.h" +#include "libc/mem/alloca.h" #include "libc/time/struct/timezone.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ @@ -15,6 +16,9 @@ axdx_t sys_gettimeofday_nt(struct timeval *, struct timezone *, void *) _Hide; int sys_utimes_nt(const char *, const struct timeval[2]) _Hide; axdx_t sys_gettimeofday_metal(struct timeval *, struct timezone *, void *); +const char *DescribeTimeval(char[45], int, const struct timeval *); +#define DescribeTimeval(rc, ts) DescribeTimeval(alloca(45), rc, ts) + COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMEVAL_INTERNAL_H_ */ diff --git a/libc/calls/fmodl.S b/libc/calls/timespec_subz.c similarity index 67% rename from libc/calls/fmodl.S rename to libc/calls/timespec_subz.c index f9fd0065f..b64613944 100644 --- a/libc/calls/fmodl.S +++ b/libc/calls/timespec_subz.c @@ -1,7 +1,7 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 sw=8 fenc=utf-8 :vi│ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ +│ 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,30 +16,17 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/runtime/pc.internal.h" -#include "libc/macros.internal.h" +#include "libc/calls/struct/timespec.h" -// fmod [sic] does (𝑥 rem 𝑦) w/ round()-style rounding. -// -// @param 𝑥 is an 80-bit long double passed on stack in 16-bytes -// @param 𝑦 is the power, also pushed on stack, in reverse order -// @return remainder ∈ (-|𝑦|,|𝑦|) in %st -// @define 𝑥-truncl(𝑥/𝑦)*𝑦 -// @see emod() - .ftrace1 -fmodl: .ftrace2 - push %rbp - mov %rsp,%rbp - fldt 32(%rbp) - fldt 16(%rbp) -1: fprem - fnstsw - test $FPU_C2>>8,%ah - jnz 1b - fstp %st(1) - pop %rbp - ret -1: int3 - pop %rbp - ret - .endfn fmodl,globl +/** + * Subtracts two nanosecond timestamps. + * + * Unlike `timespec_sub()` this function will return zero if `x < y`. + */ +struct timespec timespec_subz(struct timespec x, struct timespec y) { + if (timespec_cmp(x, y) > 0) { + return timespec_sub(x, y); + } else { + return timespec_zero; + } +} diff --git a/libc/calls/timeval_real.c b/libc/calls/timeval_real.c new file mode 100644 index 000000000..cfffbcdd0 --- /dev/null +++ b/libc/calls/timeval_real.c @@ -0,0 +1,31 @@ +/*-*- 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/assert.h" +#include "libc/calls/struct/timeval.h" + +/** + * Returns current time w/ microsecond precision. + * + * @see timespec_real() + */ +struct timeval timeval_real(void) { + struct timeval tv; + _npassert(!gettimeofday(&tv, 0)); + return tv; +} diff --git a/libc/calls/timeval_subz.c b/libc/calls/timeval_subz.c new file mode 100644 index 000000000..335296d06 --- /dev/null +++ b/libc/calls/timeval_subz.c @@ -0,0 +1,30 @@ +/*-*- 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/calls/struct/timeval.h" + +/** + * Subtracts two nanosecond timestamps. + */ +struct timeval timeval_subz(struct timeval x, struct timeval y) { + if (timeval_cmp(x, y) > 0) { + return timeval_sub(x, y); + } else { + return timeval_zero; + } +} diff --git a/libc/calls/utimes.c b/libc/calls/utimes.c index 6ab0bdb7b..fe4b427ab 100644 --- a/libc/calls/utimes.c +++ b/libc/calls/utimes.c @@ -16,10 +16,10 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/struct/itimerval.internal.h" #include "libc/calls/struct/timespec.h" #include "libc/calls/struct/timespec.internal.h" #include "libc/calls/struct/timeval.h" +#include "libc/calls/struct/timeval.internal.h" #include "libc/intrin/strace.internal.h" #include "libc/sysv/consts/at.h" diff --git a/libc/intrin/asan.c b/libc/intrin/asan.c index 8d9d5f673..113102545 100644 --- a/libc/intrin/asan.c +++ b/libc/intrin/asan.c @@ -21,6 +21,7 @@ #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/atomic.h" +#include "libc/intrin/bits.h" #include "libc/intrin/cmpxchg.h" #include "libc/intrin/directmap.internal.h" #include "libc/intrin/kmalloc.h" @@ -437,10 +438,7 @@ static struct AsanFault __asan_checka(const signed char *s, long ndiv8) { if (UNLIKELY(!((intptr_t)s & (FRAMESIZE - 1))) && kisdangerous(s)) { return (struct AsanFault){kAsanUnmapped, s}; } - if ((w = ((uint64_t)(255 & s[0]) << 000 | (uint64_t)(255 & s[1]) << 010 | - (uint64_t)(255 & s[2]) << 020 | (uint64_t)(255 & s[3]) << 030 | - (uint64_t)(255 & s[4]) << 040 | (uint64_t)(255 & s[5]) << 050 | - (uint64_t)(255 & s[6]) << 060 | (uint64_t)(255 & s[7]) << 070))) { + if ((w = READ64LE(s))) { s += __asan_bsf(w) >> 3; return __asan_fault(s, kAsanHeapOverrun); } diff --git a/libc/intrin/describearchprctlcode.c b/libc/intrin/describearchprctlcode.c index 6ebcd76a9..25093ce7b 100644 --- a/libc/intrin/describearchprctlcode.c +++ b/libc/intrin/describearchprctlcode.c @@ -19,6 +19,7 @@ #include "libc/calls/calls.h" #include "libc/fmt/itoa.h" #include "libc/intrin/describeflags.internal.h" +#include "libc/sysv/consts/arch.h" const char *(DescribeArchPrctlCode)(char buf[12], int x) { if (x == ARCH_SET_FS) return "ARCH_SET_FS"; diff --git a/libc/intrin/describeflags.internal.h b/libc/intrin/describeflags.internal.h index 219e1292d..cd585e122 100644 --- a/libc/intrin/describeflags.internal.h +++ b/libc/intrin/describeflags.internal.h @@ -24,6 +24,7 @@ const char *DescribeFrame(char[32], int); const char *DescribeFutexOp(char[64], int); const char *DescribeHow(char[12], int); const char *DescribeInOutInt64(char[23], ssize_t, int64_t *); +const char *DescribeItimer(char[12], int); const char *DescribeMapFlags(char[64], int); const char *DescribeMapping(char[8], int, int); const char *DescribeNtConsoleInFlags(char[256], uint32_t); @@ -77,6 +78,7 @@ const char *DescribeWhichPrio(char[12], int); #define DescribeFutexOp(x) DescribeFutexOp(alloca(64), x) #define DescribeHow(x) DescribeHow(alloca(12), x) #define DescribeInOutInt64(rc, x) DescribeInOutInt64(alloca(23), rc, x) +#define DescribeItimer(x) DescribeItimer(alloca(12), x) #define DescribeMapFlags(x) DescribeMapFlags(alloca(64), x) #define DescribeMapping(x, y) DescribeMapping(alloca(8), x, y) #define DescribeNtConsoleInFlags(x) DescribeNtConsoleInFlags(alloca(256), x) diff --git a/libc/intrin/describeitimer.c b/libc/intrin/describeitimer.c new file mode 100644 index 000000000..d3d5004de --- /dev/null +++ b/libc/intrin/describeitimer.c @@ -0,0 +1,29 @@ +/*-*- 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/fmt/itoa.h" +#include "libc/intrin/describeflags.internal.h" +#include "libc/sysv/consts/itimer.h" + +const char *(DescribeItimer)(char buf[12], int which) { + if (which == ITIMER_REAL) return "ITIMER_REAL"; + if (which == ITIMER_VIRTUAL) return "ITIMER_VIRTUAL"; + if (which == ITIMER_PROF) return "ITIMER_PROF"; + FormatInt32(buf, which); + return buf; +} diff --git a/tool/viz/int2float.c b/libc/intrin/describeitimerval.c similarity index 51% rename from tool/viz/int2float.c rename to libc/intrin/describeitimerval.c index ba6b12ff9..a6086cc71 100644 --- a/tool/viz/int2float.c +++ b/libc/intrin/describeitimerval.c @@ -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│ ╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ +│ 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 │ @@ -16,67 +16,26 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/fmt/conv.h" -#include "libc/limits.h" -#include "libc/macros.internal.h" -#include "libc/mem/gc.h" -#include "libc/stdio/stdio.h" -#include "libc/str/str.h" -#include "libc/x/x.h" -#include "libc/x/xasprintf.h" +#include "libc/calls/struct/itimerval.internal.h" +#include "libc/calls/struct/timeval.h" +#include "libc/calls/struct/timeval.internal.h" +#include "libc/dce.h" +#include "libc/intrin/asan.internal.h" +#include "libc/intrin/describeflags.internal.h" +#include "libc/intrin/kprintf.h" -float b32; -double b64; -long double b80; -uint32_t u32; -uint64_t u64; -int128_t x; +#define N 90 -void int2float(const char *s) { - x = strtoi128(s, NULL, 0); - if ((0 <= x && x <= UINT32_MAX) && !_startswith(s, "-") && - (!_endswith(s, "l") && !_endswith(s, "L"))) { - u32 = x; - memcpy(&b32, &u32, 4); - s = _gc(xdtoa(b32)); - if (!strchr(s, '.')) s = _gc(xasprintf("%s.", s)); - s = _gc(xasprintf("%sf", s)); - puts(s); - } else if ((0 <= x && x <= UINT64_MAX) && !_startswith(s, "-")) { - u64 = x; - memcpy(&b64, &u64, 8); - s = _gc(xdtoa(b64)); - if (!strchr(s, '.')) s = _gc(xasprintf("%s.", s)); - puts(s); - } else if ((INT32_MIN <= x && x <= 0) && - (!_endswith(s, "l") && !_endswith(s, "L"))) { - u32 = ABS(x); - memcpy(&b32, &u32, 4); - b32 = -b32; - s = _gc(xdtoa(b32)); - if (!strchr(s, '.')) s = _gc(xasprintf("%s.", s)); - s = _gc(xasprintf("%sf", s)); - puts(s); - } else if (INT64_MIN <= x && x <= 0) { - u64 = ABS(x); - memcpy(&b64, &u64, 8); - b64 = -b64; - s = _gc(xdtoa(b64)); - if (!strchr(s, '.')) s = _gc(xasprintf("%s.", s)); - puts(s); +const char *(DescribeItimerval)(char buf[N], int rc, + const struct itimerval *it) { + if (!it) return "NULL"; + if (rc == -1) return "n/a"; + if ((!IsAsan() && kisdangerous(it)) || + (IsAsan() && !__asan_is_valid(it, sizeof(*it)))) { + ksnprintf(buf, N, "%p", it); } else { - memcpy(&b80, &x, 16); - s = _gc(xdtoa(b80)); - if (!strchr(s, '.')) s = _gc(xasprintf("%s.", s)); - s = _gc(xasprintf("%sL", s)); - puts(s); + ksnprintf(buf, N, "{%s, %s}", DescribeTimeval(0, &it->it_interval), + DescribeTimeval(0, &it->it_value)); } -} - -int main(int argc, char *argv[]) { - int i; - for (i = 1; i < argc; ++i) { - int2float(argv[i]); - } - return 0; + return buf; } diff --git a/libc/intrin/describemapflags.c b/libc/intrin/describemapflags.c index fedbf81ca..c7ca0007e 100644 --- a/libc/intrin/describemapflags.c +++ b/libc/intrin/describemapflags.c @@ -31,7 +31,6 @@ const char *(DescribeMapFlags)(char buf[64], int x) { {MAP_FIXED, "FIXED"}, // {MAP_FIXED_NOREPLACE, "FIXED_NOREPLACE"}, // {MAP_CONCEAL, "CONCEAL"}, // - {MAP_HUGETLB, "HUGETLB"}, // {MAP_LOCKED, "LOCKED"}, // {MAP_NORESERVE, "NORESERVE"}, // {MAP_NONBLOCK, "NONBLOCK"}, // diff --git a/libc/intrin/describeopenflags.c b/libc/intrin/describeopenflags.c index 5e80c1069..d6f304315 100644 --- a/libc/intrin/describeopenflags.c +++ b/libc/intrin/describeopenflags.c @@ -21,6 +21,8 @@ #include "libc/fmt/magnumstrs.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/macros.internal.h" +#include "libc/str/str.h" +#include "libc/sysv/consts/o.h" #include "libc/sysv/consts/sol.h" #define N (PAGESIZE / 2 / sizeof(struct DescribeFlags)) @@ -29,17 +31,42 @@ * Describes clock_gettime() clock argument. */ const char *(DescribeOpenFlags)(char buf[128], int x) { - char *s; + char *p; int i, n; + const char *pipe; struct DescribeFlags d[N]; if (x == -1) return "-1"; - // TODO(jart): unify DescribeFlags and MagnumStr data structures - for (n = 0; kOpenFlags[n].x != MAGNUM_TERMINATOR; ++n) { - if (n == N) notpossible; + p = buf; + switch (x & O_ACCMODE) { + case O_RDONLY: + p = stpcpy(p, "O_RDONLY"); + x &= ~O_ACCMODE; + pipe = "|"; + break; + case O_WRONLY: + p = stpcpy(p, "O_WRONLY"); + x &= ~O_ACCMODE; + pipe = "|"; + break; + case O_RDWR: + p = stpcpy(p, "O_RDWR"); + x &= ~O_ACCMODE; + pipe = "|"; + break; + default: + pipe = ""; + break; } - for (i = 0; i < n; ++i) { - d[i].flag = MAGNUM_NUMBER(kOpenFlags, i); - d[i].name = MAGNUM_STRING(kOpenFlags, i); + if (x) { + p = stpcpy(p, pipe); + for (n = 0; kOpenFlags[n].x != MAGNUM_TERMINATOR; ++n) { + if (n == N) notpossible; + } + for (i = 0; i < n; ++i) { + d[i].flag = MAGNUM_NUMBER(kOpenFlags, i); + d[i].name = MAGNUM_STRING(kOpenFlags, i); + } + DescribeFlags(p, 128 - (p - buf), d, n, "O_", x); } - return DescribeFlags(buf, 128, d, n, "O_", x); + return buf; } diff --git a/libc/intrin/describetimeval.c b/libc/intrin/describetimeval.c index 9fe88d7b8..d1b6ae341 100644 --- a/libc/intrin/describetimeval.c +++ b/libc/intrin/describetimeval.c @@ -23,8 +23,8 @@ #include "libc/intrin/kprintf.h" const char *(DescribeTimeval)(char buf[45], int rc, const struct timeval *tv) { - if (rc == -1) return "n/a"; if (!tv) return "NULL"; + if (rc == -1) return "n/a"; if ((!IsAsan() && kisdangerous(tv)) || (IsAsan() && !__asan_is_valid(tv, sizeof(*tv)))) { ksnprintf(buf, 45, "%p", tv); diff --git a/libc/intrin/fenv.S b/libc/intrin/fenv.S index 0ca23467e..6c631606c 100644 --- a/libc/intrin/fenv.S +++ b/libc/intrin/fenv.S @@ -46,11 +46,14 @@ feclearexcept: // maintain exceptions in the sse mxcsr, clear x87 exceptions mov %edi,%ecx and $0x3f,%ecx +#ifndef NOX87 fnstsw %ax test %eax,%ecx jz 1f fnclex -1: stmxcsr -8(%rsp) +1: +#endif + stmxcsr -8(%rsp) and $0x3f,%eax or %eax,-8(%rsp) test %ecx,-8(%rsp) @@ -96,12 +99,16 @@ fetestexcept: .ftrace2 #ifdef __x86_64__ and $0x3f,%edi - push %rax + push $0 stmxcsr (%rsp) +#ifdef NOX87 + pop %rax +#else pop %rsi fnstsw %ax or %esi,%eax and %edi,%eax +#endif ret #elif defined(__aarch64__) and w0,w0,#0x1f @@ -138,10 +145,12 @@ __fesetround: push %rax xor %eax,%eax mov %edi,%ecx +#ifndef NOX87 fnstcw (%rsp) andb $0xf3,1(%rsp) or %ch,1(%rsp) fldcw (%rsp) +#endif stmxcsr (%rsp) shl $3,%ch andb $0x9f,1(%rsp) @@ -181,7 +190,9 @@ fegetenv: .ftrace2 #ifdef __x86_64__ xor %eax,%eax +#ifndef NOX87 fnstenv (%rdi) +#endif stmxcsr 28(%rdi) ret #elif defined(__aarch64__) @@ -200,14 +211,18 @@ fesetenv: xor %eax,%eax inc %rdi jz 1f +#ifndef NOX87 fldenv -1(%rdi) +#endif ldmxcsr 27(%rdi) ret 1: push %rax push %rax pushq $0xffff pushq $0x37f +#ifndef NOX87 fldenv (%rsp) +#endif pushq $0x1f80 ldmxcsr (%rsp) add $40,%rsp diff --git a/libc/intrin/fmax.c b/libc/intrin/fmax.c index 0719e6d7d..1e4e9ecc5 100644 --- a/libc/intrin/fmax.c +++ b/libc/intrin/fmax.c @@ -35,5 +35,5 @@ double fmax(double x, double y) { } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(fmax, fmaxl); +__weak_reference(fmax, fmaxl); #endif diff --git a/libc/intrin/scalbn.c b/libc/intrin/scalbn.c index 1ad7640a1..148aea4ac 100644 --- a/libc/intrin/scalbn.c +++ b/libc/intrin/scalbn.c @@ -69,6 +69,6 @@ double scalbn(double x, int n) __strong_reference(scalbn, ldexp); #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(scalbn, ldexpl); -__strong_reference(scalbn, scalbnl); +__weak_reference(scalbn, ldexpl); +__weak_reference(scalbn, scalbnl); #endif diff --git a/libc/mem/copyfd.internal.h b/libc/mem/copyfd.internal.h deleted file mode 100644 index 22f365c15..000000000 --- a/libc/mem/copyfd.internal.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_MEM_IO_H_ -#define COSMOPOLITAN_LIBC_MEM_IO_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -ssize_t _copyfd(int, int, size_t); - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_MEM_IO_H_ */ diff --git a/libc/runtime/cosmo.S b/libc/runtime/cosmo.S index 3c02c5eb6..172fe164b 100644 --- a/libc/runtime/cosmo.S +++ b/libc/runtime/cosmo.S @@ -45,6 +45,7 @@ cosmo: push %rbp mov %eax,%r12d #endif /* SYSDEBUG */ +#ifndef NOX87 // Windows always initializes FPU to douuble precision. // WSL breaks Linux ABI by initializing FPU to double precision. // This code makes long double long again. @@ -70,6 +71,7 @@ cosmo: push %rbp // d││││rr││││││ 1: .short 0b00000000000000000001101111111 .previous +#endif #ifdef __FAST_MATH__ push %rax diff --git a/libc/runtime/runtime.h b/libc/runtime/runtime.h index 68a06e209..3a962e4a3 100644 --- a/libc/runtime/runtime.h +++ b/libc/runtime/runtime.h @@ -20,24 +20,9 @@ typedef unsigned long jmp_buf[26]; typedef long sigjmp_buf[12]; -extern char **environ; /* CRT */ -extern int __argc; /* CRT */ -extern char **__argv; /* CRT */ -extern char **__envp; /* CRT */ -extern unsigned long *__auxv; /* CRT */ -extern intptr_t __oldstack; /* CRT */ -extern uint64_t __nosync; /* SYS */ -extern int __strace; /* SYS */ -extern int __ftrace; /* SYS */ -extern char *program_invocation_name; /* RII */ -extern char *program_invocation_short_name; /* RII */ -extern uint64_t __syscount; /* RII */ -extern uint64_t kStartTsc; /* RII */ -extern char kTmpPath[]; /* RII */ -extern const char kNtSystemDirectory[]; /* RII */ -extern const char kNtWindowsDirectory[]; /* RII */ -extern size_t __virtualmax; -extern bool __isworker; +extern char **environ; +extern char *program_invocation_name; +extern char *program_invocation_short_name; void mcount(void); int daemon(int, int); @@ -83,6 +68,21 @@ int sethostname(const char *, size_t); int acct(const char *); #ifdef COSMO +extern int __argc; +extern char **__argv; +extern char **__envp; +extern unsigned long *__auxv; +extern intptr_t __oldstack; +extern uint64_t __nosync; +extern int __strace; +extern int __ftrace; +extern uint64_t __syscount; +extern uint64_t kStartTsc; +extern char kTmpPath[]; +extern const char kNtSystemDirectory[]; +extern const char kNtWindowsDirectory[]; +extern size_t __virtualmax; +extern bool __isworker; /* utilities */ void _intsort(int *, size_t); void _longsort(long *, size_t); diff --git a/libc/runtime/set_tls.c b/libc/runtime/set_tls.c index e0a0d50c1..eeb0a4957 100644 --- a/libc/runtime/set_tls.c +++ b/libc/runtime/set_tls.c @@ -23,6 +23,7 @@ #include "libc/errno.h" #include "libc/nexgen32e/msr.internal.h" #include "libc/nt/thread.h" +#include "libc/sysv/consts/arch.h" #include "libc/thread/tls.h" #include "libc/thread/tls2.h" @@ -60,8 +61,10 @@ textstartup void __set_tls(struct CosmoTib *tib) { : "c"(MSR_IA32_FS_BASE), "a"((uint32_t)val), "d"((uint32_t)(val >> 32))); } -#else +#elif defined(__aarch64__) register long x28 asm("x28") = (long)tib; asm volatile("" : "+r"(x28)); +#else +#error "unsupported architecture" #endif } diff --git a/libc/sysv/consts.sh b/libc/sysv/consts.sh index 10b11f0a1..45602137f 100755 --- a/libc/sysv/consts.sh +++ b/libc/sysv/consts.sh @@ -231,14 +231,11 @@ syscon mmap MAP_LOCKED 0x00002000 0x00002000 0 0 0 0 0 0 syscon mmap MAP_NORESERVE 0x00004000 0x00004000 0x00000040 0x00000040 0 0 0x00000040 0 # Linux calls it "reserve"; NT calls it "commit"? which is default? syscon mmap MAP_POPULATE 0x00008000 0x00008000 0 0 0x00040000 0 0 0 # MAP_PREFAULT_READ on FreeBSD; can avoid madvise(MADV_WILLNEED) on private file mapping syscon mmap MAP_NONBLOCK 0x00010000 0x00010000 0 0 0 0 0 0 -syscon mmap MAP_HUGETLB 0x00040000 0x00040000 0 0 0 0 0 0x80000000 # kNtSecLargePages syscon mmap MAP_SYNC 0x00080000 0x00080000 0 0 0 0 0 0 # perform synchronous page faults for mapping (Linux 4.15+) syscon mmap MAP_INHERIT -1 -1 -1 -1 -1 -1 0x00000080 -1 # make it inherit across execve() syscon mmap MAP_HASSEMAPHORE 0 0 0x00000200 0x00000200 0x00000200 0 0x00000200 0 # does it matter on x86? syscon mmap MAP_NOSYNC 0 0 0 0 0x00000800 0 0 0 # flush to physical media only when necessary rather than gratuitously; be sure to use write() rather than ftruncate() with this! syscon mmap MAP_CONCEAL 0 0 0 0 0x00020000 0x00008000 0x00008000 0 # omit from core dumps; MAP_NOCORE on FreeBSD -syscon mmap MAP_HUGE_MASK 63 63 0 0 0 0 0 0 -syscon mmap MAP_HUGE_SHIFT 26 26 0 0 0 0 0 0 syscon compat MAP_NOCORE 0 0 0 0 0x00020000 0x00008000 0x00008000 0 # use MAP_CONCEAL syscon compat MAP_ANON 0x00000020 0x00000020 0x00001000 0x00001000 0x00001000 0x00001000 0x00001000 0x00000020 # bsd consensus; faked nt syscon compat MAP_EXECUTABLE 0x00001000 0x00001000 0 0 0 0 0 0 # ignored diff --git a/libc/sysv/consts/MAP_HUGETLB.S b/libc/sysv/consts/MAP_HUGETLB.S deleted file mode 100644 index 8218e2ade..000000000 --- a/libc/sysv/consts/MAP_HUGETLB.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon mmap,MAP_HUGETLB,0x00040000,0x00040000,0,0,0,0,0,0x80000000 diff --git a/libc/sysv/consts/MAP_HUGE_MASK.S b/libc/sysv/consts/MAP_HUGE_MASK.S deleted file mode 100644 index 0014eaa02..000000000 --- a/libc/sysv/consts/MAP_HUGE_MASK.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon mmap,MAP_HUGE_MASK,63,63,0,0,0,0,0,0 diff --git a/libc/sysv/consts/MAP_HUGE_SHIFT.S b/libc/sysv/consts/MAP_HUGE_SHIFT.S deleted file mode 100644 index aba8dcea0..000000000 --- a/libc/sysv/consts/MAP_HUGE_SHIFT.S +++ /dev/null @@ -1,2 +0,0 @@ -#include "libc/sysv/consts/syscon.internal.h" -.syscon mmap,MAP_HUGE_SHIFT,26,26,0,0,0,0,0,0 diff --git a/libc/sysv/consts/arch.h b/libc/sysv/consts/arch.h new file mode 100644 index 000000000..34b28f7b6 --- /dev/null +++ b/libc/sysv/consts/arch.h @@ -0,0 +1,9 @@ +#ifndef COSMOPOLITAN_LIBC_SYSV_CONSTS_ARCH_H_ +#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ARCH_H_ + +#define ARCH_SET_GS 0x1001 +#define ARCH_SET_FS 0x1002 +#define ARCH_GET_FS 0x1003 +#define ARCH_GET_GS 0x1004 + +#endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_ARCH_H_ */ diff --git a/libc/sysv/consts/map.h b/libc/sysv/consts/map.h index 3ed8d3c60..c70057f14 100644 --- a/libc/sysv/consts/map.h +++ b/libc/sysv/consts/map.h @@ -13,9 +13,6 @@ extern const int MAP_FILE; extern const int MAP_FIXED; extern const int MAP_FIXED_NOREPLACE; extern const int MAP_HASSEMAPHORE; -extern const int MAP_HUGETLB; -extern const int MAP_HUGE_MASK; -extern const int MAP_HUGE_SHIFT; extern const int MAP_INHERIT; extern const int MAP_LOCKED; extern const int MAP_NONBLOCK; diff --git a/libc/testlib/extract.c b/libc/testlib/extract.c index 4792842e8..a0da629d3 100644 --- a/libc/testlib/extract.c +++ b/libc/testlib/extract.c @@ -17,7 +17,6 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/mem/copyfd.internal.h" #include "libc/sysv/consts/o.h" #include "libc/testlib/testlib.h" @@ -34,7 +33,7 @@ void testlib_extract(const char *zip, const char *to, int mode) { int fdin, fdout; ASSERT_NE(-1, (fdin = open(zip, O_RDONLY))); ASSERT_NE(-1, (fdout = creat(to, mode))); - ASSERT_NE(-1, _copyfd(fdin, fdout, -1)); + ASSERT_NE(-1, copyfd(fdin, fdout, -1)); ASSERT_NE(-1, close(fdout)); ASSERT_NE(-1, close(fdin)); } diff --git a/libc/tinymath/acos.c b/libc/tinymath/acos.c index 939a87abf..b5320e055 100644 --- a/libc/tinymath/acos.c +++ b/libc/tinymath/acos.c @@ -143,5 +143,5 @@ double acos(double x) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(acos, acosl); +__weak_reference(acos, acosl); #endif diff --git a/libc/tinymath/acosh.c b/libc/tinymath/acosh.c index 35286d201..1ad06fb78 100644 --- a/libc/tinymath/acosh.c +++ b/libc/tinymath/acosh.c @@ -55,5 +55,5 @@ double acosh(double x) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(acosh, acoshl); +__weak_reference(acosh, acoshl); #endif diff --git a/libc/tinymath/asin.c b/libc/tinymath/asin.c index c37d612ef..eecd92803 100644 --- a/libc/tinymath/asin.c +++ b/libc/tinymath/asin.c @@ -149,5 +149,5 @@ double asin(double x) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(asin, asinl); +__weak_reference(asin, asinl); #endif diff --git a/libc/tinymath/asinh.c b/libc/tinymath/asinh.c index dcbbf87f5..140fb9411 100644 --- a/libc/tinymath/asinh.c +++ b/libc/tinymath/asinh.c @@ -66,5 +66,5 @@ double asinh(double x) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(asinh, asinhl); +__weak_reference(asinh, asinhl); #endif diff --git a/libc/tinymath/atan.c b/libc/tinymath/atan.c index 4faae90a2..80f80924f 100644 --- a/libc/tinymath/atan.c +++ b/libc/tinymath/atan.c @@ -156,5 +156,5 @@ double atan(double x) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(atan, atanl); +__weak_reference(atan, atanl); #endif diff --git a/libc/tinymath/atan2.c b/libc/tinymath/atan2.c index 1a655ffb4..b2f829bce 100644 --- a/libc/tinymath/atan2.c +++ b/libc/tinymath/atan2.c @@ -155,5 +155,5 @@ atan2(double y, double x) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(atan2, atan2l); +__weak_reference(atan2, atan2l); #endif diff --git a/libc/tinymath/atanh.c b/libc/tinymath/atanh.c index 112940c0d..75d04fa8a 100644 --- a/libc/tinymath/atanh.c +++ b/libc/tinymath/atanh.c @@ -66,5 +66,5 @@ double atanh(double x) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(atanh, atanhl); +__weak_reference(atanh, atanhl); #endif diff --git a/libc/tinymath/cabs.c b/libc/tinymath/cabs.c index b4f81f2bf..fa7790f6e 100644 --- a/libc/tinymath/cabs.c +++ b/libc/tinymath/cabs.c @@ -27,5 +27,5 @@ double cabs(double complex z) { } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(cabs, cabsl); +__weak_reference(cabs, cabsl); #endif diff --git a/libc/tinymath/cacosh.c b/libc/tinymath/cacosh.c index 4eb144956..aeef21b29 100644 --- a/libc/tinymath/cacosh.c +++ b/libc/tinymath/cacosh.c @@ -45,5 +45,5 @@ double complex cacosh(double complex z) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(cacosh, cacoshl); +__weak_reference(cacosh, cacoshl); #endif diff --git a/libc/tinymath/carg.c b/libc/tinymath/carg.c index aab4e71b6..e8f16c4cc 100644 --- a/libc/tinymath/carg.c +++ b/libc/tinymath/carg.c @@ -24,5 +24,5 @@ double carg(double complex z) { } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(carg, cargl); +__weak_reference(carg, cargl); #endif diff --git a/libc/tinymath/casin.c b/libc/tinymath/casin.c index ebde7f5e7..b23b2851d 100644 --- a/libc/tinymath/casin.c +++ b/libc/tinymath/casin.c @@ -52,5 +52,5 @@ double complex casin(double complex z) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(casin, casinl); +__weak_reference(casin, casinl); #endif diff --git a/libc/tinymath/catan.c b/libc/tinymath/catan.c index ec2a6d489..89dd797af 100644 --- a/libc/tinymath/catan.c +++ b/libc/tinymath/catan.c @@ -147,5 +147,5 @@ double complex catan(double complex z) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(catan, catanl); +__weak_reference(catan, catanl); #endif diff --git a/libc/tinymath/copysign.c b/libc/tinymath/copysign.c index df3cb7830..b6b36240b 100644 --- a/libc/tinymath/copysign.c +++ b/libc/tinymath/copysign.c @@ -32,5 +32,5 @@ double copysign(double x, double y) { } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(copysign, copysignl); +__weak_reference(copysign, copysignl); #endif diff --git a/libc/tinymath/cos.c b/libc/tinymath/cos.c index 04a4673bf..13f7ac54a 100644 --- a/libc/tinymath/cos.c +++ b/libc/tinymath/cos.c @@ -122,5 +122,5 @@ double cos(double x) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(cos, cosl); +__weak_reference(cos, cosl); #endif diff --git a/libc/tinymath/cosh.c b/libc/tinymath/cosh.c index a3a0a3b1c..7898cb5c3 100644 --- a/libc/tinymath/cosh.c +++ b/libc/tinymath/cosh.c @@ -76,3 +76,7 @@ double cosh(double x) t = __expo2(x, 1.0); return t; } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__weak_reference(cosh, coshl); +#endif diff --git a/libc/tinymath/coshl.c b/libc/tinymath/coshl.c index a0fa3c62c..5de30ed2d 100644 --- a/libc/tinymath/coshl.c +++ b/libc/tinymath/coshl.c @@ -38,6 +38,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" #include "libc/tinymath/freebsd.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ FreeBSD libm (BSD-2 License)\\n\ @@ -155,3 +156,5 @@ coshl(long double x) /* |x| > o_threshold, cosh(x) overflow */ RETURNI(huge*huge); } + +#endif /* long double is long */ diff --git a/libc/tinymath/exp.c b/libc/tinymath/exp.c index 79aaaadac..12277154d 100644 --- a/libc/tinymath/exp.c +++ b/libc/tinymath/exp.c @@ -170,5 +170,5 @@ double exp(double x) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(exp, expl); +__weak_reference(exp, expl); #endif diff --git a/libc/tinymath/exp10.c b/libc/tinymath/exp10.c index 0c95576f8..04ba42313 100644 --- a/libc/tinymath/exp10.c +++ b/libc/tinymath/exp10.c @@ -57,5 +57,6 @@ double exp10(double x) __strong_reference(exp10, pow10); #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(exp10, exp10l); +__weak_reference(exp10, exp10l); +__weak_reference(exp10, pow10l); #endif diff --git a/libc/tinymath/exp10l.c b/libc/tinymath/exp10l.c index 456e94a06..d4b04cf06 100644 --- a/libc/tinymath/exp10l.c +++ b/libc/tinymath/exp10l.c @@ -57,6 +57,6 @@ long double exp10l(long double x) return powl(10.0, x); } -__strong_reference(exp10l, pow10l); +__weak_reference(exp10l, pow10l); #endif /* long double is long */ diff --git a/libc/tinymath/exp2.c b/libc/tinymath/exp2.c index 55ea241dd..aaee09fdf 100644 --- a/libc/tinymath/exp2.c +++ b/libc/tinymath/exp2.c @@ -157,5 +157,5 @@ double exp2(double x) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(exp2, exp2l); +__weak_reference(exp2, exp2l); #endif diff --git a/libc/tinymath/expm1.c b/libc/tinymath/expm1.c index 657abd8aa..1682afd6e 100644 --- a/libc/tinymath/expm1.c +++ b/libc/tinymath/expm1.c @@ -238,5 +238,5 @@ double expm1(double x) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(expm1, expm1l); +__weak_reference(expm1, expm1l); #endif diff --git a/libc/tinymath/fabs.c b/libc/tinymath/fabs.c index 75cc9fbe8..43d0675b2 100644 --- a/libc/tinymath/fabs.c +++ b/libc/tinymath/fabs.c @@ -31,5 +31,5 @@ double fabs(double x) { } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(fabs, fabsl); +__weak_reference(fabs, fabsl); #endif diff --git a/libc/tinymath/fdim.c b/libc/tinymath/fdim.c index e76f946be..9dd8c633d 100644 --- a/libc/tinymath/fdim.c +++ b/libc/tinymath/fdim.c @@ -27,5 +27,5 @@ double fdim(double x, double y) { } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(fdim, fdiml); +__weak_reference(fdim, fdiml); #endif diff --git a/libc/tinymath/floor.c b/libc/tinymath/floor.c index 69cf60187..ff1e1050c 100644 --- a/libc/tinymath/floor.c +++ b/libc/tinymath/floor.c @@ -96,5 +96,5 @@ double floor(double x) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(floor, floorl); +__weak_reference(floor, floorl); #endif diff --git a/libc/tinymath/fmin.c b/libc/tinymath/fmin.c index 08af674ea..722da0bb2 100644 --- a/libc/tinymath/fmin.c +++ b/libc/tinymath/fmin.c @@ -35,5 +35,5 @@ double fmin(double x, double y) { } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(fmin, fminl); +__weak_reference(fmin, fminl); #endif diff --git a/libc/tinymath/fmod.c b/libc/tinymath/fmod.c index 2d3b1d7f5..cfa70958b 100644 --- a/libc/tinymath/fmod.c +++ b/libc/tinymath/fmod.c @@ -103,3 +103,7 @@ double fmod(double x, double y) ux.i = uxi; return ux.f; } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__weak_reference(fmod, fmodl); +#endif diff --git a/libc/tinymath/fmodl.c b/libc/tinymath/fmodl.c index ccf6bb8c2..4cdc13c7c 100644 --- a/libc/tinymath/fmodl.c +++ b/libc/tinymath/fmodl.c @@ -27,6 +27,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" #include "libc/tinymath/ldshape.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ @@ -34,10 +35,13 @@ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); // clang-format off +/** + * Does (𝑥 rem 𝑦) w/ round()-style rounding. + * @return remainder ∈ (-|𝑦|,|𝑦|) in %xmm0 + * @define 𝑥-trunc(𝑥/𝑦)*𝑦 + */ long double fmodl(long double x, long double y) { -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - return fmod(x, y); -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 +#if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 union ldshape ux = {x}, uy = {y}; int ex = ux.i.se & 0x7fff; int ey = uy.i.se & 0x7fff; @@ -135,3 +139,5 @@ long double fmodl(long double x, long double y) { #error "architecture unsupported" #endif } + +#endif /* long double is long */ diff --git a/libc/tinymath/frexp.c b/libc/tinymath/frexp.c index c3bad0761..99be106b4 100644 --- a/libc/tinymath/frexp.c +++ b/libc/tinymath/frexp.c @@ -58,5 +58,5 @@ double frexp(double x, int *e) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(frexp, frexpl); +__weak_reference(frexp, frexpl); #endif diff --git a/libc/tinymath/hypot.c b/libc/tinymath/hypot.c index 97ca1af9e..48be37509 100644 --- a/libc/tinymath/hypot.c +++ b/libc/tinymath/hypot.c @@ -101,5 +101,5 @@ double hypot(double x, double y) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(hypot, hypotl); +__weak_reference(hypot, hypotl); #endif diff --git a/libc/tinymath/ilogb.c b/libc/tinymath/ilogb.c index 9a5fa5c4c..6b0f99c64 100644 --- a/libc/tinymath/ilogb.c +++ b/libc/tinymath/ilogb.c @@ -63,5 +63,5 @@ int ilogb(double x) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(ilogb, ilogbl); +__weak_reference(ilogb, ilogbl); #endif diff --git a/libc/tinymath/ilogbl.c b/libc/tinymath/ilogbl.c deleted file mode 100644 index cb18842ef..000000000 --- a/libc/tinymath/ilogbl.c +++ /dev/null @@ -1,88 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│ -│vi: set et ft=c ts=8 tw=8 fenc=utf-8 :vi│ -╚──────────────────────────────────────────────────────────────────────────────╝ -│ │ -│ Musl Libc │ -│ Copyright © 2005-2014 Rich Felker, et al. │ -│ │ -│ Permission is hereby granted, free of charge, to any person obtaining │ -│ a copy of this software and associated documentation files (the │ -│ "Software"), to deal in the Software without restriction, including │ -│ without limitation the rights to use, copy, modify, merge, publish, │ -│ distribute, sublicense, and/or sell copies of the Software, and to │ -│ permit persons to whom the Software is furnished to do so, subject to │ -│ the following conditions: │ -│ │ -│ The above copyright notice and this permission notice shall be │ -│ included in all copies or substantial portions of the Software. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │ -│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │ -│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │ -│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │ -│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │ -│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │ -│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │ -│ │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/limits.h" -#include "libc/math.h" -#include "libc/tinymath/internal.h" -#include "libc/tinymath/ldshape.internal.h" -#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) - -asm(".ident\t\"\\n\\n\ -Musl libc (MIT License)\\n\ -Copyright 2005-2014 Rich Felker, et. al.\""); -asm(".include \"libc/disclaimer.inc\""); -// clang-format off - -/** - * Returns log₂𝑥 exponent part of double. - */ -int ilogbl(long double x) -{ -#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 -// #pragma STDC FENV_ACCESS ON - union ldshape u = {x}; - uint64_t m = u.i.m; - int e = u.i.se & 0x7fff; - - if (!e) { - if (m == 0) { - FORCE_EVAL(0/0.0f); - return FP_ILOGB0; - } - /* subnormal x */ - for (e = -0x3fff+1; m>>63 == 0; e--, m<<=1); - return e; - } - if (e == 0x7fff) { - FORCE_EVAL(0/0.0f); - return m<<1 ? FP_ILOGBNAN : INT_MAX; - } - return e - 0x3fff; -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -// #pragma STDC FENV_ACCESS ON - union ldshape u = {x}; - int e = u.i.se & 0x7fff; - - if (!e) { - if (x == 0) { - FORCE_EVAL(0/0.0f); - return FP_ILOGB0; - } - /* subnormal x */ - x *= 0x1p120; - return ilogbl(x) - 120; - } - if (e == 0x7fff) { - FORCE_EVAL(0/0.0f); - u.i.se = 0; - return u.f ? FP_ILOGBNAN : INT_MAX; - } - return e - 0x3fff; -#endif -} - -#endif /* long double is long */ diff --git a/libc/tinymath/ktanl.c b/libc/tinymath/ktanl.c index b63ce81b6..822563d5d 100644 --- a/libc/tinymath/ktanl.c +++ b/libc/tinymath/ktanl.c @@ -27,6 +27,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" #include "libc/tinymath/kernel.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ FreeBSD libm (BSD-2 License)\\n\ @@ -183,3 +184,5 @@ long double __tanl(long double x, long double y, int odd) { #else #error "architecture unsupported" #endif + +#endif /* long double is long */ diff --git a/libc/tinymath/log.c b/libc/tinymath/log.c index d5f41744e..636bfed94 100644 --- a/libc/tinymath/log.c +++ b/libc/tinymath/log.c @@ -142,5 +142,5 @@ double log(double x) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(log, logl); +__weak_reference(log, logl); #endif diff --git a/libc/tinymath/log10.c b/libc/tinymath/log10.c index 88bea6c85..21af3dcfa 100644 --- a/libc/tinymath/log10.c +++ b/libc/tinymath/log10.c @@ -143,5 +143,5 @@ double log10(double x) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(log10, log10l); +__weak_reference(log10, log10l); #endif diff --git a/libc/tinymath/log1p.c b/libc/tinymath/log1p.c index c5045416f..b1d25becd 100644 --- a/libc/tinymath/log1p.c +++ b/libc/tinymath/log1p.c @@ -161,5 +161,5 @@ double log1p(double x) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(log1p, log1pl); +__weak_reference(log1p, log1pl); #endif diff --git a/libc/tinymath/log2.c b/libc/tinymath/log2.c index 5675c66db..75e0a5033 100644 --- a/libc/tinymath/log2.c +++ b/libc/tinymath/log2.c @@ -159,5 +159,5 @@ double log2(double x) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(log2, log2l); +__weak_reference(log2, log2l); #endif diff --git a/libc/tinymath/logb.c b/libc/tinymath/logb.c index 5f09b9cf0..0d39fea8e 100644 --- a/libc/tinymath/logb.c +++ b/libc/tinymath/logb.c @@ -23,3 +23,7 @@ double logb(double x) { if (!x) return -1 / (x * x); return ilogb(x); } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__weak_reference(logb, logbl); +#endif diff --git a/libc/tinymath/lrint.c b/libc/tinymath/lrint.c index d3f137ec3..432712270 100644 --- a/libc/tinymath/lrint.c +++ b/libc/tinymath/lrint.c @@ -45,8 +45,8 @@ __weak_reference(lrint, llrint); #endif #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(lrint, lrintl); +__weak_reference(lrint, lrintl); #if __SIZEOF_LONG__ == __SIZEOF_LONG_LONG__ -__strong_reference(lrint, llrintl); +__weak_reference(lrint, llrintl); #endif #endif diff --git a/libc/tinymath/lround.c b/libc/tinymath/lround.c index b18b3dd4a..0e9528ab1 100644 --- a/libc/tinymath/lround.c +++ b/libc/tinymath/lround.c @@ -26,5 +26,5 @@ long lround(double x) { } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(lround, lroundl); +__weak_reference(lround, lroundl); #endif diff --git a/libc/tinymath/modf.c b/libc/tinymath/modf.c index e5e9f73bd..718717126 100644 --- a/libc/tinymath/modf.c +++ b/libc/tinymath/modf.c @@ -33,6 +33,9 @@ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); // clang-format off +/** + * Returns fractional part of 𝑥. + */ double modf(double x, double *iptr) { union {double f; uint64_t i;} u = {x}; @@ -65,3 +68,7 @@ double modf(double x, double *iptr) *iptr = u.f; return x - u.f; } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__weak_reference(modf, modfl); +#endif diff --git a/libc/tinymath/modfl.c b/libc/tinymath/modfl.c index 420eb027c..be9871acf 100644 --- a/libc/tinymath/modfl.c +++ b/libc/tinymath/modfl.c @@ -26,6 +26,7 @@ │ │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ @@ -33,20 +34,11 @@ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); // clang-format off -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double modfl(long double x, long double *iptr) -{ - double d; - long double r; - - r = modf(x, &d); - *iptr = d; - return r; -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 - static const long double toint = 1/LDBL_EPSILON; +/** + * Returns fractional part of 𝑥. + */ long double modfl(long double x, long double *iptr) { union { @@ -90,6 +82,4 @@ long double modfl(long double x, long double *iptr) return -y; } -#else -#error "architecture unsupported" -#endif +#endif /* long double is long */ diff --git a/libc/tinymath/nearbyint.c b/libc/tinymath/nearbyint.c index 114a410d9..57ea0d731 100644 --- a/libc/tinymath/nearbyint.c +++ b/libc/tinymath/nearbyint.c @@ -42,5 +42,5 @@ double nearbyint(double x) { } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(nearbyint, nearbyintl); +__weak_reference(nearbyint, nearbyintl); #endif diff --git a/libc/tinymath/nextafter.c b/libc/tinymath/nextafter.c index f99e08269..b95d8542d 100644 --- a/libc/tinymath/nextafter.c +++ b/libc/tinymath/nextafter.c @@ -65,5 +65,5 @@ double nextafter(double x, double y) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(nextafter, nextafterl); +__weak_reference(nextafter, nextafterl); #endif diff --git a/libc/tinymath/pow.c b/libc/tinymath/pow.c index da9725098..56c2e4598 100644 --- a/libc/tinymath/pow.c +++ b/libc/tinymath/pow.c @@ -381,5 +381,5 @@ double pow(double x, double y) __weak_reference(pow, __pow_finite); #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(pow, powl); +__weak_reference(pow, powl); #endif diff --git a/libc/tinymath/remainder.c b/libc/tinymath/remainder.c index e71201f08..17c8bc4d2 100644 --- a/libc/tinymath/remainder.c +++ b/libc/tinymath/remainder.c @@ -28,5 +28,5 @@ double remainder(double x, double y) { __strong_reference(remainder, drem); #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(remainder, remainderl); +__weak_reference(remainder, remainderl); #endif diff --git a/libc/tinymath/rempio2.c b/libc/tinymath/rempio2.c index 33f2a98d9..7b0065554 100644 --- a/libc/tinymath/rempio2.c +++ b/libc/tinymath/rempio2.c @@ -225,3 +225,7 @@ medium: y[1] = ty[1]; return n; } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__weak_reference(__rem_pio2, __rem_pio2l); +#endif diff --git a/libc/tinymath/rempio2l.c b/libc/tinymath/rempio2l.c index ef985ff2a..28af7c199 100644 --- a/libc/tinymath/rempio2l.c +++ b/libc/tinymath/rempio2l.c @@ -29,6 +29,7 @@ #include "libc/math.h" #include "libc/tinymath/kernel.internal.h" #include "libc/tinymath/ldshape.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ FreeBSD libm (BSD-2 License)\\n\ @@ -200,3 +201,5 @@ int __rem_pio2l(long double x, long double *y) #else #error "architecture unsupported" #endif + +#endif /* long double is long */ diff --git a/libc/tinymath/remquo.c b/libc/tinymath/remquo.c index 4b69efa07..2907a1ef8 100644 --- a/libc/tinymath/remquo.c +++ b/libc/tinymath/remquo.c @@ -117,5 +117,5 @@ end: } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(remquo, remquol); +__weak_reference(remquo, remquol); #endif diff --git a/libc/tinymath/rint.c b/libc/tinymath/rint.c index 01d0a0b1a..890dc3585 100644 --- a/libc/tinymath/rint.c +++ b/libc/tinymath/rint.c @@ -66,5 +66,5 @@ double rint(double x) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(rint, rintl); +__weak_reference(rint, rintl); #endif diff --git a/libc/tinymath/round.c b/libc/tinymath/round.c index 672a76157..ccab1f81a 100644 --- a/libc/tinymath/round.c +++ b/libc/tinymath/round.c @@ -92,5 +92,5 @@ double round(double x) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(round, roundl); +__weak_reference(round, roundl); #endif diff --git a/libc/tinymath/scalbln.c b/libc/tinymath/scalbln.c index c83371f13..b67f7ed5e 100644 --- a/libc/tinymath/scalbln.c +++ b/libc/tinymath/scalbln.c @@ -26,5 +26,5 @@ double scalbln(double x, long n) { } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(scalbln, scalblnl); +__weak_reference(scalbln, scalblnl); #endif diff --git a/libc/tinymath/significand.c b/libc/tinymath/significand.c index d4894fc9d..c1f5c2120 100644 --- a/libc/tinymath/significand.c +++ b/libc/tinymath/significand.c @@ -26,5 +26,5 @@ double significand(double x) { } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(significand, significandl); +__weak_reference(significand, significandl); #endif diff --git a/libc/tinymath/sin.c b/libc/tinymath/sin.c index d6165c569..8e44a3daf 100644 --- a/libc/tinymath/sin.c +++ b/libc/tinymath/sin.c @@ -123,5 +123,5 @@ double sin(double x) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(sin, sinl); +__weak_reference(sin, sinl); #endif diff --git a/libc/tinymath/sincos.c b/libc/tinymath/sincos.c index 1bec6f85d..83c9b2499 100644 --- a/libc/tinymath/sincos.c +++ b/libc/tinymath/sincos.c @@ -114,5 +114,5 @@ void sincos(double x, double *sin, double *cos) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(sincos, sincosl); +__weak_reference(sincos, sincosl); #endif diff --git a/libc/tinymath/sinh.c b/libc/tinymath/sinh.c index ca31389be..03eba024b 100644 --- a/libc/tinymath/sinh.c +++ b/libc/tinymath/sinh.c @@ -75,3 +75,7 @@ double sinh(double x) t = __expo2(absx, 2*h); return t; } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__weak_reference(sinh, sinhl); +#endif diff --git a/libc/tinymath/sinhl.c b/libc/tinymath/sinhl.c index 864da9142..fdc274696 100644 --- a/libc/tinymath/sinhl.c +++ b/libc/tinymath/sinhl.c @@ -39,6 +39,7 @@ #include "libc/intrin/likely.h" #include "libc/math.h" #include "libc/tinymath/freebsd.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ FreeBSD libm (BSD-2 License)\\n\ @@ -154,3 +155,5 @@ sinhl(long double x) /* |x| > o_threshold, sinh(x) overflow */ return x*shuge; } + +#endif /* long double is long */ diff --git a/libc/tinymath/sqrt.c b/libc/tinymath/sqrt.c index 332b4a683..a9181d804 100644 --- a/libc/tinymath/sqrt.c +++ b/libc/tinymath/sqrt.c @@ -222,5 +222,5 @@ double sqrt(double x) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(sqrt, sqrtl); +__weak_reference(sqrt, sqrtl); #endif diff --git a/libc/tinymath/tan.c b/libc/tinymath/tan.c index efb25e3a2..f1851f8e6 100644 --- a/libc/tinymath/tan.c +++ b/libc/tinymath/tan.c @@ -115,5 +115,5 @@ double tan(double x) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(tan, tanl); +__weak_reference(tan, tanl); #endif diff --git a/libc/tinymath/tanh.c b/libc/tinymath/tanh.c index aebdb3822..fd01f4cb9 100644 --- a/libc/tinymath/tanh.c +++ b/libc/tinymath/tanh.c @@ -76,3 +76,7 @@ double tanh(double x) } return sign ? -t : t; } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__weak_reference(tanh, tanhl); +#endif diff --git a/libc/tinymath/tanhl.c b/libc/tinymath/tanhl.c index da6f68c83..a409fe0ea 100644 --- a/libc/tinymath/tanhl.c +++ b/libc/tinymath/tanhl.c @@ -39,6 +39,7 @@ #include "libc/intrin/likely.h" #include "libc/math.h" #include "libc/tinymath/freebsd.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ FreeBSD libm (BSD-2 License)\\n\ @@ -185,3 +186,5 @@ tanhl(long double x) if (jx<0) s = -1; RETURNI(s*z); } + +#endif /* long double is long */ diff --git a/libc/tinymath/tinymath.h b/libc/tinymath/tinymath.h deleted file mode 100755 index e69de29bb..000000000 diff --git a/libc/tinymath/trunc.c b/libc/tinymath/trunc.c index e51aef61a..dcc7ac665 100644 --- a/libc/tinymath/trunc.c +++ b/libc/tinymath/trunc.c @@ -82,5 +82,5 @@ double trunc(double x) } #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -__strong_reference(trunc, truncl); +__weak_reference(trunc, truncl); #endif diff --git a/libc/x/x.h b/libc/x/x.h index 0b33edf2d..66dae189e 100644 --- a/libc/x/x.h +++ b/libc/x/x.h @@ -6,9 +6,6 @@ COSMOPOLITAN_C_START_ #define xwrite __xwrite #define xdie __xdie -#define xdtoa __xdtoa -#define xdtoaf __xdtoaf -#define xdtoal __xdtoal #define xmalloc __xmalloc #define xrealloc __xrealloc #define xcalloc __xcalloc diff --git a/libc/x/xdtoa.c b/libc/x/xdtoa.c index 1549d726f..34e624d57 100644 --- a/libc/x/xdtoa.c +++ b/libc/x/xdtoa.c @@ -31,3 +31,7 @@ char *xdtoa(double d) { g_dfmt_p(p, &d, DBL_DIG, 32, 2); return p; } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__weak_reference(xdtoa, xdtoal); +#endif diff --git a/libc/x/xdtoal.c b/libc/x/xdtoal.c index d9ae9d2aa..206cce7e8 100644 --- a/libc/x/xdtoal.c +++ b/libc/x/xdtoal.c @@ -20,6 +20,7 @@ #include "libc/mem/mem.h" #include "libc/x/x.h" #include "third_party/gdtoa/gdtoa.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) /** * Converts long double to string the easy way. @@ -31,9 +32,13 @@ char *xdtoal(long double d) { #if LDBL_MANT_DIG == 113 p = xmalloc(64); g_Qfmt_p(p, &d, 16, 64, NIK(2, 0, 0)); -#else +#elif LDBL_MANT_DIG == 64 p = xmalloc(32); g_xfmt_p(p, &d, 16, 32, NIK(2, 0, 0)); +#else +#error "unsupported long double" #endif return p; } + +#endif /* long double is long */ diff --git a/test/libc/calls/pledge_test.c b/test/libc/calls/pledge_test.c index 8cd01dbd4..cab5e869b 100644 --- a/test/libc/calls/pledge_test.c +++ b/test/libc/calls/pledge_test.c @@ -32,7 +32,6 @@ #include "libc/errno.h" #include "libc/intrin/kprintf.h" #include "libc/macros.internal.h" -#include "libc/mem/copyfd.internal.h" #include "libc/mem/mem.h" #include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" diff --git a/test/libc/calls/unveil_test.c b/test/libc/calls/unveil_test.c index 4501ec0be..275794f1a 100644 --- a/test/libc/calls/unveil_test.c +++ b/test/libc/calls/unveil_test.c @@ -24,7 +24,6 @@ #include "libc/dce.h" #include "libc/errno.h" #include "libc/intrin/kprintf.h" -#include "libc/mem/copyfd.internal.h" #include "libc/mem/gc.h" #include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" diff --git a/test/libc/log/backtrace_test.c b/test/libc/log/backtrace_test.c index 83bfd53ba..adf9cfea8 100644 --- a/test/libc/log/backtrace_test.c +++ b/test/libc/log/backtrace_test.c @@ -26,7 +26,6 @@ #include "libc/limits.h" #include "libc/log/libfatal.internal.h" #include "libc/log/log.h" -#include "libc/mem/copyfd.internal.h" #include "libc/mem/gc.h" #include "libc/mem/mem.h" #include "libc/runtime/internal.h" diff --git a/test/libc/stdio/system_test.c b/test/libc/stdio/system_test.c index 6a97baf32..7460d1b25 100644 --- a/test/libc/stdio/system_test.c +++ b/test/libc/stdio/system_test.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/dce.h" -#include "libc/mem/copyfd.internal.h" #include "libc/mem/gc.h" #include "libc/paths.h" #include "libc/runtime/runtime.h" diff --git a/test/tool/plinko/plinko_test.c b/test/tool/plinko/plinko_test.c index 769f5221d..2d63eb5fd 100644 --- a/test/tool/plinko/plinko_test.c +++ b/test/tool/plinko/plinko_test.c @@ -21,7 +21,6 @@ #include "libc/errno.h" #include "libc/intrin/kprintf.h" #include "libc/macros.internal.h" -#include "libc/mem/copyfd.internal.h" #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" @@ -58,7 +57,7 @@ void SetUpOnce(void) { ASSERT_NE(-1, mkdir("bin", 0755)); ASSERT_NE(-1, (fdin = open("/zip/plinko.com", O_RDONLY))); ASSERT_NE(-1, (fdout = creat("bin/plinko.com", 0755))); - ASSERT_NE(-1, _copyfd(fdin, fdout, -1)); + ASSERT_NE(-1, copyfd(fdin, fdout, -1)); EXPECT_EQ(0, close(fdout)); EXPECT_EQ(0, close(fdin)); } @@ -100,7 +99,7 @@ TEST(plinko, worksOrPrintsNiceError) { close(pfds[1][1]); for (i = 0; i < ARRAYLEN(kSauces); ++i) { EXPECT_NE(-1, (fdin = open(kSauces[i], O_RDONLY))); - rc = _copyfd(fdin, pfds[0][1], -1); + rc = copyfd(fdin, pfds[0][1], -1); if (rc == -1) EXPECT_EQ(EPIPE, errno); EXPECT_NE(-1, close(fdin)); } diff --git a/third_party/compiler_rt/addtf3.c b/third_party/compiler_rt/addtf3.c index c01000c98..535256e80 100644 --- a/third_party/compiler_rt/addtf3.c +++ b/third_party/compiler_rt/addtf3.c @@ -12,6 +12,8 @@ // default rounding (to nearest, ties to even). // //===----------------------------------------------------------------------===// +#include "libc/math.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) STATIC_YOINK("huge_compiler_rt_license"); @@ -26,3 +28,5 @@ COMPILER_RT_ABI long double __addtf3(long double a, long double b){ } #endif + +#endif /* long double is long */ diff --git a/third_party/compiler_rt/divtc3.c b/third_party/compiler_rt/divtc3.c index 262bffdae..28e20f501 100644 --- a/third_party/compiler_rt/divtc3.c +++ b/third_party/compiler_rt/divtc3.c @@ -12,6 +12,8 @@ * *===----------------------------------------------------------------------=== */ +#include "libc/math.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) STATIC_YOINK("huge_compiler_rt_license"); @@ -64,3 +66,5 @@ __divtc3(long double __a, long double __b, long double __c, long double __d) } return z; } + +#endif /* long double is long */ diff --git a/third_party/compiler_rt/divxc3.c b/third_party/compiler_rt/divxc3.c index aa77db02a..7e8216802 100644 --- a/third_party/compiler_rt/divxc3.c +++ b/third_party/compiler_rt/divxc3.c @@ -11,6 +11,8 @@ * This file implements __divxc3 for the compiler_rt library. * */ +#include "libc/math.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) STATIC_YOINK("huge_compiler_rt_license"); @@ -64,3 +66,5 @@ __divxc3(long double __a, long double __b, long double __c, long double __d) } #endif + +#endif /* long double is long */ diff --git a/third_party/compiler_rt/fixunsxfdi.c b/third_party/compiler_rt/fixunsxfdi.c index 0049baa74..74df1c457 100644 --- a/third_party/compiler_rt/fixunsxfdi.c +++ b/third_party/compiler_rt/fixunsxfdi.c @@ -12,6 +12,8 @@ * * ===----------------------------------------------------------------------=== */ +#include "libc/math.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) STATIC_YOINK("huge_compiler_rt_license"); @@ -47,3 +49,5 @@ __fixunsxfdi(long double a) } #endif + +#endif /* long double is long */ diff --git a/third_party/compiler_rt/fixunsxfsi.c b/third_party/compiler_rt/fixunsxfsi.c index 82b843a88..4cd4e92b4 100644 --- a/third_party/compiler_rt/fixunsxfsi.c +++ b/third_party/compiler_rt/fixunsxfsi.c @@ -12,6 +12,8 @@ * * ===----------------------------------------------------------------------=== */ +#include "libc/math.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) STATIC_YOINK("huge_compiler_rt_license"); @@ -46,3 +48,5 @@ __fixunsxfsi(long double a) } #endif /* !_ARCH_PPC */ + +#endif /* long double is long */ diff --git a/third_party/compiler_rt/fixunsxfti.c b/third_party/compiler_rt/fixunsxfti.c index f3b0d2723..5fd8bc4ef 100644 --- a/third_party/compiler_rt/fixunsxfti.c +++ b/third_party/compiler_rt/fixunsxfti.c @@ -12,6 +12,8 @@ * * ===----------------------------------------------------------------------=== */ +#include "libc/math.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) STATIC_YOINK("huge_compiler_rt_license"); @@ -51,3 +53,5 @@ __fixunsxfti(long double a) } #endif /* CRT_HAS_128BIT */ + +#endif /* long double is long */ diff --git a/third_party/compiler_rt/fixxfdi.c b/third_party/compiler_rt/fixxfdi.c index 269aa0e94..e6d002b8e 100644 --- a/third_party/compiler_rt/fixxfdi.c +++ b/third_party/compiler_rt/fixxfdi.c @@ -12,6 +12,8 @@ * * ===----------------------------------------------------------------------=== */ +#include "libc/math.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) STATIC_YOINK("huge_compiler_rt_license"); @@ -49,3 +51,5 @@ __fixxfdi(long double a) } #endif /* !_ARCH_PPC */ + +#endif /* long double is long */ diff --git a/third_party/compiler_rt/fixxfti.c b/third_party/compiler_rt/fixxfti.c index e344acdcc..2c3039c90 100644 --- a/third_party/compiler_rt/fixxfti.c +++ b/third_party/compiler_rt/fixxfti.c @@ -12,6 +12,8 @@ * * ===----------------------------------------------------------------------=== */ +#include "libc/math.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) STATIC_YOINK("huge_compiler_rt_license"); @@ -52,3 +54,5 @@ __fixxfti(long double a) } #endif /* CRT_HAS_128BIT */ + +#endif /* long double is long */ diff --git a/third_party/compiler_rt/ilogbl.c b/third_party/compiler_rt/ilogbl.c index fa21e7164..cb18842ef 100644 --- a/third_party/compiler_rt/ilogbl.c +++ b/third_party/compiler_rt/ilogbl.c @@ -29,22 +29,21 @@ #include "libc/math.h" #include "libc/tinymath/internal.h" #include "libc/tinymath/ldshape.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); -/* clang-format off */ +// clang-format off -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +/** + * Returns log₂𝑥 exponent part of double. + */ int ilogbl(long double x) { - return ilogb(x); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 -int ilogbl(long double x) -{ - //#pragma STDC FENV_ACCESS ON +#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 +// #pragma STDC FENV_ACCESS ON union ldshape u = {x}; uint64_t m = u.i.m; int e = u.i.se & 0x7fff; @@ -63,11 +62,8 @@ int ilogbl(long double x) return m<<1 ? FP_ILOGBNAN : INT_MAX; } return e - 0x3fff; -} #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -int ilogbl(long double x) -{ - //#pragma STDC FENV_ACCESS ON +// #pragma STDC FENV_ACCESS ON union ldshape u = {x}; int e = u.i.se & 0x7fff; @@ -86,5 +82,7 @@ int ilogbl(long double x) return u.f ? FP_ILOGBNAN : INT_MAX; } return e - 0x3fff; -} #endif +} + +#endif /* long double is long */ diff --git a/third_party/compiler_rt/logbl.c b/third_party/compiler_rt/logbl.c index 85022ec31..58bddfda5 100644 --- a/third_party/compiler_rt/logbl.c +++ b/third_party/compiler_rt/logbl.c @@ -26,19 +26,14 @@ │ │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); -/* clang-format off */ +// clang-format off -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double logbl(long double x) -{ - return logb(x); -} -#else long double logbl(long double x) { if (!isfinite(x)) @@ -47,4 +42,5 @@ long double logbl(long double x) return -1/(x*x); return ilogbl(x); } -#endif + +#endif /* long double is long */ diff --git a/third_party/nsync/compat.S b/third_party/nsync/compat.S index 795e39631..44e3b109d 100644 --- a/third_party/nsync/compat.S +++ b/third_party/nsync/compat.S @@ -19,10 +19,6 @@ #include "libc/calls/struct/timespec.h" #include "libc/macros.internal.h" -#ifdef __aarch64__ -#define jmp b -#endif - nsync_time_now: jmp timespec_real .endfn nsync_time_now,globl diff --git a/third_party/nsync/futex.c b/third_party/nsync/futex.c index e97ff264f..665b38111 100644 --- a/third_party/nsync/futex.c +++ b/third_party/nsync/futex.c @@ -202,11 +202,7 @@ static struct timespec *nsync_futex_timeout_ (struct timespec *memory, return memory; } else { now = timespec_real (); - if (timespec_cmp (now, *abstime) > 0) { - *memory = (struct timespec){0}; - } else { - *memory = timespec_sub (*abstime, now); - } + *memory = timespec_subz (*abstime, now); return memory; } } diff --git a/tool/build/ar.c b/tool/build/ar.c index 7de54647b..40c9a3f1d 100644 --- a/tool/build/ar.c +++ b/tool/build/ar.c @@ -30,7 +30,6 @@ #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/mem/arraylist2.internal.h" -#include "libc/mem/copyfd.internal.h" #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" #include "libc/sock/sock.h" @@ -322,8 +321,8 @@ int main(int argc, char *argv[]) { goto fail; } outsize += (remain = sizes.p[i]); - if (_copyfd(fd, outfd, remain) == -1) { - reason = "copy_file_range failed"; + if (copyfd(fd, outfd, remain) == -1) { + reason = "copy failed"; goto fail; } close(fd); diff --git a/tool/build/compile.c b/tool/build/compile.c index 30c65917d..8dd479c89 100644 --- a/tool/build/compile.c +++ b/tool/build/compile.c @@ -43,7 +43,6 @@ #include "libc/macros.internal.h" #include "libc/math.h" #include "libc/mem/alg.h" -#include "libc/mem/copyfd.internal.h" #include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/kcpuids.h" @@ -769,7 +768,7 @@ bool MovePreservingDestinationInode(const char *from, const char *to) { res = false; break; } - res = _copyfd(fdin, fdout, -1) != -1; + res = copyfd(fdin, fdout, -1) != -1; break; } else { res = false; diff --git a/tool/build/cp.c b/tool/build/cp.c index 633a50b5b..8fed73998 100644 --- a/tool/build/cp.c +++ b/tool/build/cp.c @@ -23,7 +23,6 @@ #include "libc/fmt/conv.h" #include "libc/fmt/fmt.h" #include "libc/fmt/magnumstrs.internal.h" -#include "libc/mem/copyfd.internal.h" #include "libc/mem/gc.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" @@ -176,7 +175,7 @@ bool MovePreservingDestinationInode(const char *from, const char *to) { close(fdin); return false; } - res = _copyfd(fdin, fdout, -1) != -1; + res = copyfd(fdin, fdout, -1) != -1; close(fdin); close(fdout); return res; diff --git a/tool/build/ocat.c b/tool/build/ocat.c index 630e5476f..d45bb5b79 100644 --- a/tool/build/ocat.c +++ b/tool/build/ocat.c @@ -20,7 +20,6 @@ #include "libc/errno.h" #include "libc/fmt/itoa.h" #include "libc/fmt/magnumstrs.internal.h" -#include "libc/mem/copyfd.internal.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "libc/sysv/consts/ex.h" diff --git a/tool/build/pledge.c b/tool/build/pledge.c index 98560ab67..8680c84ca 100644 --- a/tool/build/pledge.c +++ b/tool/build/pledge.c @@ -39,7 +39,6 @@ #include "libc/intrin/safemacros.internal.h" #include "libc/macros.internal.h" #include "libc/math.h" -#include "libc/mem/copyfd.internal.h" #include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/kcpuids.h" @@ -523,7 +522,7 @@ int Extract(const char *from, const char *to, int mode) { close(fdin); return -1; } - if (_copyfd(fdin, fdout, -1) == -1) { + if (copyfd(fdin, fdout, -1) == -1) { close(fdout); close(fdin); return -1; diff --git a/tool/plinko/lib/plinko.c b/tool/plinko/lib/plinko.c index a34c94d29..c0ba54dfe 100644 --- a/tool/plinko/lib/plinko.c +++ b/tool/plinko/lib/plinko.c @@ -33,6 +33,7 @@ #include "libc/runtime/symbols.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" +#include "libc/sysv/consts/arch.h" #include "libc/sysv/consts/map.h" #include "libc/sysv/consts/o.h" #include "libc/sysv/consts/prot.h" diff --git a/tool/scripts/cosmoc++ b/tool/scripts/cosmoc++ index 49cf71fca..63aaa283d 100755 --- a/tool/scripts/cosmoc++ +++ b/tool/scripts/cosmoc++ @@ -154,6 +154,10 @@ for x; do set -- "$@" "$x" done +if [ x"$MODE" = x"nox87" ]; then + CCFLAGS="$CCFLAGS -mlong-double-64" +fi + if [ x"$OPT" != x"-Os" ] && [ x"${MODE#tiny}" != x"${MODE}" ]; then # support --ftrace unless optimizing for size CXXFLAGS="$CXXFLAGS -fpatchable-function-entry=18,16" diff --git a/tool/scripts/cosmocc b/tool/scripts/cosmocc index fb5271b20..363453fdd 100755 --- a/tool/scripts/cosmocc +++ b/tool/scripts/cosmocc @@ -154,6 +154,10 @@ for x; do set -- "$@" "$x" done +if [ x"$MODE" = x"nox87" ]; then + CCFLAGS="$CCFLAGS -mlong-double-64" +fi + if [ x"$OPT" != x"-Os" ] && [ x"${MODE#tiny}" != x"${MODE}" ]; then # support --ftrace unless optimizing for size CFLAGS="$CFLAGS -fpatchable-function-entry=18,16" diff --git a/tool/viz/printpeb.c b/tool/viz/printpeb.c index 4f56c704b..1cf885cb5 100644 --- a/tool/viz/printpeb.c +++ b/tool/viz/printpeb.c @@ -21,7 +21,6 @@ #include "libc/dce.h" #include "libc/intrin/safemacros.internal.h" #include "libc/log/log.h" -#include "libc/mem/copyfd.internal.h" #include "libc/nt/dll.h" #include "libc/nt/enum/filetype.h" #include "libc/nt/enum/startf.h" @@ -58,7 +57,7 @@ int NextBestThing(void) { int64_t fd = open("/proc/self/maps", O_RDONLY); posix_fadvise(fd, 0, 0, MADV_SEQUENTIAL); ssize_t wrote; - while ((wrote = _copyfd(fd, 1, -1)) != -1) { + while ((wrote = copyfd(fd, 1, -1)) != -1) { if (wrote == 0) break; } close(fd);