xref: /openbsd-src/gnu/usr.bin/binutils/bfd/aout-adobe.c (revision 007c2a4539b8b8aaa95c5e73e77620090abe113b)
12159047fSniklas /* BFD back-end for a.out.adobe binaries.
2c074d1c9Sdrahn    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
3*007c2a45Smiod    2002, 2003
4b305b0f1Sespie    Free Software Foundation, Inc.
52159047fSniklas    Written by Cygnus Support.  Based on bout.c.
62159047fSniklas 
72159047fSniklas This file is part of BFD, the Binary File Descriptor library.
82159047fSniklas 
92159047fSniklas This program is free software; you can redistribute it and/or modify
102159047fSniklas it under the terms of the GNU General Public License as published by
112159047fSniklas the Free Software Foundation; either version 2 of the License, or
122159047fSniklas (at your option) any later version.
132159047fSniklas 
142159047fSniklas This program is distributed in the hope that it will be useful,
152159047fSniklas but WITHOUT ANY WARRANTY; without even the implied warranty of
162159047fSniklas MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
172159047fSniklas GNU General Public License for more details.
182159047fSniklas 
192159047fSniklas You should have received a copy of the GNU General Public License
202159047fSniklas along with this program; if not, write to the Free Software
212159047fSniklas Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
222159047fSniklas 
232159047fSniklas #include "bfd.h"
242159047fSniklas #include "sysdep.h"
252159047fSniklas #include "libbfd.h"
262159047fSniklas 
272159047fSniklas #include "aout/adobe.h"
282159047fSniklas 
292159047fSniklas #include "aout/stab_gnu.h"
30c074d1c9Sdrahn #include "libaout.h"		/* BFD a.out internal data structures.  */
312159047fSniklas 
32b55d4692Sfgsch /* Forward decl.  */
33b55d4692Sfgsch extern const bfd_target a_out_adobe_vec;
342159047fSniklas 
35c074d1c9Sdrahn static const bfd_target *aout_adobe_callback
36c074d1c9Sdrahn   PARAMS ((bfd *));
37c074d1c9Sdrahn extern bfd_boolean aout_32_slurp_symbol_table
38c074d1c9Sdrahn   PARAMS ((bfd *abfd));
39c074d1c9Sdrahn extern bfd_boolean aout_32_write_syms
40c074d1c9Sdrahn   PARAMS ((bfd *));
41c074d1c9Sdrahn static void aout_adobe_write_section
42c074d1c9Sdrahn   PARAMS ((bfd *abfd, sec_ptr sect));
43c074d1c9Sdrahn static const bfd_target * aout_adobe_object_p
44c074d1c9Sdrahn   PARAMS ((bfd *));
45c074d1c9Sdrahn static bfd_boolean aout_adobe_mkobject
46c074d1c9Sdrahn   PARAMS ((bfd *));
47c074d1c9Sdrahn static bfd_boolean aout_adobe_write_object_contents
48c074d1c9Sdrahn   PARAMS ((bfd *));
49c074d1c9Sdrahn static bfd_boolean aout_adobe_set_section_contents
50*007c2a45Smiod   PARAMS ((bfd *, asection *, const PTR, file_ptr, bfd_size_type));
51c074d1c9Sdrahn static bfd_boolean aout_adobe_set_arch_mach
52c074d1c9Sdrahn   PARAMS ((bfd *, enum bfd_architecture, unsigned long));
53c074d1c9Sdrahn static int     aout_adobe_sizeof_headers
54c074d1c9Sdrahn   PARAMS ((bfd *, bfd_boolean));
552159047fSniklas 
562159047fSniklas /* Swaps the information in an executable header taken from a raw byte
572159047fSniklas    stream memory image, into the internal exec_header structure.  */
582159047fSniklas 
592159047fSniklas void aout_adobe_swap_exec_header_in
60c074d1c9Sdrahn   PARAMS ((bfd *, struct external_exec *, struct internal_exec *));
612159047fSniklas 
622159047fSniklas void
aout_adobe_swap_exec_header_in(abfd,raw_bytes,execp)632159047fSniklas aout_adobe_swap_exec_header_in (abfd, raw_bytes, execp)
642159047fSniklas      bfd *abfd;
652159047fSniklas      struct external_exec *raw_bytes;
662159047fSniklas      struct internal_exec *execp;
672159047fSniklas {
682159047fSniklas   struct external_exec *bytes = (struct external_exec *) raw_bytes;
692159047fSniklas 
702159047fSniklas   /* Now fill in fields in the execp, from the bytes in the raw data.  */
71c074d1c9Sdrahn   execp->a_info   = H_GET_32 (abfd, bytes->e_info);
722159047fSniklas   execp->a_text   = GET_WORD (abfd, bytes->e_text);
732159047fSniklas   execp->a_data   = GET_WORD (abfd, bytes->e_data);
742159047fSniklas   execp->a_bss    = GET_WORD (abfd, bytes->e_bss);
752159047fSniklas   execp->a_syms   = GET_WORD (abfd, bytes->e_syms);
762159047fSniklas   execp->a_entry  = GET_WORD (abfd, bytes->e_entry);
772159047fSniklas   execp->a_trsize = GET_WORD (abfd, bytes->e_trsize);
782159047fSniklas   execp->a_drsize = GET_WORD (abfd, bytes->e_drsize);
792159047fSniklas }
802159047fSniklas 
812159047fSniklas /* Swaps the information in an internal exec header structure into the
822159047fSniklas    supplied buffer ready for writing to disk.  */
832159047fSniklas 
84c074d1c9Sdrahn void aout_adobe_swap_exec_header_out
85c074d1c9Sdrahn   PARAMS ((bfd *, struct internal_exec *, struct external_exec *));
86c074d1c9Sdrahn 
872159047fSniklas void
aout_adobe_swap_exec_header_out(abfd,execp,raw_bytes)882159047fSniklas aout_adobe_swap_exec_header_out (abfd, execp, raw_bytes)
892159047fSniklas      bfd *abfd;
902159047fSniklas      struct internal_exec *execp;
912159047fSniklas      struct external_exec *raw_bytes;
922159047fSniklas {
932159047fSniklas   struct external_exec *bytes = (struct external_exec *) raw_bytes;
942159047fSniklas 
95b55d4692Sfgsch   /* Now fill in fields in the raw data, from the fields in the exec
96b55d4692Sfgsch      struct.  */
97c074d1c9Sdrahn   H_PUT_32 (abfd, execp->a_info  , bytes->e_info);
982159047fSniklas   PUT_WORD (abfd, execp->a_text  , bytes->e_text);
992159047fSniklas   PUT_WORD (abfd, execp->a_data  , bytes->e_data);
1002159047fSniklas   PUT_WORD (abfd, execp->a_bss   , bytes->e_bss);
1012159047fSniklas   PUT_WORD (abfd, execp->a_syms  , bytes->e_syms);
1022159047fSniklas   PUT_WORD (abfd, execp->a_entry , bytes->e_entry);
1032159047fSniklas   PUT_WORD (abfd, execp->a_trsize, bytes->e_trsize);
1042159047fSniklas   PUT_WORD (abfd, execp->a_drsize, bytes->e_drsize);
1052159047fSniklas }
1062159047fSniklas 
1072159047fSniklas static const bfd_target *
aout_adobe_object_p(abfd)1082159047fSniklas aout_adobe_object_p (abfd)
1092159047fSniklas      bfd *abfd;
1102159047fSniklas {
1112159047fSniklas   struct internal_exec anexec;
1122159047fSniklas   struct external_exec exec_bytes;
1132159047fSniklas   char *targ;
114c074d1c9Sdrahn   bfd_size_type amt = EXEC_BYTES_SIZE;
1152159047fSniklas 
116c074d1c9Sdrahn   if (bfd_bread ((PTR) &exec_bytes, amt, abfd) != amt)
117b55d4692Sfgsch     {
1182159047fSniklas       if (bfd_get_error () != bfd_error_system_call)
1192159047fSniklas 	bfd_set_error (bfd_error_wrong_format);
1202159047fSniklas       return 0;
1212159047fSniklas     }
1222159047fSniklas 
123c074d1c9Sdrahn   anexec.a_info = H_GET_32 (abfd, exec_bytes.e_info);
1242159047fSniklas 
1252159047fSniklas   /* Normally we just compare for the magic number.
1262159047fSniklas      However, a bunch of Adobe tools aren't fixed up yet; they generate
1272159047fSniklas      files using ZMAGIC(!).
1282159047fSniklas      If the environment variable GNUTARGET is set to "a.out.adobe", we will
1292159047fSniklas      take just about any a.out file as an Adobe a.out file.  FIXME!  */
1302159047fSniklas 
131b55d4692Sfgsch   if (N_BADMAG (anexec))
132b55d4692Sfgsch     {
1332159047fSniklas       targ = getenv ("GNUTARGET");
1342159047fSniklas       if (targ && !strcmp (targ, a_out_adobe_vec.name))
135b55d4692Sfgsch 	/* Just continue anyway, if specifically set to this format.  */
136b55d4692Sfgsch 	;
1372159047fSniklas       else
1382159047fSniklas 	{
1392159047fSniklas 	  bfd_set_error (bfd_error_wrong_format);
1402159047fSniklas 	  return 0;
1412159047fSniklas 	}
1422159047fSniklas     }
1432159047fSniklas 
1442159047fSniklas   aout_adobe_swap_exec_header_in (abfd, &exec_bytes, &anexec);
1452159047fSniklas   return aout_32_some_aout_object_p (abfd, &anexec, aout_adobe_callback);
1462159047fSniklas }
1472159047fSniklas 
1482159047fSniklas /* Finish up the opening of a b.out file for reading.  Fill in all the
1492159047fSniklas    fields that are not handled by common code.  */
1502159047fSniklas 
1512159047fSniklas static const bfd_target *
aout_adobe_callback(abfd)1522159047fSniklas aout_adobe_callback (abfd)
1532159047fSniklas      bfd *abfd;
1542159047fSniklas {
1552159047fSniklas   struct internal_exec *execp = exec_hdr (abfd);
1562159047fSniklas   asection *sect;
1572159047fSniklas   struct external_segdesc ext[1];
1582159047fSniklas   char *section_name;
159c074d1c9Sdrahn   char try_again[30];	/* Name and number.  */
1602159047fSniklas   char *newname;
1612159047fSniklas   int trynum;
1622159047fSniklas   flagword flags;
1632159047fSniklas 
1642159047fSniklas   /* Architecture and machine type -- unknown in this format.  */
165c074d1c9Sdrahn   bfd_set_arch_mach (abfd, bfd_arch_unknown, 0L);
1662159047fSniklas 
1672159047fSniklas   /* The positions of the string table and symbol table.  */
1682159047fSniklas   obj_str_filepos (abfd) = N_STROFF (*execp);
1692159047fSniklas   obj_sym_filepos (abfd) = N_SYMOFF (*execp);
1702159047fSniklas 
1712159047fSniklas   /* Suck up the section information from the file, one section at a time.  */
172b55d4692Sfgsch   for (;;)
173b55d4692Sfgsch     {
174c074d1c9Sdrahn       bfd_size_type amt = sizeof (*ext);
175c074d1c9Sdrahn       if (bfd_bread ((PTR) ext, amt, abfd) != amt)
176b55d4692Sfgsch 	{
1772159047fSniklas 	  if (bfd_get_error () != bfd_error_system_call)
1782159047fSniklas 	    bfd_set_error (bfd_error_wrong_format);
179c074d1c9Sdrahn 
1802159047fSniklas 	  return 0;
1812159047fSniklas 	}
182b55d4692Sfgsch       switch (ext->e_type[0])
183b55d4692Sfgsch 	{
1842159047fSniklas 	case N_TEXT:
1852159047fSniklas 	  section_name = ".text";
1862159047fSniklas 	  flags = SEC_CODE | SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS;
1872159047fSniklas 	  break;
1882159047fSniklas 
1892159047fSniklas 	case N_DATA:
1902159047fSniklas 	  section_name = ".data";
1912159047fSniklas 	  flags = SEC_DATA | SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS;
1922159047fSniklas 	  break;
1932159047fSniklas 
1942159047fSniklas 	case N_BSS:
1952159047fSniklas 	  section_name = ".bss";
1962159047fSniklas 	  flags = SEC_DATA | SEC_HAS_CONTENTS;
1972159047fSniklas 	  break;
1982159047fSniklas 
1992159047fSniklas 	case 0:
2002159047fSniklas 	  goto no_more_sections;
2012159047fSniklas 
2022159047fSniklas 	default:
2032159047fSniklas 	  (*_bfd_error_handler)
204b305b0f1Sespie 	    (_("%s: Unknown section type in a.out.adobe file: %x\n"),
205c074d1c9Sdrahn 	     bfd_archive_filename (abfd), ext->e_type[0]);
2062159047fSniklas 	  goto no_more_sections;
2072159047fSniklas 	}
2082159047fSniklas 
2092159047fSniklas       /* First one is called ".text" or whatever; subsequent ones are
2102159047fSniklas 	 ".text1", ".text2", ...  */
2112159047fSniklas       bfd_set_error (bfd_error_no_error);
2122159047fSniklas       sect = bfd_make_section (abfd, section_name);
2132159047fSniklas       trynum = 0;
214c074d1c9Sdrahn 
215b55d4692Sfgsch       while (!sect)
216b55d4692Sfgsch 	{
2172159047fSniklas 	  if (bfd_get_error () != bfd_error_no_error)
218b55d4692Sfgsch 	    /* Some other error -- slide into the sunset.  */
219b55d4692Sfgsch 	    return 0;
2202159047fSniklas 	  sprintf (try_again, "%s%d", section_name, ++trynum);
2212159047fSniklas 	  sect = bfd_make_section (abfd, try_again);
2222159047fSniklas 	}
2232159047fSniklas 
2242159047fSniklas       /* Fix the name, if it is a sprintf'd name.  */
225b55d4692Sfgsch       if (sect->name == try_again)
226b55d4692Sfgsch 	{
227c074d1c9Sdrahn 	  amt = strlen (sect->name);
228c074d1c9Sdrahn 	  newname = (char *) bfd_zalloc (abfd, amt);
229c88b1d6cSniklas 	  if (newname == NULL)
2302159047fSniklas 	    return 0;
2312159047fSniklas 	  strcpy (newname, sect->name);
2322159047fSniklas 	  sect->name = newname;
2332159047fSniklas 	}
2342159047fSniklas 
2352159047fSniklas       /* Now set the section's attributes.  */
2362159047fSniklas       bfd_set_section_flags (abfd, sect, flags);
237b55d4692Sfgsch       /* Assumed big-endian.  */
238b55d4692Sfgsch       sect->_raw_size = ((ext->e_size[0] << 8)
239c074d1c9Sdrahn 			 | ext->e_size[1] << 8
240c074d1c9Sdrahn 			 | ext->e_size[2]);
2412159047fSniklas       sect->_cooked_size = sect->_raw_size;
242c074d1c9Sdrahn       sect->vma = H_GET_32 (abfd, ext->e_virtbase);
243c074d1c9Sdrahn       sect->filepos = H_GET_32 (abfd, ext->e_filebase);
2442159047fSniklas       /* FIXME XXX alignment?  */
2452159047fSniklas 
2462159047fSniklas       /* Set relocation information for first section of each type.  */
247b55d4692Sfgsch       if (trynum == 0)
248b55d4692Sfgsch 	switch (ext->e_type[0])
249b55d4692Sfgsch 	  {
2502159047fSniklas 	  case N_TEXT:
2512159047fSniklas 	    sect->rel_filepos = N_TRELOFF (*execp);
2522159047fSniklas 	    sect->reloc_count = execp->a_trsize;
2532159047fSniklas 	    break;
2542159047fSniklas 
2552159047fSniklas 	  case N_DATA:
2562159047fSniklas 	    sect->rel_filepos = N_DRELOFF (*execp);
2572159047fSniklas 	    sect->reloc_count = execp->a_drsize;
2582159047fSniklas 	    break;
259c074d1c9Sdrahn 
260c074d1c9Sdrahn 	  default:
261c074d1c9Sdrahn 	    break;
2622159047fSniklas 	  }
2632159047fSniklas     }
2642159047fSniklas  no_more_sections:
2652159047fSniklas 
2662159047fSniklas   adata (abfd).reloc_entry_size = sizeof (struct reloc_std_external);
2672159047fSniklas   adata (abfd).symbol_entry_size = sizeof (struct external_nlist);
2682159047fSniklas   adata (abfd).page_size = 1; /* Not applicable.  */
2692159047fSniklas   adata (abfd).segment_size = 1; /* Not applicable.  */
2702159047fSniklas   adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
2712159047fSniklas 
2722159047fSniklas   return abfd->xvec;
2732159047fSniklas }
2742159047fSniklas 
275c074d1c9Sdrahn struct bout_data_struct
276c074d1c9Sdrahn   {
2772159047fSniklas     struct aoutdata a;
2782159047fSniklas     struct internal_exec e;
2792159047fSniklas   };
2802159047fSniklas 
281c074d1c9Sdrahn static bfd_boolean
aout_adobe_mkobject(abfd)2822159047fSniklas aout_adobe_mkobject (abfd)
2832159047fSniklas      bfd *abfd;
2842159047fSniklas {
2852159047fSniklas   struct bout_data_struct *rawptr;
286c074d1c9Sdrahn   bfd_size_type amt = sizeof (struct bout_data_struct);
2872159047fSniklas 
288c074d1c9Sdrahn   rawptr = (struct bout_data_struct *) bfd_zalloc (abfd, amt);
289c88b1d6cSniklas   if (rawptr == NULL)
290c074d1c9Sdrahn     return FALSE;
2912159047fSniklas 
2922159047fSniklas   abfd->tdata.bout_data = rawptr;
2932159047fSniklas   exec_hdr (abfd) = &rawptr->e;
2942159047fSniklas 
2952159047fSniklas   adata (abfd).reloc_entry_size = sizeof (struct reloc_std_external);
2962159047fSniklas   adata (abfd).symbol_entry_size = sizeof (struct external_nlist);
2972159047fSniklas   adata (abfd).page_size = 1; /* Not applicable.  */
2982159047fSniklas   adata (abfd).segment_size = 1; /* Not applicable.  */
2992159047fSniklas   adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
3002159047fSniklas 
301c074d1c9Sdrahn   return TRUE;
3022159047fSniklas }
3032159047fSniklas 
304c074d1c9Sdrahn static bfd_boolean
aout_adobe_write_object_contents(abfd)3052159047fSniklas aout_adobe_write_object_contents (abfd)
3062159047fSniklas      bfd *abfd;
3072159047fSniklas {
3082159047fSniklas   struct external_exec swapped_hdr;
309b55d4692Sfgsch   static struct external_segdesc sentinel[1];	/* Initialized to zero.  */
3102159047fSniklas   asection *sect;
311c074d1c9Sdrahn   bfd_size_type amt;
3122159047fSniklas 
3132159047fSniklas   exec_hdr (abfd)->a_info = ZMAGIC;
3142159047fSniklas 
3152159047fSniklas   /* Calculate text size as total of text sections, etc.  */
3162159047fSniklas 
3172159047fSniklas   exec_hdr (abfd)->a_text = 0;
3182159047fSniklas   exec_hdr (abfd)->a_data = 0;
3192159047fSniklas   exec_hdr (abfd)->a_bss  = 0;
3202159047fSniklas   exec_hdr (abfd)->a_trsize = 0;
3212159047fSniklas   exec_hdr (abfd)->a_drsize = 0;
3222159047fSniklas 
323b55d4692Sfgsch   for (sect = abfd->sections; sect; sect = sect->next)
324b55d4692Sfgsch     {
325b55d4692Sfgsch       if (sect->flags & SEC_CODE)
326b55d4692Sfgsch 	{
3272159047fSniklas 	  exec_hdr (abfd)->a_text += sect->_raw_size;
3282159047fSniklas 	  exec_hdr (abfd)->a_trsize += sect->reloc_count *
3292159047fSniklas 	    sizeof (struct reloc_std_external);
330b55d4692Sfgsch 	}
331b55d4692Sfgsch       else if (sect->flags & SEC_DATA)
332b55d4692Sfgsch 	{
3332159047fSniklas 	  exec_hdr (abfd)->a_data += sect->_raw_size;
3342159047fSniklas 	  exec_hdr (abfd)->a_drsize += sect->reloc_count *
3352159047fSniklas 	    sizeof (struct reloc_std_external);
336b55d4692Sfgsch 	}
337b55d4692Sfgsch       else if (sect->flags & SEC_ALLOC && !(sect->flags & SEC_LOAD))
338b55d4692Sfgsch 	{
3392159047fSniklas 	  exec_hdr (abfd)->a_bss += sect->_raw_size;
3402159047fSniklas 	}
3412159047fSniklas     }
3422159047fSniklas 
3432159047fSniklas   exec_hdr (abfd)->a_syms = bfd_get_symcount (abfd)
3442159047fSniklas     * sizeof (struct external_nlist);
3452159047fSniklas   exec_hdr (abfd)->a_entry = bfd_get_start_address (abfd);
3462159047fSniklas 
3472159047fSniklas   aout_adobe_swap_exec_header_out (abfd, exec_hdr (abfd), &swapped_hdr);
3482159047fSniklas 
349c074d1c9Sdrahn   amt = EXEC_BYTES_SIZE;
3502159047fSniklas   if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
351c074d1c9Sdrahn       || bfd_bwrite ((PTR) &swapped_hdr, amt, abfd) != amt)
352c074d1c9Sdrahn     return FALSE;
3532159047fSniklas 
3542159047fSniklas   /* Now write out the section information.  Text first, data next, rest
3552159047fSniklas      afterward.  */
3562159047fSniklas 
357b55d4692Sfgsch   for (sect = abfd->sections; sect; sect = sect->next)
358b55d4692Sfgsch     if (sect->flags & SEC_CODE)
3592159047fSniklas       aout_adobe_write_section (abfd, sect);
360c074d1c9Sdrahn 
361b55d4692Sfgsch   for (sect = abfd->sections; sect; sect = sect->next)
362b55d4692Sfgsch     if (sect->flags & SEC_DATA)
3632159047fSniklas       aout_adobe_write_section (abfd, sect);
364c074d1c9Sdrahn 
365b55d4692Sfgsch   for (sect = abfd->sections; sect; sect = sect->next)
366b55d4692Sfgsch     if (!(sect->flags & (SEC_CODE | SEC_DATA)))
3672159047fSniklas       aout_adobe_write_section (abfd, sect);
3682159047fSniklas 
3692159047fSniklas   /* Write final `sentinel` section header (with type of 0).  */
370c074d1c9Sdrahn   amt = sizeof (*sentinel);
371c074d1c9Sdrahn   if (bfd_bwrite ((PTR) sentinel, amt, abfd) != amt)
372c074d1c9Sdrahn     return FALSE;
3732159047fSniklas 
374b55d4692Sfgsch   /* Now write out reloc info, followed by syms and strings.  */
3752159047fSniklas   if (bfd_get_symcount (abfd) != 0)
3762159047fSniklas     {
3772159047fSniklas       if (bfd_seek (abfd, (file_ptr) (N_SYMOFF (*exec_hdr (abfd))), SEEK_SET)
3782159047fSniklas 	  != 0)
379c074d1c9Sdrahn 	return FALSE;
3802159047fSniklas 
3812159047fSniklas       if (! aout_32_write_syms (abfd))
382c074d1c9Sdrahn 	return FALSE;
3832159047fSniklas 
3842159047fSniklas       if (bfd_seek (abfd, (file_ptr) (N_TRELOFF (*exec_hdr (abfd))), SEEK_SET)
3852159047fSniklas 	  != 0)
386c074d1c9Sdrahn 	return FALSE;
3872159047fSniklas 
388b55d4692Sfgsch       for (sect = abfd->sections; sect; sect = sect->next)
389b55d4692Sfgsch 	if (sect->flags & SEC_CODE)
3902159047fSniklas 	  if (!aout_32_squirt_out_relocs (abfd, sect))
391c074d1c9Sdrahn 	    return FALSE;
3922159047fSniklas 
3932159047fSniklas       if (bfd_seek (abfd, (file_ptr) (N_DRELOFF (*exec_hdr (abfd))), SEEK_SET)
3942159047fSniklas 	  != 0)
395c074d1c9Sdrahn 	return FALSE;
3962159047fSniklas 
397b55d4692Sfgsch       for (sect = abfd->sections; sect; sect = sect->next)
398b55d4692Sfgsch 	if (sect->flags & SEC_DATA)
3992159047fSniklas 	  if (!aout_32_squirt_out_relocs (abfd, sect))
400c074d1c9Sdrahn 	    return FALSE;
4012159047fSniklas     }
402c074d1c9Sdrahn 
403c074d1c9Sdrahn   return TRUE;
4042159047fSniklas }
4052159047fSniklas 
4062159047fSniklas static void
aout_adobe_write_section(abfd,sect)4072159047fSniklas aout_adobe_write_section (abfd, sect)
408b305b0f1Sespie      bfd *abfd ATTRIBUTE_UNUSED;
409b305b0f1Sespie      sec_ptr sect ATTRIBUTE_UNUSED;
4102159047fSniklas {
4112159047fSniklas   /* FIXME XXX */
4122159047fSniklas }
4132159047fSniklas 
414c074d1c9Sdrahn static bfd_boolean
aout_adobe_set_section_contents(abfd,section,location,offset,count)4152159047fSniklas aout_adobe_set_section_contents (abfd, section, location, offset, count)
4162159047fSniklas      bfd *abfd;
4172159047fSniklas      asection *section;
418*007c2a45Smiod      const PTR location;
4192159047fSniklas      file_ptr offset;
4202159047fSniklas      bfd_size_type count;
4212159047fSniklas {
4222159047fSniklas   file_ptr section_start;
4232159047fSniklas   sec_ptr sect;
4242159047fSniklas 
425b55d4692Sfgsch   /* Set by bfd.c handler.  */
426c074d1c9Sdrahn   if (! abfd->output_has_begun)
427b55d4692Sfgsch     {
4282159047fSniklas       /* Assign file offsets to sections.  Text sections are first, and
4292159047fSniklas 	 are contiguous.  Then data sections.  Everything else at the end.  */
4302159047fSniklas       section_start = N_TXTOFF (ignore<-->me);
4312159047fSniklas 
432b55d4692Sfgsch       for (sect = abfd->sections; sect; sect = sect->next)
433b55d4692Sfgsch 	{
434b55d4692Sfgsch 	  if (sect->flags & SEC_CODE)
435b55d4692Sfgsch 	    {
4362159047fSniklas 	      sect->filepos = section_start;
437b55d4692Sfgsch 	      /* FIXME:  Round to alignment.  */
4382159047fSniklas 	      section_start += sect->_raw_size;
4392159047fSniklas 	    }
4402159047fSniklas 	}
4412159047fSniklas 
442b55d4692Sfgsch       for (sect = abfd->sections; sect; sect = sect->next)
443b55d4692Sfgsch 	{
444b55d4692Sfgsch 	  if (sect->flags & SEC_DATA)
445b55d4692Sfgsch 	    {
4462159047fSniklas 	      sect->filepos = section_start;
447b55d4692Sfgsch 	      /* FIXME:  Round to alignment.  */
4482159047fSniklas 	      section_start += sect->_raw_size;
4492159047fSniklas 	    }
4502159047fSniklas 	}
4512159047fSniklas 
452b55d4692Sfgsch       for (sect = abfd->sections; sect; sect = sect->next)
453b55d4692Sfgsch 	{
4542159047fSniklas 	  if (sect->flags & SEC_HAS_CONTENTS &&
455b55d4692Sfgsch 	      !(sect->flags & (SEC_CODE | SEC_DATA)))
456b55d4692Sfgsch 	    {
4572159047fSniklas 	      sect->filepos = section_start;
458b55d4692Sfgsch 	      /* FIXME:  Round to alignment.  */
4592159047fSniklas 	      section_start += sect->_raw_size;
4602159047fSniklas 	    }
4612159047fSniklas 	}
4622159047fSniklas     }
4632159047fSniklas 
464b55d4692Sfgsch   /* Regardless, once we know what we're doing, we might as well get
465b55d4692Sfgsch      going.  */
4662159047fSniklas   if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
467c074d1c9Sdrahn     return FALSE;
4682159047fSniklas 
469c074d1c9Sdrahn   if (count == 0)
470c074d1c9Sdrahn     return TRUE;
471c074d1c9Sdrahn 
472c074d1c9Sdrahn   return bfd_bwrite ((PTR) location, count, abfd) == count;
4732159047fSniklas }
4742159047fSniklas 
475c074d1c9Sdrahn static bfd_boolean
aout_adobe_set_arch_mach(abfd,arch,machine)4762159047fSniklas aout_adobe_set_arch_mach (abfd, arch, machine)
4772159047fSniklas      bfd *abfd;
4782159047fSniklas      enum bfd_architecture arch;
4792159047fSniklas      unsigned long machine;
4802159047fSniklas {
4812159047fSniklas   if (! bfd_default_set_arch_mach (abfd, arch, machine))
482c074d1c9Sdrahn     return FALSE;
4832159047fSniklas 
4842159047fSniklas   if (arch == bfd_arch_unknown
4852159047fSniklas       || arch == bfd_arch_m68k)
486c074d1c9Sdrahn     return TRUE;
4872159047fSniklas 
488c074d1c9Sdrahn   return FALSE;
4892159047fSniklas }
4902159047fSniklas 
4912159047fSniklas static int
aout_adobe_sizeof_headers(ignore_abfd,ignore)4922159047fSniklas aout_adobe_sizeof_headers (ignore_abfd, ignore)
493b305b0f1Sespie      bfd *ignore_abfd ATTRIBUTE_UNUSED;
494c074d1c9Sdrahn      bfd_boolean ignore ATTRIBUTE_UNUSED;
4952159047fSniklas {
4962159047fSniklas   return sizeof (struct internal_exec);
4972159047fSniklas }
4982159047fSniklas 
4992159047fSniklas /* Build the transfer vector for Adobe A.Out files.  */
5002159047fSniklas 
5012159047fSniklas #define aout_32_close_and_cleanup aout_32_bfd_free_cached_info
5022159047fSniklas 
5032159047fSniklas #define aout_32_bfd_make_debug_symbol \
5042159047fSniklas   ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
5052159047fSniklas 
5062159047fSniklas #define aout_32_bfd_reloc_type_lookup \
5072159047fSniklas   ((reloc_howto_type *(*) \
5082159047fSniklas     PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
5092159047fSniklas 
5102159047fSniklas #define	aout_32_set_arch_mach		aout_adobe_set_arch_mach
5112159047fSniklas #define	aout_32_set_section_contents	aout_adobe_set_section_contents
5122159047fSniklas 
5132159047fSniklas #define	aout_32_sizeof_headers		aout_adobe_sizeof_headers
5142159047fSniklas #define aout_32_bfd_get_relocated_section_contents \
5152159047fSniklas   bfd_generic_get_relocated_section_contents
5162159047fSniklas #define aout_32_get_section_contents_in_window _bfd_generic_get_section_contents_in_window
5172159047fSniklas #define aout_32_bfd_relax_section       bfd_generic_relax_section
518b305b0f1Sespie #define aout_32_bfd_gc_sections         bfd_generic_gc_sections
519c074d1c9Sdrahn #define aout_32_bfd_merge_sections	bfd_generic_merge_sections
520c074d1c9Sdrahn #define aout_32_bfd_discard_group	bfd_generic_discard_group
5212159047fSniklas #define aout_32_bfd_link_hash_table_create \
5222159047fSniklas   _bfd_generic_link_hash_table_create
523c074d1c9Sdrahn #define aout_32_bfd_link_hash_table_free \
524c074d1c9Sdrahn   _bfd_generic_link_hash_table_free
5252159047fSniklas #define aout_32_bfd_link_add_symbols	_bfd_generic_link_add_symbols
526c074d1c9Sdrahn #define aout_32_bfd_link_just_syms	_bfd_generic_link_just_syms
5272159047fSniklas #define aout_32_bfd_final_link		_bfd_generic_final_link
5282159047fSniklas #define aout_32_bfd_link_split_section	_bfd_generic_link_split_section
5292159047fSniklas 
530c074d1c9Sdrahn const bfd_target a_out_adobe_vec =
531c074d1c9Sdrahn   {
5322159047fSniklas     "a.out.adobe",		/* name */
5332159047fSniklas     bfd_target_aout_flavour,
534c88b1d6cSniklas     BFD_ENDIAN_BIG,		/* data byte order is unknown (big assumed) */
535c88b1d6cSniklas     BFD_ENDIAN_BIG,		/* hdr byte order is big */
5362159047fSniklas     (HAS_RELOC | EXEC_P |	/* object flags */
5372159047fSniklas      HAS_LINENO | HAS_DEBUG |
5382159047fSniklas      HAS_SYMS | HAS_LOCALS | WP_TEXT ),
5392159047fSniklas     /* section flags */
5402159047fSniklas     (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_DATA | SEC_RELOC),
5412159047fSniklas     '_',				/*  symbol leading char */
5422159047fSniklas     ' ',				/* ar_pad_char */
5432159047fSniklas     16,					/* ar_max_namelen */
5442159047fSniklas 
5452159047fSniklas     bfd_getb64, bfd_getb_signed_64, bfd_putb64,
5462159047fSniklas     bfd_getb32, bfd_getb_signed_32, bfd_putb32,
5472159047fSniklas     bfd_getb16, bfd_getb_signed_16, bfd_putb16,	/* data */
5482159047fSniklas     bfd_getb64, bfd_getb_signed_64, bfd_putb64,
5492159047fSniklas     bfd_getb32, bfd_getb_signed_32, bfd_putb32,
5502159047fSniklas     bfd_getb16, bfd_getb_signed_16, bfd_putb16,	/* hdrs */
5512159047fSniklas     {_bfd_dummy_target, aout_adobe_object_p,	/* bfd_check_format */
5522159047fSniklas      bfd_generic_archive_p, _bfd_dummy_target},
5532159047fSniklas     {bfd_false, aout_adobe_mkobject,		/* bfd_set_format */
5542159047fSniklas      _bfd_generic_mkarchive, bfd_false},
5552159047fSniklas     {bfd_false, aout_adobe_write_object_contents,/* bfd_write_contents */
5562159047fSniklas      _bfd_write_archive_contents, bfd_false},
5572159047fSniklas 
5582159047fSniklas     BFD_JUMP_TABLE_GENERIC (aout_32),
5592159047fSniklas     BFD_JUMP_TABLE_COPY (_bfd_generic),
5602159047fSniklas     BFD_JUMP_TABLE_CORE (_bfd_nocore),
5612159047fSniklas     BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd),
5622159047fSniklas     BFD_JUMP_TABLE_SYMBOLS (aout_32),
5632159047fSniklas     BFD_JUMP_TABLE_RELOCS (aout_32),
5642159047fSniklas     BFD_JUMP_TABLE_WRITE (aout_32),
5652159047fSniklas     BFD_JUMP_TABLE_LINK (aout_32),
5662159047fSniklas     BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
5672159047fSniklas 
568b305b0f1Sespie     NULL,
569b305b0f1Sespie 
5702159047fSniklas     (PTR) 0
5712159047fSniklas   };
572