1 /* crtbegin object for windows32 targets.
2 Copyright (C) 2007 Free Software Foundation, Inc.
4 Contributed by Danny Smith <dannysmith@users.sourceforge.net>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
13 In addition to the permissions in the GNU General Public License, the
14 Free Software Foundation gives you unlimited permission to link the
15 compiled version of this file into combinations with other programs,
16 and to distribute those combinations without any restriction coming
17 from the use of this file. (The General Public License restrictions
18 do apply in other respects; for example, they cover modification of
19 the file, and distribution when not linked into a combine
22 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
23 WARRANTY; without even the implied warranty of MERCHANTABILITY or
24 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27 You should have received a copy of the GNU General Public License
28 along with GCC; see the file COPYING. If not, write to the Free
29 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
32 /* Target machine header files require this define. */
35 #include "auto-host.h"
38 #include "coretypes.h"
40 #include "unwind-dw2-fde.h"
42 #define WIN32_LEAN_AND_MEAN
46 #define LIBGCC_SONAME "libgcc_s.dll"
50 #define LIBGCJ_SONAME "libgcj_s.dll"
54 /* Make the declarations weak. This is critical for
55 _Jv_RegisterClasses because it lives in libgcj.a */
56 extern void __register_frame_info (const void *, struct object
*)
57 TARGET_ATTRIBUTE_WEAK
;
58 extern void *__deregister_frame_info (const void *)
59 TARGET_ATTRIBUTE_WEAK
;
60 extern void _Jv_RegisterClasses (const void *) TARGET_ATTRIBUTE_WEAK
;
62 #if defined(HAVE_LD_RO_RW_SECTION_MIXING)
63 # define EH_FRAME_SECTION_CONST const
65 # define EH_FRAME_SECTION_CONST
68 /* Stick a label at the beginning of the frame unwind info so we can
69 register/deregister it with the exception handling library code. */
70 #if DWARF2_UNWIND_INFO
71 static EH_FRAME_SECTION_CONST
char __EH_FRAME_BEGIN__
[]
72 __attribute__((section(EH_FRAME_SECTION_NAME
), aligned(4)))
75 static struct object obj
;
78 #if TARGET_USE_JCR_SECTION
79 static void *__JCR_LIST__
[]
80 __attribute__ ((unused
, section(JCR_SECTION_NAME
), aligned(4)))
84 /* Pull in references from libgcc.a(unwind-dw2-fde.o) in the
85 startfile. These are referenced by a ctor and dtor in crtend.o. */
86 extern void __gcc_register_frame (void);
87 extern void __gcc_deregister_frame (void);
90 __gcc_register_frame (void)
92 #if DWARF2_UNWIND_INFO
93 /* Weak undefined symbols won't be pulled in from dlls; hence
94 we first test if the dll is already loaded and, if so,
95 get the symbol's address at run-time. If the dll is not loaded,
96 fallback to weak linkage to static archive. */
98 void (*register_frame_fn
) (const void *, struct object
*);
99 HANDLE h
= GetModuleHandle (LIBGCC_SONAME
);
101 register_frame_fn
= (void (*) (const void *, struct object
*))
102 GetProcAddress (h
, "__register_frame_info");
104 register_frame_fn
= __register_frame_info
;
105 if (register_frame_fn
)
106 register_frame_fn (__EH_FRAME_BEGIN__
, &obj
);
109 #if TARGET_USE_JCR_SECTION
112 void (*register_class_fn
) (const void *);
113 HANDLE h
= GetModuleHandle (LIBGCJ_SONAME
);
115 register_class_fn
= (void (*) (const void *))
116 GetProcAddress (h
, "_Jv_RegisterClasses");
118 register_class_fn
= _Jv_RegisterClasses
;
120 if (register_class_fn
)
121 register_class_fn (__JCR_LIST__
);
127 __gcc_deregister_frame (void)
129 #if DWARF2_UNWIND_INFO
130 void * (*deregister_frame_fn
) (const void *);
131 HANDLE h
= GetModuleHandle (LIBGCC_SONAME
);
133 deregister_frame_fn
= (void* (*) (const void *))
134 GetProcAddress (h
, "__deregister_frame_info");
136 deregister_frame_fn
= __deregister_frame_info
;
137 if (deregister_frame_fn
)
138 deregister_frame_fn (__EH_FRAME_BEGIN__
);