1 /* Support for the generic parts of most COFF variants, for BFD.
2 Copyright 1995, 1996, 1997 Free Software Foundation, Inc.
3 Written by Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 Most of this hacked by Steve Chamberlain,
26 /* Hey look, some documentation [and in a place you expect to find it]!
28 The main reference for the pei format is "Microsoft Portable Executable
29 and Common Object File Format Specification 4.1". Get it if you need to
30 do some serious hacking on this code.
33 "Peering Inside the PE: A Tour of the Win32 Portable Executable
34 File Format", MSJ 1994, Volume 9.
36 The *sole* difference between the pe format and the pei format is that the
37 latter has an MSDOS 2.0 .exe header on the front that prints the message
38 "This app must be run under Windows." (or some such).
39 (FIXME: Whether that statement is *really* true or not is unknown.
40 Are there more subtle differences between pe and pei formats?
41 For now assume there aren't. If you find one, then for God sakes
44 The Microsoft docs use the word "image" instead of "executable" because
45 the former can also refer to a DLL (shared library). Confusion can arise
46 because the `i' in `pei' also refers to "image". The `pe' format can
47 also create images (i.e. executables), it's just that to run on a win32
48 system you need to use the pei format.
50 FIXME: Please add more docs here so the next poor fool that has to hack
51 on this code has a chance of getting something accomplished without
52 wasting too much time.
55 #define coff_bfd_print_private_bfd_data pe_print_private_bfd_data
56 #define coff_mkobject pe_mkobject
57 #define coff_mkobject_hook pe_mkobject_hook
59 #ifndef GET_FCN_LNNOPTR
60 #define GET_FCN_LNNOPTR(abfd, ext) \
61 bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
64 #ifndef GET_FCN_ENDNDX
65 #define GET_FCN_ENDNDX(abfd, ext) \
66 bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
69 #ifndef PUT_FCN_LNNOPTR
70 #define PUT_FCN_LNNOPTR(abfd, in, ext) bfd_h_put_32(abfd, in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
72 #ifndef PUT_FCN_ENDNDX
73 #define PUT_FCN_ENDNDX(abfd, in, ext) bfd_h_put_32(abfd, in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
76 #define GET_LNSZ_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_lnno)
79 #define GET_LNSZ_SIZE(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_size)
82 #define PUT_LNSZ_LNNO(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_sym.x_misc.x_lnsz.x_lnno)
85 #define PUT_LNSZ_SIZE(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte*) ext->x_sym.x_misc.x_lnsz.x_size)
87 #ifndef GET_SCN_SCNLEN
88 #define GET_SCN_SCNLEN(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_scn.x_scnlen)
90 #ifndef GET_SCN_NRELOC
91 #define GET_SCN_NRELOC(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nreloc)
93 #ifndef GET_SCN_NLINNO
94 #define GET_SCN_NLINNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nlinno)
96 #ifndef PUT_SCN_SCNLEN
97 #define PUT_SCN_SCNLEN(abfd,in, ext) bfd_h_put_32(abfd, in, (bfd_byte *) ext->x_scn.x_scnlen)
99 #ifndef PUT_SCN_NRELOC
100 #define PUT_SCN_NRELOC(abfd,in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_scn.x_nreloc)
102 #ifndef PUT_SCN_NLINNO
103 #define PUT_SCN_NLINNO(abfd,in, ext) bfd_h_put_16(abfd,in, (bfd_byte *) ext->x_scn.x_nlinno)
105 #ifndef GET_LINENO_LNNO
106 #define GET_LINENO_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) (ext->l_lnno));
108 #ifndef PUT_LINENO_LNNO
109 #define PUT_LINENO_LNNO(abfd,val, ext) bfd_h_put_16(abfd,val, (bfd_byte *) (ext->l_lnno));
112 /* The f_symptr field in the filehdr is sometimes 64 bits. */
113 #ifndef GET_FILEHDR_SYMPTR
114 #define GET_FILEHDR_SYMPTR bfd_h_get_32
116 #ifndef PUT_FILEHDR_SYMPTR
117 #define PUT_FILEHDR_SYMPTR bfd_h_put_32
120 /* Some fields in the aouthdr are sometimes 64 bits. */
121 #ifndef GET_AOUTHDR_TSIZE
122 #define GET_AOUTHDR_TSIZE bfd_h_get_32
124 #ifndef PUT_AOUTHDR_TSIZE
125 #define PUT_AOUTHDR_TSIZE bfd_h_put_32
127 #ifndef GET_AOUTHDR_DSIZE
128 #define GET_AOUTHDR_DSIZE bfd_h_get_32
130 #ifndef PUT_AOUTHDR_DSIZE
131 #define PUT_AOUTHDR_DSIZE bfd_h_put_32
133 #ifndef GET_AOUTHDR_BSIZE
134 #define GET_AOUTHDR_BSIZE bfd_h_get_32
136 #ifndef PUT_AOUTHDR_BSIZE
137 #define PUT_AOUTHDR_BSIZE bfd_h_put_32
139 #ifndef GET_AOUTHDR_ENTRY
140 #define GET_AOUTHDR_ENTRY bfd_h_get_32
142 #ifndef PUT_AOUTHDR_ENTRY
143 #define PUT_AOUTHDR_ENTRY bfd_h_put_32
145 #ifndef GET_AOUTHDR_TEXT_START
146 #define GET_AOUTHDR_TEXT_START bfd_h_get_32
148 #ifndef PUT_AOUTHDR_TEXT_START
149 #define PUT_AOUTHDR_TEXT_START bfd_h_put_32
151 #ifndef GET_AOUTHDR_DATA_START
152 #define GET_AOUTHDR_DATA_START bfd_h_get_32
154 #ifndef PUT_AOUTHDR_DATA_START
155 #define PUT_AOUTHDR_DATA_START bfd_h_put_32
158 /* Some fields in the scnhdr are sometimes 64 bits. */
159 #ifndef GET_SCNHDR_PADDR
160 #define GET_SCNHDR_PADDR bfd_h_get_32
162 #ifndef PUT_SCNHDR_PADDR
163 #define PUT_SCNHDR_PADDR bfd_h_put_32
165 #ifndef GET_SCNHDR_VADDR
166 #define GET_SCNHDR_VADDR bfd_h_get_32
168 #ifndef PUT_SCNHDR_VADDR
169 #define PUT_SCNHDR_VADDR bfd_h_put_32
171 #ifndef GET_SCNHDR_SIZE
172 #define GET_SCNHDR_SIZE bfd_h_get_32
174 #ifndef PUT_SCNHDR_SIZE
175 #define PUT_SCNHDR_SIZE bfd_h_put_32
177 #ifndef GET_SCNHDR_SCNPTR
178 #define GET_SCNHDR_SCNPTR bfd_h_get_32
180 #ifndef PUT_SCNHDR_SCNPTR
181 #define PUT_SCNHDR_SCNPTR bfd_h_put_32
183 #ifndef GET_SCNHDR_RELPTR
184 #define GET_SCNHDR_RELPTR bfd_h_get_32
186 #ifndef PUT_SCNHDR_RELPTR
187 #define PUT_SCNHDR_RELPTR bfd_h_put_32
189 #ifndef GET_SCNHDR_LNNOPTR
190 #define GET_SCNHDR_LNNOPTR bfd_h_get_32
192 #ifndef PUT_SCNHDR_LNNOPTR
193 #define PUT_SCNHDR_LNNOPTR bfd_h_put_32
196 static void coff_swap_reloc_in PARAMS ((bfd *, PTR, PTR));
197 static unsigned int coff_swap_reloc_out PARAMS ((bfd *, PTR, PTR));
198 static void coff_swap_filehdr_in PARAMS ((bfd *, PTR, PTR));
199 static unsigned int coff_swap_filehdr_out PARAMS ((bfd *, PTR, PTR));
200 static void coff_swap_sym_in PARAMS ((bfd *, PTR, PTR));
201 static unsigned int coff_swap_sym_out PARAMS ((bfd *, PTR, PTR));
202 static void coff_swap_aux_in PARAMS ((bfd *, PTR, int, int, int, int, PTR));
203 static unsigned int coff_swap_aux_out
204 PARAMS ((bfd *, PTR, int, int, int, int, PTR));
205 static void coff_swap_lineno_in PARAMS ((bfd *, PTR, PTR));
206 static unsigned int coff_swap_lineno_out PARAMS ((bfd *, PTR, PTR));
207 static void coff_swap_aouthdr_in PARAMS ((bfd *, PTR, PTR));
208 static void add_data_entry
209 PARAMS ((bfd *, struct internal_extra_pe_aouthdr *, int, char *, bfd_vma));
210 static unsigned int coff_swap_aouthdr_out PARAMS ((bfd *, PTR, PTR));
211 static void coff_swap_scnhdr_in PARAMS ((bfd *, PTR, PTR));
212 static unsigned int coff_swap_scnhdr_out PARAMS ((bfd *, PTR, PTR));
213 static boolean pe_print_idata PARAMS ((bfd *, PTR));
214 static boolean pe_print_edata PARAMS ((bfd *, PTR));
215 static boolean pe_print_pdata PARAMS ((bfd *, PTR));
216 static boolean pe_print_reloc PARAMS ((bfd *, PTR));
217 static boolean pe_print_private_bfd_data PARAMS ((bfd *, PTR));
218 static boolean pe_mkobject PARAMS ((bfd *));
219 static PTR pe_mkobject_hook PARAMS ((bfd *, PTR, PTR));
220 static boolean pe_bfd_copy_private_bfd_data PARAMS ((bfd *, bfd *));
222 /**********************************************************************/
225 coff_swap_reloc_in (abfd, src, dst)
230 RELOC *reloc_src = (RELOC *) src;
231 struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
233 reloc_dst->r_vaddr = bfd_h_get_32(abfd, (bfd_byte *)reloc_src->r_vaddr);
234 reloc_dst->r_symndx = bfd_h_get_signed_32(abfd, (bfd_byte *) reloc_src->r_symndx);
236 reloc_dst->r_type = bfd_h_get_16(abfd, (bfd_byte *) reloc_src->r_type);
238 #ifdef SWAP_IN_RELOC_OFFSET
239 reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET(abfd,
240 (bfd_byte *) reloc_src->r_offset);
246 coff_swap_reloc_out (abfd, src, dst)
251 struct internal_reloc *reloc_src = (struct internal_reloc *)src;
252 struct external_reloc *reloc_dst = (struct external_reloc *)dst;
253 bfd_h_put_32(abfd, reloc_src->r_vaddr, (bfd_byte *) reloc_dst->r_vaddr);
254 bfd_h_put_32(abfd, reloc_src->r_symndx, (bfd_byte *) reloc_dst->r_symndx);
256 bfd_h_put_16(abfd, reloc_src->r_type, (bfd_byte *)
259 #ifdef SWAP_OUT_RELOC_OFFSET
260 SWAP_OUT_RELOC_OFFSET(abfd,
262 (bfd_byte *) reloc_dst->r_offset);
264 #ifdef SWAP_OUT_RELOC_EXTRA
265 SWAP_OUT_RELOC_EXTRA(abfd,reloc_src, reloc_dst);
272 coff_swap_filehdr_in (abfd, src, dst)
277 FILHDR *filehdr_src = (FILHDR *) src;
278 struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
279 filehdr_dst->f_magic = bfd_h_get_16(abfd, (bfd_byte *) filehdr_src->f_magic);
280 filehdr_dst->f_nscns = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_nscns);
281 filehdr_dst->f_timdat = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_timdat);
283 filehdr_dst->f_nsyms = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_nsyms);
284 filehdr_dst->f_flags = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_flags);
285 filehdr_dst->f_symptr = bfd_h_get_32 (abfd, (bfd_byte *) filehdr_src->f_symptr);
287 /* Other people's tools sometimes generate headers
288 with an nsyms but a zero symptr. */
289 if (filehdr_dst->f_nsyms && filehdr_dst->f_symptr)
291 filehdr_dst->f_flags |= HAS_SYMS;
295 filehdr_dst->f_nsyms = 0;
296 filehdr_dst->f_flags &= ~HAS_SYMS;
299 filehdr_dst->f_opthdr = bfd_h_get_16(abfd,
300 (bfd_byte *)filehdr_src-> f_opthdr);
303 #ifdef COFF_IMAGE_WITH_PE
306 coff_swap_filehdr_out (abfd, in, out)
312 struct internal_filehdr *filehdr_in = (struct internal_filehdr *)in;
313 FILHDR *filehdr_out = (FILHDR *)out;
315 if (pe_data (abfd)->has_reloc_section)
316 filehdr_in->f_flags &= ~F_RELFLG;
318 if (pe_data (abfd)->dll)
319 filehdr_in->f_flags |= F_DLL;
321 filehdr_in->pe.e_magic = DOSMAGIC;
322 filehdr_in->pe.e_cblp = 0x90;
323 filehdr_in->pe.e_cp = 0x3;
324 filehdr_in->pe.e_crlc = 0x0;
325 filehdr_in->pe.e_cparhdr = 0x4;
326 filehdr_in->pe.e_minalloc = 0x0;
327 filehdr_in->pe.e_maxalloc = 0xffff;
328 filehdr_in->pe.e_ss = 0x0;
329 filehdr_in->pe.e_sp = 0xb8;
330 filehdr_in->pe.e_csum = 0x0;
331 filehdr_in->pe.e_ip = 0x0;
332 filehdr_in->pe.e_cs = 0x0;
333 filehdr_in->pe.e_lfarlc = 0x40;
334 filehdr_in->pe.e_ovno = 0x0;
336 for (idx=0; idx < 4; idx++)
337 filehdr_in->pe.e_res[idx] = 0x0;
339 filehdr_in->pe.e_oemid = 0x0;
340 filehdr_in->pe.e_oeminfo = 0x0;
342 for (idx=0; idx < 10; idx++)
343 filehdr_in->pe.e_res2[idx] = 0x0;
345 filehdr_in->pe.e_lfanew = 0x80;
347 /* this next collection of data are mostly just characters. It appears
348 to be constant within the headers put on NT exes */
349 filehdr_in->pe.dos_message[0] = 0x0eba1f0e;
350 filehdr_in->pe.dos_message[1] = 0xcd09b400;
351 filehdr_in->pe.dos_message[2] = 0x4c01b821;
352 filehdr_in->pe.dos_message[3] = 0x685421cd;
353 filehdr_in->pe.dos_message[4] = 0x70207369;
354 filehdr_in->pe.dos_message[5] = 0x72676f72;
355 filehdr_in->pe.dos_message[6] = 0x63206d61;
356 filehdr_in->pe.dos_message[7] = 0x6f6e6e61;
357 filehdr_in->pe.dos_message[8] = 0x65622074;
358 filehdr_in->pe.dos_message[9] = 0x6e757220;
359 filehdr_in->pe.dos_message[10] = 0x206e6920;
360 filehdr_in->pe.dos_message[11] = 0x20534f44;
361 filehdr_in->pe.dos_message[12] = 0x65646f6d;
362 filehdr_in->pe.dos_message[13] = 0x0a0d0d2e;
363 filehdr_in->pe.dos_message[14] = 0x24;
364 filehdr_in->pe.dos_message[15] = 0x0;
365 filehdr_in->pe.nt_signature = NT_SIGNATURE;
369 bfd_h_put_16(abfd, filehdr_in->f_magic, (bfd_byte *) filehdr_out->f_magic);
370 bfd_h_put_16(abfd, filehdr_in->f_nscns, (bfd_byte *) filehdr_out->f_nscns);
372 bfd_h_put_32(abfd, time (0), (bfd_byte *) filehdr_out->f_timdat);
373 PUT_FILEHDR_SYMPTR (abfd, (bfd_vma) filehdr_in->f_symptr,
374 (bfd_byte *) filehdr_out->f_symptr);
375 bfd_h_put_32(abfd, filehdr_in->f_nsyms, (bfd_byte *) filehdr_out->f_nsyms);
376 bfd_h_put_16(abfd, filehdr_in->f_opthdr, (bfd_byte *) filehdr_out->f_opthdr);
377 bfd_h_put_16(abfd, filehdr_in->f_flags, (bfd_byte *) filehdr_out->f_flags);
379 /* put in extra dos header stuff. This data remains essentially
380 constant, it just has to be tacked on to the beginning of all exes
382 bfd_h_put_16(abfd, filehdr_in->pe.e_magic, (bfd_byte *) filehdr_out->e_magic);
383 bfd_h_put_16(abfd, filehdr_in->pe.e_cblp, (bfd_byte *) filehdr_out->e_cblp);
384 bfd_h_put_16(abfd, filehdr_in->pe.e_cp, (bfd_byte *) filehdr_out->e_cp);
385 bfd_h_put_16(abfd, filehdr_in->pe.e_crlc, (bfd_byte *) filehdr_out->e_crlc);
386 bfd_h_put_16(abfd, filehdr_in->pe.e_cparhdr,
387 (bfd_byte *) filehdr_out->e_cparhdr);
388 bfd_h_put_16(abfd, filehdr_in->pe.e_minalloc,
389 (bfd_byte *) filehdr_out->e_minalloc);
390 bfd_h_put_16(abfd, filehdr_in->pe.e_maxalloc,
391 (bfd_byte *) filehdr_out->e_maxalloc);
392 bfd_h_put_16(abfd, filehdr_in->pe.e_ss, (bfd_byte *) filehdr_out->e_ss);
393 bfd_h_put_16(abfd, filehdr_in->pe.e_sp, (bfd_byte *) filehdr_out->e_sp);
394 bfd_h_put_16(abfd, filehdr_in->pe.e_csum, (bfd_byte *) filehdr_out->e_csum);
395 bfd_h_put_16(abfd, filehdr_in->pe.e_ip, (bfd_byte *) filehdr_out->e_ip);
396 bfd_h_put_16(abfd, filehdr_in->pe.e_cs, (bfd_byte *) filehdr_out->e_cs);
397 bfd_h_put_16(abfd, filehdr_in->pe.e_lfarlc, (bfd_byte *) filehdr_out->e_lfarlc);
398 bfd_h_put_16(abfd, filehdr_in->pe.e_ovno, (bfd_byte *) filehdr_out->e_ovno);
401 for (idx=0; idx < 4; idx++)
402 bfd_h_put_16(abfd, filehdr_in->pe.e_res[idx],
403 (bfd_byte *) filehdr_out->e_res[idx]);
405 bfd_h_put_16(abfd, filehdr_in->pe.e_oemid, (bfd_byte *) filehdr_out->e_oemid);
406 bfd_h_put_16(abfd, filehdr_in->pe.e_oeminfo,
407 (bfd_byte *) filehdr_out->e_oeminfo);
410 for (idx=0; idx < 10; idx++)
411 bfd_h_put_16(abfd, filehdr_in->pe.e_res2[idx],
412 (bfd_byte *) filehdr_out->e_res2[idx]);
414 bfd_h_put_32(abfd, filehdr_in->pe.e_lfanew, (bfd_byte *) filehdr_out->e_lfanew);
418 for (idx=0; idx < 16; idx++)
419 bfd_h_put_32(abfd, filehdr_in->pe.dos_message[idx],
420 (bfd_byte *) filehdr_out->dos_message[idx]);
423 /* also put in the NT signature */
424 bfd_h_put_32(abfd, filehdr_in->pe.nt_signature,
425 (bfd_byte *) filehdr_out->nt_signature);
435 coff_swap_filehdr_out (abfd, in, out)
440 struct internal_filehdr *filehdr_in = (struct internal_filehdr *)in;
441 FILHDR *filehdr_out = (FILHDR *)out;
443 bfd_h_put_16(abfd, filehdr_in->f_magic, (bfd_byte *) filehdr_out->f_magic);
444 bfd_h_put_16(abfd, filehdr_in->f_nscns, (bfd_byte *) filehdr_out->f_nscns);
445 bfd_h_put_32(abfd, filehdr_in->f_timdat, (bfd_byte *) filehdr_out->f_timdat);
446 PUT_FILEHDR_SYMPTR (abfd, (bfd_vma) filehdr_in->f_symptr,
447 (bfd_byte *) filehdr_out->f_symptr);
448 bfd_h_put_32(abfd, filehdr_in->f_nsyms, (bfd_byte *) filehdr_out->f_nsyms);
449 bfd_h_put_16(abfd, filehdr_in->f_opthdr, (bfd_byte *) filehdr_out->f_opthdr);
450 bfd_h_put_16(abfd, filehdr_in->f_flags, (bfd_byte *) filehdr_out->f_flags);
459 coff_swap_sym_in (abfd, ext1, in1)
464 SYMENT *ext = (SYMENT *)ext1;
465 struct internal_syment *in = (struct internal_syment *)in1;
467 if( ext->e.e_name[0] == 0) {
468 in->_n._n_n._n_zeroes = 0;
469 in->_n._n_n._n_offset = bfd_h_get_32(abfd, (bfd_byte *) ext->e.e.e_offset);
472 #if SYMNMLEN != E_SYMNMLEN
473 -> Error, we need to cope with truncating or extending SYMNMLEN!;
475 memcpy(in->_n._n_name, ext->e.e_name, SYMNMLEN);
479 in->n_value = bfd_h_get_32(abfd, (bfd_byte *) ext->e_value);
480 in->n_scnum = bfd_h_get_16(abfd, (bfd_byte *) ext->e_scnum);
481 if (sizeof(ext->e_type) == 2){
482 in->n_type = bfd_h_get_16(abfd, (bfd_byte *) ext->e_type);
485 in->n_type = bfd_h_get_32(abfd, (bfd_byte *) ext->e_type);
487 in->n_sclass = bfd_h_get_8(abfd, ext->e_sclass);
488 in->n_numaux = bfd_h_get_8(abfd, ext->e_numaux);
490 /* The section symbols for the .idata$ sections have class 68, which MS
491 documentation indicates is a section symbol. The problem is that the
492 value field in the symbol is simply a copy of the .idata section's flags
493 rather than something useful. When these symbols are encountered, change
494 the value to 0 and the section number to 1 so that they will be handled
495 somewhat correctly in the bfd code. */
496 if (in->n_sclass == 0x68) {
499 /* I have tried setting the class to 3 and using the following to set
500 the section number. This will put the address of the pointer to the
501 string kernel32.dll at addresses 0 and 0x10 off start of idata section
502 which is not correct */
503 /* if (strcmp (in->_n._n_name, ".idata$4") == 0) */
504 /* in->n_scnum = 3; */
506 /* in->n_scnum = 2; */
509 #ifdef coff_swap_sym_in_hook
510 coff_swap_sym_in_hook(abfd, ext1, in1);
515 coff_swap_sym_out (abfd, inp, extp)
520 struct internal_syment *in = (struct internal_syment *)inp;
521 SYMENT *ext =(SYMENT *)extp;
522 if(in->_n._n_name[0] == 0) {
523 bfd_h_put_32(abfd, 0, (bfd_byte *) ext->e.e.e_zeroes);
524 bfd_h_put_32(abfd, in->_n._n_n._n_offset, (bfd_byte *) ext->e.e.e_offset);
527 #if SYMNMLEN != E_SYMNMLEN
528 -> Error, we need to cope with truncating or extending SYMNMLEN!;
530 memcpy(ext->e.e_name, in->_n._n_name, SYMNMLEN);
534 bfd_h_put_32(abfd, in->n_value , (bfd_byte *) ext->e_value);
535 bfd_h_put_16(abfd, in->n_scnum , (bfd_byte *) ext->e_scnum);
536 if (sizeof(ext->e_type) == 2)
538 bfd_h_put_16(abfd, in->n_type , (bfd_byte *) ext->e_type);
542 bfd_h_put_32(abfd, in->n_type , (bfd_byte *) ext->e_type);
544 bfd_h_put_8(abfd, in->n_sclass , ext->e_sclass);
545 bfd_h_put_8(abfd, in->n_numaux , ext->e_numaux);
551 coff_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1)
560 AUXENT *ext = (AUXENT *)ext1;
561 union internal_auxent *in = (union internal_auxent *)in1;
565 if (ext->x_file.x_fname[0] == 0) {
566 in->x_file.x_n.x_zeroes = 0;
567 in->x_file.x_n.x_offset =
568 bfd_h_get_32(abfd, (bfd_byte *) ext->x_file.x_n.x_offset);
570 #if FILNMLEN != E_FILNMLEN
571 -> Error, we need to cope with truncating or extending FILNMLEN!;
573 memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
584 if (type == T_NULL) {
585 in->x_scn.x_scnlen = GET_SCN_SCNLEN(abfd, ext);
586 in->x_scn.x_nreloc = GET_SCN_NRELOC(abfd, ext);
587 in->x_scn.x_nlinno = GET_SCN_NLINNO(abfd, ext);
588 in->x_scn.x_checksum = bfd_h_get_32 (abfd,
589 (bfd_byte *) ext->x_scn.x_checksum);
590 in->x_scn.x_associated =
591 bfd_h_get_16 (abfd, (bfd_byte *) ext->x_scn.x_associated);
592 in->x_scn.x_comdat = bfd_h_get_8 (abfd,
593 (bfd_byte *) ext->x_scn.x_comdat);
599 in->x_sym.x_tagndx.l = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_tagndx);
601 in->x_sym.x_tvndx = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_tvndx);
604 if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
606 in->x_sym.x_fcnary.x_fcn.x_lnnoptr = GET_FCN_LNNOPTR (abfd, ext);
607 in->x_sym.x_fcnary.x_fcn.x_endndx.l = GET_FCN_ENDNDX (abfd, ext);
611 #if DIMNUM != E_DIMNUM
612 #error we need to cope with truncating or extending DIMNUM
614 in->x_sym.x_fcnary.x_ary.x_dimen[0] =
615 bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
616 in->x_sym.x_fcnary.x_ary.x_dimen[1] =
617 bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
618 in->x_sym.x_fcnary.x_ary.x_dimen[2] =
619 bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
620 in->x_sym.x_fcnary.x_ary.x_dimen[3] =
621 bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
625 in->x_sym.x_misc.x_fsize = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_misc.x_fsize);
628 in->x_sym.x_misc.x_lnsz.x_lnno = GET_LNSZ_LNNO(abfd, ext);
629 in->x_sym.x_misc.x_lnsz.x_size = GET_LNSZ_SIZE(abfd, ext);
634 coff_swap_aux_out (abfd, inp, type, class, indx, numaux, extp)
643 union internal_auxent *in = (union internal_auxent *)inp;
644 AUXENT *ext = (AUXENT *)extp;
646 memset((PTR)ext, 0, AUXESZ);
649 if (in->x_file.x_fname[0] == 0) {
650 bfd_h_put_32(abfd, 0, (bfd_byte *) ext->x_file.x_n.x_zeroes);
652 in->x_file.x_n.x_offset,
653 (bfd_byte *) ext->x_file.x_n.x_offset);
656 #if FILNMLEN != E_FILNMLEN
657 -> Error, we need to cope with truncating or extending FILNMLEN!;
659 memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
670 if (type == T_NULL) {
671 PUT_SCN_SCNLEN(abfd, in->x_scn.x_scnlen, ext);
672 PUT_SCN_NRELOC(abfd, in->x_scn.x_nreloc, ext);
673 PUT_SCN_NLINNO(abfd, in->x_scn.x_nlinno, ext);
674 bfd_h_put_32 (abfd, in->x_scn.x_checksum,
675 (bfd_byte *) ext->x_scn.x_checksum);
676 bfd_h_put_16 (abfd, in->x_scn.x_associated,
677 (bfd_byte *) ext->x_scn.x_associated);
678 bfd_h_put_8 (abfd, in->x_scn.x_comdat,
679 (bfd_byte *) ext->x_scn.x_comdat);
685 bfd_h_put_32(abfd, in->x_sym.x_tagndx.l, (bfd_byte *) ext->x_sym.x_tagndx);
687 bfd_h_put_16(abfd, in->x_sym.x_tvndx , (bfd_byte *) ext->x_sym.x_tvndx);
690 if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
692 PUT_FCN_LNNOPTR(abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr, ext);
693 PUT_FCN_ENDNDX(abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l, ext);
697 #if DIMNUM != E_DIMNUM
698 #error we need to cope with truncating or extending DIMNUM
700 bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0],
701 (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
702 bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1],
703 (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
704 bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2],
705 (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
706 bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3],
707 (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
711 bfd_h_put_32 (abfd, in->x_sym.x_misc.x_fsize,
712 (bfd_byte *) ext->x_sym.x_misc.x_fsize);
715 PUT_LNSZ_LNNO (abfd, in->x_sym.x_misc.x_lnsz.x_lnno, ext);
716 PUT_LNSZ_SIZE (abfd, in->x_sym.x_misc.x_lnsz.x_size, ext);
724 coff_swap_lineno_in (abfd, ext1, in1)
729 LINENO *ext = (LINENO *)ext1;
730 struct internal_lineno *in = (struct internal_lineno *)in1;
732 in->l_addr.l_symndx = bfd_h_get_32(abfd, (bfd_byte *) ext->l_addr.l_symndx);
733 in->l_lnno = GET_LINENO_LNNO(abfd, ext);
737 coff_swap_lineno_out (abfd, inp, outp)
742 struct internal_lineno *in = (struct internal_lineno *)inp;
743 struct external_lineno *ext = (struct external_lineno *)outp;
744 bfd_h_put_32(abfd, in->l_addr.l_symndx, (bfd_byte *)
745 ext->l_addr.l_symndx);
747 PUT_LINENO_LNNO (abfd, in->l_lnno, ext);
754 coff_swap_aouthdr_in (abfd, aouthdr_ext1, aouthdr_int1)
759 struct internal_extra_pe_aouthdr *a;
760 PEAOUTHDR *src = (PEAOUTHDR *)(aouthdr_ext1);
761 AOUTHDR *aouthdr_ext = (AOUTHDR *) aouthdr_ext1;
762 struct internal_aouthdr *aouthdr_int = (struct internal_aouthdr *)aouthdr_int1;
764 aouthdr_int->magic = bfd_h_get_16(abfd, (bfd_byte *) aouthdr_ext->magic);
765 aouthdr_int->vstamp = bfd_h_get_16(abfd, (bfd_byte *) aouthdr_ext->vstamp);
767 GET_AOUTHDR_TSIZE (abfd, (bfd_byte *) aouthdr_ext->tsize);
769 GET_AOUTHDR_DSIZE (abfd, (bfd_byte *) aouthdr_ext->dsize);
771 GET_AOUTHDR_BSIZE (abfd, (bfd_byte *) aouthdr_ext->bsize);
773 GET_AOUTHDR_ENTRY (abfd, (bfd_byte *) aouthdr_ext->entry);
774 aouthdr_int->text_start =
775 GET_AOUTHDR_TEXT_START (abfd, (bfd_byte *) aouthdr_ext->text_start);
776 aouthdr_int->data_start =
777 GET_AOUTHDR_DATA_START (abfd, (bfd_byte *) aouthdr_ext->data_start);
779 a = &aouthdr_int->pe;
780 a->ImageBase = bfd_h_get_32 (abfd, src->ImageBase);
781 a->SectionAlignment = bfd_h_get_32 (abfd, src->SectionAlignment);
782 a->FileAlignment = bfd_h_get_32 (abfd, src->FileAlignment);
783 a->MajorOperatingSystemVersion =
784 bfd_h_get_16 (abfd, src->MajorOperatingSystemVersion);
785 a->MinorOperatingSystemVersion =
786 bfd_h_get_16 (abfd, src->MinorOperatingSystemVersion);
787 a->MajorImageVersion = bfd_h_get_16 (abfd, src->MajorImageVersion);
788 a->MinorImageVersion = bfd_h_get_16 (abfd, src->MinorImageVersion);
789 a->MajorSubsystemVersion = bfd_h_get_16 (abfd, src->MajorSubsystemVersion);
790 a->MinorSubsystemVersion = bfd_h_get_16 (abfd, src->MinorSubsystemVersion);
791 a->Reserved1 = bfd_h_get_32 (abfd, src->Reserved1);
792 a->SizeOfImage = bfd_h_get_32 (abfd, src->SizeOfImage);
793 a->SizeOfHeaders = bfd_h_get_32 (abfd, src->SizeOfHeaders);
794 a->CheckSum = bfd_h_get_32 (abfd, src->CheckSum);
795 a->Subsystem = bfd_h_get_16 (abfd, src->Subsystem);
796 a->DllCharacteristics = bfd_h_get_16 (abfd, src->DllCharacteristics);
797 a->SizeOfStackReserve = bfd_h_get_32 (abfd, src->SizeOfStackReserve);
798 a->SizeOfStackCommit = bfd_h_get_32 (abfd, src->SizeOfStackCommit);
799 a->SizeOfHeapReserve = bfd_h_get_32 (abfd, src->SizeOfHeapReserve);
800 a->SizeOfHeapCommit = bfd_h_get_32 (abfd, src->SizeOfHeapCommit);
801 a->LoaderFlags = bfd_h_get_32 (abfd, src->LoaderFlags);
802 a->NumberOfRvaAndSizes = bfd_h_get_32 (abfd, src->NumberOfRvaAndSizes);
806 for (idx=0; idx < 16; idx++)
808 a->DataDirectory[idx].VirtualAddress =
809 bfd_h_get_32 (abfd, src->DataDirectory[idx][0]);
810 a->DataDirectory[idx].Size =
811 bfd_h_get_32 (abfd, src->DataDirectory[idx][1]);
815 if (aouthdr_int->entry)
817 aouthdr_int->entry += a->ImageBase;
818 aouthdr_int->entry &= 0xffffffff;
820 if (aouthdr_int->tsize)
822 aouthdr_int->text_start += a->ImageBase;
823 aouthdr_int->text_start &= 0xffffffff;
825 if (aouthdr_int->dsize)
827 aouthdr_int->data_start += a->ImageBase;
828 aouthdr_int->data_start &= 0xffffffff;
832 /* These three fields are normally set up by ppc_relocate_section.
833 In the case of reading a file in, we can pick them up from
836 first_thunk_address = a->DataDirectory[12].VirtualAddress ;
837 thunk_size = a->DataDirectory[12].Size;
838 import_table_size = a->DataDirectory[1].Size;
843 static void add_data_entry (abfd, aout, idx, name, base)
845 struct internal_extra_pe_aouthdr *aout;
850 asection *sec = bfd_get_section_by_name (abfd, name);
852 /* add import directory information if it exists */
855 aout->DataDirectory[idx].VirtualAddress = (sec->vma - base) & 0xffffffff;
856 aout->DataDirectory[idx].Size = pei_section_data (abfd, sec)->virt_size;
857 sec->flags |= SEC_DATA;
862 coff_swap_aouthdr_out (abfd, in, out)
867 struct internal_aouthdr *aouthdr_in = (struct internal_aouthdr *)in;
868 struct internal_extra_pe_aouthdr *extra = &pe_data (abfd)->pe_opthdr;
869 PEAOUTHDR *aouthdr_out = (PEAOUTHDR *)out;
871 bfd_vma sa = extra->SectionAlignment;
872 bfd_vma fa = extra->FileAlignment;
873 bfd_vma ib = extra->ImageBase ;
875 if (aouthdr_in->tsize)
877 aouthdr_in->text_start -= ib;
878 aouthdr_in->text_start &= 0xffffffff;
880 if (aouthdr_in->dsize)
882 aouthdr_in->data_start -= ib;
883 aouthdr_in->data_start &= 0xffffffff;
885 if (aouthdr_in->entry)
887 aouthdr_in->entry -= ib;
888 aouthdr_in->entry &= 0xffffffff;
891 #define FA(x) (((x) + fa -1 ) & (- fa))
892 #define SA(x) (((x) + sa -1 ) & (- sa))
894 /* We like to have the sizes aligned */
896 aouthdr_in->bsize = FA (aouthdr_in->bsize);
899 extra->NumberOfRvaAndSizes = IMAGE_NUMBEROF_DIRECTORY_ENTRIES;
901 /* first null out all data directory entries .. */
902 memset (extra->DataDirectory, sizeof (extra->DataDirectory), 0);
904 add_data_entry (abfd, extra, 0, ".edata", ib);
905 add_data_entry (abfd, extra, 1, ".idata", ib);
906 add_data_entry (abfd, extra, 2, ".rsrc" ,ib);
909 /* FIXME: do other PE platforms use this? */
910 add_data_entry (abfd, extra, 3, ".pdata" ,ib);
913 add_data_entry (abfd, extra, 5, ".reloc", ib);
916 /* On the PPC NT system, this field is set up as follows. It is
917 not an "officially" reserved field, so it currently has no title.
918 first_thunk_address is idata$5, and the thunk_size is the size
919 of the idata$5 chunk of the idata section.
921 extra->DataDirectory[12].VirtualAddress = first_thunk_address;
922 extra->DataDirectory[12].Size = thunk_size;
924 /* On the PPC NT system, the size of the directory entry is not the
925 size of the entire section. It's actually offset to the end of
926 the idata$3 component of the idata section. This is the size of
927 the entire import table. (also known as the start of idata$4)
929 extra->DataDirectory[1].Size = import_table_size;
935 bfd_vma isize = SA(abfd->sections->filepos);
938 for (sec = abfd->sections; sec; sec = sec->next)
940 int rounded = FA(sec->_raw_size);
942 if (sec->flags & SEC_DATA)
944 if (sec->flags & SEC_CODE)
946 isize += SA(rounded);
949 aouthdr_in->dsize = dsize;
950 aouthdr_in->tsize = tsize;
951 extra->SizeOfImage = isize;
954 extra->SizeOfHeaders = abfd->sections->filepos;
955 bfd_h_put_16(abfd, aouthdr_in->magic, (bfd_byte *) aouthdr_out->standard.magic);
958 /* this little piece of magic sets the "linker version" field to 2.60 */
959 bfd_h_put_16(abfd, 2 + 60 * 256, (bfd_byte *) aouthdr_out->standard.vstamp);
961 /* this little piece of magic sets the "linker version" field to 2.55 */
962 bfd_h_put_16(abfd, 2 + 55 * 256, (bfd_byte *) aouthdr_out->standard.vstamp);
965 PUT_AOUTHDR_TSIZE (abfd, aouthdr_in->tsize, (bfd_byte *) aouthdr_out->standard.tsize);
966 PUT_AOUTHDR_DSIZE (abfd, aouthdr_in->dsize, (bfd_byte *) aouthdr_out->standard.dsize);
967 PUT_AOUTHDR_BSIZE (abfd, aouthdr_in->bsize, (bfd_byte *) aouthdr_out->standard.bsize);
968 PUT_AOUTHDR_ENTRY (abfd, aouthdr_in->entry, (bfd_byte *) aouthdr_out->standard.entry);
969 PUT_AOUTHDR_TEXT_START (abfd, aouthdr_in->text_start,
970 (bfd_byte *) aouthdr_out->standard.text_start);
972 PUT_AOUTHDR_DATA_START (abfd, aouthdr_in->data_start,
973 (bfd_byte *) aouthdr_out->standard.data_start);
976 bfd_h_put_32 (abfd, extra->ImageBase,
977 (bfd_byte *) aouthdr_out->ImageBase);
978 bfd_h_put_32 (abfd, extra->SectionAlignment,
979 (bfd_byte *) aouthdr_out->SectionAlignment);
980 bfd_h_put_32 (abfd, extra->FileAlignment,
981 (bfd_byte *) aouthdr_out->FileAlignment);
982 bfd_h_put_16 (abfd, extra->MajorOperatingSystemVersion,
983 (bfd_byte *) aouthdr_out->MajorOperatingSystemVersion);
984 bfd_h_put_16 (abfd, extra->MinorOperatingSystemVersion,
985 (bfd_byte *) aouthdr_out->MinorOperatingSystemVersion);
986 bfd_h_put_16 (abfd, extra->MajorImageVersion,
987 (bfd_byte *) aouthdr_out->MajorImageVersion);
988 bfd_h_put_16 (abfd, extra->MinorImageVersion,
989 (bfd_byte *) aouthdr_out->MinorImageVersion);
990 bfd_h_put_16 (abfd, extra->MajorSubsystemVersion,
991 (bfd_byte *) aouthdr_out->MajorSubsystemVersion);
992 bfd_h_put_16 (abfd, extra->MinorSubsystemVersion,
993 (bfd_byte *) aouthdr_out->MinorSubsystemVersion);
994 bfd_h_put_32 (abfd, extra->Reserved1,
995 (bfd_byte *) aouthdr_out->Reserved1);
996 bfd_h_put_32 (abfd, extra->SizeOfImage,
997 (bfd_byte *) aouthdr_out->SizeOfImage);
998 bfd_h_put_32 (abfd, extra->SizeOfHeaders,
999 (bfd_byte *) aouthdr_out->SizeOfHeaders);
1000 bfd_h_put_32 (abfd, extra->CheckSum,
1001 (bfd_byte *) aouthdr_out->CheckSum);
1002 bfd_h_put_16 (abfd, extra->Subsystem,
1003 (bfd_byte *) aouthdr_out->Subsystem);
1004 bfd_h_put_16 (abfd, extra->DllCharacteristics,
1005 (bfd_byte *) aouthdr_out->DllCharacteristics);
1006 bfd_h_put_32 (abfd, extra->SizeOfStackReserve,
1007 (bfd_byte *) aouthdr_out->SizeOfStackReserve);
1008 bfd_h_put_32 (abfd, extra->SizeOfStackCommit,
1009 (bfd_byte *) aouthdr_out->SizeOfStackCommit);
1010 bfd_h_put_32 (abfd, extra->SizeOfHeapReserve,
1011 (bfd_byte *) aouthdr_out->SizeOfHeapReserve);
1012 bfd_h_put_32 (abfd, extra->SizeOfHeapCommit,
1013 (bfd_byte *) aouthdr_out->SizeOfHeapCommit);
1014 bfd_h_put_32 (abfd, extra->LoaderFlags,
1015 (bfd_byte *) aouthdr_out->LoaderFlags);
1016 bfd_h_put_32 (abfd, extra->NumberOfRvaAndSizes,
1017 (bfd_byte *) aouthdr_out->NumberOfRvaAndSizes);
1020 for (idx=0; idx < 16; idx++)
1022 bfd_h_put_32 (abfd, extra->DataDirectory[idx].VirtualAddress,
1023 (bfd_byte *) aouthdr_out->DataDirectory[idx][0]);
1024 bfd_h_put_32 (abfd, extra->DataDirectory[idx].Size,
1025 (bfd_byte *) aouthdr_out->DataDirectory[idx][1]);
1033 coff_swap_scnhdr_in (abfd, ext, in)
1038 SCNHDR *scnhdr_ext = (SCNHDR *) ext;
1039 struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
1041 memcpy(scnhdr_int->s_name, scnhdr_ext->s_name, sizeof(scnhdr_int->s_name));
1042 scnhdr_int->s_vaddr =
1043 GET_SCNHDR_VADDR (abfd, (bfd_byte *) scnhdr_ext->s_vaddr);
1044 scnhdr_int->s_paddr =
1045 GET_SCNHDR_PADDR (abfd, (bfd_byte *) scnhdr_ext->s_paddr);
1046 scnhdr_int->s_size =
1047 GET_SCNHDR_SIZE (abfd, (bfd_byte *) scnhdr_ext->s_size);
1048 scnhdr_int->s_scnptr =
1049 GET_SCNHDR_SCNPTR (abfd, (bfd_byte *) scnhdr_ext->s_scnptr);
1050 scnhdr_int->s_relptr =
1051 GET_SCNHDR_RELPTR (abfd, (bfd_byte *) scnhdr_ext->s_relptr);
1052 scnhdr_int->s_lnnoptr =
1053 GET_SCNHDR_LNNOPTR (abfd, (bfd_byte *) scnhdr_ext->s_lnnoptr);
1054 scnhdr_int->s_flags = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_flags);
1056 scnhdr_int->s_nreloc = bfd_h_get_16(abfd, (bfd_byte *) scnhdr_ext->s_nreloc);
1057 scnhdr_int->s_nlnno = bfd_h_get_16(abfd, (bfd_byte *) scnhdr_ext->s_nlnno);
1059 if (scnhdr_int->s_vaddr != 0)
1061 scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
1062 scnhdr_int->s_vaddr &= 0xffffffff;
1064 if (strcmp (scnhdr_int->s_name, _BSS) == 0)
1066 scnhdr_int->s_size = scnhdr_int->s_paddr;
1067 scnhdr_int->s_paddr = 0;
1072 coff_swap_scnhdr_out (abfd, in, out)
1077 struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *)in;
1078 SCNHDR *scnhdr_ext = (SCNHDR *)out;
1079 unsigned int ret = SCNHSZ;
1083 memcpy(scnhdr_ext->s_name, scnhdr_int->s_name, sizeof(scnhdr_int->s_name));
1085 PUT_SCNHDR_VADDR (abfd,
1086 ((scnhdr_int->s_vaddr
1087 - pe_data(abfd)->pe_opthdr.ImageBase)
1089 (bfd_byte *) scnhdr_ext->s_vaddr);
1091 /* NT wants the size data to be rounded up to the next NT_FILE_ALIGNMENT
1092 value except for the BSS section, its s_size should be 0 */
1095 if (strcmp (scnhdr_int->s_name, _BSS) == 0)
1097 ps = scnhdr_int->s_size;
1102 ps = scnhdr_int->s_paddr;
1103 ss = scnhdr_int->s_size;
1106 PUT_SCNHDR_SIZE (abfd, ss,
1107 (bfd_byte *) scnhdr_ext->s_size);
1110 PUT_SCNHDR_PADDR (abfd, ps, (bfd_byte *) scnhdr_ext->s_paddr);
1112 PUT_SCNHDR_SCNPTR (abfd, scnhdr_int->s_scnptr,
1113 (bfd_byte *) scnhdr_ext->s_scnptr);
1114 PUT_SCNHDR_RELPTR (abfd, scnhdr_int->s_relptr,
1115 (bfd_byte *) scnhdr_ext->s_relptr);
1116 PUT_SCNHDR_LNNOPTR (abfd, scnhdr_int->s_lnnoptr,
1117 (bfd_byte *) scnhdr_ext->s_lnnoptr);
1119 /* Extra flags must be set when dealing with NT. All sections should also
1120 have the IMAGE_SCN_MEM_READ (0x40000000) flag set. In addition, the
1121 .text section must have IMAGE_SCN_MEM_EXECUTE (0x20000000) and the data
1122 sections (.idata, .data, .bss, .CRT) must have IMAGE_SCN_MEM_WRITE set
1123 (this is especially important when dealing with the .idata section since
1124 the addresses for routines from .dlls must be overwritten). If .reloc
1125 section data is ever generated, we must add IMAGE_SCN_MEM_DISCARDABLE
1126 (0x02000000). Also, the resource data should also be read and
1129 /* FIXME: alignment is also encoded in this field, at least on ppc (krk) */
1130 /* FIXME: even worse, I don't see how to get the original alignment field*/
1134 int flags = scnhdr_int->s_flags;
1135 if (strcmp (scnhdr_int->s_name, ".data") == 0 ||
1136 strcmp (scnhdr_int->s_name, ".CRT") == 0 ||
1137 strcmp (scnhdr_int->s_name, ".rsrc") == 0 ||
1138 strcmp (scnhdr_int->s_name, ".bss") == 0)
1139 flags |= IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE;
1140 else if (strcmp (scnhdr_int->s_name, ".text") == 0)
1141 flags |= IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_EXECUTE;
1142 else if (strcmp (scnhdr_int->s_name, ".reloc") == 0)
1143 flags = SEC_DATA| IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_DISCARDABLE;
1144 else if (strcmp (scnhdr_int->s_name, ".idata") == 0)
1145 flags = IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | SEC_DATA;
1146 else if (strcmp (scnhdr_int->s_name, ".rdata") == 0
1147 || strcmp (scnhdr_int->s_name, ".edata") == 0)
1148 flags = IMAGE_SCN_MEM_READ | SEC_DATA;
1149 else if (strcmp (scnhdr_int->s_name, ".pdata") == 0)
1150 flags = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_ALIGN_4BYTES |
1151 IMAGE_SCN_MEM_READ ;
1152 /* Remember this field is a max of 8 chars, so the null is _not_ there
1153 for an 8 character name like ".reldata". (yep. Stupid bug) */
1154 else if (strncmp (scnhdr_int->s_name, ".reldata", strlen(".reldata")) == 0)
1155 flags = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_ALIGN_8BYTES |
1156 IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE ;
1157 else if (strcmp (scnhdr_int->s_name, ".ydata") == 0)
1158 flags = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_ALIGN_8BYTES |
1159 IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE ;
1160 else if (strncmp (scnhdr_int->s_name, ".drectve", strlen(".drectve")) == 0)
1161 flags = IMAGE_SCN_LNK_INFO | IMAGE_SCN_LNK_REMOVE ;
1162 #ifdef POWERPC_LE_PE
1163 else if (strncmp (scnhdr_int->s_name, ".stabstr", strlen(".stabstr")) == 0)
1165 flags = IMAGE_SCN_LNK_INFO;
1167 else if (strcmp (scnhdr_int->s_name, ".stab") == 0)
1169 flags = IMAGE_SCN_LNK_INFO;
1173 bfd_h_put_32(abfd, flags, (bfd_byte *) scnhdr_ext->s_flags);
1176 if (scnhdr_int->s_nlnno <= 0xffff)
1177 bfd_h_put_16(abfd, scnhdr_int->s_nlnno, (bfd_byte *) scnhdr_ext->s_nlnno);
1180 (*_bfd_error_handler) ("%s: line number overflow: 0x%lx > 0xffff",
1181 bfd_get_filename (abfd),
1182 scnhdr_int->s_nlnno);
1183 bfd_set_error (bfd_error_file_truncated);
1184 bfd_h_put_16 (abfd, 0xffff, (bfd_byte *) scnhdr_ext->s_nlnno);
1187 if (scnhdr_int->s_nreloc <= 0xffff)
1188 bfd_h_put_16(abfd, scnhdr_int->s_nreloc, (bfd_byte *) scnhdr_ext->s_nreloc);
1191 (*_bfd_error_handler) ("%s: reloc overflow: 0x%lx > 0xffff",
1192 bfd_get_filename (abfd),
1193 scnhdr_int->s_nreloc);
1194 bfd_set_error (bfd_error_file_truncated);
1195 bfd_h_put_16 (abfd, 0xffff, (bfd_byte *) scnhdr_ext->s_nreloc);
1201 static char * dir_names[IMAGE_NUMBEROF_DIRECTORY_ENTRIES] =
1203 "Export Directory [.edata (or where ever we found it)]",
1204 "Import Directory [parts of .idata]",
1205 "Resource Directory [.rsrc]",
1206 "Exception Directory [.pdata]",
1207 "Security Directory",
1208 "Base Relocation Directory [.reloc]",
1210 "Description Directory",
1211 "Special Directory",
1212 "Thread Storage Directory [.tls]",
1213 "Load Configuration Directory",
1214 "Bound Import Directory",
1215 "Import Address Table Directory",
1221 /**********************************************************************/
1223 pe_print_idata(abfd, vfile)
1227 FILE *file = (FILE *) vfile;
1229 asection *section = bfd_get_section_by_name (abfd, ".idata");
1231 #ifdef POWERPC_LE_PE
1232 asection *rel_section = bfd_get_section_by_name (abfd, ".reldata");
1235 bfd_size_type datasize = 0;
1237 bfd_size_type start, stop;
1240 pe_data_type *pe = pe_data (abfd);
1241 struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1246 #ifdef POWERPC_LE_PE
1247 if (rel_section != 0 && bfd_section_size (abfd, rel_section) != 0)
1249 /* The toc address can be found by taking the starting address,
1250 which on the PPC locates a function descriptor. The descriptor
1251 consists of the function code starting address followed by the
1252 address of the toc. The starting address we get from the bfd,
1253 and the descriptor is supposed to be in the .reldata section.
1256 bfd_vma loadable_toc_address;
1257 bfd_vma toc_address;
1258 bfd_vma start_address;
1261 data = (bfd_byte *) bfd_malloc ((size_t) bfd_section_size (abfd,
1263 if (data == NULL && bfd_section_size (abfd, rel_section) != 0)
1266 datasize = bfd_section_size (abfd, rel_section);
1268 bfd_get_section_contents (abfd,
1271 bfd_section_size (abfd, rel_section));
1273 offset = abfd->start_address - rel_section->vma;
1275 start_address = bfd_get_32(abfd, data+offset);
1276 loadable_toc_address = bfd_get_32(abfd, data+offset+4);
1277 toc_address = loadable_toc_address - 32768;
1280 "\nFunction descriptor located at the start address: %04lx\n",
1281 (unsigned long int) (abfd->start_address));
1283 "\tcode-base %08lx toc (loadable/actual) %08lx/%08lx\n",
1284 start_address, loadable_toc_address, toc_address);
1289 "\nNo reldata section! Function descriptor not decoded.\n");
1294 "\nThe Import Tables (interpreted .idata section contents)\n");
1296 " vma: Hint Time Forward DLL First\n");
1298 " Table Stamp Chain Name Thunk\n");
1300 if (bfd_section_size (abfd, section) == 0)
1303 data = (bfd_byte *) bfd_malloc ((size_t) bfd_section_size (abfd, section));
1304 datasize = bfd_section_size (abfd, section);
1305 if (data == NULL && datasize != 0)
1308 bfd_get_section_contents (abfd,
1311 bfd_section_size (abfd, section));
1315 stop = bfd_section_size (abfd, section);
1317 for (i = start; i < stop; i += onaline)
1321 bfd_vma forward_chain;
1323 bfd_vma first_thunk;
1327 int adj = (extra->ImageBase - section->vma) & 0xffffffff;
1331 (unsigned long int) (i + section->vma));
1339 hint_addr = bfd_get_32(abfd, data+i);
1340 time_stamp = bfd_get_32(abfd, data+i+4);
1341 forward_chain = bfd_get_32(abfd, data+i+8);
1342 dll_name = bfd_get_32(abfd, data+i+12);
1343 first_thunk = bfd_get_32(abfd, data+i+16);
1345 fprintf(file, "%08lx %08lx %08lx %08lx %08lx\n",
1357 /* the image base is present in the section->vma */
1358 dll = (char *) data + dll_name + adj;
1359 fprintf(file, "\n\tDLL Name: %s\n", dll);
1360 fprintf(file, "\tvma: Ordinal Member-Name\n");
1362 idx = hint_addr + adj;
1364 for (j=0;j<stop;j+=4)
1368 bfd_vma member = bfd_get_32(abfd, data + idx + j);
1371 ordinal = bfd_get_16(abfd,
1372 data + member + adj);
1373 member_name = (char *) data + member + adj + 2;
1374 fprintf(file, "\t%04lx\t %4d %s\n",
1375 member, ordinal, member_name);
1378 if (hint_addr != first_thunk)
1383 idx2 = first_thunk + adj;
1385 for (j=0;j<stop;j+=4)
1389 bfd_vma hint_member = bfd_get_32(abfd, data + idx + j);
1390 bfd_vma iat_member = bfd_get_32(abfd, data + idx2 + j);
1391 if (hint_member != iat_member)
1396 "\tThe Import Address Table (difference found)\n");
1397 fprintf(file, "\tvma: Ordinal Member-Name\n");
1400 if (iat_member == 0)
1403 "\t>>> Ran out of IAT members!\n");
1407 ordinal = bfd_get_16(abfd,
1408 data + iat_member + adj);
1409 member_name = (char *) data + iat_member + adj + 2;
1410 fprintf(file, "\t%04lx\t %4d %s\n",
1411 iat_member, ordinal, member_name);
1415 if (hint_member == 0)
1421 "\tThe Import Address Table is identical\n");
1425 fprintf(file, "\n");
1435 pe_print_edata (abfd, vfile)
1439 FILE *file = (FILE *) vfile;
1441 asection *section = bfd_get_section_by_name (abfd, ".edata");
1443 bfd_size_type datasize = 0;
1449 long export_flags; /* reserved - should be zero */
1453 bfd_vma name; /* rva - relative to image base */
1454 long base; /* ordinal base */
1455 long num_functions; /* Number in the export address table */
1456 long num_names; /* Number in the name pointer table */
1457 bfd_vma eat_addr; /* rva to the export address table */
1458 bfd_vma npt_addr; /* rva to the Export Name Pointer Table */
1459 bfd_vma ot_addr; /* rva to the Ordinal Table */
1462 pe_data_type *pe = pe_data (abfd);
1463 struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1468 data = (bfd_byte *) bfd_malloc ((size_t) bfd_section_size (abfd,
1470 datasize = bfd_section_size (abfd, section);
1472 if (data == NULL && datasize != 0)
1475 bfd_get_section_contents (abfd,
1478 bfd_section_size (abfd, section));
1480 /* Go get Export Directory Table */
1481 edt.export_flags = bfd_get_32(abfd, data+0);
1482 edt.time_stamp = bfd_get_32(abfd, data+4);
1483 edt.major_ver = bfd_get_16(abfd, data+8);
1484 edt.minor_ver = bfd_get_16(abfd, data+10);
1485 edt.name = bfd_get_32(abfd, data+12);
1486 edt.base = bfd_get_32(abfd, data+16);
1487 edt.num_functions = bfd_get_32(abfd, data+20);
1488 edt.num_names = bfd_get_32(abfd, data+24);
1489 edt.eat_addr = bfd_get_32(abfd, data+28);
1490 edt.npt_addr = bfd_get_32(abfd, data+32);
1491 edt.ot_addr = bfd_get_32(abfd, data+36);
1493 adj = (extra->ImageBase - section->vma) & 0xffffffff;
1496 /* Dump the EDT first first */
1498 "\nThe Export Tables (interpreted .edata section contents)\n\n");
1501 "Export Flags \t\t\t%lx\n", (unsigned long) edt.export_flags);
1504 "Time/Date stamp \t\t%lx\n", (unsigned long) edt.time_stamp);
1507 "Major/Minor \t\t\t%d/%d\n", edt.major_ver, edt.minor_ver);
1511 fprintf_vma (file, edt.name);
1513 " %s\n", data + edt.name + adj);
1516 "Ordinal Base \t\t\t%ld\n", edt.base);
1522 "\tExport Address Table \t\t%lx\n",
1523 (unsigned long) edt.num_functions);
1526 "\t[Name Pointer/Ordinal] Table\t%ld\n", edt.num_names);
1529 "Table Addresses\n");
1532 "\tExport Address Table \t\t");
1533 fprintf_vma (file, edt.eat_addr);
1534 fprintf (file, "\n");
1537 "\tName Pointer Table \t\t");
1538 fprintf_vma (file, edt.npt_addr);
1539 fprintf (file, "\n");
1542 "\tOrdinal Table \t\t\t");
1543 fprintf_vma (file, edt.ot_addr);
1544 fprintf (file, "\n");
1547 /* The next table to find si the Export Address Table. It's basically
1548 a list of pointers that either locate a function in this dll, or
1549 forward the call to another dll. Something like:
1554 } export_address_table_entry;
1558 "\nExport Address Table -- Ordinal Base %ld\n",
1561 for (i = 0; i < edt.num_functions; ++i)
1563 bfd_vma eat_member = bfd_get_32(abfd,
1564 data + edt.eat_addr + (i*4) + adj);
1565 bfd_vma eat_actual = (extra->ImageBase + eat_member) & 0xffffffff;
1566 bfd_vma edata_start = bfd_get_section_vma(abfd,section);
1567 bfd_vma edata_end = edata_start + bfd_section_size (abfd, section);
1570 if (eat_member == 0)
1573 if (edata_start < eat_actual && eat_actual < edata_end)
1575 /* this rva is to a name (forwarding function) in our section */
1576 /* Should locate a function descriptor */
1578 "\t[%4ld] +base[%4ld] %04lx %s -- %s\n",
1579 (long) i, (long) (i + edt.base), eat_member,
1580 "Forwarder RVA", data + eat_member + adj);
1584 /* Should locate a function descriptor in the reldata section */
1586 "\t[%4ld] +base[%4ld] %04lx %s\n",
1587 (long) i, (long) (i + edt.base), eat_member, "Export RVA");
1591 /* The Export Name Pointer Table is paired with the Export Ordinal Table */
1592 /* Dump them in parallel for clarity */
1594 "\n[Ordinal/Name Pointer] Table\n");
1596 for (i = 0; i < edt.num_names; ++i)
1598 bfd_vma name_ptr = bfd_get_32(abfd,
1603 char *name = (char *) data + name_ptr + adj;
1605 bfd_vma ord = bfd_get_16(abfd,
1610 "\t[%4ld] %s\n", (long) ord, name);
1620 pe_print_pdata (abfd, vfile)
1624 FILE *file = (FILE *) vfile;
1626 asection *section = bfd_get_section_by_name (abfd, ".pdata");
1627 bfd_size_type datasize = 0;
1629 bfd_size_type start, stop;
1635 stop = bfd_section_size (abfd, section);
1636 if ((stop % onaline) != 0)
1637 fprintf (file, "Warning, .pdata section size (%ld) is not a multiple of %d\n",
1638 (long)stop, onaline);
1641 "\nThe Function Table (interpreted .pdata section contents)\n");
1643 " vma:\t\tBegin End EH EH PrologEnd\n");
1645 " \t\tAddress Address Handler Data Address\n");
1647 if (bfd_section_size (abfd, section) == 0)
1650 data = (bfd_byte *) bfd_malloc ((size_t) bfd_section_size (abfd, section));
1651 datasize = bfd_section_size (abfd, section);
1652 if (data == NULL && datasize != 0)
1655 bfd_get_section_contents (abfd,
1658 bfd_section_size (abfd, section));
1662 for (i = start; i < stop; i += onaline)
1668 bfd_vma prolog_end_addr;
1673 begin_addr = bfd_get_32(abfd, data+i);
1674 end_addr = bfd_get_32(abfd, data+i+4);
1675 eh_handler = bfd_get_32(abfd, data+i+8);
1676 eh_data = bfd_get_32(abfd, data+i+12);
1677 prolog_end_addr = bfd_get_32(abfd, data+i+16);
1679 if (begin_addr == 0 && end_addr == 0 && eh_handler == 0
1680 && eh_data == 0 && prolog_end_addr == 0)
1682 /* We are probably into the padding of the
1689 (unsigned long int) (i + section->vma));
1691 fprintf(file, "%08lx %08lx %08lx %08lx %08lx",
1698 #ifdef POWERPC_LE_PE
1699 if (eh_handler == 0 && eh_data != 0)
1701 /* Special bits here, although the meaning may */
1702 /* be a little mysterious. The only one I know */
1703 /* for sure is 0x03. */
1704 /* Code Significance */
1706 /* 0x01 Register Save Millicode */
1707 /* 0x02 Register Restore Millicode */
1708 /* 0x03 Glue Code Sequence */
1712 fprintf(file, " Register save millicode");
1715 fprintf(file, " Register restore millicode");
1718 fprintf(file, " Glue code sequence");
1725 fprintf(file, "\n");
1733 static const char *tbl[6] =
1744 pe_print_reloc (abfd, vfile)
1748 FILE *file = (FILE *) vfile;
1750 asection *section = bfd_get_section_by_name (abfd, ".reloc");
1751 bfd_size_type datasize = 0;
1753 bfd_size_type start, stop;
1758 if (bfd_section_size (abfd, section) == 0)
1762 "\n\nPE File Base Relocations (interpreted .reloc section contents)\n");
1764 data = (bfd_byte *) bfd_malloc ((size_t) bfd_section_size (abfd, section));
1765 datasize = bfd_section_size (abfd, section);
1766 if (data == NULL && datasize != 0)
1769 bfd_get_section_contents (abfd,
1772 bfd_section_size (abfd, section));
1776 stop = bfd_section_size (abfd, section);
1778 for (i = start; i < stop;)
1781 bfd_vma virtual_address;
1784 /* The .reloc section is a sequence of blocks, with a header consisting
1785 of two 32 bit quantities, followed by a number of 16 bit entries */
1787 virtual_address = bfd_get_32(abfd, data+i);
1788 size = bfd_get_32(abfd, data+i+4);
1789 number = (size - 8) / 2;
1797 "\nVirtual Address: %08lx Chunk size %ld (0x%lx) Number of fixups %ld\n",
1798 virtual_address, size, size, number);
1800 for (j = 0; j < number; ++j)
1802 unsigned short e = bfd_get_16(abfd, data + i + 8 + j*2);
1803 int t = (e & 0xF000) >> 12;
1804 int off = e & 0x0FFF;
1810 "\treloc %4d offset %4x [%4lx] %s\n",
1811 j, off, (long) (off + virtual_address), tbl[t]);
1823 pe_print_private_bfd_data (abfd, vfile)
1827 FILE *file = (FILE *) vfile;
1829 pe_data_type *pe = pe_data (abfd);
1830 struct internal_extra_pe_aouthdr *i = &pe->pe_opthdr;
1832 fprintf (file,"\nImageBase\t\t");
1833 fprintf_vma (file, i->ImageBase);
1834 fprintf (file,"\nSectionAlignment\t");
1835 fprintf_vma (file, i->SectionAlignment);
1836 fprintf (file,"\nFileAlignment\t\t");
1837 fprintf_vma (file, i->FileAlignment);
1838 fprintf (file,"\nMajorOSystemVersion\t%d\n", i->MajorOperatingSystemVersion);
1839 fprintf (file,"MinorOSystemVersion\t%d\n", i->MinorOperatingSystemVersion);
1840 fprintf (file,"MajorImageVersion\t%d\n", i->MajorImageVersion);
1841 fprintf (file,"MinorImageVersion\t%d\n", i->MinorImageVersion);
1842 fprintf (file,"MajorSubsystemVersion\t%d\n", i->MajorSubsystemVersion);
1843 fprintf (file,"MinorSubsystemVersion\t%d\n", i->MinorSubsystemVersion);
1844 fprintf (file,"Reserved1\t\t%08lx\n", i->Reserved1);
1845 fprintf (file,"SizeOfImage\t\t%08lx\n", i->SizeOfImage);
1846 fprintf (file,"SizeOfHeaders\t\t%08lx\n", i->SizeOfHeaders);
1847 fprintf (file,"CheckSum\t\t%08lx\n", i->CheckSum);
1848 fprintf (file,"Subsystem\t\t%08x\n", i->Subsystem);
1849 fprintf (file,"DllCharacteristics\t%08x\n", i->DllCharacteristics);
1850 fprintf (file,"SizeOfStackReserve\t");
1851 fprintf_vma (file, i->SizeOfStackReserve);
1852 fprintf (file,"\nSizeOfStackCommit\t");
1853 fprintf_vma (file, i->SizeOfStackCommit);
1854 fprintf (file,"\nSizeOfHeapReserve\t");
1855 fprintf_vma (file, i->SizeOfHeapReserve);
1856 fprintf (file,"\nSizeOfHeapCommit\t");
1857 fprintf_vma (file, i->SizeOfHeapCommit);
1858 fprintf (file,"\nLoaderFlags\t\t%08lx\n", i->LoaderFlags);
1859 fprintf (file,"NumberOfRvaAndSizes\t%08lx\n", i->NumberOfRvaAndSizes);
1861 fprintf (file,"\nThe Data Directory\n");
1862 for (j = 0; j < IMAGE_NUMBEROF_DIRECTORY_ENTRIES; j++)
1864 fprintf (file, "Entry %1x ", j);
1865 fprintf_vma (file, i->DataDirectory[j].VirtualAddress);
1866 fprintf (file, " %08lx ", i->DataDirectory[j].Size);
1867 fprintf (file, "%s\n", dir_names[j]);
1870 pe_print_idata(abfd, vfile);
1871 pe_print_edata(abfd, vfile);
1872 pe_print_pdata(abfd, vfile);
1873 pe_print_reloc(abfd, vfile);
1883 abfd->tdata.pe_obj_data =
1884 (struct pe_tdata *) bfd_zalloc (abfd, sizeof (pe_data_type));
1886 if (abfd->tdata.pe_obj_data == 0)
1889 pe = pe_data (abfd);
1892 pe->in_reloc_p = in_reloc_p;
1896 /* Create the COFF backend specific information. */
1898 pe_mkobject_hook (abfd, filehdr, aouthdr)
1903 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1906 if (pe_mkobject (abfd) == false)
1909 pe = pe_data (abfd);
1910 pe->coff.sym_filepos = internal_f->f_symptr;
1911 /* These members communicate important constants about the symbol
1912 table to GDB's symbol-reading code. These `constants'
1913 unfortunately vary among coff implementations... */
1914 pe->coff.local_n_btmask = N_BTMASK;
1915 pe->coff.local_n_btshft = N_BTSHFT;
1916 pe->coff.local_n_tmask = N_TMASK;
1917 pe->coff.local_n_tshift = N_TSHIFT;
1918 pe->coff.local_symesz = SYMESZ;
1919 pe->coff.local_auxesz = AUXESZ;
1920 pe->coff.local_linesz = LINESZ;
1922 obj_raw_syment_count (abfd) =
1923 obj_conv_table_size (abfd) =
1924 internal_f->f_nsyms;
1926 pe->real_flags = internal_f->f_flags;
1928 #ifdef COFF_IMAGE_WITH_PE
1931 pe->pe_opthdr = ((struct internal_aouthdr *)aouthdr)->pe;
1940 /* Copy any private info we understand from the input bfd
1941 to the output bfd. */
1943 #define coff_bfd_copy_private_bfd_data pe_bfd_copy_private_bfd_data
1946 pe_bfd_copy_private_bfd_data (ibfd, obfd)
1949 /* One day we may try to grok other private data. */
1950 if (ibfd->xvec->flavour != bfd_target_coff_flavour
1951 || obfd->xvec->flavour != bfd_target_coff_flavour)
1954 pe_data(obfd)->pe_opthdr = pe_data (ibfd)->pe_opthdr;
1959 #ifdef COFF_IMAGE_WITH_PE
1961 /* Copy private section data. */
1963 #define coff_bfd_copy_private_section_data pe_bfd_copy_private_section_data
1965 static boolean pe_bfd_copy_private_section_data
1966 PARAMS ((bfd *, asection *, bfd *, asection *));
1969 pe_bfd_copy_private_section_data (ibfd, isec, obfd, osec)
1975 if (bfd_get_flavour (ibfd) != bfd_target_coff_flavour
1976 || bfd_get_flavour (obfd) != bfd_target_coff_flavour)
1979 if (coff_section_data (ibfd, isec) != NULL
1980 && pei_section_data (ibfd, isec) != NULL)
1982 if (coff_section_data (obfd, osec) == NULL)
1985 (PTR) bfd_zalloc (obfd, sizeof (struct coff_section_tdata));
1986 if (osec->used_by_bfd == NULL)
1989 if (pei_section_data (obfd, osec) == NULL)
1991 coff_section_data (obfd, osec)->tdata =
1992 (PTR) bfd_zalloc (obfd, sizeof (struct pei_section_tdata));
1993 if (coff_section_data (obfd, osec)->tdata == NULL)
1996 pei_section_data (obfd, osec)->virt_size =
1997 pei_section_data (ibfd, isec)->virt_size;