Commit | Line | Data |
---|---|---|
e20873a7 | 1 | /* Linker command language support. |
0b2f8d2e | 2 | Copyright (C) 1991, 92, 93, 94 Free Software Foundation, Inc. |
075d7359 | 3 | |
2fa0b342 DHW |
4 | This file is part of GLD, the Gnu Linker. |
5 | ||
6 | GLD 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 1, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GLD 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. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GLD; see the file COPYING. If not, write to | |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | ||
2fa0b342 | 20 | #include "bfd.h" |
075d7359 | 21 | #include "sysdep.h" |
4c2123b6 | 22 | #include "libiberty.h" |
c477527c | 23 | #include "bfdlink.h" |
2fa0b342 DHW |
24 | |
25 | #include "ld.h" | |
fcf276c4 | 26 | #include "ldmain.h" |
7bc4a0d7 | 27 | #include "ldgram.h" |
2fa0b342 | 28 | #include "ldexp.h" |
fcf276c4 | 29 | #include "ldlang.h" |
8c514453 | 30 | #include "ldemul.h" |
2fa0b342 | 31 | #include "ldlex.h" |
3f8d46e7 | 32 | #include "ldmisc.h" |
c611e285 | 33 | #include "ldctor.h" |
fcf276c4 | 34 | #include "ldfile.h" |
b98bd3db | 35 | |
2fa0b342 | 36 | /* FORWARDS */ |
e20873a7 JG |
37 | static void print_statements PARAMS ((void)); |
38 | static void print_statement PARAMS ((lang_statement_union_type *, | |
075d7359 | 39 | lang_output_section_statement_type *)); |
5af8e9d6 KR |
40 | static lang_statement_union_type *new_statement PARAMS ((enum statement_enum, |
41 | size_t, | |
42 | lang_statement_list_type*)); | |
43 | ||
2fa0b342 | 44 | |
d4c02e29 | 45 | /* LOCALS */ |
bfbdc80f | 46 | static struct obstack stat_obstack; |
075d7359 | 47 | |
0b2f8d2e | 48 | #define obstack_chunk_alloc xmalloc |
bfbdc80f | 49 | #define obstack_chunk_free free |
075d7359 | 50 | static CONST char *startup_file; |
d4c02e29 SC |
51 | static lang_statement_list_type input_file_chain; |
52 | static boolean placed_commons = false; | |
53 | static lang_output_section_statement_type *default_common_section; | |
54 | static boolean map_option_f; | |
55 | static bfd_vma print_dot; | |
56 | static lang_input_statement_type *first_file; | |
57 | static lang_statement_list_type lang_output_section_statement; | |
58 | static CONST char *current_target; | |
59 | static CONST char *output_target; | |
fcf276c4 | 60 | static int longest_section_name = 8; |
d4c02e29 | 61 | static lang_statement_list_type statement_list; |
ffc50032 | 62 | |
9f629407 ILT |
63 | static void print_size PARAMS ((size_t value)); |
64 | static void print_alignment PARAMS ((unsigned int value)); | |
65 | static void print_fill PARAMS ((fill_type value)); | |
66 | static void print_section PARAMS ((const char *name)); | |
67 | static void lang_for_each_statement_worker | |
68 | PARAMS ((void (*func) (lang_statement_union_type *), | |
69 | lang_statement_union_type *s)); | |
70 | static lang_input_statement_type *new_afile | |
71 | PARAMS ((const char *name, lang_input_file_enum_type file_type, | |
193c5f93 | 72 | const char *target, boolean add_to_list)); |
9f629407 ILT |
73 | static void print_flags PARAMS ((int *ignore_flags)); |
74 | static void init_os PARAMS ((lang_output_section_statement_type *s)); | |
9f629407 ILT |
75 | static void wild_section PARAMS ((lang_wild_statement_type *ptr, |
76 | const char *section, | |
77 | lang_input_statement_type *file, | |
78 | lang_output_section_statement_type *output)); | |
193c5f93 ILT |
79 | static lang_input_statement_type *lookup_name PARAMS ((const char *name)); |
80 | static void load_symbols PARAMS ((lang_input_statement_type *entry)); | |
9f629407 ILT |
81 | static void wild PARAMS ((lang_wild_statement_type *s, |
82 | const char *section, const char *file, | |
83 | const char *target, | |
84 | lang_output_section_statement_type *output)); | |
85 | static bfd *open_output PARAMS ((const char *name)); | |
86 | static void ldlang_open_output PARAMS ((lang_statement_union_type *statement)); | |
309c8153 ILT |
87 | static void open_input_bfds |
88 | PARAMS ((lang_statement_union_type *statement, boolean)); | |
9f629407 ILT |
89 | static void lang_reasonable_defaults PARAMS ((void)); |
90 | static void lang_place_undefineds PARAMS ((void)); | |
9f629407 ILT |
91 | static void map_input_to_output_sections |
92 | PARAMS ((lang_statement_union_type *s, | |
93 | const char *target, | |
94 | lang_output_section_statement_type *output_section_statement)); | |
95 | static void print_output_section_statement | |
96 | PARAMS ((lang_output_section_statement_type *output_section_statement)); | |
97 | static void print_assignment | |
98 | PARAMS ((lang_assignment_statement_type *assignment, | |
99 | lang_output_section_statement_type *output_section)); | |
100 | static void print_input_statement PARAMS ((lang_input_statement_type *statm)); | |
9f629407 ILT |
101 | static void print_input_section PARAMS ((lang_input_section_type *in)); |
102 | static void print_fill_statement PARAMS ((lang_fill_statement_type *fill)); | |
103 | static void print_data_statement PARAMS ((lang_data_statement_type *data)); | |
4fdbafb2 | 104 | static void print_reloc_statement PARAMS ((lang_reloc_statement_type *reloc)); |
9f629407 ILT |
105 | static void print_padding_statement PARAMS ((lang_padding_statement_type *s)); |
106 | static void print_wild_statement | |
107 | PARAMS ((lang_wild_statement_type *w, | |
108 | lang_output_section_statement_type *os)); | |
309c8153 ILT |
109 | static void print_group |
110 | PARAMS ((lang_group_statement_type *, lang_output_section_statement_type *)); | |
9f629407 ILT |
111 | static void print_statement PARAMS ((lang_statement_union_type *s, |
112 | lang_output_section_statement_type *os)); | |
113 | static void print_statements PARAMS ((void)); | |
114 | static bfd_vma insert_pad PARAMS ((lang_statement_union_type **this_ptr, | |
115 | fill_type fill, unsigned int power, | |
116 | asection *output_section_statement, | |
117 | bfd_vma dot)); | |
118 | static bfd_vma size_input_section | |
119 | PARAMS ((lang_statement_union_type **this_ptr, | |
120 | lang_output_section_statement_type *output_section_statement, | |
c477527c | 121 | fill_type fill, bfd_vma dot, boolean relax)); |
9f629407 ILT |
122 | static void lang_finish PARAMS ((void)); |
123 | static void lang_check PARAMS ((void)); | |
124 | static void lang_common PARAMS ((void)); | |
c477527c | 125 | static boolean lang_one_common PARAMS ((struct bfd_link_hash_entry *, PTR)); |
9f629407 ILT |
126 | static void lang_place_orphans PARAMS ((void)); |
127 | static int topower PARAMS ((int)); | |
128 | static void reset_memory_regions PARAMS ((void)); | |
129 | ||
2fa0b342 | 130 | /* EXPORTS */ |
ffc50032 | 131 | lang_output_section_statement_type *abs_output_section; |
d4c02e29 | 132 | lang_statement_list_type *stat_ptr = &statement_list; |
a4d2a48e | 133 | lang_statement_list_type file_chain = { 0 }; |
60e8a534 | 134 | static const char *entry_symbol = 0; |
d4c02e29 | 135 | boolean lang_has_input_file = false; |
d4c02e29 SC |
136 | boolean had_output_filename = false; |
137 | boolean lang_float_flag = false; | |
97fbbaca | 138 | boolean delete_output_file_on_failure = false; |
075d7359 | 139 | |
9fce28ed SC |
140 | etree_type *base; /* Relocation base - or null */ |
141 | ||
142 | ||
b897ed67 | 143 | #if defined(__STDC__) || defined(ALMOST_STDC) |
2fa0b342 DHW |
144 | #define cat(a,b) a##b |
145 | #else | |
146 | #define cat(a,b) a/**/b | |
147 | #endif | |
148 | ||
149 | #define new_stat(x,y) (cat(x,_type)*) new_statement(cat(x,_enum), sizeof(cat(x,_type)),y) | |
150 | ||
151 | #define outside_section_address(q) ( (q)->output_offset + (q)->output_section->vma) | |
152 | ||
153 | #define outside_symbol_address(q) ((q)->value + outside_section_address(q->section)) | |
154 | ||
bfbdc80f | 155 | PTR |
8ddef552 DM |
156 | stat_alloc (size) |
157 | size_t size; | |
bfbdc80f | 158 | { |
075d7359 | 159 | return obstack_alloc (&stat_obstack, size); |
bfbdc80f | 160 | } |
9f629407 | 161 | |
075d7359 | 162 | static void |
8ddef552 DM |
163 | print_size (value) |
164 | size_t value; | |
3f8d46e7 | 165 | { |
075d7359 | 166 | fprintf (config.map_file, "%5x", (unsigned) value); |
3f8d46e7 | 167 | } |
9f629407 | 168 | |
075d7359 | 169 | static void |
8ddef552 DM |
170 | print_alignment (value) |
171 | unsigned int value; | |
3f8d46e7 | 172 | { |
075d7359 | 173 | fprintf (config.map_file, "2**%1u", value); |
3f8d46e7 | 174 | } |
9f629407 | 175 | |
075d7359 | 176 | static void |
9f629407 ILT |
177 | print_fill (value) |
178 | fill_type value; | |
3f8d46e7 | 179 | { |
075d7359 | 180 | fprintf (config.map_file, "%04x", (unsigned) value); |
3f8d46e7 JG |
181 | } |
182 | ||
075d7359 | 183 | static void |
8ddef552 | 184 | print_section (name) |
9f629407 | 185 | CONST char *name; |
3f8d46e7 | 186 | { |
075d7359 | 187 | fprintf (config.map_file, "%*s", -longest_section_name, name); |
3f8d46e7 | 188 | } |
2fa0b342 | 189 | |
1418c83b SC |
190 | /*---------------------------------------------------------------------- |
191 | lang_for_each_statement walks the parse tree and calls the provided | |
192 | function for each node | |
193 | */ | |
194 | ||
075d7359 | 195 | static void |
8ddef552 | 196 | lang_for_each_statement_worker (func, s) |
c477527c | 197 | void (*func) PARAMS ((lang_statement_union_type *)); |
8ddef552 | 198 | lang_statement_union_type *s; |
1418c83b | 199 | { |
075d7359 SC |
200 | for (; s != (lang_statement_union_type *) NULL; s = s->next) |
201 | { | |
202 | func (s); | |
1418c83b | 203 | |
075d7359 SC |
204 | switch (s->header.type) |
205 | { | |
81016051 | 206 | case lang_constructors_statement_enum: |
075d7359 | 207 | lang_for_each_statement_worker (func, constructor_list.head); |
81016051 | 208 | break; |
1418c83b SC |
209 | case lang_output_section_statement_enum: |
210 | lang_for_each_statement_worker | |
075d7359 | 211 | (func, |
1418c83b SC |
212 | s->output_section_statement.children.head); |
213 | break; | |
214 | case lang_wild_statement_enum: | |
215 | lang_for_each_statement_worker | |
075d7359 | 216 | (func, |
1418c83b SC |
217 | s->wild_statement.children.head); |
218 | break; | |
309c8153 ILT |
219 | case lang_group_statement_enum: |
220 | lang_for_each_statement_worker (func, | |
221 | s->group_statement.children.head); | |
222 | break; | |
1418c83b | 223 | case lang_data_statement_enum: |
4fdbafb2 | 224 | case lang_reloc_statement_enum: |
1418c83b SC |
225 | case lang_object_symbols_statement_enum: |
226 | case lang_output_statement_enum: | |
227 | case lang_target_statement_enum: | |
228 | case lang_input_section_enum: | |
229 | case lang_input_statement_enum: | |
1418c83b SC |
230 | case lang_assignment_statement_enum: |
231 | case lang_padding_statement_enum: | |
232 | case lang_address_statement_enum: | |
233 | break; | |
234 | default: | |
075d7359 | 235 | FAIL (); |
1418c83b SC |
236 | break; |
237 | } | |
075d7359 | 238 | } |
1418c83b SC |
239 | } |
240 | ||
241 | void | |
8ddef552 | 242 | lang_for_each_statement (func) |
c477527c | 243 | void (*func) PARAMS ((lang_statement_union_type *)); |
1418c83b | 244 | { |
075d7359 SC |
245 | lang_for_each_statement_worker (func, |
246 | statement_list.head); | |
1418c83b | 247 | } |
075d7359 | 248 | |
1418c83b | 249 | /*----------------------------------------------------------------------*/ |
075d7359 | 250 | void |
8ddef552 DM |
251 | lang_list_init (list) |
252 | lang_statement_list_type *list; | |
2fa0b342 | 253 | { |
075d7359 SC |
254 | list->head = (lang_statement_union_type *) NULL; |
255 | list->tail = &list->head; | |
2fa0b342 DHW |
256 | } |
257 | ||
1418c83b | 258 | /*---------------------------------------------------------------------- |
075d7359 | 259 | |
1418c83b SC |
260 | build a new statement node for the parse tree |
261 | ||
262 | */ | |
2fa0b342 DHW |
263 | |
264 | static | |
075d7359 | 265 | lang_statement_union_type * |
8ddef552 DM |
266 | new_statement (type, size, list) |
267 | enum statement_enum type; | |
5af8e9d6 | 268 | size_t size; |
8ddef552 | 269 | lang_statement_list_type * list; |
2fa0b342 DHW |
270 | { |
271 | lang_statement_union_type *new = (lang_statement_union_type *) | |
075d7359 SC |
272 | stat_alloc (size); |
273 | ||
2fa0b342 | 274 | new->header.type = type; |
075d7359 SC |
275 | new->header.next = (lang_statement_union_type *) NULL; |
276 | lang_statement_append (list, new, &new->header.next); | |
2fa0b342 DHW |
277 | return new; |
278 | } | |
279 | ||
1418c83b SC |
280 | /* |
281 | Build a new input file node for the language. There are several ways | |
282 | in which we treat an input file, eg, we only look at symbols, or | |
283 | prefix it with a -l etc. | |
284 | ||
285 | We can be supplied with requests for input files more than once; | |
286 | they may, for example be split over serveral lines like foo.o(.text) | |
287 | foo.o(.data) etc, so when asked for a file we check that we havn't | |
288 | got it already so we don't duplicate the bfd. | |
289 | ||
290 | */ | |
2fa0b342 | 291 | static lang_input_statement_type * |
193c5f93 | 292 | new_afile (name, file_type, target, add_to_list) |
9f629407 ILT |
293 | CONST char *name; |
294 | lang_input_file_enum_type file_type; | |
295 | CONST char *target; | |
193c5f93 | 296 | boolean add_to_list; |
2fa0b342 | 297 | { |
193c5f93 | 298 | lang_input_statement_type *p; |
dc4726c2 | 299 | |
193c5f93 ILT |
300 | if (add_to_list) |
301 | p = new_stat (lang_input_statement, stat_ptr); | |
302 | else | |
303 | { | |
304 | p = ((lang_input_statement_type *) | |
305 | stat_alloc (sizeof (lang_input_statement_type))); | |
306 | p->header.next = NULL; | |
307 | } | |
075d7359 | 308 | |
2fa0b342 DHW |
309 | lang_has_input_file = true; |
310 | p->target = target; | |
ee4af9e8 | 311 | p->complained = false; |
075d7359 SC |
312 | switch (file_type) |
313 | { | |
314 | case lang_input_file_is_symbols_only_enum: | |
315 | p->filename = name; | |
316 | p->is_archive = false; | |
317 | p->real = true; | |
318 | p->local_sym_name = name; | |
319 | p->just_syms_flag = true; | |
320 | p->search_dirs_flag = false; | |
321 | break; | |
322 | case lang_input_file_is_fake_enum: | |
323 | p->filename = name; | |
324 | p->is_archive = false; | |
325 | p->real = false; | |
326 | p->local_sym_name = name; | |
327 | p->just_syms_flag = false; | |
328 | p->search_dirs_flag = false; | |
329 | break; | |
330 | case lang_input_file_is_l_enum: | |
331 | p->is_archive = true; | |
332 | p->filename = name; | |
333 | p->real = true; | |
ef76742f | 334 | p->local_sym_name = concat ("-l", name, (const char *) NULL); |
075d7359 SC |
335 | p->just_syms_flag = false; |
336 | p->search_dirs_flag = true; | |
337 | break; | |
075d7359 | 338 | case lang_input_file_is_marker_enum: |
193c5f93 ILT |
339 | p->filename = name; |
340 | p->is_archive = false; | |
341 | p->real = false; | |
342 | p->local_sym_name = name; | |
343 | p->just_syms_flag = false; | |
344 | p->search_dirs_flag = true; | |
345 | break; | |
346 | case lang_input_file_is_search_file_enum: | |
075d7359 SC |
347 | p->filename = name; |
348 | p->is_archive = false; | |
349 | p->real = true; | |
350 | p->local_sym_name = name; | |
351 | p->just_syms_flag = false; | |
352 | p->search_dirs_flag = true; | |
353 | break; | |
354 | case lang_input_file_is_file_enum: | |
355 | p->filename = name; | |
356 | p->is_archive = false; | |
357 | p->real = true; | |
358 | p->local_sym_name = name; | |
359 | p->just_syms_flag = false; | |
360 | p->search_dirs_flag = false; | |
361 | break; | |
362 | default: | |
363 | FAIL (); | |
364 | } | |
193c5f93 | 365 | p->the_bfd = (bfd *) NULL; |
075d7359 | 366 | p->asymbols = (asymbol **) NULL; |
075d7359 SC |
367 | p->next_real_file = (lang_statement_union_type *) NULL; |
368 | p->next = (lang_statement_union_type *) NULL; | |
2fa0b342 | 369 | p->symbol_count = 0; |
075d7359 | 370 | p->common_output_section = (asection *) NULL; |
5e6cd559 | 371 | p->loaded = false; |
075d7359 SC |
372 | lang_statement_append (&input_file_chain, |
373 | (lang_statement_union_type *) p, | |
374 | &p->next_real_file); | |
2fa0b342 DHW |
375 | return p; |
376 | } | |
377 | ||
378 | lang_input_statement_type * | |
8ddef552 DM |
379 | lang_add_input_file (name, file_type, target) |
380 | CONST char *name; | |
381 | lang_input_file_enum_type file_type; | |
382 | CONST char *target; | |
2fa0b342 | 383 | { |
1418c83b | 384 | lang_has_input_file = true; |
193c5f93 | 385 | return new_afile (name, file_type, target, true); |
2fa0b342 DHW |
386 | } |
387 | ||
1418c83b | 388 | /* Build enough state so that the parser can build its tree */ |
2fa0b342 | 389 | void |
8ddef552 | 390 | lang_init () |
2fa0b342 | 391 | { |
075d7359 | 392 | obstack_begin (&stat_obstack, 1000); |
2fa0b342 | 393 | |
075d7359 | 394 | stat_ptr = &statement_list; |
bfbdc80f | 395 | |
075d7359 | 396 | lang_list_init (stat_ptr); |
2fa0b342 | 397 | |
075d7359 SC |
398 | lang_list_init (&input_file_chain); |
399 | lang_list_init (&lang_output_section_statement); | |
400 | lang_list_init (&file_chain); | |
401 | first_file = lang_add_input_file ((char *) NULL, | |
402 | lang_input_file_is_marker_enum, | |
403 | (char *) NULL); | |
404 | abs_output_section = lang_output_section_statement_lookup (BFD_ABS_SECTION_NAME); | |
9d1fe8a4 | 405 | |
686739e2 | 406 | abs_output_section->bfd_section = bfd_abs_section_ptr; |
9d1fe8a4 | 407 | |
2fa0b342 DHW |
408 | } |
409 | ||
1418c83b | 410 | /*---------------------------------------------------------------------- |
075d7359 SC |
411 | A region is an area of memory declared with the |
412 | MEMORY { name:org=exp, len=exp ... } | |
413 | syntax. | |
2fa0b342 | 414 | |
1418c83b | 415 | We maintain a list of all the regions here |
2fa0b342 | 416 | |
1418c83b SC |
417 | If no regions are specified in the script, then the default is used |
418 | which is created when looked up to be the entire data space | |
2fa0b342 DHW |
419 | */ |
420 | ||
421 | static lang_memory_region_type *lang_memory_region_list; | |
422 | static lang_memory_region_type **lang_memory_region_list_tail = &lang_memory_region_list; | |
423 | ||
424 | lang_memory_region_type * | |
8ddef552 DM |
425 | lang_memory_region_lookup (name) |
426 | CONST char *CONST name; | |
2fa0b342 DHW |
427 | { |
428 | ||
075d7359 SC |
429 | lang_memory_region_type *p = lang_memory_region_list; |
430 | ||
1418c83b | 431 | for (p = lang_memory_region_list; |
075d7359 SC |
432 | p != (lang_memory_region_type *) NULL; |
433 | p = p->next) | |
434 | { | |
435 | if (strcmp (p->name, name) == 0) | |
436 | { | |
437 | return p; | |
438 | } | |
2fa0b342 | 439 | } |
075d7359 | 440 | if (strcmp (name, "*default*") == 0) |
2fa0b342 | 441 | { |
075d7359 SC |
442 | /* This is the default region, dig out first one on the list */ |
443 | if (lang_memory_region_list != (lang_memory_region_type *) NULL) | |
444 | { | |
445 | return lang_memory_region_list; | |
446 | } | |
2fa0b342 | 447 | } |
075d7359 SC |
448 | { |
449 | lang_memory_region_type *new = | |
450 | (lang_memory_region_type *) stat_alloc ((bfd_size_type) (sizeof (lang_memory_region_type))); | |
451 | ||
452 | new->name = buystring (name); | |
453 | new->next = (lang_memory_region_type *) NULL; | |
454 | ||
455 | *lang_memory_region_list_tail = new; | |
456 | lang_memory_region_list_tail = &new->next; | |
457 | new->origin = 0; | |
8ddef552 | 458 | new->length = ~(bfd_size_type)0; |
075d7359 SC |
459 | new->current = 0; |
460 | new->had_full_message = false; | |
461 | ||
462 | return new; | |
463 | } | |
2fa0b342 DHW |
464 | } |
465 | ||
466 | ||
2fa0b342 | 467 | lang_output_section_statement_type * |
8ddef552 DM |
468 | lang_output_section_find (name) |
469 | CONST char *CONST name; | |
2fa0b342 DHW |
470 | { |
471 | lang_statement_union_type *u; | |
472 | lang_output_section_statement_type *lookup; | |
473 | ||
474 | for (u = lang_output_section_statement.head; | |
075d7359 | 475 | u != (lang_statement_union_type *) NULL; |
2fa0b342 | 476 | u = lookup->next) |
075d7359 SC |
477 | { |
478 | lookup = &u->output_section_statement; | |
479 | if (strcmp (name, lookup->name) == 0) | |
480 | { | |
1418c83b SC |
481 | return lookup; |
482 | } | |
075d7359 SC |
483 | } |
484 | return (lang_output_section_statement_type *) NULL; | |
2fa0b342 DHW |
485 | } |
486 | ||
487 | lang_output_section_statement_type * | |
8ddef552 DM |
488 | lang_output_section_statement_lookup (name) |
489 | CONST char *CONST name; | |
2fa0b342 DHW |
490 | { |
491 | lang_output_section_statement_type *lookup; | |
2fa0b342 | 492 | |
075d7359 SC |
493 | lookup = lang_output_section_find (name); |
494 | if (lookup == (lang_output_section_statement_type *) NULL) | |
495 | { | |
2fa0b342 | 496 | |
075d7359 SC |
497 | lookup = (lang_output_section_statement_type *) |
498 | new_stat (lang_output_section_statement, stat_ptr); | |
499 | lookup->region = (lang_memory_region_type *) NULL; | |
500 | lookup->fill = 0; | |
501 | lookup->block_value = 1; | |
502 | lookup->name = name; | |
503 | ||
504 | lookup->next = (lang_statement_union_type *) NULL; | |
505 | lookup->bfd_section = (asection *) NULL; | |
506 | lookup->processed = false; | |
ae475b39 | 507 | lookup->loadable = 1; |
075d7359 SC |
508 | lookup->addr_tree = (etree_type *) NULL; |
509 | lang_list_init (&lookup->children); | |
510 | ||
1b8a42f3 ILT |
511 | lookup->memspec = (CONST char *) NULL; |
512 | lookup->flags = 0; | |
513 | lookup->subsection_alignment = -1; | |
514 | lookup->section_alignment = -1; | |
515 | lookup->load_base = (union etree_union *) NULL; | |
516 | ||
075d7359 SC |
517 | lang_statement_append (&lang_output_section_statement, |
518 | (lang_statement_union_type *) lookup, | |
519 | &lookup->next); | |
520 | } | |
521 | return lookup; | |
522 | } | |
2fa0b342 | 523 | |
9d1fe8a4 | 524 | /*ARGSUSED*/ |
2fa0b342 | 525 | static void |
8ddef552 DM |
526 | print_flags (ignore_flags) |
527 | int *ignore_flags; | |
2fa0b342 | 528 | { |
075d7359 | 529 | fprintf (config.map_file, "("); |
2fa0b342 | 530 | #if 0 |
075d7359 SC |
531 | if (flags->flag_read) |
532 | fprintf (outfile, "R"); | |
533 | if (flags->flag_write) | |
534 | fprintf (outfile, "W"); | |
535 | if (flags->flag_executable) | |
536 | fprintf (outfile, "X"); | |
537 | if (flags->flag_loadable) | |
538 | fprintf (outfile, "L"); | |
2fa0b342 | 539 | #endif |
ae475b39 | 540 | fprintf (config.map_file, ")"); |
2fa0b342 DHW |
541 | } |
542 | ||
543 | void | |
8ddef552 | 544 | lang_map () |
2fa0b342 DHW |
545 | { |
546 | lang_memory_region_type *m; | |
075d7359 SC |
547 | |
548 | fprintf (config.map_file, "**MEMORY CONFIGURATION**\n\n"); | |
48491e2e | 549 | #ifdef HOST_64_BIT |
075d7359 | 550 | fprintf (config.map_file, "name\t\torigin\t\tlength\t\tattributes\n"); |
48491e2e | 551 | #else |
ae475b39 SC |
552 | fprintf (config.map_file, |
553 | "name\t\torigin length r_size c_size is attributes\n"); | |
554 | ||
48491e2e | 555 | #endif |
2fa0b342 | 556 | for (m = lang_memory_region_list; |
075d7359 SC |
557 | m != (lang_memory_region_type *) NULL; |
558 | m = m->next) | |
2fa0b342 | 559 | { |
075d7359 SC |
560 | fprintf (config.map_file, "%-16s", m->name); |
561 | print_address (m->origin); | |
562 | print_space (); | |
8ddef552 | 563 | print_address ((bfd_vma)m->length); |
075d7359 | 564 | print_space (); |
8ddef552 | 565 | print_address ((bfd_vma)m->old_length); |
ae475b39 SC |
566 | print_space(); |
567 | print_address (m->current - m->origin); | |
568 | print_space(); | |
569 | if (m->old_length) | |
fcf276c4 ILT |
570 | fprintf (config.map_file, " %2d%% ", |
571 | (int) ((m->current - m->origin) * 100 / m->old_length)); | |
075d7359 SC |
572 | print_flags (&m->flags); |
573 | fprintf (config.map_file, "\n"); | |
2fa0b342 | 574 | } |
075d7359 SC |
575 | fprintf (config.map_file, "\n\n**LINK EDITOR MEMORY MAP**\n\n"); |
576 | fprintf (config.map_file, "output input virtual\n"); | |
577 | fprintf (config.map_file, "section section address tsize\n\n"); | |
2fa0b342 | 578 | |
075d7359 | 579 | print_statements (); |
2fa0b342 DHW |
580 | |
581 | } | |
582 | ||
583 | /* | |
584 | * | |
585 | */ | |
075d7359 | 586 | static void |
8ddef552 DM |
587 | init_os (s) |
588 | lang_output_section_statement_type * s; | |
2fa0b342 | 589 | { |
9d1fe8a4 SC |
590 | /* asection *section = bfd_get_section_by_name(output_bfd, s->name);*/ |
591 | section_userdata_type *new = | |
075d7359 SC |
592 | (section_userdata_type *) |
593 | stat_alloc ((bfd_size_type) (sizeof (section_userdata_type))); | |
594 | ||
595 | s->bfd_section = bfd_get_section_by_name (output_bfd, s->name); | |
596 | if (s->bfd_section == (asection *) NULL) | |
597 | s->bfd_section = bfd_make_section (output_bfd, s->name); | |
598 | if (s->bfd_section == (asection *) NULL) | |
599 | { | |
ddddcdf0 | 600 | einfo ("%P%F: output format %s cannot represent section called %s\n", |
075d7359 | 601 | output_bfd->xvec->name, s->name); |
9d1fe8a4 | 602 | } |
2fa0b342 | 603 | s->bfd_section->output_section = s->bfd_section; |
ae475b39 | 604 | /* s->bfd_section->flags = s->flags;*/ |
7bc4a0d7 | 605 | |
2fa0b342 DHW |
606 | /* We initialize an output sections output offset to minus its own */ |
607 | /* vma to allow us to output a section through itself */ | |
608 | s->bfd_section->output_offset = 0; | |
075d7359 | 609 | get_userdata (s->bfd_section) = (PTR) new; |
c611e285 | 610 | |
2fa0b342 DHW |
611 | } |
612 | ||
1418c83b SC |
613 | /*********************************************************************** |
614 | The wild routines. | |
615 | ||
616 | These expand statements like *(.text) and foo.o to a list of | |
617 | explicit actions, like foo.o(.text), bar.o(.text) and | |
618 | foo.o(.text,.data) . | |
619 | ||
620 | The toplevel routine, wild, takes a statement, section, file and | |
621 | target. If either the section or file is null it is taken to be the | |
622 | wildcard. Seperate lang_input_section statements are created for | |
623 | each part of the expanstion, and placed after the statement provided. | |
624 | ||
625 | */ | |
075d7359 | 626 | |
0b3499f6 | 627 | void |
8ddef552 DM |
628 | wild_doit (ptr, section, output, file) |
629 | lang_statement_list_type * ptr; | |
630 | asection * section; | |
631 | lang_output_section_statement_type * output; | |
632 | lang_input_statement_type * file; | |
2fa0b342 | 633 | { |
075d7359 | 634 | if (output->bfd_section == (asection *) NULL) |
ae475b39 | 635 | init_os (output); |
2fa0b342 | 636 | |
075d7359 SC |
637 | if (section != (asection *) NULL |
638 | && section->output_section == (asection *) NULL) | |
ae475b39 SC |
639 | { |
640 | /* Add a section reference to the list */ | |
641 | lang_input_section_type *new = new_stat (lang_input_section, ptr); | |
642 | ||
643 | new->section = section; | |
644 | new->ifile = file; | |
645 | section->output_section = output->bfd_section; | |
29f33467 | 646 | |
27f7237e ILT |
647 | /* We don't copy the SEC_NEVER_LOAD flag from an input section to |
648 | an output section, because we want to be able to include a | |
649 | SEC_NEVER_LOAD section in the middle of an otherwise loaded | |
650 | section (I don't know why we want to do this, but we do). | |
651 | build_link_order in ldwrite.c handles this case by turning the | |
652 | embedded SEC_NEVER_LOAD section into a fill. */ | |
653 | section->output_section->flags |= | |
654 | section->flags & (flagword) (~ SEC_NEVER_LOAD); | |
29f33467 | 655 | |
ae475b39 | 656 | if (!output->loadable) |
075d7359 | 657 | { |
29f33467 | 658 | /* Turn off load flag */ |
ae475b39 | 659 | output->bfd_section->flags &= ~SEC_LOAD; |
29f33467 | 660 | output->bfd_section->flags |= SEC_NEVER_LOAD; |
ae475b39 SC |
661 | } |
662 | if (section->alignment_power > output->bfd_section->alignment_power) | |
663 | { | |
664 | output->bfd_section->alignment_power = section->alignment_power; | |
075d7359 | 665 | } |
e20873a7 JG |
666 | /* If supplied an aligmnet, then force it */ |
667 | if (output->section_alignment != -1) | |
668 | { | |
669 | output->bfd_section->alignment_power = output->section_alignment; | |
670 | } | |
ae475b39 | 671 | } |
2fa0b342 DHW |
672 | } |
673 | ||
075d7359 | 674 | static void |
8ddef552 | 675 | wild_section (ptr, section, file, output) |
309c8153 ILT |
676 | lang_wild_statement_type *ptr; |
677 | const char *section; | |
678 | lang_input_statement_type *file; | |
679 | lang_output_section_statement_type *output; | |
2fa0b342 | 680 | { |
075d7359 SC |
681 | if (file->just_syms_flag == false) |
682 | { | |
309c8153 ILT |
683 | register asection *s; |
684 | ||
685 | for (s = file->the_bfd->sections; s != NULL; s = s->next) | |
075d7359 | 686 | { |
309c8153 ILT |
687 | /* Attach all sections named SECTION. If SECTION is NULL, |
688 | then attach all sections. | |
689 | ||
690 | Previously, if SECTION was NULL, this code did not call | |
691 | wild_doit if the SEC_IS_COMMON flag was set for the | |
692 | section. I did not understand that, and I took it out. | |
693 | --ian@cygnus.com. */ | |
694 | ||
695 | if (section == NULL | |
696 | || strcmp (bfd_get_section_name (file->the_bfd, s), | |
697 | section) == 0) | |
f9d3d71a | 698 | wild_doit (&ptr->children, s, output, file); |
075d7359 | 699 | } |
2fa0b342 | 700 | } |
2fa0b342 DHW |
701 | } |
702 | ||
1418c83b SC |
703 | /* passed a file name (which must have been seen already and added to |
704 | the statement tree. We will see if it has been opened already and | |
705 | had its symbols read. If not then we'll read it. | |
2fa0b342 | 706 | |
1418c83b SC |
707 | Archives are pecuilar here. We may open them once, but if they do |
708 | not define anything we need at the time, they won't have all their | |
309c8153 | 709 | symbols read. If we need them later, we'll have to redo it. */ |
193c5f93 ILT |
710 | static lang_input_statement_type * |
711 | lookup_name (name) | |
9f629407 | 712 | CONST char *name; |
2fa0b342 DHW |
713 | { |
714 | lang_input_statement_type *search; | |
075d7359 SC |
715 | |
716 | for (search = (lang_input_statement_type *) input_file_chain.head; | |
717 | search != (lang_input_statement_type *) NULL; | |
718 | search = (lang_input_statement_type *) search->next_real_file) | |
719 | { | |
720 | if (search->filename == (char *) NULL && name == (char *) NULL) | |
c477527c ILT |
721 | return search; |
722 | if (search->filename != (char *) NULL | |
723 | && name != (char *) NULL | |
724 | && strcmp (search->filename, name) == 0) | |
725 | break; | |
075d7359 | 726 | } |
2fa0b342 | 727 | |
c477527c | 728 | if (search == (lang_input_statement_type *) NULL) |
193c5f93 ILT |
729 | search = new_afile (name, lang_input_file_is_file_enum, default_target, |
730 | false); | |
c477527c | 731 | |
5e6cd559 ILT |
732 | /* If we have already added this file, or this file is not real |
733 | (FIXME: can that ever actually happen?) or the name is NULL | |
734 | (FIXME: can that ever actually happen?) don't add this file. */ | |
193c5f93 | 735 | if (search->loaded |
5e6cd559 ILT |
736 | || ! search->real |
737 | || search->filename == (const char *) NULL) | |
738 | return search; | |
739 | ||
193c5f93 ILT |
740 | load_symbols (search); |
741 | ||
742 | return search; | |
743 | } | |
744 | ||
745 | /* Get the symbols for an input file. */ | |
c477527c | 746 | |
193c5f93 ILT |
747 | static void |
748 | load_symbols (entry) | |
749 | lang_input_statement_type *entry; | |
750 | { | |
0b3499f6 ILT |
751 | char **matching; |
752 | ||
193c5f93 ILT |
753 | if (entry->loaded) |
754 | return; | |
755 | ||
756 | ldfile_open_file (entry); | |
757 | ||
0b3499f6 ILT |
758 | if (! bfd_check_format (entry->the_bfd, bfd_archive) |
759 | && ! bfd_check_format_matches (entry->the_bfd, bfd_object, &matching)) | |
760 | { | |
761 | bfd_error_type err; | |
762 | ||
763 | err = bfd_get_error (); | |
764 | if (err == bfd_error_file_ambiguously_recognized) | |
765 | { | |
766 | char **p; | |
767 | ||
768 | einfo ("%B: file not recognized: %E\n", entry->the_bfd); | |
769 | einfo ("%B: matching formats:", entry->the_bfd); | |
770 | for (p = matching; *p != NULL; p++) | |
771 | einfo (" %s", *p); | |
772 | einfo ("%F\n"); | |
773 | } | |
774 | else if (err != bfd_error_file_not_recognized) | |
775 | einfo ("%F%B: file not recognized: %E\n", entry->the_bfd); | |
776 | ||
777 | /* Try to interpret the file as a linker script. */ | |
778 | ||
779 | bfd_close (entry->the_bfd); | |
780 | entry->the_bfd = NULL; | |
781 | ||
782 | ldfile_open_command_file (entry->filename); | |
783 | ||
784 | ldfile_assumed_script = true; | |
785 | parser_input = input_script; | |
786 | yyparse (); | |
787 | ldfile_assumed_script = false; | |
788 | ||
789 | return; | |
790 | } | |
791 | ||
792 | /* We don't call ldlang_add_file for an archive. Instead, the | |
793 | add_symbols entry point will call ldlang_add_file, via the | |
794 | add_archive_element callback, for each element of the archive | |
795 | which is used. */ | |
796 | if (bfd_get_format (entry->the_bfd) == bfd_object) | |
5e6cd559 | 797 | { |
193c5f93 | 798 | ldlang_add_file (entry); |
5e6cd559 | 799 | if (trace_files || trace_file_tries) |
193c5f93 | 800 | info_msg ("%I\n", entry); |
5e6cd559 | 801 | } |
1418c83b | 802 | |
0b3499f6 | 803 | if (! bfd_link_add_symbols (entry->the_bfd, &link_info)) |
193c5f93 | 804 | einfo ("%F%B: could not read symbols: %E\n", entry->the_bfd); |
5e6cd559 | 805 | |
193c5f93 | 806 | entry->loaded = true; |
2fa0b342 DHW |
807 | } |
808 | ||
809 | static void | |
8ddef552 DM |
810 | wild (s, section, file, target, output) |
811 | lang_wild_statement_type * s; | |
9f629407 ILT |
812 | CONST char *section; |
813 | CONST char *file; | |
814 | CONST char *target; | |
8ddef552 | 815 | lang_output_section_statement_type * output; |
2fa0b342 DHW |
816 | { |
817 | lang_input_statement_type *f; | |
075d7359 SC |
818 | |
819 | if (file == (char *) NULL) | |
820 | { | |
821 | /* Perform the iteration over all files in the list */ | |
822 | for (f = (lang_input_statement_type *) file_chain.head; | |
823 | f != (lang_input_statement_type *) NULL; | |
824 | f = (lang_input_statement_type *) f->next) | |
825 | { | |
826 | wild_section (s, section, f, output); | |
827 | } | |
828 | } | |
829 | else | |
830 | { | |
831 | /* Perform the iteration over a single file */ | |
193c5f93 | 832 | wild_section (s, section, lookup_name (file), output); |
075d7359 SC |
833 | } |
834 | if (section != (char *) NULL | |
835 | && strcmp (section, "COMMON") == 0 | |
836 | && default_common_section == (lang_output_section_statement_type *) NULL) | |
837 | { | |
838 | /* Remember the section that common is going to incase we later | |
839 | get something which doesn't know where to put it */ | |
840 | default_common_section = output; | |
2fa0b342 | 841 | } |
2fa0b342 DHW |
842 | } |
843 | ||
844 | /* | |
075d7359 | 845 | read in all the files |
2fa0b342 | 846 | */ |
97fbbaca | 847 | |
075d7359 | 848 | static bfd * |
8ddef552 | 849 | open_output (name) |
9f629407 | 850 | CONST char *name; |
2fa0b342 | 851 | { |
097879bc | 852 | bfd *output; |
097879bc | 853 | |
075d7359 | 854 | if (output_target == (char *) NULL) |
ae475b39 SC |
855 | { |
856 | if (current_target != (char *) NULL) | |
857 | output_target = current_target; | |
858 | else | |
859 | output_target = default_target; | |
860 | } | |
075d7359 | 861 | output = bfd_openw (name, output_target); |
075d7359 SC |
862 | |
863 | if (output == (bfd *) NULL) | |
864 | { | |
5bcb7f28 | 865 | if (bfd_get_error () == bfd_error_invalid_target) |
ae475b39 | 866 | { |
ddddcdf0 | 867 | einfo ("%P%F: target %s not found\n", output_target); |
ae475b39 | 868 | } |
ddddcdf0 | 869 | einfo ("%P%F: cannot open output file %s: %E\n", name); |
075d7359 | 870 | } |
30d1a390 | 871 | |
97fbbaca JL |
872 | delete_output_file_on_failure = 1; |
873 | ||
30d1a390 | 874 | /* output->flags |= D_PAGED;*/ |
075d7359 | 875 | |
ddddcdf0 ILT |
876 | if (! bfd_set_format (output, bfd_object)) |
877 | einfo ("%P%F:%s: can not make object file: %E\n", name); | |
878 | if (! bfd_set_arch_mach (output, | |
879 | ldfile_output_architecture, | |
880 | ldfile_output_machine)) | |
881 | einfo ("%P%F:%s: can not set architecture: %E\n", name); | |
882 | ||
c477527c ILT |
883 | link_info.hash = bfd_link_hash_table_create (output); |
884 | if (link_info.hash == (struct bfd_link_hash_table *) NULL) | |
885 | einfo ("%P%F: can not create link hash table: %E\n"); | |
886 | ||
1b8a42f3 | 887 | bfd_set_gp_size (output, g_switch_value); |
2fa0b342 DHW |
888 | return output; |
889 | } | |
1418c83b SC |
890 | |
891 | ||
097879bc | 892 | |
1418c83b | 893 | |
2fa0b342 | 894 | static void |
8ddef552 DM |
895 | ldlang_open_output (statement) |
896 | lang_statement_union_type * statement; | |
2fa0b342 | 897 | { |
075d7359 SC |
898 | switch (statement->header.type) |
899 | { | |
c477527c ILT |
900 | case lang_output_statement_enum: |
901 | ASSERT (output_bfd == (bfd *) NULL); | |
075d7359 SC |
902 | output_bfd = open_output (statement->output_statement.name); |
903 | ldemul_set_output_arch (); | |
c477527c | 904 | if (config.magic_demand_paged && !link_info.relocateable) |
075d7359 SC |
905 | output_bfd->flags |= D_PAGED; |
906 | else | |
907 | output_bfd->flags &= ~D_PAGED; | |
908 | if (config.text_read_only) | |
909 | output_bfd->flags |= WP_TEXT; | |
910 | else | |
911 | output_bfd->flags &= ~WP_TEXT; | |
c96386c4 ILT |
912 | if (config.traditional_format) |
913 | output_bfd->flags |= BFD_TRADITIONAL_FORMAT; | |
914 | else | |
915 | output_bfd->flags &= ~BFD_TRADITIONAL_FORMAT; | |
075d7359 | 916 | break; |
1418c83b | 917 | |
075d7359 SC |
918 | case lang_target_statement_enum: |
919 | current_target = statement->target_statement.target; | |
920 | break; | |
921 | default: | |
922 | break; | |
923 | } | |
1418c83b | 924 | } |
2fa0b342 | 925 | |
309c8153 ILT |
926 | /* Open all the input files. */ |
927 | ||
1418c83b | 928 | static void |
309c8153 ILT |
929 | open_input_bfds (s, force) |
930 | lang_statement_union_type *s; | |
931 | boolean force; | |
1418c83b | 932 | { |
309c8153 | 933 | for (; s != (lang_statement_union_type *) NULL; s = s->next) |
075d7359 | 934 | { |
309c8153 | 935 | switch (s->header.type) |
075d7359 | 936 | { |
309c8153 ILT |
937 | case lang_constructors_statement_enum: |
938 | open_input_bfds (constructor_list.head, force); | |
939 | break; | |
940 | case lang_output_section_statement_enum: | |
941 | open_input_bfds (s->output_section_statement.children.head, force); | |
942 | break; | |
943 | case lang_wild_statement_enum: | |
944 | /* Maybe we should load the file's symbols */ | |
945 | if (s->wild_statement.filename) | |
946 | (void) lookup_name (s->wild_statement.filename); | |
947 | open_input_bfds (s->wild_statement.children.head, force); | |
948 | break; | |
949 | case lang_group_statement_enum: | |
950 | { | |
951 | struct bfd_link_hash_entry *undefs; | |
952 | ||
953 | /* We must continually search the entries in the group | |
954 | until no new symbols are added to the list of undefined | |
955 | symbols. */ | |
956 | ||
957 | do | |
958 | { | |
959 | undefs = link_info.hash->undefs_tail; | |
960 | open_input_bfds (s->group_statement.children.head, true); | |
961 | } | |
962 | while (undefs != link_info.hash->undefs_tail); | |
963 | } | |
964 | break; | |
965 | case lang_target_statement_enum: | |
966 | current_target = s->target_statement.target; | |
967 | break; | |
968 | case lang_input_statement_enum: | |
969 | if (s->input_statement.real == true) | |
970 | { | |
971 | s->input_statement.target = current_target; | |
972 | ||
973 | /* If we are being called from within a group, and this | |
974 | is an archive which has already been searched, then | |
975 | force it to be researched. */ | |
976 | if (force | |
977 | && s->input_statement.loaded | |
978 | && bfd_check_format (s->input_statement.the_bfd, | |
979 | bfd_archive)) | |
980 | s->input_statement.loaded = false; | |
981 | ||
982 | load_symbols (&s->input_statement); | |
983 | } | |
984 | break; | |
985 | default: | |
986 | break; | |
075d7359 | 987 | } |
075d7359 | 988 | } |
2fa0b342 | 989 | } |
075d7359 | 990 | |
2fa0b342 DHW |
991 | /* If there are [COMMONS] statements, put a wild one into the bss section */ |
992 | ||
993 | static void | |
075d7359 | 994 | lang_reasonable_defaults () |
2fa0b342 | 995 | { |
1418c83b | 996 | #if 0 |
075d7359 SC |
997 | lang_output_section_statement_lookup (".text"); |
998 | lang_output_section_statement_lookup (".data"); | |
8cb5eb31 | 999 | |
075d7359 SC |
1000 | default_common_section = |
1001 | lang_output_section_statement_lookup (".bss"); | |
8cb5eb31 | 1002 | |
1418c83b | 1003 | |
075d7359 SC |
1004 | if (placed_commons == false) |
1005 | { | |
1006 | lang_wild_statement_type *new = | |
1007 | new_stat (lang_wild_statement, | |
1008 | &default_common_section->children); | |
1009 | ||
1010 | new->section_name = "COMMON"; | |
1011 | new->filename = (char *) NULL; | |
1012 | lang_list_init (&new->children); | |
1013 | } | |
1418c83b | 1014 | #endif |
8cb5eb31 | 1015 | |
2fa0b342 DHW |
1016 | } |
1017 | ||
1418c83b SC |
1018 | /* |
1019 | Add the supplied name to the symbol table as an undefined reference. | |
1020 | Remove items from the chain as we open input bfds | |
1021 | */ | |
075d7359 SC |
1022 | typedef struct ldlang_undef_chain_list |
1023 | { | |
f177a611 | 1024 | struct ldlang_undef_chain_list *next; |
1418c83b | 1025 | char *name; |
075d7359 | 1026 | } ldlang_undef_chain_list_type; |
1418c83b SC |
1027 | |
1028 | static ldlang_undef_chain_list_type *ldlang_undef_chain_list_head; | |
1029 | ||
1030 | void | |
8ddef552 DM |
1031 | ldlang_add_undef (name) |
1032 | CONST char *CONST name; | |
2fa0b342 | 1033 | { |
1418c83b | 1034 | ldlang_undef_chain_list_type *new = |
075d7359 SC |
1035 | (ldlang_undef_chain_list_type |
1036 | *) stat_alloc ((bfd_size_type) (sizeof (ldlang_undef_chain_list_type))); | |
1418c83b SC |
1037 | |
1038 | new->next = ldlang_undef_chain_list_head; | |
1039 | ldlang_undef_chain_list_head = new; | |
1040 | ||
075d7359 | 1041 | new->name = buystring (name); |
1418c83b | 1042 | } |
075d7359 | 1043 | |
1418c83b SC |
1044 | /* Run through the list of undefineds created above and place them |
1045 | into the linker hash table as undefined symbols belonging to the | |
1046 | script file. | |
1047 | */ | |
1048 | static void | |
8ddef552 | 1049 | lang_place_undefineds () |
1418c83b | 1050 | { |
c477527c | 1051 | ldlang_undef_chain_list_type *ptr; |
1418c83b | 1052 | |
c477527c ILT |
1053 | for (ptr = ldlang_undef_chain_list_head; |
1054 | ptr != (ldlang_undef_chain_list_type *) NULL; | |
1055 | ptr = ptr->next) | |
075d7359 | 1056 | { |
c477527c | 1057 | struct bfd_link_hash_entry *h; |
075d7359 | 1058 | |
c477527c ILT |
1059 | h = bfd_link_hash_lookup (link_info.hash, ptr->name, true, false, true); |
1060 | if (h == (struct bfd_link_hash_entry *) NULL) | |
1061 | einfo ("%P%F: bfd_link_hash_lookup failed: %E"); | |
1062 | if (h->type == bfd_link_hash_new) | |
1063 | { | |
1064 | h->type = bfd_link_hash_undefined; | |
1065 | h->u.undef.abfd = NULL; | |
1066 | bfd_link_add_undef (link_info.hash, h); | |
1067 | } | |
075d7359 SC |
1068 | } |
1069 | } | |
1418c83b | 1070 | |
2fa0b342 DHW |
1071 | /* Open input files and attatch to output sections */ |
1072 | static void | |
8ddef552 DM |
1073 | map_input_to_output_sections (s, target, output_section_statement) |
1074 | lang_statement_union_type * s; | |
1075 | CONST char *target; | |
1076 | lang_output_section_statement_type * output_section_statement; | |
2fa0b342 | 1077 | { |
075d7359 | 1078 | for (; s != (lang_statement_union_type *) NULL; s = s->next) |
2fa0b342 | 1079 | { |
075d7359 | 1080 | switch (s->header.type) |
2fa0b342 | 1081 | { |
075d7359 SC |
1082 | |
1083 | ||
1084 | case lang_wild_statement_enum: | |
1085 | wild (&s->wild_statement, s->wild_statement.section_name, | |
1086 | s->wild_statement.filename, target, | |
1087 | output_section_statement); | |
1088 | ||
1089 | break; | |
1090 | case lang_constructors_statement_enum: | |
1091 | map_input_to_output_sections (constructor_list.head, | |
1092 | target, | |
1093 | output_section_statement); | |
1094 | break; | |
1095 | case lang_output_section_statement_enum: | |
1096 | map_input_to_output_sections (s->output_section_statement.children.head, | |
1097 | target, | |
1098 | &s->output_section_statement); | |
1099 | break; | |
1100 | case lang_output_statement_enum: | |
1101 | break; | |
1102 | case lang_target_statement_enum: | |
1103 | target = s->target_statement.target; | |
1104 | break; | |
309c8153 ILT |
1105 | case lang_group_statement_enum: |
1106 | map_input_to_output_sections (s->group_statement.children.head, | |
1107 | target, | |
1108 | output_section_statement); | |
1109 | break; | |
075d7359 SC |
1110 | case lang_fill_statement_enum: |
1111 | case lang_input_section_enum: | |
1112 | case lang_object_symbols_statement_enum: | |
1113 | case lang_data_statement_enum: | |
4fdbafb2 | 1114 | case lang_reloc_statement_enum: |
075d7359 SC |
1115 | case lang_assignment_statement_enum: |
1116 | case lang_padding_statement_enum: | |
f9d3d71a ILT |
1117 | case lang_input_statement_enum: |
1118 | if (output_section_statement != NULL | |
1119 | && output_section_statement->bfd_section == NULL) | |
1120 | init_os (output_section_statement); | |
075d7359 SC |
1121 | break; |
1122 | case lang_afile_asection_pair_statement_enum: | |
1123 | FAIL (); | |
1124 | break; | |
1125 | case lang_address_statement_enum: | |
1126 | /* Mark the specified section with the supplied address */ | |
1127 | { | |
1128 | lang_output_section_statement_type *os = | |
ef01a8a8 ILT |
1129 | lang_output_section_statement_lookup |
1130 | (s->address_statement.section_name); | |
075d7359 | 1131 | |
ef01a8a8 ILT |
1132 | if (os->bfd_section == NULL) |
1133 | init_os (os); | |
075d7359 | 1134 | os->addr_tree = s->address_statement.address; |
48491e2e | 1135 | } |
075d7359 | 1136 | break; |
2fa0b342 | 1137 | } |
2fa0b342 DHW |
1138 | } |
1139 | } | |
1140 | ||
075d7359 | 1141 | static void |
8ddef552 DM |
1142 | print_output_section_statement (output_section_statement) |
1143 | lang_output_section_statement_type * output_section_statement; | |
2fa0b342 DHW |
1144 | { |
1145 | asection *section = output_section_statement->bfd_section; | |
075d7359 SC |
1146 | |
1147 | print_nl (); | |
1148 | print_section (output_section_statement->name); | |
1149 | ||
e20873a7 | 1150 | |
075d7359 | 1151 | if (section) |
e20873a7 JG |
1152 | { |
1153 | print_dot = section->vma; | |
1154 | print_space (); | |
1155 | print_section (""); | |
1156 | print_space (); | |
1157 | print_address (section->vma); | |
1158 | print_space (); | |
1159 | print_size (section->_raw_size); | |
3deb20fb | 1160 | print_space (); |
e20873a7 JG |
1161 | print_size(section->_cooked_size); |
1162 | print_space (); | |
1163 | print_alignment (section->alignment_power); | |
1164 | print_space (); | |
2fa0b342 | 1165 | #if 0 |
e20873a7 JG |
1166 | fprintf (config.map_file, "%s flags", output_section_statement->region->name); |
1167 | print_flags (stdout, &output_section_statement->flags); | |
2fa0b342 | 1168 | #endif |
e20873a7 JG |
1169 | if (section->flags & SEC_LOAD) |
1170 | fprintf (config.map_file, "load "); | |
1171 | if (section->flags & SEC_ALLOC) | |
1172 | fprintf (config.map_file, "alloc "); | |
1173 | if (section->flags & SEC_RELOC) | |
1174 | fprintf (config.map_file, "reloc "); | |
1175 | if (section->flags & SEC_HAS_CONTENTS) | |
1176 | fprintf (config.map_file, "contents "); | |
2fa0b342 | 1177 | |
e20873a7 | 1178 | } |
075d7359 | 1179 | else |
e20873a7 | 1180 | { |
269773c1 | 1181 | fprintf (config.map_file, " (no attached output section)"); |
e20873a7 JG |
1182 | } |
1183 | print_nl (); | |
9fce28ed SC |
1184 | if (output_section_statement->load_base) |
1185 | { | |
0b3499f6 | 1186 | int b = exp_get_abs_int(output_section_statement->load_base, |
9fce28ed | 1187 | 0, "output base", lang_final_phase_enum); |
3deb20fb | 1188 | fprintf (config.map_file, "Output address %08x\n", b); |
9fce28ed | 1189 | } |
e20873a7 JG |
1190 | if (output_section_statement->section_alignment >= 0 |
1191 | || output_section_statement->section_alignment >= 0) | |
1192 | { | |
3deb20fb SC |
1193 | fprintf (config.map_file, "\t\t\t\t\tforced alignment "); |
1194 | if (output_section_statement->section_alignment >= 0) | |
075d7359 | 1195 | { |
3deb20fb | 1196 | fprintf (config.map_file, "section 2**%d ",output_section_statement->section_alignment ); |
075d7359 | 1197 | } |
e20873a7 JG |
1198 | if ( output_section_statement->subsection_alignment >= 0) |
1199 | { | |
3deb20fb | 1200 | fprintf (config.map_file, "subsection 2**%d ",output_section_statement->subsection_alignment ); |
e20873a7 JG |
1201 | } |
1202 | ||
1203 | print_nl (); | |
1204 | } | |
075d7359 SC |
1205 | print_statement (output_section_statement->children.head, |
1206 | output_section_statement); | |
2fa0b342 DHW |
1207 | |
1208 | } | |
1209 | ||
075d7359 | 1210 | static void |
8ddef552 DM |
1211 | print_assignment (assignment, output_section) |
1212 | lang_assignment_statement_type * assignment; | |
1213 | lang_output_section_statement_type * output_section; | |
2fa0b342 DHW |
1214 | { |
1215 | etree_value_type result; | |
075d7359 SC |
1216 | |
1217 | print_section (""); | |
1218 | print_space (); | |
1219 | print_section (""); | |
1220 | print_space (); | |
1221 | print_address (print_dot); | |
1222 | print_space (); | |
1223 | result = exp_fold_tree (assignment->exp->assign.src, | |
1224 | output_section, | |
1225 | lang_final_phase_enum, | |
1226 | print_dot, | |
1227 | &print_dot); | |
1228 | ||
1229 | if (result.valid) | |
1230 | { | |
1231 | print_address (result.value); | |
1232 | } | |
1233 | else | |
1234 | { | |
1235 | fprintf (config.map_file, "*undefined*"); | |
1236 | } | |
1237 | print_space (); | |
1238 | exp_print_tree (assignment->exp); | |
1239 | ||
1240 | fprintf (config.map_file, "\n"); | |
2fa0b342 DHW |
1241 | } |
1242 | ||
1243 | static void | |
8ddef552 DM |
1244 | print_input_statement (statm) |
1245 | lang_input_statement_type * statm; | |
2fa0b342 | 1246 | { |
075d7359 SC |
1247 | if (statm->filename != (char *) NULL) |
1248 | { | |
1249 | fprintf (config.map_file, "LOAD %s\n", statm->filename); | |
1250 | } | |
2fa0b342 DHW |
1251 | } |
1252 | ||
804c8601 SC |
1253 | /* Print all the defined symbols for the abfd provided by in the supplied |
1254 | section. | |
1255 | */ | |
1256 | ||
1257 | static boolean | |
1258 | print_one_symbol (hash_entry, ptr) | |
1259 | struct bfd_link_hash_entry *hash_entry; | |
1260 | PTR ptr; | |
2fa0b342 | 1261 | { |
804c8601 SC |
1262 | asection * sec = (asection *)ptr; |
1263 | ||
1264 | if (hash_entry->type == bfd_link_hash_defined) | |
1265 | { | |
1266 | if (sec == hash_entry->u.def.section) { | |
1267 | print_section (""); | |
1268 | fprintf (config.map_file, " "); | |
1269 | print_section (""); | |
1270 | fprintf (config.map_file, " "); | |
1271 | print_address (hash_entry->u.def.value + outside_section_address (sec)); | |
1272 | fprintf (config.map_file, " %s", hash_entry->root.string); | |
1273 | print_nl (); | |
1274 | } | |
1275 | } | |
09a5aa5e KR |
1276 | |
1277 | return true; | |
2fa0b342 | 1278 | } |
1418c83b | 1279 | |
075d7359 | 1280 | static void |
8ddef552 DM |
1281 | print_input_section (in) |
1282 | lang_input_section_type * in; | |
2fa0b342 DHW |
1283 | { |
1284 | asection *i = in->section; | |
f078dc7c | 1285 | bfd_size_type size = i->_cooked_size != 0 ? i->_cooked_size : i->_raw_size; |
1418c83b | 1286 | |
075d7359 SC |
1287 | if (size != 0) |
1288 | { | |
1289 | print_section (""); | |
1290 | fprintf (config.map_file, " "); | |
1291 | print_section (i->name); | |
1292 | fprintf (config.map_file, " "); | |
1293 | if (i->output_section) | |
1294 | { | |
1295 | print_address (i->output_section->vma + i->output_offset); | |
1296 | fprintf (config.map_file, " "); | |
ae475b39 SC |
1297 | print_size (i->_raw_size); |
1298 | fprintf (config.map_file, " "); | |
1299 | print_size(i->_cooked_size); | |
075d7359 SC |
1300 | fprintf (config.map_file, " "); |
1301 | print_alignment (i->alignment_power); | |
1302 | fprintf (config.map_file, " "); | |
1303 | if (in->ifile) | |
1304 | { | |
2fa0b342 | 1305 | |
075d7359 | 1306 | bfd *abfd = in->ifile->the_bfd; |
2fa0b342 | 1307 | |
075d7359 SC |
1308 | if (in->ifile->just_syms_flag == true) |
1309 | { | |
1310 | fprintf (config.map_file, "symbols only "); | |
1311 | } | |
2fa0b342 | 1312 | |
075d7359 SC |
1313 | fprintf (config.map_file, " %s ", abfd->xvec->name); |
1314 | if (abfd->my_archive != (bfd *) NULL) | |
1315 | { | |
1316 | fprintf (config.map_file, "[%s]%s", abfd->my_archive->filename, | |
1317 | abfd->filename); | |
1318 | } | |
1319 | else | |
1320 | { | |
1321 | fprintf (config.map_file, "%s", abfd->filename); | |
1322 | } | |
1323 | fprintf (config.map_file, "(overhead %d bytes)", (int) bfd_alloc_size (abfd)); | |
1324 | print_nl (); | |
2fa0b342 | 1325 | |
804c8601 SC |
1326 | /* Print all the symbols */ |
1327 | bfd_link_hash_traverse (link_info.hash, print_one_symbol, (PTR) i); | |
075d7359 SC |
1328 | } |
1329 | else | |
1330 | { | |
1331 | print_nl (); | |
1332 | } | |
1333 | ||
1334 | ||
1335 | print_dot = outside_section_address (i) + size; | |
1336 | } | |
1337 | else | |
1338 | { | |
1339 | fprintf (config.map_file, "No output section allocated\n"); | |
1340 | } | |
1341 | } | |
1342 | } | |
2fa0b342 DHW |
1343 | |
1344 | static void | |
8ddef552 DM |
1345 | print_fill_statement (fill) |
1346 | lang_fill_statement_type * fill; | |
075d7359 SC |
1347 | { |
1348 | fprintf (config.map_file, "FILL mask "); | |
1349 | print_fill (fill->fill); | |
1350 | } | |
1351 | ||
1352 | static void | |
8ddef552 DM |
1353 | print_data_statement (data) |
1354 | lang_data_statement_type * data; | |
2fa0b342 DHW |
1355 | { |
1356 | /* bfd_vma value; */ | |
075d7359 SC |
1357 | print_section (""); |
1358 | print_space (); | |
1359 | print_section (""); | |
1360 | print_space (); | |
65c552e3 | 1361 | /* ASSERT(print_dot == data->output_vma);*/ |
2fa0b342 | 1362 | |
075d7359 SC |
1363 | print_address (data->output_vma + data->output_section->vma); |
1364 | print_space (); | |
1365 | print_address (data->value); | |
1366 | print_space (); | |
1367 | switch (data->type) | |
1368 | { | |
1369 | case BYTE: | |
1370 | fprintf (config.map_file, "BYTE "); | |
1371 | print_dot += BYTE_SIZE; | |
1372 | break; | |
1373 | case SHORT: | |
1374 | fprintf (config.map_file, "SHORT "); | |
1375 | print_dot += SHORT_SIZE; | |
1376 | break; | |
1377 | case LONG: | |
1378 | fprintf (config.map_file, "LONG "); | |
1379 | print_dot += LONG_SIZE; | |
1380 | break; | |
c477527c ILT |
1381 | case QUAD: |
1382 | fprintf (config.map_file, "QUAD "); | |
1383 | print_dot += QUAD_SIZE; | |
1384 | break; | |
075d7359 SC |
1385 | } |
1386 | ||
1387 | exp_print_tree (data->exp); | |
2fa0b342 | 1388 | |
075d7359 | 1389 | fprintf (config.map_file, "\n"); |
2fa0b342 DHW |
1390 | } |
1391 | ||
4fdbafb2 ILT |
1392 | /* Print a reloc statement. */ |
1393 | ||
1394 | static void | |
1395 | print_reloc_statement (reloc) | |
1396 | lang_reloc_statement_type *reloc; | |
1397 | { | |
1398 | print_section (""); | |
1399 | print_space (); | |
1400 | print_section (""); | |
1401 | print_space (); | |
1402 | ||
1403 | /* ASSERT(print_dot == data->output_vma);*/ | |
1404 | ||
1405 | print_address (reloc->output_vma + reloc->output_section->vma); | |
1406 | print_space (); | |
1407 | print_address (reloc->addend_value); | |
1408 | print_space (); | |
1409 | ||
1410 | fprintf (config.map_file, "RELOC %s ", reloc->howto->name); | |
1411 | ||
1412 | print_dot += bfd_get_reloc_size (reloc->howto); | |
1413 | ||
1414 | exp_print_tree (reloc->addend_exp); | |
1415 | ||
1416 | fprintf (config.map_file, "\n"); | |
1417 | } | |
2fa0b342 DHW |
1418 | |
1419 | static void | |
8ddef552 DM |
1420 | print_padding_statement (s) |
1421 | lang_padding_statement_type * s; | |
075d7359 SC |
1422 | { |
1423 | print_section (""); | |
1424 | print_space (); | |
1425 | print_section ("*fill*"); | |
1426 | print_space (); | |
1427 | print_address (s->output_offset + s->output_section->vma); | |
1428 | print_space (); | |
1429 | print_size (s->size); | |
1430 | print_space (); | |
1431 | print_fill (s->fill); | |
1432 | print_nl (); | |
ffc50032 | 1433 | |
aa34a7c3 | 1434 | print_dot = s->output_offset + s->output_section->vma + s->size; |
ffc50032 | 1435 | |
2fa0b342 DHW |
1436 | } |
1437 | ||
075d7359 | 1438 | static void |
8ddef552 DM |
1439 | print_wild_statement (w, os) |
1440 | lang_wild_statement_type * w; | |
1441 | lang_output_section_statement_type * os; | |
2fa0b342 | 1442 | { |
075d7359 SC |
1443 | fprintf (config.map_file, " from "); |
1444 | if (w->filename != (char *) NULL) | |
1445 | { | |
1446 | fprintf (config.map_file, "%s", w->filename); | |
1447 | } | |
1448 | else | |
1449 | { | |
1450 | fprintf (config.map_file, "*"); | |
1451 | } | |
1452 | if (w->section_name != (char *) NULL) | |
1453 | { | |
1454 | fprintf (config.map_file, "(%s)", w->section_name); | |
1455 | } | |
1456 | else | |
1457 | { | |
1458 | fprintf (config.map_file, "(*)"); | |
1459 | } | |
1460 | print_nl (); | |
1461 | print_statement (w->children.head, os); | |
2fa0b342 DHW |
1462 | |
1463 | } | |
309c8153 ILT |
1464 | |
1465 | /* Print a group statement. */ | |
1466 | ||
1467 | static void | |
1468 | print_group (s, os) | |
1469 | lang_group_statement_type *s; | |
1470 | lang_output_section_statement_type *os; | |
1471 | { | |
1472 | fprintf (config.map_file, "START GROUP\n"); | |
1473 | print_statement (s->children.head, os); | |
1474 | fprintf (config.map_file, "END GROUP\n"); | |
1475 | } | |
1476 | ||
2fa0b342 | 1477 | static void |
8ddef552 DM |
1478 | print_statement (s, os) |
1479 | lang_statement_union_type * s; | |
1480 | lang_output_section_statement_type * os; | |
2fa0b342 | 1481 | { |
075d7359 | 1482 | while (s) |
c611e285 | 1483 | { |
075d7359 | 1484 | switch (s->header.type) |
c611e285 | 1485 | { |
075d7359 SC |
1486 | case lang_constructors_statement_enum: |
1487 | fprintf (config.map_file, "constructors:\n"); | |
1488 | print_statement (constructor_list.head, os); | |
1489 | break; | |
1490 | case lang_wild_statement_enum: | |
1491 | print_wild_statement (&s->wild_statement, os); | |
1492 | break; | |
1493 | default: | |
1494 | fprintf (config.map_file, "Fail with %d\n", s->header.type); | |
1495 | FAIL (); | |
1496 | break; | |
1497 | case lang_address_statement_enum: | |
1498 | fprintf (config.map_file, "address\n"); | |
1499 | break; | |
1500 | case lang_object_symbols_statement_enum: | |
1501 | fprintf (config.map_file, "object symbols\n"); | |
1502 | break; | |
1503 | case lang_fill_statement_enum: | |
1504 | print_fill_statement (&s->fill_statement); | |
1505 | break; | |
1506 | case lang_data_statement_enum: | |
1507 | print_data_statement (&s->data_statement); | |
1508 | break; | |
4fdbafb2 ILT |
1509 | case lang_reloc_statement_enum: |
1510 | print_reloc_statement (&s->reloc_statement); | |
1511 | break; | |
075d7359 SC |
1512 | case lang_input_section_enum: |
1513 | print_input_section (&s->input_section); | |
1514 | break; | |
1515 | case lang_padding_statement_enum: | |
1516 | print_padding_statement (&s->padding_statement); | |
1517 | break; | |
1518 | case lang_output_section_statement_enum: | |
1519 | print_output_section_statement (&s->output_section_statement); | |
1520 | break; | |
1521 | case lang_assignment_statement_enum: | |
1522 | print_assignment (&s->assignment_statement, | |
1523 | os); | |
1524 | break; | |
1525 | case lang_target_statement_enum: | |
1526 | fprintf (config.map_file, "TARGET(%s)\n", s->target_statement.target); | |
1527 | break; | |
1528 | case lang_output_statement_enum: | |
1529 | fprintf (config.map_file, "OUTPUT(%s %s)\n", | |
c611e285 | 1530 | s->output_statement.name, |
e20873a7 | 1531 | output_target ? output_target : ""); |
075d7359 SC |
1532 | break; |
1533 | case lang_input_statement_enum: | |
1534 | print_input_statement (&s->input_statement); | |
1535 | break; | |
309c8153 ILT |
1536 | case lang_group_statement_enum: |
1537 | print_group (&s->group_statement, os); | |
1538 | break; | |
075d7359 SC |
1539 | case lang_afile_asection_pair_statement_enum: |
1540 | FAIL (); | |
1541 | break; | |
c611e285 | 1542 | } |
075d7359 | 1543 | s = s->next; |
2fa0b342 | 1544 | } |
2fa0b342 DHW |
1545 | } |
1546 | ||
1547 | ||
1548 | static void | |
8ddef552 | 1549 | print_statements () |
2fa0b342 | 1550 | { |
075d7359 SC |
1551 | print_statement (statement_list.head, |
1552 | abs_output_section); | |
1553 | ||
2fa0b342 DHW |
1554 | } |
1555 | ||
1556 | static bfd_vma | |
9f629407 ILT |
1557 | insert_pad (this_ptr, fill, power, output_section_statement, dot) |
1558 | lang_statement_union_type ** this_ptr; | |
1559 | fill_type fill; | |
1560 | unsigned int power; | |
1561 | asection * output_section_statement; | |
1562 | bfd_vma dot; | |
075d7359 SC |
1563 | { |
1564 | /* Align this section first to the | |
2fa0b342 DHW |
1565 | input sections requirement, then |
1566 | to the output section's requirement. | |
075d7359 | 1567 | If this alignment is > than any seen before, |
2fa0b342 DHW |
1568 | then record it too. Perform the alignment by |
1569 | inserting a magic 'padding' statement. | |
1570 | */ | |
1571 | ||
075d7359 | 1572 | unsigned int alignment_needed = align_power (dot, power) - dot; |
2fa0b342 | 1573 | |
075d7359 | 1574 | if (alignment_needed != 0) |
2fa0b342 | 1575 | { |
075d7359 SC |
1576 | lang_statement_union_type *new = |
1577 | (lang_statement_union_type *) | |
1578 | stat_alloc ((bfd_size_type) (sizeof (lang_padding_statement_type))); | |
1579 | ||
2fa0b342 DHW |
1580 | /* Link into existing chain */ |
1581 | new->header.next = *this_ptr; | |
1582 | *this_ptr = new; | |
1583 | new->header.type = lang_padding_statement_enum; | |
1584 | new->padding_statement.output_section = output_section_statement; | |
1585 | new->padding_statement.output_offset = | |
1586 | dot - output_section_statement->vma; | |
1587 | new->padding_statement.fill = fill; | |
1588 | new->padding_statement.size = alignment_needed; | |
1589 | } | |
1590 | ||
1591 | ||
1592 | /* Remember the most restrictive alignment */ | |
075d7359 SC |
1593 | if (power > output_section_statement->alignment_power) |
1594 | { | |
1595 | output_section_statement->alignment_power = power; | |
1596 | } | |
c611e285 | 1597 | output_section_statement->_raw_size += alignment_needed; |
2fa0b342 DHW |
1598 | return alignment_needed + dot; |
1599 | ||
1600 | } | |
1601 | ||
1418c83b | 1602 | /* Work out how much this section will move the dot point */ |
075d7359 | 1603 | static bfd_vma |
9f629407 ILT |
1604 | size_input_section (this_ptr, output_section_statement, fill, dot, relax) |
1605 | lang_statement_union_type ** this_ptr; | |
1606 | lang_output_section_statement_type * output_section_statement; | |
c477527c | 1607 | fill_type fill; |
9f629407 ILT |
1608 | bfd_vma dot; |
1609 | boolean relax; | |
2fa0b342 DHW |
1610 | { |
1611 | lang_input_section_type *is = &((*this_ptr)->input_section); | |
1612 | asection *i = is->section; | |
2fa0b342 | 1613 | |
075d7359 SC |
1614 | if (is->ifile->just_syms_flag == false) |
1615 | { | |
e20873a7 JG |
1616 | if (output_section_statement->subsection_alignment != -1) |
1617 | i->alignment_power = | |
1618 | output_section_statement->subsection_alignment; | |
1619 | ||
075d7359 SC |
1620 | dot = insert_pad (this_ptr, fill, i->alignment_power, |
1621 | output_section_statement->bfd_section, dot); | |
1622 | ||
075d7359 | 1623 | /* Remember where in the output section this input section goes */ |
ac004870 | 1624 | |
075d7359 SC |
1625 | i->output_offset = dot - output_section_statement->bfd_section->vma; |
1626 | ||
ae475b39 SC |
1627 | /* Mark how big the output section must be to contain this now |
1628 | */ | |
f078dc7c ILT |
1629 | if (i->_cooked_size != 0) |
1630 | dot += i->_cooked_size; | |
ae475b39 | 1631 | else |
f078dc7c | 1632 | dot += i->_raw_size; |
ae475b39 | 1633 | output_section_statement->bfd_section->_raw_size = dot - output_section_statement->bfd_section->vma; |
075d7359 | 1634 | } |
ac004870 | 1635 | else |
075d7359 SC |
1636 | { |
1637 | i->output_offset = i->vma - output_section_statement->bfd_section->vma; | |
1638 | } | |
2fa0b342 | 1639 | |
075d7359 | 1640 | return dot; |
2fa0b342 DHW |
1641 | } |
1642 | ||
193c5f93 ILT |
1643 | /* This variable indicates whether bfd_relax_section should be called |
1644 | again. */ | |
1645 | ||
1646 | static boolean relax_again; | |
1647 | ||
1648 | /* Set the sizes for all the output sections. */ | |
c611e285 | 1649 | |
a62494c4 | 1650 | bfd_vma |
9f629407 ILT |
1651 | lang_size_sections (s, output_section_statement, prev, fill, dot, relax) |
1652 | lang_statement_union_type * s; | |
1653 | lang_output_section_statement_type * output_section_statement; | |
1654 | lang_statement_union_type ** prev; | |
c477527c | 1655 | fill_type fill; |
9f629407 ILT |
1656 | bfd_vma dot; |
1657 | boolean relax; | |
c611e285 SC |
1658 | { |
1659 | /* Size up the sections from their constituent parts */ | |
075d7359 | 1660 | for (; s != (lang_statement_union_type *) NULL; s = s->next) |
ae475b39 SC |
1661 | { |
1662 | switch (s->header.type) | |
075d7359 | 1663 | { |
c611e285 | 1664 | |
ae475b39 SC |
1665 | case lang_output_section_statement_enum: |
1666 | { | |
1667 | bfd_vma after; | |
1668 | lang_output_section_statement_type *os = &s->output_section_statement; | |
1669 | ||
f9d3d71a ILT |
1670 | if (os->bfd_section == NULL) |
1671 | { | |
1672 | /* This section was never actually created. */ | |
1673 | break; | |
1674 | } | |
1675 | ||
27f7237e ILT |
1676 | /* If this is a COFF shared library section, use the size and |
1677 | address from the input section. FIXME: This is COFF | |
1678 | specific; it would be cleaner if there were some other way | |
1679 | to do this, but nothing simple comes to mind. */ | |
1680 | if ((os->bfd_section->flags & SEC_COFF_SHARED_LIBRARY) != 0) | |
1681 | { | |
1682 | asection *input; | |
1683 | ||
1684 | if (os->children.head == NULL | |
1685 | || os->children.head->next != NULL | |
1686 | || os->children.head->header.type != lang_input_section_enum) | |
1687 | einfo ("%P%X: Internal error on COFF shared library section %s", | |
1688 | os->name); | |
1689 | ||
1690 | input = os->children.head->input_section.section; | |
1691 | bfd_set_section_vma (os->bfd_section->owner, | |
1692 | os->bfd_section, | |
1693 | bfd_section_vma (input->owner, input)); | |
1694 | os->bfd_section->_raw_size = input->_raw_size; | |
1695 | break; | |
1696 | } | |
e9b63852 | 1697 | |
686739e2 | 1698 | if (bfd_is_abs_section (os->bfd_section)) |
ae475b39 SC |
1699 | { |
1700 | /* No matter what happens, an abs section starts at zero */ | |
686739e2 | 1701 | ASSERT (os->bfd_section->vma == 0); |
ae475b39 SC |
1702 | } |
1703 | else | |
1704 | { | |
1705 | if (os->addr_tree == (etree_type *) NULL) | |
1706 | { | |
1707 | /* No address specified for this section, get one | |
1708 | from the region specification | |
1709 | */ | |
1710 | if (os->region == (lang_memory_region_type *) NULL) | |
1711 | { | |
1712 | os->region = lang_memory_region_lookup ("*default*"); | |
1713 | } | |
1714 | dot = os->region->current; | |
feaa9c4b ILT |
1715 | if (os->section_alignment == -1) |
1716 | dot = align_power (dot, os->bfd_section->alignment_power); | |
ae475b39 SC |
1717 | } |
1718 | else | |
1719 | { | |
1720 | etree_value_type r; | |
1721 | ||
1722 | r = exp_fold_tree (os->addr_tree, | |
1723 | abs_output_section, | |
1724 | lang_allocating_phase_enum, | |
1725 | dot, &dot); | |
1726 | if (r.valid == false) | |
1727 | { | |
1728 | einfo ("%F%S: non constant address expression for section %s\n", | |
1729 | os->name); | |
1730 | } | |
1731 | dot = r.value; | |
1732 | } | |
1733 | /* The section starts here */ | |
1734 | /* First, align to what the section needs */ | |
1735 | ||
a62494c4 JL |
1736 | if (os->section_alignment != -1) |
1737 | dot = align_power (dot, os->section_alignment); | |
ae475b39 | 1738 | |
ae475b39 | 1739 | bfd_set_section_vma (0, os->bfd_section, dot); |
9fce28ed | 1740 | |
686739e2 ILT |
1741 | os->bfd_section->output_offset = 0; |
1742 | } | |
ae475b39 SC |
1743 | |
1744 | (void) lang_size_sections (os->children.head, os, &os->children.head, | |
1745 | os->fill, dot, relax); | |
1746 | /* Ignore the size of the input sections, use the vma and size to */ | |
1747 | /* align against */ | |
1748 | ||
8ddef552 | 1749 | after = ALIGN_N (os->bfd_section->vma + |
97fbbaca JL |
1750 | os->bfd_section->_raw_size, |
1751 | /* The coercion here is important, see ld.h. */ | |
1752 | (bfd_vma) os->block_value); | |
ae475b39 | 1753 | |
686739e2 ILT |
1754 | if (bfd_is_abs_section (os->bfd_section)) |
1755 | ASSERT (after == os->bfd_section->vma); | |
1756 | else | |
1757 | os->bfd_section->_raw_size = after - os->bfd_section->vma; | |
ae475b39 SC |
1758 | dot = os->bfd_section->vma + os->bfd_section->_raw_size; |
1759 | os->processed = true; | |
1760 | ||
1761 | /* Replace into region ? */ | |
686739e2 | 1762 | if (os->region != (lang_memory_region_type *) NULL) |
ae475b39 SC |
1763 | { |
1764 | os->region->current = dot; | |
1765 | /* Make sure this isn't silly */ | |
9fce28ed SC |
1766 | if (( os->region->current |
1767 | > os->region->origin + os->region->length) | |
1768 | || ( os->region->origin > os->region->current )) | |
1769 | { | |
ddddcdf0 | 1770 | einfo ("%X%P: region %s is full (%B section %s)\n", |
9fce28ed SC |
1771 | os->region->name, |
1772 | os->bfd_section->owner, | |
1773 | os->bfd_section->name); | |
1774 | /* Reset the region pointer */ | |
1775 | os->region->current = 0; | |
ae475b39 | 1776 | |
9fce28ed | 1777 | } |
ae475b39 SC |
1778 | |
1779 | } | |
0b3499f6 ILT |
1780 | |
1781 | ||
ae475b39 | 1782 | } |
9d1fe8a4 | 1783 | |
ae475b39 SC |
1784 | break; |
1785 | case lang_constructors_statement_enum: | |
1786 | dot = lang_size_sections (constructor_list.head, | |
1787 | output_section_statement, | |
1788 | &s->wild_statement.children.head, | |
1789 | fill, | |
1790 | dot, relax); | |
1791 | break; | |
9d1fe8a4 | 1792 | |
ae475b39 SC |
1793 | case lang_data_statement_enum: |
1794 | { | |
1795 | unsigned int size = 0; | |
1796 | ||
1797 | s->data_statement.output_vma = dot - output_section_statement->bfd_section->vma; | |
1798 | s->data_statement.output_section = | |
1799 | output_section_statement->bfd_section; | |
1800 | ||
1801 | switch (s->data_statement.type) | |
1802 | { | |
c477527c ILT |
1803 | case QUAD: |
1804 | size = QUAD_SIZE; | |
1805 | break; | |
ae475b39 SC |
1806 | case LONG: |
1807 | size = LONG_SIZE; | |
1808 | break; | |
1809 | case SHORT: | |
1810 | size = SHORT_SIZE; | |
1811 | break; | |
1812 | case BYTE: | |
1813 | size = BYTE_SIZE; | |
1814 | break; | |
1815 | ||
1816 | } | |
1817 | dot += size; | |
1818 | output_section_statement->bfd_section->_raw_size += size; | |
1819 | } | |
1820 | break; | |
c611e285 | 1821 | |
4fdbafb2 ILT |
1822 | case lang_reloc_statement_enum: |
1823 | { | |
1824 | int size; | |
1825 | ||
1826 | s->reloc_statement.output_vma = | |
1827 | dot - output_section_statement->bfd_section->vma; | |
1828 | s->reloc_statement.output_section = | |
1829 | output_section_statement->bfd_section; | |
1830 | size = bfd_get_reloc_size (s->reloc_statement.howto); | |
1831 | dot += size; | |
1832 | output_section_statement->bfd_section->_raw_size += size; | |
1833 | } | |
1834 | break; | |
1835 | ||
ae475b39 | 1836 | case lang_wild_statement_enum: |
c611e285 | 1837 | |
ae475b39 SC |
1838 | dot = lang_size_sections (s->wild_statement.children.head, |
1839 | output_section_statement, | |
1840 | &s->wild_statement.children.head, | |
c611e285 | 1841 | |
ae475b39 | 1842 | fill, dot, relax); |
c611e285 | 1843 | |
ae475b39 | 1844 | break; |
c611e285 | 1845 | |
ae475b39 | 1846 | case lang_object_symbols_statement_enum: |
c477527c ILT |
1847 | link_info.create_object_symbols_section = |
1848 | output_section_statement->bfd_section; | |
ae475b39 SC |
1849 | break; |
1850 | case lang_output_statement_enum: | |
1851 | case lang_target_statement_enum: | |
1852 | break; | |
1853 | case lang_input_section_enum: | |
ae475b39 | 1854 | { |
c477527c ILT |
1855 | asection *i; |
1856 | ||
193c5f93 ILT |
1857 | i = (*prev)->input_section.section; |
1858 | if (! relax) | |
1859 | i->_cooked_size = i->_raw_size; | |
1860 | else | |
755f42fe | 1861 | { |
193c5f93 | 1862 | boolean again; |
075d7359 | 1863 | |
193c5f93 ILT |
1864 | if (! bfd_relax_section (i->owner, i, &link_info, &again)) |
1865 | einfo ("%P%F: can't relax section: %E\n"); | |
1866 | if (again) | |
1867 | relax_again = true; | |
1868 | } | |
1869 | dot = size_input_section (prev, | |
1870 | output_section_statement, | |
1871 | output_section_statement->fill, | |
1872 | dot, relax); | |
ae475b39 | 1873 | } |
ae475b39 SC |
1874 | break; |
1875 | case lang_input_statement_enum: | |
1876 | break; | |
1877 | case lang_fill_statement_enum: | |
1878 | s->fill_statement.output_section = output_section_statement->bfd_section; | |
075d7359 | 1879 | |
ae475b39 SC |
1880 | fill = s->fill_statement.fill; |
1881 | break; | |
1882 | case lang_assignment_statement_enum: | |
1883 | { | |
1884 | bfd_vma newdot = dot; | |
1885 | ||
1886 | exp_fold_tree (s->assignment_statement.exp, | |
1887 | output_section_statement, | |
1888 | lang_allocating_phase_enum, | |
1889 | dot, | |
1890 | &newdot); | |
1891 | ||
1892 | if (newdot != dot && !relax) | |
27f7237e ILT |
1893 | { |
1894 | /* The assignment changed dot. Insert a pad. */ | |
1895 | if (output_section_statement == abs_output_section) | |
1896 | { | |
1897 | /* If we don't have an output section, then just adjust | |
1898 | the default memory address. */ | |
1899 | lang_memory_region_lookup ("*default*")->current = newdot; | |
1900 | } | |
1901 | else | |
1902 | { | |
1903 | lang_statement_union_type *new = | |
1904 | ((lang_statement_union_type *) | |
1905 | stat_alloc (sizeof (lang_padding_statement_type))); | |
1906 | ||
1907 | /* Link into existing chain */ | |
1908 | new->header.next = *prev; | |
1909 | *prev = new; | |
1910 | new->header.type = lang_padding_statement_enum; | |
1911 | new->padding_statement.output_section = | |
1912 | output_section_statement->bfd_section; | |
1913 | new->padding_statement.output_offset = | |
1914 | dot - output_section_statement->bfd_section->vma; | |
1915 | new->padding_statement.fill = fill; | |
1916 | new->padding_statement.size = newdot - dot; | |
1917 | output_section_statement->bfd_section->_raw_size += | |
1918 | new->padding_statement.size; | |
1919 | } | |
1920 | ||
1921 | dot = newdot; | |
1922 | } | |
ae475b39 | 1923 | } |
27f7237e | 1924 | break; |
9d87af56 ILT |
1925 | |
1926 | case lang_padding_statement_enum: | |
1927 | /* If we are relaxing, and this is not the first pass, some | |
1928 | padding statements may have been inserted during previous | |
1929 | passes. We may have to move the padding statement to a new | |
1930 | location if dot has a different value at this point in this | |
1931 | pass than it did at this point in the previous pass. */ | |
1932 | s->padding_statement.output_offset = | |
1933 | dot - output_section_statement->bfd_section->vma; | |
1934 | dot += s->padding_statement.size; | |
1935 | break; | |
1936 | ||
309c8153 ILT |
1937 | case lang_group_statement_enum: |
1938 | dot = lang_size_sections (s->group_statement.children.head, | |
1939 | output_section_statement, | |
1940 | &s->group_statement.children.head, | |
1941 | fill, dot, relax); | |
1942 | break; | |
1943 | ||
ae475b39 SC |
1944 | default: |
1945 | FAIL (); | |
1946 | break; | |
9d87af56 | 1947 | |
ae475b39 | 1948 | /* This can only get here when relaxing is turned on */ |
075d7359 | 1949 | |
ae475b39 SC |
1950 | case lang_address_statement_enum: |
1951 | break; | |
075d7359 | 1952 | } |
ae475b39 SC |
1953 | prev = &s->header.next; |
1954 | } | |
c611e285 SC |
1955 | return dot; |
1956 | } | |
9d1fe8a4 | 1957 | |
309c8153 | 1958 | bfd_vma |
9f629407 ILT |
1959 | lang_do_assignments (s, output_section_statement, fill, dot) |
1960 | lang_statement_union_type * s; | |
1961 | lang_output_section_statement_type * output_section_statement; | |
c477527c | 1962 | fill_type fill; |
9f629407 | 1963 | bfd_vma dot; |
2fa0b342 | 1964 | { |
075d7359 | 1965 | for (; s != (lang_statement_union_type *) NULL; s = s->next) |
2fa0b342 | 1966 | { |
075d7359 | 1967 | switch (s->header.type) |
2fa0b342 | 1968 | { |
075d7359 SC |
1969 | case lang_constructors_statement_enum: |
1970 | dot = lang_do_assignments (constructor_list.head, | |
1971 | output_section_statement, | |
1972 | fill, | |
1973 | dot); | |
1974 | break; | |
1975 | ||
1976 | case lang_output_section_statement_enum: | |
1977 | { | |
1978 | lang_output_section_statement_type *os = | |
269773c1 | 1979 | &(s->output_section_statement); |
2fa0b342 | 1980 | |
269773c1 ILT |
1981 | if (os->bfd_section != NULL) |
1982 | { | |
1983 | dot = os->bfd_section->vma; | |
1984 | (void) lang_do_assignments (os->children.head, os, | |
1985 | os->fill, dot); | |
1986 | dot = os->bfd_section->vma + os->bfd_section->_raw_size; | |
1987 | } | |
0b3499f6 ILT |
1988 | if (os->load_base) |
1989 | { | |
467a0380 SC |
1990 | /* If nothing has been placed into the output section then |
1991 | it won't have a bfd_section. */ | |
1992 | if (os->bfd_section) | |
1993 | { | |
1994 | os->bfd_section->lma | |
1995 | = exp_get_abs_int(os->load_base, 0,"load base", lang_final_phase_enum); | |
1996 | } | |
0b3499f6 | 1997 | } |
075d7359 SC |
1998 | } |
1999 | break; | |
2000 | case lang_wild_statement_enum: | |
2fa0b342 | 2001 | |
075d7359 SC |
2002 | dot = lang_do_assignments (s->wild_statement.children.head, |
2003 | output_section_statement, | |
2004 | fill, dot); | |
2fa0b342 | 2005 | |
075d7359 SC |
2006 | break; |
2007 | ||
2008 | case lang_object_symbols_statement_enum: | |
2009 | case lang_output_statement_enum: | |
2010 | case lang_target_statement_enum: | |
1418c83b | 2011 | #if 0 |
075d7359 | 2012 | case lang_common_statement_enum: |
1418c83b | 2013 | #endif |
2fa0b342 | 2014 | break; |
075d7359 SC |
2015 | case lang_data_statement_enum: |
2016 | { | |
2017 | etree_value_type value; | |
2018 | ||
2019 | value = exp_fold_tree (s->data_statement.exp, | |
2020 | abs_output_section, | |
2021 | lang_final_phase_enum, dot, &dot); | |
2022 | s->data_statement.value = value.value; | |
2023 | if (value.valid == false) | |
ddddcdf0 | 2024 | einfo ("%F%P: invalid data statement\n"); |
075d7359 SC |
2025 | } |
2026 | switch (s->data_statement.type) | |
2027 | { | |
c477527c ILT |
2028 | case QUAD: |
2029 | dot += QUAD_SIZE; | |
2030 | break; | |
075d7359 SC |
2031 | case LONG: |
2032 | dot += LONG_SIZE; | |
2033 | break; | |
2034 | case SHORT: | |
2035 | dot += SHORT_SIZE; | |
2036 | break; | |
2037 | case BYTE: | |
2038 | dot += BYTE_SIZE; | |
2039 | break; | |
2040 | } | |
2fa0b342 | 2041 | break; |
4fdbafb2 ILT |
2042 | |
2043 | case lang_reloc_statement_enum: | |
2044 | { | |
2045 | etree_value_type value; | |
2046 | ||
2047 | value = exp_fold_tree (s->reloc_statement.addend_exp, | |
2048 | abs_output_section, | |
2049 | lang_final_phase_enum, dot, &dot); | |
2050 | s->reloc_statement.addend_value = value.value; | |
2051 | if (value.valid == false) | |
2052 | einfo ("%F%P: invalid reloc statement\n"); | |
2053 | } | |
2054 | dot += bfd_get_reloc_size (s->reloc_statement.howto); | |
2055 | break; | |
2056 | ||
075d7359 SC |
2057 | case lang_input_section_enum: |
2058 | { | |
2059 | asection *in = s->input_section.section; | |
2060 | ||
f078dc7c ILT |
2061 | if (in->_cooked_size != 0) |
2062 | dot += in->_cooked_size; | |
2063 | else | |
2064 | dot += in->_raw_size; | |
075d7359 | 2065 | } |
2fa0b342 | 2066 | break; |
2fa0b342 | 2067 | |
075d7359 SC |
2068 | case lang_input_statement_enum: |
2069 | break; | |
2070 | case lang_fill_statement_enum: | |
2071 | fill = s->fill_statement.fill; | |
2072 | break; | |
2073 | case lang_assignment_statement_enum: | |
2074 | { | |
2075 | exp_fold_tree (s->assignment_statement.exp, | |
2076 | output_section_statement, | |
2077 | lang_final_phase_enum, | |
2078 | dot, | |
2079 | &dot); | |
2080 | } | |
2081 | ||
2082 | break; | |
2083 | case lang_padding_statement_enum: | |
2084 | dot += s->padding_statement.size; | |
2085 | break; | |
309c8153 ILT |
2086 | |
2087 | case lang_group_statement_enum: | |
2088 | dot = lang_do_assignments (s->group_statement.children.head, | |
2089 | output_section_statement, | |
2090 | fill, dot); | |
2091 | ||
2092 | break; | |
2093 | ||
075d7359 SC |
2094 | default: |
2095 | FAIL (); | |
2096 | break; | |
2097 | case lang_address_statement_enum: | |
2098 | break; | |
2099 | } | |
2fa0b342 DHW |
2100 | |
2101 | } | |
2102 | return dot; | |
2103 | } | |
2104 | ||
2fa0b342 | 2105 | static void |
8ddef552 | 2106 | lang_finish () |
2fa0b342 | 2107 | { |
c477527c ILT |
2108 | struct bfd_link_hash_entry *h; |
2109 | boolean warn = link_info.relocateable ? false : true; | |
075d7359 | 2110 | |
c477527c ILT |
2111 | if (entry_symbol == (char *) NULL) |
2112 | { | |
2113 | /* No entry has been specified. Look for start, but don't warn | |
2114 | if we don't find it. */ | |
2115 | entry_symbol = "start"; | |
2116 | warn = false; | |
2117 | } | |
2fa0b342 | 2118 | |
c477527c ILT |
2119 | h = bfd_link_hash_lookup (link_info.hash, entry_symbol, false, false, true); |
2120 | if (h != (struct bfd_link_hash_entry *) NULL | |
2121 | && h->type == bfd_link_hash_defined) | |
075d7359 | 2122 | { |
c477527c | 2123 | bfd_vma val; |
075d7359 | 2124 | |
c477527c ILT |
2125 | val = (h->u.def.value |
2126 | + bfd_get_section_vma (output_bfd, | |
2127 | h->u.def.section->output_section) | |
2128 | + h->u.def.section->output_offset); | |
2129 | if (! bfd_set_start_address (output_bfd, val)) | |
2130 | einfo ("%P%F:%s: can't set start address\n", entry_symbol); | |
075d7359 | 2131 | } |
c477527c | 2132 | else |
22a78f0d | 2133 | { |
c477527c ILT |
2134 | asection *ts; |
2135 | ||
2136 | /* Can't find the entry symbol. Use the first address in the | |
2137 | text section. */ | |
2138 | ts = bfd_get_section_by_name (output_bfd, ".text"); | |
2139 | if (ts != (asection *) NULL) | |
2140 | { | |
2141 | if (warn) | |
2142 | einfo ("%P: warning: cannot find entry symbol %s; defaulting to %V\n", | |
2143 | entry_symbol, bfd_get_section_vma (output_bfd, ts)); | |
2144 | if (! bfd_set_start_address (output_bfd, | |
2145 | bfd_get_section_vma (output_bfd, ts))) | |
2146 | einfo ("%P%F: can't set start address\n"); | |
2147 | } | |
2148 | else | |
2149 | { | |
2150 | if (warn) | |
2151 | einfo ("%P: warning: cannot find entry symbol %s; not setting start address\n", | |
2152 | entry_symbol); | |
2153 | } | |
22a78f0d | 2154 | } |
2fa0b342 DHW |
2155 | } |
2156 | ||
0b3499f6 ILT |
2157 | /* Check that the architecture of all the input files is compatible |
2158 | with the output file. */ | |
2159 | ||
2fa0b342 | 2160 | static void |
8ddef552 | 2161 | lang_check () |
2fa0b342 DHW |
2162 | { |
2163 | lang_statement_union_type *file; | |
075d7359 | 2164 | bfd *input_bfd; |
075d7359 | 2165 | CONST bfd_arch_info_type *compatible; |
7bc4a0d7 | 2166 | |
2fa0b342 | 2167 | for (file = file_chain.head; |
075d7359 SC |
2168 | file != (lang_statement_union_type *) NULL; |
2169 | file = file->input_statement.next) | |
2170 | { | |
075d7359 | 2171 | input_bfd = file->input_statement.the_bfd; |
075d7359 SC |
2172 | compatible = bfd_arch_get_compatible (input_bfd, |
2173 | output_bfd); | |
0b3499f6 ILT |
2174 | if (compatible == NULL) |
2175 | einfo ("%P: warning: %s architecture of input file `%B' is incompatible with %s output\n", | |
2176 | bfd_printable_name (input_bfd), input_bfd, | |
2177 | bfd_printable_name (output_bfd)); | |
075d7359 SC |
2178 | } |
2179 | } | |
2fa0b342 | 2180 | |
c477527c ILT |
2181 | /* Look through all the global common symbols and attach them to the |
2182 | correct section. The -sort-common command line switch may be used | |
2183 | to roughly sort the entries by size. */ | |
2fa0b342 DHW |
2184 | |
2185 | static void | |
8ddef552 | 2186 | lang_common () |
2fa0b342 | 2187 | { |
c477527c ILT |
2188 | if (link_info.relocateable |
2189 | && ! command_line.force_common_definition) | |
2190 | return; | |
075d7359 | 2191 | |
c477527c ILT |
2192 | if (! config.sort_common) |
2193 | bfd_link_hash_traverse (link_info.hash, lang_one_common, (PTR) NULL); | |
2194 | else | |
075d7359 | 2195 | { |
c477527c | 2196 | unsigned int power; |
1418c83b | 2197 | |
36c6e8c3 | 2198 | for (power = 1; power < 4; power++) |
c477527c ILT |
2199 | bfd_link_hash_traverse (link_info.hash, lang_one_common, |
2200 | (PTR) &power); | |
2201 | } | |
2202 | } | |
29f33467 | 2203 | |
c477527c | 2204 | /* Place one common symbol in the correct section. */ |
075d7359 | 2205 | |
c477527c ILT |
2206 | static boolean |
2207 | lang_one_common (h, info) | |
2208 | struct bfd_link_hash_entry *h; | |
2209 | PTR info; | |
2210 | { | |
2211 | unsigned int power_of_two; | |
2212 | bfd_vma size; | |
c477527c | 2213 | asection *section; |
075d7359 | 2214 | |
c477527c ILT |
2215 | if (h->type != bfd_link_hash_common) |
2216 | return true; | |
075d7359 | 2217 | |
c477527c | 2218 | size = h->u.c.size; |
36c6e8c3 ILT |
2219 | power_of_two = h->u.c.alignment_power; |
2220 | ||
2221 | if (config.sort_common | |
2222 | && power_of_two < *(unsigned int *) info | |
2223 | && *(unsigned int *) info < 4) | |
c477527c | 2224 | return true; |
075d7359 | 2225 | |
c477527c | 2226 | section = h->u.c.section; |
075d7359 | 2227 | |
c477527c | 2228 | /* Increase the size of the section. */ |
36c6e8c3 ILT |
2229 | section->_raw_size = ALIGN_N (section->_raw_size, |
2230 | (bfd_size_type) (1 << power_of_two)); | |
075d7359 | 2231 | |
c477527c ILT |
2232 | /* Adjust the alignment if necessary. */ |
2233 | if (power_of_two > section->alignment_power) | |
2234 | section->alignment_power = power_of_two; | |
075d7359 | 2235 | |
c477527c ILT |
2236 | /* Change the symbol from common to defined. */ |
2237 | h->type = bfd_link_hash_defined; | |
2238 | h->u.def.section = section; | |
2239 | h->u.def.value = section->_raw_size; | |
097879bc | 2240 | |
c477527c ILT |
2241 | /* Increase the size of the section. */ |
2242 | section->_raw_size += size; | |
1418c83b | 2243 | |
b495c314 | 2244 | if (config.map_file != NULL) |
c477527c ILT |
2245 | fprintf (config.map_file, "Allocating common %s: %lx at %lx %s\n", |
2246 | h->root.string, (unsigned long) size, | |
2247 | (unsigned long) h->u.def.value, section->owner->filename); | |
1418c83b | 2248 | |
c477527c | 2249 | return true; |
2fa0b342 DHW |
2250 | } |
2251 | ||
2252 | /* | |
075d7359 | 2253 | run through the input files and ensure that every input |
2fa0b342 DHW |
2254 | section has somewhere to go. If one is found without |
2255 | a destination then create an input request and place it | |
2256 | into the statement tree. | |
2257 | */ | |
2258 | ||
075d7359 | 2259 | static void |
8ddef552 | 2260 | lang_place_orphans () |
2fa0b342 DHW |
2261 | { |
2262 | lang_input_statement_type *file; | |
1418c83b | 2263 | |
075d7359 SC |
2264 | for (file = (lang_input_statement_type *) file_chain.head; |
2265 | file != (lang_input_statement_type *) NULL; | |
2266 | file = (lang_input_statement_type *) file->next) | |
2267 | { | |
2268 | asection *s; | |
2269 | ||
f9d3d71a ILT |
2270 | if (file->just_syms_flag) |
2271 | continue; | |
2272 | ||
075d7359 SC |
2273 | for (s = file->the_bfd->sections; |
2274 | s != (asection *) NULL; | |
2275 | s = s->next) | |
2276 | { | |
2277 | if (s->output_section == (asection *) NULL) | |
2278 | { | |
2279 | /* This section of the file is not attatched, root | |
2280 | around for a sensible place for it to go */ | |
2281 | ||
2282 | if (file->common_section == s) | |
2283 | { | |
2284 | /* This is a lonely common section which must | |
2285 | have come from an archive. We attatch to the | |
2286 | section with the wildcard */ | |
c477527c ILT |
2287 | if (! link_info.relocateable |
2288 | && ! command_line.force_common_definition) | |
075d7359 SC |
2289 | { |
2290 | if (default_common_section == | |
2291 | (lang_output_section_statement_type *) NULL) | |
2292 | { | |
a4aeaacf | 2293 | info_msg ("%P: no [COMMON] command, defaulting to .bss\n"); |
075d7359 SC |
2294 | |
2295 | default_common_section = | |
2296 | lang_output_section_statement_lookup (".bss"); | |
2297 | ||
2298 | } | |
2299 | wild_doit (&default_common_section->children, s, | |
2300 | default_common_section, file); | |
2301 | } | |
2302 | } | |
0b3499f6 ILT |
2303 | else if (ldemul_place_orphan (file, s)) |
2304 | ; | |
075d7359 SC |
2305 | else |
2306 | { | |
2307 | lang_output_section_statement_type *os = | |
2308 | lang_output_section_statement_lookup (s->name); | |
2fa0b342 | 2309 | |
075d7359 SC |
2310 | wild_doit (&os->children, s, os, file); |
2311 | } | |
2312 | } | |
2fa0b342 | 2313 | } |
2fa0b342 | 2314 | } |
2fa0b342 DHW |
2315 | } |
2316 | ||
2317 | ||
2fa0b342 | 2318 | void |
8ddef552 DM |
2319 | lang_set_flags (ptr, flags) |
2320 | int *ptr; | |
2321 | CONST char *flags; | |
2fa0b342 | 2322 | { |
075d7359 SC |
2323 | boolean state = false; |
2324 | ||
2325 | *ptr = 0; | |
2fa0b342 | 2326 | while (*flags) |
075d7359 SC |
2327 | { |
2328 | if (*flags == '!') | |
2329 | { | |
2330 | state = false; | |
2331 | flags++; | |
2332 | } | |
2333 | else | |
2334 | state = true; | |
2335 | switch (*flags) | |
2336 | { | |
2337 | case 'R': | |
2338 | /* ptr->flag_read = state; */ | |
2339 | break; | |
2340 | case 'W': | |
2341 | /* ptr->flag_write = state; */ | |
2342 | break; | |
2343 | case 'X': | |
2344 | /* ptr->flag_executable= state;*/ | |
2345 | break; | |
2346 | case 'L': | |
2347 | case 'I': | |
2348 | /* ptr->flag_loadable= state;*/ | |
2349 | break; | |
2350 | default: | |
ddddcdf0 | 2351 | einfo ("%P%F: invalid syntax in flags\n"); |
075d7359 SC |
2352 | break; |
2353 | } | |
dc4726c2 SC |
2354 | flags++; |
2355 | } | |
2fa0b342 DHW |
2356 | } |
2357 | ||
a4d2a48e ILT |
2358 | /* Call a function on each input file. This function will be called |
2359 | on an archive, but not on the elements. */ | |
2360 | ||
2361 | void | |
2362 | lang_for_each_input_file (func) | |
2363 | void (*func) PARAMS ((lang_input_statement_type *)); | |
2364 | { | |
2365 | lang_input_statement_type *f; | |
2366 | ||
2367 | for (f = (lang_input_statement_type *) input_file_chain.head; | |
2368 | f != NULL; | |
2369 | f = (lang_input_statement_type *) f->next_real_file) | |
2370 | func (f); | |
2371 | } | |
2fa0b342 | 2372 | |
a4d2a48e ILT |
2373 | /* Call a function on each file. The function will be called on all |
2374 | the elements of an archive which are included in the link, but will | |
2375 | not be called on the archive file itself. */ | |
2fa0b342 DHW |
2376 | |
2377 | void | |
8ddef552 DM |
2378 | lang_for_each_file (func) |
2379 | void (*func) PARAMS ((lang_input_statement_type *)); | |
2fa0b342 DHW |
2380 | { |
2381 | lang_input_statement_type *f; | |
075d7359 SC |
2382 | |
2383 | for (f = (lang_input_statement_type *) file_chain.head; | |
2384 | f != (lang_input_statement_type *) NULL; | |
2385 | f = (lang_input_statement_type *) f->next) | |
2386 | { | |
2387 | func (f); | |
2388 | } | |
2fa0b342 DHW |
2389 | } |
2390 | ||
9f629407 ILT |
2391 | #if 0 |
2392 | ||
2393 | /* Not used. */ | |
2fa0b342 DHW |
2394 | |
2395 | void | |
8ddef552 DM |
2396 | lang_for_each_input_section (func) |
2397 | void (*func) PARAMS ((bfd * ab, asection * as)); | |
2fa0b342 DHW |
2398 | { |
2399 | lang_input_statement_type *f; | |
075d7359 SC |
2400 | |
2401 | for (f = (lang_input_statement_type *) file_chain.head; | |
2402 | f != (lang_input_statement_type *) NULL; | |
2403 | f = (lang_input_statement_type *) f->next) | |
2fa0b342 DHW |
2404 | { |
2405 | asection *s; | |
075d7359 | 2406 | |
2fa0b342 | 2407 | for (s = f->the_bfd->sections; |
075d7359 SC |
2408 | s != (asection *) NULL; |
2409 | s = s->next) | |
2410 | { | |
2411 | func (f->the_bfd, s); | |
2412 | } | |
2fa0b342 DHW |
2413 | } |
2414 | } | |
2415 | ||
9f629407 | 2416 | #endif |
2fa0b342 | 2417 | |
075d7359 | 2418 | void |
8ddef552 DM |
2419 | ldlang_add_file (entry) |
2420 | lang_input_statement_type * entry; | |
2fa0b342 | 2421 | { |
5e6cd559 ILT |
2422 | bfd **pp; |
2423 | ||
075d7359 SC |
2424 | lang_statement_append (&file_chain, |
2425 | (lang_statement_union_type *) entry, | |
2426 | &entry->next); | |
c477527c ILT |
2427 | |
2428 | /* The BFD linker needs to have a list of all input BFDs involved in | |
2429 | a link. */ | |
2430 | ASSERT (entry->the_bfd->link_next == (bfd *) NULL); | |
2431 | ASSERT (entry->the_bfd != output_bfd); | |
5e6cd559 ILT |
2432 | for (pp = &link_info.input_bfds; |
2433 | *pp != (bfd *) NULL; | |
2434 | pp = &(*pp)->link_next) | |
2435 | ; | |
2436 | *pp = entry->the_bfd; | |
c477527c | 2437 | entry->the_bfd->usrdata = (PTR) entry; |
fc1dfb71 | 2438 | bfd_set_gp_size (entry->the_bfd, g_switch_value); |
2fa0b342 DHW |
2439 | } |
2440 | ||
2fa0b342 | 2441 | void |
2c6635a4 | 2442 | lang_add_output (name, from_script) |
8ddef552 | 2443 | CONST char *name; |
2c6635a4 | 2444 | int from_script; |
2fa0b342 | 2445 | { |
2c6635a4 ILT |
2446 | /* Make -o on command line override OUTPUT in script. */ |
2447 | if (had_output_filename == false || !from_script) | |
2448 | { | |
2449 | output_filename = name; | |
2450 | had_output_filename = true; | |
2451 | } | |
2fa0b342 DHW |
2452 | } |
2453 | ||
2454 | ||
2455 | static lang_output_section_statement_type *current_section; | |
2456 | ||
e20873a7 | 2457 | static int topower(x) |
9f629407 | 2458 | int x; |
e20873a7 JG |
2459 | { |
2460 | unsigned int i = 1; | |
2461 | int l; | |
2462 | if (x < 0) return -1; | |
2463 | for (l = 0; l < 32; l++) | |
2464 | { | |
2465 | if (i >= x) return l; | |
2466 | i<<=1; | |
2467 | } | |
29f33467 | 2468 | return 0; |
e20873a7 | 2469 | } |
2fa0b342 | 2470 | void |
8ddef552 DM |
2471 | lang_enter_output_section_statement (output_section_statement_name, |
2472 | address_exp, flags, block_value, | |
9f629407 | 2473 | align, subalign, ebase) |
fcf276c4 | 2474 | const char *output_section_statement_name; |
8ddef552 DM |
2475 | etree_type * address_exp; |
2476 | int flags; | |
2477 | bfd_vma block_value; | |
2478 | etree_type *align; | |
2479 | etree_type *subalign; | |
9f629407 | 2480 | etree_type *ebase; |
2fa0b342 DHW |
2481 | { |
2482 | lang_output_section_statement_type *os; | |
075d7359 SC |
2483 | |
2484 | current_section = | |
e20873a7 | 2485 | os = |
075d7359 SC |
2486 | lang_output_section_statement_lookup (output_section_statement_name); |
2487 | ||
2488 | ||
2fa0b342 | 2489 | |
2fa0b342 DHW |
2490 | /* Add this statement to tree */ |
2491 | /* add_statement(lang_output_section_statement_enum, | |
2492 | output_section_statement);*/ | |
2493 | /* Make next things chain into subchain of this */ | |
2494 | ||
2495 | if (os->addr_tree == | |
075d7359 | 2496 | (etree_type *) NULL) |
e20873a7 JG |
2497 | { |
2498 | os->addr_tree = | |
2499 | address_exp; | |
2500 | } | |
7bc4a0d7 | 2501 | os->flags = flags; |
ae475b39 SC |
2502 | if (flags & SEC_NEVER_LOAD) |
2503 | os->loadable = 0; | |
2504 | else | |
2505 | os->loadable = 1; | |
29f33467 | 2506 | os->block_value = block_value ? block_value : 1; |
075d7359 | 2507 | stat_ptr = &os->children; |
2fa0b342 | 2508 | |
e20873a7 JG |
2509 | os->subsection_alignment = topower( |
2510 | exp_get_value_int(subalign, -1, | |
2511 | "subsection alignment", | |
2512 | 0)); | |
2513 | os->section_alignment = topower( | |
2514 | exp_get_value_int(align, -1, | |
2515 | "section alignment", 0)); | |
9fce28ed | 2516 | |
9f629407 | 2517 | os->load_base = ebase; |
2fa0b342 DHW |
2518 | } |
2519 | ||
9fce28ed | 2520 | |
075d7359 | 2521 | void |
8ddef552 | 2522 | lang_final () |
2fa0b342 | 2523 | { |
2c6635a4 ILT |
2524 | lang_output_statement_type *new = |
2525 | new_stat (lang_output_statement, stat_ptr); | |
2fa0b342 | 2526 | |
2c6635a4 | 2527 | new->name = output_filename; |
075d7359 | 2528 | } |
2fa0b342 | 2529 | |
c611e285 SC |
2530 | /* Reset the current counters in the regions */ |
2531 | static void | |
8ddef552 | 2532 | reset_memory_regions () |
c611e285 | 2533 | { |
075d7359 SC |
2534 | lang_memory_region_type *p = lang_memory_region_list; |
2535 | ||
c611e285 | 2536 | for (p = lang_memory_region_list; |
075d7359 SC |
2537 | p != (lang_memory_region_type *) NULL; |
2538 | p = p->next) | |
2539 | { | |
8ddef552 | 2540 | p->old_length = (bfd_size_type) (p->current - p->origin); |
075d7359 SC |
2541 | p->current = p->origin; |
2542 | } | |
c611e285 | 2543 | } |
2fa0b342 | 2544 | |
2fa0b342 | 2545 | void |
8ddef552 | 2546 | lang_process () |
075d7359 | 2547 | { |
075d7359 | 2548 | lang_reasonable_defaults (); |
1418c83b SC |
2549 | current_target = default_target; |
2550 | ||
075d7359 | 2551 | lang_for_each_statement (ldlang_open_output); /* Open the output file */ |
1418c83b | 2552 | |
97fbbaca JL |
2553 | ldemul_create_output_section_statements (); |
2554 | ||
1418c83b | 2555 | /* Add to the hash table all undefineds on the command line */ |
075d7359 | 2556 | lang_place_undefineds (); |
1418c83b SC |
2557 | |
2558 | /* Create a bfd for each input file */ | |
2559 | current_target = default_target; | |
309c8153 | 2560 | open_input_bfds (statement_list.head, false); |
1418c83b | 2561 | |
c477527c ILT |
2562 | /* Build all sets based on the information gathered from the input |
2563 | files. */ | |
2564 | ldctor_build_sets (); | |
2565 | ||
4fdbafb2 ILT |
2566 | /* Size up the common data */ |
2567 | lang_common (); | |
2568 | ||
1418c83b | 2569 | /* Run through the contours of the script and attatch input sections |
075d7359 | 2570 | to the correct output sections |
1418c83b | 2571 | */ |
075d7359 SC |
2572 | map_input_to_output_sections (statement_list.head, (char *) NULL, |
2573 | (lang_output_section_statement_type *) NULL); | |
1418c83b | 2574 | |
81016051 | 2575 | |
1418c83b | 2576 | /* Find any sections not attatched explicitly and handle them */ |
075d7359 | 2577 | lang_place_orphans (); |
1418c83b | 2578 | |
075d7359 | 2579 | ldemul_before_allocation (); |
1418c83b | 2580 | |
c611e285 | 2581 | /* Now run around and relax if we can */ |
075d7359 | 2582 | if (command_line.relax) |
c611e285 | 2583 | { |
97fbbaca JL |
2584 | /* First time round is a trial run to get the 'worst case' |
2585 | addresses of the objects if there was no relaxing. */ | |
ae475b39 | 2586 | lang_size_sections (statement_list.head, |
193c5f93 | 2587 | abs_output_section, |
ae475b39 | 2588 | &(statement_list.head), 0, (bfd_vma) 0, false); |
c611e285 | 2589 | |
075d7359 | 2590 | |
97fbbaca | 2591 | reset_memory_regions (); |
075d7359 | 2592 | |
193c5f93 ILT |
2593 | /* Keep relaxing until bfd_relax_section gives up. */ |
2594 | do | |
2595 | { | |
2596 | relax_again = false; | |
ae475b39 | 2597 | |
193c5f93 ILT |
2598 | /* Do all the assignments with our current guesses as to |
2599 | section sizes. */ | |
2600 | lang_do_assignments (statement_list.head, | |
2601 | abs_output_section, | |
2602 | (fill_type) 0, (bfd_vma) 0); | |
ae475b39 | 2603 | |
193c5f93 ILT |
2604 | /* Perform another relax pass - this time we know where the |
2605 | globals are, so can make better guess. */ | |
2606 | lang_size_sections (statement_list.head, | |
2607 | abs_output_section, | |
2608 | &(statement_list.head), 0, (bfd_vma) 0, true); | |
2609 | } | |
2610 | while (relax_again); | |
ae475b39 | 2611 | } |
ae475b39 SC |
2612 | else |
2613 | { | |
97fbbaca | 2614 | /* Size up the sections. */ |
ae475b39 SC |
2615 | lang_size_sections (statement_list.head, |
2616 | abs_output_section, | |
2617 | &(statement_list.head), 0, (bfd_vma) 0, false); | |
075d7359 | 2618 | } |
c611e285 | 2619 | |
1418c83b | 2620 | /* See if anything special should be done now we know how big |
97fbbaca | 2621 | everything is. */ |
075d7359 | 2622 | ldemul_after_allocation (); |
1418c83b SC |
2623 | |
2624 | /* Do all the assignments, now that we know the final restingplaces | |
2625 | of all the symbols */ | |
2626 | ||
075d7359 SC |
2627 | lang_do_assignments (statement_list.head, |
2628 | abs_output_section, | |
c477527c | 2629 | (fill_type) 0, (bfd_vma) 0); |
ffc50032 | 2630 | |
1418c83b SC |
2631 | /* Make sure that we're not mixing architectures */ |
2632 | ||
075d7359 | 2633 | lang_check (); |
1418c83b | 2634 | |
1418c83b | 2635 | /* Final stuffs */ |
97fbbaca JL |
2636 | |
2637 | ldemul_finish (); | |
075d7359 | 2638 | lang_finish (); |
2fa0b342 DHW |
2639 | } |
2640 | ||
2fa0b342 | 2641 | /* EXPORTED TO YACC */ |
1418c83b | 2642 | |
2fa0b342 | 2643 | void |
8ddef552 DM |
2644 | lang_add_wild (section_name, filename) |
2645 | CONST char *CONST section_name; | |
2646 | CONST char *CONST filename; | |
1418c83b | 2647 | { |
075d7359 SC |
2648 | lang_wild_statement_type *new = new_stat (lang_wild_statement, |
2649 | stat_ptr); | |
1418c83b | 2650 | |
075d7359 SC |
2651 | if (section_name != (char *) NULL && strcmp (section_name, "COMMON") == 0) |
2652 | { | |
2653 | placed_commons = true; | |
2654 | } | |
2655 | if (filename != (char *) NULL) | |
2656 | { | |
2657 | lang_has_input_file = true; | |
2658 | } | |
1418c83b SC |
2659 | new->section_name = section_name; |
2660 | new->filename = filename; | |
075d7359 | 2661 | lang_list_init (&new->children); |
1418c83b | 2662 | } |
075d7359 | 2663 | |
1418c83b | 2664 | void |
8ddef552 DM |
2665 | lang_section_start (name, address) |
2666 | CONST char *name; | |
2667 | etree_type * address; | |
2fa0b342 | 2668 | { |
075d7359 SC |
2669 | lang_address_statement_type *ad = new_stat (lang_address_statement, stat_ptr); |
2670 | ||
2fa0b342 DHW |
2671 | ad->section_name = name; |
2672 | ad->address = address; | |
2673 | } | |
1418c83b | 2674 | |
60e8a534 ILT |
2675 | /* Set the start symbol to NAME. CMDLINE is nonzero if this is called |
2676 | because of a -e argument on the command line, or zero if this is | |
2677 | called by ENTRY in a linker script. Command line arguments take | |
2678 | precedence. */ | |
2679 | ||
075d7359 | 2680 | void |
60e8a534 | 2681 | lang_add_entry (name, cmdline) |
8ddef552 | 2682 | CONST char *name; |
60e8a534 | 2683 | int cmdline; |
2fa0b342 | 2684 | { |
60e8a534 ILT |
2685 | static int from_cmdline; |
2686 | ||
2687 | if (entry_symbol == NULL | |
2688 | || cmdline | |
2689 | || ! from_cmdline) | |
2690 | { | |
2691 | entry_symbol = name; | |
2692 | from_cmdline = cmdline; | |
2693 | } | |
2fa0b342 DHW |
2694 | } |
2695 | ||
2696 | void | |
8ddef552 DM |
2697 | lang_add_target (name) |
2698 | CONST char *name; | |
2fa0b342 | 2699 | { |
075d7359 SC |
2700 | lang_target_statement_type *new = new_stat (lang_target_statement, |
2701 | stat_ptr); | |
2702 | ||
2fa0b342 DHW |
2703 | new->target = name; |
2704 | ||
2705 | } | |
2fa0b342 | 2706 | |
2fa0b342 | 2707 | void |
8ddef552 DM |
2708 | lang_add_map (name) |
2709 | CONST char *name; | |
2fa0b342 | 2710 | { |
075d7359 SC |
2711 | while (*name) |
2712 | { | |
2713 | switch (*name) | |
2714 | { | |
2715 | case 'F': | |
2716 | map_option_f = true; | |
2717 | break; | |
2718 | } | |
2719 | name++; | |
2fa0b342 | 2720 | } |
2fa0b342 DHW |
2721 | } |
2722 | ||
075d7359 | 2723 | void |
8ddef552 DM |
2724 | lang_add_fill (exp) |
2725 | int exp; | |
2fa0b342 | 2726 | { |
075d7359 SC |
2727 | lang_fill_statement_type *new = new_stat (lang_fill_statement, |
2728 | stat_ptr); | |
2729 | ||
2fa0b342 DHW |
2730 | new->fill = exp; |
2731 | } | |
2732 | ||
075d7359 | 2733 | void |
8ddef552 DM |
2734 | lang_add_data (type, exp) |
2735 | int type; | |
2736 | union etree_union *exp; | |
2fa0b342 DHW |
2737 | { |
2738 | ||
075d7359 | 2739 | lang_data_statement_type *new = new_stat (lang_data_statement, |
2fa0b342 | 2740 | stat_ptr); |
075d7359 SC |
2741 | |
2742 | new->exp = exp; | |
2743 | new->type = type; | |
2fa0b342 DHW |
2744 | |
2745 | } | |
075d7359 | 2746 | |
4fdbafb2 ILT |
2747 | /* Create a new reloc statement. RELOC is the BFD relocation type to |
2748 | generate. HOWTO is the corresponding howto structure (we could | |
2749 | look this up, but the caller has already done so). SECTION is the | |
2750 | section to generate a reloc against, or NAME is the name of the | |
2751 | symbol to generate a reloc against. Exactly one of SECTION and | |
2752 | NAME must be NULL. ADDEND is an expression for the addend. */ | |
2753 | ||
2754 | void | |
2755 | lang_add_reloc (reloc, howto, section, name, addend) | |
2756 | bfd_reloc_code_real_type reloc; | |
2757 | const reloc_howto_type *howto; | |
2758 | asection *section; | |
2759 | const char *name; | |
2760 | union etree_union *addend; | |
2761 | { | |
2762 | lang_reloc_statement_type *p = new_stat (lang_reloc_statement, stat_ptr); | |
2763 | ||
2764 | p->reloc = reloc; | |
2765 | p->howto = howto; | |
2766 | p->section = section; | |
2767 | p->name = name; | |
2768 | p->addend_exp = addend; | |
2769 | ||
2770 | p->addend_value = 0; | |
2771 | p->output_section = NULL; | |
2772 | p->output_vma = 0; | |
2773 | } | |
2774 | ||
2fa0b342 | 2775 | void |
8ddef552 DM |
2776 | lang_add_assignment (exp) |
2777 | etree_type * exp; | |
2fa0b342 | 2778 | { |
075d7359 SC |
2779 | lang_assignment_statement_type *new = new_stat (lang_assignment_statement, |
2780 | stat_ptr); | |
2781 | ||
2fa0b342 DHW |
2782 | new->exp = exp; |
2783 | } | |
2784 | ||
2785 | void | |
8ddef552 DM |
2786 | lang_add_attribute (attribute) |
2787 | enum statement_enum attribute; | |
2fa0b342 | 2788 | { |
075d7359 | 2789 | new_statement (attribute, sizeof (lang_statement_union_type), stat_ptr); |
2fa0b342 DHW |
2790 | } |
2791 | ||
075d7359 | 2792 | void |
8ddef552 DM |
2793 | lang_startup (name) |
2794 | CONST char *name; | |
2fa0b342 | 2795 | { |
075d7359 SC |
2796 | if (startup_file != (char *) NULL) |
2797 | { | |
ddddcdf0 | 2798 | einfo ("%P%Fmultiple STARTUP files\n"); |
075d7359 | 2799 | } |
2fa0b342 DHW |
2800 | first_file->filename = name; |
2801 | first_file->local_sym_name = name; | |
193c5f93 | 2802 | first_file->real = true; |
2fa0b342 | 2803 | |
075d7359 | 2804 | startup_file = name; |
2fa0b342 | 2805 | } |
075d7359 SC |
2806 | |
2807 | void | |
8ddef552 DM |
2808 | lang_float (maybe) |
2809 | boolean maybe; | |
2fa0b342 DHW |
2810 | { |
2811 | lang_float_flag = maybe; | |
2812 | } | |
2813 | ||
075d7359 | 2814 | void |
8ddef552 DM |
2815 | lang_leave_output_section_statement (fill, memspec) |
2816 | bfd_vma fill; | |
2817 | CONST char *memspec; | |
2fa0b342 DHW |
2818 | { |
2819 | current_section->fill = fill; | |
075d7359 | 2820 | current_section->region = lang_memory_region_lookup (memspec); |
2fa0b342 DHW |
2821 | stat_ptr = &statement_list; |
2822 | } | |
075d7359 | 2823 | |
9f32f7c2 SC |
2824 | /* |
2825 | Create an absolute symbol with the given name with the value of the | |
2826 | address of first byte of the section named. | |
2fa0b342 | 2827 | |
9f32f7c2 SC |
2828 | If the symbol already exists, then do nothing. |
2829 | */ | |
8cb5eb31 | 2830 | void |
c477527c ILT |
2831 | lang_abs_symbol_at_beginning_of (secname, name) |
2832 | const char *secname; | |
2833 | const char *name; | |
075d7359 | 2834 | { |
c477527c ILT |
2835 | struct bfd_link_hash_entry *h; |
2836 | ||
2837 | h = bfd_link_hash_lookup (link_info.hash, name, true, true, true); | |
2838 | if (h == (struct bfd_link_hash_entry *) NULL) | |
2839 | einfo ("%P%F: bfd_link_hash_lookup failed: %E\n"); | |
2840 | ||
2841 | if (h->type == bfd_link_hash_new | |
2842 | || h->type == bfd_link_hash_undefined) | |
075d7359 | 2843 | { |
c477527c | 2844 | asection *sec; |
075d7359 | 2845 | |
c477527c ILT |
2846 | h->type = bfd_link_hash_defined; |
2847 | ||
2848 | sec = bfd_get_section_by_name (output_bfd, secname); | |
2849 | if (sec == (asection *) NULL) | |
2850 | h->u.def.value = 0; | |
075d7359 | 2851 | else |
c477527c ILT |
2852 | h->u.def.value = bfd_get_section_vma (output_bfd, sec); |
2853 | ||
686739e2 | 2854 | h->u.def.section = bfd_abs_section_ptr; |
9f32f7c2 | 2855 | } |
8cb5eb31 SC |
2856 | } |
2857 | ||
9f32f7c2 SC |
2858 | /* |
2859 | Create an absolute symbol with the given name with the value of the | |
2860 | address of the first byte after the end of the section named. | |
2861 | ||
2862 | If the symbol already exists, then do nothing. | |
2863 | */ | |
2fa0b342 | 2864 | void |
c477527c ILT |
2865 | lang_abs_symbol_at_end_of (secname, name) |
2866 | const char *secname; | |
2867 | const char *name; | |
075d7359 | 2868 | { |
c477527c ILT |
2869 | struct bfd_link_hash_entry *h; |
2870 | ||
2871 | h = bfd_link_hash_lookup (link_info.hash, name, true, true, true); | |
2872 | if (h == (struct bfd_link_hash_entry *) NULL) | |
2873 | einfo ("%P%F: bfd_link_hash_lookup failed: %E\n"); | |
2874 | ||
2875 | if (h->type == bfd_link_hash_new | |
2876 | || h->type == bfd_link_hash_undefined) | |
075d7359 | 2877 | { |
c477527c | 2878 | asection *sec; |
075d7359 | 2879 | |
c477527c | 2880 | h->type = bfd_link_hash_defined; |
075d7359 | 2881 | |
c477527c ILT |
2882 | sec = bfd_get_section_by_name (output_bfd, secname); |
2883 | if (sec == (asection *) NULL) | |
2884 | h->u.def.value = 0; | |
075d7359 | 2885 | else |
c477527c ILT |
2886 | h->u.def.value = (bfd_get_section_vma (output_bfd, sec) |
2887 | + bfd_section_size (output_bfd, sec)); | |
2888 | ||
686739e2 | 2889 | h->u.def.section = bfd_abs_section_ptr; |
9f32f7c2 | 2890 | } |
2fa0b342 DHW |
2891 | } |
2892 | ||
075d7359 | 2893 | void |
8ddef552 DM |
2894 | lang_statement_append (list, element, field) |
2895 | lang_statement_list_type * list; | |
2896 | lang_statement_union_type * element; | |
2897 | lang_statement_union_type ** field; | |
2fa0b342 DHW |
2898 | { |
2899 | *(list->tail) = element; | |
2900 | list->tail = field; | |
2901 | } | |
2902 | ||
173a0c3d | 2903 | /* Set the output format type. -oformat overrides scripts. */ |
097879bc | 2904 | void |
173a0c3d | 2905 | lang_add_output_format (format, from_script) |
8ddef552 | 2906 | CONST char *format; |
173a0c3d | 2907 | int from_script; |
097879bc | 2908 | { |
2c6635a4 | 2909 | if (output_target == NULL || !from_script) |
173a0c3d | 2910 | output_target = format; |
097879bc | 2911 | } |
309c8153 ILT |
2912 | |
2913 | /* Enter a group. This creates a new lang_group_statement, and sets | |
2914 | stat_ptr to build new statements within the group. */ | |
2915 | ||
2916 | void | |
2917 | lang_enter_group () | |
2918 | { | |
2919 | lang_group_statement_type *g; | |
2920 | ||
2921 | g = new_stat (lang_group_statement, stat_ptr); | |
2922 | lang_list_init (&g->children); | |
2923 | stat_ptr = &g->children; | |
2924 | } | |
2925 | ||
2926 | /* Leave a group. This just resets stat_ptr to start writing to the | |
2927 | regular list of statements again. Note that this will not work if | |
2928 | groups can occur inside anything else which can adjust stat_ptr, | |
2929 | but currently they can't. */ | |
2930 | ||
2931 | void | |
2932 | lang_leave_group () | |
2933 | { | |
2934 | stat_ptr = &statement_list; | |
2935 | } |