diff options
author | Frederic Konrad <konrad@adacore.com> | 2020-11-05 11:34:57 +0100 |
---|---|---|
committer | Olivier Hainque <hainque@adacore.com> | 2021-12-13 18:03:03 +0000 |
commit | 4099d6501e3526ca8d1d01e904f42b83c6824674 (patch) | |
tree | de1958f3de2156933e67882c59efcbc38d2ec928 /libgcc | |
parent | 0515c95d5fe0a865f688f3ab89572b917e8f0185 (diff) | |
download | gcc-4099d6501e3526ca8d1d01e904f42b83c6824674.zip gcc-4099d6501e3526ca8d1d01e904f42b83c6824674.tar.gz gcc-4099d6501e3526ca8d1d01e904f42b83c6824674.tar.bz2 |
Tigthen libc_internal and crtstuff for VxWorks shared objects
This change tightens and documents the use of libc_internal, then
strengthens the VxWorks crtstuff objects for the support of shared
libraries. In particular:
- Define __dso_handle, which libstdc++.so requires,
- Provide _init and _fini functions to run through the init/fini arrays
for shared libs in configurations which HAVE_INITFINI_ARRAY_SUPPORT.
The init/fini functions are provided by libc_internal.a for static links
but with slightly different names and we don't want to risk dragging other
libc_internal contents in the closure accidentally so make sure we don't
link with it.
As for the !vxworks crtstuff, the new shared libs specific bits are
conditioned by a CRTSTUFFS_O macro, for which we provide new Makefile
fragment.
The bits to actually use the fragment and the shared objects will
be added by a forthcoming change, as part of a more general configury
update for shared libs.
The change also adds guards the eh table registration code
in vxcrtstuff so the objects can be used for either init/fini
or eh tables independently.
2021-12-07 Fred Konrad <konrad@adacore.com>
Olivier Hainque <hainque@adacore.com>
gcc/
* config/vxworks.h (VXWORKS_BASE_LIBS_RTP): Guard -lc_internal
on !shared+!non-static and document.
(VXWORKS_LIB_SPEC): Remove the bits intended to drag the
init/fini functions from libc_internal in the shared lib case.
(VX_CRTBEGIN_SPEC/VX_CRTEND_SPEC): Use vxcrtstuff objects also in
configurations with shared lib and INITFINI_ARRAY support.
libgcc/
* config/t-vxcrtstuffS: New Makefile fragment.
* config/vxcrtstuff.c: Provide __dso_handle. Provide _init/_fini
functions for INITFINI_ARRAY support in shared libs and guard
the definition of eh table registration functions on conditions
indicating they are needed.
Diffstat (limited to 'libgcc')
-rw-r--r-- | libgcc/config/t-vxcrtstuffS | 9 | ||||
-rw-r--r-- | libgcc/config/vxcrtstuff.c | 77 |
2 files changed, 81 insertions, 5 deletions
diff --git a/libgcc/config/t-vxcrtstuffS b/libgcc/config/t-vxcrtstuffS new file mode 100644 index 0000000..6b65b00 --- /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 c15e15e..80f51f7 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 */ |