NetBSD-Users archive

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

Re: Help to run assembly code



On Wed, Mar 18, 2026 at 09:26:51AM -0300, Isac Monção wrote:
> Hi everyone
> 
> I'm learning assembly, but I can't manage to run the linked binary. 
> It keeps saying "sh: Cannot execute ELF binary ./hello". I even
> loaded the compat_linux kernel module. Does anyone know what I'm
> forgetting?

I don't understand the compat_linux part here (why would that be needed?),
but what you are missing is the NetBSD note.

No idea how to do that with NASM, but for the as(1) that comes with
the base system you can copy the code from src/lib/csu/common/sysident.S.

Main part is:

        .section ".note.netbsd.ident", "a"
        .p2align 2

        .long   ELF_NOTE_NETBSD_NAMESZ
        .long   ELF_NOTE_NETBSD_DESCSZ
        .long   ELF_NOTE_TYPE_NETBSD_TAG
        .ascii  "NetBSD\0\0"    /* ELF_NOTE_NETBSD_NAME */
        .long   __NetBSD_Version__

Compare the file(1) output for your binary with e.g. 

	file /bin/ls

Martin


Home | Main Index | Thread Index | Old Index