Browse Source

cmake: userspace: A stab at USERSPACE + CMAKE_LINKER_GENERATOR

All in all this makes cmake linker generator able to work for at least
most of the kernel tests and samples, on cortex m4.

Make the cmake linker generator have a file-structure more similar to
the ld-skeletons.

Add or edit groups, sections and logic to make the generator reflect
what the ld-skeletons do, esp. for kobjects and APP_SMEM, nonint and
some other details are also effected.

Use the new zephyr_linker_include_generated() and
zephyr_linker_include_var() functions to to handle
${DEVICE_API_LINKER_SECTIONS_CMAKE}, the kobject-prebuilt-*.h files and
APP_SMEM partition. Essentially the output from gen_app_partitions.py,
gen_kobject_placeholders.py.

Add ALIGN_WITH_INPUT on sections being put into DATA_REGION. This makes
the init layout work for ld.

This leverages the updates in gen_app_partitions.py to generate its
output as cmake linker generator sections too, and puts them into a
group defined in linker.cmake

Setup generator variables for alignment of APP_SMEM. Note that this does
not yet handle MPU_ALIGN which depends on the size of the section...

Fix broken k_object_assignment iterable section

Signed-off-by: Björn Bergman <bjorn.bergman@iar.com>
pull/87775/head
Björn Bergman 5 months ago committed by Benjamin Cabé
parent
commit
128698fd36
  1. 41
      CMakeLists.txt
  2. 1
      cmake/linker/armlink/target.cmake
  3. 3
      cmake/linker/ld/target.cmake
  4. 5
      cmake/linker/linker_script_common.cmake
  5. 65
      cmake/linker_script/arm/linker.cmake
  6. 15
      cmake/linker_script/common/common-noinit.cmake
  7. 96
      cmake/linker_script/common/common-ram.cmake
  8. 16
      cmake/linker_script/common/common-rom.cmake
  9. 5
      cmake/linker_script/common/debug-sections.cmake
  10. 59
      cmake/linker_script/common/kobject-data.cmake
  11. 41
      cmake/linker_script/common/kobject-priv-stacks.cmake
  12. 20
      cmake/linker_script/common/kobject-rom.cmake
  13. 48
      cmake/linker_script/common/kobject-text.cmake
  14. 3
      cmake/linker_script/common/thread-local-storage.cmake
  15. 1
      include/zephyr/linker/common-noinit.ld
  16. 1
      include/zephyr/linker/common-ram.ld
  17. 1
      include/zephyr/linker/debug-sections.ld
  18. 2
      include/zephyr/linker/kobject-data.ld
  19. 1
      include/zephyr/linker/kobject-priv-stacks.ld
  20. 1
      include/zephyr/linker/kobject-rom.ld
  21. 1
      include/zephyr/linker/kobject-text.ld
  22. 5
      include/zephyr/linker/ram-end.ld
  23. 1
      include/zephyr/linker/thread-local-storage.ld

41
CMakeLists.txt

