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_doit
PARAMS ((lang_statement_list_type
*ptr
,
77 lang_output_section_statement_type
*output
,
78 lang_input_statement_type
*file
));
79 static void wild_section
PARAMS ((lang_wild_statement_type
*ptr
,
81 lang_input_statement_type
*file
,
82 lang_output_section_statement_type
*output
));
83 static lang_input_statement_type
*lookup_name
PARAMS ((const char *name
));
84 static void load_symbols
PARAMS ((lang_input_statement_type
*entry
));
85 static void wild
PARAMS ((lang_wild_statement_type
*s
,
86 const char *section
, const char *file
,
88 lang_output_section_statement_type
*output
));
89 static bfd
*open_output
PARAMS ((const char *name
));
90 static void ldlang_open_output
PARAMS ((lang_statement_union_type
*statement
));
91 static void open_input_bfds
92 PARAMS ((lang_statement_union_type
*statement
, boolean
));
93 static void lang_reasonable_defaults
PARAMS ((void));
94 static void lang_place_undefineds
PARAMS ((void));
95 static void map_input_to_output_sections
96 PARAMS ((lang_statement_union_type
*s
,
98 lang_output_section_statement_type
*output_section_statement
));
99 static void print_output_section_statement
100 PARAMS ((lang_output_section_statement_type
*output_section_statement
));
101 static void print_assignment
102 PARAMS ((lang_assignment_statement_type
*assignment
,
103 lang_output_section_statement_type
*output_section
));
104 static void print_input_statement
PARAMS ((lang_input_statement_type
*statm
));
105 static void print_input_section
PARAMS ((lang_input_section_type
*in
));
106 static void print_fill_statement
PARAMS ((lang_fill_statement_type
*fill
));
107 static void print_data_statement
PARAMS ((lang_data_statement_type
*data
));
108 static void print_reloc_statement
PARAMS ((lang_reloc_statement_type
*reloc
));
109 static void print_padding_statement
PARAMS ((lang_padding_statement_type
*s
));
110 static void print_wild_statement
111 PARAMS ((lang_wild_statement_type
*w
,
112 lang_output_section_statement_type
*os
));
113 static void print_group
114 PARAMS ((lang_group_statement_type
*, lang_output_section_statement_type
*));
115 static void print_statement
PARAMS ((lang_statement_union_type
*s
,
116 lang_output_section_statement_type
*os
));
117 static void print_statements
PARAMS ((void));
118 static bfd_vma insert_pad
PARAMS ((lang_statement_union_type
**this_ptr
,
119 fill_type fill
, unsigned int power
,
120 asection
*output_section_statement
,
122 static bfd_vma size_input_section
123 PARAMS ((lang_statement_union_type
**this_ptr
,
124 lang_output_section_statement_type
*output_section_statement
,
125 fill_type fill
, bfd_vma dot
, boolean relax
));
126 static void lang_finish
PARAMS ((void));
127 static void lang_check
PARAMS ((void));
128 static void lang_common
PARAMS ((void));
129 static boolean lang_one_common
PARAMS ((struct bfd_link_hash_entry
*, PTR
));
130 static void lang_place_orphans
PARAMS ((void));
131 static int topower
PARAMS ((int));
132 static void reset_memory_regions
PARAMS ((void));
135 lang_output_section_statement_type
*abs_output_section
;
136 lang_statement_list_type
*stat_ptr
= &statement_list
;
137 lang_statement_list_type file_chain
= { 0 };
138 static const char *entry_symbol
= 0;
139 boolean lang_has_input_file
= false;
140 boolean had_output_filename
= false;
141 boolean lang_float_flag
= false;
142 boolean delete_output_file_on_failure
= false;
144 etree_type
*base
; /* Relocation base - or null */
147 #if defined(__STDC__) || defined(ALMOST_STDC)
148 #define cat(a,b) a##b
150 #define cat(a,b) a/**/b
153 #define new_stat(x,y) (cat(x,_type)*) new_statement(cat(x,_enum), sizeof(cat(x,_type)),y)
155 #define outside_section_address(q) ( (q)->output_offset + (q)->output_section->vma)
157 #define outside_symbol_address(q) ((q)->value + outside_section_address(q->section))
163 return obstack_alloc (&stat_obstack
, size
);
170 fprintf (config
.map_file
, "%5x", (unsigned) value
);
174 print_alignment (value
)
177 fprintf (config
.map_file
, "2**%1u", value
);
184 fprintf (config
.map_file
, "%04x", (unsigned) value
);
191 fprintf (config
.map_file
, "%*s", -longest_section_name
, name
);
194 /*----------------------------------------------------------------------
195 lang_for_each_statement walks the parse tree and calls the provided
196 function for each node
200 lang_for_each_statement_worker (func
, s
)
201 void (*func
) PARAMS ((lang_statement_union_type
*));
202 lang_statement_union_type
*s
;
204 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
208 switch (s
->header
.type
)
210 case lang_constructors_statement_enum
:
211 lang_for_each_statement_worker (func
, constructor_list
.head
);
213 case lang_output_section_statement_enum
:
214 lang_for_each_statement_worker
216 s
->output_section_statement
.children
.head
);
218 case lang_wild_statement_enum
:
219 lang_for_each_statement_worker
221 s
->wild_statement
.children
.head
);
223 case lang_group_statement_enum
:
224 lang_for_each_statement_worker (func
,
225 s
->group_statement
.children
.head
);
227 case lang_data_statement_enum
:
228 case lang_reloc_statement_enum
:
229 case lang_object_symbols_statement_enum
:
230 case lang_output_statement_enum
:
231 case lang_target_statement_enum
:
232 case lang_input_section_enum
:
233 case lang_input_statement_enum
:
234 case lang_assignment_statement_enum
:
235 case lang_padding_statement_enum
:
236 case lang_address_statement_enum
:
246 lang_for_each_statement (func
)
247 void (*func
) PARAMS ((lang_statement_union_type
*));
249 lang_for_each_statement_worker (func
,
250 statement_list
.head
);
253 /*----------------------------------------------------------------------*/
255 lang_list_init (list
)
256 lang_statement_list_type
*list
;
258 list
->head
= (lang_statement_union_type
*) NULL
;
259 list
->tail
= &list
->head
;
262 /*----------------------------------------------------------------------
264 build a new statement node for the parse tree
269 lang_statement_union_type
*
270 new_statement (type
, size
, list
)
271 enum statement_enum type
;
273 lang_statement_list_type
* list
;
275 lang_statement_union_type
*new = (lang_statement_union_type
*)
278 new->header
.type
= type
;
279 new->header
.next
= (lang_statement_union_type
*) NULL
;
280 lang_statement_append (list
, new, &new->header
.next
);
285 Build a new input file node for the language. There are several ways
286 in which we treat an input file, eg, we only look at symbols, or
287 prefix it with a -l etc.
289 We can be supplied with requests for input files more than once;
290 they may, for example be split over serveral lines like foo.o(.text)
291 foo.o(.data) etc, so when asked for a file we check that we havn't
292 got it already so we don't duplicate the bfd.
295 static lang_input_statement_type
*
296 new_afile (name
, file_type
, target
, add_to_list
)
298 lang_input_file_enum_type file_type
;
302 lang_input_statement_type
*p
;
305 p
= new_stat (lang_input_statement
, stat_ptr
);
308 p
= ((lang_input_statement_type
*)
309 stat_alloc (sizeof (lang_input_statement_type
)));
310 p
->header
.next
= NULL
;
313 lang_has_input_file
= true;
315 p
->complained
= false;
318 case lang_input_file_is_symbols_only_enum
:
320 p
->is_archive
= false;
322 p
->local_sym_name
= name
;
323 p
->just_syms_flag
= true;
324 p
->search_dirs_flag
= false;
326 case lang_input_file_is_fake_enum
:
328 p
->is_archive
= false;
330 p
->local_sym_name
= name
;
331 p
->just_syms_flag
= false;
332 p
->search_dirs_flag
= false;
334 case lang_input_file_is_l_enum
:
335 p
->is_archive
= true;
338 p
->local_sym_name
= concat ("-l", name
, (const char *) NULL
);
339 p
->just_syms_flag
= false;
340 p
->search_dirs_flag
= true;
342 case lang_input_file_is_marker_enum
:
344 p
->is_archive
= false;
346 p
->local_sym_name
= name
;
347 p
->just_syms_flag
= false;
348 p
->search_dirs_flag
= true;
350 case lang_input_file_is_search_file_enum
:
352 p
->is_archive
= false;
354 p
->local_sym_name
= name
;
355 p
->just_syms_flag
= false;
356 p
->search_dirs_flag
= true;
358 case lang_input_file_is_file_enum
:
360 p
->is_archive
= false;
362 p
->local_sym_name
= name
;
363 p
->just_syms_flag
= false;
364 p
->search_dirs_flag
= false;
369 p
->the_bfd
= (bfd
*) NULL
;
370 p
->asymbols
= (asymbol
**) NULL
;
371 p
->next_real_file
= (lang_statement_union_type
*) NULL
;
372 p
->next
= (lang_statement_union_type
*) NULL
;
374 p
->common_output_section
= (asection
*) NULL
;
376 lang_statement_append (&input_file_chain
,
377 (lang_statement_union_type
*) p
,
382 lang_input_statement_type
*
383 lang_add_input_file (name
, file_type
, target
)
385 lang_input_file_enum_type file_type
;
388 lang_has_input_file
= true;
389 return new_afile (name
, file_type
, target
, true);
392 /* Build enough state so that the parser can build its tree */
396 obstack_begin (&stat_obstack
, 1000);
398 stat_ptr
= &statement_list
;
400 lang_list_init (stat_ptr
);
402 lang_list_init (&input_file_chain
);
403 lang_list_init (&lang_output_section_statement
);
404 lang_list_init (&file_chain
);
405 first_file
= lang_add_input_file ((char *) NULL
,
406 lang_input_file_is_marker_enum
,
408 abs_output_section
= lang_output_section_statement_lookup (BFD_ABS_SECTION_NAME
);
410 abs_output_section
->bfd_section
= bfd_abs_section_ptr
;
414 /*----------------------------------------------------------------------
415 A region is an area of memory declared with the
416 MEMORY { name:org=exp, len=exp ... }
419 We maintain a list of all the regions here
421 If no regions are specified in the script, then the default is used
422 which is created when looked up to be the entire data space
425 static lang_memory_region_type
*lang_memory_region_list
;
426 static lang_memory_region_type
**lang_memory_region_list_tail
= &lang_memory_region_list
;
428 lang_memory_region_type
*
429 lang_memory_region_lookup (name
)
430 CONST
char *CONST name
;
433 lang_memory_region_type
*p
= lang_memory_region_list
;
435 for (p
= lang_memory_region_list
;
436 p
!= (lang_memory_region_type
*) NULL
;
439 if (strcmp (p
->name
, name
) == 0)
444 if (strcmp (name
, "*default*") == 0)
446 /* This is the default region, dig out first one on the list */
447 if (lang_memory_region_list
!= (lang_memory_region_type
*) NULL
)
449 return lang_memory_region_list
;
453 lang_memory_region_type
*new =
454 (lang_memory_region_type
*) stat_alloc ((bfd_size_type
) (sizeof (lang_memory_region_type
)));
456 new->name
= buystring (name
);
457 new->next
= (lang_memory_region_type
*) NULL
;
459 *lang_memory_region_list_tail
= new;
460 lang_memory_region_list_tail
= &new->next
;
462 new->length
= ~(bfd_size_type
)0;
464 new->had_full_message
= false;
471 lang_output_section_statement_type
*
472 lang_output_section_find (name
)
473 CONST
char *CONST name
;
475 lang_statement_union_type
*u
;
476 lang_output_section_statement_type
*lookup
;
478 for (u
= lang_output_section_statement
.head
;
479 u
!= (lang_statement_union_type
*) NULL
;
482 lookup
= &u
->output_section_statement
;
483 if (strcmp (name
, lookup
->name
) == 0)
488 return (lang_output_section_statement_type
*) NULL
;
491 lang_output_section_statement_type
*
492 lang_output_section_statement_lookup (name
)
493 CONST
char *CONST name
;
495 lang_output_section_statement_type
*lookup
;
497 lookup
= lang_output_section_find (name
);
498 if (lookup
== (lang_output_section_statement_type
*) NULL
)
501 lookup
= (lang_output_section_statement_type
*)
502 new_stat (lang_output_section_statement
, stat_ptr
);
503 lookup
->region
= (lang_memory_region_type
*) NULL
;
505 lookup
->block_value
= 1;
508 lookup
->next
= (lang_statement_union_type
*) NULL
;
509 lookup
->bfd_section
= (asection
*) NULL
;
510 lookup
->processed
= false;
511 lookup
->loadable
= 1;
512 lookup
->addr_tree
= (etree_type
*) NULL
;
513 lang_list_init (&lookup
->children
);
515 lookup
->memspec
= (CONST
char *) NULL
;
517 lookup
->subsection_alignment
= -1;
518 lookup
->section_alignment
= -1;
519 lookup
->load_base
= (union etree_union
*) NULL
;
521 lang_statement_append (&lang_output_section_statement
,
522 (lang_statement_union_type
*) lookup
,
530 print_flags (ignore_flags
)
533 fprintf (config
.map_file
, "(");
535 if (flags
->flag_read
)
536 fprintf (outfile
, "R");
537 if (flags
->flag_write
)
538 fprintf (outfile
, "W");
539 if (flags
->flag_executable
)
540 fprintf (outfile
, "X");
541 if (flags
->flag_loadable
)
542 fprintf (outfile
, "L");
544 fprintf (config
.map_file
, ")");
550 lang_memory_region_type
*m
;
552 fprintf (config
.map_file
, "**MEMORY CONFIGURATION**\n\n");
554 fprintf (config
.map_file
, "name\t\torigin\t\tlength\t\tattributes\n");
556 fprintf (config
.map_file
,
557 "name\t\torigin length r_size c_size is attributes\n");
560 for (m
= lang_memory_region_list
;
561 m
!= (lang_memory_region_type
*) NULL
;
564 fprintf (config
.map_file
, "%-16s", m
->name
);
565 print_address (m
->origin
);
567 print_address ((bfd_vma
)m
->length
);
569 print_address ((bfd_vma
)m
->old_length
);
571 print_address (m
->current
- m
->origin
);
574 fprintf (config
.map_file
, " %2d%% ",
575 (int) ((m
->current
- m
->origin
) * 100 / m
->old_length
));
576 print_flags (&m
->flags
);
577 fprintf (config
.map_file
, "\n");
579 fprintf (config
.map_file
, "\n\n**LINK EDITOR MEMORY MAP**\n\n");
580 fprintf (config
.map_file
, "output input virtual\n");
581 fprintf (config
.map_file
, "section section address tsize\n\n");
592 lang_output_section_statement_type
* s
;
594 /* asection *section = bfd_get_section_by_name(output_bfd, s->name);*/
595 section_userdata_type
*new =
596 (section_userdata_type
*)
597 stat_alloc ((bfd_size_type
) (sizeof (section_userdata_type
)));
599 s
->bfd_section
= bfd_get_section_by_name (output_bfd
, s
->name
);
600 if (s
->bfd_section
== (asection
*) NULL
)
601 s
->bfd_section
= bfd_make_section (output_bfd
, s
->name
);
602 if (s
->bfd_section
== (asection
*) NULL
)
604 einfo ("%P%F: output format %s cannot represent section called %s\n",
605 output_bfd
->xvec
->name
, s
->name
);
607 s
->bfd_section
->output_section
= s
->bfd_section
;
608 /* s->bfd_section->flags = s->flags;*/
610 /* We initialize an output sections output offset to minus its own */
611 /* vma to allow us to output a section through itself */
612 s
->bfd_section
->output_offset
= 0;
613 get_userdata (s
->bfd_section
) = (PTR
) new;
617 /***********************************************************************
620 These expand statements like *(.text) and foo.o to a list of
621 explicit actions, like foo.o(.text), bar.o(.text) and
624 The toplevel routine, wild, takes a statement, section, file and
625 target. If either the section or file is null it is taken to be the
626 wildcard. Seperate lang_input_section statements are created for
627 each part of the expanstion, and placed after the statement provided.
632 wild_doit (ptr
, section
, output
, file
)
633 lang_statement_list_type
* ptr
;
635 lang_output_section_statement_type
* output
;
636 lang_input_statement_type
* file
;
638 if (output
->bfd_section
== (asection
*) NULL
)
641 if (section
!= (asection
*) NULL
642 && section
->output_section
== (asection
*) NULL
)
644 /* Add a section reference to the list */
645 lang_input_section_type
*new = new_stat (lang_input_section
, ptr
);
647 new->section
= section
;
649 section
->output_section
= output
->bfd_section
;
651 /* We don't copy the SEC_NEVER_LOAD flag from an input section to
652 an output section, because we want to be able to include a
653 SEC_NEVER_LOAD section in the middle of an otherwise loaded
654 section (I don't know why we want to do this, but we do).
655 build_link_order in ldwrite.c handles this case by turning the
656 embedded SEC_NEVER_LOAD section into a fill. */
657 section
->output_section
->flags
|=
658 section
->flags
& (flagword
) (~ SEC_NEVER_LOAD
);
660 if (!output
->loadable
)
662 /* Turn off load flag */
663 output
->bfd_section
->flags
&= ~SEC_LOAD
;
664 output
->bfd_section
->flags
|= SEC_NEVER_LOAD
;
666 if (section
->alignment_power
> output
->bfd_section
->alignment_power
)
668 output
->bfd_section
->alignment_power
= section
->alignment_power
;
670 /* If supplied an aligmnet, then force it */
671 if (output
->section_alignment
!= -1)
673 output
->bfd_section
->alignment_power
= output
->section_alignment
;
679 wild_section (ptr
, section
, file
, output
)
680 lang_wild_statement_type
*ptr
;
682 lang_input_statement_type
*file
;
683 lang_output_section_statement_type
*output
;
685 if (file
->just_syms_flag
== false)
687 register asection
*s
;
689 for (s
= file
->the_bfd
->sections
; s
!= NULL
; s
= s
->next
)
691 /* Attach all sections named SECTION. If SECTION is NULL,
692 then attach all sections.
694 Previously, if SECTION was NULL, this code did not call
695 wild_doit if the SEC_IS_COMMON flag was set for the
696 section. I did not understand that, and I took it out.
700 || strcmp (bfd_get_section_name (file
->the_bfd
, s
),
702 wild_doit (&ptr
->children
, s
, output
, file
);
707 /* passed a file name (which must have been seen already and added to
708 the statement tree. We will see if it has been opened already and
709 had its symbols read. If not then we'll read it.
711 Archives are pecuilar here. We may open them once, but if they do
712 not define anything we need at the time, they won't have all their
713 symbols read. If we need them later, we'll have to redo it. */
714 static lang_input_statement_type
*
718 lang_input_statement_type
*search
;
720 for (search
= (lang_input_statement_type
*) input_file_chain
.head
;
721 search
!= (lang_input_statement_type
*) NULL
;
722 search
= (lang_input_statement_type
*) search
->next_real_file
)
724 if (search
->filename
== (char *) NULL
&& name
== (char *) NULL
)
726 if (search
->filename
!= (char *) NULL
727 && name
!= (char *) NULL
728 && strcmp (search
->filename
, name
) == 0)
732 if (search
== (lang_input_statement_type
*) NULL
)
733 search
= new_afile (name
, lang_input_file_is_file_enum
, default_target
,
736 /* If we have already added this file, or this file is not real
737 (FIXME: can that ever actually happen?) or the name is NULL
738 (FIXME: can that ever actually happen?) don't add this file. */
741 || search
->filename
== (const char *) NULL
)
744 load_symbols (search
);
749 /* Get the symbols for an input file. */
753 lang_input_statement_type
*entry
;
758 ldfile_open_file (entry
);
760 if (bfd_check_format (entry
->the_bfd
, bfd_object
))
762 ldlang_add_file (entry
);
763 if (trace_files
|| trace_file_tries
)
764 info_msg ("%I\n", entry
);
766 else if (bfd_check_format (entry
->the_bfd
, bfd_archive
))
768 /* There is nothing to do here; the add_symbols routine will
769 call ldlang_add_file (via the add_archive_element callback)
770 for each element of the archive which is used. */
773 einfo ("%F%B: file not recognized: %E\n", entry
->the_bfd
);
775 if (bfd_link_add_symbols (entry
->the_bfd
, &link_info
) == false)
776 einfo ("%F%B: could not read symbols: %E\n", entry
->the_bfd
);
778 entry
->loaded
= true;
782 wild (s
, section
, file
, target
, output
)
783 lang_wild_statement_type
* s
;
787 lang_output_section_statement_type
* output
;
789 lang_input_statement_type
*f
;
791 if (file
== (char *) NULL
)
793 /* Perform the iteration over all files in the list */
794 for (f
= (lang_input_statement_type
*) file_chain
.head
;
795 f
!= (lang_input_statement_type
*) NULL
;
796 f
= (lang_input_statement_type
*) f
->next
)
798 wild_section (s
, section
, f
, output
);
803 /* Perform the iteration over a single file */
804 wild_section (s
, section
, lookup_name (file
), output
);
806 if (section
!= (char *) NULL
807 && strcmp (section
, "COMMON") == 0
808 && default_common_section
== (lang_output_section_statement_type
*) NULL
)
810 /* Remember the section that common is going to incase we later
811 get something which doesn't know where to put it */
812 default_common_section
= output
;
817 read in all the files
826 if (output_target
== (char *) NULL
)
828 if (current_target
!= (char *) NULL
)
829 output_target
= current_target
;
831 output_target
= default_target
;
833 output
= bfd_openw (name
, output_target
);
835 if (output
== (bfd
*) NULL
)
837 if (bfd_get_error () == bfd_error_invalid_target
)
839 einfo ("%P%F: target %s not found\n", output_target
);
841 einfo ("%P%F: cannot open output file %s: %E\n", name
);
844 delete_output_file_on_failure
= 1;
846 /* output->flags |= D_PAGED;*/
848 if (! bfd_set_format (output
, bfd_object
))
849 einfo ("%P%F:%s: can not make object file: %E\n", name
);
850 if (! bfd_set_arch_mach (output
,
851 ldfile_output_architecture
,
852 ldfile_output_machine
))
853 einfo ("%P%F:%s: can not set architecture: %E\n", name
);
855 link_info
.hash
= bfd_link_hash_table_create (output
);
856 if (link_info
.hash
== (struct bfd_link_hash_table
*) NULL
)
857 einfo ("%P%F: can not create link hash table: %E\n");
859 bfd_set_gp_size (output
, g_switch_value
);
867 ldlang_open_output (statement
)
868 lang_statement_union_type
* statement
;
870 switch (statement
->header
.type
)
872 case lang_output_statement_enum
:
873 ASSERT (output_bfd
== (bfd
*) NULL
);
874 output_bfd
= open_output (statement
->output_statement
.name
);
875 ldemul_set_output_arch ();
876 if (config
.magic_demand_paged
&& !link_info
.relocateable
)
877 output_bfd
->flags
|= D_PAGED
;
879 output_bfd
->flags
&= ~D_PAGED
;
880 if (config
.text_read_only
)
881 output_bfd
->flags
|= WP_TEXT
;
883 output_bfd
->flags
&= ~WP_TEXT
;
884 if (config
.traditional_format
)
885 output_bfd
->flags
|= BFD_TRADITIONAL_FORMAT
;
887 output_bfd
->flags
&= ~BFD_TRADITIONAL_FORMAT
;
890 case lang_target_statement_enum
:
891 current_target
= statement
->target_statement
.target
;
898 /* Open all the input files. */
901 open_input_bfds (s
, force
)
902 lang_statement_union_type
*s
;
905 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
907 switch (s
->header
.type
)
909 case lang_constructors_statement_enum
:
910 open_input_bfds (constructor_list
.head
, force
);
912 case lang_output_section_statement_enum
:
913 open_input_bfds (s
->output_section_statement
.children
.head
, force
);
915 case lang_wild_statement_enum
:
916 /* Maybe we should load the file's symbols */
917 if (s
->wild_statement
.filename
)
918 (void) lookup_name (s
->wild_statement
.filename
);
919 open_input_bfds (s
->wild_statement
.children
.head
, force
);
921 case lang_group_statement_enum
:
923 struct bfd_link_hash_entry
*undefs
;
925 /* We must continually search the entries in the group
926 until no new symbols are added to the list of undefined
931 undefs
= link_info
.hash
->undefs_tail
;
932 open_input_bfds (s
->group_statement
.children
.head
, true);
934 while (undefs
!= link_info
.hash
->undefs_tail
);
937 case lang_target_statement_enum
:
938 current_target
= s
->target_statement
.target
;
940 case lang_input_statement_enum
:
941 if (s
->input_statement
.real
== true)
943 s
->input_statement
.target
= current_target
;
945 /* If we are being called from within a group, and this
946 is an archive which has already been searched, then
947 force it to be researched. */
949 && s
->input_statement
.loaded
950 && bfd_check_format (s
->input_statement
.the_bfd
,
952 s
->input_statement
.loaded
= false;
954 load_symbols (&s
->input_statement
);
963 /* If there are [COMMONS] statements, put a wild one into the bss section */
966 lang_reasonable_defaults ()
969 lang_output_section_statement_lookup (".text");
970 lang_output_section_statement_lookup (".data");
972 default_common_section
=
973 lang_output_section_statement_lookup (".bss");
976 if (placed_commons
== false)
978 lang_wild_statement_type
*new =
979 new_stat (lang_wild_statement
,
980 &default_common_section
->children
);
982 new->section_name
= "COMMON";
983 new->filename
= (char *) NULL
;
984 lang_list_init (&new->children
);
991 Add the supplied name to the symbol table as an undefined reference.
992 Remove items from the chain as we open input bfds
994 typedef struct ldlang_undef_chain_list
996 struct ldlang_undef_chain_list
*next
;
998 } ldlang_undef_chain_list_type
;
1000 static ldlang_undef_chain_list_type
*ldlang_undef_chain_list_head
;
1003 ldlang_add_undef (name
)
1004 CONST
char *CONST name
;
1006 ldlang_undef_chain_list_type
*new =
1007 (ldlang_undef_chain_list_type
1008 *) stat_alloc ((bfd_size_type
) (sizeof (ldlang_undef_chain_list_type
)));
1010 new->next
= ldlang_undef_chain_list_head
;
1011 ldlang_undef_chain_list_head
= new;
1013 new->name
= buystring (name
);
1016 /* Run through the list of undefineds created above and place them
1017 into the linker hash table as undefined symbols belonging to the
1021 lang_place_undefineds ()
1023 ldlang_undef_chain_list_type
*ptr
;
1025 for (ptr
= ldlang_undef_chain_list_head
;
1026 ptr
!= (ldlang_undef_chain_list_type
*) NULL
;
1029 struct bfd_link_hash_entry
*h
;
1031 h
= bfd_link_hash_lookup (link_info
.hash
, ptr
->name
, true, false, true);
1032 if (h
== (struct bfd_link_hash_entry
*) NULL
)
1033 einfo ("%P%F: bfd_link_hash_lookup failed: %E");
1034 if (h
->type
== bfd_link_hash_new
)
1036 h
->type
= bfd_link_hash_undefined
;
1037 h
->u
.undef
.abfd
= NULL
;
1038 bfd_link_add_undef (link_info
.hash
, h
);
1043 /* Open input files and attatch to output sections */
1045 map_input_to_output_sections (s
, target
, output_section_statement
)
1046 lang_statement_union_type
* s
;
1048 lang_output_section_statement_type
* output_section_statement
;
1050 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
1052 switch (s
->header
.type
)
1056 case lang_wild_statement_enum
:
1057 wild (&s
->wild_statement
, s
->wild_statement
.section_name
,
1058 s
->wild_statement
.filename
, target
,
1059 output_section_statement
);
1062 case lang_constructors_statement_enum
:
1063 map_input_to_output_sections (constructor_list
.head
,
1065 output_section_statement
);
1067 case lang_output_section_statement_enum
:
1068 map_input_to_output_sections (s
->output_section_statement
.children
.head
,
1070 &s
->output_section_statement
);
1072 case lang_output_statement_enum
:
1074 case lang_target_statement_enum
:
1075 target
= s
->target_statement
.target
;
1077 case lang_group_statement_enum
:
1078 map_input_to_output_sections (s
->group_statement
.children
.head
,
1080 output_section_statement
);
1082 case lang_fill_statement_enum
:
1083 case lang_input_section_enum
:
1084 case lang_object_symbols_statement_enum
:
1085 case lang_data_statement_enum
:
1086 case lang_reloc_statement_enum
:
1087 case lang_assignment_statement_enum
:
1088 case lang_padding_statement_enum
:
1089 case lang_input_statement_enum
:
1090 if (output_section_statement
!= NULL
1091 && output_section_statement
->bfd_section
== NULL
)
1092 init_os (output_section_statement
);
1094 case lang_afile_asection_pair_statement_enum
:
1097 case lang_address_statement_enum
:
1098 /* Mark the specified section with the supplied address */
1100 lang_output_section_statement_type
*os
=
1101 lang_output_section_statement_lookup
1102 (s
->address_statement
.section_name
);
1104 if (os
->bfd_section
== NULL
)
1106 os
->addr_tree
= s
->address_statement
.address
;
1114 print_output_section_statement (output_section_statement
)
1115 lang_output_section_statement_type
* output_section_statement
;
1117 asection
*section
= output_section_statement
->bfd_section
;
1120 print_section (output_section_statement
->name
);
1125 print_dot
= section
->vma
;
1129 print_address (section
->vma
);
1131 print_size (section
->_raw_size
);
1133 print_size(section
->_cooked_size
);
1135 print_alignment (section
->alignment_power
);
1138 fprintf (config
.map_file
, "%s flags", output_section_statement
->region
->name
);
1139 print_flags (stdout
, &output_section_statement
->flags
);
1141 if (section
->flags
& SEC_LOAD
)
1142 fprintf (config
.map_file
, "load ");
1143 if (section
->flags
& SEC_ALLOC
)
1144 fprintf (config
.map_file
, "alloc ");
1145 if (section
->flags
& SEC_RELOC
)
1146 fprintf (config
.map_file
, "reloc ");
1147 if (section
->flags
& SEC_HAS_CONTENTS
)
1148 fprintf (config
.map_file
, "contents ");
1153 fprintf (config
.map_file
, " (no attached output section)");
1156 if (output_section_statement
->load_base
)
1158 int b
= exp_get_value_int(output_section_statement
->load_base
,
1159 0, "output base", lang_final_phase_enum
);
1160 printf("Output address %08x\n", b
);
1162 if (output_section_statement
->section_alignment
>= 0
1163 || output_section_statement
->section_alignment
>= 0)
1165 printf("\t\t\t\t\tforced alignment ");
1166 if ( output_section_statement
->section_alignment
>= 0)
1168 printf("section 2**%d ",output_section_statement
->section_alignment
);
1170 if ( output_section_statement
->subsection_alignment
>= 0)
1172 printf("subsection 2**%d ",output_section_statement
->subsection_alignment
);
1177 print_statement (output_section_statement
->children
.head
,
1178 output_section_statement
);
1183 print_assignment (assignment
, output_section
)
1184 lang_assignment_statement_type
* assignment
;
1185 lang_output_section_statement_type
* output_section
;
1187 etree_value_type result
;
1193 print_address (print_dot
);
1195 result
= exp_fold_tree (assignment
->exp
->assign
.src
,
1197 lang_final_phase_enum
,
1203 print_address (result
.value
);
1207 fprintf (config
.map_file
, "*undefined*");
1210 exp_print_tree (assignment
->exp
);
1212 fprintf (config
.map_file
, "\n");
1216 print_input_statement (statm
)
1217 lang_input_statement_type
* statm
;
1219 if (statm
->filename
!= (char *) NULL
)
1221 fprintf (config
.map_file
, "LOAD %s\n", statm
->filename
);
1225 /* Print all the defined symbols for the abfd provided by in the supplied
1230 print_one_symbol (hash_entry
, ptr
)
1231 struct bfd_link_hash_entry
*hash_entry
;
1234 asection
* sec
= (asection
*)ptr
;
1236 if (hash_entry
->type
== bfd_link_hash_defined
)
1238 if (sec
== hash_entry
->u
.def
.section
) {
1240 fprintf (config
.map_file
, " ");
1242 fprintf (config
.map_file
, " ");
1243 print_address (hash_entry
->u
.def
.value
+ outside_section_address (sec
));
1244 fprintf (config
.map_file
, " %s", hash_entry
->root
.string
);
1253 print_input_section (in
)
1254 lang_input_section_type
* in
;
1256 asection
*i
= in
->section
;
1257 bfd_size_type size
= i
->_cooked_size
!= 0 ? i
->_cooked_size
: i
->_raw_size
;
1262 fprintf (config
.map_file
, " ");
1263 print_section (i
->name
);
1264 fprintf (config
.map_file
, " ");
1265 if (i
->output_section
)
1267 print_address (i
->output_section
->vma
+ i
->output_offset
);
1268 fprintf (config
.map_file
, " ");
1269 print_size (i
->_raw_size
);
1270 fprintf (config
.map_file
, " ");
1271 print_size(i
->_cooked_size
);
1272 fprintf (config
.map_file
, " ");
1273 print_alignment (i
->alignment_power
);
1274 fprintf (config
.map_file
, " ");
1278 bfd
*abfd
= in
->ifile
->the_bfd
;
1280 if (in
->ifile
->just_syms_flag
== true)
1282 fprintf (config
.map_file
, "symbols only ");
1285 fprintf (config
.map_file
, " %s ", abfd
->xvec
->name
);
1286 if (abfd
->my_archive
!= (bfd
*) NULL
)
1288 fprintf (config
.map_file
, "[%s]%s", abfd
->my_archive
->filename
,
1293 fprintf (config
.map_file
, "%s", abfd
->filename
);
1295 fprintf (config
.map_file
, "(overhead %d bytes)", (int) bfd_alloc_size (abfd
));
1298 /* Print all the symbols */
1299 bfd_link_hash_traverse (link_info
.hash
, print_one_symbol
, (PTR
) i
);
1307 print_dot
= outside_section_address (i
) + size
;
1311 fprintf (config
.map_file
, "No output section allocated\n");
1317 print_fill_statement (fill
)
1318 lang_fill_statement_type
* fill
;
1320 fprintf (config
.map_file
, "FILL mask ");
1321 print_fill (fill
->fill
);
1325 print_data_statement (data
)
1326 lang_data_statement_type
* data
;
1328 /* bfd_vma value; */
1333 /* ASSERT(print_dot == data->output_vma);*/
1335 print_address (data
->output_vma
+ data
->output_section
->vma
);
1337 print_address (data
->value
);
1342 fprintf (config
.map_file
, "BYTE ");
1343 print_dot
+= BYTE_SIZE
;
1346 fprintf (config
.map_file
, "SHORT ");
1347 print_dot
+= SHORT_SIZE
;
1350 fprintf (config
.map_file
, "LONG ");
1351 print_dot
+= LONG_SIZE
;
1354 fprintf (config
.map_file
, "QUAD ");
1355 print_dot
+= QUAD_SIZE
;
1359 exp_print_tree (data
->exp
);
1361 fprintf (config
.map_file
, "\n");
1364 /* Print a reloc statement. */
1367 print_reloc_statement (reloc
)
1368 lang_reloc_statement_type
*reloc
;
1375 /* ASSERT(print_dot == data->output_vma);*/
1377 print_address (reloc
->output_vma
+ reloc
->output_section
->vma
);
1379 print_address (reloc
->addend_value
);
1382 fprintf (config
.map_file
, "RELOC %s ", reloc
->howto
->name
);
1384 print_dot
+= bfd_get_reloc_size (reloc
->howto
);
1386 exp_print_tree (reloc
->addend_exp
);
1388 fprintf (config
.map_file
, "\n");
1392 print_padding_statement (s
)
1393 lang_padding_statement_type
* s
;
1397 print_section ("*fill*");
1399 print_address (s
->output_offset
+ s
->output_section
->vma
);
1401 print_size (s
->size
);
1403 print_fill (s
->fill
);
1406 print_dot
= s
->output_offset
+ s
->output_section
->vma
+ s
->size
;
1411 print_wild_statement (w
, os
)
1412 lang_wild_statement_type
* w
;
1413 lang_output_section_statement_type
* os
;
1415 fprintf (config
.map_file
, " from ");
1416 if (w
->filename
!= (char *) NULL
)
1418 fprintf (config
.map_file
, "%s", w
->filename
);
1422 fprintf (config
.map_file
, "*");
1424 if (w
->section_name
!= (char *) NULL
)
1426 fprintf (config
.map_file
, "(%s)", w
->section_name
);
1430 fprintf (config
.map_file
, "(*)");
1433 print_statement (w
->children
.head
, os
);
1437 /* Print a group statement. */
1441 lang_group_statement_type
*s
;
1442 lang_output_section_statement_type
*os
;
1444 fprintf (config
.map_file
, "START GROUP\n");
1445 print_statement (s
->children
.head
, os
);
1446 fprintf (config
.map_file
, "END GROUP\n");
1450 print_statement (s
, os
)
1451 lang_statement_union_type
* s
;
1452 lang_output_section_statement_type
* os
;
1456 switch (s
->header
.type
)
1458 case lang_constructors_statement_enum
:
1459 fprintf (config
.map_file
, "constructors:\n");
1460 print_statement (constructor_list
.head
, os
);
1462 case lang_wild_statement_enum
:
1463 print_wild_statement (&s
->wild_statement
, os
);
1466 fprintf (config
.map_file
, "Fail with %d\n", s
->header
.type
);
1469 case lang_address_statement_enum
:
1470 fprintf (config
.map_file
, "address\n");
1472 case lang_object_symbols_statement_enum
:
1473 fprintf (config
.map_file
, "object symbols\n");
1475 case lang_fill_statement_enum
:
1476 print_fill_statement (&s
->fill_statement
);
1478 case lang_data_statement_enum
:
1479 print_data_statement (&s
->data_statement
);
1481 case lang_reloc_statement_enum
:
1482 print_reloc_statement (&s
->reloc_statement
);
1484 case lang_input_section_enum
:
1485 print_input_section (&s
->input_section
);
1487 case lang_padding_statement_enum
:
1488 print_padding_statement (&s
->padding_statement
);
1490 case lang_output_section_statement_enum
:
1491 print_output_section_statement (&s
->output_section_statement
);
1493 case lang_assignment_statement_enum
:
1494 print_assignment (&s
->assignment_statement
,
1497 case lang_target_statement_enum
:
1498 fprintf (config
.map_file
, "TARGET(%s)\n", s
->target_statement
.target
);
1500 case lang_output_statement_enum
:
1501 fprintf (config
.map_file
, "OUTPUT(%s %s)\n",
1502 s
->output_statement
.name
,
1503 output_target
? output_target
: "");
1505 case lang_input_statement_enum
:
1506 print_input_statement (&s
->input_statement
);
1508 case lang_group_statement_enum
:
1509 print_group (&s
->group_statement
, os
);
1511 case lang_afile_asection_pair_statement_enum
:
1523 print_statement (statement_list
.head
,
1524 abs_output_section
);
1529 insert_pad (this_ptr
, fill
, power
, output_section_statement
, dot
)
1530 lang_statement_union_type
** this_ptr
;
1533 asection
* output_section_statement
;
1536 /* Align this section first to the
1537 input sections requirement, then
1538 to the output section's requirement.
1539 If this alignment is > than any seen before,
1540 then record it too. Perform the alignment by
1541 inserting a magic 'padding' statement.
1544 unsigned int alignment_needed
= align_power (dot
, power
) - dot
;
1546 if (alignment_needed
!= 0)
1548 lang_statement_union_type
*new =
1549 (lang_statement_union_type
*)
1550 stat_alloc ((bfd_size_type
) (sizeof (lang_padding_statement_type
)));
1552 /* Link into existing chain */
1553 new->header
.next
= *this_ptr
;
1555 new->header
.type
= lang_padding_statement_enum
;
1556 new->padding_statement
.output_section
= output_section_statement
;
1557 new->padding_statement
.output_offset
=
1558 dot
- output_section_statement
->vma
;
1559 new->padding_statement
.fill
= fill
;
1560 new->padding_statement
.size
= alignment_needed
;
1564 /* Remember the most restrictive alignment */
1565 if (power
> output_section_statement
->alignment_power
)
1567 output_section_statement
->alignment_power
= power
;
1569 output_section_statement
->_raw_size
+= alignment_needed
;
1570 return alignment_needed
+ dot
;
1574 /* Work out how much this section will move the dot point */
1576 size_input_section (this_ptr
, output_section_statement
, fill
, dot
, relax
)
1577 lang_statement_union_type
** this_ptr
;
1578 lang_output_section_statement_type
* output_section_statement
;
1583 lang_input_section_type
*is
= &((*this_ptr
)->input_section
);
1584 asection
*i
= is
->section
;
1586 if (is
->ifile
->just_syms_flag
== false)
1588 if (output_section_statement
->subsection_alignment
!= -1)
1589 i
->alignment_power
=
1590 output_section_statement
->subsection_alignment
;
1592 dot
= insert_pad (this_ptr
, fill
, i
->alignment_power
,
1593 output_section_statement
->bfd_section
, dot
);
1595 /* Remember where in the output section this input section goes */
1597 i
->output_offset
= dot
- output_section_statement
->bfd_section
->vma
;
1599 /* Mark how big the output section must be to contain this now
1601 if (i
->_cooked_size
!= 0)
1602 dot
+= i
->_cooked_size
;
1604 dot
+= i
->_raw_size
;
1605 output_section_statement
->bfd_section
->_raw_size
= dot
- output_section_statement
->bfd_section
->vma
;
1609 i
->output_offset
= i
->vma
- output_section_statement
->bfd_section
->vma
;
1615 /* This variable indicates whether bfd_relax_section should be called
1618 static boolean relax_again
;
1620 /* Set the sizes for all the output sections. */
1623 lang_size_sections (s
, output_section_statement
, prev
, fill
, dot
, relax
)
1624 lang_statement_union_type
* s
;
1625 lang_output_section_statement_type
* output_section_statement
;
1626 lang_statement_union_type
** prev
;
1631 /* Size up the sections from their constituent parts */
1632 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
1634 switch (s
->header
.type
)
1637 case lang_output_section_statement_enum
:
1640 lang_output_section_statement_type
*os
= &s
->output_section_statement
;
1642 if (os
->bfd_section
== NULL
)
1644 /* This section was never actually created. */
1648 /* If this is a COFF shared library section, use the size and
1649 address from the input section. FIXME: This is COFF
1650 specific; it would be cleaner if there were some other way
1651 to do this, but nothing simple comes to mind. */
1652 if ((os
->bfd_section
->flags
& SEC_COFF_SHARED_LIBRARY
) != 0)
1656 if (os
->children
.head
== NULL
1657 || os
->children
.head
->next
!= NULL
1658 || os
->children
.head
->header
.type
!= lang_input_section_enum
)
1659 einfo ("%P%X: Internal error on COFF shared library section %s",
1662 input
= os
->children
.head
->input_section
.section
;
1663 bfd_set_section_vma (os
->bfd_section
->owner
,
1665 bfd_section_vma (input
->owner
, input
));
1666 os
->bfd_section
->_raw_size
= input
->_raw_size
;
1670 if (bfd_is_abs_section (os
->bfd_section
))
1672 /* No matter what happens, an abs section starts at zero */
1673 ASSERT (os
->bfd_section
->vma
== 0);
1677 if (os
->addr_tree
== (etree_type
*) NULL
)
1679 /* No address specified for this section, get one
1680 from the region specification
1682 if (os
->region
== (lang_memory_region_type
*) NULL
)
1684 os
->region
= lang_memory_region_lookup ("*default*");
1686 dot
= os
->region
->current
;
1687 if (os
->section_alignment
== -1)
1688 dot
= align_power (dot
, os
->bfd_section
->alignment_power
);
1694 r
= exp_fold_tree (os
->addr_tree
,
1696 lang_allocating_phase_enum
,
1698 if (r
.valid
== false)
1700 einfo ("%F%S: non constant address expression for section %s\n",
1705 /* The section starts here */
1706 /* First, align to what the section needs */
1708 if (os
->section_alignment
!= -1)
1709 dot
= align_power (dot
, os
->section_alignment
);
1711 bfd_set_section_vma (0, os
->bfd_section
, dot
);
1713 if (os
->load_base
) {
1714 os
->bfd_section
->lma
1715 = exp_get_value_int(os
->load_base
, 0,"load base", lang_final_phase_enum
);
1718 os
->bfd_section
->output_offset
= 0;
1721 (void) lang_size_sections (os
->children
.head
, os
, &os
->children
.head
,
1722 os
->fill
, dot
, relax
);
1723 /* Ignore the size of the input sections, use the vma and size to */
1726 after
= ALIGN_N (os
->bfd_section
->vma
+
1727 os
->bfd_section
->_raw_size
,
1728 /* The coercion here is important, see ld.h. */
1729 (bfd_vma
) os
->block_value
);
1731 if (bfd_is_abs_section (os
->bfd_section
))
1732 ASSERT (after
== os
->bfd_section
->vma
);
1734 os
->bfd_section
->_raw_size
= after
- os
->bfd_section
->vma
;
1735 dot
= os
->bfd_section
->vma
+ os
->bfd_section
->_raw_size
;
1736 os
->processed
= true;
1738 /* Replace into region ? */
1739 if (os
->region
!= (lang_memory_region_type
*) NULL
)
1741 os
->region
->current
= dot
;
1742 /* Make sure this isn't silly */
1743 if (( os
->region
->current
1744 > os
->region
->origin
+ os
->region
->length
)
1745 || ( os
->region
->origin
> os
->region
->current
))
1747 einfo ("%X%P: region %s is full (%B section %s)\n",
1749 os
->bfd_section
->owner
,
1750 os
->bfd_section
->name
);
1751 /* Reset the region pointer */
1752 os
->region
->current
= 0;
1760 case lang_constructors_statement_enum
:
1761 dot
= lang_size_sections (constructor_list
.head
,
1762 output_section_statement
,
1763 &s
->wild_statement
.children
.head
,
1768 case lang_data_statement_enum
:
1770 unsigned int size
= 0;
1772 s
->data_statement
.output_vma
= dot
- output_section_statement
->bfd_section
->vma
;
1773 s
->data_statement
.output_section
=
1774 output_section_statement
->bfd_section
;
1776 switch (s
->data_statement
.type
)
1793 output_section_statement
->bfd_section
->_raw_size
+= size
;
1797 case lang_reloc_statement_enum
:
1801 s
->reloc_statement
.output_vma
=
1802 dot
- output_section_statement
->bfd_section
->vma
;
1803 s
->reloc_statement
.output_section
=
1804 output_section_statement
->bfd_section
;
1805 size
= bfd_get_reloc_size (s
->reloc_statement
.howto
);
1807 output_section_statement
->bfd_section
->_raw_size
+= size
;
1811 case lang_wild_statement_enum
:
1813 dot
= lang_size_sections (s
->wild_statement
.children
.head
,
1814 output_section_statement
,
1815 &s
->wild_statement
.children
.head
,
1821 case lang_object_symbols_statement_enum
:
1822 link_info
.create_object_symbols_section
=
1823 output_section_statement
->bfd_section
;
1825 case lang_output_statement_enum
:
1826 case lang_target_statement_enum
:
1828 case lang_input_section_enum
:
1832 i
= (*prev
)->input_section
.section
;
1834 i
->_cooked_size
= i
->_raw_size
;
1839 if (! bfd_relax_section (i
->owner
, i
, &link_info
, &again
))
1840 einfo ("%P%F: can't relax section: %E\n");
1844 dot
= size_input_section (prev
,
1845 output_section_statement
,
1846 output_section_statement
->fill
,
1850 case lang_input_statement_enum
:
1852 case lang_fill_statement_enum
:
1853 s
->fill_statement
.output_section
= output_section_statement
->bfd_section
;
1855 fill
= s
->fill_statement
.fill
;
1857 case lang_assignment_statement_enum
:
1859 bfd_vma newdot
= dot
;
1861 exp_fold_tree (s
->assignment_statement
.exp
,
1862 output_section_statement
,
1863 lang_allocating_phase_enum
,
1867 if (newdot
!= dot
&& !relax
)
1869 /* The assignment changed dot. Insert a pad. */
1870 if (output_section_statement
== abs_output_section
)
1872 /* If we don't have an output section, then just adjust
1873 the default memory address. */
1874 lang_memory_region_lookup ("*default*")->current
= newdot
;
1878 lang_statement_union_type
*new =
1879 ((lang_statement_union_type
*)
1880 stat_alloc (sizeof (lang_padding_statement_type
)));
1882 /* Link into existing chain */
1883 new->header
.next
= *prev
;
1885 new->header
.type
= lang_padding_statement_enum
;
1886 new->padding_statement
.output_section
=
1887 output_section_statement
->bfd_section
;
1888 new->padding_statement
.output_offset
=
1889 dot
- output_section_statement
->bfd_section
->vma
;
1890 new->padding_statement
.fill
= fill
;
1891 new->padding_statement
.size
= newdot
- dot
;
1892 output_section_statement
->bfd_section
->_raw_size
+=
1893 new->padding_statement
.size
;
1901 case lang_padding_statement_enum
:
1902 /* If we are relaxing, and this is not the first pass, some
1903 padding statements may have been inserted during previous
1904 passes. We may have to move the padding statement to a new
1905 location if dot has a different value at this point in this
1906 pass than it did at this point in the previous pass. */
1907 s
->padding_statement
.output_offset
=
1908 dot
- output_section_statement
->bfd_section
->vma
;
1909 dot
+= s
->padding_statement
.size
;
1912 case lang_group_statement_enum
:
1913 dot
= lang_size_sections (s
->group_statement
.children
.head
,
1914 output_section_statement
,
1915 &s
->group_statement
.children
.head
,
1923 /* This can only get here when relaxing is turned on */
1925 case lang_address_statement_enum
:
1928 prev
= &s
->header
.next
;
1934 lang_do_assignments (s
, output_section_statement
, fill
, dot
)
1935 lang_statement_union_type
* s
;
1936 lang_output_section_statement_type
* output_section_statement
;
1940 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
1942 switch (s
->header
.type
)
1944 case lang_constructors_statement_enum
:
1945 dot
= lang_do_assignments (constructor_list
.head
,
1946 output_section_statement
,
1951 case lang_output_section_statement_enum
:
1953 lang_output_section_statement_type
*os
=
1954 &(s
->output_section_statement
);
1956 if (os
->bfd_section
!= NULL
)
1958 dot
= os
->bfd_section
->vma
;
1959 (void) lang_do_assignments (os
->children
.head
, os
,
1961 dot
= os
->bfd_section
->vma
+ os
->bfd_section
->_raw_size
;
1965 case lang_wild_statement_enum
:
1967 dot
= lang_do_assignments (s
->wild_statement
.children
.head
,
1968 output_section_statement
,
1973 case lang_object_symbols_statement_enum
:
1974 case lang_output_statement_enum
:
1975 case lang_target_statement_enum
:
1977 case lang_common_statement_enum
:
1980 case lang_data_statement_enum
:
1982 etree_value_type value
;
1984 value
= exp_fold_tree (s
->data_statement
.exp
,
1986 lang_final_phase_enum
, dot
, &dot
);
1987 s
->data_statement
.value
= value
.value
;
1988 if (value
.valid
== false)
1989 einfo ("%F%P: invalid data statement\n");
1991 switch (s
->data_statement
.type
)
2008 case lang_reloc_statement_enum
:
2010 etree_value_type value
;
2012 value
= exp_fold_tree (s
->reloc_statement
.addend_exp
,
2014 lang_final_phase_enum
, dot
, &dot
);
2015 s
->reloc_statement
.addend_value
= value
.value
;
2016 if (value
.valid
== false)
2017 einfo ("%F%P: invalid reloc statement\n");
2019 dot
+= bfd_get_reloc_size (s
->reloc_statement
.howto
);
2022 case lang_input_section_enum
:
2024 asection
*in
= s
->input_section
.section
;
2026 if (in
->_cooked_size
!= 0)
2027 dot
+= in
->_cooked_size
;
2029 dot
+= in
->_raw_size
;
2033 case lang_input_statement_enum
:
2035 case lang_fill_statement_enum
:
2036 fill
= s
->fill_statement
.fill
;
2038 case lang_assignment_statement_enum
:
2040 exp_fold_tree (s
->assignment_statement
.exp
,
2041 output_section_statement
,
2042 lang_final_phase_enum
,
2048 case lang_padding_statement_enum
:
2049 dot
+= s
->padding_statement
.size
;
2052 case lang_group_statement_enum
:
2053 dot
= lang_do_assignments (s
->group_statement
.children
.head
,
2054 output_section_statement
,
2062 case lang_address_statement_enum
:
2073 struct bfd_link_hash_entry
*h
;
2074 boolean warn
= link_info
.relocateable
? false : true;
2076 if (entry_symbol
== (char *) NULL
)
2078 /* No entry has been specified. Look for start, but don't warn
2079 if we don't find it. */
2080 entry_symbol
= "start";
2084 h
= bfd_link_hash_lookup (link_info
.hash
, entry_symbol
, false, false, true);
2085 if (h
!= (struct bfd_link_hash_entry
*) NULL
2086 && h
->type
== bfd_link_hash_defined
)
2090 val
= (h
->u
.def
.value
2091 + bfd_get_section_vma (output_bfd
,
2092 h
->u
.def
.section
->output_section
)
2093 + h
->u
.def
.section
->output_offset
);
2094 if (! bfd_set_start_address (output_bfd
, val
))
2095 einfo ("%P%F:%s: can't set start address\n", entry_symbol
);
2101 /* Can't find the entry symbol. Use the first address in the
2103 ts
= bfd_get_section_by_name (output_bfd
, ".text");
2104 if (ts
!= (asection
*) NULL
)
2107 einfo ("%P: warning: cannot find entry symbol %s; defaulting to %V\n",
2108 entry_symbol
, bfd_get_section_vma (output_bfd
, ts
));
2109 if (! bfd_set_start_address (output_bfd
,
2110 bfd_get_section_vma (output_bfd
, ts
)))
2111 einfo ("%P%F: can't set start address\n");
2116 einfo ("%P: warning: cannot find entry symbol %s; not setting start address\n",
2122 /* By now we know the target architecture, and we may have an */
2123 /* ldfile_output_machine_name */
2127 lang_statement_union_type
*file
;
2129 unsigned long input_machine
;
2130 enum bfd_architecture input_architecture
;
2131 CONST bfd_arch_info_type
*compatible
;
2133 for (file
= file_chain
.head
;
2134 file
!= (lang_statement_union_type
*) NULL
;
2135 file
= file
->input_statement
.next
)
2137 input_bfd
= file
->input_statement
.the_bfd
;
2139 input_machine
= bfd_get_mach (input_bfd
);
2140 input_architecture
= bfd_get_arch (input_bfd
);
2143 /* Inspect the architecture and ensure we're linking like with
2146 compatible
= bfd_arch_get_compatible (input_bfd
,
2151 ldfile_output_machine
= compatible
->mach
;
2152 ldfile_output_architecture
= compatible
->arch
;
2157 einfo ("%P: warning: %s architecture of input file `%B' is incompatible with %s output\n",
2158 bfd_printable_name (input_bfd
), input_bfd
,
2159 bfd_printable_name (output_bfd
));
2161 if (! bfd_set_arch_mach (output_bfd
,
2164 einfo ("%P%F:%s: can't set architecture: %E\n",
2165 bfd_get_filename (output_bfd
));
2171 /* Look through all the global common symbols and attach them to the
2172 correct section. The -sort-common command line switch may be used
2173 to roughly sort the entries by size. */
2178 if (link_info
.relocateable
2179 && ! command_line
.force_common_definition
)
2182 if (! config
.sort_common
)
2183 bfd_link_hash_traverse (link_info
.hash
, lang_one_common
, (PTR
) NULL
);
2188 for (power
= 1; power
< 4; power
++)
2189 bfd_link_hash_traverse (link_info
.hash
, lang_one_common
,
2194 /* Place one common symbol in the correct section. */
2197 lang_one_common (h
, info
)
2198 struct bfd_link_hash_entry
*h
;
2201 unsigned int power_of_two
;
2205 if (h
->type
!= bfd_link_hash_common
)
2209 power_of_two
= h
->u
.c
.alignment_power
;
2211 if (config
.sort_common
2212 && power_of_two
< *(unsigned int *) info
2213 && *(unsigned int *) info
< 4)
2216 section
= h
->u
.c
.section
;
2218 /* Increase the size of the section. */
2219 section
->_raw_size
= ALIGN_N (section
->_raw_size
,
2220 (bfd_size_type
) (1 << power_of_two
));
2222 /* Adjust the alignment if necessary. */
2223 if (power_of_two
> section
->alignment_power
)
2224 section
->alignment_power
= power_of_two
;
2226 /* Change the symbol from common to defined. */
2227 h
->type
= bfd_link_hash_defined
;
2228 h
->u
.def
.section
= section
;
2229 h
->u
.def
.value
= section
->_raw_size
;
2231 /* Increase the size of the section. */
2232 section
->_raw_size
+= size
;
2234 if (config
.map_file
!= NULL
)
2235 fprintf (config
.map_file
, "Allocating common %s: %lx at %lx %s\n",
2236 h
->root
.string
, (unsigned long) size
,
2237 (unsigned long) h
->u
.def
.value
, section
->owner
->filename
);
2243 run through the input files and ensure that every input
2244 section has somewhere to go. If one is found without
2245 a destination then create an input request and place it
2246 into the statement tree.
2250 lang_place_orphans ()
2252 lang_input_statement_type
*file
;
2254 for (file
= (lang_input_statement_type
*) file_chain
.head
;
2255 file
!= (lang_input_statement_type
*) NULL
;
2256 file
= (lang_input_statement_type
*) file
->next
)
2260 if (file
->just_syms_flag
)
2263 for (s
= file
->the_bfd
->sections
;
2264 s
!= (asection
*) NULL
;
2267 if (s
->output_section
== (asection
*) NULL
)
2269 /* This section of the file is not attatched, root
2270 around for a sensible place for it to go */
2272 if (file
->common_section
== s
)
2274 /* This is a lonely common section which must
2275 have come from an archive. We attatch to the
2276 section with the wildcard */
2277 if (! link_info
.relocateable
2278 && ! command_line
.force_common_definition
)
2280 if (default_common_section
==
2281 (lang_output_section_statement_type
*) NULL
)
2283 info_msg ("%P: no [COMMON] command, defaulting to .bss\n");
2285 default_common_section
=
2286 lang_output_section_statement_lookup (".bss");
2289 wild_doit (&default_common_section
->children
, s
,
2290 default_common_section
, file
);
2295 lang_output_section_statement_type
*os
=
2296 lang_output_section_statement_lookup (s
->name
);
2298 wild_doit (&os
->children
, s
, os
, file
);
2307 lang_set_flags (ptr
, flags
)
2311 boolean state
= false;
2326 /* ptr->flag_read = state; */
2329 /* ptr->flag_write = state; */
2332 /* ptr->flag_executable= state;*/
2336 /* ptr->flag_loadable= state;*/
2339 einfo ("%P%F: invalid syntax in flags\n");
2346 /* Call a function on each input file. This function will be called
2347 on an archive, but not on the elements. */
2350 lang_for_each_input_file (func
)
2351 void (*func
) PARAMS ((lang_input_statement_type
*));
2353 lang_input_statement_type
*f
;
2355 for (f
= (lang_input_statement_type
*) input_file_chain
.head
;
2357 f
= (lang_input_statement_type
*) f
->next_real_file
)
2361 /* Call a function on each file. The function will be called on all
2362 the elements of an archive which are included in the link, but will
2363 not be called on the archive file itself. */
2366 lang_for_each_file (func
)
2367 void (*func
) PARAMS ((lang_input_statement_type
*));
2369 lang_input_statement_type
*f
;
2371 for (f
= (lang_input_statement_type
*) file_chain
.head
;
2372 f
!= (lang_input_statement_type
*) NULL
;
2373 f
= (lang_input_statement_type
*) f
->next
)
2384 lang_for_each_input_section (func
)
2385 void (*func
) PARAMS ((bfd
* ab
, asection
* as
));
2387 lang_input_statement_type
*f
;
2389 for (f
= (lang_input_statement_type
*) file_chain
.head
;
2390 f
!= (lang_input_statement_type
*) NULL
;
2391 f
= (lang_input_statement_type
*) f
->next
)
2395 for (s
= f
->the_bfd
->sections
;
2396 s
!= (asection
*) NULL
;
2399 func (f
->the_bfd
, s
);
2407 ldlang_add_file (entry
)
2408 lang_input_statement_type
* entry
;
2412 lang_statement_append (&file_chain
,
2413 (lang_statement_union_type
*) entry
,
2416 /* The BFD linker needs to have a list of all input BFDs involved in
2418 ASSERT (entry
->the_bfd
->link_next
== (bfd
*) NULL
);
2419 ASSERT (entry
->the_bfd
!= output_bfd
);
2420 for (pp
= &link_info
.input_bfds
;
2421 *pp
!= (bfd
*) NULL
;
2422 pp
= &(*pp
)->link_next
)
2424 *pp
= entry
->the_bfd
;
2425 entry
->the_bfd
->usrdata
= (PTR
) entry
;
2426 bfd_set_gp_size (entry
->the_bfd
, g_switch_value
);
2430 lang_add_output (name
, from_script
)
2434 /* Make -o on command line override OUTPUT in script. */
2435 if (had_output_filename
== false || !from_script
)
2437 output_filename
= name
;
2438 had_output_filename
= true;
2443 static lang_output_section_statement_type
*current_section
;
2445 static int topower(x
)
2450 if (x
< 0) return -1;
2451 for (l
= 0; l
< 32; l
++)
2453 if (i
>= x
) return l
;
2459 lang_enter_output_section_statement (output_section_statement_name
,
2460 address_exp
, flags
, block_value
,
2461 align
, subalign
, ebase
)
2462 const char *output_section_statement_name
;
2463 etree_type
* address_exp
;
2465 bfd_vma block_value
;
2467 etree_type
*subalign
;
2470 lang_output_section_statement_type
*os
;
2474 lang_output_section_statement_lookup (output_section_statement_name
);
2478 /* Add this statement to tree */
2479 /* add_statement(lang_output_section_statement_enum,
2480 output_section_statement);*/
2481 /* Make next things chain into subchain of this */
2483 if (os
->addr_tree
==
2484 (etree_type
*) NULL
)
2490 if (flags
& SEC_NEVER_LOAD
)
2494 os
->block_value
= block_value
? block_value
: 1;
2495 stat_ptr
= &os
->children
;
2497 os
->subsection_alignment
= topower(
2498 exp_get_value_int(subalign
, -1,
2499 "subsection alignment",
2501 os
->section_alignment
= topower(
2502 exp_get_value_int(align
, -1,
2503 "section alignment", 0));
2505 os
->load_base
= ebase
;
2512 lang_output_statement_type
*new =
2513 new_stat (lang_output_statement
, stat_ptr
);
2515 new->name
= output_filename
;
2518 /* Reset the current counters in the regions */
2520 reset_memory_regions ()
2522 lang_memory_region_type
*p
= lang_memory_region_list
;
2524 for (p
= lang_memory_region_list
;
2525 p
!= (lang_memory_region_type
*) NULL
;
2528 p
->old_length
= (bfd_size_type
) (p
->current
- p
->origin
);
2529 p
->current
= p
->origin
;
2536 lang_reasonable_defaults ();
2537 current_target
= default_target
;
2539 lang_for_each_statement (ldlang_open_output
); /* Open the output file */
2541 ldemul_create_output_section_statements ();
2543 /* Add to the hash table all undefineds on the command line */
2544 lang_place_undefineds ();
2546 /* Create a bfd for each input file */
2547 current_target
= default_target
;
2548 open_input_bfds (statement_list
.head
, false);
2550 /* Build all sets based on the information gathered from the input
2552 ldctor_build_sets ();
2554 /* Size up the common data */
2557 /* Run through the contours of the script and attatch input sections
2558 to the correct output sections
2560 map_input_to_output_sections (statement_list
.head
, (char *) NULL
,
2561 (lang_output_section_statement_type
*) NULL
);
2564 /* Find any sections not attatched explicitly and handle them */
2565 lang_place_orphans ();
2567 ldemul_before_allocation ();
2569 /* Now run around and relax if we can */
2570 if (command_line
.relax
)
2572 /* First time round is a trial run to get the 'worst case'
2573 addresses of the objects if there was no relaxing. */
2574 lang_size_sections (statement_list
.head
,
2576 &(statement_list
.head
), 0, (bfd_vma
) 0, false);
2579 reset_memory_regions ();
2581 /* Keep relaxing until bfd_relax_section gives up. */
2584 relax_again
= false;
2586 /* Do all the assignments with our current guesses as to
2588 lang_do_assignments (statement_list
.head
,
2590 (fill_type
) 0, (bfd_vma
) 0);
2592 /* Perform another relax pass - this time we know where the
2593 globals are, so can make better guess. */
2594 lang_size_sections (statement_list
.head
,
2596 &(statement_list
.head
), 0, (bfd_vma
) 0, true);
2598 while (relax_again
);
2602 /* Size up the sections. */
2603 lang_size_sections (statement_list
.head
,
2605 &(statement_list
.head
), 0, (bfd_vma
) 0, false);
2608 /* See if anything special should be done now we know how big
2610 ldemul_after_allocation ();
2612 /* Do all the assignments, now that we know the final restingplaces
2613 of all the symbols */
2615 lang_do_assignments (statement_list
.head
,
2617 (fill_type
) 0, (bfd_vma
) 0);
2619 /* Make sure that we're not mixing architectures */
2629 /* EXPORTED TO YACC */
2632 lang_add_wild (section_name
, filename
)
2633 CONST
char *CONST section_name
;
2634 CONST
char *CONST filename
;
2636 lang_wild_statement_type
*new = new_stat (lang_wild_statement
,
2639 if (section_name
!= (char *) NULL
&& strcmp (section_name
, "COMMON") == 0)
2641 placed_commons
= true;
2643 if (filename
!= (char *) NULL
)
2645 lang_has_input_file
= true;
2647 new->section_name
= section_name
;
2648 new->filename
= filename
;
2649 lang_list_init (&new->children
);
2653 lang_section_start (name
, address
)
2655 etree_type
* address
;
2657 lang_address_statement_type
*ad
= new_stat (lang_address_statement
, stat_ptr
);
2659 ad
->section_name
= name
;
2660 ad
->address
= address
;
2663 /* Set the start symbol to NAME. CMDLINE is nonzero if this is called
2664 because of a -e argument on the command line, or zero if this is
2665 called by ENTRY in a linker script. Command line arguments take
2669 lang_add_entry (name
, cmdline
)
2673 static int from_cmdline
;
2675 if (entry_symbol
== NULL
2679 entry_symbol
= name
;
2680 from_cmdline
= cmdline
;
2685 lang_add_target (name
)
2688 lang_target_statement_type
*new = new_stat (lang_target_statement
,
2704 map_option_f
= true;
2715 lang_fill_statement_type
*new = new_stat (lang_fill_statement
,
2722 lang_add_data (type
, exp
)
2724 union etree_union
*exp
;
2727 lang_data_statement_type
*new = new_stat (lang_data_statement
,
2735 /* Create a new reloc statement. RELOC is the BFD relocation type to
2736 generate. HOWTO is the corresponding howto structure (we could
2737 look this up, but the caller has already done so). SECTION is the
2738 section to generate a reloc against, or NAME is the name of the
2739 symbol to generate a reloc against. Exactly one of SECTION and
2740 NAME must be NULL. ADDEND is an expression for the addend. */
2743 lang_add_reloc (reloc
, howto
, section
, name
, addend
)
2744 bfd_reloc_code_real_type reloc
;
2745 const reloc_howto_type
*howto
;
2748 union etree_union
*addend
;
2750 lang_reloc_statement_type
*p
= new_stat (lang_reloc_statement
, stat_ptr
);
2754 p
->section
= section
;
2756 p
->addend_exp
= addend
;
2758 p
->addend_value
= 0;
2759 p
->output_section
= NULL
;
2764 lang_add_assignment (exp
)
2767 lang_assignment_statement_type
*new = new_stat (lang_assignment_statement
,
2774 lang_add_attribute (attribute
)
2775 enum statement_enum attribute
;
2777 new_statement (attribute
, sizeof (lang_statement_union_type
), stat_ptr
);
2784 if (startup_file
!= (char *) NULL
)
2786 einfo ("%P%Fmultiple STARTUP files\n");
2788 first_file
->filename
= name
;
2789 first_file
->local_sym_name
= name
;
2790 first_file
->real
= true;
2792 startup_file
= name
;
2799 lang_float_flag
= maybe
;
2803 lang_leave_output_section_statement (fill
, memspec
)
2805 CONST
char *memspec
;
2807 current_section
->fill
= fill
;
2808 current_section
->region
= lang_memory_region_lookup (memspec
);
2809 stat_ptr
= &statement_list
;
2813 Create an absolute symbol with the given name with the value of the
2814 address of first byte of the section named.
2816 If the symbol already exists, then do nothing.
2819 lang_abs_symbol_at_beginning_of (secname
, name
)
2820 const char *secname
;
2823 struct bfd_link_hash_entry
*h
;
2825 h
= bfd_link_hash_lookup (link_info
.hash
, name
, true, true, true);
2826 if (h
== (struct bfd_link_hash_entry
*) NULL
)
2827 einfo ("%P%F: bfd_link_hash_lookup failed: %E\n");
2829 if (h
->type
== bfd_link_hash_new
2830 || h
->type
== bfd_link_hash_undefined
)
2834 h
->type
= bfd_link_hash_defined
;
2836 sec
= bfd_get_section_by_name (output_bfd
, secname
);
2837 if (sec
== (asection
*) NULL
)
2840 h
->u
.def
.value
= bfd_get_section_vma (output_bfd
, sec
);
2842 h
->u
.def
.section
= bfd_abs_section_ptr
;
2847 Create an absolute symbol with the given name with the value of the
2848 address of the first byte after the end of the section named.
2850 If the symbol already exists, then do nothing.
2853 lang_abs_symbol_at_end_of (secname
, name
)
2854 const char *secname
;
2857 struct bfd_link_hash_entry
*h
;
2859 h
= bfd_link_hash_lookup (link_info
.hash
, name
, true, true, true);
2860 if (h
== (struct bfd_link_hash_entry
*) NULL
)
2861 einfo ("%P%F: bfd_link_hash_lookup failed: %E\n");
2863 if (h
->type
== bfd_link_hash_new
2864 || h
->type
== bfd_link_hash_undefined
)
2868 h
->type
= bfd_link_hash_defined
;
2870 sec
= bfd_get_section_by_name (output_bfd
, secname
);
2871 if (sec
== (asection
*) NULL
)
2874 h
->u
.def
.value
= (bfd_get_section_vma (output_bfd
, sec
)
2875 + bfd_section_size (output_bfd
, sec
));
2877 h
->u
.def
.section
= bfd_abs_section_ptr
;
2882 lang_statement_append (list
, element
, field
)
2883 lang_statement_list_type
* list
;
2884 lang_statement_union_type
* element
;
2885 lang_statement_union_type
** field
;
2887 *(list
->tail
) = element
;
2891 /* Set the output format type. -oformat overrides scripts. */
2893 lang_add_output_format (format
, from_script
)
2897 if (output_target
== NULL
|| !from_script
)
2898 output_target
= format
;
2901 /* Enter a group. This creates a new lang_group_statement, and sets
2902 stat_ptr to build new statements within the group. */
2907 lang_group_statement_type
*g
;
2909 g
= new_stat (lang_group_statement
, stat_ptr
);
2910 lang_list_init (&g
->children
);
2911 stat_ptr
= &g
->children
;
2914 /* Leave a group. This just resets stat_ptr to start writing to the
2915 regular list of statements again. Note that this will not work if
2916 groups can occur inside anything else which can adjust stat_ptr,
2917 but currently they can't. */
2922 stat_ptr
= &statement_list
;