From 532d04ef3b2fc407489bae686981b4f4254d804a Mon Sep 17 00:00:00 2001 From: Philip Silva Date: Sun, 22 Mar 2026 15:44:59 +0100 Subject: [PATCH 1/6] PGO/LTO optimizations for riscv-qemu-user platform * additional Docker stage riscv-gnu-glibc-clang-installer * time-based PGO (instead of step-based as in current measurements) * stateless improves from 2147554329 steps without LTO/PGO to 1993332842 steps (7%) --- docker/Dockerfile | 12 +++++++ platform/riscv-qemu-user/custom_imports.c | 2 +- .../scripts/c2riscv-qemu-user.sh | 33 +++++++++++++++---- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index b9e840d..8cf777a 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -102,6 +102,17 @@ RUN git clone https://github.com/riscv/riscv-gnu-toolchain riscv-gnu-toolchain & cd / && \ rm -rf /tmp/riscv-gnu-toolchain +# Stage for installing pre-packaged RISC-V GNU LLVM Toolchain +FROM base AS riscv-gnu-glibc-clang-installer + +WORKDIR /tmp + +RUN wget https://github.com/riscv-collab/riscv-gnu-toolchain/releases/download/2026.03.13/riscv64-glibc-ubuntu-24.04-llvm.tar.xz && \ + cd /opt && \ + tar xf /tmp/riscv64-glibc-ubuntu-24.04-llvm.tar.xz && \ + mv /opt/riscv /opt/riscv-glibc-llvm && \ + rm /tmp/riscv64-glibc-ubuntu-24.04-llvm.tar.xz + # Stage for building AARCH64 GCC MUSL Toolchain FROM base AS aarch64-musl-builder @@ -296,6 +307,7 @@ WORKDIR /opt # Copy all built toolchains and tools COPY --from=llvm-builder /opt/llvm-21 /opt/llvm-21 COPY --from=riscv-gnu-builder /opt/riscv-newlib /opt/riscv-newlib +COPY --from=riscv-gnu-glibc-clang-installer /opt/riscv-glibc-llvm /opt/riscv-glibc-llvm COPY --from=aarch64-musl-builder /opt/aarch64-linux-musl-gcc /opt/aarch64-linux-musl-gcc COPY --from=qemu-builder /opt/qemu-install/usr/local /usr/local COPY --from=qemu-builder /opt/qemu-install/libinsn.so /libinsn.so diff --git a/platform/riscv-qemu-user/custom_imports.c b/platform/riscv-qemu-user/custom_imports.c index f22e93b..655a29c 100644 --- a/platform/riscv-qemu-user/custom_imports.c +++ b/platform/riscv-qemu-user/custom_imports.c @@ -18,7 +18,7 @@ U32 testmodule__testfunc2(void* instance, U32 a, U32 b) { return a * b; } -int testmodule__printk(void* instance, U32 val) { +void testmodule__printk(void* instance, U32 val) { char buf[12]; static const char hex[] = "0123456789abcdef"; diff --git a/platform/riscv-qemu-user/scripts/c2riscv-qemu-user.sh b/platform/riscv-qemu-user/scripts/c2riscv-qemu-user.sh index 222c8dc..afeb90f 100755 --- a/platform/riscv-qemu-user/scripts/c2riscv-qemu-user.sh +++ b/platform/riscv-qemu-user/scripts/c2riscv-qemu-user.sh @@ -73,14 +73,11 @@ echo "Compiling..." # Compiler flags (using -O0 for faster compilation of large generated files) CFLAGS=( - --target=riscv64 - -march=rv64ima_zicsr - -mabi=lp64 -mcmodel=medany -static -include stdbool.h - --sysroot=/opt/riscv-newlib/riscv64-unknown-elf - --gcc-toolchain=/opt/riscv-newlib + -flto + -mllvm -enable-misched=false $OPT_LEVEL ) @@ -99,8 +96,32 @@ SOURCES=( w2c2/embedded/wasi.c ) -clang \ +echo "" +echo "Generate instrumented binary: $OUTPUT.instrumented" +echo "" + +/opt/riscv-glibc-llvm/bin/clang \ + "${CFLAGS[@]}" \ + -fprofile-instr-generate=$OUTPUT.profraw \ + "${INCLUDES[@]}" \ + "${SOURCES[@]}" \ + -o "$OUTPUT.instrumented" -lm 2>&1 + +echo "" +echo "Run instrumented binary: $OUTPUT.instrumented" +echo "" + +qemu-riscv64 "$OUTPUT.instrumented" + +/opt/riscv-glibc-llvm/bin/llvm-profdata merge -output=$OUTPUT.profdata $OUTPUT.profraw + +echo "" +echo "Compile based on profile..." +echo "" + +/opt/riscv-glibc-llvm/bin/clang \ "${CFLAGS[@]}" \ + -fprofile-instr-use=$OUTPUT.profdata \ "${INCLUDES[@]}" \ "${SOURCES[@]}" \ -o "$OUTPUT" -lm 2>&1 From 4c11bb1b7251966648fa0b9fd38a8e4b3724ecb0 Mon Sep 17 00:00:00 2001 From: Philip Silva Date: Mon, 30 Mar 2026 17:02:51 +0200 Subject: [PATCH 2/6] PGO/LTO optimizations for riscv-qemu platform * Configurable since it affects compile time * Extra -flto argument in OPT_LEVEL * Additional PGO_OPT variable --- docker/Dockerfile | 6 +- go_benchmark.sh | 4 +- .../scripts/c2riscv-qemu-user.sh | 94 +++++++++++---- platform/riscv-qemu/custom_imports.c | 20 ++++ platform/riscv-qemu/main.c | 4 + platform/riscv-qemu/scripts/c2riscv-qemu.sh | 112 +++++++++++++++++- 6 files changed, 210 insertions(+), 30 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 8cf777a..ec3a505 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -44,6 +44,7 @@ RUN apt-get update && apt-get install -y \ wget \ jq \ binaryen \ + parallel \ && rm -rf /var/lib/apt/lists/* RUN apt-get update && apt-get install -y \ @@ -88,13 +89,14 @@ WORKDIR /tmp RUN git clone https://github.com/riscv/riscv-gnu-toolchain riscv-gnu-toolchain && \ cd riscv-gnu-toolchain && \ - git checkout 311e70f6c55953a624ca670de7c85af38c2b23c2 && \ + git checkout 98c8ec4cb520443f16cdd36280b65fba3a5c5f54 && \ CFLAGS="-O2 -g0" CXXFLAGS="-O2 -g0" ./configure \ --prefix=/opt/riscv-newlib \ --with-arch=rv64ima \ --disable-gdb \ --with-cmodel=medany \ - --enable-strip && \ + --enable-strip \ + --enable-llvm && \ make -j$(nproc) && \ find /opt/riscv-newlib -type f -executable -exec strip --strip-debug {} + 2>/dev/null || true && \ find /opt/riscv-newlib -name "*.a" -exec strip --strip-debug {} + 2>/dev/null || true && \ diff --git a/go_benchmark.sh b/go_benchmark.sh index f3fa4ad..0b9ccc2 100755 --- a/go_benchmark.sh +++ b/go_benchmark.sh @@ -25,9 +25,9 @@ echo "Transpiling WASM to WAMR AOT with wamrc..." echo "Compiling C to RISCV..." -OPT_LEVEL="-O0" ./platform/riscv-qemu/scripts/c2riscv-qemu.sh build/c-packages/stateless/ build/bin/stateless.riscv.O0.elf +OPT_LEVEL="-O0 -flto" PGO_OPT="1" ./platform/riscv-qemu/scripts/c2riscv-qemu.sh build/c-packages/stateless/ build/bin/stateless.riscv.O0.elf ls -l build/bin/ -OPT_LEVEL="-O3" ./platform/riscv-qemu/scripts/c2riscv-qemu.sh build/c-packages/stateless/ build/bin/stateless.riscv.O3.elf +OPT_LEVEL="-O3 -flto" PGO_OPT="1" ./platform/riscv-qemu/scripts/c2riscv-qemu.sh build/c-packages/stateless/ build/bin/stateless.riscv.O3.elf (cd examples/go/stateless; GOOS=linux GOARCH=riscv64 go build -buildvcs=false -o ./stateless) (cd examples/build-wasm/go/stateless-by-wasmtime/; RUSTFLAGS='-C target-feature=+crt-static -C link-arg=-static' cargo build --release --target riscv64gc-unknown-linux-gnu) (cd examples/build-wasm/go/stateless-by-wasmer/; RUSTFLAGS='-C target-feature=+crt-static -C link-arg=-static' cargo build --release --target riscv64gc-unknown-linux-gnu) diff --git a/platform/riscv-qemu-user/scripts/c2riscv-qemu-user.sh b/platform/riscv-qemu-user/scripts/c2riscv-qemu-user.sh index afeb90f..876bb60 100755 --- a/platform/riscv-qemu-user/scripts/c2riscv-qemu-user.sh +++ b/platform/riscv-qemu-user/scripts/c2riscv-qemu-user.sh @@ -40,6 +40,12 @@ else echo "OPT_LEVEL not set, using default: $OPT_LEVEL" fi +if [ -n "$PGO_OPT" ]; then + echo "Enabling profile-guided optimization" +else + echo "PGO_OPT not set, not using profile-guided optimization" +fi + # Change to project root cd "$PROJECT_ROOT" @@ -74,13 +80,18 @@ echo "Compiling..." # Compiler flags (using -O0 for faster compilation of large generated files) CFLAGS=( -mcmodel=medany - -static -include stdbool.h - -flto -mllvm -enable-misched=false - $OPT_LEVEL ) +LDFLAGS=( + -fuse-ld=lld + -static +) + +# Link libraries +LIBS=(-lm) + # Include directories INCLUDES=( -I"$GUEST_DIR" @@ -94,37 +105,76 @@ SOURCES=( "$GUEST_DIR/guest.c" $GUEST_DIR/s0*.c w2c2/embedded/wasi.c + w2c2/embedded/wasip2.c ) -echo "" -echo "Generate instrumented binary: $OUTPUT.instrumented" -echo "" +if [ -n "$PGO_OPT" ]; then + echo "" + echo "Generate instrumented binary: $OUTPUT.instrumented" + echo "" -/opt/riscv-glibc-llvm/bin/clang \ - "${CFLAGS[@]}" \ - -fprofile-instr-generate=$OUTPUT.profraw \ - "${INCLUDES[@]}" \ - "${SOURCES[@]}" \ - -o "$OUTPUT.instrumented" -lm 2>&1 + # Remove object files + rm -f $PROJECT_ROOT/custom_imports.o $PROJECT_ROOT/guest.o $PROJECT_ROOT/main.o $PROJECT_ROOT/memlib.o $PROJECT_ROOT/memops.o $PROJECT_ROOT/s00000*.o $PROJECT_ROOT/startup.o $PROJECT_ROOT/wasi.o $PROJECT_ROOT/wasip2.o $PROJECT_ROOT/zkvm.o + + parallel -j$(nproc) /opt/riscv-glibc-llvm/bin/clang \ + -c \ + -fprofile-instr-generate=$OUTPUT.profraw \ + --target=riscv64-unknown-linux-gnu \ + "${CFLAGS[@]}" \ + "${INCLUDES[@]}" \ + ::: \ + "${SOURCES[@]}" 2>&1 + + /opt/riscv-glibc-llvm/bin/clang \ + --target=riscv64-unknown-linux-gnu \ + -fprofile-instr-generate=$OUTPUT.profraw \ + *.o \ + "${LDFLAGS[@]}" \ + "${LIBS[@]}" \ + -o "$OUTPUT.instrumented" 2>&1 -echo "" -echo "Run instrumented binary: $OUTPUT.instrumented" -echo "" + echo "" + echo "Run instrumented binary: $OUTPUT.instrumented" + echo "" -qemu-riscv64 "$OUTPUT.instrumented" + qemu-riscv64 "$OUTPUT.instrumented" -/opt/riscv-glibc-llvm/bin/llvm-profdata merge -output=$OUTPUT.profdata $OUTPUT.profraw + /opt/riscv-glibc-llvm/bin/llvm-profdata merge -output=$OUTPUT.profdata $OUTPUT.profraw +fi echo "" -echo "Compile based on profile..." +echo "Compile binary..." echo "" -/opt/riscv-glibc-llvm/bin/clang \ +# Remove object files +rm -f $PROJECT_ROOT/custom_imports.o $PROJECT_ROOT/guest.o $PROJECT_ROOT/main.o $PROJECT_ROOT/memlib.o $PROJECT_ROOT/memops.o $PROJECT_ROOT/s00000*.o $PROJECT_ROOT/startup.o $PROJECT_ROOT/wasi.o $PROJECT_ROOT/wasip2.o $PROJECT_ROOT/zkvm.o + +COMMON_FLAGS=( + $OPT_LEVEL +) + +if [ -n "$PGO_OPT" ]; then + COMMON_FLAGS+=( + -fprofile-instr-use=$OUTPUT.profdata + ) +fi + +parallel -j$(nproc) /opt/riscv-glibc-llvm/bin/clang \ + -c \ + --target=riscv64-unknown-linux-gnu \ + "${COMMON_FLAGS[@]}" \ "${CFLAGS[@]}" \ - -fprofile-instr-use=$OUTPUT.profdata \ "${INCLUDES[@]}" \ - "${SOURCES[@]}" \ - -o "$OUTPUT" -lm 2>&1 + ::: \ + "${SOURCES[@]}" 2>&1 + +/opt/riscv-glibc-llvm/bin/clang \ + --target=riscv64-unknown-linux-gnu \ + *.o \ + "${COMMON_FLAGS[@]}" \ + "${LDFLAGS[@]}" \ + "${LIBS[@]}" \ + -o "$OUTPUT" 2>&1 # Check if compilation succeeded if [ $? -eq 0 ] && [ -f "$OUTPUT" ]; then diff --git a/platform/riscv-qemu/custom_imports.c b/platform/riscv-qemu/custom_imports.c index 209e835..c8eeb6a 100644 --- a/platform/riscv-qemu/custom_imports.c +++ b/platform/riscv-qemu/custom_imports.c @@ -34,7 +34,27 @@ int testmodule__printk(void* instance, U32 val) { puts(buf); } +// https://clang.llvm.org/docs/SourceBasedCodeCoverage.html#introduction +// https://developer.arm.com/documentation/ka006511/1-0 +// https://github.com/arm/arm-toolchain/blob/arm-software/arm-software/embedded/samples/src/cpp-baremetal-semihosting-prof/proflib.c#L78 (Apache 2.0) +// +// https://github.com/llvm/llvm-project/issues/123034 +// https://github.com/llvm/llvm-project/pull/167998/changes +// +// -> needs -DCOMPILER_RT_PROFILE_BAREMETAL +//extern uint64_t __llvm_profile_get_size_for_buffer(void); +//extern int __llvm_profile_write_buffer(char *buffer); + void testmodule__shutdown(void* instance) { + puts("shutdown()\n"); + /*int n = __llvm_profile_get_size_for_buffer(); + if (n < 0) { + puts("negative buffer\n"); + } else if (n == 0) { + puts("zero buffer\n"); + } else { + puts("positive buffer\n"); + }*/ exit(0); } diff --git a/platform/riscv-qemu/main.c b/platform/riscv-qemu/main.c index 5baca5b..69a66f0 100644 --- a/platform/riscv-qemu/main.c +++ b/platform/riscv-qemu/main.c @@ -53,6 +53,10 @@ size_t strlen(const char *s) { return strlen_max; } +void *fopen(const char *filename, const char *mode) { + puts("fopen\n"); +} + /* Trap handler for WASM runtime errors */ void trap(Trap trap) { puts("trap(..)\n"); diff --git a/platform/riscv-qemu/scripts/c2riscv-qemu.sh b/platform/riscv-qemu/scripts/c2riscv-qemu.sh index 3a4c067..b5bfee1 100755 --- a/platform/riscv-qemu/scripts/c2riscv-qemu.sh +++ b/platform/riscv-qemu/scripts/c2riscv-qemu.sh @@ -32,6 +32,7 @@ fi GUEST_DIR="$1" OUTPUT="$2" +OUTPUT_USER_INSTR="$OUTPUT-user-instr" if [ -n "$OPT_LEVEL" ]; then OPT_LEVEL="$OPT_LEVEL" @@ -42,6 +43,12 @@ else echo "OPT_LEVEL not set, using default: $OPT_LEVEL" fi +if [ -n "$PGO_OPT" ]; then + echo "Enabling profile-guided optimization" +else + echo "PGO_OPT not set, not using profile-guided optimization" +fi + # Change to project root cd "$PROJECT_ROOT" @@ -60,6 +67,81 @@ if [ ! -f "$GUEST_DIR/guest.c" ] || [ ! -f "$GUEST_DIR/guest.h" ]; then exit 1 fi +if [ -n "$PGO_OPT" ]; then + echo "==========================================================" + echo "C to RISC-V QEMU User Compilation for instrumentation" + echo "==========================================================" + echo "Guest package: $GUEST_DIR" + echo "Output binary: $OUTPUT_USER_INSTR." + echo "" + + # Compile everything in one command via Docker + echo "Compiling..." + + # Compiler flags (using -O0 for faster compilation of large generated files) + CFLAGS=( + -mcmodel=medany + -include stdbool.h + -mllvm -enable-misched=false + ) + + LDFLAGS=( + -fuse-ld=lld + -static + ) + + # Link libraries + LIBS=(-lm) + + # Include directories + INCLUDES=( + -I"$GUEST_DIR" + -Iw2c2/embedded + ) + + # Source files + SOURCES=( + platform/riscv-qemu-user/main.c + platform/riscv-qemu-user/custom_imports.c + "$GUEST_DIR/guest.c" + $GUEST_DIR/s0*.c + w2c2/embedded/wasi.c + w2c2/embedded/wasip2.c + ) + + echo "" + echo "Generate instrumented binary: $OUTPUT_USER_INSTR.instrumented" + echo "" + + # Remove object files + rm -f $PROJECT_ROOT/custom_imports.o $PROJECT_ROOT/guest.o $PROJECT_ROOT/main.o $PROJECT_ROOT/memlib.o $PROJECT_ROOT/memops.o $PROJECT_ROOT/s00000*.o $PROJECT_ROOT/startup.o $PROJECT_ROOT/wasi.o $PROJECT_ROOT/wasip2.o $PROJECT_ROOT/zkvm.o + + + parallel -j$(nproc) /opt/riscv-glibc-llvm/bin/clang \ + -c \ + -fprofile-instr-generate=$OUTPUT_USER_INSTR.profraw \ + "${CFLAGS[@]}" \ + "${INCLUDES[@]}" \ + ::: \ + "${SOURCES[@]}" 2>&1 + + /opt/riscv-glibc-llvm/bin/clang \ + -fprofile-instr-generate=$OUTPUT_USER_INSTR.profraw \ + *.o \ + "${LDFLAGS[@]}" \ + "${LIBS[@]}" \ + -o "$OUTPUT.instrumented" 2>&1 + + echo "" + echo "Run instrumented binary: $OUTPUT_USER_INSTR.instrumented" + echo "" + + qemu-riscv64 "$OUTPUT_USER_INSTR.instrumented" + + /opt/riscv-glibc-llvm/bin/llvm-profdata merge -output=$OUTPUT_USER_INSTR.profdata $OUTPUT_USER_INSTR.profraw +fi + + # Create output directory mkdir -p "$(dirname "$OUTPUT")" @@ -76,16 +158,27 @@ echo "Compiling..." # RISC-V toolchain prefix PREFIX=/opt/riscv-newlib/bin/riscv64-unknown-elf- +COMMON_FLAGS=( + -g + $OPT_LEVEL +) + +if [ -n "$PGO_OPT" ]; then + COMMON_FLAGS+=( + -fprofile-instr-use=$OUTPUT_USER_INSTR.profdata + ) +fi + # Compiler flags (using -O0 for faster compilation of large generated files) CFLAGS=( --target=riscv64 -march=rv64ima_zicsr -mabi=lp64 -mcmodel=medany - -specs=nosys.specs -D__bool_true_false_are_defined -include stdbool.h - $OPT_LEVEL + -Wprofile-instr-out-of-date + -Wno-profile-instr-unprofiled --sysroot=/opt/riscv-newlib/riscv64-unknown-elf --gcc-toolchain=/opt/riscv-newlib -mllvm -enable-misched=false @@ -126,16 +219,27 @@ LDFLAGS=( -static -Wl,--gc-sections -Wl,-Map="${OUTPUT%.elf}.map" + -L/opt/riscv-newlib/lib/gcc/riscv64-unknown-elf/15.2.0 ) # Link libraries LIBS=(-lm -lgcc) -clang \ +# Remove object files +rm -f $PROJECT_ROOT/custom_imports.o $PROJECT_ROOT/guest.o $PROJECT_ROOT/main.o $PROJECT_ROOT/memlib.o $PROJECT_ROOT/memops.o $PROJECT_ROOT/s00000*.o $PROJECT_ROOT/startup.o $PROJECT_ROOT/wasi.o $PROJECT_ROOT/wasip2.o $PROJECT_ROOT/zkvm.o + +parallel -j$(nproc) /opt/riscv-newlib/bin/clang \ + -c \ "${CFLAGS[@]}" \ + "${COMMON_FLAGS[@]}" \ "${INCLUDES[@]}" \ + ::: \ "${SOURCES[@]}" \ - "${ASM_SOURCES[@]}" \ + "${ASM_SOURCES[@]}" 2>&1 + +/opt/riscv-newlib/bin/clang \ + *.o \ + "${COMMON_FLAGS[@]}" \ "${LDFLAGS[@]}" \ "${LIBS[@]}" \ -o "$OUTPUT" 2>&1 From a9c407c40741f954b04011c19b65ff6fdfebc96d Mon Sep 17 00:00:00 2001 From: Philip Silva Date: Tue, 31 Mar 2026 09:46:32 +0200 Subject: [PATCH 3/6] Remove debug code --- platform/riscv-qemu/custom_imports.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/platform/riscv-qemu/custom_imports.c b/platform/riscv-qemu/custom_imports.c index c8eeb6a..1c04a3d 100644 --- a/platform/riscv-qemu/custom_imports.c +++ b/platform/riscv-qemu/custom_imports.c @@ -34,27 +34,8 @@ int testmodule__printk(void* instance, U32 val) { puts(buf); } -// https://clang.llvm.org/docs/SourceBasedCodeCoverage.html#introduction -// https://developer.arm.com/documentation/ka006511/1-0 -// https://github.com/arm/arm-toolchain/blob/arm-software/arm-software/embedded/samples/src/cpp-baremetal-semihosting-prof/proflib.c#L78 (Apache 2.0) -// -// https://github.com/llvm/llvm-project/issues/123034 -// https://github.com/llvm/llvm-project/pull/167998/changes -// -// -> needs -DCOMPILER_RT_PROFILE_BAREMETAL -//extern uint64_t __llvm_profile_get_size_for_buffer(void); -//extern int __llvm_profile_write_buffer(char *buffer); - void testmodule__shutdown(void* instance) { puts("shutdown()\n"); - /*int n = __llvm_profile_get_size_for_buffer(); - if (n < 0) { - puts("negative buffer\n"); - } else if (n == 0) { - puts("zero buffer\n"); - } else { - puts("positive buffer\n"); - }*/ exit(0); } @@ -65,3 +46,4 @@ U32 testmodule__inputX2DdataX2Dlen(void* instance) { U32 testmodule__inputX2Ddata(void* instance, U32 index) { return 0; } + From 3061f67f895847a6e5449f509c0af70297b643b3 Mon Sep 17 00:00:00 2001 From: Philip Silva Date: Tue, 31 Mar 2026 19:10:55 +0200 Subject: [PATCH 4/6] Disable PGO during benchmarks --- go_benchmark.sh | 4 ++-- rust_benchmark.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go_benchmark.sh b/go_benchmark.sh index 0b9ccc2..364677b 100755 --- a/go_benchmark.sh +++ b/go_benchmark.sh @@ -25,9 +25,9 @@ echo "Transpiling WASM to WAMR AOT with wamrc..." echo "Compiling C to RISCV..." -OPT_LEVEL="-O0 -flto" PGO_OPT="1" ./platform/riscv-qemu/scripts/c2riscv-qemu.sh build/c-packages/stateless/ build/bin/stateless.riscv.O0.elf +OPT_LEVEL="-O0 -flto" ./platform/riscv-qemu/scripts/c2riscv-qemu.sh build/c-packages/stateless/ build/bin/stateless.riscv.O0.elf ls -l build/bin/ -OPT_LEVEL="-O3 -flto" PGO_OPT="1" ./platform/riscv-qemu/scripts/c2riscv-qemu.sh build/c-packages/stateless/ build/bin/stateless.riscv.O3.elf +OPT_LEVEL="-O3 -flto" ./platform/riscv-qemu/scripts/c2riscv-qemu.sh build/c-packages/stateless/ build/bin/stateless.riscv.O3.elf (cd examples/go/stateless; GOOS=linux GOARCH=riscv64 go build -buildvcs=false -o ./stateless) (cd examples/build-wasm/go/stateless-by-wasmtime/; RUSTFLAGS='-C target-feature=+crt-static -C link-arg=-static' cargo build --release --target riscv64gc-unknown-linux-gnu) (cd examples/build-wasm/go/stateless-by-wasmer/; RUSTFLAGS='-C target-feature=+crt-static -C link-arg=-static' cargo build --release --target riscv64gc-unknown-linux-gnu) diff --git a/rust_benchmark.sh b/rust_benchmark.sh index 92df715..5910883 100755 --- a/rust_benchmark.sh +++ b/rust_benchmark.sh @@ -25,8 +25,8 @@ echo "Transpiling WASM to WAMR AOT with wamrc..." echo "Compiling C to RISCV..." -OPT_LEVEL="-O0" ./platform/riscv-qemu/scripts/c2riscv-qemu.sh build/c-packages/reva-client-eth/ build/bin/reva-client-eth.riscv.O0.elf -OPT_LEVEL="-O3" ./platform/riscv-qemu/scripts/c2riscv-qemu.sh build/c-packages/reva-client-eth/ build/bin/reva-client-eth.riscv.O3.elf +OPT_LEVEL="-O0 -flto" ./platform/riscv-qemu/scripts/c2riscv-qemu.sh build/c-packages/reva-client-eth/ build/bin/reva-client-eth.riscv.O0.elf +OPT_LEVEL="-O3 -flto" ./platform/riscv-qemu/scripts/c2riscv-qemu.sh build/c-packages/reva-client-eth/ build/bin/reva-client-eth.riscv.O3.elf (cd examples/rust/reva-client-eth; RUSTFLAGS='-C target-feature=+crt-static -C link-arg=-static' cargo build --bin=reva-client-eth --target riscv64gc-unknown-linux-gnu --release) (cd examples/build-wasm/rust/reva-client-eth-by-wasmtime/; RUSTFLAGS='-C target-feature=+crt-static -C link-arg=-static' cargo build --release --target riscv64gc-unknown-linux-gnu) From 9277de2648637d1f82c8fa84ff05c1cf063b289a Mon Sep 17 00:00:00 2001 From: Philip Silva Date: Fri, 3 Apr 2026 09:06:28 +0200 Subject: [PATCH 5/6] Remove debug flag --- platform/riscv-qemu/scripts/c2riscv-qemu.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/platform/riscv-qemu/scripts/c2riscv-qemu.sh b/platform/riscv-qemu/scripts/c2riscv-qemu.sh index 45fddc2..82ae21e 100755 --- a/platform/riscv-qemu/scripts/c2riscv-qemu.sh +++ b/platform/riscv-qemu/scripts/c2riscv-qemu.sh @@ -159,7 +159,6 @@ echo "Compiling..." PREFIX=/opt/riscv-newlib/bin/riscv64-unknown-elf- COMMON_FLAGS=( - -g $OPT_LEVEL ) From b157f22de38169892796453cc10519987c537cf5 Mon Sep 17 00:00:00 2001 From: Philip Silva Date: Fri, 3 Apr 2026 11:29:18 +0200 Subject: [PATCH 6/6] Deactivate also LTO in benchmarks to limit RAM usage --- go_benchmark.sh | 4 ++-- rust_benchmark.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go_benchmark.sh b/go_benchmark.sh index 364677b..f3fa4ad 100755 --- a/go_benchmark.sh +++ b/go_benchmark.sh @@ -25,9 +25,9 @@ echo "Transpiling WASM to WAMR AOT with wamrc..." echo "Compiling C to RISCV..." -OPT_LEVEL="-O0 -flto" ./platform/riscv-qemu/scripts/c2riscv-qemu.sh build/c-packages/stateless/ build/bin/stateless.riscv.O0.elf +OPT_LEVEL="-O0" ./platform/riscv-qemu/scripts/c2riscv-qemu.sh build/c-packages/stateless/ build/bin/stateless.riscv.O0.elf ls -l build/bin/ -OPT_LEVEL="-O3 -flto" ./platform/riscv-qemu/scripts/c2riscv-qemu.sh build/c-packages/stateless/ build/bin/stateless.riscv.O3.elf +OPT_LEVEL="-O3" ./platform/riscv-qemu/scripts/c2riscv-qemu.sh build/c-packages/stateless/ build/bin/stateless.riscv.O3.elf (cd examples/go/stateless; GOOS=linux GOARCH=riscv64 go build -buildvcs=false -o ./stateless) (cd examples/build-wasm/go/stateless-by-wasmtime/; RUSTFLAGS='-C target-feature=+crt-static -C link-arg=-static' cargo build --release --target riscv64gc-unknown-linux-gnu) (cd examples/build-wasm/go/stateless-by-wasmer/; RUSTFLAGS='-C target-feature=+crt-static -C link-arg=-static' cargo build --release --target riscv64gc-unknown-linux-gnu) diff --git a/rust_benchmark.sh b/rust_benchmark.sh index 5910883..92df715 100755 --- a/rust_benchmark.sh +++ b/rust_benchmark.sh @@ -25,8 +25,8 @@ echo "Transpiling WASM to WAMR AOT with wamrc..." echo "Compiling C to RISCV..." -OPT_LEVEL="-O0 -flto" ./platform/riscv-qemu/scripts/c2riscv-qemu.sh build/c-packages/reva-client-eth/ build/bin/reva-client-eth.riscv.O0.elf -OPT_LEVEL="-O3 -flto" ./platform/riscv-qemu/scripts/c2riscv-qemu.sh build/c-packages/reva-client-eth/ build/bin/reva-client-eth.riscv.O3.elf +OPT_LEVEL="-O0" ./platform/riscv-qemu/scripts/c2riscv-qemu.sh build/c-packages/reva-client-eth/ build/bin/reva-client-eth.riscv.O0.elf +OPT_LEVEL="-O3" ./platform/riscv-qemu/scripts/c2riscv-qemu.sh build/c-packages/reva-client-eth/ build/bin/reva-client-eth.riscv.O3.elf (cd examples/rust/reva-client-eth; RUSTFLAGS='-C target-feature=+crt-static -C link-arg=-static' cargo build --bin=reva-client-eth --target riscv64gc-unknown-linux-gnu --release) (cd examples/build-wasm/rust/reva-client-eth-by-wasmtime/; RUSTFLAGS='-C target-feature=+crt-static -C link-arg=-static' cargo build --release --target riscv64gc-unknown-linux-gnu)