New Serbian translations for various binutils sub-directories.
[binutils-gdb.git] / ld / ldlang.h
blobb853cdbd45f406e540a42786912df8e9a17396f9
1 /* ldlang.h - linker command language support
2 Copyright (C) 1991-2022 Free Software Foundation, Inc.
4 This file is part of the GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
21 #ifndef LDLANG_H
22 #define LDLANG_H
24 #define DEFAULT_MEMORY_REGION "*default*"
26 #define SECTION_NAME_MAP_LENGTH (16)
28 typedef enum
30 lang_input_file_is_l_enum,
31 lang_input_file_is_symbols_only_enum,
32 lang_input_file_is_marker_enum,
33 lang_input_file_is_fake_enum,
34 lang_input_file_is_search_file_enum,
35 lang_input_file_is_file_enum
36 } lang_input_file_enum_type;
38 struct _fill_type
40 size_t size;
41 unsigned char data[1];
44 typedef struct statement_list
46 union lang_statement_union * head;
47 union lang_statement_union ** tail;
48 } lang_statement_list_type;
50 typedef struct memory_region_name_struct
52 const char * name;
53 struct memory_region_name_struct * next;
54 } lang_memory_region_name;
56 typedef struct memory_region_struct
58 lang_memory_region_name name_list;
59 struct memory_region_struct *next;
60 union etree_union *origin_exp;
61 bfd_vma origin;
62 bfd_size_type length;
63 union etree_union *length_exp;
64 bfd_vma current;
65 union lang_statement_union *last_os;
66 flagword flags;
67 flagword not_flags;
68 bool had_full_message;
69 } lang_memory_region_type;
71 enum statement_enum
73 lang_address_statement_enum,
74 lang_assignment_statement_enum,
75 lang_data_statement_enum,
76 lang_fill_statement_enum,
77 lang_group_statement_enum,
78 lang_input_section_enum,
79 lang_input_statement_enum,
80 lang_insert_statement_enum,
81 lang_output_section_statement_enum,
82 lang_output_statement_enum,
83 lang_padding_statement_enum,
84 lang_reloc_statement_enum,
85 lang_target_statement_enum,
86 lang_wild_statement_enum,
87 lang_constructors_statement_enum,
88 lang_object_symbols_statement_enum
91 typedef struct lang_statement_header_struct
93 /* Next pointer for statement_list statement list. */
94 union lang_statement_union *next;
95 enum statement_enum type;
96 } lang_statement_header_type;
98 typedef struct
100 lang_statement_header_type header;
101 union etree_union *exp;
102 } lang_assignment_statement_type;
104 typedef struct lang_target_statement_struct
106 lang_statement_header_type header;
107 const char *target;
108 } lang_target_statement_type;
110 typedef struct lang_output_statement_struct
112 lang_statement_header_type header;
113 const char *name;
114 } lang_output_statement_type;
116 /* Section types specified in a linker script. */
118 enum section_type
120 normal_section,
121 first_overlay_section,
122 overlay_section,
123 noload_section,
124 noalloc_section,
125 type_section,
126 readonly_section,
127 typed_readonly_section
130 /* This structure holds a list of program headers describing
131 segments in which this section should be placed. */
133 typedef struct lang_output_section_phdr_list
135 struct lang_output_section_phdr_list *next;
136 const char *name;
137 bool used;
138 } lang_output_section_phdr_list;
140 typedef struct lang_output_section_statement_struct
142 lang_statement_header_type header;
143 lang_statement_list_type children;
144 struct lang_output_section_statement_struct *next;
145 struct lang_output_section_statement_struct *prev;
146 const char *name;
147 asection *bfd_section;
148 lang_memory_region_type *region;
149 lang_memory_region_type *lma_region;
150 fill_type *fill;
151 union etree_union *addr_tree;
152 union etree_union *load_base;
153 union etree_union *section_alignment;
154 union etree_union *subsection_alignment;
156 /* If non-null, an expression to evaluate after setting the section's
157 size. The expression is evaluated inside REGION (above) with '.'
158 set to the end of the section. Used in the last overlay section
159 to move '.' past all the overlaid sections. */
160 union etree_union *update_dot_tree;
162 lang_output_section_phdr_list *phdrs;
164 /* Used by ELF SHF_LINK_ORDER sorting. */
165 void *data;
167 unsigned int block_value;
168 int constraint;
169 flagword flags;
170 enum section_type sectype;
171 etree_type *sectype_value;
172 unsigned int processed_vma : 1;
173 unsigned int processed_lma : 1;
174 unsigned int all_input_readonly : 1;
175 /* If this section should be ignored. */
176 unsigned int ignored : 1;
177 /* If this section should update "dot". Prevents section being ignored. */
178 unsigned int update_dot : 1;
179 /* If this section is after assignment to _end. */
180 unsigned int after_end : 1;
181 /* If this section uses the alignment of its input sections. */
182 unsigned int align_lma_with_input : 1;
183 /* If script has duplicate output section statements of the same name
184 create duplicate output sections. */
185 unsigned int dup_output : 1;
186 } lang_output_section_statement_type;
188 typedef struct
190 lang_statement_header_type header;
191 fill_type *fill;
192 int size;
193 asection *output_section;
194 } lang_fill_statement_type;
196 typedef struct
198 lang_statement_header_type header;
199 unsigned int type;
200 union etree_union *exp;
201 bfd_vma value;
202 asection *output_section;
203 bfd_vma output_offset;
204 } lang_data_statement_type;
206 /* Generate a reloc in the output file. */
208 typedef struct
210 lang_statement_header_type header;
212 /* Reloc to generate. */
213 bfd_reloc_code_real_type reloc;
215 /* Reloc howto structure. */
216 reloc_howto_type *howto;
218 /* Section to generate reloc against.
219 Exactly one of section and name must be NULL. */
220 asection *section;
222 /* Name of symbol to generate reloc against.
223 Exactly one of section and name must be NULL. */
224 const char *name;
226 /* Expression for addend. */
227 union etree_union *addend_exp;
229 /* Resolved addend. */
230 bfd_vma addend_value;
232 /* Output section where reloc should be performed. */
233 asection *output_section;
235 /* Offset within output section. */
236 bfd_vma output_offset;
237 } lang_reloc_statement_type;
239 struct lang_input_statement_flags
241 /* 1 means this file was specified in a -l option. */
242 unsigned int maybe_archive : 1;
244 /* 1 means this file was specified in a -l:namespec option. */
245 unsigned int full_name_provided : 1;
247 /* 1 means search a set of directories for this file. */
248 unsigned int search_dirs : 1;
250 /* 1 means this was found when processing a script in the sysroot. */
251 unsigned int sysrooted : 1;
253 /* 1 means this is base file of incremental load.
254 Do not load this file's text or data.
255 Also default text_start to after this file's bss. */
256 unsigned int just_syms : 1;
258 /* Whether to search for this entry as a dynamic archive. */
259 unsigned int dynamic : 1;
261 /* Set if a DT_NEEDED tag should be added not just for the dynamic library
262 explicitly given by this entry but also for any dynamic libraries in
263 this entry's needed list. */
264 unsigned int add_DT_NEEDED_for_dynamic : 1;
266 /* Set if this entry should cause a DT_NEEDED tag only when some
267 regular file references its symbols (ie. --as-needed is in effect). */
268 unsigned int add_DT_NEEDED_for_regular : 1;
270 /* Whether to include the entire contents of an archive. */
271 unsigned int whole_archive : 1;
273 /* Set when bfd opening is successful. */
274 unsigned int loaded : 1;
276 unsigned int real : 1;
278 /* Set if the file does not exist. */
279 unsigned int missing_file : 1;
281 /* Set if reloading an archive or --as-needed lib. */
282 unsigned int reload : 1;
284 #if BFD_SUPPORTS_PLUGINS
285 /* Set if the file was claimed by a plugin. */
286 unsigned int claimed : 1;
288 /* Set if the file was claimed from an archive. */
289 unsigned int claim_archive : 1;
291 /* Set if added by the lto plugin add_input_file callback. */
292 unsigned int lto_output : 1;
293 #endif /* BFD_SUPPORTS_PLUGINS */
295 /* Head of list of pushed flags. */
296 struct lang_input_statement_flags *pushed;
299 typedef struct lang_input_statement_struct
301 lang_statement_header_type header;
302 /* Name of this file. */
303 const char *filename;
304 /* Name to use for the symbol giving address of text start.
305 Usually the same as filename, but for a file spec'd with
306 -l this is the -l switch itself rather than the filename. */
307 const char *local_sym_name;
308 /* Name to use when sorting. */
309 const char *sort_key;
310 /* Extra search path. Used to find a file relative to the
311 directory of the current linker script. */
312 const char *extra_search_path;
314 bfd *the_bfd;
316 ctf_archive_t *the_ctf;
318 struct flag_info *section_flag_list;
320 /* Next pointer for file_chain statement list. */
321 struct lang_input_statement_struct *next;
323 /* Next pointer for input_file_chain statement list. */
324 struct lang_input_statement_struct *next_real_file;
326 const char *target;
328 struct lang_input_statement_flags flags;
329 } lang_input_statement_type;
331 typedef struct
333 lang_statement_header_type header;
334 asection *section;
335 void *pattern;
336 } lang_input_section_type;
338 struct map_symbol_def {
339 struct bfd_link_hash_entry *entry;
340 struct map_symbol_def *next;
343 /* For input sections, when writing a map file: head / tail of a linked
344 list of hash table entries for symbols defined in this section. */
345 typedef struct input_section_userdata_struct
347 struct map_symbol_def *map_symbol_def_head;
348 struct map_symbol_def **map_symbol_def_tail;
349 unsigned long map_symbol_def_count;
350 } input_section_userdata_type;
352 static inline bool
353 bfd_input_just_syms (const bfd *abfd)
355 lang_input_statement_type *is = bfd_usrdata (abfd);
356 return is != NULL && is->flags.just_syms;
359 typedef struct lang_wild_statement_struct lang_wild_statement_type;
361 typedef void (*callback_t) (lang_wild_statement_type *, struct wildcard_list *,
362 asection *, lang_input_statement_type *, void *);
364 typedef void (*walk_wild_section_handler_t) (lang_wild_statement_type *,
365 lang_input_statement_type *,
366 callback_t callback,
367 void *data);
369 typedef bool (*lang_match_sec_type_func) (bfd *, const asection *,
370 bfd *, const asection *);
372 /* Binary search tree structure to efficiently sort sections by
373 name. */
374 typedef struct lang_section_bst
376 asection *section;
377 void *pattern;
378 struct lang_section_bst *left;
379 struct lang_section_bst *right;
380 } lang_section_bst_type;
382 struct lang_wild_statement_struct
384 lang_statement_header_type header;
385 const char *filename;
386 bool filenames_sorted;
387 struct wildcard_list *section_list;
388 bool keep_sections;
389 lang_statement_list_type children;
390 struct name_list *exclude_name_list;
392 walk_wild_section_handler_t walk_wild_section_handler;
393 struct wildcard_list *handler_data[4];
394 lang_section_bst_type *tree;
395 struct flag_info *section_flag_list;
398 typedef struct lang_address_statement_struct
400 lang_statement_header_type header;
401 const char *section_name;
402 union etree_union *address;
403 const segment_type *segment;
404 } lang_address_statement_type;
406 typedef struct
408 lang_statement_header_type header;
409 bfd_vma output_offset;
410 bfd_size_type size;
411 asection *output_section;
412 fill_type *fill;
413 } lang_padding_statement_type;
415 /* A group statement collects a set of libraries together. The
416 libraries are searched multiple times, until no new undefined
417 symbols are found. The effect is to search a group of libraries as
418 though they were a single library. */
420 typedef struct
422 lang_statement_header_type header;
423 lang_statement_list_type children;
424 } lang_group_statement_type;
426 typedef struct
428 lang_statement_header_type header;
429 const char *where;
430 bool is_before;
431 } lang_insert_statement_type;
433 typedef union lang_statement_union
435 lang_statement_header_type header;
436 lang_address_statement_type address_statement;
437 lang_assignment_statement_type assignment_statement;
438 lang_data_statement_type data_statement;
439 lang_fill_statement_type fill_statement;
440 lang_group_statement_type group_statement;
441 lang_input_section_type input_section;
442 lang_input_statement_type input_statement;
443 lang_insert_statement_type insert_statement;
444 lang_output_section_statement_type output_section_statement;
445 lang_output_statement_type output_statement;
446 lang_padding_statement_type padding_statement;
447 lang_reloc_statement_type reloc_statement;
448 lang_target_statement_type target_statement;
449 lang_wild_statement_type wild_statement;
450 } lang_statement_union_type;
452 /* This structure holds information about a program header, from the
453 PHDRS command in the linker script. */
455 struct lang_phdr
457 struct lang_phdr *next;
458 const char *name;
459 unsigned long type;
460 bool filehdr;
461 bool phdrs;
462 etree_type *at;
463 etree_type *flags;
466 /* This structure is used to hold a list of sections which may not
467 cross reference each other. */
469 typedef struct lang_nocrossref
471 struct lang_nocrossref *next;
472 const char *name;
473 } lang_nocrossref_type;
475 /* The list of nocrossref lists. */
477 struct lang_nocrossrefs
479 struct lang_nocrossrefs *next;
480 lang_nocrossref_type *list;
481 bool onlyfirst;
484 /* This structure is used to hold a list of input section names which
485 will not match an output section in the linker script. */
487 struct unique_sections
489 struct unique_sections *next;
490 const char *name;
493 /* Used by place_orphan to keep track of orphan sections and statements. */
495 struct orphan_save
497 const char *name;
498 flagword flags;
499 lang_output_section_statement_type *os;
500 asection **section;
501 lang_statement_union_type **stmt;
502 lang_output_section_statement_type **os_tail;
505 struct asneeded_minfo
507 struct asneeded_minfo *next;
508 const char *soname;
509 bfd *ref;
510 const char *name;
513 extern struct lang_phdr *lang_phdr_list;
514 extern struct lang_nocrossrefs *nocrossref_list;
515 extern const char *output_target;
516 extern lang_output_section_statement_type *abs_output_section;
517 extern lang_statement_list_type lang_os_list;
518 extern struct lang_input_statement_flags input_flags;
519 extern bool lang_has_input_file;
520 extern lang_statement_list_type statement_list;
521 extern lang_statement_list_type *stat_ptr;
522 extern bool delete_output_file_on_failure;
524 extern struct bfd_sym_chain entry_symbol;
525 extern const char *entry_section;
526 extern bool entry_from_cmdline;
527 extern lang_statement_list_type file_chain;
528 extern lang_statement_list_type input_file_chain;
530 extern struct bfd_elf_dynamic_list **current_dynamic_list_p;
532 extern int lang_statement_iteration;
533 extern struct asneeded_minfo **asneeded_list_tail;
535 extern void (*output_bfd_hash_table_free_fn) (struct bfd_link_hash_table *);
537 extern void lang_init
538 (void);
539 extern void lang_finish
540 (void);
541 extern lang_memory_region_type * lang_memory_region_lookup
542 (const char * const, bool);
543 extern void lang_memory_region_alias
544 (const char *, const char *);
545 extern void lang_map
546 (void);
547 extern void lang_set_flags
548 (lang_memory_region_type *, const char *, int);
549 extern void lang_add_output
550 (const char *, int from_script);
551 extern lang_output_section_statement_type *lang_enter_output_section_statement
552 (const char *, etree_type *, enum section_type, etree_type *, etree_type *,
553 etree_type *, etree_type *, int, int);
554 extern void lang_final
555 (void);
556 extern void lang_relax_sections
557 (bool);
558 extern void lang_process
559 (void);
560 extern void lang_section_start
561 (const char *, union etree_union *, const segment_type *);
562 extern void lang_add_entry
563 (const char *, bool);
564 extern void lang_default_entry
565 (const char *);
566 extern void lang_add_target
567 (const char *);
568 extern void lang_add_wild
569 (struct wildcard_spec *, struct wildcard_list *, bool);
570 extern void lang_add_map
571 (const char *);
572 extern void lang_add_fill
573 (fill_type *);
574 extern lang_assignment_statement_type *lang_add_assignment
575 (union etree_union *);
576 extern void lang_add_attribute
577 (enum statement_enum);
578 extern void lang_startup
579 (const char *);
580 extern void lang_float
581 (bool);
582 extern void lang_leave_output_section_statement
583 (fill_type *, const char *, lang_output_section_phdr_list *,
584 const char *);
585 extern void lang_for_each_input_file
586 (void (*dothis) (lang_input_statement_type *));
587 extern void lang_for_each_file
588 (void (*dothis) (lang_input_statement_type *));
589 extern void lang_reset_memory_regions
590 (void);
591 extern void lang_do_assignments
592 (lang_phase_type);
593 extern asection *section_for_dot
594 (void);
596 #define LANG_FOR_EACH_INPUT_STATEMENT(statement) \
597 lang_input_statement_type *statement; \
598 for (statement = (lang_input_statement_type *) file_chain.head; \
599 statement != NULL; \
600 statement = statement->next)
602 #define lang_output_section_find(NAME) \
603 lang_output_section_statement_lookup (NAME, 0, 0)
605 extern void lang_process
606 (void);
607 extern void ldlang_add_file
608 (lang_input_statement_type *);
609 extern lang_output_section_statement_type *lang_output_section_find_by_flags
610 (const asection *, flagword, lang_output_section_statement_type **,
611 lang_match_sec_type_func);
612 extern lang_output_section_statement_type *lang_insert_orphan
613 (asection *, const char *, int, lang_output_section_statement_type *,
614 struct orphan_save *, etree_type *, lang_statement_list_type *);
615 extern lang_input_statement_type *lang_add_input_file
616 (const char *, lang_input_file_enum_type, const char *);
617 extern void lang_add_keepsyms_file
618 (const char *);
619 extern lang_output_section_statement_type *lang_output_section_get
620 (const asection *);
621 extern lang_output_section_statement_type *lang_output_section_statement_lookup
622 (const char *, int, int);
623 extern lang_output_section_statement_type *next_matching_output_section_statement
624 (lang_output_section_statement_type *, int);
625 extern void ldlang_add_undef
626 (const char *const, bool);
627 extern void ldlang_add_require_defined
628 (const char *const);
629 extern void lang_add_output_format
630 (const char *, const char *, const char *, int);
631 extern void lang_list_init
632 (lang_statement_list_type *);
633 extern void push_stat_ptr
634 (lang_statement_list_type *);
635 extern void pop_stat_ptr
636 (void);
637 extern void lang_add_data
638 (int type, union etree_union *);
639 extern void lang_add_reloc
640 (bfd_reloc_code_real_type, reloc_howto_type *, asection *, const char *,
641 union etree_union *);
642 extern void lang_for_each_statement
643 (void (*) (lang_statement_union_type *));
644 extern void lang_for_each_statement_worker
645 (void (*) (lang_statement_union_type *), lang_statement_union_type *);
646 extern void *stat_alloc
647 (size_t);
648 extern void strip_excluded_output_sections
649 (void);
650 extern void lang_clear_os_map
651 (void);
652 extern void dprint_statement
653 (lang_statement_union_type *, int);
654 extern void lang_size_sections
655 (bool *, bool);
656 extern void one_lang_size_sections_pass
657 (bool *, bool);
658 extern void lang_add_insert
659 (const char *, int);
660 extern void lang_enter_group
661 (void);
662 extern void lang_leave_group
663 (void);
664 extern void lang_add_section
665 (lang_statement_list_type *, asection *, struct wildcard_list *,
666 struct flag_info *, lang_output_section_statement_type *);
667 extern void lang_new_phdr
668 (const char *, etree_type *, bool, bool, etree_type *,
669 etree_type *);
670 extern void lang_add_nocrossref
671 (lang_nocrossref_type *);
672 extern void lang_add_nocrossref_to
673 (lang_nocrossref_type *);
674 extern void lang_enter_overlay
675 (etree_type *, etree_type *);
676 extern void lang_enter_overlay_section
677 (const char *);
678 extern void lang_leave_overlay_section
679 (fill_type *, lang_output_section_phdr_list *);
680 extern void lang_leave_overlay
681 (etree_type *, int, fill_type *, const char *,
682 lang_output_section_phdr_list *, const char *);
684 extern struct bfd_elf_version_expr *lang_new_vers_pattern
685 (struct bfd_elf_version_expr *, const char *, const char *, bool);
686 extern struct bfd_elf_version_tree *lang_new_vers_node
687 (struct bfd_elf_version_expr *, struct bfd_elf_version_expr *);
688 extern struct bfd_elf_version_deps *lang_add_vers_depend
689 (struct bfd_elf_version_deps *, const char *);
690 extern void lang_register_vers_node
691 (const char *, struct bfd_elf_version_tree *, struct bfd_elf_version_deps *);
692 extern void lang_append_dynamic_list (struct bfd_elf_dynamic_list **,
693 struct bfd_elf_version_expr *);
694 extern void lang_append_dynamic_list_cpp_typeinfo (void);
695 extern void lang_append_dynamic_list_cpp_new (void);
696 extern void lang_add_unique
697 (const char *);
698 extern const char *lang_get_output_target
699 (void);
700 extern void add_excluded_libs (const char *);
701 extern bool load_symbols
702 (lang_input_statement_type *, lang_statement_list_type *);
704 struct elf_sym_strtab;
705 struct elf_strtab_hash;
706 extern void ldlang_ctf_acquire_strings
707 (struct elf_strtab_hash *);
708 extern void ldlang_ctf_new_dynsym
709 (int symidx, struct elf_internal_sym *);
710 extern void ldlang_write_ctf_late
711 (void);
712 extern bool
713 ldlang_override_segment_assignment
714 (struct bfd_link_info *, bfd *, asection *, asection *, bool);
716 extern void
717 lang_ld_feature (char *);
719 extern void
720 lang_print_memory_usage (void);
722 extern void
723 lang_add_gc_name (const char *);
725 extern bool
726 print_one_symbol (struct bfd_link_hash_entry *hash_entry, void *ptr);
728 #endif