test: sync tst-atfork2 with GNU libc
[uclibc-ng.git] / libpthread / nptl / sysdeps / unix / sysv / linux / xtensa / pt-initfini.c
blob4e6d26e810a66703aa52d04cec15650ca6791365
1 /* Special .init and .fini section support. Linuxthread version.
2 Copyright (C) 1995,1996,1997,2000,2001,2002 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
6 and/or modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 In addition to the permissions in the GNU Lesser General Public
11 License, the Free Software Foundation gives you unlimited
12 permission to link the compiled version of this file with other
13 programs, and to distribute those programs without any restriction
14 coming from the use of this file. (The Library General Public
15 License restrictions do apply in other respects; for example, they
16 cover modification of the file, and distribution when not linked
17 into another program.)
19 The GNU C Library is distributed in the hope that it will be
20 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
21 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU Lesser General Public License for more details.
24 You should have received a copy of the GNU Lesser General Public
25 License along with the GNU C Library; see the file COPYING.LIB. If not,
26 see <http://www.gnu.org/licenses/>. */
28 /* This file is compiled into assembly code which is then munged by a sed
29 script into two files: crti.s and crtn.s.
31 * crti.s puts a function prologue at the beginning of the
32 .init and .fini sections and defines global symbols for
33 those addresses, so they can be called as functions.
35 * crtn.s puts the corresponding function epilogues
36 in the .init and .fini sections. */
38 #include <stdlib.h>
40 /* We use embedded asm for .section unconditionally, as this makes it
41 easier to insert the necessary directives into crtn.S. */
42 #define SECTION(x) __asm__ (".section " x )
44 /* Embed an #include to pull in the alignment and .end directives. */
45 __asm__ ("\n#include \"defs.h\"");
46 __asm__ ("\n#if defined __i686 && defined __ASSEMBLER__");
47 __asm__ ("\n#undef __i686");
48 __asm__ ("\n#define __i686 __i686");
49 __asm__ ("\n#endif");
51 /* The initial common code ends here. */
52 __asm__ ("\n/*@HEADER_ENDS*/");
54 /* To determine whether we need .end and .align: */
55 __asm__ ("\n/*@TESTS_BEGIN*/");
56 extern void dummy (void (*foo) (void));
57 void
58 dummy (void (*foo) (void))
60 if (foo)
61 (*foo) ();
63 __asm__ ("\n/*@TESTS_END*/");
65 /* The beginning of _init: */
66 __asm__ ("\n/*@_init_PROLOG_BEGINS*/");
68 static void
69 call_initialize_minimal (void)
71 extern void __pthread_initialize_minimal_internal (void)
72 __attribute ((visibility ("hidden")));
74 __pthread_initialize_minimal_internal ();
77 SECTION (".init");
78 extern void __attribute__ ((section (".init"))) _init (void);
79 void
80 _init (void)
82 /* The very first thing we must do is to set up the registers. */
83 call_initialize_minimal ();
85 __asm__ ("ALIGN");
86 __asm__("END_INIT");
87 /* Now the epilog. */
88 __asm__ ("\n/*@_init_PROLOG_ENDS*/");
89 __asm__ ("\n/*@_init_EPILOG_BEGINS*/");
90 SECTION(".init");
92 __asm__ ("END_INIT");
94 /* End of the _init epilog, beginning of the _fini prolog. */
95 __asm__ ("\n/*@_init_EPILOG_ENDS*/");
96 __asm__ ("\n/*@_fini_PROLOG_BEGINS*/");
98 SECTION (".fini");
99 extern void __attribute__ ((section (".fini"))) _fini (void);
100 void
101 _fini (void)
104 /* End of the _fini prolog. */
105 __asm__ ("ALIGN");
106 __asm__ ("END_FINI");
107 __asm__ ("\n/*@_fini_PROLOG_ENDS*/");
109 /* Xtensa: It doesn't really matter whether GCC thinks this is a leaf
110 function or not, and the scripts that are supposed to remove the
111 call don't catch the literal, resulting in an undefined symbol
112 reference. */
113 #if 0
115 /* Let GCC know that _fini is not a leaf function by having a dummy
116 function call here. We arrange for this call to be omitted from
117 either crt file. */
118 extern void i_am_not_a_leaf (void);
119 i_am_not_a_leaf ();
121 #endif
123 /* Beginning of the _fini epilog. */
124 __asm__ ("\n/*@_fini_EPILOG_BEGINS*/");
125 SECTION (".fini");
127 __asm__ ("END_FINI");
129 /* End of the _fini epilog. Any further generated assembly (e.g. .ident)
130 is shared between both crt files. */
131 __asm__ ("\n/*@_fini_EPILOG_ENDS*/");
132 __asm__ ("\n/*@TRAILER_BEGINS*/");
134 /* End of file. */