mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 03:27:39 +00:00
Refactor fatcosmocc into a single file
This commit is contained in:
parent
b494d56549
commit
0e586c834a
15 changed files with 217 additions and 240 deletions
2
Makefile
2
Makefile
|
@ -425,7 +425,7 @@ $(SRCS): \
|
|||
ifeq ($(ARCH), x86_64)
|
||||
TOOLCHAIN_ARTIFACTS = \
|
||||
o/cosmopolitan.h \
|
||||
o/$(MODE)/ape/public/ape.lds \
|
||||
o/$(MODE)/ape/ape.lds \
|
||||
o/$(MODE)/libc/crt/crt.o \
|
||||
o/$(MODE)/ape/ape.elf \
|
||||
o/$(MODE)/ape/ape.o \
|
||||
|
|
20
ape/ape.mk
20
ape/ape.mk
|
@ -147,25 +147,6 @@ APE_SRCS = $(APE_SRCS_C) $(APE_SRCS_S)
|
|||
APE_OBJS = $(APE_SRCS_S:%.S=o/$(MODE)/%.o)
|
||||
APE_CHECKS = $(APE_HDRS:%=o/%.ok)
|
||||
|
||||
o/$(MODE)/ape/public/ape.lds: CPPFLAGS += -UCOSMO
|
||||
o/$(MODE)/ape/public/ape.lds: \
|
||||
ape/public/ape.lds \
|
||||
ape/ape.lds \
|
||||
ape/ape.internal.h \
|
||||
ape/macros.internal.h \
|
||||
ape/relocations.h \
|
||||
libc/intrin/bits.h \
|
||||
libc/thread/tls.h \
|
||||
libc/calls/struct/timespec.h \
|
||||
libc/thread/thread.h \
|
||||
libc/dce.h \
|
||||
libc/elf/def.h \
|
||||
libc/elf/pf2prot.internal.h \
|
||||
libc/macros.internal.h \
|
||||
libc/nt/pedef.internal.h \
|
||||
libc/str/str.h \
|
||||
libc/zip.internal.h
|
||||
|
||||
o/ape/idata.inc: \
|
||||
ape/idata.internal.h \
|
||||
ape/relocations.h
|
||||
|
@ -269,7 +250,6 @@ o/$(MODE)/ape/ape.elf.dbg: \
|
|||
o/$(MODE)/ape: $(APE_CHECKS) \
|
||||
o/$(MODE)/ape/ape.o \
|
||||
o/$(MODE)/ape/ape.lds \
|
||||
o/$(MODE)/ape/public/ape.lds \
|
||||
o/$(MODE)/ape/ape.elf \
|
||||
o/$(MODE)/ape/ape.macho \
|
||||
o/$(MODE)/ape/ape-copy-self.o \
|
||||
|
|
|
@ -113,8 +113,8 @@ log_command() {
|
|||
ORIGINAL="$0 $*"
|
||||
PLATFORM="-D__COSMOPOLITAN__ -D__COSMOCC__"
|
||||
PREDEF="-include libc/integral/normalize.inc"
|
||||
CFLAGS="-fportcosmo"
|
||||
CPPFLAGS="-fno-pie -nostdinc -iquote $COSMO"
|
||||
CFLAGS="-fportcosmo -fno-dwarf2-cfi-asm -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-semantic-interposition"
|
||||
CPPFLAGS="-fno-pie -nostdinc -fno-math-errno -iquote $COSMO"
|
||||
LDFLAGS="-static -no-pie -nostdlib -fuse-ld=bfd"
|
||||
APEFLAGS="-Wl,--gc-sections"
|
||||
PRECIOUS="-fno-omit-frame-pointer"
|
||||
|
@ -155,7 +155,7 @@ if [ x"$ARCH" = x"x86_64" ]; then
|
|||
CRT="$COSMO/o/$MODE/ape/ape-no-modify-self.o $CRT"
|
||||
CPPFLAGS="$CPPFLAGS -mno-red-zone"
|
||||
CFLAGS="$CFLAGS -mno-tls-direct-seg-refs"
|
||||
LDFLAGS="$LDFLAGS -Wl,-T,$COSMO/o/$MODE/ape/public/ape.lds"
|
||||
LDFLAGS="$LDFLAGS -Wl,-T,$COSMO/o/$MODE/ape/ape.lds"
|
||||
if [ x"$MODE" = x"aarch64" ]; then
|
||||
fatal_error '$MODE must not be aarch64 when using x86_64 cross compiler'
|
||||
elif [ x"$MODE" != x"${MODE#* }" ]; then
|
||||
|
@ -244,6 +244,9 @@ for x; do
|
|||
INTENT=cpp
|
||||
elif [ x"$x" = x"-o" ]; then
|
||||
NEED_OUTPUT=1
|
||||
elif [ x"$x" = x"-mcosmo" ]; then
|
||||
CPPFLAGS="$CPPFLAGS -D_COSMO_SOURCE"
|
||||
continue
|
||||
elif [ x"$x" != x"${x#-o}" ]; then
|
||||
OUTPUT=${x#-o}
|
||||
elif [ x"$x" = x"-fpic" ]; then
|
||||
|
|
185
bin/fatcosmocc
185
bin/fatcosmocc
|
@ -101,11 +101,11 @@
|
|||
#
|
||||
# for further details, run `man gcc`
|
||||
|
||||
export PROG=${0##*/}
|
||||
export COSMO=${COSMO:-/opt/cosmo}
|
||||
export COSMOS=${COSMOS:-/opt/cosmos}
|
||||
export ORIGINAL="$0 $*"
|
||||
export TMPDIR=${TMPDIR:-/tmp}
|
||||
PROG=${0##*/}
|
||||
COSMO=${COSMO:-/opt/cosmo}
|
||||
COSMOS=${COSMOS:-/opt/cosmos}
|
||||
ORIGINAL="$0 $*"
|
||||
TMPDIR=${TMPDIR:-/tmp}
|
||||
GCC_VERSION=11.2.0
|
||||
|
||||
if [ "$1" = "--version" ]; then
|
||||
|
@ -186,8 +186,7 @@ if [ ! -f "$COSMOS/lib/libc.a" ] ||
|
|||
exit 1
|
||||
fi
|
||||
|
||||
export FIXUPOBJ="$COSMO/o//tool/build/fixupobj.com"
|
||||
|
||||
FIXUPOBJ="$COSMO/o//tool/build/fixupobj.com"
|
||||
TEMP_FILES=
|
||||
SAVE_TEMPS=0
|
||||
|
||||
|
@ -209,9 +208,15 @@ fatal_error() {
|
|||
Exit 1
|
||||
}
|
||||
|
||||
log_original() {
|
||||
if [ -n "$BUILDLOG" ]; then
|
||||
printf '# %s\n' "$ORIGINAL" >>"$BUILDLOG"
|
||||
fi
|
||||
}
|
||||
|
||||
log_command() {
|
||||
if [ -n "$BUILDLOG" ]; then
|
||||
printf '# %s\n(cd %s; %s)\n' "$ORIGINAL" "$PWD" "$*" >>"$BUILDLOG"
|
||||
printf '(cd %s; %s)\n' "$PWD" "$*" >>"$BUILDLOG"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -227,6 +232,7 @@ OPT=
|
|||
ARGS=
|
||||
FLAGS=
|
||||
OUTPUT=
|
||||
MCOSMO=0
|
||||
INTENT=ld
|
||||
NEED_JOIN=
|
||||
NEED_EQUAL=
|
||||
|
@ -279,10 +285,13 @@ for x; do
|
|||
continue
|
||||
elif [ x"$x" = x"-v" ]; then
|
||||
exec 3<&2 # dup2(2, 3) b/c stderr will be redirected later
|
||||
export BUILDLOG=/dev/fd/3
|
||||
BUILDLOG=/dev/fd/3
|
||||
continue
|
||||
elif [ x"$x" = x"-save-temps" ]; then
|
||||
SAVE_TEMPS=1
|
||||
elif [ x"$x" = x"-mcosmo" ]; then
|
||||
MCOSMO=1
|
||||
continue
|
||||
elif [ x"$x" = x"-fomit-frame-pointer" ]; then
|
||||
# Quoth Apple: "The frame pointer register must always address a
|
||||
# valid frame record. Some functions — such as leaf functions or
|
||||
|
@ -357,27 +366,61 @@ fi
|
|||
|
||||
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"
|
||||
CCFLAGS_END="-fno-omit-frame-pointer"
|
||||
CPPFLAGS="-fno-pie -nostdinc -fno-math-errno -iquote $COSMO -isystem $COSMOS/include -isystem $COSMO/libc/isystem"
|
||||
CFLAGS="-fportcosmo -fno-dwarf2-cfi-asm -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-semantic-interposition"
|
||||
LDFLAGS="-static -nostdlib -no-pie -fuse-ld=bfd -Wl,-z,norelro -Wl,--gc-sections"
|
||||
PRECIOUS="-fno-omit-frame-pointer"
|
||||
|
||||
if [ x"$OPT" != x"-Os" ] && [ x"$MODE" != x"tiny" ]; then
|
||||
CFLAGS="$CFLAGS -fno-optimize-sibling-calls -mno-omit-leaf-frame-pointer"
|
||||
fi
|
||||
|
||||
CC_X86_64="$COSMO/o/third_party/gcc/bin/x86_64-linux-musl-gcc"
|
||||
CC_AARCH64="$COSMO/o/third_party/gcc/bin/aarch64-linux-musl-gcc"
|
||||
if [ x"$PROG" != x"${PROG%++}" ]; then
|
||||
CC_X86_64="$COSMO/o/third_party/gcc/bin/x86_64-linux-musl-g++"
|
||||
CC_AARCH64="$COSMO/o/third_party/gcc/bin/aarch64-linux-musl-g++"
|
||||
CFLAGS="$CFLAGS -fno-rtti -fno-exceptions -fuse-cxa-atexit"
|
||||
fi
|
||||
|
||||
CRT_X86_64="$COSMO/o/$MODE/ape/ape.o $COSMO/o/$MODE/libc/crt/crt.o"
|
||||
CPPFLAGS_X86_64="$CPPFLAGS -mno-red-zone"
|
||||
CFLAGS_X86_64="$CFLAGS -mno-tls-direct-seg-refs"
|
||||
LDFLAGS_X86_64="$LDFLAGS -L$COSMOS/lib -Wl,-T,$COSMO/o/$MODE/ape/ape.lds -Wl,-z,common-page-size=4096 -Wl,-z,max-page-size=4096"
|
||||
LDLIBS_X86_64="$COSMO/o/$MODE/cosmopolitan.a"
|
||||
if [ $MCOSMO -eq 1 ]; then
|
||||
CPPFLAGS_X86_64="${CPPFLAGS_X86_64} -D_COSMO_SOURCE"
|
||||
fi
|
||||
|
||||
CRT_AARCH64="$COSMO/o/$MODE_AARCH64/libc/crt/crt.o"
|
||||
CPPFLAGS_AARCH64="$CPPFLAGS"
|
||||
CFLAGS_AARCH64="$CFLAGS -ffixed-x18 -ffixed-x28 -mno-outline-atomics"
|
||||
LDFLAGS_AARCH64="$LDFLAGS -L$COSMOS/lib/.aarch64 -Wl,-T,$COSMO/o/${MODE_AARCH64}/ape/aarch64.lds -Wl,-z,common-page-size=16384 -Wl,-z,max-page-size=16384"
|
||||
LDLIBS_AARCH64="$COSMO/o/${MODE_AARCH64}/cosmopolitan.a"
|
||||
|
||||
if [ x"$OPT" != x"-Os" ] && [ x"$MODE" != x"tiny" ]; then
|
||||
CFLAGS_X86_64="${CFLAGS_X86_64} -fpatchable-function-entry=18,16"
|
||||
CFLAGS_AARCH64="${CFLAGS_AARCH64} -fpatchable-function-entry=7,6"
|
||||
fi
|
||||
|
||||
if [ x"$PROG" != x"${PROG%++}" ]; then
|
||||
LDLIBS_X86_64="$COSMO/o/$MODE/third_party/libcxx/libcxx.a ${LDLIBS_X86_64}"
|
||||
LDLIBS_AARCH64="$COSMO/o/${MODE_AARCH64}/third_party/libcxx/libcxx.a ${LDLIBS_AARCH64}"
|
||||
fi
|
||||
|
||||
if [ x"$MODE" = x"dbg" ]; then
|
||||
CPPFLAGS_START="-fsanitize=address -fsanitize=undefined"
|
||||
fi
|
||||
if [ x"$OPT" != x"-Os" ] &&
|
||||
[ x"${MODE#tiny}" != x"${MODE}" ]; then
|
||||
CCFLAGS_START="${CCFLAGS_START} -fno-optimize-sibling-calls -mno-omit-leaf-frame-pointer"
|
||||
CPPFLAGS_X86_64="${CPPFLAGS_X86_64} -fsanitize=address -fsanitize=undefined"
|
||||
CPPFLAGS_AARCH64="${CPPFLAGS_AARCH64} -fsanitize=undefined"
|
||||
fi
|
||||
|
||||
log_original
|
||||
|
||||
if [ $INTENT = cpp ]; then
|
||||
if [ -n "$OUTPUT" ]; then
|
||||
ARGS="$ARGS -o$OUTPUT"
|
||||
fi
|
||||
CC="$COSMO/o/third_party/gcc/bin/x86_64-linux-musl-gcc"
|
||||
if [ x"$PROG" != x"${PROG%++}" ]; then
|
||||
CC="$COSMO/o/third_party/gcc/bin/x86_64-linux-musl-g++"
|
||||
fi
|
||||
set -- \
|
||||
"$CC" \
|
||||
"$CC_X86_64" \
|
||||
-U__k8 \
|
||||
-U__k8__ \
|
||||
-U__amd64 \
|
||||
|
@ -419,26 +462,43 @@ mktemper() {
|
|||
build_object() {
|
||||
out2=$(mktemper .txt) || Exit
|
||||
TEMP_FILES="${TEMP_FILES} $out2"
|
||||
MODE="$MODE" \
|
||||
"$COSMO/tool/scripts/fat-x86_64" \
|
||||
-o"$OUTPUT_X86_64" \
|
||||
$PLATFORM \
|
||||
$PREDEF \
|
||||
$CPPFLAGS \
|
||||
$CCFLAGS_START \
|
||||
"$@" \
|
||||
$CCFLAGS_END &
|
||||
(
|
||||
set -- \
|
||||
"$CC_X86_64" \
|
||||
-o"$OUTPUT_X86_64" \
|
||||
$PLATFORM \
|
||||
$PREDEF \
|
||||
$CFLAGS_X86_64 \
|
||||
$CPPFLAGS_X86_64 \
|
||||
"$@" \
|
||||
$PRECIOUS
|
||||
log_command "$@"
|
||||
"$@" || exit
|
||||
set -- \
|
||||
"$COSMO/o//tool/build/fixupobj.com" \
|
||||
"$OUTPUT_X86_64"
|
||||
log_command "$@"
|
||||
exec "$@"
|
||||
) &
|
||||
pid1=$!
|
||||
MODE="$MODE_AARCH64" \
|
||||
"$COSMO/tool/scripts/fat-aarch64" \
|
||||
-o"$OUTPUT_AARCH64" \
|
||||
$PLATFORM \
|
||||
$PREDEF \
|
||||
$CPPFLAGS \
|
||||
$CCFLAGS_START \
|
||||
"$@" \
|
||||
$CCFLAGS_END \
|
||||
2>"$out2" &
|
||||
(
|
||||
set -- \
|
||||
"$CC_AARCH64" \
|
||||
-o"$OUTPUT_AARCH64" \
|
||||
$PLATFORM \
|
||||
$PREDEF \
|
||||
$CFLAGS_AARCH64 \
|
||||
$CPPFLAGS_AARCH64 \
|
||||
"$@" \
|
||||
$PRECIOUS &&
|
||||
log_command "$@"
|
||||
"$@" || exit
|
||||
set -- \
|
||||
"$COSMO/o//tool/build/fixupobj.com" \
|
||||
"$OUTPUT_AARCH64"
|
||||
log_command "$@"
|
||||
exec "$@"
|
||||
) 2>"$out2" &
|
||||
pid2=$!
|
||||
if ! wait $pid1; then
|
||||
kill $pid2 2>/dev/null
|
||||
|
@ -446,7 +506,7 @@ build_object() {
|
|||
Exit 1
|
||||
fi
|
||||
if ! wait $pid2; then
|
||||
echo "$PROG: x86_64 succeeded but failed to build object for aarch64:" >&2
|
||||
echo "$PROG: x86_64 succeeded but aarch64 failed to build object" >&2
|
||||
cat "$out2" >&2
|
||||
Exit 1
|
||||
fi
|
||||
|
@ -460,6 +520,9 @@ for x in $ARGS; do
|
|||
[ x"$x" != x"${x#-*}" ]; then # startswith(x, "-")
|
||||
# this argument is a flag
|
||||
LDARGS_X86_64="${LDARGS_X86_64} $x"
|
||||
if [ x"$x" != x"${x#-L}" ]; then # startswith(x, "-L")
|
||||
x="$x/.aarch64"
|
||||
fi
|
||||
LDARGS_AARCH64="${LDARGS_AARCH64} $x"
|
||||
else
|
||||
# this argument is an input file
|
||||
|
@ -515,11 +578,39 @@ OUTPUT_AARCH64=$(mktemper ".aarch64.elf") || Exit
|
|||
|
||||
out2=$(mktemper .txt) || Exit
|
||||
TEMP_FILES="${TEMP_FILES} $out2"
|
||||
MODE="$MODE" \
|
||||
"$COSMO/tool/scripts/fat-x86_64" -o"$OUTPUT_X86_64" $LDARGS_X86_64 &
|
||||
(
|
||||
set -- \
|
||||
"$CC_X86_64" \
|
||||
-o"$OUTPUT_X86_64"\
|
||||
$CRT_X86_64 \
|
||||
$LDFLAGS_X86_64 \
|
||||
$LDARGS_X86_64 \
|
||||
$LDLIBS_X86_64
|
||||
log_command "$@"
|
||||
"$@" || exit
|
||||
set -- \
|
||||
"$COSMO/o//tool/build/fixupobj.com" \
|
||||
"$OUTPUT_X86_64"
|
||||
log_command "$@"
|
||||
exec "$@"
|
||||
) &
|
||||
pid1=$!
|
||||
MODE="$MODE_AARCH64" \
|
||||
"$COSMO/tool/scripts/fat-aarch64" -o"$OUTPUT_AARCH64" $LDARGS_AARCH64 2>"$out2" &
|
||||
(
|
||||
set -- \
|
||||
"$CC_AARCH64" \
|
||||
-o"$OUTPUT_AARCH64"\
|
||||
$CRT_AARCH64 \
|
||||
$LDFLAGS_AARCH64 \
|
||||
$LDARGS_AARCH64 \
|
||||
$LDLIBS_AARCH64
|
||||
log_command "$@"
|
||||
"$@" || exit
|
||||
set -- \
|
||||
"$COSMO/o//tool/build/fixupobj.com" \
|
||||
"$OUTPUT_AARCH64"
|
||||
log_command "$@"
|
||||
exec "$@"
|
||||
) 2>"$out2" &
|
||||
pid2=$!
|
||||
if ! wait $pid1; then
|
||||
kill $pid2 2>/dev/null
|
||||
|
@ -527,7 +618,7 @@ if ! wait $pid1; then
|
|||
Exit 1
|
||||
fi
|
||||
if ! wait $pid2; then
|
||||
echo "$PROG: x86_64 succeeded but failed to link executable for aarch64:" >&2
|
||||
echo "$PROG: x86_64 succeeded but aarch64 failed to link executable" >&2
|
||||
cat "$out2" >&2
|
||||
Exit 1
|
||||
fi
|
||||
|
|
|
@ -74,15 +74,12 @@
|
|||
#define __BIGGEST_ALIGNMENT__ 16
|
||||
#endif
|
||||
|
||||
#ifdef _COSMO_SOURCE
|
||||
/* Programs should call GetStackSize() */
|
||||
#define APE_STACKSIZE 262144 /* default 256kb stack */
|
||||
#define FRAMESIZE 0x10000
|
||||
#define _PAGESIZE 0x1000 /* i386+ */
|
||||
#else
|
||||
#define APE_STACKSIZE 4194304 /* default 4mb stack */
|
||||
#define APE_PAGESIZE 0x10000 /* i386+ */
|
||||
#ifdef _COSMO_SOURCE
|
||||
#define FRAMESIZE 0x10000
|
||||
#define _PAGESIZE 0x1000 /* i386+ */
|
||||
#endif
|
||||
#define APE_PAGESIZE 0x10000 /* i386+ */
|
||||
|
||||
#define BUFSIZ 0x1000 /* best stdio default */
|
||||
#define CHAR_BIT 8 /* b/c von neumann */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef _GETOPT_H
|
||||
#define _GETOPT_H
|
||||
#include "third_party/getopt/long.h"
|
||||
#include "third_party/getopt/long2.h"
|
||||
#endif /* _GETOPT_H */
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/ok.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "third_party/getopt/long.h"
|
||||
#include "third_party/getopt/long1.h"
|
||||
#include "third_party/musl/crypt.h"
|
||||
#include "third_party/musl/lockf.h"
|
||||
#endif /* _UNISTD_H */
|
||||
|
|
|
@ -8,7 +8,7 @@ ifeq ($(ARCH), x86_64)
|
|||
o/$(MODE)/test/libc/release/cosmopolitan.zip: private .UNSANDBOXED = 1
|
||||
o/$(MODE)/test/libc/release/cosmopolitan.zip: \
|
||||
o/cosmopolitan.h \
|
||||
o/$(MODE)/ape/public/ape.lds \
|
||||
o/$(MODE)/ape/ape.lds \
|
||||
o/$(MODE)/libc/crt/crt.o \
|
||||
o/$(MODE)/ape/ape.o \
|
||||
o/$(MODE)/ape/ape-copy-self.o \
|
||||
|
@ -19,7 +19,7 @@ o/$(MODE)/test/libc/release/cosmopolitan.zip: \
|
|||
o/$(MODE)/third_party/zip/zip.com \
|
||||
-b$(TMPDIR) -qj $@ \
|
||||
o/cosmopolitan.h \
|
||||
o/$(MODE)/ape/public/ape.lds \
|
||||
o/$(MODE)/ape/ape.lds \
|
||||
o/$(MODE)/libc/crt/crt.o \
|
||||
o/$(MODE)/ape/ape.o \
|
||||
o/$(MODE)/ape/ape-copy-self.o \
|
||||
|
@ -44,7 +44,7 @@ o/$(MODE)/test/libc/release/smoke.o: \
|
|||
|
||||
o/$(MODE)/test/libc/release/smoke.com.dbg: \
|
||||
o/$(MODE)/test/libc/release/smoke.o \
|
||||
o/$(MODE)/ape/public/ape.lds \
|
||||
o/$(MODE)/ape/ape.lds \
|
||||
o/$(MODE)/libc/crt/crt.o \
|
||||
o/$(MODE)/ape/ape.o \
|
||||
o/$(MODE)/cosmopolitan.a
|
||||
|
@ -55,7 +55,7 @@ o/$(MODE)/test/libc/release/smoke.com.dbg: \
|
|||
--gc-sections \
|
||||
-z max-page-size=0x1000 \
|
||||
-z common-page-size=0x1000 \
|
||||
-T o/$(MODE)/ape/public/ape.lds \
|
||||
-T o/$(MODE)/ape/ape.lds \
|
||||
o/$(MODE)/test/libc/release/smoke.o \
|
||||
o/$(MODE)/libc/crt/crt.o \
|
||||
o/$(MODE)/ape/ape.o \
|
||||
|
@ -64,7 +64,7 @@ o/$(MODE)/test/libc/release/smoke.com.dbg: \
|
|||
|
||||
o/$(MODE)/test/libc/release/smoke-nms.com.dbg: \
|
||||
o/$(MODE)/test/libc/release/smoke.o \
|
||||
o/$(MODE)/ape/public/ape.lds \
|
||||
o/$(MODE)/ape/ape.lds \
|
||||
o/$(MODE)/libc/crt/crt.o \
|
||||
o/$(MODE)/ape/ape-no-modify-self.o \
|
||||
o/$(MODE)/cosmopolitan.a
|
||||
|
@ -75,7 +75,7 @@ o/$(MODE)/test/libc/release/smoke-nms.com.dbg: \
|
|||
--gc-sections \
|
||||
-z max-page-size=0x1000 \
|
||||
-z common-page-size=0x1000 \
|
||||
-T o/$(MODE)/ape/public/ape.lds \
|
||||
-T o/$(MODE)/ape/ape.lds \
|
||||
o/$(MODE)/test/libc/release/smoke.o \
|
||||
o/$(MODE)/libc/crt/crt.o \
|
||||
o/$(MODE)/ape/ape-no-modify-self.o \
|
||||
|
@ -84,7 +84,7 @@ o/$(MODE)/test/libc/release/smoke-nms.com.dbg: \
|
|||
|
||||
o/$(MODE)/test/libc/release/smoke-chibicc.com.dbg: \
|
||||
o/$(MODE)/test/libc/release/smoke-chibicc.o \
|
||||
o/$(MODE)/ape/public/ape.lds \
|
||||
o/$(MODE)/ape/ape.lds \
|
||||
o/$(MODE)/libc/crt/crt.o \
|
||||
o/$(MODE)/ape/ape-no-modify-self.o \
|
||||
o/$(MODE)/cosmopolitan.a \
|
||||
|
@ -96,7 +96,7 @@ o/$(MODE)/test/libc/release/smoke-chibicc.com.dbg: \
|
|||
--gc-sections \
|
||||
-z max-page-size=0x1000 \
|
||||
-z common-page-size=0x1000 \
|
||||
-T o/$(MODE)/ape/public/ape.lds \
|
||||
-T o/$(MODE)/ape/ape.lds \
|
||||
o/$(MODE)/test/libc/release/smoke-chibicc.o \
|
||||
o/$(MODE)/libc/crt/crt.o \
|
||||
o/$(MODE)/ape/ape-no-modify-self.o \
|
||||
|
@ -124,7 +124,7 @@ o/$(MODE)/test/libc/release/smoke-chibicc.o: \
|
|||
|
||||
o/$(MODE)/test/libc/release/smokecxx.com.dbg: \
|
||||
o/$(MODE)/test/libc/release/smokecxx.o \
|
||||
o/$(MODE)/ape/public/ape.lds \
|
||||
o/$(MODE)/ape/ape.lds \
|
||||
o/$(MODE)/libc/crt/crt.o \
|
||||
o/$(MODE)/ape/ape.o \
|
||||
o/$(MODE)/cosmopolitan.a \
|
||||
|
@ -136,7 +136,7 @@ o/$(MODE)/test/libc/release/smokecxx.com.dbg: \
|
|||
--gc-sections \
|
||||
-z max-page-size=0x1000 \
|
||||
-z common-page-size=0x1000 \
|
||||
-T o/$(MODE)/ape/public/ape.lds \
|
||||
-T o/$(MODE)/ape/ape.lds \
|
||||
o/$(MODE)/test/libc/release/smokecxx.o \
|
||||
o/$(MODE)/libc/crt/crt.o \
|
||||
o/$(MODE)/ape/ape.o \
|
||||
|
@ -162,7 +162,7 @@ o/$(MODE)/test/libc/release/smokecxx.o: \
|
|||
|
||||
o/$(MODE)/test/libc/release/smokeansi.com.dbg: \
|
||||
o/$(MODE)/test/libc/release/smokeansi.o \
|
||||
o/$(MODE)/ape/public/ape.lds \
|
||||
o/$(MODE)/ape/ape.lds \
|
||||
o/$(MODE)/libc/crt/crt.o \
|
||||
o/$(MODE)/ape/ape.o \
|
||||
o/$(MODE)/cosmopolitan.a
|
||||
|
@ -173,7 +173,7 @@ o/$(MODE)/test/libc/release/smokeansi.com.dbg: \
|
|||
--gc-sections \
|
||||
-z max-page-size=0x1000 \
|
||||
-z common-page-size=0x1000 \
|
||||
-T o/$(MODE)/ape/public/ape.lds \
|
||||
-T o/$(MODE)/ape/ape.lds \
|
||||
o/$(MODE)/test/libc/release/smokeansi.o \
|
||||
o/$(MODE)/libc/crt/crt.o \
|
||||
o/$(MODE)/ape/ape.o \
|
||||
|
|
3
third_party/getopt/getopt.internal.h
vendored
3
third_party/getopt/getopt.internal.h
vendored
|
@ -1,6 +1,7 @@
|
|||
#ifndef COSMOPOLITAN_GETOPT_H_
|
||||
#define COSMOPOLITAN_GETOPT_H_
|
||||
#ifdef COSMOPOLITAN_GETOPT_LONG_H_
|
||||
#if defined(COSMOPOLITAN_GETOPT_LONG1_H_) || \
|
||||
defined(COSMOPOLITAN_GETOPT_LONG2_H_)
|
||||
#error "don't mix getopt_long() with cosmo's getopt()"
|
||||
#endif
|
||||
|
||||
|
|
3
third_party/getopt/long.c
vendored
3
third_party/getopt/long.c
vendored
|
@ -1,7 +1,8 @@
|
|||
#include "third_party/getopt/long.h"
|
||||
#include "libc/log/bsd.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "third_party/getopt/long1.h"
|
||||
#include "third_party/getopt/long2.h"
|
||||
// clang-format off
|
||||
|
||||
/* $OpenBSD: getopt_long.c,v 1.32 2020/05/27 22:25:09 schwarze Exp $ */
|
||||
|
|
16
third_party/getopt/long1.h
vendored
Executable file
16
third_party/getopt/long1.h
vendored
Executable file
|
@ -0,0 +1,16 @@
|
|||
#ifndef COSMOPOLITAN_GETOPT_LONG1_H_
|
||||
#define COSMOPOLITAN_GETOPT_LONG1_H_
|
||||
#ifdef COSMOPOLITAN_GETOPT_H_
|
||||
#error "don't mix getopt_long() with cosmo's getopt()"
|
||||
#endif
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
extern char *optarg;
|
||||
extern int optind, opterr, optopt, optreset;
|
||||
|
||||
int getopt(int, char *const *, const char *);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_GETOPT_LONG1_H_ */
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef COSMOPOLITAN_GETOPT_LONG_H_
|
||||
#define COSMOPOLITAN_GETOPT_LONG_H_
|
||||
#ifndef COSMOPOLITAN_GETOPT_LONG2_H_
|
||||
#define COSMOPOLITAN_GETOPT_LONG2_H_
|
||||
#ifdef COSMOPOLITAN_GETOPT_H_
|
||||
#error "don't mix getopt_long() with cosmo's getopt()"
|
||||
#endif
|
||||
|
@ -18,14 +18,10 @@ struct option {
|
|||
int val;
|
||||
};
|
||||
|
||||
extern char *optarg;
|
||||
extern int optind, opterr, optopt, optreset;
|
||||
|
||||
int getopt(int, char *const *, const char *);
|
||||
int getopt_long(int, char *const *, const char *, const struct option *, int *);
|
||||
int getopt_long_only(int, char *const *, const char *, const struct option *,
|
||||
int *);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_GETOPT_LONG_H_ */
|
||||
#endif /* COSMOPOLITAN_GETOPT_LONG2_H_ */
|
31
tool/build/freebsd2sysv.c
Normal file
31
tool/build/freebsd2sysv.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/elf/def.h"
|
||||
#include "libc/elf/struct/ehdr.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sysv/consts/map.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
open(argv[1], O_RDWR);
|
||||
Elf64_Ehdr *e = mmap(0, 64, PROT_READ | PROT_WRITE, MAP_SHARED, 3, 0);
|
||||
e->e_ident[EI_OSABI] = ELFOSABI_SYSV;
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
#!/bin/sh
|
||||
# arm64 backend compiler for fatcosmocc
|
||||
|
||||
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 -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
|
||||
CC="$COSMO/o/third_party/gcc/bin/aarch64-linux-musl-g++"
|
||||
CCFLAGS="$CCFLAGS -fno-rtti -fno-exceptions -fuse-cxa-atexit"
|
||||
LDLIBS="$COSMO/o/$MODE/third_party/libcxx/libcxx.a $LDLIBS"
|
||||
fi
|
||||
|
||||
log_command() {
|
||||
if [ -n "$BUILDLOG" ]; then
|
||||
printf '# %s\n(cd %s; %s)\n' "$ORIGINAL" "$PWD" "$*" >>"$BUILDLOG"
|
||||
fi
|
||||
}
|
||||
|
||||
OPT=
|
||||
FIRST=1
|
||||
OUTPUT=
|
||||
INTENT=ld
|
||||
for x; do
|
||||
if [ $FIRST -eq 1 ]; then
|
||||
set --
|
||||
FIRST=0
|
||||
fi
|
||||
if [ x"$x" != x"${x#-O}" ]; then
|
||||
OPT=$x
|
||||
elif [ x"$x" = x"-c" ]; then
|
||||
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
|
||||
set -- "$@" "$x"
|
||||
done
|
||||
|
||||
if [ x"$OPT" != x"-Os" ] && # $OPT != -Os
|
||||
[ x"${MODE%tiny}" = x"${MODE}" ]; then # $MODE not in (tiny, aarch64-tiny)
|
||||
# support --ftrace unless optimizing for size
|
||||
CCFLAGS="$CCFLAGS -fpatchable-function-entry=7,6"
|
||||
fi
|
||||
|
||||
if [ $INTENT = cc ]; then
|
||||
set -- \
|
||||
"$CC" \
|
||||
$CCFLAGS \
|
||||
"$@"
|
||||
else
|
||||
set -- \
|
||||
"$CC" \
|
||||
"$COSMO/o/$MODE/libc/crt/crt.o" \
|
||||
"$@" \
|
||||
$LDFLAGS \
|
||||
$APEFLAGS \
|
||||
$LDLIBS
|
||||
fi
|
||||
|
||||
log_command "$@"
|
||||
"$@" || exit
|
||||
"$FIXUPOBJ" "$OUTPUT" || exit
|
|
@ -1,71 +0,0 @@
|
|||
#!/bin/sh
|
||||
# amd64 backend compiler for fatcosmocc
|
||||
|
||||
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 -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"
|
||||
LDLIBS="$COSMO/o/$MODE/cosmopolitan.a"
|
||||
|
||||
if [ x"$PROG" != x"${PROG%++}" ]; then
|
||||
CC="$COSMO/o/third_party/gcc/bin/x86_64-linux-musl-g++"
|
||||
CFLAGS="$CFLAGS -fno-rtti -fno-exceptions -fuse-cxa-atexit"
|
||||
LDLIBS="$COSMO/o/$MODE/third_party/libcxx/libcxx.a $LDLIBS"
|
||||
fi
|
||||
|
||||
log_command() {
|
||||
if [ -n "$BUILDLOG" ]; then
|
||||
printf '# %s\n(cd %s; %s)\n' "$ORIGINAL" "$PWD" "$*" >>"$BUILDLOG"
|
||||
fi
|
||||
}
|
||||
|
||||
OPT=
|
||||
FIRST=1
|
||||
OUTPUT=
|
||||
INTENT=ld
|
||||
for x; do
|
||||
if [ $FIRST -eq 1 ]; then
|
||||
set --
|
||||
FIRST=0
|
||||
fi
|
||||
if [ x"$x" != x"${x#-O}" ]; then
|
||||
OPT=$x
|
||||
elif [ x"$x" = x"-c" ]; then
|
||||
INTENT=cc
|
||||
elif [ x"$x" != x"${x#-o}" ]; then
|
||||
OUTPUT=${x#-o}
|
||||
elif [ x"$x" = x"-march=native" ]; then
|
||||
continue # doesn't make sense for a cross compiler
|
||||
fi
|
||||
set -- "$@" "$x"
|
||||
done
|
||||
|
||||
if [ x"$MODE" = x"nox87" ]; then
|
||||
CFLAGS="$CFLAGS -mlong-double-64"
|
||||
fi
|
||||
|
||||
if [ x"$OPT" != x"-Os" ] && # $OPT != -Os
|
||||
[ x"${MODE%tiny}" = x"${MODE}" ]; then # $MODE not in (tiny, aarch64-tiny)
|
||||
# support --ftrace unless optimizing for size
|
||||
CFLAGS="$CFLAGS -fpatchable-function-entry=18,16"
|
||||
fi
|
||||
|
||||
if [ $INTENT = cc ]; then
|
||||
set -- \
|
||||
"$CC" \
|
||||
$CFLAGS \
|
||||
"$@"
|
||||
else
|
||||
set -- \
|
||||
"$CC" \
|
||||
"$COSMO/o/$MODE/ape/ape.o" \
|
||||
"$COSMO/o/$MODE/libc/crt/crt.o" \
|
||||
"$@" \
|
||||
$LDFLAGS \
|
||||
$APEFLAGS \
|
||||
$LDLIBS
|
||||
fi
|
||||
|
||||
log_command "$@"
|
||||
"$@" || exit
|
||||
"$FIXUPOBJ" "$OUTPUT" || exit
|
Loading…
Reference in a new issue