Skip to content

Commit c9152b6

Browse files
committed
Release Cosmopolitan v3.8.0
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.
1 parent 5b98629 commit c9152b6

File tree

188 files changed

+199063
-636
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

188 files changed

+199063
-636
lines changed

.vscode/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"C_Cpp.default.compilerPath": ".cosmocc/3.7.1/bin/aarch64-linux-cosmo-c++",
2+
"C_Cpp.default.compilerPath": ".cosmocc/3.8.0/bin/aarch64-linux-cosmo-c++",
33
"C_Cpp.default.compilerArgs": [
44
"-nostdinc",
55
"-nostdlib",
@@ -33,4 +33,4 @@
3333
"files.associations": {
3434
"log.h": "c"
3535
}
36-
}
36+
}

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ export MODE
147147
export SOURCE_DATE_EPOCH
148148
export TMPDIR
149149

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

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

ape/aarch64.lds

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,8 @@ SECTIONS {
103103
*(.eh_frame_entry .eh_frame_entry.*)
104104
}
105105

106-
.eh_frame : ONLY_IF_RO {
107-
KEEP(*(.eh_frame))
108-
*(.eh_frame.*)
109-
}
106+
__eh_frame_hdr_start = SIZEOF(.eh_frame_hdr) > 0 ? ADDR(.eh_frame_hdr) : 0;
107+
__eh_frame_hdr_end = SIZEOF(.eh_frame_hdr) > 0 ? . : 0;
110108

