You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 or UEFI with the best possible performance and the tiniest footprint imaginable.
Getting Started
If you're doing your development work on Linux or BSD then you need just
five files to get started. Here's what you do on Linux:
You have to use /zip/... rather than zip:... when open()'ing assets stored in the PKZIP structure of your executable program. 00611e9
You should use /c/... paths on Windows rather than C:/.... Your arguments and environment variables will be patched conservatively by the runtime to normalize $PATH and make life easy. It's still possible to use DOS, WIN32, NT, and other Microsoft-style paths with our APIs.
The default stack size has been reduced to 128kb. To learn how to increase this limit, or log your stack usage, please see 226aaf3
We renamed LOGF to INFOF in the logging API. 0584684
We no longer define intmax_t as 128-bit. We now violate the standard like everyone else, by defining it as 64-bit. We've introduced a new %jjd formatting directive for int128_t. Functions like bsrmax() are now called bsr128(). 868af3f
We've renamed nothrow to dontthrow and nodiscard is now dontdiscard. 868af3f
Remove undocumented and ANSI WIN32 APIs in d3b599a and a157940
Features
We now favor the new APE loader (see ape-no-modify-self.o). It's extracted automatically. It's fast. It maps your programs into memory without copying or self-modifying the header. An --assimilate flag is baked-in to the shell script at the tops of your binaries, so you can convert them to the platform-local format whenever you want. If you're using binfmt_misc then a separate assimilate program is provided for doing just that. We also still distribute the classic ape.o bootloader. 47a53e1
Binfmt_misc support for Linux users. This is the fastest way to run APE programs. You can install it by running the ape/apeinstall.sh program in this repository.
We've polyfilled the OpenBSD pledge() and unveil() system calls for Linux. You can now use this APIs in your C/C++/Python/Redbean programs, or you can use the new pledge.com command to sandbox your existing Linux userspace.
We now use Landlock Make to build the repository, since it offers sandboxing and hermeticity guarantees. Our project will still build fine using vanilla GNU Make, since Landlock Make is backwards compatible.
We now offer support for threading that works on all seven supported platforms. Use the _spawn() and _join() functions. We're working on POSIX Threads support and recommend using our new pthread_mutex_lock implementation. For examples of multi-threaded programs, see examples/greenbean.c and tool/build/mkdeps.c.
You can now use the _Thread_local keyword. Your C runtime will now always initialize Thread-Local Storage (TLS) for your main process thread. Doing that means the minimum APE binary size had to be increased from 12kb to 16kb. We prefer using the %fs register. On Windows and Apple platforms, your executable will rewritten in memory at initialization to turn %fs opcodes into %gs. If you wish to control your segment registers, then you may do so by setting __tls_enabled to false and calling arch_prctl. Please note if you use threads, this will make errno no longer thread safe.
We now uniquely polyfill mmap(MAP_STACK) which brings the FreeBSD behavior to Linux. You must use it if you want your code to run on OpenBSD. Please see the mmap() documentation to learn more.
The Cosmopolitan monolithic repository now offers the LLVM LIBCXX Standard Template Library for C++ developers. This is not currently available in the amalgamation.
Your Cosmopolitan binaries now include an --ftrace flag which logs C function calls to standard error. Please read the Logging C Functions blog post which explains more. You need to use the -pg (and hopefully also -mnop-mcount) flag for this to work. If you don't want this functionality in your runtime, use MODE=tiny or MODE=rel.
Your Cosmopolitan binaries now include an --strace flag which logs system calls to standard error. This works consistently across platforms. It's especially helpful for ZIP-related system calls, which aren't handled by the kernel. Please read the Logging C Functions blog post which explains more. If you don't want this functionality in your runtime, use MODE=tiny or MODE=rel. 14e192e
You can now use Actually Portable Python by building o//third_party/python/python.com which includes an import cosmo module that lets you use our best features too.
New closefrom() system call for Linux 5.9+, FreeBSD 8+, and OpenBSD.
The clock_gettime and gettimeofday functions now go 10x faster on Linux via the vDSO.
Our ASAN module is now able to trace the origin of memory allocations when generating reports.
Complex math functions are now available, thanks to Musl Libc.
Many math functions, e.g. pow(), now go faster, thanks to ARM.
New nointernet() function which is similar in spirit to djb's disablenetwork() function.
New string appending library. See appendd, appendf, appendr, appends, appendw, appendz, kappendf, kvappendf, and vappendf. What makes this library good is it's (a) fast, and (b) strings made by these functions can be passed to free().
We now offer a bulletproof unbreakable kprintf() family of functions as part of the privileged runtime.
SSL performance is now significantly improved. See 398f0c1 and f3e28aa and similar changes where we've added x86 optimizations for computing SHA faster, Intel ADX code that makes RSA multiplication faster, clean up code to make Everest curve25519 faster, and wrote an assembly implementation of NIST curve quasi-reduction.
There's been a lot of fixes and fine tuning to the system call support magnums in consts.sh and syscalls.sh
Many system call polyfills have been improved, e.g. sysinfo, statfs, pselect, ppoll, sleep, sched_yield, utimensat, setsockopt, clock_gettime, sigsuspend, etc.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
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 or UEFI with the best possible performance and the tiniest footprint imaginable.
Getting Started
If you're doing your development work on Linux or BSD then you need just
five files to get started. Here's what you do on Linux:
Breaking Changes
/zip/...
rather thanzip:...
when open()'ing assets stored in the PKZIP structure of your executable program. 00611e9/c/...
paths on Windows rather thanC:/...
. Your arguments and environment variables will be patched conservatively by the runtime to normalize$PATH
and make life easy. It's still possible to use DOS, WIN32, NT, and other Microsoft-style paths with our APIs.LOGF
toINFOF
in the logging API. 0584684intmax_t
as 128-bit. We now violate the standard like everyone else, by defining it as 64-bit. We've introduced a new%jjd
formatting directive forint128_t
. Functions likebsrmax()
are now calledbsr128()
. 868af3fnothrow
todontthrow
andnodiscard
is nowdontdiscard
. 868af3fFeatures
--assimilate
flag is baked-in to the shell script at the tops of your binaries, so you can convert them to the platform-local format whenever you want. If you're using binfmt_misc then a separate assimilate program is provided for doing just that. We also still distribute the classic ape.o bootloader. 47a53e1ape/apeinstall.sh
program in this repository._spawn()
and_join()
functions. We're working on POSIX Threads support and recommend using our newpthread_mutex_lock
implementation. For examples of multi-threaded programs, see examples/greenbean.c and tool/build/mkdeps.c._Thread_local
keyword. Your C runtime will now always initialize Thread-Local Storage (TLS) for your main process thread. Doing that means the minimum APE binary size had to be increased from 12kb to 16kb. We prefer using the%fs
register. On Windows and Apple platforms, your executable will rewritten in memory at initialization to turn%fs
opcodes into%gs
. If you wish to control your segment registers, then you may do so by setting__tls_enabled
to false and callingarch_prctl
. Please note if you use threads, this will makeerrno
no longer thread safe.mmap(MAP_STACK)
which brings the FreeBSD behavior to Linux. You must use it if you want your code to run on OpenBSD. Please see the mmap() documentation to learn more.--ftrace
flag which logs C function calls to standard error. Please read the Logging C Functions blog post which explains more. You need to use the-pg
(and hopefully also-mnop-mcount
) flag for this to work. If you don't want this functionality in your runtime, useMODE=tiny
orMODE=rel
.--strace
flag which logs system calls to standard error. This works consistently across platforms. It's especially helpful for ZIP-related system calls, which aren't handled by the kernel. Please read the Logging C Functions blog post which explains more. If you don't want this functionality in your runtime, useMODE=tiny
orMODE=rel
. 14e192eo//third_party/python/python.com
which includes animport cosmo
module that lets you use our best features too.closefrom()
system call for Linux 5.9+, FreeBSD 8+, and OpenBSD.clock_gettime
andgettimeofday
functions now go 10x faster on Linux via the vDSO.nointernet()
function which is similar in spirit to djb'sdisablenetwork()
function.privileged
runtime.Bug Fixes
This discussion was created from the release Cosmopolitan v2.0.
Beta Was this translation helpful? Give feedback.
All reactions