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