Code Segments
A few bits of information on code segments and linking.
Note: This HowTo uses Xilinx EDK version 9.1i
Code Segments
Below is a list of some of the code segments that GCC can produce with descriptions of their purpose.
Segments | Description |
---|---|
.text | Program code |
.data | Initialised global data |
.sdata | Small .data |
.bss | Uninitialised global data (Block Starting Symbol) |
.sbss | Small .bss |
.rodata | Constants (Read only data) |
.sdata2 | Small read only data |
Below is an example taken from the Xilinx application note xapp642
. It shows how different variables relate to code
segments.
File:
example.c
#include <stdio.h> |
|
int array_data[10] = {0,1,2,3,4,5,6,7,8,9}; |
⇐ .data |
const int array_const[10] = {9,8,7,6,5,4,3,2,1,0}; |
⇐ .rodata |
int main(void) |
|
{ |
|
int i; |
⇐ .bss |
i = i + 10; |
⇐ .text |
printf("%d\n", array_data[0]); |
⇐ .text |
array_data[0] = array_const[0]; |
⇐ .text |
printf("%d\n",array_data[0]); |
⇐ .text |
return 0; |
|
} |
Further Reading
Suggestions for further reading.
- Xilinx
xapp642
- Relocating Code and Data for Embedded Systems