[PATCH v3] libcsupport: Address *tors FIXME

Kinsey Moore kinsey.moore at oarcorp.com
Mon Jun 29 19:35:08 UTC 2020


This introduces the CPU_USE_LIBC_INIT_FINI_ARRAY define for use by CPU
ports to determine which global constructor and destructor methods are
used instead of placing architecture defines where they shouldn't be.

Close #4018
---
 cpukit/libcsupport/src/newlibc_exit.c               | 5 +----
 cpukit/score/cpu/arm/include/rtems/score/cpu.h      | 2 ++
 cpukit/score/cpu/bfin/include/rtems/score/cpu.h     | 2 ++
 cpukit/score/cpu/epiphany/include/rtems/score/cpu.h | 2 ++
 cpukit/score/cpu/i386/include/rtems/score/cpu.h     | 2 ++
 cpukit/score/cpu/lm32/include/rtems/score/cpu.h     | 2 ++
 cpukit/score/cpu/m68k/include/rtems/score/cpu.h     | 2 ++
 cpukit/score/cpu/mips/include/rtems/score/cpu.h     | 2 ++
 cpukit/score/cpu/moxie/include/rtems/score/cpu.h    | 2 ++
 cpukit/score/cpu/nios2/include/rtems/score/cpu.h    | 2 ++
 cpukit/score/cpu/no_cpu/include/rtems/score/cpu.h   | 7 +++++++
 cpukit/score/cpu/or1k/include/rtems/score/cpu.h     | 2 ++
 cpukit/score/cpu/powerpc/include/rtems/score/cpu.h  | 3 +++
 cpukit/score/cpu/riscv/include/rtems/score/cpu.h    | 2 ++
 cpukit/score/cpu/sh/include/rtems/score/cpu.h       | 2 ++
 cpukit/score/cpu/sparc/include/rtems/score/cpu.h    | 2 ++
 cpukit/score/cpu/sparc64/include/rtems/score/cpu.h  | 2 ++
 cpukit/score/cpu/v850/include/rtems/score/cpu.h     | 2 ++
 cpukit/score/cpu/x86_64/include/rtems/score/cpu.h   | 2 ++
 cpukit/score/src/threadhandler.c                    | 8 ++++++--
 20 files changed, 49 insertions(+), 6 deletions(-)

diff --git a/cpukit/libcsupport/src/newlibc_exit.c b/cpukit/libcsupport/src/newlibc_exit.c
index 650b692c74..d29214af3f 100644
--- a/cpukit/libcsupport/src/newlibc_exit.c
+++ b/cpukit/libcsupport/src/newlibc_exit.c
@@ -17,11 +17,8 @@
 #include <stdio.h>
 #include <unistd.h>
 
-/* FIXME: These defines are a blatant hack */
-
   #if defined(__USE_INIT_FINI__)
-    #if defined(__ARM_EABI__) || defined(__riscv) \
-      || defined(__or1k__) || defined(__or1knd__)
+    #if CPU_USE_LIBC_INIT_FINI_ARRAY == TRUE
       #define FINI_SYMBOL __libc_fini_array
     #else
       #define FINI_SYMBOL _fini
diff --git a/cpukit/score/cpu/arm/include/rtems/score/cpu.h b/cpukit/score/cpu/arm/include/rtems/score/cpu.h
index b7b48a3ac3..b90fb1f394 100644
--- a/cpukit/score/cpu/arm/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/arm/include/rtems/score/cpu.h
@@ -153,6 +153,8 @@
 
 #define CPU_USE_GENERIC_BITFIELD_CODE TRUE
 
+#define CPU_USE_LIBC_INIT_FINI_ARRAY TRUE
+
 #define CPU_MAXIMUM_PROCESSORS 32
 
 #ifdef ARM_MULTILIB_HAS_THREAD_ID_REGISTER
