diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f54336dd3e..779c533a809 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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} ${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}) 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) 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) 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) 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) diff --git a/cmake/linker/armlink/target.cmake b/cmake/linker/armlink/target.cmake index bd3346cd322..7a973865c4a 100644 --- a/cmake/linker/armlink/target.cmake +++ b/cmake/linker/armlink/target.cmake @@ -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} diff --git a/cmake/linker/ld/target.cmake b/cmake/linker/ld/target.cmake index 1cde78b9655..733accda782 100644 --- a/cmake/linker/ld/target.cmake +++ b/cmake/linker/ld/target.cmake @@ -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}) diff --git a/cmake/linker/linker_script_common.cmake b/cmake/linker/linker_script_common.cmake index fae60982137..272fe797777 100644 --- a/cmake/linker/linker_script_common.cmake +++ b/cmake/linker/linker_script_common.cmake @@ -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) diff --git a/cmake/linker_script/arm/linker.cmake b/cmake/linker_script/arm/linker.cmake index ad639f373cc..47b3bcdc86f 100644 --- a/cmake/linker_script/arm/linker.cmake +++ b/cmake/linker_script/arm/linker.cmake @@ -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) 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) 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) 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) 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 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) # 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.*") diff --git a/cmake/linker_script/common/common-noinit.cmake b/cmake/linker_script/common/common-noinit.cmake new file mode 100644 index 00000000000..78093250d23 --- /dev/null +++ b/cmake/linker_script/common/common-noinit.cmake @@ -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 +include(${COMMON_ZEPHYR_LINKER_DIR}/kobject-priv-stacks.cmake) diff --git a/cmake/linker_script/common/common-ram.cmake b/cmake/linker_script/common/common-ram.cmake index 5cb6d977e74..0dda1ee3c0a 100644 --- a/cmake/linker_script/common/common-ram.cmake +++ b/cmake/linker_script/common/common-ram.cmake @@ -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() 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() diff --git a/cmake/linker_script/common/common-rom.cmake b/cmake/linker_script/common/common-rom.cmake index 5a63ecedaed..3d80c1ef37b 100644 --- a/cmake/linker_script/common/common-rom.cmake +++ b/cmake/linker_script/common/common-rom.cmake @@ -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() 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( diff --git a/cmake/linker_script/common/debug-sections.cmake b/cmake/linker_script/common/debug-sections.cmake index ba6aff11c3a..55a68e1fe7a 100644 --- a/cmake/linker_script/common/debug-sections.cmake +++ b/cmake/linker_script/common/debug-sections.cmake @@ -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. diff --git a/cmake/linker_script/common/kobject-data.cmake b/cmake/linker_script/common/kobject-data.cmake new file mode 100644 index 00000000000..072dfe635aa --- /dev/null +++ b/cmake/linker_script/common/kobject-data.cmake @@ -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() diff --git a/cmake/linker_script/common/kobject-priv-stacks.cmake b/cmake/linker_script/common/kobject-priv-stacks.cmake new file mode 100644 index 00000000000..bfbf7edb5f5 --- /dev/null +++ b/cmake/linker_script/common/kobject-priv-stacks.cmake @@ -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() diff --git a/cmake/linker_script/common/kobject-rom.cmake b/cmake/linker_script/common/kobject-rom.cmake new file mode 100644 index 00000000000..81360c1edba --- /dev/null +++ b/cmake/linker_script/common/kobject-rom.cmake @@ -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() diff --git a/cmake/linker_script/common/kobject-text.cmake b/cmake/linker_script/common/kobject-text.cmake new file mode 100644 index 00000000000..9fdf08b478f --- /dev/null +++ b/cmake/linker_script/common/kobject-text.cmake @@ -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() \ No newline at end of file diff --git a/cmake/linker_script/common/thread-local-storage.cmake b/cmake/linker_script/common/thread-local-storage.cmake index 229fc0900d1..6eb8dd417af 100644 --- a/cmake/linker_script/common/thread-local-storage.cmake +++ b/cmake/linker_script/common/thread-local-storage.cmake @@ -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) diff --git a/include/zephyr/linker/common-noinit.ld b/include/zephyr/linker/common-noinit.ld index fba2221162b..8152629af6a 100644 --- a/include/zephyr/linker/common-noinit.ld +++ b/include/zephyr/linker/common-noinit.ld @@ -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),) { diff --git a/include/zephyr/linker/common-ram.ld b/include/zephyr/linker/common-ram.ld index 1eef183d4ae..97763380526 100644 --- a/include/zephyr/linker/common-ram.ld +++ b/include/zephyr/linker/common-ram.ld @@ -1,4 +1,5 @@ /* SPDX-License-Identifier: Apache-2.0 */ +/* Please keep in sync with cmake/linker_script/common/common-ram.cmake */ #include diff --git a/include/zephyr/linker/debug-sections.ld b/include/zephyr/linker/debug-sections.ld index 2a70cccb79e..f9a4e840fef 100644 --- a/include/zephyr/linker/debug-sections.ld +++ b/include/zephyr/linker/debug-sections.ld @@ -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' */ diff --git a/include/zephyr/linker/kobject-data.ld b/include/zephyr/linker/kobject-data.ld index 573680b235e..f3bd54ca7c6 100644 --- a/include/zephyr/linker/kobject-data.ld +++ b/include/zephyr/linker/kobject-data.ld @@ -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 = .; diff --git a/include/zephyr/linker/kobject-priv-stacks.ld b/include/zephyr/linker/kobject-priv-stacks.ld index 53bd508927e..5cc2ee713a0 100644 --- a/include/zephyr/linker/kobject-priv-stacks.ld +++ b/include/zephyr/linker/kobject-priv-stacks.ld @@ -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 diff --git a/include/zephyr/linker/kobject-rom.ld b/include/zephyr/linker/kobject-rom.ld index 1bb6ee10c15..cbe664aa30c 100644 --- a/include/zephyr/linker/kobject-rom.ld +++ b/include/zephyr/linker/kobject-rom.ld @@ -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 diff --git a/include/zephyr/linker/kobject-text.ld b/include/zephyr/linker/kobject-text.ld index b1c2b69e6df..0c9805c86f5 100644 --- a/include/zephyr/linker/kobject-text.ld +++ b/include/zephyr/linker/kobject-text.ld @@ -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. diff --git a/include/zephyr/linker/ram-end.ld b/include/zephyr/linker/ram-end.ld index 71d4571e0fb..77be2a57083 100644 --- a/include/zephyr/linker/ram-end.ld +++ b/include/zephyr/linker/ram-end.ld @@ -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 */ diff --git a/include/zephyr/linker/thread-local-storage.ld b/include/zephyr/linker/thread-local-storage.ld index 5a1313e1c8c..d2bc2b2b334 100644 --- a/include/zephyr/linker/thread-local-storage.ld +++ b/include/zephyr/linker/thread-local-storage.ld @@ -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