flat assembler
Message board for the users of flat assembler.

Index > Unix > fasm port for OpenBSD amd64

Author
Thread Post new topic Reply to topic
Gibson



Joined: 03 Feb 2021
Posts: 2
Gibson 03 Feb 2021, 21:15
Based on the Linux x64 port, I've ported fasm to OpenBSD on amd64 (i386 is available in packages and as devel/fasm in ports). The libc port could not be used here as OpenBSD does not support i386 binaries on amd64.

The attached archive contains the source and the binary, so it can be self-compiled natively. Some things are marked as TODO in the source, and the code could do with improvements in places, but it does work.

You must link native executables using ld.bfd -nopie, the normal linker will not work due to how it treats the .note.openbsd.ident section when it isn't marked explicitly as a note (fasm does not support that attribute for ELF).

Notes:

  • OpenBSD does not support Linux's MAP_32BIT, so if the program break is above 4GB it will error, however that should never happen as we get the break using an external symbol rather than brk(0)
  • OpenBSD's syscall interface may or may not be stable from release to release (I couldn't find an official statement either way) -- a possible solution to this in the future is to go through libc instead


At a minimum, you need this to assemble a working native executable:
Code:
format ELF64

section '.note.openbsd.ident' align 2
        dd 8,4,1
        db 'OpenBSD',0
        dd 0

public _start
_start:
        mov rdi,0
        mov rax,1  ; SYS_exit
        syscall
    


Have fun!


Description:
Download
Filename: fasm-openbsd.tgz
Filesize: 269.91 KB
Downloaded: 809 Time(s)

Post 03 Feb 2021, 21:15
View user's profile Send private message Visit poster's website Reply with quote
andurilan



Joined: 09 Nov 2021
Posts: 3
andurilan 06 Dec 2021, 11:43
You've just injected new life into my stale Bitrig installation.
Good job!

_________________
AA
Post 06 Dec 2021, 11:43
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.