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

1.17      jym         1: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
1.1       dsieger     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>
1.17      jym        19: <div id="centralHeader">
                     20: <a href="../../"><img alt="[NetBSD Logo]" src="../../images/NetBSD-headerlogo.png"></a><div id="headerTools">
                     21: <div id="header-cse-search-form">Google custom search</div>
1.15      spz        22: <script src="http://www.google.com/jsapi" type="text/javascript"></script><script type="text/javascript"> 
                     23:                  google.load('search', '1', {language : 'en'});
                     24:                  google.setOnLoadCallback(function() {
                     25:                    var header_customSearchControl = new google.search.CustomSearchControl('006277936787196004968:mbdhrauy1wm');
                     26:                    header_customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
                     27:                    var header_options = new google.search.DrawOptions();
                     28:                    header_options.enableSearchboxOnly("http://google.com/cse?cx=006277936787196004968:mbdhrauy1wm");    
                     29:                    header_customSearchControl.draw('header-cse-search-form', header_options);
                     30:                  }, true);
1.17      jym        31:                </script>
                     32: </div>
1.3       dsieger    33: </div>
1.17      jym        34: <div id="navBar" role="navigation">
1.6       dsieger    35: <span class="doNotDisplay">
                     36:          Navigation:
1.17      jym        37:        </span><ul>
                     38: <li><a href="../../">
                     39:          Home</a></li>
                     40: <li>
                     41: <a href="../../">
                     42:          New &amp; Media</a><ul>
                     43: <li><a href="../../changes/">
                     44:            Recent changes</a></li>
1.18    ! jym        45: <li><a href="http://blog.NetBSD.org/">
1.17      jym        46:            NetBSD blog</a></li>
                     47: <li><a href="../../gallery/events.html">
                     48:            Events</a></li>
                     49: <li><a href="../../changes/rss.html">
                     50:            Feeds</a></li>
                     51: </ul>
                     52: </li>
                     53: <li>
                     54: <a href="../../about/">
                     55:          About</a><ul>
                     56: <li><a href="../../about/">
                     57:            NetBSD</a></li>
                     58: <li><a href="../../foundation/">
                     59:            The NetBSD Foundation</a></li>
                     60: <li><a href="../../gallery/">
                     61:            Advocacy</a></li>
                     62: </ul>
                     63: </li>
                     64: <li>
                     65: <a href="../../docs/">
                     66:          Documentation</a><ul>
                     67: <li><a href="../../docs/misc/index.html">
                     68:            FAQ &amp; HOWTOs</a></li>
                     69: <li><a href="../../docs/guide/en/">
                     70:            The Guide</a></li>
1.18    ! jym        71: <li><a href="http://man.NetBSD.org/">
1.17      jym        72:            Manual pages</a></li>
1.18    ! jym        73: <li><a href="http://wiki.NetBSD.org/">
1.17      jym        74:            Wiki</a></li>
                     75: </ul>
                     76: </li>
                     77: <li>
                     78: <a href="../../support/">
                     79:          Support</a><ul>
                     80: <li><a href="../../support/send-pr.html">
                     81:            Problem report guide</a></li>
                     82: <li><a href="../../cgi-bin/sendpr.cgi?gndb=netbsd">
                     83:            Report a bug</a></li>
                     84: <li><a href="../../support/query-pr.html">
                     85:            Query bug database</a></li>
                     86: <li><a href="../../support/security/">
                     87:            Security</a></li>
                     88: </ul>
                     89: </li>
                     90: <li>
                     91: <a href="../../community/">
                     92:          Community</a><ul>
                     93: <li><a href="http://onetbsd.org/">
                     94:            Blogs</a></li>
                     95: <li><a href="../../mailinglists/">
                     96:            Mailing lists</a></li>
1.18    ! jym        97: <li><a href="http://mail-index.NetBSD.org/">
1.17      jym        98:            List archives</a></li>
                     99: </ul>
                    100: </li>
                    101: <li>
                    102: <a href="../../developers/">
                    103:          Developers</a><ul>
