2.0
版本发布时间: 2022-08-19 11:12:35
jart/cosmopolitan最新发布版本:3.8.0(2024-08-31 11:52:21)
Cosmopolitan Libc makes C/C++ a build-once run-anywhere language, like Java, except it doesn't need an interpreter or virtual machine. Instead, it reconfigures stock GCC 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 use Linux, then you can build Cosmopolitan and its included software from source as follows:
wget https://justine.lol/cosmopolitan/cosmopolitan-2.0.tar.gz
tar xf cosmopolitan-2.0.tar.gz
cd cosmopolitan
build/bootstrap/make.com -j8
o//examples/hello.com
If you're doing your development work on Linux or BSD and you want to bring your own build system, then you need just five files to get started:
wget https://justine.lol/cosmopolitan/cosmopolitan-amalgamation-2.0.zip
unzip cosmopolitan-amalgamation-2.0.zip
printf 'main() { printf("hello world\\n"); }\n' >hello.c
gcc -g -Os -static -nostdlib -nostdinc -fno-pie -no-pie -mno-red-zone \
-fno-omit-frame-pointer -pg -mnop-mcount -mno-tls-direct-seg-refs \
-o hello.com.dbg hello.c -fuse-ld=bfd -Wl,-T,ape.lds -Wl,--gc-sections \
-include cosmopolitan.h crt.o ape-no-modify-self.o cosmopolitan.a
objcopy -S -O binary hello.com.dbg hello.com
Breaking Changes
- You have to use
/zip/...
rather thanzip:...
when open()'ing assets stored in the PKZIP structure of your executable program. 00611e9b06be11e8af3a05c5d60878377aa2b0bd - You should use
/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. - The default stack size has been reduced to 128kb. To learn how to increase this limit, or log your stack usage, please see 226aaf354786505e05283adfd52b43b668807336
- We renamed
LOGF
toINFOF
in the logging API. 0584684a8202dbdfc2861a32bee3e73d0161a537 - 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 forint128_t
. Functions likebsrmax()
are now calledbsr128()
. 868af3f950c562baa1a73539703c6c78d51adceb - We've renamed
nothrow
todontthrow
andnodiscard
is nowdontdiscard
. 868af3f950c562baa1a73539703c6c78d51adceb - Remove undocumented and ANSI WIN32 APIs in d3b599a79 and a157940ba61049420094a78829a062d57e78a44d
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. 47a53e143b9baf1e25b7001dd377986f8fac2989 - 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 these 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 six supported operating systems. Use the
_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. - 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. You must use the-mno-tls-direct-seg-refs
flag. 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. - 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, useMODE=tiny
orMODE=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, useMODE=tiny
orMODE=rel
. 14e192e5ba820c60fa4aef48c1a646b151723603 - You can now use Actually Portable Python by building
o//third_party/python/python.com
which includes animport 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
andgettimeofday
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'sdisablenetwork()
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 398f0c16fbdcd356bdfc14111434b0f0f8de7de5 and f3e28aa192d433c379b86df00d760d87da25a487 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.
Bug Fixes
- Fork on Windows now works reliably 0cb6b6ff4b34a3503cd899ccbb12538a58d73b49 98909b13913c80e9c61035d1fe371f4a6bed9edb e5314dedde3553973a3e8692ffec7a65a6be6d20
- Memory maps on Windows now work reliably
- Signals on Windows now works well enough for Redbean to offer a web server with a repl 072e1d29109f835a592a7e4edf53898fcea7ae88
- Fix %c with nul character 3c285337a
- 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.
- We now polyfill ENOENT vs. ENOTDIR on Windows
- Daemonization now works on Windows
1、 cosmopolitan-2.0.tar.gz 61.19MB
2、 cosmopolitan-amalgamation-2.0.zip 7.05MB
3、 cosmopolitan-amalgamation-dbg-2.0.zip 12.18MB
4、 cosmopolitan-amalgamation-rel-2.0.zip 7MB
5、 cosmopolitan-amalgamation-tiny-2.0.zip 6.67MB