1 | /* BFD semi-generic back-end for a.out binaries.
|
---|
2 | Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
|
---|
3 | 2001, 2002, 2003
|
---|
4 | Free Software Foundation, Inc.
|
---|
5 | Written by Cygnus Support.
|
---|
6 |
|
---|
7 | This file is part of BFD, the Binary File Descriptor library.
|
---|
8 |
|
---|
9 | This program is free software; you can redistribute it and/or modify
|
---|
10 | it under the terms of the GNU General Public License as published by
|
---|
11 | the Free Software Foundation; either version 2 of the License, or
|
---|
12 | (at your option) any later version.
|
---|
13 |
|
---|
14 | This program is distributed in the hope that it will be useful,
|
---|
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
17 | GNU General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU General Public License
|
---|
20 | along with this program; if not, write to the Free Software
|
---|
21 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
---|
22 |
|
---|
23 | /*
|
---|
24 | SECTION
|
---|
25 | a.out backends
|
---|
26 |
|
---|
27 | DESCRIPTION
|
---|
28 |
|
---|
29 | BFD supports a number of different flavours of a.out format,
|
---|
30 | though the major differences are only the sizes of the
|
---|
31 | structures on disk, and the shape of the relocation
|
---|
32 | information.
|
---|
33 |
|
---|
34 | The support is split into a basic support file @file{aoutx.h}
|
---|
35 | and other files which derive functions from the base. One
|
---|
36 | derivation file is @file{aoutf1.h} (for a.out flavour 1), and
|
---|
37 | adds to the basic a.out functions support for sun3, sun4, 386
|
---|
38 | and 29k a.out files, to create a target jump vector for a
|
---|
39 | specific target.
|
---|
40 |
|
---|
41 | This information is further split out into more specific files
|
---|
42 | for each machine, including @file{sunos.c} for sun3 and sun4,
|
---|
43 | @file{newsos3.c} for the Sony NEWS, and @file{demo64.c} for a
|
---|
44 | demonstration of a 64 bit a.out format.
|
---|
45 |
|
---|
46 | The base file @file{aoutx.h} defines general mechanisms for
|
---|
47 | reading and writing records to and from disk and various
|
---|
48 | other methods which BFD requires. It is included by
|
---|
49 | @file{aout32.c} and @file{aout64.c} to form the names
|
---|
50 | <<aout_32_swap_exec_header_in>>, <<aout_64_swap_exec_header_in>>, etc.
|
---|
51 |
|
---|
52 | As an example, this is what goes on to make the back end for a
|
---|
53 | sun4, from @file{aout32.c}:
|
---|
54 |
|
---|
55 | | #define ARCH_SIZE 32
|
---|
56 | | #include "aoutx.h"
|
---|
57 |
|
---|
58 | Which exports names:
|
---|
59 |
|
---|
60 | | ...
|
---|
61 | | aout_32_canonicalize_reloc
|
---|
62 | | aout_32_find_nearest_line
|
---|
63 | | aout_32_get_lineno
|
---|
64 | | aout_32_get_reloc_upper_bound
|
---|
65 | | ...
|
---|
66 |
|
---|
67 | from @file{sunos.c}:
|
---|
68 |
|
---|
69 | | #define TARGET_NAME "a.out-sunos-big"
|
---|
70 | | #define VECNAME sunos_big_vec
|
---|
71 | | #include "aoutf1.h"
|
---|
72 |
|
---|
73 | requires all the names from @file{aout32.c}, and produces the jump vector
|
---|
74 |
|
---|
75 | | sunos_big_vec
|
---|
76 |
|
---|
77 | The file @file{host-aout.c} is a special case. It is for a large set
|
---|
78 | of hosts that use ``more or less standard'' a.out files, and
|
---|
79 | for which cross-debugging is not interesting. It uses the
|
---|
80 | standard 32-bit a.out support routines, but determines the
|
---|
81 | file offsets and addresses of the text, data, and BSS
|
---|
82 | sections, the machine architecture and machine type, and the
|
---|
83 | entry point address, in a host-dependent manner. Once these
|
---|
84 | values have been determined, generic code is used to handle
|
---|
85 | the object file.
|
---|
86 |
|
---|
87 | When porting it to run on a new system, you must supply:
|
---|
88 |
|
---|
89 | | HOST_PAGE_SIZE
|
---|
90 | | HOST_SEGMENT_SIZE
|
---|
91 | | HOST_MACHINE_ARCH (optional)
|
---|
92 | | HOST_MACHINE_MACHINE (optional)
|
---|
93 | | HOST_TEXT_START_ADDR
|
---|
94 | | HOST_STACK_END_ADDR
|
---|
95 |
|
---|
96 | in the file @file{../include/sys/h-@var{XXX}.h} (for your host). These
|
---|
97 | values, plus the structures and macros defined in @file{a.out.h} on
|
---|
98 | your host system, will produce a BFD target that will access
|
---|
99 | ordinary a.out files on your host. To configure a new machine
|
---|
100 | to use @file{host-aout.c}, specify:
|
---|
101 |
|
---|
102 | | TDEFAULTS = -DDEFAULT_VECTOR=host_aout_big_vec
|
---|
103 | | TDEPFILES= host-aout.o trad-core.o
|
---|
104 |
|
---|
105 | in the @file{config/@var{XXX}.mt} file, and modify @file{configure.in}
|
---|
106 | to use the
|
---|
107 | @file{@var{XXX}.mt} file (by setting "<<bfd_target=XXX>>") when your
|
---|
108 | configuration is selected. */
|
---|
109 |
|
---|
110 | /* Some assumptions:
|
---|
111 | * Any BFD with D_PAGED set is ZMAGIC, and vice versa.
|
---|
112 | Doesn't matter what the setting of WP_TEXT is on output, but it'll
|
---|
113 | get set on input.
|
---|
114 | * Any BFD with D_PAGED clear and WP_TEXT set is NMAGIC.
|
---|
115 | * Any BFD with both flags clear is OMAGIC.
|
---|
116 | (Just want to make these explicit, so the conditions tested in this
|
---|
117 | file make sense if you're more familiar with a.out than with BFD.) */
|
---|
118 |
|
---|
119 | #define KEEPIT udata.i
|
---|
120 |
|
---|
121 | #include "bfd.h"
|
---|
122 | #include "sysdep.h"
|
---|
123 | #include "safe-ctype.h"
|
---|
124 | #include "bfdlink.h"
|
---|
125 |
|
---|
126 | #include "libaout.h"
|
---|
127 | #include "libbfd.h"
|
---|
128 | #include "aout/aout64.h"
|
---|
129 | #include "aout/stab_gnu.h"
|
---|
130 | #include "aout/ar.h"
|
---|
131 |
|
---|
132 | static bfd_boolean aout_get_external_symbols
|
---|
133 | PARAMS ((bfd *));
|
---|
134 | static bfd_boolean translate_from_native_sym_flags
|
---|
135 | PARAMS ((bfd *, aout_symbol_type *));
|
---|
136 | static bfd_boolean translate_to_native_sym_flags
|
---|
137 | PARAMS ((bfd *, asymbol *, struct external_nlist *));
|
---|
138 | static void adjust_o_magic
|
---|
139 | PARAMS ((bfd *, struct internal_exec *));
|
---|
140 | static void adjust_z_magic
|
---|
141 | PARAMS ((bfd *, struct internal_exec *));
|
---|
142 | static void adjust_n_magic
|
---|
143 | PARAMS ((bfd *, struct internal_exec *));
|
---|
144 | reloc_howto_type * NAME(aout,reloc_type_lookup)
|
---|
145 | PARAMS ((bfd *, bfd_reloc_code_real_type));
|
---|
146 |
|
---|
147 | /*
|
---|
148 | SUBSECTION
|
---|
149 | Relocations
|
---|
150 |
|
---|
151 | DESCRIPTION
|
---|
152 | The file @file{aoutx.h} provides for both the @emph{standard}
|
---|
153 | and @emph{extended} forms of a.out relocation records.
|
---|
154 |
|
---|
155 | The standard records contain only an
|
---|
156 | address, a symbol index, and a type field. The extended records
|
---|
157 | (used on 29ks and sparcs) also have a full integer for an
|
---|
158 | addend. */
|
---|
159 |
|
---|
160 | #ifndef CTOR_TABLE_RELOC_HOWTO
|
---|
161 | #define CTOR_TABLE_RELOC_IDX 2
|
---|
162 | #define CTOR_TABLE_RELOC_HOWTO(BFD) \
|
---|
163 | ((obj_reloc_entry_size (BFD) == RELOC_EXT_SIZE \
|
---|
164 | ? howto_table_ext : howto_table_std) \
|
---|
165 | + CTOR_TABLE_RELOC_IDX)
|
---|
166 | #endif
|
---|
167 |
|
---|
168 | #ifndef MY_swap_std_reloc_in
|
---|
169 | #define MY_swap_std_reloc_in NAME(aout,swap_std_reloc_in)
|
---|
170 | #endif
|
---|
171 |
|
---|
172 | #ifndef MY_swap_ext_reloc_in
|
---|
173 | #define MY_swap_ext_reloc_in NAME(aout,swap_ext_reloc_in)
|
---|
174 | #endif
|
---|
175 |
|
---|
176 | #ifndef MY_swap_std_reloc_out
|
---|
177 | #define MY_swap_std_reloc_out NAME(aout,swap_std_reloc_out)
|
---|
178 | #endif
|
---|
179 |
|
---|
180 | #ifndef MY_swap_ext_reloc_out
|
---|
181 | #define MY_swap_ext_reloc_out NAME(aout,swap_ext_reloc_out)
|
---|
182 | #endif
|
---|
183 |
|
---|
184 | #ifndef MY_final_link_relocate
|
---|
185 | #define MY_final_link_relocate _bfd_final_link_relocate
|
---|
186 | #endif
|
---|
187 |
|
---|
188 | #ifndef MY_relocate_contents
|
---|
189 | #define MY_relocate_contents _bfd_relocate_contents
|
---|
190 | #endif
|
---|
191 |
|
---|
192 | #define howto_table_ext NAME(aout,ext_howto_table)
|
---|
193 | #define howto_table_std NAME(aout,std_howto_table)
|
---|
194 |
|
---|
195 | reloc_howto_type howto_table_ext[] =
|
---|
196 | {
|
---|
197 | /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone. */
|
---|
198 | HOWTO(RELOC_8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield,0,"8", FALSE, 0,0x000000ff, FALSE),
|
---|
199 | HOWTO(RELOC_16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,0,"16", FALSE, 0,0x0000ffff, FALSE),
|
---|
200 | HOWTO(RELOC_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,0,"32", FALSE, 0,0xffffffff, FALSE),
|
---|
201 | HOWTO(RELOC_DISP8, 0, 0, 8, TRUE, 0, complain_overflow_signed,0,"DISP8", FALSE, 0,0x000000ff, FALSE),
|
---|
202 | HOWTO(RELOC_DISP16, 0, 1, 16, TRUE, 0, complain_overflow_signed,0,"DISP16", FALSE, 0,0x0000ffff, FALSE),
|
---|
203 | HOWTO(RELOC_DISP32, 0, 2, 32, TRUE, 0, complain_overflow_signed,0,"DISP32", FALSE, 0,0xffffffff, FALSE),
|
---|
204 | HOWTO(RELOC_WDISP30,2, 2, 30, TRUE, 0, complain_overflow_signed,0,"WDISP30", FALSE, 0,0x3fffffff, FALSE),
|
---|
205 | HOWTO(RELOC_WDISP22,2, 2, 22, TRUE, 0, complain_overflow_signed,0,"WDISP22", FALSE, 0,0x003fffff, FALSE),
|
---|
206 | HOWTO(RELOC_HI22, 10, 2, 22, FALSE, 0, complain_overflow_bitfield,0,"HI22", FALSE, 0,0x003fffff, FALSE),
|
---|
207 | HOWTO(RELOC_22, 0, 2, 22, FALSE, 0, complain_overflow_bitfield,0,"22", FALSE, 0,0x003fffff, FALSE),
|
---|
208 | HOWTO(RELOC_13, 0, 2, 13, FALSE, 0, complain_overflow_bitfield,0,"13", FALSE, 0,0x00001fff, FALSE),
|
---|
209 | HOWTO(RELOC_LO10, 0, 2, 10, FALSE, 0, complain_overflow_dont,0,"LO10", FALSE, 0,0x000003ff, FALSE),
|
---|
210 | HOWTO(RELOC_SFA_BASE,0, 2, 32, FALSE, 0, complain_overflow_bitfield,0,"SFA_BASE", FALSE, 0,0xffffffff, FALSE),
|
---|
211 | HOWTO(RELOC_SFA_OFF13,0,2, 32, FALSE, 0, complain_overflow_bitfield,0,"SFA_OFF13",FALSE, 0,0xffffffff, FALSE),
|
---|
212 | HOWTO(RELOC_BASE10, 0, 2, 10, FALSE, 0, complain_overflow_dont,0,"BASE10", FALSE, 0,0x000003ff, FALSE),
|
---|
213 | HOWTO(RELOC_BASE13, 0, 2, 13, FALSE, 0, complain_overflow_signed,0,"BASE13", FALSE, 0,0x00001fff, FALSE),
|
---|
214 | HOWTO(RELOC_BASE22, 10, 2, 22, FALSE, 0, complain_overflow_bitfield,0,"BASE22", FALSE, 0,0x003fffff, FALSE),
|
---|
215 | HOWTO(RELOC_PC10, 0, 2, 10, TRUE, 0, complain_overflow_dont,0,"PC10", FALSE, 0,0x000003ff, TRUE),
|
---|
216 | HOWTO(RELOC_PC22, 10, 2, 22, TRUE, 0, complain_overflow_signed,0,"PC22", FALSE, 0,0x003fffff, TRUE),
|
---|
217 | HOWTO(RELOC_JMP_TBL,2, 2, 30, TRUE, 0, complain_overflow_signed,0,"JMP_TBL", FALSE, 0,0x3fffffff, FALSE),
|
---|
218 | HOWTO(RELOC_SEGOFF16,0, 2, 0, FALSE, 0, complain_overflow_bitfield,0,"SEGOFF16", FALSE, 0,0x00000000, FALSE),
|
---|
219 | HOWTO(RELOC_GLOB_DAT,0, 2, 0, FALSE, 0, complain_overflow_bitfield,0,"GLOB_DAT", FALSE, 0,0x00000000, FALSE),
|
---|
220 | HOWTO(RELOC_JMP_SLOT,0, 2, 0, FALSE, 0, complain_overflow_bitfield,0,"JMP_SLOT", FALSE, 0,0x00000000, FALSE),
|
---|
221 | HOWTO(RELOC_RELATIVE,0, 2, 0, FALSE, 0, complain_overflow_bitfield,0,"RELATIVE", FALSE, 0,0x00000000, FALSE),
|
---|
222 | HOWTO(0, 0, 0, 0, FALSE, 0, complain_overflow_dont, 0, "R_SPARC_NONE", FALSE,0,0x00000000,TRUE),
|
---|
223 | HOWTO(0, 0, 0, 0, FALSE, 0, complain_overflow_dont, 0, "R_SPARC_NONE", FALSE,0,0x00000000,TRUE),
|
---|
224 | #define RELOC_SPARC_REV32 RELOC_WDISP19
|
---|
225 | HOWTO(RELOC_SPARC_REV32, 0, 2, 32, FALSE, 0, complain_overflow_dont,0,"R_SPARC_REV32", FALSE, 0,0xffffffff, FALSE),
|
---|
226 | };
|
---|
227 |
|
---|
228 | /* Convert standard reloc records to "arelent" format (incl byte swap). */
|
---|
229 |
|
---|
230 | reloc_howto_type howto_table_std[] =
|
---|
231 | {
|
---|
232 | /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone. */
|
---|
233 | HOWTO ( 0, 0, 0, 8, FALSE, 0, complain_overflow_bitfield,0,"8", TRUE, 0x000000ff,0x000000ff, FALSE),
|
---|
234 | HOWTO ( 1, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,0,"16", TRUE, 0x0000ffff,0x0000ffff, FALSE),
|
---|
235 | HOWTO ( 2, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,0,"32", TRUE, 0xffffffff,0xffffffff, FALSE),
|
---|
236 | HOWTO ( 3, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,0,"64", TRUE, 0xdeaddead,0xdeaddead, FALSE),
|
---|
237 | HOWTO ( 4, 0, 0, 8, TRUE, 0, complain_overflow_signed, 0,"DISP8", TRUE, 0x000000ff,0x000000ff, FALSE),
|
---|
238 | HOWTO ( 5, 0, 1, 16, TRUE, 0, complain_overflow_signed, 0,"DISP16", TRUE, 0x0000ffff,0x0000ffff, FALSE),
|
---|
239 | HOWTO ( 6, 0, 2, 32, TRUE, 0, complain_overflow_signed, 0,"DISP32", TRUE, 0xffffffff,0xffffffff, FALSE),
|
---|
240 | HOWTO ( 7, 0, 4, 64, TRUE, 0, complain_overflow_signed, 0,"DISP64", TRUE, 0xfeedface,0xfeedface, FALSE),
|
---|
241 | HOWTO ( 8, 0, 2, 0, FALSE, 0, complain_overflow_bitfield,0,"GOT_REL", FALSE, 0,0x00000000, FALSE),
|
---|
242 | HOWTO ( 9, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,0,"BASE16", FALSE,0xffffffff,0xffffffff, FALSE),
|
---|
243 | HOWTO (10, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,0,"BASE32", FALSE,0xffffffff,0xffffffff, FALSE),
|
---|
244 | EMPTY_HOWTO (-1),
|
---|
245 | EMPTY_HOWTO (-1),
|
---|
246 | EMPTY_HOWTO (-1),
|
---|
247 | EMPTY_HOWTO (-1),
|
---|
248 | EMPTY_HOWTO (-1),
|
---|
249 | HOWTO (16, 0, 2, 0, FALSE, 0, complain_overflow_bitfield,0,"JMP_TABLE", FALSE, 0,0x00000000, FALSE),
|
---|
250 | EMPTY_HOWTO (-1),
|
---|
251 | EMPTY_HOWTO (-1),
|
---|
252 | EMPTY_HOWTO (-1),
|
---|
253 | EMPTY_HOWTO (-1),
|
---|
254 | EMPTY_HOWTO (-1),
|
---|
255 | EMPTY_HOWTO (-1),
|
---|
256 | EMPTY_HOWTO (-1),
|
---|
257 | EMPTY_HOWTO (-1),
|
---|
258 | EMPTY_HOWTO (-1),
|
---|
259 | EMPTY_HOWTO (-1),
|
---|
260 | EMPTY_HOWTO (-1),
|
---|
261 | EMPTY_HOWTO (-1),
|
---|
262 | EMPTY_HOWTO (-1),
|
---|
263 | EMPTY_HOWTO (-1),
|
---|
264 | EMPTY_HOWTO (-1),
|
---|
265 | HOWTO (32, 0, 2, 0, FALSE, 0, complain_overflow_bitfield,0,"RELATIVE", FALSE, 0,0x00000000, FALSE),
|
---|
266 | EMPTY_HOWTO (-1),
|
---|
267 | EMPTY_HOWTO (-1),
|
---|
268 | EMPTY_HOWTO (-1),
|
---|
269 | EMPTY_HOWTO (-1),
|
---|
270 | EMPTY_HOWTO (-1),
|
---|
271 | EMPTY_HOWTO (-1),
|
---|
272 | EMPTY_HOWTO (-1),
|
---|
273 | HOWTO (40, 0, 2, 0, FALSE, 0, complain_overflow_bitfield,0,"BASEREL", FALSE, 0,0x00000000, FALSE),
|
---|
274 | };
|
---|
275 |
|
---|
276 | #define TABLE_SIZE(TABLE) (sizeof (TABLE) / sizeof (TABLE[0]))
|
---|
277 |
|
---|
278 | #ifndef IS_STAB
|
---|
279 | # define IS_STAB(flags) ((flags) & N_STAB)
|
---|
280 | #endif
|
---|
281 |
|
---|
282 | reloc_howto_type *
|
---|
283 | NAME(aout,reloc_type_lookup) (abfd,code)
|
---|
284 | bfd *abfd;
|
---|
285 | bfd_reloc_code_real_type code;
|
---|
286 | {
|
---|
287 | #define EXT(i, j) case i: return &howto_table_ext[j]
|
---|
288 | #define STD(i, j) case i: return &howto_table_std[j]
|
---|
289 | int ext = obj_reloc_entry_size (abfd) == RELOC_EXT_SIZE;
|
---|
290 |
|
---|
291 | if (code == BFD_RELOC_CTOR)
|
---|
292 | switch (bfd_get_arch_info (abfd)->bits_per_address)
|
---|
293 | {
|
---|
294 | case 32:
|
---|
295 | code = BFD_RELOC_32;
|
---|
296 | break;
|
---|
297 | case 64:
|
---|
298 | code = BFD_RELOC_64;
|
---|
299 | break;
|
---|
300 | }
|
---|
301 |
|
---|
302 | if (ext)
|
---|
303 | switch (code)
|
---|
304 | {
|
---|
305 | EXT (BFD_RELOC_8, 0);
|
---|
306 | EXT (BFD_RELOC_16, 1);
|
---|
307 | EXT (BFD_RELOC_32, 2);
|
---|
308 | EXT (BFD_RELOC_HI22, 8);
|
---|
309 | EXT (BFD_RELOC_LO10, 11);
|
---|
310 | EXT (BFD_RELOC_32_PCREL_S2, 6);
|
---|
311 | EXT (BFD_RELOC_SPARC_WDISP22, 7);
|
---|
312 | EXT (BFD_RELOC_SPARC13, 10);
|
---|
313 | EXT (BFD_RELOC_SPARC_GOT10, 14);
|
---|
314 | EXT (BFD_RELOC_SPARC_BASE13, 15);
|
---|
315 | EXT (BFD_RELOC_SPARC_GOT13, 15);
|
---|
316 | EXT (BFD_RELOC_SPARC_GOT22, 16);
|
---|
317 | EXT (BFD_RELOC_SPARC_PC10, 17);
|
---|
318 | EXT (BFD_RELOC_SPARC_PC22, 18);
|
---|
319 | EXT (BFD_RELOC_SPARC_WPLT30, 19);
|
---|
320 | EXT (BFD_RELOC_SPARC_REV32, 26);
|
---|
321 | default: return (reloc_howto_type *) NULL;
|
---|
322 | }
|
---|
323 | else
|
---|
324 | /* std relocs. */
|
---|
325 | switch (code)
|
---|
326 | {
|
---|
327 | STD (BFD_RELOC_8, 0);
|
---|
328 | STD (BFD_RELOC_16, 1);
|
---|
329 | STD (BFD_RELOC_32, 2);
|
---|
330 | STD (BFD_RELOC_8_PCREL, 4);
|
---|
331 | STD (BFD_RELOC_16_PCREL, 5);
|
---|
332 | STD (BFD_RELOC_32_PCREL, 6);
|
---|
333 | STD (BFD_RELOC_16_BASEREL, 9);
|
---|
334 | STD (BFD_RELOC_32_BASEREL, 10);
|
---|
335 | default: return (reloc_howto_type *) NULL;
|
---|
336 | }
|
---|
337 | }
|
---|
338 |
|
---|
339 | /*
|
---|
340 | SUBSECTION
|
---|
341 | Internal entry points
|
---|
342 |
|
---|
343 | DESCRIPTION
|
---|
344 | @file{aoutx.h} exports several routines for accessing the
|
---|
345 | contents of an a.out file, which are gathered and exported in
|
---|
346 | turn by various format specific files (eg sunos.c).
|
---|
347 |
|
---|
348 | */
|
---|
349 |
|
---|
350 | /*
|
---|
351 | FUNCTION
|
---|
352 | aout_@var{size}_swap_exec_header_in
|
---|
353 |
|
---|
354 | SYNOPSIS
|
---|
355 | void aout_@var{size}_swap_exec_header_in,
|
---|
356 | (bfd *abfd,
|
---|
357 | struct external_exec *raw_bytes,
|
---|
358 | struct internal_exec *execp);
|
---|
359 |
|
---|
360 | DESCRIPTION
|
---|
361 | Swap the information in an executable header @var{raw_bytes} taken
|
---|
362 | from a raw byte stream memory image into the internal exec header
|
---|
363 | structure @var{execp}.
|
---|
364 | */
|
---|
365 |
|
---|
366 | #ifndef NAME_swap_exec_header_in
|
---|
367 | void
|
---|
368 | NAME(aout,swap_exec_header_in) (abfd, raw_bytes, execp)
|
---|
369 | bfd *abfd;
|
---|
370 | struct external_exec *raw_bytes;
|
---|
371 | struct internal_exec *execp;
|
---|
372 | {
|
---|
373 | struct external_exec *bytes = (struct external_exec *)raw_bytes;
|
---|
374 |
|
---|
375 | /* The internal_exec structure has some fields that are unused in this
|
---|
376 | configuration (IE for i960), so ensure that all such uninitialized
|
---|
377 | fields are zero'd out. There are places where two of these structs
|
---|
378 | are memcmp'd, and thus the contents do matter. */
|
---|
379 | memset ((PTR) execp, 0, sizeof (struct internal_exec));
|
---|
380 | /* Now fill in fields in the execp, from the bytes in the raw data. */
|
---|
381 | execp->a_info = H_GET_32 (abfd, bytes->e_info);
|
---|
382 | execp->a_text = GET_WORD (abfd, bytes->e_text);
|
---|
383 | execp->a_data = GET_WORD (abfd, bytes->e_data);
|
---|
384 | execp->a_bss = GET_WORD (abfd, bytes->e_bss);
|
---|
385 | execp->a_syms = GET_WORD (abfd, bytes->e_syms);
|
---|
386 | execp->a_entry = GET_WORD (abfd, bytes->e_entry);
|
---|
387 | execp->a_trsize = GET_WORD (abfd, bytes->e_trsize);
|
---|
388 | execp->a_drsize = GET_WORD (abfd, bytes->e_drsize);
|
---|
389 | }
|
---|
390 | #define NAME_swap_exec_header_in NAME(aout,swap_exec_header_in)
|
---|
391 | #endif
|
---|
392 |
|
---|
393 | /*
|
---|
394 | FUNCTION
|
---|
395 | aout_@var{size}_swap_exec_header_out
|
---|
396 |
|
---|
397 | SYNOPSIS
|
---|
398 | void aout_@var{size}_swap_exec_header_out
|
---|
399 | (bfd *abfd,
|
---|
400 | struct internal_exec *execp,
|
---|
401 | struct external_exec *raw_bytes);
|
---|
402 |
|
---|
403 | DESCRIPTION
|
---|
404 | Swap the information in an internal exec header structure
|
---|
405 | @var{execp} into the buffer @var{raw_bytes} ready for writing to disk.
|
---|
406 | */
|
---|
407 | void
|
---|
408 | NAME(aout,swap_exec_header_out) (abfd, execp, raw_bytes)
|
---|
409 | bfd *abfd;
|
---|
410 | struct internal_exec *execp;
|
---|
411 | struct external_exec *raw_bytes;
|
---|
412 | {
|
---|
413 | struct external_exec *bytes = (struct external_exec *)raw_bytes;
|
---|
414 |
|
---|
415 | /* Now fill in fields in the raw data, from the fields in the exec struct. */
|
---|
416 | H_PUT_32 (abfd, execp->a_info , bytes->e_info);
|
---|
417 | PUT_WORD (abfd, execp->a_text , bytes->e_text);
|
---|
418 | PUT_WORD (abfd, execp->a_data , bytes->e_data);
|
---|
419 | PUT_WORD (abfd, execp->a_bss , bytes->e_bss);
|
---|
420 | PUT_WORD (abfd, execp->a_syms , bytes->e_syms);
|
---|
421 | PUT_WORD (abfd, execp->a_entry , bytes->e_entry);
|
---|
422 | PUT_WORD (abfd, execp->a_trsize, bytes->e_trsize);
|
---|
423 | PUT_WORD (abfd, execp->a_drsize, bytes->e_drsize);
|
---|
424 | }
|
---|
425 |
|
---|
426 | /* Make all the section for an a.out file. */
|
---|
427 |
|
---|
428 | bfd_boolean
|
---|
429 | NAME(aout,make_sections) (abfd)
|
---|
430 | bfd *abfd;
|
---|
431 | {
|
---|
432 | if (obj_textsec (abfd) == (asection *) NULL
|
---|
433 | && bfd_make_section (abfd, ".text") == (asection *) NULL)
|
---|
434 | return FALSE;
|
---|
435 | if (obj_datasec (abfd) == (asection *) NULL
|
---|
436 | && bfd_make_section (abfd, ".data") == (asection *) NULL)
|
---|
437 | return FALSE;
|
---|
438 | if (obj_bsssec (abfd) == (asection *) NULL
|
---|
439 | && bfd_make_section (abfd, ".bss") == (asection *) NULL)
|
---|
440 | return FALSE;
|
---|
441 | return TRUE;
|
---|
442 | }
|
---|
443 |
|
---|
444 | /*
|
---|
445 | FUNCTION
|
---|
446 | aout_@var{size}_some_aout_object_p
|
---|
447 |
|
---|
448 | SYNOPSIS
|
---|
449 | const bfd_target *aout_@var{size}_some_aout_object_p
|
---|
450 | (bfd *abfd,
|
---|
451 | const bfd_target *(*callback_to_real_object_p) ());
|
---|
452 |
|
---|
453 | DESCRIPTION
|
---|
454 | Some a.out variant thinks that the file open in @var{abfd}
|
---|
455 | checking is an a.out file. Do some more checking, and set up
|
---|
456 | for access if it really is. Call back to the calling
|
---|
457 | environment's "finish up" function just before returning, to
|
---|
458 | handle any last-minute setup.
|
---|
459 | */
|
---|
460 |
|
---|
461 | const bfd_target *
|
---|
462 | NAME(aout,some_aout_object_p) (abfd, execp, callback_to_real_object_p)
|
---|
463 | bfd *abfd;
|
---|
464 | struct internal_exec *execp;
|
---|
465 | const bfd_target *(*callback_to_real_object_p) PARAMS ((bfd *));
|
---|
466 | {
|
---|
467 | struct aout_data_struct *rawptr, *oldrawptr;
|
---|
468 | const bfd_target *result;
|
---|
469 | bfd_size_type amt = sizeof (struct aout_data_struct);
|
---|
470 |
|
---|
471 | rawptr = (struct aout_data_struct *) bfd_zalloc (abfd, amt);
|
---|
472 | if (rawptr == NULL)
|
---|
473 | return 0;
|
---|
474 |
|
---|
475 | oldrawptr = abfd->tdata.aout_data;
|
---|
476 | abfd->tdata.aout_data = rawptr;
|
---|
477 |
|
---|
478 | /* Copy the contents of the old tdata struct.
|
---|
479 | In particular, we want the subformat, since for hpux it was set in
|
---|
480 | hp300hpux.c:swap_exec_header_in and will be used in
|
---|
481 | hp300hpux.c:callback. */
|
---|
482 | if (oldrawptr != NULL)
|
---|
483 | *abfd->tdata.aout_data = *oldrawptr;
|
---|
484 |
|
---|
485 | abfd->tdata.aout_data->a.hdr = &rawptr->e;
|
---|
486 | /* Copy in the internal_exec struct. */
|
---|
487 | *(abfd->tdata.aout_data->a.hdr) = *execp;
|
---|
488 | execp = abfd->tdata.aout_data->a.hdr;
|
---|
489 |
|
---|
490 | /* Set the file flags. */
|
---|
491 | abfd->flags = BFD_NO_FLAGS;
|
---|
492 | if (execp->a_drsize || execp->a_trsize)
|
---|
493 | abfd->flags |= HAS_RELOC;
|
---|
494 | /* Setting of EXEC_P has been deferred to the bottom of this function. */
|
---|
495 | if (execp->a_syms)
|
---|
496 | abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS;
|
---|
497 | if (N_DYNAMIC (*execp))
|
---|
498 | abfd->flags |= DYNAMIC;
|
---|
499 |
|
---|
500 | if (N_MAGIC (*execp) == ZMAGIC)
|
---|
501 | {
|
---|
502 | abfd->flags |= D_PAGED | WP_TEXT;
|
---|
503 | adata (abfd).magic = z_magic;
|
---|
504 | }
|
---|
505 | else if (N_MAGIC (*execp) == QMAGIC)
|
---|
506 | {
|
---|
507 | abfd->flags |= D_PAGED | WP_TEXT;
|
---|
508 | adata (abfd).magic = z_magic;
|
---|
509 | adata (abfd).subformat = q_magic_format;
|
---|
510 | }
|
---|
511 | else if (N_MAGIC (*execp) == NMAGIC)
|
---|
512 | {
|
---|
513 | abfd->flags |= WP_TEXT;
|
---|
514 | adata (abfd).magic = n_magic;
|
---|
515 | }
|
---|
516 | else if (N_MAGIC (*execp) == OMAGIC
|
---|
517 | || N_MAGIC (*execp) == BMAGIC)
|
---|
518 | adata (abfd).magic = o_magic;
|
---|
519 | else
|
---|
520 | {
|
---|
521 | /* Should have been checked with N_BADMAG before this routine
|
---|
522 | was called. */
|
---|
523 | abort ();
|
---|
524 | }
|
---|
525 |
|
---|
526 | bfd_get_start_address (abfd) = execp->a_entry;
|
---|
527 |
|
---|
528 | obj_aout_symbols (abfd) = (aout_symbol_type *)NULL;
|
---|
529 | bfd_get_symcount (abfd) = execp->a_syms / sizeof (struct external_nlist);
|
---|
530 |
|
---|
531 | /* The default relocation entry size is that of traditional V7 Unix. */
|
---|
532 | obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
|
---|
533 |
|
---|
534 | /* The default symbol entry size is that of traditional Unix. */
|
---|
535 | obj_symbol_entry_size (abfd) = EXTERNAL_NLIST_SIZE;
|
---|
536 |
|
---|
537 | #ifdef USE_MMAP
|
---|
538 | bfd_init_window (&obj_aout_sym_window (abfd));
|
---|
539 | bfd_init_window (&obj_aout_string_window (abfd));
|
---|
540 | #endif
|
---|
541 | obj_aout_external_syms (abfd) = NULL;
|
---|
542 | obj_aout_external_strings (abfd) = NULL;
|
---|
543 | obj_aout_sym_hashes (abfd) = NULL;
|
---|
544 |
|
---|
545 | if (! NAME(aout,make_sections) (abfd))
|
---|
546 | goto error_ret;
|
---|
547 |
|
---|
548 | obj_datasec (abfd)->_raw_size = execp->a_data;
|
---|
549 | obj_bsssec (abfd)->_raw_size = execp->a_bss;
|
---|
550 |
|
---|
551 | obj_textsec (abfd)->flags =
|
---|
552 | (execp->a_trsize != 0
|
---|
553 | ? (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | SEC_RELOC)
|
---|
554 | : (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS));
|
---|
555 | obj_datasec (abfd)->flags =
|
---|
556 | (execp->a_drsize != 0
|
---|
557 | ? (SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS | SEC_RELOC)
|
---|
558 | : (SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS));
|
---|
559 | obj_bsssec (abfd)->flags = SEC_ALLOC;
|
---|
560 |
|
---|
561 | #ifdef THIS_IS_ONLY_DOCUMENTATION
|
---|
562 | /* The common code can't fill in these things because they depend
|
---|
563 | on either the start address of the text segment, the rounding
|
---|
564 | up of virtual addresses between segments, or the starting file
|
---|
565 | position of the text segment -- all of which varies among different
|
---|
566 | versions of a.out. */
|
---|
567 |
|
---|
568 | /* Call back to the format-dependent code to fill in the rest of the
|
---|
569 | fields and do any further cleanup. Things that should be filled
|
---|
570 | in by the callback: */
|
---|
571 |
|
---|
572 | struct exec *execp = exec_hdr (abfd);
|
---|
573 |
|
---|
574 | obj_textsec (abfd)->size = N_TXTSIZE (*execp);
|
---|
575 | obj_textsec (abfd)->raw_size = N_TXTSIZE (*execp);
|
---|
576 | /* Data and bss are already filled in since they're so standard. */
|
---|
577 |
|
---|
578 | /* The virtual memory addresses of the sections. */
|
---|
579 | obj_textsec (abfd)->vma = N_TXTADDR (*execp);
|
---|
580 | obj_datasec (abfd)->vma = N_DATADDR (*execp);
|
---|
581 | obj_bsssec (abfd)->vma = N_BSSADDR (*execp);
|
---|
582 |
|
---|
583 | /* The file offsets of the sections. */
|
---|
584 | obj_textsec (abfd)->filepos = N_TXTOFF (*execp);
|
---|
585 | obj_datasec (abfd)->filepos = N_DATOFF (*execp);
|
---|
586 |
|
---|
587 | /* The file offsets of the relocation info. */
|
---|
588 | obj_textsec (abfd)->rel_filepos = N_TRELOFF (*execp);
|
---|
589 | obj_datasec (abfd)->rel_filepos = N_DRELOFF (*execp);
|
---|
590 |
|
---|
591 | /* The file offsets of the string table and symbol table. */
|
---|
592 | obj_str_filepos (abfd) = N_STROFF (*execp);
|
---|
593 | obj_sym_filepos (abfd) = N_SYMOFF (*execp);
|
---|
594 |
|
---|
595 | /* Determine the architecture and machine type of the object file. */
|
---|
596 | switch (N_MACHTYPE (*exec_hdr (abfd)))
|
---|
597 | {
|
---|
598 | default:
|
---|
599 | abfd->obj_arch = bfd_arch_obscure;
|
---|
600 | break;
|
---|
601 | }
|
---|
602 |
|
---|
603 | adata (abfd)->page_size = TARGET_PAGE_SIZE;
|
---|
604 | adata (abfd)->segment_size = SEGMENT_SIZE;
|
---|
605 | adata (abfd)->exec_bytes_size = EXEC_BYTES_SIZE;
|
---|
606 |
|
---|
607 | return abfd->xvec;
|
---|
608 |
|
---|
609 | /* The architecture is encoded in various ways in various a.out variants,
|
---|
610 | or is not encoded at all in some of them. The relocation size depends
|
---|
611 | on the architecture and the a.out variant. Finally, the return value
|
---|
612 | is the bfd_target vector in use. If an error occurs, return zero and
|
---|
613 | set bfd_error to the appropriate error code.
|
---|
614 |
|
---|
615 | Formats such as b.out, which have additional fields in the a.out
|
---|
616 | header, should cope with them in this callback as well. */
|
---|
617 | #endif /* DOCUMENTATION */
|
---|
618 |
|
---|
619 | result = (*callback_to_real_object_p) (abfd);
|
---|
620 |
|
---|
621 | /* Now that the segment addresses have been worked out, take a better
|
---|
622 | guess at whether the file is executable. If the entry point
|
---|
623 | is within the text segment, assume it is. (This makes files
|
---|
624 | executable even if their entry point address is 0, as long as
|
---|
625 | their text starts at zero.).
|
---|
626 |
|
---|
627 | This test had to be changed to deal with systems where the text segment
|
---|
628 | runs at a different location than the default. The problem is that the
|
---|
629 | entry address can appear to be outside the text segment, thus causing an
|
---|
630 | erroneous conclusion that the file isn't executable.
|
---|
631 |
|
---|
632 | To fix this, we now accept any non-zero entry point as an indication of
|
---|
633 | executability. This will work most of the time, since only the linker
|
---|
634 | sets the entry point, and that is likely to be non-zero for most systems. */
|
---|
635 |
|
---|
636 | if (execp->a_entry != 0
|
---|
637 | || (execp->a_entry >= obj_textsec (abfd)->vma
|
---|
638 | && execp->a_entry < (obj_textsec (abfd)->vma
|
---|
639 | + obj_textsec (abfd)->_raw_size)))
|
---|
640 | abfd->flags |= EXEC_P;
|
---|
641 | #ifdef STAT_FOR_EXEC
|
---|
642 | else
|
---|
643 | {
|
---|
644 | struct stat stat_buf;
|
---|
645 |
|
---|
646 | /* The original heuristic doesn't work in some important cases.
|
---|
647 | The a.out file has no information about the text start
|
---|
648 | address. For files (like kernels) linked to non-standard
|
---|
649 | addresses (ld -Ttext nnn) the entry point may not be between
|
---|
650 | the default text start (obj_textsec(abfd)->vma) and
|
---|
651 | (obj_textsec(abfd)->vma) + text size. This is not just a mach
|
---|
652 | issue. Many kernels are loaded at non standard addresses. */
|
---|
653 | if (abfd->iostream != NULL
|
---|
654 | && (abfd->flags & BFD_IN_MEMORY) == 0
|
---|
655 | && (fstat (fileno ((FILE *) (abfd->iostream)), &stat_buf) == 0)
|
---|
656 | && ((stat_buf.st_mode & 0111) != 0))
|
---|
657 | abfd->flags |= EXEC_P;
|
---|
658 | }
|
---|
659 | #endif /* STAT_FOR_EXEC */
|
---|
660 |
|
---|
661 | if (result)
|
---|
662 | {
|
---|
663 | #if 0 /* These should be set correctly anyways. */
|
---|
664 | abfd->sections = obj_textsec (abfd);
|
---|
665 | obj_textsec (abfd)->next = obj_datasec (abfd);
|
---|
666 | obj_datasec (abfd)->next = obj_bsssec (abfd);
|
---|
667 | #endif
|
---|
668 | return result;
|
---|
669 | }
|
---|
670 |
|
---|
671 | error_ret:
|
---|
672 | bfd_release (abfd, rawptr);
|
---|
673 | abfd->tdata.aout_data = oldrawptr;
|
---|
674 | return NULL;
|
---|
675 | }
|
---|
676 |
|
---|
677 | /*
|
---|
678 | FUNCTION
|
---|
679 | aout_@var{size}_mkobject
|
---|
680 |
|
---|
681 | SYNOPSIS
|
---|
682 | bfd_boolean aout_@var{size}_mkobject, (bfd *abfd);
|
---|
683 |
|
---|
684 | DESCRIPTION
|
---|
685 | Initialize BFD @var{abfd} for use with a.out files.
|
---|
686 | */
|
---|
687 |
|
---|
688 | bfd_boolean
|
---|
689 | NAME(aout,mkobject) (abfd)
|
---|
690 | bfd *abfd;
|
---|
691 | {
|
---|
692 | struct aout_data_struct *rawptr;
|
---|
693 | bfd_size_type amt = sizeof (struct aout_data_struct);
|
---|
694 |
|
---|
695 | bfd_set_error (bfd_error_system_call);
|
---|
696 |
|
---|
697 | rawptr = (struct aout_data_struct *) bfd_zalloc (abfd, amt);
|
---|
698 | if (rawptr == NULL)
|
---|
699 | return FALSE;
|
---|
700 |
|
---|
701 | abfd->tdata.aout_data = rawptr;
|
---|
702 | exec_hdr (abfd) = &(rawptr->e);
|
---|
703 |
|
---|
704 | obj_textsec (abfd) = (asection *) NULL;
|
---|
705 | obj_datasec (abfd) = (asection *) NULL;
|
---|
706 | obj_bsssec (abfd) = (asection *) NULL;
|
---|
707 |
|
---|
708 | return TRUE;
|
---|
709 | }
|
---|
710 |
|
---|
711 | /*
|
---|
712 | FUNCTION
|
---|
713 | aout_@var{size}_machine_type
|
---|
714 |
|
---|
715 | SYNOPSIS
|
---|
716 | enum machine_type aout_@var{size}_machine_type
|
---|
717 | (enum bfd_architecture arch,
|
---|
718 | unsigned long machine));
|
---|
719 |
|
---|
720 | DESCRIPTION
|
---|
721 | Keep track of machine architecture and machine type for
|
---|
722 | a.out's. Return the <<machine_type>> for a particular
|
---|
723 | architecture and machine, or <<M_UNKNOWN>> if that exact architecture
|
---|
724 | and machine can't be represented in a.out format.
|
---|
725 |
|
---|
726 | If the architecture is understood, machine type 0 (default)
|
---|
727 | is always understood.
|
---|
728 | */
|
---|
729 |
|
---|
730 | enum machine_type
|
---|
731 | NAME(aout,machine_type) (arch, machine, unknown)
|
---|
732 | enum bfd_architecture arch;
|
---|
733 | unsigned long machine;
|
---|
734 | bfd_boolean *unknown;
|
---|
735 | {
|
---|
736 | enum machine_type arch_flags;
|
---|
737 |
|
---|
738 | arch_flags = M_UNKNOWN;
|
---|
739 | *unknown = TRUE;
|
---|
740 |
|
---|
741 | switch (arch)
|
---|
742 | {
|
---|
743 | case bfd_arch_sparc:
|
---|
744 | if (machine == 0
|
---|
745 | || machine == bfd_mach_sparc
|
---|
746 | || machine == bfd_mach_sparc_sparclite
|
---|
747 | || machine == bfd_mach_sparc_sparclite_le
|
---|
748 | || machine == bfd_mach_sparc_v9)
|
---|
749 | arch_flags = M_SPARC;
|
---|
750 | else if (machine == bfd_mach_sparc_sparclet)
|
---|
751 | arch_flags = M_SPARCLET;
|
---|
752 | break;
|
---|
753 |
|
---|
754 | case bfd_arch_m68k:
|
---|
755 | switch (machine)
|
---|
756 | {
|
---|
757 | case 0: arch_flags = M_68010; break;
|
---|
758 | case bfd_mach_m68000: arch_flags = M_UNKNOWN; *unknown = FALSE; break;
|
---|
759 | case bfd_mach_m68010: arch_flags = M_68010; break;
|
---|
760 | case bfd_mach_m68020: arch_flags = M_68020; break;
|
---|
761 | default: arch_flags = M_UNKNOWN; break;
|
---|
762 | }
|
---|
763 | break;
|
---|
764 |
|
---|
765 | case bfd_arch_i386:
|
---|
766 | if (machine == 0
|
---|
767 | || machine == bfd_mach_i386_i386
|
---|
768 | || machine == bfd_mach_i386_i386_intel_syntax)
|
---|
769 | arch_flags = M_386;
|
---|
770 | break;
|
---|
771 |
|
---|
772 | case bfd_arch_a29k:
|
---|
773 | if (machine == 0)
|
---|
774 | arch_flags = M_29K;
|
---|
775 | break;
|
---|
776 |
|
---|
777 | case bfd_arch_arm:
|
---|
778 | if (machine == 0)
|
---|
779 | arch_flags = M_ARM;
|
---|
780 | break;
|
---|
781 |
|
---|
782 | case bfd_arch_mips:
|
---|
783 | switch (machine)
|
---|
784 | {
|
---|
785 | case 0:
|
---|
786 | case bfd_mach_mips3000:
|
---|
787 | case bfd_mach_mips3900:
|
---|
788 | arch_flags = M_MIPS1;
|
---|
789 | break;
|
---|
790 | case bfd_mach_mips6000:
|
---|
791 | arch_flags = M_MIPS2;
|
---|
792 | break;
|
---|
793 | case bfd_mach_mips4000:
|
---|
794 | case bfd_mach_mips4010:
|
---|
795 | case bfd_mach_mips4100:
|
---|
796 | case bfd_mach_mips4300:
|
---|
797 | case bfd_mach_mips4400:
|
---|
798 | case bfd_mach_mips4600:
|
---|
799 | case bfd_mach_mips4650:
|
---|
800 | case bfd_mach_mips8000:
|
---|
801 | case bfd_mach_mips10000:
|
---|
802 | case bfd_mach_mips12000:
|
---|
803 | case bfd_mach_mips16:
|
---|
804 | case bfd_mach_mipsisa32:
|
---|
805 | case bfd_mach_mipsisa32r2:
|
---|
806 | case bfd_mach_mips5:
|
---|
807 | case bfd_mach_mipsisa64:
|
---|
808 | case bfd_mach_mips_sb1:
|
---|
809 | /* FIXME: These should be MIPS3, MIPS4, MIPS16, MIPS32, etc. */
|
---|
810 | arch_flags = M_MIPS2;
|
---|
811 | break;
|
---|
812 | default:
|
---|
813 | arch_flags = M_UNKNOWN;
|
---|
814 | break;
|
---|
815 | }
|
---|
816 | break;
|
---|
817 |
|
---|
818 | case bfd_arch_ns32k:
|
---|
819 | switch (machine)
|
---|
820 | {
|
---|
821 | case 0: arch_flags = M_NS32532; break;
|
---|
822 | case 32032: arch_flags = M_NS32032; break;
|
---|
823 | case 32532: arch_flags = M_NS32532; break;
|
---|
824 | default: arch_flags = M_UNKNOWN; break;
|
---|
825 | }
|
---|
826 | break;
|
---|
827 |
|
---|
828 | case bfd_arch_vax:
|
---|
829 | *unknown = FALSE;
|
---|
830 | break;
|
---|
831 |
|
---|
832 | case bfd_arch_cris:
|
---|
833 | if (machine == 0 || machine == 255)
|
---|
834 | arch_flags = M_CRIS;
|
---|
835 | break;
|
---|
836 |
|
---|
837 | default:
|
---|
838 | arch_flags = M_UNKNOWN;
|
---|
839 | }
|
---|
840 |
|
---|
841 | if (arch_flags != M_UNKNOWN)
|
---|
842 | *unknown = FALSE;
|
---|
843 |
|
---|
844 | return arch_flags;
|
---|
845 | }
|
---|
846 |
|
---|
847 | /*
|
---|
848 | FUNCTION
|
---|
849 | aout_@var{size}_set_arch_mach
|
---|
850 |
|
---|
851 | SYNOPSIS
|
---|
852 | bfd_boolean aout_@var{size}_set_arch_mach,
|
---|
853 | (bfd *,
|
---|
854 | enum bfd_architecture arch,
|
---|
855 | unsigned long machine));
|
---|
856 |
|
---|
857 | DESCRIPTION
|
---|
858 | Set the architecture and the machine of the BFD @var{abfd} to the
|
---|
859 | values @var{arch} and @var{machine}. Verify that @var{abfd}'s format
|
---|
860 | can support the architecture required.
|
---|
861 | */
|
---|
862 |
|
---|
863 | bfd_boolean
|
---|
864 | NAME(aout,set_arch_mach) (abfd, arch, machine)
|
---|
865 | bfd *abfd;
|
---|
866 | enum bfd_architecture arch;
|
---|
867 | unsigned long machine;
|
---|
868 | {
|
---|
869 | if (! bfd_default_set_arch_mach (abfd, arch, machine))
|
---|
870 | return FALSE;
|
---|
871 |
|
---|
872 | if (arch != bfd_arch_unknown)
|
---|
873 | {
|
---|
874 | bfd_boolean unknown;
|
---|
875 |
|
---|
876 | NAME(aout,machine_type) (arch, machine, &unknown);
|
---|
877 | if (unknown)
|
---|
878 | return FALSE;
|
---|
879 | }
|
---|
880 |
|
---|
881 | /* Determine the size of a relocation entry. */
|
---|
882 | switch (arch)
|
---|
883 | {
|
---|
884 | case bfd_arch_sparc:
|
---|
885 | case bfd_arch_a29k:
|
---|
886 | case bfd_arch_mips:
|
---|
887 | obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;
|
---|
888 | break;
|
---|
889 | default:
|
---|
890 | obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
|
---|
891 | break;
|
---|
892 | }
|
---|
893 |
|
---|
894 | return (*aout_backend_info (abfd)->set_sizes) (abfd);
|
---|
895 | }
|
---|
896 |
|
---|
897 | static void
|
---|
898 | adjust_o_magic (abfd, execp)
|
---|
899 | bfd *abfd;
|
---|
900 | struct internal_exec *execp;
|
---|
901 | {
|
---|
902 | file_ptr pos = adata (abfd).exec_bytes_size;
|
---|
903 | bfd_vma vma = 0;
|
---|
904 | int pad = 0;
|
---|
905 |
|
---|
906 | /* Text. */
|
---|
907 | obj_textsec (abfd)->filepos = pos;
|
---|
908 | if (!obj_textsec (abfd)->user_set_vma)
|
---|
909 | obj_textsec (abfd)->vma = vma;
|
---|
910 | else
|
---|
911 | vma = obj_textsec (abfd)->vma;
|
---|
912 |
|
---|
913 | pos += obj_textsec (abfd)->_raw_size;
|
---|
914 | vma += obj_textsec (abfd)->_raw_size;
|
---|
915 |
|
---|
916 | /* Data. */
|
---|
917 | if (!obj_datasec (abfd)->user_set_vma)
|
---|
918 | {
|
---|
919 | #if 0 /* ?? Does alignment in the file image really matter? */
|
---|
920 | pad = align_power (vma, obj_datasec (abfd)->alignment_power) - vma;
|
---|
921 | #endif
|
---|
922 | obj_textsec (abfd)->_raw_size += pad;
|
---|
923 | pos += pad;
|
---|
924 | vma += pad;
|
---|
925 | obj_datasec (abfd)->vma = vma;
|
---|
926 | }
|
---|
927 | else
|
---|
928 | vma = obj_datasec (abfd)->vma;
|
---|
929 | obj_datasec (abfd)->filepos = pos;
|
---|
930 | pos += obj_datasec (abfd)->_raw_size;
|
---|
931 | vma += obj_datasec (abfd)->_raw_size;
|
---|
932 |
|
---|
933 | /* BSS. */
|
---|
934 | if (!obj_bsssec (abfd)->user_set_vma)
|
---|
935 | {
|
---|
936 | #if 0
|
---|
937 | pad = align_power (vma, obj_bsssec (abfd)->alignment_power) - vma;
|
---|
938 | #endif
|
---|
939 | obj_datasec (abfd)->_raw_size += pad;
|
---|
940 | pos += pad;
|
---|
941 | vma += pad;
|
---|
942 | obj_bsssec (abfd)->vma = vma;
|
---|
943 | }
|
---|
944 | else
|
---|
945 | {
|
---|
946 | /* The VMA of the .bss section is set by the VMA of the
|
---|
947 | .data section plus the size of the .data section. We may
|
---|
948 | need to add padding bytes to make this true. */
|
---|
949 | pad = obj_bsssec (abfd)->vma - vma;
|
---|
950 | if (pad > 0)
|
---|
951 | {
|
---|
952 | obj_datasec (abfd)->_raw_size += pad;
|
---|
953 | pos += pad;
|
---|
954 | }
|
---|
955 | }
|
---|
956 | obj_bsssec (abfd)->filepos = pos;
|
---|
957 |
|
---|
958 | /* Fix up the exec header. */
|
---|
959 | execp->a_text = obj_textsec (abfd)->_raw_size;
|
---|
960 | execp->a_data = obj_datasec (abfd)->_raw_size;
|
---|
961 | execp->a_bss = obj_bsssec (abfd)->_raw_size;
|
---|
962 | N_SET_MAGIC (*execp, OMAGIC);
|
---|
963 | }
|
---|
964 |
|
---|
965 | static void
|
---|
966 | adjust_z_magic (abfd, execp)
|
---|
967 | bfd *abfd;
|
---|
968 | struct internal_exec *execp;
|
---|
969 | {
|
---|
970 | bfd_size_type data_pad, text_pad;
|
---|
971 | file_ptr text_end;
|
---|
972 | const struct aout_backend_data *abdp;
|
---|
973 | int ztih; /* Nonzero if text includes exec header. */
|
---|
974 |
|
---|
975 | abdp = aout_backend_info (abfd);
|
---|
976 |
|
---|
977 | /* Text. */
|
---|
978 | ztih = (abdp != NULL
|
---|
979 | && (abdp->text_includes_header
|
---|
980 | || obj_aout_subformat (abfd) == q_magic_format));
|
---|
981 | obj_textsec (abfd)->filepos = (ztih
|
---|
982 | ? adata (abfd).exec_bytes_size
|
---|
983 | : adata (abfd).zmagic_disk_block_size);
|
---|
984 | if (! obj_textsec (abfd)->user_set_vma)
|
---|
985 | {
|
---|
986 | /* ?? Do we really need to check for relocs here? */
|
---|
987 | obj_textsec (abfd)->vma = ((abfd->flags & HAS_RELOC)
|
---|
988 | ? 0
|
---|
989 | : (ztih
|
---|
990 | ? (abdp->default_text_vma
|
---|
991 | + adata (abfd).exec_bytes_size)
|
---|
992 | : abdp->default_text_vma));
|
---|
993 | text_pad = 0;
|
---|
994 | }
|
---|
995 | else
|
---|
996 | {
|
---|
997 | /* The .text section is being loaded at an unusual address. We
|
---|
998 | may need to pad it such that the .data section starts at a page
|
---|
999 | boundary. */
|
---|
1000 | if (ztih)
|
---|
1001 | text_pad = ((obj_textsec (abfd)->filepos - obj_textsec (abfd)->vma)
|
---|
1002 | & (adata (abfd).page_size - 1));
|
---|
1003 | else
|
---|
1004 | text_pad = ((- obj_textsec (abfd)->vma)
|
---|
1005 | & (adata (abfd).page_size - 1));
|
---|
1006 | }
|
---|
1007 |
|
---|
1008 | /* Find start of data. */
|
---|
1009 | if (ztih)
|
---|
1010 | {
|
---|
1011 | text_end = obj_textsec (abfd)->filepos + obj_textsec (abfd)->_raw_size;
|
---|
1012 | text_pad += BFD_ALIGN (text_end, adata (abfd).page_size) - text_end;
|
---|
1013 | }
|
---|
1014 | else
|
---|
1015 | {
|
---|
1016 | /* Note that if page_size == zmagic_disk_block_size, then
|
---|
1017 | filepos == page_size, and this case is the same as the ztih
|
---|
1018 | case. */
|
---|
1019 | text_end = obj_textsec (abfd)->_raw_size;
|
---|
1020 | text_pad += BFD_ALIGN (text_end, adata (abfd).page_size) - text_end;
|
---|
1021 | text_end += obj_textsec (abfd)->filepos;
|
---|
1022 | }
|
---|
1023 | obj_textsec (abfd)->_raw_size += text_pad;
|
---|
1024 | text_end += text_pad;
|
---|
1025 |
|
---|
1026 | /* Data. */
|
---|
1027 | if (!obj_datasec (abfd)->user_set_vma)
|
---|
1028 | {
|
---|
1029 | bfd_vma vma;
|
---|
1030 | vma = obj_textsec (abfd)->vma + obj_textsec (abfd)->_raw_size;
|
---|
1031 | obj_datasec (abfd)->vma = BFD_ALIGN (vma, adata (abfd).segment_size);
|
---|
1032 | }
|
---|
1033 | if (abdp && abdp->zmagic_mapped_contiguous)
|
---|
1034 | {
|
---|
1035 | asection * text = obj_textsec (abfd);
|
---|
1036 | asection * data = obj_datasec (abfd);
|
---|
1037 |
|
---|
1038 | text_pad = data->vma - (text->vma + text->_raw_size);
|
---|
1039 | /* Only pad the text section if the data
|
---|
1040 | section is going to be placed after it. */
|
---|
1041 | if (text_pad > 0)
|
---|
1042 | text->_raw_size += text_pad;
|
---|
1043 | }
|
---|
1044 | obj_datasec (abfd)->filepos = (obj_textsec (abfd)->filepos
|
---|
1045 | + obj_textsec (abfd)->_raw_size);
|
---|
1046 |
|
---|
1047 | /* Fix up exec header while we're at it. */
|
---|
1048 | execp->a_text = obj_textsec (abfd)->_raw_size;
|
---|
1049 | if (ztih && (!abdp || (abdp && !abdp->exec_header_not_counted)))
|
---|
1050 | execp->a_text += adata (abfd).exec_bytes_size;
|
---|
1051 | if (obj_aout_subformat (abfd) == q_magic_format)
|
---|
1052 | N_SET_MAGIC (*execp, QMAGIC);
|
---|
1053 | else
|
---|
1054 | N_SET_MAGIC (*execp, ZMAGIC);
|
---|
1055 |
|
---|
1056 | /* Spec says data section should be rounded up to page boundary. */
|
---|
1057 | obj_datasec (abfd)->_raw_size
|
---|
1058 | = align_power (obj_datasec (abfd)->_raw_size,
|
---|
1059 | obj_bsssec (abfd)->alignment_power);
|
---|
1060 | execp->a_data = BFD_ALIGN (obj_datasec (abfd)->_raw_size,
|
---|
1061 | adata (abfd).page_size);
|
---|
1062 | data_pad = execp->a_data - obj_datasec (abfd)->_raw_size;
|
---|
1063 |
|
---|
1064 | /* BSS. */
|
---|
1065 | if (!obj_bsssec (abfd)->user_set_vma)
|
---|
1066 | obj_bsssec (abfd)->vma = (obj_datasec (abfd)->vma
|
---|
1067 | + obj_datasec (abfd)->_raw_size);
|
---|
1068 | /* If the BSS immediately follows the data section and extra space
|
---|
1069 | in the page is left after the data section, fudge data
|
---|
1070 | in the header so that the bss section looks smaller by that
|
---|
1071 | amount. We'll start the bss section there, and lie to the OS.
|
---|
1072 | (Note that a linker script, as well as the above assignment,
|
---|
1073 | could have explicitly set the BSS vma to immediately follow
|
---|
1074 | the data section.) */
|
---|
1075 | if (align_power (obj_bsssec (abfd)->vma, obj_bsssec (abfd)->alignment_power)
|
---|
1076 | == obj_datasec (abfd)->vma + obj_datasec (abfd)->_raw_size)
|
---|
1077 | execp->a_bss = (data_pad > obj_bsssec (abfd)->_raw_size
|
---|
1078 | ? 0 : obj_bsssec (abfd)->_raw_size - data_pad);
|
---|
1079 | else
|
---|
1080 | execp->a_bss = obj_bsssec (abfd)->_raw_size;
|
---|
1081 | }
|
---|
1082 |
|
---|
1083 | static void
|
---|
1084 | adjust_n_magic (abfd, execp)
|
---|
1085 | bfd *abfd;
|
---|
1086 | struct internal_exec *execp;
|
---|
1087 | {
|
---|
1088 | file_ptr pos = adata (abfd).exec_bytes_size;
|
---|
1089 | bfd_vma vma = 0;
|
---|
1090 | int pad;
|
---|
1091 |
|
---|
1092 | /* Text. */
|
---|
1093 | obj_textsec (abfd)->filepos = pos;
|
---|
1094 | if (!obj_textsec (abfd)->user_set_vma)
|
---|
1095 | obj_textsec (abfd)->vma = vma;
|
---|
1096 | else
|
---|
1097 | vma = obj_textsec (abfd)->vma;
|
---|
1098 | pos += obj_textsec (abfd)->_raw_size;
|
---|
1099 | vma += obj_textsec (abfd)->_raw_size;
|
---|
1100 |
|
---|
1101 | /* Data. */
|
---|
1102 | obj_datasec (abfd)->filepos = pos;
|
---|
1103 | if (!obj_datasec (abfd)->user_set_vma)
|
---|
1104 | obj_datasec (abfd)->vma = BFD_ALIGN (vma, adata (abfd).segment_size);
|
---|
1105 | vma = obj_datasec (abfd)->vma;
|
---|
1106 |
|
---|
1107 | /* Since BSS follows data immediately, see if it needs alignment. */
|
---|
1108 | vma += obj_datasec (abfd)->_raw_size;
|
---|
1109 | pad = align_power (vma, obj_bsssec (abfd)->alignment_power) - vma;
|
---|
1110 | obj_datasec (abfd)->_raw_size += pad;
|
---|
1111 | pos += obj_datasec (abfd)->_raw_size;
|
---|
1112 |
|
---|
1113 | /* BSS. */
|
---|
1114 | if (!obj_bsssec (abfd)->user_set_vma)
|
---|
1115 | obj_bsssec (abfd)->vma = vma;
|
---|
1116 | else
|
---|
1117 | vma = obj_bsssec (abfd)->vma;
|
---|
1118 |
|
---|
1119 | /* Fix up exec header. */
|
---|
1120 | execp->a_text = obj_textsec (abfd)->_raw_size;
|
---|
1121 | execp->a_data = obj_datasec (abfd)->_raw_size;
|
---|
1122 | execp->a_bss = obj_bsssec (abfd)->_raw_size;
|
---|
1123 | N_SET_MAGIC (*execp, NMAGIC);
|
---|
1124 | }
|
---|
1125 |
|
---|
1126 | bfd_boolean
|
---|
1127 | NAME(aout,adjust_sizes_and_vmas) (abfd, text_size, text_end)
|
---|
1128 | bfd *abfd;
|
---|
1129 | bfd_size_type *text_size;
|
---|
1130 | file_ptr *text_end ATTRIBUTE_UNUSED;
|
---|
1131 | {
|
---|
1132 | struct internal_exec *execp = exec_hdr (abfd);
|
---|
1133 |
|
---|
1134 | if (! NAME(aout,make_sections) (abfd))
|
---|
1135 | return FALSE;
|
---|
1136 |
|
---|
1137 | if (adata (abfd).magic != undecided_magic)
|
---|
1138 | return TRUE;
|
---|
1139 |
|
---|
1140 | obj_textsec (abfd)->_raw_size =
|
---|
1141 | align_power (obj_textsec (abfd)->_raw_size,
|
---|
1142 | obj_textsec (abfd)->alignment_power);
|
---|
1143 |
|
---|
1144 | *text_size = obj_textsec (abfd)->_raw_size;
|
---|
1145 | /* Rule (heuristic) for when to pad to a new page. Note that there
|
---|
1146 | are (at least) two ways demand-paged (ZMAGIC) files have been
|
---|
1147 | handled. Most Berkeley-based systems start the text segment at
|
---|
1148 | (TARGET_PAGE_SIZE). However, newer versions of SUNOS start the text
|
---|
1149 | segment right after the exec header; the latter is counted in the
|
---|
1150 | text segment size, and is paged in by the kernel with the rest of
|
---|
1151 | the text. */
|
---|
1152 |
|
---|
1153 | /* This perhaps isn't the right way to do this, but made it simpler for me
|
---|
1154 | to understand enough to implement it. Better would probably be to go
|
---|
1155 | right from BFD flags to alignment/positioning characteristics. But the
|
---|
1156 | old code was sloppy enough about handling the flags, and had enough
|
---|
1157 | other magic, that it was a little hard for me to understand. I think
|
---|
1158 | I understand it better now, but I haven't time to do the cleanup this
|
---|
1159 | minute. */
|
---|
1160 |
|
---|
1161 | if (abfd->flags & D_PAGED)
|
---|
1162 | /* Whether or not WP_TEXT is set -- let D_PAGED override. */
|
---|
1163 | adata (abfd).magic = z_magic;
|
---|
1164 | else if (abfd->flags & WP_TEXT)
|
---|
1165 | adata (abfd).magic = n_magic;
|
---|
1166 | else
|
---|
1167 | adata (abfd).magic = o_magic;
|
---|
1168 |
|
---|
1169 | #ifdef BFD_AOUT_DEBUG /* requires gcc2 */
|
---|
1170 | #if __GNUC__ >= 2
|
---|
1171 | fprintf (stderr, "%s text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x,%x>\n",
|
---|
1172 | ({ char *str;
|
---|
1173 | switch (adata (abfd).magic)
|
---|
1174 | {
|
---|
1175 | case n_magic: str = "NMAGIC"; break;
|
---|
1176 | case o_magic: str = "OMAGIC"; break;
|
---|
1177 | case z_magic: str = "ZMAGIC"; break;
|
---|
1178 | default: abort ();
|
---|
1179 | }
|
---|
1180 | str;
|
---|
1181 | }),
|
---|
1182 | obj_textsec (abfd)->vma, obj_textsec (abfd)->_raw_size,
|
---|
1183 | obj_textsec (abfd)->alignment_power,
|
---|
1184 | obj_datasec (abfd)->vma, obj_datasec (abfd)->_raw_size,
|
---|
1185 | obj_datasec (abfd)->alignment_power,
|
---|
1186 | obj_bsssec (abfd)->vma, obj_bsssec (abfd)->_raw_size,
|
---|
1187 | obj_bsssec (abfd)->alignment_power);
|
---|
1188 | #endif
|
---|
1189 | #endif
|
---|
1190 |
|
---|
1191 | switch (adata (abfd).magic)
|
---|
1192 | {
|
---|
1193 | case o_magic:
|
---|
1194 | adjust_o_magic (abfd, execp);
|
---|
1195 | break;
|
---|
1196 | case z_magic:
|
---|
1197 | adjust_z_magic (abfd, execp);
|
---|
1198 | break;
|
---|
1199 | case n_magic:
|
---|
1200 | adjust_n_magic (abfd, execp);
|
---|
1201 | break;
|
---|
1202 | default:
|
---|
1203 | abort ();
|
---|
1204 | }
|
---|
1205 |
|
---|
1206 | #ifdef BFD_AOUT_DEBUG
|
---|
1207 | fprintf (stderr, " text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x>\n",
|
---|
1208 | obj_textsec (abfd)->vma, obj_textsec (abfd)->_raw_size,
|
---|
1209 | obj_textsec (abfd)->filepos,
|
---|
1210 | obj_datasec (abfd)->vma, obj_datasec (abfd)->_raw_size,
|
---|
1211 | obj_datasec (abfd)->filepos,
|
---|
1212 | obj_bsssec (abfd)->vma, obj_bsssec (abfd)->_raw_size);
|
---|
1213 | #endif
|
---|
1214 |
|
---|
1215 | return TRUE;
|
---|
1216 | }
|
---|
1217 |
|
---|
1218 | /*
|
---|
1219 | FUNCTION
|
---|
1220 | aout_@var{size}_new_section_hook
|
---|
1221 |
|
---|
1222 | SYNOPSIS
|
---|
1223 | bfd_boolean aout_@var{size}_new_section_hook,
|
---|
1224 | (bfd *abfd,
|
---|
1225 | asection *newsect));
|
---|
1226 |
|
---|
1227 | DESCRIPTION
|
---|
1228 | Called by the BFD in response to a @code{bfd_make_section}
|
---|
1229 | request.
|
---|
1230 | */
|
---|
1231 | bfd_boolean
|
---|
1232 | NAME(aout,new_section_hook) (abfd, newsect)
|
---|
1233 | bfd *abfd;
|
---|
1234 | asection *newsect;
|
---|
1235 | {
|
---|
1236 | /* Align to double at least. */
|
---|
1237 | newsect->alignment_power = bfd_get_arch_info (abfd)->section_align_power;
|
---|
1238 |
|
---|
1239 | if (bfd_get_format (abfd) == bfd_object)
|
---|
1240 | {
|
---|
1241 | if (obj_textsec (abfd) == NULL && !strcmp (newsect->name, ".text"))
|
---|
1242 | {
|
---|
1243 | obj_textsec (abfd)= newsect;
|
---|
1244 | newsect->target_index = N_TEXT;
|
---|
1245 | return TRUE;
|
---|
1246 | }
|
---|
1247 |
|
---|
1248 | if (obj_datasec (abfd) == NULL && !strcmp (newsect->name, ".data"))
|
---|
1249 | {
|
---|
1250 | obj_datasec (abfd) = newsect;
|
---|
1251 | newsect->target_index = N_DATA;
|
---|
1252 | return TRUE;
|
---|
1253 | }
|
---|
1254 |
|
---|
1255 | if (obj_bsssec (abfd) == NULL && !strcmp (newsect->name, ".bss"))
|
---|
1256 | {
|
---|
1257 | obj_bsssec (abfd) = newsect;
|
---|
1258 | newsect->target_index = N_BSS;
|
---|
1259 | return TRUE;
|
---|
1260 | }
|
---|
1261 | }
|
---|
1262 |
|
---|
1263 | /* We allow more than three sections internally. */
|
---|
1264 | return TRUE;
|
---|
1265 | }
|
---|
1266 |
|
---|
1267 | bfd_boolean
|
---|
1268 | NAME(aout,set_section_contents) (abfd, section, location, offset, count)
|
---|
1269 | bfd *abfd;
|
---|
1270 | sec_ptr section;
|
---|
1271 | PTR location;
|
---|
1272 | file_ptr offset;
|
---|
1273 | bfd_size_type count;
|
---|
1274 | {
|
---|
1275 | file_ptr text_end;
|
---|
1276 | bfd_size_type text_size;
|
---|
1277 |
|
---|
1278 | if (! abfd->output_has_begun)
|
---|
1279 | {
|
---|
1280 | if (! NAME(aout,adjust_sizes_and_vmas) (abfd, &text_size, &text_end))
|
---|
1281 | return FALSE;
|
---|
1282 | }
|
---|
1283 |
|
---|
1284 | if (section == obj_bsssec (abfd))
|
---|
1285 | {
|
---|
1286 | bfd_set_error (bfd_error_no_contents);
|
---|
1287 | return FALSE;
|
---|
1288 | }
|
---|
1289 |
|
---|
1290 | if (section != obj_textsec (abfd)
|
---|
1291 | && section != obj_datasec (abfd))
|
---|
1292 | {
|
---|
1293 | if (aout_section_merge_with_text_p (abfd, section))
|
---|
1294 | section->filepos = obj_textsec (abfd)->filepos +
|
---|
1295 | (section->vma - obj_textsec (abfd)->vma);
|
---|
1296 | else
|
---|
1297 | {
|
---|
1298 | (*_bfd_error_handler)
|
---|
1299 | (_("%s: can not represent section `%s' in a.out object file format"),
|
---|
1300 | bfd_get_filename (abfd), bfd_get_section_name (abfd, section));
|
---|
1301 | bfd_set_error (bfd_error_nonrepresentable_section);
|
---|
1302 | return FALSE;
|
---|
1303 | }
|
---|
1304 | }
|
---|
1305 |
|
---|
1306 | if (count != 0)
|
---|
1307 | {
|
---|
1308 | if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0
|
---|
1309 | || bfd_bwrite (location, count, abfd) != count)
|
---|
1310 | return FALSE;
|
---|
1311 | }
|
---|
1312 |
|
---|
1313 | return TRUE;
|
---|
1314 | }
|
---|
1315 | |
---|
1316 |
|
---|
1317 | /* Read the external symbols from an a.out file. */
|
---|
1318 |
|
---|
1319 | static bfd_boolean
|
---|
1320 | aout_get_external_symbols (abfd)
|
---|
1321 | bfd *abfd;
|
---|
1322 | {
|
---|
1323 | if (obj_aout_external_syms (abfd) == (struct external_nlist *) NULL)
|
---|
1324 | {
|
---|
1325 | bfd_size_type count;
|
---|
1326 | struct external_nlist *syms;
|
---|
1327 | bfd_size_type amt;
|
---|
1328 |
|
---|
1329 | count = exec_hdr (abfd)->a_syms / EXTERNAL_NLIST_SIZE;
|
---|
1330 |
|
---|
1331 | #ifdef USE_MMAP
|
---|
1332 | if (! bfd_get_file_window (abfd, obj_sym_filepos (abfd),
|
---|
1333 | exec_hdr (abfd)->a_syms,
|
---|
1334 | &obj_aout_sym_window (abfd), TRUE))
|
---|
1335 | return FALSE;
|
---|
1336 | syms = (struct external_nlist *) obj_aout_sym_window (abfd).data;
|
---|
1337 | #else
|
---|
1338 | /* We allocate using malloc to make the values easy to free
|
---|
1339 | later on. If we put them on the objalloc it might not be
|
---|
1340 | possible to free them. */
|
---|
1341 | syms = ((struct external_nlist *)
|
---|
1342 | bfd_malloc (count * EXTERNAL_NLIST_SIZE));
|
---|
1343 | if (syms == (struct external_nlist *) NULL && count != 0)
|
---|
1344 | return FALSE;
|
---|
1345 |
|
---|
1346 | amt = exec_hdr (abfd)->a_syms;
|
---|
1347 | if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0
|
---|
1348 | || bfd_bread (syms, amt, abfd) != amt)
|
---|
1349 | {
|
---|
1350 | free (syms);
|
---|
1351 | return FALSE;
|
---|
1352 | }
|
---|
1353 | #endif
|
---|
1354 |
|
---|
1355 | obj_aout_external_syms (abfd) = syms;
|
---|
1356 | obj_aout_external_sym_count (abfd) = count;
|
---|
1357 | }
|
---|
1358 |
|
---|
1359 | if (obj_aout_external_strings (abfd) == NULL
|
---|
1360 | && exec_hdr (abfd)->a_syms != 0)
|
---|
1361 | {
|
---|
1362 | unsigned char string_chars[BYTES_IN_WORD];
|
---|
1363 | bfd_size_type stringsize;
|
---|
1364 | char *strings;
|
---|
1365 | bfd_size_type amt = BYTES_IN_WORD;
|
---|
1366 |
|
---|
1367 | /* Get the size of the strings. */
|
---|
1368 | if (bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET) != 0
|
---|
1369 | || bfd_bread ((PTR) string_chars, amt, abfd) != amt)
|
---|
1370 | return FALSE;
|
---|
1371 | stringsize = GET_WORD (abfd, string_chars);
|
---|
1372 |
|
---|
1373 | #ifdef USE_MMAP
|
---|
1374 | if (! bfd_get_file_window (abfd, obj_str_filepos (abfd), stringsize,
|
---|
1375 | &obj_aout_string_window (abfd), TRUE))
|
---|
1376 | return FALSE;
|
---|
1377 | strings = (char *) obj_aout_string_window (abfd).data;
|
---|
1378 | #else
|
---|
1379 | strings = (char *) bfd_malloc (stringsize + 1);
|
---|
1380 | if (strings == NULL)
|
---|
1381 | return FALSE;
|
---|
1382 |
|
---|
1383 | /* Skip space for the string count in the buffer for convenience
|
---|
1384 | when using indexes. */
|
---|
1385 | amt = stringsize - BYTES_IN_WORD;
|
---|
1386 | if (bfd_bread (strings + BYTES_IN_WORD, amt, abfd) != amt)
|
---|
1387 | {
|
---|
1388 | free (strings);
|
---|
1389 | return FALSE;
|
---|
1390 | }
|
---|
1391 | #endif
|
---|
1392 |
|
---|
1393 | /* Ensure that a zero index yields an empty string. */
|
---|
1394 | strings[0] = '\0';
|
---|
1395 |
|
---|
1396 | strings[stringsize - 1] = 0;
|
---|
1397 |
|
---|
1398 | obj_aout_external_strings (abfd) = strings;
|
---|
1399 | obj_aout_external_string_size (abfd) = stringsize;
|
---|
1400 | }
|
---|
1401 |
|
---|
1402 | return TRUE;
|
---|
1403 | }
|
---|
1404 |
|
---|
1405 | /* Translate an a.out symbol into a BFD symbol. The desc, other, type
|
---|
1406 | and symbol->value fields of CACHE_PTR will be set from the a.out
|
---|
1407 | nlist structure. This function is responsible for setting
|
---|
1408 | symbol->flags and symbol->section, and adjusting symbol->value. */
|
---|
1409 |
|
---|
1410 | static bfd_boolean
|
---|
1411 | translate_from_native_sym_flags (abfd, cache_ptr)
|
---|
1412 | bfd *abfd;
|
---|
1413 | aout_symbol_type *cache_ptr;
|
---|
1414 | {
|
---|
1415 | flagword visible;
|
---|
1416 |
|
---|
1417 | if (IS_STAB(cache_ptr->type)
|
---|
1418 | || cache_ptr->type == N_FN)
|
---|
1419 | {
|
---|
1420 | asection *sec;
|
---|
1421 |
|
---|
1422 | /* This is a debugging symbol. */
|
---|
1423 | cache_ptr->symbol.flags = BSF_DEBUGGING;
|
---|
1424 |
|
---|
1425 | /* Work out the symbol section. */
|
---|
1426 | switch (cache_ptr->type & N_TYPE)
|
---|
1427 | {
|
---|
1428 | case N_TEXT:
|
---|
1429 | case N_FN:
|
---|
1430 | sec = obj_textsec (abfd);
|
---|
1431 | break;
|
---|
1432 | case N_DATA:
|
---|
1433 | sec = obj_datasec (abfd);
|
---|
1434 | break;
|
---|
1435 | case N_BSS:
|
---|
1436 | sec = obj_bsssec (abfd);
|
---|
1437 | break;
|
---|
1438 | default:
|
---|
1439 | case N_ABS:
|
---|
1440 | sec = bfd_abs_section_ptr;
|
---|
1441 | break;
|
---|
1442 | }
|
---|
1443 |
|
---|
1444 | cache_ptr->symbol.section = sec;
|
---|
1445 | cache_ptr->symbol.value -= sec->vma;
|
---|
1446 |
|
---|
1447 | return TRUE;
|
---|
1448 | }
|
---|
1449 |
|
---|
1450 | /* Get the default visibility. This does not apply to all types, so
|
---|
1451 | we just hold it in a local variable to use if wanted. */
|
---|
1452 | if ((cache_ptr->type & N_EXT) == 0)
|
---|
1453 | visible = BSF_LOCAL;
|
---|
1454 | else
|
---|
1455 | visible = BSF_GLOBAL;
|
---|
1456 |
|
---|
1457 | switch (cache_ptr->type)
|
---|
1458 | {
|
---|
1459 | default:
|
---|
1460 | case N_ABS: case N_ABS | N_EXT:
|
---|
1461 | cache_ptr->symbol.section = bfd_abs_section_ptr;
|
---|
1462 | cache_ptr->symbol.flags = visible;
|
---|
1463 | break;
|
---|
1464 |
|
---|
1465 | case N_UNDF | N_EXT:
|
---|
1466 | if (cache_ptr->symbol.value != 0)
|
---|
1467 | {
|
---|
1468 | /* This is a common symbol. */
|
---|
1469 | cache_ptr->symbol.flags = BSF_GLOBAL;
|
---|
1470 | cache_ptr->symbol.section = bfd_com_section_ptr;
|
---|
1471 | }
|
---|
1472 | else
|
---|
1473 | {
|
---|
1474 | cache_ptr->symbol.flags = 0;
|
---|
1475 | cache_ptr->symbol.section = bfd_und_section_ptr;
|
---|
1476 | }
|
---|
1477 | break;
|
---|
1478 |
|
---|
1479 | case N_TEXT: case N_TEXT | N_EXT:
|
---|
1480 | cache_ptr->symbol.section = obj_textsec (abfd);
|
---|
1481 | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma;
|
---|
1482 | cache_ptr->symbol.flags = visible;
|
---|
1483 | break;
|
---|
1484 |
|
---|
1485 | /* N_SETV symbols used to represent set vectors placed in the
|
---|
1486 | data section. They are no longer generated. Theoretically,
|
---|
1487 | it was possible to extract the entries and combine them with
|
---|
1488 | new ones, although I don't know if that was ever actually
|
---|
1489 | done. Unless that feature is restored, treat them as data
|
---|
1490 | symbols. */
|
---|
1491 | case N_SETV: case N_SETV | N_EXT:
|
---|
1492 | case N_DATA: case N_DATA | N_EXT:
|
---|
1493 | cache_ptr->symbol.section = obj_datasec (abfd);
|
---|
1494 | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma;
|
---|
1495 | cache_ptr->symbol.flags = visible;
|
---|
1496 | break;
|
---|
1497 |
|
---|
1498 | case N_BSS: case N_BSS | N_EXT:
|
---|
1499 | cache_ptr->symbol.section = obj_bsssec (abfd);
|
---|
1500 | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma;
|
---|
1501 | cache_ptr->symbol.flags = visible;
|
---|
1502 | break;
|
---|
1503 |
|
---|
1504 | case N_SETA: case N_SETA | N_EXT:
|
---|
1505 | case N_SETT: case N_SETT | N_EXT:
|
---|
1506 | case N_SETD: case N_SETD | N_EXT:
|
---|
1507 | case N_SETB: case N_SETB | N_EXT:
|
---|
1508 | {
|
---|
1509 | /* This code is no longer needed. It used to be used to make
|
---|
1510 | the linker handle set symbols, but they are now handled in
|
---|
1511 | the add_symbols routine instead. */
|
---|
1512 | #if 0
|
---|
1513 | asection *section;
|
---|
1514 | arelent_chain *reloc;
|
---|
1515 | asection *into_section;
|
---|
1516 | bfd_size_type amt;
|
---|
1517 |
|
---|
1518 | /* This is a set symbol. The name of the symbol is the name
|
---|
1519 | of the set (e.g., __CTOR_LIST__). The value of the symbol
|
---|
1520 | is the value to add to the set. We create a section with
|
---|
1521 | the same name as the symbol, and add a reloc to insert the
|
---|
1522 | appropriate value into the section.
|
---|
1523 |
|
---|
1524 | This action is actually obsolete; it used to make the
|
---|
1525 | linker do the right thing, but the linker no longer uses
|
---|
1526 | this function. */
|
---|
1527 |
|
---|
1528 | section = bfd_get_section_by_name (abfd, cache_ptr->symbol.name);
|
---|
1529 | if (section == NULL)
|
---|
1530 | {
|
---|
1531 | char *copy;
|
---|
1532 |
|
---|
1533 | amt = strlen (cache_ptr->symbol.name) + 1;
|
---|
1534 | copy = bfd_alloc (abfd, amt);
|
---|
1535 | if (copy == NULL)
|
---|
1536 | return FALSE;
|
---|
1537 |
|
---|
1538 | strcpy (copy, cache_ptr->symbol.name);
|
---|
1539 | section = bfd_make_section (abfd, copy);
|
---|
1540 | if (section == NULL)
|
---|
1541 | return FALSE;
|
---|
1542 | }
|
---|
1543 |
|
---|
1544 | amt = sizeof (arelent_chain);
|
---|
1545 | reloc = (arelent_chain *) bfd_alloc (abfd, amt);
|
---|
1546 | if (reloc == NULL)
|
---|
1547 | return FALSE;
|
---|
1548 |
|
---|
1549 | /* Build a relocation entry for the constructor. */
|
---|
1550 | switch (cache_ptr->type & N_TYPE)
|
---|
1551 | {
|
---|
1552 | case N_SETA:
|
---|
1553 | into_section = bfd_abs_section_ptr;
|
---|
1554 | cache_ptr->type = N_ABS;
|
---|
1555 | break;
|
---|
1556 | case N_SETT:
|
---|
1557 | into_section = obj_textsec (abfd);
|
---|
1558 | cache_ptr->type = N_TEXT;
|
---|
1559 | break;
|
---|
1560 | case N_SETD:
|
---|
1561 | into_section = obj_datasec (abfd);
|
---|
1562 | cache_ptr->type = N_DATA;
|
---|
1563 | break;
|
---|
1564 | case N_SETB:
|
---|
1565 | into_section = obj_bsssec (abfd);
|
---|
1566 | cache_ptr->type = N_BSS;
|
---|
1567 | break;
|
---|
1568 | }
|
---|
1569 |
|
---|
1570 | /* Build a relocation pointing into the constructor section
|
---|
1571 | pointing at the symbol in the set vector specified. */
|
---|
1572 | reloc->relent.addend = cache_ptr->symbol.value;
|
---|
1573 | cache_ptr->symbol.section = into_section;
|
---|
1574 | reloc->relent.sym_ptr_ptr = into_section->symbol_ptr_ptr;
|
---|
1575 |
|
---|
1576 | /* We modify the symbol to belong to a section depending upon
|
---|
1577 | the name of the symbol, and add to the size of the section
|
---|
1578 | to contain a pointer to the symbol. Build a reloc entry to
|
---|
1579 | relocate to this symbol attached to this section. */
|
---|
1580 | section->flags = SEC_CONSTRUCTOR | SEC_RELOC;
|
---|
1581 |
|
---|
1582 | section->reloc_count++;
|
---|
1583 | section->alignment_power = 2;
|
---|
1584 |
|
---|
1585 | reloc->next = section->constructor_chain;
|
---|
1586 | section->constructor_chain = reloc;
|
---|
1587 | reloc->relent.address = section->_raw_size;
|
---|
1588 | section->_raw_size += BYTES_IN_WORD;
|
---|
1589 |
|
---|
1590 | reloc->relent.howto = CTOR_TABLE_RELOC_HOWTO (abfd);
|
---|
1591 |
|
---|
1592 | #endif /* 0 */
|
---|
1593 |
|
---|
1594 | switch (cache_ptr->type & N_TYPE)
|
---|
1595 | {
|
---|
1596 | case N_SETA:
|
---|
1597 | cache_ptr->symbol.section = bfd_abs_section_ptr;
|
---|
1598 | break;
|
---|
1599 | case N_SETT:
|
---|
1600 | cache_ptr->symbol.section = obj_textsec (abfd);
|
---|
1601 | break;
|
---|
1602 | case N_SETD:
|
---|
1603 | cache_ptr->symbol.section = obj_datasec (abfd);
|
---|
1604 | break;
|
---|
1605 | case N_SETB:
|
---|
1606 | cache_ptr->symbol.section = obj_bsssec (abfd);
|
---|
1607 | break;
|
---|
1608 | }
|
---|
1609 |
|
---|
1610 | cache_ptr->symbol.flags |= BSF_CONSTRUCTOR;
|
---|
1611 | }
|
---|
1612 | break;
|
---|
1613 |
|
---|
1614 | case N_WARNING:
|
---|
1615 | /* This symbol is the text of a warning message. The next
|
---|
1616 | symbol is the symbol to associate the warning with. If a
|
---|
1617 | reference is made to that symbol, a warning is issued. */
|
---|
1618 | cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_WARNING;
|
---|
1619 | cache_ptr->symbol.section = bfd_abs_section_ptr;
|
---|
1620 | break;
|
---|
1621 |
|
---|
1622 | case N_INDR: case N_INDR | N_EXT:
|
---|
1623 | /* An indirect symbol. This consists of two symbols in a row.
|
---|
1624 | The first symbol is the name of the indirection. The second
|
---|
1625 | symbol is the name of the target. A reference to the first
|
---|
1626 | symbol becomes a reference to the second. */
|
---|
1627 | cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_INDIRECT | visible;
|
---|
1628 | cache_ptr->symbol.section = bfd_ind_section_ptr;
|
---|
1629 | break;
|
---|
1630 |
|
---|
1631 | case N_WEAKU:
|
---|
1632 | cache_ptr->symbol.section = bfd_und_section_ptr;
|
---|
1633 | cache_ptr->symbol.flags = BSF_WEAK;
|
---|
1634 | break;
|
---|
1635 |
|
---|
1636 | case N_WEAKA:
|
---|
1637 | cache_ptr->symbol.section = bfd_abs_section_ptr;
|
---|
1638 | cache_ptr->symbol.flags = BSF_WEAK;
|
---|
1639 | break;
|
---|
1640 |
|
---|
1641 | case N_WEAKT:
|
---|
1642 | cache_ptr->symbol.section = obj_textsec (abfd);
|
---|
1643 | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma;
|
---|
1644 | cache_ptr->symbol.flags = BSF_WEAK;
|
---|
1645 | break;
|
---|
1646 |
|
---|
1647 | case N_WEAKD:
|
---|
1648 | cache_ptr->symbol.section = obj_datasec (abfd);
|
---|
1649 | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma;
|
---|
1650 | cache_ptr->symbol.flags = BSF_WEAK;
|
---|
1651 | break;
|
---|
1652 |
|
---|
1653 | case N_WEAKB:
|
---|
1654 | cache_ptr->symbol.section = obj_bsssec (abfd);
|
---|
1655 | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma;
|
---|
1656 | cache_ptr->symbol.flags = BSF_WEAK;
|
---|
1657 | break;
|
---|
1658 |
|
---|
1659 | #ifdef EMX
|
---|
1660 | case N_IMP1 | N_EXT:
|
---|
1661 | cache_ptr->symbol.section = bfd_abs_section_ptr;
|
---|
1662 | cache_ptr->symbol.flags = BSF_EMX_IMPORT1;
|
---|
1663 | break;
|
---|
1664 |
|
---|
1665 | case N_IMP2 | N_EXT:
|
---|
1666 | cache_ptr->symbol.section = bfd_abs_section_ptr;
|
---|
1667 | cache_ptr->symbol.flags = BSF_EMX_IMPORT2;
|
---|
1668 | break;
|
---|
1669 | #endif /* EMX */
|
---|
1670 | }
|
---|
1671 |
|
---|
1672 | return TRUE;
|
---|
1673 | }
|
---|
1674 |
|
---|
1675 | /* Set the fields of SYM_POINTER according to CACHE_PTR. */
|
---|
1676 |
|
---|
1677 | static bfd_boolean
|
---|
1678 | translate_to_native_sym_flags (abfd, cache_ptr, sym_pointer)
|
---|
1679 | bfd *abfd;
|
---|
1680 | asymbol *cache_ptr;
|
---|
1681 | struct external_nlist *sym_pointer;
|
---|
1682 | {
|
---|
1683 | bfd_vma value = cache_ptr->value;
|
---|
1684 | asection *sec;
|
---|
1685 | bfd_vma off;
|
---|
1686 |
|
---|
1687 | /* Mask out any existing type bits in case copying from one section
|
---|
1688 | to another. */
|
---|
1689 | sym_pointer->e_type[0] &= ~N_TYPE;
|
---|
1690 |
|
---|
1691 | sec = bfd_get_section (cache_ptr);
|
---|
1692 | off = 0;
|
---|
1693 |
|
---|
1694 | if (sec == NULL)
|
---|
1695 | {
|
---|
1696 | /* This case occurs, e.g., for the *DEBUG* section of a COFF
|
---|
1697 | file. */
|
---|
1698 | (*_bfd_error_handler)
|
---|
1699 | (_("%s: can not represent section for symbol `%s' in a.out object file format"),
|
---|
1700 | bfd_get_filename (abfd),
|
---|
1701 | cache_ptr->name != NULL ? cache_ptr->name : _("*unknown*"));
|
---|
1702 | bfd_set_error (bfd_error_nonrepresentable_section);
|
---|
1703 | return FALSE;
|
---|
1704 | }
|
---|
1705 |
|
---|
1706 | if (sec->output_section != NULL)
|
---|
1707 | {
|
---|
1708 | off = sec->output_offset;
|
---|
1709 | sec = sec->output_section;
|
---|
1710 | }
|
---|
1711 |
|
---|
1712 | if (bfd_is_abs_section (sec))
|
---|
1713 | sym_pointer->e_type[0] |= N_ABS;
|
---|
1714 | else if (sec == obj_textsec (abfd))
|
---|
1715 | sym_pointer->e_type[0] |= N_TEXT;
|
---|
1716 | else if (sec == obj_datasec (abfd))
|
---|
1717 | sym_pointer->e_type[0] |= N_DATA;
|
---|
1718 | else if (sec == obj_bsssec (abfd))
|
---|
1719 | sym_pointer->e_type[0] |= N_BSS;
|
---|
1720 | else if (bfd_is_und_section (sec))
|
---|
1721 | sym_pointer->e_type[0] = N_UNDF | N_EXT;
|
---|
1722 | else if (bfd_is_ind_section (sec))
|
---|
1723 | sym_pointer->e_type[0] = N_INDR;
|
---|
1724 | else if (bfd_is_com_section (sec))
|
---|
1725 | sym_pointer->e_type[0] = N_UNDF | N_EXT;
|
---|
1726 | else
|
---|
1727 | {
|
---|
1728 | if (aout_section_merge_with_text_p (abfd, sec))
|
---|
1729 | sym_pointer->e_type[0] |= N_TEXT;
|
---|
1730 | else
|
---|
1731 | {
|
---|
1732 | (*_bfd_error_handler)
|
---|
1733 | (_("%s: can not represent section `%s' in a.out object file format"),
|
---|
1734 | bfd_get_filename (abfd), bfd_get_section_name (abfd, sec));
|
---|
1735 | bfd_set_error (bfd_error_nonrepresentable_section);
|
---|
1736 | return FALSE;
|
---|
1737 | }
|
---|
1738 | }
|
---|
1739 |
|
---|
1740 | /* Turn the symbol from section relative to absolute again. */
|
---|
1741 | value += sec->vma + off;
|
---|
1742 |
|
---|
1743 | if ((cache_ptr->flags & BSF_WARNING) != 0)
|
---|
1744 | sym_pointer->e_type[0] = N_WARNING;
|
---|
1745 |
|
---|
1746 | if ((cache_ptr->flags & BSF_DEBUGGING) != 0)
|
---|
1747 | sym_pointer->e_type[0] = ((aout_symbol_type *) cache_ptr)->type;
|
---|
1748 | else if ((cache_ptr->flags & BSF_GLOBAL) != 0)
|
---|
1749 | sym_pointer->e_type[0] |= N_EXT;
|
---|
1750 | else if ((cache_ptr->flags & BSF_LOCAL) != 0)
|
---|
1751 | sym_pointer->e_type[0] &= ~N_EXT;
|
---|
1752 |
|
---|
1753 | if ((cache_ptr->flags & BSF_CONSTRUCTOR) != 0)
|
---|
1754 | {
|
---|
1755 | int type = ((aout_symbol_type *) cache_ptr)->type;
|
---|
1756 |
|
---|
1757 | switch (type)
|
---|
1758 | {
|
---|
1759 | case N_ABS: type = N_SETA; break;
|
---|
1760 | case N_TEXT: type = N_SETT; break;
|
---|
1761 | case N_DATA: type = N_SETD; break;
|
---|
1762 | case N_BSS: type = N_SETB; break;
|
---|
1763 | }
|
---|
1764 | sym_pointer->e_type[0] = type;
|
---|
1765 | }
|
---|
1766 |
|
---|
1767 | if ((cache_ptr->flags & BSF_WEAK) != 0)
|
---|
1768 | {
|
---|
1769 | int type;
|
---|
1770 |
|
---|
1771 | switch (sym_pointer->e_type[0] & N_TYPE)
|
---|
1772 | {
|
---|
1773 | default:
|
---|
1774 | case N_ABS: type = N_WEAKA; break;
|
---|
1775 | case N_TEXT: type = N_WEAKT; break;
|
---|
1776 | case N_DATA: type = N_WEAKD; break;
|
---|
1777 | case N_BSS: type = N_WEAKB; break;
|
---|
1778 | case N_UNDF: type = N_WEAKU; break;
|
---|
1779 | }
|
---|
1780 | sym_pointer->e_type[0] = type;
|
---|
1781 | }
|
---|
1782 |
|
---|
1783 | PUT_WORD (abfd, value, sym_pointer->e_value);
|
---|
1784 |
|
---|
1785 | return TRUE;
|
---|
1786 | }
|
---|
1787 | |
---|
1788 |
|
---|
1789 | /* Native-level interface to symbols. */
|
---|
1790 |
|
---|
1791 | asymbol *
|
---|
1792 | NAME(aout,make_empty_symbol) (abfd)
|
---|
1793 | bfd *abfd;
|
---|
1794 | {
|
---|
1795 | bfd_size_type amt = sizeof (aout_symbol_type);
|
---|
1796 | aout_symbol_type *new = (aout_symbol_type *) bfd_zalloc (abfd, amt);
|
---|
1797 | if (!new)
|
---|
1798 | return NULL;
|
---|
1799 | new->symbol.the_bfd = abfd;
|
---|
1800 |
|
---|
1801 | return &new->symbol;
|
---|
1802 | }
|
---|
1803 |
|
---|
1804 | /* Translate a set of internal symbols into external symbols. */
|
---|
1805 |
|
---|
1806 | bfd_boolean
|
---|
1807 | NAME(aout,translate_symbol_table) (abfd, in, ext, count, str, strsize, dynamic)
|
---|
1808 | bfd *abfd;
|
---|
1809 | aout_symbol_type *in;
|
---|
1810 | struct external_nlist *ext;
|
---|
1811 | bfd_size_type count;
|
---|
1812 | char *str;
|
---|
1813 | bfd_size_type strsize;
|
---|
1814 | bfd_boolean dynamic;
|
---|
1815 | {
|
---|
1816 | struct external_nlist *ext_end;
|
---|
1817 |
|
---|
1818 | ext_end = ext + count;
|
---|
1819 | for (; ext < ext_end; ext++, in++)
|
---|
1820 | {
|
---|
1821 | bfd_vma x;
|
---|
1822 |
|
---|
1823 | x = GET_WORD (abfd, ext->e_strx);
|
---|
1824 | in->symbol.the_bfd = abfd;
|
---|
1825 |
|
---|
1826 | /* For the normal symbols, the zero index points at the number
|
---|
1827 | of bytes in the string table but is to be interpreted as the
|
---|
1828 | null string. For the dynamic symbols, the number of bytes in
|
---|
1829 | the string table is stored in the __DYNAMIC structure and the
|
---|
1830 | zero index points at an actual string. */
|
---|
1831 | if (x == 0 && ! dynamic)
|
---|
1832 | in->symbol.name = "";
|
---|
1833 | else if (x < strsize)
|
---|
1834 | in->symbol.name = str + x;
|
---|
1835 | else
|
---|
1836 | return FALSE;
|
---|
1837 |
|
---|
1838 | in->symbol.value = GET_SWORD (abfd, ext->e_value);
|
---|
1839 | in->desc = H_GET_16 (abfd, ext->e_desc);
|
---|
1840 | in->other = H_GET_8 (abfd, ext->e_other);
|
---|
1841 | in->type = H_GET_8 (abfd, ext->e_type);
|
---|
1842 | in->symbol.udata.p = NULL;
|
---|
1843 |
|
---|
1844 | if (! translate_from_native_sym_flags (abfd, in))
|
---|
1845 | return FALSE;
|
---|
1846 |
|
---|
1847 | if (dynamic)
|
---|
1848 | in->symbol.flags |= BSF_DYNAMIC;
|
---|
1849 | }
|
---|
1850 |
|
---|
1851 | return TRUE;
|
---|
1852 | }
|
---|
1853 |
|
---|
1854 | /* We read the symbols into a buffer, which is discarded when this
|
---|
1855 | function exits. We read the strings into a buffer large enough to
|
---|
1856 | hold them all plus all the cached symbol entries. */
|
---|
1857 |
|
---|
1858 | bfd_boolean
|
---|
1859 | NAME(aout,slurp_symbol_table) (abfd)
|
---|
1860 | bfd *abfd;
|
---|
1861 | {
|
---|
1862 | struct external_nlist *old_external_syms;
|
---|
1863 | aout_symbol_type *cached;
|
---|
1864 | bfd_size_type cached_size;
|
---|
1865 |
|
---|
1866 | /* If there's no work to be done, don't do any. */
|
---|
1867 | if (obj_aout_symbols (abfd) != (aout_symbol_type *) NULL)
|
---|
1868 | return TRUE;
|
---|
1869 |
|
---|
1870 | old_external_syms = obj_aout_external_syms (abfd);
|
---|
1871 |
|
---|
1872 | if (! aout_get_external_symbols (abfd))
|
---|
1873 | return FALSE;
|
---|
1874 |
|
---|
1875 | cached_size = obj_aout_external_sym_count (abfd);
|
---|
1876 | cached_size *= sizeof (aout_symbol_type);
|
---|
1877 | cached = (aout_symbol_type *) bfd_zmalloc (cached_size);
|
---|
1878 | if (cached == NULL && cached_size != 0)
|
---|
1879 | return FALSE;
|
---|
1880 |
|
---|
1881 | /* Convert from external symbol information to internal. */
|
---|
1882 | if (! (NAME(aout,translate_symbol_table)
|
---|
1883 | (abfd, cached,
|
---|
1884 | obj_aout_external_syms (abfd),
|
---|
1885 | obj_aout_external_sym_count (abfd),
|
---|
1886 | obj_aout_external_strings (abfd),
|
---|
1887 | obj_aout_external_string_size (abfd),
|
---|
1888 | FALSE)))
|
---|
1889 | {
|
---|
1890 | free (cached);
|
---|
1891 | return FALSE;
|
---|
1892 | }
|
---|
1893 |
|
---|
1894 | bfd_get_symcount (abfd) = obj_aout_external_sym_count (abfd);
|
---|
1895 |
|
---|
1896 | obj_aout_symbols (abfd) = cached;
|
---|
1897 |
|
---|
1898 | /* It is very likely that anybody who calls this function will not
|
---|
1899 | want the external symbol information, so if it was allocated
|
---|
1900 | because of our call to aout_get_external_symbols, we free it up
|
---|
1901 | right away to save space. */
|
---|
1902 | if (old_external_syms == (struct external_nlist *) NULL
|
---|
1903 | && obj_aout_external_syms (abfd) != (struct external_nlist *) NULL)
|
---|
1904 | {
|
---|
1905 | #ifdef USE_MMAP
|
---|
1906 | bfd_free_window (&obj_aout_sym_window (abfd));
|
---|
1907 | #else
|
---|
1908 | free (obj_aout_external_syms (abfd));
|
---|
1909 | #endif
|
---|
1910 | obj_aout_external_syms (abfd) = NULL;
|
---|
1911 | }
|
---|
1912 |
|
---|
1913 | return TRUE;
|
---|
1914 | }
|
---|
1915 | |
---|
1916 |
|
---|
1917 | /* We use a hash table when writing out symbols so that we only write
|
---|
1918 | out a particular string once. This helps particularly when the
|
---|
1919 | linker writes out stabs debugging entries, because each different
|
---|
1920 | contributing object file tends to have many duplicate stabs
|
---|
1921 | strings.
|
---|
1922 |
|
---|
1923 | This hash table code breaks dbx on SunOS 4.1.3, so we don't do it
|
---|
1924 | if BFD_TRADITIONAL_FORMAT is set. */
|
---|
1925 |
|
---|
1926 | static bfd_size_type add_to_stringtab
|
---|
1927 | PARAMS ((bfd *, struct bfd_strtab_hash *, const char *, bfd_boolean));
|
---|
1928 | static bfd_boolean emit_stringtab
|
---|
1929 | PARAMS ((bfd *, struct bfd_strtab_hash *));
|
---|
1930 |
|
---|
1931 | /* Get the index of a string in a strtab, adding it if it is not
|
---|
1932 | already present. */
|
---|
1933 |
|
---|
1934 | static INLINE bfd_size_type
|
---|
1935 | add_to_stringtab (abfd, tab, str, copy)
|
---|
1936 | bfd *abfd;
|
---|
1937 | struct bfd_strtab_hash *tab;
|
---|
1938 | const char *str;
|
---|
1939 | bfd_boolean copy;
|
---|
1940 | {
|
---|
1941 | bfd_boolean hash;
|
---|
1942 | bfd_size_type index;
|
---|
1943 |
|
---|
1944 | /* An index of 0 always means the empty string. */
|
---|
1945 | if (str == 0 || *str == '\0')
|
---|
1946 | return 0;
|
---|
1947 |
|
---|
1948 | /* Don't hash if BFD_TRADITIONAL_FORMAT is set, because SunOS dbx
|
---|
1949 | doesn't understand a hashed string table. */
|
---|
1950 | hash = TRUE;
|
---|
1951 | if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
|
---|
1952 | hash = FALSE;
|
---|
1953 |
|
---|
1954 | index = _bfd_stringtab_add (tab, str, hash, copy);
|
---|
1955 |
|
---|
1956 | if (index != (bfd_size_type) -1)
|
---|
1957 | {
|
---|
1958 | /* Add BYTES_IN_WORD to the return value to account for the
|
---|
1959 | space taken up by the string table size. */
|
---|
1960 | index += BYTES_IN_WORD;
|
---|
1961 | }
|
---|
1962 |
|
---|
1963 | return index;
|
---|
1964 | }
|
---|
1965 |
|
---|
1966 | /* Write out a strtab. ABFD is already at the right location in the
|
---|
1967 | file. */
|
---|
1968 |
|
---|
1969 | static bfd_boolean
|
---|
1970 | emit_stringtab (abfd, tab)
|
---|
1971 | register bfd *abfd;
|
---|
1972 | struct bfd_strtab_hash *tab;
|
---|
1973 | {
|
---|
1974 | bfd_byte buffer[BYTES_IN_WORD];
|
---|
1975 | bfd_size_type amt = BYTES_IN_WORD;
|
---|
1976 |
|
---|
1977 | /* The string table starts with the size. */
|
---|
1978 | PUT_WORD (abfd, _bfd_stringtab_size (tab) + BYTES_IN_WORD, buffer);
|
---|
1979 | if (bfd_bwrite ((PTR) buffer, amt, abfd) != amt)
|
---|
1980 | return FALSE;
|
---|
1981 |
|
---|
1982 | return _bfd_stringtab_emit (abfd, tab);
|
---|
1983 | }
|
---|
1984 | |
---|
1985 |
|
---|
1986 | bfd_boolean
|
---|
1987 | NAME(aout,write_syms) (abfd)
|
---|
1988 | bfd *abfd;
|
---|
1989 | {
|
---|
1990 | unsigned int count ;
|
---|
1991 | asymbol **generic = bfd_get_outsymbols (abfd);
|
---|
1992 | struct bfd_strtab_hash *strtab;
|
---|
1993 |
|
---|
1994 | strtab = _bfd_stringtab_init ();
|
---|
1995 | if (strtab == NULL)
|
---|
1996 | return FALSE;
|
---|
1997 |
|
---|
1998 | for (count = 0; count < bfd_get_symcount (abfd); count++)
|
---|
1999 | {
|
---|
2000 | asymbol *g = generic[count];
|
---|
2001 | bfd_size_type indx;
|
---|
2002 | struct external_nlist nsp;
|
---|
2003 | bfd_size_type amt;
|
---|
2004 |
|
---|
2005 | indx = add_to_stringtab (abfd, strtab, g->name, FALSE);
|
---|
2006 | if (indx == (bfd_size_type) -1)
|
---|
2007 | goto error_return;
|
---|
2008 | PUT_WORD (abfd, indx, (bfd_byte *) nsp.e_strx);
|
---|
2009 |
|
---|
2010 | if (bfd_asymbol_flavour (g) == abfd->xvec->flavour)
|
---|
2011 | {
|
---|
2012 | H_PUT_16 (abfd, aout_symbol (g)->desc, nsp.e_desc);
|
---|
2013 | H_PUT_8 (abfd, aout_symbol (g)->other, nsp.e_other);
|
---|
2014 | H_PUT_8 (abfd, aout_symbol (g)->type, nsp.e_type);
|
---|
2015 | }
|
---|
2016 | else
|
---|
2017 | {
|
---|
2018 | H_PUT_16 (abfd, 0, nsp.e_desc);
|
---|
2019 | H_PUT_8 (abfd, 0, nsp.e_other);
|
---|
2020 | H_PUT_8 (abfd, 0, nsp.e_type);
|
---|
2021 | }
|
---|
2022 |
|
---|
2023 | if (! translate_to_native_sym_flags (abfd, g, &nsp))
|
---|
2024 | goto error_return;
|
---|
2025 |
|
---|
2026 | amt = EXTERNAL_NLIST_SIZE;
|
---|
2027 | if (bfd_bwrite ((PTR) &nsp, amt, abfd) != amt)
|
---|
2028 | goto error_return;
|
---|
2029 |
|
---|
2030 | /* NB: `KEEPIT' currently overlays `udata.p', so set this only
|
---|
2031 | here, at the end. */
|
---|
2032 | g->KEEPIT = count;
|
---|
2033 | }
|
---|
2034 |
|
---|
2035 | if (! emit_stringtab (abfd, strtab))
|
---|
2036 | goto error_return;
|
---|
2037 |
|
---|
2038 | _bfd_stringtab_free (strtab);
|
---|
2039 |
|
---|
2040 | return TRUE;
|
---|
2041 |
|
---|
2042 | error_return:
|
---|
2043 | _bfd_stringtab_free (strtab);
|
---|
2044 | return FALSE;
|
---|
2045 | }
|
---|
2046 | |
---|
2047 |
|
---|
2048 | long
|
---|
2049 | NAME(aout,get_symtab) (abfd, location)
|
---|
2050 | bfd *abfd;
|
---|
2051 | asymbol **location;
|
---|
2052 | {
|
---|
2053 | unsigned int counter = 0;
|
---|
2054 | aout_symbol_type *symbase;
|
---|
2055 |
|
---|
2056 | if (!NAME(aout,slurp_symbol_table) (abfd))
|
---|
2057 | return -1;
|
---|
2058 |
|
---|
2059 | for (symbase = obj_aout_symbols (abfd);
|
---|
2060 | counter++ < bfd_get_symcount (abfd);
|
---|
2061 | )
|
---|
2062 | *(location++) = (asymbol *) (symbase++);
|
---|
2063 | *location++ =0;
|
---|
2064 | return bfd_get_symcount (abfd);
|
---|
2065 | }
|
---|
2066 | |
---|
2067 |
|
---|
2068 | /* Standard reloc stuff. */
|
---|
2069 | /* Output standard relocation information to a file in target byte order. */
|
---|
2070 |
|
---|
2071 | extern void NAME(aout,swap_std_reloc_out)
|
---|
2072 | PARAMS ((bfd *, arelent *, struct reloc_std_external *));
|
---|
2073 |
|
---|
2074 | void
|
---|
2075 | NAME(aout,swap_std_reloc_out) (abfd, g, natptr)
|
---|
2076 | bfd *abfd;
|
---|
2077 | arelent *g;
|
---|
2078 | struct reloc_std_external *natptr;
|
---|
2079 | {
|
---|
2080 | int r_index;
|
---|
2081 | asymbol *sym = *(g->sym_ptr_ptr);
|
---|
2082 | int r_extern;
|
---|
2083 | unsigned int r_length;
|
---|
2084 | int r_pcrel;
|
---|
2085 | int r_baserel, r_jmptable, r_relative;
|
---|
2086 | asection *output_section = sym->section->output_section;
|
---|
2087 |
|
---|
2088 | PUT_WORD (abfd, g->address, natptr->r_address);
|
---|
2089 |
|
---|
2090 | r_length = g->howto->size ; /* Size as a power of two. */
|
---|
2091 | r_pcrel = (int) g->howto->pc_relative; /* Relative to PC? */
|
---|
2092 | /* XXX This relies on relocs coming from a.out files. */
|
---|
2093 | r_baserel = (g->howto->type & 8) != 0;
|
---|
2094 | r_jmptable = (g->howto->type & 16) != 0;
|
---|
2095 | r_relative = (g->howto->type & 32) != 0;
|
---|
2096 |
|
---|
2097 | #if 0
|
---|
2098 | /* For a standard reloc, the addend is in the object file. */
|
---|
2099 | r_addend = g->addend + (*(g->sym_ptr_ptr))->section->output_section->vma;
|
---|
2100 | #endif
|
---|
2101 |
|
---|
2102 | /* Name was clobbered by aout_write_syms to be symbol index. */
|
---|
2103 |
|
---|
2104 | /* If this relocation is relative to a symbol then set the
|
---|
2105 | r_index to the symbols index, and the r_extern bit.
|
---|
2106 |
|
---|
2107 | Absolute symbols can come in in two ways, either as an offset
|
---|
2108 | from the abs section, or as a symbol which has an abs value.
|
---|
2109 | check for that here. */
|
---|
2110 |
|
---|
2111 | if (bfd_is_com_section (output_section)
|
---|
2112 | || bfd_is_abs_section (output_section)
|
---|
2113 | || bfd_is_und_section (output_section))
|
---|
2114 | {
|
---|
2115 | if (bfd_abs_section_ptr->symbol == sym)
|
---|
2116 | {
|
---|
2117 | /* Whoops, looked like an abs symbol, but is
|
---|
2118 | really an offset from the abs section. */
|
---|
2119 | r_index = N_ABS;
|
---|
2120 | r_extern = 0;
|
---|
2121 | }
|
---|
2122 | else
|
---|
2123 | {
|
---|
2124 | /* Fill in symbol. */
|
---|
2125 | r_extern = 1;
|
---|
2126 | r_index = (*(g->sym_ptr_ptr))->KEEPIT;
|
---|
2127 | }
|
---|
2128 | }
|
---|
2129 | else
|
---|
2130 | {
|
---|
2131 | /* Just an ordinary section. */
|
---|
2132 | r_extern = 0;
|
---|
2133 | r_index = output_section->target_index;
|
---|
2134 | }
|
---|
2135 |
|
---|
2136 | /* Now the fun stuff. */
|
---|
2137 | if (bfd_header_big_endian (abfd))
|
---|
2138 | {
|
---|
2139 | natptr->r_index[0] = r_index >> 16;
|
---|
2140 | natptr->r_index[1] = r_index >> 8;
|
---|
2141 | natptr->r_index[2] = r_index;
|
---|
2142 | natptr->r_type[0] = ((r_extern ? RELOC_STD_BITS_EXTERN_BIG : 0)
|
---|
2143 | | (r_pcrel ? RELOC_STD_BITS_PCREL_BIG : 0)
|
---|
2144 | | (r_baserel ? RELOC_STD_BITS_BASEREL_BIG : 0)
|
---|
2145 | | (r_jmptable ? RELOC_STD_BITS_JMPTABLE_BIG : 0)
|
---|
2146 | | (r_relative ? RELOC_STD_BITS_RELATIVE_BIG : 0)
|
---|
2147 | | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG));
|
---|
2148 | }
|
---|
2149 | else
|
---|
2150 | {
|
---|
2151 | natptr->r_index[2] = r_index >> 16;
|
---|
2152 | natptr->r_index[1] = r_index >> 8;
|
---|
2153 | natptr->r_index[0] = r_index;
|
---|
2154 | natptr->r_type[0] = ((r_extern ? RELOC_STD_BITS_EXTERN_LITTLE : 0)
|
---|
2155 | | (r_pcrel ? RELOC_STD_BITS_PCREL_LITTLE : 0)
|
---|
2156 | | (r_baserel ? RELOC_STD_BITS_BASEREL_LITTLE : 0)
|
---|
2157 | | (r_jmptable ? RELOC_STD_BITS_JMPTABLE_LITTLE : 0)
|
---|
2158 | | (r_relative ? RELOC_STD_BITS_RELATIVE_LITTLE : 0)
|
---|
2159 | | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE));
|
---|
2160 | }
|
---|
2161 | }
|
---|
2162 |
|
---|
2163 | /* Extended stuff. */
|
---|
2164 | /* Output extended relocation information to a file in target byte order. */
|
---|
2165 |
|
---|
2166 | extern void NAME(aout,swap_ext_reloc_out)
|
---|
2167 | PARAMS ((bfd *, arelent *, struct reloc_ext_external *));
|
---|
2168 |
|
---|
2169 | void
|
---|
2170 | NAME(aout,swap_ext_reloc_out) (abfd, g, natptr)
|
---|
2171 | bfd *abfd;
|
---|
2172 | arelent *g;
|
---|
2173 | register struct reloc_ext_external *natptr;
|
---|
2174 | {
|
---|
2175 | int r_index;
|
---|
2176 | int r_extern;
|
---|
2177 | unsigned int r_type;
|
---|
2178 | bfd_vma r_addend;
|
---|
2179 | asymbol *sym = *(g->sym_ptr_ptr);
|
---|
2180 | asection *output_section = sym->section->output_section;
|
---|
2181 |
|
---|
2182 | PUT_WORD (abfd, g->address, natptr->r_address);
|
---|
2183 |
|
---|
2184 | r_type = (unsigned int) g->howto->type;
|
---|
2185 |
|
---|
2186 | r_addend = g->addend;
|
---|
2187 | if ((sym->flags & BSF_SECTION_SYM) != 0)
|
---|
2188 | r_addend += (*(g->sym_ptr_ptr))->section->output_section->vma;
|
---|
2189 |
|
---|
2190 | /* If this relocation is relative to a symbol then set the
|
---|
2191 | r_index to the symbols index, and the r_extern bit.
|
---|
2192 |
|
---|
2193 | Absolute symbols can come in in two ways, either as an offset
|
---|
2194 | from the abs section, or as a symbol which has an abs value.
|
---|
2195 | check for that here. */
|
---|
2196 | if (bfd_is_abs_section (bfd_get_section (sym)))
|
---|
2197 | {
|
---|
2198 | r_extern = 0;
|
---|
2199 | r_index = N_ABS;
|
---|
2200 | }
|
---|
2201 | else if ((sym->flags & BSF_SECTION_SYM) == 0)
|
---|
2202 | {
|
---|
2203 | if (bfd_is_und_section (bfd_get_section (sym))
|
---|
2204 | || (sym->flags & BSF_GLOBAL) != 0)
|
---|
2205 | r_extern = 1;
|
---|
2206 | else
|
---|
2207 | r_extern = 0;
|
---|
2208 | r_index = (*(g->sym_ptr_ptr))->KEEPIT;
|
---|
2209 | }
|
---|
2210 | else
|
---|
2211 | {
|
---|
2212 | /* Just an ordinary section. */
|
---|
2213 | r_extern = 0;
|
---|
2214 | r_index = output_section->target_index;
|
---|
2215 | }
|
---|
2216 |
|
---|
2217 | /* Now the fun stuff. */
|
---|
2218 | if (bfd_header_big_endian (abfd))
|
---|
2219 | {
|
---|
2220 | natptr->r_index[0] = r_index >> 16;
|
---|
2221 | natptr->r_index[1] = r_index >> 8;
|
---|
2222 | natptr->r_index[2] = r_index;
|
---|
2223 | natptr->r_type[0] = ((r_extern ? RELOC_EXT_BITS_EXTERN_BIG : 0)
|
---|
2224 | | (r_type << RELOC_EXT_BITS_TYPE_SH_BIG));
|
---|
2225 | }
|
---|
2226 | else
|
---|
2227 | {
|
---|
2228 | natptr->r_index[2] = r_index >> 16;
|
---|
2229 | natptr->r_index[1] = r_index >> 8;
|
---|
2230 | natptr->r_index[0] = r_index;
|
---|
2231 | natptr->r_type[0] = ((r_extern ? RELOC_EXT_BITS_EXTERN_LITTLE : 0)
|
---|
2232 | | (r_type << RELOC_EXT_BITS_TYPE_SH_LITTLE));
|
---|
2233 | }
|
---|
2234 |
|
---|
2235 | PUT_WORD (abfd, r_addend, natptr->r_addend);
|
---|
2236 | }
|
---|
2237 |
|
---|
2238 | /* BFD deals internally with all things based from the section they're
|
---|
2239 | in. so, something in 10 bytes into a text section with a base of
|
---|
2240 | 50 would have a symbol (.text+10) and know .text vma was 50.
|
---|
2241 |
|
---|
2242 | Aout keeps all it's symbols based from zero, so the symbol would
|
---|
2243 | contain 60. This macro subs the base of each section from the value
|
---|
2244 | to give the true offset from the section. */
|
---|
2245 |
|
---|
2246 | #define MOVE_ADDRESS(ad) \
|
---|
2247 | if (r_extern) \
|
---|
2248 | { \
|
---|
2249 | /* Undefined symbol. */ \
|
---|
2250 | cache_ptr->sym_ptr_ptr = symbols + r_index; \
|
---|
2251 | cache_ptr->addend = ad; \
|
---|
2252 | } \
|
---|
2253 | else \
|
---|
2254 | { \
|
---|
2255 | /* Defined, section relative. Replace symbol with pointer to \
|
---|
2256 | symbol which points to section. */ \
|
---|
2257 | switch (r_index) \
|
---|
2258 | { \
|
---|
2259 | case N_TEXT: \
|
---|
2260 | case N_TEXT | N_EXT: \
|
---|
2261 | cache_ptr->sym_ptr_ptr = obj_textsec (abfd)->symbol_ptr_ptr; \
|
---|
2262 | cache_ptr->addend = ad - su->textsec->vma; \
|
---|
2263 | break; \
|
---|
2264 | case N_DATA: \
|
---|
2265 | case N_DATA | N_EXT: \
|
---|
2266 | cache_ptr->sym_ptr_ptr = obj_datasec (abfd)->symbol_ptr_ptr; \
|
---|
2267 | cache_ptr->addend = ad - su->datasec->vma; \
|
---|
2268 | break; \
|
---|
2269 | case N_BSS: \
|
---|
2270 | case N_BSS | N_EXT: \
|
---|
2271 | cache_ptr->sym_ptr_ptr = obj_bsssec (abfd)->symbol_ptr_ptr; \
|
---|
2272 | cache_ptr->addend = ad - su->bsssec->vma; \
|
---|
2273 | break; \
|
---|
2274 | default: \
|
---|
2275 | case N_ABS: \
|
---|
2276 | case N_ABS | N_EXT: \
|
---|
2277 | cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; \
|
---|
2278 | cache_ptr->addend = ad; \
|
---|
2279 | break; \
|
---|
2280 | } \
|
---|
2281 | }
|
---|
2282 |
|
---|
2283 | void
|
---|
2284 | NAME(aout,swap_ext_reloc_in) (abfd, bytes, cache_ptr, symbols, symcount)
|
---|
2285 | bfd *abfd;
|
---|
2286 | struct reloc_ext_external *bytes;
|
---|
2287 | arelent *cache_ptr;
|
---|
2288 | asymbol **symbols;
|
---|
2289 | bfd_size_type symcount;
|
---|
2290 | {
|
---|
2291 | unsigned int r_index;
|
---|
2292 | int r_extern;
|
---|
2293 | unsigned int r_type;
|
---|
2294 | struct aoutdata *su = &(abfd->tdata.aout_data->a);
|
---|
2295 |
|
---|
2296 | cache_ptr->address = (GET_SWORD (abfd, bytes->r_address));
|
---|
2297 |
|
---|
2298 | /* Now the fun stuff. */
|
---|
2299 | if (bfd_header_big_endian (abfd))
|
---|
2300 | {
|
---|
2301 | r_index = (((unsigned int) bytes->r_index[0] << 16)
|
---|
2302 | | ((unsigned int) bytes->r_index[1] << 8)
|
---|
2303 | | bytes->r_index[2]);
|
---|
2304 | r_extern = (0 != (bytes->r_type[0] & RELOC_EXT_BITS_EXTERN_BIG));
|
---|
2305 | r_type = ((bytes->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
|
---|
2306 | >> RELOC_EXT_BITS_TYPE_SH_BIG);
|
---|
2307 | }
|
---|
2308 | else
|
---|
2309 | {
|
---|
2310 | r_index = (((unsigned int) bytes->r_index[2] << 16)
|
---|
2311 | | ((unsigned int) bytes->r_index[1] << 8)
|
---|
2312 | | bytes->r_index[0]);
|
---|
2313 | r_extern = (0 != (bytes->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE));
|
---|
2314 | r_type = ((bytes->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
|
---|
2315 | >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
|
---|
2316 | }
|
---|
2317 |
|
---|
2318 | cache_ptr->howto = howto_table_ext + r_type;
|
---|
2319 |
|
---|
2320 | /* Base relative relocs are always against the symbol table,
|
---|
2321 | regardless of the setting of r_extern. r_extern just reflects
|
---|
2322 | whether the symbol the reloc is against is local or global. */
|
---|
2323 | if (r_type == (unsigned int) RELOC_BASE10
|
---|
2324 | || r_type == (unsigned int) RELOC_BASE13
|
---|
2325 | || r_type == (unsigned int) RELOC_BASE22)
|
---|
2326 | r_extern = 1;
|
---|
2327 |
|
---|
2328 | if (r_extern && r_index > symcount)
|
---|
2329 | {
|
---|
2330 | /* We could arrange to return an error, but it might be useful
|
---|
2331 | to see the file even if it is bad. */
|
---|
2332 | r_extern = 0;
|
---|
2333 | r_index = N_ABS;
|
---|
2334 | }
|
---|
2335 |
|
---|
2336 | MOVE_ADDRESS (GET_SWORD (abfd, bytes->r_addend));
|
---|
2337 | }
|
---|
2338 |
|
---|
2339 | void
|
---|
2340 | NAME(aout,swap_std_reloc_in) (abfd, bytes, cache_ptr, symbols, symcount)
|
---|
2341 | bfd *abfd;
|
---|
2342 | struct reloc_std_external *bytes;
|
---|
2343 | arelent *cache_ptr;
|
---|
2344 | asymbol **symbols;
|
---|
2345 | bfd_size_type symcount;
|
---|
2346 | {
|
---|
2347 | unsigned int r_index;
|
---|
2348 | int r_extern;
|
---|
2349 | unsigned int r_length;
|
---|
2350 | int r_pcrel;
|
---|
2351 | int r_baserel, r_jmptable, r_relative;
|
---|
2352 | struct aoutdata *su = &(abfd->tdata.aout_data->a);
|
---|
2353 | unsigned int howto_idx;
|
---|
2354 |
|
---|
2355 | cache_ptr->address = H_GET_32 (abfd, bytes->r_address);
|
---|
2356 |
|
---|
2357 | /* Now the fun stuff. */
|
---|
2358 | if (bfd_header_big_endian (abfd))
|
---|
2359 | {
|
---|
2360 | r_index = (((unsigned int) bytes->r_index[0] << 16)
|
---|
2361 | | ((unsigned int) bytes->r_index[1] << 8)
|
---|
2362 | | bytes->r_index[2]);
|
---|
2363 | r_extern = (0 != (bytes->r_type[0] & RELOC_STD_BITS_EXTERN_BIG));
|
---|
2364 | r_pcrel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_PCREL_BIG));
|
---|
2365 | r_baserel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_BASEREL_BIG));
|
---|
2366 | r_jmptable= (0 != (bytes->r_type[0] & RELOC_STD_BITS_JMPTABLE_BIG));
|
---|
2367 | r_relative= (0 != (bytes->r_type[0] & RELOC_STD_BITS_RELATIVE_BIG));
|
---|
2368 | r_length = ((bytes->r_type[0] & RELOC_STD_BITS_LENGTH_BIG)
|
---|
2369 | >> RELOC_STD_BITS_LENGTH_SH_BIG);
|
---|
2370 | }
|
---|
2371 | else
|
---|
2372 | {
|
---|
2373 | r_index = (((unsigned int) bytes->r_index[2] << 16)
|
---|
2374 | | ((unsigned int) bytes->r_index[1] << 8)
|
---|
2375 | | bytes->r_index[0]);
|
---|
2376 | r_extern = (0 != (bytes->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE));
|
---|
2377 | r_pcrel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE));
|
---|
2378 | r_baserel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_BASEREL_LITTLE));
|
---|
2379 | r_jmptable= (0 != (bytes->r_type[0] & RELOC_STD_BITS_JMPTABLE_LITTLE));
|
---|
2380 | r_relative= (0 != (bytes->r_type[0] & RELOC_STD_BITS_RELATIVE_LITTLE));
|
---|
2381 | r_length = ((bytes->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE)
|
---|
2382 | >> RELOC_STD_BITS_LENGTH_SH_LITTLE);
|
---|
2383 | }
|
---|
2384 |
|
---|
2385 | howto_idx = (r_length + 4 * r_pcrel + 8 * r_baserel
|
---|
2386 | + 16 * r_jmptable + 32 * r_relative);
|
---|
2387 | BFD_ASSERT (howto_idx < TABLE_SIZE (howto_table_std));
|
---|
2388 | cache_ptr->howto = howto_table_std + howto_idx;
|
---|
2389 | BFD_ASSERT (cache_ptr->howto->type != (unsigned int) -1);
|
---|
2390 |
|
---|
2391 | /* Base relative relocs are always against the symbol table,
|
---|
2392 | regardless of the setting of r_extern. r_extern just reflects
|
---|
2393 | whether the symbol the reloc is against is local or global. */
|
---|
2394 | if (r_baserel)
|
---|
2395 | r_extern = 1;
|
---|
2396 |
|
---|
2397 | if (r_extern && r_index > symcount)
|
---|
2398 | {
|
---|
2399 | /* We could arrange to return an error, but it might be useful
|
---|
2400 | to see the file even if it is bad. */
|
---|
2401 | r_extern = 0;
|
---|
2402 | r_index = N_ABS;
|
---|
2403 | }
|
---|
2404 |
|
---|
2405 | MOVE_ADDRESS (0);
|
---|
2406 | }
|
---|
2407 |
|
---|
2408 | /* Read and swap the relocs for a section. */
|
---|
2409 |
|
---|
2410 | bfd_boolean
|
---|
2411 | NAME(aout,slurp_reloc_table) (abfd, asect, symbols)
|
---|
2412 | bfd *abfd;
|
---|
2413 | sec_ptr asect;
|
---|
2414 | asymbol **symbols;
|
---|
2415 | {
|
---|
2416 | bfd_size_type count;
|
---|
2417 | bfd_size_type reloc_size;
|
---|
2418 | PTR relocs;
|
---|
2419 | arelent *reloc_cache;
|
---|
2420 | size_t each_size;
|
---|
2421 | unsigned int counter = 0;
|
---|
2422 | arelent *cache_ptr;
|
---|
2423 | bfd_size_type amt;
|
---|
2424 |
|
---|
2425 | if (asect->relocation)
|
---|
2426 | return TRUE;
|
---|
2427 |
|
---|
2428 | if (asect->flags & SEC_CONSTRUCTOR)
|
---|
2429 | return TRUE;
|
---|
2430 |
|
---|
2431 | if (asect == obj_datasec (abfd))
|
---|
2432 | reloc_size = exec_hdr (abfd)->a_drsize;
|
---|
2433 | else if (asect == obj_textsec (abfd))
|
---|
2434 | reloc_size = exec_hdr (abfd)->a_trsize;
|
---|
2435 | else if (asect == obj_bsssec (abfd))
|
---|
2436 | reloc_size = 0;
|
---|
2437 | else
|
---|
2438 | {
|
---|
2439 | bfd_set_error (bfd_error_invalid_operation);
|
---|
2440 | return FALSE;
|
---|
2441 | }
|
---|
2442 |
|
---|
2443 | if (bfd_seek (abfd, asect->rel_filepos, SEEK_SET) != 0)
|
---|
2444 | return FALSE;
|
---|
2445 |
|
---|
2446 | each_size = obj_reloc_entry_size (abfd);
|
---|
2447 |
|
---|
2448 | count = reloc_size / each_size;
|
---|
2449 |
|
---|
2450 | amt = count * sizeof (arelent);
|
---|
2451 | reloc_cache = (arelent *) bfd_zmalloc (amt);
|
---|
2452 | if (reloc_cache == NULL && count != 0)
|
---|
2453 | return FALSE;
|
---|
2454 |
|
---|
2455 | relocs = bfd_malloc (reloc_size);
|
---|
2456 | if (relocs == NULL && reloc_size != 0)
|
---|
2457 | {
|
---|
2458 | free (reloc_cache);
|
---|
2459 | return FALSE;
|
---|
2460 | }
|
---|
2461 |
|
---|
2462 | if (bfd_bread (relocs, reloc_size, abfd) != reloc_size)
|
---|
2463 | {
|
---|
2464 | free (relocs);
|
---|
2465 | free (reloc_cache);
|
---|
2466 | return FALSE;
|
---|
2467 | }
|
---|
2468 |
|
---|
2469 | cache_ptr = reloc_cache;
|
---|
2470 | if (each_size == RELOC_EXT_SIZE)
|
---|
2471 | {
|
---|
2472 | struct reloc_ext_external *rptr = (struct reloc_ext_external *) relocs;
|
---|
2473 |
|
---|
2474 | for (; counter < count; counter++, rptr++, cache_ptr++)
|
---|
2475 | MY_swap_ext_reloc_in (abfd, rptr, cache_ptr, symbols,
|
---|
2476 | (bfd_size_type) bfd_get_symcount (abfd));
|
---|
2477 | }
|
---|
2478 | else
|
---|
2479 | {
|
---|
2480 | struct reloc_std_external *rptr = (struct reloc_std_external *) relocs;
|
---|
2481 |
|
---|
2482 | for (; counter < count; counter++, rptr++, cache_ptr++)
|
---|
2483 | MY_swap_std_reloc_in (abfd, rptr, cache_ptr, symbols,
|
---|
2484 | (bfd_size_type) bfd_get_symcount (abfd));
|
---|
2485 | }
|
---|
2486 |
|
---|
2487 | free (relocs);
|
---|
2488 |
|
---|
2489 | asect->relocation = reloc_cache;
|
---|
2490 | asect->reloc_count = cache_ptr - reloc_cache;
|
---|
2491 |
|
---|
2492 | return TRUE;
|
---|
2493 | }
|
---|
2494 |
|
---|
2495 | /* Write out a relocation section into an object file. */
|
---|
2496 |
|
---|
2497 | bfd_boolean
|
---|
2498 | NAME(aout,squirt_out_relocs) (abfd, section)
|
---|
2499 | bfd *abfd;
|
---|
2500 | asection *section;
|
---|
2501 | {
|
---|
2502 | arelent **generic;
|
---|
2503 | unsigned char *native, *natptr;
|
---|
2504 | size_t each_size;
|
---|
2505 |
|
---|
2506 | unsigned int count = section->reloc_count;
|
---|
2507 | bfd_size_type natsize;
|
---|
2508 |
|
---|
2509 | if (count == 0 || section->orelocation == NULL)
|
---|
2510 | return TRUE;
|
---|
2511 |
|
---|
2512 | each_size = obj_reloc_entry_size (abfd);
|
---|
2513 | natsize = (bfd_size_type) each_size * count;
|
---|
2514 | native = (unsigned char *) bfd_zalloc (abfd, natsize);
|
---|
2515 | if (!native)
|
---|
2516 | return FALSE;
|
---|
2517 |
|
---|
2518 | generic = section->orelocation;
|
---|
2519 |
|
---|
2520 | if (each_size == RELOC_EXT_SIZE)
|
---|
2521 | {
|
---|
2522 | for (natptr = native;
|
---|
2523 | count != 0;
|
---|
2524 | --count, natptr += each_size, ++generic)
|
---|
2525 | MY_swap_ext_reloc_out (abfd, *generic,
|
---|
2526 | (struct reloc_ext_external *) natptr);
|
---|
2527 | }
|
---|
2528 | else
|
---|
2529 | {
|
---|
2530 | for (natptr = native;
|
---|
2531 | count != 0;
|
---|
2532 | --count, natptr += each_size, ++generic)
|
---|
2533 | MY_swap_std_reloc_out (abfd, *generic,
|
---|
2534 | (struct reloc_std_external *) natptr);
|
---|
2535 | }
|
---|
2536 |
|
---|
2537 | if (bfd_bwrite ((PTR) native, natsize, abfd) != natsize)
|
---|
2538 | {
|
---|
2539 | bfd_release (abfd, native);
|
---|
2540 | return FALSE;
|
---|
2541 | }
|
---|
2542 | bfd_release (abfd, native);
|
---|
2543 |
|
---|
2544 | return TRUE;
|
---|
2545 | }
|
---|
2546 |
|
---|
2547 | /* This is stupid. This function should be a boolean predicate. */
|
---|
2548 |
|
---|
2549 | long
|
---|
2550 | NAME(aout,canonicalize_reloc) (abfd, section, relptr, symbols)
|
---|
2551 | bfd *abfd;
|
---|
2552 | sec_ptr section;
|
---|
2553 | arelent **relptr;
|
---|
2554 | asymbol **symbols;
|
---|
2555 | {
|
---|
2556 | arelent *tblptr = section->relocation;
|
---|
2557 | unsigned int count;
|
---|
2558 |
|
---|
2559 | if (section == obj_bsssec (abfd))
|
---|
2560 | {
|
---|
2561 | *relptr = NULL;
|
---|
2562 | return 0;
|
---|
2563 | }
|
---|
2564 |
|
---|
2565 | if (!(tblptr || NAME(aout,slurp_reloc_table) (abfd, section, symbols)))
|
---|
2566 | return -1;
|
---|
2567 |
|
---|
2568 | if (section->flags & SEC_CONSTRUCTOR)
|
---|
2569 | {
|
---|
2570 | arelent_chain *chain = section->constructor_chain;
|
---|
2571 | for (count = 0; count < section->reloc_count; count ++)
|
---|
2572 | {
|
---|
2573 | *relptr ++ = &chain->relent;
|
---|
2574 | chain = chain->next;
|
---|
2575 | }
|
---|
2576 | }
|
---|
2577 | else
|
---|
2578 | {
|
---|
2579 | tblptr = section->relocation;
|
---|
2580 |
|
---|
2581 | for (count = 0; count++ < section->reloc_count; )
|
---|
2582 | {
|
---|
2583 | *relptr++ = tblptr++;
|
---|
2584 | }
|
---|
2585 | }
|
---|
2586 | *relptr = 0;
|
---|
2587 |
|
---|
2588 | return section->reloc_count;
|
---|
2589 | }
|
---|
2590 |
|
---|
2591 | long
|
---|
2592 | NAME(aout,get_reloc_upper_bound) (abfd, asect)
|
---|
2593 | bfd *abfd;
|
---|
2594 | sec_ptr asect;
|
---|
2595 | {
|
---|
2596 | if (bfd_get_format (abfd) != bfd_object)
|
---|
2597 | {
|
---|
2598 | bfd_set_error (bfd_error_invalid_operation);
|
---|
2599 | return -1;
|
---|
2600 | }
|
---|
2601 |
|
---|
2602 | if (asect->flags & SEC_CONSTRUCTOR)
|
---|
2603 | return (sizeof (arelent *) * (asect->reloc_count+1));
|
---|
2604 |
|
---|
2605 | if (asect == obj_datasec (abfd))
|
---|
2606 | return (sizeof (arelent *)
|
---|
2607 | * ((exec_hdr (abfd)->a_drsize / obj_reloc_entry_size (abfd))
|
---|
2608 | + 1));
|
---|
2609 |
|
---|
2610 | if (asect == obj_textsec (abfd))
|
---|
2611 | return (sizeof (arelent *)
|
---|
2612 | * ((exec_hdr (abfd)->a_trsize / obj_reloc_entry_size (abfd))
|
---|
2613 | + 1));
|
---|
2614 |
|
---|
2615 | if (asect == obj_bsssec (abfd))
|
---|
2616 | return sizeof (arelent *);
|
---|
2617 |
|
---|
2618 | if (asect == obj_bsssec (abfd))
|
---|
2619 | return 0;
|
---|
2620 |
|
---|
2621 | bfd_set_error (bfd_error_invalid_operation);
|
---|
2622 | return -1;
|
---|
2623 | }
|
---|
2624 | |
---|
2625 |
|
---|
2626 | long
|
---|
2627 | NAME(aout,get_symtab_upper_bound) (abfd)
|
---|
2628 | bfd *abfd;
|
---|
2629 | {
|
---|
2630 | if (!NAME(aout,slurp_symbol_table) (abfd))
|
---|
2631 | return -1;
|
---|
2632 |
|
---|
2633 | return (bfd_get_symcount (abfd)+1) * (sizeof (aout_symbol_type *));
|
---|
2634 | }
|
---|
2635 |
|
---|
2636 | alent *
|
---|
2637 | NAME(aout,get_lineno) (ignore_abfd, ignore_symbol)
|
---|
2638 | bfd *ignore_abfd ATTRIBUTE_UNUSED;
|
---|
2639 | asymbol *ignore_symbol ATTRIBUTE_UNUSED;
|
---|
2640 | {
|
---|
2641 | return (alent *)NULL;
|
---|
2642 | }
|
---|
2643 |
|
---|
2644 | void
|
---|
2645 | NAME(aout,get_symbol_info) (ignore_abfd, symbol, ret)
|
---|
2646 | bfd *ignore_abfd ATTRIBUTE_UNUSED;
|
---|
2647 | asymbol *symbol;
|
---|
2648 | symbol_info *ret;
|
---|
2649 | {
|
---|
2650 | bfd_symbol_info (symbol, ret);
|
---|
2651 |
|
---|
2652 | if (ret->type == '?')
|
---|
2653 | {
|
---|
2654 | int type_code = aout_symbol (symbol)->type & 0xff;
|
---|
2655 | const char *stab_name = bfd_get_stab_name (type_code);
|
---|
2656 | static char buf[10];
|
---|
2657 |
|
---|
2658 | if (stab_name == NULL)
|
---|
2659 | {
|
---|
2660 | sprintf (buf, "(%d)", type_code);
|
---|
2661 | stab_name = buf;
|
---|
2662 | }
|
---|
2663 | ret->type = '-';
|
---|
2664 | ret->stab_type = type_code;
|
---|
2665 | ret->stab_other = (unsigned) (aout_symbol (symbol)->other & 0xff);
|
---|
2666 | ret->stab_desc = (unsigned) (aout_symbol (symbol)->desc & 0xffff);
|
---|
2667 | ret->stab_name = stab_name;
|
---|
2668 | }
|
---|
2669 | }
|
---|
2670 |
|
---|
2671 | void
|
---|
2672 | NAME(aout,print_symbol) (abfd, afile, symbol, how)
|
---|
2673 | bfd *abfd;
|
---|
2674 | PTR afile;
|
---|
2675 | asymbol *symbol;
|
---|
2676 | bfd_print_symbol_type how;
|
---|
2677 | {
|
---|
2678 | FILE *file = (FILE *)afile;
|
---|
2679 |
|
---|
2680 | switch (how)
|
---|
2681 | {
|
---|
2682 | case bfd_print_symbol_name:
|
---|
2683 | if (symbol->name)
|
---|
2684 | fprintf (file,"%s", symbol->name);
|
---|
2685 | break;
|
---|
2686 | case bfd_print_symbol_more:
|
---|
2687 | fprintf (file,"%4x %2x %2x",
|
---|
2688 | (unsigned) (aout_symbol (symbol)->desc & 0xffff),
|
---|
2689 | (unsigned) (aout_symbol (symbol)->other & 0xff),
|
---|
2690 | (unsigned) (aout_symbol (symbol)->type));
|
---|
2691 | break;
|
---|
2692 | case bfd_print_symbol_all:
|
---|
2693 | {
|
---|
2694 | const char *section_name = symbol->section->name;
|
---|
2695 |
|
---|
2696 | bfd_print_symbol_vandf (abfd, (PTR)file, symbol);
|
---|
2697 |
|
---|
2698 | fprintf (file," %-5s %04x %02x %02x",
|
---|
2699 | section_name,
|
---|
2700 | (unsigned) (aout_symbol (symbol)->desc & 0xffff),
|
---|
2701 | (unsigned) (aout_symbol (symbol)->other & 0xff),
|
---|
2702 | (unsigned) (aout_symbol (symbol)->type & 0xff));
|
---|
2703 | if (symbol->name)
|
---|
2704 | fprintf (file," %s", symbol->name);
|
---|
2705 | }
|
---|
2706 | break;
|
---|
2707 | }
|
---|
2708 | }
|
---|
2709 |
|
---|
2710 | /* If we don't have to allocate more than 1MB to hold the generic
|
---|
2711 | symbols, we use the generic minisymbol methord: it's faster, since
|
---|
2712 | it only translates the symbols once, not multiple times. */
|
---|
2713 | #define MINISYM_THRESHOLD (1000000 / sizeof (asymbol))
|
---|
2714 |
|
---|
2715 | /* Read minisymbols. For minisymbols, we use the unmodified a.out
|
---|
2716 | symbols. The minisymbol_to_symbol function translates these into
|
---|
2717 | BFD asymbol structures. */
|
---|
2718 |
|
---|
2719 | long
|
---|
2720 | NAME(aout,read_minisymbols) (abfd, dynamic, minisymsp, sizep)
|
---|
2721 | bfd *abfd;
|
---|
2722 | bfd_boolean dynamic;
|
---|
2723 | PTR *minisymsp;
|
---|
2724 | unsigned int *sizep;
|
---|
2725 | {
|
---|
2726 | if (dynamic)
|
---|
2727 | {
|
---|
2728 | /* We could handle the dynamic symbols here as well, but it's
|
---|
2729 | easier to hand them off. */
|
---|
2730 | return _bfd_generic_read_minisymbols (abfd, dynamic, minisymsp, sizep);
|
---|
2731 | }
|
---|
2732 |
|
---|
2733 | if (! aout_get_external_symbols (abfd))
|
---|
2734 | return -1;
|
---|
2735 |
|
---|
2736 | if (obj_aout_external_sym_count (abfd) < MINISYM_THRESHOLD)
|
---|
2737 | return _bfd_generic_read_minisymbols (abfd, dynamic, minisymsp, sizep);
|
---|
2738 |
|
---|
2739 | *minisymsp = (PTR) obj_aout_external_syms (abfd);
|
---|
2740 |
|
---|
2741 | /* By passing the external symbols back from this routine, we are
|
---|
2742 | giving up control over the memory block. Clear
|
---|
2743 | obj_aout_external_syms, so that we do not try to free it
|
---|
2744 | ourselves. */
|
---|
2745 | obj_aout_external_syms (abfd) = NULL;
|
---|
2746 |
|
---|
2747 | *sizep = EXTERNAL_NLIST_SIZE;
|
---|
2748 | return obj_aout_external_sym_count (abfd);
|
---|
2749 | }
|
---|
2750 |
|
---|
2751 | /* Convert a minisymbol to a BFD asymbol. A minisymbol is just an
|
---|
2752 | unmodified a.out symbol. The SYM argument is a structure returned
|
---|
2753 | by bfd_make_empty_symbol, which we fill in here. */
|
---|
2754 |
|
---|
2755 | asymbol *
|
---|
2756 | NAME(aout,minisymbol_to_symbol) (abfd, dynamic, minisym, sym)
|
---|
2757 | bfd *abfd;
|
---|
2758 | bfd_boolean dynamic;
|
---|
2759 | const PTR minisym;
|
---|
2760 | asymbol *sym;
|
---|
2761 | {
|
---|
2762 | if (dynamic
|
---|
2763 | || obj_aout_external_sym_count (abfd) < MINISYM_THRESHOLD)
|
---|
2764 | return _bfd_generic_minisymbol_to_symbol (abfd, dynamic, minisym, sym);
|
---|
2765 |
|
---|
2766 | memset (sym, 0, sizeof (aout_symbol_type));
|
---|
2767 |
|
---|
2768 | /* We call translate_symbol_table to translate a single symbol. */
|
---|
2769 | if (! (NAME(aout,translate_symbol_table)
|
---|
2770 | (abfd,
|
---|
2771 | (aout_symbol_type *) sym,
|
---|
2772 | (struct external_nlist *) minisym,
|
---|
2773 | (bfd_size_type) 1,
|
---|
2774 | obj_aout_external_strings (abfd),
|
---|
2775 | obj_aout_external_string_size (abfd),
|
---|
2776 | FALSE)))
|
---|
2777 | return NULL;
|
---|
2778 |
|
---|
2779 | return sym;
|
---|
2780 | }
|
---|
2781 |
|
---|
2782 | /* Provided a BFD, a section and an offset into the section, calculate
|
---|
2783 | and return the name of the source file and the line nearest to the
|
---|
2784 | wanted location. */
|
---|
2785 |
|
---|
2786 | bfd_boolean
|
---|
2787 | NAME(aout,find_nearest_line)
|
---|
2788 | (abfd, section, symbols, offset, filename_ptr, functionname_ptr, line_ptr)
|
---|
2789 | bfd *abfd;
|
---|
2790 | asection *section;
|
---|
2791 | asymbol **symbols;
|
---|
2792 | bfd_vma offset;
|
---|
2793 | const char **filename_ptr;
|
---|
2794 | const char **functionname_ptr;
|
---|
2795 | unsigned int *line_ptr;
|
---|
2796 | {
|
---|
2797 | /* Run down the file looking for the filename, function and linenumber. */
|
---|
2798 | asymbol **p;
|
---|
2799 | const char *directory_name = NULL;
|
---|
2800 | const char *main_file_name = NULL;
|
---|
2801 | const char *current_file_name = NULL;
|
---|
2802 | const char *line_file_name = NULL; /* Value of current_file_name at line number. */
|
---|
2803 | const char *line_directory_name = NULL; /* Value of directory_name at line number. */
|
---|
2804 | bfd_vma low_line_vma = 0;
|
---|
2805 | bfd_vma low_func_vma = 0;
|
---|
2806 | asymbol *func = 0;
|
---|
2807 | bfd_size_type filelen, funclen;
|
---|
2808 | char *buf;
|
---|
2809 |
|
---|
2810 | *filename_ptr = abfd->filename;
|
---|
2811 | *functionname_ptr = 0;
|
---|
2812 | *line_ptr = 0;
|
---|
2813 |
|
---|
2814 | if (symbols != (asymbol **)NULL)
|
---|
2815 | {
|
---|
2816 | for (p = symbols; *p; p++)
|
---|
2817 | {
|
---|
2818 | aout_symbol_type *q = (aout_symbol_type *) (*p);
|
---|
2819 | next:
|
---|
2820 | switch (q->type)
|
---|
2821 | {
|
---|
2822 | case N_TEXT:
|
---|
2823 | /* If this looks like a file name symbol, and it comes after
|
---|
2824 | the line number we have found so far, but before the
|
---|
2825 | offset, then we have probably not found the right line
|
---|
2826 | number. */
|
---|
2827 | if (q->symbol.value <= offset
|
---|
2828 | && ((q->symbol.value > low_line_vma
|
---|
2829 | && (line_file_name != NULL
|
---|
2830 | || *line_ptr != 0))
|
---|
2831 | || (q->symbol.value > low_func_vma
|
---|
2832 | && func != NULL)))
|
---|
2833 | {
|
---|
2834 | const char *symname;
|
---|
2835 |
|
---|
2836 | symname = q->symbol.name;
|
---|
2837 | if (strcmp (symname + strlen (symname) - 2, ".o") == 0)
|
---|
2838 | {
|
---|
2839 | if (q->symbol.value > low_line_vma)
|
---|
2840 | {
|
---|
2841 | *line_ptr = 0;
|
---|
2842 | line_file_name = NULL;
|
---|
2843 | }
|
---|
2844 | if (q->symbol.value > low_func_vma)
|
---|
2845 | func = NULL;
|
---|
2846 | }
|
---|
2847 | }
|
---|
2848 | break;
|
---|
2849 |
|
---|
2850 | case N_SO:
|
---|
2851 | /* If this symbol is less than the offset, but greater than
|
---|
2852 | the line number we have found so far, then we have not
|
---|
2853 | found the right line number. */
|
---|
2854 | if (q->symbol.value <= offset)
|
---|
2855 | {
|
---|
2856 | if (q->symbol.value > low_line_vma)
|
---|
2857 | {
|
---|
2858 | *line_ptr = 0;
|
---|
2859 | line_file_name = NULL;
|
---|
2860 | }
|
---|
2861 | if (q->symbol.value > low_func_vma)
|
---|
2862 | func = NULL;
|
---|
2863 | }
|
---|
2864 |
|
---|
2865 | main_file_name = current_file_name = q->symbol.name;
|
---|
2866 | /* Look ahead to next symbol to check if that too is an N_SO. */
|
---|
2867 | p++;
|
---|
2868 | if (*p == NULL)
|
---|
2869 | break;
|
---|
2870 | q = (aout_symbol_type *) (*p);
|
---|
2871 | if (q->type != (int)N_SO)
|
---|
2872 | goto next;
|
---|
2873 |
|
---|
2874 | /* Found a second N_SO First is directory; second is filename. */
|
---|
2875 | directory_name = current_file_name;
|
---|
2876 | main_file_name = current_file_name = q->symbol.name;
|
---|
2877 | if (obj_textsec (abfd) != section)
|
---|
2878 | goto done;
|
---|
2879 | break;
|
---|
2880 | case N_SOL:
|
---|
2881 | current_file_name = q->symbol.name;
|
---|
2882 | break;
|
---|
2883 |
|
---|
2884 | case N_SLINE:
|
---|
2885 |
|
---|
2886 | case N_DSLINE:
|
---|
2887 | case N_BSLINE:
|
---|
2888 | /* We'll keep this if it resolves nearer than the one we have
|
---|
2889 | already. */
|
---|
2890 | if (q->symbol.value >= low_line_vma
|
---|
2891 | && q->symbol.value <= offset)
|
---|
2892 | {
|
---|
2893 | *line_ptr = q->desc;
|
---|
2894 | low_line_vma = q->symbol.value;
|
---|
2895 | line_file_name = current_file_name;
|
---|
2896 | line_directory_name = directory_name;
|
---|
2897 | }
|
---|
2898 | break;
|
---|
2899 | case N_FUN:
|
---|
2900 | {
|
---|
2901 | /* We'll keep this if it is nearer than the one we have already. */
|
---|
2902 | if (q->symbol.value >= low_func_vma &&
|
---|
2903 | q->symbol.value <= offset)
|
---|
2904 | {
|
---|
2905 | low_func_vma = q->symbol.value;
|
---|
2906 | func = (asymbol *)q;
|
---|
2907 | }
|
---|
2908 | else if (q->symbol.value > offset)
|
---|
2909 | goto done;
|
---|
2910 | }
|
---|
2911 | break;
|
---|
2912 | }
|
---|
2913 | }
|
---|
2914 | }
|
---|
2915 |
|
---|
2916 | done:
|
---|
2917 | if (*line_ptr != 0)
|
---|
2918 | {
|
---|
2919 | main_file_name = line_file_name;
|
---|
2920 | directory_name = line_directory_name;
|
---|
2921 | }
|
---|
2922 |
|
---|
2923 | if (main_file_name == NULL
|
---|
2924 | || IS_ABSOLUTE_PATH (main_file_name)
|
---|
2925 | || directory_name == NULL)
|
---|
2926 | filelen = 0;
|
---|
2927 | else
|
---|
2928 | filelen = strlen (directory_name) + strlen (main_file_name);
|
---|
2929 |
|
---|
2930 | if (func == NULL)
|
---|
2931 | funclen = 0;
|
---|
2932 | else
|
---|
2933 | funclen = strlen (bfd_asymbol_name (func));
|
---|
2934 |
|
---|
2935 | if (adata (abfd).line_buf != NULL)
|
---|
2936 | free (adata (abfd).line_buf);
|
---|
2937 |
|
---|
2938 | if (filelen + funclen == 0)
|
---|
2939 | adata (abfd).line_buf = buf = NULL;
|
---|
2940 | else
|
---|
2941 | {
|
---|
2942 | buf = (char *) bfd_malloc (filelen + funclen + 3);
|
---|
2943 | adata (abfd).line_buf = buf;
|
---|
2944 | if (buf == NULL)
|
---|
2945 | return FALSE;
|
---|
2946 | }
|
---|
2947 |
|
---|
2948 | if (main_file_name != NULL)
|
---|
2949 | {
|
---|
2950 | if (IS_ABSOLUTE_PATH (main_file_name) || directory_name == NULL)
|
---|
2951 | *filename_ptr = main_file_name;
|
---|
2952 | else
|
---|
2953 | {
|
---|
2954 | sprintf (buf, "%s%s", directory_name, main_file_name);
|
---|
2955 | *filename_ptr = buf;
|
---|
2956 | buf += filelen + 1;
|
---|
2957 | }
|
---|
2958 | }
|
---|
2959 |
|
---|
2960 | if (func)
|
---|
2961 | {
|
---|
2962 | const char *function = func->name;
|
---|
2963 | char *colon;
|
---|
2964 |
|
---|
2965 | /* The caller expects a symbol name. We actually have a
|
---|
2966 | function name, without the leading underscore. Put the
|
---|
2967 | underscore back in, so that the caller gets a symbol name. */
|
---|
2968 | if (bfd_get_symbol_leading_char (abfd) == '\0')
|
---|
2969 | strcpy (buf, function);
|
---|
2970 | else
|
---|
2971 | {
|
---|
2972 | buf[0] = bfd_get_symbol_leading_char (abfd);
|
---|
2973 | strcpy (buf + 1, function);
|
---|
2974 | }
|
---|
2975 | /* Have to remove : stuff. */
|
---|
2976 | colon = strchr (buf, ':');
|
---|
2977 | if (colon != NULL)
|
---|
2978 | *colon = '\0';
|
---|
2979 | *functionname_ptr = buf;
|
---|
2980 | }
|
---|
2981 |
|
---|
2982 | return TRUE;
|
---|
2983 | }
|
---|
2984 |
|
---|
2985 | int
|
---|
2986 | NAME(aout,sizeof_headers) (abfd, execable)
|
---|
2987 | bfd *abfd;
|
---|
2988 | bfd_boolean execable ATTRIBUTE_UNUSED;
|
---|
2989 | {
|
---|
2990 | return adata (abfd).exec_bytes_size;
|
---|
2991 | }
|
---|
2992 |
|
---|
2993 | /* Free all information we have cached for this BFD. We can always
|
---|
2994 | read it again later if we need it. */
|
---|
2995 |
|
---|
2996 | bfd_boolean
|
---|
2997 | NAME(aout,bfd_free_cached_info) (abfd)
|
---|
2998 | bfd *abfd;
|
---|
2999 | {
|
---|
3000 | asection *o;
|
---|
3001 |
|
---|
3002 | if (bfd_get_format (abfd) != bfd_object
|
---|
3003 | || abfd->tdata.aout_data == NULL)
|
---|
3004 | return TRUE;
|
---|
3005 |
|
---|
3006 | #define BFCI_FREE(x) if (x != NULL) { free (x); x = NULL; }
|
---|
3007 | BFCI_FREE (obj_aout_symbols (abfd));
|
---|
3008 | #ifdef USE_MMAP
|
---|
3009 | obj_aout_external_syms (abfd) = 0;
|
---|
3010 | bfd_free_window (&obj_aout_sym_window (abfd));
|
---|
3011 | bfd_free_window (&obj_aout_string_window (abfd));
|
---|
3012 | obj_aout_external_strings (abfd) = 0;
|
---|
3013 | #else
|
---|
3014 | BFCI_FREE (obj_aout_external_syms (abfd));
|
---|
3015 | BFCI_FREE (obj_aout_external_strings (abfd));
|
---|
3016 | #endif
|
---|
3017 | for (o = abfd->sections; o != (asection *) NULL; o = o->next)
|
---|
3018 | BFCI_FREE (o->relocation);
|
---|
3019 | #undef BFCI_FREE
|
---|
3020 |
|
---|
3021 | return TRUE;
|
---|
3022 | }
|
---|
3023 | |
---|
3024 |
|
---|
3025 | /* a.out link code. */
|
---|
3026 |
|
---|
3027 | static bfd_boolean aout_link_add_object_symbols
|
---|
3028 | PARAMS ((bfd *, struct bfd_link_info *));
|
---|
3029 | static bfd_boolean aout_link_check_archive_element
|
---|
3030 | PARAMS ((bfd *, struct bfd_link_info *, bfd_boolean *));
|
---|
3031 | static bfd_boolean aout_link_free_symbols
|
---|
3032 | PARAMS ((bfd *));
|
---|
3033 | static bfd_boolean aout_link_check_ar_symbols
|
---|
3034 | PARAMS ((bfd *, struct bfd_link_info *, bfd_boolean *pneeded));
|
---|
3035 | static bfd_boolean aout_link_add_symbols
|
---|
3036 | PARAMS ((bfd *, struct bfd_link_info *));
|
---|
3037 |
|
---|
3038 | /* Routine to create an entry in an a.out link hash table. */
|
---|
3039 |
|
---|
3040 | struct bfd_hash_entry *
|
---|
3041 | NAME(aout,link_hash_newfunc) (entry, table, string)
|
---|
3042 | struct bfd_hash_entry *entry;
|
---|
3043 | struct bfd_hash_table *table;
|
---|
3044 | const char *string;
|
---|
3045 | {
|
---|
3046 | struct aout_link_hash_entry *ret = (struct aout_link_hash_entry *) entry;
|
---|
3047 |
|
---|
3048 | /* Allocate the structure if it has not already been allocated by a
|
---|
3049 | subclass. */
|
---|
3050 | if (ret == (struct aout_link_hash_entry *) NULL)
|
---|
3051 | ret = ((struct aout_link_hash_entry *)
|
---|
3052 | bfd_hash_allocate (table, sizeof (struct aout_link_hash_entry)));
|
---|
3053 | if (ret == (struct aout_link_hash_entry *) NULL)
|
---|
3054 | return (struct bfd_hash_entry *) ret;
|
---|
3055 |
|
---|
3056 | /* Call the allocation method of the superclass. */
|
---|
3057 | ret = ((struct aout_link_hash_entry *)
|
---|
3058 | _bfd_link_hash_newfunc ((struct bfd_hash_entry *) ret,
|
---|
3059 | table, string));
|
---|
3060 | if (ret)
|
---|
3061 | {
|
---|
3062 | /* Set local fields. */
|
---|
3063 | ret->written = FALSE;
|
---|
3064 | ret->indx = -1;
|
---|
3065 | }
|
---|
3066 |
|
---|
3067 | return (struct bfd_hash_entry *) ret;
|
---|
3068 | }
|
---|
3069 |
|
---|
3070 | /* Initialize an a.out link hash table. */
|
---|
3071 |
|
---|
3072 | bfd_boolean
|
---|
3073 | NAME(aout,link_hash_table_init) (table, abfd, newfunc)
|
---|
3074 | struct aout_link_hash_table *table;
|
---|
3075 | bfd *abfd;
|
---|
3076 | struct bfd_hash_entry *(*newfunc)
|
---|
3077 | PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *,
|
---|
3078 | const char *));
|
---|
3079 | {
|
---|
3080 | return _bfd_link_hash_table_init (&table->root, abfd, newfunc);
|
---|
3081 | }
|
---|
3082 |
|
---|
3083 | /* Create an a.out link hash table. */
|
---|
3084 |
|
---|
3085 | struct bfd_link_hash_table *
|
---|
3086 | NAME(aout,link_hash_table_create) (abfd)
|
---|
3087 | bfd *abfd;
|
---|
3088 | {
|
---|
3089 | struct aout_link_hash_table *ret;
|
---|
3090 | bfd_size_type amt = sizeof (struct aout_link_hash_table);
|
---|
3091 |
|
---|
3092 | ret = (struct aout_link_hash_table *) bfd_malloc (amt);
|
---|
3093 | if (ret == NULL)
|
---|
3094 | return (struct bfd_link_hash_table *) NULL;
|
---|
3095 |
|
---|
3096 | if (! NAME(aout,link_hash_table_init) (ret, abfd,
|
---|
3097 | NAME(aout,link_hash_newfunc)))
|
---|
3098 | {
|
---|
3099 | free (ret);
|
---|
3100 | return (struct bfd_link_hash_table *) NULL;
|
---|
3101 | }
|
---|
3102 | return &ret->root;
|
---|
3103 | }
|
---|
3104 |
|
---|
3105 | /* Given an a.out BFD, add symbols to the global hash table as
|
---|
3106 | appropriate. */
|
---|
3107 |
|
---|
3108 | bfd_boolean
|
---|
3109 | NAME(aout,link_add_symbols) (abfd, info)
|
---|
3110 | bfd *abfd;
|
---|
3111 | struct bfd_link_info *info;
|
---|
3112 | {
|
---|
3113 | switch (bfd_get_format (abfd))
|
---|
3114 | {
|
---|
3115 | case bfd_object:
|
---|
3116 | return aout_link_add_object_symbols (abfd, info);
|
---|
3117 | case bfd_archive:
|
---|
3118 | return _bfd_generic_link_add_archive_symbols
|
---|
3119 | (abfd, info, aout_link_check_archive_element);
|
---|
3120 | default:
|
---|
3121 | bfd_set_error (bfd_error_wrong_format);
|
---|
3122 | return FALSE;
|
---|
3123 | }
|
---|
3124 | }
|
---|
3125 |
|
---|
3126 | /* Add symbols from an a.out object file. */
|
---|
3127 |
|
---|
3128 | static bfd_boolean
|
---|
3129 | aout_link_add_object_symbols (abfd, info)
|
---|
3130 | bfd *abfd;
|
---|
3131 | struct bfd_link_info *info;
|
---|
3132 | {
|
---|
3133 | if (! aout_get_external_symbols (abfd))
|
---|
3134 | return FALSE;
|
---|
3135 | if (! aout_link_add_symbols (abfd, info))
|
---|
3136 | return FALSE;
|
---|
3137 | if (! info->keep_memory)
|
---|
3138 | {
|
---|
3139 | if (! aout_link_free_symbols (abfd))
|
---|
3140 | return FALSE;
|
---|
3141 | }
|
---|
3142 | return TRUE;
|
---|
3143 | }
|
---|
3144 |
|
---|
3145 | /* Check a single archive element to see if we need to include it in
|
---|
3146 | the link. *PNEEDED is set according to whether this element is
|
---|
3147 | needed in the link or not. This is called from
|
---|
3148 | _bfd_generic_link_add_archive_symbols. */
|
---|
3149 |
|
---|
3150 | static bfd_boolean
|
---|
3151 | aout_link_check_archive_element (abfd, info, pneeded)
|
---|
3152 | bfd *abfd;
|
---|
3153 | struct bfd_link_info *info;
|
---|
3154 | bfd_boolean *pneeded;
|
---|
3155 | {
|
---|
3156 | if (! aout_get_external_symbols (abfd))
|
---|
3157 | return FALSE;
|
---|
3158 |
|
---|
3159 | if (! aout_link_check_ar_symbols (abfd, info, pneeded))
|
---|
3160 | return FALSE;
|
---|
3161 |
|
---|
3162 | if (*pneeded)
|
---|
3163 | {
|
---|
3164 | if (! aout_link_add_symbols (abfd, info))
|
---|
3165 | return FALSE;
|
---|
3166 | }
|
---|
3167 |
|
---|
3168 | if (! info->keep_memory || ! *pneeded)
|
---|
3169 | {
|
---|
3170 | if (! aout_link_free_symbols (abfd))
|
---|
3171 | return FALSE;
|
---|
3172 | }
|
---|
3173 |
|
---|
3174 | return TRUE;
|
---|
3175 | }
|
---|
3176 |
|
---|
3177 | /* Free up the internal symbols read from an a.out file. */
|
---|
3178 |
|
---|
3179 | static bfd_boolean
|
---|
3180 | aout_link_free_symbols (abfd)
|
---|
3181 | bfd *abfd;
|
---|
3182 | {
|
---|
3183 | if (obj_aout_external_syms (abfd) != (struct external_nlist *) NULL)
|
---|
3184 | {
|
---|
3185 | #ifdef USE_MMAP
|
---|
3186 | bfd_free_window (&obj_aout_sym_window (abfd));
|
---|
3187 | #else
|
---|
3188 | free ((PTR) obj_aout_external_syms (abfd));
|
---|
3189 | #endif
|
---|
3190 | obj_aout_external_syms (abfd) = (struct external_nlist *) NULL;
|
---|
3191 | }
|
---|
3192 | if (obj_aout_external_strings (abfd) != (char *) NULL)
|
---|
3193 | {
|
---|
3194 | #ifdef USE_MMAP
|
---|
3195 | bfd_free_window (&obj_aout_string_window (abfd));
|
---|
3196 | #else
|
---|
3197 | free ((PTR) obj_aout_external_strings (abfd));
|
---|
3198 | #endif
|
---|
3199 | obj_aout_external_strings (abfd) = (char *) NULL;
|
---|
3200 | }
|
---|
3201 | return TRUE;
|
---|
3202 | }
|
---|
3203 |
|
---|
3204 | /* Look through the internal symbols to see if this object file should
|
---|
3205 | be included in the link. We should include this object file if it
|
---|
3206 | defines any symbols which are currently undefined. If this object
|
---|
3207 | file defines a common symbol, then we may adjust the size of the
|
---|
3208 | known symbol but we do not include the object file in the link
|
---|
3209 | (unless there is some other reason to include it). */
|
---|
3210 |
|
---|
3211 | static bfd_boolean
|
---|
3212 | aout_link_check_ar_symbols (abfd, info, pneeded)
|
---|
3213 | bfd *abfd;
|
---|
3214 | struct bfd_link_info *info;
|
---|
3215 | bfd_boolean *pneeded;
|
---|
3216 | {
|
---|
3217 | register struct external_nlist *p;
|
---|
3218 | struct external_nlist *pend;
|
---|
3219 | char *strings;
|
---|
3220 |
|
---|
3221 | *pneeded = FALSE;
|
---|
3222 |
|
---|
3223 | /* Look through all the symbols. */
|
---|
3224 | p = obj_aout_external_syms (abfd);
|
---|
3225 | pend = p + obj_aout_external_sym_count (abfd);
|
---|
3226 | strings = obj_aout_external_strings (abfd);
|
---|
3227 | for (; p < pend; p++)
|
---|
3228 | {
|
---|
3229 | int type = H_GET_8 (abfd, p->e_type);
|
---|
3230 | const char *name;
|
---|
3231 | struct bfd_link_hash_entry *h;
|
---|
3232 |
|
---|
3233 | /* Ignore symbols that are not externally visible. This is an
|
---|
3234 | optimization only, as we check the type more thoroughly
|
---|
3235 | below. */
|
---|
3236 | if (((type & N_EXT) == 0
|
---|
3237 | || IS_STAB(type)
|
---|
3238 | || type == N_FN)
|
---|
3239 | && type != N_WEAKA
|
---|
3240 | && type != N_WEAKT
|
---|
3241 | && type != N_WEAKD
|
---|
3242 | && type != N_WEAKB)
|
---|
3243 | {
|
---|
3244 | if (type == N_WARNING
|
---|
3245 | || type == N_INDR)
|
---|
3246 | ++p;
|
---|
3247 | continue;
|
---|
3248 | }
|
---|
3249 |
|
---|
3250 | name = strings + GET_WORD (abfd, p->e_strx);
|
---|
3251 | h = bfd_link_hash_lookup (info->hash, name, FALSE, FALSE, TRUE);
|
---|
3252 |
|
---|
3253 | /* We are only interested in symbols that are currently
|
---|
3254 | undefined or common. */
|
---|
3255 | if (h == (struct bfd_link_hash_entry *) NULL
|
---|
3256 | || (h->type != bfd_link_hash_undefined
|
---|
3257 | && h->type != bfd_link_hash_common))
|
---|
3258 | {
|
---|
3259 | if (type == (N_INDR | N_EXT))
|
---|
3260 | ++p;
|
---|
3261 | continue;
|
---|
3262 | }
|
---|
3263 |
|
---|
3264 | if (type == (N_TEXT | N_EXT)
|
---|
3265 | || type == (N_DATA | N_EXT)
|
---|
3266 | || type == (N_BSS | N_EXT)
|
---|
3267 | || type == (N_ABS | N_EXT)
|
---|
3268 | || type == (N_INDR | N_EXT)
|
---|
3269 | #if defined (EMX)
|
---|
3270 | || type == (N_IMP1 | N_EXT)
|
---|
3271 | #endif
|
---|
3272 | )
|
---|
3273 | {
|
---|
3274 | /* This object file defines this symbol. We must link it
|
---|
3275 | in. This is true regardless of whether the current
|
---|
3276 | definition of the symbol is undefined or common.
|
---|
3277 |
|
---|
3278 | If the current definition is common, we have a case in
|
---|
3279 | which we have already seen an object file including:
|
---|
3280 | int a;
|
---|
3281 | and this object file from the archive includes:
|
---|
3282 | int a = 5;
|
---|
3283 | In such a case, whether to include this object is target
|
---|
3284 | dependant for backward compatability.
|
---|
3285 |
|
---|
3286 | FIXME: The SunOS 4.1.3 linker will pull in the archive
|
---|
3287 | element if the symbol is defined in the .data section,
|
---|
3288 | but not if it is defined in the .text section. That
|
---|
3289 | seems a bit crazy to me, and it has not been implemented
|
---|
3290 | yet. However, it might be correct. */
|
---|
3291 | if (h->type == bfd_link_hash_common)
|
---|
3292 | {
|
---|
3293 | int skip = 0;
|
---|
3294 |
|
---|
3295 | switch (info->common_skip_ar_aymbols)
|
---|
3296 | {
|
---|
3297 | case bfd_link_common_skip_text:
|
---|
3298 | skip = (type == (N_TEXT | N_EXT));
|
---|
3299 | break;
|
---|
3300 | case bfd_link_common_skip_data:
|
---|
3301 | skip = (type == (N_DATA | N_EXT));
|
---|
3302 | break;
|
---|
3303 | default:
|
---|
3304 | case bfd_link_common_skip_all:
|
---|
3305 | skip = 1;
|
---|
3306 | break;
|
---|
3307 | }
|
---|
3308 |
|
---|
3309 | if (skip)
|
---|
3310 | continue;
|
---|
3311 | }
|
---|
3312 |
|
---|
3313 | if (! (*info->callbacks->add_archive_element) (info, abfd, name))
|
---|
3314 | return FALSE;
|
---|
3315 | *pneeded = TRUE;
|
---|
3316 | return TRUE;
|
---|
3317 | }
|
---|
3318 |
|
---|
3319 | if (type == (N_UNDF | N_EXT))
|
---|
3320 | {
|
---|
3321 | bfd_vma value;
|
---|
3322 |
|
---|
3323 | value = GET_WORD (abfd, p->e_value);
|
---|
3324 | if (value != 0)
|
---|
3325 | {
|
---|
3326 | /* This symbol is common in the object from the archive
|
---|
3327 | file. */
|
---|
3328 | if (h->type == bfd_link_hash_undefined)
|
---|
3329 | {
|
---|
3330 | bfd *symbfd;
|
---|
3331 | unsigned int power;
|
---|
3332 |
|
---|
3333 | symbfd = h->u.undef.abfd;
|
---|
3334 | if (symbfd == (bfd *) NULL)
|
---|
3335 | {
|
---|
3336 | /* This symbol was created as undefined from
|
---|
3337 | outside BFD. We assume that we should link
|
---|
3338 | in the object file. This is done for the -u
|
---|
3339 | option in the linker. */
|
---|
3340 | if (! (*info->callbacks->add_archive_element) (info,
|
---|
3341 | abfd,
|
---|
3342 | name))
|
---|
3343 | return FALSE;
|
---|
3344 | *pneeded = TRUE;
|
---|
3345 | return TRUE;
|
---|
3346 | }
|
---|
3347 | /* Turn the current link symbol into a common
|
---|
3348 | symbol. It is already on the undefs list. */
|
---|
3349 | h->type = bfd_link_hash_common;
|
---|
3350 | h->u.c.p = ((struct bfd_link_hash_common_entry *)
|
---|
3351 | bfd_hash_allocate (&info->hash->table,
|
---|
3352 | sizeof (struct bfd_link_hash_common_entry)));
|
---|
3353 | if (h->u.c.p == NULL)
|
---|
3354 | return FALSE;
|
---|
3355 |
|
---|
3356 | h->u.c.size = value;
|
---|
3357 |
|
---|
3358 | /* FIXME: This isn't quite right. The maximum
|
---|
3359 | alignment of a common symbol should be set by the
|
---|
3360 | architecture of the output file, not of the input
|
---|
3361 | file. */
|
---|
3362 | power = bfd_log2 (value);
|
---|
3363 | if (power > bfd_get_arch_info (abfd)->section_align_power)
|
---|
3364 | power = bfd_get_arch_info (abfd)->section_align_power;
|
---|
3365 | h->u.c.p->alignment_power = power;
|
---|
3366 |
|
---|
3367 | h->u.c.p->section = bfd_make_section_old_way (symbfd,
|
---|
3368 | "COMMON");
|
---|
3369 | }
|
---|
3370 | else
|
---|
3371 | {
|
---|
3372 | /* Adjust the size of the common symbol if
|
---|
3373 | necessary. */
|
---|
3374 | if (value > h->u.c.size)
|
---|
3375 | h->u.c.size = value;
|
---|
3376 | }
|
---|
3377 | }
|
---|
3378 | }
|
---|
3379 |
|
---|
3380 | if (type == N_WEAKA
|
---|
3381 | || type == N_WEAKT
|
---|
3382 | || type == N_WEAKD
|
---|
3383 | || type == N_WEAKB)
|
---|
3384 | {
|
---|
3385 | /* This symbol is weak but defined. We must pull it in if
|
---|
3386 | the current link symbol is undefined, but we don't want
|
---|
3387 | it if the current link symbol is common. */
|
---|
3388 | if (h->type == bfd_link_hash_undefined)
|
---|
3389 | {
|
---|
3390 | if (! (*info->callbacks->add_archive_element) (info, abfd, name))
|
---|
3391 | return FALSE;
|
---|
3392 | *pneeded = TRUE;
|
---|
3393 | return TRUE;
|
---|
3394 | }
|
---|
3395 | }
|
---|
3396 | }
|
---|
3397 |
|
---|
3398 | /* We do not need this object file. */
|
---|
3399 | return TRUE;
|
---|
3400 | }
|
---|
3401 |
|
---|
3402 | /* Add all symbols from an object file to the hash table. */
|
---|
3403 |
|
---|
3404 | static bfd_boolean
|
---|
3405 | aout_link_add_symbols (abfd, info)
|
---|
3406 | bfd *abfd;
|
---|
3407 | struct bfd_link_info *info;
|
---|
3408 | {
|
---|
3409 | bfd_boolean (*add_one_symbol)
|
---|
3410 | PARAMS ((struct bfd_link_info *, bfd *, const char *, flagword, asection *,
|
---|
3411 | bfd_vma, const char *, bfd_boolean, bfd_boolean,
|
---|
3412 | struct bfd_link_hash_entry **));
|
---|
3413 | struct external_nlist *syms;
|
---|
3414 | bfd_size_type sym_count;
|
---|
3415 | char *strings;
|
---|
3416 | bfd_boolean copy;
|
---|
3417 | struct aout_link_hash_entry **sym_hash;
|
---|
3418 | register struct external_nlist *p;
|
---|
3419 | struct external_nlist *pend;
|
---|
3420 | bfd_size_type amt;
|
---|
3421 |
|
---|
3422 | syms = obj_aout_external_syms (abfd);
|
---|
3423 | sym_count = obj_aout_external_sym_count (abfd);
|
---|
3424 | strings = obj_aout_external_strings (abfd);
|
---|
3425 | if (info->keep_memory)
|
---|
3426 | copy = FALSE;
|
---|
3427 | else
|
---|
3428 | copy = TRUE;
|
---|
3429 |
|
---|
3430 | if (aout_backend_info (abfd)->add_dynamic_symbols != NULL)
|
---|
3431 | {
|
---|
3432 | if (! ((*aout_backend_info (abfd)->add_dynamic_symbols)
|
---|
3433 | (abfd, info, &syms, &sym_count, &strings)))
|
---|
3434 | return FALSE;
|
---|
3435 | }
|
---|
3436 |
|
---|
3437 | /* We keep a list of the linker hash table entries that correspond
|
---|
3438 | to particular symbols. We could just look them up in the hash
|
---|
3439 | table, but keeping the list is more efficient. Perhaps this
|
---|
3440 | should be conditional on info->keep_memory. */
|
---|
3441 | amt = sym_count * sizeof (struct aout_link_hash_entry *);
|
---|
3442 | sym_hash = (struct aout_link_hash_entry **) bfd_alloc (abfd, amt);
|
---|
3443 | if (sym_hash == NULL && sym_count != 0)
|
---|
3444 | return FALSE;
|
---|
3445 | obj_aout_sym_hashes (abfd) = sym_hash;
|
---|
3446 |
|
---|
3447 | add_one_symbol = aout_backend_info (abfd)->add_one_symbol;
|
---|
3448 | if (add_one_symbol == NULL)
|
---|
3449 | add_one_symbol = _bfd_generic_link_add_one_symbol;
|
---|
3450 |
|
---|
3451 | p = syms;
|
---|
3452 | pend = p + sym_count;
|
---|
3453 | for (; p < pend; p++, sym_hash++)
|
---|
3454 | {
|
---|
3455 | int type;
|
---|
3456 | const char *name;
|
---|
3457 | bfd_vma value;
|
---|
3458 | asection *section;
|
---|
3459 | flagword flags;
|
---|
3460 | const char *string;
|
---|
3461 |
|
---|
3462 | *sym_hash = NULL;
|
---|
3463 |
|
---|
3464 | type = H_GET_8 (abfd, p->e_type);
|
---|
3465 |
|
---|
3466 | /* Ignore debugging symbols. */
|
---|
3467 | if (IS_STAB(type))
|
---|
3468 | continue;
|
---|
3469 |
|
---|
3470 | name = strings + GET_WORD (abfd, p->e_strx);
|
---|
3471 | value = GET_WORD (abfd, p->e_value);
|
---|
3472 | flags = BSF_GLOBAL;
|
---|
3473 | string = NULL;
|
---|
3474 | switch (type)
|
---|
3475 | {
|
---|
3476 | default:
|
---|
3477 | abort ();
|
---|
3478 |
|
---|
3479 | case N_UNDF:
|
---|
3480 | case N_ABS:
|
---|
3481 | case N_TEXT:
|
---|
3482 | case N_DATA:
|
---|
3483 | case N_BSS:
|
---|
3484 | case N_FN_SEQ:
|
---|
3485 | case N_COMM:
|
---|
3486 | case N_SETV:
|
---|
3487 | case N_FN:
|
---|
3488 | /* Ignore symbols that are not externally visible. */
|
---|
3489 | continue;
|
---|
3490 | case N_INDR:
|
---|
3491 | /* Ignore local indirect symbol. */
|
---|
3492 | ++p;
|
---|
3493 | ++sym_hash;
|
---|
3494 | continue;
|
---|
3495 |
|
---|
3496 | case N_UNDF | N_EXT:
|
---|
3497 | if (value == 0)
|
---|
3498 | {
|
---|
3499 | section = bfd_und_section_ptr;
|
---|
3500 | flags = 0;
|
---|
3501 | }
|
---|
3502 | else
|
---|
3503 | section = bfd_com_section_ptr;
|
---|
3504 | break;
|
---|
3505 | case N_ABS | N_EXT:
|
---|
3506 | section = bfd_abs_section_ptr;
|
---|
3507 | break;
|
---|
3508 | case N_TEXT | N_EXT:
|
---|
3509 | section = obj_textsec (abfd);
|
---|
3510 | value -= bfd_get_section_vma (abfd, section);
|
---|
3511 | break;
|
---|
3512 | case N_DATA | N_EXT:
|
---|
3513 | case N_SETV | N_EXT:
|
---|
3514 | /* Treat N_SETV symbols as N_DATA symbol; see comment in
|
---|
3515 | translate_from_native_sym_flags. */
|
---|
3516 | section = obj_datasec (abfd);
|
---|
3517 | value -= bfd_get_section_vma (abfd, section);
|
---|
3518 | break;
|
---|
3519 | case N_BSS | N_EXT:
|
---|
3520 | section = obj_bsssec (abfd);
|
---|
3521 | value -= bfd_get_section_vma (abfd, section);
|
---|
3522 | break;
|
---|
3523 | case N_INDR | N_EXT:
|
---|
3524 | /* An indirect symbol. The next symbol is the symbol
|
---|
3525 | which this one really is. */
|
---|
3526 | BFD_ASSERT (p + 1 < pend);
|
---|
3527 | ++p;
|
---|
3528 | string = strings + GET_WORD (abfd, p->e_strx);
|
---|
3529 | section = bfd_ind_section_ptr;
|
---|
3530 | flags |= BSF_INDIRECT;
|
---|
3531 | break;
|
---|
3532 | case N_COMM | N_EXT:
|
---|
3533 | section = bfd_com_section_ptr;
|
---|
3534 | break;
|
---|
3535 | case N_SETA: case N_SETA | N_EXT:
|
---|
3536 | section = bfd_abs_section_ptr;
|
---|
3537 | flags |= BSF_CONSTRUCTOR;
|
---|
3538 | break;
|
---|
3539 | case N_SETT: case N_SETT | N_EXT:
|
---|
3540 | section = obj_textsec (abfd);
|
---|
3541 | flags |= BSF_CONSTRUCTOR;
|
---|
3542 | value -= bfd_get_section_vma (abfd, section);
|
---|
3543 | break;
|
---|
3544 | case N_SETD: case N_SETD | N_EXT:
|
---|
3545 | section = obj_datasec (abfd);
|
---|
3546 | flags |= BSF_CONSTRUCTOR;
|
---|
3547 | value -= bfd_get_section_vma (abfd, section);
|
---|
3548 | break;
|
---|
3549 | case N_SETB: case N_SETB | N_EXT:
|
---|
3550 | section = obj_bsssec (abfd);
|
---|
3551 | flags |= BSF_CONSTRUCTOR;
|
---|
3552 | value -= bfd_get_section_vma (abfd, section);
|
---|
3553 | break;
|
---|
3554 | case N_WARNING:
|
---|
3555 | /* A warning symbol. The next symbol is the one to warn
|
---|
3556 | about. */
|
---|
3557 | BFD_ASSERT (p + 1 < pend);
|
---|
3558 | ++p;
|
---|
3559 | string = name;
|
---|
3560 | name = strings + GET_WORD (abfd, p->e_strx);
|
---|
3561 | section = bfd_und_section_ptr;
|
---|
3562 | flags |= BSF_WARNING;
|
---|
3563 | break;
|
---|
3564 | case N_WEAKU:
|
---|
3565 | section = bfd_und_section_ptr;
|
---|
3566 | flags = BSF_WEAK;
|
---|
3567 | break;
|
---|
3568 | case N_WEAKA:
|
---|
3569 | section = bfd_abs_section_ptr;
|
---|
3570 | flags = BSF_WEAK;
|
---|
3571 | break;
|
---|
3572 | case N_WEAKT:
|
---|
3573 | section = obj_textsec (abfd);
|
---|
3574 | value -= bfd_get_section_vma (abfd, section);
|
---|
3575 | flags = BSF_WEAK;
|
---|
3576 | break;
|
---|
3577 | case N_WEAKD:
|
---|
3578 | section = obj_datasec (abfd);
|
---|
3579 | value -= bfd_get_section_vma (abfd, section);
|
---|
3580 | flags = BSF_WEAK;
|
---|
3581 | break;
|
---|
3582 | case N_WEAKB:
|
---|
3583 | section = obj_bsssec (abfd);
|
---|
3584 | value -= bfd_get_section_vma (abfd, section);
|
---|
3585 | flags = BSF_WEAK;
|
---|
3586 | break;
|
---|
3587 | #ifdef EMX
|
---|
3588 | case N_IMP1 | N_EXT:
|
---|
3589 | section = bfd_abs_section_ptr;
|
---|
3590 | flags = BSF_EMX_IMPORT1;
|
---|
3591 | value = -1; /* -1 in *ABS* means external imported symbol */
|
---|
3592 | break;
|
---|
3593 | case N_IMP2 | N_EXT:
|
---|
3594 | section = bfd_abs_section_ptr;
|
---|
3595 | flags = BSF_EMX_IMPORT2;
|
---|
3596 | break;
|
---|
3597 | #endif /* EMX */
|
---|
3598 | }
|
---|
3599 |
|
---|
3600 | if (! ((*add_one_symbol)
|
---|
3601 | (info, abfd, name, flags, section, value, string, copy, FALSE,
|
---|
3602 | (struct bfd_link_hash_entry **) sym_hash)))
|
---|
3603 | return FALSE;
|
---|
3604 |
|
---|
3605 | /* Restrict the maximum alignment of a common symbol based on
|
---|
3606 | the architecture, since a.out has no way to represent
|
---|
3607 | alignment requirements of a section in a .o file. FIXME:
|
---|
3608 | This isn't quite right: it should use the architecture of the
|
---|
3609 | output file, not the input files. */
|
---|
3610 | if ((*sym_hash)->root.type == bfd_link_hash_common
|
---|
3611 | && ((*sym_hash)->root.u.c.p->alignment_power >
|
---|
3612 | bfd_get_arch_info (abfd)->section_align_power))
|
---|
3613 | (*sym_hash)->root.u.c.p->alignment_power =
|
---|
3614 | bfd_get_arch_info (abfd)->section_align_power;
|
---|
3615 |
|
---|
3616 | /* If this is a set symbol, and we are not building sets, then
|
---|
3617 | it is possible for the hash entry to not have been set. In
|
---|
3618 | such a case, treat the symbol as not globally defined. */
|
---|
3619 | if ((*sym_hash)->root.type == bfd_link_hash_new)
|
---|
3620 | {
|
---|
3621 | BFD_ASSERT ((flags & BSF_CONSTRUCTOR) != 0);
|
---|
3622 | *sym_hash = NULL;
|
---|
3623 | }
|
---|
3624 |
|
---|
3625 | if (type == (N_INDR | N_EXT) || type == N_WARNING)
|
---|
3626 | ++sym_hash;
|
---|
3627 | }
|
---|
3628 |
|
---|
3629 | return TRUE;
|
---|
3630 | }
|
---|
3631 | |
---|
3632 |
|
---|
3633 | /* A hash table used for header files with N_BINCL entries. */
|
---|
3634 |
|
---|
3635 | struct aout_link_includes_table
|
---|
3636 | {
|
---|
3637 | struct bfd_hash_table root;
|
---|
3638 | };
|
---|
3639 |
|
---|
3640 | /* A linked list of totals that we have found for a particular header
|
---|
3641 | file. */
|
---|
3642 |
|
---|
3643 | struct aout_link_includes_totals
|
---|
3644 | {
|
---|
3645 | struct aout_link_includes_totals *next;
|
---|
3646 | bfd_vma total;
|
---|
3647 | };
|
---|
3648 |
|
---|
3649 | /* An entry in the header file hash table. */
|
---|
3650 |
|
---|
3651 | struct aout_link_includes_entry
|
---|
3652 | {
|
---|
3653 | struct bfd_hash_entry root;
|
---|
3654 | /* List of totals we have found for this file. */
|
---|
3655 | struct aout_link_includes_totals *totals;
|
---|
3656 | };
|
---|
3657 |
|
---|
3658 | /* Look up an entry in an the header file hash table. */
|
---|
3659 |
|
---|
3660 | #define aout_link_includes_lookup(table, string, create, copy) \
|
---|
3661 | ((struct aout_link_includes_entry *) \
|
---|
3662 | bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
|
---|
3663 |
|
---|
3664 | /* During the final link step we need to pass around a bunch of
|
---|
3665 | information, so we do it in an instance of this structure. */
|
---|
3666 |
|
---|
3667 | struct aout_final_link_info
|
---|
3668 | {
|
---|
3669 | /* General link information. */
|
---|
3670 | struct bfd_link_info *info;
|
---|
3671 | /* Output bfd. */
|
---|
3672 | bfd *output_bfd;
|
---|
3673 | /* Reloc file positions. */
|
---|
3674 | file_ptr treloff, dreloff;
|
---|
3675 | /* File position of symbols. */
|
---|
3676 | file_ptr symoff;
|
---|
3677 | /* String table. */
|
---|
3678 | struct bfd_strtab_hash *strtab;
|
---|
3679 | /* Header file hash table. */
|
---|
3680 | struct aout_link_includes_table includes;
|
---|
3681 | /* A buffer large enough to hold the contents of any section. */
|
---|
3682 | bfd_byte *contents;
|
---|
3683 | /* A buffer large enough to hold the relocs of any section. */
|
---|
3684 | PTR relocs;
|
---|
3685 | /* A buffer large enough to hold the symbol map of any input BFD. */
|
---|
3686 | int *symbol_map;
|
---|
3687 | /* A buffer large enough to hold output symbols of any input BFD. */
|
---|
3688 | struct external_nlist *output_syms;
|
---|
3689 | };
|
---|
3690 |
|
---|
3691 | static struct bfd_hash_entry *aout_link_includes_newfunc
|
---|
3692 | PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
|
---|
3693 | static bfd_boolean aout_link_input_bfd
|
---|
3694 | PARAMS ((struct aout_final_link_info *, bfd *input_bfd));
|
---|
3695 | static bfd_boolean aout_link_write_symbols
|
---|
3696 | PARAMS ((struct aout_final_link_info *, bfd *input_bfd));
|
---|
3697 | static bfd_boolean aout_link_write_other_symbol
|
---|
3698 | PARAMS ((struct aout_link_hash_entry *, PTR));
|
---|
3699 | static bfd_boolean aout_link_input_section
|
---|
3700 | PARAMS ((struct aout_final_link_info *, bfd *input_bfd,
|
---|
3701 | asection *input_section, file_ptr *reloff_ptr,
|
---|
3702 | bfd_size_type rel_size));
|
---|
3703 | static bfd_boolean aout_link_input_section_std
|
---|
3704 | PARAMS ((struct aout_final_link_info *, bfd *input_bfd,
|
---|
3705 | asection *input_section, struct reloc_std_external *,
|
---|
3706 | bfd_size_type rel_size, bfd_byte *contents));
|
---|
3707 | static bfd_boolean aout_link_input_section_ext
|
---|
3708 | PARAMS ((struct aout_final_link_info *, bfd *input_bfd,
|
---|
3709 | asection *input_section, struct reloc_ext_external *,
|
---|
3710 | bfd_size_type rel_size, bfd_byte *contents));
|
---|
3711 | static INLINE asection *aout_reloc_index_to_section
|
---|
3712 | PARAMS ((bfd *, int));
|
---|
3713 | static bfd_boolean aout_link_reloc_link_order
|
---|
3714 | PARAMS ((struct aout_final_link_info *, asection *,
|
---|
3715 | struct bfd_link_order *));
|
---|
3716 |
|
---|
3717 | /* The function to create a new entry in the header file hash table. */
|
---|
3718 |
|
---|
3719 | static struct bfd_hash_entry *
|
---|
3720 | aout_link_includes_newfunc (entry, table, string)
|
---|
3721 | struct bfd_hash_entry *entry;
|
---|
3722 | struct bfd_hash_table *table;
|
---|
3723 | const char *string;
|
---|
3724 | {
|
---|
3725 | struct aout_link_includes_entry *ret =
|
---|
3726 | (struct aout_link_includes_entry *) entry;
|
---|
3727 |
|
---|
3728 | /* Allocate the structure if it has not already been allocated by a
|
---|
3729 | subclass. */
|
---|
3730 | if (ret == (struct aout_link_includes_entry *) NULL)
|
---|
3731 | ret = ((struct aout_link_includes_entry *)
|
---|
3732 | bfd_hash_allocate (table,
|
---|
3733 | sizeof (struct aout_link_includes_entry)));
|
---|
3734 | if (ret == (struct aout_link_includes_entry *) NULL)
|
---|
3735 | return (struct bfd_hash_entry *) ret;
|
---|
3736 |
|
---|
3737 | /* Call the allocation method of the superclass. */
|
---|
3738 | ret = ((struct aout_link_includes_entry *)
|
---|
3739 | bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
|
---|
3740 | if (ret)
|
---|
3741 | {
|
---|
3742 | /* Set local fields. */
|
---|
3743 | ret->totals = NULL;
|
---|
3744 | }
|
---|
3745 |
|
---|
3746 | return (struct bfd_hash_entry *) ret;
|
---|
3747 | }
|
---|
3748 |
|
---|
3749 | /* Do the final link step. This is called on the output BFD. The
|
---|
3750 | INFO structure should point to a list of BFDs linked through the
|
---|
3751 | link_next field which can be used to find each BFD which takes part
|
---|
3752 | in the output. Also, each section in ABFD should point to a list
|
---|
3753 | of bfd_link_order structures which list all the input sections for
|
---|
3754 | the output section. */
|
---|
3755 |
|
---|
3756 | bfd_boolean
|
---|
3757 | NAME(aout,final_link) (abfd, info, callback)
|
---|
3758 | bfd *abfd;
|
---|
3759 | struct bfd_link_info *info;
|
---|
3760 | void (*callback) PARAMS ((bfd *, file_ptr *, file_ptr *, file_ptr *));
|
---|
3761 | {
|
---|
3762 | struct aout_final_link_info aout_info;
|
---|
3763 | bfd_boolean includes_hash_initialized = FALSE;
|
---|
3764 | register bfd *sub;
|
---|
3765 | bfd_size_type trsize, drsize;
|
---|
3766 | bfd_size_type max_contents_size;
|
---|
3767 | bfd_size_type max_relocs_size;
|
---|
3768 | bfd_size_type max_sym_count;
|
---|
3769 | bfd_size_type text_size;
|
---|
3770 | file_ptr text_end;
|
---|
3771 | register struct bfd_link_order *p;
|
---|
3772 | asection *o;
|
---|
3773 | bfd_boolean have_link_order_relocs;
|
---|
3774 |
|
---|
3775 | if (info->shared)
|
---|
3776 | abfd->flags |= DYNAMIC;
|
---|
3777 |
|
---|
3778 | aout_info.info = info;
|
---|
3779 | aout_info.output_bfd = abfd;
|
---|
3780 | aout_info.contents = NULL;
|
---|
3781 | aout_info.relocs = NULL;
|
---|
3782 | aout_info.symbol_map = NULL;
|
---|
3783 | aout_info.output_syms = NULL;
|
---|
3784 |
|
---|
3785 | if (! bfd_hash_table_init_n (&aout_info.includes.root,
|
---|
3786 | aout_link_includes_newfunc,
|
---|
3787 | 251))
|
---|
3788 | goto error_return;
|
---|
3789 | includes_hash_initialized = TRUE;
|
---|
3790 |
|
---|
3791 | /* Figure out the largest section size. Also, if generating
|
---|
3792 | relocateable output, count the relocs. */
|
---|
3793 | trsize = 0;
|
---|
3794 | drsize = 0;
|
---|
3795 | max_contents_size = 0;
|
---|
3796 | max_relocs_size = 0;
|
---|
3797 | max_sym_count = 0;
|
---|
3798 | for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
|
---|
3799 | {
|
---|
3800 | bfd_size_type sz;
|
---|
3801 |
|
---|
3802 | if (info->relocateable)
|
---|
3803 | {
|
---|
3804 | if (bfd_get_flavour (sub) == bfd_target_aout_flavour)
|
---|
3805 | {
|
---|
3806 | trsize += exec_hdr (sub)->a_trsize;
|
---|
3807 | drsize += exec_hdr (sub)->a_drsize;
|
---|
3808 | }
|
---|
3809 | else
|
---|
3810 | {
|
---|
3811 | /* FIXME: We need to identify the .text and .data sections
|
---|
3812 | and call get_reloc_upper_bound and canonicalize_reloc to
|
---|
3813 | work out the number of relocs needed, and then multiply
|
---|
3814 | by the reloc size. */
|
---|
3815 | (*_bfd_error_handler)
|
---|
3816 | (_("%s: relocateable link from %s to %s not supported"),
|
---|
3817 | bfd_get_filename (abfd),
|
---|
3818 | sub->xvec->name, abfd->xvec->name);
|
---|
3819 | bfd_set_error (bfd_error_invalid_operation);
|
---|
3820 | goto error_return;
|
---|
3821 | }
|
---|
3822 | }
|
---|
3823 |
|
---|
3824 | if (bfd_get_flavour (sub) == bfd_target_aout_flavour)
|
---|
3825 | {
|
---|
3826 | sz = bfd_section_size (sub, obj_textsec (sub));
|
---|
3827 | if (sz > max_contents_size)
|
---|
3828 | max_contents_size = sz;
|
---|
3829 | sz = bfd_section_size (sub, obj_datasec (sub));
|
---|
3830 | if (sz > max_contents_size)
|
---|
3831 | max_contents_size = sz;
|
---|
3832 |
|
---|
3833 | sz = exec_hdr (sub)->a_trsize;
|
---|
3834 | if (sz > max_relocs_size)
|
---|
3835 | max_relocs_size = sz;
|
---|
3836 | sz = exec_hdr (sub)->a_drsize;
|
---|
3837 | if (sz > max_relocs_size)
|
---|
3838 | max_relocs_size = sz;
|
---|
3839 |
|
---|
3840 | sz = obj_aout_external_sym_count (sub);
|
---|
3841 | if (sz > max_sym_count)
|
---|
3842 | max_sym_count = sz;
|
---|
3843 | }
|
---|
3844 | }
|
---|
3845 |
|
---|
3846 | if (info->relocateable)
|
---|
3847 | {
|
---|
3848 | if (obj_textsec (abfd) != (asection *) NULL)
|
---|
3849 | trsize += (_bfd_count_link_order_relocs (obj_textsec (abfd)
|
---|
3850 | ->link_order_head)
|
---|
3851 | * obj_reloc_entry_size (abfd));
|
---|
3852 | if (obj_datasec (abfd) != (asection *) NULL)
|
---|
3853 | drsize += (_bfd_count_link_order_relocs (obj_datasec (abfd)
|
---|
3854 | ->link_order_head)
|
---|
3855 | * obj_reloc_entry_size (abfd));
|
---|
3856 | }
|
---|
3857 |
|
---|
3858 | exec_hdr (abfd)->a_trsize = trsize;
|
---|
3859 | exec_hdr (abfd)->a_drsize = drsize;
|
---|
3860 |
|
---|
3861 | exec_hdr (abfd)->a_entry = bfd_get_start_address (abfd);
|
---|
3862 |
|
---|
3863 | /* Adjust the section sizes and vmas according to the magic number.
|
---|
3864 | This sets a_text, a_data and a_bss in the exec_hdr and sets the
|
---|
3865 | filepos for each section. */
|
---|
3866 | if (! NAME(aout,adjust_sizes_and_vmas) (abfd, &text_size, &text_end))
|
---|
3867 | goto error_return;
|
---|
3868 |
|
---|
3869 | /* The relocation and symbol file positions differ among a.out
|
---|
3870 | targets. We are passed a callback routine from the backend
|
---|
3871 | specific code to handle this.
|
---|
3872 | FIXME: At this point we do not know how much space the symbol
|
---|
3873 | table will require. This will not work for any (nonstandard)
|
---|
3874 | a.out target that needs to know the symbol table size before it
|
---|
3875 | can compute the relocation file positions. This may or may not
|
---|
3876 | be the case for the hp300hpux target, for example. */
|
---|
3877 | (*callback) (abfd, &aout_info.treloff, &aout_info.dreloff,
|
---|
3878 | &aout_info.symoff);
|
---|
3879 | obj_textsec (abfd)->rel_filepos = aout_info.treloff;
|
---|
3880 | obj_datasec (abfd)->rel_filepos = aout_info.dreloff;
|
---|
3881 | obj_sym_filepos (abfd) = aout_info.symoff;
|
---|
3882 |
|
---|
3883 | /* We keep a count of the symbols as we output them. */
|
---|
3884 | obj_aout_external_sym_count (abfd) = 0;
|
---|
3885 |
|
---|
3886 | /* We accumulate the string table as we write out the symbols. */
|
---|
3887 | aout_info.strtab = _bfd_stringtab_init ();
|
---|
3888 | if (aout_info.strtab == NULL)
|
---|
3889 | goto error_return;
|
---|
3890 |
|
---|
3891 | /* Allocate buffers to hold section contents and relocs. */
|
---|
3892 | aout_info.contents = (bfd_byte *) bfd_malloc (max_contents_size);
|
---|
3893 | aout_info.relocs = (PTR) bfd_malloc (max_relocs_size);
|
---|
3894 | aout_info.symbol_map = (int *) bfd_malloc (max_sym_count * sizeof (int *));
|
---|
3895 | aout_info.output_syms = ((struct external_nlist *)
|
---|
3896 | bfd_malloc ((max_sym_count + 1)
|
---|
3897 | * sizeof (struct external_nlist)));
|
---|
3898 | if ((aout_info.contents == NULL && max_contents_size != 0)
|
---|
3899 | || (aout_info.relocs == NULL && max_relocs_size != 0)
|
---|
3900 | || (aout_info.symbol_map == NULL && max_sym_count != 0)
|
---|
3901 | || aout_info.output_syms == NULL)
|
---|
3902 | goto error_return;
|
---|
3903 |
|
---|
3904 | /* If we have a symbol named __DYNAMIC, force it out now. This is
|
---|
3905 | required by SunOS. Doing this here rather than in sunos.c is a
|
---|
3906 | hack, but it's easier than exporting everything which would be
|
---|
3907 | needed. */
|
---|
3908 | {
|
---|
3909 | struct aout_link_hash_entry *h;
|
---|
3910 |
|
---|
3911 | h = aout_link_hash_lookup (aout_hash_table (info), "__DYNAMIC",
|
---|
3912 | FALSE, FALSE, FALSE);
|
---|
3913 | if (h != NULL)
|
---|
3914 | aout_link_write_other_symbol (h, &aout_info);
|
---|
3915 | }
|
---|
3916 |
|
---|
3917 | /* The most time efficient way to do the link would be to read all
|
---|
3918 | the input object files into memory and then sort out the
|
---|
3919 | information into the output file. Unfortunately, that will
|
---|
3920 | probably use too much memory. Another method would be to step
|
---|
3921 | through everything that composes the text section and write it
|
---|
3922 | out, and then everything that composes the data section and write
|
---|
3923 | it out, and then write out the relocs, and then write out the
|
---|
3924 | symbols. Unfortunately, that requires reading stuff from each
|
---|
3925 | input file several times, and we will not be able to keep all the
|
---|
3926 | input files open simultaneously, and reopening them will be slow.
|
---|
3927 |
|
---|
3928 | What we do is basically process one input file at a time. We do
|
---|
3929 | everything we need to do with an input file once--copy over the
|
---|
3930 | section contents, handle the relocation information, and write
|
---|
3931 | out the symbols--and then we throw away the information we read
|
---|
3932 | from it. This approach requires a lot of lseeks of the output
|
---|
3933 | file, which is unfortunate but still faster than reopening a lot
|
---|
3934 | of files.
|
---|
3935 |
|
---|
3936 | We use the output_has_begun field of the input BFDs to see
|
---|
3937 | whether we have already handled it. */
|
---|
3938 | for (sub = info->input_bfds; sub != (bfd *) NULL; sub = sub->link_next)
|
---|
3939 | sub->output_has_begun = FALSE;
|
---|
3940 |
|
---|
3941 | /* Mark all sections which are to be included in the link. This
|
---|
3942 | will normally be every section. We need to do this so that we
|
---|
3943 | can identify any sections which the linker has decided to not
|
---|
3944 | include. */
|
---|
3945 | for (o = abfd->sections; o != NULL; o = o->next)
|
---|
3946 | {
|
---|
3947 | for (p = o->link_order_head; p != NULL; p = p->next)
|
---|
3948 | if (p->type == bfd_indirect_link_order)
|
---|
3949 | p->u.indirect.section->linker_mark = TRUE;
|
---|
3950 | }
|
---|
3951 |
|
---|
3952 | have_link_order_relocs = FALSE;
|
---|
3953 | for (o = abfd->sections; o != (asection *) NULL; o = o->next)
|
---|
3954 | {
|
---|
3955 | for (p = o->link_order_head;
|
---|
3956 | p != (struct bfd_link_order *) NULL;
|
---|
3957 | p = p->next)
|
---|
3958 | {
|
---|
3959 | if (p->type == bfd_indirect_link_order
|
---|
3960 | && (bfd_get_flavour (p->u.indirect.section->owner)
|
---|
3961 | == bfd_target_aout_flavour))
|
---|
3962 | {
|
---|
3963 | bfd *input_bfd;
|
---|
3964 |
|
---|
3965 | input_bfd = p->u.indirect.section->owner;
|
---|
3966 | if (! input_bfd->output_has_begun)
|
---|
3967 | {
|
---|
3968 | if (! aout_link_input_bfd (&aout_info, input_bfd))
|
---|
3969 | goto error_return;
|
---|
3970 | input_bfd->output_has_begun = TRUE;
|
---|
3971 | }
|
---|
3972 | }
|
---|
3973 | else if (p->type == bfd_section_reloc_link_order
|
---|
3974 | || p->type == bfd_symbol_reloc_link_order)
|
---|
3975 | {
|
---|
3976 | /* These are handled below. */
|
---|
3977 | have_link_order_relocs = TRUE;
|
---|
3978 | }
|
---|
3979 | else
|
---|
3980 | {
|
---|
3981 | if (! _bfd_default_link_order (abfd, info, o, p))
|
---|
3982 | goto error_return;
|
---|
3983 | }
|
---|
3984 | }
|
---|
3985 | }
|
---|
3986 |
|
---|
3987 | /* Write out any symbols that we have not already written out. */
|
---|
3988 | aout_link_hash_traverse (aout_hash_table (info),
|
---|
3989 | aout_link_write_other_symbol,
|
---|
3990 | (PTR) &aout_info);
|
---|
3991 |
|
---|
3992 | /* Now handle any relocs we were asked to create by the linker.
|
---|
3993 | These did not come from any input file. We must do these after
|
---|
3994 | we have written out all the symbols, so that we know the symbol
|
---|
3995 | indices to use. */
|
---|
3996 | if (have_link_order_relocs)
|
---|
3997 | {
|
---|
3998 | for (o = abfd->sections; o != (asection *) NULL; o = o->next)
|
---|
3999 | {
|
---|
4000 | for (p = o->link_order_head;
|
---|
4001 | p != (struct bfd_link_order *) NULL;
|
---|
4002 | p = p->next)
|
---|
4003 | {
|
---|
4004 | if (p->type == bfd_section_reloc_link_order
|
---|
4005 | || p->type == bfd_symbol_reloc_link_order)
|
---|
4006 | {
|
---|
4007 | if (! aout_link_reloc_link_order (&aout_info, o, p))
|
---|
4008 | goto error_return;
|
---|
4009 | }
|
---|
4010 | }
|
---|
4011 | }
|
---|
4012 | }
|
---|
4013 |
|
---|
4014 | if (aout_info.contents != NULL)
|
---|
4015 | {
|
---|
4016 | free (aout_info.contents);
|
---|
4017 | aout_info.contents = NULL;
|
---|
4018 | }
|
---|
4019 | if (aout_info.relocs != NULL)
|
---|
4020 | {
|
---|
4021 | free (aout_info.relocs);
|
---|
4022 | aout_info.relocs = NULL;
|
---|
4023 | }
|
---|
4024 | if (aout_info.symbol_map != NULL)
|
---|
4025 | {
|
---|
4026 | free (aout_info.symbol_map);
|
---|
4027 | aout_info.symbol_map = NULL;
|
---|
4028 | }
|
---|
4029 | if (aout_info.output_syms != NULL)
|
---|
4030 | {
|
---|
4031 | free (aout_info.output_syms);
|
---|
4032 | aout_info.output_syms = NULL;
|
---|
4033 | }
|
---|
4034 | if (includes_hash_initialized)
|
---|
4035 | {
|
---|
4036 | bfd_hash_table_free (&aout_info.includes.root);
|
---|
4037 | includes_hash_initialized = FALSE;
|
---|
4038 | }
|
---|
4039 |
|
---|
4040 | /* Finish up any dynamic linking we may be doing. */
|
---|
4041 | if (aout_backend_info (abfd)->finish_dynamic_link != NULL)
|
---|
4042 | {
|
---|
4043 | if (! (*aout_backend_info (abfd)->finish_dynamic_link) (abfd, info))
|
---|
4044 | goto error_return;
|
---|
4045 | }
|
---|
4046 |
|
---|
4047 | /* Update the header information. */
|
---|
4048 | abfd->symcount = obj_aout_external_sym_count (abfd);
|
---|
4049 | exec_hdr (abfd)->a_syms = abfd->symcount * EXTERNAL_NLIST_SIZE;
|
---|
4050 | obj_str_filepos (abfd) = obj_sym_filepos (abfd) + exec_hdr (abfd)->a_syms;
|
---|
4051 | obj_textsec (abfd)->reloc_count =
|
---|
4052 | exec_hdr (abfd)->a_trsize / obj_reloc_entry_size (abfd);
|
---|
4053 | obj_datasec (abfd)->reloc_count =
|
---|
4054 | exec_hdr (abfd)->a_drsize / obj_reloc_entry_size (abfd);
|
---|
4055 |
|
---|
4056 | /* Write out the string table, unless there are no symbols. */
|
---|
4057 | if (abfd->symcount > 0)
|
---|
4058 | {
|
---|
4059 | if (bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET) != 0
|
---|
4060 | || ! emit_stringtab (abfd, aout_info.strtab))
|
---|
4061 | goto error_return;
|
---|
4062 | }
|
---|
4063 | else if (obj_textsec (abfd)->reloc_count == 0
|
---|
4064 | && obj_datasec (abfd)->reloc_count == 0)
|
---|
4065 | {
|
---|
4066 | bfd_byte b;
|
---|
4067 | file_ptr pos;
|
---|
4068 |
|
---|
4069 | b = 0;
|
---|
4070 | pos = obj_datasec (abfd)->filepos + exec_hdr (abfd)->a_data - 1;
|
---|
4071 | if (bfd_seek (abfd, pos, SEEK_SET) != 0
|
---|
4072 | || bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
|
---|
4073 | goto error_return;
|
---|
4074 | }
|
---|
4075 |
|
---|
4076 | return TRUE;
|
---|
4077 |
|
---|
4078 | error_return:
|
---|
4079 | if (aout_info.contents != NULL)
|
---|
4080 | free (aout_info.contents);
|
---|
4081 | if (aout_info.relocs != NULL)
|
---|
4082 | free (aout_info.relocs);
|
---|
4083 | if (aout_info.symbol_map != NULL)
|
---|
4084 | free (aout_info.symbol_map);
|
---|
4085 | if (aout_info.output_syms != NULL)
|
---|
4086 | free (aout_info.output_syms);
|
---|
4087 | if (includes_hash_initialized)
|
---|
4088 | bfd_hash_table_free (&aout_info.includes.root);
|
---|
4089 | return FALSE;
|
---|
4090 | }
|
---|
4091 |
|
---|
4092 | /* Link an a.out input BFD into the output file. */
|
---|
4093 |
|
---|
4094 | static bfd_boolean
|
---|
4095 | aout_link_input_bfd (finfo, input_bfd)
|
---|
4096 | struct aout_final_link_info *finfo;
|
---|
4097 | bfd *input_bfd;
|
---|
4098 | {
|
---|
4099 | bfd_size_type sym_count;
|
---|
4100 |
|
---|
4101 | BFD_ASSERT (bfd_get_format (input_bfd) == bfd_object);
|
---|
4102 |
|
---|
4103 | /* If this is a dynamic object, it may need special handling. */
|
---|
4104 | if ((input_bfd->flags & DYNAMIC) != 0
|
---|
4105 | && aout_backend_info (input_bfd)->link_dynamic_object != NULL)
|
---|
4106 | {
|
---|
4107 | return ((*aout_backend_info (input_bfd)->link_dynamic_object)
|
---|
4108 | (finfo->info, input_bfd));
|
---|
4109 | }
|
---|
4110 |
|
---|
4111 | /* Get the symbols. We probably have them already, unless
|
---|
4112 | finfo->info->keep_memory is FALSE. */
|
---|
4113 | if (! aout_get_external_symbols (input_bfd))
|
---|
4114 | return FALSE;
|
---|
4115 |
|
---|
4116 | sym_count = obj_aout_external_sym_count (input_bfd);
|
---|
4117 |
|
---|
4118 | /* Write out the symbols and get a map of the new indices. The map
|
---|
4119 | is placed into finfo->symbol_map. */
|
---|
4120 | if (! aout_link_write_symbols (finfo, input_bfd))
|
---|
4121 | return FALSE;
|
---|
4122 |
|
---|
4123 | /* Relocate and write out the sections. These functions use the
|
---|
4124 | symbol map created by aout_link_write_symbols. The linker_mark
|
---|
4125 | field will be set if these sections are to be included in the
|
---|
4126 | link, which will normally be the case. */
|
---|
4127 | if (obj_textsec (input_bfd)->linker_mark)
|
---|
4128 | {
|
---|
4129 | if (! aout_link_input_section (finfo, input_bfd,
|
---|
4130 | obj_textsec (input_bfd),
|
---|
4131 | &finfo->treloff,
|
---|
4132 | exec_hdr (input_bfd)->a_trsize))
|
---|
4133 | return FALSE;
|
---|
4134 | }
|
---|
4135 | if (obj_datasec (input_bfd)->linker_mark)
|
---|
4136 | {
|
---|
4137 | if (! aout_link_input_section (finfo, input_bfd,
|
---|
4138 | obj_datasec (input_bfd),
|
---|
4139 | &finfo->dreloff,
|
---|
4140 | exec_hdr (input_bfd)->a_drsize))
|
---|
4141 | return FALSE;
|
---|
4142 | }
|
---|
4143 |
|
---|
4144 | /* If we are not keeping memory, we don't need the symbols any
|
---|
4145 | longer. We still need them if we are keeping memory, because the
|
---|
4146 | strings in the hash table point into them. */
|
---|
4147 | if (! finfo->info->keep_memory)
|
---|
4148 | {
|
---|
4149 | if (! aout_link_free_symbols (input_bfd))
|
---|
4150 | return FALSE;
|
---|
4151 | }
|
---|
4152 |
|
---|
4153 | return TRUE;
|
---|
4154 | }
|
---|
4155 |
|
---|
4156 | /* Adjust and write out the symbols for an a.out file. Set the new
|
---|
4157 | symbol indices into a symbol_map. */
|
---|
4158 |
|
---|
4159 | static bfd_boolean
|
---|
4160 | aout_link_write_symbols (finfo, input_bfd)
|
---|
4161 | struct aout_final_link_info *finfo;
|
---|
4162 | bfd *input_bfd;
|
---|
4163 | {
|
---|
4164 | bfd *output_bfd;
|
---|
4165 | bfd_size_type sym_count;
|
---|
4166 | char *strings;
|
---|
4167 | enum bfd_link_strip strip;
|
---|
4168 | enum bfd_link_discard discard;
|
---|
4169 | struct external_nlist *outsym;
|
---|
4170 | bfd_size_type strtab_index;
|
---|
4171 | register struct external_nlist *sym;
|
---|
4172 | struct external_nlist *sym_end;
|
---|
4173 | struct aout_link_hash_entry **sym_hash;
|
---|
4174 | int *symbol_map;
|
---|
4175 | bfd_boolean pass;
|
---|
4176 | bfd_boolean skip_next;
|
---|
4177 |
|
---|
4178 | output_bfd = finfo->output_bfd;
|
---|
4179 | sym_count = obj_aout_external_sym_count (input_bfd);
|
---|
4180 | strings = obj_aout_external_strings (input_bfd);
|
---|
4181 | strip = finfo->info->strip;
|
---|
4182 | discard = finfo->info->discard;
|
---|
4183 | outsym = finfo->output_syms;
|
---|
4184 |
|
---|
4185 | /* First write out a symbol for this object file, unless we are
|
---|
4186 | discarding such symbols. */
|
---|
4187 | if (strip != strip_all
|
---|
4188 | && (strip != strip_some
|
---|
4189 | || bfd_hash_lookup (finfo->info->keep_hash, input_bfd->filename,
|
---|
4190 | FALSE, FALSE) != NULL)
|
---|
4191 | && discard != discard_all)
|
---|
4192 | {
|
---|
4193 | H_PUT_8 (output_bfd, N_TEXT, outsym->e_type);
|
---|
4194 | H_PUT_8 (output_bfd, 0, outsym->e_other);
|
---|
4195 | H_PUT_16 (output_bfd, 0, outsym->e_desc);
|
---|
4196 | strtab_index = add_to_stringtab (output_bfd, finfo->strtab,
|
---|
4197 | input_bfd->filename, FALSE);
|
---|
4198 | if (strtab_index == (bfd_size_type) -1)
|
---|
4199 | return FALSE;
|
---|
4200 | PUT_WORD (output_bfd, strtab_index, outsym->e_strx);
|
---|
4201 | PUT_WORD (output_bfd,
|
---|
4202 | (bfd_get_section_vma (output_bfd,
|
---|
4203 | obj_textsec (input_bfd)->output_section)
|
---|
4204 | + obj_textsec (input_bfd)->output_offset),
|
---|
4205 | outsym->e_value);
|
---|
4206 | ++obj_aout_external_sym_count (output_bfd);
|
---|
4207 | ++outsym;
|
---|
4208 | }
|
---|
4209 |
|
---|
4210 | pass = FALSE;
|
---|
4211 | skip_next = FALSE;
|
---|
4212 | sym = obj_aout_external_syms (input_bfd);
|
---|
4213 | sym_end = sym + sym_count;
|
---|
4214 | sym_hash = obj_aout_sym_hashes (input_bfd);
|
---|
4215 | symbol_map = finfo->symbol_map;
|
---|
4216 | memset (symbol_map, 0, (size_t) sym_count * sizeof *symbol_map);
|
---|
4217 | for (; sym < sym_end; sym++, sym_hash++, symbol_map++)
|
---|
4218 | {
|
---|
4219 | const char *name;
|
---|
4220 | int type;
|
---|
4221 | struct aout_link_hash_entry *h;
|
---|
4222 | bfd_boolean skip;
|
---|
4223 | asection *symsec;
|
---|
4224 | bfd_vma val = 0;
|
---|
4225 | bfd_boolean copy;
|
---|
4226 |
|
---|
4227 | /* We set *symbol_map to 0 above for all symbols. If it has
|
---|
4228 | already been set to -1 for this symbol, it means that we are
|
---|
4229 | discarding it because it appears in a duplicate header file.
|
---|
4230 | See the N_BINCL code below. */
|
---|
4231 | if (*symbol_map == -1)
|
---|
4232 | continue;
|
---|
4233 |
|
---|
4234 | /* Initialize *symbol_map to -1, which means that the symbol was
|
---|
4235 | not copied into the output file. We will change it later if
|
---|
4236 | we do copy the symbol over. */
|
---|
4237 | *symbol_map = -1;
|
---|
4238 |
|
---|
4239 | type = H_GET_8 (input_bfd, sym->e_type);
|
---|
4240 | name = strings + GET_WORD (input_bfd, sym->e_strx);
|
---|
4241 |
|
---|
4242 | h = NULL;
|
---|
4243 |
|
---|
4244 | if (pass)
|
---|
4245 | {
|
---|
4246 | /* Pass this symbol through. It is the target of an
|
---|
4247 | indirect or warning symbol. */
|
---|
4248 | val = GET_WORD (input_bfd, sym->e_value);
|
---|
4249 | pass = FALSE;
|
---|
4250 | }
|
---|
4251 | else if (skip_next)
|
---|
4252 | {
|
---|
4253 | /* Skip this symbol, which is the target of an indirect
|
---|
4254 | symbol that we have changed to no longer be an indirect
|
---|
4255 | symbol. */
|
---|
4256 | skip_next = FALSE;
|
---|
4257 | continue;
|
---|
4258 | }
|
---|
4259 | else
|
---|
4260 | {
|
---|
4261 | struct aout_link_hash_entry *hresolve;
|
---|
4262 |
|
---|
4263 | /* We have saved the hash table entry for this symbol, if
|
---|
4264 | there is one. Note that we could just look it up again
|
---|
4265 | in the hash table, provided we first check that it is an
|
---|
4266 | external symbol. */
|
---|
4267 | h = *sym_hash;
|
---|
4268 |
|
---|
4269 | /* Use the name from the hash table, in case the symbol was
|
---|
4270 | wrapped. */
|
---|
4271 | if (h != NULL
|
---|
4272 | && h->root.type != bfd_link_hash_warning)
|
---|
4273 | name = h->root.root.string;
|
---|
4274 |
|
---|
4275 | /* If this is an indirect or warning symbol, then change
|
---|
4276 | hresolve to the base symbol. We also change *sym_hash so
|
---|
4277 | that the relocation routines relocate against the real
|
---|
4278 | symbol. */
|
---|
4279 | hresolve = h;
|
---|
4280 | if (h != (struct aout_link_hash_entry *) NULL
|
---|
4281 | && (h->root.type == bfd_link_hash_indirect
|
---|
4282 | || h->root.type == bfd_link_hash_warning))
|
---|
4283 | {
|
---|
4284 | hresolve = (struct aout_link_hash_entry *) h->root.u.i.link;
|
---|
4285 | while (hresolve->root.type == bfd_link_hash_indirect
|
---|
4286 | || hresolve->root.type == bfd_link_hash_warning)
|
---|
4287 | hresolve = ((struct aout_link_hash_entry *)
|
---|
4288 | hresolve->root.u.i.link);
|
---|
4289 | *sym_hash = hresolve;
|
---|
4290 | }
|
---|
4291 |
|
---|
4292 | /* If the symbol has already been written out, skip it. */
|
---|
4293 | if (h != (struct aout_link_hash_entry *) NULL
|
---|
4294 | && h->written)
|
---|
4295 | {
|
---|
4296 | if ((type & N_TYPE) == N_INDR
|
---|
4297 | || type == N_WARNING)
|
---|
4298 | skip_next = TRUE;
|
---|
4299 | *symbol_map = h->indx;
|
---|
4300 | continue;
|
---|
4301 | }
|
---|
4302 |
|
---|
4303 | /* See if we are stripping this symbol. */
|
---|
4304 | skip = FALSE;
|
---|
4305 | switch (strip)
|
---|
4306 | {
|
---|
4307 | case strip_none:
|
---|
4308 | break;
|
---|
4309 | case strip_debugger:
|
---|
4310 | if (IS_STAB(type))
|
---|
4311 | skip = TRUE;
|
---|
4312 | break;
|
---|
4313 | case strip_some:
|
---|
4314 | if (bfd_hash_lookup (finfo->info->keep_hash, name, FALSE, FALSE)
|
---|
4315 | == NULL)
|
---|
4316 | skip = TRUE;
|
---|
4317 | break;
|
---|
4318 | case strip_all:
|
---|
4319 | skip = TRUE;
|
---|
4320 | break;
|
---|
4321 | }
|
---|
4322 | if (skip)
|
---|
4323 | {
|
---|
4324 | if (h != (struct aout_link_hash_entry *) NULL)
|
---|
4325 | h->written = TRUE;
|
---|
4326 | continue;
|
---|
4327 | }
|
---|
4328 |
|
---|
4329 | /* Get the value of the symbol. */
|
---|
4330 | if ((type & N_TYPE) == N_TEXT
|
---|
4331 | || type == N_WEAKT)
|
---|
4332 | symsec = obj_textsec (input_bfd);
|
---|
4333 | else if ((type & N_TYPE) == N_DATA
|
---|
4334 | || type == N_WEAKD)
|
---|
4335 | symsec = obj_datasec (input_bfd);
|
---|
4336 | else if ((type & N_TYPE) == N_BSS
|
---|
4337 | || type == N_WEAKB)
|
---|
4338 | symsec = obj_bsssec (input_bfd);
|
---|
4339 | else if ((type & N_TYPE) == N_ABS
|
---|
4340 | || type == N_WEAKA)
|
---|
4341 | symsec = bfd_abs_section_ptr;
|
---|
4342 | else if (((type & N_TYPE) == N_INDR
|
---|
4343 | && (hresolve == (struct aout_link_hash_entry *) NULL
|
---|
4344 | || (hresolve->root.type != bfd_link_hash_defined
|
---|
4345 | && hresolve->root.type != bfd_link_hash_defweak
|
---|
4346 | && hresolve->root.type != bfd_link_hash_common)))
|
---|
4347 | || type == N_WARNING)
|
---|
4348 | {
|
---|
4349 | /* Pass the next symbol through unchanged. The
|
---|
4350 | condition above for indirect symbols is so that if
|
---|
4351 | the indirect symbol was defined, we output it with
|
---|
4352 | the correct definition so the debugger will
|
---|
4353 | understand it. */
|
---|
4354 | pass = TRUE;
|
---|
4355 | val = GET_WORD (input_bfd, sym->e_value);
|
---|
4356 | symsec = NULL;
|
---|
4357 | }
|
---|
4358 | #ifdef EMX
|
---|
4359 | else if ((type == (N_IMP1 | N_EXT))
|
---|
4360 | || (type == (N_IMP2 | N_EXT)))
|
---|
4361 | symsec = bfd_abs_section_ptr;
|
---|
4362 | #endif
|
---|
4363 | else if (IS_STAB(type))
|
---|
4364 | {
|
---|
4365 | val = GET_WORD (input_bfd, sym->e_value);
|
---|
4366 | symsec = NULL;
|
---|
4367 | }
|
---|
4368 | else
|
---|
4369 | {
|
---|
4370 | /* If we get here with an indirect symbol, it means that
|
---|
4371 | we are outputting it with a real definition. In such
|
---|
4372 | a case we do not want to output the next symbol,
|
---|
4373 | which is the target of the indirection. */
|
---|
4374 | if ((type & N_TYPE) == N_INDR)
|
---|
4375 | skip_next = TRUE;
|
---|
4376 |
|
---|
4377 | symsec = NULL;
|
---|
4378 |
|
---|
4379 | /* We need to get the value from the hash table. We use
|
---|
4380 | hresolve so that if we have defined an indirect
|
---|
4381 | symbol we output the final definition. */
|
---|
4382 | if (h == (struct aout_link_hash_entry *) NULL)
|
---|
4383 | {
|
---|
4384 | switch (type & N_TYPE)
|
---|
4385 | {
|
---|
4386 | case N_SETT:
|
---|
4387 | symsec = obj_textsec (input_bfd);
|
---|
4388 | break;
|
---|
4389 | case N_SETD:
|
---|
4390 | symsec = obj_datasec (input_bfd);
|
---|
4391 | break;
|
---|
4392 | case N_SETB:
|
---|
4393 | symsec = obj_bsssec (input_bfd);
|
---|
4394 | break;
|
---|
4395 | case N_SETA:
|
---|
4396 | symsec = bfd_abs_section_ptr;
|
---|
4397 | break;
|
---|
4398 | default:
|
---|
4399 | val = 0;
|
---|
4400 | break;
|
---|
4401 | }
|
---|
4402 | }
|
---|
4403 | else if (hresolve->root.type == bfd_link_hash_defined
|
---|
4404 | || hresolve->root.type == bfd_link_hash_defweak)
|
---|
4405 | {
|
---|
4406 | asection *input_section;
|
---|
4407 | asection *output_section;
|
---|
4408 |
|
---|
4409 | /* This case usually means a common symbol which was
|
---|
4410 | turned into a defined symbol. */
|
---|
4411 | input_section = hresolve->root.u.def.section;
|
---|
4412 | output_section = input_section->output_section;
|
---|
4413 | BFD_ASSERT (bfd_is_abs_section (output_section)
|
---|
4414 | || output_section->owner == output_bfd);
|
---|
4415 | val = (hresolve->root.u.def.value
|
---|
4416 | + bfd_get_section_vma (output_bfd, output_section)
|
---|
4417 | + input_section->output_offset);
|
---|
4418 |
|
---|
4419 | /* Get the correct type based on the section. If
|
---|
4420 | this is a constructed set, force it to be
|
---|
4421 | globally visible. */
|
---|
4422 | if (type == N_SETT
|
---|
4423 | || type == N_SETD
|
---|
4424 | || type == N_SETB
|
---|
4425 | || type == N_SETA)
|
---|
4426 | type |= N_EXT;
|
---|
4427 |
|
---|
4428 | type &=~ N_TYPE;
|
---|
4429 |
|
---|
4430 | if (output_section == obj_textsec (output_bfd))
|
---|
4431 | type |= (hresolve->root.type == bfd_link_hash_defined
|
---|
4432 | ? N_TEXT
|
---|
4433 | : N_WEAKT);
|
---|
4434 | else if (output_section == obj_datasec (output_bfd))
|
---|
4435 | type |= (hresolve->root.type == bfd_link_hash_defined
|
---|
4436 | ? N_DATA
|
---|
4437 | : N_WEAKD);
|
---|
4438 | else if (output_section == obj_bsssec (output_bfd))
|
---|
4439 | type |= (hresolve->root.type == bfd_link_hash_defined
|
---|
4440 | ? N_BSS
|
---|
4441 | : N_WEAKB);
|
---|
4442 | else
|
---|
4443 | type |= (hresolve->root.type == bfd_link_hash_defined
|
---|
4444 | ? N_ABS
|
---|
4445 | : N_WEAKA);
|
---|
4446 | }
|
---|
4447 | else if (hresolve->root.type == bfd_link_hash_common)
|
---|
4448 | val = hresolve->root.u.c.size;
|
---|
4449 | else if (hresolve->root.type == bfd_link_hash_undefweak)
|
---|
4450 | {
|
---|
4451 | val = 0;
|
---|
4452 | type = N_WEAKU;
|
---|
4453 | }
|
---|
4454 | else
|
---|
4455 | val = 0;
|
---|
4456 | }
|
---|
4457 | if (symsec != (asection *) NULL)
|
---|
4458 | val = (symsec->output_section->vma
|
---|
4459 | + symsec->output_offset
|
---|
4460 | + (GET_WORD (input_bfd, sym->e_value)
|
---|
4461 | - symsec->vma));
|
---|
4462 |
|
---|
4463 | /* If this is a global symbol set the written flag, and if
|
---|
4464 | it is a local symbol see if we should discard it. */
|
---|
4465 | if (h != (struct aout_link_hash_entry *) NULL)
|
---|
4466 | {
|
---|
4467 | h->written = TRUE;
|
---|
4468 | h->indx = obj_aout_external_sym_count (output_bfd);
|
---|
4469 | }
|
---|
4470 | else if ((type & N_TYPE) != N_SETT
|
---|
4471 | && (type & N_TYPE) != N_SETD
|
---|
4472 | && (type & N_TYPE) != N_SETB
|
---|
4473 | && (type & N_TYPE) != N_SETA)
|
---|
4474 | {
|
---|
4475 | switch (discard)
|
---|
4476 | {
|
---|
4477 | case discard_none:
|
---|
4478 | case discard_sec_merge:
|
---|
4479 | break;
|
---|
4480 | case discard_l:
|
---|
4481 | if (!IS_STAB(type)
|
---|
4482 | && bfd_is_local_label_name (input_bfd, name))
|
---|
4483 | skip = TRUE;
|
---|
4484 | break;
|
---|
4485 | case discard_all:
|
---|
4486 | skip = TRUE;
|
---|
4487 | break;
|
---|
4488 | }
|
---|
4489 | if (skip)
|
---|
4490 | {
|
---|
4491 | pass = FALSE;
|
---|
4492 | continue;
|
---|
4493 | }
|
---|
4494 | }
|
---|
4495 |
|
---|
4496 | /* An N_BINCL symbol indicates the start of the stabs
|
---|
4497 | entries for a header file. We need to scan ahead to the
|
---|
4498 | next N_EINCL symbol, ignoring nesting, adding up all the
|
---|
4499 | characters in the symbol names, not including the file
|
---|
4500 | numbers in types (the first number after an open
|
---|
4501 | parenthesis). */
|
---|
4502 | if (type == (int) N_BINCL)
|
---|
4503 | {
|
---|
4504 | struct external_nlist *incl_sym;
|
---|
4505 | int nest;
|
---|
4506 | struct aout_link_includes_entry *incl_entry;
|
---|
4507 | struct aout_link_includes_totals *t;
|
---|
4508 |
|
---|
4509 | val = 0;
|
---|
4510 | nest = 0;
|
---|
4511 | for (incl_sym = sym + 1; incl_sym < sym_end; incl_sym++)
|
---|
4512 | {
|
---|
4513 | int incl_type;
|
---|
4514 |
|
---|
4515 | incl_type = H_GET_8 (input_bfd, incl_sym->e_type);
|
---|
4516 | if (incl_type == (int) N_EINCL)
|
---|
4517 | {
|
---|
4518 | if (nest == 0)
|
---|
4519 | break;
|
---|
4520 | --nest;
|
---|
4521 | }
|
---|
4522 | else if (incl_type == (int) N_BINCL)
|
---|
4523 | ++nest;
|
---|
4524 | else if (nest == 0)
|
---|
4525 | {
|
---|
4526 | const char *s;
|
---|
4527 |
|
---|
4528 | s = strings + GET_WORD (input_bfd, incl_sym->e_strx);
|
---|
4529 | for (; *s != '\0'; s++)
|
---|
4530 | {
|
---|
4531 | val += *s;
|
---|
4532 | if (*s == '(')
|
---|
4533 | {
|
---|
4534 | /* Skip the file number. */
|
---|
4535 | ++s;
|
---|
4536 | while (ISDIGIT (*s))
|
---|
4537 | ++s;
|
---|
4538 | --s;
|
---|
4539 | }
|
---|
4540 | }
|
---|
4541 | }
|
---|
4542 | }
|
---|
4543 |
|
---|
4544 | /* If we have already included a header file with the
|
---|
4545 | same value, then replace this one with an N_EXCL
|
---|
4546 | symbol. */
|
---|
4547 | copy = (bfd_boolean) (! finfo->info->keep_memory);
|
---|
4548 | incl_entry = aout_link_includes_lookup (&finfo->includes,
|
---|
4549 | name, TRUE, copy);
|
---|
4550 | if (incl_entry == NULL)
|
---|
4551 | return FALSE;
|
---|
4552 | for (t = incl_entry->totals; t != NULL; t = t->next)
|
---|
4553 | if (t->total == val)
|
---|
4554 | break;
|
---|
4555 | if (t == NULL)
|
---|
4556 | {
|
---|
4557 | /* This is the first time we have seen this header
|
---|
4558 | file with this set of stabs strings. */
|
---|
4559 | t = ((struct aout_link_includes_totals *)
|
---|
4560 | bfd_hash_allocate (&finfo->includes.root,
|
---|
4561 | sizeof *t));
|
---|
4562 | if (t == NULL)
|
---|
4563 | return FALSE;
|
---|
4564 | t->total = val;
|
---|
4565 | t->next = incl_entry->totals;
|
---|
4566 | incl_entry->totals = t;
|
---|
4567 | }
|
---|
4568 | else
|
---|
4569 | {
|
---|
4570 | int *incl_map;
|
---|
4571 |
|
---|
4572 | /* This is a duplicate header file. We must change
|
---|
4573 | it to be an N_EXCL entry, and mark all the
|
---|
4574 | included symbols to prevent outputting them. */
|
---|
4575 | type = (int) N_EXCL;
|
---|
4576 |
|
---|
4577 | nest = 0;
|
---|
4578 | for (incl_sym = sym + 1, incl_map = symbol_map + 1;
|
---|
4579 | incl_sym < sym_end;
|
---|
4580 | incl_sym++, incl_map++)
|
---|
4581 | {
|
---|
4582 | int incl_type;
|
---|
4583 |
|
---|
4584 | incl_type = H_GET_8 (input_bfd, incl_sym->e_type);
|
---|
4585 | if (incl_type == (int) N_EINCL)
|
---|
4586 | {
|
---|
4587 | if (nest == 0)
|
---|
4588 | {
|
---|
4589 | *incl_map = -1;
|
---|
4590 | break;
|
---|
4591 | }
|
---|
4592 | --nest;
|
---|
4593 | }
|
---|
4594 | else if (incl_type == (int) N_BINCL)
|
---|
4595 | ++nest;
|
---|
4596 | else if (nest == 0)
|
---|
4597 | *incl_map = -1;
|
---|
4598 | }
|
---|
4599 | }
|
---|
4600 | }
|
---|
4601 | }
|
---|
4602 |
|
---|
4603 | /* Copy this symbol into the list of symbols we are going to
|
---|
4604 | write out. */
|
---|
4605 | H_PUT_8 (output_bfd, type, outsym->e_type);
|
---|
4606 | H_PUT_8 (output_bfd, H_GET_8 (input_bfd, sym->e_other), outsym->e_other);
|
---|
4607 | H_PUT_16 (output_bfd, H_GET_16 (input_bfd, sym->e_desc), outsym->e_desc);
|
---|
4608 | copy = FALSE;
|
---|
4609 | if (! finfo->info->keep_memory)
|
---|
4610 | {
|
---|
4611 | /* name points into a string table which we are going to
|
---|
4612 | free. If there is a hash table entry, use that string.
|
---|
4613 | Otherwise, copy name into memory. */
|
---|
4614 | if (h != (struct aout_link_hash_entry *) NULL)
|
---|
4615 | name = h->root.root.string;
|
---|
4616 | else
|
---|
4617 | copy = TRUE;
|
---|
4618 | }
|
---|
4619 | strtab_index = add_to_stringtab (output_bfd, finfo->strtab,
|
---|
4620 | name, copy);
|
---|
4621 | if (strtab_index == (bfd_size_type) -1)
|
---|
4622 | return FALSE;
|
---|
4623 | PUT_WORD (output_bfd, strtab_index, outsym->e_strx);
|
---|
4624 | PUT_WORD (output_bfd, val, outsym->e_value);
|
---|
4625 | *symbol_map = obj_aout_external_sym_count (output_bfd);
|
---|
4626 | ++obj_aout_external_sym_count (output_bfd);
|
---|
4627 | ++outsym;
|
---|
4628 | }
|
---|
4629 |
|
---|
4630 | /* Write out the output symbols we have just constructed. */
|
---|
4631 | if (outsym > finfo->output_syms)
|
---|
4632 | {
|
---|
4633 | bfd_size_type outsym_size;
|
---|
4634 |
|
---|
4635 | if (bfd_seek (output_bfd, finfo->symoff, SEEK_SET) != 0)
|
---|
4636 | return FALSE;
|
---|
4637 | outsym_size = outsym - finfo->output_syms;
|
---|
4638 | outsym_size *= EXTERNAL_NLIST_SIZE;
|
---|
4639 | if (bfd_bwrite ((PTR) finfo->output_syms, outsym_size, output_bfd)
|
---|
4640 | != outsym_size)
|
---|
4641 | return FALSE;
|
---|
4642 | finfo->symoff += outsym_size;
|
---|
4643 | }
|
---|
4644 |
|
---|
4645 | return TRUE;
|
---|
4646 | }
|
---|
4647 |
|
---|
4648 | /* Write out a symbol that was not associated with an a.out input
|
---|
4649 | object. */
|
---|
4650 |
|
---|
4651 | static bfd_boolean
|
---|
4652 | aout_link_write_other_symbol (h, data)
|
---|
4653 | struct aout_link_hash_entry *h;
|
---|
4654 | PTR data;
|
---|
4655 | {
|
---|
4656 | struct aout_final_link_info *finfo = (struct aout_final_link_info *) data;
|
---|
4657 | bfd *output_bfd;
|
---|
4658 | int type;
|
---|
4659 | bfd_vma val;
|
---|
4660 | struct external_nlist outsym;
|
---|
4661 | bfd_size_type indx;
|
---|
4662 | bfd_size_type amt;
|
---|
4663 |
|
---|
4664 | if (h->root.type == bfd_link_hash_warning)
|
---|
4665 | {
|
---|
4666 | h = (struct aout_link_hash_entry *) h->root.u.i.link;
|
---|
4667 | if (h->root.type == bfd_link_hash_new)
|
---|
4668 | return TRUE;
|
---|
4669 | }
|
---|
4670 |
|
---|
4671 | output_bfd = finfo->output_bfd;
|
---|
4672 |
|
---|
4673 | if (aout_backend_info (output_bfd)->write_dynamic_symbol != NULL)
|
---|
4674 | {
|
---|
4675 | if (! ((*aout_backend_info (output_bfd)->write_dynamic_symbol)
|
---|
4676 | (output_bfd, finfo->info, h)))
|
---|
4677 | {
|
---|
4678 | /* FIXME: No way to handle errors. */
|
---|
4679 | abort ();
|
---|
4680 | }
|
---|
4681 | }
|
---|
4682 |
|
---|
4683 | if (h->written)
|
---|
4684 | return TRUE;
|
---|
4685 |
|
---|
4686 | h->written = TRUE;
|
---|
4687 |
|
---|
4688 | /* An indx of -2 means the symbol must be written. */
|
---|
4689 | if (h->indx != -2
|
---|
4690 | && (finfo->info->strip == strip_all
|
---|
4691 | || (finfo->info->strip == strip_some
|
---|
4692 | && bfd_hash_lookup (finfo->info->keep_hash, h->root.root.string,
|
---|
4693 | FALSE, FALSE) == NULL)))
|
---|
4694 | return TRUE;
|
---|
4695 |
|
---|
4696 | switch (h->root.type)
|
---|
4697 | {
|
---|
4698 | default:
|
---|
4699 | case bfd_link_hash_warning:
|
---|
4700 | abort ();
|
---|
4701 | /* Avoid variable not initialized warnings. */
|
---|
4702 | return TRUE;
|
---|
4703 | case bfd_link_hash_new:
|
---|
4704 | /* This can happen for set symbols when sets are not being
|
---|
4705 | built. */
|
---|
4706 | return TRUE;
|
---|
4707 | case bfd_link_hash_undefined:
|
---|
4708 | type = N_UNDF | N_EXT;
|
---|
4709 | val = 0;
|
---|
4710 | break;
|
---|
4711 | case bfd_link_hash_defined:
|
---|
4712 | case bfd_link_hash_defweak:
|
---|
4713 | {
|
---|
4714 | asection *sec;
|
---|
4715 |
|
---|
4716 | sec = h->root.u.def.section->output_section;
|
---|
4717 | BFD_ASSERT (bfd_is_abs_section (sec)
|
---|
4718 | || sec->owner == output_bfd);
|
---|
4719 | if (sec == obj_textsec (output_bfd))
|
---|
4720 | type = h->root.type == bfd_link_hash_defined ? N_TEXT : N_WEAKT;
|
---|
4721 | else if (sec == obj_datasec (output_bfd))
|
---|
4722 | type = h->root.type == bfd_link_hash_defined ? N_DATA : N_WEAKD;
|
---|
4723 | else if (sec == obj_bsssec (output_bfd))
|
---|
4724 | type = h->root.type == bfd_link_hash_defined ? N_BSS : N_WEAKB;
|
---|
4725 | else
|
---|
4726 | type = h->root.type == bfd_link_hash_defined ? N_ABS : N_WEAKA;
|
---|
4727 | type |= N_EXT;
|
---|
4728 | val = (h->root.u.def.value
|
---|
4729 | + sec->vma
|
---|
4730 | + h->root.u.def.section->output_offset);
|
---|
4731 | }
|
---|
4732 | break;
|
---|
4733 | case bfd_link_hash_common:
|
---|
4734 | type = N_UNDF | N_EXT;
|
---|
4735 | val = h->root.u.c.size;
|
---|
4736 | break;
|
---|
4737 | case bfd_link_hash_undefweak:
|
---|
4738 | type = N_WEAKU;
|
---|
4739 | val = 0;
|
---|
4740 | case bfd_link_hash_indirect:
|
---|
4741 | /* We ignore these symbols, since the indirected symbol is
|
---|
4742 | already in the hash table. */
|
---|
4743 | return TRUE;
|
---|
4744 | }
|
---|
4745 |
|
---|
4746 | H_PUT_8 (output_bfd, type, outsym.e_type);
|
---|
4747 | H_PUT_8 (output_bfd, 0, outsym.e_other);
|
---|
4748 | H_PUT_16 (output_bfd, 0, outsym.e_desc);
|
---|
4749 | indx = add_to_stringtab (output_bfd, finfo->strtab, h->root.root.string,
|
---|
4750 | FALSE);
|
---|
4751 | if (indx == - (bfd_size_type) 1)
|
---|
4752 | {
|
---|
4753 | /* FIXME: No way to handle errors. */
|
---|
4754 | abort ();
|
---|
4755 | }
|
---|
4756 | PUT_WORD (output_bfd, indx, outsym.e_strx);
|
---|
4757 | PUT_WORD (output_bfd, val, outsym.e_value);
|
---|
4758 |
|
---|
4759 | amt = EXTERNAL_NLIST_SIZE;
|
---|
4760 | if (bfd_seek (output_bfd, finfo->symoff, SEEK_SET) != 0
|
---|
4761 | || bfd_bwrite ((PTR) &outsym, amt, output_bfd) != amt)
|
---|
4762 | {
|
---|
4763 | /* FIXME: No way to handle errors. */
|
---|
4764 | abort ();
|
---|
4765 | }
|
---|
4766 |
|
---|
4767 | finfo->symoff += EXTERNAL_NLIST_SIZE;
|
---|
4768 | h->indx = obj_aout_external_sym_count (output_bfd);
|
---|
4769 | ++obj_aout_external_sym_count (output_bfd);
|
---|
4770 |
|
---|
4771 | return TRUE;
|
---|
4772 | }
|
---|
4773 |
|
---|
4774 | /* Link an a.out section into the output file. */
|
---|
4775 |
|
---|
4776 | static bfd_boolean
|
---|
4777 | aout_link_input_section (finfo, input_bfd, input_section, reloff_ptr,
|
---|
4778 | rel_size)
|
---|
4779 | struct aout_final_link_info *finfo;
|
---|
4780 | bfd *input_bfd;
|
---|
4781 | asection *input_section;
|
---|
4782 | file_ptr *reloff_ptr;
|
---|
4783 | bfd_size_type rel_size;
|
---|
4784 | {
|
---|
4785 | bfd_size_type input_size;
|
---|
4786 | PTR relocs;
|
---|
4787 |
|
---|
4788 | /* Get the section contents. */
|
---|
4789 | input_size = bfd_section_size (input_bfd, input_section);
|
---|
4790 | if (! bfd_get_section_contents (input_bfd, input_section,
|
---|
4791 | (PTR) finfo->contents,
|
---|
4792 | (file_ptr) 0, input_size))
|
---|
4793 | return FALSE;
|
---|
4794 |
|
---|
4795 | /* Read in the relocs if we haven't already done it. */
|
---|
4796 | if (aout_section_data (input_section) != NULL
|
---|
4797 | && aout_section_data (input_section)->relocs != NULL)
|
---|
4798 | relocs = aout_section_data (input_section)->relocs;
|
---|
4799 | else
|
---|
4800 | {
|
---|
4801 | relocs = finfo->relocs;
|
---|
4802 | if (rel_size > 0)
|
---|
4803 | {
|
---|
4804 | if (bfd_seek (input_bfd, input_section->rel_filepos, SEEK_SET) != 0
|
---|
4805 | || bfd_bread (relocs, rel_size, input_bfd) != rel_size)
|
---|
4806 | return FALSE;
|
---|
4807 | }
|
---|
4808 | }
|
---|
4809 |
|
---|
4810 | /* Relocate the section contents. */
|
---|
4811 | if (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE)
|
---|
4812 | {
|
---|
4813 | if (! aout_link_input_section_std (finfo, input_bfd, input_section,
|
---|
4814 | (struct reloc_std_external *) relocs,
|
---|
4815 | rel_size, finfo->contents))
|
---|
4816 | return FALSE;
|
---|
4817 | }
|
---|
4818 | else
|
---|
4819 | {
|
---|
4820 | if (! aout_link_input_section_ext (finfo, input_bfd, input_section,
|
---|
4821 | (struct reloc_ext_external *) relocs,
|
---|
4822 | rel_size, finfo->contents))
|
---|
4823 | return FALSE;
|
---|
4824 | }
|
---|
4825 |
|
---|
4826 | /* Write out the section contents. */
|
---|
4827 | if (! bfd_set_section_contents (finfo->output_bfd,
|
---|
4828 | input_section->output_section,
|
---|
4829 | (PTR) finfo->contents,
|
---|
4830 | (file_ptr) input_section->output_offset,
|
---|
4831 | input_size))
|
---|
4832 | return FALSE;
|
---|
4833 |
|
---|
4834 | /* If we are producing relocateable output, the relocs were
|
---|
4835 | modified, and we now write them out. */
|
---|
4836 | if (finfo->info->relocateable && rel_size > 0)
|
---|
4837 | {
|
---|
4838 | if (bfd_seek (finfo->output_bfd, *reloff_ptr, SEEK_SET) != 0)
|
---|
4839 | return FALSE;
|
---|
4840 | if (bfd_bwrite (relocs, rel_size, finfo->output_bfd) != rel_size)
|
---|
4841 | return FALSE;
|
---|
4842 | *reloff_ptr += rel_size;
|
---|
4843 |
|
---|
4844 | /* Assert that the relocs have not run into the symbols, and
|
---|
4845 | that if these are the text relocs they have not run into the
|
---|
4846 | data relocs. */
|
---|
4847 | BFD_ASSERT (*reloff_ptr <= obj_sym_filepos (finfo->output_bfd)
|
---|
4848 | && (reloff_ptr != &finfo->treloff
|
---|
4849 | || (*reloff_ptr
|
---|
4850 | <= obj_datasec (finfo->output_bfd)->rel_filepos)));
|
---|
4851 | }
|
---|
4852 |
|
---|
4853 | return TRUE;
|
---|
4854 | }
|
---|
4855 |
|
---|
4856 | /* Get the section corresponding to a reloc index. */
|
---|
4857 |
|
---|
4858 | static INLINE asection *
|
---|
4859 | aout_reloc_index_to_section (abfd, indx)
|
---|
4860 | bfd *abfd;
|
---|
4861 | int indx;
|
---|
4862 | {
|
---|
4863 | switch (indx & N_TYPE)
|
---|
4864 | {
|
---|
4865 | case N_TEXT:
|
---|
4866 | return obj_textsec (abfd);
|
---|
4867 | case N_DATA:
|
---|
4868 | return obj_datasec (abfd);
|
---|
4869 | case N_BSS:
|
---|
4870 | return obj_bsssec (abfd);
|
---|
4871 | case N_ABS:
|
---|
4872 | case N_UNDF:
|
---|
4873 | return bfd_abs_section_ptr;
|
---|
4874 | default:
|
---|
4875 | abort ();
|
---|
4876 | }
|
---|
4877 | /*NOTREACHED*/
|
---|
4878 | return NULL;
|
---|
4879 | }
|
---|
4880 |
|
---|
4881 | /* Relocate an a.out section using standard a.out relocs. */
|
---|
4882 |
|
---|
4883 | static bfd_boolean
|
---|
4884 | aout_link_input_section_std (finfo, input_bfd, input_section, relocs,
|
---|
4885 | rel_size, contents)
|
---|
4886 | struct aout_final_link_info *finfo;
|
---|
4887 | bfd *input_bfd;
|
---|
4888 | asection *input_section;
|
---|
4889 | struct reloc_std_external *relocs;
|
---|
4890 | bfd_size_type rel_size;
|
---|
4891 | bfd_byte *contents;
|
---|
4892 | {
|
---|
4893 | bfd_boolean (*check_dynamic_reloc)
|
---|
4894 | PARAMS ((struct bfd_link_info *, bfd *, asection *,
|
---|
4895 | struct aout_link_hash_entry *, PTR, bfd_byte *, bfd_boolean *,
|
---|
4896 | bfd_vma *));
|
---|
4897 | bfd *output_bfd;
|
---|
4898 | bfd_boolean relocateable;
|
---|
4899 | struct external_nlist *syms;
|
---|
4900 | char *strings;
|
---|
4901 | struct aout_link_hash_entry **sym_hashes;
|
---|
4902 | int *symbol_map;
|
---|
4903 | bfd_size_type reloc_count;
|
---|
4904 | register struct reloc_std_external *rel;
|
---|
4905 | struct reloc_std_external *rel_end;
|
---|
4906 |
|
---|
4907 | output_bfd = finfo->output_bfd;
|
---|
4908 | check_dynamic_reloc = aout_backend_info (output_bfd)->check_dynamic_reloc;
|
---|
4909 |
|
---|
4910 | BFD_ASSERT (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE);
|
---|
4911 | BFD_ASSERT (input_bfd->xvec->header_byteorder
|
---|
4912 | == output_bfd->xvec->header_byteorder);
|
---|
4913 |
|
---|
4914 | relocateable = finfo->info->relocateable;
|
---|
4915 | syms = obj_aout_external_syms (input_bfd);
|
---|
4916 | strings = obj_aout_external_strings (input_bfd);
|
---|
4917 | sym_hashes = obj_aout_sym_hashes (input_bfd);
|
---|
4918 | symbol_map = finfo->symbol_map;
|
---|
4919 |
|
---|
4920 | reloc_count = rel_size / RELOC_STD_SIZE;
|
---|
4921 | rel = relocs;
|
---|
4922 | rel_end = rel + reloc_count;
|
---|
4923 | for (; rel < rel_end; rel++)
|
---|
4924 | {
|
---|
4925 | bfd_vma r_addr;
|
---|
4926 | int r_index;
|
---|
4927 | int r_extern;
|
---|
4928 | int r_pcrel;
|
---|
4929 | int r_baserel = 0;
|
---|
4930 | reloc_howto_type *howto;
|
---|
4931 | struct aout_link_hash_entry *h = NULL;
|
---|
4932 | bfd_vma relocation;
|
---|
4933 | bfd_reloc_status_type r;
|
---|
4934 |
|
---|
4935 | r_addr = GET_SWORD (input_bfd, rel->r_address);
|
---|
4936 |
|
---|
4937 | #ifdef MY_reloc_howto
|
---|
4938 | howto = MY_reloc_howto (input_bfd, rel, r_index, r_extern, r_pcrel);
|
---|
4939 | #else
|
---|
4940 | {
|
---|
4941 | int r_jmptable;
|
---|
4942 | int r_relative;
|
---|
4943 | int r_length;
|
---|
4944 | unsigned int howto_idx;
|
---|
4945 |
|
---|
4946 | if (bfd_header_big_endian (input_bfd))
|
---|
4947 | {
|
---|
4948 | r_index = (((unsigned int) rel->r_index[0] << 16)
|
---|
4949 | | ((unsigned int) rel->r_index[1] << 8)
|
---|
4950 | | rel->r_index[2]);
|
---|
4951 | r_extern = (0 != (rel->r_type[0] & RELOC_STD_BITS_EXTERN_BIG));
|
---|
4952 | r_pcrel = (0 != (rel->r_type[0] & RELOC_STD_BITS_PCREL_BIG));
|
---|
4953 | r_baserel = (0 != (rel->r_type[0] & RELOC_STD_BITS_BASEREL_BIG));
|
---|
4954 | r_jmptable= (0 != (rel->r_type[0] & RELOC_STD_BITS_JMPTABLE_BIG));
|
---|
4955 | r_relative= (0 != (rel->r_type[0] & RELOC_STD_BITS_RELATIVE_BIG));
|
---|
4956 | r_length = ((rel->r_type[0] & RELOC_STD_BITS_LENGTH_BIG)
|
---|
4957 | >> RELOC_STD_BITS_LENGTH_SH_BIG);
|
---|
4958 | }
|
---|
4959 | else
|
---|
4960 | {
|
---|
4961 | r_index = (((unsigned int) rel->r_index[2] << 16)
|
---|
4962 | | ((unsigned int) rel->r_index[1] << 8)
|
---|
4963 | | rel->r_index[0]);
|
---|
4964 | r_extern = (0 != (rel->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE));
|
---|
4965 | r_pcrel = (0 != (rel->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE));
|
---|
4966 | r_baserel = (0 != (rel->r_type[0]
|
---|
4967 | & RELOC_STD_BITS_BASEREL_LITTLE));
|
---|
4968 | r_jmptable= (0 != (rel->r_type[0]
|
---|
4969 | & RELOC_STD_BITS_JMPTABLE_LITTLE));
|
---|
4970 | r_relative= (0 != (rel->r_type[0]
|
---|
4971 | & RELOC_STD_BITS_RELATIVE_LITTLE));
|
---|
4972 | r_length = ((rel->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE)
|
---|
4973 | >> RELOC_STD_BITS_LENGTH_SH_LITTLE);
|
---|
4974 | }
|
---|
4975 |
|
---|
4976 | howto_idx = (r_length + 4 * r_pcrel + 8 * r_baserel
|
---|
4977 | + 16 * r_jmptable + 32 * r_relative);
|
---|
4978 | BFD_ASSERT (howto_idx < TABLE_SIZE (howto_table_std));
|
---|
4979 | howto = howto_table_std + howto_idx;
|
---|
4980 | }
|
---|
4981 | #endif
|
---|
4982 |
|
---|
4983 | if (relocateable)
|
---|
4984 | {
|
---|
4985 | /* We are generating a relocateable output file, and must
|
---|
4986 | modify the reloc accordingly. */
|
---|
4987 | if (r_extern)
|
---|
4988 | {
|
---|
4989 | /* If we know the symbol this relocation is against,
|
---|
4990 | convert it into a relocation against a section. This
|
---|
4991 | is what the native linker does. */
|
---|
4992 | h = sym_hashes[r_index];
|
---|
4993 | if (h != (struct aout_link_hash_entry *) NULL
|
---|
4994 | #ifdef EMX
|
---|
4995 | /* Don't touch imported symbols */
|
---|
4996 | && (!bfd_is_abs_section (h->root.u.def.section)
|
---|
4997 | || (h->root.u.def.value != (unsigned)-1))
|
---|
4998 | #endif
|
---|
4999 | && (h->root.type == bfd_link_hash_defined
|
---|
5000 | || h->root.type == bfd_link_hash_defweak))
|
---|
5001 | {
|
---|
5002 | asection *output_section;
|
---|
5003 |
|
---|
5004 | /* Change the r_extern value. */
|
---|
5005 | if (bfd_header_big_endian (output_bfd))
|
---|
5006 | rel->r_type[0] &=~ RELOC_STD_BITS_EXTERN_BIG;
|
---|
5007 | else
|
---|
5008 | rel->r_type[0] &=~ RELOC_STD_BITS_EXTERN_LITTLE;
|
---|
5009 |
|
---|
5010 | /* Compute a new r_index. */
|
---|
5011 | output_section = h->root.u.def.section->output_section;
|
---|
5012 | if (output_section == obj_textsec (output_bfd))
|
---|
5013 | r_index = N_TEXT;
|
---|
5014 | else if (output_section == obj_datasec (output_bfd))
|
---|
5015 | r_index = N_DATA;
|
---|
5016 | else if (output_section == obj_bsssec (output_bfd))
|
---|
5017 | r_index = N_BSS;
|
---|
5018 | else
|
---|
5019 | r_index = N_ABS;
|
---|
5020 |
|
---|
5021 | /* Add the symbol value and the section VMA to the
|
---|
5022 | addend stored in the contents. */
|
---|
5023 | relocation = (h->root.u.def.value
|
---|
5024 | + output_section->vma
|
---|
5025 | + h->root.u.def.section->output_offset);
|
---|
5026 | }
|
---|
5027 | else
|
---|
5028 | {
|
---|
5029 | /* We must change r_index according to the symbol
|
---|
5030 | map. */
|
---|
5031 | r_index = symbol_map[r_index];
|
---|
5032 |
|
---|
5033 | if (r_index == -1)
|
---|
5034 | {
|
---|
5035 | if (h != NULL)
|
---|
5036 | {
|
---|
5037 | /* We decided to strip this symbol, but it
|
---|
5038 | turns out that we can't. Note that we
|
---|
5039 | lose the other and desc information here.
|
---|
5040 | I don't think that will ever matter for a
|
---|
5041 | global symbol. */
|
---|
5042 | if (h->indx < 0)
|
---|
5043 | {
|
---|
5044 | h->indx = -2;
|
---|
5045 | h->written = FALSE;
|
---|
5046 | if (! aout_link_write_other_symbol (h,
|
---|
5047 | (PTR) finfo))
|
---|
5048 | return FALSE;
|
---|
5049 | }
|
---|
5050 | r_index = h->indx;
|
---|
5051 | }
|
---|
5052 | else
|
---|
5053 | {
|
---|
5054 | const char *name;
|
---|
5055 |
|
---|
5056 | name = strings + GET_WORD (input_bfd,
|
---|
5057 | syms[r_index].e_strx);
|
---|
5058 | if (! ((*finfo->info->callbacks->unattached_reloc)
|
---|
5059 | (finfo->info, name, input_bfd, input_section,
|
---|
5060 | r_addr)))
|
---|
5061 | return FALSE;
|
---|
5062 | r_index = 0;
|
---|
5063 | }
|
---|
5064 | }
|
---|
5065 |
|
---|
5066 | relocation = 0;
|
---|
5067 | }
|
---|
5068 |
|
---|
5069 | /* Write out the new r_index value. */
|
---|
5070 | if (bfd_header_big_endian (output_bfd))
|
---|
5071 | {
|
---|
5072 | rel->r_index[0] = r_index >> 16;
|
---|
5073 | rel->r_index[1] = r_index >> 8;
|
---|
5074 | rel->r_index[2] = r_index;
|
---|
5075 | }
|
---|
5076 | else
|
---|
5077 | {
|
---|
5078 | rel->r_index[2] = r_index >> 16;
|
---|
5079 | rel->r_index[1] = r_index >> 8;
|
---|
5080 | rel->r_index[0] = r_index;
|
---|
5081 | }
|
---|
5082 | }
|
---|
5083 | else
|
---|
5084 | {
|
---|
5085 | asection *section;
|
---|
5086 |
|
---|
5087 | /* This is a relocation against a section. We must
|
---|
5088 | adjust by the amount that the section moved. */
|
---|
5089 | section = aout_reloc_index_to_section (input_bfd, r_index);
|
---|
5090 | relocation = (section->output_section->vma
|
---|
5091 | + section->output_offset
|
---|
5092 | - section->vma);
|
---|
5093 | }
|
---|
5094 |
|
---|
5095 | /* Change the address of the relocation. */
|
---|
5096 | PUT_WORD (output_bfd,
|
---|
5097 | r_addr + input_section->output_offset,
|
---|
5098 | rel->r_address);
|
---|
5099 |
|
---|
5100 | /* Adjust a PC relative relocation by removing the reference
|
---|
5101 | to the original address in the section and including the
|
---|
5102 | reference to the new address. */
|
---|
5103 | if (r_pcrel)
|
---|
5104 | relocation -= (input_section->output_section->vma
|
---|
5105 | + input_section->output_offset
|
---|
5106 | - input_section->vma);
|
---|
5107 |
|
---|
5108 | #ifdef MY_relocatable_reloc
|
---|
5109 | MY_relocatable_reloc (howto, output_bfd, rel, relocation, r_addr);
|
---|
5110 | #endif
|
---|
5111 |
|
---|
5112 | if (relocation == 0)
|
---|
5113 | r = bfd_reloc_ok;
|
---|
5114 | else
|
---|
5115 | r = MY_relocate_contents (howto,
|
---|
5116 | input_bfd, relocation,
|
---|
5117 | contents + r_addr);
|
---|
5118 | }
|
---|
5119 | else
|
---|
5120 | {
|
---|
5121 | bfd_boolean hundef;
|
---|
5122 |
|
---|
5123 | /* We are generating an executable, and must do a full
|
---|
5124 | relocation. */
|
---|
5125 | hundef = FALSE;
|
---|
5126 |
|
---|
5127 | if (r_extern)
|
---|
5128 | {
|
---|
5129 | h = sym_hashes[r_index];
|
---|
5130 |
|
---|
5131 | if (h != (struct aout_link_hash_entry *) NULL
|
---|
5132 | && (h->root.type == bfd_link_hash_defined
|
---|
5133 | || h->root.type == bfd_link_hash_defweak))
|
---|
5134 | {
|
---|
5135 | relocation = (h->root.u.def.value
|
---|
5136 | + h->root.u.def.section->output_section->vma
|
---|
5137 | + h->root.u.def.section->output_offset);
|
---|
5138 | }
|
---|
5139 | else if (h != (struct aout_link_hash_entry *) NULL
|
---|
5140 | && h->root.type == bfd_link_hash_undefweak)
|
---|
5141 | relocation = 0;
|
---|
5142 | else
|
---|
5143 | {
|
---|
5144 | hundef = TRUE;
|
---|
5145 | relocation = 0;
|
---|
5146 | }
|
---|
5147 | }
|
---|
5148 | else
|
---|
5149 | {
|
---|
5150 | asection *section;
|
---|
5151 |
|
---|
5152 | section = aout_reloc_index_to_section (input_bfd, r_index);
|
---|
5153 | relocation = (section->output_section->vma
|
---|
5154 | + section->output_offset
|
---|
5155 | - section->vma);
|
---|
5156 | if (r_pcrel)
|
---|
5157 | relocation += input_section->vma;
|
---|
5158 | }
|
---|
5159 |
|
---|
5160 | if (check_dynamic_reloc != NULL)
|
---|
5161 | {
|
---|
5162 | bfd_boolean skip;
|
---|
5163 |
|
---|
5164 | if (! ((*check_dynamic_reloc)
|
---|
5165 | (finfo->info, input_bfd, input_section, h,
|
---|
5166 | (PTR) rel, contents, &skip, &relocation)))
|
---|
5167 | return FALSE;
|
---|
5168 | if (skip)
|
---|
5169 | continue;
|
---|
5170 | }
|
---|
5171 |
|
---|
5172 | /* Now warn if a global symbol is undefined. We could not
|
---|
5173 | do this earlier, because check_dynamic_reloc might want
|
---|
5174 | to skip this reloc. */
|
---|
5175 | if (hundef && ! finfo->info->shared && ! r_baserel)
|
---|
5176 | {
|
---|
5177 | const char *name;
|
---|
5178 |
|
---|
5179 | if (h != NULL)
|
---|
5180 | name = h->root.root.string;
|
---|
5181 | else
|
---|
5182 | name = strings + GET_WORD (input_bfd, syms[r_index].e_strx);
|
---|
5183 | if (! ((*finfo->info->callbacks->undefined_symbol)
|
---|
5184 | (finfo->info, name, input_bfd, input_section,
|
---|
5185 | r_addr, TRUE)))
|
---|
5186 | return FALSE;
|
---|
5187 | }
|
---|
5188 |
|
---|
5189 | r = MY_final_link_relocate (howto,
|
---|
5190 | input_bfd, input_section,
|
---|
5191 | contents, r_addr, relocation,
|
---|
5192 | (bfd_vma) 0);
|
---|
5193 | }
|
---|
5194 |
|
---|
5195 | if (r != bfd_reloc_ok)
|
---|
5196 | {
|
---|
5197 | switch (r)
|
---|
5198 | {
|
---|
5199 | default:
|
---|
5200 | case bfd_reloc_outofrange:
|
---|
5201 | abort ();
|
---|
5202 | case bfd_reloc_overflow:
|
---|
5203 | {
|
---|
5204 | const char *name;
|
---|
5205 |
|
---|
5206 | if (h != NULL)
|
---|
5207 | name = h->root.root.string;
|
---|
5208 | else if (r_extern)
|
---|
5209 | name = strings + GET_WORD (input_bfd,
|
---|
5210 | syms[r_index].e_strx);
|
---|
5211 | else
|
---|
5212 | {
|
---|
5213 | asection *s;
|
---|
5214 |
|
---|
5215 | s = aout_reloc_index_to_section (input_bfd, r_index);
|
---|
5216 | name = bfd_section_name (input_bfd, s);
|
---|
5217 | }
|
---|
5218 | if (! ((*finfo->info->callbacks->reloc_overflow)
|
---|
5219 | (finfo->info, name, howto->name,
|
---|
5220 | (bfd_vma) 0, input_bfd, input_section, r_addr)))
|
---|
5221 | return FALSE;
|
---|
5222 | }
|
---|
5223 | break;
|
---|
5224 | }
|
---|
5225 | }
|
---|
5226 | }
|
---|
5227 |
|
---|
5228 | return TRUE;
|
---|
5229 | }
|
---|
5230 |
|
---|
5231 | /* Relocate an a.out section using extended a.out relocs. */
|
---|
5232 |
|
---|
5233 | static bfd_boolean
|
---|
5234 | aout_link_input_section_ext (finfo, input_bfd, input_section, relocs,
|
---|
5235 | rel_size, contents)
|
---|
5236 | struct aout_final_link_info *finfo;
|
---|
5237 | bfd *input_bfd;
|
---|
5238 | asection *input_section;
|
---|
5239 | struct reloc_ext_external *relocs;
|
---|
5240 | bfd_size_type rel_size;
|
---|
5241 | bfd_byte *contents;
|
---|
5242 | {
|
---|
5243 | bfd_boolean (*check_dynamic_reloc)
|
---|
5244 | PARAMS ((struct bfd_link_info *, bfd *, asection *,
|
---|
5245 | struct aout_link_hash_entry *, PTR, bfd_byte *, bfd_boolean *,
|
---|
5246 | bfd_vma *));
|
---|
5247 | bfd *output_bfd;
|
---|
5248 | bfd_boolean relocateable;
|
---|
5249 | struct external_nlist *syms;
|
---|
5250 | char *strings;
|
---|
5251 | struct aout_link_hash_entry **sym_hashes;
|
---|
5252 | int *symbol_map;
|
---|
5253 | bfd_size_type reloc_count;
|
---|
5254 | register struct reloc_ext_external *rel;
|
---|
5255 | struct reloc_ext_external *rel_end;
|
---|
5256 |
|
---|
5257 | output_bfd = finfo->output_bfd;
|
---|
5258 | check_dynamic_reloc = aout_backend_info (output_bfd)->check_dynamic_reloc;
|
---|
5259 |
|
---|
5260 | BFD_ASSERT (obj_reloc_entry_size (input_bfd) == RELOC_EXT_SIZE);
|
---|
5261 | BFD_ASSERT (input_bfd->xvec->header_byteorder
|
---|
5262 | == output_bfd->xvec->header_byteorder);
|
---|
5263 |
|
---|
5264 | relocateable = finfo->info->relocateable;
|
---|
5265 | syms = obj_aout_external_syms (input_bfd);
|
---|
5266 | strings = obj_aout_external_strings (input_bfd);
|
---|
5267 | sym_hashes = obj_aout_sym_hashes (input_bfd);
|
---|
5268 | symbol_map = finfo->symbol_map;
|
---|
5269 |
|
---|
5270 | reloc_count = rel_size / RELOC_EXT_SIZE;
|
---|
5271 | rel = relocs;
|
---|
5272 | rel_end = rel + reloc_count;
|
---|
5273 | for (; rel < rel_end; rel++)
|
---|
5274 | {
|
---|
5275 | bfd_vma r_addr;
|
---|
5276 | int r_index;
|
---|
5277 | int r_extern;
|
---|
5278 | unsigned int r_type;
|
---|
5279 | bfd_vma r_addend;
|
---|
5280 | struct aout_link_hash_entry *h = NULL;
|
---|
5281 | asection *r_section = NULL;
|
---|
5282 | bfd_vma relocation;
|
---|
5283 |
|
---|
5284 | r_addr = GET_SWORD (input_bfd, rel->r_address);
|
---|
5285 |
|
---|
5286 | if (bfd_header_big_endian (input_bfd))
|
---|
5287 | {
|
---|
5288 | r_index = (((unsigned int) rel->r_index[0] << 16)
|
---|
5289 | | ((unsigned int) rel->r_index[1] << 8)
|
---|
5290 | | rel->r_index[2]);
|
---|
5291 | r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_BIG));
|
---|
5292 | r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
|
---|
5293 | >> RELOC_EXT_BITS_TYPE_SH_BIG);
|
---|
5294 | }
|
---|
5295 | else
|
---|
5296 | {
|
---|
5297 | r_index = (((unsigned int) rel->r_index[2] << 16)
|
---|
5298 | | ((unsigned int) rel->r_index[1] << 8)
|
---|
5299 | | rel->r_index[0]);
|
---|
5300 | r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE));
|
---|
5301 | r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
|
---|
5302 | >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
|
---|
5303 | }
|
---|
5304 |
|
---|
5305 | r_addend = GET_SWORD (input_bfd, rel->r_addend);
|
---|
5306 |
|
---|
5307 | BFD_ASSERT (r_type < TABLE_SIZE (howto_table_ext));
|
---|
5308 |
|
---|
5309 | if (relocateable)
|
---|
5310 | {
|
---|
5311 | /* We are generating a relocateable output file, and must
|
---|
5312 | modify the reloc accordingly. */
|
---|
5313 | if (r_extern
|
---|
5314 | || r_type == (unsigned int) RELOC_BASE10
|
---|
5315 | || r_type == (unsigned int) RELOC_BASE13
|
---|
5316 | || r_type == (unsigned int) RELOC_BASE22)
|
---|
5317 | {
|
---|
5318 | /* If we know the symbol this relocation is against,
|
---|
5319 | convert it into a relocation against a section. This
|
---|
5320 | is what the native linker does. */
|
---|
5321 | if (r_type == (unsigned int) RELOC_BASE10
|
---|
5322 | || r_type == (unsigned int) RELOC_BASE13
|
---|
5323 | || r_type == (unsigned int) RELOC_BASE22)
|
---|
5324 | h = NULL;
|
---|
5325 | else
|
---|
5326 | h = sym_hashes[r_index];
|
---|
5327 | if (h != (struct aout_link_hash_entry *) NULL
|
---|
5328 | && (h->root.type == bfd_link_hash_defined
|
---|
5329 | || h->root.type == bfd_link_hash_defweak))
|
---|
5330 | {
|
---|
5331 | asection *output_section;
|
---|
5332 |
|
---|
5333 | /* Change the r_extern value. */
|
---|
5334 | if (bfd_header_big_endian (output_bfd))
|
---|
5335 | rel->r_type[0] &=~ RELOC_EXT_BITS_EXTERN_BIG;
|
---|
5336 | else
|
---|
5337 | rel->r_type[0] &=~ RELOC_EXT_BITS_EXTERN_LITTLE;
|
---|
5338 |
|
---|
5339 | /* Compute a new r_index. */
|
---|
5340 | output_section = h->root.u.def.section->output_section;
|
---|
5341 | if (output_section == obj_textsec (output_bfd))
|
---|
5342 | r_index = N_TEXT;
|
---|
5343 | else if (output_section == obj_datasec (output_bfd))
|
---|
5344 | r_index = N_DATA;
|
---|
5345 | else if (output_section == obj_bsssec (output_bfd))
|
---|
5346 | r_index = N_BSS;
|
---|
5347 | else
|
---|
5348 | r_index = N_ABS;
|
---|
5349 |
|
---|
5350 | /* Add the symbol value and the section VMA to the
|
---|
5351 | addend. */
|
---|
5352 | relocation = (h->root.u.def.value
|
---|
5353 | + output_section->vma
|
---|
5354 | + h->root.u.def.section->output_offset);
|
---|
5355 |
|
---|
5356 | /* Now RELOCATION is the VMA of the final
|
---|
5357 | destination. If this is a PC relative reloc,
|
---|
5358 | then ADDEND is the negative of the source VMA.
|
---|
5359 | We want to set ADDEND to the difference between
|
---|
5360 | the destination VMA and the source VMA, which
|
---|
5361 | means we must adjust RELOCATION by the change in
|
---|
5362 | the source VMA. This is done below. */
|
---|
5363 | }
|
---|
5364 | else
|
---|
5365 | {
|
---|
5366 | /* We must change r_index according to the symbol
|
---|
5367 | map. */
|
---|
5368 | r_index = symbol_map[r_index];
|
---|
5369 |
|
---|
5370 | if (r_index == -1)
|
---|
5371 | {
|
---|
5372 | if (h != NULL)
|
---|
5373 | {
|
---|
5374 | /* We decided to strip this symbol, but it
|
---|
5375 | turns out that we can't. Note that we
|
---|
5376 | lose the other and desc information here.
|
---|
5377 | I don't think that will ever matter for a
|
---|
5378 | global symbol. */
|
---|
5379 | if (h->indx < 0)
|
---|
5380 | {
|
---|
5381 | h->indx = -2;
|
---|
5382 | h->written = FALSE;
|
---|
5383 | if (! aout_link_write_other_symbol (h,
|
---|
5384 | (PTR) finfo))
|
---|
5385 | return FALSE;
|
---|
5386 | }
|
---|
5387 | r_index = h->indx;
|
---|
5388 | }
|
---|
5389 | else
|
---|
5390 | {
|
---|
5391 | const char *name;
|
---|
5392 |
|
---|
5393 | name = strings + GET_WORD (input_bfd,
|
---|
5394 | syms[r_index].e_strx);
|
---|
5395 | if (! ((*finfo->info->callbacks->unattached_reloc)
|
---|
5396 | (finfo->info, name, input_bfd, input_section,
|
---|
5397 | r_addr)))
|
---|
5398 | return FALSE;
|
---|
5399 | r_index = 0;
|
---|
5400 | }
|
---|
5401 | }
|
---|
5402 |
|
---|
5403 | relocation = 0;
|
---|
5404 |
|
---|
5405 | /* If this is a PC relative reloc, then the addend
|
---|
5406 | is the negative of the source VMA. We must
|
---|
5407 | adjust it by the change in the source VMA. This
|
---|
5408 | is done below. */
|
---|
5409 | }
|
---|
5410 |
|
---|
5411 | /* Write out the new r_index value. */
|
---|
5412 | if (bfd_header_big_endian (output_bfd))
|
---|
5413 | {
|
---|
5414 | rel->r_index[0] = r_index >> 16;
|
---|
5415 | rel->r_index[1] = r_index >> 8;
|
---|
5416 | rel->r_index[2] = r_index;
|
---|
5417 | }
|
---|
5418 | else
|
---|
5419 | {
|
---|
5420 | rel->r_index[2] = r_index >> 16;
|
---|
5421 | rel->r_index[1] = r_index >> 8;
|
---|
5422 | rel->r_index[0] = r_index;
|
---|
5423 | }
|
---|
5424 | }
|
---|
5425 | else
|
---|
5426 | {
|
---|
5427 | /* This is a relocation against a section. We must
|
---|
5428 | adjust by the amount that the section moved. */
|
---|
5429 | r_section = aout_reloc_index_to_section (input_bfd, r_index);
|
---|
5430 | relocation = (r_section->output_section->vma
|
---|
5431 | + r_section->output_offset
|
---|
5432 | - r_section->vma);
|
---|
5433 |
|
---|
5434 | /* If this is a PC relative reloc, then the addend is
|
---|
5435 | the difference in VMA between the destination and the
|
---|
5436 | source. We have just adjusted for the change in VMA
|
---|
5437 | of the destination, so we must also adjust by the
|
---|
5438 | change in VMA of the source. This is done below. */
|
---|
5439 | }
|
---|
5440 |
|
---|
5441 | /* As described above, we must always adjust a PC relative
|
---|
5442 | reloc by the change in VMA of the source. However, if
|
---|
5443 | pcrel_offset is set, then the addend does not include the
|
---|
5444 | location within the section, in which case we don't need
|
---|
5445 | to adjust anything. */
|
---|
5446 | if (howto_table_ext[r_type].pc_relative
|
---|
5447 | && ! howto_table_ext[r_type].pcrel_offset)
|
---|
5448 | relocation -= (input_section->output_section->vma
|
---|
5449 | + input_section->output_offset
|
---|
5450 | - input_section->vma);
|
---|
5451 |
|
---|
5452 | /* Change the addend if necessary. */
|
---|
5453 | if (relocation != 0)
|
---|
5454 | PUT_WORD (output_bfd, r_addend + relocation, rel->r_addend);
|
---|
5455 |
|
---|
5456 | /* Change the address of the relocation. */
|
---|
5457 | PUT_WORD (output_bfd,
|
---|
5458 | r_addr + input_section->output_offset,
|
---|
5459 | rel->r_address);
|
---|
5460 | }
|
---|
5461 | else
|
---|
5462 | {
|
---|
5463 | bfd_boolean hundef;
|
---|
5464 | bfd_reloc_status_type r;
|
---|
5465 |
|
---|
5466 | /* We are generating an executable, and must do a full
|
---|
5467 | relocation. */
|
---|
5468 | hundef = FALSE;
|
---|
5469 |
|
---|
5470 | if (r_extern)
|
---|
5471 | {
|
---|
5472 | h = sym_hashes[r_index];
|
---|
5473 |
|
---|
5474 | if (h != (struct aout_link_hash_entry *) NULL
|
---|
5475 | && (h->root.type == bfd_link_hash_defined
|
---|
5476 | || h->root.type == bfd_link_hash_defweak))
|
---|
5477 | {
|
---|
5478 | relocation = (h->root.u.def.value
|
---|
5479 | + h->root.u.def.section->output_section->vma
|
---|
5480 | + h->root.u.def.section->output_offset);
|
---|
5481 | }
|
---|
5482 | else if (h != (struct aout_link_hash_entry *) NULL
|
---|
5483 | && h->root.type == bfd_link_hash_undefweak)
|
---|
5484 | relocation = 0;
|
---|
5485 | else
|
---|
5486 | {
|
---|
5487 | hundef = TRUE;
|
---|
5488 | relocation = 0;
|
---|
5489 | }
|
---|
5490 | }
|
---|
5491 | else if (r_type == (unsigned int) RELOC_BASE10
|
---|
5492 | || r_type == (unsigned int) RELOC_BASE13
|
---|
5493 | || r_type == (unsigned int) RELOC_BASE22)
|
---|
5494 | {
|
---|
5495 | struct external_nlist *sym;
|
---|
5496 | int type;
|
---|
5497 |
|
---|
5498 | /* For base relative relocs, r_index is always an index
|
---|
5499 | into the symbol table, even if r_extern is 0. */
|
---|
5500 | sym = syms + r_index;
|
---|
5501 | type = H_GET_8 (input_bfd, sym->e_type);
|
---|
5502 | if ((type & N_TYPE) == N_TEXT
|
---|
5503 | || type == N_WEAKT)
|
---|
5504 | r_section = obj_textsec (input_bfd);
|
---|
5505 | else if ((type & N_TYPE) == N_DATA
|
---|
5506 | || type == N_WEAKD)
|
---|
5507 | r_section = obj_datasec (input_bfd);
|
---|
5508 | else if ((type & N_TYPE) == N_BSS
|
---|
5509 | || type == N_WEAKB)
|
---|
5510 | r_section = obj_bsssec (input_bfd);
|
---|
5511 | else if ((type & N_TYPE) == N_ABS
|
---|
5512 | || type == N_WEAKA)
|
---|
5513 | r_section = bfd_abs_section_ptr;
|
---|
5514 | else
|
---|
5515 | abort ();
|
---|
5516 | relocation = (r_section->output_section->vma
|
---|
5517 | + r_section->output_offset
|
---|
5518 | + (GET_WORD (input_bfd, sym->e_value)
|
---|
5519 | - r_section->vma));
|
---|
5520 | }
|
---|
5521 | else
|
---|
5522 | {
|
---|
5523 | r_section = aout_reloc_index_to_section (input_bfd, r_index);
|
---|
5524 |
|
---|
5525 | /* If this is a PC relative reloc, then R_ADDEND is the
|
---|
5526 | difference between the two vmas, or
|
---|
5527 | old_dest_sec + old_dest_off - (old_src_sec + old_src_off)
|
---|
5528 | where
|
---|
5529 | old_dest_sec == section->vma
|
---|
5530 | and
|
---|
5531 | old_src_sec == input_section->vma
|
---|
5532 | and
|
---|
5533 | old_src_off == r_addr
|
---|
5534 |
|
---|
5535 | _bfd_final_link_relocate expects RELOCATION +
|
---|
5536 | R_ADDEND to be the VMA of the destination minus
|
---|
5537 | r_addr (the minus r_addr is because this relocation
|
---|
5538 | is not pcrel_offset, which is a bit confusing and
|
---|
5539 | should, perhaps, be changed), or
|
---|
5540 | new_dest_sec
|
---|
5541 | where
|
---|
5542 | new_dest_sec == output_section->vma + output_offset
|
---|
5543 | We arrange for this to happen by setting RELOCATION to
|
---|
5544 | new_dest_sec + old_src_sec - old_dest_sec
|
---|
5545 |
|
---|
5546 | If this is not a PC relative reloc, then R_ADDEND is
|
---|
5547 | simply the VMA of the destination, so we set
|
---|
5548 | RELOCATION to the change in the destination VMA, or
|
---|
5549 | new_dest_sec - old_dest_sec
|
---|
5550 | */
|
---|
5551 | relocation = (r_section->output_section->vma
|
---|
5552 | + r_section->output_offset
|
---|
5553 | - r_section->vma);
|
---|
5554 | if (howto_table_ext[r_type].pc_relative)
|
---|
5555 | relocation += input_section->vma;
|
---|
5556 | }
|
---|
5557 |
|
---|
5558 | if (check_dynamic_reloc != NULL)
|
---|
5559 | {
|
---|
5560 | bfd_boolean skip;
|
---|
5561 |
|
---|
5562 | if (! ((*check_dynamic_reloc)
|
---|
5563 | (finfo->info, input_bfd, input_section, h,
|
---|
5564 | (PTR) rel, contents, &skip, &relocation)))
|
---|
5565 | return FALSE;
|
---|
5566 | if (skip)
|
---|
5567 | continue;
|
---|
5568 | }
|
---|
5569 |
|
---|
5570 | /* Now warn if a global symbol is undefined. We could not
|
---|
5571 | do this earlier, because check_dynamic_reloc might want
|
---|
5572 | to skip this reloc. */
|
---|
5573 | if (hundef
|
---|
5574 | && ! finfo->info->shared
|
---|
5575 | && r_type != (unsigned int) RELOC_BASE10
|
---|
5576 | && r_type != (unsigned int) RELOC_BASE13
|
---|
5577 | && r_type != (unsigned int) RELOC_BASE22)
|
---|
5578 | {
|
---|
5579 | const char *name;
|
---|
5580 |
|
---|
5581 | if (h != NULL)
|
---|
5582 | name = h->root.root.string;
|
---|
5583 | else
|
---|
5584 | name = strings + GET_WORD (input_bfd, syms[r_index].e_strx);
|
---|
5585 | if (! ((*finfo->info->callbacks->undefined_symbol)
|
---|
5586 | (finfo->info, name, input_bfd, input_section,
|
---|
5587 | r_addr, TRUE)))
|
---|
5588 | return FALSE;
|
---|
5589 | }
|
---|
5590 |
|
---|
5591 | if (r_type != (unsigned int) RELOC_SPARC_REV32)
|
---|
5592 | r = MY_final_link_relocate (howto_table_ext + r_type,
|
---|
5593 | input_bfd, input_section,
|
---|
5594 | contents, r_addr, relocation,
|
---|
5595 | r_addend);
|
---|
5596 | else
|
---|
5597 | {
|
---|
5598 | bfd_vma x;
|
---|
5599 |
|
---|
5600 | x = bfd_get_32 (input_bfd, contents + r_addr);
|
---|
5601 | x = x + relocation + r_addend;
|
---|
5602 | bfd_putl32 (/*input_bfd,*/ x, contents + r_addr);
|
---|
5603 | r = bfd_reloc_ok;
|
---|
5604 | }
|
---|
5605 |
|
---|
5606 | if (r != bfd_reloc_ok)
|
---|
5607 | {
|
---|
5608 | switch (r)
|
---|
5609 | {
|
---|
5610 | default:
|
---|
5611 | case bfd_reloc_outofrange:
|
---|
5612 | abort ();
|
---|
5613 | case bfd_reloc_overflow:
|
---|
5614 | {
|
---|
5615 | const char *name;
|
---|
5616 |
|
---|
5617 | if (h != NULL)
|
---|
5618 | name = h->root.root.string;
|
---|
5619 | else if (r_extern
|
---|
5620 | || r_type == (unsigned int) RELOC_BASE10
|
---|
5621 | || r_type == (unsigned int) RELOC_BASE13
|
---|
5622 | || r_type == (unsigned int) RELOC_BASE22)
|
---|
5623 | name = strings + GET_WORD (input_bfd,
|
---|
5624 | syms[r_index].e_strx);
|
---|
5625 | else
|
---|
5626 | {
|
---|
5627 | asection *s;
|
---|
5628 |
|
---|
5629 | s = aout_reloc_index_to_section (input_bfd, r_index);
|
---|
5630 | name = bfd_section_name (input_bfd, s);
|
---|
5631 | }
|
---|
5632 | if (! ((*finfo->info->callbacks->reloc_overflow)
|
---|
5633 | (finfo->info, name, howto_table_ext[r_type].name,
|
---|
5634 | r_addend, input_bfd, input_section, r_addr)))
|
---|
5635 | return FALSE;
|
---|
5636 | }
|
---|
5637 | break;
|
---|
5638 | }
|
---|
5639 | }
|
---|
5640 | }
|
---|
5641 | }
|
---|
5642 |
|
---|
5643 | return TRUE;
|
---|
5644 | }
|
---|
5645 |
|
---|
5646 | /* Handle a link order which is supposed to generate a reloc. */
|
---|
5647 |
|
---|
5648 | static bfd_boolean
|
---|
5649 | aout_link_reloc_link_order (finfo, o, p)
|
---|
5650 | struct aout_final_link_info *finfo;
|
---|
5651 | asection *o;
|
---|
5652 | struct bfd_link_order *p;
|
---|
5653 | {
|
---|
5654 | struct bfd_link_order_reloc *pr;
|
---|
5655 | int r_index;
|
---|
5656 | int r_extern;
|
---|
5657 | reloc_howto_type *howto;
|
---|
5658 | file_ptr *reloff_ptr = NULL;
|
---|
5659 | struct reloc_std_external srel;
|
---|
5660 | struct reloc_ext_external erel;
|
---|
5661 | PTR rel_ptr;
|
---|
5662 | bfd_size_type amt;
|
---|
5663 |
|
---|
5664 | pr = p->u.reloc.p;
|
---|
5665 |
|
---|
5666 | if (p->type == bfd_section_reloc_link_order)
|
---|
5667 | {
|
---|
5668 | r_extern = 0;
|
---|
5669 | if (bfd_is_abs_section (pr->u.section))
|
---|
5670 | r_index = N_ABS | N_EXT;
|
---|
5671 | else
|
---|
5672 | {
|
---|
5673 | BFD_ASSERT (pr->u.section->owner == finfo->output_bfd);
|
---|
5674 | r_index = pr->u.section->target_index;
|
---|
5675 | }
|
---|
5676 | }
|
---|
5677 | else
|
---|
5678 | {
|
---|
5679 | struct aout_link_hash_entry *h;
|
---|
5680 |
|
---|
5681 | BFD_ASSERT (p->type == bfd_symbol_reloc_link_order);
|
---|
5682 | r_extern = 1;
|
---|
5683 | h = ((struct aout_link_hash_entry *)
|
---|
5684 | bfd_wrapped_link_hash_lookup (finfo->output_bfd, finfo->info,
|
---|
5685 | pr->u.name, FALSE, FALSE, TRUE));
|
---|
5686 | if (h != (struct aout_link_hash_entry *) NULL
|
---|
5687 | && h->indx >= 0)
|
---|
5688 | r_index = h->indx;
|
---|
5689 | else if (h != NULL)
|
---|
5690 | {
|
---|
5691 | /* We decided to strip this symbol, but it turns out that we
|
---|
5692 | can't. Note that we lose the other and desc information
|
---|
5693 | here. I don't think that will ever matter for a global
|
---|
5694 | symbol. */
|
---|
5695 | h->indx = -2;
|
---|
5696 | h->written = FALSE;
|
---|
5697 | if (! aout_link_write_other_symbol (h, (PTR) finfo))
|
---|
5698 | return FALSE;
|
---|
5699 | r_index = h->indx;
|
---|
5700 | }
|
---|
5701 | else
|
---|
5702 | {
|
---|
5703 | if (! ((*finfo->info->callbacks->unattached_reloc)
|
---|
5704 | (finfo->info, pr->u.name, (bfd *) NULL,
|
---|
5705 | (asection *) NULL, (bfd_vma) 0)))
|
---|
5706 | return FALSE;
|
---|
5707 | r_index = 0;
|
---|
5708 | }
|
---|
5709 | }
|
---|
5710 |
|
---|
5711 | howto = bfd_reloc_type_lookup (finfo->output_bfd, pr->reloc);
|
---|
5712 | if (howto == 0)
|
---|
5713 | {
|
---|
5714 | bfd_set_error (bfd_error_bad_value);
|
---|
5715 | return FALSE;
|
---|
5716 | }
|
---|
5717 |
|
---|
5718 | if (o == obj_textsec (finfo->output_bfd))
|
---|
5719 | reloff_ptr = &finfo->treloff;
|
---|
5720 | else if (o == obj_datasec (finfo->output_bfd))
|
---|
5721 | reloff_ptr = &finfo->dreloff;
|
---|
5722 | else
|
---|
5723 | abort ();
|
---|
5724 |
|
---|
5725 | if (obj_reloc_entry_size (finfo->output_bfd) == RELOC_STD_SIZE)
|
---|
5726 | {
|
---|
5727 | #ifdef MY_put_reloc
|
---|
5728 | MY_put_reloc (finfo->output_bfd, r_extern, r_index, p->offset, howto,
|
---|
5729 | &srel);
|
---|
5730 | #else
|
---|
5731 | {
|
---|
5732 | int r_pcrel;
|
---|
5733 | int r_baserel;
|
---|
5734 | int r_jmptable;
|
---|
5735 | int r_relative;
|
---|
5736 | int r_length;
|
---|
5737 |
|
---|
5738 | r_pcrel = (int) howto->pc_relative;
|
---|
5739 | r_baserel = (howto->type & 8) != 0;
|
---|
5740 | r_jmptable = (howto->type & 16) != 0;
|
---|
5741 | r_relative = (howto->type & 32) != 0;
|
---|
5742 | r_length = howto->size;
|
---|
5743 |
|
---|
5744 | PUT_WORD (finfo->output_bfd, p->offset, srel.r_address);
|
---|
5745 | if (bfd_header_big_endian (finfo->output_bfd))
|
---|
5746 | {
|
---|
5747 | srel.r_index[0] = r_index >> 16;
|
---|
5748 | srel.r_index[1] = r_index >> 8;
|
---|
5749 | srel.r_index[2] = r_index;
|
---|
5750 | srel.r_type[0] =
|
---|
5751 | ((r_extern ? RELOC_STD_BITS_EXTERN_BIG : 0)
|
---|
5752 | | (r_pcrel ? RELOC_STD_BITS_PCREL_BIG : 0)
|
---|
5753 | | (r_baserel ? RELOC_STD_BITS_BASEREL_BIG : 0)
|
---|
5754 | | (r_jmptable ? RELOC_STD_BITS_JMPTABLE_BIG : 0)
|
---|
5755 | | (r_relative ? RELOC_STD_BITS_RELATIVE_BIG : 0)
|
---|
5756 | | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG));
|
---|
5757 | }
|
---|
5758 | else
|
---|
5759 | {
|
---|
5760 | srel.r_index[2] = r_index >> 16;
|
---|
5761 | srel.r_index[1] = r_index >> 8;
|
---|
5762 | srel.r_index[0] = r_index;
|
---|
5763 | srel.r_type[0] =
|
---|
5764 | ((r_extern ? RELOC_STD_BITS_EXTERN_LITTLE : 0)
|
---|
5765 | | (r_pcrel ? RELOC_STD_BITS_PCREL_LITTLE : 0)
|
---|
5766 | | (r_baserel ? RELOC_STD_BITS_BASEREL_LITTLE : 0)
|
---|
5767 | | (r_jmptable ? RELOC_STD_BITS_JMPTABLE_LITTLE : 0)
|
---|
5768 | | (r_relative ? RELOC_STD_BITS_RELATIVE_LITTLE : 0)
|
---|
5769 | | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE));
|
---|
5770 | }
|
---|
5771 | }
|
---|
5772 | #endif
|
---|
5773 | rel_ptr = (PTR) &srel;
|
---|
5774 |
|
---|
5775 | /* We have to write the addend into the object file, since
|
---|
5776 | standard a.out relocs are in place. It would be more
|
---|
5777 | reliable if we had the current contents of the file here,
|
---|
5778 | rather than assuming zeroes, but we can't read the file since
|
---|
5779 | it was opened using bfd_openw. */
|
---|
5780 | if (pr->addend != 0)
|
---|
5781 | {
|
---|
5782 | bfd_size_type size;
|
---|
5783 | bfd_reloc_status_type r;
|
---|
5784 | bfd_byte *buf;
|
---|
5785 | bfd_boolean ok;
|
---|
5786 |
|
---|
5787 | size = bfd_get_reloc_size (howto);
|
---|
5788 | buf = (bfd_byte *) bfd_zmalloc (size);
|
---|
5789 | if (buf == (bfd_byte *) NULL)
|
---|
5790 | return FALSE;
|
---|
5791 | r = MY_relocate_contents (howto, finfo->output_bfd,
|
---|
5792 | (bfd_vma) pr->addend, buf);
|
---|
5793 | switch (r)
|
---|
5794 | {
|
---|
5795 | case bfd_reloc_ok:
|
---|
5796 | break;
|
---|
5797 | default:
|
---|
5798 | case bfd_reloc_outofrange:
|
---|
5799 | abort ();
|
---|
5800 | case bfd_reloc_overflow:
|
---|
5801 | if (! ((*finfo->info->callbacks->reloc_overflow)
|
---|
5802 | (finfo->info,
|
---|
5803 | (p->type == bfd_section_reloc_link_order
|
---|
5804 | ? bfd_section_name (finfo->output_bfd,
|
---|
5805 | pr->u.section)
|
---|
5806 | : pr->u.name),
|
---|
5807 | howto->name, pr->addend, (bfd *) NULL,
|
---|
5808 | (asection *) NULL, (bfd_vma) 0)))
|
---|
5809 | {
|
---|
5810 | free (buf);
|
---|
5811 | return FALSE;
|
---|
5812 | }
|
---|
5813 | break;
|
---|
5814 | }
|
---|
5815 | ok = bfd_set_section_contents (finfo->output_bfd, o, (PTR) buf,
|
---|
5816 | (file_ptr) p->offset, size);
|
---|
5817 | free (buf);
|
---|
5818 | if (! ok)
|
---|
5819 | return FALSE;
|
---|
5820 | }
|
---|
5821 | }
|
---|
5822 | else
|
---|
5823 | {
|
---|
5824 | #ifdef MY_put_ext_reloc
|
---|
5825 | MY_put_ext_reloc (finfo->output_bfd, r_extern, r_index, p->offset,
|
---|
5826 | howto, &erel, pr->addend);
|
---|
5827 | #else
|
---|
5828 | PUT_WORD (finfo->output_bfd, p->offset, erel.r_address);
|
---|
5829 |
|
---|
5830 | if (bfd_header_big_endian (finfo->output_bfd))
|
---|
5831 | {
|
---|
5832 | erel.r_index[0] = r_index >> 16;
|
---|
5833 | erel.r_index[1] = r_index >> 8;
|
---|
5834 | erel.r_index[2] = r_index;
|
---|
5835 | erel.r_type[0] =
|
---|
5836 | ((r_extern ? RELOC_EXT_BITS_EXTERN_BIG : 0)
|
---|
5837 | | (howto->type << RELOC_EXT_BITS_TYPE_SH_BIG));
|
---|
5838 | }
|
---|
5839 | else
|
---|
5840 | {
|
---|
5841 | erel.r_index[2] = r_index >> 16;
|
---|
5842 | erel.r_index[1] = r_index >> 8;
|
---|
5843 | erel.r_index[0] = r_index;
|
---|
5844 | erel.r_type[0] =
|
---|
5845 | (r_extern ? RELOC_EXT_BITS_EXTERN_LITTLE : 0)
|
---|
5846 | | (howto->type << RELOC_EXT_BITS_TYPE_SH_LITTLE);
|
---|
5847 | }
|
---|
5848 |
|
---|
5849 | PUT_WORD (finfo->output_bfd, (bfd_vma) pr->addend, erel.r_addend);
|
---|
5850 | #endif /* MY_put_ext_reloc */
|
---|
5851 |
|
---|
5852 | rel_ptr = (PTR) &erel;
|
---|
5853 | }
|
---|
5854 |
|
---|
5855 | amt = obj_reloc_entry_size (finfo->output_bfd);
|
---|
5856 | if (bfd_seek (finfo->output_bfd, *reloff_ptr, SEEK_SET) != 0
|
---|
5857 | || bfd_bwrite (rel_ptr, amt, finfo->output_bfd) != amt)
|
---|
5858 | return FALSE;
|
---|
5859 |
|
---|
5860 | *reloff_ptr += obj_reloc_entry_size (finfo->output_bfd);
|
---|
5861 |
|
---|
5862 | /* Assert that the relocs have not run into the symbols, and that n
|
---|
5863 | the text relocs have not run into the data relocs. */
|
---|
5864 | BFD_ASSERT (*reloff_ptr <= obj_sym_filepos (finfo->output_bfd)
|
---|
5865 | && (reloff_ptr != &finfo->treloff
|
---|
5866 | || (*reloff_ptr
|
---|
5867 | <= obj_datasec (finfo->output_bfd)->rel_filepos)));
|
---|
5868 |
|
---|
5869 | return TRUE;
|
---|
5870 | }
|
---|