Annotation of htdocs/docs/kernel/elf-notes.html, revision 1.13

1.1       dsieger     1: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
                      2: <html>
                      3: <head>
                      4: <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
                      5: <meta name="generator" content="Website XSL Stylesheet V2.6.0">
                      6: <link rel="home" href="../../." title="Welcome to The NetBSD Project: Of course it runs NetBSD.">
                      7: <link rel="up" href="../../docs/kernel/." title="NetBSD Documentation: Kernel">
                      8: <link rel="previous" href="../../docs/kernel/porting-freebsd-net.html" title="Notes on porting FreeBSD network drivers to NetBSD">
                      9: <link rel="next" href="../../docs/mirror.html" title="NetBSD Mirror FAQ">
                     10: <link rel="first" href="../../docs/kernel/lazyfpu.html" title="NetBSD Documentation: How lazy FPU context switch works">
1.11      dsieger    11: <link rel="stylesheet" href="../../global.css" type="text/css">
1.1       dsieger    12: 
                     13: 
                     14: 
                     15: <title>NetBSD Documentation: Vendor-specific ELF Note Elements</title>
                     16: </head>
                     17: <body class="website"><div class="webpage">
1.3       dsieger    18: <a name="docs-kernel-elf-notes"></a><div id="top"><a href="#mainContent" class="doNotDisplay doNotPrint">Skip to main content.</a></div>
                     19: <div id="header">
                     20: <div class="topNavigation">
1.6       dsieger    21: <span>» </span><a href="../../docs/guide/en/">
                     22:          The Guide</a> |
1.3       dsieger    23:        <a href="http://man.NetBSD.org/">Manual pages</a> |
1.8       kano       24:        <a href="../../mailinglists/">
1.6       dsieger    25:          Mailing lists</a> and
1.3       dsieger    26:        <a href="http://mail-index.NetBSD.org/">Archives</a> |
                     27:        <a href="http://cvsweb.NetBSD.org/">CVS repository</a> |
1.6       dsieger    28:        <a href="http://www.NetBSD.org/cgi-bin/sendpr.cgi?gndb=netbsd">Report</a>
                     29:        or 
1.9       kano       30:        <a href="../../support/query-pr.html">
                     31:          query</a> a bug |
1.6       dsieger    32:        <a href="../../docs/software/packages.html">
                     33:          Software Packages
                     34:        </a>
1.3       dsieger    35: </div>
                     36: <div class="centralHeader">
1.6       dsieger    37: <a href="../../"><img alt="[NetBSD Logo]" width="506" height="90" src="../../images/NetBSD-headerlogo.png"></a><div class="headerTools"><div id="headerSearch"><form method="get" action="http://www.google.com/custom">
1.4       dsieger    38: <input class="whiteOnBlack" type="text" name="q" onfocus="if(this.value==this.defaultValue ) this.value='';" size="12" maxlength="255" value="Search"><input type="hidden" name="cof" value="L:http://www.NetBSD.org/images/NetBSD-smaller.png;LH:200;LW:200;AH:center;AWFID:4f6b0499f0f58d2c;"><input type="hidden" name="domains" value="NetBSD.org"><input type="hidden" name="sitesearch" value="www.NetBSD.org"><input type="submit" value="Search">
1.3       dsieger    39: </form></div></div>
                     40: </div>
                     41: <div class="navBar">
1.6       dsieger    42: <span class="doNotDisplay">
                     43:          Navigation:
                     44:        </span><a href="../../">
                     45:          Home</a> | 
                     46:        <a href="../../about/">
                     47:          About</a> | 
1.12      hubertf    48:        <a href="../../gallery/">
                     49:          Gallery</a> | 
1.6       dsieger    50:        <a href="../../releases/">
                     51:          Download</a> | 
                     52:        <a href="../../docs/">
                     53:          Documentation</a> | 
                     54:        <a href="../../support/">
                     55:          Support</a> | 
                     56:        <a href="../../community/">
                     57:          Community</a> | 
                     58:        <a href="../../ports/">
                     59:          Ports</a>
