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