yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame] | 1 | /* Special .init and .fini section support. Linuxthread version. |
| 2 | Copyright (C) 1995, 1996, 1997, 2000, 2001 Free Software Foundation, Inc. |
| 3 | This file is part of the GNU C Library. |
| 4 | |
| 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.1 of the License, or (at your option) any later version. |
| 9 | |
| 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 Lesser 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.) |
| 18 | |
| 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. |
| 23 | |
| 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 | write to the Free Software Foundation, 59 Temple Place - Suite 330, |
| 27 | Boston, MA 02111-1307, USA. */ |
| 28 | |
| 29 | /* This file is compiled into assembly code which is then munged by a sed |
| 30 | script into two files: crti.s and crtn.s. |
| 31 | |
| 32 | * crti.s puts a function prologue at the beginning of the |
| 33 | .init and .fini sections and defines global symbols for |
| 34 | those addresses, so they can be called as functions. |
| 35 | |
| 36 | * crtn.s puts the corresponding function epilogues |
| 37 | in the .init and .fini sections. */ |
| 38 | |
| 39 | #include <stdlib.h> |
| 40 | |
| 41 | /* We use embedded asm for .section unconditionally, as this makes it |
| 42 | easier to insert the necessary directives into crtn.S. */ |
| 43 | #define SECTION(x) __asm__ (".section " x ) |
| 44 | |
| 45 | /* Embed an #include to pull in the alignment and .end directives. */ |
| 46 | __asm__ ("\n#include \"defs.h\""); |
| 47 | |
| 48 | /* The initial common code ends here. */ |
| 49 | __asm__ ("\n/*@HEADER_ENDS*/"); |
| 50 | |
| 51 | /* To determine whether we need .end and .align: */ |
| 52 | __asm__ ("\n/*@TESTS_BEGIN*/"); |
| 53 | extern void dummy (void (*foo) (void)); |
| 54 | void |
| 55 | dummy (void (*foo) (void)) |
| 56 | { |
| 57 | if (foo) |
| 58 | (*foo) (); |
| 59 | } |
| 60 | __asm__ ("\n/*@TESTS_END*/"); |
| 61 | |
| 62 | /* The beginning of _init: */ |
| 63 | __asm__ ("\n/*@_init_PROLOG_BEGINS*/"); |
| 64 | |
| 65 | static void |
| 66 | call_initialize_minimal (void) |
| 67 | { |
| 68 | extern void __pthread_initialize_minimal (void); |
| 69 | |
| 70 | __pthread_initialize_minimal (); |
| 71 | } |
| 72 | |
| 73 | SECTION (".init"); |
| 74 | extern void _init (void); |
| 75 | void |
| 76 | _init (void) |
| 77 | { |
| 78 | /* The very first thing we must do is to set up the registers. */ |
| 79 | call_initialize_minimal (); |
| 80 | |
| 81 | __asm__ ("ALIGN"); |
| 82 | __asm__("END_INIT"); |
| 83 | /* Now the epilog. */ |
| 84 | __asm__ ("\n/*@_init_PROLOG_ENDS*/"); |
| 85 | __asm__ ("\n/*@_init_EPILOG_BEGINS*/"); |
| 86 | SECTION(".init"); |
| 87 | } |
| 88 | __asm__ ("END_INIT"); |
| 89 | |
| 90 | /* End of the _init epilog, beginning of the _fini prolog. */ |
| 91 | __asm__ ("\n/*@_init_EPILOG_ENDS*/"); |
| 92 | __asm__ ("\n/*@_fini_PROLOG_BEGINS*/"); |
| 93 | |
| 94 | SECTION (".fini"); |
| 95 | extern void _fini (void); |
| 96 | void |
| 97 | _fini (void) |
| 98 | { |
| 99 | |
| 100 | /* End of the _fini prolog. */ |
| 101 | __asm__ ("ALIGN"); |
| 102 | __asm__ ("END_FINI"); |
| 103 | __asm__ ("\n/*@_fini_PROLOG_ENDS*/"); |
| 104 | |
| 105 | { |
| 106 | /* Let GCC know that _fini is not a leaf function by having a dummy |
| 107 | function call here. We arrange for this call to be omitted from |
| 108 | either crt file. */ |
| 109 | extern void i_am_not_a_leaf (void); |
| 110 | i_am_not_a_leaf (); |
| 111 | } |
| 112 | |
| 113 | /* Beginning of the _fini epilog. */ |
| 114 | __asm__ ("\n/*@_fini_EPILOG_BEGINS*/"); |
| 115 | SECTION (".fini"); |
| 116 | } |
| 117 | __asm__ ("END_FINI"); |
| 118 | |
| 119 | /* End of the _fini epilog. Any further generated assembly (e.g. .ident) |
| 120 | is shared between both crt files. */ |
| 121 | __asm__ ("\n/*@_fini_EPILOG_ENDS*/"); |
| 122 | __asm__ ("\n/*@TRAILER_BEGINS*/"); |
| 123 | |
| 124 | /* End of file. */ |