1.18    ! jym       104: <li><a href="http://cvsweb.NetBSD.org/">
1.17      jym       105:            Browse source</a></li>
1.18    ! jym       106: <li><a href="http://nxr.NetBSD.org/">
1.17      jym       107:            Cross-reference</a></li>
1.18    ! jym       108: <li><a href="http://releng.NetBSD.org/">
1.17      jym       109:            Release engineering</a></li>
1.18    ! jym       110: <li><a href="http://wiki.NetBSD.org/projects/">
1.17      jym       111:            Projects list</a></li>
                    112: </ul>
                    113: </li>
                    114: <li>
                    115: <a href="../../ports/">
                    116:          Ports</a><ul>
                    117: <li><a href="../../ports/history.html">
                    118:            History</a></li>
                    119: <li><a href="../../ports/emulators.html">
                    120:            Emulators</a></li>
                    121: </ul>
                    122: </li>
                    123: <li>
                    124: <a href="http://www.pkgsrc.org/">
                    125:          Packages</a><ul>
                    126: <li><a href="http://www.pkgsrc.se/">
                    127:            Browse packages</a></li>
1.18    ! jym       128: <li><a href="http://releng.NetBSD.org/index-pkgsrc.html">
1.17      jym       129:            Release engineering</a></li>
                    130: </ul>
                    131: </li>
                    132: </ul>
1.3       dsieger   133: </div>
                    134: <div id="content"><div class="fullWidth"><div class="rowOfBoxes">
                    135: <h1>NetBSD Documentation: Vendor-specific ELF Note Elements</h1>
1.1       dsieger   136: <h3 class="title"><a name="introduction"></a></h3>
                    137: <ul>
                    138: <li><a href="#introduction-sub">Introduction</a></li>
                    139: <li><a href="#note-format">Format of an ELF Note Element</a></li>
                    140: <li><a href="#note-names">Known ELF Note Names</a></li>
                    141: <li><a href="#note-contents">Vendor-specific ELF Notes</a></li>
                    142: <li><a href="#note-creation">Creating ELF PT_NOTE Sections</a></li>
                    143: <li><a href="#netbsd-note">Creating a NetBSD ELF PT_NOTE Section</a></li>
                    144: </ul>
                    145: <hr>
                    146: <h3 class="title"></h3>
                    147:     <h4 class="title">
                    148: <a name="introduction-sub"></a>Introduction (<a href="#introduction">top</a>)
                    149:   </h4>
                    150:       <p>
                    151:        Various operating system vendors are shipping ELF binaries and those
                    152:        binaries expect different system call interfaces.  In order to help
                    153:        operating systems correctly determine whether or not they can run an
                    154:        ELF program, and how to run it (e.g. what OS emulation to use), some
                    155:        operating system vendors have begun marking their ELF binaries with
                    156:        vendor-specific note elements, and placing those notes in the
                    157:        binaries' <code class="constant">PT_NOTE</code> sections.
                    158:       </p>
                    159:       <p>
                    160:        This page is meant to be a repository of knowledge about vendor-specific
                    161:        note elements used in binaries <code class="constant">PT_NOTE</code> sections for operating system
                    162:        identification.
                    163:       </p>
                    164: 
                    165:       <p>
                    166:        If your operating system uses vendor-specific note elements to
                    167:        mark its binaries and is not listed here, please send mail to
