You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

775 lines
32KB

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