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 printf("LOAD %s\n",statm
->filename
);
991 DEFUN(print_symbol
,(q
),
998 print_address(outside_symbol_address(q
));
999 printf(" %s", q
->name
? q
->name
: " ");
1004 DEFUN(print_input_section
,(in
),
1005 lang_input_section_type
*in
)
1007 asection
*i
= in
->section
;
1012 print_section(i
->name
);
1014 if (i
->output_section
) {
1015 print_address(i
->output_section
->vma
+ i
->output_offset
);
1017 print_size(i
->size
);
1019 print_alignment(i
->alignment_power
);
1023 bfd
*abfd
= in
->ifile
->the_bfd
;
1024 if (in
->ifile
->just_syms_flag
== true) {
1025 printf("symbols only ");
1028 printf(" %s ",abfd
->xvec
->name
);
1029 if(abfd
->my_archive
!= (bfd
*)NULL
) {
1030 printf("[%s]%s", abfd
->my_archive
->filename
,
1034 printf("%s", abfd
->filename
);
1038 /* Find all the symbols in this file defined in this section */
1041 for (p
= in
->ifile
->asymbols
; *p
; p
++) {
1044 if (bfd_get_section(q
) == i
&& q
->flags
& BSF_GLOBAL
) {
1055 print_dot
= outside_section_address(i
) + i
->size
;
1058 printf("No output section allocated\n");
1064 DEFUN(print_fill_statement
,(fill
),
1065 lang_fill_statement_type
*fill
)
1067 printf("FILL mask ");
1068 print_fill( fill
->fill
);
1072 DEFUN(print_data_statement
,(data
),
1073 lang_data_statement_type
*data
)
1075 /* bfd_vma value; */
1080 ASSERT(print_dot
== data
->output_vma
);
1082 print_address(data
->output_vma
);
1084 print_address(data
->value
);
1086 switch (data
->type
) {
1089 print_dot
+= BYTE_SIZE
;
1093 print_dot
+= SHORT_SIZE
;
1097 print_dot
+= LONG_SIZE
;
1101 exp_print_tree(stdout
, data
->exp
);
1108 DEFUN(print_padding_statement
,(s
),
1109 lang_padding_statement_type
*s
)
1113 print_section("*fill*");
1115 print_address(s
->output_offset
+ s
->output_section
->vma
);
1117 print_size(s
->size
);
1119 print_fill(s
->fill
);
1124 DEFUN(print_wild_statement
,(w
,os
),
1125 lang_wild_statement_type
*w AND
1126 lang_output_section_statement_type
*os
)
1128 if (w
->filename
!= (char *)NULL
) {
1129 printf("%s",w
->filename
);
1134 if (w
->section_name
!= (char *)NULL
) {
1135 printf("(%s)",w
->section_name
);
1141 print_statement(w
->children
.head
, os
);
1145 DEFUN(print_statement
,(s
, os
),
1146 lang_statement_union_type
*s AND
1147 lang_output_section_statement_type
*os
)
1150 switch (s
->header
.type
) {
1151 case lang_wild_statement_enum
:
1152 print_wild_statement(&s
->wild_statement
, os
);
1155 printf("Fail with %d\n",s
->header
.type
);
1158 case lang_address_statement_enum
:
1159 printf("address\n");
1162 case lang_object_symbols_statement_enum
:
1163 printf("object symbols\n");
1165 case lang_fill_statement_enum
:
1166 print_fill_statement(&s
->fill_statement
);
1168 case lang_data_statement_enum
:
1169 print_data_statement(&s
->data_statement
);
1171 case lang_input_section_enum
:
1172 print_input_section(&s
->input_section
);
1174 case lang_padding_statement_enum
:
1175 print_padding_statement(&s
->padding_statement
);
1177 case lang_output_section_statement_enum
:
1178 print_output_section_statement(&s
->output_section_statement
);
1180 case lang_assignment_statement_enum
:
1181 print_assignment(&s
->assignment_statement
,
1186 case lang_target_statement_enum
:
1187 printf("TARGET(%s)\n", s
->target_statement
.target
);
1189 case lang_output_statement_enum
:
1190 printf("OUTPUT(%s)\n", s
->output_statement
.name
);
1192 case lang_input_statement_enum
:
1193 print_input_statement(&s
->input_statement
);
1195 case lang_afile_asection_pair_statement_enum
:
1205 DEFUN_VOID(print_statements
)
1207 print_statement(statement_list
.head
,
1208 (lang_output_section_statement_type
*)NULL
);
1212 DEFUN(insert_pad
,(this_ptr
, fill
, power
, output_section_statement
, dot
),
1213 lang_statement_union_type
**this_ptr AND
1215 unsigned int power AND
1216 asection
* output_section_statement AND
1219 /* Align this section first to the
1220 input sections requirement, then
1221 to the output section's requirement.
1222 If this alignment is > than any seen before,
1223 then record it too. Perform the alignment by
1224 inserting a magic 'padding' statement.
1227 unsigned int alignment_needed
= align_power(dot
, power
) - dot
;
1229 if (alignment_needed
!= 0)
1231 lang_statement_union_type
*new =
1232 (lang_statement_union_type
*)
1233 ldmalloc(sizeof(lang_padding_statement_type
));
1234 /* Link into existing chain */
1235 new->header
.next
= *this_ptr
;
1237 new->header
.type
= lang_padding_statement_enum
;
1238 new->padding_statement
.output_section
= output_section_statement
;
1239 new->padding_statement
.output_offset
=
1240 dot
- output_section_statement
->vma
;
1241 new->padding_statement
.fill
= fill
;
1242 new->padding_statement
.size
= alignment_needed
;
1246 /* Remember the most restrictive alignment */
1247 if (power
> output_section_statement
->alignment_power
) {
1248 output_section_statement
->alignment_power
= power
;
1250 output_section_statement
->size
+= alignment_needed
;
1251 return alignment_needed
+ dot
;
1255 /* Work out how much this section will move the dot point */
1257 DEFUN(size_input_section
, (this_ptr
, output_section_statement
, fill
, dot
),
1258 lang_statement_union_type
**this_ptr AND
1259 lang_output_section_statement_type
*output_section_statement AND
1260 unsigned short fill AND
1263 lang_input_section_type
*is
= &((*this_ptr
)->input_section
);
1264 asection
*i
= is
->section
;
1266 if (is
->ifile
->just_syms_flag
== false) {
1267 dot
= insert_pad(this_ptr
, fill
, i
->alignment_power
,
1268 output_section_statement
->bfd_section
, dot
);
1270 /* remember the largest size so we can malloc the largest area */
1271 /* needed for the output stage */
1272 if (i
->size
> largest_section
) {
1273 largest_section
= i
->size
;
1276 /* Remember where in the output section this input section goes */
1277 i
->output_offset
= dot
- output_section_statement
->bfd_section
->vma
;
1279 /* Mark how big the output section must be to contain this now */
1281 output_section_statement
->bfd_section
->size
=
1282 dot
- output_section_statement
->bfd_section
->vma
;
1289 /* Work out the size of the output sections
1290 from the sizes of the input sections */
1292 DEFUN(lang_size_sections
,(s
, output_section_statement
, prev
, fill
, dot
),
1293 lang_statement_union_type
*s AND
1294 lang_output_section_statement_type
* output_section_statement AND
1295 lang_statement_union_type
**prev AND
1296 unsigned short fill AND
1299 /* Size up the sections from their constituent parts */
1300 for (; s
!= (lang_statement_union_type
*)NULL
; s
= s
->next
)
1302 switch (s
->header
.type
) {
1303 case lang_output_section_statement_enum
:
1306 lang_output_section_statement_type
*os
=
1307 &(s
->output_section_statement
);
1308 /* The start of a section */
1310 if (os
->addr_tree
== (etree_type
*)NULL
) {
1311 /* No address specified for this section, get one
1312 from the region specification
1314 if (os
->region
== (lang_memory_region_type
*)NULL
) {
1315 os
->region
= lang_memory_region_lookup("*default*");
1317 dot
= os
->region
->current
;
1320 etree_value_type r
;
1321 r
= exp_fold_tree(os
->addr_tree
,
1322 (lang_output_section_statement_type
*)NULL
,
1323 lang_allocating_phase_enum
,
1325 if (r
.valid
== false) {
1326 info("%F%S: non constant address expression for section %s\n",
1331 /* The section starts here */
1332 /* First, align to what the section needs */
1334 dot
= align_power(dot
, os
->bfd_section
->alignment_power
);
1335 os
->bfd_section
->vma
= dot
;
1336 os
->bfd_section
->output_offset
= 0;
1338 (void) lang_size_sections(os
->children
.head
, os
, &os
->children
.head
,
1340 /* Ignore the size of the input sections, use the vma and size to */
1344 after
= ALIGN(os
->bfd_section
->vma
+
1345 os
->bfd_section
->size
,
1349 os
->bfd_section
->size
= after
- os
->bfd_section
->vma
;
1350 dot
= os
->bfd_section
->vma
+ os
->bfd_section
->size
;
1351 os
->processed
= true;
1353 /* Replace into region ? */
1354 if (os
->addr_tree
== (etree_type
*)NULL
1355 && os
->region
!=(lang_memory_region_type
*)NULL
) {
1356 os
->region
->current
= dot
;
1362 case lang_data_statement_enum
:
1365 s
->data_statement
.output_vma
= dot
;
1366 s
->data_statement
.output_section
=
1367 output_section_statement
->bfd_section
;
1369 switch (s
->data_statement
.type
) {
1382 output_section_statement
->bfd_section
->size
+= size
;
1386 case lang_wild_statement_enum
:
1388 dot
= lang_size_sections(s
->wild_statement
.children
.head
,
1389 output_section_statement
,
1390 &s
->wild_statement
.children
.head
,
1396 case lang_object_symbols_statement_enum
:
1397 create_object_symbols
= output_section_statement
;
1399 case lang_output_statement_enum
:
1400 case lang_target_statement_enum
:
1402 case lang_input_section_enum
:
1403 dot
= size_input_section(prev
,
1404 output_section_statement
,
1405 output_section_statement
->fill
, dot
);
1407 case lang_input_statement_enum
:
1409 case lang_fill_statement_enum
:
1410 fill
= s
->fill_statement
.fill
;
1412 case lang_assignment_statement_enum
:
1414 bfd_vma newdot
= dot
;
1415 exp_fold_tree(s
->assignment_statement
.exp
,
1416 output_section_statement
,
1417 lang_allocating_phase_enum
,
1422 /* We've been moved ! so insert a pad */
1424 lang_statement_union_type
*new =
1425 (lang_statement_union_type
*)
1426 ldmalloc(sizeof(lang_padding_statement_type
));
1427 /* Link into existing chain */
1428 new->header
.next
= *prev
;
1430 new->header
.type
= lang_padding_statement_enum
;
1431 new->padding_statement
.output_section
=
1432 output_section_statement
->bfd_section
;
1433 new->padding_statement
.output_offset
=
1434 dot
- output_section_statement
->bfd_section
->vma
;
1435 new->padding_statement
.fill
= fill
;
1436 new->padding_statement
.size
= newdot
- dot
;
1437 output_section_statement
->bfd_section
->size
+=
1438 new->padding_statement
.size
;
1444 case lang_padding_statement_enum
:
1450 case lang_address_statement_enum
:
1453 prev
= &s
->header
.next
;
1460 DEFUN(lang_do_assignments
,(s
, output_section_statement
, fill
, dot
),
1461 lang_statement_union_type
*s AND
1462 lang_output_section_statement_type
* output_section_statement AND
1463 unsigned short fill AND
1467 for (; s
!= (lang_statement_union_type
*)NULL
; s
= s
->next
)
1469 switch (s
->header
.type
) {
1470 case lang_output_section_statement_enum
:
1472 lang_output_section_statement_type
*os
=
1473 &(s
->output_section_statement
);
1474 dot
= os
->bfd_section
->vma
;
1475 (void) lang_do_assignments(os
->children
.head
, os
, os
->fill
, dot
);
1476 dot
= os
->bfd_section
->vma
+ os
->bfd_section
->size
;
1479 case lang_wild_statement_enum
:
1481 dot
= lang_do_assignments(s
->wild_statement
.children
.head
,
1482 output_section_statement
,
1487 case lang_object_symbols_statement_enum
:
1488 case lang_output_statement_enum
:
1489 case lang_target_statement_enum
:
1491 case lang_common_statement_enum
:
1494 case lang_data_statement_enum
:
1496 etree_value_type value
;
1497 value
= exp_fold_tree(s
->data_statement
.exp
,
1498 0, lang_final_phase_enum
, dot
, &dot
);
1499 s
->data_statement
.value
= value
.value
;
1500 if (value
.valid
== false) info("%F%P: Invalid data statement\n");
1502 switch (s
->data_statement
.type
) {
1514 case lang_input_section_enum
:
1516 asection
*in
= s
->input_section
.section
;
1521 case lang_input_statement_enum
:
1523 case lang_fill_statement_enum
:
1524 fill
= s
->fill_statement
.fill
;
1526 case lang_assignment_statement_enum
:
1528 exp_fold_tree(s
->assignment_statement
.exp
,
1529 output_section_statement
,
1530 lang_final_phase_enum
,
1536 case lang_padding_statement_enum
:
1537 dot
+= s
->padding_statement
.size
;
1542 case lang_address_statement_enum
:
1553 DEFUN_VOID(lang_relocate_globals
)
1557 Each ldsym_type maintains a chain of pointers to asymbols which
1558 references the definition. Replace each pointer to the referenence
1559 with a pointer to only one place, preferably the definition. If
1560 the defintion isn't available then the common symbol, and if
1561 there isn't one of them then choose one reference.
1564 FOR_EACH_LDSYM(lgs
) {
1566 if (lgs
->sdefs_chain
) {
1567 it
= *(lgs
->sdefs_chain
);
1569 else if (lgs
->scoms_chain
!= (asymbol
**)NULL
) {
1570 it
= *(lgs
->scoms_chain
);
1572 else if (lgs
->srefs_chain
!= (asymbol
**)NULL
) {
1573 it
= *(lgs
->srefs_chain
);
1576 /* This can happen when the command line asked for a symbol to
1578 it
= (asymbol
*)NULL
;
1580 if (it
!= (asymbol
*)NULL
)
1582 asymbol
**ptr
= lgs
->srefs_chain
;
1584 while (ptr
!= (asymbol
**)NULL
) {
1585 asymbol
*ref
= *ptr
;
1587 ptr
= (asymbol
**)(ref
->udata
);
1596 DEFUN_VOID(lang_finish
)
1600 if (entry_symbol
== (char *)NULL
) {
1601 /* No entry has been specified, look for start */
1602 entry_symbol
= "start";
1604 lgs
= ldsym_get_soft(entry_symbol
);
1605 if (lgs
&& lgs
->sdefs_chain
) {
1606 asymbol
*sy
= *(lgs
->sdefs_chain
);
1607 /* We can set the entry address*/
1608 bfd_set_start_address(output_bfd
,
1609 outside_symbol_address(sy
));
1613 /* Can't find anything reasonable,
1614 use the first address in the text section
1616 asection
*ts
= bfd_get_section_by_name(output_bfd
, ".text");
1618 bfd_set_start_address(output_bfd
, ts
->vma
);
1623 /* By now we know the target architecture, and we may have an */
1624 /* ldfile_output_machine_name */
1626 DEFUN_VOID(lang_check
)
1628 lang_statement_union_type
*file
;
1631 for (file
= file_chain
.head
;
1632 file
!= (lang_statement_union_type
*)NULL
;
1633 file
=file
->input_statement
.next
)
1635 /* Inspect the architecture and ensure we're linking like
1639 if (bfd_arch_compatible( file
->input_statement
.the_bfd
,
1641 &ldfile_output_architecture
,
1642 &ldfile_output_machine
)) {
1643 bfd_set_arch_mach(output_bfd
,
1644 ldfile_output_architecture
, ldfile_output_machine
);
1647 enum bfd_architecture this_architecture
=
1648 bfd_get_architecture(file
->input_statement
.the_bfd
);
1649 unsigned long this_machine
=
1650 bfd_get_machine(file
->input_statement
.the_bfd
);
1652 info("%I: architecture %s",
1654 bfd_printable_arch_mach(this_architecture
, this_machine
));
1655 info(" incompatible with output %s\n",
1656 bfd_printable_arch_mach(ldfile_output_architecture
,
1657 ldfile_output_machine
));
1658 ldfile_output_architecture
= this_architecture
;
1659 ldfile_output_machine
= this_machine
;
1660 bfd_set_arch_mach(output_bfd
,
1661 ldfile_output_architecture
,
1662 ldfile_output_machine
);
1671 * run through all the global common symbols and tie them
1672 * to the output section requested.
1676 DEFUN_VOID(lang_common
)
1679 if (config
.relocateable_output
== false ||
1680 command_line
.force_common_definition
== true) {
1681 for (lgs
= symbol_head
;
1682 lgs
!= (ldsym_type
*)NULL
;
1686 unsigned int power_of_two
;
1689 if (lgs
->scoms_chain
!= (asymbol
**)NULL
) {
1690 com
= *(lgs
->scoms_chain
);
1721 /* Change from a common symbol into a definition of
1723 lgs
->sdefs_chain
= lgs
->scoms_chain
;
1724 lgs
->scoms_chain
= (asymbol
**)NULL
;
1726 /* Point to the correct common section */
1728 ((lang_input_statement_type
*)
1729 (com
->the_bfd
->usrdata
))->common_section
;
1730 /* Fix the size of the common section */
1731 com
->section
->size
= ALIGN(com
->section
->size
, align
);
1733 /* Remember if this is the biggest alignment ever seen */
1734 if (power_of_two
> com
->section
->alignment_power
) {
1735 com
->section
->alignment_power
= power_of_two
;
1739 com
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
1743 printf ("Allocating common %s: %x at %x\n",
1746 (unsigned) com
->section
->size
);
1748 com
->value
= com
->section
->size
;
1749 com
->section
->size
+= size
;
1759 run through the input files and ensure that every input
1760 section has somewhere to go. If one is found without
1761 a destination then create an input request and place it
1762 into the statement tree.
1766 DEFUN_VOID(lang_place_orphans
)
1768 lang_input_statement_type
*file
;
1769 for (file
= (lang_input_statement_type
*)file_chain
.head
;
1770 file
!= (lang_input_statement_type
*)NULL
;
1771 file
= (lang_input_statement_type
*)file
->next
) {
1773 for (s
= file
->the_bfd
->sections
;
1774 s
!= (asection
*)NULL
;
1776 if ( s
->output_section
== (asection
*)NULL
) {
1777 /* This section of the file is not attatched, root
1778 around for a sensible place for it to go */
1780 if (file
->common_section
== s
) {
1781 /* This is a lonely common section which must
1782 have come from an archive. We attatch to the
1783 section with the wildcard */
1784 if (config
.relocateable_output
!= true
1785 && command_line
.force_common_definition
== false) {
1786 if (default_common_section
==
1787 (lang_output_section_statement_type
*)NULL
) {
1788 info("%P: No [COMMON] command, defaulting to .bss\n");
1790 default_common_section
=
1791 lang_output_section_statement_lookup(".bss");
1794 wild_doit(&default_common_section
->children
, s
,
1795 default_common_section
, file
);
1799 lang_output_section_statement_type
*os
=
1800 lang_output_section_statement_lookup(s
->name
);
1802 wild_doit(&os
->children
, s
, os
, file
);
1811 DEFUN(lang_set_flags
,(ptr
, flags
),
1812 lang_section_flags_type
*ptr AND
1815 boolean state
= true;
1816 ptr
->flag_read
= false;
1817 ptr
->flag_write
= false;
1818 ptr
->flag_executable
= false;
1819 ptr
->flag_loadable
= false;
1822 if (*flags
== '!') {
1829 ptr
->flag_read
= state
;
1832 ptr
->flag_write
= state
;
1835 ptr
->flag_executable
= state
;
1838 ptr
->flag_loadable
= state
;
1841 info("%P%F illegal syntax in flags\n");
1851 DEFUN(lang_for_each_file
,(func
),
1852 PROTO(void, (*func
),(lang_input_statement_type
*)))
1854 lang_input_statement_type
*f
;
1855 for (f
= (lang_input_statement_type
*)file_chain
.head
;
1856 f
!= (lang_input_statement_type
*)NULL
;
1857 f
= (lang_input_statement_type
*)f
->next
)
1865 DEFUN(lang_for_each_input_section
, (func
),
1866 PROTO(void ,(*func
),(bfd
*ab
, asection
*as
)))
1868 lang_input_statement_type
*f
;
1869 for (f
= (lang_input_statement_type
*)file_chain
.head
;
1870 f
!= (lang_input_statement_type
*)NULL
;
1871 f
= (lang_input_statement_type
*)f
->next
)
1874 for (s
= f
->the_bfd
->sections
;
1875 s
!= (asection
*)NULL
;
1877 func(f
->the_bfd
, s
);
1885 DEFUN(ldlang_add_file
,(entry
),
1886 lang_input_statement_type
*entry
)
1889 lang_statement_append(&file_chain
,
1890 (lang_statement_union_type
*)entry
,
1897 DEFUN(lang_add_output
,(name
),
1900 lang_output_statement_type
*new = new_stat(lang_output_statement
,
1903 had_output_filename
= true;
1907 static lang_output_section_statement_type
*current_section
;
1910 DEFUN(lang_enter_output_section_statement
,
1911 (output_section_statement_name
,
1914 char *output_section_statement_name AND
1915 etree_type
*address_exp AND
1916 bfd_vma block_value
)
1918 lang_output_section_statement_type
*os
;
1921 lang_output_section_statement_lookup(output_section_statement_name
);
1924 /* Add this statement to tree */
1925 /* add_statement(lang_output_section_statement_enum,
1926 output_section_statement);*/
1927 /* Make next things chain into subchain of this */
1929 if (os
->addr_tree
==
1930 (etree_type
*)NULL
) {
1934 os
->block_value
= block_value
;
1935 stat_ptr
= & os
->children
;
1941 DEFUN_VOID(lang_final
)
1943 if (had_output_filename
== false) {
1944 lang_add_output("a.out");
1953 DEFUN(create_symbol
,(name
, flags
, section
),
1954 CONST
char *name AND
1958 extern lang_input_statement_type
*script_file
;
1959 asymbol
**def_ptr
= (asymbol
**)ldmalloc(sizeof(asymbol
**));
1960 /* Add this definition to script file */
1961 asymbol
*def
= (asymbol
*)bfd_make_empty_symbol(script_file
->the_bfd
);
1962 def
->name
= buystring(name
);
1965 def
->section
= section
;
1968 Q_enter_global_ref(def_ptr
);
1974 DEFUN_VOID(lang_process
)
1976 if (had_script
== false) {
1977 parse_line(ldemul_get_script());
1979 lang_reasonable_defaults();
1980 current_target
= default_target
;
1982 lang_for_each_statement(ldlang_open_output
); /* Open the output file */
1983 /* For each output section statement, create a section in the output
1985 lang_create_output_section_statements();
1987 /* Create a dummy bfd for the script */
1988 lang_init_script_file();
1990 /* Add to the hash table all undefineds on the command line */
1991 lang_place_undefineds();
1993 /* Create a bfd for each input file */
1994 current_target
= default_target
;
1995 lang_for_each_statement(open_input_bfds
);
1997 common_section
.userdata
= &common_section_userdata
;
1999 /* Run through the contours of the script and attatch input sections
2000 to the correct output sections
2002 map_input_to_output_sections(statement_list
.head
, (char *)NULL
,
2003 ( lang_output_section_statement_type
*)NULL
);
2005 /* Find any sections not attatched explicitly and handle them */
2006 lang_place_orphans();
2008 /* Size up the common data */
2011 ldemul_before_allocation();
2013 /* Size up the sections */
2014 lang_size_sections(statement_list
.head
,
2015 (lang_output_section_statement_type
*)NULL
,
2016 &(statement_list
.head
), 0, (bfd_vma
)0);
2018 /* See if anything special should be done now we know how big
2020 ldemul_after_allocation();
2022 /* Do all the assignments, now that we know the final restingplaces
2023 of all the symbols */
2025 lang_do_assignments(statement_list
.head
,
2026 (lang_output_section_statement_type
*)NULL
,
2029 /* Make sure that we're not mixing architectures */
2033 /* Move the global symbols around */
2034 lang_relocate_globals();
2041 /* EXPORTED TO YACC */
2044 DEFUN(lang_add_wild
,(section_name
, filename
),
2045 CONST
char *CONST section_name AND
2046 CONST
char *CONST filename
)
2048 lang_wild_statement_type
*new = new_stat(lang_wild_statement
,
2051 if (section_name
!= (char *)NULL
&& strcmp(section_name
,"COMMON") == 0)
2053 placed_commons
= true;
2055 if (filename
!= (char *)NULL
) {
2056 lang_has_input_file
= true;
2058 new->section_name
= section_name
;
2059 new->filename
= filename
;
2060 lang_list_init(&new->children
);
2063 DEFUN(lang_section_start
,(name
, address
),
2064 CONST
char *name AND
2065 etree_type
*address
)
2067 lang_address_statement_type
*ad
=new_stat(lang_address_statement
, stat_ptr
);
2068 ad
->section_name
= name
;
2069 ad
->address
= address
;
2073 DEFUN(lang_add_entry
,(name
),
2076 entry_symbol
= name
;
2080 DEFUN(lang_add_target
,(name
),
2083 lang_target_statement_type
*new = new_stat(lang_target_statement
,
2093 DEFUN(lang_add_map
,(name
),
2099 map_option_f
= true;
2107 DEFUN(lang_add_fill
,(exp
),
2110 lang_fill_statement_type
*new = new_stat(lang_fill_statement
,
2116 DEFUN(lang_add_data
,(type
, exp
),
2118 union etree_union
*exp
)
2121 lang_data_statement_type
*new = new_stat(lang_data_statement
,
2128 DEFUN(lang_add_assignment
,(exp
),
2131 lang_assignment_statement_type
*new = new_stat(lang_assignment_statement
,
2137 DEFUN(lang_add_attribute
,(attribute
),
2138 enum statement_enum attribute
)
2140 new_statement(attribute
, sizeof(lang_statement_union_type
),stat_ptr
);
2146 DEFUN(lang_startup
,(name
),
2149 if (startup_file
!= (char *)NULL
) {
2150 info("%P%FMultiple STARTUP files\n");
2152 first_file
->filename
= name
;
2153 first_file
->local_sym_name
= name
;
2158 DEFUN(lang_float
,(maybe
),
2161 lang_float_flag
= maybe
;
2165 DEFUN(lang_leave_output_section_statement
,(fill
, memspec
),
2167 CONST
char *memspec
)
2169 current_section
->fill
= fill
;
2170 current_section
->region
= lang_memory_region_lookup(memspec
);
2171 stat_ptr
= &statement_list
;
2174 Create an absolute symbol with the given name with the value of the
2175 address of first byte of the section named.
2177 If the symbol already exists, then do nothing.
2180 DEFUN(lang_abs_symbol_at_beginning_of
,(section
, name
),
2181 CONST
char *section AND
2184 if (ldsym_undefined(name
)) {
2185 extern bfd
*output_bfd
;
2186 extern asymbol
*create_symbol();
2187 asection
*s
= bfd_get_section_by_name(output_bfd
, section
);
2188 asymbol
*def
= create_symbol(name
,
2189 BSF_GLOBAL
| BSF_EXPORT
|
2192 if (s
!= (asection
*)NULL
) {
2193 def
->value
= s
->vma
;
2202 Create an absolute symbol with the given name with the value of the
2203 address of the first byte after the end of the section named.
2205 If the symbol already exists, then do nothing.
2208 DEFUN(lang_abs_symbol_at_end_of
,(section
, name
),
2209 CONST
char *section AND
2212 if (ldsym_undefined(name
)){
2213 extern bfd
*output_bfd
;
2214 extern asymbol
*create_symbol();
2215 asection
*s
= bfd_get_section_by_name(output_bfd
, section
);
2216 /* Add a symbol called _end */
2217 asymbol
*def
= create_symbol(name
,
2218 BSF_GLOBAL
| BSF_EXPORT
|
2221 if (s
!= (asection
*)NULL
) {
2222 def
->value
= s
->vma
+ s
->size
;
2231 DEFUN(lang_statement_append
,(list
, element
, field
),
2232 lang_statement_list_type
*list AND
2233 lang_statement_union_type
*element AND
2234 lang_statement_union_type
**field
)
2236 *(list
->tail
) = element
;