Back to index

glibc  2.9
initfini.c
Go to the documentation of this file.
00001 /* Special .init and .fini section support for ia64.
00002    Copyright (C) 2000, 2002, 2003, 2005 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    In addition to the permissions in the GNU Lesser General Public
00011    License, the Free Software Foundation gives you unlimited
00012    permission to link the compiled version of this file with other
00013    programs, and to distribute those programs without any restriction
00014    coming from the use of this file. (The GNU Lesser General Public
00015    License restrictions do apply in other respects; for example, they
00016    cover modification of the file, and distribution when not linked
00017    into another program.)
00018 
00019    Note that people who make modified versions of this file are not
00020    obligated to grant this special exception for their modified
00021    versions; it is their choice whether to do so. The GNU Lesser
00022    General Public License gives permission to release a modified
00023    version without this exception; this exception also makes it
00024    possible to release a modified version which carries forward this
00025    exception.
00026 
00027    The GNU C Library is distributed in the hope that it will be useful,
00028    but WITHOUT ANY WARRANTY; without even the implied warranty of
00029    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00030    Lesser General Public License for more details.
00031 
00032    You should have received a copy of the GNU Lesser General Public
00033    License along with the GNU C Library; if not, write to the Free
00034    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00035    02111-1307 USA.  */
00036 
00037 /* This file is compiled into assembly code which is then munged by a sed
00038    script into two files: crti.s and crtn.s.
00039 
00040    * crti.s puts a function prologue at the beginning of the
00041    .init and .fini sections and defines global symbols for
00042    those addresses, so they can be called as functions.
00043 
00044    * crtn.s puts the corresponding function epilogues
00045    in the .init and .fini sections. */
00046 
00047 __asm__ ("\n\n"
00048 "#include \"defs.h\"\n"
00049 "\n"
00050 "/*@HEADER_ENDS*/\n"
00051 "\n"
00052 "/*@_init_PROLOG_BEGINS*/\n");
00053 
00054 
00055 /* If we have working .init_array support, we want to keep the .init
00056    section empty (apart from the mandatory prologue/epilogue.  This
00057    ensures that the default unwind conventions (return-pointer in b0,
00058    frame state in ar.pfs, etc.)  will do the Right Thing.  To ensure
00059    an empty .init section, we register gmon_initializer() via the
00060    .init_array.
00061 
00062        --davidm 02/10/29 */
00063 
00064 static void
00065 __attribute__ ((used))
00066 gmon_initializer (void)
00067 {
00068   extern void weak_function __gmon_start__ (void);
00069 
00070   if (__gmon_start__)
00071     (*__gmon_start__)();
00072 }
00073 
00074 __asm__ (".section .init_array, \"aw\"\n"
00075         "\tdata8 @fptr(gmon_initializer)\n");
00076 
00077 
00078 __asm__ (".section .init\n"
00079 "      .global _init#\n"
00080 "      .proc _init#\n"
00081 "_init:\n"
00082 "      .prologue\n"
00083 "      .save ar.pfs, r34\n"
00084 "      alloc r34 = ar.pfs, 0, 3, 0, 0\n"
00085 "      .vframe r32\n"
00086 "      mov r32 = r12\n"
00087 "      .save rp, r33\n"
00088 "      mov r33 = b0\n"
00089 "      .body\n"
00090 "      adds r12 = -16, r12\n"
00091 "      ;;\n"         /* see gmon_initializer() above */
00092 "      .endp _init#\n"
00093 "\n"
00094 "/*@_init_PROLOG_ENDS*/\n"
00095 "\n"
00096 "/*@_init_EPILOG_BEGINS*/\n"
00097 "      .section .init\n"
00098 "      .proc _init#\n"
00099 "_init:\n"
00100 "      .prologue\n"
00101 "      .save ar.pfs, r34\n"
00102 "      .vframe r32\n"
00103 "      .save rp, r33\n"
00104 "      .body\n"
00105 "      .regstk 0,2,0,0\n"
00106 "      mov r12 = r32\n"
00107 "      mov ar.pfs = r34\n"
00108 "      mov b0 = r33\n"
00109 "      br.ret.sptk.many b0\n"
00110 "      .endp _init#\n"
00111 "/*@_init_EPILOG_ENDS*/\n"
00112 "\n"
00113 "/*@_fini_PROLOG_BEGINS*/\n"
00114 "      .section .fini\n"
00115 "      .global _fini#\n"
00116 "      .proc _fini#\n"
00117 "_fini:\n"
00118 "      .prologue\n"
00119 "      .save ar.pfs, r34\n"
00120 "      alloc r34 = ar.pfs, 0, 3, 0, 0\n"
00121 "      .vframe r32\n"
00122 "      mov r32 = r12\n"
00123 "      .save rp, r33\n"
00124 "      mov r33 = b0\n"
00125 "      .body\n"
00126 "      adds r12 = -16, r12\n"
00127 "      ;;\n"
00128 "      .endp _fini#\n"
00129 "\n"
00130 "/*@_fini_PROLOG_ENDS*/\n"
00131 "      br.call.sptk.many b0 = i_am_not_a_leaf# ;;\n"
00132 "      ;;\n"
00133 "\n"
00134 "/*@_fini_EPILOG_BEGINS*/\n"
00135 "      .section .fini\n"
00136 "      .proc _fini#\n"
00137 "_fini:\n"
00138 "      .prologue\n"
00139 "      .save ar.pfs, r34\n"
00140 "      .vframe r32\n"
00141 "      .save rp, r33\n"
00142 "      .body\n"
00143 "      mov r12 = r32\n"
00144 "      mov ar.pfs = r34\n"
00145 "      mov b0 = r33\n"
00146 "      br.ret.sptk.many b0\n"
00147 "      .endp _fini#\n"
00148 "\n"
00149 "/*@_fini_EPILOG_ENDS*/\n"
00150 "\n"
00151 "/*@TRAILER_BEGINS*/\n"
00152 );