Programmer self-cultivation-target document

Source: Internet
Author: User

A little pitfall, just writtenArticle, Now I want to write it again.

 

In the previous blog, object files are generated, that is, the target file.

 

Different types of target files are available on different platforms. there is a popular PE (portable executable) in windows, and elf (executable linkable format) in Linux ). I only care about Linux.

For more information, see here. First, let's take a look at the ELF file type. First, let's look at the generated helloworld. o file type.

What does this mean? Slowly explain.

In the book, the author adds one:

 
Core dump file when a process stops unexpectedly, the system can dump some other information in the same address space of the process and at the time of termination to the core dump file.

Believe the information can refer to the link: http://en.wikipedia.org/wiki/Core_dump http://linux.die.net/man/5/core

 
The target file must be includedProgramThe link must be used for program execution. For convenience and efficiency, the target file format provides two parallel views.

 

The general ELF file includes three index tables: Elf header, program header table, and section header table. Elf header: at the beginning of the file, the road map is saved to describe the organization of the file. Program header table: tells the system how to create a process image. The target file used to construct the process image must have a program header table, which is not required for relocated files. Section header table: contains information about the description file section. Each section has an item in the Table. Each item provides information such as the section name and section size. The target file used for the link must contain the header table of the section. Other target files may or may not contain this table.

What is a section?

 

The following tool is used to analyze the information in helloworld. O.

The source code of the program is as follows:

 
# Include <stdio. h> # include <stdlib. h> static int global_test_var = 100; int main (INT ARGs, char ** argv) {static int Var = 20; printf ("% s \ n ", "self-cultivation of programmers! "); Return exit_success ;}

 

In. in the data section, 64000000, and F are four bytes in total, expressed in hexadecimal notation. 0x64 0x00 0x00 0x00, the conversion to binary is 100, that is, global_test_var in the source code,

The same is true for the later part of 14000000, that is, var.

 

Next let's take a look at the structure of the target file: (because there are many sections, only important sections are given ,)

 
In the. text section, program commands are saved, while program data is saved in data and. BSS.

Some explanations about the. BSS section:

 
The BSS segment is only used to reserve locations for uninitialized global variables and local static variables.

 

In addition, it is said in the book. rodata, that is, the read-only section, should store read-only data. In the test source code above, It outputs "Programmer self-cultivation! ", This string should be saved in the. rodata section.

 

In addition, the Section mentioned in many documents is the section in the book.

 

 

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.