Improve cosmocc / cosmoc++ toolchains

They'll now automatically create empty static archives for system
libraries that are provided by Cosmopolitan Libc. This helps make
configure scripts less confused. Musl does the same thing.
This commit is contained in:
Justine Tunney 2022-11-14 13:45:57 -08:00
parent a277170c9a
commit b850b14300
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
4 changed files with 78 additions and 8 deletions

View file

@ -172,6 +172,16 @@
"uint128_t"
"axdx_t"))
(linux
'("i8"
"u8"
"i16"
"u16"
"i32"
"u32"
"i64"
"u64"))
(x86intrin
'("__v8hu"
"__v16qi"
@ -218,6 +228,7 @@
gnu
cxx17
cosmo
linux
x86intrin))
"\\_>")))

View file

@ -148,7 +148,7 @@
;; M-4 C-c C-c Compile w/ MODE=dbg
;; M-5 C-c C-c Compile w/ MODE=""
;; M-7 C-c C-c Compile w/ MODE=tinylinux
;; M-8 C-c C-c Compile w/ llvm
;; M-8 C-c C-c Compile w/ clang tsan
;; M-9 C-c C-c Compile w/ chibicc
(defun cosmo-intest (&optional file-name)
@ -166,7 +166,7 @@
((eq arg 5) "")
((eq arg 6) "optlinux")
((eq arg 7) "tinylinux")
((eq arg 8) "llvm")
((eq arg 8) "tsan")
(default default)
((cosmo-intest) "dbg")
(t "fastbuild")))

View file

@ -30,12 +30,30 @@ exit 0
fi
CXX="/opt/cosmo/o/third_party/gcc/bin/x86_64-linux-musl-g++"
CCFLAGS="-O2 -fno-omit-frame-pointer -fdata-sections -ffunction-sections -fno-pie -pg -mnop-mcount -mno-tls-direct-seg-refs"
CCFLAGS="-O2 -fdata-sections -ffunction-sections -fno-pie -pg -mnop-mcount -mno-tls-direct-seg-refs"
CXXFLAGS="-fno-exceptions -fuse-cxa-atexit -fno-threadsafe-statics"
CPPFLAGS="-DNDEBUG -nostdinc -iquote /opt/cosmo -isystem /opt/cosmos/include -isystem /opt/cosmo/libc/isystem -include libc/integral/normalize.inc"
LDFLAGS="-static -no-pie -nostdlib -fuse-ld=bfd -Wl,-melf_x86_64 -Wl,--gc-sections -Wl,-z,max-page-size=0x1000 -L/opt/cosmos/lib -Wl,-T,/opt/cosmo/o/ape/public/ape.lds /opt/cosmo/o/ape/ape-no-modify-self.o /opt/cosmo/o/libc/crt/crt.o"
LDLIBS="/opt/cosmo/o/third_party/libcxx/libcxx.a /opt/cosmo/o/cosmopolitan.a"
if [ ! -d $COSMO ]; then
echo you need to checkout cosmopolitan to your $COSMO directory >&2
exit 1
fi
if [ ! -d $COSMOS ]; then
echo you need to create your $COSMOS directory >&2
exit 1
fi
# auto-install some shell libraries
if [ ! -d $COSMOS/lib ]; then
mkdir $COSMOS/lib
for lib in c dl gcc_s m pthread resolv rt z stdc++; do
printf '\041\074\141\162\143\150\076\012' >$COSMOS/lib/lib$lib.a
done
fi
HAS_C=0
HAS_O=0
HAS_E=0
@ -45,6 +63,16 @@ for x; do
set --
FIRST=0
fi
if [ "$x" = "-Werror" ]; then
# this toolchain is intended for building other people's code
# elevating warnings into errors, should only be done by devs
continue
fi
if [ "$x" = "-pedantic" ]; then
# this toolchain is intended for building other people's code
# we don't need the compiler's assistance to be more portable
continue
fi
if [ "$x" = "-c" ]; then
HAS_C=1
fi
@ -60,7 +88,7 @@ done
if [ "$HAS_E" = "1" ]; then
set -- $CPPFLAGS "$@"
elif [ "$HAS_C" = "1" ]; then
set -- $CCFLAGS $CXXFLAGS $CPPFLAGS "$@"
set -- $CCFLAGS $CXXFLAGS $CPPFLAGS "$@" -fno-omit-frame-pointer
else
set -- $LDFLAGS $CPPFLAGS "$@" $LDLIBS
fi

