Line data Source code
1 0 : /*
2 : * Copyright (C) 2020, Intel Corporation
3 : * Copyright (C) 2023, Nordic Semiconductor ASA
4 : * SPDX-License-Identifier: Apache-2.0
5 : */
6 :
7 : #ifndef INCLUDE_ZEPHYR_LINKER_ITERABLE_SECTIONS_H_
8 : #define INCLUDE_ZEPHYR_LINKER_ITERABLE_SECTIONS_H_
9 :
10 : /**
11 : * @addtogroup iterable_section_apis
12 : * @{
13 : */
14 :
15 : /* clang-format off */
16 : #define Z_LINK_ITERABLE(struct_type) \
17 : PLACE_SYMBOL_HERE(_CONCAT(_##struct_type, _list_start)); \
18 : KEEP(*(SORT_BY_NAME(._##struct_type.static.*))); \
19 : PLACE_SYMBOL_HERE(_CONCAT(_##struct_type, _list_end));
20 :
21 :
22 : #define Z_LINK_ITERABLE_NUMERIC(struct_type) \
23 : PLACE_SYMBOL_HERE(_CONCAT(_##struct_type, _list_start)); \
24 : KEEP(*(SORT(._##struct_type.static.*_?_*))); \
25 : KEEP(*(SORT(._##struct_type.static.*_??_*))); \
26 : KEEP(*(SORT(._##struct_type.static.*_???_*))); \
27 : KEEP(*(SORT(._##struct_type.static.*_????_*))); \
28 : KEEP(*(SORT(._##struct_type.static.*_?????_*))); \
29 : PLACE_SYMBOL_HERE(_CONCAT(_##struct_type, _list_end));
30 :
31 : #define Z_LINK_ITERABLE_ALIGNED(struct_type, align) \
32 : . = ALIGN(align); \
33 : Z_LINK_ITERABLE(struct_type);
34 :
35 : #define Z_LINK_ITERABLE_GC_ALLOWED(struct_type) \
36 : PLACE_SYMBOL_HERE(_CONCAT(_##struct_type, _list_start)); \
37 : *(SORT_BY_NAME(._##struct_type.static.*)); \
38 : PLACE_SYMBOL_HERE(_CONCAT(_##struct_type, _list_end));
39 : /* clang-format on */
40 :
41 : #define Z_LINK_ITERABLE_SUBALIGN CONFIG_LINKER_ITERABLE_SUBALIGN
42 :
43 : /**
44 : * @brief Define a read-only iterable section output.
45 : *
46 : * @details
47 : * Define an output section which will set up an iterable area
48 : * of equally-sized data structures. For use with STRUCT_SECTION_ITERABLE().
49 : * Input sections will be sorted by name, per ld's SORT_BY_NAME.
50 : *
51 : * This macro should be used for read-only data.
52 : *
53 : * Note that this keeps the symbols in the image even though
54 : * they are not being directly referenced. Use this when symbols
55 : * are indirectly referenced by iterating through the section.
56 : */
57 1 : #define ITERABLE_SECTION_ROM(struct_type, subalign) \
58 : SECTION_PROLOGUE(struct_type##_area, ,) \
59 : { \
60 : Z_LINK_ITERABLE(struct_type); \
61 : } GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
62 :
63 : /**
64 : * @brief Define a read-only iterable section output, sorted numerically.
65 : *
66 : * This version of ITERABLE_SECTION_ROM() sorts the entries numerically, that
67 : * is, `SECNAME_10` will come after `SECNAME_2`. `_` separator is required, and
68 : * up to 2 numeric digits are handled (0-99).
69 : *
70 : * @see ITERABLE_SECTION_ROM()
71 : */
72 1 : #define ITERABLE_SECTION_ROM_NUMERIC(struct_type, subalign) \
73 : SECTION_PROLOGUE(struct_type##_area, EMPTY,) \
74 : { \
75 : Z_LINK_ITERABLE_NUMERIC(struct_type); \
76 : } GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
77 :
78 : /**
79 : * @brief Define a garbage collectable read-only iterable section output.
80 : *
81 : * @details
82 : * Define an output section which will set up an iterable area
83 : * of equally-sized data structures. For use with STRUCT_SECTION_ITERABLE().
84 : * Input sections will be sorted by name, per ld's SORT_BY_NAME.
85 : *
86 : * This macro should be used for read-only data.
87 : *
88 : * Note that the symbols within the section can be garbage collected.
89 : */
90 1 : #define ITERABLE_SECTION_ROM_GC_ALLOWED(struct_type, subalign) \
91 : SECTION_PROLOGUE(struct_type##_area, ,) \
92 : { \
93 : Z_LINK_ITERABLE_GC_ALLOWED(struct_type); \
94 : } GROUP_LINK_IN(ROMABLE_REGION)
95 :
96 : /**
97 : * @brief Define a read-write iterable section output.
98 : *
99 : * @details
100 : * Define an output section which will set up an iterable area
101 : * of equally-sized data structures. For use with STRUCT_SECTION_ITERABLE().
102 : * Input sections will be sorted by name, per ld's SORT_BY_NAME.
103 : *
104 : * This macro should be used for read-write data that is modified at runtime.
105 : *
106 : * Note that this keeps the symbols in the image even though
107 : * they are not being directly referenced. Use this when symbols
108 : * are indirectly referenced by iterating through the section.
109 : */
110 1 : #define ITERABLE_SECTION_RAM(struct_type, subalign) \
111 : SECTION_DATA_PROLOGUE(struct_type##_area, ,) \
112 : { \
113 : Z_LINK_ITERABLE(struct_type); \
114 : } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
115 :
116 : /**
117 : * @brief Define a read-write iterable section output, sorted numerically.
118 : *
119 : * This version of ITERABLE_SECTION_RAM() sorts the entries numerically, that
120 : * is, `SECNAME10` will come after `SECNAME2`. Up to 2 numeric digits are
121 : * handled (0-99).
122 : *
123 : * @see ITERABLE_SECTION_RAM()
124 : */
125 1 : #define ITERABLE_SECTION_RAM_NUMERIC(struct_type, subalign) \
126 : SECTION_PROLOGUE(struct_type##_area, EMPTY,) \
127 : { \
128 : Z_LINK_ITERABLE_NUMERIC(struct_type); \
129 : } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
130 :
131 : /**
132 : * @brief Define a garbage collectable read-write iterable section output.
133 : *
134 : * @details
135 : * Define an output section which will set up an iterable area
136 : * of equally-sized data structures. For use with STRUCT_SECTION_ITERABLE().
137 : * Input sections will be sorted by name, per ld's SORT_BY_NAME.
138 : *
139 : * This macro should be used for read-write data that is modified at runtime.
140 : *
141 : * Note that the symbols within the section can be garbage collected.
142 : */
143 1 : #define ITERABLE_SECTION_RAM_GC_ALLOWED(struct_type, subalign) \
144 : SECTION_DATA_PROLOGUE(struct_type##_area, ,) \
145 : { \
146 : Z_LINK_ITERABLE_GC_ALLOWED(struct_type); \
147 : } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
148 :
149 : /**
150 : * @}
151 : */ /* end of struct_section_apis */
152 :
153 : #endif /* INCLUDE_ZEPHYR_LINKER_ITERABLE_SECTIONS_H_ */
|