Implement tp_richcompare for gdb.Block
[binutils-gdb.git] / ld / ldlang.h
blob4c1bb002f8e136f2be7a3e5a2c4a542312b865e0
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;
297 /* Set if added by the lto plugin add_input_file callback. */
298 unsigned int lto_output : 1;
299 #endif /* BFD_SUPPORTS_PLUGINS */
301 /* Head of list of pushed flags. */
302 struct lang_input_statement_flags *pushed;
305 typedef struct lang_input_statement_struct
307 lang_statement_header_type header;
308 /* Name of this file. */
309 const char *filename;
310 /* Name to use for the symbol giving address of text start.
311 Usually the same as filename, but for a file spec'd with
312 -l this is the -l switch itself rather than the filename. */
313 const char *local_sym_name;
314 /* Name to use when sorting. */
315 const char *sort_key;
316 /* Extra search path. Used to find a file relative to the
317 directory of the current linker script. */
318 const char *extra_search_path;
320 bfd *the_bfd;
322 ctf_archive_t *the_ctf;
324 struct flag_info *section_flag_list;
326 /* Next pointer for file_chain statement list. */
327 struct lang_input_statement_struct *next;
329 /* Next pointer for input_file_chain statement list. */
330 struct lang_input_statement_struct *next_real_file;
332 const char *target;
334 struct lang_input_statement_flags flags;
335 } lang_input_statement_type;
337 typedef struct
339 lang_statement_header_type header;
340 asection *section;
341 void *pattern;
342 } lang_input_section_type;
344 typedef struct
346 lang_statement_header_type header;
347 asection *section;
348 void *pattern;
349 lang_input_statement_type *input_stmt;
350 } lang_input_matcher_type;
352 struct map_symbol_def {
353 struct bfd_link_hash_entry *entry;
354 struct map_symbol_def *next;
357 /* For input sections, when writing a map file: head / tail of a linked
358 list of hash table entries for symbols defined in this section. */
359 typedef struct input_section_userdata_struct
361 struct map_symbol_def *map_symbol_def_head;
362 struct map_symbol_def **map_symbol_def_tail;
363 unsigned long map_symbol_def_count;
364 } input_section_userdata_type;
366 static inline bool
367 bfd_input_just_syms (const bfd *abfd)
369 lang_input_statement_type *is = bfd_usrdata (abfd);
370 return is != NULL && is->flags.just_syms;
373 typedef struct lang_wild_statement_struct lang_wild_statement_type;
375 typedef void (*callback_t) (lang_wild_statement_type *, struct wildcard_list *,
376 asection *, lang_input_statement_type *, void *);
378 typedef void (*walk_wild_section_handler_t) (lang_wild_statement_type *,
379 lang_input_statement_type *,
380 callback_t callback,
381 void *data);
383 typedef bool (*lang_match_sec_type_func) (bfd *, const asection *,
384 bfd *, const asection *);
386 /* Binary search tree structure to efficiently sort sections by
387 name. */
388 typedef struct lang_section_bst
390 asection *section;
391 void *pattern;
392 struct lang_section_bst *left;
393 struct lang_section_bst *right;
394 } lang_section_bst_type;
396 struct lang_wild_statement_struct
398 lang_statement_header_type header;
399 lang_statement_list_type children;
400 lang_statement_list_type matching_sections;
401 lang_section_bst_type * tree;
402 lang_section_bst_type ** rightmost;
403 struct wildcard_list * section_list;
404 struct name_list * exclude_name_list;
405 struct flag_info * section_flag_list;
406 const char * filename;
407 bool filenames_sorted;
408 bool filenames_reversed;
409 bool any_specs_sorted;
410 bool keep_sections;
413 typedef struct lang_address_statement_struct
415 lang_statement_header_type header;
416 const char *section_name;
417 union etree_union *address;
418 const segment_type *segment;
419 } lang_address_statement_type;
421 typedef struct
423 lang_statement_header_type header;
424 bfd_vma output_offset;
425 bfd_size_type size;
426 asection *output_section;
427 fill_type *fill;
428 } lang_padding_statement_type;
430 /* A group statement collects a set of libraries together. The
431 libraries are searched multiple times, until no new undefined
432 symbols are found. The effect is to search a group of libraries as
433 though they were a single library. */
435 typedef struct
437 lang_statement_header_type header;
438 lang_statement_list_type children;
439 } lang_group_statement_type;
441 typedef struct
443 lang_statement_header_type header;
444 const char *where;
445 bool is_before;
446 } lang_insert_statement_type;
448 typedef union lang_statement_union
450 lang_statement_header_type header;
451 lang_address_statement_type address_statement;
452 lang_assignment_statement_type assignment_statement;
453 lang_data_statement_type data_statement;
454 lang_fill_statement_type fill_statement;
455 lang_group_statement_type group_statement;
456 lang_input_section_type input_section;
457 lang_input_matcher_type input_matcher;
458 lang_input_statement_type input_statement;
459 lang_insert_statement_type insert_statement;
460 lang_output_section_statement_type output_section_statement;
461 lang_output_statement_type output_statement;
462 lang_padding_statement_type padding_statement;
463 lang_reloc_statement_type reloc_statement;
464 lang_target_statement_type target_statement;
465 lang_wild_statement_type wild_statement;
466 } lang_statement_union_type;
468 /* This structure holds information about a program header, from the
469 PHDRS command in the linker script. */
471 struct lang_phdr
473 struct lang_phdr *next;
474 const char *name;
475 unsigned long type;
476 bool filehdr;
477 bool phdrs;
478 etree_type *at;
479 etree_type *flags;
482 /* This structure is used to hold a list of sections which may not
483 cross reference each other. */
485 typedef struct lang_nocrossref
487 struct lang_nocrossref *next;
488 const char *name;
489 } lang_nocrossref_type;
491 /* The list of nocrossref lists. */
493 struct lang_nocrossrefs
495 struct lang_nocrossrefs *next;
496 lang_nocrossref_type *list;
497 bool onlyfirst;
500 /* This structure is used to hold a list of input section names which
501 will not match an output section in the linker script. */
503 struct unique_sections
505 struct unique_sections *next;
506 const char *name;
509 /* Used by place_orphan to keep track of orphan sections and statements. */
511 struct orphan_save
513 const char *name;
514 flagword flags;
515 lang_output_section_statement_type *os;
516 asection **section;
517 lang_statement_union_type **stmt;
518 lang_output_section_statement_type **os_tail;
521 struct asneeded_minfo
523 struct asneeded_minfo *next;
524 const char *soname;
525 bfd *ref;
526 const char *name;
529 extern struct lang_phdr *lang_phdr_list;
530 extern struct lang_nocrossrefs *nocrossref_list;
531 extern const char *output_target;
532 extern lang_output_section_statement_type *abs_output_section;
533 extern lang_statement_list_type lang_os_list;
534 extern struct lang_input_statement_flags input_flags;
535 extern bool lang_has_input_file;
536 extern lang_statement_list_type statement_list;
537 extern lang_statement_list_type *stat_ptr;
538 extern bool delete_output_file_on_failure;
539 extern bool enable_linker_version;
541 extern struct bfd_sym_chain entry_symbol;
542 extern const char *entry_section;
543 extern bool entry_from_cmdline;
544 extern lang_statement_list_type file_chain;
545 extern lang_statement_list_type input_file_chain;
547 extern struct bfd_elf_dynamic_list **current_dynamic_list_p;
549 extern int lang_statement_iteration;
550 extern struct asneeded_minfo **asneeded_list_tail;
552 extern void (*output_bfd_hash_table_free_fn) (struct bfd_link_hash_table *);
554 extern void lang_init
555 (void);
556 extern void lang_finish
557 (void);
558 extern lang_memory_region_type * lang_memory_region_lookup
559 (const char * const, bool);
560 extern void lang_memory_region_alias
561 (const char *, const char *);
562 extern void lang_map
563 (void);
564 extern void lang_set_flags
565 (lang_memory_region_type *, const char *, int);
566 extern void lang_add_output
567 (const char *, int from_script);
568 extern lang_output_section_statement_type *lang_enter_output_section_statement
569 (const char *, etree_type *, enum section_type, etree_type *, etree_type *,
570 etree_type *, etree_type *, int, int);
571 extern void lang_final
572 (void);
573 extern void lang_relax_sections
574 (bool);
575 extern void lang_process
576 (void);
577 extern void lang_section_start
578 (const char *, union etree_union *, const segment_type *);
579 extern void lang_add_entry
580 (const char *, bool);
581 extern void lang_default_entry
582 (const char *);
583 extern void lang_add_target
584 (const char *);
585 extern void lang_add_wild
586 (struct wildcard_spec *, struct wildcard_list *, bool);
587 extern void lang_add_map
588 (const char *);
589 extern void lang_add_fill
590 (fill_type *);
591 extern lang_assignment_statement_type *lang_add_assignment
592 (union etree_union *);
593 extern void lang_add_attribute
594 (enum statement_enum);
595 extern void lang_startup
596 (const char *);
597 extern void lang_float
598 (bool);
599 extern void lang_leave_output_section_statement
600 (fill_type *, const char *, lang_output_section_phdr_list *,
601 const char *);
602 extern void lang_for_each_input_file
603 (void (*dothis) (lang_input_statement_type *));
604 extern void lang_for_each_file
605 (void (*dothis) (lang_input_statement_type *));
606 extern void lang_reset_memory_regions
607 (void);
608 extern void lang_do_assignments
609 (lang_phase_type);
610 extern asection *section_for_dot
611 (void);
613 #define LANG_FOR_EACH_INPUT_STATEMENT(statement) \
614 lang_input_statement_type *statement; \
615 for (statement = (lang_input_statement_type *) file_chain.head; \
616 statement != NULL; \
617 statement = statement->next)
619 #define lang_output_section_find(NAME) \
620 lang_output_section_statement_lookup (NAME, 0, 0)
622 extern void lang_process
623 (void);
624 extern void ldlang_add_file
625 (lang_input_statement_type *);
626 extern lang_output_section_statement_type *lang_output_section_find_by_flags
627 (const asection *, flagword, lang_output_section_statement_type **,
628 lang_match_sec_type_func);
629 extern lang_output_section_statement_type *lang_insert_orphan
630 (asection *, const char *, int, lang_output_section_statement_type *,
631 struct orphan_save *, etree_type *, lang_statement_list_type *);
632 extern lang_input_statement_type *lang_add_input_file
633 (const char *, lang_input_file_enum_type, const char *);
634 extern void lang_add_keepsyms_file
635 (const char *);
636 extern lang_output_section_statement_type *lang_output_section_get
637 (const asection *);
638 extern lang_output_section_statement_type *lang_output_section_statement_lookup
639 (const char *, int, int);
640 extern lang_output_section_statement_type *next_matching_output_section_statement
641 (lang_output_section_statement_type *, int);
642 extern void ldlang_add_undef
643 (const char *const, bool);
644 extern void ldlang_add_require_defined
645 (const char *const);
646 extern void lang_add_output_format
647 (const char *, const char *, const char *, int);
648 extern void lang_list_init
649 (lang_statement_list_type *);
650 extern void push_stat_ptr
651 (lang_statement_list_type *);
652 extern void pop_stat_ptr
653 (void);
654 extern void lang_add_data
655 (int, union etree_union *);
656 extern void lang_add_string
657 (const char *);
658 extern void lang_add_reloc
659 (bfd_reloc_code_real_type, reloc_howto_type *, asection *, const char *,
660 union etree_union *);
661 extern void lang_for_each_statement
662 (void (*) (lang_statement_union_type *));
663 extern void lang_for_each_statement_worker
664 (void (*) (lang_statement_union_type *), lang_statement_union_type *);
665 extern void *stat_alloc
666 (size_t);
667 extern void strip_excluded_output_sections
668 (void);
669 extern void lang_clear_os_map
670 (void);
671 extern void dprint_statement
672 (lang_statement_union_type *, int);
673 extern void lang_size_sections
674 (bool *, bool);
675 extern void one_lang_size_sections_pass
676 (bool *, bool);
677 extern void lang_add_insert
678 (const char *, int);
679 extern void lang_enter_group
680 (void);
681 extern void lang_leave_group
682 (void);
683 extern void lang_add_section
684 (lang_statement_list_type *, asection *, struct wildcard_list *,
685 struct flag_info *, lang_output_section_statement_type *);
686 extern void lang_new_phdr
687 (const char *, etree_type *, bool, bool, etree_type *,
688 etree_type *);
689 extern void lang_add_nocrossref
690 (lang_nocrossref_type *);
691 extern void lang_add_nocrossref_to
692 (lang_nocrossref_type *);
693 extern void lang_enter_overlay
694 (etree_type *, etree_type *);
695 extern void lang_enter_overlay_section
696 (const char *);
697 extern void lang_leave_overlay_section
698 (fill_type *, lang_output_section_phdr_list *);
699 extern void lang_leave_overlay
700 (etree_type *, int, fill_type *, const char *,
701 lang_output_section_phdr_list *, const char *);
703 extern struct bfd_elf_version_expr *lang_new_vers_pattern
704 (struct bfd_elf_version_expr *, const char *, const char *, bool);
705 extern struct bfd_elf_version_tree *lang_new_vers_node
706 (struct bfd_elf_version_expr *, struct bfd_elf_version_expr *);
707 extern struct bfd_elf_version_deps *lang_add_vers_depend
708 (struct bfd_elf_version_deps *, const char *);
709 extern void lang_register_vers_node
710 (const char *, struct bfd_elf_version_tree *, struct bfd_elf_version_deps *);
711 extern void lang_append_dynamic_list (struct bfd_elf_dynamic_list **,
712 struct bfd_elf_version_expr *);
713 extern void lang_append_dynamic_list_cpp_typeinfo (void);
714 extern void lang_append_dynamic_list_cpp_new (void);
715 extern void lang_add_unique
716 (const char *);
717 extern const char *lang_get_output_target
718 (void);
719 extern void add_excluded_libs (const char *);
720 extern bool load_symbols
721 (lang_input_statement_type *, lang_statement_list_type *);
723 struct elf_sym_strtab;
724 struct elf_strtab_hash;
725 extern void ldlang_ctf_acquire_strings
726 (struct elf_strtab_hash *);
727 extern void ldlang_ctf_new_dynsym
728 (int symidx, struct elf_internal_sym *);
729 extern void ldlang_write_ctf_late
730 (void);
731 extern bool
732 ldlang_override_segment_assignment
733 (struct bfd_link_info *, bfd *, asection *, asection *, bool);
735 extern void
736 lang_ld_feature (char *);
738 extern void
739 lang_print_memory_usage (void);
741 extern void
742 lang_add_gc_name (const char *);
744 extern bool
745 print_one_symbol (struct bfd_link_hash_entry *, void *);
747 extern void lang_add_version_string
748 (void);
749 #endif