View file

@ -19,6 +19,9 @@
# make install
#
COSMO=/opt/cosmo
COSMOS=/opt/cosmos
if [ "$1" = "--version" ]; then
cat <<'EOF'
x86_64-unknown-cosmo-gcc (GCC) 9.2.0
@ -30,11 +33,29 @@ exit 0
fi
CC="/opt/cosmo/o/third_party/gcc/bin/x86_64-linux-musl-gcc"
CFLAGS="-g -O2 -fno-omit-frame-pointer -fdata-sections -ffunction-sections -fno-pie -pg -mnop-mcount -mno-tls-direct-seg-refs"
CPPFLAGS="-DNDEBUG -nostdinc -iquote /opt/cosmo -isystem /opt/cosmos/include -isystem /opt/cosmo/libc/isystem -include libc/integral/normalize.inc"
LDFLAGS="-static -no-pie -nostdlib -fuse-ld=bfd -Wl,-melf_x86_64 -Wl,--gc-sections -Wl,-z,max-page-size=0x1000 -L/opt/cosmos/lib -Wl,-T,/opt/cosmo/o/ape/public/ape.lds /opt/cosmo/o/ape/ape-no-modify-self.o /opt/cosmo/o/libc/crt/crt.o"
CFLAGS="-g -O2 -fdata-sections -ffunction-sections -fno-pie -pg -mnop-mcount -mno-tls-direct-seg-refs"
CPPFLAGS="-DNDEBUG -nostdinc -iquote /opt/cosmo -isystem $COSMOS/include -isystem /opt/cosmo/libc/isystem -include libc/integral/normalize.inc"
LDFLAGS="-static -no-pie -nostdlib -fuse-ld=bfd -Wl,-melf_x86_64 -Wl,--gc-sections -Wl,-z,max-page-size=0x1000 -L$COSMOS/lib -Wl,-T,/opt/cosmo/o/ape/public/ape.lds /opt/cosmo/o/ape/ape-no-modify-self.o /opt/cosmo/o/libc/crt/crt.o"
LDLIBS="/opt/cosmo/o/cosmopolitan.a"
if [ ! -d $COSMO ]; then
echo you need to checkout cosmopolitan to your $COSMO directory >&2
exit 1
fi
if [ ! -d $COSMOS ]; then
echo you need to create your $COSMOS directory >&2
exit 1
fi
# auto-install some shell libraries
if [ ! -d $COSMOS/lib ]; then
mkdir $COSMOS/lib
for lib in c dl gcc_s m pthread resolv rt z stdc++; do
printf '\041\074\141\162\143\150\076\012' >$COSMOS/lib/lib$lib.a
done
fi
HAS_C=0
HAS_O=0
HAS_E=0
@ -44,6 +65,16 @@ for x; do
set --
FIRST=0
fi
if [ "$x" = "-Werror" ]; then
# this toolchain is intended for building other people's code
# elevating warnings into errors, should only be done by devs
continue
fi
if [ "$x" = "-pedantic" ]; then
# this toolchain is intended for building other people's code
# we don't need the compiler's assistance to be more portable
continue
fi
if [ "$x" = "-c" ]; then
HAS_C=1
fi
@ -59,7 +90,7 @@ done
if [ "$HAS_E" = "1" ]; then
set -- $CPPFLAGS "$@"
elif [ "$HAS_C" = "1" ]; then
set -- $CFLAGS $CPPFLAGS "$@"
set -- $CFLAGS $CPPFLAGS "$@" -fno-omit-frame-pointer
else
set -- $LDFLAGS $CPPFLAGS "$@" $LDLIBS
fi