Linux target file ELF format

  
        1 <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"> </span><span style="font -family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">The popular executable file format on PC is mainly PE and Linux ELF files under Windows. They are all variants of the COFF format file. When the target file is compiled, the intermediate files compiled but not linked are almost the same as the format of the executable file, so the target file (.o file) is also stored in the same format as the executable file. </span>


In addition to executable files in Linux, there are several files stored in ELF format, including dynamic library files (.so), relocatable files (.o). ), core dump file (the system saves some process information to this type of file when the process terminates). We can use the file command to view the file type eg:


? 1 2 3 xiang@xiang:~/workspace/linux$ file prim prim: ELF 32-bit LSB executable, Intel 80386, version 1 ( SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0xd54ce2ecedb22482c79f597093ff8c0b8f7c7113, not stripped xiang@xiang:~/workspace/linux$ About the format of the ELF file, which contains the file header ( File header), code segment (.text), data segment (.data) uninitialized data segment (.bss), etc. The objdump command can be used to view the information of each segment.



? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 xiang@xiang:~/workspace/algorithm$ g++ -c Prim.cpp -o prim.o xiang@xiang:~/workspace/algorithm$ objdump -h prim.o prim.o: file format elf32-i386 Sections: Idx Name Size VMA LMA File off Algn 0 .text 0000031f 00000000 00000000 00000034 2**2 CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE 1 .data 00000000 00000000 00000000 00000354 2**2 CONTEN TS, ALLOC, LOAD, DATA 2 .bss 003d3c21 00000000 00000000 00000360 2**5 ALLOC 3 .rodata 00000008 00000000 00000000 00000360 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 4 .ctors 00000004 00000000 00000000 00000368 2**2 CONTENTS, ALLOC, LOAD, RELOC, DATA 5 .comment 0000002c 00000000 00000000 0000036c 2**0 CONTENTS, READONLY 6 .note.GNU-stack 00000000 00000000 00000000 00000398 2**0 CONTENTS, READONLY 7 .eh_frame 000000dc 00000000 00000000 00000398 2* *2 CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA xiang@xiang:~/workspace/algorithm$ objdump -h prim 1, the file header contains the magic number of the file in the file header. Word length, version, running platform, file type, entry address, short message, etc., where the magic number is used to tell the type of the system file, such as the magic number of the ELF file is DEL + ELF,

Copyright © Windows knowledge All Rights Reserved