1 /* Copyright (C) 1991 Free Software Foundation, Inc.
3 This file is part of GLD, the Gnu Linker.
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)
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.
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. */
31 #include "ldgram.tab.h"
40 extern char *default_target
;
42 extern unsigned int undefined_global_sym_count
;
44 static CONST
char *startup_file
;
45 static lang_input_statement_type
*first_file
;
46 lang_statement_list_type statement_list
;
47 lang_statement_list_type
*stat_ptr
= &statement_list
;
48 lang_statement_list_type lang_output_section_statement
;
49 lang_statement_list_type input_file_chain
;
50 lang_statement_list_type file_chain
;
51 extern char *current_file
;
52 static boolean placed_commons
= false;
54 boolean lang_float_flag
;
56 static lang_output_section_statement_type
*default_common_section
;
60 PROTO(static void, print_statements
,(void));
61 PROTO(static void, print_statement
,(lang_statement_union_type
*,
62 lang_output_section_statement_type
*));
67 boolean lang_has_input_file
= false;
70 extern bfd
*output_bfd
;
71 size_t largest_section
;
74 extern enum bfd_architecture ldfile_output_architecture
;
75 extern unsigned long ldfile_output_machine
;
76 extern char *ldfile_output_machine_name
;
79 extern ldsym_type
*symbol_head
;
82 unsigned int commons_pending
;
87 extern args_type command_line
;
88 extern ld_config_type config
;
90 CONST
char *entry_symbol
;
94 lang_output_section_statement_type
*create_object_symbols
;
96 extern boolean had_script
;
97 static boolean map_option_f
;
100 boolean had_output_filename
= false;
101 extern boolean write_map
;
108 size_t longest_section_name
= 8;
111 lang_input_statement_type
*script_file
;
113 section_userdata_type common_section_userdata
;
114 asection common_section
;
117 #define cat(a,b) a##b
119 #define cat(a,b) a/**/b
122 #define new_stat(x,y) (cat(x,_type)*) new_statement(cat(x,_enum), sizeof(cat(x,_type)),y)
124 #define outside_section_address(q) ( (q)->output_offset + (q)->output_section->vma)
126 #define outside_symbol_address(q) ((q)->value + outside_section_address(q->section))
128 boolean option_longmap
= false;
130 /*----------------------------------------------------------------------
131 lang_for_each_statement walks the parse tree and calls the provided
132 function for each node
136 DEFUN(lang_for_each_statement_worker
,(func
, s
),
138 lang_statement_union_type
*s
)
140 for (; s
!= (lang_statement_union_type
*)NULL
; s
= s
->next
)
144 switch (s
->header
.type
) {
145 case lang_output_section_statement_enum
:
146 lang_for_each_statement_worker
148 s
->output_section_statement
.children
.head
);
150 case lang_wild_statement_enum
:
151 lang_for_each_statement_worker
153 s
->wild_statement
.children
.head
);
155 case lang_data_statement_enum
:
156 case lang_object_symbols_statement_enum
:
157 case lang_output_statement_enum
:
158 case lang_target_statement_enum
:
159 case lang_input_section_enum
:
160 case lang_input_statement_enum
:
161 case lang_fill_statement_enum
:
162 case lang_assignment_statement_enum
:
163 case lang_padding_statement_enum
:
164 case lang_address_statement_enum
:
174 DEFUN(lang_for_each_statement
,(func
),
177 lang_for_each_statement_worker(func
,
178 statement_list
.head
);
180 /*----------------------------------------------------------------------*/
182 DEFUN(lang_list_init
,(list
),
183 lang_statement_list_type
*list
)
185 list
->head
= (lang_statement_union_type
*)NULL
;
186 list
->tail
= &list
->head
;
189 /*----------------------------------------------------------------------
190 Functions to print the link map
194 DEFUN(print_section
,(name
),
195 CONST
char *CONST name
)
197 printf("%*s", -longest_section_name
, name
);
200 DEFUN_VOID(print_space
)
210 DEFUN(print_address
,(value
),
213 printf("%8lx", value
);
216 DEFUN(print_size
,(value
),
219 printf("%5x", (unsigned)value
);
222 DEFUN(print_alignment
,(value
),
225 printf("2**%2u",value
);
229 DEFUN(print_fill
,(value
),
232 printf("%04x",(unsigned)value
);
235 /*----------------------------------------------------------------------
237 build a new statement node for the parse tree
242 lang_statement_union_type
*
243 DEFUN(new_statement
,(type
, size
, list
),
244 enum statement_enum type AND
246 lang_statement_list_type
*list
)
248 lang_statement_union_type
*new = (lang_statement_union_type
*)
250 new->header
.type
= type
;
251 new->header
.next
= (lang_statement_union_type
*)NULL
;
252 lang_statement_append(list
, new, &new->header
.next
);
257 Build a new input file node for the language. There are several ways
258 in which we treat an input file, eg, we only look at symbols, or
259 prefix it with a -l etc.
261 We can be supplied with requests for input files more than once;
262 they may, for example be split over serveral lines like foo.o(.text)
263 foo.o(.data) etc, so when asked for a file we check that we havn't
264 got it already so we don't duplicate the bfd.
267 static lang_input_statement_type
*
268 DEFUN(new_afile
, (name
, file_type
, target
),
269 CONST
char *CONST name AND
270 CONST lang_input_file_enum_type file_type AND
271 CONST
char *CONST target
)
273 lang_input_statement_type
*p
= new_stat(lang_input_statement
,
275 lang_has_input_file
= true;
278 case lang_input_file_is_symbols_only_enum
:
280 p
->is_archive
=false;
282 p
->local_sym_name
= name
;
283 p
->just_syms_flag
= true;
284 p
->search_dirs_flag
= false;
286 case lang_input_file_is_fake_enum
:
288 p
->is_archive
=false;
290 p
->local_sym_name
= name
;
291 p
->just_syms_flag
= false;
292 p
->search_dirs_flag
=false;
294 case lang_input_file_is_l_enum
:
295 p
->is_archive
= true;
298 p
->local_sym_name
= concat("-l",name
,"");
299 p
->just_syms_flag
= false;
300 p
->search_dirs_flag
= true;
302 case lang_input_file_is_search_file_enum
:
303 case lang_input_file_is_marker_enum
:
305 p
->is_archive
=false;
307 p
->local_sym_name
= name
;
308 p
->just_syms_flag
= false;
309 p
->search_dirs_flag
=true;
311 case lang_input_file_is_file_enum
:
313 p
->is_archive
=false;
315 p
->local_sym_name
= name
;
316 p
->just_syms_flag
= false;
317 p
->search_dirs_flag
=false;
322 p
->asymbols
= (asymbol
**)NULL
;
323 p
->superfile
= (lang_input_statement_type
*)NULL
;
324 p
->next_real_file
= (lang_statement_union_type
*)NULL
;
325 p
->next
= (lang_statement_union_type
*)NULL
;
327 p
->common_output_section
= (asection
*)NULL
;
328 lang_statement_append(&input_file_chain
,
329 (lang_statement_union_type
*)p
,
336 lang_input_statement_type
*
337 DEFUN(lang_add_input_file
,(name
, file_type
, target
),
339 lang_input_file_enum_type file_type AND
342 /* Look it up or build a new one */
343 lang_has_input_file
= true;
345 lang_input_statement_type
*p
;
347 for (p
= (lang_input_statement_type
*)input_file_chain
.head
;
348 p
!= (lang_input_statement_type
*)NULL
;
349 p
= (lang_input_statement_type
*)(p
->next_real_file
))
351 /* Sometimes we have incomplete entries in here */
352 if (p
->filename
!= (char *)NULL
) {
353 if(strcmp(name
,p
->filename
) == 0) return p
;
358 return new_afile(name
, file_type
, target
);
362 /* Build enough state so that the parser can build its tree */
364 DEFUN_VOID(lang_init
)
367 stat_ptr
= &statement_list
;
368 lang_list_init(stat_ptr
);
370 lang_list_init(&input_file_chain
);
371 lang_list_init(&lang_output_section_statement
);
372 lang_list_init(&file_chain
);
373 first_file
= lang_add_input_file((char *)NULL
,
374 lang_input_file_is_marker_enum
,
379 /*----------------------------------------------------------------------
380 A region is an area of memory declared with the
381 MEMORY { name:org=exp, len=exp ... }
384 We maintain a list of all the regions here
386 If no regions are specified in the script, then the default is used
387 which is created when looked up to be the entire data space
390 static lang_memory_region_type
*lang_memory_region_list
;
391 static lang_memory_region_type
**lang_memory_region_list_tail
= &lang_memory_region_list
;
393 lang_memory_region_type
*
394 DEFUN(lang_memory_region_lookup
,(name
),
395 CONST
char *CONST name
)
398 lang_memory_region_type
*p
= lang_memory_region_list
;
399 for (p
= lang_memory_region_list
;
400 p
!= ( lang_memory_region_type
*)NULL
;
402 if (strcmp(p
->name
, name
) == 0) {
406 if (strcmp(name
,"*default*")==0) {
407 /* This is the default region, dig out first one on the list */
408 if (lang_memory_region_list
!= (lang_memory_region_type
*)NULL
){
409 return lang_memory_region_list
;
413 lang_memory_region_type
*new =
414 (lang_memory_region_type
*)ldmalloc(sizeof(lang_memory_region_type
));
415 new->name
= buystring(name
);
416 new->next
= (lang_memory_region_type
*)NULL
;
418 *lang_memory_region_list_tail
= new;
419 lang_memory_region_list_tail
= &new->next
;
428 lang_output_section_statement_type
*
429 DEFUN(lang_output_section_find
,(name
),
430 CONST
char * CONST name
)
432 lang_statement_union_type
*u
;
433 lang_output_section_statement_type
*lookup
;
435 for (u
= lang_output_section_statement
.head
;
436 u
!= (lang_statement_union_type
*)NULL
;
439 lookup
= &u
->output_section_statement
;
440 if (strcmp(name
, lookup
->name
)==0) {
444 return (lang_output_section_statement_type
*)NULL
;
447 lang_output_section_statement_type
*
448 DEFUN(lang_output_section_statement_lookup
,(name
),
449 CONST
char * CONST name
)
451 lang_output_section_statement_type
*lookup
;
452 lookup
=lang_output_section_find(name
);
453 if (lookup
== (lang_output_section_statement_type
*)NULL
) {
455 lookup
=(lang_output_section_statement_type
*)
456 new_stat(lang_output_section_statement
, stat_ptr
);
457 lookup
->region
= (lang_memory_region_type
*)NULL
;
459 lookup
->block_value
= 1;
462 lookup
->next
= (lang_statement_union_type
*)NULL
;
463 lookup
->bfd_section
= (asection
*)NULL
;
464 lookup
->processed
= false;
465 lookup
->addr_tree
= (etree_type
*)NULL
;
466 lang_list_init(&lookup
->children
);
468 lang_statement_append(&lang_output_section_statement
,
469 (lang_statement_union_type
*)lookup
,
480 DEFUN(print_flags
, (outfile
, ignore_flags
),
482 lang_section_flags_type
*ignore_flags
)
484 fprintf(outfile
,"(");
486 if (flags
->flag_read
) fprintf(outfile
,"R");
487 if (flags
->flag_write
) fprintf(outfile
,"W");
488 if (flags
->flag_executable
) fprintf(outfile
,"X");
489 if (flags
->flag_loadable
) fprintf(outfile
,"L");
491 fprintf(outfile
,")");
495 DEFUN(lang_map
,(outfile
),
498 lang_memory_region_type
*m
;
499 fprintf(outfile
,"**MEMORY CONFIGURATION**\n\n");
501 fprintf(outfile
,"name\t\torigin\t\tlength\t\tattributes\n");
502 for (m
= lang_memory_region_list
;
503 m
!= (lang_memory_region_type
*)NULL
;
506 fprintf(outfile
,"%-16s", m
->name
);
508 fprintf(outfile
,"%08lx\t%08lx\t", m
->origin
, m
->length
);
509 print_flags(outfile
, &m
->flags
);
510 fprintf(outfile
,"\n");
512 fprintf(outfile
,"\n\n**LINK EDITOR MEMORY MAP**\n\n");
513 fprintf(outfile
,"output\t\tinput\t\tvirtual\n");
514 fprintf(outfile
,"section\t\tsection\t\taddress\tsize\n\n");
525 lang_output_section_statement_type
*s
)
527 section_userdata_type
*new =
528 (section_userdata_type
*)
529 ldmalloc(sizeof(section_userdata_type
));
531 s
->bfd_section
= bfd_make_section(output_bfd
, s
->name
);
532 s
->bfd_section
->output_section
= s
->bfd_section
;
533 s
->bfd_section
->flags
= SEC_NO_FLAGS
;
534 /* We initialize an output sections output offset to minus its own */
535 /* vma to allow us to output a section through itself */
536 s
->bfd_section
->output_offset
= 0;
537 get_userdata( s
->bfd_section
) = new;
540 /***********************************************************************
543 These expand statements like *(.text) and foo.o to a list of
544 explicit actions, like foo.o(.text), bar.o(.text) and
547 The toplevel routine, wild, takes a statement, section, file and
548 target. If either the section or file is null it is taken to be the
549 wildcard. Seperate lang_input_section statements are created for
550 each part of the expanstion, and placed after the statement provided.
555 DEFUN(wild_doit
,(ptr
, section
, output
, file
),
556 lang_statement_list_type
*ptr AND
557 asection
*section AND
558 lang_output_section_statement_type
*output AND
559 lang_input_statement_type
*file
)
561 if(output
->bfd_section
== (asection
*)NULL
)
566 if (section
!= (asection
*)NULL
567 && section
->output_section
== (asection
*)NULL
) {
568 /* Add a section reference to the list */
569 lang_input_section_type
*new = new_stat(lang_input_section
, ptr
);
571 new->section
= section
;
573 section
->output_section
= output
->bfd_section
;
574 section
->output_section
->flags
|= section
->flags
;
575 if (section
->alignment_power
> output
->bfd_section
->alignment_power
) {
576 output
->bfd_section
->alignment_power
= section
->alignment_power
;
582 DEFUN(our_bfd_get_section_by_name
,(abfd
, section
),
586 return bfd_get_section_by_name(abfd
, section
);
590 DEFUN(wild_section
,(ptr
, section
, file
, output
),
591 lang_wild_statement_type
*ptr AND
592 CONST
char *section AND
593 lang_input_statement_type
*file AND
594 lang_output_section_statement_type
*output
)
597 if (file
->just_syms_flag
== false) {
598 if (section
== (char *)NULL
) {
599 /* Do the creation to all sections in the file */
600 for (s
= file
->the_bfd
->sections
; s
!= (asection
*)NULL
; s
=s
->next
) {
601 wild_doit(&ptr
->children
, s
, output
, file
);
605 /* Do the creation to the named section only */
606 wild_doit(&ptr
->children
,
607 our_bfd_get_section_by_name(file
->the_bfd
, section
),
614 /* passed a file name (which must have been seen already and added to
615 the statement tree. We will see if it has been opened already and
616 had its symbols read. If not then we'll read it.
618 Archives are pecuilar here. We may open them once, but if they do
619 not define anything we need at the time, they won't have all their
620 symbols read. If we need them later, we'll have to redo it.
623 lang_input_statement_type
*
624 DEFUN(lookup_name
,(name
),
625 CONST
char * CONST name
)
627 lang_input_statement_type
*search
;
628 for(search
= (lang_input_statement_type
*)input_file_chain
.head
;
629 search
!= (lang_input_statement_type
*)NULL
;
630 search
= (lang_input_statement_type
*)search
->next_real_file
)
632 if (search
->filename
== (char *)NULL
&& name
== (char *)NULL
) {
635 if (search
->filename
!= (char *)NULL
&& name
!= (char *)NULL
) {
636 if (strcmp(search
->filename
, name
) == 0) {
637 ldmain_open_file_read_symbol(search
);
643 /* There isn't an afile entry for this file yet, this must be
644 because the name has only appeared inside a load script and not
645 on the command line */
646 search
= new_afile(name
, lang_input_file_is_file_enum
, default_target
);
647 ldmain_open_file_read_symbol(search
);
654 DEFUN(wild
,(s
, section
, file
, target
, output
),
655 lang_wild_statement_type
*s AND
656 CONST
char *CONST section AND
657 CONST
char *CONST file AND
658 CONST
char *CONST target AND
659 lang_output_section_statement_type
*output
)
661 lang_input_statement_type
*f
;
662 if (file
== (char *)NULL
) {
663 /* Perform the iteration over all files in the list */
664 for (f
= (lang_input_statement_type
*)file_chain
.head
;
665 f
!= (lang_input_statement_type
*)NULL
;
666 f
= (lang_input_statement_type
*)f
->next
) {
667 wild_section(s
, section
, f
, output
);
671 /* Perform the iteration over a single file */
672 wild_section( s
, section
, lookup_name(file
), output
);
674 if (strcmp(section
,"COMMON") == 0
675 && default_common_section
== (lang_output_section_statement_type
*)NULL
)
677 /* Remember the section that common is going to incase we later
678 get something which doesn't know where to put it */
679 default_common_section
= output
;
684 read in all the files
687 DEFUN(open_output
,(name
, target
),
688 CONST
char *CONST name AND
689 CONST
char *CONST target
)
691 extern CONST
char *output_filename
;
692 bfd
* output
= bfd_openw(name
, target
);
693 output_filename
= name
;
694 if (output
== (bfd
*)NULL
)
696 if (bfd_error
== invalid_target
) {
697 info("%P%F target %s not found\n", target
);
699 info("%P%F problem opening output file %s, %E", name
);
702 output
->flags
|= D_PAGED
;
703 bfd_set_format(output
, bfd_object
);
708 static CONST
char *current_target
;
711 DEFUN(ldlang_open_output
,(statement
),
712 lang_statement_union_type
*statement
)
714 switch (statement
->header
.type
)
716 case lang_output_statement_enum
:
717 output_bfd
= open_output(statement
->output_statement
.name
,current_target
);
718 ldemul_set_output_arch();
721 case lang_target_statement_enum
:
722 current_target
= statement
->target_statement
.target
;
730 DEFUN(open_input_bfds
,(statement
),
731 lang_statement_union_type
*statement
)
733 switch (statement
->header
.type
)
735 case lang_target_statement_enum
:
736 current_target
= statement
->target_statement
.target
;
738 case lang_wild_statement_enum
:
739 /* Maybe we should load the file's symbols */
740 if (statement
->wild_statement
.filename
)
742 (void) lookup_name(statement
->wild_statement
.filename
);
745 case lang_input_statement_enum
:
746 if (statement
->input_statement
.real
== true)
748 statement
->input_statement
.target
= current_target
;
749 lookup_name(statement
->input_statement
.filename
);
756 /* If there are [COMMONS] statements, put a wild one into the bss section */
759 lang_reasonable_defaults()
762 lang_output_section_statement_lookup(".text");
763 lang_output_section_statement_lookup(".data");
765 default_common_section
=
766 lang_output_section_statement_lookup(".bss");
769 if (placed_commons
== false) {
770 lang_wild_statement_type
*new =
771 new_stat(lang_wild_statement
,
772 &default_common_section
->children
);
773 new->section_name
= "COMMON";
774 new->filename
= (char *)NULL
;
775 lang_list_init(&new->children
);
782 Add the supplied name to the symbol table as an undefined reference.
783 Remove items from the chain as we open input bfds
785 typedef struct ldlang_undef_chain_list_struct
{
786 struct ldlang_undef_chain_list_struct
*next
;
788 } ldlang_undef_chain_list_type
;
790 static ldlang_undef_chain_list_type
*ldlang_undef_chain_list_head
;
793 DEFUN(ldlang_add_undef
,(name
),
794 CONST
char *CONST name
)
796 ldlang_undef_chain_list_type
*new =
797 (ldlang_undef_chain_list_type
798 *)ldmalloc(sizeof(ldlang_undef_chain_list_type
));
800 new->next
= ldlang_undef_chain_list_head
;
801 ldlang_undef_chain_list_head
= new;
803 new->name
= buystring(name
);
805 /* Run through the list of undefineds created above and place them
806 into the linker hash table as undefined symbols belonging to the
810 DEFUN_VOID(lang_place_undefineds
)
812 ldlang_undef_chain_list_type
*ptr
= ldlang_undef_chain_list_head
;
813 while (ptr
!= (ldlang_undef_chain_list_type
*)NULL
) {
814 ldsym_type
*sy
= ldsym_get(ptr
->name
);
816 asymbol
**def_ptr
= (asymbol
**)ldmalloc(sizeof(asymbol
**));
817 def
= (asymbol
*)bfd_make_empty_symbol(script_file
->the_bfd
);
819 def
->name
= ptr
->name
;
820 def
->flags
= BSF_UNDEFINED
;
821 def
->section
= (asection
*)NULL
;
822 Q_enter_global_ref(def_ptr
);
829 /* Copy important data from out internal form to the bfd way. Also
830 create a section for the dummy file
834 DEFUN_VOID(lang_create_output_section_statements
)
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
;
848 DEFUN_VOID(lang_init_script_file
)
850 script_file
= lang_add_input_file("script file",
851 lang_input_file_is_fake_enum
,
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
;
861 /* Open input files and attatch to output sections */
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
)
868 for (; s
!= (lang_statement_union_type
*)NULL
; s
= s
->next
)
870 switch (s
->header
.type
) {
871 case lang_wild_statement_enum
:
872 wild(&s
->wild_statement
, s
->wild_statement
.section_name
,
873 s
->wild_statement
.filename
, target
,
874 output_section_statement
);
878 case lang_output_section_statement_enum
:
879 map_input_to_output_sections(s
->output_section_statement
.children
.head
,
881 &s
->output_section_statement
);
883 case lang_output_statement_enum
:
885 case lang_target_statement_enum
:
886 target
= s
->target_statement
.target
;
888 case lang_fill_statement_enum
:
889 case lang_input_section_enum
:
890 case lang_object_symbols_statement_enum
:
891 case lang_data_statement_enum
:
892 case lang_assignment_statement_enum
:
893 case lang_padding_statement_enum
:
895 case lang_afile_asection_pair_statement_enum
:
898 case lang_address_statement_enum
:
899 /* Mark the specified section with the supplied address */
901 lang_output_section_statement_type
*os
=
902 lang_output_section_statement_lookup
903 (s
->address_statement
.section_name
);
904 os
->addr_tree
= s
->address_statement
.address
;
907 case lang_input_statement_enum
:
908 /* A standard input statement, has no wildcards */
909 /* ldmain_open_file_read_symbol(&s->input_statement);*/
920 DEFUN(print_output_section_statement
,(output_section_statement
),
921 lang_output_section_statement_type
*output_section_statement
)
923 asection
*section
= output_section_statement
->bfd_section
;
925 print_section(output_section_statement
->name
);
928 print_dot
= section
->vma
;
932 print_address(section
->vma
);
934 print_size(section
->size
);
936 print_alignment(section
->alignment_power
);
939 printf("%s flags", output_section_statement
->region
->name
);
940 print_flags(stdout
, &output_section_statement
->flags
);
945 printf("No attached output section");
948 print_statement(output_section_statement
->children
.head
,
949 output_section_statement
);
954 DEFUN(print_assignment
,(assignment
, output_section
),
955 lang_assignment_statement_type
*assignment AND
956 lang_output_section_statement_type
*output_section
)
958 etree_value_type result
;
963 print_address(print_dot
);
965 result
= exp_fold_tree(assignment
->exp
->assign
.src
,
967 lang_final_phase_enum
,
972 print_address(result
.value
);
976 printf("*undefined*");
979 exp_print_tree(stdout
, assignment
->exp
);
984 DEFUN(print_input_statement
,(statm
),
985 lang_input_statement_type
*statm
)
987 if (statm
->filename
!= (char *)NULL
) {
988 printf("LOAD %s\n",statm
->filename
);
993 DEFUN(print_symbol
,(q
),
1000 print_address(outside_symbol_address(q
));
1001 printf(" %s", q
->name
? q
->name
: " ");
1006 DEFUN(print_input_section
,(in
),
1007 lang_input_section_type
*in
)
1009 asection
*i
= in
->section
;
1014 print_section(i
->name
);
1016 if (i
->output_section
) {
1017 print_address(i
->output_section
->vma
+ i
->output_offset
);
1019 print_size(i
->size
);
1021 print_alignment(i
->alignment_power
);
1025 bfd
*abfd
= in
->ifile
->the_bfd
;
1026 if (in
->ifile
->just_syms_flag
== true) {
1027 printf("symbols only ");
1030 printf(" %s ",abfd
->xvec
->name
);
1031 if(abfd
->my_archive
!= (bfd
*)NULL
) {
1032 printf("[%s]%s", abfd
->my_archive
->filename
,
1036 printf("%s", abfd
->filename
);
1040 /* Find all the symbols in this file defined in this section */
1043 for (p
= in
->ifile
->asymbols
; *p
; p
++) {
1046 if (bfd_get_section(q
) == i
&& q
->flags
& BSF_GLOBAL
) {
1057 print_dot
= outside_section_address(i
) + i
->size
;
1060 printf("No output section allocated\n");
1066 DEFUN(print_fill_statement
,(fill
),
1067 lang_fill_statement_type
*fill
)
1069 printf("FILL mask ");
1070 print_fill( fill
->fill
);
1074 DEFUN(print_data_statement
,(data
),
1075 lang_data_statement_type
*data
)
1077 /* bfd_vma value; */
1082 ASSERT(print_dot
== data
->output_vma
);
1084 print_address(data
->output_vma
);
1086 print_address(data
->value
);
1088 switch (data
->type
) {
1091 print_dot
+= BYTE_SIZE
;
1095 print_dot
+= SHORT_SIZE
;
1099 print_dot
+= LONG_SIZE
;
1103 exp_print_tree(stdout
, data
->exp
);
1110 DEFUN(print_padding_statement
,(s
),
1111 lang_padding_statement_type
*s
)
1115 print_section("*fill*");
1117 print_address(s
->output_offset
+ s
->output_section
->vma
);
1119 print_size(s
->size
);
1121 print_fill(s
->fill
);
1126 DEFUN(print_wild_statement
,(w
,os
),
1127 lang_wild_statement_type
*w AND
1128 lang_output_section_statement_type
*os
)
1130 if (w
->filename
!= (char *)NULL
) {
1131 printf("%s",w
->filename
);
1136 if (w
->section_name
!= (char *)NULL
) {
1137 printf("(%s)",w
->section_name
);
1143 print_statement(w
->children
.head
, os
);
1147 DEFUN(print_statement
,(s
, os
),
1148 lang_statement_union_type
*s AND
1149 lang_output_section_statement_type
*os
)
1152 switch (s
->header
.type
) {
1153 case lang_wild_statement_enum
:
1154 print_wild_statement(&s
->wild_statement
, os
);
1157 printf("Fail with %d\n",s
->header
.type
);
1160 case lang_address_statement_enum
:
1161 printf("address\n");
1164 case lang_object_symbols_statement_enum
:
1165 printf("object symbols\n");
1167 case lang_fill_statement_enum
:
1168 print_fill_statement(&s
->fill_statement
);
1170 case lang_data_statement_enum
:
1171 print_data_statement(&s
->data_statement
);
1173 case lang_input_section_enum
:
1174 print_input_section(&s
->input_section
);
1176 case lang_padding_statement_enum
:
1177 print_padding_statement(&s
->padding_statement
);
1179 case lang_output_section_statement_enum
:
1180 print_output_section_statement(&s
->output_section_statement
);
1182 case lang_assignment_statement_enum
:
1183 print_assignment(&s
->assignment_statement
,
1188 case lang_target_statement_enum
:
1189 printf("TARGET(%s)\n", s
->target_statement
.target
);
1191 case lang_output_statement_enum
:
1192 printf("OUTPUT(%s)\n", s
->output_statement
.name
);
1194 case lang_input_statement_enum
:
1195 print_input_statement(&s
->input_statement
);
1197 case lang_afile_asection_pair_statement_enum
:
1207 DEFUN_VOID(print_statements
)
1209 print_statement(statement_list
.head
,
1210 (lang_output_section_statement_type
*)NULL
);
1214 DEFUN(insert_pad
,(this_ptr
, fill
, power
, output_section_statement
, dot
),
1215 lang_statement_union_type
**this_ptr AND
1217 unsigned int power AND
1218 asection
* output_section_statement AND
1221 /* Align this section first to the
1222 input sections requirement, then
1223 to the output section's requirement.
1224 If this alignment is > than any seen before,
1225 then record it too. Perform the alignment by
1226 inserting a magic 'padding' statement.
1229 unsigned int alignment_needed
= align_power(dot
, power
) - dot
;
1231 if (alignment_needed
!= 0)
1233 lang_statement_union_type
*new =
1234 (lang_statement_union_type
*)
1235 ldmalloc(sizeof(lang_padding_statement_type
));
1236 /* Link into existing chain */
1237 new->header
.next
= *this_ptr
;
1239 new->header
.type
= lang_padding_statement_enum
;
1240 new->padding_statement
.output_section
= output_section_statement
;
1241 new->padding_statement
.output_offset
=
1242 dot
- output_section_statement
->vma
;
1243 new->padding_statement
.fill
= fill
;
1244 new->padding_statement
.size
= alignment_needed
;
1248 /* Remember the most restrictive alignment */
1249 if (power
> output_section_statement
->alignment_power
) {
1250 output_section_statement
->alignment_power
= power
;
1252 output_section_statement
->size
+= alignment_needed
;
1253 return alignment_needed
+ dot
;
1257 /* Work out how much this section will move the dot point */
1259 DEFUN(size_input_section
, (this_ptr
, output_section_statement
, fill
, dot
),
1260 lang_statement_union_type
**this_ptr AND
1261 lang_output_section_statement_type
*output_section_statement AND
1262 unsigned short fill AND
1265 lang_input_section_type
*is
= &((*this_ptr
)->input_section
);
1266 asection
*i
= is
->section
;
1268 if (is
->ifile
->just_syms_flag
== false) {
1269 dot
= insert_pad(this_ptr
, fill
, i
->alignment_power
,
1270 output_section_statement
->bfd_section
, dot
);
1272 /* remember the largest size so we can malloc the largest area */
1273 /* needed for the output stage */
1274 if (i
->size
> largest_section
) {
1275 largest_section
= i
->size
;
1278 /* Remember where in the output section this input section goes */
1279 i
->output_offset
= dot
- output_section_statement
->bfd_section
->vma
;
1281 /* Mark how big the output section must be to contain this now */
1283 output_section_statement
->bfd_section
->size
=
1284 dot
- output_section_statement
->bfd_section
->vma
;
1291 /* Work out the size of the output sections
1292 from the sizes of the input sections */
1294 DEFUN(lang_size_sections
,(s
, output_section_statement
, prev
, fill
, dot
),
1295 lang_statement_union_type
*s AND
1296 lang_output_section_statement_type
* output_section_statement AND
1297 lang_statement_union_type
**prev AND
1298 unsigned short fill AND
1301 /* Size up the sections from their constituent parts */
1302 for (; s
!= (lang_statement_union_type
*)NULL
; s
= s
->next
)
1304 switch (s
->header
.type
) {
1305 case lang_output_section_statement_enum
:
1308 lang_output_section_statement_type
*os
=
1309 &(s
->output_section_statement
);
1310 /* The start of a section */
1312 if (os
->addr_tree
== (etree_type
*)NULL
) {
1313 /* No address specified for this section, get one
1314 from the region specification
1316 if (os
->region
== (lang_memory_region_type
*)NULL
) {
1317 os
->region
= lang_memory_region_lookup("*default*");
1319 dot
= os
->region
->current
;
1322 etree_value_type r
;
1323 r
= exp_fold_tree(os
->addr_tree
,
1324 (lang_output_section_statement_type
*)NULL
,
1325 lang_allocating_phase_enum
,
1327 if (r
.valid
== false) {
1328 info("%F%S: non constant address expression for section %s\n",
1333 /* The section starts here */
1334 /* First, align to what the section needs */
1336 dot
= align_power(dot
, os
->bfd_section
->alignment_power
);
1337 os
->bfd_section
->vma
= dot
;
1338 os
->bfd_section
->output_offset
= 0;
1340 (void) lang_size_sections(os
->children
.head
, os
, &os
->children
.head
,
1342 /* Ignore the size of the input sections, use the vma and size to */
1346 after
= ALIGN(os
->bfd_section
->vma
+
1347 os
->bfd_section
->size
,
1351 os
->bfd_section
->size
= after
- os
->bfd_section
->vma
;
1352 dot
= os
->bfd_section
->vma
+ os
->bfd_section
->size
;
1353 os
->processed
= true;
1355 /* Replace into region ? */
1356 if (os
->addr_tree
== (etree_type
*)NULL
1357 && os
->region
!=(lang_memory_region_type
*)NULL
) {
1358 os
->region
->current
= dot
;
1364 case lang_data_statement_enum
:
1367 s
->data_statement
.output_vma
= dot
;
1368 s
->data_statement
.output_section
=
1369 output_section_statement
->bfd_section
;
1371 switch (s
->data_statement
.type
) {
1384 output_section_statement
->bfd_section
->size
+= size
;
1388 case lang_wild_statement_enum
:
1390 dot
= lang_size_sections(s
->wild_statement
.children
.head
,
1391 output_section_statement
,
1392 &s
->wild_statement
.children
.head
,
1398 case lang_object_symbols_statement_enum
:
1399 create_object_symbols
= output_section_statement
;
1401 case lang_output_statement_enum
:
1402 case lang_target_statement_enum
:
1404 case lang_input_section_enum
:
1405 dot
= size_input_section(prev
,
1406 output_section_statement
,
1407 output_section_statement
->fill
, dot
);
1409 case lang_input_statement_enum
:
1411 case lang_fill_statement_enum
:
1412 fill
= s
->fill_statement
.fill
;
1414 case lang_assignment_statement_enum
:
1416 bfd_vma newdot
= dot
;
1417 exp_fold_tree(s
->assignment_statement
.exp
,
1418 output_section_statement
,
1419 lang_allocating_phase_enum
,
1424 /* We've been moved ! so insert a pad */
1426 lang_statement_union_type
*new =
1427 (lang_statement_union_type
*)
1428 ldmalloc(sizeof(lang_padding_statement_type
));
1429 /* Link into existing chain */
1430 new->header
.next
= *prev
;
1432 new->header
.type
= lang_padding_statement_enum
;
1433 new->padding_statement
.output_section
=
1434 output_section_statement
->bfd_section
;
1435 new->padding_statement
.output_offset
=
1436 dot
- output_section_statement
->bfd_section
->vma
;
1437 new->padding_statement
.fill
= fill
;
1438 new->padding_statement
.size
= newdot
- dot
;
1439 output_section_statement
->bfd_section
->size
+=
1440 new->padding_statement
.size
;
1446 case lang_padding_statement_enum
:
1452 case lang_address_statement_enum
:
1455 prev
= &s
->header
.next
;
1462 DEFUN(lang_do_assignments
,(s
, output_section_statement
, fill
, dot
),
1463 lang_statement_union_type
*s AND
1464 lang_output_section_statement_type
* output_section_statement AND
1465 unsigned short fill AND
1469 for (; s
!= (lang_statement_union_type
*)NULL
; s
= s
->next
)
1471 switch (s
->header
.type
) {
1472 case lang_output_section_statement_enum
:
1474 lang_output_section_statement_type
*os
=
1475 &(s
->output_section_statement
);
1476 dot
= os
->bfd_section
->vma
;
1477 (void) lang_do_assignments(os
->children
.head
, os
, os
->fill
, dot
);
1478 dot
= os
->bfd_section
->vma
+ os
->bfd_section
->size
;
1481 case lang_wild_statement_enum
:
1483 dot
= lang_do_assignments(s
->wild_statement
.children
.head
,
1484 output_section_statement
,
1489 case lang_object_symbols_statement_enum
:
1490 case lang_output_statement_enum
:
1491 case lang_target_statement_enum
:
1493 case lang_common_statement_enum
:
1496 case lang_data_statement_enum
:
1498 etree_value_type value
;
1499 value
= exp_fold_tree(s
->data_statement
.exp
,
1500 0, lang_final_phase_enum
, dot
, &dot
);
1501 s
->data_statement
.value
= value
.value
;
1502 if (value
.valid
== false) info("%F%P: Invalid data statement\n");
1504 switch (s
->data_statement
.type
) {
1516 case lang_input_section_enum
:
1518 asection
*in
= s
->input_section
.section
;
1523 case lang_input_statement_enum
:
1525 case lang_fill_statement_enum
:
1526 fill
= s
->fill_statement
.fill
;
1528 case lang_assignment_statement_enum
:
1530 exp_fold_tree(s
->assignment_statement
.exp
,
1531 output_section_statement
,
1532 lang_final_phase_enum
,
1538 case lang_padding_statement_enum
:
1539 dot
+= s
->padding_statement
.size
;
1544 case lang_address_statement_enum
:
1555 DEFUN_VOID(lang_relocate_globals
)
1559 Each ldsym_type maintains a chain of pointers to asymbols which
1560 references the definition. Replace each pointer to the referenence
1561 with a pointer to only one place, preferably the definition. If
1562 the defintion isn't available then the common symbol, and if
1563 there isn't one of them then choose one reference.
1566 FOR_EACH_LDSYM(lgs
) {
1568 if (lgs
->sdefs_chain
) {
1569 it
= *(lgs
->sdefs_chain
);
1571 else if (lgs
->scoms_chain
!= (asymbol
**)NULL
) {
1572 it
= *(lgs
->scoms_chain
);
1574 else if (lgs
->srefs_chain
!= (asymbol
**)NULL
) {
1575 it
= *(lgs
->srefs_chain
);
1578 /* This can happen when the command line asked for a symbol to
1580 it
= (asymbol
*)NULL
;
1582 if (it
!= (asymbol
*)NULL
)
1584 asymbol
**ptr
= lgs
->srefs_chain
;
1586 while (ptr
!= (asymbol
**)NULL
) {
1587 asymbol
*ref
= *ptr
;
1589 ptr
= (asymbol
**)(ref
->udata
);
1598 DEFUN_VOID(lang_finish
)
1602 if (entry_symbol
== (char *)NULL
) {
1603 /* No entry has been specified, look for start */
1604 entry_symbol
= "start";
1606 lgs
= ldsym_get_soft(entry_symbol
);
1607 if (lgs
&& lgs
->sdefs_chain
) {
1608 asymbol
*sy
= *(lgs
->sdefs_chain
);
1609 /* We can set the entry address*/
1610 bfd_set_start_address(output_bfd
,
1611 outside_symbol_address(sy
));
1615 /* Can't find anything reasonable,
1616 use the first address in the text section
1618 asection
*ts
= bfd_get_section_by_name(output_bfd
, ".text");
1620 bfd_set_start_address(output_bfd
, ts
->vma
);
1625 /* By now we know the target architecture, and we may have an */
1626 /* ldfile_output_machine_name */
1628 DEFUN_VOID(lang_check
)
1630 lang_statement_union_type
*file
;
1633 for (file
= file_chain
.head
;
1634 file
!= (lang_statement_union_type
*)NULL
;
1635 file
=file
->input_statement
.next
)
1637 /* Inspect the architecture and ensure we're linking like
1641 if (bfd_arch_compatible( file
->input_statement
.the_bfd
,
1643 &ldfile_output_architecture
,
1644 &ldfile_output_machine
)) {
1645 bfd_set_arch_mach(output_bfd
,
1646 ldfile_output_architecture
, ldfile_output_machine
);
1649 enum bfd_architecture this_architecture
=
1650 bfd_get_architecture(file
->input_statement
.the_bfd
);
1651 unsigned long this_machine
=
1652 bfd_get_machine(file
->input_statement
.the_bfd
);
1654 info("%I: architecture %s",
1656 bfd_printable_arch_mach(this_architecture
, this_machine
));
1657 info(" incompatible with output %s\n",
1658 bfd_printable_arch_mach(ldfile_output_architecture
,
1659 ldfile_output_machine
));
1660 ldfile_output_architecture
= this_architecture
;
1661 ldfile_output_machine
= this_machine
;
1662 bfd_set_arch_mach(output_bfd
,
1663 ldfile_output_architecture
,
1664 ldfile_output_machine
);
1673 * run through all the global common symbols and tie them
1674 * to the output section requested.
1678 DEFUN_VOID(lang_common
)
1681 if (config
.relocateable_output
== false ||
1682 command_line
.force_common_definition
== true) {
1683 for (lgs
= symbol_head
;
1684 lgs
!= (ldsym_type
*)NULL
;
1688 unsigned int power_of_two
;
1691 if (lgs
->scoms_chain
!= (asymbol
**)NULL
) {
1692 com
= *(lgs
->scoms_chain
);
1723 /* Change from a common symbol into a definition of
1725 lgs
->sdefs_chain
= lgs
->scoms_chain
;
1726 lgs
->scoms_chain
= (asymbol
**)NULL
;
1728 /* Point to the correct common section */
1730 ((lang_input_statement_type
*)
1731 (com
->the_bfd
->usrdata
))->common_section
;
1732 /* Fix the size of the common section */
1733 com
->section
->size
= ALIGN(com
->section
->size
, align
);
1735 /* Remember if this is the biggest alignment ever seen */
1736 if (power_of_two
> com
->section
->alignment_power
) {
1737 com
->section
->alignment_power
= power_of_two
;
1741 com
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
1745 printf ("Allocating common %s: %x at %x\n",
1748 (unsigned) com
->section
->size
);
1750 com
->value
= com
->section
->size
;
1751 com
->section
->size
+= size
;
1761 run through the input files and ensure that every input
1762 section has somewhere to go. If one is found without
1763 a destination then create an input request and place it
1764 into the statement tree.
1768 DEFUN_VOID(lang_place_orphans
)
1770 lang_input_statement_type
*file
;
1771 for (file
= (lang_input_statement_type
*)file_chain
.head
;
1772 file
!= (lang_input_statement_type
*)NULL
;
1773 file
= (lang_input_statement_type
*)file
->next
) {
1775 for (s
= file
->the_bfd
->sections
;
1776 s
!= (asection
*)NULL
;
1778 if ( s
->output_section
== (asection
*)NULL
) {
1779 /* This section of the file is not attatched, root
1780 around for a sensible place for it to go */
1782 if (file
->common_section
== s
) {
1783 /* This is a lonely common section which must
1784 have come from an archive. We attatch to the
1785 section with the wildcard */
1786 if (config
.relocateable_output
!= true
1787 && command_line
.force_common_definition
== false) {
1788 if (default_common_section
==
1789 (lang_output_section_statement_type
*)NULL
) {
1790 info("%P: No [COMMON] command, defaulting to .bss\n");
1792 default_common_section
=
1793 lang_output_section_statement_lookup(".bss");
1796 wild_doit(&default_common_section
->children
, s
,
1797 default_common_section
, file
);
1801 lang_output_section_statement_type
*os
=
1802 lang_output_section_statement_lookup(s
->name
);
1804 wild_doit(&os
->children
, s
, os
, file
);
1813 DEFUN(lang_set_flags
,(ptr
, flags
),
1814 lang_section_flags_type
*ptr AND
1817 boolean state
= true;
1818 ptr
->flag_read
= false;
1819 ptr
->flag_write
= false;
1820 ptr
->flag_executable
= false;
1821 ptr
->flag_loadable
= false;
1824 if (*flags
== '!') {
1831 ptr
->flag_read
= state
;
1834 ptr
->flag_write
= state
;
1837 ptr
->flag_executable
= state
;
1840 ptr
->flag_loadable
= state
;
1843 info("%P%F illegal syntax in flags\n");
1853 DEFUN(lang_for_each_file
,(func
),
1854 PROTO(void, (*func
),(lang_input_statement_type
*)))
1856 lang_input_statement_type
*f
;
1857 for (f
= (lang_input_statement_type
*)file_chain
.head
;
1858 f
!= (lang_input_statement_type
*)NULL
;
1859 f
= (lang_input_statement_type
*)f
->next
)
1867 DEFUN(lang_for_each_input_section
, (func
),
1868 PROTO(void ,(*func
),(bfd
*ab
, asection
*as
)))
1870 lang_input_statement_type
*f
;
1871 for (f
= (lang_input_statement_type
*)file_chain
.head
;
1872 f
!= (lang_input_statement_type
*)NULL
;
1873 f
= (lang_input_statement_type
*)f
->next
)
1876 for (s
= f
->the_bfd
->sections
;
1877 s
!= (asection
*)NULL
;
1879 func(f
->the_bfd
, s
);
1887 DEFUN(ldlang_add_file
,(entry
),
1888 lang_input_statement_type
*entry
)
1891 lang_statement_append(&file_chain
,
1892 (lang_statement_union_type
*)entry
,
1899 DEFUN(lang_add_output
,(name
),
1902 lang_output_statement_type
*new = new_stat(lang_output_statement
,
1905 had_output_filename
= true;
1909 static lang_output_section_statement_type
*current_section
;
1912 DEFUN(lang_enter_output_section_statement
,
1913 (output_section_statement_name
,
1916 char *output_section_statement_name AND
1917 etree_type
*address_exp AND
1918 bfd_vma block_value
)
1920 lang_output_section_statement_type
*os
;
1923 lang_output_section_statement_lookup(output_section_statement_name
);
1926 /* Add this statement to tree */
1927 /* add_statement(lang_output_section_statement_enum,
1928 output_section_statement);*/
1929 /* Make next things chain into subchain of this */
1931 if (os
->addr_tree
==
1932 (etree_type
*)NULL
) {
1936 os
->block_value
= block_value
;
1937 stat_ptr
= & os
->children
;
1943 DEFUN_VOID(lang_final
)
1945 if (had_output_filename
== false) {
1946 lang_add_output("a.out");
1955 DEFUN(create_symbol
,(name
, flags
, section
),
1956 CONST
char *name AND
1960 extern lang_input_statement_type
*script_file
;
1961 asymbol
**def_ptr
= (asymbol
**)ldmalloc(sizeof(asymbol
**));
1962 /* Add this definition to script file */
1963 asymbol
*def
= (asymbol
*)bfd_make_empty_symbol(script_file
->the_bfd
);
1964 def
->name
= buystring(name
);
1967 def
->section
= section
;
1970 Q_enter_global_ref(def_ptr
);
1976 DEFUN_VOID(lang_process
)
1978 if (had_script
== false) {
1979 parse_line(ldemul_get_script());
1981 lang_reasonable_defaults();
1982 current_target
= default_target
;
1984 lang_for_each_statement(ldlang_open_output
); /* Open the output file */
1985 /* For each output section statement, create a section in the output
1987 lang_create_output_section_statements();
1989 /* Create a dummy bfd for the script */
1990 lang_init_script_file();
1992 /* Add to the hash table all undefineds on the command line */
1993 lang_place_undefineds();
1995 /* Create a bfd for each input file */
1996 current_target
= default_target
;
1997 lang_for_each_statement(open_input_bfds
);
1999 common_section
.userdata
= &common_section_userdata
;
2001 /* Run through the contours of the script and attatch input sections
2002 to the correct output sections
2004 map_input_to_output_sections(statement_list
.head
, (char *)NULL
,
2005 ( lang_output_section_statement_type
*)NULL
);
2007 /* Find any sections not attatched explicitly and handle them */
2008 lang_place_orphans();
2010 /* Size up the common data */
2013 ldemul_before_allocation();
2015 /* Size up the sections */
2016 lang_size_sections(statement_list
.head
,
2017 (lang_output_section_statement_type
*)NULL
,
2018 &(statement_list
.head
), 0, (bfd_vma
)0);
2020 /* See if anything special should be done now we know how big
2022 ldemul_after_allocation();
2024 /* Do all the assignments, now that we know the final restingplaces
2025 of all the symbols */
2027 lang_do_assignments(statement_list
.head
,
2028 (lang_output_section_statement_type
*)NULL
,
2031 /* Make sure that we're not mixing architectures */
2035 /* Move the global symbols around */
2036 lang_relocate_globals();
2043 /* EXPORTED TO YACC */
2046 DEFUN(lang_add_wild
,(section_name
, filename
),
2047 CONST
char *CONST section_name AND
2048 CONST
char *CONST filename
)
2050 lang_wild_statement_type
*new = new_stat(lang_wild_statement
,
2053 if (section_name
!= (char *)NULL
&& strcmp(section_name
,"COMMON") == 0)
2055 placed_commons
= true;
2057 if (filename
!= (char *)NULL
) {
2058 lang_has_input_file
= true;
2060 new->section_name
= section_name
;
2061 new->filename
= filename
;
2062 lang_list_init(&new->children
);
2065 DEFUN(lang_section_start
,(name
, address
),
2066 CONST
char *name AND
2067 etree_type
*address
)
2069 lang_address_statement_type
*ad
=new_stat(lang_address_statement
, stat_ptr
);
2070 ad
->section_name
= name
;
2071 ad
->address
= address
;
2075 DEFUN(lang_add_entry
,(name
),
2078 entry_symbol
= name
;
2082 DEFUN(lang_add_target
,(name
),
2085 lang_target_statement_type
*new = new_stat(lang_target_statement
,
2095 DEFUN(lang_add_map
,(name
),
2101 map_option_f
= true;
2109 DEFUN(lang_add_fill
,(exp
),
2112 lang_fill_statement_type
*new = new_stat(lang_fill_statement
,
2118 DEFUN(lang_add_data
,(type
, exp
),
2120 union etree_union
*exp
)
2123 lang_data_statement_type
*new = new_stat(lang_data_statement
,
2130 DEFUN(lang_add_assignment
,(exp
),
2133 lang_assignment_statement_type
*new = new_stat(lang_assignment_statement
,
2139 DEFUN(lang_add_attribute
,(attribute
),
2140 enum statement_enum attribute
)
2142 new_statement(attribute
, sizeof(lang_statement_union_type
),stat_ptr
);
2148 DEFUN(lang_startup
,(name
),
2151 if (startup_file
!= (char *)NULL
) {
2152 info("%P%FMultiple STARTUP files\n");
2154 first_file
->filename
= name
;
2155 first_file
->local_sym_name
= name
;
2160 DEFUN(lang_float
,(maybe
),
2163 lang_float_flag
= maybe
;
2167 DEFUN(lang_leave_output_section_statement
,(fill
, memspec
),
2169 CONST
char *memspec
)
2171 current_section
->fill
= fill
;
2172 current_section
->region
= lang_memory_region_lookup(memspec
);
2173 stat_ptr
= &statement_list
;
2176 Create an absolute symbol with the given name with the value of the
2177 address of first byte of the section named.
2179 If the symbol already exists, then do nothing.
2182 DEFUN(lang_abs_symbol_at_beginning_of
,(section
, name
),
2183 CONST
char *section AND
2186 if (ldsym_undefined(name
)) {
2187 extern bfd
*output_bfd
;
2188 extern asymbol
*create_symbol();
2189 asection
*s
= bfd_get_section_by_name(output_bfd
, section
);
2190 asymbol
*def
= create_symbol(name
,
2191 BSF_GLOBAL
| BSF_EXPORT
|
2194 if (s
!= (asection
*)NULL
) {
2195 def
->value
= s
->vma
;
2204 Create an absolute symbol with the given name with the value of the
2205 address of the first byte after the end of the section named.
2207 If the symbol already exists, then do nothing.
2210 DEFUN(lang_abs_symbol_at_end_of
,(section
, name
),
2211 CONST
char *section AND
2214 if (ldsym_undefined(name
)){
2215 extern bfd
*output_bfd
;
2216 extern asymbol
*create_symbol();
2217 asection
*s
= bfd_get_section_by_name(output_bfd
, section
);
2218 /* Add a symbol called _end */
2219 asymbol
*def
= create_symbol(name
,
2220 BSF_GLOBAL
| BSF_EXPORT
|
2223 if (s
!= (asection
*)NULL
) {
2224 def
->value
= s
->vma
+ s
->size
;
2233 DEFUN(lang_statement_append
,(list
, element
, field
),
2234 lang_statement_list_type
*list AND
2235 lang_statement_union_type
*element AND
2236 lang_statement_union_type
**field
)
2238 *(list
->tail
) = element
;