* cpu-powerpc.c (powerpc_compatible): Any ISA in the PowerPC
[binutils.git] / ld / ldlang.h
blob391ae9b6d7cf60b45b7da252d912e6f83d3fdd82
1 /* ldlang.h - linker command language support
2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003
4 Free Software Foundation, Inc.
6 This file is part of GLD, the Gnu Linker.
8 GLD is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
13 GLD is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GLD; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 02111-1307, USA. */
23 #ifndef LDLANG_H
24 #define LDLANG_H
26 #define DEFAULT_MEMORY_REGION "*default*"
28 typedef enum {
29 lang_input_file_is_l_enum,
30 lang_input_file_is_symbols_only_enum,
31 lang_input_file_is_marker_enum,
32 lang_input_file_is_fake_enum,
33 lang_input_file_is_search_file_enum,
34 lang_input_file_is_file_enum
35 } lang_input_file_enum_type;
37 struct _fill_type {
38 size_t size;
39 unsigned char data[1];
42 typedef struct statement_list {
43 union lang_statement_union *head;
44 union lang_statement_union **tail;
45 } lang_statement_list_type;
47 typedef struct memory_region_struct {
48 char *name;
49 struct memory_region_struct *next;
50 bfd_vma origin;
51 bfd_size_type length;
52 bfd_vma current;
53 bfd_size_type old_length;
54 flagword flags;
55 flagword not_flags;
56 bfd_boolean had_full_message;
57 } lang_memory_region_type;
59 typedef struct lang_statement_header_struct {
60 union lang_statement_union *next;
61 enum statement_enum {
62 lang_output_section_statement_enum,
63 lang_assignment_statement_enum,
64 lang_input_statement_enum,
65 lang_address_statement_enum,
66 lang_wild_statement_enum,
67 lang_input_section_enum,
68 lang_object_symbols_statement_enum,
69 lang_fill_statement_enum,
70 lang_data_statement_enum,
71 lang_reloc_statement_enum,
72 lang_target_statement_enum,
73 lang_output_statement_enum,
74 lang_padding_statement_enum,
75 lang_group_statement_enum,
77 lang_afile_asection_pair_statement_enum,
78 lang_constructors_statement_enum
79 } type;
80 } lang_statement_header_type;
82 typedef struct {
83 lang_statement_header_type header;
84 union etree_union *exp;
85 } lang_assignment_statement_type;
87 typedef struct lang_target_statement_struct {
88 lang_statement_header_type header;
89 const char *target;
90 } lang_target_statement_type;
92 typedef struct lang_output_statement_struct {
93 lang_statement_header_type header;
94 const char *name;
95 } lang_output_statement_type;
97 /* Section types specified in a linker script. */
99 enum section_type {
100 normal_section,
101 dsect_section,
102 copy_section,
103 noload_section,
104 info_section,
105 overlay_section
108 /* This structure holds a list of program headers describing segments
109 in which this section should be placed. */
111 struct lang_output_section_phdr_list {
112 struct lang_output_section_phdr_list *next;
113 const char *name;
114 bfd_boolean used;
117 typedef struct lang_output_section_statement_struct {
118 lang_statement_header_type header;
119 union etree_union *addr_tree;
120 lang_statement_list_type children;
121 const char *memspec;
122 union lang_statement_union *next;
123 const char *name;
125 bfd_boolean processed;
127 asection *bfd_section;
128 flagword flags; /* Or together of all input sections */
129 enum section_type sectype;
130 struct memory_region_struct *region;
131 struct memory_region_struct *lma_region;
132 size_t block_value;
133 fill_type *fill;
135 int subsection_alignment; /* alignment of components */
136 int section_alignment; /* alignment of start of section */
138 union etree_union *load_base;
140 /* If non-null, an expression to evaluate after setting the section's
141 size. The expression is evaluated inside REGION (above) with '.'
142 set to the end of the section. Used in the last overlay section
143 to move '.' past all the overlaid sections. */
144 union etree_union *update_dot_tree;
146 struct lang_output_section_phdr_list *phdrs;
147 } lang_output_section_statement_type;
149 typedef struct {
150 lang_statement_header_type header;
151 } lang_common_statement_type;
153 typedef struct {
154 lang_statement_header_type header;
155 } lang_object_symbols_statement_type;
157 typedef struct {
158 lang_statement_header_type header;
159 fill_type *fill;
160 int size;
161 asection *output_section;
162 } lang_fill_statement_type;
164 typedef struct {
165 lang_statement_header_type header;
166 unsigned int type;
167 union etree_union *exp;
168 bfd_vma value;
169 asection *output_section;
170 bfd_vma output_vma;
171 } lang_data_statement_type;
173 /* Generate a reloc in the output file. */
175 typedef struct {
176 lang_statement_header_type header;
178 /* Reloc to generate. */
179 bfd_reloc_code_real_type reloc;
181 /* Reloc howto structure. */
182 reloc_howto_type *howto;
184 /* Section to generate reloc against. Exactly one of section and
185 name must be NULL. */
186 asection *section;
188 /* Name of symbol to generate reloc against. Exactly one of section
189 and name must be NULL. */
190 const char *name;
192 /* Expression for addend. */
193 union etree_union *addend_exp;
195 /* Resolved addend. */
196 bfd_vma addend_value;
198 /* Output section where reloc should be performed. */
199 asection *output_section;
201 /* VMA within output section. */
202 bfd_vma output_vma;
203 } lang_reloc_statement_type;
205 typedef struct lang_input_statement_struct {
206 lang_statement_header_type header;
207 /* Name of this file. */
208 const char *filename;
209 /* Name to use for the symbol giving address of text start */
210 /* Usually the same as filename, but for a file spec'd with -l
211 this is the -l switch itself rather than the filename. */
212 const char *local_sym_name;
214 bfd *the_bfd;
216 bfd_boolean closed;
217 file_ptr passive_position;
219 /* Symbol table of the file. */
220 asymbol **asymbols;
221 unsigned int symbol_count;
223 /* Point to the next file - whatever it is, wanders up and down
224 archives */
226 union lang_statement_union *next;
227 /* Point to the next file, but skips archive contents */
228 union lang_statement_union *next_real_file;
230 bfd_boolean is_archive;
232 /* 1 means search a set of directories for this file. */
233 bfd_boolean search_dirs_flag;
235 /* 1 means this was found in a search directory marked as sysrooted,
236 if search_dirs_flag is false, otherwise, that it should be
237 searched in ld_sysroot before any other location, as long as it
238 starts with a slash. */
239 bfd_boolean sysrooted;
241 /* 1 means this is base file of incremental load.
242 Do not load this file's text or data.
243 Also default text_start to after this file's bss. */
245 bfd_boolean just_syms_flag;
247 /* Whether to search for this entry as a dynamic archive. */
248 bfd_boolean dynamic;
250 /* Whether to include the entire contents of an archive. */
251 bfd_boolean whole_archive;
253 bfd_boolean loaded;
255 #if 0
256 unsigned int globals_in_this_file;
257 #endif
258 const char *target;
259 bfd_boolean real;
260 } lang_input_statement_type;
262 typedef struct {
263 lang_statement_header_type header;
264 asection *section;
265 lang_input_statement_type *ifile;
267 } lang_input_section_type;
269 typedef struct {
270 lang_statement_header_type header;
271 asection *section;
272 union lang_statement_union *file;
273 } lang_afile_asection_pair_statement_type;
275 typedef struct lang_wild_statement_struct {
276 lang_statement_header_type header;
277 const char *filename;
278 bfd_boolean filenames_sorted;
279 struct wildcard_list *section_list;
280 bfd_boolean keep_sections;
281 lang_statement_list_type children;
282 } lang_wild_statement_type;
284 typedef struct lang_address_statement_struct {
285 lang_statement_header_type header;
286 const char *section_name;
287 union etree_union *address;
288 } lang_address_statement_type;
290 typedef struct {
291 lang_statement_header_type header;
292 bfd_vma output_offset;
293 size_t size;
294 asection *output_section;
295 fill_type *fill;
296 } lang_padding_statement_type;
298 /* A group statement collects a set of libraries together. The
299 libraries are searched multiple times, until no new undefined
300 symbols are found. The effect is to search a group of libraries as
301 though they were a single library. */
303 typedef struct {
304 lang_statement_header_type header;
305 lang_statement_list_type children;
306 } lang_group_statement_type;
308 typedef union lang_statement_union {
309 lang_statement_header_type header;
310 lang_wild_statement_type wild_statement;
311 lang_data_statement_type data_statement;
312 lang_reloc_statement_type reloc_statement;
313 lang_address_statement_type address_statement;
314 lang_output_section_statement_type output_section_statement;
315 lang_afile_asection_pair_statement_type afile_asection_pair_statement;
316 lang_assignment_statement_type assignment_statement;
317 lang_input_statement_type input_statement;
318 lang_target_statement_type target_statement;
319 lang_output_statement_type output_statement;
320 lang_input_section_type input_section;
321 lang_common_statement_type common_statement;
322 lang_object_symbols_statement_type object_symbols_statement;
323 lang_fill_statement_type fill_statement;
324 lang_padding_statement_type padding_statement;
325 lang_group_statement_type group_statement;
326 } lang_statement_union_type;
328 /* This structure holds information about a program header, from the
329 PHDRS command in the linker script. */
331 struct lang_phdr {
332 struct lang_phdr *next;
333 const char *name;
334 unsigned long type;
335 bfd_boolean filehdr;
336 bfd_boolean phdrs;
337 etree_type *at;
338 etree_type *flags;
341 /* This structure is used to hold a list of sections which may not
342 cross reference each other. */
344 struct lang_nocrossref {
345 struct lang_nocrossref *next;
346 const char *name;
349 /* The list of nocrossref lists. */
351 struct lang_nocrossrefs {
352 struct lang_nocrossrefs *next;
353 struct lang_nocrossref *list;
356 extern struct lang_nocrossrefs *nocrossref_list;
358 /* This structure is used to hold a list of input section names which
359 will not match an output section in the linker script. */
361 struct unique_sections {
362 struct unique_sections *next;
363 const char *name;
366 /* This structure records symbols for which we need to keep track of
367 definedness for use in the DEFINED () test. */
369 struct lang_definedness_hash_entry {
370 struct bfd_hash_entry root;
371 int iteration;
374 extern struct unique_sections *unique_section_list;
376 extern lang_output_section_statement_type *abs_output_section;
377 extern lang_statement_list_type lang_output_section_statement;
378 extern bfd_boolean lang_has_input_file;
379 extern etree_type *base;
380 extern lang_statement_list_type *stat_ptr;
381 extern bfd_boolean delete_output_file_on_failure;
383 extern struct bfd_sym_chain entry_symbol;
384 extern const char *entry_section;
385 extern bfd_boolean entry_from_cmdline;
386 extern lang_statement_list_type file_chain;
388 extern int lang_statement_iteration;
390 extern void lang_init
391 (void);
392 extern struct memory_region_struct *lang_memory_region_lookup
393 (const char *const, bfd_boolean);
394 extern struct memory_region_struct *lang_memory_region_default
395 (asection *);
396 extern void lang_map
397 (void);
398 extern void lang_set_flags
399 (lang_memory_region_type *, const char *, int);
400 extern void lang_add_output
401 (const char *, int from_script);
402 extern lang_output_section_statement_type *lang_enter_output_section_statement
403 (const char *output_section_statement_name,
404 etree_type *address_exp,
405 enum section_type sectype,
406 bfd_vma block_value,
407 etree_type *align,
408 etree_type *subalign,
409 etree_type *);
410 extern void lang_final
411 (void);
412 extern void lang_process
413 (void);
414 extern void lang_section_start
415 (const char *, union etree_union *);
416 extern void lang_add_entry
417 (const char *, bfd_boolean);
418 extern void lang_add_target
419 (const char *);
420 extern void lang_add_wild
421 (struct wildcard_spec *, struct wildcard_list *, bfd_boolean);
422 extern void lang_add_map
423 (const char *);
424 extern void lang_add_fill
425 (fill_type *);
426 extern lang_assignment_statement_type *lang_add_assignment
427 (union etree_union *);
428 extern void lang_add_attribute
429 (enum statement_enum);
430 extern void lang_startup
431 (const char *);
432 extern void lang_float
433 (bfd_boolean);
434 extern void lang_leave_output_section_statement
435 (fill_type *, const char *, struct lang_output_section_phdr_list *,
436 const char *);
437 extern void lang_abs_symbol_at_end_of
438 (const char *, const char *);
439 extern void lang_abs_symbol_at_beginning_of
440 (const char *, const char *);
441 extern void lang_statement_append
442 (struct statement_list *, union lang_statement_union *,
443 union lang_statement_union **);
444 extern void lang_for_each_input_file
445 (void (*dothis) (lang_input_statement_type *));
446 extern void lang_for_each_file
447 (void (*dothis) (lang_input_statement_type *));
448 extern void lang_reset_memory_regions
449 (void);
450 extern bfd_vma lang_do_assignments
451 (lang_statement_union_type *, lang_output_section_statement_type *,
452 fill_type *, bfd_vma);
454 #define LANG_FOR_EACH_INPUT_STATEMENT(statement) \
455 lang_input_statement_type *statement; \
456 for (statement = (lang_input_statement_type *) file_chain.head; \
457 statement != (lang_input_statement_type *) NULL; \
458 statement = (lang_input_statement_type *) statement->next) \
460 extern void lang_process
461 (void);
462 extern void ldlang_add_file
463 (lang_input_statement_type *);
464 extern lang_output_section_statement_type *lang_output_section_find
465 (const char * const);
466 extern lang_input_statement_type *lang_add_input_file
467 (const char *, lang_input_file_enum_type, const char *);
468 extern void lang_add_keepsyms_file
469 (const char *);
470 extern lang_output_section_statement_type *
471 lang_output_section_statement_lookup
472 (const char *const);
473 extern void ldlang_add_undef
474 (const char *const);
475 extern void lang_add_output_format
476 (const char *, const char *, const char *, int);
477 extern void lang_list_init
478 (lang_statement_list_type *);
479 extern void lang_add_data
480 (int type, union etree_union *);
481 extern void lang_add_reloc
482 (bfd_reloc_code_real_type, reloc_howto_type *, asection *, const char *,
483 union etree_union *);
484 extern void lang_for_each_statement
485 (void (*) (lang_statement_union_type *));
486 extern void *stat_alloc
487 (size_t);
488 extern void dprint_statement
489 (lang_statement_union_type *, int);
490 extern bfd_vma lang_size_sections
491 (lang_statement_union_type *, lang_output_section_statement_type *,
492 lang_statement_union_type **, fill_type *, bfd_vma, bfd_boolean *,
493 bfd_boolean);
494 extern void lang_enter_group
495 (void);
496 extern void lang_leave_group
497 (void);
498 extern void lang_add_section
499 (lang_statement_list_type *, asection *,
500 lang_output_section_statement_type *, lang_input_statement_type *);
501 extern void lang_new_phdr
502 (const char *, etree_type *, bfd_boolean, bfd_boolean, etree_type *,
503 etree_type *);
504 extern void lang_add_nocrossref
505 (struct lang_nocrossref *);
506 extern void lang_enter_overlay
507 (etree_type *, etree_type *);
508 extern void lang_enter_overlay_section
509 (const char *);
510 extern void lang_leave_overlay_section
511 (fill_type *, struct lang_output_section_phdr_list *);
512 extern void lang_leave_overlay
513 (etree_type *, int, fill_type *, const char *,
514 struct lang_output_section_phdr_list *, const char *);
516 extern struct bfd_elf_version_tree *lang_elf_version_info;
518 extern struct bfd_elf_version_expr *lang_new_vers_pattern
519 (struct bfd_elf_version_expr *, const char *, const char *);
520 extern struct bfd_elf_version_tree *lang_new_vers_node
521 (struct bfd_elf_version_expr *, struct bfd_elf_version_expr *);
522 extern struct bfd_elf_version_deps *lang_add_vers_depend
523 (struct bfd_elf_version_deps *, const char *);
524 extern void lang_register_vers_node
525 (const char *, struct bfd_elf_version_tree *, struct bfd_elf_version_deps *);
526 bfd_boolean unique_section_p
527 (const char *);
528 extern void lang_add_unique
529 (const char *);
530 extern const char *lang_get_output_target
531 (void);
532 extern void lang_track_definedness (const char *);
533 extern int lang_symbol_definition_iteration (const char *);
534 extern void lang_update_definedness
535 (const char *, struct bfd_link_hash_entry *);
537 #endif