1 /* Linker command language support.
2 Copyright (C) 1991, 92, 93, 94 Free Software Foundation, Inc.
4 This file is part of GLD, the Gnu Linker.
6 GLD is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
11 GLD is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GLD; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 #include "libiberty.h"
37 static void print_statements
PARAMS ((void));
38 static void print_statement
PARAMS ((lang_statement_union_type
*,
39 lang_output_section_statement_type
*));
40 static lang_statement_union_type
*new_statement
PARAMS ((enum statement_enum
,
42 lang_statement_list_type
*));
46 static struct obstack stat_obstack
;
48 #define obstack_chunk_alloc xmalloc
49 #define obstack_chunk_free free
50 static CONST
char *startup_file
;
51 static lang_statement_list_type input_file_chain
;
52 static boolean placed_commons
= false;
53 static lang_output_section_statement_type
*default_common_section
;
54 static boolean map_option_f
;
55 static bfd_vma print_dot
;
56 static lang_input_statement_type
*first_file
;
57 static lang_statement_list_type lang_output_section_statement
;
58 static CONST
char *current_target
;
59 static CONST
char *output_target
;
60 static int longest_section_name
= 8;
61 static lang_statement_list_type statement_list
;
63 static void print_size
PARAMS ((size_t value
));
64 static void print_alignment
PARAMS ((unsigned int value
));
65 static void print_fill
PARAMS ((fill_type value
));
66 static void print_section
PARAMS ((const char *name
));
67 static void lang_for_each_statement_worker
68 PARAMS ((void (*func
) (lang_statement_union_type
*),
69 lang_statement_union_type
*s
));
70 static lang_input_statement_type
*new_afile
71 PARAMS ((const char *name
, lang_input_file_enum_type file_type
,
72 const char *target
, boolean add_to_list
));
73 static void print_flags
PARAMS ((int *ignore_flags
));
74 static void init_os
PARAMS ((lang_output_section_statement_type
*s
));
75 static void wild_section
PARAMS ((lang_wild_statement_type
*ptr
,
77 lang_input_statement_type
*file
,
78 lang_output_section_statement_type
*output
));
79 static lang_input_statement_type
*lookup_name
PARAMS ((const char *name
));
80 static void load_symbols
PARAMS ((lang_input_statement_type
*entry
));
81 static void wild
PARAMS ((lang_wild_statement_type
*s
,
82 const char *section
, const char *file
,
84 lang_output_section_statement_type
*output
));
85 static bfd
*open_output
PARAMS ((const char *name
));
86 static void ldlang_open_output
PARAMS ((lang_statement_union_type
*statement
));
87 static void open_input_bfds
88 PARAMS ((lang_statement_union_type
*statement
, boolean
));
89 static void lang_reasonable_defaults
PARAMS ((void));
90 static void lang_place_undefineds
PARAMS ((void));
91 static void map_input_to_output_sections
92 PARAMS ((lang_statement_union_type
*s
,
94 lang_output_section_statement_type
*output_section_statement
));
95 static void print_output_section_statement
96 PARAMS ((lang_output_section_statement_type
*output_section_statement
));
97 static void print_assignment
98 PARAMS ((lang_assignment_statement_type
*assignment
,
99 lang_output_section_statement_type
*output_section
));
100 static void print_input_statement
PARAMS ((lang_input_statement_type
*statm
));
101 static void print_input_section
PARAMS ((lang_input_section_type
*in
));
102 static void print_fill_statement
PARAMS ((lang_fill_statement_type
*fill
));
103 static void print_data_statement
PARAMS ((lang_data_statement_type
*data
));
104 static void print_reloc_statement
PARAMS ((lang_reloc_statement_type
*reloc
));
105 static void print_padding_statement
PARAMS ((lang_padding_statement_type
*s
));
106 static void print_wild_statement
107 PARAMS ((lang_wild_statement_type
*w
,
108 lang_output_section_statement_type
*os
));
109 static void print_group
110 PARAMS ((lang_group_statement_type
*, lang_output_section_statement_type
*));
111 static void print_statement
PARAMS ((lang_statement_union_type
*s
,
112 lang_output_section_statement_type
*os
));
113 static void print_statements
PARAMS ((void));
114 static bfd_vma insert_pad
PARAMS ((lang_statement_union_type
**this_ptr
,
115 fill_type fill
, unsigned int power
,
116 asection
*output_section_statement
,
118 static bfd_vma size_input_section
119 PARAMS ((lang_statement_union_type
**this_ptr
,
120 lang_output_section_statement_type
*output_section_statement
,
121 fill_type fill
, bfd_vma dot
, boolean relax
));
122 static void lang_finish
PARAMS ((void));
123 static void lang_check
PARAMS ((void));
124 static void lang_common
PARAMS ((void));
125 static boolean lang_one_common
PARAMS ((struct bfd_link_hash_entry
*, PTR
));
126 static void lang_place_orphans
PARAMS ((void));
127 static int topower
PARAMS ((int));
128 static void reset_memory_regions
PARAMS ((void));
131 lang_output_section_statement_type
*abs_output_section
;
132 lang_statement_list_type
*stat_ptr
= &statement_list
;
133 lang_statement_list_type file_chain
= { 0 };
134 static const char *entry_symbol
= 0;
135 boolean lang_has_input_file
= false;
136 boolean had_output_filename
= false;
137 boolean lang_float_flag
= false;
138 boolean delete_output_file_on_failure
= false;
140 etree_type
*base
; /* Relocation base - or null */
143 #if defined(__STDC__) || defined(ALMOST_STDC)
144 #define cat(a,b) a##b
146 #define cat(a,b) a/**/b
149 #define new_stat(x,y) (cat(x,_type)*) new_statement(cat(x,_enum), sizeof(cat(x,_type)),y)
151 #define outside_section_address(q) ( (q)->output_offset + (q)->output_section->vma)
153 #define outside_symbol_address(q) ((q)->value + outside_section_address(q->section))
159 return obstack_alloc (&stat_obstack
, size
);
166 fprintf (config
.map_file
, "%5x", (unsigned) value
);
170 print_alignment (value
)
173 fprintf (config
.map_file
, "2**%1u", value
);
180 fprintf (config
.map_file
, "%04x", (unsigned) value
);
187 fprintf (config
.map_file
, "%*s", -longest_section_name
, name
);
190 /*----------------------------------------------------------------------
191 lang_for_each_statement walks the parse tree and calls the provided
192 function for each node
196 lang_for_each_statement_worker (func
, s
)
197 void (*func
) PARAMS ((lang_statement_union_type
*));
198 lang_statement_union_type
*s
;
200 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
204 switch (s
->header
.type
)
206 case lang_constructors_statement_enum
:
207 lang_for_each_statement_worker (func
, constructor_list
.head
);
209 case lang_output_section_statement_enum
:
210 lang_for_each_statement_worker
212 s
->output_section_statement
.children
.head
);
214 case lang_wild_statement_enum
:
215 lang_for_each_statement_worker
217 s
->wild_statement
.children
.head
);
219 case lang_group_statement_enum
:
220 lang_for_each_statement_worker (func
,
221 s
->group_statement
.children
.head
);
223 case lang_data_statement_enum
:
224 case lang_reloc_statement_enum
:
225 case lang_object_symbols_statement_enum
:
226 case lang_output_statement_enum
:
227 case lang_target_statement_enum
:
228 case lang_input_section_enum
:
229 case lang_input_statement_enum
:
230 case lang_assignment_statement_enum
:
231 case lang_padding_statement_enum
:
232 case lang_address_statement_enum
:
242 lang_for_each_statement (func
)
243 void (*func
) PARAMS ((lang_statement_union_type
*));
245 lang_for_each_statement_worker (func
,
246 statement_list
.head
);
249 /*----------------------------------------------------------------------*/
251 lang_list_init (list
)
252 lang_statement_list_type
*list
;
254 list
->head
= (lang_statement_union_type
*) NULL
;
255 list
->tail
= &list
->head
;
258 /*----------------------------------------------------------------------
260 build a new statement node for the parse tree
265 lang_statement_union_type
*
266 new_statement (type
, size
, list
)
267 enum statement_enum type
;
269 lang_statement_list_type
* list
;
271 lang_statement_union_type
*new = (lang_statement_union_type
*)
274 new->header
.type
= type
;
275 new->header
.next
= (lang_statement_union_type
*) NULL
;
276 lang_statement_append (list
, new, &new->header
.next
);
281 Build a new input file node for the language. There are several ways
282 in which we treat an input file, eg, we only look at symbols, or
283 prefix it with a -l etc.
285 We can be supplied with requests for input files more than once;
286 they may, for example be split over serveral lines like foo.o(.text)
287 foo.o(.data) etc, so when asked for a file we check that we havn't
288 got it already so we don't duplicate the bfd.
291 static lang_input_statement_type
*
292 new_afile (name
, file_type
, target
, add_to_list
)
294 lang_input_file_enum_type file_type
;
298 lang_input_statement_type
*p
;
301 p
= new_stat (lang_input_statement
, stat_ptr
);
304 p
= ((lang_input_statement_type
*)
305 stat_alloc (sizeof (lang_input_statement_type
)));
306 p
->header
.next
= NULL
;
309 lang_has_input_file
= true;
311 p
->complained
= false;
314 case lang_input_file_is_symbols_only_enum
:
316 p
->is_archive
= false;
318 p
->local_sym_name
= name
;
319 p
->just_syms_flag
= true;
320 p
->search_dirs_flag
= false;
322 case lang_input_file_is_fake_enum
:
324 p
->is_archive
= false;
326 p
->local_sym_name
= name
;
327 p
->just_syms_flag
= false;
328 p
->search_dirs_flag
= false;
330 case lang_input_file_is_l_enum
:
331 p
->is_archive
= true;
334 p
->local_sym_name
= concat ("-l", name
, (const char *) NULL
);
335 p
->just_syms_flag
= false;
336 p
->search_dirs_flag
= true;
338 case lang_input_file_is_marker_enum
:
340 p
->is_archive
= false;
342 p
->local_sym_name
= name
;
343 p
->just_syms_flag
= false;
344 p
->search_dirs_flag
= true;
346 case lang_input_file_is_search_file_enum
:
348 p
->is_archive
= false;
350 p
->local_sym_name
= name
;
351 p
->just_syms_flag
= false;
352 p
->search_dirs_flag
= true;
354 case lang_input_file_is_file_enum
:
356 p
->is_archive
= false;
358 p
->local_sym_name
= name
;
359 p
->just_syms_flag
= false;
360 p
->search_dirs_flag
= false;
365 p
->the_bfd
= (bfd
*) NULL
;
366 p
->asymbols
= (asymbol
**) NULL
;
367 p
->next_real_file
= (lang_statement_union_type
*) NULL
;
368 p
->next
= (lang_statement_union_type
*) NULL
;
370 p
->common_output_section
= (asection
*) NULL
;
372 lang_statement_append (&input_file_chain
,
373 (lang_statement_union_type
*) p
,
378 lang_input_statement_type
*
379 lang_add_input_file (name
, file_type
, target
)
381 lang_input_file_enum_type file_type
;
384 lang_has_input_file
= true;
385 return new_afile (name
, file_type
, target
, true);
388 /* Build enough state so that the parser can build its tree */
392 obstack_begin (&stat_obstack
, 1000);
394 stat_ptr
= &statement_list
;
396 lang_list_init (stat_ptr
);
398 lang_list_init (&input_file_chain
);
399 lang_list_init (&lang_output_section_statement
);
400 lang_list_init (&file_chain
);
401 first_file
= lang_add_input_file ((char *) NULL
,
402 lang_input_file_is_marker_enum
,
404 abs_output_section
= lang_output_section_statement_lookup (BFD_ABS_SECTION_NAME
);
406 abs_output_section
->bfd_section
= bfd_abs_section_ptr
;
410 /*----------------------------------------------------------------------
411 A region is an area of memory declared with the
412 MEMORY { name:org=exp, len=exp ... }
415 We maintain a list of all the regions here
417 If no regions are specified in the script, then the default is used
418 which is created when looked up to be the entire data space
421 static lang_memory_region_type
*lang_memory_region_list
;
422 static lang_memory_region_type
**lang_memory_region_list_tail
= &lang_memory_region_list
;
424 lang_memory_region_type
*
425 lang_memory_region_lookup (name
)
426 CONST
char *CONST name
;
429 lang_memory_region_type
*p
= lang_memory_region_list
;
431 for (p
= lang_memory_region_list
;
432 p
!= (lang_memory_region_type
*) NULL
;
435 if (strcmp (p
->name
, name
) == 0)
440 if (strcmp (name
, "*default*") == 0)
442 /* This is the default region, dig out first one on the list */
443 if (lang_memory_region_list
!= (lang_memory_region_type
*) NULL
)
445 return lang_memory_region_list
;
449 lang_memory_region_type
*new =
450 (lang_memory_region_type
*) stat_alloc ((bfd_size_type
) (sizeof (lang_memory_region_type
)));
452 new->name
= buystring (name
);
453 new->next
= (lang_memory_region_type
*) NULL
;
455 *lang_memory_region_list_tail
= new;
456 lang_memory_region_list_tail
= &new->next
;
458 new->length
= ~(bfd_size_type
)0;
460 new->had_full_message
= false;
467 lang_output_section_statement_type
*
468 lang_output_section_find (name
)
469 CONST
char *CONST name
;
471 lang_statement_union_type
*u
;
472 lang_output_section_statement_type
*lookup
;
474 for (u
= lang_output_section_statement
.head
;
475 u
!= (lang_statement_union_type
*) NULL
;
478 lookup
= &u
->output_section_statement
;
479 if (strcmp (name
, lookup
->name
) == 0)
484 return (lang_output_section_statement_type
*) NULL
;
487 lang_output_section_statement_type
*
488 lang_output_section_statement_lookup (name
)
489 CONST
char *CONST name
;
491 lang_output_section_statement_type
*lookup
;
493 lookup
= lang_output_section_find (name
);
494 if (lookup
== (lang_output_section_statement_type
*) NULL
)
497 lookup
= (lang_output_section_statement_type
*)
498 new_stat (lang_output_section_statement
, stat_ptr
);
499 lookup
->region
= (lang_memory_region_type
*) NULL
;
501 lookup
->block_value
= 1;
504 lookup
->next
= (lang_statement_union_type
*) NULL
;
505 lookup
->bfd_section
= (asection
*) NULL
;
506 lookup
->processed
= false;
507 lookup
->loadable
= 1;
508 lookup
->addr_tree
= (etree_type
*) NULL
;
509 lang_list_init (&lookup
->children
);
511 lookup
->memspec
= (CONST
char *) NULL
;
513 lookup
->subsection_alignment
= -1;
514 lookup
->section_alignment
= -1;
515 lookup
->load_base
= (union etree_union
*) NULL
;
517 lang_statement_append (&lang_output_section_statement
,
518 (lang_statement_union_type
*) lookup
,
526 print_flags (ignore_flags
)
529 fprintf (config
.map_file
, "(");
531 if (flags
->flag_read
)
532 fprintf (outfile
, "R");
533 if (flags
->flag_write
)
534 fprintf (outfile
, "W");
535 if (flags
->flag_executable
)
536 fprintf (outfile
, "X");
537 if (flags
->flag_loadable
)
538 fprintf (outfile
, "L");
540 fprintf (config
.map_file
, ")");
546 lang_memory_region_type
*m
;
548 fprintf (config
.map_file
, "**MEMORY CONFIGURATION**\n\n");
550 fprintf (config
.map_file
, "name\t\torigin\t\tlength\t\tattributes\n");
552 fprintf (config
.map_file
,
553 "name\t\torigin length r_size c_size is attributes\n");
556 for (m
= lang_memory_region_list
;
557 m
!= (lang_memory_region_type
*) NULL
;
560 fprintf (config
.map_file
, "%-16s", m
->name
);
561 print_address (m
->origin
);
563 print_address ((bfd_vma
)m
->length
);
565 print_address ((bfd_vma
)m
->old_length
);
567 print_address (m
->current
- m
->origin
);
570 fprintf (config
.map_file
, " %2d%% ",
571 (int) ((m
->current
- m
->origin
) * 100 / m
->old_length
));
572 print_flags (&m
->flags
);
573 fprintf (config
.map_file
, "\n");
575 fprintf (config
.map_file
, "\n\n**LINK EDITOR MEMORY MAP**\n\n");
576 fprintf (config
.map_file
, "output input virtual\n");
577 fprintf (config
.map_file
, "section section address tsize\n\n");
588 lang_output_section_statement_type
* s
;
590 /* asection *section = bfd_get_section_by_name(output_bfd, s->name);*/
591 section_userdata_type
*new =
592 (section_userdata_type
*)
593 stat_alloc ((bfd_size_type
) (sizeof (section_userdata_type
)));
595 s
->bfd_section
= bfd_get_section_by_name (output_bfd
, s
->name
);
596 if (s
->bfd_section
== (asection
*) NULL
)
597 s
->bfd_section
= bfd_make_section (output_bfd
, s
->name
);
598 if (s
->bfd_section
== (asection
*) NULL
)
600 einfo ("%P%F: output format %s cannot represent section called %s\n",
601 output_bfd
->xvec
->name
, s
->name
);
603 s
->bfd_section
->output_section
= s
->bfd_section
;
604 /* s->bfd_section->flags = s->flags;*/
606 /* We initialize an output sections output offset to minus its own */
607 /* vma to allow us to output a section through itself */
608 s
->bfd_section
->output_offset
= 0;
609 get_userdata (s
->bfd_section
) = (PTR
) new;
613 /***********************************************************************
616 These expand statements like *(.text) and foo.o to a list of
617 explicit actions, like foo.o(.text), bar.o(.text) and
620 The toplevel routine, wild, takes a statement, section, file and
621 target. If either the section or file is null it is taken to be the
622 wildcard. Seperate lang_input_section statements are created for
623 each part of the expanstion, and placed after the statement provided.
628 wild_doit (ptr
, section
, output
, file
)
629 lang_statement_list_type
* ptr
;
631 lang_output_section_statement_type
* output
;
632 lang_input_statement_type
* file
;
634 if (output
->bfd_section
== (asection
*) NULL
)
637 if (section
!= (asection
*) NULL
638 && section
->output_section
== (asection
*) NULL
)
640 /* Add a section reference to the list */
641 lang_input_section_type
*new = new_stat (lang_input_section
, ptr
);
643 new->section
= section
;
645 section
->output_section
= output
->bfd_section
;
647 /* We don't copy the SEC_NEVER_LOAD flag from an input section to
648 an output section, because we want to be able to include a
649 SEC_NEVER_LOAD section in the middle of an otherwise loaded
650 section (I don't know why we want to do this, but we do).
651 build_link_order in ldwrite.c handles this case by turning the
652 embedded SEC_NEVER_LOAD section into a fill. */
653 section
->output_section
->flags
|=
654 section
->flags
& (flagword
) (~ SEC_NEVER_LOAD
);
656 if (!output
->loadable
)
658 /* Turn off load flag */
659 output
->bfd_section
->flags
&= ~SEC_LOAD
;
660 output
->bfd_section
->flags
|= SEC_NEVER_LOAD
;
662 if (section
->alignment_power
> output
->bfd_section
->alignment_power
)
664 output
->bfd_section
->alignment_power
= section
->alignment_power
;
666 /* If supplied an aligmnet, then force it */
667 if (output
->section_alignment
!= -1)
669 output
->bfd_section
->alignment_power
= output
->section_alignment
;
675 wild_section (ptr
, section
, file
, output
)
676 lang_wild_statement_type
*ptr
;
678 lang_input_statement_type
*file
;
679 lang_output_section_statement_type
*output
;
681 if (file
->just_syms_flag
== false)
683 register asection
*s
;
685 for (s
= file
->the_bfd
->sections
; s
!= NULL
; s
= s
->next
)
687 /* Attach all sections named SECTION. If SECTION is NULL,
688 then attach all sections.
690 Previously, if SECTION was NULL, this code did not call
691 wild_doit if the SEC_IS_COMMON flag was set for the
692 section. I did not understand that, and I took it out.
696 || strcmp (bfd_get_section_name (file
->the_bfd
, s
),
698 wild_doit (&ptr
->children
, s
, output
, file
);
703 /* passed a file name (which must have been seen already and added to
704 the statement tree. We will see if it has been opened already and
705 had its symbols read. If not then we'll read it.
707 Archives are pecuilar here. We may open them once, but if they do
708 not define anything we need at the time, they won't have all their
709 symbols read. If we need them later, we'll have to redo it. */
710 static lang_input_statement_type
*
714 lang_input_statement_type
*search
;
716 for (search
= (lang_input_statement_type
*) input_file_chain
.head
;
717 search
!= (lang_input_statement_type
*) NULL
;
718 search
= (lang_input_statement_type
*) search
->next_real_file
)
720 if (search
->filename
== (char *) NULL
&& name
== (char *) NULL
)
722 if (search
->filename
!= (char *) NULL
723 && name
!= (char *) NULL
724 && strcmp (search
->filename
, name
) == 0)
728 if (search
== (lang_input_statement_type
*) NULL
)
729 search
= new_afile (name
, lang_input_file_is_file_enum
, default_target
,
732 /* If we have already added this file, or this file is not real
733 (FIXME: can that ever actually happen?) or the name is NULL
734 (FIXME: can that ever actually happen?) don't add this file. */
737 || search
->filename
== (const char *) NULL
)
740 load_symbols (search
);
745 /* Get the symbols for an input file. */
749 lang_input_statement_type
*entry
;
756 ldfile_open_file (entry
);
758 if (! bfd_check_format (entry
->the_bfd
, bfd_archive
)
759 && ! bfd_check_format_matches (entry
->the_bfd
, bfd_object
, &matching
))
763 err
= bfd_get_error ();
764 if (err
== bfd_error_file_ambiguously_recognized
)
768 einfo ("%B: file not recognized: %E\n", entry
->the_bfd
);
769 einfo ("%B: matching formats:", entry
->the_bfd
);
770 for (p
= matching
; *p
!= NULL
; p
++)
774 else if (err
!= bfd_error_file_not_recognized
)
775 einfo ("%F%B: file not recognized: %E\n", entry
->the_bfd
);
777 /* Try to interpret the file as a linker script. */
779 bfd_close (entry
->the_bfd
);
780 entry
->the_bfd
= NULL
;
782 ldfile_open_command_file (entry
->filename
);
784 ldfile_assumed_script
= true;
785 parser_input
= input_script
;
787 ldfile_assumed_script
= false;
792 /* We don't call ldlang_add_file for an archive. Instead, the
793 add_symbols entry point will call ldlang_add_file, via the
794 add_archive_element callback, for each element of the archive
796 if (bfd_get_format (entry
->the_bfd
) == bfd_object
)
798 ldlang_add_file (entry
);
799 if (trace_files
|| trace_file_tries
)
800 info_msg ("%I\n", entry
);
803 if (! bfd_link_add_symbols (entry
->the_bfd
, &link_info
))
804 einfo ("%F%B: could not read symbols: %E\n", entry
->the_bfd
);
806 entry
->loaded
= true;
810 wild (s
, section
, file
, target
, output
)
811 lang_wild_statement_type
* s
;
815 lang_output_section_statement_type
* output
;
817 lang_input_statement_type
*f
;
819 if (file
== (char *) NULL
)
821 /* Perform the iteration over all files in the list */
822 for (f
= (lang_input_statement_type
*) file_chain
.head
;
823 f
!= (lang_input_statement_type
*) NULL
;
824 f
= (lang_input_statement_type
*) f
->next
)
826 wild_section (s
, section
, f
, output
);
831 /* Perform the iteration over a single file */
832 wild_section (s
, section
, lookup_name (file
), output
);
834 if (section
!= (char *) NULL
835 && strcmp (section
, "COMMON") == 0
836 && default_common_section
== (lang_output_section_statement_type
*) NULL
)
838 /* Remember the section that common is going to incase we later
839 get something which doesn't know where to put it */
840 default_common_section
= output
;
845 read in all the files
854 if (output_target
== (char *) NULL
)
856 if (current_target
!= (char *) NULL
)
857 output_target
= current_target
;
859 output_target
= default_target
;
861 output
= bfd_openw (name
, output_target
);
863 if (output
== (bfd
*) NULL
)
865 if (bfd_get_error () == bfd_error_invalid_target
)
867 einfo ("%P%F: target %s not found\n", output_target
);
869 einfo ("%P%F: cannot open output file %s: %E\n", name
);
872 delete_output_file_on_failure
= 1;
874 /* output->flags |= D_PAGED;*/
876 if (! bfd_set_format (output
, bfd_object
))
877 einfo ("%P%F:%s: can not make object file: %E\n", name
);
878 if (! bfd_set_arch_mach (output
,
879 ldfile_output_architecture
,
880 ldfile_output_machine
))
881 einfo ("%P%F:%s: can not set architecture: %E\n", name
);
883 link_info
.hash
= bfd_link_hash_table_create (output
);
884 if (link_info
.hash
== (struct bfd_link_hash_table
*) NULL
)
885 einfo ("%P%F: can not create link hash table: %E\n");
887 bfd_set_gp_size (output
, g_switch_value
);
895 ldlang_open_output (statement
)
896 lang_statement_union_type
* statement
;
898 switch (statement
->header
.type
)
900 case lang_output_statement_enum
:
901 ASSERT (output_bfd
== (bfd
*) NULL
);
902 output_bfd
= open_output (statement
->output_statement
.name
);
903 ldemul_set_output_arch ();
904 if (config
.magic_demand_paged
&& !link_info
.relocateable
)
905 output_bfd
->flags
|= D_PAGED
;
907 output_bfd
->flags
&= ~D_PAGED
;
908 if (config
.text_read_only
)
909 output_bfd
->flags
|= WP_TEXT
;
911 output_bfd
->flags
&= ~WP_TEXT
;
912 if (config
.traditional_format
)
913 output_bfd
->flags
|= BFD_TRADITIONAL_FORMAT
;
915 output_bfd
->flags
&= ~BFD_TRADITIONAL_FORMAT
;
918 case lang_target_statement_enum
:
919 current_target
= statement
->target_statement
.target
;
926 /* Open all the input files. */
929 open_input_bfds (s
, force
)
930 lang_statement_union_type
*s
;
933 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
935 switch (s
->header
.type
)
937 case lang_constructors_statement_enum
:
938 open_input_bfds (constructor_list
.head
, force
);
940 case lang_output_section_statement_enum
:
941 open_input_bfds (s
->output_section_statement
.children
.head
, force
);
943 case lang_wild_statement_enum
:
944 /* Maybe we should load the file's symbols */
945 if (s
->wild_statement
.filename
)
946 (void) lookup_name (s
->wild_statement
.filename
);
947 open_input_bfds (s
->wild_statement
.children
.head
, force
);
949 case lang_group_statement_enum
:
951 struct bfd_link_hash_entry
*undefs
;
953 /* We must continually search the entries in the group
954 until no new symbols are added to the list of undefined
959 undefs
= link_info
.hash
->undefs_tail
;
960 open_input_bfds (s
->group_statement
.children
.head
, true);
962 while (undefs
!= link_info
.hash
->undefs_tail
);
965 case lang_target_statement_enum
:
966 current_target
= s
->target_statement
.target
;
968 case lang_input_statement_enum
:
969 if (s
->input_statement
.real
== true)
971 s
->input_statement
.target
= current_target
;
973 /* If we are being called from within a group, and this
974 is an archive which has already been searched, then
975 force it to be researched. */
977 && s
->input_statement
.loaded
978 && bfd_check_format (s
->input_statement
.the_bfd
,
980 s
->input_statement
.loaded
= false;
982 load_symbols (&s
->input_statement
);
991 /* If there are [COMMONS] statements, put a wild one into the bss section */
994 lang_reasonable_defaults ()
997 lang_output_section_statement_lookup (".text");
998 lang_output_section_statement_lookup (".data");
1000 default_common_section
=
1001 lang_output_section_statement_lookup (".bss");
1004 if (placed_commons
== false)
1006 lang_wild_statement_type
*new =
1007 new_stat (lang_wild_statement
,
1008 &default_common_section
->children
);
1010 new->section_name
= "COMMON";
1011 new->filename
= (char *) NULL
;
1012 lang_list_init (&new->children
);
1019 Add the supplied name to the symbol table as an undefined reference.
1020 Remove items from the chain as we open input bfds
1022 typedef struct ldlang_undef_chain_list
1024 struct ldlang_undef_chain_list
*next
;
1026 } ldlang_undef_chain_list_type
;
1028 static ldlang_undef_chain_list_type
*ldlang_undef_chain_list_head
;
1031 ldlang_add_undef (name
)
1032 CONST
char *CONST name
;
1034 ldlang_undef_chain_list_type
*new =
1035 (ldlang_undef_chain_list_type
1036 *) stat_alloc ((bfd_size_type
) (sizeof (ldlang_undef_chain_list_type
)));
1038 new->next
= ldlang_undef_chain_list_head
;
1039 ldlang_undef_chain_list_head
= new;
1041 new->name
= buystring (name
);
1044 /* Run through the list of undefineds created above and place them
1045 into the linker hash table as undefined symbols belonging to the
1049 lang_place_undefineds ()
1051 ldlang_undef_chain_list_type
*ptr
;
1053 for (ptr
= ldlang_undef_chain_list_head
;
1054 ptr
!= (ldlang_undef_chain_list_type
*) NULL
;
1057 struct bfd_link_hash_entry
*h
;
1059 h
= bfd_link_hash_lookup (link_info
.hash
, ptr
->name
, true, false, true);
1060 if (h
== (struct bfd_link_hash_entry
*) NULL
)
1061 einfo ("%P%F: bfd_link_hash_lookup failed: %E");
1062 if (h
->type
== bfd_link_hash_new
)
1064 h
->type
= bfd_link_hash_undefined
;
1065 h
->u
.undef
.abfd
= NULL
;
1066 bfd_link_add_undef (link_info
.hash
, h
);
1071 /* Open input files and attatch to output sections */
1073 map_input_to_output_sections (s
, target
, output_section_statement
)
1074 lang_statement_union_type
* s
;
1076 lang_output_section_statement_type
* output_section_statement
;
1078 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
1080 switch (s
->header
.type
)
1084 case lang_wild_statement_enum
:
1085 wild (&s
->wild_statement
, s
->wild_statement
.section_name
,
1086 s
->wild_statement
.filename
, target
,
1087 output_section_statement
);
1090 case lang_constructors_statement_enum
:
1091 map_input_to_output_sections (constructor_list
.head
,
1093 output_section_statement
);
1095 case lang_output_section_statement_enum
:
1096 map_input_to_output_sections (s
->output_section_statement
.children
.head
,
1098 &s
->output_section_statement
);
1100 case lang_output_statement_enum
:
1102 case lang_target_statement_enum
:
1103 target
= s
->target_statement
.target
;
1105 case lang_group_statement_enum
:
1106 map_input_to_output_sections (s
->group_statement
.children
.head
,
1108 output_section_statement
);
1110 case lang_fill_statement_enum
:
1111 case lang_input_section_enum
:
1112 case lang_object_symbols_statement_enum
:
1113 case lang_data_statement_enum
:
1114 case lang_reloc_statement_enum
:
1115 case lang_assignment_statement_enum
:
1116 case lang_padding_statement_enum
:
1117 case lang_input_statement_enum
:
1118 if (output_section_statement
!= NULL
1119 && output_section_statement
->bfd_section
== NULL
)
1120 init_os (output_section_statement
);
1122 case lang_afile_asection_pair_statement_enum
:
1125 case lang_address_statement_enum
:
1126 /* Mark the specified section with the supplied address */
1128 lang_output_section_statement_type
*os
=
1129 lang_output_section_statement_lookup
1130 (s
->address_statement
.section_name
);
1132 if (os
->bfd_section
== NULL
)
1134 os
->addr_tree
= s
->address_statement
.address
;
1142 print_output_section_statement (output_section_statement
)
1143 lang_output_section_statement_type
* output_section_statement
;
1145 asection
*section
= output_section_statement
->bfd_section
;
1148 print_section (output_section_statement
->name
);
1153 print_dot
= section
->vma
;
1157 print_address (section
->vma
);
1159 print_size (section
->_raw_size
);
1161 print_size(section
->_cooked_size
);
1163 print_alignment (section
->alignment_power
);
1166 fprintf (config
.map_file
, "%s flags", output_section_statement
->region
->name
);
1167 print_flags (stdout
, &output_section_statement
->flags
);
1169 if (section
->flags
& SEC_LOAD
)
1170 fprintf (config
.map_file
, "load ");
1171 if (section
->flags
& SEC_ALLOC
)
1172 fprintf (config
.map_file
, "alloc ");
1173 if (section
->flags
& SEC_RELOC
)
1174 fprintf (config
.map_file
, "reloc ");
1175 if (section
->flags
& SEC_HAS_CONTENTS
)
1176 fprintf (config
.map_file
, "contents ");
1181 fprintf (config
.map_file
, " (no attached output section)");
1184 if (output_section_statement
->load_base
)
1186 int b
= exp_get_abs_int(output_section_statement
->load_base
,
1187 0, "output base", lang_final_phase_enum
);
1188 fprintf (config
.map_file
, "Output address %08x\n", b
);
1190 if (output_section_statement
->section_alignment
>= 0
1191 || output_section_statement
->section_alignment
>= 0)
1193 fprintf (config
.map_file
, "\t\t\t\t\tforced alignment ");
1194 if (output_section_statement
->section_alignment
>= 0)
1196 fprintf (config
.map_file
, "section 2**%d ",output_section_statement
->section_alignment
);
1198 if ( output_section_statement
->subsection_alignment
>= 0)
1200 fprintf (config
.map_file
, "subsection 2**%d ",output_section_statement
->subsection_alignment
);
1205 print_statement (output_section_statement
->children
.head
,
1206 output_section_statement
);
1211 print_assignment (assignment
, output_section
)
1212 lang_assignment_statement_type
* assignment
;
1213 lang_output_section_statement_type
* output_section
;
1215 etree_value_type result
;
1221 print_address (print_dot
);
1223 result
= exp_fold_tree (assignment
->exp
->assign
.src
,
1225 lang_final_phase_enum
,
1231 print_address (result
.value
);
1235 fprintf (config
.map_file
, "*undefined*");
1238 exp_print_tree (assignment
->exp
);
1240 fprintf (config
.map_file
, "\n");
1244 print_input_statement (statm
)
1245 lang_input_statement_type
* statm
;
1247 if (statm
->filename
!= (char *) NULL
)
1249 fprintf (config
.map_file
, "LOAD %s\n", statm
->filename
);
1253 /* Print all the defined symbols for the abfd provided by in the supplied
1258 print_one_symbol (hash_entry
, ptr
)
1259 struct bfd_link_hash_entry
*hash_entry
;
1262 asection
* sec
= (asection
*)ptr
;
1264 if (hash_entry
->type
== bfd_link_hash_defined
)
1266 if (sec
== hash_entry
->u
.def
.section
) {
1268 fprintf (config
.map_file
, " ");
1270 fprintf (config
.map_file
, " ");
1271 print_address (hash_entry
->u
.def
.value
+ outside_section_address (sec
));
1272 fprintf (config
.map_file
, " %s", hash_entry
->root
.string
);
1281 print_input_section (in
)
1282 lang_input_section_type
* in
;
1284 asection
*i
= in
->section
;
1285 bfd_size_type size
= i
->_cooked_size
!= 0 ? i
->_cooked_size
: i
->_raw_size
;
1290 fprintf (config
.map_file
, " ");
1291 print_section (i
->name
);
1292 fprintf (config
.map_file
, " ");
1293 if (i
->output_section
)
1295 print_address (i
->output_section
->vma
+ i
->output_offset
);
1296 fprintf (config
.map_file
, " ");
1297 print_size (i
->_raw_size
);
1298 fprintf (config
.map_file
, " ");
1299 print_size(i
->_cooked_size
);
1300 fprintf (config
.map_file
, " ");
1301 print_alignment (i
->alignment_power
);
1302 fprintf (config
.map_file
, " ");
1306 bfd
*abfd
= in
->ifile
->the_bfd
;
1308 if (in
->ifile
->just_syms_flag
== true)
1310 fprintf (config
.map_file
, "symbols only ");
1313 fprintf (config
.map_file
, " %s ", abfd
->xvec
->name
);
1314 if (abfd
->my_archive
!= (bfd
*) NULL
)
1316 fprintf (config
.map_file
, "[%s]%s", abfd
->my_archive
->filename
,
1321 fprintf (config
.map_file
, "%s", abfd
->filename
);
1323 fprintf (config
.map_file
, "(overhead %d bytes)", (int) bfd_alloc_size (abfd
));
1326 /* Print all the symbols */
1327 bfd_link_hash_traverse (link_info
.hash
, print_one_symbol
, (PTR
) i
);
1335 print_dot
= outside_section_address (i
) + size
;
1339 fprintf (config
.map_file
, "No output section allocated\n");
1345 print_fill_statement (fill
)
1346 lang_fill_statement_type
* fill
;
1348 fprintf (config
.map_file
, "FILL mask ");
1349 print_fill (fill
->fill
);
1353 print_data_statement (data
)
1354 lang_data_statement_type
* data
;
1356 /* bfd_vma value; */
1361 /* ASSERT(print_dot == data->output_vma);*/
1363 print_address (data
->output_vma
+ data
->output_section
->vma
);
1365 print_address (data
->value
);
1370 fprintf (config
.map_file
, "BYTE ");
1371 print_dot
+= BYTE_SIZE
;
1374 fprintf (config
.map_file
, "SHORT ");
1375 print_dot
+= SHORT_SIZE
;
1378 fprintf (config
.map_file
, "LONG ");
1379 print_dot
+= LONG_SIZE
;
1382 fprintf (config
.map_file
, "QUAD ");
1383 print_dot
+= QUAD_SIZE
;
1387 exp_print_tree (data
->exp
);
1389 fprintf (config
.map_file
, "\n");
1392 /* Print a reloc statement. */
1395 print_reloc_statement (reloc
)
1396 lang_reloc_statement_type
*reloc
;
1403 /* ASSERT(print_dot == data->output_vma);*/
1405 print_address (reloc
->output_vma
+ reloc
->output_section
->vma
);
1407 print_address (reloc
->addend_value
);
1410 fprintf (config
.map_file
, "RELOC %s ", reloc
->howto
->name
);
1412 print_dot
+= bfd_get_reloc_size (reloc
->howto
);
1414 exp_print_tree (reloc
->addend_exp
);
1416 fprintf (config
.map_file
, "\n");
1420 print_padding_statement (s
)
1421 lang_padding_statement_type
* s
;
1425 print_section ("*fill*");
1427 print_address (s
->output_offset
+ s
->output_section
->vma
);
1429 print_size (s
->size
);
1431 print_fill (s
->fill
);
1434 print_dot
= s
->output_offset
+ s
->output_section
->vma
+ s
->size
;
1439 print_wild_statement (w
, os
)
1440 lang_wild_statement_type
* w
;
1441 lang_output_section_statement_type
* os
;
1443 fprintf (config
.map_file
, " from ");
1444 if (w
->filename
!= (char *) NULL
)
1446 fprintf (config
.map_file
, "%s", w
->filename
);
1450 fprintf (config
.map_file
, "*");
1452 if (w
->section_name
!= (char *) NULL
)
1454 fprintf (config
.map_file
, "(%s)", w
->section_name
);
1458 fprintf (config
.map_file
, "(*)");
1461 print_statement (w
->children
.head
, os
);
1465 /* Print a group statement. */
1469 lang_group_statement_type
*s
;
1470 lang_output_section_statement_type
*os
;
1472 fprintf (config
.map_file
, "START GROUP\n");
1473 print_statement (s
->children
.head
, os
);
1474 fprintf (config
.map_file
, "END GROUP\n");
1478 print_statement (s
, os
)
1479 lang_statement_union_type
* s
;
1480 lang_output_section_statement_type
* os
;
1484 switch (s
->header
.type
)
1486 case lang_constructors_statement_enum
:
1487 fprintf (config
.map_file
, "constructors:\n");
1488 print_statement (constructor_list
.head
, os
);
1490 case lang_wild_statement_enum
:
1491 print_wild_statement (&s
->wild_statement
, os
);
1494 fprintf (config
.map_file
, "Fail with %d\n", s
->header
.type
);
1497 case lang_address_statement_enum
:
1498 fprintf (config
.map_file
, "address\n");
1500 case lang_object_symbols_statement_enum
:
1501 fprintf (config
.map_file
, "object symbols\n");
1503 case lang_fill_statement_enum
:
1504 print_fill_statement (&s
->fill_statement
);
1506 case lang_data_statement_enum
:
1507 print_data_statement (&s
->data_statement
);
1509 case lang_reloc_statement_enum
:
1510 print_reloc_statement (&s
->reloc_statement
);
1512 case lang_input_section_enum
:
1513 print_input_section (&s
->input_section
);
1515 case lang_padding_statement_enum
:
1516 print_padding_statement (&s
->padding_statement
);
1518 case lang_output_section_statement_enum
:
1519 print_output_section_statement (&s
->output_section_statement
);
1521 case lang_assignment_statement_enum
:
1522 print_assignment (&s
->assignment_statement
,
1525 case lang_target_statement_enum
:
1526 fprintf (config
.map_file
, "TARGET(%s)\n", s
->target_statement
.target
);
1528 case lang_output_statement_enum
:
1529 fprintf (config
.map_file
, "OUTPUT(%s %s)\n",
1530 s
->output_statement
.name
,
1531 output_target
? output_target
: "");
1533 case lang_input_statement_enum
:
1534 print_input_statement (&s
->input_statement
);
1536 case lang_group_statement_enum
:
1537 print_group (&s
->group_statement
, os
);
1539 case lang_afile_asection_pair_statement_enum
:
1551 print_statement (statement_list
.head
,
1552 abs_output_section
);
1557 insert_pad (this_ptr
, fill
, power
, output_section_statement
, dot
)
1558 lang_statement_union_type
** this_ptr
;
1561 asection
* output_section_statement
;
1564 /* Align this section first to the
1565 input sections requirement, then
1566 to the output section's requirement.
1567 If this alignment is > than any seen before,
1568 then record it too. Perform the alignment by
1569 inserting a magic 'padding' statement.
1572 unsigned int alignment_needed
= align_power (dot
, power
) - dot
;
1574 if (alignment_needed
!= 0)
1576 lang_statement_union_type
*new =
1577 (lang_statement_union_type
*)
1578 stat_alloc ((bfd_size_type
) (sizeof (lang_padding_statement_type
)));
1580 /* Link into existing chain */
1581 new->header
.next
= *this_ptr
;
1583 new->header
.type
= lang_padding_statement_enum
;
1584 new->padding_statement
.output_section
= output_section_statement
;
1585 new->padding_statement
.output_offset
=
1586 dot
- output_section_statement
->vma
;
1587 new->padding_statement
.fill
= fill
;
1588 new->padding_statement
.size
= alignment_needed
;
1592 /* Remember the most restrictive alignment */
1593 if (power
> output_section_statement
->alignment_power
)
1595 output_section_statement
->alignment_power
= power
;
1597 output_section_statement
->_raw_size
+= alignment_needed
;
1598 return alignment_needed
+ dot
;
1602 /* Work out how much this section will move the dot point */
1604 size_input_section (this_ptr
, output_section_statement
, fill
, dot
, relax
)
1605 lang_statement_union_type
** this_ptr
;
1606 lang_output_section_statement_type
* output_section_statement
;
1611 lang_input_section_type
*is
= &((*this_ptr
)->input_section
);
1612 asection
*i
= is
->section
;
1614 if (is
->ifile
->just_syms_flag
== false)
1616 if (output_section_statement
->subsection_alignment
!= -1)
1617 i
->alignment_power
=
1618 output_section_statement
->subsection_alignment
;
1620 dot
= insert_pad (this_ptr
, fill
, i
->alignment_power
,
1621 output_section_statement
->bfd_section
, dot
);
1623 /* Remember where in the output section this input section goes */
1625 i
->output_offset
= dot
- output_section_statement
->bfd_section
->vma
;
1627 /* Mark how big the output section must be to contain this now
1629 if (i
->_cooked_size
!= 0)
1630 dot
+= i
->_cooked_size
;
1632 dot
+= i
->_raw_size
;
1633 output_section_statement
->bfd_section
->_raw_size
= dot
- output_section_statement
->bfd_section
->vma
;
1637 i
->output_offset
= i
->vma
- output_section_statement
->bfd_section
->vma
;
1643 /* This variable indicates whether bfd_relax_section should be called
1646 static boolean relax_again
;
1648 /* Set the sizes for all the output sections. */
1651 lang_size_sections (s
, output_section_statement
, prev
, fill
, dot
, relax
)
1652 lang_statement_union_type
* s
;
1653 lang_output_section_statement_type
* output_section_statement
;
1654 lang_statement_union_type
** prev
;
1659 /* Size up the sections from their constituent parts */
1660 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
1662 switch (s
->header
.type
)
1665 case lang_output_section_statement_enum
:
1668 lang_output_section_statement_type
*os
= &s
->output_section_statement
;
1670 if (os
->bfd_section
== NULL
)
1672 /* This section was never actually created. */
1676 /* If this is a COFF shared library section, use the size and
1677 address from the input section. FIXME: This is COFF
1678 specific; it would be cleaner if there were some other way
1679 to do this, but nothing simple comes to mind. */
1680 if ((os
->bfd_section
->flags
& SEC_COFF_SHARED_LIBRARY
) != 0)
1684 if (os
->children
.head
== NULL
1685 || os
->children
.head
->next
!= NULL
1686 || os
->children
.head
->header
.type
!= lang_input_section_enum
)
1687 einfo ("%P%X: Internal error on COFF shared library section %s",
1690 input
= os
->children
.head
->input_section
.section
;
1691 bfd_set_section_vma (os
->bfd_section
->owner
,
1693 bfd_section_vma (input
->owner
, input
));
1694 os
->bfd_section
->_raw_size
= input
->_raw_size
;
1698 if (bfd_is_abs_section (os
->bfd_section
))
1700 /* No matter what happens, an abs section starts at zero */
1701 ASSERT (os
->bfd_section
->vma
== 0);
1705 if (os
->addr_tree
== (etree_type
*) NULL
)
1707 /* No address specified for this section, get one
1708 from the region specification
1710 if (os
->region
== (lang_memory_region_type
*) NULL
)
1712 os
->region
= lang_memory_region_lookup ("*default*");
1714 dot
= os
->region
->current
;
1715 if (os
->section_alignment
== -1)
1716 dot
= align_power (dot
, os
->bfd_section
->alignment_power
);
1722 r
= exp_fold_tree (os
->addr_tree
,
1724 lang_allocating_phase_enum
,
1726 if (r
.valid
== false)
1728 einfo ("%F%S: non constant address expression for section %s\n",
1733 /* The section starts here */
1734 /* First, align to what the section needs */
1736 if (os
->section_alignment
!= -1)
1737 dot
= align_power (dot
, os
->section_alignment
);
1739 bfd_set_section_vma (0, os
->bfd_section
, dot
);
1741 os
->bfd_section
->output_offset
= 0;
1744 (void) lang_size_sections (os
->children
.head
, os
, &os
->children
.head
,
1745 os
->fill
, dot
, relax
);
1746 /* Ignore the size of the input sections, use the vma and size to */
1749 after
= ALIGN_N (os
->bfd_section
->vma
+
1750 os
->bfd_section
->_raw_size
,
1751 /* The coercion here is important, see ld.h. */
1752 (bfd_vma
) os
->block_value
);
1754 if (bfd_is_abs_section (os
->bfd_section
))
1755 ASSERT (after
== os
->bfd_section
->vma
);
1757 os
->bfd_section
->_raw_size
= after
- os
->bfd_section
->vma
;
1758 dot
= os
->bfd_section
->vma
+ os
->bfd_section
->_raw_size
;
1759 os
->processed
= true;
1761 /* Replace into region ? */
1762 if (os
->region
!= (lang_memory_region_type
*) NULL
)
1764 os
->region
->current
= dot
;
1765 /* Make sure this isn't silly */
1766 if (( os
->region
->current
1767 > os
->region
->origin
+ os
->region
->length
)
1768 || ( os
->region
->origin
> os
->region
->current
))
1770 einfo ("%X%P: region %s is full (%B section %s)\n",
1772 os
->bfd_section
->owner
,
1773 os
->bfd_section
->name
);
1774 /* Reset the region pointer */
1775 os
->region
->current
= 0;
1785 case lang_constructors_statement_enum
:
1786 dot
= lang_size_sections (constructor_list
.head
,
1787 output_section_statement
,
1788 &s
->wild_statement
.children
.head
,
1793 case lang_data_statement_enum
:
1795 unsigned int size
= 0;
1797 s
->data_statement
.output_vma
= dot
- output_section_statement
->bfd_section
->vma
;
1798 s
->data_statement
.output_section
=
1799 output_section_statement
->bfd_section
;
1801 switch (s
->data_statement
.type
)
1818 output_section_statement
->bfd_section
->_raw_size
+= size
;
1822 case lang_reloc_statement_enum
:
1826 s
->reloc_statement
.output_vma
=
1827 dot
- output_section_statement
->bfd_section
->vma
;
1828 s
->reloc_statement
.output_section
=
1829 output_section_statement
->bfd_section
;
1830 size
= bfd_get_reloc_size (s
->reloc_statement
.howto
);
1832 output_section_statement
->bfd_section
->_raw_size
+= size
;
1836 case lang_wild_statement_enum
:
1838 dot
= lang_size_sections (s
->wild_statement
.children
.head
,
1839 output_section_statement
,
1840 &s
->wild_statement
.children
.head
,
1846 case lang_object_symbols_statement_enum
:
1847 link_info
.create_object_symbols_section
=
1848 output_section_statement
->bfd_section
;
1850 case lang_output_statement_enum
:
1851 case lang_target_statement_enum
:
1853 case lang_input_section_enum
:
1857 i
= (*prev
)->input_section
.section
;
1859 i
->_cooked_size
= i
->_raw_size
;
1864 if (! bfd_relax_section (i
->owner
, i
, &link_info
, &again
))
1865 einfo ("%P%F: can't relax section: %E\n");
1869 dot
= size_input_section (prev
,
1870 output_section_statement
,
1871 output_section_statement
->fill
,
1875 case lang_input_statement_enum
:
1877 case lang_fill_statement_enum
:
1878 s
->fill_statement
.output_section
= output_section_statement
->bfd_section
;
1880 fill
= s
->fill_statement
.fill
;
1882 case lang_assignment_statement_enum
:
1884 bfd_vma newdot
= dot
;
1886 exp_fold_tree (s
->assignment_statement
.exp
,
1887 output_section_statement
,
1888 lang_allocating_phase_enum
,
1892 if (newdot
!= dot
&& !relax
)
1894 /* The assignment changed dot. Insert a pad. */
1895 if (output_section_statement
== abs_output_section
)
1897 /* If we don't have an output section, then just adjust
1898 the default memory address. */
1899 lang_memory_region_lookup ("*default*")->current
= newdot
;
1903 lang_statement_union_type
*new =
1904 ((lang_statement_union_type
*)
1905 stat_alloc (sizeof (lang_padding_statement_type
)));
1907 /* Link into existing chain */
1908 new->header
.next
= *prev
;
1910 new->header
.type
= lang_padding_statement_enum
;
1911 new->padding_statement
.output_section
=
1912 output_section_statement
->bfd_section
;
1913 new->padding_statement
.output_offset
=
1914 dot
- output_section_statement
->bfd_section
->vma
;
1915 new->padding_statement
.fill
= fill
;
1916 new->padding_statement
.size
= newdot
- dot
;
1917 output_section_statement
->bfd_section
->_raw_size
+=
1918 new->padding_statement
.size
;
1926 case lang_padding_statement_enum
:
1927 /* If we are relaxing, and this is not the first pass, some
1928 padding statements may have been inserted during previous
1929 passes. We may have to move the padding statement to a new
1930 location if dot has a different value at this point in this
1931 pass than it did at this point in the previous pass. */
1932 s
->padding_statement
.output_offset
=
1933 dot
- output_section_statement
->bfd_section
->vma
;
1934 dot
+= s
->padding_statement
.size
;
1937 case lang_group_statement_enum
:
1938 dot
= lang_size_sections (s
->group_statement
.children
.head
,
1939 output_section_statement
,
1940 &s
->group_statement
.children
.head
,
1948 /* This can only get here when relaxing is turned on */
1950 case lang_address_statement_enum
:
1953 prev
= &s
->header
.next
;
1959 lang_do_assignments (s
, output_section_statement
, fill
, dot
)
1960 lang_statement_union_type
* s
;
1961 lang_output_section_statement_type
* output_section_statement
;
1965 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
1967 switch (s
->header
.type
)
1969 case lang_constructors_statement_enum
:
1970 dot
= lang_do_assignments (constructor_list
.head
,
1971 output_section_statement
,
1976 case lang_output_section_statement_enum
:
1978 lang_output_section_statement_type
*os
=
1979 &(s
->output_section_statement
);
1981 if (os
->bfd_section
!= NULL
)
1983 dot
= os
->bfd_section
->vma
;
1984 (void) lang_do_assignments (os
->children
.head
, os
,
1986 dot
= os
->bfd_section
->vma
+ os
->bfd_section
->_raw_size
;
1990 /* If nothing has been placed into the output section then
1991 it won't have a bfd_section. */
1992 if (os
->bfd_section
)
1994 os
->bfd_section
->lma
1995 = exp_get_abs_int(os
->load_base
, 0,"load base", lang_final_phase_enum
);
2000 case lang_wild_statement_enum
:
2002 dot
= lang_do_assignments (s
->wild_statement
.children
.head
,
2003 output_section_statement
,
2008 case lang_object_symbols_statement_enum
:
2009 case lang_output_statement_enum
:
2010 case lang_target_statement_enum
:
2012 case lang_common_statement_enum
:
2015 case lang_data_statement_enum
:
2017 etree_value_type value
;
2019 value
= exp_fold_tree (s
->data_statement
.exp
,
2021 lang_final_phase_enum
, dot
, &dot
);
2022 s
->data_statement
.value
= value
.value
;
2023 if (value
.valid
== false)
2024 einfo ("%F%P: invalid data statement\n");
2026 switch (s
->data_statement
.type
)
2043 case lang_reloc_statement_enum
:
2045 etree_value_type value
;
2047 value
= exp_fold_tree (s
->reloc_statement
.addend_exp
,
2049 lang_final_phase_enum
, dot
, &dot
);
2050 s
->reloc_statement
.addend_value
= value
.value
;
2051 if (value
.valid
== false)
2052 einfo ("%F%P: invalid reloc statement\n");
2054 dot
+= bfd_get_reloc_size (s
->reloc_statement
.howto
);
2057 case lang_input_section_enum
:
2059 asection
*in
= s
->input_section
.section
;
2061 if (in
->_cooked_size
!= 0)
2062 dot
+= in
->_cooked_size
;
2064 dot
+= in
->_raw_size
;
2068 case lang_input_statement_enum
:
2070 case lang_fill_statement_enum
:
2071 fill
= s
->fill_statement
.fill
;
2073 case lang_assignment_statement_enum
:
2075 exp_fold_tree (s
->assignment_statement
.exp
,
2076 output_section_statement
,
2077 lang_final_phase_enum
,
2083 case lang_padding_statement_enum
:
2084 dot
+= s
->padding_statement
.size
;
2087 case lang_group_statement_enum
:
2088 dot
= lang_do_assignments (s
->group_statement
.children
.head
,
2089 output_section_statement
,
2097 case lang_address_statement_enum
:
2108 struct bfd_link_hash_entry
*h
;
2109 boolean warn
= link_info
.relocateable
? false : true;
2111 if (entry_symbol
== (char *) NULL
)
2113 /* No entry has been specified. Look for start, but don't warn
2114 if we don't find it. */
2115 entry_symbol
= "start";
2119 h
= bfd_link_hash_lookup (link_info
.hash
, entry_symbol
, false, false, true);
2120 if (h
!= (struct bfd_link_hash_entry
*) NULL
2121 && h
->type
== bfd_link_hash_defined
)
2125 val
= (h
->u
.def
.value
2126 + bfd_get_section_vma (output_bfd
,
2127 h
->u
.def
.section
->output_section
)
2128 + h
->u
.def
.section
->output_offset
);
2129 if (! bfd_set_start_address (output_bfd
, val
))
2130 einfo ("%P%F:%s: can't set start address\n", entry_symbol
);
2136 /* Can't find the entry symbol. Use the first address in the
2138 ts
= bfd_get_section_by_name (output_bfd
, ".text");
2139 if (ts
!= (asection
*) NULL
)
2142 einfo ("%P: warning: cannot find entry symbol %s; defaulting to %V\n",
2143 entry_symbol
, bfd_get_section_vma (output_bfd
, ts
));
2144 if (! bfd_set_start_address (output_bfd
,
2145 bfd_get_section_vma (output_bfd
, ts
)))
2146 einfo ("%P%F: can't set start address\n");
2151 einfo ("%P: warning: cannot find entry symbol %s; not setting start address\n",
2157 /* Check that the architecture of all the input files is compatible
2158 with the output file. */
2163 lang_statement_union_type
*file
;
2165 CONST bfd_arch_info_type
*compatible
;
2167 for (file
= file_chain
.head
;
2168 file
!= (lang_statement_union_type
*) NULL
;
2169 file
= file
->input_statement
.next
)
2171 input_bfd
= file
->input_statement
.the_bfd
;
2172 compatible
= bfd_arch_get_compatible (input_bfd
,
2174 if (compatible
== NULL
)
2175 einfo ("%P: warning: %s architecture of input file `%B' is incompatible with %s output\n",
2176 bfd_printable_name (input_bfd
), input_bfd
,
2177 bfd_printable_name (output_bfd
));
2181 /* Look through all the global common symbols and attach them to the
2182 correct section. The -sort-common command line switch may be used
2183 to roughly sort the entries by size. */
2188 if (link_info
.relocateable
2189 && ! command_line
.force_common_definition
)
2192 if (! config
.sort_common
)
2193 bfd_link_hash_traverse (link_info
.hash
, lang_one_common
, (PTR
) NULL
);
2198 for (power
= 1; power
< 4; power
++)
2199 bfd_link_hash_traverse (link_info
.hash
, lang_one_common
,
2204 /* Place one common symbol in the correct section. */
2207 lang_one_common (h
, info
)
2208 struct bfd_link_hash_entry
*h
;
2211 unsigned int power_of_two
;
2215 if (h
->type
!= bfd_link_hash_common
)
2219 power_of_two
= h
->u
.c
.alignment_power
;
2221 if (config
.sort_common
2222 && power_of_two
< *(unsigned int *) info
2223 && *(unsigned int *) info
< 4)
2226 section
= h
->u
.c
.section
;
2228 /* Increase the size of the section. */
2229 section
->_raw_size
= ALIGN_N (section
->_raw_size
,
2230 (bfd_size_type
) (1 << power_of_two
));
2232 /* Adjust the alignment if necessary. */
2233 if (power_of_two
> section
->alignment_power
)
2234 section
->alignment_power
= power_of_two
;
2236 /* Change the symbol from common to defined. */
2237 h
->type
= bfd_link_hash_defined
;
2238 h
->u
.def
.section
= section
;
2239 h
->u
.def
.value
= section
->_raw_size
;
2241 /* Increase the size of the section. */
2242 section
->_raw_size
+= size
;
2244 if (config
.map_file
!= NULL
)
2245 fprintf (config
.map_file
, "Allocating common %s: %lx at %lx %s\n",
2246 h
->root
.string
, (unsigned long) size
,
2247 (unsigned long) h
->u
.def
.value
, section
->owner
->filename
);
2253 run through the input files and ensure that every input
2254 section has somewhere to go. If one is found without
2255 a destination then create an input request and place it
2256 into the statement tree.
2260 lang_place_orphans ()
2262 lang_input_statement_type
*file
;
2264 for (file
= (lang_input_statement_type
*) file_chain
.head
;
2265 file
!= (lang_input_statement_type
*) NULL
;
2266 file
= (lang_input_statement_type
*) file
->next
)
2270 if (file
->just_syms_flag
)
2273 for (s
= file
->the_bfd
->sections
;
2274 s
!= (asection
*) NULL
;
2277 if (s
->output_section
== (asection
*) NULL
)
2279 /* This section of the file is not attatched, root
2280 around for a sensible place for it to go */
2282 if (file
->common_section
== s
)
2284 /* This is a lonely common section which must
2285 have come from an archive. We attatch to the
2286 section with the wildcard */
2287 if (! link_info
.relocateable
2288 && ! command_line
.force_common_definition
)
2290 if (default_common_section
==
2291 (lang_output_section_statement_type
*) NULL
)
2293 info_msg ("%P: no [COMMON] command, defaulting to .bss\n");
2295 default_common_section
=
2296 lang_output_section_statement_lookup (".bss");
2299 wild_doit (&default_common_section
->children
, s
,
2300 default_common_section
, file
);
2303 else if (ldemul_place_orphan (file
, s
))
2307 lang_output_section_statement_type
*os
=
2308 lang_output_section_statement_lookup (s
->name
);
2310 wild_doit (&os
->children
, s
, os
, file
);
2319 lang_set_flags (ptr
, flags
)
2323 boolean state
= false;
2338 /* ptr->flag_read = state; */
2341 /* ptr->flag_write = state; */
2344 /* ptr->flag_executable= state;*/
2348 /* ptr->flag_loadable= state;*/
2351 einfo ("%P%F: invalid syntax in flags\n");
2358 /* Call a function on each input file. This function will be called
2359 on an archive, but not on the elements. */
2362 lang_for_each_input_file (func
)
2363 void (*func
) PARAMS ((lang_input_statement_type
*));
2365 lang_input_statement_type
*f
;
2367 for (f
= (lang_input_statement_type
*) input_file_chain
.head
;
2369 f
= (lang_input_statement_type
*) f
->next_real_file
)
2373 /* Call a function on each file. The function will be called on all
2374 the elements of an archive which are included in the link, but will
2375 not be called on the archive file itself. */
2378 lang_for_each_file (func
)
2379 void (*func
) PARAMS ((lang_input_statement_type
*));
2381 lang_input_statement_type
*f
;
2383 for (f
= (lang_input_statement_type
*) file_chain
.head
;
2384 f
!= (lang_input_statement_type
*) NULL
;
2385 f
= (lang_input_statement_type
*) f
->next
)
2396 lang_for_each_input_section (func
)
2397 void (*func
) PARAMS ((bfd
* ab
, asection
* as
));
2399 lang_input_statement_type
*f
;
2401 for (f
= (lang_input_statement_type
*) file_chain
.head
;
2402 f
!= (lang_input_statement_type
*) NULL
;
2403 f
= (lang_input_statement_type
*) f
->next
)
2407 for (s
= f
->the_bfd
->sections
;
2408 s
!= (asection
*) NULL
;
2411 func (f
->the_bfd
, s
);
2419 ldlang_add_file (entry
)
2420 lang_input_statement_type
* entry
;
2424 lang_statement_append (&file_chain
,
2425 (lang_statement_union_type
*) entry
,
2428 /* The BFD linker needs to have a list of all input BFDs involved in
2430 ASSERT (entry
->the_bfd
->link_next
== (bfd
*) NULL
);
2431 ASSERT (entry
->the_bfd
!= output_bfd
);
2432 for (pp
= &link_info
.input_bfds
;
2433 *pp
!= (bfd
*) NULL
;
2434 pp
= &(*pp
)->link_next
)
2436 *pp
= entry
->the_bfd
;
2437 entry
->the_bfd
->usrdata
= (PTR
) entry
;
2438 bfd_set_gp_size (entry
->the_bfd
, g_switch_value
);
2442 lang_add_output (name
, from_script
)
2446 /* Make -o on command line override OUTPUT in script. */
2447 if (had_output_filename
== false || !from_script
)
2449 output_filename
= name
;
2450 had_output_filename
= true;
2455 static lang_output_section_statement_type
*current_section
;
2457 static int topower(x
)
2462 if (x
< 0) return -1;
2463 for (l
= 0; l
< 32; l
++)
2465 if (i
>= x
) return l
;
2471 lang_enter_output_section_statement (output_section_statement_name
,
2472 address_exp
, flags
, block_value
,
2473 align
, subalign
, ebase
)
2474 const char *output_section_statement_name
;
2475 etree_type
* address_exp
;
2477 bfd_vma block_value
;
2479 etree_type
*subalign
;
2482 lang_output_section_statement_type
*os
;
2486 lang_output_section_statement_lookup (output_section_statement_name
);
2490 /* Add this statement to tree */
2491 /* add_statement(lang_output_section_statement_enum,
2492 output_section_statement);*/
2493 /* Make next things chain into subchain of this */
2495 if (os
->addr_tree
==
2496 (etree_type
*) NULL
)
2502 if (flags
& SEC_NEVER_LOAD
)
2506 os
->block_value
= block_value
? block_value
: 1;
2507 stat_ptr
= &os
->children
;
2509 os
->subsection_alignment
= topower(
2510 exp_get_value_int(subalign
, -1,
2511 "subsection alignment",
2513 os
->section_alignment
= topower(
2514 exp_get_value_int(align
, -1,
2515 "section alignment", 0));
2517 os
->load_base
= ebase
;
2524 lang_output_statement_type
*new =
2525 new_stat (lang_output_statement
, stat_ptr
);
2527 new->name
= output_filename
;
2530 /* Reset the current counters in the regions */
2532 reset_memory_regions ()
2534 lang_memory_region_type
*p
= lang_memory_region_list
;
2536 for (p
= lang_memory_region_list
;
2537 p
!= (lang_memory_region_type
*) NULL
;
2540 p
->old_length
= (bfd_size_type
) (p
->current
- p
->origin
);
2541 p
->current
= p
->origin
;
2548 lang_reasonable_defaults ();
2549 current_target
= default_target
;
2551 lang_for_each_statement (ldlang_open_output
); /* Open the output file */
2553 ldemul_create_output_section_statements ();
2555 /* Add to the hash table all undefineds on the command line */
2556 lang_place_undefineds ();
2558 /* Create a bfd for each input file */
2559 current_target
= default_target
;
2560 open_input_bfds (statement_list
.head
, false);
2562 /* Build all sets based on the information gathered from the input
2564 ldctor_build_sets ();
2566 /* Size up the common data */
2569 /* Run through the contours of the script and attatch input sections
2570 to the correct output sections
2572 map_input_to_output_sections (statement_list
.head
, (char *) NULL
,
2573 (lang_output_section_statement_type
*) NULL
);
2576 /* Find any sections not attatched explicitly and handle them */
2577 lang_place_orphans ();
2579 ldemul_before_allocation ();
2581 /* Now run around and relax if we can */
2582 if (command_line
.relax
)
2584 /* First time round is a trial run to get the 'worst case'
2585 addresses of the objects if there was no relaxing. */
2586 lang_size_sections (statement_list
.head
,
2588 &(statement_list
.head
), 0, (bfd_vma
) 0, false);
2591 reset_memory_regions ();
2593 /* Keep relaxing until bfd_relax_section gives up. */
2596 relax_again
= false;
2598 /* Do all the assignments with our current guesses as to
2600 lang_do_assignments (statement_list
.head
,
2602 (fill_type
) 0, (bfd_vma
) 0);
2604 /* Perform another relax pass - this time we know where the
2605 globals are, so can make better guess. */
2606 lang_size_sections (statement_list
.head
,
2608 &(statement_list
.head
), 0, (bfd_vma
) 0, true);
2610 while (relax_again
);
2614 /* Size up the sections. */
2615 lang_size_sections (statement_list
.head
,
2617 &(statement_list
.head
), 0, (bfd_vma
) 0, false);
2620 /* See if anything special should be done now we know how big
2622 ldemul_after_allocation ();
2624 /* Do all the assignments, now that we know the final restingplaces
2625 of all the symbols */
2627 lang_do_assignments (statement_list
.head
,
2629 (fill_type
) 0, (bfd_vma
) 0);
2631 /* Make sure that we're not mixing architectures */
2641 /* EXPORTED TO YACC */
2644 lang_add_wild (section_name
, filename
)
2645 CONST
char *CONST section_name
;
2646 CONST
char *CONST filename
;
2648 lang_wild_statement_type
*new = new_stat (lang_wild_statement
,
2651 if (section_name
!= (char *) NULL
&& strcmp (section_name
, "COMMON") == 0)
2653 placed_commons
= true;
2655 if (filename
!= (char *) NULL
)
2657 lang_has_input_file
= true;
2659 new->section_name
= section_name
;
2660 new->filename
= filename
;
2661 lang_list_init (&new->children
);
2665 lang_section_start (name
, address
)
2667 etree_type
* address
;
2669 lang_address_statement_type
*ad
= new_stat (lang_address_statement
, stat_ptr
);
2671 ad
->section_name
= name
;
2672 ad
->address
= address
;
2675 /* Set the start symbol to NAME. CMDLINE is nonzero if this is called
2676 because of a -e argument on the command line, or zero if this is
2677 called by ENTRY in a linker script. Command line arguments take
2681 lang_add_entry (name
, cmdline
)
2685 static int from_cmdline
;
2687 if (entry_symbol
== NULL
2691 entry_symbol
= name
;
2692 from_cmdline
= cmdline
;
2697 lang_add_target (name
)
2700 lang_target_statement_type
*new = new_stat (lang_target_statement
,
2716 map_option_f
= true;
2727 lang_fill_statement_type
*new = new_stat (lang_fill_statement
,
2734 lang_add_data (type
, exp
)
2736 union etree_union
*exp
;
2739 lang_data_statement_type
*new = new_stat (lang_data_statement
,
2747 /* Create a new reloc statement. RELOC is the BFD relocation type to
2748 generate. HOWTO is the corresponding howto structure (we could
2749 look this up, but the caller has already done so). SECTION is the
2750 section to generate a reloc against, or NAME is the name of the
2751 symbol to generate a reloc against. Exactly one of SECTION and
2752 NAME must be NULL. ADDEND is an expression for the addend. */
2755 lang_add_reloc (reloc
, howto
, section
, name
, addend
)
2756 bfd_reloc_code_real_type reloc
;
2757 const reloc_howto_type
*howto
;
2760 union etree_union
*addend
;
2762 lang_reloc_statement_type
*p
= new_stat (lang_reloc_statement
, stat_ptr
);
2766 p
->section
= section
;
2768 p
->addend_exp
= addend
;
2770 p
->addend_value
= 0;
2771 p
->output_section
= NULL
;
2776 lang_add_assignment (exp
)
2779 lang_assignment_statement_type
*new = new_stat (lang_assignment_statement
,
2786 lang_add_attribute (attribute
)
2787 enum statement_enum attribute
;
2789 new_statement (attribute
, sizeof (lang_statement_union_type
), stat_ptr
);
2796 if (startup_file
!= (char *) NULL
)
2798 einfo ("%P%Fmultiple STARTUP files\n");
2800 first_file
->filename
= name
;
2801 first_file
->local_sym_name
= name
;
2802 first_file
->real
= true;
2804 startup_file
= name
;
2811 lang_float_flag
= maybe
;
2815 lang_leave_output_section_statement (fill
, memspec
)
2817 CONST
char *memspec
;
2819 current_section
->fill
= fill
;
2820 current_section
->region
= lang_memory_region_lookup (memspec
);
2821 stat_ptr
= &statement_list
;
2825 Create an absolute symbol with the given name with the value of the
2826 address of first byte of the section named.
2828 If the symbol already exists, then do nothing.
2831 lang_abs_symbol_at_beginning_of (secname
, name
)
2832 const char *secname
;
2835 struct bfd_link_hash_entry
*h
;
2837 h
= bfd_link_hash_lookup (link_info
.hash
, name
, true, true, true);
2838 if (h
== (struct bfd_link_hash_entry
*) NULL
)
2839 einfo ("%P%F: bfd_link_hash_lookup failed: %E\n");
2841 if (h
->type
== bfd_link_hash_new
2842 || h
->type
== bfd_link_hash_undefined
)
2846 h
->type
= bfd_link_hash_defined
;
2848 sec
= bfd_get_section_by_name (output_bfd
, secname
);
2849 if (sec
== (asection
*) NULL
)
2852 h
->u
.def
.value
= bfd_get_section_vma (output_bfd
, sec
);
2854 h
->u
.def
.section
= bfd_abs_section_ptr
;
2859 Create an absolute symbol with the given name with the value of the
2860 address of the first byte after the end of the section named.
2862 If the symbol already exists, then do nothing.
2865 lang_abs_symbol_at_end_of (secname
, name
)
2866 const char *secname
;
2869 struct bfd_link_hash_entry
*h
;
2871 h
= bfd_link_hash_lookup (link_info
.hash
, name
, true, true, true);
2872 if (h
== (struct bfd_link_hash_entry
*) NULL
)
2873 einfo ("%P%F: bfd_link_hash_lookup failed: %E\n");
2875 if (h
->type
== bfd_link_hash_new
2876 || h
->type
== bfd_link_hash_undefined
)
2880 h
->type
= bfd_link_hash_defined
;
2882 sec
= bfd_get_section_by_name (output_bfd
, secname
);
2883 if (sec
== (asection
*) NULL
)
2886 h
->u
.def
.value
= (bfd_get_section_vma (output_bfd
, sec
)
2887 + bfd_section_size (output_bfd
, sec
));
2889 h
->u
.def
.section
= bfd_abs_section_ptr
;
2894 lang_statement_append (list
, element
, field
)
2895 lang_statement_list_type
* list
;
2896 lang_statement_union_type
* element
;
2897 lang_statement_union_type
** field
;
2899 *(list
->tail
) = element
;
2903 /* Set the output format type. -oformat overrides scripts. */
2905 lang_add_output_format (format
, from_script
)
2909 if (output_target
== NULL
|| !from_script
)
2910 output_target
= format
;
2913 /* Enter a group. This creates a new lang_group_statement, and sets
2914 stat_ptr to build new statements within the group. */
2919 lang_group_statement_type
*g
;
2921 g
= new_stat (lang_group_statement
, stat_ptr
);
2922 lang_list_init (&g
->children
);
2923 stat_ptr
= &g
->children
;
2926 /* Leave a group. This just resets stat_ptr to start writing to the
2927 regular list of statements again. Note that this will not work if
2928 groups can occur inside anything else which can adjust stat_ptr,
2929 but currently they can't. */
2934 stat_ptr
= &statement_list
;