summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/config/vxworks.h42
-rw-r--r--libgcc/config/t-vxcrtstuffS9
-rw-r--r--libgcc/config/vxcrtstuff.c77
3 files changed, 109 insertions, 19 deletions
diff --git a/gcc/config/vxworks.h b/gcc/config/vxworks.h
index 96076e3c272..52d6aa1ae96 100644
--- a/gcc/config/vxworks.h
+++ b/gcc/config/vxworks.h
@@ -101,11 +101,23 @@ along with GCC; see the file COPYING3. If not see
the default CPP spec for C++ as well. */
#undef CPLUSPLUS_CPP_SPEC
-/* For VxWorks static rtps, the system provides libc_internal.a, a superset of
- libgcc.a that we need to use e.g. to satisfy references to __init and
- __fini. We still want our libgcc to prevail for symbols it would provide
- (e.g. register save entry points), so re-place it here between libraries
- that might reference it and libc_internal.
+/* For VxWorks static rtps, the system provides libc_internal.a for a variety
+ of purposes. Care is needed to include it appropriately.
+
+ - In some configurations, libc_internal fills in possible references from
+ the static libc that we don't wouldn't satisfy ourselves, say, with
+ libgcc. An example is the __aeabi_memcpy family of functions on arm,
+ which have very specific ABI allowances.
+
+ - OTOH, in some configurations the library provides typical libgcc
+ services, for example register save/restore entry points on powerpc. We
+ want our libgcc to prevail for symbols it would provide, so place
+ -lc_internal after -lc -lgcc.
+
+ - libc_internal also contains __init/__fini functions for
+ USE_INITFINI_ARRAY support. However, the system expects these in
+ every shared lib as well, with slightly different names, and it is
+ simpler for us to provide our own versions through vxcrtstuff.
In addition, some versions of VxWorks rely on explicit extra libraries for
system calls and the set of base network libraries of common use varies
@@ -120,7 +132,8 @@ along with GCC; see the file COPYING3. If not see
#define VXWORKS_NET_LIBS_RTP "-lnet -ldsi"
#endif
-#define VXWORKS_BASE_LIBS_RTP "-lc -lgcc -lc_internal"
+#define VXWORKS_BASE_LIBS_RTP \
+ "-lc -lgcc %{!shared:%{!non-static:-lc_internal}}"
#define VXWORKS_EXTRA_LIBS_RTP
@@ -161,10 +174,9 @@ along with GCC; see the file COPYING3. If not see
#endif
#undef VXWORKS_LIB_SPEC
-#define VXWORKS_LIB_SPEC \
-"%{mrtp:%{shared:-u " USER_LABEL_PREFIX "__init -u " USER_LABEL_PREFIX "__fini} \
- %{!shared:%{non-static:-u " USER_LABEL_PREFIX "_STI__6__rtld -ldl} \
- " TLS_SYM " \
+#define VXWORKS_LIB_SPEC \
+"%{mrtp:%{!shared:%{non-static:-u " USER_LABEL_PREFIX "_STI__6__rtld -ldl} \
+ " TLS_SYM " \
--start-group " VXWORKS_LIBS_RTP " --end-group}}"
/* The no-op spec for "-shared" below is present because otherwise GCC
@@ -196,11 +208,13 @@ along with GCC; see the file COPYING3. If not see
#define VXWORKS_LIBGCC_SPEC "-lgcc"
#endif
-/* Setup the crtstuff begin/end we might need for dwarf EH registration. */
+/* Setup the crtstuff begin/end we might need for dwarf EH registration
+ and/or INITFINI_ARRAY support for shared libs. */
-#if !defined(CONFIG_SJLJ_EXCEPTIONS) && DWARF2_UNWIND_INFO
-#define VX_CRTBEGIN_SPEC "vx_crtbegin.o%s"
-#define VX_CRTEND_SPEC "-l:vx_crtend.o"
+#if (HAVE_INITFINI_ARRAY_SUPPORT && defined(ENABLE_SHARED_LIBGCC)) \
+ || (DWARF2_UNWIND_INFO && !defined(CONFIG_SJLJ_EXCEPTIONS))
+#define VX_CRTBEGIN_SPEC "%{!shared:vx_crtbegin.o%s;:vx_crtbeginS.o%s}"
+#define VX_CRTEND_SPEC "%{!shared:vx_crtend.o%s;:vx_crtendS.o%s}"
#else
#define VX_CRTBEGIN_SPEC ""
#define VX_CRTEND_SPEC ""
diff --git a/libgcc/config/t-vxcrtstuffS b/libgcc/config/t-vxcrtstuffS
new file mode 100644
index 00000000000..6b65b0005be
--- /dev/null
+++ b/libgcc/config/t-vxcrtstuffS
@@ -0,0 +1,9 @@
+# Shared versions of vx_crt{begin,end}.o, those one must be compiled only
+# when the shared libraries are available
+
+vx_crtbeginS.o: $(srcdir)/config/vxcrtstuff.c
+ $(crt_compile) $(CRTSTUFF_T_CFLAGS_S) -DCRT_BEGIN -c $< -DCRTSTUFFS_O
+vx_crtendS.o: $(srcdir)/config/vxcrtstuff.c
+ $(crt_compile) $(CRTSTUFF_T_CFLAGS_S) -DCRT_END -c $< -DCRTSTUFFS_O
+
+EXTRA_PARTS += vx_crtbeginS.o vx_crtendS.o
diff --git a/libgcc/config/vxcrtstuff.c b/libgcc/config/vxcrtstuff.c
index c15e15e54e9..80f51f7399d 100644
--- a/libgcc/config/vxcrtstuff.c
+++ b/libgcc/config/vxcrtstuff.c
@@ -50,15 +50,25 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#define USE_CDTORS_SECTIONS
#endif
+#if DWARF2_UNWIND_INFO && !defined(__USING_SJLJ_EXCEPTIONS__)
+#define USE_EH_FRAME_REGISTRY
+#endif
+
/* ------------------------------ crtbegin ------------------------------- */
#ifdef CRT_BEGIN
-/* Stick a label at the beginning of the frame unwind info so we can register
- and deregister it with the exception handling library code. */
-static const char __EH_FRAME_BEGIN__[]
-__attribute__((section(__LIBGCC_EH_FRAME_SECTION_NAME__), aligned(4)))
- = { };
+#if DEFAULT_USE_CXA_ATEXIT && defined(__RTP__)
+/* This mimics the crtstuff.c behavior. dso_handle should be NULL for the
+ main program (in vx_crtbegin.o) and a unique value for the shared libraries
+ (in vx_crtbeginS.o). */
+extern void *__dso_handle __attribute__ ((__visibility__ ("hidden")));
+#ifdef CRTSTUFFS_O
+void *__dso_handle = &__dso_handle;
+#else
+void *__dso_handle = 0;
+#endif
+#endif /* DEFAULT_USE_CXA_ATEXIT */
/* Determine what names to use for the constructor/destructor functions. */
@@ -89,6 +99,53 @@ __attribute__((section(__LIBGCC_EH_FRAME_SECTION_NAME__), aligned(4)))
#define EH_CTOR_ATTRIBUTE __attribute__((constructor (101)))
#define EH_DTOR_ATTRIBUTE __attribute__((destructor (101)))
+/* Provide the init/fini array support functions for shared libraries,
+ where we don't want to drag libc_internal contents blindly and which
+ provides functions with a slightly different name anyway. */
+
+#if HAVE_INITFINI_ARRAY_SUPPORT && defined(CRTSTUFFS_O)
+
+/* Run through the .init_array, .fini_array sections. The linker script
+ *must* provide __init_array_start, __init_array_end, __fini_array_start,
+ __fini_array_end symbols. */
+
+typedef void (*initfini_ptr) (void);
+extern initfini_ptr __init_array_start[];
+extern initfini_ptr __init_array_end[];
+extern initfini_ptr __fini_array_start[];
+extern initfini_ptr __fini_array_end[];
+
+/* Provide the actual code through static functions, which don't need
+ to be exposed in the shared lib interface. */
+
+static void __exec_init_array(void)
+{
+ initfini_ptr *fn;
+ for (fn = __init_array_start; fn < __init_array_end; ++fn)
+ (*fn)();
+}
+
+static void __exec_fini_array(void)
+{
+ initfini_ptr *fn;
+ for (fn = __fini_array_end - 1; fn >= __fini_array_start; --fn)
+ (*fn)();
+}
+
+/* Reference the two above functions as the init / fini function. */
+
+void __attribute__ ((__section__ (".init"))) _init()
+{
+ __exec_init_array();
+}
+
+void __attribute__ ((__section__ (".fini"))) _fini()
+{
+ __exec_fini_array();
+}
+
+#endif /* __CRTSTUFFS_O__ */
+
#else /* !USE_INITFINI_ARRAY */
/* Note: Even in case of .ctors/.dtors sections, we can't use the attribute
@@ -100,6 +157,13 @@ __attribute__((section(__LIBGCC_EH_FRAME_SECTION_NAME__), aligned(4)))
#endif /* USE_INITFINI_ARRAY */
+#ifdef USE_EH_FRAME_REGISTRY
+/* Stick a label at the beginning of the frame unwind info so we can register
+ and deregister it with the exception handling library code. */
+static const char __EH_FRAME_BEGIN__[]
+__attribute__((section(__LIBGCC_EH_FRAME_SECTION_NAME__), aligned(4)))
+ = { };
+
EH_LINKAGE EH_CTOR_ATTRIBUTE void EH_CTOR_NAME (void)
{
static struct object object;
@@ -110,6 +174,7 @@ EH_LINKAGE EH_DTOR_ATTRIBUTE void EH_DTOR_NAME (void)
{
__deregister_frame_info (__EH_FRAME_BEGIN__);
}
+#endif /* USE_EH_FRAME_REGISTRY */
#ifdef USE_CDTORS_SECTIONS
/* As explained above, we need to manually build the sections here as the
@@ -126,6 +191,7 @@ static void (* volatile eh_registration_dtors[])()
#elif defined (CRT_END) /* ! CRT_BEGIN */
+#ifdef USE_EH_FRAME_REGISTRY
/* Terminate the frame unwind info section with a 4byte 0 as a sentinel;
this would be the 'length' field in a real FDE. */
@@ -133,6 +199,7 @@ static const char __FRAME_END__[]
__attribute__ ((used, section(__LIBGCC_EH_FRAME_SECTION_NAME__),
aligned(4)))
= { 0, 0, 0, 0 };
+#endif /* USE_EH_FRAME_REGISTRY */
#else /* ! CRT_BEGIN & ! CRT_END */