* xcofflink.c: Extensive changes to support linking shared objects
[external/binutils.git] / bfd / libcoff-in.h
1 /* BFD COFF object file private structure.
2    Copyright (C) 1990, 91, 92, 93, 94, 1995 Free Software Foundation, Inc.
3    Written by Cygnus Support.
4
5 This file is part of BFD, the Binary File Descriptor library.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
20
21 #include "bfdlink.h"
22
23 /* Object file tdata; access macros */
24
25 #define coff_data(bfd)          ((bfd)->tdata.coff_obj_data)
26 #define exec_hdr(bfd)           (coff_data(bfd)->hdr)
27 #define obj_pe(bfd)             (coff_data(bfd)->pe)
28 #define obj_symbols(bfd)        (coff_data(bfd)->symbols)
29 #define obj_sym_filepos(bfd)    (coff_data(bfd)->sym_filepos)
30
31 #define obj_relocbase(bfd)      (coff_data(bfd)->relocbase)
32 #define obj_raw_syments(bfd)    (coff_data(bfd)->raw_syments)
33 #define obj_raw_syment_count(bfd)       (coff_data(bfd)->raw_syment_count)
34 #define obj_convert(bfd)        (coff_data(bfd)->conversion_table)
35 #define obj_conv_table_size(bfd) (coff_data(bfd)->conv_table_size)
36
37 #define obj_coff_external_syms(bfd) (coff_data (bfd)->external_syms)
38 #define obj_coff_keep_syms(bfd) (coff_data (bfd)->keep_syms)
39 #define obj_coff_strings(bfd)   (coff_data (bfd)->strings)
40 #define obj_coff_keep_strings(bfd) (coff_data (bfd)->keep_strings)
41 #define obj_coff_sym_hashes(bfd) (coff_data (bfd)->sym_hashes)
42
43 /* `Tdata' information kept for COFF files.  */
44
45 typedef struct coff_tdata
46 {
47   struct   coff_symbol_struct *symbols; /* symtab for input bfd */
48   unsigned int *conversion_table;
49   int conv_table_size;
50   file_ptr sym_filepos;
51
52   struct coff_ptr_struct *raw_syments;
53   unsigned int raw_syment_count;
54
55   /* These are only valid once writing has begun */
56   long int relocbase;
57
58   /* These members communicate important constants about the symbol table
59      to GDB's symbol-reading code.  These `constants' unfortunately vary
60      from coff implementation to implementation...  */
61   unsigned local_n_btmask;
62   unsigned local_n_btshft;
63   unsigned local_n_tmask;
64   unsigned local_n_tshift;
65   unsigned local_symesz;
66   unsigned local_auxesz;
67   unsigned local_linesz;
68
69   /* The unswapped external symbols.  May be NULL.  Read by
70      _bfd_coff_get_external_symbols.  */
71   PTR external_syms;
72   /* If this is true, the external_syms may not be freed.  */
73   boolean keep_syms;
74
75   /* The string table.  May be NULL.  Read by
76      _bfd_coff_read_string_table.  */
77   char *strings;
78   /* If this is true, the strings may not be freed.  */
79   boolean keep_strings;
80
81   /* is this a PE format coff file */
82   int pe;
83   /* Used by the COFF backend linker.  */
84   struct coff_link_hash_entry **sym_hashes;
85
86   struct bfd_link_info *link_info;
87 } coff_data_type;
88
89 /* Tdata for pe image files. */
90 typedef struct pe_tdata
91 {
92   coff_data_type coff;
93   struct internal_extra_pe_aouthdr pe_opthdr;
94   int dll;
95   int has_reloc_section;
96   boolean (*in_reloc_p) PARAMS((bfd *, reloc_howto_type *));
97 } pe_data_type;
98
99 #define pe_data(bfd)            ((bfd)->tdata.pe_obj_data)
100
101 /* Tdata for XCOFF files.  */
102
103 struct xcoff_tdata
104 {
105   /* Basic COFF information.  */
106   coff_data_type coff;
107
108   /* TOC value.  */
109   bfd_vma toc;
110
111   /* .text alignment from optional header.  */
112   int text_align_power;
113
114   /* .data alignment from optional header.  */
115   int data_align_power;
116
117   /* modtype from optional header.  */
118   short modtype;
119
120   /* cputype from optional header.  */
121   short cputype;
122
123   /* maxdata from optional header.  */
124   bfd_size_type maxdata;
125
126   /* maxstack from optional header.  */
127   bfd_size_type maxstack;
128
129   /* Used by the XCOFF backend linker.  */
130   asection **csects;
131   unsigned long *debug_indices;
132   unsigned int import_file_id;
133 };
134
135 #define xcoff_data(abfd) ((abfd)->tdata.xcoff_obj_data)
136
137 /* We take the address of the first element of a asymbol to ensure that the
138  * macro is only ever applied to an asymbol.  */
139 #define coffsymbol(asymbol) ((coff_symbol_type *)(&((asymbol)->the_bfd)))
140
141 /* The used_by_bfd field of a section may be set to a pointer to this
142    structure.  */
143
144 struct coff_section_tdata
145 {
146   /* The relocs, swapped into COFF internal form.  This may be NULL.  */
147   struct internal_reloc *relocs;
148   /* If this is true, the relocs entry may not be freed.  */
149   boolean keep_relocs;
150   /* The section contents.  This may be NULL.  */
151   bfd_byte *contents;
152   /* If this is true, the contents entry may not be freed.  */
153   boolean keep_contents;
154   /* Information cached by coff_find_nearest_line.  */
155   bfd_vma offset;
156   unsigned int i;
157   const char *function;
158   int line_base;
159   /* Available for individual backends.  */
160   PTR tdata;
161 };
162
163 /* An accessor macro for the coff_section_tdata structure.  */
164 #define coff_section_data(abfd, sec) \
165   ((struct coff_section_tdata *) (sec)->used_by_bfd)
166
167 /* Tdata for sections in XCOFF files.  This is used by the linker.  */
168
169 struct xcoff_section_tdata
170 {
171   /* Used for XCOFF csects created by the linker; points to the real
172      XCOFF section which contains this csect.  */
173   asection *enclosing;
174   /* The first and one past the last symbol indices for symbols used
175      by this csect.  */
176   unsigned long first_symndx;
177   unsigned long last_symndx;
178   /* The number of .loader relocs in this csect.  */
179   size_t ldrel_count;
180 };
181
182 /* An accessor macro the xcoff_section_tdata structure.  */
183 #define xcoff_section_data(abfd, sec) \
184   ((struct xcoff_section_tdata *) coff_section_data ((abfd), (sec))->tdata)
185
186 /* COFF linker hash table entries.  */
187
188 struct coff_link_hash_entry
189 {
190   struct bfd_link_hash_entry root;
191
192   /* Symbol index in output file.  Set to -1 initially.  Set to -2 if
193      there is a reloc against this symbol.  */
194   long indx;
195
196   /* Symbol type.  */
197   unsigned short type;
198
199   /* Symbol class.  */
200   unsigned char class;
201
202   /* Number of auxiliary entries.  */
203   char numaux;
204
205   /* BFD to take auxiliary entries from.  */
206   bfd *auxbfd;
207
208   /* Pointer to array of auxiliary entries, if any.  */
209   union internal_auxent *aux;
210 };
211
212 /* COFF linker hash table.  */
213
214 struct coff_link_hash_table
215 {
216   struct bfd_link_hash_table root;
217 };
218
219 /* Look up an entry in a COFF linker hash table.  */
220
221 #define coff_link_hash_lookup(table, string, create, copy, follow)      \
222   ((struct coff_link_hash_entry *)                                      \
223    bfd_link_hash_lookup (&(table)->root, (string), (create),            \
224                          (copy), (follow)))
225
226 /* Traverse a COFF linker hash table.  */
227
228 #define coff_link_hash_traverse(table, func, info)                      \
229   (bfd_link_hash_traverse                                               \
230    (&(table)->root,                                                     \
231     (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func),  \
232     (info)))
233
234 /* Get the COFF linker hash table from a link_info structure.  */
235
236 #define coff_hash_table(p) ((struct coff_link_hash_table *) ((p)->hash))
237
238 /* Functions in coffgen.c.  */
239 extern const bfd_target *coff_object_p PARAMS ((bfd *));
240 extern struct sec *coff_section_from_bfd_index PARAMS ((bfd *, int));
241 extern long coff_get_symtab_upper_bound PARAMS ((bfd *));
242 extern long coff_get_symtab PARAMS ((bfd *, asymbol **));
243 extern int coff_count_linenumbers PARAMS ((bfd *));
244 extern struct coff_symbol_struct *coff_symbol_from PARAMS ((bfd *, asymbol *));
245 extern boolean coff_renumber_symbols PARAMS ((bfd *, int *));
246 extern void coff_mangle_symbols PARAMS ((bfd *));
247 extern boolean coff_write_symbols PARAMS ((bfd *));
248 extern boolean coff_write_linenumbers PARAMS ((bfd *));
249 extern alent *coff_get_lineno PARAMS ((bfd *, asymbol *));
250 extern asymbol *coff_section_symbol PARAMS ((bfd *, char *));
251 extern boolean _bfd_coff_get_external_symbols PARAMS ((bfd *));
252 extern const char *_bfd_coff_read_string_table PARAMS ((bfd *));
253 extern boolean _bfd_coff_free_symbols PARAMS ((bfd *));
254 extern struct coff_ptr_struct *coff_get_normalized_symtab PARAMS ((bfd *));
255 extern long coff_get_reloc_upper_bound PARAMS ((bfd *, sec_ptr));
256 extern asymbol *coff_make_empty_symbol PARAMS ((bfd *));
257 extern void coff_print_symbol PARAMS ((bfd *, PTR filep, asymbol *,
258                                        bfd_print_symbol_type how));
259 extern void coff_get_symbol_info PARAMS ((bfd *, asymbol *,
260                                           symbol_info *ret));
261 extern asymbol *coff_bfd_make_debug_symbol PARAMS ((bfd *, PTR,
262                                                     unsigned long));
263 extern boolean coff_find_nearest_line PARAMS ((bfd *,
264                                                asection *,
265                                                asymbol **,
266                                                bfd_vma offset,
267                                                CONST char **filename_ptr,
268                                                CONST char **functionname_ptr,
269                                                unsigned int *line_ptr));
270 extern int coff_sizeof_headers PARAMS ((bfd *, boolean reloc));
271 extern boolean bfd_coff_reloc16_relax_section
272   PARAMS ((bfd *, asection *, struct bfd_link_info *, boolean *));
273 extern bfd_byte *bfd_coff_reloc16_get_relocated_section_contents
274   PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,
275            bfd_byte *, boolean relocateable, asymbol **));
276 extern bfd_vma bfd_coff_reloc16_get_value PARAMS ((arelent *,
277                                                    struct bfd_link_info *,
278                                                    asection *));
279 extern void bfd_perform_slip PARAMS ((bfd *abfd, unsigned int slip,
280                                       asection *input_section,
281                                       bfd_vma val));
282
283 /* Functions in cofflink.c.  */
284
285 extern struct bfd_hash_entry *_bfd_coff_link_hash_newfunc
286   PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
287 extern boolean _bfd_coff_link_hash_table_init
288   PARAMS ((struct coff_link_hash_table *, bfd *,
289            struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
290                                        struct bfd_hash_table *,
291                                        const char *)));
292 extern struct bfd_link_hash_table *_bfd_coff_link_hash_table_create
293   PARAMS ((bfd *));
294 extern const char *_bfd_coff_internal_syment_name
295   PARAMS ((bfd *, const struct internal_syment *, char *));
296 extern boolean _bfd_coff_link_add_symbols
297   PARAMS ((bfd *, struct bfd_link_info *));
298 extern boolean _bfd_coff_final_link
299   PARAMS ((bfd *, struct bfd_link_info *));
300 extern struct internal_reloc *_bfd_coff_read_internal_relocs
301   PARAMS ((bfd *, asection *, boolean, bfd_byte *, boolean,
302            struct internal_reloc *));
303 extern boolean _bfd_coff_generic_relocate_section
304   PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
305            struct internal_reloc *, struct internal_syment *, asection **));
306
307 /* Functions in xcofflink.c.  */
308
309 extern struct bfd_link_hash_table *_bfd_xcoff_bfd_link_hash_table_create
310   PARAMS ((bfd *));
311 extern boolean _bfd_xcoff_bfd_link_add_symbols
312   PARAMS ((bfd *, struct bfd_link_info *));
313 extern boolean _bfd_xcoff_bfd_final_link
314   PARAMS ((bfd *, struct bfd_link_info *));
315 extern boolean _bfd_ppc_xcoff_relocate_section
316   PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
317            struct internal_reloc *, struct internal_syment *, asection **));
318
319 /* And more taken from the source .. */
320