diff --git a/CMakeLists.txt b/CMakeLists.txt index 24c26ed015d..128c2756b7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -463,6 +463,11 @@ if(EXISTS ${NUTTX_BOARD_ABS_DIR}/cmake include(${NUTTX_BOARD_ABS_DIR}/cmake/Toolchain.cmake) endif() +# Support loadable and kernel options by specific arch +if(EXISTS ${CMAKE_SOURCE_DIR}/arch/${CONFIG_ARCH}/src/cmake/elf.cmake) + include(${CMAKE_SOURCE_DIR}/arch/${CONFIG_ARCH}/src/cmake/elf.cmake) +endif() + include(platform) if(CONFIG_ARCH_TOOLCHAIN_TASKING) diff --git a/arch/arm/src/cmake/elf.cmake b/arch/arm/src/cmake/elf.cmake new file mode 100644 index 00000000000..e2d8e58a4ca --- /dev/null +++ b/arch/arm/src/cmake/elf.cmake @@ -0,0 +1,35 @@ +# ############################################################################## +# arch/arm/src/cmake/elf.cmake +# +# 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. +# +# ############################################################################## + +# Loadable and ELF module settings + +nuttx_elf_compile_options(-fvisibility=hidden -mlong-calls) + +nuttx_elf_compile_options_ifdef(CONFIG_UNWINDER_ARM -fno-unwind-tables + -fno-asynchronous-unwind-tables) + +nuttx_elf_compile_options_ifdef(CONFIG_PIC --fixed-r10 -mpic-register=r10) + +nuttx_elf_link_options_ifdef( + CONFIG_PIC --unresolved-symbols=ignore-in-object-files --emit-relocs) + +nuttx_elf_link_options_ifdef(CONFIG_BINFMT_ELF_RELOCATABLE -r) + +nuttx_elf_link_options_ifdef(CONFIG_BUILD_KERNEL -Bstatic) diff --git a/arch/arm/src/common/CMakeLists.txt b/arch/arm/src/common/CMakeLists.txt index 3bbbee40b44..a7758eef7ae 100644 --- a/arch/arm/src/common/CMakeLists.txt +++ b/arch/arm/src/common/CMakeLists.txt @@ -94,3 +94,8 @@ endif() target_sources(arch PRIVATE ${SRCS}) nuttx_add_aux_library(STARTUP_OBJS crt0.c) + +target_compile_options( + STARTUP_OBJS + PRIVATE + $>) diff --git a/arch/arm64/src/cmake/elf.cmake b/arch/arm64/src/cmake/elf.cmake new file mode 100644 index 00000000000..5b879c256aa --- /dev/null +++ b/arch/arm64/src/cmake/elf.cmake @@ -0,0 +1,27 @@ +# ############################################################################## +# arch/arm/src/cmake/elf.cmake +# +# 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. +# +# ############################################################################## + +# Loadable and ELF module settings + +nuttx_elf_compile_options(-fvisibility=hidden) + +nuttx_elf_link_options_ifdef(CONFIG_BINFMT_ELF_RELOCATABLE -r) + +nuttx_elf_link_options_ifdef(CONFIG_BUILD_KERNEL -Bstatic) diff --git a/arch/arm64/src/common/CMakeLists.txt b/arch/arm64/src/common/CMakeLists.txt index 335cf602a48..acb82f39619 100644 --- a/arch/arm64/src/common/CMakeLists.txt +++ b/arch/arm64/src/common/CMakeLists.txt @@ -136,3 +136,10 @@ if(CONFIG_ARM64_SEMIHOSTING_HOSTFS) endif() target_sources(arch PRIVATE ${SRCS}) + +nuttx_add_aux_library(STARTUP_OBJS crt0.c) + +target_compile_options( + STARTUP_OBJS + PRIVATE + $>) diff --git a/cmake/nuttx_add_application.cmake b/cmake/nuttx_add_application.cmake index 2e95a9f4fb7..4dd70a872bc 100644 --- a/cmake/nuttx_add_application.cmake +++ b/cmake/nuttx_add_application.cmake @@ -126,17 +126,21 @@ function(nuttx_add_application) COMMAND ${CMAKE_LD} $> - -e __start -Bstatic -T ${CMAKE_BINARY_DIR}/gnu-elf.ld + -e __start -T ${CMAKE_BINARY_DIR}/gnu-elf.ld $ --start-group - $> + $<$:$>> + $> $ --end-group -o ${CMAKE_BINARY_DIR}/bin/${ELF_NAME} + COMMENT "Building ELF:${ELF_NAME}" COMMAND_EXPAND_LISTS) else() add_executable(${TARGET} ${SRCS}) target_link_options( - ${TARGET} PRIVATE - $>) + ${TARGET} + PRIVATE + $> + ) endif() # easy access to final ELF, regardless of how it was created @@ -148,10 +152,11 @@ function(nuttx_add_application) # loadable build requires applying ELF flags to all applications if(CONFIG_MODULES) + add_dependencies(nuttx_apps_mksymtab ${TARGET}) target_compile_options( ${TARGET} PRIVATE - $> + $> ) endif() @@ -165,24 +170,6 @@ function(nuttx_add_application) set(TARGET "apps_${NAME}") add_library(${TARGET} ${SRCS}) - # Set apps global compile options & definitions hold by - # nuttx_apps_interface - target_compile_options( - ${TARGET} - PRIVATE - $> - ) - target_compile_definitions( - ${TARGET} - PRIVATE - $> - ) - target_include_directories( - ${TARGET} - PRIVATE - $> - ) - nuttx_add_library_internal(${TARGET}) # add to list of application libraries @@ -247,6 +234,23 @@ function(nuttx_add_application) target_include_directories(${TARGET} BEFORE PRIVATE ${INCLUDE_DIRECTORIES}) endif() + + # Set apps global compile options & definitions hold by nuttx_apps_interface + target_compile_options( + ${TARGET} + PRIVATE + $> + ) + target_compile_definitions( + ${TARGET} + PRIVATE + $> + ) + target_include_directories( + ${TARGET} + PRIVATE + $> + ) endif() # add supplied dependencies diff --git a/cmake/nuttx_add_library.cmake b/cmake/nuttx_add_library.cmake index 31a55455be7..c9c82b676d4 100644 --- a/cmake/nuttx_add_library.cmake +++ b/cmake/nuttx_add_library.cmake @@ -258,12 +258,10 @@ function(nuttx_add_extra_library) set_property(GLOBAL APPEND PROPERTY NUTTX_USER_EXTRA_LIBRARIES ${extra_target}) endif() - if(CONFIG_BUILD_KERNEL) - set_property( - TARGET nuttx_global - APPEND - PROPERTY NUTTX_ELF_LINK_LIBRARIES $) - endif() + set_property( + TARGET nuttx_global + APPEND + PROPERTY NUTTX_ELF_LINK_EXTRA_LIBRARIES $) endif() endforeach() endfunction() diff --git a/cmake/nuttx_extensions.cmake b/cmake/nuttx_extensions.cmake index 4d76d779245..9b6807a56a9 100644 --- a/cmake/nuttx_extensions.cmake +++ b/cmake/nuttx_extensions.cmake @@ -257,6 +257,78 @@ function(nuttx_compile_options_ifndef cond) endif() endfunction() +# Function: nuttx_elf_compile_options +# +# Adds compile options to elf targets +# +# Usage: nuttx_elf_compile_options("-O2" "-Wall") +function(nuttx_elf_compile_options) + set_property( + TARGET nuttx_global + APPEND + PROPERTY NUTTX_ELF_APP_COMPILE_OPTIONS ${ARGN}) +endfunction() + +# Function: nuttx_elf_compile_options_ifdef +# +# Conditionally adds compile options to the elf target if the given condition is +# true. +# +# Usage: nuttx_elf_compile_options_ifdef(MY_CONDITION "-O2" "-Wall") +function(nuttx_elf_compile_options_ifdef cond) + if(${cond}) + nuttx_elf_compile_options(${ARGN}) + endif() +endfunction() + +# Function: nuttx_elf_compile_options_ifndef +# +# Conditionally adds compile options to the elf target if the given condition is +# false. +# +# Usage: nuttx_elf_compile_options_ifndef(MY_CONDITION "-O2" "-Wall") +function(nuttx_elf_compile_options_ifndef cond) + if(NOT ${cond}) + nuttx_elf_compile_options(${ARGN}) + endif() +endfunction() + +# Function: nuttx_elf_link_options +# +# Adds link options to elf targets +# +# Usage: nuttx_elf_link_options("-r") +function(nuttx_elf_link_options) + set_property( + TARGET nuttx_global + APPEND + PROPERTY NUTTX_ELF_APP_LINK_OPTIONS ${ARGN}) +endfunction() + +# Function: nuttx_elf_link_options_ifdef +# +# Conditionally adds link options to the elf target if the given condition is +# true. +# +# Usage: nuttx_elf_link_options_ifdef(MY_CONDITION "-r") +function(nuttx_elf_link_options_ifdef cond) + if(${cond}) + nuttx_elf_link_options(${ARGN}) + endif() +endfunction() + +# Function: nuttx_elf_link_options_ifndef +# +# Conditionally adds link options to the elf target if the given condition is +# false. +# +# Usage: nuttx_elf_link_options_ifndef(MY_CONDITION "-r") +function(nuttx_elf_link_options_ifndef cond) + if(NOT ${cond}) + nuttx_elf_link_options(${ARGN}) + endif() +endfunction() + # the visible scope is all the APPS include search path function(nuttx_include_directories_for_all_apps) set_property( diff --git a/libs/libc/elf/CMakeLists.txt b/libs/libc/elf/CMakeLists.txt index cb9e3dc21b2..5a0edc78cba 100644 --- a/libs/libc/elf/CMakeLists.txt +++ b/libs/libc/elf/CMakeLists.txt @@ -57,5 +57,5 @@ if(CONFIG_LIBC_ELF) add_custom_target(elfldscript_tmp DEPENDS ${ELF_LD_SCRIPT_TMP}) add_dependencies(nuttx elfldscript_tmp) - + add_dependencies(apps_post elfldscript_tmp) endif()