Back to index

glibc  2.9
pt-initfini.c
Go to the documentation of this file.
00001 /* Special .init and .fini section support for Alpha.  Linuxthreads version.
00002    Copyright (C) 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    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 /* This file is compiled into assembly code which is then munged by a sed
00021    script into two files: crti.s and crtn.s.
00022 
00023    * crti.s puts a function prologue at the beginning of the .init and .fini
00024    sections and defines global symbols for those addresses, so they can be
00025    called as functions.
00026 
00027    * crtn.s puts the corresponding function epilogues in the .init and .fini
00028    sections.
00029 
00030    This differs from what would be generated by the generic code in that
00031    we save and restore the GP within the function.  In order for linker
00032    relaxation to work, the value in the GP register on exit from a function
00033    must be valid for the function entry point.  Normally, a function is
00034    contained within one object file and this is not an issue, provided
00035    that the function reloads the gp after making any function calls.
00036    However, _init and _fini are constructed from pieces of many object
00037    files, all of which may have different GP values.  So we must reload
00038    the GP value from crti.o in crtn.o.  */
00039 
00040 __asm__ ("                                       \n\
00041 #include \"defs.h\"                              \n\
00042                                                  \n\
00043 /*@HEADER_ENDS*/                                 \n\
00044                                                  \n\
00045 /*@_init_PROLOG_BEGINS*/                         \n\
00046        .section .init, \"ax\", @progbits         \n\
00047        .globl _init                              \n\
00048        .type  _init,@function                           \n\
00049        .usepv _init,std                          \n\
00050 _init:                                           \n\
00051        ldgp   $29, 0($27)                        \n\
00052        subq   $30, 16, $30                       \n\
00053        stq    $26, 0($30)                        \n\
00054        stq    $29, 8($30)                        \n\
00055        jsr    $26, __pthread_initialize_minimal  \n\
00056        ldq    $29, 8($30)                        \n\
00057        .align 3                                  \n\
00058 /*@_init_PROLOG_ENDS*/                                  \n\
00059                                                  \n\
00060 /*@_init_EPILOG_BEGINS*/                         \n\
00061        .section .init, \"ax\", @progbits         \n\
00062        ldq    $26, 0($30)                        \n\
00063        ldq    $29, 8($30)                        \n\
00064        addq   $30, 16, $30                       \n\
00065        ret                                       \n\
00066 /*@_init_EPILOG_ENDS*/                                  \n\
00067                                                  \n\
00068 /*@_fini_PROLOG_BEGINS*/                         \n\
00069        .section .fini, \"ax\", @progbits         \n\
00070        .globl _fini                              \n\
00071        .type  _fini,@function                           \n\
00072        .usepv _fini,std                          \n\
00073 _fini:                                           \n\
00074        ldgp   $29, 0($27)                        \n\
00075        subq   $30, 16, $30                       \n\
00076        stq    $26, 0($30)                        \n\
00077        stq    $29, 8($30)                        \n\
00078        .align 3                                  \n\
00079 /*@_fini_PROLOG_ENDS*/                                  \n\
00080                                                  \n\
00081 /*@_fini_EPILOG_BEGINS*/                         \n\
00082        .section .fini, \"ax\", @progbits         \n\
00083        ldq    $26, 0($30)                        \n\
00084        ldq    $29, 8($30)                        \n\
00085        addq   $30, 16, $30                       \n\
00086        ret                                       \n\
00087 /*@_fini_EPILOG_ENDS*/                                  \n\
00088                                                  \n\
00089 /*@TRAILER_BEGINS*/                              \n\
00090 ");