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