111109
.gcc_except_table : ONLY_IF_RO {
112110
*(.gcc_except_table .gcc_except_table.*)
@@ -127,9 +125,11 @@ SECTIONS {
127125
. += CONSTANT(MAXPAGESIZE);
128126
. = DATA_SEGMENT_ALIGN(CONSTANT(MAXPAGESIZE), CONSTANT(COMMONPAGESIZE));
129127

130-
.eh_frame : ONLY_IF_RW {
128+
.eh_frame : {
129+
__eh_frame_start = .;
131130
KEEP(*(.eh_frame))
132131
*(.eh_frame.*)
132+
__eh_frame_end = .;
133133
}
134134

135135
.gnu_extab : ONLY_IF_RW {

ape/ape.lds

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,10 @@ SECTIONS {
329329
*(.ubsan.types)
330330
*(.ubsan.data)
331331

332+
__eh_frame_hdr_start_actual = .;
333+
*(.eh_frame_hdr)
334+
__eh_frame_hdr_end_actual = .;
335+
332336
/* Legal Notices */
333337
__notices = .;
334338
KEEP(*(.notice))
@@ -422,6 +426,11 @@ SECTIONS {
422426
KEEP(*(.dtors))
423427
__fini_array_end = .;
424428

429+
__eh_frame_start = .;
430+
KEEP(*(.eh_frame))
431+
*(.eh_frame.*)
432+
__eh_frame_end = .;
433+
425434
/*BEGIN: Post-Initialization Read-Only */
426435
. = ALIGN(. != 0 ? __SIZEOF_POINTER__ : 0);
427436
KEEP(*(SORT_BY_NAME(.piro.relo.sort.*)))
@@ -601,6 +610,9 @@ ape_text_memsz = ape_text_filesz;
601610
ape_text_align = CONSTANT(COMMONPAGESIZE);
602611
ape_text_rva = RVA(ape_text_vaddr);
603612

613+
__eh_frame_hdr_start = __eh_frame_hdr_end_actual > __eh_frame_hdr_start_actual ? __eh_frame_hdr_start_actual : 0;
614+
__eh_frame_hdr_end = __eh_frame_hdr_end_actual > __eh_frame_hdr_start_actual ? __eh_frame_hdr_end_actual : 0;
615+
604616
/* we roundup here because xnu wants the file load segments page-aligned */
605617
/* but we don't want to add the nop padding to the ape program, so we'll */
606618
/* let ape.S dd read past the end of the file into the wrapping binaries */

build/definitions.mk

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,7 @@ DEFAULT_COPTS ?= \
9292
-fno-gnu-unique \
9393
-fstrict-aliasing \
9494
-fstrict-overflow \
95-
-fno-semantic-interposition \
96-
-fno-dwarf2-cfi-asm \
97-
-fno-unwind-tables \
98-
-fno-asynchronous-unwind-tables
95+
-fno-semantic-interposition
9996

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

140137
DEFAULT_CXXFLAGS = \
141138
-std=gnu++23 \
142-
-fno-rtti \
143-
-fno-exceptions \
144139
-fuse-cxa-atexit \
145140
-Wno-int-in-bool-context \
146141
-Wno-narrowing \

build/objdump

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ if [ -n "$OBJDUMP" ]; then
66
fi
77

88
find_objdump() {
9-
if [ -x .cosmocc/3.6.0/bin/$1-linux-cosmo-objdump ]; then
10-
OBJDUMP=.cosmocc/3.6.0/bin/$1-linux-cosmo-objdump
11-
elif [ -x .cosmocc/3.6.0/bin/$1-linux-musl-objdump ]; then
12-
OBJDUMP=.cosmocc/3.6.0/bin/$1-linux-musl-objdump
13-
elif [ -x "$COSMO/.cosmocc/3.6.0/bin/$1-linux-cosmo-objdump" ]; then
14-
OBJDUMP="$COSMO/.cosmocc/3.6.0/bin/$1-linux-cosmo-objdump"
15-
elif [ -x "$COSMO/.cosmocc/3.6.0/bin/$1-linux-musl-objdump" ]; then
16-
OBJDUMP="$COSMO/.cosmocc/3.6.0/bin/$1-linux-musl-objdump"
9+
if [ -x .cosmocc/3.8.0/bin/$1-linux-cosmo-objdump ]; then
10+
OBJDUMP=.cosmocc/3.8.0/bin/$1-linux-cosmo-objdump
11+
elif [ -x .cosmocc/3.8.0/bin/$1-linux-musl-objdump ]; then
12+
OBJDUMP=.cosmocc/3.8.0/bin/$1-linux-musl-objdump
13+
elif [ -x "$COSMO/.cosmocc/3.8.0/bin/$1-linux-cosmo-objdump" ]; then
14+
OBJDUMP="$COSMO/.cosmocc/3.8.0/bin/$1-linux-cosmo-objdump"
15+
elif [ -x "$COSMO/.cosmocc/3.8.0/bin/$1-linux-musl-objdump" ]; then
16+
OBJDUMP="$COSMO/.cosmocc/3.8.0/bin/$1-linux-musl-objdump"
1717
else
1818
echo "error: toolchain not found (try running 'cosmocc --update' or 'make' in the cosmo monorepo)" >&2
1919
exit 1

ctl/set.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,9 @@ class set
241241
private:
242242
friend class set;
243243
node_type* node_;
244+
node_type* root_;
244245

245-
explicit reverse_iterator(node_type* node) : node_(node)
246+
explicit reverse_iterator(node_type* node, node_type* root) : node_(node), root_(root)
246247
{
247248
}
248249
};
@@ -347,17 +348,17 @@ class set
347348

348349
reverse_iterator rbegin()
349350
{
350-
return reverse_iterator(rightmost(root_));
351+
return reverse_iterator(rightmost(root_), root_);
351352
}
352353

353354
const_reverse_iterator rbegin() const
354355
{
355-
return const_reverse_iterator(rightmost(root_));
356+
return const_reverse_iterator(rightmost(root_), root_);
356357
}
357358

358359
const_reverse_iterator crbegin() const
359360
{
360-
return const_reverse_iterator(rightmost(root_));
361+
return const_reverse_iterator(rightmost(root_), root_);
361362
}
362363

363364
iterator end() noexcept
@@ -377,17 +378,17 @@ class set
377378

378379
reverse_iterator rend()
379380
{
380-
return reverse_iterator(nullptr);
381+
return reverse_iterator(nullptr, root_);
381382
}
382383

383384
const_reverse_iterator rend() const
384385
{
385-
return const_reverse_iterator(nullptr);
386+
return const_reverse_iterator(nullptr, root_);
386387
}
387388

388389
const_reverse_iterator crend() const
389390
{
390-
return const_reverse_iterator(nullptr);
391+
return const_reverse_iterator(nullptr, root_);
391392
}
392393

393394
void clear() noexcept

examples/BUILD.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ EXAMPLES_DIRECTDEPS = \
9494
THIRD_PARTY_VQSORT \
9595
THIRD_PARTY_XED \
9696
THIRD_PARTY_LIBCXXABI \
97+
THIRD_PARTY_LIBUNWIND \
9798
THIRD_PARTY_ZLIB \
9899
TOOL_ARGS \
99100
TOOL_BUILD_LIB \

libc/integral/normalize.inc

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#endif
44

55
#define __COSMOPOLITAN_MAJOR__ 3
6-
#define __COSMOPOLITAN_MINOR__ 7
7-
#define __COSMOPOLITAN_PATCH__ 1
6+
#define __COSMOPOLITAN_MINOR__ 8
7+
#define __COSMOPOLITAN_PATCH__ 0
88
#define __COSMOPOLITAN__ \
99
(100000000 * __COSMOPOLITAN_MAJOR__ + 1000000 * __COSMOPOLITAN_MINOR__ + \
1010
__COSMOPOLITAN_PATCH__)
@@ -93,6 +93,30 @@
9393
#include "libc/integral/llp64.inc"
9494
#endif
9595

96+
#undef __INT_FAST16_MAX__
97+
#undef __INT_FAST16_TYPE__
98+
#undef __UINT_FAST16_MAX__
99+
#undef __INT_FAST16_WIDTH__
100+
#undef __UINT_FAST16_TYPE__
101+
102+
#define __INT_FAST16_MAX__ 2147483647
103+
#define __INT_FAST16_TYPE__ int
104+
#define __UINT_FAST16_MAX__ 4294967295U
105+
#define __INT_FAST16_WIDTH__ 32
106+
#define __UINT_FAST16_TYPE__ unsigned int
107+
108+
#undef __INT_FAST32_MAX__
109+
#undef __INT_FAST32_TYPE__
110+
#undef __UINT_FAST32_MAX__
111+
#undef __INT_FAST32_WIDTH__
112+
#undef __UINT_FAST32_TYPE__
113+
114+
#define __INT_FAST32_MAX__ 2147483647
115+
#define __INT_FAST32_TYPE__ int
116+
#define __UINT_FAST32_MAX__ 4294967295U
117+
#define __INT_FAST32_WIDTH__ 32
118+
#define __UINT_FAST32_TYPE__ unsigned int
119+
96120
#if !(__ASSEMBLER__ + __LINKER__ + 0)
97121
#ifdef __STDC__
98122
#include "libc/integral/c.inc"

libc/intrin/personality.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
2+
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
3+
╞══════════════════════════════════════════════════════════════════════════════╡
4+
│ Copyright 2024 Justine Alexandra Roberts Tunney │
5+
│ │
6+
│ Permission to use, copy, modify, and/or distribute this software for │
7+
│ any purpose with or without fee is hereby granted, provided that the │
8+
│ above copyright notice and this permission notice appear in all copies. │
9+
│ │
10+
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
11+
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
12+
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
13+
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
14+
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
15+
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
16+
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
17+
│ PERFORMANCE OF THIS SOFTWARE. │
18+
╚─────────────────────────────────────────────────────────────────────────────*/
19+
20+
__attribute__((__weak__)) void __gxx_personality_v0() {
21+
__builtin_trap();
22+
}

0 commit comments

Comments
 (0)