On 22/09/16 14:11, Sergey Organov wrote:
Sebastian Huber <sebastian.hu...@embedded-brains.de> writes:
Hello,

for RTEMS we use linker sets to initialize the system. The following
code worked up to GCC 6, but no longer in GCC 7:

typedef void ( *rtems_sysinit_handler )( void );

typedef struct {
   rtems_sysinit_handler handler;
} rtems_sysinit_item;

rtems_sysinit_item volatile const _Linker_set__Sysinit_begin[0]
__attribute__((__section__(".rtemsroset." "_Sysinit" ".begin")))
__attribute__((__used__));

rtems_sysinit_item volatile const _Linker_set__Sysinit_end[0]
__attribute__((__section__(".rtemsroset." "_Sysinit" ".end")))
__attribute__((__used__));

void rtems_initialize_executive(void)
{
   const volatile rtems_sysinit_item *cur = _Linker_set__Sysinit_begin;
   const volatile rtems_sysinit_item *end = _Linker_set__Sysinit_end;
You likely have 'volatile' in a wrong place. Try (untested):

rtems_sysinit_item const _Linker_set__Sysinit_begin[0]
__attribute__((__section__(".rtemsroset." "_Sysinit" ".begin")))
__attribute__((__used__));

rtems_sysinit_item const _Linker_set__Sysinit_end[0]
__attribute__((__section__(".rtemsroset." "_Sysinit" ".end")))
__attribute__((__used__));

void rtems_initialize_executive(void)
{
   rtems_sysinit_item const *volatile cur = _Linker_set__Sysinit_begin;
   rtems_sysinit_item const *volatile end = _Linker_set__Sysinit_end;

   while(cur != end) {
     cur->handler();
     ++cur;
   }
}

No, I don't want to load/store the pointers from/to memory all the time in this loop.


Alternatively, try (untested, and I removed attributes to make my point
clearer):

/* Linker-defined symbols */

rtems_sysinit_item const _Linker_set__Sysinit_begin[0]
__attribute__((__section__(".rtemsroset." "_Sysinit" ".begin")))
__attribute__((__used__));

rtems_sysinit_item const _Linker_set__Sysinit_end[0]
__attribute__((__section__(".rtemsroset." "_Sysinit" ".end")))
__attribute__((__used__));

/* Get volatile pointers to the above */
static rtems_sysinit_item const *volatile begin_ = _Linker_set__Sysinit_begin;
static rtems_sysinit_item const *volatile end_   = _Linker_set__Sysinit_end;

void rtems_initialize_executive(void)
{
   rtems_sysinit_item const *cur = begin_;
   rtems_sysinit_item const *end = end_;

   while(cur != end) {
     cur->handler();
     ++cur;
   }
}



I don't want any storage for these begin/end markers.

--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.hu...@embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.

Reply via email to