Use Objdump to view file space address distribution under Linux

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.