Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20110412044419

Diff

Diff from 1.7 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/pcc/pcc-libs/csu/linux/crtbegin.c

Annotated File View

gmcgarry
1.7
1 /*      $Id: crtbegin.c,v 1.7 2011/04/12 04:44:19 gmcgarry Exp $        */
gmcgarry
1.1
2 /*-
3  * Copyright (c) 1998, 2001, 2002 The NetBSD Foundation, Inc.
4  * All rights reserved.
5  *
6  * This code is derived from software contributed to The NetBSD Foundation
7  * by Paul Kranenburg, Ross Harvey, and Jason R. Thorpe.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 /*
32  * Run-time module which handles constructors and destructors.
33  */
gmcgarry
1.3
34
35 #include "common.h"
gmcgarry
1.1
36
gmcgarry
1.6
37 void __do_global_ctors_aux(void);
gmcgarry
1.4
38 void __do_global_dtors_aux(void);
39
gmcgarry
1.6
40 extern void (*__CTOR_LIST__[1])(void);
41 extern void (*__DTOR_LIST__[1])(void);
42
gmcgarry
1.7
43 asm(    "       .section .ctors,\"aw\",@progbits\n"
44         "       .align 4\n"
gmcgarry
1.6
45         "__CTOR_LIST__:\n"
46 #ifdef __x86_64__
47         "       .quad -1\n"
48 #else
49         "       .long -1\n"
50 #endif
gmcgarry
1.7
51         "       .section .dtors,\"aw\",@progbits\n"
52         "       .align 4\n"
gmcgarry
1.6
53         "__DTOR_LIST__:\n"
54 #ifdef __x86_64__
55         "       .quad -1\n"
56 #else
57         "       .long -1\n"
58 #endif
59 );
60
gmcgarry
1.1
61
62 static void
63 __ctors(void)
64 {
65         unsigned long i = (unsigned long__CTOR_LIST__[0];
66         void (**p)(void);
67
68         if (i == (unsigned long) -1)  {
69                 for (i = 1__CTOR_LIST__[i]; i++)
70                         ;
71                 i--;
72         }
73         p = __CTOR_LIST__ + i;
74         while (i--)
75                 (**p--)();
76 }
77
78 static void
79 __dtors(void)
80 {
81         void (**p)(void) = __DTOR_LIST__ + 1;
82
83         while (*p)
84                 (**p++)();
85 }
86
87 void
88 __do_global_ctors_aux(void)
89 {
90         static int initialized;
91
92         if (!initialized) {
93                 initialized = 1;
94                 __ctors();
95         }
96 }
97
98 void
99 __do_global_dtors_aux(void)
100 {
101         static int finished;
102
103         if (finished)
104                 return;
105
106         __dtors();
107
108         finished = 1;
109 }
110
gmcgarry
1.2
111 #define MD_CALL_STATIC_FUNCTION(section, func)                          \
112 void __call_##func(void);                                               \
113 void __call_##func(void)                                                \
114 {                                                                       \
gmcgarry
1.3
115         asm volatile (".section " #section);                            \
gmcgarry
1.2
116         func();                                                         \
gmcgarry
1.3
117         asm volatile (".previous");                                     \
gmcgarry
1.2
118 }
gmcgarry
1.1
119
120 MD_CALL_STATIC_FUNCTION(.init__do_global_ctors_aux)
121 MD_CALL_STATIC_FUNCTION(.fini__do_global_dtors_aux)
gmcgarry
1.3
122
gmcgarry
1.7
123 IDENT("$Id: crtbegin.c,v 1.7 2011/04/12 04:44:19 gmcgarry Exp $");
FishEye: Open Source License registered to PCC.
Your maintenance has expired. You can renew your license at http://www.atlassian.com/fisheye/renew
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-09-20 03:56 +0200