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