bfdlink.h revision 1.1.1.2 1 1.1 christos /* bfdlink.h -- header file for BFD link routines
2 1.1 christos Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 1.1.1.2 christos 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
4 1.1.1.2 christos Free Software Foundation, Inc.
5 1.1 christos Written by Steve Chamberlain and Ian Lance Taylor, Cygnus Support.
6 1.1 christos
7 1.1 christos This file is part of BFD, the Binary File Descriptor library.
8 1.1 christos
9 1.1 christos This program is free software; you can redistribute it and/or modify
10 1.1 christos it under the terms of the GNU General Public License as published by
11 1.1 christos the Free Software Foundation; either version 3 of the License, or
12 1.1 christos (at your option) any later version.
13 1.1 christos
14 1.1 christos This program is distributed in the hope that it will be useful,
15 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
16 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 1.1 christos GNU General Public License for more details.
18 1.1 christos
19 1.1 christos You should have received a copy of the GNU General Public License
20 1.1 christos along with this program; if not, write to the Free Software
21 1.1 christos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 1.1 christos MA 02110-1301, USA. */
23 1.1 christos
24 1.1 christos #ifndef BFDLINK_H
25 1.1 christos #define BFDLINK_H
26 1.1 christos
27 1.1 christos /* Which symbols to strip during a link. */
28 1.1 christos enum bfd_link_strip
29 1.1 christos {
30 1.1 christos strip_none, /* Don't strip any symbols. */
31 1.1 christos strip_debugger, /* Strip debugging symbols. */
32 1.1 christos strip_some, /* keep_hash is the list of symbols to keep. */
33 1.1 christos strip_all /* Strip all symbols. */
34 1.1 christos };
35 1.1 christos
36 1.1 christos /* Which local symbols to discard during a link. This is irrelevant
37 1.1 christos if strip_all is used. */
38 1.1 christos enum bfd_link_discard
39 1.1 christos {
40 1.1 christos discard_sec_merge, /* Discard local temporary symbols in SEC_MERGE
41 1.1 christos sections. */
42 1.1 christos discard_none, /* Don't discard any locals. */
43 1.1 christos discard_l, /* Discard local temporary symbols. */
44 1.1 christos discard_all /* Discard all locals. */
45 1.1 christos };
46 1.1 christos
47 1.1 christos /* Describes the type of hash table entry structure being used.
48 1.1 christos Different hash table structure have different fields and so
49 1.1 christos support different linking features. */
50 1.1 christos enum bfd_link_hash_table_type
51 1.1 christos {
52 1.1 christos bfd_link_generic_hash_table,
53 1.1 christos bfd_link_elf_hash_table
54 1.1 christos };
55 1.1 christos
56 1.1 christos /* These are the possible types of an entry in the BFD link hash
58 1.1 christos table. */
59 1.1 christos
60 1.1 christos enum bfd_link_hash_type
61 1.1 christos {
62 1.1 christos bfd_link_hash_new, /* Symbol is new. */
63 1.1 christos bfd_link_hash_undefined, /* Symbol seen before, but undefined. */
64 1.1 christos bfd_link_hash_undefweak, /* Symbol is weak and undefined. */
65 1.1 christos bfd_link_hash_defined, /* Symbol is defined. */
66 1.1 christos bfd_link_hash_defweak, /* Symbol is weak and defined. */
67 1.1 christos bfd_link_hash_common, /* Symbol is common. */
68 1.1 christos bfd_link_hash_indirect, /* Symbol is an indirect link. */
69 1.1 christos bfd_link_hash_warning /* Like indirect, but warn if referenced. */
70 1.1 christos };
71 1.1 christos
72 1.1 christos enum bfd_link_common_skip_ar_symbols
73 1.1 christos {
74 1.1 christos bfd_link_common_skip_none,
75 1.1 christos bfd_link_common_skip_text,
76 1.1 christos bfd_link_common_skip_data,
77 1.1 christos bfd_link_common_skip_all
78 1.1 christos };
79 1.1 christos
80 1.1 christos struct bfd_link_hash_common_entry
81 1.1 christos {
82 1.1 christos unsigned int alignment_power; /* Alignment. */
83 1.1 christos asection *section; /* Symbol section. */
84 1.1 christos };
85 1.1 christos
86 1.1 christos /* The linking routines use a hash table which uses this structure for
87 1.1 christos its elements. */
88 1.1 christos
89 1.1 christos struct bfd_link_hash_entry
90 1.1 christos {
91 1.1 christos /* Base hash table entry structure. */
92 1.1 christos struct bfd_hash_entry root;
93 1.1 christos
94 1.1.1.2 christos /* Type of this entry. */
95 1.1.1.2 christos ENUM_BITFIELD (bfd_link_hash_type) type : 8;
96 1.1.1.2 christos
97 1.1 christos unsigned int non_ir_ref : 1;
98 1.1 christos
99 1.1 christos /* A union of information depending upon the type. */
100 1.1 christos union
101 1.1 christos {
102 1.1 christos /* Nothing is kept for bfd_hash_new. */
103 1.1 christos /* bfd_link_hash_undefined, bfd_link_hash_undefweak. */
104 1.1 christos struct
105 1.1 christos {
106 1.1 christos /* Undefined and common symbols are kept in a linked list through
107 1.1 christos this field. This field is present in all of the union element
108 1.1 christos so that we don't need to remove entries from the list when we
109 1.1 christos change their type. Removing entries would either require the
110 1.1 christos list to be doubly linked, which would waste more memory, or
111 1.1 christos require a traversal. When an undefined or common symbol is
112 1.1 christos created, it should be added to this list, the head of which is in
113 1.1 christos the link hash table itself. As symbols are defined, they need
114 1.1 christos not be removed from the list; anything which reads the list must
115 1.1 christos doublecheck the symbol type.
116 1.1 christos
117 1.1 christos Weak symbols are not kept on this list.
118 1.1 christos
119 1.1 christos Defined and defweak symbols use this field as a reference marker.
120 1.1 christos If the field is not NULL, or this structure is the tail of the
121 1.1 christos undefined symbol list, the symbol has been referenced. If the
122 1.1 christos symbol is undefined and becomes defined, this field will
123 1.1 christos automatically be non-NULL since the symbol will have been on the
124 1.1 christos undefined symbol list. */
125 1.1 christos struct bfd_link_hash_entry *next;
126 1.1 christos bfd *abfd; /* BFD symbol was found in. */
127 1.1 christos } undef;
128 1.1 christos /* bfd_link_hash_defined, bfd_link_hash_defweak. */
129 1.1 christos struct
130 1.1 christos {
131 1.1 christos struct bfd_link_hash_entry *next;
132 1.1 christos asection *section; /* Symbol section. */
133 1.1 christos bfd_vma value; /* Symbol value. */
134 1.1 christos } def;
135 1.1 christos /* bfd_link_hash_indirect, bfd_link_hash_warning. */
136 1.1 christos struct
137 1.1 christos {
138 1.1 christos struct bfd_link_hash_entry *next;
139 1.1 christos struct bfd_link_hash_entry *link; /* Real symbol. */
140 1.1 christos const char *warning; /* Warning (bfd_link_hash_warning only). */
141 1.1 christos } i;
142 1.1 christos /* bfd_link_hash_common. */
143 1.1 christos struct
144 1.1 christos {
145 1.1 christos struct bfd_link_hash_entry *next;
146 1.1 christos /* The linker needs to know three things about common
147 1.1 christos symbols: the size, the alignment, and the section in
148 1.1 christos which the symbol should be placed. We store the size
149 1.1 christos here, and we allocate a small structure to hold the
150 1.1 christos section and the alignment. The alignment is stored as a
151 1.1 christos power of two. We don't store all the information
152 1.1 christos directly because we don't want to increase the size of
153 1.1 christos the union; this structure is a major space user in the
154 1.1 christos linker. */
155 1.1 christos struct bfd_link_hash_common_entry *p;
156 1.1 christos bfd_size_type size; /* Common symbol size. */
157 1.1 christos } c;
158 1.1 christos } u;
159 1.1 christos };
160 1.1 christos
161 1.1 christos /* This is the link hash table. It is a derived class of
162 1.1 christos bfd_hash_table. */
163 1.1 christos
164 1.1 christos struct bfd_link_hash_table
165 1.1 christos {
166 1.1 christos /* The hash table itself. */
167 1.1 christos struct bfd_hash_table table;
168 1.1 christos /* A linked list of undefined and common symbols, linked through the
169 1.1 christos next field in the bfd_link_hash_entry structure. */
170 1.1 christos struct bfd_link_hash_entry *undefs;
171 1.1 christos /* Entries are added to the tail of the undefs list. */
172 1.1 christos struct bfd_link_hash_entry *undefs_tail;
173 1.1 christos /* The type of the link hash table. */
174 1.1 christos enum bfd_link_hash_table_type type;
175 1.1 christos };
176 1.1 christos
177 1.1 christos /* Look up an entry in a link hash table. If FOLLOW is TRUE, this
178 1.1 christos follows bfd_link_hash_indirect and bfd_link_hash_warning links to
179 1.1 christos the real symbol. */
180 1.1 christos extern struct bfd_link_hash_entry *bfd_link_hash_lookup
181 1.1 christos (struct bfd_link_hash_table *, const char *, bfd_boolean create,
182 1.1 christos bfd_boolean copy, bfd_boolean follow);
183 1.1 christos
184 1.1 christos /* Look up an entry in the main linker hash table if the symbol might
185 1.1 christos be wrapped. This should only be used for references to an
186 1.1 christos undefined symbol, not for definitions of a symbol. */
187 1.1 christos
188 1.1 christos extern struct bfd_link_hash_entry *bfd_wrapped_link_hash_lookup
189 1.1 christos (bfd *, struct bfd_link_info *, const char *, bfd_boolean,
190 1.1 christos bfd_boolean, bfd_boolean);
191 1.1 christos
192 1.1 christos /* Traverse a link hash table. */
193 1.1 christos extern void bfd_link_hash_traverse
194 1.1 christos (struct bfd_link_hash_table *,
195 1.1 christos bfd_boolean (*) (struct bfd_link_hash_entry *, void *),
196 1.1 christos void *);
197 1.1 christos
198 1.1 christos /* Add an entry to the undefs list. */
199 1.1 christos extern void bfd_link_add_undef
200 1.1 christos (struct bfd_link_hash_table *, struct bfd_link_hash_entry *);
201 1.1 christos
202 1.1 christos /* Remove symbols from the undefs list that don't belong there. */
203 1.1 christos extern void bfd_link_repair_undef_list
204 1.1 christos (struct bfd_link_hash_table *table);
205 1.1 christos
206 1.1 christos /* Read symbols and cache symbol pointer array in outsymbols. */
207 1.1 christos extern bfd_boolean bfd_generic_link_read_symbols (bfd *);
208 1.1 christos
209 1.1 christos struct bfd_sym_chain
210 1.1 christos {
211 1.1 christos struct bfd_sym_chain *next;
212 1.1 christos const char *name;
213 1.1 christos };
214 1.1 christos
215 1.1 christos /* How to handle unresolved symbols.
217 1.1 christos There are four possibilities which are enumerated below: */
218 1.1 christos enum report_method
219 1.1 christos {
220 1.1 christos /* This is the initial value when then link_info structure is created.
221 1.1 christos It allows the various stages of the linker to determine whether they
222 1.1 christos allowed to set the value. */
223 1.1 christos RM_NOT_YET_SET = 0,
224 1.1 christos RM_IGNORE,
225 1.1 christos RM_GENERATE_WARNING,
226 1.1 christos RM_GENERATE_ERROR
227 1.1.1.2 christos };
228 1.1.1.2 christos
229 1.1.1.2 christos typedef enum {with_flags, without_flags} flag_type;
230 1.1.1.2 christos
231 1.1.1.2 christos /* A section flag list. */
232 1.1.1.2 christos struct flag_info_list
233 1.1.1.2 christos {
234 1.1.1.2 christos flag_type with;
235 1.1.1.2 christos const char *name;
236 1.1.1.2 christos bfd_boolean valid;
237 1.1.1.2 christos struct flag_info_list *next;
238 1.1.1.2 christos };
239 1.1.1.2 christos
240 1.1.1.2 christos /* Section flag info. */
241 1.1.1.2 christos struct flag_info
242 1.1.1.2 christos {
243 1.1.1.2 christos flagword only_with_flags;
244 1.1.1.2 christos flagword not_with_flags;
245 1.1.1.2 christos struct flag_info_list *flag_list;
246 1.1.1.2 christos bfd_boolean flags_initialized;
247 1.1 christos };
248 1.1.1.2 christos
249 1.1 christos struct bfd_elf_dynamic_list;
250 1.1 christos struct bfd_elf_version_tree;
251 1.1 christos
252 1.1 christos /* This structure holds all the information needed to communicate
253 1.1 christos between BFD and the linker when doing a link. */
254 1.1 christos
255 1.1.1.2 christos struct bfd_link_info
256 1.1.1.2 christos {
257 1.1 christos /* TRUE if BFD should generate a shared object (or a pie). */
258 1.1.1.2 christos unsigned int shared: 1;
259 1.1.1.2 christos
260 1.1 christos /* TRUE if generating an executable, position independent or not. */
261 1.1.1.2 christos unsigned int executable : 1;
262 1.1.1.2 christos
263 1.1 christos /* TRUE if generating a position independent executable. */
264 1.1.1.2 christos unsigned int pie: 1;
265 1.1.1.2 christos
266 1.1 christos /* TRUE if BFD should generate a relocatable object file. */
267 1.1 christos unsigned int relocatable: 1;
268 1.1 christos
269 1.1 christos /* TRUE if BFD should pre-bind symbols in a shared object. */
270 1.1.1.2 christos unsigned int symbolic: 1;
271 1.1.1.2 christos
272 1.1.1.2 christos /* TRUE if executable should not contain copy relocs.
273 1.1.1.2 christos Setting this true may result in a non-sharable text segment. */
274 1.1 christos unsigned int nocopyreloc: 1;
275 1.1 christos
276 1.1 christos /* TRUE if BFD should export all symbols in the dynamic symbol table
277 1.1 christos of an executable, rather than only those used. */
278 1.1 christos unsigned int export_dynamic: 1;
279 1.1 christos
280 1.1 christos /* TRUE if a default symbol version should be created and used for
281 1.1 christos exported symbols. */
282 1.1.1.2 christos unsigned int create_default_symver: 1;
283 1.1.1.2 christos
284 1.1 christos /* TRUE if unreferenced sections should be removed. */
285 1.1 christos unsigned int gc_sections: 1;
286 1.1 christos
287 1.1 christos /* TRUE if every symbol should be reported back via the notice
288 1.1 christos callback. */
289 1.1.1.2 christos unsigned int notice_all: 1;
290 1.1.1.2 christos
291 1.1 christos /* TRUE if we are loading LTO outputs. */
292 1.1.1.2 christos unsigned int loading_lto_outputs: 1;
293 1.1.1.2 christos
294 1.1 christos /* TRUE if global symbols in discarded sections should be stripped. */
295 1.1.1.2 christos unsigned int strip_discarded: 1;
296 1.1.1.2 christos
297 1.1 christos /* TRUE if all data symbols should be dynamic. */
298 1.1.1.2 christos unsigned int dynamic_data: 1;
299 1.1.1.2 christos
300 1.1 christos /* Which symbols to strip. */
301 1.1.1.2 christos ENUM_BITFIELD (bfd_link_strip) strip : 2;
302 1.1.1.2 christos
303 1.1 christos /* Which local symbols to discard. */
304 1.1.1.2 christos ENUM_BITFIELD (bfd_link_discard) discard : 2;
305 1.1.1.2 christos
306 1.1.1.2 christos /* Criteria for skipping symbols when determining
307 1.1 christos whether to include an object from an archive. */
308 1.1.1.2 christos ENUM_BITFIELD (bfd_link_common_skip_ar_symbols) common_skip_ar_symbols : 2;
309 1.1.1.2 christos
310 1.1.1.2 christos /* What to do with unresolved symbols in an object file.
311 1.1.1.2 christos When producing executables the default is GENERATE_ERROR.
312 1.1.1.2 christos When producing shared libraries the default is IGNORE. The
313 1.1.1.2 christos assumption with shared libraries is that the reference will be
314 1.1 christos resolved at load/execution time. */
315 1.1.1.2 christos ENUM_BITFIELD (report_method) unresolved_syms_in_objects : 2;
316 1.1.1.2 christos
317 1.1.1.2 christos /* What to do with unresolved symbols in a shared library.
318 1.1 christos The same defaults apply. */
319 1.1.1.2 christos ENUM_BITFIELD (report_method) unresolved_syms_in_shared_libs : 2;
320 1.1.1.2 christos
321 1.1.1.2 christos /* TRUE if shared objects should be linked directly, not shared. */
322 1.1.1.2 christos unsigned int static_link: 1;
323 1.1.1.2 christos
324 1.1.1.2 christos /* TRUE if symbols should be retained in memory, FALSE if they
325 1.1.1.2 christos should be freed and reread. */
326 1.1.1.2 christos unsigned int keep_memory: 1;
327 1.1.1.2 christos
328 1.1.1.2 christos /* TRUE if BFD should generate relocation information in the final
329 1.1 christos executable. */
330 1.1 christos unsigned int emitrelocations: 1;
331 1.1 christos
332 1.1 christos /* TRUE if PT_GNU_RELRO segment should be created. */
333 1.1.1.2 christos unsigned int relro: 1;
334 1.1.1.2 christos
335 1.1.1.2 christos /* TRUE if .eh_frame_hdr section and PT_GNU_EH_FRAME ELF segment
336 1.1.1.2 christos should be created. */
337 1.1 christos unsigned int eh_frame_hdr: 1;
338 1.1 christos
339 1.1 christos /* TRUE if we should warn when adding a DT_TEXTREL to a shared object. */
340 1.1.1.2 christos unsigned int warn_shared_textrel: 1;
341 1.1.1.2 christos
342 1.1 christos /* TRUE if we should error when adding a DT_TEXTREL. */
343 1.1 christos unsigned int error_textrel: 1;
344 1.1 christos
345 1.1 christos /* TRUE if .hash section should be created. */
346 1.1 christos unsigned int emit_hash: 1;
347 1.1 christos
348 1.1 christos /* TRUE if .gnu.hash section should be created. */
349 1.1 christos unsigned int emit_gnu_hash: 1;
350 1.1 christos
351 1.1 christos /* If TRUE reduce memory overheads, at the expense of speed. This will
352 1.1 christos cause map file generation to use an O(N^2) algorithm and disable
353 1.1 christos caching ELF symbol buffer. */
354 1.1.1.2 christos unsigned int reduce_memory_overheads: 1;
355 1.1.1.2 christos
356 1.1.1.2 christos /* TRUE if the output file should be in a traditional format. This
357 1.1.1.2 christos is equivalent to the setting of the BFD_TRADITIONAL_FORMAT flag
358 1.1.1.2 christos on the output file, but may be checked when reading the input
359 1.1.1.2 christos files. */
360 1.1.1.2 christos unsigned int traditional_format: 1;
361 1.1.1.2 christos
362 1.1.1.2 christos /* TRUE if non-PLT relocs should be merged into one reloc section
363 1.1.1.2 christos and sorted so that relocs against the same symbol come together. */
364 1.1.1.2 christos unsigned int combreloc: 1;
365 1.1.1.2 christos
366 1.1.1.2 christos /* TRUE if a default symbol version should be created and used for
367 1.1.1.2 christos imported symbols. */
368 1.1.1.2 christos unsigned int default_imported_symver: 1;
369 1.1.1.2 christos
370 1.1.1.2 christos /* TRUE if the new ELF dynamic tags are enabled. */
371 1.1.1.2 christos unsigned int new_dtags: 1;
372 1.1.1.2 christos
373 1.1.1.2 christos /* FALSE if .eh_frame unwind info should be generated for PLT and other
374 1.1.1.2 christos linker created sections, TRUE if it should be omitted. */
375 1.1.1.2 christos unsigned int no_ld_generated_unwind_info: 1;
376 1.1.1.2 christos
377 1.1.1.2 christos /* TRUE if BFD should generate a "task linked" object file,
378 1.1.1.2 christos similar to relocatable but also with globals converted to
379 1.1.1.2 christos statics. */
380 1.1.1.2 christos unsigned int task_link: 1;
381 1.1.1.2 christos
382 1.1.1.2 christos /* TRUE if ok to have multiple definition. */
383 1.1.1.2 christos unsigned int allow_multiple_definition: 1;
384 1.1.1.2 christos
385 1.1 christos /* TRUE if ok to have version with no definition. */
386 1.1 christos unsigned int allow_undefined_version: 1;
387 1.1 christos
388 1.1 christos /* TRUE if some symbols have to be dynamic, controlled by
389 1.1 christos --dynamic-list command line options. */
390 1.1.1.2 christos unsigned int dynamic: 1;
391 1.1.1.2 christos
392 1.1.1.2 christos /* TRUE if PT_GNU_STACK segment should be created with PF_R|PF_W|PF_X
393 1.1 christos flags. */
394 1.1.1.2 christos unsigned int execstack: 1;
395 1.1.1.2 christos
396 1.1.1.2 christos /* TRUE if PT_GNU_STACK segment should be created with PF_R|PF_W
397 1.1 christos flags. */
398 1.1.1.2 christos unsigned int noexecstack: 1;
399 1.1.1.2 christos
400 1.1.1.2 christos /* TRUE if we want to produced optimized output files. This might
401 1.1 christos need much more time and therefore must be explicitly selected. */
402 1.1.1.2 christos unsigned int optimize: 1;
403 1.1.1.2 christos
404 1.1 christos /* TRUE if user should be informed of removed unreferenced sections. */
405 1.1.1.2 christos unsigned int print_gc_sections: 1;
406 1.1.1.2 christos
407 1.1 christos /* TRUE if we should warn alternate ELF machine code. */
408 1.1.1.2 christos unsigned int warn_alternate_em: 1;
409 1.1.1.2 christos
410 1.1 christos /* TRUE if the linker script contained an explicit PHDRS command. */
411 1.1 christos unsigned int user_phdrs: 1;
412 1.1 christos
413 1.1 christos /* Char that may appear as the first char of a symbol, but should be
414 1.1 christos skipped (like symbol_leading_char) when looking up symbols in
415 1.1 christos wrap_hash. Used by PowerPC Linux for 'dot' symbols. */
416 1.1 christos char wrap_char;
417 1.1 christos
418 1.1 christos /* Separator between archive and filename in linker script filespecs. */
419 1.1.1.2 christos char path_separator;
420 1.1.1.2 christos
421 1.1.1.2 christos /* Default stack size. Zero means default (often zero itself), -1
422 1.1.1.2 christos means explicitly zero-sized. */
423 1.1.1.2 christos bfd_signed_vma stacksize;
424 1.1.1.2 christos
425 1.1.1.2 christos /* Enable or disable target specific optimizations.
426 1.1.1.2 christos
427 1.1.1.2 christos Not all targets have optimizations to enable.
428 1.1.1.2 christos
429 1.1.1.2 christos Normally these optimizations are disabled by default but some targets
430 1.1.1.2 christos prefer to enable them by default. So this field is a tri-state variable.
431 1.1.1.2 christos The values are:
432 1.1.1.2 christos
433 1.1.1.2 christos zero: Enable the optimizations (either from --relax being specified on
434 1.1.1.2 christos the command line or the backend's before_allocation emulation function.
435 1.1.1.2 christos
436 1.1.1.2 christos positive: The user has requested that these optimizations be disabled.
437 1.1.1.2 christos (Via the --no-relax command line option).
438 1.1.1.2 christos
439 1.1.1.2 christos negative: The optimizations are disabled. (Set when initializing the
440 1.1.1.2 christos args_type structure in ldmain.c:main. */
441 1.1 christos signed int disable_target_specific_optimizations;
442 1.1 christos
443 1.1 christos /* Function callbacks. */
444 1.1 christos const struct bfd_link_callbacks *callbacks;
445 1.1 christos
446 1.1 christos /* Hash table handled by BFD. */
447 1.1 christos struct bfd_link_hash_table *hash;
448 1.1 christos
449 1.1 christos /* Hash table of symbols to keep. This is NULL unless strip is
450 1.1 christos strip_some. */
451 1.1 christos struct bfd_hash_table *keep_hash;
452 1.1 christos
453 1.1 christos /* Hash table of symbols to report back via the notice callback. If
454 1.1 christos this is NULL, and notice_all is FALSE, then no symbols are
455 1.1 christos reported back. */
456 1.1 christos struct bfd_hash_table *notice_hash;
457 1.1 christos
458 1.1 christos /* Hash table of symbols which are being wrapped (the --wrap linker
459 1.1 christos option). If this is NULL, no symbols are being wrapped. */
460 1.1.1.2 christos struct bfd_hash_table *wrap_hash;
461 1.1.1.2 christos
462 1.1.1.2 christos /* Hash table of symbols which may be left unresolved during
463 1.1.1.2 christos a link. If this is NULL, no symbols can be left unresolved. */
464 1.1 christos struct bfd_hash_table *ignore_hash;
465 1.1 christos
466 1.1 christos /* The output BFD. */
467 1.1 christos bfd *output_bfd;
468 1.1 christos
469 1.1 christos /* The list of input BFD's involved in the link. These are chained
470 1.1 christos together via the link_next field. */
471 1.1 christos bfd *input_bfds;
472 1.1 christos bfd **input_bfds_tail;
473 1.1 christos
474 1.1 christos /* If a symbol should be created for each input BFD, this is section
475 1.1 christos where those symbols should be placed. It must be a section in
476 1.1 christos the output BFD. It may be NULL, in which case no such symbols
477 1.1 christos will be created. This is to support CREATE_OBJECT_SYMBOLS in the
478 1.1 christos linker command language. */
479 1.1 christos asection *create_object_symbols_section;
480 1.1 christos
481 1.1 christos /* List of global symbol names that are starting points for marking
482 1.1 christos sections against garbage collection. */
483 1.1 christos struct bfd_sym_chain *gc_sym_list;
484 1.1 christos
485 1.1 christos /* If a base output file is wanted, then this points to it */
486 1.1 christos void *base_file;
487 1.1 christos
488 1.1 christos /* The function to call when the executable or shared object is
489 1.1 christos loaded. */
490 1.1 christos const char *init_function;
491 1.1 christos
492 1.1 christos /* The function to call when the executable or shared object is
493 1.1 christos unloaded. */
494 1.1 christos const char *fini_function;
495 1.1 christos
496 1.1 christos /* Number of relaxation passes. Usually only one relaxation pass
497 1.1 christos is needed. But a backend can have as many relaxation passes as
498 1.1 christos necessary. During bfd_relax_section call, it is set to the
499 1.1 christos current pass, starting from 0. */
500 1.1 christos int relax_pass;
501 1.1 christos
502 1.1 christos /* Number of relaxation trips. This number is incremented every
503 1.1 christos time the relaxation pass is restarted due to a previous
504 1.1 christos relaxation returning true in *AGAIN. */
505 1.1 christos int relax_trip;
506 1.1 christos
507 1.1 christos /* Non-zero if auto-import thunks for DATA items in pei386 DLLs
508 1.1 christos should be generated/linked against. Set to 1 if this feature
509 1.1 christos is explicitly requested by the user, -1 if enabled by default. */
510 1.1 christos int pei386_auto_import;
511 1.1 christos
512 1.1 christos /* Non-zero if runtime relocs for DATA items with non-zero addends
513 1.1 christos in pei386 DLLs should be generated. Set to 1 if this feature
514 1.1 christos is explicitly requested by the user, -1 if enabled by default. */
515 1.1 christos int pei386_runtime_pseudo_reloc;
516 1.1 christos
517 1.1 christos /* How many spare .dynamic DT_NULL entries should be added? */
518 1.1 christos unsigned int spare_dynamic_tags;
519 1.1 christos
520 1.1 christos /* May be used to set DT_FLAGS for ELF. */
521 1.1 christos bfd_vma flags;
522 1.1 christos
523 1.1 christos /* May be used to set DT_FLAGS_1 for ELF. */
524 1.1 christos bfd_vma flags_1;
525 1.1 christos
526 1.1 christos /* Start and end of RELRO region. */
527 1.1 christos bfd_vma relro_start, relro_end;
528 1.1 christos
529 1.1.1.2 christos /* List of symbols should be dynamic. */
530 1.1.1.2 christos struct bfd_elf_dynamic_list *dynamic_list;
531 1.1.1.2 christos
532 1.1 christos /* The version information. */
533 1.1 christos struct bfd_elf_version_tree *version_info;
534 1.1 christos };
535 1.1 christos
536 1.1 christos /* This structures holds a set of callback functions. These are called
537 1.1 christos by the BFD linker routines. Except for the info functions, the first
538 1.1 christos argument to each callback function is the bfd_link_info structure
539 1.1 christos being used and each function returns a boolean value. If the
540 1.1 christos function returns FALSE, then the BFD function which called it should
541 1.1 christos return with a failure indication. */
542 1.1 christos
543 1.1 christos struct bfd_link_callbacks
544 1.1 christos {
545 1.1 christos /* A function which is called when an object is added from an
546 1.1 christos archive. ABFD is the archive element being added. NAME is the
547 1.1 christos name of the symbol which caused the archive element to be pulled
548 1.1 christos in. This function may set *SUBSBFD to point to an alternative
549 1.1 christos BFD from which symbols should in fact be added in place of the
550 1.1 christos original BFD's symbols. */
551 1.1 christos bfd_boolean (*add_archive_element)
552 1.1.1.2 christos (struct bfd_link_info *, bfd *abfd, const char *name, bfd **subsbfd);
553 1.1.1.2 christos /* A function which is called when a symbol is found with multiple
554 1.1.1.2 christos definitions. H is the symbol which is defined multiple times.
555 1.1 christos NBFD is the new BFD, NSEC is the new section, and NVAL is the new
556 1.1.1.2 christos value. NSEC may be bfd_com_section or bfd_ind_section. */
557 1.1 christos bfd_boolean (*multiple_definition)
558 1.1 christos (struct bfd_link_info *, struct bfd_link_hash_entry *h,
559 1.1.1.2 christos bfd *nbfd, asection *nsec, bfd_vma nval);
560 1.1 christos /* A function which is called when a common symbol is defined
561 1.1 christos multiple times. H is the symbol appearing multiple times.
562 1.1 christos NBFD is the BFD of the new symbol. NTYPE is the type of the new
563 1.1 christos symbol, one of bfd_link_hash_defined, bfd_link_hash_common, or
564 1.1 christos bfd_link_hash_indirect. If NTYPE is bfd_link_hash_common, NSIZE
565 1.1.1.2 christos is the size of the new symbol. */
566 1.1 christos bfd_boolean (*multiple_common)
567 1.1 christos (struct bfd_link_info *, struct bfd_link_hash_entry *h,
568 1.1 christos bfd *nbfd, enum bfd_link_hash_type ntype, bfd_vma nsize);
569 1.1 christos /* A function which is called to add a symbol to a set. ENTRY is
570 1.1 christos the link hash table entry for the set itself (e.g.,
571 1.1 christos __CTOR_LIST__). RELOC is the relocation to use for an entry in
572 1.1 christos the set when generating a relocatable file, and is also used to
573 1.1 christos get the size of the entry when generating an executable file.
574 1.1 christos ABFD, SEC and VALUE identify the value to add to the set. */
575 1.1 christos bfd_boolean (*add_to_set)
576 1.1 christos (struct bfd_link_info *, struct bfd_link_hash_entry *entry,
577 1.1 christos bfd_reloc_code_real_type reloc, bfd *abfd, asection *sec, bfd_vma value);
578 1.1 christos /* A function which is called when the name of a g++ constructor or
579 1.1 christos destructor is found. This is only called by some object file
580 1.1 christos formats. CONSTRUCTOR is TRUE for a constructor, FALSE for a
581 1.1 christos destructor. This will use BFD_RELOC_CTOR when generating a
582 1.1 christos relocatable file. NAME is the name of the symbol found. ABFD,
583 1.1 christos SECTION and VALUE are the value of the symbol. */
584 1.1 christos bfd_boolean (*constructor)
585 1.1 christos (struct bfd_link_info *, bfd_boolean constructor, const char *name,
586 1.1 christos bfd *abfd, asection *sec, bfd_vma value);
587 1.1 christos /* A function which is called to issue a linker warning. For
588 1.1 christos example, this is called when there is a reference to a warning
589 1.1 christos symbol. WARNING is the warning to be issued. SYMBOL is the name
590 1.1 christos of the symbol which triggered the warning; it may be NULL if
591 1.1 christos there is none. ABFD, SECTION and ADDRESS identify the location
592 1.1 christos which trigerred the warning; either ABFD or SECTION or both may
593 1.1 christos be NULL if the location is not known. */
594 1.1 christos bfd_boolean (*warning)
595 1.1 christos (struct bfd_link_info *, const char *warning, const char *symbol,
596 1.1 christos bfd *abfd, asection *section, bfd_vma address);
597 1.1 christos /* A function which is called when a relocation is attempted against
598 1.1 christos an undefined symbol. NAME is the symbol which is undefined.
599 1.1 christos ABFD, SECTION and ADDRESS identify the location from which the
600 1.1 christos reference is made. IS_FATAL indicates whether an undefined symbol is
601 1.1 christos a fatal error or not. In some cases SECTION may be NULL. */
602 1.1 christos bfd_boolean (*undefined_symbol)
603 1.1 christos (struct bfd_link_info *, const char *name, bfd *abfd,
604 1.1 christos asection *section, bfd_vma address, bfd_boolean is_fatal);
605 1.1 christos /* A function which is called when a reloc overflow occurs. ENTRY is
606 1.1 christos the link hash table entry for the symbol the reloc is against.
607 1.1 christos NAME is the name of the local symbol or section the reloc is
608 1.1 christos against, RELOC_NAME is the name of the relocation, and ADDEND is
609 1.1 christos any addend that is used. ABFD, SECTION and ADDRESS identify the
610 1.1 christos location at which the overflow occurs; if this is the result of a
611 1.1 christos bfd_section_reloc_link_order or bfd_symbol_reloc_link_order, then
612 1.1 christos ABFD will be NULL. */
613 1.1 christos bfd_boolean (*reloc_overflow)
614 1.1 christos (struct bfd_link_info *, struct bfd_link_hash_entry *entry,
615 1.1 christos const char *name, const char *reloc_name, bfd_vma addend,
616 1.1 christos bfd *abfd, asection *section, bfd_vma address);
617 1.1 christos /* A function which is called when a dangerous reloc is performed.
618 1.1 christos MESSAGE is an appropriate message.
619 1.1 christos ABFD, SECTION and ADDRESS identify the location at which the
620 1.1 christos problem occurred; if this is the result of a
621 1.1 christos bfd_section_reloc_link_order or bfd_symbol_reloc_link_order, then
622 1.1 christos ABFD will be NULL. */
623 1.1 christos bfd_boolean (*reloc_dangerous)
624 1.1 christos (struct bfd_link_info *, const char *message,
625 1.1 christos bfd *abfd, asection *section, bfd_vma address);
626 1.1 christos /* A function which is called when a reloc is found to be attached
627 1.1 christos to a symbol which is not being written out. NAME is the name of
628 1.1 christos the symbol. ABFD, SECTION and ADDRESS identify the location of
629 1.1 christos the reloc; if this is the result of a
630 1.1 christos bfd_section_reloc_link_order or bfd_symbol_reloc_link_order, then
631 1.1 christos ABFD will be NULL. */
632 1.1 christos bfd_boolean (*unattached_reloc)
633 1.1 christos (struct bfd_link_info *, const char *name,
634 1.1.1.2 christos bfd *abfd, asection *section, bfd_vma address);
635 1.1.1.2 christos /* A function which is called when a symbol in notice_hash is
636 1.1.1.2 christos defined or referenced. H is the symbol. ABFD, SECTION and
637 1.1.1.2 christos ADDRESS are the (new) value of the symbol. If SECTION is
638 1.1.1.2 christos bfd_und_section, this is a reference. FLAGS are the symbol
639 1.1 christos BSF_* flags. STRING is the name of the symbol to indirect to if
640 1.1.1.2 christos the sym is indirect, or the warning string if a warning sym. */
641 1.1.1.2 christos bfd_boolean (*notice)
642 1.1.1.2 christos (struct bfd_link_info *, struct bfd_link_hash_entry *h,
643 1.1 christos bfd *abfd, asection *section, bfd_vma address, flagword flags,
644 1.1 christos const char *string);
645 1.1 christos /* Error or warning link info message. */
646 1.1 christos void (*einfo)
647 1.1 christos (const char *fmt, ...);
648 1.1 christos /* General link info message. */
649 1.1 christos void (*info)
650 1.1 christos (const char *fmt, ...);
651 1.1 christos /* Message to be printed in linker map file. */
652 1.1 christos void (*minfo)
653 1.1 christos (const char *fmt, ...);
654 1.1 christos /* This callback provides a chance for users of the BFD library to
655 1.1 christos override its decision about whether to place two adjacent sections
656 1.1 christos into the same segment. */
657 1.1 christos bfd_boolean (*override_segment_assignment)
658 1.1 christos (struct bfd_link_info *, bfd * abfd,
659 1.1 christos asection * current_section, asection * previous_section,
660 1.1 christos bfd_boolean new_segment);
661 1.1 christos };
662 1.1 christos
663 1.1 christos /* The linker builds link_order structures which tell the code how to
665 1.1 christos include input data in the output file. */
666 1.1 christos
667 1.1 christos /* These are the types of link_order structures. */
668 1.1 christos
669 1.1 christos enum bfd_link_order_type
670 1.1 christos {
671 1.1 christos bfd_undefined_link_order, /* Undefined. */
672 1.1 christos bfd_indirect_link_order, /* Built from a section. */
673 1.1 christos bfd_data_link_order, /* Set to explicit data. */
674 1.1 christos bfd_section_reloc_link_order, /* Relocate against a section. */
675 1.1 christos bfd_symbol_reloc_link_order /* Relocate against a symbol. */
676 1.1 christos };
677 1.1 christos
678 1.1 christos /* This is the link_order structure itself. These form a chain
679 1.1 christos attached to the output section whose contents they are describing. */
680 1.1 christos
681 1.1 christos struct bfd_link_order
682 1.1 christos {
683 1.1 christos /* Next link_order in chain. */
684 1.1 christos struct bfd_link_order *next;
685 1.1 christos /* Type of link_order. */
686 1.1 christos enum bfd_link_order_type type;
687 1.1 christos /* Offset within output section. */
688 1.1 christos bfd_vma offset;
689 1.1 christos /* Size within output section. */
690 1.1 christos bfd_size_type size;
691 1.1 christos /* Type specific information. */
692 1.1 christos union
693 1.1 christos {
694 1.1 christos struct
695 1.1 christos {
696 1.1 christos /* Section to include. If this is used, then
697 1.1 christos section->output_section must be the section the
698 1.1 christos link_order is attached to, section->output_offset must
699 1.1 christos equal the link_order offset field, and section->size
700 1.1 christos must equal the link_order size field. Maybe these
701 1.1 christos restrictions should be relaxed someday. */
702 1.1 christos asection *section;
703 1.1.1.2 christos } indirect;
704 1.1.1.2 christos struct
705 1.1 christos {
706 1.1 christos /* Size of contents, or zero when contents should be filled by
707 1.1 christos the architecture-dependent fill function.
708 1.1 christos A non-zero value allows filling of the output section
709 1.1 christos with an arbitrary repeated pattern. */
710 1.1 christos unsigned int size;
711 1.1 christos /* Data to put into file. */
712 1.1 christos bfd_byte *contents;
713 1.1 christos } data;
714 1.1 christos struct
715 1.1 christos {
716 1.1 christos /* Description of reloc to generate. Used for
717 1.1 christos bfd_section_reloc_link_order and
718 1.1 christos bfd_symbol_reloc_link_order. */
719 1.1 christos struct bfd_link_order_reloc *p;
720 1.1 christos } reloc;
721 1.1 christos } u;
722 1.1 christos };
723 1.1 christos
724 1.1 christos /* A linker order of type bfd_section_reloc_link_order or
725 1.1 christos bfd_symbol_reloc_link_order means to create a reloc against a
726 1.1 christos section or symbol, respectively. This is used to implement -Ur to
727 1.1 christos generate relocs for the constructor tables. The
728 1.1 christos bfd_link_order_reloc structure describes the reloc that BFD should
729 1.1 christos create. It is similar to a arelent, but I didn't use arelent
730 1.1 christos because the linker does not know anything about most symbols, and
731 1.1 christos any asymbol structure it creates will be partially meaningless.
732 1.1 christos This information could logically be in the bfd_link_order struct,
733 1.1 christos but I didn't want to waste the space since these types of relocs
734 1.1 christos are relatively rare. */
735 1.1 christos
736 1.1 christos struct bfd_link_order_reloc
737 1.1 christos {
738 1.1 christos /* Reloc type. */
739 1.1 christos bfd_reloc_code_real_type reloc;
740 1.1 christos
741 1.1 christos union
742 1.1 christos {
743 1.1 christos /* For type bfd_section_reloc_link_order, this is the section
744 1.1 christos the reloc should be against. This must be a section in the
745 1.1 christos output BFD, not any of the input BFDs. */
746 1.1 christos asection *section;
747 1.1 christos /* For type bfd_symbol_reloc_link_order, this is the name of the
748 1.1 christos symbol the reloc should be against. */
749 1.1 christos const char *name;
750 1.1 christos } u;
751 1.1 christos
752 1.1 christos /* Addend to use. The object file should contain zero. The BFD
753 1.1 christos backend is responsible for filling in the contents of the object
754 1.1 christos file correctly. For some object file formats (e.g., COFF) the
755 1.1 christos addend must be stored into in the object file, and for some
756 1.1 christos (e.g., SPARC a.out) it is kept in the reloc. */
757 1.1 christos bfd_vma addend;
758 1.1 christos };
759 1.1 christos
760 1.1 christos /* Allocate a new link_order for a section. */
761 1.1 christos extern struct bfd_link_order *bfd_new_link_order (bfd *, asection *);
762 1.1 christos
763 1.1 christos /* These structures are used to describe version information for the
764 1.1 christos ELF linker. These structures could be manipulated entirely inside
765 1.1 christos BFD, but it would be a pain. Instead, the regular linker sets up
766 1.1 christos these structures, and then passes them into BFD. */
767 1.1 christos
768 1.1 christos /* Glob pattern for a version. */
769 1.1 christos
770 1.1 christos struct bfd_elf_version_expr
771 1.1 christos {
772 1.1 christos /* Next glob pattern for this version. */
773 1.1 christos struct bfd_elf_version_expr *next;
774 1.1 christos /* Glob pattern. */
775 1.1 christos const char *pattern;
776 1.1 christos /* Set if pattern is not a glob. */
777 1.1 christos unsigned int literal : 1;
778 1.1 christos /* Defined by ".symver". */
779 1.1 christos unsigned int symver : 1;
780 1.1 christos /* Defined by version script. */
781 1.1 christos unsigned int script : 1;
782 1.1 christos /* Pattern type. */
783 1.1 christos #define BFD_ELF_VERSION_C_TYPE 1
784 1.1 christos #define BFD_ELF_VERSION_CXX_TYPE 2
785 1.1 christos #define BFD_ELF_VERSION_JAVA_TYPE 4
786 1.1 christos unsigned int mask : 3;
787 1.1 christos };
788 1.1 christos
789 1.1 christos struct bfd_elf_version_expr_head
790 1.1 christos {
791 1.1 christos /* List of all patterns, both wildcards and non-wildcards. */
792 1.1 christos struct bfd_elf_version_expr *list;
793 1.1 christos /* Hash table for non-wildcards. */
794 1.1 christos void *htab;
795 1.1 christos /* Remaining patterns. */
796 1.1 christos struct bfd_elf_version_expr *remaining;
797 1.1 christos /* What kind of pattern types are present in list (bitmask). */
798 1.1 christos unsigned int mask;
799 1.1 christos };
800 1.1 christos
801 1.1 christos /* Version dependencies. */
802 1.1 christos
803 1.1 christos struct bfd_elf_version_deps
804 1.1 christos {
805 1.1 christos /* Next dependency for this version. */
806 1.1 christos struct bfd_elf_version_deps *next;
807 1.1 christos /* The version which this version depends upon. */
808 1.1 christos struct bfd_elf_version_tree *version_needed;
809 1.1 christos };
810 1.1 christos
811 1.1 christos /* A node in the version tree. */
812 1.1 christos
813 1.1 christos struct bfd_elf_version_tree
814 1.1 christos {
815 1.1 christos /* Next version. */
816 1.1 christos struct bfd_elf_version_tree *next;
817 1.1 christos /* Name of this version. */
818 1.1 christos const char *name;
819 1.1 christos /* Version number. */
820 1.1 christos unsigned int vernum;
821 1.1 christos /* Regular expressions for global symbols in this version. */
822 1.1 christos struct bfd_elf_version_expr_head globals;
823 1.1 christos /* Regular expressions for local symbols in this version. */
824 1.1 christos struct bfd_elf_version_expr_head locals;
825 1.1 christos /* List of versions which this version depends upon. */
826 1.1 christos struct bfd_elf_version_deps *deps;
827 1.1 christos /* Index of the version name. This is used within BFD. */
828 1.1 christos unsigned int name_indx;
829 1.1 christos /* Whether this version tree was used. This is used within BFD. */
830 1.1 christos int used;
831 1.1 christos /* Matching hook. */
832 1.1 christos struct bfd_elf_version_expr *(*match)
833 1.1 christos (struct bfd_elf_version_expr_head *head,
834 1.1 christos struct bfd_elf_version_expr *prev, const char *sym);
835 1.1 christos };
836 1.1 christos
837 1.1 christos struct bfd_elf_dynamic_list
838 1.1 christos {
839 1.1 christos struct bfd_elf_version_expr_head head;
840 1.1 christos struct bfd_elf_version_expr *(*match)
841 1.1 christos (struct bfd_elf_version_expr_head *head,
842 1.1 christos struct bfd_elf_version_expr *prev, const char *sym);
843 };
844
845 #endif
846