Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 59 additions & 64 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ set(OFFSETS_H_TARGET offsets_h)
set(SYSCALL_LIST_H_TARGET syscall_list_h_target)
set(DRIVER_VALIDATION_H_TARGET driver_validation_h_target)
set(KOBJ_TYPES_H_TARGET kobj_types_h_target)
set(PARSE_SYSCALLS_TARGET parse_syscalls_target)
set(DEVICE_API_LD_TARGET device_api_ld_target)

define_property(GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT BRIEF_DOCS " " FULL_DOCS " ")
Expand Down Expand Up @@ -344,6 +343,18 @@ if (CONFIG_PICOLIBC AND NOT CONFIG_PICOLIBC_IO_FLOAT)
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,no_printf_return_value>>)
endif()

if(CONFIG_UBSAN)
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,sanitizer_undefined>>)
zephyr_link_libraries($<TARGET_PROPERTY:linker,sanitizer_undefined>)
if(CONFIG_UBSAN_LIBRARY)
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,sanitizer_undefined_library>>)
zephyr_link_libraries($<TARGET_PROPERTY:linker,sanitizer_undefined_library>)
elseif(CONFIG_UBSAN_TRAP)
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,sanitizer_undefined_trap>>)
zephyr_link_libraries($<TARGET_PROPERTY:linker,sanitizer_undefined_trap>)
endif()
endif()

# @Intent: Set compiler specific flag for tentative definitions, no-common
zephyr_compile_options($<TARGET_PROPERTY:compiler,no_common>)

Expand Down Expand Up @@ -822,7 +833,7 @@ add_custom_command(
--file-list ${syscalls_file_list_output}
$<$<BOOL:${CONFIG_EMIT_ALL_SYSCALLS}>:--emit-all-syscalls>
DEPENDS ${syscalls_subdirs_trigger} ${PARSE_SYSCALLS_HEADER_DEPENDS}
${syscalls_file_list_output} ${syscalls_interface}
${syscalls_file_list_output} syscalls_interface
)

# Make sure Picolibc is built before the rest of the system; there's no explicit
Expand All @@ -840,12 +851,6 @@ set_property(TARGET ${SYSCALL_LIST_H_TARGET}
${CMAKE_CURRENT_BINARY_DIR}/include/generated/zephyr/syscalls
)

add_custom_target(${PARSE_SYSCALLS_TARGET}
DEPENDS
${syscalls_json}
${struct_tags_json}
)

# 64-bit systems do not require special handling of 64-bit system call
# parameters or return values, indicate this to the system call boilerplate
# generation script.
Expand Down Expand Up @@ -888,30 +893,24 @@ add_custom_command(
COMMAND
${LEGACY_SYSCALL_LIST_H_ARGS}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${PARSE_SYSCALLS_TARGET}
DEPENDS ${syscalls_json}
)

# This is passed into all calls to the gen_kobject_list.py script.
set(gen_kobject_list_include_args --include-subsystem-list ${struct_tags_json})
include(${ZEPHYR_BASE}/cmake/kobj.cmake)

