Further improve fatcosmocc

This commit is contained in:
Justine Tunney 2023-08-13 01:44:39 -07:00
parent 3f2f0e3a74
commit ab9a284640
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
39 changed files with 96 additions and 28 deletions

View file

@ -273,6 +273,7 @@ SECTIONS {
*(.gnu.lto_*) *(.gnu.lto_*)
*(.eh_frame) *(.eh_frame)
*(.idata.*) *(.idata.*)
*(.yoink)
*(.head) *(.head)
} }
} }

View file

@ -466,9 +466,10 @@ for x in $ARGS; do
OUTPUT_AARCH64="$mangled_path" OUTPUT_AARCH64="$mangled_path"
build_object $FLAGS -c "$x" build_object $FLAGS -c "$x"
else else
# e.g. `cc -c foo.c` builds foo.o # e.g. `cc -c dir/foo.c` builds foo.o
OUTPUT_X86_64="${x%.*}.o" o=${x##*/}
mangle_object_path "${x%.*}.o" aarch64 OUTPUT_X86_64="${o%.*}.o"
mangle_object_path "${o%.*}.o" aarch64
OUTPUT_AARCH64="$mangled_path" OUTPUT_AARCH64="$mangled_path"
build_object $FLAGS -c "$x" build_object $FLAGS -c "$x"
fi fi

View file

@ -1,5 +1,22 @@
#!/bin/sh #!/bin/sh
# the `install -s` strip flag provided by gnu coreutils surprisngly
# enough understands the portable executable format however it will
# silently corrupt any actually portable executable it touches, due
# to how it overwrites the whole mz header and removes the dos stub
FIRST=1
for x; do
if [ $FIRST -eq 1 ]; then
set --
FIRST=0
fi
if [ x"$x" = x"-s" ]; then
continue
fi
set -- "$@" "$x"
done
# now magically copy multi-architecture build artifacts
if [ $# -gt 1 ]; then if [ $# -gt 1 ]; then
# parse `install [$flags]... $src $dst` # parse `install [$flags]... $src $dst`
@ -11,7 +28,7 @@ if [ $# -gt 1 ]; then
for x; do for x; do
if [ x"$x" != x"${x#* }" ]; then if [ x"$x" != x"${x#* }" ]; then
# give up if any arguments contain spaces # give up if any arguments contain spaces
exec /usr/bin/install "$@" exec install "$@"
fi fi
src=$dst src=$dst
dst=$x dst=$x
@ -48,8 +65,8 @@ if [ $# -gt 1 ]; then
if [ ! -d "$dstdir.$arch" ]; then if [ ! -d "$dstdir.$arch" ]; then
mkdir -p "$dstdir.$arch" || exit mkdir -p "$dstdir.$arch" || exit
fi fi
/usr/bin/install $flags $src $dst || exit install $flags $src $dst || exit
exec /usr/bin/install $flags \ exec install $flags \
"$srcdir.$arch/$srcbas" \ "$srcdir.$arch/$srcbas" \
"$dstdir.$arch/$dstbas" "$dstdir.$arch/$dstbas"
fi fi
@ -73,13 +90,11 @@ if [ $# -gt 1 ]; then
if [ ! -d "$dst/.$arch" ]; then if [ ! -d "$dst/.$arch" ]; then
mkdir -p "$dst/.$arch" || exit mkdir -p "$dst/.$arch" || exit
fi fi
/usr/bin/install $flags $src $dst || exit install $flags $src $dst || exit
exec /usr/bin/install $flags \ exec install $flags "$srcdir.$arch/$srcbas" "$dst/.$arch"
"$srcdir.$arch/$srcbas" \
"$dst/.$arch"
fi fi
fi fi
fi fi
exec /usr/bin/install "$@" exec install "$@"

View file

@ -15,6 +15,7 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
#include "libc/errno.h"
#include "libc/fmt/conv.h" #include "libc/fmt/conv.h"
#include "libc/stdio/stdio.h" #include "libc/stdio/stdio.h"
#include "libc/sysv/consts/exit.h" #include "libc/sysv/consts/exit.h"

View file

@ -7,6 +7,7 @@
http://creativecommons.org/publicdomain/zero/1.0/ │ http://creativecommons.org/publicdomain/zero/1.0/ │
*/ */
#endif #endif
#include "libc/errno.h"
#include "libc/log/log.h" #include "libc/log/log.h"
#include "libc/mem/gc.internal.h" #include "libc/mem/gc.internal.h"
#include "libc/runtime/runtime.h" #include "libc/runtime/runtime.h"

View file

@ -8,6 +8,7 @@
*/ */
#endif #endif
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h"
#include "libc/log/log.h" #include "libc/log/log.h"
#include "libc/mem/gc.h" #include "libc/mem/gc.h"
#include "libc/runtime/runtime.h" #include "libc/runtime/runtime.h"

View file

@ -1,6 +1,17 @@
#ifndef COSMOPOLITAN_LIBC_ASSERT_H_ #ifdef _ASSERT_H
#define COSMOPOLITAN_LIBC_ASSERT_H_ #undef _ASSERT_H
#if !(__ASSEMBLER__ + __LINKER__ + 0) #undef assert
#ifdef COSMO
#undef unassert
#undef npassert
#ifndef NDEBUG
#undef __assert_macro
#endif /* NDEBUG */
#endif /* COSMO */
#endif /* _ASSERT_H */
#ifndef _ASSERT_H
#define _ASSERT_H
COSMOPOLITAN_C_START_ COSMOPOLITAN_C_START_
void __assert_fail(const char *, const char *, int) relegated; void __assert_fail(const char *, const char *, int) relegated;
@ -11,7 +22,8 @@ void __assert_fail(const char *, const char *, int) relegated;
#define assert(x) ((void)((x) || (__assert_fail(#x, __FILE__, __LINE__), 0))) #define assert(x) ((void)((x) || (__assert_fail(#x, __FILE__, __LINE__), 0)))
#endif #endif
#ifndef __cplusplus #if __STDC_VERSION__ >= 201112L && !defined(__cplusplus)
#undef static_assert
#define static_assert _Static_assert #define static_assert _Static_assert
#endif #endif
@ -47,5 +59,4 @@ extern bool __assert_disable;
#endif /* COSMO */ #endif /* COSMO */
COSMOPOLITAN_C_END_ COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* _ASSERT_H */
#endif /* COSMOPOLITAN_LIBC_ASSERT_H_ */

View file

@ -660,6 +660,8 @@ extern const errno_t EXFULL;
extern errno_t __errno; extern errno_t __errno;
errno_t *__errno_location(void) dontthrow pureconst; errno_t *__errno_location(void) dontthrow pureconst;
extern char *program_invocation_short_name;
extern char *program_invocation_name;
COSMOPOLITAN_C_END_ COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

View file

@ -18,6 +18,7 @@
*/ */
#include "libc/intrin/kprintf.h" #include "libc/intrin/kprintf.h"
#include "libc/runtime/internal.h" #include "libc/runtime/internal.h"
#include "libc/errno.h"
#include "libc/runtime/runtime.h" #include "libc/runtime/runtime.h"
__attribute__((__weak__)) void __stack_chk_fail(void) { __attribute__((__weak__)) void __stack_chk_fail(void) {

View file

@ -1,4 +1 @@
#ifndef _ASSERT_H
#define _ASSERT_H
#include "libc/assert.h" #include "libc/assert.h"
#endif /* _ASSERT_H */

View file

@ -19,7 +19,7 @@
#include "libc/intrin/kprintf.h" #include "libc/intrin/kprintf.h"
#include "libc/intrin/safemacros.internal.h" #include "libc/intrin/safemacros.internal.h"
#include "libc/log/internal.h" #include "libc/log/internal.h"
#include "libc/runtime/runtime.h" #include "libc/errno.h"
#include "libc/thread/thread.h" #include "libc/thread/thread.h"
/** /**

View file

@ -33,6 +33,7 @@
#include "libc/sysv/consts/sig.h" #include "libc/sysv/consts/sig.h"
#include "libc/thread/thread.h" #include "libc/thread/thread.h"
#include "libc/thread/tls.h" #include "libc/thread/tls.h"
#include "libc/errno.h"
#include "third_party/lua/lunix.h" #include "third_party/lua/lunix.h"
#ifndef __x86_64__ #ifndef __x86_64__

View file

@ -21,8 +21,6 @@ typedef unsigned long jmp_buf[26];
typedef long sigjmp_buf[12]; typedef long sigjmp_buf[12];
extern char **environ; extern char **environ;
extern char *program_invocation_name;
extern char *program_invocation_short_name;
void mcount(void); void mcount(void);
int daemon(int, int); int daemon(int, int);

View file

@ -19,10 +19,10 @@
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/fmt/fmt.h" #include "libc/fmt/fmt.h"
#include "libc/intrin/safemacros.internal.h" #include "libc/intrin/safemacros.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h" #include "libc/stdio/stdio.h"
#include "libc/str/str.h" #include "libc/str/str.h"
#include "libc/sysv/consts/o.h" #include "libc/sysv/consts/o.h"
#include "libc/errno.h"
#include "libc/x/x.h" #include "libc/x/x.h"
/** /**

View file

@ -22,5 +22,6 @@ COSMOPOLITAN_C_END_
#define AT_SYMLINK_FOLLOW AT_SYMLINK_FOLLOW #define AT_SYMLINK_FOLLOW AT_SYMLINK_FOLLOW
#define AT_SYMLINK_NOFOLLOW AT_SYMLINK_NOFOLLOW #define AT_SYMLINK_NOFOLLOW AT_SYMLINK_NOFOLLOW
#define AT_REMOVEDIR AT_REMOVEDIR #define AT_REMOVEDIR AT_REMOVEDIR
#define AT_EACCESS AT_EACCESS
#endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_AT_H_ */ #endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_AT_H_ */

View file

@ -19,6 +19,7 @@
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/struct/cpuset.h" #include "libc/calls/struct/cpuset.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h"
#include "libc/fmt/conv.h" #include "libc/fmt/conv.h"
#include "libc/intrin/popcnt.h" #include "libc/intrin/popcnt.h"
#include "libc/intrin/safemacros.internal.h" #include "libc/intrin/safemacros.internal.h"

View file

@ -133,4 +133,9 @@ int main(int argc, char *argv[]) {
} }
} }
#else
int main(int argc, char *argv[]) {
}
#endif /* __x86_64__ */ #endif /* __x86_64__ */

View file

@ -20,6 +20,7 @@
#include "libc/calls/struct/stat.h" #include "libc/calls/struct/stat.h"
#include "libc/calls/struct/timespec.h" #include "libc/calls/struct/timespec.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/asan.internal.h" #include "libc/intrin/asan.internal.h"
#include "libc/intrin/bits.h" #include "libc/intrin/bits.h"
#include "libc/intrin/cxaatexit.internal.h" #include "libc/intrin/cxaatexit.internal.h"

View file

@ -34,6 +34,7 @@
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/runtime/runtime.h" #include "libc/runtime/runtime.h"
#include "libc/str/str.h" #include "libc/str/str.h"
#include "libc/errno.h"
#include "third_party/getopt/getopt.internal.h" #include "third_party/getopt/getopt.internal.h"
asm(".ident\t\"\\n\ asm(".ident\t\"\\n\

View file

@ -18,6 +18,7 @@
#include "third_party/make/config.h" #include "third_party/make/config.h"
#include "third_party/make/getprogname.h" #include "third_party/make/getprogname.h"
#include "libc/intrin/safemacros.internal.h" #include "libc/intrin/safemacros.internal.h"
#include "libc/errno.h"
#include "third_party/make/dirname.h" #include "third_party/make/dirname.h"
char const * char const *

View file

@ -17,6 +17,7 @@
#include "third_party/mbedtls/test/lib.h" #include "third_party/mbedtls/test/lib.h"
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h"
#include "libc/fmt/conv.h" #include "libc/fmt/conv.h"
#include "libc/fmt/fmt.h" #include "libc/fmt/fmt.h"
#include "libc/intrin/bits.h" #include "libc/intrin/bits.h"

View file

@ -34,6 +34,7 @@
*/ */
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h" #include "libc/calls/struct/stat.h"
#include "libc/errno.h"
#include "libc/fmt/fmt.h" #include "libc/fmt/fmt.h"
#include "libc/fmt/libgen.h" #include "libc/fmt/libgen.h"
#include "libc/log/bsd.h" #include "libc/log/bsd.h"

View file

@ -36,6 +36,7 @@
#include "libc/sysv/consts/o.h" #include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/prot.h" #include "libc/sysv/consts/prot.h"
#include "third_party/getopt/getopt.internal.h" #include "third_party/getopt/getopt.internal.h"
#include "libc/errno.h"
#include "third_party/regex/regex.h" #include "third_party/regex/regex.h"
#define VERSION \ #define VERSION \

View file

@ -24,6 +24,7 @@
#include "libc/str/str.h" #include "libc/str/str.h"
#include "libc/sysv/consts/ex.h" #include "libc/sysv/consts/ex.h"
#include "libc/sysv/consts/exit.h" #include "libc/sysv/consts/exit.h"
#include "libc/errno.h"
#include "third_party/getopt/getopt.internal.h" #include "third_party/getopt/getopt.internal.h"
#define USAGE \ #define USAGE \

View file

@ -22,6 +22,7 @@
#include "libc/stdio/rand.h" #include "libc/stdio/rand.h"
#include "libc/stdio/stdio.h" #include "libc/stdio/stdio.h"
#include "libc/str/str.h" #include "libc/str/str.h"
#include "libc/errno.h"
#include "libc/sysv/consts/o.h" #include "libc/sysv/consts/o.h"
/** /**

View file

@ -40,6 +40,7 @@
#include "libc/zip.internal.h" #include "libc/zip.internal.h"
#include "third_party/getopt/getopt.internal.h" #include "third_party/getopt/getopt.internal.h"
#include "tool/build/lib/elfwriter.h" #include "tool/build/lib/elfwriter.h"
#include "libc/errno.h"
#include "tool/build/lib/stripcomponents.h" #include "tool/build/lib/stripcomponents.h"
char *name_; char *name_;

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/errno.h"
#include "libc/fmt/conv.h" #include "libc/fmt/conv.h"
#include "libc/intrin/safemacros.internal.h" #include "libc/intrin/safemacros.internal.h"
#include "libc/log/check.h" #include "libc/log/check.h"

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/errno.h"
#include "libc/fmt/fmt.h" #include "libc/fmt/fmt.h"
#include "libc/intrin/safemacros.internal.h" #include "libc/intrin/safemacros.internal.h"
#include "libc/log/check.h" #include "libc/log/check.h"

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/errno.h"
#include "libc/intrin/bits.h" #include "libc/intrin/bits.h"
#include "libc/macros.internal.h" #include "libc/macros.internal.h"
#include "libc/runtime/runtime.h" #include "libc/runtime/runtime.h"

View file

@ -42,7 +42,8 @@ for x; do
set -- "$@" "$x" set -- "$@" "$x"
done done
if [ x"$OPT" != x"-Os" ] && [ x"${MODE#aarch64-tiny}" != x"${MODE}" ]; then 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 # support --ftrace unless optimizing for size
CCFLAGS="$CCFLAGS -fpatchable-function-entry=7,6" CCFLAGS="$CCFLAGS -fpatchable-function-entry=7,6"
fi fi

View file

@ -4,7 +4,7 @@
CC="$COSMO/o/third_party/gcc/bin/x86_64-linux-musl-gcc" CC="$COSMO/o/third_party/gcc/bin/x86_64-linux-musl-gcc"
CFLAGS="-mno-tls-direct-seg-refs -mno-red-zone" 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" 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" APEFLAGS="-L$COSMOS/lib -Wl,--gc-sections -Wl,-T,$COSMO/o/$MODE/ape/public/ape.lds"
LDLIBS="$COSMO/o/$MODE/cosmopolitan.a" LDLIBS="$COSMO/o/$MODE/cosmopolitan.a"
if [ x"$PROG" != x"${PROG%++}" ]; then if [ x"$PROG" != x"${PROG%++}" ]; then
@ -44,7 +44,8 @@ if [ x"$MODE" = x"nox87" ]; then
CFLAGS="$CFLAGS -mlong-double-64" CFLAGS="$CFLAGS -mlong-double-64"
fi fi
if [ x"$OPT" != x"-Os" ] && [ x"${MODE#tiny}" != x"${MODE}" ]; then 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 # support --ftrace unless optimizing for size
CFLAGS="$CFLAGS -fpatchable-function-entry=18,16" CFLAGS="$CFLAGS -fpatchable-function-entry=18,16"
fi fi
@ -57,6 +58,7 @@ if [ $INTENT = cc ]; then
else else
set -- \ set -- \
"$CC" \ "$CC" \
"$COSMO/o/$MODE/ape/ape.o" \
"$COSMO/o/$MODE/libc/crt/crt.o" \ "$COSMO/o/$MODE/libc/crt/crt.o" \
"$@" \ "$@" \
$LDFLAGS \ $LDFLAGS \

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/errno.h"
#include "libc/log/log.h" #include "libc/log/log.h"
#include "libc/runtime/runtime.h" #include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h" #include "libc/stdio/stdio.h"

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/errno.h"
#include "libc/fmt/fmt.h" #include "libc/fmt/fmt.h"
#include "libc/log/check.h" #include "libc/log/check.h"
#include "libc/mem/mem.h" #include "libc/mem/mem.h"

View file

@ -335,4 +335,9 @@ int main(int argc, char *argv[]) {
return 0; return 0;
} }
#else
int main(int argc, char *argv[]) {
}
#endif /* __x86_64__ */ #endif /* __x86_64__ */

View file

@ -616,4 +616,9 @@ int main(int argc, char *argv[]) {
return 0; return 0;
} }
#else
int main(int argc, char *argv[]) {
}
#endif /* __x86_64__ */ #endif /* __x86_64__ */

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/errno.h"
#include "libc/fmt/conv.h" #include "libc/fmt/conv.h"
#include "libc/fmt/fmt.h" #include "libc/fmt/fmt.h"
#include "libc/log/check.h" #include "libc/log/check.h"

View file

@ -27,6 +27,7 @@
#include "libc/calls/struct/winsize.h" #include "libc/calls/struct/winsize.h"
#include "libc/calls/termios.h" #include "libc/calls/termios.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h"
#include "libc/fmt/conv.h" #include "libc/fmt/conv.h"
#include "libc/intrin/bits.h" #include "libc/intrin/bits.h"
#include "libc/intrin/safemacros.internal.h" #include "libc/intrin/safemacros.internal.h"

View file

@ -26,6 +26,7 @@
#include "libc/calls/struct/winsize.h" #include "libc/calls/struct/winsize.h"
#include "libc/calls/termios.h" #include "libc/calls/termios.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h"
#include "libc/fmt/conv.h" #include "libc/fmt/conv.h"
#include "libc/log/check.h" #include "libc/log/check.h"
#include "libc/log/log.h" #include "libc/log/log.h"

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h"
#include "libc/fmt/conv.h" #include "libc/fmt/conv.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/macros.internal.h" #include "libc/macros.internal.h"