BSD daemon

NetBSD Documentation:

Vendor-specific ELF Note Elements

Various operating system vendors are shipping ELF binaries and those binaries expect different system call interfaces. In order to help operating systems correctly determine whether or not they can run an ELF program, and how to run it (e.g. what OS emulation to use), some operating system vendors have begun marking their ELF binaries with vendor-specific note elements, and placing those notes in the binaries' PT_NOTE sections.

This page is meant to be a repository of knowledge about vendor-specific note elements used in binaries PT_NOTE sections for operating system identification. It contains the following information:

If your operating system uses vendor-specific note elements to mark its binaries and is not listed here, please send mail to Chris Demetriou with information about those notes.

Format of an ELF Note Element

All ELF Note elements have the same basic structure:
	Name Size	4 bytes (integer)
	Desc Size	4 bytes (integer)
	Type		4 bytes (usually interpreted as an integer)
	Name		variable size, padded to a 4 byte boundary
	Desc		variable size, padded to a 4 byte boundary

The Name Size and Desc Size fields are integers (in the byte order specified by the binary's ELF header) which specify the size of the Name and Desc fields (excluding padding).

The Name field specifies the vendor who defined the format of the Note. Typically, vendors use names which are related to their project and/or company names. For instance, the GNU Project uses "GNU" as its name. No two vendors should use the same ELF Note Name, lest there be confusion when trying to interpret the meanings of notes.

The Type field is vendor specific, but it is usually treated as an integer which identifies the type of the note.

The Desc field is vendor specific, and usually contains data which depends on the note type.

Known ELF Note Names

The following are the strings known to be used as ELF Note Names, along with the organizations that use them. Names with lengths that are not a multiples of 4 are padded in the note, but only the given length should be be checked.
    Note Name String            Organization
    ----------------            ------------
    "NetBSD\0"                  The NetBSD Project
    0x4e 0x65 0x74 0x42 0x53 0x44 0x00 (length 7)

    "GNU\0"                     The GNU Project
    0x47 0x4e 0x55 0x00 (length 4)

Vendor-specific ELF Notes

This section contains information about the formats of ELF notes which vendors use in their PT_NOTE sections, and is split up by vendor.
The NetBSD Project
There are two vendor-specific ELF Notes for NetBSD, an OS Version note and an Emulation Name note. The former is used to indicate what OS Version native binaries were built with, and can be used to identify native binaries. The latter is used to mark binaries (both native an non-native) with a name that indicates which set of binary emulation code is to be used when they are run.

The format of the NetBSD OS Version note is:

    Name Size:          7
    Desc Size:          4
    Type:               4-byte integer containing the value 0x01
    Name:               "NetBSD\0" (padded to 8 bytes)
    Desc:               4-byte integer containing the NetBSD OS version
                        constant

The format of the NetBSD Emulation Name note is:

    Name Size:          7
    Desc Size:          variable
    Type:               4-byte integer containing the value 0x02
    Name:               "NetBSD\0" (padded to 8 bytes)
    Desc:               NUL-terminated string naming the
                        emulation to be used to run the binary
                        (padded to the next 4-byte boundary)
The GNU Project
Starting with glibc 2.1, the GNU project will be using a single ELF Note to indicate which GNU operating system and which version of that system a binary was built for. The format of that note is:
    Name Size:          4
    Desc Size:          16
    Type:               4-byte integer containing the value 0x01
    Name:               "GNU\0"
    Desc:               Four 4-byte integers containing, in order:
			OS (0 = Linux, 1 = Hurd, 2 = Solaris)
			Major, Minor, and Teeny (of earliest
			    OS version that supports this ABI)
For more documentation on the GNU C Library's use of ELF notes, consult the sources: abi-tags and csu/abi-note.S.

Creating ELF PT_NOTE Sections

If you're using the GNU binutils 2.8 or greater to create your binaries, you can generate PT_NOTE sections in your final object files. To create a PT_NOTE section, create a section in one of your object files (for systems which generate PT_NOTE entries by default, this is typically the runtime startup code) with a name starting with ".note" and having the "allocate" property set. Put properly formed ELF Notes entries in that section. When final linking is done, all sections which have names starting with ".note" and which are marked "allocate" will be put into PT_NOTE sections in the final object file.

An example of GNU assembler input which will create a PT_NOTE section during final link is:

    .section ".note.ident", "a"
    .p2align 2
    .long 1f - 0f           # name size (not including padding)
    .long 3f - 2f           # desc size (not including padding)
    .long 0x01234567        # type
0:  .asciz "NaMe"	    # name
1:  .p2align 2
2:  .long 0x76543210        # desc
    .long 0x89abcdef
3:  .p2align 2

That example will create a section called ".note.ident", marked "allocate" (so that it will be turned into a PT_NOTE section during final link), which contains a single note. That note has a type of 0x012345678, has the name "NaMe\0", and has a desc value consisting of two 4-byte integers, 0x76543210 and 0x89abcdef.

Creating a NetBSD ELF PT_NOTE Section

The NetBSD kernel will return ENOEXEC if an ELF binary does not contain a recognized PT_NOTE section. Normally, crtbegin.c contains this section for native NetBSD applications. The example below creates such a section on NetBSD/alpha. (Other ports may use slightly different assembler syntax, but, except for endian variations, they all use the same bits.)
        .section ".note.netbsd.ident", "a"
        .long   2f-1f
        .long   4f-3f
        .long   1
1:      .asciz "NetBSD"
2:      .p2align 2
3:      .long   199905
4:      .p2align 2

Up to NetBSD Documentation: Kernel
NetBSD Home Page
NetBSD Documentation top level

(Contact us) $NetBSD: elf-notes.html,v 1.19 2004/10/30 22:33:26 jschauma Exp $
Copyright © 1994-2003 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.