Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* ldlang.h - linker command language support |
a2b64bed | 2 | Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, |
e3dc8847 | 3 | 2001, 2002 |
aa8804e4 | 4 | Free Software Foundation, Inc. |
5cc18311 | 5 | |
252b5132 | 6 | This file is part of GLD, the Gnu Linker. |
5cc18311 | 7 | |
252b5132 RH |
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 | |
e3dc8847 | 10 | the Free Software Foundation; either version 2, or (at your option) |
252b5132 | 11 | any later version. |
5cc18311 | 12 | |
252b5132 RH |
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. | |
5cc18311 | 17 | |
252b5132 RH |
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 | ||
89cdebba | 26 | typedef enum { |
252b5132 RH |
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 | ||
2c382fb6 AM |
35 | struct _fill_type { |
36 | size_t size; | |
37 | unsigned char data[1]; | |
38 | }; | |
89cdebba KH |
39 | |
40 | typedef struct statement_list { | |
252b5132 RH |
41 | union lang_statement_union *head; |
42 | union lang_statement_union **tail; | |
43 | } lang_statement_list_type; | |
44 | ||
89cdebba | 45 | typedef struct memory_region_struct { |
252b5132 RH |
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 | boolean had_full_message; | |
89cdebba KH |
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; | |
252b5132 RH |
78 | } lang_statement_header_type; |
79 | ||
89cdebba | 80 | typedef struct { |
252b5132 RH |
81 | lang_statement_header_type header; |
82 | union etree_union *exp; | |
83 | } lang_assignment_statement_type; | |
84 | ||
89cdebba | 85 | typedef struct lang_target_statement_struct { |
252b5132 RH |
86 | lang_statement_header_type header; |
87 | const char *target; | |
88 | } lang_target_statement_type; | |
89 | ||
89cdebba | 90 | typedef struct lang_output_statement_struct { |
252b5132 RH |
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 | ||
89cdebba | 97 | enum section_type { |
252b5132 RH |
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 | ||
89cdebba | 109 | struct lang_output_section_phdr_list { |
252b5132 RH |
110 | struct lang_output_section_phdr_list *next; |
111 | const char *name; | |
112 | boolean used; | |
113 | }; | |
114 | ||
89cdebba | 115 | typedef struct lang_output_section_statement_struct { |
252b5132 RH |
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 | boolean processed; | |
5cc18311 | 124 | |
252b5132 RH |
125 | asection *bfd_section; |
126 | flagword flags; /* Or together of all input sections */ | |
127 | enum section_type sectype; | |
128 | struct memory_region_struct *region; | |
562d3460 | 129 | struct memory_region_struct *lma_region; |
252b5132 | 130 | size_t block_value; |
2c382fb6 | 131 | fill_type *fill; |
252b5132 | 132 | |
89cdebba KH |
133 | int subsection_alignment; /* alignment of components */ |
134 | int section_alignment; /* alignment of start of section */ | |
252b5132 RH |
135 | |
136 | union etree_union *load_base; | |
137 | ||
138 | struct lang_output_section_phdr_list *phdrs; | |
139 | } lang_output_section_statement_type; | |
140 | ||
89cdebba | 141 | typedef struct { |
252b5132 RH |
142 | lang_statement_header_type header; |
143 | } lang_common_statement_type; | |
144 | ||
89cdebba | 145 | typedef struct { |
252b5132 RH |
146 | lang_statement_header_type header; |
147 | } lang_object_symbols_statement_type; | |
148 | ||
89cdebba | 149 | typedef struct { |
252b5132 | 150 | lang_statement_header_type header; |
2c382fb6 | 151 | fill_type *fill; |
252b5132 RH |
152 | int size; |
153 | asection *output_section; | |
154 | } lang_fill_statement_type; | |
155 | ||
89cdebba | 156 | typedef struct { |
252b5132 RH |
157 | lang_statement_header_type header; |
158 | unsigned int type; | |
89cdebba | 159 | union etree_union *exp; |
252b5132 RH |
160 | bfd_vma value; |
161 | asection *output_section; | |
162 | bfd_vma output_vma; | |
163 | } lang_data_statement_type; | |
164 | ||
165 | /* Generate a reloc in the output file. */ | |
166 | ||
89cdebba | 167 | typedef struct { |
252b5132 RH |
168 | lang_statement_header_type header; |
169 | ||
170 | /* Reloc to generate. */ | |
171 | bfd_reloc_code_real_type reloc; | |
172 | ||
173 | /* Reloc howto structure. */ | |
174 | reloc_howto_type *howto; | |
175 | ||
176 | /* Section to generate reloc against. Exactly one of section and | |
177 | name must be NULL. */ | |
178 | asection *section; | |
179 | ||
180 | /* Name of symbol to generate reloc against. Exactly one of section | |
181 | and name must be NULL. */ | |
182 | const char *name; | |
183 | ||
184 | /* Expression for addend. */ | |
185 | union etree_union *addend_exp; | |
186 | ||
187 | /* Resolved addend. */ | |
188 | bfd_vma addend_value; | |
189 | ||
190 | /* Output section where reloc should be performed. */ | |
191 | asection *output_section; | |
192 | ||
193 | /* VMA within output section. */ | |
194 | bfd_vma output_vma; | |
195 | } lang_reloc_statement_type; | |
196 | ||
89cdebba | 197 | typedef struct lang_input_statement_struct { |
252b5132 RH |
198 | lang_statement_header_type header; |
199 | /* Name of this file. */ | |
200 | const char *filename; | |
201 | /* Name to use for the symbol giving address of text start */ | |
202 | /* Usually the same as filename, but for a file spec'd with -l | |
203 | this is the -l switch itself rather than the filename. */ | |
204 | const char *local_sym_name; | |
5cc18311 | 205 | |
252b5132 | 206 | bfd *the_bfd; |
5cc18311 | 207 | |
252b5132 RH |
208 | boolean closed; |
209 | file_ptr passive_position; | |
5cc18311 | 210 | |
252b5132 RH |
211 | /* Symbol table of the file. */ |
212 | asymbol **asymbols; | |
213 | unsigned int symbol_count; | |
5cc18311 | 214 | |
252b5132 RH |
215 | /* Point to the next file - whatever it is, wanders up and down |
216 | archives */ | |
5cc18311 | 217 | |
89cdebba | 218 | union lang_statement_union *next; |
252b5132 | 219 | /* Point to the next file, but skips archive contents */ |
89cdebba | 220 | union lang_statement_union *next_real_file; |
5cc18311 | 221 | |
252b5132 | 222 | boolean is_archive; |
5cc18311 | 223 | |
252b5132 RH |
224 | /* 1 means search a set of directories for this file. */ |
225 | boolean search_dirs_flag; | |
5cc18311 | 226 | |
252b5132 RH |
227 | /* 1 means this is base file of incremental load. |
228 | Do not load this file's text or data. | |
5cc18311 KH |
229 | Also default text_start to after this file's bss. */ |
230 | ||
252b5132 RH |
231 | boolean just_syms_flag; |
232 | ||
233 | /* Whether to search for this entry as a dynamic archive. */ | |
234 | boolean dynamic; | |
235 | ||
236 | /* Whether to include the entire contents of an archive. */ | |
237 | boolean whole_archive; | |
238 | ||
239 | boolean loaded; | |
5cc18311 | 240 | |
89cdebba KH |
241 | #if 0 |
242 | unsigned int globals_in_this_file; | |
243 | #endif | |
252b5132 RH |
244 | const char *target; |
245 | boolean real; | |
246 | } lang_input_statement_type; | |
247 | ||
89cdebba | 248 | typedef struct { |
252b5132 RH |
249 | lang_statement_header_type header; |
250 | asection *section; | |
251 | lang_input_statement_type *ifile; | |
252b5132 | 252 | |
5cc18311 | 253 | } lang_input_section_type; |
252b5132 | 254 | |
89cdebba | 255 | typedef struct { |
252b5132 RH |
256 | lang_statement_header_type header; |
257 | asection *section; | |
258 | union lang_statement_union *file; | |
259 | } lang_afile_asection_pair_statement_type; | |
260 | ||
89cdebba | 261 | typedef struct lang_wild_statement_struct { |
252b5132 | 262 | lang_statement_header_type header; |
252b5132 RH |
263 | const char *filename; |
264 | boolean filenames_sorted; | |
b6bf44ba | 265 | struct wildcard_list *section_list; |
252b5132 | 266 | boolean keep_sections; |
252b5132 RH |
267 | lang_statement_list_type children; |
268 | } lang_wild_statement_type; | |
269 | ||
89cdebba | 270 | typedef struct lang_address_statement_struct { |
252b5132 | 271 | lang_statement_header_type header; |
89cdebba KH |
272 | const char *section_name; |
273 | union etree_union *address; | |
252b5132 RH |
274 | } lang_address_statement_type; |
275 | ||
89cdebba | 276 | typedef struct { |
252b5132 RH |
277 | lang_statement_header_type header; |
278 | bfd_vma output_offset; | |
279 | size_t size; | |
280 | asection *output_section; | |
2c382fb6 | 281 | fill_type *fill; |
252b5132 RH |
282 | } lang_padding_statement_type; |
283 | ||
284 | /* A group statement collects a set of libraries together. The | |
285 | libraries are searched multiple times, until no new undefined | |
286 | symbols are found. The effect is to search a group of libraries as | |
287 | though they were a single library. */ | |
288 | ||
89cdebba | 289 | typedef struct { |
252b5132 RH |
290 | lang_statement_header_type header; |
291 | lang_statement_list_type children; | |
292 | } lang_group_statement_type; | |
293 | ||
89cdebba | 294 | typedef union lang_statement_union { |
252b5132 | 295 | lang_statement_header_type header; |
252b5132 RH |
296 | lang_wild_statement_type wild_statement; |
297 | lang_data_statement_type data_statement; | |
298 | lang_reloc_statement_type reloc_statement; | |
299 | lang_address_statement_type address_statement; | |
300 | lang_output_section_statement_type output_section_statement; | |
301 | lang_afile_asection_pair_statement_type afile_asection_pair_statement; | |
302 | lang_assignment_statement_type assignment_statement; | |
303 | lang_input_statement_type input_statement; | |
304 | lang_target_statement_type target_statement; | |
305 | lang_output_statement_type output_statement; | |
306 | lang_input_section_type input_section; | |
307 | lang_common_statement_type common_statement; | |
308 | lang_object_symbols_statement_type object_symbols_statement; | |
309 | lang_fill_statement_type fill_statement; | |
310 | lang_padding_statement_type padding_statement; | |
311 | lang_group_statement_type group_statement; | |
312 | } lang_statement_union_type; | |
313 | ||
314 | /* This structure holds information about a program header, from the | |
315 | PHDRS command in the linker script. */ | |
316 | ||
89cdebba | 317 | struct lang_phdr { |
252b5132 RH |
318 | struct lang_phdr *next; |
319 | const char *name; | |
320 | unsigned long type; | |
321 | boolean filehdr; | |
322 | boolean phdrs; | |
323 | etree_type *at; | |
324 | etree_type *flags; | |
325 | }; | |
326 | ||
327 | /* This structure is used to hold a list of sections which may not | |
328 | cross reference each other. */ | |
329 | ||
89cdebba | 330 | struct lang_nocrossref { |
252b5132 RH |
331 | struct lang_nocrossref *next; |
332 | const char *name; | |
333 | }; | |
334 | ||
335 | /* The list of nocrossref lists. */ | |
336 | ||
89cdebba | 337 | struct lang_nocrossrefs { |
252b5132 RH |
338 | struct lang_nocrossrefs *next; |
339 | struct lang_nocrossref *list; | |
340 | }; | |
341 | ||
342 | extern struct lang_nocrossrefs *nocrossref_list; | |
343 | ||
577a0623 AM |
344 | /* This structure is used to hold a list of input section names which |
345 | will not match an output section in the linker script. */ | |
346 | ||
347 | struct unique_sections { | |
348 | struct unique_sections *next; | |
349 | const char *name; | |
350 | }; | |
351 | ||
352 | extern struct unique_sections *unique_section_list; | |
353 | ||
252b5132 | 354 | extern lang_output_section_statement_type *abs_output_section; |
aea4bd9d | 355 | extern lang_statement_list_type lang_output_section_statement; |
252b5132 RH |
356 | extern boolean lang_has_input_file; |
357 | extern etree_type *base; | |
358 | extern lang_statement_list_type *stat_ptr; | |
359 | extern boolean delete_output_file_on_failure; | |
360 | ||
361 | extern const char *entry_symbol; | |
1e281515 | 362 | extern const char *entry_section; |
252b5132 | 363 | extern boolean entry_from_cmdline; |
b71e2778 | 364 | extern lang_statement_list_type file_chain; |
252b5132 RH |
365 | |
366 | extern void lang_init PARAMS ((void)); | |
367 | extern struct memory_region_struct *lang_memory_region_lookup | |
368 | PARAMS ((const char *const)); | |
369 | extern struct memory_region_struct *lang_memory_region_default | |
370 | PARAMS ((asection *)); | |
371 | extern void lang_map PARAMS ((void)); | |
aa8804e4 ILT |
372 | extern void lang_set_flags PARAMS ((lang_memory_region_type *, const char *, |
373 | int)); | |
252b5132 | 374 | extern void lang_add_output PARAMS ((const char *, int from_script)); |
aea4bd9d | 375 | extern lang_output_section_statement_type *lang_enter_output_section_statement |
252b5132 RH |
376 | PARAMS ((const char *output_section_statement_name, |
377 | etree_type * address_exp, | |
378 | enum section_type sectype, | |
379 | bfd_vma block_value, | |
380 | etree_type *align, | |
381 | etree_type *subalign, | |
382 | etree_type *)); | |
383 | extern void lang_final PARAMS ((void)); | |
384 | extern void lang_process PARAMS ((void)); | |
385 | extern void lang_section_start PARAMS ((const char *, union etree_union *)); | |
386 | extern void lang_add_entry PARAMS ((const char *, boolean)); | |
387 | extern void lang_add_target PARAMS ((const char *)); | |
388 | extern void lang_add_wild | |
b6bf44ba | 389 | PARAMS ((struct wildcard_spec *, struct wildcard_list *, boolean)); |
252b5132 | 390 | extern void lang_add_map PARAMS ((const char *)); |
2c382fb6 | 391 | extern void lang_add_fill PARAMS ((fill_type *)); |
252b5132 RH |
392 | extern lang_assignment_statement_type * lang_add_assignment PARAMS ((union etree_union *)); |
393 | extern void lang_add_attribute PARAMS ((enum statement_enum)); | |
394 | extern void lang_startup PARAMS ((const char *)); | |
395 | extern void lang_float PARAMS ((enum bfd_boolean)); | |
396 | extern void lang_leave_output_section_statement | |
2c382fb6 | 397 | PARAMS ((fill_type *, const char *, struct lang_output_section_phdr_list *, |
562d3460 | 398 | const char *)); |
252b5132 RH |
399 | extern void lang_abs_symbol_at_end_of PARAMS ((const char *, const char *)); |
400 | extern void lang_abs_symbol_at_beginning_of PARAMS ((const char *, | |
401 | const char *)); | |
402 | extern void lang_statement_append PARAMS ((struct statement_list *, | |
403 | union lang_statement_union *, | |
404 | union lang_statement_union **)); | |
405 | extern void lang_for_each_input_file | |
406 | PARAMS ((void (*dothis) (lang_input_statement_type *))); | |
407 | extern void lang_for_each_file | |
408 | PARAMS ((void (*dothis) (lang_input_statement_type *))); | |
e3dc8847 | 409 | extern void lang_reset_memory_regions PARAMS ((void)); |
252b5132 RH |
410 | extern bfd_vma lang_do_assignments |
411 | PARAMS ((lang_statement_union_type * s, | |
412 | lang_output_section_statement_type *output_section_statement, | |
2c382fb6 | 413 | fill_type *fill, |
252b5132 RH |
414 | bfd_vma dot)); |
415 | ||
416 | #define LANG_FOR_EACH_INPUT_STATEMENT(statement) \ | |
252b5132 RH |
417 | lang_input_statement_type *statement; \ |
418 | for (statement = (lang_input_statement_type *)file_chain.head;\ | |
419 | statement != (lang_input_statement_type *)NULL; \ | |
420 | statement = (lang_input_statement_type *)statement->next)\ | |
5cc18311 | 421 | |
252b5132 RH |
422 | extern void lang_process PARAMS ((void)); |
423 | extern void ldlang_add_file PARAMS ((lang_input_statement_type *)); | |
424 | extern lang_output_section_statement_type *lang_output_section_find | |
425 | PARAMS ((const char * const)); | |
426 | extern lang_input_statement_type *lang_add_input_file | |
427 | PARAMS ((const char *name, lang_input_file_enum_type file_type, | |
428 | const char *target)); | |
429 | extern void lang_add_keepsyms_file PARAMS ((const char *filename)); | |
430 | extern lang_output_section_statement_type * | |
431 | lang_output_section_statement_lookup PARAMS ((const char * const name)); | |
432 | extern void ldlang_add_undef PARAMS ((const char *const name)); | |
433 | extern void lang_add_output_format PARAMS ((const char *, const char *, | |
434 | const char *, int from_script)); | |
435 | extern void lang_list_init PARAMS ((lang_statement_list_type*)); | |
436 | extern void lang_add_data PARAMS ((int type, union etree_union *)); | |
437 | extern void lang_add_reloc | |
438 | PARAMS ((bfd_reloc_code_real_type reloc, reloc_howto_type *howto, | |
439 | asection *section, const char *name, union etree_union *addend)); | |
440 | extern void lang_for_each_statement | |
441 | PARAMS ((void (*func) (lang_statement_union_type *))); | |
442 | extern PTR stat_alloc PARAMS ((size_t size)); | |
443 | extern void dprint_statement PARAMS ((lang_statement_union_type *, int)); | |
444 | extern bfd_vma lang_size_sections | |
445 | PARAMS ((lang_statement_union_type *s, | |
446 | lang_output_section_statement_type *output_section_statement, | |
2c382fb6 | 447 | lang_statement_union_type **prev, fill_type *fill, |
b3327aad | 448 | bfd_vma dot, boolean *relax)); |
252b5132 RH |
449 | extern void lang_enter_group PARAMS ((void)); |
450 | extern void lang_leave_group PARAMS ((void)); | |
39dcfe18 | 451 | extern void lang_add_section |
252b5132 RH |
452 | PARAMS ((lang_statement_list_type *ptr, asection *section, |
453 | lang_output_section_statement_type *output, | |
454 | lang_input_statement_type *file)); | |
455 | extern void lang_new_phdr | |
456 | PARAMS ((const char *, etree_type *, boolean, boolean, etree_type *, | |
457 | etree_type *)); | |
458 | extern void lang_add_nocrossref PARAMS ((struct lang_nocrossref *)); | |
459 | extern void lang_enter_overlay PARAMS ((etree_type *, etree_type *, int)); | |
460 | extern void lang_enter_overlay_section PARAMS ((const char *)); | |
461 | extern void lang_leave_overlay_section | |
2c382fb6 | 462 | PARAMS ((fill_type *, struct lang_output_section_phdr_list *)); |
252b5132 | 463 | extern void lang_leave_overlay |
2c382fb6 | 464 | PARAMS ((fill_type *, const char *, struct lang_output_section_phdr_list *, |
562d3460 | 465 | const char *)); |
252b5132 RH |
466 | |
467 | extern struct bfd_elf_version_tree *lang_elf_version_info; | |
468 | ||
313e35ee | 469 | extern struct bfd_elf_version_expr *lang_new_vers_pattern |
252b5132 RH |
470 | PARAMS ((struct bfd_elf_version_expr *, const char *, const char *)); |
471 | extern struct bfd_elf_version_tree *lang_new_vers_node | |
472 | PARAMS ((struct bfd_elf_version_expr *, struct bfd_elf_version_expr *)); | |
473 | extern struct bfd_elf_version_deps *lang_add_vers_depend | |
474 | PARAMS ((struct bfd_elf_version_deps *, const char *)); | |
475 | extern void lang_register_vers_node | |
476 | PARAMS ((const char *, struct bfd_elf_version_tree *, | |
477 | struct bfd_elf_version_deps *)); | |
577a0623 AM |
478 | boolean unique_section_p PARAMS ((const char *)); |
479 | extern void lang_add_unique PARAMS ((const char *)); | |
252b5132 RH |
480 | |
481 | #endif |