Writing-the-symbol-table.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- This file documents the BFD library.
  4. Copyright (C) 1991-2017 Free Software Foundation, Inc.
  5. Permission is granted to copy, distribute and/or modify this document
  6. under the terms of the GNU Free Documentation License, Version 1.3 or
  7. any later version published by the Free Software Foundation; with the
  8. Invariant Sections being "GNU General Public License" and "Funding
  9. Free Software", the Front-Cover texts being (a) (see below), and with
  10. the Back-Cover Texts being (b) (see below). A copy of the license is
  11. included in the section entitled "GNU Free Documentation License".
  12. (a) The FSF's Front-Cover Text is:
  13. A GNU Manual
  14. (b) The FSF's Back-Cover Text is:
  15. You have freedom to copy and modify this GNU Manual, like GNU
  16. software. Copies published by the Free Software Foundation raise
  17. funds for GNU development. -->
  18. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  19. <head>
  20. <title>Untitled Document: Writing the symbol table</title>
  21. <meta name="description" content="Untitled Document: Writing the symbol table">
  22. <meta name="keywords" content="Untitled Document: Writing the symbol table">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  26. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  27. <link href="index.html#Top" rel="start" title="Top">
  28. <link href="BFD-Index.html#BFD-Index" rel="index" title="BFD Index">
  29. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  30. <link href="Performing-the-Final-Link.html#Performing-the-Final-Link" rel="up" title="Performing the Final Link">
  31. <link href="Hash-Tables.html#Hash-Tables" rel="next" title="Hash Tables">
  32. <link href="Relocating-the-section-contents.html#Relocating-the-section-contents" rel="prev" title="Relocating the section contents">
  33. <style type="text/css">
  34. <!--
  35. a.summary-letter {text-decoration: none}
  36. blockquote.smallquotation {font-size: smaller}
  37. div.display {margin-left: 3.2em}
  38. div.example {margin-left: 3.2em}
  39. div.indentedblock {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  43. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  44. div.smalllisp {margin-left: 3.2em}
  45. kbd {font-style:oblique}
  46. pre.display {font-family: inherit}
  47. pre.format {font-family: inherit}
  48. pre.menu-comment {font-family: serif}
  49. pre.menu-preformatted {font-family: serif}
  50. pre.smalldisplay {font-family: inherit; font-size: smaller}
  51. pre.smallexample {font-size: smaller}
  52. pre.smallformat {font-family: inherit; font-size: smaller}
  53. pre.smalllisp {font-size: smaller}
  54. span.nocodebreak {white-space:nowrap}
  55. span.nolinebreak {white-space:nowrap}
  56. span.roman {font-family:serif; font-weight:normal}
  57. span.sansserif {font-family:sans-serif; font-weight:normal}
  58. ul.no-bullet {list-style: none}
  59. -->
  60. </style>
  61. </head>
  62. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  63. <a name="Writing-the-symbol-table"></a>
  64. <div class="header">
  65. <p>
  66. Previous: <a href="Relocating-the-section-contents.html#Relocating-the-section-contents" accesskey="p" rel="prev">Relocating the section contents</a>, Up: <a href="Performing-the-Final-Link.html#Performing-the-Final-Link" accesskey="u" rel="up">Performing the Final Link</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="BFD-Index.html#BFD-Index" title="Index" rel="index">Index</a>]</p>
  67. </div>
  68. <hr>
  69. <a name="Writing-the-symbol-table-1"></a>
  70. <h4 class="subsubsection">2.17.3.3 Writing the symbol table</h4>
  71. <p>The <code>_bfd_final_link</code> function must gather all the symbols
  72. in the input files and write them out. It must also write out
  73. all the symbols in the global hash table. This must be
  74. controlled by the <code>strip</code> and <code>discard</code> fields of the
  75. <code>bfd_link_info</code> structure.
  76. </p>
  77. <p>The local symbols of the input files will not have been
  78. entered into the linker hash table. The <code>_bfd_final_link</code>
  79. routine must consider each input file and include the symbols
  80. in the output file. It may be convenient to do this when
  81. looking through the <code>link_order</code> structures, or it may be
  82. done by stepping through the <code>input_bfds</code> list.
  83. </p>
  84. <p>The <code>_bfd_final_link</code> routine must also traverse the global
  85. hash table to gather all the externally visible symbols. It
  86. is possible that most of the externally visible symbols may be
  87. written out when considering the symbols of each input file,
  88. but it is still necessary to traverse the hash table since the
  89. linker script may have defined some symbols that are not in
  90. any of the input files.
  91. </p>
  92. <p>The <code>strip</code> field of the <code>bfd_link_info</code> structure
  93. controls which symbols are written out. The possible values
  94. are listed in <code>bfdlink.h</code>. If the value is <code>strip_some</code>,
  95. then the <code>keep_hash</code> field of the <code>bfd_link_info</code>
  96. structure is a hash table of symbols to keep; each symbol
  97. should be looked up in this hash table, and only symbols which
  98. are present should be included in the output file.
  99. </p>
  100. <p>If the <code>strip</code> field of the <code>bfd_link_info</code> structure
  101. permits local symbols to be written out, the <code>discard</code> field
  102. is used to further controls which local symbols are included
  103. in the output file. If the value is <code>discard_l</code>, then all
  104. local symbols which begin with a certain prefix are discarded;
  105. this is controlled by the <code>bfd_is_local_label_name</code> entry point.
  106. </p>
  107. <p>The a.out backend handles symbols by calling
  108. <code>aout_link_write_symbols</code> on each input BFD and then
  109. traversing the global hash table with the function
  110. <code>aout_link_write_other_symbol</code>. It builds a string table
  111. while writing out the symbols, which is written to the output
  112. file at the end of <code>NAME(aout,final_link)</code>.
  113. </p>
  114. <a name="index-bfd_005flink_005fsplit_005fsection"></a>
  115. <a name="bfd_005flink_005fsplit_005fsection"></a>
  116. <h4 class="subsubsection">2.17.3.4 <code>bfd_link_split_section</code></h4>
  117. <p><strong>Synopsis</strong>
  118. </p><div class="example">
  119. <pre class="example">bfd_boolean bfd_link_split_section (bfd *abfd, asection *sec);
  120. </pre></div>
  121. <p><strong>Description</strong><br>
  122. Return nonzero if <var>sec</var> should be split during a
  123. reloceatable or final link.
  124. </p><div class="example">
  125. <pre class="example">#define bfd_link_split_section(abfd, sec) \
  126. BFD_SEND (abfd, _bfd_link_split_section, (abfd, sec))
  127. </pre></div>
  128. <a name="index-bfd_005fsection_005falready_005flinked"></a>
  129. <a name="bfd_005fsection_005falready_005flinked"></a>
  130. <h4 class="subsubsection">2.17.3.5 <code>bfd_section_already_linked</code></h4>
  131. <p><strong>Synopsis</strong>
  132. </p><div class="example">
  133. <pre class="example">bfd_boolean bfd_section_already_linked (bfd *abfd,
  134. asection *sec,
  135. struct bfd_link_info *info);
  136. </pre></div>
  137. <p><strong>Description</strong><br>
  138. Check if <var>data</var> has been already linked during a reloceatable
  139. or final link. Return TRUE if it has.
  140. </p><div class="example">
  141. <pre class="example">#define bfd_section_already_linked(abfd, sec, info) \
  142. BFD_SEND (abfd, _section_already_linked, (abfd, sec, info))
  143. </pre></div>
  144. <a name="index-bfd_005fgeneric_005fdefine_005fcommon_005fsymbol"></a>
  145. <a name="bfd_005fgeneric_005fdefine_005fcommon_005fsymbol"></a>
  146. <h4 class="subsubsection">2.17.3.6 <code>bfd_generic_define_common_symbol</code></h4>
  147. <p><strong>Synopsis</strong>
  148. </p><div class="example">
  149. <pre class="example">bfd_boolean bfd_generic_define_common_symbol
  150. (bfd *output_bfd, struct bfd_link_info *info,
  151. struct bfd_link_hash_entry *h);
  152. </pre></div>
  153. <p><strong>Description</strong><br>
  154. Convert common symbol <var>h</var> into a defined symbol.
  155. Return TRUE on success and FALSE on failure.
  156. </p><div class="example">
  157. <pre class="example">#define bfd_define_common_symbol(output_bfd, info, h) \
  158. BFD_SEND (output_bfd, _bfd_define_common_symbol, (output_bfd, info, h))
  159. </pre></div>
  160. <a name="index-bfd_005ffind_005fversion_005ffor_005fsym"></a>
  161. <a name="bfd_005ffind_005fversion_005ffor_005fsym"></a>
  162. <h4 class="subsubsection">2.17.3.7 <code>bfd_find_version_for_sym</code></h4>
  163. <p><strong>Synopsis</strong>
  164. </p><div class="example">
  165. <pre class="example">struct bfd_elf_version_tree * bfd_find_version_for_sym
  166. (struct bfd_elf_version_tree *verdefs,
  167. const char *sym_name, bfd_boolean *hide);
  168. </pre></div>
  169. <p><strong>Description</strong><br>
  170. Search an elf version script tree for symbol versioning
  171. info and export / don&rsquo;t-export status for a given symbol.
  172. Return non-NULL on success and NULL on failure; also sets
  173. the output &lsquo;<samp>hide</samp>&rsquo; boolean parameter.
  174. </p>
  175. <a name="index-bfd_005fhide_005fsym_005fby_005fversion"></a>
  176. <a name="bfd_005fhide_005fsym_005fby_005fversion"></a>
  177. <h4 class="subsubsection">2.17.3.8 <code>bfd_hide_sym_by_version</code></h4>
  178. <p><strong>Synopsis</strong>
  179. </p><div class="example">
  180. <pre class="example">bfd_boolean bfd_hide_sym_by_version
  181. (struct bfd_elf_version_tree *verdefs, const char *sym_name);
  182. </pre></div>
  183. <p><strong>Description</strong><br>
  184. Search an elf version script tree for symbol versioning
  185. info for a given symbol. Return TRUE if the symbol is hidden.
  186. </p>
  187. <a name="index-bfd_005flink_005fcheck_005frelocs"></a>
  188. <a name="bfd_005flink_005fcheck_005frelocs"></a>
  189. <h4 class="subsubsection">2.17.3.9 <code>bfd_link_check_relocs</code></h4>
  190. <p><strong>Synopsis</strong>
  191. </p><div class="example">
  192. <pre class="example">bfd_boolean bfd_link_check_relocs
  193. (bfd *abfd, struct bfd_link_info *info);
  194. </pre></div>
  195. <p><strong>Description</strong><br>
  196. Checks the relocs in ABFD for validity.
  197. Does not execute the relocs.
  198. Return TRUE if everything is OK, FALSE otherwise.
  199. This is the external entry point to this code.
  200. </p>
  201. <a name="index-_005fbfd_005fgeneric_005flink_005fcheck_005frelocs"></a>
  202. <a name="g_t_005fbfd_005fgeneric_005flink_005fcheck_005frelocs"></a>
  203. <h4 class="subsubsection">2.17.3.10 <code>_bfd_generic_link_check_relocs</code></h4>
  204. <p><strong>Synopsis</strong>
  205. </p><div class="example">
  206. <pre class="example">bfd_boolean _bfd_generic_link_check_relocs
  207. (bfd *abfd, struct bfd_link_info *info);
  208. </pre></div>
  209. <p><strong>Description</strong><br>
  210. Stub function for targets that do not implement reloc checking.
  211. Return TRUE.
  212. This is an internal function. It should not be called from
  213. outside the BFD library.
  214. </p>
  215. <a name="index-bfd_005fmerge_005fprivate_005fbfd_005fdata"></a>
  216. <a name="bfd_005fmerge_005fprivate_005fbfd_005fdata"></a>
  217. <h4 class="subsubsection">2.17.3.11 <code>bfd_merge_private_bfd_data</code></h4>
  218. <p><strong>Synopsis</strong>
  219. </p><div class="example">
  220. <pre class="example">bfd_boolean bfd_merge_private_bfd_data
  221. (bfd *ibfd, struct bfd_link_info *info);
  222. </pre></div>
  223. <p><strong>Description</strong><br>
  224. Merge private BFD information from the BFD <var>ibfd</var> to the
  225. the output file BFD when linking. Return <code>TRUE</code> on success,
  226. <code>FALSE</code> on error. Possible error returns are:
  227. </p>
  228. <ul>
  229. <li> <code>bfd_error_no_memory</code> -
  230. Not enough memory exists to create private data for <var>obfd</var>.
  231. </li></ul>
  232. <div class="example">
  233. <pre class="example">#define bfd_merge_private_bfd_data(ibfd, info) \
  234. BFD_SEND ((info)-&gt;output_bfd, _bfd_merge_private_bfd_data, \
  235. (ibfd, info))
  236. </pre></div>
  237. <a name="index-_005fbfd_005fgeneric_005fverify_005fendian_005fmatch"></a>
  238. <a name="g_t_005fbfd_005fgeneric_005fverify_005fendian_005fmatch"></a>
  239. <h4 class="subsubsection">2.17.3.12 <code>_bfd_generic_verify_endian_match</code></h4>
  240. <p><strong>Synopsis</strong>
  241. </p><div class="example">
  242. <pre class="example">bfd_boolean _bfd_generic_verify_endian_match
  243. (bfd *ibfd, struct bfd_link_info *info);
  244. </pre></div>
  245. <p><strong>Description</strong><br>
  246. Can be used from / for bfd_merge_private_bfd_data to check that
  247. endianness matches between input and output file. Returns
  248. TRUE for a match, otherwise returns FALSE and emits an error.
  249. </p>
  250. <hr>
  251. <div class="header">
  252. <p>
  253. Previous: <a href="Relocating-the-section-contents.html#Relocating-the-section-contents" accesskey="p" rel="prev">Relocating the section contents</a>, Up: <a href="Performing-the-Final-Link.html#Performing-the-Final-Link" accesskey="u" rel="up">Performing the Final Link</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="BFD-Index.html#BFD-Index" title="Index" rel="index">Index</a>]</p>
  254. </div>
  255. </body>
  256. </html>