flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > ELF executables segments origin

Author
Thread Post new topic Reply to topic
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
The documentation states the following:
fasm manual wrote:
To create executable file, follow the format choice directive with the executable keyword. It allows to use entry directive followed by the value to set as entry point of program. On the other hand it makes extrn and public directives unavailable, and instead of section there should be the segment directive used, followed only by one or more segment permission flags. The origin of segment is aligned to page (4096 bytes), and available flags for are: readable, writeable and executable.


However when compiling the following example:
Code:
; 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    


IDApro says:
Code:
LOAD:08048074 ; Format      : ELF (Executable)
LOAD:08048074 ;
LOAD:08048074
LOAD:08048074                 .686p
LOAD:08048074                 .mmx
LOAD:08048074                 .model flat
LOAD:08048074 .intel_syntax noprefix
LOAD:08048074
LOAD:08048074 ; ---------------------------------------------------------------------------
LOAD:08048074
LOAD:08048074 ; Segment type: Pure code
LOAD:08048074 ; Segment permissions: Read/Execute
LOAD:08048074 LOAD            segment mempage public 'CODE' use32
LOAD:08048074                 assume cs:LOAD
LOAD:08048074                 ;org 8048074h
LOAD:08048074                 assume es:nothing, ss:nothing, ds:LOAD, fs:nothing, gs:nothing
LOAD:08048074
LOAD:08048074 ; ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ S U B R O U T I N E ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
LOAD:08048074
LOAD:08048074
LOAD:08048074                 public start
LOAD:08048074 start           proc near
LOAD:08048074                 mov     eax, 4
LOAD:08048079                 mov     ebx, 1          ; fd
LOAD:0804807E                 mov     ecx, offset unk_8049093 ; addr
LOAD:08048083                 mov     edx, 0Dh        ; len
LOAD:08048088                 int     80h             ; LINUX - sys_write
LOAD:0804808A                 mov     eax, 1
LOAD:0804808F                 xor     ebx, ebx        ; status
LOAD:08048091                 int     80h             ; LINUX - sys_exit
LOAD:08048091 start           endp
LOAD:08048091
LOAD:08048091 LOAD            ends
LOAD:08048091
LOAD:08049093 ; ---------------------------------------------------------------------------
LOAD:08049093
LOAD:08049093 ; Segment type: Pure data
LOAD:08049093 ; Segment permissions: Read/Write
LOAD:08049093 LOAD            segment mempage public 'DATA' use32
LOAD:08049093                 assume cs:LOAD
LOAD:08049093                 ;org 8049093h
LOAD:08049093 ; const void unk_8049093
LOAD:08049093 unk_8049093     db  48h ; H             ; DATA XREF: start+Ao
LOAD:08049094                 db  65h ; e
LOAD:08049095                 db  6Ch ; l
LOAD:08049096                 db  6Ch ; l
LOAD:08049097                 db  6Fh ; o
LOAD:08049098                 db  20h
LOAD:08049099                 db  77h ; w
LOAD:0804909A                 db  6Fh ; o
LOAD:0804909B                 db  72h ; r
LOAD:0804909C                 db  6Ch ; l
LOAD:0804909D                 db  64h ; d
LOAD:0804909E                 db  21h ; !
LOAD:0804909F                 db  0Ah
LOAD:0804909F LOAD            ends
LOAD:0804909F
LOAD:0804909F
LOAD:0804909F                 end start    
(Take special attention to the last segment)


I've realised the lack of aligment when I've tried "movdqa xmm0, [$]" in another thread and also crashed until I used "align 16".

Is this a documentation bug?
Post 08 Aug 2009, 06:58
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7737
Location: Kraków, Poland
Tomasz Grysztar
Yes, this is a flaw in documentation. The segments themselves are aligned to page, however the data loaded into segment has to be at offset that has low 12 bits the same as offset in file.
Post 08 Aug 2009, 09:58
View user's profile Send private message Visit poster's website Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder
[content deleted]
Post 08 Aug 2009, 11:49
View user's profile Send private message 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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.