build-once run-anywhere c library

Overview

Cosmopolitan Honeybadger

Cosmopolitan

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.

Background

For an introduction to this project, please read the αcτµαlly pδrταblε εxεcµταblε blog post and cosmopolitan libc website. We also have API documentation.

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:

wget https://justine.lol/cosmopolitan/cosmopolitan-amalgamation-1.0.zip
unzip cosmopolitan-amalgamation-1.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 \
  -o hello.com.dbg hello.c -fuse-ld=bfd -Wl,-T,ape.lds \
  -include cosmopolitan.h crt.o ape.o cosmopolitan.a
objcopy -S -O binary hello.com.dbg hello.com

You now have a portable program. Please note that your APE binary will assimilate itself as a conventional resident of your platform after the first run, so it can be fast and efficient for subsequent executions.

./hello.com
bash -c './hello.com'  # zsh/fish workaround (we upstreamed patches)

So if you intend to copy the binary to Windows or Mac then please do that before you run it, not after.

MacOS

If you're developing on MacOS you can install the GNU compiler collection for x86_64-elf via homebrew:

brew install x86_64-elf-gcc

Then in the above scripts just replace gcc and objcopy with x86_64-elf-gcc and x86_64-elf-objcopy to compile your APE binary.

Windows

If you're developing on Windows then you need to download an x86_64-pc-linux-gnu toolchain beforehand. See the Compiling on Windows tutorial. It's needed because the ELF object format is what makes universal binaries possible.

Source Builds

Cosmopolitan can be compiled from source on any Linux distro. GNU make needs to be installed beforehand. This is a freestanding hermetic repository that bootstraps using a vendored static gcc9 executable. No further dependencies are required.

wget https://justine.lol/cosmopolitan/cosmopolitan-1.0.tar.gz
tar xf cosmopolitan-1.0.tar.gz  # see releases page
cd cosmopolitan
make -j16
o//examples/hello.com
find o -name \*.com | xargs ls -rShal | less

Support Vector

