Annotation of GNUtools/cc/crtstuff.c, revision 1.1.1.1

1.1       root        1: /* Specialized bits of code needed to support construction and
                      2:    destruction of file-scope objects in C++ code.
                      3: 
                      4:    Written by Ron Guilmette ([email protected]) with help from Richard Stallman.
                      5: 
                      6: Copyright (C) 1991 Free Software Foundation, Inc.
                      7: 
                      8: This file is part of GNU CC.
                      9: 
                     10: GNU CC is free software; you can redistribute it and/or modify
                     11: it under the terms of the GNU General Public License as published by
                     12: the Free Software Foundation; either version 2, or (at your option)
                     13: any later version.
                     14: 
                     15: GNU CC is distributed in the hope that it will be useful,
                     16: but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: GNU General Public License for more details.
                     19: 
                     20: You should have received a copy of the GNU General Public License
                     21: along with GNU CC; see the file COPYING.  If not, write to
                     22: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
                     23: 
                     24: /* As a special exception, if you link this library with files
                     25:    compiled with GCC to produce an executable, this does not cause
                     26:    the resulting executable to be covered by the GNU General Public License.
                     27:    This exception does not however invalidate any other reasons why
                     28:    the executable file might be covered by the GNU General Public License.  */
                     29: 
                     30: /* This file is a bit like libgcc1.c/libgcc2.c in that it is compiled
                     31:    multiple times and yields multiple .o files.
                     32: 
                     33:    This file is useful on target machines where the object file format
                     34:    supports multiple "user-defined" sections (e.g. COFF, ELF, ROSE).  On
                     35:    such systems, this file allows us to avoid running collect (or any
                     36:    other such slow and painful kludge).  Additionally, if the target
                     37:    system supports a .init section, this file allows us to support the
                     38:    linking of C++ code with a non-C++ main program.
                     39: 
                     40:    Note that if INIT_SECTION_ASM_OP is defined in the tm.h file, then
                     41:    this file *will* make use of the .init section.  If that symbol is
                     42:    not defined however, then the .init section will not be used.
                     43: 
                     44:    Currently, only ELF and COFF are supported.  It is likely however that
                     45:    ROSE could also be supported, if someone was willing to do the work to
                     46:    make whatever (small?) adaptations are needed.  (Some work may be
                     47:    needed on the ROSE assembler and linker also.)
                     48: 
                     49:    This file must be compiled with gcc.  */
                     50: 
                     51: /* It is incorrect to include config.h here, because this file is being
                     52:    compiled for the target, and hence definitions concerning only the host
                     53:    do not apply.  */
                     54: 
                     55: #include "tm.h"
                     56: 
                     57: #ifndef CTORS_SECTION_ASM_OP
                     58: #define CTORS_SECTION_ASM_OP   ".section\t.ctors,\"a\",@progbits"
                     59: #endif
                     60: #ifndef DTORS_SECTION_ASM_OP
                     61: #define DTORS_SECTION_ASM_OP   ".section\t.dtors,\"a\",@progbits"
                     62: #endif
                     63: 
                     64: #include "gbl-ctors.h"
                     65: 
                     66: #ifndef ON_EXIT
                     67: #define ON_EXIT(a, b)
                     68: #endif
                     69: 
                     70: #ifdef CRT_BEGIN
                     71: 
                     72: #ifdef INIT_SECTION_ASM_OP
                     73: 
                     74: /* The function __do_global_ctors_aux is compiled twice (once in crtbegin.o
                     75:    and once in crtend.o).  It must be declared static to avoid a link
                     76:    error.  Here, we define __do_global_ctors as an externally callable
                     77:    function.  It is externally callable so that __main can invoke it when
                     78:    INVOKE__main is defined.  This has the additional effect of forcing cc1
                     79:    to switch to the .text section.  */
                     80: static void __do_global_ctors_aux ();
                     81: void __do_global_ctors ()
                     82: {
                     83: #ifdef INVOKE__main  /* If __main won't actually call __do_global_ctors
                     84:                        then it doesn't matter what's inside the function.
                     85:                        The inside of __do_global_ctors_aux is called
                     86:                        automatically in that case.
                     87:                        And the Alliant fx2800 linker crashes
                     88:                        on this reference.  So prevent the crash.  */
                     89:   __do_global_ctors_aux ();
                     90: #endif
                     91: }
                     92: 
                     93: asm (INIT_SECTION_ASM_OP);     /* cc1 doesn't know that we are switching! */
                     94: 
                     95: /* On some svr4 systems, the .init section preamble code provided in
                     96:    crti.o may do some evil things which we have to undo before we reach
                     97:    the function prologue code for __do_global_ctors (directly below).
                     98:    For such systems, define the macro INIT_SECTION_PREAMBLE to
                     99:    expand into the code needed to undo the actions of the crti.o file.  */
                    100:    
                    101: #ifdef INIT_SECTION_PREAMBLE
                    102:   INIT_SECTION_PREAMBLE;
                    103: #endif
                    104: 
                    105: /* A routine to invoke all of the global constructors upon entry to the
                    106:    program.  We put this into the .init section (for systems that have
                    107:    such a thing) so that we can properly perform the construction of
                    108:    file-scope static-storage C++ objects within shared libraries.   */
                    109: 
                    110: static void
                    111: __do_global_ctors_aux ()       /* prologue goes in .init section */
                    112: {
                    113: #ifdef FORCE_INIT_SECTION_ALIGN
                    114:   FORCE_INIT_SECTION_ALIGN;    /* Explicit align before switch to .text */
                    115: #endif
                    116:   asm (TEXT_SECTION_ASM_OP);   /* don't put epilogue and body in .init */
                    117:   DO_GLOBAL_CTORS_BODY;
                    118:   ON_EXIT (__do_global_dtors, 0);
                    119: }
                    120: 
                    121: #endif /* defined(INIT_SECTION_ASM_OP) */
                    122: 
                    123: /* Force cc1 to switch to .data section.  */
                    124: static func_ptr force_to_data[0] = { };
                    125: 
                    126: /* The -1 is a flag to __do_global_[cd]tors
                    127:    indicating that this table does not start with a count of elements.  */
                    128: #ifdef CTOR_LIST_BEGIN
                    129: CTOR_LIST_BEGIN;
                    130: #else
                    131: asm (CTORS_SECTION_ASM_OP);    /* cc1 doesn't know that we are switching! */
                    132: func_ptr __CTOR_LIST__[1] = { (func_ptr) (-1) };
                    133: #endif
                    134: 
                    135: #ifdef DTOR_LIST_BEGIN
                    136: DTOR_LIST_BEGIN;
                    137: #else
                    138: asm (DTORS_SECTION_ASM_OP);    /* cc1 doesn't know that we are switching! */
                    139: func_ptr __DTOR_LIST__[1] = { (func_ptr) (-1) };
                    140: #endif
                    141: 
                    142: #endif /* defined(CRT_BEGIN) */
                    143: 
                    144: #ifdef CRT_END
                    145: 
                    146: #ifdef INIT_SECTION_ASM_OP
                    147: 
                    148: /* A routine to invoke all of the global constructors upon entry to the
                    149:    program.  We put this into the .init section (for systems that have
                    150:    such a thing) so that we can properly perform the construction of
                    151:    file-scope static-storage C++ objects within shared libraries.
                    152: 
                    153:    This must be virtually identical to the one above so that we can
                    154:    insure that the function prologue from the one above works correctly
                    155:    with the epilogue from this one.  (They will both go into the .init
                    156:    section as the first and last things (respectively) that the linker
                    157:    will put in that section.)
                    158: */
                    159: 
                    160: static void
                    161: __do_global_ctors_aux ()       /* prologue goes in .text section */
                    162: {
                    163:   asm (INIT_SECTION_ASM_OP);
                    164:   DO_GLOBAL_CTORS_BODY;
                    165:   ON_EXIT (__do_global_dtors, 0);
                    166: }                              /* epilogue and body go in .init section */
                    167: 
                    168: #endif /* defined(INIT_SECTION_ASM_OP) */
                    169: 
                    170: /* Force cc1 to switch to .data section.  */
                    171: static func_ptr force_to_data[0] = { };
                    172: 
                    173: #ifdef CTOR_LIST_END
                    174: CTOR_LIST_END;
                    175: #else
                    176: asm (CTORS_SECTION_ASM_OP);    /* cc1 doesn't know that we are switching! */
                    177: func_ptr __CTOR_END__[1] = { (func_ptr) 0 };
                    178: #endif
                    179: 
                    180: #ifdef DTOR_LIST_END
                    181: DTOR_LIST_END;
                    182: #else
                    183: asm (DTORS_SECTION_ASM_OP);    /* cc1 doesn't know that we are switching! */
                    184: func_ptr __DTOR_END__[1] = { (func_ptr) 0 };
                    185: #endif
                    186: 
                    187: #endif /* defined(CRT_END) */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.