Get codebase completely working with LLVM

You can now build Cosmopolitan with Clang:

    make -j8 MODE=llvm
    o/llvm/examples/hello.com

The assembler and linker code is now friendly to LLVM too.
So it's not needed to configure Clang to use binutils under
the hood. If you love LLVM then you can now use pure LLVM.
This commit is contained in:
Justine Tunney 2021-02-08 09:19:00 -08:00
parent 0e36cb3ac4
commit e75ffde09e
4528 changed files with 7776 additions and 11640 deletions

View file

@ -3,17 +3,16 @@
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
if CLANG=$(command -v clang); then
$COMPILE $CLANG \
$CLANG \
-o o/$MODE/test/libc/release/smokeclang.com.dbg \
-Os \
-Wall \
-Werror \
-static \
-no-pie \
-fno-pie \
-nostdlib \
-nostdinc \
-mno-red-zone \
-Wl,--gc-sections \
-Wl,-z,max-page-size=0x1000 \
-Wl,-T,o/$MODE/ape/ape.lds \
-include o/cosmopolitan.h \
test/libc/release/smoke.c \
@ -22,3 +21,5 @@ if CLANG=$(command -v clang); then
o/$MODE/cosmopolitan.a || exit
o/$MODE/test/libc/release/smokeclang.com.dbg || exit
fi
touch o/$MODE/test/libc/release/clang.ok

18
test/libc/release/emulate.sh Executable file
View file

@ -0,0 +1,18 @@
#!/bin/sh
# smoke test userspace binary emulation
CMD="o/$MODE/tool/build/blinkenlights.com.dbg o/$MODE/examples/hello.com"
printf '%s\n' "$CMD" >&2
if OUTPUT="$($CMD)"; then
if [ x"$OUTPUT" = x"hello world" ]; then
touch o/$MODE/test/libc/release/emulate.ok
exit 0
else
printf '%s\n' "error: $CMD printed wrong output: $OUTPUT" >&2
exit 1
fi
else
RC=$?
printf '%s\n' "error: $CMD failed: $RC" >&2
exit $RC
fi

18
test/libc/release/metal.sh Executable file
View file

@ -0,0 +1,18 @@
#!/bin/sh
# smoke test booting on bare metal and printing data to serial uart
CMD="o/$MODE/tool/build/blinkenlights.com.dbg -r o/$MODE/examples/hello.com"
printf '%s\n' "$CMD" >&2
if OUTPUT="$($CMD)"; then
if [ x"$OUTPUT" = x"hello world" ]; then
touch o/$MODE/test/libc/release/metal.ok
exit 0
else
printf '%s\n' "error: $CMD printed wrong output: $OUTPUT" >&2
exit 1
fi
else
RC=$?
printf '%s\n' "error: $CMD failed: $RC" >&2
exit $RC
fi

View file

@ -3,11 +3,13 @@ int main(int argc, char *argv[]) {
char *s;
FILE *f;
s = strdup(argv[0]);
s[0] = 'Z';
f = fopen("/dev/null", "w");
fprintf(f, "hello world %d %s\n", argc, s);
fclose(f);
rc = system("exit 42");
CHECK_NE(-1, rc);
CHECK(WIFEXITED(rc));
CHECK_EQ(42, WEXITSTATUS(rc));
free(s);
return 0;

View file

@ -11,7 +11,7 @@ o/$(MODE)/test/libc/release/cosmopolitan.zip: \
o/$(MODE)/test/libc/release/smoke.com: \
o/$(MODE)/test/libc/release/smoke.com.dbg
@objcopy -SO binary $< $@
@$(COMPILE) $(OBJCOPY) -S -O binary $< $@
o/$(MODE)/test/libc/release/smoke.com.dbg: \
test/libc/release/smoke.c \
@ -29,8 +29,6 @@ o/$(MODE)/test/libc/release/smoke.com.dbg: \
-nostdlib \
-nostdinc \
-mno-red-zone \
-Wl,--gc-sections \
-Wl,-z,max-page-size=0x1000 \
-Wl,-T,o/$(MODE)/ape/ape.lds \
-include o/cosmopolitan.h \
test/libc/release/smoke.c \
@ -40,7 +38,7 @@ o/$(MODE)/test/libc/release/smoke.com.dbg: \
o/$(MODE)/test/libc/release/smokecxx.com: \
o/$(MODE)/test/libc/release/smokecxx.com.dbg
@objcopy -SO binary $< $@
@$(COMPILE) $(OBJCOPY) -S -O binary $< $@
o/$(MODE)/test/libc/release/smokecxx.com.dbg: \
test/libc/release/smokecxx.cc \
@ -58,8 +56,6 @@ o/$(MODE)/test/libc/release/smokecxx.com.dbg: \
-nostdlib \
-nostdinc \
-mno-red-zone \
-Wl,--gc-sections \
-Wl,-z,max-page-size=0x1000 \
-Wl,-T,o/$(MODE)/ape/ape.lds \
-include o/cosmopolitan.h \
test/libc/release/smokecxx.cc \
@ -84,8 +80,6 @@ o/$(MODE)/test/libc/release/smokeansi.com.dbg: \
-nostdlib \
-nostdinc \
-mno-red-zone \
-Wl,--gc-sections \
-Wl,-z,max-page-size=0x1000 \
-Wl,-T,o/$(MODE)/ape/ape.lds \
-include o/cosmopolitan.h \
test/libc/release/smoke.c \
@ -93,7 +87,7 @@ o/$(MODE)/test/libc/release/smokeansi.com.dbg: \
o/$(MODE)/ape/ape.o \
o/$(MODE)/cosmopolitan.a
o/$(MODE)/test/libc/release/smokeclang.ok: \
o/$(MODE)/test/libc/release/clang.ok: \
test/libc/release/clang.sh \
test/libc/release/smoke.c \
o/cosmopolitan.h \
@ -103,6 +97,18 @@ o/$(MODE)/test/libc/release/smokeclang.ok: \
o/$(MODE)/cosmopolitan.a
@$<
o/$(MODE)/test/libc/release/metal.ok: \
test/libc/release/metal.sh \
o/$(MODE)/examples/hello.com \
o/$(MODE)/tool/build/blinkenlights.com.dbg
@$<
o/$(MODE)/test/libc/release/emulate.ok: \
test/libc/release/emulate.sh \
o/$(MODE)/examples/hello.com \
o/$(MODE)/tool/build/blinkenlights.com.dbg
@$<
.PHONY: o/$(MODE)/test/libc/release
o/$(MODE)/test/libc/release: \
o/$(MODE)/test/libc/release/smoke.com \
@ -111,4 +117,6 @@ o/$(MODE)/test/libc/release: \
o/$(MODE)/test/libc/release/smokecxx.com.runs \
o/$(MODE)/test/libc/release/smokeansi.com \
o/$(MODE)/test/libc/release/smokeansi.com.runs \
o/$(MODE)/test/libc/release/smokeclang.ok
o/$(MODE)/test/libc/release/clang.ok \
o/$(MODE)/test/libc/release/emulate.ok \
o/$(MODE)/test/libc/release/metal.ok