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

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

CVSweb <webmaster@jp.NetBSD.org>