Compare commits

..

12 Commits

15 changed files with 809 additions and 249 deletions

View File

@ -0,0 +1,26 @@
name: Build WASM Base Docker Image
on:
push:
branches: [disabled]
# branches: [main]
# paths:
# - ".gitea/workflows/wasm-docker.yaml"
# - "wasm-base.dockerfile"
jobs:
wasm-docker:
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Login to container registry
uses: docker/login-action@v3
with:
registry: gitea.vps.chriphost.de
username: ${{ secrets.CONTAINER_REGISTRY_USER }}
password: ${{ secrets.CONTAINER_REGISTRY_TOKEN }}
- name: Build WASM Base Docker Image
run: docker build --file wasm-base.dockerfile --tag gitea.vps.chriphost.de/christoph/wasm-base:latest .
- name: Push WASM Base Docker Image
run: docker push gitea.vps.chriphost.de/christoph/wasm-base:latest

2
.gitignore vendored
View File

@ -1 +1,3 @@
examples/build-*/
/examples/bochslog.txt
/bochslog.txt

View File

@ -1,11 +1,20 @@
docker:
docker build -t wasm-base -f wasm-base.dockerfile . --build-arg CACHE_DATE="$(shell date)"
docker build --progress=plain -t gitea.vps.chriphost.de/christoph/wasm-base:latest -f wasm-base.dockerfile . --build-arg CACHE_DATE="$(shell date)"
run:
docker run --rm -it wasm-base:latest /usr/bin/fish
docker run --rm -it gitea.vps.chriphost.de/christoph/wasm-base:latest /usr/bin/fish
run-external:
docker run --rm -it -v "./examples:/home/ubuntu/examples" wasm-base:latest /usr/bin/fish
docker run --rm -it -v "./examples:/home/ubuntu/examples" gitea.vps.chriphost.de/christoph/wasm-base:latest /usr/bin/fish
bochs:
nix shell nixpkgs#bochs --command sh -c "bochs -f ./examples/arch/bochs/bochsrc-host.txt -q"
bochs-host:
nix shell nixpkgs#bochs --command sh -c "bochs -q -f ./examples/arch/bochs/bochsrc-host.txt -q"
qemu-host:
qemu-system-i386 -drive file=./examples/build-bochs/sum/system.iso,media=cdrom -boot d -m 32 -S -s
gdb-host:
nix shell nixpkgs#gdb --command gdb ./examples/build-bochs/sum/system.elf -ex "set substitute-path build-bochs ./examples/build-bochs" -ex "target remote localhost:1234" -ex "break os_main"
radare:
radare2 -AA -c "s dbg.os_main; pdf" ./examples/build-bochs/sum/system.elf

View File

