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. */
39 PROTO(static void, print_statements
,(void));
40 PROTO(static void, print_statement
,(lang_statement_union_type
*,
41 lang_output_section_statement_type
*));
45 static CONST
char *startup_file
;
46 static lang_statement_list_type input_file_chain
;
47 static boolean placed_commons
= false;
48 static lang_output_section_statement_type
*default_common_section
;
49 static boolean map_option_f
;
50 static bfd_vma print_dot
;
51 static lang_input_statement_type
*first_file
;
52 static lang_statement_list_type lang_output_section_statement
;
53 static CONST
char *current_target
;
54 static CONST
char *output_target
;
55 static size_t longest_section_name
= 8;
56 static asection common_section
;
57 static section_userdata_type common_section_userdata
;
58 static lang_statement_list_type statement_list
;
61 lang_statement_list_type
*stat_ptr
= &statement_list
;
62 lang_input_statement_type
*script_file
= 0;
63 boolean option_longmap
= false;
64 lang_statement_list_type file_chain
= {0};
65 CONST
char *entry_symbol
= 0;
66 bfd_size_type largest_section
= 0;
67 boolean lang_has_input_file
= false;
68 lang_output_section_statement_type
*create_object_symbols
= 0;
69 boolean had_output_filename
= false;
70 boolean lang_float_flag
= false;
72 extern char *default_target
;
74 extern unsigned int undefined_global_sym_count
;
75 extern char *current_file
;
76 extern bfd
*output_bfd
;
77 extern enum bfd_architecture ldfile_output_architecture
;
78 extern unsigned long ldfile_output_machine
;
79 extern char *ldfile_output_machine_name
;
80 extern ldsym_type
*symbol_head
;
81 extern unsigned int commons_pending
;
82 extern args_type command_line
;
83 extern ld_config_type config
;
84 extern boolean had_script
;
85 extern boolean write_map
;
91 #define cat(a,b) a/**/b
94 #define new_stat(x,y) (cat(x,_type)*) new_statement(cat(x,_enum), sizeof(cat(x,_type)),y)
96 #define outside_section_address(q) ( (q)->output_offset + (q)->output_section->vma)
98 #define outside_symbol_address(q) ((q)->value + outside_section_address(q->section))
101 DEFUN(print_size
,(value
),
104 printf("%5x", (unsigned)value
);
107 DEFUN(print_alignment
,(value
),
110 printf("2**%1u",value
);
113 DEFUN(print_fill
,(value
),
116 printf("%04x",(unsigned)value
);
121 DEFUN(print_section
,(name
),
122 CONST
char *CONST name
)
124 printf("%*s", -longest_section_name
, name
);
127 /*----------------------------------------------------------------------
128 lang_for_each_statement walks the parse tree and calls the provided
129 function for each node
133 DEFUN(lang_for_each_statement_worker
,(func
, s
),
135 lang_statement_union_type
*s
)
137 for (; s
!= (lang_statement_union_type
*)NULL
; s
= s
->next
)
141 switch (s
->header
.type
) {
142 case lang_output_section_statement_enum
:
143 lang_for_each_statement_worker
145 s
->output_section_statement
.children
.head
);
147 case lang_wild_statement_enum
:
148 lang_for_each_statement_worker
150 s
->wild_statement
.children
.head
);
152 case lang_data_statement_enum
:
153 case lang_object_symbols_statement_enum
:
154 case lang_output_statement_enum
:
155 case lang_target_statement_enum
:
156 case lang_input_section_enum
:
157 case lang_input_statement_enum
:
158 case lang_fill_statement_enum
:
159 case lang_assignment_statement_enum
:
160 case lang_padding_statement_enum
:
161 case lang_address_statement_enum
:
171 DEFUN(lang_for_each_statement
,(func
),
174 lang_for_each_statement_worker(func
,
175 statement_list
.head
);
177 /*----------------------------------------------------------------------*/
179 DEFUN(lang_list_init
,(list
),
180 lang_statement_list_type
*list
)
182 list
->head
= (lang_statement_union_type
*)NULL
;
183 list
->tail
= &list
->head
;
187 /*----------------------------------------------------------------------
189 build a new statement node for the parse tree
194 lang_statement_union_type
*
195 DEFUN(new_statement
,(type
, size
, list
),
196 enum statement_enum type AND
197 bfd_size_type size AND
198 lang_statement_list_type
*list
)
200 lang_statement_union_type
*new = (lang_statement_union_type
*)
202 new->header
.type
= type
;
203 new->header
.next
= (lang_statement_union_type
*)NULL
;
204 lang_statement_append(list
, new, &new->header
.next
);
209 Build a new input file node for the language. There are several ways
210 in which we treat an input file, eg, we only look at symbols, or
211 prefix it with a -l etc.
213 We can be supplied with requests for input files more than once;
214 they may, for example be split over serveral lines like foo.o(.text)
215 foo.o(.data) etc, so when asked for a file we check that we havn't
216 got it already so we don't duplicate the bfd.
219 static lang_input_statement_type
*
220 DEFUN(new_afile
, (name
, file_type
, target
),
221 CONST
char *CONST name AND
222 CONST lang_input_file_enum_type file_type AND
223 CONST
char *CONST target
)
225 lang_input_statement_type
*p
= new_stat(lang_input_statement
,
227 lang_has_input_file
= true;
230 case lang_input_file_is_symbols_only_enum
:
232 p
->is_archive
=false;
234 p
->local_sym_name
= name
;
235 p
->just_syms_flag
= true;
236 p
->search_dirs_flag
= false;
238 case lang_input_file_is_fake_enum
:
240 p
->is_archive
=false;
242 p
->local_sym_name
= name
;
243 p
->just_syms_flag
= false;
244 p
->search_dirs_flag
=false;
246 case lang_input_file_is_l_enum
:
247 p
->is_archive
= true;
250 p
->local_sym_name
= concat("-l",name
,"");
251 p
->just_syms_flag
= false;
252 p
->search_dirs_flag
= true;
254 case lang_input_file_is_search_file_enum
:
255 case lang_input_file_is_marker_enum
:
257 p
->is_archive
=false;
259 p
->local_sym_name
= name
;
260 p
->just_syms_flag
= false;
261 p
->search_dirs_flag
=true;
263 case lang_input_file_is_file_enum
:
265 p
->is_archive
=false;
267 p
->local_sym_name
= name
;
268 p
->just_syms_flag
= false;
269 p
->search_dirs_flag
=false;
274 p
->asymbols
= (asymbol
**)NULL
;
275 p
->superfile
= (lang_input_statement_type
*)NULL
;
276 p
->next_real_file
= (lang_statement_union_type
*)NULL
;
277 p
->next
= (lang_statement_union_type
*)NULL
;
279 p
->common_output_section
= (asection
*)NULL
;
280 lang_statement_append(&input_file_chain
,
281 (lang_statement_union_type
*)p
,
288 lang_input_statement_type
*
289 DEFUN(lang_add_input_file
,(name
, file_type
, target
),
291 lang_input_file_enum_type file_type AND
294 /* Look it up or build a new one */
295 lang_has_input_file
= true;
297 lang_input_statement_type
*p
;
299 for (p
= (lang_input_statement_type
*)input_file_chain
.head
;
300 p
!= (lang_input_statement_type
*)NULL
;
301 p
= (lang_input_statement_type
*)(p
->next_real_file
))
303 /* Sometimes we have incomplete entries in here */
304 if (p
->filename
!= (char *)NULL
) {
305 if(strcmp(name
,p
->filename
) == 0) return p
;
310 return new_afile(name
, file_type
, target
);
314 /* Build enough state so that the parser can build its tree */
316 DEFUN_VOID(lang_init
)
319 stat_ptr
= &statement_list
;
320 lang_list_init(stat_ptr
);
322 lang_list_init(&input_file_chain
);
323 lang_list_init(&lang_output_section_statement
);
324 lang_list_init(&file_chain
);
325 first_file
= lang_add_input_file((char *)NULL
,
326 lang_input_file_is_marker_enum
,
331 /*----------------------------------------------------------------------
332 A region is an area of memory declared with the
333 MEMORY { name:org=exp, len=exp ... }
336 We maintain a list of all the regions here
338 If no regions are specified in the script, then the default is used
339 which is created when looked up to be the entire data space
342 static lang_memory_region_type
*lang_memory_region_list
;
343 static lang_memory_region_type
**lang_memory_region_list_tail
= &lang_memory_region_list
;
345 lang_memory_region_type
*
346 DEFUN(lang_memory_region_lookup
,(name
),
347 CONST
char *CONST name
)
350 lang_memory_region_type
*p
= lang_memory_region_list
;
351 for (p
= lang_memory_region_list
;
352 p
!= ( lang_memory_region_type
*)NULL
;
354 if (strcmp(p
->name
, name
) == 0) {
358 if (strcmp(name
,"*default*")==0) {
359 /* This is the default region, dig out first one on the list */
360 if (lang_memory_region_list
!= (lang_memory_region_type
*)NULL
){
361 return lang_memory_region_list
;
365 lang_memory_region_type
*new =
366 (lang_memory_region_type
*)ldmalloc((bfd_size_type
)(sizeof(lang_memory_region_type
)));
367 new->name
= buystring(name
);
368 new->next
= (lang_memory_region_type
*)NULL
;
370 *lang_memory_region_list_tail
= new;
371 lang_memory_region_list_tail
= &new->next
;
380 lang_output_section_statement_type
*
381 DEFUN(lang_output_section_find
,(name
),
382 CONST
char * CONST name
)
384 lang_statement_union_type
*u
;
385 lang_output_section_statement_type
*lookup
;
387 for (u
= lang_output_section_statement
.head
;
388 u
!= (lang_statement_union_type
*)NULL
;
391 lookup
= &u
->output_section_statement
;
392 if (strcmp(name
, lookup
->name
)==0) {
396 return (lang_output_section_statement_type
*)NULL
;
399 lang_output_section_statement_type
*
400 DEFUN(lang_output_section_statement_lookup
,(name
),
401 CONST
char * CONST name
)
403 lang_output_section_statement_type
*lookup
;
404 lookup
=lang_output_section_find(name
);
405 if (lookup
== (lang_output_section_statement_type
*)NULL
) {
407 lookup
=(lang_output_section_statement_type
*)
408 new_stat(lang_output_section_statement
, stat_ptr
);
409 lookup
->region
= (lang_memory_region_type
*)NULL
;
411 lookup
->block_value
= 1;
414 lookup
->next
= (lang_statement_union_type
*)NULL
;
415 lookup
->bfd_section
= (asection
*)NULL
;
416 lookup
->processed
= false;
417 lookup
->addr_tree
= (etree_type
*)NULL
;
418 lang_list_init(&lookup
->children
);
420 lang_statement_append(&lang_output_section_statement
,
421 (lang_statement_union_type
*)lookup
,
432 DEFUN(print_flags
, (outfile
, ignore_flags
),
436 fprintf(outfile
,"(");
438 if (flags
->flag_read
) fprintf(outfile
,"R");
439 if (flags
->flag_write
) fprintf(outfile
,"W");
440 if (flags
->flag_executable
) fprintf(outfile
,"X");
441 if (flags
->flag_loadable
) fprintf(outfile
,"L");
443 fprintf(outfile
,")");
447 DEFUN(lang_map
,(outfile
),
450 lang_memory_region_type
*m
;
451 fprintf(outfile
,"**MEMORY CONFIGURATION**\n\n");
453 fprintf(outfile
,"name\t\torigin\t\tlength\t\tattributes\n");
455 fprintf(outfile
,"name\t\torigin length\t\tattributes\n");
457 for (m
= lang_memory_region_list
;
458 m
!= (lang_memory_region_type
*)NULL
;
461 fprintf(outfile
,"%-16s", m
->name
);
462 print_address(m
->origin
);
464 print_address(m
->length
);
466 print_flags(outfile
, &m
->flags
);
467 fprintf(outfile
,"\n");
469 fprintf(outfile
,"\n\n**LINK EDITOR MEMORY MAP**\n\n");
470 fprintf(outfile
,"output input virtual\n");
471 fprintf(outfile
,"section section address tsize\n\n");
482 lang_output_section_statement_type
*s
)
484 section_userdata_type
*new =
485 (section_userdata_type
*)
486 ldmalloc((bfd_size_type
)(sizeof(section_userdata_type
)));
488 s
->bfd_section
= bfd_make_section(output_bfd
, s
->name
);
489 if (s
->bfd_section
== (asection
*)NULL
) {
490 info("%P%F output format %s cannot represent section called %s\n",
491 output_bfd
->xvec
->name
,
494 s
->bfd_section
->output_section
= s
->bfd_section
;
495 /* s->bfd_section->flags = s->flags;*/
497 /* We initialize an output sections output offset to minus its own */
498 /* vma to allow us to output a section through itself */
499 s
->bfd_section
->output_offset
= 0;
500 get_userdata( s
->bfd_section
) = (PTR
)new;
503 /***********************************************************************
506 These expand statements like *(.text) and foo.o to a list of
507 explicit actions, like foo.o(.text), bar.o(.text) and
510 The toplevel routine, wild, takes a statement, section, file and
511 target. If either the section or file is null it is taken to be the
512 wildcard. Seperate lang_input_section statements are created for
513 each part of the expanstion, and placed after the statement provided.
518 DEFUN(wild_doit
,(ptr
, section
, output
, file
),
519 lang_statement_list_type
*ptr AND
520 asection
*section AND
521 lang_output_section_statement_type
*output AND
522 lang_input_statement_type
*file
)
524 if(output
->bfd_section
== (asection
*)NULL
)
529 if (section
!= (asection
*)NULL
530 && section
->output_section
== (asection
*)NULL
) {
531 /* Add a section reference to the list */
532 lang_input_section_type
*new = new_stat(lang_input_section
, ptr
);
534 new->section
= section
;
536 section
->output_section
= output
->bfd_section
;
537 section
->output_section
->flags
|= section
->flags
;
538 if (section
->alignment_power
> output
->bfd_section
->alignment_power
) {
539 output
->bfd_section
->alignment_power
= section
->alignment_power
;
545 DEFUN(our_bfd_get_section_by_name
,(abfd
, section
),
549 return bfd_get_section_by_name(abfd
, section
);
553 DEFUN(wild_section
,(ptr
, section
, file
, output
),
554 lang_wild_statement_type
*ptr AND
555 CONST
char *section AND
556 lang_input_statement_type
*file AND
557 lang_output_section_statement_type
*output
)
560 if (file
->just_syms_flag
== false) {
561 if (section
== (char *)NULL
) {
562 /* Do the creation to all sections in the file */
563 for (s
= file
->the_bfd
->sections
; s
!= (asection
*)NULL
; s
=s
->next
) {
564 wild_doit(&ptr
->children
, s
, output
, file
);
568 /* Do the creation to the named section only */
569 wild_doit(&ptr
->children
,
570 our_bfd_get_section_by_name(file
->the_bfd
, section
),
577 /* passed a file name (which must have been seen already and added to
578 the statement tree. We will see if it has been opened already and
579 had its symbols read. If not then we'll read it.
581 Archives are pecuilar here. We may open them once, but if they do
582 not define anything we need at the time, they won't have all their
583 symbols read. If we need them later, we'll have to redo it.
586 lang_input_statement_type
*
587 DEFUN(lookup_name
,(name
),
588 CONST
char * CONST name
)
590 lang_input_statement_type
*search
;
591 for(search
= (lang_input_statement_type
*)input_file_chain
.head
;
592 search
!= (lang_input_statement_type
*)NULL
;
593 search
= (lang_input_statement_type
*)search
->next_real_file
)
595 if (search
->filename
== (char *)NULL
&& name
== (char *)NULL
) {
598 if (search
->filename
!= (char *)NULL
&& name
!= (char *)NULL
) {
599 if (strcmp(search
->filename
, name
) == 0) {
600 ldmain_open_file_read_symbol(search
);
606 /* There isn't an afile entry for this file yet, this must be
607 because the name has only appeared inside a load script and not
608 on the command line */
609 search
= new_afile(name
, lang_input_file_is_file_enum
, default_target
);
610 ldmain_open_file_read_symbol(search
);
617 DEFUN(wild
,(s
, section
, file
, target
, output
),
618 lang_wild_statement_type
*s AND
619 CONST
char *CONST section AND
620 CONST
char *CONST file AND
621 CONST
char *CONST target AND
622 lang_output_section_statement_type
*output
)
624 lang_input_statement_type
*f
;
625 if (file
== (char *)NULL
) {
626 /* Perform the iteration over all files in the list */
627 for (f
= (lang_input_statement_type
*)file_chain
.head
;
628 f
!= (lang_input_statement_type
*)NULL
;
629 f
= (lang_input_statement_type
*)f
->next
) {
630 wild_section(s
, section
, f
, output
);
634 /* Perform the iteration over a single file */
635 wild_section( s
, section
, lookup_name(file
), output
);
637 if (section
!= (char *)NULL
638 && strcmp(section
,"COMMON") == 0
639 && default_common_section
== (lang_output_section_statement_type
*)NULL
)
641 /* Remember the section that common is going to incase we later
642 get something which doesn't know where to put it */
643 default_common_section
= output
;
648 read in all the files
651 DEFUN(open_output
,(name
),
652 CONST
char *CONST name
)
654 extern CONST
char *output_filename
;
656 if (output_target
== (char *)NULL
) {
657 if (current_target
!= (char *)NULL
)
658 output_target
= current_target
;
660 output_target
= default_target
;
662 output
= bfd_openw(name
, output_target
);
663 output_filename
= name
;
665 if (output
== (bfd
*)NULL
)
667 if (bfd_error
== invalid_target
) {
668 info("%P%F target %s not found\n", output_target
);
670 info("%P%F problem opening output file %s, %E", name
);
673 output
->flags
|= D_PAGED
;
674 bfd_set_format(output
, bfd_object
);
682 DEFUN(ldlang_open_output
,(statement
),
683 lang_statement_union_type
*statement
)
685 switch (statement
->header
.type
)
687 case lang_output_statement_enum
:
688 output_bfd
= open_output(statement
->output_statement
.name
);
689 ldemul_set_output_arch();
692 case lang_target_statement_enum
:
693 current_target
= statement
->target_statement
.target
;
701 DEFUN(open_input_bfds
,(statement
),
702 lang_statement_union_type
*statement
)
704 switch (statement
->header
.type
)
706 case lang_target_statement_enum
:
707 current_target
= statement
->target_statement
.target
;
709 case lang_wild_statement_enum
:
710 /* Maybe we should load the file's symbols */
711 if (statement
->wild_statement
.filename
)
713 (void) lookup_name(statement
->wild_statement
.filename
);
716 case lang_input_statement_enum
:
717 if (statement
->input_statement
.real
== true)
719 statement
->input_statement
.target
= current_target
;
720 lookup_name(statement
->input_statement
.filename
);
727 /* If there are [COMMONS] statements, put a wild one into the bss section */
730 lang_reasonable_defaults()
733 lang_output_section_statement_lookup(".text");
734 lang_output_section_statement_lookup(".data");
736 default_common_section
=
737 lang_output_section_statement_lookup(".bss");
740 if (placed_commons
== false) {
741 lang_wild_statement_type
*new =
742 new_stat(lang_wild_statement
,
743 &default_common_section
->children
);
744 new->section_name
= "COMMON";
745 new->filename
= (char *)NULL
;
746 lang_list_init(&new->children
);
753 Add the supplied name to the symbol table as an undefined reference.
754 Remove items from the chain as we open input bfds
756 typedef struct ldlang_undef_chain_list_struct
{
757 struct ldlang_undef_chain_list_struct
*next
;
759 } ldlang_undef_chain_list_type
;
761 static ldlang_undef_chain_list_type
*ldlang_undef_chain_list_head
;
764 DEFUN(ldlang_add_undef
,(name
),
765 CONST
char *CONST name
)
767 ldlang_undef_chain_list_type
*new =
768 (ldlang_undef_chain_list_type
769 *)ldmalloc((bfd_size_type
)(sizeof(ldlang_undef_chain_list_type
)));
771 new->next
= ldlang_undef_chain_list_head
;
772 ldlang_undef_chain_list_head
= new;
774 new->name
= buystring(name
);
776 /* Run through the list of undefineds created above and place them
777 into the linker hash table as undefined symbols belonging to the
781 DEFUN_VOID(lang_place_undefineds
)
783 ldlang_undef_chain_list_type
*ptr
= ldlang_undef_chain_list_head
;
784 while (ptr
!= (ldlang_undef_chain_list_type
*)NULL
) {
785 ldsym_type
*sy
= ldsym_get(ptr
->name
);
787 asymbol
**def_ptr
= (asymbol
**)ldmalloc((bfd_size_type
)(sizeof(asymbol
**)));
788 def
= (asymbol
*)bfd_make_empty_symbol(script_file
->the_bfd
);
790 def
->name
= ptr
->name
;
791 def
->flags
= BSF_UNDEFINED
;
792 def
->section
= (asection
*)NULL
;
793 Q_enter_global_ref(def_ptr
);
800 /* Copy important data from out internal form to the bfd way. Also
801 create a section for the dummy file
805 DEFUN_VOID(lang_create_output_section_statements
)
807 lang_statement_union_type
*os
;
808 for (os
= lang_output_section_statement
.head
;
809 os
!= (lang_statement_union_type
*)NULL
;
810 os
= os
->output_section_statement
.next
) {
811 lang_output_section_statement_type
*s
=
812 &os
->output_section_statement
;
819 DEFUN_VOID(lang_init_script_file
)
821 script_file
= lang_add_input_file("script file",
822 lang_input_file_is_fake_enum
,
824 script_file
->the_bfd
= bfd_create("script file", output_bfd
);
825 script_file
->symbol_count
= 0;
826 script_file
->the_bfd
->sections
= output_bfd
->sections
;
832 /* Open input files and attatch to output sections */
834 DEFUN(map_input_to_output_sections
,(s
, target
, output_section_statement
),
835 lang_statement_union_type
*s AND
836 CONST
char *target AND
837 lang_output_section_statement_type
*output_section_statement
)
839 for (; s
!= (lang_statement_union_type
*)NULL
; s
= s
->next
)
841 switch (s
->header
.type
) {
842 case lang_wild_statement_enum
:
843 wild(&s
->wild_statement
, s
->wild_statement
.section_name
,
844 s
->wild_statement
.filename
, target
,
845 output_section_statement
);
849 case lang_output_section_statement_enum
:
850 map_input_to_output_sections(s
->output_section_statement
.children
.head
,
852 &s
->output_section_statement
);
854 case lang_output_statement_enum
:
856 case lang_target_statement_enum
:
857 target
= s
->target_statement
.target
;
859 case lang_fill_statement_enum
:
860 case lang_input_section_enum
:
861 case lang_object_symbols_statement_enum
:
862 case lang_data_statement_enum
:
863 case lang_assignment_statement_enum
:
864 case lang_padding_statement_enum
:
866 case lang_afile_asection_pair_statement_enum
:
869 case lang_address_statement_enum
:
870 /* Mark the specified section with the supplied address */
872 lang_output_section_statement_type
*os
=
873 lang_output_section_statement_lookup
874 (s
->address_statement
.section_name
);
875 os
->addr_tree
= s
->address_statement
.address
;
876 if (os
->bfd_section
== (asection
*)NULL
) {
877 info("%P%F can't set the address of undefined section %s\n",
878 s
->address_statement
.section_name
);
882 case lang_input_statement_enum
:
883 /* A standard input statement, has no wildcards */
884 /* ldmain_open_file_read_symbol(&s->input_statement);*/
895 DEFUN(print_output_section_statement
,(output_section_statement
),
896 lang_output_section_statement_type
*output_section_statement
)
898 asection
*section
= output_section_statement
->bfd_section
;
900 print_section(output_section_statement
->name
);
903 print_dot
= section
->vma
;
907 print_address(section
->vma
);
909 print_size(section
->size
);
911 print_alignment(section
->alignment_power
);
914 printf("%s flags", output_section_statement
->region
->name
);
915 print_flags(stdout
, &output_section_statement
->flags
);
917 if (section
->flags
& SEC_LOAD
)
919 if (section
->flags
& SEC_ALLOC
)
921 if (section
->flags
& SEC_RELOC
)
923 if (section
->flags
& SEC_HAS_CONTENTS
)
928 printf("No attached output section");
931 print_statement(output_section_statement
->children
.head
,
932 output_section_statement
);
937 DEFUN(print_assignment
,(assignment
, output_section
),
938 lang_assignment_statement_type
*assignment AND
939 lang_output_section_statement_type
*output_section
)
941 etree_value_type result
;
946 print_address(print_dot
);
948 result
= exp_fold_tree(assignment
->exp
->assign
.src
,
950 lang_final_phase_enum
,
955 print_address(result
.value
);
959 printf("*undefined*");
962 exp_print_tree(stdout
, assignment
->exp
);
967 DEFUN(print_input_statement
,(statm
),
968 lang_input_statement_type
*statm
)
970 if (statm
->filename
!= (char *)NULL
) {
971 printf("LOAD %s\n",statm
->filename
);
976 DEFUN(print_symbol
,(q
),
983 print_address(outside_symbol_address(q
));
984 printf(" %s", q
->name
? q
->name
: " ");
989 DEFUN(print_input_section
,(in
),
990 lang_input_section_type
*in
)
992 asection
*i
= in
->section
;
997 print_section(i
->name
);
999 if (i
->output_section
) {
1000 print_address(i
->output_section
->vma
+ i
->output_offset
);
1002 print_size(i
->size
);
1004 print_alignment(i
->alignment_power
);
1008 bfd
*abfd
= in
->ifile
->the_bfd
;
1009 if (in
->ifile
->just_syms_flag
== true) {
1010 printf("symbols only ");
1013 printf(" %s ",abfd
->xvec
->name
);
1014 if(abfd
->my_archive
!= (bfd
*)NULL
) {
1015 printf("[%s]%s", abfd
->my_archive
->filename
,
1019 printf("%s", abfd
->filename
);
1021 printf("(overhead %d bytes)", (int)bfd_alloc_size(abfd
));
1024 /* Find all the symbols in this file defined in this section */
1027 for (p
= in
->ifile
->asymbols
; *p
; p
++) {
1030 if (bfd_get_section(q
) == i
&& q
->flags
& BSF_GLOBAL
) {
1041 print_dot
= outside_section_address(i
) + i
->size
;
1044 printf("No output section allocated\n");
1050 DEFUN(print_fill_statement
,(fill
),
1051 lang_fill_statement_type
*fill
)
1053 printf("FILL mask ");
1054 print_fill( fill
->fill
);
1058 DEFUN(print_data_statement
,(data
),
1059 lang_data_statement_type
*data
)
1061 /* bfd_vma value; */
1066 /* ASSERT(print_dot == data->output_vma);*/
1068 print_address(data
->output_vma
);
1070 print_address(data
->value
);
1072 switch (data
->type
) {
1075 print_dot
+= BYTE_SIZE
;
1079 print_dot
+= SHORT_SIZE
;
1083 print_dot
+= LONG_SIZE
;
1087 exp_print_tree(stdout
, data
->exp
);
1094 DEFUN(print_padding_statement
,(s
),
1095 lang_padding_statement_type
*s
)
1099 print_section("*fill*");
1101 print_address(s
->output_offset
+ s
->output_section
->vma
);
1103 print_size(s
->size
);
1105 print_fill(s
->fill
);
1110 DEFUN(print_wild_statement
,(w
,os
),
1111 lang_wild_statement_type
*w AND
1112 lang_output_section_statement_type
*os
)
1115 if (w
->filename
!= (char *)NULL
) {
1116 printf("%s",w
->filename
);
1121 if (w
->section_name
!= (char *)NULL
) {
1122 printf("(%s)",w
->section_name
);
1128 print_statement(w
->children
.head
, os
);
1132 DEFUN(print_statement
,(s
, os
),
1133 lang_statement_union_type
*s AND
1134 lang_output_section_statement_type
*os
)
1137 switch (s
->header
.type
) {
1138 case lang_wild_statement_enum
:
1139 print_wild_statement(&s
->wild_statement
, os
);
1142 printf("Fail with %d\n",s
->header
.type
);
1145 case lang_address_statement_enum
:
1146 printf("address\n");
1149 case lang_object_symbols_statement_enum
:
1150 printf("object symbols\n");
1152 case lang_fill_statement_enum
:
1153 print_fill_statement(&s
->fill_statement
);
1155 case lang_data_statement_enum
:
1156 print_data_statement(&s
->data_statement
);
1158 case lang_input_section_enum
:
1159 print_input_section(&s
->input_section
);
1161 case lang_padding_statement_enum
:
1162 print_padding_statement(&s
->padding_statement
);
1164 case lang_output_section_statement_enum
:
1165 print_output_section_statement(&s
->output_section_statement
);
1167 case lang_assignment_statement_enum
:
1168 print_assignment(&s
->assignment_statement
,
1173 case lang_target_statement_enum
:
1174 printf("TARGET(%s)\n", s
->target_statement
.target
);
1176 case lang_output_statement_enum
:
1177 printf("OUTPUT(%s %s)\n",
1178 s
->output_statement
.name
,
1181 case lang_input_statement_enum
:
1182 print_input_statement(&s
->input_statement
);
1184 case lang_afile_asection_pair_statement_enum
:
1194 DEFUN_VOID(print_statements
)
1196 print_statement(statement_list
.head
,
1197 (lang_output_section_statement_type
*)NULL
);
1201 DEFUN(insert_pad
,(this_ptr
, fill
, power
, output_section_statement
, dot
),
1202 lang_statement_union_type
**this_ptr AND
1204 unsigned int power AND
1205 asection
* output_section_statement AND
1208 /* Align this section first to the
1209 input sections requirement, then
1210 to the output section's requirement.
1211 If this alignment is > than any seen before,
1212 then record it too. Perform the alignment by
1213 inserting a magic 'padding' statement.
1216 unsigned int alignment_needed
= align_power(dot
, power
) - dot
;
1218 if (alignment_needed
!= 0)
1220 lang_statement_union_type
*new =
1221 (lang_statement_union_type
*)
1222 ldmalloc((bfd_size_type
)(sizeof(lang_padding_statement_type
)));
1223 /* Link into existing chain */
1224 new->header
.next
= *this_ptr
;
1226 new->header
.type
= lang_padding_statement_enum
;
1227 new->padding_statement
.output_section
= output_section_statement
;
1228 new->padding_statement
.output_offset
=
1229 dot
- output_section_statement
->vma
;
1230 new->padding_statement
.fill
= fill
;
1231 new->padding_statement
.size
= alignment_needed
;
1235 /* Remember the most restrictive alignment */
1236 if (power
> output_section_statement
->alignment_power
) {
1237 output_section_statement
->alignment_power
= power
;
1239 output_section_statement
->size
+= alignment_needed
;
1240 return alignment_needed
+ dot
;
1244 /* Work out how much this section will move the dot point */
1246 DEFUN(size_input_section
, (this_ptr
, output_section_statement
, fill
, dot
),
1247 lang_statement_union_type
**this_ptr AND
1248 lang_output_section_statement_type
*output_section_statement AND
1249 unsigned short fill AND
1252 lang_input_section_type
*is
= &((*this_ptr
)->input_section
);
1253 asection
*i
= is
->section
;
1255 if (is
->ifile
->just_syms_flag
== false) {
1256 dot
= insert_pad(this_ptr
, fill
, i
->alignment_power
,
1257 output_section_statement
->bfd_section
, dot
);
1259 /* remember the largest size so we can malloc the largest area
1260 needed for the output stage. Only remember the size of sections
1261 which we will actually allocate */
1263 (SEC_HAS_CONTENTS
| SEC_LOAD
)) == (SEC_HAS_CONTENTS
| SEC_LOAD
))
1264 && (i
->size
> largest_section
)) {
1265 largest_section
= i
->size
;
1268 /* Remember where in the output section this input section goes */
1270 i
->output_offset
= dot
- output_section_statement
->bfd_section
->vma
;
1272 /* Mark how big the output section must be to contain this now */
1274 output_section_statement
->bfd_section
->size
=
1275 dot
- output_section_statement
->bfd_section
->vma
;
1279 i
->output_offset
= i
->vma
- output_section_statement
->bfd_section
->vma
;
1286 /* Work out the size of the output sections
1287 from the sizes of the input sections */
1289 DEFUN(lang_size_sections
,(s
, output_section_statement
, prev
, fill
, dot
),
1290 lang_statement_union_type
*s AND
1291 lang_output_section_statement_type
* output_section_statement AND
1292 lang_statement_union_type
**prev AND
1293 unsigned short fill AND
1296 /* Size up the sections from their constituent parts */
1297 for (; s
!= (lang_statement_union_type
*)NULL
; s
= s
->next
)
1299 switch (s
->header
.type
) {
1300 case lang_output_section_statement_enum
:
1303 lang_output_section_statement_type
*os
=
1304 &(s
->output_section_statement
);
1305 /* The start of a section */
1307 if (os
->addr_tree
== (etree_type
*)NULL
) {
1308 /* No address specified for this section, get one
1309 from the region specification
1311 if (os
->region
== (lang_memory_region_type
*)NULL
) {
1312 os
->region
= lang_memory_region_lookup("*default*");
1314 dot
= os
->region
->current
;
1317 etree_value_type r
;
1318 r
= exp_fold_tree(os
->addr_tree
,
1319 (lang_output_section_statement_type
*)NULL
,
1320 lang_allocating_phase_enum
,
1322 if (r
.valid
== false) {
1323 info("%F%S: non constant address expression for section %s\n",
1328 /* The section starts here */
1329 /* First, align to what the section needs */
1331 dot
= align_power(dot
, os
->bfd_section
->alignment_power
);
1332 os
->bfd_section
->vma
= dot
;
1333 os
->bfd_section
->output_offset
= 0;
1335 (void) lang_size_sections(os
->children
.head
, os
, &os
->children
.head
,
1337 /* Ignore the size of the input sections, use the vma and size to */
1341 after
= ALIGN(os
->bfd_section
->vma
+
1342 os
->bfd_section
->size
,
1346 os
->bfd_section
->size
= after
- os
->bfd_section
->vma
;
1347 dot
= os
->bfd_section
->vma
+ os
->bfd_section
->size
;
1348 os
->processed
= true;
1350 /* Replace into region ? */
1351 if (os
->addr_tree
== (etree_type
*)NULL
1352 && os
->region
!=(lang_memory_region_type
*)NULL
) {
1353 os
->region
->current
= dot
;
1359 case lang_data_statement_enum
:
1362 s
->data_statement
.output_vma
= dot
- output_section_statement
->bfd_section
->vma
;
1363 s
->data_statement
.output_section
=
1364 output_section_statement
->bfd_section
;
1366 switch (s
->data_statement
.type
) {
1379 output_section_statement
->bfd_section
->size
+= size
;
1383 case lang_wild_statement_enum
:
1385 dot
= lang_size_sections(s
->wild_statement
.children
.head
,
1386 output_section_statement
,
1387 &s
->wild_statement
.children
.head
,
1393 case lang_object_symbols_statement_enum
:
1394 create_object_symbols
= output_section_statement
;
1396 case lang_output_statement_enum
:
1397 case lang_target_statement_enum
:
1399 case lang_input_section_enum
:
1400 dot
= size_input_section(prev
,
1401 output_section_statement
,
1402 output_section_statement
->fill
, dot
);
1404 case lang_input_statement_enum
:
1406 case lang_fill_statement_enum
:
1407 fill
= s
->fill_statement
.fill
;
1409 case lang_assignment_statement_enum
:
1411 bfd_vma newdot
= dot
;
1412 exp_fold_tree(s
->assignment_statement
.exp
,
1413 output_section_statement
,
1414 lang_allocating_phase_enum
,
1419 /* We've been moved ! so insert a pad */
1421 lang_statement_union_type
*new =
1422 (lang_statement_union_type
*)
1423 ldmalloc((bfd_size_type
)(sizeof(lang_padding_statement_type
)));
1424 /* Link into existing chain */
1425 new->header
.next
= *prev
;
1427 new->header
.type
= lang_padding_statement_enum
;
1428 new->padding_statement
.output_section
=
1429 output_section_statement
->bfd_section
;
1430 new->padding_statement
.output_offset
=
1431 dot
- output_section_statement
->bfd_section
->vma
;
1432 new->padding_statement
.fill
= fill
;
1433 new->padding_statement
.size
= newdot
- dot
;
1434 output_section_statement
->bfd_section
->size
+=
1435 new->padding_statement
.size
;
1441 case lang_padding_statement_enum
:
1447 case lang_address_statement_enum
:
1450 prev
= &s
->header
.next
;
1457 DEFUN(lang_do_assignments
,(s
, output_section_statement
, fill
, dot
),
1458 lang_statement_union_type
*s AND
1459 lang_output_section_statement_type
* output_section_statement AND
1460 unsigned short fill AND
1464 for (; s
!= (lang_statement_union_type
*)NULL
; s
= s
->next
)
1466 switch (s
->header
.type
) {
1467 case lang_output_section_statement_enum
:
1469 lang_output_section_statement_type
*os
=
1470 &(s
->output_section_statement
);
1471 dot
= os
->bfd_section
->vma
;
1472 (void) lang_do_assignments(os
->children
.head
, os
, os
->fill
, dot
);
1473 dot
= os
->bfd_section
->vma
+ os
->bfd_section
->size
;
1476 case lang_wild_statement_enum
:
1478 dot
= lang_do_assignments(s
->wild_statement
.children
.head
,
1479 output_section_statement
,
1484 case lang_object_symbols_statement_enum
:
1485 case lang_output_statement_enum
:
1486 case lang_target_statement_enum
:
1488 case lang_common_statement_enum
:
1491 case lang_data_statement_enum
:
1493 etree_value_type value
;
1494 value
= exp_fold_tree(s
->data_statement
.exp
,
1495 0, lang_final_phase_enum
, dot
, &dot
);
1496 s
->data_statement
.value
= value
.value
;
1497 if (value
.valid
== false) info("%F%P: Invalid data statement\n");
1499 switch (s
->data_statement
.type
) {
1511 case lang_input_section_enum
:
1513 asection
*in
= s
->input_section
.section
;
1518 case lang_input_statement_enum
:
1520 case lang_fill_statement_enum
:
1521 fill
= s
->fill_statement
.fill
;
1523 case lang_assignment_statement_enum
:
1525 exp_fold_tree(s
->assignment_statement
.exp
,
1526 output_section_statement
,
1527 lang_final_phase_enum
,
1533 case lang_padding_statement_enum
:
1534 dot
+= s
->padding_statement
.size
;
1539 case lang_address_statement_enum
:
1550 DEFUN_VOID(lang_relocate_globals
)
1554 Each ldsym_type maintains a chain of pointers to asymbols which
1555 references the definition. Replace each pointer to the referenence
1556 with a pointer to only one place, preferably the definition. If
1557 the defintion isn't available then the common symbol, and if
1558 there isn't one of them then choose one reference.
1561 FOR_EACH_LDSYM(lgs
) {
1563 if (lgs
->sdefs_chain
) {
1564 it
= *(lgs
->sdefs_chain
);
1566 else if (lgs
->scoms_chain
!= (asymbol
**)NULL
) {
1567 it
= *(lgs
->scoms_chain
);
1569 else if (lgs
->srefs_chain
!= (asymbol
**)NULL
) {
1570 it
= *(lgs
->srefs_chain
);
1573 /* This can happen when the command line asked for a symbol to
1575 it
= (asymbol
*)NULL
;
1577 if (it
!= (asymbol
*)NULL
)
1579 asymbol
**ptr
= lgs
->srefs_chain
;
1581 while (ptr
!= (asymbol
**)NULL
) {
1582 asymbol
*ref
= *ptr
;
1584 ptr
= (asymbol
**)(ref
->udata
);
1593 DEFUN_VOID(lang_finish
)
1597 if (entry_symbol
== (char *)NULL
) {
1598 /* No entry has been specified, look for start */
1599 entry_symbol
= "start";
1601 lgs
= ldsym_get_soft(entry_symbol
);
1602 if (lgs
&& lgs
->sdefs_chain
) {
1603 asymbol
*sy
= *(lgs
->sdefs_chain
);
1604 /* We can set the entry address*/
1605 bfd_set_start_address(output_bfd
,
1606 outside_symbol_address(sy
));
1610 /* Can't find anything reasonable,
1611 use the first address in the text section
1613 asection
*ts
= bfd_get_section_by_name(output_bfd
, ".text");
1615 bfd_set_start_address(output_bfd
, ts
->vma
);
1620 /* By now we know the target architecture, and we may have an */
1621 /* ldfile_output_machine_name */
1623 DEFUN_VOID(lang_check
)
1625 lang_statement_union_type
*file
;
1628 unsigned long input_machine
;
1629 enum bfd_architecture input_architecture
;
1630 char *out_arch
, *out_arch2
;
1633 for (file
= file_chain
.head
;
1634 file
!= (lang_statement_union_type
*)NULL
;
1635 file
=file
->input_statement
.next
)
1637 unsigned long ldfile_new_output_machine
;
1638 enum bfd_architecture ldfile_new_output_architecture
;
1640 input_bfd
= file
->input_statement
.the_bfd
;
1642 input_machine
= bfd_get_machine(input_bfd
);
1643 input_architecture
= bfd_get_architecture(input_bfd
);
1646 /* Inspect the architecture and ensure we're linking like with like */
1647 if (!bfd_arch_compatible(input_bfd
,
1649 &ldfile_new_output_architecture
,
1650 &ldfile_new_output_machine
))
1653 /* Result of bfd_printable_arch_mach is not guaranteed to stick
1654 around after next call, so we have to copy it. */
1655 out_arch
= bfd_printable_arch_mach(ldfile_output_architecture
,
1656 ldfile_output_machine
);
1657 out_arch2
= ldmalloc (strlen (out_arch
)+1);
1658 strcpy (out_arch2
, out_arch
);
1660 info("%P: warning, %s architecture of input file `%B' incompatible with %s output\n",
1661 bfd_printable_arch_mach(input_architecture
, input_machine
),
1667 bfd_set_arch_mach(output_bfd
,
1668 ldfile_new_output_architecture
,
1669 ldfile_new_output_machine
);
1677 * run through all the global common symbols and tie them
1678 * to the output section requested.
1680 As an experiment we do this 4 times, once for all the byte sizes,
1681 then all the two bytes, all the four bytes and then everything else
1685 DEFUN_VOID(lang_common
)
1689 if (config
.relocateable_output
== false ||
1690 command_line
.force_common_definition
== true) {
1691 for (power
= 1; (config
.sort_common
== true && power
== 1) || (power
<= 16); power
<<=1) {
1692 for (lgs
= symbol_head
;
1693 lgs
!= (ldsym_type
*)NULL
;
1697 unsigned int power_of_two
;
1700 if (lgs
->scoms_chain
!= (asymbol
**)NULL
) {
1701 com
= *(lgs
->scoms_chain
);
1730 if (config
.sort_common
== false || align
== power
) {
1731 /* Change from a common symbol into a definition of
1733 lgs
->sdefs_chain
= lgs
->scoms_chain
;
1734 lgs
->scoms_chain
= (asymbol
**)NULL
;
1736 /* Point to the correct common section */
1738 ((lang_input_statement_type
*)
1739 (com
->the_bfd
->usrdata
))->common_section
;
1740 /* Fix the size of the common section */
1741 com
->section
->size
= ALIGN(com
->section
->size
, align
);
1743 /* Remember if this is the biggest alignment ever seen */
1744 if (power_of_two
> com
->section
->alignment_power
) {
1745 com
->section
->alignment_power
= power_of_two
;
1748 /* Symbol stops being common and starts being global, but
1749 we remember that it was common once. */
1751 com
->flags
= BSF_EXPORT
| BSF_GLOBAL
| BSF_OLD_COMMON
;
1752 com
->value
= com
->section
->size
;
1756 printf ("Allocating common %s: %x at %x %s\n",
1759 (unsigned) com
->value
,
1760 com
->the_bfd
->filename
);
1763 com
->section
->size
+= size
;
1776 run through the input files and ensure that every input
1777 section has somewhere to go. If one is found without
1778 a destination then create an input request and place it
1779 into the statement tree.
1783 DEFUN_VOID(lang_place_orphans
)
1785 lang_input_statement_type
*file
;
1786 for (file
= (lang_input_statement_type
*)file_chain
.head
;
1787 file
!= (lang_input_statement_type
*)NULL
;
1788 file
= (lang_input_statement_type
*)file
->next
) {
1790 for (s
= file
->the_bfd
->sections
;
1791 s
!= (asection
*)NULL
;
1793 if ( s
->output_section
== (asection
*)NULL
) {
1794 /* This section of the file is not attatched, root
1795 around for a sensible place for it to go */
1797 if (file
->common_section
== s
) {
1798 /* This is a lonely common section which must
1799 have come from an archive. We attatch to the
1800 section with the wildcard */
1801 if (config
.relocateable_output
!= true
1802 && command_line
.force_common_definition
== false) {
1803 if (default_common_section
==
1804 (lang_output_section_statement_type
*)NULL
) {
1805 info("%P: No [COMMON] command, defaulting to .bss\n");
1807 default_common_section
=
1808 lang_output_section_statement_lookup(".bss");
1811 wild_doit(&default_common_section
->children
, s
,
1812 default_common_section
, file
);
1816 lang_output_section_statement_type
*os
=
1817 lang_output_section_statement_lookup(s
->name
);
1819 wild_doit(&os
->children
, s
, os
, file
);
1828 DEFUN(lang_set_flags
,(ptr
, flags
),
1832 boolean state
= true;
1836 if (*flags
== '!') {
1843 /* ptr->flag_read = state; */
1846 /* ptr->flag_write = state; */
1849 /* 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
,
1930 char *output_section_statement_name AND
1931 etree_type
*address_exp AND
1933 bfd_vma block_value
)
1935 lang_output_section_statement_type
*os
;
1938 lang_output_section_statement_lookup(output_section_statement_name
);
1941 /* Add this statement to tree */
1942 /* add_statement(lang_output_section_statement_enum,
1943 output_section_statement);*/
1944 /* Make next things chain into subchain of this */
1946 if (os
->addr_tree
==
1947 (etree_type
*)NULL
) {
1952 os
->block_value
= block_value
;
1953 stat_ptr
= & os
->children
;
1959 DEFUN_VOID(lang_final
)
1961 if (had_output_filename
== false) {
1962 extern CONST
char *output_filename
;
1963 lang_add_output(output_filename
);
1972 DEFUN(create_symbol
,(name
, flags
, section
),
1973 CONST
char *name AND
1977 extern lang_input_statement_type
*script_file
;
1978 asymbol
**def_ptr
= (asymbol
**)ldmalloc((bfd_size_type
)(sizeof(asymbol
**)));
1979 /* Add this definition to script file */
1980 asymbol
*def
= (asymbol
*)bfd_make_empty_symbol(script_file
->the_bfd
);
1981 def
->name
= buystring(name
);
1984 def
->section
= section
;
1987 Q_enter_global_ref(def_ptr
);
1993 DEFUN_VOID(lang_process
)
1995 if (had_script
== false) {
1996 parse_line(ldemul_get_script());
1998 lang_reasonable_defaults();
1999 current_target
= default_target
;
2001 lang_for_each_statement(ldlang_open_output
); /* Open the output file */
2002 /* For each output section statement, create a section in the output
2004 lang_create_output_section_statements();
2006 /* Create a dummy bfd for the script */
2007 lang_init_script_file();
2009 /* Add to the hash table all undefineds on the command line */
2010 lang_place_undefineds();
2012 /* Create a bfd for each input file */
2013 current_target
= default_target
;
2014 lang_for_each_statement(open_input_bfds
);
2016 common_section
.userdata
= (PTR
)&common_section_userdata
;
2018 /* Run through the contours of the script and attatch input sections
2019 to the correct output sections
2021 map_input_to_output_sections(statement_list
.head
, (char *)NULL
,
2022 ( lang_output_section_statement_type
*)NULL
);
2024 /* Find any sections not attatched explicitly and handle them */
2025 lang_place_orphans();
2027 /* Size up the common data */
2030 ldemul_before_allocation();
2032 /* Size up the sections */
2033 lang_size_sections(statement_list
.head
,
2034 (lang_output_section_statement_type
*)NULL
,
2035 &(statement_list
.head
), 0, (bfd_vma
)0);
2037 /* See if anything special should be done now we know how big
2039 ldemul_after_allocation();
2041 /* Do all the assignments, now that we know the final restingplaces
2042 of all the symbols */
2044 lang_do_assignments(statement_list
.head
,
2045 (lang_output_section_statement_type
*)NULL
,
2048 /* Make sure that we're not mixing architectures */
2052 /* Move the global symbols around */
2053 lang_relocate_globals();
2060 /* EXPORTED TO YACC */
2063 DEFUN(lang_add_wild
,(section_name
, filename
),
2064 CONST
char *CONST section_name AND
2065 CONST
char *CONST filename
)
2067 lang_wild_statement_type
*new = new_stat(lang_wild_statement
,
2070 if (section_name
!= (char *)NULL
&& strcmp(section_name
,"COMMON") == 0)
2072 placed_commons
= true;
2074 if (filename
!= (char *)NULL
) {
2075 lang_has_input_file
= true;
2077 new->section_name
= section_name
;
2078 new->filename
= filename
;
2079 lang_list_init(&new->children
);
2082 DEFUN(lang_section_start
,(name
, address
),
2083 CONST
char *name AND
2084 etree_type
*address
)
2086 lang_address_statement_type
*ad
=new_stat(lang_address_statement
, stat_ptr
);
2087 ad
->section_name
= name
;
2088 ad
->address
= address
;
2092 DEFUN(lang_add_entry
,(name
),
2095 entry_symbol
= name
;
2099 DEFUN(lang_add_target
,(name
),
2102 lang_target_statement_type
*new = new_stat(lang_target_statement
,
2112 DEFUN(lang_add_map
,(name
),
2118 map_option_f
= true;
2126 DEFUN(lang_add_fill
,(exp
),
2129 lang_fill_statement_type
*new = new_stat(lang_fill_statement
,
2135 DEFUN(lang_add_data
,(type
, exp
),
2137 union etree_union
*exp
)
2140 lang_data_statement_type
*new = new_stat(lang_data_statement
,
2147 DEFUN(lang_add_assignment
,(exp
),
2150 lang_assignment_statement_type
*new = new_stat(lang_assignment_statement
,
2156 DEFUN(lang_add_attribute
,(attribute
),
2157 enum statement_enum attribute
)
2159 new_statement(attribute
, sizeof(lang_statement_union_type
),stat_ptr
);
2165 DEFUN(lang_startup
,(name
),
2168 if (startup_file
!= (char *)NULL
) {
2169 info("%P%FMultiple STARTUP files\n");
2171 first_file
->filename
= name
;
2172 first_file
->local_sym_name
= name
;
2177 DEFUN(lang_float
,(maybe
),
2180 lang_float_flag
= maybe
;
2184 DEFUN(lang_leave_output_section_statement
,(fill
, memspec
),
2186 CONST
char *memspec
)
2188 current_section
->fill
= fill
;
2189 current_section
->region
= lang_memory_region_lookup(memspec
);
2190 stat_ptr
= &statement_list
;
2193 Create an absolute symbol with the given name with the value of the
2194 address of first byte of the section named.
2196 If the symbol already exists, then do nothing.
2199 DEFUN(lang_abs_symbol_at_beginning_of
,(section
, name
),
2200 CONST
char *section AND
2203 if (ldsym_undefined(name
)) {
2204 extern bfd
*output_bfd
;
2205 extern asymbol
*create_symbol();
2206 asection
*s
= bfd_get_section_by_name(output_bfd
, section
);
2207 asymbol
*def
= create_symbol(name
,
2208 BSF_GLOBAL
| BSF_EXPORT
|
2211 if (s
!= (asection
*)NULL
) {
2212 def
->value
= s
->vma
;
2221 Create an absolute symbol with the given name with the value of the
2222 address of the first byte after the end of the section named.
2224 If the symbol already exists, then do nothing.
2227 DEFUN(lang_abs_symbol_at_end_of
,(section
, name
),
2228 CONST
char *section AND
2231 if (ldsym_undefined(name
)){
2232 extern bfd
*output_bfd
;
2233 extern asymbol
*create_symbol();
2234 asection
*s
= bfd_get_section_by_name(output_bfd
, section
);
2235 /* Add a symbol called _end */
2236 asymbol
*def
= create_symbol(name
,
2237 BSF_GLOBAL
| BSF_EXPORT
|
2240 if (s
!= (asection
*)NULL
) {
2241 def
->value
= s
->vma
+ s
->size
;
2250 DEFUN(lang_statement_append
,(list
, element
, field
),
2251 lang_statement_list_type
*list AND
2252 lang_statement_union_type
*element AND
2253 lang_statement_union_type
**field
)
2255 *(list
->tail
) = element
;
2259 /* Set the output format type */
2261 DEFUN(lang_add_output_format
,(format
),
2264 output_target
= format
;