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