SPARC Assembly Language Reference Manual

3.2 Sections

A section is the smallest unit of an object that can be relocated. The following sections are commonly present in an ELF file:

Sections do not need to be specified in any particular order. The current section is the section to which code is generated.

These sections contain all other information in an object file and satisfy several conditions.

  1. Every section must have one section header describing the section. However, a section header does not need to be followed by a section.

  2. Each section occupies one contiguous sequence of bytes within a file. The section may be empty (that is, of zero-length).

  3. A byte in a file can reside in only one section. Sections in a file cannot overlap.

  4. An object file may have inactive space. The contents of the data in the inactive space are unspecified.

Sections can be added for multiple text or data segments, shared data, user-defined sections, or information in the object file for debugging.


Note –

Not all of the sections need to be present.


3.2.1 Section Header

The section header allows you to locate all of the file sections. An entry in a section header table contains information characterizing the data in a section.

The section header contains the following information:


addr

Address at which the first byte resides if the section appears in the memory image of a process; the default value is 0.


addralign

Aligns the address if a section has an address alignment constraint; for example, if a section contains a double-word, the entire section must be ensured double-word alignment. Only 0 and positive integral powers of 2 are currently allowed. A value of 0 or 1 indicates no address alignment constraints.


entsize

Size in bytes for entries in fixed-size tables such as the symbol table.


flags

One-bit descriptions of section attributes. Table 3–2 describes the section attribute flags.

Table 3–2

Flag 

Default Value 

Description 

SHF_WRITE

0x1

Contains data that is writable during process execution. 

SHF_ALLOC

0x2

Occupies memory during process execution. This attribute is off if a control section does not reside in the memory image of the object file.

SHF_EXECINSTR

0x4

Contains executable machine instructions. 

SHF_MASKPROC

0xf0000000

Reserved for processor-specific semantics. 


info

Extra information. The interpretation of this information depends on the section type, as described in Table 3–3.


link

Section header table index link. The interpretation of this information depends on the section type, as described in Table 3–3.


name

Specifies the section name. An index into the section header string table section specifies the location of a null-terminated string.


offset

Specifies the byte offset from the beginning of the file to the first byte in the section.


Note –

If the section type is SHT_NOBITS, offset specifies the conceptual placement of the file.



size

Specifies the size of the section in bytes.


Note –

If the section type is SHT_NOBITS, size may be non-zero; however, the section still occupies no space in the file.



type

Categorizes the section contents and semantics. Table 3–3 describes the section types.

Table 3–3

Name 

 

Value 

 

Description 

 

Interpretation by 

info 

link 

null

0

Marks section header as inactive. 

 

 

progbits

1

Contains information defined explicitly by the program. 

 

 

symtab

2

Contains a symbol table for link editing. This table may also be used for dynamic linking; however, it may contain many unnecessary symbols. 

Note: Only one section of this type is allowed in a file

One greater than the symbol table index of the last local symbol. 

The section header index of the associated string table. 

strtab

3

Contains a string table. A file may have multiple string table sections. 

 

 

rela

4

Contains relocation entries with explicit addends. A file may have multiple relocation sections. 

The section header index of the section to which the relocation applies. 

The section header index of the associated symbol table. 

hash

5

Contains a symbol rehash table. 

Note: Only one section of this type is allowed in a file

The section header index of the symbol table to which the hash table applies. 

dynamic

6

Contains dynamic linking information. 

Note: Only one section of this type is allowed in a file

The section header index of the string table used by entries in the section. 

note

7

Contains information that marks the file. 

 

 

nobits

8

Contains information defined explicitly by the program; however, a section of this type does not occupy any space in the file. 

 

 

rel

9

Contains relocation entries without explicit addends. A file may have multiple relocation sections. 

The section header index of the section to which the relocation applies. 

The section header index of the associated symbol table. 

shlib

10

Reserved. 

 

 

dynsym

11

Contains a symbol table with a minimal set of symbols for dynamic linking.  

Note: Only one section of this type is allowed in a file

One greater than the symbol table index of the last local symbol. 

The section header index of the associated string table. 

loproc

hiproc

0x70000000

0x7fffffff

Lower and upper bound of range reserved for processor-specific semantics. 

 

 

louser

hiuser

0x80000000

0xffffffff

Lower and upper bound of range reserved for application programs. 

Note: Section types in this range may be used by an application without conflicting with system-defined section types.

 

 


Note –

Some section header table indexes are reserved and the object file will not contain sections for these special indexes.


3.2.2 Predefined User Sections

A section that can be manipulated by the section control directives is known as a user section. You can use the section control directives to change the user section in which code or data is generated. Table 3–4 lists the predefined user sections that can be named in the section control directives.

Table 3–4

Section Name  

Description 

.bss

Section contains uninitialized read-write data.  

.comment

Comment section.  

.data & .data1

Section contains initialized read-write data.  

.debug

Section contains debugging information.  

.fini

Section contains runtime finalization instructions.  

.init

Section contains runtime initialization instructions.  

.rodata & .rodata1

Section contains read-only data.  

.text

Section contains executable text.  

.line

Section contains line # info for symbolic debugging. 

.note

Section contains note information. 

3.2.2.1 Creating an .init Section in an Object File

The .init sections contain codes that are to be executed before the the main program is executed. To create an .init section in an object file, use the assembler pseudo-ops shown in Example 3–1.


Example 3–1 Creating an .init Section

.section ".init"

.align   4

<instructions>

At link time, the .init sections in a sequence of .o files are concatenated into an .init section in the linker output file. The code in the .init section are executed before the main program is executed.

Because the whole .init section is treated as a single function body, it is recommented that the only code added to these sections be in the following form:.

call routine_name

nop

The called routine should be located in another section. This will prevent conflicting register and stack usage within the .init sections.

3.2.2.2 Creating a .fini Section in an Object File

.fini sections contain codes that are to be executed after the the main program is executed. To create an .fini section in an object file, use the assembler pseudo-ops shown in Example 3–2.


Example 3–2 Creating an .fini Section

.section ".fini"

.align   4

<instructions>

At link time, the .fini sections in a sequence of .o files are concatenated into a .fini section in the linker output file. The codes in the .fini section are executed after the main program is executed.

Because the whole .fini section is treated as a single function body, it is recommended that the only code added to these section be in the following form:.

call routine_name

nop

The called routine should be located in another section. This will prevent conflicting register and stack usage within the .fini sections.

3.2.3 Predefined Non-User Sections

Table 3–5 lists sections that are predefined but cannot be named in the section control directives because they are not under user control.

Table 3–5

Section Name 

Description 

".dynamic"

Section contains dynamic linking information.  

.dynstr

Section contains strings needed for dynamic linking. 

.dynsym

Section contains the dynamic linking symbol table. 

.got

Section contains the global offset table. 

.hash

Section contains a symbol hash table. 

.interp

Section contains the path name of a program interpreter. 

.plt

Section contains the procedure linking table. 

.relname & .relaname

Section containing relocation information. name is the section to which the relocations apply, that is, ".rel.text", ".rela.text".

.shstrtab

String table for the section header table names.  

.strtab

Section contains the string table.  

.symtab

Section contains a symbol table.