ELF sections do not map to segments as expected

I am writing a compiler and just starting to generate ELF executables from scratch. I am creating a .text section (although it does not have a name because I am not yet creating a row table) and trying to put it in the PT_LOAD segment. However, readelf does not report that the section is displayed in the segment, and objdump refuses to parse the code in the .text section. This is a readelf reading, with some abbreviations omitted for brevity:

 ELF Header: Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 Class: ELF64 Data: 2 complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: Advanced Micro Devices X86-64 Version: 0x1 Entry point address: 0x0 Start of program headers: 64 (bytes into file) Start of section headers: 122 (bytes into file) Flags: 0x0 Size of this header: 64 (bytes) Size of program headers: 56 (bytes) Number of program headers: 1 Size of section headers: 64 (bytes) Number of section headers: 2 Section header string table index: 0 Section Headers: [Nr] Name Type Address Offset Size EntSize Flags Link Info Align [ 0] <no-name> NULL 0000000000000000 00000000 0000000000000000 0000000000000000 0 0 0 [ 1] <no-name> PROGBITS 0000000008048000 00000078 0000000000000002 0000000000000000 AX 0 0 16 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), l (large) I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown) O (extra OS processing required) o (OS specific), p (processor specific) There are no section groups in this file. Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flags Align LOAD 0x0000000000000078 0x0000000008048000 0x0000000008048000 0x0000000000000002 0x0000000000000002 RE 1000 

At offset 0x78 I just emit two push ebx ( 0x78 0x53 ) for testing. Here is the hex dump:

 00000000 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 |.ELF............| 00000010 02 00 3e 00 01 00 00 00 00 00 00 00 00 00 00 00 |..>.............| 00000020 40 00 00 00 00 00 00 00 7a 00 00 00 00 00 00 00 |@.......z.......| 00000030 00 00 00 00 40 00 38 00 01 00 40 00 02 00 00 00 | ....@.8... @.....| 00000040 01 00 00 00 05 00 00 00 78 00 00 00 00 00 00 00 |........x.......| 00000050 00 80 04 08 00 00 00 00 00 80 04 08 00 00 00 00 |................| 00000060 02 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 |................| 00000070 00 10 00 00 00 00 00 00 53 53 00 00 00 00 00 00 |........SS......| 00000080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 000000b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 |................| 000000c0 00 00 06 00 00 00 00 00 00 00 00 80 04 08 00 00 |................| 000000d0 00 00 78 00 00 00 00 00 00 00 02 00 00 00 00 00 |..x.............| 000000e0 00 00 00 00 00 00 00 00 00 00 10 00 00 00 00 00 |................| * 000000fa 

Edit: Question. Why does the section not separate the display displayed between them, and why is there no disassembly shown by objdump ?

+7
compiler-construction x86-64 elf
source share
1 answer

Why there is no segment for display segmentation displayed between two

Since there are no valid partitions (as far as readelf is possible).

and why is there no demonstration shown by objdump?

objdump also uses partitions.

Although partitions are not required for the ELF lifetime ELF , many tools depend on partitions present. For example, the single segment that you have in your executable file contains both the code and the ELF header and the program header. Generally, you do not want to parse the header. Without sections, objdump does not know where to start disassembling.

+1
source share

All Articles