Change "reloc_howto_type" typedef to be "const", since all uses of it are (or
[binutils-gdb.git] / bfd / bfd-in2.h
1 /* Main header file for the bfd library -- portable access to object files.
2 Copyright 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
4
5 ** NOTE: bfd.h and bfd-in2.h are GENERATED files. Don't change them;
6 ** instead, change bfd-in.h or the other BFD source files processed to
7 ** generate these files.
8
9 This file is part of BFD, the Binary File Descriptor library.
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
24
25 /* bfd.h -- The only header file required by users of the bfd library
26
27 The bfd.h file is generated from bfd-in.h and various .c files; if you
28 change it, your changes will probably be lost.
29
30 All the prototypes and definitions following the comment "THE FOLLOWING
31 IS EXTRACTED FROM THE SOURCE" are extracted from the source files for
32 BFD. If you change it, someone oneday will extract it from the source
33 again, and your changes will be lost. To save yourself from this bind,
34 change the definitions in the source in the bfd directory. Type "make
35 docs" and then "make headers" in that directory, and magically this file
36 will change to reflect your changes.
37
38 If you don't have the tools to perform the extraction, then you are
39 safe from someone on your system trampling over your header files.
40 You should still maintain the equivalence between the source and this
41 file though; every change you make to the .c file should be reflected
42 here. */
43
44 #ifndef __BFD_H_SEEN__
45 #define __BFD_H_SEEN__
46
47 #include "ansidecl.h"
48 #include "obstack.h"
49
50 /* These two lines get substitutions done by commands in Makefile.in. */
51 #define BFD_VERSION "@VERSION@"
52 #define BFD_ARCH_SIZE @WORDSIZE@
53
54 #if BFD_ARCH_SIZE >= 64
55 #define BFD64
56 #endif
57
58 #ifndef INLINE
59 #if __GNUC__ >= 2
60 #define INLINE __inline__
61 #else
62 #define INLINE
63 #endif
64 #endif
65
66 /* 64-bit type definition (if any) from bfd's sysdep.h goes here */
67
68
69 /* forward declaration */
70 typedef struct _bfd bfd;
71
72 /* To squelch erroneous compiler warnings ("illegal pointer
73 combination") from the SVR3 compiler, we would like to typedef
74 boolean to int (it doesn't like functions which return boolean.
75 Making sure they are never implicitly declared to return int
76 doesn't seem to help). But this file is not configured based on
77 the host. */
78 /* General rules: functions which are boolean return true on success
79 and false on failure (unless they're a predicate). -- bfd.doc */
80 /* I'm sure this is going to break something and someone is going to
81 force me to change it. */
82 /* typedef enum boolean {false, true} boolean; */
83 /* Yup, SVR4 has a "typedef enum boolean" in <sys/types.h> -fnf */
84 /* It gets worse if the host also defines a true/false enum... -sts */
85 #ifndef TRUE_FALSE_ALREADY_DEFINED
86 typedef enum bfd_boolean {false, true} boolean;
87 #define BFD_TRUE_FALSE
88 #else
89 typedef enum bfd_boolean {bfd_false, bfd_true} boolean;
90 #endif
91
92 /* A pointer to a position in a file. */
93 /* FIXME: This should be using off_t from <sys/types.h>.
94 For now, try to avoid breaking stuff by not including <sys/types.h> here.
95 This will break on systems with 64-bit file offsets (e.g. 4.4BSD).
96 Probably the best long-term answer is to avoid using file_ptr AND off_t
97 in this header file, and to handle this in the BFD implementation
98 rather than in its interface. */
99 /* typedef off_t file_ptr; */
100 typedef long int file_ptr;
101
102 /* Support for different sizes of target format ints and addresses.
103 If the host implements 64-bit values, it defines BFD_HOST_64_BIT to
104 be the appropriate type. Otherwise, this code will fall back on
105 gcc's "long long" type if gcc is being used. BFD_HOST_64_BIT must
106 be defined in such a way as to be a valid type name by itself or
107 with "unsigned" prefixed. It should be a signed type by itself.
108
109 If neither is the case, then compilation will fail if 64-bit
110 targets are requested. If you don't request any 64-bit targets,
111 you should be safe. */
112
113 #ifdef BFD64
114
115 #if defined (__GNUC__) && !defined (BFD_HOST_64_BIT)
116 #define BFD_HOST_64_BIT long long
117 typedef BFD_HOST_64_BIT int64_type;
118 typedef unsigned BFD_HOST_64_BIT uint64_type;
119 #endif
120
121 #if !defined (uint64_type) && defined (__GNUC__)
122 #define uint64_type unsigned long long
123 #define int64_type long long
124 #endif
125 #ifndef uint64_typeLOW
126 #define uint64_typeLOW(x) ((unsigned long)(((x) & 0xffffffff)))
127 #define uint64_typeHIGH(x) ((unsigned long)(((x) >> 32) & 0xffffffff))
128 #endif
129
130 typedef unsigned BFD_HOST_64_BIT bfd_vma;
131 typedef BFD_HOST_64_BIT bfd_signed_vma;
132 typedef unsigned BFD_HOST_64_BIT bfd_size_type;
133 typedef unsigned BFD_HOST_64_BIT symvalue;
134 #ifndef fprintf_vma
135 #define fprintf_vma(s,x) \
136 fprintf(s,"%08lx%08lx", uint64_typeHIGH(x), uint64_typeLOW(x))
137 #define sprintf_vma(s,x) \
138 sprintf(s,"%08lx%08lx", uint64_typeHIGH(x), uint64_typeLOW(x))
139 #endif
140 #else /* not BFD64 */
141
142 /* Represent a target address. Also used as a generic unsigned type
143 which is guaranteed to be big enough to hold any arithmetic types
144 we need to deal with. */
145 typedef unsigned long bfd_vma;
146
147 /* A generic signed type which is guaranteed to be big enough to hold any
148 arithmetic types we need to deal with. Can be assumed to be compatible
149 with bfd_vma in the same way that signed and unsigned ints are compatible
150 (as parameters, in assignment, etc). */
151 typedef long bfd_signed_vma;
152
153 typedef unsigned long symvalue;
154 typedef unsigned long bfd_size_type;
155
156 /* Print a bfd_vma x on stream s. */
157 #define fprintf_vma(s,x) fprintf(s, "%08lx", x)
158 #define sprintf_vma(s,x) sprintf(s, "%08lx", x)
159 #endif /* not BFD64 */
160 #define printf_vma(x) fprintf_vma(stdout,x)
161
162 typedef unsigned int flagword; /* 32 bits of flags */
163 \f
164 /** File formats */
165
166 typedef enum bfd_format {
167 bfd_unknown = 0, /* file format is unknown */
168 bfd_object, /* linker/assember/compiler output */
169 bfd_archive, /* object archive file */
170 bfd_core, /* core dump */
171 bfd_type_end} /* marks the end; don't use it! */
172 bfd_format;
173
174 /* Values that may appear in the flags field of a BFD. These also
175 appear in the object_flags field of the bfd_target structure, where
176 they indicate the set of flags used by that backend (not all flags
177 are meaningful for all object file formats) (FIXME: at the moment,
178 the object_flags values have mostly just been copied from backend
179 to another, and are not necessarily correct). */
180
181 /* No flags. */
182 #define NO_FLAGS 0x00
183
184 /* BFD contains relocation entries. */
185 #define HAS_RELOC 0x01
186
187 /* BFD is directly executable. */
188 #define EXEC_P 0x02
189
190 /* BFD has line number information (basically used for F_LNNO in a
191 COFF header). */
192 #define HAS_LINENO 0x04
193
194 /* BFD has debugging information. */
195 #define HAS_DEBUG 0x08
196
197 /* BFD has symbols. */
198 #define HAS_SYMS 0x10
199
200 /* BFD has local symbols (basically used for F_LSYMS in a COFF
201 header). */
202 #define HAS_LOCALS 0x20
203
204 /* BFD is a dynamic object. */
205 #define DYNAMIC 0x40
206
207 /* Text section is write protected (if D_PAGED is not set, this is
208 like an a.out NMAGIC file) (the linker sets this by default, but
209 clears it for -r or -N). */
210 #define WP_TEXT 0x80
211
212 /* BFD is dynamically paged (this is like an a.out ZMAGIC file) (the
213 linker sets this by default, but clears it for -r or -n or -N). */
214 #define D_PAGED 0x100
215
216 /* BFD is relaxable (this means that bfd_relax_section may be able to
217 do something) (sometimes bfd_relax_section can do something even if
218 this is not set). */
219 #define BFD_IS_RELAXABLE 0x200
220
221 /* This may be set before writing out a BFD to request using a
222 traditional format. For example, this is used to request that when
223 writing out an a.out object the symbols not be hashed to eliminate
224 duplicates. */
225 #define BFD_TRADITIONAL_FORMAT 0x400
226 \f
227 /* symbols and relocation */
228
229 /* A count of carsyms (canonical archive symbols). */
230 typedef unsigned long symindex;
231
232 #define BFD_NO_MORE_SYMBOLS ((symindex) ~0)
233
234 /* General purpose part of a symbol X;
235 target specific parts are in libcoff.h, libaout.h, etc. */
236
237 #define bfd_get_section(x) ((x)->section)
238 #define bfd_get_output_section(x) ((x)->section->output_section)
239 #define bfd_set_section(x,y) ((x)->section) = (y)
240 #define bfd_asymbol_base(x) ((x)->section->vma)
241 #define bfd_asymbol_value(x) (bfd_asymbol_base(x) + (x)->value)
242 #define bfd_asymbol_name(x) ((x)->name)
243 /*Perhaps future: #define bfd_asymbol_bfd(x) ((x)->section->owner)*/
244 #define bfd_asymbol_bfd(x) ((x)->the_bfd)
245 #define bfd_asymbol_flavour(x) (bfd_asymbol_bfd(x)->xvec->flavour)
246
247 /* A canonical archive symbol. */
248 /* This is a type pun with struct ranlib on purpose! */
249 typedef struct carsym {
250 char *name;
251 file_ptr file_offset; /* look here to find the file */
252 } carsym; /* to make these you call a carsymogen */
253
254
255 /* Used in generating armaps (archive tables of contents).
256 Perhaps just a forward definition would do? */
257 struct orl { /* output ranlib */
258 char **name; /* symbol name */
259 file_ptr pos; /* bfd* or file position */
260 int namidx; /* index into string table */
261 };
262
263 \f
264
265 /* Linenumber stuff */
266 typedef struct lineno_cache_entry {
267 unsigned int line_number; /* Linenumber from start of function*/
268 union {
269 struct symbol_cache_entry *sym; /* Function name */
270 unsigned long offset; /* Offset into section */
271 } u;
272 } alent;
273 \f
274 /* object and core file sections */
275
276 #define align_power(addr, align) \
277 ( ((addr) + ((1<<(align))-1)) & (-1 << (align)))
278
279 typedef struct sec *sec_ptr;
280
281 #define bfd_get_section_name(bfd, ptr) ((ptr)->name + 0)
282 #define bfd_get_section_vma(bfd, ptr) ((ptr)->vma + 0)
283 #define bfd_get_section_alignment(bfd, ptr) ((ptr)->alignment_power + 0)
284 #define bfd_section_name(bfd, ptr) ((ptr)->name)
285 #define bfd_section_size(bfd, ptr) (bfd_get_section_size_before_reloc(ptr))
286 #define bfd_section_vma(bfd, ptr) ((ptr)->vma)
287 #define bfd_section_alignment(bfd, ptr) ((ptr)->alignment_power)
288 #define bfd_get_section_flags(bfd, ptr) ((ptr)->flags + 0)
289 #define bfd_get_section_userdata(bfd, ptr) ((ptr)->userdata)
290
291 #define bfd_is_com_section(ptr) (((ptr)->flags & SEC_IS_COMMON) != 0)
292
293 #define bfd_set_section_vma(bfd, ptr, val) (((ptr)->vma = (ptr)->lma= (val)), ((ptr)->user_set_vma = true), true)
294 #define bfd_set_section_alignment(bfd, ptr, val) (((ptr)->alignment_power = (val)),true)
295 #define bfd_set_section_userdata(bfd, ptr, val) (((ptr)->userdata = (val)),true)
296
297 typedef struct stat stat_type;
298 \f
299 typedef enum bfd_print_symbol
300 {
301 bfd_print_symbol_name,
302 bfd_print_symbol_more,
303 bfd_print_symbol_all
304 } bfd_print_symbol_type;
305
306 /* Information about a symbol that nm needs. */
307
308 typedef struct _symbol_info
309 {
310 symvalue value;
311 char type;
312 CONST char *name; /* Symbol name. */
313 char stab_other; /* Unused. */
314 short stab_desc; /* Info for N_TYPE. */
315 CONST char *stab_name;
316 } symbol_info;
317 \f
318 /* Hash table routines. There is no way to free up a hash table. */
319
320 /* An element in the hash table. Most uses will actually use a larger
321 structure, and an instance of this will be the first field. */
322
323 struct bfd_hash_entry
324 {
325 /* Next entry for this hash code. */
326 struct bfd_hash_entry *next;
327 /* String being hashed. */
328 const char *string;
329 /* Hash code. This is the full hash code, not the index into the
330 table. */
331 unsigned long hash;
332 };
333
334 /* A hash table. */
335
336 struct bfd_hash_table
337 {
338 /* The hash array. */
339 struct bfd_hash_entry **table;
340 /* The number of slots in the hash table. */
341 unsigned int size;
342 /* A function used to create new elements in the hash table. The
343 first entry is itself a pointer to an element. When this
344 function is first invoked, this pointer will be NULL. However,
345 having the pointer permits a hierarchy of method functions to be
346 built each of which calls the function in the superclass. Thus
347 each function should be written to allocate a new block of memory
348 only if the argument is NULL. */
349 struct bfd_hash_entry *(*newfunc) PARAMS ((struct bfd_hash_entry *,
350 struct bfd_hash_table *,
351 const char *));
352 /* An obstack for this hash table. */
353 struct obstack memory;
354 };
355
356 /* Initialize a hash table. */
357 extern boolean bfd_hash_table_init
358 PARAMS ((struct bfd_hash_table *,
359 struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
360 struct bfd_hash_table *,
361 const char *)));
362
363 /* Initialize a hash table specifying a size. */
364 extern boolean bfd_hash_table_init_n
365 PARAMS ((struct bfd_hash_table *,
366 struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
367 struct bfd_hash_table *,
368 const char *),
369 unsigned int size));
370
371 /* Free up a hash table. */
372 extern void bfd_hash_table_free PARAMS ((struct bfd_hash_table *));
373
374 /* Look up a string in a hash table. If CREATE is true, a new entry
375 will be created for this string if one does not already exist. The
376 COPY argument must be true if this routine should copy the string
377 into newly allocated memory when adding an entry. */
378 extern struct bfd_hash_entry *bfd_hash_lookup
379 PARAMS ((struct bfd_hash_table *, const char *, boolean create,
380 boolean copy));
381
382 /* Base method for creating a hash table entry. */
383 extern struct bfd_hash_entry *bfd_hash_newfunc
384 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *,
385 const char *));
386
387 /* Grab some space for a hash table entry. */
388 extern PTR bfd_hash_allocate PARAMS ((struct bfd_hash_table *,
389 unsigned int));
390
391 /* Traverse a hash table in a random order, calling a function on each
392 element. If the function returns false, the traversal stops. The
393 INFO argument is passed to the function. */
394 extern void bfd_hash_traverse PARAMS ((struct bfd_hash_table *,
395 boolean (*) (struct bfd_hash_entry *,
396 PTR),
397 PTR info));
398 \f
399 /* Semi-portable string concatenation in cpp.
400 The CAT4 hack is to avoid a problem with some strict ANSI C preprocessors.
401 The problem is, "32_" is not a valid preprocessing token, and we don't
402 want extra underscores (e.g., "nlm_32_"). The XCAT2 macro will cause the
403 inner CAT macros to be evaluated first, producing still-valid pp-tokens.
404 Then the final concatenation can be done. (Sigh.) */
405 #ifndef CAT
406 #ifdef SABER
407 #define CAT(a,b) a##b
408 #define CAT3(a,b,c) a##b##c
409 #define CAT4(a,b,c,d) a##b##c##d
410 #else
411 #if defined(__STDC__) || defined(ALMOST_STDC)
412 #define CAT(a,b) a##b
413 #define CAT3(a,b,c) a##b##c
414 #define XCAT2(a,b) CAT(a,b)
415 #define CAT4(a,b,c,d) XCAT2(CAT(a,b),CAT(c,d))
416 #else
417 #define CAT(a,b) a/**/b
418 #define CAT3(a,b,c) a/**/b/**/c
419 #define CAT4(a,b,c,d) a/**/b/**/c/**/d
420 #endif
421 #endif
422 #endif
423
424 #define COFF_SWAP_TABLE (PTR) &bfd_coff_std_swap_table
425 \f
426 /* User program access to BFD facilities */
427
428 /* Direct I/O routines, for programs which know more about the object
429 file than BFD does. Use higher level routines if possible. */
430
431 extern bfd_size_type bfd_read
432 PARAMS ((PTR, bfd_size_type size, bfd_size_type nitems, bfd *abfd));
433 extern bfd_size_type bfd_write
434 PARAMS ((const PTR, bfd_size_type size, bfd_size_type nitems, bfd *abfd));
435 extern int bfd_seek PARAMS ((bfd *abfd, file_ptr fp, int direction));
436 extern long bfd_tell PARAMS ((bfd *abfd));
437 extern int bfd_flush PARAMS ((bfd *abfd));
438 extern int bfd_stat PARAMS ((bfd *abfd, struct stat *));
439
440 /* Cast from const char * to char * so that caller can assign to
441 a char * without a warning. */
442 #define bfd_get_filename(abfd) ((char *) (abfd)->filename)
443 #define bfd_get_cacheable(abfd) ((abfd)->cacheable)
444 #define bfd_get_format(abfd) ((abfd)->format)
445 #define bfd_get_target(abfd) ((abfd)->xvec->name)
446 #define bfd_get_flavour(abfd) ((abfd)->xvec->flavour)
447 #define bfd_get_file_flags(abfd) ((abfd)->flags)
448 #define bfd_applicable_file_flags(abfd) ((abfd)->xvec->object_flags)
449 #define bfd_applicable_section_flags(abfd) ((abfd)->xvec->section_flags)
450 #define bfd_my_archive(abfd) ((abfd)->my_archive)
451 #define bfd_has_map(abfd) ((abfd)->has_armap)
452
453 #define bfd_valid_reloc_types(abfd) ((abfd)->xvec->valid_reloc_types)
454 #define bfd_usrdata(abfd) ((abfd)->usrdata)
455
456 #define bfd_get_start_address(abfd) ((abfd)->start_address)
457 #define bfd_get_symcount(abfd) ((abfd)->symcount)
458 #define bfd_get_outsymbols(abfd) ((abfd)->outsymbols)
459 #define bfd_count_sections(abfd) ((abfd)->section_count)
460
461 #define bfd_get_symbol_leading_char(abfd) ((abfd)->xvec->symbol_leading_char)
462
463 #define bfd_set_cacheable(abfd,bool) (((abfd)->cacheable = (bool)), true)
464
465 /* Byte swapping routines. */
466
467 bfd_vma bfd_getb64 PARAMS ((const unsigned char *));
468 bfd_vma bfd_getl64 PARAMS ((const unsigned char *));
469 bfd_signed_vma bfd_getb_signed_64 PARAMS ((const unsigned char *));
470 bfd_signed_vma bfd_getl_signed_64 PARAMS ((const unsigned char *));
471 bfd_vma bfd_getb32 PARAMS ((const unsigned char *));
472 bfd_vma bfd_getl32 PARAMS ((const unsigned char *));
473 bfd_signed_vma bfd_getb_signed_32 PARAMS ((const unsigned char *));
474 bfd_signed_vma bfd_getl_signed_32 PARAMS ((const unsigned char *));
475 bfd_vma bfd_getb16 PARAMS ((const unsigned char *));
476 bfd_vma bfd_getl16 PARAMS ((const unsigned char *));
477 bfd_signed_vma bfd_getb_signed_16 PARAMS ((const unsigned char *));
478 bfd_signed_vma bfd_getl_signed_16 PARAMS ((const unsigned char *));
479 void bfd_putb64 PARAMS ((bfd_vma, unsigned char *));
480 void bfd_putl64 PARAMS ((bfd_vma, unsigned char *));
481 void bfd_putb32 PARAMS ((bfd_vma, unsigned char *));
482 void bfd_putl32 PARAMS ((bfd_vma, unsigned char *));
483 void bfd_putb16 PARAMS ((bfd_vma, unsigned char *));
484 void bfd_putl16 PARAMS ((bfd_vma, unsigned char *));
485 \f
486 /* Externally visible ECOFF routines. */
487
488 #if defined(__STDC__) || defined(ALMOST_STDC)
489 struct ecoff_debug_info;
490 struct ecoff_debug_swap;
491 struct ecoff_extr;
492 struct symbol_cache_entry;
493 struct bfd_link_info;
494 #endif
495 extern bfd_vma bfd_ecoff_get_gp_value PARAMS ((bfd * abfd));
496 extern boolean bfd_ecoff_set_gp_value PARAMS ((bfd *abfd, bfd_vma gp_value));
497 extern boolean bfd_ecoff_set_regmasks
498 PARAMS ((bfd *abfd, unsigned long gprmask, unsigned long fprmask,
499 unsigned long *cprmask));
500 extern PTR bfd_ecoff_debug_init
501 PARAMS ((bfd *output_bfd, struct ecoff_debug_info *output_debug,
502 const struct ecoff_debug_swap *output_swap,
503 struct bfd_link_info *));
504 extern void bfd_ecoff_debug_free
505 PARAMS ((PTR handle, bfd *output_bfd, struct ecoff_debug_info *output_debug,
506 const struct ecoff_debug_swap *output_swap,
507 struct bfd_link_info *));
508 extern boolean bfd_ecoff_debug_accumulate
509 PARAMS ((PTR handle, bfd *output_bfd, struct ecoff_debug_info *output_debug,
510 const struct ecoff_debug_swap *output_swap,
511 bfd *input_bfd, struct ecoff_debug_info *input_debug,
512 const struct ecoff_debug_swap *input_swap,
513 struct bfd_link_info *));
514 extern boolean bfd_ecoff_debug_accumulate_other
515 PARAMS ((PTR handle, bfd *output_bfd, struct ecoff_debug_info *output_debug,
516 const struct ecoff_debug_swap *output_swap, bfd *input_bfd,
517 struct bfd_link_info *));
518 extern boolean bfd_ecoff_debug_externals
519 PARAMS ((bfd *abfd, struct ecoff_debug_info *debug,
520 const struct ecoff_debug_swap *swap,
521 boolean relocateable,
522 boolean (*get_extr) (struct symbol_cache_entry *,
523 struct ecoff_extr *),
524 void (*set_index) (struct symbol_cache_entry *,
525 bfd_size_type)));
526 extern boolean bfd_ecoff_debug_one_external
527 PARAMS ((bfd *abfd, struct ecoff_debug_info *debug,
528 const struct ecoff_debug_swap *swap,
529 const char *name, struct ecoff_extr *esym));
530 extern bfd_size_type bfd_ecoff_debug_size
531 PARAMS ((bfd *abfd, struct ecoff_debug_info *debug,
532 const struct ecoff_debug_swap *swap));
533 extern boolean bfd_ecoff_write_debug
534 PARAMS ((bfd *abfd, struct ecoff_debug_info *debug,
535 const struct ecoff_debug_swap *swap, file_ptr where));
536 extern boolean bfd_ecoff_write_accumulated_debug
537 PARAMS ((PTR handle, bfd *abfd, struct ecoff_debug_info *debug,
538 const struct ecoff_debug_swap *swap,
539 struct bfd_link_info *info, file_ptr where));
540 extern boolean bfd_mips_ecoff_create_embedded_relocs
541 PARAMS ((bfd *, struct bfd_link_info *, struct sec *, struct sec *,
542 char **));
543
544 /* Externally visible ELF routines. */
545
546 extern boolean bfd_elf32_record_link_assignment
547 PARAMS ((bfd *, struct bfd_link_info *, const char *));
548 extern boolean bfd_elf64_record_link_assignment
549 PARAMS ((bfd *, struct bfd_link_info *, const char *));
550 extern boolean bfd_elf32_size_dynamic_sections
551 PARAMS ((bfd *, const char *, const char *, boolean,
552 struct bfd_link_info *, struct sec **));
553 extern boolean bfd_elf64_size_dynamic_sections
554 PARAMS ((bfd *, const char *, const char *, boolean,
555 struct bfd_link_info *, struct sec **));
556 extern void bfd_elf_set_dt_needed_name PARAMS ((bfd *, const char *));
557
558 /* SunOS shared library support routines for the linker. */
559
560 extern boolean bfd_sunos_record_link_assignment
561 PARAMS ((bfd *, struct bfd_link_info *, const char *));
562 extern boolean bfd_sunos_size_dynamic_sections
563 PARAMS ((bfd *, struct bfd_link_info *, struct sec **, struct sec **,
564 struct sec **));
565
566 /* Linux shared library support routines for the linker. */
567
568 extern boolean bfd_linux_size_dynamic_sections
569 PARAMS ((bfd *, struct bfd_link_info *));
570
571 /* And more from the source. */
572 void
573 bfd_init PARAMS ((void));
574
575 bfd *
576 bfd_openr PARAMS ((CONST char *filename, CONST char *target));
577
578 bfd *
579 bfd_fdopenr PARAMS ((CONST char *filename, CONST char *target, int fd));
580
581 bfd *
582 bfd_openw PARAMS ((CONST char *filename, CONST char *target));
583
584 boolean
585 bfd_close PARAMS ((bfd *abfd));
586
587 boolean
588 bfd_close_all_done PARAMS ((bfd *));
589
590 bfd_size_type
591 bfd_alloc_size PARAMS ((bfd *abfd));
592
593 bfd *
594 bfd_create PARAMS ((CONST char *filename, bfd *templ));
595
596
597 /* Byte swapping macros for user section data. */
598
599 #define bfd_put_8(abfd, val, ptr) \
600 (*((unsigned char *)(ptr)) = (unsigned char)(val))
601 #define bfd_put_signed_8 \
602 bfd_put_8
603 #define bfd_get_8(abfd, ptr) \
604 (*(unsigned char *)(ptr))
605 #define bfd_get_signed_8(abfd, ptr) \
606 ((*(unsigned char *)(ptr) ^ 0x80) - 0x80)
607
608 #define bfd_put_16(abfd, val, ptr) \
609 BFD_SEND(abfd, bfd_putx16, ((val),(ptr)))
610 #define bfd_put_signed_16 \
611 bfd_put_16
612 #define bfd_get_16(abfd, ptr) \
613 BFD_SEND(abfd, bfd_getx16, (ptr))
614 #define bfd_get_signed_16(abfd, ptr) \
615 BFD_SEND (abfd, bfd_getx_signed_16, (ptr))
616
617 #define bfd_put_32(abfd, val, ptr) \
618 BFD_SEND(abfd, bfd_putx32, ((val),(ptr)))
619 #define bfd_put_signed_32 \
620 bfd_put_32
621 #define bfd_get_32(abfd, ptr) \
622 BFD_SEND(abfd, bfd_getx32, (ptr))
623 #define bfd_get_signed_32(abfd, ptr) \
624 BFD_SEND(abfd, bfd_getx_signed_32, (ptr))
625
626 #define bfd_put_64(abfd, val, ptr) \
627 BFD_SEND(abfd, bfd_putx64, ((val), (ptr)))
628 #define bfd_put_signed_64 \
629 bfd_put_64
630 #define bfd_get_64(abfd, ptr) \
631 BFD_SEND(abfd, bfd_getx64, (ptr))
632 #define bfd_get_signed_64(abfd, ptr) \
633 BFD_SEND(abfd, bfd_getx_signed_64, (ptr))
634
635
636 /* Byte swapping macros for file header data. */
637
638 #define bfd_h_put_8(abfd, val, ptr) \
639 bfd_put_8 (abfd, val, ptr)
640 #define bfd_h_put_signed_8(abfd, val, ptr) \
641 bfd_put_8 (abfd, val, ptr)
642 #define bfd_h_get_8(abfd, ptr) \
643 bfd_get_8 (abfd, ptr)
644 #define bfd_h_get_signed_8(abfd, ptr) \
645 bfd_get_signed_8 (abfd, ptr)
646
647 #define bfd_h_put_16(abfd, val, ptr) \
648 BFD_SEND(abfd, bfd_h_putx16,(val,ptr))
649 #define bfd_h_put_signed_16 \
650 bfd_h_put_16
651 #define bfd_h_get_16(abfd, ptr) \
652 BFD_SEND(abfd, bfd_h_getx16,(ptr))
653 #define bfd_h_get_signed_16(abfd, ptr) \
654 BFD_SEND(abfd, bfd_h_getx_signed_16, (ptr))
655
656 #define bfd_h_put_32(abfd, val, ptr) \
657 BFD_SEND(abfd, bfd_h_putx32,(val,ptr))
658 #define bfd_h_put_signed_32 \
659 bfd_h_put_32
660 #define bfd_h_get_32(abfd, ptr) \
661 BFD_SEND(abfd, bfd_h_getx32,(ptr))
662 #define bfd_h_get_signed_32(abfd, ptr) \
663 BFD_SEND(abfd, bfd_h_getx_signed_32, (ptr))
664
665 #define bfd_h_put_64(abfd, val, ptr) \
666 BFD_SEND(abfd, bfd_h_putx64,(val, ptr))
667 #define bfd_h_put_signed_64 \
668 bfd_h_put_64
669 #define bfd_h_get_64(abfd, ptr) \
670 BFD_SEND(abfd, bfd_h_getx64,(ptr))
671 #define bfd_h_get_signed_64(abfd, ptr) \
672 BFD_SEND(abfd, bfd_h_getx_signed_64, (ptr))
673
674 typedef struct sec
675 {
676 /* The name of the section; the name isn't a copy, the pointer is
677 the same as that passed to bfd_make_section. */
678
679 CONST char *name;
680
681 /* Which section is it; 0..nth. */
682
683 int index;
684
685 /* The next section in the list belonging to the BFD, or NULL. */
686
687 struct sec *next;
688
689 /* The field flags contains attributes of the section. Some
690 flags are read in from the object file, and some are
691 synthesized from other information. */
692
693 flagword flags;
694
695 #define SEC_NO_FLAGS 0x000
696
697 /* Tells the OS to allocate space for this section when loading.
698 This is clear for a section containing debug information
699 only. */
700 #define SEC_ALLOC 0x001
701
702 /* Tells the OS to load the section from the file when loading.
703 This is clear for a .bss section. */
704 #define SEC_LOAD 0x002
705
706 /* The section contains data still to be relocated, so there is
707 some relocation information too. */
708 #define SEC_RELOC 0x004
709
710 #if 0 /* Obsolete ? */
711 #define SEC_BALIGN 0x008
712 #endif
713
714 /* A signal to the OS that the section contains read only
715 data. */
716 #define SEC_READONLY 0x010
717
718 /* The section contains code only. */
719 #define SEC_CODE 0x020
720
721 /* The section contains data only. */
722 #define SEC_DATA 0x040
723
724 /* The section will reside in ROM. */
725 #define SEC_ROM 0x080
726
727 /* The section contains constructor information. This section
728 type is used by the linker to create lists of constructors and
729 destructors used by <<g++>>. When a back end sees a symbol
730 which should be used in a constructor list, it creates a new
731 section for the type of name (e.g., <<__CTOR_LIST__>>), attaches
732 the symbol to it, and builds a relocation. To build the lists
733 of constructors, all the linker has to do is catenate all the
734 sections called <<__CTOR_LIST__>> and relocate the data
735 contained within - exactly the operations it would peform on
736 standard data. */
737 #define SEC_CONSTRUCTOR 0x100
738
739 /* The section is a constuctor, and should be placed at the
740 end of the text, data, or bss section(?). */
741 #define SEC_CONSTRUCTOR_TEXT 0x1100
742 #define SEC_CONSTRUCTOR_DATA 0x2100
743 #define SEC_CONSTRUCTOR_BSS 0x3100
744
745 /* The section has contents - a data section could be
746 <<SEC_ALLOC>> | <<SEC_HAS_CONTENTS>>; a debug section could be
747 <<SEC_HAS_CONTENTS>> */
748 #define SEC_HAS_CONTENTS 0x200
749
750 /* An instruction to the linker to not output the section
751 even if it has information which would normally be written. */
752 #define SEC_NEVER_LOAD 0x400
753
754 /* The section is a COFF shared library section. This flag is
755 only for the linker. If this type of section appears in
756 the input file, the linker must copy it to the output file
757 without changing the vma or size. FIXME: Although this
758 was originally intended to be general, it really is COFF
759 specific (and the flag was renamed to indicate this). It
760 might be cleaner to have some more general mechanism to
761 allow the back end to control what the linker does with
762 sections. */
763 #define SEC_COFF_SHARED_LIBRARY 0x800
764
765 /* The section is a common section (symbols may be defined
766 multiple times, the value of a symbol is the amount of
767 space it requires, and the largest symbol value is the one
768 used). Most targets have exactly one of these (which we
769 translate to bfd_com_section_ptr), but ECOFF has two. */
770 #define SEC_IS_COMMON 0x8000
771
772 /* The section contains only debugging information. For
773 example, this is set for ELF .debug and .stab sections.
774 strip tests this flag to see if a section can be
775 discarded. */
776 #define SEC_DEBUGGING 0x10000
777
778 /* The contents of this section are held in memory pointed to
779 by the contents field. This is checked by
780 bfd_get_section_contents, and the data is retrieved from
781 memory if appropriate. */
782 #define SEC_IN_MEMORY 0x20000
783
784 /* End of section flags. */
785
786 /* The virtual memory address of the section - where it will be
787 at run time. The symbols are relocated against this. The
788 user_set_vma flag is maintained by bfd; if it's not set, the
789 backend can assign addresses (for example, in <<a.out>>, where
790 the default address for <<.data>> is dependent on the specific
791 target and various flags). */
792
793 bfd_vma vma;
794 boolean user_set_vma;
795
796 /* The load address of the section - where it would be in a
797 rom image; really only used for writing section header
798 information. */
799
800 bfd_vma lma;
801
802 /* The size of the section in bytes, as it will be output.
803 contains a value even if the section has no contents (e.g., the
804 size of <<.bss>>). This will be filled in after relocation */
805
806 bfd_size_type _cooked_size;
807
808 /* The original size on disk of the section, in bytes. Normally this
809 value is the same as the size, but if some relaxing has
810 been done, then this value will be bigger. */
811
812 bfd_size_type _raw_size;
813
814 /* If this section is going to be output, then this value is the
815 offset into the output section of the first byte in the input
816 section. E.g., if this was going to start at the 100th byte in
817 the output section, this value would be 100. */
818
819 bfd_vma output_offset;
820
821 /* The output section through which to map on output. */
822
823 struct sec *output_section;
824
825 /* The alignment requirement of the section, as an exponent of 2 -
826 e.g., 3 aligns to 2^3 (or 8). */
827
828 unsigned int alignment_power;
829
830 /* If an input section, a pointer to a vector of relocation
831 records for the data in this section. */
832
833 struct reloc_cache_entry *relocation;
834
835 /* If an output section, a pointer to a vector of pointers to
836 relocation records for the data in this section. */
837
838 struct reloc_cache_entry **orelocation;
839
840 /* The number of relocation records in one of the above */
841
842 unsigned reloc_count;
843
844 /* Information below is back end specific - and not always used
845 or updated. */
846
847 /* File position of section data */
848
849 file_ptr filepos;
850
851 /* File position of relocation info */
852
853 file_ptr rel_filepos;
854
855 /* File position of line data */
856
857 file_ptr line_filepos;
858
859 /* Pointer to data for applications */
860
861 PTR userdata;
862
863 /* If the SEC_IN_MEMORY flag is set, this points to the actual
864 contents. */
865 unsigned char *contents;
866
867 /* Attached line number information */
868
869 alent *lineno;
870
871 /* Number of line number records */
872
873 unsigned int lineno_count;
874
875 /* When a section is being output, this value changes as more
876 linenumbers are written out */
877
878 file_ptr moving_line_filepos;
879
880 /* What the section number is in the target world */
881
882 int target_index;
883
884 PTR used_by_bfd;
885
886 /* If this is a constructor section then here is a list of the
887 relocations created to relocate items within it. */
888
889 struct relent_chain *constructor_chain;
890
891 /* The BFD which owns the section. */
892
893 bfd *owner;
894
895 boolean reloc_done;
896 /* A symbol which points at this section only */
897 struct symbol_cache_entry *symbol;
898 struct symbol_cache_entry **symbol_ptr_ptr;
899
900 struct bfd_link_order *link_order_head;
901 struct bfd_link_order *link_order_tail;
902 } asection ;
903
904 /* These sections are global, and are managed by BFD. The application
905 and target back end are not permitted to change the values in
906 these sections. New code should use the section_ptr macros rather
907 than referring directly to the const sections. The const sections
908 may eventually vanish. */
909 #define BFD_ABS_SECTION_NAME "*ABS*"
910 #define BFD_UND_SECTION_NAME "*UND*"
911 #define BFD_COM_SECTION_NAME "*COM*"
912 #define BFD_IND_SECTION_NAME "*IND*"
913
914 /* the absolute section */
915 extern const asection bfd_abs_section;
916 #define bfd_abs_section_ptr ((asection *) &bfd_abs_section)
917 #define bfd_is_abs_section(sec) ((sec) == bfd_abs_section_ptr)
918 /* Pointer to the undefined section */
919 extern const asection bfd_und_section;
920 #define bfd_und_section_ptr ((asection *) &bfd_und_section)
921 #define bfd_is_und_section(sec) ((sec) == bfd_und_section_ptr)
922 /* Pointer to the common section */
923 extern const asection bfd_com_section;
924 #define bfd_com_section_ptr ((asection *) &bfd_com_section)
925 /* Pointer to the indirect section */
926 extern const asection bfd_ind_section;
927 #define bfd_ind_section_ptr ((asection *) &bfd_ind_section)
928 #define bfd_is_ind_section(sec) ((sec) == bfd_ind_section_ptr)
929
930 extern const struct symbol_cache_entry * const bfd_abs_symbol;
931 extern const struct symbol_cache_entry * const bfd_com_symbol;
932 extern const struct symbol_cache_entry * const bfd_und_symbol;
933 extern const struct symbol_cache_entry * const bfd_ind_symbol;
934 #define bfd_get_section_size_before_reloc(section) \
935 (section->reloc_done ? (abort(),1): (section)->_raw_size)
936 #define bfd_get_section_size_after_reloc(section) \
937 ((section->reloc_done) ? (section)->_cooked_size: (abort(),1))
938 asection *
939 bfd_get_section_by_name PARAMS ((bfd *abfd, CONST char *name));
940
941 asection *
942 bfd_make_section_old_way PARAMS ((bfd *abfd, CONST char *name));
943
944 asection *
945 bfd_make_section_anyway PARAMS ((bfd *abfd, CONST char *name));
946
947 asection *
948 bfd_make_section PARAMS ((bfd *, CONST char *name));
949
950 boolean
951 bfd_set_section_flags PARAMS ((bfd *abfd, asection *sec, flagword flags));
952
953 void
954 bfd_map_over_sections PARAMS ((bfd *abfd,
955 void (*func)(bfd *abfd,
956 asection *sect,
957 PTR obj),
958 PTR obj));
959
960 boolean
961 bfd_set_section_size PARAMS ((bfd *abfd, asection *sec, bfd_size_type val));
962
963 boolean
964 bfd_set_section_contents
965 PARAMS ((bfd *abfd,
966 asection *section,
967 PTR data,
968 file_ptr offset,
969 bfd_size_type count));
970
971 boolean
972 bfd_get_section_contents
973 PARAMS ((bfd *abfd, asection *section, PTR location,
974 file_ptr offset, bfd_size_type count));
975
976 boolean
977 bfd_copy_private_section_data PARAMS ((bfd *ibfd, asection *isec, bfd *obfd, asection *osec));
978
979 #define bfd_copy_private_section_data(ibfd, isection, obfd, osection) \
980 BFD_SEND (ibfd, _bfd_copy_private_section_data, \
981 (ibfd, isection, obfd, osection))
982 enum bfd_architecture
983 {
984 bfd_arch_unknown, /* File arch not known */
985 bfd_arch_obscure, /* Arch known, not one of these */
986 bfd_arch_m68k, /* Motorola 68xxx */
987 bfd_arch_vax, /* DEC Vax */
988 bfd_arch_i960, /* Intel 960 */
989 /* The order of the following is important.
990 lower number indicates a machine type that
991 only accepts a subset of the instructions
992 available to machines with higher numbers.
993 The exception is the "ca", which is
994 incompatible with all other machines except
995 "core". */
996
997 #define bfd_mach_i960_core 1
998 #define bfd_mach_i960_ka_sa 2
999 #define bfd_mach_i960_kb_sb 3
1000 #define bfd_mach_i960_mc 4
1001 #define bfd_mach_i960_xa 5
1002 #define bfd_mach_i960_ca 6
1003 /* start-sanitize-i960xl */
1004 #define bfd_mach_i960_xl 7
1005 /* end-sanitize-i960xl */
1006
1007 bfd_arch_a29k, /* AMD 29000 */
1008 bfd_arch_sparc, /* SPARC */
1009 bfd_arch_mips, /* MIPS Rxxxx */
1010 bfd_arch_i386, /* Intel 386 */
1011 bfd_arch_we32k, /* AT&T WE32xxx */
1012 bfd_arch_tahoe, /* CCI/Harris Tahoe */
1013 bfd_arch_i860, /* Intel 860 */
1014 bfd_arch_romp, /* IBM ROMP PC/RT */
1015 bfd_arch_alliant, /* Alliant */
1016 bfd_arch_convex, /* Convex */
1017 bfd_arch_m88k, /* Motorola 88xxx */
1018 bfd_arch_pyramid, /* Pyramid Technology */
1019 bfd_arch_h8300, /* Hitachi H8/300 */
1020 #define bfd_mach_h8300 1
1021 #define bfd_mach_h8300h 2
1022 bfd_arch_powerpc, /* PowerPC */
1023 bfd_arch_rs6000, /* IBM RS/6000 */
1024 bfd_arch_hppa, /* HP PA RISC */
1025 bfd_arch_z8k, /* Zilog Z8000 */
1026 #define bfd_mach_z8001 1
1027 #define bfd_mach_z8002 2
1028 bfd_arch_h8500, /* Hitachi H8/500 */
1029 bfd_arch_sh, /* Hitachi SH */
1030 bfd_arch_alpha, /* Dec Alpha */
1031 bfd_arch_arm, /* Advanced Risc Machines ARM */
1032 bfd_arch_ns32k, /* National Semiconductors ns32000 */
1033 /* start-sanitize-rce */
1034 bfd_arch_rce, /* Motorola RCE */
1035 /* end-sanitize-rce */
1036 /* start-sanitize-arc */
1037 bfd_arch_arc, /* Argonaut RISC Core */
1038 /* end-sanitize-arc */
1039 bfd_arch_last
1040 };
1041
1042 typedef struct bfd_arch_info
1043 {
1044 int bits_per_word;
1045 int bits_per_address;
1046 int bits_per_byte;
1047 enum bfd_architecture arch;
1048 long mach;
1049 char *arch_name;
1050 CONST char *printable_name;
1051 unsigned int section_align_power;
1052 /* true if this is the default machine for the architecture */
1053 boolean the_default;
1054 CONST struct bfd_arch_info * (*compatible)
1055 PARAMS ((CONST struct bfd_arch_info *a,
1056 CONST struct bfd_arch_info *b));
1057
1058 boolean (*scan) PARAMS ((CONST struct bfd_arch_info *, CONST char *));
1059 /* How to disassemble an instruction, producing a printable
1060 representation on a specified stdio stream. This isn't
1061 defined for most processors at present, because of the size
1062 of the additional tables it would drag in, and because gdb
1063 wants to use a different interface. */
1064 unsigned int (*disassemble) PARAMS ((bfd_vma addr, CONST char *data,
1065 PTR stream));
1066
1067 struct bfd_arch_info *next;
1068 } bfd_arch_info_type;
1069 CONST char *
1070 bfd_printable_name PARAMS ((bfd *abfd));
1071
1072 bfd_arch_info_type *
1073 bfd_scan_arch PARAMS ((CONST char *string));
1074
1075 CONST bfd_arch_info_type *
1076 bfd_arch_get_compatible PARAMS ((
1077 CONST bfd *abfd,
1078 CONST bfd *bbfd));
1079
1080 void
1081 bfd_set_arch_info PARAMS ((bfd *abfd, bfd_arch_info_type *arg));
1082
1083 enum bfd_architecture
1084 bfd_get_arch PARAMS ((bfd *abfd));
1085
1086 unsigned long
1087 bfd_get_mach PARAMS ((bfd *abfd));
1088
1089 unsigned int
1090 bfd_arch_bits_per_byte PARAMS ((bfd *abfd));
1091
1092 unsigned int
1093 bfd_arch_bits_per_address PARAMS ((bfd *abfd));
1094
1095 bfd_arch_info_type *
1096 bfd_get_arch_info PARAMS ((bfd *abfd));
1097
1098 bfd_arch_info_type *
1099 bfd_lookup_arch
1100 PARAMS ((enum bfd_architecture
1101 arch,
1102 long machine));
1103
1104 CONST char *
1105 bfd_printable_arch_mach
1106 PARAMS ((enum bfd_architecture arch, unsigned long machine));
1107
1108 typedef enum bfd_reloc_status
1109 {
1110 /* No errors detected */
1111 bfd_reloc_ok,
1112
1113 /* The relocation was performed, but there was an overflow. */
1114 bfd_reloc_overflow,
1115
1116 /* The address to relocate was not within the section supplied. */
1117 bfd_reloc_outofrange,
1118
1119 /* Used by special functions */
1120 bfd_reloc_continue,
1121
1122 /* Unsupported relocation size requested. */
1123 bfd_reloc_notsupported,
1124
1125 /* Unused */
1126 bfd_reloc_other,
1127
1128 /* The symbol to relocate against was undefined. */
1129 bfd_reloc_undefined,
1130
1131 /* The relocation was performed, but may not be ok - presently
1132 generated only when linking i960 coff files with i960 b.out
1133 symbols. If this type is returned, the error_message argument
1134 to bfd_perform_relocation will be set. */
1135 bfd_reloc_dangerous
1136 }
1137 bfd_reloc_status_type;
1138
1139
1140 typedef struct reloc_cache_entry
1141 {
1142 /* A pointer into the canonical table of pointers */
1143 struct symbol_cache_entry **sym_ptr_ptr;
1144
1145 /* offset in section */
1146 bfd_size_type address;
1147
1148 /* addend for relocation value */
1149 bfd_vma addend;
1150
1151 /* Pointer to how to perform the required relocation */
1152 const struct reloc_howto_struct *howto;
1153
1154 } arelent;
1155 enum complain_overflow
1156 {
1157 /* Do not complain on overflow. */
1158 complain_overflow_dont,
1159
1160 /* Complain if the bitfield overflows, whether it is considered
1161 as signed or unsigned. */
1162 complain_overflow_bitfield,
1163
1164 /* Complain if the value overflows when considered as signed
1165 number. */
1166 complain_overflow_signed,
1167
1168 /* Complain if the value overflows when considered as an
1169 unsigned number. */
1170 complain_overflow_unsigned
1171 };
1172
1173 typedef unsigned char bfd_byte;
1174 typedef const struct reloc_howto_struct reloc_howto_type;
1175
1176 struct reloc_howto_struct
1177 {
1178 /* The type field has mainly a documetary use - the back end can
1179 do what it wants with it, though normally the back end's
1180 external idea of what a reloc number is stored
1181 in this field. For example, a PC relative word relocation
1182 in a coff environment has the type 023 - because that's
1183 what the outside world calls a R_PCRWORD reloc. */
1184 unsigned int type;
1185
1186 /* The value the final relocation is shifted right by. This drops
1187 unwanted data from the relocation. */
1188 unsigned int rightshift;
1189
1190 /* The size of the item to be relocated. This is *not* a
1191 power-of-two measure. To get the number of bytes operated
1192 on by a type of relocation, use bfd_get_reloc_size. */
1193 int size;
1194
1195 /* The number of bits in the item to be relocated. This is used
1196 when doing overflow checking. */
1197 unsigned int bitsize;
1198
1199 /* Notes that the relocation is relative to the location in the
1200 data section of the addend. The relocation function will
1201 subtract from the relocation value the address of the location
1202 being relocated. */
1203 boolean pc_relative;
1204
1205 /* The bit position of the reloc value in the destination.
1206 The relocated value is left shifted by this amount. */
1207 unsigned int bitpos;
1208
1209 /* What type of overflow error should be checked for when
1210 relocating. */
1211 enum complain_overflow complain_on_overflow;
1212
1213 /* If this field is non null, then the supplied function is
1214 called rather than the normal function. This allows really
1215 strange relocation methods to be accomodated (e.g., i960 callj
1216 instructions). */
1217 bfd_reloc_status_type (*special_function)
1218 PARAMS ((bfd *abfd,
1219 arelent *reloc_entry,
1220 struct symbol_cache_entry *symbol,
1221 PTR data,
1222 asection *input_section,
1223 bfd *output_bfd,
1224 char **error_message));
1225
1226 /* The textual name of the relocation type. */
1227 char *name;
1228
1229 /* When performing a partial link, some formats must modify the
1230 relocations rather than the data - this flag signals this.*/
1231 boolean partial_inplace;
1232
1233 /* The src_mask selects which parts of the read in data
1234 are to be used in the relocation sum. E.g., if this was an 8 bit
1235 bit of data which we read and relocated, this would be
1236 0x000000ff. When we have relocs which have an addend, such as
1237 sun4 extended relocs, the value in the offset part of a
1238 relocating field is garbage so we never use it. In this case
1239 the mask would be 0x00000000. */
1240 bfd_vma src_mask;
1241
1242 /* The dst_mask selects which parts of the instruction are replaced
1243 into the instruction. In most cases src_mask == dst_mask,
1244 except in the above special case, where dst_mask would be
1245 0x000000ff, and src_mask would be 0x00000000. */
1246 bfd_vma dst_mask;
1247
1248 /* When some formats create PC relative instructions, they leave
1249 the value of the pc of the place being relocated in the offset
1250 slot of the instruction, so that a PC relative relocation can
1251 be made just by adding in an ordinary offset (e.g., sun3 a.out).
1252 Some formats leave the displacement part of an instruction
1253 empty (e.g., m88k bcs); this flag signals the fact.*/
1254 boolean pcrel_offset;
1255
1256 };
1257 #define HOWTO(C, R,S,B, P, BI, O, SF, NAME, INPLACE, MASKSRC, MASKDST, PC) \
1258 {(unsigned)C,R,S,B, P, BI, O,SF,NAME,INPLACE,MASKSRC,MASKDST,PC}
1259 #define NEWHOWTO( FUNCTION, NAME,SIZE,REL,IN) HOWTO(0,0,SIZE,0,REL,0,complain_overflow_dont,FUNCTION, NAME,false,0,0,IN)
1260
1261 #define HOWTO_PREPARE(relocation, symbol) \
1262 { \
1263 if (symbol != (asymbol *)NULL) { \
1264 if (bfd_is_com_section (symbol->section)) { \
1265 relocation = 0; \
1266 } \
1267 else { \
1268 relocation = symbol->value; \
1269 } \
1270 } \
1271 }
1272 int
1273 bfd_get_reloc_size PARAMS ((reloc_howto_type *));
1274
1275 typedef struct relent_chain {
1276 arelent relent;
1277 struct relent_chain *next;
1278 } arelent_chain;
1279 bfd_reloc_status_type
1280
1281 bfd_perform_relocation
1282 PARAMS ((bfd *abfd,
1283 arelent *reloc_entry,
1284 PTR data,
1285 asection *input_section,
1286 bfd *output_bfd,
1287 char **error_message));
1288
1289 bfd_reloc_status_type
1290
1291 bfd_install_relocation
1292 PARAMS ((bfd *abfd,
1293 arelent *reloc_entry,
1294 PTR data, bfd_vma data_start,
1295 asection *input_section,
1296 char **error_message));
1297
1298 enum bfd_reloc_code_real {
1299 _dummy_first_bfd_reloc_code_real,
1300
1301
1302 /* Basic absolute relocations of N bits. */
1303 BFD_RELOC_64,
1304 BFD_RELOC_32,
1305 BFD_RELOC_26,
1306 BFD_RELOC_16,
1307 BFD_RELOC_14,
1308 BFD_RELOC_8,
1309
1310 /* PC-relative relocations. Sometimes these are relative to the address
1311 of the relocation itself; sometimes they are relative to the start of
1312 the section containing the relocation. It depends on the specific target.
1313
1314 The 24-bit relocation is used in some Intel 960 configurations. */
1315 BFD_RELOC_64_PCREL,
1316 BFD_RELOC_32_PCREL,
1317 BFD_RELOC_24_PCREL,
1318 BFD_RELOC_16_PCREL,
1319 BFD_RELOC_12_PCREL,
1320 BFD_RELOC_8_PCREL,
1321
1322 /* Linkage-table relative. */
1323 BFD_RELOC_32_BASEREL,
1324 BFD_RELOC_16_BASEREL,
1325 BFD_RELOC_8_BASEREL,
1326
1327 /* Absolute 8-bit relocation, but used to form an address like 0xFFnn. */
1328 BFD_RELOC_8_FFnn,
1329
1330 /* These PC-relative relocations are stored as word displacements --
1331 i.e., byte displacements shifted right two bits. The 30-bit word
1332 displacement (<<32_PCREL_S2>> -- 32 bits, shifted 2) is used on the
1333 SPARC. (SPARC tools generally refer to this as <<WDISP30>>.) The
1334 signed 16-bit displacement is used on the MIPS, and the 23-bit
1335 displacement is used on the Alpha. */
1336 BFD_RELOC_32_PCREL_S2,
1337 BFD_RELOC_16_PCREL_S2,
1338 BFD_RELOC_23_PCREL_S2,
1339
1340 /* High 22 bits and low 10 bits of 32-bit value, placed into lower bits of
1341 the target word. These are used on the SPARC. */
1342 BFD_RELOC_HI22,
1343 BFD_RELOC_LO10,
1344
1345 /* For systems that allocate a Global Pointer register, these are
1346 displacements off that register. These relocation types are
1347 handled specially, because the value the register will have is
1348 decided relatively late. */
1349 BFD_RELOC_GPREL16,
1350 BFD_RELOC_GPREL32,
1351
1352 /* Reloc types used for i960/b.out. */
1353 BFD_RELOC_I960_CALLJ,
1354
1355 /* SPARC ELF relocations. There is probably some overlap with other
1356 relocation types already defined. */
1357 BFD_RELOC_NONE,
1358 BFD_RELOC_SPARC_WDISP22,
1359 BFD_RELOC_SPARC22,
1360 BFD_RELOC_SPARC13,
1361 BFD_RELOC_SPARC_GOT10,
1362 BFD_RELOC_SPARC_GOT13,
1363 BFD_RELOC_SPARC_GOT22,
1364 BFD_RELOC_SPARC_PC10,
1365 BFD_RELOC_SPARC_PC22,
1366 BFD_RELOC_SPARC_WPLT30,
1367 BFD_RELOC_SPARC_COPY,
1368 BFD_RELOC_SPARC_GLOB_DAT,
1369 BFD_RELOC_SPARC_JMP_SLOT,
1370 BFD_RELOC_SPARC_RELATIVE,
1371 BFD_RELOC_SPARC_UA32,
1372
1373 /* I think these are specific to SPARC a.out (e.g., Sun 4). */
1374 BFD_RELOC_SPARC_BASE13,
1375 BFD_RELOC_SPARC_BASE22,
1376
1377 /* Some relocations we're using for SPARC V9 -- subject to change. */
1378 #define BFD_RELOC_SPARC_64 BFD_RELOC_64
1379 BFD_RELOC_SPARC_10,
1380 BFD_RELOC_SPARC_11,
1381 BFD_RELOC_SPARC_OLO10,
1382 BFD_RELOC_SPARC_HH22,
1383 BFD_RELOC_SPARC_HM10,
1384 BFD_RELOC_SPARC_LM22,
1385 BFD_RELOC_SPARC_PC_HH22,
1386 BFD_RELOC_SPARC_PC_HM10,
1387 BFD_RELOC_SPARC_PC_LM22,
1388 BFD_RELOC_SPARC_WDISP16,
1389 BFD_RELOC_SPARC_WDISP19,
1390 BFD_RELOC_SPARC_GLOB_JMP,
1391 BFD_RELOC_SPARC_LO7,
1392
1393 /* Alpha ECOFF relocations. Some of these treat the symbol or "addend"
1394 in some special way.
1395 For GPDISP_HI16 ("gpdisp") relocations, the symbol is ignored when
1396 writing; when reading, it will be the absolute section symbol. The
1397 addend is the displacement in bytes of the "lda" instruction from
1398 the "ldah" instruction (which is at the address of this reloc). */
1399 BFD_RELOC_ALPHA_GPDISP_HI16,
1400
1401 /* For GPDISP_LO16 ("ignore") relocations, the symbol is handled as
1402 with GPDISP_HI16 relocs. The addend is ignored when writing the
1403 relocations out, and is filled in with the file's GP value on
1404 reading, for convenience. */
1405 BFD_RELOC_ALPHA_GPDISP_LO16,
1406
1407 /* The Alpha LITERAL/LITUSE relocs are produced by a symbol reference;
1408 the assembler turns it into a LDQ instruction to load the address of
1409 the symbol, and then fills in a register in the real instruction.
1410
1411 The LITERAL reloc, at the LDQ instruction, refers to the .lita
1412 section symbol. The addend is ignored when writing, but is filled
1413 in with the file's GP value on reading, for convenience, as with the
1414 GPDISP_LO16 reloc.
1415
1416 The LITUSE reloc, on the instruction using the loaded address, gives
1417 information to the linker that it might be able to use to optimize
1418 away some literal section references. The symbol is ignored (read
1419 as the absolute section symbol), and the "addend" indicates the type
1420 of instruction using the register:
1421 1 - "memory" fmt insn
1422 2 - byte-manipulation (byte offset reg)
1423 3 - jsr (target of branch)
1424
1425 The GNU linker currently doesn't do any of this optimizing. */
1426 BFD_RELOC_ALPHA_LITERAL,
1427 BFD_RELOC_ALPHA_LITUSE,
1428
1429 /* The HINT relocation indicates a value that should be filled into the
1430 "hint" field of a jmp/jsr/ret instruction, for possible branch-
1431 prediction logic which may be provided on some processors. */
1432 BFD_RELOC_ALPHA_HINT,
1433
1434 /* Bits 27..2 of the relocation address shifted right 2 bits;
1435 simple reloc otherwise. */
1436 BFD_RELOC_MIPS_JMP,
1437
1438 /* High 16 bits of 32-bit value; simple reloc. */
1439 BFD_RELOC_HI16,
1440
1441 /* High 16 bits of 32-bit value but the low 16 bits will be sign
1442 extended and added to form the final result. If the low 16
1443 bits form a negative number, we need to add one to the high value
1444 to compensate for the borrow when the low bits are added. */
1445 BFD_RELOC_HI16_S,
1446
1447 /* Low 16 bits. */
1448 BFD_RELOC_LO16,
1449
1450 /* Like BFD_RELOC_HI16_S, but PC relative. */
1451 BFD_RELOC_PCREL_HI16_S,
1452
1453 /* Like BFD_RELOC_LO16, but PC relative. */
1454 BFD_RELOC_PCREL_LO16,
1455
1456 /* Relocation relative to the global pointer. */
1457 #define BFD_RELOC_MIPS_GPREL BFD_RELOC_GPREL16
1458
1459 /* Relocation against a MIPS literal section. */
1460 BFD_RELOC_MIPS_LITERAL,
1461
1462 /* MIPS ELF relocations. */
1463 BFD_RELOC_MIPS_GOT16,
1464 BFD_RELOC_MIPS_CALL16,
1465 #define BFD_RELOC_MIPS_GPREL32 BFD_RELOC_GPREL32
1466
1467 /* i386/elf relocations */
1468 BFD_RELOC_386_GOT32,
1469 BFD_RELOC_386_PLT32,
1470 BFD_RELOC_386_COPY,
1471 BFD_RELOC_386_GLOB_DAT,
1472 BFD_RELOC_386_JUMP_SLOT,
1473 BFD_RELOC_386_RELATIVE,
1474 BFD_RELOC_386_GOTOFF,
1475 BFD_RELOC_386_GOTPC,
1476
1477 /* ns32k relocations */
1478 BFD_RELOC_NS32K_IMM_8,
1479 BFD_RELOC_NS32K_IMM_16,
1480 BFD_RELOC_NS32K_IMM_32,
1481 BFD_RELOC_NS32K_IMM_8_PCREL,
1482 BFD_RELOC_NS32K_IMM_16_PCREL,
1483 BFD_RELOC_NS32K_IMM_32_PCREL,
1484 BFD_RELOC_NS32K_DISP_8,
1485 BFD_RELOC_NS32K_DISP_16,
1486 BFD_RELOC_NS32K_DISP_32,
1487 BFD_RELOC_NS32K_DISP_8_PCREL,
1488 BFD_RELOC_NS32K_DISP_16_PCREL,
1489 BFD_RELOC_NS32K_DISP_32_PCREL,
1490
1491 /* PowerPC/POWER (RS/6000) relocs.
1492 26 bit relative branch. Low two bits must be zero. High 24
1493 bits installed in bits 6 through 29 of instruction. */
1494 BFD_RELOC_PPC_B26,
1495
1496 /* 26 bit absolute branch, like BFD_RELOC_PPC_B26 but absolute. */
1497 BFD_RELOC_PPC_BA26,
1498
1499 /* 16 bit TOC relative reference. */
1500 BFD_RELOC_PPC_TOC16,
1501
1502 /* The type of reloc used to build a contructor table - at the moment
1503 probably a 32 bit wide absolute relocation, but the target can choose.
1504 It generally does map to one of the other relocation types. */
1505 BFD_RELOC_CTOR,
1506
1507 /* ARM 26 bit pc-relative branch. The lowest two bits must be zero and are
1508 not stored in the instruction. */
1509 BFD_RELOC_ARM_PCREL_BRANCH,
1510
1511 /* These relocs are only used within the ARM assembler. They are not
1512 (at present) written to any object files. */
1513 BFD_RELOC_ARM_IMMEDIATE,
1514 BFD_RELOC_ARM_OFFSET_IMM,
1515 BFD_RELOC_ARM_SHIFT_IMM,
1516 BFD_RELOC_ARM_SWI,
1517 BFD_RELOC_ARM_MULTI,
1518 BFD_RELOC_ARM_CP_OFF_IMM,
1519 /* start-sanitize-arc */
1520
1521 /* Argonaut RISC Core (ARC) relocs.
1522 ARC 22 bit pc-relative branch. The lowest two bits must be zero and are
1523 not stored in the instruction. High 20 bits installed in bits 7 through 26
1524 of instruction. */
1525 BFD_RELOC_ARC_B22_PCREL,
1526 /* end-sanitize-arc */
1527
1528 BFD_RELOC_UNUSED };
1529 typedef enum bfd_reloc_code_real bfd_reloc_code_real_type;
1530 const struct reloc_howto_struct *
1531
1532 bfd_reloc_type_lookup PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
1533
1534 const char *
1535 bfd_get_reloc_code_name PARAMS ((bfd_reloc_code_real_type code));
1536
1537
1538 typedef struct symbol_cache_entry
1539 {
1540 /* A pointer to the BFD which owns the symbol. This information
1541 is necessary so that a back end can work out what additional
1542 information (invisible to the application writer) is carried
1543 with the symbol.
1544
1545 This field is *almost* redundant, since you can use section->owner
1546 instead, except that some symbols point to the global sections
1547 bfd_{abs,com,und}_section. This could be fixed by making
1548 these globals be per-bfd (or per-target-flavor). FIXME. */
1549
1550 struct _bfd *the_bfd; /* Use bfd_asymbol_bfd(sym) to access this field. */
1551
1552 /* The text of the symbol. The name is left alone, and not copied; the
1553 application may not alter it. */
1554 CONST char *name;
1555
1556 /* The value of the symbol. This really should be a union of a
1557 numeric value with a pointer, since some flags indicate that
1558 a pointer to another symbol is stored here. */
1559 symvalue value;
1560
1561 /* Attributes of a symbol: */
1562
1563 #define BSF_NO_FLAGS 0x00
1564
1565 /* The symbol has local scope; <<static>> in <<C>>. The value
1566 is the offset into the section of the data. */
1567 #define BSF_LOCAL 0x01
1568
1569 /* The symbol has global scope; initialized data in <<C>>. The
1570 value is the offset into the section of the data. */
1571 #define BSF_GLOBAL 0x02
1572
1573 /* The symbol has global scope and is exported. The value is
1574 the offset into the section of the data. */
1575 #define BSF_EXPORT BSF_GLOBAL /* no real difference */
1576
1577 /* A normal C symbol would be one of:
1578 <<BSF_LOCAL>>, <<BSF_FORT_COMM>>, <<BSF_UNDEFINED>> or
1579 <<BSF_GLOBAL>> */
1580
1581 /* The symbol is a debugging record. The value has an arbitary
1582 meaning. */
1583 #define BSF_DEBUGGING 0x08
1584
1585 /* The symbol denotes a function entry point. Used in ELF,
1586 perhaps others someday. */
1587 #define BSF_FUNCTION 0x10
1588
1589 /* Used by the linker. */
1590 #define BSF_KEEP 0x20
1591 #define BSF_KEEP_G 0x40
1592
1593 /* A weak global symbol, overridable without warnings by
1594 a regular global symbol of the same name. */
1595 #define BSF_WEAK 0x80
1596
1597 /* This symbol was created to point to a section, e.g. ELF's
1598 STT_SECTION symbols. */
1599 #define BSF_SECTION_SYM 0x100
1600
1601 /* The symbol used to be a common symbol, but now it is
1602 allocated. */
1603 #define BSF_OLD_COMMON 0x200
1604
1605 /* The default value for common data. */
1606 #define BFD_FORT_COMM_DEFAULT_VALUE 0
1607
1608 /* In some files the type of a symbol sometimes alters its
1609 location in an output file - ie in coff a <<ISFCN>> symbol
1610 which is also <<C_EXT>> symbol appears where it was
1611 declared and not at the end of a section. This bit is set
1612 by the target BFD part to convey this information. */
1613
1614 #define BSF_NOT_AT_END 0x400
1615
1616 /* Signal that the symbol is the label of constructor section. */
1617 #define BSF_CONSTRUCTOR 0x800
1618
1619 /* Signal that the symbol is a warning symbol. If the symbol
1620 is a warning symbol, then the value field (I know this is
1621 tacky) will point to the asymbol which when referenced will
1622 cause the warning. */
1623 #define BSF_WARNING 0x1000
1624
1625 /* Signal that the symbol is indirect. The value of the symbol
1626 is a pointer to an undefined asymbol which contains the
1627 name to use instead. */
1628 #define BSF_INDIRECT 0x2000
1629
1630 /* BSF_FILE marks symbols that contain a file name. This is used
1631 for ELF STT_FILE symbols. */
1632 #define BSF_FILE 0x4000
1633
1634 /* Symbol is from dynamic linking information. */
1635 #define BSF_DYNAMIC 0x8000
1636
1637 flagword flags;
1638
1639 /* A pointer to the section to which this symbol is
1640 relative. This will always be non NULL, there are special
1641 sections for undefined and absolute symbols. */
1642 struct sec *section;
1643
1644 /* Back end special data. */
1645 union
1646 {
1647 PTR p;
1648 bfd_vma i;
1649 } udata;
1650
1651 } asymbol;
1652 #define bfd_get_symtab_upper_bound(abfd) \
1653 BFD_SEND (abfd, _bfd_get_symtab_upper_bound, (abfd))
1654 boolean
1655 bfd_is_local_label PARAMS ((bfd *abfd, asymbol *sym));
1656
1657 #define bfd_is_local_label(abfd, sym) \
1658 BFD_SEND (abfd, _bfd_is_local_label,(abfd, sym))
1659 #define bfd_canonicalize_symtab(abfd, location) \
1660 BFD_SEND (abfd, _bfd_canonicalize_symtab,\
1661 (abfd, location))
1662 boolean
1663 bfd_set_symtab PARAMS ((bfd *abfd, asymbol **location, unsigned int count));
1664
1665 void
1666 bfd_print_symbol_vandf PARAMS ((PTR file, asymbol *symbol));
1667
1668 #define bfd_make_empty_symbol(abfd) \
1669 BFD_SEND (abfd, _bfd_make_empty_symbol, (abfd))
1670 #define bfd_make_debug_symbol(abfd,ptr,size) \
1671 BFD_SEND (abfd, _bfd_make_debug_symbol, (abfd, ptr, size))
1672 int
1673 bfd_decode_symclass PARAMS ((asymbol *symbol));
1674
1675 void
1676 bfd_symbol_info PARAMS ((asymbol *symbol, symbol_info *ret));
1677
1678 struct _bfd
1679 {
1680 /* The filename the application opened the BFD with. */
1681 CONST char *filename;
1682
1683 /* A pointer to the target jump table. */
1684 const struct bfd_target *xvec;
1685
1686 /* To avoid dragging too many header files into every file that
1687 includes `<<bfd.h>>', IOSTREAM has been declared as a "char
1688 *", and MTIME as a "long". Their correct types, to which they
1689 are cast when used, are "FILE *" and "time_t". The iostream
1690 is the result of an fopen on the filename. */
1691 char *iostream;
1692
1693 /* Is the file descriptor being cached? That is, can it be closed as
1694 needed, and re-opened when accessed later? */
1695
1696 boolean cacheable;
1697
1698 /* Marks whether there was a default target specified when the
1699 BFD was opened. This is used to select which matching algorithm
1700 to use to choose the back end. */
1701
1702 boolean target_defaulted;
1703
1704 /* The caching routines use these to maintain a
1705 least-recently-used list of BFDs */
1706
1707 struct _bfd *lru_prev, *lru_next;
1708
1709 /* When a file is closed by the caching routines, BFD retains
1710 state information on the file here: */
1711
1712 file_ptr where;
1713
1714 /* and here: (``once'' means at least once) */
1715
1716 boolean opened_once;
1717
1718 /* Set if we have a locally maintained mtime value, rather than
1719 getting it from the file each time: */
1720
1721 boolean mtime_set;
1722
1723 /* File modified time, if mtime_set is true: */
1724
1725 long mtime;
1726
1727 /* Reserved for an unimplemented file locking extension.*/
1728
1729 int ifd;
1730
1731 /* The format which belongs to the BFD. (object, core, etc.) */
1732
1733 bfd_format format;
1734
1735 /* The direction the BFD was opened with*/
1736
1737 enum bfd_direction {no_direction = 0,
1738 read_direction = 1,
1739 write_direction = 2,
1740 both_direction = 3} direction;
1741
1742 /* Format_specific flags*/
1743
1744 flagword flags;
1745
1746 /* Currently my_archive is tested before adding origin to
1747 anything. I believe that this can become always an add of
1748 origin, with origin set to 0 for non archive files. */
1749
1750 file_ptr origin;
1751
1752 /* Remember when output has begun, to stop strange things
1753 from happening. */
1754 boolean output_has_begun;
1755
1756 /* Pointer to linked list of sections*/
1757 struct sec *sections;
1758
1759 /* The number of sections */
1760 unsigned int section_count;
1761
1762 /* Stuff only useful for object files:
1763 The start address. */
1764 bfd_vma start_address;
1765
1766 /* Used for input and output*/
1767 unsigned int symcount;
1768
1769 /* Symbol table for output BFD (with symcount entries) */
1770 struct symbol_cache_entry **outsymbols;
1771
1772 /* Pointer to structure which contains architecture information*/
1773 struct bfd_arch_info *arch_info;
1774
1775 /* Stuff only useful for archives:*/
1776 PTR arelt_data;
1777 struct _bfd *my_archive; /* The containing archive BFD. */
1778 struct _bfd *next; /* The next BFD in the archive. */
1779 struct _bfd *archive_head; /* The first BFD in the archive. */
1780 boolean has_armap;
1781
1782 /* A chain of BFD structures involved in a link. */
1783 struct _bfd *link_next;
1784
1785 /* A field used by _bfd_generic_link_add_archive_symbols. This will
1786 be used only for archive elements. */
1787 int archive_pass;
1788
1789 /* Used by the back end to hold private data. */
1790
1791 union
1792 {
1793 struct aout_data_struct *aout_data;
1794 struct artdata *aout_ar_data;
1795 struct _oasys_data *oasys_obj_data;
1796 struct _oasys_ar_data *oasys_ar_data;
1797 struct coff_tdata *coff_obj_data;
1798 struct ecoff_tdata *ecoff_obj_data;
1799 struct ieee_data_struct *ieee_data;
1800 struct ieee_ar_data_struct *ieee_ar_data;
1801 struct srec_data_struct *srec_data;
1802 struct tekhex_data_struct *tekhex_data;
1803 struct elf_obj_tdata *elf_obj_data;
1804 struct nlm_obj_tdata *nlm_obj_data;
1805 struct bout_data_struct *bout_data;
1806 struct sun_core_struct *sun_core_data;
1807 struct trad_core_struct *trad_core_data;
1808 struct som_data_struct *som_data;
1809 struct hpux_core_struct *hpux_core_data;
1810 struct hppabsd_core_struct *hppabsd_core_data;
1811 struct sgi_core_struct *sgi_core_data;
1812 struct lynx_core_struct *lynx_core_data;
1813 struct osf_core_struct *osf_core_data;
1814 struct cisco_core_struct *cisco_core_data;
1815 PTR any;
1816 } tdata;
1817
1818 /* Used by the application to hold private data*/
1819 PTR usrdata;
1820
1821 /* Where all the allocated stuff under this BFD goes */
1822 struct obstack memory;
1823 };
1824
1825 typedef enum bfd_error
1826 {
1827 bfd_error_no_error = 0,
1828 bfd_error_system_call,
1829 bfd_error_invalid_target,
1830 bfd_error_wrong_format,
1831 bfd_error_invalid_operation,
1832 bfd_error_no_memory,
1833 bfd_error_no_symbols,
1834 bfd_error_no_more_archived_files,
1835 bfd_error_malformed_archive,
1836 bfd_error_file_not_recognized,
1837 bfd_error_file_ambiguously_recognized,
1838 bfd_error_no_contents,
1839 bfd_error_nonrepresentable_section,
1840 bfd_error_no_debug_section,
1841 bfd_error_bad_value,
1842 bfd_error_file_truncated,
1843 bfd_error_invalid_error_code
1844 } bfd_error_type;
1845
1846 bfd_error_type
1847 bfd_get_error PARAMS ((void));
1848
1849 void
1850 bfd_set_error PARAMS ((bfd_error_type error_tag));
1851
1852 CONST char *
1853 bfd_errmsg PARAMS ((bfd_error_type error_tag));
1854
1855 void
1856 bfd_perror PARAMS ((CONST char *message));
1857
1858 long
1859 bfd_get_reloc_upper_bound PARAMS ((bfd *abfd, asection *sect));
1860
1861 long
1862 bfd_canonicalize_reloc
1863 PARAMS ((bfd *abfd,
1864 asection *sec,
1865 arelent **loc,
1866 asymbol **syms));
1867
1868 void
1869 bfd_set_reloc
1870 PARAMS ((bfd *abfd, asection *sec, arelent **rel, unsigned int count)
1871
1872 );
1873
1874 boolean
1875 bfd_set_file_flags PARAMS ((bfd *abfd, flagword flags));
1876
1877 boolean
1878 bfd_set_start_address PARAMS ((bfd *abfd, bfd_vma vma));
1879
1880 long
1881 bfd_get_mtime PARAMS ((bfd *abfd));
1882
1883 long
1884 bfd_get_size PARAMS ((bfd *abfd));
1885
1886 int
1887 bfd_get_gp_size PARAMS ((bfd *abfd));
1888
1889 void
1890 bfd_set_gp_size PARAMS ((bfd *abfd, int i));
1891
1892 bfd_vma
1893 bfd_scan_vma PARAMS ((CONST char *string, CONST char **end, int base));
1894
1895 boolean
1896 bfd_copy_private_bfd_data PARAMS ((bfd *ibfd, bfd *obfd));
1897
1898 #define bfd_copy_private_bfd_data(ibfd, obfd) \
1899 BFD_SEND (ibfd, _bfd_copy_private_bfd_data, \
1900 (ibfd, obfd))
1901 #define bfd_sizeof_headers(abfd, reloc) \
1902 BFD_SEND (abfd, _bfd_sizeof_headers, (abfd, reloc))
1903
1904 #define bfd_find_nearest_line(abfd, sec, syms, off, file, func, line) \
1905 BFD_SEND (abfd, _bfd_find_nearest_line, (abfd, sec, syms, off, file, func, line))
1906
1907 /* Do these three do anything useful at all, for any back end? */
1908 #define bfd_debug_info_start(abfd) \
1909 BFD_SEND (abfd, _bfd_debug_info_start, (abfd))
1910
1911 #define bfd_debug_info_end(abfd) \
1912 BFD_SEND (abfd, _bfd_debug_info_end, (abfd))
1913
1914 #define bfd_debug_info_accumulate(abfd, section) \
1915 BFD_SEND (abfd, _bfd_debug_info_accumulate, (abfd, section))
1916
1917
1918 #define bfd_stat_arch_elt(abfd, stat) \
1919 BFD_SEND (abfd, _bfd_stat_arch_elt,(abfd, stat))
1920
1921 #define bfd_update_armap_timestamp(abfd) \
1922 BFD_SEND (abfd, _bfd_update_armap_timestamp, (abfd))
1923
1924 #define bfd_set_arch_mach(abfd, arch, mach)\
1925 BFD_SEND ( abfd, _bfd_set_arch_mach, (abfd, arch, mach))
1926
1927 #define bfd_get_relocated_section_contents(abfd, link_info, link_order, data, relocateable, symbols) \
1928 BFD_SEND (abfd, _bfd_get_relocated_section_contents, \
1929 (abfd, link_info, link_order, data, relocateable, symbols))
1930
1931 #define bfd_relax_section(abfd, section, link_info, again) \
1932 BFD_SEND (abfd, _bfd_relax_section, (abfd, section, link_info, again))
1933
1934 #define bfd_link_hash_table_create(abfd) \
1935 BFD_SEND (abfd, _bfd_link_hash_table_create, (abfd))
1936
1937 #define bfd_link_add_symbols(abfd, info) \
1938 BFD_SEND (abfd, _bfd_link_add_symbols, (abfd, info))
1939
1940 #define bfd_final_link(abfd, info) \
1941 BFD_SEND (abfd, _bfd_final_link, (abfd, info))
1942
1943 #define bfd_free_cached_info(abfd) \
1944 BFD_SEND (abfd, _bfd_free_cached_info, (abfd))
1945
1946 #define bfd_get_dynamic_symtab_upper_bound(abfd) \
1947 BFD_SEND (abfd, _bfd_get_dynamic_symtab_upper_bound, (abfd))
1948
1949 #define bfd_canonicalize_dynamic_symtab(abfd, asymbols) \
1950 BFD_SEND (abfd, _bfd_canonicalize_dynamic_symtab, (abfd, asymbols))
1951
1952 #define bfd_get_dynamic_reloc_upper_bound(abfd) \
1953 BFD_SEND (abfd, _bfd_get_dynamic_reloc_upper_bound, (abfd))
1954
1955 #define bfd_canonicalize_dynamic_reloc(abfd, arels, asyms) \
1956 BFD_SEND (abfd, _bfd_canonicalize_dynamic_reloc, (abfd, arels, asyms))
1957
1958 symindex
1959 bfd_get_next_mapent PARAMS ((bfd *abfd, symindex previous, carsym **sym));
1960
1961 boolean
1962 bfd_set_archive_head PARAMS ((bfd *output, bfd *new_head));
1963
1964 bfd *
1965 bfd_get_elt_at_index PARAMS ((bfd *archive, int index));
1966
1967 bfd *
1968 bfd_openr_next_archived_file PARAMS ((bfd *archive, bfd *previous));
1969
1970 CONST char *
1971 bfd_core_file_failing_command PARAMS ((bfd *abfd));
1972
1973 int
1974 bfd_core_file_failing_signal PARAMS ((bfd *abfd));
1975
1976 boolean
1977 core_file_matches_executable_p
1978 PARAMS ((bfd *core_bfd, bfd *exec_bfd));
1979
1980 #define BFD_SEND(bfd, message, arglist) \
1981 ((*((bfd)->xvec->message)) arglist)
1982
1983 #ifdef DEBUG_BFD_SEND
1984 #undef BFD_SEND
1985 #define BFD_SEND(bfd, message, arglist) \
1986 (((bfd) && (bfd)->xvec && (bfd)->xvec->message) ? \
1987 ((*((bfd)->xvec->message)) arglist) : \
1988 (bfd_assert (__FILE__,__LINE__), NULL))
1989 #endif
1990 #define BFD_SEND_FMT(bfd, message, arglist) \
1991 (((bfd)->xvec->message[(int)((bfd)->format)]) arglist)
1992
1993 #ifdef DEBUG_BFD_SEND
1994 #undef BFD_SEND_FMT
1995 #define BFD_SEND_FMT(bfd, message, arglist) \
1996 (((bfd) && (bfd)->xvec && (bfd)->xvec->message) ? \
1997 (((bfd)->xvec->message[(int)((bfd)->format)]) arglist) : \
1998 (bfd_assert (__FILE__,__LINE__), NULL))
1999 #endif
2000 enum bfd_flavour {
2001 bfd_target_unknown_flavour,
2002 bfd_target_aout_flavour,
2003 bfd_target_coff_flavour,
2004 bfd_target_ecoff_flavour,
2005 bfd_target_elf_flavour,
2006 bfd_target_ieee_flavour,
2007 bfd_target_nlm_flavour,
2008 bfd_target_oasys_flavour,
2009 bfd_target_tekhex_flavour,
2010 bfd_target_srec_flavour,
2011 bfd_target_som_flavour,
2012 bfd_target_os9k_flavour};
2013
2014 /* Forward declaration. */
2015 typedef struct bfd_link_info _bfd_link_info;
2016
2017 typedef struct bfd_target
2018 {
2019 char *name;
2020 enum bfd_flavour flavour;
2021 boolean byteorder_big_p;
2022 boolean header_byteorder_big_p;
2023 flagword object_flags;
2024 flagword section_flags;
2025 char symbol_leading_char;
2026 char ar_pad_char;
2027 unsigned short ar_max_namelen;
2028 unsigned int align_power_min;
2029 bfd_vma (*bfd_getx64) PARAMS ((const bfd_byte *));
2030 bfd_signed_vma (*bfd_getx_signed_64) PARAMS ((const bfd_byte *));
2031 void (*bfd_putx64) PARAMS ((bfd_vma, bfd_byte *));
2032 bfd_vma (*bfd_getx32) PARAMS ((const bfd_byte *));
2033 bfd_signed_vma (*bfd_getx_signed_32) PARAMS ((const bfd_byte *));
2034 void (*bfd_putx32) PARAMS ((bfd_vma, bfd_byte *));
2035 bfd_vma (*bfd_getx16) PARAMS ((const bfd_byte *));
2036 bfd_signed_vma (*bfd_getx_signed_16) PARAMS ((const bfd_byte *));
2037 void (*bfd_putx16) PARAMS ((bfd_vma, bfd_byte *));
2038 bfd_vma (*bfd_h_getx64) PARAMS ((const bfd_byte *));
2039 bfd_signed_vma (*bfd_h_getx_signed_64) PARAMS ((const bfd_byte *));
2040 void (*bfd_h_putx64) PARAMS ((bfd_vma, bfd_byte *));
2041 bfd_vma (*bfd_h_getx32) PARAMS ((const bfd_byte *));
2042 bfd_signed_vma (*bfd_h_getx_signed_32) PARAMS ((const bfd_byte *));
2043 void (*bfd_h_putx32) PARAMS ((bfd_vma, bfd_byte *));
2044 bfd_vma (*bfd_h_getx16) PARAMS ((const bfd_byte *));
2045 bfd_signed_vma (*bfd_h_getx_signed_16) PARAMS ((const bfd_byte *));
2046 void (*bfd_h_putx16) PARAMS ((bfd_vma, bfd_byte *));
2047 const struct bfd_target *(*_bfd_check_format[bfd_type_end]) PARAMS ((bfd *));
2048 boolean (*_bfd_set_format[bfd_type_end]) PARAMS ((bfd *));
2049 boolean (*_bfd_write_contents[bfd_type_end]) PARAMS ((bfd *));
2050
2051 /* Generic entry points. */
2052 #define BFD_JUMP_TABLE_GENERIC(NAME)\
2053 CAT(NAME,_close_and_cleanup),\
2054 CAT(NAME,_bfd_free_cached_info),\
2055 CAT(NAME,_new_section_hook),\
2056 CAT(NAME,_get_section_contents)
2057 /* Called when the BFD is being closed to do any necessary cleanup. */
2058 boolean (*_close_and_cleanup) PARAMS ((bfd *));
2059 /* Ask the BFD to free all cached information. */
2060 boolean (*_bfd_free_cached_info) PARAMS ((bfd *));
2061 /* Called when a new section is created. */
2062 boolean (*_new_section_hook) PARAMS ((bfd *, sec_ptr));
2063 /* Read the contents of a section. */
2064 boolean (*_bfd_get_section_contents) PARAMS ((bfd *, sec_ptr, PTR,
2065 file_ptr, bfd_size_type));
2066
2067 /* Entry points to copy private data. */
2068 #define BFD_JUMP_TABLE_COPY(NAME)\
2069 CAT(NAME,_bfd_copy_private_bfd_data),\
2070 CAT(NAME,_bfd_copy_private_section_data)
2071 /* Called to copy BFD general private data from one object file
2072 to another. */
2073 boolean (*_bfd_copy_private_bfd_data) PARAMS ((bfd *, bfd *));
2074 /* Called to copy BFD private section data from one object file
2075 to another. */
2076 boolean (*_bfd_copy_private_section_data) PARAMS ((bfd *, sec_ptr,
2077 bfd *, sec_ptr));
2078
2079 /* Core file entry points. */
2080 #define BFD_JUMP_TABLE_CORE(NAME)\
2081 CAT(NAME,_core_file_failing_command),\
2082 CAT(NAME,_core_file_failing_signal),\
2083 CAT(NAME,_core_file_matches_executable_p)
2084 char * (*_core_file_failing_command) PARAMS ((bfd *));
2085 int (*_core_file_failing_signal) PARAMS ((bfd *));
2086 boolean (*_core_file_matches_executable_p) PARAMS ((bfd *, bfd *));
2087
2088 /* Archive entry points. */
2089 #define BFD_JUMP_TABLE_ARCHIVE(NAME)\
2090 CAT(NAME,_slurp_armap),\
2091 CAT(NAME,_slurp_extended_name_table),\
2092 CAT(NAME,_construct_extended_name_table),\
2093 CAT(NAME,_truncate_arname),\
2094 CAT(NAME,_write_armap),\
2095 CAT(NAME,_openr_next_archived_file),\
2096 CAT(NAME,_generic_stat_arch_elt),\
2097 CAT(NAME,_update_armap_timestamp)
2098 boolean (*_bfd_slurp_armap) PARAMS ((bfd *));
2099 boolean (*_bfd_slurp_extended_name_table) PARAMS ((bfd *));
2100 boolean (*_bfd_construct_extended_name_table)
2101 PARAMS ((bfd *, char **, bfd_size_type *, const char **));
2102 void (*_bfd_truncate_arname) PARAMS ((bfd *, CONST char *, char *));
2103 boolean (*write_armap) PARAMS ((bfd *arch,
2104 unsigned int elength,
2105 struct orl *map,
2106 unsigned int orl_count,
2107 int stridx));
2108 bfd * (*openr_next_archived_file) PARAMS ((bfd *arch, bfd *prev));
2109 int (*_bfd_stat_arch_elt) PARAMS ((bfd *, struct stat *));
2110 boolean (*_bfd_update_armap_timestamp) PARAMS ((bfd *));
2111
2112 /* Entry points used for symbols. */
2113 #define BFD_JUMP_TABLE_SYMBOLS(NAME)\
2114 CAT(NAME,_get_symtab_upper_bound),\
2115 CAT(NAME,_get_symtab),\
2116 CAT(NAME,_make_empty_symbol),\
2117 CAT(NAME,_print_symbol),\
2118 CAT(NAME,_get_symbol_info),\
2119 CAT(NAME,_bfd_is_local_label),\
2120 CAT(NAME,_get_lineno),\
2121 CAT(NAME,_find_nearest_line),\
2122 CAT(NAME,_bfd_make_debug_symbol)
2123 long (*_bfd_get_symtab_upper_bound) PARAMS ((bfd *));
2124 long (*_bfd_canonicalize_symtab) PARAMS ((bfd *,
2125 struct symbol_cache_entry **));
2126 struct symbol_cache_entry *
2127 (*_bfd_make_empty_symbol) PARAMS ((bfd *));
2128 void (*_bfd_print_symbol) PARAMS ((bfd *, PTR,
2129 struct symbol_cache_entry *,
2130 bfd_print_symbol_type));
2131 #define bfd_print_symbol(b,p,s,e) BFD_SEND(b, _bfd_print_symbol, (b,p,s,e))
2132 void (*_bfd_get_symbol_info) PARAMS ((bfd *,
2133 struct symbol_cache_entry *,
2134 symbol_info *));
2135 #define bfd_get_symbol_info(b,p,e) BFD_SEND(b, _bfd_get_symbol_info, (b,p,e))
2136 boolean (*_bfd_is_local_label) PARAMS ((bfd *, asymbol *));
2137
2138 alent * (*_get_lineno) PARAMS ((bfd *, struct symbol_cache_entry *));
2139 boolean (*_bfd_find_nearest_line) PARAMS ((bfd *abfd,
2140 struct sec *section, struct symbol_cache_entry **symbols,
2141 bfd_vma offset, CONST char **file, CONST char **func,
2142 unsigned int *line));
2143 /* Back-door to allow format-aware applications to create debug symbols
2144 while using BFD for everything else. Currently used by the assembler
2145 when creating COFF files. */
2146 asymbol * (*_bfd_make_debug_symbol) PARAMS ((
2147 bfd *abfd,
2148 void *ptr,
2149 unsigned long size));
2150
2151 /* Routines for relocs. */
2152 #define BFD_JUMP_TABLE_RELOCS(NAME)\
2153 CAT(NAME,_get_reloc_upper_bound),\
2154 CAT(NAME,_canonicalize_reloc),\
2155 CAT(NAME,_bfd_reloc_type_lookup)
2156 long (*_get_reloc_upper_bound) PARAMS ((bfd *, sec_ptr));
2157 long (*_bfd_canonicalize_reloc) PARAMS ((bfd *, sec_ptr, arelent **,
2158 struct symbol_cache_entry **));
2159 /* See documentation on reloc types. */
2160 CONST struct reloc_howto_struct *
2161 (*reloc_type_lookup) PARAMS ((bfd *abfd,
2162 bfd_reloc_code_real_type code));
2163
2164 /* Routines used when writing an object file. */
2165 #define BFD_JUMP_TABLE_WRITE(NAME)\
2166 CAT(NAME,_set_arch_mach),\
2167 CAT(NAME,_set_section_contents)
2168 boolean (*_bfd_set_arch_mach) PARAMS ((bfd *, enum bfd_architecture,
2169 unsigned long));
2170 boolean (*_bfd_set_section_contents) PARAMS ((bfd *, sec_ptr, PTR,
2171 file_ptr, bfd_size_type));
2172
2173 /* Routines used by the linker. */
2174 #define BFD_JUMP_TABLE_LINK(NAME)\
2175 CAT(NAME,_sizeof_headers),\
2176 CAT(NAME,_bfd_get_relocated_section_contents),\
2177 CAT(NAME,_bfd_relax_section),\
2178 CAT(NAME,_bfd_link_hash_table_create),\
2179 CAT(NAME,_bfd_link_add_symbols),\
2180 CAT(NAME,_bfd_final_link)
2181 int (*_bfd_sizeof_headers) PARAMS ((bfd *, boolean));
2182 bfd_byte * (*_bfd_get_relocated_section_contents) PARAMS ((bfd *,
2183 struct bfd_link_info *, struct bfd_link_order *,
2184 bfd_byte *data, boolean relocateable,
2185 struct symbol_cache_entry **));
2186
2187 boolean (*_bfd_relax_section) PARAMS ((bfd *, struct sec *,
2188 struct bfd_link_info *, boolean *again));
2189
2190 /* Create a hash table for the linker. Different backends store
2191 different information in this table. */
2192 struct bfd_link_hash_table *(*_bfd_link_hash_table_create) PARAMS ((bfd *));
2193
2194 /* Add symbols from this object file into the hash table. */
2195 boolean (*_bfd_link_add_symbols) PARAMS ((bfd *, struct bfd_link_info *));
2196
2197 /* Do a link based on the link_order structures attached to each
2198 section of the BFD. */
2199 boolean (*_bfd_final_link) PARAMS ((bfd *, struct bfd_link_info *));
2200
2201 /* Routines to handle dynamic symbols and relocs. */
2202 #define BFD_JUMP_TABLE_DYNAMIC(NAME)\
2203 CAT(NAME,_get_dynamic_symtab_upper_bound),\
2204 CAT(NAME,_canonicalize_dynamic_symtab),\
2205 CAT(NAME,_get_dynamic_reloc_upper_bound),\
2206 CAT(NAME,_canonicalize_dynamic_reloc)
2207 /* Get the amount of memory required to hold the dynamic symbols. */
2208 long (*_bfd_get_dynamic_symtab_upper_bound) PARAMS ((bfd *));
2209 /* Read in the dynamic symbols. */
2210 long (*_bfd_canonicalize_dynamic_symtab)
2211 PARAMS ((bfd *, struct symbol_cache_entry **));
2212 /* Get the amount of memory required to hold the dynamic relocs. */
2213 long (*_bfd_get_dynamic_reloc_upper_bound) PARAMS ((bfd *));
2214 /* Read in the dynamic relocs. */
2215 long (*_bfd_canonicalize_dynamic_reloc)
2216 PARAMS ((bfd *, arelent **, struct symbol_cache_entry **));
2217
2218 PTR backend_data;
2219 } bfd_target;
2220 const bfd_target *
2221 bfd_find_target PARAMS ((CONST char *target_name, bfd *abfd));
2222
2223 const char **
2224 bfd_target_list PARAMS ((void));
2225
2226 boolean
2227 bfd_check_format PARAMS ((bfd *abfd, bfd_format format));
2228
2229 boolean
2230 bfd_check_format_matches PARAMS ((bfd *abfd, bfd_format format, char ***matching));
2231
2232 boolean
2233 bfd_set_format PARAMS ((bfd *abfd, bfd_format format));
2234
2235 CONST char *
2236 bfd_format_string PARAMS ((bfd_format format));
2237
2238 #endif