[PATCH 2/2] score: More robust linker sets

Sebastian Huber sebastian.huber at embedded-brains.de
Wed Oct 12 09:13:08 UTC 2016


Update #2408.
Update #2790.
---
 cpukit/sapi/src/exinit.c                 |  7 ++-
 cpukit/score/include/rtems/linkersets.h  | 50 +++++++++++++---------
 testsuites/sptests/splinkersets01/init.c | 73 +++++++++++++++++++-------------
 3 files changed, 80 insertions(+), 50 deletions(-)

diff --git a/cpukit/sapi/src/exinit.c b/cpukit/sapi/src/exinit.c
index 7988a5b..f4bea7c 100644
--- a/cpukit/sapi/src/exinit.c
+++ b/cpukit/sapi/src/exinit.c
@@ -131,8 +131,11 @@ RTEMS_SYSINIT_ITEM(
 
 void rtems_initialize_executive(void)
 {
-  const volatile rtems_sysinit_item *cur = RTEMS_LINKER_SET_BEGIN(_Sysinit );
-  const volatile rtems_sysinit_item *end = RTEMS_LINKER_SET_END( _Sysinit );
+  const rtems_sysinit_item *cur;
+  const rtems_sysinit_item *end;
+
+  RTEMS_LINKER_SET_ASSIGN_BEGIN(_Sysinit, cur );
+  RTEMS_LINKER_SET_ASSIGN_END( _Sysinit, end );
 
   /* Invoke the registered system initialization handlers */
   while ( cur != end ) {
diff --git a/cpukit/score/include/rtems/linkersets.h b/cpukit/score/include/rtems/linkersets.h
index 47c210d..b790fa5 100644
--- a/cpukit/score/include/rtems/linkersets.h
+++ b/cpukit/score/include/rtems/linkersets.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 embedded brains GmbH.  All rights reserved.
+ * Copyright (c) 2015, 2016 embedded brains GmbH.  All rights reserved.
  *
  *  embedded brains GmbH
  *  Dornierstr. 4
@@ -21,40 +21,52 @@
 extern "C" {
 #endif /* __cplusplus */
 
-#define RTEMS_LINKER_SET_BEGIN( set ) \
+#define _LINKER_SET_BEGIN( set ) \
   _Linker_set_##set##_begin
 
-#define RTEMS_LINKER_SET_END( set ) \
+#define _LINKER_SET_END( set ) \
   _Linker_set_##set##_end
 
+#define RTEMS_LINKER_SET_ASSIGN_BEGIN( set, item ) \
+  do { \
+    item = _LINKER_SET_BEGIN( set ); \
+    RTEMS_OBFUSCATE_POINTER( item ); \
+  } while ( 0 )
+
+#define RTEMS_LINKER_SET_ASSIGN_END( set, item ) \
+  do { \
+    item = _LINKER_SET_END( set ); \
+    RTEMS_OBFUSCATE_POINTER( item ); \
+  } while ( 0 )
+
 #define RTEMS_LINKER_SET_SIZE( set ) \
   ( (size_t) ( _Linker_set_##set##_end - _Linker_set_##set##_begin ) )
 
 #define RTEMS_LINKER_ROSET_DECLARE( set, type ) \
-  extern type volatile const RTEMS_LINKER_SET_BEGIN( set )[0]; \
-  extern type volatile const RTEMS_LINKER_SET_END( set )[0]
+  extern type const _LINKER_SET_BEGIN( set )[0]; \
+  extern type const _LINKER_SET_END( set )[0]
 
 #define RTEMS_LINKER_ROSET( set, type ) \
-  type volatile const RTEMS_LINKER_SET_BEGIN( set )[0] \
+  type const _LINKER_SET_BEGIN( set )[0] \
   RTEMS_SECTION( ".rtemsroset." #set ".begin" ) RTEMS_USED; \
-  type volatile const RTEMS_LINKER_SET_END( set )[0] \
+  type const _LINKER_SET_END( set )[0] \
   RTEMS_SECTION( ".rtemsroset." #set ".end" ) RTEMS_USED
 
 #define RTEMS_LINKER_ROSET_ITEM_DECLARE( set, type, item ) \
-  extern type volatile const _Linker_set_##set##_##item
+  extern type const _Linker_set_##set##_##item
 
 #define RTEMS_LINKER_ROSET_ITEM_REFERENCE( set, type, item ) \
-  static type volatile const * const _Set_reference_##set##_##item \
+  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 volatile const _Linker_set_##set##_##item \
+  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 volatile const _Linker_set_##set##_##item \
+  type const _Linker_set_##set##_##item \
   RTEMS_SECTION( ".rtemsroset." #set ".content.1" ) RTEMS_USED
 
 #define RTEMS_LINKER_ROSET_CONTENT( set, decl ) \
@@ -62,17 +74,17 @@ extern "C" {
   RTEMS_SECTION( ".rtemsroset." #set ".content" )
 
 #define RTEMS_LINKER_RWSET_DECLARE( set, type ) \
-  extern type volatile RTEMS_LINKER_SET_BEGIN( set )[0]; \
-  extern type volatile RTEMS_LINKER_SET_END( set )[0]
+  extern type _LINKER_SET_BEGIN( set )[0]; \
+  extern type _LINKER_SET_END( set )[0]
 
 #define RTEMS_LINKER_RWSET( set, type ) \
-  type volatile RTEMS_LINKER_SET_BEGIN( set )[0] \
+  type _LINKER_SET_BEGIN( set )[0] \
   RTEMS_SECTION( ".rtemsrwset." #set ".begin" ) RTEMS_USED; \
-  type volatile RTEMS_LINKER_SET_END( set )[0] \
+  type _LINKER_SET_END( set )[0] \
   RTEMS_SECTION( ".rtemsrwset." #set ".end" ) RTEMS_USED
 
 #define RTEMS_LINKER_RWSET_ITEM_DECLARE( set, type, item ) \
-  extern type volatile _Linker_set_##set##_##item
+  extern type _Linker_set_##set##_##item
 
 /*
  * The .rtemsroset is here not a typo.  We must ensure that the references are
@@ -80,17 +92,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 volatile * const _Set_reference_##set##_##item \
+  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 volatile _Linker_set_##set##_##item \
+  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 volatile _Linker_set_##set##_##item \
+  type _Linker_set_##set##_##item \
   RTEMS_SECTION( ".rtemsrwset." #set ".content.1" ) RTEMS_USED
 
 #define RTEMS_LINKER_RWSET_CONTENT( set, decl ) \
diff --git a/testsuites/sptests/splinkersets01/init.c b/testsuites/sptests/splinkersets01/init.c
index 853d8e1..71f69b7 100644
--- a/testsuites/sptests/splinkersets01/init.c
+++ b/testsuites/sptests/splinkersets01/init.c
@@ -85,18 +85,29 @@ ITEM(s0, SAFE_ORDER_A);
 
 static void test(void)
 {
-  const int * volatile *b = RTEMS_LINKER_SET_BEGIN(test_rw);
-  const int * volatile *e = RTEMS_LINKER_SET_END(test_rw);
-  const int * volatile const *cb = RTEMS_LINKER_SET_BEGIN(test_ro);
-  const int * volatile const *ce = RTEMS_LINKER_SET_END(test_ro);
-  const int * volatile *bi = RTEMS_LINKER_SET_BEGIN(test_rw_i);
-  const int * volatile *ei = RTEMS_LINKER_SET_END(test_rw_i);
-  const int * volatile const *cbi = RTEMS_LINKER_SET_BEGIN(test_ro_i);
-  const int * volatile const *cei = RTEMS_LINKER_SET_END(test_ro_i);
-  const int * volatile const *sb = RTEMS_LINKER_SET_BEGIN(test_ro_s);
-  const int * volatile const *se = RTEMS_LINKER_SET_END(test_ro_s);
+  const int **b;
+  const int **e;
+  const int * const *cb;
+  const int * const *ce;
+  const int **bi;
+  const int **ei;
+  const int * const *cbi;
+  const int * const *cei;
+  const int * const *sb;
+  const int * const *se;
   size_t i;
 
+  RTEMS_LINKER_SET_ASSIGN_BEGIN(test_rw, b);
+  RTEMS_LINKER_SET_ASSIGN_END(test_rw, e);
+  RTEMS_LINKER_SET_ASSIGN_BEGIN(test_ro, cb);
+  RTEMS_LINKER_SET_ASSIGN_END(test_ro, ce);
+  RTEMS_LINKER_SET_ASSIGN_BEGIN(test_rw_i, bi);
+  RTEMS_LINKER_SET_ASSIGN_END(test_rw_i, ei);
+  RTEMS_LINKER_SET_ASSIGN_BEGIN(test_ro_i, cbi);
+  RTEMS_LINKER_SET_ASSIGN_END(test_ro_i, cei);
+  RTEMS_LINKER_SET_ASSIGN_BEGIN(test_ro_s, sb);
+  RTEMS_LINKER_SET_ASSIGN_END(test_ro_s, se);
+
   rtems_test_assert((size_t) (e - b) == RTEMS_ARRAY_SIZE(a));
   rtems_test_assert((size_t) (ce - cb) == RTEMS_ARRAY_SIZE(ca));
   rtems_test_assert(RTEMS_LINKER_SET_SIZE(test_rw) == RTEMS_ARRAY_SIZE(a));
@@ -132,25 +143,29 @@ static void test(void)
 
 static void test_content(void)
 {
-  uintptr_t b_rw = (uintptr_t) RTEMS_LINKER_SET_BEGIN(test_content_rw);
-  uintptr_t e_rw = (uintptr_t) RTEMS_LINKER_SET_END(test_content_rw);
-
-  uintptr_t b_ro = (uintptr_t) RTEMS_LINKER_SET_BEGIN(test_content_ro);
-  uintptr_t e_ro = (uintptr_t) RTEMS_LINKER_SET_END(test_content_ro);
-
-  rtems_test_assert((uintptr_t) &content_rw_1 >= b_rw);
-  rtems_test_assert((uintptr_t) &content_rw_2 >= b_rw);
-  rtems_test_assert((uintptr_t) &content_rw_3 >= b_rw);
-  rtems_test_assert((uintptr_t) &content_rw_1 <= e_rw);
-  rtems_test_assert((uintptr_t) &content_rw_2 <= e_rw);
-  rtems_test_assert((uintptr_t) &content_rw_3 <= e_rw);
-
-  rtems_test_assert((uintptr_t) &content_ro_1 >= b_ro);
-  rtems_test_assert((uintptr_t) &content_ro_2 >= b_ro);
-  rtems_test_assert((uintptr_t) &content_ro_3 >= b_ro);
-  rtems_test_assert((uintptr_t) &content_ro_1 <= e_ro);
-  rtems_test_assert((uintptr_t) &content_ro_2 <= e_ro);
-  rtems_test_assert((uintptr_t) &content_ro_3 <= e_ro);
+  const char *b_rw;
+  const char *e_rw;
+  const char *b_ro;
+  const char *e_ro;
+
+  RTEMS_LINKER_SET_ASSIGN_BEGIN(test_content_rw, b_rw);
+  RTEMS_LINKER_SET_ASSIGN_END(test_content_rw, e_rw);
+  RTEMS_LINKER_SET_ASSIGN_BEGIN(test_content_ro, b_ro);
+  RTEMS_LINKER_SET_ASSIGN_END(test_content_ro, e_ro);
+
+  rtems_test_assert((uintptr_t) &content_rw_1 >= (uintptr_t) b_rw);
+  rtems_test_assert((uintptr_t) &content_rw_2 >= (uintptr_t) b_rw);
+  rtems_test_assert((uintptr_t) &content_rw_3 >= (uintptr_t) b_rw);
+  rtems_test_assert((uintptr_t) &content_rw_1 <= (uintptr_t) e_rw);
+  rtems_test_assert((uintptr_t) &content_rw_2 <= (uintptr_t) e_rw);
+  rtems_test_assert((uintptr_t) &content_rw_3 <= (uintptr_t) e_rw);
+
+  rtems_test_assert((uintptr_t) &content_ro_1 >= (uintptr_t) b_ro);
+  rtems_test_assert((uintptr_t) &content_ro_2 >= (uintptr_t) b_ro);
+  rtems_test_assert((uintptr_t) &content_ro_3 >= (uintptr_t) b_ro);
+  rtems_test_assert((uintptr_t) &content_ro_1 <= (uintptr_t) e_ro);
+  rtems_test_assert((uintptr_t) &content_ro_2 <= (uintptr_t) e_ro);
+  rtems_test_assert((uintptr_t) &content_ro_3 <= (uintptr_t) e_ro);
 }
 
 static void Init(rtems_task_argument arg)
-- 
1.8.4.5




More information about the devel mailing list