flat assembler
Message board for the users of flat assembler.

Index > Unix > openbsd i386 minimal working executable

Author
Thread Post new topic Reply to topic
ginere



Joined: 15 Oct 2017
Posts: 13
ginere 26 Dec 2022, 15:42
i am having trouble producing an executable on openbsd i386 with fasm.
this is my simple code:
Code:
   format elf
   public a_00
   
   section '.text'
a_00:
   mov eax, $01
   push $00
   push eax
   int $80

   section '.note.openbsd.ident' align 2
   dd $08, $04, $01
   db 'OpenBSD', $00
   dd $00
    


i am linking the file like this:
Code:
fasm myfile.fasm 
ld.bfd -e a_00 -nopie -n --strip-all --static -o myfile myfile.o
    


Program does not run. It segfaults.
Whats the correct way to build an openbsd executable on i386?[/code]
Post 26 Dec 2022, 15:42
View user's profile Send private message Reply with quote
sylware



Joined: 23 Oct 2020
Posts: 462
Location: Marseille/France
sylware 27 Dec 2022, 16:38
BTW, does openbsd require gcc or clang to be compiled or have the decency to allow a clean iso c89/c99 compiler (with probably the gas assembler) to do so?

For instance, linux requires nearly the latest gcc extensions in order to be compiled. Yes, this is sad.
Post 27 Dec 2022, 16:38
View user's profile Send private message Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 732
Ali.Z 31 Dec 2022, 14:12
Im not sure about OpenBSD, I use FreeBSD. (also your program is missing a RET)

Code:
; cc -m32 asm.o -o asm
; cc is a link to clang, FreeBSD use llvm toolchain.
format elf
public main
extrn printf
section '.text' executable
main:
push _freebsd
call printf
add esp,4
ret

section '.data' writeable
_freebsd db 'FreeBSD', 0Ah, 0
    


edit:
here is a version without C functions:
Code:
; cc -m32 asm.o -o asm
format elf
public main

section '.text' executable

main:
mov eax,4
push 9
push _freebsd
push 1
push eax
int 80h
add esp,10h
ret

section '.data' writeable
_freebsd db 'FreeBSD', 0Ah, 0
    

_________________
Asm For Wise Humans
Post 31 Dec 2022, 14:12
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.