coff.html 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  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: coff</title>
  21. <meta name="description" content="Untitled Document: coff">
  22. <meta name="keywords" content="Untitled Document: coff">
  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="BFD-back-ends.html#BFD-back-ends" rel="up" title="BFD back ends">
  31. <link href="elf.html#elf" rel="next" title="elf">
  32. <link href="aout.html#aout" rel="prev" title="aout">
  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="coff"></a>
  64. <div class="header">
  65. <p>
  66. Next: <a href="elf.html#elf" accesskey="n" rel="next">elf</a>, Previous: <a href="aout.html#aout" accesskey="p" rel="prev">aout</a>, Up: <a href="BFD-back-ends.html#BFD-back-ends" accesskey="u" rel="up">BFD back ends</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="coff-backends"></a>
  70. <h3 class="section">3.3 coff backends</h3>
  71. <p>BFD supports a number of different flavours of coff format.
  72. The major differences between formats are the sizes and
  73. alignments of fields in structures on disk, and the occasional
  74. extra field.
  75. </p>
  76. <p>Coff in all its varieties is implemented with a few common
  77. files and a number of implementation specific files. For
  78. example, The 88k bcs coff format is implemented in the file
  79. <samp>coff-m88k.c</samp>. This file <code>#include</code>s
  80. <samp>coff/m88k.h</samp> which defines the external structure of the
  81. coff format for the 88k, and <samp>coff/internal.h</samp> which
  82. defines the internal structure. <samp>coff-m88k.c</samp> also
  83. defines the relocations used by the 88k format
  84. See <a href="Relocations.html#Relocations">Relocations</a>.
  85. </p>
  86. <p>The Intel i960 processor version of coff is implemented in
  87. <samp>coff-i960.c</samp>. This file has the same structure as
  88. <samp>coff-m88k.c</samp>, except that it includes <samp>coff/i960.h</samp>
  89. rather than <samp>coff-m88k.h</samp>.
  90. </p>
  91. <a name="Porting-to-a-new-version-of-coff"></a>
  92. <h4 class="subsection">3.3.1 Porting to a new version of coff</h4>
  93. <p>The recommended method is to select from the existing
  94. implementations the version of coff which is most like the one
  95. you want to use. For example, we&rsquo;ll say that i386 coff is
  96. the one you select, and that your coff flavour is called foo.
  97. Copy <samp>i386coff.c</samp> to <samp>foocoff.c</samp>, copy
  98. <samp>../include/coff/i386.h</samp> to <samp>../include/coff/foo.h</samp>,
  99. and add the lines to <samp>targets.c</samp> and <samp>Makefile.in</samp>
  100. so that your new back end is used. Alter the shapes of the
  101. structures in <samp>../include/coff/foo.h</samp> so that they match
  102. what you need. You will probably also have to add
  103. <code>#ifdef</code>s to the code in <samp>coff/internal.h</samp> and
  104. <samp>coffcode.h</samp> if your version of coff is too wild.
  105. </p>
  106. <p>You can verify that your new BFD backend works quite simply by
  107. building <samp>objdump</samp> from the <samp>binutils</samp> directory,
  108. and making sure that its version of what&rsquo;s going on and your
  109. host system&rsquo;s idea (assuming it has the pretty standard coff
  110. dump utility, usually called <code>att-dump</code> or just
  111. <code>dump</code>) are the same. Then clean up your code, and send
  112. what you&rsquo;ve done to Cygnus. Then your stuff will be in the
  113. next release, and you won&rsquo;t have to keep integrating it.
  114. </p>
  115. <a name="How-the-coff-backend-works"></a>
  116. <h4 class="subsection">3.3.2 How the coff backend works</h4>
  117. <a name="File-layout-1"></a>
  118. <h4 class="subsubsection">3.3.2.1 File layout</h4>
  119. <p>The Coff backend is split into generic routines that are
  120. applicable to any Coff target and routines that are specific
  121. to a particular target. The target-specific routines are
  122. further split into ones which are basically the same for all
  123. Coff targets except that they use the external symbol format
  124. or use different values for certain constants.
  125. </p>
  126. <p>The generic routines are in <samp>coffgen.c</samp>. These routines
  127. work for any Coff target. They use some hooks into the target
  128. specific code; the hooks are in a <code>bfd_coff_backend_data</code>
  129. structure, one of which exists for each target.
  130. </p>
  131. <p>The essentially similar target-specific routines are in
  132. <samp>coffcode.h</samp>. This header file includes executable C code.
  133. The various Coff targets first include the appropriate Coff
  134. header file, make any special defines that are needed, and
  135. then include <samp>coffcode.h</samp>.
  136. </p>
  137. <p>Some of the Coff targets then also have additional routines in
  138. the target source file itself.
  139. </p>
  140. <p>For example, <samp>coff-i960.c</samp> includes
  141. <samp>coff/internal.h</samp> and <samp>coff/i960.h</samp>. It then
  142. defines a few constants, such as <code>I960</code>, and includes
  143. <samp>coffcode.h</samp>. Since the i960 has complex relocation
  144. types, <samp>coff-i960.c</samp> also includes some code to
  145. manipulate the i960 relocs. This code is not in
  146. <samp>coffcode.h</samp> because it would not be used by any other
  147. target.
  148. </p>
  149. <a name="Coff-long-section-names"></a>
  150. <h4 class="subsubsection">3.3.2.2 Coff long section names</h4>
  151. <p>In the standard Coff object format, section names are limited to
  152. the eight bytes available in the <code>s_name</code> field of the
  153. <code>SCNHDR</code> section header structure. The format requires the
  154. field to be NUL-padded, but not necessarily NUL-terminated, so
  155. the longest section names permitted are a full eight characters.
  156. </p>
  157. <p>The Microsoft PE variants of the Coff object file format add
  158. an extension to support the use of long section names. This
  159. extension is defined in section 4 of the Microsoft PE/COFF
  160. specification (rev 8.1). If a section name is too long to fit
  161. into the section header&rsquo;s <code>s_name</code> field, it is instead
  162. placed into the string table, and the <code>s_name</code> field is
  163. filled with a slash (&quot;/&quot;) followed by the ASCII decimal
  164. representation of the offset of the full name relative to the
  165. string table base.
  166. </p>
  167. <p>Note that this implies that the extension can only be used in object
  168. files, as executables do not contain a string table. The standard
  169. specifies that long section names from objects emitted into executable
  170. images are to be truncated.
  171. </p>
  172. <p>However, as a GNU extension, BFD can generate executable images
  173. that contain a string table and long section names. This
  174. would appear to be technically valid, as the standard only says
  175. that Coff debugging information is deprecated, not forbidden,
  176. and in practice it works, although some tools that parse PE files
  177. expecting the MS standard format may become confused; <samp>PEview</samp> is
  178. one known example.
  179. </p>
  180. <p>The functionality is supported in BFD by code implemented under
  181. the control of the macro <code>COFF_LONG_SECTION_NAMES</code>. If not
  182. defined, the format does not support long section names in any way.
  183. If defined, it is used to initialise a flag,
  184. <code>_bfd_coff_long_section_names</code>, and a hook function pointer,
  185. <code>_bfd_coff_set_long_section_names</code>, in the Coff backend data
  186. structure. The flag controls the generation of long section names
  187. in output BFDs at runtime; if it is false, as it will be by default
  188. when generating an executable image, long section names are truncated;
  189. if true, the long section names extension is employed. The hook
  190. points to a function that allows the value of the flag to be altered
  191. at runtime, on formats that support long section names at all; on
  192. other formats it points to a stub that returns an error indication.
  193. </p>
  194. <p>With input BFDs, the flag is set according to whether any long section
  195. names are detected while reading the section headers. For a completely
  196. new BFD, the flag is set to the default for the target format. This
  197. information can be used by a client of the BFD library when deciding
  198. what output format to generate, and means that a BFD that is opened
  199. for read and subsequently converted to a writeable BFD and modified
  200. in-place will retain whatever format it had on input.
  201. </p>
  202. <p>If <code>COFF_LONG_SECTION_NAMES</code> is simply defined (blank), or is
  203. defined to the value &quot;1&quot;, then long section names are enabled by
  204. default; if it is defined to the value zero, they are disabled by
  205. default (but still accepted in input BFDs). The header <samp>coffcode.h</samp>
  206. defines a macro, <code>COFF_DEFAULT_LONG_SECTION_NAMES</code>, which is
  207. used in the backends to initialise the backend data structure fields
  208. appropriately; see the comments for further detail.
  209. </p>
  210. <a name="Bit-twiddling"></a>
  211. <h4 class="subsubsection">3.3.2.3 Bit twiddling</h4>
  212. <p>Each flavour of coff supported in BFD has its own header file
  213. describing the external layout of the structures. There is also
  214. an internal description of the coff layout, in
  215. <samp>coff/internal.h</samp>. A major function of the
  216. coff backend is swapping the bytes and twiddling the bits to
  217. translate the external form of the structures into the normal
  218. internal form. This is all performed in the
  219. <code>bfd_swap</code>_<i>thing</i>_<i>direction</i> routines. Some
  220. elements are different sizes between different versions of
  221. coff; it is the duty of the coff version specific include file
  222. to override the definitions of various packing routines in
  223. <samp>coffcode.h</samp>. E.g., the size of line number entry in coff is
  224. sometimes 16 bits, and sometimes 32 bits. <code>#define</code>ing
  225. <code>PUT_LNSZ_LNNO</code> and <code>GET_LNSZ_LNNO</code> will select the
  226. correct one. No doubt, some day someone will find a version of
  227. coff which has a varying field size not catered to at the
  228. moment. To port BFD, that person will have to add more <code>#defines</code>.
  229. Three of the bit twiddling routines are exported to
  230. <code>gdb</code>; <code>coff_swap_aux_in</code>, <code>coff_swap_sym_in</code>
  231. and <code>coff_swap_lineno_in</code>. <code>GDB</code> reads the symbol
  232. table on its own, but uses BFD to fix things up. More of the
  233. bit twiddlers are exported for <code>gas</code>;
  234. <code>coff_swap_aux_out</code>, <code>coff_swap_sym_out</code>,
  235. <code>coff_swap_lineno_out</code>, <code>coff_swap_reloc_out</code>,
  236. <code>coff_swap_filehdr_out</code>, <code>coff_swap_aouthdr_out</code>,
  237. <code>coff_swap_scnhdr_out</code>. <code>Gas</code> currently keeps track
  238. of all the symbol table and reloc drudgery itself, thereby
  239. saving the internal BFD overhead, but uses BFD to swap things
  240. on the way out, making cross ports much safer. Doing so also
  241. allows BFD (and thus the linker) to use the same header files
  242. as <code>gas</code>, which makes one avenue to disaster disappear.
  243. </p>
  244. <a name="Symbol-reading"></a>
  245. <h4 class="subsubsection">3.3.2.4 Symbol reading</h4>
  246. <p>The simple canonical form for symbols used by BFD is not rich
  247. enough to keep all the information available in a coff symbol
  248. table. The back end gets around this problem by keeping the original
  249. symbol table around, &quot;behind the scenes&quot;.
  250. </p>
  251. <p>When a symbol table is requested (through a call to
  252. <code>bfd_canonicalize_symtab</code>), a request gets through to
  253. <code>coff_get_normalized_symtab</code>. This reads the symbol table from
  254. the coff file and swaps all the structures inside into the
  255. internal form. It also fixes up all the pointers in the table
  256. (represented in the file by offsets from the first symbol in
  257. the table) into physical pointers to elements in the new
  258. internal table. This involves some work since the meanings of
  259. fields change depending upon context: a field that is a
  260. pointer to another structure in the symbol table at one moment
  261. may be the size in bytes of a structure at the next. Another
  262. pass is made over the table. All symbols which mark file names
  263. (<code>C_FILE</code> symbols) are modified so that the internal
  264. string points to the value in the auxent (the real filename)
  265. rather than the normal text associated with the symbol
  266. (<code>&quot;.file&quot;</code>).
  267. </p>
  268. <p>At this time the symbol names are moved around. Coff stores
  269. all symbols less than nine characters long physically
  270. within the symbol table; longer strings are kept at the end of
  271. the file in the string table. This pass moves all strings
  272. into memory and replaces them with pointers to the strings.
  273. </p>
  274. <p>The symbol table is massaged once again, this time to create
  275. the canonical table used by the BFD application. Each symbol
  276. is inspected in turn, and a decision made (using the
  277. <code>sclass</code> field) about the various flags to set in the
  278. <code>asymbol</code>. See <a href="Symbols.html#Symbols">Symbols</a>. The generated canonical table
  279. shares strings with the hidden internal symbol table.
  280. </p>
  281. <p>Any linenumbers are read from the coff file too, and attached
  282. to the symbols which own the functions the linenumbers belong to.
  283. </p>
  284. <a name="Symbol-writing"></a>
  285. <h4 class="subsubsection">3.3.2.5 Symbol writing</h4>
  286. <p>Writing a symbol to a coff file which didn&rsquo;t come from a coff
  287. file will lose any debugging information. The <code>asymbol</code>
  288. structure remembers the BFD from which the symbol was taken, and on
  289. output the back end makes sure that the same destination target as
  290. source target is present.
  291. </p>
  292. <p>When the symbols have come from a coff file then all the
  293. debugging information is preserved.
  294. </p>
  295. <p>Symbol tables are provided for writing to the back end in a
  296. vector of pointers to pointers. This allows applications like
  297. the linker to accumulate and output large symbol tables
  298. without having to do too much byte copying.
  299. </p>
  300. <p>This function runs through the provided symbol table and
  301. patches each symbol marked as a file place holder
  302. (<code>C_FILE</code>) to point to the next file place holder in the
  303. list. It also marks each <code>offset</code> field in the list with
  304. the offset from the first symbol of the current symbol.
  305. </p>
  306. <p>Another function of this procedure is to turn the canonical
  307. value form of BFD into the form used by coff. Internally, BFD
  308. expects symbol values to be offsets from a section base; so a
  309. symbol physically at 0x120, but in a section starting at
  310. 0x100, would have the value 0x20. Coff expects symbols to
  311. contain their final value, so symbols have their values
  312. changed at this point to reflect their sum with their owning
  313. section. This transformation uses the
  314. <code>output_section</code> field of the <code>asymbol</code>&rsquo;s
  315. <code>asection</code> See <a href="Sections.html#Sections">Sections</a>.
  316. </p>
  317. <ul>
  318. <li> <code>coff_mangle_symbols</code>
  319. </li></ul>
  320. <p>This routine runs though the provided symbol table and uses
  321. the offsets generated by the previous pass and the pointers
  322. generated when the symbol table was read in to create the
  323. structured hierarchy required by coff. It changes each pointer
  324. to a symbol into the index into the symbol table of the asymbol.
  325. </p>
  326. <ul>
  327. <li> <code>coff_write_symbols</code>
  328. </li></ul>
  329. <p>This routine runs through the symbol table and patches up the
  330. symbols from their internal form into the coff way, calls the
  331. bit twiddlers, and writes out the table to the file.
  332. </p>
  333. <a name="index-coff_005fsymbol_005ftype"></a>
  334. <a name="coff_005fsymbol_005ftype"></a>
  335. <h4 class="subsubsection">3.3.2.6 <code>coff_symbol_type</code></h4>
  336. <p><strong>Description</strong><br>
  337. The hidden information for an <code>asymbol</code> is described in a
  338. <code>combined_entry_type</code>:
  339. </p>
  340. <div class="example">
  341. <pre class="example">
  342. typedef struct coff_ptr_struct
  343. {
  344. /* Remembers the offset from the first symbol in the file for
  345. this symbol. Generated by coff_renumber_symbols. */
  346. unsigned int offset;
  347. /* Should the value of this symbol be renumbered. Used for
  348. XCOFF C_BSTAT symbols. Set by coff_slurp_symbol_table. */
  349. unsigned int fix_value : 1;
  350. /* Should the tag field of this symbol be renumbered.
  351. Created by coff_pointerize_aux. */
  352. unsigned int fix_tag : 1;
  353. /* Should the endidx field of this symbol be renumbered.
  354. Created by coff_pointerize_aux. */
  355. unsigned int fix_end : 1;
  356. /* Should the x_csect.x_scnlen field be renumbered.
  357. Created by coff_pointerize_aux. */
  358. unsigned int fix_scnlen : 1;
  359. /* Fix up an XCOFF C_BINCL/C_EINCL symbol. The value is the
  360. index into the line number entries. Set by coff_slurp_symbol_table. */
  361. unsigned int fix_line : 1;
  362. /* The container for the symbol structure as read and translated
  363. from the file. */
  364. union
  365. {
  366. union internal_auxent auxent;
  367. struct internal_syment syment;
  368. } u;
  369. /* Selector for the union above. */
  370. bfd_boolean is_sym;
  371. } combined_entry_type;
  372. /* Each canonical asymbol really looks like this: */
  373. typedef struct coff_symbol_struct
  374. {
  375. /* The actual symbol which the rest of BFD works with */
  376. asymbol symbol;
  377. /* A pointer to the hidden information for this symbol */
  378. combined_entry_type *native;
  379. /* A pointer to the linenumber information for this symbol */
  380. struct lineno_cache_entry *lineno;
  381. /* Have the line numbers been relocated yet ? */
  382. bfd_boolean done_lineno;
  383. } coff_symbol_type;
  384. </pre></div>
  385. <a name="index-bfd_005fcoff_005fbackend_005fdata"></a>
  386. <a name="bfd_005fcoff_005fbackend_005fdata"></a>
  387. <h4 class="subsubsection">3.3.2.7 <code>bfd_coff_backend_data</code></h4>
  388. <div class="example">
  389. <pre class="example">/* COFF symbol classifications. */
  390. enum coff_symbol_classification
  391. {
  392. /* Global symbol. */
  393. COFF_SYMBOL_GLOBAL,
  394. /* Common symbol. */
  395. COFF_SYMBOL_COMMON,
  396. /* Undefined symbol. */
  397. COFF_SYMBOL_UNDEFINED,
  398. /* Local symbol. */
  399. COFF_SYMBOL_LOCAL,
  400. /* PE section symbol. */
  401. COFF_SYMBOL_PE_SECTION
  402. };
  403. typedef asection * (*coff_gc_mark_hook_fn)
  404. (asection *, struct bfd_link_info *, struct internal_reloc *,
  405. struct coff_link_hash_entry *, struct internal_syment *);
  406. </pre></div>
  407. <p>Special entry points for gdb to swap in coff symbol table parts:
  408. </p><div class="example">
  409. <pre class="example">typedef struct
  410. {
  411. void (*_bfd_coff_swap_aux_in)
  412. (bfd *, void *, int, int, int, int, void *);
  413. void (*_bfd_coff_swap_sym_in)
  414. (bfd *, void *, void *);
  415. void (*_bfd_coff_swap_lineno_in)
  416. (bfd *, void *, void *);
  417. unsigned int (*_bfd_coff_swap_aux_out)
  418. (bfd *, void *, int, int, int, int, void *);
  419. unsigned int (*_bfd_coff_swap_sym_out)
  420. (bfd *, void *, void *);
  421. unsigned int (*_bfd_coff_swap_lineno_out)
  422. (bfd *, void *, void *);
  423. unsigned int (*_bfd_coff_swap_reloc_out)
  424. (bfd *, void *, void *);
  425. unsigned int (*_bfd_coff_swap_filehdr_out)
  426. (bfd *, void *, void *);
  427. unsigned int (*_bfd_coff_swap_aouthdr_out)
  428. (bfd *, void *, void *);
  429. unsigned int (*_bfd_coff_swap_scnhdr_out)
  430. (bfd *, void *, void *);
  431. unsigned int _bfd_filhsz;
  432. unsigned int _bfd_aoutsz;
  433. unsigned int _bfd_scnhsz;
  434. unsigned int _bfd_symesz;
  435. unsigned int _bfd_auxesz;
  436. unsigned int _bfd_relsz;
  437. unsigned int _bfd_linesz;
  438. unsigned int _bfd_filnmlen;
  439. bfd_boolean _bfd_coff_long_filenames;
  440. bfd_boolean _bfd_coff_long_section_names;
  441. bfd_boolean (*_bfd_coff_set_long_section_names)
  442. (bfd *, int);
  443. unsigned int _bfd_coff_default_section_alignment_power;
  444. bfd_boolean _bfd_coff_force_symnames_in_strings;
  445. unsigned int _bfd_coff_debug_string_prefix_length;
  446. unsigned int _bfd_coff_max_nscns;
  447. void (*_bfd_coff_swap_filehdr_in)
  448. (bfd *, void *, void *);
  449. void (*_bfd_coff_swap_aouthdr_in)
  450. (bfd *, void *, void *);
  451. void (*_bfd_coff_swap_scnhdr_in)
  452. (bfd *, void *, void *);
  453. void (*_bfd_coff_swap_reloc_in)
  454. (bfd *abfd, void *, void *);
  455. bfd_boolean (*_bfd_coff_bad_format_hook)
  456. (bfd *, void *);
  457. bfd_boolean (*_bfd_coff_set_arch_mach_hook)
  458. (bfd *, void *);
  459. void * (*_bfd_coff_mkobject_hook)
  460. (bfd *, void *, void *);
  461. bfd_boolean (*_bfd_styp_to_sec_flags_hook)
  462. (bfd *, void *, const char *, asection *, flagword *);
  463. void (*_bfd_set_alignment_hook)
  464. (bfd *, asection *, void *);
  465. bfd_boolean (*_bfd_coff_slurp_symbol_table)
  466. (bfd *);
  467. bfd_boolean (*_bfd_coff_symname_in_debug)
  468. (bfd *, struct internal_syment *);
  469. bfd_boolean (*_bfd_coff_pointerize_aux_hook)
  470. (bfd *, combined_entry_type *, combined_entry_type *,
  471. unsigned int, combined_entry_type *);
  472. bfd_boolean (*_bfd_coff_print_aux)
  473. (bfd *, FILE *, combined_entry_type *, combined_entry_type *,
  474. combined_entry_type *, unsigned int);
  475. void (*_bfd_coff_reloc16_extra_cases)
  476. (bfd *, struct bfd_link_info *, struct bfd_link_order *, arelent *,
  477. bfd_byte *, unsigned int *, unsigned int *);
  478. int (*_bfd_coff_reloc16_estimate)
  479. (bfd *, asection *, arelent *, unsigned int,
  480. struct bfd_link_info *);
  481. enum coff_symbol_classification (*_bfd_coff_classify_symbol)
  482. (bfd *, struct internal_syment *);
  483. bfd_boolean (*_bfd_coff_compute_section_file_positions)
  484. (bfd *);
  485. bfd_boolean (*_bfd_coff_start_final_link)
  486. (bfd *, struct bfd_link_info *);
  487. bfd_boolean (*_bfd_coff_relocate_section)
  488. (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
  489. struct internal_reloc *, struct internal_syment *, asection **);
  490. reloc_howto_type *(*_bfd_coff_rtype_to_howto)
  491. (bfd *, asection *, struct internal_reloc *,
  492. struct coff_link_hash_entry *, struct internal_syment *,
  493. bfd_vma *);
  494. bfd_boolean (*_bfd_coff_adjust_symndx)
  495. (bfd *, struct bfd_link_info *, bfd *, asection *,
  496. struct internal_reloc *, bfd_boolean *);
  497. bfd_boolean (*_bfd_coff_link_add_one_symbol)
  498. (struct bfd_link_info *, bfd *, const char *, flagword,
  499. asection *, bfd_vma, const char *, bfd_boolean, bfd_boolean,
  500. struct bfd_link_hash_entry **);
  501. bfd_boolean (*_bfd_coff_link_output_has_begun)
  502. (bfd *, struct coff_final_link_info *);
  503. bfd_boolean (*_bfd_coff_final_link_postscript)
  504. (bfd *, struct coff_final_link_info *);
  505. bfd_boolean (*_bfd_coff_print_pdata)
  506. (bfd *, void *);
  507. } bfd_coff_backend_data;
  508. #define coff_backend_info(abfd) \
  509. ((bfd_coff_backend_data *) (abfd)-&gt;xvec-&gt;backend_data)
  510. #define bfd_coff_swap_aux_in(a,e,t,c,ind,num,i) \
  511. ((coff_backend_info (a)-&gt;_bfd_coff_swap_aux_in) (a,e,t,c,ind,num,i))
  512. #define bfd_coff_swap_sym_in(a,e,i) \
  513. ((coff_backend_info (a)-&gt;_bfd_coff_swap_sym_in) (a,e,i))
  514. #define bfd_coff_swap_lineno_in(a,e,i) \
  515. ((coff_backend_info ( a)-&gt;_bfd_coff_swap_lineno_in) (a,e,i))
  516. #define bfd_coff_swap_reloc_out(abfd, i, o) \
  517. ((coff_backend_info (abfd)-&gt;_bfd_coff_swap_reloc_out) (abfd, i, o))
  518. #define bfd_coff_swap_lineno_out(abfd, i, o) \
  519. ((coff_backend_info (abfd)-&gt;_bfd_coff_swap_lineno_out) (abfd, i, o))
  520. #define bfd_coff_swap_aux_out(a,i,t,c,ind,num,o) \
  521. ((coff_backend_info (a)-&gt;_bfd_coff_swap_aux_out) (a,i,t,c,ind,num,o))
  522. #define bfd_coff_swap_sym_out(abfd, i,o) \
  523. ((coff_backend_info (abfd)-&gt;_bfd_coff_swap_sym_out) (abfd, i, o))
  524. #define bfd_coff_swap_scnhdr_out(abfd, i,o) \
  525. ((coff_backend_info (abfd)-&gt;_bfd_coff_swap_scnhdr_out) (abfd, i, o))
  526. #define bfd_coff_swap_filehdr_out(abfd, i,o) \
  527. ((coff_backend_info (abfd)-&gt;_bfd_coff_swap_filehdr_out) (abfd, i, o))
  528. #define bfd_coff_swap_aouthdr_out(abfd, i,o) \
  529. ((coff_backend_info (abfd)-&gt;_bfd_coff_swap_aouthdr_out) (abfd, i, o))
  530. #define bfd_coff_filhsz(abfd) (coff_backend_info (abfd)-&gt;_bfd_filhsz)
  531. #define bfd_coff_aoutsz(abfd) (coff_backend_info (abfd)-&gt;_bfd_aoutsz)
  532. #define bfd_coff_scnhsz(abfd) (coff_backend_info (abfd)-&gt;_bfd_scnhsz)
  533. #define bfd_coff_symesz(abfd) (coff_backend_info (abfd)-&gt;_bfd_symesz)
  534. #define bfd_coff_auxesz(abfd) (coff_backend_info (abfd)-&gt;_bfd_auxesz)
  535. #define bfd_coff_relsz(abfd) (coff_backend_info (abfd)-&gt;_bfd_relsz)
  536. #define bfd_coff_linesz(abfd) (coff_backend_info (abfd)-&gt;_bfd_linesz)
  537. #define bfd_coff_filnmlen(abfd) (coff_backend_info (abfd)-&gt;_bfd_filnmlen)
  538. #define bfd_coff_long_filenames(abfd) \
  539. (coff_backend_info (abfd)-&gt;_bfd_coff_long_filenames)
  540. #define bfd_coff_long_section_names(abfd) \
  541. (coff_backend_info (abfd)-&gt;_bfd_coff_long_section_names)
  542. #define bfd_coff_set_long_section_names(abfd, enable) \
  543. ((coff_backend_info (abfd)-&gt;_bfd_coff_set_long_section_names) (abfd, enable))
  544. #define bfd_coff_default_section_alignment_power(abfd) \
  545. (coff_backend_info (abfd)-&gt;_bfd_coff_default_section_alignment_power)
  546. #define bfd_coff_max_nscns(abfd) \
  547. (coff_backend_info (abfd)-&gt;_bfd_coff_max_nscns)
  548. #define bfd_coff_swap_filehdr_in(abfd, i,o) \
  549. ((coff_backend_info (abfd)-&gt;_bfd_coff_swap_filehdr_in) (abfd, i, o))
  550. #define bfd_coff_swap_aouthdr_in(abfd, i,o) \
  551. ((coff_backend_info (abfd)-&gt;_bfd_coff_swap_aouthdr_in) (abfd, i, o))
  552. #define bfd_coff_swap_scnhdr_in(abfd, i,o) \
  553. ((coff_backend_info (abfd)-&gt;_bfd_coff_swap_scnhdr_in) (abfd, i, o))
  554. #define bfd_coff_swap_reloc_in(abfd, i, o) \
  555. ((coff_backend_info (abfd)-&gt;_bfd_coff_swap_reloc_in) (abfd, i, o))
  556. #define bfd_coff_bad_format_hook(abfd, filehdr) \
  557. ((coff_backend_info (abfd)-&gt;_bfd_coff_bad_format_hook) (abfd, filehdr))
  558. #define bfd_coff_set_arch_mach_hook(abfd, filehdr)\
  559. ((coff_backend_info (abfd)-&gt;_bfd_coff_set_arch_mach_hook) (abfd, filehdr))
  560. #define bfd_coff_mkobject_hook(abfd, filehdr, aouthdr)\
  561. ((coff_backend_info (abfd)-&gt;_bfd_coff_mkobject_hook)\
  562. (abfd, filehdr, aouthdr))
  563. #define bfd_coff_styp_to_sec_flags_hook(abfd, scnhdr, name, section, flags_ptr)\
  564. ((coff_backend_info (abfd)-&gt;_bfd_styp_to_sec_flags_hook)\
  565. (abfd, scnhdr, name, section, flags_ptr))
  566. #define bfd_coff_set_alignment_hook(abfd, sec, scnhdr)\
  567. ((coff_backend_info (abfd)-&gt;_bfd_set_alignment_hook) (abfd, sec, scnhdr))
  568. #define bfd_coff_slurp_symbol_table(abfd)\
  569. ((coff_backend_info (abfd)-&gt;_bfd_coff_slurp_symbol_table) (abfd))
  570. #define bfd_coff_symname_in_debug(abfd, sym)\
  571. ((coff_backend_info (abfd)-&gt;_bfd_coff_symname_in_debug) (abfd, sym))
  572. #define bfd_coff_force_symnames_in_strings(abfd)\
  573. (coff_backend_info (abfd)-&gt;_bfd_coff_force_symnames_in_strings)
  574. #define bfd_coff_debug_string_prefix_length(abfd)\
  575. (coff_backend_info (abfd)-&gt;_bfd_coff_debug_string_prefix_length)
  576. #define bfd_coff_print_aux(abfd, file, base, symbol, aux, indaux)\
  577. ((coff_backend_info (abfd)-&gt;_bfd_coff_print_aux)\
  578. (abfd, file, base, symbol, aux, indaux))
  579. #define bfd_coff_reloc16_extra_cases(abfd, link_info, link_order,\
  580. reloc, data, src_ptr, dst_ptr)\
  581. ((coff_backend_info (abfd)-&gt;_bfd_coff_reloc16_extra_cases)\
  582. (abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr))
  583. #define bfd_coff_reloc16_estimate(abfd, section, reloc, shrink, link_info)\
  584. ((coff_backend_info (abfd)-&gt;_bfd_coff_reloc16_estimate)\
  585. (abfd, section, reloc, shrink, link_info))
  586. #define bfd_coff_classify_symbol(abfd, sym)\
  587. ((coff_backend_info (abfd)-&gt;_bfd_coff_classify_symbol)\
  588. (abfd, sym))
  589. #define bfd_coff_compute_section_file_positions(abfd)\
  590. ((coff_backend_info (abfd)-&gt;_bfd_coff_compute_section_file_positions)\
  591. (abfd))
  592. #define bfd_coff_start_final_link(obfd, info)\
  593. ((coff_backend_info (obfd)-&gt;_bfd_coff_start_final_link)\
  594. (obfd, info))
  595. #define bfd_coff_relocate_section(obfd,info,ibfd,o,con,rel,isyms,secs)\
  596. ((coff_backend_info (ibfd)-&gt;_bfd_coff_relocate_section)\
  597. (obfd, info, ibfd, o, con, rel, isyms, secs))
  598. #define bfd_coff_rtype_to_howto(abfd, sec, rel, h, sym, addendp)\
  599. ((coff_backend_info (abfd)-&gt;_bfd_coff_rtype_to_howto)\
  600. (abfd, sec, rel, h, sym, addendp))
  601. #define bfd_coff_adjust_symndx(obfd, info, ibfd, sec, rel, adjustedp)\
  602. ((coff_backend_info (abfd)-&gt;_bfd_coff_adjust_symndx)\
  603. (obfd, info, ibfd, sec, rel, adjustedp))
  604. #define bfd_coff_link_add_one_symbol(info, abfd, name, flags, section,\
  605. value, string, cp, coll, hashp)\
  606. ((coff_backend_info (abfd)-&gt;_bfd_coff_link_add_one_symbol)\
  607. (info, abfd, name, flags, section, value, string, cp, coll, hashp))
  608. #define bfd_coff_link_output_has_begun(a,p) \
  609. ((coff_backend_info (a)-&gt;_bfd_coff_link_output_has_begun) (a, p))
  610. #define bfd_coff_final_link_postscript(a,p) \
  611. ((coff_backend_info (a)-&gt;_bfd_coff_final_link_postscript) (a, p))
  612. #define bfd_coff_have_print_pdata(a) \
  613. (coff_backend_info (a)-&gt;_bfd_coff_print_pdata)
  614. #define bfd_coff_print_pdata(a,p) \
  615. ((coff_backend_info (a)-&gt;_bfd_coff_print_pdata) (a, p))
  616. /* Macro: Returns true if the bfd is a PE executable as opposed to a
  617. PE object file. */
  618. #define bfd_pei_p(abfd) \
  619. (CONST_STRNEQ ((abfd)-&gt;xvec-&gt;name, &quot;pei-&quot;))
  620. </pre></div>
  621. <a name="Writing-relocations"></a>
  622. <h4 class="subsubsection">3.3.2.8 Writing relocations</h4>
  623. <p>To write relocations, the back end steps though the
  624. canonical relocation table and create an
  625. <code>internal_reloc</code>. The symbol index to use is removed from
  626. the <code>offset</code> field in the symbol table supplied. The
  627. address comes directly from the sum of the section base
  628. address and the relocation offset; the type is dug directly
  629. from the howto field. Then the <code>internal_reloc</code> is
  630. swapped into the shape of an <code>external_reloc</code> and written
  631. out to disk.
  632. </p>
  633. <a name="Reading-linenumbers"></a>
  634. <h4 class="subsubsection">3.3.2.9 Reading linenumbers</h4>
  635. <p>Creating the linenumber table is done by reading in the entire
  636. coff linenumber table, and creating another table for internal use.
  637. </p>
  638. <p>A coff linenumber table is structured so that each function
  639. is marked as having a line number of 0. Each line within the
  640. function is an offset from the first line in the function. The
  641. base of the line number information for the table is stored in
  642. the symbol associated with the function.
  643. </p>
  644. <p>Note: The PE format uses line number 0 for a flag indicating a
  645. new source file.
  646. </p>
  647. <p>The information is copied from the external to the internal
  648. table, and each symbol which marks a function is marked by
  649. pointing its...
  650. </p>
  651. <p>How does this work ?
  652. </p>
  653. <a name="Reading-relocations"></a>
  654. <h4 class="subsubsection">3.3.2.10 Reading relocations</h4>
  655. <p>Coff relocations are easily transformed into the internal BFD form
  656. (<code>arelent</code>).
  657. </p>
  658. <p>Reading a coff relocation table is done in the following stages:
  659. </p>
  660. <ul>
  661. <li> Read the entire coff relocation table into memory.
  662. </li><li> Process each relocation in turn; first swap it from the
  663. external to the internal form.
  664. </li><li> Turn the symbol referenced in the relocation&rsquo;s symbol index
  665. into a pointer into the canonical symbol table.
  666. This table is the same as the one returned by a call to
  667. <code>bfd_canonicalize_symtab</code>. The back end will call that
  668. routine and save the result if a canonicalization hasn&rsquo;t been done.
  669. </li><li> The reloc index is turned into a pointer to a howto
  670. structure, in a back end specific way. For instance, the 386
  671. and 960 use the <code>r_type</code> to directly produce an index
  672. into a howto table vector; the 88k subtracts a number from the
  673. <code>r_type</code> field and creates an addend field.
  674. </li></ul>
  675. <hr>
  676. <div class="header">
  677. <p>
  678. Next: <a href="elf.html#elf" accesskey="n" rel="next">elf</a>, Previous: <a href="aout.html#aout" accesskey="p" rel="prev">aout</a>, Up: <a href="BFD-back-ends.html#BFD-back-ends" accesskey="u" rel="up">BFD back ends</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>
  679. </div>
  680. </body>
  681. </html>