|
|
1.1 root 1: /* Specialized bits of code needed to support construction and
2: destruction of file-scope objects in C++ code.
3:
4: Written by Ron Guilmette ([email protected]) with help from Richard Stallman.
5:
6: Copyright (C) 1991 Free Software Foundation, Inc.
7:
8: This file is part of GNU CC.
9:
10: GNU CC is free software; you can redistribute it and/or modify
11: it under the terms of the GNU General Public License as published by
12: the Free Software Foundation; either version 2, or (at your option)
13: any later version.
14:
15: GNU CC is distributed in the hope that it will be useful,
16: but WITHOUT ANY WARRANTY; without even the implied warranty of
17: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: GNU General Public License for more details.
19:
20: You should have received a copy of the GNU General Public License
21: along with GNU CC; see the file COPYING. If not, write to
22: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
23:
24: /* As a special exception, if you link this library with files
25: compiled with GCC to produce an executable, this does not cause
26: the resulting executable to be covered by the GNU General Public License.
27: This exception does not however invalidate any other reasons why
28: the executable file might be covered by the GNU General Public License. */
29:
30: /* This file is a bit like libgcc1.c/libgcc2.c in that it is compiled
31: multiple times and yields multiple .o files.
32:
33: This file is useful on target machines where the object file format
34: supports multiple "user-defined" sections (e.g. COFF, ELF, ROSE). On
35: such systems, this file allows us to avoid running collect (or any
36: other such slow and painful kludge). Additionally, if the target
37: system supports a .init section, this file allows us to support the
38: linking of C++ code with a non-C++ main program.
39:
40: Note that if INIT_SECTION_ASM_OP is defined in the tm.h file, then
41: this file *will* make use of the .init section. If that symbol is
42: not defined however, then the .init section will not be used.
43:
44: Currently, only ELF is actually supported.
45: The other formats probably need just alternative macro definitions.
46:
47: This file must be compiled with gcc. */
48:
49: /* It is incorrect to include config.h here, because this file is being
50: compiled for the target, and hence definitions concerning only the host
51: do not apply. */
52:
53: #include "tm.h"
54:
55: #ifndef CTORS_SECTION_ASM_OP
56: #define CTORS_SECTION_ASM_OP "\t.section\t.ctors,\"a\",@progbits"
57: #endif
58: #ifndef DTORS_SECTION_ASM_OP
59: #define DTORS_SECTION_ASM_OP "\t.section\t.dtors,\"a\",@progbits"
60: #endif
61:
62: #include "gbl-ctors.h"
63:
64: #ifndef ON_EXIT /* DO_GLOBAL_CTORS_BODY uses ON_EXIT */
65: #define ON_EXIT(a, b)
66: #endif
67:
68: #ifdef CRT_BEGIN
69:
70: #ifdef INIT_SECTION_ASM_OP
71:
72: /* Force cc1 to switch to .text section. */
73: static void force_to_text () { }
74:
75: asm (INIT_SECTION_ASM_OP); /* cc1 doesn't know that we are switching! */
76:
77: /* A routine to invoke all of the global constructors upon entry to the
78: program. We put this into the .init section (for systems that have
79: such a thing) so that we can properly perform the construction of
80: file-scope static-storage C++ objects within shared libraries. */
81:
82: static void
83: __do_global_ctors () /* prologue goes in .init section */
84: {
85: asm (TEXT_SECTION_ASM_OP); /* don't put epilogue and body in .init */
86: DO_GLOBAL_CTORS_BODY;
87: }
88:
89: #endif /* defined(INIT_SECTION_ASM_OP) */
90:
91: /* Force cc1 to switch to .data section. */
92: static func_ptr force_to_data[0] = { };
93:
94: /* The -1 is a flag to __do_global_[cd]tors
95: indicating that this table does not start with a count of elements. */
96: asm (CTORS_SECTION_ASM_OP); /* cc1 doesn't know that we are switching! */
97: func_ptr __CTOR_LIST__[1] = { (func_ptr) (-1) };
98:
99: asm (DTORS_SECTION_ASM_OP); /* cc1 doesn't know that we are switching! */
100: func_ptr __DTOR_LIST__[1] = { (func_ptr) (-1) };
101:
102: #endif /* defined(CRT_BEGIN) */
103:
104: #ifdef CRT_END
105:
106: #ifdef INIT_SECTION_ASM_OP
107:
108: /* A routine to invoke all of the global constructors upon entry to the
109: program. We put this into the .init section (for systems that have
110: such a thing) so that we can properly perform the construction of
111: file-scope static-storage C++ objects within shared libraries.
112:
113: This must be virtually identical to the one above so that we can
114: insure that the function prologue from the one above works correctly
115: with the epilogue from this one. (They will both go into the .init
116: section as the first and last things (respectively) that the linker
117: will put in that section.)
118: */
119:
120: static void
121: __do_global_ctors () /* prologue goes in .text section */
122: {
123: asm (INIT_SECTION_ASM_OP);
124: DO_GLOBAL_CTORS_BODY;
125: } /* epilogue and body go in .init section */
126:
127: #endif /* defined(INIT_SECTION_ASM_OP) */
128:
129: /* Force cc1 to switch to .data section. */
130: static func_ptr force_to_data[0] = { };
131:
132: asm (CTORS_SECTION_ASM_OP); /* cc1 doesn't know that we are switching! */
133: func_ptr __CTOR_END__[1] = { (func_ptr) 0 };
134:
135: asm (DTORS_SECTION_ASM_OP); /* cc1 doesn't know that we are switching! */
136: func_ptr __DTOR_END__[1] = { (func_ptr) 0 };
137:
138: #endif /* defined(CRT_END) */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.