Update release readme after making 2.43.1 release
[binutils-gdb.git] / ld / ldlang.h
blobf36e04c586a1094f1b77769f4af787a950920474
1 /* ldlang.h - linker command language support
2 Copyright (C) 1991-2024 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_matcher_enum,
80 lang_input_statement_enum,
81 lang_insert_statement_enum,
82 lang_output_section_statement_enum,
83 lang_output_statement_enum,
84 lang_padding_statement_enum,
85 lang_reloc_statement_enum,
86 lang_target_statement_enum,
87 lang_wild_statement_enum,
88 lang_constructors_statement_enum,
89 lang_object_symbols_statement_enum
92 typedef struct lang_statement_header_struct
94 /* Next pointer for statement_list statement list. */
95 union lang_statement_union *next;
96 enum statement_enum type;
97 } lang_statement_header_type;
99 typedef struct
101 lang_statement_header_type header;
102 union etree_union *exp;
103 } lang_assignment_statement_type;
105 typedef struct lang_target_statement_struct
107 lang_statement_header_type header;
108 const char *target;
109 } lang_target_statement_type;
111 typedef struct lang_output_statement_struct
113 lang_statement_header_type header;
114 const char *name;
115 } lang_output_statement_type;
117 /* Section types specified in a linker script. */
119 enum section_type
121 normal_section,
122 first_overlay_section,
123 overlay_section,
124 noload_section,
125 noalloc_section,
126 type_section,
127 readonly_section,
128 typed_readonly_section
131 /* This structure holds a list of program headers describing
132 segments in which this section should be placed. */
134 typedef struct lang_output_section_phdr_list
136 struct lang_output_section_phdr_list *next;
137 const char *name;
138 bool used;
139 } lang_output_section_phdr_list;
141 typedef struct lang_output_section_statement_struct
143 lang_statement_header_type header;
144 /* Input sections to be mapped to this output section. */
145 lang_statement_list_type children;
146 /* Input sections to be mapped to the start of this output section.
147 These sections are provided by the --section-ordering file, if used. */
148 lang_statement_list_type sort_children;
150 struct lang_output_section_statement_struct *next;
151 struct lang_output_section_statement_struct *prev;
152 const char *name;
153 asection *bfd_section;
154 lang_memory_region_type *region;
155 lang_memory_region_type *lma_region;
156 fill_type *fill;
157 union etree_union *addr_tree;
158 union etree_union *load_base;
159 union etree_union *section_alignment;
160 union etree_union *subsection_alignment;
162 /* If non-null, an expression to evaluate after setting the section's
163 size. The expression is evaluated inside REGION (above) with '.'
164 set to the end of the section. Used in the last overlay section
165 to move '.' past all the overlaid sections. */
166 union etree_union *update_dot_tree;
168 lang_output_section_phdr_list *phdrs;
170 /* Used by ELF SHF_LINK_ORDER sorting. */
171 void *data;
173 unsigned int block_value;
174 int constraint;
175 flagword flags;
176 enum section_type sectype;
177 etree_type *sectype_value;
178 unsigned int processed_vma : 1;
179 unsigned int processed_lma : 1;
180 unsigned int all_input_readonly : 1;
181 /* If this section should be ignored. */
182 unsigned int ignored : 1;
183 /* If this section should update "dot". Prevents section being ignored. */
184 unsigned int update_dot : 1;
185 /* If this section is after assignment to _end. */
186 unsigned int after_end : 1;
187 /* If this section uses the alignment of its input sections. */
188 unsigned int align_lma_with_input : 1;
189 /* If script has duplicate output section statements of the same name
190 create duplicate output sections. */
191 unsigned int dup_output : 1;
192 } lang_output_section_statement_type;
194 typedef struct
196 lang_statement_header_type header;
197 fill_type *fill;
198 int size;
199 asection *output_section;
200 } lang_fill_statement_type;
202 typedef struct
204 lang_statement_header_type header;
205 unsigned int type;
206 union etree_union *exp;
207 bfd_vma value;
208 asection *output_section;
209 bfd_vma output_offset;
210 } lang_data_statement_type;
212 /* Generate a reloc in the output file. */
214 typedef struct
216 lang_statement_header_type header;
218 /* Reloc to generate. */
219 bfd_reloc_code_real_type reloc;
221 /* Reloc howto structure. */
222 reloc_howto_type *howto;
224 /* Section to generate reloc against.
225 Exactly one of section and name must be NULL. */
226 asection *section;
228 /* Name of symbol to generate reloc against.
229 Exactly one of section and name must be NULL. */
230 const char *name;
232 /* Expression for addend. */
233 union etree_union *addend_exp;
235 /* Resolved addend. */
236 bfd_vma addend_value;
238 /* Output section where reloc should be performed. */
239 asection *output_section;
241 /* Offset within output section. */
242 bfd_vma output_offset;
243 } lang_reloc_statement_type;
245 struct lang_input_statement_flags
247 /* 1 means this file was specified in a -l option. */
248 unsigned int maybe_archive : 1;
250 /* 1 means this file was specified in a -l:namespec option. */
251 unsigned int full_name_provided : 1;
253 /* 1 means search a set of directories for this file. */
254 unsigned int search_dirs : 1;
256 /* 1 means this was found when processing a script in the sysroot. */
257 unsigned int sysrooted : 1;
259 /* 1 means this is base file of incremental load.
260 Do not load this file's text or data.
261 Also default text_start to after this file's bss. */
262 unsigned int just_syms : 1;
264 /* Whether to search for this entry as a dynamic archive. */
265 unsigned int dynamic : 1;
267 /* Set if a DT_NEEDED tag should be added not just for the dynamic library
268 explicitly given by this entry but also for any dynamic libraries in
269 this entry's needed list. */
270 unsigned int add_DT_NEEDED_for_dynamic : 1;
272 /* Set if this entry should cause a DT_NEEDED tag only when some
273 regular file references its symbols (ie. --as-needed is in effect). */
274 unsigned int add_DT_NEEDED_for_regular : 1;
276 /* Whether to include the entire contents of an archive. */
277 unsigned int whole_archive : 1;
279 /* Set when bfd opening is successful. */
280 unsigned int loaded : 1;
282 unsigned int real : 1;
284 /* Set if the file does not exist. */
285 unsigned int missing_file : 1;
287 /* Set if reloading an archive or --as-needed lib. */
288 unsigned int reload : 1;
290 #if BFD_SUPPORTS_PLUGINS
291 /* Set if the file was claimed by a plugin. */
292 unsigned int claimed : 1;
294 /* Set if the file was claimed from an archive. */
295 unsigned int claim_archive : 1;
296 #endif /* BFD_SUPPORTS_PLUGINS */
298 /* Head of list of pushed flags. */
299 struct lang_input_statement_flags *pushed;
302 typedef struct lang_input_statement_struct
304 lang_statement_header_type header;
305 /* Name of this file. */
306 const char *filename;
307 /* Name to use for the symbol giving address of text start.
308 Usually the same as filename, but for a file spec'd with
309 -l this is the -l switch itself rather than the filename. */
310 const char *local_sym_name;
311 /* Name to use when sorting. */
312 const char *sort_key;
313 /* Extra search path. Used to find a file relative to the
314 directory of the current linker script. */
315 const char *extra_search_path;
317 bfd *the_bfd;
319 ctf_archive_t *the_ctf;
321 struct flag_info *section_flag_list;
323 /* Next pointer for file_chain statement list. */
324 struct lang_input_statement_struct *next;
326 /* Next pointer for input_file_chain statement list. */
327 struct lang_input_statement_struct *next_real_file;
329 const char *target;
331 struct lang_input_statement_flags flags;
333 #if BFD_SUPPORTS_PLUGINS
334 /* If non-NULL the plugin that added this file. */
335 void * plugin;
336 #endif
337 } lang_input_statement_type;
339 typedef struct
341 lang_statement_header_type header;
342 asection *section;
343 void *pattern;
344 } lang_input_section_type;
346 typedef struct
348 lang_statement_header_type header;
349 asection *section;
350 void *pattern;
351 lang_input_statement_type *input_stmt;
352 } lang_input_matcher_type;
354 struct map_symbol_def {
355 struct bfd_link_hash_entry *entry;
356 struct map_symbol_def *next;
359 /* For input sections, when writing a map file: head / tail of a linked
360 list of hash table entries for symbols defined in this section. */
361 typedef struct input_section_userdata_struct
363 struct map_symbol_def *map_symbol_def_head;
364 struct map_symbol_def **map_symbol_def_tail;
365 unsigned long map_symbol_def_count;
366 } input_section_userdata_type;
368 static inline bool
369 bfd_input_just_syms (const bfd *abfd)
371 lang_input_statement_type *is = bfd_usrdata (abfd);
372 return is != NULL && is->flags.just_syms;
375 typedef struct lang_wild_statement_struct lang_wild_statement_type;
377 typedef void (*callback_t) (lang_wild_statement_type *, struct wildcard_list *,
378 asection *, lang_input_statement_type *, void *);
380 typedef void (*walk_wild_section_handler_t) (lang_wild_statement_type *,
381 lang_input_statement_type *,
382 callback_t callback,
383 void *data);
385 typedef bool (*lang_match_sec_type_func) (bfd *, const asection *,
386 bfd *, const asection *);
388 /* Binary search tree structure to efficiently sort sections by
389 name. */
390 typedef struct lang_section_bst
392 asection *section;
393 void *pattern;
394 struct lang_section_bst *left;
395 struct lang_section_bst *right;
396 } lang_section_bst_type;
398 struct lang_wild_statement_struct
400 lang_statement_header_type header;
401 lang_statement_list_type children;
402 lang_statement_list_type matching_sections;
403 lang_section_bst_type * tree;
404 lang_section_bst_type ** rightmost;
405 struct wildcard_list * section_list;
406 struct name_list * exclude_name_list;
407 struct flag_info * section_flag_list;
408 const char * filename;
409 bool filenames_sorted;
410 bool filenames_reversed;
411 bool any_specs_sorted;
412 bool keep_sections;
415 typedef struct lang_address_statement_struct
417 lang_statement_header_type header;
418 const char *section_name;
419 union etree_union *address;
420 const segment_type *segment;
421 } lang_address_statement_type;
423 typedef struct
425 lang_statement_header_type header;
426 bfd_vma output_offset;
427 bfd_size_type size;
428 asection *output_section;
429 fill_type *fill;
430 } lang_padding_statement_type;
432 /* A group statement collects a set of libraries together. The
433 libraries are searched multiple times, until no new undefined
434 symbols are found. The effect is to search a group of libraries as
435 though they were a single library. */
437 typedef struct
439 lang_statement_header_type header;
440 lang_statement_list_type children;
441 } lang_group_statement_type;
443 typedef struct
445 lang_statement_header_type header;
446 const char *where;
447 bool is_before;
448 } lang_insert_statement_type;
450 typedef union lang_statement_union
452 lang_statement_header_type header;
453 lang_address_statement_type address_statement;
454 lang_assignment_statement_type assignment_statement;
455 lang_data_statement_type data_statement;
456 lang_fill_statement_type fill_statement;
457 lang_group_statement_type group_statement;
458 lang_input_section_type input_section;
459 lang_input_matcher_type input_matcher;
460 lang_input_statement_type input_statement;
461 lang_insert_statement_type insert_statement;
462 lang_output_section_statement_type output_section_statement;
463 lang_output_statement_type output_statement;
464 lang_padding_statement_type padding_statement;
465 lang_reloc_statement_type reloc_statement;
466 lang_target_statement_type target_statement;
467 lang_wild_statement_type wild_statement;
468 } lang_statement_union_type;
470 /* This structure holds information about a program header, from the
471 PHDRS command in the linker script. */
473 struct lang_phdr
475 struct lang_phdr *next;
476 const char *name;
477 unsigned long type;
478 bool filehdr;
479 bool phdrs;
480 etree_type *at;
481 etree_type *flags;
484 /* This structure is used to hold a list of sections which may not
485 cross reference each other. */
487 typedef struct lang_nocrossref
489 struct lang_nocrossref *next;
490 const char *name;
491 } lang_nocrossref_type;
493 /* The list of nocrossref lists. */
495 struct lang_nocrossrefs
497 struct lang_nocrossrefs *next;
498 lang_nocrossref_type *list;
499 bool onlyfirst;
502 /* This structure is used to hold a list of input section names which
503 will not match an output section in the linker script. */
505 struct unique_sections
507 struct unique_sections *next;
508 const char *name;
511 /* Used by place_orphan to keep track of orphan sections and statements. */
513 struct orphan_save
515 const char *name;
516 flagword flags;
517 lang_output_section_statement_type *os;
518 asection **section;
519 lang_statement_union_type **stmt;
520 lang_output_section_statement_type **os_tail;
523 struct asneeded_minfo
525 struct asneeded_minfo *next;
526 const char *soname;
527 bfd *ref;
528 const char *name;
531 extern struct lang_phdr *lang_phdr_list;
532 extern struct lang_nocrossrefs *nocrossref_list;
533 extern const char *output_target;
534 extern lang_output_section_statement_type *abs_output_section;
535 extern lang_statement_list_type lang_os_list;
536 extern struct lang_input_statement_flags input_flags;
537 extern bool lang_has_input_file;
538 extern lang_statement_list_type statement_list;
539 extern lang_statement_list_type *stat_ptr;
540 extern bool delete_output_file_on_failure;
541 extern bool enable_linker_version;
543 extern struct bfd_sym_chain entry_symbol;
544 extern const char *entry_section;
545 extern bool entry_from_cmdline;
546 extern lang_statement_list_type file_chain;
547 extern lang_statement_list_type input_file_chain;
549 extern struct bfd_elf_dynamic_list **current_dynamic_list_p;
551 extern int lang_statement_iteration;
552 extern struct asneeded_minfo **asneeded_list_tail;
554 extern void (*output_bfd_hash_table_free_fn) (struct bfd_link_hash_table *);
556 extern void lang_init
557 (void);
558 extern void lang_finish
559 (void);
560 extern lang_memory_region_type * lang_memory_region_lookup
561 (const char * const, bool);
562 extern void lang_memory_region_alias
563 (const char *, const char *);
564 extern void lang_map
565 (void);
566 extern void lang_set_flags
567 (lang_memory_region_type *, const char *, int);
568 extern void lang_add_output
569 (const char *, int from_script);
570 extern lang_output_section_statement_type *lang_enter_output_section_statement
571 (const char *, etree_type *, enum section_type, etree_type *, etree_type *,
572 etree_type *, etree_type *, int, int);
573 extern void lang_final
574 (void);
575 extern void lang_relax_sections
576 (bool);
577 extern void lang_process
578 (void);
579 extern void lang_section_start
580 (const char *, union etree_union *, const segment_type *);
581 extern void lang_add_entry
582 (const char *, bool);
583 extern void lang_default_entry
584 (const char *);
585 extern void lang_add_target
586 (const char *);
587 extern void lang_add_wild
588 (struct wildcard_spec *, struct wildcard_list *, bool);
589 extern void lang_add_map
590 (const char *);
591 extern void lang_add_fill
592 (fill_type *);
593 extern lang_assignment_statement_type *lang_add_assignment
594 (union etree_union *);
595 extern void lang_add_attribute
596 (enum statement_enum);
597 extern void lang_startup
598 (const char *);
599 extern void lang_float
600 (bool);
601 extern void lang_leave_output_section_statement
602 (fill_type *, const char *, lang_output_section_phdr_list *,
603 const char *);
604 extern void lang_for_each_input_file
605 (void (*dothis) (lang_input_statement_type *));
606 extern void lang_for_each_file
607 (void (*dothis) (lang_input_statement_type *));
608 extern void lang_reset_memory_regions
609 (void);
610 extern void lang_do_assignments
611 (lang_phase_type);
612 extern asection *section_for_dot
613 (void);
615 #define LANG_FOR_EACH_INPUT_STATEMENT(statement) \
616 lang_input_statement_type *statement; \
617 for (statement = (lang_input_statement_type *) file_chain.head; \
618 statement != NULL; \
619 statement = statement->next)
621 #define lang_output_section_find(NAME) \
622 lang_output_section_statement_lookup (NAME, 0, 0)
624 extern void lang_process
625 (void);
626 extern void ldlang_add_file
627 (lang_input_statement_type *);
628 extern lang_output_section_statement_type *lang_output_section_find_by_flags
629 (const asection *, flagword, lang_output_section_statement_type **,
630 lang_match_sec_type_func);
631 extern lang_output_section_statement_type *lang_insert_orphan
632 (asection *, const char *, int, lang_output_section_statement_type *,
633 struct orphan_save *, etree_type *, lang_statement_list_type *);
634 extern lang_input_statement_type *lang_add_input_file
635 (const char *, lang_input_file_enum_type, const char *);
636 extern void lang_add_keepsyms_file
637 (const char *);
638 extern lang_output_section_statement_type *lang_output_section_get
639 (const asection *);
640 extern lang_output_section_statement_type *lang_output_section_statement_lookup
641 (const char *, int, int);
642 extern lang_output_section_statement_type *next_matching_output_section_statement
643 (lang_output_section_statement_type *, int);
644 extern void ldlang_add_undef
645 (const char *const, bool);
646 extern void ldlang_add_require_defined
647 (const char *const);
648 extern void lang_add_output_format
649 (const char *, const char *, const char *, int);
650 extern void lang_list_init
651 (lang_statement_list_type *);
652 extern void push_stat_ptr
653 (lang_statement_list_type *);
654 extern void pop_stat_ptr
655 (void);
656 extern void lang_add_data
657 (int, union etree_union *);
658 extern void lang_add_string
659 (const char *);
660 extern void lang_add_reloc
661 (bfd_reloc_code_real_type, reloc_howto_type *, asection *, const char *,
662 union etree_union *);
663 extern void lang_for_each_statement
664 (void (*) (lang_statement_union_type *));
665 extern void lang_for_each_statement_worker
666 (void (*) (lang_statement_union_type *), lang_statement_union_type *);
667 extern void *stat_alloc
668 (size_t);
669 extern void strip_excluded_output_sections
670 (void);
671 extern void lang_clear_os_map
672 (void);
673 extern void dprint_statement
674 (lang_statement_union_type *, int);
675 extern void lang_size_sections
676 (bool *, bool);
677 extern void one_lang_size_sections_pass
678 (bool *, bool);
679 extern void lang_add_insert
680 (const char *, int);
681 extern void lang_enter_group
682 (void);
683 extern void lang_leave_group
684 (void);
685 extern void lang_add_section
686 (lang_statement_list_type *, asection *, struct wildcard_list *,
687 struct flag_info *, lang_output_section_statement_type *);
688 extern void lang_new_phdr
689 (const char *, etree_type *, bool, bool, etree_type *,
690 etree_type *);
691 extern void lang_add_nocrossref
692 (lang_nocrossref_type *);
693 extern void lang_add_nocrossref_to
694 (lang_nocrossref_type *);
695 extern void lang_enter_overlay
696 (etree_type *, etree_type *);
697 extern void lang_enter_overlay_section
698 (const char *);
699 extern void lang_leave_overlay_section
700 (fill_type *, lang_output_section_phdr_list *);
701 extern void lang_leave_overlay
702 (etree_type *, int, fill_type *, const char *,
703 lang_output_section_phdr_list *, const char *);
705 extern struct bfd_elf_version_expr *lang_new_vers_pattern
706 (struct bfd_elf_version_expr *, const char *, const char *, bool);
707 extern struct bfd_elf_version_tree *lang_new_vers_node
708 (struct bfd_elf_version_expr *, struct bfd_elf_version_expr *);
709 extern struct bfd_elf_version_deps *lang_add_vers_depend
710 (struct bfd_elf_version_deps *, const char *);
711 extern void lang_register_vers_node
712 (const char *, struct bfd_elf_version_tree *, struct bfd_elf_version_deps *);
713 extern void lang_append_dynamic_list (struct bfd_elf_dynamic_list **,
714 struct bfd_elf_version_expr *);
715 extern void lang_append_dynamic_list_cpp_typeinfo (void);
716 extern void lang_append_dynamic_list_cpp_new (void);
717 extern void lang_add_unique
718 (const char *);
719 extern const char *lang_get_output_target
720 (void);
721 extern void add_excluded_libs (const char *);
722 extern bool load_symbols
723 (lang_input_statement_type *, lang_statement_list_type *);
725 struct elf_sym_strtab;
726 struct elf_strtab_hash;
727 extern void ldlang_ctf_acquire_strings
728 (struct elf_strtab_hash *);
729 extern void ldlang_ctf_new_dynsym
730 (int symidx, struct elf_internal_sym *);
731 extern void ldlang_write_ctf_late
732 (void);
733 extern bool
734 ldlang_override_segment_assignment
735 (struct bfd_link_info *, bfd *, asection *, asection *, bool);
737 extern void
738 lang_ld_feature (char *);
740 extern void
741 lang_print_memory_usage (void);
743 extern void
744 lang_add_gc_name (const char *);
746 extern bool
747 print_one_symbol (struct bfd_link_hash_entry *, void *);
749 extern void lang_add_version_string
750 (void);
751 #endif