vxcrtstuff.c revision 1.1.1.1
1/* This file is part of GCC. 2 3GCC is free software; you can redistribute it and/or modify it under 4the terms of the GNU General Public License as published by the Free 5Software Foundation; either version 3, or (at your option) any later 6version. 7 8GCC is distributed in the hope that it will be useful, but WITHOUT ANY 9WARRANTY; without even the implied warranty of MERCHANTABILITY or 10FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11for more details. 12 13Under Section 7 of GPL version 3, you are granted additional 14permissions described in the GCC Runtime Library Exception, version 153.1, as published by the Free Software Foundation. 16 17You should have received a copy of the GNU General Public License and 18a copy of the GCC Runtime Library Exception along with this program; 19see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 20<http://www.gnu.org/licenses/>. */ 21 22/* The essential point of the crtbegin/crtend files on VxWorks is to handle 23 the eh frames registration thanks to dedicated constructors and 24 destructors. What needs to be done depends on the VxWorks version and the 25 kind of module (rtp, dkm, ...) one is building. */ 26 27#define IN_LIBGCC2 28 29#include "auto-host.h" 30#include "tconfig.h" 31#include "tsystem.h" 32#include "coretypes.h" 33#include "tm.h" 34#include "libgcc_tm.h" 35#include "unwind-dw2-fde.h" 36 37/* If we are entitled/requested to use init/fini arrays, we'll rely on that. 38 Otherwise, we may rely on ctors/dtors sections for RTPs or expect munch to 39 be involved for kernel modules. */ 40 41#if !defined(USE_INITFINI_ARRAY) && defined(__RTP__) 42#define USE_CDTORS_SECTIONS 43#endif 44 45/* ------------------------------ crtbegin ------------------------------- */ 46 47#ifdef CRT_BEGIN 48 49/* Stick a label at the beginning of the frame unwind info so we can register 50 and deregister it with the exception handling library code. */ 51static const char __EH_FRAME_BEGIN__[] 52__attribute__((section(__LIBGCC_EH_FRAME_SECTION_NAME__), aligned(4))) 53 = { }; 54 55/* Determine what names to use for the constructor/destructor functions. */ 56 57#if defined(USE_CDTORS_SECTIONS) || defined(USE_INITFINI_ARRAY) 58 59#define EH_CTOR_NAME _crtbe_register_frame 60#define EH_DTOR_NAME _ctrbe_deregister_frame 61 62#else 63 64/* No specific sections for constructors or destructors: we thus use a 65 symbol naming convention so that the constructors are then recognized 66 by munch or whatever tool is used for the final link phase. */ 67#define EH_CTOR_NAME _GLOBAL__I_00101_0__crtbe_register_frame 68#define EH_DTOR_NAME _GLOBAL__D_00101_1__crtbe_deregister_frame 69 70#endif 71 72#ifdef USE_INITFINI_ARRAY 73/* .init_array and .fini_array is supported starting VxWorks 7.2 in all 74 cases. The compiler is then configured to always support priorities in 75 constructors, so we can rely on the constructor and destructor attributes 76 to generate the proper sections. */ 77#define EH_CTOR_ATTRIBUTE __attribute__((constructor (101))) 78#define EH_DTOR_ATTRIBUTE __attribute__((destructor (101))) 79 80#else /* !USE_INITFINI_ARRAY */ 81 82/* Note: Even in case of .ctors/.dtors sections, we can't use the attribute 83 (constructor (15)) here as gcc may have been configured with constructors 84 priority disabled. We will instead craft an explicit section name for this 85 purpose. */ 86#define EH_CTOR_ATTRIBUTE 87#define EH_DTOR_ATTRIBUTE 88 89#endif /* USE_INITFINI_ARRAY */ 90 91void EH_CTOR_NAME (void); 92void EH_DTOR_NAME (void); 93 94EH_CTOR_ATTRIBUTE void EH_CTOR_NAME (void) 95{ 96 static struct object object; 97 __register_frame_info (__EH_FRAME_BEGIN__, &object); 98} 99 100EH_DTOR_ATTRIBUTE void EH_DTOR_NAME (void) 101{ 102 __deregister_frame_info (__EH_FRAME_BEGIN__); 103} 104 105#ifdef USE_CDTORS_SECTIONS 106/* As explained above, we need to manually build the sections here as the 107 compiler may not have support for constructors priority enabled. */ 108static void (* volatile eh_registration_ctors[])() 109 __attribute__((section (".ctors.101"))) 110= { &EH_CTOR_NAME }; 111static void (* volatile eh_registration_dtors[])() 112 __attribute__((section (".dtors.65434"))) 113= { &EH_DTOR_NAME }; 114#endif 115 116/* ------------------------------ crtend --------------------------------- */ 117 118#elif defined (CRT_END) /* ! CRT_BEGIN */ 119 120/* Terminate the frame unwind info section with a 4byte 0 as a sentinel; 121 this would be the 'length' field in a real FDE. */ 122 123static const char __FRAME_END__[] 124 __attribute__ ((used, section(__LIBGCC_EH_FRAME_SECTION_NAME__), 125 aligned(4))) 126 = { 0, 0, 0, 0 }; 127 128#else /* ! CRT_BEGIN & ! CRT_END */ 129 130#error "One of CRT_BEGIN or CRT_END must be defined." 131 132#endif 133