]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/doc/gccint/target-macros/defining-the-output-assembler-language/macros-controlling-initialization-routines.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / doc / gccint / target-macros / defining-the-output-assembler-language / macros-controlling-initialization-routines.rst
CommitLineData
c63539ff
ML
1..
2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
5
6.. _macros-for-initialization:
7
8Macros Controlling Initialization Routines
9^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10
11Here are the macros that control how the compiler handles initialization
12and termination functions:
13
14.. c:macro:: INIT_SECTION_ASM_OP
15
16 If defined, a C string constant, including spacing, for the assembler
17 operation to identify the following data as initialization code. If not
18 defined, GCC will assume such a section does not exist. When you are
19 using special sections for initialization and termination functions, this
20 macro also controls how :samp:`crtstuff.c` and :samp:`libgcc2.c` arrange to
21 run the initialization functions.
22
23.. c:macro:: HAS_INIT_SECTION
24
25 If defined, ``main`` will not call ``__main`` as described above.
26 This macro should be defined for systems that control start-up code
27 on a symbol-by-symbol basis, such as OSF/1, and should not
28 be defined explicitly for systems that support ``INIT_SECTION_ASM_OP``.
29
30.. c:macro:: LD_INIT_SWITCH
31
32 If defined, a C string constant for a switch that tells the linker that
33 the following symbol is an initialization routine.
34
35.. c:macro:: LD_FINI_SWITCH
36
37 If defined, a C string constant for a switch that tells the linker that
38 the following symbol is a finalization routine.
39
40.. c:macro:: COLLECT_SHARED_INIT_FUNC (stream, func)
41
42 If defined, a C statement that will write a function that can be
43 automatically called when a shared library is loaded. The function
44 should call :samp:`{func}`, which takes no arguments. If not defined, and
45 the object format requires an explicit initialization function, then a
46 function called ``_GLOBAL__DI`` will be generated.
47
48 This function and the following one are used by collect2 when linking a
49 shared library that needs constructors or destructors, or has DWARF2
50 exception tables embedded in the code.
51
52.. c:macro:: COLLECT_SHARED_FINI_FUNC (stream, func)
53
54 If defined, a C statement that will write a function that can be
55 automatically called when a shared library is unloaded. The function
56 should call :samp:`{func}`, which takes no arguments. If not defined, and
57 the object format requires an explicit finalization function, then a
58 function called ``_GLOBAL__DD`` will be generated.
59
60.. c:macro:: INVOKE__main
61
62 If defined, ``main`` will call ``__main`` despite the presence of
63 ``INIT_SECTION_ASM_OP``. This macro should be defined for systems
64 where the init section is not actually run automatically, but is still
65 useful for collecting the lists of constructors and destructors.
66
67.. c:macro:: SUPPORTS_INIT_PRIORITY
68
69 If nonzero, the C++ ``init_priority`` attribute is supported and the
70 compiler should emit instructions to control the order of initialization
71 of objects. If zero, the compiler will issue an error message upon
72 encountering an ``init_priority`` attribute.
73
8f2b513c
ML
74.. include:: ../tm.rst.in
75 :start-after: [TARGET_HAVE_CTORS_DTORS]
76 :end-before: [TARGET_HAVE_CTORS_DTORS]
c63539ff 77
c63539ff 78
8f2b513c
ML
79.. include:: ../tm.rst.in
80 :start-after: [TARGET_DTORS_FROM_CXA_ATEXIT]
81 :end-before: [TARGET_DTORS_FROM_CXA_ATEXIT]
c63539ff 82
c63539ff 83
8f2b513c
ML
84.. include:: ../tm.rst.in
85 :start-after: [TARGET_ASM_CONSTRUCTOR]
86 :end-before: [TARGET_ASM_CONSTRUCTOR]
c63539ff 87
c63539ff 88
8f2b513c
ML
89.. include:: ../tm.rst.in
90 :start-after: [TARGET_ASM_DESTRUCTOR]
91 :end-before: [TARGET_ASM_DESTRUCTOR]
c63539ff 92
c63539ff
ML
93
94If ``TARGET_HAVE_CTORS_DTORS`` is true, the initialization routine
95generated for the generated object file will have static linkage.
96
97If your system uses :command:`collect2` as the means of processing
98constructors, then that program normally uses :command:`nm` to scan
99an object file for constructor functions to be called.
100
101On certain kinds of systems, you can define this macro to make
102:command:`collect2` work faster (and, in some cases, make it work at all):
103
104.. c:macro:: OBJECT_FORMAT_COFF
105
106 Define this macro if the system uses COFF (Common Object File Format)
107 object files, so that :command:`collect2` can assume this format and scan
108 object files directly for dynamic constructor/destructor functions.
109
110 This macro is effective only in a native compiler; :command:`collect2` as
111 part of a cross compiler always uses :command:`nm` for the target machine.
112
113.. c:macro:: REAL_NM_FILE_NAME
114
115 Define this macro as a C string constant containing the file name to use
116 to execute :command:`nm`. The default is to search the path normally for
117 :command:`nm`.
118
119.. c:macro:: NM_FLAGS
120
121 :command:`collect2` calls :command:`nm` to scan object files for static
122 constructors and destructors and LTO info. By default, :option:`-n` is
123 passed. Define ``NM_FLAGS`` to a C string constant if other options
124 are needed to get the same output format as GNU :command:`nm -n`
125 produces.
126
127If your system supports shared libraries and has a program to list the
128dynamic dependencies of a given library or executable, you can define
129these macros to enable support for running initialization and
130termination functions in shared libraries:
131
132.. c:macro:: LDD_SUFFIX
133
134 Define this macro to a C string constant containing the name of the program
135 which lists dynamic dependencies, like :command:`ldd` under SunOS 4.
136
137.. c:macro:: PARSE_LDD_OUTPUT (ptr)
138
139 Define this macro to be C code that extracts filenames from the output
140 of the program denoted by ``LDD_SUFFIX``. :samp:`{ptr}` is a variable
141 of type ``char *`` that points to the beginning of a line of output
142 from ``LDD_SUFFIX``. If the line lists a dynamic dependency, the
143 code must advance :samp:`{ptr}` to the beginning of the filename on that
144 line. Otherwise, it must set :samp:`{ptr}` to ``NULL``.
145
146.. c:macro:: SHLIB_SUFFIX
147
148 Define this macro to a C string constant containing the default shared
149 library extension of the target (e.g., :samp:`".so"`). :command:`collect2`
150 strips version information after this suffix when generating global
151 constructor and destructor names. This define is only needed on targets
3ed1b4ce 152 that use :command:`collect2` to process constructors and destructors.