Skip to content

Commit

Permalink
Release Cosmopolitan v3.8.0
Browse files Browse the repository at this point in the history
This change switches c++ exception handling from sjlj to standard dwarf.
It's needed because clang for aarch64 doesn't support sjlj. It turns out
that libunwind had a bare-metal configuration that made this easy to do.

This change gets the new experimental cosmocc -mclang flag in a state of
working so well that it can now be used to build all of llamafile and it
goes 3x faster in terms of build latency, without trading away any perf.

The int_fast16_t and int_fast32_t types are now always defined as 32-bit
in the interest of having more abi consistency between cosmocc -mgcc and
-mclang mode.
  • Loading branch information
jart committed Aug 31, 2024
1 parent 5b98629 commit c9152b6
Show file tree
Hide file tree
Showing 188 changed files with 199,063 additions and 636 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"C_Cpp.default.compilerPath": ".cosmocc/3.7.1/bin/aarch64-linux-cosmo-c++",
"C_Cpp.default.compilerPath": ".cosmocc/3.8.0/bin/aarch64-linux-cosmo-c++",
"C_Cpp.default.compilerArgs": [
"-nostdinc",
"-nostdlib",
Expand Down Expand Up @@ -33,4 +33,4 @@
"files.associations": {
"log.h": "c"
}
}
}
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ export MODE
export SOURCE_DATE_EPOCH
export TMPDIR

COSMOCC = .cosmocc/3.7.1
COSMOCC = .cosmocc/3.8.0
BOOTSTRAP = $(COSMOCC)/bin
TOOLCHAIN = $(COSMOCC)/bin/$(ARCH)-linux-cosmo-
DOWNLOAD := $(shell build/download-cosmocc.sh $(COSMOCC) 3.7.1 13b65b0e659b493bd82f3d0a319d0265d66f849839e484aa2a54191024711e85)
DOWNLOAD := $(shell build/download-cosmocc.sh $(COSMOCC) 3.8.0 813c6b2f95062d2e0a845307a79505424cb98cb038e8013334f8a22e3b92a474)

IGNORE := $(shell $(MKDIR) $(TMPDIR))

Expand Down
10 changes: 5 additions & 5 deletions ape/aarch64.lds
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,8 @@ SECTIONS {
*(.eh_frame_entry .eh_frame_entry.*)
}

.eh_frame : ONLY_IF_RO {
KEEP(*(.eh_frame))
*(.eh_frame.*)
}
__eh_frame_hdr_start = SIZEOF(.eh_frame_hdr) > 0 ? ADDR(.eh_frame_hdr) : 0;
__eh_frame_hdr_end = SIZEOF(.eh_frame_hdr) > 0 ? . : 0;

