1 /* BFD semi-generic back-end for a.out binaries
2 Copyright (C) 1990-1991 Free Software Foundation, Inc.
3 Written by Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
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 2 of the License, or
10 (at your option) any later version.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
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
33 The support is split into a basic support file @code{aoutx.h}
34 and other files which derive functions from the base. One
35 derivation file is @code{aoutf1.h} (for a.out flavour 1), and
36 adds to the basic a.out functions support for sun3, sun4, 386
37 and 29k a.out files, to create a target jump vector for a
40 This information is further split out into more specific files
41 for each machine, including @code{sunos.c} for sun3 and sun4,
42 @code{newsos3.c} for the Sony NEWS, and @code{demo64.c} for a
43 demonstration of a 64 bit a.out format.
45 The base file @code{aoutx.h} defines general mechanisms for
46 reading and writing records to and from disk, and various
47 other methods which BFD requires. It is included by
48 @code{aout32.c} and @code{aout64.c} to form the names
49 aout_32_swap_exec_header_in, aout_64_swap_exec_header_in, etc.
51 As an example, this is what goes on to make the back end for a
65 aout_32_canonicalize_reloc
66 aout_32_find_nearest_line
68 aout_32_get_reloc_upper_bound
77 #define TARGET_NAME "a.out-sunos-big"
78 #define VECNAME sunos_big_vec
82 requires all the names from aout32.c, and produces the jump vector
89 The file host-aout.c is a special case. It is for a large set
90 of hosts that use ``more or less standard'' a.out files, and
91 for which cross-debugging is not interesting. It uses the
92 standard 32-bit a.out support routines, but determines the
93 file offsets and addresses of the text, data, and BSS
94 sections, the machine architecture and machine type, and the
95 entry point address, in a host-dependent manner. Once these
96 values have been determined, generic code is used to handle
99 When porting it to run on a new system, you must supply:
104 HOST_MACHINE_ARCH (optional)
105 HOST_MACHINE_MACHINE (optional)
111 in the file ../include/sys/h-XXX.h (for your host). These
112 values, plus the structures and macros defined in <a.out.h> on
113 your host system, will produce a BFD target that will access
114 ordinary a.out files on your host. To configure a new machine
115 to use host-aout.c, specify:
118 TDEFAULTS = -DDEFAULT_VECTOR=host_aout_big_vec
119 TDEPFILES= host-aout.o trad-core.o
122 in the config/mt-XXX file, and modify configure.in to use the
123 mt-XXX file (by setting "bfd_target=XXX") when your
124 configuration is selected.
129 #define KEEPITTYPE int
133 #include <ansidecl.h>
135 struct external_exec;
138 #include "aout/aout64.h"
139 #include "aout/stab_gnu.h"
142 void (*bfd_error_trap)();
149 The file @code{aoutx.h} caters for both the @emph{standard}
150 and @emph{extended} forms of a.out relocation records.
152 The standard records are characterised by containing only an
153 address, a symbol index and a type field. The extended records
154 (used on 29ks and sparcs) also have a full integer for an
158 #define CTOR_TABLE_RELOC_IDX 2
161 static reloc_howto_type howto_table_ext[] =
163 HOWTO(RELOC_8, 0, 0, 8, false, 0, true, true,0,"8", false, 0,0x000000ff, false),
164 HOWTO(RELOC_16, 0, 1, 16, false, 0, true, true,0,"16", false, 0,0x0000ffff, false),
165 HOWTO(RELOC_32, 0, 2, 32, false, 0, true, true,0,"32", false, 0,0xffffffff, false),
166 HOWTO(RELOC_DISP8, 0, 0, 8, true, 0, false, true,0,"DISP8", false, 0,0x000000ff, false),
167 HOWTO(RELOC_DISP16, 0, 1, 16, true, 0, false, true,0,"DISP16", false, 0,0x0000ffff, false),
168 HOWTO(RELOC_DISP32, 0, 2, 32, true, 0, false, true,0,"DISP32", false, 0,0xffffffff, false),
169 HOWTO(RELOC_WDISP30,2, 2, 30, true, 0, false, true,0,"WDISP30", false, 0,0x3fffffff, false),
170 HOWTO(RELOC_WDISP22,2, 2, 22, true, 0, false, true,0,"WDISP22", false, 0,0x003fffff, false),
171 HOWTO(RELOC_HI22, 10, 2, 22, false, 0, false, true,0,"HI22", false, 0,0x003fffff, false),
172 HOWTO(RELOC_22, 0, 2, 22, false, 0, false, true,0,"22", false, 0,0x003fffff, false),
173 HOWTO(RELOC_13, 0, 2, 13, false, 0, false, true,0,"13", false, 0,0x00001fff, false),
174 HOWTO(RELOC_LO10, 0, 2, 10, false, 0, false, true,0,"LO10", false, 0,0x000003ff, false),
175 HOWTO(RELOC_SFA_BASE,0, 2, 32, false, 0, false, true,0,"SFA_BASE", false, 0,0xffffffff, false),
176 HOWTO(RELOC_SFA_OFF13,0,2, 32, false, 0, false, true,0,"SFA_OFF13",false, 0,0xffffffff, false),
177 HOWTO(RELOC_BASE10, 0, 2, 16, false, 0, false, true,0,"BASE10", false, 0,0x0000ffff, false),
178 HOWTO(RELOC_BASE13, 0, 2, 13, false, 0, false, true,0,"BASE13", false, 0,0x00001fff, false),
179 HOWTO(RELOC_BASE22, 0, 2, 0, false, 0, false, true,0,"BASE22", false, 0,0x00000000, false),
180 HOWTO(RELOC_PC10, 0, 2, 10, false, 0, false, true,0,"PC10", false, 0,0x000003ff, false),
181 HOWTO(RELOC_PC22, 0, 2, 22, false, 0, false, true,0,"PC22", false, 0,0x003fffff, false),
182 HOWTO(RELOC_JMP_TBL,0, 2, 32, false, 0, false, true,0,"JMP_TBL", false, 0,0xffffffff, false),
183 HOWTO(RELOC_SEGOFF16,0, 2, 0, false, 0, false, true,0,"SEGOFF16", false, 0,0x00000000, false),
184 HOWTO(RELOC_GLOB_DAT,0, 2, 0, false, 0, false, true,0,"GLOB_DAT", false, 0,0x00000000, false),
185 HOWTO(RELOC_JMP_SLOT,0, 2, 0, false, 0, false, true,0,"JMP_SLOT", false, 0,0x00000000, false),
186 HOWTO(RELOC_RELATIVE,0, 2, 0, false, 0, false, true,0,"RELATIVE", false, 0,0x00000000, false),
190 /* Convert standard reloc records to "arelent" format (incl byte swap). */
192 static reloc_howto_type howto_table_std[] = {
193 /* type rs size bsz pcrel bitpos abs ovrf sf name part_inpl readmask setmask pcdone */
194 HOWTO( 0, 0, 0, 8, false, 0, true, true,0,"8", true, 0x000000ff,0x000000ff, false),
195 HOWTO( 1, 0, 1, 16, false, 0, true, true,0,"16", true, 0x0000ffff,0x0000ffff, false),
196 HOWTO( 2, 0, 2, 32, false, 0, true, true,0,"32", true, 0xffffffff,0xffffffff, false),
197 HOWTO( 3, 0, 3, 64, false, 0, true, true,0,"64", true, 0xdeaddead,0xdeaddead, false),
198 HOWTO( 4, 0, 0, 8, true, 0, false, true,0,"DISP8", true, 0x000000ff,0x000000ff, false),
199 HOWTO( 5, 0, 1, 16, true, 0, false, true,0,"DISP16", true, 0x0000ffff,0x0000ffff, false),
200 HOWTO( 6, 0, 2, 32, true, 0, false, true,0,"DISP32", true, 0xffffffff,0xffffffff, false),
201 HOWTO( 7, 0, 3, 64, true, 0, false, true,0,"DISP64", true, 0xfeedface,0xfeedface, false),
205 bfd_error_vector_type bfd_error_vector;
209 Internal Entry Points
212 @code{aoutx.h} exports several routines for accessing the
213 contents of an a.out file, which are gathered and exported in
214 turn by various format specific files (eg sunos.c).
220 aout_<size>_swap_exec_header_in
223 Swaps the information in an executable header taken from a raw
224 byte stream memory image, into the internal exec_header
228 void aout_<size>_swap_exec_header_in,
230 struct external_exec *raw_bytes,
231 struct internal_exec *execp);
235 DEFUN(NAME(aout,swap_exec_header_in),(abfd, raw_bytes, execp),
237 struct external_exec *raw_bytes AND
238 struct internal_exec *execp)
240 struct external_exec *bytes = (struct external_exec *)raw_bytes;
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);
255 aout_<size>_swap_exec_header_out
258 Swaps the information in an internal exec header structure
259 into the supplied buffer ready for writing to disk.
262 void aout_<size>_swap_exec_header_out
264 struct internal_exec *execp,
265 struct external_exec *raw_bytes);
268 DEFUN(NAME(aout,swap_exec_header_out),(abfd, execp, raw_bytes),
270 struct internal_exec *execp AND
271 struct external_exec *raw_bytes)
273 struct external_exec *bytes = (struct external_exec *)raw_bytes;
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);
288 struct internal_exec e;
294 aout_<size>_some_aout_object_p
297 Some A.OUT variant thinks that the file whose format we're
298 checking is an a.out file. Do some more checking, and set up
299 for access if it really is. Call back to the calling
300 environments "finish up" function just before returning, to
301 handle any last-minute setup.
304 bfd_target *aout_<size>_some_aout_object_p
306 bfd_target *(*callback_to_real_object_p)());
310 DEFUN(NAME(aout,some_aout_object_p),(abfd, execp, callback_to_real_object_p),
312 struct internal_exec *execp AND
313 bfd_target *(*callback_to_real_object_p) ())
315 struct container *rawptr;
318 rawptr = (struct container *) bfd_zalloc (abfd, sizeof (struct container));
319 if (rawptr == NULL) {
320 bfd_error = no_memory;
324 set_tdata (abfd, &rawptr->a);
325 exec_hdr (abfd) = &rawptr->e;
326 *exec_hdr (abfd) = *execp; /* Copy in the internal_exec struct */
327 execp = exec_hdr (abfd); /* Switch to using the newly malloc'd one */
329 /* Set the file flags */
330 abfd->flags = NO_FLAGS;
331 if (execp->a_drsize || execp->a_trsize)
332 abfd->flags |= HAS_RELOC;
333 /* Setting of EXEC_P has been deferred to the bottom of this function */
335 abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS;
337 if (N_MAGIC (*execp) == ZMAGIC) abfd->flags |= D_PAGED;
338 if (N_MAGIC (*execp) == NMAGIC) abfd->flags |= WP_TEXT;
340 bfd_get_start_address (abfd) = execp->a_entry;
342 obj_aout_symbols (abfd) = (aout_symbol_type *)NULL;
343 bfd_get_symcount (abfd) = execp->a_syms / sizeof (struct external_nlist);
345 /* Set the default architecture and machine type. These can be
346 overridden in the callback routine. */
348 bfd_default_set_arch_mach(abfd, bfd_arch_unknown, 0);
350 /* The default relocation entry size is that of traditional V7 Unix. */
351 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
353 /* The default symbol entry size is that of traditional Unix. */
354 obj_symbol_entry_size (abfd) = EXTERNAL_NLIST_SIZE;
356 /* create the sections. This is raunchy, but bfd_close wants to reclaim
358 obj_textsec (abfd) = (asection *)NULL;
359 obj_datasec (abfd) = (asection *)NULL;
360 obj_bsssec (abfd) = (asection *)NULL;
361 (void)bfd_make_section(abfd, ".text");
362 (void)bfd_make_section(abfd, ".data");
363 (void)bfd_make_section(abfd, ".bss");
365 abfd->sections = obj_textsec (abfd);
366 obj_textsec (abfd)->next = obj_datasec (abfd);
367 obj_datasec (abfd)->next = obj_bsssec (abfd);
369 obj_datasec (abfd)->size = execp->a_data;
370 obj_bsssec (abfd)->size = execp->a_bss;
372 obj_textsec (abfd)->flags = (execp->a_trsize != 0 ?
373 (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_HAS_CONTENTS) :
374 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS));
375 obj_datasec (abfd)->flags = (execp->a_drsize != 0 ?
376 (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_HAS_CONTENTS) :
377 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS));
378 obj_bsssec (abfd)->flags = SEC_ALLOC;
380 #ifdef THIS_IS_ONLY_DOCUMENTATION
381 /* The common code can't fill in these things because they depend
382 on either the start address of the text segment, the rounding
383 up of virtual addersses between segments, or the starting file
384 position of the text segment -- all of which varies among different
385 versions of a.out. */
387 /* Call back to the format-dependent code to fill in the rest of the
388 fields and do any further cleanup. Things that should be filled
389 in by the callback: */
391 struct exec *execp = exec_hdr (abfd);
393 obj_textsec (abfd)->size = N_TXTSIZE(*execp);
394 /* data and bss are already filled in since they're so standard */
396 /* The virtual memory addresses of the sections */
397 obj_textsec (abfd)->vma = N_TXTADDR(*execp);
398 obj_datasec (abfd)->vma = N_DATADDR(*execp);
399 obj_bsssec (abfd)->vma = N_BSSADDR(*execp);
401 /* The file offsets of the sections */
402 obj_textsec (abfd)->filepos = N_TXTOFF(*execp);
403 obj_datasec (abfd)->filepos = N_DATOFF(*execp);
405 /* The file offsets of the relocation info */
406 obj_textsec (abfd)->rel_filepos = N_TRELOFF(*execp);
407 obj_datasec (abfd)->rel_filepos = N_DRELOFF(*execp);
409 /* The file offsets of the string table and symbol table. */
410 obj_str_filepos (abfd) = N_STROFF (*execp);
411 obj_sym_filepos (abfd) = N_SYMOFF (*execp);
413 /* Determine the architecture and machine type of the object file. */
414 switch (N_MACHTYPE (*exec_hdr (abfd))) {
416 abfd->obj_arch = bfd_arch_obscure;
420 /* Determine the size of a relocation entry */
421 switch (abfd->obj_arch) {
424 obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;
426 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
429 adata(abfd)->page_size = PAGE_SIZE;
430 adata(abfd)->segment_size = SEGMENT_SIZE;
431 adata(abfd)->exec_bytes_size = EXEC_BYTES_SIZE;
435 /* The architecture is encoded in various ways in various a.out variants,
436 or is not encoded at all in some of them. The relocation size depends
437 on the architecture and the a.out variant. Finally, the return value
438 is the bfd_target vector in use. If an error occurs, return zero and
439 set bfd_error to the appropriate error code.
441 Formats such as b.out, which have additional fields in the a.out
442 header, should cope with them in this callback as well. */
443 #endif /* DOCUMENTATION */
445 result = (*callback_to_real_object_p)(abfd);
447 /* Now that the segment addresses have been worked out, take a better
448 guess at whether the file is executable. If the entry point
449 is within the text segment, assume it is. (This makes files
450 executable even if their entry point address is 0, as long as
451 their text starts at zero.)
453 At some point we should probably break down and stat the file and
454 declare it executable if (one of) its 'x' bits are on... */
455 if ((execp->a_entry >= obj_textsec(abfd)->vma) &&
456 (execp->a_entry < obj_textsec(abfd)->vma + obj_textsec(abfd)->size))
457 abfd->flags |= EXEC_P;
466 This routine initializes a BFD for use with a.out files.
469 boolean aout_<size>_mkobject, (bfd *);
473 DEFUN(NAME(aout,mkobject),(abfd),
476 struct container *rawptr;
478 bfd_error = system_call_error;
480 /* Use an intermediate variable for clarity */
481 rawptr = (struct container *)bfd_zalloc (abfd, sizeof (struct container));
483 if (rawptr == NULL) {
484 bfd_error = no_memory;
488 set_tdata (abfd, rawptr);
489 exec_hdr (abfd) = &(rawptr->e);
491 /* For simplicity's sake we just make all the sections right here. */
493 obj_textsec (abfd) = (asection *)NULL;
494 obj_datasec (abfd) = (asection *)NULL;
495 obj_bsssec (abfd) = (asection *)NULL;
496 bfd_make_section (abfd, ".text");
497 bfd_make_section (abfd, ".data");
498 bfd_make_section (abfd, ".bss");
506 aout_<size>_machine_type
509 Keep track of machine architecture and machine type for
510 a.out's. Return the machine_type for a particular
511 arch&machine, or M_UNKNOWN if that exact arch&machine can't be
512 represented in a.out format.
514 If the architecture is understood, machine type 0 (default)
515 should always be understood.
518 enum machine_type aout_<size>_machine_type
519 (enum bfd_architecture arch,
520 unsigned long machine));
524 DEFUN(NAME(aout,machine_type),(arch, machine),
525 enum bfd_architecture arch AND
526 unsigned long machine)
528 enum machine_type arch_flags;
530 arch_flags = M_UNKNOWN;
534 if (machine == 0) arch_flags = M_SPARC;
539 case 0: arch_flags = M_68010; break;
540 case 68000: arch_flags = M_UNKNOWN; break;
541 case 68010: arch_flags = M_68010; break;
542 case 68020: arch_flags = M_68020; break;
543 default: arch_flags = M_UNKNOWN; break;
548 if (machine == 0) arch_flags = M_386;
552 if (machine == 0) arch_flags = M_29K;
556 arch_flags = M_UNKNOWN;
565 aout_<size>_set_arch_mach
568 Sets the architecture and the machine of the BFD to those
569 values supplied. Verifies that the format can support the
570 architecture required.
573 boolean aout_<size>_set_arch_mach,
575 enum bfd_architecture,
576 unsigned long machine));
580 DEFUN(NAME(aout,set_arch_mach),(abfd, arch, machine),
582 enum bfd_architecture arch AND
583 unsigned long machine)
585 bfd_default_set_arch_mach(abfd, arch, machine);
586 if (arch != bfd_arch_unknown &&
587 NAME(aout,machine_type) (arch, machine) == M_UNKNOWN)
588 return false; /* We can't represent this type */
589 return true; /* We're easy ... */
594 aout_<size>new_section_hook
597 Called by the BFD in response to a @code{bfd_make_section}
601 boolean aout_<size>_new_section_hook,
606 DEFUN(NAME(aout,new_section_hook),(abfd, newsect),
610 /* align to double at least */
611 newsect->alignment_power = 3;
613 if (bfd_get_format (abfd) == bfd_object) {
614 if (obj_textsec(abfd) == NULL && !strcmp(newsect->name, ".text")) {
615 obj_textsec(abfd)= newsect;
619 if (obj_datasec(abfd) == NULL && !strcmp(newsect->name, ".data")) {
620 obj_datasec(abfd) = newsect;
624 if (obj_bsssec(abfd) == NULL && !strcmp(newsect->name, ".bss")) {
625 obj_bsssec(abfd) = newsect;
630 /* We allow more than three sections internally */
635 DEFUN(NAME(aout,set_section_contents),(abfd, section, location, offset, count),
643 bfd_size_type text_header_size; /* exec_bytes_size if if included in
645 bfd_size_type text_size;
646 if (abfd->output_has_begun == false)
647 { /* set by bfd.c handler */
648 switch (abfd->direction)
652 bfd_error = invalid_operation;
658 case write_direction:
659 if ((obj_textsec (abfd) == NULL) || (obj_datasec (abfd) == NULL))
661 bfd_error = invalid_operation;
664 obj_textsec(abfd)->size =
665 align_power(obj_textsec(abfd)->size,
666 obj_textsec(abfd)->alignment_power);
667 text_size = obj_textsec (abfd)->size;
668 /* Rule (heuristic) for when to pad to a new page.
669 * Note that there are (at least) two ways demand-paged
670 * (ZMAGIC) files have been handled. Most Berkeley-based systems
671 * start the text segment at (PAGE_SIZE). However, newer
672 * versions of SUNOS start the text segment right after the
673 * exec header; the latter is counted in the text segment size,
674 * and is paged in by the kernel with the rest of the text. */
675 if (!(abfd->flags & D_PAGED))
676 { /* Not demand-paged. */
677 obj_textsec(abfd)->filepos = adata(abfd)->exec_bytes_size;
679 else if (obj_textsec(abfd)->vma % adata(abfd)->page_size
680 < adata(abfd)->exec_bytes_size)
681 { /* Old-style demand-paged. */
682 obj_textsec(abfd)->filepos = adata(abfd)->page_size;
685 { /* Sunos-style demand-paged. */
686 obj_textsec(abfd)->filepos = adata(abfd)->exec_bytes_size;
687 text_size += adata(abfd)->exec_bytes_size;
689 text_end = obj_textsec(abfd)->size + obj_textsec(abfd)->filepos;
690 if (abfd->flags & (D_PAGED|WP_TEXT))
692 bfd_size_type text_pad =
693 BFD_ALIGN(text_size, adata(abfd)->segment_size)
695 text_end += text_pad;
696 obj_textsec(abfd)->size += text_pad;
698 obj_datasec(abfd)->filepos = text_end;
699 obj_datasec(abfd)->size =
700 align_power(obj_datasec(abfd)->size,
701 obj_datasec(abfd)->alignment_power);
705 /* regardless, once we know what we're doing, we might as well get going */
706 if (section != obj_bsssec(abfd))
708 bfd_seek (abfd, section->filepos + offset, SEEK_SET);
711 return (bfd_write ((PTR)location, 1, count, abfd) == count) ?
719 /* Classify stabs symbols */
721 #define sym_in_text_section(sym) \
722 (((sym)->type & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_TEXT)
724 #define sym_in_data_section(sym) \
725 (((sym)->type & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_DATA)
727 #define sym_in_bss_section(sym) \
728 (((sym)->type & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_BSS)
730 /* Symbol is undefined if type is N_UNDF|N_EXT and if it has
731 zero in the "value" field. Nonzeroes there are fortrancommon
733 #define sym_is_undefined(sym) \
734 ((sym)->type == (N_UNDF | N_EXT) && (sym)->symbol.value == 0)
736 /* Symbol is a global definition if N_EXT is on and if it has
737 a nonzero type field. */
738 #define sym_is_global_defn(sym) \
739 (((sym)->type & N_EXT) && (sym)->type & N_TYPE)
741 /* Symbol is debugger info if any bits outside N_TYPE or N_EXT
743 #define sym_is_debugger_info(sym) \
744 ((sym)->type & ~(N_EXT | N_TYPE))
746 #define sym_is_fortrancommon(sym) \
747 (((sym)->type == (N_EXT)) && (sym)->symbol.value != 0)
749 /* Symbol is absolute if it has N_ABS set */
750 #define sym_is_absolute(sym) \
751 (((sym)->type & N_TYPE)== N_ABS)
754 #define sym_is_indirect(sym) \
755 (((sym)->type & N_ABS)== N_ABS)
757 /* Only in their own functions for ease of debugging; when sym flags have
758 stabilised these should be inlined into their (single) caller */
761 DEFUN(translate_from_native_sym_flags,(sym_pointer, cache_ptr, abfd),
762 struct external_nlist *sym_pointer AND
763 aout_symbol_type *cache_ptr AND
766 switch (cache_ptr->type & N_TYPE) {
772 char *copy = bfd_alloc(abfd, strlen(cache_ptr->symbol.name)+1);
774 arelent_chain *reloc = (arelent_chain *)bfd_alloc(abfd, sizeof(arelent_chain));
775 strcpy(copy, cache_ptr->symbol.name);
776 section = bfd_get_section_by_name (abfd, copy);
778 section = bfd_make_section(abfd,copy);
780 switch ( (cache_ptr->type & N_TYPE) ) {
782 section->flags = SEC_CONSTRUCTOR;
783 reloc->relent.section = (asection *)NULL;
784 cache_ptr->symbol.section = (asection *)NULL;
787 section->flags = SEC_CONSTRUCTOR_TEXT;
788 reloc->relent.section = (asection *)obj_textsec(abfd);
789 cache_ptr->symbol.value -= reloc->relent.section->vma;
792 section->flags = SEC_CONSTRUCTOR_DATA;
793 reloc->relent.section = (asection *)obj_datasec(abfd);
794 cache_ptr->symbol.value -= reloc->relent.section->vma;
797 section->flags = SEC_CONSTRUCTOR_BSS;
798 reloc->relent.section = (asection *)obj_bsssec(abfd);
799 cache_ptr->symbol.value -= reloc->relent.section->vma;
802 cache_ptr->symbol.section = reloc->relent.section;
803 reloc->relent.addend = cache_ptr->symbol.value ;
805 /* We modify the symbol to belong to a section depending upon the
806 name of the symbol - probably __CTOR__ or __DTOR__ but we don't
807 really care, and add to the size of the section to contain a
808 pointer to the symbol. Build a reloc entry to relocate to this
809 symbol attached to this section. */
812 section->reloc_count++;
813 section->alignment_power = 2;
814 reloc->relent.sym_ptr_ptr = (asymbol **)NULL;
815 reloc->next = section->constructor_chain;
816 section->constructor_chain = reloc;
817 reloc->relent.address = section->size;
818 section->size += sizeof(int *);
820 reloc->relent.howto = howto_table_ext +CTOR_TABLE_RELOC_IDX;
821 cache_ptr->symbol.flags |= BSF_DEBUGGING | BSF_CONSTRUCTOR;
825 if (cache_ptr->type == N_WARNING)
827 /* This symbol is the text of a warning message, the next symbol
828 is the symbol to associate the warning with */
829 cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_WARNING;
830 cache_ptr->symbol.value = (bfd_vma)((cache_ptr+1));
831 /* We furgle with the next symbol in place. We don't want it to be undefined, we'll trample the type */
832 (sym_pointer+1)->e_type[0] = 0xff;
835 if ((cache_ptr->type | N_EXT) == (N_INDR | N_EXT)) {
836 /* Two symbols in a row for an INDR message. The first symbol
837 contains the name we will match, the second symbol contains the
838 name the first name is translated into. It is supplied to us
839 undefined. This is good, since we want to pull in any files which
841 cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_INDIRECT;
842 cache_ptr->symbol.value = (bfd_vma)((cache_ptr+1));
847 if (sym_is_debugger_info (cache_ptr)) {
848 cache_ptr->symbol.flags = BSF_DEBUGGING ;
849 /* Work out the section correct for this symbol */
850 switch (cache_ptr->type & N_TYPE)
854 cache_ptr->symbol.section = obj_textsec (abfd);
855 cache_ptr->symbol.value -= obj_textsec(abfd)->vma;
858 cache_ptr->symbol.value -= obj_datasec(abfd)->vma;
859 cache_ptr->symbol.section = obj_datasec (abfd);
862 cache_ptr->symbol.section = obj_bsssec (abfd);
863 cache_ptr->symbol.value -= obj_bsssec(abfd)->vma;
867 cache_ptr->symbol.section = 0;
873 if (sym_is_fortrancommon (cache_ptr))
875 cache_ptr->symbol.flags = BSF_FORT_COMM;
876 cache_ptr->symbol.section = (asection *)NULL;
879 if (sym_is_undefined (cache_ptr)) {
880 cache_ptr->symbol.flags = BSF_UNDEFINED;
882 else if (sym_is_global_defn (cache_ptr)) {
883 cache_ptr->symbol.flags = BSF_GLOBAL | BSF_EXPORT;
886 else if (sym_is_absolute (cache_ptr)) {
887 cache_ptr->symbol.flags = BSF_ABSOLUTE;
890 cache_ptr->symbol.flags = BSF_LOCAL;
893 /* In a.out, the value of a symbol is always relative to the
894 * start of the file, if this is a data symbol we'll subtract
895 * the size of the text section to get the section relative
896 * value. If this is a bss symbol (which would be strange)
897 * we'll subtract the size of the previous two sections
898 * to find the section relative address.
901 if (sym_in_text_section (cache_ptr)) {
902 cache_ptr->symbol.value -= obj_textsec(abfd)->vma;
903 cache_ptr->symbol.section = obj_textsec (abfd);
905 else if (sym_in_data_section (cache_ptr)){
906 cache_ptr->symbol.value -= obj_datasec(abfd)->vma;
907 cache_ptr->symbol.section = obj_datasec (abfd);
909 else if (sym_in_bss_section(cache_ptr)) {
910 cache_ptr->symbol.section = obj_bsssec (abfd);
911 cache_ptr->symbol.value -= obj_bsssec(abfd)->vma;
914 cache_ptr->symbol.section = (asection *)NULL;
915 cache_ptr->symbol.flags |= BSF_ABSOLUTE;
923 DEFUN(translate_to_native_sym_flags,(sym_pointer, cache_ptr, abfd),
924 struct external_nlist *sym_pointer AND
925 asymbol *cache_ptr AND
928 bfd_vma value = cache_ptr->value;
930 if (bfd_get_section(cache_ptr)) {
931 if (bfd_get_output_section(cache_ptr) == obj_bsssec (abfd)) {
932 sym_pointer->e_type[0] |= N_BSS;
934 else if (bfd_get_output_section(cache_ptr) == obj_datasec (abfd)) {
935 sym_pointer->e_type[0] |= N_DATA;
937 else if (bfd_get_output_section(cache_ptr) == obj_textsec (abfd)) {
938 sym_pointer->e_type[0] |= N_TEXT;
941 bfd_error_vector.nonrepresentable_section(abfd,
942 bfd_get_output_section(cache_ptr)->name);
944 /* Turn the symbol from section relative to absolute again */
947 cache_ptr->section->output_section->vma
948 + cache_ptr->section->output_offset ;
951 sym_pointer->e_type[0] |= N_ABS;
953 if (cache_ptr->flags & (BSF_WARNING)) {
954 (sym_pointer+1)->e_type[0] = 1;
956 if (cache_ptr->flags & (BSF_FORT_COMM | BSF_UNDEFINED)) {
957 sym_pointer->e_type[0] = (N_UNDF | N_EXT);
960 if (cache_ptr->flags & BSF_ABSOLUTE) {
961 sym_pointer->e_type[0] |= N_ABS;
964 if (cache_ptr->flags & (BSF_GLOBAL | BSF_EXPORT)) {
965 sym_pointer->e_type[0] |= N_EXT;
967 if (cache_ptr->flags & BSF_DEBUGGING) {
968 sym_pointer->e_type [0]= ((aout_symbol_type *)cache_ptr)->type;
971 PUT_WORD(abfd, value, sym_pointer->e_value);
974 /* Native-level interface to symbols. */
976 /* We read the symbols into a buffer, which is discarded when this
977 function exits. We read the strings into a buffer large enough to
978 hold them all plus all the cached symbol entries. */
981 DEFUN(NAME(aout,make_empty_symbol),(abfd),
984 aout_symbol_type *new =
985 (aout_symbol_type *)bfd_zalloc (abfd, sizeof (aout_symbol_type));
986 new->symbol.the_bfd = abfd;
992 DEFUN(NAME(aout,slurp_symbol_table),(abfd),
995 bfd_size_type symbol_size;
996 bfd_size_type string_size;
997 unsigned char string_chars[BYTES_IN_WORD];
998 struct external_nlist *syms;
1000 aout_symbol_type *cached;
1002 /* If there's no work to be done, don't do any */
1003 if (obj_aout_symbols (abfd) != (aout_symbol_type *)NULL) return true;
1004 symbol_size = exec_hdr(abfd)->a_syms;
1005 if (symbol_size == 0) {
1006 bfd_error = no_symbols;
1010 bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET);
1011 if (bfd_read ((PTR)string_chars, BYTES_IN_WORD, 1, abfd) != BYTES_IN_WORD)
1013 string_size = GET_WORD (abfd, string_chars);
1015 strings =(char *) bfd_alloc(abfd, string_size + 1);
1016 cached = (aout_symbol_type *)
1017 bfd_zalloc(abfd, (bfd_size_type)(bfd_get_symcount (abfd) * sizeof(aout_symbol_type)));
1019 /* malloc this, so we can free it if simply. The symbol caching
1020 might want to allocate onto the bfd's obstack */
1021 syms = (struct external_nlist *) bfd_xmalloc(symbol_size);
1022 bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET);
1023 if (bfd_read ((PTR)syms, 1, symbol_size, abfd) != symbol_size) {
1025 if (syms) free (syms);
1026 if (cached) bfd_release (abfd, cached);
1027 if (strings)bfd_release (abfd, strings);
1031 bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET);
1032 if (bfd_read ((PTR)strings, 1, string_size, abfd) != string_size) {
1036 /* OK, now walk the new symtable, cacheing symbol properties */
1038 register struct external_nlist *sym_pointer;
1039 register struct external_nlist *sym_end = syms + bfd_get_symcount (abfd);
1040 register aout_symbol_type *cache_ptr = cached;
1042 /* Run through table and copy values */
1043 for (sym_pointer = syms, cache_ptr = cached;
1044 sym_pointer < sym_end; sym_pointer++, cache_ptr++)
1046 bfd_vma x = GET_WORD(abfd, sym_pointer->e_strx);
1047 cache_ptr->symbol.the_bfd = abfd;
1049 cache_ptr->symbol.name = x + strings;
1051 cache_ptr->symbol.name = (char *)NULL;
1053 cache_ptr->symbol.value = GET_SWORD(abfd, sym_pointer->e_value);
1054 cache_ptr->desc = bfd_get_16(abfd, sym_pointer->e_desc);
1055 cache_ptr->other =bfd_get_8(abfd, sym_pointer->e_other);
1056 cache_ptr->type = bfd_get_8(abfd, sym_pointer->e_type);
1057 cache_ptr->symbol.udata = 0;
1058 translate_from_native_sym_flags (sym_pointer, cache_ptr, abfd);
1062 obj_aout_symbols (abfd) = cached;
1070 DEFUN(NAME(aout,write_syms),(abfd),
1073 unsigned int count ;
1074 asymbol **generic = bfd_get_outsymbols (abfd);
1076 bfd_size_type stindex = BYTES_IN_WORD; /* initial string length */
1078 for (count = 0; count < bfd_get_symcount (abfd); count++) {
1079 asymbol *g = generic[count];
1080 struct external_nlist nsp;
1083 unsigned int length = strlen(g->name) +1;
1084 PUT_WORD (abfd, stindex, (unsigned char *)nsp.e_strx);
1088 PUT_WORD (abfd, 0, (unsigned char *)nsp.e_strx);
1091 if (g->the_bfd->xvec->flavour == abfd->xvec->flavour)
1093 bfd_h_put_16(abfd, aout_symbol(g)->desc, nsp.e_desc);
1094 bfd_h_put_8(abfd, aout_symbol(g)->other, nsp.e_other);
1095 bfd_h_put_8(abfd, aout_symbol(g)->type, nsp.e_type);
1099 bfd_h_put_16(abfd,0, nsp.e_desc);
1100 bfd_h_put_8(abfd, 0, nsp.e_other);
1101 bfd_h_put_8(abfd, 0, nsp.e_type);
1104 translate_to_native_sym_flags (&nsp, g, abfd);
1106 bfd_write((PTR)&nsp,1,EXTERNAL_NLIST_SIZE, abfd);
1109 /* Now output the strings. Be sure to put string length into correct
1110 byte ordering before writing it. */
1112 char buffer[BYTES_IN_WORD];
1113 PUT_WORD (abfd, stindex, (unsigned char *)buffer);
1115 bfd_write((PTR)buffer, 1, BYTES_IN_WORD, abfd);
1117 generic = bfd_get_outsymbols(abfd);
1118 for (count = 0; count < bfd_get_symcount(abfd); count++)
1120 asymbol *g = *(generic++);
1124 size_t length = strlen(g->name)+1;
1125 bfd_write((PTR)g->name, 1, length, abfd);
1127 if ((g->flags & BSF_FAKE)==0) {
1128 g->KEEPIT = (KEEPITTYPE) count;
1136 DEFUN(NAME(aout,get_symtab),(abfd, location),
1140 unsigned int counter = 0;
1141 aout_symbol_type *symbase;
1143 if (!NAME(aout,slurp_symbol_table)(abfd)) return 0;
1145 for (symbase = obj_aout_symbols(abfd); counter++ < bfd_get_symcount (abfd);)
1146 *(location++) = (asymbol *)( symbase++);
1148 return bfd_get_symcount(abfd);
1152 /* Standard reloc stuff */
1153 /* Output standard relocation information to a file in target byte order. */
1156 DEFUN(NAME(aout,swap_std_reloc_out),(abfd, g, natptr),
1159 struct reloc_std_external *natptr)
1163 unsigned int r_length;
1165 int r_baserel, r_jmptable, r_relative;
1166 unsigned int r_addend;
1168 PUT_WORD(abfd, g->address, natptr->r_address);
1170 r_length = g->howto->size ; /* Size as a power of two */
1171 r_pcrel = (int) g->howto->pc_relative; /* Relative to PC? */
1172 /* r_baserel, r_jmptable, r_relative??? FIXME-soon */
1177 r_addend = g->addend; /* Start here, see how it goes */
1179 /* name was clobbered by aout_write_syms to be symbol index */
1181 if (g->sym_ptr_ptr != NULL)
1183 if ((*(g->sym_ptr_ptr))->section) {
1184 /* put the section offset into the addend for output */
1185 r_addend += (*(g->sym_ptr_ptr))->section->vma;
1188 r_index = ((*(g->sym_ptr_ptr))->KEEPIT);
1193 if (g->section == NULL) {
1194 /* It is possible to have a reloc with nothing, we generate an
1197 r_index = N_ABS | N_EXT;
1199 else if(g->section->output_section == obj_textsec(abfd)) {
1200 r_index = N_TEXT | N_EXT;
1201 r_addend += g->section->output_section->vma;
1203 else if (g->section->output_section == obj_datasec(abfd)) {
1204 r_index = N_DATA | N_EXT;
1205 r_addend += g->section->output_section->vma;
1207 else if (g->section->output_section == obj_bsssec(abfd)) {
1208 r_index = N_BSS | N_EXT ;
1209 r_addend += g->section->output_section->vma;
1213 r_index = N_ABS | N_EXT;
1217 /* now the fun stuff */
1218 if (abfd->xvec->header_byteorder_big_p != false) {
1219 natptr->r_index[0] = r_index >> 16;
1220 natptr->r_index[1] = r_index >> 8;
1221 natptr->r_index[2] = r_index;
1223 (r_extern? RELOC_STD_BITS_EXTERN_BIG: 0)
1224 | (r_pcrel? RELOC_STD_BITS_PCREL_BIG: 0)
1225 | (r_baserel? RELOC_STD_BITS_BASEREL_BIG: 0)
1226 | (r_jmptable? RELOC_STD_BITS_JMPTABLE_BIG: 0)
1227 | (r_relative? RELOC_STD_BITS_RELATIVE_BIG: 0)
1228 | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG);
1230 natptr->r_index[2] = r_index >> 16;
1231 natptr->r_index[1] = r_index >> 8;
1232 natptr->r_index[0] = r_index;
1234 (r_extern? RELOC_STD_BITS_EXTERN_LITTLE: 0)
1235 | (r_pcrel? RELOC_STD_BITS_PCREL_LITTLE: 0)
1236 | (r_baserel? RELOC_STD_BITS_BASEREL_LITTLE: 0)
1237 | (r_jmptable? RELOC_STD_BITS_JMPTABLE_LITTLE: 0)
1238 | (r_relative? RELOC_STD_BITS_RELATIVE_LITTLE: 0)
1239 | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE);
1244 /* Extended stuff */
1245 /* Output extended relocation information to a file in target byte order. */
1248 DEFUN(NAME(aout,swap_ext_reloc_out),(abfd, g, natptr),
1251 register struct reloc_ext_external *natptr)
1255 unsigned int r_type;
1256 unsigned int r_addend;
1258 PUT_WORD (abfd, g->address, natptr->r_address);
1260 /* Find a type in the output format which matches the input howto -
1261 at the moment we assume input format == output format FIXME!! */
1262 r_type = (enum reloc_type) g->howto->type;
1264 r_addend = g->addend; /* Start here, see how it goes */
1266 /* name was clobbered by aout_write_syms to be symbol index*/
1268 if (g->sym_ptr_ptr != NULL)
1270 if ((*(g->sym_ptr_ptr))->section) {
1271 /* put the section offset into the addend for output */
1272 r_addend += (*(g->sym_ptr_ptr))->section->vma;
1275 r_index = stoi((*(g->sym_ptr_ptr))->KEEPIT);
1280 if (g->section == NULL) {
1282 r_index = N_ABS | N_EXT;
1284 else if(g->section->output_section == obj_textsec(abfd)) {
1285 r_index = N_TEXT | N_EXT;
1286 r_addend += g->section->output_section->vma;
1288 else if (g->section->output_section == obj_datasec(abfd)) {
1289 r_index = N_DATA | N_EXT;
1290 r_addend += g->section->output_section->vma;
1292 else if (g->section->output_section == obj_bsssec(abfd)) {
1293 r_index = N_BSS | N_EXT ;
1294 r_addend += g->section->output_section->vma;
1298 r_index = N_ABS | N_EXT;
1302 /* now the fun stuff */
1303 if (abfd->xvec->header_byteorder_big_p != false) {
1304 natptr->r_index[0] = r_index >> 16;
1305 natptr->r_index[1] = r_index >> 8;
1306 natptr->r_index[2] = r_index;
1308 (r_extern? RELOC_EXT_BITS_EXTERN_BIG: 0)
1309 | (r_type << RELOC_EXT_BITS_TYPE_SH_BIG);
1311 natptr->r_index[2] = r_index >> 16;
1312 natptr->r_index[1] = r_index >> 8;
1313 natptr->r_index[0] = r_index;
1315 (r_extern? RELOC_EXT_BITS_EXTERN_LITTLE: 0)
1316 | (r_type << RELOC_EXT_BITS_TYPE_SH_LITTLE);
1319 PUT_WORD (abfd, r_addend, natptr->r_addend);
1322 #define MOVE_ADDRESS(ad) \
1324 cache_ptr->sym_ptr_ptr = symbols + r_index; \
1325 cache_ptr->section = (asection *)NULL; \
1326 cache_ptr->addend = ad; \
1328 cache_ptr->sym_ptr_ptr = (asymbol **)NULL; \
1329 switch (r_index) { \
1331 case N_TEXT | N_EXT: \
1332 cache_ptr->section = obj_textsec(abfd); \
1333 cache_ptr->addend = ad - su->textsec->vma; \
1336 case N_DATA | N_EXT: \
1337 cache_ptr->section = obj_datasec(abfd); \
1338 cache_ptr->addend = ad - su->datasec->vma; \
1341 case N_BSS | N_EXT: \
1342 cache_ptr->section = obj_bsssec(abfd); \
1343 cache_ptr->addend = ad - su->bsssec->vma; \
1346 case N_ABS | N_EXT: \
1347 cache_ptr->section = NULL; /* No section */ \
1348 cache_ptr->addend = ad; /* FIXME, is this right? */ \
1352 cache_ptr->section = NULL; /* No section */ \
1353 cache_ptr->addend = ad; /* FIXME, is this right? */ \
1360 DEFUN(NAME(aout,swap_ext_reloc_in), (abfd, bytes, cache_ptr, symbols),
1362 struct reloc_ext_external *bytes AND
1363 arelent *cache_ptr AND
1368 unsigned int r_type;
1369 struct aoutdata *su = (struct aoutdata *)(abfd->tdata);
1371 cache_ptr->address = (GET_SWORD (abfd, bytes->r_address));
1373 /* now the fun stuff */
1374 if (abfd->xvec->header_byteorder_big_p != false) {
1375 r_index = (bytes->r_index[0] << 16)
1376 | (bytes->r_index[1] << 8)
1377 | bytes->r_index[2];
1378 r_extern = (0 != (bytes->r_type[0] & RELOC_EXT_BITS_EXTERN_BIG));
1379 r_type = (bytes->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
1380 >> RELOC_EXT_BITS_TYPE_SH_BIG;
1382 r_index = (bytes->r_index[2] << 16)
1383 | (bytes->r_index[1] << 8)
1384 | bytes->r_index[0];
1385 r_extern = (0 != (bytes->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE));
1386 r_type = (bytes->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
1387 >> RELOC_EXT_BITS_TYPE_SH_LITTLE;
1390 cache_ptr->howto = howto_table_ext + r_type;
1391 MOVE_ADDRESS(GET_SWORD(abfd,bytes->r_addend));
1395 DEFUN(NAME(aout,swap_std_reloc_in), (abfd, bytes, cache_ptr, symbols),
1397 struct reloc_std_external *bytes AND
1398 arelent *cache_ptr AND
1403 unsigned int r_length;
1405 int r_baserel, r_jmptable, r_relative;
1406 struct aoutdata *su = (struct aoutdata *)(abfd->tdata);
1408 cache_ptr->address = (int32_type)(bfd_h_get_32 (abfd, bytes->r_address));
1410 /* now the fun stuff */
1411 if (abfd->xvec->header_byteorder_big_p != false) {
1412 r_index = (bytes->r_index[0] << 16)
1413 | (bytes->r_index[1] << 8)
1414 | bytes->r_index[2];
1415 r_extern = (0 != (bytes->r_type[0] & RELOC_STD_BITS_EXTERN_BIG));
1416 r_pcrel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_PCREL_BIG));
1417 r_baserel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_BASEREL_BIG));
1418 r_jmptable= (0 != (bytes->r_type[0] & RELOC_STD_BITS_JMPTABLE_BIG));
1419 r_relative= (0 != (bytes->r_type[0] & RELOC_STD_BITS_RELATIVE_BIG));
1420 r_length = (bytes->r_type[0] & RELOC_STD_BITS_LENGTH_BIG)
1421 >> RELOC_STD_BITS_LENGTH_SH_BIG;
1423 r_index = (bytes->r_index[2] << 16)
1424 | (bytes->r_index[1] << 8)
1425 | bytes->r_index[0];
1426 r_extern = (0 != (bytes->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE));
1427 r_pcrel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE));
1428 r_baserel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_BASEREL_LITTLE));
1429 r_jmptable= (0 != (bytes->r_type[0] & RELOC_STD_BITS_JMPTABLE_LITTLE));
1430 r_relative= (0 != (bytes->r_type[0] & RELOC_STD_BITS_RELATIVE_LITTLE));
1431 r_length = (bytes->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE)
1432 >> RELOC_STD_BITS_LENGTH_SH_LITTLE;
1435 cache_ptr->howto = howto_table_std + r_length + 4 * r_pcrel;
1436 /* FIXME-soon: Roll baserel, jmptable, relative bits into howto setting */
1444 DEFUN(NAME(aout,slurp_reloc_table),(abfd, asect, symbols),
1450 bfd_size_type reloc_size;
1452 arelent *reloc_cache;
1455 if (asect->relocation) return true;
1457 if (asect->flags & SEC_CONSTRUCTOR) return true;
1459 if (asect == obj_datasec (abfd)) {
1460 reloc_size = exec_hdr(abfd)->a_drsize;
1464 if (asect == obj_textsec (abfd)) {
1465 reloc_size = exec_hdr(abfd)->a_trsize;
1469 bfd_error = invalid_operation;
1473 bfd_seek (abfd, asect->rel_filepos, SEEK_SET);
1474 each_size = obj_reloc_entry_size (abfd);
1476 count = reloc_size / each_size;
1479 reloc_cache = (arelent *) bfd_zalloc (abfd, (size_t)(count * sizeof
1483 bfd_error = no_memory;
1487 relocs = (PTR) bfd_alloc (abfd, reloc_size);
1489 bfd_release (abfd, reloc_cache);
1493 if (bfd_read (relocs, 1, reloc_size, abfd) != reloc_size) {
1494 bfd_release (abfd, relocs);
1495 bfd_release (abfd, reloc_cache);
1496 bfd_error = system_call_error;
1500 if (each_size == RELOC_EXT_SIZE) {
1501 register struct reloc_ext_external *rptr = (struct reloc_ext_external *) relocs;
1502 unsigned int counter = 0;
1503 arelent *cache_ptr = reloc_cache;
1505 for (; counter < count; counter++, rptr++, cache_ptr++) {
1506 NAME(aout,swap_ext_reloc_in)(abfd, rptr, cache_ptr, symbols);
1509 register struct reloc_std_external *rptr = (struct reloc_std_external*) relocs;
1510 unsigned int counter = 0;
1511 arelent *cache_ptr = reloc_cache;
1513 for (; counter < count; counter++, rptr++, cache_ptr++) {
1514 NAME(aout,swap_std_reloc_in)(abfd, rptr, cache_ptr, symbols);
1519 bfd_release (abfd,relocs);
1520 asect->relocation = reloc_cache;
1521 asect->reloc_count = count;
1527 /* Write out a relocation section into an object file. */
1530 DEFUN(NAME(aout,squirt_out_relocs),(abfd, section),
1535 unsigned char *native, *natptr;
1538 unsigned int count = section->reloc_count;
1541 if (count == 0) return true;
1543 each_size = obj_reloc_entry_size (abfd);
1544 natsize = each_size * count;
1545 native = (unsigned char *) bfd_zalloc (abfd, natsize);
1547 bfd_error = no_memory;
1551 generic = section->orelocation;
1553 if (each_size == RELOC_EXT_SIZE)
1555 for (natptr = native;
1557 --count, natptr += each_size, ++generic)
1558 NAME(aout,swap_ext_reloc_out) (abfd, *generic, (struct reloc_ext_external *)natptr);
1562 for (natptr = native;
1564 --count, natptr += each_size, ++generic)
1565 NAME(aout,swap_std_reloc_out)(abfd, *generic, (struct reloc_std_external *)natptr);
1568 if ( bfd_write ((PTR) native, 1, natsize, abfd) != natsize) {
1569 bfd_release(abfd, native);
1572 bfd_release (abfd, native);
1577 /* This is stupid. This function should be a boolean predicate */
1579 DEFUN(NAME(aout,canonicalize_reloc),(abfd, section, relptr, symbols),
1582 arelent **relptr AND
1585 arelent *tblptr = section->relocation;
1588 if (!(tblptr || NAME(aout,slurp_reloc_table)(abfd, section, symbols)))
1591 if (section->flags & SEC_CONSTRUCTOR) {
1592 arelent_chain *chain = section->constructor_chain;
1593 for (count = 0; count < section->reloc_count; count ++) {
1594 *relptr ++ = &chain->relent;
1595 chain = chain->next;
1599 tblptr = section->relocation;
1600 if (!tblptr) return 0;
1602 for (count = 0; count++ < section->reloc_count;)
1604 *relptr++ = tblptr++;
1609 return section->reloc_count;
1613 DEFUN(NAME(aout,get_reloc_upper_bound),(abfd, asect),
1617 if (bfd_get_format (abfd) != bfd_object) {
1618 bfd_error = invalid_operation;
1621 if (asect->flags & SEC_CONSTRUCTOR) {
1622 return (sizeof (arelent *) * (asect->reloc_count+1));
1626 if (asect == obj_datasec (abfd))
1627 return (sizeof (arelent *) *
1628 ((exec_hdr(abfd)->a_drsize / obj_reloc_entry_size (abfd))
1631 if (asect == obj_textsec (abfd))
1632 return (sizeof (arelent *) *
1633 ((exec_hdr(abfd)->a_trsize / obj_reloc_entry_size (abfd))
1636 bfd_error = invalid_operation;
1642 DEFUN(NAME(aout,get_symtab_upper_bound),(abfd),
1645 if (!NAME(aout,slurp_symbol_table)(abfd)) return 0;
1647 return (bfd_get_symcount (abfd)+1) * (sizeof (aout_symbol_type *));
1650 DEFUN(NAME(aout,get_lineno),(ignore_abfd, ignore_symbol),
1651 bfd *ignore_abfd AND
1652 asymbol *ignore_symbol)
1654 return (alent *)NULL;
1659 DEFUN(NAME(aout,print_symbol),(ignore_abfd, afile, symbol, how),
1660 bfd *ignore_abfd AND
1663 bfd_print_symbol_type how)
1665 FILE *file = (FILE *)afile;
1668 case bfd_print_symbol_name:
1670 fprintf(file,"%s", symbol->name);
1672 case bfd_print_symbol_more:
1673 fprintf(file,"%4x %2x %2x",(unsigned)(aout_symbol(symbol)->desc & 0xffff),
1674 (unsigned)(aout_symbol(symbol)->other & 0xff),
1675 (unsigned)(aout_symbol(symbol)->type));
1677 case bfd_print_symbol_all:
1679 CONST char *section_name = symbol->section == (asection *)NULL ?
1680 (CONST char *)"*abs" : symbol->section->name;
1682 bfd_print_symbol_vandf((PTR)file,symbol);
1684 fprintf(file," %-5s %04x %02x %02x",
1686 (unsigned)(aout_symbol(symbol)->desc & 0xffff),
1687 (unsigned)(aout_symbol(symbol)->other & 0xff),
1688 (unsigned)(aout_symbol(symbol)->type & 0xff));
1690 fprintf(file," %s", symbol->name);
1693 case bfd_print_symbol_nm:
1695 int section_code = bfd_decode_symclass (symbol);
1697 if (section_code == 'U')
1699 else if (symbol->section != (asection *)NULL)
1700 fprintf_vma(file, symbol->value+symbol->section->vma);
1702 fprintf_vma(file, symbol->value);
1703 if (section_code == '?')
1705 int type_code = aout_symbol(symbol)->type & 0xff;
1706 char *stab_name = aout_stab_name(type_code);
1708 if (stab_name == NULL)
1710 sprintf(buf, "(%d)", type_code);
1713 fprintf(file," - %02x %04x %5s",
1714 (unsigned)(aout_symbol(symbol)->other & 0xff),
1715 (unsigned)(aout_symbol(symbol)->desc & 0xffff),
1719 fprintf(file," %c", section_code);
1721 fprintf(file," %s", symbol->name);
1728 provided a BFD, a section and an offset into the section, calculate
1729 and return the name of the source file and the line nearest to the
1734 DEFUN(NAME(aout,find_nearest_line),(abfd,
1742 asection *section AND
1743 asymbol **symbols AND
1745 CONST char **filename_ptr AND
1746 CONST char **functionname_ptr AND
1747 unsigned int *line_ptr)
1749 /* Run down the file looking for the filename, function and linenumber */
1751 static char buffer[100];
1752 static char filename_buffer[200];
1753 bfd_vma high_line_vma = ~0;
1754 bfd_vma low_func_vma = 0;
1756 *filename_ptr = abfd->filename;
1757 *functionname_ptr = 0;
1759 if (symbols != (asymbol **)NULL) {
1760 for (p = symbols; *p; p++) {
1761 aout_symbol_type *q = (aout_symbol_type *)(*p);
1765 *filename_ptr = q->symbol.name;
1766 /* Look ahead to next symbol to check if that too is an N_SO. */
1770 q = (aout_symbol_type *)(*p);
1771 if (q->type != N_SO)
1774 /* Found a second N_SO First is directory; second is filename. */
1775 if (q->symbol.name[0] == '/')
1776 *filename_ptr = q->symbol.name;
1779 sprintf(filename_buffer, "%.140s%.50s",
1780 *filename_ptr, q->symbol.name);
1781 *filename_ptr = filename_buffer;
1784 if (obj_textsec(abfd) != section) {
1792 /* We'll keep this if it resolves nearer than the one we have already */
1793 if (q->symbol.value >= offset &&
1794 q->symbol.value < high_line_vma) {
1795 *line_ptr = q->desc;
1796 high_line_vma = q->symbol.value;
1801 /* We'll keep this if it is nearer than the one we have already */
1802 if (q->symbol.value >= low_func_vma &&
1803 q->symbol.value <= offset) {
1804 low_func_vma = q->symbol.value;
1805 func = (asymbol *)q;
1807 if (*line_ptr && func) {
1808 CONST char *function = func->name;
1810 strncpy(buffer, function, sizeof(buffer)-1);
1811 buffer[sizeof(buffer)-1] = 0;
1812 /* Have to remove : stuff */
1813 p = strchr(buffer,':');
1814 if (p != NULL) { *p = '\0'; }
1815 *functionname_ptr = buffer;
1830 DEFUN(NAME(aout,sizeof_headers),(abfd, execable),
1834 return adata(abfd)->exec_bytes_size;