Zephyr Project API 4.4.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>
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[];
204#endif
205
206#if (DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_ocm)))
207extern char __ocm_data_start[];
208extern char __ocm_data_end[];
209extern char __ocm_bss_start[];
210extern char __ocm_bss_end[];
211extern char __ocm_start[];
212extern char __ocm_end[];
213extern char __ocm_size[];
214#endif
215
216/* Used by the Security Attribution Unit to configure the
217 * Non-Secure Callable region.
218 */
219#ifdef CONFIG_ARM_FIRMWARE_HAS_SECURE_ENTRY_FUNCS
220extern char __sg_start[];
221extern char __sg_end[];
222extern char __sg_size[];
223#endif /* CONFIG_ARM_FIRMWARE_HAS_SECURE_ENTRY_FUNCS */
224
225/*
226 * Non-cached kernel memory region, currently only available on ARM Cortex-M7
227 * with a MPU. Start and end will be aligned for memory management/protection
228 * hardware for the target architecture.
229 *
230 * All the variables with '__nocache' keyword will be placed into the nocache
231 * section, variables with '__nocache_load' keyword will be placed into the
232 * nocache section that is loaded from ROM.
233 */
234#ifdef CONFIG_NOCACHE_MEMORY
235extern char _nocache_ram_start[];
236extern char _nocache_ram_end[];
237extern char _nocache_ram_size[];
238extern char _nocache_noload_ram_start[];
239extern char _nocache_noload_ram_end[];
240extern char _nocache_noload_ram_size[];
241extern char _nocache_load_ram_start[];
242extern char _nocache_load_ram_end[];
243extern char _nocache_load_ram_size[];
244extern char _nocache_load_rom_start[];
245#endif /* CONFIG_NOCACHE_MEMORY */
246
247/* Memory owned by the kernel. Start and end will be aligned for memory
248 * management/protection hardware for the target architecture.
249 *
250 * All the functions with '__ramfunc' keyword will be placed into this
251 * section, stored in RAM instead of FLASH.
252 */
253#ifdef CONFIG_ARCH_HAS_RAMFUNC_SUPPORT
254extern char __ramfunc_region_start[];
255extern char __ramfunc_start[];
256extern char __ramfunc_end[];
257extern char __ramfunc_size[];
258extern char __ramfunc_load_start[];
259#endif /* CONFIG_ARCH_HAS_RAMFUNC_SUPPORT */
260
261/* Memory owned by the kernel. Memory region for thread privilege stack buffers,
262 * currently only applicable on ARM Cortex-M architecture when building with
263 * support for User Mode.
264 *
265 * All thread privilege stack buffers will be placed into this section.
266 */
267#ifdef CONFIG_USERSPACE
268extern char z_priv_stacks_ram_start[];
269extern char z_priv_stacks_ram_end[];
270extern char z_user_stacks_start[];
271extern char z_user_stacks_end[];
272extern char z_kobject_data_begin[];
273#endif /* CONFIG_USERSPACE */
274
275#if defined(CONFIG_STACK_CANARIES_TLS_PREPEND)
276/* Stack canary is prepended to the TLS block; these symbols define its extent. */
277extern char __stack_chk_start[];
278extern char __stack_chk_end[];
279extern char __stack_chk_size[];
280extern char __stack_chk_align[];
281#endif /* CONFIG_STACK_CANARIES_TLS_PREPEND */
282
283#ifdef CONFIG_THREAD_LOCAL_STORAGE
284extern char __tdata_start[];
285extern char __tdata_end[];
286extern char __tdata_size[];
287extern char __tdata_align[];
288extern char __tbss_start[];
289extern char __tbss_end[];
290extern char __tbss_size[];
291extern char __tbss_align[];
292extern char __tls_start[];
293extern char __tls_end[];
294extern char __tls_size[];
295#endif /* CONFIG_THREAD_LOCAL_STORAGE */
296
297#ifdef CONFIG_LINKER_USE_BOOT_SECTION
298/* lnkr_boot_start[] and lnkr_boot_end[]
299 * must encapsulate all the boot sections.
300 */
301extern char lnkr_boot_start[];
302extern char lnkr_boot_end[];
303
304extern char lnkr_boot_text_start[];
305extern char lnkr_boot_text_end[];
306extern char lnkr_boot_text_size[];
307extern char lnkr_boot_data_start[];
308extern char lnkr_boot_data_end[];
309extern char lnkr_boot_data_size[];
310extern char lnkr_boot_rodata_start[];
311extern char lnkr_boot_rodata_end[];
312extern char lnkr_boot_rodata_size[];
313extern char lnkr_boot_bss_start[];
314extern char lnkr_boot_bss_end[];
315extern char lnkr_boot_bss_size[];
316extern char lnkr_boot_noinit_start[];
317extern char lnkr_boot_noinit_end[];
318extern char lnkr_boot_noinit_size[];
319#endif /* CONFIG_LINKER_USE_BOOT_SECTION */
320
321#ifdef CONFIG_LINKER_USE_ONDEMAND_SECTION
322/* lnkr_ondemand_start[] and lnkr_ondemand_end[] must encapsulate
323 * all the on-demand sections as these are used by
324 * the MMU code to mark the virtual pages with the appropriate backing store
325 * location token to have them be paged in on demand.
326 */
327extern char lnkr_ondemand_start[];
328extern char lnkr_ondemand_end[];
329extern char lnkr_ondemand_load_start[];
330
331extern char lnkr_ondemand_text_start[];
332extern char lnkr_ondemand_text_end[];
333extern char lnkr_ondemand_text_size[];
334extern char lnkr_ondemand_rodata_start[];
335extern char lnkr_ondemand_rodata_end[];
336extern char lnkr_ondemand_rodata_size[];
337
338#endif /* CONFIG_LINKER_USE_ONDEMAND_SECTION */
339#endif /* ! _ASMLANGUAGE */
340
341#ifdef ZTEST_UNITTEST
342#undef DT_NODE_HAS_STATUS
343#undef DT_NODE_HAS_STATUS_OKAY
344#endif
345
346#endif /* ZEPHYR_INCLUDE_LINKER_LINKER_DEFS_H_ */
Devicetree main header.
Common toolchain abstraction.
Definitions of various linker Sections.
Misc utilities.
Macros to abstract toolchain specific capabilities.