A. Out elf PE coff

Source: Internet
Author: User
A. Out

A. out is the abbreviation of "worker er output", which represents the output of the assembler. In earlier versions of Unix-like systems, A. out is an output format used for executable files, target files, and shared libraries. There was no linker on the early PDP-7 system, and the process of creating a program was to first connect all the source files into a file, then assemble, and the resulting assembler is saved in A. Out. A. out is a veritable Assembly output, but after the PDP-11, people write the linker for it, the creation of the program is first compiled and then the link output is saved to. out, then. out is actually a link output, but the output Executable File continues this naming convention.

The standard A. out file contains seven sections in the following format:

Exec header (Execution header | file header)

Text Segment)

Data Segment)

Text relocations (text relocation segment)

Data relocations (Data relocation segment)

Data relocations (Data relocation segment)

String table (string table)

Struct exec {

Unsigned long a_midmag;/* magic number and other information */

Unsigned long a_text;/* length of the text segment */

Unsigned long a_data;/* data segment length */

Unsigned long a_bss;/* length of the BSS segment */

Unsigned long a_syms;/* symbol table length */

Unsigned long a_entry;/* program entry point */

Unsigned long a_trsize;/* length of the text relocation table */

Unsigned long a_drsize;/* length of the Data relocation table */

};

The file header mainly describes the length of each section. The most important field is a_entry (program entry point ), it represents the entry for the system to start executing program code after loading the program and testing various environments. The A. Out format is very compact and only contains the information required for running the program: Text, data, and BSS (BSS is the uninitialized data segment generated by the Unix linker. The other segments are the "text" section containing the program code and the "data" section containing the initialized data. BSS segment variables only have names and sizes but have no values. This name was later used by many file formats, including PE. A block starting with a symbol refers to the place where the compiler processes uninitialized data. The BSS section does not contain any data, but simply maintains the start and end addresses so that the memory zone can be effectively cleared during runtime. BSS does not exist in the binary image file of the application.
The order of sections is fixed. This structure lacks scalability. For example, it cannot contain common debugging information in "modern" executable files. The A. out file contains the symbol table and two relocation tables. The content of these three tables takes effect when connecting the target file to generate an executable file. In the final executable A. out file, the length of the three tables is 0. A. the out file includes all external definitions in executable programs during connection. From the perspective of program design, this is a hard encoding method, or it can be called strong coupling between modules. A. Out is an executable file format used by early Unix systems. It was designed by at&t and is now basically replaced by the ELF file format. A. Out
The design is relatively simple, but its design concept is obviously inherited and carried forward by the subsequent executable file format.

Magic number: the executable files in UNIX are tagged in a special way, so that the system can easily confirm their attributes. The common approach is to use unique numbers, also known as "mysterious" numbers.

PE

Microsoft has designed a file format named Pe (portable executable). The main extension is to add some specialized headers to the coff file header.

Elf

Executableand linkable format, the executable connection format, is developed and released by the UNIX System Lab as the application binary interface (ABI. The tool interface standards board selects the developing elf standard as a binary file format that can be transplanted between different operating systems on 32-bit intel systems.

Coff

Coff format than. the out format must be more complex. The most important thing is to include a section table. text ,. data, and. in addition to the BSS segment, it can also contain other segments. An optional Header is also added. Different Operating Systems can define a specific header.

The coff file format is as follows:

File Header)

Optional Header (optional file header)

Section 1 header (segment header)

.........

Section N header (section header)

Raw data for section 1 (section data)

Raw data for section N (section data)

Relocation info for sect. 1 (segment relocation data)

Relocation info for sect. N (segment relocation data)

Line numbers for sect. 1 (row number data)

Line numbers for sect. N (row number data)

Symbol table)

Symbol table)

 

Struct filehdr {

Unsigned short f_magic;/* Magic Number */

Unsigned short f_nscns;/* number of nodes */

Long f_timdat;/* file creation time */

Long f_symptr;/* offset of the symbol table to the file */

Long f_nsyms;/* Number of symbol table entries */

Unsigned short f_opthdr;/* optional Header Length */

Unsigned short f_flags;/* flag */

};

The magic number in the coff file header is of different significance from the other two formats. It indicates the target machine type, for example, 0x014c is relative to the i386 platform, and 0x268 is relative to the Motorola 68000 series. When the coff file is an executable file, the value of the field f_flags is f_exec (0x00002). It also indicates that the file has no unparsed symbols. In other words, that is, the relocation has been completed during the connection. We can also see that the original
Coff format does not support dynamic connection. To solve this problem and add some new features, some operating systems have extended the coff format.

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.