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