1.11      dsieger   168:        <a class="ulink" href="mailto:cgd@NetBSD.org" target="_top">Chris Demetriou</a>
1.1       dsieger   169:        with information about those notes.
                    170:       </p>
                    171:     
                    172:       <h4 class="title">
                    173: <a name="note-format"></a>Format of an ELF Note Element (<a href="#introduction">top</a>)
                    174:   </h4>
                    175: 
                    176:       <p>
                    177:        All ELF Note elements have the same basic structure:
                    178:        </p>
                    179: <div class="variablelist"><dl>
                    180: <dt><span class="term"><code class="varname">Name Size</code></span></dt>
                    181: <dd>4 bytes (integer)</dd>
                    182: <dt><span class="term"><code class="varname">Desc Size</code></span></dt>
                    183: <dd>4 bytes (integer)</dd>
                    184: <dt><span class="term"><code class="varname">Type</code></span></dt>
                    185: <dd>4 bytes (usually interpreted as an integer)</dd>
                    186: <dt><span class="term"><code class="varname">Name</code></span></dt>
                    187: <dd>variable size, padded to a 4 byte boundary</dd>
                    188: <dt><span class="term"><code class="varname">Desc</code></span></dt>
                    189: <dd>variable size, padded to a 4 byte boundary</dd>
                    190: </dl></div>
                    191: <p>
                    192:       </p>
                    193:       
                    194:       <p>
                    195:        The "Name Size" and "Desc Size" fields are integers (in the byte order
                    196:        specified by the binary's ELF header) which specify the size of the
                    197:        "Name" and "Desc" fields (excluding padding).
                    198:       </p>
                    199:     
                    200:       <p>
                    201:        The "Name" field specifies the vendor who defined the format of the Note.
                    202:        Typically, vendors use names which are related to their project and/or
                    203:        company names.  For instance, the GNU Project uses "GNU" as its name.
                    204:        No two vendors should use the same ELF Note Name, lest there be confusion
                    205:        when trying to interpret the meanings of notes.
                    206:       </p>
                    207:       
                    208:       <p>
                    209:        The "Type" field is vendor specific, but it is usually treated as an
                    210:        integer which identifies the type of the note.
                    211:       </p>
                    212:       
                    213:       <p>
                    214:        The "Desc" field is vendor specific, and usually contains data which
                    215:        depends on the note type.
                    216:       </p>
                    217:     
                    218:       <h4 class="title">
                    219: <a name="note-names"></a>Known ELF Note Names (<a href="#introduction">top</a>)
                    220:   </h4>
                    221: 
                    222:       <p>
                    223:        The following are the strings known to be used as ELF Note Names, along
                    224:        with the organizations that use them.  Names with lengths that are
                    225:        not a multiples of 4 are padded in the note, but only the given length
                    226:        should be checked.
                    227:       </p>
                    228:       
                    229:       <div class="segmentedlist"><table border="0">
                    230: <thead><tr class="segtitle">
                    231: <th>Note Name String</th>
                    232: <th>Byte encoding of string</th>
                    233: <th>Length</th>
                    234: <th>Organization</th>
                    235: </tr></thead>
                    236: <tbody>
                    237: <tr class="seglistitem">
                    238:          <td class="seg"><code class="code">"NetBSD\0"</code></td>
                    239:          <td class="seg"><code class="code">0x4e 0x65 0x74 0x42 0x53 0x44 0x00</code></td>
                    240:          <td class="seg">7</td>
1.11      dsieger   241:          <td class="seg"><a class="xref" href="#note-contents-netbsd" title="The NetBSD Project">The NetBSD Project</a></td>
1.1       dsieger   242:        </tr>
                    243: <tr class="seglistitem">
                    244:          <td class="seg"><code class="code">"GNU\0"</code></td>
                    245:          <td class="seg"><code class="code">0x47 0x4e 0x55 0x00</code></td>
                    246:          <td class="seg">4</td>
1.11      dsieger   247:          <td class="seg"><a class="xref" href="#note-contents-gnu" title="The GNU Project">The GNU Project</a></td>
1.1       dsieger   248:        </tr>
                    249: </tbody>
                    250: </table></div>
                    251:     
                    252:     <h4 class="title">
                    253: <a name="note-contents"></a>Vendor-specific ELF Notes (<a href="#introduction">top</a>)
                    254:   </h4>
                    255:       
                    256:     <p>
                    257:       This section contains information about the formats of ELF notes which
                    258:       vendors use in their <code class="constant">PT_NOTE</code> sections, and is split up by vendor.
                    259:     </p>
                    260: 
1.15      spz       261:     <div class="sect4" title="The NetBSD Project">
1.1       dsieger   262: <div class="titlepage"><div><div><h5 class="title">
                    263: <a name="note-contents-netbsd"></a>The NetBSD Project</h5></div></div></div>
                    264:       
                    265:       
                    266:       <p>
                    267:        There are two vendor-specific ELF Notes for NetBSD, an OS Version note and
                    268:        an Emulation Name note.
                    269:        The former is used to indicate what OS Version
                    270:        native binaries were built with, and can be used to identify native
                    271:        binaries.
                    272:        The latter is used to mark binaries (both native an non-native) with
                    273:        a name that indicates which set of binary emulation code is to be used
                    274:        when they are run.
                    275:       </p>
                    276:       <p>
                    277:        The format of the NetBSD OS Version note is:
                    278:        
                    279:        </p>
                    280: <div class="variablelist"><dl>
                    281: <dt><span class="term"><code class="varname">Name Size</code></span></dt>
                    282: <dd>7</dd>
                    283: <dt><span class="term"><code class="varname">Desc Size</code></span></dt>
                    284: <dd>4</dd>
                    285: <dt><span class="term"><code class="varname">Type</code></span></dt>
                    286: <dd>4-byte integer containing the value <code class="code">0x01</code>
                    287: </dd>
                    288: <dt><span class="term"><code class="varname">Name</code></span></dt>
                    289: <dd>
                    290: <code class="code">"NetBSD\0"</code> (padded to 8 bytes)</dd>
                    291: <dt><span class="term"><code class="varname">Desc</code></span></dt>
                    292: <dd>4-byte integer containing the NetBSD OS version constant</dd>
                    293: </dl></div>
                    294: <p>
                    295:       </p>
                    296: 
                    297:       <p>
                    298:        The format of the NetBSD Emulation Name note is:
                    299:        </p>
                    300: <div class="variablelist"><dl>
                    301: <dt><span class="term"><code class="varname">Name Size</code></span></dt>
                    302: <dd>7</dd>
                    303: <dt><span class="term"><code class="varname">Desc Size</code></span></dt>
                    304: <dd>variable</dd>
                    305: <dt><span class="term"><code class="varname">Type</code></span></dt>
                    306: <dd>4-byte integer containing the value <code class="code">0x02</code>
                    307: </dd>
                    308: <dt><span class="term"><code class="varname">Name</code></span></dt>
                    309: <dd>
                    310: <code class="code">"NetBSD\0"</code> (padded to 8 bytes)</dd>
                    311: <dt><span class="term"><code class="varname">Desc</code></span></dt>
                    312: <dd>
                    313: <code class="code">NUL</code>-terminated string naming the
                    314:            emulation to be used to run the binary
                    315:            (padded to the next 4-byte boundary)</dd>
                    316: </dl></div>
                    317: <p>
                    318:       </p>
                    319:     </div>
                    320: 
1.15      spz       321:     <div class="sect4" title="The GNU Project">
1.1       dsieger   322: <div class="titlepage"><div><div><h5 class="title">
                    323: <a name="note-contents-gnu"></a>The GNU Project</h5></div></div></div>
                    324:       
                    325: 
                    326:       <p>
                    327:        Starting with glibc 2.1, the GNU project will be using a single ELF Note
                    328:        to indicate which GNU operating system and which version of that system
                    329:        a binary was built for.  The format of that note is:
                    330:        </p>
                    331: <div class="variablelist"><dl>
                    332: <dt><span class="term"><code class="varname">Name Size</code></span></dt>
                    333: <dd>4</dd>
                    334: <dt><span class="term"><code class="varname">Desc Size</code></span></dt>
                    335: <dd>16</dd>
                    336: <dt><span class="term"><code class="varname">Type</code></span></dt>
                    337: <dd>4-byte integer containing the value <code class="code">0x01</code>
                    338: </dd>
                    339: <dt><span class="term"><code class="varname">Name</code></span></dt>
                    340: <dd><code class="code">"GNU\0"</code></dd>
                    341: <dt><span class="term"><code class="varname">Desc</code></span></dt>
                    342: <dd>
                    343:              Four 4-byte integers containing, in order:
1.15      spz       344:              <div class="orderedlist"><ol class="orderedlist" type="1">
                    345: <li class="listitem">OS (0 = Linux, 1 = Hurd, 2 = Solaris)</li>
                    346: <li class="listitem">Major</li>
                    347: <li class="listitem">Minor</li>
                    348: <li class="listitem">Teeny</li>
1.1       dsieger   349: </ol></div>
                    350:              The major, minor and teeny versions are that of the earliest OS version that supports this ABI.
                    351:            </dd>
                    352: </dl></div>
                    353: <p>
                    354:       </p>
                    355: 
                    356:       <p>
                    357:        For more documentation on the GNU C Library's use of ELF notes,
                    358:        consult the sources:
1.11      dsieger   359:        <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   360:        and
1.11      dsieger   361:        <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   362:       </p>
                    363:     </div>
                    364:   
                    365:       <h4 class="title">
                    366: <a name="note-creation"></a>Creating ELF <code class="constant">PT_NOTE</code> Sections (<a href="#introduction">top</a>)
                    367:   </h4>
                    368: 
                    369:       <p>
                    370:        If you're using the GNU binutils 2.8 or greater to create your binaries,
                    371:        you can generate <code class="constant">PT_NOTE</code> sections in your final object files.
                    372:        To create a <code class="constant">PT_NOTE</code> section, create a section in one of your object
                    373:        files (for systems which generate <code class="constant">PT_NOTE</code> entries by default, this
                    374:        is typically the runtime startup code) with a name starting
                    375:        with ".note" and having the "allocate" property set.
                    376:        Put properly formed ELF Notes entries in that section.
                    377:        When final linking is done, all sections which have names starting
                    378:        with ".note" and which are marked "allocate" will be put into <code class="constant">PT_NOTE</code>
                    379:        sections in the final object file.
                    380:       </p>
                    381:       <p>
                    382:        An example of GNU assembler input which will create a <code class="constant">PT_NOTE</code> section
                    383:        during final link is:
                    384:       </p>
                    385: <pre class="programlisting">
                    386:     .section ".note.ident", "a"
                    387:     .p2align 2
                    388:     .long 1f - 0f           # name size (not including padding)
                    389:     .long 3f - 2f           # desc size (not including padding)
                    390:     .long 0x01234567        # type
                    391: 0:  .asciz "NaMe"          # name
                    392: 1:  .p2align 2
                    393: 2:  .long 0x76543210        # desc
                    394:     .long 0x89abcdef
                    395: 3:  .p2align 2
                    396: </pre>
                    397: 
                    398: <p>
                    399:   That example will create a section called ".note.ident", marked
                    400:   "allocate" (so that it will be turned into a
                    401:   <code class="constant">PT_NOTE</code> section during final link), which
                    402:   contains a single note.  That note has a <code class="varname">type</code> of
                    403:   <code class="code">0x012345678</code>, has the <code class="varname">name</code>
                    404:   <code class="code">"NaMe\0"</code>, and has a <code class="varname">desc</code> value
                    405:   consisting of two 4-byte integers, <code class="code">0x76543210</code> and
                    406:   <code class="code">0x89abcdef</code>.
                    407: </p>
                    408:     
                    409:       <h4 class="title">
                    410: <a name="netbsd-note"></a>Creating a NetBSD ELF <code class="constant">PT_NOTE</code> Section (<a href="#introduction">top</a>)
                    411:   </h4>
                    412:       
                    413:       <p>
                    414:        The NetBSD kernel will return ENOEXEC if an ELF binary does not contain
                    415:        a recognized <code class="constant">PT_NOTE</code> section. Normally, <code class="filename">crtbegin.c</code>
                    416:        contains this section
                    417:        for native NetBSD applications. The example below creates such a section
1.10      martin    418:        on NetBSD/sparc. (Other ports may use slightly different assembler syntax,
                    419:        for example arm uses %note - since @ starts a comment,
1.1       dsieger   420:        but, except for endian variations, they all use the same bits.)
                    421:       </p>
                    422: <pre class="programlisting">
1.10      martin    423:         .section ".note.netbsd.ident", "", @note
1.1       dsieger   424:         .long   2f-1f
                    425:         .long   4f-3f
                    426:         .long   1
                    427: 1:      .asciz "NetBSD"
                    428: 2:      .p2align 2
1.10      martin    429: 3:      .long   499003600
1.1       dsieger   430: 4:      .p2align 2
                    431: </pre>
1.3       dsieger   432:     </div></div></div>
                    433: <div class="navfoot"></div>
1.13      mishka    434: <div id="footer"><div id="footerContent"><center>
1.3       dsieger   435: <span class="footfeed"><a href="http://www.NetBSD.org/cgi-bin/feedback.cgi">
                    436:          Contact</a> |
1.9       kano      437:       </span><span class="footcopy"><a href="../../about/disclaimer.html">
1.3       dsieger   438:       Disclaimer</a> |
                    439: 
1.16      darcy     440:       <span class="copyright">Copyright © 1994-2012 The NetBSD Foundation, Inc. </span>ALL RIGHTS RESERVED.<br>NetBSD<sup>®</sup> is a registered trademark of The NetBSD
1.3       dsieger   441:        Foundation, Inc.</span>
1.13      mishka    442: </center></div></div>
1.1       dsieger   443: </div></body>
                    444: </html>

CVSweb <webmaster@jp.NetBSD.org>