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 Fri, 14 Apr 2023, Rocky Hotas wrote:

Even if this is intended to be amd64 code, built as `nasm -f elf64'?


Yes. `.note.netbsd.ident' is 24 bytes (4 + 4 + 4 + 8 + 4) on both 32- and
64-bit platforms. See:

/usr/include/elf.h (line 916-...)

and the check for this ELF tag in:

/usr/src/sys/kern/exec_elf.c:netbsd_elf_note()

IIUC, you replaced `db' (``define byte'') and `dq' (``define quadword'',
that should be 8 bytes) with `dd' (``define double word'', that is 4
bytes, 32 bit). So the section only contains now `dd's.


Yes, I thought it would be simpler to grok the section size if I used
the same type throughout.

I can't understand the ``NetBSD string'', which is the concatenation of
the 6 characters `NetBSD', the NULL character, and `$'. Is this a
conventional string? Where can I find it?


That last '$' is me misremembering MASM syntax :) Fortunately, it still
amounted to 8 bytes in the end.


Also, in the code comments, it is stated to be ``8 bytes'' and it is in
the first version of your code, but now it is only 6 bytes, `NetBSD'. Is
it the same?


It's still the same size: 8 bytes. According to the nasm docs, both

	db "NetBSD",0,0

and

	dd "NetBSD"

are equivalent. For `dd', the extra 2 bytes are filled with '\0'.

+section .note.netbsd.ident note alloc noexec nowrite align=4

You added `note alloc noexec nowrite align=4'. I didn't know much about
the toolchain, so I'm not able to understand well these new strings.


`readelf -Wa foo' is what I used when comparing your executable with the
regular ones. The same command will also show you the section sizes.


By `nasm docs' you refer to the manpage nasm(1)?


No, the stuff in /usr/pkg/share/doc/nasm.

HTH,

-RVP


Home | Main Index | Thread Index | Old Index