www.delorie.com/gnu/docs/gcc/gccint_142.html   search  
 
Buy the book!


GNU Compiler Collection (GCC) Internals

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

10.18 Dividing the Output into Sections (Texts, Data, ...)

An object file is divided into sections containing different types of data. In the most common case, there are three sections: the text section, which holds instructions and read-only data; the data section, which holds initialized writable data; and the bss section, which holds uninitialized data. Some systems have other kinds of sections.

The compiler must tell the assembler when to switch sections. These macros control what commands to output to tell the assembler this. You can also define additional sections.

TEXT_SECTION_ASM_OP
A C expression whose value is a string, including spacing, containing the assembler operation that should precede instructions and read-only data. Normally "\t.text" is right.

TEXT_SECTION
A C statement that switches to the default section containing instructions. Normally this is not needed, as simply defining TEXT_SECTION_ASM_OP is enough. The MIPS port uses this to sort all functions after all data declarations.

DATA_SECTION_ASM_OP
A C expression whose value is a string, including spacing, containing the assembler operation to identify the following data as writable initialized data. Normally "\t.data" is right.

SHARED_SECTION_ASM_OP
If defined, a C expression whose value is a string, including spacing, containing the assembler operation to identify the following data as shared data. If not defined, DATA_SECTION_ASM_OP will be used.

BSS_SECTION_ASM_OP
If defined, a C expression whose value is a string, including spacing, containing the assembler operation to identify the following data as uninitialized global data. If not defined, and neither ASM_OUTPUT_BSS nor ASM_OUTPUT_ALIGNED_BSS are defined, uninitialized global data will be output in the data section if `-fno-common' is passed, otherwise ASM_OUTPUT_COMMON will be used.

SHARED_BSS_SECTION_ASM_OP
If defined, a C expression whose value is a string, including spacing, containing the assembler operation to identify the following data as uninitialized global shared data. If not defined, and BSS_SECTION_ASM_OP is, the latter will be used.

INIT_SECTION_ASM_OP
If defined, a C expression whose value is a string, including spacing, containing the assembler operation to identify the following data as initialization code. If not defined, GCC will assume such a section does not exist.

FINI_SECTION_ASM_OP
If defined, a C expression whose value is a string, including spacing, containing the assembler operation to identify the following data as finalization code. If not defined, GCC will assume such a section does not exist.

CRT_CALL_STATIC_FUNCTION (section_op, function)
If defined, an ASM statement that switches to a different section via section_op, calls function, and switches back to the text section. This is used in `crtstuff.c' if INIT_SECTION_ASM_OP or FINI_SECTION_ASM_OP to calls to initialization and finalization functions from the init and fini sections. By default, this macro uses a simple function call. Some ports need hand-crafted assembly code to avoid dependencies on registers initialized in the function prologue or to ensure that constant pools don't end up too far way in the text section.

FORCE_CODE_SECTION_ALIGN
If defined, an ASM statement that aligns a code section to some arbitrary boundary. This is used to force all fragments of the .init and .fini sections to have to same alignment and thus prevent the linker from having to add any padding.

EXTRA_SECTIONS
A list of names for sections other than the standard two, which are in_text and in_data. You need not define this macro on a system with no other sections (that GCC needs to use).

EXTRA_SECTION_FUNCTIONS
One or more functions to be defined in `varasm.c'. These functions should do jobs analogous to those of text_section and data_section, for your additional sections. Do not define this macro if you do not define EXTRA_SECTIONS.

READONLY_DATA_SECTION
On most machines, read-only variables, constants, and jump tables are placed in the text section. If this is not the case on your machine, this macro should be defined to be the name of a function (either data_section or a function defined in EXTRA_SECTIONS) that switches to the section to be used for read-only items.

If these items should be placed in the text section, this macro should not be defined.

SELECT_SECTION (exp, reloc, align)
A C statement or statements to switch to the appropriate section for output of exp. You can assume that exp is either a VAR_DECL node or a constant of some sort. reloc indicates whether the initial value of exp requires link-time relocations. Bit 1 is set when variable contains local relocations only, while bit 2 is set for global relocations. Select the section by calling text_section or one of the alternatives for other sections. align is the constant alignment in bits.

Do not define this macro if you put all read-only variables and constants in the read-only data section (usually the text section).

SELECT_RTX_SECTION (mode, rtx, align)
A C statement or statements to switch to the appropriate section for output of rtx in mode mode. You can assume that rtx is some kind of constant in RTL. The argument mode is redundant except in the case of a const_int rtx. Select the section by calling text_section or one of the alternatives for other sections. align is the constant alignment in bits.

Do not define this macro if you put all constants in the read-only data section.

JUMP_TABLES_IN_TEXT_SECTION
Define this macro to be an expression with a nonzero value if jump tables (for tablejump insns) should be output in the text section, along with the assembler instructions. Otherwise, the readonly data section is used.

This macro is irrelevant if there is no separate readonly data section.

ENCODE_SECTION_INFO (decl)
Define this macro if references to a symbol or a constant must be treated differently depending on something about the variable or function named by the symbol (such as what section it is in).

The macro definition, if any, is executed under two circumstances. One is immediately after the rtl for decl that represents a variable or a function has been created and stored in DECL_RTL (decl). The value of the rtl will be a mem whose address is a symbol_ref. The other is immediately after the rtl for decl that represents a constant has been created and stored in TREE_CST_RTL (decl). The macro is called once for each distinct constant in a source file.

The usual thing for this macro to do is to record a flag in the symbol_ref (such as SYMBOL_REF_FLAG) or to store a modified name string in the symbol_ref (if one bit is not enough information).

STRIP_NAME_ENCODING (var, sym_name)
Decode sym_name and store the real name part in var, sans the characters that encode section info. Define this macro if ENCODE_SECTION_INFO alters the symbol's name string.

UNIQUE_SECTION (decl, reloc)
A C statement to build up a unique section name, expressed as a STRING_CST node, and assign it to `DECL_SECTION_NAME (decl)'. reloc indicates whether the initial value of exp requires link-time relocations. If you do not define this macro, GCC will use the symbol name prefixed by `.' as the section name. Note - this macro can now be called for uninitialized data items as well as initialized data and functions.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003