[gdb/tui] Replace macro HELP_ATTRIBUTE_MODE with std::string
[binutils-gdb.git] / ld / ldlang.h
blob463cce394e935c564f14e2b4585ae9eb5a8a222b
1 /* ldlang.h - linker command language support
2 Copyright (C) 1991-2023 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 lang_statement_list_type children;
145 struct lang_output_section_statement_struct *next;
146 struct lang_output_section_statement_struct *prev;
147 const char *name;
148 asection *bfd_section;
149 lang_memory_region_type *region;
150 lang_memory_region_type *lma_region;
151 fill_type *fill;
152 union etree_union *addr_tree;
153 union etree_union *load_base;
154 union etree_union *section_alignment;
155 union etree_union *subsection_alignment;
157 /* If non-null, an expression to evaluate after setting the section's
158 size. The expression is evaluated inside REGION (above) with '.'
159 set to the end of the section. Used in the last overlay section
160 to move '.' past all the overlaid sections. */
161 union etree_union *update_dot_tree;
163 lang_output_section_phdr_list *phdrs;
165 /* Used by ELF SHF_LINK_ORDER sorting. */
166 void *data;
168 unsigned int block_value;
169 int constraint;
170 flagword flags;
171 enum section_type sectype;
172 etree_type *sectype_value;
173 unsigned int processed_vma : 1;
174 unsigned int processed_lma : 1;
175 unsigned int all_input_readonly : 1;
176 /* If this section should be ignored. */
177 unsigned int ignored : 1;
178 /* If this section should update "dot". Prevents section being ignored. */
179 unsigned int update_dot : 1;
180 /* If this section is after assignment to _end. */
181 unsigned int after_end : 1;
182 /* If this section uses the alignment of its input sections. */
183 unsigned int align_lma_with_input : 1;
184 /* If script has duplicate output section statements of the same name
185 create duplicate output sections. */
186 unsigned int dup_output : 1;
187 } lang_output_section_statement_type;
189 typedef struct
191 lang_statement_header_type header;
192 fill_type *fill;
193 int size;
194 asection *output_section;
195 } lang_fill_statement_type;
197 typedef struct
199 lang_statement_header_type header;
200 unsigned int type;
201 union etree_union *exp;
202 bfd_vma value;
203 asection *output_section;
204 bfd_vma output_offset;
205 } lang_data_statement_type;
207 /* Generate a reloc in the output file. */
209 typedef struct
211 lang_statement_header_type header;
213 /* Reloc to generate. */
214 bfd_reloc_code_real_type reloc;
216 /* Reloc howto structure. */
217 reloc_howto_type *howto;
219 /* Section to generate reloc against.
220 Exactly one of section and name must be NULL. */
221 asection *section;
223 /* Name of symbol to generate reloc against.
224 Exactly one of section and name must be NULL. */
225 const char *name;
227 /* Expression for addend. */
228 union etree_union *addend_exp;
230 /* Resolved addend. */
231 bfd_vma addend_value;
233 /* Output section where reloc should be performed. */
234 asection *output_section;
236 /* Offset within output section. */
237 bfd_vma output_offset;
238 } lang_reloc_statement_type;
240 struct lang_input_statement_flags
242 /* 1 means this file was specified in a -l option. */
243 unsigned int maybe_archive : 1;
245 /* 1 means this file was specified in a -l:namespec option. */
246 unsigned int full_name_provided : 1;
248 /* 1 means search a set of directories for this file. */
249 unsigned int search_dirs : 1;
251 /* 1 means this was found when processing a script in the sysroot. */
252 unsigned int sysrooted : 1;
254 /* 1 means this is base file of incremental load.
255 Do not load this file's text or data.
256 Also default text_start to after this file's bss. */
257 unsigned int just_syms : 1;
259 /* Whether to search for this entry as a dynamic archive. */
260 unsigned int dynamic : 1;
262 /* Set if a DT_NEEDED tag should be added not just for the dynamic library
263 explicitly given by this entry but also for any dynamic libraries in
264 this entry's needed list. */
265 unsigned int add_DT_NEEDED_for_dynamic : 1;
267 /* Set if this entry should cause a DT_NEEDED tag only when some
268 regular file references its symbols (ie. --as-needed is in effect). */
269 unsigned int add_DT_NEEDED_for_regular : 1;
271 /* Whether to include the entire contents of an archive. */
272 unsigned int whole_archive : 1;
274 /* Set when bfd opening is successful. */
275 unsigned int loaded : 1;
277 unsigned int real : 1;
279 /* Set if the file does not exist. */
280 unsigned int missing_file : 1;
282 /* Set if reloading an archive or --as-needed lib. */
283 unsigned int reload : 1;
285 #if BFD_SUPPORTS_PLUGINS
286 /* Set if the file was claimed by a plugin. */
287 unsigned int claimed : 1;
289 /* Set if the file was claimed from an archive. */
290 unsigned int claim_archive : 1;
292 /* Set if added by the lto plugin add_input_file callback. */
293 unsigned int lto_output : 1;
294 #endif /* BFD_SUPPORTS_PLUGINS */
296 /* Head of list of pushed flags. */
297 struct lang_input_statement_flags *pushed;
300 typedef struct lang_input_statement_struct
302 lang_statement_header_type header;
303 /* Name of this file. */
304 const char *filename;
305 /* Name to use for the symbol giving address of text start.
306 Usually the same as filename, but for a file spec'd with
307 -l this is the -l switch itself rather than the filename. */
308 const char *local_sym_name;
309 /* Name to use when sorting. */
310 const char *sort_key;
311 /* Extra search path. Used to find a file relative to the
312 directory of the current linker script. */
313 const char *extra_search_path;
315 bfd *the_bfd;
317 ctf_archive_t *the_ctf;
319 struct flag_info *section_flag_list;
321 /* Next pointer for file_chain statement list. */
322 struct lang_input_statement_struct *next;
324 /* Next pointer for input_file_chain statement list. */
325 struct lang_input_statement_struct *next_real_file;
327 const char *target;
329 struct lang_input_statement_flags flags;
330 } lang_input_statement_type;
332 typedef struct
334 lang_statement_header_type header;
335 asection *section;
336 void *pattern;
337 } lang_input_section_type;
339 typedef struct
341 lang_statement_header_type header;
342 asection *section;
343 void *pattern;
344 lang_input_statement_type *input_stmt;
345 } lang_input_matcher_type;
347 struct map_symbol_def {
348 struct bfd_link_hash_entry *entry;
349 struct map_symbol_def *next;
352 /* For input sections, when writing a map file: head / tail of a linked
353 list of hash table entries for symbols defined in this section. */
354 typedef struct input_section_userdata_struct
356 struct map_symbol_def *map_symbol_def_head;
357 struct map_symbol_def **map_symbol_def_tail;
358 unsigned long map_symbol_def_count;
359 } input_section_userdata_type;
361 static inline bool
362 bfd_input_just_syms (const bfd *abfd)
364 lang_input_statement_type *is = bfd_usrdata (abfd);
365 return is != NULL && is->flags.just_syms;
368 typedef struct lang_wild_statement_struct lang_wild_statement_type;
370 typedef void (*callback_t) (lang_wild_statement_type *, struct wildcard_list *,
371 asection *, lang_input_statement_type *, void *);
373 typedef void (*walk_wild_section_handler_t) (lang_wild_statement_type *,
374 lang_input_statement_type *,
375 callback_t callback,
376 void *data);
378 typedef bool (*lang_match_sec_type_func) (bfd *, const asection *,
379 bfd *, const asection *);
381 /* Binary search tree structure to efficiently sort sections by
382 name. */
383 typedef struct lang_section_bst
385 asection *section;
386 void *pattern;
387 struct lang_section_bst *left;
388 struct lang_section_bst *right;
389 } lang_section_bst_type;
391 struct lang_wild_statement_struct
393 lang_statement_header_type header;
394 const char *filename;
395 bool filenames_sorted;
396 bool any_specs_sorted;
397 struct wildcard_list *section_list;
398 bool keep_sections;
399 lang_statement_list_type children;
400 struct name_list *exclude_name_list;
401 lang_statement_list_type matching_sections;
403 lang_section_bst_type *tree, **rightmost;
404 struct flag_info *section_flag_list;
407 typedef struct lang_address_statement_struct
409 lang_statement_header_type header;
410 const char *section_name;
411 union etree_union *address;
412 const segment_type *segment;
413 } lang_address_statement_type;
415 typedef struct
417 lang_statement_header_type header;
418 bfd_vma output_offset;
419 bfd_size_type size;
420 asection *output_section;
421 fill_type *fill;
422 } lang_padding_statement_type;
424 /* A group statement collects a set of libraries together. The
425 libraries are searched multiple times, until no new undefined
426 symbols are found. The effect is to search a group of libraries as
427 though they were a single library. */
429 typedef struct
431 lang_statement_header_type header;
432 lang_statement_list_type children;
433 } lang_group_statement_type;
435 typedef struct
437 lang_statement_header_type header;
438 const char *where;
439 bool is_before;
440 } lang_insert_statement_type;
442 typedef union lang_statement_union
444 lang_statement_header_type header;
445 lang_address_statement_type address_statement;
446 lang_assignment_statement_type assignment_statement;
447 lang_data_statement_type data_statement;
448 lang_fill_statement_type fill_statement;
449 lang_group_statement_type group_statement;
450 lang_input_section_type input_section;
451 lang_input_matcher_type input_matcher;
452 lang_input_statement_type input_statement;
453 lang_insert_statement_type insert_statement;
454 lang_output_section_statement_type output_section_statement;
455 lang_output_statement_type output_statement;
456 lang_padding_statement_type padding_statement;
457 lang_reloc_statement_type reloc_statement;
458 lang_target_statement_type target_statement;
459 lang_wild_statement_type wild_statement;
460 } lang_statement_union_type;
462 /* This structure holds information about a program header, from the
463 PHDRS command in the linker script. */
465 struct lang_phdr
467 struct lang_phdr *next;
468 const char *name;
469 unsigned long type;
470 bool filehdr;
471 bool phdrs;
472 etree_type *at;
473 etree_type *flags;
476 /* This structure is used to hold a list of sections which may not
477 cross reference each other. */
479 typedef struct lang_nocrossref
481 struct lang_nocrossref *next;
482 const char *name;
483 } lang_nocrossref_type;
485 /* The list of nocrossref lists. */
487 struct lang_nocrossrefs
489 struct lang_nocrossrefs *next;
490 lang_nocrossref_type *list;
491 bool onlyfirst;
494 /* This structure is used to hold a list of input section names which
495 will not match an output section in the linker script. */
497 struct unique_sections
499 struct unique_sections *next;
500 const char *name;
503 /* Used by place_orphan to keep track of orphan sections and statements. */
505 struct orphan_save
507 const char *name;
508 flagword flags;
509 lang_output_section_statement_type *os;
510 asection **section;
511 lang_statement_union_type **stmt;
512 lang_output_section_statement_type **os_tail;
515 struct asneeded_minfo
517 struct asneeded_minfo *next;
518 const char *soname;
519 bfd *ref;
520 const char *name;
523 extern struct lang_phdr *lang_phdr_list;
524 extern struct lang_nocrossrefs *nocrossref_list;
525 extern const char *output_target;
526 extern lang_output_section_statement_type *abs_output_section;
527 extern lang_statement_list_type lang_os_list;
528 extern struct lang_input_statement_flags input_flags;
529 extern bool lang_has_input_file;
530 extern lang_statement_list_type statement_list;
531 extern lang_statement_list_type *stat_ptr;
532 extern bool delete_output_file_on_failure;
533 extern bool enable_linker_version;
535 extern struct bfd_sym_chain entry_symbol;
536 extern const char *entry_section;
537 extern bool entry_from_cmdline;
538 extern lang_statement_list_type file_chain;
539 extern lang_statement_list_type input_file_chain;
541 extern struct bfd_elf_dynamic_list **current_dynamic_list_p;
543 extern int lang_statement_iteration;
544 extern struct asneeded_minfo **asneeded_list_tail;
546 extern void (*output_bfd_hash_table_free_fn) (struct bfd_link_hash_table *);
548 extern void lang_init
549 (void);
550 extern void lang_finish
551 (void);
552 extern lang_memory_region_type * lang_memory_region_lookup
553 (const char * const, bool);
554 extern void lang_memory_region_alias
555 (const char *, const char *);
556 extern void lang_map
557 (void);
558 extern void lang_set_flags
559 (lang_memory_region_type *, const char *, int);
560 extern void lang_add_output
561 (const char *, int from_script);
562 extern lang_output_section_statement_type *lang_enter_output_section_statement
563 (const char *, etree_type *, enum section_type, etree_type *, etree_type *,
564 etree_type *, etree_type *, int, int);
565 extern void lang_final
566 (void);
567 extern void lang_relax_sections
568 (bool);
569 extern void lang_process
570 (void);
571 extern void lang_section_start
572 (const char *, union etree_union *, const segment_type *);
573 extern void lang_add_entry
574 (const char *, bool);
575 extern void lang_default_entry
576 (const char *);
577 extern void lang_add_target
578 (const char *);
579 extern void lang_add_wild
580 (struct wildcard_spec *, struct wildcard_list *, bool);
581 extern void lang_add_map
582 (const char *);
583 extern void lang_add_fill
584 (fill_type *);
585 extern lang_assignment_statement_type *lang_add_assignment
586 (union etree_union *);
587 extern void lang_add_attribute
588 (enum statement_enum);
589 extern void lang_startup
590 (const char *);
591 extern void lang_float
592 (bool);
593 extern void lang_leave_output_section_statement
594 (fill_type *, const char *, lang_output_section_phdr_list *,
595 const char *);
596 extern void lang_for_each_input_file
597 (void (*dothis) (lang_input_statement_type *));
598 extern void lang_for_each_file
599 (void (*dothis) (lang_input_statement_type *));
600 extern void lang_reset_memory_regions
601 (void);
602 extern void lang_do_assignments
603 (lang_phase_type);
604 extern asection *section_for_dot
605 (void);
607 #define LANG_FOR_EACH_INPUT_STATEMENT(statement) \
608 lang_input_statement_type *statement; \
609 for (statement = (lang_input_statement_type *) file_chain.head; \
610 statement != NULL; \
611 statement = statement->next)
613 #define lang_output_section_find(NAME) \
614 lang_output_section_statement_lookup (NAME, 0, 0)
616 extern void lang_process
617 (void);
618 extern void ldlang_add_file
619 (lang_input_statement_type *);
620 extern lang_output_section_statement_type *lang_output_section_find_by_flags
621 (const asection *, flagword, lang_output_section_statement_type **,
622 lang_match_sec_type_func);
623 extern lang_output_section_statement_type *lang_insert_orphan
624 (asection *, const char *, int, lang_output_section_statement_type *,
625 struct orphan_save *, etree_type *, lang_statement_list_type *);
626 extern lang_input_statement_type *lang_add_input_file
627 (const char *, lang_input_file_enum_type, const char *);
628 extern void lang_add_keepsyms_file
629 (const char *);
630 extern lang_output_section_statement_type *lang_output_section_get
631 (const asection *);
632 extern lang_output_section_statement_type *lang_output_section_statement_lookup
633 (const char *, int, int);
634 extern lang_output_section_statement_type *next_matching_output_section_statement
635 (lang_output_section_statement_type *, int);
636 extern void ldlang_add_undef
637 (const char *const, bool);
638 extern void ldlang_add_require_defined
639 (const char *const);
640 extern void lang_add_output_format
641 (const char *, const char *, const char *, int);
642 extern void lang_list_init
643 (lang_statement_list_type *);
644 extern void push_stat_ptr
645 (lang_statement_list_type *);
646 extern void pop_stat_ptr
647 (void);
648 extern void lang_add_data
649 (int, union etree_union *);
650 extern void lang_add_string
651 (const char *);
652 extern void lang_add_reloc
653 (bfd_reloc_code_real_type, reloc_howto_type *, asection *, const char *,
654 union etree_union *);
655 extern void lang_for_each_statement
656 (void (*) (lang_statement_union_type *));
657 extern void lang_for_each_statement_worker
658 (void (*) (lang_statement_union_type *), lang_statement_union_type *);
659 extern void *stat_alloc
660 (size_t);
661 extern void strip_excluded_output_sections
662 (void);
663 extern void lang_clear_os_map
664 (void);
665 extern void dprint_statement
666 (lang_statement_union_type *, int);
667 extern void lang_size_sections
668 (bool *, bool);
669 extern void one_lang_size_sections_pass
670 (bool *, bool);
671 extern void lang_add_insert
672 (const char *, int);
673 extern void lang_enter_group
674 (void);
675 extern void lang_leave_group
676 (void);
677 extern void lang_add_section
678 (lang_statement_list_type *, asection *, struct wildcard_list *,
679 struct flag_info *, lang_output_section_statement_type *);
680 extern void lang_new_phdr
681 (const char *, etree_type *, bool, bool, etree_type *,
682 etree_type *);
683 extern void lang_add_nocrossref
684 (lang_nocrossref_type *);
685 extern void lang_add_nocrossref_to
686 (lang_nocrossref_type *);
687 extern void lang_enter_overlay
688 (etree_type *, etree_type *);
689 extern void lang_enter_overlay_section
690 (const char *);
691 extern void lang_leave_overlay_section
692 (fill_type *, lang_output_section_phdr_list *);
693 extern void lang_leave_overlay
694 (etree_type *, int, fill_type *, const char *,
695 lang_output_section_phdr_list *, const char *);
697 extern struct bfd_elf_version_expr *lang_new_vers_pattern
698 (struct bfd_elf_version_expr *, const char *, const char *, bool);
699 extern struct bfd_elf_version_tree *lang_new_vers_node
700 (struct bfd_elf_version_expr *, struct bfd_elf_version_expr *);
701 extern struct bfd_elf_version_deps *lang_add_vers_depend
702 (struct bfd_elf_version_deps *, const char *);
703 extern void lang_register_vers_node
704 (const char *, struct bfd_elf_version_tree *, struct bfd_elf_version_deps *);
705 extern void lang_append_dynamic_list (struct bfd_elf_dynamic_list **,
706 struct bfd_elf_version_expr *);
707 extern void lang_append_dynamic_list_cpp_typeinfo (void);
708 extern void lang_append_dynamic_list_cpp_new (void);
709 extern void lang_add_unique
710 (const char *);
711 extern const char *lang_get_output_target
712 (void);
713 extern void add_excluded_libs (const char *);
714 extern bool load_symbols
715 (lang_input_statement_type *, lang_statement_list_type *);
717 struct elf_sym_strtab;
718 struct elf_strtab_hash;
719 extern void ldlang_ctf_acquire_strings
720 (struct elf_strtab_hash *);
721 extern void ldlang_ctf_new_dynsym
722 (int symidx, struct elf_internal_sym *);
723 extern void ldlang_write_ctf_late
724 (void);
725 extern bool
726 ldlang_override_segment_assignment
727 (struct bfd_link_info *, bfd *, asection *, asection *, bool);
729 extern void
730 lang_ld_feature (char *);
732 extern void
733 lang_print_memory_usage (void);
735 extern void
736 lang_add_gc_name (const char *);
738 extern bool
739 print_one_symbol (struct bfd_link_hash_entry *, void *);
741 extern void lang_add_version_string
742 (void);
743 #endif