Back to index

glibc  2.9
initfini.c
Go to the documentation of this file.
00001 /* Special .init and .fini section support for x86-64.
00002    Copyright (C) 2001, 2002 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\
00048 #include \"defs.h\"\n\
00049 \n\
00050 /*@HEADER_ENDS*/\n\
00051 \n\
00052 /*@_init_PROLOG_BEGINS*/\n\
00053        .align 4\n\
00054        .type  call_gmon_start,@function\n\
00055 call_gmon_start:\n\
00056        subq   $8, %rsp\n\
00057        movq   __gmon_start__@GOTPCREL(%rip), %rax\n\
00058        testq  %rax, %rax\n\
00059        je     .L22\n\
00060        call   *%rax\n\
00061 .L22:\n\
00062        addq   $8, %rsp\n\
00063        ret\n\
00064 \n\
00065        .section .init\n\
00066        .align 4\n\
00067 .globl _init\n\
00068        .type  _init,@function\n\
00069 _init:\n\
00070        subq   $8, %rsp\n\
00071        call   call_gmon_start\n\
00072        ALIGN\n\
00073        END_INIT\n\
00074 \n\
00075 /*@_init_PROLOG_ENDS*/\n\
00076 \n\
00077 /*@_init_EPILOG_BEGINS*/\n\
00078        .section .init\n\
00079        addq   $8, %rsp\n\
00080        ret\n\
00081        END_INIT\n\
00082 \n\
00083 /*@_init_EPILOG_ENDS*/\n\
00084 \n\
00085 /*@_fini_PROLOG_BEGINS*/\n\
00086        .section .fini\n\
00087        .align 4\n\
00088 .globl _fini\n\
00089        .type  _fini,@function\n\
00090 _fini:\n\
00091        subq   $8, %rsp\n\
00092        ALIGN\n\
00093        END_FINI\n\
00094 \n\
00095 /*@_fini_PROLOG_ENDS*/\n\
00096        call   i_am_not_a_leaf@PLT\n\
00097 \n\
00098 /*@_fini_EPILOG_BEGINS*/\n\
00099        .section .fini\n\
00100        addq   $8, %rsp\n\
00101        ret\n\
00102        END_FINI\n\
00103 \n\
00104 /*@_fini_EPILOG_ENDS*/\n\
00105 \n\
00106 /*@TRAILER_BEGINS*/\n\
00107        .weak  __gmon_start__\n\
00108 ");