diff --git a/src/audio/microwakeword/CMakeLists.txt b/src/audio/microwakeword/CMakeLists.txt index 7a75435d9aa3..7c8e53f56b7a 100644 --- a/src/audio/microwakeword/CMakeLists.txt +++ b/src/audio/microwakeword/CMakeLists.txt @@ -21,6 +21,12 @@ set(FLATBUFFERS_PATH ${sof_top_dir}/../flatbuffers) set(GEMMLOWP_PATH ${sof_top_dir}/../gemmlowp) set(RUY_PATH ${sof_top_dir}/../ruy) +# Zephyr's -fmacro-prefix-map options don't reach the plain add_library() +# targets below, so TFLM's __FILE__ strings would embed the absolute host +# path and make the firmware differ between build machines. +get_filename_component(MWW_TOPDIR ${sof_top_dir}/.. ABSOLUTE) +set(MWW_PREFIX_MAP -fmacro-prefix-map=${MWW_TOPDIR}=WEST_TOPDIR) + set(MWW_TOOLCHAIN_LIBC_ARCHIVE "") if(CMAKE_C_COMPILER_ID STREQUAL "GNU") execute_process( @@ -204,6 +210,7 @@ target_compile_options(mww_tflm_lib PRIVATE -fno-tree-slp-vectorize -ffunction-sections -fdata-sections + ${MWW_PREFIX_MAP} -imacros ${AUTOCONF_H} ) @@ -292,6 +299,7 @@ if(CONFIG_COMP_MWW_HIFI_NNLIB AND ZEPHYR_TOOLCHAIN_VARIANT STREQUAL "xt-clang") -Dgcd=xa_nn_gcd -ffunction-sections -fdata-sections + ${MWW_PREFIX_MAP} ) set(MWW_NN_HIFI_LIB mww_nn_hifi_lib) else() diff --git a/src/audio/microwakeword/llext/CMakeLists.txt b/src/audio/microwakeword/llext/CMakeLists.txt index feb72a3041f8..26cefc3a5ef2 100644 --- a/src/audio/microwakeword/llext/CMakeLists.txt +++ b/src/audio/microwakeword/llext/CMakeLists.txt @@ -16,6 +16,10 @@ set(GEMMLOWP_PATH ${sof_top_dir}/../gemmlowp) set(RUY_PATH ${sof_top_dir}/../ruy) set(NN_HIFI_PATH ${sof_top_dir}/../nnlib-hifi4/xa_nnlib) +# Keep absolute host paths out of TFLM's __FILE__ strings, see +# ../CMakeLists.txt. +get_filename_component(MWW_TOPDIR ${sof_top_dir}/.. ABSOLUTE) + set(MWW_TOOLCHAIN_ROOT "") if(CMAKE_C_COMPILER_ID STREQUAL "GNU") execute_process( @@ -191,6 +195,7 @@ target_compile_options(mww_tflm_lib PRIVATE # ET_DYN/PIC LLEXT. -DTF_LITE_STRIP_ERROR_STRINGS -DNDEBUG + -fmacro-prefix-map=${MWW_TOPDIR}=WEST_TOPDIR -imacros ${AUTOCONF_H} ) diff --git a/src/platform/posix/ipc.c b/src/platform/posix/ipc.c index 64586755d18c..64fb21358962 100644 --- a/src/platform/posix/ipc.c +++ b/src/platform/posix/ipc.c @@ -39,6 +39,11 @@ extern size_t posix_fuzz_sz; static uint8_t fuzz_in[65536]; static size_t fuzz_in_sz; +/* Set on the driver thread by posix_fuzz_case_begin(), consumed on the EDF + * workqueue thread by ipc_platform_do_cmd(). See posix_fuzz_case_begin(). + */ +static bool posix_fuzz_teardown_pending; + /* * posix_ipc_teardown - drop all IPC-tracked objects left over from the * previous fuzz testcase so the next one starts from a clean topology. @@ -194,7 +199,15 @@ static void posix_ipc_teardown(void) */ void posix_fuzz_case_begin(void) { - posix_ipc_teardown(); + /* + * Defer the teardown to the EDF workqueue thread (ipc_platform_do_cmd()). + * This runs on the libFuzzer driver thread, where native_sim treats the + * CPU as halted; posix_ipc_teardown() releases spinlocks/mutexes, and + * releasing a spinlock while the system-tick IRQ is pending makes + * native_sim deliver it synchronously and abort ("called from a HW model + * thread"). + */ + posix_fuzz_teardown_pending = true; fuzz_in_sz = 0; } @@ -362,6 +375,17 @@ enum task_state ipc_platform_do_cmd(struct ipc *ipc) { struct ipc_cmd_hdr *hdr; +#ifdef CONFIG_ARCH_POSIX_LIBFUZZER + /* + * Reclaim the previous testcase's topology in thread context, before + * this testcase's first command. See posix_fuzz_case_begin(). + */ + if (posix_fuzz_teardown_pending) { + posix_fuzz_teardown_pending = false; + posix_ipc_teardown(); + } +#endif + #ifdef CONFIG_IPC_MAJOR_4 memset(posix_hostbox, 0, SOF_IPC_MSG_MAX_SIZE); memcpy(posix_hostbox,