source: rtems/cpukit/include/rtems/linkersets.h @ 3d2fbaf4

Last change on this file since 3d2fbaf4 was 3d2fbaf4, checked in by Sebastian Huber <sebastian.huber@…>, on 08/29/22 at 06:53:22

Revert "linkersets.h: Fix gcc 12 warning"

This reverts commit f930206724e65f188fe3b095826ceb1b11000f65.

The linker set begin must be a symbol and not a zero-initialized item.

  • Property mode set to 100644
File size: 6.4 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 * Copyright (c) 2015, 2020 embedded brains GmbH.  All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef _RTEMS_LINKERSET_H
29#define _RTEMS_LINKERSET_H
30
31#include <rtems/score/basedefs.h>
32
33#ifdef __cplusplus
34extern "C" {
35#endif /* __cplusplus */
36
37#define RTEMS_LINKER_SET_BEGIN( set ) \
38  _Linker_set_##set##_begin
39
40#define RTEMS_LINKER_SET_END( set ) \
41  _Linker_set_##set##_end
42
43/*
44 * Modern GCC optimizes for speed which may insert padding between linker
45 * sections that previous versions avoided. Alignment must now be explicit to
46 * maintain the behavior of previous versions.
47 */
48#define RTEMS_LINKER_SET_ALIGN( type ) \
49  RTEMS_ALIGNED( RTEMS_ALIGNOF( type ) )
50
51#define RTEMS_LINKER_ROSET_DECLARE( set, type ) \
52  extern RTEMS_LINKER_SET_ALIGN( type ) type    \
53  const RTEMS_LINKER_SET_BEGIN( set )[];        \
54  extern RTEMS_LINKER_SET_ALIGN( type ) type    \
55  const RTEMS_LINKER_SET_END( set )[]
56
57#define RTEMS_LINKER_ROSET( set, type ) \
58  RTEMS_LINKER_SET_ALIGN( type ) type const RTEMS_LINKER_SET_BEGIN( set )[ 0 ] \
59  RTEMS_SECTION( ".rtemsroset." #set ".begin" ) RTEMS_USED; \
60  RTEMS_LINKER_SET_ALIGN( type ) type const RTEMS_LINKER_SET_END( set )[ 0 ] \
61  RTEMS_SECTION( ".rtemsroset." #set ".end" ) RTEMS_USED
62
63#define RTEMS_LINKER_ROSET_ITEM_ORDERED_DECLARE( set, type, item, order ) \
64  extern RTEMS_LINKER_SET_ALIGN( type ) type const _Linker_set_##set##_##item \
65  RTEMS_SECTION( ".rtemsroset." #set ".content.0." RTEMS_XSTRING( order ) )
66
67#define RTEMS_LINKER_ROSET_ITEM_DECLARE( set, type, item ) \
68  extern RTEMS_LINKER_SET_ALIGN( type ) type const _Linker_set_##set##_##item \
69  RTEMS_SECTION( ".rtemsroset." #set ".content.1" )
70
71#define RTEMS_LINKER_ROSET_ITEM_REFERENCE( set, type, item )    \
72  static RTEMS_LINKER_SET_ALIGN( type ) type                    \
73  const * const _Set_reference_##set##_##item                   \
74  RTEMS_SECTION( ".rtemsroset.reference" ) RTEMS_USED =         \
75  &_Linker_set_##set##_##item
76
77#define RTEMS_LINKER_ROSET_ITEM_ORDERED( set, type, item, order ) \
78  RTEMS_LINKER_SET_ALIGN( type ) type const _Linker_set_##set##_##item \
79  RTEMS_SECTION( ".rtemsroset." #set ".content.0." RTEMS_XSTRING( order ) ) \
80  RTEMS_USED
81
82#define RTEMS_LINKER_ROSET_ITEM( set, type, item ) \
83  RTEMS_LINKER_SET_ALIGN( type ) type const _Linker_set_##set##_##item \
84  RTEMS_SECTION( ".rtemsroset." #set ".content.1" ) RTEMS_USED
85
86#define RTEMS_LINKER_ROSET_CONTENT( set, decl ) \
87  decl \
88  RTEMS_SECTION( ".rtemsroset." #set ".content" )
89
90#define RTEMS_LINKER_RWSET_DECLARE( set, type ) \
91  extern RTEMS_LINKER_SET_ALIGN( type ) type RTEMS_LINKER_SET_BEGIN( set )[]; \
92  extern RTEMS_LINKER_SET_ALIGN( type ) type RTEMS_LINKER_SET_END( set )[]
93
94#define RTEMS_LINKER_RWSET( set, type ) \
95  RTEMS_LINKER_SET_ALIGN( type ) type RTEMS_LINKER_SET_BEGIN( set )[ 0 ] \
96  RTEMS_SECTION( ".rtemsrwset." #set ".begin" ) RTEMS_USED; \
97  RTEMS_LINKER_SET_ALIGN( type ) type RTEMS_LINKER_SET_END( set )[ 0 ] \
98  RTEMS_SECTION( ".rtemsrwset." #set ".end" ) RTEMS_USED
99
100#define RTEMS_LINKER_RWSET_ITEM_ORDERED_DECLARE( set, type, item, order ) \
101  extern RTEMS_LINKER_SET_ALIGN( type ) type _Linker_set_##set##_##item \
102  RTEMS_SECTION( ".rtemsrwset." #set ".content.0." RTEMS_XSTRING( order ) )
103
104#define RTEMS_LINKER_RWSET_ITEM_DECLARE( set, type, item ) \
105  extern RTEMS_LINKER_SET_ALIGN( type ) type _Linker_set_##set##_##item \
106  RTEMS_SECTION( ".rtemsrwset." #set ".content.1" )
107
108/*
109 * The .rtemsroset is here not a typo.  We must ensure that the references are
110 * not a victim of the garbage collection of the linker.  Thus, we place them
111 * in a dedicated area of the RTEMS read-only linker set section.
112 */
113#define RTEMS_LINKER_RWSET_ITEM_REFERENCE( set, type, item ) \
114  static RTEMS_LINKER_SET_ALIGN( type ) type                    \
115  * const _Set_reference_##set##_##item                         \
116  RTEMS_SECTION( ".rtemsroset.reference" ) RTEMS_USED = \
117  &_Linker_set_##set##_##item
118
119#define RTEMS_LINKER_RWSET_ITEM_ORDERED( set, type, item, order ) \
120  RTEMS_LINKER_SET_ALIGN( type ) type _Linker_set_##set##_##item \
121  RTEMS_SECTION( ".rtemsrwset." #set ".content.0." RTEMS_XSTRING( order ) ) \
122  RTEMS_USED
123
124#define RTEMS_LINKER_RWSET_ITEM( set, type, item ) \
125  RTEMS_LINKER_SET_ALIGN( type ) type _Linker_set_##set##_##item \
126  RTEMS_SECTION( ".rtemsrwset." #set ".content.1" ) RTEMS_USED
127
128#define RTEMS_LINKER_RWSET_CONTENT( set, decl ) \
129  decl \
130  RTEMS_SECTION( ".rtemsrwset." #set ".content" )
131
132RTEMS_INLINE_ROUTINE uintptr_t _Linker_set_Obfuscate( const void *ptr )
133{
134  uintptr_t addr;
135
136  addr = (uintptr_t) ptr;
137  RTEMS_OBFUSCATE_VARIABLE( addr );
138
139  return addr;
140}
141
142#define RTEMS_LINKER_SET_SIZE( set ) \
143  ( _Linker_set_Obfuscate( RTEMS_LINKER_SET_END( set ) ) \
144    - _Linker_set_Obfuscate( RTEMS_LINKER_SET_BEGIN( set ) ) )
145
146#define RTEMS_LINKER_SET_ITEM_COUNT( set ) \
147  ( RTEMS_LINKER_SET_SIZE( set ) \
148    / sizeof( RTEMS_LINKER_SET_BEGIN( set )[ 0 ] ) )
149
150#define RTEMS_LINKER_SET_IS_EMPTY( set ) \
151  ( RTEMS_LINKER_SET_SIZE( set ) == 0 )
152
153#define RTEMS_LINKER_SET_FOREACH( set, item ) \
154  for ( \
155    item = (void *) _Linker_set_Obfuscate( RTEMS_LINKER_SET_BEGIN( set ) ) ; \
156    item != RTEMS_LINKER_SET_END( set ) ; \
157    ++item \
158  )
159
160#ifdef __cplusplus
161}
162#endif /* __cplusplus */
163
164#endif /* _RTEMS_LINKERSET_H */
Note: See TracBrowser for help on using the repository browser.