mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 03:27:39 +00:00
Make fatcosmocc good enough to build ncurses 6.4
This commit is contained in:
parent
399d14aadf
commit
3f2f0e3a74
20 changed files with 295 additions and 139 deletions
5
Makefile
5
Makefile
|
@ -99,6 +99,7 @@ endif
|
|||
.PLEDGE = stdio rpath wpath cpath fattr proc
|
||||
.UNVEIL = \
|
||||
libc/integral \
|
||||
libc/stdbool.h \
|
||||
libc/disclaimer.inc \
|
||||
rwc:/dev/shm \
|
||||
rx:build/bootstrap \
|
||||
|
@ -131,7 +132,6 @@ include libc/str/str.mk # │
|
|||
include third_party/xed/xed.mk # │
|
||||
include third_party/puff/puff.mk # │
|
||||
include third_party/zlib/zlib.mk # │
|
||||
include third_party/double-conversion/dc.mk # │
|
||||
include libc/elf/elf.mk # │
|
||||
include ape/ape.mk # │
|
||||
include libc/fmt/fmt.mk # │
|
||||
|
@ -139,7 +139,8 @@ include libc/vga/vga.mk #─┘
|
|||
include libc/calls/calls.mk #─┐
|
||||
include third_party/nsync/nsync.mk # │
|
||||
include libc/runtime/runtime.mk # ├──SYSTEMS RUNTIME
|
||||
include libc/crt/crt.mk # │ You can issue system calls
|
||||
include third_party/double-conversion/dc.mk # │ You can issue system calls
|
||||
include libc/crt/crt.mk # │
|
||||
include third_party/dlmalloc/dlmalloc.mk #─┘
|
||||
include libc/mem/mem.mk #─┐
|
||||
include third_party/gdtoa/gdtoa.mk # ├──DYNAMIC RUNTIME
|
||||
|
|
|
@ -29,8 +29,8 @@ sudo chmod 1777 /opt
|
|||
git clone https://github.com/jart/cosmopolitan /opt/cosmo
|
||||
export PATH="/opt/cosmo/bin:/opt/cosmos/bin:$PATH"
|
||||
echo 'PATH="/opt/cosmo/bin:/opt/cosmos/bin:$PATH"' >>~/.profile
|
||||
ape-install # optionally install a faster systemwide ape loader
|
||||
cosmocc --update # pull cosmo and rebuild toolchain
|
||||
ape-install # [optional] install /usr/bin/ape and binfmt_misc
|
||||
```
|
||||
|
||||
You've now successfully installed your very own cosmos. Now let's build
|
||||
|
|
12
bin/cosmocc
12
bin/cosmocc
|
@ -6,8 +6,8 @@
|
|||
#
|
||||
# sudo chmod 1777 /opt # sticky bit isn't required
|
||||
# git clone https://github.com/jart/cosmopolitan /opt/cosmo
|
||||
# export PATH="$PATH:/opt/cosmo/bin:/opt/cosmos/bin"
|
||||
# echo 'export PATH="$PATH:/opt/cosmo/bin:/opt/cosmos/bin"' >>~/.profile
|
||||
# export PATH="/opt/cosmo/bin:/opt/cosmos/bin:$PATH"
|
||||
# echo 'export PATH="/opt/cosmo/bin:/opt/cosmos/bin:$PATH"' >>~/.profile
|
||||
# ape-install # optionally install a faster systemwide ape loader
|
||||
# cosmocc --update # pull and rebuild toolchain artifacts
|
||||
#
|
||||
|
@ -114,7 +114,7 @@ PLATFORM="-D__COSMOPOLITAN__"
|
|||
PREDEF="-include libc/integral/normalize.inc"
|
||||
CCFLAGS="-fno-pie -mno-tls-direct-seg-refs -mno-red-zone -fportcosmo"
|
||||
CPPFLAGS="-nostdinc -iquote $COSMO -isystem $COSMOS/include -isystem $COSMO/libc/isystem"
|
||||
LDFLAGS="-static -no-pie -nostdlib -fuse-ld=bfd -Wl,-melf_x86_64"
|
||||
LDFLAGS="-static -no-pie -nostdlib -fuse-ld=bfd -Wl,-melf_x86_64 -Wl,-z,common-page-size=4096 -Wl,-z,max-page-size=4096"
|
||||
APEFLAGS="-L$COSMOS/lib -Wl,--gc-sections -Wl,-T,$COSMO/o/$MODE/ape/public/ape.lds $COSMO/o/$MODE/ape/ape-no-modify-self.o $COSMO/o/$MODE/libc/crt/crt.o"
|
||||
LDLIBS="$COSMO/o/$MODE/cosmopolitan.a"
|
||||
|
||||
|
@ -130,7 +130,7 @@ if [ ! -d "$COSMO" ]; then
|
|||
fi
|
||||
|
||||
if [ ! -d "$COSMOS" ] ||
|
||||
[ ! -x "$COSMO/o/$MODE/cosmopolitan.a" ]; then
|
||||
[ ! -f "$COSMO/o/$MODE/cosmopolitan.a" ]; then
|
||||
echo "$PROG: you need to run: $PROG --update" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
@ -267,8 +267,8 @@ if [ $INTENT = cpp ]; then
|
|||
elif [ $INTENT = cc ]; then
|
||||
set -- "$CC" $PLATFORM $PREDEF $CCFLAGS $CPPFLAGS "$@" -fno-omit-frame-pointer
|
||||
else
|
||||
set -- "$CC" $PLATFORM $PREDEF $CCFLAGS $CPPFLAGS $LDFLAGS $APEFLAGS $CPPFLAGS "$@" \
|
||||
$LDLIBS -Wl,-z,common-page-size=4096 -Wl,-z,max-page-size=4096 -fno-omit-frame-pointer
|
||||
set -- "$CC" $PLATFORM $PREDEF $CCFLAGS $CPPFLAGS $CPPFLAGS "$@" \
|
||||
$LDFLAGS $APEFLAGS $LDLIBS -fno-omit-frame-pointer
|
||||
fi
|
||||
|
||||
printf '# %s\n(cd %s; %s)\n' "$ORIGINAL" "$PWD" "$*" >>"${TMPDIR:-/tmp}/build.log"
|
||||
|
|
153
bin/fatcosmocc
153
bin/fatcosmocc
|
@ -26,8 +26,8 @@
|
|||
#
|
||||
# sudo chmod 1777 /opt # sticky bit isn't required
|
||||
# git clone https://github.com/jart/cosmopolitan /opt/cosmo
|
||||
# export PATH="$PATH:/opt/cosmo/bin:/opt/cosmos/bin"
|
||||
# echo 'export PATH="$PATH:/opt/cosmo/bin:/opt/cosmos/bin"' >>~/.profile
|
||||
# export PATH="/opt/cosmo/bin:/opt/cosmos/bin:$PATH"
|
||||
# echo 'export PATH="/opt/cosmo/bin:/opt/cosmos/bin:$PATH"' >>~/.profile
|
||||
# ape-install # optionally install a faster systemwide ape loader
|
||||
# fatcosmocc --update # pull and rebuild toolchain artifacts
|
||||
#
|
||||
|
@ -35,7 +35,9 @@
|
|||
#
|
||||
# fatcosmocc -o hello.com hello.c
|
||||
# ./foo.com
|
||||
# ./foo.com.dbg
|
||||
# unzip -vl ./foo.com
|
||||
# ./foo.com --strace
|
||||
# ./foo.com --ftrace
|
||||
#
|
||||
# building in tiny mode
|
||||
#
|
||||
|
@ -49,14 +51,27 @@
|
|||
# fatcosmocc --update
|
||||
# fatcosmocc -g -o foo.com foo.c
|
||||
#
|
||||
# building a project like lua 5.4.6
|
||||
# how to build a project like lua 5.4.6
|
||||
#
|
||||
# make all test CC=fatcosmocc AR='fatcosmoar rcu'
|
||||
# make install INSTALL_TOP=/opt/cosmos INSTALL=fatcosmoinstall
|
||||
#
|
||||
# how to build a project like ncurses 6.4
|
||||
#
|
||||
# ./configure CC=fatcosmocc \
|
||||
# CXX=fatcosmoc++ \
|
||||
# AR=fatcosmoar \
|
||||
# INSTALL="$(command -v fatcosmoinstall)" \
|
||||
# --prefix=/opt/cosmos \
|
||||
# --disable-shared
|
||||
# make -j8
|
||||
# make install
|
||||
#
|
||||
# detecting this environment
|
||||
#
|
||||
# - `__FATCOSMOCC__` is defined when this compiler is in play
|
||||
# - `__COSMOPOLITAN__` is always defined by Cosmopolitan Libc
|
||||
# - `__FATCOSMOCC__` is defined by fatcosmocc
|
||||
# - `__COSMOCC__` is defined by cosmocc and fatcosmocc
|
||||
# - `__COSMOPOLITAN__` is always defined by cosmopolitan
|
||||
#
|
||||
# some notes on this compiler
|
||||
#
|
||||
|
@ -70,6 +85,7 @@
|
|||
# compiler flags that work differently
|
||||
#
|
||||
# - `-v` will log fatcosmocc subcommands to stderr
|
||||
# you can also use `export BUILDLOG=/tmp/build.log`
|
||||
# - `-s` will ask apelink to not embed symbol tables in zip
|
||||
# - `-E` can't be fat and runs once with x86_64 macros undefined
|
||||
# - `-save-temps` will prevent deleting your arch-specific executables
|
||||
|
@ -90,7 +106,6 @@ export COSMO=${COSMO:-/opt/cosmo}
|
|||
export COSMOS=${COSMOS:-/opt/cosmos}
|
||||
export ORIGINAL="$0 $*"
|
||||
export TMPDIR=${TMPDIR:-/tmp}
|
||||
export BUILDLOG=
|
||||
GCC_VERSION=11.2.0
|
||||
|
||||
if [ "$1" = "--version" ]; then
|
||||
|
@ -150,8 +165,8 @@ if [ ! -d "$COSMO" ]; then
|
|||
fi
|
||||
|
||||
if [ ! -d "$COSMOS" ] ||
|
||||
[ ! -x "$COSMO/o/$MODE/cosmopolitan.a" ] ||
|
||||
[ ! -x "$COSMO/o/$MODE_AARCH64/cosmopolitan.a" ]; then
|
||||
[ ! -f "$COSMO/o/$MODE/cosmopolitan.a" ] ||
|
||||
[ ! -f "$COSMO/o/$MODE_AARCH64/cosmopolitan.a" ]; then
|
||||
echo "$PROG: you need to run: $PROG --update" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
@ -160,11 +175,10 @@ export FIXUPOBJ="$COSMO/o/$MODE/tool/build/fixupobj.com"
|
|||
|
||||
TEMP_FILES=
|
||||
SAVE_TEMPS=0
|
||||
SAVE_TMPS=0
|
||||
|
||||
Exit() {
|
||||
rc=${1:-$?}
|
||||
if [ $SAVE_TEMPS -eq 0 ] && [ $SAVE_TMPS -eq 0 ]; then
|
||||
if [ $SAVE_TEMPS -eq 0 ]; then
|
||||
rm -f $TEMP_FILES
|
||||
fi
|
||||
exit $rc
|
||||
|
@ -188,36 +202,39 @@ log_command() {
|
|||
|
||||
if [ x"$TMPDIR" != x"${TMPDIR#* }" ]; then
|
||||
fatal_error '$TMPDIR containing spaces not supported'
|
||||
fi
|
||||
if [ ! -d "$TMPDIR" ]; then
|
||||
elif [ ! -d "$TMPDIR" ]; then
|
||||
if ! mkdir -p "$TMPDIR" 2>/dev/null; then
|
||||
fatal_error "$TMPDIR: not a directory"
|
||||
fi
|
||||
fi
|
||||
|
||||
OPT=
|
||||
FILES=
|
||||
FIRST=1
|
||||
ARGS=
|
||||
FLAGS=
|
||||
OUTPUT=
|
||||
INTENT=ld
|
||||
NEED_JOIN=
|
||||
NEED_EQUAL=
|
||||
NEED_OUTPUT=
|
||||
APELINKFLAGS=
|
||||
FRAME=""
|
||||
INPUT_FILE_COUNT=0
|
||||
for x; do
|
||||
if [ $FIRST -eq 1 ]; then
|
||||
set --
|
||||
FIRST=0
|
||||
if [ x"$x" != x"${x#* }" ]; then
|
||||
fatal_error "arguments containing spaces unsupported: $x"
|
||||
fi
|
||||
if [ -n "$NEED_OUTPUT" ]; then
|
||||
NEED_OUTPUT=
|
||||
OUTPUT=$x
|
||||
continue
|
||||
fi
|
||||
if [ x"$x" = x"-" ] || # is an argument
|
||||
elif [ -n "$NEED_JOIN" ]; then
|
||||
x="${NEED_JOIN}${x}"
|
||||
NEED_JOIN=
|
||||
elif [ -n "$NEED_EQUAL" ]; then
|
||||
x="${NEED_EQUAL}=${x}"
|
||||
NEED_EQUAL=
|
||||
elif [ x"$x" = x"-" ] || # is alias for stdin
|
||||
[ x"$x" = x"${x#-*}" ]; then # !startswith(x, "-")
|
||||
if [ x"$x" != x"${x#* }" ]; then
|
||||
fatal_error "input arguments containing spaces unsupported"
|
||||
elif [ x"$x" != x"${x%.s}" ] ||
|
||||
if [ x"$x" != x"${x%.s}" ] ||
|
||||
[ x"$x" != x"${x%.S}" ]; then
|
||||
fatal_error "$x: assembler input files not supported"
|
||||
elif [ x"$x" != x"${x%.so}" ] ||
|
||||
|
@ -227,11 +244,8 @@ for x; do
|
|||
elif [ x"$x" != x"-" ] && [ ! -f "$x" ]; then
|
||||
fatal_error "$x: no such file"
|
||||
fi
|
||||
if [ -z "$FILES" ]; then
|
||||
FILES=$x
|
||||
else
|
||||
FILES="$FILES $x"
|
||||
fi
|
||||
INPUT_FILE_COUNT=$((INPUT_FILE_COUNT + 1))
|
||||
ARGS="$ARGS $x" # don't add to $FLAGS array
|
||||
continue
|
||||
elif [ x"$x" = x"-o" ]; then
|
||||
NEED_OUTPUT=1
|
||||
|
@ -252,19 +266,15 @@ for x; do
|
|||
exec 3<&2 # dup2(2, 3) b/c stderr will be redirected later
|
||||
export BUILDLOG=/dev/fd/3
|
||||
continue
|
||||
elif [ x"$x" = x"-x-save-tmps" ]; then
|
||||
SAVE_TMPS=1
|
||||
continue
|
||||
elif [ x"$x" = x"-save-temps" ]; then
|
||||
SAVE_TEMPS=1
|
||||
elif [ x"$x" = x"-fomit-frame-pointer" ]; then
|
||||
# Quoth Apple "The frame pointer register must always address a
|
||||
# Quoth Apple: "The frame pointer register must always address a
|
||||
# valid frame record. Some functions — such as leaf functions or
|
||||
# tail calls — may opt not to create an entry in this list. As a
|
||||
# result, stack traces are always meaningful, even without debug
|
||||
# information."
|
||||
set -- "$@" -momit-leaf-frame-pointer -foptimize-sibling-calls
|
||||
continue
|
||||
x="-momit-leaf-frame-pointer -foptimize-sibling-calls"
|
||||
elif [ x"$x" = x"-r" ] ||
|
||||
[ x"$x" = x"-S" ] ||
|
||||
[ x"$x" = x"-pie" ] ||
|
||||
|
@ -300,17 +310,35 @@ for x; do
|
|||
elif [ x"$x" = x"-dumpversion" ]; then
|
||||
echo $GCC_VERSION
|
||||
Exit 0
|
||||
elif [ x"$x" = x"-e" ] ||
|
||||
[ x"$x" = x"-z" ] ||
|
||||
[ x"$x" = x"-T" ] ||
|
||||
[ x"$x" = x"-L" ] ||
|
||||
[ x"$x" = x"-I" ] ||
|
||||
[ x"$x" = x"-D" ] ||
|
||||
[ x"$x" = x"-U" ] ||
|
||||
[ x"$x" = x"-iquote" ] ||
|
||||
[ x"$x" = x"-isystem" ] ||
|
||||
[ x"$x" = x"-include" ]; then
|
||||
NEED_JOIN=$x
|
||||
continue
|
||||
elif [ x"$x" = x"--param" ]; then
|
||||
NEED_EQUAL=$x
|
||||
continue
|
||||
fi
|
||||
set -- "$@" "$x"
|
||||
FLAGS="$FLAGS $x"
|
||||
ARGS="$ARGS $x"
|
||||
done
|
||||
|
||||
if [ -z "$FILES" ]; then
|
||||
fatal_error "$x: no input files"
|
||||
elif [ $INTENT != ld ] && [ x"$FILES" != x"${FILES#* }" ]; then
|
||||
if [ $INPUT_FILE_COUNT -eq 0 ]; then
|
||||
fatal_error "no input files"
|
||||
elif [ -z "$INPUT" ] &&
|
||||
[ $INTENT != ld ] &&
|
||||
[ $INPUT_FILE_COUNT -gt 1 ]; then
|
||||
fatal_error "cannot specify '-o' with '-c', or '-E' with multiple files"
|
||||
fi
|
||||
|
||||
PLATFORM="-D__COSMOPOLITAN__ -D__FATCOSMOCC__"
|
||||
PLATFORM="-D__COSMOPOLITAN__ -D__COSMOCC__ -D__FATCOSMOCC__"
|
||||
PREDEF="-include libc/integral/normalize.inc"
|
||||
CPPFLAGS="-nostdinc -iquote $COSMO -isystem $COSMOS/include -isystem $COSMO/libc/isystem -fno-pie -fno-math-errno"
|
||||
CCFLAGS_START="-fportcosmo -fno-dwarf2-cfi-asm -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-semantic-interposition"
|
||||
|
@ -325,7 +353,7 @@ fi
|
|||
|
||||
if [ $INTENT = cpp ]; then
|
||||
if [ -n "$OUTPUT" ]; then
|
||||
set -- "$@" -o"$OUTPUT"
|
||||
ARGS="$ARGS -o$OUTPUT"
|
||||
fi
|
||||
CC="$COSMO/o/third_party/gcc/bin/x86_64-linux-musl-gcc"
|
||||
if [ x"$PROG" != x"${PROG%++}" ]; then
|
||||
|
@ -345,8 +373,7 @@ if [ $INTENT = cpp ]; then
|
|||
-mno-red-zone \
|
||||
$PLATFORM \
|
||||
$CPPFLAGS \
|
||||
"$@" \
|
||||
$FILES
|
||||
$ARGS
|
||||
log_command "$@"
|
||||
MODE="$MODE" exec "$@"
|
||||
fi
|
||||
|
@ -377,7 +404,7 @@ build_object() {
|
|||
TEMP_FILES="${TEMP_FILES} $out2"
|
||||
MODE="$MODE" \
|
||||
"$COSMO/tool/scripts/fat-x86_64" \
|
||||
-c -o"$OUTPUT_X86_64" \
|
||||
-o"$OUTPUT_X86_64" \
|
||||
$PLATFORM \
|
||||
$PREDEF \
|
||||
$CPPFLAGS \
|
||||
|
@ -387,7 +414,7 @@ build_object() {
|
|||
pid1=$!
|
||||
MODE="$MODE_AARCH64" \
|
||||
"$COSMO/tool/scripts/fat-aarch64" \
|
||||
-c -o"$OUTPUT_AARCH64" \
|
||||
-o"$OUTPUT_AARCH64" \
|
||||
$PLATFORM \
|
||||
$PREDEF \
|
||||
$CPPFLAGS \
|
||||
|
@ -409,9 +436,16 @@ build_object() {
|
|||
}
|
||||
|
||||
# turn source files into objects
|
||||
OBJECTS_X86_64=
|
||||
OBJECTS_AARCH64=
|
||||
for x in $FILES; do
|
||||
LDARGS_X86_64=
|
||||
LDARGS_AARCH64=
|
||||
for x in $ARGS; do
|
||||
if [ x"$x" != x"-" ] && # is alias for stdin
|
||||
[ x"$x" != x"${x#-*}" ]; then # startswith(x, "-")
|
||||
# this argument is a flag
|
||||
LDARGS_X86_64="${LDARGS_X86_64} $x"
|
||||
LDARGS_AARCH64="${LDARGS_AARCH64} $x"
|
||||
else
|
||||
# this argument is an input file
|
||||
if [ x"$x" != x"${x%.o}" ] ||
|
||||
[ x"$x" != x"${x%.a}" ]; then
|
||||
if [ $INTENT = cc ]; then
|
||||
|
@ -421,8 +455,8 @@ for x in $FILES; do
|
|||
if [ ! -f "$mangled_path" ]; then
|
||||
fatal_error "$x: linker input missing concomitant $mangled_path file"
|
||||
fi
|
||||
OBJECTS_X86_64="${OBJECTS_X86_64} $x"
|
||||
OBJECTS_AARCH64="${OBJECTS_AARCH64} $mangled_path"
|
||||
LDARGS_X86_64="${LDARGS_X86_64} $x"
|
||||
LDARGS_AARCH64="${LDARGS_AARCH64} $mangled_path"
|
||||
fi
|
||||
elif [ $INTENT = cc ]; then
|
||||
if [ -n "$OUTPUT" ]; then
|
||||
|
@ -430,22 +464,27 @@ for x in $FILES; do
|
|||
OUTPUT_X86_64=$OUTPUT
|
||||
mangle_object_path "$OUTPUT" aarch64
|
||||
OUTPUT_AARCH64="$mangled_path"
|
||||
build_object "$@" "$x"
|
||||
build_object $FLAGS -c "$x"
|
||||
else
|
||||
# e.g. `cc -c foo.c` builds foo.o
|
||||
OUTPUT_X86_64="${x%.*}.o"
|
||||
mangle_object_path "${x%.*}.o" aarch64
|
||||
OUTPUT_AARCH64="$mangled_path"
|
||||
build_object "$@" "$x"
|
||||
build_object $FLAGS -c "$x"
|
||||
fi
|
||||
else
|
||||
# e.g. `cc foo.c` should build a.out
|
||||
if [ -z "$OUTPUT" ]; then
|
||||
OUTPUT=a.out
|
||||
fi
|
||||
# e.g. `cc -o foo foo.c` should *not* build foo.o
|
||||
OUTPUT_X86_64=$(mktemper .o) || Exit
|
||||
OUTPUT_AARCH64=$(mktemper .o) || Exit
|
||||
TEMP_FILES="${TEMP_FILES} ${OUTPUT_X86_64} ${OUTPUT_AARCH64}"
|
||||
build_object "$@" "$x"
|
||||
OBJECTS_X86_64="${OBJECTS_X86_64} ${OUTPUT_X86_64}"
|
||||
OBJECTS_AARCH64="${OBJECTS_AARCH64} ${OUTPUT_AARCH64}"
|
||||
build_object $FLAGS -c "$x"
|
||||
LDARGS_X86_64="${LDARGS_X86_64} ${OUTPUT_X86_64}"
|
||||
LDARGS_AARCH64="${LDARGS_AARCH64} ${OUTPUT_AARCH64}"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
|
@ -459,10 +498,10 @@ OUTPUT_AARCH64="$OUTPUT.aarch64"
|
|||
out2=$(mktemper .txt) || Exit
|
||||
TEMP_FILES="${TEMP_FILES} $out2"
|
||||
MODE="$MODE" \
|
||||
"$COSMO/tool/scripts/fat-x86_64" -o"$OUTPUT_X86_64" "$@" $OBJECTS_X86_64 &
|
||||
"$COSMO/tool/scripts/fat-x86_64" -o"$OUTPUT_X86_64" $LDARGS_X86_64 &
|
||||
pid1=$!
|
||||
MODE="$MODE_AARCH64" \
|
||||
"$COSMO/tool/scripts/fat-aarch64" -o"$OUTPUT_AARCH64" "$@" $OBJECTS_AARCH64 2>"$out2" &
|
||||
"$COSMO/tool/scripts/fat-aarch64" -o"$OUTPUT_AARCH64" $LDARGS_AARCH64 2>"$out2" &
|
||||
pid2=$!
|
||||
if ! wait $pid1; then
|
||||
kill $pid2 2>/dev/null
|
||||
|
|
85
bin/fatcosmoinstall
Executable file
85
bin/fatcosmoinstall
Executable file
|
@ -0,0 +1,85 @@
|
|||
#!/bin/sh
|
||||
|
||||
if [ $# -gt 1 ]; then
|
||||
|
||||
# parse `install [$flags]... $src $dst`
|
||||
i=0
|
||||
n=$(( $# - 2 ))
|
||||
dst=
|
||||
src=
|
||||
flags=
|
||||
for x; do
|
||||
if [ x"$x" != x"${x#* }" ]; then
|
||||
# give up if any arguments contain spaces
|
||||
exec /usr/bin/install "$@"
|
||||
fi
|
||||
src=$dst
|
||||
dst=$x
|
||||
if [ $i -lt $n ]; then
|
||||
flags="$flags $x"
|
||||
fi
|
||||
i=$(( i + 1 ))
|
||||
done
|
||||
|
||||
arch=aarch64
|
||||
|
||||
# turn:
|
||||
# install -c -m 644 foo.a /usr/lib/foo.a
|
||||
# into:
|
||||
# install -c -m 644 foo.a /usr/lib/foo.a
|
||||
# install -c -m 644 .aarch/foo.a /usr/lib/.aarch/foo.a
|
||||
if [ x"${dst##*/}" = x"${src##*/}" ] && # basenames are equal
|
||||
[ x"$dst" != x"${dst%.a}" ]; then # specifies static archive
|
||||
srcdir=${src%/*}
|
||||
srcbas=${dst##*/}
|
||||
if [ x"$srcdir" = x"$src" ]; then
|
||||
srcdir=
|
||||
elif [ -n "$srcdir" ]; then
|
||||
srcdir="$srcdir/"
|
||||
fi
|
||||
if [ -f "$srcdir.$arch/$srcbas" ]; then
|
||||
dstdir=${dst%/*}
|
||||
dstbas=${dst##*/}
|
||||
if [ x"$dstdir" = x"$dst" ]; then
|
||||
dstdir=
|
||||
elif [ -n "$dstdir" ]; then
|
||||
dstdir="$dstdir/"
|
||||
fi
|
||||
if [ ! -d "$dstdir.$arch" ]; then
|
||||
mkdir -p "$dstdir.$arch" || exit
|
||||
fi
|
||||
/usr/bin/install $flags $src $dst || exit
|
||||
exec /usr/bin/install $flags \
|
||||
"$srcdir.$arch/$srcbas" \
|
||||
"$dstdir.$arch/$dstbas"
|
||||
fi
|
||||
fi
|
||||
|
||||
# turn:
|
||||
# install -c -m 644 foo.a /usr/lib
|
||||
# into:
|
||||
# install -c -m 644 foo.a /usr/lib
|
||||
# install -c -m 644 .aarch/foo.a /usr/lib/.aarch
|
||||
arch=aarch64
|
||||
if [ x"$src" != x"${src%.a}" ] && [ -d "$dst" ]; then
|
||||
srcdir=${src%/*}
|
||||
srcbas=${dst##*/}
|
||||
if [ x"$srcdir" = x"$src" ]; then
|
||||
srcdir=
|
||||
elif [ -n "$srcdir" ]; then
|
||||
srcdir="$srcdir/"
|
||||
fi
|
||||
if [ -f "$srcdir.$arch/$srcbas" ]; then
|
||||
if [ ! -d "$dst/.$arch" ]; then
|
||||
mkdir -p "$dst/.$arch" || exit
|
||||
fi
|
||||
/usr/bin/install $flags $src $dst || exit
|
||||
exec /usr/bin/install $flags \
|
||||
"$srcdir.$arch/$srcbas" \
|
||||
"$dst/.$arch"
|
||||
fi
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
exec /usr/bin/install "$@"
|
|
@ -113,6 +113,12 @@ _start:
|
|||
call cosmo
|
||||
9: .unreachable
|
||||
|
||||
// strongly link main() function (discarded by linker)
|
||||
// libc_runtime had to weakly link, due to package.com
|
||||
.section .yoink
|
||||
call main
|
||||
.previous
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#elif defined(__aarch64__)
|
||||
|
||||
|
@ -140,6 +146,12 @@ _start:
|
|||
bl cosmo
|
||||
.unreachable
|
||||
|
||||
// strongly link main() function (discarded by linker)
|
||||
// libc_runtime had to weakly link, due to package.com
|
||||
.section .yoink
|
||||
bl main
|
||||
.previous
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
|
|
|
@ -97,14 +97,6 @@
|
|||
#pragma GCC push_options
|
||||
#pragma GCC diagnostic ignored "-Wc++-compat"
|
||||
#endif
|
||||
#define HAVE_STDBOOL_H 1
|
||||
#if __STDC_VERSION__ + 0 >= 201112
|
||||
typedef _Bool bool;
|
||||
#else
|
||||
#define bool int
|
||||
#endif
|
||||
#define true 1
|
||||
#define false 0
|
||||
typedef __WCHAR_TYPE__ wchar_t;
|
||||
typedef __CHAR16_TYPE__ char16_t;
|
||||
typedef __CHAR32_TYPE__ char32_t;
|
||||
|
@ -113,6 +105,10 @@ typedef __CHAR32_TYPE__ char32_t;
|
|||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifndef __COSMOCC__
|
||||
#include "libc/stdbool.h"
|
||||
#endif
|
||||
|
||||
#define _LIBCPP_STDINT_H
|
||||
|
||||
typedef int errno_t;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#ifndef _STDBOOL_H
|
||||
#define _STDBOOL_H
|
||||
#include "libc/stdbool.h"
|
||||
#endif /* _STDBOOL_H */
|
||||
|
|
|
@ -3,5 +3,6 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/calls/struct/siginfo.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/sysv/consts/sicode.h"
|
||||
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_SYS_SIGNAL_H_ */
|
||||
|
|
|
@ -29,8 +29,8 @@ int mergesort_r(void *, size_t, size_t,
|
|||
|
||||
#define __algalloc returnspointerwithnoaliases dontthrow nocallback dontdiscard
|
||||
|
||||
bool radix_sort_int32(int32_t *, size_t);
|
||||
bool radix_sort_int64(int64_t *, size_t);
|
||||
int radix_sort_int32(int32_t *, size_t);
|
||||
int radix_sort_int64(int64_t *, size_t);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
|
@ -29,22 +29,22 @@
|
|||
#define get_byte_1(v) (((v) >> 11) & 0x7FF)
|
||||
#define get_byte_2_flip_sign(v) (((unsigned)(v) >> 22) ^ 0x200)
|
||||
|
||||
bool radix_sort_int32(int32_t *A, size_t n) {
|
||||
int radix_sort_int32(int32_t *A, size_t n) {
|
||||
int32_t *T, *reader, *writer;
|
||||
size_t i, pos, sum0, sum1, sum2, tsum, *b0, *b1, *b2;
|
||||
|
||||
if (n < HIST_SIZE) {
|
||||
_intsort(A, n);
|
||||
return true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(T = (int32_t *)malloc(n * sizeof(int32_t)))) {
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(b0 = (size_t *)calloc(HIST_SIZE * 3, sizeof(size_t)))) {
|
||||
free(T);
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
b1 = b0 + HIST_SIZE;
|
||||
|
@ -97,5 +97,5 @@ bool radix_sort_int32(int32_t *A, size_t n) {
|
|||
|
||||
free(b0);
|
||||
free(T);
|
||||
return true;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -34,23 +34,23 @@
|
|||
#define get_byte_2_flip_sign(v) (((unsigned)(v) >> 22) ^ 0x200)
|
||||
#define get_byte_5_flip_sign(v) ((((v) >> 55) & 0x7FF) ^ 0x400)
|
||||
|
||||
bool radix_sort_int64(int64_t *A, size_t n) {
|
||||
int radix_sort_int64(int64_t *A, size_t n) {
|
||||
int64_t *T, *reader, *writer;
|
||||
size_t *b0, *b1, *b2, *b3, *b4, *b5;
|
||||
size_t i, pos, sum0, sum1, sum2, sum3, sum4, sum5, tsum;
|
||||
|
||||
if (n < HIST_SIZE) {
|
||||
_longsort(A, n);
|
||||
return true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(T = (int64_t *)malloc(n * sizeof(int64_t)))) {
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(b0 = (size_t *)calloc(HIST_SIZE * 6, sizeof(size_t)))) {
|
||||
free(T);
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
b1 = b0 + HIST_SIZE;
|
||||
|
@ -140,5 +140,5 @@ bool radix_sort_int64(int64_t *A, size_t n) {
|
|||
|
||||
free(b0);
|
||||
free(T);
|
||||
return true;
|
||||
return 0;
|
||||
}
|
||||
|
|
16
libc/stdbool.h
Normal file
16
libc/stdbool.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_STDBOOL_H_
|
||||
#define COSMOPOLITAN_LIBC_STDBOOL_H_
|
||||
|
||||
#ifndef __cplusplus
|
||||
#if __STDC_VERSION__ + 0 >= 201112
|
||||
#define bool _Bool
|
||||
#else
|
||||
#define bool unsigned char
|
||||
#endif
|
||||
#define true 1
|
||||
#define false 0
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define __bool_true_false_are_defined
|
||||
|
||||
#endif /* COSMOPOLITAN_LIBC_STDBOOL_H_ */
|
|
@ -15,7 +15,7 @@ COSMOPOLITAN_C_START_
|
|||
|
||||
typedef struct FILE {
|
||||
uint8_t bufmode; /* 0x00 _IOFBF, etc. (ignored if fd=-1) */
|
||||
bool noclose; /* 0x01 for fake dup() todo delete! */
|
||||
char noclose; /* 0x01 for fake dup() todo delete! */
|
||||
uint32_t iomode; /* 0x04 O_RDONLY, etc. (ignored if fd=-1) */
|
||||
int32_t state; /* 0x08 0=OK, -1=EOF, >0=errno */
|
||||
int fd; /* 0x0c ≥0=fd, -1=closed|buffer */
|
||||
|
|
|
@ -137,14 +137,6 @@ char *strtok_r(char *, const char *, char **) paramsnonnull((2, 3));
|
|||
wchar_t *wcstok(wchar_t *, const wchar_t *, wchar_t **) paramsnonnull((2, 3));
|
||||
char *wstrtrunc(uint16_t *) memcpyesque;
|
||||
char *wstrntrunc(uint16_t *, size_t) memcpyesque;
|
||||
bool _startswith(const char *, const char *) strlenesque;
|
||||
bool _startswithi(const char *, const char *) strlenesque;
|
||||
bool _startswith16(const char16_t *, const char16_t *) strlenesque;
|
||||
bool _wcsstartswith(const wchar_t *, const wchar_t *) strlenesque;
|
||||
bool _endswith(const char *, const char *) strlenesque;
|
||||
bool _endswith16(const char16_t *, const char16_t *) strlenesque;
|
||||
bool _wcsendswith(const wchar_t *, const wchar_t *) strlenesque;
|
||||
const char *IndexDoubleNulString(const char *, unsigned) strlenesque;
|
||||
int strverscmp(const char *, const char *);
|
||||
wchar_t *wmemset(wchar_t *, wchar_t, size_t) memcpyesque;
|
||||
char16_t *memset16(char16_t *, char16_t, size_t) memcpyesque;
|
||||
|
@ -165,9 +157,6 @@ char *strtoupper(char *) libcesque paramsnonnull();
|
|||
char *_chomp(char *) libcesque;
|
||||
char16_t *_chomp16(char16_t *) libcesque;
|
||||
wchar_t *_wchomp(wchar_t *) libcesque;
|
||||
bool _istext(const void *, size_t) libcesque;
|
||||
bool _isutf8(const void *, size_t) libcesque;
|
||||
bool _escapedos(char16_t *, unsigned, const char16_t *, unsigned) libcesque;
|
||||
|
||||
typedef unsigned mbstate_t;
|
||||
|
||||
|
@ -214,6 +203,20 @@ dontthrow nocallback;
|
|||
int __xpg_strerror_r(int, char *, size_t)
|
||||
dontthrow nocallback;
|
||||
|
||||
#ifdef COSMO
|
||||
bool _startswith(const char *, const char *) strlenesque;
|
||||
bool _startswithi(const char *, const char *) strlenesque;
|
||||
bool _startswith16(const char16_t *, const char16_t *) strlenesque;
|
||||
bool _wcsstartswith(const wchar_t *, const wchar_t *) strlenesque;
|
||||
bool _endswith(const char *, const char *) strlenesque;
|
||||
bool _endswith16(const char16_t *, const char16_t *) strlenesque;
|
||||
bool _wcsendswith(const wchar_t *, const wchar_t *) strlenesque;
|
||||
const char *IndexDoubleNulString(const char *, unsigned) strlenesque;
|
||||
bool _istext(const void *, size_t) libcesque;
|
||||
bool _isutf8(const void *, size_t) libcesque;
|
||||
bool _escapedos(char16_t *, unsigned, const char16_t *, unsigned) libcesque;
|
||||
#endif
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_STR_STR_H_ */
|
||||
|
|
1
third_party/double-conversion/dc.mk
vendored
1
third_party/double-conversion/dc.mk
vendored
|
@ -32,6 +32,7 @@ THIRD_PARTY_DOUBLECONVERSION_A_CHECKS = \
|
|||
THIRD_PARTY_DOUBLECONVERSION_A_DIRECTDEPS = \
|
||||
LIBC_INTRIN \
|
||||
LIBC_NEXGEN32E \
|
||||
LIBC_RUNTIME \
|
||||
LIBC_STR \
|
||||
LIBC_TINYMATH
|
||||
|
||||
|
|
|
@ -1857,7 +1857,7 @@ int main(int argc, char *argv[]) {
|
|||
struct Input *in = inputs.p + i;
|
||||
if (GetElfSymbol(in, "__zipos_get")) {
|
||||
LoadSymbols(in->elf, in->size, in->path);
|
||||
} else {
|
||||
} else if (!want_stripped) {
|
||||
tinyprint(2, in->path,
|
||||
": warning: won't generate symbol table unless "
|
||||
"__static_yoink(\"zipos\") is linked\n",
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
"__NetBSD_Version__"
|
||||
"__OpenBSD__"
|
||||
"__COSMOPOLITAN__"
|
||||
"__COSMOCC__"
|
||||
"__FATCOSMOCC__"
|
||||
"__GLIBC__"
|
||||
"__linux"
|
||||
"__MACH__"
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
CC="$COSMO/o/third_party/gcc/bin/aarch64-linux-musl-gcc"
|
||||
CCFLAGS="-ffixed-x18 -ffixed-x28 -mno-outline-atomics"
|
||||
LDFLAGS="-static -nostdlib -no-pie -Wl,-z,norelro"
|
||||
APEFLAGS="-L$COSMOS/lib/.aarch64 -Wl,--gc-sections -Wl,-T,$COSMO/o/$MODE/ape/aarch64.lds $COSMO/o/$MODE/libc/crt/crt.o"
|
||||
LDFLAGS="-static -nostdlib -no-pie -Wl,-z,norelro -Wl,-z,common-page-size=16384 -Wl,-z,max-page-size=16384"
|
||||
APEFLAGS="-L$COSMOS/lib/.aarch64 -Wl,--gc-sections -Wl,-T,$COSMO/o/$MODE/ape/aarch64.lds"
|
||||
LDLIBS="$COSMO/o/$MODE/cosmopolitan.a"
|
||||
|
||||
if [ x"$PROG" != x"${PROG%++}" ]; then
|
||||
|
@ -34,6 +34,8 @@ for x; do
|
|||
INTENT=cc
|
||||
elif [ x"$x" != x"${x#-o}" ]; then
|
||||
OUTPUT=${x#-o}
|
||||
elif [ x"$x" != x"${x#-L}" ]; then
|
||||
x="$x/.aarch64"
|
||||
elif [ x"$x" = x"-march=native" ]; then
|
||||
continue # doesn't make sense for a cross compiler
|
||||
fi
|
||||
|
@ -53,12 +55,11 @@ if [ $INTENT = cc ]; then
|
|||
else
|
||||
set -- \
|
||||
"$CC" \
|
||||
"$COSMO/o/$MODE/libc/crt/crt.o" \
|
||||
"$@" \
|
||||
$LDFLAGS \
|
||||
$APEFLAGS \
|
||||
"$@" \
|
||||
$LDLIBS \
|
||||
-Wl,-z,common-page-size=16384 \
|
||||
-Wl,-z,max-page-size=16384
|
||||
$LDLIBS
|
||||
fi
|
||||
|
||||
log_command "$@"
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
CC="$COSMO/o/third_party/gcc/bin/x86_64-linux-musl-gcc"
|
||||
CFLAGS="-mno-tls-direct-seg-refs -mno-red-zone"
|
||||
LDFLAGS="-static -nostdlib -no-pie -Wl,-melf_x86_64"
|
||||
APEFLAGS="-L$COSMOS/lib -Wl,--gc-sections -Wl,-T,$COSMO/o/$MODE/ape/public/ape.lds $COSMO/o/$MODE/ape/ape.o $COSMO/o/$MODE/libc/crt/crt.o"
|
||||
LDFLAGS="-static -nostdlib -no-pie -Wl,-melf_x86_64 -Wl,-z,common-page-size=4096 -Wl,-z,max-page-size=4096 -fuse-ld=bfd"
|
||||
APEFLAGS="-L$COSMOS/lib -Wl,--gc-sections -Wl,-T,$COSMO/o/$MODE/ape/public/ape.lds $COSMO/o/$MODE/ape/ape.o"
|
||||
LDLIBS="$COSMO/o/$MODE/cosmopolitan.a"
|
||||
|
||||
if [ x"$PROG" != x"${PROG%++}" ]; then
|
||||
|
@ -57,13 +57,11 @@ if [ $INTENT = cc ]; then
|
|||
else
|
||||
set -- \
|
||||
"$CC" \
|
||||
"$COSMO/o/$MODE/libc/crt/crt.o" \
|
||||
"$@" \
|
||||
$LDFLAGS \
|
||||
$APEFLAGS \
|
||||
"$@" \
|
||||
$LDLIBS \
|
||||
-Wl,-z,common-page-size=4096 \
|
||||
-Wl,-z,max-page-size=4096 \
|
||||
-fuse-ld=bfd
|
||||
$LDLIBS
|
||||
fi
|
||||
|
||||
log_command "$@"
|
||||
|
|
Loading…
Reference in a new issue