I want to know the exact difference between two:
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
Note that this exist for others like .bss, .rodata .etc, what about them? I know .text is the code, .dada initialized variables ... and * is wildcard .I can see in arm-none-eabi-objdump that functions are in form of .text* format but I didn't find the reference to explain exactly them.
CodePudding user response:
*(.text)
will include only objects stored in the.text
segment.*(.text*)
will include only objects stored in the segment having.text
at the beginning of its name (* works like a wildcard).
It is especially important if the compiler places functions in its own sections to remove unused ones.
If you compile, asking the compiler to place functions in separate sections you will have for example .text.baseShouldLoadMeshGUI
section containing the baseShouldLoadMeshGUI
function.
It is needed if you want to discard unused functions as the ld
linker can only discard sections, not the particular functions from the sections.
Example:
.text.baseShouldLoadUpMesh
0x0000000000000000 0x4 ./Apps/G4-MC3/baseG4MC3.o
.text.baseShouldLoadMeshGUI
0x0000000000000000 0x4 ./Apps/G4-MC3/baseG4MC3.o
.text.baseTriggerUSBDStart
0x0000000000000000 0x94 ./Apps/G4-MC3/baseG4MC3.o
.text.GUI_ShowNewSkin
0x0000000000000000 0x54 ./Apps/G4-MC3/baseG4MC3.o
More detailed explanation:
-ffunction-sections instructs gcc to place each function (including static ones) in its own section named .text.function_name instead of placing all functions in one big .text section. At link time, ld normally coalesces all such sections into one output section .text again. It is achieved by having *(.text.*) spec along with *(.text) spec in built-in linker scripts.
-fdata-sections is analogous: it places each global or static variable into .data.variable_name, .rodata.variable_name or .bss.variable_name.
Segments names are implementation-defined, but the very common names:
.text
- code.rodata
- Read Only data.data
- initialized static storage data.bss
- not initialized static storage data