Macros Controlling Initialization Routines. GNU GCC
Advertentie
Advertentie
Chapter 13: Target Description Macros and Functions 353 of a section together, which results in a complete __init function that invokes the routines we need at startup.
To use this variant, you must define the INIT_SECTION_ASM_OP macro properly.
If no init section is available, when GCC compiles any function called main (or more accurately, any function designated as a program entry point by the language front end calling expand_main_function), it inserts a procedure call to __main as the first executable code after the function prologue. The __main function is defined in ‘libgcc2.c’ and runs the global constructors.
In file formats that don’t support arbitrary sections, there are again two variants. In the simplest variant, the GNU linker (GNU ld) and an ‘a.out’ format must be used. In this case, TARGET_ASM_CONSTRUCTOR is defined to produce a .stabs entry of type ‘N_SETT’, referencing the name __CTOR_LIST__, and with the address of the void function containing the initialization code as its value. The GNU linker recognizes this as a request to add the value to a set; the values are accumulated, and are eventually placed in the executable as a vector in the format described above, with a leading (ignored) count and a trailing zero element. TARGET_ASM_DESTRUCTOR is handled similarly. Since no init section is available, the absence of INIT_SECTION_ASM_OP causes the compilation of main to call __main as above, starting the initialization process.
The last variant uses neither arbitrary sections nor the GNU linker. This is preferable when you want to do dynamic linking and when using file formats which the GNU linker does not support, such as ‘ECOFF’. In this case, TARGET_HAVE_CTORS_DTORS is false, initialization and termination functions are recognized simply by their names. This requires an extra program in the linkage step, called collect2. This program pretends to be the linker, for use with GCC; it does its job by running the ordinary linker, but also arranges to include the vectors of initialization and termination functions. These functions are called via __main as described above. In order to use this method, use_collect2 must be defined in the target in ‘config.gcc’.
13.19.6 Macros Controlling Initialization Routines
Here are the macros that control how the compiler handles initialization and termination functions:
INIT_SECTION_ASM_OP
[Macro]
If defined, a C string constant, including spacing, for the assembler operation to identify the following data as initialization code. If not defined, GCC will assume such a section does not exist. When you are using special sections for initialization and termination functions, this macro also controls how ‘crtstuff.c’ and ‘libgcc2.c’ arrange to run the initialization functions.
HAS_INIT_SECTION
[Macro]
If defined, main will not call __main as described above. This macro should be defined for systems that control start-up code on a symbol-by-symbol basis, such as OSF/1, and should not be defined explicitly for systems that support INIT_SECTION_ASM_OP.
LD_INIT_SWITCH
[Macro]
If defined, a C string constant for a switch that tells the linker that the following symbol is an initialization routine.
354 GNU Compiler Collection (GCC) Internals
LD_FINI_SWITCH
[Macro]
If defined, a C string constant for a switch that tells the linker that the following symbol is a finalization routine.
COLLECT_SHARED_INIT_FUNC
(
stream
,
func
) [Macro]
If defined, a C statement that will write a function that can be automatically called when a shared library is loaded. The function should call func, which takes no arguments. If not defined, and the object format requires an explicit initialization function, then a function called _GLOBAL__DI will be generated.
This function and the following one are used by collect2 when linking a shared library that needs constructors or destructors, or has DWARF2 exception tables embedded in the code.
COLLECT_SHARED_FINI_FUNC
(
stream
,
func
) [Macro]
If defined, a C statement that will write a function that can be automatically called when a shared library is unloaded. The function should call func, which takes no arguments. If not defined, and the object format requires an explicit finalization function, then a function called _GLOBAL__DD will be generated.
INVOKE__main
[Macro]
If defined, main will call __main despite the presence of INIT_SECTION_ASM_OP. This macro should be defined for systems where the init section is not actually run automatically, but is still useful for collecting the lists of constructors and destructors.
SUPPORTS_INIT_PRIORITY
[Macro]
If nonzero, the C++ init_priority attribute is supported and the compiler should emit instructions to control the order of initialization of objects. If zero, the compiler will issue an error message upon encountering an init_priority attribute.
bool TARGET_HAVE_CTORS_DTORS
[Target Hook]
This value is true if the target supports some “native” method of collecting constructors and destructors to be run at startup and exit. It is false if we must use collect2
.
void TARGET_ASM_CONSTRUCTOR
(rtx
symbol
, int
priority
) [Target Hook]
If defined, a function that outputs assembler code to arrange to call the function referenced by symbol at initialization time.
Assume that symbol is a SYMBOL_REF for a function taking no arguments and with no return value. If the target supports initialization priorities, priority is a value between 0 and MAX_INIT_PRIORITY; otherwise it must be DEFAULT_INIT_PRIORITY.
If this macro is not defined by the target, a suitable default will be chosen if (1) the target supports arbitrary section names, (2) the target defines CTORS_SECTION_ASM_
OP
, or (3) USE_COLLECT2 is not defined.
void TARGET_ASM_DESTRUCTOR
(rtx
symbol
, int
priority
) [Target Hook]
This is like TARGET_ASM_CONSTRUCTOR but used for termination functions rather than initialization functions.
Downloaden
Advertentie