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