Harden LinuxCNC wasm and native probe workflows
This commit is contained in:
167
test-linuxcnc-wasm-rs274ngc-pre-link-blockers.sh
Executable file
167
test-linuxcnc-wasm-rs274ngc-pre-link-blockers.sh
Executable file
@@ -0,0 +1,167 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
linuxcnc_root=${LINUXCNC_ROOT:-../linuxcnc}
|
||||
cxx=${CXX:-g++}
|
||||
build_dir=$(mktemp -d "${TMPDIR:-/tmp}/cnc_sim_linuxcnc_wasm_rs274ngc_pre_link_blockers.XXXXXX")
|
||||
report_file=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_linuxcnc_wasm_rs274ngc_pre_undefined.XXXXXX.txt")
|
||||
manifest=${1:-linuxcnc-rs274-wasm-source-files.txt}
|
||||
|
||||
if [[ ! -f "$manifest" ]]; then
|
||||
echo "missing manifest: $manifest" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -d "$linuxcnc_root" ]]; then
|
||||
echo "missing LinuxCNC root: $linuxcnc_root" >&2
|
||||
exit 1
|
||||
fi
|
||||
trap 'rm -rf "$build_dir"' EXIT
|
||||
|
||||
common_flags=(
|
||||
-std=c++20
|
||||
-DULAPI
|
||||
-ffunction-sections
|
||||
-fdata-sections
|
||||
-include wctype.h
|
||||
-I "$(pwd)/core/include"
|
||||
-I "$(pwd)/core/wasm_shims"
|
||||
-I "$linuxcnc_root/src"
|
||||
-I "$linuxcnc_root/src/emc"
|
||||
-I "$linuxcnc_root/src/emc/nml_intf"
|
||||
-I "$linuxcnc_root/src/emc/rs274ngc"
|
||||
-I "$linuxcnc_root/src/emc/motion"
|
||||
-I "$linuxcnc_root/include"
|
||||
)
|
||||
|
||||
shim_sources=(
|
||||
core/wasm_shims/dlfcn.cc
|
||||
core/wasm_shims/emc_status_shim.cc
|
||||
core/wasm_shims/gettext_shim.cc
|
||||
core/wasm_shims/linuxcnc_runtime_shim.cc
|
||||
core/wasm_shims/python_c_api_shim.cc
|
||||
core/wasm_shims/rtapi_compat.cc
|
||||
core/wasm_shims/tooldata/tooldata_mmap_backend.cc
|
||||
core/wasm_shims/tooldata/tooldata_runtime_stubs.cc
|
||||
core/wasm_shims/pythonplugin/python_plugin.cc
|
||||
)
|
||||
|
||||
project_sources=(
|
||||
core/src/canon_event_sink.cpp
|
||||
core/src/linuxcnc_canon_bridge.cpp
|
||||
core/src/linuxcnc_tooldata_fixture.cpp
|
||||
core/src/rtcp_kinematics.cpp
|
||||
)
|
||||
|
||||
linuxcnc_sources=()
|
||||
while IFS=: read -r group path note; do
|
||||
case "$group" in
|
||||
core)
|
||||
if [[ ! -f "$linuxcnc_root/$path" ]]; then
|
||||
echo "missing manifest source: $path" >&2
|
||||
exit 1
|
||||
fi
|
||||
linuxcnc_sources+=("$linuxcnc_root/$path")
|
||||
;;
|
||||
""|\#*|blocked)
|
||||
;;
|
||||
*)
|
||||
echo "unknown manifest group: $group" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done < "$manifest"
|
||||
|
||||
shim_index=0
|
||||
for source in "${shim_sources[@]}"; do
|
||||
obj="$build_dir/shim_${shim_index}.o"
|
||||
"$cxx" "${common_flags[@]}" -c "$source" -o "$obj"
|
||||
shim_index=$((shim_index + 1))
|
||||
done
|
||||
|
||||
project_index=0
|
||||
for source in "${project_sources[@]}"; do
|
||||
obj="$build_dir/project_${project_index}.o"
|
||||
"$cxx" "${common_flags[@]}" -c "$source" -o "$obj"
|
||||
project_index=$((project_index + 1))
|
||||
done
|
||||
|
||||
linuxcnc_index=0
|
||||
for source in "${linuxcnc_sources[@]}"; do
|
||||
obj="$build_dir/linuxcnc_${linuxcnc_index}.o"
|
||||
"$cxx" "${common_flags[@]}" -c "$source" -o "$obj"
|
||||
linuxcnc_index=$((linuxcnc_index + 1))
|
||||
done
|
||||
|
||||
undefined_file="$build_dir/undefined.raw"
|
||||
defined_file="$build_dir/defined.raw"
|
||||
|
||||
nm -u "$build_dir"/*.o \
|
||||
| awk '{print $2}' \
|
||||
| sed '/^$/d' \
|
||||
| LC_ALL=C sort -u \
|
||||
> "$undefined_file"
|
||||
|
||||
nm --defined-only "$build_dir"/*.o \
|
||||
| awk '{print $3}' \
|
||||
| sed '/^$/d' \
|
||||
| LC_ALL=C sort -u \
|
||||
> "$defined_file"
|
||||
|
||||
{
|
||||
comm -23 "$undefined_file" "$defined_file" \
|
||||
| grep -Ev '^(_GLOBAL_OFFSET_TABLE_|_Unwind_Resume)$' \
|
||||
| grep -Ev '^(__assert_fail|__cxa_|__divdc3|__dso_handle|__errno_location|__gxx_personality_v0|__isoc23_|__muldc3|__stack_chk_fail)' \
|
||||
| grep -Ev '^(abort|access|acos|asin|atan2|atof|atoi|basename|cabs|calloc|ceil|close|closedir|copysign|cos|cosl|exit|exp|fclose|fdatasync|fdopen|feof|fflush|fgetc|fgets|fileno|floor|fmod|fopen|fprintf|fputs|free|freelocale|fseek|fstat|ftell|fwrite|getcwd|getenv|getpid|gettimeofday|hypot|islower|isprint|isspace|isupper|isxdigit|link|localtime|log|lstat|malloc|memchr|memcmp|memcpy|memmove|memset|mkstemp|nearbyint|newlocale|open|opendir|perror|pow|printf|pthread_mutex_lock|pthread_mutex_unlock|putc|puts|read|readdir|realpath|realloc|remove|rename|setlocale|sin|sinl|snprintf|sprintf|sqrt|sscanf|stat|stderr|stdout|strcasecmp|strcat|strchr|strcmp|strcpy|strdup|strerror|strlen|strncasecmp|strncat|strncmp|strncpy|strrchr|strspn|strstr|strtod|strtok_r|strtol|strtoul|tan|tanl|tolower|toupper|towlower|unlink|uselocale|vfprintf|vsnprintf|wordexp|wordfree)$' \
|
||||
| grep -Ev '^(_ZN3fmt|_ZSt|_ZNSt|_ZNKSt|_ZNKRSt|_ZNS|_ZTI|_ZTS|_ZTV|_Zdl|_Znwm|_Znam|_Zda|_ZdaPv|_ZdaPvm|_ZdlPvm|_ZTv|_ZTh)'
|
||||
} > "$report_file" || true
|
||||
|
||||
if grep -F "_ZN6Interp13read_commentEPcPiP12block_structPd" "$report_file" >/dev/null; then
|
||||
echo "unexpected unresolved read_comment after interp_read.cc" >&2
|
||||
exit 1
|
||||
fi
|
||||
if grep -F "_ZN6Interp15find_tool_indexEP5setupiPi" "$report_file" >/dev/null; then
|
||||
echo "unexpected unresolved find_tool_index after interp_find.cc" >&2
|
||||
exit 1
|
||||
fi
|
||||
if grep -F "_ZN6Interp16find_named_paramEPKcPiPd" "$report_file" >/dev/null; then
|
||||
echo "unexpected unresolved find_named_param after interp_namedparams.cc" >&2
|
||||
exit 1
|
||||
fi
|
||||
if grep -Fx "emcStatus" "$report_file" >/dev/null; then
|
||||
echo "unexpected unresolved emcStatus after shim" >&2
|
||||
exit 1
|
||||
fi
|
||||
if grep -Fx "gettext" "$report_file" >/dev/null; then
|
||||
echo "unexpected unresolved gettext after shim" >&2
|
||||
exit 1
|
||||
fi
|
||||
if grep -Fx "_task" "$report_file" >/dev/null; then
|
||||
echo "unexpected unresolved _task after runtime shim" >&2
|
||||
exit 1
|
||||
fi
|
||||
if grep -Fx "builtin_modules" "$report_file" >/dev/null; then
|
||||
echo "unexpected unresolved builtin_modules after runtime shim" >&2
|
||||
exit 1
|
||||
fi
|
||||
for hal_symbol in \
|
||||
hal_get_param_value_by_name \
|
||||
hal_get_pin_value_by_name \
|
||||
hal_get_signal_value_by_name \
|
||||
hal_init \
|
||||
hal_ready; do
|
||||
if grep -Fx "$hal_symbol" "$report_file" >/dev/null; then
|
||||
echo "unexpected unresolved $hal_symbol after runtime shim" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
if [[ -s "$report_file" ]]; then
|
||||
echo "unexpected unresolved project symbols after rs274ngc_pre shim coverage:" >&2
|
||||
sed -n '1,120p' "$report_file" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "linuxcnc wasm rs274ngc_pre link blocker scan passed"
|
||||
echo "wrote $report_file"
|
||||
Reference in New Issue
Block a user