@ -71,6 +71,15 @@ set(ZEPHYR_CURRENT_LINKER_PASS 0) @@ -71,6 +71,15 @@ set(ZEPHYR_CURRENT_LINKER_PASS 0)
set(ZEPHYR_CURRENT_LINKER_CMD linker_zephyr_pre${ZEPHYR_CURRENT_LINKER_PASS}.cmd)
set(ZEPHYR_LINK_STAGE_EXECUTABLE zephyr_pre${ZEPHYR_CURRENT_LINKER_PASS})
# Make kconfig variables available to the linker script generator
zephyr_linker_include_generated(KCONFIG ${CMAKE_CURRENT_BINARY_DIR}/.config)
# The linker generator also needs sections.h to be able to access e.g. _APP_SMEM_SECTION_NAME
# for linkerscripts that do not support c-preprocessing.
zephyr_linker_include_generated(HEADER ${ZEPHYR_BASE}/include/zephyr/linker/sections.h)
zephyr_linker_include_var(VAR CMAKE_VERBOSE_MAKEFILE VALUE ${CMAKE_VERBOSE_MAKEFILE})
# ZEPHYR_PREBUILT_EXECUTABLE is used outside of this file, therefore keep the
# existing variable to allow slowly cleanup of linking stage handling.
# Three stage linking active: pre0 -> pre1 -> final, this will correspond to `pre1`
@ -935,6 +944,8 @@ add_custom_target(${DEVICE_API_LD_TARGET} @@ -935,6 +944,8 @@ add_custom_target(${DEVICE_API_LD_TARGET}
${DEVICE_API_LINKER_SECTIONS_CMAKE}
)
zephyr_linker_include_generated(CMAKE ${DEVICE_API_LINKER_SECTIONS_CMAKE})
# Add a pseudo-target that is up-to-date when all generated headers
# are up-to-date.
@ -1134,14 +1145,20 @@ if(NOT EXISTS ${LINKER_SCRIPT}) @@ -1134,14 +1145,20 @@ if(NOT EXISTS ${LINKER_SCRIPT})
endif()
if(CONFIG_USERSPACE)
set(APP_SMEM_ALIGNED_LD "${PROJECT_BINARY_DIR}/include/generated/app_smem_aligned.ld")
set(APP_SMEM_UNALIGNED_LD "${PROJECT_BINARY_DIR}/include/generated/app_smem_unaligned.ld")
if(CONFIG_CMAKE_LINKER_GENERATOR)
set(APP_SMEM_LD_EXT "cmake")
else()
set(APP_SMEM_LD_EXT "ld")
endif()
set(APP_SMEM_ALIGNED_LD "${PROJECT_BINARY_DIR}/include/generated/app_smem_aligned.${APP_SMEM_LD_EXT}")
set(APP_SMEM_UNALIGNED_LD "${PROJECT_BINARY_DIR}/include/generated/app_smem_unaligned.${APP_SMEM_LD_EXT}")
if(CONFIG_LINKER_USE_PINNED_SECTION)
set(APP_SMEM_PINNED_ALIGNED_LD
"${PROJECT_BINARY_DIR}/include/generated/app_smem_pinned_aligned.ld")
"${PROJECT_BINARY_DIR}/include/generated/app_smem_pinned_aligned.${APP_SMEM_LD_EXT}")
set(APP_SMEM_PINNED_UNALIGNED_LD
"${PROJECT_BINARY_DIR}/include/generated/app_smem_pinned_unaligned.ld")
"${PROJECT_BINARY_DIR}/include/generated/app_smem_pinned_unaligned.${APP_SMEM_LD_EXT}")
if(NOT CONFIG_LINKER_GENERIC_SECTIONS_PRESENT_AT_BOOT)
# The libc partition may hold symbols that are required during boot process,
@ -1206,9 +1223,11 @@ if(CONFIG_USERSPACE) @@ -1206,9 +1223,11 @@ if(CONFIG_USERSPACE)
set(APP_SMEM_UNALIGNED_LIB app_smem_unaligned_output_obj_renamed_lib)
list(APPEND LINKER_PASS_${ZEPHYR_CURRENT_LINKER_PASS}_DEFINE "LINKER_APP_SMEM_UNALIGNED")
endif()
if (CONFIG_USERSPACE)
foreach(dep ${APP_SMEM_UNALIGNED_LD} ${APP_SMEM_PINNED_UNALIGNED_LD})
zephyr_linker_include_generated(CMAKE ${dep} PASS LINKER_APP_SMEM_UNALIGNED)
endforeach()
add_custom_command(
OUTPUT ${APP_SMEM_ALIGNED_LD} ${APP_SMEM_PINNED_ALIGNED_LD}
COMMAND ${PYTHON_EXECUTABLE}
@ -1228,6 +1247,9 @@ if (CONFIG_USERSPACE) @@ -1228,6 +1247,9 @@ if (CONFIG_USERSPACE)
COMMAND_EXPAND_LISTS
COMMENT "Generating app_smem_aligned linker section"
)
foreach(dep ${APP_SMEM_ALIGNED_LD} ${APP_SMEM_PINNED_ALIGNED_LD})
zephyr_linker_include_generated(CMAKE ${dep} PASS NOT LINKER_APP_SMEM_UNALIGNED)
endforeach()
endif()
if(CONFIG_USERSPACE)
@ -1335,6 +1357,13 @@ if(CONFIG_USERSPACE) @@ -1335,6 +1357,13 @@ if(CONFIG_USERSPACE)
DEPENDS
${KOBJECT_LINKER_HEADER_DATA}
)
# gen_kobject_placeholders.py generates linker-kobject-prebuild-data.h,
# linker-kobject-prebuild-priv-stacks.h and linker-kobject-prebuild-rodata.h
foreach(ext "-data.h" "-priv-stacks.h" "-rodata.h")
string(REGEX REPLACE "-data.h$" ${ext} file ${KOBJECT_LINKER_HEADER_DATA})
zephyr_linker_include_generated(HEADER ${file} PASS LINKER_ZEPHYR_PREBUILT LINKER_ZEPHYR_FINAL)
endforeach()
endif()
if(CONFIG_USERSPACE OR CONFIG_DEVICE_DEPS)