.gcc_except_table : ONLY_IF_RO {
*(.gcc_except_table .gcc_except_table.*)
Expand All @@ -127,9 +125,11 @@ SECTIONS {
. += CONSTANT(MAXPAGESIZE);
. = DATA_SEGMENT_ALIGN(CONSTANT(MAXPAGESIZE), CONSTANT(COMMONPAGESIZE));

.eh_frame : ONLY_IF_RW {
.eh_frame : {
__eh_frame_start = .;
KEEP(*(.eh_frame))
*(.eh_frame.*)
__eh_frame_end = .;
}

.gnu_extab : ONLY_IF_RW {
Expand Down
12 changes: 12 additions & 0 deletions ape/ape.lds
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ SECTIONS {
*(.ubsan.types)
*(.ubsan.data)

__eh_frame_hdr_start_actual = .;
*(.eh_frame_hdr)
__eh_frame_hdr_end_actual = .;

/* Legal Notices */
__notices = .;
KEEP(*(.notice))
Expand Down Expand Up @@ -422,6 +426,11 @@ SECTIONS {
KEEP(*(.dtors))
__fini_array_end = .;

__eh_frame_start = .;
KEEP(*(.eh_frame))
*(.eh_frame.*)
__eh_frame_end = .;

/*BEGIN: Post-Initialization Read-Only */
. = ALIGN(. != 0 ? __SIZEOF_POINTER__ : 0);
KEEP(*(SORT_BY_NAME(.piro.relo.sort.*)))
Expand Down Expand Up @@ -601,6 +610,9 @@ ape_text_memsz = ape_text_filesz;
ape_text_align = CONSTANT(COMMONPAGESIZE);
ape_text_rva = RVA(ape_text_vaddr);

__eh_frame_hdr_start = __eh_frame_hdr_end_actual > __eh_frame_hdr_start_actual ? __eh_frame_hdr_start_actual : 0;
__eh_frame_hdr_end = __eh_frame_hdr_end_actual > __eh_frame_hdr_start_actual ? __eh_frame_hdr_end_actual : 0;

/* we roundup here because xnu wants the file load segments page-aligned */
/* but we don't want to add the nop padding to the ape program, so we'll */
/* let ape.S dd read past the end of the file into the wrapping binaries */
Expand Down
7 changes: 1 addition & 6 deletions build/definitions.mk
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,7 @@ DEFAULT_COPTS ?= \
-fno-gnu-unique \
-fstrict-aliasing \
-fstrict-overflow \
-fno-semantic-interposition \
-fno-dwarf2-cfi-asm \
-fno-unwind-tables \
-fno-asynchronous-unwind-tables
-fno-semantic-interposition

ifeq ($(ARCH), x86_64)
# Microsoft says "[a]ny memory below the stack beyond the red zone
Expand Down Expand Up @@ -139,8 +136,6 @@ DEFAULT_CFLAGS = \

DEFAULT_CXXFLAGS = \
-std=gnu++23 \
-fno-rtti \
-fno-exceptions \
-fuse-cxa-atexit \
-Wno-int-in-bool-context \
-Wno-narrowing \
Expand Down
16 changes: 8 additions & 8 deletions build/objdump
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ if [ -n "$OBJDUMP" ]; then
fi

find_objdump() {
if [ -x .cosmocc/3.6.0/bin/$1-linux-cosmo-objdump ]; then
OBJDUMP=.cosmocc/3.6.0/bin/$1-linux-cosmo-objdump
elif [ -x .cosmocc/3.6.0/bin/$1-linux-musl-objdump ]; then
OBJDUMP=.cosmocc/3.6.0/bin/$1-linux-musl-objdump
elif [ -x "$COSMO/.cosmocc/3.6.0/bin/$1-linux-cosmo-objdump" ]; then
OBJDUMP="$COSMO/.cosmocc/3.6.0/bin/$1-linux-cosmo-objdump"
elif [ -x "$COSMO/.cosmocc/3.6.0/bin/$1-linux-musl-objdump" ]; then
OBJDUMP="$COSMO/.cosmocc/3.6.0/bin/$1-linux-musl-objdump"
if [ -x .cosmocc/3.8.0/bin/$1-linux-cosmo-objdump ]; then
OBJDUMP=.cosmocc/3.8.0/bin/$1-linux-cosmo-objdump
elif [ -x .cosmocc/3.8.0/bin/$1-linux-musl-objdump ]; then
OBJDUMP=.cosmocc/3.8.0/bin/$1-linux-musl-objdump
elif [ -x "$COSMO/.cosmocc/3.8.0/bin/$1-linux-cosmo-objdump" ]; then
OBJDUMP="$COSMO/.cosmocc/3.8.0/bin/$1-linux-cosmo-objdump"
elif [ -x "$COSMO/.cosmocc/3.8.0/bin/$1-linux-musl-objdump" ]; then
OBJDUMP="$COSMO/.cosmocc/3.8.0/bin/$1-linux-musl-objdump"
else
echo "error: toolchain not found (try running 'cosmocc --update' or 'make' in the cosmo monorepo)" >&2
exit 1
Expand Down
15 changes: 8 additions & 7 deletions ctl/set.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,9 @@ class set
private:
friend class set;
node_type* node_;
node_type* root_;

explicit reverse_iterator(node_type* node) : node_(node)
explicit reverse_iterator(node_type* node, node_type* root) : node_(node), root_(root)
{
}
};
Expand Down Expand Up @@ -347,17 +348,17 @@ class set

reverse_iterator rbegin()
{
return reverse_iterator(rightmost(root_));
return reverse_iterator(rightmost(root_), root_);
}

const_reverse_iterator rbegin() const
{
return const_reverse_iterator(rightmost(root_));
return const_reverse_iterator(rightmost(root_), root_);
}

const_reverse_iterator crbegin() const
{
return const_reverse_iterator(rightmost(root_));
return const_reverse_iterator(rightmost(root_), root_);
}

iterator end() noexcept
Expand All @@ -377,17 +378,17 @@ class set

reverse_iterator rend()
{
return reverse_iterator(nullptr);
return reverse_iterator(nullptr, root_);
}

const_reverse_iterator rend() const
{
return const_reverse_iterator(nullptr);
return const_reverse_iterator(nullptr, root_);
}

const_reverse_iterator crend() const
{
return const_reverse_iterator(nullptr);
return const_reverse_iterator(nullptr, root_);
}

void clear() noexcept
Expand Down
1 change: 1 addition & 0 deletions examples/BUILD.mk
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ EXAMPLES_DIRECTDEPS = \
THIRD_PARTY_VQSORT \
THIRD_PARTY_XED \
THIRD_PARTY_LIBCXXABI \
THIRD_PARTY_LIBUNWIND \
THIRD_PARTY_ZLIB \
TOOL_ARGS \
TOOL_BUILD_LIB \
Expand Down
28 changes: 26 additions & 2 deletions libc/integral/normalize.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#endif

#define __COSMOPOLITAN_MAJOR__ 3
#define __COSMOPOLITAN_MINOR__ 7
#define __COSMOPOLITAN_PATCH__ 1
#define __COSMOPOLITAN_MINOR__ 8
#define __COSMOPOLITAN_PATCH__ 0
#define __COSMOPOLITAN__ \
(100000000 * __COSMOPOLITAN_MAJOR__ + 1000000 * __COSMOPOLITAN_MINOR__ + \
__COSMOPOLITAN_PATCH__)
Expand Down Expand Up @@ -93,6 +93,30 @@
#include "libc/integral/llp64.inc"
#endif

#undef __INT_FAST16_MAX__
#undef __INT_FAST16_TYPE__
#undef __UINT_FAST16_MAX__
#undef __INT_FAST16_WIDTH__
#undef __UINT_FAST16_TYPE__

#define __INT_FAST16_MAX__ 2147483647
#define __INT_FAST16_TYPE__ int
#define __UINT_FAST16_MAX__ 4294967295U
#define __INT_FAST16_WIDTH__ 32
#define __UINT_FAST16_TYPE__ unsigned int

#undef __INT_FAST32_MAX__
#undef __INT_FAST32_TYPE__
#undef __UINT_FAST32_MAX__
#undef __INT_FAST32_WIDTH__
#undef __UINT_FAST32_TYPE__

#define __INT_FAST32_MAX__ 2147483647
#define __INT_FAST32_TYPE__ int
#define __UINT_FAST32_MAX__ 4294967295U
#define __INT_FAST32_WIDTH__ 32
#define __UINT_FAST32_TYPE__ unsigned int

#if !(__ASSEMBLER__ + __LINKER__ + 0)
#ifdef __STDC__
#include "libc/integral/c.inc"
Expand Down
22 changes: 22 additions & 0 deletions libc/intrin/personality.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2024 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. │
╚─────────────────────────────────────────────────────────────────────────────*/

__attribute__((__weak__)) void __gxx_personality_v0() {
__builtin_trap();
}
4 changes: 4 additions & 0 deletions libc/isystem/ammintrin.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_AMMINTRIN_INTERNAL_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_AMMINTRIN_INTERNAL_H_
#ifdef __clang__
#include "third_party/intel/clang/ammintrin.h"
#else
#include "third_party/intel/ammintrin.internal.h"
#endif
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_AMMINTRIN_INTERNAL_H_ */
4 changes: 4 additions & 0 deletions libc/isystem/amxcomplexintrin.h
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
#ifdef __clang__
#include "third_party/intel/clang/amxcomplexintrin.h"
#else
#include "third_party/intel/amxcomplexintrin.internal.h"
#endif
4 changes: 4 additions & 0 deletions libc/isystem/amxfp16intrin.h
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
#ifdef __clang__
#include "third_party/intel/clang/amxfp16intrin.h"
#else
#include "third_party/intel/amxfp16intrin.internal.h"
#endif
4 changes: 4 additions & 0 deletions libc/isystem/arm_acle.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_ARM_ACLE_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_ARM_ACLE_H_
#ifdef __clang__
#include "third_party/aarch64/clang/arm_acle.h"
#else
#include "third_party/aarch64/arm_acle.internal.h"
#endif
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_ARM_ACLE_H_ */
4 changes: 4 additions & 0 deletions libc/isystem/arm_bf16.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_ARM_BF16_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_ARM_BF16_H_
#ifdef __clang__
#include "third_party/aarch64/clang/arm_bf16.h"
#else
#include "third_party/aarch64/arm_bf16.internal.h"
#endif
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_ARM_BF16_H_ */
4 changes: 4 additions & 0 deletions libc/isystem/arm_fp16.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_ARM_FP16_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_ARM_FP16_H_
#ifdef __clang__
#include "third_party/aarch64/clang/arm_fp16.h"
#else
#include "third_party/aarch64/arm_fp16.internal.h"
#endif
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_ARM_FP16_H_ */
4 changes: 4 additions & 0 deletions libc/isystem/arm_neon.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_ARM_NEON_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_ARM_NEON_H_
#ifdef __clang__
#include "third_party/aarch64/clang/arm_neon.h"
#else
#include "third_party/aarch64/arm_neon.internal.h"
#endif
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_ARM_NEON_H_ */
8 changes: 8 additions & 0 deletions libc/isystem/arm_sve.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_ARM_SVE_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_ARM_SVE_H_
#ifdef __clang__
#include "third_party/aarch64/clang/arm_sve.h"
#else
#include "third_party/aarch64/arm_sve.internal.h"
#endif
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_ARM_SVE_H_ */
8 changes: 8 additions & 0 deletions libc/isystem/arm_vector_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_ARM_VECTOR_TYPES_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_ARM_VECTOR_TYPES_H_
#ifdef __clang__
#include "third_party/aarch64/clang/arm_vector_types.h"
#else
#include "third_party/aarch64/arm_vector_types.internal.h"
#endif
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_ARM_VECTOR_TYPES_H_ */
4 changes: 4 additions & 0 deletions libc/isystem/avxifmaintrin.h
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
#ifdef __clang__
#include "third_party/intel/clang/avxifmaintrin.h"
#else
#include "third_party/intel/avxifmaintrin.internal.h"
#endif
4 changes: 4 additions & 0 deletions libc/isystem/avxneconvertintrin.h
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
#ifdef __clang__
#include "third_party/intel/clang/avxneconvertintrin.h"
#else
#include "third_party/intel/avxneconvertintrin.internal.h"
#endif
4 changes: 4 additions & 0 deletions libc/isystem/avxvnniint16intrin.h
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
#ifdef __clang__
#include "third_party/intel/clang/avxvnniint16intrin.h"
#else
#include "third_party/intel/avxvnniint16intrin.internal.h"
#endif
4 changes: 4 additions & 0 deletions libc/isystem/avxvnniint8intrin.h
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
#ifdef __clang__
#include "third_party/intel/clang/avxvnniint8intrin.h"
#else
#include "third_party/intel/avxvnniint8intrin.internal.h"
#endif
4 changes: 4 additions & 0 deletions libc/isystem/clzerointrin.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_CLZEROINTRIN_INTERNAL_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_CLZEROINTRIN_INTERNAL_H_
#ifdef __clang__
#include "third_party/intel/clang/clzerointrin.h"
#else
#include "third_party/intel/clzerointrin.internal.h"
#endif
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_CLZEROINTRIN_INTERNAL_H_ */
4 changes: 4 additions & 0 deletions libc/isystem/cmpccxaddintrin.h
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
#ifdef __clang__
#include "third_party/intel/clang/cmpccxaddintrin.h"
#else
#include "third_party/intel/cmpccxaddintrin.internal.h"
#endif
4 changes: 4 additions & 0 deletions libc/isystem/emmintrin.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_EMMINTRIN_INTERNAL_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_EMMINTRIN_INTERNAL_H_
#ifdef __clang__
#include "third_party/intel/clang/emmintrin.h"
#else
#include "third_party/intel/emmintrin.internal.h"
#endif
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_EMMINTRIN_INTERNAL_H_ */
4 changes: 4 additions & 0 deletions libc/isystem/immintrin.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_IMMINTRIN_INTERNAL_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_IMMINTRIN_INTERNAL_H_
#ifdef __clang__
#include "third_party/intel/clang/immintrin.h"
#else
#include "third_party/intel/immintrin.internal.h"
#endif
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_IMMINTRIN_INTERNAL_H_ */
4 changes: 4 additions & 0 deletions libc/isystem/mm_malloc.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_MM_MALLOC_INTERNAL_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_MM_MALLOC_INTERNAL_H_
#ifdef __clang__
#include "third_party/intel/clang/mm_malloc.h"
#else
#include "third_party/intel/mm_malloc.internal.h"
#endif
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_MM_MALLOC_INTERNAL_H_ */
Loading

0 comments on commit c9152b6

Please sign in to comment.