[v2,3/4] vxworks: enable use of .init_array/.fini_array for cdtors

Message ID 20180628084329.22754-4-rv@rasmusvillemoes.dk
State New
Headers show
Series
  • some vxworks/powerpc patches
Related show

Commit Message

Rasmus Villemoes June 28, 2018, 8:43 a.m.
The target OS actually runs all function pointers found in the _ctors
array when the module is loaded. So it is not that hard to make use of
the "modern" .init_array/.fini_array mechanism - it mostly just requires
a linker script adding the _ctors and _dtors symbols and terminating
LONG(0) entries.

Assume that if the user passed --enable-initfini-array when building
gcc, the rest of the toolchain (including the link spec and linker
script) is set up appropriately.

Note that configuring with --enable-initfini-array may prevent the -mrtp
mode from working, due to the (unconditional) use of .init_array.*
sections instead of .ctors.* - however, that is the case regardless of this
patch.

2018-06-04  Rasmus Villemoes  <rv@rasmusvillemoes.dk>

gcc/
	config/vxworks.c: Set targetm.have_ctors_dtors if HAVE_INITFINI_ARRAY_SUPPORT.
	config/vxworks.h: Set SUPPORTS_INIT_PRIORITY if HAVE_INITFINI_ARRAY_SUPPORT.
---
 gcc/config/vxworks.c |  7 +++++--
 gcc/config/vxworks.h | 10 +++++++---
 2 files changed, 12 insertions(+), 5 deletions(-)

-- 
2.16.4

Comments

Olivier Hainque Aug. 10, 2018, 3:59 p.m. | #1
Hello Rasmus,

> On 28 Jun 2018, at 10:43, Rasmus Villemoes <rv@rasmusvillemoes.dk> wrote:

> 

> Assume that if the user passed --enable-initfini-array when building

> gcc, the rest of the toolchain (including the link spec and linker

> script) is set up appropriately.

> 

> Note that configuring with --enable-initfini-array may prevent the -mrtp

> mode from working,


> due to the (unconditional) use of .init_array.*

> sections instead of .ctors.* -


Just spent some time verifying this, and, indeed getting
a RTP to work with this setup is going to be tough, if at
all possible.

> however, that is the case regardless of this patch.


Right, though the situation becomes a bit different
with the patch as we now have references to the macro,
sort of implying it should work.

I still think it's fine, as what we do is simply honor
what the doc of --enable-initfini-array states: generate
constructor/desctructors in init/fini_array sections,
nothing more, and the comments pretty clearly state that
it's the responsibility of the one who configured this
way to manage the constructors and fit them into the OS
runtime.

And we can revisit if we find a better way out.

So, as it allows at least a use case to operate smoothly
...

> 2018-06-04  Rasmus Villemoes  <rv@rasmusvillemoes.dk>

> 

> gcc/

> 	config/vxworks.c: Set targetm.have_ctors_dtors if HAVE_INITFINI_ARRAY_SUPPORT.

>  config/vxworks.h: Set SUPPORTS_INIT_PRIORITY if HAVE_INITFINI_ARRAY_SUPPORT.


Ok, modulo ChangeLog reformatting:

	* config/vxworks.c: Set targetm.have_ctors_dtors if
	HAVE_INITFINI_ARRAY_SUPPORT.
	* config/vxworks.h: Set SUPPORTS_INIT_PRIORITY if
	HAVE_INITFINI_ARRAY_SUPPORT.

Thanks,

Olivier
Rasmus Villemoes Aug. 13, 2018, 8:24 a.m. | #2
On 2018-08-10 17:59, Olivier Hainque wrote:
> Hello Rasmus,

> 

>> On 28 Jun 2018, at 10:43, Rasmus Villemoes <rv@rasmusvillemoes.dk> wrote:

>>

>> Assume that if the user passed --enable-initfini-array when building