1
cmake/linker/armlink/target.cmake

@ -36,7 +36,6 @@ macro(configure_linker_script linker_script_gen linker_pass_define) @@ -36,7 +36,6 @@ macro(configure_linker_script linker_script_gen linker_pass_define)
${STEERING_FILE}
${STEERING_C}
COMMAND ${CMAKE_COMMAND}
-C ${DEVICE_API_LINKER_SECTIONS_CMAKE}
-C ${cmake_linker_script_settings}
-DPASS="${linker_pass_define}"
${STEERING_FILE_ARG}

3
cmake/linker/ld/target.cmake

@ -31,13 +31,12 @@ macro(configure_linker_script linker_script_gen linker_pass_define) @@ -31,13 +31,12 @@ macro(configure_linker_script linker_script_gen linker_pass_define)
DEPENDS
${extra_dependencies}
${cmake_linker_script_settings}
${DEVICE_API_LD_TARGET}
COMMAND ${CMAKE_COMMAND}
-C ${DEVICE_API_LINKER_SECTIONS_CMAKE}
-C ${cmake_linker_script_settings}
-DPASS="${linker_pass_define}"
-DOUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/${linker_script_gen}
-P ${ZEPHYR_BASE}/cmake/linker/ld/ld_script.cmake
DEPENDS ${DEVICE_API_LD_TARGET}
)
else()
set(template_script_defines ${linker_pass_define})

5
cmake/linker/linker_script_common.cmake

@ -733,7 +733,10 @@ function(do_var_replace_in res_ptr src) @@ -733,7 +733,10 @@ function(do_var_replace_in res_ptr src)
# can't warn here because we can't check for what is relevant in this pass
# message(WARNING "Missing definition for ${match}")
endif()
message("Replacing ${match} with ${value}")
if(CMAKE_VERBOSE_MAKEFILE)
message("Using variable ${match} with value ${value}")
endif()
string(REPLACE "${match}" "${value}" src "${src}")
endforeach()
set(${res_ptr} "${src}" PARENT_SCOPE)

65
cmake/linker_script/arm/linker.cmake

