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