1.3       dsieger    60: </div>
                     61: </div>
                     62: <div id="content"><div class="fullWidth"><div class="rowOfBoxes">
                     63: <h1>NetBSD Documentation: Vendor-specific ELF Note Elements</h1>
1.1       dsieger    64: <h3 class="title"><a name="introduction"></a></h3>
                     65: <ul>
                     66: <li><a href="#introduction-sub">Introduction</a></li>
                     67: <li><a href="#note-format">Format of an ELF Note Element</a></li>
                     68: <li><a href="#note-names">Known ELF Note Names</a></li>
                     69: <li><a href="#note-contents">Vendor-specific ELF Notes</a></li>
                     70: <li><a href="#note-creation">Creating ELF PT_NOTE Sections</a></li>
                     71: <li><a href="#netbsd-note">Creating a NetBSD ELF PT_NOTE Section</a></li>
                     72: </ul>
                     73: <hr>
                     74: <h3 class="title"></h3>
                     75:     <h4 class="title">
                     76: <a name="introduction-sub"></a>Introduction (<a href="#introduction">top</a>)
                     77:   </h4>
                     78:       <p>
                     79:        Various operating system vendors are shipping ELF binaries and those
                     80:        binaries expect different system call interfaces.  In order to help
                     81:        operating systems correctly determine whether or not they can run an
                     82:        ELF program, and how to run it (e.g. what OS emulation to use), some
                     83:        operating system vendors have begun marking their ELF binaries with
                     84:        vendor-specific note elements, and placing those notes in the
                     85:        binaries' <code class="constant">PT_NOTE</code> sections.
                     86:       </p>
                     87:       <p>
                     88:        This page is meant to be a repository of knowledge about vendor-specific
                     89:        note elements used in binaries <code class="constant">PT_NOTE</code> sections for operating system
                     90:        identification.
                     91:       </p>
                     92: 
                     93:       <p>
                     94:        If your operating system uses vendor-specific note elements to
                     95:        mark its binaries and is not listed here, please send mail to
