Readd special linkage permissions to license.
[glibc.git] / sysdeps / generic / initfini.c
blobaf5846a6a80644a51a527cd0f7e641197a05e70d
1 /* Special .init and .fini section support.
2 Copyright (C) 1995, 1996, 1997, 2000 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
11 In addition to the permissions in the GNU Lesser General Public
12 License, the Free Software Foundation gives you unlimited
13 permission to link the compiled version of this file with other
14 programs, and to distribute those programs without any restriction
15 coming from the use of this file. (The GNU Lesser General Public
16 License restrictions do apply in other respects; for example, they
17 cover modification of the file, and distribution when not linked
18 into another program.)
20 The GNU C Library is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 Lesser General Public License for more details.
25 You should have received a copy of the GNU Lesser General Public
26 License along with the GNU C Library; if not, write to the Free
27 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
28 02111-1307 USA. */
30 /* This file is compiled into assembly code which is then munged by a sed
31 script into two files: crti.s and crtn.s.
33 * crti.s puts a function prologue at the beginning of the
34 .init and .fini sections and defines global symbols for
35 those addresses, so they can be called as functions.
37 * crtn.s puts the corresponding function epilogues
38 in the .init and .fini sections. */
40 #include <stdlib.h>
42 /* We use embedded asm for .section unconditionally, as this makes it
43 easier to insert the necessary directives into crtn.S. */
44 #define SECTION(x) asm (".section " x )
46 /* Embed an #include to pull in the alignment and .end directives. */
47 asm ("\n#include \"defs.h\"");
49 /* The initial common code ends here. */
50 asm ("\n/*@HEADER_ENDS*/");
52 /* To determine whether we need .end and .align: */
53 asm ("\n/*@TESTS_BEGIN*/");
54 extern void dummy (void (*foo) (void));
55 void
56 dummy (void (*foo) (void))
58 if (foo)
59 (*foo) ();
61 asm ("\n/*@TESTS_END*/");
63 /* The beginning of _init: */
64 asm ("\n/*@_init_PROLOG_BEGINS*/");
66 static void
67 call_gmon_start(void)
69 extern void __gmon_start__ (void) __attribute__ ((weak)); /*weak_extern (__gmon_start__);*/
70 void (*gmon_start) (void) = __gmon_start__;
72 if (gmon_start)
73 gmon_start ();
76 SECTION (".init");
77 extern void _init (void);
78 void
79 _init (void)
81 /* We cannot use the normal constructor mechanism in gcrt1.o because it
82 appears before crtbegin.o in the link, so the header elt of .ctors
83 would come after the elt for __gmon_start__. One approach is for
84 gcrt1.o to reference a symbol which would be defined by some library
85 module which has a constructor; but then user code's constructors
86 would come first, and not be profiled. */
87 call_gmon_start ();
89 asm ("ALIGN");
90 asm("END_INIT");
91 /* Now the epilog. */
92 asm ("\n/*@_init_PROLOG_ENDS*/");
93 asm ("\n/*@_init_EPILOG_BEGINS*/");
94 SECTION(".init");
96 asm ("END_INIT");
98 /* End of the _init epilog, beginning of the _fini prolog. */
99 asm ("\n/*@_init_EPILOG_ENDS*/");
100 asm ("\n/*@_fini_PROLOG_BEGINS*/");
102 SECTION (".fini");
103 extern void _fini (void);
104 void
105 _fini (void)
108 /* End of the _fini prolog. */
109 asm ("ALIGN");
110 asm ("END_FINI");
111 asm ("\n/*@_fini_PROLOG_ENDS*/");
114 /* Let GCC know that _fini is not a leaf function by having a dummy
115 function call here. We arrange for this call to be omitted from
116 either crt file. */
117 extern void i_am_not_a_leaf (void);
118 i_am_not_a_leaf ();
121 /* Beginning of the _fini epilog. */
122 asm ("\n/*@_fini_EPILOG_BEGINS*/");
123 SECTION (".fini");
125 asm ("END_FINI");
127 /* End of the _fini epilog. Any further generated assembly (e.g. .ident)
128 is shared between both crt files. */
129 asm ("\n/*@_fini_EPILOG_ENDS*/");
130 asm ("\n/*@TRAILER_BEGINS*/");
132 /* End of file. */