This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[RFC PATCH 4/6] powerpc/vxworks: [hack] add crti.o file
- From: Rasmus Villemoes <rasmus dot villemoes at prevas dot dk>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Olivier Hainque <hainque at adacore dot com>, Rasmus Villemoes <rasmus dot villemoes at prevas dot dk>
- Date: Mon, 4 Jun 2018 16:46:24 +0200
- Subject: [RFC PATCH 4/6] powerpc/vxworks: [hack] add crti.o file
- References: <20180604144626.5902-1-rasmus.villemoes@prevas.dk>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
The run-time linker on VxWorks almost supports the "modern"
.init_array/.fini_array way of dealing with static constructors and
destructors. On load of a module, it simply looks for a symbol _ctors
and expects that to be a NULL-terminated array of function pointers to
call (and similarly for _dtors on unload), and it does indeed call
_ctors in forward order and _dtors in reverse order. So all we need to
do is ensure the symbols _ctors and _dtors exist and arrange for a zero
terminator.
At first, I tried simply doing this in the linker script, i.e. something
like
PROVIDE(_ctors = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*)))
KEEP (*(.init_array))
LONG(0)
similar to the default linker scripts that just provide
__init_array_{start,end} symbols. Unfortunately, that is not quite
enough, since the _ctors symbol ends up with NOTYPE rather than OBJECT,
so it does not get recognized as a _ctors array by the VxWorks
runtime. I couldn't find a way to define the type of a linker-provided
symbol, so I'm resorting to this "hack".
I thought of also defining the symbol in the assembly file, but
then we'd have to put it in the .init_array.00000 section to also make
the _ctors array span static constructors with an init_priority. And
a corresponding crtn.o with a 0 entry would have to go in the
.init_array itself. I don't like that asymmetry between the crt{i,o}
files, and I think it's cleaner that the linker script defines both ends
of the array - this crti.o is merely a hack around my inability to
define the type of _ctors in the linker language.
2018-06-04 Rasmus Villemoes <rasmus.villemoes@prevas.dk>
libgcc/
* config.host: Add vxworks-crti.o to extra_parts for
powerpc-wrs-vxworks.
* config/rs6000/t-vxworks: New file.
* config/rs6000/vxworks-crti.S: New file.
---
libgcc/config.host | 4 ++--
libgcc/config/rs6000/t-vxworks | 5 +++++
libgcc/config/rs6000/vxworks-crti.S | 10 ++++++++++
3 files changed, 17 insertions(+), 2 deletions(-)
create mode 100644 libgcc/config/rs6000/t-vxworks
create mode 100644 libgcc/config/rs6000/vxworks-crti.S
diff --git a/libgcc/config.host b/libgcc/config.host
index b75c86bd4a6..a0da84647a6 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -1111,8 +1111,8 @@ powerpc*-*-linux*)
md_unwind_header=rs6000/linux-unwind.h
;;
powerpc-wrs-vxworks*)
- tmake_file="$tmake_file rs6000/t-ppccomm rs6000/t-savresfgpr t-fdpbit"
- extra_parts="$extra_parts crtbegin.o crtend.o"
+ tmake_file="$tmake_file rs6000/t-ppccomm rs6000/t-savresfgpr rs6000/t-vxworks t-fdpbit"
+ extra_parts="$extra_parts crtbegin.o crtend.o vxworks-crti.o"
;;
powerpc-*-lynxos*)
tmake_file="$tmake_file rs6000/t-lynx t-fdpbit"
diff --git a/libgcc/config/rs6000/t-vxworks b/libgcc/config/rs6000/t-vxworks
new file mode 100644
index 00000000000..ab9bee121c9
--- /dev/null
+++ b/libgcc/config/rs6000/t-vxworks
@@ -0,0 +1,5 @@
+# We build crti.o, which serves to set the type of _ctors and _dtors
+# symbols to "object".
+
+vxworks-crti$(objext): $(srcdir)/config/rs6000/vxworks-crti.S
+ $(crt_compile) -c $<
diff --git a/libgcc/config/rs6000/vxworks-crti.S b/libgcc/config/rs6000/vxworks-crti.S
new file mode 100644
index 00000000000..14d571f8fa2
--- /dev/null
+++ b/libgcc/config/rs6000/vxworks-crti.S
@@ -0,0 +1,10 @@
+/* This file just ensures the global (linker-supplied) symbols _ctors
+ and _dtors get the appropriate type. */
+
+ .ident "GNU C vxworks-crti.o"
+
+ .globl _ctors
+ .type _ctors, @object
+
+ .globl _dtors
+ .type _dtors, @object
--
2.15.1