NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: MrCBofBCinTX on October 14, 2012, 03:20:22 PM
-
I sent a message to the OpenBSD mailing list, but since it's the weekend, I am still waiting a reply.
I haven't used NASM for a while, too busy.
So this is a newer version of both NASM and OpenBSD.
nasm-2.10.04
Just running a quick test and I get these errors
Any thoughts?
I am getting errors with NASM. ( I also tried many other combinations. )
# nasm -f aoutb hello.asm
# ld -e _start -o hello hello.o
ld: warning: cannot find entry symbol _start; defaulting to 1c000114
# ./hello
./hello[1]: syntax error: `(' unexpected
or
# nasm -f aout hello.asm
# ld -s -o hello hello.o
hello.o: file not recognized: File format not recognized
or
# nasm -f elf hello.asm
# ld -s -o hello hello.o
ld: warning: cannot find entry symbol _start; defaulting to 1c000120
# ./hello
./hello[1]: syntax error: `(' unexpected
I have never had a problem previously.
I am running:
OpenBSD 5.2-current (GENERIC) #22: Mon Sep 24 18:31:52 MDT 2012
hello.asm:
%include 'system.inc'
section .data
hello db 'Hello, World!', 0Ah
hbytes equ $-hello
section .text
global _start
_start:
push dword hbytes
push dword hello
push dword stdout
sys.write
push dword 0
sys.exit
system.inc:
%define stdin 0
%define stdout 1
%define stderr 2
%define SYS_nosys 0
%define SYS_exit 1
%define SYS_fork 2
%define SYS_read 3
%define SYS_write 4
%define SYS_open 5
%define SYS_close 6
section .text
align 4
access.the.bsd.kernel:
int 80h
ret
%macro system 1
mov eax, %1
call access.the.bsd.kernel
%endmacro
%macro sys.exit 0
system SYS_exit
%endmacro
%macro sys.fork 0
system SYS_fork
%endmacro
%macro sys.read 0
system SYS_read
%endmacro
%macro sys.write 0
system SYS_write
%endmacro
%macro sys.open 0
system SYS_open
%endmacro
%macro sys.close 0
system SYS_close
%endmacro
-
Please use code tags -- available by pressing the # button in the WYSIWYG editor.
-
1.) Split the problem in half. What version of NASM did you have before? Does that known working version create the same errors on newer OpenBSD. If possible, test the opposite as well, i.e. newer NASM on older OpenBSD.
2.) NASM 2.10.05 is available... update and check again.
3.) Try an alternate/simpler example and compare, such as http://asm.sourceforge.net/intro/hello.html#AEN124 (http://asm.sourceforge.net/intro/hello.html#AEN124)
-
3.) Try an alternate/simpler example and compare, such as http://asm.sourceforge.net/intro/hello.html#AEN124 (http://asm.sourceforge.net/intro/hello.html#AEN124)
I tried this but got same error.
I am building 2.10.05, and will report back
-
2.10.5 gave same error.
I cannot download a newer OpenBSD, due to bad internet connection where I am at.
Need to wait until I have time to go to better connection.
I have an older version in storage room.
I was either using nasm-2.10.tgz or nasm-2.08.01.tgz
not sure which one.
-
I also get error from nasm-2.10
at this point I am going to guess that it is OpenBSD -current version I am using.
nasm-2.08.01 is too old to load on my laptop
-
If you are on 64-bit (AMD64) OpenBSD, try the following:
nasm -f elf32 -o hello.o hello.asm
ld -m elf_i386 -o hello hello.o
-
Found this interesting older OpenBSD message: http://monkey.org/openbsd/archive/misc/0403/msg01148.html (http://monkey.org/openbsd/archive/misc/0403/msg01148.html)
Makes sense, as it seems like the binary is being interpreted as a shell script per the error message.
Based on the above message, try adding the following (mostly verbatim conversion) to your source code:
section .note.openbsd.ident
align 2
dd 8
dd 4
dd 1
db 'OpenBSD',0
dd 0
align 2
Alternatively, use "main" in your source instead of "_start" and link via GCC instead of LD.
-
This did not work.
I get error:
sfhello.asm:1: error: segment name `.note.openbsd.ident' not recognized
I will try with gcc
-
Nevermind gcc. This works fine:
add note section then compile like this:
nasm -f elf32 -o sfhello.o sfhello.asm
ld -m elf_i386_obsd -o sfhello sfhello.o
./sfhello
Hello, world!