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.1.1 1991/03/21 21:11:23 gumby
24 * Back from Intel with Steve
26 * Revision 1.1 1991/03/21 21:11:23 gumby
29 * Revision 1.2 1991/03/15 18:16:52 rich
30 * *** empty log message ***
32 * Revision 1.12 1991/03/10 19:11:41 rich
34 * bfd.c coff-code.h libbfd.c libbfd.h srec.c sunos.c
36 * Working bugs out of coff support.
38 * Revision 1.11 1991/03/09 03:40:04 rich
40 * Makefile b.out.c liba.out.h libbfd.c sunos.c sysdep.h
42 * Changes dictated by porting binutils.
44 * Revision 1.10 1991/03/08 07:52:02 sac
45 * Reinstalled things which went away after latest merge from Intel.
47 * Fixed a couple of problems in symbol handling too.
49 * Revision 1.9 1991/03/08 04:18:16 rich
50 * *** empty log message ***
52 * Revision 1.8 1991/03/07 21:57:26 sac
53 * Moved type info out of the asymbol into the private space.
54 * Cleaned up C++ stuff
56 * Revision 1.7 1991/03/06 21:49:02 sac
57 * Modified bfd_find_filename to return name of function too.
59 * Revision 1.6 1991/03/06 02:19:36 sac
60 * Moved howto table, added support for constructor sections and provided
61 * sunos4_find_nearest_line
63 * Revision 1.5 1991/03/05 16:25:44 sac
64 * Modified howto vector to include inplace and mask fields.
68 #define TARGET_BYTE_ORDER_BIG_P 1
69 #define TARGET TARGET_SPARC
83 typedef void generic_symbol_type;
84 /* These values are correct for the SPARC. I dunno about anything else */
85 #define PAGE_SIZE 0x02000
86 #define SEGMENT_SIZE PAGE_SIZE
87 #define TEXT_START_ADDR PAGE_SIZE
88 #include "a.out.gnu.h"
91 #include "liba.out.h" /* BFD a.out internal data structures */
93 #include "a.out.sun4.h"
95 #define CTOR_TABLE_RELOC_IDX 2
96 static reloc_howto_type howto_table[] =
98 /* type rs size bsz pcrel bitpos abs ovrf sf name partial inplace mask*/
99 { (unsigned int) RELOC_8, 0, 0, 8, false, 0, true, true,0,"8", false, 0x000000ff},
100 { (unsigned int) RELOC_16, 0, 1, 16, false, 0, true, true,0,"16", false, 0x0000ffff},
101 { (unsigned int) RELOC_32, 0, 2, 32, false, 0, true, true,0,"32", false, 0xffffffff},
102 { (unsigned int) RELOC_DISP8, 0, 0, 8, true, 0, false, true,0,"DISP8", false, 0x000000ff},
103 { (unsigned int) RELOC_DISP16, 0, 1, 16, true, 0, false, true,0,"DISP16", false, 0x0000ffff},
104 { (unsigned int) RELOC_DISP32, 0, 2, 32, true, 0, false, true,0,"DISP32", false, 0xffffffff},
105 { (unsigned int) RELOC_WDISP30,2, 2, 30, true, 0, false, true,0,"WDISP30", false, 0x3fffffff},
106 { (unsigned int) RELOC_WDISP22,2, 2, 22, true, 0, false, true,0,"WDISP22", false, 0x003fffff},
107 { (unsigned int) RELOC_HI22, 10, 2, 22, false, 0, false, true,0,"HI22", false, 0x003fffff},
108 { (unsigned int) RELOC_22, 0, 2, 22, false, 0, false, true,0,"22", false, 0x003fffff},
109 { (unsigned int) RELOC_13, 0, 2, 13, false, 0, false, true,0,"13", false, 0x00001fff},
110 { (unsigned int) RELOC_LO10, 0, 2, 10, false, 0, false, true,0,"LO10", false, 0x000003ff},
111 { (unsigned int) RELOC_SFA_BASE,0, 2, 32, false, 0, false, true,0,"SFA_BASE", false, 0xffffffff},
112 { (unsigned int) RELOC_SFA_OFF13,0,2, 32, false, 0, false, true,0,"SFA_OFF13",false, 0xffffffff},
113 { (unsigned int) RELOC_BASE10, 0, 2, 16, false, 0, false, true,0,"BASE10", false, 0x0000ffff},
114 { (unsigned int) RELOC_BASE13, 0, 2, 13, false, 0, false, true,0,"BASE13", false, 0x00001fff},
115 { (unsigned int) RELOC_BASE22, 0, 2, 0, false, 0, false, true,0,"BASE22", false, 0x00000000},
116 { (unsigned int) RELOC_PC10, 0, 2, 10, false, 0, false, true,0,"PC10", false, 0x000003ff},
117 { (unsigned int) RELOC_PC22, 0, 2, 22, false, 0, false, true,0,"PC22", false, 0x003fffff},
118 { (unsigned int) RELOC_JMP_TBL,0, 2, 32, false, 0, false, true,0,"JMP_TBL", false, 0xffffffff},
119 { (unsigned int) RELOC_SEGOFF16,0, 2, 0, false, 0, false, true,0,"SEGOFF16", false, 0x00000000},
120 { (unsigned int) RELOC_GLOB_DAT,0, 2, 0, false, 0, false, true,0,"GLOB_DAT", false, 0x00000000},
121 { (unsigned int) RELOC_JMP_SLOT,0, 2, 0, false, 0, false, true,0,"JMP_SLOT", false, 0x00000000},
122 { (unsigned int) RELOC_RELATIVE,0, 2, 0, false, 0, false, true,0,"RELATIVE", false, 0x00000000},
123 { (unsigned int) RELOC_JUMPTARG,2, 13, 16, true, 0, false, true,0,"JUMPTARG", false, 0x0000ffff},
124 { (unsigned int) RELOC_CONST, 0, 13, 16, false, 0, false, true,0,"CONST", false, 0x0000ffff},
125 { (unsigned int) RELOC_CONSTH, 16, 13, 16, false, 0, false, true,0,"CONSTH", false, 0x0000ffff},
130 PROTO (static void, swap_exec_header, (bfd *abfd, struct exec *execp));
131 PROTO (void , sunos4_write_syms, ());
132 PROTO (static boolean,sunos4_squirt_out_relocs,(bfd *abfd, asection *section));
134 /* Steve wants some way to frob this stuff from Saber while he's debugging
135 ld, so we have these funny shadow functions */
136 /* ZMAGIC's start at 0 (making the exec part of the text section),
137 other formats start after the exec
139 unsigned int n_txtoff(ptr)
141 {return N_MAGIC(*ptr)== ZMAGIC ? 0: sizeof(struct exec);}
143 unsigned int n_datoff(ptr)
145 {return n_txtoff(ptr) + ptr->a_text;}
147 unsigned int n_treloff(ptr)
149 {return n_datoff(ptr) + ptr->a_data;}
151 unsigned int n_dreloff(ptr)
153 {return n_treloff(ptr) + ptr->a_trsize;}
155 unsigned int n_symoff(ptr)
157 {return n_dreloff(ptr) + ptr->a_drsize;}
159 unsigned int n_stroff(ptr)
161 {return n_symoff(ptr) + ptr->a_syms;}
163 unsigned int n_badmag(ptr)
166 switch (N_MAGIC(*ptr)) {
167 case OMAGIC: case NMAGIC: case ZMAGIC: return 0;
174 sunos4_object_p (abfd)
178 struct exec anexec; /* save consing when you don't have to. */
179 struct exec *execp = &anexec;
182 bfd_error = system_call_error;
184 if (bfd_read ((void *)&magic, 1, sizeof (magic), abfd) != sizeof (magic))
186 magic = bfd_h_getlong (abfd, &magic);
188 /* Baroque syntax to mask deficiencies of the Sun compiler */
189 /* if (N_BADMAG (*((struct exec *) &magic))) return 0; */
190 if (n_badmag ((struct exec *) &magic)) return 0;
192 if (bfd_seek (abfd, 0L, SEEK_SET) < 0) return 0;
194 if (bfd_read ((void *) execp, 1, sizeof (struct exec), abfd)
195 != sizeof (struct exec)) {
196 bfd_error = wrong_format;
200 /* Use an intermediate variable for clarity */
201 rawptr = (void *) zalloc (sizeof (struct sunexdata) + sizeof (struct exec));
203 if (rawptr == NULL) {
204 bfd_error = no_memory;
208 abfd->tdata =(void *)( (struct sunexdata *) rawptr);
210 (struct exec *) ((char *)rawptr + sizeof (struct sunexdata));
212 swap_exec_header (abfd, execp);
213 memcpy (exec_hdr (abfd), execp, sizeof (struct exec));
215 /* Set the file flags */
216 abfd->flags = NO_FLAGS;
217 if (execp->a_drsize || execp->a_trsize)
218 abfd->flags |= HAS_RELOC;
220 abfd->flags |= EXEC_P;
222 abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS;
225 if (N_MAGIC (anexec) == ZMAGIC) abfd->flags |= D_PAGED;
226 if (N_MAGIC (anexec) == NMAGIC) abfd->flags |= WP_TEXT;
228 /* Determine the architecture and machine type of the object file. */
229 abfd->obj_arch = bfd_arch_unknown; /* Default values */
230 abfd->obj_machine = 0;
231 switch (N_MACHTYPE (anexec)) {
237 abfd->obj_arch = bfd_arch_m68k;
238 abfd->obj_machine = 68010;
242 abfd->obj_arch = bfd_arch_m68k;
243 abfd->obj_machine = 68020;
247 abfd->obj_arch = bfd_arch_sparc;
251 abfd->obj_arch = bfd_arch_i386;
255 abfd->obj_arch = bfd_arch_a29k;
259 abfd->obj_arch = bfd_arch_obscure;
263 bfd_get_start_address (abfd) = execp->a_entry;
265 /* Remember the positions of the string table and symbol table. */
266 obj_str_filepos (abfd) = n_stroff (&anexec);
267 obj_sym_filepos (abfd) = n_symoff (&anexec);
269 /* create the sections. This is raunchy, but bfd_close wants to reclaim
271 obj_textsec (abfd) = (asection *)NULL;
272 obj_datasec (abfd) = (asection *)NULL;
273 obj_bsssec (abfd) = (asection *)NULL;
274 obj_aout_symbols(abfd) = (aout_symbol_type *)NULL;
275 (void)bfd_make_section(abfd, ".text");
276 (void)bfd_make_section(abfd, ".data");
277 (void)bfd_make_section(abfd, ".bss");
279 obj_datasec (abfd)->size = execp->a_data;
280 obj_bsssec (abfd)->size = execp->a_bss;
281 obj_textsec (abfd)->size = execp->a_text;
282 obj_datasec (abfd)->vma = N_DATADDR(anexec);
283 obj_bsssec (abfd)->vma = N_BSSADDR(anexec);
284 obj_textsec (abfd)->vma = N_TXTADDR(anexec);
286 obj_textsec (abfd)->filepos = n_txtoff(&anexec);
287 obj_datasec (abfd)->filepos = n_datoff(&anexec);
289 obj_textsec (abfd)->rel_filepos = n_treloff(&anexec);
290 obj_datasec (abfd)->rel_filepos = n_dreloff(&anexec);
292 obj_textsec (abfd)->flags =
293 (execp->a_trsize != 0 ?
294 (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_HAS_CONTENTS) :
295 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS));
296 obj_datasec (abfd)->flags =
297 (execp->a_drsize != 0 ?
298 (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_HAS_CONTENTS) :
299 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS));
300 obj_bsssec (abfd)->flags = SEC_ALLOC;
302 abfd->sections = obj_textsec (abfd);
303 obj_textsec (abfd)->next = obj_datasec (abfd);
304 obj_datasec (abfd)->next = obj_bsssec (abfd);
310 sunos4_mkobject (abfd)
315 bfd_error = system_call_error;
317 /* Use an intermediate variable for clarity */
318 rawptr = zalloc (sizeof (struct sunexdata) + sizeof (struct exec));
320 if (rawptr == NULL) {
321 bfd_error = no_memory;
325 abfd->tdata = (void *)((struct sunexdata *) rawptr);
326 exec_hdr (abfd) = (struct exec *) (rawptr + sizeof (struct sunexdata));
328 /* For simplicity's sake we just make all the sections right here. */
330 obj_textsec (abfd) = (asection *)NULL;
331 obj_datasec (abfd) = (asection *)NULL;
332 obj_bsssec (abfd) = (asection *)NULL;
333 bfd_make_section (abfd, ".text");
334 bfd_make_section (abfd, ".data");
335 bfd_make_section (abfd, ".bss");
340 /* Keep track of machine architecture and machine type for a.out's.
341 Return the machine_type for a particular arch&machine, or M_UNKNOWN
342 if that exact arch&machine can't be represented in a.out format.
344 If the architecture is understood, machine type 0 (default) should
345 always be understood. */
347 static enum machine_type
348 aout_machine_type (arch, machine)
349 enum bfd_architecture arch;
350 unsigned long machine;
352 enum machine_type arch_flags;
354 arch_flags = M_UNKNOWN;
358 if (machine == 0) arch_flags = M_SPARC;
363 case 0: arch_flags = M_UNKNOWN; break;
364 case 68000: arch_flags = M_UNKNOWN; break;
365 case 68010: arch_flags = M_68010; break;
366 case 68020: arch_flags = M_68020; break;
367 default: arch_flags = M_UNKNOWN; break;
372 if (machine == 0) arch_flags = M_386;
376 if (machine == 0) arch_flags = M_29K;
380 arch_flags = M_UNKNOWN;
387 sunos4_set_arch_mach (abfd, arch, machine)
389 enum bfd_architecture arch;
390 unsigned long machine;
392 abfd->obj_arch = arch;
393 abfd->obj_machine = machine;
394 if (arch != bfd_arch_unknown &&
395 aout_machine_type (arch, machine) == M_UNKNOWN)
396 return false; /* We can't represent this type */
397 return true; /* We're easy ... */
401 sunos4_write_object_contents (abfd)
405 struct exec *execp = exec_hdr (abfd);
409 /* Magic number, maestro, please! */
410 switch (bfd_get_architecture(abfd)) {
412 switch (bfd_get_machine(abfd)) {
414 N_SET_MACHTYPE(*execp, M_68010);
418 N_SET_MACHTYPE(*execp, M_68020);
423 N_SET_MACHTYPE(*execp, M_SPARC);
426 N_SET_MACHTYPE(*execp, M_386);
429 N_SET_MACHTYPE(*execp, M_29K);
432 N_SET_MACHTYPE(*execp, M_UNKNOWN);
434 execp->a_text = obj_textsec (abfd)->size;
435 N_SET_MAGIC (*execp, OMAGIC);
436 if (abfd->flags & D_PAGED) {
437 execp->a_text = obj_textsec (abfd)->size + sizeof(struct exec);
438 N_SET_MAGIC (*execp, ZMAGIC);
439 } else if (abfd->flags & WP_TEXT) {
440 N_SET_MAGIC (*execp, NMAGIC);
442 N_SET_FLAGS (*execp, 0x1); /* copied from ld.c; who the hell knows? */
444 if (abfd->flags & D_PAGED)
446 data_pad = ((obj_datasec(abfd)->size + PAGE_SIZE -1)
447 & (- PAGE_SIZE)) - obj_datasec(abfd)->size;
449 if (data_pad > obj_bsssec(abfd)->size)
452 execp->a_bss = obj_bsssec(abfd)->size - data_pad;
453 execp->a_data = obj_datasec(abfd)->size + data_pad;
457 execp->a_data = obj_datasec (abfd)->size;
458 execp->a_bss = obj_bsssec (abfd)->size;
461 execp->a_syms = bfd_get_symcount (abfd) * sizeof (struct nlist);
462 execp->a_entry = bfd_get_start_address (abfd);
463 execp->a_trsize = ((obj_textsec (abfd)->reloc_count) *
464 sizeof (struct reloc_info_extended));
465 execp->a_drsize = ((obj_datasec (abfd)->reloc_count) *
466 sizeof (struct reloc_info_extended));;
468 swap_exec_header (abfd, execp);
470 bfd_seek (abfd, 0L, SEEK_SET);
471 bfd_write ((void *) execp, 1, sizeof (struct exec), abfd);
473 /* Now write out reloc info, followed by syms and strings */
475 if (bfd_get_symcount (abfd) != 0)
478 (long)(N_SYMOFF(*execp)), SEEK_SET);
480 sunos4_write_syms (abfd);
482 bfd_seek (abfd, (long)(N_TROFF(*execp)), SEEK_SET);
484 if (!sunos4_squirt_out_relocs (abfd, obj_textsec (abfd))) return false;
485 bfd_seek (abfd, (long)(N_DROFF(*execp)), SEEK_SET);
487 if (!sunos4_squirt_out_relocs (abfd, obj_datasec (abfd))) return false;
493 swap_exec_header (abfd, execp)
497 if (bfd_header_twiddle_required(abfd)) {
498 /* execp->a_info = bfd_h_getlong (abfd, &execp->a_info); */
499 *(unsigned long *) execp =
500 bfd_h_getlong (abfd, (unsigned long *) execp);
501 execp->a_text = bfd_h_getlong (abfd, &execp->a_text);
502 execp->a_data = bfd_h_getlong (abfd, &execp->a_data);
503 execp->a_bss = bfd_h_getlong (abfd, &execp->a_bss);
504 execp->a_syms = bfd_h_getlong (abfd, &execp->a_syms);
505 execp->a_entry = bfd_h_getlong (abfd, &execp->a_entry);
506 execp->a_trsize = bfd_h_getlong (abfd, &execp->a_trsize);
507 execp->a_drsize = bfd_h_getlong (abfd, &execp->a_drsize);
509 } /* swap_exec_header() */
513 #define CORE_MAGIC 0x080456
514 #define CORE_NAMELEN 16
516 /* The core structure is taken from the Sun documentation.
517 Unfortunately, they don't document the FPA structure, or at least I
518 can't find it easily. Fortunately the core header contains its own
519 length. So this shouldn't cause problems, except for c_ucode, which
520 so far we don't use but is easy to find with a little arithmetic. */
522 /* But the reg structure can be gotten from the SPARC processor handbook.
523 This really should be in a GNU include file though so that gdb can use
547 /* Taken from Sun documentation: */
550 int c_magic; /* Corefile magic number */
551 int c_len; /* Sizeof (struct core) */
552 struct regs c_regs; /* General purpose registers */
553 struct exec c_aouthdr; /* A.out header */
554 int c_signo; /* Killing signal, if any */
555 int c_tsize; /* Text size (bytes) */
556 int c_dsize; /* Data size (bytes) */
557 int c_ssize; /* Stack size (bytes) */
558 char c_cmdname[CORE_NAMELEN + 1]; /* Command name */
559 double fp_stuff[1]; /* external FPU state (size unknown by us) */
560 /* The type "double" is critical here, for alignment.
561 SunOS declares a struct here, but the struct's
562 alignment is double since it contains doubles. */
563 int c_ucode; /* Exception no. from u_code */
564 /* (this member not accessible by name since we don't
565 portably know the size of fp_stuff.) */
568 /* Supposedly the user stack grows downward from the bottom of kernel memory.
569 Presuming that this remains true, this definition will work. */
570 #define USRSTACK (-(128*1024*1024))
572 PROTO (static void, swapcore, (bfd *abfd, struct core *core));
574 /* need this cast b/c ptr is really void * */
575 #define core_hdr(bfd) (((struct suncordata *) (bfd->tdata))->hdr)
576 #define core_datasec(bfd) (((struct suncordata *) ((bfd)->tdata))->data_section)
577 #define core_stacksec(bfd) (((struct suncordata*)((bfd)->tdata))->stack_section)
578 #define core_regsec(bfd) (((struct suncordata *) ((bfd)->tdata))->reg_section)
579 #define core_regsec2(bfd) (((struct suncordata *) ((bfd)->tdata))->reg2_section)
581 /* These are stored in the bfd's tdata */
583 struct core *hdr; /* core file header */
584 asection *data_section;
585 asection *stack_section;
586 asection *reg_section;
587 asection *reg2_section;
591 sunos4_core_file_p (abfd)
594 /* includes redundent variables for code clarity */
600 bfd_error = system_call_error;
602 if (bfd_read ((void *)&core_mag, 1, sizeof (int), abfd) != sizeof (int))
604 core_mag = bfd_h_getlong(abfd, &core_mag);
606 if (core_mag != CORE_MAGIC) return 0;
608 /* SunOS core headers can vary in length; second word is size; */
609 if (bfd_read ((void *)&core_size, 1, sizeof (int), abfd) != sizeof (int))
611 core_size = bfd_h_getlong(abfd, &core_size);
613 if (bfd_seek (abfd, 0L, SEEK_SET) < 0) return 0;
615 rawptr = zalloc (core_size + sizeof (struct suncordata));
616 if (rawptr == NULL) {
617 bfd_error = no_memory;
621 core = (struct core *) (rawptr + sizeof (struct suncordata));
623 if ((bfd_read ((void *) core, 1, core_size, abfd)) != core_size) {
624 bfd_error = system_call_error;
625 free ((void *)rawptr);
629 swapcore (abfd, core);
630 abfd->tdata = (void *)((struct suncordata *) rawptr);
631 core_hdr (abfd) = core;
633 /* create the sections. This is raunchy, but bfd_close wants to reclaim
635 core_stacksec (abfd) = (asection *) zalloc (sizeof (asection));
636 if (core_stacksec (abfd) == NULL) {
638 bfd_error = no_memory;
639 free ((void *)rawptr);
642 core_datasec (abfd) = (asection *) zalloc (sizeof (asection));
643 if (core_datasec (abfd) == NULL) {
645 free ((void *)core_stacksec (abfd));
648 core_regsec (abfd) = (asection *) zalloc (sizeof (asection));
649 if (core_regsec (abfd) == NULL) {
651 free ((void *)core_datasec (abfd));
654 core_regsec2 (abfd) = (asection *) zalloc (sizeof (asection));
655 if (core_regsec2 (abfd) == NULL) {
656 free ((void *)core_regsec (abfd));
660 core_stacksec (abfd)->name = ".stack";
661 core_datasec (abfd)->name = ".data";
662 core_regsec (abfd)->name = ".reg";
663 core_regsec2 (abfd)->name = ".reg2";
665 core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD;
666 core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD;
667 core_regsec (abfd)->flags = SEC_ALLOC;
668 core_regsec2 (abfd)->flags = SEC_ALLOC;
670 core_stacksec (abfd)->size = core->c_ssize;
671 core_datasec (abfd)->size = core->c_dsize;
672 core_regsec (abfd)->size = (sizeof core->c_regs);
673 /* Float regs take up end of struct, except c_ucode. */
674 core_regsec2 (abfd)->size = core_size - (sizeof core->c_ucode) -
675 (file_ptr)(((struct core *)0)->fp_stuff);
677 core_stacksec (abfd)->vma = (USRSTACK - core->c_ssize);
678 core_datasec (abfd)->vma = N_DATADDR(core->c_aouthdr);
679 core_regsec (abfd)->vma = -1;
680 core_regsec2 (abfd)->vma = -1;
682 core_stacksec (abfd)->filepos = core->c_len + core->c_dsize;
683 core_datasec (abfd)->filepos = core->c_len;
684 /* In file header: */
685 core_regsec (abfd)->filepos = (file_ptr)(&((struct core *)0)->c_regs);
686 core_regsec2 (abfd)->filepos = (file_ptr)(((struct core *)0)->fp_stuff);
688 /* Align to word at least */
689 core_stacksec (abfd)->alignment_power = 2;
690 core_datasec (abfd)->alignment_power = 2;
691 core_regsec (abfd)->alignment_power = 2;
692 core_regsec2 (abfd)->alignment_power = 2;
694 abfd->sections = core_stacksec (abfd);
695 core_stacksec (abfd)->next = core_datasec (abfd);
696 core_datasec (abfd)->next = core_regsec (abfd);
697 core_regsec (abfd)->next = core_regsec2 (abfd);
699 abfd->section_count = 4;
705 sunos4_core_file_failing_command (abfd)
708 return core_hdr (abfd)->c_cmdname;
712 sunos4_core_file_failing_signal (abfd)
715 return core_hdr (abfd)->c_signo;
719 sunos4_core_file_matches_executable_p (core_bfd, exec_bfd)
720 bfd *core_bfd, *exec_bfd;
722 if (core_bfd->xvec != exec_bfd->xvec) {
723 bfd_error = system_call_error;
727 return (bcmp (&core_hdr (core_bfd), &exec_hdr (exec_bfd),
728 sizeof (struct exec)) == 0) ? true : false;
731 /* byte-swap core structure */
733 swapcore (abfd, core)
737 if (bfd_header_twiddle_required(abfd)) {
738 core->c_magic = bfd_h_getlong (abfd, &core->c_magic);
739 core->c_len = bfd_h_getlong (abfd, &core->c_len);
741 swap_exec_header (abfd, &(core->c_aouthdr));
742 core->c_signo = bfd_h_getlong (abfd, &core->c_signo);
743 core->c_tsize = bfd_h_getlong (abfd, &core->c_tsize);
744 core->c_dsize = bfd_h_getlong (abfd, &core->c_dsize);
745 core->c_ssize = bfd_h_getlong (abfd, &core->c_ssize);
746 core->c_ucode = bfd_h_getlong (abfd, &core->c_ucode);
747 /* I don't understand how to swap an FP register */
751 /** exec and core file sections */
754 sunos4_new_section_hook (abfd, newsect)
758 /* align to double at least */
759 newsect->alignment_power = 3;
761 if (bfd_get_format (abfd) == bfd_object) {
762 if (obj_textsec(abfd) == NULL && !strcmp(newsect->name, ".text")) {
763 obj_textsec(abfd)= newsect;
767 if (obj_datasec(abfd) == NULL && !strcmp(newsect->name, ".data")) {
768 obj_datasec(abfd) = newsect;
772 if (obj_bsssec(abfd) == NULL && !strcmp(newsect->name, ".bss")) {
773 obj_bsssec(abfd) = newsect;
778 #if 0 /* FIXME -- this is temporary for steve */
779 bfd_error = invalid_operation;
784 /* We allow more than three sections internally */
789 sunos4_set_section_contents (abfd, section, location, offset, count)
792 unsigned char *location;
796 if (abfd->output_has_begun == false)
797 { /* set by bfd.c handler */
798 if ((obj_textsec (abfd) == NULL) || (obj_datasec (abfd) == NULL)
801 (obj_textsec (abfd)->size == 0) || (obj_datasec (abfd)->size=
805 bfd_error = invalid_operation;
811 if (abfd->flags & D_PAGED)
813 obj_textsec (abfd)->filepos = sizeof(struct exec);
814 obj_datasec(abfd)->filepos = obj_textsec (abfd)->size;
819 obj_textsec (abfd)->filepos = sizeof(struct exec);
820 obj_datasec(abfd)->filepos = obj_textsec(abfd)->filepos + obj_textsec (abfd)->size;
824 /* regardless, once we know what we're doing, we might as well get going */
826 bfd_seek (abfd, section->filepos + offset, SEEK_SET);
829 return (bfd_write ((void *)location, 1, count, abfd) == count) ? true : false;
834 sunos4_get_section_contents (abfd, section, location, offset, count)
842 if (offset >= section->size) return false;
844 bfd_seek (abfd, section->filepos + offset, SEEK_SET);
846 return (bfd_read (location, 1, count, abfd) == count) ? true:false;
852 /* Classify stabs symbols */
855 #define sym_in_text_section(sym) \
856 (((sym)->n_type & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_TEXT)
858 #define sym_in_data_section(sym) \
859 (((sym)->n_type & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_DATA)
861 #define sym_in_bss_section(sym) \
862 (((sym)->n_type & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_BSS)
864 /* Symbol is undefined if type is N_UNDF|N_EXT and if it has
865 zero in the "value" field. Nonzeroes there are fortrancommon
867 #define sym_is_undefined(sym) \
868 ((sym)->n_type == (N_UNDF | N_EXT) && (sym)->n_value == 0)
870 /* Symbol is a global definition if N_EXT is on and if it has
871 a nonzero type field. */
872 #define sym_is_global_defn(sym) \
873 (((sym)->n_type & N_EXT) && (sym)->n_type & N_TYPE)
875 /* Symbol is debugger info if any bits outside N_TYPE or N_EXT
877 #define sym_is_debugger_info(sym) \
878 ((sym)->n_type & ~(N_EXT | N_TYPE))
880 #define sym_is_fortrancommon(sym) \
881 (((sym)->n_type == (N_EXT)) && (sym)->n_value != 0)
883 /* Symbol is absolute if it has N_ABS set */
884 #define sym_is_absolute(sym) \
885 (((sym)->n_type & N_TYPE)== N_ABS)
888 #define sym_is_indirect(sym) \
889 (((sym)->n_type & N_ABS)== N_ABS)
891 /* Only in their own functions for ease of debugging; when sym flags have
892 stabilised these should be inlined into their (single) caller */
895 translate_from_native_sym_flags (sym_pointer, cache_ptr, abfd)
896 struct nlist *sym_pointer;
897 aout_symbol_type *cache_ptr;
900 switch (cache_ptr->type & N_TYPE) {
906 asection *section = bfd_make_section(abfd,
907 cache_ptr->symbol.name);
908 arelent_chain *reloc = (arelent_chain *)malloc(sizeof(arelent_chain));
910 switch ( (cache_ptr->type & N_TYPE) ) {
912 reloc->relent.section = (asection *)NULL;
913 cache_ptr->symbol.section = (asection *)NULL;
916 reloc->relent.section = (asection *)obj_textsec(abfd);
917 cache_ptr->symbol.value -= reloc->relent.section->vma;
920 reloc->relent.section = (asection *)obj_datasec(abfd);
921 cache_ptr->symbol.value -= reloc->relent.section->vma;
924 reloc->relent.section = (asection *)obj_bsssec(abfd);
925 cache_ptr->symbol.value -= reloc->relent.section->vma;
928 cache_ptr->symbol.section = reloc->relent.section;
929 reloc->relent.addend = cache_ptr->symbol.value ;
931 We modify the symbol to belong to a section depending upon the
932 name of the symbol - probably __CTOR__ or __DTOR__ but we don't
933 really care, and add to the size of the section to contain a
934 pointer to the symbol. Build a reloc entry to relocate to this
935 symbol attached to this section.
939 section->flags = SEC_CONSTRUCTOR;
940 section->reloc_count++;
941 section->alignment_power = 2;
942 reloc->relent.sym_ptr_ptr = (asymbol **)NULL;
943 reloc->next = section->constructor_chain;
944 section->constructor_chain = reloc;
945 reloc->relent.address = section->size;
946 section->size += sizeof(int *);
948 reloc->relent.howto = howto_table +CTOR_TABLE_RELOC_IDX;
949 cache_ptr->symbol.flags |= BSF_DEBUGGING ;
954 if (sym_is_debugger_info (sym_pointer)) {
955 cache_ptr->symbol.flags = BSF_DEBUGGING ;
956 /* Work out the section correct for this symbol */
957 switch (sym_pointer->n_type & N_TYPE)
961 cache_ptr->symbol.section = obj_textsec (abfd);
962 cache_ptr->symbol.value -= obj_textsec(abfd)->vma;
965 cache_ptr->symbol.value -= obj_datasec(abfd)->vma;
966 cache_ptr->symbol.section = obj_datasec (abfd);
969 cache_ptr->symbol.section = obj_bsssec (abfd);
970 cache_ptr->symbol.value -= obj_bsssec(abfd)->vma;
974 cache_ptr->symbol.section = 0;
979 if (sym_is_fortrancommon (sym_pointer))
981 cache_ptr->symbol.flags = BSF_FORT_COMM;
982 cache_ptr->symbol.section = (asection *)NULL;
985 if (sym_is_undefined (sym_pointer)) {
986 cache_ptr->symbol.flags = BSF_UNDEFINED;
988 else if (sym_is_global_defn (sym_pointer)) {
989 cache_ptr->symbol.flags = BSF_GLOBAL | BSF_EXPORT;
992 else if (sym_is_absolute (sym_pointer)) {
993 cache_ptr->symbol.flags = BSF_ABSOLUTE;
996 cache_ptr->symbol.flags = BSF_LOCAL;
999 /* In a.out, the value of a symbol is always relative to the
1000 * start of the file, if this is a data symbol we'll subtract
1001 * the size of the text section to get the section relative
1002 * value. If this is a bss symbol (which would be strange)
1003 * we'll subtract the size of the previous two sections
1004 * to find the section relative address.
1007 if (sym_in_text_section (sym_pointer)) {
1008 cache_ptr->symbol.value -= obj_textsec(abfd)->vma;
1009 cache_ptr->symbol.section = obj_textsec (abfd);
1011 else if (sym_in_data_section (sym_pointer)){
1012 cache_ptr->symbol.value -= obj_datasec(abfd)->vma;
1013 cache_ptr->symbol.section = obj_datasec (abfd);
1015 else if (sym_in_bss_section(sym_pointer)) {
1016 cache_ptr->symbol.section = obj_bsssec (abfd);
1017 cache_ptr->symbol.value -= obj_bsssec(abfd)->vma;
1020 cache_ptr->symbol.section = (asection *)NULL;
1021 cache_ptr->symbol.flags |= BSF_ABSOLUTE;
1028 translate_to_native_sym_flags (sym_pointer, cache_ptr_g, abfd)
1029 struct nlist *sym_pointer;
1030 generic_symbol_type *cache_ptr_g;
1033 asymbol *cache_ptr = (asymbol *)cache_ptr_g;
1035 /* FIXME check for wrigin bss */
1036 if (bfd_get_section(cache_ptr)) {
1037 if (bfd_get_output_section(cache_ptr) == obj_bsssec (abfd)) {
1038 sym_pointer->n_type |= N_BSS;
1040 else if (bfd_get_output_section(cache_ptr) == obj_datasec (abfd)) {
1041 sym_pointer->n_type |= N_DATA;
1043 else if (bfd_get_output_section(cache_ptr) == obj_textsec (abfd)) {
1044 sym_pointer->n_type |= N_TEXT;
1049 /* Turn the symbol from section relative to absolute again */
1050 sym_pointer->n_value +=
1051 cache_ptr->section->output_section->vma
1052 + cache_ptr->section->output_offset ;
1055 sym_pointer->n_type |= N_ABS;
1058 if (cache_ptr->flags & (BSF_FORT_COMM | BSF_UNDEFINED)) {
1059 sym_pointer->n_type = (N_UNDF | N_EXT);
1063 if (cache_ptr->flags & BSF_ABSOLUTE) {
1064 sym_pointer->n_type |= N_ABS;
1067 if (cache_ptr->flags & (BSF_GLOBAL | BSF_EXPORT)) {
1068 sym_pointer->n_type |= N_EXT;
1070 if (cache_ptr->flags & BSF_DEBUGGING) {
1071 sym_pointer->n_type = ((aout_symbol_type *)cache_ptr)->type;
1076 /* Native-level interface to symbols. */
1078 /* We read the symbols into a buffer, which is discarded when this
1079 function exits. We read the strings into a buffer large enough to
1080 hold them all plus all the cached symbol entries. */
1083 sunos4_make_empty_symbol (abfd)
1086 aout_symbol_type *new =
1087 (aout_symbol_type *)zalloc (sizeof (aout_symbol_type));
1088 new->symbol.the_bfd = abfd;
1090 return &new->symbol;
1094 sunos4_slurp_symbol_table (abfd)
1097 unsigned int symbol_count;
1102 aout_symbol_type *cached;
1104 /* If there's no work to be done, don't do any */
1105 if (obj_aout_symbols (abfd) != (aout_symbol_type *)NULL) return true;
1106 symbol_size = exec_hdr(abfd)->a_syms;
1107 if (symbol_size == 0) {
1108 bfd_error = no_symbols;
1112 bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET);
1113 if (bfd_read ((void *)&string_size, 4, 1, abfd) != 4)
1115 string_size = bfd_h_getlong (abfd, (unsigned char *)&string_size);
1117 symbol_count = symbol_size / sizeof (struct nlist);
1119 /* Malloc (should alloca) space for native symbols, and
1120 malloc space for string table and symbol cache. */
1122 syms = (struct nlist *) zalloc (symbol_size);
1124 bfd_error = no_memory;
1128 cached = (aout_symbol_type *) zalloc ((size_t)(string_size + 1 +
1129 (symbol_count * sizeof (aout_symbol_type))));
1130 if (cached == NULL) {
1131 bfd_error = no_memory;
1132 free ((void *)syms);
1136 strings = ((char *) cached) + (symbol_count * sizeof (aout_symbol_type));
1138 bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET);
1139 if (bfd_read ((void *)syms, 1, symbol_size, abfd) != symbol_size) {
1141 free ((void *)cached);
1146 bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET);
1147 if (bfd_read ((void *)strings, 1, string_size, abfd) != string_size) {
1151 /* OK, now walk the new symtable, cacheing symbol properties */
1153 register struct nlist *sym_pointer;
1154 register struct nlist *sym_end = syms + symbol_count;
1155 register aout_symbol_type *cache_ptr = cached;
1157 if (bfd_header_twiddle_required (abfd) == true) {
1158 /* run through the table and byte swap if needed */
1159 for (sym_pointer = syms; sym_pointer < sym_end; sym_pointer++) {
1160 sym_pointer->n_un.n_strx =
1161 bfd_h_get_x (abfd, &sym_pointer->n_un.n_strx);
1162 sym_pointer->n_desc =
1163 bfd_h_get_x (abfd, &sym_pointer->n_desc);
1164 sym_pointer->n_value =
1165 bfd_h_get_x (abfd, &sym_pointer->n_value);
1166 sym_pointer->n_other = (char)
1167 bfd_h_get_x(abfd, &sym_pointer->n_other);
1168 sym_pointer->n_type = (char)
1169 bfd_h_get_x(abfd, &sym_pointer->n_type);
1173 /* Run through table and copy values */
1174 for (sym_pointer = syms, cache_ptr = cached;
1175 sym_pointer < sym_end; sym_pointer++, cache_ptr++)
1177 cache_ptr->symbol.the_bfd = abfd;
1178 if (sym_pointer->n_un.n_strx)
1179 cache_ptr->symbol.name = sym_pointer->n_un.n_strx + strings;
1181 cache_ptr->symbol.name = (char *)NULL;
1182 cache_ptr->symbol.value = sym_pointer->n_value;
1183 cache_ptr->desc = sym_pointer->n_desc;
1184 cache_ptr->other = sym_pointer->n_other;
1185 cache_ptr->type = sym_pointer->n_type;
1186 cache_ptr->symbol.udata = 0;
1187 translate_from_native_sym_flags (sym_pointer, cache_ptr, abfd);
1192 obj_aout_symbols (abfd) = cached;
1193 bfd_get_symcount (abfd) = symbol_count;
1194 free ((void *)syms);
1201 sunos4_write_syms (abfd)
1204 unsigned int count ;
1205 asymbol **generic = bfd_get_outsymbols (abfd);
1207 unsigned int stindex = sizeof(stindex); /* initial string length */
1209 for (count = 0; count < bfd_get_symcount (abfd); count++) {
1210 asymbol *g = generic[count];
1214 unsigned int length = strlen(g->name) +1;
1215 bfd_h_putlong (abfd, stindex, (unsigned char *)&nsp.n_un.n_strx);
1219 bfd_h_putlong (abfd, 0, (unsigned char *)&nsp.n_un.n_strx);
1222 if (g->the_bfd->xvec->flavour == abfd->xvec->flavour)
1224 nsp.n_desc = aout_symbol( g)->desc;
1225 nsp.n_other = aout_symbol(g)->other;
1226 nsp.n_type = aout_symbol(g)->type;
1236 nsp.n_value = g->value;
1237 translate_to_native_sym_flags (&nsp, (generic_symbol_type *)g, abfd);
1240 bfd_h_putshort (abfd, nsp.n_desc, (unsigned char *)&nsp.n_desc);
1241 bfd_h_putlong (abfd, nsp.n_value, (unsigned char *)&nsp.n_value);
1242 bfd_write((void *)&nsp,1, sizeof(nsp), abfd);
1246 /* Now output the strings. Be sure to put string length into correct
1247 * byte ordering before writing it.
1249 bfd_h_putlong (abfd, stindex, (unsigned char *)&stindex);
1251 bfd_write((void *)&stindex, 1, sizeof(stindex), abfd);
1253 generic = bfd_get_outsymbols(abfd);
1254 for (count = 0; count < bfd_get_symcount(abfd); count++)
1256 asymbol *g = *(generic++);
1258 if (g->name != (char *)NULL)
1260 size_t length = strlen(g->name)+1;
1261 bfd_write((void *)g->name, 1, length, abfd);
1263 if ((g->flags & BSF_FAKE)==0) {
1264 g->name = itos(count); /* smash the generic symbol */
1271 sunos4_reclaim_symbol_table (abfd)
1276 if (!bfd_get_symcount (abfd)) return;
1278 for (section = abfd->sections;
1279 section != (asection *) NULL;
1280 section = section->next)
1281 if (section->relocation) {
1282 free ((void *)section->relocation);
1283 section->relocation = NULL;
1284 section->reloc_count = 0;
1287 bfd_get_symcount (abfd) = 0;
1288 free ((void *)obj_aout_symbols (abfd));
1289 obj_aout_symbols (abfd) = (aout_symbol_type *)NULL;
1293 sunos4_get_symtab_upper_bound (abfd)
1296 if (!sunos4_slurp_symbol_table (abfd)) return 0;
1298 return (bfd_get_symcount (abfd)+1) * (sizeof (aout_symbol_type *));
1302 sunos4_get_symtab (abfd, location)
1306 unsigned int counter = 0;
1307 aout_symbol_type *symbase;
1309 if (!sunos4_slurp_symbol_table (abfd)) return 0;
1311 for (symbase = obj_aout_symbols(abfd); counter++ < bfd_get_symcount (abfd);)
1312 *(location++) = (asymbol *)( symbase++);
1314 return bfd_get_symcount(abfd);
1318 /* Obsolete procedural interface; better to look at the cache directly */
1320 /* User should have checked the file flags; perhaps we should return
1321 BFD_NO_MORE_SYMBOLS if there are none? */
1324 sunos4_get_symcount_upper_bound (abfd)
1327 /* In case we're doing an output file or something...? */
1328 if (bfd_get_symcount (abfd)) return bfd_get_symcount (abfd);
1330 return (exec_hdr (abfd)->a_syms) / (sizeof (struct nlist));
1334 sunos4_get_first_symbol (ignore_abfd)
1341 sunos4_get_next_symbol (abfd, oidx)
1345 if (oidx == BFD_NO_MORE_SYMBOLS) return BFD_NO_MORE_SYMBOLS;
1346 return ++oidx >= bfd_get_symcount (abfd) ? BFD_NO_MORE_SYMBOLS : oidx;
1350 sunos4_symbol_name (abfd, idx)
1354 return (obj_aout_symbols (abfd) + idx)->symbol.name;
1358 sunos4_symbol_value (abfd, idx)
1362 return (obj_aout_symbols (abfd) + idx)->symbol.value;
1366 sunos4_classify_symbol (abfd, idx)
1370 aout_symbol_type *sym = obj_aout_symbols (abfd) + idx;
1372 if ((sym->symbol.flags & BSF_FORT_COMM) != 0) return bfd_symclass_fcommon;
1373 if ((sym->symbol.flags & BSF_GLOBAL) != 0) return bfd_symclass_global;
1374 if ((sym->symbol.flags & BSF_DEBUGGING) != 0) return bfd_symclass_debugger;
1375 if ((sym->symbol.flags & BSF_UNDEFINED) != 0) return bfd_symclass_undefined;
1377 return bfd_symclass_unknown;
1381 sunos4_symbol_hasclass (abfd, idx, class)
1386 aout_symbol_type *sym = obj_aout_symbols (abfd) + idx;
1388 case bfd_symclass_fcommon:
1389 return (sym->symbol.flags & BSF_FORT_COMM) ? true :false;
1390 case bfd_symclass_global:
1391 return (sym->symbol.flags & BSF_GLOBAL) ? true:false;
1392 case bfd_symclass_debugger:
1393 return (sym->symbol.flags & BSF_DEBUGGING) ? true:false;;
1394 case bfd_symclass_undefined:
1395 return (sym->symbol.flags & BSF_UNDEFINED) ? true:false;;
1396 default: return false;
1400 /** Some reloc hackery */
1404 sunos4_slurp_reloc_table (abfd, asect, symbols)
1411 struct reloc_info_extended *relocs;
1412 arelent *reloc_cache;
1414 if (asect->relocation) return true;
1416 if (asect->flags & SEC_CONSTRUCTOR) return true;
1418 if (asect == obj_datasec (abfd)) {
1419 reloc_size = exec_hdr(abfd)->a_drsize;
1423 if (asect == obj_textsec (abfd)) {
1424 reloc_size = exec_hdr(abfd)->a_trsize;
1428 bfd_error = invalid_operation;
1432 bfd_seek (abfd, asect->rel_filepos, SEEK_SET);
1433 count = reloc_size / sizeof (struct reloc_info_extended);
1435 relocs = (struct reloc_info_extended *) malloc (reloc_size);
1437 bfd_error = no_memory;
1440 reloc_cache = (arelent *) zalloc ((size_t)(count * sizeof (arelent)));
1441 if (reloc_cache == (arelent *)NULL) {
1442 free ((void *)relocs);
1443 bfd_error = no_memory;
1447 if (bfd_read ((void*) relocs, 1, reloc_size, abfd) != reloc_size) {
1448 bfd_error = system_call_error;
1455 register struct reloc_info_extended *rptr = relocs;
1456 unsigned int counter = 0;
1457 arelent *cache_ptr = reloc_cache;
1459 for (; counter < count; counter++, rptr++, cache_ptr++) {
1460 /* john's old swap_reloc was a hell of a lot hairier... */
1461 /* FIXME, it needs to be!!! */
1462 rptr->r_address = bfd_h_getlong (abfd, &rptr->r_address);
1464 * The following can't be done because r_index is a bit field:
1466 * rptr->r_index = bfd_h_getlong (abfd, &rptr->r_index);
1468 rptr->r_addend = bfd_h_getlong (abfd, &rptr->r_addend);
1469 if (rptr->r_extern) {
1470 /* If this bit is set then the r_index is a index into the symbol table
1471 * if the bit is not set then r_index contains a section map.
1472 * We either fill in the sym entry with a pointer to the symbol,
1473 * or point to the correct section
1476 cache_ptr->sym_ptr_ptr = symbols + rptr->r_index;
1477 cache_ptr->addend = rptr->r_addend;
1478 cache_ptr->section = (asection *)NULL;
1482 /* Remember that in a.out symbols are relative to the
1483 beginning of the file rather than sections ? (look in
1484 translate_from_native_sym_flags) The reloc entry addend
1485 has added to it the offset into the file of the data, so
1486 subtract the base to make the reloc section relative */
1488 cache_ptr->sym_ptr_ptr = (asymbol **)NULL;
1489 switch (rptr->r_index) {
1491 case N_TEXT | N_EXT:
1492 cache_ptr->section = obj_textsec(abfd);
1493 cache_ptr->addend = rptr->r_addend - obj_textsec(abfd)->vma ;
1496 case N_DATA | N_EXT:
1497 cache_ptr->section = obj_datasec(abfd);
1498 cache_ptr->addend = rptr->r_addend - obj_datasec(abfd)->vma ;
1502 cache_ptr->section = obj_bsssec(abfd);
1503 cache_ptr->addend = rptr->r_addend - obj_bsssec(abfd)->vma;
1516 cache_ptr->address = rptr->r_address;
1517 cache_ptr->howto = howto_table + (unsigned int)( rptr->r_type);
1522 asect->relocation = reloc_cache;
1523 asect->reloc_count = count;
1528 sunos4_squirt_out_relocs (abfd, section)
1534 unsigned int count = section->reloc_count;
1535 struct reloc_info_extended *native, *natptr;
1536 size_t natsize = count * sizeof (struct reloc_info_extended);
1538 if (count == 0) return true;
1539 generic = section->orelocation;
1540 native = ((struct reloc_info_extended *) zalloc (natsize));
1542 bfd_error = no_memory;
1546 for (natptr = native; count != 0; --count, ++natptr, ++generic)
1548 arelent *g = *generic;
1550 natptr->r_address = g->address;
1551 /* Find a type in the output format which matches the input howto -
1552 * at the moment we assume input format == output format FIXME!!
1554 natptr->r_type = (enum reloc_type) g->howto->type;
1555 /* name clobbered by sunos4_write_syms to be symbol index*/
1557 if (g->sym_ptr_ptr != (asymbol **)NULL)
1559 if ((*(g->sym_ptr_ptr))->section) {
1560 /* replace the section offset into the addent */
1561 g->addend += (*(g->sym_ptr_ptr))->section->vma;
1564 natptr->r_index = stoi((*(g->sym_ptr_ptr))->name);
1565 BFD_ASSERT(natptr->r_index < 0xfff);
1566 natptr->r_extern = 1;
1567 natptr->r_addend = g->addend;
1570 natptr->r_extern = 0;
1571 if (g->section == (asection *)NULL) {
1573 natptr->r_index = N_ABS | N_EXT;
1574 natptr->r_addend = g->addend;
1576 else if(g->section->output_section == obj_textsec(abfd)) {
1577 natptr->r_index = N_TEXT | N_EXT;
1578 natptr->r_addend = g->addend + obj_textsec(abfd)->vma;
1580 else if (g->section->output_section == obj_datasec(abfd)) {
1581 natptr->r_index = N_DATA | N_EXT;
1582 natptr->r_addend = g->addend + obj_datasec(abfd)->vma;
1584 else if (g->section->output_section == obj_bsssec(abfd)) {
1585 natptr->r_index = N_BSS | N_EXT ;
1586 natptr->r_addend = g->addend + obj_bsssec(abfd)->vma;
1594 if ( bfd_header_twiddle_required(abfd) ){
1595 bfd_h_putlong ( abfd, natptr->r_address, &natptr->r_address );
1599 * I came through here as part of my campaign to make compile-time
1600 * definition of host and target byte orders unnecessary. The new
1601 * code won't even compile because but r_index is a bit field.
1602 * But the simple-minded byte swap that was here before wasn't going
1603 * to work on a bit field anyway.
1605 * The old code used to be #ifdef'd on
1606 * TARGET_BYTE_ORDER_BIG_P != HOST_BYTE_ORDER_BIG_P
1607 * Apparently, it was never tested in such a condition: the
1608 * macro invocations here (of swapoutlong) had the wrong number
1609 * of arguments and would never have compiled.
1611 bfd_h_putlong ( abfd, natptr->r_index, &natptr->r_index );
1614 bfd_h_putlong ( abfd, natptr->r_addend, &natptr->r_addend );
1619 if ( bfd_write ((void *) native, 1, natsize, abfd) != natsize) {
1628 /* This is stupid. This function should be a boolean predicate */
1630 sunos4_canonicalize_reloc (abfd, section, relptr, symbols)
1636 arelent *tblptr = section->relocation;
1639 if (!(tblptr || sunos4_slurp_reloc_table (abfd, section, symbols)))
1642 if (section->flags & SEC_CONSTRUCTOR) {
1643 arelent_chain *chain = section->constructor_chain;
1644 for (count = 0; count < section->reloc_count; count ++) {
1645 *relptr ++ = &chain->relent;
1646 chain = chain->next;
1650 tblptr = section->relocation;
1651 if (!tblptr) return 0;
1653 for (count = 0; count++ < section->reloc_count;)
1655 *relptr++ = tblptr++;
1660 return section->reloc_count;
1664 sunos4_get_reloc_upper_bound (abfd, asect)
1668 if (bfd_get_format (abfd) != bfd_object) {
1669 bfd_error = invalid_operation;
1672 if (asect->flags & SEC_CONSTRUCTOR) {
1673 return (sizeof (arelent *) * (asect->reloc_count+1));
1676 if (asect == obj_datasec (abfd))
1677 return (sizeof (arelent *) *
1678 ((exec_hdr(abfd)->a_drsize / sizeof (struct reloc_info_extended))
1681 if (asect == obj_textsec (abfd))
1682 return (sizeof (arelent *) *
1683 ((exec_hdr(abfd)->a_trsize / sizeof (struct reloc_info_extended))
1686 bfd_error = invalid_operation;
1691 sunos4_reclaim_reloc (ignore_abfd, section)
1695 if (section->relocation) {
1696 free (section->relocation);
1697 section->relocation = NULL;
1698 section->reloc_count = 0;
1704 sunos4_get_lineno(ignore_abfd, ignore_symbol)
1706 generic_symbol_type *ignore_symbol;
1708 return (alent *)NULL;
1712 sunos4_print_symbol(ignore_abfd, file, symbol, how)
1716 bfd_print_symbol_enum_type how;
1719 case bfd_print_symbol_name_enum:
1720 fprintf(file,"%s", symbol->name);
1722 case bfd_print_symbol_type_enum:
1723 fprintf(file,"%4x %2x %2x",(unsigned)(aout_symbol(symbol)->desc & 0xffff),
1724 (unsigned)( aout_symbol(symbol)->other & 0xff),
1725 (unsigned)(aout_symbol(symbol)->type));
1727 case bfd_print_symbol_all_enum:
1729 char *section_name = symbol->section == (asection *)NULL ?
1730 "*abs" : symbol->section->name;
1732 bfd_print_symbol_vandf((void *)file,symbol);
1734 fprintf(file," %-5s %04x %02x %02x %s",
1736 (unsigned)(aout_symbol(symbol)->desc & 0xffff),
1737 (unsigned)(aout_symbol(symbol)->other & 0xff),
1738 (unsigned)(aout_symbol(symbol)->type & 0xff),
1744 /* Once we know all the stuff that could be consed, we know how to clean
1745 it up. So why don't we? */
1748 sunos4_close_and_cleanup (abfd)
1751 if (!bfd_read_p (abfd))
1752 switch (abfd->format) {
1754 if (!_bfd_write_archive_contents (abfd)) return false; break;
1756 if (!sunos4_write_object_contents (abfd)) return false; break;
1757 default: bfd_error = invalid_operation; return false;
1760 #define cleaner(ptr) if (abfd->ptr) free (abfd->ptr)
1763 if (abfd->my_archive)
1771 provided a bfd, a section and an offset into the section, calculate
1772 and return the name of the source file and the line nearest to the
1777 sunos4_find_nearest_line(abfd,
1788 char **filename_ptr;
1789 char **functionname_ptr;
1790 unsigned int *line_ptr;
1792 /* Run down the file looking for the filename, function and linenumber */
1794 static char buffer[100];
1795 bfd_vma high_line_vma = ~0;
1796 bfd_vma low_func_vma = 0;
1798 *filename_ptr = abfd->filename;
1799 *functionname_ptr = 0;
1801 if (symbols != (asymbol **)NULL) {
1802 for (p = symbols; *p; p++) {
1803 aout_symbol_type *q = (aout_symbol_type *)(*p);
1806 *filename_ptr = q->symbol.name;
1807 if (obj_textsec(abfd) != section) {
1815 /* We'll keep this if it resolves nearer than the one we have already */
1816 if (q->symbol.value >= offset &&
1817 q->symbol.value < high_line_vma) {
1818 *line_ptr = q->desc;
1819 high_line_vma = q->symbol.value;
1824 /* We'll keep this if it is nearer than the one we have already */
1825 if (q->symbol.value >= low_func_vma &&
1826 q->symbol.value <= offset) {
1827 low_func_vma = q->symbol.value;
1828 func = (asymbol *)q;
1830 if (*line_ptr && func) {
1831 char *function = func->name;
1833 strncpy(buffer, function, sizeof(buffer)-1);
1834 buffer[sizeof(buffer)-1] = 0;
1835 /* Have to remove : stuff */
1836 p = strchr(buffer,':');
1837 if (p != NULL) {*p = NULL; }
1838 *functionname_ptr = buffer;
1852 bfd_target aoutvec =
1854 "a.out-generic-big", /* name */
1855 bfd_target_aout_flavour_enum,
1856 true, /* target byte order */
1857 true, /* target headers byte order */
1858 (HAS_RELOC | EXEC_P | /* object flags */
1859 HAS_LINENO | HAS_DEBUG |
1860 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
1861 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
1862 0, /* valid reloc types */
1863 ' ', /* ar_pad_char */
1864 16, /* ar_max_namelen */
1865 sunos4_close_and_cleanup, /* _close_and_cleanup */
1866 sunos4_set_section_contents, /* bfd_set_section_contents */
1867 sunos4_get_section_contents, /* bfd_get_section_contents */
1868 sunos4_new_section_hook, /* new_section_hook */
1869 sunos4_core_file_failing_command, /* _core_file_failing_command */
1870 sunos4_core_file_failing_signal, /* _core_file_failing_signal */
1871 sunos4_core_file_matches_executable_p, /* _core_file_matches_ex...p */
1873 bfd_slurp_bsd_armap, /* bfd_slurp_armap */
1874 bfd_true, /* bfd_slurp_extended_name_table */
1875 bfd_bsd_truncate_arname, /* bfd_truncate_arname */
1877 sunos4_get_symtab_upper_bound, /* get_symtab_upper_bound */
1878 sunos4_get_symtab, /* canonicalize_symtab */
1879 sunos4_reclaim_symbol_table, /* bfd_reclaim_symbol_table */
1880 sunos4_get_reloc_upper_bound, /* get_reloc_upper_bound */
1881 sunos4_canonicalize_reloc, /* bfd_canonicalize_reloc */
1882 sunos4_reclaim_reloc, /* bfd_reclaim_reloc */
1883 sunos4_get_symcount_upper_bound, /* bfd_get_symcount_upper_bound */
1884 sunos4_get_first_symbol, /* bfd_get_first_symbol */
1885 sunos4_get_next_symbol, /* bfd_get_next_symbol */
1886 sunos4_classify_symbol, /* bfd_classify_symbol */
1887 sunos4_symbol_hasclass, /* bfd_symbol_hasclass */
1888 sunos4_symbol_name, /* bfd_symbol_name */
1889 sunos4_symbol_value, /* bfd_symbol_value */
1891 _do_getblong, _do_putblong, _do_getbshort, _do_putbshort, /* data */
1892 _do_getblong, _do_putblong, _do_getbshort, _do_putbshort, /* hdrs */
1894 {_bfd_dummy_target, sunos4_object_p, /* bfd_check_format */
1895 bfd_generic_archive_p, sunos4_core_file_p},
1896 {bfd_false, sunos4_mkobject, /* bfd_zxset_format */
1897 _bfd_generic_mkarchive, bfd_false},
1898 sunos4_make_empty_symbol,
1899 sunos4_print_symbol,
1901 sunos4_set_arch_mach,
1903 bfd_generic_openr_next_archived_file,
1904 sunos4_find_nearest_line, /* bfd_find_nearest_line */
1905 bfd_generic_stat_arch_elt /* bfd_stat_arch_elt */