1 /* Copyright (C) 1991 Free Software Foundation, Inc.
3 This file is part of GLD, the Gnu Linker.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20 This module writes out the final image by reading sections from the
21 input files, relocating them and writing them out
23 There are two main paths through this module, one for normal
24 operation and one for partial linking.
26 During normal operation, raw section data is read along with the
27 associated relocation information, the relocation info applied and
28 the section data written out on a section by section basis.
30 When partially linking, all the relocation records are read to work
31 out how big the output relocation vector will be. Then raw data is
32 read, relocated and written section by section.
34 Written by Steve Chamberlain sac@cygnus.com
53 read_relocs (abfd
, section
, symbols
)
58 /* Work out the output section ascociated with this input section */
59 asection
*output_section
= section
->output_section
;
61 bfd_size_type reloc_size
= bfd_get_reloc_upper_bound (abfd
, section
);
62 arelent
**reloc_vector
= (arelent
**) ldmalloc (reloc_size
);
64 if (bfd_canonicalize_reloc (abfd
,
69 output_section
->reloc_count
+= section
->reloc_count
;
78 Run through each section of each file and work work out the total
79 number of relocation records which will finally be in each output
83 LANG_FOR_EACH_INPUT_SECTION
84 (statement
, abfd
, section
,
85 (read_relocs (abfd
, section
, statement
->asymbols
)));
90 Now run though all the output sections and allocate the space for
93 LANG_FOR_EACH_OUTPUT_SECTION
95 (section
->orelocation
=
96 (arelent
**) ldmalloc ((bfd_size_type
) (sizeof (arelent
**) *
97 section
->reloc_count
)),
98 section
->reloc_count
= 0));
104 PTR data_area
= (PTR
) ldmalloc (largest_section
);
108 if (config
.relocateable_output
== true)
111 write_relax (output_bfd
, data_area
, config
.relocateable_output
);
115 /* Output the symbol table (both globals and locals). */
117 /* Print a map, if requested and possible. */
121 ldsym_print_symbol_table ();