Linux -Blue forest free software | Return to home page | Site Map | Search WWW | Contact Us |
Your current position : Homepage > Free Software > Technological exchanges >Application Programming


    

Blue Forest http://www.lslnet.com at 10:18 on June 6, 2006


Gcc and obj document DLL paper documents and ELF

1, obj documents
Programmer programming, in fact, the preparation of a 2-band (binary) documents. If we declare a variable char c, a 8bit space is a need, then we need to stay 8bit system statement Tsang space, how to do this? Translation is a special two-band --obj paper documents using the C language compiler gcc implementation of the document, which includes not only CPU instructions, and many other information on the inside, it has a lot of format files, etc. : ELF : in the final editing process. Linkers (+) ld executable files will be loaded into a heap of information. For example, when a number of links to wait after the translation. This re-positioning o (relocatable) documents, since these documents were inside the parameters relative position or function itself is located. O documents relative position Links have some information to tell the editor (link editor) how the revised section, do relocate, reference is made to address the re-synthesis of a new executable files.
Obj a period of two important documents, one is available (link), which is at
Hard disk (disk) when Lane; One is being implemented, of course then it falls Memory Lane. The fact that we usually call linker ld link editor, compiler of the final steps in the day to put some information into executable files. If the function is static link will look libxxx.a Secretary document, and want a copy of the code fragment into executable files, and create after relocation, you're talking! Reference into executable files that can be implemented on this document.
2, Dynamic Link documents
Comparing with the static link (static link) copies of the original program code into executable files, DLL is not done, link editor some information into executable files only. For example, the programs for people in need, function, etc., the final performance, we must do call dynamic linker program
Intepreter, the dynamic linker will need the name of the library, want to create an executable image name of the function into memory, the implementation of the DLL implementation document, OS usually by the end of the exec system call and the dynamic linker such as a series of joint ld.so completed.
Dynamic linker will usually do the following :
(1) loading the contents of the executable files to process image
(2) shared obj needs of the loading process image
(3) the completion of relocation
Originally obj papers and documents inside the virtual address should be the address of a relative offset (offset), while the document is usually the first address 0x08040800, which is absolutely virtual address, but only for executable files, such as Linux extuable file is usually :
File offset virtual address
          -----------         ----------------
0x0 0x08048000
0x100 0x08048100
Obj function thus shared code Position for position independent code
Independent Code (PIC), which means it may be the address with a different process and different, for example, a procedure used only libc.so, ld-linux.so usually is this time lib.so 0x40017000 from the beginning, However, if more than one procedure to another libm.so, libc.so starting from 0x40034000 printf reference to the two (reference), a different address, this information is necessary to the internal dynamics of these library code is PIC.
3, ELF documents
(1) Introduction
Now is the most commonly used format called ELF (executable and linkable format) document on the implementation, a number of ELF definition of variables and information made more flexible Dynamic Link, a 2-band ELF 1.1 version of the document in accordance with the spec versions have six, the following are the more common :

Relocatable : it is caused by the compiler. O document contains code and data (data sharing, and other important documents and positioning the object to the use of linked documents)

Executable : it is the final executable files that contain the code and data shared obj : it is available in /lib /usr/lib those under the dynamic link library documents containing the code and data (data link connector time was running one day and the use of Dynamic Linker)

Core:Core Dump when the document contains a heap of garbage data

ELF : these two documents is a broad band document, not just the executable files.
   
(2) ELF component
ELF obj documents with a period of its existence and composition of demand is not the same name, located in the hard disk to link linking period, including :
ELF header
Program header table (can not)
Section 0
Section 1
Section 2
Section 3
Section. . .
Section n
Section header table
ELF put a header identifying ELF definition of ELF format string (commonly known as the magic number), obj (shared obj, relocatable or executable) These general (general); program is described in the table header (segment) structure array of information and procedures in preparation for some information. Segement section and quite different, the procedural elements of the implementation period, the period of implementation of the procedures was necessary, the period is unnecessary in the link, if the procedures are not linked movements, as long as they have the program could header table; section header table is a table, each section to record the directory sections attribute is to use the information required under the category of small pools, there. bss. data. init. Killing. dynamic. fini. : : : text, the more important are :
. Text
Really there to preserve order CPU
. Bss
Not initialize the data preservation
The statement is static and global variables
. Data
Initialize the data preservation

