mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
fix(build): add kconfig support for fortified toolchains
This commit is contained in:
parent
94580ab1e5
commit
7d392394dd
@ -240,8 +240,15 @@ if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE ${PX4_BUILD_TYPE} CACHE STRING "Build type" FORCE)
|
||||
endif()
|
||||
|
||||
if(CONFIG_BOARD_SUPPORT_FORTIFIED_TOOLCHAIN)
|
||||
set(PX4_DEBUG_OPT_LEVEL -Og)
|
||||
message(STATUS "fortified toolchain support enabled: PX4_DEBUG_OPT_LEVEL=${PX4_DEBUG_OPT_LEVEL}")
|
||||
else()
|
||||
set(PX4_DEBUG_OPT_LEVEL -O0)
|
||||
endif()
|
||||
|
||||
if((CMAKE_BUILD_TYPE STREQUAL "Debug") OR (CMAKE_BUILD_TYPE STREQUAL "Coverage"))
|
||||
set(MAX_CUSTOM_OPT_LEVEL -O0)
|
||||
set(MAX_CUSTOM_OPT_LEVEL ${PX4_DEBUG_OPT_LEVEL})
|
||||
elseif(CMAKE_BUILD_TYPE MATCHES "Sanitizer")
|
||||
set(MAX_CUSTOM_OPT_LEVEL -O1)
|
||||
elseif(CMAKE_BUILD_TYPE MATCHES "Release")
|
||||
|
||||
10
Kconfig
10
Kconfig
@ -67,6 +67,16 @@ menu "Toolchain"
|
||||
help
|
||||
Enables Cmake Release for -O3 optimization
|
||||
|
||||
config BOARD_SUPPORT_FORTIFIED_TOOLCHAIN
|
||||
bool "Fortified toolchain support"
|
||||
default n
|
||||
help
|
||||
Enable compatibility with toolchains that define
|
||||
_FORTIFY_SOURCE.
|
||||
|
||||
This switches PX4_DEBUG_OPT_LEVEL from -O0 to -Og. Keep this
|
||||
disabled unless the fortified toolchain requires optimization.
|
||||
|
||||
config BOARD_ROMFSROOT
|
||||
string "ROMFSROOT"
|
||||
default "px4fmu_common"
|
||||
|
||||
@ -52,10 +52,10 @@ endif()
|
||||
|
||||
# add code coverage build type
|
||||
if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES "AppleClang"))
|
||||
set(CMAKE_C_FLAGS_COVERAGE "--coverage -ftest-coverage -fdiagnostics-absolute-paths -O0 -fprofile-arcs -fno-inline-functions"
|
||||
set(CMAKE_C_FLAGS_COVERAGE "--coverage -ftest-coverage -fdiagnostics-absolute-paths ${PX4_DEBUG_OPT_LEVEL} -fprofile-arcs -fno-inline-functions"
|
||||
CACHE STRING "Flags used by the C compiler during coverage builds" FORCE)
|
||||
|
||||
set(CMAKE_CXX_FLAGS_COVERAGE "--coverage -ftest-coverage -fdiagnostics-absolute-paths -O0-fprofile-arcs -fno-inline-functions -fno-elide-constructors"
|
||||
set(CMAKE_CXX_FLAGS_COVERAGE "--coverage -ftest-coverage -fdiagnostics-absolute-paths ${PX4_DEBUG_OPT_LEVEL} -fprofile-arcs -fno-inline-functions -fno-elide-constructors"
|
||||
CACHE STRING "Flags used by the C++ compiler during coverage builds" FORCE)
|
||||
|
||||
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE "-ftest-coverage -fdiagnostics-absolute-paths"
|
||||
@ -63,11 +63,11 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") OR ("${CMAKE_CXX_COMPILER_ID}"
|
||||
|
||||
else()
|
||||
# Add -fprofile-abs-path for GCC v8/9 later on
|
||||
set(CMAKE_C_FLAGS_COVERAGE "--coverage -ftest-coverage -fprofile-arcs -O0 -fno-default-inline -fno-inline"
|
||||
set(CMAKE_C_FLAGS_COVERAGE "--coverage -ftest-coverage -fprofile-arcs ${PX4_DEBUG_OPT_LEVEL} -fno-default-inline -fno-inline"
|
||||
CACHE STRING "Flags used by the C compiler during coverage builds" FORCE)
|
||||
|
||||
# Add -fprofile-abs-path for GCC v8/9 later on
|
||||
set(CMAKE_CXX_FLAGS_COVERAGE "--coverage -ftest-coverage -fprofile-arcs -O0 -fno-default-inline -fno-inline -fno-elide-constructors"
|
||||
set(CMAKE_CXX_FLAGS_COVERAGE "--coverage -ftest-coverage -fprofile-arcs ${PX4_DEBUG_OPT_LEVEL} -fno-default-inline -fno-inline -fno-elide-constructors"
|
||||
CACHE STRING "Flags used by the C++ compiler during coverage builds" FORCE)
|
||||
|
||||
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE "--coverage -ftest-coverage -lgcov"
|
||||
|
||||
@ -70,3 +70,19 @@ The command line and GUI interfaces are shown below.
|
||||
### menuconfig Command Line Interface
|
||||
|
||||

|
||||
|
||||
## Fortified Toolchain Compatibility
|
||||
|
||||
Some toolchains define `_FORTIFY_SOURCE` by default. Those toolchains generally require some optimization, which means PX4 configurations that use `-O0` may fail.
|
||||
|
||||
PX4 keeps the default debug optimization unchanged unless you explicitly opt in. To switch `PX4_DEBUG_OPT_LEVEL` from `-O0` to `-Og`, enable:
|
||||
|
||||
- `Toolchain > Fortified toolchain support`
|
||||
|
||||
This is the Kconfig symbol:
|
||||
|
||||
```sh
|
||||
CONFIG_BOARD_SUPPORT_FORTIFIED_TOOLCHAIN=y
|
||||
```
|
||||
|
||||
You can set it either in `boardconfig`/`boardguiconfig` or directly in your board's `*.px4board` file.
|
||||
|
||||
@ -109,7 +109,7 @@ px4_add_module(
|
||||
COMPILE_FLAGS
|
||||
#-DCANARD_ASSERT
|
||||
-DUINT32_C\(x\)=__UINT32_C\(x\)
|
||||
-O0
|
||||
${PX4_DEBUG_OPT_LEVEL}
|
||||
${DRIVERS_CYPHAL_OPTIONS}
|
||||
INCLUDES
|
||||
${LIBCANARD_DIR}/libcanard/
|
||||
|
||||
@ -57,5 +57,5 @@ target_compile_options(world_magnetic_model PRIVATE ${MAX_CUSTOM_OPT_LEVEL})
|
||||
|
||||
if(BUILD_TESTING)
|
||||
px4_add_unit_gtest(SRC test_geo_lookup.cpp LINKLIBS world_magnetic_model)
|
||||
target_compile_options(unit-test_geo_lookup PRIVATE -O0 -Wno-double-promotion)
|
||||
target_compile_options(unit-test_geo_lookup PRIVATE ${PX4_DEBUG_OPT_LEVEL} -Wno-double-promotion)
|
||||
endif()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user