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
;
107 static CONST
char *current_target
;
108 static CONST
char *output_target
;
109 size_t longest_section_name
= 8;
112 lang_input_statement_type
*script_file
;
114 section_userdata_type common_section_userdata
;
115 asection common_section
;
118 #define cat(a,b) a##b
120 #define cat(a,b) a/**/b
123 #define new_stat(x,y) (cat(x,_type)*) new_statement(cat(x,_enum), sizeof(cat(x,_type)),y)
125 #define outside_section_address(q) ( (q)->output_offset + (q)->output_section->vma)
127 #define outside_symbol_address(q) ((q)->value + outside_section_address(q->section))
129 boolean option_longmap
= false;
131 /*----------------------------------------------------------------------
132 lang_for_each_statement walks the parse tree and calls the provided
133 function for each node
137 DEFUN(lang_for_each_statement_worker
,(func
, s
),
139 lang_statement_union_type
*s
)
141 for (; s
!= (lang_statement_union_type
*)NULL
; s
= s
->next
)
145 switch (s
->header
.type
) {
146 case lang_output_section_statement_enum
:
147 lang_for_each_statement_worker
149 s
->output_section_statement
.children
.head
);
151 case lang_wild_statement_enum
:
152 lang_for_each_statement_worker
154 s
->wild_statement
.children
.head
);
156 case lang_data_statement_enum
:
157 case lang_object_symbols_statement_enum
:
158 case lang_output_statement_enum
:
159 case lang_target_statement_enum
:
160 case lang_input_section_enum
:
161 case lang_input_statement_enum
:
162 case lang_fill_statement_enum
:
163 case lang_assignment_statement_enum
:
164 case lang_padding_statement_enum
:
165 case lang_address_statement_enum
:
175 DEFUN(lang_for_each_statement
,(func
),
178 lang_for_each_statement_worker(func
,
179 statement_list
.head
);
181 /*----------------------------------------------------------------------*/
183 DEFUN(lang_list_init
,(list
),
184 lang_statement_list_type
*list
)
186 list
->head
= (lang_statement_union_type
*)NULL
;
187 list
->tail
= &list
->head
;
190 /*----------------------------------------------------------------------
191 Functions to print the link map
195 DEFUN(print_section
,(name
),
196 CONST
char *CONST name
)
198 printf("%*s", -longest_section_name
, name
);
201 DEFUN_VOID(print_space
)
211 DEFUN(print_address
,(value
),
214 printf("%8lx", value
);
217 DEFUN(print_size
,(value
),
220 printf("%5x", (unsigned)value
);
223 DEFUN(print_alignment
,(value
),
226 printf("2**%2u",value
);
230 DEFUN(print_fill
,(value
),
233 printf("%04x",(unsigned)value
);
236 /*----------------------------------------------------------------------
238 build a new statement node for the parse tree
243 lang_statement_union_type
*
244 DEFUN(new_statement
,(type
, size
, list
),
245 enum statement_enum type AND
247 lang_statement_list_type
*list
)
249 lang_statement_union_type
*new = (lang_statement_union_type
*)
251 new->header
.type
= type
;
252 new->header
.next
= (lang_statement_union_type
*)NULL
;
253 lang_statement_append(list
, new, &new->header
.next
);
258 Build a new input file node for the language. There are several ways
259 in which we treat an input file, eg, we only look at symbols, or
260 prefix it with a -l etc.
262 We can be supplied with requests for input files more than once;
263 they may, for example be split over serveral lines like foo.o(.text)
264 foo.o(.data) etc, so when asked for a file we check that we havn't
265 got it already so we don't duplicate the bfd.
268 static lang_input_statement_type
*
269 DEFUN(new_afile
, (name
, file_type
, target
),
270 CONST
char *CONST name AND
271 CONST lang_input_file_enum_type file_type AND
272 CONST
char *CONST target
)
274 lang_input_statement_type
*p
= new_stat(lang_input_statement
,
276 lang_has_input_file
= true;
279 case lang_input_file_is_symbols_only_enum
:
281 p
->is_archive
=false;
283 p
->local_sym_name
= name
;
284 p
->just_syms_flag
= true;
285 p
->search_dirs_flag
= false;
287 case lang_input_file_is_fake_enum
:
289 p
->is_archive
=false;
291 p
->local_sym_name
= name
;
292 p
->just_syms_flag
= false;
293 p
->search_dirs_flag
=false;
295 case lang_input_file_is_l_enum
:
296 p
->is_archive
= true;
299 p
->local_sym_name
= concat("-l",name
,"");
300 p
->just_syms_flag
= false;
301 p
->search_dirs_flag
= true;
303 case lang_input_file_is_search_file_enum
:
304 case lang_input_file_is_marker_enum
:
306 p
->is_archive
=false;
308 p
->local_sym_name
= name
;
309 p
->just_syms_flag
= false;
310 p
->search_dirs_flag
=true;
312 case lang_input_file_is_file_enum
:
314 p
->is_archive
=false;
316 p
->local_sym_name
= name
;
317 p
->just_syms_flag
= false;
318 p
->search_dirs_flag
=false;
323 p
->asymbols
= (asymbol
**)NULL
;
324 p
->superfile
= (lang_input_statement_type
*)NULL
;
325 p
->next_real_file
= (lang_statement_union_type
*)NULL
;
326 p
->next
= (lang_statement_union_type
*)NULL
;
328 p
->common_output_section
= (asection
*)NULL
;
329 lang_statement_append(&input_file_chain
,
330 (lang_statement_union_type
*)p
,
337 lang_input_statement_type
*
338 DEFUN(lang_add_input_file
,(name
, file_type
, target
),
340 lang_input_file_enum_type file_type AND
343 /* Look it up or build a new one */
344 lang_has_input_file
= true;
346 lang_input_statement_type
*p
;
348 for (p
= (lang_input_statement_type
*)input_file_chain
.head
;
349 p
!= (lang_input_statement_type
*)NULL
;
350 p
= (lang_input_statement_type
*)(p
->next_real_file
))
352 /* Sometimes we have incomplete entries in here */
353 if (p
->filename
!= (char *)NULL
) {
354 if(strcmp(name
,p
->filename
) == 0) return p
;
359 return new_afile(name
, file_type
, target
);
363 /* Build enough state so that the parser can build its tree */
365 DEFUN_VOID(lang_init
)
368 stat_ptr
= &statement_list
;
369 lang_list_init(stat_ptr
);
371 lang_list_init(&input_file_chain
);
372 lang_list_init(&lang_output_section_statement
);
373 lang_list_init(&file_chain
);
374 first_file
= lang_add_input_file((char *)NULL
,
375 lang_input_file_is_marker_enum
,
380 /*----------------------------------------------------------------------
381 A region is an area of memory declared with the
382 MEMORY { name:org=exp, len=exp ... }
385 We maintain a list of all the regions here
387 If no regions are specified in the script, then the default is used
388 which is created when looked up to be the entire data space
391 static lang_memory_region_type
*lang_memory_region_list
;
392 static lang_memory_region_type
**lang_memory_region_list_tail
= &lang_memory_region_list
;
394 lang_memory_region_type
*
395 DEFUN(lang_memory_region_lookup
,(name
),
396 CONST
char *CONST name
)
399 lang_memory_region_type
*p
= lang_memory_region_list
;
400 for (p
= lang_memory_region_list
;
401 p
!= ( lang_memory_region_type
*)NULL
;
403 if (strcmp(p
->name
, name
) == 0) {
407 if (strcmp(name
,"*default*")==0) {
408 /* This is the default region, dig out first one on the list */
409 if (lang_memory_region_list
!= (lang_memory_region_type
*)NULL
){
410 return lang_memory_region_list
;
414 lang_memory_region_type
*new =
415 (lang_memory_region_type
*)ldmalloc(sizeof(lang_memory_region_type
));
416 new->name
= buystring(name
);
417 new->next
= (lang_memory_region_type
*)NULL
;
419 *lang_memory_region_list_tail
= new;
420 lang_memory_region_list_tail
= &new->next
;
429 lang_output_section_statement_type
*
430 DEFUN(lang_output_section_find
,(name
),
431 CONST
char * CONST name
)
433 lang_statement_union_type
*u
;
434 lang_output_section_statement_type
*lookup
;
436 for (u
= lang_output_section_statement
.head
;
437 u
!= (lang_statement_union_type
*)NULL
;
440 lookup
= &u
->output_section_statement
;
441 if (strcmp(name
, lookup
->name
)==0) {
445 return (lang_output_section_statement_type
*)NULL
;
448 lang_output_section_statement_type
*
449 DEFUN(lang_output_section_statement_lookup
,(name
),
450 CONST
char * CONST name
)
452 lang_output_section_statement_type
*lookup
;
453 lookup
=lang_output_section_find(name
);
454 if (lookup
== (lang_output_section_statement_type
*)NULL
) {
456 lookup
=(lang_output_section_statement_type
*)
457 new_stat(lang_output_section_statement
, stat_ptr
);
458 lookup
->region
= (lang_memory_region_type
*)NULL
;
460 lookup
->block_value
= 1;
463 lookup
->next
= (lang_statement_union_type
*)NULL
;
464 lookup
->bfd_section
= (asection
*)NULL
;
465 lookup
->processed
= false;
466 lookup
->addr_tree
= (etree_type
*)NULL
;
467 lang_list_init(&lookup
->children
);
469 lang_statement_append(&lang_output_section_statement
,
470 (lang_statement_union_type
*)lookup
,
481 DEFUN(print_flags
, (outfile
, ignore_flags
),
483 lang_section_flags_type
*ignore_flags
)
485 fprintf(outfile
,"(");
487 if (flags
->flag_read
) fprintf(outfile
,"R");
488 if (flags
->flag_write
) fprintf(outfile
,"W");
489 if (flags
->flag_executable
) fprintf(outfile
,"X");
490 if (flags
->flag_loadable
) fprintf(outfile
,"L");
492 fprintf(outfile
,")");
496 DEFUN(lang_map
,(outfile
),
499 lang_memory_region_type
*m
;
500 fprintf(outfile
,"**MEMORY CONFIGURATION**\n\n");
502 fprintf(outfile
,"name\t\torigin\t\tlength\t\tattributes\n");
503 for (m
= lang_memory_region_list
;
504 m
!= (lang_memory_region_type
*)NULL
;
507 fprintf(outfile
,"%-16s", m
->name
);
509 fprintf(outfile
,"%08lx\t%08lx\t", m
->origin
, m
->length
);
510 print_flags(outfile
, &m
->flags
);
511 fprintf(outfile
,"\n");
513 fprintf(outfile
,"\n\n**LINK EDITOR MEMORY MAP**\n\n");
514 fprintf(outfile
,"output\t\tinput\t\tvirtual\n");
515 fprintf(outfile
,"section\t\tsection\t\taddress\tsize\n\n");
526 lang_output_section_statement_type
*s
)
528 section_userdata_type
*new =
529 (section_userdata_type
*)
530 ldmalloc(sizeof(section_userdata_type
));
532 s
->bfd_section
= bfd_make_section(output_bfd
, s
->name
);
533 s
->bfd_section
->output_section
= s
->bfd_section
;
534 s
->bfd_section
->flags
= SEC_NO_FLAGS
;
535 /* We initialize an output sections output offset to minus its own */
536 /* vma to allow us to output a section through itself */
537 s
->bfd_section
->output_offset
= 0;
538 get_userdata( s
->bfd_section
) = new;
541 /***********************************************************************
544 These expand statements like *(.text) and foo.o to a list of
545 explicit actions, like foo.o(.text), bar.o(.text) and
548 The toplevel routine, wild, takes a statement, section, file and
549 target. If either the section or file is null it is taken to be the
550 wildcard. Seperate lang_input_section statements are created for
551 each part of the expanstion, and placed after the statement provided.
556 DEFUN(wild_doit
,(ptr
, section
, output
, file
),
557 lang_statement_list_type
*ptr AND
558 asection
*section AND
559 lang_output_section_statement_type
*output AND
560 lang_input_statement_type
*file
)
562 if(output
->bfd_section
== (asection
*)NULL
)
567 if (section
!= (asection
*)NULL
568 && section
->output_section
== (asection
*)NULL
) {
569 /* Add a section reference to the list */
570 lang_input_section_type
*new = new_stat(lang_input_section
, ptr
);
572 new->section
= section
;
574 section
->output_section
= output
->bfd_section
;
575 section
->output_section
->flags
|= section
->flags
;
576 if (section
->alignment_power
> output
->bfd_section
->alignment_power
) {
577 output
->bfd_section
->alignment_power
= section
->alignment_power
;
583 DEFUN(our_bfd_get_section_by_name
,(abfd
, section
),
587 return bfd_get_section_by_name(abfd
, section
);
591 DEFUN(wild_section
,(ptr
, section
, file
, output
),
592 lang_wild_statement_type
*ptr AND
593 CONST
char *section AND
594 lang_input_statement_type
*file AND
595 lang_output_section_statement_type
*output
)
598 if (file
->just_syms_flag
== false) {
599 if (section
== (char *)NULL
) {
600 /* Do the creation to all sections in the file */
601 for (s
= file
->the_bfd
->sections
; s
!= (asection
*)NULL
; s
=s
->next
) {
602 wild_doit(&ptr
->children
, s
, output
, file
);
606 /* Do the creation to the named section only */
607 wild_doit(&ptr
->children
,
608 our_bfd_get_section_by_name(file
->the_bfd
, section
),
615 /* passed a file name (which must have been seen already and added to
616 the statement tree. We will see if it has been opened already and
617 had its symbols read. If not then we'll read it.
619 Archives are pecuilar here. We may open them once, but if they do
620 not define anything we need at the time, they won't have all their
621 symbols read. If we need them later, we'll have to redo it.
624 lang_input_statement_type
*
625 DEFUN(lookup_name
,(name
),
626 CONST
char * CONST name
)
628 lang_input_statement_type
*search
;
629 for(search
= (lang_input_statement_type
*)input_file_chain
.head
;
630 search
!= (lang_input_statement_type
*)NULL
;
631 search
= (lang_input_statement_type
*)search
->next_real_file
)
633 if (search
->filename
== (char *)NULL
&& name
== (char *)NULL
) {
636 if (search
->filename
!= (char *)NULL
&& name
!= (char *)NULL
) {
637 if (strcmp(search
->filename
, name
) == 0) {
638 ldmain_open_file_read_symbol(search
);
644 /* There isn't an afile entry for this file yet, this must be
645 because the name has only appeared inside a load script and not
646 on the command line */
647 search
= new_afile(name
, lang_input_file_is_file_enum
, default_target
);
648 ldmain_open_file_read_symbol(search
);
655 DEFUN(wild
,(s
, section
, file
, target
, output
),
656 lang_wild_statement_type
*s AND
657 CONST
char *CONST section AND
658 CONST
char *CONST file AND
659 CONST
char *CONST target AND
660 lang_output_section_statement_type
*output
)
662 lang_input_statement_type
*f
;
663 if (file
== (char *)NULL
) {
664 /* Perform the iteration over all files in the list */
665 for (f
= (lang_input_statement_type
*)file_chain
.head
;
666 f
!= (lang_input_statement_type
*)NULL
;
667 f
= (lang_input_statement_type
*)f
->next
) {
668 wild_section(s
, section
, f
, output
);
672 /* Perform the iteration over a single file */
673 wild_section( s
, section
, lookup_name(file
), output
);
675 if (strcmp(section
,"COMMON") == 0
676 && default_common_section
== (lang_output_section_statement_type
*)NULL
)
678 /* Remember the section that common is going to incase we later
679 get something which doesn't know where to put it */
680 default_common_section
= output
;
685 read in all the files
688 DEFUN(open_output
,(name
),
689 CONST
char *CONST name
)
691 extern CONST
char *output_filename
;
693 if (output_target
== (char *)NULL
) {
694 if (current_target
!= (char *)NULL
)
695 output_target
= current_target
;
697 output_target
= default_target
;
699 output
= bfd_openw(name
, output_target
);
700 output_filename
= name
;
702 if (output
== (bfd
*)NULL
)
704 if (bfd_error
== invalid_target
) {
705 info("%P%F target %s not found\n", output_target
);
707 info("%P%F problem opening output file %s, %E", name
);
710 output
->flags
|= D_PAGED
;
711 bfd_set_format(output
, bfd_object
);
719 DEFUN(ldlang_open_output
,(statement
),
720 lang_statement_union_type
*statement
)
722 switch (statement
->header
.type
)
724 case lang_output_statement_enum
:
725 output_bfd
= open_output(statement
->output_statement
.name
);
726 ldemul_set_output_arch();
729 case lang_target_statement_enum
:
730 current_target
= statement
->target_statement
.target
;
738 DEFUN(open_input_bfds
,(statement
),
739 lang_statement_union_type
*statement
)
741 switch (statement
->header
.type
)
743 case lang_target_statement_enum
:
744 current_target
= statement
->target_statement
.target
;
746 case lang_wild_statement_enum
:
747 /* Maybe we should load the file's symbols */
748 if (statement
->wild_statement
.filename
)
750 (void) lookup_name(statement
->wild_statement
.filename
);
753 case lang_input_statement_enum
:
754 if (statement
->input_statement
.real
== true)
756 statement
->input_statement
.target
= current_target
;
757 lookup_name(statement
->input_statement
.filename
);
764 /* If there are [COMMONS] statements, put a wild one into the bss section */
767 lang_reasonable_defaults()
770 lang_output_section_statement_lookup(".text");
771 lang_output_section_statement_lookup(".data");
773 default_common_section
=
774 lang_output_section_statement_lookup(".bss");
777 if (placed_commons
== false) {
778 lang_wild_statement_type
*new =
779 new_stat(lang_wild_statement
,
780 &default_common_section
->children
);
781 new->section_name
= "COMMON";
782 new->filename
= (char *)NULL
;
783 lang_list_init(&new->children
);
790 Add the supplied name to the symbol table as an undefined reference.
791 Remove items from the chain as we open input bfds
793 typedef struct ldlang_undef_chain_list_struct
{
794 struct ldlang_undef_chain_list_struct
*next
;
796 } ldlang_undef_chain_list_type
;
798 static ldlang_undef_chain_list_type
*ldlang_undef_chain_list_head
;
801 DEFUN(ldlang_add_undef
,(name
),
802 CONST
char *CONST name
)
804 ldlang_undef_chain_list_type
*new =
805 (ldlang_undef_chain_list_type
806 *)ldmalloc(sizeof(ldlang_undef_chain_list_type
));
808 new->next
= ldlang_undef_chain_list_head
;
809 ldlang_undef_chain_list_head
= new;
811 new->name
= buystring(name
);
813 /* Run through the list of undefineds created above and place them
814 into the linker hash table as undefined symbols belonging to the
818 DEFUN_VOID(lang_place_undefineds
)
820 ldlang_undef_chain_list_type
*ptr
= ldlang_undef_chain_list_head
;
821 while (ptr
!= (ldlang_undef_chain_list_type
*)NULL
) {
822 ldsym_type
*sy
= ldsym_get(ptr
->name
);
824 asymbol
**def_ptr
= (asymbol
**)ldmalloc(sizeof(asymbol
**));
825 def
= (asymbol
*)bfd_make_empty_symbol(script_file
->the_bfd
);
827 def
->name
= ptr
->name
;
828 def
->flags
= BSF_UNDEFINED
;
829 def
->section
= (asection
*)NULL
;
830 Q_enter_global_ref(def_ptr
);
837 /* Copy important data from out internal form to the bfd way. Also
838 create a section for the dummy file
842 DEFUN_VOID(lang_create_output_section_statements
)
844 lang_statement_union_type
*os
;
845 for (os
= lang_output_section_statement
.head
;
846 os
!= (lang_statement_union_type
*)NULL
;
847 os
= os
->output_section_statement
.next
) {
848 lang_output_section_statement_type
*s
=
849 &os
->output_section_statement
;
856 DEFUN_VOID(lang_init_script_file
)
858 script_file
= lang_add_input_file("script file",
859 lang_input_file_is_fake_enum
,
861 script_file
->the_bfd
= bfd_create("script file", output_bfd
);
862 script_file
->symbol_count
= 0;
863 script_file
->the_bfd
->sections
= output_bfd
->sections
;
869 /* Open input files and attatch to output sections */
871 DEFUN(map_input_to_output_sections
,(s
, target
, output_section_statement
),
872 lang_statement_union_type
*s AND
873 CONST
char *target AND
874 lang_output_section_statement_type
*output_section_statement
)
876 for (; s
!= (lang_statement_union_type
*)NULL
; s
= s
->next
)
878 switch (s
->header
.type
) {
879 case lang_wild_statement_enum
:
880 wild(&s
->wild_statement
, s
->wild_statement
.section_name
,
881 s
->wild_statement
.filename
, target
,
882 output_section_statement
);
886 case lang_output_section_statement_enum
:
887 map_input_to_output_sections(s
->output_section_statement
.children
.head
,
889 &s
->output_section_statement
);
891 case lang_output_statement_enum
:
893 case lang_target_statement_enum
:
894 target
= s
->target_statement
.target
;
896 case lang_fill_statement_enum
:
897 case lang_input_section_enum
:
898 case lang_object_symbols_statement_enum
:
899 case lang_data_statement_enum
:
900 case lang_assignment_statement_enum
:
901 case lang_padding_statement_enum
:
903 case lang_afile_asection_pair_statement_enum
:
906 case lang_address_statement_enum
:
907 /* Mark the specified section with the supplied address */
909 lang_output_section_statement_type
*os
=
910 lang_output_section_statement_lookup
911 (s
->address_statement
.section_name
);
912 os
->addr_tree
= s
->address_statement
.address
;
915 case lang_input_statement_enum
:
916 /* A standard input statement, has no wildcards */
917 /* ldmain_open_file_read_symbol(&s->input_statement);*/
928 DEFUN(print_output_section_statement
,(output_section_statement
),
929 lang_output_section_statement_type
*output_section_statement
)
931 asection
*section
= output_section_statement
->bfd_section
;
933 print_section(output_section_statement
->name
);
936 print_dot
= section
->vma
;
940 print_address(section
->vma
);
942 print_size(section
->size
);
944 print_alignment(section
->alignment_power
);
947 printf("%s flags", output_section_statement
->region
->name
);
948 print_flags(stdout
, &output_section_statement
->flags
);
953 printf("No attached output section");
956 print_statement(output_section_statement
->children
.head
,
957 output_section_statement
);
962 DEFUN(print_assignment
,(assignment
, output_section
),
963 lang_assignment_statement_type
*assignment AND
964 lang_output_section_statement_type
*output_section
)
966 etree_value_type result
;
971 print_address(print_dot
);
973 result
= exp_fold_tree(assignment
->exp
->assign
.src
,
975 lang_final_phase_enum
,
980 print_address(result
.value
);
984 printf("*undefined*");
987 exp_print_tree(stdout
, assignment
->exp
);
992 DEFUN(print_input_statement
,(statm
),
993 lang_input_statement_type
*statm
)
995 if (statm
->filename
!= (char *)NULL
) {
996 printf("LOAD %s\n",statm
->filename
);
1001 DEFUN(print_symbol
,(q
),
1008 print_address(outside_symbol_address(q
));
1009 printf(" %s", q
->name
? q
->name
: " ");
1014 DEFUN(print_input_section
,(in
),
1015 lang_input_section_type
*in
)
1017 asection
*i
= in
->section
;
1022 print_section(i
->name
);
1024 if (i
->output_section
) {
1025 print_address(i
->output_section
->vma
+ i
->output_offset
);
1027 print_size(i
->size
);
1029 print_alignment(i
->alignment_power
);
1033 bfd
*abfd
= in
->ifile
->the_bfd
;
1034 if (in
->ifile
->just_syms_flag
== true) {
1035 printf("symbols only ");
1038 printf(" %s ",abfd
->xvec
->name
);
1039 if(abfd
->my_archive
!= (bfd
*)NULL
) {
1040 printf("[%s]%s", abfd
->my_archive
->filename
,
1044 printf("%s", abfd
->filename
);
1048 /* Find all the symbols in this file defined in this section */
1051 for (p
= in
->ifile
->asymbols
; *p
; p
++) {
1054 if (bfd_get_section(q
) == i
&& q
->flags
& BSF_GLOBAL
) {
1065 print_dot
= outside_section_address(i
) + i
->size
;
1068 printf("No output section allocated\n");
1074 DEFUN(print_fill_statement
,(fill
),
1075 lang_fill_statement_type
*fill
)
1077 printf("FILL mask ");
1078 print_fill( fill
->fill
);
1082 DEFUN(print_data_statement
,(data
),
1083 lang_data_statement_type
*data
)
1085 /* bfd_vma value; */
1090 ASSERT(print_dot
== data
->output_vma
);
1092 print_address(data
->output_vma
);
1094 print_address(data
->value
);
1096 switch (data
->type
) {
1099 print_dot
+= BYTE_SIZE
;
1103 print_dot
+= SHORT_SIZE
;
1107 print_dot
+= LONG_SIZE
;
1111 exp_print_tree(stdout
, data
->exp
);
1118 DEFUN(print_padding_statement
,(s
),
1119 lang_padding_statement_type
*s
)
1123 print_section("*fill*");
1125 print_address(s
->output_offset
+ s
->output_section
->vma
);
1127 print_size(s
->size
);
1129 print_fill(s
->fill
);
1134 DEFUN(print_wild_statement
,(w
,os
),
1135 lang_wild_statement_type
*w AND
1136 lang_output_section_statement_type
*os
)
1138 if (w
->filename
!= (char *)NULL
) {
1139 printf("%s",w
->filename
);
1144 if (w
->section_name
!= (char *)NULL
) {
1145 printf("(%s)",w
->section_name
);
1151 print_statement(w
->children
.head
, os
);
1155 DEFUN(print_statement
,(s
, os
),
1156 lang_statement_union_type
*s AND
1157 lang_output_section_statement_type
*os
)
1160 switch (s
->header
.type
) {
1161 case lang_wild_statement_enum
:
1162 print_wild_statement(&s
->wild_statement
, os
);
1165 printf("Fail with %d\n",s
->header
.type
);
1168 case lang_address_statement_enum
:
1169 printf("address\n");
1172 case lang_object_symbols_statement_enum
:
1173 printf("object symbols\n");
1175 case lang_fill_statement_enum
:
1176 print_fill_statement(&s
->fill_statement
);
1178 case lang_data_statement_enum
:
1179 print_data_statement(&s
->data_statement
);
1181 case lang_input_section_enum
:
1182 print_input_section(&s
->input_section
);
1184 case lang_padding_statement_enum
:
1185 print_padding_statement(&s
->padding_statement
);
1187 case lang_output_section_statement_enum
:
1188 print_output_section_statement(&s
->output_section_statement
);
1190 case lang_assignment_statement_enum
:
1191 print_assignment(&s
->assignment_statement
,
1196 case lang_target_statement_enum
:
1197 printf("TARGET(%s)\n", s
->target_statement
.target
);
1199 case lang_output_statement_enum
:
1200 printf("OUTPUT(%s %s)\n",
1201 s
->output_statement
.name
,
1204 case lang_input_statement_enum
:
1205 print_input_statement(&s
->input_statement
);
1207 case lang_afile_asection_pair_statement_enum
:
1217 DEFUN_VOID(print_statements
)
1219 print_statement(statement_list
.head
,
1220 (lang_output_section_statement_type
*)NULL
);
1224 DEFUN(insert_pad
,(this_ptr
, fill
, power
, output_section_statement
, dot
),
1225 lang_statement_union_type
**this_ptr AND
1227 unsigned int power AND
1228 asection
* output_section_statement AND
1231 /* Align this section first to the
1232 input sections requirement, then
1233 to the output section's requirement.
1234 If this alignment is > than any seen before,
1235 then record it too. Perform the alignment by
1236 inserting a magic 'padding' statement.
1239 unsigned int alignment_needed
= align_power(dot
, power
) - dot
;
1241 if (alignment_needed
!= 0)
1243 lang_statement_union_type
*new =
1244 (lang_statement_union_type
*)
1245 ldmalloc(sizeof(lang_padding_statement_type
));
1246 /* Link into existing chain */
1247 new->header
.next
= *this_ptr
;
1249 new->header
.type
= lang_padding_statement_enum
;
1250 new->padding_statement
.output_section
= output_section_statement
;
1251 new->padding_statement
.output_offset
=
1252 dot
- output_section_statement
->vma
;
1253 new->padding_statement
.fill
= fill
;
1254 new->padding_statement
.size
= alignment_needed
;
1258 /* Remember the most restrictive alignment */
1259 if (power
> output_section_statement
->alignment_power
) {
1260 output_section_statement
->alignment_power
= power
;
1262 output_section_statement
->size
+= alignment_needed
;
1263 return alignment_needed
+ dot
;
1267 /* Work out how much this section will move the dot point */
1269 DEFUN(size_input_section
, (this_ptr
, output_section_statement
, fill
, dot
),
1270 lang_statement_union_type
**this_ptr AND
1271 lang_output_section_statement_type
*output_section_statement AND
1272 unsigned short fill AND
1275 lang_input_section_type
*is
= &((*this_ptr
)->input_section
);
1276 asection
*i
= is
->section
;
1278 if (is
->ifile
->just_syms_flag
== false) {
1279 dot
= insert_pad(this_ptr
, fill
, i
->alignment_power
,
1280 output_section_statement
->bfd_section
, dot
);
1282 /* remember the largest size so we can malloc the largest area */
1283 /* needed for the output stage */
1284 if (i
->size
> largest_section
) {
1285 largest_section
= i
->size
;
1288 /* Remember where in the output section this input section goes */
1289 i
->output_offset
= dot
- output_section_statement
->bfd_section
->vma
;
1291 /* Mark how big the output section must be to contain this now */
1293 output_section_statement
->bfd_section
->size
=
1294 dot
- output_section_statement
->bfd_section
->vma
;
1301 /* Work out the size of the output sections
1302 from the sizes of the input sections */
1304 DEFUN(lang_size_sections
,(s
, output_section_statement
, prev
, fill
, dot
),
1305 lang_statement_union_type
*s AND
1306 lang_output_section_statement_type
* output_section_statement AND
1307 lang_statement_union_type
**prev AND
1308 unsigned short fill AND
1311 /* Size up the sections from their constituent parts */
1312 for (; s
!= (lang_statement_union_type
*)NULL
; s
= s
->next
)
1314 switch (s
->header
.type
) {
1315 case lang_output_section_statement_enum
:
1318 lang_output_section_statement_type
*os
=
1319 &(s
->output_section_statement
);
1320 /* The start of a section */
1322 if (os
->addr_tree
== (etree_type
*)NULL
) {
1323 /* No address specified for this section, get one
1324 from the region specification
1326 if (os
->region
== (lang_memory_region_type
*)NULL
) {
1327 os
->region
= lang_memory_region_lookup("*default*");
1329 dot
= os
->region
->current
;
1332 etree_value_type r
;
1333 r
= exp_fold_tree(os
->addr_tree
,
1334 (lang_output_section_statement_type
*)NULL
,
1335 lang_allocating_phase_enum
,
1337 if (r
.valid
== false) {
1338 info("%F%S: non constant address expression for section %s\n",
1343 /* The section starts here */
1344 /* First, align to what the section needs */
1346 dot
= align_power(dot
, os
->bfd_section
->alignment_power
);
1347 os
->bfd_section
->vma
= dot
;
1348 os
->bfd_section
->output_offset
= 0;
1350 (void) lang_size_sections(os
->children
.head
, os
, &os
->children
.head
,
1352 /* Ignore the size of the input sections, use the vma and size to */
1356 after
= ALIGN(os
->bfd_section
->vma
+
1357 os
->bfd_section
->size
,
1361 os
->bfd_section
->size
= after
- os
->bfd_section
->vma
;
1362 dot
= os
->bfd_section
->vma
+ os
->bfd_section
->size
;
1363 os
->processed
= true;
1365 /* Replace into region ? */
1366 if (os
->addr_tree
== (etree_type
*)NULL
1367 && os
->region
!=(lang_memory_region_type
*)NULL
) {
1368 os
->region
->current
= dot
;
1374 case lang_data_statement_enum
:
1377 s
->data_statement
.output_vma
= dot
;
1378 s
->data_statement
.output_section
=
1379 output_section_statement
->bfd_section
;
1381 switch (s
->data_statement
.type
) {
1394 output_section_statement
->bfd_section
->size
+= size
;
1398 case lang_wild_statement_enum
:
1400 dot
= lang_size_sections(s
->wild_statement
.children
.head
,
1401 output_section_statement
,
1402 &s
->wild_statement
.children
.head
,
1408 case lang_object_symbols_statement_enum
:
1409 create_object_symbols
= output_section_statement
;
1411 case lang_output_statement_enum
:
1412 case lang_target_statement_enum
:
1414 case lang_input_section_enum
:
1415 dot
= size_input_section(prev
,
1416 output_section_statement
,
1417 output_section_statement
->fill
, dot
);
1419 case lang_input_statement_enum
:
1421 case lang_fill_statement_enum
:
1422 fill
= s
->fill_statement
.fill
;
1424 case lang_assignment_statement_enum
:
1426 bfd_vma newdot
= dot
;
1427 exp_fold_tree(s
->assignment_statement
.exp
,
1428 output_section_statement
,
1429 lang_allocating_phase_enum
,
1434 /* We've been moved ! so insert a pad */
1436 lang_statement_union_type
*new =
1437 (lang_statement_union_type
*)
1438 ldmalloc(sizeof(lang_padding_statement_type
));
1439 /* Link into existing chain */
1440 new->header
.next
= *prev
;
1442 new->header
.type
= lang_padding_statement_enum
;
1443 new->padding_statement
.output_section
=
1444 output_section_statement
->bfd_section
;
1445 new->padding_statement
.output_offset
=
1446 dot
- output_section_statement
->bfd_section
->vma
;
1447 new->padding_statement
.fill
= fill
;
1448 new->padding_statement
.size
= newdot
- dot
;
1449 output_section_statement
->bfd_section
->size
+=
1450 new->padding_statement
.size
;
1456 case lang_padding_statement_enum
:
1462 case lang_address_statement_enum
:
1465 prev
= &s
->header
.next
;
1472 DEFUN(lang_do_assignments
,(s
, output_section_statement
, fill
, dot
),
1473 lang_statement_union_type
*s AND
1474 lang_output_section_statement_type
* output_section_statement AND
1475 unsigned short fill AND
1479 for (; s
!= (lang_statement_union_type
*)NULL
; s
= s
->next
)
1481 switch (s
->header
.type
) {
1482 case lang_output_section_statement_enum
:
1484 lang_output_section_statement_type
*os
=
1485 &(s
->output_section_statement
);
1486 dot
= os
->bfd_section
->vma
;
1487 (void) lang_do_assignments(os
->children
.head
, os
, os
->fill
, dot
);
1488 dot
= os
->bfd_section
->vma
+ os
->bfd_section
->size
;
1491 case lang_wild_statement_enum
:
1493 dot
= lang_do_assignments(s
->wild_statement
.children
.head
,
1494 output_section_statement
,
1499 case lang_object_symbols_statement_enum
:
1500 case lang_output_statement_enum
:
1501 case lang_target_statement_enum
:
1503 case lang_common_statement_enum
:
1506 case lang_data_statement_enum
:
1508 etree_value_type value
;
1509 value
= exp_fold_tree(s
->data_statement
.exp
,
1510 0, lang_final_phase_enum
, dot
, &dot
);
1511 s
->data_statement
.value
= value
.value
;
1512 if (value
.valid
== false) info("%F%P: Invalid data statement\n");
1514 switch (s
->data_statement
.type
) {
1526 case lang_input_section_enum
:
1528 asection
*in
= s
->input_section
.section
;
1533 case lang_input_statement_enum
:
1535 case lang_fill_statement_enum
:
1536 fill
= s
->fill_statement
.fill
;
1538 case lang_assignment_statement_enum
:
1540 exp_fold_tree(s
->assignment_statement
.exp
,
1541 output_section_statement
,
1542 lang_final_phase_enum
,
1548 case lang_padding_statement_enum
:
1549 dot
+= s
->padding_statement
.size
;
1554 case lang_address_statement_enum
:
1565 DEFUN_VOID(lang_relocate_globals
)
1569 Each ldsym_type maintains a chain of pointers to asymbols which
1570 references the definition. Replace each pointer to the referenence
1571 with a pointer to only one place, preferably the definition. If
1572 the defintion isn't available then the common symbol, and if
1573 there isn't one of them then choose one reference.
1576 FOR_EACH_LDSYM(lgs
) {
1578 if (lgs
->sdefs_chain
) {
1579 it
= *(lgs
->sdefs_chain
);
1581 else if (lgs
->scoms_chain
!= (asymbol
**)NULL
) {
1582 it
= *(lgs
->scoms_chain
);
1584 else if (lgs
->srefs_chain
!= (asymbol
**)NULL
) {
1585 it
= *(lgs
->srefs_chain
);
1588 /* This can happen when the command line asked for a symbol to
1590 it
= (asymbol
*)NULL
;
1592 if (it
!= (asymbol
*)NULL
)
1594 asymbol
**ptr
= lgs
->srefs_chain
;
1596 while (ptr
!= (asymbol
**)NULL
) {
1597 asymbol
*ref
= *ptr
;
1599 ptr
= (asymbol
**)(ref
->udata
);
1608 DEFUN_VOID(lang_finish
)
1612 if (entry_symbol
== (char *)NULL
) {
1613 /* No entry has been specified, look for start */
1614 entry_symbol
= "start";
1616 lgs
= ldsym_get_soft(entry_symbol
);
1617 if (lgs
&& lgs
->sdefs_chain
) {
1618 asymbol
*sy
= *(lgs
->sdefs_chain
);
1619 /* We can set the entry address*/
1620 bfd_set_start_address(output_bfd
,
1621 outside_symbol_address(sy
));
1625 /* Can't find anything reasonable,
1626 use the first address in the text section
1628 asection
*ts
= bfd_get_section_by_name(output_bfd
, ".text");
1630 bfd_set_start_address(output_bfd
, ts
->vma
);
1635 /* By now we know the target architecture, and we may have an */
1636 /* ldfile_output_machine_name */
1638 DEFUN_VOID(lang_check
)
1640 lang_statement_union_type
*file
;
1643 for (file
= file_chain
.head
;
1644 file
!= (lang_statement_union_type
*)NULL
;
1645 file
=file
->input_statement
.next
)
1647 /* Inspect the architecture and ensure we're linking like
1651 if (bfd_arch_compatible( file
->input_statement
.the_bfd
,
1653 &ldfile_output_architecture
,
1654 &ldfile_output_machine
)) {
1655 bfd_set_arch_mach(output_bfd
,
1656 ldfile_output_architecture
, ldfile_output_machine
);
1659 enum bfd_architecture this_architecture
=
1660 bfd_get_architecture(file
->input_statement
.the_bfd
);
1661 unsigned long this_machine
=
1662 bfd_get_machine(file
->input_statement
.the_bfd
);
1664 info("%I: architecture %s",
1666 bfd_printable_arch_mach(this_architecture
, this_machine
));
1667 info(" incompatible with output %s\n",
1668 bfd_printable_arch_mach(ldfile_output_architecture
,
1669 ldfile_output_machine
));
1670 ldfile_output_architecture
= this_architecture
;
1671 ldfile_output_machine
= this_machine
;
1672 bfd_set_arch_mach(output_bfd
,
1673 ldfile_output_architecture
,
1674 ldfile_output_machine
);
1683 * run through all the global common symbols and tie them
1684 * to the output section requested.
1688 DEFUN_VOID(lang_common
)
1691 if (config
.relocateable_output
== false ||
1692 command_line
.force_common_definition
== true) {
1693 for (lgs
= symbol_head
;
1694 lgs
!= (ldsym_type
*)NULL
;
1698 unsigned int power_of_two
;
1701 if (lgs
->scoms_chain
!= (asymbol
**)NULL
) {
1702 com
= *(lgs
->scoms_chain
);
1733 /* Change from a common symbol into a definition of
1735 lgs
->sdefs_chain
= lgs
->scoms_chain
;
1736 lgs
->scoms_chain
= (asymbol
**)NULL
;
1738 /* Point to the correct common section */
1740 ((lang_input_statement_type
*)
1741 (com
->the_bfd
->usrdata
))->common_section
;
1742 /* Fix the size of the common section */
1743 com
->section
->size
= ALIGN(com
->section
->size
, align
);
1745 /* Remember if this is the biggest alignment ever seen */
1746 if (power_of_two
> com
->section
->alignment_power
) {
1747 com
->section
->alignment_power
= power_of_two
;
1751 com
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
1756 printf ("Allocating common %s: %x at %x\n",
1759 (unsigned) com
->section
->size
);
1761 com
->value
= com
->section
->size
;
1762 com
->section
->size
+= size
;
1763 com
->the_bfd
= output_bfd
;
1774 run through the input files and ensure that every input
1775 section has somewhere to go. If one is found without
1776 a destination then create an input request and place it
1777 into the statement tree.
1781 DEFUN_VOID(lang_place_orphans
)
1783 lang_input_statement_type
*file
;
1784 for (file
= (lang_input_statement_type
*)file_chain
.head
;
1785 file
!= (lang_input_statement_type
*)NULL
;
1786 file
= (lang_input_statement_type
*)file
->next
) {
1788 for (s
= file
->the_bfd
->sections
;
1789 s
!= (asection
*)NULL
;
1791 if ( s
->output_section
== (asection
*)NULL
) {
1792 /* This section of the file is not attatched, root
1793 around for a sensible place for it to go */
1795 if (file
->common_section
== s
) {
1796 /* This is a lonely common section which must
1797 have come from an archive. We attatch to the
1798 section with the wildcard */
1799 if (config
.relocateable_output
!= true
1800 && command_line
.force_common_definition
== false) {
1801 if (default_common_section
==
1802 (lang_output_section_statement_type
*)NULL
) {
1803 info("%P: No [COMMON] command, defaulting to .bss\n");
1805 default_common_section
=
1806 lang_output_section_statement_lookup(".bss");
1809 wild_doit(&default_common_section
->children
, s
,
1810 default_common_section
, file
);
1814 lang_output_section_statement_type
*os
=
1815 lang_output_section_statement_lookup(s
->name
);
1817 wild_doit(&os
->children
, s
, os
, file
);
1826 DEFUN(lang_set_flags
,(ptr
, flags
),
1827 lang_section_flags_type
*ptr AND
1830 boolean state
= true;
1831 ptr
->flag_read
= false;
1832 ptr
->flag_write
= false;
1833 ptr
->flag_executable
= false;
1834 ptr
->flag_loadable
= false;
1837 if (*flags
== '!') {
1844 ptr
->flag_read
= state
;
1847 ptr
->flag_write
= state
;
1850 ptr
->flag_executable
= state
;
1853 ptr
->flag_loadable
= state
;
1856 info("%P%F illegal syntax in flags\n");
1866 DEFUN(lang_for_each_file
,(func
),
1867 PROTO(void, (*func
),(lang_input_statement_type
*)))
1869 lang_input_statement_type
*f
;
1870 for (f
= (lang_input_statement_type
*)file_chain
.head
;
1871 f
!= (lang_input_statement_type
*)NULL
;
1872 f
= (lang_input_statement_type
*)f
->next
)
1880 DEFUN(lang_for_each_input_section
, (func
),
1881 PROTO(void ,(*func
),(bfd
*ab
, asection
*as
)))
1883 lang_input_statement_type
*f
;
1884 for (f
= (lang_input_statement_type
*)file_chain
.head
;
1885 f
!= (lang_input_statement_type
*)NULL
;
1886 f
= (lang_input_statement_type
*)f
->next
)
1889 for (s
= f
->the_bfd
->sections
;
1890 s
!= (asection
*)NULL
;
1892 func(f
->the_bfd
, s
);
1900 DEFUN(ldlang_add_file
,(entry
),
1901 lang_input_statement_type
*entry
)
1904 lang_statement_append(&file_chain
,
1905 (lang_statement_union_type
*)entry
,
1912 DEFUN(lang_add_output
,(name
),
1915 lang_output_statement_type
*new = new_stat(lang_output_statement
,
1918 had_output_filename
= true;
1922 static lang_output_section_statement_type
*current_section
;
1925 DEFUN(lang_enter_output_section_statement
,
1926 (output_section_statement_name
,
1929 char *output_section_statement_name AND
1930 etree_type
*address_exp AND
1931 bfd_vma block_value
)
1933 lang_output_section_statement_type
*os
;
1936 lang_output_section_statement_lookup(output_section_statement_name
);
1939 /* Add this statement to tree */
1940 /* add_statement(lang_output_section_statement_enum,
1941 output_section_statement);*/
1942 /* Make next things chain into subchain of this */
1944 if (os
->addr_tree
==
1945 (etree_type
*)NULL
) {
1949 os
->block_value
= block_value
;
1950 stat_ptr
= & os
->children
;
1956 DEFUN_VOID(lang_final
)
1958 if (had_output_filename
== false) {
1959 lang_add_output("a.out");
1968 DEFUN(create_symbol
,(name
, flags
, section
),
1969 CONST
char *name AND
1973 extern lang_input_statement_type
*script_file
;
1974 asymbol
**def_ptr
= (asymbol
**)ldmalloc(sizeof(asymbol
**));
1975 /* Add this definition to script file */
1976 asymbol
*def
= (asymbol
*)bfd_make_empty_symbol(script_file
->the_bfd
);
1977 def
->name
= buystring(name
);
1980 def
->section
= section
;
1983 Q_enter_global_ref(def_ptr
);
1989 DEFUN_VOID(lang_process
)
1991 if (had_script
== false) {
1992 parse_line(ldemul_get_script());
1994 lang_reasonable_defaults();
1995 current_target
= default_target
;
1997 lang_for_each_statement(ldlang_open_output
); /* Open the output file */
1998 /* For each output section statement, create a section in the output
2000 lang_create_output_section_statements();
2002 /* Create a dummy bfd for the script */
2003 lang_init_script_file();
2005 /* Add to the hash table all undefineds on the command line */
2006 lang_place_undefineds();
2008 /* Create a bfd for each input file */
2009 current_target
= default_target
;
2010 lang_for_each_statement(open_input_bfds
);
2012 common_section
.userdata
= &common_section_userdata
;
2014 /* Run through the contours of the script and attatch input sections
2015 to the correct output sections
2017 map_input_to_output_sections(statement_list
.head
, (char *)NULL
,
2018 ( lang_output_section_statement_type
*)NULL
);
2020 /* Find any sections not attatched explicitly and handle them */
2021 lang_place_orphans();
2023 /* Size up the common data */
2026 ldemul_before_allocation();
2028 /* Size up the sections */
2029 lang_size_sections(statement_list
.head
,
2030 (lang_output_section_statement_type
*)NULL
,
2031 &(statement_list
.head
), 0, (bfd_vma
)0);
2033 /* See if anything special should be done now we know how big
2035 ldemul_after_allocation();
2037 /* Do all the assignments, now that we know the final restingplaces
2038 of all the symbols */
2040 lang_do_assignments(statement_list
.head
,
2041 (lang_output_section_statement_type
*)NULL
,
2044 /* Make sure that we're not mixing architectures */
2048 /* Move the global symbols around */
2049 lang_relocate_globals();
2056 /* EXPORTED TO YACC */
2059 DEFUN(lang_add_wild
,(section_name
, filename
),
2060 CONST
char *CONST section_name AND
2061 CONST
char *CONST filename
)
2063 lang_wild_statement_type
*new = new_stat(lang_wild_statement
,
2066 if (section_name
!= (char *)NULL
&& strcmp(section_name
,"COMMON") == 0)
2068 placed_commons
= true;
2070 if (filename
!= (char *)NULL
) {
2071 lang_has_input_file
= true;
2073 new->section_name
= section_name
;
2074 new->filename
= filename
;
2075 lang_list_init(&new->children
);
2078 DEFUN(lang_section_start
,(name
, address
),
2079 CONST
char *name AND
2080 etree_type
*address
)
2082 lang_address_statement_type
*ad
=new_stat(lang_address_statement
, stat_ptr
);
2083 ad
->section_name
= name
;
2084 ad
->address
= address
;
2088 DEFUN(lang_add_entry
,(name
),
2091 entry_symbol
= name
;
2095 DEFUN(lang_add_target
,(name
),
2098 lang_target_statement_type
*new = new_stat(lang_target_statement
,
2108 DEFUN(lang_add_map
,(name
),
2114 map_option_f
= true;
2122 DEFUN(lang_add_fill
,(exp
),
2125 lang_fill_statement_type
*new = new_stat(lang_fill_statement
,
2131 DEFUN(lang_add_data
,(type
, exp
),
2133 union etree_union
*exp
)
2136 lang_data_statement_type
*new = new_stat(lang_data_statement
,
2143 DEFUN(lang_add_assignment
,(exp
),
2146 lang_assignment_statement_type
*new = new_stat(lang_assignment_statement
,
2152 DEFUN(lang_add_attribute
,(attribute
),
2153 enum statement_enum attribute
)
2155 new_statement(attribute
, sizeof(lang_statement_union_type
),stat_ptr
);
2161 DEFUN(lang_startup
,(name
),
2164 if (startup_file
!= (char *)NULL
) {
2165 info("%P%FMultiple STARTUP files\n");
2167 first_file
->filename
= name
;
2168 first_file
->local_sym_name
= name
;
2173 DEFUN(lang_float
,(maybe
),
2176 lang_float_flag
= maybe
;
2180 DEFUN(lang_leave_output_section_statement
,(fill
, memspec
),
2182 CONST
char *memspec
)
2184 current_section
->fill
= fill
;
2185 current_section
->region
= lang_memory_region_lookup(memspec
);
2186 stat_ptr
= &statement_list
;
2189 Create an absolute symbol with the given name with the value of the
2190 address of first byte of the section named.
2192 If the symbol already exists, then do nothing.
2195 DEFUN(lang_abs_symbol_at_beginning_of
,(section
, name
),
2196 CONST
char *section AND
2199 if (ldsym_undefined(name
)) {
2200 extern bfd
*output_bfd
;
2201 extern asymbol
*create_symbol();
2202 asection
*s
= bfd_get_section_by_name(output_bfd
, section
);
2203 asymbol
*def
= create_symbol(name
,
2204 BSF_GLOBAL
| BSF_EXPORT
|
2207 if (s
!= (asection
*)NULL
) {
2208 def
->value
= s
->vma
;
2217 Create an absolute symbol with the given name with the value of the
2218 address of the first byte after the end of the section named.
2220 If the symbol already exists, then do nothing.
2223 DEFUN(lang_abs_symbol_at_end_of
,(section
, name
),
2224 CONST
char *section AND
2227 if (ldsym_undefined(name
)){
2228 extern bfd
*output_bfd
;
2229 extern asymbol
*create_symbol();
2230 asection
*s
= bfd_get_section_by_name(output_bfd
, section
);
2231 /* Add a symbol called _end */
2232 asymbol
*def
= create_symbol(name
,
2233 BSF_GLOBAL
| BSF_EXPORT
|
2236 if (s
!= (asection
*)NULL
) {
2237 def
->value
= s
->vma
+ s
->size
;
2246 DEFUN(lang_statement_append
,(list
, element
, field
),
2247 lang_statement_list_type
*list AND
2248 lang_statement_union_type
*element AND
2249 lang_statement_union_type
**field
)
2251 *(list
->tail
) = element
;
2255 /* Set the output format type */
2257 DEFUN(lang_add_output_format
,(format
),
2260 output_target
= format
;