[PATCH v2 2/3] cpukit: Explicitly enforce alignment requirements

Gedare Bloom gedare at rtems.org
Tue Mar 2 20:00:44 UTC 2021


On Tue, Mar 2, 2021 at 12:48 PM Kinsey Moore <kinsey.moore at oarcorp.com> wrote:
>
> 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 | 46 +++++++++++++++++++------------
>  1 file changed, 28 insertions(+), 18 deletions(-)
>
> diff --git a/cpukit/include/rtems/linkersets.h b/cpukit/include/rtems/linkersets.h
> index d3ed76043a..822cc6081b 100644
> --- a/cpukit/include/rtems/linkersets.h
> +++ b/cpukit/include/rtems/linkersets.h
> @@ -27,36 +27,46 @@ extern "C" {
>  #define RTEMS_LINKER_SET_END( set ) \
>    _Linker_set_##set##_end
>
> +/*
> + * The use of explicit alignment is necessary below due to behavioral
> + * expectations of GCC on which RTEMS has relied in the past. These
> + * behaviors were consistent, but never guaranteed. Some newer platforms
> + * violate this previous consistency. For more information, see GCC bug
> + * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99143
> + */
I think the comment can be simplified, but I can tell you got bugged
by this. (pun, intended)

To summarize my understanding, GCC now optimizes space more
aggressively, and if we want an explicit alignment, it has to be
explicitly made on each variable that must be aligned. ("typedef"
alignment now seems to be ignored.)

> +#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_LINKER_SET_ALIGN( type ) static 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 +74,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 +97,17 @@ 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 \
> +  RTEMS_LINKER_SET_ALIGN( type ) static 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
>
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel


More information about the devel mailing list