https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99143

--- Comment #2 from Will <nyphbl8d at gmail dot com> ---
The issue is that these are not getting aligned down to the size of the type
causing extra space in the linker sets. The above may be a bad reduced test
case. Below is a test case that focuses on 4-byte alignment which is the
primary issue on ILP32. When compiling with ARM gcc instead of AArch64 gcc, the
int section is aligned at 4 bytes instead of 8.

An example closer to the real code:
test-linkersets.c:
#define RTEMS_USED __attribute__(( __used__ ))

#define RTEMS_SECTION( _section ) __attribute__(( __section__( _section ) ))

#define RTEMS_LINKER_SET_BEGIN( set ) \
   _Linker_set_##set##_begin

#define RTEMS_LINKER_SET_END( set ) \
   _Linker_set_##set##_end

#define RTEMS_LINKER_ROSET( set, 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_SECTION( ".rtemsroset." #set ".end" ) RTEMS_USED

RTEMS_LINKER_ROSET( i, int );
RTEMS_LINKER_ROSET( ll, long long );

test-linkersets.i:
# 1 "test-linkersets.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "test-linkersets.c"
# 17 "test-linkersets.c"
char const _Linker_set_c_begin[ 0 ] __attribute__(( __section__( ".rtemsroset."
"c" ".begin" ) )) __attribute__(( __used__ )); char const _Linker_set_c_end[ 0
] __attribute__(( __section__( ".rtemsroset." "c" ".end" ) )) __attribute__((
__used__ ));
int const _Linker_set_i_begin[ 0 ] __attribute__(( __section__( ".rtemsroset."
"i" ".begin" ) )) __attribute__(( __used__ )); int const _Linker_set_i_end[ 0 ]
__attribute__(( __section__( ".rtemsroset." "i" ".end" ) )) __attribute__((
__used__ ));
long long const _Linker_set_ll_begin[ 0 ] __attribute__(( __section__(
".rtemsroset." "ll" ".begin" ) )) __attribute__(( __used__ )); long long const
_Linker_set_ll_end[ 0 ] __attribute__(( __section__( ".rtemsroset." "ll" ".end"
) )) __attribute__(( __used__ ));

aarch64-rtems6-gcc -O2 -S -mabi=ilp32 -o - test-linkersets.c
        .arch armv8-a
        .file   "test-linkersets.c"
        .text
        .global _Linker_set_ll_end
        .global _Linker_set_ll_begin
        .global _Linker_set_i_end
        .global _Linker_set_i_begin
        .global _Linker_set_c_end
        .global _Linker_set_c_begin
        .section        .rtemsroset.c.begin,"a"
        .align  3
        .type   _Linker_set_c_begin, %object
        .size   _Linker_set_c_begin, 0
_Linker_set_c_begin:
        .section        .rtemsroset.c.end,"a"
        .align  3
        .type   _Linker_set_c_end, %object
        .size   _Linker_set_c_end, 0
_Linker_set_c_end:
        .section        .rtemsroset.i.begin,"a"
        .align  3
        .type   _Linker_set_i_begin, %object
        .size   _Linker_set_i_begin, 0
_Linker_set_i_begin:
        .section        .rtemsroset.i.end,"a"
        .align  3
        .type   _Linker_set_i_end, %object
        .size   _Linker_set_i_end, 0
_Linker_set_i_end:
        .section        .rtemsroset.ll.begin,"a"
        .align  3
        .type   _Linker_set_ll_begin, %object
        .size   _Linker_set_ll_begin, 0
_Linker_set_ll_begin:
        .section        .rtemsroset.ll.end,"a"
        .align  3
        .type   _Linker_set_ll_end, %object
        .size   _Linker_set_ll_end, 0
_Linker_set_ll_end:
        .ident  "GCC: (GNU) 10.2.1 20200918 (RTEMS 6, RSB
f5fc2bfabbd18f31901ffa6fc0e5b6b47874797c-modified, Newlib 749cbcc)"

Reply via email to