@ -1,14 +1,38 @@ @@ -1,14 +1,38 @@
set(COMMON_ZEPHYR_LINKER_DIR ${ZEPHYR_BASE}/cmake/linker_script/common)
set_ifndef(region_min_align CONFIG_CUSTOM_SECTION_MIN_ALIGN_SIZE)
# This should be different for cortex_r or cortex_a....
# cut from zephyr/include/zephyr/arch/arm/cortex_m/scripts/linker.ld
if(DEFINED CONFIG_CUSTOM_SECTION_MIN_ALIGN_SIZE)
set_ifndef(region_min_align ${CONFIG_CUSTOM_SECTION_MIN_ALIGN_SIZE})
endif()
# Set alignment to CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE if not set above
# to make linker section alignment comply with MPU granularity.
set_ifndef(region_min_align CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE)
if(DEFINED CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE)
set_ifndef(region_min_align ${CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE})
endif()
# If building without MPU support, use default 4-byte alignment.. if not set above.
set_ifndef(region_min_align 4)
zephyr_linker_include_var(VAR region_min_align)
if((NOT DEFINED CONFIG_CUSTOM_SECTION_ALIGN) AND DEFINED CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT)
# define MPU_ALIGN(region_size) \
# . = ALIGN(_region_min_align); \
# . = ALIGN( 1 << LOG2CEIL(region_size))
# Handling this requires us to handle log2ceil() in iar linker since the size
# isn't known until then.
set(MPU_ALIGN_BYTES ${region_min_align})
#message(WARNING "We can not handle . = ALIGN( 1 << LOG2CEIL(region_size)) ")
else()
set(MPU_ALIGN_BYTES ${region_min_align})
endif()
# The APP_SHARED_ALIGN and SMEM_PARTITION_ALIGN macros are defined as
# ". = ALIGN(...)" things.
# the cmake generator stuff needs an align-size in bytes so:
zephyr_linker_include_var(VAR APP_SHARED_ALIGN_BYTES VALUE ${region_min_align})
zephyr_linker_include_var(VAR SMEM_PARTITION_ALIGN_BYTES VALUE ${MPU_ALIGN_BYTES})
# Note, the `+ 0` in formulas below avoids errors in cases where a Kconfig
# variable is undefined and thus expands to nothing.
math(EXPR FLASH_ADDR
@ -59,6 +83,7 @@ zephyr_linker_group(NAME RAM_REGION VMA RAM LMA ROM_REGION) @@ -59,6 +83,7 @@ zephyr_linker_group(NAME RAM_REGION VMA RAM LMA ROM_REGION)
zephyr_linker_group(NAME TEXT_REGION GROUP ROM_REGION SYMBOL SECTION)
zephyr_linker_group(NAME RODATA_REGION GROUP ROM_REGION)
zephyr_linker_group(NAME DATA_REGION GROUP RAM_REGION SYMBOL SECTION)
zephyr_linker_group(NAME NOINIT_REGION GROUP RAM_REGION SYMBOL SECTION)
# should go to a relocation.cmake - from include/linker/rel-sections.ld - start
zephyr_linker_section(NAME .rel.plt HIDDEN)
@ -82,6 +107,8 @@ zephyr_linker_section(NAME .text GROUP TEXT_REGION) @@ -82,6 +107,8 @@ zephyr_linker_section(NAME .text GROUP TEXT_REGION)
zephyr_linker_section_configure(SECTION .rel.plt INPUT ".rel.iplt")
zephyr_linker_section_configure(SECTION .rela.plt INPUT ".rela.iplt")
include(${COMMON_ZEPHYR_LINKER_DIR}/kobject-text.cmake)
zephyr_linker_section_configure(SECTION .text INPUT ".TEXT.*")
zephyr_linker_section_configure(SECTION .text INPUT ".gnu.linkonce.t.*")
@ -107,9 +134,9 @@ include(${COMMON_ZEPHYR_LINKER_DIR}/thread-local-storage.cmake) @@ -107,9 +134,9 @@ include(${COMMON_ZEPHYR_LINKER_DIR}/thread-local-storage.cmake)
zephyr_linker_section(NAME .rodata GROUP RODATA_REGION)
zephyr_linker_section_configure(SECTION .rodata INPUT ".gnu.linkonce.r.*")
if(CONFIG_USERSPACE AND CONFIG_XIP)
zephyr_linker_section_configure(SECTION .rodata INPUT ".kobject_data.rodata*")
endif()
include(${COMMON_ZEPHYR_LINKER_DIR}/kobject-rom.cmake)
zephyr_linker_section_configure(SECTION .rodata ALIGN 4)
# ToDo - . = ALIGN(_region_min_align);
@ -119,13 +146,33 @@ zephyr_linker_section_configure(SECTION .rodata ALIGN 4) @@ -119,13 +146,33 @@ zephyr_linker_section_configure(SECTION .rodata ALIGN 4)
zephyr_linker_section(NAME .ramfunc GROUP RAM_REGION SUBALIGN 8)
# Todo: handle MPU_ALIGN(_ramfunc_size);
# ToDo - handle if(CONFIG_USERSPACE)
if(CONFIG_USERSPACE)
# This is where the app_mem_partition stuff is going to be placed, once it
# is generated by gen_app_partitions.py. _app_smem has its own init-copy
# handling in z_data_copy, so put it in RAM_REGIOM rather than DATA_REGION
zephyr_linker_group(NAME APP_SMEM_GROUP GROUP RAM_REGION SYMBOL SECTION)
zephyr_linker_symbol(SYMBOL "_app_smem_size" EXPR "@__app_smem_group_size@")
zephyr_linker_symbol(SYMBOL "_app_smem_rom_start" EXPR "@__app_smem_group_load_start@")
zephyr_linker_section(NAME .bss VMA RAM LMA FLASH TYPE BSS)
zephyr_linker_section_configure(SECTION .bss INPUT COMMON)
zephyr_linker_section_configure(SECTION .bss INPUT ".kernel_bss.*")
#TODO: the skeletons includes <linker_sram_bss_relocate.ld> here
# As memory is cleared in words only, it is simpler to ensure the BSS
# section ends on a 4 byte boundary. This wastes a maximum of 3 bytes.
zephyr_linker_section_configure(SECTION .bss ALIGN 4)
include(${COMMON_ZEPHYR_LINKER_DIR}/common-noinit.cmake)
endif()
zephyr_linker_section(NAME .data GROUP DATA_REGION)
zephyr_linker_section(NAME .data GROUP DATA_REGION ALIGN_WITH_INPUT)
zephyr_linker_section_configure(SECTION .data INPUT ".kernel.*")
include(${COMMON_ZEPHYR_LINKER_DIR}/common-ram.cmake)
#include(kobject.ld)
include(${COMMON_ZEPHYR_LINKER_DIR}/kobject-data.cmake)
if(NOT CONFIG_USERSPACE)
zephyr_linker_section(NAME .bss VMA RAM LMA FLASH TYPE BSS)
@ -135,7 +182,7 @@ if(NOT CONFIG_USERSPACE) @@ -135,7 +182,7 @@ if(NOT CONFIG_USERSPACE)
# section ends on a 4 byte boundary. This wastes a maximum of 3 bytes.
zephyr_linker_section_configure(SECTION .bss ALIGN 4)
zephyr_linker_section(NAME .noinit GROUP RAM_REGION TYPE NOLOAD NOINIT)
zephyr_linker_section(NAME .noinit GROUP NOINIT_REGION TYPE NOLOAD NOINIT)
# This section is used for non-initialized objects that
# will not be cleared during the boot process.
zephyr_linker_section_configure(SECTION .noinit INPUT ".kernel_noinit.*")

15
cmake/linker_script/common/common-noinit.cmake

@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
# SPDX-License-Identifier: Apache-2.0
# The contents of this file is based on include/zephyr/linker/common-noinit.ld
# Please keep in sync
zephyr_linker_section(NAME .noinit GROUP NOINIT_REGION TYPE NOLOAD NOINIT)
if(CONFIG_USERSPACE)
zephyr_linker_section_configure(
SECTION .noinit
INPUT ".user_stacks*"
SYMBOLS z_user_stacks_start z_user_stacks_end)
endif()
# TODO: #include <snippets-noinit.ld>
include(${COMMON_ZEPHYR_LINKER_DIR}/kobject-priv-stacks.cmake)

96
cmake/linker_script/common/common-ram.cmake

@ -1,4 +1,6 @@ @@ -1,4 +1,6 @@
# originates from common-ram.ld
# SPDX-License-Identifier: Apache-2.0
# The contents of this file is based on include/zephyr/linker/common-ram.ld
# Please keep in sync
if(CONFIG_GEN_SW_ISR_TABLE AND CONFIG_DYNAMIC_INTERRUPTS)
# ld align has been changed to subalign to provide identical behavior scatter vs. ld.
@ -30,79 +32,91 @@ endif() @@ -30,79 +32,91 @@ endif()
zephyr_iterable_section(NAME log_dynamic GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
if(CONFIG_USERSPACE)
set(K_OBJECTS_GROUP "K_OBJECTS_IN_DATA_REGION")
# All kernel objects within are assumed to be either completely
# initialized at build time, or initialized automatically at runtime
# via iteration before the POST_KERNEL phase.
#
# These two symbols only used by gen_kobject_list.py
# _static_kernel_objects_begin = .;
endif()
zephyr_iterable_section(NAME k_timer GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME k_mem_slab GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME k_heap GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME k_mutex GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME k_stack GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME k_msgq GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME k_mbox GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME k_pipe GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME k_sem GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME k_event GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME k_queue GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME k_fifo GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME k_lifo GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME k_condvar GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME sys_mem_blocks_ptr GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME net_buf_pool GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_linker_group(NAME ${K_OBJECTS_GROUP} GROUP DATA_REGION SYMBOL SECTION)
# gen_kobject_list.py expects the start and end symbols to be called
# _static_kernel_objects_begin and _static_kernel_objects_end respectively...
zephyr_linker_symbol(
SYMBOL
_static_kernel_objects_begin
EXPR
"(@__k_objects_in_data_region_start@)"
)
zephyr_linker_symbol(
SYMBOL
_static_kernel_objects_end
EXPR
"(@__k_objects_in_data_region_end@)"
)
else()
set(K_OBJECTS_GROUP "DATA_REGION")
endif()
zephyr_iterable_section(NAME k_timer GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME k_mem_slab GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME k_heap GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME k_mutex GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME k_stack GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME k_msgq GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME k_mbox GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME k_pipe GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME k_sem GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME k_event GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME k_queue GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME k_fifo GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME k_lifo GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME k_condvar GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME sys_mem_blocks_ptr GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME net_buf_pool GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
if(CONFIG_NETWORKING)
zephyr_iterable_section(NAME net_if GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME net_if_dev GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME net_l2 GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME eth_bridge GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME net_if GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME net_if_dev GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME net_l2 GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME eth_bridge GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
endif()
if(CONFIG_ARM_SCMI)
zephyr_iterable_section(NAME scmi_protocol GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME scmi_protocol GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
endif()
if(CONFIG_SENSING)
zephyr_iterable_section(NAME sensing_sensor GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME sensing_sensor GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
endif()
if(CONFIG_USB_DEVICE_STACK)
zephyr_linker_section(NAME usb_descriptor GROUP DATA_REGION NOINPUT ${XIP_ALIGN_WITH_INPUT} SUBALIGN 1)
zephyr_linker_section(NAME usb_descriptor GROUP ${K_OBJECTS_GROUP} NOINPUT ${XIP_ALIGN_WITH_INPUT} SUBALIGN 1)
zephyr_linker_section_configure(SECTION usb_descriptor
KEEP SORT NAME INPUT ".usb.descriptor*"
)
zephyr_iterable_section(NAME usb_cfg_data GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME usb_cfg_data GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
endif()
if(CONFIG_USB_DEVICE_BOS)
zephyr_linker_section(NAME usb_bos_desc GROUP DATA_REGION NOINPUT ${XIP_ALIGN_WITH_INPUT} SUBALIGN 1)
zephyr_linker_section(NAME usb_bos_desc GROUP ${K_OBJECTS_GROUP} NOINPUT ${XIP_ALIGN_WITH_INPUT} SUBALIGN 1)
zephyr_linker_section_configure(SECTION usb_data
KEEP SORT NAME INPUT ".usb.bos_desc"
)
endif()
if(CONFIG_RTIO)
zephyr_iterable_section(NAME rtio GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME rtio_iodev GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME rtio_sqe_pool GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME rtio_cqe_pool GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME rtio GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME rtio_iodev GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME rtio_sqe_pool GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME rtio_cqe_pool GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
endif()
if(CONFIG_SENSING)
zephyr_iterable_section(NAME sensing_sensor GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
zephyr_iterable_section(NAME sensing_sensor GROUP ${K_OBJECTS_GROUP} ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
endif()
#if(CONFIG_USERSPACE)
# _static_kernel_objects_end = .;
#endif()
#
if(CONFIG_ZBUS)
zephyr_iterable_section(NAME zbus_channel_observation_mask GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 1)
endif()

16
cmake/linker_script/common/common-rom.cmake

@ -1,4 +1,7 @@ @@ -1,4 +1,7 @@
# originates from common-rom.ld
# SPDX-License-Identifier: Apache-2.0
# The contents of this file is based on include/zephyr/linker/common-rom.ld
# and som of include/zephyr/linker/common-rom/*.ld
# Please keep in sync
zephyr_linker_section(NAME init KVMA RAM_REGION GROUP RODATA_REGION)
zephyr_linker_section_obj_level(SECTION init LEVEL EARLY)
@ -72,16 +75,7 @@ endif() @@ -72,16 +75,7 @@ endif()
if(CONFIG_USERSPACE)
# Build-time assignment of permissions to kernel objects to
# threads declared with K_THREAD_DEFINE()
zephyr_linker_section(
NAME k_object_assignment_area
VMA FLASH NOINPUT
SUBALIGN 4
)
zephyr_linker_section_configure(
SECTION k_object_assignment
INPUT ".k_object_assignment.static.*"
KEEP SORT NAME
)
zephyr_iterable_section(NAME k_object_assignment VMA FLASH SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
endif()
zephyr_linker_section(

5
cmake/linker_script/common/debug-sections.cmake

@ -1,4 +1,7 @@ @@ -1,4 +1,7 @@
# Content of this file originates from include/zephyr/linker/debug-sections.ld
# SPDX-License-Identifier: Apache-2.0
# The contents of this file is based on include/zephyr/linker/debug-sections.ld
# Please keep in sync
# Following sections are obtained via 'ld --verbose'
# Stabs debugging sections.

59
cmake/linker_script/common/kobject-data.cmake

@ -0,0 +1,59 @@ @@ -0,0 +1,59 @@
# SPDX-License-Identifier: Apache-2.0
# The contents of this file is based on include/zephyr/linker/kobject-data.ld
# Please keep in sync
if(CONFIG_USERSPACE)
zephyr_linker_section(NAME kobject_data GROUP ${K_OBJECTS_GROUP} ALIGN_WITH_INPUT NOINPUT)
zephyr_linker_section_configure(
SECTION kobject_data
SYMBOLS z_kobject_data_begin
)
if(CONFIG_DYNAMIC_OBJECTS)
# generated by gperf, this avoids errors for the first build.
# Also, we dont have KOBJECT_DATA_SZ for the first build
zephyr_linker_section_configure(
SECTION kobject_data
SYMBOLS _thread_idx_map
MIN_SIZE ${CONFIG_MAX_THREAD_BYTES}
PASS NOT LINKER_ZEPHYR_PREBUILT LINKER_ZEPHYR_FINAL
)
zephyr_linker_section_configure(
SECTION kobject_data
SYMBOLS _kobject_data_area_start _kobject_data_area_end
PASS NOT LINKER_ZEPHYR_PREBUILT LINKER_ZEPHYR_FINAL
)
endif()
# During LINKER_KOBJECT_PREBUILT and LINKER_ZEPHYR_PREBUILT,
# space needs to be reserved for the rodata that will be
# produced by gperf during the final stages of linking.
# The alignment and size are produced by
# scripts/build/gen_kobject_placeholders.py. These are here
# so the addresses to kobjects would remain the same
# during the final stages of linking (LINKER_ZEPHYR_FINAL).
if(CONFIG_DYNAMIC_OBJECTS)
# in LINKER_ZEPHYR_PREBUILT there is no object file defining _thread_idx_map
# so we must have a synthetic one. Note that the size is not set here,
# since the space is provided in the section below:
zephyr_linker_section_configure(
SECTION kobject_data
SYMBOLS _thread_idx_map
PASS LINKER_ZEPHYR_PREBUILT
)
endif()
zephyr_linker_section_configure(
SECTION kobject_data
INPUT
".kobject_data.data*"
".kobject_data.sdata*"
PASS LINKER_ZEPHYR_PREBUILT LINKER_ZEPHYR_FINAL
ALIGN @KOBJECT_DATA_ALIGN,undef:4@
MIN_SIZE @KOBJECT_DATA_SZ@
MAX_SIZE @KOBJECT_DATA_SZ@
SYMBOLS _kobject_data_area_start _kobject_data_area_end
)
endif()

41
cmake/linker_script/common/kobject-priv-stacks.cmake

@ -0,0 +1,41 @@ @@ -0,0 +1,41 @@
# SPDX-License-Identifier: Apache-2.0
# The contents of this file is based on include/zephyr/linker/kobject-priv-stacks.ld
# Please keep in sync
if(CONFIG_USERSPACE)
if(CONFIG_GEN_PRIV_STACKS)
# Padding is needed to preserve kobject addresses
# if we have reserved more space than needed.
zephyr_linker_section(NAME .priv_stacks_noinit GROUP NOINIT_REGION NOINPUT NOINIT
MIN_SIZE @KOBJECT_PRIV_STACKS_SZ,undef:0@ MAX_SIZE @KOBJECT_PRIV_STACKS_SZ,undef:0@)
zephyr_linker_section_configure(
SECTION .priv_stacks_noinit
SYMBOLS z_priv_stacks_ram_start
)
# During LINKER_KOBJECT_PREBUILT and LINKER_ZEPHYR_PREBUILT,
# space needs to be reserved for the rodata that will be
# produced by gperf during the final stages of linking.
# The alignment and size are produced by
# scripts/build/gen_kobject_placeholders.py. These are here
# so the addresses to kobjects would remain the same
# during the final stages of linking (LINKER_ZEPHYR_FINAL).
zephyr_linker_section_configure(
SECTION .priv_stacks_noinit
ALIGN @KOBJECT_PRIV_STACKS_ALIGN,undef:0@
INPUT ".priv_stacks.noinit"
KEEP
PASS LINKER_ZEPHYR_PREBUILT LINKER_ZEPHYR_FINAL
SYMBOLS z_priv_stacks_ram_aligned_start z_priv_stacks_ram_end
)
if(KOBJECT_PRIV_STACKS_ALIGN)
zephyr_linker_symbol(
SYMBOL z_priv_stacks_ram_used
EXPR "(@z_priv_stacks_ram_end@ - @z_priv_stacks_ram_start@)"
PASS LINKER_ZEPHYR_FINAL
)
endif()
endif()
endif()

20
cmake/linker_script/common/kobject-rom.cmake

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
# SPDX-License-Identifier: Apache-2.0
# The contents of this file is based on include/zephyr/linker/kobject-rom.ld
# Please keep in sync
# During LINKER_KOBJECT_PREBUILT and LINKER_ZEPHYR_PREBUILT,
# space needs to be reserved for the rodata that will be
# produced by gperf during the final stages of linking.
# The alignment and size are produced by
# scripts/build/gen_kobject_placeholders.py. These are here
# so the addresses to kobjects would remain the same
# during the final stages of linking (LINKER_ZEPHYR_FINAL).
if(CONFIG_USERSPACE)
# By the magic of MIN_SIZE the space will be there
zephyr_linker_section_configure(SECTION .rodata KEEP INPUT ".kobject_data.rodata*"
MIN_SIZE @KOBJECT_RODATA_SZ@
ALIGN @KOBJECT_RODATA_ALIGN@
PASS LINKER_ZEPHYR_PREBUILT LINKER_ZEPHYR_FINAL
)
endif()

48
cmake/linker_script/common/kobject-text.cmake

@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
# SPDX-License-Identifier: Apache-2.0
# The contents of this file is based on include/zephyr/linker/kobject-text.ld
# Please keep in sync
if(CONFIG_USERSPACE)
zephyr_linker_section(NAME _kobject_text_area
GROUP TEXT_REGION NOINPUT)
zephyr_linker_section_configure(
SECTION
_kobject_text_area
INPUT
".kobject_data.literal*"
".kobject_data.text*"
MIN_SIZE ${CONFIG_KOBJECT_TEXT_AREA}
MAX_SIZE ${CONFIG_KOBJECT_TEXT_AREA}
SYMBOLS
_kobject_text_area_start
_kobject_text_area_end
)
zephyr_linker_symbol(
SYMBOL
_kobject_text_area_used
EXPR
"(@_kobject_text_area_end@ - @_kobject_text_area_start@)"
)
if(CONFIG_DYNAMIC_OBJECTS)
zephyr_linker_section_configure(
SECTION
_kobject_text_area
SYMBOLS
z_object_gperf_find
z_object_gperf_wordlist_foreach
PASS NOT LINKER_ZEPHYR_FINAL
)
else()
zephyr_linker_section_configure(
SECTION
_kobject_text_area
SYMBOLS
k_object_find
k_object_wordlist_foreach
PASS NOT LINKER_ZEPHYR_FINAL
)
endif()
endif()

3
cmake/linker_script/common/thread-local-storage.cmake

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
# originates from thread-local-storage.ld
# The contents of this file is based on include/zephyr/linker/thread-local-storage.ld
# Please keep in sync
if(CONFIG_THREAD_LOCAL_STORAGE)
zephyr_linker_section(NAME .tdata LMA FLASH NOINPUT)

1
include/zephyr/linker/common-noinit.ld

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
/* Please keep in sync with cmake/linker_script/common/common-noinit.cmake */
SECTION_PROLOGUE(_NOINIT_SECTION_NAME,(NOLOAD),)
{

1
include/zephyr/linker/common-ram.ld

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
/* SPDX-License-Identifier: Apache-2.0 */
/* Please keep in sync with cmake/linker_script/common/common-ram.cmake */
#include <zephyr/linker/iterable_sections.h>

1
include/zephyr/linker/debug-sections.ld

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
/* SPDX-License-Identifier: Apache-2.0 */
/* Please keep in sync with cmake/linker_script/common/debug-sections.cmake */
/* following sections are obtained via 'ld --verbose' */

2
include/zephyr/linker/kobject-data.ld

@ -4,6 +4,8 @@ @@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
/* Please keep in sync with cmake/linker_script/common/kobject-data.cmake */
#ifdef CONFIG_USERSPACE
z_kobject_data_begin = .;

1
include/zephyr/linker/kobject-priv-stacks.ld

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
/* Please keep in sync with cmake/linker_script/common/kobject-priv-stacks.cmake */
#ifdef CONFIG_USERSPACE
#ifdef CONFIG_GEN_PRIV_STACKS

1
include/zephyr/linker/kobject-rom.ld

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
/* Please keep in sync with cmake/linker_script/common/kobject-rom.cmake */
#ifdef CONFIG_USERSPACE

1
include/zephyr/linker/kobject-text.ld

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
/* SPDX-License-Identifier: Apache-2.0 */
/* Plase keep in sync with cmake/linker_script/common/kobject-text.cmake */
#ifdef CONFIG_USERSPACE
/* We need to reserve room for the gperf generated hash functions.

5
include/zephyr/linker/ram-end.ld

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
/*
* Added after the very last allocation that might land in RAM to define the various
/* Please keep in sync with cmake/linker_script/common/ram-end.cmake */
/* Added after the very last allocation that might land in RAM to define the various
* end-of-used-memory symbols
*/

1
include/zephyr/linker/thread-local-storage.ld

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
/* SPDX-License-Identifier: Apache-2.0 */
/* Please keep in sync with cmake/linker_script/common/thread-local-storage.cmake */
#ifdef CONFIG_THREAD_LOCAL_STORAGE

Loading…
Cancel
Save