94afa982c3
Here's why we got those `Killed: 11` failures on MacOS after modifying the contentns of the redbean.com executable. If you were inserting a small file, such as a HelloWorld.html file, then InfoZIP might have decreased the size of the executable to less than what the Mach-O section had been expecting. That's because when zipobj.com put things like time zone data in the executable, it aligned each zip file entry on a 64-byte boundary, simply for the sake of readability in binary dumps. But when InfoZIP edited the file it would rewrite every entry using ZIP's usual 2-byte alignment. Thus causing shrinkage. The solution was to reconfigure the linker script so that zip file bits that get put into the executable at link-time, such as timezone data, aren't officially part of the executable image, i.e. we don't want the operating system to load that part. The original decision to put the linked zip files into the .data section was mostly made so that when the executable was run in its .com.dbg form it would still have the zip entries be accessible, even though there was tons of GNU debug data following the central directory. We're not going to be able to do that. The .com executable should be the canonical executable. We have really good tools for automatically attaching and configuring GDB correctly with debug symbols even when the .com is run. We'll have to rely on those in cases where zip embedding is used. See #53 See #54 See #68 |
||
---|---|---|
.github | ||
.vscode | ||
ape | ||
build | ||
dsp | ||
examples | ||
libc | ||
net | ||
test | ||
third_party | ||
tool | ||
usr/share | ||
.clang-format | ||
.gitignore | ||
LICENSE | ||
Makefile | ||
README.md |
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:
wget https://justine.lol/cosmopolitan/cosmopolitan-amalgamation-0.2.zip
unzip cosmopolitan-amalgamation-0.2.zip
printf 'main() { printf("hello world\\n"); }\n' >hello.c
gcc -g -O -static -nostdlib -nostdinc -fno-pie -no-pie -mno-red-zone \
-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
./hello.com
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.2.tar.gz
tar xf cosmopolitan-0.2.tar.gz # see releases page
cd cosmopolitan-0.2
make -j16
o//examples/hello.com
find o -name \*.com | xargs ls -rShal | less