00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 #define IN_LIBGCC2
00056
00057
00058
00059
00060 #include "auto-host.h"
00061 #undef gid_t
00062 #undef pid_t
00063 #undef rlim_t
00064 #undef ssize_t
00065 #undef uid_t
00066 #undef vfork
00067 #include "tconfig.h"
00068 #include "tsystem.h"
00069 #include "coretypes.h"
00070 #include "tm.h"
00071 #include "unwind-dw2-fde.h"
00072
00073 #ifndef FORCE_CODE_SECTION_ALIGN
00074 # define FORCE_CODE_SECTION_ALIGN
00075 #endif
00076
00077 #ifndef CRT_CALL_STATIC_FUNCTION
00078 # define CRT_CALL_STATIC_FUNCTION(SECTION_OP, FUNC) \
00079 static void __attribute__((__used__)) \
00080 call_ ## FUNC (void) \
00081 { \
00082 asm (SECTION_OP); \
00083 FUNC (); \
00084 FORCE_CODE_SECTION_ALIGN \
00085 asm (TEXT_SECTION_ASM_OP); \
00086 }
00087 #endif
00088
00089 #if defined(OBJECT_FORMAT_ELF) && defined(HAVE_LD_EH_FRAME_HDR) \
00090 && !defined(inhibit_libc) && !defined(CRTSTUFFT_O) \
00091 && defined(__GLIBC__) && __GLIBC__ >= 2
00092 #include <link.h>
00093 # if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) \
00094 || (__GLIBC__ == 2 && __GLIBC_MINOR__ == 2 && defined(DT_CONFIG)))
00095 # define USE_PT_GNU_EH_FRAME
00096 # endif
00097 #endif
00098 #if defined(EH_FRAME_SECTION_NAME) && !defined(USE_PT_GNU_EH_FRAME)
00099 # define USE_EH_FRAME_REGISTRY
00100 #endif
00101 #if defined(EH_FRAME_SECTION_NAME) && EH_TABLES_CAN_BE_READ_ONLY
00102 # define EH_FRAME_SECTION_CONST const
00103 #else
00104 # define EH_FRAME_SECTION_CONST
00105 #endif
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 extern void __register_frame_info (const void *, struct object *)
00130 TARGET_ATTRIBUTE_WEAK;
00131 extern void __register_frame_info_bases (const void *, struct object *,
00132 void *, void *)
00133 TARGET_ATTRIBUTE_WEAK;
00134 extern void *__deregister_frame_info (const void *)
00135 TARGET_ATTRIBUTE_WEAK;
00136 extern void *__deregister_frame_info_bases (const void *)
00137 TARGET_ATTRIBUTE_WEAK;
00138 extern void __do_global_ctors_1 (void);
00139
00140
00141 extern void _Jv_RegisterClasses (void *) TARGET_ATTRIBUTE_WEAK;
00142
00143 #ifdef OBJECT_FORMAT_ELF
00144
00145
00146 typedef void (*func_ptr) (void);
00147 #define STATIC static
00148
00149 #else
00150
00151 #include "gbl-ctors.h"
00152
00153 #define STATIC
00154
00155 #endif
00156
00157 #ifdef CRT_BEGIN
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173 #ifdef CTOR_LIST_BEGIN
00174 CTOR_LIST_BEGIN;
00175 #elif defined(CTORS_SECTION_ASM_OP)
00176
00177
00178 static func_ptr force_to_data[1] __attribute__ ((__unused__)) = { };
00179 asm (CTORS_SECTION_ASM_OP);
00180 STATIC func_ptr __CTOR_LIST__[1]
00181 __attribute__ ((__unused__, aligned(sizeof(func_ptr))))
00182 = { (func_ptr) (-1) };
00183 #else
00184 STATIC func_ptr __CTOR_LIST__[1]
00185 __attribute__ ((__unused__, section(".ctors"), aligned(sizeof(func_ptr))))
00186 = { (func_ptr) (-1) };
00187 #endif
00188
00189 #ifdef DTOR_LIST_BEGIN
00190 DTOR_LIST_BEGIN;
00191 #elif defined(DTORS_SECTION_ASM_OP)
00192 asm (DTORS_SECTION_ASM_OP);
00193 STATIC func_ptr __DTOR_LIST__[1]
00194 __attribute__ ((aligned(sizeof(func_ptr))))
00195 = { (func_ptr) (-1) };
00196 #else
00197 STATIC func_ptr __DTOR_LIST__[1]
00198 __attribute__((section(".dtors"), aligned(sizeof(func_ptr))))
00199 = { (func_ptr) (-1) };
00200 #endif
00201
00202 #ifdef USE_EH_FRAME_REGISTRY
00203
00204
00205 STATIC EH_FRAME_SECTION_CONST char __EH_FRAME_BEGIN__[]
00206 __attribute__((section(EH_FRAME_SECTION_NAME), aligned(4)))
00207 = { };
00208 #endif
00209
00210 #ifdef JCR_SECTION_NAME
00211
00212
00213 STATIC void *__JCR_LIST__[]
00214 __attribute__ ((unused, section(JCR_SECTION_NAME), aligned(sizeof(void*))))
00215 = { };
00216 #endif
00217
00218 #if defined(INIT_SECTION_ASM_OP) || defined(INIT_ARRAY_SECTION_ASM_OP)
00219
00220 #ifdef OBJECT_FORMAT_ELF
00221
00222
00223
00224
00225
00226
00227
00228 #ifdef TARGET_LIBGCC_SDATA_SECTION
00229 extern void *__dso_handle __attribute__ ((__section__ (TARGET_LIBGCC_SDATA_SECTION)));
00230 #endif
00231 #ifdef HAVE_GAS_HIDDEN
00232 extern void *__dso_handle __attribute__ ((__visibility__ ("hidden")));
00233 #endif
00234 #ifdef CRTSTUFFS_O
00235 void *__dso_handle = &__dso_handle;
00236 #else
00237 void *__dso_handle = 0;
00238 #endif
00239
00240
00241
00242 extern void __cxa_finalize (void *) TARGET_ATTRIBUTE_WEAK;
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263 static void __attribute__((used))
00264 __do_global_dtors_aux (void)
00265 {
00266 #ifndef FINI_ARRAY_SECTION_ASM_OP
00267 static func_ptr *p = __DTOR_LIST__ + 1;
00268 func_ptr f;
00269 #endif
00270 static _Bool completed;
00271
00272 if (__builtin_expect (completed, 0))
00273 return;
00274
00275 #ifdef CRTSTUFFS_O
00276 if (__cxa_finalize)
00277 __cxa_finalize (__dso_handle);
00278 #endif
00279
00280 #ifdef FINI_ARRAY_SECTION_ASM_OP
00281
00282
00283 #else
00284 while ((f = *p))
00285 {
00286 p++;
00287 f ();
00288 }
00289 #endif
00290
00291 #ifdef USE_EH_FRAME_REGISTRY
00292 #ifdef CRT_GET_RFIB_DATA
00293
00294
00295 if (__deregister_frame_info_bases)
00296 __deregister_frame_info_bases (__EH_FRAME_BEGIN__);
00297 #else
00298 if (__deregister_frame_info)
00299 __deregister_frame_info (__EH_FRAME_BEGIN__);
00300 #endif
00301 #endif
00302
00303 completed = 1;
00304 }
00305
00306
00307 #ifdef FINI_SECTION_ASM_OP
00308 CRT_CALL_STATIC_FUNCTION (FINI_SECTION_ASM_OP, __do_global_dtors_aux)
00309 #else
00310 static func_ptr __do_global_dtors_aux_fini_array_entry[]
00311 __attribute__ ((__unused__, section(".fini_array")))
00312 = { __do_global_dtors_aux };
00313 #endif
00314
00315 #if defined(USE_EH_FRAME_REGISTRY) || defined(JCR_SECTION_NAME)
00316
00317
00318
00319
00320 static void __attribute__((used))
00321 frame_dummy (void)
00322 {
00323 #ifdef USE_EH_FRAME_REGISTRY
00324 static struct object object;
00325 #ifdef CRT_GET_RFIB_DATA
00326 void *tbase, *dbase;
00327 tbase = 0;
00328 CRT_GET_RFIB_DATA (dbase);
00329 if (__register_frame_info_bases)
00330 __register_frame_info_bases (__EH_FRAME_BEGIN__, &object, tbase, dbase);
00331 #else
00332 if (__register_frame_info)
00333 __register_frame_info (__EH_FRAME_BEGIN__, &object);
00334 #endif
00335 #endif
00336 #ifdef JCR_SECTION_NAME
00337 if (__JCR_LIST__[0])
00338 {
00339 void (*register_classes) (void *) = _Jv_RegisterClasses;
00340 __asm ("" : "+r" (register_classes));
00341 if (register_classes)
00342 register_classes (__JCR_LIST__);
00343 }
00344 #endif
00345 }
00346
00347 #ifdef INIT_SECTION_ASM_OP
00348 CRT_CALL_STATIC_FUNCTION (INIT_SECTION_ASM_OP, frame_dummy)
00349 #else
00350 static func_ptr __frame_dummy_init_array_entry[]
00351 __attribute__ ((__unused__, section(".init_array")))
00352 = { frame_dummy };
00353 #endif
00354 #endif
00355
00356 #else
00357
00358
00359
00360
00361
00362
00363
00364
00365 static void __do_global_ctors_aux (void);
00366 void
00367 __do_global_ctors (void)
00368 {
00369 #ifdef INVOKE__main
00370
00371
00372
00373
00374 __do_global_ctors_aux ();
00375 #endif
00376 }
00377
00378 asm (INIT_SECTION_ASM_OP);
00379
00380
00381
00382
00383
00384
00385 static void __attribute__((used))
00386 __do_global_ctors_aux (void)
00387 {
00388 FORCE_CODE_SECTION_ALIGN
00389 asm (TEXT_SECTION_ASM_OP);
00390 DO_GLOBAL_CTORS_BODY;
00391 atexit (__do_global_dtors);
00392 }
00393
00394 #endif
00395
00396 #elif defined(HAS_INIT_SECTION)
00397
00398 extern void __do_global_dtors (void);
00399
00400
00401
00402
00403
00404 void
00405 __do_global_dtors (void)
00406 {
00407 func_ptr *p, f;
00408 for (p = __DTOR_LIST__ + 1; (f = *p); p++)
00409 f ();
00410
00411 #ifdef USE_EH_FRAME_REGISTRY
00412 if (__deregister_frame_info)
00413 __deregister_frame_info (__EH_FRAME_BEGIN__);
00414 #endif
00415 }
00416
00417 #if defined(USE_EH_FRAME_REGISTRY) || defined(JCR_SECTION_NAME)
00418
00419
00420
00421
00422 void
00423 __do_global_ctors_1(void)
00424 {
00425 #ifdef USE_EH_FRAME_REGISTRY
00426 static struct object object;
00427 if (__register_frame_info)
00428 __register_frame_info (__EH_FRAME_BEGIN__, &object);
00429 #endif
00430 #ifdef JCR_SECTION_NAME
00431 if (__JCR_LIST__[0])
00432 {
00433 void (*register_classes) (void *) = _Jv_RegisterClasses;
00434 __asm ("" : "+r" (register_classes));
00435 if (register_classes)
00436 register_classes (__JCR_LIST__);
00437 }
00438 #endif
00439 }
00440 #endif
00441
00442 #else
00443 #error "What are you doing with crtstuff.c, then?"
00444 #endif
00445
00446 #elif defined(CRT_END)
00447
00448
00449
00450
00451
00452
00453
00454 #ifdef CTOR_LIST_END
00455 CTOR_LIST_END;
00456 #elif defined(CTORS_SECTION_ASM_OP)
00457
00458
00459 static func_ptr force_to_data[1] __attribute__ ((__unused__)) = { };
00460 asm (CTORS_SECTION_ASM_OP);
00461 STATIC func_ptr __CTOR_END__[1]
00462 __attribute__((aligned(sizeof(func_ptr))))
00463 = { (func_ptr) 0 };
00464 #else
00465 STATIC func_ptr __CTOR_END__[1]
00466 __attribute__((section(".ctors"), aligned(sizeof(func_ptr))))
00467 = { (func_ptr) 0 };
00468 #endif
00469
00470 #ifdef DTOR_LIST_END
00471 DTOR_LIST_END;
00472 #elif defined(DTORS_SECTION_ASM_OP)
00473 asm (DTORS_SECTION_ASM_OP);
00474 STATIC func_ptr __DTOR_END__[1]
00475 __attribute__ ((unused, aligned(sizeof(func_ptr))))
00476 = { (func_ptr) 0 };
00477 #else
00478 STATIC func_ptr __DTOR_END__[1]
00479 __attribute__((unused, section(".dtors"), aligned(sizeof(func_ptr))))
00480 = { (func_ptr) 0 };
00481 #endif
00482
00483 #ifdef EH_FRAME_SECTION_NAME
00484
00485
00486 # if __INT_MAX__ == 2147483647
00487 typedef int int32;
00488 # elif __LONG_MAX__ == 2147483647
00489 typedef long int32;
00490 # elif __SHRT_MAX__ == 2147483647
00491 typedef short int32;
00492 # else
00493 # error "Missing a 4 byte integer"
00494 # endif
00495 STATIC EH_FRAME_SECTION_CONST int32 __FRAME_END__[]
00496 __attribute__ ((unused, section(EH_FRAME_SECTION_NAME),
00497 aligned(sizeof(int32))))
00498 = { 0 };
00499 #endif
00500
00501 #ifdef JCR_SECTION_NAME
00502
00503 STATIC void *__JCR_END__[1]
00504 __attribute__ ((unused, section(JCR_SECTION_NAME),
00505 aligned(sizeof(void *))))
00506 = { 0 };
00507 #endif
00508
00509 #ifdef INIT_ARRAY_SECTION_ASM_OP
00510
00511
00512
00513 #elif defined(INIT_SECTION_ASM_OP)
00514
00515 #ifdef OBJECT_FORMAT_ELF
00516 static void __attribute__((used))
00517 __do_global_ctors_aux (void)
00518 {
00519 func_ptr *p;
00520 for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
00521 (*p) ();
00522 }
00523
00524
00525 CRT_CALL_STATIC_FUNCTION (INIT_SECTION_ASM_OP, __do_global_ctors_aux)
00526 #else
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549 static void
00550 __do_global_ctors_aux (void)
00551 {
00552 asm (INIT_SECTION_ASM_OP);
00553 DO_GLOBAL_CTORS_BODY;
00554 atexit (__do_global_dtors);
00555 }
00556
00557 FORCE_CODE_SECTION_ALIGN
00558 asm (TEXT_SECTION_ASM_OP);
00559
00560 #endif
00561
00562 #elif defined(HAS_INIT_SECTION)
00563
00564 extern void __do_global_ctors (void);
00565
00566
00567
00568
00569 void
00570 __do_global_ctors (void)
00571 {
00572 func_ptr *p;
00573 #if defined(USE_EH_FRAME_REGISTRY) || defined(JCR_SECTION_NAME)
00574 __do_global_ctors_1();
00575 #endif
00576 for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
00577 (*p) ();
00578 }
00579
00580 #else
00581 #error "What are you doing with crtstuff.c, then?"
00582 #endif
00583
00584 #else
00585 #error "One of CRT_BEGIN or CRT_END must be defined."
00586 #endif