LCOV - code coverage report
Current view: top level - zephyr/linker - linker-defs.h Coverage Total Hit
Test: new.info Lines: 0.0 % 3 0
Test Date: 2025-09-05 16:43:28

            Line data    Source code
       1            0 : /*
       2              :  * Copyright (c) 2013-2014, Wind River Systems, Inc.
       3              :  *
       4              :  * SPDX-License-Identifier: Apache-2.0
       5              :  */
       6              : 
       7              : /*
       8              :  * DESCRIPTION
       9              :  * Platform independent, commonly used macros and defines related to linker
      10              :  * script.
      11              :  *
      12              :  * This file may be included by:
      13              :  * - Linker script files: for linker section declarations
      14              :  * - C files: for external declaration of address or size of linker section
      15              :  * - Assembly files: for external declaration of address or size of linker
      16              :  *   section
      17              :  */
      18              : 
      19              : #ifndef ZEPHYR_INCLUDE_LINKER_LINKER_DEFS_H_
      20              : #define ZEPHYR_INCLUDE_LINKER_LINKER_DEFS_H_
      21              : 
      22              : #include <zephyr/toolchain.h>
      23              : #include <zephyr/toolchain/common.h>
      24              : #include <zephyr/linker/sections.h>
      25              : #include <zephyr/sys/util.h>
      26              : #include <zephyr/offsets.h>
      27              : 
      28              : /* We need to dummy out DT_NODE_HAS_STATUS and DT_NODE_HAS_STATUS_OKAY when
      29              :  * building the unittests.
      30              :  * Including devicetree.h would require generating dummy header files
      31              :  * to match what gen_defines creates, so it's easier to just dummy out
      32              :  * DT_NODE_HAS_STATUS and DT_NODE_HAS_STATUS_OKAY. These are undefined at the
      33              :  * end of the file.
      34              :  */
      35              : #ifdef ZTEST_UNITTEST
      36              : #ifdef DT_NODE_HAS_STATUS
      37              : #undef DT_NODE_HAS_STATUS
      38              : #endif
      39              : #define DT_NODE_HAS_STATUS(node, status) 0
      40              : 
      41              : #ifdef DT_NODE_HAS_STATUS_OKAY
      42              : #undef DT_NODE_HAS_STATUS_OKAY
      43              : #endif
      44              : #define DT_NODE_HAS_STATUS_OKAY(node) 0
      45              : #else
      46              : #include <zephyr/devicetree.h>
      47              : #endif
      48              : 
      49              : /* The GCC for Renesas RX processors adds leading underscores to C-symbols
      50              :  * by default. As a workaroud for symbols defined in linker scripts to be
      51              :  * available in C code, an alias with a leading underscore has to be provided.
      52              :  */
      53              : #if defined(CONFIG_RX)
      54              : #define PLACE_SYMBOL_HERE(symbol)                                                                  \
      55              :         symbol = .;                                                                                \
      56              :         PROVIDE(_CONCAT(_, symbol) = symbol)
      57              : #else
      58            0 : #define PLACE_SYMBOL_HERE(symbol) symbol = .
      59              : #endif
      60              : 
      61              : #ifdef _LINKER
      62              : /*
      63              :  * generate a symbol to mark the start of the objects array for
      64              :  * the specified object and level, then link all of those objects
      65              :  * (sorted by priority). Ensure the objects aren't discarded if there is
      66              :  * no direct reference to them
      67              :  */
      68              : 
      69              : /* clang-format off */
      70            0 : #define CREATE_OBJ_LEVEL(object, level)                         \
      71              :                 PLACE_SYMBOL_HERE(__##object##_##level##_start);\
      72              :                 KEEP(*(SORT(.z_##object##_##level##_P_?_*)));   \
      73              :                 KEEP(*(SORT(.z_##object##_##level##_P_??_*)));  \
      74              :                 KEEP(*(SORT(.z_##object##_##level##_P_???_*)));
      75              : /* clang-format on */
      76              : 
      77              : /*
      78              :  * link in shell initialization objects for all modules that use shell and
      79              :  * their shell commands are automatically initialized by the kernel.
      80              :  */
      81              : 
      82              : #elif defined(_ASMLANGUAGE)
      83              : 
      84              : /* Assembly FILES: declaration defined by the linker script */
      85              : GDATA(__bss_start)
      86              : GDATA(__bss_num_words)
      87              : #ifdef CONFIG_XIP
      88              : GDATA(__data_region_load_start)
      89              : GDATA(__data_region_start)
      90              : GDATA(__data_region_num_words)
      91              : #endif
      92              : 
      93              : #else /* ! _ASMLANGUAGE */
      94              : 
      95              : #include <zephyr/types.h>
      96              : /*
      97              :  * Memory owned by the kernel, to be used as shared memory between
      98              :  * application threads.
      99              :  *
     100              :  * The following are extern symbols from the linker. This enables
     101              :  * the dynamic k_mem_domain and k_mem_partition creation and alignment
     102              :  * to the section produced in the linker.
     103              : 
     104              :  * The policy for this memory will be to initially configure all of it as
     105              :  * kernel / supervisor thread accessible.
     106              :  */
     107              : extern char _app_smem_start[];
     108              : extern char _app_smem_end[];
     109              : extern char _app_smem_size[];
     110              : extern char _app_smem_rom_start[];
     111              : extern char _app_smem_num_words[];
     112              : 
     113              : #ifdef CONFIG_LINKER_USE_PINNED_SECTION
     114              : extern char _app_smem_pinned_start[];
     115              : extern char _app_smem_pinned_end[];
     116              : extern char _app_smem_pinned_size[];
     117              : extern char _app_smem_pinned_num_words[];
     118              : #endif
     119              : 
     120              : /* Memory owned by the kernel. Start and end will be aligned for memory
     121              :  * management/protection hardware for the target architecture.
     122              :  *
     123              :  * Consists of all kernel-side globals, all kernel objects, all thread stacks,
     124              :  * and all currently unused RAM.
     125              :  *
     126              :  * Except for the stack of the currently executing thread, none of this memory
     127              :  * is normally accessible to user threads unless specifically granted at
     128              :  * runtime.
     129              :  */
     130              : extern char __kernel_ram_start[];
     131              : extern char __kernel_ram_end[];
     132              : extern char __kernel_ram_size[];
     133              : 
     134              : /* Used by z_bss_zero or arch-specific implementation */
     135              : extern char __bss_start[];
     136              : extern char __bss_end[];
     137              : 
     138              : /* Used by z_data_copy() or arch-specific implementation */
     139              : #ifdef CONFIG_XIP
     140              : extern char __data_region_load_start[];
     141              : extern char __data_region_start[];
     142              : extern char __data_region_end[];
     143              : #endif /* CONFIG_XIP */
     144              : 
     145              : #ifdef CONFIG_MMU
     146              : /* Virtual addresses of page-aligned kernel image mapped into RAM at boot */
     147              : extern char z_mapped_start[];
     148              : extern char z_mapped_end[];
     149              : #endif /* CONFIG_MMU */
     150              : 
     151              : /* Includes text and rodata */
     152              : extern char __rom_region_start[];
     153              : extern char __rom_region_end[];
     154              : extern char __rom_region_size[];
     155              : 
     156              : /* Includes all ROMable data, i.e. the size of the output image file. */
     157              : extern char _flash_used[];
     158              : 
     159              : /* datas, bss, noinit */
     160              : extern char _image_ram_start[];
     161              : extern char _image_ram_end[];
     162              : extern char _image_ram_size[];
     163              : 
     164              : extern char __text_region_start[];
     165              : extern char __text_region_end[];
     166              : extern char __text_region_size[];
     167              : 
     168              : extern char __rodata_region_start[];
     169              : extern char __rodata_region_end[];
     170              : extern char __rodata_region_size[];
     171              : 
     172              : extern char _vector_start[];
     173              : extern char _vector_end[];
     174              : 
     175              : #ifdef CONFIG_SW_VECTOR_RELAY
     176              : extern char __vector_relay_table[];
     177              : #endif
     178              : 
     179              : #ifdef CONFIG_SRAM_VECTOR_TABLE
     180              : extern char _sram_vector_start[];
     181              : extern char _sram_vector_end[];
     182              : extern char _sram_vector_size[];
     183              : #endif
     184              : 
     185              : #ifdef CONFIG_COVERAGE_GCOV
     186              : extern char __gcov_bss_start[];
     187              : extern char __gcov_bss_end[];
     188              : extern char __gcov_bss_size[];
     189              : #endif  /* CONFIG_COVERAGE_GCOV */
     190              : 
     191              : /* end address of image, used by newlib for the heap */
     192              : extern char _end[];
     193              : 
     194              : #if (DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_ccm)))
     195              : extern char __ccm_data_load_start[];
     196              : extern char __ccm_start[];
     197              : extern char __ccm_data_start[];
     198              : extern char __ccm_data_end[];
     199              : extern char __ccm_bss_start[];
     200              : extern char __ccm_bss_end[];
     201              : extern char __ccm_noinit_start[];
     202              : extern char __ccm_noinit_end[];
     203              : extern char __ccm_end[];
     204              : #endif
     205              : 
     206              : #if (DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_itcm)))
     207              : extern char __itcm_start[];
     208              : extern char __itcm_end[];
     209              : extern char __itcm_size[];
     210              : extern char __itcm_load_start[];
     211              : #endif
     212              : 
     213              : #if (DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_dtcm)))
     214              : extern char __dtcm_data_start[];
     215              : extern char __dtcm_data_end[];
     216              : extern char __dtcm_bss_start[];
     217              : extern char __dtcm_bss_end[];
     218              : extern char __dtcm_noinit_start[];
     219              : extern char __dtcm_noinit_end[];
     220              : extern char __dtcm_data_load_start[];
     221              : extern char __dtcm_start[];
     222              : extern char __dtcm_end[];
     223              : #endif
     224              : 
     225              : #if (DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_ocm)))
     226              : extern char __ocm_data_start[];
     227              : extern char __ocm_data_end[];
     228              : extern char __ocm_bss_start[];
     229              : extern char __ocm_bss_end[];
     230              : extern char __ocm_start[];
     231              : extern char __ocm_end[];
     232              : extern char __ocm_size[];
     233              : #endif
     234              : 
     235              : /* Used by the Security Attribution Unit to configure the
     236              :  * Non-Secure Callable region.
     237              :  */
     238              : #ifdef CONFIG_ARM_FIRMWARE_HAS_SECURE_ENTRY_FUNCS
     239              : extern char __sg_start[];
     240              : extern char __sg_end[];
     241              : extern char __sg_size[];
     242              : #endif /* CONFIG_ARM_FIRMWARE_HAS_SECURE_ENTRY_FUNCS */
     243              : 
     244              : /*
     245              :  * Non-cached kernel memory region, currently only available on ARM Cortex-M7
     246              :  * with a MPU. Start and end will be aligned for memory management/protection
     247              :  * hardware for the target architecture.
     248              :  *
     249              :  * All the variables with '__nocache' keyword will be placed into the nocache
     250              :  * section, variables with '__nocache_load' keyword will be placed into the
     251              :  * nocache section that is loaded from ROM.
     252              :  */
     253              : #ifdef CONFIG_NOCACHE_MEMORY
     254              : extern char _nocache_ram_start[];
     255              : extern char _nocache_ram_end[];
     256              : extern char _nocache_ram_size[];
     257              : extern char _nocache_noload_ram_start[];
     258              : extern char _nocache_noload_ram_end[];
     259              : extern char _nocache_noload_ram_size[];
     260              : extern char _nocache_load_ram_start[];
     261              : extern char _nocache_load_ram_end[];
     262              : extern char _nocache_load_ram_size[];
     263              : extern char _nocache_load_rom_start[];
     264              : #endif /* CONFIG_NOCACHE_MEMORY */
     265              : 
     266              : /* Memory owned by the kernel. Start and end will be aligned for memory
     267              :  * management/protection hardware for the target architecture.
     268              :  *
     269              :  * All the functions with '__ramfunc' keyword will be placed into this
     270              :  * section, stored in RAM instead of FLASH.
     271              :  */
     272              : #ifdef CONFIG_ARCH_HAS_RAMFUNC_SUPPORT
     273              : extern char __ramfunc_region_start[];
     274              : extern char __ramfunc_start[];
     275              : extern char __ramfunc_end[];
     276              : extern char __ramfunc_size[];
     277              : extern char __ramfunc_load_start[];
     278              : #endif /* CONFIG_ARCH_HAS_RAMFUNC_SUPPORT */
     279              : 
     280              : /* Memory owned by the kernel. Memory region for thread privilege stack buffers,
     281              :  * currently only applicable on ARM Cortex-M architecture when building with
     282              :  * support for User Mode.
     283              :  *
     284              :  * All thread privilege stack buffers will be placed into this section.
     285              :  */
     286              : #ifdef CONFIG_USERSPACE
     287              : extern char z_priv_stacks_ram_start[];
     288              : extern char z_priv_stacks_ram_end[];
     289              : extern char z_user_stacks_start[];
     290              : extern char z_user_stacks_end[];
     291              : extern char z_kobject_data_begin[];
     292              : #endif /* CONFIG_USERSPACE */
     293              : 
     294              : #ifdef CONFIG_THREAD_LOCAL_STORAGE
     295              : extern char __tdata_start[];
     296              : extern char __tdata_end[];
     297              : extern char __tdata_size[];
     298              : extern char __tdata_align[];
     299              : extern char __tbss_start[];
     300              : extern char __tbss_end[];
     301              : extern char __tbss_size[];
     302              : extern char __tbss_align[];
     303              : extern char __tls_start[];
     304              : extern char __tls_end[];
     305              : extern char __tls_size[];
     306              : #endif /* CONFIG_THREAD_LOCAL_STORAGE */
     307              : 
     308              : #ifdef CONFIG_LINKER_USE_BOOT_SECTION
     309              : /* lnkr_boot_start[] and lnkr_boot_end[]
     310              :  * must encapsulate all the boot sections.
     311              :  */
     312              : extern char lnkr_boot_start[];
     313              : extern char lnkr_boot_end[];
     314              : 
     315              : extern char lnkr_boot_text_start[];
     316              : extern char lnkr_boot_text_end[];
     317              : extern char lnkr_boot_text_size[];
     318              : extern char lnkr_boot_data_start[];
     319              : extern char lnkr_boot_data_end[];
     320              : extern char lnkr_boot_data_size[];
     321              : extern char lnkr_boot_rodata_start[];
     322              : extern char lnkr_boot_rodata_end[];
     323              : extern char lnkr_boot_rodata_size[];
     324              : extern char lnkr_boot_bss_start[];
     325              : extern char lnkr_boot_bss_end[];
     326              : extern char lnkr_boot_bss_size[];
     327              : extern char lnkr_boot_noinit_start[];
     328              : extern char lnkr_boot_noinit_end[];
     329              : extern char lnkr_boot_noinit_size[];
     330              : #endif /* CONFIG_LINKER_USE_BOOT_SECTION */
     331              : 
     332              : #ifdef CONFIG_LINKER_USE_PINNED_SECTION
     333              : /* lnkr_pinned_start[] and lnkr_pinned_end[] must encapsulate
     334              :  * all the pinned sections as these are used by
     335              :  * the MMU code to mark the physical page frames with
     336              :  * K_MEM_PAGE_FRAME_PINNED.
     337              :  */
     338              : extern char lnkr_pinned_start[];
     339              : extern char lnkr_pinned_end[];
     340              : 
     341              : extern char lnkr_pinned_text_start[];
     342              : extern char lnkr_pinned_text_end[];
     343              : extern char lnkr_pinned_text_size[];
     344              : extern char lnkr_pinned_data_start[];
     345              : extern char lnkr_pinned_data_end[];
     346              : extern char lnkr_pinned_data_size[];
     347              : extern char lnkr_pinned_rodata_start[];
     348              : extern char lnkr_pinned_rodata_end[];
     349              : extern char lnkr_pinned_rodata_size[];
     350              : extern char lnkr_pinned_bss_start[];
     351              : extern char lnkr_pinned_bss_end[];
     352              : extern char lnkr_pinned_bss_size[];
     353              : extern char lnkr_pinned_noinit_start[];
     354              : extern char lnkr_pinned_noinit_end[];
     355              : extern char lnkr_pinned_noinit_size[];
     356              : 
     357              : __pinned_func
     358              : static inline bool lnkr_is_pinned(uint8_t *addr)
     359              : {
     360              :         if ((addr >= (uint8_t *)lnkr_pinned_start) &&
     361              :             (addr < (uint8_t *)lnkr_pinned_end)) {
     362              :                 return true;
     363              :         } else {
     364              :                 return false;
     365              :         }
     366              : }
     367              : 
     368              : __pinned_func
     369              : static inline bool lnkr_is_region_pinned(uint8_t *addr, size_t sz)
     370              : {
     371              :         if ((addr >= (uint8_t *)lnkr_pinned_start) &&
     372              :             ((addr + sz) < (uint8_t *)lnkr_pinned_end)) {
     373              :                 return true;
     374              :         } else {
     375              :                 return false;
     376              :         }
     377              : }
     378              : 
     379              : #endif /* CONFIG_LINKER_USE_PINNED_SECTION */
     380              : 
     381              : #ifdef CONFIG_LINKER_USE_ONDEMAND_SECTION
     382              : /* lnkr_ondemand_start[] and lnkr_ondemand_end[] must encapsulate
     383              :  * all the on-demand sections as these are used by
     384              :  * the MMU code to mark the virtual pages with the appropriate backing store
     385              :  * location token to have them be paged in on demand.
     386              :  */
     387              : extern char lnkr_ondemand_start[];
     388              : extern char lnkr_ondemand_end[];
     389              : extern char lnkr_ondemand_load_start[];
     390              : 
     391              : extern char lnkr_ondemand_text_start[];
     392              : extern char lnkr_ondemand_text_end[];
     393              : extern char lnkr_ondemand_text_size[];
     394              : extern char lnkr_ondemand_rodata_start[];
     395              : extern char lnkr_ondemand_rodata_end[];
     396              : extern char lnkr_ondemand_rodata_size[];
     397              : 
     398              : #endif /* CONFIG_LINKER_USE_ONDEMAND_SECTION */
     399              : #endif /* ! _ASMLANGUAGE */
     400              : 
     401              : #ifdef ZTEST_UNITTEST
     402              : #undef DT_NODE_HAS_STATUS
     403              : #undef DT_NODE_HAS_STATUS_OKAY
     404              : #endif
     405              : 
     406              : #endif /* ZEPHYR_INCLUDE_LINKER_LINKER_DEFS_H_ */
        

Generated by: LCOV version 2.0-1