/src/binutils-gdb/bfd/aoutx.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* BFD semi-generic back-end for a.out binaries. |
2 | | Copyright (C) 1990-2025 Free Software Foundation, Inc. |
3 | | Written by Cygnus Support. |
4 | | |
5 | | This file is part of BFD, the Binary File Descriptor library. |
6 | | |
7 | | This program is free software; you can redistribute it and/or modify |
8 | | it under the terms of the GNU General Public License as published by |
9 | | the Free Software Foundation; either version 3 of the License, or |
10 | | (at your option) any later version. |
11 | | |
12 | | This program is distributed in the hope that it will be useful, |
13 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | GNU General Public License for more details. |
16 | | |
17 | | You should have received a copy of the GNU General Public License |
18 | | along with this program; if not, write to the Free Software |
19 | | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
20 | | MA 02110-1301, USA. */ |
21 | | |
22 | | /* |
23 | | SECTION |
24 | | a.out backends |
25 | | |
26 | | DESCRIPTION |
27 | | |
28 | | BFD supports a number of different flavours of a.out format, |
29 | | though the major differences are only the sizes of the |
30 | | structures on disk, and the shape of the relocation |
31 | | information. |
32 | | |
33 | | The support is split into a basic support file @file{aoutx.h} |
34 | | and other files which derive functions from the base. One |
35 | | derivation file is @file{aoutf1.h} (for a.out flavour 1), and |
36 | | adds to the basic a.out functions support for sun3, sun4, and |
37 | | 386 a.out files, to create a target jump vector for a specific |
38 | | target. |
39 | | |
40 | | This information is further split out into more specific files |
41 | | for each machine, including @file{sunos.c} for sun3 and sun4, |
42 | | and @file{demo64.c} for a demonstration of a 64 bit a.out format. |
43 | | |
44 | | The base file @file{aoutx.h} defines general mechanisms for |
45 | | reading and writing records to and from disk and various |
46 | | other methods which BFD requires. It is included by |
47 | | @file{aout32.c} and @file{aout64.c} to form the names |
48 | | <<aout_32_swap_exec_header_in>>, <<aout_64_swap_exec_header_in>>, etc. |
49 | | |
50 | | As an example, this is what goes on to make the back end for a |
51 | | sun4, from @file{aout32.c}: |
52 | | |
53 | | | #define ARCH_SIZE 32 |
54 | | | #include "aoutx.h" |
55 | | |
56 | | Which exports names: |
57 | | |
58 | | | ... |
59 | | | aout_32_canonicalize_reloc |
60 | | | aout_32_find_nearest_line |
61 | | | aout_32_get_lineno |
62 | | | aout_32_get_reloc_upper_bound |
63 | | | ... |
64 | | |
65 | | from @file{sunos.c}: |
66 | | |
67 | | | #define TARGET_NAME "a.out-sunos-big" |
68 | | | #define VECNAME sparc_aout_sunos_be_vec |
69 | | | #include "aoutf1.h" |
70 | | |
71 | | requires all the names from @file{aout32.c}, and produces the jump vector |
72 | | |
73 | | | sparc_aout_sunos_be_vec |
74 | | |
75 | | The file @file{host-aout.c} is a special case. It is for a large set |
76 | | of hosts that use ``more or less standard'' a.out files, and |
77 | | for which cross-debugging is not interesting. It uses the |
78 | | standard 32-bit a.out support routines, but determines the |
79 | | file offsets and addresses of the text, data, and BSS |
80 | | sections, the machine architecture and machine type, and the |
81 | | entry point address, in a host-dependent manner. Once these |
82 | | values have been determined, generic code is used to handle |
83 | | the object file. |
84 | | |
85 | | When porting it to run on a new system, you must supply: |
86 | | |
87 | | | HOST_PAGE_SIZE |
88 | | | HOST_SEGMENT_SIZE |
89 | | | HOST_MACHINE_ARCH (optional) |
90 | | | HOST_MACHINE_MACHINE (optional) |
91 | | | HOST_TEXT_START_ADDR |
92 | | | HOST_STACK_END_ADDR |
93 | | |
94 | | in the file @file{../include/sys/h-@var{XXX}.h} (for your host). These |
95 | | values, plus the structures and macros defined in @file{a.out.h} on |
96 | | your host system, will produce a BFD target that will access |
97 | | ordinary a.out files on your host. To configure a new machine |
98 | | to use @file{host-aout.c}, specify: |
99 | | |
100 | | | TDEFAULTS = -DDEFAULT_VECTOR=host_aout_big_vec |
101 | | | TDEPFILES= host-aout.o trad-core.o |
102 | | |
103 | | in the @file{config/@var{XXX}.mt} file, and modify @file{configure.ac} |
104 | | to use the |
105 | | @file{@var{XXX}.mt} file (by setting "<<bfd_target=XXX>>") when your |
106 | | configuration is selected. */ |
107 | | |
108 | | /* Some assumptions: |
109 | | * Any BFD with D_PAGED set is ZMAGIC, and vice versa. |
110 | | Doesn't matter what the setting of WP_TEXT is on output, but it'll |
111 | | get set on input. |
112 | | * Any BFD with D_PAGED clear and WP_TEXT set is NMAGIC. |
113 | | * Any BFD with both flags clear is OMAGIC. |
114 | | (Just want to make these explicit, so the conditions tested in this |
115 | | file make sense if you're more familiar with a.out than with BFD.) */ |
116 | | |
117 | 9.61k | #define KEEPIT udata.i |
118 | | |
119 | | #include "sysdep.h" |
120 | | #include <limits.h> |
121 | | #include "bfd.h" |
122 | | #include "safe-ctype.h" |
123 | | #include "bfdlink.h" |
124 | | |
125 | | #include "libaout.h" |
126 | | #include "libbfd.h" |
127 | | #include "aout/aout64.h" |
128 | | #include "aout/stab_gnu.h" |
129 | | #include "aout/ar.h" |
130 | | |
131 | | #ifdef BMAGIC |
132 | 0 | #define N_IS_BMAGIC(x) (N_MAGIC (x) == BMAGIC) |
133 | | #else |
134 | | #define N_IS_BMAGIC(x) (0) |
135 | | #endif |
136 | | |
137 | | #ifdef QMAGIC |
138 | 1 | #define N_SET_QMAGIC(x) N_SET_MAGIC (x, QMAGIC) |
139 | | #else |
140 | | #define N_SET_QMAGIC(x) do { /**/ } while (0) |
141 | | #endif |
142 | | |
143 | | /* |
144 | | SUBSECTION |
145 | | Relocations |
146 | | |
147 | | DESCRIPTION |
148 | | The file @file{aoutx.h} provides for both the @emph{standard} |
149 | | and @emph{extended} forms of a.out relocation records. |
150 | | |
151 | | The standard records contain only an address, a symbol index, |
152 | | and a type field. The extended records also have a full |
153 | | integer for an addend. */ |
154 | | |
155 | | #ifndef CTOR_TABLE_RELOC_HOWTO |
156 | | #define CTOR_TABLE_RELOC_IDX 2 |
157 | | #define CTOR_TABLE_RELOC_HOWTO(BFD) \ |
158 | | ((obj_reloc_entry_size (BFD) == RELOC_EXT_SIZE \ |
159 | | ? howto_table_ext : howto_table_std) \ |
160 | | + CTOR_TABLE_RELOC_IDX) |
161 | | #endif |
162 | | |
163 | | #ifndef MY_swap_std_reloc_in |
164 | 3.04k | #define MY_swap_std_reloc_in NAME (aout, swap_std_reloc_in) |
165 | | #endif |
166 | | |
167 | | #ifndef MY_swap_ext_reloc_in |
168 | 0 | #define MY_swap_ext_reloc_in NAME (aout, swap_ext_reloc_in) |
169 | | #endif |
170 | | |
171 | | #ifndef MY_swap_std_reloc_out |
172 | 28 | #define MY_swap_std_reloc_out NAME (aout, swap_std_reloc_out) |
173 | | #endif |
174 | | |
175 | | #ifndef MY_swap_ext_reloc_out |
176 | 0 | #define MY_swap_ext_reloc_out NAME (aout, swap_ext_reloc_out) |
177 | | #endif |
178 | | |
179 | | #ifndef MY_final_link_relocate |
180 | 0 | #define MY_final_link_relocate _bfd_final_link_relocate |
181 | | #endif |
182 | | |
183 | | #ifndef MY_relocate_contents |
184 | 0 | #define MY_relocate_contents _bfd_relocate_contents |
185 | | #endif |
186 | | |
187 | 0 | #define howto_table_ext NAME (aout, ext_howto_table) |
188 | 2.33k | #define howto_table_std NAME (aout, std_howto_table) |
189 | | |
190 | | reloc_howto_type howto_table_ext[] = |
191 | | { |
192 | | /* Type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone. */ |
193 | | HOWTO (RELOC_8, 0, 1, 8, false, 0, complain_overflow_bitfield, 0, "8", false, 0, 0x000000ff, false), |
194 | | HOWTO (RELOC_16, 0, 2, 16, false, 0, complain_overflow_bitfield, 0, "16", false, 0, 0x0000ffff, false), |
195 | | HOWTO (RELOC_32, 0, 4, 32, false, 0, complain_overflow_bitfield, 0, "32", false, 0, 0xffffffff, false), |
196 | | HOWTO (RELOC_DISP8, 0, 1, 8, true, 0, complain_overflow_signed, 0, "DISP8", false, 0, 0x000000ff, false), |
197 | | HOWTO (RELOC_DISP16, 0, 2, 16, true, 0, complain_overflow_signed, 0, "DISP16", false, 0, 0x0000ffff, false), |
198 | | HOWTO (RELOC_DISP32, 0, 4, 32, true, 0, complain_overflow_signed, 0, "DISP32", false, 0, 0xffffffff, false), |
199 | | HOWTO (RELOC_WDISP30, 2, 4, 30, true, 0, complain_overflow_signed, 0, "WDISP30", false, 0, 0x3fffffff, false), |
200 | | HOWTO (RELOC_WDISP22, 2, 4, 22, true, 0, complain_overflow_signed, 0, "WDISP22", false, 0, 0x003fffff, false), |
201 | | HOWTO (RELOC_HI22, 10, 4, 22, false, 0, complain_overflow_bitfield, 0, "HI22", false, 0, 0x003fffff, false), |
202 | | HOWTO (RELOC_22, 0, 4, 22, false, 0, complain_overflow_bitfield, 0, "22", false, 0, 0x003fffff, false), |
203 | | HOWTO (RELOC_13, 0, 4, 13, false, 0, complain_overflow_bitfield, 0, "13", false, 0, 0x00001fff, false), |
204 | | HOWTO (RELOC_LO10, 0, 4, 10, false, 0, complain_overflow_dont, 0, "LO10", false, 0, 0x000003ff, false), |
205 | | HOWTO (RELOC_SFA_BASE,0, 4, 32, false, 0, complain_overflow_bitfield, 0, "SFA_BASE", false, 0, 0xffffffff, false), |
206 | | HOWTO (RELOC_SFA_OFF13,0, 4, 32, false, 0, complain_overflow_bitfield, 0, "SFA_OFF13", false, 0, 0xffffffff, false), |
207 | | HOWTO (RELOC_BASE10, 0, 4, 10, false, 0, complain_overflow_dont, 0, "BASE10", false, 0, 0x000003ff, false), |
208 | | HOWTO (RELOC_BASE13, 0, 4, 13, false, 0, complain_overflow_signed, 0, "BASE13", false, 0, 0x00001fff, false), |
209 | | HOWTO (RELOC_BASE22, 10, 4, 22, false, 0, complain_overflow_bitfield, 0, "BASE22", false, 0, 0x003fffff, false), |
210 | | HOWTO (RELOC_PC10, 0, 4, 10, true, 0, complain_overflow_dont, 0, "PC10", false, 0, 0x000003ff, true), |
211 | | HOWTO (RELOC_PC22, 10, 4, 22, true, 0, complain_overflow_signed, 0, "PC22", false, 0, 0x003fffff, true), |
212 | | HOWTO (RELOC_JMP_TBL, 2, 4, 30, true, 0, complain_overflow_signed, 0, "JMP_TBL", false, 0, 0x3fffffff, false), |
213 | | HOWTO (RELOC_SEGOFF16,0, 4, 0, false, 0, complain_overflow_bitfield, 0, "SEGOFF16", false, 0, 0x00000000, false), |
214 | | HOWTO (RELOC_GLOB_DAT,0, 4, 0, false, 0, complain_overflow_bitfield, 0, "GLOB_DAT", false, 0, 0x00000000, false), |
215 | | HOWTO (RELOC_JMP_SLOT,0, 4, 0, false, 0, complain_overflow_bitfield, 0, "JMP_SLOT", false, 0, 0x00000000, false), |
216 | | HOWTO (RELOC_RELATIVE,0, 4, 0, false, 0, complain_overflow_bitfield, 0, "RELATIVE", false, 0, 0x00000000, false), |
217 | | HOWTO (0, 0, 0, 0, false, 0, complain_overflow_dont, 0, "R_SPARC_NONE",false, 0, 0x00000000, true), |
218 | | HOWTO (0, 0, 0, 0, false, 0, complain_overflow_dont, 0, "R_SPARC_NONE",false, 0, 0x00000000, true), |
219 | 0 | #define RELOC_SPARC_REV32 RELOC_WDISP19 |
220 | | HOWTO (RELOC_SPARC_REV32, 0, 4, 32, false, 0, complain_overflow_dont, 0,"R_SPARC_REV32",false, 0, 0xffffffff, false), |
221 | | }; |
222 | | |
223 | | /* Convert standard reloc records to "arelent" format (incl byte swap). */ |
224 | | |
225 | | reloc_howto_type howto_table_std[] = |
226 | | { |
227 | | /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone. */ |
228 | | HOWTO ( 0, 0, 1, 8, false, 0, complain_overflow_bitfield,0,"8", true, 0x000000ff,0x000000ff, false), |
229 | | HOWTO ( 1, 0, 2, 16, false, 0, complain_overflow_bitfield,0,"16", true, 0x0000ffff,0x0000ffff, false), |
230 | | HOWTO ( 2, 0, 4, 32, false, 0, complain_overflow_bitfield,0,"32", true, 0xffffffff,0xffffffff, false), |
231 | | HOWTO ( 3, 0, 8, 64, false, 0, complain_overflow_bitfield,0,"64", true, 0xdeaddead,0xdeaddead, false), |
232 | | HOWTO ( 4, 0, 1, 8, true, 0, complain_overflow_signed, 0,"DISP8", true, 0x000000ff,0x000000ff, false), |
233 | | HOWTO ( 5, 0, 2, 16, true, 0, complain_overflow_signed, 0,"DISP16", true, 0x0000ffff,0x0000ffff, false), |
234 | | HOWTO ( 6, 0, 4, 32, true, 0, complain_overflow_signed, 0,"DISP32", true, 0xffffffff,0xffffffff, false), |
235 | | HOWTO ( 7, 0, 8, 64, true, 0, complain_overflow_signed, 0,"DISP64", true, 0xfeedface,0xfeedface, false), |
236 | | HOWTO ( 8, 0, 4, 0, false, 0, complain_overflow_bitfield,0,"GOT_REL", false, 0,0x00000000, false), |
237 | | HOWTO ( 9, 0, 2, 16, false, 0, complain_overflow_bitfield,0,"BASE16", false,0xffffffff,0xffffffff, false), |
238 | | HOWTO (10, 0, 4, 32, false, 0, complain_overflow_bitfield,0,"BASE32", false,0xffffffff,0xffffffff, false), |
239 | | EMPTY_HOWTO (-1), |
240 | | EMPTY_HOWTO (-1), |
241 | | EMPTY_HOWTO (-1), |
242 | | EMPTY_HOWTO (-1), |
243 | | EMPTY_HOWTO (-1), |
244 | | HOWTO (16, 0, 4, 0, false, 0, complain_overflow_bitfield,0,"JMP_TABLE", false, 0,0x00000000, false), |
245 | | EMPTY_HOWTO (-1), |
246 | | EMPTY_HOWTO (-1), |
247 | | EMPTY_HOWTO (-1), |
248 | | EMPTY_HOWTO (-1), |
249 | | EMPTY_HOWTO (-1), |
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 | | HOWTO (32, 0, 4, 0, false, 0, complain_overflow_bitfield,0,"RELATIVE", false, 0,0x00000000, false), |
261 | | EMPTY_HOWTO (-1), |
262 | | EMPTY_HOWTO (-1), |
263 | | EMPTY_HOWTO (-1), |
264 | | EMPTY_HOWTO (-1), |
265 | | EMPTY_HOWTO (-1), |
266 | | EMPTY_HOWTO (-1), |
267 | | EMPTY_HOWTO (-1), |
268 | | HOWTO (40, 0, 4, 0, false, 0, complain_overflow_bitfield,0,"BASEREL", false, 0,0x00000000, false), |
269 | | }; |
270 | | |
271 | 3.04k | #define TABLE_SIZE(TABLE) (sizeof (TABLE) / sizeof (TABLE[0])) |
272 | | |
273 | | reloc_howto_type * |
274 | | NAME (aout, reloc_type_lookup) (bfd *abfd, bfd_reloc_code_real_type code) |
275 | 0 | { |
276 | 0 | #define EXT(i, j) case i: return & howto_table_ext [j] |
277 | 0 | #define STD(i, j) case i: return & howto_table_std [j] |
278 | 0 | int ext = obj_reloc_entry_size (abfd) == RELOC_EXT_SIZE; |
279 | |
|
280 | 0 | if (code == BFD_RELOC_CTOR) |
281 | 0 | switch (bfd_arch_bits_per_address (abfd)) |
282 | 0 | { |
283 | 0 | case 32: |
284 | 0 | code = BFD_RELOC_32; |
285 | 0 | break; |
286 | 0 | case 64: |
287 | 0 | code = BFD_RELOC_64; |
288 | 0 | break; |
289 | 0 | } |
290 | | |
291 | 0 | if (ext) |
292 | 0 | switch (code) |
293 | 0 | { |
294 | 0 | EXT (BFD_RELOC_8, 0); |
295 | 0 | EXT (BFD_RELOC_16, 1); |
296 | 0 | EXT (BFD_RELOC_32, 2); |
297 | 0 | EXT (BFD_RELOC_HI22, 8); |
298 | 0 | EXT (BFD_RELOC_LO10, 11); |
299 | 0 | EXT (BFD_RELOC_32_PCREL_S2, 6); |
300 | 0 | EXT (BFD_RELOC_SPARC_WDISP22, 7); |
301 | 0 | EXT (BFD_RELOC_SPARC13, 10); |
302 | 0 | EXT (BFD_RELOC_SPARC_GOT10, 14); |
303 | 0 | EXT (BFD_RELOC_SPARC_BASE13, 15); |
304 | 0 | EXT (BFD_RELOC_SPARC_GOT13, 15); |
305 | 0 | EXT (BFD_RELOC_SPARC_GOT22, 16); |
306 | 0 | EXT (BFD_RELOC_SPARC_PC10, 17); |
307 | 0 | EXT (BFD_RELOC_SPARC_PC22, 18); |
308 | 0 | EXT (BFD_RELOC_SPARC_WPLT30, 19); |
309 | 0 | EXT (BFD_RELOC_SPARC_REV32, 26); |
310 | 0 | default: |
311 | 0 | return NULL; |
312 | 0 | } |
313 | 0 | else |
314 | | /* std relocs. */ |
315 | 0 | switch (code) |
316 | 0 | { |
317 | 0 | STD (BFD_RELOC_8, 0); |
318 | 0 | STD (BFD_RELOC_16, 1); |
319 | 0 | STD (BFD_RELOC_32, 2); |
320 | 0 | STD (BFD_RELOC_8_PCREL, 4); |
321 | 0 | STD (BFD_RELOC_16_PCREL, 5); |
322 | 0 | STD (BFD_RELOC_32_PCREL, 6); |
323 | 0 | STD (BFD_RELOC_16_BASEREL, 9); |
324 | 0 | STD (BFD_RELOC_32_BASEREL, 10); |
325 | 0 | default: |
326 | 0 | return NULL; |
327 | 0 | } |
328 | 0 | } Unexecuted instantiation: cris_aout_32_reloc_type_lookup Unexecuted instantiation: ns32kaout_32_reloc_type_lookup Unexecuted instantiation: aout_32_reloc_type_lookup |
329 | | |
330 | | reloc_howto_type * |
331 | | NAME (aout, reloc_name_lookup) (bfd *abfd, const char *r_name) |
332 | 0 | { |
333 | 0 | unsigned int i, size; |
334 | 0 | reloc_howto_type *howto_table; |
335 | |
|
336 | 0 | if (obj_reloc_entry_size (abfd) == RELOC_EXT_SIZE) |
337 | 0 | { |
338 | 0 | howto_table = howto_table_ext; |
339 | 0 | size = sizeof (howto_table_ext) / sizeof (howto_table_ext[0]); |
340 | 0 | } |
341 | 0 | else |
342 | 0 | { |
343 | 0 | howto_table = howto_table_std; |
344 | 0 | size = sizeof (howto_table_std) / sizeof (howto_table_std[0]); |
345 | 0 | } |
346 | |
|
347 | 0 | for (i = 0; i < size; i++) |
348 | 0 | if (howto_table[i].name != NULL |
349 | 0 | && strcasecmp (howto_table[i].name, r_name) == 0) |
350 | 0 | return &howto_table[i]; |
351 | | |
352 | 0 | return NULL; |
353 | 0 | } Unexecuted instantiation: cris_aout_32_reloc_name_lookup Unexecuted instantiation: ns32kaout_32_reloc_name_lookup Unexecuted instantiation: aout_32_reloc_name_lookup |
354 | | |
355 | | /* |
356 | | SUBSECTION |
357 | | Internal entry points |
358 | | |
359 | | DESCRIPTION |
360 | | @file{aoutx.h} exports several routines for accessing the |
361 | | contents of an a.out file, which are gathered and exported in |
362 | | turn by various format specific files (eg sunos.c). |
363 | | */ |
364 | | |
365 | | /* |
366 | | FUNCTION |
367 | | aout_@var{size}_swap_exec_header_in |
368 | | |
369 | | SYNOPSIS |
370 | | void aout_@var{size}_swap_exec_header_in, |
371 | | (bfd *abfd, |
372 | | struct external_exec *bytes, |
373 | | struct internal_exec *execp); |
374 | | |
375 | | DESCRIPTION |
376 | | Swap the information in an executable header @var{raw_bytes} taken |
377 | | from a raw byte stream memory image into the internal exec header |
378 | | structure @var{execp}. |
379 | | */ |
380 | | |
381 | | #ifndef NAME_swap_exec_header_in |
382 | | void |
383 | | NAME (aout, swap_exec_header_in) (bfd *abfd, |
384 | | struct external_exec *bytes, |
385 | | struct internal_exec *execp) |
386 | 80.6k | { |
387 | | /* The internal_exec structure has some fields that are unused in this |
388 | | configuration (IE for i960), so ensure that all such uninitialized |
389 | | fields are zero'd out. There are places where two of these structs |
390 | | are memcmp'd, and thus the contents do matter. */ |
391 | 80.6k | memset ((void *) execp, 0, sizeof (struct internal_exec)); |
392 | | /* Now fill in fields in the execp, from the bytes in the raw data. */ |
393 | 80.6k | execp->a_info = H_GET_32 (abfd, bytes->e_info); |
394 | 80.6k | execp->a_text = GET_WORD (abfd, bytes->e_text); |
395 | 80.6k | execp->a_data = GET_WORD (abfd, bytes->e_data); |
396 | 80.6k | execp->a_bss = GET_WORD (abfd, bytes->e_bss); |
397 | 80.6k | execp->a_syms = GET_WORD (abfd, bytes->e_syms); |
398 | 80.6k | execp->a_entry = GET_WORD (abfd, bytes->e_entry); |
399 | 80.6k | execp->a_trsize = GET_WORD (abfd, bytes->e_trsize); |
400 | 80.6k | execp->a_drsize = GET_WORD (abfd, bytes->e_drsize); |
401 | 80.6k | } cris_aout_32_swap_exec_header_in Line | Count | Source | 386 | 5.72k | { | 387 | | /* The internal_exec structure has some fields that are unused in this | 388 | | configuration (IE for i960), so ensure that all such uninitialized | 389 | | fields are zero'd out. There are places where two of these structs | 390 | | are memcmp'd, and thus the contents do matter. */ | 391 | 5.72k | memset ((void *) execp, 0, sizeof (struct internal_exec)); | 392 | | /* Now fill in fields in the execp, from the bytes in the raw data. */ | 393 | 5.72k | execp->a_info = H_GET_32 (abfd, bytes->e_info); | 394 | 5.72k | execp->a_text = GET_WORD (abfd, bytes->e_text); | 395 | 5.72k | execp->a_data = GET_WORD (abfd, bytes->e_data); | 396 | 5.72k | execp->a_bss = GET_WORD (abfd, bytes->e_bss); | 397 | 5.72k | execp->a_syms = GET_WORD (abfd, bytes->e_syms); | 398 | 5.72k | execp->a_entry = GET_WORD (abfd, bytes->e_entry); | 399 | 5.72k | execp->a_trsize = GET_WORD (abfd, bytes->e_trsize); | 400 | 5.72k | execp->a_drsize = GET_WORD (abfd, bytes->e_drsize); | 401 | 5.72k | } |
ns32kaout_32_swap_exec_header_in Line | Count | Source | 386 | 25.2k | { | 387 | | /* The internal_exec structure has some fields that are unused in this | 388 | | configuration (IE for i960), so ensure that all such uninitialized | 389 | | fields are zero'd out. There are places where two of these structs | 390 | | are memcmp'd, and thus the contents do matter. */ | 391 | 25.2k | memset ((void *) execp, 0, sizeof (struct internal_exec)); | 392 | | /* Now fill in fields in the execp, from the bytes in the raw data. */ | 393 | 25.2k | execp->a_info = H_GET_32 (abfd, bytes->e_info); | 394 | 25.2k | execp->a_text = GET_WORD (abfd, bytes->e_text); | 395 | 25.2k | execp->a_data = GET_WORD (abfd, bytes->e_data); | 396 | 25.2k | execp->a_bss = GET_WORD (abfd, bytes->e_bss); | 397 | 25.2k | execp->a_syms = GET_WORD (abfd, bytes->e_syms); | 398 | 25.2k | execp->a_entry = GET_WORD (abfd, bytes->e_entry); | 399 | 25.2k | execp->a_trsize = GET_WORD (abfd, bytes->e_trsize); | 400 | 25.2k | execp->a_drsize = GET_WORD (abfd, bytes->e_drsize); | 401 | 25.2k | } |
aout_32_swap_exec_header_in Line | Count | Source | 386 | 49.7k | { | 387 | | /* The internal_exec structure has some fields that are unused in this | 388 | | configuration (IE for i960), so ensure that all such uninitialized | 389 | | fields are zero'd out. There are places where two of these structs | 390 | | are memcmp'd, and thus the contents do matter. */ | 391 | 49.7k | memset ((void *) execp, 0, sizeof (struct internal_exec)); | 392 | | /* Now fill in fields in the execp, from the bytes in the raw data. */ | 393 | 49.7k | execp->a_info = H_GET_32 (abfd, bytes->e_info); | 394 | 49.7k | execp->a_text = GET_WORD (abfd, bytes->e_text); | 395 | 49.7k | execp->a_data = GET_WORD (abfd, bytes->e_data); | 396 | 49.7k | execp->a_bss = GET_WORD (abfd, bytes->e_bss); | 397 | 49.7k | execp->a_syms = GET_WORD (abfd, bytes->e_syms); | 398 | 49.7k | execp->a_entry = GET_WORD (abfd, bytes->e_entry); | 399 | 49.7k | execp->a_trsize = GET_WORD (abfd, bytes->e_trsize); | 400 | 49.7k | execp->a_drsize = GET_WORD (abfd, bytes->e_drsize); | 401 | 49.7k | } |
|
402 | | #define NAME_swap_exec_header_in NAME (aout, swap_exec_header_in) |
403 | | #endif |
404 | | |
405 | | /* |
406 | | FUNCTION |
407 | | aout_@var{size}_swap_exec_header_out |
408 | | |
409 | | SYNOPSIS |
410 | | bool aout_@var{size}_swap_exec_header_out |
411 | | (bfd *abfd, |
412 | | struct internal_exec *execp, |
413 | | struct external_exec *raw_bytes); |
414 | | |
415 | | DESCRIPTION |
416 | | Swap the information in an internal exec header structure |
417 | | @var{execp} into the buffer @var{raw_bytes} ready for writing to disk. |
418 | | */ |
419 | | bool |
420 | | NAME (aout, swap_exec_header_out) (bfd *abfd, |
421 | | struct internal_exec *execp, |
422 | | struct external_exec *bytes) |
423 | 4 | { |
424 | 4 | const char *err = NULL; |
425 | 4 | uint64_t val; |
426 | 28 | #define MAXVAL(x) ((UINT64_C (1) << (8 * sizeof (x) - 1) << 1) - 1) |
427 | 4 | if ((val = execp->a_text) > MAXVAL (bytes->e_text)) |
428 | 0 | err = "e_text"; |
429 | 4 | else if ((val = execp->a_data) > MAXVAL (bytes->e_data)) |
430 | 0 | err = "e_data"; |
431 | 4 | else if ((val = execp->a_bss) > MAXVAL (bytes->e_bss)) |
432 | 0 | err = "e_bss"; |
433 | 4 | else if ((val = execp->a_syms) > MAXVAL (bytes->e_syms)) |
434 | 0 | err = "e_syms"; |
435 | 4 | else if ((val = execp->a_entry) > MAXVAL (bytes->e_entry)) |
436 | 0 | err = "e_entry"; |
437 | 4 | else if ((val = execp->a_trsize) > MAXVAL (bytes->e_trsize)) |
438 | 0 | err = "e_trsize"; |
439 | 4 | else if ((val = execp->a_drsize) > MAXVAL (bytes->e_drsize)) |
440 | 0 | err = "e_drsize"; |
441 | 4 | #undef MAXVAL |
442 | 4 | if (err) |
443 | 0 | { |
444 | 0 | _bfd_error_handler (_("%pB: %#" PRIx64 " overflows header %s field"), |
445 | 0 | abfd, val, err); |
446 | 0 | bfd_set_error (bfd_error_file_too_big); |
447 | 0 | return false; |
448 | 0 | } |
449 | | |
450 | | /* Now fill in fields in the raw data, from the fields in the exec struct. */ |
451 | 4 | H_PUT_32 (abfd, execp->a_info , bytes->e_info); |
452 | 4 | PUT_WORD (abfd, execp->a_text , bytes->e_text); |
453 | 4 | PUT_WORD (abfd, execp->a_data , bytes->e_data); |
454 | 4 | PUT_WORD (abfd, execp->a_bss , bytes->e_bss); |
455 | 4 | PUT_WORD (abfd, execp->a_syms , bytes->e_syms); |
456 | 4 | PUT_WORD (abfd, execp->a_entry , bytes->e_entry); |
457 | 4 | PUT_WORD (abfd, execp->a_trsize, bytes->e_trsize); |
458 | 4 | PUT_WORD (abfd, execp->a_drsize, bytes->e_drsize); |
459 | 4 | return true; |
460 | 4 | } Unexecuted instantiation: cris_aout_32_swap_exec_header_out ns32kaout_32_swap_exec_header_out Line | Count | Source | 423 | 1 | { | 424 | 1 | const char *err = NULL; | 425 | 1 | uint64_t val; | 426 | 1 | #define MAXVAL(x) ((UINT64_C (1) << (8 * sizeof (x) - 1) << 1) - 1) | 427 | 1 | if ((val = execp->a_text) > MAXVAL (bytes->e_text)) | 428 | 0 | err = "e_text"; | 429 | 1 | else if ((val = execp->a_data) > MAXVAL (bytes->e_data)) | 430 | 0 | err = "e_data"; | 431 | 1 | else if ((val = execp->a_bss) > MAXVAL (bytes->e_bss)) | 432 | 0 | err = "e_bss"; | 433 | 1 | else if ((val = execp->a_syms) > MAXVAL (bytes->e_syms)) | 434 | 0 | err = "e_syms"; | 435 | 1 | else if ((val = execp->a_entry) > MAXVAL (bytes->e_entry)) | 436 | 0 | err = "e_entry"; | 437 | 1 | else if ((val = execp->a_trsize) > MAXVAL (bytes->e_trsize)) | 438 | 0 | err = "e_trsize"; | 439 | 1 | else if ((val = execp->a_drsize) > MAXVAL (bytes->e_drsize)) | 440 | 0 | err = "e_drsize"; | 441 | 1 | #undef MAXVAL | 442 | 1 | if (err) | 443 | 0 | { | 444 | 0 | _bfd_error_handler (_("%pB: %#" PRIx64 " overflows header %s field"), | 445 | 0 | abfd, val, err); | 446 | 0 | bfd_set_error (bfd_error_file_too_big); | 447 | 0 | return false; | 448 | 0 | } | 449 | | | 450 | | /* Now fill in fields in the raw data, from the fields in the exec struct. */ | 451 | 1 | H_PUT_32 (abfd, execp->a_info , bytes->e_info); | 452 | 1 | PUT_WORD (abfd, execp->a_text , bytes->e_text); | 453 | 1 | PUT_WORD (abfd, execp->a_data , bytes->e_data); | 454 | 1 | PUT_WORD (abfd, execp->a_bss , bytes->e_bss); | 455 | 1 | PUT_WORD (abfd, execp->a_syms , bytes->e_syms); | 456 | 1 | PUT_WORD (abfd, execp->a_entry , bytes->e_entry); | 457 | 1 | PUT_WORD (abfd, execp->a_trsize, bytes->e_trsize); | 458 | 1 | PUT_WORD (abfd, execp->a_drsize, bytes->e_drsize); | 459 | 1 | return true; | 460 | 1 | } |
aout_32_swap_exec_header_out Line | Count | Source | 423 | 3 | { | 424 | 3 | const char *err = NULL; | 425 | 3 | uint64_t val; | 426 | 3 | #define MAXVAL(x) ((UINT64_C (1) << (8 * sizeof (x) - 1) << 1) - 1) | 427 | 3 | if ((val = execp->a_text) > MAXVAL (bytes->e_text)) | 428 | 0 | err = "e_text"; | 429 | 3 | else if ((val = execp->a_data) > MAXVAL (bytes->e_data)) | 430 | 0 | err = "e_data"; | 431 | 3 | else if ((val = execp->a_bss) > MAXVAL (bytes->e_bss)) | 432 | 0 | err = "e_bss"; | 433 | 3 | else if ((val = execp->a_syms) > MAXVAL (bytes->e_syms)) | 434 | 0 | err = "e_syms"; | 435 | 3 | else if ((val = execp->a_entry) > MAXVAL (bytes->e_entry)) | 436 | 0 | err = "e_entry"; | 437 | 3 | else if ((val = execp->a_trsize) > MAXVAL (bytes->e_trsize)) | 438 | 0 | err = "e_trsize"; | 439 | 3 | else if ((val = execp->a_drsize) > MAXVAL (bytes->e_drsize)) | 440 | 0 | err = "e_drsize"; | 441 | 3 | #undef MAXVAL | 442 | 3 | if (err) | 443 | 0 | { | 444 | 0 | _bfd_error_handler (_("%pB: %#" PRIx64 " overflows header %s field"), | 445 | 0 | abfd, val, err); | 446 | 0 | bfd_set_error (bfd_error_file_too_big); | 447 | 0 | return false; | 448 | 0 | } | 449 | | | 450 | | /* Now fill in fields in the raw data, from the fields in the exec struct. */ | 451 | 3 | H_PUT_32 (abfd, execp->a_info , bytes->e_info); | 452 | 3 | PUT_WORD (abfd, execp->a_text , bytes->e_text); | 453 | 3 | PUT_WORD (abfd, execp->a_data , bytes->e_data); | 454 | 3 | PUT_WORD (abfd, execp->a_bss , bytes->e_bss); | 455 | 3 | PUT_WORD (abfd, execp->a_syms , bytes->e_syms); | 456 | 3 | PUT_WORD (abfd, execp->a_entry , bytes->e_entry); | 457 | 3 | PUT_WORD (abfd, execp->a_trsize, bytes->e_trsize); | 458 | 3 | PUT_WORD (abfd, execp->a_drsize, bytes->e_drsize); | 459 | 3 | return true; | 460 | 3 | } |
|
461 | | |
462 | | /* Make all the section for an a.out file. */ |
463 | | |
464 | | bool |
465 | | NAME (aout, make_sections) (bfd *abfd) |
466 | 80.6k | { |
467 | 80.6k | if (obj_textsec (abfd) == NULL && bfd_make_section (abfd, ".text") == NULL) |
468 | 0 | return false; |
469 | 80.6k | if (obj_datasec (abfd) == NULL && bfd_make_section (abfd, ".data") == NULL) |
470 | 0 | return false; |
471 | 80.6k | if (obj_bsssec (abfd) == NULL && bfd_make_section (abfd, ".bss") == NULL) |
472 | 0 | return false; |
473 | 80.6k | return true; |
474 | 80.6k | } cris_aout_32_make_sections Line | Count | Source | 466 | 5.72k | { | 467 | 5.72k | if (obj_textsec (abfd) == NULL && bfd_make_section (abfd, ".text") == NULL) | 468 | 0 | return false; | 469 | 5.72k | if (obj_datasec (abfd) == NULL && bfd_make_section (abfd, ".data") == NULL) | 470 | 0 | return false; | 471 | 5.72k | if (obj_bsssec (abfd) == NULL && bfd_make_section (abfd, ".bss") == NULL) | 472 | 0 | return false; | 473 | 5.72k | return true; | 474 | 5.72k | } |
ns32kaout_32_make_sections Line | Count | Source | 466 | 25.2k | { | 467 | 25.2k | if (obj_textsec (abfd) == NULL && bfd_make_section (abfd, ".text") == NULL) | 468 | 0 | return false; | 469 | 25.2k | if (obj_datasec (abfd) == NULL && bfd_make_section (abfd, ".data") == NULL) | 470 | 0 | return false; | 471 | 25.2k | if (obj_bsssec (abfd) == NULL && bfd_make_section (abfd, ".bss") == NULL) | 472 | 0 | return false; | 473 | 25.2k | return true; | 474 | 25.2k | } |
Line | Count | Source | 466 | 49.7k | { | 467 | 49.7k | if (obj_textsec (abfd) == NULL && bfd_make_section (abfd, ".text") == NULL) | 468 | 0 | return false; | 469 | 49.7k | if (obj_datasec (abfd) == NULL && bfd_make_section (abfd, ".data") == NULL) | 470 | 0 | return false; | 471 | 49.7k | if (obj_bsssec (abfd) == NULL && bfd_make_section (abfd, ".bss") == NULL) | 472 | 0 | return false; | 473 | 49.7k | return true; | 474 | 49.7k | } |
|
475 | | |
476 | | /* |
477 | | FUNCTION |
478 | | aout_@var{size}_some_aout_object_p |
479 | | |
480 | | SYNOPSIS |
481 | | bfd_cleanup aout_@var{size}_some_aout_object_p |
482 | | (bfd *abfd, |
483 | | struct internal_exec *execp, |
484 | | bfd_cleanup (*callback_to_real_object_p) (bfd *)); |
485 | | |
486 | | DESCRIPTION |
487 | | Some a.out variant thinks that the file open in @var{abfd} |
488 | | checking is an a.out file. Do some more checking, and set up |
489 | | for access if it really is. Call back to the calling |
490 | | environment's "finish up" function just before returning, to |
491 | | handle any last-minute setup. |
492 | | */ |
493 | | |
494 | | bfd_cleanup |
495 | | NAME (aout, some_aout_object_p) (bfd *abfd, |
496 | | struct internal_exec *execp, |
497 | | bfd_cleanup (*callback_to_real_object_p) (bfd *)) |
498 | 80.6k | { |
499 | 80.6k | struct aout_data_struct *rawptr; |
500 | 80.6k | bfd_cleanup result; |
501 | | |
502 | 80.6k | rawptr = bfd_zalloc (abfd, sizeof (*rawptr)); |
503 | 80.6k | if (rawptr == NULL) |
504 | 0 | return NULL; |
505 | 80.6k | abfd->tdata.aout_data = rawptr; |
506 | | |
507 | 80.6k | abfd->tdata.aout_data->a.hdr = &rawptr->e; |
508 | | /* Copy in the internal_exec struct. */ |
509 | 80.6k | *(abfd->tdata.aout_data->a.hdr) = *execp; |
510 | 80.6k | execp = abfd->tdata.aout_data->a.hdr; |
511 | | |
512 | | /* Set the file flags. */ |
513 | 80.6k | abfd->flags = BFD_NO_FLAGS; |
514 | 80.6k | if (execp->a_drsize || execp->a_trsize) |
515 | 70.7k | abfd->flags |= HAS_RELOC; |
516 | | /* Setting of EXEC_P has been deferred to the bottom of this function. */ |
517 | 80.6k | if (execp->a_syms) |
518 | 61.4k | abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS; |
519 | 80.6k | if (N_DYNAMIC (execp)) |
520 | 27.8k | abfd->flags |= DYNAMIC; |
521 | | |
522 | 80.6k | if (N_MAGIC (execp) == ZMAGIC) |
523 | 11.1k | { |
524 | 11.1k | abfd->flags |= D_PAGED | WP_TEXT; |
525 | 11.1k | adata (abfd).magic = z_magic; |
526 | 11.1k | } |
527 | 69.5k | else if (N_IS_QMAGIC (execp)) |
528 | 16.5k | { |
529 | 16.5k | abfd->flags |= D_PAGED | WP_TEXT; |
530 | 16.5k | adata (abfd).magic = z_magic; |
531 | 16.5k | adata (abfd).subformat = q_magic_format; |
532 | 16.5k | } |
533 | 52.9k | else if (N_MAGIC (execp) == NMAGIC) |
534 | 24.8k | { |
535 | 24.8k | abfd->flags |= WP_TEXT; |
536 | 24.8k | adata (abfd).magic = n_magic; |
537 | 24.8k | } |
538 | 28.0k | else if (N_MAGIC (execp) == OMAGIC || N_IS_BMAGIC (execp)) |
539 | 28.0k | adata (abfd).magic = o_magic; |
540 | 0 | else |
541 | | /* Should have been checked with N_BADMAG before this routine |
542 | | was called. */ |
543 | 0 | abort (); |
544 | | |
545 | 80.6k | abfd->start_address = execp->a_entry; |
546 | | |
547 | 80.6k | abfd->symcount = execp->a_syms / sizeof (struct external_nlist); |
548 | | |
549 | | /* The default relocation entry size is that of traditional V7 Unix. */ |
550 | 80.6k | obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; |
551 | | |
552 | | /* The default symbol entry size is that of traditional Unix. */ |
553 | 80.6k | obj_symbol_entry_size (abfd) = EXTERNAL_NLIST_SIZE; |
554 | | |
555 | 80.6k | if (! NAME (aout, make_sections) (abfd)) |
556 | 0 | goto error_ret; |
557 | | |
558 | 80.6k | obj_datasec (abfd)->size = execp->a_data; |
559 | 80.6k | obj_bsssec (abfd)->size = execp->a_bss; |
560 | | |
561 | 80.6k | obj_textsec (abfd)->flags = |
562 | 80.6k | (execp->a_trsize != 0 |
563 | 80.6k | ? (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | SEC_RELOC) |
564 | 80.6k | : (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)); |
565 | 80.6k | obj_datasec (abfd)->flags = |
566 | 80.6k | (execp->a_drsize != 0 |
567 | 80.6k | ? (SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS | SEC_RELOC) |
568 | 80.6k | : (SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS)); |
569 | 80.6k | obj_bsssec (abfd)->flags = SEC_ALLOC; |
570 | | |
571 | | #ifdef THIS_IS_ONLY_DOCUMENTATION |
572 | | /* The common code can't fill in these things because they depend |
573 | | on either the start address of the text segment, the rounding |
574 | | up of virtual addresses between segments, or the starting file |
575 | | position of the text segment -- all of which varies among different |
576 | | versions of a.out. */ |
577 | | |
578 | | /* Call back to the format-dependent code to fill in the rest of the |
579 | | fields and do any further cleanup. Things that should be filled |
580 | | in by the callback: */ |
581 | | struct exec *execp = exec_hdr (abfd); |
582 | | |
583 | | obj_textsec (abfd)->size = N_TXTSIZE (execp); |
584 | | /* Data and bss are already filled in since they're so standard. */ |
585 | | |
586 | | /* The virtual memory addresses of the sections. */ |
587 | | obj_textsec (abfd)->vma = N_TXTADDR (execp); |
588 | | obj_datasec (abfd)->vma = N_DATADDR (execp); |
589 | | obj_bsssec (abfd)->vma = N_BSSADDR (execp); |
590 | | |
591 | | /* The file offsets of the sections. */ |
592 | | obj_textsec (abfd)->filepos = N_TXTOFF (execp); |
593 | | obj_datasec (abfd)->filepos = N_DATOFF (execp); |
594 | | |
595 | | /* The file offsets of the relocation info. */ |
596 | | obj_textsec (abfd)->rel_filepos = N_TRELOFF (execp); |
597 | | obj_datasec (abfd)->rel_filepos = N_DRELOFF (execp); |
598 | | |
599 | | /* The file offsets of the string table and symbol table. */ |
600 | | obj_str_filepos (abfd) = N_STROFF (execp); |
601 | | obj_sym_filepos (abfd) = N_SYMOFF (execp); |
602 | | |
603 | | /* Determine the architecture and machine type of the object file. */ |
604 | | abfd->obj_arch = bfd_arch_obscure; |
605 | | |
606 | | adata (abfd)->page_size = TARGET_PAGE_SIZE; |
607 | | adata (abfd)->segment_size = SEGMENT_SIZE; |
608 | | adata (abfd)->exec_bytes_size = EXEC_BYTES_SIZE; |
609 | | |
610 | | return _bfd_no_cleanup; |
611 | | |
612 | | /* The architecture is encoded in various ways in various a.out variants, |
613 | | or is not encoded at all in some of them. The relocation size depends |
614 | | on the architecture and the a.out variant. Finally, the return value |
615 | | is the bfd_target vector in use. If an error occurs, return zero and |
616 | | set bfd_error to the appropriate error code. |
617 | | |
618 | | Formats such as b.out, which have additional fields in the a.out |
619 | | header, should cope with them in this callback as well. */ |
620 | | #endif /* DOCUMENTATION */ |
621 | | |
622 | 80.6k | result = (*callback_to_real_object_p) (abfd); |
623 | | |
624 | | /* Now that the segment addresses have been worked out, take a better |
625 | | guess at whether the file is executable. If the entry point |
626 | | is within the text segment, assume it is. (This makes files |
627 | | executable even if their entry point address is 0, as long as |
628 | | their text starts at zero.). |
629 | | |
630 | | This test had to be changed to deal with systems where the text segment |
631 | | runs at a different location than the default. The problem is that the |
632 | | entry address can appear to be outside the text segment, thus causing an |
633 | | erroneous conclusion that the file isn't executable. |
634 | | |
635 | | To fix this, we now accept any non-zero entry point as an indication of |
636 | | executability. This will work most of the time, since only the linker |
637 | | sets the entry point, and that is likely to be non-zero for most systems. */ |
638 | | |
639 | 80.6k | if (execp->a_entry != 0 |
640 | 80.6k | || (execp->a_entry >= obj_textsec (abfd)->vma |
641 | 35.7k | && execp->a_entry < (obj_textsec (abfd)->vma |
642 | 27.7k | + obj_textsec (abfd)->size) |
643 | 35.7k | && execp->a_trsize == 0 |
644 | 35.7k | && execp->a_drsize == 0)) |
645 | 49.5k | abfd->flags |= EXEC_P; |
646 | | #ifdef STAT_FOR_EXEC |
647 | | else |
648 | 10.7k | { |
649 | 10.7k | struct stat stat_buf; |
650 | | |
651 | | /* The original heuristic doesn't work in some important cases. |
652 | | The a.out file has no information about the text start |
653 | | address. For files (like kernels) linked to non-standard |
654 | | addresses (ld -Ttext nnn) the entry point may not be between |
655 | | the default text start (obj_textsec(abfd)->vma) and |
656 | | (obj_textsec(abfd)->vma) + text size. This is not just a mach |
657 | | issue. Many kernels are loaded at non standard addresses. */ |
658 | 10.7k | if (abfd->iostream != NULL |
659 | 10.7k | && (abfd->flags & BFD_IN_MEMORY) == 0 |
660 | 10.7k | && (fstat (fileno ((FILE *) (abfd->iostream)), &stat_buf) == 0) |
661 | 10.7k | && ((stat_buf.st_mode & 0111) != 0)) |
662 | 0 | abfd->flags |= EXEC_P; |
663 | 10.7k | } |
664 | | #endif /* STAT_FOR_EXEC */ |
665 | | |
666 | 80.6k | if (result) |
667 | 80.6k | return result; |
668 | | |
669 | 0 | error_ret: |
670 | 0 | bfd_release (abfd, rawptr); |
671 | 0 | return NULL; |
672 | 80.6k | } cris_aout_32_some_aout_object_p Line | Count | Source | 498 | 5.72k | { | 499 | 5.72k | struct aout_data_struct *rawptr; | 500 | 5.72k | bfd_cleanup result; | 501 | | | 502 | 5.72k | rawptr = bfd_zalloc (abfd, sizeof (*rawptr)); | 503 | 5.72k | if (rawptr == NULL) | 504 | 0 | return NULL; | 505 | 5.72k | abfd->tdata.aout_data = rawptr; | 506 | | | 507 | 5.72k | abfd->tdata.aout_data->a.hdr = &rawptr->e; | 508 | | /* Copy in the internal_exec struct. */ | 509 | 5.72k | *(abfd->tdata.aout_data->a.hdr) = *execp; | 510 | 5.72k | execp = abfd->tdata.aout_data->a.hdr; | 511 | | | 512 | | /* Set the file flags. */ | 513 | 5.72k | abfd->flags = BFD_NO_FLAGS; | 514 | 5.72k | if (execp->a_drsize || execp->a_trsize) | 515 | 4.98k | abfd->flags |= HAS_RELOC; | 516 | | /* Setting of EXEC_P has been deferred to the bottom of this function. */ | 517 | 5.72k | if (execp->a_syms) | 518 | 3.95k | abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS; | 519 | 5.72k | if (N_DYNAMIC (execp)) | 520 | 2.47k | abfd->flags |= DYNAMIC; | 521 | | | 522 | 5.72k | if (N_MAGIC (execp) == ZMAGIC) | 523 | 440 | { | 524 | 440 | abfd->flags |= D_PAGED | WP_TEXT; | 525 | 440 | adata (abfd).magic = z_magic; | 526 | 440 | } | 527 | 5.28k | else if (N_IS_QMAGIC (execp)) | 528 | 1.31k | { | 529 | 1.31k | abfd->flags |= D_PAGED | WP_TEXT; | 530 | 1.31k | adata (abfd).magic = z_magic; | 531 | 1.31k | adata (abfd).subformat = q_magic_format; | 532 | 1.31k | } | 533 | 3.96k | else if (N_MAGIC (execp) == NMAGIC) | 534 | 2.15k | { | 535 | 2.15k | abfd->flags |= WP_TEXT; | 536 | 2.15k | adata (abfd).magic = n_magic; | 537 | 2.15k | } | 538 | 1.81k | else if (N_MAGIC (execp) == OMAGIC || N_IS_BMAGIC (execp)) | 539 | 1.81k | adata (abfd).magic = o_magic; | 540 | 0 | else | 541 | | /* Should have been checked with N_BADMAG before this routine | 542 | | was called. */ | 543 | 0 | abort (); | 544 | | | 545 | 5.72k | abfd->start_address = execp->a_entry; | 546 | | | 547 | 5.72k | abfd->symcount = execp->a_syms / sizeof (struct external_nlist); | 548 | | | 549 | | /* The default relocation entry size is that of traditional V7 Unix. */ | 550 | 5.72k | obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; | 551 | | | 552 | | /* The default symbol entry size is that of traditional Unix. */ | 553 | 5.72k | obj_symbol_entry_size (abfd) = EXTERNAL_NLIST_SIZE; | 554 | | | 555 | 5.72k | if (! NAME (aout, make_sections) (abfd)) | 556 | 0 | goto error_ret; | 557 | | | 558 | 5.72k | obj_datasec (abfd)->size = execp->a_data; | 559 | 5.72k | obj_bsssec (abfd)->size = execp->a_bss; | 560 | | | 561 | 5.72k | obj_textsec (abfd)->flags = | 562 | 5.72k | (execp->a_trsize != 0 | 563 | 5.72k | ? (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | SEC_RELOC) | 564 | 5.72k | : (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)); | 565 | 5.72k | obj_datasec (abfd)->flags = | 566 | 5.72k | (execp->a_drsize != 0 | 567 | 5.72k | ? (SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS | SEC_RELOC) | 568 | 5.72k | : (SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS)); | 569 | 5.72k | obj_bsssec (abfd)->flags = SEC_ALLOC; | 570 | | | 571 | | #ifdef THIS_IS_ONLY_DOCUMENTATION | 572 | | /* The common code can't fill in these things because they depend | 573 | | on either the start address of the text segment, the rounding | 574 | | up of virtual addresses between segments, or the starting file | 575 | | position of the text segment -- all of which varies among different | 576 | | versions of a.out. */ | 577 | | | 578 | | /* Call back to the format-dependent code to fill in the rest of the | 579 | | fields and do any further cleanup. Things that should be filled | 580 | | in by the callback: */ | 581 | | struct exec *execp = exec_hdr (abfd); | 582 | | | 583 | | obj_textsec (abfd)->size = N_TXTSIZE (execp); | 584 | | /* Data and bss are already filled in since they're so standard. */ | 585 | | | 586 | | /* The virtual memory addresses of the sections. */ | 587 | | obj_textsec (abfd)->vma = N_TXTADDR (execp); | 588 | | obj_datasec (abfd)->vma = N_DATADDR (execp); | 589 | | obj_bsssec (abfd)->vma = N_BSSADDR (execp); | 590 | | | 591 | | /* The file offsets of the sections. */ | 592 | | obj_textsec (abfd)->filepos = N_TXTOFF (execp); | 593 | | obj_datasec (abfd)->filepos = N_DATOFF (execp); | 594 | | | 595 | | /* The file offsets of the relocation info. */ | 596 | | obj_textsec (abfd)->rel_filepos = N_TRELOFF (execp); | 597 | | obj_datasec (abfd)->rel_filepos = N_DRELOFF (execp); | 598 | | | 599 | | /* The file offsets of the string table and symbol table. */ | 600 | | obj_str_filepos (abfd) = N_STROFF (execp); | 601 | | obj_sym_filepos (abfd) = N_SYMOFF (execp); | 602 | | | 603 | | /* Determine the architecture and machine type of the object file. */ | 604 | | abfd->obj_arch = bfd_arch_obscure; | 605 | | | 606 | | adata (abfd)->page_size = TARGET_PAGE_SIZE; | 607 | | adata (abfd)->segment_size = SEGMENT_SIZE; | 608 | | adata (abfd)->exec_bytes_size = EXEC_BYTES_SIZE; | 609 | | | 610 | | return _bfd_no_cleanup; | 611 | | | 612 | | /* The architecture is encoded in various ways in various a.out variants, | 613 | | or is not encoded at all in some of them. The relocation size depends | 614 | | on the architecture and the a.out variant. Finally, the return value | 615 | | is the bfd_target vector in use. If an error occurs, return zero and | 616 | | set bfd_error to the appropriate error code. | 617 | | | 618 | | Formats such as b.out, which have additional fields in the a.out | 619 | | header, should cope with them in this callback as well. */ | 620 | | #endif /* DOCUMENTATION */ | 621 | | | 622 | 5.72k | result = (*callback_to_real_object_p) (abfd); | 623 | | | 624 | | /* Now that the segment addresses have been worked out, take a better | 625 | | guess at whether the file is executable. If the entry point | 626 | | is within the text segment, assume it is. (This makes files | 627 | | executable even if their entry point address is 0, as long as | 628 | | their text starts at zero.). | 629 | | | 630 | | This test had to be changed to deal with systems where the text segment | 631 | | runs at a different location than the default. The problem is that the | 632 | | entry address can appear to be outside the text segment, thus causing an | 633 | | erroneous conclusion that the file isn't executable. | 634 | | | 635 | | To fix this, we now accept any non-zero entry point as an indication of | 636 | | executability. This will work most of the time, since only the linker | 637 | | sets the entry point, and that is likely to be non-zero for most systems. */ | 638 | | | 639 | 5.72k | if (execp->a_entry != 0 | 640 | 5.72k | || (execp->a_entry >= obj_textsec (abfd)->vma | 641 | 2.82k | && execp->a_entry < (obj_textsec (abfd)->vma | 642 | 2.82k | + obj_textsec (abfd)->size) | 643 | 2.82k | && execp->a_trsize == 0 | 644 | 2.82k | && execp->a_drsize == 0)) | 645 | 3.32k | abfd->flags |= EXEC_P; | 646 | | #ifdef STAT_FOR_EXEC | 647 | | else | 648 | | { | 649 | | struct stat stat_buf; | 650 | | | 651 | | /* The original heuristic doesn't work in some important cases. | 652 | | The a.out file has no information about the text start | 653 | | address. For files (like kernels) linked to non-standard | 654 | | addresses (ld -Ttext nnn) the entry point may not be between | 655 | | the default text start (obj_textsec(abfd)->vma) and | 656 | | (obj_textsec(abfd)->vma) + text size. This is not just a mach | 657 | | issue. Many kernels are loaded at non standard addresses. */ | 658 | | if (abfd->iostream != NULL | 659 | | && (abfd->flags & BFD_IN_MEMORY) == 0 | 660 | | && (fstat (fileno ((FILE *) (abfd->iostream)), &stat_buf) == 0) | 661 | | && ((stat_buf.st_mode & 0111) != 0)) | 662 | | abfd->flags |= EXEC_P; | 663 | | } | 664 | | #endif /* STAT_FOR_EXEC */ | 665 | | | 666 | 5.72k | if (result) | 667 | 5.72k | return result; | 668 | | | 669 | 0 | error_ret: | 670 | 0 | bfd_release (abfd, rawptr); | 671 | 0 | return NULL; | 672 | 5.72k | } |
ns32kaout_32_some_aout_object_p Line | Count | Source | 498 | 25.2k | { | 499 | 25.2k | struct aout_data_struct *rawptr; | 500 | 25.2k | bfd_cleanup result; | 501 | | | 502 | 25.2k | rawptr = bfd_zalloc (abfd, sizeof (*rawptr)); | 503 | 25.2k | if (rawptr == NULL) | 504 | 0 | return NULL; | 505 | 25.2k | abfd->tdata.aout_data = rawptr; | 506 | | | 507 | 25.2k | abfd->tdata.aout_data->a.hdr = &rawptr->e; | 508 | | /* Copy in the internal_exec struct. */ | 509 | 25.2k | *(abfd->tdata.aout_data->a.hdr) = *execp; | 510 | 25.2k | execp = abfd->tdata.aout_data->a.hdr; | 511 | | | 512 | | /* Set the file flags. */ | 513 | 25.2k | abfd->flags = BFD_NO_FLAGS; | 514 | 25.2k | if (execp->a_drsize || execp->a_trsize) | 515 | 21.9k | abfd->flags |= HAS_RELOC; | 516 | | /* Setting of EXEC_P has been deferred to the bottom of this function. */ | 517 | 25.2k | if (execp->a_syms) | 518 | 18.5k | abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS; | 519 | 25.2k | if (N_DYNAMIC (execp)) | 520 | 7.80k | abfd->flags |= DYNAMIC; | 521 | | | 522 | 25.2k | if (N_MAGIC (execp) == ZMAGIC) | 523 | 3.01k | { | 524 | 3.01k | abfd->flags |= D_PAGED | WP_TEXT; | 525 | 3.01k | adata (abfd).magic = z_magic; | 526 | 3.01k | } | 527 | 22.2k | else if (N_IS_QMAGIC (execp)) | 528 | 4.37k | { | 529 | 4.37k | abfd->flags |= D_PAGED | WP_TEXT; | 530 | 4.37k | adata (abfd).magic = z_magic; | 531 | 4.37k | adata (abfd).subformat = q_magic_format; | 532 | 4.37k | } | 533 | 17.8k | else if (N_MAGIC (execp) == NMAGIC) | 534 | 7.47k | { | 535 | 7.47k | abfd->flags |= WP_TEXT; | 536 | 7.47k | adata (abfd).magic = n_magic; | 537 | 7.47k | } | 538 | 10.4k | else if (N_MAGIC (execp) == OMAGIC || N_IS_BMAGIC (execp)) | 539 | 10.4k | adata (abfd).magic = o_magic; | 540 | 0 | else | 541 | | /* Should have been checked with N_BADMAG before this routine | 542 | | was called. */ | 543 | 0 | abort (); | 544 | | | 545 | 25.2k | abfd->start_address = execp->a_entry; | 546 | | | 547 | 25.2k | abfd->symcount = execp->a_syms / sizeof (struct external_nlist); | 548 | | | 549 | | /* The default relocation entry size is that of traditional V7 Unix. */ | 550 | 25.2k | obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; | 551 | | | 552 | | /* The default symbol entry size is that of traditional Unix. */ | 553 | 25.2k | obj_symbol_entry_size (abfd) = EXTERNAL_NLIST_SIZE; | 554 | | | 555 | 25.2k | if (! NAME (aout, make_sections) (abfd)) | 556 | 0 | goto error_ret; | 557 | | | 558 | 25.2k | obj_datasec (abfd)->size = execp->a_data; | 559 | 25.2k | obj_bsssec (abfd)->size = execp->a_bss; | 560 | | | 561 | 25.2k | obj_textsec (abfd)->flags = | 562 | 25.2k | (execp->a_trsize != 0 | 563 | 25.2k | ? (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | SEC_RELOC) | 564 | 25.2k | : (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)); | 565 | 25.2k | obj_datasec (abfd)->flags = | 566 | 25.2k | (execp->a_drsize != 0 | 567 | 25.2k | ? (SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS | SEC_RELOC) | 568 | 25.2k | : (SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS)); | 569 | 25.2k | obj_bsssec (abfd)->flags = SEC_ALLOC; | 570 | | | 571 | | #ifdef THIS_IS_ONLY_DOCUMENTATION | 572 | | /* The common code can't fill in these things because they depend | 573 | | on either the start address of the text segment, the rounding | 574 | | up of virtual addresses between segments, or the starting file | 575 | | position of the text segment -- all of which varies among different | 576 | | versions of a.out. */ | 577 | | | 578 | | /* Call back to the format-dependent code to fill in the rest of the | 579 | | fields and do any further cleanup. Things that should be filled | 580 | | in by the callback: */ | 581 | | struct exec *execp = exec_hdr (abfd); | 582 | | | 583 | | obj_textsec (abfd)->size = N_TXTSIZE (execp); | 584 | | /* Data and bss are already filled in since they're so standard. */ | 585 | | | 586 | | /* The virtual memory addresses of the sections. */ | 587 | | obj_textsec (abfd)->vma = N_TXTADDR (execp); | 588 | | obj_datasec (abfd)->vma = N_DATADDR (execp); | 589 | | obj_bsssec (abfd)->vma = N_BSSADDR (execp); | 590 | | | 591 | | /* The file offsets of the sections. */ | 592 | | obj_textsec (abfd)->filepos = N_TXTOFF (execp); | 593 | | obj_datasec (abfd)->filepos = N_DATOFF (execp); | 594 | | | 595 | | /* The file offsets of the relocation info. */ | 596 | | obj_textsec (abfd)->rel_filepos = N_TRELOFF (execp); | 597 | | obj_datasec (abfd)->rel_filepos = N_DRELOFF (execp); | 598 | | | 599 | | /* The file offsets of the string table and symbol table. */ | 600 | | obj_str_filepos (abfd) = N_STROFF (execp); | 601 | | obj_sym_filepos (abfd) = N_SYMOFF (execp); | 602 | | | 603 | | /* Determine the architecture and machine type of the object file. */ | 604 | | abfd->obj_arch = bfd_arch_obscure; | 605 | | | 606 | | adata (abfd)->page_size = TARGET_PAGE_SIZE; | 607 | | adata (abfd)->segment_size = SEGMENT_SIZE; | 608 | | adata (abfd)->exec_bytes_size = EXEC_BYTES_SIZE; | 609 | | | 610 | | return _bfd_no_cleanup; | 611 | | | 612 | | /* The architecture is encoded in various ways in various a.out variants, | 613 | | or is not encoded at all in some of them. The relocation size depends | 614 | | on the architecture and the a.out variant. Finally, the return value | 615 | | is the bfd_target vector in use. If an error occurs, return zero and | 616 | | set bfd_error to the appropriate error code. | 617 | | | 618 | | Formats such as b.out, which have additional fields in the a.out | 619 | | header, should cope with them in this callback as well. */ | 620 | | #endif /* DOCUMENTATION */ | 621 | | | 622 | 25.2k | result = (*callback_to_real_object_p) (abfd); | 623 | | | 624 | | /* Now that the segment addresses have been worked out, take a better | 625 | | guess at whether the file is executable. If the entry point | 626 | | is within the text segment, assume it is. (This makes files | 627 | | executable even if their entry point address is 0, as long as | 628 | | their text starts at zero.). | 629 | | | 630 | | This test had to be changed to deal with systems where the text segment | 631 | | runs at a different location than the default. The problem is that the | 632 | | entry address can appear to be outside the text segment, thus causing an | 633 | | erroneous conclusion that the file isn't executable. | 634 | | | 635 | | To fix this, we now accept any non-zero entry point as an indication of | 636 | | executability. This will work most of the time, since only the linker | 637 | | sets the entry point, and that is likely to be non-zero for most systems. */ | 638 | | | 639 | 25.2k | if (execp->a_entry != 0 | 640 | 25.2k | || (execp->a_entry >= obj_textsec (abfd)->vma | 641 | 12.2k | && execp->a_entry < (obj_textsec (abfd)->vma | 642 | 8.09k | + obj_textsec (abfd)->size) | 643 | 12.2k | && execp->a_trsize == 0 | 644 | 12.2k | && execp->a_drsize == 0)) | 645 | 14.5k | abfd->flags |= EXEC_P; | 646 | 10.7k | #ifdef STAT_FOR_EXEC | 647 | 10.7k | else | 648 | 10.7k | { | 649 | 10.7k | struct stat stat_buf; | 650 | | | 651 | | /* The original heuristic doesn't work in some important cases. | 652 | | The a.out file has no information about the text start | 653 | | address. For files (like kernels) linked to non-standard | 654 | | addresses (ld -Ttext nnn) the entry point may not be between | 655 | | the default text start (obj_textsec(abfd)->vma) and | 656 | | (obj_textsec(abfd)->vma) + text size. This is not just a mach | 657 | | issue. Many kernels are loaded at non standard addresses. */ | 658 | 10.7k | if (abfd->iostream != NULL | 659 | 10.7k | && (abfd->flags & BFD_IN_MEMORY) == 0 | 660 | 10.7k | && (fstat (fileno ((FILE *) (abfd->iostream)), &stat_buf) == 0) | 661 | 10.7k | && ((stat_buf.st_mode & 0111) != 0)) | 662 | 0 | abfd->flags |= EXEC_P; | 663 | 10.7k | } | 664 | 25.2k | #endif /* STAT_FOR_EXEC */ | 665 | | | 666 | 25.2k | if (result) | 667 | 25.2k | return result; | 668 | | | 669 | 0 | error_ret: | 670 | 0 | bfd_release (abfd, rawptr); | 671 | 0 | return NULL; | 672 | 25.2k | } |
aout_32_some_aout_object_p Line | Count | Source | 498 | 49.7k | { | 499 | 49.7k | struct aout_data_struct *rawptr; | 500 | 49.7k | bfd_cleanup result; | 501 | | | 502 | 49.7k | rawptr = bfd_zalloc (abfd, sizeof (*rawptr)); | 503 | 49.7k | if (rawptr == NULL) | 504 | 0 | return NULL; | 505 | 49.7k | abfd->tdata.aout_data = rawptr; | 506 | | | 507 | 49.7k | abfd->tdata.aout_data->a.hdr = &rawptr->e; | 508 | | /* Copy in the internal_exec struct. */ | 509 | 49.7k | *(abfd->tdata.aout_data->a.hdr) = *execp; | 510 | 49.7k | execp = abfd->tdata.aout_data->a.hdr; | 511 | | | 512 | | /* Set the file flags. */ | 513 | 49.7k | abfd->flags = BFD_NO_FLAGS; | 514 | 49.7k | if (execp->a_drsize || execp->a_trsize) | 515 | 43.8k | abfd->flags |= HAS_RELOC; | 516 | | /* Setting of EXEC_P has been deferred to the bottom of this function. */ | 517 | 49.7k | if (execp->a_syms) | 518 | 38.8k | abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS; | 519 | 49.7k | if (N_DYNAMIC (execp)) | 520 | 17.5k | abfd->flags |= DYNAMIC; | 521 | | | 522 | 49.7k | if (N_MAGIC (execp) == ZMAGIC) | 523 | 7.71k | { | 524 | 7.71k | abfd->flags |= D_PAGED | WP_TEXT; | 525 | 7.71k | adata (abfd).magic = z_magic; | 526 | 7.71k | } | 527 | 41.9k | else if (N_IS_QMAGIC (execp)) | 528 | 10.8k | { | 529 | 10.8k | abfd->flags |= D_PAGED | WP_TEXT; | 530 | 10.8k | adata (abfd).magic = z_magic; | 531 | 10.8k | adata (abfd).subformat = q_magic_format; | 532 | 10.8k | } | 533 | 31.1k | else if (N_MAGIC (execp) == NMAGIC) | 534 | 15.2k | { | 535 | 15.2k | abfd->flags |= WP_TEXT; | 536 | 15.2k | adata (abfd).magic = n_magic; | 537 | 15.2k | } | 538 | 15.8k | else if (N_MAGIC (execp) == OMAGIC || N_IS_BMAGIC (execp)) | 539 | 15.8k | adata (abfd).magic = o_magic; | 540 | 0 | else | 541 | | /* Should have been checked with N_BADMAG before this routine | 542 | | was called. */ | 543 | 0 | abort (); | 544 | | | 545 | 49.7k | abfd->start_address = execp->a_entry; | 546 | | | 547 | 49.7k | abfd->symcount = execp->a_syms / sizeof (struct external_nlist); | 548 | | | 549 | | /* The default relocation entry size is that of traditional V7 Unix. */ | 550 | 49.7k | obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; | 551 | | | 552 | | /* The default symbol entry size is that of traditional Unix. */ | 553 | 49.7k | obj_symbol_entry_size (abfd) = EXTERNAL_NLIST_SIZE; | 554 | | | 555 | 49.7k | if (! NAME (aout, make_sections) (abfd)) | 556 | 0 | goto error_ret; | 557 | | | 558 | 49.7k | obj_datasec (abfd)->size = execp->a_data; | 559 | 49.7k | obj_bsssec (abfd)->size = execp->a_bss; | 560 | | | 561 | 49.7k | obj_textsec (abfd)->flags = | 562 | 49.7k | (execp->a_trsize != 0 | 563 | 49.7k | ? (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | SEC_RELOC) | 564 | 49.7k | : (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)); | 565 | 49.7k | obj_datasec (abfd)->flags = | 566 | 49.7k | (execp->a_drsize != 0 | 567 | 49.7k | ? (SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS | SEC_RELOC) | 568 | 49.7k | : (SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS)); | 569 | 49.7k | obj_bsssec (abfd)->flags = SEC_ALLOC; | 570 | | | 571 | | #ifdef THIS_IS_ONLY_DOCUMENTATION | 572 | | /* The common code can't fill in these things because they depend | 573 | | on either the start address of the text segment, the rounding | 574 | | up of virtual addresses between segments, or the starting file | 575 | | position of the text segment -- all of which varies among different | 576 | | versions of a.out. */ | 577 | | | 578 | | /* Call back to the format-dependent code to fill in the rest of the | 579 | | fields and do any further cleanup. Things that should be filled | 580 | | in by the callback: */ | 581 | | struct exec *execp = exec_hdr (abfd); | 582 | | | 583 | | obj_textsec (abfd)->size = N_TXTSIZE (execp); | 584 | | /* Data and bss are already filled in since they're so standard. */ | 585 | | | 586 | | /* The virtual memory addresses of the sections. */ | 587 | | obj_textsec (abfd)->vma = N_TXTADDR (execp); | 588 | | obj_datasec (abfd)->vma = N_DATADDR (execp); | 589 | | obj_bsssec (abfd)->vma = N_BSSADDR (execp); | 590 | | | 591 | | /* The file offsets of the sections. */ | 592 | | obj_textsec (abfd)->filepos = N_TXTOFF (execp); | 593 | | obj_datasec (abfd)->filepos = N_DATOFF (execp); | 594 | | | 595 | | /* The file offsets of the relocation info. */ | 596 | | obj_textsec (abfd)->rel_filepos = N_TRELOFF (execp); | 597 | | obj_datasec (abfd)->rel_filepos = N_DRELOFF (execp); | 598 | | | 599 | | /* The file offsets of the string table and symbol table. */ | 600 | | obj_str_filepos (abfd) = N_STROFF (execp); | 601 | | obj_sym_filepos (abfd) = N_SYMOFF (execp); | 602 | | | 603 | | /* Determine the architecture and machine type of the object file. */ | 604 | | abfd->obj_arch = bfd_arch_obscure; | 605 | | | 606 | | adata (abfd)->page_size = TARGET_PAGE_SIZE; | 607 | | adata (abfd)->segment_size = SEGMENT_SIZE; | 608 | | adata (abfd)->exec_bytes_size = EXEC_BYTES_SIZE; | 609 | | | 610 | | return _bfd_no_cleanup; | 611 | | | 612 | | /* The architecture is encoded in various ways in various a.out variants, | 613 | | or is not encoded at all in some of them. The relocation size depends | 614 | | on the architecture and the a.out variant. Finally, the return value | 615 | | is the bfd_target vector in use. If an error occurs, return zero and | 616 | | set bfd_error to the appropriate error code. | 617 | | | 618 | | Formats such as b.out, which have additional fields in the a.out | 619 | | header, should cope with them in this callback as well. */ | 620 | | #endif /* DOCUMENTATION */ | 621 | | | 622 | 49.7k | result = (*callback_to_real_object_p) (abfd); | 623 | | | 624 | | /* Now that the segment addresses have been worked out, take a better | 625 | | guess at whether the file is executable. If the entry point | 626 | | is within the text segment, assume it is. (This makes files | 627 | | executable even if their entry point address is 0, as long as | 628 | | their text starts at zero.). | 629 | | | 630 | | This test had to be changed to deal with systems where the text segment | 631 | | runs at a different location than the default. The problem is that the | 632 | | entry address can appear to be outside the text segment, thus causing an | 633 | | erroneous conclusion that the file isn't executable. | 634 | | | 635 | | To fix this, we now accept any non-zero entry point as an indication of | 636 | | executability. This will work most of the time, since only the linker | 637 | | sets the entry point, and that is likely to be non-zero for most systems. */ | 638 | | | 639 | 49.7k | if (execp->a_entry != 0 | 640 | 49.7k | || (execp->a_entry >= obj_textsec (abfd)->vma | 641 | 20.7k | && execp->a_entry < (obj_textsec (abfd)->vma | 642 | 16.8k | + obj_textsec (abfd)->size) | 643 | 20.7k | && execp->a_trsize == 0 | 644 | 20.7k | && execp->a_drsize == 0)) | 645 | 31.6k | abfd->flags |= EXEC_P; | 646 | | #ifdef STAT_FOR_EXEC | 647 | | else | 648 | | { | 649 | | struct stat stat_buf; | 650 | | | 651 | | /* The original heuristic doesn't work in some important cases. | 652 | | The a.out file has no information about the text start | 653 | | address. For files (like kernels) linked to non-standard | 654 | | addresses (ld -Ttext nnn) the entry point may not be between | 655 | | the default text start (obj_textsec(abfd)->vma) and | 656 | | (obj_textsec(abfd)->vma) + text size. This is not just a mach | 657 | | issue. Many kernels are loaded at non standard addresses. */ | 658 | | if (abfd->iostream != NULL | 659 | | && (abfd->flags & BFD_IN_MEMORY) == 0 | 660 | | && (fstat (fileno ((FILE *) (abfd->iostream)), &stat_buf) == 0) | 661 | | && ((stat_buf.st_mode & 0111) != 0)) | 662 | | abfd->flags |= EXEC_P; | 663 | | } | 664 | | #endif /* STAT_FOR_EXEC */ | 665 | | | 666 | 49.7k | if (result) | 667 | 49.7k | return result; | 668 | | | 669 | 0 | error_ret: | 670 | 0 | bfd_release (abfd, rawptr); | 671 | 0 | return NULL; | 672 | 49.7k | } |
|
673 | | |
674 | | /* |
675 | | FUNCTION |
676 | | aout_@var{size}_mkobject |
677 | | |
678 | | SYNOPSIS |
679 | | bool aout_@var{size}_mkobject, (bfd *abfd); |
680 | | |
681 | | DESCRIPTION |
682 | | Initialize BFD @var{abfd} for use with a.out files. |
683 | | */ |
684 | | |
685 | | bool |
686 | | NAME (aout, mkobject) (bfd *abfd) |
687 | 611k | { |
688 | 611k | struct aout_data_struct *rawptr; |
689 | 611k | size_t amt = sizeof (* rawptr); |
690 | | |
691 | 611k | bfd_set_error (bfd_error_system_call); |
692 | | |
693 | 611k | rawptr = (struct aout_data_struct *) bfd_zalloc (abfd, amt); |
694 | 611k | if (rawptr == NULL) |
695 | 0 | return false; |
696 | | |
697 | 611k | abfd->tdata.aout_data = rawptr; |
698 | 611k | exec_hdr (abfd) = &(rawptr->e); |
699 | | |
700 | 611k | obj_textsec (abfd) = NULL; |
701 | 611k | obj_datasec (abfd) = NULL; |
702 | 611k | obj_bsssec (abfd) = NULL; |
703 | | |
704 | 611k | return true; |
705 | 611k | } Unexecuted instantiation: cris_aout_32_mkobject Line | Count | Source | 687 | 1 | { | 688 | 1 | struct aout_data_struct *rawptr; | 689 | 1 | size_t amt = sizeof (* rawptr); | 690 | | | 691 | 1 | bfd_set_error (bfd_error_system_call); | 692 | | | 693 | 1 | rawptr = (struct aout_data_struct *) bfd_zalloc (abfd, amt); | 694 | 1 | if (rawptr == NULL) | 695 | 0 | return false; | 696 | | | 697 | 1 | abfd->tdata.aout_data = rawptr; | 698 | 1 | exec_hdr (abfd) = &(rawptr->e); | 699 | | | 700 | 1 | obj_textsec (abfd) = NULL; | 701 | 1 | obj_datasec (abfd) = NULL; | 702 | 1 | obj_bsssec (abfd) = NULL; | 703 | | | 704 | 1 | return true; | 705 | 1 | } |
Line | Count | Source | 687 | 611k | { | 688 | 611k | struct aout_data_struct *rawptr; | 689 | 611k | size_t amt = sizeof (* rawptr); | 690 | | | 691 | 611k | bfd_set_error (bfd_error_system_call); | 692 | | | 693 | 611k | rawptr = (struct aout_data_struct *) bfd_zalloc (abfd, amt); | 694 | 611k | if (rawptr == NULL) | 695 | 0 | return false; | 696 | | | 697 | 611k | abfd->tdata.aout_data = rawptr; | 698 | 611k | exec_hdr (abfd) = &(rawptr->e); | 699 | | | 700 | 611k | obj_textsec (abfd) = NULL; | 701 | 611k | obj_datasec (abfd) = NULL; | 702 | 611k | obj_bsssec (abfd) = NULL; | 703 | | | 704 | 611k | return true; | 705 | 611k | } |
|
706 | | |
707 | | /* |
708 | | FUNCTION |
709 | | aout_@var{size}_machine_type |
710 | | |
711 | | SYNOPSIS |
712 | | enum machine_type aout_@var{size}_machine_type |
713 | | (enum bfd_architecture arch, |
714 | | unsigned long machine, |
715 | | bool *unknown); |
716 | | |
717 | | DESCRIPTION |
718 | | Keep track of machine architecture and machine type for |
719 | | a.out's. Return the <<machine_type>> for a particular |
720 | | architecture and machine, or <<M_UNKNOWN>> if that exact architecture |
721 | | and machine can't be represented in a.out format. |
722 | | |
723 | | If the architecture is understood, machine type 0 (default) |
724 | | is always understood. |
725 | | */ |
726 | | |
727 | | enum machine_type |
728 | | NAME (aout, machine_type) (enum bfd_architecture arch, |
729 | | unsigned long machine, |
730 | | bool *unknown) |
731 | 5.73k | { |
732 | 5.73k | enum machine_type arch_flags; |
733 | | |
734 | 5.73k | arch_flags = M_UNKNOWN; |
735 | 5.73k | *unknown = true; |
736 | | |
737 | 5.73k | switch (arch) |
738 | 5.73k | { |
739 | 0 | case bfd_arch_sparc: |
740 | 0 | if (machine == 0 |
741 | 0 | || machine == bfd_mach_sparc |
742 | 0 | || machine == bfd_mach_sparc_sparclite |
743 | 0 | || machine == bfd_mach_sparc_sparclite_le |
744 | 0 | || machine == bfd_mach_sparc_v8plus |
745 | 0 | || machine == bfd_mach_sparc_v8plusa |
746 | 0 | || machine == bfd_mach_sparc_v8plusb |
747 | 0 | || machine == bfd_mach_sparc_v8plusc |
748 | 0 | || machine == bfd_mach_sparc_v8plusd |
749 | 0 | || machine == bfd_mach_sparc_v8pluse |
750 | 0 | || machine == bfd_mach_sparc_v8plusv |
751 | 0 | || machine == bfd_mach_sparc_v8plusm |
752 | 0 | || machine == bfd_mach_sparc_v8plusm8 |
753 | 0 | || machine == bfd_mach_sparc_v9 |
754 | 0 | || machine == bfd_mach_sparc_v9a |
755 | 0 | || machine == bfd_mach_sparc_v9b |
756 | 0 | || machine == bfd_mach_sparc_v9c |
757 | 0 | || machine == bfd_mach_sparc_v9d |
758 | 0 | || machine == bfd_mach_sparc_v9e |
759 | 0 | || machine == bfd_mach_sparc_v9v |
760 | 0 | || machine == bfd_mach_sparc_v9m |
761 | 0 | || machine == bfd_mach_sparc_v9m8) |
762 | 0 | arch_flags = M_SPARC; |
763 | 0 | else if (machine == bfd_mach_sparc_sparclet) |
764 | 0 | arch_flags = M_SPARCLET; |
765 | 0 | break; |
766 | | |
767 | 0 | case bfd_arch_i386: |
768 | 0 | if (machine == 0 |
769 | 0 | || machine == bfd_mach_i386_i386 |
770 | 0 | || machine == bfd_mach_i386_i386_intel_syntax) |
771 | 0 | arch_flags = M_386; |
772 | 0 | break; |
773 | | |
774 | 0 | case bfd_arch_arm: |
775 | 0 | if (machine == 0) |
776 | 0 | arch_flags = M_ARM; |
777 | 0 | break; |
778 | | |
779 | 0 | case bfd_arch_mips: |
780 | 0 | switch (machine) |
781 | 0 | { |
782 | 0 | case 0: |
783 | 0 | case bfd_mach_mips3000: |
784 | 0 | case bfd_mach_mips3900: |
785 | 0 | arch_flags = M_MIPS1; |
786 | 0 | break; |
787 | 0 | case bfd_mach_mips6000: |
788 | 0 | arch_flags = M_MIPS2; |
789 | 0 | break; |
790 | 0 | case bfd_mach_mips4000: |
791 | 0 | case bfd_mach_mips4010: |
792 | 0 | case bfd_mach_mips4100: |
793 | 0 | case bfd_mach_mips4300: |
794 | 0 | case bfd_mach_mips4400: |
795 | 0 | case bfd_mach_mips4600: |
796 | 0 | case bfd_mach_mips4650: |
797 | 0 | case bfd_mach_mips8000: |
798 | 0 | case bfd_mach_mips9000: |
799 | 0 | case bfd_mach_mips10000: |
800 | 0 | case bfd_mach_mips12000: |
801 | 0 | case bfd_mach_mips14000: |
802 | 0 | case bfd_mach_mips16000: |
803 | 0 | case bfd_mach_mips16: |
804 | 0 | case bfd_mach_mipsisa32: |
805 | 0 | case bfd_mach_mipsisa32r2: |
806 | 0 | case bfd_mach_mipsisa32r3: |
807 | 0 | case bfd_mach_mipsisa32r5: |
808 | 0 | case bfd_mach_mipsisa32r6: |
809 | 0 | case bfd_mach_mips5: |
810 | 0 | case bfd_mach_mipsisa64: |
811 | 0 | case bfd_mach_mipsisa64r2: |
812 | 0 | case bfd_mach_mipsisa64r3: |
813 | 0 | case bfd_mach_mipsisa64r5: |
814 | 0 | case bfd_mach_mipsisa64r6: |
815 | 0 | case bfd_mach_mips_sb1: |
816 | 0 | case bfd_mach_mips_xlr: |
817 | | /* FIXME: These should be MIPS3, MIPS4, MIPS16, MIPS32, etc. */ |
818 | 0 | arch_flags = M_MIPS2; |
819 | 0 | break; |
820 | 0 | default: |
821 | 0 | arch_flags = M_UNKNOWN; |
822 | 0 | break; |
823 | 0 | } |
824 | 0 | break; |
825 | | |
826 | 1 | case bfd_arch_ns32k: |
827 | 1 | switch (machine) |
828 | 1 | { |
829 | 0 | case 0: arch_flags = M_NS32532; break; |
830 | 0 | case 32032: arch_flags = M_NS32032; break; |
831 | 1 | case 32532: arch_flags = M_NS32532; break; |
832 | 0 | default: arch_flags = M_UNKNOWN; break; |
833 | 1 | } |
834 | 1 | break; |
835 | | |
836 | 4 | case bfd_arch_vax: |
837 | 4 | *unknown = false; |
838 | 4 | break; |
839 | | |
840 | 5.72k | case bfd_arch_cris: |
841 | 5.72k | if (machine == 0 || machine == 255) |
842 | 5.72k | arch_flags = M_CRIS; |
843 | 5.72k | break; |
844 | | |
845 | 0 | default: |
846 | 0 | arch_flags = M_UNKNOWN; |
847 | 5.73k | } |
848 | | |
849 | 5.73k | if (arch_flags != M_UNKNOWN) |
850 | 5.72k | *unknown = false; |
851 | | |
852 | 5.73k | return arch_flags; |
853 | 5.73k | } cris_aout_32_machine_type Line | Count | Source | 731 | 5.72k | { | 732 | 5.72k | enum machine_type arch_flags; | 733 | | | 734 | 5.72k | arch_flags = M_UNKNOWN; | 735 | 5.72k | *unknown = true; | 736 | | | 737 | 5.72k | switch (arch) | 738 | 5.72k | { | 739 | 0 | case bfd_arch_sparc: | 740 | 0 | if (machine == 0 | 741 | 0 | || machine == bfd_mach_sparc | 742 | 0 | || machine == bfd_mach_sparc_sparclite | 743 | 0 | || machine == bfd_mach_sparc_sparclite_le | 744 | 0 | || machine == bfd_mach_sparc_v8plus | 745 | 0 | || machine == bfd_mach_sparc_v8plusa | 746 | 0 | || machine == bfd_mach_sparc_v8plusb | 747 | 0 | || machine == bfd_mach_sparc_v8plusc | 748 | 0 | || machine == bfd_mach_sparc_v8plusd | 749 | 0 | || machine == bfd_mach_sparc_v8pluse | 750 | 0 | || machine == bfd_mach_sparc_v8plusv | 751 | 0 | || machine == bfd_mach_sparc_v8plusm | 752 | 0 | || machine == bfd_mach_sparc_v8plusm8 | 753 | 0 | || machine == bfd_mach_sparc_v9 | 754 | 0 | || machine == bfd_mach_sparc_v9a | 755 | 0 | || machine == bfd_mach_sparc_v9b | 756 | 0 | || machine == bfd_mach_sparc_v9c | 757 | 0 | || machine == bfd_mach_sparc_v9d | 758 | 0 | || machine == bfd_mach_sparc_v9e | 759 | 0 | || machine == bfd_mach_sparc_v9v | 760 | 0 | || machine == bfd_mach_sparc_v9m | 761 | 0 | || machine == bfd_mach_sparc_v9m8) | 762 | 0 | arch_flags = M_SPARC; | 763 | 0 | else if (machine == bfd_mach_sparc_sparclet) | 764 | 0 | arch_flags = M_SPARCLET; | 765 | 0 | break; | 766 | | | 767 | 0 | case bfd_arch_i386: | 768 | 0 | if (machine == 0 | 769 | 0 | || machine == bfd_mach_i386_i386 | 770 | 0 | || machine == bfd_mach_i386_i386_intel_syntax) | 771 | 0 | arch_flags = M_386; | 772 | 0 | break; | 773 | | | 774 | 0 | case bfd_arch_arm: | 775 | 0 | if (machine == 0) | 776 | 0 | arch_flags = M_ARM; | 777 | 0 | break; | 778 | | | 779 | 0 | case bfd_arch_mips: | 780 | 0 | switch (machine) | 781 | 0 | { | 782 | 0 | case 0: | 783 | 0 | case bfd_mach_mips3000: | 784 | 0 | case bfd_mach_mips3900: | 785 | 0 | arch_flags = M_MIPS1; | 786 | 0 | break; | 787 | 0 | case bfd_mach_mips6000: | 788 | 0 | arch_flags = M_MIPS2; | 789 | 0 | break; | 790 | 0 | case bfd_mach_mips4000: | 791 | 0 | case bfd_mach_mips4010: | 792 | 0 | case bfd_mach_mips4100: | 793 | 0 | case bfd_mach_mips4300: | 794 | 0 | case bfd_mach_mips4400: | 795 | 0 | case bfd_mach_mips4600: | 796 | 0 | case bfd_mach_mips4650: | 797 | 0 | case bfd_mach_mips8000: | 798 | 0 | case bfd_mach_mips9000: | 799 | 0 | case bfd_mach_mips10000: | 800 | 0 | case bfd_mach_mips12000: | 801 | 0 | case bfd_mach_mips14000: | 802 | 0 | case bfd_mach_mips16000: | 803 | 0 | case bfd_mach_mips16: | 804 | 0 | case bfd_mach_mipsisa32: | 805 | 0 | case bfd_mach_mipsisa32r2: | 806 | 0 | case bfd_mach_mipsisa32r3: | 807 | 0 | case bfd_mach_mipsisa32r5: | 808 | 0 | case bfd_mach_mipsisa32r6: | 809 | 0 | case bfd_mach_mips5: | 810 | 0 | case bfd_mach_mipsisa64: | 811 | 0 | case bfd_mach_mipsisa64r2: | 812 | 0 | case bfd_mach_mipsisa64r3: | 813 | 0 | case bfd_mach_mipsisa64r5: | 814 | 0 | case bfd_mach_mipsisa64r6: | 815 | 0 | case bfd_mach_mips_sb1: | 816 | 0 | case bfd_mach_mips_xlr: | 817 | | /* FIXME: These should be MIPS3, MIPS4, MIPS16, MIPS32, etc. */ | 818 | 0 | arch_flags = M_MIPS2; | 819 | 0 | break; | 820 | 0 | default: | 821 | 0 | arch_flags = M_UNKNOWN; | 822 | 0 | break; | 823 | 0 | } | 824 | 0 | break; | 825 | | | 826 | 0 | case bfd_arch_ns32k: | 827 | 0 | switch (machine) | 828 | 0 | { | 829 | 0 | case 0: arch_flags = M_NS32532; break; | 830 | 0 | case 32032: arch_flags = M_NS32032; break; | 831 | 0 | case 32532: arch_flags = M_NS32532; break; | 832 | 0 | default: arch_flags = M_UNKNOWN; break; | 833 | 0 | } | 834 | 0 | break; | 835 | | | 836 | 0 | case bfd_arch_vax: | 837 | 0 | *unknown = false; | 838 | 0 | break; | 839 | | | 840 | 5.72k | case bfd_arch_cris: | 841 | 5.72k | if (machine == 0 || machine == 255) | 842 | 5.72k | arch_flags = M_CRIS; | 843 | 5.72k | break; | 844 | | | 845 | 0 | default: | 846 | 0 | arch_flags = M_UNKNOWN; | 847 | 5.72k | } | 848 | | | 849 | 5.72k | if (arch_flags != M_UNKNOWN) | 850 | 5.72k | *unknown = false; | 851 | | | 852 | 5.72k | return arch_flags; | 853 | 5.72k | } |
ns32kaout_32_machine_type Line | Count | Source | 731 | 1 | { | 732 | 1 | enum machine_type arch_flags; | 733 | | | 734 | 1 | arch_flags = M_UNKNOWN; | 735 | 1 | *unknown = true; | 736 | | | 737 | 1 | switch (arch) | 738 | 1 | { | 739 | 0 | case bfd_arch_sparc: | 740 | 0 | if (machine == 0 | 741 | 0 | || machine == bfd_mach_sparc | 742 | 0 | || machine == bfd_mach_sparc_sparclite | 743 | 0 | || machine == bfd_mach_sparc_sparclite_le | 744 | 0 | || machine == bfd_mach_sparc_v8plus | 745 | 0 | || machine == bfd_mach_sparc_v8plusa | 746 | 0 | || machine == bfd_mach_sparc_v8plusb | 747 | 0 | || machine == bfd_mach_sparc_v8plusc | 748 | 0 | || machine == bfd_mach_sparc_v8plusd | 749 | 0 | || machine == bfd_mach_sparc_v8pluse | 750 | 0 | || machine == bfd_mach_sparc_v8plusv | 751 | 0 | || machine == bfd_mach_sparc_v8plusm | 752 | 0 | || machine == bfd_mach_sparc_v8plusm8 | 753 | 0 | || machine == bfd_mach_sparc_v9 | 754 | 0 | || machine == bfd_mach_sparc_v9a | 755 | 0 | || machine == bfd_mach_sparc_v9b | 756 | 0 | || machine == bfd_mach_sparc_v9c | 757 | 0 | || machine == bfd_mach_sparc_v9d | 758 | 0 | || machine == bfd_mach_sparc_v9e | 759 | 0 | || machine == bfd_mach_sparc_v9v | 760 | 0 | || machine == bfd_mach_sparc_v9m | 761 | 0 | || machine == bfd_mach_sparc_v9m8) | 762 | 0 | arch_flags = M_SPARC; | 763 | 0 | else if (machine == bfd_mach_sparc_sparclet) | 764 | 0 | arch_flags = M_SPARCLET; | 765 | 0 | break; | 766 | | | 767 | 0 | case bfd_arch_i386: | 768 | 0 | if (machine == 0 | 769 | 0 | || machine == bfd_mach_i386_i386 | 770 | 0 | || machine == bfd_mach_i386_i386_intel_syntax) | 771 | 0 | arch_flags = M_386; | 772 | 0 | break; | 773 | | | 774 | 0 | case bfd_arch_arm: | 775 | 0 | if (machine == 0) | 776 | 0 | arch_flags = M_ARM; | 777 | 0 | break; | 778 | | | 779 | 0 | case bfd_arch_mips: | 780 | 0 | switch (machine) | 781 | 0 | { | 782 | 0 | case 0: | 783 | 0 | case bfd_mach_mips3000: | 784 | 0 | case bfd_mach_mips3900: | 785 | 0 | arch_flags = M_MIPS1; | 786 | 0 | break; | 787 | 0 | case bfd_mach_mips6000: | 788 | 0 | arch_flags = M_MIPS2; | 789 | 0 | break; | 790 | 0 | case bfd_mach_mips4000: | 791 | 0 | case bfd_mach_mips4010: | 792 | 0 | case bfd_mach_mips4100: | 793 | 0 | case bfd_mach_mips4300: | 794 | 0 | case bfd_mach_mips4400: | 795 | 0 | case bfd_mach_mips4600: | 796 | 0 | case bfd_mach_mips4650: | 797 | 0 | case bfd_mach_mips8000: | 798 | 0 | case bfd_mach_mips9000: | 799 | 0 | case bfd_mach_mips10000: | 800 | 0 | case bfd_mach_mips12000: | 801 | 0 | case bfd_mach_mips14000: | 802 | 0 | case bfd_mach_mips16000: | 803 | 0 | case bfd_mach_mips16: | 804 | 0 | case bfd_mach_mipsisa32: | 805 | 0 | case bfd_mach_mipsisa32r2: | 806 | 0 | case bfd_mach_mipsisa32r3: | 807 | 0 | case bfd_mach_mipsisa32r5: | 808 | 0 | case bfd_mach_mipsisa32r6: | 809 | 0 | case bfd_mach_mips5: | 810 | 0 | case bfd_mach_mipsisa64: | 811 | 0 | case bfd_mach_mipsisa64r2: | 812 | 0 | case bfd_mach_mipsisa64r3: | 813 | 0 | case bfd_mach_mipsisa64r5: | 814 | 0 | case bfd_mach_mipsisa64r6: | 815 | 0 | case bfd_mach_mips_sb1: | 816 | 0 | case bfd_mach_mips_xlr: | 817 | | /* FIXME: These should be MIPS3, MIPS4, MIPS16, MIPS32, etc. */ | 818 | 0 | arch_flags = M_MIPS2; | 819 | 0 | break; | 820 | 0 | default: | 821 | 0 | arch_flags = M_UNKNOWN; | 822 | 0 | break; | 823 | 0 | } | 824 | 0 | break; | 825 | | | 826 | 1 | case bfd_arch_ns32k: | 827 | 1 | switch (machine) | 828 | 1 | { | 829 | 0 | case 0: arch_flags = M_NS32532; break; | 830 | 0 | case 32032: arch_flags = M_NS32032; break; | 831 | 1 | case 32532: arch_flags = M_NS32532; break; | 832 | 0 | default: arch_flags = M_UNKNOWN; break; | 833 | 1 | } | 834 | 1 | break; | 835 | | | 836 | 1 | case bfd_arch_vax: | 837 | 0 | *unknown = false; | 838 | 0 | break; | 839 | | | 840 | 0 | case bfd_arch_cris: | 841 | 0 | if (machine == 0 || machine == 255) | 842 | 0 | arch_flags = M_CRIS; | 843 | 0 | break; | 844 | | | 845 | 0 | default: | 846 | 0 | arch_flags = M_UNKNOWN; | 847 | 1 | } | 848 | | | 849 | 1 | if (arch_flags != M_UNKNOWN) | 850 | 1 | *unknown = false; | 851 | | | 852 | 1 | return arch_flags; | 853 | 1 | } |
Line | Count | Source | 731 | 4 | { | 732 | 4 | enum machine_type arch_flags; | 733 | | | 734 | 4 | arch_flags = M_UNKNOWN; | 735 | 4 | *unknown = true; | 736 | | | 737 | 4 | switch (arch) | 738 | 4 | { | 739 | 0 | case bfd_arch_sparc: | 740 | 0 | if (machine == 0 | 741 | 0 | || machine == bfd_mach_sparc | 742 | 0 | || machine == bfd_mach_sparc_sparclite | 743 | 0 | || machine == bfd_mach_sparc_sparclite_le | 744 | 0 | || machine == bfd_mach_sparc_v8plus | 745 | 0 | || machine == bfd_mach_sparc_v8plusa | 746 | 0 | || machine == bfd_mach_sparc_v8plusb | 747 | 0 | || machine == bfd_mach_sparc_v8plusc | 748 | 0 | || machine == bfd_mach_sparc_v8plusd | 749 | 0 | || machine == bfd_mach_sparc_v8pluse | 750 | 0 | || machine == bfd_mach_sparc_v8plusv | 751 | 0 | || machine == bfd_mach_sparc_v8plusm | 752 | 0 | || machine == bfd_mach_sparc_v8plusm8 | 753 | 0 | || machine == bfd_mach_sparc_v9 | 754 | 0 | || machine == bfd_mach_sparc_v9a | 755 | 0 | || machine == bfd_mach_sparc_v9b | 756 | 0 | || machine == bfd_mach_sparc_v9c | 757 | 0 | || machine == bfd_mach_sparc_v9d | 758 | 0 | || machine == bfd_mach_sparc_v9e | 759 | 0 | || machine == bfd_mach_sparc_v9v | 760 | 0 | || machine == bfd_mach_sparc_v9m | 761 | 0 | || machine == bfd_mach_sparc_v9m8) | 762 | 0 | arch_flags = M_SPARC; | 763 | 0 | else if (machine == bfd_mach_sparc_sparclet) | 764 | 0 | arch_flags = M_SPARCLET; | 765 | 0 | break; | 766 | | | 767 | 0 | case bfd_arch_i386: | 768 | 0 | if (machine == 0 | 769 | 0 | || machine == bfd_mach_i386_i386 | 770 | 0 | || machine == bfd_mach_i386_i386_intel_syntax) | 771 | 0 | arch_flags = M_386; | 772 | 0 | break; | 773 | | | 774 | 0 | case bfd_arch_arm: | 775 | 0 | if (machine == 0) | 776 | 0 | arch_flags = M_ARM; | 777 | 0 | break; | 778 | | | 779 | 0 | case bfd_arch_mips: | 780 | 0 | switch (machine) | 781 | 0 | { | 782 | 0 | case 0: | 783 | 0 | case bfd_mach_mips3000: | 784 | 0 | case bfd_mach_mips3900: | 785 | 0 | arch_flags = M_MIPS1; | 786 | 0 | break; | 787 | 0 | case bfd_mach_mips6000: | 788 | 0 | arch_flags = M_MIPS2; | 789 | 0 | break; | 790 | 0 | case bfd_mach_mips4000: | 791 | 0 | case bfd_mach_mips4010: | 792 | 0 | case bfd_mach_mips4100: | 793 | 0 | case bfd_mach_mips4300: | 794 | 0 | case bfd_mach_mips4400: | 795 | 0 | case bfd_mach_mips4600: | 796 | 0 | case bfd_mach_mips4650: | 797 | 0 | case bfd_mach_mips8000: | 798 | 0 | case bfd_mach_mips9000: | 799 | 0 | case bfd_mach_mips10000: | 800 | 0 | case bfd_mach_mips12000: | 801 | 0 | case bfd_mach_mips14000: | 802 | 0 | case bfd_mach_mips16000: | 803 | 0 | case bfd_mach_mips16: | 804 | 0 | case bfd_mach_mipsisa32: | 805 | 0 | case bfd_mach_mipsisa32r2: | 806 | 0 | case bfd_mach_mipsisa32r3: | 807 | 0 | case bfd_mach_mipsisa32r5: | 808 | 0 | case bfd_mach_mipsisa32r6: | 809 | 0 | case bfd_mach_mips5: | 810 | 0 | case bfd_mach_mipsisa64: | 811 | 0 | case bfd_mach_mipsisa64r2: | 812 | 0 | case bfd_mach_mipsisa64r3: | 813 | 0 | case bfd_mach_mipsisa64r5: | 814 | 0 | case bfd_mach_mipsisa64r6: | 815 | 0 | case bfd_mach_mips_sb1: | 816 | 0 | case bfd_mach_mips_xlr: | 817 | | /* FIXME: These should be MIPS3, MIPS4, MIPS16, MIPS32, etc. */ | 818 | 0 | arch_flags = M_MIPS2; | 819 | 0 | break; | 820 | 0 | default: | 821 | 0 | arch_flags = M_UNKNOWN; | 822 | 0 | break; | 823 | 0 | } | 824 | 0 | break; | 825 | | | 826 | 0 | case bfd_arch_ns32k: | 827 | 0 | switch (machine) | 828 | 0 | { | 829 | 0 | case 0: arch_flags = M_NS32532; break; | 830 | 0 | case 32032: arch_flags = M_NS32032; break; | 831 | 0 | case 32532: arch_flags = M_NS32532; break; | 832 | 0 | default: arch_flags = M_UNKNOWN; break; | 833 | 0 | } | 834 | 0 | break; | 835 | | | 836 | 4 | case bfd_arch_vax: | 837 | 4 | *unknown = false; | 838 | 4 | break; | 839 | | | 840 | 0 | case bfd_arch_cris: | 841 | 0 | if (machine == 0 || machine == 255) | 842 | 0 | arch_flags = M_CRIS; | 843 | 0 | break; | 844 | | | 845 | 0 | default: | 846 | 0 | arch_flags = M_UNKNOWN; | 847 | 4 | } | 848 | | | 849 | 4 | if (arch_flags != M_UNKNOWN) | 850 | 0 | *unknown = false; | 851 | | | 852 | 4 | return arch_flags; | 853 | 4 | } |
|
854 | | |
855 | | /* |
856 | | FUNCTION |
857 | | aout_@var{size}_set_arch_mach |
858 | | |
859 | | SYNOPSIS |
860 | | bool aout_@var{size}_set_arch_mach, |
861 | | (bfd *, |
862 | | enum bfd_architecture arch, |
863 | | unsigned long machine); |
864 | | |
865 | | DESCRIPTION |
866 | | Set the architecture and the machine of the BFD @var{abfd} to the |
867 | | values @var{arch} and @var{machine}. Verify that @var{abfd}'s format |
868 | | can support the architecture required. |
869 | | */ |
870 | | |
871 | | bool |
872 | | NAME (aout, set_arch_mach) (bfd *abfd, |
873 | | enum bfd_architecture arch, |
874 | | unsigned long machine) |
875 | 5.73k | { |
876 | 5.73k | if (! bfd_default_set_arch_mach (abfd, arch, machine)) |
877 | 0 | return false; |
878 | | |
879 | 5.73k | if (arch != bfd_arch_unknown) |
880 | 5.73k | { |
881 | 5.73k | bool unknown; |
882 | | |
883 | 5.73k | NAME (aout, machine_type) (arch, machine, &unknown); |
884 | 5.73k | if (unknown) |
885 | 0 | return false; |
886 | 5.73k | } |
887 | | |
888 | | /* Determine the size of a relocation entry. */ |
889 | 5.73k | switch (arch) |
890 | 5.73k | { |
891 | 0 | case bfd_arch_sparc: |
892 | 0 | case bfd_arch_mips: |
893 | 0 | obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE; |
894 | 0 | break; |
895 | 5.73k | default: |
896 | 5.73k | obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; |
897 | 5.73k | break; |
898 | 5.73k | } |
899 | | |
900 | 5.73k | return (*aout_backend_info (abfd)->set_sizes) (abfd); |
901 | 5.73k | } cris_aout_32_set_arch_mach Line | Count | Source | 875 | 5.72k | { | 876 | 5.72k | if (! bfd_default_set_arch_mach (abfd, arch, machine)) | 877 | 0 | return false; | 878 | | | 879 | 5.72k | if (arch != bfd_arch_unknown) | 880 | 5.72k | { | 881 | 5.72k | bool unknown; | 882 | | | 883 | 5.72k | NAME (aout, machine_type) (arch, machine, &unknown); | 884 | 5.72k | if (unknown) | 885 | 0 | return false; | 886 | 5.72k | } | 887 | | | 888 | | /* Determine the size of a relocation entry. */ | 889 | 5.72k | switch (arch) | 890 | 5.72k | { | 891 | 0 | case bfd_arch_sparc: | 892 | 0 | case bfd_arch_mips: | 893 | 0 | obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE; | 894 | 0 | break; | 895 | 5.72k | default: | 896 | 5.72k | obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; | 897 | 5.72k | break; | 898 | 5.72k | } | 899 | | | 900 | 5.72k | return (*aout_backend_info (abfd)->set_sizes) (abfd); | 901 | 5.72k | } |
ns32kaout_32_set_arch_mach Line | Count | Source | 875 | 1 | { | 876 | 1 | if (! bfd_default_set_arch_mach (abfd, arch, machine)) | 877 | 0 | return false; | 878 | | | 879 | 1 | if (arch != bfd_arch_unknown) | 880 | 1 | { | 881 | 1 | bool unknown; | 882 | | | 883 | 1 | NAME (aout, machine_type) (arch, machine, &unknown); | 884 | 1 | if (unknown) | 885 | 0 | return false; | 886 | 1 | } | 887 | | | 888 | | /* Determine the size of a relocation entry. */ | 889 | 1 | switch (arch) | 890 | 1 | { | 891 | 0 | case bfd_arch_sparc: | 892 | 0 | case bfd_arch_mips: | 893 | 0 | obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE; | 894 | 0 | break; | 895 | 1 | default: | 896 | 1 | obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; | 897 | 1 | break; | 898 | 1 | } | 899 | | | 900 | 1 | return (*aout_backend_info (abfd)->set_sizes) (abfd); | 901 | 1 | } |
Line | Count | Source | 875 | 4 | { | 876 | 4 | if (! bfd_default_set_arch_mach (abfd, arch, machine)) | 877 | 0 | return false; | 878 | | | 879 | 4 | if (arch != bfd_arch_unknown) | 880 | 4 | { | 881 | 4 | bool unknown; | 882 | | | 883 | 4 | NAME (aout, machine_type) (arch, machine, &unknown); | 884 | 4 | if (unknown) | 885 | 0 | return false; | 886 | 4 | } | 887 | | | 888 | | /* Determine the size of a relocation entry. */ | 889 | 4 | switch (arch) | 890 | 4 | { | 891 | 0 | case bfd_arch_sparc: | 892 | 0 | case bfd_arch_mips: | 893 | 0 | obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE; | 894 | 0 | break; | 895 | 4 | default: | 896 | 4 | obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; | 897 | 4 | break; | 898 | 4 | } | 899 | | | 900 | 4 | return (*aout_backend_info (abfd)->set_sizes) (abfd); | 901 | 4 | } |
|
902 | | |
903 | | static void |
904 | | adjust_o_magic (bfd *abfd, struct internal_exec *execp) |
905 | 0 | { |
906 | 0 | file_ptr pos = adata (abfd).exec_bytes_size; |
907 | 0 | bfd_vma vma = 0; |
908 | 0 | int pad = 0; |
909 | 0 | asection *text = obj_textsec (abfd); |
910 | 0 | asection *data = obj_datasec (abfd); |
911 | 0 | asection *bss = obj_bsssec (abfd); |
912 | | |
913 | | /* Text. */ |
914 | 0 | text->filepos = pos; |
915 | 0 | if (!text->user_set_vma) |
916 | 0 | text->vma = vma; |
917 | 0 | else |
918 | 0 | vma = text->vma; |
919 | |
|
920 | 0 | pos += execp->a_text; |
921 | 0 | vma += execp->a_text; |
922 | | |
923 | | /* Data. */ |
924 | 0 | if (!data->user_set_vma) |
925 | 0 | { |
926 | 0 | pos += pad; |
927 | 0 | vma += pad; |
928 | 0 | data->vma = vma; |
929 | 0 | } |
930 | 0 | else |
931 | 0 | vma = data->vma; |
932 | 0 | execp->a_text += pad; |
933 | |
|
934 | 0 | data->filepos = pos; |
935 | 0 | pos += data->size; |
936 | 0 | vma += data->size; |
937 | | |
938 | | /* BSS. */ |
939 | 0 | if (!bss->user_set_vma) |
940 | 0 | { |
941 | 0 | pos += pad; |
942 | 0 | vma += pad; |
943 | 0 | bss->vma = vma; |
944 | 0 | } |
945 | 0 | else |
946 | 0 | { |
947 | | /* The VMA of the .bss section is set by the VMA of the |
948 | | .data section plus the size of the .data section. We may |
949 | | need to add padding bytes to make this true. */ |
950 | 0 | pad = bss->vma - vma; |
951 | 0 | if (pad < 0) |
952 | 0 | pad = 0; |
953 | 0 | pos += pad; |
954 | 0 | } |
955 | 0 | execp->a_data = data->size + pad; |
956 | 0 | bss->filepos = pos; |
957 | 0 | execp->a_bss = bss->size; |
958 | |
|
959 | 0 | N_SET_MAGIC (execp, OMAGIC); |
960 | 0 | } Unexecuted instantiation: aout-cris.c:adjust_o_magic Unexecuted instantiation: aout-ns32k.c:adjust_o_magic Unexecuted instantiation: aout32.c:adjust_o_magic |
961 | | |
962 | | static void |
963 | | adjust_z_magic (bfd *abfd, struct internal_exec *execp) |
964 | 4 | { |
965 | 4 | bfd_size_type data_pad, text_pad; |
966 | 4 | file_ptr text_end; |
967 | 4 | const struct aout_backend_data *abdp; |
968 | | /* TRUE if text includes exec header. */ |
969 | 4 | bool ztih; |
970 | 4 | asection *text = obj_textsec (abfd); |
971 | 4 | asection *data = obj_datasec (abfd); |
972 | 4 | asection *bss = obj_bsssec (abfd); |
973 | | |
974 | 4 | abdp = aout_backend_info (abfd); |
975 | | |
976 | | /* Text. */ |
977 | 4 | ztih = (abdp != NULL |
978 | 4 | && (abdp->text_includes_header |
979 | 4 | || obj_aout_subformat (abfd) == q_magic_format)); |
980 | 4 | text->filepos = (ztih |
981 | 4 | ? adata (abfd).exec_bytes_size |
982 | 4 | : adata (abfd).zmagic_disk_block_size); |
983 | 4 | if (!text->user_set_vma) |
984 | 1 | { |
985 | | /* ?? Do we really need to check for relocs here? */ |
986 | 1 | text->vma = ((abfd->flags & HAS_RELOC) |
987 | 1 | ? 0 |
988 | 1 | : (ztih |
989 | 0 | ? abdp->default_text_vma + adata (abfd).exec_bytes_size |
990 | 0 | : abdp->default_text_vma)); |
991 | 1 | text_pad = 0; |
992 | 1 | } |
993 | 3 | else |
994 | 3 | { |
995 | | /* The .text section is being loaded at an unusual address. We |
996 | | may need to pad it such that the .data section starts at a page |
997 | | boundary. */ |
998 | 3 | if (ztih) |
999 | 3 | text_pad = ((text->filepos - text->vma) |
1000 | 3 | & (adata (abfd).page_size - 1)); |
1001 | 0 | else |
1002 | 0 | text_pad = (-text->vma |
1003 | 0 | & (adata (abfd).page_size - 1)); |
1004 | 3 | } |
1005 | | |
1006 | | /* Find start of data. */ |
1007 | 4 | if (ztih) |
1008 | 4 | { |
1009 | 4 | text_end = text->filepos + execp->a_text; |
1010 | 4 | text_pad += BFD_ALIGN (text_end, adata (abfd).page_size) - text_end; |
1011 | 4 | } |
1012 | 0 | else |
1013 | 0 | { |
1014 | | /* Note that if page_size == zmagic_disk_block_size, then |
1015 | | filepos == page_size, and this case is the same as the ztih |
1016 | | case. */ |
1017 | 0 | text_end = execp->a_text; |
1018 | 0 | text_pad += BFD_ALIGN (text_end, adata (abfd).page_size) - text_end; |
1019 | 0 | text_end += text->filepos; |
1020 | 0 | } |
1021 | 4 | execp->a_text += text_pad; |
1022 | | |
1023 | | /* Data. */ |
1024 | 4 | if (!data->user_set_vma) |
1025 | 1 | { |
1026 | 1 | bfd_vma vma; |
1027 | 1 | vma = text->vma + execp->a_text; |
1028 | 1 | data->vma = BFD_ALIGN (vma, adata (abfd).segment_size); |
1029 | 1 | } |
1030 | 4 | if (abdp && abdp->zmagic_mapped_contiguous) |
1031 | 0 | { |
1032 | 0 | text_pad = data->vma - (text->vma + execp->a_text); |
1033 | | /* Only pad the text section if the data |
1034 | | section is going to be placed after it. */ |
1035 | 0 | if (text_pad > 0) |
1036 | 0 | execp->a_text += text_pad; |
1037 | 0 | } |
1038 | 4 | data->filepos = text->filepos + execp->a_text; |
1039 | | |
1040 | | /* Fix up exec header while we're at it. */ |
1041 | 4 | if (ztih && (!abdp || (abdp && !abdp->exec_header_not_counted))) |
1042 | 4 | execp->a_text += adata (abfd).exec_bytes_size; |
1043 | 4 | if (obj_aout_subformat (abfd) == q_magic_format) |
1044 | 4 | N_SET_QMAGIC (execp); |
1045 | 3 | else |
1046 | 3 | N_SET_MAGIC (execp, ZMAGIC); |
1047 | | |
1048 | | /* Spec says data section should be rounded up to page boundary. */ |
1049 | 4 | execp->a_data = align_power (data->size, bss->alignment_power); |
1050 | 4 | execp->a_data = BFD_ALIGN (execp->a_data, adata (abfd).page_size); |
1051 | 4 | data_pad = execp->a_data - data->size; |
1052 | | |
1053 | | /* BSS. */ |
1054 | 4 | if (!bss->user_set_vma) |
1055 | 1 | bss->vma = data->vma + execp->a_data; |
1056 | | /* If the BSS immediately follows the data section and extra space |
1057 | | in the page is left after the data section, fudge data |
1058 | | in the header so that the bss section looks smaller by that |
1059 | | amount. We'll start the bss section there, and lie to the OS. |
1060 | | (Note that a linker script, as well as the above assignment, |
1061 | | could have explicitly set the BSS vma to immediately follow |
1062 | | the data section.) */ |
1063 | 4 | if (align_power (bss->vma, bss->alignment_power) == data->vma + execp->a_data) |
1064 | 3 | execp->a_bss = data_pad > bss->size ? 0 : bss->size - data_pad; |
1065 | 1 | else |
1066 | 1 | execp->a_bss = bss->size; |
1067 | 4 | } Unexecuted instantiation: aout-cris.c:adjust_z_magic aout-ns32k.c:adjust_z_magic Line | Count | Source | 964 | 1 | { | 965 | 1 | bfd_size_type data_pad, text_pad; | 966 | 1 | file_ptr text_end; | 967 | 1 | const struct aout_backend_data *abdp; | 968 | | /* TRUE if text includes exec header. */ | 969 | 1 | bool ztih; | 970 | 1 | asection *text = obj_textsec (abfd); | 971 | 1 | asection *data = obj_datasec (abfd); | 972 | 1 | asection *bss = obj_bsssec (abfd); | 973 | | | 974 | 1 | abdp = aout_backend_info (abfd); | 975 | | | 976 | | /* Text. */ | 977 | 1 | ztih = (abdp != NULL | 978 | 1 | && (abdp->text_includes_header | 979 | 1 | || obj_aout_subformat (abfd) == q_magic_format)); | 980 | 1 | text->filepos = (ztih | 981 | 1 | ? adata (abfd).exec_bytes_size | 982 | 1 | : adata (abfd).zmagic_disk_block_size); | 983 | 1 | if (!text->user_set_vma) | 984 | 0 | { | 985 | | /* ?? Do we really need to check for relocs here? */ | 986 | 0 | text->vma = ((abfd->flags & HAS_RELOC) | 987 | 0 | ? 0 | 988 | 0 | : (ztih | 989 | 0 | ? abdp->default_text_vma + adata (abfd).exec_bytes_size | 990 | 0 | : abdp->default_text_vma)); | 991 | 0 | text_pad = 0; | 992 | 0 | } | 993 | 1 | else | 994 | 1 | { | 995 | | /* The .text section is being loaded at an unusual address. We | 996 | | may need to pad it such that the .data section starts at a page | 997 | | boundary. */ | 998 | 1 | if (ztih) | 999 | 1 | text_pad = ((text->filepos - text->vma) | 1000 | 1 | & (adata (abfd).page_size - 1)); | 1001 | 0 | else | 1002 | 0 | text_pad = (-text->vma | 1003 | 0 | & (adata (abfd).page_size - 1)); | 1004 | 1 | } | 1005 | | | 1006 | | /* Find start of data. */ | 1007 | 1 | if (ztih) | 1008 | 1 | { | 1009 | 1 | text_end = text->filepos + execp->a_text; | 1010 | 1 | text_pad += BFD_ALIGN (text_end, adata (abfd).page_size) - text_end; | 1011 | 1 | } | 1012 | 0 | else | 1013 | 0 | { | 1014 | | /* Note that if page_size == zmagic_disk_block_size, then | 1015 | | filepos == page_size, and this case is the same as the ztih | 1016 | | case. */ | 1017 | 0 | text_end = execp->a_text; | 1018 | 0 | text_pad += BFD_ALIGN (text_end, adata (abfd).page_size) - text_end; | 1019 | 0 | text_end += text->filepos; | 1020 | 0 | } | 1021 | 1 | execp->a_text += text_pad; | 1022 | | | 1023 | | /* Data. */ | 1024 | 1 | if (!data->user_set_vma) | 1025 | 0 | { | 1026 | 0 | bfd_vma vma; | 1027 | 0 | vma = text->vma + execp->a_text; | 1028 | 0 | data->vma = BFD_ALIGN (vma, adata (abfd).segment_size); | 1029 | 0 | } | 1030 | 1 | if (abdp && abdp->zmagic_mapped_contiguous) | 1031 | 0 | { | 1032 | 0 | text_pad = data->vma - (text->vma + execp->a_text); | 1033 | | /* Only pad the text section if the data | 1034 | | section is going to be placed after it. */ | 1035 | 0 | if (text_pad > 0) | 1036 | 0 | execp->a_text += text_pad; | 1037 | 0 | } | 1038 | 1 | data->filepos = text->filepos + execp->a_text; | 1039 | | | 1040 | | /* Fix up exec header while we're at it. */ | 1041 | 1 | if (ztih && (!abdp || (abdp && !abdp->exec_header_not_counted))) | 1042 | 1 | execp->a_text += adata (abfd).exec_bytes_size; | 1043 | 1 | if (obj_aout_subformat (abfd) == q_magic_format) | 1044 | 1 | N_SET_QMAGIC (execp); | 1045 | 0 | else | 1046 | 0 | N_SET_MAGIC (execp, ZMAGIC); | 1047 | | | 1048 | | /* Spec says data section should be rounded up to page boundary. */ | 1049 | 1 | execp->a_data = align_power (data->size, bss->alignment_power); | 1050 | 1 | execp->a_data = BFD_ALIGN (execp->a_data, adata (abfd).page_size); | 1051 | 1 | data_pad = execp->a_data - data->size; | 1052 | | | 1053 | | /* BSS. */ | 1054 | 1 | if (!bss->user_set_vma) | 1055 | 0 | bss->vma = data->vma + execp->a_data; | 1056 | | /* If the BSS immediately follows the data section and extra space | 1057 | | in the page is left after the data section, fudge data | 1058 | | in the header so that the bss section looks smaller by that | 1059 | | amount. We'll start the bss section there, and lie to the OS. | 1060 | | (Note that a linker script, as well as the above assignment, | 1061 | | could have explicitly set the BSS vma to immediately follow | 1062 | | the data section.) */ | 1063 | 1 | if (align_power (bss->vma, bss->alignment_power) == data->vma + execp->a_data) | 1064 | 0 | execp->a_bss = data_pad > bss->size ? 0 : bss->size - data_pad; | 1065 | 1 | else | 1066 | 1 | execp->a_bss = bss->size; | 1067 | 1 | } |
Line | Count | Source | 964 | 3 | { | 965 | 3 | bfd_size_type data_pad, text_pad; | 966 | 3 | file_ptr text_end; | 967 | 3 | const struct aout_backend_data *abdp; | 968 | | /* TRUE if text includes exec header. */ | 969 | 3 | bool ztih; | 970 | 3 | asection *text = obj_textsec (abfd); | 971 | 3 | asection *data = obj_datasec (abfd); | 972 | 3 | asection *bss = obj_bsssec (abfd); | 973 | | | 974 | 3 | abdp = aout_backend_info (abfd); | 975 | | | 976 | | /* Text. */ | 977 | 3 | ztih = (abdp != NULL | 978 | 3 | && (abdp->text_includes_header | 979 | 3 | || obj_aout_subformat (abfd) == q_magic_format)); | 980 | 3 | text->filepos = (ztih | 981 | 3 | ? adata (abfd).exec_bytes_size | 982 | 3 | : adata (abfd).zmagic_disk_block_size); | 983 | 3 | if (!text->user_set_vma) | 984 | 1 | { | 985 | | /* ?? Do we really need to check for relocs here? */ | 986 | 1 | text->vma = ((abfd->flags & HAS_RELOC) | 987 | 1 | ? 0 | 988 | 1 | : (ztih | 989 | 0 | ? abdp->default_text_vma + adata (abfd).exec_bytes_size | 990 | 0 | : abdp->default_text_vma)); | 991 | 1 | text_pad = 0; | 992 | 1 | } | 993 | 2 | else | 994 | 2 | { | 995 | | /* The .text section is being loaded at an unusual address. We | 996 | | may need to pad it such that the .data section starts at a page | 997 | | boundary. */ | 998 | 2 | if (ztih) | 999 | 2 | text_pad = ((text->filepos - text->vma) | 1000 | 2 | & (adata (abfd).page_size - 1)); | 1001 | 0 | else | 1002 | 0 | text_pad = (-text->vma | 1003 | 0 | & (adata (abfd).page_size - 1)); | 1004 | 2 | } | 1005 | | | 1006 | | /* Find start of data. */ | 1007 | 3 | if (ztih) | 1008 | 3 | { | 1009 | 3 | text_end = text->filepos + execp->a_text; | 1010 | 3 | text_pad += BFD_ALIGN (text_end, adata (abfd).page_size) - text_end; | 1011 | 3 | } | 1012 | 0 | else | 1013 | 0 | { | 1014 | | /* Note that if page_size == zmagic_disk_block_size, then | 1015 | | filepos == page_size, and this case is the same as the ztih | 1016 | | case. */ | 1017 | 0 | text_end = execp->a_text; | 1018 | 0 | text_pad += BFD_ALIGN (text_end, adata (abfd).page_size) - text_end; | 1019 | 0 | text_end += text->filepos; | 1020 | 0 | } | 1021 | 3 | execp->a_text += text_pad; | 1022 | | | 1023 | | /* Data. */ | 1024 | 3 | if (!data->user_set_vma) | 1025 | 1 | { | 1026 | 1 | bfd_vma vma; | 1027 | 1 | vma = text->vma + execp->a_text; | 1028 | 1 | data->vma = BFD_ALIGN (vma, adata (abfd).segment_size); | 1029 | 1 | } | 1030 | 3 | if (abdp && abdp->zmagic_mapped_contiguous) | 1031 | 0 | { | 1032 | 0 | text_pad = data->vma - (text->vma + execp->a_text); | 1033 | | /* Only pad the text section if the data | 1034 | | section is going to be placed after it. */ | 1035 | 0 | if (text_pad > 0) | 1036 | 0 | execp->a_text += text_pad; | 1037 | 0 | } | 1038 | 3 | data->filepos = text->filepos + execp->a_text; | 1039 | | | 1040 | | /* Fix up exec header while we're at it. */ | 1041 | 3 | if (ztih && (!abdp || (abdp && !abdp->exec_header_not_counted))) | 1042 | 3 | execp->a_text += adata (abfd).exec_bytes_size; | 1043 | 3 | if (obj_aout_subformat (abfd) == q_magic_format) | 1044 | 3 | N_SET_QMAGIC (execp); | 1045 | 3 | else | 1046 | 3 | N_SET_MAGIC (execp, ZMAGIC); | 1047 | | | 1048 | | /* Spec says data section should be rounded up to page boundary. */ | 1049 | 3 | execp->a_data = align_power (data->size, bss->alignment_power); | 1050 | 3 | execp->a_data = BFD_ALIGN (execp->a_data, adata (abfd).page_size); | 1051 | 3 | data_pad = execp->a_data - data->size; | 1052 | | | 1053 | | /* BSS. */ | 1054 | 3 | if (!bss->user_set_vma) | 1055 | 1 | bss->vma = data->vma + execp->a_data; | 1056 | | /* If the BSS immediately follows the data section and extra space | 1057 | | in the page is left after the data section, fudge data | 1058 | | in the header so that the bss section looks smaller by that | 1059 | | amount. We'll start the bss section there, and lie to the OS. | 1060 | | (Note that a linker script, as well as the above assignment, | 1061 | | could have explicitly set the BSS vma to immediately follow | 1062 | | the data section.) */ | 1063 | 3 | if (align_power (bss->vma, bss->alignment_power) == data->vma + execp->a_data) | 1064 | 3 | execp->a_bss = data_pad > bss->size ? 0 : bss->size - data_pad; | 1065 | 0 | else | 1066 | 0 | execp->a_bss = bss->size; | 1067 | 3 | } |
|
1068 | | |
1069 | | static void |
1070 | | adjust_n_magic (bfd *abfd, struct internal_exec *execp) |
1071 | 0 | { |
1072 | 0 | file_ptr pos = adata (abfd).exec_bytes_size; |
1073 | 0 | bfd_vma vma = 0; |
1074 | 0 | int pad; |
1075 | 0 | asection *text = obj_textsec (abfd); |
1076 | 0 | asection *data = obj_datasec (abfd); |
1077 | 0 | asection *bss = obj_bsssec (abfd); |
1078 | | |
1079 | | /* Text. */ |
1080 | 0 | text->filepos = pos; |
1081 | 0 | if (!text->user_set_vma) |
1082 | 0 | text->vma = vma; |
1083 | 0 | else |
1084 | 0 | vma = text->vma; |
1085 | 0 | pos += execp->a_text; |
1086 | 0 | vma += execp->a_text; |
1087 | | |
1088 | | /* Data. */ |
1089 | 0 | data->filepos = pos; |
1090 | 0 | if (!data->user_set_vma) |
1091 | 0 | data->vma = BFD_ALIGN (vma, adata (abfd).segment_size); |
1092 | 0 | vma = data->vma; |
1093 | | |
1094 | | /* Since BSS follows data immediately, see if it needs alignment. */ |
1095 | 0 | vma += data->size; |
1096 | 0 | pad = align_power (vma, bss->alignment_power) - vma; |
1097 | 0 | execp->a_data = data->size + pad; |
1098 | 0 | pos += execp->a_data; |
1099 | | |
1100 | | /* BSS. */ |
1101 | 0 | if (!bss->user_set_vma) |
1102 | 0 | bss->vma = vma; |
1103 | 0 | else |
1104 | 0 | vma = bss->vma; |
1105 | | |
1106 | | /* Fix up exec header. */ |
1107 | 0 | execp->a_bss = bss->size; |
1108 | 0 | N_SET_MAGIC (execp, NMAGIC); |
1109 | 0 | } Unexecuted instantiation: aout-cris.c:adjust_n_magic Unexecuted instantiation: aout-ns32k.c:adjust_n_magic Unexecuted instantiation: aout32.c:adjust_n_magic |
1110 | | |
1111 | | bool |
1112 | | NAME (aout, adjust_sizes_and_vmas) (bfd *abfd) |
1113 | 4 | { |
1114 | 4 | struct internal_exec *execp = exec_hdr (abfd); |
1115 | | |
1116 | 4 | if (! NAME (aout, make_sections) (abfd)) |
1117 | 0 | return false; |
1118 | | |
1119 | 4 | if (adata (abfd).magic != undecided_magic) |
1120 | 0 | return true; |
1121 | | |
1122 | 4 | execp->a_text = align_power (obj_textsec (abfd)->size, |
1123 | 4 | obj_textsec (abfd)->alignment_power); |
1124 | | |
1125 | | /* Rule (heuristic) for when to pad to a new page. Note that there |
1126 | | are (at least) two ways demand-paged (ZMAGIC) files have been |
1127 | | handled. Most Berkeley-based systems start the text segment at |
1128 | | (TARGET_PAGE_SIZE). However, newer versions of SUNOS start the text |
1129 | | segment right after the exec header; the latter is counted in the |
1130 | | text segment size, and is paged in by the kernel with the rest of |
1131 | | the text. */ |
1132 | | |
1133 | | /* This perhaps isn't the right way to do this, but made it simpler for me |
1134 | | to understand enough to implement it. Better would probably be to go |
1135 | | right from BFD flags to alignment/positioning characteristics. But the |
1136 | | old code was sloppy enough about handling the flags, and had enough |
1137 | | other magic, that it was a little hard for me to understand. I think |
1138 | | I understand it better now, but I haven't time to do the cleanup this |
1139 | | minute. */ |
1140 | | |
1141 | 4 | if (abfd->flags & D_PAGED) |
1142 | | /* Whether or not WP_TEXT is set -- let D_PAGED override. */ |
1143 | 4 | adata (abfd).magic = z_magic; |
1144 | 0 | else if (abfd->flags & WP_TEXT) |
1145 | 0 | adata (abfd).magic = n_magic; |
1146 | 0 | else |
1147 | 0 | adata (abfd).magic = o_magic; |
1148 | | |
1149 | | #ifdef BFD_AOUT_DEBUG /* requires gcc2 */ |
1150 | | #if __GNUC__ >= 2 |
1151 | | fprintf (stderr, "%s text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x,%x>\n", |
1152 | | ({ char *str; |
1153 | | switch (adata (abfd).magic) |
1154 | | { |
1155 | | case n_magic: str = "NMAGIC"; break; |
1156 | | case o_magic: str = "OMAGIC"; break; |
1157 | | case z_magic: str = "ZMAGIC"; break; |
1158 | | default: abort (); |
1159 | | } |
1160 | | str; |
1161 | | }), |
1162 | | obj_textsec (abfd)->vma, obj_textsec (abfd)->size, |
1163 | | obj_textsec (abfd)->alignment_power, |
1164 | | obj_datasec (abfd)->vma, obj_datasec (abfd)->size, |
1165 | | obj_datasec (abfd)->alignment_power, |
1166 | | obj_bsssec (abfd)->vma, obj_bsssec (abfd)->size, |
1167 | | obj_bsssec (abfd)->alignment_power); |
1168 | | #endif |
1169 | | #endif |
1170 | | |
1171 | 4 | switch (adata (abfd).magic) |
1172 | 4 | { |
1173 | 0 | case o_magic: |
1174 | 0 | adjust_o_magic (abfd, execp); |
1175 | 0 | break; |
1176 | 4 | case z_magic: |
1177 | 4 | adjust_z_magic (abfd, execp); |
1178 | 4 | break; |
1179 | 0 | case n_magic: |
1180 | 0 | adjust_n_magic (abfd, execp); |
1181 | 0 | break; |
1182 | 0 | default: |
1183 | 0 | abort (); |
1184 | 4 | } |
1185 | | |
1186 | | #ifdef BFD_AOUT_DEBUG |
1187 | | fprintf (stderr, " text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x>\n", |
1188 | | obj_textsec (abfd)->vma, execp->a_text, |
1189 | | obj_textsec (abfd)->filepos, |
1190 | | obj_datasec (abfd)->vma, execp->a_data, |
1191 | | obj_datasec (abfd)->filepos, |
1192 | | obj_bsssec (abfd)->vma, execp->a_bss); |
1193 | | #endif |
1194 | | |
1195 | 4 | return true; |
1196 | 4 | } Unexecuted instantiation: cris_aout_32_adjust_sizes_and_vmas ns32kaout_32_adjust_sizes_and_vmas Line | Count | Source | 1113 | 1 | { | 1114 | 1 | struct internal_exec *execp = exec_hdr (abfd); | 1115 | | | 1116 | 1 | if (! NAME (aout, make_sections) (abfd)) | 1117 | 0 | return false; | 1118 | | | 1119 | 1 | if (adata (abfd).magic != undecided_magic) | 1120 | 0 | return true; | 1121 | | | 1122 | 1 | execp->a_text = align_power (obj_textsec (abfd)->size, | 1123 | 1 | obj_textsec (abfd)->alignment_power); | 1124 | | | 1125 | | /* Rule (heuristic) for when to pad to a new page. Note that there | 1126 | | are (at least) two ways demand-paged (ZMAGIC) files have been | 1127 | | handled. Most Berkeley-based systems start the text segment at | 1128 | | (TARGET_PAGE_SIZE). However, newer versions of SUNOS start the text | 1129 | | segment right after the exec header; the latter is counted in the | 1130 | | text segment size, and is paged in by the kernel with the rest of | 1131 | | the text. */ | 1132 | | | 1133 | | /* This perhaps isn't the right way to do this, but made it simpler for me | 1134 | | to understand enough to implement it. Better would probably be to go | 1135 | | right from BFD flags to alignment/positioning characteristics. But the | 1136 | | old code was sloppy enough about handling the flags, and had enough | 1137 | | other magic, that it was a little hard for me to understand. I think | 1138 | | I understand it better now, but I haven't time to do the cleanup this | 1139 | | minute. */ | 1140 | | | 1141 | 1 | if (abfd->flags & D_PAGED) | 1142 | | /* Whether or not WP_TEXT is set -- let D_PAGED override. */ | 1143 | 1 | adata (abfd).magic = z_magic; | 1144 | 0 | else if (abfd->flags & WP_TEXT) | 1145 | 0 | adata (abfd).magic = n_magic; | 1146 | 0 | else | 1147 | 0 | adata (abfd).magic = o_magic; | 1148 | | | 1149 | | #ifdef BFD_AOUT_DEBUG /* requires gcc2 */ | 1150 | | #if __GNUC__ >= 2 | 1151 | | fprintf (stderr, "%s text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x,%x>\n", | 1152 | | ({ char *str; | 1153 | | switch (adata (abfd).magic) | 1154 | | { | 1155 | | case n_magic: str = "NMAGIC"; break; | 1156 | | case o_magic: str = "OMAGIC"; break; | 1157 | | case z_magic: str = "ZMAGIC"; break; | 1158 | | default: abort (); | 1159 | | } | 1160 | | str; | 1161 | | }), | 1162 | | obj_textsec (abfd)->vma, obj_textsec (abfd)->size, | 1163 | | obj_textsec (abfd)->alignment_power, | 1164 | | obj_datasec (abfd)->vma, obj_datasec (abfd)->size, | 1165 | | obj_datasec (abfd)->alignment_power, | 1166 | | obj_bsssec (abfd)->vma, obj_bsssec (abfd)->size, | 1167 | | obj_bsssec (abfd)->alignment_power); | 1168 | | #endif | 1169 | | #endif | 1170 | | | 1171 | 1 | switch (adata (abfd).magic) | 1172 | 1 | { | 1173 | 0 | case o_magic: | 1174 | 0 | adjust_o_magic (abfd, execp); | 1175 | 0 | break; | 1176 | 1 | case z_magic: | 1177 | 1 | adjust_z_magic (abfd, execp); | 1178 | 1 | break; | 1179 | 0 | case n_magic: | 1180 | 0 | adjust_n_magic (abfd, execp); | 1181 | 0 | break; | 1182 | 0 | default: | 1183 | 0 | abort (); | 1184 | 1 | } | 1185 | | | 1186 | | #ifdef BFD_AOUT_DEBUG | 1187 | | fprintf (stderr, " text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x>\n", | 1188 | | obj_textsec (abfd)->vma, execp->a_text, | 1189 | | obj_textsec (abfd)->filepos, | 1190 | | obj_datasec (abfd)->vma, execp->a_data, | 1191 | | obj_datasec (abfd)->filepos, | 1192 | | obj_bsssec (abfd)->vma, execp->a_bss); | 1193 | | #endif | 1194 | | | 1195 | 1 | return true; | 1196 | 1 | } |
aout_32_adjust_sizes_and_vmas Line | Count | Source | 1113 | 3 | { | 1114 | 3 | struct internal_exec *execp = exec_hdr (abfd); | 1115 | | | 1116 | 3 | if (! NAME (aout, make_sections) (abfd)) | 1117 | 0 | return false; | 1118 | | | 1119 | 3 | if (adata (abfd).magic != undecided_magic) | 1120 | 0 | return true; | 1121 | | | 1122 | 3 | execp->a_text = align_power (obj_textsec (abfd)->size, | 1123 | 3 | obj_textsec (abfd)->alignment_power); | 1124 | | | 1125 | | /* Rule (heuristic) for when to pad to a new page. Note that there | 1126 | | are (at least) two ways demand-paged (ZMAGIC) files have been | 1127 | | handled. Most Berkeley-based systems start the text segment at | 1128 | | (TARGET_PAGE_SIZE). However, newer versions of SUNOS start the text | 1129 | | segment right after the exec header; the latter is counted in the | 1130 | | text segment size, and is paged in by the kernel with the rest of | 1131 | | the text. */ | 1132 | | | 1133 | | /* This perhaps isn't the right way to do this, but made it simpler for me | 1134 | | to understand enough to implement it. Better would probably be to go | 1135 | | right from BFD flags to alignment/positioning characteristics. But the | 1136 | | old code was sloppy enough about handling the flags, and had enough | 1137 | | other magic, that it was a little hard for me to understand. I think | 1138 | | I understand it better now, but I haven't time to do the cleanup this | 1139 | | minute. */ | 1140 | | | 1141 | 3 | if (abfd->flags & D_PAGED) | 1142 | | /* Whether or not WP_TEXT is set -- let D_PAGED override. */ | 1143 | 3 | adata (abfd).magic = z_magic; | 1144 | 0 | else if (abfd->flags & WP_TEXT) | 1145 | 0 | adata (abfd).magic = n_magic; | 1146 | 0 | else | 1147 | 0 | adata (abfd).magic = o_magic; | 1148 | | | 1149 | | #ifdef BFD_AOUT_DEBUG /* requires gcc2 */ | 1150 | | #if __GNUC__ >= 2 | 1151 | | fprintf (stderr, "%s text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x,%x>\n", | 1152 | | ({ char *str; | 1153 | | switch (adata (abfd).magic) | 1154 | | { | 1155 | | case n_magic: str = "NMAGIC"; break; | 1156 | | case o_magic: str = "OMAGIC"; break; | 1157 | | case z_magic: str = "ZMAGIC"; break; | 1158 | | default: abort (); | 1159 | | } | 1160 | | str; | 1161 | | }), | 1162 | | obj_textsec (abfd)->vma, obj_textsec (abfd)->size, | 1163 | | obj_textsec (abfd)->alignment_power, | 1164 | | obj_datasec (abfd)->vma, obj_datasec (abfd)->size, | 1165 | | obj_datasec (abfd)->alignment_power, | 1166 | | obj_bsssec (abfd)->vma, obj_bsssec (abfd)->size, | 1167 | | obj_bsssec (abfd)->alignment_power); | 1168 | | #endif | 1169 | | #endif | 1170 | | | 1171 | 3 | switch (adata (abfd).magic) | 1172 | 3 | { | 1173 | 0 | case o_magic: | 1174 | 0 | adjust_o_magic (abfd, execp); | 1175 | 0 | break; | 1176 | 3 | case z_magic: | 1177 | 3 | adjust_z_magic (abfd, execp); | 1178 | 3 | break; | 1179 | 0 | case n_magic: | 1180 | 0 | adjust_n_magic (abfd, execp); | 1181 | 0 | break; | 1182 | 0 | default: | 1183 | 0 | abort (); | 1184 | 3 | } | 1185 | | | 1186 | | #ifdef BFD_AOUT_DEBUG | 1187 | | fprintf (stderr, " text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x>\n", | 1188 | | obj_textsec (abfd)->vma, execp->a_text, | 1189 | | obj_textsec (abfd)->filepos, | 1190 | | obj_datasec (abfd)->vma, execp->a_data, | 1191 | | obj_datasec (abfd)->filepos, | 1192 | | obj_bsssec (abfd)->vma, execp->a_bss); | 1193 | | #endif | 1194 | | | 1195 | 3 | return true; | 1196 | 3 | } |
|
1197 | | |
1198 | | /* |
1199 | | FUNCTION |
1200 | | aout_@var{size}_new_section_hook |
1201 | | |
1202 | | SYNOPSIS |
1203 | | bool aout_@var{size}_new_section_hook, |
1204 | | (bfd *abfd, |
1205 | | asection *newsect); |
1206 | | |
1207 | | DESCRIPTION |
1208 | | Called by the BFD in response to a @code{bfd_make_section} |
1209 | | request. |
1210 | | */ |
1211 | | bool |
1212 | | NAME (aout, new_section_hook) (bfd *abfd, asection *newsect) |
1213 | 242k | { |
1214 | | /* Align to double at least. */ |
1215 | 242k | newsect->alignment_power = bfd_get_arch_info (abfd)->section_align_power; |
1216 | | |
1217 | 242k | if (bfd_get_format (abfd) == bfd_object) |
1218 | 242k | { |
1219 | 242k | if (obj_textsec (abfd) == NULL && !strcmp (newsect->name, ".text")) |
1220 | 80.6k | { |
1221 | 80.6k | obj_textsec (abfd)= newsect; |
1222 | 80.6k | newsect->target_index = N_TEXT; |
1223 | 80.6k | } |
1224 | 161k | else if (obj_datasec (abfd) == NULL && !strcmp (newsect->name, ".data")) |
1225 | 80.6k | { |
1226 | 80.6k | obj_datasec (abfd) = newsect; |
1227 | 80.6k | newsect->target_index = N_DATA; |
1228 | 80.6k | } |
1229 | 80.6k | else if (obj_bsssec (abfd) == NULL && !strcmp (newsect->name, ".bss")) |
1230 | 80.6k | { |
1231 | 80.6k | obj_bsssec (abfd) = newsect; |
1232 | 80.6k | newsect->target_index = N_BSS; |
1233 | 80.6k | } |
1234 | 242k | } |
1235 | | |
1236 | | /* We allow more than three sections internally. */ |
1237 | 242k | return _bfd_generic_new_section_hook (abfd, newsect); |
1238 | 242k | } cris_aout_32_new_section_hook Line | Count | Source | 1213 | 17.1k | { | 1214 | | /* Align to double at least. */ | 1215 | 17.1k | newsect->alignment_power = bfd_get_arch_info (abfd)->section_align_power; | 1216 | | | 1217 | 17.1k | if (bfd_get_format (abfd) == bfd_object) | 1218 | 17.1k | { | 1219 | 17.1k | if (obj_textsec (abfd) == NULL && !strcmp (newsect->name, ".text")) | 1220 | 5.72k | { | 1221 | 5.72k | obj_textsec (abfd)= newsect; | 1222 | 5.72k | newsect->target_index = N_TEXT; | 1223 | 5.72k | } | 1224 | 11.4k | else if (obj_datasec (abfd) == NULL && !strcmp (newsect->name, ".data")) | 1225 | 5.72k | { | 1226 | 5.72k | obj_datasec (abfd) = newsect; | 1227 | 5.72k | newsect->target_index = N_DATA; | 1228 | 5.72k | } | 1229 | 5.72k | else if (obj_bsssec (abfd) == NULL && !strcmp (newsect->name, ".bss")) | 1230 | 5.72k | { | 1231 | 5.72k | obj_bsssec (abfd) = newsect; | 1232 | 5.72k | newsect->target_index = N_BSS; | 1233 | 5.72k | } | 1234 | 17.1k | } | 1235 | | | 1236 | | /* We allow more than three sections internally. */ | 1237 | 17.1k | return _bfd_generic_new_section_hook (abfd, newsect); | 1238 | 17.1k | } |
ns32kaout_32_new_section_hook Line | Count | Source | 1213 | 75.7k | { | 1214 | | /* Align to double at least. */ | 1215 | 75.7k | newsect->alignment_power = bfd_get_arch_info (abfd)->section_align_power; | 1216 | | | 1217 | 75.7k | if (bfd_get_format (abfd) == bfd_object) | 1218 | 75.7k | { | 1219 | 75.7k | if (obj_textsec (abfd) == NULL && !strcmp (newsect->name, ".text")) | 1220 | 25.2k | { | 1221 | 25.2k | obj_textsec (abfd)= newsect; | 1222 | 25.2k | newsect->target_index = N_TEXT; | 1223 | 25.2k | } | 1224 | 50.5k | else if (obj_datasec (abfd) == NULL && !strcmp (newsect->name, ".data")) | 1225 | 25.2k | { | 1226 | 25.2k | obj_datasec (abfd) = newsect; | 1227 | 25.2k | newsect->target_index = N_DATA; | 1228 | 25.2k | } | 1229 | 25.2k | else if (obj_bsssec (abfd) == NULL && !strcmp (newsect->name, ".bss")) | 1230 | 25.2k | { | 1231 | 25.2k | obj_bsssec (abfd) = newsect; | 1232 | 25.2k | newsect->target_index = N_BSS; | 1233 | 25.2k | } | 1234 | 75.7k | } | 1235 | | | 1236 | | /* We allow more than three sections internally. */ | 1237 | 75.7k | return _bfd_generic_new_section_hook (abfd, newsect); | 1238 | 75.7k | } |
Line | Count | Source | 1213 | 149k | { | 1214 | | /* Align to double at least. */ | 1215 | 149k | newsect->alignment_power = bfd_get_arch_info (abfd)->section_align_power; | 1216 | | | 1217 | 149k | if (bfd_get_format (abfd) == bfd_object) | 1218 | 149k | { | 1219 | 149k | if (obj_textsec (abfd) == NULL && !strcmp (newsect->name, ".text")) | 1220 | 49.7k | { | 1221 | 49.7k | obj_textsec (abfd)= newsect; | 1222 | 49.7k | newsect->target_index = N_TEXT; | 1223 | 49.7k | } | 1224 | 99.4k | else if (obj_datasec (abfd) == NULL && !strcmp (newsect->name, ".data")) | 1225 | 49.7k | { | 1226 | 49.7k | obj_datasec (abfd) = newsect; | 1227 | 49.7k | newsect->target_index = N_DATA; | 1228 | 49.7k | } | 1229 | 49.7k | else if (obj_bsssec (abfd) == NULL && !strcmp (newsect->name, ".bss")) | 1230 | 49.7k | { | 1231 | 49.7k | obj_bsssec (abfd) = newsect; | 1232 | 49.7k | newsect->target_index = N_BSS; | 1233 | 49.7k | } | 1234 | 149k | } | 1235 | | | 1236 | | /* We allow more than three sections internally. */ | 1237 | 149k | return _bfd_generic_new_section_hook (abfd, newsect); | 1238 | 149k | } |
|
1239 | | |
1240 | | bool |
1241 | | NAME (aout, set_section_contents) (bfd *abfd, |
1242 | | sec_ptr section, |
1243 | | const void * location, |
1244 | | file_ptr offset, |
1245 | | bfd_size_type count) |
1246 | 4 | { |
1247 | 4 | if (! abfd->output_has_begun) |
1248 | 3 | { |
1249 | 3 | if (! NAME (aout, adjust_sizes_and_vmas) (abfd)) |
1250 | 0 | return false; |
1251 | 3 | } |
1252 | | |
1253 | 4 | if (section == obj_bsssec (abfd)) |
1254 | 0 | { |
1255 | 0 | bfd_set_error (bfd_error_no_contents); |
1256 | 0 | return false; |
1257 | 0 | } |
1258 | | |
1259 | 4 | if (section != obj_textsec (abfd) |
1260 | 4 | && section != obj_datasec (abfd)) |
1261 | 0 | { |
1262 | 0 | if (aout_section_merge_with_text_p (abfd, section)) |
1263 | 0 | section->filepos = obj_textsec (abfd)->filepos + |
1264 | 0 | (section->vma - obj_textsec (abfd)->vma); |
1265 | 0 | else |
1266 | 0 | { |
1267 | 0 | _bfd_error_handler |
1268 | | /* xgettext:c-format */ |
1269 | 0 | (_("%pB: can not represent section `%pA' in a.out object file format"), |
1270 | 0 | abfd, section); |
1271 | 0 | bfd_set_error (bfd_error_nonrepresentable_section); |
1272 | 0 | return false; |
1273 | 0 | } |
1274 | 0 | } |
1275 | | |
1276 | 4 | if (count != 0) |
1277 | 4 | { |
1278 | 4 | if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0 |
1279 | 4 | || bfd_write (location, count, abfd) != count) |
1280 | 0 | return false; |
1281 | 4 | } |
1282 | | |
1283 | 4 | return true; |
1284 | 4 | } Unexecuted instantiation: cris_aout_32_set_section_contents ns32kaout_32_set_section_contents Line | Count | Source | 1246 | 2 | { | 1247 | 2 | if (! abfd->output_has_begun) | 1248 | 1 | { | 1249 | 1 | if (! NAME (aout, adjust_sizes_and_vmas) (abfd)) | 1250 | 0 | return false; | 1251 | 1 | } | 1252 | | | 1253 | 2 | if (section == obj_bsssec (abfd)) | 1254 | 0 | { | 1255 | 0 | bfd_set_error (bfd_error_no_contents); | 1256 | 0 | return false; | 1257 | 0 | } | 1258 | | | 1259 | 2 | if (section != obj_textsec (abfd) | 1260 | 2 | && section != obj_datasec (abfd)) | 1261 | 0 | { | 1262 | 0 | if (aout_section_merge_with_text_p (abfd, section)) | 1263 | 0 | section->filepos = obj_textsec (abfd)->filepos + | 1264 | 0 | (section->vma - obj_textsec (abfd)->vma); | 1265 | 0 | else | 1266 | 0 | { | 1267 | 0 | _bfd_error_handler | 1268 | | /* xgettext:c-format */ | 1269 | 0 | (_("%pB: can not represent section `%pA' in a.out object file format"), | 1270 | 0 | abfd, section); | 1271 | 0 | bfd_set_error (bfd_error_nonrepresentable_section); | 1272 | 0 | return false; | 1273 | 0 | } | 1274 | 0 | } | 1275 | | | 1276 | 2 | if (count != 0) | 1277 | 2 | { | 1278 | 2 | if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0 | 1279 | 2 | || bfd_write (location, count, abfd) != count) | 1280 | 0 | return false; | 1281 | 2 | } | 1282 | | | 1283 | 2 | return true; | 1284 | 2 | } |
aout_32_set_section_contents Line | Count | Source | 1246 | 2 | { | 1247 | 2 | if (! abfd->output_has_begun) | 1248 | 2 | { | 1249 | 2 | if (! NAME (aout, adjust_sizes_and_vmas) (abfd)) | 1250 | 0 | return false; | 1251 | 2 | } | 1252 | | | 1253 | 2 | if (section == obj_bsssec (abfd)) | 1254 | 0 | { | 1255 | 0 | bfd_set_error (bfd_error_no_contents); | 1256 | 0 | return false; | 1257 | 0 | } | 1258 | | | 1259 | 2 | if (section != obj_textsec (abfd) | 1260 | 2 | && section != obj_datasec (abfd)) | 1261 | 0 | { | 1262 | 0 | if (aout_section_merge_with_text_p (abfd, section)) | 1263 | 0 | section->filepos = obj_textsec (abfd)->filepos + | 1264 | 0 | (section->vma - obj_textsec (abfd)->vma); | 1265 | 0 | else | 1266 | 0 | { | 1267 | 0 | _bfd_error_handler | 1268 | | /* xgettext:c-format */ | 1269 | 0 | (_("%pB: can not represent section `%pA' in a.out object file format"), | 1270 | 0 | abfd, section); | 1271 | 0 | bfd_set_error (bfd_error_nonrepresentable_section); | 1272 | 0 | return false; | 1273 | 0 | } | 1274 | 0 | } | 1275 | | | 1276 | 2 | if (count != 0) | 1277 | 2 | { | 1278 | 2 | if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0 | 1279 | 2 | || bfd_write (location, count, abfd) != count) | 1280 | 0 | return false; | 1281 | 2 | } | 1282 | | | 1283 | 2 | return true; | 1284 | 2 | } |
|
1285 | | |
1286 | | /* Read the external symbols from an a.out file. */ |
1287 | | |
1288 | | static bool |
1289 | | aout_get_external_symbols (bfd *abfd) |
1290 | 1.83k | { |
1291 | 1.83k | if (obj_aout_external_syms (abfd) == NULL) |
1292 | 1.56k | { |
1293 | 1.56k | bfd_size_type count; |
1294 | 1.56k | struct external_nlist *syms = NULL; |
1295 | 1.56k | bfd_size_type amt = exec_hdr (abfd)->a_syms; |
1296 | | |
1297 | 1.56k | count = amt / EXTERNAL_NLIST_SIZE; |
1298 | 1.56k | if (count == 0) |
1299 | 20 | return true; |
1300 | | |
1301 | | /* We allocate using malloc to make the values easy to free |
1302 | | later on. If we put them on the objalloc it might not be |
1303 | | possible to free them. */ |
1304 | 1.54k | if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0) |
1305 | 0 | return false; |
1306 | 1.54k | syms = _bfd_malloc_and_read (abfd, amt, amt); |
1307 | 1.54k | if (syms == NULL) |
1308 | 162 | return false; |
1309 | | |
1310 | 1.38k | obj_aout_external_syms (abfd) = syms; |
1311 | 1.38k | obj_aout_external_sym_count (abfd) = count; |
1312 | 1.38k | } |
1313 | | |
1314 | 1.65k | if (obj_aout_external_strings (abfd) == NULL |
1315 | 1.65k | && exec_hdr (abfd)->a_syms != 0) |
1316 | 1.36k | { |
1317 | 1.36k | unsigned char string_chars[BYTES_IN_WORD]; |
1318 | 1.36k | bfd_size_type stringsize; |
1319 | 1.36k | char *strings; |
1320 | 1.36k | bfd_size_type amt = BYTES_IN_WORD; |
1321 | | |
1322 | | /* Get the size of the strings. */ |
1323 | 1.36k | if (bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET) != 0 |
1324 | 1.36k | || bfd_read (string_chars, amt, abfd) != amt) |
1325 | 7 | return false; |
1326 | 1.35k | stringsize = GET_WORD (abfd, string_chars); |
1327 | 1.35k | if (stringsize == 0) |
1328 | 689 | stringsize = 1; |
1329 | 667 | else if (stringsize + 1 < BYTES_IN_WORD + 1 |
1330 | 667 | || (size_t) stringsize != stringsize) |
1331 | 7 | { |
1332 | 7 | bfd_set_error (bfd_error_bad_value); |
1333 | 7 | return false; |
1334 | 7 | } |
1335 | | |
1336 | 1.34k | strings = (char *) bfd_malloc (stringsize + 1); |
1337 | 1.34k | if (strings == NULL) |
1338 | 0 | return false; |
1339 | | |
1340 | 1.34k | if (stringsize >= BYTES_IN_WORD) |
1341 | 660 | { |
1342 | 660 | amt = stringsize - BYTES_IN_WORD; |
1343 | 660 | if (bfd_read (strings + BYTES_IN_WORD, amt, abfd) != amt) |
1344 | 74 | { |
1345 | 74 | free (strings); |
1346 | 74 | return false; |
1347 | 74 | } |
1348 | 660 | } |
1349 | | |
1350 | | /* Ensure that a zero index yields an empty string. */ |
1351 | 1.27k | if (stringsize >= BYTES_IN_WORD) |
1352 | 586 | memset (strings, 0, BYTES_IN_WORD); |
1353 | | |
1354 | | /* Ensure that the string buffer is NUL terminated. */ |
1355 | 1.27k | strings[stringsize] = 0; |
1356 | | |
1357 | 1.27k | obj_aout_external_strings (abfd) = strings; |
1358 | 1.27k | obj_aout_external_string_size (abfd) = stringsize; |
1359 | 1.27k | } |
1360 | | |
1361 | 1.56k | return true; |
1362 | 1.65k | } Unexecuted instantiation: aout-cris.c:aout_get_external_symbols aout-ns32k.c:aout_get_external_symbols Line | Count | Source | 1290 | 1.01k | { | 1291 | 1.01k | if (obj_aout_external_syms (abfd) == NULL) | 1292 | 882 | { | 1293 | 882 | bfd_size_type count; | 1294 | 882 | struct external_nlist *syms = NULL; | 1295 | 882 | bfd_size_type amt = exec_hdr (abfd)->a_syms; | 1296 | | | 1297 | 882 | count = amt / EXTERNAL_NLIST_SIZE; | 1298 | 882 | if (count == 0) | 1299 | 13 | return true; | 1300 | | | 1301 | | /* We allocate using malloc to make the values easy to free | 1302 | | later on. If we put them on the objalloc it might not be | 1303 | | possible to free them. */ | 1304 | 869 | if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0) | 1305 | 0 | return false; | 1306 | 869 | syms = _bfd_malloc_and_read (abfd, amt, amt); | 1307 | 869 | if (syms == NULL) | 1308 | 86 | return false; | 1309 | | | 1310 | 783 | obj_aout_external_syms (abfd) = syms; | 1311 | 783 | obj_aout_external_sym_count (abfd) = count; | 1312 | 783 | } | 1313 | | | 1314 | 918 | if (obj_aout_external_strings (abfd) == NULL | 1315 | 918 | && exec_hdr (abfd)->a_syms != 0) | 1316 | 777 | { | 1317 | 777 | unsigned char string_chars[BYTES_IN_WORD]; | 1318 | 777 | bfd_size_type stringsize; | 1319 | 777 | char *strings; | 1320 | 777 | bfd_size_type amt = BYTES_IN_WORD; | 1321 | | | 1322 | | /* Get the size of the strings. */ | 1323 | 777 | if (bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET) != 0 | 1324 | 777 | || bfd_read (string_chars, amt, abfd) != amt) | 1325 | 3 | return false; | 1326 | 774 | stringsize = GET_WORD (abfd, string_chars); | 1327 | 774 | if (stringsize == 0) | 1328 | 348 | stringsize = 1; | 1329 | 426 | else if (stringsize + 1 < BYTES_IN_WORD + 1 | 1330 | 426 | || (size_t) stringsize != stringsize) | 1331 | 3 | { | 1332 | 3 | bfd_set_error (bfd_error_bad_value); | 1333 | 3 | return false; | 1334 | 3 | } | 1335 | | | 1336 | 771 | strings = (char *) bfd_malloc (stringsize + 1); | 1337 | 771 | if (strings == NULL) | 1338 | 0 | return false; | 1339 | | | 1340 | 771 | if (stringsize >= BYTES_IN_WORD) | 1341 | 423 | { | 1342 | 423 | amt = stringsize - BYTES_IN_WORD; | 1343 | 423 | if (bfd_read (strings + BYTES_IN_WORD, amt, abfd) != amt) | 1344 | 35 | { | 1345 | 35 | free (strings); | 1346 | 35 | return false; | 1347 | 35 | } | 1348 | 423 | } | 1349 | | | 1350 | | /* Ensure that a zero index yields an empty string. */ | 1351 | 736 | if (stringsize >= BYTES_IN_WORD) | 1352 | 388 | memset (strings, 0, BYTES_IN_WORD); | 1353 | | | 1354 | | /* Ensure that the string buffer is NUL terminated. */ | 1355 | 736 | strings[stringsize] = 0; | 1356 | | | 1357 | 736 | obj_aout_external_strings (abfd) = strings; | 1358 | 736 | obj_aout_external_string_size (abfd) = stringsize; | 1359 | 736 | } | 1360 | | | 1361 | 877 | return true; | 1362 | 918 | } |
aout32.c:aout_get_external_symbols Line | Count | Source | 1290 | 816 | { | 1291 | 816 | if (obj_aout_external_syms (abfd) == NULL) | 1292 | 685 | { | 1293 | 685 | bfd_size_type count; | 1294 | 685 | struct external_nlist *syms = NULL; | 1295 | 685 | bfd_size_type amt = exec_hdr (abfd)->a_syms; | 1296 | | | 1297 | 685 | count = amt / EXTERNAL_NLIST_SIZE; | 1298 | 685 | if (count == 0) | 1299 | 7 | return true; | 1300 | | | 1301 | | /* We allocate using malloc to make the values easy to free | 1302 | | later on. If we put them on the objalloc it might not be | 1303 | | possible to free them. */ | 1304 | 678 | if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0) | 1305 | 0 | return false; | 1306 | 678 | syms = _bfd_malloc_and_read (abfd, amt, amt); | 1307 | 678 | if (syms == NULL) | 1308 | 76 | return false; | 1309 | | | 1310 | 602 | obj_aout_external_syms (abfd) = syms; | 1311 | 602 | obj_aout_external_sym_count (abfd) = count; | 1312 | 602 | } | 1313 | | | 1314 | 733 | if (obj_aout_external_strings (abfd) == NULL | 1315 | 733 | && exec_hdr (abfd)->a_syms != 0) | 1316 | 586 | { | 1317 | 586 | unsigned char string_chars[BYTES_IN_WORD]; | 1318 | 586 | bfd_size_type stringsize; | 1319 | 586 | char *strings; | 1320 | 586 | bfd_size_type amt = BYTES_IN_WORD; | 1321 | | | 1322 | | /* Get the size of the strings. */ | 1323 | 586 | if (bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET) != 0 | 1324 | 586 | || bfd_read (string_chars, amt, abfd) != amt) | 1325 | 4 | return false; | 1326 | 582 | stringsize = GET_WORD (abfd, string_chars); | 1327 | 582 | if (stringsize == 0) | 1328 | 341 | stringsize = 1; | 1329 | 241 | else if (stringsize + 1 < BYTES_IN_WORD + 1 | 1330 | 241 | || (size_t) stringsize != stringsize) | 1331 | 4 | { | 1332 | 4 | bfd_set_error (bfd_error_bad_value); | 1333 | 4 | return false; | 1334 | 4 | } | 1335 | | | 1336 | 578 | strings = (char *) bfd_malloc (stringsize + 1); | 1337 | 578 | if (strings == NULL) | 1338 | 0 | return false; | 1339 | | | 1340 | 578 | if (stringsize >= BYTES_IN_WORD) | 1341 | 237 | { | 1342 | 237 | amt = stringsize - BYTES_IN_WORD; | 1343 | 237 | if (bfd_read (strings + BYTES_IN_WORD, amt, abfd) != amt) | 1344 | 39 | { | 1345 | 39 | free (strings); | 1346 | 39 | return false; | 1347 | 39 | } | 1348 | 237 | } | 1349 | | | 1350 | | /* Ensure that a zero index yields an empty string. */ | 1351 | 539 | if (stringsize >= BYTES_IN_WORD) | 1352 | 198 | memset (strings, 0, BYTES_IN_WORD); | 1353 | | | 1354 | | /* Ensure that the string buffer is NUL terminated. */ | 1355 | 539 | strings[stringsize] = 0; | 1356 | | | 1357 | 539 | obj_aout_external_strings (abfd) = strings; | 1358 | 539 | obj_aout_external_string_size (abfd) = stringsize; | 1359 | 539 | } | 1360 | | | 1361 | 686 | return true; | 1362 | 733 | } |
|
1363 | | |
1364 | | /* Translate an a.out symbol into a BFD symbol. The desc, other, type |
1365 | | and symbol->value fields of CACHE_PTR will be set from the a.out |
1366 | | nlist structure. This function is responsible for setting |
1367 | | symbol->flags and symbol->section, and adjusting symbol->value. */ |
1368 | | |
1369 | | static bool |
1370 | | translate_from_native_sym_flags (bfd *abfd, aout_symbol_type *cache_ptr) |
1371 | 62.8M | { |
1372 | 62.8M | flagword visible; |
1373 | | |
1374 | 62.8M | if ((cache_ptr->type & N_STAB) != 0 |
1375 | 62.8M | || cache_ptr->type == N_FN) |
1376 | 106k | { |
1377 | 106k | asection *sec; |
1378 | | |
1379 | | /* This is a debugging symbol. */ |
1380 | 106k | cache_ptr->symbol.flags = BSF_DEBUGGING; |
1381 | | |
1382 | | /* Work out the symbol section. */ |
1383 | 106k | switch (cache_ptr->type & N_TYPE) |
1384 | 106k | { |
1385 | 6.60k | case N_TEXT: |
1386 | 6.60k | case N_FN: |
1387 | 6.60k | sec = obj_textsec (abfd); |
1388 | 6.60k | break; |
1389 | 5.19k | case N_DATA: |
1390 | 5.19k | sec = obj_datasec (abfd); |
1391 | 5.19k | break; |
1392 | 8.25k | case N_BSS: |
1393 | 8.25k | sec = obj_bsssec (abfd); |
1394 | 8.25k | break; |
1395 | 82.3k | default: |
1396 | 86.6k | case N_ABS: |
1397 | 86.6k | sec = bfd_abs_section_ptr; |
1398 | 86.6k | break; |
1399 | 106k | } |
1400 | | |
1401 | 106k | cache_ptr->symbol.section = sec; |
1402 | 106k | cache_ptr->symbol.value -= sec->vma; |
1403 | | |
1404 | 106k | return true; |
1405 | 106k | } |
1406 | | |
1407 | | /* Get the default visibility. This does not apply to all types, so |
1408 | | we just hold it in a local variable to use if wanted. */ |
1409 | 62.7M | if ((cache_ptr->type & N_EXT) == 0) |
1410 | 61.1M | visible = BSF_LOCAL; |
1411 | 1.64M | else |
1412 | 1.64M | visible = BSF_GLOBAL; |
1413 | | |
1414 | 62.7M | switch (cache_ptr->type) |
1415 | 62.7M | { |
1416 | 60.0M | default: |
1417 | 60.4M | case N_ABS: case N_ABS | N_EXT: |
1418 | 60.4M | cache_ptr->symbol.section = bfd_abs_section_ptr; |
1419 | 60.4M | cache_ptr->symbol.flags = visible; |
1420 | 60.4M | break; |
1421 | | |
1422 | 946k | case N_UNDF | N_EXT: |
1423 | 946k | if (cache_ptr->symbol.value != 0) |
1424 | 881k | { |
1425 | | /* This is a common symbol. */ |
1426 | 881k | cache_ptr->symbol.flags = BSF_GLOBAL; |
1427 | 881k | cache_ptr->symbol.section = bfd_com_section_ptr; |
1428 | 881k | } |
1429 | 65.5k | else |
1430 | 65.5k | { |
1431 | 65.5k | cache_ptr->symbol.flags = 0; |
1432 | 65.5k | cache_ptr->symbol.section = bfd_und_section_ptr; |
1433 | 65.5k | } |
1434 | 946k | break; |
1435 | | |
1436 | 363k | case N_TEXT: case N_TEXT | N_EXT: |
1437 | 363k | cache_ptr->symbol.section = obj_textsec (abfd); |
1438 | 363k | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma; |
1439 | 363k | cache_ptr->symbol.flags = visible; |
1440 | 363k | break; |
1441 | | |
1442 | | /* N_SETV symbols used to represent set vectors placed in the |
1443 | | data section. They are no longer generated. Theoretically, |
1444 | | it was possible to extract the entries and combine them with |
1445 | | new ones, although I don't know if that was ever actually |
1446 | | done. Unless that feature is restored, treat them as data |
1447 | | symbols. */ |
1448 | 63.5k | case N_SETV: case N_SETV | N_EXT: |
1449 | 293k | case N_DATA: case N_DATA | N_EXT: |
1450 | 293k | cache_ptr->symbol.section = obj_datasec (abfd); |
1451 | 293k | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma; |
1452 | 293k | cache_ptr->symbol.flags = visible; |
1453 | 293k | break; |
1454 | | |
1455 | 142k | case N_BSS: case N_BSS | N_EXT: |
1456 | 142k | cache_ptr->symbol.section = obj_bsssec (abfd); |
1457 | 142k | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma; |
1458 | 142k | cache_ptr->symbol.flags = visible; |
1459 | 142k | break; |
1460 | | |
1461 | 98.6k | case N_SETA: case N_SETA | N_EXT: |
1462 | 139k | case N_SETT: case N_SETT | N_EXT: |
1463 | 287k | case N_SETD: case N_SETD | N_EXT: |
1464 | 342k | case N_SETB: case N_SETB | N_EXT: |
1465 | 342k | { |
1466 | | /* This code is no longer needed. It used to be used to make |
1467 | | the linker handle set symbols, but they are now handled in |
1468 | | the add_symbols routine instead. */ |
1469 | 342k | switch (cache_ptr->type & N_TYPE) |
1470 | 342k | { |
1471 | 98.6k | case N_SETA: |
1472 | 98.6k | cache_ptr->symbol.section = bfd_abs_section_ptr; |
1473 | 98.6k | break; |
1474 | 40.7k | case N_SETT: |
1475 | 40.7k | cache_ptr->symbol.section = obj_textsec (abfd); |
1476 | 40.7k | break; |
1477 | 147k | case N_SETD: |
1478 | 147k | cache_ptr->symbol.section = obj_datasec (abfd); |
1479 | 147k | break; |
1480 | 54.7k | case N_SETB: |
1481 | 54.7k | cache_ptr->symbol.section = obj_bsssec (abfd); |
1482 | 54.7k | break; |
1483 | 342k | } |
1484 | | |
1485 | 342k | cache_ptr->symbol.flags |= BSF_CONSTRUCTOR; |
1486 | 342k | } |
1487 | 0 | break; |
1488 | | |
1489 | 1.26k | case N_WARNING: |
1490 | | /* This symbol is the text of a warning message. The next |
1491 | | symbol is the symbol to associate the warning with. If a |
1492 | | reference is made to that symbol, a warning is issued. */ |
1493 | 1.26k | cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_WARNING; |
1494 | 1.26k | cache_ptr->symbol.section = bfd_abs_section_ptr; |
1495 | 1.26k | break; |
1496 | | |
1497 | 7.86k | case N_INDR: case N_INDR | N_EXT: |
1498 | | /* An indirect symbol. This consists of two symbols in a row. |
1499 | | The first symbol is the name of the indirection. The second |
1500 | | symbol is the name of the target. A reference to the first |
1501 | | symbol becomes a reference to the second. */ |
1502 | 7.86k | cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_INDIRECT | visible; |
1503 | 7.86k | cache_ptr->symbol.section = bfd_ind_section_ptr; |
1504 | 7.86k | break; |
1505 | | |
1506 | 15.5k | case N_WEAKU: |
1507 | 15.5k | cache_ptr->symbol.section = bfd_und_section_ptr; |
1508 | 15.5k | cache_ptr->symbol.flags = BSF_WEAK; |
1509 | 15.5k | break; |
1510 | | |
1511 | 13.4k | case N_WEAKA: |
1512 | 13.4k | cache_ptr->symbol.section = bfd_abs_section_ptr; |
1513 | 13.4k | cache_ptr->symbol.flags = BSF_WEAK; |
1514 | 13.4k | break; |
1515 | | |
1516 | 60.1k | case N_WEAKT: |
1517 | 60.1k | cache_ptr->symbol.section = obj_textsec (abfd); |
1518 | 60.1k | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma; |
1519 | 60.1k | cache_ptr->symbol.flags = BSF_WEAK; |
1520 | 60.1k | break; |
1521 | | |
1522 | 152k | case N_WEAKD: |
1523 | 152k | cache_ptr->symbol.section = obj_datasec (abfd); |
1524 | 152k | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma; |
1525 | 152k | cache_ptr->symbol.flags = BSF_WEAK; |
1526 | 152k | break; |
1527 | | |
1528 | 32.2k | case N_WEAKB: |
1529 | 32.2k | cache_ptr->symbol.section = obj_bsssec (abfd); |
1530 | 32.2k | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma; |
1531 | 32.2k | cache_ptr->symbol.flags = BSF_WEAK; |
1532 | 32.2k | break; |
1533 | 62.7M | } |
1534 | | |
1535 | 62.7M | return true; |
1536 | 62.7M | } Unexecuted instantiation: aout-cris.c:translate_from_native_sym_flags aout-ns32k.c:translate_from_native_sym_flags Line | Count | Source | 1371 | 36.0M | { | 1372 | 36.0M | flagword visible; | 1373 | | | 1374 | 36.0M | if ((cache_ptr->type & N_STAB) != 0 | 1375 | 36.0M | || cache_ptr->type == N_FN) | 1376 | 48.5k | { | 1377 | 48.5k | asection *sec; | 1378 | | | 1379 | | /* This is a debugging symbol. */ | 1380 | 48.5k | cache_ptr->symbol.flags = BSF_DEBUGGING; | 1381 | | | 1382 | | /* Work out the symbol section. */ | 1383 | 48.5k | switch (cache_ptr->type & N_TYPE) | 1384 | 48.5k | { | 1385 | 3.13k | case N_TEXT: | 1386 | 3.13k | case N_FN: | 1387 | 3.13k | sec = obj_textsec (abfd); | 1388 | 3.13k | break; | 1389 | 2.13k | case N_DATA: | 1390 | 2.13k | sec = obj_datasec (abfd); | 1391 | 2.13k | break; | 1392 | 3.37k | case N_BSS: | 1393 | 3.37k | sec = obj_bsssec (abfd); | 1394 | 3.37k | break; | 1395 | 37.8k | default: | 1396 | 39.9k | case N_ABS: | 1397 | 39.9k | sec = bfd_abs_section_ptr; | 1398 | 39.9k | break; | 1399 | 48.5k | } | 1400 | | | 1401 | 48.5k | cache_ptr->symbol.section = sec; | 1402 | 48.5k | cache_ptr->symbol.value -= sec->vma; | 1403 | | | 1404 | 48.5k | return true; | 1405 | 48.5k | } | 1406 | | | 1407 | | /* Get the default visibility. This does not apply to all types, so | 1408 | | we just hold it in a local variable to use if wanted. */ | 1409 | 36.0M | if ((cache_ptr->type & N_EXT) == 0) | 1410 | 35.3M | visible = BSF_LOCAL; | 1411 | 680k | else | 1412 | 680k | visible = BSF_GLOBAL; | 1413 | | | 1414 | 36.0M | switch (cache_ptr->type) | 1415 | 36.0M | { | 1416 | 34.8M | default: | 1417 | 35.0M | case N_ABS: case N_ABS | N_EXT: | 1418 | 35.0M | cache_ptr->symbol.section = bfd_abs_section_ptr; | 1419 | 35.0M | cache_ptr->symbol.flags = visible; | 1420 | 35.0M | break; | 1421 | | | 1422 | 364k | case N_UNDF | N_EXT: | 1423 | 364k | if (cache_ptr->symbol.value != 0) | 1424 | 333k | { | 1425 | | /* This is a common symbol. */ | 1426 | 333k | cache_ptr->symbol.flags = BSF_GLOBAL; | 1427 | 333k | cache_ptr->symbol.section = bfd_com_section_ptr; | 1428 | 333k | } | 1429 | 31.4k | else | 1430 | 31.4k | { | 1431 | 31.4k | cache_ptr->symbol.flags = 0; | 1432 | 31.4k | cache_ptr->symbol.section = bfd_und_section_ptr; | 1433 | 31.4k | } | 1434 | 364k | break; | 1435 | | | 1436 | 111k | case N_TEXT: case N_TEXT | N_EXT: | 1437 | 111k | cache_ptr->symbol.section = obj_textsec (abfd); | 1438 | 111k | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma; | 1439 | 111k | cache_ptr->symbol.flags = visible; | 1440 | 111k | break; | 1441 | | | 1442 | | /* N_SETV symbols used to represent set vectors placed in the | 1443 | | data section. They are no longer generated. Theoretically, | 1444 | | it was possible to extract the entries and combine them with | 1445 | | new ones, although I don't know if that was ever actually | 1446 | | done. Unless that feature is restored, treat them as data | 1447 | | symbols. */ | 1448 | 29.5k | case N_SETV: case N_SETV | N_EXT: | 1449 | 157k | case N_DATA: case N_DATA | N_EXT: | 1450 | 157k | cache_ptr->symbol.section = obj_datasec (abfd); | 1451 | 157k | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma; | 1452 | 157k | cache_ptr->symbol.flags = visible; | 1453 | 157k | break; | 1454 | | | 1455 | 77.0k | case N_BSS: case N_BSS | N_EXT: | 1456 | 77.0k | cache_ptr->symbol.section = obj_bsssec (abfd); | 1457 | 77.0k | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma; | 1458 | 77.0k | cache_ptr->symbol.flags = visible; | 1459 | 77.0k | break; | 1460 | | | 1461 | 52.9k | case N_SETA: case N_SETA | N_EXT: | 1462 | 75.8k | case N_SETT: case N_SETT | N_EXT: | 1463 | 130k | case N_SETD: case N_SETD | N_EXT: | 1464 | 163k | case N_SETB: case N_SETB | N_EXT: | 1465 | 163k | { | 1466 | | /* This code is no longer needed. It used to be used to make | 1467 | | the linker handle set symbols, but they are now handled in | 1468 | | the add_symbols routine instead. */ | 1469 | 163k | switch (cache_ptr->type & N_TYPE) | 1470 | 163k | { | 1471 | 52.9k | case N_SETA: | 1472 | 52.9k | cache_ptr->symbol.section = bfd_abs_section_ptr; | 1473 | 52.9k | break; | 1474 | 22.8k | case N_SETT: | 1475 | 22.8k | cache_ptr->symbol.section = obj_textsec (abfd); | 1476 | 22.8k | break; | 1477 | 54.2k | case N_SETD: | 1478 | 54.2k | cache_ptr->symbol.section = obj_datasec (abfd); | 1479 | 54.2k | break; | 1480 | 33.4k | case N_SETB: | 1481 | 33.4k | cache_ptr->symbol.section = obj_bsssec (abfd); | 1482 | 33.4k | break; | 1483 | 163k | } | 1484 | | | 1485 | 163k | cache_ptr->symbol.flags |= BSF_CONSTRUCTOR; | 1486 | 163k | } | 1487 | 0 | break; | 1488 | | | 1489 | 549 | case N_WARNING: | 1490 | | /* This symbol is the text of a warning message. The next | 1491 | | symbol is the symbol to associate the warning with. If a | 1492 | | reference is made to that symbol, a warning is issued. */ | 1493 | 549 | cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_WARNING; | 1494 | 549 | cache_ptr->symbol.section = bfd_abs_section_ptr; | 1495 | 549 | break; | 1496 | | | 1497 | 4.51k | case N_INDR: case N_INDR | N_EXT: | 1498 | | /* An indirect symbol. This consists of two symbols in a row. | 1499 | | The first symbol is the name of the indirection. The second | 1500 | | symbol is the name of the target. A reference to the first | 1501 | | symbol becomes a reference to the second. */ | 1502 | 4.51k | cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_INDIRECT | visible; | 1503 | 4.51k | cache_ptr->symbol.section = bfd_ind_section_ptr; | 1504 | 4.51k | break; | 1505 | | | 1506 | 5.64k | case N_WEAKU: | 1507 | 5.64k | cache_ptr->symbol.section = bfd_und_section_ptr; | 1508 | 5.64k | cache_ptr->symbol.flags = BSF_WEAK; | 1509 | 5.64k | break; | 1510 | | | 1511 | 5.19k | case N_WEAKA: | 1512 | 5.19k | cache_ptr->symbol.section = bfd_abs_section_ptr; | 1513 | 5.19k | cache_ptr->symbol.flags = BSF_WEAK; | 1514 | 5.19k | break; | 1515 | | | 1516 | 18.4k | case N_WEAKT: | 1517 | 18.4k | cache_ptr->symbol.section = obj_textsec (abfd); | 1518 | 18.4k | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma; | 1519 | 18.4k | cache_ptr->symbol.flags = BSF_WEAK; | 1520 | 18.4k | break; | 1521 | | | 1522 | 78.5k | case N_WEAKD: | 1523 | 78.5k | cache_ptr->symbol.section = obj_datasec (abfd); | 1524 | 78.5k | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma; | 1525 | 78.5k | cache_ptr->symbol.flags = BSF_WEAK; | 1526 | 78.5k | break; | 1527 | | | 1528 | 15.7k | case N_WEAKB: | 1529 | 15.7k | cache_ptr->symbol.section = obj_bsssec (abfd); | 1530 | 15.7k | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma; | 1531 | 15.7k | cache_ptr->symbol.flags = BSF_WEAK; | 1532 | 15.7k | break; | 1533 | 36.0M | } | 1534 | | | 1535 | 36.0M | return true; | 1536 | 36.0M | } |
aout32.c:translate_from_native_sym_flags Line | Count | Source | 1371 | 26.7M | { | 1372 | 26.7M | flagword visible; | 1373 | | | 1374 | 26.7M | if ((cache_ptr->type & N_STAB) != 0 | 1375 | 26.7M | || cache_ptr->type == N_FN) | 1376 | 58.1k | { | 1377 | 58.1k | asection *sec; | 1378 | | | 1379 | | /* This is a debugging symbol. */ | 1380 | 58.1k | cache_ptr->symbol.flags = BSF_DEBUGGING; | 1381 | | | 1382 | | /* Work out the symbol section. */ | 1383 | 58.1k | switch (cache_ptr->type & N_TYPE) | 1384 | 58.1k | { | 1385 | 3.47k | case N_TEXT: | 1386 | 3.47k | case N_FN: | 1387 | 3.47k | sec = obj_textsec (abfd); | 1388 | 3.47k | break; | 1389 | 3.06k | case N_DATA: | 1390 | 3.06k | sec = obj_datasec (abfd); | 1391 | 3.06k | break; | 1392 | 4.88k | case N_BSS: | 1393 | 4.88k | sec = obj_bsssec (abfd); | 1394 | 4.88k | break; | 1395 | 44.5k | default: | 1396 | 46.7k | case N_ABS: | 1397 | 46.7k | sec = bfd_abs_section_ptr; | 1398 | 46.7k | break; | 1399 | 58.1k | } | 1400 | | | 1401 | 58.1k | cache_ptr->symbol.section = sec; | 1402 | 58.1k | cache_ptr->symbol.value -= sec->vma; | 1403 | | | 1404 | 58.1k | return true; | 1405 | 58.1k | } | 1406 | | | 1407 | | /* Get the default visibility. This does not apply to all types, so | 1408 | | we just hold it in a local variable to use if wanted. */ | 1409 | 26.7M | if ((cache_ptr->type & N_EXT) == 0) | 1410 | 25.7M | visible = BSF_LOCAL; | 1411 | 962k | else | 1412 | 962k | visible = BSF_GLOBAL; | 1413 | | | 1414 | 26.7M | switch (cache_ptr->type) | 1415 | 26.7M | { | 1416 | 25.1M | default: | 1417 | 25.3M | case N_ABS: case N_ABS | N_EXT: | 1418 | 25.3M | cache_ptr->symbol.section = bfd_abs_section_ptr; | 1419 | 25.3M | cache_ptr->symbol.flags = visible; | 1420 | 25.3M | break; | 1421 | | | 1422 | 582k | case N_UNDF | N_EXT: | 1423 | 582k | if (cache_ptr->symbol.value != 0) | 1424 | 548k | { | 1425 | | /* This is a common symbol. */ | 1426 | 548k | cache_ptr->symbol.flags = BSF_GLOBAL; | 1427 | 548k | cache_ptr->symbol.section = bfd_com_section_ptr; | 1428 | 548k | } | 1429 | 34.1k | else | 1430 | 34.1k | { | 1431 | 34.1k | cache_ptr->symbol.flags = 0; | 1432 | 34.1k | cache_ptr->symbol.section = bfd_und_section_ptr; | 1433 | 34.1k | } | 1434 | 582k | break; | 1435 | | | 1436 | 251k | case N_TEXT: case N_TEXT | N_EXT: | 1437 | 251k | cache_ptr->symbol.section = obj_textsec (abfd); | 1438 | 251k | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma; | 1439 | 251k | cache_ptr->symbol.flags = visible; | 1440 | 251k | break; | 1441 | | | 1442 | | /* N_SETV symbols used to represent set vectors placed in the | 1443 | | data section. They are no longer generated. Theoretically, | 1444 | | it was possible to extract the entries and combine them with | 1445 | | new ones, although I don't know if that was ever actually | 1446 | | done. Unless that feature is restored, treat them as data | 1447 | | symbols. */ | 1448 | 33.9k | case N_SETV: case N_SETV | N_EXT: | 1449 | 135k | case N_DATA: case N_DATA | N_EXT: | 1450 | 135k | cache_ptr->symbol.section = obj_datasec (abfd); | 1451 | 135k | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma; | 1452 | 135k | cache_ptr->symbol.flags = visible; | 1453 | 135k | break; | 1454 | | | 1455 | 65.5k | case N_BSS: case N_BSS | N_EXT: | 1456 | 65.5k | cache_ptr->symbol.section = obj_bsssec (abfd); | 1457 | 65.5k | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma; | 1458 | 65.5k | cache_ptr->symbol.flags = visible; | 1459 | 65.5k | break; | 1460 | | | 1461 | 45.7k | case N_SETA: case N_SETA | N_EXT: | 1462 | 63.5k | case N_SETT: case N_SETT | N_EXT: | 1463 | 157k | case N_SETD: case N_SETD | N_EXT: | 1464 | 178k | case N_SETB: case N_SETB | N_EXT: | 1465 | 178k | { | 1466 | | /* This code is no longer needed. It used to be used to make | 1467 | | the linker handle set symbols, but they are now handled in | 1468 | | the add_symbols routine instead. */ | 1469 | 178k | switch (cache_ptr->type & N_TYPE) | 1470 | 178k | { | 1471 | 45.7k | case N_SETA: | 1472 | 45.7k | cache_ptr->symbol.section = bfd_abs_section_ptr; | 1473 | 45.7k | break; | 1474 | 17.8k | case N_SETT: | 1475 | 17.8k | cache_ptr->symbol.section = obj_textsec (abfd); | 1476 | 17.8k | break; | 1477 | 93.7k | case N_SETD: | 1478 | 93.7k | cache_ptr->symbol.section = obj_datasec (abfd); | 1479 | 93.7k | break; | 1480 | 21.2k | case N_SETB: | 1481 | 21.2k | cache_ptr->symbol.section = obj_bsssec (abfd); | 1482 | 21.2k | break; | 1483 | 178k | } | 1484 | | | 1485 | 178k | cache_ptr->symbol.flags |= BSF_CONSTRUCTOR; | 1486 | 178k | } | 1487 | 0 | break; | 1488 | | | 1489 | 714 | case N_WARNING: | 1490 | | /* This symbol is the text of a warning message. The next | 1491 | | symbol is the symbol to associate the warning with. If a | 1492 | | reference is made to that symbol, a warning is issued. */ | 1493 | 714 | cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_WARNING; | 1494 | 714 | cache_ptr->symbol.section = bfd_abs_section_ptr; | 1495 | 714 | break; | 1496 | | | 1497 | 3.35k | case N_INDR: case N_INDR | N_EXT: | 1498 | | /* An indirect symbol. This consists of two symbols in a row. | 1499 | | The first symbol is the name of the indirection. The second | 1500 | | symbol is the name of the target. A reference to the first | 1501 | | symbol becomes a reference to the second. */ | 1502 | 3.35k | cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_INDIRECT | visible; | 1503 | 3.35k | cache_ptr->symbol.section = bfd_ind_section_ptr; | 1504 | 3.35k | break; | 1505 | | | 1506 | 9.85k | case N_WEAKU: | 1507 | 9.85k | cache_ptr->symbol.section = bfd_und_section_ptr; | 1508 | 9.85k | cache_ptr->symbol.flags = BSF_WEAK; | 1509 | 9.85k | break; | 1510 | | | 1511 | 8.24k | case N_WEAKA: | 1512 | 8.24k | cache_ptr->symbol.section = bfd_abs_section_ptr; | 1513 | 8.24k | cache_ptr->symbol.flags = BSF_WEAK; | 1514 | 8.24k | break; | 1515 | | | 1516 | 41.7k | case N_WEAKT: | 1517 | 41.7k | cache_ptr->symbol.section = obj_textsec (abfd); | 1518 | 41.7k | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma; | 1519 | 41.7k | cache_ptr->symbol.flags = BSF_WEAK; | 1520 | 41.7k | break; | 1521 | | | 1522 | 73.6k | case N_WEAKD: | 1523 | 73.6k | cache_ptr->symbol.section = obj_datasec (abfd); | 1524 | 73.6k | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma; | 1525 | 73.6k | cache_ptr->symbol.flags = BSF_WEAK; | 1526 | 73.6k | break; | 1527 | | | 1528 | 16.4k | case N_WEAKB: | 1529 | 16.4k | cache_ptr->symbol.section = obj_bsssec (abfd); | 1530 | 16.4k | cache_ptr->symbol.value -= cache_ptr->symbol.section->vma; | 1531 | 16.4k | cache_ptr->symbol.flags = BSF_WEAK; | 1532 | 16.4k | break; | 1533 | 26.7M | } | 1534 | | | 1535 | 26.7M | return true; | 1536 | 26.7M | } |
|
1537 | | |
1538 | | /* Set the fields of SYM_POINTER according to CACHE_PTR. */ |
1539 | | |
1540 | | static bool |
1541 | | translate_to_native_sym_flags (bfd *abfd, |
1542 | | asymbol *cache_ptr, |
1543 | | struct external_nlist *sym_pointer) |
1544 | 9.61k | { |
1545 | 9.61k | bfd_vma value = cache_ptr->value; |
1546 | 9.61k | asection *sec; |
1547 | 9.61k | bfd_vma off; |
1548 | | |
1549 | | /* Mask out any existing type bits in case copying from one section |
1550 | | to another. */ |
1551 | 9.61k | sym_pointer->e_type[0] &= ~N_TYPE; |
1552 | | |
1553 | 9.61k | sec = bfd_asymbol_section (cache_ptr); |
1554 | 9.61k | off = 0; |
1555 | | |
1556 | 9.61k | if (sec == NULL) |
1557 | 0 | { |
1558 | | /* This case occurs, e.g., for the *DEBUG* section of a COFF |
1559 | | file. */ |
1560 | 0 | _bfd_error_handler |
1561 | | /* xgettext:c-format */ |
1562 | 0 | (_("%pB: can not represent section for symbol `%s' in a.out " |
1563 | 0 | "object file format"), |
1564 | 0 | abfd, |
1565 | 0 | cache_ptr->name != NULL ? cache_ptr->name : _("*unknown*")); |
1566 | 0 | bfd_set_error (bfd_error_nonrepresentable_section); |
1567 | 0 | return false; |
1568 | 0 | } |
1569 | | |
1570 | 9.61k | if (sec->output_section != NULL) |
1571 | 9.61k | { |
1572 | 9.61k | off = sec->output_offset; |
1573 | 9.61k | sec = sec->output_section; |
1574 | 9.61k | } |
1575 | | |
1576 | 9.61k | if (bfd_is_abs_section (sec)) |
1577 | 9.60k | sym_pointer->e_type[0] |= N_ABS; |
1578 | 14 | else if (sec == obj_textsec (abfd)) |
1579 | 0 | sym_pointer->e_type[0] |= N_TEXT; |
1580 | 14 | else if (sec == obj_datasec (abfd)) |
1581 | 8 | sym_pointer->e_type[0] |= N_DATA; |
1582 | 6 | else if (sec == obj_bsssec (abfd)) |
1583 | 5 | sym_pointer->e_type[0] |= N_BSS; |
1584 | 1 | else if (bfd_is_und_section (sec)) |
1585 | 0 | sym_pointer->e_type[0] = N_UNDF | N_EXT; |
1586 | 1 | else if (bfd_is_ind_section (sec)) |
1587 | 1 | sym_pointer->e_type[0] = N_INDR; |
1588 | 0 | else if (bfd_is_com_section (sec)) |
1589 | 0 | sym_pointer->e_type[0] = N_UNDF | N_EXT; |
1590 | 0 | else |
1591 | 0 | { |
1592 | 0 | if (aout_section_merge_with_text_p (abfd, sec)) |
1593 | 0 | sym_pointer->e_type[0] |= N_TEXT; |
1594 | 0 | else |
1595 | 0 | { |
1596 | 0 | _bfd_error_handler |
1597 | | /* xgettext:c-format */ |
1598 | 0 | (_("%pB: can not represent section `%pA' in a.out object file format"), |
1599 | 0 | abfd, sec); |
1600 | 0 | bfd_set_error (bfd_error_nonrepresentable_section); |
1601 | 0 | return false; |
1602 | 0 | } |
1603 | 0 | } |
1604 | | |
1605 | | /* Turn the symbol from section relative to absolute again. */ |
1606 | 9.61k | value += sec->vma + off; |
1607 | | |
1608 | 9.61k | if ((cache_ptr->flags & BSF_WARNING) != 0) |
1609 | 0 | sym_pointer->e_type[0] = N_WARNING; |
1610 | | |
1611 | 9.61k | if ((cache_ptr->flags & BSF_DEBUGGING) != 0) |
1612 | 23 | sym_pointer->e_type[0] = ((aout_symbol_type *) cache_ptr)->type; |
1613 | 9.59k | else if ((cache_ptr->flags & BSF_GLOBAL) != 0) |
1614 | 0 | sym_pointer->e_type[0] |= N_EXT; |
1615 | 9.59k | else if ((cache_ptr->flags & BSF_LOCAL) != 0) |
1616 | 9.59k | sym_pointer->e_type[0] &= ~N_EXT; |
1617 | | |
1618 | 9.61k | if ((cache_ptr->flags & BSF_CONSTRUCTOR) != 0) |
1619 | 3 | { |
1620 | 3 | int type = ((aout_symbol_type *) cache_ptr)->type; |
1621 | | |
1622 | 3 | switch (type) |
1623 | 3 | { |
1624 | 0 | case N_ABS: type = N_SETA; break; |
1625 | 0 | case N_TEXT: type = N_SETT; break; |
1626 | 0 | case N_DATA: type = N_SETD; break; |
1627 | 0 | case N_BSS: type = N_SETB; break; |
1628 | 3 | } |
1629 | 3 | sym_pointer->e_type[0] = type; |
1630 | 3 | } |
1631 | | |
1632 | 9.61k | if ((cache_ptr->flags & BSF_WEAK) != 0) |
1633 | 0 | { |
1634 | 0 | int type; |
1635 | |
|
1636 | 0 | switch (sym_pointer->e_type[0] & N_TYPE) |
1637 | 0 | { |
1638 | 0 | default: |
1639 | 0 | case N_ABS: type = N_WEAKA; break; |
1640 | 0 | case N_TEXT: type = N_WEAKT; break; |
1641 | 0 | case N_DATA: type = N_WEAKD; break; |
1642 | 0 | case N_BSS: type = N_WEAKB; break; |
1643 | 0 | case N_UNDF: type = N_WEAKU; break; |
1644 | 0 | } |
1645 | 0 | sym_pointer->e_type[0] = type; |
1646 | 0 | } |
1647 | | |
1648 | 9.61k | PUT_WORD (abfd, value, sym_pointer->e_value); |
1649 | | |
1650 | 9.61k | return true; |
1651 | 9.61k | } Unexecuted instantiation: aout-cris.c:translate_to_native_sym_flags aout-ns32k.c:translate_to_native_sym_flags Line | Count | Source | 1544 | 21 | { | 1545 | 21 | bfd_vma value = cache_ptr->value; | 1546 | 21 | asection *sec; | 1547 | 21 | bfd_vma off; | 1548 | | | 1549 | | /* Mask out any existing type bits in case copying from one section | 1550 | | to another. */ | 1551 | 21 | sym_pointer->e_type[0] &= ~N_TYPE; | 1552 | | | 1553 | 21 | sec = bfd_asymbol_section (cache_ptr); | 1554 | 21 | off = 0; | 1555 | | | 1556 | 21 | if (sec == NULL) | 1557 | 0 | { | 1558 | | /* This case occurs, e.g., for the *DEBUG* section of a COFF | 1559 | | file. */ | 1560 | 0 | _bfd_error_handler | 1561 | | /* xgettext:c-format */ | 1562 | 0 | (_("%pB: can not represent section for symbol `%s' in a.out " | 1563 | 0 | "object file format"), | 1564 | 0 | abfd, | 1565 | 0 | cache_ptr->name != NULL ? cache_ptr->name : _("*unknown*")); | 1566 | 0 | bfd_set_error (bfd_error_nonrepresentable_section); | 1567 | 0 | return false; | 1568 | 0 | } | 1569 | | | 1570 | 21 | if (sec->output_section != NULL) | 1571 | 21 | { | 1572 | 21 | off = sec->output_offset; | 1573 | 21 | sec = sec->output_section; | 1574 | 21 | } | 1575 | | | 1576 | 21 | if (bfd_is_abs_section (sec)) | 1577 | 11 | sym_pointer->e_type[0] |= N_ABS; | 1578 | 10 | else if (sec == obj_textsec (abfd)) | 1579 | 0 | sym_pointer->e_type[0] |= N_TEXT; | 1580 | 10 | else if (sec == obj_datasec (abfd)) | 1581 | 8 | sym_pointer->e_type[0] |= N_DATA; | 1582 | 2 | else if (sec == obj_bsssec (abfd)) | 1583 | 2 | sym_pointer->e_type[0] |= N_BSS; | 1584 | 0 | else if (bfd_is_und_section (sec)) | 1585 | 0 | sym_pointer->e_type[0] = N_UNDF | N_EXT; | 1586 | 0 | else if (bfd_is_ind_section (sec)) | 1587 | 0 | sym_pointer->e_type[0] = N_INDR; | 1588 | 0 | else if (bfd_is_com_section (sec)) | 1589 | 0 | sym_pointer->e_type[0] = N_UNDF | N_EXT; | 1590 | 0 | else | 1591 | 0 | { | 1592 | 0 | if (aout_section_merge_with_text_p (abfd, sec)) | 1593 | 0 | sym_pointer->e_type[0] |= N_TEXT; | 1594 | 0 | else | 1595 | 0 | { | 1596 | 0 | _bfd_error_handler | 1597 | | /* xgettext:c-format */ | 1598 | 0 | (_("%pB: can not represent section `%pA' in a.out object file format"), | 1599 | 0 | abfd, sec); | 1600 | 0 | bfd_set_error (bfd_error_nonrepresentable_section); | 1601 | 0 | return false; | 1602 | 0 | } | 1603 | 0 | } | 1604 | | | 1605 | | /* Turn the symbol from section relative to absolute again. */ | 1606 | 21 | value += sec->vma + off; | 1607 | | | 1608 | 21 | if ((cache_ptr->flags & BSF_WARNING) != 0) | 1609 | 0 | sym_pointer->e_type[0] = N_WARNING; | 1610 | | | 1611 | 21 | if ((cache_ptr->flags & BSF_DEBUGGING) != 0) | 1612 | 21 | sym_pointer->e_type[0] = ((aout_symbol_type *) cache_ptr)->type; | 1613 | 0 | else if ((cache_ptr->flags & BSF_GLOBAL) != 0) | 1614 | 0 | sym_pointer->e_type[0] |= N_EXT; | 1615 | 0 | else if ((cache_ptr->flags & BSF_LOCAL) != 0) | 1616 | 0 | sym_pointer->e_type[0] &= ~N_EXT; | 1617 | | | 1618 | 21 | if ((cache_ptr->flags & BSF_CONSTRUCTOR) != 0) | 1619 | 0 | { | 1620 | 0 | int type = ((aout_symbol_type *) cache_ptr)->type; | 1621 | |
| 1622 | 0 | switch (type) | 1623 | 0 | { | 1624 | 0 | case N_ABS: type = N_SETA; break; | 1625 | 0 | case N_TEXT: type = N_SETT; break; | 1626 | 0 | case N_DATA: type = N_SETD; break; | 1627 | 0 | case N_BSS: type = N_SETB; break; | 1628 | 0 | } | 1629 | 0 | sym_pointer->e_type[0] = type; | 1630 | 0 | } | 1631 | | | 1632 | 21 | if ((cache_ptr->flags & BSF_WEAK) != 0) | 1633 | 0 | { | 1634 | 0 | int type; | 1635 | |
| 1636 | 0 | switch (sym_pointer->e_type[0] & N_TYPE) | 1637 | 0 | { | 1638 | 0 | default: | 1639 | 0 | case N_ABS: type = N_WEAKA; break; | 1640 | 0 | case N_TEXT: type = N_WEAKT; break; | 1641 | 0 | case N_DATA: type = N_WEAKD; break; | 1642 | 0 | case N_BSS: type = N_WEAKB; break; | 1643 | 0 | case N_UNDF: type = N_WEAKU; break; | 1644 | 0 | } | 1645 | 0 | sym_pointer->e_type[0] = type; | 1646 | 0 | } | 1647 | | | 1648 | 21 | PUT_WORD (abfd, value, sym_pointer->e_value); | 1649 | | | 1650 | 21 | return true; | 1651 | 21 | } |
aout32.c:translate_to_native_sym_flags Line | Count | Source | 1544 | 9.59k | { | 1545 | 9.59k | bfd_vma value = cache_ptr->value; | 1546 | 9.59k | asection *sec; | 1547 | 9.59k | bfd_vma off; | 1548 | | | 1549 | | /* Mask out any existing type bits in case copying from one section | 1550 | | to another. */ | 1551 | 9.59k | sym_pointer->e_type[0] &= ~N_TYPE; | 1552 | | | 1553 | 9.59k | sec = bfd_asymbol_section (cache_ptr); | 1554 | 9.59k | off = 0; | 1555 | | | 1556 | 9.59k | if (sec == NULL) | 1557 | 0 | { | 1558 | | /* This case occurs, e.g., for the *DEBUG* section of a COFF | 1559 | | file. */ | 1560 | 0 | _bfd_error_handler | 1561 | | /* xgettext:c-format */ | 1562 | 0 | (_("%pB: can not represent section for symbol `%s' in a.out " | 1563 | 0 | "object file format"), | 1564 | 0 | abfd, | 1565 | 0 | cache_ptr->name != NULL ? cache_ptr->name : _("*unknown*")); | 1566 | 0 | bfd_set_error (bfd_error_nonrepresentable_section); | 1567 | 0 | return false; | 1568 | 0 | } | 1569 | | | 1570 | 9.59k | if (sec->output_section != NULL) | 1571 | 9.59k | { | 1572 | 9.59k | off = sec->output_offset; | 1573 | 9.59k | sec = sec->output_section; | 1574 | 9.59k | } | 1575 | | | 1576 | 9.59k | if (bfd_is_abs_section (sec)) | 1577 | 9.59k | sym_pointer->e_type[0] |= N_ABS; | 1578 | 4 | else if (sec == obj_textsec (abfd)) | 1579 | 0 | sym_pointer->e_type[0] |= N_TEXT; | 1580 | 4 | else if (sec == obj_datasec (abfd)) | 1581 | 0 | sym_pointer->e_type[0] |= N_DATA; | 1582 | 4 | else if (sec == obj_bsssec (abfd)) | 1583 | 3 | sym_pointer->e_type[0] |= N_BSS; | 1584 | 1 | else if (bfd_is_und_section (sec)) | 1585 | 0 | sym_pointer->e_type[0] = N_UNDF | N_EXT; | 1586 | 1 | else if (bfd_is_ind_section (sec)) | 1587 | 1 | sym_pointer->e_type[0] = N_INDR; | 1588 | 0 | else if (bfd_is_com_section (sec)) | 1589 | 0 | sym_pointer->e_type[0] = N_UNDF | N_EXT; | 1590 | 0 | else | 1591 | 0 | { | 1592 | 0 | if (aout_section_merge_with_text_p (abfd, sec)) | 1593 | 0 | sym_pointer->e_type[0] |= N_TEXT; | 1594 | 0 | else | 1595 | 0 | { | 1596 | 0 | _bfd_error_handler | 1597 | | /* xgettext:c-format */ | 1598 | 0 | (_("%pB: can not represent section `%pA' in a.out object file format"), | 1599 | 0 | abfd, sec); | 1600 | 0 | bfd_set_error (bfd_error_nonrepresentable_section); | 1601 | 0 | return false; | 1602 | 0 | } | 1603 | 0 | } | 1604 | | | 1605 | | /* Turn the symbol from section relative to absolute again. */ | 1606 | 9.59k | value += sec->vma + off; | 1607 | | | 1608 | 9.59k | if ((cache_ptr->flags & BSF_WARNING) != 0) | 1609 | 0 | sym_pointer->e_type[0] = N_WARNING; | 1610 | | | 1611 | 9.59k | if ((cache_ptr->flags & BSF_DEBUGGING) != 0) | 1612 | 2 | sym_pointer->e_type[0] = ((aout_symbol_type *) cache_ptr)->type; | 1613 | 9.59k | else if ((cache_ptr->flags & BSF_GLOBAL) != 0) | 1614 | 0 | sym_pointer->e_type[0] |= N_EXT; | 1615 | 9.59k | else if ((cache_ptr->flags & BSF_LOCAL) != 0) | 1616 | 9.59k | sym_pointer->e_type[0] &= ~N_EXT; | 1617 | | | 1618 | 9.59k | if ((cache_ptr->flags & BSF_CONSTRUCTOR) != 0) | 1619 | 3 | { | 1620 | 3 | int type = ((aout_symbol_type *) cache_ptr)->type; | 1621 | | | 1622 | 3 | switch (type) | 1623 | 3 | { | 1624 | 0 | case N_ABS: type = N_SETA; break; | 1625 | 0 | case N_TEXT: type = N_SETT; break; | 1626 | 0 | case N_DATA: type = N_SETD; break; | 1627 | 0 | case N_BSS: type = N_SETB; break; | 1628 | 3 | } | 1629 | 3 | sym_pointer->e_type[0] = type; | 1630 | 3 | } | 1631 | | | 1632 | 9.59k | if ((cache_ptr->flags & BSF_WEAK) != 0) | 1633 | 0 | { | 1634 | 0 | int type; | 1635 | |
| 1636 | 0 | switch (sym_pointer->e_type[0] & N_TYPE) | 1637 | 0 | { | 1638 | 0 | default: | 1639 | 0 | case N_ABS: type = N_WEAKA; break; | 1640 | 0 | case N_TEXT: type = N_WEAKT; break; | 1641 | 0 | case N_DATA: type = N_WEAKD; break; | 1642 | 0 | case N_BSS: type = N_WEAKB; break; | 1643 | 0 | case N_UNDF: type = N_WEAKU; break; | 1644 | 0 | } | 1645 | 0 | sym_pointer->e_type[0] = type; | 1646 | 0 | } | 1647 | | | 1648 | 9.59k | PUT_WORD (abfd, value, sym_pointer->e_value); | 1649 | | | 1650 | 9.59k | return true; | 1651 | 9.59k | } |
|
1652 | | |
1653 | | /* Native-level interface to symbols. */ |
1654 | | |
1655 | | asymbol * |
1656 | | NAME (aout, make_empty_symbol) (bfd *abfd) |
1657 | 855k | { |
1658 | 855k | size_t amt = sizeof (aout_symbol_type); |
1659 | | |
1660 | 855k | aout_symbol_type *new_symbol = (aout_symbol_type *) bfd_zalloc (abfd, amt); |
1661 | 855k | if (!new_symbol) |
1662 | 0 | return NULL; |
1663 | 855k | new_symbol->symbol.the_bfd = abfd; |
1664 | | |
1665 | 855k | return &new_symbol->symbol; |
1666 | 855k | } cris_aout_32_make_empty_symbol Line | Count | Source | 1657 | 17.1k | { | 1658 | 17.1k | size_t amt = sizeof (aout_symbol_type); | 1659 | | | 1660 | 17.1k | aout_symbol_type *new_symbol = (aout_symbol_type *) bfd_zalloc (abfd, amt); | 1661 | 17.1k | if (!new_symbol) | 1662 | 0 | return NULL; | 1663 | 17.1k | new_symbol->symbol.the_bfd = abfd; | 1664 | | | 1665 | 17.1k | return &new_symbol->symbol; | 1666 | 17.1k | } |
ns32kaout_32_make_empty_symbol Line | Count | Source | 1657 | 76.5k | { | 1658 | 76.5k | size_t amt = sizeof (aout_symbol_type); | 1659 | | | 1660 | 76.5k | aout_symbol_type *new_symbol = (aout_symbol_type *) bfd_zalloc (abfd, amt); | 1661 | 76.5k | if (!new_symbol) | 1662 | 0 | return NULL; | 1663 | 76.5k | new_symbol->symbol.the_bfd = abfd; | 1664 | | | 1665 | 76.5k | return &new_symbol->symbol; | 1666 | 76.5k | } |
aout_32_make_empty_symbol Line | Count | Source | 1657 | 761k | { | 1658 | 761k | size_t amt = sizeof (aout_symbol_type); | 1659 | | | 1660 | 761k | aout_symbol_type *new_symbol = (aout_symbol_type *) bfd_zalloc (abfd, amt); | 1661 | 761k | if (!new_symbol) | 1662 | 0 | return NULL; | 1663 | 761k | new_symbol->symbol.the_bfd = abfd; | 1664 | | | 1665 | 761k | return &new_symbol->symbol; | 1666 | 761k | } |
|
1667 | | |
1668 | | /* Translate a set of external symbols into internal symbols. */ |
1669 | | |
1670 | | bool |
1671 | | NAME (aout, translate_symbol_table) (bfd *abfd, |
1672 | | aout_symbol_type *in, |
1673 | | struct external_nlist *ext, |
1674 | | bfd_size_type count, |
1675 | | char *str, |
1676 | | bfd_size_type strsize, |
1677 | | bool dynamic) |
1678 | 65.8M | { |
1679 | 65.8M | struct external_nlist *ext_end; |
1680 | | |
1681 | 65.8M | ext_end = ext + count; |
1682 | 128M | for (; ext < ext_end; ext++, in++) |
1683 | 65.8M | { |
1684 | 65.8M | bfd_vma x; |
1685 | | |
1686 | 65.8M | x = GET_WORD (abfd, ext->e_strx); |
1687 | 65.8M | in->symbol.the_bfd = abfd; |
1688 | | |
1689 | | /* For the normal symbols, the zero index points at the number |
1690 | | of bytes in the string table but is to be interpreted as the |
1691 | | null string. For the dynamic symbols, the number of bytes in |
1692 | | the string table is stored in the __DYNAMIC structure and the |
1693 | | zero index points at an actual string. */ |
1694 | 65.8M | if (x == 0 && ! dynamic) |
1695 | 61.2M | in->symbol.name = ""; |
1696 | 4.59M | else if (x < strsize) |
1697 | 1.59M | in->symbol.name = str + x; |
1698 | 2.99M | else |
1699 | 2.99M | { |
1700 | 2.99M | _bfd_error_handler |
1701 | 2.99M | (_("%pB: invalid string offset %" PRIu64 " >= %" PRIu64), |
1702 | 2.99M | abfd, (uint64_t) x, (uint64_t) strsize); |
1703 | 2.99M | bfd_set_error (bfd_error_bad_value); |
1704 | 2.99M | return false; |
1705 | 2.99M | } |
1706 | | |
1707 | 62.8M | in->symbol.value = GET_SWORD (abfd, ext->e_value); |
1708 | 62.8M | in->desc = H_GET_16 (abfd, ext->e_desc); |
1709 | 62.8M | in->other = H_GET_8 (abfd, ext->e_other); |
1710 | 62.8M | in->type = H_GET_8 (abfd, ext->e_type); |
1711 | 62.8M | in->symbol.udata.p = NULL; |
1712 | | |
1713 | 62.8M | if (! translate_from_native_sym_flags (abfd, in)) |
1714 | 0 | return false; |
1715 | | |
1716 | 62.8M | if (dynamic) |
1717 | 0 | in->symbol.flags |= BSF_DYNAMIC; |
1718 | 62.8M | } |
1719 | | |
1720 | 62.8M | return true; |
1721 | 65.8M | } Unexecuted instantiation: cris_aout_32_translate_symbol_table ns32kaout_32_translate_symbol_table Line | Count | Source | 1678 | 37.5M | { | 1679 | 37.5M | struct external_nlist *ext_end; | 1680 | | | 1681 | 37.5M | ext_end = ext + count; | 1682 | 73.6M | for (; ext < ext_end; ext++, in++) | 1683 | 37.5M | { | 1684 | 37.5M | bfd_vma x; | 1685 | | | 1686 | 37.5M | x = GET_WORD (abfd, ext->e_strx); | 1687 | 37.5M | in->symbol.the_bfd = abfd; | 1688 | | | 1689 | | /* For the normal symbols, the zero index points at the number | 1690 | | of bytes in the string table but is to be interpreted as the | 1691 | | null string. For the dynamic symbols, the number of bytes in | 1692 | | the string table is stored in the __DYNAMIC structure and the | 1693 | | zero index points at an actual string. */ | 1694 | 37.5M | if (x == 0 && ! dynamic) | 1695 | 35.3M | in->symbol.name = ""; | 1696 | 2.27M | else if (x < strsize) | 1697 | 782k | in->symbol.name = str + x; | 1698 | 1.48M | else | 1699 | 1.48M | { | 1700 | 1.48M | _bfd_error_handler | 1701 | 1.48M | (_("%pB: invalid string offset %" PRIu64 " >= %" PRIu64), | 1702 | 1.48M | abfd, (uint64_t) x, (uint64_t) strsize); | 1703 | 1.48M | bfd_set_error (bfd_error_bad_value); | 1704 | 1.48M | return false; | 1705 | 1.48M | } | 1706 | | | 1707 | 36.0M | in->symbol.value = GET_SWORD (abfd, ext->e_value); | 1708 | 36.0M | in->desc = H_GET_16 (abfd, ext->e_desc); | 1709 | 36.0M | in->other = H_GET_8 (abfd, ext->e_other); | 1710 | 36.0M | in->type = H_GET_8 (abfd, ext->e_type); | 1711 | 36.0M | in->symbol.udata.p = NULL; | 1712 | | | 1713 | 36.0M | if (! translate_from_native_sym_flags (abfd, in)) | 1714 | 0 | return false; | 1715 | | | 1716 | 36.0M | if (dynamic) | 1717 | 0 | in->symbol.flags |= BSF_DYNAMIC; | 1718 | 36.0M | } | 1719 | | | 1720 | 36.0M | return true; | 1721 | 37.5M | } |
aout_32_translate_symbol_table Line | Count | Source | 1678 | 28.2M | { | 1679 | 28.2M | struct external_nlist *ext_end; | 1680 | | | 1681 | 28.2M | ext_end = ext + count; | 1682 | 55.0M | for (; ext < ext_end; ext++, in++) | 1683 | 28.2M | { | 1684 | 28.2M | bfd_vma x; | 1685 | | | 1686 | 28.2M | x = GET_WORD (abfd, ext->e_strx); | 1687 | 28.2M | in->symbol.the_bfd = abfd; | 1688 | | | 1689 | | /* For the normal symbols, the zero index points at the number | 1690 | | of bytes in the string table but is to be interpreted as the | 1691 | | null string. For the dynamic symbols, the number of bytes in | 1692 | | the string table is stored in the __DYNAMIC structure and the | 1693 | | zero index points at an actual string. */ | 1694 | 28.2M | if (x == 0 && ! dynamic) | 1695 | 25.9M | in->symbol.name = ""; | 1696 | 2.32M | else if (x < strsize) | 1697 | 817k | in->symbol.name = str + x; | 1698 | 1.50M | else | 1699 | 1.50M | { | 1700 | 1.50M | _bfd_error_handler | 1701 | 1.50M | (_("%pB: invalid string offset %" PRIu64 " >= %" PRIu64), | 1702 | 1.50M | abfd, (uint64_t) x, (uint64_t) strsize); | 1703 | 1.50M | bfd_set_error (bfd_error_bad_value); | 1704 | 1.50M | return false; | 1705 | 1.50M | } | 1706 | | | 1707 | 26.7M | in->symbol.value = GET_SWORD (abfd, ext->e_value); | 1708 | 26.7M | in->desc = H_GET_16 (abfd, ext->e_desc); | 1709 | 26.7M | in->other = H_GET_8 (abfd, ext->e_other); | 1710 | 26.7M | in->type = H_GET_8 (abfd, ext->e_type); | 1711 | 26.7M | in->symbol.udata.p = NULL; | 1712 | | | 1713 | 26.7M | if (! translate_from_native_sym_flags (abfd, in)) | 1714 | 0 | return false; | 1715 | | | 1716 | 26.7M | if (dynamic) | 1717 | 0 | in->symbol.flags |= BSF_DYNAMIC; | 1718 | 26.7M | } | 1719 | | | 1720 | 26.7M | return true; | 1721 | 28.2M | } |
|
1722 | | |
1723 | | /* We read the symbols into a buffer, which is discarded when this |
1724 | | function exits. We read the strings into a buffer large enough to |
1725 | | hold them all plus all the cached symbol entries. */ |
1726 | | |
1727 | | bool |
1728 | | NAME (aout, slurp_symbol_table) (bfd *abfd) |
1729 | 2.53k | { |
1730 | 2.53k | struct external_nlist *old_external_syms; |
1731 | 2.53k | aout_symbol_type *cached; |
1732 | 2.53k | bfd_size_type cached_size; |
1733 | | |
1734 | | /* If there's no work to be done, don't do any. */ |
1735 | 2.53k | if (obj_aout_symbols (abfd) != NULL) |
1736 | 1.21k | return true; |
1737 | | |
1738 | 1.32k | old_external_syms = obj_aout_external_syms (abfd); |
1739 | | |
1740 | 1.32k | if (! aout_get_external_symbols (abfd)) |
1741 | 196 | return false; |
1742 | | |
1743 | 1.12k | cached_size = obj_aout_external_sym_count (abfd); |
1744 | 1.12k | if (cached_size == 0) |
1745 | 18 | return true; /* Nothing to do. */ |
1746 | | |
1747 | 1.11k | cached_size *= sizeof (aout_symbol_type); |
1748 | 1.11k | cached = (aout_symbol_type *) bfd_zmalloc (cached_size); |
1749 | 1.11k | if (cached == NULL) |
1750 | 0 | return false; |
1751 | | |
1752 | | /* Convert from external symbol information to internal. */ |
1753 | 1.11k | if (! (NAME (aout, translate_symbol_table) |
1754 | 1.11k | (abfd, cached, |
1755 | 1.11k | obj_aout_external_syms (abfd), |
1756 | 1.11k | obj_aout_external_sym_count (abfd), |
1757 | 1.11k | obj_aout_external_strings (abfd), |
1758 | 1.11k | obj_aout_external_string_size (abfd), |
1759 | 1.11k | false))) |
1760 | 228 | { |
1761 | 228 | free (cached); |
1762 | 228 | return false; |
1763 | 228 | } |
1764 | | |
1765 | 882 | abfd->symcount = obj_aout_external_sym_count (abfd); |
1766 | | |
1767 | 882 | obj_aout_symbols (abfd) = cached; |
1768 | | |
1769 | | /* It is very likely that anybody who calls this function will not |
1770 | | want the external symbol information, so if it was allocated |
1771 | | because of our call to aout_get_external_symbols, we free it up |
1772 | | right away to save space. */ |
1773 | 882 | if (old_external_syms == NULL |
1774 | 882 | && obj_aout_external_syms (abfd) != NULL) |
1775 | 668 | { |
1776 | 668 | free (obj_aout_external_syms (abfd)); |
1777 | 668 | obj_aout_external_syms (abfd) = NULL; |
1778 | 668 | } |
1779 | | |
1780 | 882 | return true; |
1781 | 1.11k | } Unexecuted instantiation: cris_aout_32_slurp_symbol_table ns32kaout_32_slurp_symbol_table Line | Count | Source | 1729 | 1.50k | { | 1730 | 1.50k | struct external_nlist *old_external_syms; | 1731 | 1.50k | aout_symbol_type *cached; | 1732 | 1.50k | bfd_size_type cached_size; | 1733 | | | 1734 | | /* If there's no work to be done, don't do any. */ | 1735 | 1.50k | if (obj_aout_symbols (abfd) != NULL) | 1736 | 724 | return true; | 1737 | | | 1738 | 776 | old_external_syms = obj_aout_external_syms (abfd); | 1739 | | | 1740 | 776 | if (! aout_get_external_symbols (abfd)) | 1741 | 100 | return false; | 1742 | | | 1743 | 676 | cached_size = obj_aout_external_sym_count (abfd); | 1744 | 676 | if (cached_size == 0) | 1745 | 12 | return true; /* Nothing to do. */ | 1746 | | | 1747 | 664 | cached_size *= sizeof (aout_symbol_type); | 1748 | 664 | cached = (aout_symbol_type *) bfd_zmalloc (cached_size); | 1749 | 664 | if (cached == NULL) | 1750 | 0 | return false; | 1751 | | | 1752 | | /* Convert from external symbol information to internal. */ | 1753 | 664 | if (! (NAME (aout, translate_symbol_table) | 1754 | 664 | (abfd, cached, | 1755 | 664 | obj_aout_external_syms (abfd), | 1756 | 664 | obj_aout_external_sym_count (abfd), | 1757 | 664 | obj_aout_external_strings (abfd), | 1758 | 664 | obj_aout_external_string_size (abfd), | 1759 | 664 | false))) | 1760 | 102 | { | 1761 | 102 | free (cached); | 1762 | 102 | return false; | 1763 | 102 | } | 1764 | | | 1765 | 562 | abfd->symcount = obj_aout_external_sym_count (abfd); | 1766 | | | 1767 | 562 | obj_aout_symbols (abfd) = cached; | 1768 | | | 1769 | | /* It is very likely that anybody who calls this function will not | 1770 | | want the external symbol information, so if it was allocated | 1771 | | because of our call to aout_get_external_symbols, we free it up | 1772 | | right away to save space. */ | 1773 | 562 | if (old_external_syms == NULL | 1774 | 562 | && obj_aout_external_syms (abfd) != NULL) | 1775 | 452 | { | 1776 | 452 | free (obj_aout_external_syms (abfd)); | 1777 | 452 | obj_aout_external_syms (abfd) = NULL; | 1778 | 452 | } | 1779 | | | 1780 | 562 | return true; | 1781 | 664 | } |
aout_32_slurp_symbol_table Line | Count | Source | 1729 | 1.03k | { | 1730 | 1.03k | struct external_nlist *old_external_syms; | 1731 | 1.03k | aout_symbol_type *cached; | 1732 | 1.03k | bfd_size_type cached_size; | 1733 | | | 1734 | | /* If there's no work to be done, don't do any. */ | 1735 | 1.03k | if (obj_aout_symbols (abfd) != NULL) | 1736 | 490 | return true; | 1737 | | | 1738 | 548 | old_external_syms = obj_aout_external_syms (abfd); | 1739 | | | 1740 | 548 | if (! aout_get_external_symbols (abfd)) | 1741 | 96 | return false; | 1742 | | | 1743 | 452 | cached_size = obj_aout_external_sym_count (abfd); | 1744 | 452 | if (cached_size == 0) | 1745 | 6 | return true; /* Nothing to do. */ | 1746 | | | 1747 | 446 | cached_size *= sizeof (aout_symbol_type); | 1748 | 446 | cached = (aout_symbol_type *) bfd_zmalloc (cached_size); | 1749 | 446 | if (cached == NULL) | 1750 | 0 | return false; | 1751 | | | 1752 | | /* Convert from external symbol information to internal. */ | 1753 | 446 | if (! (NAME (aout, translate_symbol_table) | 1754 | 446 | (abfd, cached, | 1755 | 446 | obj_aout_external_syms (abfd), | 1756 | 446 | obj_aout_external_sym_count (abfd), | 1757 | 446 | obj_aout_external_strings (abfd), | 1758 | 446 | obj_aout_external_string_size (abfd), | 1759 | 446 | false))) | 1760 | 126 | { | 1761 | 126 | free (cached); | 1762 | 126 | return false; | 1763 | 126 | } | 1764 | | | 1765 | 320 | abfd->symcount = obj_aout_external_sym_count (abfd); | 1766 | | | 1767 | 320 | obj_aout_symbols (abfd) = cached; | 1768 | | | 1769 | | /* It is very likely that anybody who calls this function will not | 1770 | | want the external symbol information, so if it was allocated | 1771 | | because of our call to aout_get_external_symbols, we free it up | 1772 | | right away to save space. */ | 1773 | 320 | if (old_external_syms == NULL | 1774 | 320 | && obj_aout_external_syms (abfd) != NULL) | 1775 | 216 | { | 1776 | 216 | free (obj_aout_external_syms (abfd)); | 1777 | 216 | obj_aout_external_syms (abfd) = NULL; | 1778 | 216 | } | 1779 | | | 1780 | 320 | return true; | 1781 | 446 | } |
|
1782 | | |
1783 | | /* We use a hash table when writing out symbols so that we only write |
1784 | | out a particular string once. This helps particularly when the |
1785 | | linker writes out stabs debugging entries, because each different |
1786 | | contributing object file tends to have many duplicate stabs |
1787 | | strings. |
1788 | | |
1789 | | This hash table code breaks dbx on SunOS 4.1.3, so we don't do it |
1790 | | if BFD_TRADITIONAL_FORMAT is set. */ |
1791 | | |
1792 | | /* Get the index of a string in a strtab, adding it if it is not |
1793 | | already present. */ |
1794 | | |
1795 | | static inline bfd_size_type |
1796 | | add_to_stringtab (bfd *abfd, |
1797 | | struct bfd_strtab_hash *tab, |
1798 | | const char *str, |
1799 | | bool copy) |
1800 | 9.61k | { |
1801 | 9.61k | bool hash; |
1802 | 9.61k | bfd_size_type str_index; |
1803 | | |
1804 | | /* An index of 0 always means the empty string. */ |
1805 | 9.61k | if (str == 0 || *str == '\0') |
1806 | 9.61k | return 0; |
1807 | | |
1808 | | /* Don't hash if BFD_TRADITIONAL_FORMAT is set, because SunOS dbx |
1809 | | doesn't understand a hashed string table. */ |
1810 | 0 | hash = true; |
1811 | 0 | if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0) |
1812 | 0 | hash = false; |
1813 | |
|
1814 | 0 | str_index = _bfd_stringtab_add (tab, str, hash, copy); |
1815 | |
|
1816 | 0 | if (str_index != (bfd_size_type) -1) |
1817 | | /* Add BYTES_IN_WORD to the return value to account for the |
1818 | | space taken up by the string table size. */ |
1819 | 0 | str_index += BYTES_IN_WORD; |
1820 | |
|
1821 | 0 | return str_index; |
1822 | 9.61k | } Unexecuted instantiation: aout-cris.c:add_to_stringtab aout-ns32k.c:add_to_stringtab Line | Count | Source | 1800 | 21 | { | 1801 | 21 | bool hash; | 1802 | 21 | bfd_size_type str_index; | 1803 | | | 1804 | | /* An index of 0 always means the empty string. */ | 1805 | 21 | if (str == 0 || *str == '\0') | 1806 | 21 | return 0; | 1807 | | | 1808 | | /* Don't hash if BFD_TRADITIONAL_FORMAT is set, because SunOS dbx | 1809 | | doesn't understand a hashed string table. */ | 1810 | 0 | hash = true; | 1811 | 0 | if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0) | 1812 | 0 | hash = false; | 1813 | |
| 1814 | 0 | str_index = _bfd_stringtab_add (tab, str, hash, copy); | 1815 | |
| 1816 | 0 | if (str_index != (bfd_size_type) -1) | 1817 | | /* Add BYTES_IN_WORD to the return value to account for the | 1818 | | space taken up by the string table size. */ | 1819 | 0 | str_index += BYTES_IN_WORD; | 1820 | |
| 1821 | 0 | return str_index; | 1822 | 21 | } |
aout32.c:add_to_stringtab Line | Count | Source | 1800 | 9.59k | { | 1801 | 9.59k | bool hash; | 1802 | 9.59k | bfd_size_type str_index; | 1803 | | | 1804 | | /* An index of 0 always means the empty string. */ | 1805 | 9.59k | if (str == 0 || *str == '\0') | 1806 | 9.59k | return 0; | 1807 | | | 1808 | | /* Don't hash if BFD_TRADITIONAL_FORMAT is set, because SunOS dbx | 1809 | | doesn't understand a hashed string table. */ | 1810 | 0 | hash = true; | 1811 | 0 | if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0) | 1812 | 0 | hash = false; | 1813 | |
| 1814 | 0 | str_index = _bfd_stringtab_add (tab, str, hash, copy); | 1815 | |
| 1816 | 0 | if (str_index != (bfd_size_type) -1) | 1817 | | /* Add BYTES_IN_WORD to the return value to account for the | 1818 | | space taken up by the string table size. */ | 1819 | 0 | str_index += BYTES_IN_WORD; | 1820 | |
| 1821 | 0 | return str_index; | 1822 | 9.59k | } |
|
1823 | | |
1824 | | /* Write out a strtab. ABFD is already at the right location in the |
1825 | | file. */ |
1826 | | |
1827 | | static bool |
1828 | | emit_stringtab (bfd *abfd, struct bfd_strtab_hash *tab) |
1829 | 3 | { |
1830 | 3 | bfd_byte buffer[BYTES_IN_WORD]; |
1831 | 3 | size_t amt = BYTES_IN_WORD; |
1832 | | |
1833 | | /* The string table starts with the size. */ |
1834 | 3 | PUT_WORD (abfd, _bfd_stringtab_size (tab) + BYTES_IN_WORD, buffer); |
1835 | 3 | if (bfd_write (buffer, amt, abfd) != amt) |
1836 | 0 | return false; |
1837 | | |
1838 | 3 | return _bfd_stringtab_emit (abfd, tab); |
1839 | 3 | } Unexecuted instantiation: aout-cris.c:emit_stringtab aout-ns32k.c:emit_stringtab Line | Count | Source | 1829 | 1 | { | 1830 | 1 | bfd_byte buffer[BYTES_IN_WORD]; | 1831 | 1 | size_t amt = BYTES_IN_WORD; | 1832 | | | 1833 | | /* The string table starts with the size. */ | 1834 | 1 | PUT_WORD (abfd, _bfd_stringtab_size (tab) + BYTES_IN_WORD, buffer); | 1835 | 1 | if (bfd_write (buffer, amt, abfd) != amt) | 1836 | 0 | return false; | 1837 | | | 1838 | 1 | return _bfd_stringtab_emit (abfd, tab); | 1839 | 1 | } |
Line | Count | Source | 1829 | 2 | { | 1830 | 2 | bfd_byte buffer[BYTES_IN_WORD]; | 1831 | 2 | size_t amt = BYTES_IN_WORD; | 1832 | | | 1833 | | /* The string table starts with the size. */ | 1834 | 2 | PUT_WORD (abfd, _bfd_stringtab_size (tab) + BYTES_IN_WORD, buffer); | 1835 | 2 | if (bfd_write (buffer, amt, abfd) != amt) | 1836 | 0 | return false; | 1837 | | | 1838 | 2 | return _bfd_stringtab_emit (abfd, tab); | 1839 | 2 | } |
|
1840 | | |
1841 | | bool |
1842 | | NAME (aout, write_syms) (bfd *abfd) |
1843 | 3 | { |
1844 | 3 | unsigned int count ; |
1845 | 3 | asymbol **generic = bfd_get_outsymbols (abfd); |
1846 | 3 | struct bfd_strtab_hash *strtab; |
1847 | | |
1848 | 3 | strtab = _bfd_stringtab_init (); |
1849 | 3 | if (strtab == NULL) |
1850 | 0 | return false; |
1851 | | |
1852 | 9.62k | for (count = 0; count < bfd_get_symcount (abfd); count++) |
1853 | 9.61k | { |
1854 | 9.61k | asymbol *g = generic[count]; |
1855 | 9.61k | bfd_size_type indx; |
1856 | 9.61k | struct external_nlist nsp; |
1857 | 9.61k | size_t amt; |
1858 | | |
1859 | 9.61k | indx = add_to_stringtab (abfd, strtab, g->name, false); |
1860 | 9.61k | if (indx == (bfd_size_type) -1) |
1861 | 0 | goto error_return; |
1862 | 9.61k | PUT_WORD (abfd, indx, (bfd_byte *) nsp.e_strx); |
1863 | | |
1864 | 9.61k | if (bfd_asymbol_flavour (g) == abfd->xvec->flavour) |
1865 | 9.61k | { |
1866 | 9.61k | H_PUT_16 (abfd, aout_symbol (g)->desc, nsp.e_desc); |
1867 | 9.61k | H_PUT_8 (abfd, aout_symbol (g)->other, nsp.e_other); |
1868 | 9.61k | H_PUT_8 (abfd, aout_symbol (g)->type, nsp.e_type); |
1869 | 9.61k | } |
1870 | 0 | else |
1871 | 0 | { |
1872 | 0 | H_PUT_16 (abfd, 0, nsp.e_desc); |
1873 | 0 | H_PUT_8 (abfd, 0, nsp.e_other); |
1874 | 0 | H_PUT_8 (abfd, 0, nsp.e_type); |
1875 | 0 | } |
1876 | | |
1877 | 9.61k | if (! translate_to_native_sym_flags (abfd, g, &nsp)) |
1878 | 0 | goto error_return; |
1879 | | |
1880 | 9.61k | amt = EXTERNAL_NLIST_SIZE; |
1881 | 9.61k | if (bfd_write (&nsp, amt, abfd) != amt) |
1882 | 0 | goto error_return; |
1883 | | |
1884 | | /* NB: `KEEPIT' currently overlays `udata.p', so set this only |
1885 | | here, at the end. */ |
1886 | 9.61k | g->KEEPIT = count; |
1887 | 9.61k | } |
1888 | | |
1889 | 3 | if (! emit_stringtab (abfd, strtab)) |
1890 | 0 | goto error_return; |
1891 | | |
1892 | 3 | _bfd_stringtab_free (strtab); |
1893 | | |
1894 | 3 | return true; |
1895 | | |
1896 | 0 | error_return: |
1897 | 0 | _bfd_stringtab_free (strtab); |
1898 | 0 | return false; |
1899 | 3 | } Unexecuted instantiation: cris_aout_32_write_syms Line | Count | Source | 1843 | 1 | { | 1844 | 1 | unsigned int count ; | 1845 | 1 | asymbol **generic = bfd_get_outsymbols (abfd); | 1846 | 1 | struct bfd_strtab_hash *strtab; | 1847 | | | 1848 | 1 | strtab = _bfd_stringtab_init (); | 1849 | 1 | if (strtab == NULL) | 1850 | 0 | return false; | 1851 | | | 1852 | 22 | for (count = 0; count < bfd_get_symcount (abfd); count++) | 1853 | 21 | { | 1854 | 21 | asymbol *g = generic[count]; | 1855 | 21 | bfd_size_type indx; | 1856 | 21 | struct external_nlist nsp; | 1857 | 21 | size_t amt; | 1858 | | | 1859 | 21 | indx = add_to_stringtab (abfd, strtab, g->name, false); | 1860 | 21 | if (indx == (bfd_size_type) -1) | 1861 | 0 | goto error_return; | 1862 | 21 | PUT_WORD (abfd, indx, (bfd_byte *) nsp.e_strx); | 1863 | | | 1864 | 21 | if (bfd_asymbol_flavour (g) == abfd->xvec->flavour) | 1865 | 21 | { | 1866 | 21 | H_PUT_16 (abfd, aout_symbol (g)->desc, nsp.e_desc); | 1867 | 21 | H_PUT_8 (abfd, aout_symbol (g)->other, nsp.e_other); | 1868 | 21 | H_PUT_8 (abfd, aout_symbol (g)->type, nsp.e_type); | 1869 | 21 | } | 1870 | 0 | else | 1871 | 0 | { | 1872 | 0 | H_PUT_16 (abfd, 0, nsp.e_desc); | 1873 | 0 | H_PUT_8 (abfd, 0, nsp.e_other); | 1874 | 0 | H_PUT_8 (abfd, 0, nsp.e_type); | 1875 | 0 | } | 1876 | | | 1877 | 21 | if (! translate_to_native_sym_flags (abfd, g, &nsp)) | 1878 | 0 | goto error_return; | 1879 | | | 1880 | 21 | amt = EXTERNAL_NLIST_SIZE; | 1881 | 21 | if (bfd_write (&nsp, amt, abfd) != amt) | 1882 | 0 | goto error_return; | 1883 | | | 1884 | | /* NB: `KEEPIT' currently overlays `udata.p', so set this only | 1885 | | here, at the end. */ | 1886 | 21 | g->KEEPIT = count; | 1887 | 21 | } | 1888 | | | 1889 | 1 | if (! emit_stringtab (abfd, strtab)) | 1890 | 0 | goto error_return; | 1891 | | | 1892 | 1 | _bfd_stringtab_free (strtab); | 1893 | | | 1894 | 1 | return true; | 1895 | | | 1896 | 0 | error_return: | 1897 | 0 | _bfd_stringtab_free (strtab); | 1898 | 0 | return false; | 1899 | 1 | } |
Line | Count | Source | 1843 | 2 | { | 1844 | 2 | unsigned int count ; | 1845 | 2 | asymbol **generic = bfd_get_outsymbols (abfd); | 1846 | 2 | struct bfd_strtab_hash *strtab; | 1847 | | | 1848 | 2 | strtab = _bfd_stringtab_init (); | 1849 | 2 | if (strtab == NULL) | 1850 | 0 | return false; | 1851 | | | 1852 | 9.60k | for (count = 0; count < bfd_get_symcount (abfd); count++) | 1853 | 9.59k | { | 1854 | 9.59k | asymbol *g = generic[count]; | 1855 | 9.59k | bfd_size_type indx; | 1856 | 9.59k | struct external_nlist nsp; | 1857 | 9.59k | size_t amt; | 1858 | | | 1859 | 9.59k | indx = add_to_stringtab (abfd, strtab, g->name, false); | 1860 | 9.59k | if (indx == (bfd_size_type) -1) | 1861 | 0 | goto error_return; | 1862 | 9.59k | PUT_WORD (abfd, indx, (bfd_byte *) nsp.e_strx); | 1863 | | | 1864 | 9.59k | if (bfd_asymbol_flavour (g) == abfd->xvec->flavour) | 1865 | 9.59k | { | 1866 | 9.59k | H_PUT_16 (abfd, aout_symbol (g)->desc, nsp.e_desc); | 1867 | 9.59k | H_PUT_8 (abfd, aout_symbol (g)->other, nsp.e_other); | 1868 | 9.59k | H_PUT_8 (abfd, aout_symbol (g)->type, nsp.e_type); | 1869 | 9.59k | } | 1870 | 0 | else | 1871 | 0 | { | 1872 | 0 | H_PUT_16 (abfd, 0, nsp.e_desc); | 1873 | 0 | H_PUT_8 (abfd, 0, nsp.e_other); | 1874 | 0 | H_PUT_8 (abfd, 0, nsp.e_type); | 1875 | 0 | } | 1876 | | | 1877 | 9.59k | if (! translate_to_native_sym_flags (abfd, g, &nsp)) | 1878 | 0 | goto error_return; | 1879 | | | 1880 | 9.59k | amt = EXTERNAL_NLIST_SIZE; | 1881 | 9.59k | if (bfd_write (&nsp, amt, abfd) != amt) | 1882 | 0 | goto error_return; | 1883 | | | 1884 | | /* NB: `KEEPIT' currently overlays `udata.p', so set this only | 1885 | | here, at the end. */ | 1886 | 9.59k | g->KEEPIT = count; | 1887 | 9.59k | } | 1888 | | | 1889 | 2 | if (! emit_stringtab (abfd, strtab)) | 1890 | 0 | goto error_return; | 1891 | | | 1892 | 2 | _bfd_stringtab_free (strtab); | 1893 | | | 1894 | 2 | return true; | 1895 | | | 1896 | 0 | error_return: | 1897 | 0 | _bfd_stringtab_free (strtab); | 1898 | 0 | return false; | 1899 | 2 | } |
|
1900 | | |
1901 | | long |
1902 | | NAME (aout, canonicalize_symtab) (bfd *abfd, asymbol **location) |
1903 | 1.05k | { |
1904 | 1.05k | unsigned int counter = 0; |
1905 | 1.05k | aout_symbol_type *symbase; |
1906 | | |
1907 | 1.05k | if (!NAME (aout, slurp_symbol_table) (abfd)) |
1908 | 0 | return -1; |
1909 | | |
1910 | 1.05k | for (symbase = obj_aout_symbols (abfd); |
1911 | 25.0k | counter++ < bfd_get_symcount (abfd); |
1912 | 1.05k | ) |
1913 | 24.0k | *(location++) = (asymbol *) (symbase++); |
1914 | 1.05k | *location++ =0; |
1915 | 1.05k | return bfd_get_symcount (abfd); |
1916 | 1.05k | } Unexecuted instantiation: cris_aout_32_canonicalize_symtab ns32kaout_32_canonicalize_symtab Line | Count | Source | 1903 | 649 | { | 1904 | 649 | unsigned int counter = 0; | 1905 | 649 | aout_symbol_type *symbase; | 1906 | | | 1907 | 649 | if (!NAME (aout, slurp_symbol_table) (abfd)) | 1908 | 0 | return -1; | 1909 | | | 1910 | 649 | for (symbase = obj_aout_symbols (abfd); | 1911 | 5.78k | counter++ < bfd_get_symcount (abfd); | 1912 | 649 | ) | 1913 | 5.13k | *(location++) = (asymbol *) (symbase++); | 1914 | 649 | *location++ =0; | 1915 | 649 | return bfd_get_symcount (abfd); | 1916 | 649 | } |
aout_32_canonicalize_symtab Line | Count | Source | 1903 | 408 | { | 1904 | 408 | unsigned int counter = 0; | 1905 | 408 | aout_symbol_type *symbase; | 1906 | | | 1907 | 408 | if (!NAME (aout, slurp_symbol_table) (abfd)) | 1908 | 0 | return -1; | 1909 | | | 1910 | 408 | for (symbase = obj_aout_symbols (abfd); | 1911 | 19.3k | counter++ < bfd_get_symcount (abfd); | 1912 | 408 | ) | 1913 | 18.9k | *(location++) = (asymbol *) (symbase++); | 1914 | 408 | *location++ =0; | 1915 | 408 | return bfd_get_symcount (abfd); | 1916 | 408 | } |
|
1917 | | |
1918 | | /* Standard reloc stuff. */ |
1919 | | /* Output standard relocation information to a file in target byte order. */ |
1920 | | |
1921 | | extern void NAME (aout, swap_std_reloc_out) |
1922 | | (bfd *, arelent *, struct reloc_std_external *); |
1923 | | |
1924 | | void |
1925 | | NAME (aout, swap_std_reloc_out) (bfd *abfd, |
1926 | | arelent *g, |
1927 | | struct reloc_std_external *natptr) |
1928 | 28 | { |
1929 | 28 | int r_index; |
1930 | 28 | asymbol *sym = *(g->sym_ptr_ptr); |
1931 | 28 | int r_extern; |
1932 | 28 | unsigned int r_length, r_size; |
1933 | 28 | int r_pcrel; |
1934 | 28 | int r_baserel, r_jmptable, r_relative; |
1935 | 28 | asection *output_section = sym->section->output_section; |
1936 | | |
1937 | 28 | PUT_WORD (abfd, g->address, natptr->r_address); |
1938 | | |
1939 | 28 | BFD_ASSERT (g->howto != NULL); |
1940 | | |
1941 | 28 | r_size = bfd_get_reloc_size (g->howto); |
1942 | 28 | r_length = bfd_log2 (r_size); |
1943 | 28 | if (1u << r_length != r_size) |
1944 | 0 | { |
1945 | 0 | _bfd_error_handler (_("%pB: unsupported AOUT relocation size: %d"), |
1946 | 0 | abfd, r_size); |
1947 | 0 | bfd_set_error (bfd_error_bad_value); |
1948 | 0 | return; |
1949 | 0 | } |
1950 | | |
1951 | 28 | r_pcrel = (int) g->howto->pc_relative; /* Relative to PC? */ |
1952 | | /* XXX This relies on relocs coming from a.out files. */ |
1953 | 28 | r_baserel = (g->howto->type & 8) != 0; |
1954 | 28 | r_jmptable = (g->howto->type & 16) != 0; |
1955 | 28 | r_relative = (g->howto->type & 32) != 0; |
1956 | | |
1957 | | /* Name was clobbered by aout_write_syms to be symbol index. */ |
1958 | | |
1959 | | /* If this relocation is relative to a symbol then set the |
1960 | | r_index to the symbols index, and the r_extern bit. |
1961 | | |
1962 | | Absolute symbols can come in in two ways, either as an offset |
1963 | | from the abs section, or as a symbol which has an abs value. |
1964 | | check for that here. */ |
1965 | | |
1966 | 28 | if (bfd_is_com_section (output_section) |
1967 | 28 | || bfd_is_abs_section (output_section) |
1968 | 28 | || bfd_is_und_section (output_section) |
1969 | | /* PR gas/3041 a.out relocs against weak symbols |
1970 | | must be treated as if they were against externs. */ |
1971 | 28 | || (sym->flags & BSF_WEAK)) |
1972 | 28 | { |
1973 | 28 | if (bfd_abs_section_ptr->symbol == sym) |
1974 | 28 | { |
1975 | | /* Whoops, looked like an abs symbol, but is |
1976 | | really an offset from the abs section. */ |
1977 | 28 | r_index = N_ABS; |
1978 | 28 | r_extern = 0; |
1979 | 28 | } |
1980 | 0 | else |
1981 | 0 | { |
1982 | | /* Fill in symbol. */ |
1983 | 0 | r_extern = 1; |
1984 | 0 | r_index = (*(g->sym_ptr_ptr))->KEEPIT; |
1985 | 0 | } |
1986 | 28 | } |
1987 | 0 | else |
1988 | 0 | { |
1989 | | /* Just an ordinary section. */ |
1990 | 0 | r_extern = 0; |
1991 | 0 | r_index = output_section->target_index; |
1992 | 0 | } |
1993 | | |
1994 | | /* Now the fun stuff. */ |
1995 | 28 | if (bfd_header_big_endian (abfd)) |
1996 | 0 | { |
1997 | 0 | natptr->r_index[0] = r_index >> 16; |
1998 | 0 | natptr->r_index[1] = r_index >> 8; |
1999 | 0 | natptr->r_index[2] = r_index; |
2000 | 0 | natptr->r_type[0] = ((r_extern ? RELOC_STD_BITS_EXTERN_BIG : 0) |
2001 | 0 | | (r_pcrel ? RELOC_STD_BITS_PCREL_BIG : 0) |
2002 | 0 | | (r_baserel ? RELOC_STD_BITS_BASEREL_BIG : 0) |
2003 | 0 | | (r_jmptable ? RELOC_STD_BITS_JMPTABLE_BIG : 0) |
2004 | 0 | | (r_relative ? RELOC_STD_BITS_RELATIVE_BIG : 0) |
2005 | 0 | | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG)); |
2006 | 0 | } |
2007 | 28 | else |
2008 | 28 | { |
2009 | 28 | natptr->r_index[2] = r_index >> 16; |
2010 | 28 | natptr->r_index[1] = r_index >> 8; |
2011 | 28 | natptr->r_index[0] = r_index; |
2012 | 28 | natptr->r_type[0] = ((r_extern ? RELOC_STD_BITS_EXTERN_LITTLE : 0) |
2013 | 28 | | (r_pcrel ? RELOC_STD_BITS_PCREL_LITTLE : 0) |
2014 | 28 | | (r_baserel ? RELOC_STD_BITS_BASEREL_LITTLE : 0) |
2015 | 28 | | (r_jmptable ? RELOC_STD_BITS_JMPTABLE_LITTLE : 0) |
2016 | 28 | | (r_relative ? RELOC_STD_BITS_RELATIVE_LITTLE : 0) |
2017 | 28 | | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE)); |
2018 | 28 | } |
2019 | 28 | } Unexecuted instantiation: cris_aout_32_swap_std_reloc_out Unexecuted instantiation: ns32kaout_32_swap_std_reloc_out aout_32_swap_std_reloc_out Line | Count | Source | 1928 | 28 | { | 1929 | 28 | int r_index; | 1930 | 28 | asymbol *sym = *(g->sym_ptr_ptr); | 1931 | 28 | int r_extern; | 1932 | 28 | unsigned int r_length, r_size; | 1933 | 28 | int r_pcrel; | 1934 | 28 | int r_baserel, r_jmptable, r_relative; | 1935 | 28 | asection *output_section = sym->section->output_section; | 1936 | | | 1937 | 28 | PUT_WORD (abfd, g->address, natptr->r_address); | 1938 | | | 1939 | 28 | BFD_ASSERT (g->howto != NULL); | 1940 | | | 1941 | 28 | r_size = bfd_get_reloc_size (g->howto); | 1942 | 28 | r_length = bfd_log2 (r_size); | 1943 | 28 | if (1u << r_length != r_size) | 1944 | 0 | { | 1945 | 0 | _bfd_error_handler (_("%pB: unsupported AOUT relocation size: %d"), | 1946 | 0 | abfd, r_size); | 1947 | 0 | bfd_set_error (bfd_error_bad_value); | 1948 | 0 | return; | 1949 | 0 | } | 1950 | | | 1951 | 28 | r_pcrel = (int) g->howto->pc_relative; /* Relative to PC? */ | 1952 | | /* XXX This relies on relocs coming from a.out files. */ | 1953 | 28 | r_baserel = (g->howto->type & 8) != 0; | 1954 | 28 | r_jmptable = (g->howto->type & 16) != 0; | 1955 | 28 | r_relative = (g->howto->type & 32) != 0; | 1956 | | | 1957 | | /* Name was clobbered by aout_write_syms to be symbol index. */ | 1958 | | | 1959 | | /* If this relocation is relative to a symbol then set the | 1960 | | r_index to the symbols index, and the r_extern bit. | 1961 | | | 1962 | | Absolute symbols can come in in two ways, either as an offset | 1963 | | from the abs section, or as a symbol which has an abs value. | 1964 | | check for that here. */ | 1965 | | | 1966 | 28 | if (bfd_is_com_section (output_section) | 1967 | 28 | || bfd_is_abs_section (output_section) | 1968 | 28 | || bfd_is_und_section (output_section) | 1969 | | /* PR gas/3041 a.out relocs against weak symbols | 1970 | | must be treated as if they were against externs. */ | 1971 | 28 | || (sym->flags & BSF_WEAK)) | 1972 | 28 | { | 1973 | 28 | if (bfd_abs_section_ptr->symbol == sym) | 1974 | 28 | { | 1975 | | /* Whoops, looked like an abs symbol, but is | 1976 | | really an offset from the abs section. */ | 1977 | 28 | r_index = N_ABS; | 1978 | 28 | r_extern = 0; | 1979 | 28 | } | 1980 | 0 | else | 1981 | 0 | { | 1982 | | /* Fill in symbol. */ | 1983 | 0 | r_extern = 1; | 1984 | 0 | r_index = (*(g->sym_ptr_ptr))->KEEPIT; | 1985 | 0 | } | 1986 | 28 | } | 1987 | 0 | else | 1988 | 0 | { | 1989 | | /* Just an ordinary section. */ | 1990 | 0 | r_extern = 0; | 1991 | 0 | r_index = output_section->target_index; | 1992 | 0 | } | 1993 | | | 1994 | | /* Now the fun stuff. */ | 1995 | 28 | if (bfd_header_big_endian (abfd)) | 1996 | 0 | { | 1997 | 0 | natptr->r_index[0] = r_index >> 16; | 1998 | 0 | natptr->r_index[1] = r_index >> 8; | 1999 | 0 | natptr->r_index[2] = r_index; | 2000 | 0 | natptr->r_type[0] = ((r_extern ? RELOC_STD_BITS_EXTERN_BIG : 0) | 2001 | 0 | | (r_pcrel ? RELOC_STD_BITS_PCREL_BIG : 0) | 2002 | 0 | | (r_baserel ? RELOC_STD_BITS_BASEREL_BIG : 0) | 2003 | 0 | | (r_jmptable ? RELOC_STD_BITS_JMPTABLE_BIG : 0) | 2004 | 0 | | (r_relative ? RELOC_STD_BITS_RELATIVE_BIG : 0) | 2005 | 0 | | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG)); | 2006 | 0 | } | 2007 | 28 | else | 2008 | 28 | { | 2009 | 28 | natptr->r_index[2] = r_index >> 16; | 2010 | 28 | natptr->r_index[1] = r_index >> 8; | 2011 | 28 | natptr->r_index[0] = r_index; | 2012 | 28 | natptr->r_type[0] = ((r_extern ? RELOC_STD_BITS_EXTERN_LITTLE : 0) | 2013 | 28 | | (r_pcrel ? RELOC_STD_BITS_PCREL_LITTLE : 0) | 2014 | 28 | | (r_baserel ? RELOC_STD_BITS_BASEREL_LITTLE : 0) | 2015 | 28 | | (r_jmptable ? RELOC_STD_BITS_JMPTABLE_LITTLE : 0) | 2016 | 28 | | (r_relative ? RELOC_STD_BITS_RELATIVE_LITTLE : 0) | 2017 | 28 | | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE)); | 2018 | 28 | } | 2019 | 28 | } |
|
2020 | | |
2021 | | /* Extended stuff. */ |
2022 | | /* Output extended relocation information to a file in target byte order. */ |
2023 | | |
2024 | | extern void NAME (aout, swap_ext_reloc_out) |
2025 | | (bfd *, arelent *, struct reloc_ext_external *); |
2026 | | |
2027 | | void |
2028 | | NAME (aout, swap_ext_reloc_out) (bfd *abfd, |
2029 | | arelent *g, |
2030 | | struct reloc_ext_external *natptr) |
2031 | 0 | { |
2032 | 0 | int r_index; |
2033 | 0 | int r_extern; |
2034 | 0 | unsigned int r_type; |
2035 | 0 | bfd_vma r_addend; |
2036 | 0 | asymbol *sym = *(g->sym_ptr_ptr); |
2037 | 0 | asection *output_section = sym->section->output_section; |
2038 | |
|
2039 | 0 | PUT_WORD (abfd, g->address, natptr->r_address); |
2040 | |
|
2041 | 0 | r_type = (unsigned int) g->howto->type; |
2042 | |
|
2043 | 0 | r_addend = g->addend; |
2044 | 0 | if ((sym->flags & BSF_SECTION_SYM) != 0) |
2045 | 0 | r_addend += (*(g->sym_ptr_ptr))->section->output_section->vma; |
2046 | | |
2047 | | /* If this relocation is relative to a symbol then set the |
2048 | | r_index to the symbols index, and the r_extern bit. |
2049 | | |
2050 | | Absolute symbols can come in in two ways, either as an offset |
2051 | | from the abs section, or as a symbol which has an abs value. |
2052 | | check for that here. */ |
2053 | 0 | if (bfd_is_abs_section (bfd_asymbol_section (sym))) |
2054 | 0 | { |
2055 | 0 | r_extern = 0; |
2056 | 0 | r_index = N_ABS; |
2057 | 0 | } |
2058 | 0 | else if ((sym->flags & BSF_SECTION_SYM) == 0) |
2059 | 0 | { |
2060 | 0 | if (bfd_is_und_section (bfd_asymbol_section (sym)) |
2061 | 0 | || (sym->flags & BSF_GLOBAL) != 0) |
2062 | 0 | r_extern = 1; |
2063 | 0 | else |
2064 | 0 | r_extern = 0; |
2065 | 0 | r_index = (*(g->sym_ptr_ptr))->KEEPIT; |
2066 | 0 | } |
2067 | 0 | else |
2068 | 0 | { |
2069 | | /* Just an ordinary section. */ |
2070 | 0 | r_extern = 0; |
2071 | 0 | r_index = output_section->target_index; |
2072 | 0 | } |
2073 | | |
2074 | | /* Now the fun stuff. */ |
2075 | 0 | if (bfd_header_big_endian (abfd)) |
2076 | 0 | { |
2077 | 0 | natptr->r_index[0] = r_index >> 16; |
2078 | 0 | natptr->r_index[1] = r_index >> 8; |
2079 | 0 | natptr->r_index[2] = r_index; |
2080 | 0 | natptr->r_type[0] = ((r_extern ? RELOC_EXT_BITS_EXTERN_BIG : 0) |
2081 | 0 | | (r_type << RELOC_EXT_BITS_TYPE_SH_BIG)); |
2082 | 0 | } |
2083 | 0 | else |
2084 | 0 | { |
2085 | 0 | natptr->r_index[2] = r_index >> 16; |
2086 | 0 | natptr->r_index[1] = r_index >> 8; |
2087 | 0 | natptr->r_index[0] = r_index; |
2088 | 0 | natptr->r_type[0] = ((r_extern ? RELOC_EXT_BITS_EXTERN_LITTLE : 0) |
2089 | 0 | | (r_type << RELOC_EXT_BITS_TYPE_SH_LITTLE)); |
2090 | 0 | } |
2091 | |
|
2092 | 0 | PUT_WORD (abfd, r_addend, natptr->r_addend); |
2093 | 0 | } Unexecuted instantiation: cris_aout_32_swap_ext_reloc_out Unexecuted instantiation: ns32kaout_32_swap_ext_reloc_out Unexecuted instantiation: aout_32_swap_ext_reloc_out |
2094 | | |
2095 | | /* BFD deals internally with all things based from the section they're |
2096 | | in. so, something in 10 bytes into a text section with a base of |
2097 | | 50 would have a symbol (.text+10) and know .text vma was 50. |
2098 | | |
2099 | | Aout keeps all it's symbols based from zero, so the symbol would |
2100 | | contain 60. This macro subs the base of each section from the value |
2101 | | to give the true offset from the section. */ |
2102 | | |
2103 | | #define MOVE_ADDRESS(ad) \ |
2104 | 13.9k | if (r_extern) \ |
2105 | 13.9k | { \ |
2106 | 3.75k | /* Undefined symbol. */ \ |
2107 | 3.75k | if (symbols != NULL && r_index < bfd_get_symcount (abfd)) \ |
2108 | 3.75k | cache_ptr->sym_ptr_ptr = symbols + r_index; \ |
2109 | 3.75k | else \ |
2110 | 3.75k | cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol; \ |
2111 | 3.75k | cache_ptr->addend = ad; \ |
2112 | 3.75k | } \ |
2113 | 13.9k | else \ |
2114 | 13.9k | { \ |
2115 | 10.1k | /* Defined, section relative. Replace symbol with pointer to \ |
2116 | 10.1k | symbol which points to section. */ \ |
2117 | 10.1k | switch (r_index) \ |
2118 | 10.1k | { \ |
2119 | 22 | case N_TEXT: \ |
2120 | 67 | case N_TEXT | N_EXT: \ |
2121 | 67 | cache_ptr->sym_ptr_ptr = &obj_textsec (abfd)->symbol; \ |
2122 | 67 | cache_ptr->addend = ad - su->textsec->vma; \ |
2123 | 67 | break; \ |
2124 | 22 | case N_DATA: \ |
2125 | 25 | case N_DATA | N_EXT: \ |
2126 | 25 | cache_ptr->sym_ptr_ptr = &obj_datasec (abfd)->symbol; \ |
2127 | 25 | cache_ptr->addend = ad - su->datasec->vma; \ |
2128 | 25 | break; \ |
2129 | 22 | case N_BSS: \ |
2130 | 37 | case N_BSS | N_EXT: \ |
2131 | 37 | cache_ptr->sym_ptr_ptr = &obj_bsssec (abfd)->symbol; \ |
2132 | 37 | cache_ptr->addend = ad - su->bsssec->vma; \ |
2133 | 37 | break; \ |
2134 | 9.04k | default: \ |
2135 | 10.0k | case N_ABS: \ |
2136 | 10.0k | case N_ABS | N_EXT: \ |
2137 | 10.0k | cache_ptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol; \ |
2138 | 10.0k | cache_ptr->addend = ad; \ |
2139 | 10.0k | break; \ |
2140 | 10.1k | } \ |
2141 | 10.1k | } |
2142 | | |
2143 | | void |
2144 | | NAME (aout, swap_ext_reloc_in) (bfd *abfd, |
2145 | | struct reloc_ext_external *bytes, |
2146 | | arelent *cache_ptr, |
2147 | | asymbol **symbols, |
2148 | | bfd_size_type symcount) |
2149 | 0 | { |
2150 | 0 | unsigned int r_index; |
2151 | 0 | int r_extern; |
2152 | 0 | unsigned int r_type; |
2153 | 0 | struct aoutdata *su = &(abfd->tdata.aout_data->a); |
2154 | |
|
2155 | 0 | cache_ptr->address = (GET_SWORD (abfd, bytes->r_address)); |
2156 | | |
2157 | | /* Now the fun stuff. */ |
2158 | 0 | if (bfd_header_big_endian (abfd)) |
2159 | 0 | { |
2160 | 0 | r_index = (((unsigned int) bytes->r_index[0] << 16) |
2161 | 0 | | ((unsigned int) bytes->r_index[1] << 8) |
2162 | 0 | | bytes->r_index[2]); |
2163 | 0 | r_extern = (0 != (bytes->r_type[0] & RELOC_EXT_BITS_EXTERN_BIG)); |
2164 | 0 | r_type = ((bytes->r_type[0] & RELOC_EXT_BITS_TYPE_BIG) |
2165 | 0 | >> RELOC_EXT_BITS_TYPE_SH_BIG); |
2166 | 0 | } |
2167 | 0 | else |
2168 | 0 | { |
2169 | 0 | r_index = (((unsigned int) bytes->r_index[2] << 16) |
2170 | 0 | | ((unsigned int) bytes->r_index[1] << 8) |
2171 | 0 | | bytes->r_index[0]); |
2172 | 0 | r_extern = (0 != (bytes->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE)); |
2173 | 0 | r_type = ((bytes->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE) |
2174 | 0 | >> RELOC_EXT_BITS_TYPE_SH_LITTLE); |
2175 | 0 | } |
2176 | |
|
2177 | 0 | if (r_type < TABLE_SIZE (howto_table_ext)) |
2178 | 0 | cache_ptr->howto = howto_table_ext + r_type; |
2179 | 0 | else |
2180 | 0 | cache_ptr->howto = NULL; |
2181 | | |
2182 | | /* Base relative relocs are always against the symbol table, |
2183 | | regardless of the setting of r_extern. r_extern just reflects |
2184 | | whether the symbol the reloc is against is local or global. */ |
2185 | 0 | if (r_type == (unsigned int) RELOC_BASE10 |
2186 | 0 | || r_type == (unsigned int) RELOC_BASE13 |
2187 | 0 | || r_type == (unsigned int) RELOC_BASE22) |
2188 | 0 | r_extern = 1; |
2189 | |
|
2190 | 0 | if (r_extern && r_index > symcount) |
2191 | 0 | { |
2192 | | /* We could arrange to return an error, but it might be useful |
2193 | | to see the file even if it is bad. */ |
2194 | 0 | r_extern = 0; |
2195 | 0 | r_index = N_ABS; |
2196 | 0 | } |
2197 | |
|
2198 | 0 | MOVE_ADDRESS (GET_SWORD (abfd, bytes->r_addend)); |
2199 | 0 | } Unexecuted instantiation: cris_aout_32_swap_ext_reloc_in Unexecuted instantiation: ns32kaout_32_swap_ext_reloc_in Unexecuted instantiation: aout_32_swap_ext_reloc_in |
2200 | | |
2201 | | void |
2202 | | NAME (aout, swap_std_reloc_in) (bfd *abfd, |
2203 | | struct reloc_std_external *bytes, |
2204 | | arelent *cache_ptr, |
2205 | | asymbol **symbols, |
2206 | | bfd_size_type symcount) |
2207 | 3.04k | { |
2208 | 3.04k | unsigned int r_index; |
2209 | 3.04k | int r_extern; |
2210 | 3.04k | unsigned int r_length; |
2211 | 3.04k | int r_pcrel; |
2212 | 3.04k | int r_baserel, r_jmptable, r_relative; |
2213 | 3.04k | struct aoutdata *su = &(abfd->tdata.aout_data->a); |
2214 | 3.04k | unsigned int howto_idx; |
2215 | | |
2216 | 3.04k | cache_ptr->address = H_GET_32 (abfd, bytes->r_address); |
2217 | | |
2218 | | /* Now the fun stuff. */ |
2219 | 3.04k | if (bfd_header_big_endian (abfd)) |
2220 | 0 | { |
2221 | 0 | r_index = (((unsigned int) bytes->r_index[0] << 16) |
2222 | 0 | | ((unsigned int) bytes->r_index[1] << 8) |
2223 | 0 | | bytes->r_index[2]); |
2224 | 0 | r_extern = (0 != (bytes->r_type[0] & RELOC_STD_BITS_EXTERN_BIG)); |
2225 | 0 | r_pcrel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_PCREL_BIG)); |
2226 | 0 | r_baserel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_BASEREL_BIG)); |
2227 | 0 | r_jmptable= (0 != (bytes->r_type[0] & RELOC_STD_BITS_JMPTABLE_BIG)); |
2228 | 0 | r_relative= (0 != (bytes->r_type[0] & RELOC_STD_BITS_RELATIVE_BIG)); |
2229 | 0 | r_length = ((bytes->r_type[0] & RELOC_STD_BITS_LENGTH_BIG) |
2230 | 0 | >> RELOC_STD_BITS_LENGTH_SH_BIG); |
2231 | 0 | } |
2232 | 3.04k | else |
2233 | 3.04k | { |
2234 | 3.04k | r_index = (((unsigned int) bytes->r_index[2] << 16) |
2235 | 3.04k | | ((unsigned int) bytes->r_index[1] << 8) |
2236 | 3.04k | | bytes->r_index[0]); |
2237 | 3.04k | r_extern = (0 != (bytes->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE)); |
2238 | 3.04k | r_pcrel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE)); |
2239 | 3.04k | r_baserel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_BASEREL_LITTLE)); |
2240 | 3.04k | r_jmptable= (0 != (bytes->r_type[0] & RELOC_STD_BITS_JMPTABLE_LITTLE)); |
2241 | 3.04k | r_relative= (0 != (bytes->r_type[0] & RELOC_STD_BITS_RELATIVE_LITTLE)); |
2242 | 3.04k | r_length = ((bytes->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE) |
2243 | 3.04k | >> RELOC_STD_BITS_LENGTH_SH_LITTLE); |
2244 | 3.04k | } |
2245 | | |
2246 | 3.04k | howto_idx = (r_length + 4 * r_pcrel + 8 * r_baserel |
2247 | 3.04k | + 16 * r_jmptable + 32 * r_relative); |
2248 | 3.04k | if (howto_idx < TABLE_SIZE (howto_table_std)) |
2249 | 2.33k | { |
2250 | 2.33k | cache_ptr->howto = howto_table_std + howto_idx; |
2251 | 2.33k | if (cache_ptr->howto->type == (unsigned int) -1) |
2252 | 795 | cache_ptr->howto = NULL; |
2253 | 2.33k | } |
2254 | 706 | else |
2255 | 706 | cache_ptr->howto = NULL; |
2256 | | |
2257 | | /* Base relative relocs are always against the symbol table, |
2258 | | regardless of the setting of r_extern. r_extern just reflects |
2259 | | whether the symbol the reloc is against is local or global. */ |
2260 | 3.04k | if (r_baserel) |
2261 | 1.05k | r_extern = 1; |
2262 | | |
2263 | 3.04k | if (r_extern && r_index >= symcount) |
2264 | 915 | { |
2265 | | /* We could arrange to return an error, but it might be useful |
2266 | | to see the file even if it is bad. FIXME: Of course this |
2267 | | means that objdump -r *doesn't* see the actual reloc, and |
2268 | | objcopy silently writes a different reloc. */ |
2269 | 915 | r_extern = 0; |
2270 | 915 | r_index = N_ABS; |
2271 | 915 | } |
2272 | | |
2273 | 3.04k | MOVE_ADDRESS (0); |
2274 | 3.04k | } Unexecuted instantiation: cris_aout_32_swap_std_reloc_in Unexecuted instantiation: ns32kaout_32_swap_std_reloc_in aout_32_swap_std_reloc_in Line | Count | Source | 2207 | 3.04k | { | 2208 | 3.04k | unsigned int r_index; | 2209 | 3.04k | int r_extern; | 2210 | 3.04k | unsigned int r_length; | 2211 | 3.04k | int r_pcrel; | 2212 | 3.04k | int r_baserel, r_jmptable, r_relative; | 2213 | 3.04k | struct aoutdata *su = &(abfd->tdata.aout_data->a); | 2214 | 3.04k | unsigned int howto_idx; | 2215 | | | 2216 | 3.04k | cache_ptr->address = H_GET_32 (abfd, bytes->r_address); | 2217 | | | 2218 | | /* Now the fun stuff. */ | 2219 | 3.04k | if (bfd_header_big_endian (abfd)) | 2220 | 0 | { | 2221 | 0 | r_index = (((unsigned int) bytes->r_index[0] << 16) | 2222 | 0 | | ((unsigned int) bytes->r_index[1] << 8) | 2223 | 0 | | bytes->r_index[2]); | 2224 | 0 | r_extern = (0 != (bytes->r_type[0] & RELOC_STD_BITS_EXTERN_BIG)); | 2225 | 0 | r_pcrel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_PCREL_BIG)); | 2226 | 0 | r_baserel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_BASEREL_BIG)); | 2227 | 0 | r_jmptable= (0 != (bytes->r_type[0] & RELOC_STD_BITS_JMPTABLE_BIG)); | 2228 | 0 | r_relative= (0 != (bytes->r_type[0] & RELOC_STD_BITS_RELATIVE_BIG)); | 2229 | 0 | r_length = ((bytes->r_type[0] & RELOC_STD_BITS_LENGTH_BIG) | 2230 | 0 | >> RELOC_STD_BITS_LENGTH_SH_BIG); | 2231 | 0 | } | 2232 | 3.04k | else | 2233 | 3.04k | { | 2234 | 3.04k | r_index = (((unsigned int) bytes->r_index[2] << 16) | 2235 | 3.04k | | ((unsigned int) bytes->r_index[1] << 8) | 2236 | 3.04k | | bytes->r_index[0]); | 2237 | 3.04k | r_extern = (0 != (bytes->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE)); | 2238 | 3.04k | r_pcrel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE)); | 2239 | 3.04k | r_baserel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_BASEREL_LITTLE)); | 2240 | 3.04k | r_jmptable= (0 != (bytes->r_type[0] & RELOC_STD_BITS_JMPTABLE_LITTLE)); | 2241 | 3.04k | r_relative= (0 != (bytes->r_type[0] & RELOC_STD_BITS_RELATIVE_LITTLE)); | 2242 | 3.04k | r_length = ((bytes->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE) | 2243 | 3.04k | >> RELOC_STD_BITS_LENGTH_SH_LITTLE); | 2244 | 3.04k | } | 2245 | | | 2246 | 3.04k | howto_idx = (r_length + 4 * r_pcrel + 8 * r_baserel | 2247 | 3.04k | + 16 * r_jmptable + 32 * r_relative); | 2248 | 3.04k | if (howto_idx < TABLE_SIZE (howto_table_std)) | 2249 | 2.33k | { | 2250 | 2.33k | cache_ptr->howto = howto_table_std + howto_idx; | 2251 | 2.33k | if (cache_ptr->howto->type == (unsigned int) -1) | 2252 | 795 | cache_ptr->howto = NULL; | 2253 | 2.33k | } | 2254 | 706 | else | 2255 | 706 | cache_ptr->howto = NULL; | 2256 | | | 2257 | | /* Base relative relocs are always against the symbol table, | 2258 | | regardless of the setting of r_extern. r_extern just reflects | 2259 | | whether the symbol the reloc is against is local or global. */ | 2260 | 3.04k | if (r_baserel) | 2261 | 1.05k | r_extern = 1; | 2262 | | | 2263 | 3.04k | if (r_extern && r_index >= symcount) | 2264 | 915 | { | 2265 | | /* We could arrange to return an error, but it might be useful | 2266 | | to see the file even if it is bad. FIXME: Of course this | 2267 | | means that objdump -r *doesn't* see the actual reloc, and | 2268 | | objcopy silently writes a different reloc. */ | 2269 | 915 | r_extern = 0; | 2270 | 915 | r_index = N_ABS; | 2271 | 915 | } | 2272 | | | 2273 | 3.04k | MOVE_ADDRESS (0); | 2274 | 3.04k | } |
|
2275 | | |
2276 | | /* Read and swap the relocs for a section. */ |
2277 | | |
2278 | | bool |
2279 | | NAME (aout, slurp_reloc_table) (bfd *abfd, sec_ptr asect, asymbol **symbols) |
2280 | 114 | { |
2281 | 114 | bfd_size_type count; |
2282 | 114 | bfd_size_type reloc_size; |
2283 | 114 | void * relocs; |
2284 | 114 | arelent *reloc_cache; |
2285 | 114 | size_t each_size; |
2286 | 114 | unsigned int counter = 0; |
2287 | 114 | arelent *cache_ptr; |
2288 | 114 | bfd_size_type amt; |
2289 | | |
2290 | 114 | if (asect->relocation) |
2291 | 0 | return true; |
2292 | | |
2293 | 114 | if (asect->flags & SEC_CONSTRUCTOR) |
2294 | 0 | return true; |
2295 | | |
2296 | 114 | if (asect == obj_datasec (abfd)) |
2297 | 9 | reloc_size = exec_hdr (abfd)->a_drsize; |
2298 | 105 | else if (asect == obj_textsec (abfd)) |
2299 | 105 | reloc_size = exec_hdr (abfd)->a_trsize; |
2300 | 0 | else if (asect == obj_bsssec (abfd)) |
2301 | 0 | reloc_size = 0; |
2302 | 0 | else |
2303 | 0 | { |
2304 | 0 | bfd_set_error (bfd_error_invalid_operation); |
2305 | 0 | return false; |
2306 | 0 | } |
2307 | | |
2308 | 114 | each_size = obj_reloc_entry_size (abfd); |
2309 | 114 | count = reloc_size / each_size; |
2310 | 114 | if (count == 0) |
2311 | 2 | return true; /* Nothing to be done. */ |
2312 | | |
2313 | 112 | if (bfd_seek (abfd, asect->rel_filepos, SEEK_SET) != 0) |
2314 | 0 | return false; |
2315 | 112 | relocs = _bfd_malloc_and_read (abfd, reloc_size, reloc_size); |
2316 | 112 | if (relocs == NULL) |
2317 | 6 | return false; |
2318 | | |
2319 | 106 | amt = count * sizeof (arelent); |
2320 | 106 | reloc_cache = (arelent *) bfd_zmalloc (amt); |
2321 | 106 | if (reloc_cache == NULL) |
2322 | 0 | { |
2323 | 0 | free (relocs); |
2324 | 0 | return false; |
2325 | 0 | } |
2326 | | |
2327 | 106 | cache_ptr = reloc_cache; |
2328 | 106 | if (each_size == RELOC_EXT_SIZE) |
2329 | 0 | { |
2330 | 0 | struct reloc_ext_external *rptr = (struct reloc_ext_external *) relocs; |
2331 | |
|
2332 | 0 | for (; counter < count; counter++, rptr++, cache_ptr++) |
2333 | 0 | MY_swap_ext_reloc_in (abfd, rptr, cache_ptr, symbols, |
2334 | 0 | (bfd_size_type) bfd_get_symcount (abfd)); |
2335 | 0 | } |
2336 | 106 | else |
2337 | 106 | { |
2338 | 106 | struct reloc_std_external *rptr = (struct reloc_std_external *) relocs; |
2339 | | |
2340 | 14.0k | for (; counter < count; counter++, rptr++, cache_ptr++) |
2341 | 13.9k | MY_swap_std_reloc_in (abfd, rptr, cache_ptr, symbols, |
2342 | 13.9k | (bfd_size_type) bfd_get_symcount (abfd)); |
2343 | 106 | } |
2344 | | |
2345 | 106 | free (relocs); |
2346 | | |
2347 | 106 | asect->relocation = reloc_cache; |
2348 | 106 | asect->reloc_count = cache_ptr - reloc_cache; |
2349 | | |
2350 | 106 | return true; |
2351 | 106 | } Unexecuted instantiation: cris_aout_32_slurp_reloc_table ns32kaout_32_slurp_reloc_table Line | Count | Source | 2280 | 55 | { | 2281 | 55 | bfd_size_type count; | 2282 | 55 | bfd_size_type reloc_size; | 2283 | 55 | void * relocs; | 2284 | 55 | arelent *reloc_cache; | 2285 | 55 | size_t each_size; | 2286 | 55 | unsigned int counter = 0; | 2287 | 55 | arelent *cache_ptr; | 2288 | 55 | bfd_size_type amt; | 2289 | | | 2290 | 55 | if (asect->relocation) | 2291 | 0 | return true; | 2292 | | | 2293 | 55 | if (asect->flags & SEC_CONSTRUCTOR) | 2294 | 0 | return true; | 2295 | | | 2296 | 55 | if (asect == obj_datasec (abfd)) | 2297 | 7 | reloc_size = exec_hdr (abfd)->a_drsize; | 2298 | 48 | else if (asect == obj_textsec (abfd)) | 2299 | 48 | reloc_size = exec_hdr (abfd)->a_trsize; | 2300 | 0 | else if (asect == obj_bsssec (abfd)) | 2301 | 0 | reloc_size = 0; | 2302 | 0 | else | 2303 | 0 | { | 2304 | 0 | bfd_set_error (bfd_error_invalid_operation); | 2305 | 0 | return false; | 2306 | 0 | } | 2307 | | | 2308 | 55 | each_size = obj_reloc_entry_size (abfd); | 2309 | 55 | count = reloc_size / each_size; | 2310 | 55 | if (count == 0) | 2311 | 1 | return true; /* Nothing to be done. */ | 2312 | | | 2313 | 54 | if (bfd_seek (abfd, asect->rel_filepos, SEEK_SET) != 0) | 2314 | 0 | return false; | 2315 | 54 | relocs = _bfd_malloc_and_read (abfd, reloc_size, reloc_size); | 2316 | 54 | if (relocs == NULL) | 2317 | 6 | return false; | 2318 | | | 2319 | 48 | amt = count * sizeof (arelent); | 2320 | 48 | reloc_cache = (arelent *) bfd_zmalloc (amt); | 2321 | 48 | if (reloc_cache == NULL) | 2322 | 0 | { | 2323 | 0 | free (relocs); | 2324 | 0 | return false; | 2325 | 0 | } | 2326 | | | 2327 | 48 | cache_ptr = reloc_cache; | 2328 | 48 | if (each_size == RELOC_EXT_SIZE) | 2329 | 0 | { | 2330 | 0 | struct reloc_ext_external *rptr = (struct reloc_ext_external *) relocs; | 2331 | |
| 2332 | 0 | for (; counter < count; counter++, rptr++, cache_ptr++) | 2333 | 0 | MY_swap_ext_reloc_in (abfd, rptr, cache_ptr, symbols, | 2334 | 0 | (bfd_size_type) bfd_get_symcount (abfd)); | 2335 | 0 | } | 2336 | 48 | else | 2337 | 48 | { | 2338 | 48 | struct reloc_std_external *rptr = (struct reloc_std_external *) relocs; | 2339 | | | 2340 | 10.9k | for (; counter < count; counter++, rptr++, cache_ptr++) | 2341 | 10.8k | MY_swap_std_reloc_in (abfd, rptr, cache_ptr, symbols, | 2342 | 10.8k | (bfd_size_type) bfd_get_symcount (abfd)); | 2343 | 48 | } | 2344 | | | 2345 | 48 | free (relocs); | 2346 | | | 2347 | 48 | asect->relocation = reloc_cache; | 2348 | 48 | asect->reloc_count = cache_ptr - reloc_cache; | 2349 | | | 2350 | 48 | return true; | 2351 | 48 | } |
aout_32_slurp_reloc_table Line | Count | Source | 2280 | 59 | { | 2281 | 59 | bfd_size_type count; | 2282 | 59 | bfd_size_type reloc_size; | 2283 | 59 | void * relocs; | 2284 | 59 | arelent *reloc_cache; | 2285 | 59 | size_t each_size; | 2286 | 59 | unsigned int counter = 0; | 2287 | 59 | arelent *cache_ptr; | 2288 | 59 | bfd_size_type amt; | 2289 | | | 2290 | 59 | if (asect->relocation) | 2291 | 0 | return true; | 2292 | | | 2293 | 59 | if (asect->flags & SEC_CONSTRUCTOR) | 2294 | 0 | return true; | 2295 | | | 2296 | 59 | if (asect == obj_datasec (abfd)) | 2297 | 2 | reloc_size = exec_hdr (abfd)->a_drsize; | 2298 | 57 | else if (asect == obj_textsec (abfd)) | 2299 | 57 | reloc_size = exec_hdr (abfd)->a_trsize; | 2300 | 0 | else if (asect == obj_bsssec (abfd)) | 2301 | 0 | reloc_size = 0; | 2302 | 0 | else | 2303 | 0 | { | 2304 | 0 | bfd_set_error (bfd_error_invalid_operation); | 2305 | 0 | return false; | 2306 | 0 | } | 2307 | | | 2308 | 59 | each_size = obj_reloc_entry_size (abfd); | 2309 | 59 | count = reloc_size / each_size; | 2310 | 59 | if (count == 0) | 2311 | 1 | return true; /* Nothing to be done. */ | 2312 | | | 2313 | 58 | if (bfd_seek (abfd, asect->rel_filepos, SEEK_SET) != 0) | 2314 | 0 | return false; | 2315 | 58 | relocs = _bfd_malloc_and_read (abfd, reloc_size, reloc_size); | 2316 | 58 | if (relocs == NULL) | 2317 | 0 | return false; | 2318 | | | 2319 | 58 | amt = count * sizeof (arelent); | 2320 | 58 | reloc_cache = (arelent *) bfd_zmalloc (amt); | 2321 | 58 | if (reloc_cache == NULL) | 2322 | 0 | { | 2323 | 0 | free (relocs); | 2324 | 0 | return false; | 2325 | 0 | } | 2326 | | | 2327 | 58 | cache_ptr = reloc_cache; | 2328 | 58 | if (each_size == RELOC_EXT_SIZE) | 2329 | 0 | { | 2330 | 0 | struct reloc_ext_external *rptr = (struct reloc_ext_external *) relocs; | 2331 | |
| 2332 | 0 | for (; counter < count; counter++, rptr++, cache_ptr++) | 2333 | 0 | MY_swap_ext_reloc_in (abfd, rptr, cache_ptr, symbols, | 2334 | 0 | (bfd_size_type) bfd_get_symcount (abfd)); | 2335 | 0 | } | 2336 | 58 | else | 2337 | 58 | { | 2338 | 58 | struct reloc_std_external *rptr = (struct reloc_std_external *) relocs; | 2339 | | | 2340 | 3.10k | for (; counter < count; counter++, rptr++, cache_ptr++) | 2341 | 3.04k | MY_swap_std_reloc_in (abfd, rptr, cache_ptr, symbols, | 2342 | 3.04k | (bfd_size_type) bfd_get_symcount (abfd)); | 2343 | 58 | } | 2344 | | | 2345 | 58 | free (relocs); | 2346 | | | 2347 | 58 | asect->relocation = reloc_cache; | 2348 | 58 | asect->reloc_count = cache_ptr - reloc_cache; | 2349 | | | 2350 | 58 | return true; | 2351 | 58 | } |
|
2352 | | |
2353 | | /* Write out a relocation section into an object file. */ |
2354 | | |
2355 | | bool |
2356 | | NAME (aout, squirt_out_relocs) (bfd *abfd, asection *section) |
2357 | 7 | { |
2358 | 7 | arelent **generic; |
2359 | 7 | unsigned char *native, *natptr; |
2360 | 7 | size_t each_size; |
2361 | | |
2362 | 7 | unsigned int count = section->reloc_count; |
2363 | 7 | bfd_size_type natsize; |
2364 | | |
2365 | 7 | if (count == 0 || section->orelocation == NULL) |
2366 | 4 | return true; |
2367 | | |
2368 | 3 | each_size = obj_reloc_entry_size (abfd); |
2369 | 3 | natsize = (bfd_size_type) each_size * count; |
2370 | 3 | native = (unsigned char *) bfd_zalloc (abfd, natsize); |
2371 | 3 | if (!native) |
2372 | 0 | return false; |
2373 | | |
2374 | 3 | generic = section->orelocation; |
2375 | | |
2376 | 3 | if (each_size == RELOC_EXT_SIZE) |
2377 | 0 | { |
2378 | 0 | for (natptr = native; |
2379 | 0 | count != 0; |
2380 | 0 | --count, natptr += each_size, ++generic) |
2381 | 0 | { |
2382 | | /* PR 20921: If the howto field has not been initialised then skip |
2383 | | this reloc. |
2384 | | PR 20929: Similarly for the symbol field. */ |
2385 | 0 | if ((*generic)->howto == NULL |
2386 | 0 | || (*generic)->sym_ptr_ptr == NULL) |
2387 | 0 | { |
2388 | 0 | bfd_set_error (bfd_error_invalid_operation); |
2389 | 0 | _bfd_error_handler (_("%pB: attempt to write out " |
2390 | 0 | "unknown reloc type"), abfd); |
2391 | 0 | return false; |
2392 | 0 | } |
2393 | 0 | MY_swap_ext_reloc_out (abfd, *generic, |
2394 | 0 | (struct reloc_ext_external *) natptr); |
2395 | 0 | } |
2396 | 0 | } |
2397 | 3 | else |
2398 | 3 | { |
2399 | 3 | for (natptr = native; |
2400 | 32 | count != 0; |
2401 | 29 | --count, natptr += each_size, ++generic) |
2402 | 30 | { |
2403 | 30 | if ((*generic)->howto == NULL |
2404 | 30 | || (*generic)->sym_ptr_ptr == NULL) |
2405 | 1 | { |
2406 | 1 | bfd_set_error (bfd_error_invalid_operation); |
2407 | 1 | _bfd_error_handler (_("%pB: attempt to write out " |
2408 | 1 | "unknown reloc type"), abfd); |
2409 | 1 | return false; |
2410 | 1 | } |
2411 | 29 | MY_swap_std_reloc_out (abfd, *generic, |
2412 | 29 | (struct reloc_std_external *) natptr); |
2413 | 29 | } |
2414 | 3 | } |
2415 | | |
2416 | 2 | if (bfd_write (native, natsize, abfd) != natsize) |
2417 | 0 | { |
2418 | 0 | bfd_release (abfd, native); |
2419 | 0 | return false; |
2420 | 0 | } |
2421 | 2 | bfd_release (abfd, native); |
2422 | | |
2423 | 2 | return true; |
2424 | 2 | } Unexecuted instantiation: cris_aout_32_squirt_out_relocs ns32kaout_32_squirt_out_relocs Line | Count | Source | 2357 | 1 | { | 2358 | 1 | arelent **generic; | 2359 | 1 | unsigned char *native, *natptr; | 2360 | 1 | size_t each_size; | 2361 | | | 2362 | 1 | unsigned int count = section->reloc_count; | 2363 | 1 | bfd_size_type natsize; | 2364 | | | 2365 | 1 | if (count == 0 || section->orelocation == NULL) | 2366 | 0 | return true; | 2367 | | | 2368 | 1 | each_size = obj_reloc_entry_size (abfd); | 2369 | 1 | natsize = (bfd_size_type) each_size * count; | 2370 | 1 | native = (unsigned char *) bfd_zalloc (abfd, natsize); | 2371 | 1 | if (!native) | 2372 | 0 | return false; | 2373 | | | 2374 | 1 | generic = section->orelocation; | 2375 | | | 2376 | 1 | if (each_size == RELOC_EXT_SIZE) | 2377 | 0 | { | 2378 | 0 | for (natptr = native; | 2379 | 0 | count != 0; | 2380 | 0 | --count, natptr += each_size, ++generic) | 2381 | 0 | { | 2382 | | /* PR 20921: If the howto field has not been initialised then skip | 2383 | | this reloc. | 2384 | | PR 20929: Similarly for the symbol field. */ | 2385 | 0 | if ((*generic)->howto == NULL | 2386 | 0 | || (*generic)->sym_ptr_ptr == NULL) | 2387 | 0 | { | 2388 | 0 | bfd_set_error (bfd_error_invalid_operation); | 2389 | 0 | _bfd_error_handler (_("%pB: attempt to write out " | 2390 | 0 | "unknown reloc type"), abfd); | 2391 | 0 | return false; | 2392 | 0 | } | 2393 | 0 | MY_swap_ext_reloc_out (abfd, *generic, | 2394 | 0 | (struct reloc_ext_external *) natptr); | 2395 | 0 | } | 2396 | 0 | } | 2397 | 1 | else | 2398 | 1 | { | 2399 | 1 | for (natptr = native; | 2400 | 2 | count != 0; | 2401 | 1 | --count, natptr += each_size, ++generic) | 2402 | 2 | { | 2403 | 2 | if ((*generic)->howto == NULL | 2404 | 2 | || (*generic)->sym_ptr_ptr == NULL) | 2405 | 1 | { | 2406 | 1 | bfd_set_error (bfd_error_invalid_operation); | 2407 | 1 | _bfd_error_handler (_("%pB: attempt to write out " | 2408 | 1 | "unknown reloc type"), abfd); | 2409 | 1 | return false; | 2410 | 1 | } | 2411 | 1 | MY_swap_std_reloc_out (abfd, *generic, | 2412 | 1 | (struct reloc_std_external *) natptr); | 2413 | 1 | } | 2414 | 1 | } | 2415 | | | 2416 | 0 | if (bfd_write (native, natsize, abfd) != natsize) | 2417 | 0 | { | 2418 | 0 | bfd_release (abfd, native); | 2419 | 0 | return false; | 2420 | 0 | } | 2421 | 0 | bfd_release (abfd, native); | 2422 | |
| 2423 | 0 | return true; | 2424 | 0 | } |
aout_32_squirt_out_relocs Line | Count | Source | 2357 | 6 | { | 2358 | 6 | arelent **generic; | 2359 | 6 | unsigned char *native, *natptr; | 2360 | 6 | size_t each_size; | 2361 | | | 2362 | 6 | unsigned int count = section->reloc_count; | 2363 | 6 | bfd_size_type natsize; | 2364 | | | 2365 | 6 | if (count == 0 || section->orelocation == NULL) | 2366 | 4 | return true; | 2367 | | | 2368 | 2 | each_size = obj_reloc_entry_size (abfd); | 2369 | 2 | natsize = (bfd_size_type) each_size * count; | 2370 | 2 | native = (unsigned char *) bfd_zalloc (abfd, natsize); | 2371 | 2 | if (!native) | 2372 | 0 | return false; | 2373 | | | 2374 | 2 | generic = section->orelocation; | 2375 | | | 2376 | 2 | if (each_size == RELOC_EXT_SIZE) | 2377 | 0 | { | 2378 | 0 | for (natptr = native; | 2379 | 0 | count != 0; | 2380 | 0 | --count, natptr += each_size, ++generic) | 2381 | 0 | { | 2382 | | /* PR 20921: If the howto field has not been initialised then skip | 2383 | | this reloc. | 2384 | | PR 20929: Similarly for the symbol field. */ | 2385 | 0 | if ((*generic)->howto == NULL | 2386 | 0 | || (*generic)->sym_ptr_ptr == NULL) | 2387 | 0 | { | 2388 | 0 | bfd_set_error (bfd_error_invalid_operation); | 2389 | 0 | _bfd_error_handler (_("%pB: attempt to write out " | 2390 | 0 | "unknown reloc type"), abfd); | 2391 | 0 | return false; | 2392 | 0 | } | 2393 | 0 | MY_swap_ext_reloc_out (abfd, *generic, | 2394 | 0 | (struct reloc_ext_external *) natptr); | 2395 | 0 | } | 2396 | 0 | } | 2397 | 2 | else | 2398 | 2 | { | 2399 | 2 | for (natptr = native; | 2400 | 30 | count != 0; | 2401 | 28 | --count, natptr += each_size, ++generic) | 2402 | 28 | { | 2403 | 28 | if ((*generic)->howto == NULL | 2404 | 28 | || (*generic)->sym_ptr_ptr == NULL) | 2405 | 0 | { | 2406 | 0 | bfd_set_error (bfd_error_invalid_operation); | 2407 | 0 | _bfd_error_handler (_("%pB: attempt to write out " | 2408 | 0 | "unknown reloc type"), abfd); | 2409 | 0 | return false; | 2410 | 0 | } | 2411 | 28 | MY_swap_std_reloc_out (abfd, *generic, | 2412 | 28 | (struct reloc_std_external *) natptr); | 2413 | 28 | } | 2414 | 2 | } | 2415 | | | 2416 | 2 | if (bfd_write (native, natsize, abfd) != natsize) | 2417 | 0 | { | 2418 | 0 | bfd_release (abfd, native); | 2419 | 0 | return false; | 2420 | 0 | } | 2421 | 2 | bfd_release (abfd, native); | 2422 | | | 2423 | 2 | return true; | 2424 | 2 | } |
|
2425 | | |
2426 | | /* This is stupid. This function should be a boolean predicate. */ |
2427 | | |
2428 | | long |
2429 | | NAME (aout, canonicalize_reloc) (bfd *abfd, |
2430 | | sec_ptr section, |
2431 | | arelent **relptr, |
2432 | | asymbol **symbols) |
2433 | 117 | { |
2434 | 117 | arelent *tblptr = section->relocation; |
2435 | 117 | unsigned int count; |
2436 | | |
2437 | 117 | if (section == obj_bsssec (abfd)) |
2438 | 3 | { |
2439 | 3 | *relptr = NULL; |
2440 | 3 | return 0; |
2441 | 3 | } |
2442 | | |
2443 | 114 | if (!(tblptr || NAME (aout, slurp_reloc_table) (abfd, section, symbols))) |
2444 | 6 | return -1; |
2445 | | |
2446 | 108 | if (section->flags & SEC_CONSTRUCTOR) |
2447 | 0 | { |
2448 | 0 | arelent_chain *chain = section->constructor_chain; |
2449 | 0 | for (count = 0; count < section->reloc_count; count ++) |
2450 | 0 | { |
2451 | 0 | *relptr ++ = &chain->relent; |
2452 | 0 | chain = chain->next; |
2453 | 0 | } |
2454 | 0 | } |
2455 | 108 | else |
2456 | 108 | { |
2457 | 108 | tblptr = section->relocation; |
2458 | | |
2459 | 14.0k | for (count = 0; count++ < section->reloc_count; ) |
2460 | 13.9k | { |
2461 | 13.9k | *relptr++ = tblptr++; |
2462 | 13.9k | } |
2463 | 108 | } |
2464 | 108 | *relptr = 0; |
2465 | | |
2466 | 108 | return section->reloc_count; |
2467 | 114 | } Unexecuted instantiation: cris_aout_32_canonicalize_reloc ns32kaout_32_canonicalize_reloc Line | Count | Source | 2433 | 56 | { | 2434 | 56 | arelent *tblptr = section->relocation; | 2435 | 56 | unsigned int count; | 2436 | | | 2437 | 56 | if (section == obj_bsssec (abfd)) | 2438 | 1 | { | 2439 | 1 | *relptr = NULL; | 2440 | 1 | return 0; | 2441 | 1 | } | 2442 | | | 2443 | 55 | if (!(tblptr || NAME (aout, slurp_reloc_table) (abfd, section, symbols))) | 2444 | 6 | return -1; | 2445 | | | 2446 | 49 | if (section->flags & SEC_CONSTRUCTOR) | 2447 | 0 | { | 2448 | 0 | arelent_chain *chain = section->constructor_chain; | 2449 | 0 | for (count = 0; count < section->reloc_count; count ++) | 2450 | 0 | { | 2451 | 0 | *relptr ++ = &chain->relent; | 2452 | 0 | chain = chain->next; | 2453 | 0 | } | 2454 | 0 | } | 2455 | 49 | else | 2456 | 49 | { | 2457 | 49 | tblptr = section->relocation; | 2458 | | | 2459 | 10.9k | for (count = 0; count++ < section->reloc_count; ) | 2460 | 10.8k | { | 2461 | 10.8k | *relptr++ = tblptr++; | 2462 | 10.8k | } | 2463 | 49 | } | 2464 | 49 | *relptr = 0; | 2465 | | | 2466 | 49 | return section->reloc_count; | 2467 | 55 | } |
aout_32_canonicalize_reloc Line | Count | Source | 2433 | 61 | { | 2434 | 61 | arelent *tblptr = section->relocation; | 2435 | 61 | unsigned int count; | 2436 | | | 2437 | 61 | if (section == obj_bsssec (abfd)) | 2438 | 2 | { | 2439 | 2 | *relptr = NULL; | 2440 | 2 | return 0; | 2441 | 2 | } | 2442 | | | 2443 | 59 | if (!(tblptr || NAME (aout, slurp_reloc_table) (abfd, section, symbols))) | 2444 | 0 | return -1; | 2445 | | | 2446 | 59 | if (section->flags & SEC_CONSTRUCTOR) | 2447 | 0 | { | 2448 | 0 | arelent_chain *chain = section->constructor_chain; | 2449 | 0 | for (count = 0; count < section->reloc_count; count ++) | 2450 | 0 | { | 2451 | 0 | *relptr ++ = &chain->relent; | 2452 | 0 | chain = chain->next; | 2453 | 0 | } | 2454 | 0 | } | 2455 | 59 | else | 2456 | 59 | { | 2457 | 59 | tblptr = section->relocation; | 2458 | | | 2459 | 3.10k | for (count = 0; count++ < section->reloc_count; ) | 2460 | 3.04k | { | 2461 | 3.04k | *relptr++ = tblptr++; | 2462 | 3.04k | } | 2463 | 59 | } | 2464 | 59 | *relptr = 0; | 2465 | | | 2466 | 59 | return section->reloc_count; | 2467 | 59 | } |
|
2468 | | |
2469 | | long |
2470 | | NAME (aout, get_reloc_upper_bound) (bfd *abfd, sec_ptr asect) |
2471 | 153 | { |
2472 | 153 | size_t count, raw; |
2473 | | |
2474 | 153 | if (asect->flags & SEC_CONSTRUCTOR) |
2475 | 0 | count = asect->reloc_count; |
2476 | 153 | else if (asect == obj_datasec (abfd)) |
2477 | 30 | count = exec_hdr (abfd)->a_drsize / obj_reloc_entry_size (abfd); |
2478 | 123 | else if (asect == obj_textsec (abfd)) |
2479 | 120 | count = exec_hdr (abfd)->a_trsize / obj_reloc_entry_size (abfd); |
2480 | 3 | else if (asect == obj_bsssec (abfd)) |
2481 | 3 | count = 0; |
2482 | 0 | else |
2483 | 0 | { |
2484 | 0 | bfd_set_error (bfd_error_invalid_operation); |
2485 | 0 | return -1; |
2486 | 0 | } |
2487 | | |
2488 | 153 | if (count >= LONG_MAX / sizeof (arelent *) |
2489 | 153 | || _bfd_mul_overflow (count, obj_reloc_entry_size (abfd), &raw)) |
2490 | 0 | { |
2491 | 0 | bfd_set_error (bfd_error_file_too_big); |
2492 | 0 | return -1; |
2493 | 0 | } |
2494 | 153 | if (!bfd_write_p (abfd)) |
2495 | 153 | { |
2496 | 153 | ufile_ptr filesize = bfd_get_file_size (abfd); |
2497 | 153 | if (filesize != 0 && raw > filesize) |
2498 | 36 | { |
2499 | 36 | bfd_set_error (bfd_error_file_truncated); |
2500 | 36 | return -1; |
2501 | 36 | } |
2502 | 153 | } |
2503 | 117 | return (count + 1) * sizeof (arelent *); |
2504 | 153 | } Unexecuted instantiation: cris_aout_32_get_reloc_upper_bound ns32kaout_32_get_reloc_upper_bound Line | Count | Source | 2471 | 88 | { | 2472 | 88 | size_t count, raw; | 2473 | | | 2474 | 88 | if (asect->flags & SEC_CONSTRUCTOR) | 2475 | 0 | count = asect->reloc_count; | 2476 | 88 | else if (asect == obj_datasec (abfd)) | 2477 | 25 | count = exec_hdr (abfd)->a_drsize / obj_reloc_entry_size (abfd); | 2478 | 63 | else if (asect == obj_textsec (abfd)) | 2479 | 62 | count = exec_hdr (abfd)->a_trsize / obj_reloc_entry_size (abfd); | 2480 | 1 | else if (asect == obj_bsssec (abfd)) | 2481 | 1 | count = 0; | 2482 | 0 | else | 2483 | 0 | { | 2484 | 0 | bfd_set_error (bfd_error_invalid_operation); | 2485 | 0 | return -1; | 2486 | 0 | } | 2487 | | | 2488 | 88 | if (count >= LONG_MAX / sizeof (arelent *) | 2489 | 88 | || _bfd_mul_overflow (count, obj_reloc_entry_size (abfd), &raw)) | 2490 | 0 | { | 2491 | 0 | bfd_set_error (bfd_error_file_too_big); | 2492 | 0 | return -1; | 2493 | 0 | } | 2494 | 88 | if (!bfd_write_p (abfd)) | 2495 | 88 | { | 2496 | 88 | ufile_ptr filesize = bfd_get_file_size (abfd); | 2497 | 88 | if (filesize != 0 && raw > filesize) | 2498 | 32 | { | 2499 | 32 | bfd_set_error (bfd_error_file_truncated); | 2500 | 32 | return -1; | 2501 | 32 | } | 2502 | 88 | } | 2503 | 56 | return (count + 1) * sizeof (arelent *); | 2504 | 88 | } |
aout_32_get_reloc_upper_bound Line | Count | Source | 2471 | 65 | { | 2472 | 65 | size_t count, raw; | 2473 | | | 2474 | 65 | if (asect->flags & SEC_CONSTRUCTOR) | 2475 | 0 | count = asect->reloc_count; | 2476 | 65 | else if (asect == obj_datasec (abfd)) | 2477 | 5 | count = exec_hdr (abfd)->a_drsize / obj_reloc_entry_size (abfd); | 2478 | 60 | else if (asect == obj_textsec (abfd)) | 2479 | 58 | count = exec_hdr (abfd)->a_trsize / obj_reloc_entry_size (abfd); | 2480 | 2 | else if (asect == obj_bsssec (abfd)) | 2481 | 2 | count = 0; | 2482 | 0 | else | 2483 | 0 | { | 2484 | 0 | bfd_set_error (bfd_error_invalid_operation); | 2485 | 0 | return -1; | 2486 | 0 | } | 2487 | | | 2488 | 65 | if (count >= LONG_MAX / sizeof (arelent *) | 2489 | 65 | || _bfd_mul_overflow (count, obj_reloc_entry_size (abfd), &raw)) | 2490 | 0 | { | 2491 | 0 | bfd_set_error (bfd_error_file_too_big); | 2492 | 0 | return -1; | 2493 | 0 | } | 2494 | 65 | if (!bfd_write_p (abfd)) | 2495 | 65 | { | 2496 | 65 | ufile_ptr filesize = bfd_get_file_size (abfd); | 2497 | 65 | if (filesize != 0 && raw > filesize) | 2498 | 4 | { | 2499 | 4 | bfd_set_error (bfd_error_file_truncated); | 2500 | 4 | return -1; | 2501 | 4 | } | 2502 | 65 | } | 2503 | 61 | return (count + 1) * sizeof (arelent *); | 2504 | 65 | } |
|
2505 | | |
2506 | | long |
2507 | | NAME (aout, get_symtab_upper_bound) (bfd *abfd) |
2508 | 1.48k | { |
2509 | 1.48k | if (!NAME (aout, slurp_symbol_table) (abfd)) |
2510 | 424 | return -1; |
2511 | | |
2512 | 1.05k | return (bfd_get_symcount (abfd)+1) * (sizeof (aout_symbol_type *)); |
2513 | 1.48k | } Unexecuted instantiation: cris_aout_32_get_symtab_upper_bound ns32kaout_32_get_symtab_upper_bound Line | Count | Source | 2508 | 851 | { | 2509 | 851 | if (!NAME (aout, slurp_symbol_table) (abfd)) | 2510 | 202 | return -1; | 2511 | | | 2512 | 649 | return (bfd_get_symcount (abfd)+1) * (sizeof (aout_symbol_type *)); | 2513 | 851 | } |
aout_32_get_symtab_upper_bound Line | Count | Source | 2508 | 630 | { | 2509 | 630 | if (!NAME (aout, slurp_symbol_table) (abfd)) | 2510 | 222 | return -1; | 2511 | | | 2512 | 408 | return (bfd_get_symcount (abfd)+1) * (sizeof (aout_symbol_type *)); | 2513 | 630 | } |
|
2514 | | |
2515 | | alent * |
2516 | | NAME (aout, get_lineno) (bfd *ignore_abfd ATTRIBUTE_UNUSED, |
2517 | | asymbol *ignore_symbol ATTRIBUTE_UNUSED) |
2518 | 0 | { |
2519 | 0 | return NULL; |
2520 | 0 | } Unexecuted instantiation: cris_aout_32_get_lineno Unexecuted instantiation: ns32kaout_32_get_lineno Unexecuted instantiation: aout_32_get_lineno |
2521 | | |
2522 | | void |
2523 | | NAME (aout, get_symbol_info) (bfd *ignore_abfd ATTRIBUTE_UNUSED, |
2524 | | asymbol *symbol, |
2525 | | symbol_info *ret) |
2526 | 1.83M | { |
2527 | 1.83M | bfd_symbol_info (symbol, ret); |
2528 | | |
2529 | 1.83M | if (ret->type == '?') |
2530 | 10.7k | { |
2531 | 10.7k | int type_code = aout_symbol (symbol)->type & 0xff; |
2532 | 10.7k | const char *stab_name = bfd_get_stab_name (type_code); |
2533 | 10.7k | static char buf[10]; |
2534 | | |
2535 | 10.7k | if (stab_name == NULL) |
2536 | 4.30k | { |
2537 | 4.30k | sprintf (buf, "(%d)", type_code); |
2538 | 4.30k | stab_name = buf; |
2539 | 4.30k | } |
2540 | 10.7k | ret->type = '-'; |
2541 | 10.7k | ret->stab_type = type_code; |
2542 | 10.7k | ret->stab_other = (unsigned) (aout_symbol (symbol)->other & 0xff); |
2543 | 10.7k | ret->stab_desc = (unsigned) (aout_symbol (symbol)->desc & 0xffff); |
2544 | 10.7k | ret->stab_name = stab_name; |
2545 | 10.7k | } |
2546 | 1.83M | } Unexecuted instantiation: cris_aout_32_get_symbol_info ns32kaout_32_get_symbol_info Line | Count | Source | 2526 | 1.01M | { | 2527 | 1.01M | bfd_symbol_info (symbol, ret); | 2528 | | | 2529 | 1.01M | if (ret->type == '?') | 2530 | 5.19k | { | 2531 | 5.19k | int type_code = aout_symbol (symbol)->type & 0xff; | 2532 | 5.19k | const char *stab_name = bfd_get_stab_name (type_code); | 2533 | 5.19k | static char buf[10]; | 2534 | | | 2535 | 5.19k | if (stab_name == NULL) | 2536 | 2.23k | { | 2537 | 2.23k | sprintf (buf, "(%d)", type_code); | 2538 | 2.23k | stab_name = buf; | 2539 | 2.23k | } | 2540 | 5.19k | ret->type = '-'; | 2541 | 5.19k | ret->stab_type = type_code; | 2542 | 5.19k | ret->stab_other = (unsigned) (aout_symbol (symbol)->other & 0xff); | 2543 | 5.19k | ret->stab_desc = (unsigned) (aout_symbol (symbol)->desc & 0xffff); | 2544 | 5.19k | ret->stab_name = stab_name; | 2545 | 5.19k | } | 2546 | 1.01M | } |
Line | Count | Source | 2526 | 819k | { | 2527 | 819k | bfd_symbol_info (symbol, ret); | 2528 | | | 2529 | 819k | if (ret->type == '?') | 2530 | 5.53k | { | 2531 | 5.53k | int type_code = aout_symbol (symbol)->type & 0xff; | 2532 | 5.53k | const char *stab_name = bfd_get_stab_name (type_code); | 2533 | 5.53k | static char buf[10]; | 2534 | | | 2535 | 5.53k | if (stab_name == NULL) | 2536 | 2.07k | { | 2537 | 2.07k | sprintf (buf, "(%d)", type_code); | 2538 | 2.07k | stab_name = buf; | 2539 | 2.07k | } | 2540 | 5.53k | ret->type = '-'; | 2541 | 5.53k | ret->stab_type = type_code; | 2542 | 5.53k | ret->stab_other = (unsigned) (aout_symbol (symbol)->other & 0xff); | 2543 | 5.53k | ret->stab_desc = (unsigned) (aout_symbol (symbol)->desc & 0xffff); | 2544 | 5.53k | ret->stab_name = stab_name; | 2545 | 5.53k | } | 2546 | 819k | } |
|
2547 | | |
2548 | | void |
2549 | | NAME (aout, print_symbol) (bfd *abfd, |
2550 | | void * afile, |
2551 | | asymbol *symbol, |
2552 | | bfd_print_symbol_type how) |
2553 | 0 | { |
2554 | 0 | FILE *file = (FILE *)afile; |
2555 | |
|
2556 | 0 | switch (how) |
2557 | 0 | { |
2558 | 0 | case bfd_print_symbol_name: |
2559 | 0 | if (symbol->name) |
2560 | 0 | fprintf (file,"%s", symbol->name); |
2561 | 0 | break; |
2562 | 0 | case bfd_print_symbol_more: |
2563 | 0 | fprintf (file,"%4x %2x %2x", |
2564 | 0 | (unsigned) (aout_symbol (symbol)->desc & 0xffff), |
2565 | 0 | (unsigned) (aout_symbol (symbol)->other & 0xff), |
2566 | 0 | (unsigned) (aout_symbol (symbol)->type)); |
2567 | 0 | break; |
2568 | 0 | case bfd_print_symbol_all: |
2569 | 0 | { |
2570 | 0 | const char *section_name = symbol->section->name; |
2571 | |
|
2572 | 0 | bfd_print_symbol_vandf (abfd, (void *)file, symbol); |
2573 | |
|
2574 | 0 | fprintf (file," %-5s %04x %02x %02x", |
2575 | 0 | section_name, |
2576 | 0 | (unsigned) (aout_symbol (symbol)->desc & 0xffff), |
2577 | 0 | (unsigned) (aout_symbol (symbol)->other & 0xff), |
2578 | 0 | (unsigned) (aout_symbol (symbol)->type & 0xff)); |
2579 | 0 | if (symbol->name) |
2580 | 0 | fprintf (file," %s", symbol->name); |
2581 | 0 | } |
2582 | 0 | break; |
2583 | 0 | } |
2584 | 0 | } Unexecuted instantiation: cris_aout_32_print_symbol Unexecuted instantiation: ns32kaout_32_print_symbol Unexecuted instantiation: aout_32_print_symbol |
2585 | | |
2586 | | /* If we don't have to allocate more than 1MB to hold the generic |
2587 | | symbols, we use the generic minisymbol methord: it's faster, since |
2588 | | it only translates the symbols once, not multiple times. */ |
2589 | 65.8M | #define MINISYM_THRESHOLD (1000000 / sizeof (asymbol)) |
2590 | | |
2591 | | /* Read minisymbols. For minisymbols, we use the unmodified a.out |
2592 | | symbols. The minisymbol_to_symbol function translates these into |
2593 | | BFD asymbol structures. */ |
2594 | | |
2595 | | long |
2596 | | NAME (aout, read_minisymbols) (bfd *abfd, |
2597 | | bool dynamic, |
2598 | | void * *minisymsp, |
2599 | | unsigned int *sizep) |
2600 | 509 | { |
2601 | 509 | if (dynamic) |
2602 | | /* We could handle the dynamic symbols here as well, but it's |
2603 | | easier to hand them off. */ |
2604 | 0 | return _bfd_generic_read_minisymbols (abfd, dynamic, minisymsp, sizep); |
2605 | | |
2606 | 509 | if (! aout_get_external_symbols (abfd)) |
2607 | 54 | return -1; |
2608 | | |
2609 | 455 | if (obj_aout_external_sym_count (abfd) < MINISYM_THRESHOLD) |
2610 | 268 | return _bfd_generic_read_minisymbols (abfd, dynamic, minisymsp, sizep); |
2611 | | |
2612 | 187 | *minisymsp = (void *) obj_aout_external_syms (abfd); |
2613 | | |
2614 | | /* By passing the external symbols back from this routine, we are |
2615 | | giving up control over the memory block. Clear |
2616 | | obj_aout_external_syms, so that we do not try to free it |
2617 | | ourselves. */ |
2618 | 187 | obj_aout_external_syms (abfd) = NULL; |
2619 | | |
2620 | 187 | *sizep = EXTERNAL_NLIST_SIZE; |
2621 | 187 | return obj_aout_external_sym_count (abfd); |
2622 | 455 | } Unexecuted instantiation: cris_aout_32_read_minisymbols ns32kaout_32_read_minisymbols Line | Count | Source | 2600 | 241 | { | 2601 | 241 | if (dynamic) | 2602 | | /* We could handle the dynamic symbols here as well, but it's | 2603 | | easier to hand them off. */ | 2604 | 0 | return _bfd_generic_read_minisymbols (abfd, dynamic, minisymsp, sizep); | 2605 | | | 2606 | 241 | if (! aout_get_external_symbols (abfd)) | 2607 | 27 | return -1; | 2608 | | | 2609 | 214 | if (obj_aout_external_sym_count (abfd) < MINISYM_THRESHOLD) | 2610 | 136 | return _bfd_generic_read_minisymbols (abfd, dynamic, minisymsp, sizep); | 2611 | | | 2612 | 78 | *minisymsp = (void *) obj_aout_external_syms (abfd); | 2613 | | | 2614 | | /* By passing the external symbols back from this routine, we are | 2615 | | giving up control over the memory block. Clear | 2616 | | obj_aout_external_syms, so that we do not try to free it | 2617 | | ourselves. */ | 2618 | 78 | obj_aout_external_syms (abfd) = NULL; | 2619 | | | 2620 | 78 | *sizep = EXTERNAL_NLIST_SIZE; | 2621 | 78 | return obj_aout_external_sym_count (abfd); | 2622 | 214 | } |
Line | Count | Source | 2600 | 268 | { | 2601 | 268 | if (dynamic) | 2602 | | /* We could handle the dynamic symbols here as well, but it's | 2603 | | easier to hand them off. */ | 2604 | 0 | return _bfd_generic_read_minisymbols (abfd, dynamic, minisymsp, sizep); | 2605 | | | 2606 | 268 | if (! aout_get_external_symbols (abfd)) | 2607 | 27 | return -1; | 2608 | | | 2609 | 241 | if (obj_aout_external_sym_count (abfd) < MINISYM_THRESHOLD) | 2610 | 132 | return _bfd_generic_read_minisymbols (abfd, dynamic, minisymsp, sizep); | 2611 | | | 2612 | 109 | *minisymsp = (void *) obj_aout_external_syms (abfd); | 2613 | | | 2614 | | /* By passing the external symbols back from this routine, we are | 2615 | | giving up control over the memory block. Clear | 2616 | | obj_aout_external_syms, so that we do not try to free it | 2617 | | ourselves. */ | 2618 | 109 | obj_aout_external_syms (abfd) = NULL; | 2619 | | | 2620 | 109 | *sizep = EXTERNAL_NLIST_SIZE; | 2621 | 109 | return obj_aout_external_sym_count (abfd); | 2622 | 241 | } |
|
2623 | | |
2624 | | /* Convert a minisymbol to a BFD asymbol. A minisymbol is just an |
2625 | | unmodified a.out symbol. The SYM argument is a structure returned |
2626 | | by bfd_make_empty_symbol, which we fill in here. */ |
2627 | | |
2628 | | asymbol * |
2629 | | NAME (aout, minisymbol_to_symbol) (bfd *abfd, |
2630 | | bool dynamic, |
2631 | | const void * minisym, |
2632 | | asymbol *sym) |
2633 | 65.8M | { |
2634 | 65.8M | if (dynamic |
2635 | 65.8M | || obj_aout_external_sym_count (abfd) < MINISYM_THRESHOLD) |
2636 | 20.2k | return _bfd_generic_minisymbol_to_symbol (abfd, dynamic, minisym, sym); |
2637 | | |
2638 | 65.8M | memset (sym, 0, sizeof (aout_symbol_type)); |
2639 | | |
2640 | | /* We call translate_symbol_table to translate a single symbol. */ |
2641 | 65.8M | if (! (NAME (aout, translate_symbol_table) |
2642 | 65.8M | (abfd, |
2643 | 65.8M | (aout_symbol_type *) sym, |
2644 | 65.8M | (struct external_nlist *) minisym, |
2645 | 65.8M | (bfd_size_type) 1, |
2646 | 65.8M | obj_aout_external_strings (abfd), |
2647 | 65.8M | obj_aout_external_string_size (abfd), |
2648 | 65.8M | false))) |
2649 | 2.99M | return NULL; |
2650 | | |
2651 | 62.8M | return sym; |
2652 | 65.8M | } Unexecuted instantiation: cris_aout_32_minisymbol_to_symbol ns32kaout_32_minisymbol_to_symbol Line | Count | Source | 2633 | 37.5M | { | 2634 | 37.5M | if (dynamic | 2635 | 37.5M | || obj_aout_external_sym_count (abfd) < MINISYM_THRESHOLD) | 2636 | 11.3k | return _bfd_generic_minisymbol_to_symbol (abfd, dynamic, minisym, sym); | 2637 | | | 2638 | 37.5M | memset (sym, 0, sizeof (aout_symbol_type)); | 2639 | | | 2640 | | /* We call translate_symbol_table to translate a single symbol. */ | 2641 | 37.5M | if (! (NAME (aout, translate_symbol_table) | 2642 | 37.5M | (abfd, | 2643 | 37.5M | (aout_symbol_type *) sym, | 2644 | 37.5M | (struct external_nlist *) minisym, | 2645 | 37.5M | (bfd_size_type) 1, | 2646 | 37.5M | obj_aout_external_strings (abfd), | 2647 | 37.5M | obj_aout_external_string_size (abfd), | 2648 | 37.5M | false))) | 2649 | 1.48M | return NULL; | 2650 | | | 2651 | 36.0M | return sym; | 2652 | 37.5M | } |
aout_32_minisymbol_to_symbol Line | Count | Source | 2633 | 28.2M | { | 2634 | 28.2M | if (dynamic | 2635 | 28.2M | || obj_aout_external_sym_count (abfd) < MINISYM_THRESHOLD) | 2636 | 8.89k | return _bfd_generic_minisymbol_to_symbol (abfd, dynamic, minisym, sym); | 2637 | | | 2638 | 28.2M | memset (sym, 0, sizeof (aout_symbol_type)); | 2639 | | | 2640 | | /* We call translate_symbol_table to translate a single symbol. */ | 2641 | 28.2M | if (! (NAME (aout, translate_symbol_table) | 2642 | 28.2M | (abfd, | 2643 | 28.2M | (aout_symbol_type *) sym, | 2644 | 28.2M | (struct external_nlist *) minisym, | 2645 | 28.2M | (bfd_size_type) 1, | 2646 | 28.2M | obj_aout_external_strings (abfd), | 2647 | 28.2M | obj_aout_external_string_size (abfd), | 2648 | 28.2M | false))) | 2649 | 1.50M | return NULL; | 2650 | | | 2651 | 26.7M | return sym; | 2652 | 28.2M | } |
|
2653 | | |
2654 | | /* Provided a BFD, a section and an offset into the section, calculate |
2655 | | and return the name of the source file and the line nearest to the |
2656 | | wanted location. */ |
2657 | | |
2658 | | bool |
2659 | | NAME (aout, find_nearest_line) (bfd *abfd, |
2660 | | asymbol **symbols, |
2661 | | asection *section, |
2662 | | bfd_vma offset, |
2663 | | const char **filename_ptr, |
2664 | | const char **functionname_ptr, |
2665 | | unsigned int *line_ptr, |
2666 | | unsigned int *disriminator_ptr) |
2667 | 2.45k | { |
2668 | | /* Run down the file looking for the filename, function and linenumber. */ |
2669 | 2.45k | asymbol **p; |
2670 | 2.45k | const char *directory_name = NULL; |
2671 | 2.45k | const char *main_file_name = NULL; |
2672 | 2.45k | const char *current_file_name = NULL; |
2673 | 2.45k | const char *line_file_name = NULL; /* Value of current_file_name at line number. */ |
2674 | 2.45k | const char *line_directory_name = NULL; /* Value of directory_name at line number. */ |
2675 | 2.45k | bfd_vma low_line_vma = 0; |
2676 | 2.45k | bfd_vma low_func_vma = 0; |
2677 | 2.45k | asymbol *func = 0; |
2678 | 2.45k | bfd_size_type filelen, funclen; |
2679 | 2.45k | char *buf; |
2680 | | |
2681 | 2.45k | *filename_ptr = bfd_get_filename (abfd); |
2682 | 2.45k | *functionname_ptr = NULL; |
2683 | 2.45k | *line_ptr = 0; |
2684 | 2.45k | if (disriminator_ptr) |
2685 | 1.89k | *disriminator_ptr = 0; |
2686 | | |
2687 | 2.45k | if (symbols != NULL) |
2688 | 1.80k | { |
2689 | 15.8k | for (p = symbols; *p; p++) |
2690 | 14.8k | { |
2691 | 14.8k | aout_symbol_type *q = (aout_symbol_type *) (*p); |
2692 | 15.8k | next: |
2693 | 15.8k | switch (q->type) |
2694 | 15.8k | { |
2695 | 1.60k | case N_TEXT: |
2696 | | /* If this looks like a file name symbol, and it comes after |
2697 | | the line number we have found so far, but before the |
2698 | | offset, then we have probably not found the right line |
2699 | | number. */ |
2700 | 1.60k | if (q->symbol.value <= offset |
2701 | 1.60k | && ((q->symbol.value > low_line_vma |
2702 | 1.11k | && (line_file_name != NULL |
2703 | 842 | || *line_ptr != 0)) |
2704 | 1.11k | || (q->symbol.value > low_func_vma |
2705 | 932 | && func != NULL))) |
2706 | 396 | { |
2707 | 396 | const char *symname; |
2708 | | |
2709 | 396 | symname = q->symbol.name; |
2710 | | |
2711 | 396 | if (symname != NULL |
2712 | 396 | && strlen (symname) > 2 |
2713 | 396 | && strcmp (symname + strlen (symname) - 2, ".o") == 0) |
2714 | 0 | { |
2715 | 0 | if (q->symbol.value > low_line_vma) |
2716 | 0 | { |
2717 | 0 | *line_ptr = 0; |
2718 | 0 | line_file_name = NULL; |
2719 | 0 | } |
2720 | 0 | if (q->symbol.value > low_func_vma) |
2721 | 0 | func = NULL; |
2722 | 0 | } |
2723 | 396 | } |
2724 | 1.60k | break; |
2725 | | |
2726 | 1.55k | case N_SO: |
2727 | | /* If this symbol is less than the offset, but greater than |
2728 | | the line number we have found so far, then we have not |
2729 | | found the right line number. */ |
2730 | 1.55k | if (q->symbol.value <= offset) |
2731 | 1.00k | { |
2732 | 1.00k | if (q->symbol.value > low_line_vma) |
2733 | 776 | { |
2734 | 776 | *line_ptr = 0; |
2735 | 776 | line_file_name = NULL; |
2736 | 776 | } |
2737 | 1.00k | if (q->symbol.value > low_func_vma) |
2738 | 762 | func = NULL; |
2739 | 1.00k | } |
2740 | | |
2741 | 1.55k | main_file_name = current_file_name = q->symbol.name; |
2742 | | /* Look ahead to next symbol to check if that too is an N_SO. */ |
2743 | 1.55k | p++; |
2744 | 1.55k | if (*p == NULL) |
2745 | 431 | goto done; |
2746 | 1.12k | q = (aout_symbol_type *) (*p); |
2747 | 1.12k | if (q->type != (int)N_SO) |
2748 | 1.01k | goto next; |
2749 | | |
2750 | | /* Found a second N_SO First is directory; second is filename. */ |
2751 | 110 | directory_name = current_file_name; |
2752 | 110 | main_file_name = current_file_name = q->symbol.name; |
2753 | 110 | if (obj_textsec (abfd) != section) |
2754 | 70 | goto done; |
2755 | 40 | break; |
2756 | 83 | case N_SOL: |
2757 | 83 | current_file_name = q->symbol.name; |
2758 | 83 | break; |
2759 | | |
2760 | 375 | case N_SLINE: |
2761 | | |
2762 | 786 | case N_DSLINE: |
2763 | 1.13k | case N_BSLINE: |
2764 | | /* We'll keep this if it resolves nearer than the one we have |
2765 | | already. */ |
2766 | 1.13k | if (q->symbol.value >= low_line_vma |
2767 | 1.13k | && q->symbol.value <= offset) |
2768 | 566 | { |
2769 | 566 | *line_ptr = q->desc; |
2770 | 566 | low_line_vma = q->symbol.value; |
2771 | 566 | line_file_name = current_file_name; |
2772 | 566 | line_directory_name = directory_name; |
2773 | 566 | } |
2774 | 1.13k | break; |
2775 | 821 | case N_FUN: |
2776 | 821 | { |
2777 | | /* We'll keep this if it is nearer than the one we have already. */ |
2778 | 821 | if (q->symbol.value >= low_func_vma |
2779 | 821 | && q->symbol.value <= offset) |
2780 | 470 | { |
2781 | 470 | low_func_vma = q->symbol.value; |
2782 | 470 | func = (asymbol *)q; |
2783 | 470 | } |
2784 | 351 | else if (q->symbol.value > offset) |
2785 | 255 | goto done; |
2786 | 821 | } |
2787 | 566 | break; |
2788 | 15.8k | } |
2789 | 15.8k | } |
2790 | 1.80k | } |
2791 | | |
2792 | 2.45k | done: |
2793 | 2.45k | if (*line_ptr != 0) |
2794 | 312 | { |
2795 | 312 | main_file_name = line_file_name; |
2796 | 312 | directory_name = line_directory_name; |
2797 | 312 | } |
2798 | | |
2799 | 2.45k | if (main_file_name == NULL |
2800 | 2.45k | || IS_ABSOLUTE_PATH (main_file_name) |
2801 | 2.45k | || directory_name == NULL) |
2802 | 2.34k | filelen = 0; |
2803 | 106 | else |
2804 | 106 | filelen = strlen (directory_name) + strlen (main_file_name); |
2805 | | |
2806 | 2.45k | if (func == NULL) |
2807 | 2.07k | funclen = 0; |
2808 | 374 | else |
2809 | 374 | funclen = strlen (bfd_asymbol_name (func)); |
2810 | | |
2811 | 2.45k | free (adata (abfd).line_buf); |
2812 | | |
2813 | 2.45k | if (filelen + funclen == 0) |
2814 | 2.26k | adata (abfd).line_buf = buf = NULL; |
2815 | 192 | else |
2816 | 192 | { |
2817 | 192 | buf = (char *) bfd_malloc (filelen + funclen + 3); |
2818 | 192 | adata (abfd).line_buf = buf; |
2819 | 192 | if (buf == NULL) |
2820 | 0 | return false; |
2821 | 192 | } |
2822 | | |
2823 | 2.45k | if (main_file_name != NULL) |
2824 | 817 | { |
2825 | 817 | if (IS_ABSOLUTE_PATH (main_file_name) || directory_name == NULL) |
2826 | 711 | *filename_ptr = main_file_name; |
2827 | 106 | else |
2828 | 106 | { |
2829 | 106 | if (buf == NULL) |
2830 | | /* PR binutils/20891: In a corrupt input file both |
2831 | | main_file_name and directory_name can be empty... */ |
2832 | 62 | * filename_ptr = NULL; |
2833 | 44 | else |
2834 | 44 | { |
2835 | 44 | snprintf (buf, filelen + 1, "%s%s", directory_name, |
2836 | 44 | main_file_name); |
2837 | 44 | *filename_ptr = buf; |
2838 | 44 | buf += filelen + 1; |
2839 | 44 | } |
2840 | 106 | } |
2841 | 817 | } |
2842 | | |
2843 | 2.45k | if (func) |
2844 | 374 | { |
2845 | 374 | const char *function = func->name; |
2846 | 374 | char *colon; |
2847 | | |
2848 | 374 | if (buf == NULL) |
2849 | 217 | { |
2850 | | /* PR binutils/20892: In a corrupt input file func can be empty. */ |
2851 | 217 | * functionname_ptr = NULL; |
2852 | 217 | return true; |
2853 | 217 | } |
2854 | | /* The caller expects a symbol name. We actually have a |
2855 | | function name, without the leading underscore. Put the |
2856 | | underscore back in, so that the caller gets a symbol name. */ |
2857 | 157 | if (bfd_get_symbol_leading_char (abfd) == '\0') |
2858 | 0 | strcpy (buf, function); |
2859 | 157 | else |
2860 | 157 | { |
2861 | 157 | buf[0] = bfd_get_symbol_leading_char (abfd); |
2862 | 157 | strcpy (buf + 1, function); |
2863 | 157 | } |
2864 | | /* Have to remove : stuff. */ |
2865 | 157 | colon = strchr (buf, ':'); |
2866 | 157 | if (colon != NULL) |
2867 | 44 | *colon = '\0'; |
2868 | 157 | *functionname_ptr = buf; |
2869 | 157 | } |
2870 | | |
2871 | 2.23k | return true; |
2872 | 2.45k | } Unexecuted instantiation: cris_aout_32_find_nearest_line ns32kaout_32_find_nearest_line Line | Count | Source | 2667 | 1.20k | { | 2668 | | /* Run down the file looking for the filename, function and linenumber. */ | 2669 | 1.20k | asymbol **p; | 2670 | 1.20k | const char *directory_name = NULL; | 2671 | 1.20k | const char *main_file_name = NULL; | 2672 | 1.20k | const char *current_file_name = NULL; | 2673 | 1.20k | const char *line_file_name = NULL; /* Value of current_file_name at line number. */ | 2674 | 1.20k | const char *line_directory_name = NULL; /* Value of directory_name at line number. */ | 2675 | 1.20k | bfd_vma low_line_vma = 0; | 2676 | 1.20k | bfd_vma low_func_vma = 0; | 2677 | 1.20k | asymbol *func = 0; | 2678 | 1.20k | bfd_size_type filelen, funclen; | 2679 | 1.20k | char *buf; | 2680 | | | 2681 | 1.20k | *filename_ptr = bfd_get_filename (abfd); | 2682 | 1.20k | *functionname_ptr = NULL; | 2683 | 1.20k | *line_ptr = 0; | 2684 | 1.20k | if (disriminator_ptr) | 2685 | 953 | *disriminator_ptr = 0; | 2686 | | | 2687 | 1.20k | if (symbols != NULL) | 2688 | 905 | { | 2689 | 7.26k | for (p = symbols; *p; p++) | 2690 | 6.72k | { | 2691 | 6.72k | aout_symbol_type *q = (aout_symbol_type *) (*p); | 2692 | 6.98k | next: | 2693 | 6.98k | switch (q->type) | 2694 | 6.98k | { | 2695 | 581 | case N_TEXT: | 2696 | | /* If this looks like a file name symbol, and it comes after | 2697 | | the line number we have found so far, but before the | 2698 | | offset, then we have probably not found the right line | 2699 | | number. */ | 2700 | 581 | if (q->symbol.value <= offset | 2701 | 581 | && ((q->symbol.value > low_line_vma | 2702 | 389 | && (line_file_name != NULL | 2703 | 312 | || *line_ptr != 0)) | 2704 | 389 | || (q->symbol.value > low_func_vma | 2705 | 330 | && func != NULL))) | 2706 | 90 | { | 2707 | 90 | const char *symname; | 2708 | | | 2709 | 90 | symname = q->symbol.name; | 2710 | | | 2711 | 90 | if (symname != NULL | 2712 | 90 | && strlen (symname) > 2 | 2713 | 90 | && strcmp (symname + strlen (symname) - 2, ".o") == 0) | 2714 | 0 | { | 2715 | 0 | if (q->symbol.value > low_line_vma) | 2716 | 0 | { | 2717 | 0 | *line_ptr = 0; | 2718 | 0 | line_file_name = NULL; | 2719 | 0 | } | 2720 | 0 | if (q->symbol.value > low_func_vma) | 2721 | 0 | func = NULL; | 2722 | 0 | } | 2723 | 90 | } | 2724 | 581 | break; | 2725 | | | 2726 | 482 | case N_SO: | 2727 | | /* If this symbol is less than the offset, but greater than | 2728 | | the line number we have found so far, then we have not | 2729 | | found the right line number. */ | 2730 | 482 | if (q->symbol.value <= offset) | 2731 | 297 | { | 2732 | 297 | if (q->symbol.value > low_line_vma) | 2733 | 235 | { | 2734 | 235 | *line_ptr = 0; | 2735 | 235 | line_file_name = NULL; | 2736 | 235 | } | 2737 | 297 | if (q->symbol.value > low_func_vma) | 2738 | 268 | func = NULL; | 2739 | 297 | } | 2740 | | | 2741 | 482 | main_file_name = current_file_name = q->symbol.name; | 2742 | | /* Look ahead to next symbol to check if that too is an N_SO. */ | 2743 | 482 | p++; | 2744 | 482 | if (*p == NULL) | 2745 | 200 | goto done; | 2746 | 282 | q = (aout_symbol_type *) (*p); | 2747 | 282 | if (q->type != (int)N_SO) | 2748 | 257 | goto next; | 2749 | | | 2750 | | /* Found a second N_SO First is directory; second is filename. */ | 2751 | 25 | directory_name = current_file_name; | 2752 | 25 | main_file_name = current_file_name = q->symbol.name; | 2753 | 25 | if (obj_textsec (abfd) != section) | 2754 | 12 | goto done; | 2755 | 13 | break; | 2756 | 29 | case N_SOL: | 2757 | 29 | current_file_name = q->symbol.name; | 2758 | 29 | break; | 2759 | | | 2760 | 257 | case N_SLINE: | 2761 | | | 2762 | 497 | case N_DSLINE: | 2763 | 665 | case N_BSLINE: | 2764 | | /* We'll keep this if it resolves nearer than the one we have | 2765 | | already. */ | 2766 | 665 | if (q->symbol.value >= low_line_vma | 2767 | 665 | && q->symbol.value <= offset) | 2768 | 295 | { | 2769 | 295 | *line_ptr = q->desc; | 2770 | 295 | low_line_vma = q->symbol.value; | 2771 | 295 | line_file_name = current_file_name; | 2772 | 295 | line_directory_name = directory_name; | 2773 | 295 | } | 2774 | 665 | break; | 2775 | 384 | case N_FUN: | 2776 | 384 | { | 2777 | | /* We'll keep this if it is nearer than the one we have already. */ | 2778 | 384 | if (q->symbol.value >= low_func_vma | 2779 | 384 | && q->symbol.value <= offset) | 2780 | 195 | { | 2781 | 195 | low_func_vma = q->symbol.value; | 2782 | 195 | func = (asymbol *)q; | 2783 | 195 | } | 2784 | 189 | else if (q->symbol.value > offset) | 2785 | 150 | goto done; | 2786 | 384 | } | 2787 | 234 | break; | 2788 | 6.98k | } | 2789 | 6.98k | } | 2790 | 905 | } | 2791 | | | 2792 | 1.20k | done: | 2793 | 1.20k | if (*line_ptr != 0) | 2794 | 160 | { | 2795 | 160 | main_file_name = line_file_name; | 2796 | 160 | directory_name = line_directory_name; | 2797 | 160 | } | 2798 | | | 2799 | 1.20k | if (main_file_name == NULL | 2800 | 1.20k | || IS_ABSOLUTE_PATH (main_file_name) | 2801 | 1.20k | || directory_name == NULL) | 2802 | 1.18k | filelen = 0; | 2803 | 23 | else | 2804 | 23 | filelen = strlen (directory_name) + strlen (main_file_name); | 2805 | | | 2806 | 1.20k | if (func == NULL) | 2807 | 1.02k | funclen = 0; | 2808 | 181 | else | 2809 | 181 | funclen = strlen (bfd_asymbol_name (func)); | 2810 | | | 2811 | 1.20k | free (adata (abfd).line_buf); | 2812 | | | 2813 | 1.20k | if (filelen + funclen == 0) | 2814 | 1.13k | adata (abfd).line_buf = buf = NULL; | 2815 | 73 | else | 2816 | 73 | { | 2817 | 73 | buf = (char *) bfd_malloc (filelen + funclen + 3); | 2818 | 73 | adata (abfd).line_buf = buf; | 2819 | 73 | if (buf == NULL) | 2820 | 0 | return false; | 2821 | 73 | } | 2822 | | | 2823 | 1.20k | if (main_file_name != NULL) | 2824 | 307 | { | 2825 | 307 | if (IS_ABSOLUTE_PATH (main_file_name) || directory_name == NULL) | 2826 | 284 | *filename_ptr = main_file_name; | 2827 | 23 | else | 2828 | 23 | { | 2829 | 23 | if (buf == NULL) | 2830 | | /* PR binutils/20891: In a corrupt input file both | 2831 | | main_file_name and directory_name can be empty... */ | 2832 | 15 | * filename_ptr = NULL; | 2833 | 8 | else | 2834 | 8 | { | 2835 | 8 | snprintf (buf, filelen + 1, "%s%s", directory_name, | 2836 | 8 | main_file_name); | 2837 | 8 | *filename_ptr = buf; | 2838 | 8 | buf += filelen + 1; | 2839 | 8 | } | 2840 | 23 | } | 2841 | 307 | } | 2842 | | | 2843 | 1.20k | if (func) | 2844 | 181 | { | 2845 | 181 | const char *function = func->name; | 2846 | 181 | char *colon; | 2847 | | | 2848 | 181 | if (buf == NULL) | 2849 | 115 | { | 2850 | | /* PR binutils/20892: In a corrupt input file func can be empty. */ | 2851 | 115 | * functionname_ptr = NULL; | 2852 | 115 | return true; | 2853 | 115 | } | 2854 | | /* The caller expects a symbol name. We actually have a | 2855 | | function name, without the leading underscore. Put the | 2856 | | underscore back in, so that the caller gets a symbol name. */ | 2857 | 66 | if (bfd_get_symbol_leading_char (abfd) == '\0') | 2858 | 0 | strcpy (buf, function); | 2859 | 66 | else | 2860 | 66 | { | 2861 | 66 | buf[0] = bfd_get_symbol_leading_char (abfd); | 2862 | 66 | strcpy (buf + 1, function); | 2863 | 66 | } | 2864 | | /* Have to remove : stuff. */ | 2865 | 66 | colon = strchr (buf, ':'); | 2866 | 66 | if (colon != NULL) | 2867 | 23 | *colon = '\0'; | 2868 | 66 | *functionname_ptr = buf; | 2869 | 66 | } | 2870 | | | 2871 | 1.09k | return true; | 2872 | 1.20k | } |
aout_32_find_nearest_line Line | Count | Source | 2667 | 1.24k | { | 2668 | | /* Run down the file looking for the filename, function and linenumber. */ | 2669 | 1.24k | asymbol **p; | 2670 | 1.24k | const char *directory_name = NULL; | 2671 | 1.24k | const char *main_file_name = NULL; | 2672 | 1.24k | const char *current_file_name = NULL; | 2673 | 1.24k | const char *line_file_name = NULL; /* Value of current_file_name at line number. */ | 2674 | 1.24k | const char *line_directory_name = NULL; /* Value of directory_name at line number. */ | 2675 | 1.24k | bfd_vma low_line_vma = 0; | 2676 | 1.24k | bfd_vma low_func_vma = 0; | 2677 | 1.24k | asymbol *func = 0; | 2678 | 1.24k | bfd_size_type filelen, funclen; | 2679 | 1.24k | char *buf; | 2680 | | | 2681 | 1.24k | *filename_ptr = bfd_get_filename (abfd); | 2682 | 1.24k | *functionname_ptr = NULL; | 2683 | 1.24k | *line_ptr = 0; | 2684 | 1.24k | if (disriminator_ptr) | 2685 | 943 | *disriminator_ptr = 0; | 2686 | | | 2687 | 1.24k | if (symbols != NULL) | 2688 | 904 | { | 2689 | 8.59k | for (p = symbols; *p; p++) | 2690 | 8.08k | { | 2691 | 8.08k | aout_symbol_type *q = (aout_symbol_type *) (*p); | 2692 | 8.83k | next: | 2693 | 8.83k | switch (q->type) | 2694 | 8.83k | { | 2695 | 1.02k | case N_TEXT: | 2696 | | /* If this looks like a file name symbol, and it comes after | 2697 | | the line number we have found so far, but before the | 2698 | | offset, then we have probably not found the right line | 2699 | | number. */ | 2700 | 1.02k | if (q->symbol.value <= offset | 2701 | 1.02k | && ((q->symbol.value > low_line_vma | 2702 | 724 | && (line_file_name != NULL | 2703 | 530 | || *line_ptr != 0)) | 2704 | 724 | || (q->symbol.value > low_func_vma | 2705 | 602 | && func != NULL))) | 2706 | 306 | { | 2707 | 306 | const char *symname; | 2708 | | | 2709 | 306 | symname = q->symbol.name; | 2710 | | | 2711 | 306 | if (symname != NULL | 2712 | 306 | && strlen (symname) > 2 | 2713 | 306 | && strcmp (symname + strlen (symname) - 2, ".o") == 0) | 2714 | 0 | { | 2715 | 0 | if (q->symbol.value > low_line_vma) | 2716 | 0 | { | 2717 | 0 | *line_ptr = 0; | 2718 | 0 | line_file_name = NULL; | 2719 | 0 | } | 2720 | 0 | if (q->symbol.value > low_func_vma) | 2721 | 0 | func = NULL; | 2722 | 0 | } | 2723 | 306 | } | 2724 | 1.02k | break; | 2725 | | | 2726 | 1.06k | case N_SO: | 2727 | | /* If this symbol is less than the offset, but greater than | 2728 | | the line number we have found so far, then we have not | 2729 | | found the right line number. */ | 2730 | 1.06k | if (q->symbol.value <= offset) | 2731 | 707 | { | 2732 | 707 | if (q->symbol.value > low_line_vma) | 2733 | 541 | { | 2734 | 541 | *line_ptr = 0; | 2735 | 541 | line_file_name = NULL; | 2736 | 541 | } | 2737 | 707 | if (q->symbol.value > low_func_vma) | 2738 | 494 | func = NULL; | 2739 | 707 | } | 2740 | | | 2741 | 1.06k | main_file_name = current_file_name = q->symbol.name; | 2742 | | /* Look ahead to next symbol to check if that too is an N_SO. */ | 2743 | 1.06k | p++; | 2744 | 1.06k | if (*p == NULL) | 2745 | 231 | goto done; | 2746 | 838 | q = (aout_symbol_type *) (*p); | 2747 | 838 | if (q->type != (int)N_SO) | 2748 | 753 | goto next; | 2749 | | | 2750 | | /* Found a second N_SO First is directory; second is filename. */ | 2751 | 85 | directory_name = current_file_name; | 2752 | 85 | main_file_name = current_file_name = q->symbol.name; | 2753 | 85 | if (obj_textsec (abfd) != section) | 2754 | 58 | goto done; | 2755 | 27 | break; | 2756 | 54 | case N_SOL: | 2757 | 54 | current_file_name = q->symbol.name; | 2758 | 54 | break; | 2759 | | | 2760 | 118 | case N_SLINE: | 2761 | | | 2762 | 289 | case N_DSLINE: | 2763 | 474 | case N_BSLINE: | 2764 | | /* We'll keep this if it resolves nearer than the one we have | 2765 | | already. */ | 2766 | 474 | if (q->symbol.value >= low_line_vma | 2767 | 474 | && q->symbol.value <= offset) | 2768 | 271 | { | 2769 | 271 | *line_ptr = q->desc; | 2770 | 271 | low_line_vma = q->symbol.value; | 2771 | 271 | line_file_name = current_file_name; | 2772 | 271 | line_directory_name = directory_name; | 2773 | 271 | } | 2774 | 474 | break; | 2775 | 437 | case N_FUN: | 2776 | 437 | { | 2777 | | /* We'll keep this if it is nearer than the one we have already. */ | 2778 | 437 | if (q->symbol.value >= low_func_vma | 2779 | 437 | && q->symbol.value <= offset) | 2780 | 275 | { | 2781 | 275 | low_func_vma = q->symbol.value; | 2782 | 275 | func = (asymbol *)q; | 2783 | 275 | } | 2784 | 162 | else if (q->symbol.value > offset) | 2785 | 105 | goto done; | 2786 | 437 | } | 2787 | 332 | break; | 2788 | 8.83k | } | 2789 | 8.83k | } | 2790 | 904 | } | 2791 | | | 2792 | 1.24k | done: | 2793 | 1.24k | if (*line_ptr != 0) | 2794 | 152 | { | 2795 | 152 | main_file_name = line_file_name; | 2796 | 152 | directory_name = line_directory_name; | 2797 | 152 | } | 2798 | | | 2799 | 1.24k | if (main_file_name == NULL | 2800 | 1.24k | || IS_ABSOLUTE_PATH (main_file_name) | 2801 | 1.24k | || directory_name == NULL) | 2802 | 1.16k | filelen = 0; | 2803 | 83 | else | 2804 | 83 | filelen = strlen (directory_name) + strlen (main_file_name); | 2805 | | | 2806 | 1.24k | if (func == NULL) | 2807 | 1.05k | funclen = 0; | 2808 | 193 | else | 2809 | 193 | funclen = strlen (bfd_asymbol_name (func)); | 2810 | | | 2811 | 1.24k | free (adata (abfd).line_buf); | 2812 | | | 2813 | 1.24k | if (filelen + funclen == 0) | 2814 | 1.12k | adata (abfd).line_buf = buf = NULL; | 2815 | 119 | else | 2816 | 119 | { | 2817 | 119 | buf = (char *) bfd_malloc (filelen + funclen + 3); | 2818 | 119 | adata (abfd).line_buf = buf; | 2819 | 119 | if (buf == NULL) | 2820 | 0 | return false; | 2821 | 119 | } | 2822 | | | 2823 | 1.24k | if (main_file_name != NULL) | 2824 | 510 | { | 2825 | 510 | if (IS_ABSOLUTE_PATH (main_file_name) || directory_name == NULL) | 2826 | 427 | *filename_ptr = main_file_name; | 2827 | 83 | else | 2828 | 83 | { | 2829 | 83 | if (buf == NULL) | 2830 | | /* PR binutils/20891: In a corrupt input file both | 2831 | | main_file_name and directory_name can be empty... */ | 2832 | 47 | * filename_ptr = NULL; | 2833 | 36 | else | 2834 | 36 | { | 2835 | 36 | snprintf (buf, filelen + 1, "%s%s", directory_name, | 2836 | 36 | main_file_name); | 2837 | 36 | *filename_ptr = buf; | 2838 | 36 | buf += filelen + 1; | 2839 | 36 | } | 2840 | 83 | } | 2841 | 510 | } | 2842 | | | 2843 | 1.24k | if (func) | 2844 | 193 | { | 2845 | 193 | const char *function = func->name; | 2846 | 193 | char *colon; | 2847 | | | 2848 | 193 | if (buf == NULL) | 2849 | 102 | { | 2850 | | /* PR binutils/20892: In a corrupt input file func can be empty. */ | 2851 | 102 | * functionname_ptr = NULL; | 2852 | 102 | return true; | 2853 | 102 | } | 2854 | | /* The caller expects a symbol name. We actually have a | 2855 | | function name, without the leading underscore. Put the | 2856 | | underscore back in, so that the caller gets a symbol name. */ | 2857 | 91 | if (bfd_get_symbol_leading_char (abfd) == '\0') | 2858 | 0 | strcpy (buf, function); | 2859 | 91 | else | 2860 | 91 | { | 2861 | 91 | buf[0] = bfd_get_symbol_leading_char (abfd); | 2862 | 91 | strcpy (buf + 1, function); | 2863 | 91 | } | 2864 | | /* Have to remove : stuff. */ | 2865 | 91 | colon = strchr (buf, ':'); | 2866 | 91 | if (colon != NULL) | 2867 | 21 | *colon = '\0'; | 2868 | 91 | *functionname_ptr = buf; | 2869 | 91 | } | 2870 | | | 2871 | 1.14k | return true; | 2872 | 1.24k | } |
|
2873 | | |
2874 | | int |
2875 | | NAME (aout, sizeof_headers) (bfd *abfd, |
2876 | | struct bfd_link_info *info ATTRIBUTE_UNUSED) |
2877 | 0 | { |
2878 | 0 | return adata (abfd).exec_bytes_size; |
2879 | 0 | } Unexecuted instantiation: cris_aout_32_sizeof_headers Unexecuted instantiation: ns32kaout_32_sizeof_headers Unexecuted instantiation: aout_32_sizeof_headers |
2880 | | |
2881 | | /* Throw away most malloc'd and alloc'd information for this BFD. */ |
2882 | | |
2883 | | bool |
2884 | | NAME (aout, bfd_free_cached_info) (bfd *abfd) |
2885 | 19.4k | { |
2886 | 19.4k | if ((bfd_get_format (abfd) == bfd_object |
2887 | 19.4k | || bfd_get_format (abfd) == bfd_core) |
2888 | 19.4k | && abfd->tdata.aout_data != NULL) |
2889 | 19.4k | { |
2890 | 135k | #define BFCI_FREE(x) do { free (x); x = NULL; } while (0) |
2891 | 19.4k | BFCI_FREE (adata (abfd).line_buf); |
2892 | 19.4k | BFCI_FREE (obj_aout_symbols (abfd)); |
2893 | 19.4k | BFCI_FREE (obj_aout_external_syms (abfd)); |
2894 | 19.4k | BFCI_FREE (obj_aout_external_strings (abfd)); |
2895 | 77.6k | for (asection *o = abfd->sections; o != NULL; o = o->next) |
2896 | 58.2k | BFCI_FREE (o->relocation); |
2897 | 19.4k | #undef BFCI_FREE |
2898 | 19.4k | } |
2899 | | |
2900 | 19.4k | return _bfd_generic_bfd_free_cached_info (abfd); |
2901 | 19.4k | } Unexecuted instantiation: cris_aout_32_bfd_free_cached_info ns32kaout_32_bfd_free_cached_info Line | Count | Source | 2885 | 8.54k | { | 2886 | 8.54k | if ((bfd_get_format (abfd) == bfd_object | 2887 | 8.54k | || bfd_get_format (abfd) == bfd_core) | 2888 | 8.54k | && abfd->tdata.aout_data != NULL) | 2889 | 8.54k | { | 2890 | 8.54k | #define BFCI_FREE(x) do { free (x); x = NULL; } while (0) | 2891 | 8.54k | BFCI_FREE (adata (abfd).line_buf); | 2892 | 8.54k | BFCI_FREE (obj_aout_symbols (abfd)); | 2893 | 8.54k | BFCI_FREE (obj_aout_external_syms (abfd)); | 2894 | 8.54k | BFCI_FREE (obj_aout_external_strings (abfd)); | 2895 | 34.1k | for (asection *o = abfd->sections; o != NULL; o = o->next) | 2896 | 25.6k | BFCI_FREE (o->relocation); | 2897 | 8.54k | #undef BFCI_FREE | 2898 | 8.54k | } | 2899 | | | 2900 | 8.54k | return _bfd_generic_bfd_free_cached_info (abfd); | 2901 | 8.54k | } |
aout_32_bfd_free_cached_info Line | Count | Source | 2885 | 10.8k | { | 2886 | 10.8k | if ((bfd_get_format (abfd) == bfd_object | 2887 | 10.8k | || bfd_get_format (abfd) == bfd_core) | 2888 | 10.8k | && abfd->tdata.aout_data != NULL) | 2889 | 10.8k | { | 2890 | 10.8k | #define BFCI_FREE(x) do { free (x); x = NULL; } while (0) | 2891 | 10.8k | BFCI_FREE (adata (abfd).line_buf); | 2892 | 10.8k | BFCI_FREE (obj_aout_symbols (abfd)); | 2893 | 10.8k | BFCI_FREE (obj_aout_external_syms (abfd)); | 2894 | 10.8k | BFCI_FREE (obj_aout_external_strings (abfd)); | 2895 | 43.5k | for (asection *o = abfd->sections; o != NULL; o = o->next) | 2896 | 32.6k | BFCI_FREE (o->relocation); | 2897 | 10.8k | #undef BFCI_FREE | 2898 | 10.8k | } | 2899 | | | 2900 | 10.8k | return _bfd_generic_bfd_free_cached_info (abfd); | 2901 | 10.8k | } |
|
2902 | | |
2903 | | /* a.out link code. */ |
2904 | | |
2905 | | /* Routine to create an entry in an a.out link hash table. */ |
2906 | | |
2907 | | struct bfd_hash_entry * |
2908 | | NAME (aout, link_hash_newfunc) (struct bfd_hash_entry *entry, |
2909 | | struct bfd_hash_table *table, |
2910 | | const char *string) |
2911 | 0 | { |
2912 | 0 | struct aout_link_hash_entry *ret = (struct aout_link_hash_entry *) entry; |
2913 | | |
2914 | | /* Allocate the structure if it has not already been allocated by a |
2915 | | subclass. */ |
2916 | 0 | if (ret == NULL) |
2917 | 0 | ret = (struct aout_link_hash_entry *) bfd_hash_allocate (table, |
2918 | 0 | sizeof (* ret)); |
2919 | 0 | if (ret == NULL) |
2920 | 0 | return NULL; |
2921 | | |
2922 | | /* Call the allocation method of the superclass. */ |
2923 | 0 | ret = ((struct aout_link_hash_entry *) |
2924 | 0 | _bfd_link_hash_newfunc ((struct bfd_hash_entry *) ret, |
2925 | 0 | table, string)); |
2926 | 0 | if (ret) |
2927 | 0 | { |
2928 | | /* Set local fields. */ |
2929 | 0 | ret->written = false; |
2930 | 0 | ret->indx = -1; |
2931 | 0 | } |
2932 | |
|
2933 | 0 | return (struct bfd_hash_entry *) ret; |
2934 | 0 | } Unexecuted instantiation: cris_aout_32_link_hash_newfunc Unexecuted instantiation: ns32kaout_32_link_hash_newfunc Unexecuted instantiation: aout_32_link_hash_newfunc |
2935 | | |
2936 | | /* Initialize an a.out link hash table. */ |
2937 | | |
2938 | | bool |
2939 | | NAME (aout, link_hash_table_init) (struct aout_link_hash_table *table, |
2940 | | bfd *abfd, |
2941 | | struct bfd_hash_entry *(*newfunc) |
2942 | | (struct bfd_hash_entry *, struct bfd_hash_table *, |
2943 | | const char *), |
2944 | | unsigned int entsize) |
2945 | 0 | { |
2946 | 0 | return _bfd_link_hash_table_init (&table->root, abfd, newfunc, entsize); |
2947 | 0 | } Unexecuted instantiation: cris_aout_32_link_hash_table_init Unexecuted instantiation: ns32kaout_32_link_hash_table_init Unexecuted instantiation: aout_32_link_hash_table_init |
2948 | | |
2949 | | /* Create an a.out link hash table. */ |
2950 | | |
2951 | | struct bfd_link_hash_table * |
2952 | | NAME (aout, link_hash_table_create) (bfd *abfd) |
2953 | 0 | { |
2954 | 0 | struct aout_link_hash_table *ret; |
2955 | 0 | size_t amt = sizeof (* ret); |
2956 | |
|
2957 | 0 | ret = (struct aout_link_hash_table *) bfd_malloc (amt); |
2958 | 0 | if (ret == NULL) |
2959 | 0 | return NULL; |
2960 | | |
2961 | 0 | if (!NAME (aout, link_hash_table_init) (ret, abfd, |
2962 | 0 | NAME (aout, link_hash_newfunc), |
2963 | 0 | sizeof (struct aout_link_hash_entry))) |
2964 | 0 | { |
2965 | 0 | free (ret); |
2966 | 0 | return NULL; |
2967 | 0 | } |
2968 | 0 | return &ret->root; |
2969 | 0 | } Unexecuted instantiation: cris_aout_32_link_hash_table_create Unexecuted instantiation: ns32kaout_32_link_hash_table_create Unexecuted instantiation: aout_32_link_hash_table_create |
2970 | | |
2971 | | /* Add all symbols from an object file to the hash table. */ |
2972 | | |
2973 | | static bool |
2974 | | aout_link_add_symbols (bfd *abfd, struct bfd_link_info *info) |
2975 | 0 | { |
2976 | 0 | struct external_nlist *syms; |
2977 | 0 | bfd_size_type sym_count; |
2978 | 0 | char *strings; |
2979 | 0 | bool copy; |
2980 | 0 | struct aout_link_hash_entry **sym_hash; |
2981 | 0 | struct external_nlist *p; |
2982 | 0 | struct external_nlist *pend; |
2983 | 0 | bfd_size_type amt; |
2984 | |
|
2985 | 0 | syms = obj_aout_external_syms (abfd); |
2986 | 0 | sym_count = obj_aout_external_sym_count (abfd); |
2987 | 0 | strings = obj_aout_external_strings (abfd); |
2988 | 0 | if (info->keep_memory) |
2989 | 0 | copy = false; |
2990 | 0 | else |
2991 | 0 | copy = true; |
2992 | |
|
2993 | 0 | if (aout_backend_info (abfd)->add_dynamic_symbols != NULL) |
2994 | 0 | { |
2995 | 0 | if (! ((*aout_backend_info (abfd)->add_dynamic_symbols) |
2996 | 0 | (abfd, info, &syms, &sym_count, &strings))) |
2997 | 0 | return false; |
2998 | 0 | } |
2999 | | |
3000 | 0 | if (sym_count == 0) |
3001 | 0 | return true; /* Nothing to do. */ |
3002 | | |
3003 | | /* We keep a list of the linker hash table entries that correspond |
3004 | | to particular symbols. We could just look them up in the hash |
3005 | | table, but keeping the list is more efficient. Perhaps this |
3006 | | should be conditional on info->keep_memory. */ |
3007 | 0 | amt = sym_count * sizeof (struct aout_link_hash_entry *); |
3008 | 0 | sym_hash = (struct aout_link_hash_entry **) bfd_alloc (abfd, amt); |
3009 | 0 | if (sym_hash == NULL) |
3010 | 0 | return false; |
3011 | 0 | obj_aout_sym_hashes (abfd) = sym_hash; |
3012 | |
|
3013 | 0 | p = syms; |
3014 | 0 | pend = p + sym_count; |
3015 | 0 | for (; p < pend; p++, sym_hash++) |
3016 | 0 | { |
3017 | 0 | int type; |
3018 | 0 | const char *name; |
3019 | 0 | bfd_vma value; |
3020 | 0 | asection *section; |
3021 | 0 | flagword flags; |
3022 | 0 | const char *string; |
3023 | |
|
3024 | 0 | *sym_hash = NULL; |
3025 | |
|
3026 | 0 | type = H_GET_8 (abfd, p->e_type); |
3027 | | |
3028 | | /* Ignore debugging symbols. */ |
3029 | 0 | if ((type & N_STAB) != 0) |
3030 | 0 | continue; |
3031 | | |
3032 | | /* PR 19629: Corrupt binaries can contain illegal string offsets. */ |
3033 | 0 | if (GET_WORD (abfd, p->e_strx) >= obj_aout_external_string_size (abfd)) |
3034 | 0 | return false; |
3035 | 0 | name = strings + GET_WORD (abfd, p->e_strx); |
3036 | 0 | value = GET_WORD (abfd, p->e_value); |
3037 | 0 | flags = BSF_GLOBAL; |
3038 | 0 | string = NULL; |
3039 | 0 | switch (type) |
3040 | 0 | { |
3041 | 0 | default: |
3042 | 0 | abort (); |
3043 | | |
3044 | 0 | case N_UNDF: |
3045 | 0 | case N_ABS: |
3046 | 0 | case N_TEXT: |
3047 | 0 | case N_DATA: |
3048 | 0 | case N_BSS: |
3049 | 0 | case N_FN_SEQ: |
3050 | 0 | case N_COMM: |
3051 | 0 | case N_SETV: |
3052 | 0 | case N_FN: |
3053 | | /* Ignore symbols that are not externally visible. */ |
3054 | 0 | continue; |
3055 | 0 | case N_INDR: |
3056 | | /* Ignore local indirect symbol. */ |
3057 | 0 | ++p; |
3058 | 0 | ++sym_hash; |
3059 | 0 | continue; |
3060 | | |
3061 | 0 | case N_UNDF | N_EXT: |
3062 | 0 | if (value == 0) |
3063 | 0 | { |
3064 | 0 | section = bfd_und_section_ptr; |
3065 | 0 | flags = 0; |
3066 | 0 | } |
3067 | 0 | else |
3068 | 0 | section = bfd_com_section_ptr; |
3069 | 0 | break; |
3070 | 0 | case N_ABS | N_EXT: |
3071 | 0 | section = bfd_abs_section_ptr; |
3072 | 0 | break; |
3073 | 0 | case N_TEXT | N_EXT: |
3074 | 0 | section = obj_textsec (abfd); |
3075 | 0 | value -= bfd_section_vma (section); |
3076 | 0 | break; |
3077 | 0 | case N_DATA | N_EXT: |
3078 | 0 | case N_SETV | N_EXT: |
3079 | | /* Treat N_SETV symbols as N_DATA symbol; see comment in |
3080 | | translate_from_native_sym_flags. */ |
3081 | 0 | section = obj_datasec (abfd); |
3082 | 0 | value -= bfd_section_vma (section); |
3083 | 0 | break; |
3084 | 0 | case N_BSS | N_EXT: |
3085 | 0 | section = obj_bsssec (abfd); |
3086 | 0 | value -= bfd_section_vma (section); |
3087 | 0 | break; |
3088 | 0 | case N_INDR | N_EXT: |
3089 | | /* An indirect symbol. The next symbol is the symbol |
3090 | | which this one really is. */ |
3091 | | /* See PR 20925 for a reproducer. */ |
3092 | 0 | if (p + 1 >= pend) |
3093 | 0 | return false; |
3094 | 0 | ++p; |
3095 | | /* PR 19629: Corrupt binaries can contain illegal string offsets. */ |
3096 | 0 | if (GET_WORD (abfd, p->e_strx) >= obj_aout_external_string_size (abfd)) |
3097 | 0 | return false; |
3098 | 0 | string = strings + GET_WORD (abfd, p->e_strx); |
3099 | 0 | section = bfd_ind_section_ptr; |
3100 | 0 | flags |= BSF_INDIRECT; |
3101 | 0 | break; |
3102 | 0 | case N_COMM | N_EXT: |
3103 | 0 | section = bfd_com_section_ptr; |
3104 | 0 | break; |
3105 | 0 | case N_SETA: case N_SETA | N_EXT: |
3106 | 0 | section = bfd_abs_section_ptr; |
3107 | 0 | flags |= BSF_CONSTRUCTOR; |
3108 | 0 | break; |
3109 | 0 | case N_SETT: case N_SETT | N_EXT: |
3110 | 0 | section = obj_textsec (abfd); |
3111 | 0 | flags |= BSF_CONSTRUCTOR; |
3112 | 0 | value -= bfd_section_vma (section); |
3113 | 0 | break; |
3114 | 0 | case N_SETD: case N_SETD | N_EXT: |
3115 | 0 | section = obj_datasec (abfd); |
3116 | 0 | flags |= BSF_CONSTRUCTOR; |
3117 | 0 | value -= bfd_section_vma (section); |
3118 | 0 | break; |
3119 | 0 | case N_SETB: case N_SETB | N_EXT: |
3120 | 0 | section = obj_bsssec (abfd); |
3121 | 0 | flags |= BSF_CONSTRUCTOR; |
3122 | 0 | value -= bfd_section_vma (section); |
3123 | 0 | break; |
3124 | 0 | case N_WARNING: |
3125 | | /* A warning symbol. The next symbol is the one to warn |
3126 | | about. If there is no next symbol, just look away. */ |
3127 | 0 | if (p + 1 >= pend) |
3128 | 0 | return true; |
3129 | 0 | ++p; |
3130 | 0 | string = name; |
3131 | | /* PR 19629: Corrupt binaries can contain illegal string offsets. */ |
3132 | 0 | if (GET_WORD (abfd, p->e_strx) >= obj_aout_external_string_size (abfd)) |
3133 | 0 | return false; |
3134 | 0 | name = strings + GET_WORD (abfd, p->e_strx); |
3135 | 0 | section = bfd_und_section_ptr; |
3136 | 0 | flags |= BSF_WARNING; |
3137 | 0 | break; |
3138 | 0 | case N_WEAKU: |
3139 | 0 | section = bfd_und_section_ptr; |
3140 | 0 | flags = BSF_WEAK; |
3141 | 0 | break; |
3142 | 0 | case N_WEAKA: |
3143 | 0 | section = bfd_abs_section_ptr; |
3144 | 0 | flags = BSF_WEAK; |
3145 | 0 | break; |
3146 | 0 | case N_WEAKT: |
3147 | 0 | section = obj_textsec (abfd); |
3148 | 0 | value -= bfd_section_vma (section); |
3149 | 0 | flags = BSF_WEAK; |
3150 | 0 | break; |
3151 | 0 | case N_WEAKD: |
3152 | 0 | section = obj_datasec (abfd); |
3153 | 0 | value -= bfd_section_vma (section); |
3154 | 0 | flags = BSF_WEAK; |
3155 | 0 | break; |
3156 | 0 | case N_WEAKB: |
3157 | 0 | section = obj_bsssec (abfd); |
3158 | 0 | value -= bfd_section_vma (section); |
3159 | 0 | flags = BSF_WEAK; |
3160 | 0 | break; |
3161 | 0 | } |
3162 | | |
3163 | 0 | if (! (_bfd_generic_link_add_one_symbol |
3164 | 0 | (info, abfd, name, flags, section, value, string, copy, false, |
3165 | 0 | (struct bfd_link_hash_entry **) sym_hash))) |
3166 | 0 | return false; |
3167 | | |
3168 | | /* Restrict the maximum alignment of a common symbol based on |
3169 | | the architecture, since a.out has no way to represent |
3170 | | alignment requirements of a section in a .o file. FIXME: |
3171 | | This isn't quite right: it should use the architecture of the |
3172 | | output file, not the input files. */ |
3173 | 0 | if ((*sym_hash)->root.type == bfd_link_hash_common |
3174 | 0 | && ((*sym_hash)->root.u.c.p->alignment_power > |
3175 | 0 | bfd_get_arch_info (abfd)->section_align_power)) |
3176 | 0 | (*sym_hash)->root.u.c.p->alignment_power = |
3177 | 0 | bfd_get_arch_info (abfd)->section_align_power; |
3178 | | |
3179 | | /* If this is a set symbol, and we are not building sets, then |
3180 | | it is possible for the hash entry to not have been set. In |
3181 | | such a case, treat the symbol as not globally defined. */ |
3182 | 0 | if ((*sym_hash)->root.type == bfd_link_hash_new) |
3183 | 0 | { |
3184 | 0 | BFD_ASSERT ((flags & BSF_CONSTRUCTOR) != 0); |
3185 | 0 | *sym_hash = NULL; |
3186 | 0 | } |
3187 | |
|
3188 | 0 | if (type == (N_INDR | N_EXT) || type == N_WARNING) |
3189 | 0 | ++sym_hash; |
3190 | 0 | } |
3191 | | |
3192 | 0 | return true; |
3193 | 0 | } Unexecuted instantiation: aout-cris.c:aout_link_add_symbols Unexecuted instantiation: aout-ns32k.c:aout_link_add_symbols Unexecuted instantiation: aout32.c:aout_link_add_symbols |
3194 | | |
3195 | | /* Free up the internal symbols read from an a.out file. */ |
3196 | | |
3197 | | static bool |
3198 | | aout_link_free_symbols (bfd *abfd) |
3199 | 0 | { |
3200 | 0 | if (obj_aout_external_syms (abfd) != NULL) |
3201 | 0 | { |
3202 | 0 | free ((void *) obj_aout_external_syms (abfd)); |
3203 | 0 | obj_aout_external_syms (abfd) = NULL; |
3204 | 0 | } |
3205 | 0 | if (obj_aout_external_strings (abfd) != NULL) |
3206 | 0 | { |
3207 | 0 | free ((void *) obj_aout_external_strings (abfd)); |
3208 | 0 | obj_aout_external_strings (abfd) = NULL; |
3209 | 0 | } |
3210 | 0 | return true; |
3211 | 0 | } Unexecuted instantiation: aout-cris.c:aout_link_free_symbols Unexecuted instantiation: aout-ns32k.c:aout_link_free_symbols Unexecuted instantiation: aout32.c:aout_link_free_symbols |
3212 | | |
3213 | | /* Add symbols from an a.out object file. */ |
3214 | | |
3215 | | static bool |
3216 | | aout_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) |
3217 | 0 | { |
3218 | 0 | if (! aout_get_external_symbols (abfd)) |
3219 | 0 | return false; |
3220 | 0 | if (! aout_link_add_symbols (abfd, info)) |
3221 | 0 | return false; |
3222 | 0 | if (! info->keep_memory) |
3223 | 0 | { |
3224 | 0 | if (! aout_link_free_symbols (abfd)) |
3225 | 0 | return false; |
3226 | 0 | } |
3227 | 0 | return true; |
3228 | 0 | } Unexecuted instantiation: aout-cris.c:aout_link_add_object_symbols Unexecuted instantiation: aout-ns32k.c:aout_link_add_object_symbols Unexecuted instantiation: aout32.c:aout_link_add_object_symbols |
3229 | | |
3230 | | /* Look through the internal symbols to see if this object file should |
3231 | | be included in the link. We should include this object file if it |
3232 | | defines any symbols which are currently undefined. If this object |
3233 | | file defines a common symbol, then we may adjust the size of the |
3234 | | known symbol but we do not include the object file in the link |
3235 | | (unless there is some other reason to include it). */ |
3236 | | |
3237 | | static bool |
3238 | | aout_link_check_ar_symbols (bfd *abfd, |
3239 | | struct bfd_link_info *info, |
3240 | | bool *pneeded, |
3241 | | bfd **subsbfd) |
3242 | 0 | { |
3243 | 0 | struct external_nlist *p; |
3244 | 0 | struct external_nlist *pend; |
3245 | 0 | char *strings; |
3246 | |
|
3247 | 0 | *pneeded = false; |
3248 | | |
3249 | | /* Look through all the symbols. */ |
3250 | 0 | p = obj_aout_external_syms (abfd); |
3251 | 0 | pend = p + obj_aout_external_sym_count (abfd); |
3252 | 0 | strings = obj_aout_external_strings (abfd); |
3253 | 0 | for (; p < pend; p++) |
3254 | 0 | { |
3255 | 0 | int type = H_GET_8 (abfd, p->e_type); |
3256 | 0 | const char *name; |
3257 | 0 | struct bfd_link_hash_entry *h; |
3258 | | |
3259 | | /* Ignore symbols that are not externally visible. This is an |
3260 | | optimization only, as we check the type more thoroughly |
3261 | | below. */ |
3262 | 0 | if (((type & N_EXT) == 0 |
3263 | 0 | || (type & N_STAB) != 0 |
3264 | 0 | || type == N_FN) |
3265 | 0 | && type != N_WEAKA |
3266 | 0 | && type != N_WEAKT |
3267 | 0 | && type != N_WEAKD |
3268 | 0 | && type != N_WEAKB) |
3269 | 0 | { |
3270 | 0 | if (type == N_WARNING |
3271 | 0 | || type == N_INDR) |
3272 | 0 | ++p; |
3273 | 0 | continue; |
3274 | 0 | } |
3275 | | |
3276 | 0 | name = strings + GET_WORD (abfd, p->e_strx); |
3277 | 0 | h = bfd_link_hash_lookup (info->hash, name, false, false, true); |
3278 | | |
3279 | | /* We are only interested in symbols that are currently |
3280 | | undefined or common. */ |
3281 | 0 | if (h == NULL |
3282 | 0 | || (h->type != bfd_link_hash_undefined |
3283 | 0 | && h->type != bfd_link_hash_common)) |
3284 | 0 | { |
3285 | 0 | if (type == (N_INDR | N_EXT)) |
3286 | 0 | ++p; |
3287 | 0 | continue; |
3288 | 0 | } |
3289 | | |
3290 | 0 | if (type == (N_TEXT | N_EXT) |
3291 | 0 | || type == (N_DATA | N_EXT) |
3292 | 0 | || type == (N_BSS | N_EXT) |
3293 | 0 | || type == (N_ABS | N_EXT) |
3294 | 0 | || type == (N_INDR | N_EXT)) |
3295 | 0 | { |
3296 | | /* This object file defines this symbol. We must link it |
3297 | | in. This is true regardless of whether the current |
3298 | | definition of the symbol is undefined or common. |
3299 | | |
3300 | | If the current definition is common, we have a case in |
3301 | | which we have already seen an object file including: |
3302 | | int a; |
3303 | | and this object file from the archive includes: |
3304 | | int a = 5; |
3305 | | In such a case, whether to include this object is target |
3306 | | dependant for backward compatibility. |
3307 | | |
3308 | | FIXME: The SunOS 4.1.3 linker will pull in the archive |
3309 | | element if the symbol is defined in the .data section, |
3310 | | but not if it is defined in the .text section. That |
3311 | | seems a bit crazy to me, and it has not been implemented |
3312 | | yet. However, it might be correct. */ |
3313 | 0 | if (h->type == bfd_link_hash_common) |
3314 | 0 | { |
3315 | 0 | int skip = 0; |
3316 | |
|
3317 | 0 | switch (info->common_skip_ar_symbols) |
3318 | 0 | { |
3319 | 0 | case bfd_link_common_skip_none: |
3320 | 0 | break; |
3321 | 0 | case bfd_link_common_skip_text: |
3322 | 0 | skip = (type == (N_TEXT | N_EXT)); |
3323 | 0 | break; |
3324 | 0 | case bfd_link_common_skip_data: |
3325 | 0 | skip = (type == (N_DATA | N_EXT)); |
3326 | 0 | break; |
3327 | 0 | case bfd_link_common_skip_all: |
3328 | 0 | skip = 1; |
3329 | 0 | break; |
3330 | 0 | } |
3331 | | |
3332 | 0 | if (skip) |
3333 | 0 | continue; |
3334 | 0 | } |
3335 | | |
3336 | 0 | if (!(*info->callbacks |
3337 | 0 | ->add_archive_element) (info, abfd, name, subsbfd)) |
3338 | 0 | return false; |
3339 | 0 | *pneeded = true; |
3340 | 0 | return true; |
3341 | 0 | } |
3342 | | |
3343 | 0 | if (type == (N_UNDF | N_EXT)) |
3344 | 0 | { |
3345 | 0 | bfd_vma value; |
3346 | |
|
3347 | 0 | value = GET_WORD (abfd, p->e_value); |
3348 | 0 | if (value != 0) |
3349 | 0 | { |
3350 | | /* This symbol is common in the object from the archive |
3351 | | file. */ |
3352 | 0 | if (h->type == bfd_link_hash_undefined) |
3353 | 0 | { |
3354 | 0 | bfd *symbfd; |
3355 | 0 | unsigned int power; |
3356 | |
|
3357 | 0 | symbfd = h->u.undef.abfd; |
3358 | 0 | if (symbfd == NULL) |
3359 | 0 | { |
3360 | | /* This symbol was created as undefined from |
3361 | | outside BFD. We assume that we should link |
3362 | | in the object file. This is done for the -u |
3363 | | option in the linker. */ |
3364 | 0 | if (!(*info->callbacks |
3365 | 0 | ->add_archive_element) (info, abfd, name, subsbfd)) |
3366 | 0 | return false; |
3367 | 0 | *pneeded = true; |
3368 | 0 | return true; |
3369 | 0 | } |
3370 | | /* Turn the current link symbol into a common |
3371 | | symbol. It is already on the undefs list. */ |
3372 | 0 | h->type = bfd_link_hash_common; |
3373 | 0 | h->u.c.p = (struct bfd_link_hash_common_entry *) |
3374 | 0 | bfd_hash_allocate (&info->hash->table, |
3375 | 0 | sizeof (struct bfd_link_hash_common_entry)); |
3376 | 0 | if (h->u.c.p == NULL) |
3377 | 0 | return false; |
3378 | | |
3379 | 0 | h->u.c.size = value; |
3380 | | |
3381 | | /* FIXME: This isn't quite right. The maximum |
3382 | | alignment of a common symbol should be set by the |
3383 | | architecture of the output file, not of the input |
3384 | | file. */ |
3385 | 0 | power = bfd_log2 (value); |
3386 | 0 | if (power > bfd_get_arch_info (abfd)->section_align_power) |
3387 | 0 | power = bfd_get_arch_info (abfd)->section_align_power; |
3388 | 0 | h->u.c.p->alignment_power = power; |
3389 | |
|
3390 | 0 | h->u.c.p->section = bfd_make_section_old_way (symbfd, |
3391 | 0 | "COMMON"); |
3392 | 0 | } |
3393 | 0 | else |
3394 | 0 | { |
3395 | | /* Adjust the size of the common symbol if |
3396 | | necessary. */ |
3397 | 0 | if (value > h->u.c.size) |
3398 | 0 | h->u.c.size = value; |
3399 | 0 | } |
3400 | 0 | } |
3401 | 0 | } |
3402 | | |
3403 | 0 | if (type == N_WEAKA |
3404 | 0 | || type == N_WEAKT |
3405 | 0 | || type == N_WEAKD |
3406 | 0 | || type == N_WEAKB) |
3407 | 0 | { |
3408 | | /* This symbol is weak but defined. We must pull it in if |
3409 | | the current link symbol is undefined, but we don't want |
3410 | | it if the current link symbol is common. */ |
3411 | 0 | if (h->type == bfd_link_hash_undefined) |
3412 | 0 | { |
3413 | 0 | if (!(*info->callbacks |
3414 | 0 | ->add_archive_element) (info, abfd, name, subsbfd)) |
3415 | 0 | return false; |
3416 | 0 | *pneeded = true; |
3417 | 0 | return true; |
3418 | 0 | } |
3419 | 0 | } |
3420 | 0 | } |
3421 | | |
3422 | | /* We do not need this object file. */ |
3423 | 0 | return true; |
3424 | 0 | } Unexecuted instantiation: aout-cris.c:aout_link_check_ar_symbols Unexecuted instantiation: aout-ns32k.c:aout_link_check_ar_symbols Unexecuted instantiation: aout32.c:aout_link_check_ar_symbols |
3425 | | /* Check a single archive element to see if we need to include it in |
3426 | | the link. *PNEEDED is set according to whether this element is |
3427 | | needed in the link or not. This is called from |
3428 | | _bfd_generic_link_add_archive_symbols. */ |
3429 | | |
3430 | | static bool |
3431 | | aout_link_check_archive_element (bfd *abfd, |
3432 | | struct bfd_link_info *info, |
3433 | | struct bfd_link_hash_entry *h ATTRIBUTE_UNUSED, |
3434 | | const char *name ATTRIBUTE_UNUSED, |
3435 | | bool *pneeded) |
3436 | 0 | { |
3437 | 0 | bfd *oldbfd; |
3438 | 0 | bool needed; |
3439 | |
|
3440 | 0 | if (!aout_get_external_symbols (abfd)) |
3441 | 0 | return false; |
3442 | | |
3443 | 0 | oldbfd = abfd; |
3444 | 0 | if (!aout_link_check_ar_symbols (abfd, info, pneeded, &abfd)) |
3445 | 0 | return false; |
3446 | | |
3447 | 0 | needed = *pneeded; |
3448 | 0 | if (needed) |
3449 | 0 | { |
3450 | | /* Potentially, the add_archive_element hook may have set a |
3451 | | substitute BFD for us. */ |
3452 | 0 | if (abfd != oldbfd) |
3453 | 0 | { |
3454 | 0 | if (!info->keep_memory |
3455 | 0 | && !aout_link_free_symbols (oldbfd)) |
3456 | 0 | return false; |
3457 | 0 | if (!aout_get_external_symbols (abfd)) |
3458 | 0 | return false; |
3459 | 0 | } |
3460 | 0 | if (!aout_link_add_symbols (abfd, info)) |
3461 | 0 | return false; |
3462 | 0 | } |
3463 | | |
3464 | 0 | if (!info->keep_memory || !needed) |
3465 | 0 | { |
3466 | 0 | if (!aout_link_free_symbols (abfd)) |
3467 | 0 | return false; |
3468 | 0 | } |
3469 | | |
3470 | 0 | return true; |
3471 | 0 | } Unexecuted instantiation: aout-cris.c:aout_link_check_archive_element Unexecuted instantiation: aout-ns32k.c:aout_link_check_archive_element Unexecuted instantiation: aout32.c:aout_link_check_archive_element |
3472 | | |
3473 | | /* Given an a.out BFD, add symbols to the global hash table as |
3474 | | appropriate. */ |
3475 | | |
3476 | | bool |
3477 | | NAME (aout, link_add_symbols) (bfd *abfd, struct bfd_link_info *info) |
3478 | 0 | { |
3479 | 0 | switch (bfd_get_format (abfd)) |
3480 | 0 | { |
3481 | 0 | case bfd_object: |
3482 | 0 | return aout_link_add_object_symbols (abfd, info); |
3483 | 0 | case bfd_archive: |
3484 | 0 | return _bfd_generic_link_add_archive_symbols |
3485 | 0 | (abfd, info, aout_link_check_archive_element); |
3486 | 0 | default: |
3487 | 0 | bfd_set_error (bfd_error_wrong_format); |
3488 | 0 | return false; |
3489 | 0 | } |
3490 | 0 | } Unexecuted instantiation: cris_aout_32_link_add_symbols Unexecuted instantiation: ns32kaout_32_link_add_symbols Unexecuted instantiation: aout_32_link_add_symbols |
3491 | | |
3492 | | /* A hash table used for header files with N_BINCL entries. */ |
3493 | | |
3494 | | struct aout_link_includes_table |
3495 | | { |
3496 | | struct bfd_hash_table root; |
3497 | | }; |
3498 | | |
3499 | | /* A linked list of totals that we have found for a particular header |
3500 | | file. */ |
3501 | | |
3502 | | struct aout_link_includes_totals |
3503 | | { |
3504 | | struct aout_link_includes_totals *next; |
3505 | | bfd_vma total; |
3506 | | }; |
3507 | | |
3508 | | /* An entry in the header file hash table. */ |
3509 | | |
3510 | | struct aout_link_includes_entry |
3511 | | { |
3512 | | struct bfd_hash_entry root; |
3513 | | /* List of totals we have found for this file. */ |
3514 | | struct aout_link_includes_totals *totals; |
3515 | | }; |
3516 | | |
3517 | | /* Look up an entry in an the header file hash table. */ |
3518 | | |
3519 | | #define aout_link_includes_lookup(table, string, create, copy) \ |
3520 | 0 | ((struct aout_link_includes_entry *) \ |
3521 | 0 | bfd_hash_lookup (&(table)->root, (string), (create), (copy))) |
3522 | | |
3523 | | /* During the final link step we need to pass around a bunch of |
3524 | | information, so we do it in an instance of this structure. */ |
3525 | | |
3526 | | struct aout_final_link_info |
3527 | | { |
3528 | | /* General link information. */ |
3529 | | struct bfd_link_info *info; |
3530 | | /* Output bfd. */ |
3531 | | bfd *output_bfd; |
3532 | | /* Reloc file positions. */ |
3533 | | file_ptr treloff, dreloff; |
3534 | | /* File position of symbols. */ |
3535 | | file_ptr symoff; |
3536 | | /* String table. */ |
3537 | | struct bfd_strtab_hash *strtab; |
3538 | | /* Header file hash table. */ |
3539 | | struct aout_link_includes_table includes; |
3540 | | /* A buffer large enough to hold the contents of any section. */ |
3541 | | bfd_byte *contents; |
3542 | | /* A buffer large enough to hold the relocs of any section. */ |
3543 | | void * relocs; |
3544 | | /* A buffer large enough to hold the symbol map of any input BFD. */ |
3545 | | int *symbol_map; |
3546 | | /* A buffer large enough to hold output symbols of any input BFD. */ |
3547 | | struct external_nlist *output_syms; |
3548 | | }; |
3549 | | |
3550 | | /* The function to create a new entry in the header file hash table. */ |
3551 | | |
3552 | | static struct bfd_hash_entry * |
3553 | | aout_link_includes_newfunc (struct bfd_hash_entry *entry, |
3554 | | struct bfd_hash_table *table, |
3555 | | const char *string) |
3556 | 0 | { |
3557 | 0 | struct aout_link_includes_entry *ret = |
3558 | 0 | (struct aout_link_includes_entry *) entry; |
3559 | | |
3560 | | /* Allocate the structure if it has not already been allocated by a |
3561 | | subclass. */ |
3562 | 0 | if (ret == NULL) |
3563 | 0 | ret = (struct aout_link_includes_entry *) |
3564 | 0 | bfd_hash_allocate (table, sizeof (* ret)); |
3565 | 0 | if (ret == NULL) |
3566 | 0 | return NULL; |
3567 | | |
3568 | | /* Call the allocation method of the superclass. */ |
3569 | 0 | ret = ((struct aout_link_includes_entry *) |
3570 | 0 | bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string)); |
3571 | 0 | if (ret) |
3572 | 0 | { |
3573 | | /* Set local fields. */ |
3574 | 0 | ret->totals = NULL; |
3575 | 0 | } |
3576 | |
|
3577 | 0 | return (struct bfd_hash_entry *) ret; |
3578 | 0 | } Unexecuted instantiation: aout-cris.c:aout_link_includes_newfunc Unexecuted instantiation: aout-ns32k.c:aout_link_includes_newfunc Unexecuted instantiation: aout32.c:aout_link_includes_newfunc |
3579 | | |
3580 | | /* Write out a symbol that was not associated with an a.out input |
3581 | | object. */ |
3582 | | |
3583 | | static bool |
3584 | | aout_link_write_other_symbol (struct bfd_hash_entry *bh, void *data) |
3585 | 0 | { |
3586 | 0 | struct aout_link_hash_entry *h = (struct aout_link_hash_entry *) bh; |
3587 | 0 | struct aout_final_link_info *flaginfo = (struct aout_final_link_info *) data; |
3588 | 0 | bfd *output_bfd; |
3589 | 0 | int type; |
3590 | 0 | bfd_vma val; |
3591 | 0 | struct external_nlist outsym; |
3592 | 0 | bfd_size_type indx; |
3593 | 0 | size_t amt; |
3594 | |
|
3595 | 0 | if (h->root.type == bfd_link_hash_warning) |
3596 | 0 | { |
3597 | 0 | h = (struct aout_link_hash_entry *) h->root.u.i.link; |
3598 | 0 | if (h->root.type == bfd_link_hash_new) |
3599 | 0 | return true; |
3600 | 0 | } |
3601 | | |
3602 | 0 | output_bfd = flaginfo->output_bfd; |
3603 | |
|
3604 | 0 | if (aout_backend_info (output_bfd)->write_dynamic_symbol != NULL) |
3605 | 0 | { |
3606 | 0 | if (! ((*aout_backend_info (output_bfd)->write_dynamic_symbol) |
3607 | 0 | (output_bfd, flaginfo->info, h))) |
3608 | 0 | { |
3609 | | /* FIXME: No way to handle errors. */ |
3610 | 0 | abort (); |
3611 | 0 | } |
3612 | 0 | } |
3613 | | |
3614 | 0 | if (h->written) |
3615 | 0 | return true; |
3616 | | |
3617 | 0 | h->written = true; |
3618 | | |
3619 | | /* An indx of -2 means the symbol must be written. */ |
3620 | 0 | if (h->indx != -2 |
3621 | 0 | && (flaginfo->info->strip == strip_all |
3622 | 0 | || (flaginfo->info->strip == strip_some |
3623 | 0 | && bfd_hash_lookup (flaginfo->info->keep_hash, h->root.root.string, |
3624 | 0 | false, false) == NULL))) |
3625 | 0 | return true; |
3626 | | |
3627 | 0 | switch (h->root.type) |
3628 | 0 | { |
3629 | 0 | default: |
3630 | 0 | case bfd_link_hash_warning: |
3631 | 0 | abort (); |
3632 | | /* Avoid variable not initialized warnings. */ |
3633 | 0 | return true; |
3634 | 0 | case bfd_link_hash_new: |
3635 | | /* This can happen for set symbols when sets are not being |
3636 | | built. */ |
3637 | 0 | return true; |
3638 | 0 | case bfd_link_hash_undefined: |
3639 | 0 | type = N_UNDF | N_EXT; |
3640 | 0 | val = 0; |
3641 | 0 | break; |
3642 | 0 | case bfd_link_hash_defined: |
3643 | 0 | case bfd_link_hash_defweak: |
3644 | 0 | { |
3645 | 0 | asection *sec; |
3646 | |
|
3647 | 0 | sec = h->root.u.def.section->output_section; |
3648 | 0 | BFD_ASSERT (bfd_is_abs_section (sec) |
3649 | 0 | || sec->owner == output_bfd); |
3650 | 0 | if (sec == obj_textsec (output_bfd)) |
3651 | 0 | type = h->root.type == bfd_link_hash_defined ? N_TEXT : N_WEAKT; |
3652 | 0 | else if (sec == obj_datasec (output_bfd)) |
3653 | 0 | type = h->root.type == bfd_link_hash_defined ? N_DATA : N_WEAKD; |
3654 | 0 | else if (sec == obj_bsssec (output_bfd)) |
3655 | 0 | type = h->root.type == bfd_link_hash_defined ? N_BSS : N_WEAKB; |
3656 | 0 | else |
3657 | 0 | type = h->root.type == bfd_link_hash_defined ? N_ABS : N_WEAKA; |
3658 | 0 | type |= N_EXT; |
3659 | 0 | val = (h->root.u.def.value |
3660 | 0 | + sec->vma |
3661 | 0 | + h->root.u.def.section->output_offset); |
3662 | 0 | } |
3663 | 0 | break; |
3664 | 0 | case bfd_link_hash_common: |
3665 | 0 | type = N_UNDF | N_EXT; |
3666 | 0 | val = h->root.u.c.size; |
3667 | 0 | break; |
3668 | 0 | case bfd_link_hash_undefweak: |
3669 | 0 | type = N_WEAKU; |
3670 | 0 | val = 0; |
3671 | 0 | break; |
3672 | 0 | case bfd_link_hash_indirect: |
3673 | | /* We ignore these symbols, since the indirected symbol is |
3674 | | already in the hash table. */ |
3675 | 0 | return true; |
3676 | 0 | } |
3677 | | |
3678 | 0 | H_PUT_8 (output_bfd, type, outsym.e_type); |
3679 | 0 | H_PUT_8 (output_bfd, 0, outsym.e_other); |
3680 | 0 | H_PUT_16 (output_bfd, 0, outsym.e_desc); |
3681 | 0 | indx = add_to_stringtab (output_bfd, flaginfo->strtab, h->root.root.string, |
3682 | 0 | false); |
3683 | 0 | if (indx == - (bfd_size_type) 1) |
3684 | | /* FIXME: No way to handle errors. */ |
3685 | 0 | abort (); |
3686 | | |
3687 | 0 | PUT_WORD (output_bfd, indx, outsym.e_strx); |
3688 | 0 | PUT_WORD (output_bfd, val, outsym.e_value); |
3689 | |
|
3690 | 0 | amt = EXTERNAL_NLIST_SIZE; |
3691 | 0 | if (bfd_seek (output_bfd, flaginfo->symoff, SEEK_SET) != 0 |
3692 | 0 | || bfd_write (&outsym, amt, output_bfd) != amt) |
3693 | | /* FIXME: No way to handle errors. */ |
3694 | 0 | abort (); |
3695 | | |
3696 | 0 | flaginfo->symoff += EXTERNAL_NLIST_SIZE; |
3697 | 0 | h->indx = obj_aout_external_sym_count (output_bfd); |
3698 | 0 | ++obj_aout_external_sym_count (output_bfd); |
3699 | |
|
3700 | 0 | return true; |
3701 | 0 | } Unexecuted instantiation: aout-cris.c:aout_link_write_other_symbol Unexecuted instantiation: aout-ns32k.c:aout_link_write_other_symbol Unexecuted instantiation: aout32.c:aout_link_write_other_symbol |
3702 | | |
3703 | | /* Handle a link order which is supposed to generate a reloc. */ |
3704 | | |
3705 | | static bool |
3706 | | aout_link_reloc_link_order (struct aout_final_link_info *flaginfo, |
3707 | | asection *o, |
3708 | | struct bfd_link_order *p) |
3709 | 0 | { |
3710 | 0 | struct bfd_link_order_reloc *pr; |
3711 | 0 | int r_index; |
3712 | 0 | int r_extern; |
3713 | 0 | reloc_howto_type *howto; |
3714 | 0 | file_ptr *reloff_ptr = NULL; |
3715 | 0 | struct reloc_std_external srel; |
3716 | 0 | struct reloc_ext_external erel; |
3717 | 0 | void * rel_ptr; |
3718 | 0 | size_t amt; |
3719 | |
|
3720 | 0 | pr = p->u.reloc.p; |
3721 | |
|
3722 | 0 | if (p->type == bfd_section_reloc_link_order) |
3723 | 0 | { |
3724 | 0 | r_extern = 0; |
3725 | 0 | if (bfd_is_abs_section (pr->u.section)) |
3726 | 0 | r_index = N_ABS | N_EXT; |
3727 | 0 | else |
3728 | 0 | { |
3729 | 0 | BFD_ASSERT (pr->u.section->owner == flaginfo->output_bfd); |
3730 | 0 | r_index = pr->u.section->target_index; |
3731 | 0 | } |
3732 | 0 | } |
3733 | 0 | else |
3734 | 0 | { |
3735 | 0 | struct aout_link_hash_entry *h; |
3736 | |
|
3737 | 0 | BFD_ASSERT (p->type == bfd_symbol_reloc_link_order); |
3738 | 0 | r_extern = 1; |
3739 | 0 | h = ((struct aout_link_hash_entry *) |
3740 | 0 | bfd_wrapped_link_hash_lookup (flaginfo->output_bfd, flaginfo->info, |
3741 | 0 | pr->u.name, false, false, true)); |
3742 | 0 | if (h != NULL |
3743 | 0 | && h->indx >= 0) |
3744 | 0 | r_index = h->indx; |
3745 | 0 | else if (h != NULL) |
3746 | 0 | { |
3747 | | /* We decided to strip this symbol, but it turns out that we |
3748 | | can't. Note that we lose the other and desc information |
3749 | | here. I don't think that will ever matter for a global |
3750 | | symbol. */ |
3751 | 0 | h->indx = -2; |
3752 | 0 | h->written = false; |
3753 | 0 | if (!aout_link_write_other_symbol (&h->root.root, flaginfo)) |
3754 | 0 | return false; |
3755 | 0 | r_index = h->indx; |
3756 | 0 | } |
3757 | 0 | else |
3758 | 0 | { |
3759 | 0 | (*flaginfo->info->callbacks->unattached_reloc) |
3760 | 0 | (flaginfo->info, pr->u.name, NULL, NULL, (bfd_vma) 0); |
3761 | 0 | r_index = 0; |
3762 | 0 | } |
3763 | 0 | } |
3764 | | |
3765 | 0 | howto = bfd_reloc_type_lookup (flaginfo->output_bfd, pr->reloc); |
3766 | 0 | if (howto == 0) |
3767 | 0 | { |
3768 | 0 | bfd_set_error (bfd_error_bad_value); |
3769 | 0 | return false; |
3770 | 0 | } |
3771 | | |
3772 | 0 | if (o == obj_textsec (flaginfo->output_bfd)) |
3773 | 0 | reloff_ptr = &flaginfo->treloff; |
3774 | 0 | else if (o == obj_datasec (flaginfo->output_bfd)) |
3775 | 0 | reloff_ptr = &flaginfo->dreloff; |
3776 | 0 | else |
3777 | 0 | abort (); |
3778 | | |
3779 | 0 | if (obj_reloc_entry_size (flaginfo->output_bfd) == RELOC_STD_SIZE) |
3780 | 0 | { |
3781 | | #ifdef MY_put_reloc |
3782 | 0 | MY_put_reloc (flaginfo->output_bfd, r_extern, r_index, p->offset, howto, |
3783 | | &srel); |
3784 | | #else |
3785 | | { |
3786 | | int r_pcrel; |
3787 | | int r_baserel; |
3788 | | int r_jmptable; |
3789 | | int r_relative; |
3790 | | unsigned int r_length; |
3791 | | |
3792 | | r_pcrel = (int) howto->pc_relative; |
3793 | | r_baserel = (howto->type & 8) != 0; |
3794 | | r_jmptable = (howto->type & 16) != 0; |
3795 | | r_relative = (howto->type & 32) != 0; |
3796 | | r_length = bfd_log2 (bfd_get_reloc_size (howto)); |
3797 | | |
3798 | 0 | PUT_WORD (flaginfo->output_bfd, p->offset, srel.r_address); |
3799 | 0 | if (bfd_header_big_endian (flaginfo->output_bfd)) |
3800 | 0 | { |
3801 | 0 | srel.r_index[0] = r_index >> 16; |
3802 | 0 | srel.r_index[1] = r_index >> 8; |
3803 | 0 | srel.r_index[2] = r_index; |
3804 | 0 | srel.r_type[0] = |
3805 | 0 | ((r_extern ? RELOC_STD_BITS_EXTERN_BIG : 0) |
3806 | 0 | | (r_pcrel ? RELOC_STD_BITS_PCREL_BIG : 0) |
3807 | 0 | | (r_baserel ? RELOC_STD_BITS_BASEREL_BIG : 0) |
3808 | 0 | | (r_jmptable ? RELOC_STD_BITS_JMPTABLE_BIG : 0) |
3809 | 0 | | (r_relative ? RELOC_STD_BITS_RELATIVE_BIG : 0) |
3810 | 0 | | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG)); |
3811 | 0 | } |
3812 | 0 | else |
3813 | 0 | { |
3814 | 0 | srel.r_index[2] = r_index >> 16; |
3815 | 0 | srel.r_index[1] = r_index >> 8; |
3816 | 0 | srel.r_index[0] = r_index; |
3817 | 0 | srel.r_type[0] = |
3818 | 0 | ((r_extern ? RELOC_STD_BITS_EXTERN_LITTLE : 0) |
3819 | 0 | | (r_pcrel ? RELOC_STD_BITS_PCREL_LITTLE : 0) |
3820 | 0 | | (r_baserel ? RELOC_STD_BITS_BASEREL_LITTLE : 0) |
3821 | 0 | | (r_jmptable ? RELOC_STD_BITS_JMPTABLE_LITTLE : 0) |
3822 | 0 | | (r_relative ? RELOC_STD_BITS_RELATIVE_LITTLE : 0) |
3823 | 0 | | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE)); |
3824 | 0 | } |
3825 | | } |
3826 | | #endif |
3827 | 0 | rel_ptr = (void *) &srel; |
3828 | | |
3829 | | /* We have to write the addend into the object file, since |
3830 | | standard a.out relocs are in place. It would be more |
3831 | | reliable if we had the current contents of the file here, |
3832 | | rather than assuming zeroes, but we can't read the file since |
3833 | | it was opened using bfd_openw. */ |
3834 | 0 | if (pr->addend != 0) |
3835 | 0 | { |
3836 | 0 | bfd_size_type size; |
3837 | 0 | bfd_reloc_status_type r; |
3838 | 0 | bfd_byte *buf; |
3839 | 0 | bool ok; |
3840 | |
|
3841 | 0 | size = bfd_get_reloc_size (howto); |
3842 | 0 | buf = (bfd_byte *) bfd_zmalloc (size); |
3843 | 0 | if (buf == NULL && size != 0) |
3844 | 0 | return false; |
3845 | 0 | r = MY_relocate_contents (howto, flaginfo->output_bfd, |
3846 | 0 | (bfd_vma) pr->addend, buf); |
3847 | 0 | switch (r) |
3848 | 0 | { |
3849 | 0 | case bfd_reloc_ok: |
3850 | 0 | break; |
3851 | 0 | default: |
3852 | 0 | case bfd_reloc_outofrange: |
3853 | 0 | abort (); |
3854 | 0 | case bfd_reloc_overflow: |
3855 | 0 | (*flaginfo->info->callbacks->reloc_overflow) |
3856 | 0 | (flaginfo->info, NULL, |
3857 | 0 | (p->type == bfd_section_reloc_link_order |
3858 | 0 | ? bfd_section_name (pr->u.section) |
3859 | 0 | : pr->u.name), |
3860 | 0 | howto->name, pr->addend, NULL, NULL, (bfd_vma) 0); |
3861 | 0 | break; |
3862 | 0 | } |
3863 | 0 | ok = bfd_set_section_contents (flaginfo->output_bfd, o, (void *) buf, |
3864 | 0 | (file_ptr) p->offset, size); |
3865 | 0 | free (buf); |
3866 | 0 | if (! ok) |
3867 | 0 | return false; |
3868 | 0 | } |
3869 | 0 | } |
3870 | 0 | else |
3871 | 0 | { |
3872 | | #ifdef MY_put_ext_reloc |
3873 | | MY_put_ext_reloc (flaginfo->output_bfd, r_extern, r_index, p->offset, |
3874 | | howto, &erel, pr->addend); |
3875 | | #else |
3876 | 0 | PUT_WORD (flaginfo->output_bfd, p->offset, erel.r_address); |
3877 | |
|
3878 | 0 | if (bfd_header_big_endian (flaginfo->output_bfd)) |
3879 | 0 | { |
3880 | 0 | erel.r_index[0] = r_index >> 16; |
3881 | 0 | erel.r_index[1] = r_index >> 8; |
3882 | 0 | erel.r_index[2] = r_index; |
3883 | 0 | erel.r_type[0] = |
3884 | 0 | ((r_extern ? RELOC_EXT_BITS_EXTERN_BIG : 0) |
3885 | 0 | | (howto->type << RELOC_EXT_BITS_TYPE_SH_BIG)); |
3886 | 0 | } |
3887 | 0 | else |
3888 | 0 | { |
3889 | 0 | erel.r_index[2] = r_index >> 16; |
3890 | 0 | erel.r_index[1] = r_index >> 8; |
3891 | 0 | erel.r_index[0] = r_index; |
3892 | 0 | erel.r_type[0] = |
3893 | 0 | (r_extern ? RELOC_EXT_BITS_EXTERN_LITTLE : 0) |
3894 | 0 | | (howto->type << RELOC_EXT_BITS_TYPE_SH_LITTLE); |
3895 | 0 | } |
3896 | |
|
3897 | 0 | PUT_WORD (flaginfo->output_bfd, (bfd_vma) pr->addend, erel.r_addend); |
3898 | 0 | #endif /* MY_put_ext_reloc */ |
3899 | |
|
3900 | 0 | rel_ptr = (void *) &erel; |
3901 | 0 | } |
3902 | | |
3903 | 0 | amt = obj_reloc_entry_size (flaginfo->output_bfd); |
3904 | 0 | if (bfd_seek (flaginfo->output_bfd, *reloff_ptr, SEEK_SET) != 0 |
3905 | 0 | || bfd_write (rel_ptr, amt, flaginfo->output_bfd) != amt) |
3906 | 0 | return false; |
3907 | | |
3908 | 0 | *reloff_ptr += obj_reloc_entry_size (flaginfo->output_bfd); |
3909 | | |
3910 | | /* Assert that the relocs have not run into the symbols, and that n |
3911 | | the text relocs have not run into the data relocs. */ |
3912 | 0 | BFD_ASSERT (*reloff_ptr <= obj_sym_filepos (flaginfo->output_bfd) |
3913 | 0 | && (reloff_ptr != &flaginfo->treloff |
3914 | 0 | || (*reloff_ptr |
3915 | 0 | <= obj_datasec (flaginfo->output_bfd)->rel_filepos))); |
3916 | |
|
3917 | 0 | return true; |
3918 | 0 | } Unexecuted instantiation: aout-cris.c:aout_link_reloc_link_order Unexecuted instantiation: aout-ns32k.c:aout_link_reloc_link_order Unexecuted instantiation: aout32.c:aout_link_reloc_link_order |
3919 | | |
3920 | | /* Get the section corresponding to a reloc index. */ |
3921 | | |
3922 | | static inline asection * |
3923 | | aout_reloc_index_to_section (bfd *abfd, int indx) |
3924 | 0 | { |
3925 | 0 | switch (indx & N_TYPE) |
3926 | 0 | { |
3927 | 0 | case N_TEXT: return obj_textsec (abfd); |
3928 | 0 | case N_DATA: return obj_datasec (abfd); |
3929 | 0 | case N_BSS: return obj_bsssec (abfd); |
3930 | 0 | case N_ABS: |
3931 | 0 | case N_UNDF: return bfd_abs_section_ptr; |
3932 | 0 | default: abort (); |
3933 | 0 | } |
3934 | 0 | return NULL; |
3935 | 0 | } Unexecuted instantiation: aout-cris.c:aout_reloc_index_to_section Unexecuted instantiation: aout-ns32k.c:aout_reloc_index_to_section Unexecuted instantiation: aout32.c:aout_reloc_index_to_section |
3936 | | |
3937 | | /* Relocate an a.out section using standard a.out relocs. */ |
3938 | | |
3939 | | static bool |
3940 | | aout_link_input_section_std (struct aout_final_link_info *flaginfo, |
3941 | | bfd *input_bfd, |
3942 | | asection *input_section, |
3943 | | struct reloc_std_external *relocs, |
3944 | | bfd_size_type rel_size, |
3945 | | bfd_byte *contents) |
3946 | 0 | { |
3947 | 0 | bool (*check_dynamic_reloc) |
3948 | 0 | (struct bfd_link_info *, bfd *, asection *, |
3949 | 0 | struct aout_link_hash_entry *, void *, bfd_byte *, bool *, bfd_vma *); |
3950 | 0 | bfd *output_bfd; |
3951 | 0 | bool relocatable; |
3952 | 0 | struct external_nlist *syms; |
3953 | 0 | char *strings; |
3954 | 0 | struct aout_link_hash_entry **sym_hashes; |
3955 | 0 | int *symbol_map; |
3956 | 0 | bfd_size_type reloc_count; |
3957 | 0 | struct reloc_std_external *rel; |
3958 | 0 | struct reloc_std_external *rel_end; |
3959 | |
|
3960 | 0 | output_bfd = flaginfo->output_bfd; |
3961 | 0 | check_dynamic_reloc = aout_backend_info (output_bfd)->check_dynamic_reloc; |
3962 | |
|
3963 | 0 | BFD_ASSERT (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE); |
3964 | 0 | BFD_ASSERT (input_bfd->xvec->header_byteorder |
3965 | 0 | == output_bfd->xvec->header_byteorder); |
3966 | |
|
3967 | 0 | relocatable = bfd_link_relocatable (flaginfo->info); |
3968 | 0 | syms = obj_aout_external_syms (input_bfd); |
3969 | 0 | strings = obj_aout_external_strings (input_bfd); |
3970 | 0 | sym_hashes = obj_aout_sym_hashes (input_bfd); |
3971 | 0 | symbol_map = flaginfo->symbol_map; |
3972 | |
|
3973 | 0 | reloc_count = rel_size / RELOC_STD_SIZE; |
3974 | 0 | rel = relocs; |
3975 | 0 | rel_end = rel + reloc_count; |
3976 | 0 | for (; rel < rel_end; rel++) |
3977 | 0 | { |
3978 | 0 | bfd_vma r_addr; |
3979 | 0 | unsigned int r_index; |
3980 | 0 | int r_extern; |
3981 | 0 | int r_pcrel; |
3982 | 0 | int r_baserel = 0; |
3983 | 0 | reloc_howto_type *howto; |
3984 | 0 | struct aout_link_hash_entry *h = NULL; |
3985 | 0 | bfd_vma relocation; |
3986 | 0 | bfd_reloc_status_type r; |
3987 | |
|
3988 | 0 | r_addr = GET_SWORD (input_bfd, rel->r_address); |
3989 | |
|
3990 | | #ifdef MY_reloc_howto |
3991 | 0 | howto = MY_reloc_howto (input_bfd, rel, r_index, r_extern, r_pcrel); |
3992 | | #else |
3993 | | { |
3994 | | int r_jmptable; |
3995 | | int r_relative; |
3996 | | int r_length; |
3997 | | unsigned int howto_idx; |
3998 | | |
3999 | 0 | if (bfd_header_big_endian (input_bfd)) |
4000 | 0 | { |
4001 | 0 | r_index = (((unsigned int) rel->r_index[0] << 16) |
4002 | 0 | | ((unsigned int) rel->r_index[1] << 8) |
4003 | 0 | | rel->r_index[2]); |
4004 | 0 | r_extern = (0 != (rel->r_type[0] & RELOC_STD_BITS_EXTERN_BIG)); |
4005 | 0 | r_pcrel = (0 != (rel->r_type[0] & RELOC_STD_BITS_PCREL_BIG)); |
4006 | 0 | r_baserel = (0 != (rel->r_type[0] & RELOC_STD_BITS_BASEREL_BIG)); |
4007 | 0 | r_jmptable= (0 != (rel->r_type[0] & RELOC_STD_BITS_JMPTABLE_BIG)); |
4008 | 0 | r_relative= (0 != (rel->r_type[0] & RELOC_STD_BITS_RELATIVE_BIG)); |
4009 | 0 | r_length = ((rel->r_type[0] & RELOC_STD_BITS_LENGTH_BIG) |
4010 | 0 | >> RELOC_STD_BITS_LENGTH_SH_BIG); |
4011 | 0 | } |
4012 | 0 | else |
4013 | 0 | { |
4014 | 0 | r_index = (((unsigned int) rel->r_index[2] << 16) |
4015 | 0 | | ((unsigned int) rel->r_index[1] << 8) |
4016 | 0 | | rel->r_index[0]); |
4017 | 0 | r_extern = (0 != (rel->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE)); |
4018 | 0 | r_pcrel = (0 != (rel->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE)); |
4019 | 0 | r_baserel = (0 != (rel->r_type[0] |
4020 | 0 | & RELOC_STD_BITS_BASEREL_LITTLE)); |
4021 | 0 | r_jmptable= (0 != (rel->r_type[0] |
4022 | 0 | & RELOC_STD_BITS_JMPTABLE_LITTLE)); |
4023 | 0 | r_relative= (0 != (rel->r_type[0] |
4024 | 0 | & RELOC_STD_BITS_RELATIVE_LITTLE)); |
4025 | 0 | r_length = ((rel->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE) |
4026 | 0 | >> RELOC_STD_BITS_LENGTH_SH_LITTLE); |
4027 | 0 | } |
4028 | | |
4029 | | howto_idx = (r_length + 4 * r_pcrel + 8 * r_baserel |
4030 | | + 16 * r_jmptable + 32 * r_relative); |
4031 | 0 | if (howto_idx < TABLE_SIZE (howto_table_std)) |
4032 | 0 | howto = howto_table_std + howto_idx; |
4033 | 0 | else |
4034 | 0 | howto = NULL; |
4035 | | } |
4036 | | #endif |
4037 | |
|
4038 | 0 | if (howto == NULL) |
4039 | 0 | { |
4040 | 0 | _bfd_error_handler (_("%pB: unsupported relocation type"), |
4041 | 0 | input_bfd); |
4042 | 0 | bfd_set_error (bfd_error_bad_value); |
4043 | 0 | return false; |
4044 | 0 | } |
4045 | | |
4046 | 0 | if (relocatable) |
4047 | 0 | { |
4048 | | /* We are generating a relocatable output file, and must |
4049 | | modify the reloc accordingly. */ |
4050 | 0 | if (r_extern) |
4051 | 0 | { |
4052 | | /* If we know the symbol this relocation is against, |
4053 | | convert it into a relocation against a section. This |
4054 | | is what the native linker does. */ |
4055 | 0 | h = sym_hashes[r_index]; |
4056 | 0 | if (h != NULL |
4057 | 0 | && (h->root.type == bfd_link_hash_defined |
4058 | 0 | || h->root.type == bfd_link_hash_defweak)) |
4059 | 0 | { |
4060 | 0 | asection *output_section; |
4061 | | |
4062 | | /* Change the r_extern value. */ |
4063 | 0 | if (bfd_header_big_endian (output_bfd)) |
4064 | 0 | rel->r_type[0] &=~ RELOC_STD_BITS_EXTERN_BIG; |
4065 | 0 | else |
4066 | 0 | rel->r_type[0] &=~ RELOC_STD_BITS_EXTERN_LITTLE; |
4067 | | |
4068 | | /* Compute a new r_index. */ |
4069 | 0 | output_section = h->root.u.def.section->output_section; |
4070 | 0 | if (output_section == obj_textsec (output_bfd)) |
4071 | 0 | r_index = N_TEXT; |
4072 | 0 | else if (output_section == obj_datasec (output_bfd)) |
4073 | 0 | r_index = N_DATA; |
4074 | 0 | else if (output_section == obj_bsssec (output_bfd)) |
4075 | 0 | r_index = N_BSS; |
4076 | 0 | else |
4077 | 0 | r_index = N_ABS; |
4078 | | |
4079 | | /* Add the symbol value and the section VMA to the |
4080 | | addend stored in the contents. */ |
4081 | 0 | relocation = (h->root.u.def.value |
4082 | 0 | + output_section->vma |
4083 | 0 | + h->root.u.def.section->output_offset); |
4084 | 0 | } |
4085 | 0 | else |
4086 | 0 | { |
4087 | | /* We must change r_index according to the symbol |
4088 | | map. */ |
4089 | 0 | r_index = symbol_map[r_index]; |
4090 | |
|
4091 | 0 | if (r_index == -1u) |
4092 | 0 | { |
4093 | 0 | if (h != NULL) |
4094 | 0 | { |
4095 | | /* We decided to strip this symbol, but it |
4096 | | turns out that we can't. Note that we |
4097 | | lose the other and desc information here. |
4098 | | I don't think that will ever matter for a |
4099 | | global symbol. */ |
4100 | 0 | if (h->indx < 0) |
4101 | 0 | { |
4102 | 0 | h->indx = -2; |
4103 | 0 | h->written = false; |
4104 | 0 | if (!aout_link_write_other_symbol (&h->root.root, |
4105 | 0 | flaginfo)) |
4106 | 0 | return false; |
4107 | 0 | } |
4108 | 0 | r_index = h->indx; |
4109 | 0 | } |
4110 | 0 | else |
4111 | 0 | { |
4112 | 0 | const char *name; |
4113 | |
|
4114 | 0 | name = strings + GET_WORD (input_bfd, |
4115 | 0 | syms[r_index].e_strx); |
4116 | 0 | (*flaginfo->info->callbacks->unattached_reloc) |
4117 | 0 | (flaginfo->info, name, |
4118 | 0 | input_bfd, input_section, r_addr); |
4119 | 0 | r_index = 0; |
4120 | 0 | } |
4121 | 0 | } |
4122 | | |
4123 | 0 | relocation = 0; |
4124 | 0 | } |
4125 | | |
4126 | | /* Write out the new r_index value. */ |
4127 | 0 | if (bfd_header_big_endian (output_bfd)) |
4128 | 0 | { |
4129 | 0 | rel->r_index[0] = r_index >> 16; |
4130 | 0 | rel->r_index[1] = r_index >> 8; |
4131 | 0 | rel->r_index[2] = r_index; |
4132 | 0 | } |
4133 | 0 | else |
4134 | 0 | { |
4135 | 0 | rel->r_index[2] = r_index >> 16; |
4136 | 0 | rel->r_index[1] = r_index >> 8; |
4137 | 0 | rel->r_index[0] = r_index; |
4138 | 0 | } |
4139 | 0 | } |
4140 | 0 | else |
4141 | 0 | { |
4142 | 0 | asection *section; |
4143 | | |
4144 | | /* This is a relocation against a section. We must |
4145 | | adjust by the amount that the section moved. */ |
4146 | 0 | section = aout_reloc_index_to_section (input_bfd, r_index); |
4147 | 0 | relocation = (section->output_section->vma |
4148 | 0 | + section->output_offset |
4149 | 0 | - section->vma); |
4150 | 0 | } |
4151 | | |
4152 | | /* Change the address of the relocation. */ |
4153 | 0 | PUT_WORD (output_bfd, |
4154 | 0 | r_addr + input_section->output_offset, |
4155 | 0 | rel->r_address); |
4156 | | |
4157 | | /* Adjust a PC relative relocation by removing the reference |
4158 | | to the original address in the section and including the |
4159 | | reference to the new address. */ |
4160 | 0 | if (r_pcrel) |
4161 | 0 | relocation -= (input_section->output_section->vma |
4162 | 0 | + input_section->output_offset |
4163 | 0 | - input_section->vma); |
4164 | |
|
4165 | | #ifdef MY_relocatable_reloc |
4166 | | MY_relocatable_reloc (howto, output_bfd, rel, relocation, r_addr); |
4167 | | #endif |
4168 | |
|
4169 | 0 | if (relocation == 0) |
4170 | 0 | r = bfd_reloc_ok; |
4171 | 0 | else |
4172 | 0 | r = MY_relocate_contents (howto, |
4173 | 0 | input_bfd, relocation, |
4174 | 0 | contents + r_addr); |
4175 | 0 | } |
4176 | 0 | else |
4177 | 0 | { |
4178 | 0 | bool hundef; |
4179 | | |
4180 | | /* We are generating an executable, and must do a full |
4181 | | relocation. */ |
4182 | 0 | hundef = false; |
4183 | |
|
4184 | 0 | if (r_extern) |
4185 | 0 | { |
4186 | 0 | h = sym_hashes[r_index]; |
4187 | |
|
4188 | 0 | if (h != NULL |
4189 | 0 | && (h->root.type == bfd_link_hash_defined |
4190 | 0 | || h->root.type == bfd_link_hash_defweak)) |
4191 | 0 | { |
4192 | 0 | relocation = (h->root.u.def.value |
4193 | 0 | + h->root.u.def.section->output_section->vma |
4194 | 0 | + h->root.u.def.section->output_offset); |
4195 | 0 | } |
4196 | 0 | else if (h != NULL |
4197 | 0 | && h->root.type == bfd_link_hash_undefweak) |
4198 | 0 | relocation = 0; |
4199 | 0 | else |
4200 | 0 | { |
4201 | 0 | hundef = true; |
4202 | 0 | relocation = 0; |
4203 | 0 | } |
4204 | 0 | } |
4205 | 0 | else |
4206 | 0 | { |
4207 | 0 | asection *section; |
4208 | |
|
4209 | 0 | section = aout_reloc_index_to_section (input_bfd, r_index); |
4210 | 0 | relocation = (section->output_section->vma |
4211 | 0 | + section->output_offset |
4212 | 0 | - section->vma); |
4213 | 0 | if (r_pcrel) |
4214 | 0 | relocation += input_section->vma; |
4215 | 0 | } |
4216 | |
|
4217 | 0 | if (check_dynamic_reloc != NULL) |
4218 | 0 | { |
4219 | 0 | bool skip; |
4220 | |
|
4221 | 0 | if (! ((*check_dynamic_reloc) |
4222 | 0 | (flaginfo->info, input_bfd, input_section, h, |
4223 | 0 | (void *) rel, contents, &skip, &relocation))) |
4224 | 0 | return false; |
4225 | 0 | if (skip) |
4226 | 0 | continue; |
4227 | 0 | } |
4228 | | |
4229 | | /* Now warn if a global symbol is undefined. We could not |
4230 | | do this earlier, because check_dynamic_reloc might want |
4231 | | to skip this reloc. */ |
4232 | 0 | if (hundef && ! bfd_link_pic (flaginfo->info) && ! r_baserel) |
4233 | 0 | { |
4234 | 0 | const char *name; |
4235 | |
|
4236 | 0 | if (h != NULL) |
4237 | 0 | name = h->root.root.string; |
4238 | 0 | else |
4239 | 0 | name = strings + GET_WORD (input_bfd, syms[r_index].e_strx); |
4240 | 0 | (*flaginfo->info->callbacks->undefined_symbol) |
4241 | 0 | (flaginfo->info, name, input_bfd, input_section, r_addr, true); |
4242 | 0 | } |
4243 | |
|
4244 | 0 | r = MY_final_link_relocate (howto, |
4245 | 0 | input_bfd, input_section, |
4246 | 0 | contents, r_addr, relocation, |
4247 | 0 | (bfd_vma) 0); |
4248 | 0 | } |
4249 | | |
4250 | 0 | if (r != bfd_reloc_ok) |
4251 | 0 | { |
4252 | 0 | switch (r) |
4253 | 0 | { |
4254 | 0 | default: |
4255 | 0 | case bfd_reloc_outofrange: |
4256 | 0 | abort (); |
4257 | 0 | case bfd_reloc_overflow: |
4258 | 0 | { |
4259 | 0 | const char *name; |
4260 | |
|
4261 | 0 | if (h != NULL) |
4262 | 0 | name = NULL; |
4263 | 0 | else if (r_extern) |
4264 | 0 | name = strings + GET_WORD (input_bfd, |
4265 | 0 | syms[r_index].e_strx); |
4266 | 0 | else |
4267 | 0 | { |
4268 | 0 | asection *s; |
4269 | |
|
4270 | 0 | s = aout_reloc_index_to_section (input_bfd, r_index); |
4271 | 0 | name = bfd_section_name (s); |
4272 | 0 | } |
4273 | 0 | (*flaginfo->info->callbacks->reloc_overflow) |
4274 | 0 | (flaginfo->info, (h ? &h->root : NULL), name, howto->name, |
4275 | 0 | (bfd_vma) 0, input_bfd, input_section, r_addr); |
4276 | 0 | } |
4277 | 0 | break; |
4278 | 0 | } |
4279 | 0 | } |
4280 | 0 | } |
4281 | | |
4282 | 0 | return true; |
4283 | 0 | } Unexecuted instantiation: aout-cris.c:aout_link_input_section_std Unexecuted instantiation: aout-ns32k.c:aout_link_input_section_std Unexecuted instantiation: aout32.c:aout_link_input_section_std |
4284 | | |
4285 | | /* Relocate an a.out section using extended a.out relocs. */ |
4286 | | |
4287 | | static bool |
4288 | | aout_link_input_section_ext (struct aout_final_link_info *flaginfo, |
4289 | | bfd *input_bfd, |
4290 | | asection *input_section, |
4291 | | struct reloc_ext_external *relocs, |
4292 | | bfd_size_type rel_size, |
4293 | | bfd_byte *contents) |
4294 | 0 | { |
4295 | 0 | bool (*check_dynamic_reloc) |
4296 | 0 | (struct bfd_link_info *, bfd *, asection *, |
4297 | 0 | struct aout_link_hash_entry *, void *, bfd_byte *, bool *, bfd_vma *); |
4298 | 0 | bfd *output_bfd; |
4299 | 0 | bool relocatable; |
4300 | 0 | struct external_nlist *syms; |
4301 | 0 | char *strings; |
4302 | 0 | struct aout_link_hash_entry **sym_hashes; |
4303 | 0 | int *symbol_map; |
4304 | 0 | bfd_size_type reloc_count; |
4305 | 0 | struct reloc_ext_external *rel; |
4306 | 0 | struct reloc_ext_external *rel_end; |
4307 | |
|
4308 | 0 | output_bfd = flaginfo->output_bfd; |
4309 | 0 | check_dynamic_reloc = aout_backend_info (output_bfd)->check_dynamic_reloc; |
4310 | |
|
4311 | 0 | BFD_ASSERT (obj_reloc_entry_size (input_bfd) == RELOC_EXT_SIZE); |
4312 | 0 | BFD_ASSERT (input_bfd->xvec->header_byteorder |
4313 | 0 | == output_bfd->xvec->header_byteorder); |
4314 | |
|
4315 | 0 | relocatable = bfd_link_relocatable (flaginfo->info); |
4316 | 0 | syms = obj_aout_external_syms (input_bfd); |
4317 | 0 | strings = obj_aout_external_strings (input_bfd); |
4318 | 0 | sym_hashes = obj_aout_sym_hashes (input_bfd); |
4319 | 0 | symbol_map = flaginfo->symbol_map; |
4320 | |
|
4321 | 0 | reloc_count = rel_size / RELOC_EXT_SIZE; |
4322 | 0 | rel = relocs; |
4323 | 0 | rel_end = rel + reloc_count; |
4324 | 0 | for (; rel < rel_end; rel++) |
4325 | 0 | { |
4326 | 0 | bfd_vma r_addr; |
4327 | 0 | unsigned int r_index; |
4328 | 0 | int r_extern; |
4329 | 0 | unsigned int r_type; |
4330 | 0 | bfd_vma r_addend; |
4331 | 0 | struct aout_link_hash_entry *h = NULL; |
4332 | 0 | asection *r_section = NULL; |
4333 | 0 | bfd_vma relocation; |
4334 | |
|
4335 | 0 | r_addr = GET_SWORD (input_bfd, rel->r_address); |
4336 | |
|
4337 | 0 | if (bfd_header_big_endian (input_bfd)) |
4338 | 0 | { |
4339 | 0 | r_index = (((unsigned int) rel->r_index[0] << 16) |
4340 | 0 | | ((unsigned int) rel->r_index[1] << 8) |
4341 | 0 | | rel->r_index[2]); |
4342 | 0 | r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_BIG)); |
4343 | 0 | r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_BIG) |
4344 | 0 | >> RELOC_EXT_BITS_TYPE_SH_BIG); |
4345 | 0 | } |
4346 | 0 | else |
4347 | 0 | { |
4348 | 0 | r_index = (((unsigned int) rel->r_index[2] << 16) |
4349 | 0 | | ((unsigned int) rel->r_index[1] << 8) |
4350 | 0 | | rel->r_index[0]); |
4351 | 0 | r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE)); |
4352 | 0 | r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE) |
4353 | 0 | >> RELOC_EXT_BITS_TYPE_SH_LITTLE); |
4354 | 0 | } |
4355 | |
|
4356 | 0 | r_addend = GET_SWORD (input_bfd, rel->r_addend); |
4357 | |
|
4358 | 0 | if (r_type >= TABLE_SIZE (howto_table_ext)) |
4359 | 0 | { |
4360 | 0 | _bfd_error_handler (_("%pB: unsupported relocation type %#x"), |
4361 | 0 | input_bfd, r_type); |
4362 | 0 | bfd_set_error (bfd_error_bad_value); |
4363 | 0 | return false; |
4364 | 0 | } |
4365 | | |
4366 | 0 | if (relocatable) |
4367 | 0 | { |
4368 | | /* We are generating a relocatable output file, and must |
4369 | | modify the reloc accordingly. */ |
4370 | 0 | if (r_extern |
4371 | 0 | || r_type == (unsigned int) RELOC_BASE10 |
4372 | 0 | || r_type == (unsigned int) RELOC_BASE13 |
4373 | 0 | || r_type == (unsigned int) RELOC_BASE22) |
4374 | 0 | { |
4375 | | /* If we know the symbol this relocation is against, |
4376 | | convert it into a relocation against a section. This |
4377 | | is what the native linker does. */ |
4378 | 0 | if (r_type == (unsigned int) RELOC_BASE10 |
4379 | 0 | || r_type == (unsigned int) RELOC_BASE13 |
4380 | 0 | || r_type == (unsigned int) RELOC_BASE22) |
4381 | 0 | h = NULL; |
4382 | 0 | else |
4383 | 0 | h = sym_hashes[r_index]; |
4384 | 0 | if (h != NULL |
4385 | 0 | && (h->root.type == bfd_link_hash_defined |
4386 | 0 | || h->root.type == bfd_link_hash_defweak)) |
4387 | 0 | { |
4388 | 0 | asection *output_section; |
4389 | | |
4390 | | /* Change the r_extern value. */ |
4391 | 0 | if (bfd_header_big_endian (output_bfd)) |
4392 | 0 | rel->r_type[0] &=~ RELOC_EXT_BITS_EXTERN_BIG; |
4393 | 0 | else |
4394 | 0 | rel->r_type[0] &=~ RELOC_EXT_BITS_EXTERN_LITTLE; |
4395 | | |
4396 | | /* Compute a new r_index. */ |
4397 | 0 | output_section = h->root.u.def.section->output_section; |
4398 | 0 | if (output_section == obj_textsec (output_bfd)) |
4399 | 0 | r_index = N_TEXT; |
4400 | 0 | else if (output_section == obj_datasec (output_bfd)) |
4401 | 0 | r_index = N_DATA; |
4402 | 0 | else if (output_section == obj_bsssec (output_bfd)) |
4403 | 0 | r_index = N_BSS; |
4404 | 0 | else |
4405 | 0 | r_index = N_ABS; |
4406 | | |
4407 | | /* Add the symbol value and the section VMA to the |
4408 | | addend. */ |
4409 | 0 | relocation = (h->root.u.def.value |
4410 | 0 | + output_section->vma |
4411 | 0 | + h->root.u.def.section->output_offset); |
4412 | | |
4413 | | /* Now RELOCATION is the VMA of the final |
4414 | | destination. If this is a PC relative reloc, |
4415 | | then ADDEND is the negative of the source VMA. |
4416 | | We want to set ADDEND to the difference between |
4417 | | the destination VMA and the source VMA, which |
4418 | | means we must adjust RELOCATION by the change in |
4419 | | the source VMA. This is done below. */ |
4420 | 0 | } |
4421 | 0 | else |
4422 | 0 | { |
4423 | | /* We must change r_index according to the symbol |
4424 | | map. */ |
4425 | 0 | r_index = symbol_map[r_index]; |
4426 | |
|
4427 | 0 | if (r_index == -1u) |
4428 | 0 | { |
4429 | 0 | if (h != NULL) |
4430 | 0 | { |
4431 | | /* We decided to strip this symbol, but it |
4432 | | turns out that we can't. Note that we |
4433 | | lose the other and desc information here. |
4434 | | I don't think that will ever matter for a |
4435 | | global symbol. */ |
4436 | 0 | if (h->indx < 0) |
4437 | 0 | { |
4438 | 0 | h->indx = -2; |
4439 | 0 | h->written = false; |
4440 | 0 | if (!aout_link_write_other_symbol (&h->root.root, |
4441 | 0 | flaginfo)) |
4442 | 0 | return false; |
4443 | 0 | } |
4444 | 0 | r_index = h->indx; |
4445 | 0 | } |
4446 | 0 | else |
4447 | 0 | { |
4448 | 0 | const char *name; |
4449 | |
|
4450 | 0 | name = strings + GET_WORD (input_bfd, |
4451 | 0 | syms[r_index].e_strx); |
4452 | 0 | (*flaginfo->info->callbacks->unattached_reloc) |
4453 | 0 | (flaginfo->info, name, |
4454 | 0 | input_bfd, input_section, r_addr); |
4455 | 0 | r_index = 0; |
4456 | 0 | } |
4457 | 0 | } |
4458 | | |
4459 | 0 | relocation = 0; |
4460 | | |
4461 | | /* If this is a PC relative reloc, then the addend |
4462 | | is the negative of the source VMA. We must |
4463 | | adjust it by the change in the source VMA. This |
4464 | | is done below. */ |
4465 | 0 | } |
4466 | | |
4467 | | /* Write out the new r_index value. */ |
4468 | 0 | if (bfd_header_big_endian (output_bfd)) |
4469 | 0 | { |
4470 | 0 | rel->r_index[0] = r_index >> 16; |
4471 | 0 | rel->r_index[1] = r_index >> 8; |
4472 | 0 | rel->r_index[2] = r_index; |
4473 | 0 | } |
4474 | 0 | else |
4475 | 0 | { |
4476 | 0 | rel->r_index[2] = r_index >> 16; |
4477 | 0 | rel->r_index[1] = r_index >> 8; |
4478 | 0 | rel->r_index[0] = r_index; |
4479 | 0 | } |
4480 | 0 | } |
4481 | 0 | else |
4482 | 0 | { |
4483 | | /* This is a relocation against a section. We must |
4484 | | adjust by the amount that the section moved. */ |
4485 | 0 | r_section = aout_reloc_index_to_section (input_bfd, r_index); |
4486 | 0 | relocation = (r_section->output_section->vma |
4487 | 0 | + r_section->output_offset |
4488 | 0 | - r_section->vma); |
4489 | | |
4490 | | /* If this is a PC relative reloc, then the addend is |
4491 | | the difference in VMA between the destination and the |
4492 | | source. We have just adjusted for the change in VMA |
4493 | | of the destination, so we must also adjust by the |
4494 | | change in VMA of the source. This is done below. */ |
4495 | 0 | } |
4496 | | |
4497 | | /* As described above, we must always adjust a PC relative |
4498 | | reloc by the change in VMA of the source. However, if |
4499 | | pcrel_offset is set, then the addend does not include the |
4500 | | location within the section, in which case we don't need |
4501 | | to adjust anything. */ |
4502 | 0 | if (howto_table_ext[r_type].pc_relative |
4503 | 0 | && ! howto_table_ext[r_type].pcrel_offset) |
4504 | 0 | relocation -= (input_section->output_section->vma |
4505 | 0 | + input_section->output_offset |
4506 | 0 | - input_section->vma); |
4507 | | |
4508 | | /* Change the addend if necessary. */ |
4509 | 0 | if (relocation != 0) |
4510 | 0 | PUT_WORD (output_bfd, r_addend + relocation, rel->r_addend); |
4511 | | |
4512 | | /* Change the address of the relocation. */ |
4513 | 0 | PUT_WORD (output_bfd, |
4514 | 0 | r_addr + input_section->output_offset, |
4515 | 0 | rel->r_address); |
4516 | 0 | } |
4517 | 0 | else |
4518 | 0 | { |
4519 | 0 | bool hundef; |
4520 | 0 | bfd_reloc_status_type r; |
4521 | | |
4522 | | /* We are generating an executable, and must do a full |
4523 | | relocation. */ |
4524 | 0 | hundef = false; |
4525 | |
|
4526 | 0 | if (r_extern) |
4527 | 0 | { |
4528 | 0 | h = sym_hashes[r_index]; |
4529 | |
|
4530 | 0 | if (h != NULL |
4531 | 0 | && (h->root.type == bfd_link_hash_defined |
4532 | 0 | || h->root.type == bfd_link_hash_defweak)) |
4533 | 0 | { |
4534 | 0 | relocation = (h->root.u.def.value |
4535 | 0 | + h->root.u.def.section->output_section->vma |
4536 | 0 | + h->root.u.def.section->output_offset); |
4537 | 0 | } |
4538 | 0 | else if (h != NULL |
4539 | 0 | && h->root.type == bfd_link_hash_undefweak) |
4540 | 0 | relocation = 0; |
4541 | 0 | else |
4542 | 0 | { |
4543 | 0 | hundef = true; |
4544 | 0 | relocation = 0; |
4545 | 0 | } |
4546 | 0 | } |
4547 | 0 | else if (r_type == (unsigned int) RELOC_BASE10 |
4548 | 0 | || r_type == (unsigned int) RELOC_BASE13 |
4549 | 0 | || r_type == (unsigned int) RELOC_BASE22) |
4550 | 0 | { |
4551 | 0 | struct external_nlist *sym; |
4552 | 0 | int type; |
4553 | | |
4554 | | /* For base relative relocs, r_index is always an index |
4555 | | into the symbol table, even if r_extern is 0. */ |
4556 | 0 | sym = syms + r_index; |
4557 | 0 | type = H_GET_8 (input_bfd, sym->e_type); |
4558 | 0 | if ((type & N_TYPE) == N_TEXT |
4559 | 0 | || type == N_WEAKT) |
4560 | 0 | r_section = obj_textsec (input_bfd); |
4561 | 0 | else if ((type & N_TYPE) == N_DATA |
4562 | 0 | || type == N_WEAKD) |
4563 | 0 | r_section = obj_datasec (input_bfd); |
4564 | 0 | else if ((type & N_TYPE) == N_BSS |
4565 | 0 | || type == N_WEAKB) |
4566 | 0 | r_section = obj_bsssec (input_bfd); |
4567 | 0 | else if ((type & N_TYPE) == N_ABS |
4568 | 0 | || type == N_WEAKA) |
4569 | 0 | r_section = bfd_abs_section_ptr; |
4570 | 0 | else |
4571 | 0 | abort (); |
4572 | 0 | relocation = (r_section->output_section->vma |
4573 | 0 | + r_section->output_offset |
4574 | 0 | + (GET_WORD (input_bfd, sym->e_value) |
4575 | 0 | - r_section->vma)); |
4576 | 0 | } |
4577 | 0 | else |
4578 | 0 | { |
4579 | 0 | r_section = aout_reloc_index_to_section (input_bfd, r_index); |
4580 | | |
4581 | | /* If this is a PC relative reloc, then R_ADDEND is the |
4582 | | difference between the two vmas, or |
4583 | | old_dest_sec + old_dest_off - (old_src_sec + old_src_off) |
4584 | | where |
4585 | | old_dest_sec == section->vma |
4586 | | and |
4587 | | old_src_sec == input_section->vma |
4588 | | and |
4589 | | old_src_off == r_addr |
4590 | | |
4591 | | _bfd_final_link_relocate expects RELOCATION + |
4592 | | R_ADDEND to be the VMA of the destination minus |
4593 | | r_addr (the minus r_addr is because this relocation |
4594 | | is not pcrel_offset, which is a bit confusing and |
4595 | | should, perhaps, be changed), or |
4596 | | new_dest_sec |
4597 | | where |
4598 | | new_dest_sec == output_section->vma + output_offset |
4599 | | We arrange for this to happen by setting RELOCATION to |
4600 | | new_dest_sec + old_src_sec - old_dest_sec |
4601 | | |
4602 | | If this is not a PC relative reloc, then R_ADDEND is |
4603 | | simply the VMA of the destination, so we set |
4604 | | RELOCATION to the change in the destination VMA, or |
4605 | | new_dest_sec - old_dest_sec |
4606 | | */ |
4607 | 0 | relocation = (r_section->output_section->vma |
4608 | 0 | + r_section->output_offset |
4609 | 0 | - r_section->vma); |
4610 | 0 | if (howto_table_ext[r_type].pc_relative) |
4611 | 0 | relocation += input_section->vma; |
4612 | 0 | } |
4613 | | |
4614 | 0 | if (check_dynamic_reloc != NULL) |
4615 | 0 | { |
4616 | 0 | bool skip; |
4617 | |
|
4618 | 0 | if (! ((*check_dynamic_reloc) |
4619 | 0 | (flaginfo->info, input_bfd, input_section, h, |
4620 | 0 | (void *) rel, contents, &skip, &relocation))) |
4621 | 0 | return false; |
4622 | 0 | if (skip) |
4623 | 0 | continue; |
4624 | 0 | } |
4625 | | |
4626 | | /* Now warn if a global symbol is undefined. We could not |
4627 | | do this earlier, because check_dynamic_reloc might want |
4628 | | to skip this reloc. */ |
4629 | 0 | if (hundef |
4630 | 0 | && ! bfd_link_pic (flaginfo->info) |
4631 | 0 | && r_type != (unsigned int) RELOC_BASE10 |
4632 | 0 | && r_type != (unsigned int) RELOC_BASE13 |
4633 | 0 | && r_type != (unsigned int) RELOC_BASE22) |
4634 | 0 | { |
4635 | 0 | const char *name; |
4636 | |
|
4637 | 0 | if (h != NULL) |
4638 | 0 | name = h->root.root.string; |
4639 | 0 | else |
4640 | 0 | name = strings + GET_WORD (input_bfd, syms[r_index].e_strx); |
4641 | 0 | (*flaginfo->info->callbacks->undefined_symbol) |
4642 | 0 | (flaginfo->info, name, input_bfd, input_section, r_addr, true); |
4643 | 0 | } |
4644 | |
|
4645 | 0 | if (r_type != (unsigned int) RELOC_SPARC_REV32) |
4646 | 0 | r = MY_final_link_relocate (howto_table_ext + r_type, |
4647 | 0 | input_bfd, input_section, |
4648 | 0 | contents, r_addr, relocation, |
4649 | 0 | r_addend); |
4650 | 0 | else |
4651 | 0 | { |
4652 | 0 | bfd_vma x; |
4653 | |
|
4654 | 0 | x = bfd_get_32 (input_bfd, contents + r_addr); |
4655 | 0 | x = x + relocation + r_addend; |
4656 | 0 | bfd_putl32 (/*input_bfd,*/ x, contents + r_addr); |
4657 | 0 | r = bfd_reloc_ok; |
4658 | 0 | } |
4659 | |
|
4660 | 0 | if (r != bfd_reloc_ok) |
4661 | 0 | { |
4662 | 0 | switch (r) |
4663 | 0 | { |
4664 | 0 | default: |
4665 | 0 | case bfd_reloc_outofrange: |
4666 | 0 | abort (); |
4667 | 0 | case bfd_reloc_overflow: |
4668 | 0 | { |
4669 | 0 | const char *name; |
4670 | |
|
4671 | 0 | if (h != NULL) |
4672 | 0 | name = NULL; |
4673 | 0 | else if (r_extern |
4674 | 0 | || r_type == (unsigned int) RELOC_BASE10 |
4675 | 0 | || r_type == (unsigned int) RELOC_BASE13 |
4676 | 0 | || r_type == (unsigned int) RELOC_BASE22) |
4677 | 0 | name = strings + GET_WORD (input_bfd, |
4678 | 0 | syms[r_index].e_strx); |
4679 | 0 | else |
4680 | 0 | { |
4681 | 0 | asection *s; |
4682 | |
|
4683 | 0 | s = aout_reloc_index_to_section (input_bfd, r_index); |
4684 | 0 | name = bfd_section_name (s); |
4685 | 0 | } |
4686 | 0 | (*flaginfo->info->callbacks->reloc_overflow) |
4687 | 0 | (flaginfo->info, (h ? &h->root : NULL), name, |
4688 | 0 | howto_table_ext[r_type].name, |
4689 | 0 | r_addend, input_bfd, input_section, r_addr); |
4690 | 0 | } |
4691 | 0 | break; |
4692 | 0 | } |
4693 | 0 | } |
4694 | 0 | } |
4695 | 0 | } |
4696 | | |
4697 | 0 | return true; |
4698 | 0 | } Unexecuted instantiation: aout-cris.c:aout_link_input_section_ext Unexecuted instantiation: aout-ns32k.c:aout_link_input_section_ext Unexecuted instantiation: aout32.c:aout_link_input_section_ext |
4699 | | |
4700 | | /* Link an a.out section into the output file. */ |
4701 | | |
4702 | | static bool |
4703 | | aout_link_input_section (struct aout_final_link_info *flaginfo, |
4704 | | bfd *input_bfd, |
4705 | | asection *input_section, |
4706 | | file_ptr *reloff_ptr, |
4707 | | bfd_size_type rel_size) |
4708 | 0 | { |
4709 | 0 | bfd_size_type input_size; |
4710 | 0 | void * relocs; |
4711 | | |
4712 | | /* Get the section contents. */ |
4713 | 0 | input_size = input_section->size; |
4714 | 0 | if (! bfd_get_section_contents (input_bfd, input_section, |
4715 | 0 | (void *) flaginfo->contents, |
4716 | 0 | (file_ptr) 0, input_size)) |
4717 | 0 | return false; |
4718 | | |
4719 | 0 | relocs = flaginfo->relocs; |
4720 | 0 | if (rel_size > 0) |
4721 | 0 | { |
4722 | 0 | if (bfd_seek (input_bfd, input_section->rel_filepos, SEEK_SET) != 0 |
4723 | 0 | || bfd_read (relocs, rel_size, input_bfd) != rel_size) |
4724 | 0 | return false; |
4725 | 0 | } |
4726 | | |
4727 | | /* Relocate the section contents. */ |
4728 | 0 | if (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE) |
4729 | 0 | { |
4730 | 0 | if (! aout_link_input_section_std (flaginfo, input_bfd, input_section, |
4731 | 0 | (struct reloc_std_external *) relocs, |
4732 | 0 | rel_size, flaginfo->contents)) |
4733 | 0 | return false; |
4734 | 0 | } |
4735 | 0 | else |
4736 | 0 | { |
4737 | 0 | if (! aout_link_input_section_ext (flaginfo, input_bfd, input_section, |
4738 | 0 | (struct reloc_ext_external *) relocs, |
4739 | 0 | rel_size, flaginfo->contents)) |
4740 | 0 | return false; |
4741 | 0 | } |
4742 | | |
4743 | | /* Write out the section contents. */ |
4744 | 0 | if (! bfd_set_section_contents (flaginfo->output_bfd, |
4745 | 0 | input_section->output_section, |
4746 | 0 | (void *) flaginfo->contents, |
4747 | 0 | (file_ptr) input_section->output_offset, |
4748 | 0 | input_size)) |
4749 | 0 | return false; |
4750 | | |
4751 | | /* If we are producing relocatable output, the relocs were |
4752 | | modified, and we now write them out. */ |
4753 | 0 | if (bfd_link_relocatable (flaginfo->info) && rel_size > 0) |
4754 | 0 | { |
4755 | 0 | if (bfd_seek (flaginfo->output_bfd, *reloff_ptr, SEEK_SET) != 0) |
4756 | 0 | return false; |
4757 | 0 | if (bfd_write (relocs, rel_size, flaginfo->output_bfd) != rel_size) |
4758 | 0 | return false; |
4759 | 0 | *reloff_ptr += rel_size; |
4760 | | |
4761 | | /* Assert that the relocs have not run into the symbols, and |
4762 | | that if these are the text relocs they have not run into the |
4763 | | data relocs. */ |
4764 | 0 | BFD_ASSERT (*reloff_ptr <= obj_sym_filepos (flaginfo->output_bfd) |
4765 | 0 | && (reloff_ptr != &flaginfo->treloff |
4766 | 0 | || (*reloff_ptr |
4767 | 0 | <= obj_datasec (flaginfo->output_bfd)->rel_filepos))); |
4768 | 0 | } |
4769 | | |
4770 | 0 | return true; |
4771 | 0 | } Unexecuted instantiation: aout-cris.c:aout_link_input_section Unexecuted instantiation: aout-ns32k.c:aout_link_input_section Unexecuted instantiation: aout32.c:aout_link_input_section |
4772 | | |
4773 | | /* Adjust and write out the symbols for an a.out file. Set the new |
4774 | | symbol indices into a symbol_map. */ |
4775 | | |
4776 | | static bool |
4777 | | aout_link_write_symbols (struct aout_final_link_info *flaginfo, bfd *input_bfd) |
4778 | 0 | { |
4779 | 0 | bfd *output_bfd; |
4780 | 0 | bfd_size_type sym_count; |
4781 | 0 | char *strings; |
4782 | 0 | enum bfd_link_strip strip; |
4783 | 0 | enum bfd_link_discard discard; |
4784 | 0 | struct external_nlist *outsym; |
4785 | 0 | bfd_size_type strtab_index; |
4786 | 0 | struct external_nlist *sym; |
4787 | 0 | struct external_nlist *sym_end; |
4788 | 0 | struct aout_link_hash_entry **sym_hash; |
4789 | 0 | int *symbol_map; |
4790 | 0 | bool pass; |
4791 | 0 | bool skip_next; |
4792 | |
|
4793 | 0 | output_bfd = flaginfo->output_bfd; |
4794 | 0 | sym_count = obj_aout_external_sym_count (input_bfd); |
4795 | 0 | strings = obj_aout_external_strings (input_bfd); |
4796 | 0 | strip = flaginfo->info->strip; |
4797 | 0 | discard = flaginfo->info->discard; |
4798 | 0 | outsym = flaginfo->output_syms; |
4799 | | |
4800 | | /* First write out a symbol for this object file, unless we are |
4801 | | discarding such symbols. */ |
4802 | 0 | if (strip != strip_all |
4803 | 0 | && (strip != strip_some |
4804 | 0 | || bfd_hash_lookup (flaginfo->info->keep_hash, |
4805 | 0 | bfd_get_filename (input_bfd), |
4806 | 0 | false, false) != NULL) |
4807 | 0 | && discard != discard_all) |
4808 | 0 | { |
4809 | 0 | H_PUT_8 (output_bfd, N_TEXT, outsym->e_type); |
4810 | 0 | H_PUT_8 (output_bfd, 0, outsym->e_other); |
4811 | 0 | H_PUT_16 (output_bfd, 0, outsym->e_desc); |
4812 | 0 | strtab_index = add_to_stringtab (output_bfd, flaginfo->strtab, |
4813 | 0 | bfd_get_filename (input_bfd), false); |
4814 | 0 | if (strtab_index == (bfd_size_type) -1) |
4815 | 0 | return false; |
4816 | 0 | PUT_WORD (output_bfd, strtab_index, outsym->e_strx); |
4817 | 0 | PUT_WORD (output_bfd, |
4818 | 0 | (bfd_section_vma (obj_textsec (input_bfd)->output_section) |
4819 | 0 | + obj_textsec (input_bfd)->output_offset), |
4820 | 0 | outsym->e_value); |
4821 | 0 | ++obj_aout_external_sym_count (output_bfd); |
4822 | 0 | ++outsym; |
4823 | 0 | } |
4824 | | |
4825 | 0 | pass = false; |
4826 | 0 | skip_next = false; |
4827 | 0 | sym = obj_aout_external_syms (input_bfd); |
4828 | 0 | sym_end = sym + sym_count; |
4829 | 0 | sym_hash = obj_aout_sym_hashes (input_bfd); |
4830 | 0 | symbol_map = flaginfo->symbol_map; |
4831 | 0 | memset (symbol_map, 0, (size_t) sym_count * sizeof *symbol_map); |
4832 | 0 | for (; sym < sym_end; sym++, sym_hash++, symbol_map++) |
4833 | 0 | { |
4834 | 0 | const char *name; |
4835 | 0 | int type; |
4836 | 0 | struct aout_link_hash_entry *h; |
4837 | 0 | bool skip; |
4838 | 0 | asection *symsec; |
4839 | 0 | bfd_vma val = 0; |
4840 | 0 | bool copy; |
4841 | | |
4842 | | /* We set *symbol_map to 0 above for all symbols. If it has |
4843 | | already been set to -1 for this symbol, it means that we are |
4844 | | discarding it because it appears in a duplicate header file. |
4845 | | See the N_BINCL code below. */ |
4846 | 0 | if (*symbol_map == -1) |
4847 | 0 | continue; |
4848 | | |
4849 | | /* Initialize *symbol_map to -1, which means that the symbol was |
4850 | | not copied into the output file. We will change it later if |
4851 | | we do copy the symbol over. */ |
4852 | 0 | *symbol_map = -1; |
4853 | |
|
4854 | 0 | type = H_GET_8 (input_bfd, sym->e_type); |
4855 | 0 | name = strings + GET_WORD (input_bfd, sym->e_strx); |
4856 | |
|
4857 | 0 | h = NULL; |
4858 | |
|
4859 | 0 | if (pass) |
4860 | 0 | { |
4861 | | /* Pass this symbol through. It is the target of an |
4862 | | indirect or warning symbol. */ |
4863 | 0 | val = GET_WORD (input_bfd, sym->e_value); |
4864 | 0 | pass = false; |
4865 | 0 | } |
4866 | 0 | else if (skip_next) |
4867 | 0 | { |
4868 | | /* Skip this symbol, which is the target of an indirect |
4869 | | symbol that we have changed to no longer be an indirect |
4870 | | symbol. */ |
4871 | 0 | skip_next = false; |
4872 | 0 | continue; |
4873 | 0 | } |
4874 | 0 | else |
4875 | 0 | { |
4876 | 0 | struct aout_link_hash_entry *hresolve; |
4877 | | |
4878 | | /* We have saved the hash table entry for this symbol, if |
4879 | | there is one. Note that we could just look it up again |
4880 | | in the hash table, provided we first check that it is an |
4881 | | external symbol. */ |
4882 | 0 | h = *sym_hash; |
4883 | | |
4884 | | /* Use the name from the hash table, in case the symbol was |
4885 | | wrapped. */ |
4886 | 0 | if (h != NULL |
4887 | 0 | && h->root.type != bfd_link_hash_warning) |
4888 | 0 | name = h->root.root.string; |
4889 | | |
4890 | | /* If this is an indirect or warning symbol, then change |
4891 | | hresolve to the base symbol. We also change *sym_hash so |
4892 | | that the relocation routines relocate against the real |
4893 | | symbol. */ |
4894 | 0 | hresolve = h; |
4895 | 0 | if (h != (struct aout_link_hash_entry *) NULL |
4896 | 0 | && (h->root.type == bfd_link_hash_indirect |
4897 | 0 | || h->root.type == bfd_link_hash_warning)) |
4898 | 0 | { |
4899 | 0 | hresolve = (struct aout_link_hash_entry *) h->root.u.i.link; |
4900 | 0 | while (hresolve->root.type == bfd_link_hash_indirect |
4901 | 0 | || hresolve->root.type == bfd_link_hash_warning) |
4902 | 0 | hresolve = ((struct aout_link_hash_entry *) |
4903 | 0 | hresolve->root.u.i.link); |
4904 | 0 | *sym_hash = hresolve; |
4905 | 0 | } |
4906 | | |
4907 | | /* If the symbol has already been written out, skip it. */ |
4908 | 0 | if (h != NULL |
4909 | 0 | && h->written) |
4910 | 0 | { |
4911 | 0 | if ((type & N_TYPE) == N_INDR |
4912 | 0 | || type == N_WARNING) |
4913 | 0 | skip_next = true; |
4914 | 0 | *symbol_map = h->indx; |
4915 | 0 | continue; |
4916 | 0 | } |
4917 | | |
4918 | | /* See if we are stripping this symbol. */ |
4919 | 0 | skip = false; |
4920 | 0 | switch (strip) |
4921 | 0 | { |
4922 | 0 | case strip_none: |
4923 | 0 | break; |
4924 | 0 | case strip_debugger: |
4925 | 0 | if ((type & N_STAB) != 0) |
4926 | 0 | skip = true; |
4927 | 0 | break; |
4928 | 0 | case strip_some: |
4929 | 0 | if (bfd_hash_lookup (flaginfo->info->keep_hash, name, false, false) |
4930 | 0 | == NULL) |
4931 | 0 | skip = true; |
4932 | 0 | break; |
4933 | 0 | case strip_all: |
4934 | 0 | skip = true; |
4935 | 0 | break; |
4936 | 0 | } |
4937 | 0 | if (skip) |
4938 | 0 | { |
4939 | 0 | if (h != NULL) |
4940 | 0 | h->written = true; |
4941 | 0 | continue; |
4942 | 0 | } |
4943 | | |
4944 | | /* Get the value of the symbol. */ |
4945 | 0 | if ((type & N_TYPE) == N_TEXT |
4946 | 0 | || type == N_WEAKT) |
4947 | 0 | symsec = obj_textsec (input_bfd); |
4948 | 0 | else if ((type & N_TYPE) == N_DATA |
4949 | 0 | || type == N_WEAKD) |
4950 | 0 | symsec = obj_datasec (input_bfd); |
4951 | 0 | else if ((type & N_TYPE) == N_BSS |
4952 | 0 | || type == N_WEAKB) |
4953 | 0 | symsec = obj_bsssec (input_bfd); |
4954 | 0 | else if ((type & N_TYPE) == N_ABS |
4955 | 0 | || type == N_WEAKA) |
4956 | 0 | symsec = bfd_abs_section_ptr; |
4957 | 0 | else if (((type & N_TYPE) == N_INDR |
4958 | 0 | && (hresolve == NULL |
4959 | 0 | || (hresolve->root.type != bfd_link_hash_defined |
4960 | 0 | && hresolve->root.type != bfd_link_hash_defweak |
4961 | 0 | && hresolve->root.type != bfd_link_hash_common))) |
4962 | 0 | || type == N_WARNING) |
4963 | 0 | { |
4964 | | /* Pass the next symbol through unchanged. The |
4965 | | condition above for indirect symbols is so that if |
4966 | | the indirect symbol was defined, we output it with |
4967 | | the correct definition so the debugger will |
4968 | | understand it. */ |
4969 | 0 | pass = true; |
4970 | 0 | val = GET_WORD (input_bfd, sym->e_value); |
4971 | 0 | symsec = NULL; |
4972 | 0 | } |
4973 | 0 | else if ((type & N_STAB) != 0) |
4974 | 0 | { |
4975 | 0 | val = GET_WORD (input_bfd, sym->e_value); |
4976 | 0 | symsec = NULL; |
4977 | 0 | } |
4978 | 0 | else |
4979 | 0 | { |
4980 | | /* If we get here with an indirect symbol, it means that |
4981 | | we are outputting it with a real definition. In such |
4982 | | a case we do not want to output the next symbol, |
4983 | | which is the target of the indirection. */ |
4984 | 0 | if ((type & N_TYPE) == N_INDR) |
4985 | 0 | skip_next = true; |
4986 | |
|
4987 | 0 | symsec = NULL; |
4988 | | |
4989 | | /* We need to get the value from the hash table. We use |
4990 | | hresolve so that if we have defined an indirect |
4991 | | symbol we output the final definition. */ |
4992 | 0 | if (h == NULL) |
4993 | 0 | { |
4994 | 0 | switch (type & N_TYPE) |
4995 | 0 | { |
4996 | 0 | case N_SETT: |
4997 | 0 | symsec = obj_textsec (input_bfd); |
4998 | 0 | break; |
4999 | 0 | case N_SETD: |
5000 | 0 | symsec = obj_datasec (input_bfd); |
5001 | 0 | break; |
5002 | 0 | case N_SETB: |
5003 | 0 | symsec = obj_bsssec (input_bfd); |
5004 | 0 | break; |
5005 | 0 | case N_SETA: |
5006 | 0 | symsec = bfd_abs_section_ptr; |
5007 | 0 | break; |
5008 | 0 | default: |
5009 | 0 | val = 0; |
5010 | 0 | break; |
5011 | 0 | } |
5012 | 0 | } |
5013 | 0 | else if (hresolve->root.type == bfd_link_hash_defined |
5014 | 0 | || hresolve->root.type == bfd_link_hash_defweak) |
5015 | 0 | { |
5016 | 0 | asection *input_section; |
5017 | 0 | asection *output_section; |
5018 | | |
5019 | | /* This case usually means a common symbol which was |
5020 | | turned into a defined symbol. */ |
5021 | 0 | input_section = hresolve->root.u.def.section; |
5022 | 0 | output_section = input_section->output_section; |
5023 | 0 | BFD_ASSERT (bfd_is_abs_section (output_section) |
5024 | 0 | || output_section->owner == output_bfd); |
5025 | 0 | val = (hresolve->root.u.def.value |
5026 | 0 | + bfd_section_vma (output_section) |
5027 | 0 | + input_section->output_offset); |
5028 | | |
5029 | | /* Get the correct type based on the section. If |
5030 | | this is a constructed set, force it to be |
5031 | | globally visible. */ |
5032 | 0 | if (type == N_SETT |
5033 | 0 | || type == N_SETD |
5034 | 0 | || type == N_SETB |
5035 | 0 | || type == N_SETA) |
5036 | 0 | type |= N_EXT; |
5037 | |
|
5038 | 0 | type &=~ N_TYPE; |
5039 | |
|
5040 | 0 | if (output_section == obj_textsec (output_bfd)) |
5041 | 0 | type |= (hresolve->root.type == bfd_link_hash_defined |
5042 | 0 | ? N_TEXT |
5043 | 0 | : N_WEAKT); |
5044 | 0 | else if (output_section == obj_datasec (output_bfd)) |
5045 | 0 | type |= (hresolve->root.type == bfd_link_hash_defined |
5046 | 0 | ? N_DATA |
5047 | 0 | : N_WEAKD); |
5048 | 0 | else if (output_section == obj_bsssec (output_bfd)) |
5049 | 0 | type |= (hresolve->root.type == bfd_link_hash_defined |
5050 | 0 | ? N_BSS |
5051 | 0 | : N_WEAKB); |
5052 | 0 | else |
5053 | 0 | type |= (hresolve->root.type == bfd_link_hash_defined |
5054 | 0 | ? N_ABS |
5055 | 0 | : N_WEAKA); |
5056 | 0 | } |
5057 | 0 | else if (hresolve->root.type == bfd_link_hash_common) |
5058 | 0 | val = hresolve->root.u.c.size; |
5059 | 0 | else if (hresolve->root.type == bfd_link_hash_undefweak) |
5060 | 0 | { |
5061 | 0 | val = 0; |
5062 | 0 | type = N_WEAKU; |
5063 | 0 | } |
5064 | 0 | else |
5065 | 0 | val = 0; |
5066 | 0 | } |
5067 | 0 | if (symsec != NULL) |
5068 | 0 | val = (symsec->output_section->vma |
5069 | 0 | + symsec->output_offset |
5070 | 0 | + (GET_WORD (input_bfd, sym->e_value) |
5071 | 0 | - symsec->vma)); |
5072 | | |
5073 | | /* If this is a global symbol set the written flag, and if |
5074 | | it is a local symbol see if we should discard it. */ |
5075 | 0 | if (h != NULL) |
5076 | 0 | { |
5077 | 0 | h->written = true; |
5078 | 0 | h->indx = obj_aout_external_sym_count (output_bfd); |
5079 | 0 | } |
5080 | 0 | else if ((type & N_TYPE) != N_SETT |
5081 | 0 | && (type & N_TYPE) != N_SETD |
5082 | 0 | && (type & N_TYPE) != N_SETB |
5083 | 0 | && (type & N_TYPE) != N_SETA) |
5084 | 0 | { |
5085 | 0 | switch (discard) |
5086 | 0 | { |
5087 | 0 | case discard_none: |
5088 | 0 | case discard_sec_merge: |
5089 | 0 | break; |
5090 | 0 | case discard_l: |
5091 | 0 | if ((type & N_STAB) == 0 |
5092 | 0 | && bfd_is_local_label_name (input_bfd, name)) |
5093 | 0 | skip = true; |
5094 | 0 | break; |
5095 | 0 | case discard_all: |
5096 | 0 | skip = true; |
5097 | 0 | break; |
5098 | 0 | } |
5099 | 0 | if (skip) |
5100 | 0 | { |
5101 | 0 | pass = false; |
5102 | 0 | continue; |
5103 | 0 | } |
5104 | 0 | } |
5105 | | |
5106 | | /* An N_BINCL symbol indicates the start of the stabs |
5107 | | entries for a header file. We need to scan ahead to the |
5108 | | next N_EINCL symbol, ignoring nesting, adding up all the |
5109 | | characters in the symbol names, not including the file |
5110 | | numbers in types (the first number after an open |
5111 | | parenthesis). */ |
5112 | 0 | if (type == (int) N_BINCL) |
5113 | 0 | { |
5114 | 0 | struct external_nlist *incl_sym; |
5115 | 0 | int nest; |
5116 | 0 | struct aout_link_includes_entry *incl_entry; |
5117 | 0 | struct aout_link_includes_totals *t; |
5118 | |
|
5119 | 0 | val = 0; |
5120 | 0 | nest = 0; |
5121 | 0 | for (incl_sym = sym + 1; incl_sym < sym_end; incl_sym++) |
5122 | 0 | { |
5123 | 0 | int incl_type; |
5124 | |
|
5125 | 0 | incl_type = H_GET_8 (input_bfd, incl_sym->e_type); |
5126 | 0 | if (incl_type == (int) N_EINCL) |
5127 | 0 | { |
5128 | 0 | if (nest == 0) |
5129 | 0 | break; |
5130 | 0 | --nest; |
5131 | 0 | } |
5132 | 0 | else if (incl_type == (int) N_BINCL) |
5133 | 0 | ++nest; |
5134 | 0 | else if (nest == 0) |
5135 | 0 | { |
5136 | 0 | const char *s; |
5137 | |
|
5138 | 0 | s = strings + GET_WORD (input_bfd, incl_sym->e_strx); |
5139 | 0 | for (; *s != '\0'; s++) |
5140 | 0 | { |
5141 | 0 | val += *s; |
5142 | 0 | if (*s == '(') |
5143 | 0 | { |
5144 | | /* Skip the file number. */ |
5145 | 0 | ++s; |
5146 | 0 | while (ISDIGIT (*s)) |
5147 | 0 | ++s; |
5148 | 0 | --s; |
5149 | 0 | } |
5150 | 0 | } |
5151 | 0 | } |
5152 | 0 | } |
5153 | | |
5154 | | /* If we have already included a header file with the |
5155 | | same value, then replace this one with an N_EXCL |
5156 | | symbol. */ |
5157 | 0 | copy = !flaginfo->info->keep_memory; |
5158 | 0 | incl_entry = aout_link_includes_lookup (&flaginfo->includes, |
5159 | 0 | name, true, copy); |
5160 | 0 | if (incl_entry == NULL) |
5161 | 0 | return false; |
5162 | 0 | for (t = incl_entry->totals; t != NULL; t = t->next) |
5163 | 0 | if (t->total == val) |
5164 | 0 | break; |
5165 | 0 | if (t == NULL) |
5166 | 0 | { |
5167 | | /* This is the first time we have seen this header |
5168 | | file with this set of stabs strings. */ |
5169 | 0 | t = (struct aout_link_includes_totals *) |
5170 | 0 | bfd_hash_allocate (&flaginfo->includes.root, |
5171 | 0 | sizeof *t); |
5172 | 0 | if (t == NULL) |
5173 | 0 | return false; |
5174 | 0 | t->total = val; |
5175 | 0 | t->next = incl_entry->totals; |
5176 | 0 | incl_entry->totals = t; |
5177 | 0 | } |
5178 | 0 | else |
5179 | 0 | { |
5180 | 0 | int *incl_map; |
5181 | | |
5182 | | /* This is a duplicate header file. We must change |
5183 | | it to be an N_EXCL entry, and mark all the |
5184 | | included symbols to prevent outputting them. */ |
5185 | 0 | type = (int) N_EXCL; |
5186 | |
|
5187 | 0 | nest = 0; |
5188 | 0 | for (incl_sym = sym + 1, incl_map = symbol_map + 1; |
5189 | 0 | incl_sym < sym_end; |
5190 | 0 | incl_sym++, incl_map++) |
5191 | 0 | { |
5192 | 0 | int incl_type; |
5193 | |
|
5194 | 0 | incl_type = H_GET_8 (input_bfd, incl_sym->e_type); |
5195 | 0 | if (incl_type == (int) N_EINCL) |
5196 | 0 | { |
5197 | 0 | if (nest == 0) |
5198 | 0 | { |
5199 | 0 | *incl_map = -1; |
5200 | 0 | break; |
5201 | 0 | } |
5202 | 0 | --nest; |
5203 | 0 | } |
5204 | 0 | else if (incl_type == (int) N_BINCL) |
5205 | 0 | ++nest; |
5206 | 0 | else if (nest == 0) |
5207 | 0 | *incl_map = -1; |
5208 | 0 | } |
5209 | 0 | } |
5210 | 0 | } |
5211 | 0 | } |
5212 | | |
5213 | | /* Copy this symbol into the list of symbols we are going to |
5214 | | write out. */ |
5215 | 0 | H_PUT_8 (output_bfd, type, outsym->e_type); |
5216 | 0 | H_PUT_8 (output_bfd, H_GET_8 (input_bfd, sym->e_other), outsym->e_other); |
5217 | 0 | H_PUT_16 (output_bfd, H_GET_16 (input_bfd, sym->e_desc), outsym->e_desc); |
5218 | 0 | copy = false; |
5219 | 0 | if (! flaginfo->info->keep_memory) |
5220 | 0 | { |
5221 | | /* name points into a string table which we are going to |
5222 | | free. If there is a hash table entry, use that string. |
5223 | | Otherwise, copy name into memory. */ |
5224 | 0 | if (h != NULL) |
5225 | 0 | name = h->root.root.string; |
5226 | 0 | else |
5227 | 0 | copy = true; |
5228 | 0 | } |
5229 | 0 | strtab_index = add_to_stringtab (output_bfd, flaginfo->strtab, |
5230 | 0 | name, copy); |
5231 | 0 | if (strtab_index == (bfd_size_type) -1) |
5232 | 0 | return false; |
5233 | 0 | PUT_WORD (output_bfd, strtab_index, outsym->e_strx); |
5234 | 0 | PUT_WORD (output_bfd, val, outsym->e_value); |
5235 | 0 | *symbol_map = obj_aout_external_sym_count (output_bfd); |
5236 | 0 | ++obj_aout_external_sym_count (output_bfd); |
5237 | 0 | ++outsym; |
5238 | 0 | } |
5239 | | |
5240 | | /* Write out the output symbols we have just constructed. */ |
5241 | 0 | if (outsym > flaginfo->output_syms) |
5242 | 0 | { |
5243 | 0 | bfd_size_type outsym_size; |
5244 | |
|
5245 | 0 | if (bfd_seek (output_bfd, flaginfo->symoff, SEEK_SET) != 0) |
5246 | 0 | return false; |
5247 | 0 | outsym_size = outsym - flaginfo->output_syms; |
5248 | 0 | outsym_size *= EXTERNAL_NLIST_SIZE; |
5249 | 0 | if (bfd_write (flaginfo->output_syms, outsym_size, output_bfd) |
5250 | 0 | != outsym_size) |
5251 | 0 | return false; |
5252 | 0 | flaginfo->symoff += outsym_size; |
5253 | 0 | } |
5254 | | |
5255 | 0 | return true; |
5256 | 0 | } Unexecuted instantiation: aout-cris.c:aout_link_write_symbols Unexecuted instantiation: aout-ns32k.c:aout_link_write_symbols Unexecuted instantiation: aout32.c:aout_link_write_symbols |
5257 | | |
5258 | | /* Link an a.out input BFD into the output file. */ |
5259 | | |
5260 | | static bool |
5261 | | aout_link_input_bfd (struct aout_final_link_info *flaginfo, bfd *input_bfd) |
5262 | 0 | { |
5263 | 0 | BFD_ASSERT (bfd_get_format (input_bfd) == bfd_object); |
5264 | | |
5265 | | /* If this is a dynamic object, it may need special handling. */ |
5266 | 0 | if ((input_bfd->flags & DYNAMIC) != 0 |
5267 | 0 | && aout_backend_info (input_bfd)->link_dynamic_object != NULL) |
5268 | 0 | return ((*aout_backend_info (input_bfd)->link_dynamic_object) |
5269 | 0 | (flaginfo->info, input_bfd)); |
5270 | | |
5271 | | /* Get the symbols. We probably have them already, unless |
5272 | | flaginfo->info->keep_memory is FALSE. */ |
5273 | 0 | if (! aout_get_external_symbols (input_bfd)) |
5274 | 0 | return false; |
5275 | | |
5276 | | /* Write out the symbols and get a map of the new indices. The map |
5277 | | is placed into flaginfo->symbol_map. */ |
5278 | 0 | if (! aout_link_write_symbols (flaginfo, input_bfd)) |
5279 | 0 | return false; |
5280 | | |
5281 | | /* Relocate and write out the sections. These functions use the |
5282 | | symbol map created by aout_link_write_symbols. The linker_mark |
5283 | | field will be set if these sections are to be included in the |
5284 | | link, which will normally be the case. */ |
5285 | 0 | if (obj_textsec (input_bfd)->linker_mark) |
5286 | 0 | { |
5287 | 0 | if (! aout_link_input_section (flaginfo, input_bfd, |
5288 | 0 | obj_textsec (input_bfd), |
5289 | 0 | &flaginfo->treloff, |
5290 | 0 | exec_hdr (input_bfd)->a_trsize)) |
5291 | 0 | return false; |
5292 | 0 | } |
5293 | 0 | if (obj_datasec (input_bfd)->linker_mark) |
5294 | 0 | { |
5295 | 0 | if (! aout_link_input_section (flaginfo, input_bfd, |
5296 | 0 | obj_datasec (input_bfd), |
5297 | 0 | &flaginfo->dreloff, |
5298 | 0 | exec_hdr (input_bfd)->a_drsize)) |
5299 | 0 | return false; |
5300 | 0 | } |
5301 | | |
5302 | | /* If we are not keeping memory, we don't need the symbols any |
5303 | | longer. We still need them if we are keeping memory, because the |
5304 | | strings in the hash table point into them. */ |
5305 | 0 | if (! flaginfo->info->keep_memory) |
5306 | 0 | { |
5307 | 0 | if (! aout_link_free_symbols (input_bfd)) |
5308 | 0 | return false; |
5309 | 0 | } |
5310 | | |
5311 | 0 | return true; |
5312 | 0 | } Unexecuted instantiation: aout-cris.c:aout_link_input_bfd Unexecuted instantiation: aout-ns32k.c:aout_link_input_bfd Unexecuted instantiation: aout32.c:aout_link_input_bfd |
5313 | | |
5314 | | /* Do the final link step. This is called on the output BFD. The |
5315 | | INFO structure should point to a list of BFDs linked through the |
5316 | | link.next field which can be used to find each BFD which takes part |
5317 | | in the output. Also, each section in ABFD should point to a list |
5318 | | of bfd_link_order structures which list all the input sections for |
5319 | | the output section. */ |
5320 | | |
5321 | | bool |
5322 | | NAME (aout, final_link) (bfd *abfd, |
5323 | | struct bfd_link_info *info, |
5324 | | void (*callback) (bfd *, file_ptr *, file_ptr *, file_ptr *)) |
5325 | 0 | { |
5326 | 0 | struct aout_final_link_info aout_info; |
5327 | 0 | bool includes_hash_initialized = false; |
5328 | 0 | bfd *sub; |
5329 | 0 | bfd_size_type trsize, drsize; |
5330 | 0 | bfd_size_type max_contents_size; |
5331 | 0 | bfd_size_type max_relocs_size; |
5332 | 0 | bfd_size_type max_sym_count; |
5333 | 0 | struct bfd_link_order *p; |
5334 | 0 | asection *o; |
5335 | 0 | bool have_link_order_relocs; |
5336 | |
|
5337 | 0 | if (bfd_link_pic (info)) |
5338 | 0 | abfd->flags |= DYNAMIC; |
5339 | |
|
5340 | 0 | aout_info.info = info; |
5341 | 0 | aout_info.output_bfd = abfd; |
5342 | 0 | aout_info.contents = NULL; |
5343 | 0 | aout_info.relocs = NULL; |
5344 | 0 | aout_info.symbol_map = NULL; |
5345 | 0 | aout_info.output_syms = NULL; |
5346 | |
|
5347 | 0 | if (!bfd_hash_table_init_n (&aout_info.includes.root, |
5348 | 0 | aout_link_includes_newfunc, |
5349 | 0 | sizeof (struct aout_link_includes_entry), |
5350 | 0 | 251)) |
5351 | 0 | goto error_return; |
5352 | 0 | includes_hash_initialized = true; |
5353 | | |
5354 | | /* Figure out the largest section size. Also, if generating |
5355 | | relocatable output, count the relocs. */ |
5356 | 0 | trsize = 0; |
5357 | 0 | drsize = 0; |
5358 | 0 | max_contents_size = 0; |
5359 | 0 | max_relocs_size = 0; |
5360 | 0 | max_sym_count = 0; |
5361 | 0 | for (sub = info->input_bfds; sub != NULL; sub = sub->link.next) |
5362 | 0 | { |
5363 | 0 | bfd_size_type sz; |
5364 | |
|
5365 | 0 | if (bfd_link_relocatable (info)) |
5366 | 0 | { |
5367 | 0 | if (bfd_get_flavour (sub) == bfd_target_aout_flavour) |
5368 | 0 | { |
5369 | 0 | trsize += exec_hdr (sub)->a_trsize; |
5370 | 0 | drsize += exec_hdr (sub)->a_drsize; |
5371 | 0 | } |
5372 | 0 | else |
5373 | 0 | { |
5374 | | /* FIXME: We need to identify the .text and .data sections |
5375 | | and call get_reloc_upper_bound and canonicalize_reloc to |
5376 | | work out the number of relocs needed, and then multiply |
5377 | | by the reloc size. */ |
5378 | 0 | _bfd_error_handler |
5379 | | /* xgettext:c-format */ |
5380 | 0 | (_("%pB: relocatable link from %s to %s not supported"), |
5381 | 0 | abfd, sub->xvec->name, abfd->xvec->name); |
5382 | 0 | bfd_set_error (bfd_error_invalid_operation); |
5383 | 0 | goto error_return; |
5384 | 0 | } |
5385 | 0 | } |
5386 | | |
5387 | 0 | if (bfd_get_flavour (sub) == bfd_target_aout_flavour) |
5388 | 0 | { |
5389 | 0 | sz = obj_textsec (sub)->size; |
5390 | 0 | if (sz > max_contents_size) |
5391 | 0 | max_contents_size = sz; |
5392 | 0 | sz = obj_datasec (sub)->size; |
5393 | 0 | if (sz > max_contents_size) |
5394 | 0 | max_contents_size = sz; |
5395 | |
|
5396 | 0 | sz = exec_hdr (sub)->a_trsize; |
5397 | 0 | if (sz > max_relocs_size) |
5398 | 0 | max_relocs_size = sz; |
5399 | 0 | sz = exec_hdr (sub)->a_drsize; |
5400 | 0 | if (sz > max_relocs_size) |
5401 | 0 | max_relocs_size = sz; |
5402 | |
|
5403 | 0 | sz = obj_aout_external_sym_count (sub); |
5404 | 0 | if (sz > max_sym_count) |
5405 | 0 | max_sym_count = sz; |
5406 | 0 | } |
5407 | 0 | } |
5408 | | |
5409 | 0 | if (bfd_link_relocatable (info)) |
5410 | 0 | { |
5411 | 0 | if (obj_textsec (abfd) != NULL) |
5412 | 0 | trsize += (_bfd_count_link_order_relocs (obj_textsec (abfd) |
5413 | 0 | ->map_head.link_order) |
5414 | 0 | * obj_reloc_entry_size (abfd)); |
5415 | 0 | if (obj_datasec (abfd) != NULL) |
5416 | 0 | drsize += (_bfd_count_link_order_relocs (obj_datasec (abfd) |
5417 | 0 | ->map_head.link_order) |
5418 | 0 | * obj_reloc_entry_size (abfd)); |
5419 | 0 | } |
5420 | |
|
5421 | 0 | exec_hdr (abfd)->a_trsize = trsize; |
5422 | 0 | exec_hdr (abfd)->a_drsize = drsize; |
5423 | |
|
5424 | 0 | exec_hdr (abfd)->a_entry = bfd_get_start_address (abfd); |
5425 | | |
5426 | | /* Adjust the section sizes and vmas according to the magic number. |
5427 | | This sets a_text, a_data and a_bss in the exec_hdr and sets the |
5428 | | filepos for each section. */ |
5429 | 0 | if (! NAME (aout, adjust_sizes_and_vmas) (abfd)) |
5430 | 0 | goto error_return; |
5431 | | |
5432 | | /* The relocation and symbol file positions differ among a.out |
5433 | | targets. We are passed a callback routine from the backend |
5434 | | specific code to handle this. |
5435 | | FIXME: At this point we do not know how much space the symbol |
5436 | | table will require. This will not work for any (nonstandard) |
5437 | | a.out target that needs to know the symbol table size before it |
5438 | | can compute the relocation file positions. */ |
5439 | 0 | (*callback) (abfd, &aout_info.treloff, &aout_info.dreloff, |
5440 | 0 | &aout_info.symoff); |
5441 | 0 | obj_textsec (abfd)->rel_filepos = aout_info.treloff; |
5442 | 0 | obj_datasec (abfd)->rel_filepos = aout_info.dreloff; |
5443 | 0 | obj_sym_filepos (abfd) = aout_info.symoff; |
5444 | | |
5445 | | /* We keep a count of the symbols as we output them. */ |
5446 | 0 | obj_aout_external_sym_count (abfd) = 0; |
5447 | | |
5448 | | /* We accumulate the string table as we write out the symbols. */ |
5449 | 0 | aout_info.strtab = _bfd_stringtab_init (); |
5450 | 0 | if (aout_info.strtab == NULL) |
5451 | 0 | goto error_return; |
5452 | | |
5453 | | /* Allocate buffers to hold section contents and relocs. */ |
5454 | 0 | aout_info.contents = (bfd_byte *) bfd_malloc (max_contents_size); |
5455 | 0 | aout_info.relocs = bfd_malloc (max_relocs_size); |
5456 | 0 | aout_info.symbol_map = (int *) bfd_malloc (max_sym_count * sizeof (int)); |
5457 | 0 | aout_info.output_syms = (struct external_nlist *) |
5458 | 0 | bfd_malloc ((max_sym_count + 1) * sizeof (struct external_nlist)); |
5459 | 0 | if ((aout_info.contents == NULL && max_contents_size != 0) |
5460 | 0 | || (aout_info.relocs == NULL && max_relocs_size != 0) |
5461 | 0 | || (aout_info.symbol_map == NULL && max_sym_count != 0) |
5462 | 0 | || aout_info.output_syms == NULL) |
5463 | 0 | goto error_return; |
5464 | | |
5465 | | /* If we have a symbol named __DYNAMIC, force it out now. This is |
5466 | | required by SunOS. Doing this here rather than in sunos.c is a |
5467 | | hack, but it's easier than exporting everything which would be |
5468 | | needed. */ |
5469 | 0 | { |
5470 | 0 | struct aout_link_hash_entry *h; |
5471 | |
|
5472 | 0 | h = aout_link_hash_lookup (aout_hash_table (info), "__DYNAMIC", |
5473 | 0 | false, false, false); |
5474 | 0 | if (h != NULL) |
5475 | 0 | aout_link_write_other_symbol (&h->root.root, &aout_info); |
5476 | 0 | } |
5477 | | |
5478 | | /* The most time efficient way to do the link would be to read all |
5479 | | the input object files into memory and then sort out the |
5480 | | information into the output file. Unfortunately, that will |
5481 | | probably use too much memory. Another method would be to step |
5482 | | through everything that composes the text section and write it |
5483 | | out, and then everything that composes the data section and write |
5484 | | it out, and then write out the relocs, and then write out the |
5485 | | symbols. Unfortunately, that requires reading stuff from each |
5486 | | input file several times, and we will not be able to keep all the |
5487 | | input files open simultaneously, and reopening them will be slow. |
5488 | | |
5489 | | What we do is basically process one input file at a time. We do |
5490 | | everything we need to do with an input file once--copy over the |
5491 | | section contents, handle the relocation information, and write |
5492 | | out the symbols--and then we throw away the information we read |
5493 | | from it. This approach requires a lot of lseeks of the output |
5494 | | file, which is unfortunate but still faster than reopening a lot |
5495 | | of files. |
5496 | | |
5497 | | We use the output_has_begun field of the input BFDs to see |
5498 | | whether we have already handled it. */ |
5499 | 0 | for (sub = info->input_bfds; sub != NULL; sub = sub->link.next) |
5500 | 0 | sub->output_has_begun = false; |
5501 | | |
5502 | | /* Mark all sections which are to be included in the link. This |
5503 | | will normally be every section. We need to do this so that we |
5504 | | can identify any sections which the linker has decided to not |
5505 | | include. */ |
5506 | 0 | for (o = abfd->sections; o != NULL; o = o->next) |
5507 | 0 | { |
5508 | 0 | for (p = o->map_head.link_order; p != NULL; p = p->next) |
5509 | 0 | if (p->type == bfd_indirect_link_order) |
5510 | 0 | p->u.indirect.section->linker_mark = true; |
5511 | 0 | } |
5512 | |
|
5513 | 0 | have_link_order_relocs = false; |
5514 | 0 | for (o = abfd->sections; o != NULL; o = o->next) |
5515 | 0 | { |
5516 | 0 | for (p = o->map_head.link_order; |
5517 | 0 | p != NULL; |
5518 | 0 | p = p->next) |
5519 | 0 | { |
5520 | 0 | if (p->type == bfd_indirect_link_order |
5521 | 0 | && (bfd_get_flavour (p->u.indirect.section->owner) |
5522 | 0 | == bfd_target_aout_flavour)) |
5523 | 0 | { |
5524 | 0 | bfd *input_bfd; |
5525 | |
|
5526 | 0 | input_bfd = p->u.indirect.section->owner; |
5527 | 0 | if (! input_bfd->output_has_begun) |
5528 | 0 | { |
5529 | 0 | if (! aout_link_input_bfd (&aout_info, input_bfd)) |
5530 | 0 | goto error_return; |
5531 | 0 | input_bfd->output_has_begun = true; |
5532 | 0 | } |
5533 | 0 | } |
5534 | 0 | else if (p->type == bfd_section_reloc_link_order |
5535 | 0 | || p->type == bfd_symbol_reloc_link_order) |
5536 | 0 | { |
5537 | | /* These are handled below. */ |
5538 | 0 | have_link_order_relocs = true; |
5539 | 0 | } |
5540 | 0 | else |
5541 | 0 | { |
5542 | 0 | if (! _bfd_default_link_order (abfd, info, o, p)) |
5543 | 0 | goto error_return; |
5544 | 0 | } |
5545 | 0 | } |
5546 | 0 | } |
5547 | | |
5548 | | /* Write out any symbols that we have not already written out. */ |
5549 | 0 | bfd_hash_traverse (&info->hash->table, |
5550 | 0 | aout_link_write_other_symbol, |
5551 | 0 | &aout_info); |
5552 | | |
5553 | | /* Now handle any relocs we were asked to create by the linker. |
5554 | | These did not come from any input file. We must do these after |
5555 | | we have written out all the symbols, so that we know the symbol |
5556 | | indices to use. */ |
5557 | 0 | if (have_link_order_relocs) |
5558 | 0 | { |
5559 | 0 | for (o = abfd->sections; o != NULL; o = o->next) |
5560 | 0 | { |
5561 | 0 | for (p = o->map_head.link_order; |
5562 | 0 | p != NULL; |
5563 | 0 | p = p->next) |
5564 | 0 | { |
5565 | 0 | if (p->type == bfd_section_reloc_link_order |
5566 | 0 | || p->type == bfd_symbol_reloc_link_order) |
5567 | 0 | { |
5568 | 0 | if (! aout_link_reloc_link_order (&aout_info, o, p)) |
5569 | 0 | goto error_return; |
5570 | 0 | } |
5571 | 0 | } |
5572 | 0 | } |
5573 | 0 | } |
5574 | | |
5575 | 0 | free (aout_info.contents); |
5576 | 0 | aout_info.contents = NULL; |
5577 | 0 | free (aout_info.relocs); |
5578 | 0 | aout_info.relocs = NULL; |
5579 | 0 | free (aout_info.symbol_map); |
5580 | 0 | aout_info.symbol_map = NULL; |
5581 | 0 | free (aout_info.output_syms); |
5582 | 0 | aout_info.output_syms = NULL; |
5583 | |
|
5584 | 0 | if (includes_hash_initialized) |
5585 | 0 | { |
5586 | 0 | bfd_hash_table_free (&aout_info.includes.root); |
5587 | 0 | includes_hash_initialized = false; |
5588 | 0 | } |
5589 | | |
5590 | | /* Finish up any dynamic linking we may be doing. */ |
5591 | 0 | if (aout_backend_info (abfd)->finish_dynamic_link != NULL) |
5592 | 0 | { |
5593 | 0 | if (! (*aout_backend_info (abfd)->finish_dynamic_link) (abfd, info)) |
5594 | 0 | goto error_return; |
5595 | 0 | } |
5596 | | |
5597 | | /* Update the header information. */ |
5598 | 0 | abfd->symcount = obj_aout_external_sym_count (abfd); |
5599 | 0 | exec_hdr (abfd)->a_syms = abfd->symcount * EXTERNAL_NLIST_SIZE; |
5600 | 0 | obj_str_filepos (abfd) = obj_sym_filepos (abfd) + exec_hdr (abfd)->a_syms; |
5601 | 0 | obj_textsec (abfd)->reloc_count = |
5602 | 0 | exec_hdr (abfd)->a_trsize / obj_reloc_entry_size (abfd); |
5603 | 0 | obj_datasec (abfd)->reloc_count = |
5604 | 0 | exec_hdr (abfd)->a_drsize / obj_reloc_entry_size (abfd); |
5605 | | |
5606 | | /* Write out the string table, unless there are no symbols. */ |
5607 | 0 | if (bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET) != 0) |
5608 | 0 | goto error_return; |
5609 | 0 | if (abfd->symcount > 0) |
5610 | 0 | { |
5611 | 0 | if (!emit_stringtab (abfd, aout_info.strtab)) |
5612 | 0 | goto error_return; |
5613 | 0 | } |
5614 | 0 | else |
5615 | 0 | { |
5616 | 0 | bfd_byte b[BYTES_IN_WORD]; |
5617 | |
|
5618 | 0 | memset (b, 0, BYTES_IN_WORD); |
5619 | 0 | if (bfd_write (b, BYTES_IN_WORD, abfd) != BYTES_IN_WORD) |
5620 | 0 | goto error_return; |
5621 | 0 | } |
5622 | | |
5623 | 0 | return true; |
5624 | | |
5625 | 0 | error_return: |
5626 | 0 | free (aout_info.contents); |
5627 | 0 | free (aout_info.relocs); |
5628 | 0 | free (aout_info.symbol_map); |
5629 | 0 | free (aout_info.output_syms); |
5630 | 0 | if (includes_hash_initialized) |
5631 | 0 | bfd_hash_table_free (&aout_info.includes.root); |
5632 | 0 | return false; |
5633 | 0 | } Unexecuted instantiation: cris_aout_32_final_link Unexecuted instantiation: ns32kaout_32_final_link Unexecuted instantiation: aout_32_final_link |