From d7c79f43ef2e4b1c21d27f825004deb23fc975f6 Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Sun, 18 Jun 2023 00:55:09 -0700 Subject: [PATCH] Clean up more code - Found some bugs in LLVM compiler-rt library - The useless LIBC_STUBS package is now deleted - Improve the overflow checking story even further - Get chibicc tests working in MODE=dbg mode again - The libc/isystem/ headers now have correctly named guards --- Makefile | 4 +- dsp/bmp/bmp.mk | 3 +- dsp/core/core.mk | 3 +- dsp/mpeg/mpeg.mk | 1 - dsp/scale/scale.mk | 2 - dsp/tty/tty.mk | 1 - examples/clock.c | 2 +- examples/examples.mk | 3 +- examples/package/build.mk | 1 - examples/package/lib/build.mk | 3 +- examples/whois.c | 1 - libc/calls/calls.h | 6 + libc/calls/calls.mk | 5 +- libc/calls/copy.c | 3 +- libc/calls/now.c | 2 + libc/calls/oldbench.c | 2 + libc/calls/weirdtypes.h | 70 +++--- libc/dns/dns.mk | 9 +- libc/elf/elf.h | 15 +- libc/elf/elf.mk | 1 - libc/elf/getelfdynstringtable.c | 36 --- libc/elf/getelfdynsymboltable.c | 35 --- ...address.c => getelfprogramheaderaddress.c} | 25 +- libc/elf/getelfsectionaddress.c | 21 +- libc/elf/getelfsectionheaderaddress.c | 22 +- libc/elf/getelfsectionnamestringtable.c | 9 +- libc/elf/getelfstring.c | 27 +- libc/elf/getelfstringtable.c | 18 +- libc/elf/getelfstrs.c | 37 --- libc/elf/getelfsymboltable.c | 32 ++- libc/elf/getelfvirtualaddressrange.c | 39 --- libc/elf/iself64binary.c | 16 +- libc/elf/scalar.h | 2 - libc/fmt/fmt.h | 9 +- libc/fmt/fmt.mk | 3 +- libc/intrin/__cxa_pure_virtual.c | 3 +- libc/{stubs/retpoline.S => intrin/abort.c} | 15 +- libc/intrin/asan.c | 2 +- libc/intrin/ashlti3.c | 4 - libc/intrin/assertfail.greg.c | 1 + libc/intrin/divmodti4.c | 8 +- libc/{stubs => intrin}/gcov.S | 0 libc/intrin/intrin.mk | 11 +- libc/intrin/mulodi4.c | 2 +- libc/intrin/mulosi4.c | 2 +- libc/intrin/muloti4.c | 2 +- libc/intrin/onarithmeticoverflow.c | 3 +- libc/{runtime => intrin}/stackchkfail.c | 5 +- libc/{runtime => intrin}/stackchkfaillocal.c | 2 +- libc/{stubs => intrin}/stackchkguard.S | 0 libc/{stubs => intrin}/typeinfo.S | 0 libc/intrin/ubsan.c | 2 +- libc/isystem/assert.h | 6 +- libc/isystem/byteswap.h | 6 +- libc/isystem/complex.h | 6 +- libc/isystem/cosmo.h | 1 + libc/isystem/cpio.h | 6 +- libc/isystem/cpuid.h | 6 +- libc/isystem/crypt.h | 6 +- libc/isystem/ctype.h | 6 +- libc/isystem/dirent.h | 6 +- libc/isystem/dlfcn.h | 6 +- libc/isystem/dog.py | 4 - libc/isystem/elf.h | 26 +- libc/isystem/endian.h | 6 +- libc/isystem/err.h | 6 +- libc/isystem/errno.h | 6 +- libc/isystem/fcntl.h | 6 +- libc/isystem/features.h | 6 +- libc/isystem/fenv.h | 6 +- libc/isystem/float.h | 6 +- libc/isystem/fnmatch.h | 6 +- libc/isystem/ftw.h | 6 +- libc/isystem/fun.py | 4 - libc/isystem/getopt.h | 6 +- libc/isystem/glob.h | 6 +- libc/isystem/grp.h | 6 +- libc/isystem/iconv.h | 6 +- libc/isystem/inttypes.h | 6 +- libc/isystem/iso646.h | 6 +- libc/isystem/langinfo.h | 6 +- libc/isystem/libgen.h | 6 +- libc/isystem/limits.h | 6 +- libc/isystem/locale.h | 6 +- libc/isystem/malloc.h | 6 +- libc/isystem/math.h | 6 +- libc/isystem/memory.h | 6 +- libc/isystem/netdb.h | 6 +- libc/isystem/setjmp.h | 6 +- libc/isystem/signal.h | 6 +- libc/isystem/stdalign.h | 6 +- libc/isystem/stdarg.h | 6 +- libc/isystem/stdatomic.h | 6 +- libc/isystem/stdbool.h | 6 +- libc/isystem/stdckdint.h | 6 +- libc/isystem/stddef.h | 6 +- libc/isystem/stdint.h | 6 +- libc/isystem/stdio.h | 9 +- libc/isystem/stdio_ext.h | 6 +- libc/isystem/stdlib.h | 6 +- libc/isystem/stdnoreturn.h | 19 +- libc/isystem/string.h | 6 +- libc/isystem/strings.h | 6 +- libc/isystem/sysexits.h | 6 +- libc/isystem/syslog.h | 6 +- libc/isystem/termios.h | 6 +- libc/isystem/tgmath.h | 6 +- libc/isystem/time.h | 7 +- libc/isystem/unistd.h | 6 +- libc/isystem/utime.h | 6 +- libc/isystem/utmp.h | 6 +- libc/isystem/utmpx.h | 6 +- libc/isystem/wait.h | 6 +- libc/isystem/wchar.h | 6 +- libc/isystem/wctype.h | 6 +- libc/log/attachdebugger.c | 2 +- libc/log/log.mk | 1 - libc/log/oncrash_amd64.c | 7 +- libc/mem/fmt.h | 12 - libc/mem/mem.mk | 3 +- libc/nexgen32e/nexgen32e.mk | 3 - libc/nt/struct/msg.h | 4 +- .../xnu.S => runtime/__stack_chk_fail.c} | 11 +- libc/runtime/isdynamicexecutable.c | 2 +- libc/runtime/mmap.c | 1 + libc/runtime/runtime.mk | 1 - libc/runtime/utmp.c | 4 + libc/sock/sock.mk | 7 +- libc/stdckdint.h | 101 +++++++- libc/stdio/asprintf.c | 6 +- libc/stdio/dprintf.c | 4 +- libc/stdio/fprintf.c | 4 +- libc/stdio/fprintf_unlocked.c | 4 +- libc/stdio/fscanf.c | 4 +- libc/stdio/printf.c | 4 +- libc/stdio/scanf.c | 4 +- libc/stdio/snprintf.c | 4 +- libc/stdio/sprintf.c | 4 +- libc/stdio/sscanf.c | 4 +- libc/stdio/stdio.h | 14 +- libc/stdio/stdio.mk | 1 - libc/stdio/vasprintf.c | 6 +- libc/stdio/vcscanf.c | 7 +- libc/stdio/vdprintf.c | 2 +- libc/stdio/vfprintf.c | 4 +- libc/stdio/vfprintf_unlocked.c | 2 +- libc/stdio/vfscanf.c | 4 +- libc/stdio/vprintf.c | 4 +- libc/stdio/vscanf.c | 4 +- libc/stdio/vsnprintf.c | 2 +- libc/stdio/vsprintf.c | 4 +- libc/stdio/vsscanf.c | 4 +- libc/str/str.mk | 3 +- libc/stubs/abort.S | 33 --- libc/stubs/debugbreak.S | 31 --- libc/stubs/instrumentation.S | 32 --- libc/stubs/panic.S | 32 --- libc/stubs/pututxline.S | 27 -- libc/stubs/stackguard.S | 44 ---- libc/stubs/stubs.mk | 56 ----- libc/testlib/testlib.mk | 3 - libc/thread/thread.mk | 3 +- libc/time/time.h | 28 +-- libc/time/time.mk | 3 - libc/time/xiso8601.c | 4 +- libc/tinymath/tinymath.mk | 1 - libc/vga/tty.greg.c | 2 +- libc/vga/vga.mk | 9 +- libc/x/x.mk | 1 - libc/x/xasprintf.c | 4 +- libc/x/xvasprintf.c | 6 +- libc/zipos/zipos.mk | 15 +- net/http/foldheader.c | 12 +- net/http/http.mk | 1 - net/https/https.mk | 1 - net/turfwar/turfwar.mk | 1 - test/dsp/scale/test.mk | 1 - test/dsp/tty/test.mk | 1 - test/libc/calls/test.mk | 1 - test/libc/dns/test.mk | 1 - test/libc/fmt/test.mk | 1 - test/libc/intrin/stdckdint_test.c | 238 +++++++++++++++--- test/libc/intrin/test.mk | 1 - test/libc/log/test.mk | 1 - test/libc/mem/test.mk | 1 - test/libc/nexgen32e/test.mk | 1 - test/libc/runtime/test.mk | 1 - test/libc/sock/test.mk | 1 - test/libc/stdio/test.mk | 1 - test/libc/str/test.mk | 1 - test/libc/thread/sem_open_test.c | 5 +- test/libc/thread/sem_timedwait_test.c | 8 +- test/libc/thread/test.mk | 1 - test/libc/time/test.mk | 1 - test/libc/tinymath/test.mk | 1 - test/libc/x/test.mk | 1 - test/libc/xed/test.mk | 2 - test/libc/zipos/test.mk | 1 - test/tool/args/test.mk | 1 - test/tool/build/lib/test.mk | 1 - test/tool/net/test.mk | 1 - test/tool/plinko/test.mk | 1 - test/tool/viz/lib/test.mk | 1 - third_party/argon2/argon2.mk | 3 +- third_party/awk/awk.mk | 1 - third_party/bzip2/bzip2.mk | 1 - third_party/chibicc/chibicc.mk | 6 - third_party/chibicc/test/arith_test.c | 1 + third_party/chibicc/test/test.mk | 5 - third_party/compiler_rt/compiler_rt.mk | 1 - third_party/ctags/args.h | 1 - third_party/ctags/ctags.mk | 1 - third_party/ctags/eiffel.c | 1 - third_party/ctags/entry.h | 1 - third_party/ctags/flex.c | 1 - third_party/ctags/jscript.c | 1 - third_party/ctags/main.h | 1 - third_party/ctags/options.c | 1 - third_party/ctags/read.h | 1 - third_party/ctags/sort.c | 1 - third_party/ctags/sql.c | 1 - third_party/ctags/tex.c | 1 - third_party/ctags/vim.c | 1 - third_party/dlmalloc/dlmalloc.mk | 1 - third_party/finger/finger.mk | 1 - third_party/gdtoa/gdtoa.mk | 1 - third_party/getopt/getopt.mk | 3 +- third_party/ggml/ggml.mk | 2 - third_party/hiredis/hiredis.mk | 1 - third_party/hiredis/net.c | 1 - third_party/hiredis/read.h | 1 - third_party/hiredis/sds.c | 2 - third_party/libcxx/__bsd_locale_fallbacks.h | 1 - third_party/libcxx/ctime | 1 + third_party/libcxx/libcxx.mk | 1 - third_party/linenoise/linenoise.mk | 1 - third_party/lua/lmathlib.c | 2 +- third_party/lua/ltablib.c | 2 +- third_party/lua/lua.mk | 1 - third_party/lua/lunix.c | 1 - third_party/maxmind/maxmind.mk | 1 - third_party/mbedtls/platform.h | 1 + third_party/musl/musl.mk | 1 - third_party/nsync/mem/mem.mk | 1 - third_party/nsync/nsync.mk | 1 - third_party/nsync/testing/testing.mk | 1 - third_party/puff/puff.mk | 3 +- third_party/python/python.mk | 4 - third_party/quickjs/qjs.c | 2 +- third_party/quickjs/run-test262.c | 2 +- third_party/radpajama/radpajama.mk | 2 - third_party/regex/regex.mk | 3 +- third_party/sed/sed.mk | 1 - third_party/smallz4/smallz4.mk | 1 - third_party/sqlite3/sqlite3.mk | 1 - third_party/stb/stb.mk | 1 - third_party/tidy/tidy.mk | 3 +- third_party/tr/tr.mk | 1 - third_party/unzip/unzip.mk | 1 - third_party/vqsort/vqsort.mk | 1 - third_party/xed/xed.mk | 3 +- third_party/zip/tailor.h | 1 - third_party/zip/zip.c | 1 - third_party/zip/zip.mk | 1 - third_party/zlib/deflate.c | 8 +- third_party/zlib/gz/gz.mk | 1 - third_party/zlib/inflate.c | 3 +- third_party/zlib/trees.c | 1 - third_party/zlib/zlib.h | 2 +- third_party/zlib/zlib.mk | 3 +- tool/args/args.mk | 1 - tool/build/ar.c | 6 +- tool/build/build.mk | 1 - tool/build/fixupobj.c | 4 +- tool/build/lib/buffer.c | 3 +- tool/build/lib/buildlib.mk | 4 +- tool/build/package.c | 5 +- tool/curl/curl.mk | 1 - tool/decode/decode.mk | 1 - tool/decode/elf.c | 16 +- tool/decode/lib/decodelib.mk | 1 - tool/hash/crctab.c | 49 ---- tool/hash/hash.mk | 48 ---- tool/hello/hello.mk | 3 +- tool/lambda/lambda.mk | 13 +- tool/lambda/lib/lib.mk | 5 +- tool/net/net.mk | 1 - tool/plinko/lib/lib.mk | 1 - tool/plinko/plinko.mk | 1 - tool/scripts/cosmoc++ | 10 +- tool/scripts/cosmocc | 10 +- tool/tool.mk | 1 - tool/viz/lib/vizlib.mk | 1 - tool/viz/viz.mk | 1 - 294 files changed, 912 insertions(+), 1208 deletions(-) delete mode 100644 libc/elf/getelfdynstringtable.c delete mode 100644 libc/elf/getelfdynsymboltable.c rename libc/elf/{getelfsegmentheaderaddress.c => getelfprogramheaderaddress.c} (74%) delete mode 100644 libc/elf/getelfstrs.c delete mode 100644 libc/elf/getelfvirtualaddressrange.c rename libc/{stubs/retpoline.S => intrin/abort.c} (82%) rename libc/{stubs => intrin}/gcov.S (100%) rename libc/{runtime => intrin}/stackchkfail.c (92%) rename libc/{runtime => intrin}/stackchkfaillocal.c (96%) rename libc/{stubs => intrin}/stackchkguard.S (100%) rename libc/{stubs => intrin}/typeinfo.S (100%) delete mode 100644 libc/isystem/dog.py delete mode 100644 libc/isystem/fun.py delete mode 100644 libc/mem/fmt.h rename libc/{stubs/xnu.S => runtime/__stack_chk_fail.c} (85%) delete mode 100644 libc/stubs/abort.S delete mode 100644 libc/stubs/debugbreak.S delete mode 100644 libc/stubs/instrumentation.S delete mode 100644 libc/stubs/panic.S delete mode 100644 libc/stubs/pututxline.S delete mode 100644 libc/stubs/stackguard.S delete mode 100644 libc/stubs/stubs.mk delete mode 100644 tool/hash/crctab.c delete mode 100644 tool/hash/hash.mk diff --git a/Makefile b/Makefile index 84bd79b00..4185f5682 100644 --- a/Makefile +++ b/Makefile @@ -113,8 +113,7 @@ include build/functions.mk #─┐ include build/definitions.mk # ├──META include build/config.mk # │ You can build include build/rules.mk # │ You can topologically order -include build/online.mk # │ -include libc/stubs/stubs.mk #─┘ +include build/online.mk #─┘ include libc/nexgen32e/nexgen32e.mk #─┐ include libc/sysv/sysv.mk # ├──SYSTEM SUPPORT include libc/nt/nt.mk # │ You can do math @@ -214,7 +213,6 @@ include tool/lambda/lambda.mk include tool/plinko/lib/lib.mk include tool/plinko/plinko.mk include test/tool/plinko/test.mk -include tool/hash/hash.mk include tool/net/net.mk include tool/viz/viz.mk include tool/tool.mk diff --git a/dsp/bmp/bmp.mk b/dsp/bmp/bmp.mk index ee0f394a0..7f9c19158 100644 --- a/dsp/bmp/bmp.mk +++ b/dsp/bmp/bmp.mk @@ -25,8 +25,7 @@ DSP_BMP_A_CHECKS = \ DSP_BMP_A_DIRECTDEPS = \ LIBC_NEXGEN32E \ - LIBC_TINYMATH \ - LIBC_STUBS + LIBC_TINYMATH DSP_BMP_A_DEPS := \ $(call uniq,$(foreach x,$(DSP_BMP_A_DIRECTDEPS),$($(x)))) diff --git a/dsp/core/core.mk b/dsp/core/core.mk index 4386f5970..833e0b495 100644 --- a/dsp/core/core.mk +++ b/dsp/core/core.mk @@ -20,8 +20,7 @@ DSP_CORE_A_DIRECTDEPS = \ LIBC_MEM \ LIBC_NEXGEN32E \ LIBC_STR \ - LIBC_TINYMATH \ - LIBC_STUBS + LIBC_TINYMATH DSP_CORE_A_DEPS := \ $(call uniq,$(foreach x,$(DSP_CORE_A_DIRECTDEPS),$($(x)))) diff --git a/dsp/mpeg/mpeg.mk b/dsp/mpeg/mpeg.mk index 5e154b420..a485cfdce 100644 --- a/dsp/mpeg/mpeg.mk +++ b/dsp/mpeg/mpeg.mk @@ -34,7 +34,6 @@ DSP_MPEG_A_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_TIME \ LIBC_TINYMATH \ diff --git a/dsp/scale/scale.mk b/dsp/scale/scale.mk index d9d5f309e..84f57a008 100644 --- a/dsp/scale/scale.mk +++ b/dsp/scale/scale.mk @@ -31,8 +31,6 @@ DSP_SCALE_A_DIRECTDEPS = \ LIBC_NEXGEN32E \ LIBC_RUNTIME \ LIBC_STR \ - LIBC_STUBS \ - LIBC_STUBS \ LIBC_TIME \ LIBC_TINYMATH \ LIBC_X diff --git a/dsp/tty/tty.mk b/dsp/tty/tty.mk index d6ca0ef9d..928531f58 100644 --- a/dsp/tty/tty.mk +++ b/dsp/tty/tty.mk @@ -35,7 +35,6 @@ DSP_TTY_A_DIRECTDEPS = \ LIBC_NT_KERNEL32 \ LIBC_STR \ LIBC_STDIO \ - LIBC_STUBS \ LIBC_SOCK \ LIBC_SYSV \ LIBC_TINYMATH \ diff --git a/examples/clock.c b/examples/clock.c index ef3574f33..527973b53 100644 --- a/examples/clock.c +++ b/examples/clock.c @@ -7,10 +7,10 @@ │ • http://creativecommons.org/publicdomain/zero/1.0/ │ ╚─────────────────────────────────────────────────────────────────*/ #endif +#include "libc/calls/calls.h" #include "libc/calls/struct/timespec.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" -#include "libc/time/time.h" /** * @fileoverview clock() function demo diff --git a/examples/examples.mk b/examples/examples.mk index 0b38a6a35..9b59ae44c 100644 --- a/examples/examples.mk +++ b/examples/examples.mk @@ -59,7 +59,6 @@ EXAMPLES_DIRECTDEPS = \ LIBC_SOCK \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_SYSV_CALLS \ LIBC_TESTLIB \ @@ -77,10 +76,10 @@ EXAMPLES_DIRECTDEPS = \ THIRD_PARTY_DOUBLECONVERSION \ THIRD_PARTY_GDTOA \ THIRD_PARTY_GETOPT \ + THIRD_PARTY_HIREDIS \ THIRD_PARTY_LIBCXX \ THIRD_PARTY_LINENOISE \ THIRD_PARTY_LUA \ - THIRD_PARTY_HIREDIS \ THIRD_PARTY_MBEDTLS \ THIRD_PARTY_MUSL \ THIRD_PARTY_NSYNC \ diff --git a/examples/package/build.mk b/examples/package/build.mk index acf3bf46b..284195ef7 100644 --- a/examples/package/build.mk +++ b/examples/package/build.mk @@ -43,7 +43,6 @@ EXAMPLES_PACKAGE_DIRECTDEPS = \ EXAMPLES_PACKAGE_LIB \ LIBC_INTRIN \ LIBC_STDIO \ - LIBC_STUBS \ LIBC_TINYMATH # Evaluates the set of transitive package dependencies. diff --git a/examples/package/lib/build.mk b/examples/package/lib/build.mk index 33ee311e8..74a9507cd 100644 --- a/examples/package/lib/build.mk +++ b/examples/package/lib/build.mk @@ -69,10 +69,9 @@ EXAMPLES_PACKAGE_LIB_A_CHECKS = \ # Lists packages whose symbols are or may be directly referenced here. # Note that linking stubs is always a good idea due to synthetic code. EXAMPLES_PACKAGE_LIB_A_DIRECTDEPS = \ - LIBC_STDIO \ LIBC_INTRIN \ LIBC_NEXGEN32E \ - LIBC_STUBS + LIBC_STDIO # Evaluates variable as set of transitive package dependencies. EXAMPLES_PACKAGE_LIB_A_DEPS := \ diff --git a/examples/whois.c b/examples/whois.c index 2d9a1c210..39cf65e91 100644 --- a/examples/whois.c +++ b/examples/whois.c @@ -32,7 +32,6 @@ #include "libc/dns/dns.h" #include "libc/errno.h" #include "libc/log/bsd.h" -#include "libc/mem/fmt.h" #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" #include "libc/sock/struct/pollfd.h" diff --git a/libc/calls/calls.h b/libc/calls/calls.h index 8c772f93a..dbcabc411 100644 --- a/libc/calls/calls.h +++ b/libc/calls/calls.h @@ -40,6 +40,8 @@ #define SIG_DFL ((void (*)(int))0) #define SIG_IGN ((void (*)(int))1) +#define CLOCKS_PER_SEC 1000000L + #define MAP_FAILED ((void *)-1) #define WCOREDUMP(s) (128 & (s)) @@ -174,6 +176,8 @@ int usleep(unsigned); int vfork(void) returnstwice; int wait(int *); int waitpid(int, int *, int); +int64_t clock(void); +int64_t time(int64_t *); 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); @@ -183,10 +187,12 @@ 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); ssize_t write(int, const void *, size_t); +unsigned alarm(unsigned); unsigned getegid(void) nosideeffect; unsigned geteuid(void) nosideeffect; unsigned getgid(void) nosideeffect; unsigned getuid(void) libcesque; +unsigned sleep(unsigned); unsigned umask(unsigned); void sync(void); diff --git a/libc/calls/calls.mk b/libc/calls/calls.mk index dbe7e7633..bba78da4b 100644 --- a/libc/calls/calls.mk +++ b/libc/calls/calls.mk @@ -45,13 +45,12 @@ LIBC_CALLS_A_DIRECTDEPS = \ LIBC_NT_KERNEL32 \ LIBC_NT_NTDLL \ LIBC_NT_PDH \ - LIBC_NT_PSAPI \ LIBC_NT_POWRPROF \ + LIBC_NT_PSAPI \ LIBC_NT_WS2_32 \ LIBC_STR \ - LIBC_STUBS \ - LIBC_SYSV_CALLS \ LIBC_SYSV \ + LIBC_SYSV_CALLS \ THIRD_PARTY_COMPILER_RT LIBC_CALLS_A_DEPS := \ diff --git a/libc/calls/copy.c b/libc/calls/copy.c index 3eff499c4..b8bd92968 100644 --- a/libc/calls/copy.c +++ b/libc/calls/copy.c @@ -18,6 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/macros.internal.h" +#include "libc/runtime/runtime.h" /** * Copies data between file descriptors the old fashioned way. @@ -43,7 +44,7 @@ ssize_t copyfd(int in, int out, size_t n) { if (dw != dr) { // POSIX requires atomic IO up to PIPE_BUF // The minimum permissible PIPE_BUF is 512 - __builtin_trap(); + abort(); } } return i; diff --git a/libc/calls/now.c b/libc/calls/now.c index f56c865a6..237ae58e3 100644 --- a/libc/calls/now.c +++ b/libc/calls/now.c @@ -33,6 +33,8 @@ #include "libc/thread/tls.h" #include "libc/time/time.h" +// TODO(jart): DELETE + static clock_gettime_f *__gettime; static struct Now { diff --git a/libc/calls/oldbench.c b/libc/calls/oldbench.c index 834e190f0..5d38c5dea 100644 --- a/libc/calls/oldbench.c +++ b/libc/calls/oldbench.c @@ -31,6 +31,8 @@ #include "libc/thread/tls.h" #include "libc/time/time.h" +// TODO(jart): DELETE + static struct Now { bool once; uint64_t k0; diff --git a/libc/calls/weirdtypes.h b/libc/calls/weirdtypes.h index aee41190b..dfb7424af 100644 --- a/libc/calls/weirdtypes.h +++ b/libc/calls/weirdtypes.h @@ -6,44 +6,44 @@ * @fileoverview Types we'd prefer hadn't been invented. */ -#define blkcnt_t int64_t -#define cc_t uint8_t -#define clock_t int64_t /* uint64_t on xnu */ -#define dev_t uint64_t /* int32_t on xnu */ -#define fsblkcnt_t uint64_t -#define fsfilcnt_t int64_t /* uint32_t on xnu */ -#define gid_t uint32_t -#define id_t uint32_t /* int32_t on linux/freebsd/etc. */ -#define in_addr_t uint32_t -#define in_addr_t uint32_t -#define in_port_t uint16_t -#define ino_t uint64_t -#define key_t int32_t -#define loff_t int64_t -#define mode_t uint32_t /* uint16_t on xnu */ -#define nfds_t uint64_t -#define off_t int64_t -#define pid_t int32_t -#define register_t int64_t -#define sa_family_t uint16_t /* bsd:uint8_t */ -#define socklen_t uint32_t -#define speed_t uint32_t -#define suseconds_t int64_t /* int32_t on xnu */ -#define useconds_t uint64_t /* uint32_t on xnu */ -#define syscall_arg_t int64_t /* uint64_t on xnu */ -#define tcflag_t uint32_t -#define time_t int64_t -#define timer_t void* -#define uid_t uint32_t -#define rlim_t uint64_t /* int64_t on bsd */ -#define clockid_t int32_t +typedef int64_t blkcnt_t; +typedef uint8_t cc_t; +typedef int64_t clock_t; /* uint64_t on xnu */ +typedef uint64_t dev_t; /* int32_t on xnu */ +typedef uint64_t fsblkcnt_t; +typedef int64_t fsfilcnt_t; /* uint32_t on xnu */ +typedef uint32_t gid_t; +typedef uint32_t id_t; /* int32_t on linux/freebsd/etc. */ +typedef uint32_t in_addr_t; +typedef uint32_t in_addr_t; +typedef uint16_t in_port_t; +typedef uint64_t ino_t; +typedef int32_t key_t; +typedef int64_t loff_t; +typedef uint32_t mode_t; /* uint16_t on xnu */ +typedef uint64_t nfds_t; +typedef int64_t off_t; +typedef int32_t pid_t; +typedef int64_t register_t; +typedef uint16_t sa_family_t; /* bsd:uint8_t */ +typedef uint32_t socklen_t; +typedef uint32_t speed_t; +typedef int64_t suseconds_t; /* int32_t on xnu */ +typedef uint64_t useconds_t; /* uint32_t on xnu */ +typedef int64_t syscall_arg_t; /* uint64_t on xnu */ +typedef uint32_t tcflag_t; +typedef int64_t time_t; +typedef void *timer_t; +typedef uint32_t uid_t; +typedef uint64_t rlim_t; /* int64_t on bsd */ +typedef int32_t clockid_t; #ifdef __x86_64__ -#define blksize_t int64_t /* int32_t on xnu */ -#define nlink_t uint64_t +typedef int64_t blksize_t; /* int32_t on xnu */ +typedef uint64_t nlink_t; #elif defined(__aarch64__) -#define blksize_t int32_t -#define nlink_t uint32_t /* uint16_t on xnu */ +typedef int32_t blksize_t; +typedef uint32_t nlink_t; /* uint16_t on xnu */ #endif #define TIME_T_MAX __INT64_MAX__ diff --git a/libc/dns/dns.mk b/libc/dns/dns.mk index 2adacf41b..1885e322f 100644 --- a/libc/dns/dns.mk +++ b/libc/dns/dns.mk @@ -26,17 +26,16 @@ LIBC_DNS_A_CHECKS = \ LIBC_DNS_A_DIRECTDEPS = \ LIBC_CALLS \ LIBC_FMT \ + LIBC_INTRIN \ LIBC_MEM \ LIBC_NEXGEN32E \ + LIBC_NT_ADVAPI32 \ + LIBC_NT_KERNEL32 \ LIBC_RUNTIME \ LIBC_SOCK \ LIBC_STDIO \ - LIBC_INTRIN \ - LIBC_STUBS \ LIBC_STR \ - LIBC_SYSV \ - LIBC_NT_ADVAPI32 \ - LIBC_NT_KERNEL32 + LIBC_SYSV LIBC_DNS_A_DEPS := \ $(call uniq,$(foreach x,$(LIBC_DNS_A_DIRECTDEPS),$($(x)))) diff --git a/libc/elf/elf.h b/libc/elf/elf.h index 9d42dd1bc..985bcf445 100644 --- a/libc/elf/elf.h +++ b/libc/elf/elf.h @@ -4,30 +4,23 @@ #include "libc/elf/struct/phdr.h" #include "libc/elf/struct/shdr.h" #include "libc/elf/struct/sym.h" -#include "libc/runtime/ezmap.internal.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ #ifdef COSMO - /*───────────────────────────────────────────────────────────────────────────│─╗ -│ cosmopolitan § executable & linkable format ─╬─│┼ +│ cosmopolitan § executable linkable format ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -char *GetElfStringTable(const Elf64_Ehdr *, size_t); -char *GetElfStrs(const Elf64_Ehdr *, size_t, size_t *); -Elf64_Sym *GetElfSymbolTable(const Elf64_Ehdr *, size_t, Elf64_Xword *); +char *GetElfStringTable(const Elf64_Ehdr *, size_t, const char *); +Elf64_Sym *GetElfSymbolTable(const Elf64_Ehdr *, size_t, int, Elf64_Xword *); bool IsElf64Binary(const Elf64_Ehdr *, size_t); bool IsElfSymbolContent(const Elf64_Sym *); -Elf64_Phdr *GetElfSegmentHeaderAddress(const Elf64_Ehdr *, size_t, Elf64_Half); +Elf64_Phdr *GetElfProgramHeaderAddress(const Elf64_Ehdr *, size_t, Elf64_Half); Elf64_Shdr *GetElfSectionHeaderAddress(const Elf64_Ehdr *, size_t, Elf64_Half); void *GetElfSectionAddress(const Elf64_Ehdr *, size_t, const Elf64_Shdr *); char *GetElfSectionNameStringTable(const Elf64_Ehdr *, size_t); -void GetElfVirtualAddressRange(const Elf64_Ehdr *, size_t, intptr_t *, - intptr_t *); char *GetElfString(const Elf64_Ehdr *, size_t, const char *, Elf64_Word); const char *GetElfSectionName(const Elf64_Ehdr *, size_t, Elf64_Shdr *); -Elf64_Sym *GetElfDynSymbolTable(const Elf64_Ehdr *, size_t, Elf64_Xword *); -char *GetElfDynStringTable(const Elf64_Ehdr *, size_t); #endif /* COSMO */ COSMOPOLITAN_C_END_ diff --git a/libc/elf/elf.mk b/libc/elf/elf.mk index f56eb18d0..2d4190461 100644 --- a/libc/elf/elf.mk +++ b/libc/elf/elf.mk @@ -27,7 +27,6 @@ LIBC_ELF_A_DIRECTDEPS = \ LIBC_INTRIN \ LIBC_NEXGEN32E \ LIBC_STR \ - LIBC_STUBS LIBC_ELF_A_DEPS := \ $(call uniq,$(foreach x,$(LIBC_ELF_A_DIRECTDEPS),$($(x)))) diff --git a/libc/elf/getelfdynstringtable.c b/libc/elf/getelfdynstringtable.c deleted file mode 100644 index 7fd633542..000000000 --- a/libc/elf/getelfdynstringtable.c +++ /dev/null @@ -1,36 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/elf/def.h" -#include "libc/elf/elf.h" -#include "libc/str/str.h" - -char *GetElfDynStringTable(const Elf64_Ehdr *elf, size_t mapsize) { - int i; - char *name; - Elf64_Shdr *shdr; - for (i = 0; i < elf->e_shnum; ++i) { - if ((shdr = GetElfSectionHeaderAddress(elf, mapsize, i)) && - shdr->sh_type == SHT_STRTAB && - (name = GetElfSectionName(elf, mapsize, shdr)) && - !strcmp(name, ".dynstr")) { - return GetElfSectionAddress(elf, mapsize, shdr); - } - } - return 0; -} diff --git a/libc/elf/getelfdynsymboltable.c b/libc/elf/getelfdynsymboltable.c deleted file mode 100644 index 0b23e59f0..000000000 --- a/libc/elf/getelfdynsymboltable.c +++ /dev/null @@ -1,35 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/elf/def.h" -#include "libc/elf/elf.h" - -Elf64_Sym *GetElfDynSymbolTable(const Elf64_Ehdr *elf, size_t mapsize, - Elf64_Xword *out_count) { - int i; - Elf64_Shdr *shdr; - for (i = elf->e_shnum; i-- > 0;) { - if ((shdr = GetElfSectionHeaderAddress(elf, mapsize, i)) && // - shdr->sh_type == SHT_DYNSYM && // - shdr->sh_entsize == sizeof(Elf64_Sym)) { - if (out_count) *out_count = shdr->sh_size / sizeof(Elf64_Sym); - return GetElfSectionAddress(elf, mapsize, shdr); - } - } - return 0; -} diff --git a/libc/elf/getelfsegmentheaderaddress.c b/libc/elf/getelfprogramheaderaddress.c similarity index 74% rename from libc/elf/getelfsegmentheaderaddress.c rename to libc/elf/getelfprogramheaderaddress.c index 918cf3779..b31a2ecf5 100644 --- a/libc/elf/getelfsegmentheaderaddress.c +++ b/libc/elf/getelfprogramheaderaddress.c @@ -17,16 +17,25 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/elf/elf.h" -#include "libc/stdckdint.h" +#include "libc/elf/scalar.h" +#include "libc/elf/struct/phdr.h" -Elf64_Phdr *GetElfSegmentHeaderAddress(const Elf64_Ehdr *elf, // +/** + * Returns program header at `elf.phdr[i]`. + * + * @param elf points to the start of the executable image + * @param mapsize is the number of bytes past `elf` we can access + * @param i is the program header index, starting at zero + * @return program header pointer, or null on error + */ +Elf64_Phdr *GetElfProgramHeaderAddress(const Elf64_Ehdr *elf, // size_t mapsize, // Elf64_Half i) { // - uint64_t last, addr; + uint64_t off; if (i >= elf->e_phnum) return 0; - if (ckd_add(&addr, (uintptr_t)elf, elf->e_phoff)) return 0; - if (ckd_add(&addr, addr, (unsigned)i * elf->e_phentsize)) return 0; - if (ckd_add(&last, addr, elf->e_phentsize)) return 0; - if (last > (uintptr_t)elf + mapsize) return 0; - return (Elf64_Phdr *)addr; + if (elf->e_phoff <= 0) return 0; + if (elf->e_phoff >= mapsize) return 0; + if (elf->e_phentsize < sizeof(Elf64_Phdr)) return 0; + if ((off = elf->e_phoff + (unsigned)i * elf->e_phentsize) > mapsize) return 0; + return (Elf64_Phdr *)((char *)elf + off); } diff --git a/libc/elf/getelfsectionaddress.c b/libc/elf/getelfsectionaddress.c index 3171d3a46..9cce7b293 100644 --- a/libc/elf/getelfsectionaddress.c +++ b/libc/elf/getelfsectionaddress.c @@ -19,14 +19,23 @@ #include "libc/elf/elf.h" #include "libc/stdckdint.h" -// note: should not be used on bss section +/** + * Returns pointer to elf section file content. + * + * This function shouldn't be used on the bss section. + * + * @param elf points to the start of the executable image + * @param mapsize is the number of bytes past `elf` we can access + * @param shdr is from GetElfSectionHeaderAddress() and null-propagating + * @return pointer to content bytes, or null on error + */ void *GetElfSectionAddress(const Elf64_Ehdr *elf, // validated size_t mapsize, // validated const Elf64_Shdr *shdr) { // foreign - uint64_t addr, last; + uint64_t last; if (!shdr) return 0; - if (ckd_add(&addr, (uintptr_t)elf, shdr->sh_offset)) return 0; - if (ckd_add(&last, addr, shdr->sh_size)) return 0; - if (last > (uintptr_t)elf + mapsize) return 0; - return (void *)addr; + if (shdr->sh_size <= 0) return 0; + if (ckd_add(&last, shdr->sh_offset, shdr->sh_size)) return 0; + if (last > mapsize) return 0; + return (char *)elf + shdr->sh_offset; } diff --git a/libc/elf/getelfsectionheaderaddress.c b/libc/elf/getelfsectionheaderaddress.c index 139a9abb9..2d54fc600 100644 --- a/libc/elf/getelfsectionheaderaddress.c +++ b/libc/elf/getelfsectionheaderaddress.c @@ -17,16 +17,24 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/elf/elf.h" -#include "libc/stdckdint.h" +#include "libc/elf/struct/shdr.h" +/** + * Returns section header object at `elf.section[i]`. + * + * @param elf points to the start of the executable image + * @param mapsize is the number of bytes past `elf` we can access + * @param i is the section header index, starting at zero + * @return section header pointer, or null on error + */ Elf64_Shdr *GetElfSectionHeaderAddress(const Elf64_Ehdr *elf, // size_t mapsize, // Elf64_Half i) { // - uint64_t addr, last; + uint64_t off; if (i >= elf->e_shnum) return 0; - if (ckd_add(&addr, (uintptr_t)elf, elf->e_shoff)) return 0; - if (ckd_add(&addr, addr, (unsigned)i * elf->e_shentsize)) return 0; - if (ckd_add(&last, addr, elf->e_shentsize)) return 0; - if (last > (uintptr_t)elf + mapsize) return 0; - return (Elf64_Shdr *)addr; + if (elf->e_shoff <= 0) return 0; + if (elf->e_shoff >= mapsize) return 0; + if (elf->e_shentsize < sizeof(Elf64_Shdr)) return 0; + if ((off = elf->e_shoff + (unsigned)i * elf->e_shentsize) > mapsize) return 0; + return (Elf64_Shdr *)((char *)elf + off); } diff --git a/libc/elf/getelfsectionnamestringtable.c b/libc/elf/getelfsectionnamestringtable.c index ab7671384..3897d9a94 100644 --- a/libc/elf/getelfsectionnamestringtable.c +++ b/libc/elf/getelfsectionnamestringtable.c @@ -17,9 +17,16 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/elf/elf.h" +#include "libc/elf/struct/shdr.h" +/** + * Returns section name string table. + * + * @param elf points to the start of the executable image + * @param mapsize is the number of bytes past `elf` we can access + * @return double-nul terminated string list, or null on error + */ char *GetElfSectionNameStringTable(const Elf64_Ehdr *elf, size_t mapsize) { - if (!elf->e_shoff || !elf->e_shentsize) return 0; return GetElfSectionAddress( elf, mapsize, GetElfSectionHeaderAddress(elf, mapsize, elf->e_shstrndx)); } diff --git a/libc/elf/getelfstring.c b/libc/elf/getelfstring.c index e8460ecf3..a2e5c6d79 100644 --- a/libc/elf/getelfstring.c +++ b/libc/elf/getelfstring.c @@ -17,17 +17,28 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/elf/elf.h" -#include "libc/stdckdint.h" +#include "libc/elf/scalar.h" +#include "libc/elf/struct/ehdr.h" #include "libc/str/str.h" +/** + * Returns `strtab + i` from elf string table. + * + * @param elf points to the start of the executable image + * @param mapsize is the number of bytes past `elf` we can access + * @param strtab is double-nul string list from GetElfStringTable() + * @param i is byte index into strtab where needed string starts + * @return pointer to nul terminated string, or null on error + */ char *GetElfString(const Elf64_Ehdr *elf, // validated size_t mapsize, // validated const char *strtab, // validated - Elf64_Word rva) { // foreign - uintptr_t addr; - if (!strtab) return 0; - if (ckd_add(&addr, (uintptr_t)strtab, rva)) return 0; - if (addr >= (uintptr_t)elf + mapsize) return 0; - if (!memchr((char *)addr, 0, (uintptr_t)elf + mapsize - addr)) return 0; - return (char *)addr; + Elf64_Word i) { // foreign + const char *e; + e = (const char *)elf; + if (strtab < e) return 0; + if (strtab >= e + mapsize) return 0; + if (strtab + i >= e + mapsize) return 0; + if (!memchr(strtab + i, 0, (e + mapsize) - (strtab + i))) return 0; + return (char *)strtab + i; } diff --git a/libc/elf/getelfstringtable.c b/libc/elf/getelfstringtable.c index 30c6f7639..cc6d38292 100644 --- a/libc/elf/getelfstringtable.c +++ b/libc/elf/getelfstringtable.c @@ -18,9 +18,21 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/elf/def.h" #include "libc/elf/elf.h" +#include "libc/elf/struct/ehdr.h" +#include "libc/elf/struct/shdr.h" #include "libc/str/str.h" -char *GetElfStringTable(const Elf64_Ehdr *elf, size_t mapsize) { +/** + * Returns pointer to elf string table. + * + * @param elf points to the start of the executable image + * @param mapsize is the number of bytes past `elf` we can access + * @param section_name is usually `".strtab"`, `".dynstr"`, or null + * @return pointer to double-nul terminated string list or null on error + */ +char *GetElfStringTable(const Elf64_Ehdr *elf, // + size_t mapsize, // + const char *section_name) { int i; char *name; Elf64_Shdr *shdr; @@ -28,9 +40,9 @@ char *GetElfStringTable(const Elf64_Ehdr *elf, size_t mapsize) { if ((shdr = GetElfSectionHeaderAddress(elf, mapsize, i)) && shdr->sh_type == SHT_STRTAB && (name = GetElfSectionName(elf, mapsize, shdr)) && - !strcmp(name, ".strtab")) { + (!section_name || !strcmp(name, section_name))) { return GetElfSectionAddress(elf, mapsize, shdr); } } - return NULL; + return 0; } diff --git a/libc/elf/getelfstrs.c b/libc/elf/getelfstrs.c deleted file mode 100644 index 500e96802..000000000 --- a/libc/elf/getelfstrs.c +++ /dev/null @@ -1,37 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/elf/def.h" -#include "libc/elf/elf.h" -#include "libc/str/str.h" - -char *GetElfStrs(const Elf64_Ehdr *elf, size_t mapsize, size_t *out_size) { - int i; - char *name; - Elf64_Shdr *shdr; - for (i = 0; i < elf->e_shnum; ++i) { - if ((shdr = GetElfSectionHeaderAddress(elf, mapsize, i)) && - shdr->sh_type == SHT_STRTAB && - (name = GetElfSectionName(elf, mapsize, shdr)) && - !strcmp(name, ".strtab")) { - if (out_size) *out_size = shdr->sh_size; - return GetElfSectionAddress(elf, mapsize, shdr); - } - } - return 0; -} diff --git a/libc/elf/getelfsymboltable.c b/libc/elf/getelfsymboltable.c index 393b19988..faa74cf1f 100644 --- a/libc/elf/getelfsymboltable.c +++ b/libc/elf/getelfsymboltable.c @@ -18,20 +18,32 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/elf/def.h" #include "libc/elf/elf.h" +#include "libc/elf/scalar.h" +#include "libc/elf/struct/ehdr.h" +#include "libc/elf/struct/sym.h" -Elf64_Sym *GetElfSymbolTable(const Elf64_Ehdr *elf, size_t mapsize, +/** + * Returns pointer to elf symbol table. + * + * @param elf points to the start of the executable image + * @param mapsize is the number of bytes past `elf` we can access + * @param section_type is usually `SHT_SYMTAB` or `SHT_DYNSYM` + * @param out_count optionally receives number of elements in res + * @return pointer to symbol array, or null on error + */ +Elf64_Sym *GetElfSymbolTable(const Elf64_Ehdr *elf, // + size_t mapsize, // + int section_type, // Elf64_Xword *out_count) { int i; Elf64_Shdr *shdr; - if (elf->e_shentsize) { - for (i = elf->e_shnum; i > 0; --i) { - shdr = GetElfSectionHeaderAddress(elf, mapsize, i - 1); - if (shdr->sh_type == SHT_SYMTAB) { - if (shdr->sh_entsize != sizeof(Elf64_Sym)) __builtin_trap(); - if (out_count) *out_count = shdr->sh_size / sizeof(Elf64_Sym); - return GetElfSectionAddress(elf, mapsize, shdr); - } + for (i = elf->e_shnum; i > 0; --i) { + if ((shdr = GetElfSectionHeaderAddress(elf, mapsize, i - 1)) && // + shdr->sh_entsize == sizeof(Elf64_Sym) && // + shdr->sh_type == section_type) { + if (out_count) *out_count = shdr->sh_size / sizeof(Elf64_Sym); + return GetElfSectionAddress(elf, mapsize, shdr); } } - return NULL; + return 0; } diff --git a/libc/elf/getelfvirtualaddressrange.c b/libc/elf/getelfvirtualaddressrange.c deleted file mode 100644 index f7fbf5373..000000000 --- a/libc/elf/getelfvirtualaddressrange.c +++ /dev/null @@ -1,39 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/elf/elf.h" -#include "libc/limits.h" - -void GetElfVirtualAddressRange(const Elf64_Ehdr *elf, size_t elfsize, - intptr_t *out_start, intptr_t *out_end) { - unsigned i; - Elf64_Phdr *phdr; - intptr_t start, end, pstart, pend; - start = INTPTR_MAX; - end = 0; - for (i = 0; i < elf->e_phnum; ++i) { - phdr = GetElfSegmentHeaderAddress(elf, elfsize, i); - if (phdr->p_type != PT_LOAD) continue; - pstart = phdr->p_vaddr; - pend = phdr->p_vaddr + phdr->p_memsz; - if (pstart < start) start = pstart; - if (pend > end) end = pend; - } - if (out_start) *out_start = start; - if (out_end) *out_end = end; -} diff --git a/libc/elf/iself64binary.c b/libc/elf/iself64binary.c index 8a7b4b86a..1c77c951d 100644 --- a/libc/elf/iself64binary.c +++ b/libc/elf/iself64binary.c @@ -16,12 +16,20 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/elf/def.h" #include "libc/elf/elf.h" -#include "libc/str/str.h" +#include "libc/elf/struct/ehdr.h" +#include "libc/intrin/bits.h" +/** + * Returns true if `elf` is a 64-bit elf executable. + * + * @param elf points to the start of the executable image + * @param mapsize is the number of bytes past `elf` we can access + * @return true if elf header looks legit + */ bool IsElf64Binary(const Elf64_Ehdr *elf, size_t mapsize) { if (mapsize < sizeof(Elf64_Ehdr)) return false; - if (memcmp(elf->e_ident, ELFMAG, 4)) return false; - return (elf->e_ident[EI_CLASS] == ELFCLASSNONE || - elf->e_ident[EI_CLASS] == ELFCLASS64); + if (READ32LE(elf->e_ident) != READ32LE(ELFMAG)) return false; + return elf->e_ident[EI_CLASS] != ELFCLASS32; } diff --git a/libc/elf/scalar.h b/libc/elf/scalar.h index 93919c8b8..39c452fe1 100644 --- a/libc/elf/scalar.h +++ b/libc/elf/scalar.h @@ -1,6 +1,5 @@ #ifndef COSMOPOLITAN_LIBC_ELF_SCALAR_H_ #define COSMOPOLITAN_LIBC_ELF_SCALAR_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) #define Elf64_Addr uint64_t #define Elf64_Half uint16_t @@ -13,5 +12,4 @@ #define Elf64_Xword uint64_t #define Elf_Symndx uint32_t -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_ELF_SCALAR_H_ */ diff --git a/libc/fmt/fmt.h b/libc/fmt/fmt.h index d8c9e84d9..f8cc2afb2 100644 --- a/libc/fmt/fmt.h +++ b/libc/fmt/fmt.h @@ -22,14 +22,17 @@ int vsprintf(char *, const char *, va_list) dontthrow nocallback; int sscanf(const char *, const char *, ...) scanfesque(2); int vsscanf(const char *, const char *, va_list); -int vcscanf(int (*)(void *), int (*)(int, void *), void *, const char *, - va_list); -int __fmt(void *, void *, const char *, va_list) _Hide; char *itoa(int, char *, int) compatfn; char *fcvt(double, int, int *, int *); char *ecvt(double, int, int *, int *); char *gcvt(double, int, char *); +#ifdef COSMO +int __vcscanf(int (*)(void *), int (*)(int, void *), void *, const char *, + va_list); +int __fmt(void *, void *, const char *, va_list) _Hide; +#endif + COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_FMT_FMT_H_ */ diff --git a/libc/fmt/fmt.mk b/libc/fmt/fmt.mk index 097586bab..2c787c60d 100644 --- a/libc/fmt/fmt.mk +++ b/libc/fmt/fmt.mk @@ -34,11 +34,10 @@ LIBC_FMT_A_CHECKS = \ $(LIBC_FMT_A_HDRS:%=o/$(MODE)/%.ok) LIBC_FMT_A_DIRECTDEPS = \ + LIBC_INTRIN \ LIBC_NEXGEN32E \ LIBC_NT_KERNEL32 \ LIBC_STR \ - LIBC_INTRIN \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_TINYMATH \ THIRD_PARTY_COMPILER_RT diff --git a/libc/intrin/__cxa_pure_virtual.c b/libc/intrin/__cxa_pure_virtual.c index c084bbbaa..a6a256f22 100644 --- a/libc/intrin/__cxa_pure_virtual.c +++ b/libc/intrin/__cxa_pure_virtual.c @@ -17,11 +17,12 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/kprintf.h" +#include "libc/runtime/runtime.h" void __cxa_pure_virtual(void) { #ifndef NDEBUG kprintf("__cxa_pure_virtual() called\n" "Did you call a virtual method from a destructor?\n"); #endif - __builtin_trap(); + abort(); } diff --git a/libc/stubs/retpoline.S b/libc/intrin/abort.c similarity index 82% rename from libc/stubs/retpoline.S rename to libc/intrin/abort.c index 66815678d..76575c4b8 100644 --- a/libc/stubs/retpoline.S +++ b/libc/intrin/abort.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 tw=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,9 +16,8 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.internal.h" -// See -mfunction-return=thunk -__x86_return_thunk: - ret - .endfn __x86_return_thunk,weak +// stub version of abort() for low-dependency apps +__attribute__((__noreturn__, __weak__)) void abort(void) { + __builtin_trap(); +} diff --git a/libc/intrin/asan.c b/libc/intrin/asan.c index 113102545..e38e5a27b 100644 --- a/libc/intrin/asan.c +++ b/libc/intrin/asan.c @@ -176,7 +176,7 @@ static bool __asan_once(void) { #define __asan_unreachable() \ do { \ kprintf("%s:%d: __asan_unreachable()\n", __FILE__, __LINE__); \ - for (;;) __builtin_trap(); \ + __builtin_trap(); \ } while (0) static int __asan_bsf(uint64_t x) { diff --git a/libc/intrin/ashlti3.c b/libc/intrin/ashlti3.c index dfef2dcd7..4796d8132 100644 --- a/libc/intrin/ashlti3.c +++ b/libc/intrin/ashlti3.c @@ -15,8 +15,6 @@ #include "third_party/compiler_rt/int_lib.h" -#ifdef CRT_HAS_128BIT - /* Returns: a << b */ /* Precondition: 0 <= b < bits_in_tword */ @@ -42,5 +40,3 @@ __ashlti3(ti_int a, si_int b) } return result.all; } - -#endif /* CRT_HAS_128BIT */ diff --git a/libc/intrin/assertfail.greg.c b/libc/intrin/assertfail.greg.c index 788f0df17..b84640c34 100644 --- a/libc/intrin/assertfail.greg.c +++ b/libc/intrin/assertfail.greg.c @@ -20,6 +20,7 @@ #include "libc/atomic.h" #include "libc/intrin/atomic.h" #include "libc/intrin/kprintf.h" +#include "libc/runtime/runtime.h" privileged void __assert_fail(const char *expr, const char *file, int line) { static atomic_bool once; diff --git a/libc/intrin/divmodti4.c b/libc/intrin/divmodti4.c index e92fc7cdc..eb572e555 100644 --- a/libc/intrin/divmodti4.c +++ b/libc/intrin/divmodti4.c @@ -29,13 +29,13 @@ COMPILER_RT_ABI ti_int __divmodti4(ti_int a, ti_int b, tu_int *opt_out_rem) { } sa = a >> k; // sa = a < 0 ? -1 : 0 sb = b >> k; // sb = b < 0 ? -1 : 0 - x = (a ^ sa) - sa; // negate if sa == -1 - y = (b ^ sb) - sb; // negate if sb == -1 + x = (tu_int)(a ^ sa) - sa; // negate if sa == -1 + y = (tu_int)(b ^ sb) - sb; // negate if sb == -1 sq = sa ^ sb; // sign of quotient sr = sa; // sign of remainder q = __udivmodti4(x, y, &r); // unsigned divide - q = (q ^ sq) - sq; // fix quotient sign - r = (r ^ sr) - sr; // fix remainder sign + q = (tu_int)(q ^ sq) - sq; // fix quotient sign + r = (tu_int)(r ^ sr) - sr; // fix remainder sign if (opt_out_rem) *opt_out_rem = r; return q; } diff --git a/libc/stubs/gcov.S b/libc/intrin/gcov.S similarity index 100% rename from libc/stubs/gcov.S rename to libc/intrin/gcov.S diff --git a/libc/intrin/intrin.mk b/libc/intrin/intrin.mk index 207121538..350a2b46d 100644 --- a/libc/intrin/intrin.mk +++ b/libc/intrin/intrin.mk @@ -28,12 +28,11 @@ LIBC_INTRIN_A_CHECKS = \ $(LIBC_INTRIN_A_HDRS:%=o/$(MODE)/%.ok) LIBC_INTRIN_A_DIRECTDEPS = \ - LIBC_STUBS \ - LIBC_SYSV \ - LIBC_SYSV_CALLS \ LIBC_NEXGEN32E \ LIBC_NT_KERNEL32 \ - LIBC_NT_WS2_32 + LIBC_NT_WS2_32 \ + LIBC_SYSV \ + LIBC_SYSV_CALLS LIBC_INTRIN_A_DEPS := \ $(call uniq,$(foreach x,$(LIBC_INTRIN_A_DIRECTDEPS),$($(x)))) @@ -218,8 +217,12 @@ o/$(MODE)/libc/intrin/aarch64/%.o: libc/intrin/aarch64/%.S @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $< o/$(MODE)/libc/intrin/fenv.o: libc/intrin/fenv.S @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $< +o/$(MODE)/libc/intrin/gcov.o: libc/intrin/gcov.S + @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $< o/$(MODE)/libc/intrin/futex.o: libc/intrin/futex.S @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $< +o/$(MODE)/libc/intrin/typeinfo.o: libc/intrin/typeinfo.S + @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $< o/$(MODE)/libc/intrin/kclocknames.o: libc/intrin/kclocknames.S @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $< o/$(MODE)/libc/intrin/kdos2errno.o: libc/intrin/kdos2errno.S diff --git a/libc/intrin/mulodi4.c b/libc/intrin/mulodi4.c index c2a49342e..067ac4510 100644 --- a/libc/intrin/mulodi4.c +++ b/libc/intrin/mulodi4.c @@ -26,7 +26,7 @@ __mulodi4(di_int a, di_int b, int* overflow) const di_int MIN = (du_int)1 << (N-1); const di_int MAX = ~MIN; *overflow = 0; - di_int result = (du_int)a * (du_int)b; + di_int result = (du_int)a * b; if (a == MIN) { if (b != 0 && b != 1) diff --git a/libc/intrin/mulosi4.c b/libc/intrin/mulosi4.c index 5261a6f90..2f6f73305 100644 --- a/libc/intrin/mulosi4.c +++ b/libc/intrin/mulosi4.c @@ -26,7 +26,7 @@ __mulosi4(si_int a, si_int b, int* overflow) const si_int MIN = (su_int)1 << (N-1); const si_int MAX = ~MIN; *overflow = 0; - si_int result = (su_int)a * (su_int)b; + si_int result = (su_int)a * b; if (a == MIN) { if (b != 0 && b != 1) diff --git a/libc/intrin/muloti4.c b/libc/intrin/muloti4.c index bc799d654..a104606c6 100644 --- a/libc/intrin/muloti4.c +++ b/libc/intrin/muloti4.c @@ -28,7 +28,7 @@ __muloti4(ti_int a, ti_int b, int* overflow) const ti_int MIN = (tu_int)1 << (N-1); const ti_int MAX = ~MIN; *overflow = 0; - ti_int result = (tu_int)a * (tu_int)b; + ti_int result = (tu_int)a * b; if (a == MIN) { if (b != 0 && b != 1) diff --git a/libc/intrin/onarithmeticoverflow.c b/libc/intrin/onarithmeticoverflow.c index 843bd42b4..8fa573833 100644 --- a/libc/intrin/onarithmeticoverflow.c +++ b/libc/intrin/onarithmeticoverflow.c @@ -17,6 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/kprintf.h" +#include "libc/runtime/runtime.h" /** * Arithmetic overflow handler. @@ -31,5 +32,5 @@ */ __attribute__((__weak__)) void __on_arithmetic_overflow(void) { kprintf("error: -ftrapv caught arithmetic overflow\n"); - __builtin_trap(); + abort(); } diff --git a/libc/runtime/stackchkfail.c b/libc/intrin/stackchkfail.c similarity index 92% rename from libc/runtime/stackchkfail.c rename to libc/intrin/stackchkfail.c index b5152e6ad..300c24830 100644 --- a/libc/runtime/stackchkfail.c +++ b/libc/intrin/stackchkfail.c @@ -17,8 +17,9 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/kprintf.h" +#include "libc/runtime/runtime.h" -void __stack_chk_fail(void) { - kprintf("stack smashed\n"); +__attribute__((__weak__)) void __stack_chk_fail(void) { + kprintf("%s: stack smashed\n", program_invocation_name); __builtin_trap(); } diff --git a/libc/runtime/stackchkfaillocal.c b/libc/intrin/stackchkfaillocal.c similarity index 96% rename from libc/runtime/stackchkfaillocal.c rename to libc/intrin/stackchkfaillocal.c index bcc6f276f..7f464c523 100644 --- a/libc/runtime/stackchkfaillocal.c +++ b/libc/intrin/stackchkfaillocal.c @@ -18,6 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/runtime/internal.h" -void __stack_chk_fail_local(void) { +__attribute__((__weak__)) void __stack_chk_fail_local(void) { __stack_chk_fail(); } diff --git a/libc/stubs/stackchkguard.S b/libc/intrin/stackchkguard.S similarity index 100% rename from libc/stubs/stackchkguard.S rename to libc/intrin/stackchkguard.S diff --git a/libc/stubs/typeinfo.S b/libc/intrin/typeinfo.S similarity index 100% rename from libc/stubs/typeinfo.S rename to libc/intrin/typeinfo.S diff --git a/libc/intrin/ubsan.c b/libc/intrin/ubsan.c index 6057ab11f..35d8c101c 100644 --- a/libc/intrin/ubsan.c +++ b/libc/intrin/ubsan.c @@ -199,7 +199,7 @@ static uintptr_t __ubsan_extend(struct UbsanTypeDescriptor *t, uintptr_t x) { } static wontreturn void __ubsan_unreachable(void) { - for (;;) __builtin_trap(); + for (;;) abort(); } static void __ubsan_exit(void) { diff --git a/libc/isystem/assert.h b/libc/isystem/assert.h index 909eaf1a3..399d0c04d 100644 --- a/libc/isystem/assert.h +++ b/libc/isystem/assert.h @@ -1,4 +1,4 @@ -#ifndef LIBC_ISYSTEM_ASSERT_H_ -#define LIBC_ISYSTEM_ASSERT_H_ +#ifndef _ASSERT_H +#define _ASSERT_H #include "libc/assert.h" -#endif +#endif /* _ASSERT_H */ diff --git a/libc/isystem/byteswap.h b/libc/isystem/byteswap.h index 37e93d38e..072d2759b 100644 --- a/libc/isystem/byteswap.h +++ b/libc/isystem/byteswap.h @@ -1,4 +1,4 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_BYTESWAP_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_BYTESWAP_H_ +#ifndef _BYTESWAP_H +#define _BYTESWAP_H #include "libc/intrin/bswap.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_BYTESWAP_H_ */ +#endif /* _BYTESWAP_H */ diff --git a/libc/isystem/complex.h b/libc/isystem/complex.h index e42e8e4a2..bd8c4569b 100644 --- a/libc/isystem/complex.h +++ b/libc/isystem/complex.h @@ -1,6 +1,6 @@ -#ifndef LIBC_ISYSTEM_COMPLEX_H_ -#define LIBC_ISYSTEM_COMPLEX_H_ +#ifndef _COMPLEX_H +#define _COMPLEX_H #include "libc/complex.h" #include "libc/imag.internal.h" #include "libc/math.h" -#endif +#endif /* _COMPLEX_H */ diff --git a/libc/isystem/cosmo.h b/libc/isystem/cosmo.h index 4e7e5d580..548253148 100644 --- a/libc/isystem/cosmo.h +++ b/libc/isystem/cosmo.h @@ -30,6 +30,7 @@ #include "libc/calls/struct/timespec.h" #include "libc/calls/struct/timeval.h" #include "libc/dce.h" +#include "libc/elf/elf.h" #include "libc/fmt/itoa.h" #include "libc/fmt/leb128.h" #include "libc/intrin/bsf.h" diff --git a/libc/isystem/cpio.h b/libc/isystem/cpio.h index ded259fcc..bfe7894df 100644 --- a/libc/isystem/cpio.h +++ b/libc/isystem/cpio.h @@ -1,4 +1,4 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_CPIO_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_CPIO_H_ +#ifndef _CPIO_H +#define _CPIO_H #include "libc/sysv/consts/c.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_CPIO_H_ */ +#endif /* _CPIO_H */ diff --git a/libc/isystem/cpuid.h b/libc/isystem/cpuid.h index 89ac3c77c..9a631edac 100644 --- a/libc/isystem/cpuid.h +++ b/libc/isystem/cpuid.h @@ -1,4 +1,4 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_CPUID_INTERNAL_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_CPUID_INTERNAL_H_ +#ifndef _CPUID_H +#define _CPUID_H #include "third_party/intel/cpuid.internal.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_CPUID_INTERNAL_H_ */ +#endif /* _CPUID_H */ diff --git a/libc/isystem/crypt.h b/libc/isystem/crypt.h index 64b206eb6..0c3019147 100644 --- a/libc/isystem/crypt.h +++ b/libc/isystem/crypt.h @@ -1,4 +1,4 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_CRYPT_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_CRYPT_H_ +#ifndef _CRYPT_H +#define _CRYPT_H #include "third_party/musl/crypt.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_CRYPT_H_ */ +#endif /* _CRYPT_H */ diff --git a/libc/isystem/ctype.h b/libc/isystem/ctype.h index 143cc5e56..c375b5004 100644 --- a/libc/isystem/ctype.h +++ b/libc/isystem/ctype.h @@ -1,4 +1,4 @@ -#ifndef LIBC_ISYSTEM_CTYPE_H_ -#define LIBC_ISYSTEM_CTYPE_H_ +#ifndef _CTYPE_H +#define _CTYPE_H #include "libc/str/str.h" -#endif +#endif /* _CTYPE_H */ diff --git a/libc/isystem/dirent.h b/libc/isystem/dirent.h index fa9b3e28c..27cc36c31 100644 --- a/libc/isystem/dirent.h +++ b/libc/isystem/dirent.h @@ -1,7 +1,7 @@ -#ifndef LIBC_ISYSTEM_DIRENT_H_ -#define LIBC_ISYSTEM_DIRENT_H_ +#ifndef _DIRENT_H +#define _DIRENT_H #include "libc/calls/calls.h" #include "libc/calls/struct/dirent.h" #include "libc/calls/weirdtypes.h" #include "libc/sysv/consts/dt.h" -#endif +#endif /* _DIRENT_H */ diff --git a/libc/isystem/dlfcn.h b/libc/isystem/dlfcn.h index 3d124aa22..82c1c2faf 100644 --- a/libc/isystem/dlfcn.h +++ b/libc/isystem/dlfcn.h @@ -1,4 +1,4 @@ -#ifndef LIBC_ISYSTEM_SYS_DLFCN_H_ -#define LIBC_ISYSTEM_SYS_DLFCN_H_ +#ifndef _DLFCN_H +#define _DLFCN_H #include "libc/runtime/dlfcn.h" -#endif +#endif /* _DLFCN_H */ diff --git a/libc/isystem/dog.py b/libc/isystem/dog.py deleted file mode 100644 index c9a4ca10e..000000000 --- a/libc/isystem/dog.py +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_DOG_PY_ -#define COSMOPOLITAN_LIBC_ISYSTEM_DOG_PY_ -#include "third_party/intel/dog.py" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_DOG_PY_ */ diff --git a/libc/isystem/elf.h b/libc/isystem/elf.h index ee55a421c..f902519a0 100644 --- a/libc/isystem/elf.h +++ b/libc/isystem/elf.h @@ -1,4 +1,22 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_ELF_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_ELF_H_ -#include "libc/elf/elf.h" -#endif +#ifndef _ELF_H +#define _ELF_H +#include "libc/elf/def.h" +#include "libc/elf/scalar.h" +#include "libc/elf/struct/auxv.h" +#include "libc/elf/struct/chdr.h" +#include "libc/elf/struct/dyn.h" +#include "libc/elf/struct/ehdr.h" +#include "libc/elf/struct/lib.h" +#include "libc/elf/struct/move.h" +#include "libc/elf/struct/nhdr.h" +#include "libc/elf/struct/phdr.h" +#include "libc/elf/struct/rel.h" +#include "libc/elf/struct/rela.h" +#include "libc/elf/struct/shdr.h" +#include "libc/elf/struct/sym.h" +#include "libc/elf/struct/syminfo.h" +#include "libc/elf/struct/verdaux.h" +#include "libc/elf/struct/verdef.h" +#include "libc/elf/struct/vernaux.h" +#include "libc/elf/struct/verneed.h" +#endif /* _ELF_H */ diff --git a/libc/isystem/endian.h b/libc/isystem/endian.h index c1600654f..b37411dd1 100644 --- a/libc/isystem/endian.h +++ b/libc/isystem/endian.h @@ -1,5 +1,5 @@ -#ifndef LIBC_ISYSTEM_ENDIAN_H_ -#define LIBC_ISYSTEM_ENDIAN_H_ +#ifndef _ENDIAN_H +#define _ENDIAN_H #include "libc/intrin/newbie.h" #include "libc/sysv/consts/endian.h" -#endif /* LIBC_ISYSTEM_ENDIAN_H_ */ +#endif /* _ENDIAN_H */ diff --git a/libc/isystem/err.h b/libc/isystem/err.h index 0bba6cfdc..7982abdb3 100644 --- a/libc/isystem/err.h +++ b/libc/isystem/err.h @@ -1,4 +1,4 @@ -#ifndef LIBC_ISYSTEM_ERR_H_ -#define LIBC_ISYSTEM_ERR_H_ +#ifndef _ERR_H +#define _ERR_H #include "libc/log/bsd.h" -#endif +#endif /* _ERR_H */ diff --git a/libc/isystem/errno.h b/libc/isystem/errno.h index 9c360d89b..96490245b 100644 --- a/libc/isystem/errno.h +++ b/libc/isystem/errno.h @@ -1,4 +1,4 @@ -#ifndef LIBC_ISYSTEM_ERRNO_H_ -#define LIBC_ISYSTEM_ERRNO_H_ +#ifndef _ERRNO_H +#define _ERRNO_H #include "libc/errno.h" -#endif +#endif /* _ERRNO_H */ diff --git a/libc/isystem/fcntl.h b/libc/isystem/fcntl.h index 7e1cfa02c..6caa95ca3 100644 --- a/libc/isystem/fcntl.h +++ b/libc/isystem/fcntl.h @@ -1,5 +1,5 @@ -#ifndef LIBC_ISYSTEM_SYS_FCNTL_H_ -#define LIBC_ISYSTEM_SYS_FCNTL_H_ +#ifndef _FCNTL_H +#define _FCNTL_H #include "libc/calls/calls.h" #include "libc/calls/struct/flock.h" #include "libc/calls/weirdtypes.h" @@ -10,4 +10,4 @@ #include "libc/sysv/consts/posix.h" #include "libc/sysv/consts/s.h" #include "libc/sysv/consts/splice.h" -#endif +#endif /* _FCNTL_H */ diff --git a/libc/isystem/features.h b/libc/isystem/features.h index eb3f84a50..61238fb01 100644 --- a/libc/isystem/features.h +++ b/libc/isystem/features.h @@ -1,5 +1,5 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_FEATURES_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_FEATURES_H_ +#ifndef _FEATURES_H +#define _FEATURES_H #if defined(_ALL_SOURCE) && !defined(_GNU_SOURCE) #define _GNU_SOURCE 1 @@ -35,4 +35,4 @@ #define _Noreturn #endif -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_FEATURES_H_ */ +#endif /* _FEATURES_H */ diff --git a/libc/isystem/fenv.h b/libc/isystem/fenv.h index 7eb86051e..cb67b540c 100644 --- a/libc/isystem/fenv.h +++ b/libc/isystem/fenv.h @@ -1,4 +1,4 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_FENV_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_FENV_H_ +#ifndef _FENV_H +#define _FENV_H #include "libc/runtime/fenv.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_FENV_H_ */ +#endif /* _FENV_H */ diff --git a/libc/isystem/float.h b/libc/isystem/float.h index 3b76ad848..c1effda08 100644 --- a/libc/isystem/float.h +++ b/libc/isystem/float.h @@ -1,5 +1,5 @@ -#ifndef LIBC_ISYSTEM_FLOAT_H_ -#define LIBC_ISYSTEM_FLOAT_H_ +#ifndef _FLOAT_H +#define _FLOAT_H #include "libc/math.h" #include "libc/runtime/fenv.h" -#endif +#endif /* _FLOAT_H */ diff --git a/libc/isystem/fnmatch.h b/libc/isystem/fnmatch.h index 630a1389b..9bfad342b 100644 --- a/libc/isystem/fnmatch.h +++ b/libc/isystem/fnmatch.h @@ -1,4 +1,4 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_FNMATCH_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_FNMATCH_H_ +#ifndef _FNMATCH_H +#define _FNMATCH_H #include "third_party/musl/fnmatch.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_FNMATCH_H_ */ +#endif /* _FNMATCH_H */ diff --git a/libc/isystem/ftw.h b/libc/isystem/ftw.h index 034cb918b..dd7b91cef 100644 --- a/libc/isystem/ftw.h +++ b/libc/isystem/ftw.h @@ -1,6 +1,6 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_FTW_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_FTW_H_ +#ifndef _FTW_H +#define _FTW_H #include "libc/calls/weirdtypes.h" #include "libc/sysv/consts/s.h" #include "third_party/musl/ftw.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_FTW_H_ */ +#endif /* _FTW_H */ diff --git a/libc/isystem/fun.py b/libc/isystem/fun.py deleted file mode 100644 index 00b7e78de..000000000 --- a/libc/isystem/fun.py +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_FUN_PY_ -#define COSMOPOLITAN_LIBC_ISYSTEM_FUN_PY_ -#include "third_party/intel/fun.py" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_FUN_PY_ */ diff --git a/libc/isystem/getopt.h b/libc/isystem/getopt.h index ffbc0bc35..88dfd1f3a 100644 --- a/libc/isystem/getopt.h +++ b/libc/isystem/getopt.h @@ -1,4 +1,4 @@ -#ifndef LIBC_ISYSTEM_GETOPT_H_ -#define LIBC_ISYSTEM_GETOPT_H_ +#ifndef _GETOPT_H +#define _GETOPT_H #include "third_party/getopt/getopt.h" -#endif +#endif /* _GETOPT_H */ diff --git a/libc/isystem/glob.h b/libc/isystem/glob.h index bdefa8042..03be998c0 100644 --- a/libc/isystem/glob.h +++ b/libc/isystem/glob.h @@ -1,4 +1,4 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_GLOB_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_GLOB_H_ +#ifndef _GLOB_H +#define _GLOB_H #include "third_party/musl/glob.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_GLOB_H_ */ +#endif /* _GLOB_H */ diff --git a/libc/isystem/grp.h b/libc/isystem/grp.h index 73951c06d..475d075b2 100644 --- a/libc/isystem/grp.h +++ b/libc/isystem/grp.h @@ -1,5 +1,5 @@ -#ifndef LIBC_ISYSTEM_GRP_H_ -#define LIBC_ISYSTEM_GRP_H_ +#ifndef _GRP_H +#define _GRP_H #include "libc/calls/calls.h" #include "third_party/musl/passwd.h" -#endif +#endif /* _GRP_H */ diff --git a/libc/isystem/iconv.h b/libc/isystem/iconv.h index c7610a71a..7a1175f9b 100644 --- a/libc/isystem/iconv.h +++ b/libc/isystem/iconv.h @@ -1,4 +1,4 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_ICONV_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_ICONV_H_ +#ifndef _ICONV_H +#define _ICONV_H #include "libc/stdio/iconv.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_ICONV_H_ */ +#endif /* _ICONV_H */ diff --git a/libc/isystem/inttypes.h b/libc/isystem/inttypes.h index 5d0afed9e..14064eab7 100644 --- a/libc/isystem/inttypes.h +++ b/libc/isystem/inttypes.h @@ -1,7 +1,7 @@ -#ifndef LIBC_ISYSTEM_INTTYPES_H_ -#define LIBC_ISYSTEM_INTTYPES_H_ +#ifndef _INTTYPES_H +#define _INTTYPES_H #include "libc/fmt/conv.h" #include "libc/inttypes.h" #include "libc/limits.h" #include "libc/literal.h" -#endif /* LIBC_ISYSTEM_INTTYPES_H_ */ +#endif /* _INTTYPES_H */ diff --git a/libc/isystem/iso646.h b/libc/isystem/iso646.h index ecac914e2..5d203df5f 100644 --- a/libc/isystem/iso646.h +++ b/libc/isystem/iso646.h @@ -1,4 +1,4 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_ISO646_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_ISO646_H_ +#ifndef _ISO646_H +#define _ISO646_H #include "libc/iso646.internal.h" -#endif +#endif /* _ISO646_H */ diff --git a/libc/isystem/langinfo.h b/libc/isystem/langinfo.h index de503701f..6be085243 100644 --- a/libc/isystem/langinfo.h +++ b/libc/isystem/langinfo.h @@ -1,6 +1,6 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_LANGINFO_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_LANGINFO_H_ +#ifndef _LANGINFO_H +#define _LANGINFO_H #include "libc/str/langinfo.h" #include "libc/str/locale.h" #include "libc/str/nltypes.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_LANGINFO_H_ */ +#endif /* _LANGINFO_H */ diff --git a/libc/isystem/libgen.h b/libc/isystem/libgen.h index db17f68f0..509df8db7 100644 --- a/libc/isystem/libgen.h +++ b/libc/isystem/libgen.h @@ -1,4 +1,4 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_LIBGEN_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_LIBGEN_H_ +#ifndef _LIBGEN_H +#define _LIBGEN_H #include "libc/fmt/conv.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_LIBGEN_H_ */ +#endif /* _LIBGEN_H */ diff --git a/libc/isystem/limits.h b/libc/isystem/limits.h index 45a682014..40c3fd3b3 100644 --- a/libc/isystem/limits.h +++ b/libc/isystem/limits.h @@ -1,9 +1,9 @@ -#ifndef LIBC_ISYSTEM_LIMITS_H_ -#define LIBC_ISYSTEM_LIMITS_H_ +#ifndef _LIMITS_H +#define _LIMITS_H #include "libc/limits.h" #include "libc/sysv/consts/_posix.h" #include "libc/sysv/consts/iov.h" #include "libc/sysv/consts/limits.h" #include "libc/sysv/consts/xopen.h" #include "libc/thread/thread.h" -#endif +#endif /* _LIMITS_H */ diff --git a/libc/isystem/locale.h b/libc/isystem/locale.h index cbce7fdf3..da33afc4c 100644 --- a/libc/isystem/locale.h +++ b/libc/isystem/locale.h @@ -1,5 +1,5 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_LOCALE_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_LOCALE_H_ +#ifndef _LOCALE_H +#define _LOCALE_H #include "libc/str/locale.h" #include "libc/str/unicode.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_LOCALE_H_ */ +#endif /* _LOCALE_H */ diff --git a/libc/isystem/malloc.h b/libc/isystem/malloc.h index 4172e752f..44db730b4 100644 --- a/libc/isystem/malloc.h +++ b/libc/isystem/malloc.h @@ -1,4 +1,4 @@ -#ifndef LIBC_ISYSTEM_MALLOC_H_ -#define LIBC_ISYSTEM_MALLOC_H_ +#ifndef _MALLOC_H +#define _MALLOC_H #include "libc/mem/mem.h" -#endif +#endif /* _MALLOC_H */ diff --git a/libc/isystem/math.h b/libc/isystem/math.h index 16452ab7d..f0467ef93 100644 --- a/libc/isystem/math.h +++ b/libc/isystem/math.h @@ -1,4 +1,4 @@ -#ifndef LIBC_ISYSTEM_MATH_H_ -#define LIBC_ISYSTEM_MATH_H_ +#ifndef _MATH_H +#define _MATH_H #include "libc/math.h" -#endif +#endif /* _MATH_H */ diff --git a/libc/isystem/memory.h b/libc/isystem/memory.h index 1de49e5a4..71fc8fa16 100644 --- a/libc/isystem/memory.h +++ b/libc/isystem/memory.h @@ -1,5 +1,5 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_MEMORY_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_MEMORY_H_ +#ifndef _MEMORY_H +#define _MEMORY_H #include "libc/mem/alg.h" #include "libc/str/str.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_MEMORY_H_ */ +#endif /* _MEMORY_H */ diff --git a/libc/isystem/netdb.h b/libc/isystem/netdb.h index a42783197..10650883d 100644 --- a/libc/isystem/netdb.h +++ b/libc/isystem/netdb.h @@ -1,5 +1,5 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_NETDB_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_NETDB_H_ +#ifndef _NETDB_H +#define _NETDB_H #include "libc/dns/dns.h" #include "libc/dns/ent.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_NETDB_H_ */ +#endif /* _NETDB_H */ diff --git a/libc/isystem/setjmp.h b/libc/isystem/setjmp.h index cdaa6181c..ae54f4c52 100644 --- a/libc/isystem/setjmp.h +++ b/libc/isystem/setjmp.h @@ -1,4 +1,4 @@ -#ifndef LIBC_ISYSTEM_SETJMP_H_ -#define LIBC_ISYSTEM_SETJMP_H_ +#ifndef _SETJMP_H +#define _SETJMP_H #include "libc/runtime/runtime.h" -#endif +#endif /* _SETJMP_H */ diff --git a/libc/isystem/signal.h b/libc/isystem/signal.h index f009abeca..0342af9c6 100644 --- a/libc/isystem/signal.h +++ b/libc/isystem/signal.h @@ -1,5 +1,5 @@ -#ifndef LIBC_ISYSTEM_SIGNAL_H_ -#define LIBC_ISYSTEM_SIGNAL_H_ +#ifndef _SIGNAL_H +#define _SIGNAL_H #include "libc/calls/calls.h" #include "libc/calls/sigtimedwait.h" #include "libc/calls/struct/sigaction.h" @@ -7,4 +7,4 @@ #include "libc/sysv/consts/sa.h" #include "libc/sysv/consts/sicode.h" #include "libc/sysv/consts/ss.h" -#endif +#endif /* _SIGNAL_H */ diff --git a/libc/isystem/stdalign.h b/libc/isystem/stdalign.h index c35db49b1..16874814a 100644 --- a/libc/isystem/stdalign.h +++ b/libc/isystem/stdalign.h @@ -1,4 +1,4 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_STDALIGN_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_STDALIGN_H_ +#ifndef _STDALIGN_H +#define _STDALIGN_H #include "libc/stdalign.internal.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_STDALIGN_H_ */ +#endif /* _STDALIGN_H */ diff --git a/libc/isystem/stdarg.h b/libc/isystem/stdarg.h index d726d372a..232d26075 100644 --- a/libc/isystem/stdarg.h +++ b/libc/isystem/stdarg.h @@ -1,3 +1,3 @@ -#ifndef LIBC_ISYSTEM_STDARG_H_ -#define LIBC_ISYSTEM_STDARG_H_ -#endif +#ifndef _STDARG_H +#define _STDARG_H +#endif /* _STDARG_H */ diff --git a/libc/isystem/stdatomic.h b/libc/isystem/stdatomic.h index 8c80073aa..52fdc5d6e 100644 --- a/libc/isystem/stdatomic.h +++ b/libc/isystem/stdatomic.h @@ -1,4 +1,4 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_STDATOMIC_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_STDATOMIC_H_ +#ifndef _STDATOMIC_H +#define _STDATOMIC_H #include "libc/intrin/atomic.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_STDATOMIC_H_ */ +#endif /* _STDATOMIC_H */ diff --git a/libc/isystem/stdbool.h b/libc/isystem/stdbool.h index e8f37fb81..686336b9f 100644 --- a/libc/isystem/stdbool.h +++ b/libc/isystem/stdbool.h @@ -1,3 +1,3 @@ -#ifndef LIBC_ISYSTEM_STDBOOL_H_ -#define LIBC_ISYSTEM_STDBOOL_H_ -#endif +#ifndef _STDBOOL_H +#define _STDBOOL_H +#endif /* _STDBOOL_H */ diff --git a/libc/isystem/stdckdint.h b/libc/isystem/stdckdint.h index bf921d486..8556c8906 100644 --- a/libc/isystem/stdckdint.h +++ b/libc/isystem/stdckdint.h @@ -1,4 +1,4 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_STDCKDINT_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_STDCKDINT_H_ +#ifndef _STDCKDINT_H +#define _STDCKDINT_H #include "libc/stdckdint.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_STDCKDINT_H_ */ +#endif /* _STDCKDINT_H */ diff --git a/libc/isystem/stddef.h b/libc/isystem/stddef.h index 34201e5bf..d302cbfe3 100644 --- a/libc/isystem/stddef.h +++ b/libc/isystem/stddef.h @@ -1,3 +1,3 @@ -#ifndef LIBC_ISYSTEM_STDDEF_H_ -#define LIBC_ISYSTEM_STDDEF_H_ -#endif +#ifndef _STDDEF_H +#define _STDDEF_H +#endif /* _STDDEF_H */ diff --git a/libc/isystem/stdint.h b/libc/isystem/stdint.h index 1f16a96a2..5753dc873 100644 --- a/libc/isystem/stdint.h +++ b/libc/isystem/stdint.h @@ -1,6 +1,6 @@ -#ifndef LIBC_ISYSTEM_STDINT_H_ -#define LIBC_ISYSTEM_STDINT_H_ +#ifndef _STDINT_H +#define _STDINT_H #include "libc/inttypes.h" #include "libc/limits.h" #include "libc/literal.h" -#endif +#endif /* _STDINT_H */ diff --git a/libc/isystem/stdio.h b/libc/isystem/stdio.h index d36eac7ed..800df8b3a 100644 --- a/libc/isystem/stdio.h +++ b/libc/isystem/stdio.h @@ -1,11 +1,10 @@ -#ifndef LIBC_ISYSTEM_STDIO_H_ -#define LIBC_ISYSTEM_STDIO_H_ +#ifndef _STDIO_H +#define _STDIO_H #include "libc/calls/calls.h" -#include "libc/stdio/dprintf.h" #include "libc/calls/weirdtypes.h" #include "libc/fmt/fmt.h" -#include "libc/mem/fmt.h" +#include "libc/stdio/dprintf.h" #include "libc/stdio/stdio.h" #include "libc/stdio/temp.h" #include "third_party/musl/tempnam.h" -#endif +#endif /* _STDIO_H */ diff --git a/libc/isystem/stdio_ext.h b/libc/isystem/stdio_ext.h index 03e1c2446..8eefe71d0 100644 --- a/libc/isystem/stdio_ext.h +++ b/libc/isystem/stdio_ext.h @@ -1,4 +1,4 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_STDIO_EXT_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_STDIO_EXT_H_ +#ifndef _STDIO_EXT_H +#define _STDIO_EXT_H #include "libc/stdio/stdio_ext.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_STDIO_EXT_H_ */ +#endif /* _STDIO_EXT_H */ diff --git a/libc/isystem/stdlib.h b/libc/isystem/stdlib.h index fe583d7ec..d4451db32 100644 --- a/libc/isystem/stdlib.h +++ b/libc/isystem/stdlib.h @@ -1,5 +1,5 @@ -#ifndef LIBC_ISYSTEM_STDLIB_H_ -#define LIBC_ISYSTEM_STDLIB_H_ +#ifndef _STDLIB_H +#define _STDLIB_H #include "libc/calls/calls.h" #include "libc/calls/termios.h" #include "libc/fmt/conv.h" @@ -15,4 +15,4 @@ #include "third_party/getopt/getopt.h" #include "third_party/musl/crypt.h" #include "third_party/musl/rand48.h" -#endif +#endif /* _STDLIB_H */ diff --git a/libc/isystem/stdnoreturn.h b/libc/isystem/stdnoreturn.h index 216c41bf9..301259c18 100644 --- a/libc/isystem/stdnoreturn.h +++ b/libc/isystem/stdnoreturn.h @@ -1,10 +1,11 @@ -#ifndef LIBC_ISYSTEM_STDNORETURN_H_ -#define LIBC_ISYSTEM_STDNORETURN_H_ - -COSMOPOLITAN_C_START_ - -#define noreturn wontreturn - -COSMOPOLITAN_C_END_ - +#ifndef _STDNORETURN_H +#define _STDNORETURN_H +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112 +#define noreturn _Noreturn +#elif (defined(__has_attribute) && __has_attribute(__noreturn__)) || \ + (defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ >= 208) +#define noreturn __attribute__((__noreturn__)) +#else +#define noreturn #endif +#endif /* _STDNORETURN_H */ diff --git a/libc/isystem/string.h b/libc/isystem/string.h index e8a0fc362..a1247abbb 100644 --- a/libc/isystem/string.h +++ b/libc/isystem/string.h @@ -1,6 +1,6 @@ -#ifndef LIBC_ISYSTEM_STRING_H_ -#define LIBC_ISYSTEM_STRING_H_ +#ifndef _STRING_H +#define _STRING_H #include "libc/mem/alg.h" #include "libc/mem/mem.h" #include "libc/str/str.h" -#endif +#endif /* _STRING_H */ diff --git a/libc/isystem/strings.h b/libc/isystem/strings.h index 6dcf85003..89ba104a0 100644 --- a/libc/isystem/strings.h +++ b/libc/isystem/strings.h @@ -1,5 +1,5 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_STRINGS_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_STRINGS_H_ +#ifndef _STRINGS_H +#define _STRINGS_H #include "libc/nexgen32e/ffs.h" #include "libc/str/locale.h" #include "libc/str/str.h" @@ -8,4 +8,4 @@ #include "libc/nexgen32e/ffs.h" #endif -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_STRINGS_H_ */ +#endif /* _STRINGS_H */ diff --git a/libc/isystem/sysexits.h b/libc/isystem/sysexits.h index 7e52e2c87..2b7fa9ba8 100644 --- a/libc/isystem/sysexits.h +++ b/libc/isystem/sysexits.h @@ -1,4 +1,4 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_SYSEXITS_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_SYSEXITS_H_ +#ifndef _SYSEXITS_H +#define _SYSEXITS_H #include "libc/sysv/consts/ex.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_SYSEXITS_H_ */ +#endif /* _SYSEXITS_H */ diff --git a/libc/isystem/syslog.h b/libc/isystem/syslog.h index f77924ad7..d23ffc91d 100644 --- a/libc/isystem/syslog.h +++ b/libc/isystem/syslog.h @@ -1,5 +1,5 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_SYSLOG_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_SYSLOG_H_ +#ifndef _SYSLOG_H +#define _SYSLOG_H #include "libc/sock/syslog.h" #include "libc/sysv/consts/log.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_SYSLOG_H_ */ +#endif /* _SYSLOG_H */ diff --git a/libc/isystem/termios.h b/libc/isystem/termios.h index ef988e466..53fa558b7 100644 --- a/libc/isystem/termios.h +++ b/libc/isystem/termios.h @@ -1,7 +1,7 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_TERMIOS_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_TERMIOS_H_ +#ifndef _TERMIOS_H +#define _TERMIOS_H #include "libc/calls/termios.h" #include "libc/calls/weirdtypes.h" #include "libc/sysv/consts/baud.internal.h" #include "libc/sysv/consts/termios.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_TERMIOS_H_ */ +#endif /* _TERMIOS_H */ diff --git a/libc/isystem/tgmath.h b/libc/isystem/tgmath.h index 39785a918..d5f6aa9c0 100644 --- a/libc/isystem/tgmath.h +++ b/libc/isystem/tgmath.h @@ -1,5 +1,5 @@ -#ifndef LIBC_ISYSTEM_TGMATH_H_ -#define LIBC_ISYSTEM_TGMATH_H_ +#ifndef _TGMATH_H +#define _TGMATH_H #include "libc/complex.h" #include "libc/imag.internal.h" #include "libc/math.h" @@ -329,4 +329,4 @@ #endif /* C11 */ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* LIBC_ISYSTEM_TGMATH_H_ */ +#endif /* _TGMATH_H */ diff --git a/libc/isystem/time.h b/libc/isystem/time.h index f1af736fe..f9a7f137c 100644 --- a/libc/isystem/time.h +++ b/libc/isystem/time.h @@ -1,5 +1,6 @@ -#ifndef LIBC_ISYSTEM_TIME_H_ -#define LIBC_ISYSTEM_TIME_H_ +#ifndef _TIME_H +#define _TIME_H +#include "libc/calls/calls.h" #include "libc/calls/struct/timespec.h" #include "libc/calls/struct/timeval.h" #include "libc/calls/weirdtypes.h" @@ -8,4 +9,4 @@ #include "libc/sysv/consts/timer.h" #include "libc/time/struct/tm.h" #include "libc/time/time.h" -#endif +#endif /* _TIME_H */ diff --git a/libc/isystem/unistd.h b/libc/isystem/unistd.h index df61bfd0b..3f3e74f05 100644 --- a/libc/isystem/unistd.h +++ b/libc/isystem/unistd.h @@ -1,5 +1,5 @@ -#ifndef LIBC_ISYSTEM_UNISTD_H_ -#define LIBC_ISYSTEM_UNISTD_H_ +#ifndef _UNISTD_H +#define _UNISTD_H #include "libc/calls/calls.h" #include "libc/calls/weirdtypes.h" #include "libc/runtime/pathconf.h" @@ -13,4 +13,4 @@ #include "third_party/getopt/getopt.h" #include "third_party/musl/crypt.h" #include "third_party/musl/lockf.h" -#endif +#endif /* _UNISTD_H */ diff --git a/libc/isystem/utime.h b/libc/isystem/utime.h index 1b11e6957..c3cf95e65 100644 --- a/libc/isystem/utime.h +++ b/libc/isystem/utime.h @@ -1,5 +1,5 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_UTIME_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_UTIME_H_ +#ifndef _UTIME_H +#define _UTIME_H #include "libc/time/struct/utimbuf.h" #include "libc/time/time.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_UTIME_H_ */ +#endif /* _UTIME_H */ diff --git a/libc/isystem/utmp.h b/libc/isystem/utmp.h index bf585f0c3..2365ac94e 100644 --- a/libc/isystem/utmp.h +++ b/libc/isystem/utmp.h @@ -1,4 +1,4 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_UTMP_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_UTMP_H_ +#ifndef _UTMP_H +#define _UTMP_H #include "libc/runtime/utmp.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_UTMP_H_ */ +#endif /* _UTMP_H */ diff --git a/libc/isystem/utmpx.h b/libc/isystem/utmpx.h index 02048d933..a3375e6f4 100644 --- a/libc/isystem/utmpx.h +++ b/libc/isystem/utmpx.h @@ -1,4 +1,4 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_UTMPX_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_UTMPX_H_ +#ifndef _UTMPX_H +#define _UTMPX_H #include "libc/runtime/utmpx.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_UTMPX_H_ */ +#endif /* _UTMPX_H */ diff --git a/libc/isystem/wait.h b/libc/isystem/wait.h index c03a54de4..9d8e84241 100644 --- a/libc/isystem/wait.h +++ b/libc/isystem/wait.h @@ -1,6 +1,6 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_WAIT_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_WAIT_H_ +#ifndef _WAIT_H +#define _WAIT_H #include "libc/calls/calls.h" #include "libc/calls/weirdtypes.h" #include "libc/sysv/consts/w.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_WAIT_H_ */ +#endif /* _WAIT_H */ diff --git a/libc/isystem/wchar.h b/libc/isystem/wchar.h index 4fb2f7eba..0d0fc0fdf 100644 --- a/libc/isystem/wchar.h +++ b/libc/isystem/wchar.h @@ -1,8 +1,8 @@ -#ifndef LIBC_ISYSTEM_WCHAR_H_ -#define LIBC_ISYSTEM_WCHAR_H_ +#ifndef _WCHAR_H +#define _WCHAR_H #include "libc/fmt/conv.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/str/unicode.h" #include "libc/time/time.h" -#endif +#endif /* _WCHAR_H */ diff --git a/libc/isystem/wctype.h b/libc/isystem/wctype.h index da1785f31..ba782a3bc 100644 --- a/libc/isystem/wctype.h +++ b/libc/isystem/wctype.h @@ -1,6 +1,6 @@ -#ifndef LIBC_ISYSTEM_WCTYPE_H_ -#define LIBC_ISYSTEM_WCTYPE_H_ +#ifndef _WCTYPE_H +#define _WCTYPE_H #include "libc/calls/calls.h" #include "libc/fmt/conv.h" #include "libc/str/str.h" -#endif +#endif /* _WCTYPE_H */ diff --git a/libc/log/attachdebugger.c b/libc/log/attachdebugger.c index 494bfac99..231990f0f 100644 --- a/libc/log/attachdebugger.c +++ b/libc/log/attachdebugger.c @@ -108,7 +108,7 @@ relegated int(AttachDebugger)(intptr_t continuetoaddr) { "c", NULL, }, environ); - __builtin_trap(); + abort(); } return pid; } diff --git a/libc/log/log.mk b/libc/log/log.mk index 666deb9f2..176f9a8b8 100644 --- a/libc/log/log.mk +++ b/libc/log/log.mk @@ -35,7 +35,6 @@ LIBC_LOG_A_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_SYSV_CALLS \ LIBC_TIME \ diff --git a/libc/log/oncrash_amd64.c b/libc/log/oncrash_amd64.c index 40bfde820..8725d68bc 100644 --- a/libc/log/oncrash_amd64.c +++ b/libc/log/oncrash_amd64.c @@ -45,6 +45,7 @@ #include "libc/str/str.h" #include "libc/thread/thread.h" #include "libc/thread/tls.h" +#include "libc/str/str.h" #include "third_party/libcxx/math.h" #ifdef __x86_64__ @@ -222,14 +223,14 @@ relegated void ShowCrashReport(int err, int sig, struct siginfo *si, p, n, "\n%serror%s: Uncaught %G (%s) on %s pid %d tid %d\n" " %s\n" - " %m\n" + " %s\n" " %s %s %s %s\n", !__nocolor ? "\e[30;101m" : "", !__nocolor ? "\e[0m" : "", sig, (ctx && (ctx->uc_mcontext.rsp >= GetStaticStackAddr(0) && ctx->uc_mcontext.rsp <= GetStaticStackAddr(0) + APE_GUARDSIZE)) ? "Stack Overflow" : GetSiCodeName(sig, si->si_code), - host, getpid(), gettid(), program_invocation_name, names.sysname, + host, getpid(), gettid(), program_invocation_name, strerror(err), names.sysname, names.version, names.nodename, names.release); if (ctx) { p = ShowGeneralRegisters(p, ctx); @@ -343,7 +344,7 @@ relegated void __oncrash_amd64(int sig, struct siginfo *si, void *arg) { } else { // somehow __minicrash() crashed not possible for (;;) { - __builtin_trap(); + abort(); } } } else { diff --git a/libc/mem/fmt.h b/libc/mem/fmt.h deleted file mode 100644 index bf19f197b..000000000 --- a/libc/mem/fmt.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_MEM_FMT_H_ -#define COSMOPOLITAN_LIBC_MEM_FMT_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -int asprintf(char **, const char *, ...) printfesque(2) - paramsnonnull((1, 2)) libcesque; -int vasprintf(char **, const char *, va_list) paramsnonnull() libcesque; - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_MEM_FMT_H_ */ diff --git a/libc/mem/mem.mk b/libc/mem/mem.mk index f8524fe78..2cc9b3cc0 100644 --- a/libc/mem/mem.mk +++ b/libc/mem/mem.mk @@ -17,14 +17,13 @@ LIBC_MEM_A_CHECKS = \ LIBC_MEM_A_DIRECTDEPS = \ LIBC_CALLS \ - LIBC_SYSV_CALLS \ LIBC_FMT \ LIBC_INTRIN \ LIBC_NEXGEN32E \ LIBC_RUNTIME \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ + LIBC_SYSV_CALLS \ THIRD_PARTY_DLMALLOC LIBC_MEM_A_DEPS := \ diff --git a/libc/nexgen32e/nexgen32e.mk b/libc/nexgen32e/nexgen32e.mk index ac13445c4..c7f9cd69d 100644 --- a/libc/nexgen32e/nexgen32e.mk +++ b/libc/nexgen32e/nexgen32e.mk @@ -27,9 +27,6 @@ LIBC_NEXGEN32E_A_CHECKS = \ $(LIBC_NEXGEN32E_A).pkg \ $(LIBC_NEXGEN32E_A_HDRS:%=o/$(MODE)/%.ok) -LIBC_NEXGEN32E_A_DIRECTDEPS = \ - LIBC_STUBS - LIBC_NEXGEN32E_A_DEPS := \ $(call uniq,$(foreach x,$(LIBC_NEXGEN32E_A_DIRECTDEPS),$($(x)))) diff --git a/libc/nt/struct/msg.h b/libc/nt/struct/msg.h index 3009d30de..91bf24403 100644 --- a/libc/nt/struct/msg.h +++ b/libc/nt/struct/msg.h @@ -5,10 +5,10 @@ struct NtMsg { int64_t hwnd; - uint32_t message; + uint32_t dwMessage; uint64_t wParam; int64_t lParam; - uint32_t time; + uint32_t dwTime; struct NtPoint pt; }; diff --git a/libc/stubs/xnu.S b/libc/runtime/__stack_chk_fail.c similarity index 85% rename from libc/stubs/xnu.S rename to libc/runtime/__stack_chk_fail.c index 465b2c842..3bdd04a7a 100644 --- a/libc/stubs/xnu.S +++ b/libc/runtime/__stack_chk_fail.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 tw=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,7 +16,4 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.internal.h" - -_xnu: ud2 - .endfn _xnu,weak +#include "libc/runtime/runtime.h" diff --git a/libc/runtime/isdynamicexecutable.c b/libc/runtime/isdynamicexecutable.c index 588da0009..b2b33f190 100644 --- a/libc/runtime/isdynamicexecutable.c +++ b/libc/runtime/isdynamicexecutable.c @@ -64,7 +64,7 @@ bool _IsDynamicExecutable(const char *prog) { goto Finish; } for (i = 0; i < e->e_phnum; ++i) { - p = GetElfSegmentHeaderAddress(e, st.st_size, i); + p = GetElfProgramHeaderAddress(e, st.st_size, i); if (p->p_type == PT_INTERP || p->p_type == PT_DYNAMIC) { res = true; goto Finish; diff --git a/libc/runtime/mmap.c b/libc/runtime/mmap.c index f5e89c3c2..878296a6c 100644 --- a/libc/runtime/mmap.c +++ b/libc/runtime/mmap.c @@ -28,6 +28,7 @@ #include "libc/intrin/bsr.h" #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/directmap.internal.h" +#include "libc/intrin/kprintf.h" #include "libc/intrin/likely.h" #include "libc/intrin/safemacros.internal.h" #include "libc/intrin/strace.internal.h" diff --git a/libc/runtime/runtime.mk b/libc/runtime/runtime.mk index 1e73755d4..eab72da13 100644 --- a/libc/runtime/runtime.mk +++ b/libc/runtime/runtime.mk @@ -42,7 +42,6 @@ LIBC_RUNTIME_A_DIRECTDEPS = \ LIBC_NT_KERNEL32 \ LIBC_NT_SYNCHRONIZATION \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_SYSV_CALLS \ THIRD_PARTY_PUFF \ diff --git a/libc/runtime/utmp.c b/libc/runtime/utmp.c index 819c103d3..a7ead4854 100644 --- a/libc/runtime/utmp.c +++ b/libc/runtime/utmp.c @@ -39,6 +39,10 @@ void updwtmp(const char *x, const struct utmp *y) { void updwtmpx(const char *x, const struct utmpx *y) { } +struct utmpx *pututxline(const struct utmpx *p) { + return 0; +} + void setutxent(void) { } diff --git a/libc/sock/sock.mk b/libc/sock/sock.mk index 4c5158d1a..f95fbfce4 100644 --- a/libc/sock/sock.mk +++ b/libc/sock/sock.mk @@ -32,19 +32,18 @@ LIBC_SOCK_A_DIRECTDEPS = \ LIBC_NEXGEN32E \ LIBC_NT_ADVAPI32 \ LIBC_NT_IPHLPAPI \ + LIBC_NT_IPHLPAPI \ LIBC_NT_KERNEL32 \ LIBC_NT_MSWSOCK \ LIBC_NT_NTDLL \ LIBC_NT_WS2_32 \ - LIBC_NT_IPHLPAPI \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ LIBC_STR \ - LIBC_STUBS \ + LIBC_SYSV \ LIBC_SYSV_CALLS \ - LIBC_TIME \ - LIBC_SYSV + LIBC_TIME LIBC_SOCK_A_DEPS := \ $(call uniq,$(foreach x,$(LIBC_SOCK_A_DIRECTDEPS),$($(x)))) diff --git a/libc/stdckdint.h b/libc/stdckdint.h index f2ea4dbcc..51ccc5232 100644 --- a/libc/stdckdint.h +++ b/libc/stdckdint.h @@ -1,5 +1,8 @@ #ifndef COSMOPOLITAN_LIBC_STDCKDINT_H_ #define COSMOPOLITAN_LIBC_STDCKDINT_H_ + +#define __STDC_VERSION_STDCKDINT_H__ 202311L + #if !defined(MODE_DBG) && \ ((defined(__GNUC__) && __GNUC__ >= 5 && !defined(__ICC)) || \ (defined(__has_builtin) && (__has_builtin(__builtin_add_overflow) && \ @@ -16,6 +19,10 @@ #define ckd_sub(res, x, y) __ckd_arithmetic(sub, res, x, y) #define ckd_mul(res, x, y) __ckd_arithmetic(mul, res, x, y) +/* + * implementation details + */ + #if defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ == 8 && \ ((defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ >= 406) || \ defined(__llvm__)) && \ @@ -25,18 +32,96 @@ #define __ckd_dword long long #endif -#define __ckd_arithmetic(op, res, x, y) \ - (sizeof(*(res)) == sizeof(int) ? __ckd_##op((int *)(res), (x), (y)) \ - : sizeof(*(res)) == sizeof(long) ? __ckd_##op##l((long *)(res), (x), (y)) \ - : sizeof(*(res)) == sizeof(__ckd_dword) \ - ? __ckd_##op##ll((__ckd_dword *)(res), (x), (y)) \ - : __ckd_trap()) +#if defined(__cplusplus) && __cplusplus >= 201103L +#include +#define __ckd_is_unsigned(res) std::is_unsigned::value +#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +#define __ckd_is_unsigned(res) \ + _Generic(*(res), unsigned : 1, unsigned long : 1, unsigned long long : 1, \ + unsigned __ckd_dword : 1, default : 0) +#else +#define __ckd_is_unsigned(res) ((__typeof(*(res)))-1 >= 0) +#endif + +#define __ckd_arithmetic(op, res, x, y) \ + (__ckd_is_unsigned(res) \ + ? (sizeof(*(res)) == sizeof(int) \ + ? __ckd_##op##u((unsigned *)(res), (x), (y)) \ + : sizeof(*(res)) == sizeof(long) \ + ? __ckd_##op##ul((unsigned long *)(res), (x), (y)) \ + : sizeof(*(res)) == sizeof(__ckd_dword) \ + ? __ckd_##op##ull((unsigned __ckd_dword *)(res), (x), (y)) \ + : __ckd_trap()) \ + : (sizeof(*(res)) == sizeof(int) \ + ? __ckd_##op((signed int *)(res), (x), (y)) \ + : sizeof(*(res)) == sizeof(long) \ + ? __ckd_##op##l((long *)(res), (x), (y)) \ + : sizeof(*(res)) == sizeof(__ckd_dword) \ + ? __ckd_##op##ll((__ckd_dword *)(res), (x), (y)) \ + : __ckd_trap())) __funline int __ckd_trap(void) { volatile int __x = 0; return 1 / __x; } +/* + * unsigned checked arithmetic + */ + +__funline int __ckd_addu(unsigned *__z, unsigned __x, unsigned __y) { + *__z = __x + __y; + return *__z < __x; +} +__funline int __ckd_addul(unsigned long *__z, unsigned long __x, + unsigned long __y) { + *__z = __x + __y; + return *__z < __x; +} +__funline int __ckd_addull(unsigned __ckd_dword *__z, unsigned __ckd_dword __x, + unsigned __ckd_dword __y) { + *__z = __x + __y; + return *__z < __x; +} + +__funline int __ckd_subu(unsigned *__z, unsigned __x, unsigned __y) { + *__z = __x - __y; + return __x < __y; +} +__funline int __ckd_subul(unsigned long *__z, unsigned long __x, + unsigned long __y) { + *__z = __x - __y; + return __x < __y; +} +__funline int __ckd_subull(unsigned __ckd_dword *__z, unsigned __ckd_dword __x, + unsigned __ckd_dword __y) { + *__z = __x - __y; + return __x < __y; +} + +__funline int __ckd_mulu(unsigned *__z, unsigned __x, unsigned __y) { + *__z = __x * __y; + return __x && *__z / __x != __y; +} +__funline int __ckd_mulul(unsigned long *__z, unsigned long __x, + unsigned long __y) { + *__z = __x * __y; + return __x && *__z / __x != __y; +} +__funline int __ckd_mulull(unsigned __ckd_dword *__z, unsigned __ckd_dword __x, + unsigned __ckd_dword __y) { + *__z = __x * __y; + return __x && *__z / __x != __y; +} + +/* + * signed checked arithmetic + */ + +int __mulosi4(int, int, int *); +long __mulodi4(long, long, int *); +__ckd_dword __muloti4(__ckd_dword, __ckd_dword, int *); + __funline int __ckd_add(int *__z, int __x, int __y) { unsigned int __a, __b, __c; *__z = __c = (__a = __x) + (__b = __y); @@ -69,10 +154,6 @@ __funline int __ckd_subll(__ckd_dword *__z, __ckd_dword __x, __ckd_dword __y) { return ((__a ^ __b) & (__c ^ __a)) >> (sizeof(__ckd_dword) * CHAR_BIT - 1); } -int __mulosi4(int, int, int *); -long __mulodi4(long, long, int *); -__ckd_dword __muloti4(__ckd_dword, __ckd_dword, int *); - __funline int __ckd_mul(int *__z, int __x, int __y) { int __o; *__z = __mulosi4(__x, __y, &__o); diff --git a/libc/stdio/asprintf.c b/libc/stdio/asprintf.c index 7e76a84d0..6e540a169 100644 --- a/libc/stdio/asprintf.c +++ b/libc/stdio/asprintf.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/mem/fmt.h" +#include "libc/stdio/stdio.h" /** * Formats string, allocating needed memory. @@ -28,11 +28,11 @@ * @see xasprintf() for a better API * @threadsafe */ -int(asprintf)(char **strp, const char *fmt, ...) { +int asprintf(char **strp, const char *fmt, ...) { int res; va_list va; va_start(va, fmt); - res = (vasprintf)(strp, fmt, va); + res = vasprintf(strp, fmt, va); va_end(va); return res; } diff --git a/libc/stdio/dprintf.c b/libc/stdio/dprintf.c index 9d4b32281..a8e151161 100644 --- a/libc/stdio/dprintf.c +++ b/libc/stdio/dprintf.c @@ -21,11 +21,11 @@ /** * Formats string directly to file descriptor. */ -int(dprintf)(int fd, const char *fmt, ...) { +int dprintf(int fd, const char *fmt, ...) { int rc; va_list va; va_start(va, fmt); - rc = (vdprintf)(fd, fmt, va); + rc = vdprintf(fd, fmt, va); va_end(va); return rc; } diff --git a/libc/stdio/fprintf.c b/libc/stdio/fprintf.c index fd512ca11..f0e9bed9b 100644 --- a/libc/stdio/fprintf.c +++ b/libc/stdio/fprintf.c @@ -23,12 +23,12 @@ * Formats and writes text to stream. * @see printf() for further documentation */ -int(fprintf)(FILE *f, const char *fmt, ...) { +int fprintf(FILE *f, const char *fmt, ...) { int rc; va_list va; flockfile(f); va_start(va, fmt); - rc = (vfprintf_unlocked)(f, fmt, va); + rc = vfprintf_unlocked(f, fmt, va); va_end(va); funlockfile(f); return rc; diff --git a/libc/stdio/fprintf_unlocked.c b/libc/stdio/fprintf_unlocked.c index f6267dab2..0dbbf8ff3 100644 --- a/libc/stdio/fprintf_unlocked.c +++ b/libc/stdio/fprintf_unlocked.c @@ -22,11 +22,11 @@ * Formats and writes text to stream. * @see printf() for further documentation */ -int(fprintf_unlocked)(FILE *f, const char *fmt, ...) { +int fprintf_unlocked(FILE *f, const char *fmt, ...) { int rc; va_list va; va_start(va, fmt); - rc = (vfprintf_unlocked)(f, fmt, va); + rc = vfprintf_unlocked(f, fmt, va); va_end(va); return rc; } diff --git a/libc/stdio/fscanf.c b/libc/stdio/fscanf.c index a713b7bc9..0e5913b03 100644 --- a/libc/stdio/fscanf.c +++ b/libc/stdio/fscanf.c @@ -34,11 +34,11 @@ * * @see libc/fmt/vcscanf.c */ -int(fscanf)(FILE *stream, const char *fmt, ...) { +int fscanf(FILE *stream, const char *fmt, ...) { int rc; va_list va; va_start(va, fmt); - rc = (vcscanf)((int (*)(void *))fgetc, (void *)ungetc, stream, fmt, va); + rc = __vcscanf((int (*)(void *))fgetc, (void *)ungetc, stream, fmt, va); va_end(va); return rc; } diff --git a/libc/stdio/printf.c b/libc/stdio/printf.c index bfd4acf3a..051c118c2 100644 --- a/libc/stdio/printf.c +++ b/libc/stdio/printf.c @@ -57,11 +57,11 @@ * @see __fmt() for intuitive reference documentation * @see {,v}{,s{,n},{,{,x}as},f,d}printf */ -int(printf)(const char* fmt, ...) { +int printf(const char* fmt, ...) { int rc; va_list va; va_start(va, fmt); - rc = (vfprintf)(stdout, fmt, va); + rc = vfprintf(stdout, fmt, va); va_end(va); return rc; } diff --git a/libc/stdio/scanf.c b/libc/stdio/scanf.c index e2b19b27d..497b47ed2 100644 --- a/libc/stdio/scanf.c +++ b/libc/stdio/scanf.c @@ -23,11 +23,11 @@ * Standard input decoder. * @see libc/fmt/vcscanf.h */ -int(scanf)(const char *fmt, ...) { +int scanf(const char *fmt, ...) { int rc; va_list va; va_start(va, fmt); - rc = (vcscanf)((int (*)(void *))fgetc, NULL, stdin, fmt, va); + rc = __vcscanf((int (*)(void *))fgetc, NULL, stdin, fmt, va); va_end(va); return rc; } diff --git a/libc/stdio/snprintf.c b/libc/stdio/snprintf.c index d2bbd3eaf..dff485baf 100644 --- a/libc/stdio/snprintf.c +++ b/libc/stdio/snprintf.c @@ -28,11 +28,11 @@ * @asyncsignalsafe * @vforksafe */ -int(snprintf)(char* buf, size_t count, const char* fmt, ...) { +int snprintf(char* buf, size_t count, const char* fmt, ...) { int rc; va_list va; va_start(va, fmt); - rc = (vsnprintf)(buf, count, fmt, va); + rc = vsnprintf(buf, count, fmt, va); va_end(va); return rc; } diff --git a/libc/stdio/sprintf.c b/libc/stdio/sprintf.c index fb8b3f90d..d819f9f2a 100644 --- a/libc/stdio/sprintf.c +++ b/libc/stdio/sprintf.c @@ -28,11 +28,11 @@ * @asyncsignalsafe * @vforksafe */ -int(sprintf)(char *buf, const char *fmt, ...) { +int sprintf(char *buf, const char *fmt, ...) { int rc; va_list va; va_start(va, fmt); - rc = (vsnprintf)(buf, INT_MAX, fmt, va); + rc = vsnprintf(buf, INT_MAX, fmt, va); va_end(va); return rc; } diff --git a/libc/stdio/sscanf.c b/libc/stdio/sscanf.c index 7b709cd4a..cf2830305 100644 --- a/libc/stdio/sscanf.c +++ b/libc/stdio/sscanf.c @@ -23,11 +23,11 @@ * String decoder. * @see libc/fmt/vcscanf.h (for docs and implementation) */ -int(sscanf)(const char *str, const char *fmt, ...) { +int sscanf(const char *str, const char *fmt, ...) { int rc; va_list va; va_start(va, fmt); - rc = (vsscanf)(str, fmt, va); + rc = vsscanf(str, fmt, va); va_end(va); return rc; } diff --git a/libc/stdio/stdio.h b/libc/stdio/stdio.h index ff6f19d94..a7fbc5556 100644 --- a/libc/stdio/stdio.h +++ b/libc/stdio/stdio.h @@ -1,5 +1,5 @@ -#ifndef _STDIO_H -#define _STDIO_H +#ifndef COSMOPOLITAN_LIBC_STDIO_H_ +#define COSMOPOLITAN_LIBC_STDIO_H_ #define L_ctermid 20 #define FILENAME_MAX PATH_MAX @@ -125,6 +125,14 @@ int wprintf(const wchar_t *, ...); int wscanf(const wchar_t *, ...); int fwide(FILE *, int); +/*───────────────────────────────────────────────────────────────────────────│─╗ +│ cosmopolitan § standard i/o » allocating ─╬─│┼ +╚────────────────────────────────────────────────────────────────────────────│*/ + +int asprintf(char **, const char *, ...) printfesque(2) + paramsnonnull((1, 2)) libcesque; +int vasprintf(char **, const char *, va_list) paramsnonnull() libcesque; + /*───────────────────────────────────────────────────────────────────────────│─╗ │ cosmopolitan § standard i/o » without mutexes ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ @@ -163,4 +171,4 @@ int vfprintf_unlocked(FILE *, const char *, va_list) COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* _STDIO_H */ +#endif /* COSMOPOLITAN_LIBC_STDIO_H_ */ diff --git a/libc/stdio/stdio.mk b/libc/stdio/stdio.mk index ac8558b51..8794cfcd8 100644 --- a/libc/stdio/stdio.mk +++ b/libc/stdio/stdio.mk @@ -33,7 +33,6 @@ LIBC_STDIO_A_DIRECTDEPS = \ LIBC_NT_KERNEL32 \ LIBC_RUNTIME \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_SYSV_CALLS \ THIRD_PARTY_GDTOA diff --git a/libc/stdio/vasprintf.c b/libc/stdio/vasprintf.c index 4b3c3462f..a4d5a9f0f 100644 --- a/libc/stdio/vasprintf.c +++ b/libc/stdio/vasprintf.c @@ -25,14 +25,14 @@ * @see xasprintf() for a better API * @threadsafe */ -int(vasprintf)(char **strp, const char *fmt, va_list va) { +int vasprintf(char **strp, const char *fmt, va_list va) { va_list vb; size_t size; char *p, *p2; int wrote, rc = -1; if ((p = malloc((size = 512)))) { va_copy(vb, va); - wrote = (vsnprintf)(p, size, fmt, va); + wrote = vsnprintf(p, size, fmt, va); if (wrote < size) { if ((p2 = realloc(p, wrote + 1))) { p = p2; @@ -42,7 +42,7 @@ int(vasprintf)(char **strp, const char *fmt, va_list va) { size = wrote + 1; if ((p2 = realloc(p, size))) { p = p2; - wrote = (vsnprintf)(p, size, fmt, vb); + wrote = vsnprintf(p, size, fmt, vb); _unassert(wrote == size - 1); rc = wrote; } diff --git a/libc/stdio/vcscanf.c b/libc/stdio/vcscanf.c index 8f7c479e9..e0011e314 100644 --- a/libc/stdio/vcscanf.c +++ b/libc/stdio/vcscanf.c @@ -44,8 +44,11 @@ * @param va points to the variadic argument state * @see libc/fmt/pflink.h (dynamic memory is not a requirement) */ -int vcscanf(int callback(void *), int unget(int, void *), void *arg, - const char *fmt, va_list va) { +int __vcscanf(int callback(void *), // + int unget(int, void *), // + void *arg, // + const char *fmt, // + va_list va) { struct FreeMe { struct FreeMe *next; void *ptr; diff --git a/libc/stdio/vdprintf.c b/libc/stdio/vdprintf.c index 045068114..6becb772c 100644 --- a/libc/stdio/vdprintf.c +++ b/libc/stdio/vdprintf.c @@ -58,7 +58,7 @@ static int vdprintf_putc(const char *s, struct VdprintfState *t, size_t n) { * @asyncsignalsafe * @vforksafe */ -int(vdprintf)(int fd, const char *fmt, va_list va) { +int vdprintf(int fd, const char *fmt, va_list va) { struct iovec iov[1]; struct VdprintfState t; t.n = 0; diff --git a/libc/stdio/vfprintf.c b/libc/stdio/vfprintf.c index 6978a0a26..7c55d7a31 100644 --- a/libc/stdio/vfprintf.c +++ b/libc/stdio/vfprintf.c @@ -23,10 +23,10 @@ * Formats and writes text to stream. * @see printf() for further documentation */ -int(vfprintf)(FILE *f, const char *fmt, va_list va) { +int vfprintf(FILE *f, const char *fmt, va_list va) { int rc; flockfile(f); - rc = (vfprintf_unlocked)(f, fmt, va); + rc = vfprintf_unlocked(f, fmt, va); funlockfile(f); return rc; } diff --git a/libc/stdio/vfprintf_unlocked.c b/libc/stdio/vfprintf_unlocked.c index 1e20f7831..c9cf3ee12 100644 --- a/libc/stdio/vfprintf_unlocked.c +++ b/libc/stdio/vfprintf_unlocked.c @@ -51,7 +51,7 @@ static int vfprintfputchar(const char *s, struct state *t, size_t n) { * Formats and writes text to stream. * @see printf() for further documentation */ -int(vfprintf_unlocked)(FILE *f, const char *fmt, va_list va) { +int vfprintf_unlocked(FILE *f, const char *fmt, va_list va) { int rc; struct state st[1] = {{f, 0}}; if ((rc = __fmt(vfprintfputchar, st, fmt, va)) != -1) { diff --git a/libc/stdio/vfscanf.c b/libc/stdio/vfscanf.c index 536c554a3..29a911b2b 100644 --- a/libc/stdio/vfscanf.c +++ b/libc/stdio/vfscanf.c @@ -23,6 +23,6 @@ * Stream decoder. * @see libc/fmt/vcscanf.h */ -int(vfscanf)(FILE *stream, const char *fmt, va_list ap) { - return (vcscanf)((void *)fgetc, (void *)ungetc, stream, fmt, ap); +int vfscanf(FILE *stream, const char *fmt, va_list ap) { + return __vcscanf((void *)fgetc, (void *)ungetc, stream, fmt, ap); } diff --git a/libc/stdio/vprintf.c b/libc/stdio/vprintf.c index a1e273c98..1b3d92330 100644 --- a/libc/stdio/vprintf.c +++ b/libc/stdio/vprintf.c @@ -22,6 +22,6 @@ * Formats and writes text to stdout. * @see printf() for further documentation */ -int(vprintf)(const char* fmt, va_list va) { - return (vfprintf)(stdout, fmt, va); +int vprintf(const char* fmt, va_list va) { + return vfprintf(stdout, fmt, va); } diff --git a/libc/stdio/vscanf.c b/libc/stdio/vscanf.c index acb01a298..26e64f989 100644 --- a/libc/stdio/vscanf.c +++ b/libc/stdio/vscanf.c @@ -23,6 +23,6 @@ * String decoder. * @see libc/fmt/vcscanf.h */ -int(vscanf)(const char *fmt, va_list ap) { - return (vcscanf)((int (*)(void *))fgetc, (void *)ungetc, stdin, fmt, ap); +int vscanf(const char *fmt, va_list ap) { + return __vcscanf((int (*)(void *))fgetc, (void *)ungetc, stdin, fmt, ap); } diff --git a/libc/stdio/vsnprintf.c b/libc/stdio/vsnprintf.c index dcb54417e..aa85a6b98 100644 --- a/libc/stdio/vsnprintf.c +++ b/libc/stdio/vsnprintf.c @@ -56,7 +56,7 @@ static int vsnprintfputchar(const char *s, struct SprintfStr *t, size_t n) { * @asyncsignalsafe * @vforksafe */ -int(vsnprintf)(char *buf, size_t size, const char *fmt, va_list va) { +int vsnprintf(char *buf, size_t size, const char *fmt, va_list va) { struct SprintfStr str = {buf, 0, size}; __fmt(vsnprintfputchar, &str, fmt, va); if (str.n) str.p[MIN(str.i, str.n - 1)] = '\0'; diff --git a/libc/stdio/vsprintf.c b/libc/stdio/vsprintf.c index fcfea86d6..cea4ef7c0 100644 --- a/libc/stdio/vsprintf.c +++ b/libc/stdio/vsprintf.c @@ -25,6 +25,6 @@ * @see __fmt() and printf() for detailed documentation * @see vsnprintf() for modern alternative w/ buf size param */ -int(vsprintf)(char *buf, const char *fmt, va_list va) { - return (vsnprintf)(buf, INT_MAX, fmt, va); +int vsprintf(char *buf, const char *fmt, va_list va) { + return vsnprintf(buf, INT_MAX, fmt, va); } diff --git a/libc/stdio/vsscanf.c b/libc/stdio/vsscanf.c index f100bcfed..570750b18 100644 --- a/libc/stdio/vsscanf.c +++ b/libc/stdio/vsscanf.c @@ -44,7 +44,7 @@ static int vsscanfcb(void *arg) { * needing vsscanf() won't need sscanf() too; and as such, there's * a small code size penalty to using both */ -int(vsscanf)(const char *str, const char *fmt, va_list va) { +int vsscanf(const char *str, const char *fmt, va_list va) { struct StringScannerState state = {(const unsigned char *)str, 0}; - return vcscanf(vsscanfcb, NULL, &state, fmt, va); + return __vcscanf(vsscanfcb, NULL, &state, fmt, va); } diff --git a/libc/str/str.mk b/libc/str/str.mk index e042e0e91..07b53ff72 100644 --- a/libc/str/str.mk +++ b/libc/str/str.mk @@ -29,9 +29,8 @@ LIBC_STR_A_CHECKS = \ LIBC_STR_A_DIRECTDEPS = \ LIBC_INTRIN \ - LIBC_STUBS \ - LIBC_SYSV \ LIBC_NEXGEN32E \ + LIBC_SYSV \ THIRD_PARTY_COMPILER_RT LIBC_STR_A_DEPS := \ diff --git a/libc/stubs/abort.S b/libc/stubs/abort.S deleted file mode 100644 index 891191941..000000000 --- a/libc/stubs/abort.S +++ /dev/null @@ -1,33 +0,0 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "ape/macros.internal.h" -.real - -// Most basic tier of program self-termination. -// -// @mode long,legacy,real -abort: -#ifdef __x86_64__ - ud2 -#elif defined(__aarch64__) - brk #1000 -#else -#error "architecture unsupported" -#endif - .endfn abort,weak diff --git a/libc/stubs/debugbreak.S b/libc/stubs/debugbreak.S deleted file mode 100644 index 95cae0be3..000000000 --- a/libc/stubs/debugbreak.S +++ /dev/null @@ -1,31 +0,0 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.internal.h" -.real -.code16 # ∩ .code32 ∩ .code64 - -// Triggers breakpoint in software debugger. -// -// This should work with GDB, Bochs, WinDbg, etc. -// -// @mode long,legacy,real -DebugBreak: - .softicebp - ret - .endfn DebugBreak,weak diff --git a/libc/stubs/instrumentation.S b/libc/stubs/instrumentation.S deleted file mode 100644 index a008e81a7..000000000 --- a/libc/stubs/instrumentation.S +++ /dev/null @@ -1,32 +0,0 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.internal.h" - -// @fileoverview Function Instrumentation No-Op Runtime -// -// The compiler generates synthetic calls to these functions when -// the -finstrument-functions flag is passed. - -__cyg_profile_func_enter: - ret - .endfn __cyg_profile_func_enter,weak - -__cyg_profile_func_exit: - ret - .endfn __cyg_profile_func_exit,weak diff --git a/libc/stubs/panic.S b/libc/stubs/panic.S deleted file mode 100644 index fc68e0587..000000000 --- a/libc/stubs/panic.S +++ /dev/null @@ -1,32 +0,0 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.internal.h" -.real -.code16 # ∩ .code32 ∩ .code64 - -// Aborts or hard blocks instruction pointer. -// @mode long,legacy,real -__panic: - push %bp - mov %sp,%bp - .softicebp - cli -1: hlt - jmp 1b - .endfn __panic,weak diff --git a/libc/stubs/pututxline.S b/libc/stubs/pututxline.S deleted file mode 100644 index 2dc323b0a..000000000 --- a/libc/stubs/pututxline.S +++ /dev/null @@ -1,27 +0,0 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 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/macros.internal.h" - -// Puts in the user accounting database. -// @note unsupported -pututxline: - xor %eax,%eax - ret - .endfn pututxline,globl - .alias pututxline,pututline diff --git a/libc/stubs/stackguard.S b/libc/stubs/stackguard.S deleted file mode 100644 index 138f11ad9..000000000 --- a/libc/stubs/stackguard.S +++ /dev/null @@ -1,44 +0,0 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "ape/macros.internal.h" -.real -.code16 # ∩ .code32 ∩ .code64 - -/** - * @fileoverview Overridable stubs for synthetic stack protector calls. - */ - -__stack_chk_fail_local: - nop -// fallthrough - .endfn __stack_chk_fail_local,weak,hidden - -__stack_chk_fail: - push %bp - mov %sp,%bp - rlcall abort - nop - .endfn __stack_chk_fail,weak - - .bss - .balign 8 -__stack_chk_guard: - .quad 0 - .endobj __stack_chk_guard,weak - .previous diff --git a/libc/stubs/stubs.mk b/libc/stubs/stubs.mk deleted file mode 100644 index 51be93c7a..000000000 --- a/libc/stubs/stubs.mk +++ /dev/null @@ -1,56 +0,0 @@ -#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐ -#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘ -# -# SYNOPSIS -# -# Universally Linkable Weak Functions -# -# DESCRIPTION -# -# This package contains no-op implementations for (1) synthetic -# compiler surprises and (2) mission-critical core functions, e.g. -# abort(). These functions are designed to work in all addressing -# modes, including real mode. Every package links this. It's at the -# base of the topological order of things. - -PKGS += LIBC_STUBS - -LIBC_STUBS_ARTIFACTS += LIBC_STUBS_A -LIBC_STUBS = $(LIBC_STUBS_A) -LIBC_STUBS_A = o/$(MODE)/libc/stubs/stubs.a -LIBC_STUBS_A_FILES := $(wildcard libc/stubs/*.S) - -LIBC_STUBS_A_HDRS = \ - $(filter %.h,$(LIBC_STUBS_A_FILES)) - -LIBC_STUBS_A_SRCS = \ - $(filter %.S,$(LIBC_STUBS_A_FILES)) - -LIBC_STUBS_A_OBJS = \ - $(LIBC_STUBS_A_SRCS:%.S=o/$(MODE)/%.o) - -LIBC_STUBS_A_CHECKS = \ - $(LIBC_STUBS_A).pkg \ - $(LIBC_STUBS_A_HDRS:%=o/%.ok) - -$(LIBC_STUBS_A): \ - libc/stubs/ \ - $(LIBC_STUBS_A).pkg \ - $(LIBC_STUBS_A_OBJS) - -$(LIBC_STUBS_A).pkg: \ - $(LIBC_STUBS_A_OBJS) \ - $(foreach x,$(LIBC_STUBS_A_DIRECTDEPS),$($(x)_A).pkg) - -# these assembly files are safe to build on aarch64 -o/$(MODE)/libc/stubs/abort.o: libc/stubs/abort.S - @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $< - -LIBC_STUBS_LIBS = $(foreach x,$(LIBC_STUBS_ARTIFACTS),$($(x))) -LIBC_STUBS_SRCS = $(foreach x,$(LIBC_STUBS_ARTIFACTS),$($(x)_SRCS)) -LIBC_STUBS_CHECKS = $(foreach x,$(LIBC_STUBS_ARTIFACTS),$($(x)_CHECKS)) -LIBC_STUBS_OBJS = $(foreach x,$(LIBC_STUBS_ARTIFACTS),$($(x)_OBJS)) - -.PHONY: o/$(MODE)/libc/stubs -o/$(MODE)/libc/stubs: \ - $(LIBC_STUBS_CHECKS) diff --git a/libc/testlib/testlib.mk b/libc/testlib/testlib.mk index 7bcebe91d..562e14f41 100644 --- a/libc/testlib/testlib.mk +++ b/libc/testlib/testlib.mk @@ -102,7 +102,6 @@ LIBC_TESTLIB_A_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_SYSV_CALLS \ LIBC_TIME \ @@ -171,7 +170,6 @@ LIBC_TESTLIB_RUNNER_A_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_TESTLIB LIBC_TESTLIB_RUNNER_A_DEPS := \ @@ -211,7 +209,6 @@ LIBC_TESTMAIN_DIRECTDEPS = \ LIBC_NEXGEN32E \ LIBC_RUNTIME \ LIBC_STDIO \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_SYSV_CALLS \ LIBC_TESTLIB \ diff --git a/libc/thread/thread.mk b/libc/thread/thread.mk index 704c99e19..0f7d2eb57 100644 --- a/libc/thread/thread.mk +++ b/libc/thread/thread.mk @@ -27,14 +27,13 @@ LIBC_THREAD_A_DIRECTDEPS = \ LIBC_CALLS \ LIBC_INTRIN \ LIBC_MEM \ + LIBC_NEXGEN32E \ LIBC_NT_KERNEL32 \ LIBC_NT_SYNCHRONIZATION \ LIBC_RUNTIME \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_SYSV_CALLS \ - LIBC_NEXGEN32E \ THIRD_PARTY_NSYNC \ THIRD_PARTY_NSYNC_MEM diff --git a/libc/time/time.h b/libc/time/time.h index e21d116b6..72c7d7256 100644 --- a/libc/time/time.h +++ b/libc/time/time.h @@ -1,38 +1,34 @@ #ifndef COSMOPOLITAN_LIBC_TIME_TIME_H_ #define COSMOPOLITAN_LIBC_TIME_TIME_H_ -#define TIME_UTC 1 -#define CLOCKS_PER_SEC 1000000L +#define TIME_UTC 1 #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -_Hide extern const char kWeekdayNameShort[7][4]; -_Hide extern const char kWeekdayName[7][10]; -_Hide extern const char kMonthNameShort[12][4]; -_Hide extern const char kMonthName[12][10]; -_Hide extern const unsigned short kMonthYearDay[2][12]; - extern char *tzname[2]; extern long timezone; extern int daylight; char *ctime(const int64_t *); char *ctime_r(const int64_t *, char[hasatleast 26]); -double difftime(int64_t, int64_t) -dontthrow pureconst; -extern long double (*nowl)(void); -int64_t clock(void); +double difftime(int64_t, int64_t) pureconst; int64_t posix2time(int64_t) pureconst; -int64_t time(int64_t *); int64_t time2posix(int64_t) pureconst; +void tzset(void); + +#ifdef COSMO +_Hide extern const char kWeekdayNameShort[7][4]; +_Hide extern const char kWeekdayName[7][10]; +_Hide extern const char kMonthNameShort[12][4]; +_Hide extern const char kMonthName[12][10]; +_Hide extern const unsigned short kMonthYearDay[2][12]; +extern long double (*nowl)(void); long double ConvertTicksToNanos(double); long double dsleep(long double); long double dtime(int); -unsigned alarm(unsigned); -unsigned sleep(unsigned); void RefreshTime(void); -void tzset(void); +#endif COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/time/time.mk b/libc/time/time.mk index e5c2021f9..ee86f5e35 100644 --- a/libc/time/time.mk +++ b/libc/time/time.mk @@ -34,13 +34,10 @@ LIBC_TIME_A_DIRECTDEPS = \ LIBC_MEM \ LIBC_NEXGEN32E \ LIBC_NT_KERNEL32 \ - LIBC_NT_NTDLL \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ - LIBC_SYSV_CALLS \ LIBC_ZIPOS \ THIRD_PARTY_COMPILER_RT diff --git a/libc/time/xiso8601.c b/libc/time/xiso8601.c index f8b05d14f..09d3ef7a0 100644 --- a/libc/time/xiso8601.c +++ b/libc/time/xiso8601.c @@ -20,8 +20,8 @@ #include "libc/calls/struct/timeval.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/mem/fmt.h" #include "libc/mem/mem.h" +#include "libc/stdio/stdio.h" #include "libc/sysv/consts/clock.h" #include "libc/time/struct/tm.h" #include "libc/time/time.h" @@ -56,7 +56,7 @@ static char *xiso8601_impl(struct timespec *opt_ts, int sswidth) { localtime_r(&sec, &tm); strftime(timebuf, sizeof(timebuf), "%Y-%m-%dT%H:%M:%S", &tm); strftime(zonebuf, sizeof(zonebuf), "%z", &tm); - (asprintf)(&p, "%s.%0*ld%s", timebuf, sswidth, subsec, zonebuf); + asprintf(&p, "%s.%0*ld%s", timebuf, sswidth, subsec, zonebuf); return p; } diff --git a/libc/tinymath/tinymath.mk b/libc/tinymath/tinymath.mk index f10dcbe8d..6a5865745 100644 --- a/libc/tinymath/tinymath.mk +++ b/libc/tinymath/tinymath.mk @@ -25,7 +25,6 @@ LIBC_TINYMATH_A_CHECKS = \ LIBC_TINYMATH_A_DIRECTDEPS = \ LIBC_INTRIN \ - LIBC_STUBS \ LIBC_NEXGEN32E \ LIBC_SYSV \ THIRD_PARTY_COMPILER_RT diff --git a/libc/vga/tty.greg.c b/libc/vga/tty.greg.c index 532e94c45..30c1d907f 100644 --- a/libc/vga/tty.greg.c +++ b/libc/vga/tty.greg.c @@ -1002,7 +1002,7 @@ static void TtySelectGraphicsRendition(struct Tty *tty) { tty->pr &= ~kTtyTrue; break; default: - abort(); + __builtin_trap(); } break; default: diff --git a/libc/vga/vga.mk b/libc/vga/vga.mk index 0fabf0284..1030e08b8 100644 --- a/libc/vga/vga.mk +++ b/libc/vga/vga.mk @@ -27,12 +27,11 @@ LIBC_VGA_A_CHECKS = \ $(LIBC_VGA_A_HDRS:%=o/$(MODE)/%.ok) LIBC_VGA_A_DIRECTDEPS = \ - LIBC_NEXGEN32E \ - LIBC_SYSV \ - LIBC_STR \ + LIBC_FMT \ LIBC_INTRIN \ - LIBC_STUBS \ - LIBC_FMT + LIBC_NEXGEN32E \ + LIBC_STR \ + LIBC_SYSV LIBC_VGA_A_DEPS := \ $(call uniq,$(foreach x,$(LIBC_VGA_A_DIRECTDEPS),$($(x)))) diff --git a/libc/x/x.mk b/libc/x/x.mk index e05fc18fb..0d23edf8a 100644 --- a/libc/x/x.mk +++ b/libc/x/x.mk @@ -33,7 +33,6 @@ LIBC_X_A_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ THIRD_PARTY_GDTOA \ THIRD_PARTY_ZLIB diff --git a/libc/x/xasprintf.c b/libc/x/xasprintf.c index 50293edc9..59518892f 100644 --- a/libc/x/xasprintf.c +++ b/libc/x/xasprintf.c @@ -24,11 +24,11 @@ * @return must be free()'d or gc()'d * @note greatest of all C functions */ -char *(xasprintf)(const char *fmt, ...) { +char *xasprintf(const char *fmt, ...) { char *res; va_list va; va_start(va, fmt); - res = (xvasprintf)(fmt, va); + res = xvasprintf(fmt, va); va_end(va); return res; } diff --git a/libc/x/xvasprintf.c b/libc/x/xvasprintf.c index 25ece9dbe..c1a63e154 100644 --- a/libc/x/xvasprintf.c +++ b/libc/x/xvasprintf.c @@ -16,7 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/mem/fmt.h" +#include "libc/stdio/stdio.h" #include "libc/x/x.h" #include "libc/x/xasprintf.h" @@ -26,8 +26,8 @@ * @return fully formatted string, which must be free()'d * @see xasprintf() */ -char *(xvasprintf)(const char *fmt, va_list va) { +char *xvasprintf(const char *fmt, va_list va) { char *buf; - if ((vasprintf)(&buf, fmt, va) == -1) xdie(); + if (vasprintf(&buf, fmt, va) == -1) xdie(); return buf; } diff --git a/libc/zipos/zipos.mk b/libc/zipos/zipos.mk index 4b03357c8..36e5d1d6d 100644 --- a/libc/zipos/zipos.mk +++ b/libc/zipos/zipos.mk @@ -29,17 +29,16 @@ LIBC_ZIPOS_A_CHECKS = \ LIBC_ZIPOS_A_DIRECTDEPS = \ LIBC_CALLS \ + LIBC_FMT \ + LIBC_INTRIN \ LIBC_MEM \ LIBC_NEXGEN32E \ - LIBC_FMT \ - LIBC_RUNTIME \ - LIBC_SYSV \ - LIBC_THREAD \ - LIBC_STR \ - LIBC_INTRIN \ - LIBC_STUBS \ - LIBC_SYSV_CALLS \ LIBC_NT_KERNEL32 \ + LIBC_RUNTIME \ + LIBC_STR \ + LIBC_SYSV \ + LIBC_SYSV_CALLS \ + LIBC_THREAD \ THIRD_PARTY_PUFF LIBC_ZIPOS_A_DEPS := \ diff --git a/net/http/foldheader.c b/net/http/foldheader.c index ac930abf9..5d019d2d1 100644 --- a/net/http/foldheader.c +++ b/net/http/foldheader.c @@ -25,7 +25,7 @@ * Collapses repeating headers onto a single line. */ char *FoldHeader(struct HttpMessage *msg, char *b, int h, size_t *z) { - char *p; + char *p, *p2; size_t i, n, m; struct HttpHeader *x; n = msg->headers[h].b - msg->headers[h].a; @@ -35,9 +35,13 @@ char *FoldHeader(struct HttpMessage *msg, char *b, int h, size_t *z) { x = msg->xheaders.p + i; if (GetHttpHeader(b + x->k.a, x->k.b - x->k.a) == h) { m = x->v.b - x->v.a; - if (!(p = realloc(p, n + 2 + m))) abort(); - memcpy(mempcpy(p + n, ", ", 2), b + x->v.a, m); - n += 2 + m; + if ((p2 = realloc(p, n + 2 + m))) { + memcpy(mempcpy((p = p2) + n, ", ", 2), b + x->v.a, m); + n += 2 + m; + } else { + free(p); + return 0; + } } } *z = n; diff --git a/net/http/http.mk b/net/http/http.mk index 5630fd652..2a96f04e0 100644 --- a/net/http/http.mk +++ b/net/http/http.mk @@ -22,7 +22,6 @@ NET_HTTP_A_DIRECTDEPS = \ LIBC_MEM \ LIBC_NEXGEN32E \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_TIME diff --git a/net/https/https.mk b/net/https/https.mk index e98b11a11..4380e663e 100644 --- a/net/https/https.mk +++ b/net/https/https.mk @@ -30,7 +30,6 @@ NET_HTTPS_A_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_TIME \ LIBC_X \ diff --git a/net/turfwar/turfwar.mk b/net/turfwar/turfwar.mk index d3c2e58de..36f09b426 100644 --- a/net/turfwar/turfwar.mk +++ b/net/turfwar/turfwar.mk @@ -27,7 +27,6 @@ NET_TURFWAR_DIRECTDEPS = \ LIBC_SOCK \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_THREAD \ LIBC_TIME \ diff --git a/test/dsp/scale/test.mk b/test/dsp/scale/test.mk index e638a64e8..1343ddd6b 100644 --- a/test/dsp/scale/test.mk +++ b/test/dsp/scale/test.mk @@ -30,7 +30,6 @@ TEST_DSP_SCALE_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_TINYMATH \ LIBC_X \ TOOL_VIZ_LIB \ diff --git a/test/dsp/tty/test.mk b/test/dsp/tty/test.mk index e53ccc4ef..2cc04f5d8 100644 --- a/test/dsp/tty/test.mk +++ b/test/dsp/tty/test.mk @@ -28,7 +28,6 @@ TEST_DSP_TTY_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_TINYMATH \ LIBC_TESTLIB diff --git a/test/libc/calls/test.mk b/test/libc/calls/test.mk index fa6042414..17329d6e8 100644 --- a/test/libc/calls/test.mk +++ b/test/libc/calls/test.mk @@ -44,7 +44,6 @@ TEST_LIBC_CALLS_DIRECTDEPS = \ LIBC_SYSV_CALLS \ LIBC_RUNTIME \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_THREAD \ LIBC_TIME \ diff --git a/test/libc/dns/test.mk b/test/libc/dns/test.mk index 658b4b2ac..cc9da059d 100644 --- a/test/libc/dns/test.mk +++ b/test/libc/dns/test.mk @@ -34,7 +34,6 @@ TEST_LIBC_DNS_DIRECTDEPS = \ LIBC_SOCK \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_TESTLIB \ LIBC_X diff --git a/test/libc/fmt/test.mk b/test/libc/fmt/test.mk index 8ed240936..9cede3f6c 100644 --- a/test/libc/fmt/test.mk +++ b/test/libc/fmt/test.mk @@ -26,7 +26,6 @@ TEST_LIBC_FMT_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_TESTLIB \ LIBC_TINYMATH \ diff --git a/test/libc/intrin/stdckdint_test.c b/test/libc/intrin/stdckdint_test.c index 3fdd5f8d7..045b62f93 100644 --- a/test/libc/intrin/stdckdint_test.c +++ b/test/libc/intrin/stdckdint_test.c @@ -17,10 +17,12 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/stdckdint.h" -#include "libc/intrin/kprintf.h" #include "libc/macros.internal.h" +#include "libc/stdio/stdio.h" #include "libc/str/str.h" +#define FAIL ++failed < 100 + #define uintmax_t uint128_t #define T int @@ -77,11 +79,11 @@ void test_ckd_add(void) { int z1, z2, o1, o2, y = Vint[i]; o1 = ckd_add(&z1, x, y); o2 = __builtin_add_overflow(x, y, &z2); - if (z1 != z2 && ++failed < 100) { - kprintf("add %d * %d = %d vs. %d\n", x, y, z1, z2); + if (z1 != z2 && FAIL) { + fprintf(stderr, "add %d + %d = %d vs. %d\n", x, y, z1, z2); } - if (o1 != o2 && ++failed < 100) { - kprintf("add %d * %d overflow disagreement\n", x, y); + if (o1 != o2 && FAIL) { + fprintf(stderr, "add %d + %d overflow disagreement\n", x, y); } } } @@ -94,11 +96,11 @@ void test_ckd_sub(void) { int z1, z2, o1, o2, y = Vint[i]; o1 = ckd_sub(&z1, x, y); o2 = __builtin_sub_overflow(x, y, &z2); - if (z1 != z2 && ++failed < 100) { - kprintf("sub %d * %d = %d vs. %d\n", x, y, z1, z2); + if (z1 != z2 && FAIL) { + fprintf(stderr, "sub %d - %d = %d vs. %d\n", x, y, z1, z2); } - if (o1 != o2 && ++failed < 100) { - kprintf("sub %d * %d overflow disagreement\n", x, y); + if (o1 != o2 && FAIL) { + fprintf(stderr, "sub %d - %d overflow disagreement\n", x, y); } } } @@ -111,11 +113,11 @@ void test_ckd_mul(void) { int z1, z2, o1, o2, y = Vint[i]; o1 = ckd_mul(&z1, x, y); o2 = __builtin_mul_overflow(x, y, &z2); - if (z1 != z2 && ++failed < 100) { - kprintf("mul %d * %d = %d vs. %d\n", x, y, z1, z2); + if (z1 != z2 && FAIL) { + fprintf(stderr, "mul %d * %d = %d vs. %d\n", x, y, z1, z2); } - if (o1 != o2 && ++failed < 100) { - kprintf("mul %d * %d overflow disagreement\n", x, y); + if (o1 != o2 && FAIL) { + fprintf(stderr, "mul %d * %d overflow disagreement\n", x, y); } } } @@ -128,11 +130,11 @@ void test_ckd_add_long(void) { long z1, z2, o1, o2, y = Vlong[i]; o1 = ckd_add(&z1, x, y); o2 = __builtin_add_overflow(x, y, &z2); - if (z1 != z2 && ++failed < 100) { - kprintf("add %d * %d = %d vs. %d\n", x, y, z1, z2); + if (z1 != z2 && FAIL) { + fprintf(stderr, "add %ld + %ld = %ld vs. %ld\n", x, y, z1, z2); } - if (o1 != o2 && ++failed < 100) { - kprintf("add %d * %d overflow disagreement\n", x, y); + if (o1 != o2 && FAIL) { + fprintf(stderr, "add %ld + %ld overflow disagreement\n", x, y); } } } @@ -145,11 +147,11 @@ void test_ckd_sub_long(void) { long z1, z2, o1, o2, y = Vlong[i]; o1 = ckd_sub(&z1, x, y); o2 = __builtin_sub_overflow(x, y, &z2); - if (z1 != z2 && ++failed < 100) { - kprintf("sub %d * %d = %d vs. %d\n", x, y, z1, z2); + if (z1 != z2 && FAIL) { + fprintf(stderr, "sub %ld - %ld = %ld vs. %ld\n", x, y, z1, z2); } - if (o1 != o2 && ++failed < 100) { - kprintf("sub %d * %d overflow disagreement\n", x, y); + if (o1 != o2 && FAIL) { + fprintf(stderr, "sub %ld - %ld overflow disagreement\n", x, y); } } } @@ -162,11 +164,11 @@ void test_ckd_mul_long(void) { long z1, z2, o1, o2, y = Vlong[i]; o1 = ckd_mul(&z1, x, y); o2 = __builtin_mul_overflow(x, y, &z2); - if (z1 != z2 && ++failed < 100) { - kprintf("mul %d * %d = %d vs. %d\n", x, y, z1, z2); + if (z1 != z2 && FAIL) { + fprintf(stderr, "mul %ld * %ld = %ld vs. %ld\n", x, y, z1, z2); } - if (o1 != o2 && ++failed < 100) { - kprintf("mul %d * %d overflow disagreement\n", x, y); + if (o1 != o2 && FAIL) { + fprintf(stderr, "mul %ld * %ld overflow disagreement\n", x, y); } } } @@ -179,11 +181,11 @@ void test_ckd_add_int128(void) { int128_t z1, z2, o1, o2, y = Vint128[i]; o1 = ckd_add(&z1, x, y); o2 = __builtin_add_overflow(x, y, &z2); - if (z1 != z2 && ++failed < 100) { - kprintf("add %d * %d = %d vs. %d\n", x, y, z1, z2); + if (z1 != z2 && FAIL) { + fprintf(stderr, "add %jjd * %jjd = %jjd vs. %jjd\n", x, y, z1, z2); } - if (o1 != o2 && ++failed < 100) { - kprintf("add %d * %d overflow disagreement\n", x, y); + if (o1 != o2 && FAIL) { + fprintf(stderr, "add %jjd * %jjd overflow disagreement\n", x, y); } } } @@ -196,11 +198,11 @@ void test_ckd_sub_int128(void) { int128_t z1, z2, o1, o2, y = Vint128[i]; o1 = ckd_sub(&z1, x, y); o2 = __builtin_sub_overflow(x, y, &z2); - if (z1 != z2 && ++failed < 100) { - kprintf("sub %d * %d = %d vs. %d\n", x, y, z1, z2); + if (z1 != z2 && FAIL) { + fprintf(stderr, "sub %jjd * %jjd = %jjd vs. %jjd\n", x, y, z1, z2); } - if (o1 != o2 && ++failed < 100) { - kprintf("sub %d * %d overflow disagreement\n", x, y); + if (o1 != o2 && FAIL) { + fprintf(stderr, "sub %jjd * %jjd overflow disagreement\n", x, y); } } } @@ -213,11 +215,164 @@ void test_ckd_mul_int128(void) { int128_t z1, z2, o1, o2, y = Vint128[i]; o1 = ckd_mul(&z1, x, y); o2 = __builtin_mul_overflow(x, y, &z2); - if (z1 != z2 && ++failed < 100) { - kprintf("mul %d * %d = %d vs. %d\n", x, y, z1, z2); + if (z1 != z2 && FAIL) { + fprintf(stderr, "mul %jjd * %jjd = %jjd vs. %jjd\n", x, y, z1, z2); } - if (o1 != o2 && ++failed < 100) { - kprintf("mul %d * %d overflow disagreement\n", x, y); + if (o1 != o2 && FAIL) { + fprintf(stderr, "mul %jjd * %jjd overflow disagreement\n", x, y); + } + } + } +} + +void test_ckd_addu(void) { + for (int i = 0; i < ARRAYLEN(Vint); ++i) { + unsigned int x = Vint[i]; + for (int j = 0; j < ARRAYLEN(Vint); ++j) { + unsigned int z1, z2, o1, o2, y = Vint[i]; + o1 = ckd_add(&z1, x, y); + o2 = __builtin_add_overflow(x, y, &z2); + if (z1 != z2 && FAIL) { + fprintf(stderr, "unsigned add %u + %u = %u vs. %u\n", x, y, z1, z2); + } + if (o1 != o2 && FAIL) { + fprintf(stderr, "unsigned add %u + %u overflow disagreement\n", x, y); + } + } + } +} + +void test_ckd_subu(void) { + for (int i = 0; i < ARRAYLEN(Vint); ++i) { + unsigned int x = Vint[i]; + for (int j = 0; j < ARRAYLEN(Vint); ++j) { + unsigned int z1, z2, o1, o2, y = Vint[i]; + o1 = ckd_sub(&z1, x, y); + o2 = __builtin_sub_overflow(x, y, &z2); + if (z1 != z2 && FAIL) { + fprintf(stderr, "unsigned sub %u - %u = %u vs. %u\n", x, y, z1, z2); + } + if (o1 != o2 && FAIL) { + fprintf(stderr, "unsigned sub %u - %u overflow disagreement\n", x, y); + } + } + } +} + +void test_ckd_mulu(void) { + for (int i = 0; i < ARRAYLEN(Vint); ++i) { + unsigned int x = Vint[i]; + for (int j = 0; j < ARRAYLEN(Vint); ++j) { + unsigned int z1, z2, o1, o2, y = Vint[i]; + o1 = ckd_mul(&z1, x, y); + o2 = __builtin_mul_overflow(x, y, &z2); + if (z1 != z2 && FAIL) { + fprintf(stderr, "unsigned mul %u * %u = %u vs. %u\n", x, y, z1, z2); + } + if (o1 != o2 && FAIL) { + fprintf(stderr, "unsigned mul %u * %u overflow disagreement\n", x, y); + } + } + } +} + +void test_ckd_addul(void) { + for (int i = 0; i < ARRAYLEN(Vlong); ++i) { + unsigned long x = Vlong[i]; + for (int j = 0; j < ARRAYLEN(Vlong); ++j) { + unsigned long z1, z2, o1, o2, y = Vlong[i]; + o1 = ckd_add(&z1, x, y); + o2 = __builtin_add_overflow(x, y, &z2); + if (z1 != z2 && FAIL) { + fprintf(stderr, "ulong add %lu + %lu = %lu vs. %lu\n", x, y, z1, z2); + } + if (o1 != o2 && FAIL) { + fprintf(stderr, "ulong add %lu + %lu overflow disagreement\n", x, y); + } + } + } +} + +void test_ckd_subul(void) { + for (int i = 0; i < ARRAYLEN(Vlong); ++i) { + unsigned long x = Vlong[i]; + for (int j = 0; j < ARRAYLEN(Vlong); ++j) { + unsigned long z1, z2, o1, o2, y = Vlong[i]; + o1 = ckd_sub(&z1, x, y); + o2 = __builtin_sub_overflow(x, y, &z2); + if (z1 != z2 && FAIL) { + fprintf(stderr, "ulong sub %lu - %lu = %lu vs. %lu\n", x, y, z1, z2); + } + if (o1 != o2 && FAIL) { + fprintf(stderr, "ulong sub %lu - %lu overflow disagreement\n", x, y); + } + } + } +} + +void test_ckd_mulul(void) { + for (int i = 0; i < ARRAYLEN(Vlong); ++i) { + unsigned long x = Vlong[i]; + for (int j = 0; j < ARRAYLEN(Vlong); ++j) { + unsigned long z1, z2, o1, o2, y = Vlong[i]; + o1 = ckd_mul(&z1, x, y); + o2 = __builtin_mul_overflow(x, y, &z2); + if (z1 != z2 && FAIL) { + fprintf(stderr, "ulong mul %lu * %lu = %lu vs. %lu\n", x, y, z1, z2); + } + if (o1 != o2 && FAIL) { + fprintf(stderr, "ulong mul %lu * %lu overflow disagreement\n", x, y); + } + } + } +} + +void test_ckd_addull(void) { + for (int i = 0; i < ARRAYLEN(Vint128); ++i) { + uint128_t x = Vint128[i]; + for (int j = 0; j < ARRAYLEN(Vint128); ++j) { + uint128_t z1, z2, o1, o2, y = Vint128[i]; + o1 = ckd_add(&z1, x, y); + o2 = __builtin_add_overflow(x, y, &z2); + if (z1 != z2 && FAIL) { + fprintf(stderr, "u128 add %jju + %jju = %jju vs. %jju\n", x, y, z1, z2); + } + if (o1 != o2 && FAIL) { + fprintf(stderr, "u128 add %jju + %jju overflow disagreement\n", x, y); + } + } + } +} + +void test_ckd_subull(void) { + for (int i = 0; i < ARRAYLEN(Vint128); ++i) { + uint128_t x = Vint128[i]; + for (int j = 0; j < ARRAYLEN(Vint128); ++j) { + uint128_t z1, z2, o1, o2, y = Vint128[i]; + o1 = ckd_sub(&z1, x, y); + o2 = __builtin_sub_overflow(x, y, &z2); + if (z1 != z2 && FAIL) { + fprintf(stderr, "u128 sub %jju - %jju = %jju vs. %jju\n", x, y, z1, z2); + } + if (o1 != o2 && FAIL) { + fprintf(stderr, "u128 sub %jju - %jju overflow disagreement\n", x, y); + } + } + } +} + +void test_ckd_mulull(void) { + for (int i = 0; i < ARRAYLEN(Vint128); ++i) { + uint128_t x = Vint128[i]; + for (int j = 0; j < ARRAYLEN(Vint128); ++j) { + uint128_t z1, z2, o1, o2, y = Vint128[i]; + o1 = ckd_mul(&z1, x, y); + o2 = __builtin_mul_overflow(x, y, &z2); + if (z1 != z2 && FAIL) { + fprintf(stderr, "u128 mul %jju * %jju = %jju vs. %jju\n", x, y, z1, z2); + } + if (o1 != o2 && FAIL) { + fprintf(stderr, "u128 mul %jju * %jju overflow disagreement\n", x, y); } } } @@ -233,5 +388,14 @@ int main(int argc, char *argv[]) { test_ckd_add_int128(); test_ckd_sub_int128(); test_ckd_mul_int128(); + test_ckd_addu(); + test_ckd_subu(); + test_ckd_mulu(); + test_ckd_addul(); + test_ckd_subul(); + test_ckd_mulul(); + test_ckd_addull(); + test_ckd_subull(); + test_ckd_mulull(); return failed ? 1 : 0; } diff --git a/test/libc/intrin/test.mk b/test/libc/intrin/test.mk index ace6a84aa..ff5e7e7fe 100644 --- a/test/libc/intrin/test.mk +++ b/test/libc/intrin/test.mk @@ -32,7 +32,6 @@ TEST_LIBC_INTRIN_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_SYSV_CALLS \ LIBC_THREAD \ diff --git a/test/libc/log/test.mk b/test/libc/log/test.mk index cc7c9e34e..cdb7a0948 100644 --- a/test/libc/log/test.mk +++ b/test/libc/log/test.mk @@ -36,7 +36,6 @@ TEST_LIBC_LOG_DIRECTDEPS = \ LIBC_NEXGEN32E \ LIBC_LOG \ LIBC_STR \ - LIBC_STUBS \ LIBC_TESTLIB \ LIBC_SYSV \ LIBC_LOG \ diff --git a/test/libc/mem/test.mk b/test/libc/mem/test.mk index f76176027..32178903d 100644 --- a/test/libc/mem/test.mk +++ b/test/libc/mem/test.mk @@ -39,7 +39,6 @@ TEST_LIBC_MEM_DIRECTDEPS = \ LIBC_SOCK \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_SYSV_CALLS \ LIBC_TESTLIB \ diff --git a/test/libc/nexgen32e/test.mk b/test/libc/nexgen32e/test.mk index 45531fc86..bdfec96e2 100644 --- a/test/libc/nexgen32e/test.mk +++ b/test/libc/nexgen32e/test.mk @@ -34,7 +34,6 @@ TEST_LIBC_NEXGEN32E_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_THREAD \ LIBC_TESTLIB \ diff --git a/test/libc/runtime/test.mk b/test/libc/runtime/test.mk index e7cecbb96..5a462cc9c 100644 --- a/test/libc/runtime/test.mk +++ b/test/libc/runtime/test.mk @@ -32,7 +32,6 @@ TEST_LIBC_RUNTIME_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_THREAD \ LIBC_TESTLIB \ diff --git a/test/libc/sock/test.mk b/test/libc/sock/test.mk index 1cdc64d55..b9f514b36 100644 --- a/test/libc/sock/test.mk +++ b/test/libc/sock/test.mk @@ -32,7 +32,6 @@ TEST_LIBC_SOCK_DIRECTDEPS = \ LIBC_SOCK \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_LOG \ LIBC_SYSV_CALLS \ diff --git a/test/libc/stdio/test.mk b/test/libc/stdio/test.mk index 6c49439c0..0380d01c0 100644 --- a/test/libc/stdio/test.mk +++ b/test/libc/stdio/test.mk @@ -31,7 +31,6 @@ TEST_LIBC_STDIO_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_TINYMATH \ LIBC_TESTLIB \ diff --git a/test/libc/str/test.mk b/test/libc/str/test.mk index f609ecbff..ca5521d27 100644 --- a/test/libc/str/test.mk +++ b/test/libc/str/test.mk @@ -41,7 +41,6 @@ TEST_LIBC_STR_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_SYSV_CALLS \ LIBC_TESTLIB \ diff --git a/test/libc/thread/sem_open_test.c b/test/libc/thread/sem_open_test.c index 9b8fbe8c8..e0308def6 100644 --- a/test/libc/thread/sem_open_test.c +++ b/test/libc/thread/sem_open_test.c @@ -26,6 +26,7 @@ #include "libc/str/str.h" #include "libc/sysv/consts/clock.h" #include "libc/sysv/consts/o.h" +#include "libc/sysv/consts/sig.h" #include "libc/testlib/subprocess.h" #include "libc/testlib/testlib.h" #include "libc/thread/semaphore.h" @@ -107,7 +108,7 @@ TEST(sem_close, withUnnamedSemaphore_isUndefinedBehavior) { SPAWN(fork); IgnoreStderr(); sem_close(&sem); - EXITS(23); // see __assert_fail + EXITS(128 + SIGILL); // see __assert_fail ASSERT_SYS(0, 0, sem_destroy(&sem)); } @@ -118,7 +119,7 @@ TEST(sem_destroy, withNamedSemaphore_isUndefinedBehavior) { SPAWN(fork); IgnoreStderr(); sem_destroy(sem); - EXITS(23); // see __assert_fail + EXITS(128 + SIGILL); // see __assert_fail ASSERT_SYS(0, 0, sem_unlink("/boop")); ASSERT_SYS(0, 0, sem_close(sem)); } diff --git a/test/libc/thread/sem_timedwait_test.c b/test/libc/thread/sem_timedwait_test.c index ddd5d2b28..b7de6beb2 100644 --- a/test/libc/thread/sem_timedwait_test.c +++ b/test/libc/thread/sem_timedwait_test.c @@ -51,7 +51,7 @@ TEST(sem_post, afterDestroyed_isUndefinedBehavior) { ASSERT_SYS(0, 0, sem_destroy(&sem)); IgnoreStderr(); sem_post(&sem); - EXITS(23); // see __assert_fail + EXITS(128 + SIGILL); // see __assert_fail } TEST(sem_trywait, afterDestroyed_isUndefinedBehavior) { @@ -63,7 +63,7 @@ TEST(sem_trywait, afterDestroyed_isUndefinedBehavior) { ASSERT_SYS(0, 0, sem_destroy(&sem)); IgnoreStderr(); sem_trywait(&sem); - EXITS(23); // see __assert_fail + EXITS(128 + SIGILL); // see __assert_fail } TEST(sem_wait, afterDestroyed_isUndefinedBehavior) { @@ -75,7 +75,7 @@ TEST(sem_wait, afterDestroyed_isUndefinedBehavior) { ASSERT_SYS(0, 0, sem_destroy(&sem)); IgnoreStderr(); sem_wait(&sem); - EXITS(23); // see __assert_fail + EXITS(128 + SIGILL); // see __assert_fail } TEST(sem_timedwait, afterDestroyed_isUndefinedBehavior) { @@ -87,7 +87,7 @@ TEST(sem_timedwait, afterDestroyed_isUndefinedBehavior) { ASSERT_SYS(0, 0, sem_destroy(&sem)); IgnoreStderr(); sem_timedwait(&sem, 0); - EXITS(23); // see __assert_fail + EXITS(128 + SIGILL); // see __assert_fail } void *Worker(void *arg) { diff --git a/test/libc/thread/test.mk b/test/libc/thread/test.mk index c3c230f38..3f7e11e73 100644 --- a/test/libc/thread/test.mk +++ b/test/libc/thread/test.mk @@ -31,7 +31,6 @@ TEST_LIBC_THREAD_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_TESTLIB \ LIBC_THREAD \ diff --git a/test/libc/time/test.mk b/test/libc/time/test.mk index caa61cba9..d6606e6ad 100644 --- a/test/libc/time/test.mk +++ b/test/libc/time/test.mk @@ -24,7 +24,6 @@ TEST_LIBC_TIME_DIRECTDEPS = \ LIBC_MEM \ LIBC_NEXGEN32E \ LIBC_RUNTIME \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_TESTLIB \ LIBC_TIME \ diff --git a/test/libc/tinymath/test.mk b/test/libc/tinymath/test.mk index 5a7ffb2f8..fddf8772d 100644 --- a/test/libc/tinymath/test.mk +++ b/test/libc/tinymath/test.mk @@ -31,7 +31,6 @@ TEST_LIBC_TINYMATH_DIRECTDEPS = \ LIBC_STDIO \ LIBC_RUNTIME \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_TESTLIB \ LIBC_TINYMATH \ diff --git a/test/libc/x/test.mk b/test/libc/x/test.mk index cd10050ca..6ea260400 100644 --- a/test/libc/x/test.mk +++ b/test/libc/x/test.mk @@ -32,7 +32,6 @@ TEST_LIBC_X_DIRECTDEPS = \ LIBC_STDIO \ LIBC_STR \ LIBC_SOCK \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_THREAD \ LIBC_TESTLIB \ diff --git a/test/libc/xed/test.mk b/test/libc/xed/test.mk index 440f93ec9..c1cfe38db 100644 --- a/test/libc/xed/test.mk +++ b/test/libc/xed/test.mk @@ -30,7 +30,6 @@ TEST_LIBC_XED_TESTLIB_A_DIRECTDEPS = \ LIBC_MEM \ LIBC_NEXGEN32E \ LIBC_RUNTIME \ - LIBC_STUBS \ LIBC_TESTLIB \ LIBC_X \ THIRD_PARTY_XED @@ -75,7 +74,6 @@ TEST_LIBC_XED_DIRECTDEPS = \ LIBC_NEXGEN32E \ LIBC_RUNTIME \ LIBC_RUNTIME \ - LIBC_STUBS \ LIBC_TESTLIB \ TEST_LIBC_XED_TESTLIB \ THIRD_PARTY_XED diff --git a/test/libc/zipos/test.mk b/test/libc/zipos/test.mk index 086867e33..a3a29fb7b 100644 --- a/test/libc/zipos/test.mk +++ b/test/libc/zipos/test.mk @@ -30,7 +30,6 @@ TEST_LIBC_ZIPOS_DIRECTDEPS = \ LIBC_NEXGEN32E \ LIBC_RUNTIME \ LIBC_STR \ - LIBC_STUBS \ LIBC_THREAD \ LIBC_SYSV \ LIBC_ZIPOS \ diff --git a/test/tool/args/test.mk b/test/tool/args/test.mk index 673946eaa..d0de12885 100644 --- a/test/tool/args/test.mk +++ b/test/tool/args/test.mk @@ -38,7 +38,6 @@ TEST_TOOL_ARGS_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_TESTLIB \ LIBC_ZIPOS \ diff --git a/test/tool/build/lib/test.mk b/test/tool/build/lib/test.mk index 0fb48fcb2..5b3978a9f 100644 --- a/test/tool/build/lib/test.mk +++ b/test/tool/build/lib/test.mk @@ -38,7 +38,6 @@ TEST_TOOL_BUILD_LIB_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_TESTLIB \ LIBC_X \ diff --git a/test/tool/net/test.mk b/test/tool/net/test.mk index 68c2b980d..273b40ed1 100644 --- a/test/tool/net/test.mk +++ b/test/tool/net/test.mk @@ -39,7 +39,6 @@ TEST_TOOL_NET_DIRECTDEPS = \ LIBC_SOCK \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_TESTLIB \ LIBC_THREAD \ diff --git a/test/tool/plinko/test.mk b/test/tool/plinko/test.mk index 7f1f53c76..517d153c2 100644 --- a/test/tool/plinko/test.mk +++ b/test/tool/plinko/test.mk @@ -48,7 +48,6 @@ TEST_TOOL_PLINKO_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_TESTLIB \ LIBC_X \ diff --git a/test/tool/viz/lib/test.mk b/test/tool/viz/lib/test.mk index 12208a778..c3b7cef95 100644 --- a/test/tool/viz/lib/test.mk +++ b/test/tool/viz/lib/test.mk @@ -31,7 +31,6 @@ TEST_TOOL_VIZ_LIB_DIRECTDEPS = \ LIBC_NEXGEN32E \ LIBC_RUNTIME \ LIBC_STDIO \ - LIBC_STUBS \ LIBC_TESTLIB \ LIBC_STR \ LIBC_TIME \ diff --git a/third_party/argon2/argon2.mk b/third_party/argon2/argon2.mk index 5095c9845..18a92ad46 100644 --- a/third_party/argon2/argon2.mk +++ b/third_party/argon2/argon2.mk @@ -25,8 +25,7 @@ THIRD_PARTY_ARGON2_A_DIRECTDEPS = \ LIBC_STDIO \ LIBC_RUNTIME \ LIBC_SYSV_CALLS \ - LIBC_STR \ - LIBC_STUBS + LIBC_STR THIRD_PARTY_ARGON2_A_DEPS := \ $(call uniq,$(foreach x,$(THIRD_PARTY_ARGON2_A_DIRECTDEPS),$($(x)))) diff --git a/third_party/awk/awk.mk b/third_party/awk/awk.mk index b5f531a4d..0cff336c0 100644 --- a/third_party/awk/awk.mk +++ b/third_party/awk/awk.mk @@ -22,7 +22,6 @@ THIRD_PARTY_AWK_A_DIRECTDEPS = \ LIBC_STDIO \ LIBC_SYSV \ LIBC_STR \ - LIBC_STUBS \ LIBC_TINYMATH \ TOOL_ARGS \ THIRD_PARTY_GDTOA diff --git a/third_party/bzip2/bzip2.mk b/third_party/bzip2/bzip2.mk index 123e6a7bb..47f15e952 100644 --- a/third_party/bzip2/bzip2.mk +++ b/third_party/bzip2/bzip2.mk @@ -31,7 +31,6 @@ THIRD_PARTY_BZIP2_A_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV THIRD_PARTY_BZIP2_A_DEPS := \ diff --git a/third_party/chibicc/chibicc.mk b/third_party/chibicc/chibicc.mk index 00bc01945..524a71fbd 100644 --- a/third_party/chibicc/chibicc.mk +++ b/third_party/chibicc/chibicc.mk @@ -10,8 +10,6 @@ # This makefile compiles and runs each test twice. The first with # GCC-built chibicc, and a second time with chibicc-built chibicc -ifneq ($(MODE), dbg) -ifneq ($(MODE), asan) ifeq ($(ARCH), x86_64) CHIBICC = o/$(MODE)/third_party/chibicc/chibicc.com @@ -51,13 +49,11 @@ THIRD_PARTY_CHIBICC_A_DIRECTDEPS = \ LIBC_FMT \ LIBC_INTRIN \ LIBC_LOG \ - LIBC_LOG \ LIBC_MEM \ LIBC_NEXGEN32E \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_TIME \ LIBC_X \ @@ -115,8 +111,6 @@ THIRD_PARTY_CHIBICC_CHECKS = $(foreach x,$(THIRD_PARTY_CHIBICC_ARTIFACTS),$($(x) THIRD_PARTY_CHIBICC_OBJS = $(foreach x,$(THIRD_PARTY_CHIBICC_ARTIFACTS),$($(x)_OBJS)) $(THIRD_PARTY_CHIBICC_OBJS): $(BUILD_FILES) third_party/chibicc/chibicc.mk -endif -endif endif .PHONY: o/$(MODE)/third_party/chibicc diff --git a/third_party/chibicc/test/arith_test.c b/third_party/chibicc/test/arith_test.c index 6d10a39a4..5cda6a45e 100644 --- a/third_party/chibicc/test/arith_test.c +++ b/third_party/chibicc/test/arith_test.c @@ -1,6 +1,7 @@ #include "third_party/chibicc/test/test.h" int main() { + ASSERT(0, 0); ASSERT(42, 42); ASSERT(21, 5 + 20 - 4); diff --git a/third_party/chibicc/test/test.mk b/third_party/chibicc/test/test.mk index 550424ac7..aa02fcf2b 100644 --- a/third_party/chibicc/test/test.mk +++ b/third_party/chibicc/test/test.mk @@ -10,8 +10,6 @@ # This makefile compiles and runs each test twice. The first with # GCC-built chibicc, and a second time with chibicc-built chibicc -ifneq ($(MODE), dbg) -ifneq ($(MODE), asan) ifeq ($(ARCH), x86_64) PKGS += THIRD_PARTY_CHIBICC_TEST @@ -46,7 +44,6 @@ THIRD_PARTY_CHIBICC_TEST_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_TINYMATH \ LIBC_X \ THIRD_PARTY_CHIBICC \ @@ -79,8 +76,6 @@ o/$(MODE)/third_party/chibicc/test/%.o: \ o/$(MODE)/third_party/chibicc/test/int128_test.o: private QUOTA = -M1024m -endif -endif endif .PHONY: o/$(MODE)/third_party/chibicc/test diff --git a/third_party/compiler_rt/compiler_rt.mk b/third_party/compiler_rt/compiler_rt.mk index ee913c341..914d4b771 100644 --- a/third_party/compiler_rt/compiler_rt.mk +++ b/third_party/compiler_rt/compiler_rt.mk @@ -29,7 +29,6 @@ THIRD_PARTY_COMPILER_RT_A_CHECKS = \ THIRD_PARTY_COMPILER_RT_A_DIRECTDEPS = \ LIBC_INTRIN \ LIBC_NEXGEN32E \ - LIBC_STUBS THIRD_PARTY_COMPILER_RT_A_DEPS := \ $(call uniq,$(foreach x,$(THIRD_PARTY_COMPILER_RT_A_DIRECTDEPS),$($(x)))) diff --git a/third_party/ctags/args.h b/third_party/ctags/args.h index 438720fb1..07928eaec 100644 --- a/third_party/ctags/args.h +++ b/third_party/ctags/args.h @@ -21,7 +21,6 @@ #include "libc/stdio/dprintf.h" #include "libc/calls/weirdtypes.h" #include "libc/fmt/fmt.h" -#include "libc/mem/fmt.h" #include "libc/stdio/stdio.h" #include "libc/stdio/temp.h" #include "third_party/musl/tempnam.h" diff --git a/third_party/ctags/ctags.mk b/third_party/ctags/ctags.mk index a11107496..488b6a580 100644 --- a/third_party/ctags/ctags.mk +++ b/third_party/ctags/ctags.mk @@ -22,7 +22,6 @@ THIRD_PARTY_CTAGS_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ THIRD_PARTY_MUSL \ THIRD_PARTY_REGEX diff --git a/third_party/ctags/eiffel.c b/third_party/ctags/eiffel.c index b4347a4a5..5ef5413f4 100644 --- a/third_party/ctags/eiffel.c +++ b/third_party/ctags/eiffel.c @@ -22,7 +22,6 @@ #include "libc/stdio/dprintf.h" #include "libc/calls/weirdtypes.h" #include "libc/fmt/fmt.h" -#include "libc/mem/fmt.h" #include "libc/stdio/stdio.h" #include "libc/stdio/temp.h" #include "third_party/musl/tempnam.h" diff --git a/third_party/ctags/entry.h b/third_party/ctags/entry.h index 2dbf20980..fb84400db 100644 --- a/third_party/ctags/entry.h +++ b/third_party/ctags/entry.h @@ -21,7 +21,6 @@ #include "libc/stdio/dprintf.h" #include "libc/calls/weirdtypes.h" #include "libc/fmt/fmt.h" -#include "libc/mem/fmt.h" #include "libc/stdio/stdio.h" #include "libc/stdio/temp.h" #include "third_party/musl/tempnam.h" diff --git a/third_party/ctags/flex.c b/third_party/ctags/flex.c index f37f99e69..b98b035d6 100644 --- a/third_party/ctags/flex.c +++ b/third_party/ctags/flex.c @@ -28,7 +28,6 @@ #include "libc/stdio/dprintf.h" #include "libc/calls/weirdtypes.h" #include "libc/fmt/fmt.h" -#include "libc/mem/fmt.h" #include "libc/stdio/stdio.h" #include "libc/stdio/temp.h" #include "third_party/musl/tempnam.h" diff --git a/third_party/ctags/jscript.c b/third_party/ctags/jscript.c index 9878c963f..b2becf75f 100644 --- a/third_party/ctags/jscript.c +++ b/third_party/ctags/jscript.c @@ -27,7 +27,6 @@ #include "libc/stdio/dprintf.h" #include "libc/calls/weirdtypes.h" #include "libc/fmt/fmt.h" -#include "libc/mem/fmt.h" #include "libc/stdio/stdio.h" #include "libc/stdio/temp.h" #include "third_party/musl/tempnam.h" diff --git a/third_party/ctags/main.h b/third_party/ctags/main.h index 0b2bb7f50..a814bb358 100644 --- a/third_party/ctags/main.h +++ b/third_party/ctags/main.h @@ -21,7 +21,6 @@ #include "libc/stdio/dprintf.h" #include "libc/calls/weirdtypes.h" #include "libc/fmt/fmt.h" -#include "libc/mem/fmt.h" #include "libc/stdio/stdio.h" #include "libc/stdio/temp.h" #include "third_party/musl/tempnam.h" diff --git a/third_party/ctags/options.c b/third_party/ctags/options.c index fdefd60f3..04bb5fb88 100644 --- a/third_party/ctags/options.c +++ b/third_party/ctags/options.c @@ -37,7 +37,6 @@ #include "libc/stdio/dprintf.h" #include "libc/calls/weirdtypes.h" #include "libc/fmt/fmt.h" -#include "libc/mem/fmt.h" #include "libc/stdio/stdio.h" #include "libc/stdio/temp.h" #include "third_party/musl/tempnam.h" diff --git a/third_party/ctags/read.h b/third_party/ctags/read.h index d9de83c5d..e6729b0b7 100644 --- a/third_party/ctags/read.h +++ b/third_party/ctags/read.h @@ -27,7 +27,6 @@ #include "libc/stdio/dprintf.h" #include "libc/calls/weirdtypes.h" #include "libc/fmt/fmt.h" -#include "libc/mem/fmt.h" #include "libc/stdio/stdio.h" #include "libc/stdio/temp.h" #include "third_party/musl/tempnam.h" diff --git a/third_party/ctags/sort.c b/third_party/ctags/sort.c index ad28db151..6b1b2e039 100644 --- a/third_party/ctags/sort.c +++ b/third_party/ctags/sort.c @@ -40,7 +40,6 @@ #include "libc/stdio/dprintf.h" #include "libc/calls/weirdtypes.h" #include "libc/fmt/fmt.h" -#include "libc/mem/fmt.h" #include "libc/stdio/stdio.h" #include "libc/stdio/temp.h" #include "third_party/musl/tempnam.h" diff --git a/third_party/ctags/sql.c b/third_party/ctags/sql.c index 1f69f0c3e..5f719b960 100644 --- a/third_party/ctags/sql.c +++ b/third_party/ctags/sql.c @@ -23,7 +23,6 @@ #include "libc/stdio/dprintf.h" #include "libc/calls/weirdtypes.h" #include "libc/fmt/fmt.h" -#include "libc/mem/fmt.h" #include "libc/stdio/stdio.h" #include "libc/stdio/temp.h" #include "third_party/musl/tempnam.h" diff --git a/third_party/ctags/tex.c b/third_party/ctags/tex.c index e67f3f6cd..801032dbe 100644 --- a/third_party/ctags/tex.c +++ b/third_party/ctags/tex.c @@ -24,7 +24,6 @@ #include "libc/stdio/dprintf.h" #include "libc/calls/weirdtypes.h" #include "libc/fmt/fmt.h" -#include "libc/mem/fmt.h" #include "libc/stdio/stdio.h" #include "libc/stdio/temp.h" #include "third_party/musl/tempnam.h" diff --git a/third_party/ctags/vim.c b/third_party/ctags/vim.c index 989d8e91c..69e1e48b0 100644 --- a/third_party/ctags/vim.c +++ b/third_party/ctags/vim.c @@ -26,7 +26,6 @@ #include "libc/stdio/dprintf.h" #include "libc/calls/weirdtypes.h" #include "libc/fmt/fmt.h" -#include "libc/mem/fmt.h" #include "libc/stdio/stdio.h" #include "libc/stdio/temp.h" #include "third_party/musl/tempnam.h" diff --git a/third_party/dlmalloc/dlmalloc.mk b/third_party/dlmalloc/dlmalloc.mk index 39c5c58a6..514b9edd5 100644 --- a/third_party/dlmalloc/dlmalloc.mk +++ b/third_party/dlmalloc/dlmalloc.mk @@ -23,7 +23,6 @@ THIRD_PARTY_DLMALLOC_A_DIRECTDEPS = \ LIBC_NEXGEN32E \ LIBC_RUNTIME \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_SYSV_CALLS \ THIRD_PARTY_COMPILER_RT \ diff --git a/third_party/finger/finger.mk b/third_party/finger/finger.mk index f29c90a0d..48eee3658 100644 --- a/third_party/finger/finger.mk +++ b/third_party/finger/finger.mk @@ -21,7 +21,6 @@ THIRD_PARTY_FINGER_A_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_DNS \ LIBC_SOCK \ diff --git a/third_party/gdtoa/gdtoa.mk b/third_party/gdtoa/gdtoa.mk index 4aeb3bf3c..5e6d34a3f 100644 --- a/third_party/gdtoa/gdtoa.mk +++ b/third_party/gdtoa/gdtoa.mk @@ -22,7 +22,6 @@ THIRD_PARTY_GDTOA_A_DIRECTDEPS = \ LIBC_NEXGEN32E \ LIBC_RUNTIME \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_TINYMATH diff --git a/third_party/getopt/getopt.mk b/third_party/getopt/getopt.mk index 89b5c3476..5b387bb32 100644 --- a/third_party/getopt/getopt.mk +++ b/third_party/getopt/getopt.mk @@ -19,8 +19,7 @@ THIRD_PARTY_GETOPT_A_DIRECTDEPS = \ LIBC_CALLS \ LIBC_INTRIN \ LIBC_NEXGEN32E \ - LIBC_STR \ - LIBC_STUBS + LIBC_STR THIRD_PARTY_GETOPT_A_DEPS := \ $(call uniq,$(foreach x,$(THIRD_PARTY_GETOPT_A_DIRECTDEPS),$($(x)))) diff --git a/third_party/ggml/ggml.mk b/third_party/ggml/ggml.mk index d19eeb079..47f2bd53b 100644 --- a/third_party/ggml/ggml.mk +++ b/third_party/ggml/ggml.mk @@ -63,7 +63,6 @@ THIRD_PARTY_GGML_A_DIRECTDEPS = \ LIBC_STDIO \ LIBC_THREAD \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_TINYMATH \ THIRD_PARTY_COMPILER_RT @@ -133,7 +132,6 @@ THIRD_PARTY_GGML_LLAMA_DIRECTDEPS = \ LIBC_STDIO \ LIBC_LOG \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_SYSV_CALLS \ LIBC_THREAD \ diff --git a/third_party/hiredis/hiredis.mk b/third_party/hiredis/hiredis.mk index e50312059..58e4517af 100644 --- a/third_party/hiredis/hiredis.mk +++ b/third_party/hiredis/hiredis.mk @@ -25,7 +25,6 @@ THIRD_PARTY_HIREDIS_A_DIRECTDEPS = \ LIBC_SOCK \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_TIME \ LIBC_X \ diff --git a/third_party/hiredis/net.c b/third_party/hiredis/net.c index dbd828717..4517c2116 100644 --- a/third_party/hiredis/net.c +++ b/third_party/hiredis/net.c @@ -69,7 +69,6 @@ #include "libc/stdio/dprintf.h" #include "libc/calls/weirdtypes.h" #include "libc/fmt/fmt.h" -#include "libc/mem/fmt.h" #include "libc/stdio/stdio.h" #include "libc/stdio/temp.h" #include "third_party/musl/tempnam.h" diff --git a/third_party/hiredis/read.h b/third_party/hiredis/read.h index b0fb0d143..e9c6bb4a2 100644 --- a/third_party/hiredis/read.h +++ b/third_party/hiredis/read.h @@ -37,7 +37,6 @@ #include "libc/stdio/dprintf.h" #include "libc/calls/weirdtypes.h" #include "libc/fmt/fmt.h" -#include "libc/mem/fmt.h" #include "libc/stdio/stdio.h" #include "libc/stdio/temp.h" #include "third_party/musl/tempnam.h" /* for size_t */ diff --git a/third_party/hiredis/sds.c b/third_party/hiredis/sds.c index 76bc8a6f2..9b4c0b335 100644 --- a/third_party/hiredis/sds.c +++ b/third_party/hiredis/sds.c @@ -35,7 +35,6 @@ #include "libc/stdio/dprintf.h" #include "libc/calls/weirdtypes.h" #include "libc/fmt/fmt.h" -#include "libc/mem/fmt.h" #include "libc/stdio/stdio.h" #include "libc/stdio/temp.h" #include "third_party/musl/tempnam.h" @@ -1148,7 +1147,6 @@ void sds_free(void *ptr) { s_free(ptr); } #include "libc/stdio/dprintf.h" #include "libc/calls/weirdtypes.h" #include "libc/fmt/fmt.h" -#include "libc/mem/fmt.h" #include "libc/stdio/stdio.h" #include "libc/stdio/temp.h" #include "third_party/musl/tempnam.h" diff --git a/third_party/libcxx/__bsd_locale_fallbacks.h b/third_party/libcxx/__bsd_locale_fallbacks.h index 469981afd..6faca54bb 100644 --- a/third_party/libcxx/__bsd_locale_fallbacks.h +++ b/third_party/libcxx/__bsd_locale_fallbacks.h @@ -14,7 +14,6 @@ #define _LIBCPP_BSD_LOCALE_FALLBACKS_DEFAULTS_H #include "third_party/libcxx/stdlib.h" -#include "libc/mem/fmt.h" #include "libc/str/unicode.h" #include "libc/fmt/fmt.h" #include "libc/str/locale.h" diff --git a/third_party/libcxx/ctime b/third_party/libcxx/ctime index 086ee2b47..31df2a5af 100644 --- a/third_party/libcxx/ctime +++ b/third_party/libcxx/ctime @@ -12,6 +12,7 @@ #include "third_party/libcxx/__config" #include "libc/calls/weirdtypes.h" +#include "libc/calls/calls.h" #include "libc/isystem/time.h" #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/third_party/libcxx/libcxx.mk b/third_party/libcxx/libcxx.mk index 4820b23c9..0df78731c 100644 --- a/third_party/libcxx/libcxx.mk +++ b/third_party/libcxx/libcxx.mk @@ -189,7 +189,6 @@ THIRD_PARTY_LIBCXX_A_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_TIME \ LIBC_THREAD \ diff --git a/third_party/linenoise/linenoise.mk b/third_party/linenoise/linenoise.mk index 1f0750e0c..aafe2695a 100644 --- a/third_party/linenoise/linenoise.mk +++ b/third_party/linenoise/linenoise.mk @@ -28,7 +28,6 @@ THIRD_PARTY_LINENOISE_A_DIRECTDEPS = \ LIBC_LOG \ LIBC_SYSV_CALLS \ LIBC_STR \ - LIBC_STUBS \ NET_HTTP THIRD_PARTY_LINENOISE_A_DEPS := \ diff --git a/third_party/lua/lmathlib.c b/third_party/lua/lmathlib.c index 9e0ee7305..59e4bb51b 100644 --- a/third_party/lua/lmathlib.c +++ b/third_party/lua/lmathlib.c @@ -27,9 +27,9 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #define lmathlib_c #define LUA_LIB +#include "libc/calls/calls.h" #include "libc/math.h" #include "libc/nt/struct/msg.h" -#include "libc/time/time.h" #include "third_party/lua/lauxlib.h" #include "third_party/lua/lprefix.h" #include "third_party/lua/lua.h" diff --git a/third_party/lua/ltablib.c b/third_party/lua/ltablib.c index ab55093ef..4ed8f478e 100644 --- a/third_party/lua/ltablib.c +++ b/third_party/lua/ltablib.c @@ -27,9 +27,9 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #define ltablib_c #define LUA_LIB +#include "libc/calls/calls.h" #include "libc/calls/weirdtypes.h" #include "libc/str/str.h" -#include "libc/time/time.h" #include "third_party/lua/lauxlib.h" #include "third_party/lua/lprefix.h" #include "third_party/lua/lua.h" diff --git a/third_party/lua/lua.mk b/third_party/lua/lua.mk index f17ad4e89..73da76bea 100644 --- a/third_party/lua/lua.mk +++ b/third_party/lua/lua.mk @@ -194,7 +194,6 @@ THIRD_PARTY_LUA_UNIX_DIRECTDEPS = \ LIBC_SOCK \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_THREAD \ LIBC_TIME \ diff --git a/third_party/lua/lunix.c b/third_party/lua/lunix.c index 0bf99673d..4484325ee 100644 --- a/third_party/lua/lunix.c +++ b/third_party/lua/lunix.c @@ -52,7 +52,6 @@ #include "libc/limits.h" #include "libc/log/log.h" #include "libc/macros.internal.h" -#include "libc/mem/fmt.h" #include "libc/mem/mem.h" #include "libc/nt/runtime.h" #include "libc/nt/synchronization.h" diff --git a/third_party/maxmind/maxmind.mk b/third_party/maxmind/maxmind.mk index 31cc33521..c53e18c05 100644 --- a/third_party/maxmind/maxmind.mk +++ b/third_party/maxmind/maxmind.mk @@ -26,7 +26,6 @@ THIRD_PARTY_MAXMIND_A_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV THIRD_PARTY_MAXMIND_A_DEPS := \ diff --git a/third_party/mbedtls/platform.h b/third_party/mbedtls/platform.h index c16bcc432..11d426046 100644 --- a/third_party/mbedtls/platform.h +++ b/third_party/mbedtls/platform.h @@ -1,6 +1,7 @@ #ifndef COSMOPOLITAN_THIRD_PARTY_MBEDTLS_PLATFORM_H_ #define COSMOPOLITAN_THIRD_PARTY_MBEDTLS_PLATFORM_H_ #include "libc/assert.h" +#include "libc/calls/calls.h" #include "libc/fmt/fmt.h" #include "libc/intrin/likely.h" #include "libc/mem/mem.h" diff --git a/third_party/musl/musl.mk b/third_party/musl/musl.mk index 2bd943f16..d8e1a47f2 100644 --- a/third_party/musl/musl.mk +++ b/third_party/musl/musl.mk @@ -25,7 +25,6 @@ THIRD_PARTY_MUSL_A_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV THIRD_PARTY_MUSL_A_DEPS := \ diff --git a/third_party/nsync/mem/mem.mk b/third_party/nsync/mem/mem.mk index 922fe9414..fa0f19cab 100644 --- a/third_party/nsync/mem/mem.mk +++ b/third_party/nsync/mem/mem.mk @@ -19,7 +19,6 @@ THIRD_PARTY_NSYNC_MEM_A_DIRECTDEPS = \ LIBC_INTRIN \ LIBC_NEXGEN32E \ LIBC_MEM \ - LIBC_STUBS \ LIBC_SYSV \ THIRD_PARTY_NSYNC diff --git a/third_party/nsync/nsync.mk b/third_party/nsync/nsync.mk index 64a92f4aa..ccb17bff2 100644 --- a/third_party/nsync/nsync.mk +++ b/third_party/nsync/nsync.mk @@ -29,7 +29,6 @@ THIRD_PARTY_NSYNC_A_DIRECTDEPS = \ LIBC_NT_KERNEL32 \ LIBC_NT_SYNCHRONIZATION \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_SYSV_CALLS diff --git a/third_party/nsync/testing/testing.mk b/third_party/nsync/testing/testing.mk index f215b838b..ae041b869 100644 --- a/third_party/nsync/testing/testing.mk +++ b/third_party/nsync/testing/testing.mk @@ -25,7 +25,6 @@ THIRD_PARTY_NSYNC_TESTING_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_THREAD \ THIRD_PARTY_NSYNC \ diff --git a/third_party/puff/puff.mk b/third_party/puff/puff.mk index e5f660cdf..0fd58c8a3 100644 --- a/third_party/puff/puff.mk +++ b/third_party/puff/puff.mk @@ -19,8 +19,7 @@ THIRD_PARTY_PUFF_A_CHECKS = \ THIRD_PARTY_PUFF_A_DIRECTDEPS = \ LIBC_INTRIN \ - LIBC_NEXGEN32E \ - LIBC_STUBS + LIBC_NEXGEN32E THIRD_PARTY_PUFF_A_DEPS := \ $(call uniq,$(foreach x,$(THIRD_PARTY_PUFF_A_DIRECTDEPS),$($(x)))) diff --git a/third_party/python/python.mk b/third_party/python/python.mk index dfc90302b..e143bf93d 100644 --- a/third_party/python/python.mk +++ b/third_party/python/python.mk @@ -460,7 +460,6 @@ THIRD_PARTY_PYTHON_STAGE1_A_DIRECTDEPS = \ LIBC_THREAD \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_SYSV_CALLS \ LIBC_TIME \ @@ -1171,7 +1170,6 @@ THIRD_PARTY_PYTHON_STAGE2_A_DIRECTDEPS = \ LIBC_SOCK \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_SYSV_CALLS \ LIBC_TIME \ @@ -3998,7 +3996,6 @@ THIRD_PARTY_PYTHON_PYTHON_DIRECTDEPS = \ LIBC_STDIO \ LIBC_MEM \ LIBC_STR \ - LIBC_STUBS \ LIBC_LOG \ LIBC_SYSV \ LIBC_X \ @@ -4050,7 +4047,6 @@ THIRD_PARTY_PYTHON_FREEZE_DIRECTDEPS = \ LIBC_MEM \ LIBC_STR \ LIBC_LOG \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_X \ THIRD_PARTY_GETOPT \ diff --git a/third_party/quickjs/qjs.c b/third_party/quickjs/qjs.c index 75ae383ed..9f265a9b4 100644 --- a/third_party/quickjs/qjs.c +++ b/third_party/quickjs/qjs.c @@ -23,6 +23,7 @@ * THE SOFTWARE. */ #include "libc/assert.h" +#include "libc/calls/calls.h" #include "libc/calls/weirdtypes.h" #include "libc/dce.h" #include "libc/fmt/conv.h" @@ -32,7 +33,6 @@ #include "libc/runtime/stack.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" -#include "libc/time/time.h" #include "third_party/quickjs/cutils.h" #include "third_party/quickjs/quickjs-libc.h" #include "tool/args/args.h" diff --git a/third_party/quickjs/run-test262.c b/third_party/quickjs/run-test262.c index af5292f79..f187a9f67 100644 --- a/third_party/quickjs/run-test262.c +++ b/third_party/quickjs/run-test262.c @@ -22,6 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/calls/weirdtypes.h" #include "libc/fmt/conv.h" @@ -32,7 +33,6 @@ #include "libc/runtime/runtime.h" #include "libc/str/str.h" #include "libc/sysv/consts/clock.h" -#include "libc/time/time.h" #include "third_party/musl/ftw.h" #include "third_party/quickjs/cutils.h" #include "third_party/quickjs/list.h" diff --git a/third_party/radpajama/radpajama.mk b/third_party/radpajama/radpajama.mk index e4a103ef0..72beb6803 100644 --- a/third_party/radpajama/radpajama.mk +++ b/third_party/radpajama/radpajama.mk @@ -31,7 +31,6 @@ THIRD_PARTY_RADPAJAMA_A_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_THREAD \ LIBC_TINYMATH \ @@ -84,7 +83,6 @@ THIRD_PARTY_RADPAJAMA_MAIN_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ THIRD_PARTY_GGML \ THIRD_PARTY_RADPAJAMA \ THIRD_PARTY_LIBCXX diff --git a/third_party/regex/regex.mk b/third_party/regex/regex.mk index df2a41cb2..58012049f 100644 --- a/third_party/regex/regex.mk +++ b/third_party/regex/regex.mk @@ -20,8 +20,7 @@ THIRD_PARTY_REGEX_A_DIRECTDEPS = \ LIBC_MEM \ LIBC_NEXGEN32E \ LIBC_RUNTIME \ - LIBC_STR \ - LIBC_STUBS + LIBC_STR THIRD_PARTY_REGEX_A_DEPS := \ $(call uniq,$(foreach x,$(THIRD_PARTY_REGEX_A_DIRECTDEPS),$($(x)))) diff --git a/third_party/sed/sed.mk b/third_party/sed/sed.mk index ca60a196b..463e63a9d 100644 --- a/third_party/sed/sed.mk +++ b/third_party/sed/sed.mk @@ -22,7 +22,6 @@ THIRD_PARTY_SED_A_DIRECTDEPS = \ LIBC_SYSV \ LIBC_STR \ LIBC_LOG \ - LIBC_STUBS \ THIRD_PARTY_GETOPT \ THIRD_PARTY_REGEX diff --git a/third_party/smallz4/smallz4.mk b/third_party/smallz4/smallz4.mk index dd1e4b326..b90af5543 100644 --- a/third_party/smallz4/smallz4.mk +++ b/third_party/smallz4/smallz4.mk @@ -36,7 +36,6 @@ THIRD_PARTY_SMALLZ4_A_DIRECTDEPS = \ LIBC_CALLS \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ THIRD_PARTY_LIBCXX THIRD_PARTY_SMALLZ4_A_DEPS := \ diff --git a/third_party/sqlite3/sqlite3.mk b/third_party/sqlite3/sqlite3.mk index 9b433a33d..32933d4b0 100644 --- a/third_party/sqlite3/sqlite3.mk +++ b/third_party/sqlite3/sqlite3.mk @@ -51,7 +51,6 @@ THIRD_PARTY_SQLITE3_A_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_SYSV_CALLS \ LIBC_THREAD \ diff --git a/third_party/stb/stb.mk b/third_party/stb/stb.mk index 0476593bc..c7352949f 100644 --- a/third_party/stb/stb.mk +++ b/third_party/stb/stb.mk @@ -34,7 +34,6 @@ THIRD_PARTY_STB_A_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_TINYMATH \ LIBC_X \ THIRD_PARTY_ZLIB diff --git a/third_party/tidy/tidy.mk b/third_party/tidy/tidy.mk index 5e47a4c12..be02bf258 100644 --- a/third_party/tidy/tidy.mk +++ b/third_party/tidy/tidy.mk @@ -26,8 +26,7 @@ THIRD_PARTY_TIDY_A_DIRECTDEPS = \ LIBC_CALLS \ LIBC_STDIO \ LIBC_SYSV \ - LIBC_STR \ - LIBC_STUBS + LIBC_STR THIRD_PARTY_TIDY_A_DEPS := \ $(call uniq,$(foreach x,$(THIRD_PARTY_TIDY_A_DIRECTDEPS),$($(x)))) diff --git a/third_party/tr/tr.mk b/third_party/tr/tr.mk index 5d1c4d8b7..bbd0f27bb 100644 --- a/third_party/tr/tr.mk +++ b/third_party/tr/tr.mk @@ -22,7 +22,6 @@ THIRD_PARTY_TR_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ THIRD_PARTY_GETOPT THIRD_PARTY_TR_DEPS := \ diff --git a/third_party/unzip/unzip.mk b/third_party/unzip/unzip.mk index ca5938ae8..0730153eb 100644 --- a/third_party/unzip/unzip.mk +++ b/third_party/unzip/unzip.mk @@ -22,7 +22,6 @@ THIRD_PARTY_UNZIP_A_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_TIME \ LIBC_ZIPOS \ diff --git a/third_party/vqsort/vqsort.mk b/third_party/vqsort/vqsort.mk index ca1f785ff..499de4bd5 100644 --- a/third_party/vqsort/vqsort.mk +++ b/third_party/vqsort/vqsort.mk @@ -26,7 +26,6 @@ THIRD_PARTY_VQSORT_A_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ THIRD_PARTY_COMPILER_RT THIRD_PARTY_VQSORT_A_DEPS := \ diff --git a/third_party/xed/xed.mk b/third_party/xed/xed.mk index c94ccfb89..4339a57b0 100644 --- a/third_party/xed/xed.mk +++ b/third_party/xed/xed.mk @@ -26,8 +26,7 @@ THIRD_PARTY_XED_A_CHECKS = \ THIRD_PARTY_XED_A_DIRECTDEPS = \ LIBC_INTRIN \ LIBC_NEXGEN32E \ - LIBC_STR \ - LIBC_STUBS + LIBC_STR THIRD_PARTY_XED_A_DEPS := \ $(call uniq,$(foreach x,$(THIRD_PARTY_XED_A_DIRECTDEPS),$($(x)))) diff --git a/third_party/zip/tailor.h b/third_party/zip/tailor.h index ab5cef02a..84d49db92 100644 --- a/third_party/zip/tailor.h +++ b/third_party/zip/tailor.h @@ -224,7 +224,6 @@ #include "libc/stdio/dprintf.h" #include "libc/calls/weirdtypes.h" #include "libc/fmt/fmt.h" -#include "libc/mem/fmt.h" #include "libc/stdio/stdio.h" #include "libc/stdio/temp.h" #include "third_party/musl/tempnam.h" diff --git a/third_party/zip/zip.c b/third_party/zip/zip.c index f493d6879..4b2b33ee1 100644 --- a/third_party/zip/zip.c +++ b/third_party/zip/zip.c @@ -88,7 +88,6 @@ #include "libc/stdio/dprintf.h" #include "libc/calls/weirdtypes.h" #include "libc/fmt/fmt.h" -#include "libc/mem/fmt.h" #include "libc/stdio/stdio.h" #include "libc/stdio/temp.h" #include "third_party/musl/tempnam.h" diff --git a/third_party/zip/zip.mk b/third_party/zip/zip.mk index 9c93befd4..bc92a2532 100644 --- a/third_party/zip/zip.mk +++ b/third_party/zip/zip.mk @@ -88,7 +88,6 @@ THIRD_PARTY_ZIP_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_TIME \ LIBC_X \ diff --git a/third_party/zlib/deflate.c b/third_party/zlib/deflate.c index ec434a97d..06a467b3c 100644 --- a/third_party/zlib/deflate.c +++ b/third_party/zlib/deflate.c @@ -957,10 +957,10 @@ int ZEXPORT deflate(strm, flush) (s->gzhead->name == Z_NULL ? 0 : 8) + (s->gzhead->comment == Z_NULL ? 0 : 16) ); - put_byte(s, (Byte)(s->gzhead->time & 0xff)); - put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff)); - put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff)); - put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff)); + put_byte(s, (Byte)(s->gzhead->time_ & 0xff)); + put_byte(s, (Byte)((s->gzhead->time_ >> 8) & 0xff)); + put_byte(s, (Byte)((s->gzhead->time_ >> 16) & 0xff)); + put_byte(s, (Byte)((s->gzhead->time_ >> 24) & 0xff)); put_byte(s, s->level == 9 ? 2 : (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? 4 : 0)); diff --git a/third_party/zlib/gz/gz.mk b/third_party/zlib/gz/gz.mk index e14b08480..383f2f396 100644 --- a/third_party/zlib/gz/gz.mk +++ b/third_party/zlib/gz/gz.mk @@ -24,7 +24,6 @@ THIRD_PARTY_ZLIB_GZ_A_DIRECTDEPS = \ LIBC_NEXGEN32E \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ THIRD_PARTY_ZLIB diff --git a/third_party/zlib/inflate.c b/third_party/zlib/inflate.c index f267b42c5..1bd98f9e5 100644 --- a/third_party/zlib/inflate.c +++ b/third_party/zlib/inflate.c @@ -331,7 +331,6 @@ struct inflate_state FAR *state; #include "libc/stdio/dprintf.h" #include "libc/calls/weirdtypes.h" #include "libc/fmt/fmt.h" -#include "libc/mem/fmt.h" #include "libc/stdio/stdio.h" #include "libc/stdio/temp.h" #include "third_party/musl/tempnam.h" @@ -751,7 +750,7 @@ int flush; case TIME: NEEDBITS(32); if (state->head != Z_NULL) - state->head->time = hold; + state->head->time_ = hold; if ((state->flags & 0x0200) && (state->wrap & 4)) CRC4(state->check, hold); INITBITS(); diff --git a/third_party/zlib/trees.c b/third_party/zlib/trees.c index ed8c45e45..cd87304d3 100644 --- a/third_party/zlib/trees.c +++ b/third_party/zlib/trees.c @@ -8,7 +8,6 @@ */ #include "libc/calls/calls.h" #include "libc/fmt/fmt.h" -#include "libc/mem/fmt.h" #include "libc/stdio/lock.internal.h" #include "libc/stdio/stdio.h" #include "libc/stdio/temp.h" diff --git a/third_party/zlib/zlib.h b/third_party/zlib/zlib.h index 39268182d..41489f0f9 100644 --- a/third_party/zlib/zlib.h +++ b/third_party/zlib/zlib.h @@ -171,7 +171,7 @@ typedef z_stream *z_streamp; */ typedef struct gz_header_s { int text; /* true if compressed data believed to be text */ - uLong time; /* modification time */ + uLong time_; /* modification time */ int xflags; /* extra flags (not used when writing a gzip file) */ int os; /* operating system */ Bytef *extra; /* pointer to extra field or Z_NULL if none */ diff --git a/third_party/zlib/zlib.mk b/third_party/zlib/zlib.mk index 005f7bc96..c6e19c1b3 100644 --- a/third_party/zlib/zlib.mk +++ b/third_party/zlib/zlib.mk @@ -19,9 +19,8 @@ THIRD_PARTY_ZLIB_A_CHECKS = \ THIRD_PARTY_ZLIB_A_DIRECTDEPS = \ LIBC_INTRIN \ LIBC_NEXGEN32E \ - LIBC_SYSV \ LIBC_STR \ - LIBC_STUBS + LIBC_SYSV THIRD_PARTY_ZLIB_A_DEPS := \ $(call uniq,$(foreach x,$(THIRD_PARTY_ZLIB_A_DIRECTDEPS),$($(x)))) diff --git a/tool/args/args.mk b/tool/args/args.mk index 03618a287..e64398df0 100644 --- a/tool/args/args.mk +++ b/tool/args/args.mk @@ -20,7 +20,6 @@ TOOL_ARGS_A_DIRECTDEPS = \ LIBC_MEM \ LIBC_NEXGEN32E \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_X \ LIBC_ZIPOS diff --git a/tool/build/ar.c b/tool/build/ar.c index 40c9a3f1d..6db33b3fa 100644 --- a/tool/build/ar.c +++ b/tool/build/ar.c @@ -20,6 +20,7 @@ #include "libc/calls/calls.h" #include "libc/calls/struct/iovec.h" #include "libc/calls/struct/stat.h" +#include "libc/elf/def.h" #include "libc/elf/elf.h" #include "libc/errno.h" #include "libc/fmt/conv.h" @@ -247,8 +248,9 @@ int main(int argc, char *argv[]) { CHECK_NE(MAP_FAILED, (elf = mmap(0, st->st_size, PROT_READ, MAP_PRIVATE, fd, 0))); CHECK(IsElf64Binary(elf, st->st_size), "%s", arg); - CHECK_NOTNULL((strs = GetElfStringTable(elf, st->st_size))); - CHECK_NOTNULL((syms = GetElfSymbolTable(elf, st->st_size, &symcount))); + CHECK_NOTNULL((strs = GetElfStringTable(elf, st->st_size, ".strtab"))); + CHECK_NOTNULL( + (syms = GetElfSymbolTable(elf, st->st_size, SHT_SYMTAB, &symcount))); for (j = 0; j < symcount; ++j) { if (syms[j].st_shndx == SHN_UNDEF) continue; if (syms[j].st_other == STV_INTERNAL) continue; diff --git a/tool/build/build.mk b/tool/build/build.mk index 7af5ae4f5..21b5f0110 100644 --- a/tool/build/build.mk +++ b/tool/build/build.mk @@ -53,7 +53,6 @@ TOOL_BUILD_DIRECTDEPS = \ LIBC_SOCK \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_SYSV_CALLS \ LIBC_THREAD \ diff --git a/tool/build/fixupobj.c b/tool/build/fixupobj.c index 5240c70a4..e9bb2221d 100644 --- a/tool/build/fixupobj.c +++ b/tool/build/fixupobj.c @@ -350,13 +350,13 @@ static void FixupObject(void) { if (!IsElf64Binary(elf, esize)) { Die("not an elf64 binary"); } - if (!(syms = GetElfSymbolTable(elf, esize, &symcount))) { + if (!(syms = GetElfSymbolTable(elf, esize, SHT_SYMTAB, &symcount))) { Die("missing elf symbol table"); } if (!(secstrs = GetElfSectionNameStringTable(elf, esize))) { Die("missing elf section string table"); } - if (!(symstrs = GetElfStringTable(elf, esize))) { + if (!(symstrs = GetElfStringTable(elf, esize, ".strtab"))) { Die("missing elf symbol string table"); } CheckPrivilegedCrossReferences(); diff --git a/tool/build/lib/buffer.c b/tool/build/lib/buffer.c index 06bb45ffd..92c19874c 100644 --- a/tool/build/lib/buffer.c +++ b/tool/build/lib/buffer.c @@ -16,16 +16,15 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "tool/build/lib/buffer.h" #include "libc/calls/calls.h" #include "libc/errno.h" #include "libc/fmt/fmt.h" #include "libc/intrin/tpenc.h" #include "libc/macros.internal.h" #include "libc/mem/arraylist2.internal.h" -#include "libc/mem/fmt.h" #include "libc/mem/mem.h" #include "libc/str/str.h" -#include "tool/build/lib/buffer.h" /* TODO(jart): replace with new append*() library */ diff --git a/tool/build/lib/buildlib.mk b/tool/build/lib/buildlib.mk index 07ff037a1..02bece42c 100644 --- a/tool/build/lib/buildlib.mk +++ b/tool/build/lib/buildlib.mk @@ -33,7 +33,6 @@ TOOL_BUILD_LIB_A_OBJS = \ TOOL_BUILD_LIB_A_DIRECTDEPS = \ LIBC_CALLS \ - LIBC_ELF \ LIBC_FMT \ LIBC_INTRIN \ LIBC_LOG \ @@ -43,7 +42,6 @@ TOOL_BUILD_LIB_A_DIRECTDEPS = \ LIBC_SOCK \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_SYSV_CALLS \ LIBC_TIME \ @@ -109,6 +107,8 @@ TOOL_BUILD_LIB_CHECKS = $(foreach x,$(TOOL_BUILD_LIB_ARTIFACTS),$($(x)_CHECKS)) TOOL_BUILD_LIB_OBJS = $(foreach x,$(TOOL_BUILD_LIB_ARTIFACTS),$($(x)_OBJS)) TOOL_BUILD_LIB_TESTS = $(foreach x,$(TOOL_BUILD_LIB_ARTIFACTS),$($(x)_TESTS)) +$(TOOL_BUILD_LIB_OBJS): tool/build/lib/buildlib.mk + .PHONY: o/$(MODE)/tool/build/lib o/$(MODE)/tool/build/lib: \ $(TOOL_BUILD_LIB_COMS) \ diff --git a/tool/build/package.c b/tool/build/package.c index f89f11a42..80e0a22f0 100644 --- a/tool/build/package.c +++ b/tool/build/package.c @@ -526,10 +526,11 @@ static void OpenObject(struct Package *pkg, struct Object *obj, int oid) { if (!IsElf64Binary(obj->elf, obj->size)) { Die(path, "not an elf64 binary"); } - if (!(obj->strs = GetElfStringTable(obj->elf, obj->size))) { + if (!(obj->strs = GetElfStringTable(obj->elf, obj->size, ".strtab"))) { Die(path, "missing elf string table"); } - if (!(obj->syms = GetElfSymbolTable(obj->elf, obj->size, &obj->symcount))) { + if (!(obj->syms = GetElfSymbolTable(obj->elf, obj->size, SHT_SYMTAB, + &obj->symcount))) { Die(path, "missing elf symbol table"); } IndexSections(pkg, obj); diff --git a/tool/curl/curl.mk b/tool/curl/curl.mk index a65b6c4ce..a0b73e953 100644 --- a/tool/curl/curl.mk +++ b/tool/curl/curl.mk @@ -24,7 +24,6 @@ TOOL_CURL_DIRECTDEPS = \ LIBC_SOCK \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_TIME \ LIBC_X \ diff --git a/tool/decode/decode.mk b/tool/decode/decode.mk index 14628ef53..e5430164a 100644 --- a/tool/decode/decode.mk +++ b/tool/decode/decode.mk @@ -31,7 +31,6 @@ TOOL_DECODE_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_SYSV_CALLS \ LIBC_TIME \ diff --git a/tool/decode/elf.c b/tool/decode/elf.c index a2790c2dc..3909dcd95 100644 --- a/tool/decode/elf.c +++ b/tool/decode/elf.c @@ -104,9 +104,9 @@ static void printelfehdr(void) { } static void printelfsegmentheader(int i) { - Elf64_Phdr *phdr = GetElfSegmentHeaderAddress(elf, st->st_size, i); + Elf64_Phdr *phdr = GetElfProgramHeaderAddress(elf, st->st_size, i); if (!phdr) return; - printf("/\tElf64_Phdr *phdr = GetElfSegmentHeaderAddress(elf, st->st_size, " + printf("/\tElf64_Phdr *phdr = GetElfProgramHeaderAddress(elf, st->st_size, " "%d)\n", i); printf(".Lph%d:", i); @@ -272,9 +272,10 @@ static void printelfsymbol(Elf64_Sym *sym, char *strtab, char *shstrtab) { static void printelfsymboltable(void) { size_t i, symcount = 0; - Elf64_Sym *symtab = GetElfSymbolTable(elf, st->st_size, &symcount); + Elf64_Sym *symtab = + GetElfSymbolTable(elf, st->st_size, SHT_SYMTAB, &symcount); if (!symtab) return; - char *strtab = GetElfStringTable(elf, st->st_size); + char *strtab = GetElfStringTable(elf, st->st_size, ".strtab"); char *shstrtab = GetElfSectionNameStringTable(elf, st->st_size); printf("\n\n"); printf("\t.org\t%#x\n", (intptr_t)symtab - (intptr_t)elf); @@ -288,9 +289,10 @@ static void printelfsymboltable(void) { static void printelfdynsymboltable(void) { size_t i, symcount = 0; - Elf64_Sym *symtab = GetElfDynSymbolTable(elf, st->st_size, &symcount); + Elf64_Sym *symtab = + GetElfSymbolTable(elf, st->st_size, SHT_DYNSYM, &symcount); if (!symtab) return; - char *strtab = GetElfDynStringTable(elf, st->st_size); + char *strtab = GetElfStringTable(elf, st->st_size, ".dynstr"); char *shstrtab = GetElfSectionNameStringTable(elf, st->st_size); printf("\n\n"); printf("\t.org\t%#x\n", (intptr_t)symtab - (intptr_t)elf); @@ -326,7 +328,7 @@ static void printelfrelocations(void) { const Elf64_Rela *rela; char *strtab, *shstrtab, *symbolname; const Elf64_Shdr *shdr, *shdr2, *symtab; - strtab = GetElfStringTable(elf, st->st_size); + strtab = GetElfStringTable(elf, st->st_size, ".strtab"); shstrtab = GetElfSectionNameStringTable(elf, st->st_size); for (i = 0; i < elf->e_shnum; ++i) { if ((shdr = GetElfSectionHeaderAddress(elf, st->st_size, i)) && diff --git a/tool/decode/lib/decodelib.mk b/tool/decode/lib/decodelib.mk index a9d94db59..42c736a57 100644 --- a/tool/decode/lib/decodelib.mk +++ b/tool/decode/lib/decodelib.mk @@ -28,7 +28,6 @@ TOOL_DECODE_LIB_A_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV TOOL_DECODE_LIB_A_DEPS := \ diff --git a/tool/hash/crctab.c b/tool/hash/crctab.c deleted file mode 100644 index 63da79974..000000000 --- a/tool/hash/crctab.c +++ /dev/null @@ -1,49 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/fmt/conv.h" -#include "libc/intrin/bits.h" -#include "libc/macros.internal.h" -#include "libc/nexgen32e/crc32.h" -#include "libc/runtime/runtime.h" -#include "libc/stdio/stdio.h" - -/** - * @fileoverview CRC Lookup Table Generator - * @see http://reveng.sourceforge.net/crc-catalogue/17plus.htm - */ - -int main(int argc, char *argv[]) { - if (argc != 2) { - fprintf(stderr, "Usage: %s POLYNOMIAL\n", argv[0]); - exit(1); - } - static uint32_t tab[256]; - crc32init(tab, strtol(argv[1], NULL, 0)); - for (unsigned i = 0; i < ARRAYLEN(tab); ++i) { - if (i > 0) { - printf(","); - if (i % 6 == 0) { - printf("\n"); - } - } - printf("0x%08x", tab[i]); - } - printf("\n"); - return 0; -} diff --git a/tool/hash/hash.mk b/tool/hash/hash.mk deleted file mode 100644 index d1b373763..000000000 --- a/tool/hash/hash.mk +++ /dev/null @@ -1,48 +0,0 @@ -#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐ -#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘ - -PKGS += TOOL_HASH - -TOOL_HASH_SRCS := $(wildcard tool/hash/*.c) - -TOOL_HASH_OBJS = \ - $(TOOL_HASH_SRCS:%.c=o/$(MODE)/%.o) - -TOOL_HASH_COMS = \ - $(TOOL_HASH_SRCS:%.c=o/$(MODE)/%.com) - -TOOL_HASH_BINS = \ - $(TOOL_HASH_COMS) \ - $(TOOL_HASH_COMS:%=%.dbg) - -TOOL_HASH_DIRECTDEPS = \ - LIBC_FMT \ - LIBC_INTRIN \ - LIBC_NEXGEN32E \ - LIBC_RUNTIME \ - LIBC_STDIO \ - LIBC_STR \ - LIBC_MEM \ - LIBC_STUBS - -TOOL_HASH_DEPS := \ - $(call uniq,$(foreach x,$(TOOL_HASH_DIRECTDEPS),$($(x)))) - -o/$(MODE)/tool/hash/hash.pkg: \ - $(TOOL_HASH_OBJS) \ - $(foreach x,$(TOOL_HASH_DIRECTDEPS),$($(x)_A).pkg) - -o/$(MODE)/tool/hash/%.com.dbg: \ - $(TOOL_HASH_DEPS) \ - o/$(MODE)/tool/hash/%.o \ - o/$(MODE)/tool/hash/hash.pkg \ - $(CRT) \ - $(APE_NO_MODIFY_SELF) - @$(APELINK) - -$(TOOL_HASH_OBJS): \ - $(BUILD_FILES) \ - tool/hash/hash.mk - -.PHONY: o/$(MODE)/tool/hash -o/$(MODE)/tool/hash: $(TOOL_HASH_BINS) $(TOOL_HASH_CHECKS) diff --git a/tool/hello/hello.mk b/tool/hello/hello.mk index e2711b9e2..041eb41bb 100644 --- a/tool/hello/hello.mk +++ b/tool/hello/hello.mk @@ -14,8 +14,7 @@ TOOL_HELLO_DIRECTDEPS = \ LIBC_NEXGEN32E \ LIBC_RUNTIME \ LIBC_STR \ - LIBC_SYSV \ - LIBC_STUBS + LIBC_SYSV TOOL_HELLO_DEPS := \ $(call uniq,$(foreach x,$(TOOL_HELLO_DIRECTDEPS),$($(x)))) diff --git a/tool/lambda/lambda.mk b/tool/lambda/lambda.mk index 8b1d3e64c..75e71b757 100644 --- a/tool/lambda/lambda.mk +++ b/tool/lambda/lambda.mk @@ -16,20 +16,19 @@ TOOL_LAMBDA_BINS = \ $(TOOL_LAMBDA_COMS:%=%.dbg) TOOL_LAMBDA_DIRECTDEPS = \ + LIBC_CALLS \ + LIBC_FMT \ LIBC_INTRIN \ LIBC_LOG \ LIBC_MEM \ - LIBC_CALLS \ + LIBC_NEXGEN32E \ LIBC_RUNTIME \ - LIBC_FMT \ + LIBC_STDIO \ LIBC_STR \ LIBC_SYSV \ - LIBC_STDIO \ LIBC_X \ - LIBC_STUBS \ - LIBC_NEXGEN32E \ - TOOL_LAMBDA_LIB \ - THIRD_PARTY_GETOPT + THIRD_PARTY_GETOPT \ + TOOL_LAMBDA_LIB TOOL_LAMBDA_DEPS := \ $(call uniq,$(foreach x,$(TOOL_LAMBDA_DIRECTDEPS),$($(x)))) diff --git a/tool/lambda/lib/lib.mk b/tool/lambda/lib/lib.mk index 898b031e1..f6d44726c 100644 --- a/tool/lambda/lib/lib.mk +++ b/tool/lambda/lib/lib.mk @@ -25,16 +25,15 @@ TOOL_LAMBDA_LIB_A_OBJS = \ TOOL_LAMBDA_LIB_A_DIRECTDEPS = \ LIBC_CALLS \ + LIBC_FMT \ LIBC_INTRIN \ LIBC_LOG \ + LIBC_MEM \ LIBC_NEXGEN32E \ LIBC_RUNTIME \ - LIBC_MEM \ - LIBC_FMT \ LIBC_SOCK \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ THIRD_PARTY_COMPILER_RT \ THIRD_PARTY_GETOPT diff --git a/tool/net/net.mk b/tool/net/net.mk index 43fc32fd6..785bc3907 100644 --- a/tool/net/net.mk +++ b/tool/net/net.mk @@ -42,7 +42,6 @@ TOOL_NET_DIRECTDEPS = \ LIBC_SOCK \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_SYSV_CALLS \ LIBC_TIME \ diff --git a/tool/plinko/lib/lib.mk b/tool/plinko/lib/lib.mk index 245677d9e..644d39930 100644 --- a/tool/plinko/lib/lib.mk +++ b/tool/plinko/lib/lib.mk @@ -36,7 +36,6 @@ TOOL_PLINKO_LIB_A_DIRECTDEPS = \ LIBC_SOCK \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_SYSV_CALLS \ THIRD_PARTY_COMPILER_RT \ diff --git a/tool/plinko/plinko.mk b/tool/plinko/plinko.mk index eebf3cd43..8602a7762 100644 --- a/tool/plinko/plinko.mk +++ b/tool/plinko/plinko.mk @@ -26,7 +26,6 @@ TOOL_PLINKO_DIRECTDEPS = \ LIBC_SYSV \ LIBC_STDIO \ LIBC_X \ - LIBC_STUBS \ LIBC_NEXGEN32E \ LIBC_ZIPOS \ TOOL_PLINKO_LIB diff --git a/tool/scripts/cosmoc++ b/tool/scripts/cosmoc++ index 63aaa283d..121243376 100755 --- a/tool/scripts/cosmoc++ +++ b/tool/scripts/cosmoc++ @@ -102,11 +102,13 @@ fi # auto-install some shell libraries if [ ! -d "$COSMOS/lib" ]; then - mkdir "$COSMOS/lib" - for lib in c dl gcc_s m pthread resolv rt z stdc++; do - printf '\041\074\141\162\143\150\076\012' >"$COSMOS/lib/lib$lib.a" - done + mkdir -p "$COSMOS/lib" fi +for lib in c dl gcc_s m pthread resolv rt dl z stdc++; do + if [ ! -f "$COSMOS/lib/lib$lib.a" ]; then + printf '\041\074\141\162\143\150\076\012' >"$COSMOS/lib/lib$lib.a" + fi +done OPT= FIRST=1 diff --git a/tool/scripts/cosmocc b/tool/scripts/cosmocc index 363453fdd..c60315317 100755 --- a/tool/scripts/cosmocc +++ b/tool/scripts/cosmocc @@ -102,11 +102,13 @@ fi # auto-install some shell libraries if [ ! -d "$COSMOS/lib" ]; then - mkdir "$COSMOS/lib" - for lib in c dl gcc_s m pthread resolv rt z stdc++; do - printf '\041\074\141\162\143\150\076\012' >"$COSMOS/lib/lib$lib.a" - done + mkdir -p "$COSMOS/lib" fi +for lib in c dl gcc_s m pthread resolv rt dl z stdc++; do + if [ ! -f "$COSMOS/lib/lib$lib.a" ]; then + printf '\041\074\141\162\143\150\076\012' >"$COSMOS/lib/lib$lib.a" + fi +done OPT= FIRST=1 diff --git a/tool/tool.mk b/tool/tool.mk index 501801aaf..f23e92388 100644 --- a/tool/tool.mk +++ b/tool/tool.mk @@ -7,7 +7,6 @@ o/$(MODE)/tool: \ o/$(MODE)/tool/build \ o/$(MODE)/tool/curl \ o/$(MODE)/tool/decode \ - o/$(MODE)/tool/hash \ o/$(MODE)/tool/hello \ o/$(MODE)/tool/lambda \ o/$(MODE)/tool/net \ diff --git a/tool/viz/lib/vizlib.mk b/tool/viz/lib/vizlib.mk index 6244d3630..4cf71eeeb 100644 --- a/tool/viz/lib/vizlib.mk +++ b/tool/viz/lib/vizlib.mk @@ -36,7 +36,6 @@ TOOL_VIZ_LIB_A_DIRECTDEPS = \ LIBC_RUNTIME \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_TESTLIB \ LIBC_TIME \ diff --git a/tool/viz/viz.mk b/tool/viz/viz.mk index fc75f4913..66bd7cf49 100644 --- a/tool/viz/viz.mk +++ b/tool/viz/viz.mk @@ -35,7 +35,6 @@ TOOL_VIZ_DIRECTDEPS = \ LIBC_SOCK \ LIBC_STDIO \ LIBC_STR \ - LIBC_STUBS \ LIBC_SYSV \ LIBC_SYSV_CALLS \ LIBC_TIME \