Arm-ELF File Format and GNU arm linker Mechanism

Source: Internet
Author: User

The basic file formats of the arm system are commonly used in ARM-based embedded system development.

There are three basic file formats for the arm system:

1) bin, flat-board binary format, which is generally used for Directly Writing to flash and loading to the monitor program.

2) Elf, executable and linkable format, a common object file format, generally generated by GNU Compiler Collection (GCC.

3) axf, an extended version in Bin format. The main part is the same as the bin, and debugging information is added to the file header and tail for axd.

This article mainly discusses bin and elf.

The ELF format is an object file format. Generally, object files can be divided into three types: relocated object files, executable object files, and shared object files. Elf files can also be divided into these three types.

First

First, let's talk about the object that can be relocated. This object file is generally generated by the jsoner (AS) in GCC (please do not think that GCC is just a compiler), except for Binary

And some information that can be used for relocation. It is mainly used as the linker (LD) Input. Linker will relocate the symbols to be relocated based on the information, and then generate

Generate executable object files. The relocable object file in the ELF format consists of the header and section.

Header includes

The elf header and section header. Elf header are located in the file header, used to store the architecture of the target machine.

Set, elf header size, object file type, section header offset in the file, section header large

Small, number of items in section header and other information. Section header defines the type, location, size, and other information of each section in the file.

Linker searches for elf headers, finds the section header entry, and then finds the corresponding section header

To locate the target section.

Section includes

. Text: compiled machine code.

. Rodata: read-only data, such as printf ("Hello !") The string hello in.

. Data: initialized global variables. Local variables will be stored in the stack at runtime and will not appear in. Data or. BSS segments.

. BSS: uninitialized global variable. Here it is just a placeholder and there is no actual storage space in the object file.

. Symtab: symbol table, used to store information about global variables and functions defined or referenced in a program.

. Rel. Text:

A list that stores a series of positions in. Text. These locations will be modified When linker merges the file with other object files. In general, these locations are all stored in

Commands that reference global variables or external functions. Commands that reference local variables or local functions do not need to be modified, because the address of local variables and local functions generally uses the PC relative offset address.

Note that this section and the following. Rel. Data are not required at runtime. This section will be removed when an executable elf object file is generated.

. Rel. Data: Save the relocation information of global variables. Generally, if the initial value of a global variable is the address of another global variable or the address of an external function, it needs to be relocated.

. Debug: Save the debug information.

. Strtab: 1

String tables, saving. symtab and. debug, and the names of each section .. In symtab,. debug, and section table

It is the domain that stores the name. In fact, an offset value is saved. The corresponding string can be found in this string table through this offset value.

The following is a detailed discussion of. symtab:

Each relocated object file has a. symtab. This symbol table stores all the defined and referenced symbols in this object file. When the source program is a C-language program, the symbols in. symtab are directly derived from the C compiler (PC3 ). There are three main types of symbols mentioned here:

1) defined in this object file can be global symbols of other object files. In C language source programs, it is mainly those non-static (without static modification) global variables and non-static functions. In arm assembly language, it is the variables exported by the Export command.

2) global variables referenced in this object file but defined in other files. In arm assembly language, it is a variable introduced by the import command.

3) Ben

Local variable. Local variables are only visible in this object file. The local variable here refers to the local variable of the connector, which should be different from the local variable of the general program. The local variables mentioned here include

Static global variable, section name in the object file, and source code file name. Generally, local variables are managed by the runtime environment of the system.

Linker is not concerned.

Each symbol that meets the preceding conditions has a data item in the. symtab file. The data structure of this data item is:

Typedef struct {

Int name; // The symbol name, which is actually the Offset Value of. strtab.

Int value; // The position in the Section, which is expressed by the offset relative to the section address.

Int size; // size

Char type; // type, generally data or function

Char binding; // whether it is a local variable or a global variable

Char reserved; // Reserved Bit

Char section; // the section to which the symbol belongs. Optional values:. Text (represented by number 1) and. Data (represented by number

// 3 stands for), ABS (symbols that should not be relocated), und (in this object file

// Undefined symbols, which may be defined in other files) and COM (General uninitialized variable symbols ).

} Elf_sym

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.