From b850b14300f112c238debf441746ef9ff93e8dba Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Mon, 14 Nov 2022 13:45:57 -0800 Subject: [PATCH] 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. --- tool/emacs/cosmo-c-types.el | 11 +++++++++++ tool/emacs/cosmo-stuff.el | 4 ++-- tool/scripts/cosmoc++ | 32 ++++++++++++++++++++++++++++-- tool/scripts/cosmocc | 39 +++++++++++++++++++++++++++++++++---- 4 files changed, 78 insertions(+), 8 deletions(-) diff --git a/tool/emacs/cosmo-c-types.el b/tool/emacs/cosmo-c-types.el index 4ab5365ab..096161cd2 100644 --- a/tool/emacs/cosmo-c-types.el +++ b/tool/emacs/cosmo-c-types.el @@ -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)) "\\_>"))) diff --git a/tool/emacs/cosmo-stuff.el b/tool/emacs/cosmo-stuff.el index f5ea874a4..f48f11cb9 100644 --- a/tool/emacs/cosmo-stuff.el +++ b/tool/emacs/cosmo-stuff.el @@ -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"))) diff --git a/tool/scripts/cosmoc++ b/tool/scripts/cosmoc++ index 3cf4c0519..66e08eed4 100755 --- a/tool/scripts/cosmoc++ +++ b/tool/scripts/cosmoc++ @@ -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 diff --git a/tool/scripts/cosmocc b/tool/scripts/cosmocc index eb8857b2e..73b5b0ae1 100755 --- a/tool/scripts/cosmocc +++ b/tool/scripts/cosmocc @@ -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