>> gcc, the rest of the toolchain (including the link spec and linker

>> script) is set up appropriately.

>> 2018-06-04  Rasmus Villemoes  <rv@rasmusvillemoes.dk>

>>

>> gcc/

>> 	config/vxworks.c: Set targetm.have_ctors_dtors if HAVE_INITFINI_ARRAY_SUPPORT.

>>  config/vxworks.h: Set SUPPORTS_INIT_PRIORITY if HAVE_INITFINI_ARRAY_SUPPORT.

> 

> Ok, modulo ChangeLog reformatting:

> 

> 	* config/vxworks.c: Set targetm.have_ctors_dtors if

> 	HAVE_INITFINI_ARRAY_SUPPORT.

> 	* config/vxworks.h: Set SUPPORTS_INIT_PRIORITY if

> 	HAVE_INITFINI_ARRAY_SUPPORT.


Thanks for spotting that. I have a script that fixes the whitespace
issue automatically, but it doesn't catch missing leading * in entries.

Do you want me to send an updated and rebased version of these patches
(including changelog fixups)?

Thanks,
Rasmus
Olivier Hainque Aug. 13, 2018, 11:54 a.m. | #3
Hi Rasmus,

> On 13 Aug 2018, at 10:24, Rasmus Villemoes <rv@rasmusvillemoes.dk> wrote:

> 

>> Ok, modulo ChangeLog reformatting:

> 

> Thanks for spotting that. I have a script that fixes the whitespace

> issue automatically, but it doesn't catch missing leading * in entries.

> 

> Do you want me to send an updated and rebased version of these patches

> (including changelog fixups)?


No, no need to repost just for the ChangeLog
format update.

Thanks,

Olivier

Patch

diff --git a/gcc/config/vxworks.c b/gcc/config/vxworks.c
index 061f02057c2..953f74f71af 100644
--- a/gcc/config/vxworks.c
+++ b/gcc/config/vxworks.c
@@ -143,8 +143,11 @@  vxworks_override_options (void)
       targetm.emutls.debug_form_tls_address = true;
     }
 
-  /* We can use .ctors/.dtors sections only in RTP mode.  */
-  targetm.have_ctors_dtors = TARGET_VXWORKS_RTP;
+  /* We can use .ctors/.dtors sections only in RTP mode.  But, if the
+     compiler was built with --enable-initfini-array, assume the
+     toolchain implements the proper glue to make .init_array and
+     .fini_array work.  */
+  targetm.have_ctors_dtors = TARGET_VXWORKS_RTP || HAVE_INITFINI_ARRAY_SUPPORT;
 
   /* PIC is only supported for RTPs.  */
   if (flag_pic && !TARGET_VXWORKS_RTP)
diff --git a/gcc/config/vxworks.h b/gcc/config/vxworks.h
index 08d2c9d76d6..4c2d98381f6 100644
--- a/gcc/config/vxworks.h
+++ b/gcc/config/vxworks.h
@@ -142,9 +142,13 @@  along with GCC; see the file COPYING3.  If not see
 #define VXWORKS_OVERRIDE_OPTIONS vxworks_override_options ()
 extern void vxworks_override_options (void);
 
-/* Only RTPs support prioritized constructors and destructors:
-   the implementation relies on numbered .ctors* sections.  */
-#define SUPPORTS_INIT_PRIORITY TARGET_VXWORKS_RTP
+/* RTPs support prioritized constructors and destructors: the
+   implementation relies on numbered .ctors* sections. If the compiler
+   was built with --enable-initfini-array, we assume the user uses a
+   linker script that sorts and merges the .init_array.* sections
+   appropriately.  */
+#define SUPPORTS_INIT_PRIORITY \
+  (TARGET_VXWORKS_RTP || HAVE_INITFINI_ARRAY_SUPPORT)
 
 /* VxWorks requires special handling of constructors and destructors.
    All VxWorks configurations must use these functions.  */