Skip to content

Commit 81cbeb2

Browse files
committed
Add Component Model binary parser + validation
1 parent fcec30e commit 81cbeb2

File tree

59 files changed

+12190
-129
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+12190
-129
lines changed

.clang-tidy

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,30 @@
44

55
# Here is an explanation for why some of the checks are disabled:
66
#
7+
# -misc-include-cleaner: too noisy with platform abstraction headers
8+
# -bugprone-easily-swappable-parameters: most C APIs have consecutive same-type params
9+
# -bugprone-macro-parentheses: WAMR macros intentionally use unparenthesized args
10+
# -misc-no-recursion: interpreter/validator use intentional recursion
11+
# -readability-magic-numbers: wasm spec constants (opcodes, limits) are ubiquitous
12+
#
713

814
Checks: >
915
-*,
1016
bugprone-*,
1117
cert-*,
1218
clang-analyzer-*,
1319
concurrency-*,
20+
cppcoreguidelines-init-variables,
21+
cppcoreguidelines-narrowing-conversions,
22+
cppcoreguidelines-pro-type-cstyle-cast,
1423
misc-*,
1524
modernize-*,
1625
performance-*,
1726
portability-*,
1827
readability-*,
1928
-bugprone-easily-swappable-parameters,
2029
-bugprone-macro-parentheses,
30+
-misc-include-cleaner,
2131
-misc-no-recursion,
2232
-misc-unused-parameters,
2333
-readability-braces-around-statements,

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*.so
1414
.clangd
1515
.DS_Store
16+
code_analysis_report.log
1617
*.o
1718
.aider*
1819

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
7979
set (WAMR_BUILD_LIBC_WASI 1)
8080
endif ()
8181

82+
if (NOT DEFINED WAMR_BUILD_COMPONENT_MODEL)
83+
# Enable Component Model by default
84+
set (WAMR_BUILD_COMPONENT_MODEL 1)
85+
endif ()
86+
8287
if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
8388
# Enable fast interpreter
8489
set (WAMR_BUILD_FAST_INTERP 1)

build-scripts/config_common.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,13 @@ if (WAMR_BUILD_BRANCH_HINTS EQUAL 1)
779779
message (" Branch hints enabled")
780780
add_definitions(-DWASM_ENABLE_BRANCH_HINTS=1)
781781
endif ()
782-
782+
if (WAMR_BUILD_COMPONENT_MODEL EQUAL 1)
783+
message (" Component Model enabled")
784+
add_definitions(-DWASM_ENABLE_COMPONENT_MODEL=1)
785+
else()
786+
message (" Component Model disabled")
787+
add_definitions(-DWASM_ENABLE_COMPONENT_MODEL=0)
788+
endif ()
783789
########################################
784790
# Show Phase4 Wasm proposals status.
785791
########################################

build-scripts/runtime_lib.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ if (WAMR_BUILD_GC EQUAL 1)
8787
set (WAMR_BUILD_REF_TYPES 1)
8888
endif ()
8989