set(DRV_VALIDATION ${PROJECT_BINARY_DIR}/include/generated/zephyr/driver-validation.h)
add_custom_command(
OUTPUT ${DRV_VALIDATION}
COMMAND
${PYTHON_EXECUTABLE}
${ZEPHYR_BASE}/scripts/build/gen_kobject_list.py
--validation-output ${DRV_VALIDATION}
${gen_kobject_list_include_args}
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
DEPENDS
${ZEPHYR_BASE}/scripts/build/gen_kobject_list.py
${PARSE_SYSCALLS_TARGET}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
gen_kobject_list(
TARGET ${DRIVER_VALIDATION_H_TARGET}
OUTPUTS ${DRV_VALIDATION}
SCRIPT_ARGS --validation-output ${DRV_VALIDATION}
INCLUDES ${struct_tags_json}
DEPENDS ${struct_tags_json}
)
add_custom_target(${DRIVER_VALIDATION_H_TARGET} DEPENDS ${DRV_VALIDATION})

include(${ZEPHYR_BASE}/cmake/kobj.cmake)
gen_kobj(KOBJ_INCLUDE_PATH)
gen_kobject_list_headers(
INCLUDES ${struct_tags_json}
DEPENDS ${struct_tags_json}
)

# Generate sections for kernel device subsystems
set(
Expand Down Expand Up @@ -1110,7 +1109,6 @@ if(CONFIG_USERSPACE)
NO_COVERAGE_FLAGS "${compiler_flags_priv}"
)

set(GEN_KOBJ_LIST ${ZEPHYR_BASE}/scripts/build/gen_kobject_list.py)
set(PROCESS_GPERF ${ZEPHYR_BASE}/scripts/build/process_gperf.py)
endif()

Expand Down Expand Up @@ -1264,23 +1262,13 @@ if(CONFIG_USERSPACE)
set(KOBJECT_PREBUILT_HASH_OUTPUT_SRC_PRE kobject_prebuilt_hash_preprocessed.c)
set(KOBJECT_PREBUILT_HASH_OUTPUT_SRC kobject_prebuilt_hash.c)

add_custom_command(
gen_kobject_list_gperf(
TARGET kobj_prebuilt_hash_list
OUTPUT ${KOBJECT_PREBUILT_HASH_LIST}
COMMAND
${PYTHON_EXECUTABLE}
${GEN_KOBJ_LIST}
--kernel $<TARGET_FILE:${ZEPHYR_LINK_STAGE_EXECUTABLE}>
--gperf-output ${KOBJECT_PREBUILT_HASH_LIST}
${gen_kobject_list_include_args}
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
DEPENDS
${ZEPHYR_LINK_STAGE_EXECUTABLE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
KERNEL_TARGET ${ZEPHYR_LINK_STAGE_EXECUTABLE}
INCLUDES ${struct_tags_json}
DEPENDS ${struct_tags_json}
)
add_custom_target(
kobj_prebuilt_hash_list
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_PREBUILT_HASH_LIST}
)

add_custom_command(
OUTPUT ${KOBJECT_PREBUILT_HASH_OUTPUT_SRC_PRE}
Expand Down Expand Up @@ -1471,23 +1459,13 @@ if(CONFIG_USERSPACE)
# Use the script GEN_KOBJ_LIST to scan the kernel binary's
# (${ZEPHYR_LINK_STAGE_EXECUTABLE}) DWARF information to produce a table of kernel
# objects (KOBJECT_HASH_LIST) which we will then pass to gperf
add_custom_command(
gen_kobject_list_gperf(
TARGET kobj_hash_list
OUTPUT ${KOBJECT_HASH_LIST}
COMMAND
${PYTHON_EXECUTABLE}
${GEN_KOBJ_LIST}
--kernel $<TARGET_FILE:${ZEPHYR_LINK_STAGE_EXECUTABLE}>
--gperf-output ${KOBJECT_HASH_LIST}
${gen_kobject_list_include_args}
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
DEPENDS
${ZEPHYR_LINK_STAGE_EXECUTABLE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
KERNEL_TARGET ${ZEPHYR_LINK_STAGE_EXECUTABLE}
INCLUDES ${struct_tags_json}
DEPENDS ${struct_tags_json}
)
add_custom_target(
kobj_hash_list
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_HASH_LIST}
)

# Use gperf to generate C code (KOBJECT_HASH_OUTPUT_SRC_PRE) which implements a
# perfect hashtable based on KOBJECT_HASH_LIST
Expand Down Expand Up @@ -1750,13 +1728,8 @@ if(CONFIG_BUILD_OUTPUT_ADJUST_LMA)
)
endif()

if(NOT CONFIG_CPP_EXCEPTIONS)
set(eh_frame_section ".eh_frame")
else()
set(eh_frame_section "")
endif()
set(remove_sections_argument_list "")
foreach(section .comment COMMON ${eh_frame_section})
foreach(section .comment COMMON)
list(APPEND remove_sections_argument_list
$<TARGET_PROPERTY:bintools,elfconvert_flag_section_remove>${section})
endforeach()
Expand Down Expand Up @@ -1837,6 +1810,28 @@ if(CONFIG_BUILD_OUTPUT_BIN AND CONFIG_BUILD_OUTPUT_UF2)
set(BYPRODUCT_KERNEL_UF2_NAME "${PROJECT_BINARY_DIR}/${KERNEL_UF2_NAME}" CACHE FILEPATH "Kernel uf2 file" FORCE)
endif()

if(CONFIG_BUILD_OUTPUT_MOT)
get_property(elfconvert_formats TARGET bintools PROPERTY elfconvert_formats)
if(srec IN_LIST elfconvert_formats)
list(APPEND
post_build_commands
COMMAND $<TARGET_PROPERTY:bintools,elfconvert_command>
$<TARGET_PROPERTY:bintools,elfconvert_flag>
${GAP_FILL}
$<TARGET_PROPERTY:bintools,elfconvert_flag_outtarget>srec
$<TARGET_PROPERTY:bintools,elfconvert_flag_intarget>${OUTPUT_FORMAT}
$<TARGET_PROPERTY:bintools,elfconvert_flag_infile>${KERNEL_ELF_NAME}
$<TARGET_PROPERTY:bintools,elfconvert_flag_outfile>${KERNEL_MOT_NAME}
$<TARGET_PROPERTY:bintools,elfconvert_flag_final>
)
list(APPEND
post_build_byproducts
${KERNEL_MOT_NAME}
)
set(BYPRODUCT_KERNEL_MOT_NAME "${PROJECT_BINARY_DIR}/${KERNEL_MOT_NAME}" CACHE FILEPATH "Kernel mot file" FORCE)
endif()
endif()

set(KERNEL_META_PATH ${PROJECT_BINARY_DIR}/${KERNEL_META_NAME} CACHE INTERNAL "")
if(CONFIG_BUILD_OUTPUT_META)
list(APPEND
Expand Down Expand Up @@ -2302,7 +2297,7 @@ if(CONFIG_LLEXT_EDK)
${SYSCALL_SPLIT_TIMEOUT_ARG}
COMMAND ${CMAKE_COMMAND}
-P ${ZEPHYR_BASE}/cmake/llext-edk.cmake
DEPENDS ${logical_target_for_zephyr_elf} build_info_yaml_saved
DEPENDS ${logical_target_for_zephyr_elf} ${syscalls_json} build_info_yaml_saved
COMMAND_EXPAND_LISTS
)
add_custom_target(llext-edk DEPENDS ${llext_edk_file})
Expand Down
6 changes: 6 additions & 0 deletions Kconfig.zephyr
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,12 @@ config BUILD_OUTPUT_UF2
Build a UF2 binary zephyr/zephyr.uf2 in the build directory.
The name of this file can be customized with CONFIG_KERNEL_BIN_NAME.

config BUILD_OUTPUT_MOT
bool "Build a binary in MOT format"
help
Build a MOT binary zephyr/zephyr.mot in the build directory.
The name of this file can be customized with CONFIG_KERNEL_BIN_NAME.

if BUILD_OUTPUT_UF2

config BUILD_OUTPUT_UF2_FAMILY_ID
Expand Down
1 change: 1 addition & 0 deletions arch/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ config PRIVILEGED_STACK_SIZE

config KOBJECT_TEXT_AREA
int "Size of kobject text area"
default 1024 if UBSAN
default 512 if COVERAGE_GCOV
default 512 if NO_OPTIMIZATIONS
default 512 if STACK_CANARIES && RISCV
Expand Down
1 change: 1 addition & 0 deletions arch/arm64/core/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ config PRIVILEGED_STACK_SIZE
default 4096

config KOBJECT_TEXT_AREA
default 1024 if UBSAN
default 512 if TEST

config WAIT_AT_RESET_VECTOR
Expand Down
4 changes: 2 additions & 2 deletions cmake/bintools/gnu/target_bintools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
set_property(TARGET bintools PROPERTY elfconvert_command ${CMAKE_OBJCOPY})

# List of format the tool supports for converting, for example,
# GNU tools uses objectcopy, which supports the following: ihex, srec, binary
set_property(TARGET bintools PROPERTY elfconvert_formats ihex srec binary)
# GNU tools uses objectcopy, which supports the following: ihex, srec, binary, mot
set_property(TARGET bintools PROPERTY elfconvert_formats ihex srec binary mot)

set_property(TARGET bintools PROPERTY elfconvert_flag "")
set_property(TARGET bintools PROPERTY elfconvert_flag_final "")
Expand Down
4 changes: 4 additions & 0 deletions cmake/compiler/gcc/compiler_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ if(NOT CONFIG_NO_OPTIMIZATIONS)
set_compiler_property(PROPERTY security_fortify_run_time _FORTIFY_SOURCE=2)
endif()

check_set_compiler_property(PROPERTY sanitizer_undefined -fsanitize=undefined)
check_set_compiler_property(PROPERTY sanitizer_undefined_trap -fsanitize-undefined-trap-on-error)
check_set_compiler_property(PROPERTY sanitizer_undefined_library)

# gcc flag for a hosted (no-freestanding) application
check_set_compiler_property(APPEND PROPERTY hosted -fno-freestanding)

Expand Down
4 changes: 4 additions & 0 deletions cmake/flash/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ function(runners_yaml_append_config)
get_runners_prop(uf2_file uf2 "${KERNEL_UF2_NAME}")
runners_yaml_append(" uf2_file: ${uf2}")
endif()
if(CONFIG_BUILD_OUTPUT_MOT)
get_runners_prop(mot_file mot "${KERNEL_MOT_NAME}")
runners_yaml_append(" mot_file: ${mot}")
endif()

zephyr_get(OPENOCD)
zephyr_get(OPENOCD_DEFAULT_PATH)
Expand Down
91 changes: 72 additions & 19 deletions cmake/kobj.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,62 @@
# SPDX-License-Identifier: Apache-2.0

function(gen_kobj gen_dir_out)
set(GEN_KOBJECT_LIST ${ZEPHYR_BASE}/scripts/build/gen_kobject_list.py)

# Invokes gen_kobject_list.py with the given SCRIPT_ARGS, creating a TARGET that depends on the
# script's OUTPUTS
function(gen_kobject_list)
cmake_parse_arguments(PARSE_ARGV 0 arg
""
"TARGET"
"OUTPUTS;SCRIPT_ARGS;INCLUDES;DEPENDS"
)
foreach(include ${arg_INCLUDES})
list(APPEND arg_SCRIPT_ARGS --include-subsystem-list ${include})
endforeach()
add_custom_command(
OUTPUT ${arg_OUTPUTS}
COMMAND
${PYTHON_EXECUTABLE}
${GEN_KOBJECT_LIST}
${arg_SCRIPT_ARGS}
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
DEPENDS
${arg_DEPENDS}
${GEN_KOBJECT_LIST}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
add_custom_target(${arg_TARGET} DEPENDS ${arg_OUTPUTS})
endfunction()

# Generates a gperf header file named OUTPUT using the symbols found in the KERNEL_TARGET's output
# binary. INCLUDES is a list of JSON files defining kernel subsystems and sockets.
function(gen_kobject_list_gperf)
cmake_parse_arguments(PARSE_ARGV 0 arg
""
"TARGET;OUTPUT;KERNEL_TARGET"
"INCLUDES;DEPENDS"
)
gen_kobject_list(
TARGET ${arg_TARGET}
OUTPUTS ${arg_OUTPUT}
SCRIPT_ARGS
--kernel $<TARGET_FILE:${arg_KERNEL_TARGET}>
--gperf-output ${arg_OUTPUT}
INCLUDES ${arg_INCLUDES}
DEPENDS
${arg_DEPENDS}
${arg_KERNEL_TARGET}
)
endfunction()

# Generates header files describing the kernel subsystems defined by the JSON files in INCLUDES. The
# variable named by GEN_DIR_OUT_VAR is set to the directory containing the header files.
function(gen_kobject_list_headers)
cmake_parse_arguments(PARSE_ARGV 0 arg
""
"GEN_DIR_OUT_VAR"
"INCLUDES;DEPENDS"
)
if (PROJECT_BINARY_DIR)
set(gen_dir ${PROJECT_BINARY_DIR}/include/generated/zephyr)
else ()
Expand All @@ -13,24 +69,21 @@ function(gen_kobj gen_dir_out)

file(MAKE_DIRECTORY ${gen_dir})

add_custom_command(
OUTPUT ${KOBJ_TYPES} ${KOBJ_OTYPE} ${KOBJ_SIZE}
COMMAND
${PYTHON_EXECUTABLE}
${ZEPHYR_BASE}/scripts/build/gen_kobject_list.py
--kobj-types-output ${KOBJ_TYPES}
--kobj-otype-output ${KOBJ_OTYPE}
--kobj-size-output ${KOBJ_SIZE}
${gen_kobject_list_include_args}
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
gen_kobject_list(
TARGET ${KOBJ_TYPES_H_TARGET}
OUTPUTS ${KOBJ_TYPES} ${KOBJ_OTYPE} ${KOBJ_SIZE}
SCRIPT_ARGS
--kobj-types-output ${KOBJ_TYPES}
--kobj-otype-output ${KOBJ_OTYPE}
--kobj-size-output ${KOBJ_SIZE}
INCLUDES ${arg_INCLUDES}
DEPENDS
${ZEPHYR_BASE}/scripts/build/gen_kobject_list.py
${PARSE_SYSCALLS_TARGET}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
add_custom_target(${KOBJ_TYPES_H_TARGET} DEPENDS ${KOBJ_TYPES} ${KOBJ_OTYPE})

cmake_path(GET gen_dir PARENT_PATH gen_dir)
set(${gen_dir_out} ${gen_dir} PARENT_SCOPE)
${arg_DEPENDS}
${arg_KERNEL_TARGET}
)

if(arg_GEN_DIR_OUT_VAR)
cmake_path(GET gen_dir PARENT_PATH gen_dir)
set(${arg_GEN_DIR_OUT_VAR} ${gen_dir} PARENT_SCOPE)
endif()
endfunction ()
4 changes: 4 additions & 0 deletions cmake/linker/ld/linker_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ check_set_linker_property(TARGET linker PROPERTY orphan_error

check_set_linker_property(TARGET linker PROPERTY memusage "${LINKERFLAGPREFIX},--print-memory-usage")

check_set_linker_property(TARGET linker PROPERTY sanitizer_undefined -fsanitize=undefined)
check_set_linker_property(TARGET linker PROPERTY sanitizer_undefined_trap -fsanitize-undefined-trap-on-error)
check_set_linker_property(TARGET linker PROPERTY sanitizer_undefined_library)

# -no-pie is not supported until binutils 2.37.
# If -no-pie is passed to old binutils <= 2.36, it is parsed
# as separate arguments -n and -o, which results in output file
Expand Down
Loading
Loading