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