Platform Min Version Circa
AMD K8 Venus 2005
Intel Core 2006
New Technology Vista 2006
GNU/Systemd 2.6.18 2007
XNU's Not UNIX! 15.6 2018
FreeBSD 12 2018
OpenBSD 6.4 2018
NetBSD 9.1 2020
GNU Make 4.0 2015
Comments
  • Redbean dynamic serving language

    Redbean dynamic serving language

    (Based on the author's note in https://github.com/jart/cosmopolitan/issues/95#issuecomment-788605775, opened a separate ticket)

    • For default index file
    • For some redirection (say, old URL to new URL with 301 or 302)
    • For hiding extension (say, to avoid .html. Preferably GitHub pages approaches for handling static files)
    • For hiding server signature
    opened by rrjanbiah 192
  • Compiling Lua

    Compiling Lua

    I thought it might be fun to compile a portable version of a language which has C source code.
    I picked Lua, and I eventually got it to compile and run on Windows/Linux.

    I thought some of the compilation errors might be useful info:

    • The following functions/macros in the Lua source clashed names with those in cosmopolitan.h: panic, reverse and isempty.
    • strcoll, tanh, sinh, and cosh are unimplemented (leads to linker error)
    • UCHAR_MAX in limits.h of the C stdlib is not defined even though SCHAR_MAX is
    • Maybe similar to #58, but floats don't print in the portable Lua console
    opened by ahgamut 67
  • Get cosmopolitation working on Vista again

    Get cosmopolitation working on Vista again

    Ideally the fixed size array would be removed on Vista/7 as well but I am not entirely sure how. If it's truly related to older versions of Windows having smaller virtual address spaces then perhaps using a smaller address would be enough.

    opened by JoshuaWierenga 51
  • Cannot build it with lots of cores.

    Cannot build it with lots of cores.

    I've been trying and failing to build cosmopolitan under Devuan Chimaera, which is a Debian based Linux distribution without systemd. I do notice that you keep mentioning GNU/systemd instead of Linux, I was thinking that was some sort of joke, but maybe my problem is the lack of systemd?

    I have tried git head, and the source tarball, same result.

    make -j1 -O
    ♥cosmo
    error: clone(0) failed EAGAIN/11/Try again
    
    `make MODE= -j128 o//depend` exited with 1:
    build/bootstrap/mkdeps.com -o o//depend -r o// @o//srcs.txt @o//hdrs.txt @o//incs.txt
    consumed 561µs wall time
    ballooned to 160kb in size
    needed 523us cpu (0% kernel)
    caused 18 page faults (100% memcpy)
    
    x86_64-linux-musl-gcc: fatal error: cannot execute '/media/DATA/home/dvs1/src/APE_Cosmo_STUFFS/cosmopolitan_ORIGINAL_BUILD/o/third_party/gcc/bin/../libexec/gcc/x86_64-linux-musl/9.2.0/cc1': vfork: Resource temporarily unavailable
    compilation terminated.
    
    `make MODE= -j128 o/ape/config.h.ok` exited with 1:
    o/third_party/gcc/bin/x86_64-linux-musl-gcc -S -Wall -Werror -fdebug-prefix-map=/media/DATA/home/dvs1/src/APE_Cosmo_STUFFS/cosmopolitan_ORIGINAL_BUILD= -frecord-gcc-switches -fno-schedule-insns2 -fno-optimize-sibling-calls -mno-omit-leaf-frame-pointer -DSYSDEBUG -Og -DCOSMO -DMODE="" -DIMAGE_BASE_VIRTUAL=0x400000 -nostdinc -iquote. -includelibc/integral/normalize.inc -msse3 -fno-math-errno -fno-trapping-math -fno-fp-int-builtin-inexact -fno-ident -fno-common -fno-gnu-unique -fstrict-aliasing -fstrict-overflow -fno-semantic-interposition -std=gnu2x -xc -g0 -o o/ape/config.h.ok ape/config.h -fdiagnostics-color=always -pg -D__PG__ -mno-red-zone -D__MNO_RED_ZONE__ -fno-omit-frame-pointer -D__FNO_OMIT_FRAME_POINTER__
    consumed 15,001,251µs wall time
    ballooned to 1,148kb in size
    needed 884us cpu (0% kernel)
    caused 49 page faults (100% memcpy)
    5 context switches (100% consensual)
    
    make: *** [build/rules.mk:32: o/ape/config.h.ok] Error 1
    

    The number of "vfork: Resource temporarily unavailable" sections I get depends on how many -jx I use. Despite giving specific -jx, there's always the "make MODE= -j128". Yes I have a Ryzen Threadripper with 64 cores, so CPU counting ends up at 128. Do I have too many cores, and something is tripping up on that? It seems to be running out of cores. lol

    I notice there's no way of building completely from source, otherwise I would hack away at the source code until it worked, but the build system tries to use it's own pre compiled build tools that come with the source code, and it's this build system binary blob that is failing. So I can't fix this myself with out lots of work essentially rebuilding things from the ground up one step at a time.

    Redbean worked fine, which is the thing that attracted me to cosmo in the first place. I want to try redbean out as the basis for my OpenSim rewrite (3D virtual world metaverse that has been around for over a decade).

    opened by onefang 35
  • Added _multiprocessing C extension to stdlib

    Added _multiprocessing C extension to stdlib

    Also moved PYTHON_YOINK of email and encodings.idna so that http.server would work in MODE=tiny. (If tree-shaking for Python stdlib is possible, then the above change will be handled during the build process).

    Should the PYTHON_YOINKs be somewhere else than python.c?

    Many stdlib components have X.py and _X.c (locale, multiprocessing, sqlite for example) so it may be better to add PYTHON_YOINK("sqlite.py") to _sqlite.c and then skip adding sqlite3.pyc if _sqlite3 is not compiled.

    opened by ahgamut 26
  • Implemented missing socketpair

    Implemented missing socketpair

    Added the missing implementation of socketpair(). Since Win32 doesn't have socketpair (as far as I know), I have implemented a simple wrapper that creates two individual sockets, set them in non-blocking mode and connects them together. sysv implementation simply calls into sys_socketpair() that was already implemented.

    opened by fabriziobertocci 25
  • Add support for VGA console output in bare metal mode

    Add support for VGA console output in bare metal mode

    I have added (as of https://github.com/tkchia/cosmopolitan/commit/c42c607c80c2920b585ee1a65a9c66ec68acd609) some very rough and preliminary support for console output to the VGA screen — in addition to the serial port — when in bare metal mode.

    I hope to improve on it further, e.g.:

    • [x] ensure that the screen in a known mode (text or graphics), at rlinit time (rather than simply assuming that the screen is in the classical 80 × 25 × 16 text mode, with a text buffer at address 0xb8000); (✓ https://github.com/tkchia/cosmopolitan/pull/588/commits/aeacc4239dc14b9adfaa7be80bde9a6f4711f7f8)
    • [ ] ~~switch to using a font embedded in the program, rather than rely on the BIOS's CP437 font;~~
    • [x] handle UTF-8 multi-byte characters; (✓ https://github.com/tkchia/cosmopolitan/pull/588/commits/d4d24482ce0a7b79a4dc4439024198c323fbb975)
    • [x] handle VT102 escape sequences; (✓ https://github.com/tkchia/cosmopolitan/pull/588/commits/d4d24482ce0a7b79a4dc4439024198c323fbb975)
    • [ ] ~~maybe handle the BEL ('\a') character code.~~
    opened by tkchia 24
  • binfmt_misc tuning can break ape

    binfmt_misc tuning can break ape

    Hello,

    I'm just trying this on Ubuntu 20.04 and get the following error:

    $ make -j8 -O o//examples/hello.com
    
    MKDEPS         o//depend
    ZIPOBJ         o//libc/stubs/errno.S.zip.o
    run-detectors: unable to find an interpreter for o/build/bootstrap/zipobj.com
    make: *** [build/rules.mk:76: o//libc/stubs/errno.S.zip.o] Error 2
    ZIPOBJ         o//libc/stubs/triplf.S.zip.o
    run-detectors: unable to find an interpreter for o/build/bootstrap/zipobj.com
    ZIPOBJ         o//libc/stubs/asanjmp.greg.S.zip.o
    run-detectors: unable to find an interpreter for o/build/bootstrap/zipobj.com
    ZIPOBJ         o//libc/stubs/subvsi3.S.zip.o
    run-detectors: unable to find an interpreter for o/build/bootstrap/zipobj.com
    ZIPOBJ         o//libc/stubs/mulvdi3.S.zip.o
    run-detectors: unable to find an interpreter for o/build/bootstrap/zipobj.com
    ZIPOBJ         o//libc/stubs/errnolocation.S.zip.o
    run-detectors: unable to find an interpreter for o/build/bootstrap/zipobj.com
    ZIPOBJ         o//libc/stubs/mcount.S.zip.o
    run-detectors: unable to find an interpreter for o/build/bootstrap/zipobj.com
    ZIPOBJ         o//libc/stubs/panic.S.zip.o
    run-detectors: unable to find an interpreter for o/build/bootstrap/zipobj.com
    make: *** [build/rules.mk:76: o//libc/stubs/panic.S.zip.o] Error 2
    

    If I try to run zipobj.com directly, it returns the following:

    $build/bootstrap/zipobj.com
    
    error:tool/build/zipobj.c:93:zipobj.com: check failed
            CHECK_NE(NULL, outpath_);
                     → 0 (outpath_)
                    != 0 (NULL)
            E?/err=0/errno:0/GetLastError:0
            build/bootstrap/zipobj.com
    

    Thanks!

    opened by omimo 23
  • Hello.com, redbean.com fail to run on MacOS M1 under Rosetta

    Hello.com, redbean.com fail to run on MacOS M1 under Rosetta

    hello.com is built on linux following instructions published here: https://justine.lol/cosmopolitan/ and then executed on a MacBook Pro with the M1 Max chip (arm64) running macOS Monterey 12.4 under Rosetta translation.

    #To confirm that it's running under Rosetta:
    ❯ arch -arch x86_64 ./[hello.com](http://hello.com/)
    [1]    79473 segmentation fault  arch -arch x86_64 ./[hello.com](http://hello.com/)
    
    ❯ sh ./[hello.com](http://hello.com/)
    [1]    73377 segmentation fault  sh ./[hello.com](http://hello.com/)
    ❯ sh ./[hello.com](http://hello.com/) --assimilate
    ❯ ./[hello.com](http://hello.com/)
    [1]    73395 segmentation fault  ./[hello.com](http://hello.com/)
    ❯ lldb --file ./[hello.com](http://hello.com/)
    (lldb) target create "./[hello.com](http://hello.com/)"
    Current executable set to '/Users/user/cosmo/[hello.com](http://hello.com/)' (x86_64).
    (lldb) r
    Process 73409 launched: '/Users/user/cosmo/[hello.com](http://hello.com/)' (x86_64)
    Process 73409 stopped
    * thread #1, stop reason = EXC_BAD_ACCESS (code=1, address=0x1f)
        frame #0: 0x000000000040239f [hello.com](http://hello.com/)
    ->  0x40239f: movl   (%rsp), %ebx
        0x4023a2: leaq   0x8(%rsp), %rsi
        0x4023a7: leaq   0x10(%rsp,%rbx,8), %rdx
        0x4023ac: movq   %rsp, 0x1e97d(%rip)
    Target 0: ([hello.com](http://hello.com/)) stopped.
    (lldb) bt
    * thread #1, stop reason = EXC_BAD_ACCESS (code=1, address=0x1f)
      * frame #0: 0x000000000040239f [hello.com](http://hello.com/)
    (lldb)
    ❯ file [hello.com](http://hello.com/)
    [hello.com](http://hello.com/): Mach-O 64-bit executable x86_64
    

    Full crash report:

    {"app_name":"[hello.com](http://hello.com/)","timestamp":"2022-06-17 12:25:25.00 -0700","app_version":"","slice_uuid":"45e417b7-2c6d-a6da-45e4-17b72c6da6da","build_version":"","platform":0,"share_with_app_devs":1,"is_first_party":1,"bug_type":"309","os_version":"macOS 12.4 (21F79)","incident_id":"E185D602-4547-4382-874C-6A44AF63AAD3","name":"[hello.com](http://hello.com/)"}
    {
      "uptime" : 2300000,
      "procLaunch" : "2022-06-17 12:25:25.2262 -0700",
      "procRole" : "Unspecified",
      "version" : 2,
      "userID" : 501,
      "deployVersion" : 210,
      "modelCode" : "MacBookPro18,4",
      "procStartAbsTime" : 55200184527962,
      "coalitionID" : 3240,
      "osVersion" : {
        "train" : "macOS 12.4",
        "build" : "21F79",
        "releaseType" : "User"
      },
      "captureTime" : "2022-06-17 12:25:25.4489 -0700",
      "incident" : "E185D602-4547-4382-874C-6A44AF63AAD3",
      "bug_type" : "309",
      "pid" : 73395,
      "procExitAbsTime" : 55200189857901,
      "translated" : true,
      "cpuType" : "X86-64",
      "procName" : "[hello.com](http://hello.com/)",
      "procPath" : "\/Users\/USER\/*\/[hello.com](http://hello.com/)",
      "parentProc" : "zsh",
      "parentPid" : 73319,
      "coalitionName" : "com.googlecode.iterm2",
      "crashReporterKey" : "917168CC-9F91-8E09-0E83-6F8C1759F8E6",
      "responsiblePid" : 10569,
      "responsibleProc" : "iTerm2",
      "wakeTime" : 29832,
      "sleepWakeUUID" : "5126274E-4713-4921-8ECB-404A80F155BC",
      "sip" : "enabled",
      "vmRegionInfo" : "0x1f is not in any region.  Bytes before following region: 140718563835873\n      REGION TYPE                    START - END         [ VSIZE] PRT\/MAX SHRMOD  REGION DETAIL\n      UNUSED SPACE AT START\n--->  \n      mapped file              7ffb9802c000-7ffbc5b10000 [730.9M] r-x\/r-x SM=COW  ...t_id=a25954a5",
      "isCorpse" : 1,
      "exception" : {"codes":"0x0000000000000001, 0x000000000000001f","rawCodes":[1,31],"type":"EXC_BAD_ACCESS","signal":"SIGSEGV","subtype":"KERN_INVALID_ADDRESS at 0x000000000000001f"},
      "termination" : {"flags":0,"code":11,"namespace":"SIGNAL","indicator":"Segmentation fault: 11","byProc":"exc handler","byPid":73395},
      "vmregioninfo" : "0x1f is not in any region.  Bytes before following region: 140718563835873\n      REGION TYPE                    START - END         [ VSIZE] PRT\/MAX SHRMOD  REGION DETAIL\n      UNUSED SPACE AT START\n--->  \n      mapped file              7ffb9802c000-7ffbc5b10000 [730.9M] r-x\/r-x SM=COW  ...t_id=a25954a5",
      "extMods" : {"caller":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"system":{"thread_create":0,"thread_set_state":1,"task_for_pid":2},"targeted":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"warnings":0},
      "usedImages" : [
      {
        "size" : 0,
        "source" : "A",
        "base" : 0,
        "uuid" : "00000000-0000-0000-0000-000000000000"
      }
    ],
      "legacyInfo" : {
      "threadHighlighted" : 0
    },
      "trialInfo" : {
      "rollouts" : [
        {
          "rolloutId" : "6112e14f37f5d11121dcd519",
          "factorPackIds" : {
            "SIRI_TEXT_TO_SPEECH" : "629e5353a0d1644ed53959b8"
          },
          "deploymentId" : 240000148
        },
        {
          "rolloutId" : "61301e3a61217b3110231469",
          "factorPackIds" : {
            "SIRI_FIND_MY_CONFIGURATION_FILES" : "6216ae152a40e71046e16225"
          },
          "deploymentId" : 240000016
        }
      ],
      "experiments" : [
    
      ]
    },
      "reportNotes" : [
      "_dyld_process_info_create failed with 5",
      "dyld_process_snapshot_get_shared_cache failed",
      "Failed to create CSSymbolicatorRef - corpse still valid ¯\\_(ツ)_\/¯"
    ]
    }
    

    @jart, is there any additional information I can get to troubleshoot this? --ftrace doesn't show any information at all, so it appears to be crashing before it gets to any of the function frames.

    It may be related to AVX instruction support (even though EXC_BAD_ACCESS seems to indicate a memory issue); Rosetta documentation indicates the following:

    Rosetta translates all x86_64 instructions, but it doesn’t support the execution of some newer instruction sets and processor features, such as AVX, AVX2, and AVX512 vector instructions. If you include these newer instructions in your code, execute them only after verifying that they are available. For example, to determine if AVX512 vector instructions are available, use the sysctlbyname function to check the hw.optional.avx512f attribute.

    contributions welcome 
    opened by pkulchenko 22
  • redbean: LaunchBrowser not working on macos

    redbean: LaunchBrowser not working on macos

    redbean 1.5 macos big sur 11.6

    If I add in an index.html file then it works fine and I get the server running, but as soon as I add the command LaunchBrowser() to the .init.lua file, it fails with:

    error: Uncaught SIGSEGV (SEGV_MAPERR) on Mikas-Mac-Pro pid 5793
      ./redbrean.com.zip
      ENOENT[No such file or directory][2]
    

    I've tried with paths "/" and "/index.html" and "index.html" but they all fail with the same issue.

    opened by mika76 21
  • Get bare metal code (mostly) working outside of an emulator

    Get bare metal code (mostly) working outside of an emulator

    These patches fix a few issues, which were causing the bare metal code to crash (and reboot) when run on a real machine, outside of an emulator. These have to do with

    • the retrieval of the system memory map (int 0x15, eax = 0xe820), and
    • the initial creation of the page tables for virtual memory operation.

    I have debugged and tested the patched code, by booting it from a USB drive, on a x86-64 PC with a "legacy BIOS".

    Thank you!

    opened by tkchia 17
  • Modern Protocols: TLS 1.3, QUIC, and IPv6

    Modern Protocols: TLS 1.3, QUIC, and IPv6

    Currently Cosmopolitan includes a modified MbedTLS, and most network functions appear to only readily support IPv4. I propose adding more complete support for IPv6, which would allow network applications such as Redbean to work on systems without any IPv4 interfaces (low-end IPv6-only virtual servers, test networks, other IPv6-only networks, etc.)

    I also propose integrating PicoTLS (https://github.com/h2o/picotls) and PicoQUIC (https://github.com/private-octopus/picoquic), minimal and portable C implementations of TLS 1.3 and QUIC respectively. PicoTLS would likely have to be modified to use cryptographic primitives from MbedTLS/mbedcrypto. As a bonus, PicoTLS will receive support for ECH fairly soon.

    opened by Ronsor 1
  • [metal] Allow programs larger than 440 KiB to run in bare metal mode

    [metal] Allow programs larger than 440 KiB to run in bare metal mode

    This PR tries to address the problem outlined at https://github.com/jart/cosmopolitan/pull/667#issuecomment-1283748049 : the bare metal bootloader only loads the first 440 KiB of the program image into memory, so programs larger than 440 KiB crash.

    To do:

    • [x] Get o//examples/hellolua.com to run correctly under QEMU in legacy BIOS mode
      • [x] Copy first 440 KiB of program pages to extended memory
      • [x] Load program pages beyond first 440 KiB into extended memory as well
      • [x] Reclaim memory pages used at boot time, and make them available for later application use
    • [x] Ensure o//examples/vga2.com ~~(and/or o//examples/hellolua.com)~~ also run correctly when started in UEFI mode (✓ https://github.com/tkchia/cosmopolitan/commit/36b06ab73e107796d93f27e63e17e5a0655170db, https://github.com/tkchia/cosmopolitan/commit/9fe2f551139d08c23d17bc94e1cde45076de4794, https://github.com/tkchia/cosmopolitan/commit/8f698a13f570a2c41e46ea357e3db8b12af02855)
    • [x] Allow munmap to reclaim dynamically allocated pages (✓ https://github.com/tkchia/cosmopolitan/commit/de295966b1f24dc5c2c70d3d36a60af9aab47313)
      • [x] Implement reference counting of physical pages, to decide when to reclaim them
    • [ ] (?) Maybe add integrity checks to guard against corruption in free list of reclaimed pages
    opened by tkchia 3
  • ape error: phdrs must be 4096-aligned,

    ape error: phdrs must be 4096-aligned,

    I get this error, when running a linked executable, which I don't understand. What are phdrs and how can I influence their makeup ?

    ape error: ./kitchen/cosmopolitan/Debug/xxx1: APE phdrs must be 4096-aligned and 4096-padded
    
    opened by mulle-nat 11
  • CVE-2007-4559 Patch

    CVE-2007-4559 Patch

    Patching CVE-2007-4559

    Hi, we are security researchers from the Advanced Research Center at Trellix. We have began a campaign to patch a widespread bug named CVE-2007-4559. CVE-2007-4559 is a 15 year old bug in the Python tarfile package. By using extract() or extractall() on a tarfile object without sanitizing input, a maliciously crafted .tar file could perform a directory path traversal attack. We found at least one unsantized extractall() in your codebase and are providing a patch for you via pull request. The patch essentially checks to see if all tarfile members will be extracted safely and throws an exception otherwise. We encourage you to use this patch or your own solution to secure against CVE-2007-4559. Further technical information about the vulnerability can be found in this blog.

    If you have further questions you may contact us through this projects lead researcher Kasimir Schulz.

    opened by TrellixVulnTeam 0
  • Document appropriate compiler flags for clang usage

    Document appropriate compiler flags for clang usage

    Hi folks. Awesome project! I was wondering if it might be possible to document somewhere an example of the clang equivalent to the simple gcc example given in the readme, i.e.:

    wget https://justine.lol/cosmopolitan/cosmopolitan-amalgamation-2.1.1.zip
    unzip cosmopolitan-amalgamation-2.1.1.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 -gdwarf-4 \
      -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
    

    I understand that clang should in principle be an option here, but if I just try to substitute clang in for gcc here, I get various errors about unsupported flags, including

    clang: error: unsupported option '-mnop-mcount' for target 'x86_64-pc-linux-gnu'
    

    What would I have to change to get this to work with clang instead?

    opened by brenhinkeller 1
Releases(2.2)
  • 2.2(Nov 7, 2022)

    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.2.tar.gz
    tar xf cosmopolitan-2.2.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.2.zip
    unzip cosmopolitan-amalgamation-2.2.zip
    printf 'main() { printf("hello world\\n"); }\n' >hello.c
    gcc -g -Os -static -nostdlib -nostdinc -fno-pie -no-pie -mno-red-zone -gdwarf-4 \
      -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
    

    Features

    • Implement POSIX semaphores 811146278
    • Implement POSIX cancellations 2278327eb 022536cab 3f0bcdc3e 3f0bcdc3e 4a6fd3d91 e522aa3a0
    • Implement atomic swar token bucket library for DDOS protection e7329b7cb
    • Introduce sigtimedwait() and sigwaitinfo() 467a332e3
    • Invent iso8601us() for faster timestamps f7ff77d86
    • Work towards zipos / open(argv[0]) on metal cb9a0466f
    • Introduce readdir_r, scandir, pthread_kill, sigsetjmp, etc.. e557058ac
    • Allow more fine-grained control over bare metal page permissions d38700687
    • Make cli commands yoinkable into cosmo shell 3d2d04b25
    • Support Ctrl-Left / Ctrl-Right keystrokes in Bestline
    • Introduce a ParseCidr() API c995838e5

    Fixes and Improvements

    • Make fcntl() locks on Windows work well enough to support SQLite 997ce29dd
    • Make fork/system/popen thread safe 60cb435cb f52f65b2e
    • Fix support for WSL1 platform fc96af058 f44d88707 d6ff4c754 fae0c0286 14d036b68
    • Fix bug: do not initialize IDT & TSS if unneeded (#654)
    • Integrate upstream dash changes into unbourne shell (#656)
    • Import more of the remaining math library routines from Musl e557058ac
    • Make the conformance of libc/isystem/ headers nearly perfect e557058ac
    • Fixed bug where stdio eof wasn't being sticky d5910e267
    • Fixed bug where fseeko() wasn't clearing eof state d5910e267
    • Fix ParseHttpMessage failing to store >2 repeatable headers (#657)
    • Fix a harmless integer overflow in ParseIp() c995838e5
    • Improve cosmo's conformance to libc-test e557058ac
    • Improve lock performance on NetBSD c995838e5
    • Elevate the quality of getrandom() and getentropy() 3f0bcdc3e
    • Make Windows fcntl() and lseek() fixes da8f5009f
    • Windows fork() now restores TLS memory of calling thread e522aa3a0
    • More cosmocc toolchain FOSS compatibility improvements 5af19b7ee
    • Rewrite makedirs() so it doesn't need dynamic memory 0f8914088
    • Rewrite putenv() and friends to conform to POSIX f7ff77d86
    • Permit Linux OFD fcntl() locks under pledge(flock) f7ff77d86
    • Support closefrom() on NetBSD
    • Support tgkill() on FreeBSD

    Breakages

    • Remove underscore prefix from awesome timespec_*() APIs 3f0bcdc3e
    • Rename LINUX to _HOSTLINUX etc. to reduce clashes (#655)
    • Rename rand64() to _rand64() 7ae556463
    Source code(tar.gz)
    Source code(zip)
    cosmopolitan-2.2.tar.gz(61.83 MB)
    cosmopolitan-amalgamation-2.2.zip(7.39 MB)
    cosmopolitan-amalgamation-dbg-2.2.zip(12.15 MB)
    cosmopolitan-amalgamation-rel-2.2.zip(7.38 MB)
    cosmopolitan-amalgamation-tiny-2.2.zip(2.65 MB)
    cosmopolitan-amalgamation-tinylinux-2.2.zip(2.60 MB)
  • 2.1.1(Oct 8, 2022)

    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.

    This release fixes bugs and makes system call wrapper improvements:

    • Fix corner case in Linux stack mappings 3b4fcd8575e2048987721fda130e501877607dfa
    • Implement clock_nanosleep() across platforms and refactor sleeping code to use it.
    • Polyfill futexes on unsupported platforms by polling memory with exponential backoff
    • Imported *NSYNC unit tests and confirmed we're passing them (except for cancellations on Windows)
    • system() now uses our builtin cocmd interpreter which offers a subset of bourne that works on windows and is fast
    • sched_setaffinty() is now explicitly for processes since we now have pthread_setaffinity_np() for threads
    • Numerous improvements to system call documentation, especially when it comes to possible errno results
    • Change accept type to struct sockaddr * (#630)
    • Rewrite brk() and sbrk() 5005f2e44651c8be30b5730398c232c4cdadefce which can be used by tiny apps that don't want to link mmap() and would rather have 4096-byte memory granularity, with the tradeoff of not working on Windows

    We're working to make every Cosmopolitan binary a true operating system by introducing features like VGA support:

    • Fix sys_mmap_metal() for non-MAP_FIXED case (#651)
    • Show "screen of death" on VGA console upon program crash (#650)
    • Add basic character output for VGA graphics mode console (#649

    Other changes:

    • Add imaxdiv, wcscoll, getdtablesize (#639)
    • Fix wcsdup malloc size (#641)
    • Add utime to utime.h (#648)
    Source code(tar.gz)
    Source code(zip)
    cosmopolitan-2.1.1.tar.gz(61.67 MB)
    cosmopolitan-amalgamation-2.1.1.zip(7.20 MB)
    cosmopolitan-amalgamation-dbg-2.1.1.zip(11.54 MB)
    cosmopolitan-amalgamation-rel-2.1.1.zip(7.14 MB)
    cosmopolitan-amalgamation-tiny-2.1.1.zip(2.58 MB)
    cosmopolitan-amalgamation-tinylinux-2.1.1.zip(2.53 MB)
  • redbean-2.1(Oct 8, 2022)

    redbean is an open source webserver in a zip executable that runs on six operating systems. The basic idea is if you want to build a web app that runs anywhere, then you download the redbean.com file, put your .html and .lua files inside it using the zip command, and then you've got a hermetic app you can deploy and share.

    • New unix.mapshared() api that lets you allocate memory that's shared between processes. It returns a module that has atomics and futexes. A demo script has been added that shows how it can be used to serialize a JSON GetPath() hit counter to shared memory.
    • This release fixes a bug with the parsing of space / plus parameters in the Request-URI.
    • Proof of concept of sqlite serialization (#436)
    • Lua's os.execute() function will now use Cosmopolitan's builtin cocmd interpreter, which provides a subset of bourne shell features, with faster performance, and consistent behavior across unixes and windows.
    • Fix re.NOSUB memory error (#645)
    • Update redbean api definitions (#652)
    • Make HTTP message parsing a little faster
    • Permit multiple certs with same common name

    This is the first redbean release announcement that's been shared on GitHub. It only reflects the changes to redbean since 2.0.19. The web page for the 2.0.x release series is at https://redbean.dev/2.0.html which has links at the bottom to pages detailing older releases. For details on features and bug fixes that were introduced during the series over the past several months, please see the cosmo commit log.

    Source code(tar.gz)
    Source code(zip)
    redbean-2.1.com(2.21 MB)
    redbean-2.1.com.dbg(19.72 MB)
    redbean-asan-2.1.com(6.19 MB)
    redbean-demo-2.1.com(2.25 MB)
    redbean-original-2.1.com(622.31 KB)
    redbean-original-tinylinux-2.1.com(328.83 KB)
    redbean-static-2.1.com(1.02 MB)
    redbean-tiny-2.1.com(1.53 MB)
    redbean-unsecure-2.1.com(1.82 MB)
  • pledge-1.8(Oct 8, 2022)

  • 2.1(Sep 20, 2022)

    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.1.tar.gz
    tar xf cosmopolitan-2.1.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.1.zip
    unzip cosmopolitan-amalgamation-2.1.zip
    printf 'main() { printf("hello world\\n"); }\n' >hello.c
    gcc -g -Os -static -nostdlib -nostdinc -fno-pie -no-pie -mno-red-zone -gdwarf-4 \
      -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
    

    Features

    • Introduce POSIX threads support with locking primitives based on *NSYNC
    • Add VGA terminal support on bare metal (see examples/vga.c) 3fdb1c14f1e245d9ea16d72ce0d247d1cba3659a
    • System call portability is now documented at https://justine.lol/cosmopolitan/functions.html
    • Add cosmocc and cosmoc++ scripts which can serve as an open source toolchain 6cc9e08f1b6355381182dd9ff6261b27527c6072
    • Add lchown(), lchmod(), statvfs(), fstatvfs() 5a632cf72d5c6116a5c62ae0b9730476900b4df7
    • Add sigpending() a849a6377130a4ab63ae994f05a833637b7d0082
    • Add getgroups() and setgroups() 4c40c500b82be387a33ad5c65f084198211507f5
    • Implement inet_pton for AF_INET6 d213a481906ce7edf485009ebb486735caada9ed
    • The _gc() garbage collector is now thread safe 0e2b1bfeed2654fa425a70f7d88e5d1306611a6d
    • Use OpenBSD qsort() which is faster (quicksort) and secure (heapsort fallback) d861d2787b0decc5776db8922a68da960db16bc9
    • Add notpossible keyword and _npassert() 0c70e8963db77e4db2ee7de2da3139fa4b558171
    • IPv6 is now polyfilled on non-Linux 0547eabcd6b32cfe0335924e91ca8436fe66d3cc
    • Introduce MODE=fastbuild and shorthand notation m=fastbuild

    Bug Fixes

    • Upgrade to the latest Chromium Zlib. This improves security and performance 224c12f54d58abdcc73cec60ec761814fcc219f3 775944a2d03f3f24357e90394a2bc4df0103bcff
    • Fix out of bounds read in IP address parser 775944a2d03f3f24357e90394a2bc4df0103bcff
    • APE binaries now work better with BusyBox 0305194d9854556e2bbef1fdcfda6e76910b1baf
    • Numerous fixes to bare metal support 3733b43a8fa011331fcb733680d0783dc1321384 8569704c1ddcff3403502d84ca66d65b5f22c347 e0fabd1d497fb3ffcbdb674667812aaf26d84261
    • Fix bug where SIG_IGN and SIG_DFL weren't working as advertised on BSDs c5c4dfcd218d834b94d4a73ab952f65c1a8b93d4
    • Improve quality of raise(), abort(), and tkill() c5c4dfcd218d834b94d4a73ab952f65c1a8b93d4
    • Improve quality of uname(), gethostname(), and getdomainname() b66bd064d8b026696fe1523d699724c0fe7f35fb
    • Improve quality of clock() 12d9e1e12859398c1698fcf073aa0d3c67f31a0c
    • Improve quality of copy_file_range(), sendfile(), splice(), openpty(), closefrom(), close_range(), fadvise() and posix_fadvise() c7a8cd21e90ab84be4caf5bd865ec90f17bd7017 9fa672506738cd210cb819e3fd05d2dd7d3f2997
    • Fix _Thread_local with fork() on Windows bf757c46469a5361fb00c6c3483858242087251f
    • Improve zipos path handling 1ef955c33b3092e62d5d05855b13c1fe6204006a
    • Fix preadv() and pwritev() for old distros 3f4988984183dae5bf8a39b9fcbb8cdf78ce10c7
    • Support fcntl(F_DUPFD_CLOEXEC) on more systems 3f4988984183dae5bf8a39b9fcbb8cdf78ce10c7
    • Fix POSIX advisory locks on Windows 3f4988984183dae5bf8a39b9fcbb8cdf78ce10c7
    • Fix race condition in makedirs() 571c2c3c698f31426c5ef5614745ba11e70e0783
    • Fix pledge() thread kill semantics 1ea01fc9055fae058ce1589593fb8bfbeacb5418
    • Improve open source compatibility b73e35c6fac2960b3a5fb082a712145318e2218b dbf12c30b05e8bffaa73356c229391538fd0b322 55c6297e13b49387708208d86cd0fc5d23e01678
    • Make SIG_DFL and SIG_IGN C++ compatible 8cd4248f7f74e2ea91a8ea22c6d685d5b13a0fcb
    • Discard ignored signals on New Technology 7de2f229a7e9f19074342010d57155d4fa4cc451
    • Fix inability to add some signals to mask on NT 598640864aadfe3bad418bceb9ae2fef3a0c825b
    • Fix issue with ZipOS file descriptors in MODE=asan 3265324e00634e8e9d659ba705da5b0ce88e78ef
    • The virtual memory layout is now more optimized b69f3d2488dbaf9dcc541e699f5b7c09fbf046e0
    • Repository is now buildable by GCC11

    Breaking changes

    • Underscore added to many non-standard APIs to improve open source compatibility 6f7d0cb1c3962f7cb474b04de75df7cd82a3e5d3
    • Windows 7 and Vista support has now been moved to our vista branch 134ffee51900a4d70e8e68b598374856ceec8355
    • Add sys_ prefix to unwrapped system calls to improve open source compatibility aab4ee407299c5282b71a175045aa5c526ed6852
    • Debug symbols now removed from MODE=tiny* builds by default
    • Removed testonly keyword

    Third Party

    • FreeBSD's o//examples/script.com can record and playback terminal screencasts on five OSes 1ad2f530f9c6197dfca199fc67a2296bbaac856e
    • NetBSD's sed command is now available in third_party/sed/
    • The One True Awk is now available in third_party/awk/ and https://justine.lol/awk/

    Community

    • We built an online game (https://ipv4.games/) based on Redbean that handled 600 qps on just 2 vcpu (Loam and https://github.com/shamblesides/turfwar/)
    • We got Actually Portable Perl 96% passing test suites (G4Vi https://github.com/G4Vi/perl5/blob/cosmo/README.cosmo)
    • We got Actually Portable Python 3.11.0rc1 passing 96% test suites (ahgamut https://github.com/ahgamut/cpython/tree/cosmo_py311)
    • We got 176 Actually Portable Rust demo programs to build (ahgamut https://github.com/ahgamut/rust-ape-example)
    Source code(tar.gz)
    Source code(zip)
    cosmopolitan-2.1.tar.gz(61.58 MB)
    cosmopolitan-amalgamation-2.1.zip(7.13 MB)
    cosmopolitan-amalgamation-dbg-2.1.zip(11.47 MB)
    cosmopolitan-amalgamation-rel-2.1.zip(7.07 MB)
    cosmopolitan-amalgamation-tiny-2.1.zip(2.57 MB)
    cosmopolitan-amalgamation-tinylinux-2.1.zip(2.52 MB)
  • 2.0(Aug 19, 2022)

    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 than zip:... when open()'ing assets stored in the PKZIP structure of your executable program. 00611e9b06be11e8af3a05c5d60878377aa2b0bd
    • 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 226aaf354786505e05283adfd52b43b668807336
    • We renamed LOGF to INFOF 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 for int128_t. Functions like bsrmax() are now called bsr128(). 868af3f950c562baa1a73539703c6c78d51adceb
    • We've renamed nothrow to dontthrow and nodiscard is now dontdiscard. 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 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. 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 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. 14e192e5ba820c60fa4aef48c1a646b151723603
    • 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 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
    Source code(tar.gz)
    Source code(zip)
    cosmopolitan-2.0.tar.gz(61.18 MB)
    cosmopolitan-amalgamation-2.0.zip(7.05 MB)
    cosmopolitan-amalgamation-dbg-2.0.zip(12.18 MB)
    cosmopolitan-amalgamation-rel-2.0.zip(7.00 MB)
    cosmopolitan-amalgamation-tiny-2.0.zip(6.66 MB)
    cosmopolitan-amalgamation-tinylinux-2.0.zip(6.49 MB)
  • 1.0(May 17, 2021)

    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.

    Changes

    • Productionize redbean web server bf03b2e6 af59806a 01e6b3ad e56a9d0e 690be544 472b95fe c029e83d
    • Make it possible for APE binaries to modify their own ZIP contents bf03b2e6 daa32d27 b9187061 690be544
    • Introduce OpenExecutable for restoring APE bf03b2e64c1f38f2e20cbd0126dc858d31f9ead4 or alternatively ape-no-modify-self.o da8a08fd58324a87f6ac673b7774512e861fe477
    • Add Fabrice Bellard's JavaScript engine to third party 8f52c0d7 and get it to pass test262 8a915186
    • System calls now return EFAULT in ASAN mode if memory is invalid 690be544da77eb3323858df6562543db2978243d
    • Add SQLite to third party (thanks @ahgamut) #162 221817e5
    • Add sendmsg and recvmsg (thanks @fabriziobertocci) #148
    • Added LaunchBrowser API to redbean (thanks @Rotario) #153
    • Wide character classification now supports UNICODE 1b5a5719
    • Add syslog (thanks @fabriziobertocci) #136
    • Add strxfrm (thanks @ahgamut) #160
    • Add struct ip_mreq (thanks @fabriziobertocci) #143
    • Add MacOS toolchain instructions (thanks @d4tocchini) #163
    • Add 14 missing system call prototypes (thanks @dosisod) #142
    • Improve consts.sh magnums bf03b2e6 b107d2709f15341fb49940bb5ea06126d15749a1 1b5a5719c39b72089e3ba216b49e51a6ddae98ee 690be544da77eb3323858df6562543db2978243d
      • Polyfill POSIX Advisory Locks 690be544
      • Add polyfills for SO_LINGER, SO_RCVTIMEO, and SO_SNDTIMEO 48645651983ca46a31b3e85fb7b7e61500759f52
      • Polyfill TCP_CORK on BSD and XNU using TCP_NOPUSH magnums b107d2709f15341fb49940bb5ea06126d15749a1
    • Fix stdio in cases where it overflows kernel tty buffer b107d2709f15341fb49940bb5ea06126d15749a1
    • Improve backwards compatibility with GNU Make 1f2288be
    • Fix GDB attach on crash w/ OpenBSD msyscall() bf03b2e64c1f38f2e20cbd0126dc858d31f9ead4
    • Remove undefined behaviors b3838173
    • Add TUI paneling example 26ac6871
    • Add netcat clone b107d2709f15341fb49940bb5ea06126d15749a1 48645651983ca46a31b3e85fb7b7e61500759f52
    • Improve rusage accounting apis bf03b2e64c1f38f2e20cbd0126dc858d31f9ead4

    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:

    wget https://justine.lol/cosmopolitan/cosmopolitan-amalgamation-1.0.zip
    unzip cosmopolitan-amalgamation-1.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 \
      -o hello.com.dbg hello.c -fuse-ld=bfd -Wl,-T,ape.lds \
      -include cosmopolitan.h crt.o ape.o cosmopolitan.a
    objcopy -S -O binary hello.com.dbg hello.com
    

    You now have a portable program. Please note that your APE binary will assimilate itself as a conventional resident of your platform after the first run, so it can be fast and efficient for subsequent executions.

    ./hello.com
    bash -c './hello.com'  # zsh/fish workaround (we upstreamed patches)
    

    So if you intend to copy the binary to Windows or Mac then please do that before you run it, not after.

    If you're developing on MacOS you can install the GNU compiler collection for x86_64-elf via homebrew:

    brew install x86_64-elf-gcc
    

    Then in the above scripts just replace gcc and objcopy with x86_64-elf-gcc and x86_64-elf-objcopy to compile your APE binary.

    If you're developing on Windows then you need to download an x86_64-pc-linux-gnu toolchain beforehand. See the Compiling on Windows tutorial. It's needed because the ELF object format is what makes universal binaries possible.

    Cosmopolitan can also be compiled from source on any Linux distro.

    wget https://justine.lol/cosmopolitan/cosmopolitan-1.0.tar.gz
    tar xf cosmopolitan-1.0.tar.gz  # see releases page
    cd cosmopolitan
    make -j8  # should take ~30 seconds
    o//examples/hello.com
    o/third_party/lua/lua.com -e 'print(2 + 2)'
    o/third_party/quickjs/qjs.com -e 'console.log(2+2)'
    echo select 2 + 2 | o/third_party/sqlite3/sqlite3.com
    printf 'GET /404.html\n\n' | o//examples/nc.com redbean.justine.lol 80
    o//tool/viz/life.com
    

    Contributing

    We have automated Travis CI testing. Any pull request you send is going to get feedback in 2 minutes and 16 seconds. That's how long Travis CI takes to test this whole repository, which builds 14,507 objects, 68 libraries, and 461 static executables, 289 of which are test executables which are run too. On a real PC, building and testing everything from scratch takes 34 seconds instead of two minutes. If the hostnames freebsd, openbsd, netbsd, rhel7, rhel5, xnu, win7, and win10 can be ssh'd into, then make test -j8 takes 15 additional seconds to deploy and run all 300 test executables on those operating systems too. See CONTRIBUTING.md for further details.

    Support Vector

    | Platform | Min Version | Circa | | :--- | ---: | ---: | | AMD | K8 Venus | 2005 | | Intel | Core | 2006 | | New Technology | Vista | 2006 | | GNU/Systemd | 2.6.18 | 2007 | | XNU's Not UNIX! | 15.6 | 2018 | | FreeBSD | 12 | 2018 | | OpenBSD | 6.4 | 2018 | | NetBSD | 9.1 | 2020 | | GNU Make | 3.80 | 2010 |

    Source code(tar.gz)
    Source code(zip)
    cosmopolitan-1.0.tar.gz(36.33 MB)
    cosmopolitan-amalgamation-1.0.zip(5.54 MB)
  • 0.3(Mar 29, 2021)

    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.

    This release adds features such as Lua server pages to redbean (which last month became the third most popular "Show HN" thread). There's been a number of performance enhancements, improvements to compatibility, and bug fixes. We also managed to port several high-level languages to Cosmopolitan with passing test suites. This project has also received its first thirty sponsors. Thank you for your support!

    Changes

    • Major improvements to redbean 09bcfa23 4d21cd31 dcbd2b86 a1677d60 3c19b6e3 1753b669
    • Major improvements to stdio da36e7e2 c3ed8d6c aad84161
    • Add socketpair thanks to @fabriziobertocci ca88ce50
    • Numerous bug fixes, thanks to @alisonatwork 9c817290 6cd10376 8a6ac6dd f5da4efc 813e11b9 5d334b9c
    • Add missing math functions, and fix isystem headers, thanks to @dosisod 8a236433 fb7b7c6e
    • Fix APE error if unable to modify self, thanks to @tomberek 0eaad9dd
    • UEFI support 537c2133
    • Support proper %g, %f, and %a float formatting f0641836
    • Add posix_spawn 5ce83b08
    • Make pow() conform to standard definition 8af91bcb 43b2475a

    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:

    wget https://justine.lol/cosmopolitan/cosmopolitan-amalgamation-0.3.zip
    unzip cosmopolitan-amalgamation-0.3.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 \
      -o hello.com.dbg hello.c -fuse-ld=bfd -Wl,-T,ape.lds \
      -include cosmopolitan.h crt.o ape.o cosmopolitan.a
    objcopy -S -O binary hello.com.dbg hello.com
    

    You now have a portable program. Please note that your APE binary will assimilate itself as a conventional resident of your platform after the first run, so it can be fast and efficient for subsequent executions.

    ./hello.com
    bash -c './hello.com'  # zsh/fish workaround (we upstreamed a patch)
    

    So if you intend to copy the binary to Windows or Mac then please do that before you run it, not after.

    If you're developing on Windows or MacOS then you need to download an x86_64-pc-linux-gnu toolchain beforehand. See the Compiling on Windows tutorial. It's needed because the ELF object format is what makes universal binaries possible.

    Cosmopolitan can also be compiled from source on any Linux distro.

    wget https://justine.lol/cosmopolitan/cosmopolitan-0.3.tar.gz
    tar xf cosmopolitan-0.3.tar.gz  # see releases page
    cd cosmopolitan
    make -j16
    o//examples/hello.com
    find o -name \*.com | xargs ls -rShal | less
    

    Contributing

    We now have automated Travis CI testing. That means any pull request you send is going to get feedback in two minutes, which is how long it takes to build and test this whole repository inside a tiny VM.

    Support Vector

    | Platform | Min Version | Circa | | :--- | ---: | ---: | | AMD | K8 Venus | 2005 | | Intel | Core | 2006 | | New Technology | Vista | 2006 | | GNU/Systemd | 2.6.18 | 2007 | | XNU's Not UNIX! | 15.6 | 2018 | | FreeBSD | 12 | 2018 | | OpenBSD | 6.4 | 2018 | | NetBSD | 9.1 | 2020 |

    Source code(tar.gz)
    Source code(zip)
    cosmopolitan-0.3.tar.gz(32.96 MB)
    cosmopolitan-amalgamation-0.3.zip(5.55 MB)
  • 0.2(Feb 10, 2021)

    • VSCode support #40
    • Your executables now run on NetBSD too b2cd58a3226627179f58807bd333fbe0606ff489 23ae9dfceb6f657862f00e674a8e4dc357a9d24d
    • You can now compile your programs on BSD using the amalgamated release binaries
    • You can now build Cosmopolitan from source using LLVM e75ffde09e2db6abea0c0658d1336ec5ec57c342
    • You can now tune the source build to cherry pick which operating systems you want to support at compile time. By default, all seven are supported. To change that, simply redefine make CPPFLAGS=-DSUPPORT_VECTOR=0xFF which is a bitset defined by libc/dce.h. For example, -DSUPPORT_VECTOR=1 will ask Cosmopolitan's Makefile to produce conventional ELF binaries that only run on Linux.
    • Numerous bug fixes
    Source code(tar.gz)
    Source code(zip)
    cosmopolitan-0.2.tar.gz(33.42 MB)
    cosmopolitan-amalgamation-0.2.zip(5.55 MB)
  • 0.1.2(Jan 30, 2021)

  • 0.1.1(Jan 29, 2021)

  • 0.1(Jan 29, 2021)

    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 to output a POSIX-approved polyglot format that runs natively on Linux + Mac + Windows + FreeBSD + OpenBSD + BIOS with the best possible performance and the tiniest footprint imaginable.

    Changes

    This is our first official release. You may remember the pre-alpha demo that went viral on Hacker News last month. There's been a considerable number of bug fixes since then. Here's a curated list of what happened:

    • Fix Z-shell (pending upstream) https://github.com/jart/zsh/commit/94a4bc14bb2e415ec3d10cf716512bd3e0d99f48
    • Fix FreeBSD Almquist Shell #23 in https://github.com/freebsd/freebsd-src/commit/e0f5c1387df23c8c4811f5b24a7ef6ecac51a71a thanks @jillest and Austin Group!
    • Fix metal bugs so executables boot in qemu-system-x86_64 #20
    • Fix Windows 7 compatibility #19
    • Fix memcpy on sandybridge and ivybridge 8fa47ace
    • Fix RHEL5 and RHEL7 compatibility 45b72485 565edd05 #24
    • Fix link order in cosmopolitan.a 9f68d6eee95f04f0ff146c4214c021beee551e98
    • Fix opendir() on XNU and OpenBSD 45b72485ad102206574629cf278199d050fa7bf7
    • Fix system() on NT and improve vfork() / execve() implementation 45b72485ad102206574629cf278199d050fa7bf7
    • Fix system calls with 7+ arguments 45b72485ad102206574629cf278199d050fa7bf7
    • Fix OpenBSD truncate() and ftruncate() thunk typo 45b72485ad102206574629cf278199d050fa7bf7
    • Fix Windows when FDs exceeds OPEN_MAX 45b72485ad102206574629cf278199d050fa7bf7
    • Make long double long again on Windows 45b72485ad102206574629cf278199d050fa7bf7
    • Use copy_file_range on FreeBSD 13+ 45b72485ad102206574629cf278199d050fa7bf7
    • Create integrated assembler for chibicc 81ef1627
    • Add popen(), pclose(), brk(), sbrk() d7ac16a9ed56ebdc70481f4a802265ea15619894
    • Add timingsafe_memcmp #13

    Getting Started

    Here's how to get started with the freestanding hermetically-sealed monolithic source repository:

    tar xf cosmopolitan-0.1.tar.gz
    cd cosmo
    make -j12
    o//examples/hello.com
    

    Here's how to get started with the amalgamated binaries, which let you bring your own build system:

    unzip cosmopolitan-amalgamated-0.1.zip
    echo 'main() { printf("hello world\n"); }' >hello.c
    gcc -g -O -static -fno-pie -no-pie -mno-red-zone -nostdlib -nostdinc \
      -o hello.com.dbg hello.c -Wl,--gc-sections -Wl,-z,max-page-size=0x1000 -fuse-ld=bfd \
      -Wl,-T,ape.lds -include cosmopolitan.h crt.o ape.o cosmopolitan.a
    objcopy -SO binary hello.com.dbg hello.com
    ./hello.com
    

    Please note we assume that you compile your programs on Linux. If you want to compile your binaries on Windows, then please read our new tutorial on how you can use the x86_64-linux-gnu static exes we created. See https://justine.lol/cosmopolitan/windows-compiling.html and https://justine.lol/cosmopolitan/windows-debugging.html If you use XNU then we'll be sharing a prebuilt Linux toolchain for you too soon.

    Quality Assurance

    All 196 tests passing on the following systems is confirmed:

    • Alpine Linux 5.4.43
    • Debian Linux 10 Buster 4.19.0
    • Red Hat Enterprise Linux 7 3.10.0
    • Red Hat Enterprise Linux 5 2.6.18
    • XNU 19.6.0
    • Windows 7
    • Windows 10
    • FreeBSD 12.1
    • OpenBSD 6.8

    cosmopolitan-0 1

    Thanks

    Thanks go out to @jillest, @probonopd, @nicholatian, @vshymanskyy, @PerfectProductions, @JesseRMeyer, @nikhedonia, @tpoindex, @maroneze, @zhengshuxin, @Phate6660, @Theldus, @severak, @paususe, @rhdxmr, @tankf33der, @nuclight, @nsauzede, @gavinhoward, and many others who've helped make this release possible.

    Source code(tar.gz)
    Source code(zip)
    cosmopolitan-0.1.tar.gz(33.60 MB)
    cosmopolitan-amalgamation-0.1.zip(5.55 MB)
Owner
Justine Tunney
Justine Tunney
sampctl-runner: Easy way to build and run package..

sampctl-runner Easy way to build and run package.. Usage Just enter the name of the repository from pawn.json and let the program do other things.. Ex

Emmett 1 Apr 17, 2022
A python library to run metal compute kernels on MacOS

metalcompute for Python A python library to run metal compute kernels on MacOS Usage Example execution from M1-based Mac running MacOS 12.0: > ./build

Andrew Baldwin 21 Nov 7, 2022
A run-time C++ library for working with units of measurement and conversions between them and with string representations of units and measurements

Units What's new Some of the CMake target names have changed in the latest release, please update builds appropriately Documentation A library that pr

Lawrence Livermore National Laboratory 111 Nov 29, 2022
Unity project with an example on how to run the depthai library in Android.

depthai-android-unity-example Unity project (built with Unity 2020.3.25f1) with an example on how to run the depthai library in Android. Important Thi

Ibai Gorordo 18 Mar 13, 2022
Libft is an individual project at 42 that requires us to re-create some standard C library functions including some additional ones that can be used later to build a library of useful functions for the rest of the program.

Libft is an individual project at 42 that requires us to re-create some standard C library functions including some additional ones that can be used later to build a library of useful functions for the rest of the program.

Paulo Rafael Ramalho 0 Apr 5, 2022
Combining Sealighter with unpatched exploits to run the Threat-Intelligence ETW Provider

Sealighter-TI Combining Sealighter with unpatched exploits and PPLDump to run the Microsoft-Windows-Threat-Intelligence ETW Provider without a signed

pat_h/to/file 56 Nov 17, 2022
An attempt to run fcitx5 on Android

fcitx5-android-poc An attempt to run fcitx5 on Android. Project status It can build, run, and print to stdout. Build Dependencies Android SDK Platform

null 407 Nov 27, 2022
Run-time program generator embedded in C++

Run-time program generator embedded in C++

Z Guan 25 Aug 5, 2022
anthemtotheego 392 Dec 1, 2022
Run Linux programs on DOS

A WSL alternative for users who prefer an MS-DOS environment. DOS Subsystem for Linux integrates a real Linux environment into MS-DOS systems, allowing users to make use of both DOS and Linux applications from the DOS command prompt.

Hailey Somerville 1.3k Nov 26, 2022
Project #1: Run-length Encoding (Computer Architecture, Fall 2021)

4190.308 Computer Architecture (Fall 2021) Project #1: Run-length Encoding Due: 11:59PM, September 26 (Sunday) Introduction In this project, you need

SNU Systems Software & Architecture Laboratory 7 Sep 19, 2022
Realtime Micro Kernel -- Event-driven Run-to-Completion RTOS with Active Objects, Timed Events, Memory Pools, and Message Queues

Realtime Micro Kernel Features Active Objects Message queues Variable sized, custom messages Periodic and single timed events Memory pools Supported P

null 3 Nov 7, 2022
Phan Sang 13 Nov 12, 2022
Patch for Sierra's PowerChess to run on newer Windows Versions >9x

What is it? I recently stumbled upon the following thread: https://sourceforge.net/p/dxwnd/discussion/general/thread/98dd46dfc6/?page=0 Some people we

null 2 Mar 27, 2022
A utility to run ELF files in memory.

execelf - A utility to execute ELF files in memory. execelf is small utility for running ELF files in memory, without touching the disk! Installation

null 11 Nov 21, 2022
Purity toolsHades A HIDS is designed run on Windows

方案:   x64内核探针粗糙分为两类技术方案:第一种基于Intel-x/d虚拟化技术,绕过PG保护做花式Hook,功能强大-系统无痕,第二种基于微型过滤框架和注册回调,兼容性好/快速开发/接口完善。   该项目采用过滤驱动+注册回调,这种方案中规中矩。后续可能会集成VT接口,但是支持有限,优先支持

null 95 Nov 27, 2022
PikaScript is an ultra-lightweight Python engine with zero dependencies and zero-configuration, that can run with 4KB of RAM (such as STM32G030C8 and STM32F103C8), and is very easy to deploy and expand.

PikaScript 中文页| Star please~ 1. Abstract PikaScript is an ultra-lightweight Python engine with zero dependencies and zero-configuration, that can run

Lyon 891 Nov 24, 2022
Run statically-compiled WebAssembly apps on any embedded platform

embedded-wasm-apps Run native, statically-compiled apps on any platform, using WebAssembly. Examples include AssemblyScript, Rust, C/C++, TinyGo, Zig,

Wasm3 Labs 111 Nov 18, 2022
A Geometry Dash mod that lets you select the screen to run the game on

Screen Selector A mod that lets you select the screen to run Geometry Dash on Fully compatible with Mega Hack v6 (except the "Fullscreen" and "Borderl

ConfiG 8 Jun 3, 2022