1 /* Linker command language support.
2 Copyright (C) 1991, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
4 This file is part of GLD, the Gnu Linker.
6 GLD is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
11 GLD is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GLD; see the file COPYING. If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include "libiberty.h"
42 static lang_statement_union_type
*new_statement
PARAMS ((enum statement_enum
,
44 lang_statement_list_type
*));
48 static struct obstack stat_obstack
;
50 #define obstack_chunk_alloc xmalloc
51 #define obstack_chunk_free free
52 static CONST
char *startup_file
;
53 static lang_statement_list_type input_file_chain
;
54 static boolean placed_commons
= false;
55 static lang_output_section_statement_type
*default_common_section
;
56 static boolean map_option_f
;
57 static bfd_vma print_dot
;
58 static lang_input_statement_type
*first_file
;
59 static lang_statement_list_type lang_output_section_statement
;
60 static CONST
char *current_target
;
61 static CONST
char *output_target
;
62 static lang_statement_list_type statement_list
;
63 static struct lang_phdr
*lang_phdr_list
;
65 static void lang_for_each_statement_worker
66 PARAMS ((void (*func
) (lang_statement_union_type
*),
67 lang_statement_union_type
*s
));
68 static lang_input_statement_type
*new_afile
69 PARAMS ((const char *name
, lang_input_file_enum_type file_type
,
70 const char *target
, boolean add_to_list
));
71 static void init_os
PARAMS ((lang_output_section_statement_type
*s
));
72 static void exp_init_os
PARAMS ((etree_type
*));
73 static void section_already_linked
PARAMS ((bfd
*, asection
*, PTR
));
74 static boolean wildcardp
PARAMS ((const char *));
75 static void wild_section
PARAMS ((lang_wild_statement_type
*ptr
,
77 lang_input_statement_type
*file
,
78 lang_output_section_statement_type
*output
));
79 static lang_input_statement_type
*lookup_name
PARAMS ((const char *name
));
80 static void load_symbols
PARAMS ((lang_input_statement_type
*entry
,
81 lang_statement_list_type
*));
82 static void wild_file
PARAMS ((lang_wild_statement_type
*, const char *,
83 lang_input_statement_type
*,
84 lang_output_section_statement_type
*));
85 static void wild
PARAMS ((lang_wild_statement_type
*s
,
86 const char *section
, const char *file
,
88 lang_output_section_statement_type
*output
));
89 static bfd
*open_output
PARAMS ((const char *name
));
90 static void ldlang_open_output
PARAMS ((lang_statement_union_type
*statement
));
91 static void open_input_bfds
92 PARAMS ((lang_statement_union_type
*statement
, boolean
));
93 static void lang_reasonable_defaults
PARAMS ((void));
94 static void lang_place_undefineds
PARAMS ((void));
95 static void map_input_to_output_sections
96 PARAMS ((lang_statement_union_type
*s
,
98 lang_output_section_statement_type
*output_section_statement
));
99 static void print_output_section_statement
100 PARAMS ((lang_output_section_statement_type
*output_section_statement
));
101 static void print_assignment
102 PARAMS ((lang_assignment_statement_type
*assignment
,
103 lang_output_section_statement_type
*output_section
));
104 static void print_input_statement
PARAMS ((lang_input_statement_type
*statm
));
105 static boolean print_one_symbol
PARAMS ((struct bfd_link_hash_entry
*, PTR
));
106 static void print_input_section
PARAMS ((lang_input_section_type
*in
));
107 static void print_fill_statement
PARAMS ((lang_fill_statement_type
*fill
));
108 static void print_data_statement
PARAMS ((lang_data_statement_type
*data
));
109 static void print_address_statement
PARAMS ((lang_address_statement_type
*));
110 static void print_reloc_statement
PARAMS ((lang_reloc_statement_type
*reloc
));
111 static void print_padding_statement
PARAMS ((lang_padding_statement_type
*s
));
112 static void print_wild_statement
113 PARAMS ((lang_wild_statement_type
*w
,
114 lang_output_section_statement_type
*os
));
115 static void print_group
116 PARAMS ((lang_group_statement_type
*, lang_output_section_statement_type
*));
117 static void print_statement
PARAMS ((lang_statement_union_type
*s
,
118 lang_output_section_statement_type
*os
));
119 static void print_statement_list
PARAMS ((lang_statement_union_type
*s
,
120 lang_output_section_statement_type
*os
));
121 static void print_statements
PARAMS ((void));
122 static bfd_vma insert_pad
PARAMS ((lang_statement_union_type
**this_ptr
,
123 fill_type fill
, unsigned int power
,
124 asection
*output_section_statement
,
126 static bfd_vma size_input_section
127 PARAMS ((lang_statement_union_type
**this_ptr
,
128 lang_output_section_statement_type
*output_section_statement
,
129 fill_type fill
, bfd_vma dot
, boolean relax
));
130 static void lang_finish
PARAMS ((void));
131 static void ignore_bfd_errors
PARAMS ((const char *, ...));
132 static void lang_check
PARAMS ((void));
133 static void lang_common
PARAMS ((void));
134 static boolean lang_one_common
PARAMS ((struct bfd_link_hash_entry
*, PTR
));
135 static void lang_place_orphans
PARAMS ((void));
136 static int topower
PARAMS ((int));
137 static void lang_set_startof
PARAMS ((void));
138 static void reset_memory_regions
PARAMS ((void));
139 static void lang_record_phdrs
PARAMS ((void));
142 lang_output_section_statement_type
*abs_output_section
;
143 lang_statement_list_type
*stat_ptr
= &statement_list
;
144 lang_statement_list_type file_chain
= { 0 };
145 const char *entry_symbol
= NULL
;
146 boolean entry_from_cmdline
;
147 boolean lang_has_input_file
= false;
148 boolean had_output_filename
= false;
149 boolean lang_float_flag
= false;
150 boolean delete_output_file_on_failure
= false;
151 struct lang_nocrossrefs
*nocrossref_list
;
153 etree_type
*base
; /* Relocation base - or null */
156 #if defined(__STDC__) || defined(ALMOST_STDC)
157 #define cat(a,b) a##b
159 #define cat(a,b) a/**/b
162 #define new_stat(x,y) (cat(x,_type)*) new_statement(cat(x,_enum), sizeof(cat(x,_type)),y)
164 #define outside_section_address(q) ( (q)->output_offset + (q)->output_section->vma)
166 #define outside_symbol_address(q) ((q)->value + outside_section_address(q->section))
168 #define SECTION_NAME_MAP_LENGTH (16)
174 return obstack_alloc (&stat_obstack
, size
);
177 /*----------------------------------------------------------------------
178 lang_for_each_statement walks the parse tree and calls the provided
179 function for each node
183 lang_for_each_statement_worker (func
, s
)
184 void (*func
) PARAMS ((lang_statement_union_type
*));
185 lang_statement_union_type
*s
;
187 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
191 switch (s
->header
.type
)
193 case lang_constructors_statement_enum
:
194 lang_for_each_statement_worker (func
, constructor_list
.head
);
196 case lang_output_section_statement_enum
:
197 lang_for_each_statement_worker
199 s
->output_section_statement
.children
.head
);
201 case lang_wild_statement_enum
:
202 lang_for_each_statement_worker
204 s
->wild_statement
.children
.head
);
206 case lang_group_statement_enum
:
207 lang_for_each_statement_worker (func
,
208 s
->group_statement
.children
.head
);
210 case lang_data_statement_enum
:
211 case lang_reloc_statement_enum
:
212 case lang_object_symbols_statement_enum
:
213 case lang_output_statement_enum
:
214 case lang_target_statement_enum
:
215 case lang_input_section_enum
:
216 case lang_input_statement_enum
:
217 case lang_assignment_statement_enum
:
218 case lang_padding_statement_enum
:
219 case lang_address_statement_enum
:
220 case lang_fill_statement_enum
:
230 lang_for_each_statement (func
)
231 void (*func
) PARAMS ((lang_statement_union_type
*));
233 lang_for_each_statement_worker (func
,
234 statement_list
.head
);
237 /*----------------------------------------------------------------------*/
239 lang_list_init (list
)
240 lang_statement_list_type
*list
;
242 list
->head
= (lang_statement_union_type
*) NULL
;
243 list
->tail
= &list
->head
;
246 /*----------------------------------------------------------------------
248 build a new statement node for the parse tree
253 lang_statement_union_type
*
254 new_statement (type
, size
, list
)
255 enum statement_enum type
;
257 lang_statement_list_type
* list
;
259 lang_statement_union_type
*new = (lang_statement_union_type
*)
262 new->header
.type
= type
;
263 new->header
.next
= (lang_statement_union_type
*) NULL
;
264 lang_statement_append (list
, new, &new->header
.next
);
269 Build a new input file node for the language. There are several ways
270 in which we treat an input file, eg, we only look at symbols, or
271 prefix it with a -l etc.
273 We can be supplied with requests for input files more than once;
274 they may, for example be split over serveral lines like foo.o(.text)
275 foo.o(.data) etc, so when asked for a file we check that we havn't
276 got it already so we don't duplicate the bfd.
279 static lang_input_statement_type
*
280 new_afile (name
, file_type
, target
, add_to_list
)
282 lang_input_file_enum_type file_type
;
286 lang_input_statement_type
*p
;
289 p
= new_stat (lang_input_statement
, stat_ptr
);
292 p
= ((lang_input_statement_type
*)
293 stat_alloc (sizeof (lang_input_statement_type
)));
294 p
->header
.next
= NULL
;
297 lang_has_input_file
= true;
301 case lang_input_file_is_symbols_only_enum
:
303 p
->is_archive
= false;
305 p
->local_sym_name
= name
;
306 p
->just_syms_flag
= true;
307 p
->search_dirs_flag
= false;
309 case lang_input_file_is_fake_enum
:
311 p
->is_archive
= false;
313 p
->local_sym_name
= name
;
314 p
->just_syms_flag
= false;
315 p
->search_dirs_flag
= false;
317 case lang_input_file_is_l_enum
:
318 p
->is_archive
= true;
321 p
->local_sym_name
= concat ("-l", name
, (const char *) NULL
);
322 p
->just_syms_flag
= false;
323 p
->search_dirs_flag
= true;
325 case lang_input_file_is_marker_enum
:
327 p
->is_archive
= false;
329 p
->local_sym_name
= name
;
330 p
->just_syms_flag
= false;
331 p
->search_dirs_flag
= true;
333 case lang_input_file_is_search_file_enum
:
335 p
->is_archive
= false;
337 p
->local_sym_name
= name
;
338 p
->just_syms_flag
= false;
339 p
->search_dirs_flag
= true;
341 case lang_input_file_is_file_enum
:
343 p
->is_archive
= false;
345 p
->local_sym_name
= name
;
346 p
->just_syms_flag
= false;
347 p
->search_dirs_flag
= false;
352 p
->the_bfd
= (bfd
*) NULL
;
353 p
->asymbols
= (asymbol
**) NULL
;
354 p
->next_real_file
= (lang_statement_union_type
*) NULL
;
355 p
->next
= (lang_statement_union_type
*) NULL
;
357 p
->dynamic
= config
.dynamic_link
;
358 p
->whole_archive
= whole_archive
;
360 lang_statement_append (&input_file_chain
,
361 (lang_statement_union_type
*) p
,
366 lang_input_statement_type
*
367 lang_add_input_file (name
, file_type
, target
)
369 lang_input_file_enum_type file_type
;
372 lang_has_input_file
= true;
373 return new_afile (name
, file_type
, target
, true);
376 /* Build enough state so that the parser can build its tree */
380 obstack_begin (&stat_obstack
, 1000);
382 stat_ptr
= &statement_list
;
384 lang_list_init (stat_ptr
);
386 lang_list_init (&input_file_chain
);
387 lang_list_init (&lang_output_section_statement
);
388 lang_list_init (&file_chain
);
389 first_file
= lang_add_input_file ((char *) NULL
,
390 lang_input_file_is_marker_enum
,
392 abs_output_section
= lang_output_section_statement_lookup (BFD_ABS_SECTION_NAME
);
394 abs_output_section
->bfd_section
= bfd_abs_section_ptr
;
398 /*----------------------------------------------------------------------
399 A region is an area of memory declared with the
400 MEMORY { name:org=exp, len=exp ... }
403 We maintain a list of all the regions here
405 If no regions are specified in the script, then the default is used
406 which is created when looked up to be the entire data space
409 static lang_memory_region_type
*lang_memory_region_list
;
410 static lang_memory_region_type
**lang_memory_region_list_tail
= &lang_memory_region_list
;
412 lang_memory_region_type
*
413 lang_memory_region_lookup (name
)
414 CONST
char *CONST name
;
416 lang_memory_region_type
*p
;
418 for (p
= lang_memory_region_list
;
419 p
!= (lang_memory_region_type
*) NULL
;
422 if (strcmp (p
->name
, name
) == 0)
429 /* This code used to always use the first region in the list as the
430 default region. I changed it to instead use a region
431 encompassing all of memory as the default region. This permits
432 NOLOAD sections to work reasonably without requiring a region.
433 People should specify what region they mean, if they really want
435 if (strcmp (name
, "*default*") == 0)
437 if (lang_memory_region_list
!= (lang_memory_region_type
*) NULL
)
439 return lang_memory_region_list
;
445 lang_memory_region_type
*new =
446 (lang_memory_region_type
*) stat_alloc (sizeof (lang_memory_region_type
));
448 new->name
= buystring (name
);
449 new->next
= (lang_memory_region_type
*) NULL
;
451 *lang_memory_region_list_tail
= new;
452 lang_memory_region_list_tail
= &new->next
;
456 new->length
= ~(bfd_size_type
)0;
458 new->had_full_message
= false;
465 lang_memory_region_type
*
466 lang_memory_default (section
)
469 lang_memory_region_type
*p
;
471 flagword sec_flags
= section
->flags
;
473 /* Override SEC_DATA to mean a writable section. */
474 if (sec_flags
& (SEC_ALLOC
| SEC_READONLY
| SEC_CODE
) == SEC_ALLOC
)
475 sec_flags
|= SEC_DATA
;
477 for (p
= lang_memory_region_list
;
478 p
!= (lang_memory_region_type
*) NULL
;
481 if ((p
->flags
& sec_flags
) != 0
482 && (p
->not_flags
& sec_flags
) == 0)
487 return lang_memory_region_lookup ("*default*");
490 lang_output_section_statement_type
*
491 lang_output_section_find (name
)
492 CONST
char *CONST name
;
494 lang_statement_union_type
*u
;
495 lang_output_section_statement_type
*lookup
;
497 for (u
= lang_output_section_statement
.head
;
498 u
!= (lang_statement_union_type
*) NULL
;
501 lookup
= &u
->output_section_statement
;
502 if (strcmp (name
, lookup
->name
) == 0)
507 return (lang_output_section_statement_type
*) NULL
;
510 lang_output_section_statement_type
*
511 lang_output_section_statement_lookup (name
)
512 CONST
char *CONST name
;
514 lang_output_section_statement_type
*lookup
;
516 lookup
= lang_output_section_find (name
);
517 if (lookup
== (lang_output_section_statement_type
*) NULL
)
520 lookup
= (lang_output_section_statement_type
*)
521 new_stat (lang_output_section_statement
, stat_ptr
);
522 lookup
->region
= (lang_memory_region_type
*) NULL
;
524 lookup
->block_value
= 1;
527 lookup
->next
= (lang_statement_union_type
*) NULL
;
528 lookup
->bfd_section
= (asection
*) NULL
;
529 lookup
->processed
= false;
530 lookup
->sectype
= normal_section
;
531 lookup
->addr_tree
= (etree_type
*) NULL
;
532 lang_list_init (&lookup
->children
);
534 lookup
->memspec
= (CONST
char *) NULL
;
536 lookup
->subsection_alignment
= -1;
537 lookup
->section_alignment
= -1;
538 lookup
->load_base
= (union etree_union
*) NULL
;
539 lookup
->phdrs
= NULL
;
541 lang_statement_append (&lang_output_section_statement
,
542 (lang_statement_union_type
*) lookup
,
549 lang_map_flags (flag
)
552 if (flag
& SEC_ALLOC
)
558 if (flag
& SEC_READONLY
)
571 lang_memory_region_type
*m
;
573 minfo ("\nMemory Configuration\n\n");
574 fprintf (config
.map_file
, "%-16s %-18s %-18s %s\n",
575 "Name", "Origin", "Length", "Attributes");
577 for (m
= lang_memory_region_list
;
578 m
!= (lang_memory_region_type
*) NULL
;
584 fprintf (config
.map_file
, "%-16s ", m
->name
);
586 sprintf_vma (buf
, m
->origin
);
587 minfo ("0x%s ", buf
);
595 minfo ("0x%V", m
->length
);
596 if (m
->flags
|| m
->not_flags
)
604 lang_map_flags (m
->flags
);
610 lang_map_flags (m
->not_flags
);
617 fprintf (config
.map_file
, "\nLinker script and memory map\n\n");
622 /* Initialize an output section. */
626 lang_output_section_statement_type
*s
;
628 section_userdata_type
*new;
630 if (s
->bfd_section
!= NULL
)
633 if (strcmp (s
->name
, DISCARD_SECTION_NAME
) == 0)
634 einfo ("%P%F: Illegal use of `%s' section", DISCARD_SECTION_NAME
);
636 new = ((section_userdata_type
*)
637 stat_alloc (sizeof (section_userdata_type
)));
639 s
->bfd_section
= bfd_get_section_by_name (output_bfd
, s
->name
);
640 if (s
->bfd_section
== (asection
*) NULL
)
641 s
->bfd_section
= bfd_make_section (output_bfd
, s
->name
);
642 if (s
->bfd_section
== (asection
*) NULL
)
644 einfo ("%P%F: output format %s cannot represent section called %s\n",
645 output_bfd
->xvec
->name
, s
->name
);
647 s
->bfd_section
->output_section
= s
->bfd_section
;
649 /* We initialize an output sections output offset to minus its own */
650 /* vma to allow us to output a section through itself */
651 s
->bfd_section
->output_offset
= 0;
652 get_userdata (s
->bfd_section
) = (PTR
) new;
654 /* If there is a base address, make sure that any sections it might
655 mention are initialized. */
656 if (s
->addr_tree
!= NULL
)
657 exp_init_os (s
->addr_tree
);
660 /* Make sure that all output sections mentioned in an expression are
667 switch (exp
->type
.node_class
)
670 exp_init_os (exp
->assign
.src
);
674 exp_init_os (exp
->binary
.lhs
);
675 exp_init_os (exp
->binary
.rhs
);
679 exp_init_os (exp
->trinary
.cond
);
680 exp_init_os (exp
->trinary
.lhs
);
681 exp_init_os (exp
->trinary
.rhs
);
685 exp_init_os (exp
->unary
.child
);
689 switch (exp
->type
.node_code
)
695 lang_output_section_statement_type
*os
;
697 os
= lang_output_section_find (exp
->name
.name
);
698 if (os
!= NULL
&& os
->bfd_section
== NULL
)
709 /* Sections marked with the SEC_LINK_ONCE flag should only be linked
710 once into the output. This routine checks each sections, and
711 arranges to discard it if a section of the same name has already
712 been linked. This code assumes that all relevant sections have the
713 SEC_LINK_ONCE flag set; that is, it does not depend solely upon the
714 section name. This is called via bfd_map_over_sections. */
718 section_already_linked (abfd
, sec
, data
)
723 lang_input_statement_type
*entry
= (lang_input_statement_type
*) data
;
726 struct sec_link_once
*next
;
729 static struct sec_link_once
*sec_link_once_list
;
732 struct sec_link_once
*l
;
734 /* If we are only reading symbols from this object, then we want to
735 discard all sections. */
736 if (entry
->just_syms_flag
)
738 sec
->output_section
= bfd_abs_section_ptr
;
739 sec
->output_offset
= sec
->vma
;
743 flags
= bfd_get_section_flags (abfd
, sec
);
745 if ((flags
& SEC_LINK_ONCE
) == 0)
748 name
= bfd_get_section_name (abfd
, sec
);
750 for (l
= sec_link_once_list
; l
!= NULL
; l
= l
->next
)
752 if (strcmp (name
, bfd_get_section_name (l
->sec
->owner
, l
->sec
)) == 0)
754 /* The section has already been linked. See if we should
756 switch (flags
& SEC_LINK_DUPLICATES
)
761 case SEC_LINK_DUPLICATES_DISCARD
:
764 case SEC_LINK_DUPLICATES_ONE_ONLY
:
765 einfo ("%P: %B: warning: ignoring duplicate section `%s'\n",
769 case SEC_LINK_DUPLICATES_SAME_CONTENTS
:
770 /* FIXME: We should really dig out the contents of both
771 sections and memcmp them. The COFF/PE spec says that
772 the Microsoft linker does not implement this
773 correctly, so I'm not going to bother doing it
776 case SEC_LINK_DUPLICATES_SAME_SIZE
:
777 if (bfd_section_size (abfd
, sec
)
778 != bfd_section_size (l
->sec
->owner
, l
->sec
))
779 einfo ("%P: %B: warning: duplicate section `%s' has different size\n",
784 /* Set the output_section field so that wild_doit does not
785 create a lang_input_section structure for this section. */
786 sec
->output_section
= bfd_abs_section_ptr
;
792 /* This is the first section with this name. Record it. */
794 l
= (struct sec_link_once
*) xmalloc (sizeof *l
);
796 l
->next
= sec_link_once_list
;
797 sec_link_once_list
= l
;
800 /* The wild routines.
802 These expand statements like *(.text) and foo.o to a list of
803 explicit actions, like foo.o(.text), bar.o(.text) and
804 foo.o(.text, .data). */
806 /* Return true if the PATTERN argument is a wildcard pattern.
807 Although backslashes are treated specially if a pattern contains
808 wildcards, we do not consider the mere presence of a backslash to
809 be enough to cause the the pattern to be treated as a wildcard.
810 That lets us handle DOS filenames more naturally. */
818 for (s
= pattern
; *s
!= '\0'; ++s
)
826 /* Add SECTION to the output section OUTPUT. Do this by creating a
827 lang_input_section statement which is placed at PTR. FILE is the
828 input file which holds SECTION. */
831 wild_doit (ptr
, section
, output
, file
)
832 lang_statement_list_type
*ptr
;
834 lang_output_section_statement_type
*output
;
835 lang_input_statement_type
*file
;
840 flags
= bfd_get_section_flags (section
->owner
, section
);
844 /* If we are doing a final link, discard sections marked with
846 if (! link_info
.relocateable
847 && (flags
& SEC_EXCLUDE
) != 0)
850 /* Discard input sections which are assigned to a section named
851 DISCARD_SECTION_NAME. */
852 if (strcmp (output
->name
, DISCARD_SECTION_NAME
) == 0)
855 /* Discard debugging sections if we are stripping debugging
857 if ((link_info
.strip
== strip_debugger
|| link_info
.strip
== strip_all
)
858 && (flags
& SEC_DEBUGGING
) != 0)
863 if (section
->output_section
== NULL
)
865 /* This prevents future calls from assigning this section. */
866 section
->output_section
= bfd_abs_section_ptr
;
871 if (section
->output_section
== NULL
)
874 lang_input_section_type
*new;
877 if (output
->bfd_section
== NULL
)
885 /* Add a section reference to the list */
886 new = new_stat (lang_input_section
, ptr
);
888 new->section
= section
;
890 section
->output_section
= output
->bfd_section
;
892 flags
= section
->flags
;
894 /* We don't copy the SEC_NEVER_LOAD flag from an input section
895 to an output section, because we want to be able to include a
896 SEC_NEVER_LOAD section in the middle of an otherwise loaded
897 section (I don't know why we want to do this, but we do).
898 build_link_order in ldwrite.c handles this case by turning
899 the embedded SEC_NEVER_LOAD section into a fill. */
901 flags
&= ~ SEC_NEVER_LOAD
;
903 /* If final link, don't copy the SEC_LINK_ONCE flags, they've
904 already been processed. One reason to do this is that on pe
905 format targets, .text$foo sections go into .text and it's odd
906 to see .text with SEC_LINK_ONCE set. */
908 if (! link_info
.relocateable
)
909 flags
&= ~ (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES
);
911 /* If this is not the first input section, and the SEC_READONLY
912 flag is not currently set, then don't set it just because the
913 input section has it set. */
915 if (! first
&& (section
->output_section
->flags
& SEC_READONLY
) == 0)
916 flags
&= ~ SEC_READONLY
;
918 section
->output_section
->flags
|= flags
;
920 /* If SEC_READONLY is not set in the input section, then clear
921 it from the output section. */
922 if ((section
->flags
& SEC_READONLY
) == 0)
923 section
->output_section
->flags
&= ~SEC_READONLY
;
925 switch (output
->sectype
)
932 case overlay_section
:
933 output
->bfd_section
->flags
&= ~SEC_ALLOC
;
936 output
->bfd_section
->flags
&= ~SEC_LOAD
;
937 output
->bfd_section
->flags
|= SEC_NEVER_LOAD
;
941 if (section
->alignment_power
> output
->bfd_section
->alignment_power
)
942 output
->bfd_section
->alignment_power
= section
->alignment_power
;
944 /* If supplied an aligment, then force it. */
945 if (output
->section_alignment
!= -1)
946 output
->bfd_section
->alignment_power
= output
->section_alignment
;
950 /* Expand a wild statement for a particular FILE. SECTION may be
951 NULL, in which case it is a wild card. */
954 wild_section (ptr
, section
, file
, output
)
955 lang_wild_statement_type
*ptr
;
957 lang_input_statement_type
*file
;
958 lang_output_section_statement_type
*output
;
960 if (file
->just_syms_flag
== false)
962 register asection
*s
;
968 wildcard
= wildcardp (section
);
970 for (s
= file
->the_bfd
->sections
; s
!= NULL
; s
= s
->next
)
974 /* Attach all sections named SECTION. If SECTION is NULL,
975 then attach all sections.
977 Previously, if SECTION was NULL, this code did not call
978 wild_doit if the SEC_IS_COMMON flag was set for the
979 section. I did not understand that, and I took it out.
988 name
= bfd_get_section_name (file
->the_bfd
, s
);
990 match
= fnmatch (section
, name
, 0) == 0 ? true : false;
992 match
= strcmp (section
, name
) == 0 ? true : false;
995 wild_doit (&ptr
->children
, s
, output
, file
);
1000 /* This is passed a file name which must have been seen already and
1001 added to the statement tree. We will see if it has been opened
1002 already and had its symbols read. If not then we'll read it. */
1004 static lang_input_statement_type
*
1008 lang_input_statement_type
*search
;
1010 for (search
= (lang_input_statement_type
*) input_file_chain
.head
;
1011 search
!= (lang_input_statement_type
*) NULL
;
1012 search
= (lang_input_statement_type
*) search
->next_real_file
)
1014 if (search
->filename
== (char *) NULL
&& name
== (char *) NULL
)
1016 if (search
->filename
!= (char *) NULL
1017 && name
!= (char *) NULL
1018 && strcmp (search
->filename
, name
) == 0)
1022 if (search
== (lang_input_statement_type
*) NULL
)
1023 search
= new_afile (name
, lang_input_file_is_file_enum
, default_target
,
1026 /* If we have already added this file, or this file is not real
1027 (FIXME: can that ever actually happen?) or the name is NULL
1028 (FIXME: can that ever actually happen?) don't add this file. */
1031 || search
->filename
== (const char *) NULL
)
1034 load_symbols (search
, (lang_statement_list_type
*) NULL
);
1039 /* Get the symbols for an input file. */
1042 load_symbols (entry
, place
)
1043 lang_input_statement_type
*entry
;
1044 lang_statement_list_type
*place
;
1051 ldfile_open_file (entry
);
1053 if (! bfd_check_format (entry
->the_bfd
, bfd_archive
)
1054 && ! bfd_check_format_matches (entry
->the_bfd
, bfd_object
, &matching
))
1057 lang_statement_list_type
*hold
;
1059 err
= bfd_get_error ();
1060 if (err
== bfd_error_file_ambiguously_recognized
)
1064 einfo ("%B: file not recognized: %E\n", entry
->the_bfd
);
1065 einfo ("%B: matching formats:", entry
->the_bfd
);
1066 for (p
= matching
; *p
!= NULL
; p
++)
1070 else if (err
!= bfd_error_file_not_recognized
1072 einfo ("%F%B: file not recognized: %E\n", entry
->the_bfd
);
1074 bfd_close (entry
->the_bfd
);
1075 entry
->the_bfd
= NULL
;
1077 /* See if the emulation has some special knowledge. */
1079 if (ldemul_unrecognized_file (entry
))
1082 /* Try to interpret the file as a linker script. */
1084 ldfile_open_command_file (entry
->filename
);
1089 ldfile_assumed_script
= true;
1090 parser_input
= input_script
;
1092 ldfile_assumed_script
= false;
1099 /* We don't call ldlang_add_file for an archive. Instead, the
1100 add_symbols entry point will call ldlang_add_file, via the
1101 add_archive_element callback, for each element of the archive
1103 switch (bfd_get_format (entry
->the_bfd
))
1109 ldlang_add_file (entry
);
1110 if (trace_files
|| trace_file_tries
)
1111 info_msg ("%I\n", entry
);
1115 if (entry
->whole_archive
)
1117 bfd
*member
= bfd_openr_next_archived_file (entry
->the_bfd
,
1119 while (member
!= NULL
)
1121 if (! bfd_check_format (member
, bfd_object
))
1122 einfo ("%F%B: object %B in archive is not object\n",
1123 entry
->the_bfd
, member
);
1124 if (! ((*link_info
.callbacks
->add_archive_element
)
1125 (&link_info
, member
, "--whole-archive")))
1127 if (! bfd_link_add_symbols (member
, &link_info
))
1128 einfo ("%F%B: could not read symbols: %E\n", member
);
1129 member
= bfd_openr_next_archived_file (entry
->the_bfd
,
1133 entry
->loaded
= true;
1139 if (! bfd_link_add_symbols (entry
->the_bfd
, &link_info
))
1140 einfo ("%F%B: could not read symbols: %E\n", entry
->the_bfd
);
1142 entry
->loaded
= true;
1145 /* Handle a wild statement for a single file F. */
1148 wild_file (s
, section
, f
, output
)
1149 lang_wild_statement_type
*s
;
1150 const char *section
;
1151 lang_input_statement_type
*f
;
1152 lang_output_section_statement_type
*output
;
1154 if (f
->the_bfd
== NULL
1155 || ! bfd_check_format (f
->the_bfd
, bfd_archive
))
1156 wild_section (s
, section
, f
, output
);
1161 /* This is an archive file. We must map each member of the
1162 archive separately. */
1163 member
= bfd_openr_next_archived_file (f
->the_bfd
, (bfd
*) NULL
);
1164 while (member
!= NULL
)
1166 /* When lookup_name is called, it will call the add_symbols
1167 entry point for the archive. For each element of the
1168 archive which is included, BFD will call ldlang_add_file,
1169 which will set the usrdata field of the member to the
1170 lang_input_statement. */
1171 if (member
->usrdata
!= NULL
)
1173 wild_section (s
, section
,
1174 (lang_input_statement_type
*) member
->usrdata
,
1178 member
= bfd_openr_next_archived_file (f
->the_bfd
, member
);
1183 /* Handle a wild statement. SECTION or FILE or both may be NULL,
1184 indicating that it is a wildcard. Separate lang_input_section
1185 statements are created for each part of the expansion; they are
1186 added after the wild statement S. OUTPUT is the output section. */
1189 wild (s
, section
, file
, target
, output
)
1190 lang_wild_statement_type
*s
;
1191 const char *section
;
1194 lang_output_section_statement_type
*output
;
1196 lang_input_statement_type
*f
;
1198 if (file
== (char *) NULL
)
1200 /* Perform the iteration over all files in the list */
1201 for (f
= (lang_input_statement_type
*) file_chain
.head
;
1202 f
!= (lang_input_statement_type
*) NULL
;
1203 f
= (lang_input_statement_type
*) f
->next
)
1205 wild_file (s
, section
, f
, output
);
1208 else if (wildcardp (file
))
1210 for (f
= (lang_input_statement_type
*) file_chain
.head
;
1211 f
!= (lang_input_statement_type
*) NULL
;
1212 f
= (lang_input_statement_type
*) f
->next
)
1214 if (fnmatch (file
, f
->filename
, FNM_FILE_NAME
) == 0)
1215 wild_file (s
, section
, f
, output
);
1220 /* Perform the iteration over a single file */
1221 f
= lookup_name (file
);
1222 wild_file (s
, section
, f
, output
);
1225 if (section
!= (char *) NULL
1226 && strcmp (section
, "COMMON") == 0
1227 && default_common_section
== NULL
)
1229 /* Remember the section that common is going to in case we later
1230 get something which doesn't know where to put it. */
1231 default_common_section
= output
;
1235 /* Open the output file. */
1243 if (output_target
== (char *) NULL
)
1245 if (current_target
!= (char *) NULL
)
1246 output_target
= current_target
;
1248 output_target
= default_target
;
1250 output
= bfd_openw (name
, output_target
);
1252 if (output
== (bfd
*) NULL
)
1254 if (bfd_get_error () == bfd_error_invalid_target
)
1256 einfo ("%P%F: target %s not found\n", output_target
);
1258 einfo ("%P%F: cannot open output file %s: %E\n", name
);
1261 delete_output_file_on_failure
= true;
1263 /* output->flags |= D_PAGED;*/
1265 if (! bfd_set_format (output
, bfd_object
))
1266 einfo ("%P%F:%s: can not make object file: %E\n", name
);
1267 if (! bfd_set_arch_mach (output
,
1268 ldfile_output_architecture
,
1269 ldfile_output_machine
))
1270 einfo ("%P%F:%s: can not set architecture: %E\n", name
);
1272 link_info
.hash
= bfd_link_hash_table_create (output
);
1273 if (link_info
.hash
== (struct bfd_link_hash_table
*) NULL
)
1274 einfo ("%P%F: can not create link hash table: %E\n");
1276 bfd_set_gp_size (output
, g_switch_value
);
1284 ldlang_open_output (statement
)
1285 lang_statement_union_type
* statement
;
1287 switch (statement
->header
.type
)
1289 case lang_output_statement_enum
:
1290 ASSERT (output_bfd
== (bfd
*) NULL
);
1291 output_bfd
= open_output (statement
->output_statement
.name
);
1292 ldemul_set_output_arch ();
1293 if (config
.magic_demand_paged
&& !link_info
.relocateable
)
1294 output_bfd
->flags
|= D_PAGED
;
1296 output_bfd
->flags
&= ~D_PAGED
;
1297 if (config
.text_read_only
)
1298 output_bfd
->flags
|= WP_TEXT
;
1300 output_bfd
->flags
&= ~WP_TEXT
;
1301 if (link_info
.traditional_format
)
1302 output_bfd
->flags
|= BFD_TRADITIONAL_FORMAT
;
1304 output_bfd
->flags
&= ~BFD_TRADITIONAL_FORMAT
;
1307 case lang_target_statement_enum
:
1308 current_target
= statement
->target_statement
.target
;
1315 /* Open all the input files. */
1318 open_input_bfds (s
, force
)
1319 lang_statement_union_type
*s
;
1322 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
1324 switch (s
->header
.type
)
1326 case lang_constructors_statement_enum
:
1327 open_input_bfds (constructor_list
.head
, force
);
1329 case lang_output_section_statement_enum
:
1330 open_input_bfds (s
->output_section_statement
.children
.head
, force
);
1332 case lang_wild_statement_enum
:
1333 /* Maybe we should load the file's symbols */
1334 if (s
->wild_statement
.filename
1335 && ! wildcardp (s
->wild_statement
.filename
))
1336 (void) lookup_name (s
->wild_statement
.filename
);
1337 open_input_bfds (s
->wild_statement
.children
.head
, force
);
1339 case lang_group_statement_enum
:
1341 struct bfd_link_hash_entry
*undefs
;
1343 /* We must continually search the entries in the group
1344 until no new symbols are added to the list of undefined
1349 undefs
= link_info
.hash
->undefs_tail
;
1350 open_input_bfds (s
->group_statement
.children
.head
, true);
1352 while (undefs
!= link_info
.hash
->undefs_tail
);
1355 case lang_target_statement_enum
:
1356 current_target
= s
->target_statement
.target
;
1358 case lang_input_statement_enum
:
1359 if (s
->input_statement
.real
== true)
1361 lang_statement_list_type add
;
1363 s
->input_statement
.target
= current_target
;
1365 /* If we are being called from within a group, and this
1366 is an archive which has already been searched, then
1367 force it to be researched. */
1369 && s
->input_statement
.loaded
1370 && bfd_check_format (s
->input_statement
.the_bfd
,
1372 s
->input_statement
.loaded
= false;
1374 lang_list_init (&add
);
1376 load_symbols (&s
->input_statement
, &add
);
1378 if (add
.head
!= NULL
)
1380 *add
.tail
= s
->next
;
1391 /* If there are [COMMONS] statements, put a wild one into the bss section */
1394 lang_reasonable_defaults ()
1397 lang_output_section_statement_lookup (".text");
1398 lang_output_section_statement_lookup (".data");
1400 default_common_section
=
1401 lang_output_section_statement_lookup (".bss");
1404 if (placed_commons
== false)
1406 lang_wild_statement_type
*new =
1407 new_stat (lang_wild_statement
,
1408 &default_common_section
->children
);
1410 new->section_name
= "COMMON";
1411 new->filename
= (char *) NULL
;
1412 lang_list_init (&new->children
);
1419 Add the supplied name to the symbol table as an undefined reference.
1420 Remove items from the chain as we open input bfds
1422 typedef struct ldlang_undef_chain_list
1424 struct ldlang_undef_chain_list
*next
;
1426 } ldlang_undef_chain_list_type
;
1428 static ldlang_undef_chain_list_type
*ldlang_undef_chain_list_head
;
1431 ldlang_add_undef (name
)
1432 CONST
char *CONST name
;
1434 ldlang_undef_chain_list_type
*new =
1435 ((ldlang_undef_chain_list_type
*)
1436 stat_alloc (sizeof (ldlang_undef_chain_list_type
)));
1438 new->next
= ldlang_undef_chain_list_head
;
1439 ldlang_undef_chain_list_head
= new;
1441 new->name
= buystring (name
);
1444 /* Run through the list of undefineds created above and place them
1445 into the linker hash table as undefined symbols belonging to the
1449 lang_place_undefineds ()
1451 ldlang_undef_chain_list_type
*ptr
;
1453 for (ptr
= ldlang_undef_chain_list_head
;
1454 ptr
!= (ldlang_undef_chain_list_type
*) NULL
;
1457 struct bfd_link_hash_entry
*h
;
1459 h
= bfd_link_hash_lookup (link_info
.hash
, ptr
->name
, true, false, true);
1460 if (h
== (struct bfd_link_hash_entry
*) NULL
)
1461 einfo ("%P%F: bfd_link_hash_lookup failed: %E\n");
1462 if (h
->type
== bfd_link_hash_new
)
1464 h
->type
= bfd_link_hash_undefined
;
1465 h
->u
.undef
.abfd
= NULL
;
1466 bfd_link_add_undef (link_info
.hash
, h
);
1471 /* Open input files and attatch to output sections */
1473 map_input_to_output_sections (s
, target
, output_section_statement
)
1474 lang_statement_union_type
* s
;
1476 lang_output_section_statement_type
* output_section_statement
;
1478 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
1480 switch (s
->header
.type
)
1484 case lang_wild_statement_enum
:
1485 wild (&s
->wild_statement
, s
->wild_statement
.section_name
,
1486 s
->wild_statement
.filename
, target
,
1487 output_section_statement
);
1490 case lang_constructors_statement_enum
:
1491 map_input_to_output_sections (constructor_list
.head
,
1493 output_section_statement
);
1495 case lang_output_section_statement_enum
:
1496 map_input_to_output_sections (s
->output_section_statement
.children
.head
,
1498 &s
->output_section_statement
);
1500 case lang_output_statement_enum
:
1502 case lang_target_statement_enum
:
1503 target
= s
->target_statement
.target
;
1505 case lang_group_statement_enum
:
1506 map_input_to_output_sections (s
->group_statement
.children
.head
,
1508 output_section_statement
);
1510 case lang_fill_statement_enum
:
1511 case lang_input_section_enum
:
1512 case lang_object_symbols_statement_enum
:
1513 case lang_data_statement_enum
:
1514 case lang_reloc_statement_enum
:
1515 case lang_padding_statement_enum
:
1516 case lang_input_statement_enum
:
1517 if (output_section_statement
!= NULL
1518 && output_section_statement
->bfd_section
== NULL
)
1519 init_os (output_section_statement
);
1521 case lang_assignment_statement_enum
:
1522 if (output_section_statement
!= NULL
1523 && output_section_statement
->bfd_section
== NULL
)
1524 init_os (output_section_statement
);
1526 /* Make sure that any sections mentioned in the assignment
1528 exp_init_os (s
->assignment_statement
.exp
);
1530 case lang_afile_asection_pair_statement_enum
:
1533 case lang_address_statement_enum
:
1534 /* Mark the specified section with the supplied address */
1536 lang_output_section_statement_type
*os
=
1537 lang_output_section_statement_lookup
1538 (s
->address_statement
.section_name
);
1540 if (os
->bfd_section
== NULL
)
1542 os
->addr_tree
= s
->address_statement
.address
;
1550 print_output_section_statement (output_section_statement
)
1551 lang_output_section_statement_type
* output_section_statement
;
1553 asection
*section
= output_section_statement
->bfd_section
;
1556 if (output_section_statement
!= abs_output_section
)
1558 minfo ("\n%s", output_section_statement
->name
);
1560 if (section
!= NULL
)
1562 print_dot
= section
->vma
;
1564 len
= strlen (output_section_statement
->name
);
1565 if (len
>= SECTION_NAME_MAP_LENGTH
- 1)
1570 while (len
< SECTION_NAME_MAP_LENGTH
)
1576 minfo ("0x%V %W", section
->vma
, section
->_raw_size
);
1578 if (output_section_statement
->load_base
!= NULL
)
1582 addr
= exp_get_abs_int (output_section_statement
->load_base
, 0,
1583 "load base", lang_final_phase_enum
);
1584 minfo (" load address 0x%V", addr
);
1591 print_statement_list (output_section_statement
->children
.head
,
1592 output_section_statement
);
1596 print_assignment (assignment
, output_section
)
1597 lang_assignment_statement_type
* assignment
;
1598 lang_output_section_statement_type
* output_section
;
1601 etree_value_type result
;
1603 for (i
= 0; i
< SECTION_NAME_MAP_LENGTH
; i
++)
1606 result
= exp_fold_tree (assignment
->exp
->assign
.src
, output_section
,
1607 lang_final_phase_enum
, print_dot
, &print_dot
);
1609 minfo ("0x%V", result
.value
+ result
.section
->bfd_section
->vma
);
1620 exp_print_tree (assignment
->exp
);
1626 print_input_statement (statm
)
1627 lang_input_statement_type
* statm
;
1629 if (statm
->filename
!= (char *) NULL
)
1631 fprintf (config
.map_file
, "LOAD %s\n", statm
->filename
);
1635 /* Print all symbols defined in a particular section. This is called
1636 via bfd_link_hash_traverse. */
1639 print_one_symbol (hash_entry
, ptr
)
1640 struct bfd_link_hash_entry
*hash_entry
;
1643 asection
*sec
= (asection
*) ptr
;
1645 if ((hash_entry
->type
== bfd_link_hash_defined
1646 || hash_entry
->type
== bfd_link_hash_defweak
)
1647 && sec
== hash_entry
->u
.def
.section
)
1651 for (i
= 0; i
< SECTION_NAME_MAP_LENGTH
; i
++)
1654 (hash_entry
->u
.def
.value
1655 + hash_entry
->u
.def
.section
->output_offset
1656 + hash_entry
->u
.def
.section
->output_section
->vma
));
1658 minfo (" %T\n", hash_entry
->root
.string
);
1664 /* Print information about an input section to the map file. */
1667 print_input_section (in
)
1668 lang_input_section_type
* in
;
1670 asection
*i
= in
->section
;
1671 bfd_size_type size
= i
->_cooked_size
!= 0 ? i
->_cooked_size
: i
->_raw_size
;
1677 minfo ("%s", i
->name
);
1679 if (i
->output_section
!= NULL
)
1683 len
= 1 + strlen (i
->name
);
1684 if (len
>= SECTION_NAME_MAP_LENGTH
- 1)
1689 while (len
< SECTION_NAME_MAP_LENGTH
)
1695 minfo ("0x%V %W %B\n",
1696 i
->output_section
->vma
+ i
->output_offset
, size
,
1699 if (i
->_cooked_size
!= 0 && i
->_cooked_size
!= i
->_raw_size
)
1701 len
= SECTION_NAME_MAP_LENGTH
+ 3;
1713 minfo ("%W (size before relaxing)\n", i
->_raw_size
);
1716 bfd_link_hash_traverse (link_info
.hash
, print_one_symbol
, (PTR
) i
);
1718 print_dot
= i
->output_section
->vma
+ i
->output_offset
+ size
;
1724 print_fill_statement (fill
)
1725 lang_fill_statement_type
* fill
;
1727 fprintf (config
.map_file
, " FILL mask 0x%x\n", fill
->fill
);
1731 print_data_statement (data
)
1732 lang_data_statement_type
* data
;
1739 for (i
= 0; i
< SECTION_NAME_MAP_LENGTH
; i
++)
1742 addr
= data
->output_vma
;
1743 if (data
->output_section
!= NULL
)
1744 addr
+= data
->output_section
->vma
;
1772 minfo ("0x%V %W %s 0x%v", addr
, size
, name
, data
->value
);
1774 if (data
->exp
->type
.node_class
!= etree_value
)
1777 exp_print_tree (data
->exp
);
1782 print_dot
= addr
+ size
;
1785 /* Print an address statement. These are generated by options like
1789 print_address_statement (address
)
1790 lang_address_statement_type
*address
;
1792 minfo ("Address of section %s set to ", address
->section_name
);
1793 exp_print_tree (address
->address
);
1797 /* Print a reloc statement. */
1800 print_reloc_statement (reloc
)
1801 lang_reloc_statement_type
*reloc
;
1807 for (i
= 0; i
< SECTION_NAME_MAP_LENGTH
; i
++)
1810 addr
= reloc
->output_vma
;
1811 if (reloc
->output_section
!= NULL
)
1812 addr
+= reloc
->output_section
->vma
;
1814 size
= bfd_get_reloc_size (reloc
->howto
);
1816 minfo ("0x%V %W RELOC %s ", addr
, size
, reloc
->howto
->name
);
1818 if (reloc
->name
!= NULL
)
1819 minfo ("%s+", reloc
->name
);
1821 minfo ("%s+", reloc
->section
->name
);
1823 exp_print_tree (reloc
->addend_exp
);
1827 print_dot
= addr
+ size
;
1831 print_padding_statement (s
)
1832 lang_padding_statement_type
*s
;
1839 len
= sizeof " *fill*" - 1;
1840 while (len
< SECTION_NAME_MAP_LENGTH
)
1846 addr
= s
->output_offset
;
1847 if (s
->output_section
!= NULL
)
1848 addr
+= s
->output_section
->vma
;
1849 minfo ("0x%V %W", addr
, s
->size
);
1852 minfo (" %u", s
->fill
);
1856 print_dot
= addr
+ s
->size
;
1860 print_wild_statement (w
, os
)
1861 lang_wild_statement_type
* w
;
1862 lang_output_section_statement_type
* os
;
1866 if (w
->filename
!= NULL
)
1867 minfo ("%s", w
->filename
);
1871 if (w
->section_name
!= NULL
)
1872 minfo ("(%s)", w
->section_name
);
1878 print_statement_list (w
->children
.head
, os
);
1881 /* Print a group statement. */
1885 lang_group_statement_type
*s
;
1886 lang_output_section_statement_type
*os
;
1888 fprintf (config
.map_file
, "START GROUP\n");
1889 print_statement_list (s
->children
.head
, os
);
1890 fprintf (config
.map_file
, "END GROUP\n");
1893 /* Print the list of statements in S.
1894 This can be called for any statement type. */
1897 print_statement_list (s
, os
)
1898 lang_statement_union_type
*s
;
1899 lang_output_section_statement_type
*os
;
1903 print_statement (s
, os
);
1908 /* Print the first statement in statement list S.
1909 This can be called for any statement type. */
1912 print_statement (s
, os
)
1913 lang_statement_union_type
*s
;
1914 lang_output_section_statement_type
*os
;
1916 switch (s
->header
.type
)
1919 fprintf (config
.map_file
, "Fail with %d\n", s
->header
.type
);
1922 case lang_constructors_statement_enum
:
1923 if (constructor_list
.head
!= NULL
)
1925 minfo (" CONSTRUCTORS\n");
1926 print_statement_list (constructor_list
.head
, os
);
1929 case lang_wild_statement_enum
:
1930 print_wild_statement (&s
->wild_statement
, os
);
1932 case lang_address_statement_enum
:
1933 print_address_statement (&s
->address_statement
);
1935 case lang_object_symbols_statement_enum
:
1936 minfo (" CREATE_OBJECT_SYMBOLS\n");
1938 case lang_fill_statement_enum
:
1939 print_fill_statement (&s
->fill_statement
);
1941 case lang_data_statement_enum
:
1942 print_data_statement (&s
->data_statement
);
1944 case lang_reloc_statement_enum
:
1945 print_reloc_statement (&s
->reloc_statement
);
1947 case lang_input_section_enum
:
1948 print_input_section (&s
->input_section
);
1950 case lang_padding_statement_enum
:
1951 print_padding_statement (&s
->padding_statement
);
1953 case lang_output_section_statement_enum
:
1954 print_output_section_statement (&s
->output_section_statement
);
1956 case lang_assignment_statement_enum
:
1957 print_assignment (&s
->assignment_statement
, os
);
1959 case lang_target_statement_enum
:
1960 fprintf (config
.map_file
, "TARGET(%s)\n", s
->target_statement
.target
);
1962 case lang_output_statement_enum
:
1963 minfo ("OUTPUT(%s", s
->output_statement
.name
);
1964 if (output_target
!= NULL
)
1965 minfo (" %s", output_target
);
1968 case lang_input_statement_enum
:
1969 print_input_statement (&s
->input_statement
);
1971 case lang_group_statement_enum
:
1972 print_group (&s
->group_statement
, os
);
1974 case lang_afile_asection_pair_statement_enum
:
1983 print_statement_list (statement_list
.head
, abs_output_section
);
1986 /* Print the first N statements in statement list S to STDERR.
1987 If N == 0, nothing is printed.
1988 If N < 0, the entire list is printed.
1989 Intended to be called from GDB. */
1992 dprint_statement (s
, n
)
1993 lang_statement_union_type
* s
;
1996 FILE *map_save
= config
.map_file
;
1998 config
.map_file
= stderr
;
2001 print_statement_list (s
, abs_output_section
);
2004 while (s
&& --n
>= 0)
2006 print_statement (s
, abs_output_section
);
2011 config
.map_file
= map_save
;
2015 insert_pad (this_ptr
, fill
, power
, output_section_statement
, dot
)
2016 lang_statement_union_type
** this_ptr
;
2019 asection
* output_section_statement
;
2022 /* Align this section first to the
2023 input sections requirement, then
2024 to the output section's requirement.
2025 If this alignment is > than any seen before,
2026 then record it too. Perform the alignment by
2027 inserting a magic 'padding' statement.
2030 unsigned int alignment_needed
= align_power (dot
, power
) - dot
;
2032 if (alignment_needed
!= 0)
2034 lang_statement_union_type
*new =
2035 ((lang_statement_union_type
*)
2036 stat_alloc (sizeof (lang_padding_statement_type
)));
2038 /* Link into existing chain */
2039 new->header
.next
= *this_ptr
;
2041 new->header
.type
= lang_padding_statement_enum
;
2042 new->padding_statement
.output_section
= output_section_statement
;
2043 new->padding_statement
.output_offset
=
2044 dot
- output_section_statement
->vma
;
2045 new->padding_statement
.fill
= fill
;
2046 new->padding_statement
.size
= alignment_needed
;
2050 /* Remember the most restrictive alignment */
2051 if (power
> output_section_statement
->alignment_power
)
2053 output_section_statement
->alignment_power
= power
;
2055 output_section_statement
->_raw_size
+= alignment_needed
;
2056 return alignment_needed
+ dot
;
2060 /* Work out how much this section will move the dot point */
2062 size_input_section (this_ptr
, output_section_statement
, fill
, dot
, relax
)
2063 lang_statement_union_type
** this_ptr
;
2064 lang_output_section_statement_type
* output_section_statement
;
2069 lang_input_section_type
*is
= &((*this_ptr
)->input_section
);
2070 asection
*i
= is
->section
;
2072 if (is
->ifile
->just_syms_flag
== false)
2074 if (output_section_statement
->subsection_alignment
!= -1)
2075 i
->alignment_power
=
2076 output_section_statement
->subsection_alignment
;
2078 dot
= insert_pad (this_ptr
, fill
, i
->alignment_power
,
2079 output_section_statement
->bfd_section
, dot
);
2081 /* Remember where in the output section this input section goes */
2083 i
->output_offset
= dot
- output_section_statement
->bfd_section
->vma
;
2085 /* Mark how big the output section must be to contain this now
2087 if (i
->_cooked_size
!= 0)
2088 dot
+= i
->_cooked_size
;
2090 dot
+= i
->_raw_size
;
2091 output_section_statement
->bfd_section
->_raw_size
= dot
- output_section_statement
->bfd_section
->vma
;
2095 i
->output_offset
= i
->vma
- output_section_statement
->bfd_section
->vma
;
2101 /* This variable indicates whether bfd_relax_section should be called
2104 static boolean relax_again
;
2106 /* Set the sizes for all the output sections. */
2109 lang_size_sections (s
, output_section_statement
, prev
, fill
, dot
, relax
)
2110 lang_statement_union_type
* s
;
2111 lang_output_section_statement_type
* output_section_statement
;
2112 lang_statement_union_type
** prev
;
2117 /* Size up the sections from their constituent parts */
2118 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
2120 switch (s
->header
.type
)
2123 case lang_output_section_statement_enum
:
2126 lang_output_section_statement_type
*os
= &s
->output_section_statement
;
2128 if (os
->bfd_section
== NULL
)
2130 /* This section was never actually created. */
2134 /* If this is a COFF shared library section, use the size and
2135 address from the input section. FIXME: This is COFF
2136 specific; it would be cleaner if there were some other way
2137 to do this, but nothing simple comes to mind. */
2138 if ((os
->bfd_section
->flags
& SEC_COFF_SHARED_LIBRARY
) != 0)
2142 if (os
->children
.head
== NULL
2143 || os
->children
.head
->next
!= NULL
2144 || os
->children
.head
->header
.type
!= lang_input_section_enum
)
2145 einfo ("%P%X: Internal error on COFF shared library section %s\n",
2148 input
= os
->children
.head
->input_section
.section
;
2149 bfd_set_section_vma (os
->bfd_section
->owner
,
2151 bfd_section_vma (input
->owner
, input
));
2152 os
->bfd_section
->_raw_size
= input
->_raw_size
;
2156 if (bfd_is_abs_section (os
->bfd_section
))
2158 /* No matter what happens, an abs section starts at zero */
2159 ASSERT (os
->bfd_section
->vma
== 0);
2163 if (os
->addr_tree
== (etree_type
*) NULL
)
2165 /* No address specified for this section, get one
2166 from the region specification
2168 if (os
->region
== (lang_memory_region_type
*) NULL
)
2170 os
->region
= lang_memory_default (os
->bfd_section
);
2172 dot
= os
->region
->current
;
2173 if (os
->section_alignment
== -1)
2178 dot
= align_power (dot
, os
->bfd_section
->alignment_power
);
2179 if (dot
!= olddot
&& config
.warn_section_align
)
2180 einfo ("%P: warning: changing start of section %s by %u bytes\n",
2181 os
->name
, (unsigned int) (dot
- olddot
));
2188 r
= exp_fold_tree (os
->addr_tree
,
2190 lang_allocating_phase_enum
,
2192 if (r
.valid
== false)
2194 einfo ("%F%S: non constant address expression for section %s\n",
2197 dot
= r
.value
+ r
.section
->bfd_section
->vma
;
2199 /* The section starts here */
2200 /* First, align to what the section needs */
2202 if (os
->section_alignment
!= -1)
2203 dot
= align_power (dot
, os
->section_alignment
);
2205 bfd_set_section_vma (0, os
->bfd_section
, dot
);
2207 os
->bfd_section
->output_offset
= 0;
2210 (void) lang_size_sections (os
->children
.head
, os
, &os
->children
.head
,
2211 os
->fill
, dot
, relax
);
2212 /* Ignore the size of the input sections, use the vma and size to */
2215 after
= ALIGN_N (os
->bfd_section
->vma
+
2216 os
->bfd_section
->_raw_size
,
2217 /* The coercion here is important, see ld.h. */
2218 (bfd_vma
) os
->block_value
);
2220 if (bfd_is_abs_section (os
->bfd_section
))
2221 ASSERT (after
== os
->bfd_section
->vma
);
2223 os
->bfd_section
->_raw_size
= after
- os
->bfd_section
->vma
;
2224 dot
= os
->bfd_section
->vma
+ os
->bfd_section
->_raw_size
;
2225 os
->processed
= true;
2227 /* Replace into region ? */
2228 if (os
->region
!= (lang_memory_region_type
*) NULL
)
2230 os
->region
->current
= dot
;
2231 /* Make sure this isn't silly. */
2232 if (os
->region
->current
< os
->region
->origin
2233 || (os
->region
->current
- os
->region
->origin
2234 > os
->region
->length
))
2236 if (os
->addr_tree
!= (etree_type
*) NULL
)
2238 einfo ("%X%P: address 0x%v of %B section %s is not within region %s\n",
2239 os
->region
->current
,
2240 os
->bfd_section
->owner
,
2241 os
->bfd_section
->name
,
2246 einfo ("%X%P: region %s is full (%B section %s)\n",
2248 os
->bfd_section
->owner
,
2249 os
->bfd_section
->name
);
2251 /* Reset the region pointer. */
2252 os
->region
->current
= os
->region
->origin
;
2258 case lang_constructors_statement_enum
:
2259 dot
= lang_size_sections (constructor_list
.head
,
2260 output_section_statement
,
2261 &s
->wild_statement
.children
.head
,
2266 case lang_data_statement_enum
:
2268 unsigned int size
= 0;
2270 s
->data_statement
.output_vma
= dot
- output_section_statement
->bfd_section
->vma
;
2271 s
->data_statement
.output_section
=
2272 output_section_statement
->bfd_section
;
2274 switch (s
->data_statement
.type
)
2292 output_section_statement
->bfd_section
->_raw_size
+= size
;
2293 /* The output section gets contents, and then we inspect for
2294 any flags set in the input script which override any ALLOC */
2295 output_section_statement
->bfd_section
->flags
|= SEC_HAS_CONTENTS
;
2296 if (!(output_section_statement
->flags
& SEC_NEVER_LOAD
)) {
2297 output_section_statement
->bfd_section
->flags
|= SEC_ALLOC
| SEC_LOAD
;
2302 case lang_reloc_statement_enum
:
2306 s
->reloc_statement
.output_vma
=
2307 dot
- output_section_statement
->bfd_section
->vma
;
2308 s
->reloc_statement
.output_section
=
2309 output_section_statement
->bfd_section
;
2310 size
= bfd_get_reloc_size (s
->reloc_statement
.howto
);
2312 output_section_statement
->bfd_section
->_raw_size
+= size
;
2316 case lang_wild_statement_enum
:
2318 dot
= lang_size_sections (s
->wild_statement
.children
.head
,
2319 output_section_statement
,
2320 &s
->wild_statement
.children
.head
,
2326 case lang_object_symbols_statement_enum
:
2327 link_info
.create_object_symbols_section
=
2328 output_section_statement
->bfd_section
;
2330 case lang_output_statement_enum
:
2331 case lang_target_statement_enum
:
2333 case lang_input_section_enum
:
2337 i
= (*prev
)->input_section
.section
;
2340 if (i
->_cooked_size
== 0)
2341 i
->_cooked_size
= i
->_raw_size
;
2347 if (! bfd_relax_section (i
->owner
, i
, &link_info
, &again
))
2348 einfo ("%P%F: can't relax section: %E\n");
2352 dot
= size_input_section (prev
,
2353 output_section_statement
,
2354 output_section_statement
->fill
,
2358 case lang_input_statement_enum
:
2360 case lang_fill_statement_enum
:
2361 s
->fill_statement
.output_section
= output_section_statement
->bfd_section
;
2363 fill
= s
->fill_statement
.fill
;
2365 case lang_assignment_statement_enum
:
2367 bfd_vma newdot
= dot
;
2369 exp_fold_tree (s
->assignment_statement
.exp
,
2370 output_section_statement
,
2371 lang_allocating_phase_enum
,
2375 if (newdot
!= dot
&& !relax
)
2377 /* The assignment changed dot. Insert a pad. */
2378 if (output_section_statement
== abs_output_section
)
2380 /* If we don't have an output section, then just adjust
2381 the default memory address. */
2382 lang_memory_region_lookup ("*default*")->current
= newdot
;
2386 lang_statement_union_type
*new =
2387 ((lang_statement_union_type
*)
2388 stat_alloc (sizeof (lang_padding_statement_type
)));
2390 /* Link into existing chain */
2391 new->header
.next
= *prev
;
2393 new->header
.type
= lang_padding_statement_enum
;
2394 new->padding_statement
.output_section
=
2395 output_section_statement
->bfd_section
;
2396 new->padding_statement
.output_offset
=
2397 dot
- output_section_statement
->bfd_section
->vma
;
2398 new->padding_statement
.fill
= fill
;
2399 new->padding_statement
.size
= newdot
- dot
;
2400 output_section_statement
->bfd_section
->_raw_size
+=
2401 new->padding_statement
.size
;
2409 case lang_padding_statement_enum
:
2410 /* If we are relaxing, and this is not the first pass, some
2411 padding statements may have been inserted during previous
2412 passes. We may have to move the padding statement to a new
2413 location if dot has a different value at this point in this
2414 pass than it did at this point in the previous pass. */
2415 s
->padding_statement
.output_offset
=
2416 dot
- output_section_statement
->bfd_section
->vma
;
2417 dot
+= s
->padding_statement
.size
;
2418 output_section_statement
->bfd_section
->_raw_size
+=
2419 s
->padding_statement
.size
;
2422 case lang_group_statement_enum
:
2423 dot
= lang_size_sections (s
->group_statement
.children
.head
,
2424 output_section_statement
,
2425 &s
->group_statement
.children
.head
,
2433 /* This can only get here when relaxing is turned on */
2435 case lang_address_statement_enum
:
2438 prev
= &s
->header
.next
;
2444 lang_do_assignments (s
, output_section_statement
, fill
, dot
)
2445 lang_statement_union_type
* s
;
2446 lang_output_section_statement_type
* output_section_statement
;
2450 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
2452 switch (s
->header
.type
)
2454 case lang_constructors_statement_enum
:
2455 dot
= lang_do_assignments (constructor_list
.head
,
2456 output_section_statement
,
2461 case lang_output_section_statement_enum
:
2463 lang_output_section_statement_type
*os
=
2464 &(s
->output_section_statement
);
2466 if (os
->bfd_section
!= NULL
)
2468 dot
= os
->bfd_section
->vma
;
2469 (void) lang_do_assignments (os
->children
.head
, os
,
2471 dot
= os
->bfd_section
->vma
+ os
->bfd_section
->_raw_size
;
2475 /* If nothing has been placed into the output section then
2476 it won't have a bfd_section. */
2477 if (os
->bfd_section
)
2479 os
->bfd_section
->lma
2480 = exp_get_abs_int(os
->load_base
, 0,"load base", lang_final_phase_enum
);
2485 case lang_wild_statement_enum
:
2487 dot
= lang_do_assignments (s
->wild_statement
.children
.head
,
2488 output_section_statement
,
2493 case lang_object_symbols_statement_enum
:
2494 case lang_output_statement_enum
:
2495 case lang_target_statement_enum
:
2497 case lang_common_statement_enum
:
2500 case lang_data_statement_enum
:
2502 etree_value_type value
;
2504 value
= exp_fold_tree (s
->data_statement
.exp
,
2506 lang_final_phase_enum
, dot
, &dot
);
2507 s
->data_statement
.value
= value
.value
;
2508 if (value
.valid
== false)
2509 einfo ("%F%P: invalid data statement\n");
2511 switch (s
->data_statement
.type
)
2529 case lang_reloc_statement_enum
:
2531 etree_value_type value
;
2533 value
= exp_fold_tree (s
->reloc_statement
.addend_exp
,
2535 lang_final_phase_enum
, dot
, &dot
);
2536 s
->reloc_statement
.addend_value
= value
.value
;
2537 if (value
.valid
== false)
2538 einfo ("%F%P: invalid reloc statement\n");
2540 dot
+= bfd_get_reloc_size (s
->reloc_statement
.howto
);
2543 case lang_input_section_enum
:
2545 asection
*in
= s
->input_section
.section
;
2547 if (in
->_cooked_size
!= 0)
2548 dot
+= in
->_cooked_size
;
2550 dot
+= in
->_raw_size
;
2554 case lang_input_statement_enum
:
2556 case lang_fill_statement_enum
:
2557 fill
= s
->fill_statement
.fill
;
2559 case lang_assignment_statement_enum
:
2561 exp_fold_tree (s
->assignment_statement
.exp
,
2562 output_section_statement
,
2563 lang_final_phase_enum
,
2569 case lang_padding_statement_enum
:
2570 dot
+= s
->padding_statement
.size
;
2573 case lang_group_statement_enum
:
2574 dot
= lang_do_assignments (s
->group_statement
.children
.head
,
2575 output_section_statement
,
2583 case lang_address_statement_enum
:
2591 /* Fix any .startof. or .sizeof. symbols. When the assemblers see the
2592 operator .startof. (section_name), it produces an undefined symbol
2593 .startof.section_name. Similarly, when it sees
2594 .sizeof. (section_name), it produces an undefined symbol
2595 .sizeof.section_name. For all the output sections, we look for
2596 such symbols, and set them to the correct value. */
2603 if (link_info
.relocateable
)
2606 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
2608 const char *secname
;
2610 struct bfd_link_hash_entry
*h
;
2612 secname
= bfd_get_section_name (output_bfd
, s
);
2613 buf
= xmalloc (10 + strlen (secname
));
2615 sprintf (buf
, ".startof.%s", secname
);
2616 h
= bfd_link_hash_lookup (link_info
.hash
, buf
, false, false, true);
2617 if (h
!= NULL
&& h
->type
== bfd_link_hash_undefined
)
2619 h
->type
= bfd_link_hash_defined
;
2620 h
->u
.def
.value
= bfd_get_section_vma (output_bfd
, s
);
2621 h
->u
.def
.section
= bfd_abs_section_ptr
;
2624 sprintf (buf
, ".sizeof.%s", secname
);
2625 h
= bfd_link_hash_lookup (link_info
.hash
, buf
, false, false, true);
2626 if (h
!= NULL
&& h
->type
== bfd_link_hash_undefined
)
2628 h
->type
= bfd_link_hash_defined
;
2629 if (s
->_cooked_size
!= 0)
2630 h
->u
.def
.value
= s
->_cooked_size
;
2632 h
->u
.def
.value
= s
->_raw_size
;
2633 h
->u
.def
.section
= bfd_abs_section_ptr
;
2643 struct bfd_link_hash_entry
*h
;
2646 if (link_info
.relocateable
|| link_info
.shared
)
2651 if (entry_symbol
== (char *) NULL
)
2653 /* No entry has been specified. Look for start, but don't warn
2654 if we don't find it. */
2655 entry_symbol
= "start";
2659 h
= bfd_link_hash_lookup (link_info
.hash
, entry_symbol
, false, false, true);
2660 if (h
!= (struct bfd_link_hash_entry
*) NULL
2661 && (h
->type
== bfd_link_hash_defined
2662 || h
->type
== bfd_link_hash_defweak
)
2663 && h
->u
.def
.section
->output_section
!= NULL
)
2667 val
= (h
->u
.def
.value
2668 + bfd_get_section_vma (output_bfd
,
2669 h
->u
.def
.section
->output_section
)
2670 + h
->u
.def
.section
->output_offset
);
2671 if (! bfd_set_start_address (output_bfd
, val
))
2672 einfo ("%P%F:%s: can't set start address\n", entry_symbol
);
2678 /* Can't find the entry symbol. Use the first address in the
2680 ts
= bfd_get_section_by_name (output_bfd
, ".text");
2681 if (ts
!= (asection
*) NULL
)
2684 einfo ("%P: warning: cannot find entry symbol %s; defaulting to %V\n",
2685 entry_symbol
, bfd_get_section_vma (output_bfd
, ts
));
2686 if (! bfd_set_start_address (output_bfd
,
2687 bfd_get_section_vma (output_bfd
, ts
)))
2688 einfo ("%P%F: can't set start address\n");
2693 einfo ("%P: warning: cannot find entry symbol %s; not setting start address\n",
2699 /* This is a small function used when we want to ignore errors from
2703 #ifdef ANSI_PROTOTYPES
2704 ignore_bfd_errors (const char *s
, ...)
2706 ignore_bfd_errors (s
)
2710 /* Don't do anything. */
2713 /* Check that the architecture of all the input files is compatible
2714 with the output file. Also call the backend to let it do any
2715 other checking that is needed. */
2720 lang_statement_union_type
*file
;
2722 CONST bfd_arch_info_type
*compatible
;
2724 for (file
= file_chain
.head
;
2725 file
!= (lang_statement_union_type
*) NULL
;
2726 file
= file
->input_statement
.next
)
2728 input_bfd
= file
->input_statement
.the_bfd
;
2729 compatible
= bfd_arch_get_compatible (input_bfd
,
2731 if (compatible
== NULL
)
2733 if (command_line
.warn_mismatch
)
2734 einfo ("%P: warning: %s architecture of input file `%B' is incompatible with %s output\n",
2735 bfd_printable_name (input_bfd
), input_bfd
,
2736 bfd_printable_name (output_bfd
));
2740 bfd_error_handler_type pfn
;
2742 /* If we aren't supposed to warn about mismatched input
2743 files, temporarily set the BFD error handler to a
2744 function which will do nothing. We still want to call
2745 bfd_merge_private_bfd_data, since it may set up
2746 information which is needed in the output file. */
2747 if (! command_line
.warn_mismatch
)
2748 pfn
= bfd_set_error_handler (ignore_bfd_errors
);
2749 if (! bfd_merge_private_bfd_data (input_bfd
, output_bfd
))
2751 if (command_line
.warn_mismatch
)
2752 einfo ("%E%X: failed to merge target specific data of file %B\n",
2755 if (! command_line
.warn_mismatch
)
2756 bfd_set_error_handler (pfn
);
2761 /* Look through all the global common symbols and attach them to the
2762 correct section. The -sort-common command line switch may be used
2763 to roughly sort the entries by size. */
2768 if (link_info
.relocateable
2769 && ! command_line
.force_common_definition
)
2772 if (! config
.sort_common
)
2773 bfd_link_hash_traverse (link_info
.hash
, lang_one_common
, (PTR
) NULL
);
2778 for (power
= 4; power
>= 0; power
--)
2779 bfd_link_hash_traverse (link_info
.hash
, lang_one_common
,
2784 /* Place one common symbol in the correct section. */
2787 lang_one_common (h
, info
)
2788 struct bfd_link_hash_entry
*h
;
2791 unsigned int power_of_two
;
2795 if (h
->type
!= bfd_link_hash_common
)
2799 power_of_two
= h
->u
.c
.p
->alignment_power
;
2801 if (config
.sort_common
2802 && power_of_two
< (unsigned int) *(int *) info
)
2805 section
= h
->u
.c
.p
->section
;
2807 /* Increase the size of the section. */
2808 section
->_raw_size
= ALIGN_N (section
->_raw_size
,
2809 (bfd_size_type
) (1 << power_of_two
));
2811 /* Adjust the alignment if necessary. */
2812 if (power_of_two
> section
->alignment_power
)
2813 section
->alignment_power
= power_of_two
;
2815 /* Change the symbol from common to defined. */
2816 h
->type
= bfd_link_hash_defined
;
2817 h
->u
.def
.section
= section
;
2818 h
->u
.def
.value
= section
->_raw_size
;
2820 /* Increase the size of the section. */
2821 section
->_raw_size
+= size
;
2823 /* Make sure the section is allocated in memory, and make sure that
2824 it is no longer a common section. */
2825 section
->flags
|= SEC_ALLOC
;
2826 section
->flags
&= ~ SEC_IS_COMMON
;
2828 if (config
.map_file
!= NULL
)
2830 static boolean header_printed
;
2835 if (! header_printed
)
2837 minfo ("\nAllocating common symbols\n");
2838 minfo ("Common symbol size file\n\n");
2839 header_printed
= true;
2842 name
= demangle (h
->root
.string
);
2844 len
= strlen (name
);
2859 if (size
<= 0xffffffff)
2860 sprintf (buf
, "%lx", (unsigned long) size
);
2862 sprintf_vma (buf
, size
);
2872 minfo ("%B\n", section
->owner
);
2879 run through the input files and ensure that every input
2880 section has somewhere to go. If one is found without
2881 a destination then create an input request and place it
2882 into the statement tree.
2886 lang_place_orphans ()
2888 lang_input_statement_type
*file
;
2890 for (file
= (lang_input_statement_type
*) file_chain
.head
;
2891 file
!= (lang_input_statement_type
*) NULL
;
2892 file
= (lang_input_statement_type
*) file
->next
)
2896 for (s
= file
->the_bfd
->sections
;
2897 s
!= (asection
*) NULL
;
2900 if (s
->output_section
== (asection
*) NULL
)
2902 /* This section of the file is not attatched, root
2903 around for a sensible place for it to go */
2905 if (file
->just_syms_flag
)
2907 /* We are only retrieving symbol values from this
2908 file. We want the symbols to act as though the
2909 values in the file are absolute. */
2910 s
->output_section
= bfd_abs_section_ptr
;
2911 s
->output_offset
= s
->vma
;
2913 else if (strcmp (s
->name
, "COMMON") == 0)
2915 /* This is a lonely common section which must have
2916 come from an archive. We attach to the section
2917 with the wildcard. */
2918 if (! link_info
.relocateable
2919 || command_line
.force_common_definition
)
2921 if (default_common_section
== NULL
)
2924 /* This message happens when using the
2925 svr3.ifile linker script, so I have
2927 info_msg ("%P: no [COMMON] command, defaulting to .bss\n");
2929 default_common_section
=
2930 lang_output_section_statement_lookup (".bss");
2933 wild_doit (&default_common_section
->children
, s
,
2934 default_common_section
, file
);
2937 else if (ldemul_place_orphan (file
, s
))
2941 lang_output_section_statement_type
*os
=
2942 lang_output_section_statement_lookup (s
->name
);
2944 wild_doit (&os
->children
, s
, os
, file
);
2953 lang_set_flags (ptr
, flags
)
2954 lang_memory_region_type
*ptr
;
2957 flagword
*ptr_flags
= &ptr
->flags
;
2959 ptr
->flags
= ptr
->not_flags
= 0;
2965 ptr_flags
= (ptr_flags
== &ptr
->flags
) ? &ptr
->not_flags
: &ptr
->flags
;
2969 *ptr_flags
|= SEC_ALLOC
;
2973 *ptr_flags
|= SEC_READONLY
;
2977 *ptr_flags
|= SEC_DATA
;
2981 *ptr_flags
|= SEC_CODE
;
2986 *ptr_flags
|= SEC_LOAD
;
2990 einfo ("%P%F: invalid syntax in flags\n");
2997 /* Call a function on each input file. This function will be called
2998 on an archive, but not on the elements. */
3001 lang_for_each_input_file (func
)
3002 void (*func
) PARAMS ((lang_input_statement_type
*));
3004 lang_input_statement_type
*f
;
3006 for (f
= (lang_input_statement_type
*) input_file_chain
.head
;
3008 f
= (lang_input_statement_type
*) f
->next_real_file
)
3012 /* Call a function on each file. The function will be called on all
3013 the elements of an archive which are included in the link, but will
3014 not be called on the archive file itself. */
3017 lang_for_each_file (func
)
3018 void (*func
) PARAMS ((lang_input_statement_type
*));
3020 lang_input_statement_type
*f
;
3022 for (f
= (lang_input_statement_type
*) file_chain
.head
;
3023 f
!= (lang_input_statement_type
*) NULL
;
3024 f
= (lang_input_statement_type
*) f
->next
)
3035 lang_for_each_input_section (func
)
3036 void (*func
) PARAMS ((bfd
* ab
, asection
* as
));
3038 lang_input_statement_type
*f
;
3040 for (f
= (lang_input_statement_type
*) file_chain
.head
;
3041 f
!= (lang_input_statement_type
*) NULL
;
3042 f
= (lang_input_statement_type
*) f
->next
)
3046 for (s
= f
->the_bfd
->sections
;
3047 s
!= (asection
*) NULL
;
3050 func (f
->the_bfd
, s
);
3058 ldlang_add_file (entry
)
3059 lang_input_statement_type
* entry
;
3063 lang_statement_append (&file_chain
,
3064 (lang_statement_union_type
*) entry
,
3067 /* The BFD linker needs to have a list of all input BFDs involved in
3069 ASSERT (entry
->the_bfd
->link_next
== (bfd
*) NULL
);
3070 ASSERT (entry
->the_bfd
!= output_bfd
);
3071 for (pp
= &link_info
.input_bfds
;
3072 *pp
!= (bfd
*) NULL
;
3073 pp
= &(*pp
)->link_next
)
3075 *pp
= entry
->the_bfd
;
3076 entry
->the_bfd
->usrdata
= (PTR
) entry
;
3077 bfd_set_gp_size (entry
->the_bfd
, g_switch_value
);
3079 /* Look through the sections and check for any which should not be
3080 included in the link. We need to do this now, so that we can
3081 notice when the backend linker tries to report multiple
3082 definition errors for symbols which are in sections we aren't
3083 going to link. FIXME: It might be better to entirely ignore
3084 symbols which are defined in sections which are going to be
3085 discarded. This would require modifying the backend linker for
3086 each backend which might set the SEC_LINK_ONCE flag. If we do
3087 this, we should probably handle SEC_EXCLUDE in the same way. */
3089 bfd_map_over_sections (entry
->the_bfd
, section_already_linked
, (PTR
) entry
);
3093 lang_add_output (name
, from_script
)
3097 /* Make -o on command line override OUTPUT in script. */
3098 if (had_output_filename
== false || !from_script
)
3100 output_filename
= name
;
3101 had_output_filename
= true;
3106 static lang_output_section_statement_type
*current_section
;
3118 for (l
= 0; l
< 32; l
++)
3120 if (i
>= (unsigned int) x
)
3129 lang_enter_output_section_statement (output_section_statement_name
,
3130 address_exp
, sectype
, block_value
,
3131 align
, subalign
, ebase
)
3132 const char *output_section_statement_name
;
3133 etree_type
* address_exp
;
3134 enum section_type sectype
;
3135 bfd_vma block_value
;
3137 etree_type
*subalign
;
3140 lang_output_section_statement_type
*os
;
3144 lang_output_section_statement_lookup (output_section_statement_name
);
3148 /* Add this statement to tree */
3149 /* add_statement(lang_output_section_statement_enum,
3150 output_section_statement);*/
3151 /* Make next things chain into subchain of this */
3153 if (os
->addr_tree
==
3154 (etree_type
*) NULL
)
3159 os
->sectype
= sectype
;
3160 if (sectype
!= noload_section
)
3161 os
->flags
= SEC_NO_FLAGS
;
3163 os
->flags
= SEC_NEVER_LOAD
;
3164 os
->block_value
= block_value
? block_value
: 1;
3165 stat_ptr
= &os
->children
;
3167 os
->subsection_alignment
= topower(
3168 exp_get_value_int(subalign
, -1,
3169 "subsection alignment",
3171 os
->section_alignment
= topower(
3172 exp_get_value_int(align
, -1,
3173 "section alignment", 0));
3175 os
->load_base
= ebase
;
3182 lang_output_statement_type
*new =
3183 new_stat (lang_output_statement
, stat_ptr
);
3185 new->name
= output_filename
;
3188 /* Reset the current counters in the regions */
3190 reset_memory_regions ()
3192 lang_memory_region_type
*p
= lang_memory_region_list
;
3194 for (p
= lang_memory_region_list
;
3195 p
!= (lang_memory_region_type
*) NULL
;
3198 p
->old_length
= (bfd_size_type
) (p
->current
- p
->origin
);
3199 p
->current
= p
->origin
;
3206 lang_reasonable_defaults ();
3207 current_target
= default_target
;
3209 lang_for_each_statement (ldlang_open_output
); /* Open the output file */
3211 ldemul_create_output_section_statements ();
3213 /* Add to the hash table all undefineds on the command line */
3214 lang_place_undefineds ();
3216 /* Create a bfd for each input file */
3217 current_target
= default_target
;
3218 open_input_bfds (statement_list
.head
, false);
3220 ldemul_after_open ();
3222 /* Make sure that we're not mixing architectures. We call this
3223 after all the input files have been opened, but before we do any
3224 other processing, so that any operations merge_private_bfd_data
3225 does on the output file will be known during the rest of the
3229 /* Build all sets based on the information gathered from the input
3231 ldctor_build_sets ();
3233 /* Size up the common data */
3236 /* Run through the contours of the script and attach input sections
3237 to the correct output sections
3239 map_input_to_output_sections (statement_list
.head
, (char *) NULL
,
3240 (lang_output_section_statement_type
*) NULL
);
3243 /* Find any sections not attached explicitly and handle them */
3244 lang_place_orphans ();
3246 ldemul_before_allocation ();
3248 /* We must record the program headers before we try to fix the
3249 section positions, since they will affect SIZEOF_HEADERS. */
3250 lang_record_phdrs ();
3252 /* Now run around and relax if we can */
3253 if (command_line
.relax
)
3255 /* First time round is a trial run to get the 'worst case'
3256 addresses of the objects if there was no relaxing. */
3257 lang_size_sections (statement_list
.head
,
3259 &(statement_list
.head
), 0, (bfd_vma
) 0, false);
3261 /* Keep relaxing until bfd_relax_section gives up. */
3264 reset_memory_regions ();
3266 relax_again
= false;
3268 /* Do all the assignments with our current guesses as to
3270 lang_do_assignments (statement_list
.head
,
3272 (fill_type
) 0, (bfd_vma
) 0);
3274 /* Perform another relax pass - this time we know where the
3275 globals are, so can make better guess. */
3276 lang_size_sections (statement_list
.head
,
3278 &(statement_list
.head
), 0, (bfd_vma
) 0, true);
3280 while (relax_again
);
3284 /* Size up the sections. */
3285 lang_size_sections (statement_list
.head
,
3287 &(statement_list
.head
), 0, (bfd_vma
) 0, false);
3290 /* See if anything special should be done now we know how big
3292 ldemul_after_allocation ();
3294 /* Fix any .startof. or .sizeof. symbols. */
3295 lang_set_startof ();
3297 /* Do all the assignments, now that we know the final restingplaces
3298 of all the symbols */
3300 lang_do_assignments (statement_list
.head
,
3302 (fill_type
) 0, (bfd_vma
) 0);
3310 /* EXPORTED TO YACC */
3313 lang_add_wild (section_name
, filename
)
3314 CONST
char *CONST section_name
;
3315 CONST
char *CONST filename
;
3317 lang_wild_statement_type
*new = new_stat (lang_wild_statement
,
3320 if (section_name
!= (char *) NULL
&& strcmp (section_name
, "COMMON") == 0)
3322 placed_commons
= true;
3324 if (filename
!= (char *) NULL
)
3326 lang_has_input_file
= true;
3328 new->section_name
= section_name
;
3329 new->filename
= filename
;
3330 lang_list_init (&new->children
);
3334 lang_section_start (name
, address
)
3336 etree_type
* address
;
3338 lang_address_statement_type
*ad
= new_stat (lang_address_statement
, stat_ptr
);
3340 ad
->section_name
= name
;
3341 ad
->address
= address
;
3344 /* Set the start symbol to NAME. CMDLINE is nonzero if this is called
3345 because of a -e argument on the command line, or zero if this is
3346 called by ENTRY in a linker script. Command line arguments take
3349 /* WINDOWS_NT. When an entry point has been specified, we will also force
3350 this symbol to be defined by calling ldlang_add_undef (equivalent to
3351 having switch -u entry_name on the command line). The reason we do
3352 this is so that the user doesn't have to because they would have to use
3353 the -u switch if they were specifying an entry point other than
3354 _mainCRTStartup. Specifically, if creating a windows application, entry
3355 point _WinMainCRTStartup must be specified.
3356 What I have found for non console applications (entry not _mainCRTStartup)
3357 is that the .obj that contains mainCRTStartup is brought in since it is
3358 the first encountered in libc.lib and it has other symbols in it which will
3359 be pulled in by the link process. To avoid this, adding -u with the entry
3360 point name specified forces the correct .obj to be used. We can avoid
3361 making the user do this by always adding the entry point name as an
3362 undefined symbol. */
3365 lang_add_entry (name
, cmdline
)
3369 if (entry_symbol
== NULL
3371 || ! entry_from_cmdline
)
3373 entry_symbol
= name
;
3374 entry_from_cmdline
= cmdline
;
3377 /* don't do this yet. It seems to work (the executables run), but the
3378 image created is very different from what I was getting before indicating
3379 that something else is being pulled in. When everything else is working,
3380 then try to put this back in to see if it will do the right thing for
3381 other more complicated applications */
3382 ldlang_add_undef (name
);
3387 lang_add_target (name
)
3390 lang_target_statement_type
*new = new_stat (lang_target_statement
,
3406 map_option_f
= true;
3417 lang_fill_statement_type
*new = new_stat (lang_fill_statement
,
3424 lang_add_data (type
, exp
)
3426 union etree_union
*exp
;
3429 lang_data_statement_type
*new = new_stat (lang_data_statement
,
3437 /* Create a new reloc statement. RELOC is the BFD relocation type to
3438 generate. HOWTO is the corresponding howto structure (we could
3439 look this up, but the caller has already done so). SECTION is the
3440 section to generate a reloc against, or NAME is the name of the
3441 symbol to generate a reloc against. Exactly one of SECTION and
3442 NAME must be NULL. ADDEND is an expression for the addend. */
3445 lang_add_reloc (reloc
, howto
, section
, name
, addend
)
3446 bfd_reloc_code_real_type reloc
;
3447 reloc_howto_type
*howto
;
3450 union etree_union
*addend
;
3452 lang_reloc_statement_type
*p
= new_stat (lang_reloc_statement
, stat_ptr
);
3456 p
->section
= section
;
3458 p
->addend_exp
= addend
;
3460 p
->addend_value
= 0;
3461 p
->output_section
= NULL
;
3466 lang_add_assignment (exp
)
3469 lang_assignment_statement_type
*new = new_stat (lang_assignment_statement
,
3476 lang_add_attribute (attribute
)
3477 enum statement_enum attribute
;
3479 new_statement (attribute
, sizeof (lang_statement_union_type
), stat_ptr
);
3486 if (startup_file
!= (char *) NULL
)
3488 einfo ("%P%Fmultiple STARTUP files\n");
3490 first_file
->filename
= name
;
3491 first_file
->local_sym_name
= name
;
3492 first_file
->real
= true;
3494 startup_file
= name
;
3501 lang_float_flag
= maybe
;
3505 lang_leave_output_section_statement (fill
, memspec
, phdrs
)
3507 const char *memspec
;
3508 struct lang_output_section_phdr_list
*phdrs
;
3510 current_section
->fill
= fill
;
3511 current_section
->region
= lang_memory_region_lookup (memspec
);
3512 current_section
->phdrs
= phdrs
;
3513 stat_ptr
= &statement_list
;
3517 Create an absolute symbol with the given name with the value of the
3518 address of first byte of the section named.
3520 If the symbol already exists, then do nothing.
3523 lang_abs_symbol_at_beginning_of (secname
, name
)
3524 const char *secname
;
3527 struct bfd_link_hash_entry
*h
;
3529 h
= bfd_link_hash_lookup (link_info
.hash
, name
, true, true, true);
3530 if (h
== (struct bfd_link_hash_entry
*) NULL
)
3531 einfo ("%P%F: bfd_link_hash_lookup failed: %E\n");
3533 if (h
->type
== bfd_link_hash_new
3534 || h
->type
== bfd_link_hash_undefined
)
3538 h
->type
= bfd_link_hash_defined
;
3540 sec
= bfd_get_section_by_name (output_bfd
, secname
);
3541 if (sec
== (asection
*) NULL
)
3544 h
->u
.def
.value
= bfd_get_section_vma (output_bfd
, sec
);
3546 h
->u
.def
.section
= bfd_abs_section_ptr
;
3551 Create an absolute symbol with the given name with the value of the
3552 address of the first byte after the end of the section named.
3554 If the symbol already exists, then do nothing.
3557 lang_abs_symbol_at_end_of (secname
, name
)
3558 const char *secname
;
3561 struct bfd_link_hash_entry
*h
;
3563 h
= bfd_link_hash_lookup (link_info
.hash
, name
, true, true, true);
3564 if (h
== (struct bfd_link_hash_entry
*) NULL
)
3565 einfo ("%P%F: bfd_link_hash_lookup failed: %E\n");
3567 if (h
->type
== bfd_link_hash_new
3568 || h
->type
== bfd_link_hash_undefined
)
3572 h
->type
= bfd_link_hash_defined
;
3574 sec
= bfd_get_section_by_name (output_bfd
, secname
);
3575 if (sec
== (asection
*) NULL
)
3578 h
->u
.def
.value
= (bfd_get_section_vma (output_bfd
, sec
)
3579 + bfd_section_size (output_bfd
, sec
));
3581 h
->u
.def
.section
= bfd_abs_section_ptr
;
3586 lang_statement_append (list
, element
, field
)
3587 lang_statement_list_type
* list
;
3588 lang_statement_union_type
* element
;
3589 lang_statement_union_type
** field
;
3591 *(list
->tail
) = element
;
3595 /* Set the output format type. -oformat overrides scripts. */
3598 lang_add_output_format (format
, big
, little
, from_script
)
3604 if (output_target
== NULL
|| !from_script
)
3606 if (command_line
.endian
== ENDIAN_BIG
3609 else if (command_line
.endian
== ENDIAN_LITTLE
3613 output_target
= format
;
3617 /* Enter a group. This creates a new lang_group_statement, and sets
3618 stat_ptr to build new statements within the group. */
3623 lang_group_statement_type
*g
;
3625 g
= new_stat (lang_group_statement
, stat_ptr
);
3626 lang_list_init (&g
->children
);
3627 stat_ptr
= &g
->children
;
3630 /* Leave a group. This just resets stat_ptr to start writing to the
3631 regular list of statements again. Note that this will not work if
3632 groups can occur inside anything else which can adjust stat_ptr,
3633 but currently they can't. */
3638 stat_ptr
= &statement_list
;
3641 /* Add a new program header. This is called for each entry in a PHDRS
3642 command in a linker script. */
3645 lang_new_phdr (name
, type
, filehdr
, phdrs
, at
, flags
)
3653 struct lang_phdr
*n
, **pp
;
3655 n
= (struct lang_phdr
*) stat_alloc (sizeof (struct lang_phdr
));
3658 n
->type
= exp_get_value_int (type
, 0, "program header type",
3659 lang_final_phase_enum
);
3660 n
->filehdr
= filehdr
;
3665 for (pp
= &lang_phdr_list
; *pp
!= NULL
; pp
= &(*pp
)->next
)
3670 /* Record the program header information in the output BFD. FIXME: We
3671 should not be calling an ELF specific function here. */
3674 lang_record_phdrs ()
3678 struct lang_output_section_phdr_list
*last
;
3679 struct lang_phdr
*l
;
3680 lang_statement_union_type
*u
;
3683 secs
= (asection
**) xmalloc (alc
* sizeof (asection
*));
3685 for (l
= lang_phdr_list
; l
!= NULL
; l
= l
->next
)
3692 for (u
= lang_output_section_statement
.head
;
3694 u
= u
->output_section_statement
.next
)
3696 lang_output_section_statement_type
*os
;
3697 struct lang_output_section_phdr_list
*pl
;
3699 os
= &u
->output_section_statement
;
3706 if (os
->sectype
== noload_section
3707 || os
->bfd_section
== NULL
3708 || (os
->bfd_section
->flags
& SEC_ALLOC
) == 0)
3713 if (os
->bfd_section
== NULL
)
3716 for (; pl
!= NULL
; pl
= pl
->next
)
3718 if (strcmp (pl
->name
, l
->name
) == 0)
3723 secs
= ((asection
**)
3724 xrealloc (secs
, alc
* sizeof (asection
*)));
3726 secs
[c
] = os
->bfd_section
;
3733 if (l
->flags
== NULL
)
3736 flags
= exp_get_vma (l
->flags
, 0, "phdr flags",
3737 lang_final_phase_enum
);
3742 at
= exp_get_vma (l
->at
, 0, "phdr load address",
3743 lang_final_phase_enum
);
3745 if (! bfd_record_phdr (output_bfd
, l
->type
,
3746 l
->flags
== NULL
? false : true,
3748 l
->at
== NULL
? false : true,
3749 at
, l
->filehdr
, l
->phdrs
, c
, secs
))
3750 einfo ("%F%P: bfd_record_phdr failed: %E\n");
3755 /* Make sure all the phdr assignments succeeded. */
3756 for (u
= lang_output_section_statement
.head
;
3758 u
= u
->output_section_statement
.next
)
3760 struct lang_output_section_phdr_list
*pl
;
3762 if (u
->output_section_statement
.bfd_section
== NULL
)
3765 for (pl
= u
->output_section_statement
.phdrs
;
3768 if (! pl
->used
&& strcmp (pl
->name
, "NONE") != 0)
3769 einfo ("%X%P: section `%s' assigned to non-existent phdr `%s'\n",
3770 u
->output_section_statement
.name
, pl
->name
);
3774 /* Record a list of sections which may not be cross referenced. */
3777 lang_add_nocrossref (l
)
3778 struct lang_nocrossref
*l
;
3780 struct lang_nocrossrefs
*n
;
3782 n
= (struct lang_nocrossrefs
*) xmalloc (sizeof *n
);
3783 n
->next
= nocrossref_list
;
3785 nocrossref_list
= n
;
3787 /* Set notice_all so that we get informed about all symbols. */
3788 link_info
.notice_all
= true;
3791 /* Overlay handling. We handle overlays with some static variables. */
3793 /* The overlay virtual address. */
3794 static etree_type
*overlay_vma
;
3796 /* The overlay load address. */
3797 static etree_type
*overlay_lma
;
3799 /* Whether nocrossrefs is set for this overlay. */
3800 static int overlay_nocrossrefs
;
3802 /* An expression for the maximum section size seen so far. */
3803 static etree_type
*overlay_max
;
3805 /* A list of all the sections in this overlay. */
3809 struct overlay_list
*next
;
3810 lang_output_section_statement_type
*os
;
3813 static struct overlay_list
*overlay_list
;
3815 /* Start handling an overlay. */
3818 lang_enter_overlay (vma_expr
, lma_expr
, nocrossrefs
)
3819 etree_type
*vma_expr
;
3820 etree_type
*lma_expr
;
3823 /* The grammar should prevent nested overlays from occurring. */
3824 ASSERT (overlay_vma
== NULL
3825 && overlay_lma
== NULL
3826 && overlay_list
== NULL
3827 && overlay_max
== NULL
);
3829 overlay_vma
= vma_expr
;
3830 overlay_lma
= lma_expr
;
3831 overlay_nocrossrefs
= nocrossrefs
;
3834 /* Start a section in an overlay. We handle this by calling
3835 lang_enter_output_section_statement with the correct VMA and LMA. */
3838 lang_enter_overlay_section (name
)
3841 struct overlay_list
*n
;
3844 lang_enter_output_section_statement (name
, overlay_vma
, normal_section
,
3845 0, 0, 0, overlay_lma
);
3847 /* If this is the first section, then base the VMA and LMA of future
3848 sections on this one. This will work correctly even if `.' is
3849 used in the addresses. */
3850 if (overlay_list
== NULL
)
3852 overlay_vma
= exp_nameop (ADDR
, name
);
3853 overlay_lma
= exp_nameop (LOADADDR
, name
);
3856 /* Remember the section. */
3857 n
= (struct overlay_list
*) xmalloc (sizeof *n
);
3858 n
->os
= current_section
;
3859 n
->next
= overlay_list
;
3862 size
= exp_nameop (SIZEOF
, name
);
3864 /* Adjust the LMA for the next section. */
3865 overlay_lma
= exp_binop ('+', overlay_lma
, size
);
3867 /* Arrange to work out the maximum section end address. */
3868 if (overlay_max
== NULL
)
3871 overlay_max
= exp_binop (MAX
, overlay_max
, size
);
3874 /* Finish a section in an overlay. There isn't any special to do
3878 lang_leave_overlay_section (fill
, phdrs
)
3880 struct lang_output_section_phdr_list
*phdrs
;
3887 name
= current_section
->name
;
3889 lang_leave_output_section_statement (fill
, "*default*", phdrs
);
3891 /* Define the magic symbols. */
3893 clean
= xmalloc (strlen (name
) + 1);
3895 for (s1
= name
; *s1
!= '\0'; s1
++)
3896 if (isalnum (*s1
) || *s1
== '_')
3900 buf
= xmalloc (strlen (clean
) + sizeof "__load_start_");
3901 sprintf (buf
, "__load_start_%s", clean
);
3902 lang_add_assignment (exp_assop ('=', buf
,
3903 exp_nameop (LOADADDR
, name
)));
3905 buf
= xmalloc (strlen (clean
) + sizeof "__load_stop_");
3906 sprintf (buf
, "__load_stop_%s", clean
);
3907 lang_add_assignment (exp_assop ('=', buf
,
3909 exp_nameop (LOADADDR
, name
),
3910 exp_nameop (SIZEOF
, name
))));
3915 /* Finish an overlay. If there are any overlay wide settings, this
3916 looks through all the sections in the overlay and sets them. */
3919 lang_leave_overlay (fill
, memspec
, phdrs
)
3921 const char *memspec
;
3922 struct lang_output_section_phdr_list
*phdrs
;
3924 lang_memory_region_type
*region
;
3925 struct overlay_list
*l
;
3926 struct lang_nocrossref
*nocrossref
;
3928 if (memspec
== NULL
)
3931 region
= lang_memory_region_lookup (memspec
);
3938 struct overlay_list
*next
;
3940 if (fill
!= 0 && l
->os
->fill
== 0)
3942 if (region
!= NULL
&& l
->os
->region
== NULL
)
3943 l
->os
->region
= region
;
3944 if (phdrs
!= NULL
&& l
->os
->phdrs
== NULL
)
3945 l
->os
->phdrs
= phdrs
;
3947 if (overlay_nocrossrefs
)
3949 struct lang_nocrossref
*nc
;
3951 nc
= (struct lang_nocrossref
*) xmalloc (sizeof *nc
);
3952 nc
->name
= l
->os
->name
;
3953 nc
->next
= nocrossref
;
3962 if (nocrossref
!= NULL
)
3963 lang_add_nocrossref (nocrossref
);
3965 /* Update . for the end of the overlay. */
3966 lang_add_assignment (exp_assop ('=', ".",
3967 exp_binop ('+', overlay_vma
, overlay_max
)));
3971 overlay_nocrossrefs
= 0;
3972 overlay_list
= NULL
;
3976 /* Version handling. This is only useful for ELF. */
3978 /* This global variable holds the version tree that we build. */
3980 struct bfd_elf_version_tree
*lang_elf_version_info
;
3982 /* This is called for each variable name or match expression. */
3984 struct bfd_elf_version_expr
*
3985 lang_new_vers_regex (orig
, new)
3986 struct bfd_elf_version_expr
*orig
;
3989 struct bfd_elf_version_expr
*ret
;
3991 ret
= (struct bfd_elf_version_expr
*) xmalloc (sizeof *ret
);
3997 /* This is called for each set of variable names and match
4000 struct bfd_elf_version_tree
*
4001 lang_new_vers_node (globals
, locals
)
4002 struct bfd_elf_version_expr
*globals
;
4003 struct bfd_elf_version_expr
*locals
;
4005 struct bfd_elf_version_tree
*ret
;
4007 ret
= (struct bfd_elf_version_tree
*) xmalloc (sizeof *ret
);
4011 ret
->globals
= globals
;
4012 ret
->locals
= locals
;
4014 ret
->name_indx
= (unsigned int) -1;
4019 /* This static variable keeps track of version indices. */
4021 static int version_index
;
4023 /* This is called when we know the name and dependencies of the
4027 lang_register_vers_node (name
, version
, deps
)
4029 struct bfd_elf_version_tree
*version
;
4030 struct bfd_elf_version_deps
*deps
;
4032 struct bfd_elf_version_tree
*t
, **pp
;
4033 struct bfd_elf_version_expr
*e1
;
4035 /* Make sure this node has a unique name. */
4036 for (t
= lang_elf_version_info
; t
!= NULL
; t
= t
->next
)
4037 if (strcmp (t
->name
, name
) == 0)
4038 einfo ("%X%P: duplicate version tag `%s'\n", name
);
4040 /* Check the global and local match names, and make sure there
4041 aren't any duplicates. */
4043 for (e1
= version
->globals
; e1
!= NULL
; e1
= e1
->next
)
4045 for (t
= lang_elf_version_info
; t
!= NULL
; t
= t
->next
)
4047 struct bfd_elf_version_expr
*e2
;
4049 for (e2
= t
->locals
; e2
!= NULL
; e2
= e2
->next
)
4050 if (strcmp (e1
->match
, e2
->match
) == 0)
4051 einfo ("%X%P: duplicate expression `%s' in version information\n",
4056 for (e1
= version
->locals
; e1
!= NULL
; e1
= e1
->next
)
4058 for (t
= lang_elf_version_info
; t
!= NULL
; t
= t
->next
)
4060 struct bfd_elf_version_expr
*e2
;
4062 for (e2
= t
->globals
; e2
!= NULL
; e2
= e2
->next
)
4063 if (strcmp (e1
->match
, e2
->match
) == 0)
4064 einfo ("%X%P: duplicate expression `%s' in version information\n",
4069 version
->deps
= deps
;
4070 version
->name
= name
;
4072 version
->vernum
= version_index
;
4074 for (pp
= &lang_elf_version_info
; *pp
!= NULL
; pp
= &(*pp
)->next
)
4079 /* This is called when we see a version dependency. */
4081 struct bfd_elf_version_deps
*
4082 lang_add_vers_depend (list
, name
)
4083 struct bfd_elf_version_deps
*list
;
4086 struct bfd_elf_version_deps
*ret
;
4087 struct bfd_elf_version_tree
*t
;
4089 ret
= (struct bfd_elf_version_deps
*) xmalloc (sizeof *ret
);
4092 for (t
= lang_elf_version_info
; t
!= NULL
; t
= t
->next
)
4094 if (strcmp (t
->name
, name
) == 0)
4096 ret
->version_needed
= t
;
4101 einfo ("%X%P: unable to find version dependency `%s'\n", name
);