This is an automated email from the ASF dual-hosted git repository. GUIDINGLI pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 972edd6fa6494a590aaa975a5d7738bee496a4e8 Author: xuxin19 <[email protected]> AuthorDate: Wed Jun 4 21:51:16 2025 +0800 syscall/wraps: generate syscall_wraps.ldcmd in the CMake build With CONFIG_SCHED_INSTRUMENTATION_SYSCALL=y and CONFIG_LIB_SYSCALL=n, the Makefile build preprocesses syscall_wraps.h into syscall_wraps.ldcmd and passes it to the linker, so that system calls are routed through the __wrap_ functions. The CMake build only had a TODO for this, so the instrumentation was not linked in. Generate syscall_wraps.ldcmd with -Wl,--wrap= options and add it to the nuttx link. Skip it on sim for now: the final sim link also contains the host objects, which must keep calling the host libc, so the wraps would have to be applied to the partial link of nuttx.rel only. Signed-off-by: xuxin19 <[email protected]> --- syscall/wraps/CMakeLists.txt | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/syscall/wraps/CMakeLists.txt b/syscall/wraps/CMakeLists.txt index a443323ba38..d37077e404e 100644 --- a/syscall/wraps/CMakeLists.txt +++ b/syscall/wraps/CMakeLists.txt @@ -31,9 +31,30 @@ add_custom_command( WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} DEPENDS mksyscall) -# TODO: SYSCALLWRAPS = syscall_wraps.ldcmd $(Q) $(CPP) $(CPPFLAGS) -# $(SYSCALLWRAPS:.ldcmd=.h) | \ sed -e '1,/WRAPOPTSTARTS/d' -e '/^#/d' > -# $(SYSCALLWRAPS) +# On sim the final link also contains the host objects, which must keep calling +# the host libc. The wraps would have to be applied to nuttx.rel only, so skip +# them there. + +if(NOT CONFIG_ARCH_SIM) + set(WRAP_LD_CMD "${CMAKE_BINARY_DIR}/syscall_wraps.ldcmd") + + add_custom_command( + OUTPUT ${WRAP_LD_CMD} + COMMAND + ${PREPROCESS} -I${CMAKE_BINARY_DIR}/include -I${NUTTX_DIR}/include + -I${NUTTX_CHIP_ABS_DIR} ${CMAKE_CURRENT_LIST_DIR}/../syscall_wraps.h > + ${WRAP_LD_CMD}tmp + COMMAND + bash -c + "sed -e '1,/WRAPOPTSTARTS/d' -e '/^#/d' -e 's/--wrap /-Wl,--wrap=/g' ${WRAP_LD_CMD}tmp > ${WRAP_LD_CMD}" + DEPENDS ${CMAKE_CURRENT_LIST_DIR}/../syscall_wraps.h + VERBATIM) + + add_custom_target(wrap_ld_cmd DEPENDS ${WRAP_LD_CMD}) + add_dependencies(nuttx wrap_ld_cmd) + + target_link_options(nuttx PRIVATE "@${WRAP_LD_CMD}") +endif() # add sources to target target_sources(wraps PRIVATE ${SYSCALLS})
