RTEMS 6.1-rc5
Loading...
Searching...
No Matches
linkersets.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
11/*
12 * Copyright (C) 2015, 2020 embedded brains GmbH & Co. KG
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#ifndef _RTEMS_LINKERSET_H
37#define _RTEMS_LINKERSET_H
38
40
41#ifdef __cplusplus
42extern "C" {
43#endif /* __cplusplus */
44
55static inline uintptr_t _Linker_set_Obfuscate( const void *ptr )
56{
57 uintptr_t addr;
58
59 addr = (uintptr_t) ptr;
61
62 return addr;
63}
64
75#define RTEMS_LINKER_SET_BEGIN( set ) \
76 _Linker_set_##set##_begin
77
78#define RTEMS_LINKER_SET_END( set ) \
79 _Linker_set_##set##_end
80
81/*
82 * Modern GCC optimizes for speed which may insert padding between linker
83 * sections that previous versions avoided. Alignment must now be explicit to
84 * maintain the behavior of previous versions.
85 */
86#define RTEMS_LINKER_SET_ALIGN( type ) \
87 RTEMS_ALIGNED( RTEMS_ALIGNOF( type ) )
88
89#define RTEMS_LINKER_ROSET_DECLARE( set, type ) \
90 extern RTEMS_LINKER_SET_ALIGN( type ) type \
91 const RTEMS_LINKER_SET_BEGIN( set )[]; \
92 extern RTEMS_LINKER_SET_ALIGN( type ) type \
93 const RTEMS_LINKER_SET_END( set )[]
94
95#define RTEMS_LINKER_ROSET( set, type ) \
96 RTEMS_LINKER_SET_ALIGN( type ) type const RTEMS_LINKER_SET_BEGIN( set )[ 0 ] \
97 RTEMS_SECTION( ".rtemsroset." #set ".begin" ) RTEMS_USED; \
98 RTEMS_LINKER_SET_ALIGN( type ) type const RTEMS_LINKER_SET_END( set )[ 0 ] \
99 RTEMS_SECTION( ".rtemsroset." #set ".end" ) RTEMS_USED
100
101#define RTEMS_LINKER_ROSET_ITEM_ORDERED_DECLARE( set, type, item, order ) \
102 extern RTEMS_LINKER_SET_ALIGN( type ) type const _Linker_set_##set##_##item \
103 RTEMS_SECTION( ".rtemsroset." #set ".content.0." RTEMS_XSTRING( order ) )
104
105#define RTEMS_LINKER_ROSET_ITEM_DECLARE( set, type, item ) \
106 extern RTEMS_LINKER_SET_ALIGN( type ) type const _Linker_set_##set##_##item \
107 RTEMS_SECTION( ".rtemsroset." #set ".content.1" )
108
109#define RTEMS_LINKER_ROSET_ITEM_REFERENCE( set, type, item ) \
110 static RTEMS_LINKER_SET_ALIGN( type ) type \
111 const * const _Set_reference_##set##_##item \
112 RTEMS_SECTION( ".rtemsroset.reference" ) RTEMS_USED = \
113 &_Linker_set_##set##_##item
114
115#define RTEMS_LINKER_ROSET_ITEM_ORDERED( set, type, item, order ) \
116 RTEMS_LINKER_SET_ALIGN( type ) type const _Linker_set_##set##_##item \
117 RTEMS_SECTION( ".rtemsroset." #set ".content.0." RTEMS_XSTRING( order ) ) \
118 RTEMS_USED
119
120#define RTEMS_LINKER_ROSET_ITEM( set, type, item ) \
121 RTEMS_LINKER_SET_ALIGN( type ) type const _Linker_set_##set##_##item \
122 RTEMS_SECTION( ".rtemsroset." #set ".content.1" ) RTEMS_USED
123
124#define RTEMS_LINKER_ROSET_CONTENT( set, decl ) \
125 decl \
126 RTEMS_SECTION( ".rtemsroset." #set ".content" )
127
128#define RTEMS_LINKER_RWSET_DECLARE( set, type ) \
129 extern RTEMS_LINKER_SET_ALIGN( type ) type RTEMS_LINKER_SET_BEGIN( set )[]; \
130 extern RTEMS_LINKER_SET_ALIGN( type ) type RTEMS_LINKER_SET_END( set )[]
131
132#define RTEMS_LINKER_RWSET( set, type ) \
133 RTEMS_LINKER_SET_ALIGN( type ) type RTEMS_LINKER_SET_BEGIN( set )[ 0 ] \
134 RTEMS_SECTION( ".rtemsrwset." #set ".begin" ) RTEMS_USED; \
135 RTEMS_LINKER_SET_ALIGN( type ) type RTEMS_LINKER_SET_END( set )[ 0 ] \
136 RTEMS_SECTION( ".rtemsrwset." #set ".end" ) RTEMS_USED
137
138#define RTEMS_LINKER_RWSET_ITEM_ORDERED_DECLARE( set, type, item, order ) \
139 extern RTEMS_LINKER_SET_ALIGN( type ) type _Linker_set_##set##_##item \
140 RTEMS_SECTION( ".rtemsrwset." #set ".content.0." RTEMS_XSTRING( order ) )
141
142#define RTEMS_LINKER_RWSET_ITEM_DECLARE( set, type, item ) \
143 extern RTEMS_LINKER_SET_ALIGN( type ) type _Linker_set_##set##_##item \
144 RTEMS_SECTION( ".rtemsrwset." #set ".content.1" )
145
146/*
147 * The .rtemsroset is here not a typo. We must ensure that the references are
148 * not a victim of the garbage collection of the linker. Thus, we place them
149 * in a dedicated area of the RTEMS read-only linker set section.
150 */
151#define RTEMS_LINKER_RWSET_ITEM_REFERENCE( set, type, item ) \
152 static RTEMS_LINKER_SET_ALIGN( type ) type \
153 * const _Set_reference_##set##_##item \
154 RTEMS_SECTION( ".rtemsroset.reference" ) RTEMS_USED = \
155 &_Linker_set_##set##_##item
156
157#define RTEMS_LINKER_RWSET_ITEM_ORDERED( set, type, item, order ) \
158 RTEMS_LINKER_SET_ALIGN( type ) type _Linker_set_##set##_##item \
159 RTEMS_SECTION( ".rtemsrwset." #set ".content.0." RTEMS_XSTRING( order ) ) \
160 RTEMS_USED
161
162#define RTEMS_LINKER_RWSET_ITEM( set, type, item ) \
163 RTEMS_LINKER_SET_ALIGN( type ) type _Linker_set_##set##_##item \
164 RTEMS_SECTION( ".rtemsrwset." #set ".content.1" ) RTEMS_USED
165
166#define RTEMS_LINKER_RWSET_CONTENT( set, decl ) \
167 decl \
168 RTEMS_SECTION( ".rtemsrwset." #set ".content" )
169
170#define RTEMS_LINKER_SET_SIZE( set ) \
171 ( _Linker_set_Obfuscate( RTEMS_LINKER_SET_END( set ) ) \
172 - _Linker_set_Obfuscate( RTEMS_LINKER_SET_BEGIN( set ) ) )
173
174#define RTEMS_LINKER_SET_ITEM_COUNT( set ) \
175 ( RTEMS_LINKER_SET_SIZE( set ) \
176 / sizeof( RTEMS_LINKER_SET_BEGIN( set )[ 0 ] ) )
177
178#define RTEMS_LINKER_SET_IS_EMPTY( set ) \
179 ( RTEMS_LINKER_SET_SIZE( set ) == 0 )
180
181#define RTEMS_LINKER_SET_FOREACH( set, item ) \
182 for ( \
183 item = (void *) _Linker_set_Obfuscate( RTEMS_LINKER_SET_BEGIN( set ) ) ; \
184 item != RTEMS_LINKER_SET_END( set ) ; \
185 ++item \
186 )
187
190#ifdef __cplusplus
191}
192#endif /* __cplusplus */
193
194#endif /* _RTEMS_LINKERSET_H */
This header file provides basic definitions used by the API and the implementation.
#define RTEMS_OBFUSCATE_VARIABLE(_var)
Obfuscates the variable so that the compiler cannot perform optimizations based on the variable value...
Definition: basedefs.h:690