diff --git a/cpukit/score/cpu/bfin/include/rtems/score/cpu.h b/cpukit/score/cpu/bfin/include/rtems/score/cpu.h
index 893a3ae359..3b0f0bece3 100644
--- a/cpukit/score/cpu/bfin/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/bfin/include/rtems/score/cpu.h
@@ -507,6 +507,8 @@ void _CPU_Context_Initialize(
 
 #define CPU_USE_GENERIC_BITFIELD_CODE TRUE
 
+#define CPU_USE_LIBC_INIT_FINI_ARRAY FALSE
+
 /* functions */
 
 /**
diff --git a/cpukit/score/cpu/epiphany/include/rtems/score/cpu.h b/cpukit/score/cpu/epiphany/include/rtems/score/cpu.h
index 462ffab040..70a9790606 100644
--- a/cpukit/score/cpu/epiphany/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/epiphany/include/rtems/score/cpu.h
@@ -445,6 +445,8 @@ void _CPU_Context_Initialize(
 
 #define CPU_USE_GENERIC_BITFIELD_CODE TRUE
 
+#define CPU_USE_LIBC_INIT_FINI_ARRAY FALSE
+
 #endif /* ASM */
 
 /**
diff --git a/cpukit/score/cpu/i386/include/rtems/score/cpu.h b/cpukit/score/cpu/i386/include/rtems/score/cpu.h
index 0145ff8db3..225b72802d 100644
--- a/cpukit/score/cpu/i386/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/i386/include/rtems/score/cpu.h
@@ -503,6 +503,8 @@ extern void _CPU_Fatal_halt(uint32_t source, uint32_t error)
 
 /* end of Fatal Error manager macros */
 
+#define CPU_USE_LIBC_INIT_FINI_ARRAY FALSE
+
 /*
  *  Bitfield handler macros
  *
diff --git a/cpukit/score/cpu/lm32/include/rtems/score/cpu.h b/cpukit/score/cpu/lm32/include/rtems/score/cpu.h
index 13f8f36194..8e702992c1 100644
--- a/cpukit/score/cpu/lm32/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/lm32/include/rtems/score/cpu.h
@@ -628,6 +628,8 @@ extern char _gp[];
 
 #define CPU_USE_GENERIC_BITFIELD_CODE TRUE
 
+#define CPU_USE_LIBC_INIT_FINI_ARRAY FALSE
+
 /* functions */
 
 /**
diff --git a/cpukit/score/cpu/m68k/include/rtems/score/cpu.h b/cpukit/score/cpu/m68k/include/rtems/score/cpu.h
index de085c9f7d..777fbfeb30 100644
--- a/cpukit/score/cpu/m68k/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/m68k/include/rtems/score/cpu.h
@@ -433,6 +433,8 @@ void *_CPU_Thread_Idle_body( uintptr_t ignored );
 
 /* end of Fatal Error manager macros */
 
+#define CPU_USE_LIBC_INIT_FINI_ARRAY FALSE
+
 /*
  *  Bitfield handler macros
  *
diff --git a/cpukit/score/cpu/mips/include/rtems/score/cpu.h b/cpukit/score/cpu/mips/include/rtems/score/cpu.h
index c9c212eab5..2b662cd549 100644
--- a/cpukit/score/cpu/mips/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/mips/include/rtems/score/cpu.h
@@ -740,6 +740,8 @@ extern void mips_break( int error );
 
 #define CPU_USE_GENERIC_BITFIELD_CODE TRUE
 
+#define CPU_USE_LIBC_INIT_FINI_ARRAY FALSE
+
 /* functions */
 
 /*
diff --git a/cpukit/score/cpu/moxie/include/rtems/score/cpu.h b/cpukit/score/cpu/moxie/include/rtems/score/cpu.h
index 318650ea3f..c47e414f92 100644
--- a/cpukit/score/cpu/moxie/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/moxie/include/rtems/score/cpu.h
@@ -427,6 +427,8 @@ uint32_t   _CPU_ISR_Get_level( void );
 
 #define CPU_USE_GENERIC_BITFIELD_CODE TRUE
 
+#define CPU_USE_LIBC_INIT_FINI_ARRAY FALSE
+
 /* functions */
 
 /*
diff --git a/cpukit/score/cpu/nios2/include/rtems/score/cpu.h b/cpukit/score/cpu/nios2/include/rtems/score/cpu.h
index d98b0c5c35..5528561d1c 100644
--- a/cpukit/score/cpu/nios2/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/nios2/include/rtems/score/cpu.h
@@ -90,6 +90,8 @@ extern "C" {
 
 #define CPU_USE_GENERIC_BITFIELD_CODE TRUE
 
+#define CPU_USE_LIBC_INIT_FINI_ARRAY FALSE
+
 #define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
 
 #define CPU_MAXIMUM_PROCESSORS 32
diff --git a/cpukit/score/cpu/no_cpu/include/rtems/score/cpu.h b/cpukit/score/cpu/no_cpu/include/rtems/score/cpu.h
index 7f6e1f539d..84125aa16b 100644
--- a/cpukit/score/cpu/no_cpu/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/no_cpu/include/rtems/score/cpu.h
@@ -249,6 +249,13 @@ extern "C" {
  */
 #define CPU_MAXIMUM_PROCESSORS 32
 
+/**
+ * The following define determines whether or not this CPU port will use
+ * libc global constructors and destructors instead of _init/_fini functions
+ * depending on .ctors and .dtors linker sections.
+ */
+#define CPU_USE_LIBC_INIT_FINI_ARRAY TRUE
+
 /*
  *  Processor defined structures required for cpukit/score.
  *
diff --git a/cpukit/score/cpu/or1k/include/rtems/score/cpu.h b/cpukit/score/cpu/or1k/include/rtems/score/cpu.h
index 39920bebc3..6790694b05 100644
--- a/cpukit/score/cpu/or1k/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/or1k/include/rtems/score/cpu.h
@@ -435,6 +435,8 @@ void _CPU_Context_Initialize(
 
 #define CPU_USE_GENERIC_BITFIELD_CODE TRUE
 
+#define CPU_USE_LIBC_INIT_FINI_ARRAY TRUE
+
 #endif /* ASM */
 
 #define CPU_SIZEOF_POINTER 4
diff --git a/cpukit/score/cpu/powerpc/include/rtems/score/cpu.h b/cpukit/score/cpu/powerpc/include/rtems/score/cpu.h
index 8e4b10156f..33d8755ba4 100644
--- a/cpukit/score/cpu/powerpc/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/powerpc/include/rtems/score/cpu.h
@@ -805,6 +805,9 @@ void _CPU_Context_Initialize(
 #endif /* ASM */
 
 #ifndef ASM
+
+#define CPU_USE_LIBC_INIT_FINI_ARRAY FALSE
+
 /* Bitfield handler macros */
 
 #define CPU_USE_GENERIC_BITFIELD_CODE FALSE
diff --git a/cpukit/score/cpu/riscv/include/rtems/score/cpu.h b/cpukit/score/cpu/riscv/include/rtems/score/cpu.h
index e08307d372..501973a6dc 100644
--- a/cpukit/score/cpu/riscv/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/riscv/include/rtems/score/cpu.h
@@ -219,6 +219,8 @@ extern void _CPU_Fatal_halt(uint32_t source, uint32_t error) RTEMS_NO_RETURN;
 
 #define CPU_USE_GENERIC_BITFIELD_DATA TRUE
 
+#define CPU_USE_LIBC_INIT_FINI_ARRAY TRUE
+
 #define CPU_MAXIMUM_PROCESSORS 32
 
 typedef uint16_t Priority_bit_map_Word;
diff --git a/cpukit/score/cpu/sh/include/rtems/score/cpu.h b/cpukit/score/cpu/sh/include/rtems/score/cpu.h
index a7cd5f89fd..9264479153 100644
--- a/cpukit/score/cpu/sh/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/sh/include/rtems/score/cpu.h
@@ -535,6 +535,8 @@ void _CPU_Context_Initialize(
 
 #define CPU_USE_GENERIC_BITFIELD_CODE TRUE
 
+#define CPU_USE_LIBC_INIT_FINI_ARRAY FALSE
+
 /* functions */
 
 /*
diff --git a/cpukit/score/cpu/sparc/include/rtems/score/cpu.h b/cpukit/score/cpu/sparc/include/rtems/score/cpu.h
index d4b24f3f56..13782f2f12 100644
--- a/cpukit/score/cpu/sparc/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/sparc/include/rtems/score/cpu.h
@@ -917,6 +917,8 @@ extern void _CPU_Fatal_halt(uint32_t source, uint32_t error)
 
 /* end of Fatal Error manager macros */
 
+#define CPU_USE_LIBC_INIT_FINI_ARRAY FALSE
+
 /* Bitfield handler macros */
 
 #if ( SPARC_HAS_BITSCAN == 0 )
diff --git a/cpukit/score/cpu/sparc64/include/rtems/score/cpu.h b/cpukit/score/cpu/sparc64/include/rtems/score/cpu.h
index 84cb5865bd..2dd5cb194f 100644
--- a/cpukit/score/cpu/sparc64/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/sparc64/include/rtems/score/cpu.h
@@ -801,6 +801,8 @@ void _CPU_Context_Initialize(
 
 /* end of Fatal Error manager macros */
 
+#define CPU_USE_LIBC_INIT_FINI_ARRAY FALSE
+
 /* Bitfield handler macros */
 
 /*
diff --git a/cpukit/score/cpu/v850/include/rtems/score/cpu.h b/cpukit/score/cpu/v850/include/rtems/score/cpu.h
index 0ab1d68ba7..a538789a58 100644
--- a/cpukit/score/cpu/v850/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/v850/include/rtems/score/cpu.h
@@ -493,6 +493,8 @@ void _CPU_Context_Initialize(
 
 #define CPU_USE_GENERIC_BITFIELD_CODE TRUE
 
+#define CPU_USE_LIBC_INIT_FINI_ARRAY FALSE
+
 /* functions */
 
 /**
diff --git a/cpukit/score/cpu/x86_64/include/rtems/score/cpu.h b/cpukit/score/cpu/x86_64/include/rtems/score/cpu.h
index e3da0aa524..12ae14e229 100644
--- a/cpukit/score/cpu/x86_64/include/rtems/score/cpu.h
+++ b/cpukit/score/cpu/x86_64/include/rtems/score/cpu.h
@@ -242,6 +242,8 @@ void _CPU_Context_Initialize(
 
 /* end of Fatal Error manager macros */
 
+#define CPU_USE_LIBC_INIT_FINI_ARRAY FALSE
+
 /* Bitfield handler macros */
 
 #define CPU_USE_GENERIC_BITFIELD_CODE TRUE
diff --git a/cpukit/score/src/threadhandler.c b/cpukit/score/src/threadhandler.c
index acbe186a53..6742b0b391 100644
--- a/cpukit/score/src/threadhandler.c
+++ b/cpukit/score/src/threadhandler.c
@@ -28,9 +28,13 @@
  *  Conditional magic to determine what style of C++ constructor
  *  initialization this target and compiler version uses.
  */
+RTEMS_STATIC_ASSERT(
+  CPU_USE_LIBC_INIT_FINI_ARRAY == TRUE
+    || CPU_USE_LIBC_INIT_FINI_ARRAY == FALSE,
+  CPU_USE_LIBC_INIT_FINI_ARRAY
+);
 #if defined(__USE_INIT_FINI__)
-  #if defined(__ARM_EABI__) || defined(__riscv) \
-    || defined(__or1k__) || defined(__or1knd__)
+  #if CPU_USE_LIBC_INIT_FINI_ARRAY == TRUE
     #define INIT_NAME __libc_init_array
   #else
     #define INIT_NAME _init
-- 
2.20.1



More information about the devel mailing list