Compare commits

...
14 Commits
Author SHA1 Message Date
Justine Tunney 98d06b23cc Release Cosmopolitan v3.3.3 2024-03-30 19:24:04 -07:00
Justine Tunney 9ff65cff63 Fix ZipOS extraction of ZIP64 assets 2024-03-30 19:00:40 -07:00
Justine Tunney bef2cb05ff Fix AVX512_BF16 2024-03-26 00:00:46 -07:00
mierenhoop 43885a76e4 Fix binary formatting for integers 2 and 3 (#1123) 2024-03-25 21:11:09 -07:00
Justine Tunney 74a85087de Support -S in cosmocross
You can now run commands like `x86_64-unknown-cosmo-c++ -S` when using
your cosmocc toolchain. Please note the S flag isn't supported for the
cosmocc command itself.
2024-03-24 15:49:55 -07:00
Justine Tunney 045632a743 Make fixupobj work on Windows
This fixes a regression with recent cosmocc toolchain releases that
causes fixupobj to fail with "ifunc ftruncate #1 failed" on Windows
2024-03-24 03:14:25 -07:00
Justine Tunney 9a10adac35 Remove .com from README 2024-03-22 19:38:38 -07:00
Justine Tunney 0c12c26e1d Update Emacs config 2024-03-22 19:27:11 -07:00
Justine Tunney 40b7da8422 Speed up fmaf() on x86 2024-03-22 19:26:56 -07:00
Justine Tunney 640668931d Clarify MacOS supported versions
We technically support versions much earlier, possibly dating back to
2018 or earlier, but they're not officially supported since I have no
way of testing them.

Closes #1129
2024-03-22 19:25:07 -07:00
Justine Tunney 1c34088ba0 Ignore -pie and -fpie in cosmocc
Fixes #1126
2024-03-22 03:55:01 -07:00
Justine Tunney bb92347158 Add deprecated stubs for _bsf / _bsr 2024-03-05 09:45:51 -08:00
Justine Tunney 8bfd56b59e Rename _bsr/_bsf to bsr/bsf
Now that these functions are behind _COSMO_SOURCE there's no reason for
having the ugly underscore anymore. To use these functions, you need to
pass -mcosmo to cosmocc.
2024-03-04 17:33:26 -08:00
Justine Tunney a6baba1b07 Stop using .com extension in monorepo
The WIN32 CreateProcess() function does not require an .exe or .com
suffix in order to spawn an executable. Now that we have Cosmo bash
we're no longer so dependent on the cmd.exe prompt.
2024-03-03 03:12:19 -08:00
306 changed files with 2377 additions and 2411 deletions

No files matched your search

+48 -48
View File
@@ -21,23 +21,23 @@
# make -j8 -O MODE=tiny
#
# # build individual target
# make -j8 -O o//examples/hello.com
# o//examples/hello.com
# make -j8 -O o//examples/hello
# o//examples/hello
#
# # view source
# less examples/hello.c
#
# # view binary
# o//tool/viz/bing.com o//examples/hello.com |
# o//tool/viz/fold.com
# o//tool/viz/bing o//examples/hello |
# o//tool/viz/fold
#
# # view transitive closure of legalese
# o//tool/viz/bing.com -n o//examples/hello.com |
# o//tool/viz/fold.com
# o//tool/viz/bing -n o//examples/hello |
# o//tool/viz/fold
#
# # basic debugging
# make -j8 -O MODE=dbg o/dbg/examples/crashreport.com
# o/examples/crashreport.com
# make -j8 -O MODE=dbg o/dbg/examples/crashreport
# o/examples/crashreport
# less examples/crashreport.c
#
# # extremely tiny binaries
@@ -51,7 +51,7 @@
#
# TROUBLESHOOTING
#
# make -j8 -O V=1 o//examples/hello.com
# make -j8 -O V=1 o//examples/hello
# make o//examples/life.elf -pn |& less
# etc.
#
@@ -59,7 +59,7 @@
#
# build/config.mk
SHELL = build/bootstrap/cocmd.com
SHELL = build/bootstrap/cocmd
MAKEFLAGS += --no-builtin-rules
.SUFFIXES:
@@ -77,8 +77,8 @@ COMMA := ,
PWD := $(shell pwd)
# detect wsl2 running cosmopolitan binaries on the host by checking whether:
# - user ran build/bootstrap/make.com, in which case make's working directory is in wsl
# - user ran make, in which case cocmd.com's working directory is in wsl
# - user ran build/bootstrap/make, in which case make's working directory is in wsl
# - user ran make, in which case cocmd's working directory is in wsl
ifneq ($(findstring //wsl.localhost/,$(CURDIR) $(PWD)),)
$(warning wsl2 interop is enabled)
$(error you need to run sudo sh -c 'echo -1 > /proc/sys/fs/binfmt_misc/WSLInterop')
@@ -89,7 +89,7 @@ UNAME_S := $(shell uname -s)
# apple still distributes a 17 year old version of gnu make
ifeq ($(MAKE_VERSION), 3.81)
$(error please use build/bootstrap/make.com)
$(error please use build/bootstrap/make)
endif
LC_ALL = C
@@ -101,21 +101,21 @@ XARGS ?= xargs -P4 -rs8000
DOT ?= dot
CLANG = clang
TMPDIR = o/tmp
AR = build/bootstrap/ar.com
CP = build/bootstrap/cp.com
RM = build/bootstrap/rm.com -f
GZIP = build/bootstrap/gzip.com
ECHO = build/bootstrap/echo.com
CHMOD = build/bootstrap/chmod.com
TOUCH = build/bootstrap/touch.com
PKG = build/bootstrap/package.com
MKDEPS = build/bootstrap/mkdeps.com
ZIPOBJ = build/bootstrap/zipobj.com
ZIPCOPY = build/bootstrap/zipcopy.com
PECHECK = build/bootstrap/pecheck.com
FIXUPOBJ = build/bootstrap/fixupobj.com
MKDIR = build/bootstrap/mkdir.com -p
COMPILE = build/bootstrap/compile.com -V9 -M2048m -P8192 $(QUOTA)
AR = build/bootstrap/ar
CP = build/bootstrap/cp
RM = build/bootstrap/rm -f
GZIP = build/bootstrap/gzip
ECHO = build/bootstrap/echo
CHMOD = build/bootstrap/chmod
TOUCH = build/bootstrap/touch
PKG = build/bootstrap/package
MKDEPS = build/bootstrap/mkdeps
ZIPOBJ = build/bootstrap/zipobj
ZIPCOPY = build/bootstrap/zipcopy
PECHECK = build/bootstrap/pecheck
FIXUPOBJ = build/bootstrap/fixupobj
MKDIR = build/bootstrap/mkdir -p
COMPILE = build/bootstrap/compile -V9 -M2048m -P8192 $(QUOTA)
IGNORE := $(shell $(MKDIR) $(TMPDIR))
@@ -133,7 +133,7 @@ endif
ifneq ($(findstring aarch64,$(MODE)),)
ARCH = aarch64
HOSTS ?= pi studio freebsdarm
HOSTS ?= pi pi5 studio freebsdarm
else
ARCH = x86_64
HOSTS ?= freebsd rhel7 xnu openbsd netbsd win10
@@ -187,7 +187,7 @@ o/$(MODE): \
o/$(MODE)/: o/$(MODE)
o/$(MODE)/.: o/$(MODE)
# check if we're using o//third_party/make/make.com
# check if we're using o//third_party/make/make
# we added sandboxing to guarantee cosmo's makefile is hermetic
# it also shaves away 200ms of startup latency with native $(uniq)
ifneq ($(LANDLOCKMAKE_VERSION),)
@@ -415,17 +415,17 @@ o/$(MODE)/hdrs-old.txt: o/$(MODE)/.x $(MAKEFILES) $(call uniq,$(foreach x,$(HDRS
$(file >$@) $(foreach x,$(HDRS) $(INCS),$(file >>$@,$(x)))
TAGS: private .UNSANDBOXED = 1
TAGS: o/$(MODE)/srcs-old.txt $(SRCS) #o/$(MODE)/third_party/ctags/ctags.com
TAGS: o/$(MODE)/srcs-old.txt $(SRCS) #o/$(MODE)/third_party/ctags/ctags
@$(RM) $@
@o/$(MODE)/third_party/ctags/ctags.com $(TAGSFLAGS) -L $< -o $@
@o/$(MODE)/third_party/ctags/ctags $(TAGSFLAGS) -L $< -o $@
HTAGS: private .UNSANDBOXED = 1
HTAGS: o/$(MODE)/hdrs-old.txt $(filter-out third_party/libcxx/%,$(HDRS)) #o/$(MODE)/third_party/ctags/ctags.com
HTAGS: o/$(MODE)/hdrs-old.txt $(filter-out third_party/libcxx/%,$(HDRS)) #o/$(MODE)/third_party/ctags/ctags
@$(RM) $@
@build/htags o/$(MODE)/third_party/ctags/ctags.com -L $< -o $@
@build/htags o/$(MODE)/third_party/ctags/ctags -L $< -o $@
loc: private .UNSANDBOXED = 1
loc: o/$(MODE)/tool/build/summy.com
loc: o/$(MODE)/tool/build/summy
find -name \*.h -or -name \*.c -or -name \*.S | \
$(XARGS) wc -l | grep total | awk '{print $$1}' | $<
@@ -550,16 +550,16 @@ o/cosmopolitan.h: o/cosmopolitan.h.txt \
$(wildcard libc/integral/*) \
$(foreach x,$(COSMOPOLITAN_H_PKGS),$($(x)_HDRS)) \
$(foreach x,$(COSMOPOLITAN_H_PKGS),$($(x)_INCS))
@$(COMPILE) -AROLLUP -T$@ build/bootstrap/rollup.com @$< >>$@
@$(COMPILE) -AROLLUP -T$@ build/bootstrap/rollup @$< >>$@
o/cosmopolitan.html: private .UNSANDBOXED = 1
o/cosmopolitan.html: \
o/$(MODE)/third_party/chibicc/chibicc.com.dbg \
o/$(MODE)/third_party/chibicc/chibicc.dbg \
$(filter-out %.s,$(foreach x,$(COSMOPOLITAN_OBJECTS),$($(x)_SRCS))) \
$(filter-out %.cpp,$(filter-out %.cc,$(SRCS))) \
$(HDRS)
$(file >$(TMPDIR)/$(subst /,_,$@),$(filter-out %.cpp,$(filter-out %.cc,$(filter-out %.s,$(foreach x,$(COSMOPOLITAN_OBJECTS),$($(x)_SRCS))))))
o/$(MODE)/third_party/chibicc/chibicc.com.dbg -J \
o/$(MODE)/third_party/chibicc/chibicc.dbg -J \
-fno-common -include libc/integral/normalize.inc -o $@ \
-DCOSMO @$(TMPDIR)/$(subst /,_,$@)
@@ -582,13 +582,13 @@ TOOLCHAIN_ARTIFACTS = \
o/$(MODE)/ape/ape-no-modify-self.o \
o/$(MODE)/cosmopolitan.a \
o/$(MODE)/third_party/libcxx/libcxx.a \
o/$(MODE)/tool/build/march-native.com \
o/$(MODE)/tool/build/ar.com \
o/$(MODE)/tool/build/mktemper.com \
o/$(MODE)/tool/build/fixupobj.com \
o/$(MODE)/tool/build/zipcopy.com \
o/$(MODE)/tool/build/apelink.com \
o/$(MODE)/tool/build/pecheck.com
o/$(MODE)/tool/build/march-native \
o/$(MODE)/tool/build/ar \
o/$(MODE)/tool/build/mktemper \
o/$(MODE)/tool/build/fixupobj \
o/$(MODE)/tool/build/zipcopy \
o/$(MODE)/tool/build/apelink \
o/$(MODE)/tool/build/pecheck
else
TOOLCHAIN_ARTIFACTS = \
o/$(MODE)/ape/ape.elf \
@@ -596,9 +596,9 @@ TOOLCHAIN_ARTIFACTS = \
o/$(MODE)/libc/crt/crt.o \
o/$(MODE)/cosmopolitan.a \
o/$(MODE)/third_party/libcxx/libcxx.a \
o/$(MODE)/tool/build/march-native.com \
o/$(MODE)/tool/build/fixupobj.com \
o/$(MODE)/tool/build/zipcopy.com
o/$(MODE)/tool/build/march-native \
o/$(MODE)/tool/build/fixupobj \
o/$(MODE)/tool/build/zipcopy
endif
.PHONY: toolchain
+20 -20
View File
@@ -92,8 +92,8 @@ guaranteed to be compatible and furthermore includes our extensions for
doing build system sandboxing.
```sh
build/bootstrap/make.com -j8
o//examples/hello.com
build/bootstrap/make -j8
o//examples/hello
```
Since the Cosmopolitan repository is very large, you might only want to
@@ -103,8 +103,8 @@ depends on core LIBC packages.
```sh
rm -rf o//libc o//test
build/bootstrap/make.com o//test/posix/signal_test.com
o//test/posix/signal_test.com
build/bootstrap/make o//test/posix/signal_test
o//test/posix/signal_test
```
Sometimes it's desirable to build a subset of targets, without having to
@@ -112,21 +112,21 @@ list out each individual one. For example if you wanted to build and run
all the unit tests in the `TEST_POSIX` package, you could say:
```sh
build/bootstrap/make.com o//test/posix
build/bootstrap/make o//test/posix
```
Cosmopolitan provides a variety of build modes. For example, if you want
really tiny binaries (as small as 12kb in size) then you'd say:
```sh
build/bootstrap/make.com m=tiny
build/bootstrap/make m=tiny
```
You can furthermore cut out the bloat of other operating systems, and
have Cosmopolitan become much more similar to Musl Libc.
```sh
build/bootstrap/make.com m=tinylinux
build/bootstrap/make m=tinylinux
```
For further details, see [//build/config.mk](build/config.mk).
@@ -179,11 +179,11 @@ end
src
```
You normally run the `.com.dbg` file under gdb. If you need to debug the
`.com` file itself, then you can load the debug symbols independently as
You normally run the `.dbg` file under gdb. If you need to debug the
`` file itself, then you can load the debug symbols independently as
```sh
gdb foo.com -ex 'add-symbol-file foo.com.dbg 0x401000'
gdb foo -ex 'add-symbol-file foo.dbg 0x401000'
```
## Platform Notes
@@ -242,16 +242,16 @@ server. You're welcome to join us! <https://discord.gg/FwAVVu7eJ4>
## Support Vector
| Platform | Min Version | Circa |
| :--- | ---: | ---: |
| AMD | K8 Venus | 2005 |
| Intel | Core | 2006 |
| Linux | 2.6.18 | 2007 |
| Windows | 8 [1] | 2012 |
| Mac OS X | 15.6 | 2018 |
| OpenBSD | 7 | 2021 |
| FreeBSD | 13 | 2020 |
| NetBSD | 9.2 | 2021 |
| Platform | Min Version | Circa |
| :--- | ---: | ---: |
| AMD | K8 Venus | 2005 |
| Intel | Core | 2006 |
| Linux | 2.6.18 | 2007 |
| Windows | 8 [1] | 2012 |
| Darwin (macOS) | 23.1.0+ | 2023 |
| OpenBSD | 7 | 2021 |
| FreeBSD | 13 | 2020 |
| NetBSD | 9.2 | 2021 |
[1] See our [vista branch](https://github.com/jart/cosmopolitan/tree/vista)
for a community supported version of Cosmopolitan that works on Windows
+2 -2
View File
@@ -220,10 +220,10 @@ o/$(MODE)/ape/loader-xnu-clang.asm: ape/loader.c
@$(COMPILE) -AOBJECTIFY.c $(CLANG) -DSUPPORT_VECTOR=8 -S -g0 $(APE_LOADER_FLAGS)
o/$(MODE)/ape/ape.elf: o/$(MODE)/ape/ape.elf.dbg
@$(COMPILE) -AOBJBINCOPY -w build/bootstrap/objbincopy.com -f -o $@ $<
@$(COMPILE) -AOBJBINCOPY -w build/bootstrap/objbincopy -f -o $@ $<
o/$(MODE)/ape/ape.macho: o/$(MODE)/ape/ape.elf.dbg
@$(COMPILE) -AOBJBINCOPY -w build/bootstrap/objbincopy.com -fm -o $@ $<
@$(COMPILE) -AOBJBINCOPY -w build/bootstrap/objbincopy -fm -o $@ $<
APE_LOADER_LDFLAGS = \
-static \
+1 -1
View File
@@ -22,7 +22,7 @@
#include "libc/macros.internal.h"
// Apple Mach-O Executable Headers
// Fixups are applied by objbincopy.com
// Fixups are applied by objbincopy
// There must exist a MAC_LC_SEGMENT_64 for every PT_LOAD
.section .macho,"a",@progbits
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+8 -8
View File
@@ -22,14 +22,14 @@
# - tool/build/runit.c
# - tool/build/runitd.c
.PRECIOUS: o/$(MODE)/%.com.ok
o/$(MODE)/%.com.ok: private .PLEDGE = stdio rpath wpath cpath proc fattr inet dns
o/$(MODE)/%.com.ok: private .UNVEIL += r:/etc/resolv.conf
o/$(MODE)/%.com.ok: \
o/$(MODE)/tool/build/runit.com \
o/$(MODE)/tool/build/runitd.com \
o/$(MODE)/%.com
.PRECIOUS: o/$(MODE)/%.ok
o/$(MODE)/%.ok: private .PLEDGE = stdio rpath wpath cpath proc fattr inet dns
o/$(MODE)/%.ok: private .UNVEIL += r:/etc/resolv.conf
o/$(MODE)/%.ok: \
o/$(MODE)/tool/build/runit \
o/$(MODE)/tool/build/runitd \
o/$(MODE)/%
@$(COMPILE) -wATEST -tT$@ $^ $(HOSTS)
.PHONY:
o/tiny/tool/build/runit.com:
o/tiny/tool/build/runit:
+14 -31
View File
@@ -79,17 +79,17 @@ o/$(MODE)/%.pkg:
$(file >$(TMPSAFE).args,$(filter %.o,$^))
@$(COMPILE) -APACKAGE -wT$@ $(PKG) $(OUTPUT_OPTION) $(addprefix -d,$(filter %.pkg,$^)) @$(TMPSAFE).args
o/$(MODE)/%.o: %.py o/$(MODE)/third_party/python/pyobj.com
@$(COMPILE) -wAPYOBJ o/$(MODE)/third_party/python/pyobj.com $(PYFLAGS) -o $@ $<
o/$(MODE)/%.o: %.py o/$(MODE)/third_party/python/pyobj
@$(COMPILE) -wAPYOBJ o/$(MODE)/third_party/python/pyobj $(PYFLAGS) -o $@ $<
o/$(MODE)/%.pyc: %.py o/$(MODE)/third_party/python/pycomp.com
@$(COMPILE) -wAPYCOMP o/$(MODE)/third_party/python/pycomp.com $(PYCFLAGS) -o $@ $<
o/$(MODE)/%.pyc: %.py o/$(MODE)/third_party/python/pycomp
@$(COMPILE) -wAPYCOMP o/$(MODE)/third_party/python/pycomp $(PYCFLAGS) -o $@ $<
o/$(MODE)/%.lua: %.lua o/$(MODE)/third_party/lua/luac.com
@$(COMPILE) -wALUAC o/$(MODE)/third_party/lua/luac.com -s -o $@ $<
o/$(MODE)/%.lua: %.lua o/$(MODE)/third_party/lua/luac
@$(COMPILE) -wALUAC o/$(MODE)/third_party/lua/luac -s -o $@ $<
o/$(MODE)/%.lua.runs: %.lua o/$(MODE)/tool/net/redbean.com
@$(COMPILE) -wALUA -tT$@ o/$(MODE)/tool/net/redbean.com $(LUAFLAGS) -i $<
o/$(MODE)/%.lua.runs: %.lua o/$(MODE)/tool/net/redbean
@$(COMPILE) -wALUA -tT$@ o/$(MODE)/tool/net/redbean $(LUAFLAGS) -i $<
################################################################################
# LOCAL UNIT TESTS
@@ -108,22 +108,22 @@ o/$(MODE)/%.lua.runs: %.lua o/$(MODE)/tool/net/redbean.com
#
# You could then run a command like:
#
# make -j8 o//test/libc/calls/openbsd_test.com.runs
# make -j8 o//test/libc/calls/openbsd_test.runs
#
# You need PROT_EXEC permission since ftrace morphs the binary. It's
# also worth mentioning that the pledge.com command can simulate what
# also worth mentioning that the pledge command can simulate what
# Landlock Make does:
#
# o//tool/build/pledge.com \
# o//tool/build/pledge \
# -v. -p 'stdio rpath wpath cpath tty prot_exec' \
# o//test/libc/calls/openbsd_test.com \
# o//test/libc/calls/openbsd_test \
# ----ftrace
#
# This is useful in the event a test binary should run by itself, but
# fails to run beneath Landlock Make. It's also useful sometimes to
# override the verbosity when running tests:
#
# make V=5 TESTARGS=-b o//test/libc/calls/openbsd_test.com.runs
# make V=5 TESTARGS=-b o//test/libc/calls/openbsd_test.runs
#
# This way, if for some reason a test should fail but calls exit(0),
# then the stdout/stderr output, which would normally be suppressed,
@@ -135,7 +135,7 @@ o/$(MODE)/%.runs: o/$(MODE)/%
################################################################################
# ELF ZIP FILES
#
# zipobj.com lets us do fast incremental linking of compressed data.
# zipobj lets us do fast incremental linking of compressed data.
# it's nice because if we link a hundred binaries that use the time zone
# database, then that database only needs to be DEFLATE'd once.
@@ -183,23 +183,6 @@ o/$(MODE)/%.okk: private .UNSANDBOXED = 1
o/$(MODE)/%.okk: %
@$(COMPILE) -ACHECK.h $(COMPILE.cxx) -xc++ -g0 -o $@ $<
################################################################################
# EXECUTABLE HELPERS
MAKE_SYMTAB_CREATE = \
$(COMPILE) -wASYMTAB \
o/$(MODE)/tool/build/symtab.com \
-o $(TMPSAFE)/.symtab \
$<
MAKE_SYMTAB_ZIP = \
$(COMPILE) -AZIP -T$@ \
o/$(MODE)/third_party/zip/zip.com \
-b$(TMPDIR) \
-9qj \
$@ \
$(TMPSAFE)/.symtab
################################################################################
# EMACS ASSEMBLY GENERATION
+2 -2
View File
@@ -202,8 +202,8 @@ void *Gyarados(long dyw, long dxw, int dst[dyw][dxw], long syw, long sxw,
CHECK_LE(sxn, sxw);
CHECK_LE(dyn, dyw);
CHECK_LE(dxn, dxw);
CHECK_LT(_bsrl(syn) + _bsrl(sxn), 32);
CHECK_LT(_bsrl(dyn) + _bsrl(dxn), 32);
CHECK_LT(bsrl(syn) + bsrl(sxn), 32);
CHECK_LT(bsrl(dyn) + bsrl(dxn), 32);
CHECK_LE(dyw, 0x7fff);
CHECK_LE(dxw, 0x7fff);
CHECK_LE(syw, 0x7fff);
+103 -103
View File
@@ -14,130 +14,130 @@ EXAMPLES_MAINS_S = $(filter %.S,$(EXAMPLES_FILES))
EXAMPLES_MAINS_C = $(filter %.c,$(EXAMPLES_FILES))
EXAMPLES_MAINS_CC = $(filter %.cc,$(EXAMPLES_FILES))
EXAMPLES_SRCS = \
$(EXAMPLES_MAINS_S) \
$(EXAMPLES_MAINS_C) \
EXAMPLES_SRCS = \
$(EXAMPLES_MAINS_S) \
$(EXAMPLES_MAINS_C) \
$(EXAMPLES_MAINS_CC)
EXAMPLES_MAINS = \
$(EXAMPLES_MAINS_S) \
$(EXAMPLES_MAINS_C) \
EXAMPLES_MAINS = \
$(EXAMPLES_MAINS_S) \
$(EXAMPLES_MAINS_C) \
$(EXAMPLES_MAINS_CC)
EXAMPLES_OBJS = \
$(EXAMPLES_MAINS_S:%.S=o/$(MODE)/%.o) \
$(EXAMPLES_MAINS_C:%.c=o/$(MODE)/%.o) \
EXAMPLES_OBJS = \
$(EXAMPLES_MAINS_S:%.S=o/$(MODE)/%.o) \
$(EXAMPLES_MAINS_C:%.c=o/$(MODE)/%.o) \
$(EXAMPLES_MAINS_CC:%.cc=o/$(MODE)/%.o)
EXAMPLES_COMS = \
$(EXAMPLES_MAINS_S:%.S=o/$(MODE)/%.com) \
$(EXAMPLES_MAINS_C:%.c=o/$(MODE)/%.com) \
$(EXAMPLES_MAINS_CC:%.cc=o/$(MODE)/%.com)
EXAMPLES_COMS = \
$(EXAMPLES_MAINS_S:%.S=o/$(MODE)/%) \
$(EXAMPLES_MAINS_C:%.c=o/$(MODE)/%) \
$(EXAMPLES_MAINS_CC:%.cc=o/$(MODE)/%)
EXAMPLES_BINS = \
$(EXAMPLES_COMS) \
EXAMPLES_BINS = \
$(EXAMPLES_COMS) \
$(EXAMPLES_COMS:%=%.dbg)
EXAMPLES_DIRECTDEPS = \
DSP_CORE \
DSP_SCALE \
DSP_TTY \
LIBC_CALLS \
LIBC_DLOPEN \
LIBC_FMT \
LIBC_INTRIN \
LIBC_IRQ \
LIBC_LOG \
LIBC_MEM \
LIBC_NEXGEN32E \
LIBC_NT_ADVAPI32 \
LIBC_NT_IPHLPAPI \
LIBC_NT_KERNEL32 \
LIBC_NT_NTDLL \
LIBC_NT_USER32 \
LIBC_NT_WS2_32 \
LIBC_PROC \
LIBC_RUNTIME \
LIBC_SOCK \
LIBC_STDIO \
LIBC_STR \
LIBC_SYSV \
LIBC_SYSV_CALLS \
LIBC_TESTLIB \
LIBC_THREAD \
LIBC_TIME \
LIBC_TINYMATH \
LIBC_VGA \
LIBC_X \
NET_HTTP \
NET_HTTPS \
THIRD_PARTY_AWK \
THIRD_PARTY_COMPILER_RT \
THIRD_PARTY_DLMALLOC \
THIRD_PARTY_DOUBLECONVERSION \
THIRD_PARTY_GDTOA \
THIRD_PARTY_GETOPT \
THIRD_PARTY_HIREDIS \
THIRD_PARTY_LIBCXX \
THIRD_PARTY_LINENOISE \
THIRD_PARTY_LUA \
THIRD_PARTY_MBEDTLS \
THIRD_PARTY_MUSL \
THIRD_PARTY_NSYNC \
THIRD_PARTY_NSYNC_MEM \
THIRD_PARTY_OPENMP \
THIRD_PARTY_SED \
THIRD_PARTY_STB \
THIRD_PARTY_TR \
THIRD_PARTY_VQSORT \
THIRD_PARTY_XED \
THIRD_PARTY_ZLIB \
TOOL_ARGS \
TOOL_BUILD_LIB \
EXAMPLES_DIRECTDEPS = \
DSP_CORE \
DSP_SCALE \
DSP_TTY \
LIBC_CALLS \
LIBC_DLOPEN \
LIBC_FMT \
LIBC_INTRIN \
LIBC_IRQ \
LIBC_LOG \
LIBC_MEM \
LIBC_NEXGEN32E \
LIBC_NT_ADVAPI32 \
LIBC_NT_IPHLPAPI \
LIBC_NT_KERNEL32 \
LIBC_NT_NTDLL \
LIBC_NT_USER32 \
LIBC_NT_WS2_32 \
LIBC_PROC \
LIBC_RUNTIME \
LIBC_SOCK \
LIBC_STDIO \
LIBC_STR \
LIBC_SYSV \
LIBC_SYSV_CALLS \
LIBC_TESTLIB \
LIBC_THREAD \
LIBC_TIME \
LIBC_TINYMATH \
LIBC_VGA \
LIBC_X \
NET_HTTP \
NET_HTTPS \
THIRD_PARTY_AWK \
THIRD_PARTY_COMPILER_RT \
THIRD_PARTY_DLMALLOC \
THIRD_PARTY_DOUBLECONVERSION \
THIRD_PARTY_GDTOA \
THIRD_PARTY_GETOPT \
THIRD_PARTY_HIREDIS \
THIRD_PARTY_LIBCXX \
THIRD_PARTY_LINENOISE \
THIRD_PARTY_LUA \
THIRD_PARTY_MBEDTLS \
THIRD_PARTY_MUSL \
THIRD_PARTY_NSYNC \
THIRD_PARTY_NSYNC_MEM \
THIRD_PARTY_OPENMP \
THIRD_PARTY_SED \
THIRD_PARTY_STB \
THIRD_PARTY_TR \
THIRD_PARTY_VQSORT \
THIRD_PARTY_XED \
THIRD_PARTY_ZLIB \
TOOL_ARGS \
TOOL_BUILD_LIB \
TOOL_VIZ_LIB
EXAMPLES_DEPS := \
EXAMPLES_DEPS := \
$(call uniq,$(foreach x,$(EXAMPLES_DIRECTDEPS),$($(x))))
o/$(MODE)/examples/examples.pkg: \
$(EXAMPLES_OBJS) \
o/$(MODE)/examples/examples.pkg: \
$(EXAMPLES_OBJS) \
$(foreach x,$(EXAMPLES_DIRECTDEPS),$($(x)_A).pkg)
o/$(MODE)/examples/unbourne.o: private \
CPPFLAGS += \
-DSTACK_FRAME_UNLIMITED \
o/$(MODE)/examples/unbourne.o: private \
CPPFLAGS += \
-DSTACK_FRAME_UNLIMITED \
-fpie
o/$(MODE)/examples/%.com.dbg: \
$(EXAMPLES_DEPS) \
o/$(MODE)/examples/%.o \
o/$(MODE)/examples/examples.pkg \
o/$(MODE)/examples/%.dbg: \
$(EXAMPLES_DEPS) \
o/$(MODE)/examples/%.o \
o/$(MODE)/examples/examples.pkg \
$(EXAMPLES_BOOTLOADER)
@$(APELINK)
o/$(MODE)/examples/hellolua.com.dbg: \
$(EXAMPLES_DEPS) \
o/$(MODE)/examples/hellolua.o \
o/$(MODE)/examples/hellolua.lua.zip.o \
o/$(MODE)/examples/examples.pkg \
o/$(MODE)/examples/hellolua.dbg: \
$(EXAMPLES_DEPS) \
o/$(MODE)/examples/hellolua.o \
o/$(MODE)/examples/hellolua.lua.zip.o \
o/$(MODE)/examples/examples.pkg \
$(EXAMPLES_BOOTLOADER)
@$(APELINK)
o/$(MODE)/examples/ispell.com.dbg: \
$(EXAMPLES_DEPS) \
o/$(MODE)/examples/ispell.o \
o/$(MODE)/usr/share/dict/words.zip.o \
o/$(MODE)/examples/examples.pkg \
o/$(MODE)/examples/ispell.dbg: \
$(EXAMPLES_DEPS) \
o/$(MODE)/examples/ispell.o \
o/$(MODE)/usr/share/dict/words.zip.o \
o/$(MODE)/examples/examples.pkg \
$(EXAMPLES_BOOTLOADER)
@$(APELINK)
o/$(MODE)/examples/nesemu1.com.dbg: \
$(EXAMPLES_DEPS) \
o/$(MODE)/examples/nesemu1.o \
o/$(MODE)/usr/share/rom/mario.nes.zip.o \
o/$(MODE)/usr/share/rom/zelda.nes.zip.o \
o/$(MODE)/usr/share/rom/tetris.nes.zip.o \
o/$(MODE)/examples/examples.pkg \
o/$(MODE)/examples/nesemu1.dbg: \
$(EXAMPLES_DEPS) \
o/$(MODE)/examples/nesemu1.o \
o/$(MODE)/usr/share/rom/mario.nes.zip.o \
o/$(MODE)/usr/share/rom/zelda.nes.zip.o \
o/$(MODE)/usr/share/rom/tetris.nes.zip.o \
o/$(MODE)/examples/examples.pkg \
$(EXAMPLES_BOOTLOADER)
@$(APELINK)
@@ -145,7 +145,7 @@ o/$(MODE)/examples/picol.o: private \
CPPFLAGS += \
-DSTACK_FRAME_UNLIMITED
o/$(MODE)/examples/picol.com.dbg: \
o/$(MODE)/examples/picol.dbg: \
$(EXAMPLES_DEPS) \
o/$(MODE)/examples/picol.o \
o/$(MODE)/examples/examples.pkg \
@@ -166,8 +166,8 @@ o/$(MODE)/usr/share/dict/words: \
################################################################################
.PHONY: o/$(MODE)/examples
o/$(MODE)/examples: \
o/$(MODE)/examples/package \
o/$(MODE)/examples/pylife \
o/$(MODE)/examples/pyapp \
o/$(MODE)/examples: \
o/$(MODE)/examples/package \
o/$(MODE)/examples/pylife \
o/$(MODE)/examples/pyapp \
$(EXAMPLES_BINS)
+17 -17
View File
@@ -14,13 +14,13 @@
# GETTING STARTED
#
# # run these commands after cloning the cosmo repo on linux
# $ make -j8 o//examples/pyapp/pyapp.com
# $ o//examples/pyapp/pyapp.com
# $ make -j8 o//examples/pyapp/pyapp
# $ o//examples/pyapp/pyapp
# cosmopolitan is cool!
#
# HOW IT WORKS
#
# $ pyobj.com -m -o pyapp.o pyapp.py
# $ pyobj -m -o pyapp.o pyapp.py
# $ ld -static -nostdlib -T o//ape/ape.lds ape.o crt.o \
# pyapp.o \
# cosmopolitan-python-stage2.a \
@@ -29,19 +29,19 @@
# cosmopolitan-bzip2.a \
# cosmopolitan-python-stage1.a \
# cosmopolitan.a
# $ ./pyapp.com
# $ ./pyapp
# cosmopolitan is cool!
#
# NOTES
#
# If you enjoy this tutorial, let us know jtunney@gmail.com. If
# If you enjoy this tutorial, let us know jtunney@gmail. If
# you're building something cool, then we can we can add you to
# our .gitowners file which grants you commit access so you can
# indepnedently maintain your package, as part of the mono-repo
PKGS += PYAPP
PYAPP = $(PYAPP_DEPS) o/$(MODE)/examples/pyapp/pyapp.a
PYAPP_COMS = o/$(MODE)/examples/pyapp/pyapp.com
PYAPP_COMS = o/$(MODE)/examples/pyapp/pyapp
PYAPP_BINS = $(PYAPP_COMS) $(PYAPP_COMS:%=%.dbg)
# Specify our Cosmopolitan library dependencies
@@ -58,7 +58,7 @@ PYAPP_DIRECTDEPS = \
# them all out and arranges them in the correct order.
PYAPP_DEPS := $(call uniq,$(foreach x,$(PYAPP_DIRECTDEPS),$($(x))))
# # Asks PYOBJ.COM to turn our Python source into an ELF object which
# # Asks PYOBJ to turn our Python source into an ELF object which
# # contains (a) embedded zip file artifacts of our .py file and .pyc
# # which it it compiled; and (b) statically analyzed listings of our
# # python namespaces and imports that GNU ld will use for tree shake
@@ -71,18 +71,18 @@ PYAPP_DEPS := $(call uniq,$(foreach x,$(PYAPP_DIRECTDEPS),$($(x))))
# in `.python/` (which is accessible via open() system calls, using
# the synthetic path `"/zip/.python/"`) which means that if we want
# to turn `pyapp/pyapp.py` into `.python/pyapp.py` so it's imported
# using `import pyapp` then we can simply append to PYOBJ.COM flags
# using `import pyapp` then we can simply append to PYOBJ flags
# flags above asking it to strip one directory component and prefix
# Lastly be sure that whenever you use this variable override trick
# you only do it to .o files, since otherwise it'll ruin everything
# Passing -m to PYOBJ.COM causes a C main() function to get yoinked
# Passing -m to PYOBJ causes a C main() function to get yoinked
# and it means our Python module can no longer be used as a library
o/$(MODE)/examples/pyapp/pyapp.o: PYFLAGS += -m -C2 -P.python
# Asks PACKAGE.COM to sanity check our DIRECTDEPS and symbol graph.
# Asks PACKAGE to sanity check our DIRECTDEPS and symbol graph.
# This program functions as an incremental linker. It also provides
# enhancements to the object code that GCC generated similar to LTO
# so be certain that your .com.dbg rule depends on the .pkg output!
# so be certain that your .dbg rule depends on the .pkg output!
o/$(MODE)/examples/pyapp/pyapp.pkg: \
o/$(MODE)/examples/pyapp/pyapp.o \
$(foreach x,$(PYAPP_DIRECTDEPS),$($(x)_A).pkg)
@@ -90,7 +90,7 @@ o/$(MODE)/examples/pyapp/pyapp.pkg: \
# Ask GNU LD to link our APE executable within an ELF binary shell.
# The CRT and APE dependencies are special dependencies that define
# your _start() / WinMain() entrpoints as well as APE linker script
o/$(MODE)/examples/pyapp/pyapp.com.dbg: \
o/$(MODE)/examples/pyapp/pyapp.dbg: \
$(PYAPP_DEPS) \
o/$(MODE)/examples/pyapp/pyapp.pkg \
o/$(MODE)/examples/pyapp/pyapp.o \
@@ -98,10 +98,10 @@ o/$(MODE)/examples/pyapp/pyapp.com.dbg: \
$(APE_NO_MODIFY_SELF)
@$(COMPILE) -ALINK.ape $(LINK) $(LINKARGS) -o $@
# # Unwrap the APE .COM binary, that's embedded within the linked file
# # Unwrap the APE binary, that's embedded within the linked file
# # NOTE: This line can be commented out, since it's in build/rules.mk
# o/$(MODE)/examples/pyapp/pyapp.com: \
# o/$(MODE)/examples/pyapp/pyapp.com.dbg
# o/$(MODE)/examples/pyapp/pyapp: \
# o/$(MODE)/examples/pyapp/pyapp.dbg
# $(OBJCOPY) -S -O binary $< $@
# Ensure that build config changes will invalidate build artifacts.
@@ -112,5 +112,5 @@ o/$(MODE)/examples/pyapp/pyapp.o: \
# and have it build all targets the package defines.
.PHONY: o/$(MODE)/examples/pyapp
o/$(MODE)/examples/pyapp: \
o/$(MODE)/examples/pyapp/pyapp.com \
o/$(MODE)/examples/pyapp/pyapp.com.dbg
o/$(MODE)/examples/pyapp/pyapp \
o/$(MODE)/examples/pyapp/pyapp.dbg
+17 -17
View File
@@ -14,13 +14,13 @@
# GETTING STARTED
#
# # run these commands after cloning the cosmo repo on linux
# $ make -j8 o//examples/pylife/pylife.com
# $ o//examples/pylife/pylife.com
# $ make -j8 o//examples/pylife/pylife
# $ o//examples/pylife/pylife
# cosmopolitan is cool!
#
# HOW IT WORKS
#
# $ pyobj.com -m -o pylife.o pylife.py
# $ pyobj -m -o pylife.o pylife.py
# $ ld -static -nostdlib -T o//ape/ape.lds ape.o crt.o \
# pylife.o \
# cosmopolitan-python-stage2.a \
@@ -29,19 +29,19 @@
# cosmopolitan-bzip2.a \
# cosmopolitan-python-stage1.a \
# cosmopolitan.a
# $ ./pylife.com
# $ ./pylife
# cosmopolitan is cool!
#
# NOTES
#
# If you enjoy this tutorial, let us know jtunney@gmail.com. If
# If you enjoy this tutorial, let us know jtunney@gmail. If
# you're building something cool, then we can we can add you to
# our .gitowners file which grants you commit access so you can
# indepnedently maintain your package, as part of the mono-repo
PKGS += PYLIFE
PYLIFE = $(PYLIFE_DEPS) o/$(MODE)/examples/pylife/pylife.a
PYLIFE_COMS = o/$(MODE)/examples/pylife/pylife.com
PYLIFE_COMS = o/$(MODE)/examples/pylife/pylife
PYLIFE_BINS = $(PYLIFE_COMS) $(PYLIFE_COMS:%=%.dbg)
# Specify our Cosmopolitan library dependencies
@@ -58,7 +58,7 @@ PYLIFE_DIRECTDEPS = \
# them all out and arranges them in the correct order.
PYLIFE_DEPS := $(call uniq,$(foreach x,$(PYLIFE_DIRECTDEPS),$($(x))))
# # Asks PYOBJ.COM to turn our Python source into an ELF object which
# # Asks PYOBJ to turn our Python source into an ELF object which
# # contains (a) embedded zip file artifacts of our .py file and .pyc
# # which it it compiled; and (b) statically analyzed listings of our
# # python namespaces and imports that GNU ld will use for tree shake
@@ -71,18 +71,18 @@ PYLIFE_DEPS := $(call uniq,$(foreach x,$(PYLIFE_DIRECTDEPS),$($(x))))
# in `.python/` (which is accessible via open() system calls, using
# the synthetic path `"/zip/.python/"`) which means that if we want
# to turn `pylife/pylife.py` into `.python/pylife.py` so it's imported
# using `import pylife` then we can simply append to PYOBJ.COM flags
# using `import pylife` then we can simply append to PYOBJ flags
# flags above asking it to strip one directory component and prefix
# Lastly be sure that whenever you use this variable override trick
# you only do it to .o files, since otherwise it'll ruin everything
# Passing -m to PYOBJ.COM causes a C main() function to get yoinked
# Passing -m to PYOBJ causes a C main() function to get yoinked
# and it means our Python module can no longer be used as a library
o/$(MODE)/examples/pylife/pylife.o: PYFLAGS += -m -C2 -P.python
# Asks PACKAGE.COM to sanity check our DIRECTDEPS and symbol graph.
# Asks PACKAGE to sanity check our DIRECTDEPS and symbol graph.
# This program functions as an incremental linker. It also provides
# enhancements to the object code that GCC generated similar to LTO
# so be certain that your .com.dbg rule depends on the .pkg output!
# so be certain that your .dbg rule depends on the .pkg output!
o/$(MODE)/examples/pylife/pylife.pkg: \
o/$(MODE)/examples/pylife/pylife.o \
$(foreach x,$(PYLIFE_DIRECTDEPS),$($(x)_A).pkg)
@@ -90,7 +90,7 @@ o/$(MODE)/examples/pylife/pylife.pkg: \
# Ask GNU LD to link our APE executable within an ELF binary shell.
# The CRT and APE dependencies are special dependencies that define
# your _start() / WinMain() entrpoints as well as APE linker script
o/$(MODE)/examples/pylife/pylife.com.dbg: \
o/$(MODE)/examples/pylife/pylife.dbg: \
$(PYLIFE_DEPS) \
o/$(MODE)/examples/pylife/pylife.pkg \
o/$(MODE)/examples/pylife/pylife.o \
@@ -98,10 +98,10 @@ o/$(MODE)/examples/pylife/pylife.com.dbg: \
$(APE_NO_MODIFY_SELF)
@$(COMPILE) -ALINK.ape $(LINK) $(LINKARGS) -o $@
# # Unwrap the APE .COM binary, that's embedded within the linked file
# # Unwrap the APE binary, that's embedded within the linked file
# # NOTE: This line can be commented out, since it's in build/rules.mk
# o/$(MODE)/examples/pylife/pylife.com: \
# o/$(MODE)/examples/pylife/pylife.com.dbg
# o/$(MODE)/examples/pylife/pylife: \
# o/$(MODE)/examples/pylife/pylife.dbg
# $(OBJCOPY) -S -O binary $< $@
# Ensure that build config changes will invalidate build artifacts.
@@ -112,5 +112,5 @@ o/$(MODE)/examples/pylife/pylife.o: \
# and have it build all targets the package defines.
.PHONY: o/$(MODE)/examples/pylife
o/$(MODE)/examples/pylife: \
o/$(MODE)/examples/pylife/pylife.com \
o/$(MODE)/examples/pylife/pylife.com.dbg
o/$(MODE)/examples/pylife/pylife \
o/$(MODE)/examples/pylife/pylife.dbg
+1 -1
View File
@@ -23,7 +23,7 @@
* Changes permissions on file, e.g.:
*
* CHECK_NE(-1, chmod("foo/bar.txt", 0644));
* CHECK_NE(-1, chmod("o/default/program.com", 0755));
* CHECK_NE(-1, chmod("o/default/program", 0755));
* CHECK_NE(-1, chmod("privatefolder/", 0700));
*
* The esoteric bits generally available on System Five are:
+1 -1
View File
@@ -36,7 +36,7 @@ int sys_fchmodat2(int, const char *, unsigned, int);
* Changes permissions on file, e.g.:
*
* CHECK_NE(-1, fchmodat(AT_FDCWD, "foo/bar.txt", 0644));
* CHECK_NE(-1, fchmodat(AT_FDCWD, "o/default/program.com", 0755));
* CHECK_NE(-1, fchmodat(AT_FDCWD, "o/default/program", 0755));
* CHECK_NE(-1, fchmodat(AT_FDCWD, "privatefolder/", 0700));
*
* @param path must exist
+1 -1
View File
@@ -71,7 +71,7 @@ static textwindows long GetSizeOfReparsePoint(int64_t fh) {
}
}
if (x >= 0200) {
z += _bsrl(tpenc(x)) >> 3;
z += bsrl(tpenc(x)) >> 3;
}
++z;
}
@@ -118,6 +118,8 @@ static char *CopyWithCwd(const char *q, char *p, char *e) {
// if q exists then turn it into an absolute path. we also try adding
// a .com suffix since the ape auto-appends it when resolving
//
// TODO(jart): is this still relevant?
static int TryPath(const char *q, int com) {
char *p;
if (!(p = CopyWithCwd(q, g_prog.u.buf,
+3 -3
View File
@@ -950,14 +950,14 @@ static const uint16_t kPledgeUnveil[] = {
// placeholder group
//
// pledge.com checks this to do auto-unveiling
// pledge checks this to do auto-unveiling
static const uint16_t kPledgeVminfo[] = {
__NR_linux_sched_yield, //
};
// placeholder group
//
// pledge.com uses this to auto-unveil /tmp and $TMPPATH with rwc
// pledge uses this to auto-unveil /tmp and $TMPPATH with rwc
// permissions. pledge() alone (without unveil() too) offers very
// little security here. consider using them together.
static const uint16_t kPledgeTmppath[] = {
@@ -1040,7 +1040,7 @@ static privileged char *FixCpy(char p[17], uint64_t x, int k) {
}
static privileged char *HexCpy(char p[17], uint64_t x) {
return FixCpy(p, x, ROUNDUP(x ? _bsrl(x) + 1 : 1, 4));
return FixCpy(p, x, ROUNDUP(x ? bsrl(x) + 1 : 1, 4));
}
static privileged int GetPid(void) {
+4 -4
View File
@@ -163,7 +163,7 @@
* interpreted, and ape binaries, you'll usually want `rpath` and
* `prot_exec` too. With APE it's possible to work around this
* requirement, by "assimilating" your binaries beforehand. See the
* assimilate.com program and `--assimilate` flag which can be used to
* assimilate program and `--assimilate` flag which can be used to
* turn APE binaries into static native binaries.
*
* - "prot_exec" allows mmap(PROT_EXEC) and mprotect(PROT_EXEC). This is
@@ -176,13 +176,13 @@
* calls on Linux.
*
* - "vminfo" OpenBSD defines this for programs like `top`. On Linux,
* this is a placeholder group that lets tools like pledge.com check
* this is a placeholder group that lets tools like pledge check
* `__promises` and automatically unveil() a subset of files top would
* need, e.g. /proc/stat, /proc/meminfo.
*
* - "tmppath" allows unlink, unlinkat, and lstat. This is mostly a
* placeholder group for pledge.com, which reads the `__promises`
* global to determine if /tmp and $TMPPATH should be unveiled.
* placeholder group for pledge, which reads the `__promises` global
* to determine if /tmp and $TMPPATH should be unveiled.
*
* `execpromises` only matters if "exec" is specified in `promises`. In
* that case, this specifies the promises that'll apply once execve()
+1 -1
View File
@@ -368,7 +368,7 @@ static textwindows int ProcessKeyEvent(const struct NtInputRecord *r, char *p) {
// To use the tty mouse events feature:
// - write(1, "\e[?1000;1002;1015;1006h") to enable
// - write(1, "\e[?1000;1002;1015;1006l") to disable
// See o//examples/ttyinfo.com and o//tool/viz/life.com
// See o//examples/ttyinfo and o//tool/viz/life
static textwindows int ProcessMouseEvent(const struct NtInputRecord *r,
char *b) {
char *p = b;
+1 -1
View File
@@ -97,7 +97,7 @@ static textwindows int __sig_getter(atomic_ulong *sigs, sigset_t masked) {
for (;;) {
pending = atomic_load_explicit(sigs, memory_order_acquire);
if ((deliverable = pending & ~masked)) {
sig = _bsfl(deliverable) + 1;
sig = bsfl(deliverable) + 1;
bit = 1ull << (sig - 1);
if (atomic_fetch_and_explicit(sigs, ~bit, memory_order_acq_rel) & bit) {
return sig;
-2
View File
@@ -116,7 +116,6 @@ _start:
9: .unreachable
// strongly link main() function (discarded by linker)
// libc_runtime had to weakly link, due to package.com
.section .yoink
call main
.previous
@@ -154,7 +153,6 @@ _start:
.unreachable
// strongly link main() function (discarded by linker)
// libc_runtime had to weakly link, due to package.com
.section .yoink
bl main
.previous
+2 -2
View File
@@ -21,7 +21,7 @@
static inline int PickGoodWidth(unsigned x) {
if (x < 16) {
if (x < 2) return 0;
if (x < 2) return 1;
if (x < 8) return 7;
return 15;
} else {
@@ -45,7 +45,7 @@ char *FormatBinary64(char p[hasatleast 67], uint64_t x, char z) {
*p++ = '0';
*p++ = 'b';
}
i = PickGoodWidth(_bsrl(x));
i = PickGoodWidth(bsrl(x));
do {
b = 1;
b <<= i;
+1 -1
View File
@@ -22,5 +22,5 @@
#include "libc/macros.internal.h"
size_t uint64toarray_radix16(uint64_t x, char b[hasatleast 17]) {
return uint64toarray_fixed16(x, b, ROUNDUP(x ? _bsrl(x) + 1 : 1, 4));
return uint64toarray_fixed16(x, b, ROUNDUP(x ? bsrl(x) + 1 : 1, 4));
}
+9 -2
View File
@@ -18,12 +18,14 @@
#if 1
template <bool _P, typename _T, typename _U>
struct __cxx_choose_expr {
__cxx_choose_expr(_T _a, _U _b) : _value(_a) {}
__cxx_choose_expr(_T _a, _U _b) : _value(_a) {
}
const _T _value;
};
template <typename _T, typename _U>
struct __cxx_choose_expr<false, _T, _U> {
__cxx_choose_expr(_T _a, _U _b) : _value(_b) {}
__cxx_choose_expr(_T _a, _U _b) : _value(_b) {
}
const _U _value;
};
#define __builtin_choose_expr(X, A, B) \
@@ -32,3 +34,8 @@ struct __cxx_choose_expr<false, _T, _U> {
#define __builtin_choose_expr(X, A, B) ((X) ? (A) : (B))
#endif
#endif
#ifdef __aarch64__
/* todo jart whyyyy */
#define _Float16 __fp16
#endif
+1 -1
View File
@@ -4,7 +4,7 @@
#define __COSMOPOLITAN_MAJOR__ 3
#define __COSMOPOLITAN_MINOR__ 3
#define __COSMOPOLITAN_PATCH__ 2
#define __COSMOPOLITAN_PATCH__ 3
#define __COSMOPOLITAN__ \
(100000000 * __COSMOPOLITAN_MAJOR__ + 1000000 * __COSMOPOLITAN_MINOR__ + \
__COSMOPOLITAN_PATCH__)
+2 -2
View File
@@ -24,7 +24,6 @@
#include "libc/errno.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/atomic.h"
#include "libc/serialize.h"
#include "libc/intrin/cmpxchg.h"
#include "libc/intrin/describebacktrace.internal.h"
#include "libc/intrin/directmap.internal.h"
@@ -45,6 +44,7 @@
#include "libc/runtime/runtime.h"
#include "libc/runtime/stack.h"
#include "libc/runtime/symbols.internal.h"
#include "libc/serialize.h"
#include "libc/stdckdint.h"
#include "libc/str/str.h"
#include "libc/str/tab.internal.h"
@@ -767,7 +767,7 @@ static void __asan_report_memory_origin_image(intptr_t a, int z) {
}
}
} else {
kprintf("\tunknown please supply .com.dbg symbols or set COMDBG\n");
kprintf("\tunknown please supply .dbg symbols or set COMDBG\n");
}
} else {
kprintf("\tunknown please __static_yoink(\"GetSymbolTable\");\n");
+6 -6
View File
@@ -22,7 +22,7 @@
* Returns position of first bit set.
*
* ctz(𝑥) 31^clz(𝑥) clz(𝑥)
* uint32 𝑥 _bsf(𝑥) tzcnt(𝑥) ffs(𝑥) _bsr(𝑥) lzcnt(𝑥)
* uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥)
* 0x00000000 wut 32 0 wut 32
* 0x00000001 0 0 1 0 31
* 0x80000001 0 0 1 31 0
@@ -35,7 +35,7 @@
* @param 𝑥 is a 64-bit integer
* @return number in range 0..63 or undefined if 𝑥 is 0
*/
int(_bsfl)(long x) {
int(bsfl)(long x) {
unsigned l, r;
x &= -x;
l = x | x >> 32;
@@ -52,7 +52,7 @@ int(_bsfl)(long x) {
* Returns position of first bit set.
*
* ctz(𝑥) 31^clz(𝑥) clz(𝑥)
* uint32 𝑥 _bsf(𝑥) tzcnt(𝑥) ffs(𝑥) _bsr(𝑥) lzcnt(𝑥)
* uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥)
* 0x00000000 wut 32 0 wut 32
* 0x00000001 0 0 1 0 31
* 0x80000001 0 0 1 31 0
@@ -65,8 +65,8 @@ int(_bsfl)(long x) {
* @param x is a 32-bit integer
* @return number in range 0..31 or undefined if 𝑥 is 0
*/
int(_bsf)(int x) {
return _bsf((unsigned)x);
int(bsf)(int x) {
return bsf((unsigned)x);
}
__weak_reference(_bsfl, _bsfll);
__weak_reference(bsfl, bsfll);
+13 -6
View File
@@ -1,16 +1,23 @@
#ifdef _COSMO_SOURCE
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_
#define COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_
COSMOPOLITAN_C_START_
libcesque int _bsf(int) pureconst;
libcesque int _bsfl(long) pureconst;
libcesque int _bsfll(long long) pureconst;
libcesque int bsf(int) pureconst;
libcesque int bsfl(long) pureconst;
libcesque int bsfll(long long) pureconst;
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define _bsf(x) __builtin_ctz(x)
#define _bsfl(x) __builtin_ctzl(x)
#define _bsfll(x) __builtin_ctzll(x)
#define bsf(x) __builtin_ctz(x)
#define bsfl(x) __builtin_ctzl(x)
#define bsfll(x) __builtin_ctzll(x)
#endif
/* deprecated */
#define _bsf(x) bsf(x)
#define _bsfl(x) bsfl(x)
#define _bsfll(x) bsfll(x)
COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_ */
#endif /* _COSMO_SOURCE */
+2 -2
View File
@@ -23,7 +23,7 @@
* Returns binary logarithm of 𝑥.
*
* ctz(𝑥) 31^clz(𝑥) clz(𝑥)
* uint32 𝑥 _bsf(𝑥) tzcnt(𝑥) ffs(𝑥) _bsr(𝑥) lzcnt(𝑥)
* uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥)
* 0x00000000 wut 32 0 wut 32
* 0x00000001 0 0 1 0 31
* 0x80000001 0 0 1 31 0
@@ -36,7 +36,7 @@
* @param x is a 32-bit integer
* @return number in range 0..31 or undefined if 𝑥 is 0
*/
int(_bsr)(int x) {
int(bsr)(int x) {
int r = 0;
if(x & 0xFFFF0000u) { x >>= 16; r |= 16; }
if(x & 0xFF00) { x >>= 8; r |= 8; }
+13 -6
View File
@@ -1,16 +1,23 @@
#ifdef _COSMO_SOURCE
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_
#define COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_
COSMOPOLITAN_C_START_
libcesque int _bsr(int) pureconst;
libcesque int _bsrl(long) pureconst;
libcesque int _bsrll(long long) pureconst;
libcesque int bsr(int) pureconst;
libcesque int bsrl(long) pureconst;
libcesque int bsrll(long long) pureconst;
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define _bsr(x) (__builtin_clz(x) ^ (sizeof(int) * 8 - 1))
#define _bsrl(x) (__builtin_clzl(x) ^ (sizeof(long) * 8 - 1))
#define _bsrll(x) (__builtin_clzll(x) ^ (sizeof(long long) * 8 - 1))
#define bsr(x) (__builtin_clz(x) ^ (sizeof(int) * 8 - 1))
#define bsrl(x) (__builtin_clzl(x) ^ (sizeof(long) * 8 - 1))
#define bsrll(x) (__builtin_clzll(x) ^ (sizeof(long long) * 8 - 1))
#endif
/* deprecated */
#define _bsr(x) bsr(x)
#define _bsrl(x) bsrl(x)
#define _bsrll(x) bsrll(x)
COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_ */
#endif /* _COSMO_SOURCE */
+3 -3
View File
@@ -29,7 +29,7 @@ static const char kDebruijn[64] = {
* Returns binary logarithm of 𝑥.
*
* ctz(𝑥) 31^clz(𝑥) clz(𝑥)
* uint32 𝑥 _bsf(𝑥) tzcnt(𝑥) ffs(𝑥) _bsr(𝑥) lzcnt(𝑥)
* uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥)
* 0x00000000 wut 32 0 wut 32
* 0x00000001 0 0 1 0 31
* 0x80000001 0 0 1 31 0
@@ -42,7 +42,7 @@ static const char kDebruijn[64] = {
* @param x is a 64-bit integer
* @return number in range 0..63 or undefined if 𝑥 is 0
*/
int(_bsrl)(long x) {
int(bsrl)(long x) {
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
@@ -52,4 +52,4 @@ int(_bsrl)(long x) {
return kDebruijn[(x * 0x03f79d71b4cb0a89ull) >> 58];
}
__weak_reference(_bsrl, _bsrll);
__weak_reference(bsrl, bsrll);
+1 -1
View File
@@ -58,7 +58,7 @@ int __cxa_atexit(void *fp, void *arg, void *pred) {
return enomem();
}
}
i = _bsr(~b->mask);
i = bsr(~b->mask);
b->mask |= 1u << i;
b->p[i].fp = fp;
b->p[i].arg = arg;
+1 -1
View File
@@ -43,7 +43,7 @@ StartOverLocked:
for (;;) {
mask = b->mask;
while (mask) {
i = _bsf(mask);
i = bsf(mask);
mask &= ~(1u << i);
if (!pred || pred == b->p[i].pred) {
b->mask &= ~(1u << i);
+1 -1
View File
@@ -43,7 +43,7 @@ const char *(DescribeFdSet)(char buf[N], ssize_t rc, int nfds, fd_set *fds) {
for (int fd = 0; fd < nfds; fd += 64) {
uint64_t w = fds->fds_bits[fd >> 6];
while (w) {
unsigned m = _bsr(w);
unsigned m = bsr(w);
w &= ~((uint64_t)1 << m);
if (fd + m < nfds) {
if (!gotsome) {
+1 -1
View File
@@ -48,7 +48,7 @@ char *FormatHex64(char p[hasatleast 19], uint64_t x, char z) {
*p++ = '0';
*p++ = 'x';
}
i = PickGoodWidth(_bsrl(x), z);
i = PickGoodWidth(bsrl(x), z);
do {
*p++ = "0123456789abcdef"[(x >> (i -= 4)) & 15];
} while (i);
+1 -1
View File
@@ -97,7 +97,7 @@ __excep0_isr:
xor %eax,%eax # kprintf is variadic, remember to
# pass no. of vector regs. used (= 0)
.weak kprintf # weakly link kprintf() because we
ezlea kprintf,bx # want to keep life.com tiny
ezlea kprintf,bx # want to keep examples/life tiny
test %ebx,%ebx
jz 8f
call *%rbx # print error message
+1 -1
View File
@@ -34,7 +34,7 @@ uint64_t tpenc(uint32_t c) {
int e, n;
uint64_t w;
if (0 <= c && c <= 127) return c;
e = kTpEnc[_bsr(c) - 7];
e = kTpEnc[bsr(c) - 7];
n = e & 0xff;
w = 0;
do {
+2 -2
View File
@@ -28,8 +28,8 @@
*
* This handler (1) makes binaries smaller by not embedding source code;
* and therefore (2) less likely to leak sensitive information. This can
* still print backtraces with function names if the .com.dbg file is in
* the same folder.
* still print backtraces with function names if the .dbg file is in the
* same folder.
*
* @see libc/log/thunks/__check_fail_ndebug.S
*/
+1 -1
View File
@@ -41,7 +41,7 @@ void __cxa_printexits(FILE *f, void *pred) {
do {
mask = b->mask;
while (mask) {
i = _bsf(mask);
i = bsf(mask);
mask &= ~(1u << i);
if (!pred || pred == b->p[i].pred) {
symbol = GetSymbolByAddr((intptr_t)b->p[i].fp);
+2 -2
View File
@@ -44,12 +44,12 @@
*
* delimited by spaces. For example, to see peak malloc usage:
*
* ./myprog.com 2>log
* ./myprog 2>log
* grep ^MEM log | sort -nk4 | tail -n10
*
* To see the largest allocations:
*
* ./myprog.com 2>log
* ./myprog 2>log
* grep ^MEM log | grep -v free | sort -nk7 | tail -n10
*/
+6
View File
@@ -61,6 +61,12 @@
#define _X86_CC_AVX512BF16 0
#endif
#ifdef __AVX512FP16__
#define _X86_CC_AVX512FP16 1
#else
#define _X86_CC_AVX512FP16 0
#endif
#ifdef __AVX512VBMI__
#define _X86_CC_AVX512VBMI 1
#else
+3 -1
View File
@@ -42,7 +42,8 @@
#define X86_AVX512VL 7H, EBX, 31, 0
#define X86_AVX512_4FMAPS 7H, EDX, 3, 0
#define X86_AVX512_4VNNIW 7H, EDX, 2, _X86_CC_AVX5124VNNIW
#define X86_AVX512_BF16 7H, EAX, 5, _X86_CC_AVX512BF16
#define X86_AVX512_FP16 7H, EDX, 23, _X86_CC_AVX512FP16
#define X86_AVX512_BF16 7H_1H, EAX, 5, _X86_CC_AVX512BF16
#define X86_AVX512_BITALG 7H, ECX, 12, 0
#define X86_AVX512_VBMI2 7H, ECX, 6, 0
#define X86_AVX512_VNNI 7H, ECX, 11, _X86_CC_AVX512VNNI
@@ -153,6 +154,7 @@
#define X86_XTPR 1H, ECX, 14, 0
#define X86_ZERO_FCS_FDS 7H, EBX, 13, 0
#define X86_JIT 80000001H, ECX, 31, 0 /* IsGenuineBlink() */
#define X86_HYBRID_CPU 7H, EDX, 15, 0 /* Has performance and efficiency cores */
/* clang-format on */
/* AMD specific features */
+2 -2
View File
@@ -25,12 +25,12 @@
#include "libc/fmt/conv.h"
#include "libc/fmt/itoa.h"
#include "libc/fmt/magnumstrs.internal.h"
#include "libc/serialize.h"
#include "libc/intrin/getenv.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/limits.h"
#include "libc/macros.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/serialize.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/lock.h"
@@ -986,7 +986,7 @@ int _cocmd(int argc, char **argv, char **envp) {
size_t globCount = 0;
int globFlags = 0;
glob_t globTheBuilder;
prog = argc > 0 ? argv[0] : "cocmd.com";
prog = argc > 0 ? argv[0] : "cocmd";
for (i = 1; i < 32; ++i) {
unsupported[i] = true;
+12 -16
View File
@@ -53,23 +53,19 @@ static struct {
} g_execve;
static bool IsApeFile(const char *path) {
if (endswith(path, ".com")) {
return true;
} else {
bool res = false;
BLOCK_SIGNALS;
BLOCK_CANCELATION;
int fd;
char buf[8];
int flags = O_RDONLY | O_NOCTTY | O_NONBLOCK | O_CLOEXEC;
if ((fd = sys_openat(AT_FDCWD, path, flags, 0)) != -1) {
res = sys_pread(fd, buf, 8, 0, 0) == 8 && IsApeLoadable(buf);
sys_close(fd);
}
ALLOW_CANCELATION;
ALLOW_SIGNALS;
return res;
bool res = false;
BLOCK_SIGNALS;
BLOCK_CANCELATION;
int fd;
char buf[8];
int flags = O_RDONLY | O_NOCTTY | O_NONBLOCK | O_CLOEXEC;
if ((fd = sys_openat(AT_FDCWD, path, flags, 0)) != -1) {
res = sys_pread(fd, buf, 8, 0, 0) == 8 && IsApeLoadable(buf);
sys_close(fd);
}
ALLOW_CANCELATION;
ALLOW_SIGNALS;
return res;
}
static const char *Join(const char *a, const char *b, char buf[PATH_MAX]) {
+1 -1
View File
@@ -587,7 +587,7 @@ errno_t posix_spawn(int *pid, const char *path,
if (flags & POSIX_SPAWN_SETRLIMIT) {
int rlimset = (*attrp)->rlimset;
while (rlimset) {
int resource = _bsf(rlimset);
int resource = bsf(rlimset);
rlimset &= ~(1u << resource);
if (setrlimit(resource, (*attrp)->rlim + resource)) {
// MacOS ARM64 RLIMIT_STACK always returns EINVAL
+1 -1
View File
@@ -160,7 +160,7 @@ static void EfiInitAcpi(struct mman *mm, EFI_SYSTEM_TABLE *SystemTable) {
* -net none \
* -drive format=raw,file=fat:rw:o/tool/viz
* FS0:
* deathstar.com
* deathstar
*
* @see libc/dce.h
*/
+6 -6
View File
@@ -88,7 +88,7 @@ static struct SymbolTable *GetSymbolTableFromZip(struct Zipos *zipos) {
}
/**
* Reads symbol table from .com.dbg file.
* Reads symbol table from .dbg file.
* @note This code can't depend on dlmalloc()
*/
static struct SymbolTable *GetSymbolTableFromElf(void) {
@@ -109,11 +109,11 @@ static struct SymbolTable *GetSymbolTableFromElf(void) {
* __static_yoink("__zipos_get");
*
* In that case, the symbol table may be read from `/zip/.symtab` which
* is generated by `o//tool/build/symtab.com`. The second strategy is to
* look for the concomitant `.com.dbg` executable, which may very well
* be the one currently executing, or it could be placed in the same
* folder as your `.com` binary, or lastly, it could be explicitly
* specified via the `COMDBG` environment variable.
* is generated by `o//tool/build/symtab`. The second strategy is to
* look for the concomitant `.dbg` executable, which may very well be
* the one currently executing, or it could be placed in the same folder
* as your binary, or lastly, it could be explicitly specified via the
* `COMDBG` environment variable.
*
* Function tracing is disabled throughout the duration of this call.
* Backtraces and other core runtime functionality depend on this.
+1 -1
View File
@@ -73,7 +73,7 @@
#define FRAME(x) ((int)((intptr_t)(x) >> 16))
static inline pureconst unsigned long __rounddown2pow(unsigned long x) {
return x ? 1ul << _bsrl(x) : 0;
return x ? 1ul << bsrl(x) : 0;
}
static wontreturn void __mmap_die(const char *s) {
+1 -1
View File
@@ -55,7 +55,7 @@ ssize_t appendr(char **b, size_t i) {
z = appendz((p = *b));
if (i != z.i || !p) {
n = ROUNDUP(i + 1, 8) + W;
if (n > z.n || _bsrl(n) < _bsrl(z.n)) {
if (n > z.n || bsrl(n) < bsrl(z.n)) {
if ((p = realloc(p, n))) {
z.n = malloc_usable_size(p);
unassert(!(z.n & (W - 1)));
+2 -2
View File
@@ -18,10 +18,10 @@
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/assert.h"
#include "libc/dce.h"
#include "libc/serialize.h"
#include "libc/intrin/bsr.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/serialize.h"
#include "libc/stdio/append.h"
#define W sizeof(size_t)
@@ -59,7 +59,7 @@ ssize_t appendw(char **b, uint64_t w) {
char *p, *q;
struct appendz z;
z = appendz((p = *b));
l = w ? (_bsrl(w) >> 3) + 1 : 1;
l = w ? (bsrl(w) >> 3) + 1 : 1;
n = ROUNDUP(z.i + 8 + 1, 8) + W;
if (n > z.n) {
if (!z.n) z.n = W * 2;
+3 -3
View File
@@ -359,14 +359,14 @@ static int __fmt_stoa_wide(out_f out, void *a, uint64_t w) {
char buf[8];
if (!isascii(w)) w = tpenc(w);
WRITE64LE(buf, w);
return out(buf, a, w ? (_bsr(w) >> 3) + 1 : 1);
return out(buf, a, w ? (bsr(w) >> 3) + 1 : 1);
}
static int __fmt_stoa_bing(out_f out, void *a, uint64_t w) {
char buf[8];
w = tpenc(kCp437[w & 0xFF]);
WRITE64LE(buf, w);
return out(buf, a, w ? (_bsr(w) >> 3) + 1 : 1);
return out(buf, a, w ? (bsr(w) >> 3) + 1 : 1);
}
static int __fmt_stoa_quoted(out_f out, void *a, uint64_t w) {
@@ -377,7 +377,7 @@ static int __fmt_stoa_quoted(out_f out, void *a, uint64_t w) {
w = tpenc(w);
}
WRITE64LE(buf, w);
return out(buf, a, w ? (_bsr(w) >> 3) + 1 : 1);
return out(buf, a, w ? (bsr(w) >> 3) + 1 : 1);
}
/**
+6 -2
View File
@@ -29,8 +29,12 @@ int64_t GetZipCfileCompressedSize(const uint8_t *z) {
const uint8_t *pe = p + ZIP_CFILE_EXTRASIZE(z);
for (; p + ZIP_EXTRA_SIZE(p) <= pe; p += ZIP_EXTRA_SIZE(p)) {
if (ZIP_EXTRA_HEADERID(p) == kZipExtraZip64) {
if (8 <= ZIP_EXTRA_CONTENTSIZE(p)) {
return ZIP_READ64(ZIP_EXTRA_CONTENT(p));
int offset = 0;
if (ZIP_CFILE_UNCOMPRESSEDSIZE(z) == 0xFFFFFFFFu) {
offset += 8;
}
if (offset + 8 <= ZIP_EXTRA_CONTENTSIZE(p)) {
return ZIP_READ64(ZIP_EXTRA_CONTENT(p) + offset);
}
}
}
+2 -6
View File
@@ -29,12 +29,8 @@ int64_t GetZipCfileUncompressedSize(const uint8_t *z) {
const uint8_t *pe = p + ZIP_CFILE_EXTRASIZE(z);
for (; p + ZIP_EXTRA_SIZE(p) <= pe; p += ZIP_EXTRA_SIZE(p)) {
if (ZIP_EXTRA_HEADERID(p) == kZipExtraZip64) {
int offset = 0;
if (ZIP_CFILE_COMPRESSEDSIZE(z) == 0xFFFFFFFFu) {
offset += 8;
}
if (offset + 8 <= ZIP_EXTRA_CONTENTSIZE(p)) {
return ZIP_READ64(ZIP_EXTRA_CONTENT(p) + offset);
if (8 <= ZIP_EXTRA_CONTENTSIZE(p)) {
return ZIP_READ64(ZIP_EXTRA_CONTENT(p));
}
}
}
+6 -2
View File
@@ -29,8 +29,12 @@ int64_t GetZipLfileCompressedSize(const uint8_t *z) {
const uint8_t *pe = p + ZIP_LFILE_EXTRASIZE(z);
for (; p + ZIP_EXTRA_SIZE(p) <= pe; p += ZIP_EXTRA_SIZE(p)) {
if (ZIP_EXTRA_HEADERID(p) == kZipExtraZip64) {
if (8 <= ZIP_EXTRA_CONTENTSIZE(p)) {
return ZIP_READ64(ZIP_EXTRA_CONTENT(p));
int offset = 0;
if (ZIP_LFILE_UNCOMPRESSEDSIZE(z) == 0xFFFFFFFFu) {
offset += 8;
}
if (offset + 8 <= ZIP_EXTRA_CONTENTSIZE(p)) {
return ZIP_READ64(ZIP_EXTRA_CONTENT(p) + offset);
}
}
}
+2 -6
View File
@@ -29,12 +29,8 @@ int64_t GetZipLfileUncompressedSize(const uint8_t *z) {
const uint8_t *pe = p + ZIP_LFILE_EXTRASIZE(z);
for (; p + ZIP_EXTRA_SIZE(p) <= pe; p += ZIP_EXTRA_SIZE(p)) {
if (ZIP_EXTRA_HEADERID(p) == kZipExtraZip64) {
int offset = 0;
if (ZIP_LFILE_COMPRESSEDSIZE(z) == 0xFFFFFFFFu) {
offset += 8;
}
if (offset + 8 <= ZIP_EXTRA_CONTENTSIZE(p)) {
return ZIP_READ64(ZIP_EXTRA_CONTENT(p) + offset);
if (8 <= ZIP_EXTRA_CONTENTSIZE(p)) {
return ZIP_READ64(ZIP_EXTRA_CONTENT(p));
}
}
}
+1 -1
View File
@@ -5,7 +5,7 @@
#define ThomPikeCont(x) (0200 == (0300 & (x)))
#define ThomPikeByte(x) ((x) & (((1 << ThomPikeMsb(x)) - 1) | 3))
#define ThomPikeLen(x) (7 - ThomPikeMsb(x))
#define ThomPikeMsb(x) ((255 & (x)) < 252 ? _bsr(255 & ~(x)) : 1)
#define ThomPikeMsb(x) ((255 & (x)) < 252 ? bsr(255 & ~(x)) : 1)
#define ThomPikeMerge(x, y) ((x) << 6 | (077 & (y)))
#endif /* COSMOPOLITAN_LIBC_STR_THOMPIKE_H_ */
+1 -1
View File
@@ -18,7 +18,7 @@ forceinline int tpdecodecb(wint_t *out, int first,
if ((wc = get(arg, i++)) == -1) return -1;
}
if (__builtin_expect(!(0 <= wc && wc <= 0x7F), 0)) {
msb = wc < 252 ? _bsr(~wc & 0xff) : 1;
msb = wc < 252 ? bsr(~wc & 0xff) : 1;
need = 7 - msb;
wc &= ((1u << msb) - 1) | 0b00000011;
for (j = 1; j < need; ++j) {
+2 -2
View File
@@ -1,11 +1,11 @@
#!/bin/sh
[ -d libc/str ] || exit
[ -x o//examples/curl.com ] || make -j8 o//examples/curl.com || exit
[ -x o//tool/curl/curl ] || make -j8 o//tool/curl/curl || exit
mkdir -p o/tmp/ || exit
shineget() {
echo $2
o//examples/curl.com $2 >o/tmp/$$ || exit
o//tool/curl/curl $2 >o/tmp/$$ || exit
mv o/tmp/$$ $1 || exit
}
+2 -2
View File
@@ -32,8 +32,8 @@ COSMOPOLITAN_C_START_
/**
* Declares benchmark function.
*
* These only run if (1) the -b flag is passed to the FOO_test.com; and
* (2) the unit tests passed. It's just an ordinary function, that gets
* These only run if (1) the -b flag is passed to the FOO_test; and (2)
* the unit tests passed. It's just an ordinary function, that gets
* registered with the linker. It should print things to stdout.
*
* @see EZBENCH()
+1 -1
View File
@@ -162,7 +162,7 @@ dontasan int main(int argc, char *argv[]) {
// we're done!
int status = MIN(255, g_testlib_failed);
if (!status && IsRunningUnderMake()) {
return 254; // compile.com considers this 0 and propagates output
return 254; // compile considers this 0 and propagates output
} else if (!status && _weaken(pthread_exit)) {
_weaken(pthread_exit)(0);
} else {
+4 -4
View File
@@ -81,10 +81,10 @@ void testlib_runtestcases(const testfn_t *start, const testfn_t *end,
// getpid() calls are inserted to help visually see tests in traces
// which can be performed on Linux, FreeBSD, OpenBSD, and XNU:
//
// strace -f o/default/test.com |& less
// truss o/default/test.com |& less
// ktrace -f trace o/default/test.com </dev/null; kdump -f trace | less
// dtruss o/default/test.com |& less
// strace -f o/default/test |& less
// truss o/default/test |& less
// ktrace -f trace o/default/test </dev/null; kdump -f trace | less
// dtruss o/default/test |& less
//
// Test cases are iterable via a decentralized section. Your TEST()
// macro inserts .testcase.SUITENAME sections into the binary which
+10
View File
@@ -100,6 +100,16 @@ float fmaf(float x, float y, float z)
#else
#ifdef __x86_64__
if (X86_HAVE(FMA)) {
asm("vfmadd132ss\t%1,%2,%0" : "+x"(x) : "x"(y), "x"(z));
return x;
} else if (X86_HAVE(FMA4)) {
asm("vfmaddss\t%3,%2,%1,%0" : "=x"(x) : "x"(x), "x"(y), "x"(z));
return x;
}
#endif
/* A double has more than twice as much precision than a float,
so direct double-precision arithmetic suffices, except where
double rounding occurs. */
+2 -2
View File
@@ -16,7 +16,6 @@
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/serialize.h"
#include "libc/intrin/bsr.h"
#include "libc/intrin/packsswb.h"
#include "libc/intrin/pandn.h"
@@ -26,6 +25,7 @@
#include "libc/intrin/punpckhbw.h"
#include "libc/intrin/punpcklbw.h"
#include "libc/mem/mem.h"
#include "libc/serialize.h"
#include "libc/str/str.h"
#include "libc/str/thompike.h"
#include "libc/str/utf16.h"
@@ -78,7 +78,7 @@ char *utf16to8(const char16_t *p, size_t n, size_t *z) {
} else {
w = tpenc(x);
WRITE64LE(q, w);
q += _bsr(w) >> 3;
q += bsr(w) >> 3;
q += 1;
}
}
+1 -1
View File
@@ -36,7 +36,7 @@ uint32_t FingerSyn(const char *p, size_t n) {
// ttl<=128 Windows, OpenVMS 8+
// ttl<=64 Mac, Linux, BSD, Solaris 8+, Tru64, HP-UX
ttl = p[8] & 255;
h += _bsr(MAX(1, ttl - 1));
h += bsr(MAX(1, ttl - 1));
h *= 0x9e3779b1;
// TCP Options
// We care about the order and presence of leading common options.
+1 -1
View File
@@ -21,7 +21,7 @@
const char *GetOsName(int os) {
if (os) {
switch (_bsr(os)) {
switch (bsr(os)) {
case 0:
return "LINUX";
case 1:
-8
View File
@@ -68,14 +68,6 @@ o/$(MODE)/net/turfwar/turfbean.com.dbg: \
$(APE_NO_MODIFY_SELF)
@$(APELINK)
o/$(MODE)/net/turfwar/turfbean.com: \
o/$(MODE)/net/turfwar/turfbean.com.dbg \
o/$(MODE)/third_party/zip/zip.com \
o/$(MODE)/tool/build/symtab.com
@$(MAKE_OBJCOPY)
@$(MAKE_SYMTAB_CREATE)
@$(MAKE_SYMTAB_ZIP)
o/$(MODE)/net/turfwar/.init.lua.zip.o: private \
ZIPOBJ_FLAGS += \
-B
+1 -1
View File
@@ -1538,7 +1538,7 @@ bool GeneratePlot(struct Asset *out, long block, long cash) {
CHECK_SQL(sqlite3_exec(db, "BEGIN TRANSACTION", 0, 0, 0));
area = XN * YN;
mask = area - 1;
clump = 32 - _bsr(area) - 8;
clump = 32 - bsr(area) - 8;
while ((rc = DbStep(stmt)) != SQLITE_DONE) {
if (rc != SQLITE_ROW) CHECK_DB(rc);
ip = sqlite3_column_int64(stmt, 0);
+4 -4
View File
@@ -11,13 +11,13 @@ TEST_DSP_CORE_OBJS = \
$(TEST_DSP_CORE_SRCS:%.c=o/$(MODE)/%.o)
TEST_DSP_CORE_COMS = \
$(TEST_DSP_CORE_SRCS:%.c=o/$(MODE)/%.com)
$(TEST_DSP_CORE_SRCS:%.c=o/$(MODE)/%)
TEST_DSP_CORE_TESTS = \
$(TEST_DSP_CORE_SRCS_TEST:%.c=o/$(MODE)/%.com.ok)
$(TEST_DSP_CORE_SRCS_TEST:%.c=o/$(MODE)/%.ok)
TEST_DSP_CORE_CHECKS = \
$(TEST_DSP_CORE_SRCS_TEST:%.c=o/$(MODE)/%.com.runs)
$(TEST_DSP_CORE_SRCS_TEST:%.c=o/$(MODE)/%.runs)
TEST_DSP_CORE_DIRECTDEPS = \
DSP_CORE \
@@ -37,7 +37,7 @@ o/$(MODE)/test/dsp/core/core.pkg: \
$(TEST_DSP_CORE_OBJS) \
$(foreach x,$(TEST_DSP_CORE_DIRECTDEPS),$($(x)_A).pkg)
o/$(MODE)/test/dsp/core/%.com.dbg: \
o/$(MODE)/test/dsp/core/%.dbg: \
$(TEST_DSP_CORE_DEPS) \
o/$(MODE)/test/dsp/core/%.o \
$(LIBC_TESTMAIN) \
+4 -4
View File
@@ -11,13 +11,13 @@ TEST_DSP_SCALE_OBJS = \
$(TEST_DSP_SCALE_SRCS:%.c=o/$(MODE)/%.o)
TEST_DSP_SCALE_COMS = \
$(TEST_DSP_SCALE_SRCS:%.c=o/$(MODE)/%.com)
$(TEST_DSP_SCALE_SRCS:%.c=o/$(MODE)/%)
TEST_DSP_SCALE_TESTS = \
$(TEST_DSP_SCALE_SRCS_TEST:%.c=o/$(MODE)/%.com.ok)
$(TEST_DSP_SCALE_SRCS_TEST:%.c=o/$(MODE)/%.ok)
TEST_DSP_SCALE_CHECKS = \
$(TEST_DSP_SCALE_SRCS_TEST:%.c=o/$(MODE)/%.com.runs)
$(TEST_DSP_SCALE_SRCS_TEST:%.c=o/$(MODE)/%.runs)
TEST_DSP_SCALE_DIRECTDEPS = \
DSP_CORE \
@@ -42,7 +42,7 @@ o/$(MODE)/test/dsp/scale/scale.pkg: \
$(TEST_DSP_SCALE_OBJS) \
$(foreach x,$(TEST_DSP_SCALE_DIRECTDEPS),$($(x)_A).pkg)
o/$(MODE)/test/dsp/scale/%.com.dbg: \
o/$(MODE)/test/dsp/scale/%.dbg: \
$(TEST_DSP_SCALE_DEPS) \
o/$(MODE)/test/dsp/scale/%.o \
o/$(MODE)/test/dsp/scale/scale.pkg \
+4 -4
View File
@@ -11,13 +11,13 @@ TEST_DSP_TTY_OBJS = \
$(TEST_DSP_TTY_SRCS:%.c=o/$(MODE)/%.o)
TEST_DSP_TTY_COMS = \
$(TEST_DSP_TTY_SRCS:%.c=o/$(MODE)/%.com)
$(TEST_DSP_TTY_SRCS:%.c=o/$(MODE)/%)
TEST_DSP_TTY_TESTS = \
$(TEST_DSP_TTY_SRCS_TEST:%.c=o/$(MODE)/%.com.ok)
$(TEST_DSP_TTY_SRCS_TEST:%.c=o/$(MODE)/%.ok)
TEST_DSP_TTY_CHECKS = \
$(TEST_DSP_TTY_SRCS_TEST:%.c=o/$(MODE)/%.com.runs)
$(TEST_DSP_TTY_SRCS_TEST:%.c=o/$(MODE)/%.runs)
TEST_DSP_TTY_DIRECTDEPS = \
DSP_TTY \
@@ -38,7 +38,7 @@ o/$(MODE)/test/dsp/tty/tty.pkg: \
$(TEST_DSP_TTY_OBJS) \
$(foreach x,$(TEST_DSP_TTY_DIRECTDEPS),$($(x)_A).pkg)
o/$(MODE)/test/dsp/tty/%.com.dbg: \
o/$(MODE)/test/dsp/tty/%.dbg: \
$(TEST_DSP_TTY_DEPS) \
o/$(MODE)/test/dsp/tty/%.o \
o/$(MODE)/test/dsp/tty/tty.pkg \
+30 -30
View File
@@ -13,21 +13,21 @@ TEST_LIBC_CALLS_OBJS = \
$(TEST_LIBC_CALLS_SRCS:%.c=o/$(MODE)/%.o)
TEST_LIBC_CALLS_COMS = \
$(TEST_LIBC_CALLS_SRCS_TEST:%.c=o/$(MODE)/%.com)
$(TEST_LIBC_CALLS_SRCS_TEST:%.c=o/$(MODE)/%)
TEST_LIBC_CALLS_BINS = \
$(TEST_LIBC_CALLS_COMS) \
$(TEST_LIBC_CALLS_COMS:%=%.dbg) \
o/$(MODE)/test/libc/calls/life-nomod.com \
o/$(MODE)/test/libc/calls/life-classic.com \
o/$(MODE)/test/libc/calls/zipread.com.dbg \
o/$(MODE)/test/libc/calls/zipread.com
o/$(MODE)/test/libc/calls/life-nomod \
o/$(MODE)/test/libc/calls/life-classic \
o/$(MODE)/test/libc/calls/zipread.dbg \
o/$(MODE)/test/libc/calls/zipread
TEST_LIBC_CALLS_TESTS = \
$(TEST_LIBC_CALLS_SRCS_TEST:%.c=o/$(MODE)/%.com.ok)
$(TEST_LIBC_CALLS_SRCS_TEST:%.c=o/$(MODE)/%.ok)
TEST_LIBC_CALLS_CHECKS = \
$(TEST_LIBC_CALLS_SRCS_TEST:%.c=o/$(MODE)/%.com.runs)
$(TEST_LIBC_CALLS_SRCS_TEST:%.c=o/$(MODE)/%.runs)
TEST_LIBC_CALLS_DIRECTDEPS = \
DSP_CORE \
@@ -61,7 +61,7 @@ o/$(MODE)/test/libc/calls/calls.pkg: \
$(TEST_LIBC_CALLS_OBJS) \
$(foreach x,$(TEST_LIBC_CALLS_DIRECTDEPS),$($(x)_A).pkg)
o/$(MODE)/test/libc/calls/%.com.dbg: \
o/$(MODE)/test/libc/calls/%.dbg: \
$(TEST_LIBC_CALLS_DEPS) \
o/$(MODE)/test/libc/calls/%.o \
o/$(MODE)/test/libc/calls/calls.pkg \
@@ -70,7 +70,7 @@ o/$(MODE)/test/libc/calls/%.com.dbg: \
$(APE_NO_MODIFY_SELF)
@$(APELINK)
o/$(MODE)/test/libc/calls/stat_test.com.dbg: \
o/$(MODE)/test/libc/calls/stat_test.dbg: \
$(TEST_LIBC_CALLS_DEPS) \
o/$(MODE)/test/libc/calls/stat_test.o \
o/$(MODE)/third_party/python/Lib/test/tokenize_tests-latin1-coding-cookie-and-utf8-bom-sig.txt.zip.o \
@@ -80,7 +80,7 @@ o/$(MODE)/test/libc/calls/stat_test.com.dbg: \
$(APE_NO_MODIFY_SELF)
@$(APELINK)
o/$(MODE)/test/libc/calls/unveil_test.com.dbg: \
o/$(MODE)/test/libc/calls/unveil_test.dbg: \
$(TEST_LIBC_CALLS_DEPS) \
o/$(MODE)/test/libc/calls/unveil_test.o \
o/$(MODE)/test/libc/mem/prog/life.elf.zip.o \
@@ -91,7 +91,7 @@ o/$(MODE)/test/libc/calls/unveil_test.com.dbg: \
$(APE_NO_MODIFY_SELF)
@$(APELINK)
o/$(MODE)/test/libc/calls/pledge_test.com.dbg: \
o/$(MODE)/test/libc/calls/pledge_test.dbg: \
$(TEST_LIBC_CALLS_DEPS) \
o/$(MODE)/test/libc/calls/pledge_test.o \
o/$(MODE)/test/libc/mem/prog/life.elf.zip.o \
@@ -102,14 +102,14 @@ o/$(MODE)/test/libc/calls/pledge_test.com.dbg: \
$(APE_NO_MODIFY_SELF)
@$(APELINK)
o/$(MODE)/test/libc/calls/life-classic.com.dbg: \
o/$(MODE)/test/libc/calls/life-classic.dbg: \
$(LIBC_RUNTIME) \
o/$(MODE)/test/libc/calls/life.o \
$(CRT) \
$(APE)
@$(APELINK)
o/$(MODE)/test/libc/calls/life-nomod.com.dbg: \
o/$(MODE)/test/libc/calls/life-nomod.dbg: \
$(LIBC_RUNTIME) \
o/$(MODE)/test/libc/calls/life.o \
$(CRT) \
@@ -117,43 +117,43 @@ o/$(MODE)/test/libc/calls/life-nomod.com.dbg: \
@$(APELINK)
o/$(MODE)/test/libc/calls/tiny64.elf.zip.o \
o/$(MODE)/test/libc/calls/life-nomod.com.zip.o \
o/$(MODE)/test/libc/calls/life-classic.com.zip.o \
o/$(MODE)/test/libc/calls/zipread.com.zip.o: private \
o/$(MODE)/test/libc/calls/life-nomod.zip.o \
o/$(MODE)/test/libc/calls/life-classic.zip.o \
o/$(MODE)/test/libc/calls/zipread.zip.o: private \
ZIPOBJ_FLAGS += \
-B
# TODO(jart): Have pledge() support SIOCGIFCONF
o/$(MODE)/test/libc/calls/ioctl_test.com.runs: \
o/$(MODE)/test/libc/calls/ioctl_test.runs: \
private .PLEDGE =
o/$(MODE)/test/libc/calls/lseek_test.com.runs \
o/$(MODE)/test/libc/calls/poll_test.com.runs: \
o/$(MODE)/test/libc/calls/lseek_test.runs \
o/$(MODE)/test/libc/calls/poll_test.runs: \
private .PLEDGE = stdio rpath wpath cpath fattr proc inet
o/$(MODE)/test/libc/calls/fcntl_test.com.runs \
o/$(MODE)/test/libc/calls/lock_test.com.runs \
o/$(MODE)/test/libc/calls/lock2_test.com.runs \
o/$(MODE)/test/libc/calls/lock_ofd_test.com.runs: \
o/$(MODE)/test/libc/calls/fcntl_test.runs \
o/$(MODE)/test/libc/calls/lock_test.runs \
o/$(MODE)/test/libc/calls/lock2_test.runs \
o/$(MODE)/test/libc/calls/lock_ofd_test.runs: \
private .PLEDGE = stdio rpath wpath cpath fattr proc flock
o/$(MODE)/test/libc/calls/unveil_test.com.runs \
o/$(MODE)/test/libc/calls/openbsd_test.com.runs: \
o/$(MODE)/test/libc/calls/unveil_test.runs \
o/$(MODE)/test/libc/calls/openbsd_test.runs: \
private .PLEDGE = stdio rpath wpath cpath fattr proc unveil
o/$(MODE)/test/libc/calls/fexecve_test.com.runs: \
o/$(MODE)/test/libc/calls/fexecve_test.runs: \
private .UNSANDBOXED = 1 # for memfd_create()
o/$(MODE)/test/libc/calls/execve_test.com.runs: \
o/$(MODE)/test/libc/calls/execve_test.runs: \
private .UNSANDBOXED = 1 # for memfd_create()
o/$(MODE)/test/libc/calls/read_test.com.runs: \
o/$(MODE)/test/libc/calls/read_test.runs: \
private .UNVEIL += /dev/zero
# TODO(jart): Update nointernet() to allow AF_INET6
o/$(MODE)/test/libc/calls/pledge_test.com.runs: \
o/$(MODE)/test/libc/calls/pledge_test.runs: \
private .INTERNET = 1
o/$(MODE)/test/libc/calls/pledge_test.com.runs: \
o/$(MODE)/test/libc/calls/pledge_test.runs: \
private .PLEDGE =
.PHONY: o/$(MODE)/test/libc/calls
+10 -12
View File
@@ -55,35 +55,34 @@ TEST(commandv, testPathSearch) {
}
TEST(commandv, testSlashes_wontSearchPath_butChecksAccess) {
EXPECT_SYS(0, 3, creat("home/sh.com", 0755));
EXPECT_SYS(0, 3, creat("home/sh", 0755));
EXPECT_SYS(0, 2, write(3, "MZ", 2));
EXPECT_SYS(0, 0, close(3));
EXPECT_STREQ("home/sh.com",
commandv("home/sh.com", pathbuf, sizeof(pathbuf)));
EXPECT_STREQ("home/sh", commandv("home/sh", pathbuf, sizeof(pathbuf)));
}
TEST(commandv, testSameDir_doesntHappenByDefaultUnlessItsWindows) {
EXPECT_SYS(0, 3, creat("bog.com", 0755));
EXPECT_SYS(0, 3, creat("bog", 0755));
EXPECT_SYS(0, 2, write(3, "MZ", 2));
EXPECT_SYS(0, 0, close(3));
EXPECT_STREQ(NULL, commandv("bog.com", pathbuf, sizeof(pathbuf)));
EXPECT_STREQ(NULL, commandv("bog", pathbuf, sizeof(pathbuf)));
EXPECT_EQ(ENOENT, errno);
}
TEST(commandv, testSameDir_willHappenWithColonBlank) {
ASSERT_NE(-1, setenv("PATH", "bin:", true));
EXPECT_SYS(0, 3, creat("bog.com", 0755));
EXPECT_SYS(0, 3, creat("bog", 0755));
EXPECT_SYS(0, 2, write(3, "MZ", 2));
EXPECT_SYS(0, 0, close(3));
EXPECT_STREQ("bog.com", commandv("bog.com", pathbuf, sizeof(pathbuf)));
EXPECT_STREQ("bog", commandv("bog", pathbuf, sizeof(pathbuf)));
}
TEST(commandv, testSameDir_willHappenWithColonBlank2) {
ASSERT_NE(-1, setenv("PATH", ":bin", true));
EXPECT_SYS(0, 3, creat("bog.com", 0755));
EXPECT_SYS(0, 3, creat("bog", 0755));
EXPECT_SYS(0, 2, write(3, "MZ", 2));
EXPECT_SYS(0, 0, close(3));
EXPECT_STREQ("bog.com", commandv("bog.com", pathbuf, sizeof(pathbuf)));
EXPECT_STREQ("bog", commandv("bog", pathbuf, sizeof(pathbuf)));
}
TEST(commandv, test_DirPaths_wontConsiderDirectoriesExecutable) {
@@ -95,9 +94,8 @@ TEST(commandv, test_DirPaths_wontConsiderDirectoriesExecutable) {
TEST(commandv, test_DirPaths_wontConsiderDirectoriesExecutable2) {
ASSERT_NE(-1, setenv("PATH", ":bin", true));
EXPECT_SYS(0, 0, mkdir("this_is_a_directory.com", 0755));
EXPECT_STREQ(NULL,
commandv("this_is_a_directory.com", pathbuf, sizeof(pathbuf)));
EXPECT_SYS(0, 0, mkdir("this_is_a_directory", 0755));
EXPECT_STREQ(NULL, commandv("this_is_a_directory", pathbuf, sizeof(pathbuf)));
EXPECT_EQ(ENOENT, errno);
}
@@ -124,7 +124,7 @@ TEST(GetProgramExecutableName, movedSelf) {
if (skiptests) return;
if (IsAarch64() && IsQemuUser()) {
// clang-format off
// TODO(mrdomino): fix: make -j8 m=aarch64 o/aarch64/test/libc/calls/getprogramexecutablename_test.com.ok
// TODO(mrdomino): fix: make -j8 m=aarch64 o/aarch64/test/libc/calls/getprogramexecutablename_test.ok
// possibly related to the intersection of binfmt_misc and qemu-aarch64
// clang-format on
return;
+2 -2
View File
@@ -85,9 +85,9 @@ TEST(mkntcmdline, fixit) {
}
TEST(mkntcmdline, testWut) {
char *argv[] = {"C:\\Users\\jart\\𝑟𝑒𝑑𝑏𝑒𝑎𝑛.com", "--strace", NULL};
char *argv[] = {"C:\\Users\\jart\\𝑟𝑒𝑑𝑏𝑒𝑎𝑛", "--strace", NULL};
EXPECT_NE(-1, mkntcmdline(cmdline, argv));
EXPECT_STREQ(u"C:\\Users\\jart\\𝑟𝑒𝑑𝑏𝑒𝑎𝑛.com --strace", cmdline);
EXPECT_STREQ(u"C:\\Users\\jart\\𝑟𝑒𝑑𝑏𝑒𝑎𝑛 --strace", cmdline);
}
BENCH(mkntcmdline, lotsOfArgs) {
+2 -2
View File
@@ -37,8 +37,8 @@ TEST(mkntpath, testSlashes) {
* all it takes to make the feature entirely useless to us, similar to
* the law of noncontradiction. We address the issue as follows:
*/
EXPECT_EQ(9, __mkntpath("o/foo.com", p));
EXPECT_STREQ(u"o\\foo.com", p);
EXPECT_EQ(5, __mkntpath("o/foo", p));
EXPECT_STREQ(u"o\\foo", p);
}
TEST(mkntpath, testUnicode) {
+33 -33
View File
@@ -6,58 +6,58 @@ PKGS += TEST_LIBC_FMT
TEST_LIBC_FMT_SRCS := $(wildcard test/libc/fmt/*.c)
TEST_LIBC_FMT_SRCS_TEST = $(filter %_test.c,$(TEST_LIBC_FMT_SRCS))
TEST_LIBC_FMT_BINS = $(TEST_LIBC_FMT_COMS) $(TEST_LIBC_FMT_COMS:%=%.dbg)
TEST_LIBC_FMT_TESTS = $(TEST_LIBC_FMT_SRCS_TEST:%.c=o/$(MODE)/%.com.ok)
TEST_LIBC_FMT_TESTS = $(TEST_LIBC_FMT_SRCS_TEST:%.c=o/$(MODE)/%.ok)
TEST_LIBC_FMT_OBJS = \
TEST_LIBC_FMT_OBJS = \
$(TEST_LIBC_FMT_SRCS:%.c=o/$(MODE)/%.o)
TEST_LIBC_FMT_COMS = \
$(TEST_LIBC_FMT_SRCS:%.c=o/$(MODE)/%.com)
TEST_LIBC_FMT_COMS = \
$(TEST_LIBC_FMT_SRCS:%.c=o/$(MODE)/%)
TEST_LIBC_FMT_CHECKS = \
$(TEST_LIBC_FMT_SRCS_TEST:%.c=o/$(MODE)/%.com.runs)
TEST_LIBC_FMT_CHECKS = \
$(TEST_LIBC_FMT_SRCS_TEST:%.c=o/$(MODE)/%.runs)
TEST_LIBC_FMT_DIRECTDEPS = \
LIBC_FMT \
LIBC_INTRIN \
LIBC_LOG \
LIBC_MEM \
LIBC_NEXGEN32E \
LIBC_RUNTIME \
LIBC_STDIO \
LIBC_STR \
LIBC_SYSV \
LIBC_TESTLIB \
LIBC_TINYMATH \
LIBC_X \
TEST_LIBC_FMT_DIRECTDEPS = \
LIBC_FMT \
LIBC_INTRIN \
LIBC_LOG \
LIBC_MEM \
LIBC_NEXGEN32E \
LIBC_RUNTIME \
LIBC_STDIO \
LIBC_STR \
LIBC_SYSV \
LIBC_TESTLIB \
LIBC_TINYMATH \
LIBC_X \
THIRD_PARTY_GDTOA
TEST_LIBC_FMT_DEPS := \
TEST_LIBC_FMT_DEPS := \
$(call uniq,$(foreach x,$(TEST_LIBC_FMT_DIRECTDEPS),$($(x))))
o/$(MODE)/test/libc/fmt/fmt.pkg: \
$(TEST_LIBC_FMT_OBJS) \
o/$(MODE)/test/libc/fmt/fmt.pkg: \
$(TEST_LIBC_FMT_OBJS) \
$(foreach x,$(TEST_LIBC_FMT_DIRECTDEPS),$($(x)_A).pkg)
o/$(MODE)/test/libc/fmt/%.com.dbg: \
$(TEST_LIBC_FMT_DEPS) \
o/$(MODE)/test/libc/fmt/%.o \
o/$(MODE)/test/libc/fmt/fmt.pkg \
$(LIBC_TESTMAIN) \
$(CRT) \
o/$(MODE)/test/libc/fmt/%.dbg: \
$(TEST_LIBC_FMT_DEPS) \
o/$(MODE)/test/libc/fmt/%.o \
o/$(MODE)/test/libc/fmt/fmt.pkg \
$(LIBC_TESTMAIN) \
$(CRT) \
$(APE_NO_MODIFY_SELF)
@$(APELINK)
$(TEST_LIBC_FMT_OBJS): test/libc/fmt/BUILD.mk
$(TEST_LIBC_FMT_OBJS): private \
DEFAULT_CCFLAGS += \
$(TEST_LIBC_FMT_OBJS): private \
DEFAULT_CCFLAGS += \
-fno-builtin
o/$(MODE)/test/libc/fmt/fprintf_test.com.runs: \
o/$(MODE)/test/libc/fmt/fprintf_test.runs: \
private .UNVEIL += w:/dev/full
.PHONY: o/$(MODE)/test/libc/fmt
o/$(MODE)/test/libc/fmt: \
$(TEST_LIBC_FMT_BINS) \
o/$(MODE)/test/libc/fmt: \
$(TEST_LIBC_FMT_BINS) \
$(TEST_LIBC_FMT_CHECKS)
+4 -4
View File
@@ -40,13 +40,13 @@ TEST(FormatBinary64, test2) {
}
TEST(FormatBinary64, test3) {
EXPECT_EQ(3, FormatBinary64(buf, 1, 2) - buf);
EXPECT_STREQ("0b1", buf);
EXPECT_EQ(4, FormatBinary64(buf, 1, 2) - buf);
EXPECT_STREQ("0b01", buf);
}
TEST(FormatBinary64, test4) {
EXPECT_EQ(1, FormatBinary64(buf, 1, 0) - buf);
EXPECT_STREQ("1", buf);
EXPECT_EQ(2, FormatBinary64(buf, 1, 0) - buf);
EXPECT_STREQ("01", buf);
}
TEST(FormatBinary64, test5) {
+4 -4
View File
@@ -23,19 +23,19 @@
#include "libc/x/x.h"
TEST(stripexts, test) {
char s[] = "foo/bar.com.dbg";
char s[] = "foo/bar.dbg";
EXPECT_STREQ("foo/bar", stripexts(s));
}
TEST(stripexts, test2) {
char s[] = "foo/bar.com.dbg";
char s[] = "foo/bar.dbg";
EXPECT_STREQ("bar", stripexts(basename(s)));
}
TEST(xstripexts, test) {
EXPECT_STREQ("foo/bar", gc(xstripexts("foo/bar.com.dbg")));
EXPECT_STREQ("foo/bar", gc(xstripexts("foo/bar.dbg")));
}
TEST(xstripexts, test2) {
EXPECT_STREQ("bar", gc(xstripexts(basename("foo/bar.com.dbg"))));
EXPECT_STREQ("bar", gc(xstripexts(basename("foo/bar.dbg"))));
}
+5 -5
View File
@@ -10,17 +10,17 @@ TEST_LIBC_INTRIN_OBJS = \
$(TEST_LIBC_INTRIN_SRCS:%.c=o/$(MODE)/%.o)
TEST_LIBC_INTRIN_COMS = \
$(TEST_LIBC_INTRIN_SRCS:%.c=o/$(MODE)/%.com)
$(TEST_LIBC_INTRIN_SRCS:%.c=o/$(MODE)/%)
TEST_LIBC_INTRIN_BINS = \
$(TEST_LIBC_INTRIN_COMS) \
$(TEST_LIBC_INTRIN_COMS:%=%.dbg)
TEST_LIBC_INTRIN_TESTS = \
$(TEST_LIBC_INTRIN_SRCS_TEST:%.c=o/$(MODE)/%.com.ok)
$(TEST_LIBC_INTRIN_SRCS_TEST:%.c=o/$(MODE)/%.ok)
TEST_LIBC_INTRIN_CHECKS = \
$(TEST_LIBC_INTRIN_SRCS_TEST:%.c=o/$(MODE)/%.com.runs)
$(TEST_LIBC_INTRIN_SRCS_TEST:%.c=o/$(MODE)/%.runs)
TEST_LIBC_INTRIN_DIRECTDEPS = \
LIBC_CALLS \
@@ -50,7 +50,7 @@ o/$(MODE)/test/libc/intrin/intrin.pkg: \
$(TEST_LIBC_INTRIN_OBJS) \
$(foreach x,$(TEST_LIBC_INTRIN_DIRECTDEPS),$($(x)_A).pkg)
o/$(MODE)/test/libc/intrin/%.com.dbg: \
o/$(MODE)/test/libc/intrin/%.dbg: \
$(TEST_LIBC_INTRIN_DEPS) \
o/$(MODE)/test/libc/intrin/%.o \
o/$(MODE)/test/libc/intrin/intrin.pkg \
@@ -60,7 +60,7 @@ o/$(MODE)/test/libc/intrin/%.com.dbg: \
@$(APELINK)
# Test what happens when *NSYNC isn't linked.
o/$(MODE)/test/libc/intrin/lock_test.com.dbg: \
o/$(MODE)/test/libc/intrin/lock_test.dbg: \
$(TEST_LIBC_INTRIN_DEPS) \
o/$(MODE)/test/libc/intrin/lock_test.o \
o/$(MODE)/test/libc/intrin/intrin.pkg \
+1 -1
View File
@@ -31,7 +31,7 @@
*
* This test can be run as follows:
*
* make o//test/libc/intrin/lockscale_test.com.runs V=5 TESTARGS=-b
* make o//test/libc/intrin/lockscale_test.runs V=5 TESTARGS=-b
*
* It's intended to demonstrate the importance of futexes. On systems
* that don't have them, this test consumes orders of a magnitude more
-2
View File
@@ -19,11 +19,9 @@
#include "libc/macros.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/nexgen32e.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/sysconf.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/prot.h"
+12 -12
View File
@@ -8,21 +8,21 @@ TEST_LIBC_LOG_SRCS_TEST = $(filter %_test.c,$(TEST_LIBC_LOG_SRCS))
TEST_LIBC_LOG_OBJS = \
$(TEST_LIBC_LOG_SRCS:%.c=o/$(MODE)/%.o) \
o/$(MODE)/test/libc/log/backtrace.com.zip.o \
o/$(MODE)/test/libc/log/backtrace.com.dbg.zip.o
o/$(MODE)/test/libc/log/backtrace.zip.o \
o/$(MODE)/test/libc/log/backtrace.dbg.zip.o
TEST_LIBC_LOG_COMS = \
$(TEST_LIBC_LOG_SRCS:%.c=o/$(MODE)/%.com)
$(TEST_LIBC_LOG_SRCS:%.c=o/$(MODE)/%)
TEST_LIBC_LOG_BINS = \
$(TEST_LIBC_LOG_COMS) \
$(TEST_LIBC_LOG_COMS:%=%.dbg)
TEST_LIBC_LOG_TESTS = \
$(TEST_LIBC_LOG_SRCS_TEST:%.c=o/$(MODE)/%.com.ok)
$(TEST_LIBC_LOG_SRCS_TEST:%.c=o/$(MODE)/%.ok)
TEST_LIBC_LOG_CHECKS = \
$(TEST_LIBC_LOG_SRCS_TEST:%.c=o/$(MODE)/%.com.runs)
$(TEST_LIBC_LOG_SRCS_TEST:%.c=o/$(MODE)/%.runs)
TEST_LIBC_LOG_DIRECTDEPS = \
LIBC_CALLS \
@@ -47,7 +47,7 @@ o/$(MODE)/test/libc/log/log.pkg: \
$(TEST_LIBC_LOG_OBJS) \
$(foreach x,$(TEST_LIBC_LOG_DIRECTDEPS),$($(x)_A).pkg)
o/$(MODE)/test/libc/log/%.com.dbg: \
o/$(MODE)/test/libc/log/%.dbg: \
$(TEST_LIBC_LOG_DEPS) \
o/$(MODE)/test/libc/log/%.o \
o/$(MODE)/test/libc/log/log.pkg \
@@ -56,10 +56,10 @@ o/$(MODE)/test/libc/log/%.com.dbg: \
$(APE_NO_MODIFY_SELF)
@$(APELINK)
o/$(MODE)/test/libc/log/backtrace_test.com.dbg: \
o/$(MODE)/test/libc/log/backtrace_test.dbg: \
$(TEST_LIBC_LOG_DEPS) \
o/$(MODE)/test/libc/log/backtrace.com.zip.o \
o/$(MODE)/test/libc/log/backtrace.com.dbg.zip.o \
o/$(MODE)/test/libc/log/backtrace.zip.o \
o/$(MODE)/test/libc/log/backtrace.dbg.zip.o \
o/$(MODE)/test/libc/log/backtrace_test.o \
o/$(MODE)/test/libc/log/log.pkg \
$(LIBC_TESTMAIN) \
@@ -67,15 +67,15 @@ o/$(MODE)/test/libc/log/backtrace_test.com.dbg: \
$(APE_NO_MODIFY_SELF)
@$(APELINK)
o/$(MODE)/test/libc/log/backtrace.com.dbg: \
o/$(MODE)/test/libc/log/backtrace.dbg: \
$(TEST_LIBC_LOG_DEPS) \
o/$(MODE)/test/libc/log/backtrace.o \
$(CRT) \
$(APE_NO_MODIFY_SELF)
@$(APELINK)
o/$(MODE)/test/libc/log/backtrace.com.zip.o \
o/$(MODE)/test/libc/log/backtrace.com.dbg.zip.o: private \
o/$(MODE)/test/libc/log/backtrace.zip.o \
o/$(MODE)/test/libc/log/backtrace.dbg.zip.o: private \
ZIPOBJ_FLAGS += \
-B
+15 -15
View File
@@ -41,14 +41,14 @@
#ifdef __x86_64__
#if 0
__static_yoink("backtrace.com");
__static_yoink("backtrace.com.dbg");
__static_yoink("backtrace");
__static_yoink("backtrace.dbg");
void SetUpOnce(void) {
testlib_enable_tmp_setup_teardown_once();
ASSERT_NE(-1, mkdir("bin", 0755));
testlib_extract("/zip/backtrace.com", "bin/backtrace.com", 0755);
testlib_extract("/zip/backtrace.com.dbg", "bin/backtrace.com.dbg", 0755);
testlib_extract("/zip/backtrace", "bin/backtrace", 0755);
testlib_extract("/zip/backtrace.dbg", "bin/backtrace.dbg", 0755);
}
static bool OutputHasSymbol(const char *output, const char *s) {
@@ -56,7 +56,7 @@ static bool OutputHasSymbol(const char *output, const char *s) {
}
// UNFREED MEMORY
// o/dbg/test/libc/log/backtrace_test.com
// o/dbg/test/libc/log/backtrace_test
// max allocated space 655,360
// total allocated space 80
// total free space 327,600
@@ -95,7 +95,7 @@ TEST(ShowCrashReports, testMemoryLeakCrash) {
if (!pid) {
dup2(fds[1], 1);
dup2(fds[1], 2);
execv("bin/backtrace.com", (char *const[]){"bin/backtrace.com", "6", 0});
execv("bin/backtrace", (char *const[]){"bin/backtrace", "6", 0});
_Exit(127);
}
close(fds[1]);
@@ -126,7 +126,7 @@ TEST(ShowCrashReports, testMemoryLeakCrash) {
}
// error: Uncaught SIGFPE (FPE_INTDIV) on nightmare pid 11724
// /home/jart/cosmo/o/dbg/test/libc/log/backtrace_test.com.tmp.11721
// /home/jart/cosmo/o/dbg/test/libc/log/backtrace_test.tmp.11721
// ENOTTY[25]
// Linux nightmare SMP Thu, 12 Aug 2021 06:16:45 UTC
//
@@ -164,9 +164,9 @@ TEST(ShowCrashReports, testMemoryLeakCrash) {
// /* 22 frames mapped w/ 1,879,015,395 frames gapped */
//
// 00400000-0045b000 r-xp 00000000 08:03 4587526
// /home/jart/cosmo/o/dbg/test/libc/log/backtrace_test.com.tmp.11721
// /home/jart/cosmo/o/dbg/test/libc/log/backtrace_test.tmp.11721
// 0045b000-00461000 rw-p 0005b000 08:03 4587526
// /home/jart/cosmo/o/dbg/test/libc/log/backtrace_test.com.tmp.11721
// /home/jart/cosmo/o/dbg/test/libc/log/backtrace_test.tmp.11721
// 00461000-004a0000 rw-p 00000000 00:00 0
// 80070000-80090000 rw-p 00000000 00:00 0
// e007ffd0000-e0080000000 rw-p 00000000 00:00 0
@@ -176,7 +176,7 @@ TEST(ShowCrashReports, testMemoryLeakCrash) {
// 7ffe075a8000-7ffe075ab000 r--p 00000000 00:00 0 [vvar]
// 7ffe075ab000-7ffe075ac000 r-xp 00000000 00:00 0 [vdso]
//
// /home/jart/cosmo/o/dbg/test/libc/log/backtrace_test.com.tmp.11721 1
// /home/jart/cosmo/o/dbg/test/libc/log/backtrace_test.tmp.11721 1
TEST(ShowCrashReports, testDivideByZero) {
size_t got;
ssize_t rc;
@@ -187,7 +187,7 @@ TEST(ShowCrashReports, testDivideByZero) {
if (!pid) {
dup2(fds[1], 1);
dup2(fds[1], 2);
execv("bin/backtrace.com", (char *const[]){"bin/backtrace.com", "1", 0});
execv("bin/backtrace", (char *const[]){"bin/backtrace", "1", 0});
_Exit(127);
}
close(fds[1]);
@@ -312,7 +312,7 @@ TEST(ShowCrashReports, testBssOverrunCrash) {
if (!pid) {
dup2(fds[1], 1);
dup2(fds[1], 2);
execv("bin/backtrace.com", (char *const[]){"bin/backtrace.com", "2", 0});
execv("bin/backtrace", (char *const[]){"bin/backtrace", "2", 0});
_Exit(127);
}
close(fds[1]);
@@ -387,7 +387,7 @@ TEST(ShowCrashReports, testNpeCrash) {
if (!pid) {
dup2(fds[1], 1);
dup2(fds[1], 2);
execv("bin/backtrace.com", (char *const[]){"bin/backtrace.com", "7", 0});
execv("bin/backtrace", (char *const[]){"bin/backtrace", "7", 0});
_Exit(127);
}
close(fds[1]);
@@ -431,7 +431,7 @@ TEST(ShowCrashReports, testDataOverrunCrash) {
if (!pid) {
dup2(fds[1], 1);
dup2(fds[1], 2);
execv("bin/backtrace.com", (char *const[]){"bin/backtrace.com", "4", 0});
execv("bin/backtrace", (char *const[]){"bin/backtrace", "4", 0});
_Exit(127);
}
close(fds[1]);
@@ -479,7 +479,7 @@ TEST(ShowCrashReports, testNpeCrashAfterFinalize) {
if (!pid) {
dup2(fds[1], 1);
dup2(fds[1], 2);
execv("bin/backtrace.com", (char *const[]){"bin/backtrace.com", "8", 0});
execv("bin/backtrace", (char *const[]){"bin/backtrace", "8", 0});
_Exit(127);
}
close(fds[1]);
Loaded 100 of 306 files, more files were not shown because too many files have changed in this diff. Show more