]>
Commit | Line | Data |
---|---|---|
ce07dd7c | 1 | #define BFD_AOUT_DEBUG |
88dfcd68 SC |
2 | /* BFD semi-generic back-end for a.out binaries |
3 | Copyright (C) 1990-1991 Free Software Foundation, Inc. | |
4 | Written by Cygnus Support. | |
7ed4093a | 5 | |
88dfcd68 | 6 | This file is part of BFD, the Binary File Descriptor library. |
7ed4093a | 7 | |
88dfcd68 | 8 | This program is free software; you can redistribute it and/or modify |
7ed4093a | 9 | it under the terms of the GNU General Public License as published by |
88dfcd68 SC |
10 | the Free Software Foundation; either version 2 of the License, or |
11 | (at your option) any later version. | |
7ed4093a | 12 | |
88dfcd68 | 13 | This program is distributed in the hope that it will be useful, |
7ed4093a SC |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
88dfcd68 SC |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
7ed4093a | 21 | |
4e41b5aa SC |
22 | /* |
23 | SECTION | |
24 | a.out backends | |
6f715d66 | 25 | |
6f715d66 | 26 | |
4e41b5aa | 27 | DESCRIPTION |
6f715d66 | 28 | |
4e41b5aa SC |
29 | BFD supports a number of different flavours of a.out format, |
30 | though the major differences are only the sizes of the | |
31 | structures on disk, and the shape of the relocation | |
32 | information. | |
6f715d66 | 33 | |
4e41b5aa SC |
34 | The support is split into a basic support file @code{aoutx.h} |
35 | and other files which derive functions from the base. One | |
36 | derivation file is @code{aoutf1.h} (for a.out flavour 1), and | |
37 | adds to the basic a.out functions support for sun3, sun4, 386 | |
38 | and 29k a.out files, to create a target jump vector for a | |
39 | specific target. | |
6f715d66 | 40 | |
4e41b5aa SC |
41 | This information is further split out into more specific files |
42 | for each machine, including @code{sunos.c} for sun3 and sun4, | |
43 | @code{newsos3.c} for the Sony NEWS, and @code{demo64.c} for a | |
44 | demonstration of a 64 bit a.out format. | |
45 | ||
46 | The base file @code{aoutx.h} defines general mechanisms for | |
47 | reading and writing records to and from disk, and various | |
48 | other methods which BFD requires. It is included by | |
49 | @code{aout32.c} and @code{aout64.c} to form the names | |
50 | aout_32_swap_exec_header_in, aout_64_swap_exec_header_in, etc. | |
51 | ||
52 | As an example, this is what goes on to make the back end for a | |
53 | sun4, from aout32.c | |
54 | ||
3f7607af PB |
55 | | #define ARCH_SIZE 32 |
56 | | #include "aoutx.h" | |
4e41b5aa SC |
57 | |
58 | Which exports names: | |
59 | ||
3f7607af PB |
60 | | ... |
61 | | aout_32_canonicalize_reloc | |
62 | | aout_32_find_nearest_line | |
63 | | aout_32_get_lineno | |
64 | | aout_32_get_reloc_upper_bound | |
65 | | ... | |
6f715d66 | 66 | |
4e41b5aa SC |
67 | from sunos.c |
68 | ||
3f7607af PB |
69 | | #define ARCH 32 |
70 | | #define TARGET_NAME "a.out-sunos-big" | |
71 | | #define VECNAME sunos_big_vec | |
72 | | #include "aoutf1.h" | |
4e41b5aa SC |
73 | |
74 | requires all the names from aout32.c, and produces the jump vector | |
6f715d66 | 75 | |
3f7607af | 76 | | sunos_big_vec |
c6705697 | 77 | |
4e41b5aa SC |
78 | The file host-aout.c is a special case. It is for a large set |
79 | of hosts that use ``more or less standard'' a.out files, and | |
80 | for which cross-debugging is not interesting. It uses the | |
81 | standard 32-bit a.out support routines, but determines the | |
82 | file offsets and addresses of the text, data, and BSS | |
83 | sections, the machine architecture and machine type, and the | |
84 | entry point address, in a host-dependent manner. Once these | |
85 | values have been determined, generic code is used to handle | |
86 | the object file. | |
c6705697 | 87 | |
4e41b5aa SC |
88 | When porting it to run on a new system, you must supply: |
89 | ||
3f7607af PB |
90 | | HOST_PAGE_SIZE |
91 | | HOST_SEGMENT_SIZE | |
92 | | HOST_MACHINE_ARCH (optional) | |
93 | | HOST_MACHINE_MACHINE (optional) | |
94 | | HOST_TEXT_START_ADDR | |
95 | | HOST_STACK_END_ADDR | |
c6705697 | 96 | |
3f7607af PB |
97 | in the file <<../include/sys/h-XXX.h>> (for your host). These |
98 | values, plus the structures and macros defined in <<a.out.h>> on | |
4e41b5aa SC |
99 | your host system, will produce a BFD target that will access |
100 | ordinary a.out files on your host. To configure a new machine | |
3f7607af | 101 | to use <<host-aout.c>., specify: |
c6705697 | 102 | |
3f7607af PB |
103 | | TDEFAULTS = -DDEFAULT_VECTOR=host_aout_big_vec |
104 | | TDEPFILES= host-aout.o trad-core.o | |
c6705697 | 105 | |
3f7607af PB |
106 | in the <<config/mt-XXX>> file, and modify configure.in to use the |
107 | <<mt-XXX>> file (by setting "<<bfd_target=XXX>>") when your | |
4e41b5aa | 108 | configuration is selected. |
c6705697 | 109 | |
6f715d66 SC |
110 | */ |
111 | ||
ce07dd7c KR |
112 | /* Some assumptions: |
113 | * Any BFD with D_PAGED set is ZMAGIC, and vice versa. | |
114 | Doesn't matter what the setting of WP_TEXT is on output, but it'll | |
115 | get set on input. | |
116 | * Any BFD with D_PAGED clear and WP_TEXT set is NMAGIC. | |
117 | * Any BFD with both flags clear is OMAGIC. | |
118 | (Just want to make these explicit, so the conditions tested in this | |
119 | file make sense if you're more familiar with a.out than with BFD.) */ | |
120 | ||
c618de01 SC |
121 | #define KEEPIT flags |
122 | #define KEEPITTYPE int | |
67c060c3 SC |
123 | |
124 | #include "bfd.h" | |
7ed4093a SC |
125 | #include <sysdep.h> |
126 | #include <ansidecl.h> | |
127 | ||
9e2dad8e | 128 | struct external_exec; |
6f715d66 | 129 | #include "libaout.h" |
7ed4093a | 130 | #include "libbfd.h" |
c3eb25fc SC |
131 | #include "aout/aout64.h" |
132 | #include "aout/stab_gnu.h" | |
133 | #include "aout/ar.h" | |
7ed4093a | 134 | |
ce07dd7c | 135 | extern void (*bfd_error_trap)(); |
7ed4093a | 136 | |
4e41b5aa SC |
137 | /* |
138 | SUBSECTION | |
139 | relocations | |
140 | ||
141 | DESCRIPTION | |
142 | The file @code{aoutx.h} caters for both the @emph{standard} | |
143 | and @emph{extended} forms of a.out relocation records. | |
144 | ||
145 | The standard records are characterised by containing only an | |
146 | address, a symbol index and a type field. The extended records | |
147 | (used on 29ks and sparcs) also have a full integer for an | |
148 | addend. | |
7ed4093a | 149 | |
6f715d66 | 150 | */ |
7ed4093a | 151 | #define CTOR_TABLE_RELOC_IDX 2 |
67c060c3 | 152 | |
ce07dd7c KR |
153 | #define howto_table_ext NAME(aout,ext_howto_table) |
154 | #define howto_table_std NAME(aout,std_howto_table) | |
67c060c3 | 155 | |
ce07dd7c | 156 | reloc_howto_type howto_table_ext[] = |
7ed4093a SC |
157 | { |
158 | HOWTO(RELOC_8, 0, 0, 8, false, 0, true, true,0,"8", false, 0,0x000000ff, false), | |
159 | HOWTO(RELOC_16, 0, 1, 16, false, 0, true, true,0,"16", false, 0,0x0000ffff, false), | |
160 | HOWTO(RELOC_32, 0, 2, 32, false, 0, true, true,0,"32", false, 0,0xffffffff, false), | |
161 | HOWTO(RELOC_DISP8, 0, 0, 8, true, 0, false, true,0,"DISP8", false, 0,0x000000ff, false), | |
162 | HOWTO(RELOC_DISP16, 0, 1, 16, true, 0, false, true,0,"DISP16", false, 0,0x0000ffff, false), | |
163 | HOWTO(RELOC_DISP32, 0, 2, 32, true, 0, false, true,0,"DISP32", false, 0,0xffffffff, false), | |
164 | HOWTO(RELOC_WDISP30,2, 2, 30, true, 0, false, true,0,"WDISP30", false, 0,0x3fffffff, false), | |
165 | HOWTO(RELOC_WDISP22,2, 2, 22, true, 0, false, true,0,"WDISP22", false, 0,0x003fffff, false), | |
166 | HOWTO(RELOC_HI22, 10, 2, 22, false, 0, false, true,0,"HI22", false, 0,0x003fffff, false), | |
167 | HOWTO(RELOC_22, 0, 2, 22, false, 0, false, true,0,"22", false, 0,0x003fffff, false), | |
168 | HOWTO(RELOC_13, 0, 2, 13, false, 0, false, true,0,"13", false, 0,0x00001fff, false), | |
169 | HOWTO(RELOC_LO10, 0, 2, 10, false, 0, false, true,0,"LO10", false, 0,0x000003ff, false), | |
170 | HOWTO(RELOC_SFA_BASE,0, 2, 32, false, 0, false, true,0,"SFA_BASE", false, 0,0xffffffff, false), | |
171 | HOWTO(RELOC_SFA_OFF13,0,2, 32, false, 0, false, true,0,"SFA_OFF13",false, 0,0xffffffff, false), | |
172 | HOWTO(RELOC_BASE10, 0, 2, 16, false, 0, false, true,0,"BASE10", false, 0,0x0000ffff, false), | |
173 | HOWTO(RELOC_BASE13, 0, 2, 13, false, 0, false, true,0,"BASE13", false, 0,0x00001fff, false), | |
174 | HOWTO(RELOC_BASE22, 0, 2, 0, false, 0, false, true,0,"BASE22", false, 0,0x00000000, false), | |
175 | HOWTO(RELOC_PC10, 0, 2, 10, false, 0, false, true,0,"PC10", false, 0,0x000003ff, false), | |
176 | HOWTO(RELOC_PC22, 0, 2, 22, false, 0, false, true,0,"PC22", false, 0,0x003fffff, false), | |
177 | HOWTO(RELOC_JMP_TBL,0, 2, 32, false, 0, false, true,0,"JMP_TBL", false, 0,0xffffffff, false), | |
178 | HOWTO(RELOC_SEGOFF16,0, 2, 0, false, 0, false, true,0,"SEGOFF16", false, 0,0x00000000, false), | |
179 | HOWTO(RELOC_GLOB_DAT,0, 2, 0, false, 0, false, true,0,"GLOB_DAT", false, 0,0x00000000, false), | |
180 | HOWTO(RELOC_JMP_SLOT,0, 2, 0, false, 0, false, true,0,"JMP_SLOT", false, 0,0x00000000, false), | |
67c060c3 SC |
181 | HOWTO(RELOC_RELATIVE,0, 2, 0, false, 0, false, true,0,"RELATIVE", false, 0,0x00000000, false), |
182 | ||
7ed4093a SC |
183 | }; |
184 | ||
185 | /* Convert standard reloc records to "arelent" format (incl byte swap). */ | |
186 | ||
ce07dd7c | 187 | reloc_howto_type howto_table_std[] = { |
7ed4093a SC |
188 | /* type rs size bsz pcrel bitpos abs ovrf sf name part_inpl readmask setmask pcdone */ |
189 | HOWTO( 0, 0, 0, 8, false, 0, true, true,0,"8", true, 0x000000ff,0x000000ff, false), | |
190 | HOWTO( 1, 0, 1, 16, false, 0, true, true,0,"16", true, 0x0000ffff,0x0000ffff, false), | |
191 | HOWTO( 2, 0, 2, 32, false, 0, true, true,0,"32", true, 0xffffffff,0xffffffff, false), | |
192 | HOWTO( 3, 0, 3, 64, false, 0, true, true,0,"64", true, 0xdeaddead,0xdeaddead, false), | |
193 | HOWTO( 4, 0, 0, 8, true, 0, false, true,0,"DISP8", true, 0x000000ff,0x000000ff, false), | |
194 | HOWTO( 5, 0, 1, 16, true, 0, false, true,0,"DISP16", true, 0x0000ffff,0x0000ffff, false), | |
195 | HOWTO( 6, 0, 2, 32, true, 0, false, true,0,"DISP32", true, 0xffffffff,0xffffffff, false), | |
196 | HOWTO( 7, 0, 3, 64, true, 0, false, true,0,"DISP64", true, 0xfeedface,0xfeedface, false), | |
197 | }; | |
198 | ||
199 | ||
ce07dd7c | 200 | extern bfd_error_vector_type bfd_error_vector; |
6f715d66 | 201 | |
4e41b5aa SC |
202 | /* |
203 | SUBSECTION | |
204 | Internal Entry Points | |
205 | ||
206 | DESCRIPTION | |
207 | @code{aoutx.h} exports several routines for accessing the | |
208 | contents of an a.out file, which are gathered and exported in | |
209 | turn by various format specific files (eg sunos.c). | |
210 | ||
6f715d66 SC |
211 | */ |
212 | ||
4e41b5aa SC |
213 | /* |
214 | FUNCTION | |
215 | aout_<size>_swap_exec_header_in | |
216 | ||
217 | DESCRIPTION | |
218 | Swaps the information in an executable header taken from a raw | |
219 | byte stream memory image, into the internal exec_header | |
220 | structure. | |
221 | ||
222 | EXAMPLE | |
223 | void aout_<size>_swap_exec_header_in, | |
224 | (bfd *abfd, | |
225 | struct external_exec *raw_bytes, | |
226 | struct internal_exec *execp); | |
6f715d66 SC |
227 | */ |
228 | ||
7ed4093a SC |
229 | void |
230 | DEFUN(NAME(aout,swap_exec_header_in),(abfd, raw_bytes, execp), | |
231 | bfd *abfd AND | |
232 | struct external_exec *raw_bytes AND | |
233 | struct internal_exec *execp) | |
234 | { | |
235 | struct external_exec *bytes = (struct external_exec *)raw_bytes; | |
236 | ||
55c0061e FF |
237 | /* The internal_exec structure has some fields that are unused in this |
238 | configuration (IE for i960), so ensure that all such uninitialized | |
239 | fields are zero'd out. There are places where two of these structs | |
240 | are memcmp'd, and thus the contents do matter. */ | |
241 | memset (execp, 0, sizeof (struct internal_exec)); | |
7ed4093a SC |
242 | /* Now fill in fields in the execp, from the bytes in the raw data. */ |
243 | execp->a_info = bfd_h_get_32 (abfd, bytes->e_info); | |
244 | execp->a_text = GET_WORD (abfd, bytes->e_text); | |
245 | execp->a_data = GET_WORD (abfd, bytes->e_data); | |
246 | execp->a_bss = GET_WORD (abfd, bytes->e_bss); | |
247 | execp->a_syms = GET_WORD (abfd, bytes->e_syms); | |
248 | execp->a_entry = GET_WORD (abfd, bytes->e_entry); | |
249 | execp->a_trsize = GET_WORD (abfd, bytes->e_trsize); | |
250 | execp->a_drsize = GET_WORD (abfd, bytes->e_drsize); | |
251 | } | |
252 | ||
4e41b5aa SC |
253 | /* |
254 | FUNCTION | |
255 | aout_<size>_swap_exec_header_out | |
256 | ||
257 | DESCRIPTION | |
258 | Swaps the information in an internal exec header structure | |
259 | into the supplied buffer ready for writing to disk. | |
260 | ||
261 | EXAMPLE | |
262 | void aout_<size>_swap_exec_header_out | |
6f715d66 SC |
263 | (bfd *abfd, |
264 | struct internal_exec *execp, | |
4e41b5aa | 265 | struct external_exec *raw_bytes); |
6f715d66 | 266 | */ |
7ed4093a SC |
267 | void |
268 | DEFUN(NAME(aout,swap_exec_header_out),(abfd, execp, raw_bytes), | |
269 | bfd *abfd AND | |
270 | struct internal_exec *execp AND | |
271 | struct external_exec *raw_bytes) | |
272 | { | |
273 | struct external_exec *bytes = (struct external_exec *)raw_bytes; | |
274 | ||
275 | /* Now fill in fields in the raw data, from the fields in the exec struct. */ | |
276 | bfd_h_put_32 (abfd, execp->a_info , bytes->e_info); | |
277 | PUT_WORD (abfd, execp->a_text , bytes->e_text); | |
278 | PUT_WORD (abfd, execp->a_data , bytes->e_data); | |
279 | PUT_WORD (abfd, execp->a_bss , bytes->e_bss); | |
280 | PUT_WORD (abfd, execp->a_syms , bytes->e_syms); | |
281 | PUT_WORD (abfd, execp->a_entry , bytes->e_entry); | |
282 | PUT_WORD (abfd, execp->a_trsize, bytes->e_trsize); | |
283 | PUT_WORD (abfd, execp->a_drsize, bytes->e_drsize); | |
284 | } | |
285 | ||
7ed4093a | 286 | |
6f715d66 | 287 | |
4e41b5aa SC |
288 | /* |
289 | FUNCTION | |
290 | aout_<size>_some_aout_object_p | |
6f715d66 | 291 | |
4e41b5aa SC |
292 | DESCRIPTION |
293 | Some A.OUT variant thinks that the file whose format we're | |
294 | checking is an a.out file. Do some more checking, and set up | |
295 | for access if it really is. Call back to the calling | |
296 | environments "finish up" function just before returning, to | |
297 | handle any last-minute setup. | |
6f715d66 | 298 | |
4e41b5aa SC |
299 | EXAMPLE |
300 | bfd_target *aout_<size>_some_aout_object_p | |
6f715d66 | 301 | (bfd *abfd, |
4e41b5aa | 302 | bfd_target *(*callback_to_real_object_p)()); |
6f715d66 | 303 | */ |
7ed4093a SC |
304 | |
305 | bfd_target * | |
7b02b4ed | 306 | DEFUN(NAME(aout,some_aout_object_p),(abfd, execp, callback_to_real_object_p), |
7ed4093a | 307 | bfd *abfd AND |
7b02b4ed | 308 | struct internal_exec *execp AND |
7ed4093a SC |
309 | bfd_target *(*callback_to_real_object_p) ()) |
310 | { | |
6db82ea7 | 311 | struct aout_data_struct *rawptr; |
e6e265ce | 312 | bfd_target *result; |
7ed4093a | 313 | |
6db82ea7 | 314 | rawptr = (struct aout_data_struct *) bfd_zalloc (abfd, sizeof (struct aout_data_struct )); |
7ed4093a SC |
315 | if (rawptr == NULL) { |
316 | bfd_error = no_memory; | |
317 | return 0; | |
318 | } | |
319 | ||
6db82ea7 SC |
320 | abfd->tdata.aout_data = rawptr; |
321 | abfd->tdata.aout_data->a.hdr = &rawptr->e; | |
322 | *(abfd->tdata.aout_data->a.hdr) = *execp; /* Copy in the internal_exec struct */ | |
323 | execp = abfd->tdata.aout_data->a.hdr; | |
7ed4093a SC |
324 | |
325 | /* Set the file flags */ | |
326 | abfd->flags = NO_FLAGS; | |
327 | if (execp->a_drsize || execp->a_trsize) | |
328 | abfd->flags |= HAS_RELOC; | |
e6e265ce | 329 | /* Setting of EXEC_P has been deferred to the bottom of this function */ |
7ed4093a SC |
330 | if (execp->a_syms) |
331 | abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS; | |
332 | ||
ce07dd7c KR |
333 | if (N_MAGIC (*execp) == ZMAGIC) |
334 | { | |
335 | abfd->flags |= D_PAGED|WP_TEXT; | |
336 | adata(abfd).magic = z_magic; | |
337 | } | |
338 | else if (N_MAGIC (*execp) == NMAGIC) | |
339 | { | |
340 | abfd->flags |= WP_TEXT; | |
341 | adata(abfd).magic = n_magic; | |
342 | } | |
343 | else | |
344 | adata(abfd).magic = o_magic; | |
7ed4093a SC |
345 | |
346 | bfd_get_start_address (abfd) = execp->a_entry; | |
347 | ||
348 | obj_aout_symbols (abfd) = (aout_symbol_type *)NULL; | |
349 | bfd_get_symcount (abfd) = execp->a_syms / sizeof (struct external_nlist); | |
350 | ||
7ed4093a SC |
351 | /* The default relocation entry size is that of traditional V7 Unix. */ |
352 | obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; | |
353 | ||
7b02b4ed JG |
354 | /* The default symbol entry size is that of traditional Unix. */ |
355 | obj_symbol_entry_size (abfd) = EXTERNAL_NLIST_SIZE; | |
356 | ||
7ed4093a SC |
357 | /* create the sections. This is raunchy, but bfd_close wants to reclaim |
358 | them */ | |
6db82ea7 | 359 | |
7ed4093a SC |
360 | obj_textsec (abfd) = (asection *)NULL; |
361 | obj_datasec (abfd) = (asection *)NULL; | |
362 | obj_bsssec (abfd) = (asection *)NULL; | |
6db82ea7 | 363 | |
7ed4093a SC |
364 | (void)bfd_make_section(abfd, ".text"); |
365 | (void)bfd_make_section(abfd, ".data"); | |
366 | (void)bfd_make_section(abfd, ".bss"); | |
6db82ea7 SC |
367 | /* (void)bfd_make_section(abfd, BFD_ABS_SECTION_NAME); |
368 | (void)bfd_make_section (abfd, BFD_UND_SECTION_NAME); | |
369 | (void)bfd_make_section (abfd, BFD_COM_SECTION_NAME);*/ | |
7ed4093a SC |
370 | abfd->sections = obj_textsec (abfd); |
371 | obj_textsec (abfd)->next = obj_datasec (abfd); | |
372 | obj_datasec (abfd)->next = obj_bsssec (abfd); | |
373 | ||
6db82ea7 SC |
374 | obj_datasec (abfd)->_raw_size = execp->a_data; |
375 | obj_bsssec (abfd)->_raw_size = execp->a_bss; | |
7ed4093a | 376 | |
7ed4093a | 377 | obj_textsec (abfd)->flags = (execp->a_trsize != 0 ? |
7b02b4ed JG |
378 | (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_HAS_CONTENTS) : |
379 | (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS)); | |
7ed4093a | 380 | obj_datasec (abfd)->flags = (execp->a_drsize != 0 ? |
7b02b4ed JG |
381 | (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_HAS_CONTENTS) : |
382 | (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS)); | |
7ed4093a SC |
383 | obj_bsssec (abfd)->flags = SEC_ALLOC; |
384 | ||
385 | #ifdef THIS_IS_ONLY_DOCUMENTATION | |
98d43107 JG |
386 | /* The common code can't fill in these things because they depend |
387 | on either the start address of the text segment, the rounding | |
388 | up of virtual addersses between segments, or the starting file | |
389 | position of the text segment -- all of which varies among different | |
390 | versions of a.out. */ | |
391 | ||
7ed4093a SC |
392 | /* Call back to the format-dependent code to fill in the rest of the |
393 | fields and do any further cleanup. Things that should be filled | |
394 | in by the callback: */ | |
395 | ||
396 | struct exec *execp = exec_hdr (abfd); | |
397 | ||
98d43107 | 398 | obj_textsec (abfd)->size = N_TXTSIZE(*execp); |
6db82ea7 | 399 | obj_textsec (abfd)->raw_size = N_TXTSIZE(*execp); |
98d43107 JG |
400 | /* data and bss are already filled in since they're so standard */ |
401 | ||
7ed4093a | 402 | /* The virtual memory addresses of the sections */ |
7ed4093a | 403 | obj_textsec (abfd)->vma = N_TXTADDR(*execp); |
98d43107 JG |
404 | obj_datasec (abfd)->vma = N_DATADDR(*execp); |
405 | obj_bsssec (abfd)->vma = N_BSSADDR(*execp); | |
7ed4093a SC |
406 | |
407 | /* The file offsets of the sections */ | |
408 | obj_textsec (abfd)->filepos = N_TXTOFF(*execp); | |
409 | obj_datasec (abfd)->filepos = N_DATOFF(*execp); | |
410 | ||
411 | /* The file offsets of the relocation info */ | |
412 | obj_textsec (abfd)->rel_filepos = N_TRELOFF(*execp); | |
413 | obj_datasec (abfd)->rel_filepos = N_DRELOFF(*execp); | |
414 | ||
415 | /* The file offsets of the string table and symbol table. */ | |
416 | obj_str_filepos (abfd) = N_STROFF (*execp); | |
417 | obj_sym_filepos (abfd) = N_SYMOFF (*execp); | |
418 | ||
7ed4093a SC |
419 | /* Determine the architecture and machine type of the object file. */ |
420 | switch (N_MACHTYPE (*exec_hdr (abfd))) { | |
421 | default: | |
422 | abfd->obj_arch = bfd_arch_obscure; | |
423 | break; | |
424 | } | |
425 | ||
426 | /* Determine the size of a relocation entry */ | |
427 | switch (abfd->obj_arch) { | |
428 | case bfd_arch_sparc: | |
429 | case bfd_arch_a29k: | |
430 | obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE; | |
431 | default: | |
432 | obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; | |
433 | } | |
434 | ||
7b02b4ed JG |
435 | adata(abfd)->page_size = PAGE_SIZE; |
436 | adata(abfd)->segment_size = SEGMENT_SIZE; | |
437 | adata(abfd)->exec_bytes_size = EXEC_BYTES_SIZE; | |
438 | ||
7ed4093a SC |
439 | return abfd->xvec; |
440 | ||
441 | /* The architecture is encoded in various ways in various a.out variants, | |
442 | or is not encoded at all in some of them. The relocation size depends | |
443 | on the architecture and the a.out variant. Finally, the return value | |
444 | is the bfd_target vector in use. If an error occurs, return zero and | |
445 | set bfd_error to the appropriate error code. | |
446 | ||
447 | Formats such as b.out, which have additional fields in the a.out | |
448 | header, should cope with them in this callback as well. */ | |
449 | #endif /* DOCUMENTATION */ | |
450 | ||
e6e265ce JG |
451 | result = (*callback_to_real_object_p)(abfd); |
452 | ||
453 | /* Now that the segment addresses have been worked out, take a better | |
454 | guess at whether the file is executable. If the entry point | |
455 | is within the text segment, assume it is. (This makes files | |
456 | executable even if their entry point address is 0, as long as | |
457 | their text starts at zero.) | |
458 | ||
459 | At some point we should probably break down and stat the file and | |
460 | declare it executable if (one of) its 'x' bits are on... */ | |
461 | if ((execp->a_entry >= obj_textsec(abfd)->vma) && | |
6db82ea7 | 462 | (execp->a_entry < obj_textsec(abfd)->vma + obj_textsec(abfd)->_raw_size)) |
e6e265ce JG |
463 | abfd->flags |= EXEC_P; |
464 | return result; | |
7ed4093a SC |
465 | } |
466 | ||
4e41b5aa SC |
467 | /* |
468 | FUNCTION | |
469 | aout_<size>_mkobject | |
6f715d66 | 470 | |
4e41b5aa SC |
471 | DESCRIPTION |
472 | This routine initializes a BFD for use with a.out files. | |
6f715d66 | 473 | |
4e41b5aa SC |
474 | EXAMPLE |
475 | boolean aout_<size>_mkobject, (bfd *); | |
6f715d66 | 476 | */ |
7ed4093a SC |
477 | |
478 | boolean | |
479 | DEFUN(NAME(aout,mkobject),(abfd), | |
480 | bfd *abfd) | |
481 | { | |
6db82ea7 | 482 | struct aout_data_struct *rawptr; |
7ed4093a SC |
483 | |
484 | bfd_error = system_call_error; | |
485 | ||
486 | /* Use an intermediate variable for clarity */ | |
6db82ea7 | 487 | rawptr = (struct aout_data_struct *)bfd_zalloc (abfd, sizeof (struct aout_data_struct )); |
7ed4093a SC |
488 | |
489 | if (rawptr == NULL) { | |
490 | bfd_error = no_memory; | |
491 | return false; | |
492 | } | |
493 | ||
6db82ea7 | 494 | abfd->tdata.aout_data = rawptr; |
7ed4093a SC |
495 | exec_hdr (abfd) = &(rawptr->e); |
496 | ||
497 | /* For simplicity's sake we just make all the sections right here. */ | |
498 | ||
499 | obj_textsec (abfd) = (asection *)NULL; | |
500 | obj_datasec (abfd) = (asection *)NULL; | |
501 | obj_bsssec (abfd) = (asection *)NULL; | |
502 | bfd_make_section (abfd, ".text"); | |
503 | bfd_make_section (abfd, ".data"); | |
504 | bfd_make_section (abfd, ".bss"); | |
6db82ea7 SC |
505 | bfd_make_section (abfd, BFD_ABS_SECTION_NAME); |
506 | bfd_make_section (abfd, BFD_UND_SECTION_NAME); | |
507 | bfd_make_section (abfd, BFD_COM_SECTION_NAME); | |
7ed4093a SC |
508 | |
509 | return true; | |
510 | } | |
511 | ||
6f715d66 | 512 | |
4e41b5aa SC |
513 | /* |
514 | FUNCTION | |
515 | aout_<size>_machine_type | |
6f715d66 | 516 | |
4e41b5aa SC |
517 | DESCRIPTION |
518 | Keep track of machine architecture and machine type for | |
519 | a.out's. Return the machine_type for a particular | |
520 | arch&machine, or M_UNKNOWN if that exact arch&machine can't be | |
521 | represented in a.out format. | |
7ed4093a | 522 | |
4e41b5aa SC |
523 | If the architecture is understood, machine type 0 (default) |
524 | should always be understood. | |
6f715d66 | 525 | |
4e41b5aa SC |
526 | EXAMPLE |
527 | enum machine_type aout_<size>_machine_type | |
6f715d66 SC |
528 | (enum bfd_architecture arch, |
529 | unsigned long machine)); | |
530 | */ | |
7ed4093a SC |
531 | |
532 | enum machine_type | |
533 | DEFUN(NAME(aout,machine_type),(arch, machine), | |
534 | enum bfd_architecture arch AND | |
535 | unsigned long machine) | |
536 | { | |
537 | enum machine_type arch_flags; | |
538 | ||
539 | arch_flags = M_UNKNOWN; | |
540 | ||
541 | switch (arch) { | |
542 | case bfd_arch_sparc: | |
543 | if (machine == 0) arch_flags = M_SPARC; | |
544 | break; | |
545 | ||
546 | case bfd_arch_m68k: | |
547 | switch (machine) { | |
548 | case 0: arch_flags = M_68010; break; | |
549 | case 68000: arch_flags = M_UNKNOWN; break; | |
550 | case 68010: arch_flags = M_68010; break; | |
551 | case 68020: arch_flags = M_68020; break; | |
552 | default: arch_flags = M_UNKNOWN; break; | |
553 | } | |
554 | break; | |
555 | ||
556 | case bfd_arch_i386: | |
557 | if (machine == 0) arch_flags = M_386; | |
558 | break; | |
559 | ||
560 | case bfd_arch_a29k: | |
561 | if (machine == 0) arch_flags = M_29K; | |
562 | break; | |
563 | ||
564 | default: | |
565 | arch_flags = M_UNKNOWN; | |
566 | break; | |
567 | } | |
568 | return arch_flags; | |
569 | } | |
570 | ||
9e2dad8e | 571 | |
4e41b5aa SC |
572 | /* |
573 | FUNCTION | |
574 | aout_<size>_set_arch_mach | |
6f715d66 | 575 | |
4e41b5aa SC |
576 | DESCRIPTION |
577 | Sets the architecture and the machine of the BFD to those | |
578 | values supplied. Verifies that the format can support the | |
579 | architecture required. | |
6f715d66 | 580 | |
4e41b5aa SC |
581 | EXAMPLE |
582 | boolean aout_<size>_set_arch_mach, | |
6f715d66 SC |
583 | (bfd *, |
584 | enum bfd_architecture, | |
585 | unsigned long machine)); | |
586 | */ | |
587 | ||
7ed4093a SC |
588 | boolean |
589 | DEFUN(NAME(aout,set_arch_mach),(abfd, arch, machine), | |
590 | bfd *abfd AND | |
591 | enum bfd_architecture arch AND | |
592 | unsigned long machine) | |
593 | { | |
ce07dd7c KR |
594 | bfd_arch_info_type *ainfo; |
595 | ||
9e2dad8e | 596 | bfd_default_set_arch_mach(abfd, arch, machine); |
7ed4093a SC |
597 | if (arch != bfd_arch_unknown && |
598 | NAME(aout,machine_type) (arch, machine) == M_UNKNOWN) | |
599 | return false; /* We can't represent this type */ | |
ce07dd7c KR |
600 | |
601 | BFD_ASSERT (&adata(abfd) != 0); | |
602 | ainfo = bfd_get_arch_info (abfd); | |
603 | if (ainfo->segment_size) | |
604 | adata(abfd).segment_size = ainfo->segment_size; | |
605 | if (ainfo->page_size) | |
606 | adata(abfd).page_size = ainfo->page_size; | |
7ed4093a SC |
607 | return true; /* We're easy ... */ |
608 | } | |
7ed4093a | 609 | |
ce07dd7c KR |
610 | boolean |
611 | DEFUN (NAME (aout,adjust_sizes_and_vmas), (abfd, text_size, text_end), | |
612 | bfd *abfd AND bfd_size_type *text_size AND file_ptr *text_end) | |
613 | { | |
614 | struct internal_exec *execp = exec_hdr (abfd); | |
615 | if ((obj_textsec (abfd) == NULL) || (obj_datasec (abfd) == NULL)) | |
616 | { | |
617 | bfd_error = invalid_operation; | |
618 | return false; | |
619 | } | |
620 | if (adata(abfd).magic != undecided_magic) return true; | |
621 | obj_textsec(abfd)->_raw_size = | |
622 | align_power(obj_textsec(abfd)->_raw_size, | |
623 | obj_textsec(abfd)->alignment_power); | |
624 | ||
625 | *text_size = obj_textsec (abfd)->_raw_size; | |
626 | /* Rule (heuristic) for when to pad to a new page. Note that there | |
627 | * are (at least) two ways demand-paged (ZMAGIC) files have been | |
628 | * handled. Most Berkeley-based systems start the text segment at | |
629 | * (PAGE_SIZE). However, newer versions of SUNOS start the text | |
630 | * segment right after the exec header; the latter is counted in the | |
631 | * text segment size, and is paged in by the kernel with the rest of | |
632 | * the text. */ | |
633 | ||
634 | /* This perhaps isn't the right way to do this, but made it simpler for me | |
635 | to understand enough to implement it. Better would probably be to go | |
636 | right from BFD flags to alignment/positioning characteristics. But the | |
637 | old code was sloppy enough about handling the flags, and had enough | |
638 | other magic, that it was a little hard for me to understand. I think | |
639 | I understand it better now, but I haven't time to do the cleanup this | |
640 | minute. */ | |
641 | if (adata(abfd).magic == undecided_magic) | |
642 | { | |
643 | if (abfd->flags & D_PAGED) | |
644 | /* whether or not WP_TEXT is set */ | |
645 | adata(abfd).magic = z_magic; | |
646 | else if (abfd->flags & WP_TEXT) | |
647 | adata(abfd).magic = n_magic; | |
648 | else | |
649 | adata(abfd).magic = o_magic; | |
650 | } | |
651 | ||
652 | #ifdef BFD_AOUT_DEBUG /* requires gcc2 */ | |
653 | #if __GNUC__ >= 2 | |
654 | fprintf (stderr, "%s text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x,%x>\n", | |
655 | ({ char *str; | |
656 | switch (adata(abfd).magic) { | |
657 | case n_magic: str = "NMAGIC"; break; | |
658 | case o_magic: str = "OMAGIC"; break; | |
659 | case z_magic: str = "ZMAGIC"; break; | |
660 | default: abort (); | |
661 | } | |
662 | str; | |
663 | }), | |
664 | obj_textsec(abfd)->vma, obj_textsec(abfd)->_raw_size, obj_textsec(abfd)->alignment_power, | |
665 | obj_datasec(abfd)->vma, obj_datasec(abfd)->_raw_size, obj_datasec(abfd)->alignment_power, | |
666 | obj_bsssec(abfd)->vma, obj_bsssec(abfd)->_raw_size, obj_bsssec(abfd)->alignment_power); | |
667 | #endif | |
668 | #endif | |
669 | ||
670 | switch (adata(abfd).magic) | |
671 | { | |
672 | case o_magic: | |
673 | { | |
674 | file_ptr pos = adata (abfd).exec_bytes_size; | |
675 | bfd_vma vma = 0; | |
676 | int pad; | |
677 | ||
678 | obj_textsec(abfd)->filepos = pos; | |
679 | pos += obj_textsec(abfd)->_raw_size; | |
680 | vma += obj_textsec(abfd)->_raw_size; | |
681 | if (!obj_datasec(abfd)->user_set_vma) | |
682 | { | |
683 | /* ?? Does alignment in the file image really matter? */ | |
684 | pad = align_power (vma, obj_datasec(abfd)->alignment_power) - vma; | |
685 | obj_textsec(abfd)->_raw_size += pad; | |
686 | pos += pad; | |
687 | vma += pad; | |
688 | obj_datasec(abfd)->vma = vma; | |
689 | } | |
690 | obj_datasec(abfd)->filepos = pos; | |
691 | pos += obj_datasec(abfd)->_raw_size; | |
692 | vma += obj_datasec(abfd)->_raw_size; | |
693 | if (!obj_bsssec(abfd)->user_set_vma) | |
694 | { | |
695 | pad = align_power (vma, obj_bsssec(abfd)->alignment_power) - vma; | |
696 | obj_datasec(abfd)->_raw_size += pad; | |
697 | pos += pad; | |
698 | vma += pad; | |
699 | obj_bsssec(abfd)->vma = vma; | |
700 | } | |
701 | obj_bsssec(abfd)->filepos = pos; | |
702 | execp->a_text = obj_textsec(abfd)->_raw_size; | |
703 | execp->a_data = obj_datasec(abfd)->_raw_size; | |
704 | execp->a_bss = obj_bsssec(abfd)->_raw_size; | |
705 | N_SET_MAGIC (*execp, OMAGIC); | |
706 | } | |
707 | break; | |
708 | case z_magic: | |
709 | { | |
710 | bfd_size_type data_pad, text_pad; | |
711 | file_ptr text_end; | |
712 | CONST struct aout_backend_data *abdp; | |
713 | int ztih; | |
714 | bfd_vma data_vma; | |
715 | ||
716 | abdp = aout_backend_info (abfd); | |
717 | ztih = abdp && abdp->text_includes_header; | |
718 | obj_textsec(abfd)->filepos = (ztih | |
719 | ? adata(abfd).exec_bytes_size | |
720 | : adata(abfd).page_size); | |
721 | if (! obj_textsec(abfd)->user_set_vma) | |
722 | /* ?? Do we really need to check for relocs here? */ | |
723 | obj_textsec(abfd)->vma = ((abfd->flags & HAS_RELOC) | |
724 | ? 0 | |
725 | : (ztih | |
726 | ? (abdp->default_text_vma | |
727 | + adata(abfd).exec_bytes_size) | |
728 | : abdp->default_text_vma)); | |
729 | /* Could take strange alignment of text section into account here? */ | |
730 | ||
731 | /* Find start of data. */ | |
732 | text_end = obj_textsec(abfd)->filepos + obj_textsec(abfd)->_raw_size; | |
733 | text_pad = BFD_ALIGN (text_end, adata(abfd).page_size) - text_end; | |
734 | obj_textsec(abfd)->_raw_size += text_pad; | |
735 | text_end += text_pad; | |
736 | ||
737 | if (!obj_datasec(abfd)->user_set_vma) | |
738 | { | |
739 | bfd_vma vma; | |
740 | vma = obj_textsec(abfd)->vma + obj_textsec(abfd)->_raw_size; | |
741 | obj_datasec(abfd)->vma = BFD_ALIGN (vma, adata(abfd).segment_size); | |
742 | } | |
743 | data_vma = obj_datasec(abfd)->vma; | |
744 | if (abdp && abdp->zmagic_mapped_contiguous) | |
745 | { | |
746 | text_pad = (obj_datasec(abfd)->vma | |
747 | - obj_textsec(abfd)->vma | |
748 | - obj_textsec(abfd)->_raw_size); | |
749 | obj_textsec(abfd)->_raw_size += text_pad; | |
750 | } | |
751 | obj_datasec(abfd)->filepos = (obj_textsec(abfd)->filepos | |
752 | + obj_textsec(abfd)->_raw_size); | |
753 | ||
754 | /* Fix up exec header while we're at it. */ | |
755 | execp->a_text = obj_textsec(abfd)->_raw_size; | |
756 | if (ztih) | |
757 | execp->a_text += adata(abfd).exec_bytes_size; | |
758 | N_SET_MAGIC (*execp, ZMAGIC); | |
759 | /* Spec says data section should be rounded up to page boundary. */ | |
760 | /* If extra space in page is left after data section, fudge data | |
761 | in the header so that the bss section looks smaller by that | |
762 | amount. We'll start the bss section there, and lie to the OS. */ | |
763 | obj_datasec(abfd)->_raw_size | |
764 | = align_power (obj_datasec(abfd)->_raw_size, | |
765 | obj_bsssec(abfd)->alignment_power); | |
766 | execp->a_data = BFD_ALIGN (obj_datasec(abfd)->_raw_size, | |
767 | adata(abfd).page_size); | |
768 | data_pad = execp->a_data - obj_datasec(abfd)->_raw_size; | |
769 | /* This code is almost surely botched. It'll only get tested | |
770 | for the case where the application does explicitly set the VMA | |
771 | of the BSS section. */ | |
772 | if (obj_bsssec(abfd)->user_set_vma | |
773 | && (obj_bsssec(abfd)->vma | |
774 | > BFD_ALIGN (obj_datasec(abfd)->vma | |
775 | + obj_datasec(abfd)->_raw_size, | |
776 | adata(abfd).page_size))) | |
777 | { | |
778 | /* Can't play with squeezing into data pages; fix this code. */ | |
779 | abort (); | |
780 | } | |
781 | if (!obj_bsssec(abfd)->user_set_vma) | |
782 | obj_bsssec(abfd)->vma = (obj_datasec(abfd)->vma | |
783 | + obj_datasec(abfd)->_raw_size); | |
784 | if (data_pad > obj_bsssec(abfd)->_raw_size) | |
785 | execp->a_bss = 0; | |
786 | else | |
787 | execp->a_bss = obj_bsssec(abfd)->_raw_size - data_pad; | |
788 | } | |
789 | break; | |
790 | case n_magic: | |
791 | { | |
792 | CONST struct aout_backend_data *abdp; | |
793 | file_ptr pos = adata(abfd).exec_bytes_size; | |
794 | bfd_vma vma = 0; | |
795 | int pad; | |
796 | ||
797 | obj_textsec(abfd)->filepos = pos; | |
798 | if (!obj_textsec(abfd)->user_set_vma) | |
799 | obj_textsec(abfd)->vma = vma; | |
800 | else | |
801 | vma = obj_textsec(abfd)->vma; | |
802 | pos += obj_textsec(abfd)->_raw_size; | |
803 | vma += obj_textsec(abfd)->_raw_size; | |
804 | obj_datasec(abfd)->filepos = pos; | |
805 | if (!obj_datasec(abfd)->user_set_vma) | |
806 | obj_datasec(abfd)->vma = BFD_ALIGN (vma, adata(abfd).segment_size); | |
807 | vma = obj_datasec(abfd)->vma; | |
808 | ||
809 | /* Since BSS follows data immediately, see if it needs alignment. */ | |
810 | vma += obj_datasec(abfd)->_raw_size; | |
811 | pad = align_power (vma, obj_bsssec(abfd)->alignment_power) - vma; | |
812 | obj_datasec(abfd)->_raw_size += pad; | |
813 | pos += obj_datasec(abfd)->_raw_size; | |
814 | ||
815 | if (!obj_bsssec(abfd)->user_set_vma) | |
816 | obj_bsssec(abfd)->vma = vma; | |
817 | else | |
818 | vma = obj_bsssec(abfd)->vma; | |
819 | } | |
820 | execp->a_text = obj_textsec(abfd)->_raw_size; | |
821 | execp->a_data = obj_datasec(abfd)->_raw_size; | |
822 | execp->a_bss = obj_bsssec(abfd)->_raw_size; | |
823 | N_SET_MAGIC (*execp, NMAGIC); | |
824 | break; | |
825 | default: | |
826 | abort (); | |
827 | } | |
828 | #ifdef BFD_AOUT_DEBUG | |
829 | fprintf (stderr, " text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x>\n", | |
830 | obj_textsec(abfd)->vma, obj_textsec(abfd)->_raw_size, obj_textsec(abfd)->filepos, | |
831 | obj_datasec(abfd)->vma, obj_datasec(abfd)->_raw_size, obj_datasec(abfd)->filepos, | |
832 | obj_bsssec(abfd)->vma, obj_bsssec(abfd)->_raw_size); | |
833 | #endif | |
834 | } | |
835 | ||
4e41b5aa SC |
836 | /* |
837 | FUNCTION | |
838 | aout_<size>new_section_hook | |
9e2dad8e | 839 | |
4e41b5aa SC |
840 | DESCRIPTION |
841 | Called by the BFD in response to a @code{bfd_make_section} | |
842 | request. | |
843 | ||
844 | EXAMPLE | |
845 | boolean aout_<size>_new_section_hook, | |
9e2dad8e JG |
846 | (bfd *abfd, |
847 | asection *newsect)); | |
6f715d66 | 848 | */ |
7ed4093a | 849 | boolean |
3f7607af | 850 | DEFUN(NAME(aout,new_section_hook),(abfd, newsect), |
9e2dad8e JG |
851 | bfd *abfd AND |
852 | asection *newsect) | |
7ed4093a | 853 | { |
6db82ea7 SC |
854 | /* align to double at least */ |
855 | newsect->alignment_power = bfd_get_arch_info(abfd)->section_align_power; | |
3f7607af | 856 | |
7ed4093a | 857 | |
6db82ea7 SC |
858 | if (bfd_get_format (abfd) == bfd_object) |
859 | { | |
860 | if (obj_textsec(abfd) == NULL && !strcmp(newsect->name, ".text")) { | |
861 | obj_textsec(abfd)= newsect; | |
862 | newsect->target_index = N_TEXT | N_EXT; | |
863 | return true; | |
864 | } | |
7ed4093a | 865 | |
6db82ea7 SC |
866 | if (obj_datasec(abfd) == NULL && !strcmp(newsect->name, ".data")) { |
867 | obj_datasec(abfd) = newsect; | |
868 | newsect->target_index = N_DATA | N_EXT; | |
869 | return true; | |
870 | } | |
7ed4093a | 871 | |
6db82ea7 SC |
872 | if (obj_bsssec(abfd) == NULL && !strcmp(newsect->name, ".bss")) { |
873 | obj_bsssec(abfd) = newsect; | |
874 | newsect->target_index = N_BSS | N_EXT; | |
875 | return true; | |
876 | } | |
877 | ||
878 | } | |
7ed4093a | 879 | |
6db82ea7 SC |
880 | /* We allow more than three sections internally */ |
881 | return true; | |
7ed4093a SC |
882 | } |
883 | ||
884 | boolean | |
9e2dad8e JG |
885 | DEFUN(NAME(aout,set_section_contents),(abfd, section, location, offset, count), |
886 | bfd *abfd AND | |
887 | sec_ptr section AND | |
888 | PTR location AND | |
889 | file_ptr offset AND | |
890 | bfd_size_type count) | |
7ed4093a | 891 | { |
7b02b4ed | 892 | file_ptr text_end; |
7b02b4ed | 893 | bfd_size_type text_size; |
ce07dd7c | 894 | |
7ed4093a | 895 | if (abfd->output_has_begun == false) |
9e2dad8e JG |
896 | { /* set by bfd.c handler */ |
897 | switch (abfd->direction) | |
898 | { | |
899 | case read_direction: | |
900 | case no_direction: | |
901 | bfd_error = invalid_operation; | |
902 | return false; | |
ce07dd7c KR |
903 | |
904 | case write_direction: | |
905 | if (NAME(aout,adjust_sizes_and_vmas) (abfd, | |
906 | &text_size, | |
907 | &text_end) == false) | |
908 | return false; | |
9e2dad8e JG |
909 | case both_direction: |
910 | break; | |
12e7087f | 911 | } |
9e2dad8e | 912 | } |
12e7087f | 913 | |
7ed4093a SC |
914 | /* regardless, once we know what we're doing, we might as well get going */ |
915 | if (section != obj_bsssec(abfd)) | |
916 | { | |
917 | bfd_seek (abfd, section->filepos + offset, SEEK_SET); | |
9e2dad8e | 918 | |
7ed4093a SC |
919 | if (count) { |
920 | return (bfd_write ((PTR)location, 1, count, abfd) == count) ? | |
921 | true : false; | |
922 | } | |
6db82ea7 | 923 | return true; |
7ed4093a SC |
924 | } |
925 | return true; | |
926 | } | |
927 | \f | |
928 | /* Classify stabs symbols */ | |
929 | ||
930 | #define sym_in_text_section(sym) \ | |
9e2dad8e | 931 | (((sym)->type & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_TEXT) |
7ed4093a SC |
932 | |
933 | #define sym_in_data_section(sym) \ | |
9e2dad8e | 934 | (((sym)->type & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_DATA) |
7ed4093a SC |
935 | |
936 | #define sym_in_bss_section(sym) \ | |
9e2dad8e | 937 | (((sym)->type & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_BSS) |
7ed4093a SC |
938 | |
939 | /* Symbol is undefined if type is N_UNDF|N_EXT and if it has | |
9e2dad8e JG |
940 | zero in the "value" field. Nonzeroes there are fortrancommon |
941 | symbols. */ | |
7ed4093a | 942 | #define sym_is_undefined(sym) \ |
9e2dad8e | 943 | ((sym)->type == (N_UNDF | N_EXT) && (sym)->symbol.value == 0) |
7ed4093a SC |
944 | |
945 | /* Symbol is a global definition if N_EXT is on and if it has | |
9e2dad8e | 946 | a nonzero type field. */ |
7ed4093a | 947 | #define sym_is_global_defn(sym) \ |
9e2dad8e | 948 | (((sym)->type & N_EXT) && (sym)->type & N_TYPE) |
7ed4093a SC |
949 | |
950 | /* Symbol is debugger info if any bits outside N_TYPE or N_EXT | |
9e2dad8e | 951 | are on. */ |
7ed4093a | 952 | #define sym_is_debugger_info(sym) \ |
9e2dad8e | 953 | ((sym)->type & ~(N_EXT | N_TYPE)) |
7ed4093a SC |
954 | |
955 | #define sym_is_fortrancommon(sym) \ | |
9e2dad8e | 956 | (((sym)->type == (N_EXT)) && (sym)->symbol.value != 0) |
7ed4093a SC |
957 | |
958 | /* Symbol is absolute if it has N_ABS set */ | |
959 | #define sym_is_absolute(sym) \ | |
9e2dad8e | 960 | (((sym)->type & N_TYPE)== N_ABS) |
7ed4093a SC |
961 | |
962 | ||
963 | #define sym_is_indirect(sym) \ | |
9e2dad8e | 964 | (((sym)->type & N_ABS)== N_ABS) |
7ed4093a SC |
965 | |
966 | /* Only in their own functions for ease of debugging; when sym flags have | |
9e2dad8e JG |
967 | stabilised these should be inlined into their (single) caller */ |
968 | ||
7ed4093a SC |
969 | static void |
970 | DEFUN(translate_from_native_sym_flags,(sym_pointer, cache_ptr, abfd), | |
4e41b5aa SC |
971 | struct external_nlist *sym_pointer AND |
972 | aout_symbol_type *cache_ptr AND | |
973 | bfd *abfd) | |
9e2dad8e | 974 | { |
6db82ea7 SC |
975 | switch (cache_ptr->type & N_TYPE) |
976 | { | |
9e2dad8e JG |
977 | case N_SETA: |
978 | case N_SETT: | |
979 | case N_SETD: | |
980 | case N_SETB: | |
6db82ea7 SC |
981 | { |
982 | char *copy = bfd_alloc(abfd, strlen(cache_ptr->symbol.name)+1); | |
983 | asection *section ; | |
984 | asection *into_section; | |
985 | ||
986 | arelent_chain *reloc = (arelent_chain *)bfd_alloc(abfd, sizeof(arelent_chain)); | |
987 | strcpy(copy, cache_ptr->symbol.name); | |
988 | ||
989 | /* Make sure that this bfd has a section with the right contructor | |
990 | name */ | |
991 | section = bfd_get_section_by_name (abfd, copy); | |
992 | if (!section) | |
993 | section = bfd_make_section(abfd,copy); | |
994 | ||
995 | /* Build a relocation entry for the constructor */ | |
996 | switch ( (cache_ptr->type & N_TYPE) ) | |
997 | { | |
998 | case N_SETA: | |
999 | into_section = &bfd_abs_section; | |
1000 | break; | |
1001 | case N_SETT: | |
1002 | into_section = (asection *)obj_textsec(abfd); | |
1003 | break; | |
1004 | case N_SETD: | |
1005 | into_section = (asection *)obj_datasec(abfd); | |
1006 | break; | |
1007 | case N_SETB: | |
1008 | into_section = (asection *)obj_bsssec(abfd); | |
1009 | break; | |
1010 | default: | |
1011 | abort(); | |
1012 | } | |
1013 | ||
1014 | /* Build a relocation pointing into the constuctor section | |
1015 | pointing at the symbol in the set vector specified */ | |
1016 | ||
1017 | reloc->relent.addend = cache_ptr->symbol.value; | |
1018 | cache_ptr->symbol.section = into_section->symbol->section; | |
1019 | reloc->relent.sym_ptr_ptr = into_section->symbol_ptr_ptr; | |
1020 | ||
c618de01 | 1021 | |
6db82ea7 SC |
1022 | /* We modify the symbol to belong to a section depending upon the |
1023 | name of the symbol - probably __CTOR__ or __DTOR__ but we don't | |
1024 | really care, and add to the size of the section to contain a | |
1025 | pointer to the symbol. Build a reloc entry to relocate to this | |
1026 | symbol attached to this section. */ | |
c618de01 | 1027 | |
6db82ea7 SC |
1028 | section->flags = SEC_CONSTRUCTOR; |
1029 | ||
c618de01 | 1030 | |
6db82ea7 SC |
1031 | section->reloc_count++; |
1032 | section->alignment_power = 2; | |
1033 | ||
1034 | reloc->next = section->constructor_chain; | |
1035 | section->constructor_chain = reloc; | |
1036 | reloc->relent.address = section->_raw_size; | |
1037 | section->_raw_size += sizeof(int *); | |
1038 | ||
1039 | reloc->relent.howto = howto_table_ext + CTOR_TABLE_RELOC_IDX; | |
1040 | cache_ptr->symbol.flags |= BSF_DEBUGGING | BSF_CONSTRUCTOR; | |
1041 | } | |
9e2dad8e | 1042 | break; |
7ed4093a | 1043 | default: |
88dfcd68 | 1044 | if (cache_ptr->type == N_WARNING) |
6db82ea7 SC |
1045 | { |
1046 | /* This symbol is the text of a warning message, the next symbol | |
1047 | is the symbol to associate the warning with */ | |
1048 | cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_WARNING; | |
88dfcd68 | 1049 | cache_ptr->symbol.value = (bfd_vma)((cache_ptr+1)); |
6db82ea7 SC |
1050 | /* We furgle with the next symbol in place. We don't want it to be undefined, we'll trample the type */ |
1051 | (sym_pointer+1)->e_type[0] = 0xff; | |
88dfcd68 SC |
1052 | break; |
1053 | } | |
6db82ea7 SC |
1054 | if ((cache_ptr->type | N_EXT) == (N_INDR | N_EXT)) { |
1055 | /* Two symbols in a row for an INDR message. The first symbol | |
1056 | contains the name we will match, the second symbol contains the | |
1057 | name the first name is translated into. It is supplied to us | |
1058 | undefined. This is good, since we want to pull in any files which | |
1059 | define it */ | |
1060 | cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_INDIRECT; | |
1061 | cache_ptr->symbol.value = (bfd_vma)((cache_ptr+1)); | |
1062 | cache_ptr->symbol.section = &bfd_und_section; | |
1063 | break; | |
1064 | } | |
88dfcd68 SC |
1065 | |
1066 | ||
7ed4093a | 1067 | if (sym_is_debugger_info (cache_ptr)) { |
6db82ea7 SC |
1068 | cache_ptr->symbol.flags = BSF_DEBUGGING ; |
1069 | /* Work out the section correct for this symbol */ | |
1070 | switch (cache_ptr->type & N_TYPE) | |
1071 | { | |
1072 | case N_TEXT: | |
1073 | case N_FN: | |
1074 | cache_ptr->symbol.section = obj_textsec (abfd); | |
1075 | cache_ptr->symbol.value -= obj_textsec(abfd)->vma; | |
1076 | break; | |
1077 | case N_DATA: | |
1078 | cache_ptr->symbol.value -= obj_datasec(abfd)->vma; | |
1079 | cache_ptr->symbol.section = obj_datasec (abfd); | |
1080 | break; | |
1081 | case N_BSS : | |
1082 | cache_ptr->symbol.section = obj_bsssec (abfd); | |
1083 | cache_ptr->symbol.value -= obj_bsssec(abfd)->vma; | |
1084 | break; | |
1085 | default: | |
1086 | case N_ABS: | |
88dfcd68 | 1087 | |
6db82ea7 SC |
1088 | cache_ptr->symbol.section = &bfd_abs_section; |
1089 | break; | |
7ed4093a | 1090 | } |
6db82ea7 SC |
1091 | } |
1092 | else { | |
1093 | ||
1094 | if (sym_is_fortrancommon (cache_ptr)) | |
1095 | { | |
1096 | cache_ptr->symbol.flags = 0; | |
1097 | cache_ptr->symbol.section = &bfd_com_section; | |
7ed4093a SC |
1098 | } |
1099 | else { | |
6db82ea7 SC |
1100 | |
1101 | ||
1102 | } | |
88dfcd68 | 1103 | |
7ed4093a SC |
1104 | /* In a.out, the value of a symbol is always relative to the |
1105 | * start of the file, if this is a data symbol we'll subtract | |
1106 | * the size of the text section to get the section relative | |
1107 | * value. If this is a bss symbol (which would be strange) | |
1108 | * we'll subtract the size of the previous two sections | |
1109 | * to find the section relative address. | |
1110 | */ | |
88dfcd68 | 1111 | |
7ed4093a | 1112 | if (sym_in_text_section (cache_ptr)) { |
6db82ea7 SC |
1113 | cache_ptr->symbol.value -= obj_textsec(abfd)->vma; |
1114 | cache_ptr->symbol.section = obj_textsec (abfd); | |
1115 | } | |
7ed4093a | 1116 | else if (sym_in_data_section (cache_ptr)){ |
6db82ea7 SC |
1117 | cache_ptr->symbol.value -= obj_datasec(abfd)->vma; |
1118 | cache_ptr->symbol.section = obj_datasec (abfd); | |
1119 | } | |
7ed4093a | 1120 | else if (sym_in_bss_section(cache_ptr)) { |
6db82ea7 SC |
1121 | cache_ptr->symbol.section = obj_bsssec (abfd); |
1122 | cache_ptr->symbol.value -= obj_bsssec(abfd)->vma; | |
1123 | } | |
1124 | else if (sym_is_undefined (cache_ptr)) { | |
1125 | cache_ptr->symbol.flags = 0; | |
1126 | cache_ptr->symbol.section = &bfd_und_section; | |
1127 | } | |
1128 | else if (sym_is_absolute(cache_ptr)) | |
1129 | { | |
1130 | cache_ptr->symbol.section = &bfd_abs_section; | |
7ed4093a | 1131 | } |
6db82ea7 SC |
1132 | |
1133 | if (sym_is_global_defn (cache_ptr)) | |
1134 | { | |
1135 | cache_ptr->symbol.flags = BSF_GLOBAL | BSF_EXPORT; | |
1136 | } | |
1137 | else | |
1138 | { | |
1139 | cache_ptr->symbol.flags = BSF_LOCAL; | |
7ed4093a SC |
1140 | } |
1141 | } | |
7ed4093a SC |
1142 | } |
1143 | } | |
1144 | ||
6db82ea7 SC |
1145 | |
1146 | ||
7ed4093a SC |
1147 | static void |
1148 | DEFUN(translate_to_native_sym_flags,(sym_pointer, cache_ptr, abfd), | |
1149 | struct external_nlist *sym_pointer AND | |
1150 | asymbol *cache_ptr AND | |
1151 | bfd *abfd) | |
1152 | { | |
1153 | bfd_vma value = cache_ptr->value; | |
1154 | ||
10dea9ed DHW |
1155 | /* mask out any existing type bits in case copying from one section |
1156 | to another */ | |
1157 | sym_pointer->e_type[0] &= ~N_TYPE; | |
1158 | ||
6db82ea7 | 1159 | if (bfd_get_output_section(cache_ptr) == obj_bsssec (abfd)) { |
7ed4093a SC |
1160 | sym_pointer->e_type[0] |= N_BSS; |
1161 | } | |
6db82ea7 | 1162 | else if (bfd_get_output_section(cache_ptr) == obj_datasec (abfd)) { |
7ed4093a SC |
1163 | sym_pointer->e_type[0] |= N_DATA; |
1164 | } | |
6db82ea7 | 1165 | else if (bfd_get_output_section(cache_ptr) == obj_textsec (abfd)) { |
7ed4093a SC |
1166 | sym_pointer->e_type[0] |= N_TEXT; |
1167 | } | |
6db82ea7 SC |
1168 | else if (bfd_get_output_section(cache_ptr) == &bfd_abs_section) |
1169 | { | |
7ed4093a SC |
1170 | sym_pointer->e_type[0] |= N_ABS; |
1171 | } | |
6db82ea7 SC |
1172 | else if (bfd_get_output_section(cache_ptr) == &bfd_und_section) |
1173 | { | |
7ed4093a SC |
1174 | sym_pointer->e_type[0] = (N_UNDF | N_EXT); |
1175 | } | |
6db82ea7 SC |
1176 | else if (bfd_get_output_section(cache_ptr) == &bfd_com_section) { |
1177 | sym_pointer->e_type[0] = (N_UNDF | N_EXT); | |
1178 | } | |
1179 | else { | |
e7b4046c SC |
1180 | if (cache_ptr->section->output_section) |
1181 | { | |
1182 | ||
1183 | bfd_error_vector.nonrepresentable_section(abfd, | |
1184 | bfd_get_output_section(cache_ptr)->name); | |
1185 | } | |
1186 | else | |
1187 | { | |
1188 | bfd_error_vector.nonrepresentable_section(abfd, | |
1189 | cache_ptr->section->name); | |
1190 | ||
1191 | } | |
1192 | ||
7ed4093a | 1193 | } |
6db82ea7 | 1194 | /* Turn the symbol from section relative to absolute again */ |
7ed4093a | 1195 | |
6db82ea7 SC |
1196 | value += cache_ptr->section->output_section->vma + cache_ptr->section->output_offset ; |
1197 | ||
1198 | ||
1199 | if (cache_ptr->flags & (BSF_WARNING)) { | |
1200 | (sym_pointer+1)->e_type[0] = 1; | |
1201 | } | |
1202 | ||
1203 | if (cache_ptr->flags & (BSF_GLOBAL | BSF_EXPORT)) { | |
7ed4093a SC |
1204 | sym_pointer->e_type[0] |= N_EXT; |
1205 | } | |
6db82ea7 | 1206 | if (cache_ptr->flags & BSF_DEBUGGING) { |
7ed4093a SC |
1207 | sym_pointer->e_type [0]= ((aout_symbol_type *)cache_ptr)->type; |
1208 | } | |
6db82ea7 | 1209 | |
7ed4093a SC |
1210 | PUT_WORD(abfd, value, sym_pointer->e_value); |
1211 | } | |
1212 | \f | |
1213 | /* Native-level interface to symbols. */ | |
1214 | ||
1215 | /* We read the symbols into a buffer, which is discarded when this | |
1216 | function exits. We read the strings into a buffer large enough to | |
1217 | hold them all plus all the cached symbol entries. */ | |
1218 | ||
1219 | asymbol * | |
1220 | DEFUN(NAME(aout,make_empty_symbol),(abfd), | |
1221 | bfd *abfd) | |
9e2dad8e JG |
1222 | { |
1223 | aout_symbol_type *new = | |
1224 | (aout_symbol_type *)bfd_zalloc (abfd, sizeof (aout_symbol_type)); | |
1225 | new->symbol.the_bfd = abfd; | |
7ed4093a | 1226 | |
9e2dad8e JG |
1227 | return &new->symbol; |
1228 | } | |
7ed4093a SC |
1229 | |
1230 | boolean | |
1231 | DEFUN(NAME(aout,slurp_symbol_table),(abfd), | |
1232 | bfd *abfd) | |
9e2dad8e JG |
1233 | { |
1234 | bfd_size_type symbol_size; | |
1235 | bfd_size_type string_size; | |
1236 | unsigned char string_chars[BYTES_IN_WORD]; | |
1237 | struct external_nlist *syms; | |
1238 | char *strings; | |
1239 | aout_symbol_type *cached; | |
7ed4093a | 1240 | |
9e2dad8e JG |
1241 | /* If there's no work to be done, don't do any */ |
1242 | if (obj_aout_symbols (abfd) != (aout_symbol_type *)NULL) return true; | |
1243 | symbol_size = exec_hdr(abfd)->a_syms; | |
1244 | if (symbol_size == 0) { | |
1245 | bfd_error = no_symbols; | |
1246 | return false; | |
1247 | } | |
7ed4093a | 1248 | |
9e2dad8e JG |
1249 | bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET); |
1250 | if (bfd_read ((PTR)string_chars, BYTES_IN_WORD, 1, abfd) != BYTES_IN_WORD) | |
1251 | return false; | |
1252 | string_size = GET_WORD (abfd, string_chars); | |
7ed4093a | 1253 | |
9e2dad8e JG |
1254 | strings =(char *) bfd_alloc(abfd, string_size + 1); |
1255 | cached = (aout_symbol_type *) | |
1256 | bfd_zalloc(abfd, (bfd_size_type)(bfd_get_symcount (abfd) * sizeof(aout_symbol_type))); | |
1257 | ||
1258 | /* malloc this, so we can free it if simply. The symbol caching | |
1259 | might want to allocate onto the bfd's obstack */ | |
98d43107 | 1260 | syms = (struct external_nlist *) bfd_xmalloc(symbol_size); |
9e2dad8e JG |
1261 | bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET); |
1262 | if (bfd_read ((PTR)syms, 1, symbol_size, abfd) != symbol_size) { | |
1263 | bailout: | |
1264 | if (syms) free (syms); | |
1265 | if (cached) bfd_release (abfd, cached); | |
1266 | if (strings)bfd_release (abfd, strings); | |
1267 | return false; | |
1268 | } | |
7ed4093a | 1269 | |
9e2dad8e JG |
1270 | bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET); |
1271 | if (bfd_read ((PTR)strings, 1, string_size, abfd) != string_size) { | |
1272 | goto bailout; | |
1273 | } | |
7ed4093a | 1274 | |
9e2dad8e JG |
1275 | /* OK, now walk the new symtable, cacheing symbol properties */ |
1276 | { | |
1277 | register struct external_nlist *sym_pointer; | |
1278 | register struct external_nlist *sym_end = syms + bfd_get_symcount (abfd); | |
1279 | register aout_symbol_type *cache_ptr = cached; | |
7ed4093a | 1280 | |
9e2dad8e JG |
1281 | /* Run through table and copy values */ |
1282 | for (sym_pointer = syms, cache_ptr = cached; | |
1283 | sym_pointer < sym_end; sym_pointer++, cache_ptr++) | |
1284 | { | |
1285 | bfd_vma x = GET_WORD(abfd, sym_pointer->e_strx); | |
1286 | cache_ptr->symbol.the_bfd = abfd; | |
1287 | if (x) | |
1288 | cache_ptr->symbol.name = x + strings; | |
1289 | else | |
1290 | cache_ptr->symbol.name = (char *)NULL; | |
7ed4093a | 1291 | |
9e2dad8e JG |
1292 | cache_ptr->symbol.value = GET_SWORD(abfd, sym_pointer->e_value); |
1293 | cache_ptr->desc = bfd_get_16(abfd, sym_pointer->e_desc); | |
1294 | cache_ptr->other =bfd_get_8(abfd, sym_pointer->e_other); | |
1295 | cache_ptr->type = bfd_get_8(abfd, sym_pointer->e_type); | |
1296 | cache_ptr->symbol.udata = 0; | |
1297 | translate_from_native_sym_flags (sym_pointer, cache_ptr, abfd); | |
1298 | } | |
1299 | } | |
7ed4093a | 1300 | |
9e2dad8e JG |
1301 | obj_aout_symbols (abfd) = cached; |
1302 | free((PTR)syms); | |
7ed4093a | 1303 | |
9e2dad8e JG |
1304 | return true; |
1305 | } | |
7ed4093a SC |
1306 | |
1307 | ||
1308 | void | |
1309 | DEFUN(NAME(aout,write_syms),(abfd), | |
1310 | bfd *abfd) | |
1311 | { | |
1312 | unsigned int count ; | |
1313 | asymbol **generic = bfd_get_outsymbols (abfd); | |
1314 | ||
1315 | bfd_size_type stindex = BYTES_IN_WORD; /* initial string length */ | |
1316 | ||
1317 | for (count = 0; count < bfd_get_symcount (abfd); count++) { | |
1318 | asymbol *g = generic[count]; | |
1319 | struct external_nlist nsp; | |
6db82ea7 SC |
1320 | |
1321 | ||
7ed4093a SC |
1322 | if (g->name) { |
1323 | unsigned int length = strlen(g->name) +1; | |
1324 | PUT_WORD (abfd, stindex, (unsigned char *)nsp.e_strx); | |
1325 | stindex += length; | |
1326 | } | |
6db82ea7 SC |
1327 | else |
1328 | ||
1329 | { | |
7ed4093a SC |
1330 | PUT_WORD (abfd, 0, (unsigned char *)nsp.e_strx); |
1331 | } | |
1332 | ||
1333 | if (g->the_bfd->xvec->flavour == abfd->xvec->flavour) | |
1334 | { | |
1335 | bfd_h_put_16(abfd, aout_symbol(g)->desc, nsp.e_desc); | |
1336 | bfd_h_put_8(abfd, aout_symbol(g)->other, nsp.e_other); | |
1337 | bfd_h_put_8(abfd, aout_symbol(g)->type, nsp.e_type); | |
1338 | } | |
1339 | else | |
1340 | { | |
1341 | bfd_h_put_16(abfd,0, nsp.e_desc); | |
1342 | bfd_h_put_8(abfd, 0, nsp.e_other); | |
1343 | bfd_h_put_8(abfd, 0, nsp.e_type); | |
1344 | } | |
7b02b4ed | 1345 | |
7d003262 | 1346 | translate_to_native_sym_flags (&nsp, g, abfd); |
7b02b4ed JG |
1347 | |
1348 | bfd_write((PTR)&nsp,1,EXTERNAL_NLIST_SIZE, abfd); | |
7ed4093a SC |
1349 | } |
1350 | ||
7ed4093a | 1351 | /* Now output the strings. Be sure to put string length into correct |
7b02b4ed | 1352 | byte ordering before writing it. */ |
7ed4093a SC |
1353 | { |
1354 | char buffer[BYTES_IN_WORD]; | |
1355 | PUT_WORD (abfd, stindex, (unsigned char *)buffer); | |
1356 | ||
1357 | bfd_write((PTR)buffer, 1, BYTES_IN_WORD, abfd); | |
1358 | } | |
1359 | generic = bfd_get_outsymbols(abfd); | |
1360 | for (count = 0; count < bfd_get_symcount(abfd); count++) | |
1361 | { | |
1362 | asymbol *g = *(generic++); | |
1363 | ||
1364 | if (g->name) | |
1365 | { | |
1366 | size_t length = strlen(g->name)+1; | |
1367 | bfd_write((PTR)g->name, 1, length, abfd); | |
1368 | } | |
c618de01 | 1369 | g->KEEPIT = (KEEPITTYPE) count; |
7ed4093a SC |
1370 | } |
1371 | } | |
1372 | ||
1373 | ||
1374 | ||
1375 | unsigned int | |
1376 | DEFUN(NAME(aout,get_symtab),(abfd, location), | |
1377 | bfd *abfd AND | |
1378 | asymbol **location) | |
3f7607af | 1379 | { |
7ed4093a SC |
1380 | unsigned int counter = 0; |
1381 | aout_symbol_type *symbase; | |
ce07dd7c | 1382 | |
7ed4093a | 1383 | if (!NAME(aout,slurp_symbol_table)(abfd)) return 0; |
ce07dd7c | 1384 | |
7ed4093a SC |
1385 | for (symbase = obj_aout_symbols(abfd); counter++ < bfd_get_symcount (abfd);) |
1386 | *(location++) = (asymbol *)( symbase++); | |
1387 | *location++ =0; | |
ce07dd7c | 1388 | return bfd_get_symcount (abfd); |
3f7607af | 1389 | } |
7ed4093a SC |
1390 | |
1391 | \f | |
1392 | /* Standard reloc stuff */ | |
1393 | /* Output standard relocation information to a file in target byte order. */ | |
1394 | ||
1395 | void | |
1396 | DEFUN(NAME(aout,swap_std_reloc_out),(abfd, g, natptr), | |
1397 | bfd *abfd AND | |
1398 | arelent *g AND | |
1399 | struct reloc_std_external *natptr) | |
3f7607af | 1400 | { |
6db82ea7 SC |
1401 | int r_index; |
1402 | asymbol *sym = *(g->sym_ptr_ptr); | |
1403 | int r_extern; | |
1404 | unsigned int r_length; | |
1405 | int r_pcrel; | |
1406 | int r_baserel, r_jmptable, r_relative; | |
1407 | unsigned int r_addend; | |
1408 | asection *output_section = sym->section->output_section; | |
ce07dd7c | 1409 | |
6db82ea7 | 1410 | PUT_WORD(abfd, g->address, natptr->r_address); |
ce07dd7c | 1411 | |
6db82ea7 SC |
1412 | r_length = g->howto->size ; /* Size as a power of two */ |
1413 | r_pcrel = (int) g->howto->pc_relative; /* Relative to PC? */ | |
1414 | /* r_baserel, r_jmptable, r_relative??? FIXME-soon */ | |
1415 | r_baserel = 0; | |
1416 | r_jmptable = 0; | |
1417 | r_relative = 0; | |
7ed4093a | 1418 | |
6db82ea7 | 1419 | r_addend = g->addend + (*(g->sym_ptr_ptr))->section->output_section->vma; |
7ed4093a | 1420 | |
6db82ea7 SC |
1421 | /* name was clobbered by aout_write_syms to be symbol index */ |
1422 | ||
ce07dd7c KR |
1423 | if (output_section == &bfd_com_section |
1424 | || output_section == &bfd_abs_section | |
1425 | || output_section == &bfd_und_section) | |
1426 | { | |
1427 | /* Fill in symbol */ | |
1428 | r_extern = 1; | |
1429 | r_index = stoi((*(g->sym_ptr_ptr))->KEEPIT); | |
1430 | } | |
6db82ea7 | 1431 | else |
ce07dd7c KR |
1432 | { |
1433 | /* Just an ordinary section */ | |
1434 | r_extern = 0; | |
1435 | r_index = output_section->target_index; | |
1436 | } | |
1437 | ||
6db82ea7 SC |
1438 | /* now the fun stuff */ |
1439 | if (abfd->xvec->header_byteorder_big_p != false) { | |
7ed4093a SC |
1440 | natptr->r_index[0] = r_index >> 16; |
1441 | natptr->r_index[1] = r_index >> 8; | |
1442 | natptr->r_index[2] = r_index; | |
1443 | natptr->r_type[0] = | |
6db82ea7 SC |
1444 | (r_extern? RELOC_STD_BITS_EXTERN_BIG: 0) |
1445 | | (r_pcrel? RELOC_STD_BITS_PCREL_BIG: 0) | |
1446 | | (r_baserel? RELOC_STD_BITS_BASEREL_BIG: 0) | |
1447 | | (r_jmptable? RELOC_STD_BITS_JMPTABLE_BIG: 0) | |
1448 | | (r_relative? RELOC_STD_BITS_RELATIVE_BIG: 0) | |
1449 | | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG); | |
7ed4093a | 1450 | } else { |
6db82ea7 SC |
1451 | natptr->r_index[2] = r_index >> 16; |
1452 | natptr->r_index[1] = r_index >> 8; | |
1453 | natptr->r_index[0] = r_index; | |
1454 | natptr->r_type[0] = | |
1455 | (r_extern? RELOC_STD_BITS_EXTERN_LITTLE: 0) | |
7ed4093a | 1456 | | (r_pcrel? RELOC_STD_BITS_PCREL_LITTLE: 0) |
6db82ea7 SC |
1457 | | (r_baserel? RELOC_STD_BITS_BASEREL_LITTLE: 0) |
1458 | | (r_jmptable? RELOC_STD_BITS_JMPTABLE_LITTLE: 0) | |
1459 | | (r_relative? RELOC_STD_BITS_RELATIVE_LITTLE: 0) | |
1460 | | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE); | |
1461 | } | |
3f7607af | 1462 | } |
7ed4093a SC |
1463 | |
1464 | ||
1465 | /* Extended stuff */ | |
1466 | /* Output extended relocation information to a file in target byte order. */ | |
1467 | ||
1468 | void | |
1469 | DEFUN(NAME(aout,swap_ext_reloc_out),(abfd, g, natptr), | |
1470 | bfd *abfd AND | |
1471 | arelent *g AND | |
1472 | register struct reloc_ext_external *natptr) | |
3f7607af | 1473 | { |
6db82ea7 SC |
1474 | int r_index; |
1475 | int r_extern; | |
1476 | unsigned int r_type; | |
1477 | unsigned int r_addend; | |
1478 | asymbol *sym = *(g->sym_ptr_ptr); | |
1479 | asection *output_section = sym->section->output_section; | |
1480 | ||
1481 | PUT_WORD (abfd, g->address, natptr->r_address); | |
7ed4093a | 1482 | |
6db82ea7 | 1483 | r_type = (unsigned int) g->howto->type; |
7ed4093a | 1484 | |
6db82ea7 | 1485 | r_addend = g->addend + (*(g->sym_ptr_ptr))->section->output_section->vma; |
7ed4093a | 1486 | |
7ed4093a | 1487 | |
10dea9ed DHW |
1488 | if (output_section == &bfd_com_section |
1489 | || output_section == &bfd_abs_section | |
1490 | || output_section == &bfd_und_section) | |
6db82ea7 SC |
1491 | { |
1492 | /* Fill in symbol */ | |
1493 | r_extern = 1; | |
1494 | r_index = stoi((*(g->sym_ptr_ptr))->KEEPIT); | |
1495 | } | |
1496 | else | |
1497 | { | |
1498 | /* Just an ordinary section */ | |
1499 | r_extern = 0; | |
1500 | r_index = output_section->target_index; | |
1501 | } | |
1502 | ||
1503 | ||
7ed4093a SC |
1504 | /* now the fun stuff */ |
1505 | if (abfd->xvec->header_byteorder_big_p != false) { | |
6db82ea7 SC |
1506 | natptr->r_index[0] = r_index >> 16; |
1507 | natptr->r_index[1] = r_index >> 8; | |
1508 | natptr->r_index[2] = r_index; | |
1509 | natptr->r_type[0] = | |
1510 | (r_extern? RELOC_EXT_BITS_EXTERN_BIG: 0) | |
7ed4093a | 1511 | | (r_type << RELOC_EXT_BITS_TYPE_SH_BIG); |
6db82ea7 SC |
1512 | } else { |
1513 | natptr->r_index[2] = r_index >> 16; | |
1514 | natptr->r_index[1] = r_index >> 8; | |
1515 | natptr->r_index[0] = r_index; | |
1516 | natptr->r_type[0] = | |
1517 | (r_extern? RELOC_EXT_BITS_EXTERN_LITTLE: 0) | |
1518 | | (r_type << RELOC_EXT_BITS_TYPE_SH_LITTLE); | |
1519 | } | |
7ed4093a SC |
1520 | |
1521 | PUT_WORD (abfd, r_addend, natptr->r_addend); | |
1522 | } | |
1523 | ||
6db82ea7 SC |
1524 | /* BFD deals internally with all things based from the section they're |
1525 | in. so, something in 10 bytes into a text section with a base of | |
1526 | 50 would have a symbol (.text+10) and know .text vma was 50. | |
1527 | ||
1528 | Aout keeps all it's symbols based from zero, so the symbol would | |
1529 | contain 60. This macro subs the base of each section from the value | |
1530 | to give the true offset from the section */ | |
1531 | ||
1532 | ||
7ed4093a SC |
1533 | #define MOVE_ADDRESS(ad) \ |
1534 | if (r_extern) { \ | |
6db82ea7 SC |
1535 | /* undefined symbol */ \ |
1536 | cache_ptr->sym_ptr_ptr = symbols + r_index; \ | |
1537 | cache_ptr->addend = ad; \ | |
1538 | } else { \ | |
1539 | /* defined, section relative. replace symbol with pointer to \ | |
1540 | symbol which points to section */ \ | |
7ed4093a SC |
1541 | switch (r_index) { \ |
1542 | case N_TEXT: \ | |
1543 | case N_TEXT | N_EXT: \ | |
6db82ea7 | 1544 | cache_ptr->sym_ptr_ptr = obj_textsec(abfd)->symbol_ptr_ptr; \ |
7ed4093a SC |
1545 | cache_ptr->addend = ad - su->textsec->vma; \ |
1546 | break; \ | |
1547 | case N_DATA: \ | |
1548 | case N_DATA | N_EXT: \ | |
6db82ea7 | 1549 | cache_ptr->sym_ptr_ptr = obj_datasec(abfd)->symbol_ptr_ptr; \ |
7ed4093a SC |
1550 | cache_ptr->addend = ad - su->datasec->vma; \ |
1551 | break; \ | |
1552 | case N_BSS: \ | |
1553 | case N_BSS | N_EXT: \ | |
6db82ea7 | 1554 | cache_ptr->sym_ptr_ptr = obj_bsssec(abfd)->symbol_ptr_ptr; \ |
7ed4093a SC |
1555 | cache_ptr->addend = ad - su->bsssec->vma; \ |
1556 | break; \ | |
6db82ea7 | 1557 | default: \ |
7ed4093a SC |
1558 | case N_ABS: \ |
1559 | case N_ABS | N_EXT: \ | |
6db82ea7 SC |
1560 | cache_ptr->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr; \ |
1561 | cache_ptr->addend = ad; \ | |
7ed4093a SC |
1562 | break; \ |
1563 | } \ | |
1564 | } \ | |
1565 | ||
1566 | void | |
1567 | DEFUN(NAME(aout,swap_ext_reloc_in), (abfd, bytes, cache_ptr, symbols), | |
1568 | bfd *abfd AND | |
1569 | struct reloc_ext_external *bytes AND | |
1570 | arelent *cache_ptr AND | |
1571 | asymbol **symbols) | |
1572 | { | |
1573 | int r_index; | |
1574 | int r_extern; | |
1575 | unsigned int r_type; | |
6db82ea7 | 1576 | struct aoutdata *su = &(abfd->tdata.aout_data->a); |
7ed4093a SC |
1577 | |
1578 | cache_ptr->address = (GET_SWORD (abfd, bytes->r_address)); | |
1579 | ||
1580 | /* now the fun stuff */ | |
1581 | if (abfd->xvec->header_byteorder_big_p != false) { | |
1582 | r_index = (bytes->r_index[0] << 16) | |
1583 | | (bytes->r_index[1] << 8) | |
1584 | | bytes->r_index[2]; | |
1585 | r_extern = (0 != (bytes->r_type[0] & RELOC_EXT_BITS_EXTERN_BIG)); | |
1586 | r_type = (bytes->r_type[0] & RELOC_EXT_BITS_TYPE_BIG) | |
1587 | >> RELOC_EXT_BITS_TYPE_SH_BIG; | |
1588 | } else { | |
1589 | r_index = (bytes->r_index[2] << 16) | |
1590 | | (bytes->r_index[1] << 8) | |
1591 | | bytes->r_index[0]; | |
1592 | r_extern = (0 != (bytes->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE)); | |
1593 | r_type = (bytes->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE) | |
1594 | >> RELOC_EXT_BITS_TYPE_SH_LITTLE; | |
1595 | } | |
1596 | ||
1597 | cache_ptr->howto = howto_table_ext + r_type; | |
6db82ea7 | 1598 | MOVE_ADDRESS(GET_SWORD(abfd, bytes->r_addend)); |
7ed4093a SC |
1599 | } |
1600 | ||
1601 | void | |
1602 | DEFUN(NAME(aout,swap_std_reloc_in), (abfd, bytes, cache_ptr, symbols), | |
1603 | bfd *abfd AND | |
1604 | struct reloc_std_external *bytes AND | |
1605 | arelent *cache_ptr AND | |
1606 | asymbol **symbols) | |
1607 | { | |
1608 | int r_index; | |
1609 | int r_extern; | |
1610 | unsigned int r_length; | |
1611 | int r_pcrel; | |
1612 | int r_baserel, r_jmptable, r_relative; | |
6db82ea7 | 1613 | struct aoutdata *su = &(abfd->tdata.aout_data->a); |
7ed4093a SC |
1614 | |
1615 | cache_ptr->address = (int32_type)(bfd_h_get_32 (abfd, bytes->r_address)); | |
1616 | ||
1617 | /* now the fun stuff */ | |
1618 | if (abfd->xvec->header_byteorder_big_p != false) { | |
1619 | r_index = (bytes->r_index[0] << 16) | |
1620 | | (bytes->r_index[1] << 8) | |
1621 | | bytes->r_index[2]; | |
1622 | r_extern = (0 != (bytes->r_type[0] & RELOC_STD_BITS_EXTERN_BIG)); | |
1623 | r_pcrel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_PCREL_BIG)); | |
1624 | r_baserel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_BASEREL_BIG)); | |
1625 | r_jmptable= (0 != (bytes->r_type[0] & RELOC_STD_BITS_JMPTABLE_BIG)); | |
1626 | r_relative= (0 != (bytes->r_type[0] & RELOC_STD_BITS_RELATIVE_BIG)); | |
1627 | r_length = (bytes->r_type[0] & RELOC_STD_BITS_LENGTH_BIG) | |
1628 | >> RELOC_STD_BITS_LENGTH_SH_BIG; | |
1629 | } else { | |
1630 | r_index = (bytes->r_index[2] << 16) | |
1631 | | (bytes->r_index[1] << 8) | |
1632 | | bytes->r_index[0]; | |
1633 | r_extern = (0 != (bytes->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE)); | |
1634 | r_pcrel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE)); | |
1635 | r_baserel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_BASEREL_LITTLE)); | |
1636 | r_jmptable= (0 != (bytes->r_type[0] & RELOC_STD_BITS_JMPTABLE_LITTLE)); | |
1637 | r_relative= (0 != (bytes->r_type[0] & RELOC_STD_BITS_RELATIVE_LITTLE)); | |
1638 | r_length = (bytes->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE) | |
1639 | >> RELOC_STD_BITS_LENGTH_SH_LITTLE; | |
1640 | } | |
1641 | ||
1642 | cache_ptr->howto = howto_table_std + r_length + 4 * r_pcrel; | |
1643 | /* FIXME-soon: Roll baserel, jmptable, relative bits into howto setting */ | |
1644 | ||
1645 | MOVE_ADDRESS(0); | |
1646 | } | |
1647 | ||
1648 | /* Reloc hackery */ | |
1649 | ||
1650 | boolean | |
1651 | DEFUN(NAME(aout,slurp_reloc_table),(abfd, asect, symbols), | |
1652 | bfd *abfd AND | |
1653 | sec_ptr asect AND | |
1654 | asymbol **symbols) | |
1655 | { | |
1656 | unsigned int count; | |
1657 | bfd_size_type reloc_size; | |
1658 | PTR relocs; | |
1659 | arelent *reloc_cache; | |
1660 | size_t each_size; | |
1661 | ||
1662 | if (asect->relocation) return true; | |
1663 | ||
1664 | if (asect->flags & SEC_CONSTRUCTOR) return true; | |
1665 | ||
1666 | if (asect == obj_datasec (abfd)) { | |
1667 | reloc_size = exec_hdr(abfd)->a_drsize; | |
1668 | goto doit; | |
1669 | } | |
1670 | ||
1671 | if (asect == obj_textsec (abfd)) { | |
1672 | reloc_size = exec_hdr(abfd)->a_trsize; | |
1673 | goto doit; | |
1674 | } | |
1675 | ||
1676 | bfd_error = invalid_operation; | |
1677 | return false; | |
1678 | ||
1679 | doit: | |
1680 | bfd_seek (abfd, asect->rel_filepos, SEEK_SET); | |
1681 | each_size = obj_reloc_entry_size (abfd); | |
1682 | ||
1683 | count = reloc_size / each_size; | |
1684 | ||
1685 | ||
1686 | reloc_cache = (arelent *) bfd_zalloc (abfd, (size_t)(count * sizeof | |
1687 | (arelent))); | |
1688 | if (!reloc_cache) { | |
1689 | nomem: | |
1690 | bfd_error = no_memory; | |
1691 | return false; | |
1692 | } | |
1693 | ||
1694 | relocs = (PTR) bfd_alloc (abfd, reloc_size); | |
1695 | if (!relocs) { | |
1696 | bfd_release (abfd, reloc_cache); | |
1697 | goto nomem; | |
1698 | } | |
1699 | ||
1700 | if (bfd_read (relocs, 1, reloc_size, abfd) != reloc_size) { | |
1701 | bfd_release (abfd, relocs); | |
1702 | bfd_release (abfd, reloc_cache); | |
1703 | bfd_error = system_call_error; | |
1704 | return false; | |
1705 | } | |
1706 | ||
1707 | if (each_size == RELOC_EXT_SIZE) { | |
1708 | register struct reloc_ext_external *rptr = (struct reloc_ext_external *) relocs; | |
1709 | unsigned int counter = 0; | |
1710 | arelent *cache_ptr = reloc_cache; | |
1711 | ||
1712 | for (; counter < count; counter++, rptr++, cache_ptr++) { | |
1713 | NAME(aout,swap_ext_reloc_in)(abfd, rptr, cache_ptr, symbols); | |
1714 | } | |
1715 | } else { | |
1716 | register struct reloc_std_external *rptr = (struct reloc_std_external*) relocs; | |
1717 | unsigned int counter = 0; | |
1718 | arelent *cache_ptr = reloc_cache; | |
1719 | ||
1720 | for (; counter < count; counter++, rptr++, cache_ptr++) { | |
1721 | NAME(aout,swap_std_reloc_in)(abfd, rptr, cache_ptr, symbols); | |
1722 | } | |
1723 | ||
1724 | } | |
1725 | ||
1726 | bfd_release (abfd,relocs); | |
1727 | asect->relocation = reloc_cache; | |
1728 | asect->reloc_count = count; | |
1729 | return true; | |
1730 | } | |
1731 | ||
1732 | ||
1733 | ||
1734 | /* Write out a relocation section into an object file. */ | |
1735 | ||
1736 | boolean | |
1737 | DEFUN(NAME(aout,squirt_out_relocs),(abfd, section), | |
1738 | bfd *abfd AND | |
1739 | asection *section) | |
1740 | { | |
1741 | arelent **generic; | |
1742 | unsigned char *native, *natptr; | |
1743 | size_t each_size; | |
1744 | ||
1745 | unsigned int count = section->reloc_count; | |
1746 | size_t natsize; | |
1747 | ||
1748 | if (count == 0) return true; | |
1749 | ||
1750 | each_size = obj_reloc_entry_size (abfd); | |
1751 | natsize = each_size * count; | |
1752 | native = (unsigned char *) bfd_zalloc (abfd, natsize); | |
1753 | if (!native) { | |
1754 | bfd_error = no_memory; | |
1755 | return false; | |
1756 | } | |
1757 | ||
1758 | generic = section->orelocation; | |
1759 | ||
1760 | if (each_size == RELOC_EXT_SIZE) | |
1761 | { | |
1762 | for (natptr = native; | |
1763 | count != 0; | |
1764 | --count, natptr += each_size, ++generic) | |
1765 | NAME(aout,swap_ext_reloc_out) (abfd, *generic, (struct reloc_ext_external *)natptr); | |
1766 | } | |
1767 | else | |
1768 | { | |
1769 | for (natptr = native; | |
1770 | count != 0; | |
1771 | --count, natptr += each_size, ++generic) | |
1772 | NAME(aout,swap_std_reloc_out)(abfd, *generic, (struct reloc_std_external *)natptr); | |
1773 | } | |
1774 | ||
1775 | if ( bfd_write ((PTR) native, 1, natsize, abfd) != natsize) { | |
1776 | bfd_release(abfd, native); | |
1777 | return false; | |
1778 | } | |
1779 | bfd_release (abfd, native); | |
1780 | ||
1781 | return true; | |
1782 | } | |
1783 | ||
1784 | /* This is stupid. This function should be a boolean predicate */ | |
1785 | unsigned int | |
1786 | DEFUN(NAME(aout,canonicalize_reloc),(abfd, section, relptr, symbols), | |
1787 | bfd *abfd AND | |
1788 | sec_ptr section AND | |
1789 | arelent **relptr AND | |
1790 | asymbol **symbols) | |
1791 | { | |
1792 | arelent *tblptr = section->relocation; | |
1793 | unsigned int count; | |
1794 | ||
1795 | if (!(tblptr || NAME(aout,slurp_reloc_table)(abfd, section, symbols))) | |
1796 | return 0; | |
1797 | ||
1798 | if (section->flags & SEC_CONSTRUCTOR) { | |
1799 | arelent_chain *chain = section->constructor_chain; | |
1800 | for (count = 0; count < section->reloc_count; count ++) { | |
1801 | *relptr ++ = &chain->relent; | |
1802 | chain = chain->next; | |
1803 | } | |
1804 | } | |
1805 | else { | |
1806 | tblptr = section->relocation; | |
1807 | if (!tblptr) return 0; | |
1808 | ||
1809 | for (count = 0; count++ < section->reloc_count;) | |
1810 | { | |
1811 | *relptr++ = tblptr++; | |
1812 | } | |
1813 | } | |
1814 | *relptr = 0; | |
1815 | ||
1816 | return section->reloc_count; | |
1817 | } | |
1818 | ||
1819 | unsigned int | |
1820 | DEFUN(NAME(aout,get_reloc_upper_bound),(abfd, asect), | |
1821 | bfd *abfd AND | |
1822 | sec_ptr asect) | |
1823 | { | |
1824 | if (bfd_get_format (abfd) != bfd_object) { | |
1825 | bfd_error = invalid_operation; | |
1826 | return 0; | |
1827 | } | |
1828 | if (asect->flags & SEC_CONSTRUCTOR) { | |
1829 | return (sizeof (arelent *) * (asect->reloc_count+1)); | |
1830 | } | |
1831 | ||
1832 | ||
1833 | if (asect == obj_datasec (abfd)) | |
1834 | return (sizeof (arelent *) * | |
1835 | ((exec_hdr(abfd)->a_drsize / obj_reloc_entry_size (abfd)) | |
1836 | +1)); | |
1837 | ||
1838 | if (asect == obj_textsec (abfd)) | |
1839 | return (sizeof (arelent *) * | |
1840 | ((exec_hdr(abfd)->a_trsize / obj_reloc_entry_size (abfd)) | |
1841 | +1)); | |
1842 | ||
1843 | bfd_error = invalid_operation; | |
1844 | return 0; | |
1845 | } | |
1846 | ||
1847 | \f | |
1848 | unsigned int | |
1849 | DEFUN(NAME(aout,get_symtab_upper_bound),(abfd), | |
1850 | bfd *abfd) | |
1851 | { | |
1852 | if (!NAME(aout,slurp_symbol_table)(abfd)) return 0; | |
1853 | ||
1854 | return (bfd_get_symcount (abfd)+1) * (sizeof (aout_symbol_type *)); | |
1855 | } | |
1856 | alent * | |
1857 | DEFUN(NAME(aout,get_lineno),(ignore_abfd, ignore_symbol), | |
1858 | bfd *ignore_abfd AND | |
1859 | asymbol *ignore_symbol) | |
1860 | { | |
1861 | return (alent *)NULL; | |
1862 | } | |
1863 | ||
1864 | ||
1865 | void | |
1866 | DEFUN(NAME(aout,print_symbol),(ignore_abfd, afile, symbol, how), | |
1867 | bfd *ignore_abfd AND | |
1868 | PTR afile AND | |
1869 | asymbol *symbol AND | |
9e2dad8e | 1870 | bfd_print_symbol_type how) |
7ed4093a SC |
1871 | { |
1872 | FILE *file = (FILE *)afile; | |
1873 | ||
1874 | switch (how) { | |
9e2dad8e | 1875 | case bfd_print_symbol_name: |
fb3be09b JG |
1876 | if (symbol->name) |
1877 | fprintf(file,"%s", symbol->name); | |
7ed4093a | 1878 | break; |
9e2dad8e | 1879 | case bfd_print_symbol_more: |
7ed4093a SC |
1880 | fprintf(file,"%4x %2x %2x",(unsigned)(aout_symbol(symbol)->desc & 0xffff), |
1881 | (unsigned)(aout_symbol(symbol)->other & 0xff), | |
1882 | (unsigned)(aout_symbol(symbol)->type)); | |
1883 | break; | |
9e2dad8e | 1884 | case bfd_print_symbol_all: |
7ed4093a | 1885 | { |
6db82ea7 SC |
1886 | CONST char *section_name = symbol->section->name; |
1887 | ||
7ed4093a SC |
1888 | |
1889 | bfd_print_symbol_vandf((PTR)file,symbol); | |
1890 | ||
fb3be09b | 1891 | fprintf(file," %-5s %04x %02x %02x", |
7ed4093a SC |
1892 | section_name, |
1893 | (unsigned)(aout_symbol(symbol)->desc & 0xffff), | |
1894 | (unsigned)(aout_symbol(symbol)->other & 0xff), | |
9e2dad8e | 1895 | (unsigned)(aout_symbol(symbol)->type & 0xff)); |
fb3be09b JG |
1896 | if (symbol->name) |
1897 | fprintf(file," %s", symbol->name); | |
7ed4093a SC |
1898 | } |
1899 | break; | |
98d43107 JG |
1900 | case bfd_print_symbol_nm: |
1901 | { | |
1902 | int section_code = bfd_decode_symclass (symbol); | |
1903 | ||
1904 | if (section_code == 'U') | |
1905 | fprintf(file, " "); | |
55c0061e FF |
1906 | else |
1907 | fprintf_vma(file, symbol->value+symbol->section->vma); | |
98d43107 JG |
1908 | if (section_code == '?') |
1909 | { | |
1910 | int type_code = aout_symbol(symbol)->type & 0xff; | |
7de245d3 | 1911 | char *stab_name = aout_stab_name(type_code); |
98d43107 JG |
1912 | char buf[10]; |
1913 | if (stab_name == NULL) | |
1914 | { | |
1915 | sprintf(buf, "(%d)", type_code); | |
1916 | stab_name = buf; | |
1917 | } | |
1918 | fprintf(file," - %02x %04x %5s", | |
1919 | (unsigned)(aout_symbol(symbol)->other & 0xff), | |
1920 | (unsigned)(aout_symbol(symbol)->desc & 0xffff), | |
1921 | stab_name); | |
1922 | } | |
1923 | else | |
1924 | fprintf(file," %c", section_code); | |
1925 | if (symbol->name) | |
1926 | fprintf(file," %s", symbol->name); | |
1927 | } | |
1928 | break; | |
7ed4093a SC |
1929 | } |
1930 | } | |
1931 | ||
1932 | /* | |
6724ff46 | 1933 | provided a BFD, a section and an offset into the section, calculate |
7ed4093a SC |
1934 | and return the name of the source file and the line nearest to the |
1935 | wanted location. | |
1936 | */ | |
1937 | ||
1938 | boolean | |
1939 | DEFUN(NAME(aout,find_nearest_line),(abfd, | |
1940 | section, | |
1941 | symbols, | |
1942 | offset, | |
1943 | filename_ptr, | |
1944 | functionname_ptr, | |
1945 | line_ptr), | |
1946 | bfd *abfd AND | |
1947 | asection *section AND | |
1948 | asymbol **symbols AND | |
1949 | bfd_vma offset AND | |
1950 | CONST char **filename_ptr AND | |
1951 | CONST char **functionname_ptr AND | |
1952 | unsigned int *line_ptr) | |
1953 | { | |
1954 | /* Run down the file looking for the filename, function and linenumber */ | |
1955 | asymbol **p; | |
1956 | static char buffer[100]; | |
98d43107 | 1957 | static char filename_buffer[200]; |
6db82ea7 SC |
1958 | CONST char *directory_name = NULL; |
1959 | CONST char *main_file_name = NULL; | |
1960 | CONST char *current_file_name = NULL; | |
1961 | CONST char *line_file_name = NULL; /* Value of current_file_name at line number. */ | |
7ed4093a SC |
1962 | bfd_vma high_line_vma = ~0; |
1963 | bfd_vma low_func_vma = 0; | |
1964 | asymbol *func = 0; | |
1965 | *filename_ptr = abfd->filename; | |
1966 | *functionname_ptr = 0; | |
1967 | *line_ptr = 0; | |
1968 | if (symbols != (asymbol **)NULL) { | |
1969 | for (p = symbols; *p; p++) { | |
1970 | aout_symbol_type *q = (aout_symbol_type *)(*p); | |
98d43107 | 1971 | next: |
7ed4093a SC |
1972 | switch (q->type){ |
1973 | case N_SO: | |
3f7607af | 1974 | main_file_name = current_file_name = q->symbol.name; |
98d43107 JG |
1975 | /* Look ahead to next symbol to check if that too is an N_SO. */ |
1976 | p++; | |
1977 | if (*p == NULL) | |
1978 | break; | |
1979 | q = (aout_symbol_type *)(*p); | |
6db82ea7 | 1980 | if (q->type != (int)N_SO) |
98d43107 JG |
1981 | goto next; |
1982 | ||
1983 | /* Found a second N_SO First is directory; second is filename. */ | |
3f7607af PB |
1984 | directory_name = current_file_name; |
1985 | main_file_name = current_file_name = q->symbol.name; | |
1986 | if (obj_textsec(abfd) != section) | |
1987 | goto done; | |
1988 | break; | |
1989 | case N_SOL: | |
1990 | current_file_name = q->symbol.name; | |
7ed4093a | 1991 | break; |
3f7607af | 1992 | |
7ed4093a SC |
1993 | case N_SLINE: |
1994 | ||
1995 | case N_DSLINE: | |
1996 | case N_BSLINE: | |
1997 | /* We'll keep this if it resolves nearer than the one we have already */ | |
1998 | if (q->symbol.value >= offset && | |
1999 | q->symbol.value < high_line_vma) { | |
2000 | *line_ptr = q->desc; | |
2001 | high_line_vma = q->symbol.value; | |
3f7607af | 2002 | line_file_name = current_file_name; |
7ed4093a SC |
2003 | } |
2004 | break; | |
2005 | case N_FUN: | |
2006 | { | |
2007 | /* We'll keep this if it is nearer than the one we have already */ | |
2008 | if (q->symbol.value >= low_func_vma && | |
2009 | q->symbol.value <= offset) { | |
2010 | low_func_vma = q->symbol.value; | |
2011 | func = (asymbol *)q; | |
2012 | } | |
2013 | if (*line_ptr && func) { | |
2014 | CONST char *function = func->name; | |
2015 | char *p; | |
2016 | strncpy(buffer, function, sizeof(buffer)-1); | |
2017 | buffer[sizeof(buffer)-1] = 0; | |
2018 | /* Have to remove : stuff */ | |
2019 | p = strchr(buffer,':'); | |
7b02b4ed | 2020 | if (p != NULL) { *p = '\0'; } |
7ed4093a | 2021 | *functionname_ptr = buffer; |
3f7607af | 2022 | goto done; |
7ed4093a SC |
2023 | |
2024 | } | |
2025 | } | |
2026 | break; | |
2027 | } | |
2028 | } | |
2029 | } | |
3f7607af PB |
2030 | |
2031 | done: | |
2032 | if (*line_ptr) | |
2033 | main_file_name = line_file_name; | |
2034 | if (main_file_name) { | |
2035 | if (main_file_name[0] == '/' || directory_name == NULL) | |
2036 | *filename_ptr = main_file_name; | |
2037 | else { | |
2038 | sprintf(filename_buffer, "%.140s%.50s", | |
2039 | directory_name, main_file_name); | |
2040 | *filename_ptr = filename_buffer; | |
2041 | } | |
2042 | } | |
7ed4093a SC |
2043 | return true; |
2044 | ||
2045 | } | |
2046 | ||
2047 | int | |
cbdc7909 JG |
2048 | DEFUN(NAME(aout,sizeof_headers),(abfd, execable), |
2049 | bfd *abfd AND | |
9e2dad8e | 2050 | boolean execable) |
7ed4093a | 2051 | { |
6db82ea7 | 2052 | return adata(abfd).exec_bytes_size; |
7ed4093a | 2053 | } |