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, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 #include "libiberty.h"
37 static void print_statements
PARAMS ((void));
38 static void print_statement
PARAMS ((lang_statement_union_type
*,
39 lang_output_section_statement_type
*));
40 static lang_statement_union_type
*new_statement
PARAMS ((enum statement_enum
,
42 lang_statement_list_type
*));
46 static struct obstack stat_obstack
;
48 #define obstack_chunk_alloc xmalloc
49 #define obstack_chunk_free free
50 static CONST
char *startup_file
;
51 static lang_statement_list_type input_file_chain
;
52 static boolean placed_commons
= false;
53 static lang_output_section_statement_type
*default_common_section
;
54 static boolean map_option_f
;
55 static bfd_vma print_dot
;
56 static lang_input_statement_type
*first_file
;
57 static lang_statement_list_type lang_output_section_statement
;
58 static CONST
char *current_target
;
59 static CONST
char *output_target
;
60 static int longest_section_name
= 8;
61 static lang_statement_list_type statement_list
;
63 static void print_size
PARAMS ((size_t value
));
64 static void print_alignment
PARAMS ((unsigned int value
));
65 static void print_fill
PARAMS ((fill_type value
));
66 static void print_section
PARAMS ((const char *name
));
67 static void lang_for_each_statement_worker
68 PARAMS ((void (*func
) (lang_statement_union_type
*),
69 lang_statement_union_type
*s
));
70 static lang_input_statement_type
*new_afile
71 PARAMS ((const char *name
, lang_input_file_enum_type file_type
,
72 const char *target
, boolean add_to_list
));
73 static void print_flags
PARAMS ((int *ignore_flags
));
74 static void init_os
PARAMS ((lang_output_section_statement_type
*s
));
75 static void wild_section
PARAMS ((lang_wild_statement_type
*ptr
,
77 lang_input_statement_type
*file
,
78 lang_output_section_statement_type
*output
));
79 static lang_input_statement_type
*lookup_name
PARAMS ((const char *name
));
80 static void load_symbols
PARAMS ((lang_input_statement_type
*entry
,
81 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 reset_memory_regions
PARAMS ((void));
132 lang_output_section_statement_type
*abs_output_section
;
133 lang_statement_list_type
*stat_ptr
= &statement_list
;
134 lang_statement_list_type file_chain
= { 0 };
135 static const char *entry_symbol
= 0;
136 boolean lang_has_input_file
= false;
137 boolean had_output_filename
= false;
138 boolean lang_float_flag
= false;
139 boolean delete_output_file_on_failure
= false;
141 etree_type
*base
; /* Relocation base - or null */
144 #if defined(__STDC__) || defined(ALMOST_STDC)
145 #define cat(a,b) a##b
147 #define cat(a,b) a/**/b
150 #define new_stat(x,y) (cat(x,_type)*) new_statement(cat(x,_enum), sizeof(cat(x,_type)),y)
152 #define outside_section_address(q) ( (q)->output_offset + (q)->output_section->vma)
154 #define outside_symbol_address(q) ((q)->value + outside_section_address(q->section))
160 return obstack_alloc (&stat_obstack
, size
);
167 fprintf (config
.map_file
, "%5x", (unsigned) value
);
171 print_alignment (value
)
174 fprintf (config
.map_file
, "2**%1u", value
);
181 fprintf (config
.map_file
, "%04x", (unsigned) value
);
188 fprintf (config
.map_file
, "%*s", -longest_section_name
, name
);
191 /*----------------------------------------------------------------------
192 lang_for_each_statement walks the parse tree and calls the provided
193 function for each node
197 lang_for_each_statement_worker (func
, s
)
198 void (*func
) PARAMS ((lang_statement_union_type
*));
199 lang_statement_union_type
*s
;
201 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
205 switch (s
->header
.type
)
207 case lang_constructors_statement_enum
:
208 lang_for_each_statement_worker (func
, constructor_list
.head
);
210 case lang_output_section_statement_enum
:
211 lang_for_each_statement_worker
213 s
->output_section_statement
.children
.head
);
215 case lang_wild_statement_enum
:
216 lang_for_each_statement_worker
218 s
->wild_statement
.children
.head
);
220 case lang_group_statement_enum
:
221 lang_for_each_statement_worker (func
,
222 s
->group_statement
.children
.head
);
224 case lang_data_statement_enum
:
225 case lang_reloc_statement_enum
:
226 case lang_object_symbols_statement_enum
:
227 case lang_output_statement_enum
:
228 case lang_target_statement_enum
:
229 case lang_input_section_enum
:
230 case lang_input_statement_enum
:
231 case lang_assignment_statement_enum
:
232 case lang_padding_statement_enum
:
233 case lang_address_statement_enum
:
243 lang_for_each_statement (func
)
244 void (*func
) PARAMS ((lang_statement_union_type
*));
246 lang_for_each_statement_worker (func
,
247 statement_list
.head
);
250 /*----------------------------------------------------------------------*/
252 lang_list_init (list
)
253 lang_statement_list_type
*list
;
255 list
->head
= (lang_statement_union_type
*) NULL
;
256 list
->tail
= &list
->head
;
259 /*----------------------------------------------------------------------
261 build a new statement node for the parse tree
266 lang_statement_union_type
*
267 new_statement (type
, size
, list
)
268 enum statement_enum type
;
270 lang_statement_list_type
* list
;
272 lang_statement_union_type
*new = (lang_statement_union_type
*)
275 new->header
.type
= type
;
276 new->header
.next
= (lang_statement_union_type
*) NULL
;
277 lang_statement_append (list
, new, &new->header
.next
);
282 Build a new input file node for the language. There are several ways
283 in which we treat an input file, eg, we only look at symbols, or
284 prefix it with a -l etc.
286 We can be supplied with requests for input files more than once;
287 they may, for example be split over serveral lines like foo.o(.text)
288 foo.o(.data) etc, so when asked for a file we check that we havn't
289 got it already so we don't duplicate the bfd.
292 static lang_input_statement_type
*
293 new_afile (name
, file_type
, target
, add_to_list
)
295 lang_input_file_enum_type file_type
;
299 lang_input_statement_type
*p
;
302 p
= new_stat (lang_input_statement
, stat_ptr
);
305 p
= ((lang_input_statement_type
*)
306 stat_alloc (sizeof (lang_input_statement_type
)));
307 p
->header
.next
= NULL
;
310 lang_has_input_file
= true;
312 p
->complained
= false;
315 case lang_input_file_is_symbols_only_enum
:
317 p
->is_archive
= false;
319 p
->local_sym_name
= name
;
320 p
->just_syms_flag
= true;
321 p
->search_dirs_flag
= false;
323 case lang_input_file_is_fake_enum
:
325 p
->is_archive
= false;
327 p
->local_sym_name
= name
;
328 p
->just_syms_flag
= false;
329 p
->search_dirs_flag
= false;
331 case lang_input_file_is_l_enum
:
332 p
->is_archive
= true;
335 p
->local_sym_name
= concat ("-l", name
, (const char *) NULL
);
336 p
->just_syms_flag
= false;
337 p
->search_dirs_flag
= true;
339 case lang_input_file_is_marker_enum
:
341 p
->is_archive
= false;
343 p
->local_sym_name
= name
;
344 p
->just_syms_flag
= false;
345 p
->search_dirs_flag
= true;
347 case lang_input_file_is_search_file_enum
:
349 p
->is_archive
= false;
351 p
->local_sym_name
= name
;
352 p
->just_syms_flag
= false;
353 p
->search_dirs_flag
= true;
355 case lang_input_file_is_file_enum
:
357 p
->is_archive
= false;
359 p
->local_sym_name
= name
;
360 p
->just_syms_flag
= false;
361 p
->search_dirs_flag
= false;
366 p
->the_bfd
= (bfd
*) NULL
;
367 p
->asymbols
= (asymbol
**) NULL
;
368 p
->next_real_file
= (lang_statement_union_type
*) NULL
;
369 p
->next
= (lang_statement_union_type
*) NULL
;
371 p
->common_output_section
= (asection
*) NULL
;
373 lang_statement_append (&input_file_chain
,
374 (lang_statement_union_type
*) p
,
379 lang_input_statement_type
*
380 lang_add_input_file (name
, file_type
, target
)
382 lang_input_file_enum_type file_type
;
385 lang_has_input_file
= true;
386 return new_afile (name
, file_type
, target
, true);
389 /* Build enough state so that the parser can build its tree */
393 obstack_begin (&stat_obstack
, 1000);
395 stat_ptr
= &statement_list
;
397 lang_list_init (stat_ptr
);
399 lang_list_init (&input_file_chain
);
400 lang_list_init (&lang_output_section_statement
);
401 lang_list_init (&file_chain
);
402 first_file
= lang_add_input_file ((char *) NULL
,
403 lang_input_file_is_marker_enum
,
405 abs_output_section
= lang_output_section_statement_lookup (BFD_ABS_SECTION_NAME
);
407 abs_output_section
->bfd_section
= bfd_abs_section_ptr
;
411 /*----------------------------------------------------------------------
412 A region is an area of memory declared with the
413 MEMORY { name:org=exp, len=exp ... }
416 We maintain a list of all the regions here
418 If no regions are specified in the script, then the default is used
419 which is created when looked up to be the entire data space
422 static lang_memory_region_type
*lang_memory_region_list
;
423 static lang_memory_region_type
**lang_memory_region_list_tail
= &lang_memory_region_list
;
425 lang_memory_region_type
*
426 lang_memory_region_lookup (name
)
427 CONST
char *CONST name
;
430 lang_memory_region_type
*p
= lang_memory_region_list
;
432 for (p
= lang_memory_region_list
;
433 p
!= (lang_memory_region_type
*) NULL
;
436 if (strcmp (p
->name
, name
) == 0)
441 if (strcmp (name
, "*default*") == 0)
443 /* This is the default region, dig out first one on the list */
444 if (lang_memory_region_list
!= (lang_memory_region_type
*) NULL
)
446 return lang_memory_region_list
;
450 lang_memory_region_type
*new =
451 (lang_memory_region_type
*) stat_alloc ((bfd_size_type
) (sizeof (lang_memory_region_type
)));
453 new->name
= buystring (name
);
454 new->next
= (lang_memory_region_type
*) NULL
;
456 *lang_memory_region_list_tail
= new;
457 lang_memory_region_list_tail
= &new->next
;
459 new->length
= ~(bfd_size_type
)0;
461 new->had_full_message
= false;
468 lang_output_section_statement_type
*
469 lang_output_section_find (name
)
470 CONST
char *CONST name
;
472 lang_statement_union_type
*u
;
473 lang_output_section_statement_type
*lookup
;
475 for (u
= lang_output_section_statement
.head
;
476 u
!= (lang_statement_union_type
*) NULL
;
479 lookup
= &u
->output_section_statement
;
480 if (strcmp (name
, lookup
->name
) == 0)
485 return (lang_output_section_statement_type
*) NULL
;
488 lang_output_section_statement_type
*
489 lang_output_section_statement_lookup (name
)
490 CONST
char *CONST name
;
492 lang_output_section_statement_type
*lookup
;
494 lookup
= lang_output_section_find (name
);
495 if (lookup
== (lang_output_section_statement_type
*) NULL
)
498 lookup
= (lang_output_section_statement_type
*)
499 new_stat (lang_output_section_statement
, stat_ptr
);
500 lookup
->region
= (lang_memory_region_type
*) NULL
;
502 lookup
->block_value
= 1;
505 lookup
->next
= (lang_statement_union_type
*) NULL
;
506 lookup
->bfd_section
= (asection
*) NULL
;
507 lookup
->processed
= false;
508 lookup
->loadable
= 1;
509 lookup
->addr_tree
= (etree_type
*) NULL
;
510 lang_list_init (&lookup
->children
);
512 lookup
->memspec
= (CONST
char *) NULL
;
514 lookup
->subsection_alignment
= -1;
515 lookup
->section_alignment
= -1;
516 lookup
->load_base
= (union etree_union
*) NULL
;
518 lang_statement_append (&lang_output_section_statement
,
519 (lang_statement_union_type
*) lookup
,
527 print_flags (ignore_flags
)
530 fprintf (config
.map_file
, "(");
532 if (flags
->flag_read
)
533 fprintf (outfile
, "R");
534 if (flags
->flag_write
)
535 fprintf (outfile
, "W");
536 if (flags
->flag_executable
)
537 fprintf (outfile
, "X");
538 if (flags
->flag_loadable
)
539 fprintf (outfile
, "L");
541 fprintf (config
.map_file
, ")");
547 lang_memory_region_type
*m
;
549 fprintf (config
.map_file
, "**MEMORY CONFIGURATION**\n\n");
551 fprintf (config
.map_file
, "name\t\torigin\t\tlength\t\tattributes\n");
553 fprintf (config
.map_file
,
554 "name\t\torigin length r_size c_size is attributes\n");
557 for (m
= lang_memory_region_list
;
558 m
!= (lang_memory_region_type
*) NULL
;
561 fprintf (config
.map_file
, "%-16s", m
->name
);
562 print_address (m
->origin
);
564 print_address ((bfd_vma
)m
->length
);
566 print_address ((bfd_vma
)m
->old_length
);
568 print_address (m
->current
- m
->origin
);
571 fprintf (config
.map_file
, " %2d%% ",
572 (int) ((m
->current
- m
->origin
) * 100 / m
->old_length
));
573 print_flags (&m
->flags
);
574 fprintf (config
.map_file
, "\n");
576 fprintf (config
.map_file
, "\n\n**LINK EDITOR MEMORY MAP**\n\n");
577 fprintf (config
.map_file
, "output input virtual\n");
578 fprintf (config
.map_file
, "section section address tsize\n\n");
589 lang_output_section_statement_type
* s
;
591 /* asection *section = bfd_get_section_by_name(output_bfd, s->name);*/
592 section_userdata_type
*new =
593 (section_userdata_type
*)
594 stat_alloc ((bfd_size_type
) (sizeof (section_userdata_type
)));
596 s
->bfd_section
= bfd_get_section_by_name (output_bfd
, s
->name
);
597 if (s
->bfd_section
== (asection
*) NULL
)
598 s
->bfd_section
= bfd_make_section (output_bfd
, s
->name
);
599 if (s
->bfd_section
== (asection
*) NULL
)
601 einfo ("%P%F: output format %s cannot represent section called %s\n",
602 output_bfd
->xvec
->name
, s
->name
);
604 s
->bfd_section
->output_section
= s
->bfd_section
;
605 /* s->bfd_section->flags = s->flags;*/
607 /* We initialize an output sections output offset to minus its own */
608 /* vma to allow us to output a section through itself */
609 s
->bfd_section
->output_offset
= 0;
610 get_userdata (s
->bfd_section
) = (PTR
) new;
614 /***********************************************************************
617 These expand statements like *(.text) and foo.o to a list of
618 explicit actions, like foo.o(.text), bar.o(.text) and
621 The toplevel routine, wild, takes a statement, section, file and
622 target. If either the section or file is null it is taken to be the
623 wildcard. Seperate lang_input_section statements are created for
624 each part of the expanstion, and placed after the statement provided.
629 wild_doit (ptr
, section
, output
, file
)
630 lang_statement_list_type
* ptr
;
632 lang_output_section_statement_type
* output
;
633 lang_input_statement_type
* file
;
635 if (output
->bfd_section
== (asection
*) NULL
)
638 if (section
!= (asection
*) NULL
639 && section
->output_section
== (asection
*) NULL
)
641 /* Add a section reference to the list */
642 lang_input_section_type
*new = new_stat (lang_input_section
, ptr
);
644 new->section
= section
;
646 section
->output_section
= output
->bfd_section
;
648 /* We don't copy the SEC_NEVER_LOAD flag from an input section to
649 an output section, because we want to be able to include a
650 SEC_NEVER_LOAD section in the middle of an otherwise loaded
651 section (I don't know why we want to do this, but we do).
652 build_link_order in ldwrite.c handles this case by turning the
653 embedded SEC_NEVER_LOAD section into a fill. */
654 section
->output_section
->flags
|=
655 section
->flags
& (flagword
) (~ SEC_NEVER_LOAD
);
657 if (!output
->loadable
)
659 /* Turn off load flag */
660 output
->bfd_section
->flags
&= ~SEC_LOAD
;
661 output
->bfd_section
->flags
|= SEC_NEVER_LOAD
;
663 if (section
->alignment_power
> output
->bfd_section
->alignment_power
)
665 output
->bfd_section
->alignment_power
= section
->alignment_power
;
667 /* If supplied an aligmnet, then force it */
668 if (output
->section_alignment
!= -1)
670 output
->bfd_section
->alignment_power
= output
->section_alignment
;
676 wild_section (ptr
, section
, file
, output
)
677 lang_wild_statement_type
*ptr
;
679 lang_input_statement_type
*file
;
680 lang_output_section_statement_type
*output
;
682 if (file
->just_syms_flag
== false)
684 register asection
*s
;
686 for (s
= file
->the_bfd
->sections
; s
!= NULL
; s
= s
->next
)
688 /* Attach all sections named SECTION. If SECTION is NULL,
689 then attach all sections.
691 Previously, if SECTION was NULL, this code did not call
692 wild_doit if the SEC_IS_COMMON flag was set for the
693 section. I did not understand that, and I took it out.
697 || strcmp (bfd_get_section_name (file
->the_bfd
, s
),
699 wild_doit (&ptr
->children
, s
, output
, file
);
704 /* passed a file name (which must have been seen already and added to
705 the statement tree. We will see if it has been opened already and
706 had its symbols read. If not then we'll read it.
708 Archives are pecuilar here. We may open them once, but if they do
709 not define anything we need at the time, they won't have all their
710 symbols read. If we need them later, we'll have to redo it. */
711 static lang_input_statement_type
*
715 lang_input_statement_type
*search
;
717 for (search
= (lang_input_statement_type
*) input_file_chain
.head
;
718 search
!= (lang_input_statement_type
*) NULL
;
719 search
= (lang_input_statement_type
*) search
->next_real_file
)
721 if (search
->filename
== (char *) NULL
&& name
== (char *) NULL
)
723 if (search
->filename
!= (char *) NULL
724 && name
!= (char *) NULL
725 && strcmp (search
->filename
, name
) == 0)
729 if (search
== (lang_input_statement_type
*) NULL
)
730 search
= new_afile (name
, lang_input_file_is_file_enum
, default_target
,
733 /* If we have already added this file, or this file is not real
734 (FIXME: can that ever actually happen?) or the name is NULL
735 (FIXME: can that ever actually happen?) don't add this file. */
738 || search
->filename
== (const char *) NULL
)
741 load_symbols (search
, (lang_statement_list_type
*) NULL
);
746 /* Get the symbols for an input file. */
749 load_symbols (entry
, place
)
750 lang_input_statement_type
*entry
;
751 lang_statement_list_type
*place
;
758 ldfile_open_file (entry
);
760 if (! bfd_check_format (entry
->the_bfd
, bfd_archive
)
761 && ! bfd_check_format_matches (entry
->the_bfd
, bfd_object
, &matching
))
764 lang_statement_list_type
*hold
;
766 err
= bfd_get_error ();
767 if (err
== bfd_error_file_ambiguously_recognized
)
771 einfo ("%B: file not recognized: %E\n", entry
->the_bfd
);
772 einfo ("%B: matching formats:", entry
->the_bfd
);
773 for (p
= matching
; *p
!= NULL
; p
++)
777 else if (err
!= bfd_error_file_not_recognized
779 einfo ("%F%B: file not recognized: %E\n", entry
->the_bfd
);
781 /* Try to interpret the file as a linker script. */
783 bfd_close (entry
->the_bfd
);
784 entry
->the_bfd
= NULL
;
786 ldfile_open_command_file (entry
->filename
);
791 ldfile_assumed_script
= true;
792 parser_input
= input_script
;
794 ldfile_assumed_script
= false;
801 /* We don't call ldlang_add_file for an archive. Instead, the
802 add_symbols entry point will call ldlang_add_file, via the
803 add_archive_element callback, for each element of the archive
805 switch (bfd_get_format (entry
->the_bfd
))
811 ldlang_add_file (entry
);
812 if (trace_files
|| trace_file_tries
)
813 info_msg ("%I\n", entry
);
819 bfd
*member
= bfd_openr_next_archived_file (entry
->the_bfd
,
821 while (member
!= NULL
)
823 if (! bfd_check_format (member
, bfd_object
))
824 einfo ("%F%B: object %B in archive is not object\n",
825 entry
->the_bfd
, member
);
826 if (! ((*link_info
.callbacks
->add_archive_element
)
827 (&link_info
, member
, "-whole-archive")))
829 if (! bfd_link_add_symbols (member
, &link_info
))
830 einfo ("%F%B: could not read symbols: %E\n", member
);
831 member
= bfd_openr_next_archived_file (entry
->the_bfd
,
835 entry
->loaded
= true;
841 if (! bfd_link_add_symbols (entry
->the_bfd
, &link_info
))
842 einfo ("%F%B: could not read symbols: %E\n", entry
->the_bfd
);
844 entry
->loaded
= true;
848 wild (s
, section
, file
, target
, output
)
849 lang_wild_statement_type
* s
;
853 lang_output_section_statement_type
* output
;
855 lang_input_statement_type
*f
;
857 if (file
== (char *) NULL
)
859 /* Perform the iteration over all files in the list */
860 for (f
= (lang_input_statement_type
*) file_chain
.head
;
861 f
!= (lang_input_statement_type
*) NULL
;
862 f
= (lang_input_statement_type
*) f
->next
)
864 wild_section (s
, section
, f
, output
);
869 /* Perform the iteration over a single file */
870 wild_section (s
, section
, lookup_name (file
), output
);
872 if (section
!= (char *) NULL
873 && strcmp (section
, "COMMON") == 0
874 && default_common_section
== (lang_output_section_statement_type
*) NULL
)
876 /* Remember the section that common is going to incase we later
877 get something which doesn't know where to put it */
878 default_common_section
= output
;
883 read in all the files
892 if (output_target
== (char *) NULL
)
894 if (current_target
!= (char *) NULL
)
895 output_target
= current_target
;
897 output_target
= default_target
;
899 output
= bfd_openw (name
, output_target
);
901 if (output
== (bfd
*) NULL
)
903 if (bfd_get_error () == bfd_error_invalid_target
)
905 einfo ("%P%F: target %s not found\n", output_target
);
907 einfo ("%P%F: cannot open output file %s: %E\n", name
);
910 delete_output_file_on_failure
= 1;
912 /* output->flags |= D_PAGED;*/
914 if (! bfd_set_format (output
, bfd_object
))
915 einfo ("%P%F:%s: can not make object file: %E\n", name
);
916 if (! bfd_set_arch_mach (output
,
917 ldfile_output_architecture
,
918 ldfile_output_machine
))
919 einfo ("%P%F:%s: can not set architecture: %E\n", name
);
921 link_info
.hash
= bfd_link_hash_table_create (output
);
922 if (link_info
.hash
== (struct bfd_link_hash_table
*) NULL
)
923 einfo ("%P%F: can not create link hash table: %E\n");
925 bfd_set_gp_size (output
, g_switch_value
);
933 ldlang_open_output (statement
)
934 lang_statement_union_type
* statement
;
936 switch (statement
->header
.type
)
938 case lang_output_statement_enum
:
939 ASSERT (output_bfd
== (bfd
*) NULL
);
940 output_bfd
= open_output (statement
->output_statement
.name
);
941 ldemul_set_output_arch ();
942 if (config
.magic_demand_paged
&& !link_info
.relocateable
)
943 output_bfd
->flags
|= D_PAGED
;
945 output_bfd
->flags
&= ~D_PAGED
;
946 if (config
.text_read_only
)
947 output_bfd
->flags
|= WP_TEXT
;
949 output_bfd
->flags
&= ~WP_TEXT
;
950 if (config
.traditional_format
)
951 output_bfd
->flags
|= BFD_TRADITIONAL_FORMAT
;
953 output_bfd
->flags
&= ~BFD_TRADITIONAL_FORMAT
;
956 case lang_target_statement_enum
:
957 current_target
= statement
->target_statement
.target
;
964 /* Open all the input files. */
967 open_input_bfds (s
, force
)
968 lang_statement_union_type
*s
;
971 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
973 switch (s
->header
.type
)
975 case lang_constructors_statement_enum
:
976 open_input_bfds (constructor_list
.head
, force
);
978 case lang_output_section_statement_enum
:
979 open_input_bfds (s
->output_section_statement
.children
.head
, force
);
981 case lang_wild_statement_enum
:
982 /* Maybe we should load the file's symbols */
983 if (s
->wild_statement
.filename
)
984 (void) lookup_name (s
->wild_statement
.filename
);
985 open_input_bfds (s
->wild_statement
.children
.head
, force
);
987 case lang_group_statement_enum
:
989 struct bfd_link_hash_entry
*undefs
;
991 /* We must continually search the entries in the group
992 until no new symbols are added to the list of undefined
997 undefs
= link_info
.hash
->undefs_tail
;
998 open_input_bfds (s
->group_statement
.children
.head
, true);
1000 while (undefs
!= link_info
.hash
->undefs_tail
);
1003 case lang_target_statement_enum
:
1004 current_target
= s
->target_statement
.target
;
1006 case lang_input_statement_enum
:
1007 if (s
->input_statement
.real
== true)
1009 lang_statement_list_type add
;
1011 s
->input_statement
.target
= current_target
;
1013 /* If we are being called from within a group, and this
1014 is an archive which has already been searched, then
1015 force it to be researched. */
1017 && s
->input_statement
.loaded
1018 && bfd_check_format (s
->input_statement
.the_bfd
,
1020 s
->input_statement
.loaded
= false;
1022 lang_list_init (&add
);
1024 load_symbols (&s
->input_statement
, &add
);
1026 if (add
.head
!= NULL
)
1028 *add
.tail
= s
->next
;
1039 /* If there are [COMMONS] statements, put a wild one into the bss section */
1042 lang_reasonable_defaults ()
1045 lang_output_section_statement_lookup (".text");
1046 lang_output_section_statement_lookup (".data");
1048 default_common_section
=
1049 lang_output_section_statement_lookup (".bss");
1052 if (placed_commons
== false)
1054 lang_wild_statement_type
*new =
1055 new_stat (lang_wild_statement
,
1056 &default_common_section
->children
);
1058 new->section_name
= "COMMON";
1059 new->filename
= (char *) NULL
;
1060 lang_list_init (&new->children
);
1067 Add the supplied name to the symbol table as an undefined reference.
1068 Remove items from the chain as we open input bfds
1070 typedef struct ldlang_undef_chain_list
1072 struct ldlang_undef_chain_list
*next
;
1074 } ldlang_undef_chain_list_type
;
1076 static ldlang_undef_chain_list_type
*ldlang_undef_chain_list_head
;
1079 ldlang_add_undef (name
)
1080 CONST
char *CONST name
;
1082 ldlang_undef_chain_list_type
*new =
1083 (ldlang_undef_chain_list_type
1084 *) stat_alloc ((bfd_size_type
) (sizeof (ldlang_undef_chain_list_type
)));
1086 new->next
= ldlang_undef_chain_list_head
;
1087 ldlang_undef_chain_list_head
= new;
1089 new->name
= buystring (name
);
1092 /* Run through the list of undefineds created above and place them
1093 into the linker hash table as undefined symbols belonging to the
1097 lang_place_undefineds ()
1099 ldlang_undef_chain_list_type
*ptr
;
1101 for (ptr
= ldlang_undef_chain_list_head
;
1102 ptr
!= (ldlang_undef_chain_list_type
*) NULL
;
1105 struct bfd_link_hash_entry
*h
;
1107 h
= bfd_link_hash_lookup (link_info
.hash
, ptr
->name
, true, false, true);
1108 if (h
== (struct bfd_link_hash_entry
*) NULL
)
1109 einfo ("%P%F: bfd_link_hash_lookup failed: %E");
1110 if (h
->type
== bfd_link_hash_new
)
1112 h
->type
= bfd_link_hash_undefined
;
1113 h
->u
.undef
.abfd
= NULL
;
1114 bfd_link_add_undef (link_info
.hash
, h
);
1119 /* Open input files and attatch to output sections */
1121 map_input_to_output_sections (s
, target
, output_section_statement
)
1122 lang_statement_union_type
* s
;
1124 lang_output_section_statement_type
* output_section_statement
;
1126 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
1128 switch (s
->header
.type
)
1132 case lang_wild_statement_enum
:
1133 wild (&s
->wild_statement
, s
->wild_statement
.section_name
,
1134 s
->wild_statement
.filename
, target
,
1135 output_section_statement
);
1138 case lang_constructors_statement_enum
:
1139 map_input_to_output_sections (constructor_list
.head
,
1141 output_section_statement
);
1143 case lang_output_section_statement_enum
:
1144 map_input_to_output_sections (s
->output_section_statement
.children
.head
,
1146 &s
->output_section_statement
);
1148 case lang_output_statement_enum
:
1150 case lang_target_statement_enum
:
1151 target
= s
->target_statement
.target
;
1153 case lang_group_statement_enum
:
1154 map_input_to_output_sections (s
->group_statement
.children
.head
,
1156 output_section_statement
);
1158 case lang_fill_statement_enum
:
1159 case lang_input_section_enum
:
1160 case lang_object_symbols_statement_enum
:
1161 case lang_data_statement_enum
:
1162 case lang_reloc_statement_enum
:
1163 case lang_assignment_statement_enum
:
1164 case lang_padding_statement_enum
:
1165 case lang_input_statement_enum
:
1166 if (output_section_statement
!= NULL
1167 && output_section_statement
->bfd_section
== NULL
)
1168 init_os (output_section_statement
);
1170 case lang_afile_asection_pair_statement_enum
:
1173 case lang_address_statement_enum
:
1174 /* Mark the specified section with the supplied address */
1176 lang_output_section_statement_type
*os
=
1177 lang_output_section_statement_lookup
1178 (s
->address_statement
.section_name
);
1180 if (os
->bfd_section
== NULL
)
1182 os
->addr_tree
= s
->address_statement
.address
;
1190 print_output_section_statement (output_section_statement
)
1191 lang_output_section_statement_type
* output_section_statement
;
1193 asection
*section
= output_section_statement
->bfd_section
;
1196 print_section (output_section_statement
->name
);
1201 print_dot
= section
->vma
;
1205 print_address (section
->vma
);
1207 print_size (section
->_raw_size
);
1209 print_size(section
->_cooked_size
);
1211 print_alignment (section
->alignment_power
);
1214 fprintf (config
.map_file
, "%s flags", output_section_statement
->region
->name
);
1215 print_flags (stdout
, &output_section_statement
->flags
);
1217 if (section
->flags
& SEC_LOAD
)
1218 fprintf (config
.map_file
, "load ");
1219 if (section
->flags
& SEC_ALLOC
)
1220 fprintf (config
.map_file
, "alloc ");
1221 if (section
->flags
& SEC_RELOC
)
1222 fprintf (config
.map_file
, "reloc ");
1223 if (section
->flags
& SEC_HAS_CONTENTS
)
1224 fprintf (config
.map_file
, "contents ");
1229 fprintf (config
.map_file
, " (no attached output section)");
1232 if (output_section_statement
->load_base
)
1234 int b
= exp_get_abs_int(output_section_statement
->load_base
,
1235 0, "output base", lang_final_phase_enum
);
1236 fprintf (config
.map_file
, "Output address %08x\n", b
);
1238 if (output_section_statement
->section_alignment
>= 0
1239 || output_section_statement
->subsection_alignment
>= 0)
1241 fprintf (config
.map_file
, "\t\t\t\t\tforced alignment ");
1242 if (output_section_statement
->section_alignment
>= 0)
1244 fprintf (config
.map_file
, "section 2**%d ",output_section_statement
->section_alignment
);
1246 if ( output_section_statement
->subsection_alignment
>= 0)
1248 fprintf (config
.map_file
, "subsection 2**%d ",output_section_statement
->subsection_alignment
);
1253 print_statement (output_section_statement
->children
.head
,
1254 output_section_statement
);
1259 print_assignment (assignment
, output_section
)
1260 lang_assignment_statement_type
* assignment
;
1261 lang_output_section_statement_type
* output_section
;
1263 etree_value_type result
;
1269 print_address (print_dot
);
1271 result
= exp_fold_tree (assignment
->exp
->assign
.src
,
1273 lang_final_phase_enum
,
1279 print_address (result
.value
);
1283 fprintf (config
.map_file
, "*undefined*");
1286 exp_print_tree (assignment
->exp
);
1288 fprintf (config
.map_file
, "\n");
1292 print_input_statement (statm
)
1293 lang_input_statement_type
* statm
;
1295 if (statm
->filename
!= (char *) NULL
)
1297 fprintf (config
.map_file
, "LOAD %s\n", statm
->filename
);
1301 /* Print all the defined symbols for the abfd provided by in the supplied
1306 print_one_symbol (hash_entry
, ptr
)
1307 struct bfd_link_hash_entry
*hash_entry
;
1310 asection
* sec
= (asection
*)ptr
;
1312 if (hash_entry
->type
== bfd_link_hash_defined
1313 || hash_entry
->type
== bfd_link_hash_defweak
)
1315 if (sec
== hash_entry
->u
.def
.section
) {
1317 fprintf (config
.map_file
, " ");
1319 fprintf (config
.map_file
, " ");
1320 print_address (hash_entry
->u
.def
.value
+ outside_section_address (sec
));
1321 fprintf (config
.map_file
, " %s", hash_entry
->root
.string
);
1330 print_input_section (in
)
1331 lang_input_section_type
* in
;
1333 asection
*i
= in
->section
;
1334 bfd_size_type size
= i
->_cooked_size
!= 0 ? i
->_cooked_size
: i
->_raw_size
;
1339 fprintf (config
.map_file
, " ");
1340 print_section (i
->name
);
1341 fprintf (config
.map_file
, " ");
1342 if (i
->output_section
)
1344 print_address (i
->output_section
->vma
+ i
->output_offset
);
1345 fprintf (config
.map_file
, " ");
1346 print_size (i
->_raw_size
);
1347 fprintf (config
.map_file
, " ");
1348 print_size(i
->_cooked_size
);
1349 fprintf (config
.map_file
, " ");
1350 print_alignment (i
->alignment_power
);
1351 fprintf (config
.map_file
, " ");
1355 bfd
*abfd
= in
->ifile
->the_bfd
;
1357 if (in
->ifile
->just_syms_flag
== true)
1359 fprintf (config
.map_file
, "symbols only ");
1362 fprintf (config
.map_file
, " %s ", abfd
->xvec
->name
);
1363 if (abfd
->my_archive
!= (bfd
*) NULL
)
1365 fprintf (config
.map_file
, "[%s]%s", abfd
->my_archive
->filename
,
1370 fprintf (config
.map_file
, "%s", abfd
->filename
);
1372 fprintf (config
.map_file
, "(overhead %d bytes)", (int) bfd_alloc_size (abfd
));
1375 /* Print all the symbols */
1376 bfd_link_hash_traverse (link_info
.hash
, print_one_symbol
, (PTR
) i
);
1384 print_dot
= outside_section_address (i
) + size
;
1388 fprintf (config
.map_file
, "No output section allocated\n");
1394 print_fill_statement (fill
)
1395 lang_fill_statement_type
* fill
;
1397 fprintf (config
.map_file
, "FILL mask ");
1398 print_fill (fill
->fill
);
1402 print_data_statement (data
)
1403 lang_data_statement_type
* data
;
1405 /* bfd_vma value; */
1410 /* ASSERT(print_dot == data->output_vma);*/
1412 print_address (data
->output_vma
+ data
->output_section
->vma
);
1414 print_address (data
->value
);
1419 fprintf (config
.map_file
, "BYTE ");
1420 print_dot
+= BYTE_SIZE
;
1423 fprintf (config
.map_file
, "SHORT ");
1424 print_dot
+= SHORT_SIZE
;
1427 fprintf (config
.map_file
, "LONG ");
1428 print_dot
+= LONG_SIZE
;
1431 fprintf (config
.map_file
, "QUAD ");
1432 print_dot
+= QUAD_SIZE
;
1436 exp_print_tree (data
->exp
);
1438 fprintf (config
.map_file
, "\n");
1441 /* Print a reloc statement. */
1444 print_reloc_statement (reloc
)
1445 lang_reloc_statement_type
*reloc
;
1452 /* ASSERT(print_dot == data->output_vma);*/
1454 print_address (reloc
->output_vma
+ reloc
->output_section
->vma
);
1456 print_address (reloc
->addend_value
);
1459 fprintf (config
.map_file
, "RELOC %s ", reloc
->howto
->name
);
1461 print_dot
+= bfd_get_reloc_size (reloc
->howto
);
1463 exp_print_tree (reloc
->addend_exp
);
1465 fprintf (config
.map_file
, "\n");
1469 print_padding_statement (s
)
1470 lang_padding_statement_type
* s
;
1474 print_section ("*fill*");
1476 print_address (s
->output_offset
+ s
->output_section
->vma
);
1478 print_size (s
->size
);
1480 print_fill (s
->fill
);
1483 print_dot
= s
->output_offset
+ s
->output_section
->vma
+ s
->size
;
1488 print_wild_statement (w
, os
)
1489 lang_wild_statement_type
* w
;
1490 lang_output_section_statement_type
* os
;
1492 fprintf (config
.map_file
, " from ");
1493 if (w
->filename
!= (char *) NULL
)
1495 fprintf (config
.map_file
, "%s", w
->filename
);
1499 fprintf (config
.map_file
, "*");
1501 if (w
->section_name
!= (char *) NULL
)
1503 fprintf (config
.map_file
, "(%s)", w
->section_name
);
1507 fprintf (config
.map_file
, "(*)");
1510 print_statement (w
->children
.head
, os
);
1514 /* Print a group statement. */
1518 lang_group_statement_type
*s
;
1519 lang_output_section_statement_type
*os
;
1521 fprintf (config
.map_file
, "START GROUP\n");
1522 print_statement (s
->children
.head
, os
);
1523 fprintf (config
.map_file
, "END GROUP\n");
1527 print_statement (s
, os
)
1528 lang_statement_union_type
* s
;
1529 lang_output_section_statement_type
* os
;
1533 switch (s
->header
.type
)
1535 case lang_constructors_statement_enum
:
1536 fprintf (config
.map_file
, "constructors:\n");
1537 print_statement (constructor_list
.head
, os
);
1539 case lang_wild_statement_enum
:
1540 print_wild_statement (&s
->wild_statement
, os
);
1543 fprintf (config
.map_file
, "Fail with %d\n", s
->header
.type
);
1546 case lang_address_statement_enum
:
1547 fprintf (config
.map_file
, "address\n");
1549 case lang_object_symbols_statement_enum
:
1550 fprintf (config
.map_file
, "object symbols\n");
1552 case lang_fill_statement_enum
:
1553 print_fill_statement (&s
->fill_statement
);
1555 case lang_data_statement_enum
:
1556 print_data_statement (&s
->data_statement
);
1558 case lang_reloc_statement_enum
:
1559 print_reloc_statement (&s
->reloc_statement
);
1561 case lang_input_section_enum
:
1562 print_input_section (&s
->input_section
);
1564 case lang_padding_statement_enum
:
1565 print_padding_statement (&s
->padding_statement
);
1567 case lang_output_section_statement_enum
:
1568 print_output_section_statement (&s
->output_section_statement
);
1570 case lang_assignment_statement_enum
:
1571 print_assignment (&s
->assignment_statement
,
1574 case lang_target_statement_enum
:
1575 fprintf (config
.map_file
, "TARGET(%s)\n", s
->target_statement
.target
);
1577 case lang_output_statement_enum
:
1578 fprintf (config
.map_file
, "OUTPUT(%s %s)\n",
1579 s
->output_statement
.name
,
1580 output_target
? output_target
: "");
1582 case lang_input_statement_enum
:
1583 print_input_statement (&s
->input_statement
);
1585 case lang_group_statement_enum
:
1586 print_group (&s
->group_statement
, os
);
1588 case lang_afile_asection_pair_statement_enum
:
1600 print_statement (statement_list
.head
,
1601 abs_output_section
);
1606 insert_pad (this_ptr
, fill
, power
, output_section_statement
, dot
)
1607 lang_statement_union_type
** this_ptr
;
1610 asection
* output_section_statement
;
1613 /* Align this section first to the
1614 input sections requirement, then
1615 to the output section's requirement.
1616 If this alignment is > than any seen before,
1617 then record it too. Perform the alignment by
1618 inserting a magic 'padding' statement.
1621 unsigned int alignment_needed
= align_power (dot
, power
) - dot
;
1623 if (alignment_needed
!= 0)
1625 lang_statement_union_type
*new =
1626 (lang_statement_union_type
*)
1627 stat_alloc ((bfd_size_type
) (sizeof (lang_padding_statement_type
)));
1629 /* Link into existing chain */
1630 new->header
.next
= *this_ptr
;
1632 new->header
.type
= lang_padding_statement_enum
;
1633 new->padding_statement
.output_section
= output_section_statement
;
1634 new->padding_statement
.output_offset
=
1635 dot
- output_section_statement
->vma
;
1636 new->padding_statement
.fill
= fill
;
1637 new->padding_statement
.size
= alignment_needed
;
1641 /* Remember the most restrictive alignment */
1642 if (power
> output_section_statement
->alignment_power
)
1644 output_section_statement
->alignment_power
= power
;
1646 output_section_statement
->_raw_size
+= alignment_needed
;
1647 return alignment_needed
+ dot
;
1651 /* Work out how much this section will move the dot point */
1653 size_input_section (this_ptr
, output_section_statement
, fill
, dot
, relax
)
1654 lang_statement_union_type
** this_ptr
;
1655 lang_output_section_statement_type
* output_section_statement
;
1660 lang_input_section_type
*is
= &((*this_ptr
)->input_section
);
1661 asection
*i
= is
->section
;
1663 if (is
->ifile
->just_syms_flag
== false)
1665 if (output_section_statement
->subsection_alignment
!= -1)
1666 i
->alignment_power
=
1667 output_section_statement
->subsection_alignment
;
1669 dot
= insert_pad (this_ptr
, fill
, i
->alignment_power
,
1670 output_section_statement
->bfd_section
, dot
);
1672 /* Remember where in the output section this input section goes */
1674 i
->output_offset
= dot
- output_section_statement
->bfd_section
->vma
;
1676 /* Mark how big the output section must be to contain this now
1678 if (i
->_cooked_size
!= 0)
1679 dot
+= i
->_cooked_size
;
1681 dot
+= i
->_raw_size
;
1682 output_section_statement
->bfd_section
->_raw_size
= dot
- output_section_statement
->bfd_section
->vma
;
1686 i
->output_offset
= i
->vma
- output_section_statement
->bfd_section
->vma
;
1692 /* This variable indicates whether bfd_relax_section should be called
1695 static boolean relax_again
;
1697 /* Set the sizes for all the output sections. */
1700 lang_size_sections (s
, output_section_statement
, prev
, fill
, dot
, relax
)
1701 lang_statement_union_type
* s
;
1702 lang_output_section_statement_type
* output_section_statement
;
1703 lang_statement_union_type
** prev
;
1708 /* Size up the sections from their constituent parts */
1709 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
1711 switch (s
->header
.type
)
1714 case lang_output_section_statement_enum
:
1717 lang_output_section_statement_type
*os
= &s
->output_section_statement
;
1719 if (os
->bfd_section
== NULL
)
1721 /* This section was never actually created. */
1725 /* If this is a COFF shared library section, use the size and
1726 address from the input section. FIXME: This is COFF
1727 specific; it would be cleaner if there were some other way
1728 to do this, but nothing simple comes to mind. */
1729 if ((os
->bfd_section
->flags
& SEC_COFF_SHARED_LIBRARY
) != 0)
1733 if (os
->children
.head
== NULL
1734 || os
->children
.head
->next
!= NULL
1735 || os
->children
.head
->header
.type
!= lang_input_section_enum
)
1736 einfo ("%P%X: Internal error on COFF shared library section %s",
1739 input
= os
->children
.head
->input_section
.section
;
1740 bfd_set_section_vma (os
->bfd_section
->owner
,
1742 bfd_section_vma (input
->owner
, input
));
1743 os
->bfd_section
->_raw_size
= input
->_raw_size
;
1747 if (bfd_is_abs_section (os
->bfd_section
))
1749 /* No matter what happens, an abs section starts at zero */
1750 ASSERT (os
->bfd_section
->vma
== 0);
1754 if (os
->addr_tree
== (etree_type
*) NULL
)
1756 /* No address specified for this section, get one
1757 from the region specification
1759 if (os
->region
== (lang_memory_region_type
*) NULL
)
1761 os
->region
= lang_memory_region_lookup ("*default*");
1763 dot
= os
->region
->current
;
1764 if (os
->section_alignment
== -1)
1765 dot
= align_power (dot
, os
->bfd_section
->alignment_power
);
1771 r
= exp_fold_tree (os
->addr_tree
,
1773 lang_allocating_phase_enum
,
1775 if (r
.valid
== false)
1777 einfo ("%F%S: non constant address expression for section %s\n",
1782 /* The section starts here */
1783 /* First, align to what the section needs */
1785 if (os
->section_alignment
!= -1)
1786 dot
= align_power (dot
, os
->section_alignment
);
1788 bfd_set_section_vma (0, os
->bfd_section
, dot
);
1790 os
->bfd_section
->output_offset
= 0;
1793 (void) lang_size_sections (os
->children
.head
, os
, &os
->children
.head
,
1794 os
->fill
, dot
, relax
);
1795 /* Ignore the size of the input sections, use the vma and size to */
1798 after
= ALIGN_N (os
->bfd_section
->vma
+
1799 os
->bfd_section
->_raw_size
,
1800 /* The coercion here is important, see ld.h. */
1801 (bfd_vma
) os
->block_value
);
1803 if (bfd_is_abs_section (os
->bfd_section
))
1804 ASSERT (after
== os
->bfd_section
->vma
);
1806 os
->bfd_section
->_raw_size
= after
- os
->bfd_section
->vma
;
1807 dot
= os
->bfd_section
->vma
+ os
->bfd_section
->_raw_size
;
1808 os
->processed
= true;
1810 /* Replace into region ? */
1811 if (os
->region
!= (lang_memory_region_type
*) NULL
)
1813 os
->region
->current
= dot
;
1814 /* Make sure this isn't silly. */
1815 if ((os
->region
->current
< os
->region
->origin
)
1816 || (os
->region
->current
1817 > os
->region
->origin
+ os
->region
->length
))
1819 if (os
->addr_tree
!= (etree_type
*) NULL
)
1821 einfo ("%X%P: address 0x%v of %B section %s is not within region %s\n",
1822 os
->region
->current
,
1823 os
->bfd_section
->owner
,
1824 os
->bfd_section
->name
,
1829 einfo ("%X%P: region %s is full (%B section %s)\n",
1831 os
->bfd_section
->owner
,
1832 os
->bfd_section
->name
);
1834 /* Reset the region pointer. */
1835 os
->region
->current
= os
->region
->origin
;
1841 case lang_constructors_statement_enum
:
1842 dot
= lang_size_sections (constructor_list
.head
,
1843 output_section_statement
,
1844 &s
->wild_statement
.children
.head
,
1849 case lang_data_statement_enum
:
1851 unsigned int size
= 0;
1853 s
->data_statement
.output_vma
= dot
- output_section_statement
->bfd_section
->vma
;
1854 s
->data_statement
.output_section
=
1855 output_section_statement
->bfd_section
;
1857 switch (s
->data_statement
.type
)
1874 output_section_statement
->bfd_section
->_raw_size
+= size
;
1878 case lang_reloc_statement_enum
:
1882 s
->reloc_statement
.output_vma
=
1883 dot
- output_section_statement
->bfd_section
->vma
;
1884 s
->reloc_statement
.output_section
=
1885 output_section_statement
->bfd_section
;
1886 size
= bfd_get_reloc_size (s
->reloc_statement
.howto
);
1888 output_section_statement
->bfd_section
->_raw_size
+= size
;
1892 case lang_wild_statement_enum
:
1894 dot
= lang_size_sections (s
->wild_statement
.children
.head
,
1895 output_section_statement
,
1896 &s
->wild_statement
.children
.head
,
1902 case lang_object_symbols_statement_enum
:
1903 link_info
.create_object_symbols_section
=
1904 output_section_statement
->bfd_section
;
1906 case lang_output_statement_enum
:
1907 case lang_target_statement_enum
:
1909 case lang_input_section_enum
:
1913 i
= (*prev
)->input_section
.section
;
1915 i
->_cooked_size
= i
->_raw_size
;
1920 if (! bfd_relax_section (i
->owner
, i
, &link_info
, &again
))
1921 einfo ("%P%F: can't relax section: %E\n");
1925 dot
= size_input_section (prev
,
1926 output_section_statement
,
1927 output_section_statement
->fill
,
1931 case lang_input_statement_enum
:
1933 case lang_fill_statement_enum
:
1934 s
->fill_statement
.output_section
= output_section_statement
->bfd_section
;
1936 fill
= s
->fill_statement
.fill
;
1938 case lang_assignment_statement_enum
:
1940 bfd_vma newdot
= dot
;
1942 exp_fold_tree (s
->assignment_statement
.exp
,
1943 output_section_statement
,
1944 lang_allocating_phase_enum
,
1948 if (newdot
!= dot
&& !relax
)
1950 /* The assignment changed dot. Insert a pad. */
1951 if (output_section_statement
== abs_output_section
)
1953 /* If we don't have an output section, then just adjust
1954 the default memory address. */
1955 lang_memory_region_lookup ("*default*")->current
= newdot
;
1959 lang_statement_union_type
*new =
1960 ((lang_statement_union_type
*)
1961 stat_alloc (sizeof (lang_padding_statement_type
)));
1963 /* Link into existing chain */
1964 new->header
.next
= *prev
;
1966 new->header
.type
= lang_padding_statement_enum
;
1967 new->padding_statement
.output_section
=
1968 output_section_statement
->bfd_section
;
1969 new->padding_statement
.output_offset
=
1970 dot
- output_section_statement
->bfd_section
->vma
;
1971 new->padding_statement
.fill
= fill
;
1972 new->padding_statement
.size
= newdot
- dot
;
1973 output_section_statement
->bfd_section
->_raw_size
+=
1974 new->padding_statement
.size
;
1982 case lang_padding_statement_enum
:
1983 /* If we are relaxing, and this is not the first pass, some
1984 padding statements may have been inserted during previous
1985 passes. We may have to move the padding statement to a new
1986 location if dot has a different value at this point in this
1987 pass than it did at this point in the previous pass. */
1988 s
->padding_statement
.output_offset
=
1989 dot
- output_section_statement
->bfd_section
->vma
;
1990 dot
+= s
->padding_statement
.size
;
1993 case lang_group_statement_enum
:
1994 dot
= lang_size_sections (s
->group_statement
.children
.head
,
1995 output_section_statement
,
1996 &s
->group_statement
.children
.head
,
2004 /* This can only get here when relaxing is turned on */
2006 case lang_address_statement_enum
:
2009 prev
= &s
->header
.next
;
2015 lang_do_assignments (s
, output_section_statement
, fill
, dot
)
2016 lang_statement_union_type
* s
;
2017 lang_output_section_statement_type
* output_section_statement
;
2021 for (; s
!= (lang_statement_union_type
*) NULL
; s
= s
->next
)
2023 switch (s
->header
.type
)
2025 case lang_constructors_statement_enum
:
2026 dot
= lang_do_assignments (constructor_list
.head
,
2027 output_section_statement
,
2032 case lang_output_section_statement_enum
:
2034 lang_output_section_statement_type
*os
=
2035 &(s
->output_section_statement
);
2037 if (os
->bfd_section
!= NULL
)
2039 dot
= os
->bfd_section
->vma
;
2040 (void) lang_do_assignments (os
->children
.head
, os
,
2042 dot
= os
->bfd_section
->vma
+ os
->bfd_section
->_raw_size
;
2046 /* If nothing has been placed into the output section then
2047 it won't have a bfd_section. */
2048 if (os
->bfd_section
)
2050 os
->bfd_section
->lma
2051 = exp_get_abs_int(os
->load_base
, 0,"load base", lang_final_phase_enum
);
2056 case lang_wild_statement_enum
:
2058 dot
= lang_do_assignments (s
->wild_statement
.children
.head
,
2059 output_section_statement
,
2064 case lang_object_symbols_statement_enum
:
2065 case lang_output_statement_enum
:
2066 case lang_target_statement_enum
:
2068 case lang_common_statement_enum
:
2071 case lang_data_statement_enum
:
2073 etree_value_type value
;
2075 value
= exp_fold_tree (s
->data_statement
.exp
,
2077 lang_final_phase_enum
, dot
, &dot
);
2078 s
->data_statement
.value
= value
.value
;
2079 if (value
.valid
== false)
2080 einfo ("%F%P: invalid data statement\n");
2082 switch (s
->data_statement
.type
)
2099 case lang_reloc_statement_enum
:
2101 etree_value_type value
;
2103 value
= exp_fold_tree (s
->reloc_statement
.addend_exp
,
2105 lang_final_phase_enum
, dot
, &dot
);
2106 s
->reloc_statement
.addend_value
= value
.value
;
2107 if (value
.valid
== false)
2108 einfo ("%F%P: invalid reloc statement\n");
2110 dot
+= bfd_get_reloc_size (s
->reloc_statement
.howto
);
2113 case lang_input_section_enum
:
2115 asection
*in
= s
->input_section
.section
;
2117 if (in
->_cooked_size
!= 0)
2118 dot
+= in
->_cooked_size
;
2120 dot
+= in
->_raw_size
;
2124 case lang_input_statement_enum
:
2126 case lang_fill_statement_enum
:
2127 fill
= s
->fill_statement
.fill
;
2129 case lang_assignment_statement_enum
:
2131 exp_fold_tree (s
->assignment_statement
.exp
,
2132 output_section_statement
,
2133 lang_final_phase_enum
,
2139 case lang_padding_statement_enum
:
2140 dot
+= s
->padding_statement
.size
;
2143 case lang_group_statement_enum
:
2144 dot
= lang_do_assignments (s
->group_statement
.children
.head
,
2145 output_section_statement
,
2153 case lang_address_statement_enum
:
2164 struct bfd_link_hash_entry
*h
;
2167 if (link_info
.relocateable
|| link_info
.shared
)
2172 if (entry_symbol
== (char *) NULL
)
2174 /* No entry has been specified. Look for start, but don't warn
2175 if we don't find it. */
2176 entry_symbol
= "start";
2180 h
= bfd_link_hash_lookup (link_info
.hash
, entry_symbol
, false, false, true);
2181 if (h
!= (struct bfd_link_hash_entry
*) NULL
2182 && (h
->type
== bfd_link_hash_defined
2183 || h
->type
== bfd_link_hash_defweak
))
2187 val
= (h
->u
.def
.value
2188 + bfd_get_section_vma (output_bfd
,
2189 h
->u
.def
.section
->output_section
)
2190 + h
->u
.def
.section
->output_offset
);
2191 if (! bfd_set_start_address (output_bfd
, val
))
2192 einfo ("%P%F:%s: can't set start address\n", entry_symbol
);
2198 /* Can't find the entry symbol. Use the first address in the
2200 ts
= bfd_get_section_by_name (output_bfd
, ".text");
2201 if (ts
!= (asection
*) NULL
)
2204 einfo ("%P: warning: cannot find entry symbol %s; defaulting to %V\n",
2205 entry_symbol
, bfd_get_section_vma (output_bfd
, ts
));
2206 if (! bfd_set_start_address (output_bfd
,
2207 bfd_get_section_vma (output_bfd
, ts
)))
2208 einfo ("%P%F: can't set start address\n");
2213 einfo ("%P: warning: cannot find entry symbol %s; not setting start address\n",
2219 /* Check that the architecture of all the input files is compatible
2220 with the output file. Also call the backend to let it do any
2221 other checking that is needed. */
2226 lang_statement_union_type
*file
;
2228 CONST bfd_arch_info_type
*compatible
;
2230 for (file
= file_chain
.head
;
2231 file
!= (lang_statement_union_type
*) NULL
;
2232 file
= file
->input_statement
.next
)
2234 input_bfd
= file
->input_statement
.the_bfd
;
2235 compatible
= bfd_arch_get_compatible (input_bfd
,
2237 if (compatible
== NULL
)
2238 einfo ("%P: warning: %s architecture of input file `%B' is incompatible with %s output\n",
2239 bfd_printable_name (input_bfd
), input_bfd
,
2240 bfd_printable_name (output_bfd
));
2243 bfd_merge_private_bfd_data (input_bfd
, output_bfd
);
2247 /* Look through all the global common symbols and attach them to the
2248 correct section. The -sort-common command line switch may be used
2249 to roughly sort the entries by size. */
2254 if (link_info
.relocateable
2255 && ! command_line
.force_common_definition
)
2258 if (! config
.sort_common
)
2259 bfd_link_hash_traverse (link_info
.hash
, lang_one_common
, (PTR
) NULL
);
2264 for (power
= 4; power
>= 0; power
--)
2265 bfd_link_hash_traverse (link_info
.hash
, lang_one_common
,
2270 /* Place one common symbol in the correct section. */
2273 lang_one_common (h
, info
)
2274 struct bfd_link_hash_entry
*h
;
2277 unsigned int power_of_two
;
2281 if (h
->type
!= bfd_link_hash_common
)
2285 power_of_two
= h
->u
.c
.p
->alignment_power
;
2287 if (config
.sort_common
2288 && power_of_two
< *(int *) info
)
2291 section
= h
->u
.c
.p
->section
;
2293 /* Increase the size of the section. */
2294 section
->_raw_size
= ALIGN_N (section
->_raw_size
,
2295 (bfd_size_type
) (1 << power_of_two
));
2297 /* Adjust the alignment if necessary. */
2298 if (power_of_two
> section
->alignment_power
)
2299 section
->alignment_power
= power_of_two
;
2301 /* Change the symbol from common to defined. */
2302 h
->type
= bfd_link_hash_defined
;
2303 h
->u
.def
.section
= section
;
2304 h
->u
.def
.value
= section
->_raw_size
;
2306 /* Increase the size of the section. */
2307 section
->_raw_size
+= size
;
2309 /* Make sure the section is allocated in memory. */
2310 section
->flags
|= SEC_ALLOC
;
2312 if (config
.map_file
!= NULL
)
2313 fprintf (config
.map_file
, "Allocating common %s: %lx at %lx %s\n",
2314 h
->root
.string
, (unsigned long) size
,
2315 (unsigned long) h
->u
.def
.value
, section
->owner
->filename
);
2321 run through the input files and ensure that every input
2322 section has somewhere to go. If one is found without
2323 a destination then create an input request and place it
2324 into the statement tree.
2328 lang_place_orphans ()
2330 lang_input_statement_type
*file
;
2332 for (file
= (lang_input_statement_type
*) file_chain
.head
;
2333 file
!= (lang_input_statement_type
*) NULL
;
2334 file
= (lang_input_statement_type
*) file
->next
)
2338 for (s
= file
->the_bfd
->sections
;
2339 s
!= (asection
*) NULL
;
2342 if (s
->output_section
== (asection
*) NULL
)
2344 /* This section of the file is not attatched, root
2345 around for a sensible place for it to go */
2347 if (file
->just_syms_flag
)
2349 /* We are only retrieving symbol values from this
2350 file. We want the symbols to act as though the
2351 values in the file are absolute. */
2352 s
->output_section
= bfd_abs_section_ptr
;
2353 s
->output_offset
= s
->vma
;
2355 else if (file
->common_section
== s
)
2357 /* This is a lonely common section which must
2358 have come from an archive. We attatch to the
2359 section with the wildcard */
2360 if (! link_info
.relocateable
2361 && ! command_line
.force_common_definition
)
2363 if (default_common_section
==
2364 (lang_output_section_statement_type
*) NULL
)
2366 info_msg ("%P: no [COMMON] command, defaulting to .bss\n");
2368 default_common_section
=
2369 lang_output_section_statement_lookup (".bss");
2372 wild_doit (&default_common_section
->children
, s
,
2373 default_common_section
, file
);
2376 else if (ldemul_place_orphan (file
, s
))
2380 lang_output_section_statement_type
*os
=
2381 lang_output_section_statement_lookup (s
->name
);
2383 wild_doit (&os
->children
, s
, os
, file
);
2392 lang_set_flags (ptr
, flags
)
2396 boolean state
= false;
2411 /* ptr->flag_read = state; */
2414 /* ptr->flag_write = state; */
2417 /* ptr->flag_executable= state;*/
2421 /* ptr->flag_loadable= state;*/
2424 einfo ("%P%F: invalid syntax in flags\n");
2431 /* Call a function on each input file. This function will be called
2432 on an archive, but not on the elements. */
2435 lang_for_each_input_file (func
)
2436 void (*func
) PARAMS ((lang_input_statement_type
*));
2438 lang_input_statement_type
*f
;
2440 for (f
= (lang_input_statement_type
*) input_file_chain
.head
;
2442 f
= (lang_input_statement_type
*) f
->next_real_file
)
2446 /* Call a function on each file. The function will be called on all
2447 the elements of an archive which are included in the link, but will
2448 not be called on the archive file itself. */
2451 lang_for_each_file (func
)
2452 void (*func
) PARAMS ((lang_input_statement_type
*));
2454 lang_input_statement_type
*f
;
2456 for (f
= (lang_input_statement_type
*) file_chain
.head
;
2457 f
!= (lang_input_statement_type
*) NULL
;
2458 f
= (lang_input_statement_type
*) f
->next
)
2469 lang_for_each_input_section (func
)
2470 void (*func
) PARAMS ((bfd
* ab
, asection
* as
));
2472 lang_input_statement_type
*f
;
2474 for (f
= (lang_input_statement_type
*) file_chain
.head
;
2475 f
!= (lang_input_statement_type
*) NULL
;
2476 f
= (lang_input_statement_type
*) f
->next
)
2480 for (s
= f
->the_bfd
->sections
;
2481 s
!= (asection
*) NULL
;
2484 func (f
->the_bfd
, s
);
2492 ldlang_add_file (entry
)
2493 lang_input_statement_type
* entry
;
2497 lang_statement_append (&file_chain
,
2498 (lang_statement_union_type
*) entry
,
2501 /* The BFD linker needs to have a list of all input BFDs involved in
2503 ASSERT (entry
->the_bfd
->link_next
== (bfd
*) NULL
);
2504 ASSERT (entry
->the_bfd
!= output_bfd
);
2505 for (pp
= &link_info
.input_bfds
;
2506 *pp
!= (bfd
*) NULL
;
2507 pp
= &(*pp
)->link_next
)
2509 *pp
= entry
->the_bfd
;
2510 entry
->the_bfd
->usrdata
= (PTR
) entry
;
2511 bfd_set_gp_size (entry
->the_bfd
, g_switch_value
);
2515 lang_add_output (name
, from_script
)
2519 /* Make -o on command line override OUTPUT in script. */
2520 if (had_output_filename
== false || !from_script
)
2522 output_filename
= name
;
2523 had_output_filename
= true;
2528 static lang_output_section_statement_type
*current_section
;
2530 static int topower(x
)
2535 if (x
< 0) return -1;
2536 for (l
= 0; l
< 32; l
++)
2538 if (i
>= x
) return l
;
2544 lang_enter_output_section_statement (output_section_statement_name
,
2545 address_exp
, flags
, block_value
,
2546 align
, subalign
, ebase
)
2547 const char *output_section_statement_name
;
2548 etree_type
* address_exp
;
2550 bfd_vma block_value
;
2552 etree_type
*subalign
;
2555 lang_output_section_statement_type
*os
;
2559 lang_output_section_statement_lookup (output_section_statement_name
);
2563 /* Add this statement to tree */
2564 /* add_statement(lang_output_section_statement_enum,
2565 output_section_statement);*/
2566 /* Make next things chain into subchain of this */
2568 if (os
->addr_tree
==
2569 (etree_type
*) NULL
)
2575 if (flags
& SEC_NEVER_LOAD
)
2579 os
->block_value
= block_value
? block_value
: 1;
2580 stat_ptr
= &os
->children
;
2582 os
->subsection_alignment
= topower(
2583 exp_get_value_int(subalign
, -1,
2584 "subsection alignment",
2586 os
->section_alignment
= topower(
2587 exp_get_value_int(align
, -1,
2588 "section alignment", 0));
2590 os
->load_base
= ebase
;
2597 lang_output_statement_type
*new =
2598 new_stat (lang_output_statement
, stat_ptr
);
2600 new->name
= output_filename
;
2603 /* Reset the current counters in the regions */
2605 reset_memory_regions ()
2607 lang_memory_region_type
*p
= lang_memory_region_list
;
2609 for (p
= lang_memory_region_list
;
2610 p
!= (lang_memory_region_type
*) NULL
;
2613 p
->old_length
= (bfd_size_type
) (p
->current
- p
->origin
);
2614 p
->current
= p
->origin
;
2621 lang_reasonable_defaults ();
2622 current_target
= default_target
;
2624 lang_for_each_statement (ldlang_open_output
); /* Open the output file */
2626 ldemul_create_output_section_statements ();
2628 /* Add to the hash table all undefineds on the command line */
2629 lang_place_undefineds ();
2631 /* Create a bfd for each input file */
2632 current_target
= default_target
;
2633 open_input_bfds (statement_list
.head
, false);
2635 ldemul_after_open ();
2637 /* Build all sets based on the information gathered from the input
2639 ldctor_build_sets ();
2641 /* Size up the common data */
2644 /* Run through the contours of the script and attatch input sections
2645 to the correct output sections
2647 map_input_to_output_sections (statement_list
.head
, (char *) NULL
,
2648 (lang_output_section_statement_type
*) NULL
);
2651 /* Find any sections not attatched explicitly and handle them */
2652 lang_place_orphans ();
2654 ldemul_before_allocation ();
2656 /* Now run around and relax if we can */
2657 if (command_line
.relax
)
2659 /* First time round is a trial run to get the 'worst case'
2660 addresses of the objects if there was no relaxing. */
2661 lang_size_sections (statement_list
.head
,
2663 &(statement_list
.head
), 0, (bfd_vma
) 0, false);
2666 reset_memory_regions ();
2668 /* Keep relaxing until bfd_relax_section gives up. */
2671 relax_again
= false;
2673 /* Do all the assignments with our current guesses as to
2675 lang_do_assignments (statement_list
.head
,
2677 (fill_type
) 0, (bfd_vma
) 0);
2679 /* Perform another relax pass - this time we know where the
2680 globals are, so can make better guess. */
2681 lang_size_sections (statement_list
.head
,
2683 &(statement_list
.head
), 0, (bfd_vma
) 0, true);
2685 while (relax_again
);
2689 /* Size up the sections. */
2690 lang_size_sections (statement_list
.head
,
2692 &(statement_list
.head
), 0, (bfd_vma
) 0, false);
2695 /* See if anything special should be done now we know how big
2697 ldemul_after_allocation ();
2699 /* Do all the assignments, now that we know the final restingplaces
2700 of all the symbols */
2702 lang_do_assignments (statement_list
.head
,
2704 (fill_type
) 0, (bfd_vma
) 0);
2706 /* Make sure that we're not mixing architectures */
2716 /* EXPORTED TO YACC */
2719 lang_add_wild (section_name
, filename
)
2720 CONST
char *CONST section_name
;
2721 CONST
char *CONST filename
;
2723 lang_wild_statement_type
*new = new_stat (lang_wild_statement
,
2726 if (section_name
!= (char *) NULL
&& strcmp (section_name
, "COMMON") == 0)
2728 placed_commons
= true;
2730 if (filename
!= (char *) NULL
)
2732 lang_has_input_file
= true;
2734 new->section_name
= section_name
;
2735 new->filename
= filename
;
2736 lang_list_init (&new->children
);
2740 lang_section_start (name
, address
)
2742 etree_type
* address
;
2744 lang_address_statement_type
*ad
= new_stat (lang_address_statement
, stat_ptr
);
2746 ad
->section_name
= name
;
2747 ad
->address
= address
;
2750 /* Set the start symbol to NAME. CMDLINE is nonzero if this is called
2751 because of a -e argument on the command line, or zero if this is
2752 called by ENTRY in a linker script. Command line arguments take
2755 /* WINDOWS_NT. When an entry point has been specified, we will also force
2756 this symbol to be defined by calling ldlang_add_undef (equivalent to
2757 having switch -u entry_name on the command line). The reason we do
2758 this is so that the user doesn't have to because they would have to use
2759 the -u switch if they were specifying an entry point other than
2760 _mainCRTStartup. Specifically, if creating a windows application, entry
2761 point _WinMainCRTStartup must be specified.
2762 What I have found for non console applications (entry not _mainCRTStartup)
2763 is that the .obj that contains mainCRTStartup is brought in since it is
2764 the first encountered in libc.lib and it has other symbols in it which will
2765 be pulled in by the link process. To avoid this, adding -u with the entry
2766 point name specified forces the correct .obj to be used. We can avoid
2767 making the user do this by always adding the entry point name as an
2768 undefined symbol. */
2771 lang_add_entry (name
, cmdline
)
2775 static int from_cmdline
;
2777 if (entry_symbol
== NULL
2781 entry_symbol
= name
;
2782 from_cmdline
= cmdline
;
2784 #ifdef 0 /* WINDOWS_NT */
2785 /* don't do this yet. It seems to work (the executables run), but the
2786 image created is very different from what I was getting before indicating
2787 that something else is being pulled in. When everything else is working,
2788 then try to put this back in to see if it will do the right thing for
2789 other more complicated applications */
2790 ldlang_add_undef (name
);
2795 lang_add_target (name
)
2798 lang_target_statement_type
*new = new_stat (lang_target_statement
,
2814 map_option_f
= true;
2825 lang_fill_statement_type
*new = new_stat (lang_fill_statement
,
2832 lang_add_data (type
, exp
)
2834 union etree_union
*exp
;
2837 lang_data_statement_type
*new = new_stat (lang_data_statement
,
2845 /* Create a new reloc statement. RELOC is the BFD relocation type to
2846 generate. HOWTO is the corresponding howto structure (we could
2847 look this up, but the caller has already done so). SECTION is the
2848 section to generate a reloc against, or NAME is the name of the
2849 symbol to generate a reloc against. Exactly one of SECTION and
2850 NAME must be NULL. ADDEND is an expression for the addend. */
2853 lang_add_reloc (reloc
, howto
, section
, name
, addend
)
2854 bfd_reloc_code_real_type reloc
;
2855 reloc_howto_type
*howto
;
2858 union etree_union
*addend
;
2860 lang_reloc_statement_type
*p
= new_stat (lang_reloc_statement
, stat_ptr
);
2864 p
->section
= section
;
2866 p
->addend_exp
= addend
;
2868 p
->addend_value
= 0;
2869 p
->output_section
= NULL
;
2874 lang_add_assignment (exp
)
2877 lang_assignment_statement_type
*new = new_stat (lang_assignment_statement
,
2884 lang_add_attribute (attribute
)
2885 enum statement_enum attribute
;
2887 new_statement (attribute
, sizeof (lang_statement_union_type
), stat_ptr
);
2894 if (startup_file
!= (char *) NULL
)
2896 einfo ("%P%Fmultiple STARTUP files\n");
2898 first_file
->filename
= name
;
2899 first_file
->local_sym_name
= name
;
2900 first_file
->real
= true;
2902 startup_file
= name
;
2909 lang_float_flag
= maybe
;
2913 lang_leave_output_section_statement (fill
, memspec
)
2915 CONST
char *memspec
;
2917 current_section
->fill
= fill
;
2918 current_section
->region
= lang_memory_region_lookup (memspec
);
2919 stat_ptr
= &statement_list
;
2923 Create an absolute symbol with the given name with the value of the
2924 address of first byte of the section named.
2926 If the symbol already exists, then do nothing.
2929 lang_abs_symbol_at_beginning_of (secname
, name
)
2930 const char *secname
;
2933 struct bfd_link_hash_entry
*h
;
2935 h
= bfd_link_hash_lookup (link_info
.hash
, name
, true, true, true);
2936 if (h
== (struct bfd_link_hash_entry
*) NULL
)
2937 einfo ("%P%F: bfd_link_hash_lookup failed: %E\n");
2939 if (h
->type
== bfd_link_hash_new
2940 || h
->type
== bfd_link_hash_undefined
)
2944 h
->type
= bfd_link_hash_defined
;
2946 sec
= bfd_get_section_by_name (output_bfd
, secname
);
2947 if (sec
== (asection
*) NULL
)
2950 h
->u
.def
.value
= bfd_get_section_vma (output_bfd
, sec
);
2952 h
->u
.def
.section
= bfd_abs_section_ptr
;
2957 Create an absolute symbol with the given name with the value of the
2958 address of the first byte after the end of the section named.
2960 If the symbol already exists, then do nothing.
2963 lang_abs_symbol_at_end_of (secname
, name
)
2964 const char *secname
;
2967 struct bfd_link_hash_entry
*h
;
2969 h
= bfd_link_hash_lookup (link_info
.hash
, name
, true, true, true);
2970 if (h
== (struct bfd_link_hash_entry
*) NULL
)
2971 einfo ("%P%F: bfd_link_hash_lookup failed: %E\n");
2973 if (h
->type
== bfd_link_hash_new
2974 || h
->type
== bfd_link_hash_undefined
)
2978 h
->type
= bfd_link_hash_defined
;
2980 sec
= bfd_get_section_by_name (output_bfd
, secname
);
2981 if (sec
== (asection
*) NULL
)
2984 h
->u
.def
.value
= (bfd_get_section_vma (output_bfd
, sec
)
2985 + bfd_section_size (output_bfd
, sec
));
2987 h
->u
.def
.section
= bfd_abs_section_ptr
;
2992 lang_statement_append (list
, element
, field
)
2993 lang_statement_list_type
* list
;
2994 lang_statement_union_type
* element
;
2995 lang_statement_union_type
** field
;
2997 *(list
->tail
) = element
;
3001 /* Set the output format type. -oformat overrides scripts. */
3004 lang_add_output_format (format
, big
, little
, from_script
)
3010 if (output_target
== NULL
|| !from_script
)
3012 if (command_line
.endian
== ENDIAN_BIG
3015 else if (command_line
.endian
== ENDIAN_LITTLE
3019 output_target
= format
;
3023 /* Enter a group. This creates a new lang_group_statement, and sets
3024 stat_ptr to build new statements within the group. */
3029 lang_group_statement_type
*g
;
3031 g
= new_stat (lang_group_statement
, stat_ptr
);
3032 lang_list_init (&g
->children
);
3033 stat_ptr
= &g
->children
;
3036 /* Leave a group. This just resets stat_ptr to start writing to the
3037 regular list of statements again. Note that this will not work if
3038 groups can occur inside anything else which can adjust stat_ptr,
3039 but currently they can't. */
3044 stat_ptr
= &statement_list
;