flat assembler
Message board for the users of flat assembler.
Index
> Linux > Section or Segment? |
Author |
|
AlexP 29 Jun 2008, 05:01
I too have been wondering about how the ELF file structure works (Don't worry Rev, I'm not asking for a link ).
ChristianK: You should google for the ELF File Structure |
|||
29 Jun 2008, 05:01 |
|
ChristianK 29 Jun 2008, 15:19
Thanks for your answer.
I found many descriptions of the ELF file structure, but i can't understand why some executables have section and some have segments. Since sections only appear in the linking view of an ELF file, all executables should have segments instead of section, or am i wrong? |
|||
29 Jun 2008, 15:19 |
|
LocoDelAssembly 29 Jun 2008, 19:27
On executables sections are OPTIONAL and segments mandatory while in ELF objects sections are mandatory and segments not sure if optional or disallowed at all but I think it is the second.
|
|||
29 Jun 2008, 19:27 |
|
ChristianK 30 Jun 2008, 13:55
Thank you, LocoDelAssembly.
But there is one question left: C-Programs compiled with GCC have sections although they are executable. If there are sections and segments, do code and data exist twice in this file? |
|||
30 Jun 2008, 13:55 |
|
LocoDelAssembly 30 Jun 2008, 15:37
Quote:
No, only once but it is referenced by both tables. Code: readelf output for fasm generated executable: Elf file type is EXEC (Executable file) Entry point 0x8048074 There are 2 program headers, starting at offset 52 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align LOAD 0x000074 0x08048074 0x08048074 0x0001f 0x0001f R E 0x1000 LOAD 0x000093 0x08049093 0x08049093 0x0000d 0x0000d RW 0x1000 readelf output for ld generated executable (from a fasm generated object): Elf file type is EXEC (Executable file) Entry point 0x8048074 There are 2 program headers, starting at offset 52 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align LOAD 0x000000 0x08048000 0x08048000 0x00093 0x00093 R E 0x1000 LOAD 0x000094 0x08049094 0x08049094 0x00010 0x00010 RW 0x1000 Section to Segment mapping: Segment Sections... 00 .text 01 .bss ELF executable source: ; fasm demonstration of writing simple ELF executable format ELF executable entry start segment readable executable start: mov eax,4 mov ebx,1 mov ecx,msg mov edx,msg_size int 0x80 mov eax,1 xor ebx,ebx int 0x80 segment readable writeable msg db 'Hello world!',0xA msg_size = $-msg ELF object source: ; fasm demonstration of writing simple ELF executable format ELF public _start section '.text' executable _start: mov eax,4 mov ebx,1 mov ecx,msg mov edx,msg_size int 0x80 mov eax,1 xor ebx,ebx int 0x80 section '.bss' writable msg db 'Hello world!',0xA msg_size = $-msg Code: #!/bin/sh echo "readelf output for fasm generated executable:" readelf exe -l echo "readelf output for ld generated executable (from a fasm generated object):" readelf obj -l echo "ELF executable source:" cat exe.asm echo "ELF object source:" cat obj.asm After passing strip to obj the size is reduced but still it is a little more than the double of exe's size generated with fasm. Well, part of that is the sections table but I don't remember now which other things are inside making obj bigger than exe but believe me that it is not because of code duplication |
|||
30 Jun 2008, 15:37 |
|
ChristianK 30 Jun 2008, 18:38
Thank you very, very much LocoDelAssembly. I think i can understand the ELF format now.
|
|||
30 Jun 2008, 18:38 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.