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