gccint: Sections
1
1 18.18 Dividing the Output into Sections (Texts, Data, ...)
1 ==========================================================
1
1 An object file is divided into sections containing different types of
1 data. In the most common case, there are three sections: the "text
1 section", which holds instructions and read-only data; the "data
1 section", which holds initialized writable data; and the "bss section",
1 which holds uninitialized data. Some systems have other kinds of
1 sections.
1
1 'varasm.c' provides several well-known sections, such as
1 'text_section', 'data_section' and 'bss_section'. The normal way of
1 controlling a 'FOO_section' variable is to define the associated
1 'FOO_SECTION_ASM_OP' macro, as described below. The macros are only
1 read once, when 'varasm.c' initializes itself, so their values must be
1 run-time constants. They may however depend on command-line flags.
1
1 _Note:_ Some run-time files, such 'crtstuff.c', also make use of the
1 'FOO_SECTION_ASM_OP' macros, and expect them to be string literals.
1
1 Some assemblers require a different string to be written every time a
1 section is selected. If your assembler falls into this category, you
1 should define the 'TARGET_ASM_INIT_SECTIONS' hook and use
1 'get_unnamed_section' to set up the sections.
1
1 You must always create a 'text_section', either by defining
1 'TEXT_SECTION_ASM_OP' or by initializing 'text_section' in
1 'TARGET_ASM_INIT_SECTIONS'. The same is true of 'data_section' and
1 'DATA_SECTION_ASM_OP'. If you do not create a distinct
1 'readonly_data_section', the default is to reuse 'text_section'.
1
1 All the other 'varasm.c' sections are optional, and are null if the
1 target does not provide them.
1
1 -- Macro: TEXT_SECTION_ASM_OP
1 A C expression whose value is a string, including spacing,
1 containing the assembler operation that should precede instructions
1 and read-only data. Normally '"\t.text"' is right.
1
1 -- Macro: HOT_TEXT_SECTION_NAME
1 If defined, a C string constant for the name of the section
1 containing most frequently executed functions of the program. If
1 not defined, GCC will provide a default definition if the target
1 supports named sections.
1
1 -- Macro: UNLIKELY_EXECUTED_TEXT_SECTION_NAME
1 If defined, a C string constant for the name of the section
1 containing unlikely executed functions in the program.
1
1 -- Macro: DATA_SECTION_ASM_OP
1 A C expression whose value is a string, including spacing,
1 containing the assembler operation to identify the following data
1 as writable initialized data. Normally '"\t.data"' is right.
1
1 -- Macro: SDATA_SECTION_ASM_OP
1 If defined, a C expression whose value is a string, including
1 spacing, containing the assembler operation to identify the
1 following data as initialized, writable small data.
1
1 -- Macro: READONLY_DATA_SECTION_ASM_OP
1 A C expression whose value is a string, including spacing,
1 containing the assembler operation to identify the following data
1 as read-only initialized data.
1
1 -- Macro: BSS_SECTION_ASM_OP
1 If defined, a C expression whose value is a string, including
1 spacing, containing the assembler operation to identify the
1 following data as uninitialized global data. If not defined, and
1 'ASM_OUTPUT_ALIGNED_BSS' not defined, uninitialized global data
1 will be output in the data section if '-fno-common' is passed,
1 otherwise 'ASM_OUTPUT_COMMON' will be used.
1
1 -- Macro: SBSS_SECTION_ASM_OP
1 If defined, a C expression whose value is a string, including
1 spacing, containing the assembler operation to identify the
1 following data as uninitialized, writable small data.
1
1 -- Macro: TLS_COMMON_ASM_OP
1 If defined, a C expression whose value is a string containing the
1 assembler operation to identify the following data as thread-local
1 common data. The default is '".tls_common"'.
1
1 -- Macro: TLS_SECTION_ASM_FLAG
1 If defined, a C expression whose value is a character constant
1 containing the flag used to mark a section as a TLS section. The
1 default is ''T''.
1
1 -- Macro: INIT_SECTION_ASM_OP
1 If defined, a C expression whose value is a string, including
1 spacing, containing the assembler operation to identify the
1 following data as initialization code. If not defined, GCC will
1 assume such a section does not exist. This section has no
1 corresponding 'init_section' variable; it is used entirely in
1 runtime code.
1
1 -- Macro: FINI_SECTION_ASM_OP
1 If defined, a C expression whose value is a string, including
1 spacing, containing the assembler operation to identify the
1 following data as finalization code. If not defined, GCC will
1 assume such a section does not exist. This section has no
1 corresponding 'fini_section' variable; it is used entirely in
1 runtime code.
1
1 -- Macro: INIT_ARRAY_SECTION_ASM_OP
1 If defined, a C expression whose value is a string, including
1 spacing, containing the assembler operation to identify the
1 following data as part of the '.init_array' (or equivalent)
1 section. If not defined, GCC will assume such a section does not
1 exist. Do not define both this macro and 'INIT_SECTION_ASM_OP'.
1
1 -- Macro: FINI_ARRAY_SECTION_ASM_OP
1 If defined, a C expression whose value is a string, including
1 spacing, containing the assembler operation to identify the
1 following data as part of the '.fini_array' (or equivalent)
1 section. If not defined, GCC will assume such a section does not
1 exist. Do not define both this macro and 'FINI_SECTION_ASM_OP'.
1
1 -- Macro: MACH_DEP_SECTION_ASM_FLAG
1 If defined, a C expression whose value is a character constant
1 containing the flag used to mark a machine-dependent section. This
1 corresponds to the 'SECTION_MACH_DEP' section flag.
1
1 -- Macro: CRT_CALL_STATIC_FUNCTION (SECTION_OP, FUNCTION)
1 If defined, an ASM statement that switches to a different section
1 via SECTION_OP, calls FUNCTION, and switches back to the text
1 section. This is used in 'crtstuff.c' if 'INIT_SECTION_ASM_OP' or
1 'FINI_SECTION_ASM_OP' to calls to initialization and finalization
1 functions from the init and fini sections. By default, this macro
1 uses a simple function call. Some ports need hand-crafted assembly
1 code to avoid dependencies on registers initialized in the function
1 prologue or to ensure that constant pools don't end up too far way
1 in the text section.
1
1 -- Macro: TARGET_LIBGCC_SDATA_SECTION
1 If defined, a string which names the section into which small
1 variables defined in crtstuff and libgcc should go. This is useful
1 when the target has options for optimizing access to small data,
1 and you want the crtstuff and libgcc routines to be conservative in
1 what they expect of your application yet liberal in what your
1 application expects. For example, for targets with a '.sdata'
1 section (like MIPS), you could compile crtstuff with '-G 0' so that
1 it doesn't require small data support from your application, but
1 use this macro to put small data into '.sdata' so that your
1 application can access these variables whether it uses small data
1 or not.
1
1 -- Macro: FORCE_CODE_SECTION_ALIGN
1 If defined, an ASM statement that aligns a code section to some
1 arbitrary boundary. This is used to force all fragments of the
1 '.init' and '.fini' sections to have to same alignment and thus
1 prevent the linker from having to add any padding.
1
1 -- Macro: JUMP_TABLES_IN_TEXT_SECTION
1 Define this macro to be an expression with a nonzero value if jump
1 tables (for 'tablejump' insns) should be output in the text
1 section, along with the assembler instructions. Otherwise, the
1 readonly data section is used.
1
1 This macro is irrelevant if there is no separate readonly data
1 section.
1
1 -- Target Hook: void TARGET_ASM_INIT_SECTIONS (void)
1 Define this hook if you need to do something special to set up the
1 'varasm.c' sections, or if your target has some special sections of
1 its own that you need to create.
1
1 GCC calls this hook after processing the command line, but before
1 writing any assembly code, and before calling any of the
1 section-returning hooks described below.
1
1 -- Target Hook: int TARGET_ASM_RELOC_RW_MASK (void)
1 Return a mask describing how relocations should be treated when
1 selecting sections. Bit 1 should be set if global relocations
1 should be placed in a read-write section; bit 0 should be set if
1 local relocations should be placed in a read-write section.
1
1 The default version of this function returns 3 when '-fpic' is in
1 effect, and 0 otherwise. The hook is typically redefined when the
1 target cannot support (some kinds of) dynamic relocations in
1 read-only sections even in executables.
1
1 -- Target Hook: section * TARGET_ASM_SELECT_SECTION (tree EXP, int
1 RELOC, unsigned HOST_WIDE_INT ALIGN)
1 Return the section into which EXP should be placed. You can assume
1 that EXP is either a 'VAR_DECL' node or a constant of some sort.
1 RELOC indicates whether the initial value of EXP requires link-time
1 relocations. Bit 0 is set when variable contains local relocations
1 only, while bit 1 is set for global relocations. ALIGN is the
1 constant alignment in bits.
1
1 The default version of this function takes care of putting
1 read-only variables in 'readonly_data_section'.
1
1 See also USE_SELECT_SECTION_FOR_FUNCTIONS.
1
1 -- Macro: USE_SELECT_SECTION_FOR_FUNCTIONS
1 Define this macro if you wish TARGET_ASM_SELECT_SECTION to be
1 called for 'FUNCTION_DECL's as well as for variables and constants.
1
1 In the case of a 'FUNCTION_DECL', RELOC will be zero if the
1 function has been determined to be likely to be called, and nonzero
1 if it is unlikely to be called.
1
1 -- Target Hook: void TARGET_ASM_UNIQUE_SECTION (tree DECL, int RELOC)
1 Build up a unique section name, expressed as a 'STRING_CST' node,
1 and assign it to 'DECL_SECTION_NAME (DECL)'. As with
1 'TARGET_ASM_SELECT_SECTION', RELOC indicates whether the initial
1 value of EXP requires link-time relocations.
1
1 The default version of this function appends the symbol name to the
1 ELF section name that would normally be used for the symbol. For
1 example, the function 'foo' would be placed in '.text.foo'.
1 Whatever the actual target object format, this is often good
1 enough.
1
1 -- Target Hook: section * TARGET_ASM_FUNCTION_RODATA_SECTION (tree
1 DECL)
1 Return the readonly data section associated with 'DECL_SECTION_NAME
1 (DECL)'. The default version of this function selects
1 '.gnu.linkonce.r.name' if the function's section is
1 '.gnu.linkonce.t.name', '.rodata.name' if function is in
1 '.text.name', and the normal readonly-data section otherwise.
1
1 -- Target Hook: const char * TARGET_ASM_MERGEABLE_RODATA_PREFIX
1 Usually, the compiler uses the prefix '".rodata"' to construct
1 section names for mergeable constant data. Define this macro to
1 override the string if a different section name should be used.
1
1 -- Target Hook: section * TARGET_ASM_TM_CLONE_TABLE_SECTION (void)
1 Return the section that should be used for transactional memory
1 clone tables.
1
1 -- Target Hook: section * TARGET_ASM_SELECT_RTX_SECTION (machine_mode
1 MODE, rtx X, unsigned HOST_WIDE_INT ALIGN)
1 Return the section into which a constant X, of mode MODE, should be
1 placed. You can assume that X is some kind of constant in RTL.
1 The argument MODE is redundant except in the case of a 'const_int'
1 rtx. ALIGN is the constant alignment in bits.
1
1 The default version of this function takes care of putting symbolic
1 constants in 'flag_pic' mode in 'data_section' and everything else
1 in 'readonly_data_section'.
1
1 -- Target Hook: tree TARGET_MANGLE_DECL_ASSEMBLER_NAME (tree DECL, tree
1 ID)
1 Define this hook if you need to postprocess the assembler name
1 generated by target-independent code. The ID provided to this hook
1 will be the computed name (e.g., the macro 'DECL_NAME' of the DECL
1 in C, or the mangled name of the DECL in C++). The return value of
1 the hook is an 'IDENTIFIER_NODE' for the appropriate mangled name
1 on your target system. The default implementation of this hook
1 just returns the ID provided.
1
1 -- Target Hook: void TARGET_ENCODE_SECTION_INFO (tree DECL, rtx RTL,
1 int NEW_DECL_P)
1 Define this hook if references to a symbol or a constant must be
1 treated differently depending on something about the variable or
1 function named by the symbol (such as what section it is in).
1
1 The hook is executed immediately after rtl has been created for
1 DECL, which may be a variable or function declaration or an entry
1 in the constant pool. In either case, RTL is the rtl in question.
1 Do _not_ use 'DECL_RTL (DECL)' in this hook; that field may not
1 have been initialized yet.
1
1 In the case of a constant, it is safe to assume that the rtl is a
1 'mem' whose address is a 'symbol_ref'. Most decls will also have
1 this form, but that is not guaranteed. Global register variables,
1 for instance, will have a 'reg' for their rtl. (Normally the right
1 thing to do with such unusual rtl is leave it alone.)
1
1 The NEW_DECL_P argument will be true if this is the first time that
1 'TARGET_ENCODE_SECTION_INFO' has been invoked on this decl. It
1 will be false for subsequent invocations, which will happen for
1 duplicate declarations. Whether or not anything must be done for
1 the duplicate declaration depends on whether the hook examines
1 'DECL_ATTRIBUTES'. NEW_DECL_P is always true when the hook is
1 called for a constant.
1
1 The usual thing for this hook to do is to record flags in the
1 'symbol_ref', using 'SYMBOL_REF_FLAG' or 'SYMBOL_REF_FLAGS'.
1 Historically, the name string was modified if it was necessary to
1 encode more than one bit of information, but this practice is now
1 discouraged; use 'SYMBOL_REF_FLAGS'.
1
1 The default definition of this hook, 'default_encode_section_info'
1 in 'varasm.c', sets a number of commonly-useful bits in
1 'SYMBOL_REF_FLAGS'. Check whether the default does what you need
1 before overriding it.
1
1 -- Target Hook: const char * TARGET_STRIP_NAME_ENCODING (const char
1 *NAME)
1 Decode NAME and return the real name part, sans the characters that
1 'TARGET_ENCODE_SECTION_INFO' may have added.
1
1 -- Target Hook: bool TARGET_IN_SMALL_DATA_P (const_tree EXP)
1 Returns true if EXP should be placed into a "small data" section.
1 The default version of this hook always returns false.
1
1 -- Target Hook: bool TARGET_HAVE_SRODATA_SECTION
1 Contains the value true if the target places read-only "small data"
1 into a separate section. The default value is false.
1
1 -- Target Hook: bool TARGET_PROFILE_BEFORE_PROLOGUE (void)
1 It returns true if target wants profile code emitted before
1 prologue.
1
1 The default version of this hook use the target macro
1 'PROFILE_BEFORE_PROLOGUE'.
1
1 -- Target Hook: bool TARGET_BINDS_LOCAL_P (const_tree EXP)
1 Returns true if EXP names an object for which name resolution rules
1 must resolve to the current "module" (dynamic shared library or
1 executable image).
1
1 The default version of this hook implements the name resolution
1 rules for ELF, which has a looser model of global name binding than
1 other currently supported object file formats.
1
1 -- Target Hook: bool TARGET_HAVE_TLS
1 Contains the value true if the target supports thread-local
1 storage. The default value is false.
1