[PATCH v3 1/2] cpukit: Explicitly enforce alignment requirements

Kinsey Moore kinsey.moore at oarcorp.com
Wed Mar 3 13:37:19 UTC 2021


According to commentary on GCC bug
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99143, the alignment
behavior of linker sections on which RTEMS has relied was never
guaranteed to be consistent across platforms and any alignment
requirements for linker sections needs to be enforced explicitly.
This adds those explicit alignment requirements.

Closes #4255.
---
 cpukit/include/rtems/linkersets.h | 52 +++++++++++++++++++------------
 1 file changed, 32 insertions(+), 20 deletions(-)

diff --git a/cpukit/include/rtems/linkersets.h b/cpukit/include/rtems/linkersets.h
index d3ed76043a..e156fd4379 100644
--- a/cpukit/include/rtems/linkersets.h
+++ b/cpukit/include/rtems/linkersets.h
@@ -27,36 +27,47 @@ extern "C" {
 #define RTEMS_LINKER_SET_END( set ) \
   _Linker_set_##set##_end
 
+/*
+ * Modern GCC optimizes for speed which may insert padding between linker
+ * sections that previous versions avoided. Alignment must now be explicit to
+ * maintain the behavior of previous versions.
+ */
+#define RTEMS_LINKER_SET_ALIGN( type ) \
+  RTEMS_ALIGNED( RTEMS_ALIGNOF( type ) )
+
 #define RTEMS_LINKER_ROSET_DECLARE( set, type ) \
-  extern type const RTEMS_LINKER_SET_BEGIN( set )[]; \
-  extern type const RTEMS_LINKER_SET_END( set )[]
+  extern RTEMS_LINKER_SET_ALIGN( type ) type	\
+  const RTEMS_LINKER_SET_BEGIN( set )[];	\
+  extern RTEMS_LINKER_SET_ALIGN( type ) type	\
+  const RTEMS_LINKER_SET_END( set )[]
 
 #define RTEMS_LINKER_ROSET( set, type ) \
-  type const RTEMS_LINKER_SET_BEGIN( set )[ 0 ] \
+  RTEMS_LINKER_SET_ALIGN( type ) type const RTEMS_LINKER_SET_BEGIN( set )[ 0 ] \
   RTEMS_SECTION( ".rtemsroset." #set ".begin" ) RTEMS_USED; \
-  type const RTEMS_LINKER_SET_END( set )[ 0 ] \
+  RTEMS_LINKER_SET_ALIGN( type ) type const RTEMS_LINKER_SET_END( set )[ 0 ] \
   RTEMS_SECTION( ".rtemsroset." #set ".end" ) RTEMS_USED
 
 #define RTEMS_LINKER_ROSET_ITEM_ORDERED_DECLARE( set, type, item, order ) \
-  extern type const _Linker_set_##set##_##item \
+  extern RTEMS_LINKER_SET_ALIGN( type ) type const _Linker_set_##set##_##item \
   RTEMS_SECTION( ".rtemsroset." #set ".content.0." RTEMS_XSTRING( order ) )
 
 #define RTEMS_LINKER_ROSET_ITEM_DECLARE( set, type, item ) \
-  extern type const _Linker_set_##set##_##item \
+  extern RTEMS_LINKER_SET_ALIGN( type ) type const _Linker_set_##set##_##item \
   RTEMS_SECTION( ".rtemsroset." #set ".content.1" )
 
-#define RTEMS_LINKER_ROSET_ITEM_REFERENCE( set, type, item ) \
-  static type const * const _Set_reference_##set##_##item \
-  RTEMS_SECTION( ".rtemsroset.reference" ) RTEMS_USED = \
+#define RTEMS_LINKER_ROSET_ITEM_REFERENCE( set, type, item )	\
+  static RTEMS_LINKER_SET_ALIGN( type ) type			\
+  const * const _Set_reference_##set##_##item			\
+  RTEMS_SECTION( ".rtemsroset.reference" ) RTEMS_USED =		\
   &_Linker_set_##set##_##item
 
 #define RTEMS_LINKER_ROSET_ITEM_ORDERED( set, type, item, order ) \
-  type const _Linker_set_##set##_##item \
+  RTEMS_LINKER_SET_ALIGN( type ) type const _Linker_set_##set##_##item \
   RTEMS_SECTION( ".rtemsroset." #set ".content.0." RTEMS_XSTRING( order ) ) \
   RTEMS_USED
 
 #define RTEMS_LINKER_ROSET_ITEM( set, type, item ) \
-  type const _Linker_set_##set##_##item \
+  RTEMS_LINKER_SET_ALIGN( type ) type const _Linker_set_##set##_##item \
   RTEMS_SECTION( ".rtemsroset." #set ".content.1" ) RTEMS_USED
 
 #define RTEMS_LINKER_ROSET_CONTENT( set, decl ) \
@@ -64,21 +75,21 @@ extern "C" {
   RTEMS_SECTION( ".rtemsroset." #set ".content" )
 
 #define RTEMS_LINKER_RWSET_DECLARE( set, type ) \
-  extern type RTEMS_LINKER_SET_BEGIN( set )[]; \
-  extern type RTEMS_LINKER_SET_END( set )[]
+  extern RTEMS_LINKER_SET_ALIGN( type ) type RTEMS_LINKER_SET_BEGIN( set )[]; \
+  extern RTEMS_LINKER_SET_ALIGN( type ) type RTEMS_LINKER_SET_END( set )[]
 
 #define RTEMS_LINKER_RWSET( set, type ) \
-  type RTEMS_LINKER_SET_BEGIN( set )[ 0 ] \
+  RTEMS_LINKER_SET_ALIGN( type ) type RTEMS_LINKER_SET_BEGIN( set )[ 0 ] \
   RTEMS_SECTION( ".rtemsrwset." #set ".begin" ) RTEMS_USED; \
-  type RTEMS_LINKER_SET_END( set )[ 0 ] \
+  RTEMS_LINKER_SET_ALIGN( type ) type RTEMS_LINKER_SET_END( set )[ 0 ] \
   RTEMS_SECTION( ".rtemsrwset." #set ".end" ) RTEMS_USED
 
 #define RTEMS_LINKER_RWSET_ITEM_ORDERED_DECLARE( set, type, item, order ) \
-  extern type _Linker_set_##set##_##item \
+  extern RTEMS_LINKER_SET_ALIGN( type ) type _Linker_set_##set##_##item \
   RTEMS_SECTION( ".rtemsrwset." #set ".content.0." RTEMS_XSTRING( order ) )
 
 #define RTEMS_LINKER_RWSET_ITEM_DECLARE( set, type, item ) \
-  extern type _Linker_set_##set##_##item \
+  extern RTEMS_LINKER_SET_ALIGN( type ) type _Linker_set_##set##_##item \
   RTEMS_SECTION( ".rtemsrwset." #set ".content.1" )
 
 /*
@@ -87,17 +98,18 @@ extern "C" {
  * in a dedicated area of the RTEMS read-only linker set section.
  */
 #define RTEMS_LINKER_RWSET_ITEM_REFERENCE( set, type, item ) \
-  static type * const _Set_reference_##set##_##item \
+  static RTEMS_LINKER_SET_ALIGN( type ) type			\
+  * const _Set_reference_##set##_##item				\
   RTEMS_SECTION( ".rtemsroset.reference" ) RTEMS_USED = \
   &_Linker_set_##set##_##item
 
 #define RTEMS_LINKER_RWSET_ITEM_ORDERED( set, type, item, order ) \
-  type _Linker_set_##set##_##item \
+  RTEMS_LINKER_SET_ALIGN( type ) type _Linker_set_##set##_##item \
   RTEMS_SECTION( ".rtemsrwset." #set ".content.0." RTEMS_XSTRING( order ) ) \
   RTEMS_USED
 
 #define RTEMS_LINKER_RWSET_ITEM( set, type, item ) \
-  type _Linker_set_##set##_##item \
+  RTEMS_LINKER_SET_ALIGN( type ) type _Linker_set_##set##_##item \
   RTEMS_SECTION( ".rtemsrwset." #set ".content.1" ) RTEMS_USED
 
 #define RTEMS_LINKER_RWSET_CONTENT( set, decl ) \
-- 
2.20.1



More information about the devel mailing list