1 |
1181 |
sfurman |
This is bfd.info, produced by makeinfo version 4.1 from bfd.texinfo.
|
2 |
|
|
|
3 |
|
|
START-INFO-DIR-ENTRY
|
4 |
|
|
* Bfd: (bfd). The Binary File Descriptor library.
|
5 |
|
|
END-INFO-DIR-ENTRY
|
6 |
|
|
|
7 |
|
|
This file documents the BFD library.
|
8 |
|
|
|
9 |
|
|
Copyright (C) 1991, 2000, 2001 Free Software Foundation, Inc.
|
10 |
|
|
|
11 |
|
|
Permission is granted to copy, distribute and/or modify this document
|
12 |
|
|
under the terms of the GNU Free Documentation License, Version 1.1
|
13 |
|
|
or any later version published by the Free Software Foundation;
|
14 |
|
|
with no Invariant Sections, with no Front-Cover Texts, and with no
|
15 |
|
|
Back-Cover Texts. A copy of the license is included in the
|
16 |
|
|
section entitled "GNU Free Documentation License".
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
File: bfd.info, Node: coff, Next: elf, Prev: aout, Up: BFD back ends
|
20 |
|
|
|
21 |
|
|
coff backends
|
22 |
|
|
=============
|
23 |
|
|
|
24 |
|
|
BFD supports a number of different flavours of coff format. The
|
25 |
|
|
major differences between formats are the sizes and alignments of
|
26 |
|
|
fields in structures on disk, and the occasional extra field.
|
27 |
|
|
|
28 |
|
|
Coff in all its varieties is implemented with a few common files and
|
29 |
|
|
a number of implementation specific files. For example, The 88k bcs
|
30 |
|
|
coff format is implemented in the file `coff-m88k.c'. This file
|
31 |
|
|
`#include's `coff/m88k.h' which defines the external structure of the
|
32 |
|
|
coff format for the 88k, and `coff/internal.h' which defines the
|
33 |
|
|
internal structure. `coff-m88k.c' also defines the relocations used by
|
34 |
|
|
the 88k format *Note Relocations::.
|
35 |
|
|
|
36 |
|
|
The Intel i960 processor version of coff is implemented in
|
37 |
|
|
`coff-i960.c'. This file has the same structure as `coff-m88k.c',
|
38 |
|
|
except that it includes `coff/i960.h' rather than `coff-m88k.h'.
|
39 |
|
|
|
40 |
|
|
Porting to a new version of coff
|
41 |
|
|
--------------------------------
|
42 |
|
|
|
43 |
|
|
The recommended method is to select from the existing
|
44 |
|
|
implementations the version of coff which is most like the one you want
|
45 |
|
|
to use. For example, we'll say that i386 coff is the one you select,
|
46 |
|
|
and that your coff flavour is called foo. Copy `i386coff.c' to
|
47 |
|
|
`foocoff.c', copy `../include/coff/i386.h' to `../include/coff/foo.h',
|
48 |
|
|
and add the lines to `targets.c' and `Makefile.in' so that your new
|
49 |
|
|
back end is used. Alter the shapes of the structures in
|
50 |
|
|
`../include/coff/foo.h' so that they match what you need. You will
|
51 |
|
|
probably also have to add `#ifdef's to the code in `coff/internal.h' and
|
52 |
|
|
`coffcode.h' if your version of coff is too wild.
|
53 |
|
|
|
54 |
|
|
You can verify that your new BFD backend works quite simply by
|
55 |
|
|
building `objdump' from the `binutils' directory, and making sure that
|
56 |
|
|
its version of what's going on and your host system's idea (assuming it
|
57 |
|
|
has the pretty standard coff dump utility, usually called `att-dump' or
|
58 |
|
|
just `dump') are the same. Then clean up your code, and send what
|
59 |
|
|
you've done to Cygnus. Then your stuff will be in the next release, and
|
60 |
|
|
you won't have to keep integrating it.
|
61 |
|
|
|
62 |
|
|
How the coff backend works
|
63 |
|
|
--------------------------
|
64 |
|
|
|
65 |
|
|
File layout
|
66 |
|
|
...........
|
67 |
|
|
|
68 |
|
|
The Coff backend is split into generic routines that are applicable
|
69 |
|
|
to any Coff target and routines that are specific to a particular
|
70 |
|
|
target. The target-specific routines are further split into ones which
|
71 |
|
|
are basically the same for all Coff targets except that they use the
|
72 |
|
|
external symbol format or use different values for certain constants.
|
73 |
|
|
|
74 |
|
|
The generic routines are in `coffgen.c'. These routines work for
|
75 |
|
|
any Coff target. They use some hooks into the target specific code;
|
76 |
|
|
the hooks are in a `bfd_coff_backend_data' structure, one of which
|
77 |
|
|
exists for each target.
|
78 |
|
|
|
79 |
|
|
The essentially similar target-specific routines are in
|
80 |
|
|
`coffcode.h'. This header file includes executable C code. The
|
81 |
|
|
various Coff targets first include the appropriate Coff header file,
|
82 |
|
|
make any special defines that are needed, and then include `coffcode.h'.
|
83 |
|
|
|
84 |
|
|
Some of the Coff targets then also have additional routines in the
|
85 |
|
|
target source file itself.
|
86 |
|
|
|
87 |
|
|
For example, `coff-i960.c' includes `coff/internal.h' and
|
88 |
|
|
`coff/i960.h'. It then defines a few constants, such as `I960', and
|
89 |
|
|
includes `coffcode.h'. Since the i960 has complex relocation types,
|
90 |
|
|
`coff-i960.c' also includes some code to manipulate the i960 relocs.
|
91 |
|
|
This code is not in `coffcode.h' because it would not be used by any
|
92 |
|
|
other target.
|
93 |
|
|
|
94 |
|
|
Bit twiddling
|
95 |
|
|
.............
|
96 |
|
|
|
97 |
|
|
Each flavour of coff supported in BFD has its own header file
|
98 |
|
|
describing the external layout of the structures. There is also an
|
99 |
|
|
internal description of the coff layout, in `coff/internal.h'. A major
|
100 |
|
|
function of the coff backend is swapping the bytes and twiddling the
|
101 |
|
|
bits to translate the external form of the structures into the normal
|
102 |
|
|
internal form. This is all performed in the `bfd_swap'_thing_direction
|
103 |
|
|
routines. Some elements are different sizes between different versions
|
104 |
|
|
of coff; it is the duty of the coff version specific include file to
|
105 |
|
|
override the definitions of various packing routines in `coffcode.h'.
|
106 |
|
|
E.g., the size of line number entry in coff is sometimes 16 bits, and
|
107 |
|
|
sometimes 32 bits. `#define'ing `PUT_LNSZ_LNNO' and `GET_LNSZ_LNNO'
|
108 |
|
|
will select the correct one. No doubt, some day someone will find a
|
109 |
|
|
version of coff which has a varying field size not catered to at the
|
110 |
|
|
moment. To port BFD, that person will have to add more `#defines'.
|
111 |
|
|
Three of the bit twiddling routines are exported to `gdb';
|
112 |
|
|
`coff_swap_aux_in', `coff_swap_sym_in' and `coff_swap_lineno_in'. `GDB'
|
113 |
|
|
reads the symbol table on its own, but uses BFD to fix things up. More
|
114 |
|
|
of the bit twiddlers are exported for `gas'; `coff_swap_aux_out',
|
115 |
|
|
`coff_swap_sym_out', `coff_swap_lineno_out', `coff_swap_reloc_out',
|
116 |
|
|
`coff_swap_filehdr_out', `coff_swap_aouthdr_out',
|
117 |
|
|
`coff_swap_scnhdr_out'. `Gas' currently keeps track of all the symbol
|
118 |
|
|
table and reloc drudgery itself, thereby saving the internal BFD
|
119 |
|
|
overhead, but uses BFD to swap things on the way out, making cross
|
120 |
|
|
ports much safer. Doing so also allows BFD (and thus the linker) to
|
121 |
|
|
use the same header files as `gas', which makes one avenue to disaster
|
122 |
|
|
disappear.
|
123 |
|
|
|
124 |
|
|
Symbol reading
|
125 |
|
|
..............
|
126 |
|
|
|
127 |
|
|
The simple canonical form for symbols used by BFD is not rich enough
|
128 |
|
|
to keep all the information available in a coff symbol table. The back
|
129 |
|
|
end gets around this problem by keeping the original symbol table
|
130 |
|
|
around, "behind the scenes".
|
131 |
|
|
|
132 |
|
|
When a symbol table is requested (through a call to
|
133 |
|
|
`bfd_canonicalize_symtab'), a request gets through to
|
134 |
|
|
`coff_get_normalized_symtab'. This reads the symbol table from the coff
|
135 |
|
|
file and swaps all the structures inside into the internal form. It
|
136 |
|
|
also fixes up all the pointers in the table (represented in the file by
|
137 |
|
|
offsets from the first symbol in the table) into physical pointers to
|
138 |
|
|
elements in the new internal table. This involves some work since the
|
139 |
|
|
meanings of fields change depending upon context: a field that is a
|
140 |
|
|
pointer to another structure in the symbol table at one moment may be
|
141 |
|
|
the size in bytes of a structure at the next. Another pass is made
|
142 |
|
|
over the table. All symbols which mark file names (`C_FILE' symbols)
|
143 |
|
|
are modified so that the internal string points to the value in the
|
144 |
|
|
auxent (the real filename) rather than the normal text associated with
|
145 |
|
|
the symbol (`".file"').
|
146 |
|
|
|
147 |
|
|
At this time the symbol names are moved around. Coff stores all
|
148 |
|
|
symbols less than nine characters long physically within the symbol
|
149 |
|
|
table; longer strings are kept at the end of the file in the string
|
150 |
|
|
table. This pass moves all strings into memory and replaces them with
|
151 |
|
|
pointers to the strings.
|
152 |
|
|
|
153 |
|
|
The symbol table is massaged once again, this time to create the
|
154 |
|
|
canonical table used by the BFD application. Each symbol is inspected
|
155 |
|
|
in turn, and a decision made (using the `sclass' field) about the
|
156 |
|
|
various flags to set in the `asymbol'. *Note Symbols::. The generated
|
157 |
|
|
canonical table shares strings with the hidden internal symbol table.
|
158 |
|
|
|
159 |
|
|
Any linenumbers are read from the coff file too, and attached to the
|
160 |
|
|
symbols which own the functions the linenumbers belong to.
|
161 |
|
|
|
162 |
|
|
Symbol writing
|
163 |
|
|
..............
|
164 |
|
|
|
165 |
|
|
Writing a symbol to a coff file which didn't come from a coff file
|
166 |
|
|
will lose any debugging information. The `asymbol' structure remembers
|
167 |
|
|
the BFD from which the symbol was taken, and on output the back end
|
168 |
|
|
makes sure that the same destination target as source target is present.
|
169 |
|
|
|
170 |
|
|
When the symbols have come from a coff file then all the debugging
|
171 |
|
|
information is preserved.
|
172 |
|
|
|
173 |
|
|
Symbol tables are provided for writing to the back end in a vector
|
174 |
|
|
of pointers to pointers. This allows applications like the linker to
|
175 |
|
|
accumulate and output large symbol tables without having to do too much
|
176 |
|
|
byte copying.
|
177 |
|
|
|
178 |
|
|
This function runs through the provided symbol table and patches
|
179 |
|
|
each symbol marked as a file place holder (`C_FILE') to point to the
|
180 |
|
|
next file place holder in the list. It also marks each `offset' field
|
181 |
|
|
in the list with the offset from the first symbol of the current symbol.
|
182 |
|
|
|
183 |
|
|
Another function of this procedure is to turn the canonical value
|
184 |
|
|
form of BFD into the form used by coff. Internally, BFD expects symbol
|
185 |
|
|
values to be offsets from a section base; so a symbol physically at
|
186 |
|
|
0x120, but in a section starting at 0x100, would have the value 0x20.
|
187 |
|
|
Coff expects symbols to contain their final value, so symbols have
|
188 |
|
|
their values changed at this point to reflect their sum with their
|
189 |
|
|
owning section. This transformation uses the `output_section' field of
|
190 |
|
|
the `asymbol''s `asection' *Note Sections::.
|
191 |
|
|
|
192 |
|
|
* `coff_mangle_symbols'
|
193 |
|
|
This routine runs though the provided symbol table and uses the
|
194 |
|
|
offsets generated by the previous pass and the pointers generated when
|
195 |
|
|
the symbol table was read in to create the structured hierachy required
|
196 |
|
|
by coff. It changes each pointer to a symbol into the index into the
|
197 |
|
|
symbol table of the asymbol.
|
198 |
|
|
|
199 |
|
|
* `coff_write_symbols'
|
200 |
|
|
This routine runs through the symbol table and patches up the
|
201 |
|
|
symbols from their internal form into the coff way, calls the bit
|
202 |
|
|
twiddlers, and writes out the table to the file.
|
203 |
|
|
|
204 |
|
|
`coff_symbol_type'
|
205 |
|
|
..................
|
206 |
|
|
|
207 |
|
|
*Description*
|
208 |
|
|
The hidden information for an `asymbol' is described in a
|
209 |
|
|
`combined_entry_type':
|
210 |
|
|
|
211 |
|
|
|
212 |
|
|
typedef struct coff_ptr_struct
|
213 |
|
|
{
|
214 |
|
|
/* Remembers the offset from the first symbol in the file for
|
215 |
|
|
this symbol. Generated by coff_renumber_symbols. */
|
216 |
|
|
unsigned int offset;
|
217 |
|
|
|
218 |
|
|
/* Should the value of this symbol be renumbered. Used for
|
219 |
|
|
XCOFF C_BSTAT symbols. Set by coff_slurp_symbol_table. */
|
220 |
|
|
unsigned int fix_value : 1;
|
221 |
|
|
|
222 |
|
|
/* Should the tag field of this symbol be renumbered.
|
223 |
|
|
Created by coff_pointerize_aux. */
|
224 |
|
|
unsigned int fix_tag : 1;
|
225 |
|
|
|
226 |
|
|
/* Should the endidx field of this symbol be renumbered.
|
227 |
|
|
Created by coff_pointerize_aux. */
|
228 |
|
|
unsigned int fix_end : 1;
|
229 |
|
|
|
230 |
|
|
/* Should the x_csect.x_scnlen field be renumbered.
|
231 |
|
|
Created by coff_pointerize_aux. */
|
232 |
|
|
unsigned int fix_scnlen : 1;
|
233 |
|
|
|
234 |
|
|
/* Fix up an XCOFF C_BINCL/C_EINCL symbol. The value is the
|
235 |
|
|
index into the line number entries. Set by coff_slurp_symbol_table. */
|
236 |
|
|
unsigned int fix_line : 1;
|
237 |
|
|
|
238 |
|
|
/* The container for the symbol structure as read and translated
|
239 |
|
|
from the file. */
|
240 |
|
|
union
|
241 |
|
|
{
|
242 |
|
|
union internal_auxent auxent;
|
243 |
|
|
struct internal_syment syment;
|
244 |
|
|
} u;
|
245 |
|
|
} combined_entry_type;
|
246 |
|
|
|
247 |
|
|
|
248 |
|
|
/* Each canonical asymbol really looks like this: */
|
249 |
|
|
|
250 |
|
|
typedef struct coff_symbol_struct
|
251 |
|
|
{
|
252 |
|
|
/* The actual symbol which the rest of BFD works with */
|
253 |
|
|
asymbol symbol;
|
254 |
|
|
|
255 |
|
|
/* A pointer to the hidden information for this symbol */
|
256 |
|
|
combined_entry_type *native;
|
257 |
|
|
|
258 |
|
|
/* A pointer to the linenumber information for this symbol */
|
259 |
|
|
struct lineno_cache_entry *lineno;
|
260 |
|
|
|
261 |
|
|
/* Have the line numbers been relocated yet ? */
|
262 |
|
|
boolean done_lineno;
|
263 |
|
|
} coff_symbol_type;
|
264 |
|
|
|
265 |
|
|
`bfd_coff_backend_data'
|
266 |
|
|
.......................
|
267 |
|
|
|
268 |
|
|
/* COFF symbol classifications. */
|
269 |
|
|
|
270 |
|
|
enum coff_symbol_classification
|
271 |
|
|
{
|
272 |
|
|
/* Global symbol. */
|
273 |
|
|
COFF_SYMBOL_GLOBAL,
|
274 |
|
|
/* Common symbol. */
|
275 |
|
|
COFF_SYMBOL_COMMON,
|
276 |
|
|
/* Undefined symbol. */
|
277 |
|
|
COFF_SYMBOL_UNDEFINED,
|
278 |
|
|
/* Local symbol. */
|
279 |
|
|
COFF_SYMBOL_LOCAL,
|
280 |
|
|
/* PE section symbol. */
|
281 |
|
|
COFF_SYMBOL_PE_SECTION
|
282 |
|
|
};
|
283 |
|
|
Special entry points for gdb to swap in coff symbol table parts:
|
284 |
|
|
typedef struct
|
285 |
|
|
{
|
286 |
|
|
void (*_bfd_coff_swap_aux_in)
|
287 |
|
|
PARAMS ((bfd *, PTR, int, int, int, int, PTR));
|
288 |
|
|
|
289 |
|
|
void (*_bfd_coff_swap_sym_in)
|
290 |
|
|
PARAMS ((bfd *, PTR, PTR));
|
291 |
|
|
|
292 |
|
|
void (*_bfd_coff_swap_lineno_in)
|
293 |
|
|
PARAMS ((bfd *, PTR, PTR));
|
294 |
|
|
|
295 |
|
|
unsigned int (*_bfd_coff_swap_aux_out)
|
296 |
|
|
PARAMS ((bfd *, PTR, int, int, int, int, PTR));
|
297 |
|
|
|
298 |
|
|
unsigned int (*_bfd_coff_swap_sym_out)
|
299 |
|
|
PARAMS ((bfd *, PTR, PTR));
|
300 |
|
|
|
301 |
|
|
unsigned int (*_bfd_coff_swap_lineno_out)
|
302 |
|
|
PARAMS ((bfd *, PTR, PTR));
|
303 |
|
|
|
304 |
|
|
unsigned int (*_bfd_coff_swap_reloc_out)
|
305 |
|
|
PARAMS ((bfd *, PTR, PTR));
|
306 |
|
|
|
307 |
|
|
unsigned int (*_bfd_coff_swap_filehdr_out)
|
308 |
|
|
PARAMS ((bfd *, PTR, PTR));
|
309 |
|
|
|
310 |
|
|
unsigned int (*_bfd_coff_swap_aouthdr_out)
|
311 |
|
|
PARAMS ((bfd *, PTR, PTR));
|
312 |
|
|
|
313 |
|
|
unsigned int (*_bfd_coff_swap_scnhdr_out)
|
314 |
|
|
PARAMS ((bfd *, PTR, PTR));
|
315 |
|
|
|
316 |
|
|
unsigned int _bfd_filhsz;
|
317 |
|
|
unsigned int _bfd_aoutsz;
|
318 |
|
|
unsigned int _bfd_scnhsz;
|
319 |
|
|
unsigned int _bfd_symesz;
|
320 |
|
|
unsigned int _bfd_auxesz;
|
321 |
|
|
unsigned int _bfd_relsz;
|
322 |
|
|
unsigned int _bfd_linesz;
|
323 |
|
|
unsigned int _bfd_filnmlen;
|
324 |
|
|
boolean _bfd_coff_long_filenames;
|
325 |
|
|
boolean _bfd_coff_long_section_names;
|
326 |
|
|
unsigned int _bfd_coff_default_section_alignment_power;
|
327 |
|
|
boolean _bfd_coff_force_symnames_in_strings;
|
328 |
|
|
unsigned int _bfd_coff_debug_string_prefix_length;
|
329 |
|
|
|
330 |
|
|
void (*_bfd_coff_swap_filehdr_in)
|
331 |
|
|
PARAMS ((bfd *, PTR, PTR));
|
332 |
|
|
|
333 |
|
|
void (*_bfd_coff_swap_aouthdr_in)
|
334 |
|
|
PARAMS ((bfd *, PTR, PTR));
|
335 |
|
|
|
336 |
|
|
void (*_bfd_coff_swap_scnhdr_in)
|
337 |
|
|
PARAMS ((bfd *, PTR, PTR));
|
338 |
|
|
|
339 |
|
|
void (*_bfd_coff_swap_reloc_in)
|
340 |
|
|
PARAMS ((bfd *abfd, PTR, PTR));
|
341 |
|
|
|
342 |
|
|
boolean (*_bfd_coff_bad_format_hook)
|
343 |
|
|
PARAMS ((bfd *, PTR));
|
344 |
|
|
|
345 |
|
|
boolean (*_bfd_coff_set_arch_mach_hook)
|
346 |
|
|
PARAMS ((bfd *, PTR));
|
347 |
|
|
|
348 |
|
|
PTR (*_bfd_coff_mkobject_hook)
|
349 |
|
|
PARAMS ((bfd *, PTR, PTR));
|
350 |
|
|
|
351 |
|
|
boolean (*_bfd_styp_to_sec_flags_hook)
|
352 |
|
|
PARAMS ((bfd *, PTR, const char *, asection *, flagword *));
|
353 |
|
|
|
354 |
|
|
void (*_bfd_set_alignment_hook)
|
355 |
|
|
PARAMS ((bfd *, asection *, PTR));
|
356 |
|
|
|
357 |
|
|
boolean (*_bfd_coff_slurp_symbol_table)
|
358 |
|
|
PARAMS ((bfd *));
|
359 |
|
|
|
360 |
|
|
boolean (*_bfd_coff_symname_in_debug)
|
361 |
|
|
PARAMS ((bfd *, struct internal_syment *));
|
362 |
|
|
|
363 |
|
|
boolean (*_bfd_coff_pointerize_aux_hook)
|
364 |
|
|
PARAMS ((bfd *, combined_entry_type *, combined_entry_type *,
|
365 |
|
|
unsigned int, combined_entry_type *));
|
366 |
|
|
|
367 |
|
|
boolean (*_bfd_coff_print_aux)
|
368 |
|
|
PARAMS ((bfd *, FILE *, combined_entry_type *, combined_entry_type *,
|
369 |
|
|
combined_entry_type *, unsigned int));
|
370 |
|
|
|
371 |
|
|
void (*_bfd_coff_reloc16_extra_cases)
|
372 |
|
|
PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *, arelent *,
|
373 |
|
|
bfd_byte *, unsigned int *, unsigned int *));
|
374 |
|
|
|
375 |
|
|
int (*_bfd_coff_reloc16_estimate)
|
376 |
|
|
PARAMS ((bfd *, asection *, arelent *, unsigned int,
|
377 |
|
|
struct bfd_link_info *));
|
378 |
|
|
|
379 |
|
|
enum coff_symbol_classification (*_bfd_coff_classify_symbol)
|
380 |
|
|
PARAMS ((bfd *, struct internal_syment *));
|
381 |
|
|
|
382 |
|
|
boolean (*_bfd_coff_compute_section_file_positions)
|
383 |
|
|
PARAMS ((bfd *));
|
384 |
|
|
|
385 |
|
|
boolean (*_bfd_coff_start_final_link)
|
386 |
|
|
PARAMS ((bfd *, struct bfd_link_info *));
|
387 |
|
|
|
388 |
|
|
boolean (*_bfd_coff_relocate_section)
|
389 |
|
|
PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
|
390 |
|
|
struct internal_reloc *, struct internal_syment *, asection **));
|
391 |
|
|
|
392 |
|
|
reloc_howto_type *(*_bfd_coff_rtype_to_howto)
|
393 |
|
|
PARAMS ((bfd *, asection *, struct internal_reloc *,
|
394 |
|
|
struct coff_link_hash_entry *, struct internal_syment *,
|
395 |
|
|
bfd_vma *));
|
396 |
|
|
|
397 |
|
|
boolean (*_bfd_coff_adjust_symndx)\
|
398 |
|
|
PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *,
|
399 |
|
|
struct internal_reloc *, boolean *));
|
400 |
|
|
|
401 |
|
|
boolean (*_bfd_coff_link_add_one_symbol)
|
402 |
|
|
PARAMS ((struct bfd_link_info *, bfd *, const char *, flagword,
|
403 |
|
|
asection *, bfd_vma, const char *, boolean, boolean,
|
404 |
|
|
struct bfd_link_hash_entry **));
|
405 |
|
|
|
406 |
|
|
boolean (*_bfd_coff_link_output_has_begun)
|
407 |
|
|
PARAMS ((bfd *, struct coff_final_link_info *));
|
408 |
|
|
|
409 |
|
|
boolean (*_bfd_coff_final_link_postscript)
|
410 |
|
|
PARAMS ((bfd *, struct coff_final_link_info *));
|
411 |
|
|
|
412 |
|
|
} bfd_coff_backend_data;
|
413 |
|
|
|
414 |
|
|
#define coff_backend_info(abfd) \
|
415 |
|
|
((bfd_coff_backend_data *) (abfd)->xvec->backend_data)
|
416 |
|
|
|
417 |
|
|
#define bfd_coff_swap_aux_in(a,e,t,c,ind,num,i) \
|
418 |
|
|
((coff_backend_info (a)->_bfd_coff_swap_aux_in) (a,e,t,c,ind,num,i))
|
419 |
|
|
|
420 |
|
|
#define bfd_coff_swap_sym_in(a,e,i) \
|
421 |
|
|
((coff_backend_info (a)->_bfd_coff_swap_sym_in) (a,e,i))
|
422 |
|
|
|
423 |
|
|
#define bfd_coff_swap_lineno_in(a,e,i) \
|
424 |
|
|
((coff_backend_info ( a)->_bfd_coff_swap_lineno_in) (a,e,i))
|
425 |
|
|
|
426 |
|
|
#define bfd_coff_swap_reloc_out(abfd, i, o) \
|
427 |
|
|
((coff_backend_info (abfd)->_bfd_coff_swap_reloc_out) (abfd, i, o))
|
428 |
|
|
|
429 |
|
|
#define bfd_coff_swap_lineno_out(abfd, i, o) \
|
430 |
|
|
((coff_backend_info (abfd)->_bfd_coff_swap_lineno_out) (abfd, i, o))
|
431 |
|
|
|
432 |
|
|
#define bfd_coff_swap_aux_out(a,i,t,c,ind,num,o) \
|
433 |
|
|
((coff_backend_info (a)->_bfd_coff_swap_aux_out) (a,i,t,c,ind,num,o))
|
434 |
|
|
|
435 |
|
|
#define bfd_coff_swap_sym_out(abfd, i,o) \
|
436 |
|
|
((coff_backend_info (abfd)->_bfd_coff_swap_sym_out) (abfd, i, o))
|
437 |
|
|
|
438 |
|
|
#define bfd_coff_swap_scnhdr_out(abfd, i,o) \
|
439 |
|
|
((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_out) (abfd, i, o))
|
440 |
|
|
|
441 |
|
|
#define bfd_coff_swap_filehdr_out(abfd, i,o) \
|
442 |
|
|
((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_out) (abfd, i, o))
|
443 |
|
|
|
444 |
|
|
#define bfd_coff_swap_aouthdr_out(abfd, i,o) \
|
445 |
|
|
((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_out) (abfd, i, o))
|
446 |
|
|
|
447 |
|
|
#define bfd_coff_filhsz(abfd) (coff_backend_info (abfd)->_bfd_filhsz)
|
448 |
|
|
#define bfd_coff_aoutsz(abfd) (coff_backend_info (abfd)->_bfd_aoutsz)
|
449 |
|
|
#define bfd_coff_scnhsz(abfd) (coff_backend_info (abfd)->_bfd_scnhsz)
|
450 |
|
|
#define bfd_coff_symesz(abfd) (coff_backend_info (abfd)->_bfd_symesz)
|
451 |
|
|
#define bfd_coff_auxesz(abfd) (coff_backend_info (abfd)->_bfd_auxesz)
|
452 |
|
|
#define bfd_coff_relsz(abfd) (coff_backend_info (abfd)->_bfd_relsz)
|
453 |
|
|
#define bfd_coff_linesz(abfd) (coff_backend_info (abfd)->_bfd_linesz)
|
454 |
|
|
#define bfd_coff_filnmlen(abfd) (coff_backend_info (abfd)->_bfd_filnmlen)
|
455 |
|
|
#define bfd_coff_long_filenames(abfd) \
|
456 |
|
|
(coff_backend_info (abfd)->_bfd_coff_long_filenames)
|
457 |
|
|
#define bfd_coff_long_section_names(abfd) \
|
458 |
|
|
(coff_backend_info (abfd)->_bfd_coff_long_section_names)
|
459 |
|
|
#define bfd_coff_default_section_alignment_power(abfd) \
|
460 |
|
|
(coff_backend_info (abfd)->_bfd_coff_default_section_alignment_power)
|
461 |
|
|
#define bfd_coff_swap_filehdr_in(abfd, i,o) \
|
462 |
|
|
((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_in) (abfd, i, o))
|
463 |
|
|
|
464 |
|
|
#define bfd_coff_swap_aouthdr_in(abfd, i,o) \
|
465 |
|
|
((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_in) (abfd, i, o))
|
466 |
|
|
|
467 |
|
|
#define bfd_coff_swap_scnhdr_in(abfd, i,o) \
|
468 |
|
|
((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_in) (abfd, i, o))
|
469 |
|
|
|
470 |
|
|
#define bfd_coff_swap_reloc_in(abfd, i, o) \
|
471 |
|
|
((coff_backend_info (abfd)->_bfd_coff_swap_reloc_in) (abfd, i, o))
|
472 |
|
|
|
473 |
|
|
#define bfd_coff_bad_format_hook(abfd, filehdr) \
|
474 |
|
|
((coff_backend_info (abfd)->_bfd_coff_bad_format_hook) (abfd, filehdr))
|
475 |
|
|
|
476 |
|
|
#define bfd_coff_set_arch_mach_hook(abfd, filehdr)\
|
477 |
|
|
((coff_backend_info (abfd)->_bfd_coff_set_arch_mach_hook) (abfd, filehdr))
|
478 |
|
|
#define bfd_coff_mkobject_hook(abfd, filehdr, aouthdr)\
|
479 |
|
|
((coff_backend_info (abfd)->_bfd_coff_mkobject_hook) (abfd, filehdr, aouthdr))
|
480 |
|
|
|
481 |
|
|
#define bfd_coff_styp_to_sec_flags_hook(abfd, scnhdr, name, section, flags_ptr)\
|
482 |
|
|
((coff_backend_info (abfd)->_bfd_styp_to_sec_flags_hook)\
|
483 |
|
|
(abfd, scnhdr, name, section, flags_ptr))
|
484 |
|
|
|
485 |
|
|
#define bfd_coff_set_alignment_hook(abfd, sec, scnhdr)\
|
486 |
|
|
((coff_backend_info (abfd)->_bfd_set_alignment_hook) (abfd, sec, scnhdr))
|
487 |
|
|
|
488 |
|
|
#define bfd_coff_slurp_symbol_table(abfd)\
|
489 |
|
|
((coff_backend_info (abfd)->_bfd_coff_slurp_symbol_table) (abfd))
|
490 |
|
|
|
491 |
|
|
#define bfd_coff_symname_in_debug(abfd, sym)\
|
492 |
|
|
((coff_backend_info (abfd)->_bfd_coff_symname_in_debug) (abfd, sym))
|
493 |
|
|
|
494 |
|
|
#define bfd_coff_force_symnames_in_strings(abfd)\
|
495 |
|
|
(coff_backend_info (abfd)->_bfd_coff_force_symnames_in_strings)
|
496 |
|
|
|
497 |
|
|
#define bfd_coff_debug_string_prefix_length(abfd)\
|
498 |
|
|
(coff_backend_info (abfd)->_bfd_coff_debug_string_prefix_length)
|
499 |
|
|
|
500 |
|
|
#define bfd_coff_print_aux(abfd, file, base, symbol, aux, indaux)\
|
501 |
|
|
((coff_backend_info (abfd)->_bfd_coff_print_aux)\
|
502 |
|
|
(abfd, file, base, symbol, aux, indaux))
|
503 |
|
|
|
504 |
|
|
#define bfd_coff_reloc16_extra_cases(abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr)\
|
505 |
|
|
((coff_backend_info (abfd)->_bfd_coff_reloc16_extra_cases)\
|
506 |
|
|
(abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr))
|
507 |
|
|
|
508 |
|
|
#define bfd_coff_reloc16_estimate(abfd, section, reloc, shrink, link_info)\
|
509 |
|
|
((coff_backend_info (abfd)->_bfd_coff_reloc16_estimate)\
|
510 |
|
|
(abfd, section, reloc, shrink, link_info))
|
511 |
|
|
|
512 |
|
|
#define bfd_coff_classify_symbol(abfd, sym)\
|
513 |
|
|
((coff_backend_info (abfd)->_bfd_coff_classify_symbol)\
|
514 |
|
|
(abfd, sym))
|
515 |
|
|
|
516 |
|
|
#define bfd_coff_compute_section_file_positions(abfd)\
|
517 |
|
|
((coff_backend_info (abfd)->_bfd_coff_compute_section_file_positions)\
|
518 |
|
|
(abfd))
|
519 |
|
|
|
520 |
|
|
#define bfd_coff_start_final_link(obfd, info)\
|
521 |
|
|
((coff_backend_info (obfd)->_bfd_coff_start_final_link)\
|
522 |
|
|
(obfd, info))
|
523 |
|
|
#define bfd_coff_relocate_section(obfd,info,ibfd,o,con,rel,isyms,secs)\
|
524 |
|
|
((coff_backend_info (ibfd)->_bfd_coff_relocate_section)\
|
525 |
|
|
(obfd, info, ibfd, o, con, rel, isyms, secs))
|
526 |
|
|
#define bfd_coff_rtype_to_howto(abfd, sec, rel, h, sym, addendp)\
|
527 |
|
|
((coff_backend_info (abfd)->_bfd_coff_rtype_to_howto)\
|
528 |
|
|
(abfd, sec, rel, h, sym, addendp))
|
529 |
|
|
#define bfd_coff_adjust_symndx(obfd, info, ibfd, sec, rel, adjustedp)\
|
530 |
|
|
((coff_backend_info (abfd)->_bfd_coff_adjust_symndx)\
|
531 |
|
|
(obfd, info, ibfd, sec, rel, adjustedp))
|
532 |
|
|
#define bfd_coff_link_add_one_symbol(info,abfd,name,flags,section,value,string,cp,coll,hashp)\
|
533 |
|
|
((coff_backend_info (abfd)->_bfd_coff_link_add_one_symbol)\
|
534 |
|
|
(info, abfd, name, flags, section, value, string, cp, coll, hashp))
|
535 |
|
|
|
536 |
|
|
#define bfd_coff_link_output_has_begun(a,p) \
|
537 |
|
|
((coff_backend_info (a)->_bfd_coff_link_output_has_begun) (a,p))
|
538 |
|
|
#define bfd_coff_final_link_postscript(a,p) \
|
539 |
|
|
((coff_backend_info (a)->_bfd_coff_final_link_postscript) (a,p))
|
540 |
|
|
|
541 |
|
|
Writing relocations
|
542 |
|
|
...................
|
543 |
|
|
|
544 |
|
|
To write relocations, the back end steps though the canonical
|
545 |
|
|
relocation table and create an `internal_reloc'. The symbol index to
|
546 |
|
|
use is removed from the `offset' field in the symbol table supplied.
|
547 |
|
|
The address comes directly from the sum of the section base address and
|
548 |
|
|
the relocation offset; the type is dug directly from the howto field.
|
549 |
|
|
Then the `internal_reloc' is swapped into the shape of an
|
550 |
|
|
`external_reloc' and written out to disk.
|
551 |
|
|
|
552 |
|
|
Reading linenumbers
|
553 |
|
|
...................
|
554 |
|
|
|
555 |
|
|
Creating the linenumber table is done by reading in the entire coff
|
556 |
|
|
linenumber table, and creating another table for internal use.
|
557 |
|
|
|
558 |
|
|
A coff linenumber table is structured so that each function is
|
559 |
|
|
marked as having a line number of 0. Each line within the function is
|
560 |
|
|
an offset from the first line in the function. The base of the line
|
561 |
|
|
number information for the table is stored in the symbol associated
|
562 |
|
|
with the function.
|
563 |
|
|
|
564 |
|
|
Note: The PE format uses line number 0 for a flag indicating a new
|
565 |
|
|
source file.
|
566 |
|
|
|
567 |
|
|
The information is copied from the external to the internal table,
|
568 |
|
|
and each symbol which marks a function is marked by pointing its...
|
569 |
|
|
|
570 |
|
|
How does this work ?
|
571 |
|
|
|
572 |
|
|
Reading relocations
|
573 |
|
|
...................
|
574 |
|
|
|
575 |
|
|
Coff relocations are easily transformed into the internal BFD form
|
576 |
|
|
(`arelent').
|
577 |
|
|
|
578 |
|
|
Reading a coff relocation table is done in the following stages:
|
579 |
|
|
|
580 |
|
|
* Read the entire coff relocation table into memory.
|
581 |
|
|
|
582 |
|
|
* Process each relocation in turn; first swap it from the external
|
583 |
|
|
to the internal form.
|
584 |
|
|
|
585 |
|
|
* Turn the symbol referenced in the relocation's symbol index into a
|
586 |
|
|
pointer into the canonical symbol table. This table is the same
|
587 |
|
|
as the one returned by a call to `bfd_canonicalize_symtab'. The
|
588 |
|
|
back end will call that routine and save the result if a
|
589 |
|
|
canonicalization hasn't been done.
|
590 |
|
|
|
591 |
|
|
* The reloc index is turned into a pointer to a howto structure, in
|
592 |
|
|
a back end specific way. For instance, the 386 and 960 use the
|
593 |
|
|
`r_type' to directly produce an index into a howto table vector;
|
594 |
|
|
the 88k subtracts a number from the `r_type' field and creates an
|
595 |
|
|
addend field.
|
596 |
|
|
|
597 |
|
|
|
598 |
|
|
File: bfd.info, Node: elf, Next: mmo, Prev: coff, Up: BFD back ends
|
599 |
|
|
|
600 |
|
|
|
601 |
|
|
|
602 |
|
|
ELF backends
|
603 |
|
|
|
604 |
|
|
BFD support for ELF formats is being worked on. Currently, the best
|
605 |
|
|
supported back ends are for sparc and i386 (running svr4 or Solaris 2).
|
606 |
|
|
|
607 |
|
|
Documentation of the internals of the support code still needs to be
|
608 |
|
|
written. The code is changing quickly enough that we haven't bothered
|
609 |
|
|
yet.
|
610 |
|
|
|
611 |
|
|
`bfd_elf_find_section'
|
612 |
|
|
......................
|
613 |
|
|
|
614 |
|
|
*Synopsis*
|
615 |
|
|
struct elf_internal_shdr *bfd_elf_find_section (bfd *abfd, char *name);
|
616 |
|
|
*Description*
|
617 |
|
|
Helper functions for GDB to locate the string tables. Since BFD hides
|
618 |
|
|
string tables from callers, GDB needs to use an internal hook to find
|
619 |
|
|
them. Sun's .stabstr, in particular, isn't even pointed to by the
|
620 |
|
|
.stab section, so ordinary mechanisms wouldn't work to find it, even if
|
621 |
|
|
we had some.
|
622 |
|
|
|
623 |
|
|
|
624 |
|
|
File: bfd.info, Node: mmo, Prev: elf, Up: BFD back ends
|
625 |
|
|
|
626 |
|
|
mmo backend
|
627 |
|
|
===========
|
628 |
|
|
|
629 |
|
|
The mmo object format is used exclusively together with Professor
|
630 |
|
|
Donald E. Knuth's educational 64-bit processor MMIX. The simulator
|
631 |
|
|
`mmix' which is available at
|
632 |
|
|
|
633 |
|
|
understands this format. That package also includes a combined
|
634 |
|
|
assembler and linker called `mmixal'. The mmo format has no advantages
|
635 |
|
|
feature-wise compared to e.g. ELF. It is a simple non-relocatable
|
636 |
|
|
object format with no support for archives or debugging information,
|
637 |
|
|
except for symbol value information and line numbers (which is not yet
|
638 |
|
|
implemented in BFD). See
|
639 |
|
|
for more
|
640 |
|
|
information about MMIX. The ELF format is used for intermediate object
|
641 |
|
|
files in the BFD implementation.
|
642 |
|
|
|
643 |
|
|
* Menu:
|
644 |
|
|
|
645 |
|
|
* File layout::
|
646 |
|
|
* Symbol-table::
|
647 |
|
|
* mmo section mapping::
|
648 |
|
|
|
649 |
|
|
|
650 |
|
|
File: bfd.info, Node: File layout, Next: Symbol-table, Prev: mmo, Up: mmo
|
651 |
|
|
|
652 |
|
|
File layout
|
653 |
|
|
-----------
|
654 |
|
|
|
655 |
|
|
The mmo file contents is not partitioned into named sections as with
|
656 |
|
|
e.g. ELF. Memory areas is formed by specifying the location of the
|
657 |
|
|
data that follows. Only the memory area `0x0000...00' to `0x01ff...ff'
|
658 |
|
|
is executable, so it is used for code (and constants) and the area
|
659 |
|
|
`0x2000...00' to `0x20ff...ff' is used for writable data. *Note mmo
|
660 |
|
|
section mapping::.
|
661 |
|
|
|
662 |
|
|
Contents is entered as 32-bit words, xor:ed over previous contents,
|
663 |
|
|
always zero-initialized. A word that starts with the byte `0x98' forms
|
664 |
|
|
a command called a `lopcode', where the next byte distinguished between
|
665 |
|
|
the thirteen lopcodes. The two remaining bytes, called the `Y' and `Z'
|
666 |
|
|
fields, or the `YZ' field (a 16-bit big-endian number), are used for
|
667 |
|
|
various purposes different for each lopcode. As documented in
|
668 |
|
|
, the
|
669 |
|
|
lopcodes are:
|
670 |
|
|
|
671 |
|
|
There is provision for specifying "special data" of 65536 different
|
672 |
|
|
types. We use type 80 (decimal), arbitrarily chosen the same as the
|
673 |
|
|
ELF `e_machine' number for MMIX, filling it with section information
|
674 |
|
|
normally found in ELF objects. *Note mmo section mapping::.
|
675 |
|
|
|
676 |
|
|
`lop_quote'
|
677 |
|
|
0x98000001. The next word is contents, regardless of whether it
|
678 |
|
|
starts with 0x98 or not.
|
679 |
|
|
|
680 |
|
|
`lop_loc'
|
681 |
|
|
0x9801YYZZ, where `Z' is 1 or 2. This is a location directive,
|
682 |
|
|
setting the location for the next data to the next 32-bit word
|
683 |
|
|
(for Z = 1) or 64-bit word (for Z = 2), plus Y * 2^56. Normally
|
684 |
|
|
`Y' is 0 for the text segment and 2 for the data segment.
|
685 |
|
|
|
686 |
|
|
`lop_skip'
|
687 |
|
|
0x9802YYZZ. Increase the current location by `YZ' bytes.
|
688 |
|
|
|
689 |
|
|
`lop_fixo'
|
690 |
|
|
0x9803YYZZ, where `Z' is 1 or 2. Store the current location as 64
|
691 |
|
|
bits into the location pointed to by the next 32-bit (Z = 1) or
|
692 |
|
|
64-bit (Z = 2) word, plus Y * 2^56.
|
693 |
|
|
|
694 |
|
|
`lop_fixr'
|
695 |
|
|
0x9804YYZZ. `YZ' is stored into the current location plus 2 - 4 *
|
696 |
|
|
YZ.
|
697 |
|
|
|
698 |
|
|
`lop_fixrx'
|
699 |
|
|
0x980500ZZ. `Z' is 16 or 24. A value `L' derived from the
|
700 |
|
|
following 32-bit word are used in a manner similar to `YZ' in
|
701 |
|
|
lop_fixr: it is xor:ed into the current location minus 4 * L. The
|
702 |
|
|
first byte of the word is 0 or 1. If it is 1, then L = (LOWEST 24
|
703 |
|
|
BITS OF WORD) - 2^Z, if 0, then L = (LOWEST 24 BITS OF WORD).
|
704 |
|
|
|
705 |
|
|
`lop_file'
|
706 |
|
|
0x9806YYZZ. `Y' is the file number, `Z' is count of 32-bit words.
|
707 |
|
|
Set the file number to `Y' and the line counter to 0. The next Z
|
708 |
|
|
* 4 bytes contain the file name, padded with zeros if the count is
|
709 |
|
|
not a multiple of four. The same `Y' may occur multiple times,
|
710 |
|
|
but `Z' must be 0 for all but the first occurrence.
|
711 |
|
|
|
712 |
|
|
`lop_line'
|
713 |
|
|
0x9807YYZZ. `YZ' is the line number. Together with lop_file, it
|
714 |
|
|
forms the source location for the next 32-bit word. Note that for
|
715 |
|
|
each non-lopcode 32-bit word, line numbers are assumed incremented
|
716 |
|
|
by one.
|
717 |
|
|
|
718 |
|
|
`lop_spec'
|
719 |
|
|
0x9808YYZZ. `YZ' is the type number. Data until the next lopcode
|
720 |
|
|
other than lop_quote forms special data of type `YZ'. *Note mmo
|
721 |
|
|
section mapping::.
|
722 |
|
|
|
723 |
|
|
Other types than 80, (or type 80 with a content that does not
|
724 |
|
|
parse) is stored in sections named `.MMIX.spec_data.N' where N is
|
725 |
|
|
the `YZ'-type. The flags for such a sections say not to allocate
|
726 |
|
|
or load the data. The vma is 0. Contents of multiple occurrences
|
727 |
|
|
of special data N is concatenated to the data of the previous
|
728 |
|
|
lop_spec Ns. The location in data or code at which the lop_spec
|
729 |
|
|
occurred is lost.
|
730 |
|
|
|
731 |
|
|
`lop_pre'
|
732 |
|
|
0x980901ZZ. The first lopcode in a file. The `Z' field forms the
|
733 |
|
|
length of header information in 32-bit words, where the first word
|
734 |
|
|
tells the time in seconds since `00:00:00 GMT Jan 1 1970'.
|
735 |
|
|
|
736 |
|
|
`lop_post'
|
737 |
|
|
0x980a00ZZ. Z > 32. This lopcode follows after all
|
738 |
|
|
content-generating lopcodes in a program. The `Z' field denotes
|
739 |
|
|
the value of `rG' at the beginning of the program. The following
|
740 |
|
|
256 - Z big-endian 64-bit words are loaded into global registers
|
741 |
|
|
`$G' ... `$255'.
|
742 |
|
|
|
743 |
|
|
`lop_stab'
|
744 |
|
|
0x980b0000. The next-to-last lopcode in a program. Must follow
|
745 |
|
|
immediately after the lop_post lopcode and its data. After this
|
746 |
|
|
lopcode follows all symbols in a compressed format (*note
|
747 |
|
|
Symbol-table::).
|
748 |
|
|
|
749 |
|
|
`lop_end'
|
750 |
|
|
0x980cYYZZ. The last lopcode in a program. It must follow the
|
751 |
|
|
lop_stab lopcode and its data. The `YZ' field contains the number
|
752 |
|
|
of 32-bit words of symbol table information after the preceding
|
753 |
|
|
lop_stab lopcode.
|
754 |
|
|
|
755 |
|
|
Note that the lopcode "fixups"; `lop_fixr', `lop_fixrx' and
|
756 |
|
|
`lop_fixo' are not generated by BFD, but are handled. They are
|
757 |
|
|
generated by `mmixal'.
|
758 |
|
|
|
759 |
|
|
This trivial one-label, one-instruction file:
|
760 |
|
|
|
761 |
|
|
:Main TRAP 1,2,3
|
762 |
|
|
|
763 |
|
|
can be represented this way in mmo:
|
764 |
|
|
|
765 |
|
|
0x98090101 - lop_pre, one 32-bit word with timestamp.
|
766 |
|
|
|
767 |
|
|
0x98010002 - lop_loc, text segment, using a 64-bit address.
|
768 |
|
|
Note that mmixal does not emit this for the file above.
|
769 |
|
|
0x00000000 - Address, high 32 bits.
|
770 |
|
|
0x00000000 - Address, low 32 bits.
|
771 |
|
|
0x98060002 - lop_file, 2 32-bit words for file-name.
|
772 |
|
|
0x74657374 - "test"
|
773 |
|
|
0x2e730000 - ".s\0\0"
|
774 |
|
|
0x98070001 - lop_line, line 1.
|
775 |
|
|
0x00010203 - TRAP 1,2,3
|
776 |
|
|
0x980a00ff - lop_post, setting $255 to 0.
|
777 |
|
|
0x00000000
|
778 |
|
|
0x00000000
|
779 |
|
|
0x980b0000 - lop_stab for ":Main" = 0, serial 1.
|
780 |
|
|
0x203a4040 *Note Symbol-table::.
|
781 |
|
|
0x10404020
|
782 |
|
|
0x4d206120
|
783 |
|
|
0x69016e00
|
784 |
|
|
0x81000000
|
785 |
|
|
0x980c0005 - lop_end; symbol table contained five 32-bit words.
|
786 |
|
|
|
787 |
|
|
|
788 |
|
|
File: bfd.info, Node: Symbol-table, Next: mmo section mapping, Prev: File layout, Up: mmo
|
789 |
|
|
|
790 |
|
|
Symbol table format
|
791 |
|
|
-------------------
|
792 |
|
|
|
793 |
|
|
From mmixal.w (or really, the generated mmixal.tex) in
|
794 |
|
|
):
|
795 |
|
|
"Symbols are stored and retrieved by means of a `ternary search trie',
|
796 |
|
|
following ideas of Bentley and Sedgewick. (See ACM-SIAM Symp. on
|
797 |
|
|
Discrete Algorithms `8' (1997), 360-369; R.Sedgewick, `Algorithms in C'
|
798 |
|
|
(Reading, Mass. Addison-Wesley, 1998), `15.4'.) Each trie node stores
|
799 |
|
|
a character, and there are branches to subtries for the cases where a
|
800 |
|
|
given character is less than, equal to, or greater than the character
|
801 |
|
|
in the trie. There also is a pointer to a symbol table entry if a
|
802 |
|
|
symbol ends at the current node."
|
803 |
|
|
|
804 |
|
|
So it's a tree encoded as a stream of bytes. The stream of bytes
|
805 |
|
|
acts on a single virtual global symbol, adding and removing characters
|
806 |
|
|
and signalling complete symbol points. Here, we read the stream and
|
807 |
|
|
create symbols at the completion points.
|
808 |
|
|
|
809 |
|
|
First, there's a control byte `m'. If any of the listed bits in `m'
|
810 |
|
|
is nonzero, we execute what stands at the right, in the listed order:
|
811 |
|
|
|
812 |
|
|
(MMO3_LEFT)
|
813 |
|
|
0x40 - Traverse left trie.
|
814 |
|
|
(Read a new command byte and recurse.)
|
815 |
|
|
|
816 |
|
|
(MMO3_SYMBITS)
|
817 |
|
|
0x2f - Read the next byte as a character and store it in the
|
818 |
|
|
current character position; increment character position.
|
819 |
|
|
Test the bits of `m':
|
820 |
|
|
|
821 |
|
|
(MMO3_WCHAR)
|
822 |
|
|
0x80 - The character is 16-bit (so read another byte,
|
823 |
|
|
merge into current character.
|
824 |
|
|
|
825 |
|
|
(MMO3_TYPEBITS)
|
826 |
|
|
0xf - We have a complete symbol; parse the type, value
|
827 |
|
|
and serial number and do what should be done
|
828 |
|
|
with a symbol. The type and length information
|
829 |
|
|
is in j = (m & 0xf).
|
830 |
|
|
|
831 |
|
|
(MMO3_REGQUAL_BITS)
|
832 |
|
|
j == 0xf: A register variable. The following
|
833 |
|
|
byte tells which register.
|
834 |
|
|
j <= 8: An absolute symbol. Read j bytes as the
|
835 |
|
|
big-endian number the symbol equals.
|
836 |
|
|
A j = 2 with two zero bytes denotes an
|
837 |
|
|
unknown symbol.
|
838 |
|
|
j > 8: As with j <= 8, but add (0x20 << 56)
|
839 |
|
|
to the value in the following j - 8
|
840 |
|
|
bytes.
|
841 |
|
|
|
842 |
|
|
Then comes the serial number, as a variant of
|
843 |
|
|
uleb128, but better named ubeb128:
|
844 |
|
|
Read bytes and shift the previous value left 7
|
845 |
|
|
(multiply by 128). Add in the new byte, repeat
|
846 |
|
|
until a byte has bit 7 set. The serial number
|
847 |
|
|
is the computed value minus 128.
|
848 |
|
|
|
849 |
|
|
(MMO3_MIDDLE)
|
850 |
|
|
0x20 - Traverse middle trie. (Read a new command byte
|
851 |
|
|
and recurse.) Decrement character position.
|
852 |
|
|
|
853 |
|
|
(MMO3_RIGHT)
|
854 |
|
|
0x10 - Traverse right trie. (Read a new command byte and
|
855 |
|
|
recurse.)
|
856 |
|
|
|
857 |
|
|
Let's look again at the `lop_stab' for the trivial file (*note File
|
858 |
|
|
layout::).
|
859 |
|
|
|
860 |
|
|
0x980b0000 - lop_stab for ":Main" = 0, serial 1.
|
861 |
|
|
0x203a4040
|
862 |
|
|
0x10404020
|
863 |
|
|
0x4d206120
|
864 |
|
|
0x69016e00
|
865 |
|
|
0x81000000
|
866 |
|
|
|
867 |
|
|
This forms the trivial trie (note that the path between ":" and "M"
|
868 |
|
|
is redundant):
|
869 |
|
|
|
870 |
|
|
203a ":"
|
871 |
|
|
40 /
|
872 |
|
|
40 /
|
873 |
|
|
10 \
|
874 |
|
|
40 /
|
875 |
|
|
40 /
|
876 |
|
|
204d "M"
|
877 |
|
|
2061 "a"
|
878 |
|
|
2069 "i"
|
879 |
|
|
016e "n" is the last character in a full symbol, and
|
880 |
|
|
with a value represented in one byte.
|
881 |
|
|
00 The value is 0.
|
882 |
|
|
81 The serial number is 1.
|
883 |
|
|
|
884 |
|
|
|
885 |
|
|
File: bfd.info, Node: mmo section mapping, Prev: Symbol-table, Up: mmo
|
886 |
|
|
|
887 |
|
|
mmo section mapping
|
888 |
|
|
-------------------
|
889 |
|
|
|
890 |
|
|
The implementation in BFD uses special data type 80 (decimal) to
|
891 |
|
|
encapsulate and describe named sections, containing e.g. debug
|
892 |
|
|
information. If needed, any datum in the encapsulation will be quoted
|
893 |
|
|
using lop_quote. First comes a 32-bit word holding the number of
|
894 |
|
|
32-bit words containing the zero-terminated zero-padded segment name.
|
895 |
|
|
After the name there's a 32-bit word holding flags describing the
|
896 |
|
|
section type. Then comes a 64-bit big-endian word with the section
|
897 |
|
|
length (in bytes), then another with the section start address.
|
898 |
|
|
Depending on the type of section, the contents might follow,
|
899 |
|
|
zero-padded to 32-bit boundary. For a loadable section (such as data
|
900 |
|
|
or code), the contents might follow at some later point, not
|
901 |
|
|
necessarily immediately, as a lop_loc with the same start address as in
|
902 |
|
|
the section description, followed by the contents. This in effect
|
903 |
|
|
forms a descriptor that must be emitted before the actual contents.
|
904 |
|
|
Sections described this way must not overlap.
|
905 |
|
|
|
906 |
|
|
For areas that don't have such descriptors, synthetic sections are
|
907 |
|
|
formed by BFD. Consecutive contents in the two memory areas
|
908 |
|
|
`0x0000...00' to `0x01ff...ff' and `0x2000...00' to `0x20ff...ff' are
|
909 |
|
|
entered in sections named `.text' and `.data' respectively. If an area
|
910 |
|
|
is not otherwise described, but would together with a neighboring lower
|
911 |
|
|
area be less than `0x40000000' bytes long, it is joined with the lower
|
912 |
|
|
area and the gap is zero-filled. For other cases, a new section is
|
913 |
|
|
formed, named `.MMIX.sec.N'. Here, N is a number, a running count
|
914 |
|
|
through the mmo file, starting at 0.
|
915 |
|
|
|
916 |
|
|
A loadable section specified as:
|
917 |
|
|
|
918 |
|
|
.section secname,"ax"
|
919 |
|
|
TETRA 1,2,3,4,-1,-2009
|
920 |
|
|
BYTE 80
|
921 |
|
|
|
922 |
|
|
and linked to address `0x4', is represented by the sequence:
|
923 |
|
|
|
924 |
|
|
0x98080050 - lop_spec 80
|
925 |
|
|
0x00000002 - two 32-bit words for the section name
|
926 |
|
|
0x7365636e - "secn"
|
927 |
|
|
0x616d6500 - "ame\0"
|
928 |
|
|
0x00000033 - flags CODE, READONLY, LOAD, ALLOC
|
929 |
|
|
0x00000000 - high 32 bits of section length
|
930 |
|
|
0x0000001c - section length is 28 bytes; 6 * 4 + 1 + alignment to 32 bits
|
931 |
|
|
0x00000000 - high 32 bits of section address
|
932 |
|
|
0x00000004 - section address is 4
|
933 |
|
|
0x98010002 - 64 bits with address of following data
|
934 |
|
|
0x00000000 - high 32 bits of address
|
935 |
|
|
0x00000004 - low 32 bits: data starts at address 4
|
936 |
|
|
0x00000001 - 1
|
937 |
|
|
0x00000002 - 2
|
938 |
|
|
0x00000003 - 3
|
939 |
|
|
0x00000004 - 4
|
940 |
|
|
0xffffffff - -1
|
941 |
|
|
0xfffff827 - -2009
|
942 |
|
|
0x50000000 - 80 as a byte, padded with zeros.
|
943 |
|
|
|
944 |
|
|
Note that the lop_spec wrapping does not include the section
|
945 |
|
|
contents. Compare this to a non-loaded section specified as:
|
946 |
|
|
|
947 |
|
|
.section thirdsec
|
948 |
|
|
TETRA 200001,100002
|
949 |
|
|
BYTE 38,40
|
950 |
|
|
|
951 |
|
|
This, when linked to address `0x200000000000001c', is represented by:
|
952 |
|
|
|
953 |
|
|
0x98080050 - lop_spec 80
|
954 |
|
|
0x00000002 - two 32-bit words for the section name
|
955 |
|
|
0x7365636e - "thir"
|
956 |
|
|
0x616d6500 - "dsec"
|
957 |
|
|
0x00000010 - flag READONLY
|
958 |
|
|
0x00000000 - high 32 bits of section length
|
959 |
|
|
0x0000000c - section length is 12 bytes; 2 * 4 + 2 + alignment to 32 bits
|
960 |
|
|
0x20000000 - high 32 bits of address
|
961 |
|
|
0x0000001c - low 32 bits of address 0x200000000000001c
|
962 |
|
|
0x00030d41 - 200001
|
963 |
|
|
0x000186a2 - 100002
|
964 |
|
|
0x26280000 - 38, 40 as bytes, padded with zeros
|
965 |
|
|
|
966 |
|
|
For the latter example, the section contents must not be loaded in
|
967 |
|
|
memory, and is therefore specified as part of the special data. The
|
968 |
|
|
address is usually unimportant but might provide information for e.g.
|
969 |
|
|
the DWARF 2 debugging format.
|
970 |
|
|
|