1 /*** bfd backend for sunos binaries */
3 /* Copyright (C) 1990, 1991 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Diddler.
7 BFD 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 1, or (at your option)
12 BFD 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 BFD; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
23 * Revision 1.1 1991/03/21 21:11:23 gumby
26 * Revision 1.2 1991/03/15 18:16:52 rich
27 * *** empty log message ***
29 * Revision 1.12 1991/03/10 19:11:41 rich
31 * bfd.c coff-code.h libbfd.c libbfd.h srec.c sunos.c
33 * Working bugs out of coff support.
35 * Revision 1.11 1991/03/09 03:40:04 rich
37 * Makefile b.out.c liba.out.h libbfd.c sunos.c sysdep.h
39 * Changes dictated by porting binutils.
41 * Revision 1.10 1991/03/08 07:52:02 sac
42 * Reinstalled things which went away after latest merge from Intel.
44 * Fixed a couple of problems in symbol handling too.
46 * Revision 1.9 1991/03/08 04:18:16 rich
47 * *** empty log message ***
49 * Revision 1.8 1991/03/07 21:57:26 sac
50 * Moved type info out of the asymbol into the private space.
51 * Cleaned up C++ stuff
53 * Revision 1.7 1991/03/06 21:49:02 sac
54 * Modified bfd_find_filename to return name of function too.
56 * Revision 1.6 1991/03/06 02:19:36 sac
57 * Moved howto table, added support for constructor sections and provided
58 * sunos4_find_nearest_line
60 * Revision 1.5 1991/03/05 16:25:44 sac
61 * Modified howto vector to include inplace and mask fields.
65 #define TARGET_BYTE_ORDER_BIG_P 1
66 #define TARGET TARGET_SPARC
80 typedef void generic_symbol_type
;
81 /* These values are correct for the SPARC. I dunno about anything else */
82 #define PAGE_SIZE 0x02000
83 #define SEGMENT_SIZE PAGE_SIZE
84 #define TEXT_START_ADDR PAGE_SIZE
85 #include "a.out.gnu.h"
88 #include "liba.out.h" /* BFD a.out internal data structures */
90 #include "a.out.sun4.h"
92 #define CTOR_TABLE_RELOC_IDX 2
93 static reloc_howto_type howto_table
[] =
95 /* type rs size bsz pcrel bitpos abs ovrf sf name partial inplace mask*/
96 { (unsigned int) RELOC_8
, 0, 0, 8, false, 0, true, true,0,"8", false, 0x000000ff},
97 { (unsigned int) RELOC_16
, 0, 1, 16, false, 0, true, true,0,"16", false, 0x0000ffff},
98 { (unsigned int) RELOC_32
, 0, 2, 32, false, 0, true, true,0,"32", false, 0xffffffff},
99 { (unsigned int) RELOC_DISP8
, 0, 0, 8, true, 0, false, true,0,"DISP8", false, 0x000000ff},
100 { (unsigned int) RELOC_DISP16
, 0, 1, 16, true, 0, false, true,0,"DISP16", false, 0x0000ffff},
101 { (unsigned int) RELOC_DISP32
, 0, 2, 32, true, 0, false, true,0,"DISP32", false, 0xffffffff},
102 { (unsigned int) RELOC_WDISP30
,2, 2, 30, true, 0, false, true,0,"WDISP30", false, 0x3fffffff},
103 { (unsigned int) RELOC_WDISP22
,2, 2, 22, true, 0, false, true,0,"WDISP22", false, 0x003fffff},
104 { (unsigned int) RELOC_HI22
, 10, 2, 22, false, 0, false, true,0,"HI22", false, 0x003fffff},
105 { (unsigned int) RELOC_22
, 0, 2, 22, false, 0, false, true,0,"22", false, 0x003fffff},
106 { (unsigned int) RELOC_13
, 0, 2, 13, false, 0, false, true,0,"13", false, 0x00001fff},
107 { (unsigned int) RELOC_LO10
, 0, 2, 10, false, 0, false, true,0,"LO10", false, 0x000003ff},
108 { (unsigned int) RELOC_SFA_BASE
,0, 2, 32, false, 0, false, true,0,"SFA_BASE", false, 0xffffffff},
109 { (unsigned int) RELOC_SFA_OFF13
,0,2, 32, false, 0, false, true,0,"SFA_OFF13",false, 0xffffffff},
110 { (unsigned int) RELOC_BASE10
, 0, 2, 16, false, 0, false, true,0,"BASE10", false, 0x0000ffff},
111 { (unsigned int) RELOC_BASE13
, 0, 2, 13, false, 0, false, true,0,"BASE13", false, 0x00001fff},
112 { (unsigned int) RELOC_BASE22
, 0, 2, 0, false, 0, false, true,0,"BASE22", false, 0x00000000},
113 { (unsigned int) RELOC_PC10
, 0, 2, 10, false, 0, false, true,0,"PC10", false, 0x000003ff},
114 { (unsigned int) RELOC_PC22
, 0, 2, 22, false, 0, false, true,0,"PC22", false, 0x003fffff},
115 { (unsigned int) RELOC_JMP_TBL
,0, 2, 32, false, 0, false, true,0,"JMP_TBL", false, 0xffffffff},
116 { (unsigned int) RELOC_SEGOFF16
,0, 2, 0, false, 0, false, true,0,"SEGOFF16", false, 0x00000000},
117 { (unsigned int) RELOC_GLOB_DAT
,0, 2, 0, false, 0, false, true,0,"GLOB_DAT", false, 0x00000000},
118 { (unsigned int) RELOC_JMP_SLOT
,0, 2, 0, false, 0, false, true,0,"JMP_SLOT", false, 0x00000000},
119 { (unsigned int) RELOC_RELATIVE
,0, 2, 0, false, 0, false, true,0,"RELATIVE", false, 0x00000000},
120 { (unsigned int) RELOC_JUMPTARG
,2, 13, 16, true, 0, false, true,0,"JUMPTARG", false, 0x0000ffff},
121 { (unsigned int) RELOC_CONST
, 0, 13, 16, false, 0, false, true,0,"CONST", false, 0x0000ffff},
122 { (unsigned int) RELOC_CONSTH
, 16, 13, 16, false, 0, false, true,0,"CONSTH", false, 0x0000ffff},
127 PROTO (static void, swap_exec_header
, (bfd
*abfd
, struct exec
*execp
));
128 PROTO (void , sunos4_write_syms
, ());
129 PROTO (static boolean
,sunos4_squirt_out_relocs
,(bfd
*abfd
, asection
*section
));
131 /* Steve wants some way to frob this stuff from Saber while he's debugging
132 ld, so we have these funny shadow functions */
133 /* ZMAGIC's start at 0 (making the exec part of the text section),
134 other formats start after the exec
136 unsigned int n_txtoff(ptr
)
138 {return N_MAGIC(*ptr
)== ZMAGIC
? 0: sizeof(struct exec
);}
140 unsigned int n_datoff(ptr
)
142 {return n_txtoff(ptr
) + ptr
->a_text
;}
144 unsigned int n_treloff(ptr
)
146 {return n_datoff(ptr
) + ptr
->a_data
;}
148 unsigned int n_dreloff(ptr
)
150 {return n_treloff(ptr
) + ptr
->a_trsize
;}
152 unsigned int n_symoff(ptr
)
154 {return n_dreloff(ptr
) + ptr
->a_drsize
;}
156 unsigned int n_stroff(ptr
)
158 {return n_symoff(ptr
) + ptr
->a_syms
;}
160 unsigned int n_badmag(ptr
)
163 switch (N_MAGIC(*ptr
)) {
164 case OMAGIC
: case NMAGIC
: case ZMAGIC
: return 0;
171 sunos4_object_p (abfd
)
175 struct exec anexec
; /* save consing when you don't have to. */
176 struct exec
*execp
= &anexec
;
179 bfd_error
= system_call_error
;
181 if (bfd_read ((void *)&magic
, 1, sizeof (magic
), abfd
) != sizeof (magic
))
183 magic
= bfd_h_getlong (abfd
, &magic
);
185 /* Baroque syntax to mask deficiencies of the Sun compiler */
186 /* if (N_BADMAG (*((struct exec *) &magic))) return 0; */
187 if (n_badmag ((struct exec
*) &magic
)) return 0;
189 if (bfd_seek (abfd
, 0L, SEEK_SET
) < 0) return 0;
191 if (bfd_read ((void *) execp
, 1, sizeof (struct exec
), abfd
)
192 != sizeof (struct exec
)) {
193 bfd_error
= wrong_format
;
197 /* Use an intermediate variable for clarity */
198 rawptr
= (void *) zalloc (sizeof (struct sunexdata
) + sizeof (struct exec
));
200 if (rawptr
== NULL
) {
201 bfd_error
= no_memory
;
205 abfd
->tdata
=(void *)( (struct sunexdata
*) rawptr
);
207 (struct exec
*) ((char *)rawptr
+ sizeof (struct sunexdata
));
209 swap_exec_header (abfd
, execp
);
210 memcpy (exec_hdr (abfd
), execp
, sizeof (struct exec
));
212 /* Set the file flags */
213 abfd
->flags
= NO_FLAGS
;
214 if (execp
->a_drsize
|| execp
->a_trsize
)
215 abfd
->flags
|= HAS_RELOC
;
217 abfd
->flags
|= EXEC_P
;
219 abfd
->flags
|= HAS_LINENO
| HAS_DEBUG
| HAS_SYMS
| HAS_LOCALS
;
222 if (N_MAGIC (anexec
) == ZMAGIC
) abfd
->flags
|= D_PAGED
;
223 if (N_MAGIC (anexec
) == NMAGIC
) abfd
->flags
|= WP_TEXT
;
225 /* Determine the architecture and machine type of the object file. */
226 abfd
->obj_arch
= bfd_arch_unknown
; /* Default values */
227 abfd
->obj_machine
= 0;
228 switch (N_MACHTYPE (anexec
)) {
234 abfd
->obj_arch
= bfd_arch_m68k
;
235 abfd
->obj_machine
= 68010;
239 abfd
->obj_arch
= bfd_arch_m68k
;
240 abfd
->obj_machine
= 68020;
244 abfd
->obj_arch
= bfd_arch_sparc
;
248 abfd
->obj_arch
= bfd_arch_i386
;
252 abfd
->obj_arch
= bfd_arch_a29k
;
256 abfd
->obj_arch
= bfd_arch_obscure
;
260 bfd_get_start_address (abfd
) = execp
->a_entry
;
262 /* Remember the positions of the string table and symbol table. */
263 obj_str_filepos (abfd
) = n_stroff (&anexec
);
264 obj_sym_filepos (abfd
) = n_symoff (&anexec
);
266 /* create the sections. This is raunchy, but bfd_close wants to reclaim
268 obj_textsec (abfd
) = (asection
*)NULL
;
269 obj_datasec (abfd
) = (asection
*)NULL
;
270 obj_bsssec (abfd
) = (asection
*)NULL
;
271 obj_aout_symbols(abfd
) = (aout_symbol_type
*)NULL
;
272 (void)bfd_make_section(abfd
, ".text");
273 (void)bfd_make_section(abfd
, ".data");
274 (void)bfd_make_section(abfd
, ".bss");
276 obj_datasec (abfd
)->size
= execp
->a_data
;
277 obj_bsssec (abfd
)->size
= execp
->a_bss
;
278 obj_textsec (abfd
)->size
= execp
->a_text
;
279 obj_datasec (abfd
)->vma
= N_DATADDR(anexec
);
280 obj_bsssec (abfd
)->vma
= N_BSSADDR(anexec
);
281 obj_textsec (abfd
)->vma
= N_TXTADDR(anexec
);
283 obj_textsec (abfd
)->filepos
= n_txtoff(&anexec
);
284 obj_datasec (abfd
)->filepos
= n_datoff(&anexec
);
286 obj_textsec (abfd
)->rel_filepos
= n_treloff(&anexec
);
287 obj_datasec (abfd
)->rel_filepos
= n_dreloff(&anexec
);
289 obj_textsec (abfd
)->flags
=
290 (execp
->a_trsize
!= 0 ?
291 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_HAS_CONTENTS
) :
292 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
));
293 obj_datasec (abfd
)->flags
=
294 (execp
->a_drsize
!= 0 ?
295 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_HAS_CONTENTS
) :
296 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
));
297 obj_bsssec (abfd
)->flags
= SEC_ALLOC
;
299 abfd
->sections
= obj_textsec (abfd
);
300 obj_textsec (abfd
)->next
= obj_datasec (abfd
);
301 obj_datasec (abfd
)->next
= obj_bsssec (abfd
);
307 sunos4_mkobject (abfd
)
312 bfd_error
= system_call_error
;
314 /* Use an intermediate variable for clarity */
315 rawptr
= zalloc (sizeof (struct sunexdata
) + sizeof (struct exec
));
317 if (rawptr
== NULL
) {
318 bfd_error
= no_memory
;
322 abfd
->tdata
= (void *)((struct sunexdata
*) rawptr
);
323 exec_hdr (abfd
) = (struct exec
*) (rawptr
+ sizeof (struct sunexdata
));
325 /* For simplicity's sake we just make all the sections right here. */
327 obj_textsec (abfd
) = (asection
*)NULL
;
328 obj_datasec (abfd
) = (asection
*)NULL
;
329 obj_bsssec (abfd
) = (asection
*)NULL
;
330 bfd_make_section (abfd
, ".text");
331 bfd_make_section (abfd
, ".data");
332 bfd_make_section (abfd
, ".bss");
337 /* Keep track of machine architecture and machine type for a.out's.
338 Return the machine_type for a particular arch&machine, or M_UNKNOWN
339 if that exact arch&machine can't be represented in a.out format.
341 If the architecture is understood, machine type 0 (default) should
342 always be understood. */
344 static enum machine_type
345 aout_machine_type (arch
, machine
)
346 enum bfd_architecture arch
;
347 unsigned long machine
;
349 enum machine_type arch_flags
;
351 arch_flags
= M_UNKNOWN
;
355 if (machine
== 0) arch_flags
= M_SPARC
;
360 case 0: arch_flags
= M_UNKNOWN
; break;
361 case 68000: arch_flags
= M_UNKNOWN
; break;
362 case 68010: arch_flags
= M_68010
; break;
363 case 68020: arch_flags
= M_68020
; break;
364 default: arch_flags
= M_UNKNOWN
; break;
369 if (machine
== 0) arch_flags
= M_386
;
373 if (machine
== 0) arch_flags
= M_29K
;
377 arch_flags
= M_UNKNOWN
;
384 sunos4_set_arch_mach (abfd
, arch
, machine
)
386 enum bfd_architecture arch
;
387 unsigned long machine
;
389 abfd
->obj_arch
= arch
;
390 abfd
->obj_machine
= machine
;
391 if (arch
!= bfd_arch_unknown
&&
392 aout_machine_type (arch
, machine
) == M_UNKNOWN
)
393 return false; /* We can't represent this type */
394 return true; /* We're easy ... */
398 sunos4_write_object_contents (abfd
)
402 struct exec
*execp
= exec_hdr (abfd
);
406 /* Magic number, maestro, please! */
407 switch (bfd_get_architecture(abfd
)) {
409 switch (bfd_get_machine(abfd
)) {
411 N_SET_MACHTYPE(*execp
, M_68010
);
415 N_SET_MACHTYPE(*execp
, M_68020
);
420 N_SET_MACHTYPE(*execp
, M_SPARC
);
423 N_SET_MACHTYPE(*execp
, M_386
);
426 N_SET_MACHTYPE(*execp
, M_29K
);
429 N_SET_MACHTYPE(*execp
, M_UNKNOWN
);
431 execp
->a_text
= obj_textsec (abfd
)->size
;
432 N_SET_MAGIC (*execp
, OMAGIC
);
433 if (abfd
->flags
& D_PAGED
) {
434 execp
->a_text
= obj_textsec (abfd
)->size
+ sizeof(struct exec
);
435 N_SET_MAGIC (*execp
, ZMAGIC
);
436 } else if (abfd
->flags
& WP_TEXT
) {
437 N_SET_MAGIC (*execp
, NMAGIC
);
439 N_SET_FLAGS (*execp
, 0x1); /* copied from ld.c; who the hell knows? */
441 if (abfd
->flags
& D_PAGED
)
443 data_pad
= ((obj_datasec(abfd
)->size
+ PAGE_SIZE
-1)
444 & (- PAGE_SIZE
)) - obj_datasec(abfd
)->size
;
446 if (data_pad
> obj_bsssec(abfd
)->size
)
449 execp
->a_bss
= obj_bsssec(abfd
)->size
- data_pad
;
450 execp
->a_data
= obj_datasec(abfd
)->size
+ data_pad
;
454 execp
->a_data
= obj_datasec (abfd
)->size
;
455 execp
->a_bss
= obj_bsssec (abfd
)->size
;
458 execp
->a_syms
= bfd_get_symcount (abfd
) * sizeof (struct nlist
);
459 execp
->a_entry
= bfd_get_start_address (abfd
);
460 execp
->a_trsize
= ((obj_textsec (abfd
)->reloc_count
) *
461 sizeof (struct reloc_info_extended
));
462 execp
->a_drsize
= ((obj_datasec (abfd
)->reloc_count
) *
463 sizeof (struct reloc_info_extended
));;
465 swap_exec_header (abfd
, execp
);
467 bfd_seek (abfd
, 0L, SEEK_SET
);
468 bfd_write ((void *) execp
, 1, sizeof (struct exec
), abfd
);
470 /* Now write out reloc info, followed by syms and strings */
472 if (bfd_get_symcount (abfd
) != 0)
475 (long)(N_SYMOFF(*execp
)), SEEK_SET
);
477 sunos4_write_syms (abfd
);
479 bfd_seek (abfd
, (long)(N_TROFF(*execp
)), SEEK_SET
);
481 if (!sunos4_squirt_out_relocs (abfd
, obj_textsec (abfd
))) return false;
482 bfd_seek (abfd
, (long)(N_DROFF(*execp
)), SEEK_SET
);
484 if (!sunos4_squirt_out_relocs (abfd
, obj_datasec (abfd
))) return false;
490 swap_exec_header (abfd
, execp
)
494 if (bfd_header_twiddle_required(abfd
)) {
495 /* execp->a_info = bfd_h_getlong (abfd, &execp->a_info); */
496 *(unsigned long *) execp
=
497 bfd_h_getlong (abfd
, (unsigned long *) execp
);
498 execp
->a_text
= bfd_h_getlong (abfd
, &execp
->a_text
);
499 execp
->a_data
= bfd_h_getlong (abfd
, &execp
->a_data
);
500 execp
->a_bss
= bfd_h_getlong (abfd
, &execp
->a_bss
);
501 execp
->a_syms
= bfd_h_getlong (abfd
, &execp
->a_syms
);
502 execp
->a_entry
= bfd_h_getlong (abfd
, &execp
->a_entry
);
503 execp
->a_trsize
= bfd_h_getlong (abfd
, &execp
->a_trsize
);
504 execp
->a_drsize
= bfd_h_getlong (abfd
, &execp
->a_drsize
);
506 } /* swap_exec_header() */
510 #define CORE_MAGIC 0x080456
511 #define CORE_NAMELEN 16
513 /* The core structure is taken from the Sun documentation.
514 Unfortunately, they don't document the FPA structure, or at least I
515 can't find it easily. Fortunately the core header contains its own
516 length. So this shouldn't cause problems, except for c_ucode, which
517 so far we don't use but is easy to find with a little arithmetic. */
519 /* But the reg structure can be gotten from the SPARC processor handbook.
520 This really should be in a GNU include file though so that gdb can use
544 /* Taken from Sun documentation: */
547 int c_magic
; /* Corefile magic number */
548 int c_len
; /* Sizeof (struct core) */
549 struct regs c_regs
; /* General purpose registers */
550 struct exec c_aouthdr
; /* A.out header */
551 int c_signo
; /* Killing signal, if any */
552 int c_tsize
; /* Text size (bytes) */
553 int c_dsize
; /* Data size (bytes) */
554 int c_ssize
; /* Stack size (bytes) */
555 char c_cmdname
[CORE_NAMELEN
+ 1]; /* Command name */
556 double fp_stuff
[1]; /* external FPU state (size unknown by us) */
557 /* The type "double" is critical here, for alignment.
558 SunOS declares a struct here, but the struct's
559 alignment is double since it contains doubles. */
560 int c_ucode
; /* Exception no. from u_code */
561 /* (this member not accessible by name since we don't
562 portably know the size of fp_stuff.) */
565 /* Supposedly the user stack grows downward from the bottom of kernel memory.
566 Presuming that this remains true, this definition will work. */
567 #define USRSTACK (-(128*1024*1024))
569 PROTO (static void, swapcore
, (bfd
*abfd
, struct core
*core
));
571 /* need this cast b/c ptr is really void * */
572 #define core_hdr(bfd) (((struct suncordata *) (bfd->tdata))->hdr)
573 #define core_datasec(bfd) (((struct suncordata *) ((bfd)->tdata))->data_section)
574 #define core_stacksec(bfd) (((struct suncordata*)((bfd)->tdata))->stack_section)
575 #define core_regsec(bfd) (((struct suncordata *) ((bfd)->tdata))->reg_section)
576 #define core_regsec2(bfd) (((struct suncordata *) ((bfd)->tdata))->reg2_section)
578 /* These are stored in the bfd's tdata */
580 struct core
*hdr
; /* core file header */
581 asection
*data_section
;
582 asection
*stack_section
;
583 asection
*reg_section
;
584 asection
*reg2_section
;
588 sunos4_core_file_p (abfd
)
591 /* includes redundent variables for code clarity */
597 bfd_error
= system_call_error
;
599 if (bfd_read ((void *)&core_mag
, 1, sizeof (int), abfd
) != sizeof (int))
601 core_mag
= bfd_h_getlong(abfd
, &core_mag
);
603 if (core_mag
!= CORE_MAGIC
) return 0;
605 /* SunOS core headers can vary in length; second word is size; */
606 if (bfd_read ((void *)&core_size
, 1, sizeof (int), abfd
) != sizeof (int))
608 core_size
= bfd_h_getlong(abfd
, &core_size
);
610 if (bfd_seek (abfd
, 0L, SEEK_SET
) < 0) return 0;
612 rawptr
= zalloc (core_size
+ sizeof (struct suncordata
));
613 if (rawptr
== NULL
) {
614 bfd_error
= no_memory
;
618 core
= (struct core
*) (rawptr
+ sizeof (struct suncordata
));
620 if ((bfd_read ((void *) core
, 1, core_size
, abfd
)) != core_size
) {
621 bfd_error
= system_call_error
;
622 free ((void *)rawptr
);
626 swapcore (abfd
, core
);
627 abfd
->tdata
= (void *)((struct suncordata
*) rawptr
);
628 core_hdr (abfd
) = core
;
630 /* create the sections. This is raunchy, but bfd_close wants to reclaim
632 core_stacksec (abfd
) = (asection
*) zalloc (sizeof (asection
));
633 if (core_stacksec (abfd
) == NULL
) {
635 bfd_error
= no_memory
;
636 free ((void *)rawptr
);
639 core_datasec (abfd
) = (asection
*) zalloc (sizeof (asection
));
640 if (core_datasec (abfd
) == NULL
) {
642 free ((void *)core_stacksec (abfd
));
645 core_regsec (abfd
) = (asection
*) zalloc (sizeof (asection
));
646 if (core_regsec (abfd
) == NULL
) {
648 free ((void *)core_datasec (abfd
));
651 core_regsec2 (abfd
) = (asection
*) zalloc (sizeof (asection
));
652 if (core_regsec2 (abfd
) == NULL
) {
653 free ((void *)core_regsec (abfd
));
657 core_stacksec (abfd
)->name
= ".stack";
658 core_datasec (abfd
)->name
= ".data";
659 core_regsec (abfd
)->name
= ".reg";
660 core_regsec2 (abfd
)->name
= ".reg2";
662 core_stacksec (abfd
)->flags
= SEC_ALLOC
+ SEC_LOAD
;
663 core_datasec (abfd
)->flags
= SEC_ALLOC
+ SEC_LOAD
;
664 core_regsec (abfd
)->flags
= SEC_ALLOC
;
665 core_regsec2 (abfd
)->flags
= SEC_ALLOC
;
667 core_stacksec (abfd
)->size
= core
->c_ssize
;
668 core_datasec (abfd
)->size
= core
->c_dsize
;
669 core_regsec (abfd
)->size
= (sizeof core
->c_regs
);
670 /* Float regs take up end of struct, except c_ucode. */
671 core_regsec2 (abfd
)->size
= core_size
- (sizeof core
->c_ucode
) -
672 (file_ptr
)(((struct core
*)0)->fp_stuff
);
674 core_stacksec (abfd
)->vma
= (USRSTACK
- core
->c_ssize
);
675 core_datasec (abfd
)->vma
= N_DATADDR(core
->c_aouthdr
);
676 core_regsec (abfd
)->vma
= -1;
677 core_regsec2 (abfd
)->vma
= -1;
679 core_stacksec (abfd
)->filepos
= core
->c_len
+ core
->c_dsize
;
680 core_datasec (abfd
)->filepos
= core
->c_len
;
681 /* In file header: */
682 core_regsec (abfd
)->filepos
= (file_ptr
)(&((struct core
*)0)->c_regs
);
683 core_regsec2 (abfd
)->filepos
= (file_ptr
)(((struct core
*)0)->fp_stuff
);
685 /* Align to word at least */
686 core_stacksec (abfd
)->alignment_power
= 2;
687 core_datasec (abfd
)->alignment_power
= 2;
688 core_regsec (abfd
)->alignment_power
= 2;
689 core_regsec2 (abfd
)->alignment_power
= 2;
691 abfd
->sections
= core_stacksec (abfd
);
692 core_stacksec (abfd
)->next
= core_datasec (abfd
);
693 core_datasec (abfd
)->next
= core_regsec (abfd
);
694 core_regsec (abfd
)->next
= core_regsec2 (abfd
);
696 abfd
->section_count
= 4;
702 sunos4_core_file_failing_command (abfd
)
705 return core_hdr (abfd
)->c_cmdname
;
709 sunos4_core_file_failing_signal (abfd
)
712 return core_hdr (abfd
)->c_signo
;
716 sunos4_core_file_matches_executable_p (core_bfd
, exec_bfd
)
717 bfd
*core_bfd
, *exec_bfd
;
719 if (core_bfd
->xvec
!= exec_bfd
->xvec
) {
720 bfd_error
= system_call_error
;
724 return (bcmp (&core_hdr (core_bfd
), &exec_hdr (exec_bfd
),
725 sizeof (struct exec
)) == 0) ? true : false;
728 /* byte-swap core structure */
730 swapcore (abfd
, core
)
734 if (bfd_header_twiddle_required(abfd
)) {
735 core
->c_magic
= bfd_h_getlong (abfd
, &core
->c_magic
);
736 core
->c_len
= bfd_h_getlong (abfd
, &core
->c_len
);
738 swap_exec_header (abfd
, &(core
->c_aouthdr
));
739 core
->c_signo
= bfd_h_getlong (abfd
, &core
->c_signo
);
740 core
->c_tsize
= bfd_h_getlong (abfd
, &core
->c_tsize
);
741 core
->c_dsize
= bfd_h_getlong (abfd
, &core
->c_dsize
);
742 core
->c_ssize
= bfd_h_getlong (abfd
, &core
->c_ssize
);
743 core
->c_ucode
= bfd_h_getlong (abfd
, &core
->c_ucode
);
744 /* I don't understand how to swap an FP register */
748 /** exec and core file sections */
751 sunos4_new_section_hook (abfd
, newsect
)
755 /* align to double at least */
756 newsect
->alignment_power
= 3;
758 if (bfd_get_format (abfd
) == bfd_object
) {
759 if (obj_textsec(abfd
) == NULL
&& !strcmp(newsect
->name
, ".text")) {
760 obj_textsec(abfd
)= newsect
;
764 if (obj_datasec(abfd
) == NULL
&& !strcmp(newsect
->name
, ".data")) {
765 obj_datasec(abfd
) = newsect
;
769 if (obj_bsssec(abfd
) == NULL
&& !strcmp(newsect
->name
, ".bss")) {
770 obj_bsssec(abfd
) = newsect
;
775 #if 0 /* FIXME -- this is temporary for steve */
776 bfd_error
= invalid_operation
;
781 /* We allow more than three sections internally */
786 sunos4_set_section_contents (abfd
, section
, location
, offset
, count
)
789 unsigned char *location
;
793 if (abfd
->output_has_begun
== false)
794 { /* set by bfd.c handler */
795 if ((obj_textsec (abfd
) == NULL
) || (obj_datasec (abfd
) == NULL
)
798 (obj_textsec (abfd)->size == 0) || (obj_datasec (abfd)->size=
802 bfd_error
= invalid_operation
;
808 if (abfd
->flags
& D_PAGED
)
810 obj_textsec (abfd
)->filepos
= sizeof(struct exec
);
811 obj_datasec(abfd
)->filepos
= obj_textsec (abfd
)->size
;
816 obj_textsec (abfd
)->filepos
= sizeof(struct exec
);
817 obj_datasec(abfd
)->filepos
= obj_textsec(abfd
)->filepos
+ obj_textsec (abfd
)->size
;
821 /* regardless, once we know what we're doing, we might as well get going */
823 bfd_seek (abfd
, section
->filepos
+ offset
, SEEK_SET
);
826 return (bfd_write ((void *)location
, 1, count
, abfd
) == count
) ? true : false;
831 sunos4_get_section_contents (abfd
, section
, location
, offset
, count
)
839 if (offset
>= section
->size
) return false;
841 bfd_seek (abfd
, section
->filepos
+ offset
, SEEK_SET
);
843 return (bfd_read (location
, 1, count
, abfd
) == count
) ? true:false;
849 /* Classify stabs symbols */
852 #define sym_in_text_section(sym) \
853 (((sym)->n_type & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_TEXT)
855 #define sym_in_data_section(sym) \
856 (((sym)->n_type & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_DATA)
858 #define sym_in_bss_section(sym) \
859 (((sym)->n_type & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_BSS)
861 /* Symbol is undefined if type is N_UNDF|N_EXT and if it has
862 zero in the "value" field. Nonzeroes there are fortrancommon
864 #define sym_is_undefined(sym) \
865 ((sym)->n_type == (N_UNDF | N_EXT) && (sym)->n_value == 0)
867 /* Symbol is a global definition if N_EXT is on and if it has
868 a nonzero type field. */
869 #define sym_is_global_defn(sym) \
870 (((sym)->n_type & N_EXT) && (sym)->n_type & N_TYPE)
872 /* Symbol is debugger info if any bits outside N_TYPE or N_EXT
874 #define sym_is_debugger_info(sym) \
875 ((sym)->n_type & ~(N_EXT | N_TYPE))
877 #define sym_is_fortrancommon(sym) \
878 (((sym)->n_type == (N_EXT)) && (sym)->n_value != 0)
880 /* Symbol is absolute if it has N_ABS set */
881 #define sym_is_absolute(sym) \
882 (((sym)->n_type & N_TYPE)== N_ABS)
885 #define sym_is_indirect(sym) \
886 (((sym)->n_type & N_ABS)== N_ABS)
888 /* Only in their own functions for ease of debugging; when sym flags have
889 stabilised these should be inlined into their (single) caller */
892 translate_from_native_sym_flags (sym_pointer
, cache_ptr
, abfd
)
893 struct nlist
*sym_pointer
;
894 aout_symbol_type
*cache_ptr
;
897 switch (cache_ptr
->type
& N_TYPE
) {
903 asection
*section
= bfd_make_section(abfd
,
904 cache_ptr
->symbol
.name
);
905 arelent_chain
*reloc
= (arelent_chain
*)malloc(sizeof(arelent_chain
));
907 switch ( (cache_ptr
->type
& N_TYPE
) ) {
909 reloc
->relent
.section
= (asection
*)NULL
;
910 cache_ptr
->symbol
.section
= (asection
*)NULL
;
913 reloc
->relent
.section
= (asection
*)obj_textsec(abfd
);
914 cache_ptr
->symbol
.value
-= reloc
->relent
.section
->vma
;
917 reloc
->relent
.section
= (asection
*)obj_datasec(abfd
);
918 cache_ptr
->symbol
.value
-= reloc
->relent
.section
->vma
;
921 reloc
->relent
.section
= (asection
*)obj_bsssec(abfd
);
922 cache_ptr
->symbol
.value
-= reloc
->relent
.section
->vma
;
925 cache_ptr
->symbol
.section
= reloc
->relent
.section
;
926 reloc
->relent
.addend
= cache_ptr
->symbol
.value
;
928 We modify the symbol to belong to a section depending upon the
929 name of the symbol - probably __CTOR__ or __DTOR__ but we don't
930 really care, and add to the size of the section to contain a
931 pointer to the symbol. Build a reloc entry to relocate to this
932 symbol attached to this section.
936 section
->flags
= SEC_CONSTRUCTOR
;
937 section
->reloc_count
++;
938 section
->alignment_power
= 2;
939 reloc
->relent
.sym_ptr_ptr
= (asymbol
**)NULL
;
940 reloc
->next
= section
->constructor_chain
;
941 section
->constructor_chain
= reloc
;
942 reloc
->relent
.address
= section
->size
;
943 section
->size
+= sizeof(int *);
945 reloc
->relent
.howto
= howto_table
+CTOR_TABLE_RELOC_IDX
;
946 cache_ptr
->symbol
.flags
|= BSF_DEBUGGING
;
951 if (sym_is_debugger_info (sym_pointer
)) {
952 cache_ptr
->symbol
.flags
= BSF_DEBUGGING
;
953 /* Work out the section correct for this symbol */
954 switch (sym_pointer
->n_type
& N_TYPE
)
958 cache_ptr
->symbol
.section
= obj_textsec (abfd
);
959 cache_ptr
->symbol
.value
-= obj_textsec(abfd
)->vma
;
962 cache_ptr
->symbol
.value
-= obj_datasec(abfd
)->vma
;
963 cache_ptr
->symbol
.section
= obj_datasec (abfd
);
966 cache_ptr
->symbol
.section
= obj_bsssec (abfd
);
967 cache_ptr
->symbol
.value
-= obj_bsssec(abfd
)->vma
;
971 cache_ptr
->symbol
.section
= 0;
976 if (sym_is_fortrancommon (sym_pointer
))
978 cache_ptr
->symbol
.flags
= BSF_FORT_COMM
;
979 cache_ptr
->symbol
.section
= (asection
*)NULL
;
982 if (sym_is_undefined (sym_pointer
)) {
983 cache_ptr
->symbol
.flags
= BSF_UNDEFINED
;
985 else if (sym_is_global_defn (sym_pointer
)) {
986 cache_ptr
->symbol
.flags
= BSF_GLOBAL
| BSF_EXPORT
;
989 else if (sym_is_absolute (sym_pointer
)) {
990 cache_ptr
->symbol
.flags
= BSF_ABSOLUTE
;
993 cache_ptr
->symbol
.flags
= BSF_LOCAL
;
996 /* In a.out, the value of a symbol is always relative to the
997 * start of the file, if this is a data symbol we'll subtract
998 * the size of the text section to get the section relative
999 * value. If this is a bss symbol (which would be strange)
1000 * we'll subtract the size of the previous two sections
1001 * to find the section relative address.
1004 if (sym_in_text_section (sym_pointer
)) {
1005 cache_ptr
->symbol
.value
-= obj_textsec(abfd
)->vma
;
1006 cache_ptr
->symbol
.section
= obj_textsec (abfd
);
1008 else if (sym_in_data_section (sym_pointer
)){
1009 cache_ptr
->symbol
.value
-= obj_datasec(abfd
)->vma
;
1010 cache_ptr
->symbol
.section
= obj_datasec (abfd
);
1012 else if (sym_in_bss_section(sym_pointer
)) {
1013 cache_ptr
->symbol
.section
= obj_bsssec (abfd
);
1014 cache_ptr
->symbol
.value
-= obj_bsssec(abfd
)->vma
;
1017 cache_ptr
->symbol
.section
= (asection
*)NULL
;
1018 cache_ptr
->symbol
.flags
|= BSF_ABSOLUTE
;
1025 translate_to_native_sym_flags (sym_pointer
, cache_ptr_g
, abfd
)
1026 struct nlist
*sym_pointer
;
1027 generic_symbol_type
*cache_ptr_g
;
1030 asymbol
*cache_ptr
= (asymbol
*)cache_ptr_g
;
1032 /* FIXME check for wrigin bss */
1033 if (bfd_get_section(cache_ptr
)) {
1034 if (bfd_get_output_section(cache_ptr
) == obj_bsssec (abfd
)) {
1035 sym_pointer
->n_type
|= N_BSS
;
1037 else if (bfd_get_output_section(cache_ptr
) == obj_datasec (abfd
)) {
1038 sym_pointer
->n_type
|= N_DATA
;
1040 else if (bfd_get_output_section(cache_ptr
) == obj_textsec (abfd
)) {
1041 sym_pointer
->n_type
|= N_TEXT
;
1046 /* Turn the symbol from section relative to absolute again */
1047 sym_pointer
->n_value
+=
1048 cache_ptr
->section
->output_section
->vma
1049 + cache_ptr
->section
->output_offset
;
1052 sym_pointer
->n_type
|= N_ABS
;
1055 if (cache_ptr
->flags
& (BSF_FORT_COMM
| BSF_UNDEFINED
)) {
1056 sym_pointer
->n_type
= (N_UNDF
| N_EXT
);
1060 if (cache_ptr
->flags
& BSF_ABSOLUTE
) {
1061 sym_pointer
->n_type
|= N_ABS
;
1064 if (cache_ptr
->flags
& (BSF_GLOBAL
| BSF_EXPORT
)) {
1065 sym_pointer
->n_type
|= N_EXT
;
1067 if (cache_ptr
->flags
& BSF_DEBUGGING
) {
1068 sym_pointer
->n_type
= ((aout_symbol_type
*)cache_ptr
)->type
;
1073 /* Native-level interface to symbols. */
1075 /* We read the symbols into a buffer, which is discarded when this
1076 function exits. We read the strings into a buffer large enough to
1077 hold them all plus all the cached symbol entries. */
1080 sunos4_make_empty_symbol (abfd
)
1083 aout_symbol_type
*new =
1084 (aout_symbol_type
*)zalloc (sizeof (aout_symbol_type
));
1085 new->symbol
.the_bfd
= abfd
;
1087 return &new->symbol
;
1091 sunos4_slurp_symbol_table (abfd
)
1094 unsigned int symbol_count
;
1099 aout_symbol_type
*cached
;
1101 /* If there's no work to be done, don't do any */
1102 if (obj_aout_symbols (abfd
) != (aout_symbol_type
*)NULL
) return true;
1103 symbol_size
= exec_hdr(abfd
)->a_syms
;
1104 if (symbol_size
== 0) {
1105 bfd_error
= no_symbols
;
1109 bfd_seek (abfd
, obj_str_filepos (abfd
), SEEK_SET
);
1110 if (bfd_read ((void *)&string_size
, 4, 1, abfd
) != 4)
1112 string_size
= bfd_h_getlong (abfd
, (unsigned char *)&string_size
);
1114 symbol_count
= symbol_size
/ sizeof (struct nlist
);
1116 /* Malloc (should alloca) space for native symbols, and
1117 malloc space for string table and symbol cache. */
1119 syms
= (struct nlist
*) zalloc (symbol_size
);
1121 bfd_error
= no_memory
;
1125 cached
= (aout_symbol_type
*) zalloc ((size_t)(string_size
+ 1 +
1126 (symbol_count
* sizeof (aout_symbol_type
))));
1127 if (cached
== NULL
) {
1128 bfd_error
= no_memory
;
1129 free ((void *)syms
);
1133 strings
= ((char *) cached
) + (symbol_count
* sizeof (aout_symbol_type
));
1135 bfd_seek (abfd
, obj_sym_filepos (abfd
), SEEK_SET
);
1136 if (bfd_read ((void *)syms
, 1, symbol_size
, abfd
) != symbol_size
) {
1138 free ((void *)cached
);
1143 bfd_seek (abfd
, obj_str_filepos (abfd
), SEEK_SET
);
1144 if (bfd_read ((void *)strings
, 1, string_size
, abfd
) != string_size
) {
1148 /* OK, now walk the new symtable, cacheing symbol properties */
1150 register struct nlist
*sym_pointer
;
1151 register struct nlist
*sym_end
= syms
+ symbol_count
;
1152 register aout_symbol_type
*cache_ptr
= cached
;
1154 if (bfd_header_twiddle_required (abfd
) == true) {
1155 /* run through the table and byte swap if needed */
1156 for (sym_pointer
= syms
; sym_pointer
< sym_end
; sym_pointer
++) {
1157 sym_pointer
->n_un
.n_strx
=
1158 bfd_h_get_x (abfd
, &sym_pointer
->n_un
.n_strx
);
1159 sym_pointer
->n_desc
=
1160 bfd_h_get_x (abfd
, &sym_pointer
->n_desc
);
1161 sym_pointer
->n_value
=
1162 bfd_h_get_x (abfd
, &sym_pointer
->n_value
);
1163 sym_pointer
->n_other
= (char)
1164 bfd_h_get_x(abfd
, &sym_pointer
->n_other
);
1165 sym_pointer
->n_type
= (char)
1166 bfd_h_get_x(abfd
, &sym_pointer
->n_type
);
1170 /* Run through table and copy values */
1171 for (sym_pointer
= syms
, cache_ptr
= cached
;
1172 sym_pointer
< sym_end
; sym_pointer
++, cache_ptr
++)
1174 cache_ptr
->symbol
.the_bfd
= abfd
;
1175 if (sym_pointer
->n_un
.n_strx
)
1176 cache_ptr
->symbol
.name
= sym_pointer
->n_un
.n_strx
+ strings
;
1178 cache_ptr
->symbol
.name
= (char *)NULL
;
1179 cache_ptr
->symbol
.value
= sym_pointer
->n_value
;
1180 cache_ptr
->desc
= sym_pointer
->n_desc
;
1181 cache_ptr
->other
= sym_pointer
->n_other
;
1182 cache_ptr
->type
= sym_pointer
->n_type
;
1183 cache_ptr
->symbol
.udata
= 0;
1184 translate_from_native_sym_flags (sym_pointer
, cache_ptr
, abfd
);
1189 obj_aout_symbols (abfd
) = cached
;
1190 bfd_get_symcount (abfd
) = symbol_count
;
1191 free ((void *)syms
);
1198 sunos4_write_syms (abfd
)
1201 unsigned int count
;
1202 asymbol
**generic
= bfd_get_outsymbols (abfd
);
1204 unsigned int stindex
= sizeof(stindex
); /* initial string length */
1206 for (count
= 0; count
< bfd_get_symcount (abfd
); count
++) {
1207 asymbol
*g
= generic
[count
];
1211 unsigned int length
= strlen(g
->name
) +1;
1212 bfd_h_putlong (abfd
, stindex
, (unsigned char *)&nsp
.n_un
.n_strx
);
1216 bfd_h_putlong (abfd
, 0, (unsigned char *)&nsp
.n_un
.n_strx
);
1219 if (g
->the_bfd
->xvec
->flavour
== abfd
->xvec
->flavour
)
1221 nsp
.n_desc
= aout_symbol( g
)->desc
;
1222 nsp
.n_other
= aout_symbol(g
)->other
;
1223 nsp
.n_type
= aout_symbol(g
)->type
;
1233 nsp
.n_value
= g
->value
;
1234 translate_to_native_sym_flags (&nsp
, (generic_symbol_type
*)g
, abfd
);
1237 bfd_h_putshort (abfd
, nsp
.n_desc
, (unsigned char *)&nsp
.n_desc
);
1238 bfd_h_putlong (abfd
, nsp
.n_value
, (unsigned char *)&nsp
.n_value
);
1239 bfd_write((void *)&nsp
,1, sizeof(nsp
), abfd
);
1243 /* Now output the strings. Be sure to put string length into correct
1244 * byte ordering before writing it.
1246 bfd_h_putlong (abfd
, stindex
, (unsigned char *)&stindex
);
1248 bfd_write((void *)&stindex
, 1, sizeof(stindex
), abfd
);
1250 generic
= bfd_get_outsymbols(abfd
);
1251 for (count
= 0; count
< bfd_get_symcount(abfd
); count
++)
1253 asymbol
*g
= *(generic
++);
1255 if (g
->name
!= (char *)NULL
)
1257 size_t length
= strlen(g
->name
)+1;
1258 bfd_write((void *)g
->name
, 1, length
, abfd
);
1260 if ((g
->flags
& BSF_FAKE
)==0) {
1261 g
->name
= itos(count
); /* smash the generic symbol */
1268 sunos4_reclaim_symbol_table (abfd
)
1273 if (!bfd_get_symcount (abfd
)) return;
1275 for (section
= abfd
->sections
;
1276 section
!= (asection
*) NULL
;
1277 section
= section
->next
)
1278 if (section
->relocation
) {
1279 free ((void *)section
->relocation
);
1280 section
->relocation
= NULL
;
1281 section
->reloc_count
= 0;
1284 bfd_get_symcount (abfd
) = 0;
1285 free ((void *)obj_aout_symbols (abfd
));
1286 obj_aout_symbols (abfd
) = (aout_symbol_type
*)NULL
;
1290 sunos4_get_symtab_upper_bound (abfd
)
1293 if (!sunos4_slurp_symbol_table (abfd
)) return 0;
1295 return (bfd_get_symcount (abfd
)+1) * (sizeof (aout_symbol_type
*));
1299 sunos4_get_symtab (abfd
, location
)
1303 unsigned int counter
= 0;
1304 aout_symbol_type
*symbase
;
1306 if (!sunos4_slurp_symbol_table (abfd
)) return 0;
1308 for (symbase
= obj_aout_symbols(abfd
); counter
++ < bfd_get_symcount (abfd
);)
1309 *(location
++) = (asymbol
*)( symbase
++);
1311 return bfd_get_symcount(abfd
);
1315 /* Obsolete procedural interface; better to look at the cache directly */
1317 /* User should have checked the file flags; perhaps we should return
1318 BFD_NO_MORE_SYMBOLS if there are none? */
1321 sunos4_get_symcount_upper_bound (abfd
)
1324 /* In case we're doing an output file or something...? */
1325 if (bfd_get_symcount (abfd
)) return bfd_get_symcount (abfd
);
1327 return (exec_hdr (abfd
)->a_syms
) / (sizeof (struct nlist
));
1331 sunos4_get_first_symbol (ignore_abfd
)
1338 sunos4_get_next_symbol (abfd
, oidx
)
1342 if (oidx
== BFD_NO_MORE_SYMBOLS
) return BFD_NO_MORE_SYMBOLS
;
1343 return ++oidx
>= bfd_get_symcount (abfd
) ? BFD_NO_MORE_SYMBOLS
: oidx
;
1347 sunos4_symbol_name (abfd
, idx
)
1351 return (obj_aout_symbols (abfd
) + idx
)->symbol
.name
;
1355 sunos4_symbol_value (abfd
, idx
)
1359 return (obj_aout_symbols (abfd
) + idx
)->symbol
.value
;
1363 sunos4_classify_symbol (abfd
, idx
)
1367 aout_symbol_type
*sym
= obj_aout_symbols (abfd
) + idx
;
1369 if ((sym
->symbol
.flags
& BSF_FORT_COMM
) != 0) return bfd_symclass_fcommon
;
1370 if ((sym
->symbol
.flags
& BSF_GLOBAL
) != 0) return bfd_symclass_global
;
1371 if ((sym
->symbol
.flags
& BSF_DEBUGGING
) != 0) return bfd_symclass_debugger
;
1372 if ((sym
->symbol
.flags
& BSF_UNDEFINED
) != 0) return bfd_symclass_undefined
;
1374 return bfd_symclass_unknown
;
1378 sunos4_symbol_hasclass (abfd
, idx
, class)
1383 aout_symbol_type
*sym
= obj_aout_symbols (abfd
) + idx
;
1385 case bfd_symclass_fcommon
:
1386 return (sym
->symbol
.flags
& BSF_FORT_COMM
) ? true :false;
1387 case bfd_symclass_global
:
1388 return (sym
->symbol
.flags
& BSF_GLOBAL
) ? true:false;
1389 case bfd_symclass_debugger
:
1390 return (sym
->symbol
.flags
& BSF_DEBUGGING
) ? true:false;;
1391 case bfd_symclass_undefined
:
1392 return (sym
->symbol
.flags
& BSF_UNDEFINED
) ? true:false;;
1393 default: return false;
1397 /** Some reloc hackery */
1401 sunos4_slurp_reloc_table (abfd
, asect
, symbols
)
1408 struct reloc_info_extended
*relocs
;
1409 arelent
*reloc_cache
;
1411 if (asect
->relocation
) return true;
1413 if (asect
->flags
& SEC_CONSTRUCTOR
) return true;
1415 if (asect
== obj_datasec (abfd
)) {
1416 reloc_size
= exec_hdr(abfd
)->a_drsize
;
1420 if (asect
== obj_textsec (abfd
)) {
1421 reloc_size
= exec_hdr(abfd
)->a_trsize
;
1425 bfd_error
= invalid_operation
;
1429 bfd_seek (abfd
, asect
->rel_filepos
, SEEK_SET
);
1430 count
= reloc_size
/ sizeof (struct reloc_info_extended
);
1432 relocs
= (struct reloc_info_extended
*) malloc (reloc_size
);
1434 bfd_error
= no_memory
;
1437 reloc_cache
= (arelent
*) zalloc ((size_t)(count
* sizeof (arelent
)));
1438 if (reloc_cache
== (arelent
*)NULL
) {
1439 free ((void *)relocs
);
1440 bfd_error
= no_memory
;
1444 if (bfd_read ((void*) relocs
, 1, reloc_size
, abfd
) != reloc_size
) {
1445 bfd_error
= system_call_error
;
1452 register struct reloc_info_extended
*rptr
= relocs
;
1453 unsigned int counter
= 0;
1454 arelent
*cache_ptr
= reloc_cache
;
1456 for (; counter
< count
; counter
++, rptr
++, cache_ptr
++) {
1457 /* john's old swap_reloc was a hell of a lot hairier... */
1458 /* FIXME, it needs to be!!! */
1459 rptr
->r_address
= bfd_h_getlong (abfd
, &rptr
->r_address
);
1461 * The following can't be done because r_index is a bit field:
1463 * rptr->r_index = bfd_h_getlong (abfd, &rptr->r_index);
1465 rptr
->r_addend
= bfd_h_getlong (abfd
, &rptr
->r_addend
);
1466 if (rptr
->r_extern
) {
1467 /* If this bit is set then the r_index is a index into the symbol table
1468 * if the bit is not set then r_index contains a section map.
1469 * We either fill in the sym entry with a pointer to the symbol,
1470 * or point to the correct section
1473 cache_ptr
->sym_ptr_ptr
= symbols
+ rptr
->r_index
;
1474 cache_ptr
->addend
= rptr
->r_addend
;
1475 cache_ptr
->section
= (asection
*)NULL
;
1479 /* Remember that in a.out symbols are relative to the
1480 beginning of the file rather than sections ? (look in
1481 translate_from_native_sym_flags) The reloc entry addend
1482 has added to it the offset into the file of the data, so
1483 subtract the base to make the reloc section relative */
1485 cache_ptr
->sym_ptr_ptr
= (asymbol
**)NULL
;
1486 switch (rptr
->r_index
) {
1488 case N_TEXT
| N_EXT
:
1489 cache_ptr
->section
= obj_textsec(abfd
);
1490 cache_ptr
->addend
= rptr
->r_addend
- obj_textsec(abfd
)->vma
;
1493 case N_DATA
| N_EXT
:
1494 cache_ptr
->section
= obj_datasec(abfd
);
1495 cache_ptr
->addend
= rptr
->r_addend
- obj_datasec(abfd
)->vma
;
1499 cache_ptr
->section
= obj_bsssec(abfd
);
1500 cache_ptr
->addend
= rptr
->r_addend
- obj_bsssec(abfd
)->vma
;
1513 cache_ptr
->address
= rptr
->r_address
;
1514 cache_ptr
->howto
= howto_table
+ (unsigned int)( rptr
->r_type
);
1519 asect
->relocation
= reloc_cache
;
1520 asect
->reloc_count
= count
;
1525 sunos4_squirt_out_relocs (abfd
, section
)
1531 unsigned int count
= section
->reloc_count
;
1532 struct reloc_info_extended
*native
, *natptr
;
1533 size_t natsize
= count
* sizeof (struct reloc_info_extended
);
1535 if (count
== 0) return true;
1536 generic
= section
->orelocation
;
1537 native
= ((struct reloc_info_extended
*) zalloc (natsize
));
1539 bfd_error
= no_memory
;
1543 for (natptr
= native
; count
!= 0; --count
, ++natptr
, ++generic
)
1545 arelent
*g
= *generic
;
1547 natptr
->r_address
= g
->address
;
1548 /* Find a type in the output format which matches the input howto -
1549 * at the moment we assume input format == output format FIXME!!
1551 natptr
->r_type
= (enum reloc_type
) g
->howto
->type
;
1552 /* name clobbered by sunos4_write_syms to be symbol index*/
1554 if (g
->sym_ptr_ptr
!= (asymbol
**)NULL
)
1556 if ((*(g
->sym_ptr_ptr
))->section
) {
1557 /* replace the section offset into the addent */
1558 g
->addend
+= (*(g
->sym_ptr_ptr
))->section
->vma
;
1561 natptr
->r_index
= stoi((*(g
->sym_ptr_ptr
))->name
);
1562 BFD_ASSERT(natptr
->r_index
< 0xfff);
1563 natptr
->r_extern
= 1;
1564 natptr
->r_addend
= g
->addend
;
1567 natptr
->r_extern
= 0;
1568 if (g
->section
== (asection
*)NULL
) {
1570 natptr
->r_index
= N_ABS
| N_EXT
;
1571 natptr
->r_addend
= g
->addend
;
1573 else if(g
->section
->output_section
== obj_textsec(abfd
)) {
1574 natptr
->r_index
= N_TEXT
| N_EXT
;
1575 natptr
->r_addend
= g
->addend
+ obj_textsec(abfd
)->vma
;
1577 else if (g
->section
->output_section
== obj_datasec(abfd
)) {
1578 natptr
->r_index
= N_DATA
| N_EXT
;
1579 natptr
->r_addend
= g
->addend
+ obj_datasec(abfd
)->vma
;
1581 else if (g
->section
->output_section
== obj_bsssec(abfd
)) {
1582 natptr
->r_index
= N_BSS
| N_EXT
;
1583 natptr
->r_addend
= g
->addend
+ obj_bsssec(abfd
)->vma
;
1591 if ( bfd_header_twiddle_required(abfd
) ){
1592 bfd_h_putlong ( abfd
, natptr
->r_address
, &natptr
->r_address
);
1596 * I came through here as part of my campaign to make compile-time
1597 * definition of host and target byte orders unnecessary. The new
1598 * code won't even compile because but r_index is a bit field.
1599 * But the simple-minded byte swap that was here before wasn't going
1600 * to work on a bit field anyway.
1602 * The old code used to be #ifdef'd on
1603 * TARGET_BYTE_ORDER_BIG_P != HOST_BYTE_ORDER_BIG_P
1604 * Apparently, it was never tested in such a condition: the
1605 * macro invocations here (of swapoutlong) had the wrong number
1606 * of arguments and would never have compiled.
1608 bfd_h_putlong ( abfd, natptr->r_index, &natptr->r_index );
1611 bfd_h_putlong ( abfd
, natptr
->r_addend
, &natptr
->r_addend
);
1616 if ( bfd_write ((void *) native
, 1, natsize
, abfd
) != natsize
) {
1625 /* This is stupid. This function should be a boolean predicate */
1627 sunos4_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
1633 arelent
*tblptr
= section
->relocation
;
1636 if (!(tblptr
|| sunos4_slurp_reloc_table (abfd
, section
, symbols
)))
1639 if (section
->flags
& SEC_CONSTRUCTOR
) {
1640 arelent_chain
*chain
= section
->constructor_chain
;
1641 for (count
= 0; count
< section
->reloc_count
; count
++) {
1642 *relptr
++ = &chain
->relent
;
1643 chain
= chain
->next
;
1647 tblptr
= section
->relocation
;
1648 if (!tblptr
) return 0;
1650 for (count
= 0; count
++ < section
->reloc_count
;)
1652 *relptr
++ = tblptr
++;
1657 return section
->reloc_count
;
1661 sunos4_get_reloc_upper_bound (abfd
, asect
)
1665 if (bfd_get_format (abfd
) != bfd_object
) {
1666 bfd_error
= invalid_operation
;
1669 if (asect
->flags
& SEC_CONSTRUCTOR
) {
1670 return (sizeof (arelent
*) * (asect
->reloc_count
+1));
1673 if (asect
== obj_datasec (abfd
))
1674 return (sizeof (arelent
*) *
1675 ((exec_hdr(abfd
)->a_drsize
/ sizeof (struct reloc_info_extended
))
1678 if (asect
== obj_textsec (abfd
))
1679 return (sizeof (arelent
*) *
1680 ((exec_hdr(abfd
)->a_trsize
/ sizeof (struct reloc_info_extended
))
1683 bfd_error
= invalid_operation
;
1688 sunos4_reclaim_reloc (ignore_abfd
, section
)
1692 if (section
->relocation
) {
1693 free (section
->relocation
);
1694 section
->relocation
= NULL
;
1695 section
->reloc_count
= 0;
1701 sunos4_get_lineno(ignore_abfd
, ignore_symbol
)
1703 generic_symbol_type
*ignore_symbol
;
1705 return (alent
*)NULL
;
1709 sunos4_print_symbol(ignore_abfd
, file
, symbol
, how
)
1713 bfd_print_symbol_enum_type how
;
1716 case bfd_print_symbol_name_enum
:
1717 fprintf(file
,"%s", symbol
->name
);
1719 case bfd_print_symbol_type_enum
:
1720 fprintf(file
,"%4x %2x %2x",(unsigned)(aout_symbol(symbol
)->desc
& 0xffff),
1721 (unsigned)( aout_symbol(symbol
)->other
& 0xff),
1722 (unsigned)(aout_symbol(symbol
)->type
));
1724 case bfd_print_symbol_all_enum
:
1726 char *section_name
= symbol
->section
== (asection
*)NULL
?
1727 "*abs" : symbol
->section
->name
;
1729 bfd_print_symbol_vandf((void *)file
,symbol
);
1731 fprintf(file
," %-5s %04x %02x %02x %s",
1733 (unsigned)(aout_symbol(symbol
)->desc
& 0xffff),
1734 (unsigned)(aout_symbol(symbol
)->other
& 0xff),
1735 (unsigned)(aout_symbol(symbol
)->type
& 0xff),
1741 /* Once we know all the stuff that could be consed, we know how to clean
1742 it up. So why don't we? */
1745 sunos4_close_and_cleanup (abfd
)
1748 if (!bfd_read_p (abfd
))
1749 switch (abfd
->format
) {
1751 if (!_bfd_write_archive_contents (abfd
)) return false; break;
1753 if (!sunos4_write_object_contents (abfd
)) return false; break;
1754 default: bfd_error
= invalid_operation
; return false;
1757 #define cleaner(ptr) if (abfd->ptr) free (abfd->ptr)
1760 if (abfd
->my_archive
)
1768 provided a bfd, a section and an offset into the section, calculate
1769 and return the name of the source file and the line nearest to the
1774 sunos4_find_nearest_line(abfd
,
1785 char **filename_ptr
;
1786 char **functionname_ptr
;
1787 unsigned int *line_ptr
;
1789 /* Run down the file looking for the filename, function and linenumber */
1791 static char buffer
[100];
1792 bfd_vma high_line_vma
= ~0;
1793 bfd_vma low_func_vma
= 0;
1795 *filename_ptr
= abfd
->filename
;
1796 *functionname_ptr
= 0;
1798 if (symbols
!= (asymbol
**)NULL
) {
1799 for (p
= symbols
; *p
; p
++) {
1800 aout_symbol_type
*q
= (aout_symbol_type
*)(*p
);
1803 *filename_ptr
= q
->symbol
.name
;
1804 if (obj_textsec(abfd
) != section
) {
1812 /* We'll keep this if it resolves nearer than the one we have already */
1813 if (q
->symbol
.value
>= offset
&&
1814 q
->symbol
.value
< high_line_vma
) {
1815 *line_ptr
= q
->desc
;
1816 high_line_vma
= q
->symbol
.value
;
1821 /* We'll keep this if it is nearer than the one we have already */
1822 if (q
->symbol
.value
>= low_func_vma
&&
1823 q
->symbol
.value
<= offset
) {
1824 low_func_vma
= q
->symbol
.value
;
1825 func
= (asymbol
*)q
;
1827 if (*line_ptr
&& func
) {
1828 char *function
= func
->name
;
1830 strncpy(buffer
, function
, sizeof(buffer
)-1);
1831 buffer
[sizeof(buffer
)-1] = 0;
1832 /* Have to remove : stuff */
1833 p
= strchr(buffer
,':');
1834 if (p
!= NULL
) {*p
= NULL
; }
1835 *functionname_ptr
= buffer
;
1849 bfd_target aoutvec
=
1851 "a.out-generic-big", /* name */
1852 bfd_target_aout_flavour_enum
,
1853 true, /* target byte order */
1854 true, /* target headers byte order */
1855 (HAS_RELOC
| EXEC_P
| /* object flags */
1856 HAS_LINENO
| HAS_DEBUG
|
1857 HAS_SYMS
| HAS_LOCALS
| DYNAMIC
| WP_TEXT
| D_PAGED
),
1858 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
1859 0, /* valid reloc types */
1860 ' ', /* ar_pad_char */
1861 16, /* ar_max_namelen */
1862 sunos4_close_and_cleanup
, /* _close_and_cleanup */
1863 sunos4_set_section_contents
, /* bfd_set_section_contents */
1864 sunos4_get_section_contents
, /* bfd_get_section_contents */
1865 sunos4_new_section_hook
, /* new_section_hook */
1866 sunos4_core_file_failing_command
, /* _core_file_failing_command */
1867 sunos4_core_file_failing_signal
, /* _core_file_failing_signal */
1868 sunos4_core_file_matches_executable_p
, /* _core_file_matches_ex...p */
1870 bfd_slurp_bsd_armap
, /* bfd_slurp_armap */
1871 bfd_true
, /* bfd_slurp_extended_name_table */
1872 bfd_bsd_truncate_arname
, /* bfd_truncate_arname */
1874 sunos4_get_symtab_upper_bound
, /* get_symtab_upper_bound */
1875 sunos4_get_symtab
, /* canonicalize_symtab */
1876 sunos4_reclaim_symbol_table
, /* bfd_reclaim_symbol_table */
1877 sunos4_get_reloc_upper_bound
, /* get_reloc_upper_bound */
1878 sunos4_canonicalize_reloc
, /* bfd_canonicalize_reloc */
1879 sunos4_reclaim_reloc
, /* bfd_reclaim_reloc */
1880 sunos4_get_symcount_upper_bound
, /* bfd_get_symcount_upper_bound */
1881 sunos4_get_first_symbol
, /* bfd_get_first_symbol */
1882 sunos4_get_next_symbol
, /* bfd_get_next_symbol */
1883 sunos4_classify_symbol
, /* bfd_classify_symbol */
1884 sunos4_symbol_hasclass
, /* bfd_symbol_hasclass */
1885 sunos4_symbol_name
, /* bfd_symbol_name */
1886 sunos4_symbol_value
, /* bfd_symbol_value */
1888 _do_getblong
, _do_putblong
, _do_getbshort
, _do_putbshort
, /* data */
1889 _do_getblong
, _do_putblong
, _do_getbshort
, _do_putbshort
, /* hdrs */
1891 {_bfd_dummy_target
, sunos4_object_p
, /* bfd_check_format */
1892 bfd_generic_archive_p
, sunos4_core_file_p
},
1893 {bfd_false
, sunos4_mkobject
, /* bfd_zxset_format */
1894 _bfd_generic_mkarchive
, bfd_false
},
1895 sunos4_make_empty_symbol
,
1896 sunos4_print_symbol
,
1898 sunos4_set_arch_mach
,
1900 bfd_generic_openr_next_archived_file
,
1901 sunos4_find_nearest_line
, /* bfd_find_nearest_line */
1902 bfd_generic_stat_arch_elt
/* bfd_stat_arch_elt */