Written procedures used in the function, and a number of variables were distributed in source code catalog, the need for a
Reference (reference), linking the information to do these names symbol is being used to connect the linker to do, because there are scattered documents obj, it is necessary to document these obj code together, it is up to symbol
To identify, string table string a lot of firms that use NULL string in each row separately, each trip is the symbol and the string section's name. Symbol table is a table, there should address in the future or to address in the symbol definitions and reference information. 1986-1991 Judge document also shared the obj. Dynsym this section, which have dynamic symbol table, using the DLL. In addition, if the procedure should Debug debugging tools, the compiler options to increase g, it will sumbol
Killing more and string table into the information needed to obj documents, most of the information is now stored in a format called stab the same time, it will also enable the implementation of file size to almost three times.
ELF in different types of documents, some of the information has ELF definition, the value of which is : : header section or different.
Unix/Linux _start function normally from the beginning instead of a main, main _start later will be deployed, if necessary streamlining of procedures, not to use gcc compiler that can be directly compiled with the _start (^_^). Another section header table, as if no link could not do, such as executable files in the symbol table, all these can not, but should be compiled and executable files to generate the same GAS. There are a lot of things, which is why even if there is no transfer of any function, create dynamic documents using the ldd can certainly ld-linux.so libc.so.
The process of memory and an image, as follows :
ELF header
Program header table
Segment 0
Segment 1
Segment 2
Segment. . .
Segment n
Section header table (can not)
Segment have Text, Data, OS based on different definitions, Text documents under the existing hard disk. Txt. Fini section to the other, in accordance with paragraph Data. Data. Bss section to the other. a segment usually includes one or more of the section, the section even more important in the perspective of a programmer.
ELF support in the system, a procedure is added to the executable files or shared obj files. In order to implement such a process, the process of creating the system memory kept those documents. To load a document into memory ELF, a program header table (table header of the program is a description of the structure of the array of information and procedures in preparation for some of the information). There are several definitions of the ELF file special sections. These are particularly useful to the following procedures :
. Fini
Preservation process termination code instructions
Therefore, the normal procedure, the system of arrangements for the implementation of the code section
. Init
Enforceable order to preserve, which constitutes the process initialization code
Therefore, when a process has begun operation, was deployed in the former main function (known as the main language C)
Arrangements for the implementation of this section of the code system

. Init and. Fini sections of the existence of a special purpose. If a function put. Init section, the main function before the system will implement it. Similarly, if a function put. Fini section, the main function will return the function implementation. Characteristics of the C + + compiler was used to complete the overall structure function analysis of the structure and functions.
When ELF executable files to be implemented, the system will be handed over to the control of the relevant executable files before loading So
Shared document object. Construction correct. Init and. Fini sections, the constructor function and structure function analysis of the sequence will be the correct call.
Unix/Linux the scope of the use of virtual memory :

User area

0x0 - 0x0bffffff ->; 3GB

Kernel area

0x0c000000 ->; 1GB - 0xffffffff

With the following code as an example :
Int global;

Static int func1 (void)
{
Static int 1997a
Int *c;
Int days.
Func2 ();
Return 1;
}
Int func2 (void)
{
Int c;
Static int days.
Return 2;
}
Int main (void)
{
Int a;
Static int 1997a
Int init = 3;
Func1 ();
Return 3;
}

Well, from a Linux implementation document is in memory looks like this :

The implementation of image from beginning for the i386 Linux

Virtual Address Allocation

|----------------------------------|0x0
              | |-----------------------------|  |
              | |                                     |  |
Thread stack | | | |
              | |------------------------------|  |      
              |                                           |
| |------------------------------| |0x08048000 Text
| | | | executable Data
              | |                                      |  |                     ……
              | |                                      |  |
              | |                                      |  |
              | |                                      |  |
              | |------------------------------|  |
              |                                           |
| |------------------------------| |0x40000000 ld-linux.so
| | | | libm.so
| | | | libc.so shared LIB
              | |                                     |  |           
| | | | Stack
              | |                                     |  |
3GB| |----------------------------- | |
              |                                           |
| |------------------------------| |0xc0000000
              | |                                      |  |
| | | | Kernel Code and Data
              | |                                      |  |
              | |-------------------------------|  |
4GB|--------------------------------- |0xffffffff

~ ~ 0xc0000000 0x40000000 0x08048000 which is there.

C : from the angle of the image

0x08048000
     |--------------------------------------------------------|
     |   |--------------------------------------------------|  |
| | main () | |
Text | | | | xxxx
| | func1 (instrction) | |
| | | | xxxx
| | | | func2
| | | | xxxx
     |   |-------------------------------------------------|  |
     |                                                                     |
     |   |-------------------------------------------------|  |
| | | | int global Data
| | static int b (main) static int b (func1) | |
| | static int c (func2) | |
     |   |-------------------------------------------------|  |
     |                                                                     |
     |   |-------------------------------------------------|  |
| | malloc (int) Heap | |
     |   |-------------------------------------------------|  |
     |                      |                                              |   
     |                      |                                              |
     |                     \|/                                             |                             
     |--------------------------------------------------------|
0x40000000 | |
     |                                                                      |
     |                                                                      |
     |--------------------------------------------------------|
     |                     /|\                                             |
     |                      |                                               |
     |                      |                                               |
     |    |-------------------------------------------------|  |
| | | | func2 int c Stack 2
     |    |-------------------------------------------------|  |
     |                                                                      |
     |    |-------------------------------------------------|  |
| | | | 1 func1 int b Stack
     |    |-------------------------------------------------|  |
     |                                                                      |
     |    |-------------------------------------------------|  |
| | main () : | | argv[0] argv[1]
     |    |-------------------------------------------------|  |
     |--------------------------------------------------------|
0xbfffffff

So can clearly see different variables (global, static or auto) and the life cycle (storage class), and the effective range of different variables (scope).
Kernel code and data memory is certainly there, there are actually still read the page table
Turn into actual address. 0x0~ 0xbfffffff in the page table, the process is different for each page
Table, but in the following page table 0xc0000000, are the same.

Gcc and obj document DLL paper documents and ELF

Good classic

Good

Detailed collection

Thank you, study.

Eastern better, the landlord is a master!

Not a classic!

Is a classic!

PIC code unrelated to the location of interest.
Ask the landlord, with the realization of a compilation of the PIC procedure.
What attention?

Ah, the good writing



 Privacy Policy  Copyright © 1999-2000 LSLNET.COM. All rights reserved. Blue Forest website owners. E-mail : Webmaster@lslnet.com