make --xip and .wamr_mmap configurable from build menu

This commit is contained in:
2026-05-29 00:15:59 +02:00
parent 05a4aa18e4
commit c57ae5fced
10 changed files with 194 additions and 109 deletions

View File

@ -6,14 +6,16 @@ rec {
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
}; };
outputs = { outputs =
{
self, self,
nixpkgs, nixpkgs,
flake-utils, flake-utils,
}: }:
# Create a shell (and possibly package) for each possible system, not only x86_64-linux # Create a shell (and possibly package) for each possible system, not only x86_64-linux
flake-utils.lib.eachDefaultSystem ( flake-utils.lib.eachDefaultSystem (
system: let system:
let
# ========================================================================================= # =========================================================================================
# Define pkgs/stdenvs # Define pkgs/stdenvs
# ========================================================================================= # =========================================================================================
@ -62,7 +64,8 @@ rec {
# ========================================================================================= # =========================================================================================
# Setup the shell when entering the "nix develop" environment (bash script). # Setup the shell when entering the "nix develop" environment (bash script).
shellHook = let shellHook =
let
# Add project-local fish abbrs here # Add project-local fish abbrs here
abbrs = { abbrs = {
fail = "perl ./scripts/menu.pl"; fail = "perl ./scripts/menu.pl";
@ -114,8 +117,7 @@ rec {
# =========================================================================================== # ===========================================================================================
python = pkgs.python314.withPackages ( python = pkgs.python314.withPackages (
p: p: with p; [
with p; [
setuptools setuptools
flask flask
flask-mysqldb flask-mysqldb
@ -161,7 +163,8 @@ rec {
pname = "wasi-sdk"; pname = "wasi-sdk";
version = "29"; version = "29";
src = let src =
let
baseurl = "https://github.com/WebAssembly/wasi-sdk/releases/download"; baseurl = "https://github.com/WebAssembly/wasi-sdk/releases/download";
in in
builtins.fetchTarball { builtins.fetchTarball {
@ -192,7 +195,8 @@ rec {
pname = "iwasm"; pname = "iwasm";
version = "2.4.4"; version = "2.4.4";
src = let src =
let
baseurl = "https://github.com/bytecodealliance/wasm-micro-runtime/releases/download"; baseurl = "https://github.com/bytecodealliance/wasm-micro-runtime/releases/download";
in in
builtins.fetchTarball { builtins.fetchTarball {
@ -225,7 +229,8 @@ rec {
pname = "wamrc"; pname = "wamrc";
version = "2.4.4"; version = "2.4.4";
src = let src =
let
baseurl = "https://github.com/bytecodealliance/wasm-micro-runtime/releases/download"; baseurl = "https://github.com/bytecodealliance/wasm-micro-runtime/releases/download";
in in
builtins.fetchTarball { builtins.fetchTarball {
@ -294,25 +299,27 @@ rec {
''; '';
}; };
mkLibiwasm = { mkLibiwasm =
{
buildenv, buildenv,
platform, platform,
buildtype, buildtype,
cflags, cflags,
extraCmakeFlags ? [ ], extraCmakeFlags ? [ ],
patches ? [ ],
}: }:
buildenv.mkDerivation { buildenv.mkDerivation {
pname = "libiwasm"; pname = "libiwasm";
version = "2.4.4"; version = "2.4.4";
src = wamr_src; src = wamr_src;
inherit patches;
nativeBuildInputs = with pkgs; [ cmake ]; nativeBuildInputs = with pkgs; [ cmake ];
dontStrip = true; dontStrip = true;
cmakeBuildType = buildtype; cmakeBuildType = buildtype;
cmakeFlags = cmakeFlags = extraCmakeFlags ++ [
extraCmakeFlags
++ [
"-DCMAKE_VERBOSE_MAKEFILE=ON" "-DCMAKE_VERBOSE_MAKEFILE=ON"
"-DCMAKE_COLOR_DIAGNOSTICS=ON" "-DCMAKE_COLOR_DIAGNOSTICS=ON"
@ -333,11 +340,34 @@ rec {
NIX_CFLAGS_COMPILE = "-Wno-error=implicit-function-declaration " + cflags; NIX_CFLAGS_COMPILE = "-Wno-error=implicit-function-declaration " + cflags;
}; };
libiwasm-baremetal-mmap-debug = mkLibiwasm {
buildenv = i386_pkgs.stdenv;
platform = "baremetal";
buildtype = "Debug";
cflags = "-O0 -ggdb3";
extraCmakeFlags = [
"-DCMAKE_SYSTEM_NAME=Generic"
"-DCMAKE_SYSTEM_PROCESSOR=i386"
"-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY"
];
};
libiwasm-baremetal-mmap-release = mkLibiwasm {
buildenv = i386_pkgs.stdenv;
platform = "baremetal";
buildtype = "MinSizeRel";
cflags = "-O2 -ggdb3 -DNDEBUG";
extraCmakeFlags = [
"-DCMAKE_SYSTEM_NAME=Generic"
"-DCMAKE_SYSTEM_PROCESSOR=i386"
"-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY"
];
};
libiwasm-baremetal-debug = mkLibiwasm { libiwasm-baremetal-debug = mkLibiwasm {
buildenv = i386_pkgs.stdenv; buildenv = i386_pkgs.stdenv;
platform = "baremetal"; platform = "baremetal";
buildtype = "Debug"; buildtype = "Debug";
cflags = "-O0 -ggdb3"; cflags = "-O0 -ggdb3";
patches = [ ./patches/disable_wamr_mmap.patch ];
extraCmakeFlags = [ extraCmakeFlags = [
"-DCMAKE_SYSTEM_NAME=Generic" "-DCMAKE_SYSTEM_NAME=Generic"
"-DCMAKE_SYSTEM_PROCESSOR=i386" "-DCMAKE_SYSTEM_PROCESSOR=i386"
@ -349,6 +379,7 @@ rec {
platform = "baremetal"; platform = "baremetal";
buildtype = "MinSizeRel"; buildtype = "MinSizeRel";
cflags = "-O2 -ggdb3 -DNDEBUG"; cflags = "-O2 -ggdb3 -DNDEBUG";
patches = [ ./patches/disable_wamr_mmap.patch ];
extraCmakeFlags = [ extraCmakeFlags = [
"-DCMAKE_SYSTEM_NAME=Generic" "-DCMAKE_SYSTEM_NAME=Generic"
"-DCMAKE_SYSTEM_PROCESSOR=i386" "-DCMAKE_SYSTEM_PROCESSOR=i386"
@ -462,7 +493,8 @@ rec {
runHook postInstall runHook postInstall
''; '';
}; };
in { in
{
# Provide package for "nix build" # Provide package for "nix build"
packages = { packages = {
default = fail-bin; default = fail-bin;
@ -502,6 +534,8 @@ rec {
WAMR_ROOT = wamr; WAMR_ROOT = wamr;
LIBIWASM_DEBUG = "${libiwasm-baremetal-debug}/lib"; LIBIWASM_DEBUG = "${libiwasm-baremetal-debug}/lib";
LIBIWASM_RELEASE = "${libiwasm-baremetal-release}/lib"; LIBIWASM_RELEASE = "${libiwasm-baremetal-release}/lib";
LIBIWASM_MMAP_DEBUG = "${libiwasm-baremetal-mmap-debug}/lib";
LIBIWASM_MMAP_RELEASE = "${libiwasm-baremetal-mmap-release}/lib";
LIBIWASM_LINUX_DEBUG = "${libiwasm-linux-debug}/lib"; LIBIWASM_LINUX_DEBUG = "${libiwasm-linux-debug}/lib";
LIBIWASM_LINUX_RELEASE = "${libiwasm-linux-release}/lib"; LIBIWASM_LINUX_RELEASE = "${libiwasm-linux-release}/lib";
CROSS_CC = "${i386_pkgs.stdenv.cc}/bin/i386-elf-gcc"; CROSS_CC = "${i386_pkgs.stdenv.cc}/bin/i386-elf-gcc";

View File

@ -0,0 +1,13 @@
diff --git a/core/shared/platform/baremetal/platform_init.c b/core/shared/platform/baremetal/platform_init.c
index bbf7c102..f0fd43b7 100644
--- a/core/shared/platform/baremetal/platform_init.c
+++ b/core/shared/platform/baremetal/platform_init.c
@@ -45,7 +45,7 @@ os_dumps_proc_mem_info(char *out, unsigned int size)
// #12 0x08048112 in main
// To place mmap memory inside the .text segment:
-__attribute__((section(".text.wamr_mmap"), aligned(4096)))
+// __attribute__((section(".text.wamr_mmap"), aligned(4096)))
static uint8_t mmap_space[MMAP_SPACE_SIZE];
static size_t mmap_offset = 0; // Free space begins here

View File

@ -45,12 +45,24 @@ my @selected_modes =
TUI::select_from_list( "Select Execution Modes", 1, @modes ); TUI::select_from_list( "Select Execution Modes", 1, @modes );
die "No mode selected" unless @selected_modes; die "No mode selected" unless @selected_modes;
# Select WAMR mmap variant
my @wamr_variants = ( "no .wamr_mmap", ".wamr_mmap" );
my @selected_variants =
TUI::select_from_list( "Select WAMR mmap Variant", 1, @wamr_variants );
die "No variant selected" unless @selected_variants;
# Select XIP variant
my @xip_variants = ( "no --xip", "--xip" );
my @selected_xip_variants =
TUI::select_from_list( "Select WAMRC XIP Variant", 1, @xip_variants );
die "No XIP variant selected" unless @selected_xip_variants;
# Select 0.info contents # Select 0.info contents
my $info = join " ", TUI::select_from_list( "Select '0.info' Contents for ", 1, ( my $info = join " ", TUI::select_from_list( "Select '0.info' Contents for ", 1, (
"baseline", "baseline",
"--catch-outer", "--catch-outer",
"--catch-text", "--catch-text",
".wamr_mmap", # ".wamr_mmap",
".wamr_aot", ".wamr_aot",
)); ));
@ -60,9 +72,17 @@ system( "mkdir", "-p", "$local_builds_dir" );
foreach my $experiment (@selected_experiments) { foreach my $experiment (@selected_experiments) {
foreach my $target (@selected_targets) { foreach my $target (@selected_targets) {
foreach my $mode (@selected_modes) { foreach my $mode (@selected_modes) {
foreach my $variant (@selected_variants) {
foreach my $xip_variant (@selected_xip_variants) {
# These variables control which libiwasm and wamrc flags are used
local $ENV{WAMR_USE_MMAP} = ( $variant eq ".wamr_mmap" ) ? "true" : "false";
local $ENV{WAMR_USE_XIP} = ( $xip_variant eq "--xip" ) ? "true" : "false";
just( "build", $experiment, $target, $mode ); just( "build", $experiment, $target, $mode );
system( "echo '$mode $info' > $local_root/build-$experiment/0.info" ); my $mmap = $variant eq ".wamr_mmap" ? ".wamr_mmap" : "";
my $xip = $xip_variant eq "--xip" ? "--xip" : "";
system( "echo '$mode $mmap $info $xip' > $local_root/build-$experiment/0.info" );
system( system(
join " ", join " ",
@ -75,3 +95,5 @@ foreach my $experiment (@selected_experiments) {
} }
} }
} }
}
}

View File

@ -10,6 +10,8 @@ WASI_ROOT := env("WASI_ROOT")
WAMR_ROOT := env("WAMR_ROOT") WAMR_ROOT := env("WAMR_ROOT")
LIBIWASM_DEBUG := env("LIBIWASM_DEBUG") LIBIWASM_DEBUG := env("LIBIWASM_DEBUG")
LIBIWASM_RELEASE := env("LIBIWASM_RELEASE") LIBIWASM_RELEASE := env("LIBIWASM_RELEASE")
LIBIWASM_MMAP_DEBUG := env("LIBIWASM_MMAP_DEBUG")
LIBIWASM_MMAP_RELEASE := env("LIBIWASM_MMAP_RELEASE")
LIBIWASM_LINUX_DEBUG := env("LIBIWASM_LINUX_DEBUG") LIBIWASM_LINUX_DEBUG := env("LIBIWASM_LINUX_DEBUG")
LIBIWASM_LINUX_RELEASE := env("LIBIWASM_LINUX_RELEASE") LIBIWASM_LINUX_RELEASE := env("LIBIWASM_LINUX_RELEASE")
CROSS_CC := env("CROSS_CC") CROSS_CC := env("CROSS_CC")

View File

@ -223,7 +223,8 @@ sub inject {
# Catch invalid instruction pointers # Catch invalid instruction pointers
"-Wf,--catch-outerspace", "-Wf,--catch-outerspace",
# Messes with AOT compilation target if mmap memory is part of .text # Messes with Wasm compilation targets if mmap memory is part of .text
# (because the linear memory is allocated using os_mmap)
"-Wf,--catch-write-textsegment", "-Wf,--catch-write-textsegment",
"-Wf,--timeout=500000", "-Wf,--timeout=500000",

View File

@ -48,12 +48,12 @@ LINUX_LDFLAGS_NOWASM := "\
-lm \ -lm \
" "
WAMRC := "wamrc" WAMRC := "wamrc"
WAMR_USE_XIP := env_var_or_default("WAMR_USE_XIP", "false")
CROSS_WAMRCFLAGS := "\ CROSS_WAMRCFLAGS := "\
--target=i386 \ --target=i386 \
--cpu=generic \ --cpu=generic \
--opt-level=0 \ --opt-level=0 \
--xip \ " + if WAMR_USE_XIP == "true" { "--xip" } else { "" }
"
LINUX_WAMRCFLAGS := "\ LINUX_WAMRCFLAGS := "\
--target=i386 \ --target=i386 \
--cpu=generic \ --cpu=generic \
@ -74,7 +74,6 @@ build-wasm-aot-linux module:
build-wasm-aot-cross module: build-wasm-aot-cross module:
{{ WAMRC }} {{ CROSS_WAMRCFLAGS }} -o {{ BUILD_DIR }}-{{ module }}/wasm_module.aot {{ BUILD_DIR }}-{{ module }}/wasm_module.wasm {{ WAMRC }} {{ CROSS_WAMRCFLAGS }} -o {{ BUILD_DIR }}-{{ module }}/wasm_module.aot {{ BUILD_DIR }}-{{ module }}/wasm_module.wasm
[doc("WASM -> AOT: Compile a WASM module ahead-of-time using WAMR")] [doc("WASM -> AOT: Compile a WASM module ahead-of-time using WAMR")]
[group("1: build module")] [group("1: build module")]
build-wasm-aot module target="fail": build-wasm-aot module target="fail":
@ -144,8 +143,10 @@ copy-auxiliary module:
# =================================================================================================================== # # =================================================================================================================== #
# FAIL* # FAIL*
WAMR_USE_MMAP := env_var_or_default("WAMR_USE_MMAP", "false")
ACTIVE_LIBIWASM_DEBUG := if WAMR_USE_MMAP == "true" { LIBIWASM_MMAP_DEBUG } else { LIBIWASM_DEBUG }
CROSS_CFLAGS := f"-I./targets/wasm-host {{CROSS_CFLAGS_NOWASM}}" CROSS_CFLAGS := f"-I./targets/wasm-host {{CROSS_CFLAGS_NOWASM}}"
CROSS_LDFLAGS := f"-L{{LIBIWASM_DEBUG}} -liwasm {{CROSS_LDFLAGS_NOWASM}}" CROSS_LDFLAGS := f"-L{{ACTIVE_LIBIWASM_DEBUG}} -liwasm {{CROSS_LDFLAGS_NOWASM}}"
CROSS_INCLUDES := f"\ CROSS_INCLUDES := f"\
-I{{WAMR_ROOT}}/core/iwasm/include \ -I{{WAMR_ROOT}}/core/iwasm/include \
-I{{WAMR_ROOT}}/core/shared/utils \ -I{{WAMR_ROOT}}/core/shared/utils \
@ -178,7 +179,7 @@ LINUX_BAREMETAL_LDFLAGS := f"\
-static \ -static \
-nostdlib \ -nostdlib \
-m32 \ -m32 \
-L{{LIBIWASM_DEBUG}} \ -L{{ACTIVE_LIBIWASM_DEBUG}} \
-liwasm \ -liwasm \
-lc \ -lc \
-lgcc \ -lgcc \

View File

@ -36,10 +36,13 @@ extern "C" EXPORT("wasm_module") int wasm_module(void) {
YC = 0; YC = 0;
ZC = 0; ZC = 0;
// "early" starts trace here
sum<0>(); sum<0>();
sum<1>(); sum<1>();
sum<2>(); sum<2>();
// "late" starts trace here
fail_start_trace(); fail_start_trace();
naive_vote(); naive_vote();

View File

@ -69,10 +69,13 @@ extern "C" EXPORT("wasm_module") int wasm_module(void) {
YC = 0; YC = 0;
ZC = 0; ZC = 0;
// "early" starts trace here
sum<0, SIG_X>(); sum<0, SIG_X>();
sum<1, SIG_Y>(); sum<1, SIG_Y>();
sum<2, SIG_Z>(); sum<2, SIG_Z>();
// "late" starts trace here
fail_start_trace(); fail_start_trace();
sign_t static_sig = cored_vote(); sign_t static_sig = cored_vote();

View File

@ -36,12 +36,15 @@ extern "C" EXPORT("wasm_module") int wasm_module(void) {
YC = 0; YC = 0;
ZC = 0; ZC = 0;
// "early" starts trace here
fail_start_trace(); fail_start_trace();
sum<0>(); sum<0>();
sum<1>(); sum<1>();
sum<2>(); sum<2>();
// "late" starts trace here
naive_vote(); naive_vote();
fail_stop_trace(); fail_stop_trace();

View File

@ -69,12 +69,15 @@ extern "C" EXPORT("wasm_module") int wasm_module(void) {
YC = 0; YC = 0;
ZC = 0; ZC = 0;
// "early" starts trace here
fail_start_trace(); fail_start_trace();
sum<0, SIG_X>(); sum<0, SIG_X>();
sum<1, SIG_Y>(); sum<1, SIG_Y>();
sum<2, SIG_Z>(); sum<2, SIG_Z>();
// "late" starts trace here
sign_t static_sig = cored_vote(); sign_t static_sig = cored_vote();
fail_stop_trace(); fail_stop_trace();