1 /* Linker command language support.
2 Copyright (C) 1991, 92, 93, 94, 1995 Free Software Foundation, Inc.
4 This file is part of GLD, the Gnu Linker.
6 GLD is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
11 GLD is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GLD; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #include "libiberty.h"
37 static void print_statements
PARAMS ((void));
38 static void print_statement
PARAMS ((lang_statement_union_type
*,
39 lang_output_section_statement_type
*));
40 static lang_statement_union_type
*new_statement
PARAMS ((enum statement_enum
,
42 lang_statement_list_type
*));
46 static struct obstack stat_obstack
;
48 #define obstack_chunk_alloc xmalloc
49 #define obstack_chunk_free free
50 static CONST
char *startup_file
;
51 static lang_statement_list_type input_file_chain
;
52 static boolean placed_commons
= false;
53 static lang_output_section_statement_type
*default_common_section
;
54 static boolean map_option_f
;
55 static bfd_vma print_dot
;
56 static lang_input_statement_type
*first_file
;
57 static lang_statement_list_type lang_output_section_statement
;
58 static CONST
char *current_target
;
59 static CONST
char *output_target
;
60 static int longest_section_name
= 8;
61 static lang_statement_list_type statement_list
;
63 static void print_size
PARAMS ((size_t value
));
64 static void print_alignment
PARAMS ((unsigned int value
));
65 static void print_fill
PARAMS ((fill_type value
));
66 static void print_section
PARAMS ((const char *name
));
67 static void lang_for_each_statement_worker
68 PARAMS ((void (*func
) (lang_statement_union_type
*),
69 lang_statement_union_type
*s
));
70 static lang_input_statement_type
*new_afile
71 PARAMS ((const char *name
, lang_input_file_enum_type file_type
,
72 const char *target
, boolean add_to_list
));
73 static void print_flags
PARAMS ((int *ignore_flags
));
74 static void init_os
PARAMS ((lang_output_section_statement_type
*s
));
75 static void wild_section
PARAMS ((lang_wild_statement_type
*ptr
,
77 lang_input_statement_type
*file
,
78 lang_output_section_statement_type
*output
));
79 static lang_input_statement_type
*lookup_name
PARAMS ((const char *name
));
80 static void load_symbols
PARAMS ((lang_input_statement_type
*entry
,
81 lang_statement_list_type
*));
82 static void wild
PARAMS ((lang_wild_statement_type
*s
,
83 const char *section
, const char *file
,
85 lang_output_section_statement_type
*output
));
86 static bfd
*open_output
PARAMS ((const char *name
));
87 static void ldlang_open_output
PARAMS ((lang_statement_union_type
*statement
));
88 static void open_input_bfds
89 PARAMS ((lang_statement_union_type
*statement
, boolean
));
90 static void lang_reasonable_defaults
PARAMS ((void));
91 static void lang_place_undefineds
PARAMS ((void));
92 static void map_input_to_output_sections
93 PARAMS ((lang_statement_union_type
*s
,
95 lang_output_section_statement_type
*output_section_statement
));
96 static void print_output_section_statement
97 PARAMS ((lang_output_section_statement_type
*output_section_statement
));
98 static void print_assignment
99 PARAMS ((lang_assignment_statement_type
*assignment
,
100 lang_output_section_statement_type
*output_section
));
101 static void print_input_statement
PARAMS ((lang_input_statement_type
*statm
));
102 static void print_input_section
PARAMS ((lang_input_section_type
*in
));
103 static void print_fill_statement
PARAMS ((lang_fill_statement_type
*fill
));
104 static void print_data_statement
PARAMS ((lang_data_statement_type
*data
));
105 static void print_reloc_statement
PARAMS ((lang_reloc_statement_type
*reloc
));
106 static void print_padding_statement
PARAMS ((lang_padding_statement_type
*s
));
107 static void print_wild_statement
108 PARAMS ((lang_wild_statement_type
*w
,
109 lang_output_section_statement_type
*os
));
110 static void print_group
111 PARAMS ((lang_group_statement_type
*, lang_output_section_statement_type
*));
112 static void print_statement
PARAMS ((lang_statement_union_type
*s
,
113 lang_output_section_statement_type
*os
));
114 static void print_statements
PARAMS ((void));
115 static bfd_vma insert_pad
PARAMS ((lang_statement_union_type
**this_ptr
,
116 fill_type fill
, unsigned int power
,
117 asection
*output_section_statement
,
119 static bfd_vma size_input_section
120 PARAMS ((lang_statement_union_type
**this_ptr
,
121 lang_output_section_statement_type
*output_section_statement
,
122 fill_type fill
, bfd_vma dot
, boolean relax
));
123 static void lang_finish
PARAMS ((void));
124 static void lang_check
PARAMS ((void));
125 static void lang_common
PARAMS ((void));
126 static boolean lang_one_common
PARAMS ((struct bfd_link_hash_entry
*, PTR
));
127 static void lang_place_orphans
PARAMS ((void));
128 static int topower
PARAMS ((int));
129 static void lang_set_startof
PARAMS ((void));
130 static void reset_memory_regions
PARAMS ((void));
133 lang_output_section_statement_type
*abs_output_section
;
134 lang_statement_list_type
*stat_ptr
= &statement_list
;
135 lang_statement_list_type file_chain
= { 0 };
136 static const char *entry_symbol
= 0;
137 boolean lang_has_input_file
= false;
138 boolean had_output_filename
= false;
139 boolean lang_float_flag
= false;
140 boolean delete_output_file_on_failure
= false;
142 etree_type
*base
; /* Relocation base - or null */
145 #if defined(__STDC__) || defined(ALMOST_STDC)
146 #define cat(a,b) a##b
148 #define cat(a,b) a/**/b
151 #define new_stat(x,y) (cat(x,_type)*) new_statement(cat(x,_enum), sizeof(cat(x,_type)),y)
153 #define outside_section_address(q) ( (q)->output_offset + (q)->output_section->vma)
155 #define outside_symbol_address(q) ((q)->value + outside_section_address(q->section))
161 return obstack_alloc (&stat_obstack
, size
);
168 fprintf (config
.map_file
, "%5x", (unsigned) value
);
172 print_alignment (value
)
175 fprintf (config
.map_file
, "2**%1u", value
);
182 fprintf (config
.map_file
, "%04x", (unsigned) value
);
189 fprintf (config
.map_file
, "%*s", -longest_section_name
, name
);
192 /*----------------------------------------------------------------------
193 lang_for_each_statement walks the parse tree and calls the provided
194 function for each node
198 lang_for_each_statement_worker (func
, s
)
199 void (*func
) PARAMS ((lang_statement_union_type
*));
200 lang_statement_union_type
*s
;
202 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
206 switch (s
->header
.type
)
208 case lang_constructors_statement_enum
:
209 lang_for_each_statement_worker (func
, constructor_list
.head
);
211 case lang_output_section_statement_enum
:
212 lang_for_each_statement_worker
214 s
->output_section_statement
.children
.head
);
216 case lang_wild_statement_enum
:
217 lang_for_each_statement_worker
219 s
->wild_statement
.children
.head
);
221 case lang_group_statement_enum
:
222 lang_for_each_statement_worker (func
,
223 s
->group_statement
.children
.head
);
225 case lang_data_statement_enum
:
226 case lang_reloc_statement_enum
:
227 case lang_object_symbols_statement_enum
:
228 case lang_output_statement_enum
:
229 case lang_target_statement_enum
:
230 case lang_input_section_enum
:
231 case lang_input_statement_enum
:
232 case lang_assignment_statement_enum
:
233 case lang_padding_statement_enum
:
234 case lang_address_statement_enum
:
244 lang_for_each_statement (func
)
245 void (*func
) PARAMS ((lang_statement_union_type
*));
247 lang_for_each_statement_worker (func
,
248 statement_list
.head
);
251 /*----------------------------------------------------------------------*/
253 lang_list_init (list
)
254 lang_statement_list_type
*list
;
256 list
->head
= (lang_statement_union_type
*) NULL
;
257 list
->tail
= &list
->head
;
260 /*----------------------------------------------------------------------
262 build a new statement node for the parse tree
267 lang_statement_union_type
*
268 new_statement (type
, size
, list
)
269 enum statement_enum type
;
271 lang_statement_list_type
* list
;
273 lang_statement_union_type
*new = (lang_statement_union_type
*)
276 new->header
.type
= type
;
277 new->header
.next
= (lang_statement_union_type
*) NULL
;
278 lang_statement_append (list
, new, &new->header
.next
);
283 Build a new input file node for the language. There are several ways
284 in which we treat an input file, eg, we only look at symbols, or
285 prefix it with a -l etc.
287 We can be supplied with requests for input files more than once;
288 they may, for example be split over serveral lines like foo.o(.text)
289 foo.o(.data) etc, so when asked for a file we check that we havn't
290 got it already so we don't duplicate the bfd.
293 static lang_input_statement_type
*
294 new_afile (name
, file_type
, target
, add_to_list
)
296 lang_input_file_enum_type file_type
;
300 lang_input_statement_type
*p
;
303 p
= new_stat (lang_input_statement
, stat_ptr
);
306 p
= ((lang_input_statement_type
*)
307 stat_alloc (sizeof (lang_input_statement_type
)));
308 p
->header
.next
= NULL
;
311 lang_has_input_file
= true;
313 p
->complained
= false;
316 case lang_input_file_is_symbols_only_enum
:
318 p
->is_archive
= false;
320 p
->local_sym_name
= name
;
321 p
->just_syms_flag
= true;
322 p
->search_dirs_flag
= false;
324 case lang_input_file_is_fake_enum
:
326 p
->is_archive
= false;
328 p
->local_sym_name
= name
;
329 p
->just_syms_flag
= false;
330 p
->search_dirs_flag
= false;
332 case lang_input_file_is_l_enum
:
333 p
->is_archive
= true;
336 p
->local_sym_name
= concat ("-l", name
, (const char *) NULL
);
337 p
->just_syms_flag
= false;
338 p
->search_dirs_flag
= true;
340 case lang_input_file_is_marker_enum
:
342 p
->is_archive
= false;
344 p
->local_sym_name
= name
;
345 p
->just_syms_flag
= false;
346 p
->search_dirs_flag
= true;
348 case lang_input_file_is_search_file_enum
:
350 p
->is_archive
= false;
352 p
->local_sym_name
= name
;
353 p
->just_syms_flag
= false;
354 p
->search_dirs_flag
= true;
356 case lang_input_file_is_file_enum
:
358 p
->is_archive
= false;
360 p
->local_sym_name
= name
;
361 p
->just_syms_flag
= false;
362 p
->search_dirs_flag
= false;
367 p
->the_bfd
= (bfd
*) NULL
;
368 p
->asymbols
= (asymbol
**) NULL
;
369 p
->next_real_file
= (lang_statement_union_type
*) NULL
;
370 p
->next
= (lang_statement_union_type
*) NULL
;
372 p
->common_output_section
= (asection
*) NULL
;
373 p
->dynamic
= config
.dynamic_link
;
375 lang_statement_append (&input_file_chain
,
376 (lang_statement_union_type
*) p
,
381 lang_input_statement_type
*
382 lang_add_input_file (name
, file_type
, target
)
384 lang_input_file_enum_type file_type
;
387 lang_has_input_file
= true;
388 return new_afile (name
, file_type
, target
, true);
391 /* Build enough state so that the parser can build its tree */
395 obstack_begin (&stat_obstack
, 1000);
397 stat_ptr
= &statement_list
;
399 lang_list_init (stat_ptr
);
401 lang_list_init (&input_file_chain
);
402 lang_list_init (&lang_output_section_statement
);
403 lang_list_init (&file_chain
);
404 first_file
= lang_add_input_file ((char *) NULL
,
405 lang_input_file_is_marker_enum
,
407 abs_output_section
= lang_output_section_statement_lookup (BFD_ABS_SECTION_NAME
);
409 abs_output_section
->bfd_section
= bfd_abs_section_ptr
;
413 /*----------------------------------------------------------------------
414 A region is an area of memory declared with the
415 MEMORY { name:org=exp, len=exp ... }
418 We maintain a list of all the regions here
420 If no regions are specified in the script, then the default is used
421 which is created when looked up to be the entire data space
424 static lang_memory_region_type
*lang_memory_region_list
;
425 static lang_memory_region_type
**lang_memory_region_list_tail
= &lang_memory_region_list
;
427 lang_memory_region_type
*
428 lang_memory_region_lookup (name
)
429 CONST
char *CONST name
;
432 lang_memory_region_type
*p
= lang_memory_region_list
;
434 for (p
= lang_memory_region_list
;
435 p
!= (lang_memory_region_type
*) NULL
;
438 if (strcmp (p
->name
, name
) == 0)
443 if (strcmp (name
, "*default*") == 0)
445 /* This is the default region, dig out first one on the list */
446 if (lang_memory_region_list
!= (lang_memory_region_type
*) NULL
)
448 return lang_memory_region_list
;
452 lang_memory_region_type
*new =
453 (lang_memory_region_type
*) stat_alloc (sizeof (lang_memory_region_type
));
455 new->name
= buystring (name
);
456 new->next
= (lang_memory_region_type
*) NULL
;
458 *lang_memory_region_list_tail
= new;
459 lang_memory_region_list_tail
= &new->next
;
461 new->length
= ~(bfd_size_type
)0;
463 new->had_full_message
= false;
470 lang_output_section_statement_type
*
471 lang_output_section_find (name
)
472 CONST
char *CONST name
;
474 lang_statement_union_type
*u
;
475 lang_output_section_statement_type
*lookup
;
477 for (u
= lang_output_section_statement
.head
;
478 u
!= (lang_statement_union_type
*) NULL
;
481 lookup
= &u
->output_section_statement
;
482 if (strcmp (name
, lookup
->name
) == 0)
487 return (lang_output_section_statement_type
*) NULL
;
490 lang_output_section_statement_type
*
491 lang_output_section_statement_lookup (name
)
492 CONST
char *CONST name
;
494 lang_output_section_statement_type
*lookup
;
496 lookup
= lang_output_section_find (name
);
497 if (lookup
== (lang_output_section_statement_type
*) NULL
)
500 lookup
= (lang_output_section_statement_type
*)
501 new_stat (lang_output_section_statement
, stat_ptr
);
502 lookup
->region
= (lang_memory_region_type
*) NULL
;
504 lookup
->block_value
= 1;
507 lookup
->next
= (lang_statement_union_type
*) NULL
;
508 lookup
->bfd_section
= (asection
*) NULL
;
509 lookup
->processed
= false;
510 lookup
->loadable
= 1;
511 lookup
->addr_tree
= (etree_type
*) NULL
;
512 lang_list_init (&lookup
->children
);
514 lookup
->memspec
= (CONST
char *) NULL
;
516 lookup
->subsection_alignment
= -1;
517 lookup
->section_alignment
= -1;
518 lookup
->load_base
= (union etree_union
*) NULL
;
520 lang_statement_append (&lang_output_section_statement
,
521 (lang_statement_union_type
*) lookup
,
529 print_flags (ignore_flags
)
532 fprintf (config
.map_file
, "(");
534 if (flags
->flag_read
)
535 fprintf (outfile
, "R");
536 if (flags
->flag_write
)
537 fprintf (outfile
, "W");
538 if (flags
->flag_executable
)
539 fprintf (outfile
, "X");
540 if (flags
->flag_loadable
)
541 fprintf (outfile
, "L");
543 fprintf (config
.map_file
, ")");
549 lang_memory_region_type
*m
;
551 fprintf (config
.map_file
, "**MEMORY CONFIGURATION**\n\n");
553 fprintf (config
.map_file
, "name\t\torigin\t\tlength\t\tattributes\n");
555 fprintf (config
.map_file
,
556 "name\t\torigin length r_size c_size is attributes\n");
559 for (m
= lang_memory_region_list
;
560 m
!= (lang_memory_region_type
*) NULL
;
563 fprintf (config
.map_file
, "%-16s", m
->name
);
564 print_address (m
->origin
);
566 print_address ((bfd_vma
)m
->length
);
568 print_address ((bfd_vma
)m
->old_length
);
570 print_address (m
->current
- m
->origin
);
573 fprintf (config
.map_file
, " %2d%% ",
574 (int) ((m
->current
- m
->origin
) * 100 / m
->old_length
));
575 print_flags (&m
->flags
);
576 fprintf (config
.map_file
, "\n");
578 fprintf (config
.map_file
, "\n\n**LINK EDITOR MEMORY MAP**\n\n");
579 fprintf (config
.map_file
, "output input virtual\n");
580 fprintf (config
.map_file
, "section section address tsize\n\n");
591 lang_output_section_statement_type
* s
;
593 /* asection *section = bfd_get_section_by_name(output_bfd, s->name);*/
594 section_userdata_type
*new =
595 (section_userdata_type
*)
596 stat_alloc (sizeof (section_userdata_type
));
598 s
->bfd_section
= bfd_get_section_by_name (output_bfd
, s
->name
);
599 if (s
->bfd_section
== (asection
*) NULL
)
600 s
->bfd_section
= bfd_make_section (output_bfd
, s
->name
);
601 if (s
->bfd_section
== (asection
*) NULL
)
603 einfo ("%P%F: output format %s cannot represent section called %s\n",
604 output_bfd
->xvec
->name
, s
->name
);
606 s
->bfd_section
->output_section
= s
->bfd_section
;
607 /* s->bfd_section->flags = s->flags;*/
609 /* We initialize an output sections output offset to minus its own */
610 /* vma to allow us to output a section through itself */
611 s
->bfd_section
->output_offset
= 0;
612 get_userdata (s
->bfd_section
) = (PTR
) new;
616 /***********************************************************************
619 These expand statements like *(.text) and foo.o to a list of
620 explicit actions, like foo.o(.text), bar.o(.text) and
623 The toplevel routine, wild, takes a statement, section, file and
624 target. If either the section or file is null it is taken to be the
625 wildcard. Seperate lang_input_section statements are created for
626 each part of the expanstion, and placed after the statement provided.
631 wild_doit (ptr
, section
, output
, file
)
632 lang_statement_list_type
* ptr
;
634 lang_output_section_statement_type
* output
;
635 lang_input_statement_type
* file
;
637 if (output
->bfd_section
== (asection
*) NULL
)
640 if (section
!= (asection
*) NULL
641 && section
->output_section
== (asection
*) NULL
)
643 /* Add a section reference to the list */
644 lang_input_section_type
*new = new_stat (lang_input_section
, ptr
);
646 new->section
= section
;
648 section
->output_section
= output
->bfd_section
;
650 /* We don't copy the SEC_NEVER_LOAD flag from an input section to
651 an output section, because we want to be able to include a
652 SEC_NEVER_LOAD section in the middle of an otherwise loaded
653 section (I don't know why we want to do this, but we do).
654 build_link_order in ldwrite.c handles this case by turning the
655 embedded SEC_NEVER_LOAD section into a fill. */
656 section
->output_section
->flags
|=
657 section
->flags
& (flagword
) (~ SEC_NEVER_LOAD
);
659 if (!output
->loadable
)
661 /* Turn off load flag */
662 output
->bfd_section
->flags
&= ~SEC_LOAD
;
663 output
->bfd_section
->flags
|= SEC_NEVER_LOAD
;
665 if (section
->alignment_power
> output
->bfd_section
->alignment_power
)
667 output
->bfd_section
->alignment_power
= section
->alignment_power
;
669 /* If supplied an aligmnet, then force it */
670 if (output
->section_alignment
!= -1)
672 output
->bfd_section
->alignment_power
= output
->section_alignment
;
678 wild_section (ptr
, section
, file
, output
)
679 lang_wild_statement_type
*ptr
;
681 lang_input_statement_type
*file
;
682 lang_output_section_statement_type
*output
;
684 if (file
->just_syms_flag
== false)
686 register asection
*s
;
688 for (s
= file
->the_bfd
->sections
; s
!= NULL
; s
= s
->next
)
690 /* Attach all sections named SECTION. If SECTION is NULL,
691 then attach all sections.
693 Previously, if SECTION was NULL, this code did not call
694 wild_doit if the SEC_IS_COMMON flag was set for the
695 section. I did not understand that, and I took it out.
699 || strcmp (bfd_get_section_name (file
->the_bfd
, s
),
701 wild_doit (&ptr
->children
, s
, output
, file
);
706 /* passed a file name (which must have been seen already and added to
707 the statement tree. We will see if it has been opened already and
708 had its symbols read. If not then we'll read it.
710 Archives are pecuilar here. We may open them once, but if they do
711 not define anything we need at the time, they won't have all their
712 symbols read. If we need them later, we'll have to redo it. */
713 static lang_input_statement_type
*
717 lang_input_statement_type
*search
;
719 for (search
= (lang_input_statement_type
*) input_file_chain
.head
;
720 search
!= (lang_input_statement_type
*) NULL
;
721 search
= (lang_input_statement_type
*) search
->next_real_file
)
723 if (search
->filename
== (char *) NULL
&& name
== (char *) NULL
)
725 if (search
->filename
!= (char *) NULL
726 && name
!= (char *) NULL
727 && strcmp (search
->filename
, name
) == 0)
731 if (search
== (lang_input_statement_type
*) NULL
)
732 search
= new_afile (name
, lang_input_file_is_file_enum
, default_target
,
735 /* If we have already added this file, or this file is not real
736 (FIXME: can that ever actually happen?) or the name is NULL
737 (FIXME: can that ever actually happen?) don't add this file. */
740 || search
->filename
== (const char *) NULL
)
743 load_symbols (search
, (lang_statement_list_type
*) NULL
);
748 /* Get the symbols for an input file. */
751 load_symbols (entry
, place
)
752 lang_input_statement_type
*entry
;
753 lang_statement_list_type
*place
;
760 ldfile_open_file (entry
);
762 if (! bfd_check_format (entry
->the_bfd
, bfd_archive
)
763 && ! bfd_check_format_matches (entry
->the_bfd
, bfd_object
, &matching
))
766 lang_statement_list_type
*hold
;
768 err
= bfd_get_error ();
769 if (err
== bfd_error_file_ambiguously_recognized
)
773 einfo ("%B: file not recognized: %E\n", entry
->the_bfd
);
774 einfo ("%B: matching formats:", entry
->the_bfd
);
775 for (p
= matching
; *p
!= NULL
; p
++)
779 else if (err
!= bfd_error_file_not_recognized
781 einfo ("%F%B: file not recognized: %E\n", entry
->the_bfd
);
783 /* Try to interpret the file as a linker script. */
785 bfd_close (entry
->the_bfd
);
786 entry
->the_bfd
= NULL
;
788 ldfile_open_command_file (entry
->filename
);
793 ldfile_assumed_script
= true;
794 parser_input
= input_script
;
796 ldfile_assumed_script
= false;
803 /* We don't call ldlang_add_file for an archive. Instead, the
804 add_symbols entry point will call ldlang_add_file, via the
805 add_archive_element callback, for each element of the archive
807 switch (bfd_get_format (entry
->the_bfd
))
813 ldlang_add_file (entry
);
814 if (trace_files
|| trace_file_tries
)
815 info_msg ("%I\n", entry
);
821 bfd
*member
= bfd_openr_next_archived_file (entry
->the_bfd
,
823 while (member
!= NULL
)
825 if (! bfd_check_format (member
, bfd_object
))
826 einfo ("%F%B: object %B in archive is not object\n",
827 entry
->the_bfd
, member
);
828 if (! ((*link_info
.callbacks
->add_archive_element
)
829 (&link_info
, member
, "-whole-archive")))
831 if (! bfd_link_add_symbols (member
, &link_info
))
832 einfo ("%F%B: could not read symbols: %E\n", member
);
833 member
= bfd_openr_next_archived_file (entry
->the_bfd
,
837 entry
->loaded
= true;
843 if (! bfd_link_add_symbols (entry
->the_bfd
, &link_info
))
844 einfo ("%F%B: could not read symbols: %E\n", entry
->the_bfd
);
846 entry
->loaded
= true;
850 wild (s
, section
, file
, target
, output
)
851 lang_wild_statement_type
* s
;
855 lang_output_section_statement_type
* output
;
857 lang_input_statement_type
*f
;
859 if (file
== (char *) NULL
)
861 /* Perform the iteration over all files in the list */
862 for (f
= (lang_input_statement_type
*) file_chain
.head
;
863 f
!= (lang_input_statement_type
*) NULL
;
864 f
= (lang_input_statement_type
*) f
->next
)
866 wild_section (s
, section
, f
, output
);
871 /* Perform the iteration over a single file */
872 wild_section (s
, section
, lookup_name (file
), output
);
874 if (section
!= (char *) NULL
875 && strcmp (section
, "COMMON") == 0
876 && default_common_section
== (lang_output_section_statement_type
*) NULL
)
878 /* Remember the section that common is going to incase we later
879 get something which doesn't know where to put it */
880 default_common_section
= output
;
885 read in all the files
894 if (output_target
== (char *) NULL
)
896 if (current_target
!= (char *) NULL
)
897 output_target
= current_target
;
899 output_target
= default_target
;
901 output
= bfd_openw (name
, output_target
);
903 if (output
== (bfd
*) NULL
)
905 if (bfd_get_error () == bfd_error_invalid_target
)
907 einfo ("%P%F: target %s not found\n", output_target
);
909 einfo ("%P%F: cannot open output file %s: %E\n", name
);
912 delete_output_file_on_failure
= 1;
914 /* output->flags |= D_PAGED;*/
916 if (! bfd_set_format (output
, bfd_object
))
917 einfo ("%P%F:%s: can not make object file: %E\n", name
);
918 if (! bfd_set_arch_mach (output
,
919 ldfile_output_architecture
,
920 ldfile_output_machine
))
921 einfo ("%P%F:%s: can not set architecture: %E\n", name
);
923 link_info
.hash
= bfd_link_hash_table_create (output
);
924 if (link_info
.hash
== (struct bfd_link_hash_table
*) NULL
)
925 einfo ("%P%F: can not create link hash table: %E\n");
927 bfd_set_gp_size (output
, g_switch_value
);
935 ldlang_open_output (statement
)
936 lang_statement_union_type
* statement
;
938 switch (statement
->header
.type
)
940 case lang_output_statement_enum
:
941 ASSERT (output_bfd
== (bfd
*) NULL
);
942 output_bfd
= open_output (statement
->output_statement
.name
);
943 ldemul_set_output_arch ();
944 if (config
.magic_demand_paged
&& !link_info
.relocateable
)
945 output_bfd
->flags
|= D_PAGED
;
947 output_bfd
->flags
&= ~D_PAGED
;
948 if (config
.text_read_only
)
949 output_bfd
->flags
|= WP_TEXT
;
951 output_bfd
->flags
&= ~WP_TEXT
;
952 if (config
.traditional_format
)
953 output_bfd
->flags
|= BFD_TRADITIONAL_FORMAT
;
955 output_bfd
->flags
&= ~BFD_TRADITIONAL_FORMAT
;
958 case lang_target_statement_enum
:
959 current_target
= statement
->target_statement
.target
;
966 /* Open all the input files. */
969 open_input_bfds (s
, force
)
970 lang_statement_union_type
*s
;
973 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
975 switch (s
->header
.type
)
977 case lang_constructors_statement_enum
:
978 open_input_bfds (constructor_list
.head
, force
);
980 case lang_output_section_statement_enum
:
981 open_input_bfds (s
->output_section_statement
.children
.head
, force
);
983 case lang_wild_statement_enum
:
984 /* Maybe we should load the file's symbols */
985 if (s
->wild_statement
.filename
)
986 (void) lookup_name (s
->wild_statement
.filename
);
987 open_input_bfds (s
->wild_statement
.children
.head
, force
);
989 case lang_group_statement_enum
:
991 struct bfd_link_hash_entry
*undefs
;
993 /* We must continually search the entries in the group
994 until no new symbols are added to the list of undefined
999 undefs
= link_info
.hash
->undefs_tail
;
1000 open_input_bfds (s
->group_statement
.children
.head
, true);
1002 while (undefs
!= link_info
.hash
->undefs_tail
);
1005 case lang_target_statement_enum
:
1006 current_target
= s
->target_statement
.target
;
1008 case lang_input_statement_enum
:
1009 if (s
->input_statement
.real
== true)
1011 lang_statement_list_type add
;
1013 s
->input_statement
.target
= current_target
;
1015 /* If we are being called from within a group, and this
1016 is an archive which has already been searched, then
1017 force it to be researched. */
1019 && s
->input_statement
.loaded
1020 && bfd_check_format (s
->input_statement
.the_bfd
,
1022 s
->input_statement
.loaded
= false;
1024 lang_list_init (&add
);
1026 load_symbols (&s
->input_statement
, &add
);
1028 if (add
.head
!= NULL
)
1030 *add
.tail
= s
->next
;
1041 /* If there are [COMMONS] statements, put a wild one into the bss section */
1044 lang_reasonable_defaults ()
1047 lang_output_section_statement_lookup (".text");
1048 lang_output_section_statement_lookup (".data");
1050 default_common_section
=
1051 lang_output_section_statement_lookup (".bss");
1054 if (placed_commons
== false)
1056 lang_wild_statement_type
*new =
1057 new_stat (lang_wild_statement
,
1058 &default_common_section
->children
);
1060 new->section_name
= "COMMON";
1061 new->filename
= (char *) NULL
;
1062 lang_list_init (&new->children
);
1069 Add the supplied name to the symbol table as an undefined reference.
1070 Remove items from the chain as we open input bfds
1072 typedef struct ldlang_undef_chain_list
1074 struct ldlang_undef_chain_list
*next
;
1076 } ldlang_undef_chain_list_type
;
1078 static ldlang_undef_chain_list_type
*ldlang_undef_chain_list_head
;
1081 ldlang_add_undef (name
)
1082 CONST
char *CONST name
;
1084 ldlang_undef_chain_list_type
*new =
1085 ((ldlang_undef_chain_list_type
*)
1086 stat_alloc (sizeof (ldlang_undef_chain_list_type
)));
1088 new->next
= ldlang_undef_chain_list_head
;
1089 ldlang_undef_chain_list_head
= new;
1091 new->name
= buystring (name
);
1094 /* Run through the list of undefineds created above and place them
1095 into the linker hash table as undefined symbols belonging to the
1099 lang_place_undefineds ()
1101 ldlang_undef_chain_list_type
*ptr
;
1103 for (ptr
= ldlang_undef_chain_list_head
;
1104 ptr
!= (ldlang_undef_chain_list_type
*) NULL
;
1107 struct bfd_link_hash_entry
*h
;
1109 h
= bfd_link_hash_lookup (link_info
.hash
, ptr
->name
, true, false, true);
1110 if (h
== (struct bfd_link_hash_entry
*) NULL
)
1111 einfo ("%P%F: bfd_link_hash_lookup failed: %E");
1112 if (h
->type
== bfd_link_hash_new
)
1114 h
->type
= bfd_link_hash_undefined
;
1115 h
->u
.undef
.abfd
= NULL
;
1116 bfd_link_add_undef (link_info
.hash
, h
);
1121 /* Open input files and attatch to output sections */
1123 map_input_to_output_sections (s
, target
, output_section_statement
)
1124 lang_statement_union_type
* s
;
1126 lang_output_section_statement_type
* output_section_statement
;
1128 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
1130 switch (s
->header
.type
)
1134 case lang_wild_statement_enum
:
1135 wild (&s
->wild_statement
, s
->wild_statement
.section_name
,
1136 s
->wild_statement
.filename
, target
,
1137 output_section_statement
);
1140 case lang_constructors_statement_enum
:
1141 map_input_to_output_sections (constructor_list
.head
,
1143 output_section_statement
);
1145 case lang_output_section_statement_enum
:
1146 map_input_to_output_sections (s
->output_section_statement
.children
.head
,
1148 &s
->output_section_statement
);
1150 case lang_output_statement_enum
:
1152 case lang_target_statement_enum
:
1153 target
= s
->target_statement
.target
;
1155 case lang_group_statement_enum
:
1156 map_input_to_output_sections (s
->group_statement
.children
.head
,
1158 output_section_statement
);
1160 case lang_fill_statement_enum
:
1161 case lang_input_section_enum
:
1162 case lang_object_symbols_statement_enum
:
1163 case lang_data_statement_enum
:
1164 case lang_reloc_statement_enum
:
1165 case lang_assignment_statement_enum
:
1166 case lang_padding_statement_enum
:
1167 case lang_input_statement_enum
:
1168 if (output_section_statement
!= NULL
1169 && output_section_statement
->bfd_section
== NULL
)
1170 init_os (output_section_statement
);
1172 case lang_afile_asection_pair_statement_enum
:
1175 case lang_address_statement_enum
:
1176 /* Mark the specified section with the supplied address */
1178 lang_output_section_statement_type
*os
=
1179 lang_output_section_statement_lookup
1180 (s
->address_statement
.section_name
);
1182 if (os
->bfd_section
== NULL
)
1184 os
->addr_tree
= s
->address_statement
.address
;
1192 print_output_section_statement (output_section_statement
)
1193 lang_output_section_statement_type
* output_section_statement
;
1195 asection
*section
= output_section_statement
->bfd_section
;
1198 print_section (output_section_statement
->name
);
1203 print_dot
= section
->vma
;
1207 print_address (section
->vma
);
1209 print_size (section
->_raw_size
);
1211 print_size(section
->_cooked_size
);
1213 print_alignment (section
->alignment_power
);
1216 fprintf (config
.map_file
, "%s flags", output_section_statement
->region
->name
);
1217 print_flags (stdout
, &output_section_statement
->flags
);
1219 if (section
->flags
& SEC_LOAD
)
1220 fprintf (config
.map_file
, "load ");
1221 if (section
->flags
& SEC_ALLOC
)
1222 fprintf (config
.map_file
, "alloc ");
1223 if (section
->flags
& SEC_RELOC
)
1224 fprintf (config
.map_file
, "reloc ");
1225 if (section
->flags
& SEC_HAS_CONTENTS
)
1226 fprintf (config
.map_file
, "contents ");
1231 fprintf (config
.map_file
, " (no attached output section)");
1234 if (output_section_statement
->load_base
)
1236 int b
= exp_get_abs_int(output_section_statement
->load_base
,
1237 0, "output base", lang_final_phase_enum
);
1238 fprintf (config
.map_file
, "Output address %08x\n", b
);
1240 if (output_section_statement
->section_alignment
>= 0
1241 || output_section_statement
->subsection_alignment
>= 0)
1243 fprintf (config
.map_file
, "\t\t\t\t\tforced alignment ");
1244 if (output_section_statement
->section_alignment
>= 0)
1246 fprintf (config
.map_file
, "section 2**%d ",output_section_statement
->section_alignment
);
1248 if ( output_section_statement
->subsection_alignment
>= 0)
1250 fprintf (config
.map_file
, "subsection 2**%d ",output_section_statement
->subsection_alignment
);
1255 print_statement (output_section_statement
->children
.head
,
1256 output_section_statement
);
1261 print_assignment (assignment
, output_section
)
1262 lang_assignment_statement_type
* assignment
;
1263 lang_output_section_statement_type
* output_section
;
1265 etree_value_type result
;
1271 print_address (print_dot
);
1273 result
= exp_fold_tree (assignment
->exp
->assign
.src
,
1275 lang_final_phase_enum
,
1281 print_address (result
.value
);
1285 fprintf (config
.map_file
, "*undefined*");
1288 exp_print_tree (assignment
->exp
);
1290 fprintf (config
.map_file
, "\n");
1294 print_input_statement (statm
)
1295 lang_input_statement_type
* statm
;
1297 if (statm
->filename
!= (char *) NULL
)
1299 fprintf (config
.map_file
, "LOAD %s\n", statm
->filename
);
1303 /* Print all the defined symbols for the abfd provided by in the supplied
1308 print_one_symbol (hash_entry
, ptr
)
1309 struct bfd_link_hash_entry
*hash_entry
;
1312 asection
* sec
= (asection
*)ptr
;
1314 if (hash_entry
->type
== bfd_link_hash_defined
1315 || hash_entry
->type
== bfd_link_hash_defweak
)
1317 if (sec
== hash_entry
->u
.def
.section
) {
1319 fprintf (config
.map_file
, " ");
1321 fprintf (config
.map_file
, " ");
1322 print_address (hash_entry
->u
.def
.value
+ outside_section_address (sec
));
1323 fprintf (config
.map_file
, " %s", hash_entry
->root
.string
);
1332 print_input_section (in
)
1333 lang_input_section_type
* in
;
1335 asection
*i
= in
->section
;
1336 bfd_size_type size
= i
->_cooked_size
!= 0 ? i
->_cooked_size
: i
->_raw_size
;
1341 fprintf (config
.map_file
, " ");
1342 print_section (i
->name
);
1343 fprintf (config
.map_file
, " ");
1344 if (i
->output_section
)
1346 print_address (i
->output_section
->vma
+ i
->output_offset
);
1347 fprintf (config
.map_file
, " ");
1348 print_size (i
->_raw_size
);
1349 fprintf (config
.map_file
, " ");
1350 print_size(i
->_cooked_size
);
1351 fprintf (config
.map_file
, " ");
1352 print_alignment (i
->alignment_power
);
1353 fprintf (config
.map_file
, " ");
1357 bfd
*abfd
= in
->ifile
->the_bfd
;
1359 if (in
->ifile
->just_syms_flag
== true)
1361 fprintf (config
.map_file
, "symbols only ");
1364 fprintf (config
.map_file
, " %s ", abfd
->xvec
->name
);
1365 if (abfd
->my_archive
!= (bfd
*) NULL
)
1367 fprintf (config
.map_file
, "[%s]%s", abfd
->my_archive
->filename
,
1372 fprintf (config
.map_file
, "%s", abfd
->filename
);
1374 fprintf (config
.map_file
, "(overhead %d bytes)", (int) bfd_alloc_size (abfd
));
1377 /* Print all the symbols */
1378 bfd_link_hash_traverse (link_info
.hash
, print_one_symbol
, (PTR
) i
);
1386 print_dot
= outside_section_address (i
) + size
;
1390 fprintf (config
.map_file
, "No output section allocated\n");
1396 print_fill_statement (fill
)
1397 lang_fill_statement_type
* fill
;
1399 fprintf (config
.map_file
, "FILL mask ");
1400 print_fill (fill
->fill
);
1404 print_data_statement (data
)
1405 lang_data_statement_type
* data
;
1407 /* bfd_vma value; */
1412 /* ASSERT(print_dot == data->output_vma);*/
1414 print_address (data
->output_vma
+ data
->output_section
->vma
);
1416 print_address (data
->value
);
1421 fprintf (config
.map_file
, "BYTE ");
1422 print_dot
+= BYTE_SIZE
;
1425 fprintf (config
.map_file
, "SHORT ");
1426 print_dot
+= SHORT_SIZE
;
1429 fprintf (config
.map_file
, "LONG ");
1430 print_dot
+= LONG_SIZE
;
1433 fprintf (config
.map_file
, "QUAD ");
1434 print_dot
+= QUAD_SIZE
;
1438 exp_print_tree (data
->exp
);
1440 fprintf (config
.map_file
, "\n");
1443 /* Print a reloc statement. */
1446 print_reloc_statement (reloc
)
1447 lang_reloc_statement_type
*reloc
;
1454 /* ASSERT(print_dot == data->output_vma);*/
1456 print_address (reloc
->output_vma
+ reloc
->output_section
->vma
);
1458 print_address (reloc
->addend_value
);
1461 fprintf (config
.map_file
, "RELOC %s ", reloc
->howto
->name
);
1463 print_dot
+= bfd_get_reloc_size (reloc
->howto
);
1465 exp_print_tree (reloc
->addend_exp
);
1467 fprintf (config
.map_file
, "\n");
1471 print_padding_statement (s
)
1472 lang_padding_statement_type
* s
;
1476 print_section ("*fill*");
1478 print_address (s
->output_offset
+ s
->output_section
->vma
);
1480 print_size (s
->size
);
1482 print_fill (s
->fill
);
1485 print_dot
= s
->output_offset
+ s
->output_section
->vma
+ s
->size
;
1490 print_wild_statement (w
, os
)
1491 lang_wild_statement_type
* w
;
1492 lang_output_section_statement_type
* os
;
1494 fprintf (config
.map_file
, " from ");
1495 if (w
->filename
!= (char *) NULL
)
1497 fprintf (config
.map_file
, "%s", w
->filename
);
1501 fprintf (config
.map_file
, "*");
1503 if (w
->section_name
!= (char *) NULL
)
1505 fprintf (config
.map_file
, "(%s)", w
->section_name
);
1509 fprintf (config
.map_file
, "(*)");
1512 print_statement (w
->children
.head
, os
);
1516 /* Print a group statement. */
1520 lang_group_statement_type
*s
;
1521 lang_output_section_statement_type
*os
;
1523 fprintf (config
.map_file
, "START GROUP\n");
1524 print_statement (s
->children
.head
, os
);
1525 fprintf (config
.map_file
, "END GROUP\n");
1529 print_statement (s
, os
)
1530 lang_statement_union_type
* s
;
1531 lang_output_section_statement_type
* os
;
1535 switch (s
->header
.type
)
1537 case lang_constructors_statement_enum
:
1538 fprintf (config
.map_file
, "constructors:\n");
1539 print_statement (constructor_list
.head
, os
);
1541 case lang_wild_statement_enum
:
1542 print_wild_statement (&s
->wild_statement
, os
);
1545 fprintf (config
.map_file
, "Fail with %d\n", s
->header
.type
);
1548 case lang_address_statement_enum
:
1549 fprintf (config
.map_file
, "address\n");
1551 case lang_object_symbols_statement_enum
:
1552 fprintf (config
.map_file
, "object symbols\n");
1554 case lang_fill_statement_enum
:
1555 print_fill_statement (&s
->fill_statement
);
1557 case lang_data_statement_enum
:
1558 print_data_statement (&s
->data_statement
);
1560 case lang_reloc_statement_enum
:
1561 print_reloc_statement (&s
->reloc_statement
);
1563 case lang_input_section_enum
:
1564 print_input_section (&s
->input_section
);
1566 case lang_padding_statement_enum
:
1567 print_padding_statement (&s
->padding_statement
);
1569 case lang_output_section_statement_enum
:
1570 print_output_section_statement (&s
->output_section_statement
);
1572 case lang_assignment_statement_enum
:
1573 print_assignment (&s
->assignment_statement
,
1576 case lang_target_statement_enum
:
1577 fprintf (config
.map_file
, "TARGET(%s)\n", s
->target_statement
.target
);
1579 case lang_output_statement_enum
:
1580 fprintf (config
.map_file
, "OUTPUT(%s %s)\n",
1581 s
->output_statement
.name
,
1582 output_target
? output_target
: "");
1584 case lang_input_statement_enum
:
1585 print_input_statement (&s
->input_statement
);
1587 case lang_group_statement_enum
:
1588 print_group (&s
->group_statement
, os
);
1590 case lang_afile_asection_pair_statement_enum
:
1602 print_statement (statement_list
.head
,
1603 abs_output_section
);
1608 insert_pad (this_ptr
, fill
, power
, output_section_statement
, dot
)
1609 lang_statement_union_type
** this_ptr
;
1612 asection
* output_section_statement
;
1615 /* Align this section first to the
1616 input sections requirement, then
1617 to the output section's requirement.
1618 If this alignment is > than any seen before,
1619 then record it too. Perform the alignment by
1620 inserting a magic 'padding' statement.
1623 unsigned int alignment_needed
= align_power (dot
, power
) - dot
;
1625 if (alignment_needed
!= 0)
1627 lang_statement_union_type
*new =
1628 ((lang_statement_union_type
*)
1629 stat_alloc (sizeof (lang_padding_statement_type
)));
1631 /* Link into existing chain */
1632 new->header
.next
= *this_ptr
;
1634 new->header
.type
= lang_padding_statement_enum
;
1635 new->padding_statement
.output_section
= output_section_statement
;
1636 new->padding_statement
.output_offset
=
1637 dot
- output_section_statement
->vma
;
1638 new->padding_statement
.fill
= fill
;
1639 new->padding_statement
.size
= alignment_needed
;
1643 /* Remember the most restrictive alignment */
1644 if (power
> output_section_statement
->alignment_power
)
1646 output_section_statement
->alignment_power
= power
;
1648 output_section_statement
->_raw_size
+= alignment_needed
;
1649 return alignment_needed
+ dot
;
1653 /* Work out how much this section will move the dot point */
1655 size_input_section (this_ptr
, output_section_statement
, fill
, dot
, relax
)
1656 lang_statement_union_type
** this_ptr
;
1657 lang_output_section_statement_type
* output_section_statement
;
1662 lang_input_section_type
*is
= &((*this_ptr
)->input_section
);
1663 asection
*i
= is
->section
;
1665 if (is
->ifile
->just_syms_flag
== false)
1667 if (output_section_statement
->subsection_alignment
!= -1)
1668 i
->alignment_power
=
1669 output_section_statement
->subsection_alignment
;
1671 dot
= insert_pad (this_ptr
, fill
, i
->alignment_power
,
1672 output_section_statement
->bfd_section
, dot
);
1674 /* Remember where in the output section this input section goes */
1676 i
->output_offset
= dot
- output_section_statement
->bfd_section
->vma
;
1678 /* Mark how big the output section must be to contain this now
1680 if (i
->_cooked_size
!= 0)
1681 dot
+= i
->_cooked_size
;
1683 dot
+= i
->_raw_size
;
1684 output_section_statement
->bfd_section
->_raw_size
= dot
- output_section_statement
->bfd_section
->vma
;
1688 i
->output_offset
= i
->vma
- output_section_statement
->bfd_section
->vma
;
1694 /* This variable indicates whether bfd_relax_section should be called
1697 static boolean relax_again
;
1699 /* Set the sizes for all the output sections. */
1702 lang_size_sections (s
, output_section_statement
, prev
, fill
, dot
, relax
)
1703 lang_statement_union_type
* s
;
1704 lang_output_section_statement_type
* output_section_statement
;
1705 lang_statement_union_type
** prev
;
1710 /* Size up the sections from their constituent parts */
1711 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
1713 switch (s
->header
.type
)
1716 case lang_output_section_statement_enum
:
1719 lang_output_section_statement_type
*os
= &s
->output_section_statement
;
1721 if (os
->bfd_section
== NULL
)
1723 /* This section was never actually created. */
1727 /* If this is a COFF shared library section, use the size and
1728 address from the input section. FIXME: This is COFF
1729 specific; it would be cleaner if there were some other way
1730 to do this, but nothing simple comes to mind. */
1731 if ((os
->bfd_section
->flags
& SEC_COFF_SHARED_LIBRARY
) != 0)
1735 if (os
->children
.head
== NULL
1736 || os
->children
.head
->next
!= NULL
1737 || os
->children
.head
->header
.type
!= lang_input_section_enum
)
1738 einfo ("%P%X: Internal error on COFF shared library section %s",
1741 input
= os
->children
.head
->input_section
.section
;
1742 bfd_set_section_vma (os
->bfd_section
->owner
,
1744 bfd_section_vma (input
->owner
, input
));
1745 os
->bfd_section
->_raw_size
= input
->_raw_size
;
1749 if (bfd_is_abs_section (os
->bfd_section
))
1751 /* No matter what happens, an abs section starts at zero */
1752 ASSERT (os
->bfd_section
->vma
== 0);
1756 if (os
->addr_tree
== (etree_type
*) NULL
)
1758 /* No address specified for this section, get one
1759 from the region specification
1761 if (os
->region
== (lang_memory_region_type
*) NULL
)
1763 os
->region
= lang_memory_region_lookup ("*default*");
1765 dot
= os
->region
->current
;
1766 if (os
->section_alignment
== -1)
1767 dot
= align_power (dot
, os
->bfd_section
->alignment_power
);
1773 r
= exp_fold_tree (os
->addr_tree
,
1775 lang_allocating_phase_enum
,
1777 if (r
.valid
== false)
1779 einfo ("%F%S: non constant address expression for section %s\n",
1784 /* The section starts here */
1785 /* First, align to what the section needs */
1787 if (os
->section_alignment
!= -1)
1788 dot
= align_power (dot
, os
->section_alignment
);
1790 bfd_set_section_vma (0, os
->bfd_section
, dot
);
1792 os
->bfd_section
->output_offset
= 0;
1795 (void) lang_size_sections (os
->children
.head
, os
, &os
->children
.head
,
1796 os
->fill
, dot
, relax
);
1797 /* Ignore the size of the input sections, use the vma and size to */
1800 after
= ALIGN_N (os
->bfd_section
->vma
+
1801 os
->bfd_section
->_raw_size
,
1802 /* The coercion here is important, see ld.h. */
1803 (bfd_vma
) os
->block_value
);
1805 if (bfd_is_abs_section (os
->bfd_section
))
1806 ASSERT (after
== os
->bfd_section
->vma
);
1808 os
->bfd_section
->_raw_size
= after
- os
->bfd_section
->vma
;
1809 dot
= os
->bfd_section
->vma
+ os
->bfd_section
->_raw_size
;
1810 os
->processed
= true;
1812 /* Replace into region ? */
1813 if (os
->region
!= (lang_memory_region_type
*) NULL
)
1815 os
->region
->current
= dot
;
1816 /* Make sure this isn't silly. */
1817 if ((os
->region
->current
< os
->region
->origin
)
1818 || (os
->region
->current
1819 > os
->region
->origin
+ os
->region
->length
))
1821 if (os
->addr_tree
!= (etree_type
*) NULL
)
1823 einfo ("%X%P: address 0x%v of %B section %s is not within region %s\n",
1824 os
->region
->current
,
1825 os
->bfd_section
->owner
,
1826 os
->bfd_section
->name
,
1831 einfo ("%X%P: region %s is full (%B section %s)\n",
1833 os
->bfd_section
->owner
,
1834 os
->bfd_section
->name
);
1836 /* Reset the region pointer. */
1837 os
->region
->current
= os
->region
->origin
;
1843 case lang_constructors_statement_enum
:
1844 dot
= lang_size_sections (constructor_list
.head
,
1845 output_section_statement
,
1846 &s
->wild_statement
.children
.head
,
1851 case lang_data_statement_enum
:
1853 unsigned int size
= 0;
1855 s
->data_statement
.output_vma
= dot
- output_section_statement
->bfd_section
->vma
;
1856 s
->data_statement
.output_section
=
1857 output_section_statement
->bfd_section
;
1859 switch (s
->data_statement
.type
)
1876 output_section_statement
->bfd_section
->_raw_size
+= size
;
1877 output_section_statement
->bfd_section
->flags
|= SEC_HAS_CONTENTS
;
1881 case lang_reloc_statement_enum
:
1885 s
->reloc_statement
.output_vma
=
1886 dot
- output_section_statement
->bfd_section
->vma
;
1887 s
->reloc_statement
.output_section
=
1888 output_section_statement
->bfd_section
;
1889 size
= bfd_get_reloc_size (s
->reloc_statement
.howto
);
1891 output_section_statement
->bfd_section
->_raw_size
+= size
;
1895 case lang_wild_statement_enum
:
1897 dot
= lang_size_sections (s
->wild_statement
.children
.head
,
1898 output_section_statement
,
1899 &s
->wild_statement
.children
.head
,
1905 case lang_object_symbols_statement_enum
:
1906 link_info
.create_object_symbols_section
=
1907 output_section_statement
->bfd_section
;
1909 case lang_output_statement_enum
:
1910 case lang_target_statement_enum
:
1912 case lang_input_section_enum
:
1916 i
= (*prev
)->input_section
.section
;
1918 i
->_cooked_size
= i
->_raw_size
;
1923 if (! bfd_relax_section (i
->owner
, i
, &link_info
, &again
))
1924 einfo ("%P%F: can't relax section: %E\n");
1928 dot
= size_input_section (prev
,
1929 output_section_statement
,
1930 output_section_statement
->fill
,
1934 case lang_input_statement_enum
:
1936 case lang_fill_statement_enum
:
1937 s
->fill_statement
.output_section
= output_section_statement
->bfd_section
;
1939 fill
= s
->fill_statement
.fill
;
1941 case lang_assignment_statement_enum
:
1943 bfd_vma newdot
= dot
;
1945 exp_fold_tree (s
->assignment_statement
.exp
,
1946 output_section_statement
,
1947 lang_allocating_phase_enum
,
1951 if (newdot
!= dot
&& !relax
)
1953 /* The assignment changed dot. Insert a pad. */
1954 if (output_section_statement
== abs_output_section
)
1956 /* If we don't have an output section, then just adjust
1957 the default memory address. */
1958 lang_memory_region_lookup ("*default*")->current
= newdot
;
1962 lang_statement_union_type
*new =
1963 ((lang_statement_union_type
*)
1964 stat_alloc (sizeof (lang_padding_statement_type
)));
1966 /* Link into existing chain */
1967 new->header
.next
= *prev
;
1969 new->header
.type
= lang_padding_statement_enum
;
1970 new->padding_statement
.output_section
=
1971 output_section_statement
->bfd_section
;
1972 new->padding_statement
.output_offset
=
1973 dot
- output_section_statement
->bfd_section
->vma
;
1974 new->padding_statement
.fill
= fill
;
1975 new->padding_statement
.size
= newdot
- dot
;
1976 output_section_statement
->bfd_section
->_raw_size
+=
1977 new->padding_statement
.size
;
1985 case lang_padding_statement_enum
:
1986 /* If we are relaxing, and this is not the first pass, some
1987 padding statements may have been inserted during previous
1988 passes. We may have to move the padding statement to a new
1989 location if dot has a different value at this point in this
1990 pass than it did at this point in the previous pass. */
1991 s
->padding_statement
.output_offset
=
1992 dot
- output_section_statement
->bfd_section
->vma
;
1993 dot
+= s
->padding_statement
.size
;
1996 case lang_group_statement_enum
:
1997 dot
= lang_size_sections (s
->group_statement
.children
.head
,
1998 output_section_statement
,
1999 &s
->group_statement
.children
.head
,
2007 /* This can only get here when relaxing is turned on */
2009 case lang_address_statement_enum
:
2012 prev
= &s
->header
.next
;
2018 lang_do_assignments (s
, output_section_statement
, fill
, dot
)
2019 lang_statement_union_type
* s
;
2020 lang_output_section_statement_type
* output_section_statement
;
2024 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
2026 switch (s
->header
.type
)
2028 case lang_constructors_statement_enum
:
2029 dot
= lang_do_assignments (constructor_list
.head
,
2030 output_section_statement
,
2035 case lang_output_section_statement_enum
:
2037 lang_output_section_statement_type
*os
=
2038 &(s
->output_section_statement
);
2040 if (os
->bfd_section
!= NULL
)
2042 dot
= os
->bfd_section
->vma
;
2043 (void) lang_do_assignments (os
->children
.head
, os
,
2045 dot
= os
->bfd_section
->vma
+ os
->bfd_section
->_raw_size
;
2049 /* If nothing has been placed into the output section then
2050 it won't have a bfd_section. */
2051 if (os
->bfd_section
)
2053 os
->bfd_section
->lma
2054 = exp_get_abs_int(os
->load_base
, 0,"load base", lang_final_phase_enum
);
2059 case lang_wild_statement_enum
:
2061 dot
= lang_do_assignments (s
->wild_statement
.children
.head
,
2062 output_section_statement
,
2067 case lang_object_symbols_statement_enum
:
2068 case lang_output_statement_enum
:
2069 case lang_target_statement_enum
:
2071 case lang_common_statement_enum
:
2074 case lang_data_statement_enum
:
2076 etree_value_type value
;
2078 value
= exp_fold_tree (s
->data_statement
.exp
,
2080 lang_final_phase_enum
, dot
, &dot
);
2081 s
->data_statement
.value
= value
.value
;
2082 if (value
.valid
== false)
2083 einfo ("%F%P: invalid data statement\n");
2085 switch (s
->data_statement
.type
)
2102 case lang_reloc_statement_enum
:
2104 etree_value_type value
;
2106 value
= exp_fold_tree (s
->reloc_statement
.addend_exp
,
2108 lang_final_phase_enum
, dot
, &dot
);
2109 s
->reloc_statement
.addend_value
= value
.value
;
2110 if (value
.valid
== false)
2111 einfo ("%F%P: invalid reloc statement\n");
2113 dot
+= bfd_get_reloc_size (s
->reloc_statement
.howto
);
2116 case lang_input_section_enum
:
2118 asection
*in
= s
->input_section
.section
;
2120 if (in
->_cooked_size
!= 0)
2121 dot
+= in
->_cooked_size
;
2123 dot
+= in
->_raw_size
;
2127 case lang_input_statement_enum
:
2129 case lang_fill_statement_enum
:
2130 fill
= s
->fill_statement
.fill
;
2132 case lang_assignment_statement_enum
:
2134 exp_fold_tree (s
->assignment_statement
.exp
,
2135 output_section_statement
,
2136 lang_final_phase_enum
,
2142 case lang_padding_statement_enum
:
2143 dot
+= s
->padding_statement
.size
;
2146 case lang_group_statement_enum
:
2147 dot
= lang_do_assignments (s
->group_statement
.children
.head
,
2148 output_section_statement
,
2156 case lang_address_statement_enum
:
2164 /* Fix any .startof. or .sizeof. symbols. When the assemblers see the
2165 operator .startof. (section_name), it produces an undefined symbol
2166 .startof.section_name. Similarly, when it sees
2167 .sizeof. (section_name), it produces an undefined symbol
2168 .sizeof.section_name. For all the output sections, we look for
2169 such symbols, and set them to the correct value. */
2176 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
2178 const char *secname
;
2180 struct bfd_link_hash_entry
*h
;
2182 secname
= bfd_get_section_name (output_bfd
, s
);
2183 buf
= xmalloc (10 + strlen (secname
));
2185 sprintf (buf
, ".startof.%s", secname
);
2186 h
= bfd_link_hash_lookup (link_info
.hash
, buf
, false, false, true);
2187 if (h
!= NULL
&& h
->type
== bfd_link_hash_undefined
)
2189 h
->type
= bfd_link_hash_defined
;
2190 h
->u
.def
.value
= bfd_get_section_vma (output_bfd
, s
);
2191 h
->u
.def
.section
= bfd_abs_section_ptr
;
2194 sprintf (buf
, ".sizeof.%s", secname
);
2195 h
= bfd_link_hash_lookup (link_info
.hash
, buf
, false, false, true);
2196 if (h
!= NULL
&& h
->type
== bfd_link_hash_undefined
)
2198 h
->type
= bfd_link_hash_defined
;
2199 if (s
->_cooked_size
!= 0)
2200 h
->u
.def
.value
= s
->_cooked_size
;
2202 h
->u
.def
.value
= s
->_raw_size
;
2203 h
->u
.def
.section
= bfd_abs_section_ptr
;
2213 struct bfd_link_hash_entry
*h
;
2216 if (link_info
.relocateable
|| link_info
.shared
)
2221 if (entry_symbol
== (char *) NULL
)
2223 /* No entry has been specified. Look for start, but don't warn
2224 if we don't find it. */
2225 entry_symbol
= "start";
2229 h
= bfd_link_hash_lookup (link_info
.hash
, entry_symbol
, false, false, true);
2230 if (h
!= (struct bfd_link_hash_entry
*) NULL
2231 && (h
->type
== bfd_link_hash_defined
2232 || h
->type
== bfd_link_hash_defweak
))
2236 val
= (h
->u
.def
.value
2237 + bfd_get_section_vma (output_bfd
,
2238 h
->u
.def
.section
->output_section
)
2239 + h
->u
.def
.section
->output_offset
);
2240 if (! bfd_set_start_address (output_bfd
, val
))
2241 einfo ("%P%F:%s: can't set start address\n", entry_symbol
);
2247 /* Can't find the entry symbol. Use the first address in the
2249 ts
= bfd_get_section_by_name (output_bfd
, ".text");
2250 if (ts
!= (asection
*) NULL
)
2253 einfo ("%P: warning: cannot find entry symbol %s; defaulting to %V\n",
2254 entry_symbol
, bfd_get_section_vma (output_bfd
, ts
));
2255 if (! bfd_set_start_address (output_bfd
,
2256 bfd_get_section_vma (output_bfd
, ts
)))
2257 einfo ("%P%F: can't set start address\n");
2262 einfo ("%P: warning: cannot find entry symbol %s; not setting start address\n",
2268 /* Check that the architecture of all the input files is compatible
2269 with the output file. Also call the backend to let it do any
2270 other checking that is needed. */
2275 lang_statement_union_type
*file
;
2277 CONST bfd_arch_info_type
*compatible
;
2279 for (file
= file_chain
.head
;
2280 file
!= (lang_statement_union_type
*) NULL
;
2281 file
= file
->input_statement
.next
)
2283 input_bfd
= file
->input_statement
.the_bfd
;
2284 compatible
= bfd_arch_get_compatible (input_bfd
,
2286 if (compatible
== NULL
)
2287 einfo ("%P: warning: %s architecture of input file `%B' is incompatible with %s output\n",
2288 bfd_printable_name (input_bfd
), input_bfd
,
2289 bfd_printable_name (output_bfd
));
2292 bfd_merge_private_bfd_data (input_bfd
, output_bfd
);
2296 /* Look through all the global common symbols and attach them to the
2297 correct section. The -sort-common command line switch may be used
2298 to roughly sort the entries by size. */
2303 if (link_info
.relocateable
2304 && ! command_line
.force_common_definition
)
2307 if (! config
.sort_common
)
2308 bfd_link_hash_traverse (link_info
.hash
, lang_one_common
, (PTR
) NULL
);
2313 for (power
= 4; power
>= 0; power
--)
2314 bfd_link_hash_traverse (link_info
.hash
, lang_one_common
,
2319 /* Place one common symbol in the correct section. */
2322 lang_one_common (h
, info
)
2323 struct bfd_link_hash_entry
*h
;
2326 unsigned int power_of_two
;
2330 if (h
->type
!= bfd_link_hash_common
)
2334 power_of_two
= h
->u
.c
.p
->alignment_power
;
2336 if (config
.sort_common
2337 && power_of_two
< *(int *) info
)
2340 section
= h
->u
.c
.p
->section
;
2342 /* Increase the size of the section. */
2343 section
->_raw_size
= ALIGN_N (section
->_raw_size
,
2344 (bfd_size_type
) (1 << power_of_two
));
2346 /* Adjust the alignment if necessary. */
2347 if (power_of_two
> section
->alignment_power
)
2348 section
->alignment_power
= power_of_two
;
2350 /* Change the symbol from common to defined. */
2351 h
->type
= bfd_link_hash_defined
;
2352 h
->u
.def
.section
= section
;
2353 h
->u
.def
.value
= section
->_raw_size
;
2355 /* Increase the size of the section. */
2356 section
->_raw_size
+= size
;
2358 /* Make sure the section is allocated in memory. */
2359 section
->flags
|= SEC_ALLOC
;
2361 if (config
.map_file
!= NULL
)
2362 fprintf (config
.map_file
, "Allocating common %s: %lx at %lx %s\n",
2363 h
->root
.string
, (unsigned long) size
,
2364 (unsigned long) h
->u
.def
.value
, section
->owner
->filename
);
2370 run through the input files and ensure that every input
2371 section has somewhere to go. If one is found without
2372 a destination then create an input request and place it
2373 into the statement tree.
2377 lang_place_orphans ()
2379 lang_input_statement_type
*file
;
2381 for (file
= (lang_input_statement_type
*) file_chain
.head
;
2382 file
!= (lang_input_statement_type
*) NULL
;
2383 file
= (lang_input_statement_type
*) file
->next
)
2387 for (s
= file
->the_bfd
->sections
;
2388 s
!= (asection
*) NULL
;
2391 if (s
->output_section
== (asection
*) NULL
)
2393 /* This section of the file is not attatched, root
2394 around for a sensible place for it to go */
2396 if (file
->just_syms_flag
)
2398 /* We are only retrieving symbol values from this
2399 file. We want the symbols to act as though the
2400 values in the file are absolute. */
2401 s
->output_section
= bfd_abs_section_ptr
;
2402 s
->output_offset
= s
->vma
;
2404 else if (file
->common_section
== s
)
2406 /* This is a lonely common section which must
2407 have come from an archive. We attatch to the
2408 section with the wildcard */
2409 if (! link_info
.relocateable
2410 && ! command_line
.force_common_definition
)
2412 if (default_common_section
==
2413 (lang_output_section_statement_type
*) NULL
)
2415 info_msg ("%P: no [COMMON] command, defaulting to .bss\n");
2417 default_common_section
=
2418 lang_output_section_statement_lookup (".bss");
2421 wild_doit (&default_common_section
->children
, s
,
2422 default_common_section
, file
);
2425 else if (ldemul_place_orphan (file
, s
))
2429 lang_output_section_statement_type
*os
=
2430 lang_output_section_statement_lookup (s
->name
);
2432 wild_doit (&os
->children
, s
, os
, file
);
2441 lang_set_flags (ptr
, flags
)
2445 boolean state
= false;
2460 /* ptr->flag_read = state; */
2463 /* ptr->flag_write = state; */
2466 /* ptr->flag_executable= state;*/
2470 /* ptr->flag_loadable= state;*/
2473 einfo ("%P%F: invalid syntax in flags\n");
2480 /* Call a function on each input file. This function will be called
2481 on an archive, but not on the elements. */
2484 lang_for_each_input_file (func
)
2485 void (*func
) PARAMS ((lang_input_statement_type
*));
2487 lang_input_statement_type
*f
;
2489 for (f
= (lang_input_statement_type
*) input_file_chain
.head
;
2491 f
= (lang_input_statement_type
*) f
->next_real_file
)
2495 /* Call a function on each file. The function will be called on all
2496 the elements of an archive which are included in the link, but will
2497 not be called on the archive file itself. */
2500 lang_for_each_file (func
)
2501 void (*func
) PARAMS ((lang_input_statement_type
*));
2503 lang_input_statement_type
*f
;
2505 for (f
= (lang_input_statement_type
*) file_chain
.head
;
2506 f
!= (lang_input_statement_type
*) NULL
;
2507 f
= (lang_input_statement_type
*) f
->next
)
2518 lang_for_each_input_section (func
)
2519 void (*func
) PARAMS ((bfd
* ab
, asection
* as
));
2521 lang_input_statement_type
*f
;
2523 for (f
= (lang_input_statement_type
*) file_chain
.head
;
2524 f
!= (lang_input_statement_type
*) NULL
;
2525 f
= (lang_input_statement_type
*) f
->next
)
2529 for (s
= f
->the_bfd
->sections
;
2530 s
!= (asection
*) NULL
;
2533 func (f
->the_bfd
, s
);
2541 ldlang_add_file (entry
)
2542 lang_input_statement_type
* entry
;
2546 lang_statement_append (&file_chain
,
2547 (lang_statement_union_type
*) entry
,
2550 /* The BFD linker needs to have a list of all input BFDs involved in
2552 ASSERT (entry
->the_bfd
->link_next
== (bfd
*) NULL
);
2553 ASSERT (entry
->the_bfd
!= output_bfd
);
2554 for (pp
= &link_info
.input_bfds
;
2555 *pp
!= (bfd
*) NULL
;
2556 pp
= &(*pp
)->link_next
)
2558 *pp
= entry
->the_bfd
;
2559 entry
->the_bfd
->usrdata
= (PTR
) entry
;
2560 bfd_set_gp_size (entry
->the_bfd
, g_switch_value
);
2564 lang_add_output (name
, from_script
)
2568 /* Make -o on command line override OUTPUT in script. */
2569 if (had_output_filename
== false || !from_script
)
2571 output_filename
= name
;
2572 had_output_filename
= true;
2577 static lang_output_section_statement_type
*current_section
;
2579 static int topower(x
)
2584 if (x
< 0) return -1;
2585 for (l
= 0; l
< 32; l
++)
2587 if (i
>= x
) return l
;
2593 lang_enter_output_section_statement (output_section_statement_name
,
2594 address_exp
, flags
, block_value
,
2595 align
, subalign
, ebase
)
2596 const char *output_section_statement_name
;
2597 etree_type
* address_exp
;
2599 bfd_vma block_value
;
2601 etree_type
*subalign
;
2604 lang_output_section_statement_type
*os
;
2608 lang_output_section_statement_lookup (output_section_statement_name
);
2612 /* Add this statement to tree */
2613 /* add_statement(lang_output_section_statement_enum,
2614 output_section_statement);*/
2615 /* Make next things chain into subchain of this */
2617 if (os
->addr_tree
==
2618 (etree_type
*) NULL
)
2624 if (flags
& SEC_NEVER_LOAD
)
2628 os
->block_value
= block_value
? block_value
: 1;
2629 stat_ptr
= &os
->children
;
2631 os
->subsection_alignment
= topower(
2632 exp_get_value_int(subalign
, -1,
2633 "subsection alignment",
2635 os
->section_alignment
= topower(
2636 exp_get_value_int(align
, -1,
2637 "section alignment", 0));
2639 os
->load_base
= ebase
;
2646 lang_output_statement_type
*new =
2647 new_stat (lang_output_statement
, stat_ptr
);
2649 new->name
= output_filename
;
2652 /* Reset the current counters in the regions */
2654 reset_memory_regions ()
2656 lang_memory_region_type
*p
= lang_memory_region_list
;
2658 for (p
= lang_memory_region_list
;
2659 p
!= (lang_memory_region_type
*) NULL
;
2662 p
->old_length
= (bfd_size_type
) (p
->current
- p
->origin
);
2663 p
->current
= p
->origin
;
2670 lang_reasonable_defaults ();
2671 current_target
= default_target
;
2673 lang_for_each_statement (ldlang_open_output
); /* Open the output file */
2675 ldemul_create_output_section_statements ();
2677 /* Add to the hash table all undefineds on the command line */
2678 lang_place_undefineds ();
2680 /* Create a bfd for each input file */
2681 current_target
= default_target
;
2682 open_input_bfds (statement_list
.head
, false);
2684 ldemul_after_open ();
2686 /* Build all sets based on the information gathered from the input
2688 ldctor_build_sets ();
2690 /* Size up the common data */
2693 /* Run through the contours of the script and attatch input sections
2694 to the correct output sections
2696 map_input_to_output_sections (statement_list
.head
, (char *) NULL
,
2697 (lang_output_section_statement_type
*) NULL
);
2700 /* Find any sections not attatched explicitly and handle them */
2701 lang_place_orphans ();
2703 ldemul_before_allocation ();
2705 /* Now run around and relax if we can */
2706 if (command_line
.relax
)
2708 /* First time round is a trial run to get the 'worst case'
2709 addresses of the objects if there was no relaxing. */
2710 lang_size_sections (statement_list
.head
,
2712 &(statement_list
.head
), 0, (bfd_vma
) 0, false);
2714 /* Keep relaxing until bfd_relax_section gives up. */
2717 reset_memory_regions ();
2719 relax_again
= false;
2721 /* Do all the assignments with our current guesses as to
2723 lang_do_assignments (statement_list
.head
,
2725 (fill_type
) 0, (bfd_vma
) 0);
2727 /* Perform another relax pass - this time we know where the
2728 globals are, so can make better guess. */
2729 lang_size_sections (statement_list
.head
,
2731 &(statement_list
.head
), 0, (bfd_vma
) 0, true);
2733 while (relax_again
);
2737 /* Size up the sections. */
2738 lang_size_sections (statement_list
.head
,
2740 &(statement_list
.head
), 0, (bfd_vma
) 0, false);
2743 /* See if anything special should be done now we know how big
2745 ldemul_after_allocation ();
2747 /* Fix any .startof. or .sizeof. symbols. */
2748 lang_set_startof ();
2750 /* Do all the assignments, now that we know the final restingplaces
2751 of all the symbols */
2753 lang_do_assignments (statement_list
.head
,
2755 (fill_type
) 0, (bfd_vma
) 0);
2757 /* Make sure that we're not mixing architectures */
2767 /* EXPORTED TO YACC */
2770 lang_add_wild (section_name
, filename
)
2771 CONST
char *CONST section_name
;
2772 CONST
char *CONST filename
;
2774 lang_wild_statement_type
*new = new_stat (lang_wild_statement
,
2777 if (section_name
!= (char *) NULL
&& strcmp (section_name
, "COMMON") == 0)
2779 placed_commons
= true;
2781 if (filename
!= (char *) NULL
)
2783 lang_has_input_file
= true;
2785 new->section_name
= section_name
;
2786 new->filename
= filename
;
2787 lang_list_init (&new->children
);
2791 lang_section_start (name
, address
)
2793 etree_type
* address
;
2795 lang_address_statement_type
*ad
= new_stat (lang_address_statement
, stat_ptr
);
2797 ad
->section_name
= name
;
2798 ad
->address
= address
;
2801 /* Set the start symbol to NAME. CMDLINE is nonzero if this is called
2802 because of a -e argument on the command line, or zero if this is
2803 called by ENTRY in a linker script. Command line arguments take
2806 /* WINDOWS_NT. When an entry point has been specified, we will also force
2807 this symbol to be defined by calling ldlang_add_undef (equivalent to
2808 having switch -u entry_name on the command line). The reason we do
2809 this is so that the user doesn't have to because they would have to use
2810 the -u switch if they were specifying an entry point other than
2811 _mainCRTStartup. Specifically, if creating a windows application, entry
2812 point _WinMainCRTStartup must be specified.
2813 What I have found for non console applications (entry not _mainCRTStartup)
2814 is that the .obj that contains mainCRTStartup is brought in since it is
2815 the first encountered in libc.lib and it has other symbols in it which will
2816 be pulled in by the link process. To avoid this, adding -u with the entry
2817 point name specified forces the correct .obj to be used. We can avoid
2818 making the user do this by always adding the entry point name as an
2819 undefined symbol. */
2822 lang_add_entry (name
, cmdline
)
2826 static int from_cmdline
;
2828 if (entry_symbol
== NULL
2832 entry_symbol
= name
;
2833 from_cmdline
= cmdline
;
2836 /* don't do this yet. It seems to work (the executables run), but the
2837 image created is very different from what I was getting before indicating
2838 that something else is being pulled in. When everything else is working,
2839 then try to put this back in to see if it will do the right thing for
2840 other more complicated applications */
2841 ldlang_add_undef (name
);
2846 lang_add_target (name
)
2849 lang_target_statement_type
*new = new_stat (lang_target_statement
,
2865 map_option_f
= true;
2876 lang_fill_statement_type
*new = new_stat (lang_fill_statement
,
2883 lang_add_data (type
, exp
)
2885 union etree_union
*exp
;
2888 lang_data_statement_type
*new = new_stat (lang_data_statement
,
2896 /* Create a new reloc statement. RELOC is the BFD relocation type to
2897 generate. HOWTO is the corresponding howto structure (we could
2898 look this up, but the caller has already done so). SECTION is the
2899 section to generate a reloc against, or NAME is the name of the
2900 symbol to generate a reloc against. Exactly one of SECTION and
2901 NAME must be NULL. ADDEND is an expression for the addend. */
2904 lang_add_reloc (reloc
, howto
, section
, name
, addend
)
2905 bfd_reloc_code_real_type reloc
;
2906 reloc_howto_type
*howto
;
2909 union etree_union
*addend
;
2911 lang_reloc_statement_type
*p
= new_stat (lang_reloc_statement
, stat_ptr
);
2915 p
->section
= section
;
2917 p
->addend_exp
= addend
;
2919 p
->addend_value
= 0;
2920 p
->output_section
= NULL
;
2925 lang_add_assignment (exp
)
2928 lang_assignment_statement_type
*new = new_stat (lang_assignment_statement
,
2935 lang_add_attribute (attribute
)
2936 enum statement_enum attribute
;
2938 new_statement (attribute
, sizeof (lang_statement_union_type
), stat_ptr
);
2945 if (startup_file
!= (char *) NULL
)
2947 einfo ("%P%Fmultiple STARTUP files\n");
2949 first_file
->filename
= name
;
2950 first_file
->local_sym_name
= name
;
2951 first_file
->real
= true;
2953 startup_file
= name
;
2960 lang_float_flag
= maybe
;
2964 lang_leave_output_section_statement (fill
, memspec
)
2966 CONST
char *memspec
;
2968 current_section
->fill
= fill
;
2969 current_section
->region
= lang_memory_region_lookup (memspec
);
2970 stat_ptr
= &statement_list
;
2974 Create an absolute symbol with the given name with the value of the
2975 address of first byte of the section named.
2977 If the symbol already exists, then do nothing.
2980 lang_abs_symbol_at_beginning_of (secname
, name
)
2981 const char *secname
;
2984 struct bfd_link_hash_entry
*h
;
2986 h
= bfd_link_hash_lookup (link_info
.hash
, name
, true, true, true);
2987 if (h
== (struct bfd_link_hash_entry
*) NULL
)
2988 einfo ("%P%F: bfd_link_hash_lookup failed: %E\n");
2990 if (h
->type
== bfd_link_hash_new
2991 || h
->type
== bfd_link_hash_undefined
)
2995 h
->type
= bfd_link_hash_defined
;
2997 sec
= bfd_get_section_by_name (output_bfd
, secname
);
2998 if (sec
== (asection
*) NULL
)
3001 h
->u
.def
.value
= bfd_get_section_vma (output_bfd
, sec
);
3003 h
->u
.def
.section
= bfd_abs_section_ptr
;
3008 Create an absolute symbol with the given name with the value of the
3009 address of the first byte after the end of the section named.
3011 If the symbol already exists, then do nothing.
3014 lang_abs_symbol_at_end_of (secname
, name
)
3015 const char *secname
;
3018 struct bfd_link_hash_entry
*h
;
3020 h
= bfd_link_hash_lookup (link_info
.hash
, name
, true, true, true);
3021 if (h
== (struct bfd_link_hash_entry
*) NULL
)
3022 einfo ("%P%F: bfd_link_hash_lookup failed: %E\n");
3024 if (h
->type
== bfd_link_hash_new
3025 || h
->type
== bfd_link_hash_undefined
)
3029 h
->type
= bfd_link_hash_defined
;
3031 sec
= bfd_get_section_by_name (output_bfd
, secname
);
3032 if (sec
== (asection
*) NULL
)
3035 h
->u
.def
.value
= (bfd_get_section_vma (output_bfd
, sec
)
3036 + bfd_section_size (output_bfd
, sec
));
3038 h
->u
.def
.section
= bfd_abs_section_ptr
;
3043 lang_statement_append (list
, element
, field
)
3044 lang_statement_list_type
* list
;
3045 lang_statement_union_type
* element
;
3046 lang_statement_union_type
** field
;
3048 *(list
->tail
) = element
;
3052 /* Set the output format type. -oformat overrides scripts. */
3055 lang_add_output_format (format
, big
, little
, from_script
)
3061 if (output_target
== NULL
|| !from_script
)
3063 if (command_line
.endian
== ENDIAN_BIG
3066 else if (command_line
.endian
== ENDIAN_LITTLE
3070 output_target
= format
;
3074 /* Enter a group. This creates a new lang_group_statement, and sets
3075 stat_ptr to build new statements within the group. */
3080 lang_group_statement_type
*g
;
3082 g
= new_stat (lang_group_statement
, stat_ptr
);
3083 lang_list_init (&g
->children
);
3084 stat_ptr
= &g
->children
;
3087 /* Leave a group. This just resets stat_ptr to start writing to the
3088 regular list of statements again. Note that this will not work if
3089 groups can occur inside anything else which can adjust stat_ptr,
3090 but currently they can't. */
3095 stat_ptr
= &statement_list
;