flat assembler
Message board for the users of flat assembler.

Index > Unix > openbsd

Author
Thread Post new topic Reply to topic
sloppy



Joined: 10 Nov 2007
Posts: 6
sloppy
I am wondering whether it would be possible to bootstrap fasm or fasmg on a 64bit OpenBSD. I know this has been discussed in other threads, but the infos are sparse and outdated. Most discussions pre-date the x86_64 port for Linux.

I thought my best bet is to take the x86_64 Linux version and adapt the syscalls part.

Before trying this myself I wanted to see if I can produce at least a working 64bit executable with fasm/fasmg so I installed a 32bit OpenBSD virtual machine using the native vmd, grabbed the libC version of fasm and linked it with clang -nopie. For fasmg I had to start from Linux, make a fasmg.o and then link it under 32bit OBSD.
So now I have 32 bits fasm/fasmg on OBSD.

I cannot make however a working 64bit executable. My best try is:
Code:
format ELF64

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

section '.text' executable align 16
        public _start
        _start:
        mov rax, 1
        mov rdi, 7 ; exit code 7
        syscall
    


I compiled it with fasm 32bit and linked it on the 64bit OS with ld.bfd
If I run it I get Abort trap. If I compile it with clang -nopie (with main instead of _start) I get:
./t64[1]: syntax error: `)' unexpected

On a 64bit machine the following is working with NASM
Code:
section .note.openbsd.ident note
        align   2
        dd      8,4,1
        db      "OpenBSD",0
        dd      0
        align   2
section .text

        global  _start
        _start:

        mov     rax, 1
        mov     rdi, 7         ; exit code 7
        syscall
    


One difference is that if I compare the elf headers, the .note.openbsd.ident section is not marked as note in fasm, however I don't think it's enough to solve the problem, if I omit "note" in the nasm example I get the section marked as PROGBITS like with fasm, but the program still runs.

I tried to compile the example above with fasmg aswell, including the selfhost.inc file for linux (I am not using any of the 32on64 parts) but I still get the same abort trap.

Can someone give me hints on how to proceed? Do I need implement an elf64 format specific for OpenBSD or is there much more that I am missing? I am still trying to assess how complicated this is

Thanks
Post 27 Nov 2020, 13:06
View user's profile Send private message Reply with quote
Gibson



Joined: 03 Feb 2021
Posts: 2
Gibson
I've ported fasm to OpenBSD/amd64 in the thread at https://board.flatassembler.net/topic.php?t=21803, the same ideas could possibly be used to bootstrap fasmg but I'm not familiar with it.

I'm not sure what the issue you're having here is, but the example you sent assembles fine in the build I have:
Code:
openbsd$ cat >test.asm
format ELF64

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

section '.text' executable align 16
        public _start
        _start:
        mov rax, 1
        mov rdi, 7 ; exit code 7
        syscall
openbsd$ fasm test.asm
flat assembler  version 1.73.27  (16384 kilobytes memory, x64)
1 passes, 576 bytes.
openbsd$ ld.bfd -nopie test.o
openbsd$ ./a.out
openbsd$ echo $?
7
    
Post 03 Feb 2021, 21: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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.