Back to index

glibc  2.9
initfini.c
Go to the documentation of this file.
00001 /* Special .init and .fini section support for Alpha.
00002    Copyright (C) 2001, 2002, 2003 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 .init and .fini
00041    sections and defines global symbols for those addresses, so they can be
00042    called as functions.
00043 
00044    * crtn.s puts the corresponding function epilogues in the .init and .fini
00045    sections.
00046 
00047    This differs from what would be generated by the generic code in that
00048    we save and restore the GP within the function.  In order for linker
00049    relaxation to work, the value in the GP register on exit from a function
00050    must be valid for the function entry point.  Normally, a function is
00051    contained within one object file and this is not an issue, provided
00052    that the function reloads the gp after making any function calls.
00053    However, _init and _fini are constructed from pieces of many object
00054    files, all of which may have different GP values.  So we must reload
00055    the GP value from crti.o in crtn.o.  */
00056 
00057 __asm__ ("                                       \n\
00058 #include \"defs.h\"                              \n\
00059                                                  \n\
00060 /*@HEADER_ENDS*/                                 \n\
00061                                                  \n\
00062 /*@_init_PROLOG_BEGINS*/                         \n\
00063        .section .init, \"ax\", @progbits         \n\
00064        .globl _init                              \n\
00065        .type  _init, @function                   \n\
00066        .usepv _init, std                         \n\
00067 _init:                                           \n\
00068        ldgp   $29, 0($27)                        \n\
00069        subq   $30, 16, $30                       \n\
00070        lda    $27, __gmon_start__                \n\
00071        stq    $26, 0($30)                        \n\
00072        stq    $29, 8($30)                        \n\
00073        beq    $27, 1f                                   \n\
00074        jsr    $26, ($27), __gmon_start__         \n\
00075        ldq    $29, 8($30)                        \n\
00076        .align 3                                  \n\
00077 1:                                               \n\
00078 /*@_init_PROLOG_ENDS*/                                  \n\
00079                                                  \n\
00080 /*@_init_EPILOG_BEGINS*/                         \n\
00081        .section .init, \"ax\", @progbits         \n\
00082        ldq    $26, 0($30)                        \n\
00083        ldq    $29, 8($30)                        \n\
00084        addq   $30, 16, $30                       \n\
00085        ret                                       \n\
00086 /*@_init_EPILOG_ENDS*/                                  \n\
00087                                                  \n\
00088 /*@_fini_PROLOG_BEGINS*/                         \n\
00089        .section .fini, \"ax\", @progbits         \n\
00090        .globl _fini                              \n\
00091        .type  _fini,@function                           \n\
00092        .usepv _fini,std                          \n\
00093 _fini:                                           \n\
00094        ldgp   $29, 0($27)                        \n\
00095        subq   $30, 16, $30                       \n\
00096        stq    $26, 0($30)                        \n\
00097        stq    $29, 8($30)                        \n\
00098        .align 3                                  \n\
00099 /*@_fini_PROLOG_ENDS*/                                  \n\
00100                                                  \n\
00101 /*@_fini_EPILOG_BEGINS*/                         \n\
00102        .section .fini, \"ax\", @progbits         \n\
00103        ldq    $26, 0($30)                        \n\
00104        ldq    $29, 8($30)                        \n\
00105        addq   $30, 16, $30                       \n\
00106        ret                                       \n\
00107 /*@_fini_EPILOG_ENDS*/                                  \n\
00108                                                  \n\
00109 /*@TRAILER_BEGINS*/                              \n\
00110 ");