1 /* Linker command language support.
2 Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 1998
3 Free Software Foundation, Inc.
5 This file is part of GLD, the Gnu Linker.
7 GLD is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 1, or (at your option)
12 GLD is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GLD; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "libiberty.h"
43 static lang_statement_union_type
*new_statement
PARAMS ((enum statement_enum
,
45 lang_statement_list_type
*));
49 static struct obstack stat_obstack
;
51 #define obstack_chunk_alloc xmalloc
52 #define obstack_chunk_free free
53 static CONST
char *startup_file
;
54 static lang_statement_list_type input_file_chain
;
55 static boolean placed_commons
= false;
56 static lang_output_section_statement_type
*default_common_section
;
57 static boolean map_option_f
;
58 static bfd_vma print_dot
;
59 static lang_input_statement_type
*first_file
;
60 static lang_statement_list_type lang_output_section_statement
;
61 static CONST
char *current_target
;
62 static CONST
char *output_target
;
63 static lang_statement_list_type statement_list
;
64 static struct lang_phdr
*lang_phdr_list
;
66 static void lang_for_each_statement_worker
67 PARAMS ((void (*func
) (lang_statement_union_type
*),
68 lang_statement_union_type
*s
));
69 static lang_input_statement_type
*new_afile
70 PARAMS ((const char *name
, lang_input_file_enum_type file_type
,
71 const char *target
, boolean add_to_list
));
72 static void init_os
PARAMS ((lang_output_section_statement_type
*s
));
73 static void exp_init_os
PARAMS ((etree_type
*));
74 static void section_already_linked
PARAMS ((bfd
*, asection
*, PTR
));
75 static boolean wildcardp
PARAMS ((const char *));
76 static void wild_section
PARAMS ((lang_wild_statement_type
*ptr
,
78 lang_input_statement_type
*file
,
79 lang_output_section_statement_type
*output
));
80 static lang_input_statement_type
*lookup_name
PARAMS ((const char *name
));
81 static void load_symbols
PARAMS ((lang_input_statement_type
*entry
,
82 lang_statement_list_type
*));
83 static void wild_file
PARAMS ((lang_wild_statement_type
*, const char *,
84 lang_input_statement_type
*,
85 lang_output_section_statement_type
*));
86 static void wild
PARAMS ((lang_wild_statement_type
*s
,
87 const char *section
, const char *file
,
89 lang_output_section_statement_type
*output
));
90 static bfd
*open_output
PARAMS ((const char *name
));
91 static void ldlang_open_output
PARAMS ((lang_statement_union_type
*statement
));
92 static void open_input_bfds
93 PARAMS ((lang_statement_union_type
*statement
, boolean
));
94 static void lang_reasonable_defaults
PARAMS ((void));
95 static void lang_place_undefineds
PARAMS ((void));
96 static void map_input_to_output_sections
97 PARAMS ((lang_statement_union_type
*s
,
99 lang_output_section_statement_type
*output_section_statement
));
100 static void print_output_section_statement
101 PARAMS ((lang_output_section_statement_type
*output_section_statement
));
102 static void print_assignment
103 PARAMS ((lang_assignment_statement_type
*assignment
,
104 lang_output_section_statement_type
*output_section
));
105 static void print_input_statement
PARAMS ((lang_input_statement_type
*statm
));
106 static boolean print_one_symbol
PARAMS ((struct bfd_link_hash_entry
*, PTR
));
107 static void print_input_section
PARAMS ((lang_input_section_type
*in
));
108 static void print_fill_statement
PARAMS ((lang_fill_statement_type
*fill
));
109 static void print_data_statement
PARAMS ((lang_data_statement_type
*data
));
110 static void print_address_statement
PARAMS ((lang_address_statement_type
*));
111 static void print_reloc_statement
PARAMS ((lang_reloc_statement_type
*reloc
));
112 static void print_padding_statement
PARAMS ((lang_padding_statement_type
*s
));
113 static void print_wild_statement
114 PARAMS ((lang_wild_statement_type
*w
,
115 lang_output_section_statement_type
*os
));
116 static void print_group
117 PARAMS ((lang_group_statement_type
*, lang_output_section_statement_type
*));
118 static void print_statement
PARAMS ((lang_statement_union_type
*s
,
119 lang_output_section_statement_type
*os
));
120 static void print_statement_list
PARAMS ((lang_statement_union_type
*s
,
121 lang_output_section_statement_type
*os
));
122 static void print_statements
PARAMS ((void));
123 static bfd_vma insert_pad
PARAMS ((lang_statement_union_type
**this_ptr
,
124 fill_type fill
, unsigned int power
,
125 asection
*output_section_statement
,
127 static bfd_vma size_input_section
128 PARAMS ((lang_statement_union_type
**this_ptr
,
129 lang_output_section_statement_type
*output_section_statement
,
130 fill_type fill
, bfd_vma dot
, boolean relax
));
131 static void lang_finish
PARAMS ((void));
132 static void ignore_bfd_errors
PARAMS ((const char *, ...));
133 static void lang_check
PARAMS ((void));
134 static void lang_common
PARAMS ((void));
135 static boolean lang_one_common
PARAMS ((struct bfd_link_hash_entry
*, PTR
));
136 static void lang_place_orphans
PARAMS ((void));
137 static int topower
PARAMS ((int));
138 static void lang_set_startof
PARAMS ((void));
139 static void reset_memory_regions
PARAMS ((void));
140 static void lang_record_phdrs
PARAMS ((void));
143 lang_output_section_statement_type
*abs_output_section
;
144 lang_statement_list_type
*stat_ptr
= &statement_list
;
145 lang_statement_list_type file_chain
= { 0 };
146 const char *entry_symbol
= NULL
;
147 boolean entry_from_cmdline
;
148 boolean lang_has_input_file
= false;
149 boolean had_output_filename
= false;
150 boolean lang_float_flag
= false;
151 boolean delete_output_file_on_failure
= false;
152 struct lang_nocrossrefs
*nocrossref_list
;
154 etree_type
*base
; /* Relocation base - or null */
157 #if defined(__STDC__) || defined(ALMOST_STDC)
158 #define cat(a,b) a##b
160 #define cat(a,b) a/**/b
163 #define new_stat(x,y) (cat(x,_type)*) new_statement(cat(x,_enum), sizeof(cat(x,_type)),y)
165 #define outside_section_address(q) ( (q)->output_offset + (q)->output_section->vma)
167 #define outside_symbol_address(q) ((q)->value + outside_section_address(q->section))
169 #define SECTION_NAME_MAP_LENGTH (16)
175 return obstack_alloc (&stat_obstack
, size
);
178 /*----------------------------------------------------------------------
179 lang_for_each_statement walks the parse tree and calls the provided
180 function for each node
184 lang_for_each_statement_worker (func
, s
)
185 void (*func
) PARAMS ((lang_statement_union_type
*));
186 lang_statement_union_type
*s
;
188 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
192 switch (s
->header
.type
)
194 case lang_constructors_statement_enum
:
195 lang_for_each_statement_worker (func
, constructor_list
.head
);
197 case lang_output_section_statement_enum
:
198 lang_for_each_statement_worker
200 s
->output_section_statement
.children
.head
);
202 case lang_wild_statement_enum
:
203 lang_for_each_statement_worker
205 s
->wild_statement
.children
.head
);
207 case lang_group_statement_enum
:
208 lang_for_each_statement_worker (func
,
209 s
->group_statement
.children
.head
);
211 case lang_data_statement_enum
:
212 case lang_reloc_statement_enum
:
213 case lang_object_symbols_statement_enum
:
214 case lang_output_statement_enum
:
215 case lang_target_statement_enum
:
216 case lang_input_section_enum
:
217 case lang_input_statement_enum
:
218 case lang_assignment_statement_enum
:
219 case lang_padding_statement_enum
:
220 case lang_address_statement_enum
:
221 case lang_fill_statement_enum
:
231 lang_for_each_statement (func
)
232 void (*func
) PARAMS ((lang_statement_union_type
*));
234 lang_for_each_statement_worker (func
,
235 statement_list
.head
);
238 /*----------------------------------------------------------------------*/
240 lang_list_init (list
)
241 lang_statement_list_type
*list
;
243 list
->head
= (lang_statement_union_type
*) NULL
;
244 list
->tail
= &list
->head
;
247 /*----------------------------------------------------------------------
249 build a new statement node for the parse tree
254 lang_statement_union_type
*
255 new_statement (type
, size
, list
)
256 enum statement_enum type
;
258 lang_statement_list_type
* list
;
260 lang_statement_union_type
*new = (lang_statement_union_type
*)
263 new->header
.type
= type
;
264 new->header
.next
= (lang_statement_union_type
*) NULL
;
265 lang_statement_append (list
, new, &new->header
.next
);
270 Build a new input file node for the language. There are several ways
271 in which we treat an input file, eg, we only look at symbols, or
272 prefix it with a -l etc.
274 We can be supplied with requests for input files more than once;
275 they may, for example be split over serveral lines like foo.o(.text)
276 foo.o(.data) etc, so when asked for a file we check that we havn't
277 got it already so we don't duplicate the bfd.
280 static lang_input_statement_type
*
281 new_afile (name
, file_type
, target
, add_to_list
)
283 lang_input_file_enum_type file_type
;
287 lang_input_statement_type
*p
;
290 p
= new_stat (lang_input_statement
, stat_ptr
);
293 p
= ((lang_input_statement_type
*)
294 stat_alloc (sizeof (lang_input_statement_type
)));
295 p
->header
.next
= NULL
;
298 lang_has_input_file
= true;
302 case lang_input_file_is_symbols_only_enum
:
304 p
->is_archive
= false;
306 p
->local_sym_name
= name
;
307 p
->just_syms_flag
= true;
308 p
->search_dirs_flag
= false;
310 case lang_input_file_is_fake_enum
:
312 p
->is_archive
= false;
314 p
->local_sym_name
= name
;
315 p
->just_syms_flag
= false;
316 p
->search_dirs_flag
= false;
318 case lang_input_file_is_l_enum
:
319 p
->is_archive
= true;
322 p
->local_sym_name
= concat ("-l", name
, (const char *) NULL
);
323 p
->just_syms_flag
= false;
324 p
->search_dirs_flag
= true;
326 case lang_input_file_is_marker_enum
:
328 p
->is_archive
= false;
330 p
->local_sym_name
= name
;
331 p
->just_syms_flag
= false;
332 p
->search_dirs_flag
= true;
334 case lang_input_file_is_search_file_enum
:
336 p
->is_archive
= false;
338 p
->local_sym_name
= name
;
339 p
->just_syms_flag
= false;
340 p
->search_dirs_flag
= true;
342 case lang_input_file_is_file_enum
:
344 p
->is_archive
= false;
346 p
->local_sym_name
= name
;
347 p
->just_syms_flag
= false;
348 p
->search_dirs_flag
= false;
353 p
->the_bfd
= (bfd
*) NULL
;
354 p
->asymbols
= (asymbol
**) NULL
;
355 p
->next_real_file
= (lang_statement_union_type
*) NULL
;
356 p
->next
= (lang_statement_union_type
*) NULL
;
358 p
->dynamic
= config
.dynamic_link
;
359 p
->whole_archive
= whole_archive
;
361 lang_statement_append (&input_file_chain
,
362 (lang_statement_union_type
*) p
,
367 lang_input_statement_type
*
368 lang_add_input_file (name
, file_type
, target
)
370 lang_input_file_enum_type file_type
;
373 lang_has_input_file
= true;
374 return new_afile (name
, file_type
, target
, true);
377 /* Build enough state so that the parser can build its tree */
381 obstack_begin (&stat_obstack
, 1000);
383 stat_ptr
= &statement_list
;
385 lang_list_init (stat_ptr
);
387 lang_list_init (&input_file_chain
);
388 lang_list_init (&lang_output_section_statement
);
389 lang_list_init (&file_chain
);
390 first_file
= lang_add_input_file ((char *) NULL
,
391 lang_input_file_is_marker_enum
,
393 abs_output_section
= lang_output_section_statement_lookup (BFD_ABS_SECTION_NAME
);
395 abs_output_section
->bfd_section
= bfd_abs_section_ptr
;
399 /*----------------------------------------------------------------------
400 A region is an area of memory declared with the
401 MEMORY { name:org=exp, len=exp ... }
404 We maintain a list of all the regions here
406 If no regions are specified in the script, then the default is used
407 which is created when looked up to be the entire data space
410 static lang_memory_region_type
*lang_memory_region_list
;
411 static lang_memory_region_type
**lang_memory_region_list_tail
= &lang_memory_region_list
;
413 lang_memory_region_type
*
414 lang_memory_region_lookup (name
)
415 CONST
char *CONST name
;
417 lang_memory_region_type
*p
;
419 for (p
= lang_memory_region_list
;
420 p
!= (lang_memory_region_type
*) NULL
;
423 if (strcmp (p
->name
, name
) == 0)
430 /* This code used to always use the first region in the list as the
431 default region. I changed it to instead use a region
432 encompassing all of memory as the default region. This permits
433 NOLOAD sections to work reasonably without requiring a region.
434 People should specify what region they mean, if they really want
436 if (strcmp (name
, "*default*") == 0)
438 if (lang_memory_region_list
!= (lang_memory_region_type
*) NULL
)
440 return lang_memory_region_list
;
446 lang_memory_region_type
*new =
447 (lang_memory_region_type
*) stat_alloc (sizeof (lang_memory_region_type
));
449 new->name
= buystring (name
);
450 new->next
= (lang_memory_region_type
*) NULL
;
452 *lang_memory_region_list_tail
= new;
453 lang_memory_region_list_tail
= &new->next
;
457 new->length
= ~(bfd_size_type
)0;
459 new->had_full_message
= false;
466 lang_memory_region_type
*
467 lang_memory_default (section
)
470 lang_memory_region_type
*p
;
472 flagword sec_flags
= section
->flags
;
474 /* Override SEC_DATA to mean a writable section. */
475 if ((sec_flags
& (SEC_ALLOC
| SEC_READONLY
| SEC_CODE
)) == SEC_ALLOC
)
476 sec_flags
|= SEC_DATA
;
478 for (p
= lang_memory_region_list
;
479 p
!= (lang_memory_region_type
*) NULL
;
482 if ((p
->flags
& sec_flags
) != 0
483 && (p
->not_flags
& sec_flags
) == 0)
488 return lang_memory_region_lookup ("*default*");
491 lang_output_section_statement_type
*
492 lang_output_section_find (name
)
493 CONST
char *CONST name
;
495 lang_statement_union_type
*u
;
496 lang_output_section_statement_type
*lookup
;
498 for (u
= lang_output_section_statement
.head
;
499 u
!= (lang_statement_union_type
*) NULL
;
502 lookup
= &u
->output_section_statement
;
503 if (strcmp (name
, lookup
->name
) == 0)
508 return (lang_output_section_statement_type
*) NULL
;
511 lang_output_section_statement_type
*
512 lang_output_section_statement_lookup (name
)
513 CONST
char *CONST name
;
515 lang_output_section_statement_type
*lookup
;
517 lookup
= lang_output_section_find (name
);
518 if (lookup
== (lang_output_section_statement_type
*) NULL
)
521 lookup
= (lang_output_section_statement_type
*)
522 new_stat (lang_output_section_statement
, stat_ptr
);
523 lookup
->region
= (lang_memory_region_type
*) NULL
;
525 lookup
->block_value
= 1;
528 lookup
->next
= (lang_statement_union_type
*) NULL
;
529 lookup
->bfd_section
= (asection
*) NULL
;
530 lookup
->processed
= false;
531 lookup
->sectype
= normal_section
;
532 lookup
->addr_tree
= (etree_type
*) NULL
;
533 lang_list_init (&lookup
->children
);
535 lookup
->memspec
= (CONST
char *) NULL
;
537 lookup
->subsection_alignment
= -1;
538 lookup
->section_alignment
= -1;
539 lookup
->load_base
= (union etree_union
*) NULL
;
540 lookup
->phdrs
= NULL
;
542 lang_statement_append (&lang_output_section_statement
,
543 (lang_statement_union_type
*) lookup
,
550 lang_map_flags (flag
)
553 if (flag
& SEC_ALLOC
)
559 if (flag
& SEC_READONLY
)
572 lang_memory_region_type
*m
;
574 minfo ("\nMemory Configuration\n\n");
575 fprintf (config
.map_file
, "%-16s %-18s %-18s %s\n",
576 "Name", "Origin", "Length", "Attributes");
578 for (m
= lang_memory_region_list
;
579 m
!= (lang_memory_region_type
*) NULL
;
585 fprintf (config
.map_file
, "%-16s ", m
->name
);
587 sprintf_vma (buf
, m
->origin
);
588 minfo ("0x%s ", buf
);
596 minfo ("0x%V", m
->length
);
597 if (m
->flags
|| m
->not_flags
)
605 lang_map_flags (m
->flags
);
611 lang_map_flags (m
->not_flags
);
618 fprintf (config
.map_file
, "\nLinker script and memory map\n\n");
623 /* Initialize an output section. */
627 lang_output_section_statement_type
*s
;
629 section_userdata_type
*new;
631 if (s
->bfd_section
!= NULL
)
634 if (strcmp (s
->name
, DISCARD_SECTION_NAME
) == 0)
635 einfo ("%P%F: Illegal use of `%s' section", DISCARD_SECTION_NAME
);
637 new = ((section_userdata_type
*)
638 stat_alloc (sizeof (section_userdata_type
)));
640 s
->bfd_section
= bfd_get_section_by_name (output_bfd
, s
->name
);
641 if (s
->bfd_section
== (asection
*) NULL
)
642 s
->bfd_section
= bfd_make_section (output_bfd
, s
->name
);
643 if (s
->bfd_section
== (asection
*) NULL
)
645 einfo ("%P%F: output format %s cannot represent section called %s\n",
646 output_bfd
->xvec
->name
, s
->name
);
648 s
->bfd_section
->output_section
= s
->bfd_section
;
650 /* We initialize an output sections output offset to minus its own */
651 /* vma to allow us to output a section through itself */
652 s
->bfd_section
->output_offset
= 0;
653 get_userdata (s
->bfd_section
) = (PTR
) new;
655 /* If there is a base address, make sure that any sections it might
656 mention are initialized. */
657 if (s
->addr_tree
!= NULL
)
658 exp_init_os (s
->addr_tree
);
661 /* Make sure that all output sections mentioned in an expression are
668 switch (exp
->type
.node_class
)
671 exp_init_os (exp
->assign
.src
);
675 exp_init_os (exp
->binary
.lhs
);
676 exp_init_os (exp
->binary
.rhs
);
680 exp_init_os (exp
->trinary
.cond
);
681 exp_init_os (exp
->trinary
.lhs
);
682 exp_init_os (exp
->trinary
.rhs
);
686 exp_init_os (exp
->unary
.child
);
690 switch (exp
->type
.node_code
)
696 lang_output_section_statement_type
*os
;
698 os
= lang_output_section_find (exp
->name
.name
);
699 if (os
!= NULL
&& os
->bfd_section
== NULL
)
710 /* Sections marked with the SEC_LINK_ONCE flag should only be linked
711 once into the output. This routine checks each sections, and
712 arranges to discard it if a section of the same name has already
713 been linked. This code assumes that all relevant sections have the
714 SEC_LINK_ONCE flag set; that is, it does not depend solely upon the
715 section name. This is called via bfd_map_over_sections. */
719 section_already_linked (abfd
, sec
, data
)
724 lang_input_statement_type
*entry
= (lang_input_statement_type
*) data
;
727 struct sec_link_once
*next
;
730 static struct sec_link_once
*sec_link_once_list
;
733 struct sec_link_once
*l
;
735 /* If we are only reading symbols from this object, then we want to
736 discard all sections. */
737 if (entry
->just_syms_flag
)
739 sec
->output_section
= bfd_abs_section_ptr
;
740 sec
->output_offset
= sec
->vma
;
744 flags
= bfd_get_section_flags (abfd
, sec
);
746 if ((flags
& SEC_LINK_ONCE
) == 0)
749 name
= bfd_get_section_name (abfd
, sec
);
751 for (l
= sec_link_once_list
; l
!= NULL
; l
= l
->next
)
753 if (strcmp (name
, bfd_get_section_name (l
->sec
->owner
, l
->sec
)) == 0)
755 /* The section has already been linked. See if we should
757 switch (flags
& SEC_LINK_DUPLICATES
)
762 case SEC_LINK_DUPLICATES_DISCARD
:
765 case SEC_LINK_DUPLICATES_ONE_ONLY
:
766 einfo ("%P: %B: warning: ignoring duplicate section `%s'\n",
770 case SEC_LINK_DUPLICATES_SAME_CONTENTS
:
771 /* FIXME: We should really dig out the contents of both
772 sections and memcmp them. The COFF/PE spec says that
773 the Microsoft linker does not implement this
774 correctly, so I'm not going to bother doing it
777 case SEC_LINK_DUPLICATES_SAME_SIZE
:
778 if (bfd_section_size (abfd
, sec
)
779 != bfd_section_size (l
->sec
->owner
, l
->sec
))
780 einfo ("%P: %B: warning: duplicate section `%s' has different size\n",
785 /* Set the output_section field so that wild_doit does not
786 create a lang_input_section structure for this section. */
787 sec
->output_section
= bfd_abs_section_ptr
;
793 /* This is the first section with this name. Record it. */
795 l
= (struct sec_link_once
*) xmalloc (sizeof *l
);
797 l
->next
= sec_link_once_list
;
798 sec_link_once_list
= l
;
801 /* The wild routines.
803 These expand statements like *(.text) and foo.o to a list of
804 explicit actions, like foo.o(.text), bar.o(.text) and
805 foo.o(.text, .data). */
807 /* Return true if the PATTERN argument is a wildcard pattern.
808 Although backslashes are treated specially if a pattern contains
809 wildcards, we do not consider the mere presence of a backslash to
810 be enough to cause the the pattern to be treated as a wildcard.
811 That lets us handle DOS filenames more naturally. */
819 for (s
= pattern
; *s
!= '\0'; ++s
)
827 /* Add SECTION to the output section OUTPUT. Do this by creating a
828 lang_input_section statement which is placed at PTR. FILE is the
829 input file which holds SECTION. */
832 wild_doit (ptr
, section
, output
, file
)
833 lang_statement_list_type
*ptr
;
835 lang_output_section_statement_type
*output
;
836 lang_input_statement_type
*file
;
841 flags
= bfd_get_section_flags (section
->owner
, section
);
845 /* If we are doing a final link, discard sections marked with
847 if (! link_info
.relocateable
848 && (flags
& SEC_EXCLUDE
) != 0)
851 /* Discard input sections which are assigned to a section named
852 DISCARD_SECTION_NAME. */
853 if (strcmp (output
->name
, DISCARD_SECTION_NAME
) == 0)
856 /* Discard debugging sections if we are stripping debugging
858 if ((link_info
.strip
== strip_debugger
|| link_info
.strip
== strip_all
)
859 && (flags
& SEC_DEBUGGING
) != 0)
864 if (section
->output_section
== NULL
)
866 /* This prevents future calls from assigning this section. */
867 section
->output_section
= bfd_abs_section_ptr
;
872 if (section
->output_section
== NULL
)
875 lang_input_section_type
*new;
878 if (output
->bfd_section
== NULL
)
886 /* Add a section reference to the list */
887 new = new_stat (lang_input_section
, ptr
);
889 new->section
= section
;
891 section
->output_section
= output
->bfd_section
;
893 flags
= section
->flags
;
895 /* We don't copy the SEC_NEVER_LOAD flag from an input section
896 to an output section, because we want to be able to include a
897 SEC_NEVER_LOAD section in the middle of an otherwise loaded
898 section (I don't know why we want to do this, but we do).
899 build_link_order in ldwrite.c handles this case by turning
900 the embedded SEC_NEVER_LOAD section into a fill. */
902 flags
&= ~ SEC_NEVER_LOAD
;
904 /* If final link, don't copy the SEC_LINK_ONCE flags, they've
905 already been processed. One reason to do this is that on pe
906 format targets, .text$foo sections go into .text and it's odd
907 to see .text with SEC_LINK_ONCE set. */
909 if (! link_info
.relocateable
)
910 flags
&= ~ (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES
);
912 /* If this is not the first input section, and the SEC_READONLY
913 flag is not currently set, then don't set it just because the
914 input section has it set. */
916 if (! first
&& (section
->output_section
->flags
& SEC_READONLY
) == 0)
917 flags
&= ~ SEC_READONLY
;
919 section
->output_section
->flags
|= flags
;
921 /* If SEC_READONLY is not set in the input section, then clear
922 it from the output section. */
923 if ((section
->flags
& SEC_READONLY
) == 0)
924 section
->output_section
->flags
&= ~SEC_READONLY
;
926 switch (output
->sectype
)
933 case overlay_section
:
934 output
->bfd_section
->flags
&= ~SEC_ALLOC
;
937 output
->bfd_section
->flags
&= ~SEC_LOAD
;
938 output
->bfd_section
->flags
|= SEC_NEVER_LOAD
;
942 if (section
->alignment_power
> output
->bfd_section
->alignment_power
)
943 output
->bfd_section
->alignment_power
= section
->alignment_power
;
945 /* If supplied an aligment, then force it. */
946 if (output
->section_alignment
!= -1)
947 output
->bfd_section
->alignment_power
= output
->section_alignment
;
951 /* Expand a wild statement for a particular FILE. SECTION may be
952 NULL, in which case it is a wild card. */
955 wild_section (ptr
, section
, file
, output
)
956 lang_wild_statement_type
*ptr
;
958 lang_input_statement_type
*file
;
959 lang_output_section_statement_type
*output
;
961 if (file
->just_syms_flag
== false)
963 register asection
*s
;
969 wildcard
= wildcardp (section
);
971 for (s
= file
->the_bfd
->sections
; s
!= NULL
; s
= s
->next
)
975 /* Attach all sections named SECTION. If SECTION is NULL,
976 then attach all sections.
978 Previously, if SECTION was NULL, this code did not call
979 wild_doit if the SEC_IS_COMMON flag was set for the
980 section. I did not understand that, and I took it out.
989 name
= bfd_get_section_name (file
->the_bfd
, s
);
991 match
= fnmatch (section
, name
, 0) == 0 ? true : false;
993 match
= strcmp (section
, name
) == 0 ? true : false;
996 wild_doit (&ptr
->children
, s
, output
, file
);
1001 /* This is passed a file name which must have been seen already and
1002 added to the statement tree. We will see if it has been opened
1003 already and had its symbols read. If not then we'll read it. */
1005 static lang_input_statement_type
*
1009 lang_input_statement_type
*search
;
1011 for (search
= (lang_input_statement_type
*) input_file_chain
.head
;
1012 search
!= (lang_input_statement_type
*) NULL
;
1013 search
= (lang_input_statement_type
*) search
->next_real_file
)
1015 if (search
->filename
== (char *) NULL
&& name
== (char *) NULL
)
1017 if (search
->filename
!= (char *) NULL
1018 && name
!= (char *) NULL
1019 && strcmp (search
->filename
, name
) == 0)
1023 if (search
== (lang_input_statement_type
*) NULL
)
1024 search
= new_afile (name
, lang_input_file_is_file_enum
, default_target
,
1027 /* If we have already added this file, or this file is not real
1028 (FIXME: can that ever actually happen?) or the name is NULL
1029 (FIXME: can that ever actually happen?) don't add this file. */
1032 || search
->filename
== (const char *) NULL
)
1035 load_symbols (search
, (lang_statement_list_type
*) NULL
);
1040 /* Get the symbols for an input file. */
1043 load_symbols (entry
, place
)
1044 lang_input_statement_type
*entry
;
1045 lang_statement_list_type
*place
;
1052 ldfile_open_file (entry
);
1054 if (! bfd_check_format (entry
->the_bfd
, bfd_archive
)
1055 && ! bfd_check_format_matches (entry
->the_bfd
, bfd_object
, &matching
))
1058 lang_statement_list_type
*hold
;
1060 err
= bfd_get_error ();
1061 if (err
== bfd_error_file_ambiguously_recognized
)
1065 einfo ("%B: file not recognized: %E\n", entry
->the_bfd
);
1066 einfo ("%B: matching formats:", entry
->the_bfd
);
1067 for (p
= matching
; *p
!= NULL
; p
++)
1071 else if (err
!= bfd_error_file_not_recognized
1073 einfo ("%F%B: file not recognized: %E\n", entry
->the_bfd
);
1075 bfd_close (entry
->the_bfd
);
1076 entry
->the_bfd
= NULL
;
1078 /* See if the emulation has some special knowledge. */
1080 if (ldemul_unrecognized_file (entry
))
1083 /* Try to interpret the file as a linker script. */
1085 ldfile_open_command_file (entry
->filename
);
1090 ldfile_assumed_script
= true;
1091 parser_input
= input_script
;
1093 ldfile_assumed_script
= false;
1100 /* We don't call ldlang_add_file for an archive. Instead, the
1101 add_symbols entry point will call ldlang_add_file, via the
1102 add_archive_element callback, for each element of the archive
1104 switch (bfd_get_format (entry
->the_bfd
))
1110 ldlang_add_file (entry
);
1111 if (trace_files
|| trace_file_tries
)
1112 info_msg ("%I\n", entry
);
1116 if (entry
->whole_archive
)
1118 bfd
*member
= bfd_openr_next_archived_file (entry
->the_bfd
,
1120 while (member
!= NULL
)
1122 if (! bfd_check_format (member
, bfd_object
))
1123 einfo ("%F%B: object %B in archive is not object\n",
1124 entry
->the_bfd
, member
);
1125 if (! ((*link_info
.callbacks
->add_archive_element
)
1126 (&link_info
, member
, "--whole-archive")))
1128 if (! bfd_link_add_symbols (member
, &link_info
))
1129 einfo ("%F%B: could not read symbols: %E\n", member
);
1130 member
= bfd_openr_next_archived_file (entry
->the_bfd
,
1134 entry
->loaded
= true;
1140 if (! bfd_link_add_symbols (entry
->the_bfd
, &link_info
))
1141 einfo ("%F%B: could not read symbols: %E\n", entry
->the_bfd
);
1143 entry
->loaded
= true;
1146 /* Handle a wild statement for a single file F. */
1149 wild_file (s
, section
, f
, output
)
1150 lang_wild_statement_type
*s
;
1151 const char *section
;
1152 lang_input_statement_type
*f
;
1153 lang_output_section_statement_type
*output
;
1155 if (f
->the_bfd
== NULL
1156 || ! bfd_check_format (f
->the_bfd
, bfd_archive
))
1157 wild_section (s
, section
, f
, output
);
1162 /* This is an archive file. We must map each member of the
1163 archive separately. */
1164 member
= bfd_openr_next_archived_file (f
->the_bfd
, (bfd
*) NULL
);
1165 while (member
!= NULL
)
1167 /* When lookup_name is called, it will call the add_symbols
1168 entry point for the archive. For each element of the
1169 archive which is included, BFD will call ldlang_add_file,
1170 which will set the usrdata field of the member to the
1171 lang_input_statement. */
1172 if (member
->usrdata
!= NULL
)
1174 wild_section (s
, section
,
1175 (lang_input_statement_type
*) member
->usrdata
,
1179 member
= bfd_openr_next_archived_file (f
->the_bfd
, member
);
1184 /* Handle a wild statement. SECTION or FILE or both may be NULL,
1185 indicating that it is a wildcard. Separate lang_input_section
1186 statements are created for each part of the expansion; they are
1187 added after the wild statement S. OUTPUT is the output section. */
1190 wild (s
, section
, file
, target
, output
)
1191 lang_wild_statement_type
*s
;
1192 const char *section
;
1195 lang_output_section_statement_type
*output
;
1197 lang_input_statement_type
*f
;
1199 if (file
== (char *) NULL
)
1201 /* Perform the iteration over all files in the list */
1202 for (f
= (lang_input_statement_type
*) file_chain
.head
;
1203 f
!= (lang_input_statement_type
*) NULL
;
1204 f
= (lang_input_statement_type
*) f
->next
)
1206 wild_file (s
, section
, f
, output
);
1209 else if (wildcardp (file
))
1211 for (f
= (lang_input_statement_type
*) file_chain
.head
;
1212 f
!= (lang_input_statement_type
*) NULL
;
1213 f
= (lang_input_statement_type
*) f
->next
)
1215 if (fnmatch (file
, f
->filename
, FNM_FILE_NAME
) == 0)
1216 wild_file (s
, section
, f
, output
);
1221 /* Perform the iteration over a single file */
1222 f
= lookup_name (file
);
1223 wild_file (s
, section
, f
, output
);
1226 if (section
!= (char *) NULL
1227 && strcmp (section
, "COMMON") == 0
1228 && default_common_section
== NULL
)
1230 /* Remember the section that common is going to in case we later
1231 get something which doesn't know where to put it. */
1232 default_common_section
= output
;
1236 /* Open the output file. */
1244 if (output_target
== (char *) NULL
)
1246 if (current_target
!= (char *) NULL
)
1247 output_target
= current_target
;
1249 output_target
= default_target
;
1251 output
= bfd_openw (name
, output_target
);
1253 if (output
== (bfd
*) NULL
)
1255 if (bfd_get_error () == bfd_error_invalid_target
)
1257 einfo ("%P%F: target %s not found\n", output_target
);
1259 einfo ("%P%F: cannot open output file %s: %E\n", name
);
1262 delete_output_file_on_failure
= true;
1264 /* output->flags |= D_PAGED;*/
1266 if (! bfd_set_format (output
, bfd_object
))
1267 einfo ("%P%F:%s: can not make object file: %E\n", name
);
1268 if (! bfd_set_arch_mach (output
,
1269 ldfile_output_architecture
,
1270 ldfile_output_machine
))
1271 einfo ("%P%F:%s: can not set architecture: %E\n", name
);
1273 link_info
.hash
= bfd_link_hash_table_create (output
);
1274 if (link_info
.hash
== (struct bfd_link_hash_table
*) NULL
)
1275 einfo ("%P%F: can not create link hash table: %E\n");
1277 bfd_set_gp_size (output
, g_switch_value
);
1285 ldlang_open_output (statement
)
1286 lang_statement_union_type
* statement
;
1288 switch (statement
->header
.type
)
1290 case lang_output_statement_enum
:
1291 ASSERT (output_bfd
== (bfd
*) NULL
);
1292 output_bfd
= open_output (statement
->output_statement
.name
);
1293 ldemul_set_output_arch ();
1294 if (config
.magic_demand_paged
&& !link_info
.relocateable
)
1295 output_bfd
->flags
|= D_PAGED
;
1297 output_bfd
->flags
&= ~D_PAGED
;
1298 if (config
.text_read_only
)
1299 output_bfd
->flags
|= WP_TEXT
;
1301 output_bfd
->flags
&= ~WP_TEXT
;
1302 if (link_info
.traditional_format
)
1303 output_bfd
->flags
|= BFD_TRADITIONAL_FORMAT
;
1305 output_bfd
->flags
&= ~BFD_TRADITIONAL_FORMAT
;
1308 case lang_target_statement_enum
:
1309 current_target
= statement
->target_statement
.target
;
1316 /* Open all the input files. */
1319 open_input_bfds (s
, force
)
1320 lang_statement_union_type
*s
;
1323 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
1325 switch (s
->header
.type
)
1327 case lang_constructors_statement_enum
:
1328 open_input_bfds (constructor_list
.head
, force
);
1330 case lang_output_section_statement_enum
:
1331 open_input_bfds (s
->output_section_statement
.children
.head
, force
);
1333 case lang_wild_statement_enum
:
1334 /* Maybe we should load the file's symbols */
1335 if (s
->wild_statement
.filename
1336 && ! wildcardp (s
->wild_statement
.filename
))
1337 (void) lookup_name (s
->wild_statement
.filename
);
1338 open_input_bfds (s
->wild_statement
.children
.head
, force
);
1340 case lang_group_statement_enum
:
1342 struct bfd_link_hash_entry
*undefs
;
1344 /* We must continually search the entries in the group
1345 until no new symbols are added to the list of undefined
1350 undefs
= link_info
.hash
->undefs_tail
;
1351 open_input_bfds (s
->group_statement
.children
.head
, true);
1353 while (undefs
!= link_info
.hash
->undefs_tail
);
1356 case lang_target_statement_enum
:
1357 current_target
= s
->target_statement
.target
;
1359 case lang_input_statement_enum
:
1360 if (s
->input_statement
.real
== true)
1362 lang_statement_list_type add
;
1364 s
->input_statement
.target
= current_target
;
1366 /* If we are being called from within a group, and this
1367 is an archive which has already been searched, then
1368 force it to be researched. */
1370 && s
->input_statement
.loaded
1371 && bfd_check_format (s
->input_statement
.the_bfd
,
1373 s
->input_statement
.loaded
= false;
1375 lang_list_init (&add
);
1377 load_symbols (&s
->input_statement
, &add
);
1379 if (add
.head
!= NULL
)
1381 *add
.tail
= s
->next
;
1392 /* If there are [COMMONS] statements, put a wild one into the bss section */
1395 lang_reasonable_defaults ()
1398 lang_output_section_statement_lookup (".text");
1399 lang_output_section_statement_lookup (".data");
1401 default_common_section
=
1402 lang_output_section_statement_lookup (".bss");
1405 if (placed_commons
== false)
1407 lang_wild_statement_type
*new =
1408 new_stat (lang_wild_statement
,
1409 &default_common_section
->children
);
1411 new->section_name
= "COMMON";
1412 new->filename
= (char *) NULL
;
1413 lang_list_init (&new->children
);
1420 Add the supplied name to the symbol table as an undefined reference.
1421 Remove items from the chain as we open input bfds
1423 typedef struct ldlang_undef_chain_list
1425 struct ldlang_undef_chain_list
*next
;
1427 } ldlang_undef_chain_list_type
;
1429 static ldlang_undef_chain_list_type
*ldlang_undef_chain_list_head
;
1432 ldlang_add_undef (name
)
1433 CONST
char *CONST name
;
1435 ldlang_undef_chain_list_type
*new =
1436 ((ldlang_undef_chain_list_type
*)
1437 stat_alloc (sizeof (ldlang_undef_chain_list_type
)));
1439 new->next
= ldlang_undef_chain_list_head
;
1440 ldlang_undef_chain_list_head
= new;
1442 new->name
= buystring (name
);
1445 /* Run through the list of undefineds created above and place them
1446 into the linker hash table as undefined symbols belonging to the
1450 lang_place_undefineds ()
1452 ldlang_undef_chain_list_type
*ptr
;
1454 for (ptr
= ldlang_undef_chain_list_head
;
1455 ptr
!= (ldlang_undef_chain_list_type
*) NULL
;
1458 struct bfd_link_hash_entry
*h
;
1460 h
= bfd_link_hash_lookup (link_info
.hash
, ptr
->name
, true, false, true);
1461 if (h
== (struct bfd_link_hash_entry
*) NULL
)
1462 einfo ("%P%F: bfd_link_hash_lookup failed: %E\n");
1463 if (h
->type
== bfd_link_hash_new
)
1465 h
->type
= bfd_link_hash_undefined
;
1466 h
->u
.undef
.abfd
= NULL
;
1467 bfd_link_add_undef (link_info
.hash
, h
);
1472 /* Open input files and attatch to output sections */
1474 map_input_to_output_sections (s
, target
, output_section_statement
)
1475 lang_statement_union_type
* s
;
1477 lang_output_section_statement_type
* output_section_statement
;
1479 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
1481 switch (s
->header
.type
)
1485 case lang_wild_statement_enum
:
1486 wild (&s
->wild_statement
, s
->wild_statement
.section_name
,
1487 s
->wild_statement
.filename
, target
,
1488 output_section_statement
);
1491 case lang_constructors_statement_enum
:
1492 map_input_to_output_sections (constructor_list
.head
,
1494 output_section_statement
);
1496 case lang_output_section_statement_enum
:
1497 map_input_to_output_sections (s
->output_section_statement
.children
.head
,
1499 &s
->output_section_statement
);
1501 case lang_output_statement_enum
:
1503 case lang_target_statement_enum
:
1504 target
= s
->target_statement
.target
;
1506 case lang_group_statement_enum
:
1507 map_input_to_output_sections (s
->group_statement
.children
.head
,
1509 output_section_statement
);
1511 case lang_fill_statement_enum
:
1512 case lang_input_section_enum
:
1513 case lang_object_symbols_statement_enum
:
1514 case lang_data_statement_enum
:
1515 case lang_reloc_statement_enum
:
1516 case lang_padding_statement_enum
:
1517 case lang_input_statement_enum
:
1518 if (output_section_statement
!= NULL
1519 && output_section_statement
->bfd_section
== NULL
)
1520 init_os (output_section_statement
);
1522 case lang_assignment_statement_enum
:
1523 if (output_section_statement
!= NULL
1524 && output_section_statement
->bfd_section
== NULL
)
1525 init_os (output_section_statement
);
1527 /* Make sure that any sections mentioned in the assignment
1529 exp_init_os (s
->assignment_statement
.exp
);
1531 case lang_afile_asection_pair_statement_enum
:
1534 case lang_address_statement_enum
:
1535 /* Mark the specified section with the supplied address */
1537 lang_output_section_statement_type
*os
=
1538 lang_output_section_statement_lookup
1539 (s
->address_statement
.section_name
);
1541 if (os
->bfd_section
== NULL
)
1543 os
->addr_tree
= s
->address_statement
.address
;
1551 print_output_section_statement (output_section_statement
)
1552 lang_output_section_statement_type
* output_section_statement
;
1554 asection
*section
= output_section_statement
->bfd_section
;
1557 if (output_section_statement
!= abs_output_section
)
1559 minfo ("\n%s", output_section_statement
->name
);
1561 if (section
!= NULL
)
1563 print_dot
= section
->vma
;
1565 len
= strlen (output_section_statement
->name
);
1566 if (len
>= SECTION_NAME_MAP_LENGTH
- 1)
1571 while (len
< SECTION_NAME_MAP_LENGTH
)
1577 minfo ("0x%V %W", section
->vma
, section
->_raw_size
);
1579 if (output_section_statement
->load_base
!= NULL
)
1583 addr
= exp_get_abs_int (output_section_statement
->load_base
, 0,
1584 "load base", lang_final_phase_enum
);
1585 minfo (" load address 0x%V", addr
);
1592 print_statement_list (output_section_statement
->children
.head
,
1593 output_section_statement
);
1597 print_assignment (assignment
, output_section
)
1598 lang_assignment_statement_type
* assignment
;
1599 lang_output_section_statement_type
* output_section
;
1602 etree_value_type result
;
1604 for (i
= 0; i
< SECTION_NAME_MAP_LENGTH
; i
++)
1607 result
= exp_fold_tree (assignment
->exp
->assign
.src
, output_section
,
1608 lang_final_phase_enum
, print_dot
, &print_dot
);
1610 minfo ("0x%V", result
.value
+ result
.section
->bfd_section
->vma
);
1621 exp_print_tree (assignment
->exp
);
1627 print_input_statement (statm
)
1628 lang_input_statement_type
* statm
;
1630 if (statm
->filename
!= (char *) NULL
)
1632 fprintf (config
.map_file
, "LOAD %s\n", statm
->filename
);
1636 /* Print all symbols defined in a particular section. This is called
1637 via bfd_link_hash_traverse. */
1640 print_one_symbol (hash_entry
, ptr
)
1641 struct bfd_link_hash_entry
*hash_entry
;
1644 asection
*sec
= (asection
*) ptr
;
1646 if ((hash_entry
->type
== bfd_link_hash_defined
1647 || hash_entry
->type
== bfd_link_hash_defweak
)
1648 && sec
== hash_entry
->u
.def
.section
)
1652 for (i
= 0; i
< SECTION_NAME_MAP_LENGTH
; i
++)
1655 (hash_entry
->u
.def
.value
1656 + hash_entry
->u
.def
.section
->output_offset
1657 + hash_entry
->u
.def
.section
->output_section
->vma
));
1659 minfo (" %T\n", hash_entry
->root
.string
);
1665 /* Print information about an input section to the map file. */
1668 print_input_section (in
)
1669 lang_input_section_type
* in
;
1671 asection
*i
= in
->section
;
1672 bfd_size_type size
= i
->_cooked_size
!= 0 ? i
->_cooked_size
: i
->_raw_size
;
1678 minfo ("%s", i
->name
);
1680 if (i
->output_section
!= NULL
)
1684 len
= 1 + strlen (i
->name
);
1685 if (len
>= SECTION_NAME_MAP_LENGTH
- 1)
1690 while (len
< SECTION_NAME_MAP_LENGTH
)
1696 minfo ("0x%V %W %B\n",
1697 i
->output_section
->vma
+ i
->output_offset
, size
,
1700 if (i
->_cooked_size
!= 0 && i
->_cooked_size
!= i
->_raw_size
)
1702 len
= SECTION_NAME_MAP_LENGTH
+ 3;
1714 minfo ("%W (size before relaxing)\n", i
->_raw_size
);
1717 bfd_link_hash_traverse (link_info
.hash
, print_one_symbol
, (PTR
) i
);
1719 print_dot
= i
->output_section
->vma
+ i
->output_offset
+ size
;
1725 print_fill_statement (fill
)
1726 lang_fill_statement_type
* fill
;
1728 fprintf (config
.map_file
, " FILL mask 0x%x\n", fill
->fill
);
1732 print_data_statement (data
)
1733 lang_data_statement_type
* data
;
1740 for (i
= 0; i
< SECTION_NAME_MAP_LENGTH
; i
++)
1743 addr
= data
->output_vma
;
1744 if (data
->output_section
!= NULL
)
1745 addr
+= data
->output_section
->vma
;
1773 minfo ("0x%V %W %s 0x%v", addr
, size
, name
, data
->value
);
1775 if (data
->exp
->type
.node_class
!= etree_value
)
1778 exp_print_tree (data
->exp
);
1783 print_dot
= addr
+ size
;
1786 /* Print an address statement. These are generated by options like
1790 print_address_statement (address
)
1791 lang_address_statement_type
*address
;
1793 minfo ("Address of section %s set to ", address
->section_name
);
1794 exp_print_tree (address
->address
);
1798 /* Print a reloc statement. */
1801 print_reloc_statement (reloc
)
1802 lang_reloc_statement_type
*reloc
;
1808 for (i
= 0; i
< SECTION_NAME_MAP_LENGTH
; i
++)
1811 addr
= reloc
->output_vma
;
1812 if (reloc
->output_section
!= NULL
)
1813 addr
+= reloc
->output_section
->vma
;
1815 size
= bfd_get_reloc_size (reloc
->howto
);
1817 minfo ("0x%V %W RELOC %s ", addr
, size
, reloc
->howto
->name
);
1819 if (reloc
->name
!= NULL
)
1820 minfo ("%s+", reloc
->name
);
1822 minfo ("%s+", reloc
->section
->name
);
1824 exp_print_tree (reloc
->addend_exp
);
1828 print_dot
= addr
+ size
;
1832 print_padding_statement (s
)
1833 lang_padding_statement_type
*s
;
1840 len
= sizeof " *fill*" - 1;
1841 while (len
< SECTION_NAME_MAP_LENGTH
)
1847 addr
= s
->output_offset
;
1848 if (s
->output_section
!= NULL
)
1849 addr
+= s
->output_section
->vma
;
1850 minfo ("0x%V %W", addr
, s
->size
);
1853 minfo (" %u", s
->fill
);
1857 print_dot
= addr
+ s
->size
;
1861 print_wild_statement (w
, os
)
1862 lang_wild_statement_type
* w
;
1863 lang_output_section_statement_type
* os
;
1867 if (w
->filename
!= NULL
)
1868 minfo ("%s", w
->filename
);
1872 if (w
->section_name
!= NULL
)
1873 minfo ("(%s)", w
->section_name
);
1879 print_statement_list (w
->children
.head
, os
);
1882 /* Print a group statement. */
1886 lang_group_statement_type
*s
;
1887 lang_output_section_statement_type
*os
;
1889 fprintf (config
.map_file
, "START GROUP\n");
1890 print_statement_list (s
->children
.head
, os
);
1891 fprintf (config
.map_file
, "END GROUP\n");
1894 /* Print the list of statements in S.
1895 This can be called for any statement type. */
1898 print_statement_list (s
, os
)
1899 lang_statement_union_type
*s
;
1900 lang_output_section_statement_type
*os
;
1904 print_statement (s
, os
);
1909 /* Print the first statement in statement list S.
1910 This can be called for any statement type. */
1913 print_statement (s
, os
)
1914 lang_statement_union_type
*s
;
1915 lang_output_section_statement_type
*os
;
1917 switch (s
->header
.type
)
1920 fprintf (config
.map_file
, "Fail with %d\n", s
->header
.type
);
1923 case lang_constructors_statement_enum
:
1924 if (constructor_list
.head
!= NULL
)
1926 minfo (" CONSTRUCTORS\n");
1927 print_statement_list (constructor_list
.head
, os
);
1930 case lang_wild_statement_enum
:
1931 print_wild_statement (&s
->wild_statement
, os
);
1933 case lang_address_statement_enum
:
1934 print_address_statement (&s
->address_statement
);
1936 case lang_object_symbols_statement_enum
:
1937 minfo (" CREATE_OBJECT_SYMBOLS\n");
1939 case lang_fill_statement_enum
:
1940 print_fill_statement (&s
->fill_statement
);
1942 case lang_data_statement_enum
:
1943 print_data_statement (&s
->data_statement
);
1945 case lang_reloc_statement_enum
:
1946 print_reloc_statement (&s
->reloc_statement
);
1948 case lang_input_section_enum
:
1949 print_input_section (&s
->input_section
);
1951 case lang_padding_statement_enum
:
1952 print_padding_statement (&s
->padding_statement
);
1954 case lang_output_section_statement_enum
:
1955 print_output_section_statement (&s
->output_section_statement
);
1957 case lang_assignment_statement_enum
:
1958 print_assignment (&s
->assignment_statement
, os
);
1960 case lang_target_statement_enum
:
1961 fprintf (config
.map_file
, "TARGET(%s)\n", s
->target_statement
.target
);
1963 case lang_output_statement_enum
:
1964 minfo ("OUTPUT(%s", s
->output_statement
.name
);
1965 if (output_target
!= NULL
)
1966 minfo (" %s", output_target
);
1969 case lang_input_statement_enum
:
1970 print_input_statement (&s
->input_statement
);
1972 case lang_group_statement_enum
:
1973 print_group (&s
->group_statement
, os
);
1975 case lang_afile_asection_pair_statement_enum
:
1984 print_statement_list (statement_list
.head
, abs_output_section
);
1987 /* Print the first N statements in statement list S to STDERR.
1988 If N == 0, nothing is printed.
1989 If N < 0, the entire list is printed.
1990 Intended to be called from GDB. */
1993 dprint_statement (s
, n
)
1994 lang_statement_union_type
* s
;
1997 FILE *map_save
= config
.map_file
;
1999 config
.map_file
= stderr
;
2002 print_statement_list (s
, abs_output_section
);
2005 while (s
&& --n
>= 0)
2007 print_statement (s
, abs_output_section
);
2012 config
.map_file
= map_save
;
2016 insert_pad (this_ptr
, fill
, power
, output_section_statement
, dot
)
2017 lang_statement_union_type
** this_ptr
;
2020 asection
* output_section_statement
;
2023 /* Align this section first to the
2024 input sections requirement, then
2025 to the output section's requirement.
2026 If this alignment is > than any seen before,
2027 then record it too. Perform the alignment by
2028 inserting a magic 'padding' statement.
2031 unsigned int alignment_needed
= align_power (dot
, power
) - dot
;
2033 if (alignment_needed
!= 0)
2035 lang_statement_union_type
*new =
2036 ((lang_statement_union_type
*)
2037 stat_alloc (sizeof (lang_padding_statement_type
)));
2039 /* Link into existing chain */
2040 new->header
.next
= *this_ptr
;
2042 new->header
.type
= lang_padding_statement_enum
;
2043 new->padding_statement
.output_section
= output_section_statement
;
2044 new->padding_statement
.output_offset
=
2045 dot
- output_section_statement
->vma
;
2046 new->padding_statement
.fill
= fill
;
2047 new->padding_statement
.size
= alignment_needed
;
2051 /* Remember the most restrictive alignment */
2052 if (power
> output_section_statement
->alignment_power
)
2054 output_section_statement
->alignment_power
= power
;
2056 output_section_statement
->_raw_size
+= alignment_needed
;
2057 return alignment_needed
+ dot
;
2061 /* Work out how much this section will move the dot point */
2063 size_input_section (this_ptr
, output_section_statement
, fill
, dot
, relax
)
2064 lang_statement_union_type
** this_ptr
;
2065 lang_output_section_statement_type
* output_section_statement
;
2070 lang_input_section_type
*is
= &((*this_ptr
)->input_section
);
2071 asection
*i
= is
->section
;
2073 if (is
->ifile
->just_syms_flag
== false)
2075 if (output_section_statement
->subsection_alignment
!= -1)
2076 i
->alignment_power
=
2077 output_section_statement
->subsection_alignment
;
2079 dot
= insert_pad (this_ptr
, fill
, i
->alignment_power
,
2080 output_section_statement
->bfd_section
, dot
);
2082 /* Remember where in the output section this input section goes */
2084 i
->output_offset
= dot
- output_section_statement
->bfd_section
->vma
;
2086 /* Mark how big the output section must be to contain this now
2088 if (i
->_cooked_size
!= 0)
2089 dot
+= i
->_cooked_size
;
2091 dot
+= i
->_raw_size
;
2092 output_section_statement
->bfd_section
->_raw_size
= dot
- output_section_statement
->bfd_section
->vma
;
2096 i
->output_offset
= i
->vma
- output_section_statement
->bfd_section
->vma
;
2102 /* This variable indicates whether bfd_relax_section should be called
2105 static boolean relax_again
;
2107 /* Set the sizes for all the output sections. */
2110 lang_size_sections (s
, output_section_statement
, prev
, fill
, dot
, relax
)
2111 lang_statement_union_type
* s
;
2112 lang_output_section_statement_type
* output_section_statement
;
2113 lang_statement_union_type
** prev
;
2118 /* Size up the sections from their constituent parts */
2119 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
2121 switch (s
->header
.type
)
2124 case lang_output_section_statement_enum
:
2127 lang_output_section_statement_type
*os
= &s
->output_section_statement
;
2129 if (os
->bfd_section
== NULL
)
2131 /* This section was never actually created. */
2135 /* If this is a COFF shared library section, use the size and
2136 address from the input section. FIXME: This is COFF
2137 specific; it would be cleaner if there were some other way
2138 to do this, but nothing simple comes to mind. */
2139 if ((os
->bfd_section
->flags
& SEC_COFF_SHARED_LIBRARY
) != 0)
2143 if (os
->children
.head
== NULL
2144 || os
->children
.head
->next
!= NULL
2145 || os
->children
.head
->header
.type
!= lang_input_section_enum
)
2146 einfo ("%P%X: Internal error on COFF shared library section %s\n",
2149 input
= os
->children
.head
->input_section
.section
;
2150 bfd_set_section_vma (os
->bfd_section
->owner
,
2152 bfd_section_vma (input
->owner
, input
));
2153 os
->bfd_section
->_raw_size
= input
->_raw_size
;
2157 if (bfd_is_abs_section (os
->bfd_section
))
2159 /* No matter what happens, an abs section starts at zero */
2160 ASSERT (os
->bfd_section
->vma
== 0);
2164 if (os
->addr_tree
== (etree_type
*) NULL
)
2166 /* No address specified for this section, get one
2167 from the region specification
2169 if (os
->region
== (lang_memory_region_type
*) NULL
2170 || (((bfd_get_section_flags (output_bfd
, os
->bfd_section
)
2171 & (SEC_ALLOC
| SEC_LOAD
)) != 0)
2172 && os
->region
->name
[0] == '*'
2173 && strcmp (os
->region
->name
, "*default*") == 0))
2175 os
->region
= lang_memory_default (os
->bfd_section
);
2178 /* If a loadable section is using the default memory
2179 region, and some non default memory regions were
2180 defined, issue a warning. */
2181 if ((bfd_get_section_flags (output_bfd
, os
->bfd_section
)
2182 & (SEC_ALLOC
| SEC_LOAD
)) != 0
2183 && ! link_info
.relocateable
2184 && strcmp (os
->region
->name
, "*default*") == 0
2185 && lang_memory_region_list
!= NULL
2186 && (strcmp (lang_memory_region_list
->name
, "*default*") != 0
2187 || lang_memory_region_list
->next
!= NULL
))
2188 einfo ("%P: warning: no memory region specified for section `%s'\n",
2189 bfd_get_section_name (output_bfd
, os
->bfd_section
));
2191 dot
= os
->region
->current
;
2192 if (os
->section_alignment
== -1)
2197 dot
= align_power (dot
, os
->bfd_section
->alignment_power
);
2198 if (dot
!= olddot
&& config
.warn_section_align
)
2199 einfo ("%P: warning: changing start of section %s by %u bytes\n",
2200 os
->name
, (unsigned int) (dot
- olddot
));
2207 r
= exp_fold_tree (os
->addr_tree
,
2209 lang_allocating_phase_enum
,
2211 if (r
.valid
== false)
2213 einfo ("%F%S: non constant address expression for section %s\n",
2216 dot
= r
.value
+ r
.section
->bfd_section
->vma
;
2218 /* The section starts here */
2219 /* First, align to what the section needs */
2221 if (os
->section_alignment
!= -1)
2222 dot
= align_power (dot
, os
->section_alignment
);
2224 bfd_set_section_vma (0, os
->bfd_section
, dot
);
2226 os
->bfd_section
->output_offset
= 0;
2229 (void) lang_size_sections (os
->children
.head
, os
, &os
->children
.head
,
2230 os
->fill
, dot
, relax
);
2231 /* Ignore the size of the input sections, use the vma and size to */
2234 after
= ALIGN_N (os
->bfd_section
->vma
+
2235 os
->bfd_section
->_raw_size
,
2236 /* The coercion here is important, see ld.h. */
2237 (bfd_vma
) os
->block_value
);
2239 if (bfd_is_abs_section (os
->bfd_section
))
2240 ASSERT (after
== os
->bfd_section
->vma
);
2242 os
->bfd_section
->_raw_size
= after
- os
->bfd_section
->vma
;
2243 dot
= os
->bfd_section
->vma
+ os
->bfd_section
->_raw_size
;
2244 os
->processed
= true;
2246 /* Replace into region ? */
2247 if (os
->region
!= (lang_memory_region_type
*) NULL
)
2249 os
->region
->current
= dot
;
2250 /* Make sure this isn't silly. */
2251 if (os
->region
->current
< os
->region
->origin
2252 || (os
->region
->current
- os
->region
->origin
2253 > os
->region
->length
))
2255 if (os
->addr_tree
!= (etree_type
*) NULL
)
2257 einfo ("%X%P: address 0x%v of %B section %s is not within region %s\n",
2258 os
->region
->current
,
2259 os
->bfd_section
->owner
,
2260 os
->bfd_section
->name
,
2265 einfo ("%X%P: region %s is full (%B section %s)\n",
2267 os
->bfd_section
->owner
,
2268 os
->bfd_section
->name
);
2270 /* Reset the region pointer. */
2271 os
->region
->current
= os
->region
->origin
;
2277 case lang_constructors_statement_enum
:
2278 dot
= lang_size_sections (constructor_list
.head
,
2279 output_section_statement
,
2280 &s
->wild_statement
.children
.head
,
2285 case lang_data_statement_enum
:
2287 unsigned int size
= 0;
2289 s
->data_statement
.output_vma
= dot
- output_section_statement
->bfd_section
->vma
;
2290 s
->data_statement
.output_section
=
2291 output_section_statement
->bfd_section
;
2293 switch (s
->data_statement
.type
)
2311 output_section_statement
->bfd_section
->_raw_size
+= size
;
2312 /* The output section gets contents, and then we inspect for
2313 any flags set in the input script which override any ALLOC */
2314 output_section_statement
->bfd_section
->flags
|= SEC_HAS_CONTENTS
;
2315 if (!(output_section_statement
->flags
& SEC_NEVER_LOAD
)) {
2316 output_section_statement
->bfd_section
->flags
|= SEC_ALLOC
| SEC_LOAD
;
2321 case lang_reloc_statement_enum
:
2325 s
->reloc_statement
.output_vma
=
2326 dot
- output_section_statement
->bfd_section
->vma
;
2327 s
->reloc_statement
.output_section
=
2328 output_section_statement
->bfd_section
;
2329 size
= bfd_get_reloc_size (s
->reloc_statement
.howto
);
2331 output_section_statement
->bfd_section
->_raw_size
+= size
;
2335 case lang_wild_statement_enum
:
2337 dot
= lang_size_sections (s
->wild_statement
.children
.head
,
2338 output_section_statement
,
2339 &s
->wild_statement
.children
.head
,
2345 case lang_object_symbols_statement_enum
:
2346 link_info
.create_object_symbols_section
=
2347 output_section_statement
->bfd_section
;
2349 case lang_output_statement_enum
:
2350 case lang_target_statement_enum
:
2352 case lang_input_section_enum
:
2356 i
= (*prev
)->input_section
.section
;
2359 if (i
->_cooked_size
== 0)
2360 i
->_cooked_size
= i
->_raw_size
;
2366 if (! bfd_relax_section (i
->owner
, i
, &link_info
, &again
))
2367 einfo ("%P%F: can't relax section: %E\n");
2371 dot
= size_input_section (prev
,
2372 output_section_statement
,
2373 output_section_statement
->fill
,
2377 case lang_input_statement_enum
:
2379 case lang_fill_statement_enum
:
2380 s
->fill_statement
.output_section
= output_section_statement
->bfd_section
;
2382 fill
= s
->fill_statement
.fill
;
2384 case lang_assignment_statement_enum
:
2386 bfd_vma newdot
= dot
;
2388 exp_fold_tree (s
->assignment_statement
.exp
,
2389 output_section_statement
,
2390 lang_allocating_phase_enum
,
2394 if (newdot
!= dot
&& !relax
)
2396 /* The assignment changed dot. Insert a pad. */
2397 if (output_section_statement
== abs_output_section
)
2399 /* If we don't have an output section, then just adjust
2400 the default memory address. */
2401 lang_memory_region_lookup ("*default*")->current
= newdot
;
2405 lang_statement_union_type
*new =
2406 ((lang_statement_union_type
*)
2407 stat_alloc (sizeof (lang_padding_statement_type
)));
2409 /* Link into existing chain */
2410 new->header
.next
= *prev
;
2412 new->header
.type
= lang_padding_statement_enum
;
2413 new->padding_statement
.output_section
=
2414 output_section_statement
->bfd_section
;
2415 new->padding_statement
.output_offset
=
2416 dot
- output_section_statement
->bfd_section
->vma
;
2417 new->padding_statement
.fill
= fill
;
2418 new->padding_statement
.size
= newdot
- dot
;
2419 output_section_statement
->bfd_section
->_raw_size
+=
2420 new->padding_statement
.size
;
2428 case lang_padding_statement_enum
:
2429 /* If we are relaxing, and this is not the first pass, some
2430 padding statements may have been inserted during previous
2431 passes. We may have to move the padding statement to a new
2432 location if dot has a different value at this point in this
2433 pass than it did at this point in the previous pass. */
2434 s
->padding_statement
.output_offset
=
2435 dot
- output_section_statement
->bfd_section
->vma
;
2436 dot
+= s
->padding_statement
.size
;
2437 output_section_statement
->bfd_section
->_raw_size
+=
2438 s
->padding_statement
.size
;
2441 case lang_group_statement_enum
:
2442 dot
= lang_size_sections (s
->group_statement
.children
.head
,
2443 output_section_statement
,
2444 &s
->group_statement
.children
.head
,
2452 /* This can only get here when relaxing is turned on */
2454 case lang_address_statement_enum
:
2457 prev
= &s
->header
.next
;
2463 lang_do_assignments (s
, output_section_statement
, fill
, dot
)
2464 lang_statement_union_type
* s
;
2465 lang_output_section_statement_type
* output_section_statement
;
2469 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
2471 switch (s
->header
.type
)
2473 case lang_constructors_statement_enum
:
2474 dot
= lang_do_assignments (constructor_list
.head
,
2475 output_section_statement
,
2480 case lang_output_section_statement_enum
:
2482 lang_output_section_statement_type
*os
=
2483 &(s
->output_section_statement
);
2485 if (os
->bfd_section
!= NULL
)
2487 dot
= os
->bfd_section
->vma
;
2488 (void) lang_do_assignments (os
->children
.head
, os
,
2490 dot
= os
->bfd_section
->vma
+ os
->bfd_section
->_raw_size
;
2494 /* If nothing has been placed into the output section then
2495 it won't have a bfd_section. */
2496 if (os
->bfd_section
)
2498 os
->bfd_section
->lma
2499 = exp_get_abs_int(os
->load_base
, 0,"load base", lang_final_phase_enum
);
2504 case lang_wild_statement_enum
:
2506 dot
= lang_do_assignments (s
->wild_statement
.children
.head
,
2507 output_section_statement
,
2512 case lang_object_symbols_statement_enum
:
2513 case lang_output_statement_enum
:
2514 case lang_target_statement_enum
:
2516 case lang_common_statement_enum
:
2519 case lang_data_statement_enum
:
2521 etree_value_type value
;
2523 value
= exp_fold_tree (s
->data_statement
.exp
,
2525 lang_final_phase_enum
, dot
, &dot
);
2526 s
->data_statement
.value
= value
.value
;
2527 if (value
.valid
== false)
2528 einfo ("%F%P: invalid data statement\n");
2530 switch (s
->data_statement
.type
)
2548 case lang_reloc_statement_enum
:
2550 etree_value_type value
;
2552 value
= exp_fold_tree (s
->reloc_statement
.addend_exp
,
2554 lang_final_phase_enum
, dot
, &dot
);
2555 s
->reloc_statement
.addend_value
= value
.value
;
2556 if (value
.valid
== false)
2557 einfo ("%F%P: invalid reloc statement\n");
2559 dot
+= bfd_get_reloc_size (s
->reloc_statement
.howto
);
2562 case lang_input_section_enum
:
2564 asection
*in
= s
->input_section
.section
;
2566 if (in
->_cooked_size
!= 0)
2567 dot
+= in
->_cooked_size
;
2569 dot
+= in
->_raw_size
;
2573 case lang_input_statement_enum
:
2575 case lang_fill_statement_enum
:
2576 fill
= s
->fill_statement
.fill
;
2578 case lang_assignment_statement_enum
:
2580 exp_fold_tree (s
->assignment_statement
.exp
,
2581 output_section_statement
,
2582 lang_final_phase_enum
,
2588 case lang_padding_statement_enum
:
2589 dot
+= s
->padding_statement
.size
;
2592 case lang_group_statement_enum
:
2593 dot
= lang_do_assignments (s
->group_statement
.children
.head
,
2594 output_section_statement
,
2602 case lang_address_statement_enum
:
2610 /* Fix any .startof. or .sizeof. symbols. When the assemblers see the
2611 operator .startof. (section_name), it produces an undefined symbol
2612 .startof.section_name. Similarly, when it sees
2613 .sizeof. (section_name), it produces an undefined symbol
2614 .sizeof.section_name. For all the output sections, we look for
2615 such symbols, and set them to the correct value. */
2622 if (link_info
.relocateable
)
2625 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
2627 const char *secname
;
2629 struct bfd_link_hash_entry
*h
;
2631 secname
= bfd_get_section_name (output_bfd
, s
);
2632 buf
= xmalloc (10 + strlen (secname
));
2634 sprintf (buf
, ".startof.%s", secname
);
2635 h
= bfd_link_hash_lookup (link_info
.hash
, buf
, false, false, true);
2636 if (h
!= NULL
&& h
->type
== bfd_link_hash_undefined
)
2638 h
->type
= bfd_link_hash_defined
;
2639 h
->u
.def
.value
= bfd_get_section_vma (output_bfd
, s
);
2640 h
->u
.def
.section
= bfd_abs_section_ptr
;
2643 sprintf (buf
, ".sizeof.%s", secname
);
2644 h
= bfd_link_hash_lookup (link_info
.hash
, buf
, false, false, true);
2645 if (h
!= NULL
&& h
->type
== bfd_link_hash_undefined
)
2647 h
->type
= bfd_link_hash_defined
;
2648 if (s
->_cooked_size
!= 0)
2649 h
->u
.def
.value
= s
->_cooked_size
;
2651 h
->u
.def
.value
= s
->_raw_size
;
2652 h
->u
.def
.section
= bfd_abs_section_ptr
;
2662 struct bfd_link_hash_entry
*h
;
2665 if (link_info
.relocateable
|| link_info
.shared
)
2670 if (entry_symbol
== (char *) NULL
)
2672 /* No entry has been specified. Look for start, but don't warn
2673 if we don't find it. */
2674 entry_symbol
= "start";
2678 h
= bfd_link_hash_lookup (link_info
.hash
, entry_symbol
, false, false, true);
2679 if (h
!= (struct bfd_link_hash_entry
*) NULL
2680 && (h
->type
== bfd_link_hash_defined
2681 || h
->type
== bfd_link_hash_defweak
)
2682 && h
->u
.def
.section
->output_section
!= NULL
)
2686 val
= (h
->u
.def
.value
2687 + bfd_get_section_vma (output_bfd
,
2688 h
->u
.def
.section
->output_section
)
2689 + h
->u
.def
.section
->output_offset
);
2690 if (! bfd_set_start_address (output_bfd
, val
))
2691 einfo ("%P%F:%s: can't set start address\n", entry_symbol
);
2697 /* Can't find the entry symbol. Use the first address in the
2699 ts
= bfd_get_section_by_name (output_bfd
, ".text");
2700 if (ts
!= (asection
*) NULL
)
2703 einfo ("%P: warning: cannot find entry symbol %s; defaulting to %V\n",
2704 entry_symbol
, bfd_get_section_vma (output_bfd
, ts
));
2705 if (! bfd_set_start_address (output_bfd
,
2706 bfd_get_section_vma (output_bfd
, ts
)))
2707 einfo ("%P%F: can't set start address\n");
2712 einfo ("%P: warning: cannot find entry symbol %s; not setting start address\n",
2718 /* This is a small function used when we want to ignore errors from
2722 #ifdef ANSI_PROTOTYPES
2723 ignore_bfd_errors (const char *s
, ...)
2725 ignore_bfd_errors (s
)
2729 /* Don't do anything. */
2732 /* Check that the architecture of all the input files is compatible
2733 with the output file. Also call the backend to let it do any
2734 other checking that is needed. */
2739 lang_statement_union_type
*file
;
2741 CONST bfd_arch_info_type
*compatible
;
2743 for (file
= file_chain
.head
;
2744 file
!= (lang_statement_union_type
*) NULL
;
2745 file
= file
->input_statement
.next
)
2747 input_bfd
= file
->input_statement
.the_bfd
;
2748 compatible
= bfd_arch_get_compatible (input_bfd
,
2750 if (compatible
== NULL
)
2752 if (command_line
.warn_mismatch
)
2753 einfo ("%P: warning: %s architecture of input file `%B' is incompatible with %s output\n",
2754 bfd_printable_name (input_bfd
), input_bfd
,
2755 bfd_printable_name (output_bfd
));
2759 bfd_error_handler_type pfn
= NULL
;
2761 /* If we aren't supposed to warn about mismatched input
2762 files, temporarily set the BFD error handler to a
2763 function which will do nothing. We still want to call
2764 bfd_merge_private_bfd_data, since it may set up
2765 information which is needed in the output file. */
2766 if (! command_line
.warn_mismatch
)
2767 pfn
= bfd_set_error_handler (ignore_bfd_errors
);
2768 if (! bfd_merge_private_bfd_data (input_bfd
, output_bfd
))
2770 if (command_line
.warn_mismatch
)
2771 einfo ("%E%X: failed to merge target specific data of file %B\n",
2774 if (! command_line
.warn_mismatch
)
2775 bfd_set_error_handler (pfn
);
2780 /* Look through all the global common symbols and attach them to the
2781 correct section. The -sort-common command line switch may be used
2782 to roughly sort the entries by size. */
2787 if (link_info
.relocateable
2788 && ! command_line
.force_common_definition
)
2791 if (! config
.sort_common
)
2792 bfd_link_hash_traverse (link_info
.hash
, lang_one_common
, (PTR
) NULL
);
2797 for (power
= 4; power
>= 0; power
--)
2798 bfd_link_hash_traverse (link_info
.hash
, lang_one_common
,
2803 /* Place one common symbol in the correct section. */
2806 lang_one_common (h
, info
)
2807 struct bfd_link_hash_entry
*h
;
2810 unsigned int power_of_two
;
2814 if (h
->type
!= bfd_link_hash_common
)
2818 power_of_two
= h
->u
.c
.p
->alignment_power
;
2820 if (config
.sort_common
2821 && power_of_two
< (unsigned int) *(int *) info
)
2824 section
= h
->u
.c
.p
->section
;
2826 /* Increase the size of the section. */
2827 section
->_raw_size
= ALIGN_N (section
->_raw_size
,
2828 (bfd_size_type
) (1 << power_of_two
));
2830 /* Adjust the alignment if necessary. */
2831 if (power_of_two
> section
->alignment_power
)
2832 section
->alignment_power
= power_of_two
;
2834 /* Change the symbol from common to defined. */
2835 h
->type
= bfd_link_hash_defined
;
2836 h
->u
.def
.section
= section
;
2837 h
->u
.def
.value
= section
->_raw_size
;
2839 /* Increase the size of the section. */
2840 section
->_raw_size
+= size
;
2842 /* Make sure the section is allocated in memory, and make sure that
2843 it is no longer a common section. */
2844 section
->flags
|= SEC_ALLOC
;
2845 section
->flags
&= ~ SEC_IS_COMMON
;
2847 if (config
.map_file
!= NULL
)
2849 static boolean header_printed
;
2854 if (! header_printed
)
2856 minfo ("\nAllocating common symbols\n");
2857 minfo ("Common symbol size file\n\n");
2858 header_printed
= true;
2861 name
= demangle (h
->root
.string
);
2863 len
= strlen (name
);
2878 if (size
<= 0xffffffff)
2879 sprintf (buf
, "%lx", (unsigned long) size
);
2881 sprintf_vma (buf
, size
);
2891 minfo ("%B\n", section
->owner
);
2898 run through the input files and ensure that every input
2899 section has somewhere to go. If one is found without
2900 a destination then create an input request and place it
2901 into the statement tree.
2905 lang_place_orphans ()
2907 lang_input_statement_type
*file
;
2909 for (file
= (lang_input_statement_type
*) file_chain
.head
;
2910 file
!= (lang_input_statement_type
*) NULL
;
2911 file
= (lang_input_statement_type
*) file
->next
)
2915 for (s
= file
->the_bfd
->sections
;
2916 s
!= (asection
*) NULL
;
2919 if (s
->output_section
== (asection
*) NULL
)
2921 /* This section of the file is not attatched, root
2922 around for a sensible place for it to go */
2924 if (file
->just_syms_flag
)
2926 /* We are only retrieving symbol values from this
2927 file. We want the symbols to act as though the
2928 values in the file are absolute. */
2929 s
->output_section
= bfd_abs_section_ptr
;
2930 s
->output_offset
= s
->vma
;
2932 else if (strcmp (s
->name
, "COMMON") == 0)
2934 /* This is a lonely common section which must have
2935 come from an archive. We attach to the section
2936 with the wildcard. */
2937 if (! link_info
.relocateable
2938 || command_line
.force_common_definition
)
2940 if (default_common_section
== NULL
)
2943 /* This message happens when using the
2944 svr3.ifile linker script, so I have
2946 info_msg ("%P: no [COMMON] command, defaulting to .bss\n");
2948 default_common_section
=
2949 lang_output_section_statement_lookup (".bss");
2952 wild_doit (&default_common_section
->children
, s
,
2953 default_common_section
, file
);
2956 else if (ldemul_place_orphan (file
, s
))
2960 lang_output_section_statement_type
*os
=
2961 lang_output_section_statement_lookup (s
->name
);
2963 wild_doit (&os
->children
, s
, os
, file
);
2972 lang_set_flags (ptr
, flags
)
2973 lang_memory_region_type
*ptr
;
2976 flagword
*ptr_flags
= &ptr
->flags
;
2978 ptr
->flags
= ptr
->not_flags
= 0;
2984 ptr_flags
= (ptr_flags
== &ptr
->flags
) ? &ptr
->not_flags
: &ptr
->flags
;
2988 *ptr_flags
|= SEC_ALLOC
;
2992 *ptr_flags
|= SEC_READONLY
;
2996 *ptr_flags
|= SEC_DATA
;
3000 *ptr_flags
|= SEC_CODE
;
3005 *ptr_flags
|= SEC_LOAD
;
3009 einfo ("%P%F: invalid syntax in flags\n");
3016 /* Call a function on each input file. This function will be called
3017 on an archive, but not on the elements. */
3020 lang_for_each_input_file (func
)
3021 void (*func
) PARAMS ((lang_input_statement_type
*));
3023 lang_input_statement_type
*f
;
3025 for (f
= (lang_input_statement_type
*) input_file_chain
.head
;
3027 f
= (lang_input_statement_type
*) f
->next_real_file
)
3031 /* Call a function on each file. The function will be called on all
3032 the elements of an archive which are included in the link, but will
3033 not be called on the archive file itself. */
3036 lang_for_each_file (func
)
3037 void (*func
) PARAMS ((lang_input_statement_type
*));
3039 lang_input_statement_type
*f
;
3041 for (f
= (lang_input_statement_type
*) file_chain
.head
;
3042 f
!= (lang_input_statement_type
*) NULL
;
3043 f
= (lang_input_statement_type
*) f
->next
)
3054 lang_for_each_input_section (func
)
3055 void (*func
) PARAMS ((bfd
* ab
, asection
* as
));
3057 lang_input_statement_type
*f
;
3059 for (f
= (lang_input_statement_type
*) file_chain
.head
;
3060 f
!= (lang_input_statement_type
*) NULL
;
3061 f
= (lang_input_statement_type
*) f
->next
)
3065 for (s
= f
->the_bfd
->sections
;
3066 s
!= (asection
*) NULL
;
3069 func (f
->the_bfd
, s
);
3077 ldlang_add_file (entry
)
3078 lang_input_statement_type
* entry
;
3082 lang_statement_append (&file_chain
,
3083 (lang_statement_union_type
*) entry
,
3086 /* The BFD linker needs to have a list of all input BFDs involved in
3088 ASSERT (entry
->the_bfd
->link_next
== (bfd
*) NULL
);
3089 ASSERT (entry
->the_bfd
!= output_bfd
);
3090 for (pp
= &link_info
.input_bfds
;
3091 *pp
!= (bfd
*) NULL
;
3092 pp
= &(*pp
)->link_next
)
3094 *pp
= entry
->the_bfd
;
3095 entry
->the_bfd
->usrdata
= (PTR
) entry
;
3096 bfd_set_gp_size (entry
->the_bfd
, g_switch_value
);
3098 /* Look through the sections and check for any which should not be
3099 included in the link. We need to do this now, so that we can
3100 notice when the backend linker tries to report multiple
3101 definition errors for symbols which are in sections we aren't
3102 going to link. FIXME: It might be better to entirely ignore
3103 symbols which are defined in sections which are going to be
3104 discarded. This would require modifying the backend linker for
3105 each backend which might set the SEC_LINK_ONCE flag. If we do
3106 this, we should probably handle SEC_EXCLUDE in the same way. */
3108 bfd_map_over_sections (entry
->the_bfd
, section_already_linked
, (PTR
) entry
);
3112 lang_add_output (name
, from_script
)
3116 /* Make -o on command line override OUTPUT in script. */
3117 if (had_output_filename
== false || !from_script
)
3119 output_filename
= name
;
3120 had_output_filename
= true;
3125 static lang_output_section_statement_type
*current_section
;
3137 for (l
= 0; l
< 32; l
++)
3139 if (i
>= (unsigned int) x
)
3148 lang_enter_output_section_statement (output_section_statement_name
,
3149 address_exp
, sectype
, block_value
,
3150 align
, subalign
, ebase
)
3151 const char *output_section_statement_name
;
3152 etree_type
* address_exp
;
3153 enum section_type sectype
;
3154 bfd_vma block_value
;
3156 etree_type
*subalign
;
3159 lang_output_section_statement_type
*os
;
3163 lang_output_section_statement_lookup (output_section_statement_name
);
3167 /* Add this statement to tree */
3168 /* add_statement(lang_output_section_statement_enum,
3169 output_section_statement);*/
3170 /* Make next things chain into subchain of this */
3172 if (os
->addr_tree
==
3173 (etree_type
*) NULL
)
3178 os
->sectype
= sectype
;
3179 if (sectype
!= noload_section
)
3180 os
->flags
= SEC_NO_FLAGS
;
3182 os
->flags
= SEC_NEVER_LOAD
;
3183 os
->block_value
= block_value
? block_value
: 1;
3184 stat_ptr
= &os
->children
;
3186 os
->subsection_alignment
= topower(
3187 exp_get_value_int(subalign
, -1,
3188 "subsection alignment",
3190 os
->section_alignment
= topower(
3191 exp_get_value_int(align
, -1,
3192 "section alignment", 0));
3194 os
->load_base
= ebase
;
3201 lang_output_statement_type
*new =
3202 new_stat (lang_output_statement
, stat_ptr
);
3204 new->name
= output_filename
;
3207 /* Reset the current counters in the regions */
3209 reset_memory_regions ()
3211 lang_memory_region_type
*p
= lang_memory_region_list
;
3213 for (p
= lang_memory_region_list
;
3214 p
!= (lang_memory_region_type
*) NULL
;
3217 p
->old_length
= (bfd_size_type
) (p
->current
- p
->origin
);
3218 p
->current
= p
->origin
;
3225 lang_reasonable_defaults ();
3226 current_target
= default_target
;
3228 lang_for_each_statement (ldlang_open_output
); /* Open the output file */
3230 ldemul_create_output_section_statements ();
3232 /* Add to the hash table all undefineds on the command line */
3233 lang_place_undefineds ();
3235 /* Create a bfd for each input file */
3236 current_target
= default_target
;
3237 open_input_bfds (statement_list
.head
, false);
3239 ldemul_after_open ();
3241 /* Make sure that we're not mixing architectures. We call this
3242 after all the input files have been opened, but before we do any
3243 other processing, so that any operations merge_private_bfd_data
3244 does on the output file will be known during the rest of the
3248 /* Build all sets based on the information gathered from the input
3250 ldctor_build_sets ();
3252 /* Size up the common data */
3255 /* Run through the contours of the script and attach input sections
3256 to the correct output sections
3258 map_input_to_output_sections (statement_list
.head
, (char *) NULL
,
3259 (lang_output_section_statement_type
*) NULL
);
3262 /* Find any sections not attached explicitly and handle them */
3263 lang_place_orphans ();
3265 ldemul_before_allocation ();
3267 /* We must record the program headers before we try to fix the
3268 section positions, since they will affect SIZEOF_HEADERS. */
3269 lang_record_phdrs ();
3271 /* Now run around and relax if we can */
3272 if (command_line
.relax
)
3274 /* First time round is a trial run to get the 'worst case'
3275 addresses of the objects if there was no relaxing. */
3276 lang_size_sections (statement_list
.head
,
3278 &(statement_list
.head
), 0, (bfd_vma
) 0, false);
3280 /* Keep relaxing until bfd_relax_section gives up. */
3283 reset_memory_regions ();
3285 relax_again
= false;
3287 /* Do all the assignments with our current guesses as to
3289 lang_do_assignments (statement_list
.head
,
3291 (fill_type
) 0, (bfd_vma
) 0);
3293 /* Perform another relax pass - this time we know where the
3294 globals are, so can make better guess. */
3295 lang_size_sections (statement_list
.head
,
3297 &(statement_list
.head
), 0, (bfd_vma
) 0, true);
3299 while (relax_again
);
3303 /* Size up the sections. */
3304 lang_size_sections (statement_list
.head
,
3306 &(statement_list
.head
), 0, (bfd_vma
) 0, false);
3309 /* See if anything special should be done now we know how big
3311 ldemul_after_allocation ();
3313 /* Fix any .startof. or .sizeof. symbols. */
3314 lang_set_startof ();
3316 /* Do all the assignments, now that we know the final restingplaces
3317 of all the symbols */
3319 lang_do_assignments (statement_list
.head
,
3321 (fill_type
) 0, (bfd_vma
) 0);
3329 /* EXPORTED TO YACC */
3332 lang_add_wild (section_name
, filename
)
3333 CONST
char *CONST section_name
;
3334 CONST
char *CONST filename
;
3336 lang_wild_statement_type
*new = new_stat (lang_wild_statement
,
3339 if (section_name
!= (char *) NULL
&& strcmp (section_name
, "COMMON") == 0)
3341 placed_commons
= true;
3343 if (filename
!= (char *) NULL
)
3345 lang_has_input_file
= true;
3347 new->section_name
= section_name
;
3348 new->filename
= filename
;
3349 lang_list_init (&new->children
);
3353 lang_section_start (name
, address
)
3355 etree_type
* address
;
3357 lang_address_statement_type
*ad
= new_stat (lang_address_statement
, stat_ptr
);
3359 ad
->section_name
= name
;
3360 ad
->address
= address
;
3363 /* Set the start symbol to NAME. CMDLINE is nonzero if this is called
3364 because of a -e argument on the command line, or zero if this is
3365 called by ENTRY in a linker script. Command line arguments take
3368 /* WINDOWS_NT. When an entry point has been specified, we will also force
3369 this symbol to be defined by calling ldlang_add_undef (equivalent to
3370 having switch -u entry_name on the command line). The reason we do
3371 this is so that the user doesn't have to because they would have to use
3372 the -u switch if they were specifying an entry point other than
3373 _mainCRTStartup. Specifically, if creating a windows application, entry
3374 point _WinMainCRTStartup must be specified.
3375 What I have found for non console applications (entry not _mainCRTStartup)
3376 is that the .obj that contains mainCRTStartup is brought in since it is
3377 the first encountered in libc.lib and it has other symbols in it which will
3378 be pulled in by the link process. To avoid this, adding -u with the entry
3379 point name specified forces the correct .obj to be used. We can avoid
3380 making the user do this by always adding the entry point name as an
3381 undefined symbol. */
3384 lang_add_entry (name
, cmdline
)
3388 if (entry_symbol
== NULL
3390 || ! entry_from_cmdline
)
3392 entry_symbol
= name
;
3393 entry_from_cmdline
= cmdline
;
3396 /* don't do this yet. It seems to work (the executables run), but the
3397 image created is very different from what I was getting before indicating
3398 that something else is being pulled in. When everything else is working,
3399 then try to put this back in to see if it will do the right thing for
3400 other more complicated applications */
3401 ldlang_add_undef (name
);
3406 lang_add_target (name
)
3409 lang_target_statement_type
*new = new_stat (lang_target_statement
,
3425 map_option_f
= true;
3436 lang_fill_statement_type
*new = new_stat (lang_fill_statement
,
3443 lang_add_data (type
, exp
)
3445 union etree_union
*exp
;
3448 lang_data_statement_type
*new = new_stat (lang_data_statement
,
3456 /* Create a new reloc statement. RELOC is the BFD relocation type to
3457 generate. HOWTO is the corresponding howto structure (we could
3458 look this up, but the caller has already done so). SECTION is the
3459 section to generate a reloc against, or NAME is the name of the
3460 symbol to generate a reloc against. Exactly one of SECTION and
3461 NAME must be NULL. ADDEND is an expression for the addend. */
3464 lang_add_reloc (reloc
, howto
, section
, name
, addend
)
3465 bfd_reloc_code_real_type reloc
;
3466 reloc_howto_type
*howto
;
3469 union etree_union
*addend
;
3471 lang_reloc_statement_type
*p
= new_stat (lang_reloc_statement
, stat_ptr
);
3475 p
->section
= section
;
3477 p
->addend_exp
= addend
;
3479 p
->addend_value
= 0;
3480 p
->output_section
= NULL
;
3485 lang_add_assignment (exp
)
3488 lang_assignment_statement_type
*new = new_stat (lang_assignment_statement
,
3495 lang_add_attribute (attribute
)
3496 enum statement_enum attribute
;
3498 new_statement (attribute
, sizeof (lang_statement_union_type
), stat_ptr
);
3505 if (startup_file
!= (char *) NULL
)
3507 einfo ("%P%Fmultiple STARTUP files\n");
3509 first_file
->filename
= name
;
3510 first_file
->local_sym_name
= name
;
3511 first_file
->real
= true;
3513 startup_file
= name
;
3520 lang_float_flag
= maybe
;
3524 lang_leave_output_section_statement (fill
, memspec
, phdrs
)
3526 const char *memspec
;
3527 struct lang_output_section_phdr_list
*phdrs
;
3529 current_section
->fill
= fill
;
3530 current_section
->region
= lang_memory_region_lookup (memspec
);
3531 current_section
->phdrs
= phdrs
;
3532 stat_ptr
= &statement_list
;
3536 Create an absolute symbol with the given name with the value of the
3537 address of first byte of the section named.
3539 If the symbol already exists, then do nothing.
3542 lang_abs_symbol_at_beginning_of (secname
, name
)
3543 const char *secname
;
3546 struct bfd_link_hash_entry
*h
;
3548 h
= bfd_link_hash_lookup (link_info
.hash
, name
, true, true, true);
3549 if (h
== (struct bfd_link_hash_entry
*) NULL
)
3550 einfo ("%P%F: bfd_link_hash_lookup failed: %E\n");
3552 if (h
->type
== bfd_link_hash_new
3553 || h
->type
== bfd_link_hash_undefined
)
3557 h
->type
= bfd_link_hash_defined
;
3559 sec
= bfd_get_section_by_name (output_bfd
, secname
);
3560 if (sec
== (asection
*) NULL
)
3563 h
->u
.def
.value
= bfd_get_section_vma (output_bfd
, sec
);
3565 h
->u
.def
.section
= bfd_abs_section_ptr
;
3570 Create an absolute symbol with the given name with the value of the
3571 address of the first byte after the end of the section named.
3573 If the symbol already exists, then do nothing.
3576 lang_abs_symbol_at_end_of (secname
, name
)
3577 const char *secname
;
3580 struct bfd_link_hash_entry
*h
;
3582 h
= bfd_link_hash_lookup (link_info
.hash
, name
, true, true, true);
3583 if (h
== (struct bfd_link_hash_entry
*) NULL
)
3584 einfo ("%P%F: bfd_link_hash_lookup failed: %E\n");
3586 if (h
->type
== bfd_link_hash_new
3587 || h
->type
== bfd_link_hash_undefined
)
3591 h
->type
= bfd_link_hash_defined
;
3593 sec
= bfd_get_section_by_name (output_bfd
, secname
);
3594 if (sec
== (asection
*) NULL
)
3597 h
->u
.def
.value
= (bfd_get_section_vma (output_bfd
, sec
)
3598 + bfd_section_size (output_bfd
, sec
));
3600 h
->u
.def
.section
= bfd_abs_section_ptr
;
3605 lang_statement_append (list
, element
, field
)
3606 lang_statement_list_type
* list
;
3607 lang_statement_union_type
* element
;
3608 lang_statement_union_type
** field
;
3610 *(list
->tail
) = element
;
3614 /* Set the output format type. -oformat overrides scripts. */
3617 lang_add_output_format (format
, big
, little
, from_script
)
3623 if (output_target
== NULL
|| !from_script
)
3625 if (command_line
.endian
== ENDIAN_BIG
3628 else if (command_line
.endian
== ENDIAN_LITTLE
3632 output_target
= format
;
3636 /* Enter a group. This creates a new lang_group_statement, and sets
3637 stat_ptr to build new statements within the group. */
3642 lang_group_statement_type
*g
;
3644 g
= new_stat (lang_group_statement
, stat_ptr
);
3645 lang_list_init (&g
->children
);
3646 stat_ptr
= &g
->children
;
3649 /* Leave a group. This just resets stat_ptr to start writing to the
3650 regular list of statements again. Note that this will not work if
3651 groups can occur inside anything else which can adjust stat_ptr,
3652 but currently they can't. */
3657 stat_ptr
= &statement_list
;
3660 /* Add a new program header. This is called for each entry in a PHDRS
3661 command in a linker script. */
3664 lang_new_phdr (name
, type
, filehdr
, phdrs
, at
, flags
)
3672 struct lang_phdr
*n
, **pp
;
3674 n
= (struct lang_phdr
*) stat_alloc (sizeof (struct lang_phdr
));
3677 n
->type
= exp_get_value_int (type
, 0, "program header type",
3678 lang_final_phase_enum
);
3679 n
->filehdr
= filehdr
;
3684 for (pp
= &lang_phdr_list
; *pp
!= NULL
; pp
= &(*pp
)->next
)
3689 /* Record the program header information in the output BFD. FIXME: We
3690 should not be calling an ELF specific function here. */
3693 lang_record_phdrs ()
3697 struct lang_output_section_phdr_list
*last
;
3698 struct lang_phdr
*l
;
3699 lang_statement_union_type
*u
;
3702 secs
= (asection
**) xmalloc (alc
* sizeof (asection
*));
3704 for (l
= lang_phdr_list
; l
!= NULL
; l
= l
->next
)
3711 for (u
= lang_output_section_statement
.head
;
3713 u
= u
->output_section_statement
.next
)
3715 lang_output_section_statement_type
*os
;
3716 struct lang_output_section_phdr_list
*pl
;
3718 os
= &u
->output_section_statement
;
3725 if (os
->sectype
== noload_section
3726 || os
->bfd_section
== NULL
3727 || (os
->bfd_section
->flags
& SEC_ALLOC
) == 0)
3732 if (os
->bfd_section
== NULL
)
3735 for (; pl
!= NULL
; pl
= pl
->next
)
3737 if (strcmp (pl
->name
, l
->name
) == 0)
3742 secs
= ((asection
**)
3743 xrealloc (secs
, alc
* sizeof (asection
*)));
3745 secs
[c
] = os
->bfd_section
;
3752 if (l
->flags
== NULL
)
3755 flags
= exp_get_vma (l
->flags
, 0, "phdr flags",
3756 lang_final_phase_enum
);
3761 at
= exp_get_vma (l
->at
, 0, "phdr load address",
3762 lang_final_phase_enum
);
3764 if (! bfd_record_phdr (output_bfd
, l
->type
,
3765 l
->flags
== NULL
? false : true,
3767 l
->at
== NULL
? false : true,
3768 at
, l
->filehdr
, l
->phdrs
, c
, secs
))
3769 einfo ("%F%P: bfd_record_phdr failed: %E\n");
3774 /* Make sure all the phdr assignments succeeded. */
3775 for (u
= lang_output_section_statement
.head
;
3777 u
= u
->output_section_statement
.next
)
3779 struct lang_output_section_phdr_list
*pl
;
3781 if (u
->output_section_statement
.bfd_section
== NULL
)
3784 for (pl
= u
->output_section_statement
.phdrs
;
3787 if (! pl
->used
&& strcmp (pl
->name
, "NONE") != 0)
3788 einfo ("%X%P: section `%s' assigned to non-existent phdr `%s'\n",
3789 u
->output_section_statement
.name
, pl
->name
);
3793 /* Record a list of sections which may not be cross referenced. */
3796 lang_add_nocrossref (l
)
3797 struct lang_nocrossref
*l
;
3799 struct lang_nocrossrefs
*n
;
3801 n
= (struct lang_nocrossrefs
*) xmalloc (sizeof *n
);
3802 n
->next
= nocrossref_list
;
3804 nocrossref_list
= n
;
3806 /* Set notice_all so that we get informed about all symbols. */
3807 link_info
.notice_all
= true;
3810 /* Overlay handling. We handle overlays with some static variables. */
3812 /* The overlay virtual address. */
3813 static etree_type
*overlay_vma
;
3815 /* The overlay load address. */
3816 static etree_type
*overlay_lma
;
3818 /* Whether nocrossrefs is set for this overlay. */
3819 static int overlay_nocrossrefs
;
3821 /* An expression for the maximum section size seen so far. */
3822 static etree_type
*overlay_max
;
3824 /* A list of all the sections in this overlay. */
3828 struct overlay_list
*next
;
3829 lang_output_section_statement_type
*os
;
3832 static struct overlay_list
*overlay_list
;
3834 /* Start handling an overlay. */
3837 lang_enter_overlay (vma_expr
, lma_expr
, nocrossrefs
)
3838 etree_type
*vma_expr
;
3839 etree_type
*lma_expr
;
3842 /* The grammar should prevent nested overlays from occurring. */
3843 ASSERT (overlay_vma
== NULL
3844 && overlay_lma
== NULL
3845 && overlay_list
== NULL
3846 && overlay_max
== NULL
);
3848 overlay_vma
= vma_expr
;
3849 overlay_lma
= lma_expr
;
3850 overlay_nocrossrefs
= nocrossrefs
;
3853 /* Start a section in an overlay. We handle this by calling
3854 lang_enter_output_section_statement with the correct VMA and LMA. */
3857 lang_enter_overlay_section (name
)
3860 struct overlay_list
*n
;
3863 lang_enter_output_section_statement (name
, overlay_vma
, normal_section
,
3864 0, 0, 0, overlay_lma
);
3866 /* If this is the first section, then base the VMA and LMA of future
3867 sections on this one. This will work correctly even if `.' is
3868 used in the addresses. */
3869 if (overlay_list
== NULL
)
3871 overlay_vma
= exp_nameop (ADDR
, name
);
3872 overlay_lma
= exp_nameop (LOADADDR
, name
);
3875 /* Remember the section. */
3876 n
= (struct overlay_list
*) xmalloc (sizeof *n
);
3877 n
->os
= current_section
;
3878 n
->next
= overlay_list
;
3881 size
= exp_nameop (SIZEOF
, name
);
3883 /* Adjust the LMA for the next section. */
3884 overlay_lma
= exp_binop ('+', overlay_lma
, size
);
3886 /* Arrange to work out the maximum section end address. */
3887 if (overlay_max
== NULL
)
3890 overlay_max
= exp_binop (MAX
, overlay_max
, size
);
3893 /* Finish a section in an overlay. There isn't any special to do
3897 lang_leave_overlay_section (fill
, phdrs
)
3899 struct lang_output_section_phdr_list
*phdrs
;
3906 name
= current_section
->name
;
3908 lang_leave_output_section_statement (fill
, "*default*", phdrs
);
3910 /* Define the magic symbols. */
3912 clean
= xmalloc (strlen (name
) + 1);
3914 for (s1
= name
; *s1
!= '\0'; s1
++)
3915 if (isalnum ((unsigned char) *s1
) || *s1
== '_')
3919 buf
= xmalloc (strlen (clean
) + sizeof "__load_start_");
3920 sprintf (buf
, "__load_start_%s", clean
);
3921 lang_add_assignment (exp_assop ('=', buf
,
3922 exp_nameop (LOADADDR
, name
)));
3924 buf
= xmalloc (strlen (clean
) + sizeof "__load_stop_");
3925 sprintf (buf
, "__load_stop_%s", clean
);
3926 lang_add_assignment (exp_assop ('=', buf
,
3928 exp_nameop (LOADADDR
, name
),
3929 exp_nameop (SIZEOF
, name
))));
3934 /* Finish an overlay. If there are any overlay wide settings, this
3935 looks through all the sections in the overlay and sets them. */
3938 lang_leave_overlay (fill
, memspec
, phdrs
)
3940 const char *memspec
;
3941 struct lang_output_section_phdr_list
*phdrs
;
3943 lang_memory_region_type
*region
;
3944 struct overlay_list
*l
;
3945 struct lang_nocrossref
*nocrossref
;
3947 if (memspec
== NULL
)
3950 region
= lang_memory_region_lookup (memspec
);
3957 struct overlay_list
*next
;
3959 if (fill
!= 0 && l
->os
->fill
== 0)
3961 if (region
!= NULL
&& l
->os
->region
== NULL
)
3962 l
->os
->region
= region
;
3963 if (phdrs
!= NULL
&& l
->os
->phdrs
== NULL
)
3964 l
->os
->phdrs
= phdrs
;
3966 if (overlay_nocrossrefs
)
3968 struct lang_nocrossref
*nc
;
3970 nc
= (struct lang_nocrossref
*) xmalloc (sizeof *nc
);
3971 nc
->name
= l
->os
->name
;
3972 nc
->next
= nocrossref
;
3981 if (nocrossref
!= NULL
)
3982 lang_add_nocrossref (nocrossref
);
3984 /* Update . for the end of the overlay. */
3985 lang_add_assignment (exp_assop ('=', ".",
3986 exp_binop ('+', overlay_vma
, overlay_max
)));
3990 overlay_nocrossrefs
= 0;
3991 overlay_list
= NULL
;
3995 /* Version handling. This is only useful for ELF. */
3997 /* This global variable holds the version tree that we build. */
3999 struct bfd_elf_version_tree
*lang_elf_version_info
;
4001 /* This is called for each variable name or match expression. */
4003 struct bfd_elf_version_expr
*
4004 lang_new_vers_regex (orig
, new)
4005 struct bfd_elf_version_expr
*orig
;
4008 struct bfd_elf_version_expr
*ret
;
4010 ret
= (struct bfd_elf_version_expr
*) xmalloc (sizeof *ret
);
4016 /* This is called for each set of variable names and match
4019 struct bfd_elf_version_tree
*
4020 lang_new_vers_node (globals
, locals
)
4021 struct bfd_elf_version_expr
*globals
;
4022 struct bfd_elf_version_expr
*locals
;
4024 struct bfd_elf_version_tree
*ret
;
4026 ret
= (struct bfd_elf_version_tree
*) xmalloc (sizeof *ret
);
4030 ret
->globals
= globals
;
4031 ret
->locals
= locals
;
4033 ret
->name_indx
= (unsigned int) -1;
4038 /* This static variable keeps track of version indices. */
4040 static int version_index
;
4042 /* This is called when we know the name and dependencies of the
4046 lang_register_vers_node (name
, version
, deps
)
4048 struct bfd_elf_version_tree
*version
;
4049 struct bfd_elf_version_deps
*deps
;
4051 struct bfd_elf_version_tree
*t
, **pp
;
4052 struct bfd_elf_version_expr
*e1
;
4054 /* Make sure this node has a unique name. */
4055 for (t
= lang_elf_version_info
; t
!= NULL
; t
= t
->next
)
4056 if (strcmp (t
->name
, name
) == 0)
4057 einfo ("%X%P: duplicate version tag `%s'\n", name
);
4059 /* Check the global and local match names, and make sure there
4060 aren't any duplicates. */
4062 for (e1
= version
->globals
; e1
!= NULL
; e1
= e1
->next
)
4064 for (t
= lang_elf_version_info
; t
!= NULL
; t
= t
->next
)
4066 struct bfd_elf_version_expr
*e2
;
4068 for (e2
= t
->locals
; e2
!= NULL
; e2
= e2
->next
)
4069 if (strcmp (e1
->match
, e2
->match
) == 0)
4070 einfo ("%X%P: duplicate expression `%s' in version information\n",
4075 for (e1
= version
->locals
; e1
!= NULL
; e1
= e1
->next
)
4077 for (t
= lang_elf_version_info
; t
!= NULL
; t
= t
->next
)
4079 struct bfd_elf_version_expr
*e2
;
4081 for (e2
= t
->globals
; e2
!= NULL
; e2
= e2
->next
)
4082 if (strcmp (e1
->match
, e2
->match
) == 0)
4083 einfo ("%X%P: duplicate expression `%s' in version information\n",
4088 version
->deps
= deps
;
4089 version
->name
= name
;
4091 version
->vernum
= version_index
;
4093 for (pp
= &lang_elf_version_info
; *pp
!= NULL
; pp
= &(*pp
)->next
)
4098 /* This is called when we see a version dependency. */
4100 struct bfd_elf_version_deps
*
4101 lang_add_vers_depend (list
, name
)
4102 struct bfd_elf_version_deps
*list
;
4105 struct bfd_elf_version_deps
*ret
;
4106 struct bfd_elf_version_tree
*t
;
4108 ret
= (struct bfd_elf_version_deps
*) xmalloc (sizeof *ret
);
4111 for (t
= lang_elf_version_info
; t
!= NULL
; t
= t
->next
)
4113 if (strcmp (t
->name
, name
) == 0)
4115 ret
->version_needed
= t
;
4120 einfo ("%X%P: unable to find version dependency `%s'\n", name
);