diff --git a/CMakeLists.txt b/CMakeLists.txt index 69f856617aa..5b2c5d4b224 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -416,6 +416,10 @@ include(platform) # Setup main nuttx target #################################################### add_executable(nuttx) +if(CONFIG_BUILD_PROTECTED) + add_executable(nuttx_user) +endif() + add_dependencies(nuttx nuttx_context) if(WIN32) @@ -604,9 +608,6 @@ get_property(nuttx_extra_libs GLOBAL PROPERTY NUTTX_EXTRA_LIBRARIES) if(CONFIG_BUILD_FLAT) get_property(nuttx_system_libs GLOBAL PROPERTY NUTTX_SYSTEM_LIBRARIES) -endif() - -if(NOT CONFIG_BUILD_KERNEL) get_property(nuttx_apps_libs GLOBAL PROPERTY NUTTX_APPS_LIBRARIES) endif() @@ -742,25 +743,36 @@ endif() # Userspace portion ########################################################## if(CONFIG_BUILD_PROTECTED) - add_executable(nuttx_user) get_property(nuttx_system_libs GLOBAL PROPERTY NUTTX_SYSTEM_LIBRARIES) + get_property(nuttx_apps_libs GLOBAL PROPERTY NUTTX_APPS_LIBRARIES) + get_property(user_ldscript GLOBAL PROPERTY LD_SCRIPT_USER) list(TRANSFORM user_ldscript PREPEND "-Wl,--script=") + execute_process( + COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} ${NUTTX_EXTRA_FLAGS} + --print-libgcc-file-name + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE nuttx_user_libgcc) + + # reset link options for userspace to prevent sections from being accidentally + # deleted + set_target_properties(nuttx_user PROPERTIES LINK_OPTIONS "") + target_link_options( nuttx_user PRIVATE -nostartfiles -nodefaultlibs - -Wl,--entry=${CONFIG_USER_ENTRYPOINT} - -Wl,--undefined=${CONFIG_USER_ENTRYPOINT}) + -Wl,--entry=${CONFIG_INIT_ENTRYPOINT} + -Wl,--undefined=${CONFIG_INIT_ENTRYPOINT}) target_link_libraries( nuttx_user PRIVATE ${user_ldscript} - userspace $<$>:-Wl,--start-group> ${nuttx_system_libs} - gcc + ${nuttx_apps_libs} + ${nuttx_user_libgcc} $<$:supc++> $<$>:-Wl,--end-group>) diff --git a/arch/arm/src/common/CMakeLists.txt b/arch/arm/src/common/CMakeLists.txt index ac630ec46b9..5776283ea23 100644 --- a/arch/arm/src/common/CMakeLists.txt +++ b/arch/arm/src/common/CMakeLists.txt @@ -59,7 +59,8 @@ if(CONFIG_BUILD_PROTECTED OR CONFIG_BUILD_KERNEL) list(APPEND SRCS arm_task_start.c arm_pthread_start.c arm_signal_dispatch.c) if(CONFIG_BUILD_PROTECTED) - list(APPEND SRCS ${ARCH_TOOLCHAIN_PATH}/arm_signal_handler.S) + target_sources(arch_interface + PRIVATE ${ARCH_TOOLCHAIN_PATH}/arm_signal_handler.S) endif() endif() diff --git a/arch/risc-v/src/common/CMakeLists.txt b/arch/risc-v/src/common/CMakeLists.txt index a240435682e..164d828bd64 100644 --- a/arch/risc-v/src/common/CMakeLists.txt +++ b/arch/risc-v/src/common/CMakeLists.txt @@ -51,7 +51,7 @@ endif() if(NOT CONFIG_BUILD_FLAT) list(APPEND SRCS riscv_task_start.c riscv_pthread_start.c riscv_signal_dispatch.c) - list(APPEND SRCS riscv_signal_handler.S) + target_sources(arch_interface PRIVATE riscv_signal_handler.S) endif() if(CONFIG_SCHED_BACKTRACE) diff --git a/boards/arm/tiva/lm3s6965-ek/CMakeLists.txt b/boards/arm/tiva/lm3s6965-ek/CMakeLists.txt index d2081c5c05e..43e258b869a 100644 --- a/boards/arm/tiva/lm3s6965-ek/CMakeLists.txt +++ b/boards/arm/tiva/lm3s6965-ek/CMakeLists.txt @@ -20,7 +20,7 @@ add_subdirectory(src) -if(NOT CONFIG_BUILD_FLAT) +if(CONFIG_BUILD_PROTECTED) add_subdirectory(kernel) set_property( GLOBAL PROPERTY LD_SCRIPT_USER ${CMAKE_CURRENT_LIST_DIR}/scripts/memory.ld diff --git a/boards/arm/tiva/lm3s6965-ek/kernel/CMakeLists.txt b/boards/arm/tiva/lm3s6965-ek/kernel/CMakeLists.txt new file mode 100644 index 00000000000..fa755dfe96f --- /dev/null +++ b/boards/arm/tiva/lm3s6965-ek/kernel/CMakeLists.txt @@ -0,0 +1,21 @@ +# ############################################################################## +# boards/arm/tiva/lm3s6965-ek/kernel/CMakeLists.txt +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with this work for +# additional information regarding copyright ownership. The ASF licenses this +# file to you under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +# ############################################################################## + +target_sources(nuttx_user PRIVATE lm_userspace.c)