Pay off more technical debt

This makes breaking changes to add underscores to many non-standard
function names provided by the c library. MODE=tiny is now tinier and
we now use smaller locks that are better for tiny apps in this mode.
Some headers have been renamed to be in the same folder as the build
package, so it'll be easier to know which build dependency is needed.
Certain old misguided interfaces have been removed. Intel intrinsics
headers are now listed in libc/isystem (but not in the amalgamation)
to help further improve open source compatibility. Header complexity
has also been reduced. Lastly, more shell scripts are now available.
This commit is contained in:
Justine Tunney 2022-09-12 23:10:38 -07:00
parent b69f3d2488
commit 6f7d0cb1c3
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
960 changed files with 4072 additions and 4873 deletions

View file

@ -2,11 +2,11 @@
#
# OVERVIEW
#
# Micro-experiment assembler.
# Micro-Experiment Assembler
#
# EXAMPLES
#
# asmexpr 'mov $-4096,%rax' 'not %rax' 'bsr %rax,%rax'
# asmexpr 'mov $8,%rax' 'bsr %rax,%rax'
# asmexpr 'mov $0,%ecx' 'vmovd %ecx,%xmm1' 'vpbroadcastb %xmm1,%ymm1' 'mov $0x20202032489001ff,%rax' 'vmovq %rax,%xmm0' 'vpcmpgtb %ymm1,%ymm0,%ymm2'
c=/tmp/asmexpr.c

2
tool/scripts/awk1 Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
exec awk "$@" '{print $1}'

2
tool/scripts/awk2 Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
exec awk "$@" '{print $2}'

2
tool/scripts/awk3 Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
exec awk "$@" '{print $3}'

2
tool/scripts/awk4 Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
exec awk "$@" '{print $4}'

2
tool/scripts/awk5 Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
exec awk "$@" '{print $5}'

2
tool/scripts/awk6 Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
exec awk "$@" '{print $6}'

2
tool/scripts/awk7 Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
exec awk "$@" '{print $7}'

2
tool/scripts/awk8 Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
exec awk "$@" '{print $8}'

4
tool/scripts/bf Executable file
View file

@ -0,0 +1,4 @@
#!/bin/sh
bing.com <"$1" |
fold.com |
exec less

5
tool/scripts/bloat Executable file
View file

@ -0,0 +1,5 @@
#!/bin/sh
nm -C --size "$@" |
sort -r |
grep ' [bBtTRr] ' |
exec less

View file

