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. */
22 * Revision 1.3 1991/03/27 00:52:49 steve
23 * *** empty log message ***
25 * Revision 1.2 1991/03/22 23:02:34 steve
26 * Brought up to sync with Intel again.
28 * Revision 1.3 1991/03/16 22:19:21 rich
31 * Revision 1.2 1991/03/15 18:52:42 rich
34 * Revision 1.1 1991/03/13 00:48:23 chrisb
37 * Revision 1.8 1991/03/10 09:31:28 rich
39 * Makefile config.h ld-emul.c ld-emul.h ld-gld.c ld-gld960.c
40 * ld-lnk960.c ld.h lddigest.c ldexp.c ldexp.h ldfile.c ldfile.h
41 * ldgram.y ldinfo.h ldlang.c ldlang.h ldlex.h ldlex.l ldmain.c
42 * ldmain.h ldmisc.c ldmisc.h ldsym.c ldsym.h ldversion.c
43 * ldversion.h ldwarn.h ldwrite.c ldwrite.h y.tab.h
45 * As of this round of changes, ld now builds on all hosts of (Intel960)
46 * interest and copy passes my copy test on big endian hosts again.
48 * Revision 1.7 1991/03/09 03:31:03 sac
49 * After a fatal info message, the output file is deleted.
51 * Revision 1.6 1991/03/09 03:25:06 sac
52 * Added support for LONG, SHORT and BYTE keywords in scripts
54 * Revision 1.5 1991/03/06 21:59:31 sac
55 * Completed G++ support
57 * Revision 1.4 1991/03/06 02:26:02 sac
58 * Added support for constructor sections.
59 * Remove parsing ambiguity.
62 * Revision 1.3 1991/02/22 17:15:01 sac
63 * Added RCS keywords and copyrights
75 #include "ldgram.tab.h"
86 extern unsigned int undefined_global_sym_count
;
88 static char *startup_file
;
89 static lang_input_statement_type
*first_file
;
90 lang_statement_list_type statement_list
;
91 lang_statement_list_type
*stat_ptr
= &statement_list
;
92 lang_statement_list_type lang_output_section_statement
;
93 lang_statement_list_type input_file_chain
;
94 lang_statement_list_type file_chain
;
95 extern char *current_file
;
96 static boolean placed_commons
= false;
98 boolean lang_float_flag
;
100 static lang_output_section_statement_type
*default_common_section
;
104 PROTO(static void, print_statements
,(void));
105 PROTO(static void, print_statement
,(lang_statement_union_type
*,
106 lang_output_section_statement_type
*));
111 boolean lang_has_input_file
= false;
114 extern bfd
*output_bfd
;
115 size_t largest_section
;
118 extern enum bfd_architecture ldfile_output_architecture
;
119 extern unsigned long ldfile_output_machine
;
120 extern char *ldfile_output_machine_name
;
123 extern ldsym_type
*symbol_head
;
126 unsigned int commons_pending
;
131 extern args_type command_line
;
132 extern ld_config_type config
;
138 lang_output_section_statement_type
*create_object_symbols
;
140 extern boolean had_script
;
141 static boolean map_option_f
;
144 boolean had_output_filename
= false;
145 extern boolean write_map
;
152 size_t longest_section_name
= 8;
155 lang_input_statement_type
*script_file
;
157 section_userdata_type common_section_userdata
;
158 asection common_section
;
161 #define cat(a,b) a##b
163 #define cat(a,b) a/**/b
166 #define new_stat(x,y) (cat(x,_type)*) new_statement(cat(x,_enum), sizeof(cat(x,_type)),y)
168 #define outside_section_address(q) ( (q)->output_offset + (q)->output_section->vma)
170 #define outside_symbol_address(q) ((q)->value + outside_section_address(q->section))
172 boolean option_longmap
= false;
174 static void lang_list_init(list
)
175 lang_statement_list_type
*list
;
177 list
->head
= (lang_statement_union_type
*)NULL
;
178 list
->tail
= &list
->head
;
185 printf("%*s", -longest_section_name
, name
);
201 printf("%8lx", value
);
207 printf("%5x", (unsigned)value
);
210 print_alignment(value
)
213 printf("2**%2u",value
);
219 printf("%04x",(unsigned)value
);
224 lang_statement_union_type
*new_statement(type
, size
, list
)
225 enum statement_enum type
;
227 lang_statement_list_type
*list
;
229 lang_statement_union_type
*new = (lang_statement_union_type
*)
231 new->header
.type
= type
;
232 new->header
.next
= (lang_statement_union_type
*)NULL
;
233 lang_statement_append(list
, new, &new->header
.next
);
237 static lang_input_statement_type
*
238 new_afile(name
, file_type
, target
)
240 lang_input_file_enum_type file_type
;
243 lang_input_statement_type
*p
= new_stat(lang_input_statement
,
245 lang_has_input_file
= true;
248 case lang_input_file_is_symbols_only_enum
:
250 p
->is_archive
=false;
252 p
->local_sym_name
= name
;
253 p
->just_syms_flag
= true;
254 p
->search_dirs_flag
= false;
256 case lang_input_file_is_fake_enum
:
258 p
->is_archive
=false;
260 p
->local_sym_name
= name
;
261 p
->just_syms_flag
= false;
262 p
->search_dirs_flag
=false;
265 case lang_input_file_is_l_enum
:
266 p
->is_archive
= true;
269 p
->local_sym_name
= concat("-l",name
,"");
270 p
->just_syms_flag
= false;
271 p
->search_dirs_flag
= true;
274 case lang_input_file_is_search_file_enum
:
275 case lang_input_file_is_marker_enum
:
277 p
->is_archive
=false;
279 p
->local_sym_name
= name
;
280 p
->just_syms_flag
= false;
281 p
->search_dirs_flag
=true;
286 case lang_input_file_is_file_enum
:
288 p
->is_archive
=false;
290 p
->local_sym_name
= name
;
291 p
->just_syms_flag
= false;
292 p
->search_dirs_flag
=false;
299 p
->asymbols
= (asymbol
**)NULL
;
300 p
->superfile
= (lang_input_statement_type
*)NULL
;
302 p
->next_real_file
= (lang_statement_union_type
*)NULL
;
303 p
->next
= (lang_statement_union_type
*)NULL
;
305 p
->common_output_section
= (asection
*)NULL
;
307 lang_statement_append(&input_file_chain
,
308 (lang_statement_union_type
*)p
,
313 lang_input_statement_type
*
314 lang_add_input_file(name
,
318 lang_input_file_enum_type file_type
;
321 /* Look it up or build a new one */
323 lang_input_statement_type
*p
;
325 for (p
= (lang_input_statement_type
*)input_file_chain
.head
;
326 p
!= (lang_input_statement_type
*)NULL
;
327 p
= (lang_input_statement_type
*)(p
->next_real_file
))
329 /* Sometimes we have incomplete entries in here */
330 if (p
->filename
!= (char *)NULL
) {
331 if(strcmp(name
,p
->filename
) == 0) return p
;
335 return new_afile(name
, file_type
, target
);
344 stat_ptr
= &statement_list
;
345 lang_list_init(stat_ptr
);
347 lang_list_init(&input_file_chain
);
348 lang_list_init(&lang_output_section_statement
);
349 lang_list_init(&file_chain
);
350 first_file
= lang_add_input_file((char *)NULL
,
351 lang_input_file_is_marker_enum
,
359 script_file
= lang_add_input_file("script file",
360 lang_input_file_is_fake_enum
,
362 script_file
->the_bfd
= bfd_create("script file", output_bfd
);
363 script_file
->symbol_count
= 0;
365 common_section
.userdata
= &common_section_userdata
;
371 /* this function mainains a dictionary of regions. If the *default*
372 region is asked for then a pointer to the first region is
373 returned. If there is no first pointer then one is created
376 static lang_memory_region_type
*lang_memory_region_list
;
377 static lang_memory_region_type
**lang_memory_region_list_tail
= &lang_memory_region_list
;
379 lang_memory_region_type
*
380 lang_memory_region_lookup(name
)
384 lang_memory_region_type
*p
= lang_memory_region_list
;
385 for (p
= lang_memory_region_list
;
386 p
!= ( lang_memory_region_type
*)NULL
;
388 if (strcmp(p
->name
, name
) == 0) {
392 if (strcmp(name
,"*default*")==0) {
393 /* This is the default region, dig out first one on the list */
394 if (lang_memory_region_list
!= (lang_memory_region_type
*)NULL
){
395 return lang_memory_region_list
;
399 lang_memory_region_type
*new =
400 (lang_memory_region_type
*)ldmalloc(sizeof(lang_memory_region_type
));
402 new->next
= (lang_memory_region_type
*)NULL
;
404 *lang_memory_region_list_tail
= new;
405 lang_memory_region_list_tail
= &new->next
;
415 lang_output_section_statement_type
*
416 lang_output_section_find(name
)
419 lang_statement_union_type
*u
;
420 lang_output_section_statement_type
*lookup
;
422 for (u
= lang_output_section_statement
.head
;
423 u
!= (lang_statement_union_type
*)NULL
;
426 lookup
= &u
->output_section_statement
;
427 if (strcmp(name
, lookup
->name
)==0) {
431 return (lang_output_section_statement_type
*)NULL
;
434 lang_output_section_statement_type
*
435 lang_output_section_statement_lookup(name
)
439 lang_output_section_statement_type
*lookup
;
440 lookup
=lang_output_section_find(name
);
441 if (lookup
== (lang_output_section_statement_type
*)NULL
) {
443 lookup
=(lang_output_section_statement_type
*)
444 new_stat(lang_output_section_statement
, stat_ptr
);
445 lookup
->region
= (lang_memory_region_type
*)NULL
;
447 lookup
->block_value
= 1;
450 lookup
->next
= (lang_statement_union_type
*)NULL
;
451 lookup
->bfd_section
= (asection
*)NULL
;
452 lookup
->processed
= false;
453 lookup
->addr_tree
= (etree_type
*)NULL
;
454 lang_list_init(&lookup
->children
);
456 lang_statement_append(&lang_output_section_statement
,
457 (lang_statement_union_type
*)lookup
,
468 print_flags(outfile
, ignore_flags
)
470 lang_section_flags_type
*ignore_flags
;
472 fprintf(outfile
,"(");
474 if (flags
->flag_read
) fprintf(outfile
,"R");
475 if (flags
->flag_write
) fprintf(outfile
,"W");
476 if (flags
->flag_executable
) fprintf(outfile
,"X");
477 if (flags
->flag_loadable
) fprintf(outfile
,"L");
479 fprintf(outfile
,")");
486 lang_memory_region_type
*m
;
487 fprintf(outfile
,"**MEMORY CONFIGURATION**\n\n");
489 fprintf(outfile
,"name\t\torigin\t\tlength\t\tattributes\n");
490 for (m
= lang_memory_region_list
;
491 m
!= (lang_memory_region_type
*)NULL
;
494 fprintf(outfile
,"%-16s", m
->name
);
496 fprintf(outfile
,"%08lx\t%08lx\t", m
->origin
, m
->length
);
497 print_flags(outfile
, &m
->flags
);
498 fprintf(outfile
,"\n");
500 fprintf(outfile
,"\n\n**LINK EDITOR MEMORY MAP**\n\n");
501 fprintf(outfile
,"output\t\tinput\t\tvirtual\n");
502 fprintf(outfile
,"section\t\tsection\t\taddress\tsize\n\n");
511 static void init_os(s
)
512 lang_output_section_statement_type
*s
;
514 section_userdata_type
*new =
515 (section_userdata_type
*)
516 ldmalloc(sizeof(section_userdata_type
));
518 s
->bfd_section
= bfd_make_section(output_bfd
, s
->name
);
519 s
->bfd_section
->output_section
= s
->bfd_section
;
520 s
->bfd_section
->flags
= SEC_NO_FLAGS
;
521 /* We initialize an output sections output offset to minus its own */
522 /* vma to allow us to output a section through itself */
523 s
->bfd_section
->output_offset
= 0;
524 get_userdata( s
->bfd_section
) = new;
528 wild_doit(ptr
, section
,output
, file
)
529 lang_statement_list_type
*ptr
;
531 lang_output_section_statement_type
*output
;
532 lang_input_statement_type
*file
;
534 if(output
->bfd_section
== (asection
*)NULL
)
539 if (section
!= (asection
*)NULL
540 && section
->output_section
== (asection
*)NULL
) {
541 /* Add a section reference to the list */
542 lang_input_section_type
*new = new_stat(lang_input_section
, ptr
);
544 new->section
= section
;
546 section
->output_section
= output
->bfd_section
;
547 section
->output_section
->flags
|= section
->flags
;
548 if (section
->alignment_power
> output
->bfd_section
->alignment_power
) {
549 output
->bfd_section
->alignment_power
= section
->alignment_power
;
556 our_bfd_get_section_by_name(abfd
, section
)
560 return bfd_get_section_by_name(abfd
, section
);
564 wild_section(ptr
, section
, file
, output
)
565 lang_wild_statement_type
*ptr
;
567 lang_input_statement_type
*file
;
568 lang_output_section_statement_type
*output
;
571 if (section
== (char *)NULL
) {
572 /* Do the creation to all sections in the file */
573 for (s
= file
->the_bfd
->sections
; s
!= (asection
*)NULL
; s
=s
->next
) {
574 wild_doit(&ptr
->children
, s
, output
, file
);
578 /* Do the creation to the named section only */
579 wild_doit(&ptr
->children
,
580 our_bfd_get_section_by_name(file
->the_bfd
, section
),
591 lang_input_statement_type
*lookup_name(name
, target
)
595 lang_input_statement_type
*search
;
596 for(search
= (lang_input_statement_type
*)input_file_chain
.head
;
597 search
!= (lang_input_statement_type
*)NULL
;
598 search
= (lang_input_statement_type
*)search
->next_real_file
)
600 if (search
->filename
== (char *)NULL
&& name
== (char *)NULL
) {
603 if (search
->filename
!= (char *)NULL
&& name
!= (char *)NULL
) {
604 if (strcmp(search
->filename
, name
) == 0) {
605 Q_read_file_symbols(search
);
611 /* There isn't an afile entry for this file yet, this must be */
612 /* because the name has only appeared inside a load script and not */
613 /* on the command line */
614 search
= new_afile(name
, lang_input_file_is_file_enum
, target
);
615 Q_read_file_symbols(search
);
621 wild(s
, section
, file
, target
, output
)
622 lang_wild_statement_type
*s
;
626 lang_output_section_statement_type
*output
;
628 lang_input_statement_type
*f
;
629 if (file
== (char *)NULL
) {
630 /* Perform the iteration over all files in the list */
631 for (f
= (lang_input_statement_type
*)file_chain
.head
;
632 f
!= (lang_input_statement_type
*)NULL
;
633 f
= (lang_input_statement_type
*)f
->next
) {
634 wild_section(s
, section
, f
, output
);
638 /* Perform the iteration over a single file */
639 wild_section( s
, section
, lookup_name(file
, target
), output
);
644 read in all the files
647 open_output(name
, target
)
651 extern char *output_filename
;
652 bfd
* output
= bfd_openw(name
, target
);
653 output_filename
= name
;
654 if (output
== (bfd
*)NULL
)
656 if (bfd_error
== invalid_target
) {
657 info("%P%F target %s not found\n", target
);
659 info("%P%F problem opening output file %s, %E", name
);
662 output
->flags
|= D_PAGED
;
663 bfd_set_format(output
, bfd_object
);
666 extern char *default_target
;
668 lang_phase_0(sh
,target
)
669 lang_statement_union_type
*sh
;
672 lang_statement_union_type
*s
= (lang_statement_union_type
*)sh
;
673 for (; s
!= (lang_statement_union_type
*)NULL
; s
= s
->next
)
675 switch (s
->header
.type
) {
676 case lang_output_section_statement_enum
:
677 lang_phase_0(s
->output_section_statement
.children
.head
,
680 case lang_output_statement_enum
:
682 output_bfd
= open_output(s
->output_statement
.name
,
683 target
== (char *)NULL
?
684 default_target
: target
);
685 ldemul_set_output_arch();
688 case lang_target_statement_enum
:
689 target
= s
->target_statement
.target
;
691 case lang_wild_statement_enum
:
692 /* Maybe we should load the file's symbols */
693 if (s
->wild_statement
.filename
) {
694 (void) lookup_name(s
->wild_statement
.filename
, target
);
697 /* Attatch this to the current output section */
698 case lang_common_statement_enum
:
699 case lang_fill_statement_enum
:
700 case lang_input_section_enum
:
701 case lang_object_symbols_statement_enum
:
702 case lang_address_statement_enum
:
703 case lang_data_statement_enum
:
705 case lang_afile_asection_pair_statement_enum
:
710 case lang_input_statement_enum
:
711 if (s
->input_statement
.real
== true) {
712 s
->input_statement
.target
= target
;
713 lookup_name(s
->input_statement
.filename
, target
);
716 case lang_assignment_statement_enum
:
718 (void) exp_fold_tree(s
->assignment_statement
.exp
,
724 case lang_padding_statement_enum
:
732 /* If there are [COMMONS] statements, put a wild one into the bss section */
735 lang_reasonable_defaults()
738 lang_output_section_statement_lookup(".text");
739 lang_output_section_statement_lookup(".data");
741 default_common_section
=
742 lang_output_section_statement_lookup(".bss");
744 if (placed_commons
== false) {
745 lang_wild_statement_type
*new =
746 new_stat(lang_wild_statement
,
747 &default_common_section
->children
);
748 new->section_name
= "COMMON";
749 new->filename
= (char *)NULL
;
750 lang_list_init(&new->children
);
757 if (had_script
== false) {
758 parse_line(ldemul_get_script());
761 lang_reasonable_defaults();
762 lang_phase_0(statement_list
.head
,default_target
);
766 /* Open input files and attatch to output sections */
768 lang_open_input(s
, target
, output_section_statement
)
769 lang_statement_union_type
*s
;
771 lang_output_section_statement_type
*output_section_statement
;
773 for (; s
!= (lang_statement_union_type
*)NULL
; s
= s
->next
)
775 switch (s
->header
.type
) {
776 case lang_wild_statement_enum
:
777 wild(&s
->wild_statement
, s
->wild_statement
.section_name
,
778 s
->wild_statement
.filename
, target
,
779 output_section_statement
);
783 case lang_output_section_statement_enum
:
784 lang_open_input(s
->output_section_statement
.children
.head
,
786 &s
->output_section_statement
);
788 case lang_output_statement_enum
:
790 case lang_target_statement_enum
:
791 target
= s
->target_statement
.target
;
793 case lang_common_statement_enum
:
794 case lang_fill_statement_enum
:
795 case lang_input_section_enum
:
796 case lang_object_symbols_statement_enum
:
797 case lang_data_statement_enum
:
799 case lang_afile_asection_pair_statement_enum
:
803 case lang_assignment_statement_enum
:
804 case lang_padding_statement_enum
:
807 case lang_address_statement_enum
:
808 /* Mark the specified section with the supplied address */
810 lang_output_section_statement_type
*os
=
811 lang_output_section_statement_lookup
812 (s
->address_statement
.section_name
);
813 os
->addr_tree
= s
->address_statement
.address
;
816 case lang_input_statement_enum
:
817 /* A standard input statement, has no wildcards */
818 /* Q_read_file_symbols(&s->input_statement);*/
829 print_output_section_statement(output_section_statement
)
830 lang_output_section_statement_type
*output_section_statement
;
832 asection
*section
= output_section_statement
->bfd_section
;
834 print_section(output_section_statement
->name
);
837 print_dot
= section
->vma
;
841 print_address(section
->vma
);
843 print_size(section
->size
);
845 print_alignment(section
->alignment_power
);
848 printf("%s flags", output_section_statement
->region
->name
);
849 print_flags(stdout
, &output_section_statement
->flags
);
854 printf("No attached output section");
857 print_statement(output_section_statement
->children
.head
,
858 output_section_statement
);
863 print_assignment(assignment
, output_section
)
864 lang_assignment_statement_type
*assignment
;
865 lang_output_section_statement_type
*output_section
;
867 etree_value_type result
;
872 print_address(print_dot
);
874 result
= exp_fold_tree(assignment
->exp
->assign
.src
,
876 lang_final_phase_enum
,
881 print_address(result
.value
);
885 printf("*undefined*");
888 exp_print_tree(stdout
, assignment
->exp
);
893 print_input_statement(statm
)
894 lang_input_statement_type
*statm
;
896 printf("LOAD %s\n",statm
->filename
);
899 static void print_symbol(q
)
906 print_address(outside_symbol_address(q
));
907 printf(" %s", q
->name
? q
->name
: " ");
911 print_input_section(in
)
912 lang_input_section_type
*in
;
914 asection
*i
= in
->section
;
919 print_section(i
->name
);
921 if (i
->output_section
) {
922 print_address(i
->output_section
->vma
+ i
->output_offset
);
926 print_alignment(i
->alignment_power
);
929 bfd
*abfd
= in
->ifile
->the_bfd
;
930 printf(" %s ",abfd
->xvec
->name
);
931 if(abfd
->my_archive
!= (bfd
*)NULL
) {
932 printf("[%s]%s", abfd
->my_archive
->filename
,
936 printf("%s", abfd
->filename
);
940 /* Find all the symbols in this file defined in this section */
943 for (p
= in
->ifile
->asymbols
; *p
; p
++) {
946 if (bfd_get_section(q
) == i
&& q
->flags
& BSF_GLOBAL
) {
957 print_dot
= outside_section_address(i
) + i
->size
;
960 printf("No output section allocated\n");
965 print_common_statement()
970 print_section(common_section
.output_section
->name
);
972 print_address(common_section
.output_offset
+
973 common_section
.output_section
->vma
);
975 print_size(common_section
.size
);
979 /* Print out all the global symbols */
982 for (lgs
= symbol_head
; lgs
!= (ldsym_type
*)NULL
; lgs
=
984 if (lgs
->sdefs_chain
) {
985 asymbol
*def
= *(lgs
->sdefs_chain
);
986 if (def
->section
== &common_section
) {
992 print_dot
= common_section
.output_offset
+
993 common_section
.output_section
->vma
+ common_section
.size
;
998 print_fill_statement(fill
)
999 lang_fill_statement_type
*fill
;
1001 printf("FILL mask ");
1002 print_fill( fill
->fill
);
1006 print_data_statement(data
)
1007 lang_data_statement_type
*data
;
1009 /* bfd_vma value; */
1014 ASSERT(print_dot
== data
->output_vma
);
1016 print_address(data
->output_vma
);
1018 print_address(data
->value
);
1020 switch (data
->type
) {
1023 print_dot
+= BYTE_SIZE
;
1027 print_dot
+= SHORT_SIZE
;
1031 print_dot
+= LONG_SIZE
;
1035 exp_print_tree(stdout
, data
->exp
);
1042 print_padding_statement(s
)
1043 lang_padding_statement_type
*s
;
1047 print_section("*fill*");
1049 print_address(s
->output_offset
+ s
->output_section
->vma
);
1051 print_size(s
->size
);
1053 print_fill(s
->fill
);
1057 static void print_wild_statement(w
,os
)
1058 lang_wild_statement_type
*w
;
1059 lang_output_section_statement_type
*os
;
1061 if (w
->filename
!= (char *)NULL
) {
1062 printf("%s",w
->filename
);
1067 if (w
->section_name
!= (char *)NULL
) {
1068 printf("(%s)",w
->section_name
);
1074 print_statement(w
->children
.head
, os
);
1078 print_statement(s
, os
)
1079 lang_statement_union_type
*s
;
1080 lang_output_section_statement_type
*os
;
1083 switch (s
->header
.type
) {
1084 case lang_wild_statement_enum
:
1085 print_wild_statement(&s
->wild_statement
, os
);
1088 printf("Fail with %d\n",s
->header
.type
);
1091 case lang_address_statement_enum
:
1092 printf("address\n");
1094 case lang_common_statement_enum
:
1095 print_common_statement();
1097 case lang_object_symbols_statement_enum
:
1098 printf("object symbols\n");
1100 case lang_fill_statement_enum
:
1101 print_fill_statement(&s
->fill_statement
);
1103 case lang_data_statement_enum
:
1104 print_data_statement(&s
->data_statement
);
1108 case lang_input_section_enum
:
1109 print_input_section(&s
->input_section
);
1111 case lang_padding_statement_enum
:
1112 print_padding_statement(&s
->padding_statement
);
1114 case lang_output_section_statement_enum
:
1115 print_output_section_statement(&s
->output_section_statement
);
1117 case lang_assignment_statement_enum
:
1118 print_assignment(&s
->assignment_statement
,
1123 case lang_target_statement_enum
:
1124 printf("TARGET(%s)\n", s
->target_statement
.target
);
1126 case lang_output_statement_enum
:
1127 printf("OUTPUT(%s)\n", s
->output_statement
.name
);
1129 case lang_input_statement_enum
:
1130 print_input_statement(&s
->input_statement
);
1132 case lang_afile_asection_pair_statement_enum
:
1144 print_statement(statement_list
.head
,
1145 (lang_output_section_statement_type
*)NULL
);
1149 insert_pad(this_ptr
, fill
, power
, output_section_statement
, dot
)
1150 lang_statement_union_type
**this_ptr
;
1153 asection
* output_section_statement
;
1156 /* Align this section first to the
1157 input sections requirement, then
1158 to the output section's requirement.
1159 If this alignment is > than any seen before,
1160 then record it too. Perform the alignment by
1161 inserting a magic 'padding' statement.
1164 unsigned int alignment_needed
= align_power(dot
, power
) - dot
;
1166 if (alignment_needed
!= 0)
1168 lang_statement_union_type
*new =
1169 (lang_statement_union_type
*)
1170 ldmalloc(sizeof(lang_padding_statement_type
));
1171 /* Link into existing chain */
1172 new->header
.next
= *this_ptr
;
1174 new->header
.type
= lang_padding_statement_enum
;
1175 new->padding_statement
.output_section
= output_section_statement
;
1176 new->padding_statement
.output_offset
=
1177 dot
- output_section_statement
->vma
;
1178 new->padding_statement
.fill
= fill
;
1179 new->padding_statement
.size
= alignment_needed
;
1183 /* Remember the most restrictive alignment */
1184 if (power
> output_section_statement
->alignment_power
) {
1185 output_section_statement
->alignment_power
= power
;
1187 output_section_statement
->size
+= alignment_needed
;
1188 return alignment_needed
+ dot
;
1193 size_common runs run though each global symboxl, and works
1194 out how big the common section will be.
1198 size_common(output_section_statement
, this_ptr
, dot
)
1199 lang_output_section_statement_type
*output_section_statement
;
1200 lang_statement_union_type
**this_ptr
;
1203 extern ldsym_type
*symbol_head
;
1205 /* Make sure that each symbol is only defined once.
1206 Allocate common symbols
1207 Make the ref chain point to the defining asymbol.
1209 /* Now, for each symbol, verify that it is defined globally at most once.
1210 Put the global value into the symbol entry.
1211 Common symbols are allocated here, in the BSS section.
1212 Each defined symbol is given a '->defined' field
1213 which is the correct N_ code for its definition,
1214 except in the case of common symbols with -r.
1215 Then make all the references point at the symbol entry
1216 instead of being chained together. */
1219 common_section
.name
= output_section_statement
->bfd_section
->name
;
1220 common_section
.output_section
= output_section_statement
->bfd_section
;
1221 common_section
.output_offset
=
1222 dot
- output_section_statement
->bfd_section
->vma
;
1223 if (config
.relocateable_output
== false ||
1224 command_line
.force_common_definition
== true) {
1225 dot
= insert_pad(this_ptr
,
1226 0x0, 4, output_section_statement
->bfd_section
, dot
);
1228 for (sp
= symbol_head
; sp
!= (ldsym_type
*)NULL
; sp
= sp
->next
)
1230 /* Attatch this symbol to the correct output section*/
1232 /* Allocate as common if wanted */
1234 if (sp
->scoms_chain
)
1237 unsigned long com
= (*(sp
->scoms_chain
))->value
;
1238 /* Work out what alignment this common item s
1239 hould be put on. Anything < int is int aligned,
1240 anything bigger is self aligned,
1241 up to the restriction of the machine */
1243 unsigned int align
= sizeof(int);
1245 /* Round up size of object to nearest int */
1246 com
= ALIGN(com
, sizeof(int));
1247 /* See what alignment is necessary -*/
1249 while ((com
& align
)==0) align
<<=1;
1255 dot
= ALIGN(dot
, align
);
1258 /* Transmogrify this from a common symbol
1259 into a definition of a symbol in common
1261 sp
->sdefs_chain
= sp
->scoms_chain
;
1264 asymbol
*com_ptr
= *(sp
->sdefs_chain
);
1266 sp
->scoms_chain
= (asymbol
**)NULL
;
1268 /* Assign address, but keep section relative */
1270 /* Force the symbol to belong in the bss section */
1271 com_ptr
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
1272 com_ptr
->section
= &common_section
;
1273 common_section
.size
+= com
;
1276 printf ("Allocating common %s: %lx at %lx\n",
1281 com_ptr
->value
= common_section
.size
;
1287 (common_section
.output_section
->vma
+
1288 common_section
.output_section
->size
)) {
1289 common_section
.output_section
->size
=
1290 dot
- common_section
.output_section
->vma
;
1292 return dot
+ common_section
.size
;
1296 size_input_section( this_ptr
, output_section_statement
, fill
, dot
)
1297 lang_statement_union_type
**this_ptr
;
1298 lang_output_section_statement_type
*output_section_statement
;
1299 unsigned short fill
;
1302 lang_input_section_type
*is
= &((*this_ptr
)->input_section
);
1303 asection
*i
= is
->section
;
1305 dot
= insert_pad(this_ptr
, fill
, i
->alignment_power
,
1306 output_section_statement
->bfd_section
, dot
);
1308 /* remember the largest size so we can malloc the largest area */
1309 /* needed for the output stage */
1310 if (i
->size
> largest_section
) {
1311 largest_section
= i
->size
;
1314 /* Remember where in the output section this input section goes */
1315 i
->output_offset
= dot
- output_section_statement
->bfd_section
->vma
;
1317 /* Mark how big the output section must be to contain this now */
1319 output_section_statement
->bfd_section
->size
=
1320 dot
- output_section_statement
->bfd_section
->vma
;
1327 /* Work out the size of the output sections
1328 from the sizes of the input sections */
1330 lang_size_sections(s
, output_section_statement
, prev
, fill
, dot
)
1331 lang_statement_union_type
*s
;
1332 lang_output_section_statement_type
* output_section_statement
;
1333 lang_statement_union_type
**prev
;
1334 unsigned short fill
;
1337 /* Size up the sections from their constituent parts */
1338 for (; s
!= (lang_statement_union_type
*)NULL
; s
= s
->next
)
1340 switch (s
->header
.type
) {
1341 case lang_output_section_statement_enum
:
1344 lang_output_section_statement_type
*os
=
1345 &(s
->output_section_statement
);
1346 /* The start of a section */
1348 if (os
->addr_tree
== (etree_type
*)NULL
) {
1349 /* No address specified for this section, get one
1350 from the region specification
1352 if (os
->region
== (lang_memory_region_type
*)NULL
) {
1353 os
->region
= lang_memory_region_lookup("*default*");
1355 dot
= os
->region
->current
;
1358 etree_value_type r
;
1359 r
= exp_fold_tree(os
->addr_tree
,
1360 (lang_output_section_statement_type
*)NULL
,
1361 lang_allocating_phase_enum
,
1363 if (r
.valid
== false) {
1364 info("%F%S: non constant address expression for section %s\n",
1369 /* The section starts here */
1370 /* First, align to what the section needs */
1372 dot
= align_power(dot
, os
->bfd_section
->alignment_power
);
1373 os
->bfd_section
->vma
= dot
;
1374 os
->bfd_section
->output_offset
= 0;
1376 (void) lang_size_sections(os
->children
.head
, os
, &os
->children
.head
,
1378 /* Ignore the size of the input sections, use the vma and size to */
1382 after
= ALIGN(os
->bfd_section
->vma
+
1383 os
->bfd_section
->size
,
1387 os
->bfd_section
->size
= after
- os
->bfd_section
->vma
;
1388 dot
= os
->bfd_section
->vma
+ os
->bfd_section
->size
;
1389 os
->processed
= true;
1391 /* Replace into region ? */
1392 if (os
->addr_tree
== (etree_type
*)NULL
1393 && os
->region
!=(lang_memory_region_type
*)NULL
) {
1394 os
->region
->current
= dot
;
1400 case lang_data_statement_enum
:
1403 s
->data_statement
.output_vma
= dot
;
1404 s
->data_statement
.output_section
=
1405 output_section_statement
->bfd_section
;
1407 switch (s
->data_statement
.type
) {
1420 output_section_statement
->bfd_section
->size
+= size
;
1424 case lang_wild_statement_enum
:
1426 dot
= lang_size_sections(s
->wild_statement
.children
.head
,
1427 output_section_statement
,
1428 &s
->wild_statement
.children
.head
,
1434 case lang_object_symbols_statement_enum
:
1435 create_object_symbols
= output_section_statement
;
1437 case lang_output_statement_enum
:
1439 case lang_target_statement_enum
:
1441 case lang_common_statement_enum
:
1442 dot
= size_common(output_section_statement
, prev
, dot
);
1446 case lang_input_section_enum
:
1447 dot
= size_input_section(prev
,
1448 output_section_statement
,
1449 output_section_statement
->fill
, dot
);
1451 case lang_input_statement_enum
:
1453 case lang_fill_statement_enum
:
1454 fill
= s
->fill_statement
.fill
;
1456 case lang_assignment_statement_enum
:
1458 bfd_vma newdot
= dot
;
1459 exp_fold_tree(s
->assignment_statement
.exp
,
1460 output_section_statement
,
1461 lang_allocating_phase_enum
,
1466 /* We've been moved ! so insert a pad */
1468 lang_statement_union_type
*new =
1469 (lang_statement_union_type
*)
1470 ldmalloc(sizeof(lang_padding_statement_type
));
1471 /* Link into existing chain */
1472 new->header
.next
= *prev
;
1474 new->header
.type
= lang_padding_statement_enum
;
1475 new->padding_statement
.output_section
=
1476 output_section_statement
->bfd_section
;
1477 new->padding_statement
.output_offset
=
1478 dot
- output_section_statement
->bfd_section
->vma
;
1479 new->padding_statement
.fill
= fill
;
1480 new->padding_statement
.size
= newdot
- dot
;
1481 output_section_statement
->bfd_section
->size
+=
1482 new->padding_statement
.size
;
1488 case lang_padding_statement_enum
:
1494 case lang_address_statement_enum
:
1497 prev
= &s
->header
.next
;
1504 lang_do_assignments(s
, output_section_statement
, fill
, dot
)
1505 lang_statement_union_type
*s
;
1506 lang_output_section_statement_type
* output_section_statement
;
1507 unsigned short fill
;
1511 for (; s
!= (lang_statement_union_type
*)NULL
; s
= s
->next
)
1513 switch (s
->header
.type
) {
1514 case lang_output_section_statement_enum
:
1516 lang_output_section_statement_type
*os
=
1517 &(s
->output_section_statement
);
1518 dot
= os
->bfd_section
->vma
;
1519 (void) lang_do_assignments(os
->children
.head
, os
, os
->fill
, dot
);
1520 dot
= os
->bfd_section
->vma
+ os
->bfd_section
->size
;
1523 case lang_wild_statement_enum
:
1525 dot
= lang_do_assignments(s
->wild_statement
.children
.head
,
1526 output_section_statement
,
1531 case lang_object_symbols_statement_enum
:
1532 case lang_output_statement_enum
:
1533 case lang_target_statement_enum
:
1534 case lang_common_statement_enum
:
1536 case lang_data_statement_enum
:
1538 etree_value_type value
;
1539 value
= exp_fold_tree(s
->data_statement
.exp
,
1540 0, lang_final_phase_enum
, dot
, &dot
);
1541 s
->data_statement
.value
= value
.value
;
1542 if (value
.valid
== false) info("%F%P: Invalid data statement\n");
1544 switch (s
->data_statement
.type
) {
1556 case lang_input_section_enum
:
1558 asection
*in
= s
->input_section
.section
;
1563 case lang_input_statement_enum
:
1565 case lang_fill_statement_enum
:
1566 fill
= s
->fill_statement
.fill
;
1568 case lang_assignment_statement_enum
:
1570 exp_fold_tree(s
->assignment_statement
.exp
,
1571 output_section_statement
,
1572 lang_final_phase_enum
,
1578 case lang_padding_statement_enum
:
1579 dot
+= s
->padding_statement
.size
;
1584 case lang_address_statement_enum
:
1594 static void lang_relocate_globals()
1598 Each ldsym_type maintains a chain of pointers to asymbols which
1599 references the definition. Replace each pointer to the referenence
1600 with a pointer to only one place, preferably the definition. If
1601 the defintion isn't available then the common symbol, and if
1602 there isn't one of them then choose one reference.
1605 FOR_EACH_LDSYM(lgs
) {
1607 if (lgs
->sdefs_chain
) {
1608 it
= *(lgs
->sdefs_chain
);
1610 else if (lgs
->scoms_chain
!= (asymbol
**)NULL
) {
1611 it
= *(lgs
->scoms_chain
);
1613 else if (lgs
->srefs_chain
!= (asymbol
**)NULL
) {
1614 it
= *(lgs
->srefs_chain
);
1619 if (it
!= (asymbol
*)NULL
)
1621 asymbol
**ptr
= lgs
->srefs_chain
;
1623 while (ptr
!= (asymbol
**)NULL
) {
1624 asymbol
*ref
= *ptr
;
1626 ptr
= (asymbol
**)(ref
->udata
);
1634 /* now that all the jiggery pokery is finished, copy important data from
1635 * out internal form to the bfd way. Also create a section
1636 * for each dummy file
1640 lang_create_output_section_statements()
1642 lang_statement_union_type
*os
;
1643 for (os
= lang_output_section_statement
.head
;
1644 os
!= (lang_statement_union_type
*)NULL
;
1645 os
= os
->output_section_statement
.next
) {
1646 lang_output_section_statement_type
*s
=
1647 &os
->output_section_statement
;
1650 script_file
->the_bfd
->sections
= output_bfd
->sections
;
1658 if (entry_symbol
== (char *)NULL
) {
1659 /* No entry has been specified, look for start */
1660 entry_symbol
= "start";
1662 lgs
= ldsym_get_soft(entry_symbol
);
1663 if (lgs
&& lgs
->sdefs_chain
) {
1664 asymbol
*sy
= *(lgs
->sdefs_chain
);
1665 /* We can set the entry address*/
1666 bfd_set_start_address(output_bfd
,
1667 outside_symbol_address(sy
));
1671 /* Can't find anything reasonable,
1672 use the first address in the text section
1674 asection
*ts
= bfd_get_section_by_name(output_bfd
, ".text");
1676 bfd_set_start_address(output_bfd
, ts
->vma
);
1681 /* By now we know the target architecture, and we may have an */
1682 /* ldfile_output_machine_name */
1686 lang_statement_union_type
*file
;
1689 for (file
= file_chain
.head
;
1690 file
!= (lang_statement_union_type
*)NULL
;
1691 file
=file
->input_statement
.next
)
1693 /* Inspect the architecture and ensure we're linking like
1697 if (bfd_arch_compatible( file
->input_statement
.the_bfd
,
1699 &ldfile_output_architecture
,
1700 &ldfile_output_machine
)) {
1701 bfd_set_arch_mach(output_bfd
,
1702 ldfile_output_architecture
, ldfile_output_machine
);
1705 enum bfd_architecture this_architecture
=
1706 bfd_get_architecture(file
->input_statement
.the_bfd
);
1707 unsigned long this_machine
=
1708 bfd_get_machine(file
->input_statement
.the_bfd
);
1710 info("%I: architecture %s",
1712 bfd_printable_arch_mach(this_architecture
, this_machine
));
1713 info(" incompatible with output %s\n",
1714 bfd_printable_arch_mach(ldfile_output_architecture
,
1715 ldfile_output_machine
));
1716 ldfile_output_architecture
= this_architecture
;
1717 ldfile_output_machine
= this_machine
;
1718 bfd_set_arch_mach(output_bfd
,
1719 ldfile_output_architecture
,
1720 ldfile_output_machine
);
1729 * run through all the global common symbols and tie them
1730 * to the output section requested.
1737 if (config
.relocateable_output
== false ||
1738 command_line
.force_common_definition
== true) {
1739 for (lgs
= symbol_head
;
1740 lgs
!= (ldsym_type
*)NULL
;
1746 if (lgs
->scoms_chain
!= (asymbol
**)NULL
) {
1748 com
= *(lgs
->scoms_chain
);
1750 align
= sizeof(int);
1751 /* Round up size of object to nearest int */
1752 size
= ALIGN(size
, sizeof(int));
1753 /* Force alignment */
1755 while ((size
& align
)==0) align
<<=1;
1760 /* Change from a common symbol into a definition of
1762 lgs
->sdefs_chain
= lgs
->scoms_chain
;
1763 lgs
->scoms_chain
= (asymbol
**)NULL
;
1765 /* Point to the correct common section */
1767 ((lang_input_statement_type
*)
1768 (com
->the_bfd
->usrdata
))->common_section
;
1769 /* Fix the size of the common section */
1772 com
->flags
= BSF_EXPORT
| BSF_GLOBAL
;
1776 printf ("Allocating common %s: %x at %x\n",
1779 (unsigned) com
->section
->size
);
1781 com
->value
= com
->section
->size
;
1782 com
->section
->size
+= size
;
1789 run through the input files and ensure that every input
1790 section has somewhere to go. If one is found without
1791 a destination then create an input request and place it
1792 into the statement tree.
1795 static void lang_place_orphans()
1797 lang_input_statement_type
*file
;
1798 for (file
= (lang_input_statement_type
*)file_chain
.head
;
1799 file
!= (lang_input_statement_type
*)NULL
;
1800 file
= (lang_input_statement_type
*)file
->next
) {
1802 for (s
= file
->the_bfd
->sections
;
1803 s
!= (asection
*)NULL
;
1805 if ( s
->output_section
== (asection
*)NULL
) {
1806 /* This section of the file is not attatched, root
1807 around for a sensible place for it to go */
1809 if (file
->common_section
== s
) {
1810 /* This is a lonely common section which must
1811 have come from an archive. We attatch to the
1812 section with the wildcard */
1813 wild_doit(&default_common_section
->children
, s
,
1814 default_common_section
, file
);
1817 lang_output_section_statement_type
*os
=
1818 lang_output_section_statement_lookup(s
->name
);
1820 wild_doit(&os
->children
, s
, os
, file
);
1832 * peformed after every file has been opened and symbols read
1839 lang_create_output_section_statements();
1840 lang_open_input(statement_list
.head
, (char *)NULL
,
1841 ( lang_output_section_statement_type
*)NULL
);
1842 lang_place_orphans();
1845 ldemul_before_allocation();
1847 lang_size_sections(statement_list
.head
,
1848 (lang_output_section_statement_type
*)NULL
,
1849 &(statement_list
.head
), 0, (bfd_vma
)0);
1850 ldemul_after_allocation();
1851 /* Do it once again now that we know the sizes of everything */
1853 lang_do_assignments(statement_list
.head
,
1854 (lang_output_section_statement_type
*)NULL
,
1861 lang_relocate_globals();
1871 lang_set_flags(ptr
, flags
)
1872 lang_section_flags_type
*ptr
;
1875 boolean state
= true;
1876 ptr
->flag_read
= false;
1877 ptr
->flag_write
= false;
1878 ptr
->flag_executable
= false;
1879 ptr
->flag_loadable
= false;
1882 if (*flags
== '!') {
1889 ptr
->flag_read
= state
;
1892 ptr
->flag_write
= state
;
1895 ptr
->flag_executable
= state
;
1898 ptr
->flag_loadable
= state
;
1901 info("%P%F illegal syntax in flags\n");
1911 lang_for_each_file(func
)
1914 lang_input_statement_type
*f
;
1915 for (f
= (lang_input_statement_type
*)file_chain
.head
;
1916 f
!= (lang_input_statement_type
*)NULL
;
1917 f
= (lang_input_statement_type
*)f
->next
)
1925 lang_for_each_input_section(func
)
1928 lang_input_statement_type
*f
;
1929 for (f
= (lang_input_statement_type
*)file_chain
.head
;
1930 f
!= (lang_input_statement_type
*)NULL
;
1931 f
= (lang_input_statement_type
*)f
->next
)
1934 for (s
= f
->the_bfd
->sections
;
1935 s
!= (asection
*)NULL
;
1937 func(f
->the_bfd
, s
);
1945 ldlang_add_file(entry
)
1946 lang_input_statement_type
*entry
;
1948 lang_has_input_file
= true;
1949 lang_statement_append(&file_chain
,
1950 (lang_statement_union_type
*)entry
,
1957 lang_add_output(name
)
1960 lang_output_statement_type
*new = new_stat(lang_output_statement
,
1963 had_output_filename
= true;
1967 static lang_output_section_statement_type
*current_section
;
1970 lang_enter_output_section_statement(output_section_statement_name
,
1973 char *output_section_statement_name
;
1974 etree_type
*address_exp
;
1975 bfd_vma block_value
;
1977 lang_output_section_statement_type
*os
;
1980 lang_output_section_statement_lookup(output_section_statement_name
);
1983 /* Add this statement to tree */
1984 /* add_statement(lang_output_section_statement_enum,
1985 output_section_statement);*/
1986 /* Make next things chain into subchain of this */
1988 if (os
->addr_tree
==
1989 (etree_type
*)NULL
) {
1993 os
->block_value
= block_value
;
1994 stat_ptr
= & os
->children
;
2002 if (had_output_filename
== false) {
2003 lang_add_output("a.out");
2013 asymbol
*create_symbol(name
, flags
, section
)
2018 extern lang_input_statement_type
*script_file
;
2019 asymbol
**def_ptr
= (asymbol
**)ldmalloc(sizeof(asymbol
**));
2020 /* Add this definition to script file */
2021 asymbol
*def
= (asymbol
*)bfd_make_empty_symbol(script_file
->the_bfd
);
2025 def
->section
= section
;
2028 Q_enter_global_ref(def_ptr
);
2041 /* EXPORTED TO YACC */
2043 lang_section_start(name
, address
)
2045 etree_type
*address
;
2047 lang_address_statement_type
*ad
=new_stat(lang_address_statement
, stat_ptr
);
2048 ad
->section_name
= name
;
2049 ad
->address
= address
;
2051 void lang_add_entry(name
)
2054 entry_symbol
= name
;
2058 lang_add_target(name
)
2061 lang_target_statement_type
*new = new_stat(lang_target_statement
,
2067 lang_add_wild(section_name
, filename
)
2071 lang_wild_statement_type
*new = new_stat(lang_wild_statement
,
2074 if (section_name
!= (char *)NULL
&& strcmp(section_name
,"COMMON") == 0)
2076 placed_commons
= true;
2078 new->section_name
= section_name
;
2079 new->filename
= filename
;
2080 lang_list_init(&new->children
);
2090 map_option_f
= true;
2097 void lang_add_fill(exp
)
2100 lang_fill_statement_type
*new = new_stat(lang_fill_statement
,
2105 void lang_add_data(type
, exp
)
2107 union etree_union
*exp
;
2110 lang_data_statement_type
*new = new_stat(lang_data_statement
,
2117 lang_add_assignment(exp
)
2120 lang_assignment_statement_type
*new = new_stat(lang_assignment_statement
,
2126 lang_add_attribute(attribute
)
2127 enum statement_enum attribute
;
2129 new_statement(attribute
, sizeof(lang_statement_union_type
),stat_ptr
);
2138 if (startup_file
!= (char *)NULL
) {
2139 info("%P%FMultiple STARTUP files\n");
2141 first_file
->filename
= name
;
2142 first_file
->local_sym_name
= name
;
2150 lang_float_flag
= maybe
;
2154 lang_leave_output_section_statement(fill
, memspec
)
2158 current_section
->fill
= fill
;
2159 current_section
->region
= lang_memory_region_lookup(memspec
);
2160 stat_ptr
= &statement_list
;
2163 Create an absolute symbol with the given name with the value of the
2164 address of first byte of the section named.
2166 If the symbol already exists, then do nothing.
2169 lang_abs_symbol_at_beginning_of(section
, name
)
2173 if (ldsym_get_soft(name
) == (asymbol
*)NULL
) {
2174 extern bfd
*output_bfd
;
2175 extern asymbol
*create_symbol();
2176 asection
*s
= bfd_get_section_by_name(output_bfd
, section
);
2177 asymbol
*def
= create_symbol(name
,
2178 BSF_GLOBAL
| BSF_EXPORT
|
2181 if (s
!= (asection
*)NULL
) {
2182 def
->value
= s
->vma
;
2191 Create an absolute symbol with the given name with the value of the
2192 address of the first byte after the end of the section named.
2194 If the symbol already exists, then do nothing.
2197 lang_abs_symbol_at_end_of(section
, name
)
2201 if (ldsym_get_soft(name
) == (asymbol
*)NULL
) {
2202 extern bfd
*output_bfd
;
2203 extern asymbol
*create_symbol();
2204 asection
*s
= bfd_get_section_by_name(output_bfd
, section
);
2205 /* Add a symbol called _end */
2206 asymbol
*def
= create_symbol(name
,
2207 BSF_GLOBAL
| BSF_EXPORT
|
2210 if (s
!= (asection
*)NULL
) {
2211 def
->value
= s
->vma
+ s
->size
;
2220 lang_statement_append(list
, element
, field
)
2221 lang_statement_list_type
*list
;
2222 lang_statement_union_type
*element
;
2223 lang_statement_union_type
**field
;
2225 *(list
->tail
) = element
;
2231 lang_for_each_statement_worker(func
, s
)
2233 lang_statement_union_type
*s
;
2235 for (; s
!= (lang_statement_union_type
*)NULL
; s
= s
->next
)
2239 switch (s
->header
.type
) {
2240 case lang_output_section_statement_enum
:
2241 lang_for_each_statement_worker
2243 s
->output_section_statement
.children
.head
);
2245 case lang_wild_statement_enum
:
2246 lang_for_each_statement_worker
2248 s
->wild_statement
.children
.head
);
2250 case lang_data_statement_enum
:
2251 case lang_object_symbols_statement_enum
:
2252 case lang_output_statement_enum
:
2253 case lang_target_statement_enum
:
2254 case lang_common_statement_enum
:
2255 case lang_input_section_enum
:
2256 case lang_input_statement_enum
:
2257 case lang_fill_statement_enum
:
2258 case lang_assignment_statement_enum
:
2259 case lang_padding_statement_enum
:
2260 case lang_address_statement_enum
:
2269 void lang_for_each_statement(func
)
2272 lang_for_each_statement_worker(func
,
2273 statement_list
.head
);