1.11      dsieger    96:        <a class="ulink" href="mailto:cgd@NetBSD.org" target="_top">Chris Demetriou</a>
1.1       dsieger    97:        with information about those notes.
                     98:       </p>
                     99:     
                    100:       <h4 class="title">
                    101: <a name="note-format"></a>Format of an ELF Note Element (<a href="#introduction">top</a>)
                    102:   </h4>
                    103: 
                    104:       <p>
                    105:        All ELF Note elements have the same basic structure:
                    106:        </p>
                    107: <div class="variablelist"><dl>
                    108: <dt><span class="term"><code class="varname">Name Size</code></span></dt>
                    109: <dd>4 bytes (integer)</dd>
                    110: <dt><span class="term"><code class="varname">Desc Size</code></span></dt>
                    111: <dd>4 bytes (integer)</dd>
                    112: <dt><span class="term"><code class="varname">Type</code></span></dt>
                    113: <dd>4 bytes (usually interpreted as an integer)</dd>
                    114: <dt><span class="term"><code class="varname">Name</code></span></dt>
                    115: <dd>variable size, padded to a 4 byte boundary</dd>
                    116: <dt><span class="term"><code class="varname">Desc</code></span></dt>
                    117: <dd>variable size, padded to a 4 byte boundary</dd>
                    118: </dl></div>
                    119: <p>
                    120:       </p>
                    121:       
                    122:       <p>
                    123:        The "Name Size" and "Desc Size" fields are integers (in the byte order
                    124:        specified by the binary's ELF header) which specify the size of the
                    125:        "Name" and "Desc" fields (excluding padding).
                    126:       </p>
                    127:     
                    128:       <p>
                    129:        The "Name" field specifies the vendor who defined the format of the Note.
                    130:        Typically, vendors use names which are related to their project and/or
                    131:        company names.  For instance, the GNU Project uses "GNU" as its name.
                    132:        No two vendors should use the same ELF Note Name, lest there be confusion
                    133:        when trying to interpret the meanings of notes.
                    134:       </p>
                    135:       
                    136:       <p>
                    137:        The "Type" field is vendor specific, but it is usually treated as an
                    138:        integer which identifies the type of the note.
                    139:       </p>
                    140:       
                    141:       <p>
                    142:        The "Desc" field is vendor specific, and usually contains data which
                    143:        depends on the note type.
                    144:       </p>
                    145:     
                    146:       <h4 class="title">
                    147: <a name="note-names"></a>Known ELF Note Names (<a href="#introduction">top</a>)
                    148:   </h4>
                    149: 
                    150:       <p>
                    151:        The following are the strings known to be used as ELF Note Names, along
                    152:        with the organizations that use them.  Names with lengths that are
                    153:        not a multiples of 4 are padded in the note, but only the given length
                    154:        should be checked.
                    155:       </p>
                    156:       
                    157:       <div class="segmentedlist"><table border="0">
                    158: <thead><tr class="segtitle">
                    159: <th>Note Name String</th>
                    160: <th>Byte encoding of string</th>
                    161: <th>Length</th>
                    162: <th>Organization</th>
                    163: </tr></thead>
                    164: <tbody>
                    165: <tr class="seglistitem">
                    166:          <td class="seg"><code class="code">"NetBSD\0"</code></td>
                    167:          <td class="seg"><code class="code">0x4e 0x65 0x74 0x42 0x53 0x44 0x00</code></td>
                    168:          <td class="seg">7</td>
1.11      dsieger   169:          <td class="seg"><a class="xref" href="#note-contents-netbsd" title="The NetBSD Project">The NetBSD Project</a></td>
1.1       dsieger   170:        </tr>
                    171: <tr class="seglistitem">
                    172:          <td class="seg"><code class="code">"GNU\0"</code></td>
                    173:          <td class="seg"><code class="code">0x47 0x4e 0x55 0x00</code></td>
                    174:          <td class="seg">4</td>
1.11      dsieger   175:          <td class="seg"><a class="xref" href="#note-contents-gnu" title="The GNU Project">The GNU Project</a></td>
1.1       dsieger   176:        </tr>
                    177: </tbody>
                    178: </table></div>
                    179:     
                    180:     <h4 class="title">
                    181: <a name="note-contents"></a>Vendor-specific ELF Notes (<a href="#introduction">top</a>)
                    182:   </h4>
                    183:       
                    184:     <p>
                    185:       This section contains information about the formats of ELF notes which
                    186:       vendors use in their <code class="constant">PT_NOTE</code> sections, and is split up by vendor.
                    187:     </p>
                    188: 
                    189:     <div class="sect4" lang="en">
                    190: <div class="titlepage"><div><div><h5 class="title">
                    191: <a name="note-contents-netbsd"></a>The NetBSD Project</h5></div></div></div>
                    192:       
                    193:       
                    194:       <p>
                    195:        There are two vendor-specific ELF Notes for NetBSD, an OS Version note and
                    196:        an Emulation Name note.
                    197:        The former is used to indicate what OS Version
                    198:        native binaries were built with, and can be used to identify native
                    199:        binaries.
                    200:        The latter is used to mark binaries (both native an non-native) with
                    201:        a name that indicates which set of binary emulation code is to be used
                    202:        when they are run.
                    203:       </p>
                    204:       <p>
                    205:        The format of the NetBSD OS Version note is:
                    206:        
                    207:        </p>
                    208: <div class="variablelist"><dl>
                    209: <dt><span class="term"><code class="varname">Name Size</code></span></dt>
                    210: <dd>7</dd>
                    211: <dt><span class="term"><code class="varname">Desc Size</code></span></dt>
                    212: <dd>4</dd>
                    213: <dt><span class="term"><code class="varname">Type</code></span></dt>
                    214: <dd>4-byte integer containing the value <code class="code">0x01</code>
                    215: </dd>
                    216: <dt><span class="term"><code class="varname">Name</code></span></dt>
                    217: <dd>
                    218: <code class="code">"NetBSD\0"</code> (padded to 8 bytes)</dd>
                    219: <dt><span class="term"><code class="varname">Desc</code></span></dt>
                    220: <dd>4-byte integer containing the NetBSD OS version constant</dd>
                    221: </dl></div>
                    222: <p>
                    223:       </p>
                    224: 
                    225:       <p>
                    226:        The format of the NetBSD Emulation Name note is:
                    227:        </p>
                    228: <div class="variablelist"><dl>
                    229: <dt><span class="term"><code class="varname">Name Size</code></span></dt>
                    230: <dd>7</dd>
                    231: <dt><span class="term"><code class="varname">Desc Size</code></span></dt>
                    232: <dd>variable</dd>
                    233: <dt><span class="term"><code class="varname">Type</code></span></dt>
                    234: <dd>4-byte integer containing the value <code class="code">0x02</code>
                    235: </dd>
                    236: <dt><span class="term"><code class="varname">Name</code></span></dt>
                    237: <dd>
                    238: <code class="code">"NetBSD\0"</code> (padded to 8 bytes)</dd>
                    239: <dt><span class="term"><code class="varname">Desc</code></span></dt>
                    240: <dd>
                    241: <code class="code">NUL</code>-terminated string naming the
                    242:            emulation to be used to run the binary
                    243:            (padded to the next 4-byte boundary)</dd>
                    244: </dl></div>
                    245: <p>
                    246:       </p>
                    247:     </div>
                    248: 
                    249:     <div class="sect4" lang="en">
                    250: <div class="titlepage"><div><div><h5 class="title">
                    251: <a name="note-contents-gnu"></a>The GNU Project</h5></div></div></div>
                    252:       
                    253: 
                    254:       <p>
                    255:        Starting with glibc 2.1, the GNU project will be using a single ELF Note
                    256:        to indicate which GNU operating system and which version of that system
                    257:        a binary was built for.  The format of that note is:
                    258:        </p>
                    259: <div class="variablelist"><dl>
                    260: <dt><span class="term"><code class="varname">Name Size</code></span></dt>
                    261: <dd>4</dd>
                    262: <dt><span class="term"><code class="varname">Desc Size</code></span></dt>
                    263: <dd>16</dd>
                    264: <dt><span class="term"><code class="varname">Type</code></span></dt>
                    265: <dd>4-byte integer containing the value <code class="code">0x01</code>
                    266: </dd>
                    267: <dt><span class="term"><code class="varname">Name</code></span></dt>
                    268: <dd><code class="code">"GNU\0"</code></dd>
                    269: <dt><span class="term"><code class="varname">Desc</code></span></dt>
                    270: <dd>
                    271:              Four 4-byte integers containing, in order:
                    272:              <div class="orderedlist"><ol type="1">
                    273: <li>OS (0 = Linux, 1 = Hurd, 2 = Solaris)</li>
                    274: <li>Major</li>
                    275: <li>Minor</li>
                    276: <li>Teeny</li>
                    277: </ol></div>
                    278:              The major, minor and teeny versions are that of the earliest OS version that supports this ABI.
                    279:            </dd>
                    280: </dl></div>
                    281: <p>
                    282:       </p>
                    283: 
                    284:       <p>
                    285:        For more documentation on the GNU C Library's use of ELF notes,
                    286:        consult the sources:
1.11      dsieger   287:        <a class="ulink" href="http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/abi-tags?cvsroot=glibc" target="_top">abi-tags</a>
1.1       dsieger   288:        and
1.11      dsieger   289:        <a class="ulink" href="http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/csu/abi-note.S?cvsroot=glibc" target="_top">csu/abi-note.S</a>.
1.1       dsieger   290:       </p>
                    291:     </div>
                    292:   
                    293:       <h4 class="title">
                    294: <a name="note-creation"></a>Creating ELF <code class="constant">PT_NOTE</code> Sections (<a href="#introduction">top</a>)
                    295:   </h4>
                    296: 
                    297:       <p>
                    298:        If you're using the GNU binutils 2.8 or greater to create your binaries,
                    299:        you can generate <code class="constant">PT_NOTE</code> sections in your final object files.
                    300:        To create a <code class="constant">PT_NOTE</code> section, create a section in one of your object
                    301:        files (for systems which generate <code class="constant">PT_NOTE</code> entries by default, this
                    302:        is typically the runtime startup code) with a name starting
                    303:        with ".note" and having the "allocate" property set.
                    304:        Put properly formed ELF Notes entries in that section.
                    305:        When final linking is done, all sections which have names starting
                    306:        with ".note" and which are marked "allocate" will be put into <code class="constant">PT_NOTE</code>
                    307:        sections in the final object file.
                    308:       </p>
                    309:       <p>
                    310:        An example of GNU assembler input which will create a <code class="constant">PT_NOTE</code> section
                    311:        during final link is:
                    312:       </p>
                    313: <pre class="programlisting">
                    314:     .section ".note.ident", "a"
                    315:     .p2align 2
                    316:     .long 1f - 0f           # name size (not including padding)
                    317:     .long 3f - 2f           # desc size (not including padding)
                    318:     .long 0x01234567        # type
                    319: 0:  .asciz "NaMe"          # name
                    320: 1:  .p2align 2
                    321: 2:  .long 0x76543210        # desc
                    322:     .long 0x89abcdef
                    323: 3:  .p2align 2
                    324: </pre>
                    325: 
                    326: <p>
                    327:   That example will create a section called ".note.ident", marked
                    328:   "allocate" (so that it will be turned into a
                    329:   <code class="constant">PT_NOTE</code> section during final link), which
                    330:   contains a single note.  That note has a <code class="varname">type</code> of
                    331:   <code class="code">0x012345678</code>, has the <code class="varname">name</code>
                    332:   <code class="code">"NaMe\0"</code>, and has a <code class="varname">desc</code> value
                    333:   consisting of two 4-byte integers, <code class="code">0x76543210</code> and
                    334:   <code class="code">0x89abcdef</code>.
                    335: </p>
                    336:     
                    337:       <h4 class="title">
                    338: <a name="netbsd-note"></a>Creating a NetBSD ELF <code class="constant">PT_NOTE</code> Section (<a href="#introduction">top</a>)
                    339:   </h4>
                    340:       
                    341:       <p>
                    342:        The NetBSD kernel will return ENOEXEC if an ELF binary does not contain
                    343:        a recognized <code class="constant">PT_NOTE</code> section. Normally, <code class="filename">crtbegin.c</code>
                    344:        contains this section
                    345:        for native NetBSD applications. The example below creates such a section
1.10      martin    346:        on NetBSD/sparc. (Other ports may use slightly different assembler syntax,
                    347:        for example arm uses %note - since @ starts a comment,
1.1       dsieger   348:        but, except for endian variations, they all use the same bits.)
                    349:       </p>
                    350: <pre class="programlisting">
1.10      martin    351:         .section ".note.netbsd.ident", "", @note
1.1       dsieger   352:         .long   2f-1f
                    353:         .long   4f-3f
                    354:         .long   1
                    355: 1:      .asciz "NetBSD"
                    356: 2:      .p2align 2
1.10      martin    357: 3:      .long   499003600
1.1       dsieger   358: 4:      .p2align 2
                    359: </pre>
1.3       dsieger   360:     </div></div></div>
                    361: <div class="navfoot"></div>
1.13    ! mishka    362: <div id="footer"><div id="footerContent"><center>
1.3       dsieger   363: <span class="footfeed"><a href="http://www.NetBSD.org/cgi-bin/feedback.cgi">
                    364:          Contact</a> |
1.9       kano      365:       </span><span class="footcopy"><a href="../../about/disclaimer.html">
1.3       dsieger   366:       Disclaimer</a> |
                    367: 
1.13    ! mishka    368:       <span class="copyright">Copyright © 1994-2009 The NetBSD Foundation, Inc. </span>ALL RIGHTS RESERVED.<br>NetBSD<sup>®</sup> is a registered trademark of The NetBSD
1.3       dsieger   369:        Foundation, Inc.</span>
1.13    ! mishka    370: </center></div></div>
1.1       dsieger   371: </div></body>
                    372: </html>

CVSweb <webmaster@jp.NetBSD.org>