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