github jart/cosmopolitan 3.3
Cosmopolitan v3.3

latest releases: 3.9.4, 3.9.3, 3.9.2...
9 months ago

Cosmopolitan Libc makes C a build-once run-anywhere language, like Java, except it doesn't need an interpreter or virtual machine. Instead, it reconfigures stock GCC and Clang to output a POSIX-approved polyglot format that runs natively on Linux + Mac + Windows + FreeBSD + OpenBSD + NetBSD + BIOS with the best possible performance and the tiniest footprint imaginable. For further details, read Cosmopolitan Third Edition, the Cosmo README, and the Cosmopolitan Toolchain README.

Major Changes

This release upgrades us to GCC 12.3 and binutils 2.42. The GNU linker
appears to have changed things so that only a single de-duplicated str
table is present in the binary, and it gets placed wherever the linker
wants, regardless of what the linker script says. To cope with that we
need to stop using .ident to embed licenses. As such, this change does
significant work to revamp how third party licenses are defined in the
codebase, using .section .notice,"aR",@progbits.

This new GCC 12.3 toolchain has support for GNU indirect functions. It
lets us support __target_clones__ for the first time. It is used for
optimizing the performance of libc string functions such as strlen and
friends so far on x86, by ensuring AVX systems favor a second codepath
that uses VEX encoding. It shaves some latency off certain operations.
It's a useful feature to have for scientific computing for the reasons
explained by the test/libcxx/openmp_test.cc example which compiles for
fifteen different microarchitectures. Thanks to the upgrades, it's now
also possible to use newer instruction sets, such as AVX512FP16, VNNI.

Experimental support has been added for OpenMP, which lets you whip up
multithreaded mathematical code very easily. It works on all supported
platforms for simple examples like openmp_test.cc but you may run into
issues on MacOS ARM64 with more complicated usage.

Cosmo now uses the %gs register on x86 by default for TLS. Doing it is
helpful for any program that links cosmo_dlopen(). Such programs had
to recompile their binaries at startup to change the TLS instructions.
That's not great, since it means every page in the executable needs to
be faulted. The work of rewriting TLS-related x86 opcodes, is moved to
fixupobj.com instead. This is great news for MacOS x86 users, since we
previously needed to morph the binary every time for that platform but
now that's no longer necessary. The only platforms where we need fixup
of TLS x86 opcodes at runtime are now Windows, OpenBSD, and NetBSD. On
Windows we morph TLS to point deeper into the TIB, based on a TlsAlloc
assignment, and on OpenBSD/NetBSD we morph %gs back into %fs since the
kernels do not allow us to specify a value for the %gs register.

OpenBSD users are now required to use APE Loader to run Cosmo binaries
and assimilation is no longer possible. OpenBSD kernel needs to change
to allow programs to specify a value for the %gs register, or it needs
to stop marking executable pages loaded by the kernel as mimmutable().

Other Changes

  • This release fixes __constructor__, .ctor, .init_array, and .preinit_array so they behave the exact same way as glibc.
  • The math.h constants no longer use hex notation.
  • WinMain() will now ensure $HOME and $USER are always defined.
  • Redbean Fetch redirect with relative URLs has been fixed (#1034)
  • The complex.h header now works and support is added for struct ipv6_mreq (#1100)
  • MODE=dbg support is now restored, as of c1e18e7
  • The static yoinks for blink, i.e. __static_yoink("blink_linux_aarch64"), and __static_yoink("blink_xnu_aarch64"), have been removed. Please build blink from source on your platform to use blink to run cosmo binaries.
  • There's a now Curve25519() API added to redbean in d50064a and #1096
  • Calling pthread_create() will no longer raise an assertion error if it fails, as of 8ebe2e9
  • cosmocc now properly handles dependency output in #1091
  • The __cxa_thread_atexit prototype has been fixed in #1088
  • The final remaining libcxx source files have been added in #1089
  • cosmocc is now fixed so that it doesn't run fixupobj on text output in #1084
  • The STL is now more conformant since std::pair can now be trivial fd75fd1
  • Most libc functions are now annotated as dontthrow, to save on size.

Notes

Cosmopolitan no longer distributes cosmo binaries for QuickJS, because
Fabrice Bellard is now doing it himself on his website. You should use
his binaries instead: https://bellard.org/quickjs/

Errata

  • cosmocc --version reports the incorrect gcc version.
  • cosmocc builds are broken on macos arm (fixed in 77ddf4c)
  • Compiling the mono repo on Windows is currently broken due to #1010. In the meantime, use cosmopolitan-3.2.tar.gz

Don't miss a new cosmopolitan release

NewReleases is sending notifications on new releases.