section-selectors
Syntax
[section-selector[ ,section-selector... ] ]
section-selector is:
[section-attribute][section-type] [ sectionsection-name][ objectmodule-spec] [ pathfilepath] [ symbolsymbol-name]
section-attribute is:
ro [ code | data ] | rw [ code | data ] | zi
section-type is:
[ preinit_array | init_array ]
Parameters
| Only sections with the specified attribute will be selected.
In each category, sections can be further divided into those that contain code and those that contain data, resulting in four main categories:
|
| Only sections with that ELF section type will be selected.
|
| Only sections whose names match the
|
| Only sections that originate from library modules or object files that matches
Two wildcards are allowed:
|
| Selects all object files in a directory or library file.
For example, Using relative paths like |
| Only sections that define at least one public symbol that matches the symbol name pattern will be selected.
See the note below for a more detailed description. |
Description
A section selector selects all sections that match the section attribute, section type, symbol name, section name, and the name of the module. Up to four of the five conditions can be omitted.
It is also possible to use only { } without any section selectors, which can be useful when defining blocks.
Note
Like all section selectors, symbol selects sections, not symbols. If you specify the symbol __mySymbol, you select the section that contains the public symbol __mySymbol. If that section contains more public symbols, those will also be selected. If a section contains more than one public symbol, for instance symbA and symbB, you cannot select symbol symbA to one section selector and symbol symbB to another. A section can only match one section selector, and the match is case sensitive. Static symbols are not affected by this directive.
You can inspect the symbol table of object files with the command ielfdumparm -s .symtab file.o. The number of the containing section will be listed for each symbol. If two public symbols reside in the same section, they cannot be matched by two section selectors that use the two symbols—the single section must be matched by one section selector.
Which section a symbol resides in might change with the optimization level. The compiler uses an optimization called static clustering on optimization levels Medium and higher. Clustering typically places several data symbols in the same section, which typically reduces both the size and the execution time of the generated code. You can disable static clustering (using the compiler option ‑‑no_clustering) to get symbols into different sections (which allows you to match them individually with different symbol section selectors), but the generated code will typically be larger and slower.
Note
A section selector with narrower scope has higher priority than a more generic section selector. If more than one section selector matches for the same purpose, one of them must be more specific. A section selector is more specific than another one if in priority order:
It specifies a public symbol name with no wildcards and the other one does not.
It specifies a section name or object name with no wildcards and the other one does not
It specifies a section type and the other one does not
There could be sections that match the other selector that also match this one, however, the reverse is not true.
Selector 1 | Selector 2 | More specific |
|---|---|---|
|
| Selector 2 |
|
| Selector 1 |
|
| Selector 1 |
|
| Selector 1 |
|
| Neither |
|
| Selector 1 |
|
| Selector 1 |
|
| Neither |
Examples
{ rw } /* Selects all read-write sections */
{ section .mydata* } /* Selects only .mydata* sections */
/* Selects .mydata* sections available in the object special.o */
{ section .mydata* object special.o }Assuming a section in an object named foo.o in a library named lib.a, any of these selectors will select that section:
object foo.o(lib.a) object f*(lib*) object foo.o object lib.a
The path selector only works with actual files. To match against individual objects inside of a library, use the object selector or a combination of path/object. These examples both select member.o from library.a:
object member.o path "*/library.a" object member.o(library.a)
Wildcards do not treat directory separators in the file path as having a distinct meaning—"*/mp3player*.o" will also match "/mp3player/sub/dir/obj.o". If you need to, you can combine the path selector with the object selector, which only filters on the filename.
See also
initialize directive, do not initialize directive, and keep directive.