90+
if (WAMR_BUILD_COMPONENT_MODEL EQUAL 1)
91+
include (${IWASM_DIR}/common/component-model/iwasm_component.cmake)
92+
endif ()
93+
9094
if (WAMR_BUILD_LIBC_BUILTIN EQUAL 1)
9195
include (${IWASM_DIR}/libraries/libc-builtin/libc_builtin.cmake)
9296
endif ()
@@ -219,6 +223,7 @@ set (source_all
219223
${IWASM_COMPL_SOURCE}
220224
${IWASM_FAST_JIT_SOURCE}
221225
${IWASM_GC_SOURCE}
226+
${IWASM_COMPONENT_SOURCE}
222227
${LIB_WASI_THREADS_SOURCE}
223228
${LIB_PTHREAD_SOURCE}
224229
${THREAD_MGR_SOURCE}

code_analysis.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/sh
2+
3+
# Copyright (C) 2026 Airbus Defence and Space Romania SRL. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
# Prerequisites: clang-tidy and cppcheck (First time install: sudo apt-get update && sudo apt-get install -y clang-tidy cppcheck)
7+
# Prerequisite for clang-tidy: CMAKE_EXPORT_COMPILE_COMMANDS=ON
8+
rm -rf product-mini/platforms/linux/build && mkdir -p product-mini/platforms/linux/build
9+
cd product-mini/platforms/linux/build
10+
cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS=ON && make -j8
11+
cd ../../../../
12+
13+
# Define the target folders
14+
TARGET_DIRS="core/iwasm/interpreter \
15+
core/iwasm/common/component-model \
16+
tests/unit/component*"
17+
18+
# Define the log report file
19+
REPORT_FILE="code_analysis_report.log"
20+
echo "--- Running code analysis for: $TARGET_DIRS"
21+
echo "--- The analysis report will be written into $REPORT_FILE"
22+
23+
: > "$REPORT_FILE"
24+
exec > "$REPORT_FILE" 2>&1
25+
26+
echo "--- Running Cppcheck ---"
27+
cppcheck -q --force --enable=warning,performance,style,portability $TARGET_DIRS
28+
29+
echo "--- Running Clang-Tidy ---"
30+
FILES=$(find $TARGET_DIRS -name "*.c")
31+
HEADERS=$(find $TARGET_DIRS -name "*.h")
32+
$(command -v /opt/wasi-sdk/bin/clang-tidy || echo clang-tidy) -p product-mini/platforms/linux/build --quiet $HEADERS $FILES
33+
34+
TOTAL=$(grep -c ': error:' "$REPORT_FILE" 2>/dev/null || echo 0)
35+
printf "Total errors: $TOTAL"
36+
37+
for CHECK in \
38+
bugprone-narrowing-conversions \
39+
bugprone-multi-level-implicit-pointer-conversion \
40+
bugprone-null-dereference \
41+
bugprone-use-after-move \
42+
bugprone-sizeof-expression \
43+
clang-analyzer-core \
44+
clang-analyzer-security \
45+
clang-analyzer-deadcode \
46+
cppcoreguidelines-init-variables \
47+
cppcoreguidelines-narrowing-conversions \
48+
performance-no-int-to-ptr \
49+
readability-math-missing-parentheses \
50+
concurrency-mt-unsafe \
51+
cert-msc30-c \
52+
cert-err34-c \
53+
readability-redundant-casting; do
54+
COUNT=$(grep -c "$CHECK" "$REPORT_FILE" 2>/dev/null || echo 0)
55+
if [ "$COUNT" -gt 0 ]; then
56+
printf ' %-56s %d\n' "$CHECK:" "$COUNT" | tee -a "$REPORT_FILE"
57+
fi
58+
done
59+
60+
echo "--- Analysis complete. Check $REPORT_FILE ---"

core/config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@
137137
#define WASM_ENABLE_WAMR_COMPILER 0
138138
#endif
139139

140+
#ifndef WASM_ENABLE_COMPONENT_MODEL
141+
#define WASM_ENABLE_COMPONENT_MODEL 0
142+
#endif
143+
140144
#ifndef WASM_ENABLE_LIBC_BUILTIN
141145
#define WASM_ENABLE_LIBC_BUILTIN 0
142146
#endif

core/iwasm/aot/aot_runtime.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ bh_static_assert(offsetof(AOTModuleInstance, cur_exception)
5151
bh_static_assert(offsetof(AOTModuleInstance, c_api_func_imports)
5252
== 13 * sizeof(uint64) + 128 + 7 * sizeof(uint64));
5353
bh_static_assert(offsetof(AOTModuleInstance, global_table_data)
54-
== 13 * sizeof(uint64) + 128 + 14 * sizeof(uint64));
54+
== 13 * sizeof(uint64) + 128 + 14 * sizeof(uint64)
55+
#if WASM_ENABLE_COMPONENT_MODEL != 0
56+
+ sizeof(void *) + sizeof(uint64)
57+
#endif
58+
);
5559

5660
bh_static_assert(sizeof(AOTMemoryInstance) == 120);
5761
bh_static_assert(offsetof(AOTTableInstance, elems) == 24);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright (C) 2026 Airbus Defence and Space Romania SRL. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
set (IWASM_COMPONENT_DIR ${CMAKE_CURRENT_LIST_DIR})
5+
6+
add_definitions (-DWASM_ENABLE_COMPONENT_MODEL=1)
7+
8+
include_directories (${IWASM_COMPONENT_DIR})
9+
10+
file (GLOB source_all ${IWASM_COMPONENT_DIR}/*.c)
11+
12+
set (IWASM_COMPONENT_SOURCE ${source_all})

0 commit comments

Comments
 (0)