zephyr/cmake/compiler/compiler_flags_template.cmake
Stephanos Ioannidis 9672858c19 cmake: compiler: Add flag template for disabling strict aliasing rule
This commit adds a template for specifying the C/C++ compiler flag for
disabling the strict aliasing rule.

It also enables this flag globally because the Zephyr codebase does not
strictly adhere to the aliasing rules specified by the C/C++ standards
and the optimisation strategies that assume these rules may end up
generating invalid code.

For instance, GCC 11 and above tend to optimise more aggressively
assuming the strict adherence to the standard aliasing rules and may
generate invalid code, when compiling Zephyr with `-fstrict-aliasing`,
that results in various run-time failures.

Note that the footprint and performance ramifications of disabling the
strict aliasing rule are negligible.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2022-08-11 17:45:58 +02:00

117 lines
4.2 KiB
CMake

# Overview of used compiler properties for gcc / g++ compilers.
#
# Define the flags your toolchain support, and keep the unsupported flags empty.
#####################################################
# This section covers flags related to optimization #
#####################################################
set_compiler_property(PROPERTY no_optimization)
set_compiler_property(PROPERTY optimization_debug)
set_compiler_property(PROPERTY optimization_speed)
set_compiler_property(PROPERTY optimization_size)
#######################################################
# This section covers flags related to warning levels #
#######################################################
# Property for standard warning base in Zephyr, this will always bet set when compiling.
set_compiler_property(PROPERTY warning_base)
# GCC options for warning levels 1, 2, 3, when using `-DW=[1|2|3]`
# Property for warning levels 1, 2, 3 in Zephyr when using `-DW=[1|2|3]`
set_compiler_property(PROPERTY warning_dw_1)
set_compiler_property(PROPERTY warning_dw_2)
set_compiler_property(PROPERTY warning_dw_3)
# Extended warning set supported by the compiler
set_compiler_property(PROPERTY warning_extended)
# Compiler property that will issue error if a declaration does not specify a type
set_compiler_property(PROPERTY warning_error_implicit_int)
# Compiler flags to use when compiling according to MISRA
set_compiler_property(PROPERTY warning_error_misra_sane)
###########################################################################
# This section covers flags related to C or C++ standards / standard libs #
###########################################################################
# Compiler flags for C standard. The specific standard must be appended by user.
# For example, gcc specifies this as: set_compiler_property(PROPERTY cstd -std=)
set_compiler_property(PROPERTY cstd)
# Compiler flags for disabling C standard include and instead specify include
# dirs in nostdinc_include to use.
set_compiler_property(PROPERTY nostdinc)
set_compiler_property(PROPERTY nostdinc_include)
# Compiler flags for disabling C++ standard include.
set_compiler_property(TARGET compiler-cpp PROPERTY nostdincxx)
# Required C++ flags when compiling C++ code
set_property(TARGET compiler-cpp PROPERTY required)
# Compiler flags to use for specific C++ dialects
set_property(TARGET compiler-cpp PROPERTY dialect_cpp98)
set_property(TARGET compiler-cpp PROPERTY dialect_cpp11)
set_property(TARGET compiler-cpp PROPERTY dialect_cpp14)
set_property(TARGET compiler-cpp PROPERTY dialect_cpp17)
set_property(TARGET compiler-cpp PROPERTY dialect_cpp2a)
set_property(TARGET compiler-cpp PROPERTY dialect_cpp20)
set_property(TARGET compiler-cpp PROPERTY dialect_cpp2b)
# Flag for disabling strict aliasing rule in C and C++
set_compiler_property(PROPERTY no_strict_aliasing)
# Flag for disabling exceptions in C++
set_property(TARGET compiler-cpp PROPERTY no_exceptions)
# Flag for disabling rtti in C++
set_property(TARGET compiler-cpp PROPERTY no_rtti)
###################################################
# This section covers all remaining C / C++ flags #
###################################################
# Flags for coverage generation
set_compiler_property(PROPERTY coverage)
# Security canaries flags.
set_compiler_property(PROPERTY security_canaries)
set_compiler_property(PROPERTY security_fortify)
# Flag for a hosted (no-freestanding) application
set_compiler_property(PROPERTY hosted)
# gcc flag for a freestanding application
set_compiler_property(PROPERTY freestanding)
# Flag to include debugging symbol in compilation
set_compiler_property(PROPERTY debug)
set_compiler_property(PROPERTY no_common)
# Flags for imacros. The specific header must be appended by user.
set_compiler_property(PROPERTY imacros)
# Compiler flags for sanitizing.
set_compiler_property(PROPERTY sanitize_address)
set_compiler_property(PROPERTY sanitize_undefined)
# Compiler flag for turning off thread-safe initialization of local statics
set_property(TARGET compiler-cpp PROPERTY no_threadsafe_statics)
# Required ASM flags when compiling
set_property(TARGET asm PROPERTY required)
# Compiler flag for disabling pointer arithmetic warnings
set_compiler_property(PROPERTY warning_no_pointer_arithmetic)