Annotation of htdocs/docs/kernel/elf-notes.html, revision 1.66
1.57 nia 1: <!DOCTYPE html>
1.63 martin 2: <html lang="en">
1.1 dsieger 3: <head>
1.66 ! maya 4: <meta charset="utf-8">
1.1 dsieger 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.48 maya 12: <link rel="stylesheet" href="../../donations/thermo/fundraiser.css" type="text/css">
1.1 dsieger 13:
14:
15:
16: <title>NetBSD Documentation: Vendor-specific ELF Note Elements</title>
1.62 andvar 17: <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
1.1 dsieger 18: </head>
1.64 andvar 19: <body class="website"><div class="webpage" id="docs-kernel-elf-notes">
20: <div id="top"><a href="#mainContent" id="skiplink" tabindex="1">Skip to main content.</a></div>
1.49 maya 21: <input id="hamburger" type="checkbox"><label class="menuicon" for="hamburger"><span></span><span></span><span></span></label><div id="navBar" role="navigation">
1.30 maya 22: <div id="centralHeader"><div id="logo">
1.50 maya 23: <a href="../../"><img id="projectLogo" alt="" height="120" src="../../images/NetBSD-smaller-tb.png"></a><a href="/"><div id="fundraiser">
1.48 maya 24: <br><div id="fundraiser-amount"><div id="fundraiser-raised"></div></div>
25: </div></a>
1.30 maya 26: </div></div>
1.6 dsieger 27: <span class="doNotDisplay">
28: Navigation:
1.17 jym 29: </span><ul>
30: <li>
31: <a href="../../">
1.51 maya 32: Home</a><ul>
1.17 jym 33: <li><a href="../../changes/">
34: Recent changes</a></li>
1.33 maya 35: <li><a href="//blog.NetBSD.org/">
1.17 jym 36: NetBSD blog</a></li>
1.47 maya 37: <li><a href="../../gallery/presentations/">
38: Presentations</a></li>
1.17 jym 39: </ul>
40: </li>
41: <li>
42: <a href="../../about/">
43: About</a><ul>
1.38 maya 44: <li><a href="../../people/developers.html">
1.51 maya 45: Developers</a></li>
1.17 jym 46: <li><a href="../../gallery/">
1.44 leot 47: Gallery</a></li>
1.51 maya 48: <li><a href="//wiki.NetBSD.org/ports/">
49: Ports</a></li>
1.56 nia 50: <li><a href="//www.pkgsrc.org/">
1.51 maya 51: Packages</a></li>
1.17 jym 52: </ul>
53: </li>
54: <li>
55: <a href="../../docs/">
56: Documentation</a><ul>
57: <li><a href="../../docs/misc/index.html">
58: FAQ & HOWTOs</a></li>
59: <li><a href="../../docs/guide/en/">
60: The Guide</a></li>
1.53 nia 61: <li><a href="//man.NetBSD.org/">
1.17 jym 62: Manual pages</a></li>
1.33 maya 63: <li><a href="//wiki.NetBSD.org/">
1.17 jym 64: Wiki</a></li>
65: </ul>
66: </li>
67: <li>
68: <a href="../../support/">
69: Support</a><ul>
1.52 leot 70: <li><a href="/community/">
1.51 maya 71: Community</a></li>
1.52 leot 72: <li><a href="/mailinglists/">
73: Mailing lists</a></li>
1.17 jym 74: <li><a href="../../support/send-pr.html">
1.51 maya 75: Bug reports</a></li>
1.17 jym 76: <li><a href="../../support/security/">
77: Security</a></li>
78: </ul>
79: </li>
80: <li>
81: <a href="../../developers/">
82: Developers</a><ul>
1.35 maya 83: <li><a href="http://cvsweb.NetBSD.org/">
1.51 maya 84: CVSWeb</a></li>
85: <li><a href="//anonhg.NetBSD.org/">
86: Mercurial</a></li>
1.33 maya 87: <li><a href="//nxr.NetBSD.org/">
1.17 jym 88: Cross-reference</a></li>
1.33 maya 89: <li><a href="//releng.NetBSD.org/">
1.17 jym 90: Release engineering</a></li>
1.33 maya 91: <li><a href="//wiki.NetBSD.org/projects/">
1.17 jym 92: Projects list</a></li>
93: </ul>
94: </li>
95: </ul>
1.3 dsieger 96: </div>
1.41 maya 97: <div id="content"><div id="mainContent" class="fullWidth"><div class="rowOfBoxes">
1.3 dsieger 98: <h1>NetBSD Documentation: Vendor-specific ELF Note Elements</h1>
1.1 dsieger 99: <ul>
100: <li><a href="#introduction-sub">Introduction</a></li>
101: <li><a href="#note-format">Format of an ELF Note Element</a></li>
102: <li><a href="#note-names">Known ELF Note Names</a></li>
103: <li><a href="#note-contents">Vendor-specific ELF Notes</a></li>
104: <li><a href="#note-creation">Creating ELF PT_NOTE Sections</a></li>
105: <li><a href="#netbsd-note">Creating a NetBSD ELF PT_NOTE Section</a></li>
106: </ul>
107: <hr>
1.64 andvar 108: <h4 class="title" id="introduction-sub">Introduction</h4>
1.1 dsieger 109: <p>
110: Various operating system vendors are shipping ELF binaries and those
111: binaries expect different system call interfaces. In order to help
112: operating systems correctly determine whether or not they can run an
113: ELF program, and how to run it (e.g. what OS emulation to use), some
114: operating system vendors have begun marking their ELF binaries with
115: vendor-specific note elements, and placing those notes in the
116: binaries' <code class="constant">PT_NOTE</code> sections.
117: </p>
118: <p>
119: This page is meant to be a repository of knowledge about vendor-specific
120: note elements used in binaries <code class="constant">PT_NOTE</code> sections for operating system
121: identification.
122: </p>
123:
124: <p>
125: If your operating system uses vendor-specific note elements to
126: mark its binaries and is not listed here, please send mail to
1.24 mbalmer 127: <a class="ulink" href="mailto:netbsd-docs@NetBSD.org" target="_top">NetBSD documentation list</a>
1.1 dsieger 128: with information about those notes.
129: </p>
130:
1.64 andvar 131: <h4 class="title" id="note-format">Format of an ELF Note Element</h4>
1.1 dsieger 132:
133: <p>
134: All ELF Note elements have the same basic structure:
135: </p>
1.22 tron 136: <div class="variablelist"><dl class="variablelist">
1.1 dsieger 137: <dt><span class="term"><code class="varname">Name Size</code></span></dt>
138: <dd>4 bytes (integer)</dd>
139: <dt><span class="term"><code class="varname">Desc Size</code></span></dt>
140: <dd>4 bytes (integer)</dd>
141: <dt><span class="term"><code class="varname">Type</code></span></dt>
142: <dd>4 bytes (usually interpreted as an integer)</dd>
143: <dt><span class="term"><code class="varname">Name</code></span></dt>
144: <dd>variable size, padded to a 4 byte boundary</dd>
145: <dt><span class="term"><code class="varname">Desc</code></span></dt>
146: <dd>variable size, padded to a 4 byte boundary</dd>
147: </dl></div>
148: <p>
149: </p>
150:
151: <p>
152: The "Name Size" and "Desc Size" fields are integers (in the byte order
153: specified by the binary's ELF header) which specify the size of the
154: "Name" and "Desc" fields (excluding padding).
155: </p>
156:
157: <p>
158: The "Name" field specifies the vendor who defined the format of the Note.
159: Typically, vendors use names which are related to their project and/or
160: company names. For instance, the GNU Project uses "GNU" as its name.
161: No two vendors should use the same ELF Note Name, lest there be confusion
162: when trying to interpret the meanings of notes.
163: </p>
164:
165: <p>
166: The "Type" field is vendor specific, but it is usually treated as an
167: integer which identifies the type of the note.
168: </p>
169:
170: <p>
171: The "Desc" field is vendor specific, and usually contains data which
172: depends on the note type.
173: </p>
174:
1.64 andvar 175: <h4 class="title" id="note-names">Known ELF Note Names</h4>
1.1 dsieger 176:
177: <p>
178: The following are the strings known to be used as ELF Note Names, along
179: with the organizations that use them. Names with lengths that are
180: not a multiples of 4 are padded in the note, but only the given length
181: should be checked.
182: </p>
183:
184: <div class="segmentedlist"><table border="0">
185: <thead><tr class="segtitle">
186: <th>Note Name String</th>
187: <th>Byte encoding of string</th>
188: <th>Length</th>
189: <th>Organization</th>
190: </tr></thead>
191: <tbody>
192: <tr class="seglistitem">
193: <td class="seg"><code class="code">"NetBSD\0"</code></td>
194: <td class="seg"><code class="code">0x4e 0x65 0x74 0x42 0x53 0x44 0x00</code></td>
195: <td class="seg">7</td>
1.11 dsieger 196: <td class="seg"><a class="xref" href="#note-contents-netbsd" title="The NetBSD Project">The NetBSD Project</a></td>
1.1 dsieger 197: </tr>
198: <tr class="seglistitem">
1.25 mbalmer 199: <td class="seg"><code class="code">"PaX\0"</code></td>
200: <td class="seg"><code class="code">0x50 0x61 0x58 0x00</code></td>
201: <td class="seg">4</td>
202: <td class="seg">specific to <a class="xref" href="#note-contents-netbsd" title="The NetBSD Project">The NetBSD Project</a> ? </td>
203: </tr>
204: <tr class="seglistitem">
1.1 dsieger 205: <td class="seg"><code class="code">"GNU\0"</code></td>
206: <td class="seg"><code class="code">0x47 0x4e 0x55 0x00</code></td>
207: <td class="seg">4</td>
1.11 dsieger 208: <td class="seg"><a class="xref" href="#note-contents-gnu" title="The GNU Project">The GNU Project</a></td>
1.1 dsieger 209: </tr>
210: </tbody>
211: </table></div>
212:
1.64 andvar 213: <h4 class="title" id="note-contents">Vendor-specific ELF Notes</h4>
1.1 dsieger 214:
215: <p>
216: This section contains information about the formats of ELF notes which
217: vendors use in their <code class="constant">PT_NOTE</code> sections, and is split up by vendor.
218: </p>
219:
1.64 andvar 220: <div class="sect4" id="note-contents-netbsd">
221: <div class="titlepage"><h5 class="titlepage">The NetBSD Project</h5></div>
1.1 dsieger 222:
223:
224: <p>
1.25 mbalmer 225: There are four vendor-specific ELF Notes for NetBSD and the
226: PaX note also included in this list, as currently it is
227: not know wether it is used with other operating systems
228: as well.</p>
229:
230: <p>The OS Version note
231: is used to indicate what OS Version
1.1 dsieger 232: native binaries were built with, and can be used to identify native
1.25 mbalmer 233: binaries.</p>
1.1 dsieger 234: <p>
1.25 mbalmer 235: The format is:
1.1 dsieger 236:
237: </p>
1.22 tron 238: <div class="variablelist"><dl class="variablelist">
1.1 dsieger 239: <dt><span class="term"><code class="varname">Name Size</code></span></dt>
240: <dd>7</dd>
241: <dt><span class="term"><code class="varname">Desc Size</code></span></dt>
242: <dd>4</dd>
243: <dt><span class="term"><code class="varname">Type</code></span></dt>
244: <dd>4-byte integer containing the value <code class="code">0x01</code>
245: </dd>
246: <dt><span class="term"><code class="varname">Name</code></span></dt>
247: <dd>
248: <code class="code">"NetBSD\0"</code> (padded to 8 bytes)</dd>
249: <dt><span class="term"><code class="varname">Desc</code></span></dt>
250: <dd>4-byte integer containing the NetBSD OS version constant</dd>
251: </dl></div>
252: <p>
253: </p>
254:
255: <p>
1.25 mbalmer 256: The Emulation Name note is used to mark binaries (both native an non-native) with
257: a name that indicates which set of binary emulation code is to be used
258: when they are run.</p>
259: <p>
260: The format is:
1.1 dsieger 261: </p>
1.22 tron 262: <div class="variablelist"><dl class="variablelist">
1.1 dsieger 263: <dt><span class="term"><code class="varname">Name Size</code></span></dt>
264: <dd>7</dd>
265: <dt><span class="term"><code class="varname">Desc Size</code></span></dt>
266: <dd>variable</dd>
267: <dt><span class="term"><code class="varname">Type</code></span></dt>
268: <dd>4-byte integer containing the value <code class="code">0x02</code>
269: </dd>
270: <dt><span class="term"><code class="varname">Name</code></span></dt>
271: <dd>
272: <code class="code">"NetBSD\0"</code> (padded to 8 bytes)</dd>
273: <dt><span class="term"><code class="varname">Desc</code></span></dt>
274: <dd>
275: <code class="code">NUL</code>-terminated string naming the
276: emulation to be used to run the binary
277: (padded to the next 4-byte boundary)</dd>
278: </dl></div>
279: <p>
280: </p>
1.24 mbalmer 281:
282: <p>
1.25 mbalmer 283: The PaX note encodes execution protection and addrss space
284: layout randomization flags.</p>
285: <p>
286: The format is:
1.24 mbalmer 287:
288: </p>
289: <div class="variablelist"><dl class="variablelist">
290: <dt><span class="term"><code class="varname">Name Size</code></span></dt>
291: <dd>4</dd>
292: <dt><span class="term"><code class="varname">Desc Size</code></span></dt>
293: <dd>4</dd>
294: <dt><span class="term"><code class="varname">Type</code></span></dt>
295: <dd>4-byte integer containing the value <code class="code">0x03</code>
296: </dd>
297: <dt><span class="term"><code class="varname">Name</code></span></dt>
1.25 mbalmer 298: <dd><code class="code">"PaX\0"</code></dd>
1.24 mbalmer 299: <dt><span class="term"><code class="varname">Desc</code></span></dt>
300: <dd>4-byte bitmask with the following bits:
301: <div class="segmentedlist"><table border="0">
302: <thead><tr class="segtitle">
303: <th>Bit</th>
304: <th>Meaning</th>
305: </tr></thead>
306: <tbody>
307: <tr class="seglistitem">
308: <td class="seg"><code class="code">0x01</code></td>
309: <td class="seg">Force enable Mprotect</td>
310: </tr>
311: <tr class="seglistitem">
312: <td class="seg"><code class="code">0x02</code></td>
313: <td class="seg">Force disable Mprotect</td>
314: </tr>
315: <tr class="seglistitem">
316: <td class="seg"><code class="code">0x04</code></td>
317: <td class="seg">Force enable Segvguard</td>
318: </tr>
319: <tr class="seglistitem">
320: <td class="seg"><code class="code">0x08</code></td>
321: <td class="seg">Force disable Segvguard</td>
322: </tr>
323: <tr class="seglistitem">
324: <td class="seg"><code class="code">0x10</code></td>
325: <td class="seg">Force enable ASLR</td>
326: </tr>
327: <tr class="seglistitem">
328: <td class="seg"><code class="code">0x20</code></td>
329: <td class="seg">Force disable ASLR</td>
330: </tr>
331: </tbody>
332: </table></div>
333: </dd>
334: </dl></div>
335: <p>
336: </p>
337:
338: <p>
1.25 mbalmer 339: The Architecture Note encodes machine architecture details.</p>
340: <p>
341: The format is:
1.24 mbalmer 342:
343: </p>
344: <div class="variablelist"><dl class="variablelist">
345: <dt><span class="term"><code class="varname">Name Size</code></span></dt>
346: <dd>7</dd>
347: <dt><span class="term"><code class="varname">Desc Size</code></span></dt>
348: <dd>variable</dd>
349: <dt><span class="term"><code class="varname">Type</code></span></dt>
350: <dd>4-byte integer containing the value <code class="code">0x05</code>
351: </dd>
352: <dt><span class="term"><code class="varname">Name</code></span></dt>
353: <dd>
354: <code class="code">"NetBSD\0"</code> (padded to 8 bytes)</dd>
355: <dt><span class="term"><code class="varname">Desc</code></span></dt>
356: <dd>A string describing the architecture the binary was
357: compiled for (for example used on ARM to distinguish
358: hardware floating point ABI and softfloat)</dd>
359: </dl></div>
360: <p>
361: </p>
362:
363: <p>
1.25 mbalmer 364: The Code Model Note encodes code model details.</p>
365: <p>
366: The format is:
1.24 mbalmer 367:
368: </p>
369: <div class="variablelist"><dl class="variablelist">
370: <dt><span class="term"><code class="varname">Name Size</code></span></dt>
371: <dd>7</dd>
372: <dt><span class="term"><code class="varname">Desc Size</code></span></dt>
373: <dd>variable</dd>
374: <dt><span class="term"><code class="varname">Type</code></span></dt>
375: <dd>4-byte integer containing the value <code class="code">0x06</code>
376: </dd>
377: <dt><span class="term"><code class="varname">Name</code></span></dt>
378: <dd>
379: <code class="code">"NetBSD\0"</code> (padded to 8 bytes)</dd>
380: <dt><span class="term"><code class="varname">Desc</code></span></dt>
381: <dd>A string describing the code model the binary was
382: compiled for. Used for example on sparc64 to tell
383: binaries compiled with -mcmodel=medlow apart from
1.25 mbalmer 384: standard (-mcmodel=medmid) ones, because the former
1.24 mbalmer 385: are not eligible for top-down virtual memory
386: layout.</dd>
387: </dl></div>
388: <p>
389: </p>
390:
1.1 dsieger 391: </div>
392:
1.64 andvar 393: <div class="sect4" id="note-contents-gnu">
394: <div class="titlepage"><h5 class="titlepage">The GNU Project</h5></div>
1.1 dsieger 395:
396:
397: <p>
398: Starting with glibc 2.1, the GNU project will be using a single ELF Note
399: to indicate which GNU operating system and which version of that system
400: a binary was built for. The format of that note is:
401: </p>
1.22 tron 402: <div class="variablelist"><dl class="variablelist">
1.1 dsieger 403: <dt><span class="term"><code class="varname">Name Size</code></span></dt>
404: <dd>4</dd>
405: <dt><span class="term"><code class="varname">Desc Size</code></span></dt>
406: <dd>16</dd>
407: <dt><span class="term"><code class="varname">Type</code></span></dt>
408: <dd>4-byte integer containing the value <code class="code">0x01</code>
409: </dd>
410: <dt><span class="term"><code class="varname">Name</code></span></dt>
411: <dd><code class="code">"GNU\0"</code></dd>
412: <dt><span class="term"><code class="varname">Desc</code></span></dt>
413: <dd>
414: Four 4-byte integers containing, in order:
1.15 spz 415: <div class="orderedlist"><ol class="orderedlist" type="1">
416: <li class="listitem">OS (0 = Linux, 1 = Hurd, 2 = Solaris)</li>
417: <li class="listitem">Major</li>
418: <li class="listitem">Minor</li>
419: <li class="listitem">Teeny</li>
1.1 dsieger 420: </ol></div>
421: The major, minor and teeny versions are that of the earliest OS version that supports this ABI.
422: </dd>
423: </dl></div>
424: <p>
425: </p>
426:
427: <p>
428: For more documentation on the GNU C Library's use of ELF notes,
429: consult the sources:
1.11 dsieger 430: <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 431: and
1.11 dsieger 432: <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 433: </p>
434: </div>
435:
1.64 andvar 436: <h4 class="title" id="note-creation">Creating ELF <code class="constant">PT_NOTE</code> Sections</h4>
1.1 dsieger 437:
438: <p>
439: If you're using the GNU binutils 2.8 or greater to create your binaries,
440: you can generate <code class="constant">PT_NOTE</code> sections in your final object files.
441: To create a <code class="constant">PT_NOTE</code> section, create a section in one of your object
442: files (for systems which generate <code class="constant">PT_NOTE</code> entries by default, this
443: is typically the runtime startup code) with a name starting
444: with ".note" and having the "allocate" property set.
445: Put properly formed ELF Notes entries in that section.
446: When final linking is done, all sections which have names starting
447: with ".note" and which are marked "allocate" will be put into <code class="constant">PT_NOTE</code>
448: sections in the final object file.
449: </p>
450: <p>
451: An example of GNU assembler input which will create a <code class="constant">PT_NOTE</code> section
452: during final link is:
453: </p>
454: <pre class="programlisting">
455: .section ".note.ident", "a"
456: .p2align 2
457: .long 1f - 0f # name size (not including padding)
458: .long 3f - 2f # desc size (not including padding)
459: .long 0x01234567 # type
460: 0: .asciz "NaMe" # name
461: 1: .p2align 2
462: 2: .long 0x76543210 # desc
463: .long 0x89abcdef
464: 3: .p2align 2
465: </pre>
466:
467: <p>
468: That example will create a section called ".note.ident", marked
469: "allocate" (so that it will be turned into a
470: <code class="constant">PT_NOTE</code> section during final link), which
471: contains a single note. That note has a <code class="varname">type</code> of
472: <code class="code">0x012345678</code>, has the <code class="varname">name</code>
473: <code class="code">"NaMe\0"</code>, and has a <code class="varname">desc</code> value
474: consisting of two 4-byte integers, <code class="code">0x76543210</code> and
475: <code class="code">0x89abcdef</code>.
476: </p>
477:
1.64 andvar 478: <h4 class="title" id="netbsd-note">Creating a NetBSD ELF <code class="constant">PT_NOTE</code> Section</h4>
1.1 dsieger 479:
480: <p>
481: The NetBSD kernel will return ENOEXEC if an ELF binary does not contain
482: a recognized <code class="constant">PT_NOTE</code> section. Normally, <code class="filename">crtbegin.c</code>
483: contains this section
484: for native NetBSD applications. The example below creates such a section
1.10 martin 485: on NetBSD/sparc. (Other ports may use slightly different assembler syntax,
486: for example arm uses %note - since @ starts a comment,
1.1 dsieger 487: but, except for endian variations, they all use the same bits.)
488: </p>
489: <pre class="programlisting">
1.10 martin 490: .section ".note.netbsd.ident", "", @note
1.1 dsieger 491: .long 2f-1f
492: .long 4f-3f
493: .long 1
494: 1: .asciz "NetBSD"
495: 2: .p2align 2
1.10 martin 496: 3: .long 499003600
1.1 dsieger 497: 4: .p2align 2
498: </pre>
1.3 dsieger 499: </div></div></div>
500: <div class="navfoot"></div>
1.64 andvar 501: <div id="footer"><div id="footerContent">
502: <span class="footfeed"><a href="//www.NetBSD.org/cgi-bin/feedback.cgi">
1.3 dsieger 503: Contact</a> |
1.9 kano 504: </span><span class="footcopy"><a href="../../about/disclaimer.html">
1.3 dsieger 505: Disclaimer</a> |
506:
1.65 leot 507: <span class="copyright">Copyright © 1994-2026 The NetBSD Foundation, Inc. </span>ALL RIGHTS RESERVED.<br>NetBSD<sup>®</sup> is a registered trademark of The NetBSD
1.64 andvar 508: Foundation, Inc.</span>
509: </div></div>
1.1 dsieger 510: </div></body>
511: </html>
CVSweb <webmaster@jp.NetBSD.org>