OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [bfd/] [doc/] [coffcode.texi] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.