NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Assembly example (nasm) for amd64 in NetBSD



On Thu, 13 Apr 2023, Rocky Hotas wrote:

On NetBSD 9.0 I built it with

nasm -f elf64 -o testcpu.o testcpu.s
ld -s -o testcpu testcpu.o

This gives no error, however the file can not execute. If I try to run
the file, I obtain:

/bin/sh: Cannot execute ELF binary ./testcpu


Try adding a ".note.netbsd.ident" section:

```
$ diff -u testcpu.s.orig testcpu.s
--- testcpu.s.orig	2023-04-14 01:42:08.984238899 +0000
+++ testcpu.s	2023-04-14 01:41:06.204866303 +0000
@@ -23,3 +23,11 @@
     mov rax, 1
     mov rbx, 0
     syscall
+
+section .note.netbsd.ident
+
+   dd 7			; ELF_NOTE_NETBSD_NAMESZ
+   dd 4			; ELF_NOTE_NETBSD_DESCSZ
+   dd 1			; ELF_NOTE_TYPE_NETBSD_TAG
+   db 'NetBSD',0,'$'	; NetBSD string
+   dq 903000000		; NetBSD version 9.3.0
$
```

-RVP


Home | Main Index | Thread Index | Old Index