To create a new test.c file in Linux, the source code is as follows:
1 #include <stdio.h>2int a=1; 3 int Main () 4 {5 printf ("A is%d. " , a); 6 return 0 ; 7 }
Then generate the TEST.O and test files separately
$ gcc-o test test.c
View TEST.O and test separately using the Objdump command
First Look at TEST.O
File format elf64-x86-64: The platform properties of the files, this is the 64-bit x86 processor platform
Sections:
Size: The length of the segment, in bytes
VMA: The position of the segment in the virtual address
LMA: The position of the segment in the load address
File off:file Offset, starting position of the segment
ALGN: Byte Alignment, 2**2 represents 2 squared is 4,2**3 means 2 of 3 is 8
It's important to have
. Text (Code snippet)
. Data (segment)
. BSS
To view the space location of the test file:
The number of segments is significantly greater than the unlinked files TEST.O
We copy the TEST.C code to the test1.c file and modify it slightly
You can see that both the. Text code snippet and the. Data segment size are increased,
. Text snippet increased by 9 bytes (22 to 31)
The. Data segment adds an int type 4-byte variable size (int b=2 in source code, one variable B)
Note that the file off starting position of data is 00000074, not 00000071, which is the result of byte alignment
Here's a question to answer:
Why does the. Text code snippet and. Data segment and other segments have byte alignment differently?
Use Objdump to view file space address distribution under Linux