1*3d8817e4Smiod /* BFD back-end for a.out.adobe binaries.
2*3d8817e4Smiod Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000,
3*3d8817e4Smiod 2001, 2002, 2003, 2004, 2005
4*3d8817e4Smiod Free Software Foundation, Inc.
5*3d8817e4Smiod Written by Cygnus Support. Based on bout.c.
6*3d8817e4Smiod
7*3d8817e4Smiod This file is part of BFD, the Binary File Descriptor library.
8*3d8817e4Smiod
9*3d8817e4Smiod This program is free software; you can redistribute it and/or modify
10*3d8817e4Smiod it under the terms of the GNU General Public License as published by
11*3d8817e4Smiod the Free Software Foundation; either version 2 of the License, or
12*3d8817e4Smiod (at your option) any later version.
13*3d8817e4Smiod
14*3d8817e4Smiod This program is distributed in the hope that it will be useful,
15*3d8817e4Smiod but WITHOUT ANY WARRANTY; without even the implied warranty of
16*3d8817e4Smiod MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17*3d8817e4Smiod GNU General Public License for more details.
18*3d8817e4Smiod
19*3d8817e4Smiod You should have received a copy of the GNU General Public License
20*3d8817e4Smiod along with this program; if not, write to the Free Software
21*3d8817e4Smiod Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
22*3d8817e4Smiod
23*3d8817e4Smiod #include "bfd.h"
24*3d8817e4Smiod #include "sysdep.h"
25*3d8817e4Smiod #include "libbfd.h"
26*3d8817e4Smiod #include "aout/adobe.h"
27*3d8817e4Smiod #include "aout/stab_gnu.h"
28*3d8817e4Smiod #include "libaout.h" /* BFD a.out internal data structures. */
29*3d8817e4Smiod
30*3d8817e4Smiod /* Forward decl. */
31*3d8817e4Smiod extern const bfd_target a_out_adobe_vec;
32*3d8817e4Smiod
33*3d8817e4Smiod /* Swaps the information in an executable header taken from a raw byte
34*3d8817e4Smiod stream memory image, into the internal exec_header structure. */
35*3d8817e4Smiod
36*3d8817e4Smiod static void
aout_adobe_swap_exec_header_in(bfd * abfd,struct external_exec * bytes,struct internal_exec * execp)37*3d8817e4Smiod aout_adobe_swap_exec_header_in (bfd *abfd,
38*3d8817e4Smiod struct external_exec *bytes,
39*3d8817e4Smiod struct internal_exec *execp)
40*3d8817e4Smiod {
41*3d8817e4Smiod /* Now fill in fields in the execp, from the bytes in the raw data. */
42*3d8817e4Smiod execp->a_info = H_GET_32 (abfd, bytes->e_info);
43*3d8817e4Smiod execp->a_text = GET_WORD (abfd, bytes->e_text);
44*3d8817e4Smiod execp->a_data = GET_WORD (abfd, bytes->e_data);
45*3d8817e4Smiod execp->a_bss = GET_WORD (abfd, bytes->e_bss);
46*3d8817e4Smiod execp->a_syms = GET_WORD (abfd, bytes->e_syms);
47*3d8817e4Smiod execp->a_entry = GET_WORD (abfd, bytes->e_entry);
48*3d8817e4Smiod execp->a_trsize = GET_WORD (abfd, bytes->e_trsize);
49*3d8817e4Smiod execp->a_drsize = GET_WORD (abfd, bytes->e_drsize);
50*3d8817e4Smiod }
51*3d8817e4Smiod
52*3d8817e4Smiod /* Swaps the information in an internal exec header structure into the
53*3d8817e4Smiod supplied buffer ready for writing to disk. */
54*3d8817e4Smiod
55*3d8817e4Smiod static void
aout_adobe_swap_exec_header_out(bfd * abfd,struct internal_exec * execp,struct external_exec * bytes)56*3d8817e4Smiod aout_adobe_swap_exec_header_out (bfd *abfd,
57*3d8817e4Smiod struct internal_exec *execp,
58*3d8817e4Smiod struct external_exec *bytes)
59*3d8817e4Smiod {
60*3d8817e4Smiod /* Now fill in fields in the raw data, from the fields in the exec
61*3d8817e4Smiod struct. */
62*3d8817e4Smiod H_PUT_32 (abfd, execp->a_info , bytes->e_info);
63*3d8817e4Smiod PUT_WORD (abfd, execp->a_text , bytes->e_text);
64*3d8817e4Smiod PUT_WORD (abfd, execp->a_data , bytes->e_data);
65*3d8817e4Smiod PUT_WORD (abfd, execp->a_bss , bytes->e_bss);
66*3d8817e4Smiod PUT_WORD (abfd, execp->a_syms , bytes->e_syms);
67*3d8817e4Smiod PUT_WORD (abfd, execp->a_entry , bytes->e_entry);
68*3d8817e4Smiod PUT_WORD (abfd, execp->a_trsize, bytes->e_trsize);
69*3d8817e4Smiod PUT_WORD (abfd, execp->a_drsize, bytes->e_drsize);
70*3d8817e4Smiod }
71*3d8817e4Smiod
72*3d8817e4Smiod /* Finish up the opening of a b.out file for reading. Fill in all the
73*3d8817e4Smiod fields that are not handled by common code. */
74*3d8817e4Smiod
75*3d8817e4Smiod static const bfd_target *
aout_adobe_callback(bfd * abfd)76*3d8817e4Smiod aout_adobe_callback (bfd *abfd)
77*3d8817e4Smiod {
78*3d8817e4Smiod struct internal_exec *execp = exec_hdr (abfd);
79*3d8817e4Smiod asection *sect;
80*3d8817e4Smiod struct external_segdesc ext[1];
81*3d8817e4Smiod char *section_name;
82*3d8817e4Smiod char try_again[30]; /* Name and number. */
83*3d8817e4Smiod char *newname;
84*3d8817e4Smiod int trynum;
85*3d8817e4Smiod flagword flags;
86*3d8817e4Smiod
87*3d8817e4Smiod /* Architecture and machine type -- unknown in this format. */
88*3d8817e4Smiod bfd_set_arch_mach (abfd, bfd_arch_unknown, 0L);
89*3d8817e4Smiod
90*3d8817e4Smiod /* The positions of the string table and symbol table. */
91*3d8817e4Smiod obj_str_filepos (abfd) = N_STROFF (*execp);
92*3d8817e4Smiod obj_sym_filepos (abfd) = N_SYMOFF (*execp);
93*3d8817e4Smiod
94*3d8817e4Smiod /* Suck up the section information from the file, one section at a time. */
95*3d8817e4Smiod for (;;)
96*3d8817e4Smiod {
97*3d8817e4Smiod bfd_size_type amt = sizeof (*ext);
98*3d8817e4Smiod if (bfd_bread ( ext, amt, abfd) != amt)
99*3d8817e4Smiod {
100*3d8817e4Smiod if (bfd_get_error () != bfd_error_system_call)
101*3d8817e4Smiod bfd_set_error (bfd_error_wrong_format);
102*3d8817e4Smiod
103*3d8817e4Smiod return NULL;
104*3d8817e4Smiod }
105*3d8817e4Smiod switch (ext->e_type[0])
106*3d8817e4Smiod {
107*3d8817e4Smiod case N_TEXT:
108*3d8817e4Smiod section_name = ".text";
109*3d8817e4Smiod flags = SEC_CODE | SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS;
110*3d8817e4Smiod break;
111*3d8817e4Smiod
112*3d8817e4Smiod case N_DATA:
113*3d8817e4Smiod section_name = ".data";
114*3d8817e4Smiod flags = SEC_DATA | SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS;
115*3d8817e4Smiod break;
116*3d8817e4Smiod
117*3d8817e4Smiod case N_BSS:
118*3d8817e4Smiod section_name = ".bss";
119*3d8817e4Smiod flags = SEC_DATA | SEC_HAS_CONTENTS;
120*3d8817e4Smiod break;
121*3d8817e4Smiod
122*3d8817e4Smiod case 0:
123*3d8817e4Smiod goto no_more_sections;
124*3d8817e4Smiod
125*3d8817e4Smiod default:
126*3d8817e4Smiod (*_bfd_error_handler)
127*3d8817e4Smiod (_("%B: Unknown section type in a.out.adobe file: %x\n"),
128*3d8817e4Smiod abfd, ext->e_type[0]);
129*3d8817e4Smiod goto no_more_sections;
130*3d8817e4Smiod }
131*3d8817e4Smiod
132*3d8817e4Smiod /* First one is called ".text" or whatever; subsequent ones are
133*3d8817e4Smiod ".text1", ".text2", ... */
134*3d8817e4Smiod bfd_set_error (bfd_error_no_error);
135*3d8817e4Smiod sect = bfd_make_section (abfd, section_name);
136*3d8817e4Smiod trynum = 0;
137*3d8817e4Smiod
138*3d8817e4Smiod while (!sect)
139*3d8817e4Smiod {
140*3d8817e4Smiod if (bfd_get_error () != bfd_error_no_error)
141*3d8817e4Smiod /* Some other error -- slide into the sunset. */
142*3d8817e4Smiod return NULL;
143*3d8817e4Smiod sprintf (try_again, "%s%d", section_name, ++trynum);
144*3d8817e4Smiod sect = bfd_make_section (abfd, try_again);
145*3d8817e4Smiod }
146*3d8817e4Smiod
147*3d8817e4Smiod /* Fix the name, if it is a sprintf'd name. */
148*3d8817e4Smiod if (sect->name == try_again)
149*3d8817e4Smiod {
150*3d8817e4Smiod amt = strlen (sect->name);
151*3d8817e4Smiod newname = bfd_zalloc (abfd, amt);
152*3d8817e4Smiod if (newname == NULL)
153*3d8817e4Smiod return NULL;
154*3d8817e4Smiod strcpy (newname, sect->name);
155*3d8817e4Smiod sect->name = newname;
156*3d8817e4Smiod }
157*3d8817e4Smiod
158*3d8817e4Smiod /* Now set the section's attributes. */
159*3d8817e4Smiod bfd_set_section_flags (abfd, sect, flags);
160*3d8817e4Smiod /* Assumed big-endian. */
161*3d8817e4Smiod sect->size = ((ext->e_size[0] << 8)
162*3d8817e4Smiod | ext->e_size[1] << 8
163*3d8817e4Smiod | ext->e_size[2]);
164*3d8817e4Smiod sect->vma = H_GET_32 (abfd, ext->e_virtbase);
165*3d8817e4Smiod sect->filepos = H_GET_32 (abfd, ext->e_filebase);
166*3d8817e4Smiod /* FIXME XXX alignment? */
167*3d8817e4Smiod
168*3d8817e4Smiod /* Set relocation information for first section of each type. */
169*3d8817e4Smiod if (trynum == 0)
170*3d8817e4Smiod switch (ext->e_type[0])
171*3d8817e4Smiod {
172*3d8817e4Smiod case N_TEXT:
173*3d8817e4Smiod sect->rel_filepos = N_TRELOFF (*execp);
174*3d8817e4Smiod sect->reloc_count = execp->a_trsize;
175*3d8817e4Smiod break;
176*3d8817e4Smiod
177*3d8817e4Smiod case N_DATA:
178*3d8817e4Smiod sect->rel_filepos = N_DRELOFF (*execp);
179*3d8817e4Smiod sect->reloc_count = execp->a_drsize;
180*3d8817e4Smiod break;
181*3d8817e4Smiod
182*3d8817e4Smiod default:
183*3d8817e4Smiod break;
184*3d8817e4Smiod }
185*3d8817e4Smiod }
186*3d8817e4Smiod no_more_sections:
187*3d8817e4Smiod
188*3d8817e4Smiod adata (abfd).reloc_entry_size = sizeof (struct reloc_std_external);
189*3d8817e4Smiod adata (abfd).symbol_entry_size = sizeof (struct external_nlist);
190*3d8817e4Smiod adata (abfd).page_size = 1; /* Not applicable. */
191*3d8817e4Smiod adata (abfd).segment_size = 1; /* Not applicable. */
192*3d8817e4Smiod adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
193*3d8817e4Smiod
194*3d8817e4Smiod return abfd->xvec;
195*3d8817e4Smiod }
196*3d8817e4Smiod
197*3d8817e4Smiod static const bfd_target *
aout_adobe_object_p(bfd * abfd)198*3d8817e4Smiod aout_adobe_object_p (bfd *abfd)
199*3d8817e4Smiod {
200*3d8817e4Smiod struct internal_exec anexec;
201*3d8817e4Smiod struct external_exec exec_bytes;
202*3d8817e4Smiod char *targ;
203*3d8817e4Smiod bfd_size_type amt = EXEC_BYTES_SIZE;
204*3d8817e4Smiod
205*3d8817e4Smiod if (bfd_bread (& exec_bytes, amt, abfd) != amt)
206*3d8817e4Smiod {
207*3d8817e4Smiod if (bfd_get_error () != bfd_error_system_call)
208*3d8817e4Smiod bfd_set_error (bfd_error_wrong_format);
209*3d8817e4Smiod return NULL;
210*3d8817e4Smiod }
211*3d8817e4Smiod
212*3d8817e4Smiod anexec.a_info = H_GET_32 (abfd, exec_bytes.e_info);
213*3d8817e4Smiod
214*3d8817e4Smiod /* Normally we just compare for the magic number.
215*3d8817e4Smiod However, a bunch of Adobe tools aren't fixed up yet; they generate
216*3d8817e4Smiod files using ZMAGIC(!).
217*3d8817e4Smiod If the environment variable GNUTARGET is set to "a.out.adobe", we will
218*3d8817e4Smiod take just about any a.out file as an Adobe a.out file. FIXME! */
219*3d8817e4Smiod
220*3d8817e4Smiod if (N_BADMAG (anexec))
221*3d8817e4Smiod {
222*3d8817e4Smiod targ = getenv ("GNUTARGET");
223*3d8817e4Smiod if (targ && !strcmp (targ, a_out_adobe_vec.name))
224*3d8817e4Smiod /* Just continue anyway, if specifically set to this format. */
225*3d8817e4Smiod ;
226*3d8817e4Smiod else
227*3d8817e4Smiod {
228*3d8817e4Smiod bfd_set_error (bfd_error_wrong_format);
229*3d8817e4Smiod return NULL;
230*3d8817e4Smiod }
231*3d8817e4Smiod }
232*3d8817e4Smiod
233*3d8817e4Smiod aout_adobe_swap_exec_header_in (abfd, &exec_bytes, &anexec);
234*3d8817e4Smiod return aout_32_some_aout_object_p (abfd, &anexec, aout_adobe_callback);
235*3d8817e4Smiod }
236*3d8817e4Smiod
237*3d8817e4Smiod struct bout_data_struct
238*3d8817e4Smiod {
239*3d8817e4Smiod struct aoutdata a;
240*3d8817e4Smiod struct internal_exec e;
241*3d8817e4Smiod };
242*3d8817e4Smiod
243*3d8817e4Smiod static bfd_boolean
aout_adobe_mkobject(bfd * abfd)244*3d8817e4Smiod aout_adobe_mkobject (bfd *abfd)
245*3d8817e4Smiod {
246*3d8817e4Smiod struct bout_data_struct *rawptr;
247*3d8817e4Smiod bfd_size_type amt = sizeof (struct bout_data_struct);
248*3d8817e4Smiod
249*3d8817e4Smiod rawptr = bfd_zalloc (abfd, amt);
250*3d8817e4Smiod if (rawptr == NULL)
251*3d8817e4Smiod return FALSE;
252*3d8817e4Smiod
253*3d8817e4Smiod abfd->tdata.bout_data = rawptr;
254*3d8817e4Smiod exec_hdr (abfd) = &rawptr->e;
255*3d8817e4Smiod
256*3d8817e4Smiod adata (abfd).reloc_entry_size = sizeof (struct reloc_std_external);
257*3d8817e4Smiod adata (abfd).symbol_entry_size = sizeof (struct external_nlist);
258*3d8817e4Smiod adata (abfd).page_size = 1; /* Not applicable. */
259*3d8817e4Smiod adata (abfd).segment_size = 1; /* Not applicable. */
260*3d8817e4Smiod adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
261*3d8817e4Smiod
262*3d8817e4Smiod return TRUE;
263*3d8817e4Smiod }
264*3d8817e4Smiod
265*3d8817e4Smiod static void
aout_adobe_write_section(bfd * abfd ATTRIBUTE_UNUSED,sec_ptr sect ATTRIBUTE_UNUSED)266*3d8817e4Smiod aout_adobe_write_section (bfd *abfd ATTRIBUTE_UNUSED,
267*3d8817e4Smiod sec_ptr sect ATTRIBUTE_UNUSED)
268*3d8817e4Smiod {
269*3d8817e4Smiod /* FIXME XXX. */
270*3d8817e4Smiod }
271*3d8817e4Smiod
272*3d8817e4Smiod static bfd_boolean
aout_adobe_write_object_contents(bfd * abfd)273*3d8817e4Smiod aout_adobe_write_object_contents (bfd *abfd)
274*3d8817e4Smiod {
275*3d8817e4Smiod struct external_exec swapped_hdr;
276*3d8817e4Smiod static struct external_segdesc sentinel[1]; /* Initialized to zero. */
277*3d8817e4Smiod asection *sect;
278*3d8817e4Smiod bfd_size_type amt;
279*3d8817e4Smiod
280*3d8817e4Smiod exec_hdr (abfd)->a_info = ZMAGIC;
281*3d8817e4Smiod
282*3d8817e4Smiod /* Calculate text size as total of text sections, etc. */
283*3d8817e4Smiod exec_hdr (abfd)->a_text = 0;
284*3d8817e4Smiod exec_hdr (abfd)->a_data = 0;
285*3d8817e4Smiod exec_hdr (abfd)->a_bss = 0;
286*3d8817e4Smiod exec_hdr (abfd)->a_trsize = 0;
287*3d8817e4Smiod exec_hdr (abfd)->a_drsize = 0;
288*3d8817e4Smiod
289*3d8817e4Smiod for (sect = abfd->sections; sect; sect = sect->next)
290*3d8817e4Smiod {
291*3d8817e4Smiod if (sect->flags & SEC_CODE)
292*3d8817e4Smiod {
293*3d8817e4Smiod exec_hdr (abfd)->a_text += sect->size;
294*3d8817e4Smiod exec_hdr (abfd)->a_trsize += sect->reloc_count *
295*3d8817e4Smiod sizeof (struct reloc_std_external);
296*3d8817e4Smiod }
297*3d8817e4Smiod else if (sect->flags & SEC_DATA)
298*3d8817e4Smiod {
299*3d8817e4Smiod exec_hdr (abfd)->a_data += sect->size;
300*3d8817e4Smiod exec_hdr (abfd)->a_drsize += sect->reloc_count *
301*3d8817e4Smiod sizeof (struct reloc_std_external);
302*3d8817e4Smiod }
303*3d8817e4Smiod else if (sect->flags & SEC_ALLOC && !(sect->flags & SEC_LOAD))
304*3d8817e4Smiod exec_hdr (abfd)->a_bss += sect->size;
305*3d8817e4Smiod }
306*3d8817e4Smiod
307*3d8817e4Smiod exec_hdr (abfd)->a_syms = bfd_get_symcount (abfd)
308*3d8817e4Smiod * sizeof (struct external_nlist);
309*3d8817e4Smiod exec_hdr (abfd)->a_entry = bfd_get_start_address (abfd);
310*3d8817e4Smiod
311*3d8817e4Smiod aout_adobe_swap_exec_header_out (abfd, exec_hdr (abfd), &swapped_hdr);
312*3d8817e4Smiod
313*3d8817e4Smiod amt = EXEC_BYTES_SIZE;
314*3d8817e4Smiod if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
315*3d8817e4Smiod || bfd_bwrite (& swapped_hdr, amt, abfd) != amt)
316*3d8817e4Smiod return FALSE;
317*3d8817e4Smiod
318*3d8817e4Smiod /* Now write out the section information. Text first, data next, rest
319*3d8817e4Smiod afterward. */
320*3d8817e4Smiod for (sect = abfd->sections; sect; sect = sect->next)
321*3d8817e4Smiod if (sect->flags & SEC_CODE)
322*3d8817e4Smiod aout_adobe_write_section (abfd, sect);
323*3d8817e4Smiod
324*3d8817e4Smiod for (sect = abfd->sections; sect; sect = sect->next)
325*3d8817e4Smiod if (sect->flags & SEC_DATA)
326*3d8817e4Smiod aout_adobe_write_section (abfd, sect);
327*3d8817e4Smiod
328*3d8817e4Smiod for (sect = abfd->sections; sect; sect = sect->next)
329*3d8817e4Smiod if (!(sect->flags & (SEC_CODE | SEC_DATA)))
330*3d8817e4Smiod aout_adobe_write_section (abfd, sect);
331*3d8817e4Smiod
332*3d8817e4Smiod /* Write final `sentinel` section header (with type of 0). */
333*3d8817e4Smiod amt = sizeof (*sentinel);
334*3d8817e4Smiod if (bfd_bwrite (sentinel, amt, abfd) != amt)
335*3d8817e4Smiod return FALSE;
336*3d8817e4Smiod
337*3d8817e4Smiod /* Now write out reloc info, followed by syms and strings. */
338*3d8817e4Smiod if (bfd_get_symcount (abfd) != 0)
339*3d8817e4Smiod {
340*3d8817e4Smiod if (bfd_seek (abfd, (file_ptr) (N_SYMOFF (*exec_hdr (abfd))), SEEK_SET)
341*3d8817e4Smiod != 0)
342*3d8817e4Smiod return FALSE;
343*3d8817e4Smiod
344*3d8817e4Smiod if (! aout_32_write_syms (abfd))
345*3d8817e4Smiod return FALSE;
346*3d8817e4Smiod
347*3d8817e4Smiod if (bfd_seek (abfd, (file_ptr) (N_TRELOFF (*exec_hdr (abfd))), SEEK_SET)
348*3d8817e4Smiod != 0)
349*3d8817e4Smiod return FALSE;
350*3d8817e4Smiod
351*3d8817e4Smiod for (sect = abfd->sections; sect; sect = sect->next)
352*3d8817e4Smiod if (sect->flags & SEC_CODE)
353*3d8817e4Smiod if (!aout_32_squirt_out_relocs (abfd, sect))
354*3d8817e4Smiod return FALSE;
355*3d8817e4Smiod
356*3d8817e4Smiod if (bfd_seek (abfd, (file_ptr) (N_DRELOFF (*exec_hdr (abfd))), SEEK_SET)
357*3d8817e4Smiod != 0)
358*3d8817e4Smiod return FALSE;
359*3d8817e4Smiod
360*3d8817e4Smiod for (sect = abfd->sections; sect; sect = sect->next)
361*3d8817e4Smiod if (sect->flags & SEC_DATA)
362*3d8817e4Smiod if (!aout_32_squirt_out_relocs (abfd, sect))
363*3d8817e4Smiod return FALSE;
364*3d8817e4Smiod }
365*3d8817e4Smiod
366*3d8817e4Smiod return TRUE;
367*3d8817e4Smiod }
368*3d8817e4Smiod
369*3d8817e4Smiod static bfd_boolean
aout_adobe_set_section_contents(bfd * abfd,asection * section,const void * location,file_ptr offset,bfd_size_type count)370*3d8817e4Smiod aout_adobe_set_section_contents (bfd *abfd,
371*3d8817e4Smiod asection *section,
372*3d8817e4Smiod const void * location,
373*3d8817e4Smiod file_ptr offset,
374*3d8817e4Smiod bfd_size_type count)
375*3d8817e4Smiod {
376*3d8817e4Smiod file_ptr section_start;
377*3d8817e4Smiod sec_ptr sect;
378*3d8817e4Smiod
379*3d8817e4Smiod /* Set by bfd.c handler. */
380*3d8817e4Smiod if (! abfd->output_has_begun)
381*3d8817e4Smiod {
382*3d8817e4Smiod /* Assign file offsets to sections. Text sections are first, and
383*3d8817e4Smiod are contiguous. Then data sections. Everything else at the end. */
384*3d8817e4Smiod section_start = N_TXTOFF (ignore<-->me);
385*3d8817e4Smiod
386*3d8817e4Smiod for (sect = abfd->sections; sect; sect = sect->next)
387*3d8817e4Smiod {
388*3d8817e4Smiod if (sect->flags & SEC_CODE)
389*3d8817e4Smiod {
390*3d8817e4Smiod sect->filepos = section_start;
391*3d8817e4Smiod /* FIXME: Round to alignment. */
392*3d8817e4Smiod section_start += sect->size;
393*3d8817e4Smiod }
394*3d8817e4Smiod }
395*3d8817e4Smiod
396*3d8817e4Smiod for (sect = abfd->sections; sect; sect = sect->next)
397*3d8817e4Smiod {
398*3d8817e4Smiod if (sect->flags & SEC_DATA)
399*3d8817e4Smiod {
400*3d8817e4Smiod sect->filepos = section_start;
401*3d8817e4Smiod /* FIXME: Round to alignment. */
402*3d8817e4Smiod section_start += sect->size;
403*3d8817e4Smiod }
404*3d8817e4Smiod }
405*3d8817e4Smiod
406*3d8817e4Smiod for (sect = abfd->sections; sect; sect = sect->next)
407*3d8817e4Smiod {
408*3d8817e4Smiod if (sect->flags & SEC_HAS_CONTENTS &&
409*3d8817e4Smiod !(sect->flags & (SEC_CODE | SEC_DATA)))
410*3d8817e4Smiod {
411*3d8817e4Smiod sect->filepos = section_start;
412*3d8817e4Smiod /* FIXME: Round to alignment. */
413*3d8817e4Smiod section_start += sect->size;
414*3d8817e4Smiod }
415*3d8817e4Smiod }
416*3d8817e4Smiod }
417*3d8817e4Smiod
418*3d8817e4Smiod /* Regardless, once we know what we're doing, we might as well get
419*3d8817e4Smiod going. */
420*3d8817e4Smiod if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
421*3d8817e4Smiod return FALSE;
422*3d8817e4Smiod
423*3d8817e4Smiod if (count == 0)
424*3d8817e4Smiod return TRUE;
425*3d8817e4Smiod
426*3d8817e4Smiod return bfd_bwrite (location, count, abfd) == count;
427*3d8817e4Smiod }
428*3d8817e4Smiod
429*3d8817e4Smiod static bfd_boolean
aout_adobe_set_arch_mach(bfd * abfd,enum bfd_architecture arch,unsigned long machine)430*3d8817e4Smiod aout_adobe_set_arch_mach (bfd *abfd,
431*3d8817e4Smiod enum bfd_architecture arch,
432*3d8817e4Smiod unsigned long machine)
433*3d8817e4Smiod {
434*3d8817e4Smiod if (! bfd_default_set_arch_mach (abfd, arch, machine))
435*3d8817e4Smiod return FALSE;
436*3d8817e4Smiod
437*3d8817e4Smiod if (arch == bfd_arch_unknown
438*3d8817e4Smiod || arch == bfd_arch_m68k)
439*3d8817e4Smiod return TRUE;
440*3d8817e4Smiod
441*3d8817e4Smiod return FALSE;
442*3d8817e4Smiod }
443*3d8817e4Smiod
444*3d8817e4Smiod static int
aout_adobe_sizeof_headers(bfd * ignore_abfd ATTRIBUTE_UNUSED,bfd_boolean ignore ATTRIBUTE_UNUSED)445*3d8817e4Smiod aout_adobe_sizeof_headers (bfd *ignore_abfd ATTRIBUTE_UNUSED,
446*3d8817e4Smiod bfd_boolean ignore ATTRIBUTE_UNUSED)
447*3d8817e4Smiod {
448*3d8817e4Smiod return sizeof (struct internal_exec);
449*3d8817e4Smiod }
450*3d8817e4Smiod
451*3d8817e4Smiod /* Build the transfer vector for Adobe A.Out files. */
452*3d8817e4Smiod
453*3d8817e4Smiod #define aout_32_bfd_make_debug_symbol ((asymbol *(*) (bfd *, void *, unsigned long)) bfd_nullvoidptr)
454*3d8817e4Smiod #define aout_32_bfd_reloc_type_lookup ((reloc_howto_type *(*) (bfd *, bfd_reloc_code_real_type)) bfd_nullvoidptr)
455*3d8817e4Smiod #define aout_32_close_and_cleanup aout_32_bfd_free_cached_info
456*3d8817e4Smiod #define aout_32_set_arch_mach aout_adobe_set_arch_mach
457*3d8817e4Smiod #define aout_32_set_section_contents aout_adobe_set_section_contents
458*3d8817e4Smiod #define aout_32_sizeof_headers aout_adobe_sizeof_headers
459*3d8817e4Smiod #define aout_32_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
460*3d8817e4Smiod #define aout_32_get_section_contents_in_window _bfd_generic_get_section_contents_in_window
461*3d8817e4Smiod #define aout_32_bfd_relax_section bfd_generic_relax_section
462*3d8817e4Smiod #define aout_32_bfd_gc_sections bfd_generic_gc_sections
463*3d8817e4Smiod #define aout_32_bfd_merge_sections bfd_generic_merge_sections
464*3d8817e4Smiod #define aout_32_bfd_is_group_section bfd_generic_is_group_section
465*3d8817e4Smiod #define aout_32_bfd_discard_group bfd_generic_discard_group
466*3d8817e4Smiod #define aout_32_section_already_linked _bfd_generic_section_already_linked
467*3d8817e4Smiod #define aout_32_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
468*3d8817e4Smiod #define aout_32_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
469*3d8817e4Smiod #define aout_32_bfd_link_add_symbols _bfd_generic_link_add_symbols
470*3d8817e4Smiod #define aout_32_bfd_link_just_syms _bfd_generic_link_just_syms
471*3d8817e4Smiod #define aout_32_bfd_final_link _bfd_generic_final_link
472*3d8817e4Smiod #define aout_32_bfd_link_split_section _bfd_generic_link_split_section
473*3d8817e4Smiod
474*3d8817e4Smiod const bfd_target a_out_adobe_vec =
475*3d8817e4Smiod {
476*3d8817e4Smiod "a.out.adobe", /* Name. */
477*3d8817e4Smiod bfd_target_aout_flavour,
478*3d8817e4Smiod BFD_ENDIAN_BIG, /* Data byte order is unknown (big assumed). */
479*3d8817e4Smiod BFD_ENDIAN_BIG, /* Header byte order is big. */
480*3d8817e4Smiod (HAS_RELOC | EXEC_P | /* Object flags. */
481*3d8817e4Smiod HAS_LINENO | HAS_DEBUG |
482*3d8817e4Smiod HAS_SYMS | HAS_LOCALS | WP_TEXT ),
483*3d8817e4Smiod /* section flags */
484*3d8817e4Smiod (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_DATA | SEC_RELOC),
485*3d8817e4Smiod '_', /* Symbol leading char. */
486*3d8817e4Smiod ' ', /* AR_pad_char. */
487*3d8817e4Smiod 16, /* AR_max_namelen. */
488*3d8817e4Smiod
489*3d8817e4Smiod bfd_getb64, bfd_getb_signed_64, bfd_putb64,
490*3d8817e4Smiod bfd_getb32, bfd_getb_signed_32, bfd_putb32,
491*3d8817e4Smiod bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */
492*3d8817e4Smiod bfd_getb64, bfd_getb_signed_64, bfd_putb64,
493*3d8817e4Smiod bfd_getb32, bfd_getb_signed_32, bfd_putb32,
494*3d8817e4Smiod bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Headers. */
495*3d8817e4Smiod
496*3d8817e4Smiod {_bfd_dummy_target, aout_adobe_object_p, /* bfd_check_format. */
497*3d8817e4Smiod bfd_generic_archive_p, _bfd_dummy_target},
498*3d8817e4Smiod {bfd_false, aout_adobe_mkobject, /* bfd_set_format. */
499*3d8817e4Smiod _bfd_generic_mkarchive, bfd_false},
500*3d8817e4Smiod {bfd_false, aout_adobe_write_object_contents,/* bfd_write_contents. */
501*3d8817e4Smiod _bfd_write_archive_contents, bfd_false},
502*3d8817e4Smiod
503*3d8817e4Smiod BFD_JUMP_TABLE_GENERIC (aout_32),
504*3d8817e4Smiod BFD_JUMP_TABLE_COPY (_bfd_generic),
505*3d8817e4Smiod BFD_JUMP_TABLE_CORE (_bfd_nocore),
506*3d8817e4Smiod BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd),
507*3d8817e4Smiod BFD_JUMP_TABLE_SYMBOLS (aout_32),
508*3d8817e4Smiod BFD_JUMP_TABLE_RELOCS (aout_32),
509*3d8817e4Smiod BFD_JUMP_TABLE_WRITE (aout_32),
510*3d8817e4Smiod BFD_JUMP_TABLE_LINK (aout_32),
511*3d8817e4Smiod BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
512*3d8817e4Smiod
513*3d8817e4Smiod NULL,
514*3d8817e4Smiod
515*3d8817e4Smiod NULL
516*3d8817e4Smiod };
517