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