build-once run-anywhere c library
This release fixes two issues with the recent 3.3.1 cosmocc release.
_Float16
type__STRICT_ANSI__
Please see the previous release for the latest cosmos and further details.
This release fixes regressions introduced by v3.3, squashes additional bugs,
makes reliability and quality improvements, makes math better, and introduces
the getcpu()
system call.
*scanf()
fixes to make TeX work (#1109)apelink
in some edge cases (#1106)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.
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().
__constructor__
, .ctor, .init_array, and .preinit_array so they behave the exact same way as glibc.$HOME
and $USER
are always defined.complex.h
header now works and support is added for struct ipv6_mreq
(#1100)MODE=dbg
support is now restored, as of c1e18e790__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.pthread_create()
will no longer raise an assertion error if it fails, as of 8ebe2e902__cxa_thread_atexit
prototype has been fixed in #1088dontthrow
, to save on size.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/
cosmocc --version
reports the incorrect gcc version.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.
This v3.2.4 release of Cosmopolitan introduces C++ exceptions and RTTI,
which can be enabled by passing the -fexceptions
and/or -rtti
flags
to your cosmocc
compiler.
If C is your preferred language, then you can use Cosmopolitan garbage
collection via our new gc()
macro. To enable this feature, you need to
pass the -mcosmo
flag to cosmocc. For example, to say gc(malloc(32))
means that memory will be reclaimed when your function returns, and it
will be reclaimed by pthread_exit()
too. There's also defer() which is
generalized and allows any callback. Pointers exist on a shadow stack.
gc()
functionHere's some additional developments since the last release:
This release introduces two new features:
Your cosmo_dlsym() function now returns the raw symbols. You need to
update your code to call cosmo_dltramp() on the result, otherwise it
will crash on Windows. Better yet, just use __ms_abi__
if you can.
The following fixes have been implemented:
-z execstack
on LinuxAPE Loader has a backwards compatibility regression right now. If you
run ape/apeinstall.sh
on Linux then, due to a new binfmt_misc feature,
many old APE binaries that need to load zip assets will refuse to run. You
can fix that on Linux x64 for example by running:
ape/apeuninstall.sh
make -j8 o//ape
sudo mv o//ape/ape.elf /usr/bin/ape
sudo sh -c "echo ':APE:M::MZqFpD::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register"
sudo sh -c "echo ':APE-jart:M::jartsr::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register"
This will be solved by the next release, to ensure that only modern
APE binaries can use Linux's new P
feature. APE is after all designed
to stand the test of time. The intent is to support every APE executable
created since the beginning of the project.
Function pointers are now safer when using dynamically linked libraries.
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.
Our latest 3.2 release features exciting fixes and improvements.
We've fixed important threading bugs on /zip/...
file descriptors.
We now have a hack that lets you use cosmo binaries as a login shell. Setuid security is improved. Executable path self-detection is better. There's a new APE loader version as a result. If you have a systemwide APE loader install, it's recommended that you upgrade, but not required.
Our public header files now have better open source compatibility.
gid_t
and uid_t
in passwd.h
(#995)tcgetpgrp
and tcsetpgrp
decls to unistd.h
(#996) (#997)