flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Alignment problem with the ELF output

Author
Thread Post new topic Reply to topic
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20299
Location: In your JS exploiting you and your system
revolution 24 Sep 2005, 10:11
I have noticed an alignment problem with the ELF output
Code:
format ELF executable at 0

entry start

section executable readable writeable

org 0
use32

start:
        mov     al,[section_2]
        mov     bl,[section_3]
        mov     cl,[section_4]
        jmp     $

;for this section the program header has this:
;p_vaddr = 0x000000b4 <--- should be 0x00000000
;p_paddr = 0x000000b4 <--- should be 0x00000000

section executable readable
section_2 db 2

;for this section the program header has this:
;p_vaddr = 0x000010c7 <--- should be 0x00001000
;p_paddr = 0x000010c7 <--- should be 0x00001000

section executable
section_3 db 3

;for this section the program header has this:
;p_vaddr = 0x000020c8 <--- should be 0x00002000
;p_paddr = 0x000020c8 <--- should be 0x00002000

section writeable
org 0xaaa0
section_4 db 4

;for this section the program header has this:
;p_vaddr = 0x000030c9 <--- should be 0x00003000
;p_paddr = 0x000030c9 <--- should be 0x00003000    
I think alignment to page boundaries is not working properly.
Post 24 Sep 2005, 10:11
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 27 Sep 2005, 14:35
In ELF executables the p_vaddr and p_offset must be the same modulo p_align. Thus the offset in file and address in memory for each section must have the same last three hexadecimal digits.

I forgot to mention in docs that for ELF executables the sections are not aligned by default (because of the above) - you can however use any "align" inside those sections freely, since the ELF executables are not relocatable (and thus $ is an absolute value).
Post 27 Sep 2005, 14:35
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20299
Location: In your JS exploiting you and your system
revolution 28 Sep 2005, 01:24
Quote:
you can however use any "align" inside those sections freely, since the ELF executables are not relocatable (and thus $ is an absolute value).
You are correct, my mistake, thanks for the info I will use this technique.
Post 28 Sep 2005, 01:24
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.