Message board for the users of flat assembler.
> Unix > openbsd
sloppy 27 Nov 2020, 13:06
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:
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: syntax error: `)' unexpected
On a 64bit machine the following is working with NASM
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
|27 Nov 2020, 13:06||
Gibson 03 Feb 2021, 21:24
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:
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
|03 Feb 2021, 21:24||
< Last Thread | Next Thread >
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.