@ -1,17 +1,6 @@
ARCH ?= bochs
BUILD_DIR := build-${ARCH}
FAIL_BIN ?= /home/fail/bin
FAIL_SERVER ?= ${FAIL_BIN}/generic-experiment-server
FAIL_TRACE ?= ${FAIL_BIN}/generic-tracing-client
FAIL_INJECT ?= ${FAIL_BIN}/generic-experiment-client
FAIL_DUMP ?= ${FAIL_BIN}/dump-trace
FAIL_IMPORT ?= ${FAIL_BIN}/import-trace --enable-sanitychecks
FAIL_PRUNE ?= ${FAIL_BIN}/prune-trace
BOCHS_RUNNER ?= ${FAIL_BIN}/bochs-experiment-runner.py
RESULT_BROWSER ?= ${FAIL_BIN}/resultbrowser.py
EXPERIMENTS := $(patsubst %.c,%,$(shell echo *.c))
BUILD_DIR := build-${ARCH}
EXPERIMENTS := $(patsubst %.c,%,$(shell echo *.c))
include arch/${ARCH}.mk
@ -25,42 +14,39 @@ help:
@echo "Current Configuartion"
@echo " ARCH=${ARCH}"
clean:
rm -f *.wasm
rm -f *.aot
rm -f *_wasm.c
rm -f *.d
rm -f *.o
rm -f embed/*_host.c
rm -f *_host.elf
rm -rf ${BUILD_DIR}
# rm -f *.wasm
# rm -f *.aot
# rm -f *_wasm.c
# rm -f *.d
# rm -f *.o
# rm -f embed/*_host.c
# rm -f *_host.elf
rm -rf ${BUILD_DIR}/*
clean-%:
rm -rf ${BUILD_DIR}/$(patsubst clean-%,%,$@)
contrib/clean-db '${ARCH}/$(patsubst clean-%,%,$@)'
build-%:
@echo "****************************************************************\n\
* The next step is to trace a golden run. The golden run executes the\n\
* system-under-test (SUT) within the emulator. A trace file is \n\
* produced and saved as: ${BUILD_DIR}/main/trace.pb\n\
*\n\
* $ make trace-$(patsubst build-%,%,$@)\n\
****************************************************************"
* The next step is to trace a golden run. The golden run executes the\n \
* system-under-test (SUT) within the emulator. A trace file is \n \
* produced and saved as: ${BUILD_DIR}/main/trace.pb\n \
*\n \
* $ make trace-$(patsubst build-%,%,$@)\n \
****************************************************************"
trace-%:
@echo "****************************************************************\n\
* The trace is now generated. It can be viewed with\n\
*\n\
* $ make dump-$(patsubst trace-%,%,$@)\n\
*\n\
* Next, we have to import the trace into the database\n\
*\n\
* $ make import-$(patsubst trace-%,%,$@)\n\
****************************************************************"
* The trace is now generated. It can be viewed with\n \
*\n \
* $ make dump-$(patsubst trace-%,%,$@)\n \
*\n \
* Next, we have to import the trace into the database\n \
*\n \
* $ make import-$(patsubst trace-%,%,$@)\n \
****************************************************************"
dump-%: ${BUILD_DIR}/%/trace.pb
${FAIL_DUMP} $(shell dirname $<)/trace.pb
@ -75,35 +61,31 @@ ${HOME}/.my.cnf:
import-%: import-arch-%
@echo "****************************************************************\n\
* The golden run sits now within the MySQL database. If you are interested,\n\
* use the 'mysql' command to inspect the curent state of the DB. The tables\n\
* trace, fsppilot, and fspgroup are of special interest.\n\
*\n\
* Next, we have to run the campaign sever and the injection client\n\
*\n\
* $ make server-$(patsubst import-%,%,$@) &\n\
* $ make client-$(patsubst import-%,%,$@) \n\n\
* Afterwards, the results can be viewd with\n\
* $ make result-$(subst import-,,$@)\n\
****************************************************************"
server-%:
${FAIL_SERVER} -v ${ARCH}/$(subst server-,,$@) -b %
* The golden run sits now within the MySQL database. If you are interested,\n \
* use the 'mysql' command to inspect the curent state of the DB. The tables\n \
* trace, fsppilot, and fspgroup are of special interest.\n \
*\n \
* Next, we have to run the campaign sever and the injection client\n \
*\n \
* $ make server-$(patsubst import-%,%,$@) &\n \
* $ make client-$(patsubst import-%,%,$@) \n\n \
* Afterwards, the results can be viewd with\n \
* $ make result-$(subst import-,,$@)\n \
****************************************************************"
result-%:
@echo "select variant, benchmark, resulttype, sum(t.time2 - t.time1 + 1) as faults\
FROM variant v \
JOIN trace t ON v.id = t.variant_id \
JOIN fspgroup g ON g.variant_id = t.variant_id AND g.instr2 = t.instr2 AND g.data_address = t.data_address\
JOIN result_GenericExperimentMessage r ON r.pilot_id = g.pilot_id \
JOIN fspgroup g ON g.variant_id = t.variant_id AND g.instr2 = t.instr2 AND g.data_address = t.data_address \
JOIN result_GenericExperimentMessage r ON r.pilot_id = g.pilot_id \
JOIN fsppilot p ON r.pilot_id = p.id \
WHERE v.variant = \"${ARCH}/$(patsubst result-%,%,$@)\"\
WHERE v.variant = \"${ARCH}/$(patsubst result-%,%,$@)\" \
GROUP BY v.id, resulttype \
ORDER BY variant, benchmark, resulttype;" |mysql -t
resultbrowser:
${RESULT_BROWSER} --host=0.0.0.0 --port=5000
# Do never remove implicitly generated stuff
.SECONDARY:

View File

@ -1,86 +0,0 @@
# This makefile embeds an application compiled to WASM into a native C program.
# The WASM module will be loaded by the WASM runtime.
# Paths
WAMR_ROOT := /opt/wamr
WAMRC := /opt/wamr-wamrc/wamrc
IWASM := /opt/wamr-iwasm/iwasm
WAMRC_LIB := /opt/wamr-libvmlib
IWASM_LIB := /opt/wamr-libiwasm
WASI_ROOT := /opt/wasi-sdk
WASI_CC := $(WASI_ROOT)/bin/clang
WASI_CFLAGS := --target=wasm32-wasi \
--sysroot=$(WASI_ROOT)/share/wasi-sysroot \
-O0 -g -Wall
# Embedding
EMBED_CC := gcc
EMBED_INCL := -I$(WAMR_ROOT)/core/iwasm/include \
-I$(WAMR_ROOT)/core/iwasm/common \
-I$(WAMR_ROOT)/core/shared/platform/linux \
-I$(WAMR_ROOT)/core/shared/utils \
-I$(WAMR_ROOT)/core/shared/utils/uncommon
EMBED_SOURCES := $(WAMR_ROOT)/core/shared/utils/uncommon/bh_read_file.c # Not used when reading from buffer
EMBED_CFLAGS := -O0 -g -Wall $(EMBED_INCL)
AOT_LDFLAGS := -Wl,-rpath,$(WAMRC_LIB)
AOT_LDLIBS := -L$(WAMRC_LIB) -lvmlib -lm
INTER_LDFLAGS := -Wl,-rpath,$(IWASM_LIB)
INTER_LDLIBS := -L$(IWASM_LIB) -liwasm -lm
XXD := busybox xxd
# Files
SRCS := $(wildcard *.c)
WASMS := $(SRCS:.c=.wasm)
CWASMS := $(SRCS:.c=_wasm.c)
AOTS := $(SRCS:.c=.aot)
OBJS := $(SRCS:.c=.o)
DEPS := $(SRCS:.c=.d)
HOSTS := $(SRCS:.c=_host.elf)
.PHONY: all build-wasms build-aots build-cwasms build-hosts clean
all: build-wasms build-aots build-cwasms build-hosts
# Compile to wasm bytecode using wasi-sdk
build-wasms: $(WASMS)
%.wasm: %.c
$(WASI_CC) $(WASI_CFLAGS) $< -o $@
# Compile ahead-of-time module using wamrc
build-aots: $(AOTS)
%.aot: %.wasm
$(WAMRC) -o $@ $<
# Convert the .aot files to C-style arrays (to embed them into the resulting host binary)
build-cwasms: $(CWASMS)
%_wasm.c: %.aot
$(XXD) -i $< > $@
# Compile the host that will load and run the compiled wasm module
# The compiled wasm module is embedded as C-style array
build-hosts: $(HOSTS)
# The C-style array is called %_aot, e.g. test_aot
# We have to modify the host to refer to that with the correct name
%_host.elf: %_wasm.c
cp embed/host.c embed/$*_host.c
sed -i \
-e "s@__WASM_ARRAY_FILE__@../$*_wasm.c@g" \
-e "s@__WASM_ARRAY__@$*_aot@g" \
-e "s@__WASM_ARRAY_LEN__@$*_aot_len@g" \
embed/$*_host.c
$(EMBED_CC) $(EMBED_CFLAGS) embed/$*_host.c -o $@ $(INTER_LDFLAGS) $(INTER_LDLIBS)
clean:
rm -f *.wasm
rm -f *.aot
rm -f *_wasm.c
rm -f *.d
rm -f *.o
rm -f embed/*_host.c
rm -f *_host.elf

View File

@ -1,45 +1,34 @@
# C -> WASM
WASI_ROOT := /opt/wasi-sdk
WASI_CC := ${WASI_ROOT}/bin/clang
WASI_CFLAGS := --target=wasm32 \
--sysroot=${WASI_ROOT}/share/wasi-sysroot \
-z stack-size=4096 \
-O0 -nostdlib \
-Wl,--no-entry \
-Wl,--initial-memory=65536 \
-Wl,--export-all \
-Wl,--export=__heap_base \
-Wl,--export=__data_end
# WASM -> Baremetal
WAMR := /opt/wamr
IWASM_LIB := /opt/wamr-libiwasm
CC := gcc
# NOTE: When compiling I get "error: bp cannot be used in asm here"
# I could remove "ebp" from the clobber list (ARCH_ASM_CLOBBER_ALL) or
# use the -fomit-frame-pointer flag to tell gcc it shouldn't rely on ebp for enter/leave...
CFLAGS := -I. -O0 -m32 -ffunction-sections -std=c11 -fomit-frame-pointer
LDFLAGS = -Wl,-T linker.ld $^ -Wl,--build-id=none -static -nostdlib -m32 \
-Wl,-rpath,${IWASM_LIB} -L${IWASM_LIB} -liwasm -lgcc
INCL := -I${WAMR}/core/iwasm/include \
-I${WAMR}/core/shared/utils \
-I${WAMR}/core/shared/platform/baremetal
WAMRC := /opt/wamr-wamrc/wamrc
WAMRCFLAGS := --target=i386 --format=object
XXD := busybox xxd
WASI_ROOT := /opt/wasi-sdk
WAMR := /opt/wamr
# -O3 generates more code than -O2 (unrolling/inlining etc.)
OPT := -O2
################################################################
# C -> WASM
WASI_CC := ${WASI_ROOT}/bin/clang
WASI_CFLAGS := \
--target=wasm32 \
--sysroot=${WASI_ROOT}/share/wasi-sysroot \
-z stack-size=4096 \
-O0 \
-nostdlib \
-Wl,--no-entry \
-Wl,--export-all \
-Wl,--no-gc-sections \
-Wl,--initial-memory=65536 \
-Wl,--export=__heap_base \
-Wl,--export=__data_end
${BUILD_DIR}/%/module.wasm: %.c
mkdir -p $(shell dirname $@)
${WASI_CC} ${WASI_CFLAGS} $< -o $@
################################################################
# WASM -> Native Object File
# ${BUILD_DIR}/%/system.o: ${BUILD_DIR}/%/module.wasm
# ${WAMRC} ${WAMRCFLAGS} -o ${BUILD_DIR}/$*/system.o ${BUILD_DIR}/$*/module.wasm
# ${WAMRC} --target=i386 --format=object -o ${BUILD_DIR}/$*/system.o ${BUILD_DIR}/$*/module.wasm
#
# ${BUILD_DIR}/startup.o: arch/bochs/startup.s
# ${CC} $< ${CFLAGS} -c -o $@
@ -47,32 +36,179 @@ ${BUILD_DIR}/%/module.wasm: %.c
# ${BUILD_DIR}/%/system.elf: ${BUILD_DIR}/%/system.o ${BUILD_DIR}/startup.o
# ${CC} ${LDFLAGS} -o $@
################################################################
# WASM -> AOT -> Loaded by Runtime
# WASM -> AOT
WAMRC := /opt/wamr-wamrc/wamrc
WAMRCFLAGS := \
--target=i386 \
--cpu=generic \
--opt-level=0
${BUILD_DIR}/%/module.aot: ${BUILD_DIR}/%/module.wasm
${WAMRC} -o $@ $<
${WAMRC} ${WAMRCFLAGS} -o $@ $<
XXD := busybox xxd
${BUILD_DIR}/%/module_wasm.c: ${BUILD_DIR}/%/module.aot
${XXD} -i $< > $@
################################################################
# AOT loaded by Runtime (FAIL+Baremetal platform)
# NOTE: make build-sum: "error: bp cannot be used in asm here"
# could remove "ebp" from the clobber list (ARCH_ASM_CLOBBER_ALL) or
# use the -fomit-frame-pointer flag to tell gcc it shouldn't rely on ebp for enter/leave...
CC := /opt/crosscompiler/bin/i386-elf-gcc
CFLAGS := \
-I. \
${OPT} \
-m32 \
-ffunction-sections \
-ffreestanding \
-fomit-frame-pointer \
-ggdb
IWASM_LIB_DEBUG := /opt/wamr-libiwasm-baremetal-debug
IWASM_LIB_RELEASE := /opt/wamr-libiwasm-baremetal-release
LDFLAGS = \
-Wl,-T linker.ld \
$^ \
-Wl,--build-id=none \
-static \
-nostdlib \
-m32 \
-L${IWASM_LIB_RELEASE} \
-liwasm \
-lc \
-lgcc \
-lm
INCL := \
-I${WAMR}/core/iwasm/include \
-I${WAMR}/core/shared/utils \
-I${WAMR}/core/shared/platform/baremetal
${BUILD_DIR}/%/system.o: ${BUILD_DIR}/%/module_wasm.c
cp embed/host.c ${BUILD_DIR}/$*/module_host.c
cp embed/host-fail.c ${BUILD_DIR}/$*/module_host-fail.c
sed -i \
-e "s/__WASM_ARRAY_FILE__/module_wasm.c/g" \
-e "s/__WASM_ARRAY__/build_bochs_$*_module_aot/g" \
-e "s/__WASM_ARRAY_LEN__/build_bochs_$*_module_aot_len/g" \
${BUILD_DIR}/$*/module_host.c
${CC} ${CFLAGS} ${INCL} -c ${BUILD_DIR}/$*/module_host.c -o $@
${BUILD_DIR}/$*/module_host-fail.c
${CC} ${CFLAGS} ${INCL} -c ${BUILD_DIR}/$*/module_host-fail.c -o $@
${BUILD_DIR}/startup.o: arch/bochs/startup.s
${CC} $< ${CFLAGS} -c -o $@
${BUILD_DIR}/%/system.elf: ${BUILD_DIR}/%/system.o ${BUILD_DIR}/startup.o
${BUILD_DIR}/syscalls.o: syscalls.c
${CC} $< ${CFLAGS} -c -o $@
${BUILD_DIR}/%/system.elf: ${BUILD_DIR}/%/system.o ${BUILD_DIR}/syscalls.o ${BUILD_DIR}/startup.o
${CC} ${LDFLAGS} -o $@
################################################################
# Bochs
# AOT loaded by Runtime (Host+Linux platform)
CC_LINUX := gcc
CFLAGS_LINUX := \
-I. \
${OPT} \
-m32 \
-ffunction-sections \
-ggdb
IWASM_LIB_LINUX_DEBUG := /opt/wamr-libiwasm-linux-debug
IWASM_LIB_LINUX_RELEASE := /opt/wamr-libiwasm-linux-release
LDFLAGS_LINUX = \
$^ \
-Wl,--build-id=none \
-static \
-m32 \
-Wl,-rpath,${IWASM_LIB_LINUX_RELEASE} \
-L${IWASM_LIB_LINUX_RELEASE} \
-liwasm \
-lm
INCL_LINUX := \
-I${WAMR}/core/iwasm/include \
-I${WAMR}/core/shared/utils \
-I${WAMR}/core/shared/platform/linux
${BUILD_DIR}/%/system-linux.o: ${BUILD_DIR}/%/module_wasm.c
cp embed/host-linux.c ${BUILD_DIR}/$*/module_host-linux.c
sed -i \
-e "s/__WASM_ARRAY_FILE__/module_wasm.c/g" \
-e "s/__WASM_ARRAY__/build_bochs_$*_module_aot/g" \
-e "s/__WASM_ARRAY_LEN__/build_bochs_$*_module_aot_len/g" \
${BUILD_DIR}/$*/module_host-linux.c
${CC_LINUX} ${CFLAGS_LINUX} ${INCL_LINUX} -c ${BUILD_DIR}/$*/module_host-linux.c -o $@
${BUILD_DIR}/%/system-linux.elf: ${BUILD_DIR}/%/system-linux.o
${CC_LINUX} ${LDFLAGS_LINUX} -o $@
################################################################
# AOT loaded by Runtime (Host+Baremetal platform)
CC_BAREMETAL := /opt/crosscompiler/bin/i386-elf-gcc
CFLAGS_BAREMETAL := \
-I. \
${OPT} \
-m32 \
-ffunction-sections \
-ffreestanding \
-ggdb
IWASM_LIB_BAREMETAL := /opt/wamr-libiwasm
LDFLAGS_BAREMETAL = \
$^ \
-Wl,--build-id=none \
-static \
-nostdlib \
-m32 \
-L${IWASM_LIB_BAREMETAL} \
-liwasm \
-lc \
-lgcc \
-lm \
--entry main
# Trace where the memset symbol is actually coming from
# LDFLAGS_BAREMETAL += -Wl,-Map,$@.map -Wl,--trace-symbol=memset
INCL_BAREMETAL := \
-I${WAMR}/core/iwasm/include \
-I${WAMR}/core/shared/utils \
-I${WAMR}/core/shared/platform/baremetal
${BUILD_DIR}/%/system-baremetal.o: ${BUILD_DIR}/%/module_wasm.c
cp embed/host-baremetal.c ${BUILD_DIR}/$*/module_host-baremetal.c
sed -i \
-e "s/__WASM_ARRAY_FILE__/module_wasm.c/g" \
-e "s/__WASM_ARRAY__/build_bochs_$*_module_aot/g" \
-e "s/__WASM_ARRAY_LEN__/build_bochs_$*_module_aot_len/g" \
${BUILD_DIR}/$*/module_host-baremetal.c
${CC_BAREMETAL} ${CFLAGS_BAREMETAL} ${INCL_BAREMETAL} -c ${BUILD_DIR}/$*/module_host-baremetal.c -o $@
${BUILD_DIR}/%/system-baremetal.elf: ${BUILD_DIR}/%/system-baremetal.o ${BUILD_DIR}/syscalls.o
${CC_BAREMETAL} ${LDFLAGS_BAREMETAL} -o $@
################################################################
# Fail/Bochs
# FAIL_BIN ?= /home/fail/bin
# FAIL_SERVER ?= ${FAIL_BIN}/generic-experiment-server
# FAIL_TRACE ?= ${FAIL_BIN}/generic-tracing-client
# FAIL_INJECT ?= ${FAIL_BIN}/generic-experiment-client
# FAIL_DUMP ?= ${FAIL_BIN}/dump-trace
# FAIL_IMPORT ?= ${FAIL_BIN}/import-trace --enable-sanitychecks
# FAIL_PRUNE ?= ${FAIL_BIN}/prune-trace
# BOCHS_RUNNER ?= ${FAIL_BIN}/bochs-experiment-runner.py
# RESULT_BROWSER ?= ${FAIL_BIN}/resultbrowser.py
FAIL_BIN ?= /home/fail/mars
FAIL_SERVER ?= ${FAIL_BIN}/generic-experiment-server
FAIL_TRACE ?= ${FAIL_BIN}/fail-x86-tracing
FAIL_INJECT ?= ${FAIL_BIN}/generic-experiment-client
FAIL_DUMP ?= ${FAIL_BIN}/dump-trace
FAIL_IMPORT ?= ${FAIL_BIN}/import-trace --enable-sanitychecks
FAIL_PRUNE ?= ${FAIL_BIN}/prune-trace
BOCHS_RUNNER ?= ${FAIL_BIN}/bochs-experiment-runner.py
RESULT_BROWSER ?= ${FAIL_BIN}/resultbrowser
${BUILD_DIR}/%/system.iso: ${BUILD_DIR}/%/system.elf
rm -rf $(shell dirname $<)/grub
mkdir -p $(shell dirname $<)/grub/boot/grub
@ -80,68 +216,83 @@ ${BUILD_DIR}/%/system.iso: ${BUILD_DIR}/%/system.elf
cp $< $(shell dirname $<)/grub/boot/system.elf
grub-mkrescue -o $@ $(shell dirname $<)/grub
BOCHS_RUNNER_ARGS = \
-V arch/bochs/vgabios.bin \
-b arch/bochs/BIOS-bochs-latest \
-V arch/bochs/vgabios.bin \
-b arch/bochs/BIOS-bochs-latest \
# Don't depend on system.iso so we can run the trace target from the fail docker image that does not have any wamr/wasi stuff
# ${BUILD_DIR}/%/trace.pb: ${BUILD_DIR}/%/system.iso
${BUILD_DIR}/%/trace.pb:
${BOCHS_RUNNER} ${BOCHS_RUNNER_ARGS} -1 \
-f ${FAIL_TRACE} \
-e $(shell dirname $<)/$*/system.elf \
-i $(shell dirname $<)/$*/system.iso \
${BOCHS_RUNNER} ${BOCHS_RUNNER_ARGS} -1 \
-f ${FAIL_TRACE} \
-e ${BUILD_DIR}/$*/system.elf \
-i ${BUILD_DIR}/$*/system.iso \
-- \
-Wf,--state-file=$(shell dirname $<)/state \
-Wf,--trace-file=$(shell dirname $<)/trace.pb \
-Wf,--start-symbol=start_trace \
-Wf,--end-symbol=stop_trace \
-Wf,--check-bounds
-Wf,--start-symbol=start_trace \
-Wf,--save-symbol=start_trace \
-Wf,--end-symbol=stop_trace \
-Wf,--state-file=${BUILD_DIR}/$*/state \
-Wf,--trace-file=${BUILD_DIR}/$*/trace.pb \
-Wf,--elf-file=${BUILD_DIR}/$*/system.elf
# -Wf,--check-bounds
server-%:
${FAIL_SERVER} -v ${ARCH}/$(subst server-,,$@) -b % --inject-single-bit --inject-registers
client-%:
${BOCHS_RUNNER} ${BOCHS_RUNNER_ARGS} \
-f ${FAIL_INJECT} \
${BOCHS_RUNNER} ${BOCHS_RUNNER_ARGS} \
-f ${FAIL_INJECT} \
-e ${BUILD_DIR}/$(subst client-,,$@)/system.elf \
-i ${BUILD_DIR}/$(subst client-,,$@)/system.iso \
-j $(shell getconf _NPROCESSORS_ONLN) \
-- \
-Wf,--state-dir=${BUILD_DIR}/$(subst client-,,$@)/state \
-Wf,--trap \
-Wf,--timeout=10 \
-Wf,--ok-marker=ok_marker \
-Wf,--trap \
-Wf,--timeout=500000 \
-Wf,--ok-marker=ok_marker \
-Wf,--fail-marker=fail_marker \
-Wf,--catch-write-textsegment \
-Wf,--catch-outerspace \
2>/dev/null | grep -B 2 -A 8 'INJECT'
# -Wf,--catch-write-textsegment \
# -Wf,--catch-outerspace \
inject-%:
${BOCHS_RUNNER} ${BOCHS_RUNNER_ARGS} -1 \
-f ${FAIL_INJECT} \
${BOCHS_RUNNER} ${BOCHS_RUNNER_ARGS} -1 \
-f ${FAIL_INJECT} \
-e ${BUILD_DIR}/$(subst inject-,,$@)/system.elf \
-i ${BUILD_DIR}/$(subst inject-,,$@)/system.iso \
-j 1 -- \
-Wf,--state-dir=${BUILD_DIR}/$(subst inject-,,$@)/state \
-Wf,--trap \
-Wf,--timeout=10 \
-Wf,--ok-marker=ok_marker \
-Wf,--trap \
-Wf,--timeout=10 \
-Wf,--ok-marker=ok_marker \
-Wf,--fail-marker=fail_marker \
-Wf,--catch-write-textsegment \
-Wf,--catch-outerspace
# TODO: Command line interface changed
# NOTE: Command line interface changed?
import-arch-%: ${BUILD_DIR}/%/trace.pb ${HOME}/.my.cnf
# ${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b mem -t $< -e $(shell dirname $<)/system.elf -i mem --memory-type ram
# ${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b regs-trace -t $< -e $(shell dirname $<)/system.elf -i mem --memory-type register
# ${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b regs -t $< -e $(shell dirname $<)/system.elf -i regs
# ${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b ip -t $< -e $(shell dirname $<)/system.elf -i regs --no-gp --ip
# ${FAIL_PRUNE} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b %% --overwrite
${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b mem -t $< -e $(shell dirname $<)/system.elf -i MemoryImporter
${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b regs-trace -t $< -e $(shell dirname $<)/system.elf -i MemoryImporter
${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b regs -t $< -e $(shell dirname $<)/system.elf -i RegisterImporter
${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b ip -t $< -e $(shell dirname $<)/system.elf -i RegisterImporter --no-gp --ip
${FAIL_PRUNE} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b %% --overwrite
# ${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b mem -t $< -e $(shell dirname $<)/system.elf -i mem --memory-type ram
# ${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b regs-trace -t $< -e $(shell dirname $<)/system.elf -i mem --memory-type register
# ${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b regs -t $< -e $(shell dirname $<)/system.elf -i regs
# ${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b ip -t $< -e $(shell dirname $<)/system.elf -i regs --no-gp --ip
# ${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b mem -t $< -e $(shell dirname $<)/system.elf -i MemoryImporter
# ${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b regs-trace -t $< -e $(shell dirname $<)/system.elf -i MemoryImporter
# ${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b regs -t $< -e $(shell dirname $<)/system.elf -i RegisterImporter
# ${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b ip -t $< -e $(shell dirname $<)/system.elf -i RegisterImporter --no-gp --ip
${FAIL_IMPORT} -t $< -i MemoryImporter -e $(shell dirname $<)/system.elf -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b mem
${FAIL_IMPORT} -t $< -i RegisterImporter -e $(shell dirname $<)/system.elf -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b regs --flags
${FAIL_IMPORT} -t $< -i RegisterImporter -e $(shell dirname $<)/system.elf -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b ip --no-gp --ip
${FAIL_IMPORT} -t $< -i ElfImporter --objdump /usr/bin/objdump -e $(shell dirname $<)/system.elf -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b ip
${FAIL_IMPORT} -t $< -i ElfImporter --objdump /usr/bin/objdump -e $(shell dirname $<)/system.elf -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b mem
${FAIL_IMPORT} -t $< -i ElfImporter --objdump /usr/bin/objdump -e $(shell dirname $<)/system.elf -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b regs
${FAIL_IMPORT} -t $< -i ElfImporter --objdump /usr/bin/objdump -e $(shell dirname $<)/system.elf -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b ip --sources
${FAIL_IMPORT} -t $< -i ElfImporter --objdump /usr/bin/objdump -e $(shell dirname $<)/system.elf -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b mem --sources
${FAIL_IMPORT} -t $< -i ElfImporter --objdump /usr/bin/objdump -e $(shell dirname $<)/system.elf -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b regs --sources
${FAIL_PRUNE} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b %% --overwrite
define arch-make-targets
@ -149,4 +300,32 @@ build-$1: ${BUILD_DIR}/$1/system.iso
trace-$1: ${BUILD_DIR}/$1/trace.pb
objdump-$1:
objdump --disassemble --disassembler-options intel --disassembler-color=off --source ${BUILD_DIR}/$1/system.elf | less
linux-build-$1: ${BUILD_DIR}/$1/system-linux.elf
linux-run-$1: ${BUILD_DIR}/$1/system-linux.elf
${BUILD_DIR}/$1/system-linux.elf
linux-gdb-$1: ${BUILD_DIR}/$1/system-linux.elf
gdb --tui ${BUILD_DIR}/$1/system-linux.elf
linux-objdump-$1:
objdump --disassemble --disassembler-options intel --disassembler-color=off --source ${BUILD_DIR}/$1/system-linux.elf | less
baremetal-build-$1: ${BUILD_DIR}/$1/system-baremetal.elf
baremetal-run-$1: ${BUILD_DIR}/$1/system-baremetal.elf
${BUILD_DIR}/$1/system-baremetal.elf
baremetal-gdb-$1: ${BUILD_DIR}/$1/system-baremetal.elf
gdb --tui -ex "set substitute-path /wamrlib ${WAMR}" ${BUILD_DIR}/$1/system-baremetal.elf
baremetal-objdump-$1:
objdump --disassemble --disassembler-options intel --disassembler-color=off --source ${BUILD_DIR}/$1/system-baremetal.elf | less
bochs-run-$1: ${BUILD_DIR}/$1/system.iso
bochs -q -f arch/bochs/bochsrc-docker.txt
endef

View File

@ -4,7 +4,6 @@ romimage: file="/home/christoph/Notes/TU/MastersThesis/3 Wasm/examples/arch/boch
vgaromimage: file="/home/christoph/Notes/TU/MastersThesis/3 Wasm/examples/arch/bochs/vgabios.bin"
ata0-master: type=cdrom, path="/home/christoph/Notes/TU/MastersThesis/3 Wasm/examples/build-bochs/sum/system.iso", status=inserted
boot: cdrom
log: bochslog.txt
clock: sync=realtime, time0=local
cpu: count=1, ips=1000000
sound: driver=dummy

View File

@ -13,20 +13,41 @@
# checksum: -(magic+flags)
.long -(0x1BADB002 + 0x3)
# the initial kernel stack
.section .kernel_stack
.global os_stack
.size os_stack, 4096
# NOTE: New Start
# .section .gdt
# gdt_start:
# .quad 0x0000000000000000 # null descriptor
# .quad 0x00cf9a000000ffff # code segment descriptor: base=0, limit=4GB, 32-bit code
# .quad 0x00cf92000000ffff # data segment descriptor: base=0, limit=4GB, 32-bit data
# gdt_end:
#
# gdt_descriptor:
# .word gdt_end - gdt_start - 1 # limit
# .long gdt_start # base
#
# .section .idt
# idt_table:
# .space 256*8 # 256 entries x 8 bytes each
# idt_descriptor:
# .word 256*8-1 # limit
# .long idt_table # base
# NOTE: New End
#.Lstack_bottom:
os_stack:
.byte 0
#.skip 16384 # 16 KiB
.skip 4094 # 4 KiB
.byte 0
.Lstack_top:
.byte 0
.skip 65565 # 64 KiB
# .skip 16384 # 16 KiB
# .skip 4094 # 4 KiB
.byte 0
.Lstack_top:
# The linker script specifies _start as the entry point to the kernel and the
@ -36,7 +57,9 @@ os_stack:
.global _start
.type _start, @function
_start:
# Welcome to kernel mode!
# NOTE: Old Start
# Welcome to kernel mode!
# To set up a stack, we simply set the esp register to point to the top of
# our stack (as it grows downwards).
movl $.Lstack_top, %esp
@ -54,6 +77,34 @@ _start:
.Lhang:
jmp .Lhang
# NOTE: Old End
# NOTE: New Start
# cli
#
# lgdt gdt_descriptor # GDT
# lidt idt_descriptor # IDT Stub
#
# # set up segment registers (flat 32-bit)
# movw $0x10, %ax
# movw %ax, %ds
# movw %ax, %es
# movw %ax, %fs
# movw %ax, %gs
# movw %ax, %ss
# movl $.Lstack_top, %esp # set stack
#
# # call main C function
# call os_main
#
# cli
# hlt
# .Lhang:
# jmp .Lhang
# NOTE: New End
# Set the size of the _start symbol to the current location '.' minus its start.
# This is useful when debugging or when you implement call tracing.
.size _start, . - _start

View File

@ -0,0 +1,85 @@
// https://github.com/bytecodealliance/wasm-micro-runtime/blob/WAMR-2.4.4/doc/embed_wamr.md
#include "lib.c"
#include "bh_platform.h"
#include "wasm_export.h"
#include "__WASM_ARRAY_FILE__"
#define STACK_SIZE (4 * 1024)
#define HEAP_SIZE STACK_SIZE
#define RUNTIME_POOL_SIZE (4 * STACK_SIZE)
// TODO: Set this up so the lsp actually finds the includes...
// MAIN() {
int main(int argc, char *argv[]) {
char error_buf[128];
wasm_module_t module;
wasm_module_inst_t module_inst;
wasm_function_inst_t func;
wasm_exec_env_t exec_env;
/* initialize the wasm runtime */
static char global_heap_buf[RUNTIME_POOL_SIZE];
static RuntimeInitArgs init_args;
memset(&init_args, 0, sizeof(RuntimeInitArgs));
// init_args.mem_alloc_type = Alloc_With_System_Allocator;
init_args.mem_alloc_type = Alloc_With_Pool;
init_args.mem_alloc_option.pool.heap_buf = global_heap_buf;
init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf);
init_args.max_thread_num = 1;
if (!wasm_runtime_full_init(&init_args)) {
return 1;
}
/* parse the WASM file from buffer and create a WASM module */
module = wasm_runtime_load(__WASM_ARRAY__, __WASM_ARRAY_LEN__, error_buf,
sizeof(error_buf));
if (!module) {
return 1;
}
/* create an instance of the WASM module (WASM linear memory is ready) */
module_inst = wasm_runtime_instantiate(module, STACK_SIZE, HEAP_SIZE,
error_buf, sizeof(error_buf));
if (!module_inst) {
return 1;
}
/* lookup a WASM function by its name, the function signature can NULL here */
func = wasm_runtime_lookup_function(module_inst, "wasm_module");
/* create an execution environment to execute arbitrary WASM functions */
exec_env = wasm_runtime_create_exec_env(module_inst, STACK_SIZE);
/* arguments are always transferred in 32-bit element */
uint32_t args[1];
/* call an arbitrary WASM function */
// MARKER(start_trace);
if (!wasm_runtime_call_wasm(exec_env, func, 0, args)) {
/* function wasn't called correctly */
}
// MARKER(stop_trace);
//
uint32_t result = args[0];
wasm_runtime_destroy_exec_env(exec_env);
wasm_runtime_deinstantiate(module_inst);
wasm_runtime_unload(module);
wasm_runtime_destroy();
/* the return value is stored in args[0] */
if (result == 100) {
// MARKER(ok_marker);
return 0;
} else {
// MARKER(fail_marker);
return 1;
}
}

View File

@ -8,7 +8,8 @@
#include "__WASM_ARRAY_FILE__"
#define STACK_SIZE (4 * 1024)
#define HEAP_SIZE (4 * 1024)
#define HEAP_SIZE STACK_SIZE
#define RUNTIME_POOL_SIZE 4 * STACK_SIZE
// TODO: Set this up so the lsp actually finds the includes...
@ -20,10 +21,15 @@ MAIN() {
wasm_exec_env_t exec_env;
/* initialize the wasm runtime */
RuntimeInitArgs init_args;
memset(&init_args, 0, sizeof(init_args));
static char global_heap_buf[RUNTIME_POOL_SIZE];
static RuntimeInitArgs init_args;
memset(&init_args, 0, sizeof(RuntimeInitArgs));
init_args.mem_alloc_type = Alloc_With_System_Allocator;
// init_args.mem_alloc_type = Alloc_With_System_Allocator;
init_args.mem_alloc_type = Alloc_With_Pool;
init_args.mem_alloc_option.pool.heap_buf = global_heap_buf;
init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf);
init_args.max_thread_num = 1;
if (!wasm_runtime_full_init(&init_args)) {
return;
}
@ -32,10 +38,20 @@ MAIN() {
module = wasm_runtime_load(__WASM_ARRAY__, __WASM_ARRAY_LEN__, error_buf,
sizeof(error_buf));
if (!module) {
// printf("Load failed: %s\n", error_buf);
return;
}
/* create an instance of the WASM module (WASM linear memory is ready) */
module_inst = wasm_runtime_instantiate(module, STACK_SIZE, HEAP_SIZE,
error_buf, sizeof(error_buf));
if (!module_inst) {
// printf("Inst failed: %s\n", error_buf);
return;
}
/* lookup a WASM function by its name, the function signature can NULL here */
func = wasm_runtime_lookup_function(module_inst, "wasm_module");
@ -43,17 +59,17 @@ MAIN() {
exec_env = wasm_runtime_create_exec_env(module_inst, STACK_SIZE);
/* arguments are always transferred in 32-bit element */
uint32 args[1];
uint32_t args[1];
/* call an arbitrary WASM function */
MARKER(start_trace);
if (!wasm_runtime_call_wasm(exec_env, func, 0, args)) {
/* function wasn't called correctly */
POSIX_PRINTF("Failed to call function 'wasm_module'!\n");
// printf("Failed to call function 'wasm_module'!\n");
}
MARKER(stop_trace);
POSIX_PRINTF("Sum: %d\n!", args[0]);
// printf("Sum: %d\n", args[0]);
/* the return value is stored in args[0] */
if (args[0] == 100) {
@ -66,4 +82,6 @@ MAIN() {
wasm_runtime_deinstantiate(module_inst);
wasm_runtime_unload(module);
wasm_runtime_destroy();
return;
}

View File

@ -0,0 +1,89 @@
// https://github.com/bytecodealliance/wasm-micro-runtime/blob/WAMR-2.4.4/doc/embed_wamr.md
#include "lib.c"
#include "bh_platform.h"
#include "wasm_export.h"
#include "__WASM_ARRAY_FILE__"
#include <stdio.h>
#define STACK_SIZE (4 * 1024)
#define HEAP_SIZE STACK_SIZE
#define RUNTIME_POOL_SIZE 4 * STACK_SIZE
// TODO: Set this up so the lsp actually finds the includes...
// MAIN() {
int main(int argc, char *argv[]) {
char error_buf[128];
wasm_module_t module;
wasm_module_inst_t module_inst;
wasm_function_inst_t func;
wasm_exec_env_t exec_env;
/* initialize the wasm runtime */
static char global_heap_buf[RUNTIME_POOL_SIZE];
static RuntimeInitArgs init_args;
memset(&init_args, 0, sizeof(RuntimeInitArgs));
// init_args.mem_alloc_type = Alloc_With_System_Allocator;
init_args.mem_alloc_type = Alloc_With_Pool;
init_args.mem_alloc_option.pool.heap_buf = global_heap_buf;
init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf);
init_args.max_thread_num = 1;
if (!wasm_runtime_full_init(&init_args)) {
return 1;
}
/* parse the WASM file from buffer and create a WASM module */
module = wasm_runtime_load(__WASM_ARRAY__, __WASM_ARRAY_LEN__, error_buf,
sizeof(error_buf));
if (!module) {
printf("Load failed: %s\n", error_buf);
return 1;
}
/* create an instance of the WASM module (WASM linear memory is ready) */
module_inst = wasm_runtime_instantiate(module, STACK_SIZE, HEAP_SIZE,
error_buf, sizeof(error_buf));
if (!module_inst) {
printf("Inst failed: %s\n", error_buf);
return 1;
}
/* lookup a WASM function by its name, the function signature can NULL here */
func = wasm_runtime_lookup_function(module_inst, "wasm_module");
/* create an execution environment to execute arbitrary WASM functions */
exec_env = wasm_runtime_create_exec_env(module_inst, STACK_SIZE);
/* arguments are always transferred in 32-bit element */
uint32_t args[1];
/* call an arbitrary WASM function */
// MARKER(start_trace);
if (!wasm_runtime_call_wasm(exec_env, func, 0, args)) {
/* function wasn't called correctly */
printf("Failed to call function 'wasm_module'!\n");
}
// MARKER(stop_trace);
printf("Sum: %d\n", args[0]);
/* the return value is stored in args[0] */
if (args[0] == 100) {
// MARKER(ok_marker);
} else {
// MARKER(fail_marker);
}
wasm_runtime_destroy_exec_env(exec_env);
wasm_runtime_deinstantiate(module_inst);
wasm_runtime_unload(module);
wasm_runtime_destroy();
return 0;
}

View File

@ -7,6 +7,8 @@
#define QUOTE(x) __QUOTE(x)
#ifndef ARCH_ASM_CLOBBER_ALL
// TODO: Is my gcc to new? It won't let me clobber ebp unless I specify
// -fomit-frame-pointer
#define ARCH_ASM_CLOBBER_ALL "eax", "ebx", "ecx", "edx", "esi", "edi", "ebp"
#endif

View File

@ -18,6 +18,7 @@ SECTIONS {
/* Code and readonly data */
.text : {
/* fill gaps with int3 opcode to detect invalid jumps */
/* TODO: Crashes */
FILL(0xcc)
/* multiboot header */
@ -55,9 +56,20 @@ SECTIONS {
KEEP (*(".startup_stack"))
KEEP (*(".kernel_stack"))
*(".data*")
*(COMMON);
}
/* Uninitialized data */
.bss : {
_sbss = .;
*(.bss*)
*(COMMON)
_ebss = .;
}
/* Align and mark end of all sections — heap starts here */
. = ALIGN(4096);
_end = .;
/* Memory-mapped I/O APIC */
_sioapic = 0xFEC00000;
ioapic = 0xFEC00000;

35
examples/syscalls.c Normal file
View File

@ -0,0 +1,35 @@
#include <errno.h>
#include <sys/stat.h>
extern char _end; /* provided by linker script */
static char *heap_ptr = &_end;
void *sbrk(int incr) {
char *prev = heap_ptr;
heap_ptr += incr;
return prev;
}
int write(int fd, const char *buf, int len) { return len; }
int read(int fd, char *buf, int len) { return 0; }
int close(int fd) { return -1; }
int fstat(int fd, struct stat *st) {
st->st_mode = S_IFCHR;
return 0;
}
int isatty(int fd) { return 1; }
int lseek(int fd, int offset, int whence) { return 0; }
void _exit(int status) {
while (1)
;
}
void exit(int status) {
while (1)
;
}
int kill(int pid, int sig) {
errno = EINVAL;
return -1;
}
int getpid(void) { return 1; }

View File

@ -1,7 +1,72 @@
# We need an old ubuntu version with an old enough gcc to build an old gcc...
# This gcc can't bootstrap itself because it's target is another platform.
FROM ubuntu:bionic AS compiler-builder
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive TZ=Europe/Berlin apt-get install -y --no-install-recommends \
build-essential \
git \
ca-certificates \
cmake \
bison \
flex \
libgmp3-dev \
libmpc-dev \
libmpfr-dev \
texinfo \
libisl-dev \
wget \
&& apt-get clean
ARG GCCVERSION=5.4.0
ARG BINUTILSVERSION=2.26.1
ARG CROSSPREFIX=/opt/crosscompiler
ARG CROSSTARGET=i386-elf
# Build Binutils for cross-compilation
WORKDIR /
RUN wget https://ftp.gnu.org/gnu/binutils/binutils-$BINUTILSVERSION.tar.gz \
&& tar xf binutils-$BINUTILSVERSION.tar.gz
RUN mkdir binutils-build && cd binutils-build \
&& /binutils-$BINUTILSVERSION/configure --target=$CROSSTARGET --prefix="$CROSSPREFIX" --with-sysroot --disable-nls --disable-werror \
&& make -j$(nproc) \
&& make install
# Build GCC for cross-compilation
WORKDIR /
RUN wget https://ftp.gnu.org/gnu/gcc/gcc-$GCCVERSION/gcc-$GCCVERSION.tar.gz \
&& tar xf gcc-$GCCVERSION.tar.gz \
&& cd gcc-$GCCVERSION \
&& contrib/download_prerequisites
RUN mkdir gcc-build && cd gcc-build \
&& PATH="$CROSSPREFIX/bin:$PATH" /gcc-$GCCVERSION/configure --target=$CROSSTARGET --prefix="$CROSSPREFIX" --disable-nls --enable-languages=c,c++ --without-headers --disable-hosted-libstdcxx --disable-libsanitizer --disable-threads \
&& PATH="$CROSSPREFIX/bin:$PATH" make all-gcc -j$(nproc) \
&& PATH="$CROSSPREFIX/bin:$PATH" make all-target-libgcc -j$(nproc) \
&& PATH="$CROSSPREFIX/bin:$PATH" make install-gcc \
&& PATH="$CROSSPREFIX/bin:$PATH" make install-target-libgcc
# && PATH="$CROSSPREFIX/bin:$PATH" make all-target-libstdc++-v3 -j$(nproc) \
# && PATH="$CROSSPREFIX/bin:$PATH" make install-target-libstdc++-v3
# Build newlib in the gcc prefix - don't need to specify include paths
ARG NEWLIBVERSION=4.1.0
WORKDIR /
RUN wget ftp://sourceware.org/pub/newlib/newlib-$NEWLIBVERSION.tar.gz \
&& tar xf newlib-$NEWLIBVERSION.tar.gz
RUN mkdir newlib-build && cd newlib-build \
&& PATH="$CROSSPREFIX/bin:$PATH" /newlib-$NEWLIBVERSION/configure \
--target=$CROSSTARGET \
--prefix="$CROSSPREFIX" \
--disable-nls \
--disable-newlib-supplied-syscalls \
&& PATH="$CROSSPREFIX/bin:$PATH" make -j$(nproc) \
&& PATH="$CROSSPREFIX/bin:$PATH" make install
# =============================================================================
FROM ubuntu:noble AS wamr-builder
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive TZ=Europe/Berline apt-get install -y --no-install-recommends \
&& DEBIAN_FRONTEND=noninteractive TZ=Europe/Berlin apt-get install -y --no-install-recommends \
build-essential \
gcc-multilib \
g++-multilib \
@ -16,21 +81,18 @@ RUN apt-get update \
python3-minimal \
python3-pip \
ninja-build \
wget \
&& apt-get clean
# TODO: Can't find pthread on X86_32
# RUN ln -s /usr/lib/x86_64-linux-gnu/libpthread.so.0 /usr/lib/x86_64-linux-gnu/libpthread.so
# RUN ln -s /usr/lib32/libpthread.so.0 /usr/lib32/libpthread.so
RUN python3 -m pip config set global.break-system-packages true
# Clone WAMR
RUN git clone https://gitea.vps.chriphost.de/christoph/wamr \
&& cd wamr \
&& git checkout WAMR-2.4.4
WORKDIR /wamr
# Build WAMR iwasm (vmcore standalone interpreter)
WORKDIR /wamr
RUN cd product-mini/platforms/linux \
&& mkdir build_iwasm && cd build_iwasm \
&& cmake \
@ -48,6 +110,7 @@ RUN cd product-mini/platforms/linux \
&& make -j$(nproc)
# Build WAMR wamrc (standalone compiler)
WORKDIR /wamr
RUN cd wamr-compiler \
&& ./build_llvm.sh \
&& mkdir build_wamrc && cd build_wamrc \
@ -74,9 +137,11 @@ WORKDIR /
RUN git clone https://gitea.vps.chriphost.de/christoph/wamr wamrlib \
&& cd wamrlib \
&& git checkout WAMR-2.4.4
WORKDIR /wamrlib
# TODO: Should this stuff not be compiled with the crosscompiler?
# Build WAMR libvmlib (compiler runtime - to compile wasm modules embedded in a native application)
# WORKDIR /wamrlib
# RUN cd wamr-compiler \
# && ./build_llvm.sh \
# # && ./build_llvm.sh --extra-cmake-flags "-DCMAKE_C_FLAGS=-m32 -DCMAKE_CXX_FLAGS=-m32 -DCMAKE_EXE_LINKER_FLAGS=-m32 -lstdc++" \
@ -97,11 +162,95 @@ WORKDIR /wamrlib
# && make -j$(nproc)
# Build WAMR libiwasm (vmcore interpreter runtime - to run wasm modules embedded in a native application)
RUN mkdir build_libiwasm && cd build_libiwasm \
# TODO: Should probably put the cross-compilation definitions in a toolchain file
COPY --from=compiler-builder /opt/crosscompiler /opt/crosscompiler
WORKDIR /wamrlib
RUN mkdir build_libiwasm_baremetal_release && cd build_libiwasm_baremetal_release \
&& cmake \
-DCMAKE_SYSTEM_NAME=Generic \
-DCMAKE_SYSTEM_PROCESSOR=i386 \
-DCMAKE_C_COMPILER=/opt/crosscompiler/bin/i386-elf-gcc \
-DCMAKE_CXX_COMPILER=/opt/crosscompiler/bin/i386-elf-g++ \
-DCMAKE_ASM_COMPILER=/opt/crosscompiler/bin/i386-elf-gcc \
-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_FLAGS_RELEASE="-O2 -DNDEBUG" \
-DCMAKE_CXX_FLAGS_RELEASE="-O2 -DNDEBUG" \
-DCMAKE_VERBOSE_MAKEFILE=ON \
-DWAMR_BUILD_PLATFORM=baremetal \
-DWAMR_BUILD_TARGET=X86_32 \
-DWAMR_BUILD_AOT=0 \
-DWAMR_BUILD_AOT=1 \
-DWAMR_BUILD_WAMR_COMPILER=0 \
-DWAMR_BUILD_INTERP=1 \
-DWAMR_BUILD_FAST_INTERP=0 \
-DWAMR_BUILD_JIT=0 \
-DWAMR_BUILD_FAST_JIT=0 \
-DWAMR_BUILD_LIBC_BUILTIN=1 \
-DWAMR_BUILD_LIBC_WASI=0 \
-DWAMR_BUILD_SIMD=0 \
-DCMAKE_COLOR_DIAGNOSTICS=ON \
.. \
&& make -j$(nproc)
WORKDIR /wamrlib
RUN mkdir build_libiwasm_baremetal_debug && cd build_libiwasm_baremetal_debug \
&& cmake \
-DCMAKE_SYSTEM_NAME=Generic \
-DCMAKE_SYSTEM_PROCESSOR=i386 \
-DCMAKE_C_COMPILER=/opt/crosscompiler/bin/i386-elf-gcc \
-DCMAKE_CXX_COMPILER=/opt/crosscompiler/bin/i386-elf-g++ \
-DCMAKE_ASM_COMPILER=/opt/crosscompiler/bin/i386-elf-gcc \
-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_C_FLAGS_DEBUG="-O0 -ggdb" \
-DCMAKE_CXX_FLAGS_DEBUG="-O0 -ggdb" \
-DCMAKE_VERBOSE_MAKEFILE=ON \
-DWAMR_BUILD_PLATFORM=baremetal \
-DWAMR_BUILD_TARGET=X86_32 \
-DWAMR_BUILD_AOT=1 \
-DWAMR_BUILD_WAMR_COMPILER=0 \
-DWAMR_BUILD_INTERP=1 \
-DWAMR_BUILD_FAST_INTERP=0 \
-DWAMR_BUILD_JIT=0 \
-DWAMR_BUILD_FAST_JIT=0 \
-DWAMR_BUILD_LIBC_BUILTIN=1 \
-DWAMR_BUILD_LIBC_WASI=0 \
-DWAMR_BUILD_SIMD=0 \
-DCMAKE_COLOR_DIAGNOSTICS=ON \
.. \
&& make -j$(nproc)
# Build WAMR libiwasm for the host system
WORKDIR /wamrlib
RUN mkdir build_libiwasm_linux_release && cd build_libiwasm_linux_release \
&& cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_FLAGS_RELEASE="-O2 -DNDEBUG" \
-DCMAKE_CXX_FLAGS_RELEASE="-O2 -DNDEBUG" \
-DWAMR_BUILD_PLATFORM=linux \
-DWAMR_BUILD_TARGET=X86_32 \
-DWAMR_BUILD_AOT=1 \
-DWAMR_BUILD_WAMR_COMPILER=0 \
-DWAMR_BUILD_INTERP=1 \
-DWAMR_BUILD_FAST_INTERP=0 \
-DWAMR_BUILD_JIT=0 \
-DWAMR_BUILD_FAST_JIT=0 \
-DWAMR_BUILD_LIBC_BUILTIN=1 \
-DWAMR_BUILD_LIBC_WASI=0 \
-DWAMR_BUILD_SIMD=0 \
-DCMAKE_COLOR_DIAGNOSTICS=ON \
.. \
&& make -j$(nproc)
WORKDIR /wamrlib
RUN mkdir build_libiwasm_linux_debug && cd build_libiwasm_linux_debug \
&& cmake \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_C_FLAGS_DEBUG="-O0 -ggdb" \
-DCMAKE_CXX_FLAGS_DEBUG="-O0 -ggdb" \
-DWAMR_BUILD_PLATFORM=linux \
-DWAMR_BUILD_TARGET=X86_32 \
-DWAMR_BUILD_AOT=1 \
-DWAMR_BUILD_WAMR_COMPILER=0 \
-DWAMR_BUILD_INTERP=1 \
-DWAMR_BUILD_FAST_INTERP=0 \
@ -129,19 +278,27 @@ RUN apt-get update \
neovim \
ranger \
wabt \
gdb \
valgrind \
fish \
grub-common \
xorriso \
grub-pc-bin \
bochs \
less \
&& apt-get clean
COPY --from=compiler-builder /opt/crosscompiler /opt/crosscompiler
COPY --from=wamr-builder /wamrlib /opt/wamr
COPY --from=wamr-builder /wamr/wamr-compiler/build_wamrc /opt/wamr/wamr-compiler/build_wamrc
COPY --from=wamr-builder /wamr/product-mini/platforms/linux/build_iwasm /opt/wamr/product-mini/platforms/linux/build_iwasm
RUN ln -sf /opt/wamr/product-mini/platforms/linux/build_iwasm /opt/wamr-iwasm \
&& ln -sf /opt/wamr/wamr-compiler/build_wamrc /opt/wamr-wamrc \
&& ln -sf /opt/wamr/wamr-compiler/build_libvmlib /opt/wamr-libvmlib \
&& ln -sf /opt/wamr/build_libiwasm /opt/wamr-libiwasm
&& ln -sf /opt/wamr/build_libiwasm_baremetal_release /opt/wamr-libiwasm-baremetal-release \
&& ln -sf /opt/wamr/build_libiwasm_baremetal_debug /opt/wamr-libiwasm-baremetal-debug \
&& ln -sf /opt/wamr/build_libiwasm_linux_release /opt/wamr-libiwasm-linux-release \
&& ln -sf /opt/wamr/build_libiwasm_linux_debug /opt/wamr-libiwasm-linux-debug
COPY ./examples /home/ubuntu/examples
WORKDIR /home/ubuntu/examples