@ -1,17 +0,0 @@
#!/bin/sh
if ! [ -e ape/ape.S ]; then
echo please cd to cosmopolitan root directory >&2
exit 1
fi
COSMOPOLITAN="$PWD"
EMACSCONFIGS="$HOME/.emacs.d/init.el"
[ -e "$EMACSCONFIGS" ] || EMACSCONFIGS="$HOME/.emacs"
cat >>"$EMACSCONFIGS" <<EOF # idempotent
(let ((path "$COSMOPOLITAN/tool/emacs"))
(when (file-directory-p path)
(add-to-list 'load-path path)
(require 'cosmo)))
EOF

View file

@ -1,43 +0,0 @@
#!/bin/sh
set -ex
rm -f o/ansi/.cosmopolitan.h o/ansi/cosmopolitan.h
make -j12 o/ansi/cosmopolitan.h MODE=ansi
make -j12 o//libc/crt/crt.o o//ape/ape.o o//ape/ape.lds
make -j12 o//cosmopolitan.a
rm -rf o/cosmo
mkdir -p o/cosmo
cp o//ape/ape.o \
o//ape/ape.lds \
o//libc/crt/crt.o \
o//cosmopolitan.a \
o/cosmo
{
echo '#ifndef COSMOPOLITAN_H_'
echo '#define COSMOPOLITAN_H_'
echo '#ifdef __cplusplus'
echo 'extern "C" {'
echo '#endif'
cat o/ansi/cosmopolitan.h
echo '#ifdef __cplusplus'
echo '} /* extern C */'
echo '#endif'
echo '#endif /* COSMOPOLITAN_H_ */'
} >o/cosmo/cosmopolitan.h
cd o/cosmo
cat <<EOF >HELLO.C
int main(int argc, char *argv[]) {
printf("hello world\n");
return 0;
}
EOF
gcc -O -s -static -nostdlib -nostdinc \
-Wl,-T,ape.lds -include cosmopolitan.h \
-o HELLO.COM.DBG HELLO.C crt.o ape.o cosmopolitan.a
objcopy -S -O binary HELLO.COM.DBG HELLO.COM
ls -hal ./HELLO.COM
./HELLO.COM

4
tool/scripts/ezgdb Executable file
View file

@ -0,0 +1,4 @@
#!/bin/sh
PROG="$1"
shift
exec gdb "$PROG" -ex "set args $*" -ex run

View file

@ -1,4 +1,14 @@
#!/usr/bin/env python.com
#
# OVERVIEW
#
# One-Off Makefile Rule Generator
#
# EXAMPLES
#
# tool/scripts/get-deps.py examples/hello.c
# asmexpr 'mov $0,%ecx' 'vmovd %ecx,%xmm1' 'vpbroadcastb %xmm1,%ymm1' 'mov $0x20202032489001ff,%rax' 'vmovq %rax,%xmm0' 'vpcmpgtb %ymm1,%ymm0,%ymm2'
#
import os
import re

View file

@ -1,6 +1,10 @@
#!/bin/sh
exec /usr/bin/grep \
--exclude-dir=o \
--exclude-dir=gcc \
--exclude-dir=.git \
exec grep \
--exclude=TAGS \
--exclude=HTAGS \
--exclude=*.com \
--exclude-dir=o \
--exclude-dir=gcc \
--exclude-dir=.git \
--exclude=archive-contents \
"$@"

View file

@ -1,15 +0,0 @@
#!/bin/sh
# installs emacs version w/ working (replace-buffer-contents)
# it's sooooo worth it due to clang-format-10 working so well
set -ex
sudo apt build-dep emacs
cd "$HOME"
export CFLAGS="-O2"
rm -rf emacs-26.3
wget https://mirrors.kernel.org/gnu/emacs/emacs-26.3.tar.gz
tar xf emacs-26.3.tar.gz
cd emacs-26.3
./configure
make -j8
sudo make install
rm -f ../emacs-26.3.tar.gz

6
tool/scripts/loc Executable file
View file

@ -0,0 +1,6 @@
#!/bin/bash
echo $(( $(find ape dsp libc examples net test third_party tool -name \*.c | xargs cat | wc -l) +
$(find ape dsp libc examples net test third_party tool -name \*.h | xargs cat | wc -l) +
$(find ape dsp libc examples net test third_party tool -name \*.S | xargs cat | wc -l) +
$(find ape dsp libc examples net test third_party tool -name \*.el | xargs cat | wc -l) +
$(find ape dsp libc examples net test third_party tool -name \*.mk | xargs cat | wc -l) ))

3
tool/scripts/obj Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh
objdump -Cwd "$@" |
exec less

16
tool/scripts/pb Executable file
View file

@ -0,0 +1,16 @@
#!/bin/sh
exec python.com -c "
# -*- coding: utf-8 -*-
import sys
from math import *
x = $*
s = x < 0
x = abs(x)
b = str(bin(x))[2:].replace('L', '')
n = len(b)
if n <= 8: n = 8
elif n <= 16: n = 16
elif n <= 32: n = 32
elif n <= 64: n = 64
sys.stdout.write(('%%s0b%%0%dd' % n) % ('-' if s else '', int(b)))
"

9
tool/scripts/pe Executable file
View file

@ -0,0 +1,9 @@
#!/bin/sh
echo "# -*- coding: utf-8 -*-
import os
import sys
from math import *
s = str($*)
sys.stdout.write(s)
" >/tmp/pe
exec python.com /tmp/pe

2
tool/scripts/performance Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
echo "performance" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

14
tool/scripts/po Executable file
View file

@ -0,0 +1,14 @@
#!/bin/sh
exec python.com -c "
import sys
from math import *
s = str(oct($*).replace('o',''))
if len(s) > 1: s = s[1:]
b = s.replace('L', '')
n = len(b)
if n <= 3: n = 3
elif n <= 6: n = 6
elif n <= 11: n = 11
elif n <= 22: n = 22
sys.stdout.write(('0%%0%dd' % n) % int(b))
"

2
tool/scripts/powersave Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
echo "powersave" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

17
tool/scripts/px Executable file
View file

@ -0,0 +1,17 @@
#!/bin/sh
exec python.com -c "
# -*- coding: utf-8 -*-
import sys
from math import *
x = $*
s = x < 0
x = abs(x)
b = str(hex(x))[2:].replace('L', '')
n = len(b)
if n <= 2: n = 2
elif n <= 4: n = 4
elif n <= 8: n = 8
elif n <= 12: n = 12
elif n <= 16: n = 16
sys.stdout.write(('%%s0x%%0%dx' % n) % ('-' if s else '', int(b,16)))
"

4
tool/scripts/re Executable file
View file

@ -0,0 +1,4 @@
#!/bin/sh
readelf -Wa "$1" |
c++filt |
exec less

15
tool/scripts/renameheader Executable file
View file

@ -0,0 +1,15 @@
#!/usr/bin/env bash
FROM="${1?from}"
TO="${2?to}"
if [ -f "$TO" ]; then
rm -f "$FROM" || exit
else
mv "$FROM" "$TO" || exit
fi
sed -i -e "s/$(echo "${FROM//\//_}" | sed 's/\./_/' | tr a-z A-Z)_H_/$(echo "${TO//\//_}" | sed 's/\./_/' | tr a-z A-Z)_H_/" "$TO" || exit
tool/scripts/grep -nH -RPie "\"$FROM\"" |
tool/scripts/awk1 -F: |
xargs sed -i -e "s/${FROM//\//\\/}/${TO//\//\\/}/"

98
tool/scripts/wut Executable file
View file

@ -0,0 +1,98 @@
#!/bin/sh
rm -f /tmp/wut-linux
(
grep -R "$1" ~/dox/susv4-2018/ | sed '
/meta.idx/d
' >/tmp/wut-posix
) &
(
grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/linux/include/ | sed '
/\/asm-/ {
/asm-\(x86\|generic\)/!d
}
s/\([^:]*\):\(.*\)/\2\t\t\t\1\t\1/
s/\(.*\)\/home\/jart\/vendor\/\([^\/]*\)\/[^[:blank:]]*/\2\t\1/
' >>/tmp/wut-linux
) &
(
grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/linux-2.6.18/include/ | sed '
/\/asm-/ {
/asm-\(x86\|generic\)/!d
}
s/\([^:]*\):\(.*\)/\2\t\t\t\1\t\1/
s/\(.*\)\/home\/jart\/vendor\/\([^\/]*\)\/[^[:blank:]]*/2.6.18\t\1/
' >>/tmp/wut-linux
) &
(
grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/xnu/ | sed '
s/\([^:]*\):\(.*\)/\2\t\t\t\1\t\1/
s/\(.*\)\/home\/jart\/vendor\/\([^\/]*\)\/[^[:blank:]]*/\2\t\1/
' >/tmp/wut-xnu
) &
(
{
if ! grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/freebsd/sys/; then
grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/freebsd/lib/libc/
fi
} | sed '
/\/contrib\//d
/\/linux\//d
s/\([^:]*\):\(.*\)/\2\t\t\t\1\t\1/
s/\(.*\)\/home\/jart\/vendor\/\([^\/]*\)\/[^[:blank:]]*/\2\t\1/
' >/tmp/wut-freebsd
) &
(
{
if ! grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/openbsd/sys/; then
grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/openbsd/lib/libc/
fi
} | sed '
/\/linux\//d
s/\([^:]*\):\(.*\)/\2\t\t\t\1\t\1/
s/\(.*\)\/home\/jart\/vendor\/\([^\/]*\)\/[^[:blank:]]*/\2\t\1/
' >/tmp/wut-openbsd
) &
(
{
if ! grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/netbsd/sys/; then
grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/netbsd/lib/libc/
fi
} | sed '
/\/linux\//d
s/\([^:]*\):\(.*\)/\2\t\t\t\1\t\1/
s/\(.*\)\/home\/jart\/vendor\/\([^\/]*\)\/[^[:blank:]]*/\2\t\1/
' >/tmp/wut-netbsd
) &
(
grep -R "#define[[:blank:]]\+$1[[:blank:]]" ~/vendor/10.0.18362.0/um/ | sed '
s/\([^:]*\):\(.*\)/\2\t\t\t\1\t\1/
s/\(.*\)\/home\/jart\/vendor\/\([^\/]*\)\/[^[:blank:]]*/\2\t\1/
' >/tmp/wut-windows
) &
wait
f() {
if [ $(ls -lH /tmp/wut-$1 | awk5) -gt 0 ]; then
cat /tmp/wut-$1
else
echo $1 says nothing
fi
}
f linux
f xnu
f freebsd
f openbsd
f netbsd
f windows
f posix