Zephyr API Documentation 4.5.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
linker-defs.h
Go to the documentation of this file.
1/*
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>
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 workaround 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#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#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 */
85GDATA(__bss_start)
86GDATA(__bss_num_words)
87#ifdef CONFIG_XIP
88GDATA(__data_region_load_start)
89GDATA(__data_region_start)
90GDATA(__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 */
107extern char _app_smem_start[];
108extern char _app_smem_end[];
109extern char _app_smem_size[];
110extern char _app_smem_rom_start[];
111extern char _app_smem_num_words[];
112
113/* Memory owned by the kernel. Start and end will be aligned for memory
114 * management/protection hardware for the target architecture.
115 *
116 * Consists of all kernel-side globals, all kernel objects, all thread stacks,
117 * and all currently unused RAM.
118 *
119 * Except for the stack of the currently executing thread, none of this memory
120 * is normally accessible to user threads unless specifically granted at
121 * runtime.
122 */
123extern char __kernel_ram_start[];
124extern char __kernel_ram_end[];
125extern char __kernel_ram_size[];
126
127/* Used by arch_bss_zero or arch-specific implementation */
128extern char __bss_start[];
129extern char __bss_end[];
130
131/* Used by arch_data_copy() or arch-specific implementation */
132#ifdef CONFIG_XIP
133extern char __data_region_load_start[];
134extern char __data_region_start[];
135extern char __data_region_end[];
136#endif /* CONFIG_XIP */
137
138#ifdef CONFIG_MMU
139/* Virtual addresses of page-aligned kernel image mapped into RAM at boot */
140extern char z_mapped_start[];
141extern char z_mapped_end[];
142#endif /* CONFIG_MMU */
143
144/* Includes text and rodata */
145extern char __rom_region_start[];
146extern char __rom_region_end[];
147extern char __rom_region_size[];
148
149/* Includes all ROMable data, i.e. the size of the output image file. */
150extern char _flash_used[];
151
152/* datas, bss, noinit */
153extern char _image_ram_start[];
154extern char _image_ram_end[];
155extern char _image_ram_size[];
156
157extern char __text_region_start[];
158extern char __text_region_end[];
159extern char __text_region_size[];
160
161extern char __rodata_region_start[];
162extern char __rodata_region_end[];
163extern char __rodata_region_size[];
164
165extern char _vector_start[];
166extern char _vector_end[];
167
168#ifdef CONFIG_SW_VECTOR_RELAY
169extern char __vector_relay_table[];
170#endif
171
172#ifdef CONFIG_SRAM_VECTOR_TABLE
173extern char _sram_vector_start[];
174extern char _sram_vector_end[];
175extern char _sram_vector_size[];
176#endif
177
178#ifdef CONFIG_COVERAGE_GCOV
179extern char __gcov_bss_start[];
180extern char __gcov_bss_end[];
181extern char __gcov_bss_size[];
182#endif /* CONFIG_COVERAGE_GCOV */
183
184/* end address of image, used by newlib for the heap */
185extern char _end[];
186
187#if (DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_itcm)))
188extern char __itcm_start[];
189extern char __itcm_end[];
190extern char __itcm_size[];
191extern char __itcm_load_start[];
192#endif
193
194#if (DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_dtcm)))
195extern char __dtcm_data_start[];
196extern char __dtcm_data_end[];
197extern char __dtcm_bss_start[];
198extern char __dtcm_bss_end[];
199extern char __dtcm_noinit_start[];
200extern char __dtcm_noinit_end[];
201extern char __dtcm_data_load_start[];
202extern char __dtcm_start[];
203extern char __dtcm_end[];
204extern char __dtcm_size[];
205#endif
206
207#if (DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_ocm)))
208extern char __ocm_data_start[];
209extern char __ocm_data_end[];
210extern char __ocm_bss_start[];
211extern char __ocm_bss_end[];
212extern char __ocm_start[];
213extern char __ocm_end[];
214extern char __ocm_size[];
215#endif
216
217/* Used by the Security Attribution Unit to configure the
218 * Non-Secure Callable region.
219 */
220#ifdef CONFIG_ARM_FIRMWARE_HAS_SECURE_ENTRY_FUNCS
221extern char __sg_start[];
222extern char __sg_end[];
223extern char __sg_size[];
224#endif /* CONFIG_ARM_FIRMWARE_HAS_SECURE_ENTRY_FUNCS */
225
226/*
227 * Non-cached kernel memory region, currently only available on ARM Cortex-M7
228 * with a MPU. Start and end will be aligned for memory management/protection
229 * hardware for the target architecture.
230 *
231 * All the variables with '__nocache' keyword will be placed into the nocache
232 * section, variables with '__nocache_load' keyword will be placed into the
233 * nocache section that is loaded from ROM.
234 */
235#ifdef CONFIG_NOCACHE_MEMORY
236extern char _nocache_ram_start[];
237extern char _nocache_ram_end[];
238extern char _nocache_ram_size[];
239extern char _nocache_noload_ram_start[];
240extern char _nocache_noload_ram_end[];
241extern char _nocache_noload_ram_size[];
242extern char _nocache_load_ram_start[];
243extern char _nocache_load_ram_end[];
244extern char _nocache_load_ram_size[];
245extern char _nocache_load_rom_start[];
246#endif /* CONFIG_NOCACHE_MEMORY */
247
248/* Memory owned by the kernel. Start and end will be aligned for memory
249 * management/protection hardware for the target architecture.
250 *
251 * All the functions with '__ramfunc' keyword will be placed into this
252 * section, stored in RAM instead of FLASH.
253 */
254#ifdef CONFIG_ARCH_HAS_RAMFUNC_SUPPORT
255extern char __ramfunc_region_start[];
256extern char __ramfunc_start[];
257extern char __ramfunc_end[];
258extern char __ramfunc_size[];
259extern char __ramfunc_load_start[];
260#endif /* CONFIG_ARCH_HAS_RAMFUNC_SUPPORT */
261
262/* Memory owned by the kernel. Memory region for thread privilege stack buffers,
263 * currently only applicable on ARM Cortex-M architecture when building with
264 * support for User Mode.
265 *
266 * All thread privilege stack buffers will be placed into this section.
267 */
268#ifdef CONFIG_USERSPACE
269extern char z_priv_stacks_ram_start[];
270extern char z_priv_stacks_ram_end[];
271extern char z_user_stacks_start[];
272extern char z_user_stacks_end[];
273extern char z_kobject_data_begin[];
274#endif /* CONFIG_USERSPACE */
275
276#if defined(CONFIG_STACK_CANARIES_TLS_PREPEND)
277/* Stack canary is prepended to the TLS block; these symbols define its extent. */
278extern char __stack_chk_start[];
279extern char __stack_chk_end[];
280extern char __stack_chk_size[];
281extern char __stack_chk_align[];
282#endif /* CONFIG_STACK_CANARIES_TLS_PREPEND */
283
284#ifdef CONFIG_THREAD_LOCAL_STORAGE
285extern char __tdata_start[];
286extern char __tdata_end[];
287extern char __tdata_size[];
288extern char __tdata_align[];
289extern char __tbss_start[];
290extern char __tbss_end[];
291extern char __tbss_size[];
292extern char __tbss_align[];
293extern char __tls_start[];
294extern char __tls_end[];
295extern char __tls_size[];
296#endif /* CONFIG_THREAD_LOCAL_STORAGE */
297
298#ifdef CONFIG_LINKER_USE_BOOT_SECTION
299/* lnkr_boot_start[] and lnkr_boot_end[]
300 * must encapsulate all the boot sections.
301 */
302extern char lnkr_boot_start[];
303extern char lnkr_boot_end[];
304
305extern char lnkr_boot_text_start[];
306extern char lnkr_boot_text_end[];
307extern char lnkr_boot_text_size[];
308extern char lnkr_boot_data_start[];
309extern char lnkr_boot_data_end[];
310extern char lnkr_boot_data_size[];
311extern char lnkr_boot_rodata_start[];
312extern char lnkr_boot_rodata_end[];
313extern char lnkr_boot_rodata_size[];
314extern char lnkr_boot_bss_start[];
315extern char lnkr_boot_bss_end[];
316extern char lnkr_boot_bss_size[];
317extern char lnkr_boot_noinit_start[];
318extern char lnkr_boot_noinit_end[];
319extern char lnkr_boot_noinit_size[];
320#endif /* CONFIG_LINKER_USE_BOOT_SECTION */
321
322#ifdef CONFIG_LINKER_USE_ONDEMAND_SECTION
323/* lnkr_ondemand_start[] and lnkr_ondemand_end[] must encapsulate
324 * all the on-demand sections as these are used by
325 * the MMU code to mark the virtual pages with the appropriate backing store
326 * location token to have them be paged in on demand.
327 */
328extern char lnkr_ondemand_start[];
329extern char lnkr_ondemand_end[];
330extern char lnkr_ondemand_load_start[];
331
332extern char lnkr_ondemand_text_start[];
333extern char lnkr_ondemand_text_end[];
334extern char lnkr_ondemand_text_size[];
335extern char lnkr_ondemand_rodata_start[];
336extern char lnkr_ondemand_rodata_end[];
337extern char lnkr_ondemand_rodata_size[];
338
339#endif /* CONFIG_LINKER_USE_ONDEMAND_SECTION */
340#endif /* ! _ASMLANGUAGE */
341
342#ifdef ZTEST_UNITTEST
343#undef DT_NODE_HAS_STATUS
344#undef DT_NODE_HAS_STATUS_OKAY
345#endif
346
347#endif /* ZEPHYR_INCLUDE_LINKER_LINKER_DEFS_H_ */
Devicetree main header.
Definitions of various linker Sections.
Misc utilities.
Macros to abstract toolchain specific capabilities.