選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

156 行
7.3KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1992-2020 Free Software Foundation, Inc.
  4. Contributed by Cygnus Support. Written by Julia Menapace, Jim Kingdon,
  5. and David MacKenzie.
  6. Permission is granted to copy, distribute and/or modify this document
  7. under the terms of the GNU Free Documentation License, Version 1.3 or
  8. any later version published by the Free Software Foundation; with no
  9. Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
  10. Texts. A copy of the license is included in the section entitled "GNU
  11. Free Documentation License". -->
  12. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  13. <head>
  14. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  15. <title>Stab Section Basics (STABS)</title>
  16. <meta name="description" content="Stab Section Basics (STABS)">
  17. <meta name="keywords" content="Stab Section Basics (STABS)">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  21. <link href="index.html#Top" rel="start" title="Top">
  22. <link href="Symbol-Types-Index.html#Symbol-Types-Index" rel="index" title="Symbol Types Index">
  23. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  24. <link href="Stab-Sections.html#Stab-Sections" rel="up" title="Stab Sections">
  25. <link href="ELF-Linker-Relocation.html#ELF-Linker-Relocation" rel="next" title="ELF Linker Relocation">
  26. <link href="Stab-Sections.html#Stab-Sections" rel="prev" title="Stab Sections">
  27. <style type="text/css">
  28. <!--
  29. a.summary-letter {text-decoration: none}
  30. blockquote.indentedblock {margin-right: 0em}
  31. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  32. blockquote.smallquotation {font-size: smaller}
  33. div.display {margin-left: 3.2em}
  34. div.example {margin-left: 3.2em}
  35. div.lisp {margin-left: 3.2em}
  36. div.smalldisplay {margin-left: 3.2em}
  37. div.smallexample {margin-left: 3.2em}
  38. div.smalllisp {margin-left: 3.2em}
  39. kbd {font-style: oblique}
  40. pre.display {font-family: inherit}
  41. pre.format {font-family: inherit}
  42. pre.menu-comment {font-family: serif}
  43. pre.menu-preformatted {font-family: serif}
  44. pre.smalldisplay {font-family: inherit; font-size: smaller}
  45. pre.smallexample {font-size: smaller}
  46. pre.smallformat {font-family: inherit; font-size: smaller}
  47. pre.smalllisp {font-size: smaller}
  48. span.nolinebreak {white-space: nowrap}
  49. span.roman {font-family: initial; font-weight: normal}
  50. span.sansserif {font-family: sans-serif; font-weight: normal}
  51. ul.no-bullet {list-style: none}
  52. -->
  53. </style>
  54. </head>
  55. <body lang="en">
  56. <a name="Stab-Section-Basics"></a>
  57. <div class="header">
  58. <p>
  59. Next: <a href="ELF-Linker-Relocation.html#ELF-Linker-Relocation" accesskey="n" rel="next">ELF Linker Relocation</a>, Up: <a href="Stab-Sections.html#Stab-Sections" accesskey="u" rel="up">Stab Sections</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Types-Index.html#Symbol-Types-Index" title="Index" rel="index">Index</a>]</p>
  60. </div>
  61. <hr>
  62. <a name="How-to-Embed-Stabs-in-Sections"></a>
  63. <h3 class="appendixsec">F.1 How to Embed Stabs in Sections</h3>
  64. <p>The assembler creates two custom sections, a section named <code>.stab</code>
  65. which contains an array of fixed length structures, one struct per stab,
  66. and a section named <code>.stabstr</code> containing all the variable length
  67. strings that are referenced by stabs in the <code>.stab</code> section. The
  68. byte order of the stabs binary data depends on the object file format.
  69. For ELF, it matches the byte order of the ELF file itself, as determined
  70. from the <code>EI_DATA</code> field in the <code>e_ident</code> member of the ELF
  71. header. For SOM, it is always big-endian (is this true??? FIXME). For
  72. COFF, it matches the byte order of the COFF headers. The meaning of the
  73. fields is the same as for a.out (see <a href="Symbol-Table-Format.html#Symbol-Table-Format">Symbol Table Format</a>), except
  74. that the <code>n_strx</code> field is relative to the strings for the current
  75. compilation unit (which can be found using the synthetic N_UNDF stab
  76. described below), rather than the entire string table.
  77. </p>
  78. <p>The first stab in the <code>.stab</code> section for each compilation unit is
  79. synthetic, generated entirely by the assembler, with no corresponding
  80. <code>.stab</code> directive as input to the assembler. This stab contains
  81. the following fields:
  82. </p>
  83. <dl compact="compact">
  84. <dt><code>n_strx</code></dt>
  85. <dd><p>Offset in the <code>.stabstr</code> section to the source filename.
  86. </p>
  87. </dd>
  88. <dt><code>n_type</code></dt>
  89. <dd><p><code>N_UNDF</code>.
  90. </p>
  91. </dd>
  92. <dt><code>n_other</code></dt>
  93. <dd><p>Unused field, always zero.
  94. This may eventually be used to hold overflows from the count in
  95. the <code>n_desc</code> field.
  96. </p>
  97. </dd>
  98. <dt><code>n_desc</code></dt>
  99. <dd><p>Count of upcoming symbols, i.e., the number of remaining stabs for this
  100. source file.
  101. </p>
  102. </dd>
  103. <dt><code>n_value</code></dt>
  104. <dd><p>Size of the string table fragment associated with this source file, in
  105. bytes.
  106. </p></dd>
  107. </dl>
  108. <p>The <code>.stabstr</code> section always starts with a null byte (so that string
  109. offsets of zero reference a null string), followed by random length strings,
  110. each of which is null byte terminated.
  111. </p>
  112. <p>The ELF section header for the <code>.stab</code> section has its
  113. <code>sh_link</code> member set to the section number of the <code>.stabstr</code>
  114. section, and the <code>.stabstr</code> section has its ELF section
  115. header <code>sh_type</code> member set to <code>SHT_STRTAB</code> to mark it as a
  116. string table. SOM and COFF have no way of linking the sections together
  117. or marking them as string tables.
  118. </p>
  119. <p>For COFF, the <code>.stab</code> and <code>.stabstr</code> sections may be simply
  120. concatenated by the linker. GDB then uses the <code>n_desc</code> fields to
  121. figure out the extent of the original sections. Similarly, the
  122. <code>n_value</code> fields of the header symbols are added together in order
  123. to get the actual position of the strings in a desired <code>.stabstr</code>
  124. section. Although this design obviates any need for the linker to
  125. relocate or otherwise manipulate <code>.stab</code> and <code>.stabstr</code>
  126. sections, it also requires some care to ensure that the offsets are
  127. calculated correctly. For instance, if the linker were to pad in
  128. between the <code>.stabstr</code> sections before concatenating, then the
  129. offsets to strings in the middle of the executable&rsquo;s <code>.stabstr</code>
  130. section would be wrong.
  131. </p>
  132. <p>The GNU linker is able to optimize stabs information by merging
  133. duplicate strings and removing duplicate header file information
  134. (see <a href="Include-Files.html#Include-Files">Include Files</a>). When some versions of the GNU linker optimize
  135. stabs in sections, they remove the leading <code>N_UNDF</code> symbol and
  136. arranges for all the <code>n_strx</code> fields to be relative to the start of
  137. the <code>.stabstr</code> section.
  138. </p>
  139. <hr>
  140. <div class="header">
  141. <p>
  142. Next: <a href="ELF-Linker-Relocation.html#ELF-Linker-Relocation" accesskey="n" rel="next">ELF Linker Relocation</a>, Up: <a href="Stab-Sections.html#Stab-Sections" accesskey="u" rel="up">Stab Sections</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Types-Index.html#Symbol-Types-Index" title="Index" rel="index">Index</a>]</p>
  143. </div>
  144. </body>
  145. </html>