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