1 /* Support for the generic parts of most COFF variants, for BFD.
2 Copyright 1995, 1996, 1997, 1998 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 #ifdef coff_bfd_print_private_bfd_data
56 static boolean (* pe_saved_coff_bfd_print_private_bfd_data
) (bfd
*, PTR
) = coff_bfd_print_private_bfd_data
;
57 #undef coff_bfd_print_private_bfd_data
59 static boolean (* pe_saved_coff_bfd_print_private_bfd_data
) (bfd
*, PTR
) = NULL
;
61 #define coff_bfd_print_private_bfd_data pe_print_private_bfd_data
63 #define coff_mkobject pe_mkobject
64 #define coff_mkobject_hook pe_mkobject_hook
66 #ifndef GET_FCN_LNNOPTR
67 #define GET_FCN_LNNOPTR(abfd, ext) \
68 bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
71 #ifndef GET_FCN_ENDNDX
72 #define GET_FCN_ENDNDX(abfd, ext) \
73 bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
76 #ifndef PUT_FCN_LNNOPTR
77 #define PUT_FCN_LNNOPTR(abfd, in, ext) bfd_h_put_32(abfd, in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
79 #ifndef PUT_FCN_ENDNDX
80 #define PUT_FCN_ENDNDX(abfd, in, ext) bfd_h_put_32(abfd, in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
83 #define GET_LNSZ_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_lnno)
86 #define GET_LNSZ_SIZE(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_size)
89 #define PUT_LNSZ_LNNO(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_sym.x_misc.x_lnsz.x_lnno)
92 #define PUT_LNSZ_SIZE(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte*) ext->x_sym.x_misc.x_lnsz.x_size)
94 #ifndef GET_SCN_SCNLEN
95 #define GET_SCN_SCNLEN(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_scn.x_scnlen)
97 #ifndef GET_SCN_NRELOC
98 #define GET_SCN_NRELOC(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nreloc)
100 #ifndef GET_SCN_NLINNO
101 #define GET_SCN_NLINNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nlinno)
103 #ifndef PUT_SCN_SCNLEN
104 #define PUT_SCN_SCNLEN(abfd,in, ext) bfd_h_put_32(abfd, in, (bfd_byte *) ext->x_scn.x_scnlen)
106 #ifndef PUT_SCN_NRELOC
107 #define PUT_SCN_NRELOC(abfd,in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_scn.x_nreloc)
109 #ifndef PUT_SCN_NLINNO
110 #define PUT_SCN_NLINNO(abfd,in, ext) bfd_h_put_16(abfd,in, (bfd_byte *) ext->x_scn.x_nlinno)
112 #ifndef GET_LINENO_LNNO
113 #define GET_LINENO_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) (ext->l_lnno));
115 #ifndef PUT_LINENO_LNNO
116 #define PUT_LINENO_LNNO(abfd,val, ext) bfd_h_put_16(abfd,val, (bfd_byte *) (ext->l_lnno));
119 /* The f_symptr field in the filehdr is sometimes 64 bits. */
120 #ifndef GET_FILEHDR_SYMPTR
121 #define GET_FILEHDR_SYMPTR bfd_h_get_32
123 #ifndef PUT_FILEHDR_SYMPTR
124 #define PUT_FILEHDR_SYMPTR bfd_h_put_32
127 /* Some fields in the aouthdr are sometimes 64 bits. */
128 #ifndef GET_AOUTHDR_TSIZE
129 #define GET_AOUTHDR_TSIZE bfd_h_get_32
131 #ifndef PUT_AOUTHDR_TSIZE
132 #define PUT_AOUTHDR_TSIZE bfd_h_put_32
134 #ifndef GET_AOUTHDR_DSIZE
135 #define GET_AOUTHDR_DSIZE bfd_h_get_32
137 #ifndef PUT_AOUTHDR_DSIZE
138 #define PUT_AOUTHDR_DSIZE bfd_h_put_32
140 #ifndef GET_AOUTHDR_BSIZE
141 #define GET_AOUTHDR_BSIZE bfd_h_get_32
143 #ifndef PUT_AOUTHDR_BSIZE
144 #define PUT_AOUTHDR_BSIZE bfd_h_put_32
146 #ifndef GET_AOUTHDR_ENTRY
147 #define GET_AOUTHDR_ENTRY bfd_h_get_32
149 #ifndef PUT_AOUTHDR_ENTRY
150 #define PUT_AOUTHDR_ENTRY bfd_h_put_32
152 #ifndef GET_AOUTHDR_TEXT_START
153 #define GET_AOUTHDR_TEXT_START bfd_h_get_32
155 #ifndef PUT_AOUTHDR_TEXT_START
156 #define PUT_AOUTHDR_TEXT_START bfd_h_put_32
158 #ifndef GET_AOUTHDR_DATA_START
159 #define GET_AOUTHDR_DATA_START bfd_h_get_32
161 #ifndef PUT_AOUTHDR_DATA_START
162 #define PUT_AOUTHDR_DATA_START bfd_h_put_32
165 /* Some fields in the scnhdr are sometimes 64 bits. */
166 #ifndef GET_SCNHDR_PADDR
167 #define GET_SCNHDR_PADDR bfd_h_get_32
169 #ifndef PUT_SCNHDR_PADDR
170 #define PUT_SCNHDR_PADDR bfd_h_put_32
172 #ifndef GET_SCNHDR_VADDR
173 #define GET_SCNHDR_VADDR bfd_h_get_32
175 #ifndef PUT_SCNHDR_VADDR
176 #define PUT_SCNHDR_VADDR bfd_h_put_32
178 #ifndef GET_SCNHDR_SIZE
179 #define GET_SCNHDR_SIZE bfd_h_get_32
181 #ifndef PUT_SCNHDR_SIZE
182 #define PUT_SCNHDR_SIZE bfd_h_put_32
184 #ifndef GET_SCNHDR_SCNPTR
185 #define GET_SCNHDR_SCNPTR bfd_h_get_32
187 #ifndef PUT_SCNHDR_SCNPTR
188 #define PUT_SCNHDR_SCNPTR bfd_h_put_32
190 #ifndef GET_SCNHDR_RELPTR
191 #define GET_SCNHDR_RELPTR bfd_h_get_32
193 #ifndef PUT_SCNHDR_RELPTR
194 #define PUT_SCNHDR_RELPTR bfd_h_put_32
196 #ifndef GET_SCNHDR_LNNOPTR
197 #define GET_SCNHDR_LNNOPTR bfd_h_get_32
199 #ifndef PUT_SCNHDR_LNNOPTR
200 #define PUT_SCNHDR_LNNOPTR bfd_h_put_32
203 static void coff_swap_reloc_in
PARAMS ((bfd
*, PTR
, PTR
));
204 static unsigned int coff_swap_reloc_out
PARAMS ((bfd
*, PTR
, PTR
));
205 static void coff_swap_filehdr_in
PARAMS ((bfd
*, PTR
, PTR
));
206 static unsigned int coff_swap_filehdr_out
PARAMS ((bfd
*, PTR
, PTR
));
207 static void coff_swap_sym_in
PARAMS ((bfd
*, PTR
, PTR
));
208 static unsigned int coff_swap_sym_out
PARAMS ((bfd
*, PTR
, PTR
));
209 static void coff_swap_aux_in
PARAMS ((bfd
*, PTR
, int, int, int, int, PTR
));
210 static unsigned int coff_swap_aux_out
211 PARAMS ((bfd
*, PTR
, int, int, int, int, PTR
));
212 static void coff_swap_lineno_in
PARAMS ((bfd
*, PTR
, PTR
));
213 static unsigned int coff_swap_lineno_out
PARAMS ((bfd
*, PTR
, PTR
));
214 static void coff_swap_aouthdr_in
PARAMS ((bfd
*, PTR
, PTR
));
215 static void add_data_entry
216 PARAMS ((bfd
*, struct internal_extra_pe_aouthdr
*, int, char *, bfd_vma
));
217 static unsigned int coff_swap_aouthdr_out
PARAMS ((bfd
*, PTR
, PTR
));
218 static void coff_swap_scnhdr_in
PARAMS ((bfd
*, PTR
, PTR
));
219 static unsigned int coff_swap_scnhdr_out
PARAMS ((bfd
*, PTR
, PTR
));
220 static boolean pe_print_idata
PARAMS ((bfd
*, PTR
));
221 static boolean pe_print_edata
PARAMS ((bfd
*, PTR
));
222 static boolean pe_print_pdata
PARAMS ((bfd
*, PTR
));
223 static boolean pe_print_reloc
PARAMS ((bfd
*, PTR
));
224 static boolean pe_print_private_bfd_data
PARAMS ((bfd
*, PTR
));
225 static boolean pe_mkobject
PARAMS ((bfd
*));
226 static PTR pe_mkobject_hook
PARAMS ((bfd
*, PTR
, PTR
));
227 static boolean pe_bfd_copy_private_bfd_data
PARAMS ((bfd
*, bfd
*));
229 /**********************************************************************/
232 coff_swap_reloc_in (abfd
, src
, dst
)
237 RELOC
*reloc_src
= (RELOC
*) src
;
238 struct internal_reloc
*reloc_dst
= (struct internal_reloc
*) dst
;
240 reloc_dst
->r_vaddr
= bfd_h_get_32(abfd
, (bfd_byte
*)reloc_src
->r_vaddr
);
241 reloc_dst
->r_symndx
= bfd_h_get_signed_32(abfd
, (bfd_byte
*) reloc_src
->r_symndx
);
243 reloc_dst
->r_type
= bfd_h_get_16(abfd
, (bfd_byte
*) reloc_src
->r_type
);
245 #ifdef SWAP_IN_RELOC_OFFSET
246 reloc_dst
->r_offset
= SWAP_IN_RELOC_OFFSET(abfd
,
247 (bfd_byte
*) reloc_src
->r_offset
);
253 coff_swap_reloc_out (abfd
, src
, dst
)
258 struct internal_reloc
*reloc_src
= (struct internal_reloc
*)src
;
259 struct external_reloc
*reloc_dst
= (struct external_reloc
*)dst
;
260 bfd_h_put_32(abfd
, reloc_src
->r_vaddr
, (bfd_byte
*) reloc_dst
->r_vaddr
);
261 bfd_h_put_32(abfd
, reloc_src
->r_symndx
, (bfd_byte
*) reloc_dst
->r_symndx
);
263 bfd_h_put_16(abfd
, reloc_src
->r_type
, (bfd_byte
*)
266 #ifdef SWAP_OUT_RELOC_OFFSET
267 SWAP_OUT_RELOC_OFFSET(abfd
,
269 (bfd_byte
*) reloc_dst
->r_offset
);
271 #ifdef SWAP_OUT_RELOC_EXTRA
272 SWAP_OUT_RELOC_EXTRA(abfd
,reloc_src
, reloc_dst
);
279 coff_swap_filehdr_in (abfd
, src
, dst
)
284 FILHDR
*filehdr_src
= (FILHDR
*) src
;
285 struct internal_filehdr
*filehdr_dst
= (struct internal_filehdr
*) dst
;
286 filehdr_dst
->f_magic
= bfd_h_get_16(abfd
, (bfd_byte
*) filehdr_src
->f_magic
);
287 filehdr_dst
->f_nscns
= bfd_h_get_16(abfd
, (bfd_byte
*)filehdr_src
-> f_nscns
);
288 filehdr_dst
->f_timdat
= bfd_h_get_32(abfd
, (bfd_byte
*)filehdr_src
-> f_timdat
);
290 filehdr_dst
->f_nsyms
= bfd_h_get_32(abfd
, (bfd_byte
*)filehdr_src
-> f_nsyms
);
291 filehdr_dst
->f_flags
= bfd_h_get_16(abfd
, (bfd_byte
*)filehdr_src
-> f_flags
);
292 filehdr_dst
->f_symptr
= bfd_h_get_32 (abfd
, (bfd_byte
*) filehdr_src
->f_symptr
);
294 /* Other people's tools sometimes generate headers with an nsyms but
296 if (filehdr_dst
->f_nsyms
!= 0 && filehdr_dst
->f_symptr
== 0)
298 filehdr_dst
->f_nsyms
= 0;
299 filehdr_dst
->f_flags
|= F_LSYMS
;
302 filehdr_dst
->f_opthdr
= bfd_h_get_16(abfd
,
303 (bfd_byte
*)filehdr_src
-> f_opthdr
);
306 #ifdef COFF_IMAGE_WITH_PE
309 coff_swap_filehdr_out (abfd
, in
, out
)
315 struct internal_filehdr
*filehdr_in
= (struct internal_filehdr
*)in
;
316 FILHDR
*filehdr_out
= (FILHDR
*)out
;
318 if (pe_data (abfd
)->has_reloc_section
)
319 filehdr_in
->f_flags
&= ~F_RELFLG
;
321 if (pe_data (abfd
)->dll
)
322 filehdr_in
->f_flags
|= F_DLL
;
324 filehdr_in
->pe
.e_magic
= DOSMAGIC
;
325 filehdr_in
->pe
.e_cblp
= 0x90;
326 filehdr_in
->pe
.e_cp
= 0x3;
327 filehdr_in
->pe
.e_crlc
= 0x0;
328 filehdr_in
->pe
.e_cparhdr
= 0x4;
329 filehdr_in
->pe
.e_minalloc
= 0x0;
330 filehdr_in
->pe
.e_maxalloc
= 0xffff;
331 filehdr_in
->pe
.e_ss
= 0x0;
332 filehdr_in
->pe
.e_sp
= 0xb8;
333 filehdr_in
->pe
.e_csum
= 0x0;
334 filehdr_in
->pe
.e_ip
= 0x0;
335 filehdr_in
->pe
.e_cs
= 0x0;
336 filehdr_in
->pe
.e_lfarlc
= 0x40;
337 filehdr_in
->pe
.e_ovno
= 0x0;
339 for (idx
=0; idx
< 4; idx
++)
340 filehdr_in
->pe
.e_res
[idx
] = 0x0;
342 filehdr_in
->pe
.e_oemid
= 0x0;
343 filehdr_in
->pe
.e_oeminfo
= 0x0;
345 for (idx
=0; idx
< 10; idx
++)
346 filehdr_in
->pe
.e_res2
[idx
] = 0x0;
348 filehdr_in
->pe
.e_lfanew
= 0x80;
350 /* this next collection of data are mostly just characters. It appears
351 to be constant within the headers put on NT exes */
352 filehdr_in
->pe
.dos_message
[0] = 0x0eba1f0e;
353 filehdr_in
->pe
.dos_message
[1] = 0xcd09b400;
354 filehdr_in
->pe
.dos_message
[2] = 0x4c01b821;
355 filehdr_in
->pe
.dos_message
[3] = 0x685421cd;
356 filehdr_in
->pe
.dos_message
[4] = 0x70207369;
357 filehdr_in
->pe
.dos_message
[5] = 0x72676f72;
358 filehdr_in
->pe
.dos_message
[6] = 0x63206d61;
359 filehdr_in
->pe
.dos_message
[7] = 0x6f6e6e61;
360 filehdr_in
->pe
.dos_message
[8] = 0x65622074;
361 filehdr_in
->pe
.dos_message
[9] = 0x6e757220;
362 filehdr_in
->pe
.dos_message
[10] = 0x206e6920;
363 filehdr_in
->pe
.dos_message
[11] = 0x20534f44;
364 filehdr_in
->pe
.dos_message
[12] = 0x65646f6d;
365 filehdr_in
->pe
.dos_message
[13] = 0x0a0d0d2e;
366 filehdr_in
->pe
.dos_message
[14] = 0x24;
367 filehdr_in
->pe
.dos_message
[15] = 0x0;
368 filehdr_in
->pe
.nt_signature
= NT_SIGNATURE
;
372 bfd_h_put_16(abfd
, filehdr_in
->f_magic
, (bfd_byte
*) filehdr_out
->f_magic
);
373 bfd_h_put_16(abfd
, filehdr_in
->f_nscns
, (bfd_byte
*) filehdr_out
->f_nscns
);
375 bfd_h_put_32(abfd
, time (0), (bfd_byte
*) filehdr_out
->f_timdat
);
376 PUT_FILEHDR_SYMPTR (abfd
, (bfd_vma
) filehdr_in
->f_symptr
,
377 (bfd_byte
*) filehdr_out
->f_symptr
);
378 bfd_h_put_32(abfd
, filehdr_in
->f_nsyms
, (bfd_byte
*) filehdr_out
->f_nsyms
);
379 bfd_h_put_16(abfd
, filehdr_in
->f_opthdr
, (bfd_byte
*) filehdr_out
->f_opthdr
);
380 bfd_h_put_16(abfd
, filehdr_in
->f_flags
, (bfd_byte
*) filehdr_out
->f_flags
);
382 /* put in extra dos header stuff. This data remains essentially
383 constant, it just has to be tacked on to the beginning of all exes
385 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_magic
, (bfd_byte
*) filehdr_out
->e_magic
);
386 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_cblp
, (bfd_byte
*) filehdr_out
->e_cblp
);
387 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_cp
, (bfd_byte
*) filehdr_out
->e_cp
);
388 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_crlc
, (bfd_byte
*) filehdr_out
->e_crlc
);
389 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_cparhdr
,
390 (bfd_byte
*) filehdr_out
->e_cparhdr
);
391 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_minalloc
,
392 (bfd_byte
*) filehdr_out
->e_minalloc
);
393 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_maxalloc
,
394 (bfd_byte
*) filehdr_out
->e_maxalloc
);
395 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_ss
, (bfd_byte
*) filehdr_out
->e_ss
);
396 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_sp
, (bfd_byte
*) filehdr_out
->e_sp
);
397 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_csum
, (bfd_byte
*) filehdr_out
->e_csum
);
398 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_ip
, (bfd_byte
*) filehdr_out
->e_ip
);
399 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_cs
, (bfd_byte
*) filehdr_out
->e_cs
);
400 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_lfarlc
, (bfd_byte
*) filehdr_out
->e_lfarlc
);
401 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_ovno
, (bfd_byte
*) filehdr_out
->e_ovno
);
404 for (idx
=0; idx
< 4; idx
++)
405 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_res
[idx
],
406 (bfd_byte
*) filehdr_out
->e_res
[idx
]);
408 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_oemid
, (bfd_byte
*) filehdr_out
->e_oemid
);
409 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_oeminfo
,
410 (bfd_byte
*) filehdr_out
->e_oeminfo
);
413 for (idx
=0; idx
< 10; idx
++)
414 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_res2
[idx
],
415 (bfd_byte
*) filehdr_out
->e_res2
[idx
]);
417 bfd_h_put_32(abfd
, filehdr_in
->pe
.e_lfanew
, (bfd_byte
*) filehdr_out
->e_lfanew
);
421 for (idx
=0; idx
< 16; idx
++)
422 bfd_h_put_32(abfd
, filehdr_in
->pe
.dos_message
[idx
],
423 (bfd_byte
*) filehdr_out
->dos_message
[idx
]);
426 /* also put in the NT signature */
427 bfd_h_put_32(abfd
, filehdr_in
->pe
.nt_signature
,
428 (bfd_byte
*) filehdr_out
->nt_signature
);
438 coff_swap_filehdr_out (abfd
, in
, out
)
443 struct internal_filehdr
*filehdr_in
= (struct internal_filehdr
*)in
;
444 FILHDR
*filehdr_out
= (FILHDR
*)out
;
446 bfd_h_put_16(abfd
, filehdr_in
->f_magic
, (bfd_byte
*) filehdr_out
->f_magic
);
447 bfd_h_put_16(abfd
, filehdr_in
->f_nscns
, (bfd_byte
*) filehdr_out
->f_nscns
);
448 bfd_h_put_32(abfd
, filehdr_in
->f_timdat
, (bfd_byte
*) filehdr_out
->f_timdat
);
449 PUT_FILEHDR_SYMPTR (abfd
, (bfd_vma
) filehdr_in
->f_symptr
,
450 (bfd_byte
*) filehdr_out
->f_symptr
);
451 bfd_h_put_32(abfd
, filehdr_in
->f_nsyms
, (bfd_byte
*) filehdr_out
->f_nsyms
);
452 bfd_h_put_16(abfd
, filehdr_in
->f_opthdr
, (bfd_byte
*) filehdr_out
->f_opthdr
);
453 bfd_h_put_16(abfd
, filehdr_in
->f_flags
, (bfd_byte
*) filehdr_out
->f_flags
);
462 coff_swap_sym_in (abfd
, ext1
, in1
)
467 SYMENT
*ext
= (SYMENT
*)ext1
;
468 struct internal_syment
*in
= (struct internal_syment
*)in1
;
470 if( ext
->e
.e_name
[0] == 0) {
471 in
->_n
._n_n
._n_zeroes
= 0;
472 in
->_n
._n_n
._n_offset
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->e
.e
.e_offset
);
475 #if SYMNMLEN != E_SYMNMLEN
476 -> Error
, we need to cope with truncating
or extending SYMNMLEN
!;
478 memcpy(in
->_n
._n_name
, ext
->e
.e_name
, SYMNMLEN
);
482 in
->n_value
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->e_value
);
483 in
->n_scnum
= bfd_h_get_16(abfd
, (bfd_byte
*) ext
->e_scnum
);
484 if (sizeof(ext
->e_type
) == 2){
485 in
->n_type
= bfd_h_get_16(abfd
, (bfd_byte
*) ext
->e_type
);
488 in
->n_type
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->e_type
);
490 in
->n_sclass
= bfd_h_get_8(abfd
, ext
->e_sclass
);
491 in
->n_numaux
= bfd_h_get_8(abfd
, ext
->e_numaux
);
493 /* The section symbols for the .idata$ sections have class 68, which MS
494 documentation indicates is a section symbol. The problem is that the
495 value field in the symbol is simply a copy of the .idata section's flags
496 rather than something useful. When these symbols are encountered, change
497 the value to 0 and the section number to 1 so that they will be handled
498 somewhat correctly in the bfd code. */
499 if (in
->n_sclass
== 0x68) {
502 /* I have tried setting the class to 3 and using the following to set
503 the section number. This will put the address of the pointer to the
504 string kernel32.dll at addresses 0 and 0x10 off start of idata section
505 which is not correct */
506 /* if (strcmp (in->_n._n_name, ".idata$4") == 0) */
507 /* in->n_scnum = 3; */
509 /* in->n_scnum = 2; */
512 #ifdef coff_swap_sym_in_hook
513 coff_swap_sym_in_hook(abfd
, ext1
, in1
);
518 coff_swap_sym_out (abfd
, inp
, extp
)
523 struct internal_syment
*in
= (struct internal_syment
*)inp
;
524 SYMENT
*ext
=(SYMENT
*)extp
;
525 if(in
->_n
._n_name
[0] == 0) {
526 bfd_h_put_32(abfd
, 0, (bfd_byte
*) ext
->e
.e
.e_zeroes
);
527 bfd_h_put_32(abfd
, in
->_n
._n_n
._n_offset
, (bfd_byte
*) ext
->e
.e
.e_offset
);
530 #if SYMNMLEN != E_SYMNMLEN
531 -> Error
, we need to cope with truncating
or extending SYMNMLEN
!;
533 memcpy(ext
->e
.e_name
, in
->_n
._n_name
, SYMNMLEN
);
537 bfd_h_put_32(abfd
, in
->n_value
, (bfd_byte
*) ext
->e_value
);
538 bfd_h_put_16(abfd
, in
->n_scnum
, (bfd_byte
*) ext
->e_scnum
);
539 if (sizeof(ext
->e_type
) == 2)
541 bfd_h_put_16(abfd
, in
->n_type
, (bfd_byte
*) ext
->e_type
);
545 bfd_h_put_32(abfd
, in
->n_type
, (bfd_byte
*) ext
->e_type
);
547 bfd_h_put_8(abfd
, in
->n_sclass
, ext
->e_sclass
);
548 bfd_h_put_8(abfd
, in
->n_numaux
, ext
->e_numaux
);
554 coff_swap_aux_in (abfd
, ext1
, type
, class, indx
, numaux
, in1
)
563 AUXENT
*ext
= (AUXENT
*)ext1
;
564 union internal_auxent
*in
= (union internal_auxent
*)in1
;
568 if (ext
->x_file
.x_fname
[0] == 0) {
569 in
->x_file
.x_n
.x_zeroes
= 0;
570 in
->x_file
.x_n
.x_offset
=
571 bfd_h_get_32(abfd
, (bfd_byte
*) ext
->x_file
.x_n
.x_offset
);
573 #if FILNMLEN != E_FILNMLEN
574 -> Error
, we need to cope with truncating
or extending FILNMLEN
!;
576 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_fname
, FILNMLEN
);
587 if (type
== T_NULL
) {
588 in
->x_scn
.x_scnlen
= GET_SCN_SCNLEN(abfd
, ext
);
589 in
->x_scn
.x_nreloc
= GET_SCN_NRELOC(abfd
, ext
);
590 in
->x_scn
.x_nlinno
= GET_SCN_NLINNO(abfd
, ext
);
591 in
->x_scn
.x_checksum
= bfd_h_get_32 (abfd
,
592 (bfd_byte
*) ext
->x_scn
.x_checksum
);
593 in
->x_scn
.x_associated
=
594 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_scn
.x_associated
);
595 in
->x_scn
.x_comdat
= bfd_h_get_8 (abfd
,
596 (bfd_byte
*) ext
->x_scn
.x_comdat
);
602 in
->x_sym
.x_tagndx
.l
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->x_sym
.x_tagndx
);
604 in
->x_sym
.x_tvndx
= bfd_h_get_16(abfd
, (bfd_byte
*) ext
->x_sym
.x_tvndx
);
607 if (class == C_BLOCK
|| class == C_FCN
|| ISFCN (type
) || ISTAG (class))
609 in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
= GET_FCN_LNNOPTR (abfd
, ext
);
610 in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
= GET_FCN_ENDNDX (abfd
, ext
);
614 #if DIMNUM != E_DIMNUM
615 #error we need to cope with truncating or extending DIMNUM
617 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0] =
618 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
619 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1] =
620 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
621 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2] =
622 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
623 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3] =
624 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
628 in
->x_sym
.x_misc
.x_fsize
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->x_sym
.x_misc
.x_fsize
);
631 in
->x_sym
.x_misc
.x_lnsz
.x_lnno
= GET_LNSZ_LNNO(abfd
, ext
);
632 in
->x_sym
.x_misc
.x_lnsz
.x_size
= GET_LNSZ_SIZE(abfd
, ext
);
637 coff_swap_aux_out (abfd
, inp
, type
, class, indx
, numaux
, extp
)
646 union internal_auxent
*in
= (union internal_auxent
*)inp
;
647 AUXENT
*ext
= (AUXENT
*)extp
;
649 memset((PTR
)ext
, 0, AUXESZ
);
652 if (in
->x_file
.x_fname
[0] == 0) {
653 bfd_h_put_32(abfd
, 0, (bfd_byte
*) ext
->x_file
.x_n
.x_zeroes
);
655 in
->x_file
.x_n
.x_offset
,
656 (bfd_byte
*) ext
->x_file
.x_n
.x_offset
);
659 #if FILNMLEN != E_FILNMLEN
660 -> Error
, we need to cope with truncating
or extending FILNMLEN
!;
662 memcpy (ext
->x_file
.x_fname
, in
->x_file
.x_fname
, FILNMLEN
);
673 if (type
== T_NULL
) {
674 PUT_SCN_SCNLEN(abfd
, in
->x_scn
.x_scnlen
, ext
);
675 PUT_SCN_NRELOC(abfd
, in
->x_scn
.x_nreloc
, ext
);
676 PUT_SCN_NLINNO(abfd
, in
->x_scn
.x_nlinno
, ext
);
677 bfd_h_put_32 (abfd
, in
->x_scn
.x_checksum
,
678 (bfd_byte
*) ext
->x_scn
.x_checksum
);
679 bfd_h_put_16 (abfd
, in
->x_scn
.x_associated
,
680 (bfd_byte
*) ext
->x_scn
.x_associated
);
681 bfd_h_put_8 (abfd
, in
->x_scn
.x_comdat
,
682 (bfd_byte
*) ext
->x_scn
.x_comdat
);
688 bfd_h_put_32(abfd
, in
->x_sym
.x_tagndx
.l
, (bfd_byte
*) ext
->x_sym
.x_tagndx
);
690 bfd_h_put_16(abfd
, in
->x_sym
.x_tvndx
, (bfd_byte
*) ext
->x_sym
.x_tvndx
);
693 if (class == C_BLOCK
|| class == C_FCN
|| ISFCN (type
) || ISTAG (class))
695 PUT_FCN_LNNOPTR(abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
, ext
);
696 PUT_FCN_ENDNDX(abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
, ext
);
700 #if DIMNUM != E_DIMNUM
701 #error we need to cope with truncating or extending DIMNUM
703 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0],
704 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
705 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1],
706 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
707 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2],
708 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
709 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3],
710 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
714 bfd_h_put_32 (abfd
, in
->x_sym
.x_misc
.x_fsize
,
715 (bfd_byte
*) ext
->x_sym
.x_misc
.x_fsize
);
718 PUT_LNSZ_LNNO (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_lnno
, ext
);
719 PUT_LNSZ_SIZE (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_size
, ext
);
727 coff_swap_lineno_in (abfd
, ext1
, in1
)
732 LINENO
*ext
= (LINENO
*)ext1
;
733 struct internal_lineno
*in
= (struct internal_lineno
*)in1
;
735 in
->l_addr
.l_symndx
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->l_addr
.l_symndx
);
736 in
->l_lnno
= GET_LINENO_LNNO(abfd
, ext
);
740 coff_swap_lineno_out (abfd
, inp
, outp
)
745 struct internal_lineno
*in
= (struct internal_lineno
*)inp
;
746 struct external_lineno
*ext
= (struct external_lineno
*)outp
;
747 bfd_h_put_32(abfd
, in
->l_addr
.l_symndx
, (bfd_byte
*)
748 ext
->l_addr
.l_symndx
);
750 PUT_LINENO_LNNO (abfd
, in
->l_lnno
, ext
);
757 coff_swap_aouthdr_in (abfd
, aouthdr_ext1
, aouthdr_int1
)
762 struct internal_extra_pe_aouthdr
*a
;
763 PEAOUTHDR
*src
= (PEAOUTHDR
*)(aouthdr_ext1
);
764 AOUTHDR
*aouthdr_ext
= (AOUTHDR
*) aouthdr_ext1
;
765 struct internal_aouthdr
*aouthdr_int
= (struct internal_aouthdr
*)aouthdr_int1
;
767 aouthdr_int
->magic
= bfd_h_get_16(abfd
, (bfd_byte
*) aouthdr_ext
->magic
);
768 aouthdr_int
->vstamp
= bfd_h_get_16(abfd
, (bfd_byte
*) aouthdr_ext
->vstamp
);
770 GET_AOUTHDR_TSIZE (abfd
, (bfd_byte
*) aouthdr_ext
->tsize
);
772 GET_AOUTHDR_DSIZE (abfd
, (bfd_byte
*) aouthdr_ext
->dsize
);
774 GET_AOUTHDR_BSIZE (abfd
, (bfd_byte
*) aouthdr_ext
->bsize
);
776 GET_AOUTHDR_ENTRY (abfd
, (bfd_byte
*) aouthdr_ext
->entry
);
777 aouthdr_int
->text_start
=
778 GET_AOUTHDR_TEXT_START (abfd
, (bfd_byte
*) aouthdr_ext
->text_start
);
779 aouthdr_int
->data_start
=
780 GET_AOUTHDR_DATA_START (abfd
, (bfd_byte
*) aouthdr_ext
->data_start
);
782 a
= &aouthdr_int
->pe
;
783 a
->ImageBase
= bfd_h_get_32 (abfd
, (bfd_byte
*) src
->ImageBase
);
784 a
->SectionAlignment
= bfd_h_get_32 (abfd
, (bfd_byte
*) src
->SectionAlignment
);
785 a
->FileAlignment
= bfd_h_get_32 (abfd
, (bfd_byte
*) src
->FileAlignment
);
786 a
->MajorOperatingSystemVersion
=
787 bfd_h_get_16 (abfd
, (bfd_byte
*) src
->MajorOperatingSystemVersion
);
788 a
->MinorOperatingSystemVersion
=
789 bfd_h_get_16 (abfd
, (bfd_byte
*) src
->MinorOperatingSystemVersion
);
790 a
->MajorImageVersion
= bfd_h_get_16 (abfd
, (bfd_byte
*) src
->MajorImageVersion
);
791 a
->MinorImageVersion
= bfd_h_get_16 (abfd
, (bfd_byte
*) src
->MinorImageVersion
);
792 a
->MajorSubsystemVersion
= bfd_h_get_16 (abfd
, (bfd_byte
*) src
->MajorSubsystemVersion
);
793 a
->MinorSubsystemVersion
= bfd_h_get_16 (abfd
, (bfd_byte
*) src
->MinorSubsystemVersion
);
794 a
->Reserved1
= bfd_h_get_32 (abfd
, (bfd_byte
*) src
->Reserved1
);
795 a
->SizeOfImage
= bfd_h_get_32 (abfd
, (bfd_byte
*) src
->SizeOfImage
);
796 a
->SizeOfHeaders
= bfd_h_get_32 (abfd
, (bfd_byte
*) src
->SizeOfHeaders
);
797 a
->CheckSum
= bfd_h_get_32 (abfd
, (bfd_byte
*) src
->CheckSum
);
798 a
->Subsystem
= bfd_h_get_16 (abfd
, (bfd_byte
*) src
->Subsystem
);
799 a
->DllCharacteristics
= bfd_h_get_16 (abfd
, (bfd_byte
*) src
->DllCharacteristics
);
800 a
->SizeOfStackReserve
= bfd_h_get_32 (abfd
, (bfd_byte
*) src
->SizeOfStackReserve
);
801 a
->SizeOfStackCommit
= bfd_h_get_32 (abfd
, (bfd_byte
*) src
->SizeOfStackCommit
);
802 a
->SizeOfHeapReserve
= bfd_h_get_32 (abfd
, (bfd_byte
*) src
->SizeOfHeapReserve
);
803 a
->SizeOfHeapCommit
= bfd_h_get_32 (abfd
, (bfd_byte
*) src
->SizeOfHeapCommit
);
804 a
->LoaderFlags
= bfd_h_get_32 (abfd
, (bfd_byte
*) src
->LoaderFlags
);
805 a
->NumberOfRvaAndSizes
= bfd_h_get_32 (abfd
, (bfd_byte
*) src
->NumberOfRvaAndSizes
);
809 for (idx
=0; idx
< 16; idx
++)
811 a
->DataDirectory
[idx
].VirtualAddress
=
812 bfd_h_get_32 (abfd
, (bfd_byte
*) src
->DataDirectory
[idx
][0]);
813 a
->DataDirectory
[idx
].Size
=
814 bfd_h_get_32 (abfd
, (bfd_byte
*) src
->DataDirectory
[idx
][1]);
818 if (aouthdr_int
->entry
)
820 aouthdr_int
->entry
+= a
->ImageBase
;
821 aouthdr_int
->entry
&= 0xffffffff;
823 if (aouthdr_int
->tsize
)
825 aouthdr_int
->text_start
+= a
->ImageBase
;
826 aouthdr_int
->text_start
&= 0xffffffff;
828 if (aouthdr_int
->dsize
)
830 aouthdr_int
->data_start
+= a
->ImageBase
;
831 aouthdr_int
->data_start
&= 0xffffffff;
835 /* These three fields are normally set up by ppc_relocate_section.
836 In the case of reading a file in, we can pick them up from
839 first_thunk_address
= a
->DataDirectory
[12].VirtualAddress
;
840 thunk_size
= a
->DataDirectory
[12].Size
;
841 import_table_size
= a
->DataDirectory
[1].Size
;
846 static void add_data_entry (abfd
, aout
, idx
, name
, base
)
848 struct internal_extra_pe_aouthdr
*aout
;
853 asection
*sec
= bfd_get_section_by_name (abfd
, name
);
855 /* add import directory information if it exists */
858 aout
->DataDirectory
[idx
].VirtualAddress
= (sec
->vma
- base
) & 0xffffffff;
859 aout
->DataDirectory
[idx
].Size
= pei_section_data (abfd
, sec
)->virt_size
;
860 sec
->flags
|= SEC_DATA
;
865 coff_swap_aouthdr_out (abfd
, in
, out
)
870 struct internal_aouthdr
*aouthdr_in
= (struct internal_aouthdr
*)in
;
871 struct internal_extra_pe_aouthdr
*extra
= &pe_data (abfd
)->pe_opthdr
;
872 PEAOUTHDR
*aouthdr_out
= (PEAOUTHDR
*)out
;
874 bfd_vma sa
= extra
->SectionAlignment
;
875 bfd_vma fa
= extra
->FileAlignment
;
876 bfd_vma ib
= extra
->ImageBase
;
878 if (aouthdr_in
->tsize
)
880 aouthdr_in
->text_start
-= ib
;
881 aouthdr_in
->text_start
&= 0xffffffff;
883 if (aouthdr_in
->dsize
)
885 aouthdr_in
->data_start
-= ib
;
886 aouthdr_in
->data_start
&= 0xffffffff;
888 if (aouthdr_in
->entry
)
890 aouthdr_in
->entry
-= ib
;
891 aouthdr_in
->entry
&= 0xffffffff;
894 #define FA(x) (((x) + fa -1 ) & (- fa))
895 #define SA(x) (((x) + sa -1 ) & (- sa))
897 /* We like to have the sizes aligned */
899 aouthdr_in
->bsize
= FA (aouthdr_in
->bsize
);
902 extra
->NumberOfRvaAndSizes
= IMAGE_NUMBEROF_DIRECTORY_ENTRIES
;
904 /* first null out all data directory entries .. */
905 memset (extra
->DataDirectory
, sizeof (extra
->DataDirectory
), 0);
907 add_data_entry (abfd
, extra
, 0, ".edata", ib
);
908 add_data_entry (abfd
, extra
, 1, ".idata", ib
);
909 add_data_entry (abfd
, extra
, 2, ".rsrc" ,ib
);
912 /* FIXME: do other PE platforms use this? */
913 add_data_entry (abfd
, extra
, 3, ".pdata" ,ib
);
916 add_data_entry (abfd
, extra
, 5, ".reloc", ib
);
919 /* On the PPC NT system, this field is set up as follows. It is
920 not an "officially" reserved field, so it currently has no title.
921 first_thunk_address is idata$5, and the thunk_size is the size
922 of the idata$5 chunk of the idata section.
924 extra
->DataDirectory
[12].VirtualAddress
= first_thunk_address
;
925 extra
->DataDirectory
[12].Size
= thunk_size
;
927 /* On the PPC NT system, the size of the directory entry is not the
928 size of the entire section. It's actually offset to the end of
929 the idata$3 component of the idata section. This is the size of
930 the entire import table. (also known as the start of idata$4)
932 extra
->DataDirectory
[1].Size
= import_table_size
;
938 bfd_vma isize
= SA(abfd
->sections
->filepos
);
941 for (sec
= abfd
->sections
; sec
; sec
= sec
->next
)
943 int rounded
= FA(sec
->_raw_size
);
945 if (sec
->flags
& SEC_DATA
)
947 if (sec
->flags
& SEC_CODE
)
949 isize
+= SA(rounded
);
952 aouthdr_in
->dsize
= dsize
;
953 aouthdr_in
->tsize
= tsize
;
954 extra
->SizeOfImage
= isize
;
957 extra
->SizeOfHeaders
= abfd
->sections
->filepos
;
958 bfd_h_put_16(abfd
, aouthdr_in
->magic
, (bfd_byte
*) aouthdr_out
->standard
.magic
);
961 /* this little piece of magic sets the "linker version" field to 2.60 */
962 bfd_h_put_16(abfd
, 2 + 60 * 256, (bfd_byte
*) aouthdr_out
->standard
.vstamp
);
964 /* this little piece of magic sets the "linker version" field to 2.55 */
965 bfd_h_put_16(abfd
, 2 + 55 * 256, (bfd_byte
*) aouthdr_out
->standard
.vstamp
);
968 PUT_AOUTHDR_TSIZE (abfd
, aouthdr_in
->tsize
, (bfd_byte
*) aouthdr_out
->standard
.tsize
);
969 PUT_AOUTHDR_DSIZE (abfd
, aouthdr_in
->dsize
, (bfd_byte
*) aouthdr_out
->standard
.dsize
);
970 PUT_AOUTHDR_BSIZE (abfd
, aouthdr_in
->bsize
, (bfd_byte
*) aouthdr_out
->standard
.bsize
);
971 PUT_AOUTHDR_ENTRY (abfd
, aouthdr_in
->entry
, (bfd_byte
*) aouthdr_out
->standard
.entry
);
972 PUT_AOUTHDR_TEXT_START (abfd
, aouthdr_in
->text_start
,
973 (bfd_byte
*) aouthdr_out
->standard
.text_start
);
975 PUT_AOUTHDR_DATA_START (abfd
, aouthdr_in
->data_start
,
976 (bfd_byte
*) aouthdr_out
->standard
.data_start
);
979 bfd_h_put_32 (abfd
, extra
->ImageBase
,
980 (bfd_byte
*) aouthdr_out
->ImageBase
);
981 bfd_h_put_32 (abfd
, extra
->SectionAlignment
,
982 (bfd_byte
*) aouthdr_out
->SectionAlignment
);
983 bfd_h_put_32 (abfd
, extra
->FileAlignment
,
984 (bfd_byte
*) aouthdr_out
->FileAlignment
);
985 bfd_h_put_16 (abfd
, extra
->MajorOperatingSystemVersion
,
986 (bfd_byte
*) aouthdr_out
->MajorOperatingSystemVersion
);
987 bfd_h_put_16 (abfd
, extra
->MinorOperatingSystemVersion
,
988 (bfd_byte
*) aouthdr_out
->MinorOperatingSystemVersion
);
989 bfd_h_put_16 (abfd
, extra
->MajorImageVersion
,
990 (bfd_byte
*) aouthdr_out
->MajorImageVersion
);
991 bfd_h_put_16 (abfd
, extra
->MinorImageVersion
,
992 (bfd_byte
*) aouthdr_out
->MinorImageVersion
);
993 bfd_h_put_16 (abfd
, extra
->MajorSubsystemVersion
,
994 (bfd_byte
*) aouthdr_out
->MajorSubsystemVersion
);
995 bfd_h_put_16 (abfd
, extra
->MinorSubsystemVersion
,
996 (bfd_byte
*) aouthdr_out
->MinorSubsystemVersion
);
997 bfd_h_put_32 (abfd
, extra
->Reserved1
,
998 (bfd_byte
*) aouthdr_out
->Reserved1
);
999 bfd_h_put_32 (abfd
, extra
->SizeOfImage
,
1000 (bfd_byte
*) aouthdr_out
->SizeOfImage
);
1001 bfd_h_put_32 (abfd
, extra
->SizeOfHeaders
,
1002 (bfd_byte
*) aouthdr_out
->SizeOfHeaders
);
1003 bfd_h_put_32 (abfd
, extra
->CheckSum
,
1004 (bfd_byte
*) aouthdr_out
->CheckSum
);
1005 bfd_h_put_16 (abfd
, extra
->Subsystem
,
1006 (bfd_byte
*) aouthdr_out
->Subsystem
);
1007 bfd_h_put_16 (abfd
, extra
->DllCharacteristics
,
1008 (bfd_byte
*) aouthdr_out
->DllCharacteristics
);
1009 bfd_h_put_32 (abfd
, extra
->SizeOfStackReserve
,
1010 (bfd_byte
*) aouthdr_out
->SizeOfStackReserve
);
1011 bfd_h_put_32 (abfd
, extra
->SizeOfStackCommit
,
1012 (bfd_byte
*) aouthdr_out
->SizeOfStackCommit
);
1013 bfd_h_put_32 (abfd
, extra
->SizeOfHeapReserve
,
1014 (bfd_byte
*) aouthdr_out
->SizeOfHeapReserve
);
1015 bfd_h_put_32 (abfd
, extra
->SizeOfHeapCommit
,
1016 (bfd_byte
*) aouthdr_out
->SizeOfHeapCommit
);
1017 bfd_h_put_32 (abfd
, extra
->LoaderFlags
,
1018 (bfd_byte
*) aouthdr_out
->LoaderFlags
);
1019 bfd_h_put_32 (abfd
, extra
->NumberOfRvaAndSizes
,
1020 (bfd_byte
*) aouthdr_out
->NumberOfRvaAndSizes
);
1023 for (idx
=0; idx
< 16; idx
++)
1025 bfd_h_put_32 (abfd
, extra
->DataDirectory
[idx
].VirtualAddress
,
1026 (bfd_byte
*) aouthdr_out
->DataDirectory
[idx
][0]);
1027 bfd_h_put_32 (abfd
, extra
->DataDirectory
[idx
].Size
,
1028 (bfd_byte
*) aouthdr_out
->DataDirectory
[idx
][1]);
1036 coff_swap_scnhdr_in (abfd
, ext
, in
)
1041 SCNHDR
*scnhdr_ext
= (SCNHDR
*) ext
;
1042 struct internal_scnhdr
*scnhdr_int
= (struct internal_scnhdr
*) in
;
1044 memcpy(scnhdr_int
->s_name
, scnhdr_ext
->s_name
, sizeof(scnhdr_int
->s_name
));
1045 scnhdr_int
->s_vaddr
=
1046 GET_SCNHDR_VADDR (abfd
, (bfd_byte
*) scnhdr_ext
->s_vaddr
);
1047 scnhdr_int
->s_paddr
=
1048 GET_SCNHDR_PADDR (abfd
, (bfd_byte
*) scnhdr_ext
->s_paddr
);
1049 scnhdr_int
->s_size
=
1050 GET_SCNHDR_SIZE (abfd
, (bfd_byte
*) scnhdr_ext
->s_size
);
1051 scnhdr_int
->s_scnptr
=
1052 GET_SCNHDR_SCNPTR (abfd
, (bfd_byte
*) scnhdr_ext
->s_scnptr
);
1053 scnhdr_int
->s_relptr
=
1054 GET_SCNHDR_RELPTR (abfd
, (bfd_byte
*) scnhdr_ext
->s_relptr
);
1055 scnhdr_int
->s_lnnoptr
=
1056 GET_SCNHDR_LNNOPTR (abfd
, (bfd_byte
*) scnhdr_ext
->s_lnnoptr
);
1057 scnhdr_int
->s_flags
= bfd_h_get_32(abfd
, (bfd_byte
*) scnhdr_ext
->s_flags
);
1059 scnhdr_int
->s_nreloc
= bfd_h_get_16(abfd
, (bfd_byte
*) scnhdr_ext
->s_nreloc
);
1060 scnhdr_int
->s_nlnno
= bfd_h_get_16(abfd
, (bfd_byte
*) scnhdr_ext
->s_nlnno
);
1062 if (scnhdr_int
->s_vaddr
!= 0)
1064 scnhdr_int
->s_vaddr
+= pe_data (abfd
)->pe_opthdr
.ImageBase
;
1065 scnhdr_int
->s_vaddr
&= 0xffffffff;
1067 if (strcmp (scnhdr_int
->s_name
, _BSS
) == 0)
1069 scnhdr_int
->s_size
= scnhdr_int
->s_paddr
;
1070 scnhdr_int
->s_paddr
= 0;
1075 coff_swap_scnhdr_out (abfd
, in
, out
)
1080 struct internal_scnhdr
*scnhdr_int
= (struct internal_scnhdr
*)in
;
1081 SCNHDR
*scnhdr_ext
= (SCNHDR
*)out
;
1082 unsigned int ret
= SCNHSZ
;
1086 memcpy(scnhdr_ext
->s_name
, scnhdr_int
->s_name
, sizeof(scnhdr_int
->s_name
));
1088 PUT_SCNHDR_VADDR (abfd
,
1089 ((scnhdr_int
->s_vaddr
1090 - pe_data(abfd
)->pe_opthdr
.ImageBase
)
1092 (bfd_byte
*) scnhdr_ext
->s_vaddr
);
1094 /* NT wants the size data to be rounded up to the next NT_FILE_ALIGNMENT
1095 value except for the BSS section, its s_size should be 0 */
1098 if (strcmp (scnhdr_int
->s_name
, _BSS
) == 0)
1100 ps
= scnhdr_int
->s_size
;
1105 ps
= scnhdr_int
->s_paddr
;
1106 ss
= scnhdr_int
->s_size
;
1109 PUT_SCNHDR_SIZE (abfd
, ss
,
1110 (bfd_byte
*) scnhdr_ext
->s_size
);
1113 PUT_SCNHDR_PADDR (abfd
, ps
, (bfd_byte
*) scnhdr_ext
->s_paddr
);
1115 PUT_SCNHDR_SCNPTR (abfd
, scnhdr_int
->s_scnptr
,
1116 (bfd_byte
*) scnhdr_ext
->s_scnptr
);
1117 PUT_SCNHDR_RELPTR (abfd
, scnhdr_int
->s_relptr
,
1118 (bfd_byte
*) scnhdr_ext
->s_relptr
);
1119 PUT_SCNHDR_LNNOPTR (abfd
, scnhdr_int
->s_lnnoptr
,
1120 (bfd_byte
*) scnhdr_ext
->s_lnnoptr
);
1122 /* Extra flags must be set when dealing with NT. All sections should also
1123 have the IMAGE_SCN_MEM_READ (0x40000000) flag set. In addition, the
1124 .text section must have IMAGE_SCN_MEM_EXECUTE (0x20000000) and the data
1125 sections (.idata, .data, .bss, .CRT) must have IMAGE_SCN_MEM_WRITE set
1126 (this is especially important when dealing with the .idata section since
1127 the addresses for routines from .dlls must be overwritten). If .reloc
1128 section data is ever generated, we must add IMAGE_SCN_MEM_DISCARDABLE
1129 (0x02000000). Also, the resource data should also be read and
1132 /* FIXME: alignment is also encoded in this field, at least on ppc (krk) */
1133 /* FIXME: even worse, I don't see how to get the original alignment field*/
1136 /* FIXME: Basing this on section names is bogus. Also, this should
1137 be in sec_to_styp_flags. */
1140 int flags
= scnhdr_int
->s_flags
;
1141 if (strcmp (scnhdr_int
->s_name
, ".data") == 0 ||
1142 strcmp (scnhdr_int
->s_name
, ".CRT") == 0 ||
1143 strcmp (scnhdr_int
->s_name
, ".bss") == 0)
1144 flags
|= IMAGE_SCN_MEM_READ
| IMAGE_SCN_MEM_WRITE
;
1145 else if (strcmp (scnhdr_int
->s_name
, ".text") == 0)
1146 flags
|= IMAGE_SCN_MEM_READ
| IMAGE_SCN_MEM_EXECUTE
;
1147 else if (strcmp (scnhdr_int
->s_name
, ".reloc") == 0)
1148 flags
= (SEC_DATA
| IMAGE_SCN_MEM_READ
| IMAGE_SCN_MEM_DISCARDABLE
1149 | IMAGE_SCN_MEM_SHARED
);
1150 else if (strcmp (scnhdr_int
->s_name
, ".idata") == 0)
1151 flags
= IMAGE_SCN_MEM_READ
| IMAGE_SCN_MEM_WRITE
| SEC_DATA
;
1152 else if (strcmp (scnhdr_int
->s_name
, ".rdata") == 0
1153 || strcmp (scnhdr_int
->s_name
, ".edata") == 0)
1154 flags
= IMAGE_SCN_MEM_READ
| SEC_DATA
;
1155 else if (strcmp (scnhdr_int
->s_name
, ".pdata") == 0)
1156 flags
= IMAGE_SCN_CNT_INITIALIZED_DATA
| IMAGE_SCN_ALIGN_4BYTES
|
1157 IMAGE_SCN_MEM_READ
;
1158 /* Remember this field is a max of 8 chars, so the null is _not_ there
1159 for an 8 character name like ".reldata". (yep. Stupid bug) */
1160 else if (strncmp (scnhdr_int
->s_name
, ".reldata", 8) == 0)
1161 flags
= IMAGE_SCN_CNT_INITIALIZED_DATA
| IMAGE_SCN_ALIGN_8BYTES
|
1162 IMAGE_SCN_MEM_READ
| IMAGE_SCN_MEM_WRITE
;
1163 else if (strcmp (scnhdr_int
->s_name
, ".ydata") == 0)
1164 flags
= IMAGE_SCN_CNT_INITIALIZED_DATA
| IMAGE_SCN_ALIGN_8BYTES
|
1165 IMAGE_SCN_MEM_READ
| IMAGE_SCN_MEM_WRITE
;
1166 else if (strncmp (scnhdr_int
->s_name
, ".drectve", 8) == 0)
1167 flags
= IMAGE_SCN_LNK_INFO
| IMAGE_SCN_LNK_REMOVE
;
1168 else if (strncmp (scnhdr_int
->s_name
, ".stab", 5) == 0)
1169 flags
|= (IMAGE_SCN_LNK_INFO
| IMAGE_SCN_MEM_DISCARDABLE
1170 | IMAGE_SCN_MEM_SHARED
| IMAGE_SCN_MEM_READ
);
1171 else if (strcmp (scnhdr_int
->s_name
, ".rsrc") == 0)
1172 flags
|= IMAGE_SCN_MEM_READ
| IMAGE_SCN_MEM_SHARED
;
1174 flags
|= IMAGE_SCN_MEM_READ
;
1176 bfd_h_put_32(abfd
, flags
, (bfd_byte
*) scnhdr_ext
->s_flags
);
1179 if (scnhdr_int
->s_nlnno
<= 0xffff)
1180 bfd_h_put_16(abfd
, scnhdr_int
->s_nlnno
, (bfd_byte
*) scnhdr_ext
->s_nlnno
);
1183 (*_bfd_error_handler
) ("%s: line number overflow: 0x%lx > 0xffff",
1184 bfd_get_filename (abfd
),
1185 scnhdr_int
->s_nlnno
);
1186 bfd_set_error (bfd_error_file_truncated
);
1187 bfd_h_put_16 (abfd
, 0xffff, (bfd_byte
*) scnhdr_ext
->s_nlnno
);
1190 if (scnhdr_int
->s_nreloc
<= 0xffff)
1191 bfd_h_put_16(abfd
, scnhdr_int
->s_nreloc
, (bfd_byte
*) scnhdr_ext
->s_nreloc
);
1194 (*_bfd_error_handler
) ("%s: reloc overflow: 0x%lx > 0xffff",
1195 bfd_get_filename (abfd
),
1196 scnhdr_int
->s_nreloc
);
1197 bfd_set_error (bfd_error_file_truncated
);
1198 bfd_h_put_16 (abfd
, 0xffff, (bfd_byte
*) scnhdr_ext
->s_nreloc
);
1204 static char * dir_names
[IMAGE_NUMBEROF_DIRECTORY_ENTRIES
] =
1206 "Export Directory [.edata (or where ever we found it)]",
1207 "Import Directory [parts of .idata]",
1208 "Resource Directory [.rsrc]",
1209 "Exception Directory [.pdata]",
1210 "Security Directory",
1211 "Base Relocation Directory [.reloc]",
1213 "Description Directory",
1214 "Special Directory",
1215 "Thread Storage Directory [.tls]",
1216 "Load Configuration Directory",
1217 "Bound Import Directory",
1218 "Import Address Table Directory",
1224 /**********************************************************************/
1226 pe_print_idata(abfd
, vfile
)
1230 FILE *file
= (FILE *) vfile
;
1232 asection
*section
= bfd_get_section_by_name (abfd
, ".idata");
1235 #ifdef POWERPC_LE_PE
1236 asection
*rel_section
= bfd_get_section_by_name (abfd
, ".reldata");
1239 bfd_size_type datasize
;
1240 bfd_size_type dataoff
;
1241 bfd_size_type secsize
;
1243 bfd_size_type start
, stop
;
1246 pe_data_type
*pe
= pe_data (abfd
);
1247 struct internal_extra_pe_aouthdr
*extra
= &pe
->pe_opthdr
;
1249 if (section
!= NULL
)
1251 datasize
= bfd_section_size (abfd
, section
);
1261 addr
= extra
->DataDirectory
[1].VirtualAddress
;
1262 size
= extra
->DataDirectory
[1].Size
;
1264 if (addr
== 0 || size
== 0)
1267 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
1269 if (section
->vma
- extra
->ImageBase
<= addr
1270 && ((section
->vma
- extra
->ImageBase
1271 + bfd_section_size (abfd
, section
))
1275 if (section
== NULL
)
1278 /* For some reason the import table size is not reliable. The
1279 import data will extend past the indicated size, and before
1280 the indicated address. */
1281 dataoff
= addr
- (section
->vma
- extra
->ImageBase
);
1285 #ifdef POWERPC_LE_PE
1286 if (rel_section
!= 0 && bfd_section_size (abfd
, rel_section
) != 0)
1288 /* The toc address can be found by taking the starting address,
1289 which on the PPC locates a function descriptor. The descriptor
1290 consists of the function code starting address followed by the
1291 address of the toc. The starting address we get from the bfd,
1292 and the descriptor is supposed to be in the .reldata section.
1295 bfd_vma loadable_toc_address
;
1296 bfd_vma toc_address
;
1297 bfd_vma start_address
;
1300 data
= (bfd_byte
*) bfd_malloc ((size_t) bfd_section_size (abfd
,
1302 if (data
== NULL
&& bfd_section_size (abfd
, rel_section
) != 0)
1305 datasize
= bfd_section_size (abfd
, rel_section
);
1307 bfd_get_section_contents (abfd
,
1310 bfd_section_size (abfd
, rel_section
));
1312 offset
= abfd
->start_address
- rel_section
->vma
;
1314 start_address
= bfd_get_32(abfd
, data
+offset
);
1315 loadable_toc_address
= bfd_get_32(abfd
, data
+offset
+4);
1316 toc_address
= loadable_toc_address
- 32768;
1319 "\nFunction descriptor located at the start address: %04lx\n",
1320 (unsigned long int) (abfd
->start_address
));
1322 "\tcode-base %08lx toc (loadable/actual) %08lx/%08lx\n",
1323 start_address
, loadable_toc_address
, toc_address
);
1328 "\nNo reldata section! Function descriptor not decoded.\n");
1333 "\nThe Import Tables (interpreted .idata section contents)\n");
1335 " vma: Hint Time Forward DLL First\n");
1337 " Table Stamp Chain Name Thunk\n");
1339 secsize
= bfd_section_size (abfd
, section
);
1340 data
= (bfd_byte
*) bfd_malloc (secsize
);
1341 if (data
== NULL
&& secsize
!= 0)
1344 if (! bfd_get_section_contents (abfd
, section
, (PTR
) data
, 0, secsize
))
1347 adj
= (extra
->ImageBase
- section
->vma
) & 0xffffffff;
1350 stop
= dataoff
+ datasize
;
1351 for (i
= start
; i
< stop
; i
+= onaline
)
1355 bfd_vma forward_chain
;
1357 bfd_vma first_thunk
;
1364 (unsigned long int) (i
+ section
->vma
+ dataoff
));
1372 hint_addr
= bfd_get_32(abfd
, data
+i
);
1373 time_stamp
= bfd_get_32(abfd
, data
+i
+4);
1374 forward_chain
= bfd_get_32(abfd
, data
+i
+8);
1375 dll_name
= bfd_get_32(abfd
, data
+i
+12);
1376 first_thunk
= bfd_get_32(abfd
, data
+i
+16);
1378 fprintf(file
, "%08lx %08lx %08lx %08lx %08lx\n",
1385 if (hint_addr
== 0 && first_thunk
== 0)
1388 /* the image base is present in the section->vma */
1389 dll
= (char *) data
+ dll_name
+ adj
;
1390 fprintf(file
, "\n\tDLL Name: %s\n", dll
);
1394 fprintf (file
, "\tvma: Hint/Ord Member-Name\n");
1396 idx
= hint_addr
+ adj
;
1398 for (j
= 0; j
< stop
; j
+= 4)
1400 unsigned long member
= bfd_get_32 (abfd
, data
+ idx
+ j
);
1404 if (member
& 0x80000000)
1405 fprintf (file
, "\t%04lx\t %4lu", member
,
1406 member
& 0x7fffffff);
1412 ordinal
= bfd_get_16 (abfd
, data
+ member
+ adj
);
1413 member_name
= (char *) data
+ member
+ adj
+ 2;
1414 fprintf (file
, "\t%04lx\t %4d %s",
1415 member
, ordinal
, member_name
);
1418 /* If the time stamp is not zero, the import address
1419 table holds actual addresses. */
1422 && first_thunk
!= hint_addr
)
1423 fprintf (file
, "\t%04lx",
1424 bfd_get_32 (abfd
, data
+ first_thunk
+ adj
+ j
));
1426 fprintf (file
, "\n");
1430 if (hint_addr
!= first_thunk
&& time_stamp
== 0)
1435 idx2
= first_thunk
+ adj
;
1437 for (j
=0;j
<stop
;j
+=4)
1441 bfd_vma hint_member
;
1444 if (time_stamp
!= 0)
1449 hint_member
= bfd_get_32 (abfd
, data
+ idx
+ j
);
1450 iat_member
= bfd_get_32 (abfd
, data
+ idx2
+ j
);
1452 if (hint_addr
== 0 && iat_member
== 0)
1455 if (hint_addr
== 0 || hint_member
!= iat_member
)
1460 "\tThe Import Address Table (difference found)\n");
1461 fprintf(file
, "\tvma: Hint/Ord Member-Name\n");
1464 if (iat_member
== 0)
1467 "\t>>> Ran out of IAT members!\n");
1471 ordinal
= bfd_get_16(abfd
,
1472 data
+ iat_member
+ adj
);
1473 member_name
= (char *) data
+ iat_member
+ adj
+ 2;
1474 fprintf(file
, "\t%04lx\t %4d %s\n",
1475 iat_member
, ordinal
, member_name
);
1479 if (hint_addr
!= 0 && hint_member
== 0)
1485 "\tThe Import Address Table is identical\n");
1489 fprintf(file
, "\n");
1499 pe_print_edata (abfd
, vfile
)
1503 FILE *file
= (FILE *) vfile
;
1505 asection
*section
= bfd_get_section_by_name (abfd
, ".edata");
1507 bfd_size_type datasize
;
1508 bfd_size_type dataoff
;
1514 long export_flags
; /* reserved - should be zero */
1518 bfd_vma name
; /* rva - relative to image base */
1519 long base
; /* ordinal base */
1520 long num_functions
; /* Number in the export address table */
1521 long num_names
; /* Number in the name pointer table */
1522 bfd_vma eat_addr
; /* rva to the export address table */
1523 bfd_vma npt_addr
; /* rva to the Export Name Pointer Table */
1524 bfd_vma ot_addr
; /* rva to the Ordinal Table */
1527 pe_data_type
*pe
= pe_data (abfd
);
1528 struct internal_extra_pe_aouthdr
*extra
= &pe
->pe_opthdr
;
1530 if (section
!= NULL
)
1532 datasize
= bfd_section_size (abfd
, section
);
1539 addr
= extra
->DataDirectory
[0].VirtualAddress
;
1540 size
= extra
->DataDirectory
[0].Size
;
1542 if (addr
== 0 || size
== 0)
1545 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
1547 if (section
->vma
- extra
->ImageBase
<= addr
1548 && ((section
->vma
- extra
->ImageBase
1549 + bfd_section_size (abfd
, section
))
1553 if (section
== NULL
)
1557 dataoff
= addr
- (section
->vma
- extra
->ImageBase
);
1560 data
= (bfd_byte
*) bfd_malloc (datasize
);
1561 if (data
== NULL
&& datasize
!= 0)
1564 if (! bfd_get_section_contents (abfd
, section
, (PTR
) data
, dataoff
,
1568 /* Go get Export Directory Table */
1569 edt
.export_flags
= bfd_get_32(abfd
, data
+0);
1570 edt
.time_stamp
= bfd_get_32(abfd
, data
+4);
1571 edt
.major_ver
= bfd_get_16(abfd
, data
+8);
1572 edt
.minor_ver
= bfd_get_16(abfd
, data
+10);
1573 edt
.name
= bfd_get_32(abfd
, data
+12);
1574 edt
.base
= bfd_get_32(abfd
, data
+16);
1575 edt
.num_functions
= bfd_get_32(abfd
, data
+20);
1576 edt
.num_names
= bfd_get_32(abfd
, data
+24);
1577 edt
.eat_addr
= bfd_get_32(abfd
, data
+28);
1578 edt
.npt_addr
= bfd_get_32(abfd
, data
+32);
1579 edt
.ot_addr
= bfd_get_32(abfd
, data
+36);
1581 adj
= (extra
->ImageBase
- (section
->vma
+ dataoff
)) & 0xffffffff;
1584 /* Dump the EDT first first */
1586 "\nThe Export Tables (interpreted .edata section contents)\n\n");
1589 "Export Flags \t\t\t%lx\n", (unsigned long) edt
.export_flags
);
1592 "Time/Date stamp \t\t%lx\n", (unsigned long) edt
.time_stamp
);
1595 "Major/Minor \t\t\t%d/%d\n", edt
.major_ver
, edt
.minor_ver
);
1599 fprintf_vma (file
, edt
.name
);
1601 " %s\n", data
+ edt
.name
+ adj
);
1604 "Ordinal Base \t\t\t%ld\n", edt
.base
);
1610 "\tExport Address Table \t\t%lx\n",
1611 (unsigned long) edt
.num_functions
);
1614 "\t[Name Pointer/Ordinal] Table\t%ld\n", edt
.num_names
);
1617 "Table Addresses\n");
1620 "\tExport Address Table \t\t");
1621 fprintf_vma (file
, edt
.eat_addr
);
1622 fprintf (file
, "\n");
1625 "\tName Pointer Table \t\t");
1626 fprintf_vma (file
, edt
.npt_addr
);
1627 fprintf (file
, "\n");
1630 "\tOrdinal Table \t\t\t");
1631 fprintf_vma (file
, edt
.ot_addr
);
1632 fprintf (file
, "\n");
1635 /* The next table to find si the Export Address Table. It's basically
1636 a list of pointers that either locate a function in this dll, or
1637 forward the call to another dll. Something like:
1642 } export_address_table_entry;
1646 "\nExport Address Table -- Ordinal Base %ld\n",
1649 for (i
= 0; i
< edt
.num_functions
; ++i
)
1651 bfd_vma eat_member
= bfd_get_32 (abfd
,
1652 data
+ edt
.eat_addr
+ (i
* 4) + adj
);
1653 bfd_vma eat_actual
= (extra
->ImageBase
+ eat_member
) & 0xffffffff;
1654 bfd_vma edata_start
= bfd_get_section_vma (abfd
,section
) + dataoff
;
1655 bfd_vma edata_end
= edata_start
+ datasize
;
1657 if (eat_member
== 0)
1660 if (edata_start
< eat_actual
&& eat_actual
< edata_end
)
1662 /* this rva is to a name (forwarding function) in our section */
1663 /* Should locate a function descriptor */
1665 "\t[%4ld] +base[%4ld] %04lx %s -- %s\n",
1666 (long) i
, (long) (i
+ edt
.base
), eat_member
,
1667 "Forwarder RVA", data
+ eat_member
+ adj
);
1671 /* Should locate a function descriptor in the reldata section */
1673 "\t[%4ld] +base[%4ld] %04lx %s\n",
1674 (long) i
, (long) (i
+ edt
.base
), eat_member
, "Export RVA");
1678 /* The Export Name Pointer Table is paired with the Export Ordinal Table */
1679 /* Dump them in parallel for clarity */
1681 "\n[Ordinal/Name Pointer] Table\n");
1683 for (i
= 0; i
< edt
.num_names
; ++i
)
1685 bfd_vma name_ptr
= bfd_get_32(abfd
,
1690 char *name
= (char *) data
+ name_ptr
+ adj
;
1692 bfd_vma ord
= bfd_get_16(abfd
,
1697 "\t[%4ld] %s\n", (long) ord
, name
);
1707 pe_print_pdata (abfd
, vfile
)
1711 FILE *file
= (FILE *) vfile
;
1713 asection
*section
= bfd_get_section_by_name (abfd
, ".pdata");
1714 bfd_size_type datasize
= 0;
1716 bfd_size_type start
, stop
;
1722 stop
= bfd_section_size (abfd
, section
);
1723 if ((stop
% onaline
) != 0)
1724 fprintf (file
, "Warning, .pdata section size (%ld) is not a multiple of %d\n",
1725 (long)stop
, onaline
);
1728 "\nThe Function Table (interpreted .pdata section contents)\n");
1730 " vma:\t\tBegin End EH EH PrologEnd\n");
1732 " \t\tAddress Address Handler Data Address\n");
1734 if (bfd_section_size (abfd
, section
) == 0)
1737 data
= (bfd_byte
*) bfd_malloc ((size_t) bfd_section_size (abfd
, section
));
1738 datasize
= bfd_section_size (abfd
, section
);
1739 if (data
== NULL
&& datasize
!= 0)
1742 bfd_get_section_contents (abfd
,
1745 bfd_section_size (abfd
, section
));
1749 for (i
= start
; i
< stop
; i
+= onaline
)
1755 bfd_vma prolog_end_addr
;
1760 begin_addr
= bfd_get_32(abfd
, data
+i
);
1761 end_addr
= bfd_get_32(abfd
, data
+i
+4);
1762 eh_handler
= bfd_get_32(abfd
, data
+i
+8);
1763 eh_data
= bfd_get_32(abfd
, data
+i
+12);
1764 prolog_end_addr
= bfd_get_32(abfd
, data
+i
+16);
1766 if (begin_addr
== 0 && end_addr
== 0 && eh_handler
== 0
1767 && eh_data
== 0 && prolog_end_addr
== 0)
1769 /* We are probably into the padding of the
1776 (unsigned long int) (i
+ section
->vma
));
1778 fprintf(file
, "%08lx %08lx %08lx %08lx %08lx",
1785 #ifdef POWERPC_LE_PE
1786 if (eh_handler
== 0 && eh_data
!= 0)
1788 /* Special bits here, although the meaning may */
1789 /* be a little mysterious. The only one I know */
1790 /* for sure is 0x03. */
1791 /* Code Significance */
1793 /* 0x01 Register Save Millicode */
1794 /* 0x02 Register Restore Millicode */
1795 /* 0x03 Glue Code Sequence */
1799 fprintf(file
, " Register save millicode");
1802 fprintf(file
, " Register restore millicode");
1805 fprintf(file
, " Glue code sequence");
1812 fprintf(file
, "\n");
1820 static const char *tbl
[6] =
1831 pe_print_reloc (abfd
, vfile
)
1835 FILE *file
= (FILE *) vfile
;
1837 asection
*section
= bfd_get_section_by_name (abfd
, ".reloc");
1838 bfd_size_type datasize
= 0;
1840 bfd_size_type start
, stop
;
1845 if (bfd_section_size (abfd
, section
) == 0)
1849 "\n\nPE File Base Relocations (interpreted .reloc section contents)\n");
1851 data
= (bfd_byte
*) bfd_malloc ((size_t) bfd_section_size (abfd
, section
));
1852 datasize
= bfd_section_size (abfd
, section
);
1853 if (data
== NULL
&& datasize
!= 0)
1856 bfd_get_section_contents (abfd
,
1859 bfd_section_size (abfd
, section
));
1863 stop
= bfd_section_size (abfd
, section
);
1865 for (i
= start
; i
< stop
;)
1868 bfd_vma virtual_address
;
1871 /* The .reloc section is a sequence of blocks, with a header consisting
1872 of two 32 bit quantities, followed by a number of 16 bit entries */
1874 virtual_address
= bfd_get_32(abfd
, data
+i
);
1875 size
= bfd_get_32(abfd
, data
+i
+4);
1876 number
= (size
- 8) / 2;
1884 "\nVirtual Address: %08lx Chunk size %ld (0x%lx) Number of fixups %ld\n",
1885 virtual_address
, size
, size
, number
);
1887 for (j
= 0; j
< number
; ++j
)
1889 unsigned short e
= bfd_get_16(abfd
, data
+ i
+ 8 + j
*2);
1890 int t
= (e
& 0xF000) >> 12;
1891 int off
= e
& 0x0FFF;
1897 "\treloc %4d offset %4x [%4lx] %s\n",
1898 j
, off
, (long) (off
+ virtual_address
), tbl
[t
]);
1910 pe_print_private_bfd_data (abfd
, vfile
)
1914 FILE *file
= (FILE *) vfile
;
1916 pe_data_type
*pe
= pe_data (abfd
);
1917 struct internal_extra_pe_aouthdr
*i
= &pe
->pe_opthdr
;
1919 /* The MS dumpbin program reportedly ands with 0xff0f before
1920 printing the characteristics field. Not sure why. No reason to
1922 fprintf (file
, "\nCharacteristics 0x%x\n", pe
->real_flags
);
1924 #define PF(x, y) if (pe->real_flags & x) { fprintf (file, "\t%s\n", y); }
1925 PF (F_RELFLG
, "relocations stripped");
1926 PF (F_EXEC
, "executable");
1927 PF (F_LNNO
, "line numbers stripped");
1928 PF (F_LSYMS
, "symbols stripped");
1929 PF (0x80, "little endian");
1930 PF (F_AR32WR
, "32 bit words");
1931 PF (0x200, "debugging information removed");
1932 PF (0x1000, "system file");
1934 PF (0x8000, "big endian");
1937 fprintf (file
,"\nImageBase\t\t");
1938 fprintf_vma (file
, i
->ImageBase
);
1939 fprintf (file
,"\nSectionAlignment\t");
1940 fprintf_vma (file
, i
->SectionAlignment
);
1941 fprintf (file
,"\nFileAlignment\t\t");
1942 fprintf_vma (file
, i
->FileAlignment
);
1943 fprintf (file
,"\nMajorOSystemVersion\t%d\n", i
->MajorOperatingSystemVersion
);
1944 fprintf (file
,"MinorOSystemVersion\t%d\n", i
->MinorOperatingSystemVersion
);
1945 fprintf (file
,"MajorImageVersion\t%d\n", i
->MajorImageVersion
);
1946 fprintf (file
,"MinorImageVersion\t%d\n", i
->MinorImageVersion
);
1947 fprintf (file
,"MajorSubsystemVersion\t%d\n", i
->MajorSubsystemVersion
);
1948 fprintf (file
,"MinorSubsystemVersion\t%d\n", i
->MinorSubsystemVersion
);
1949 fprintf (file
,"Reserved1\t\t%08lx\n", i
->Reserved1
);
1950 fprintf (file
,"SizeOfImage\t\t%08lx\n", i
->SizeOfImage
);
1951 fprintf (file
,"SizeOfHeaders\t\t%08lx\n", i
->SizeOfHeaders
);
1952 fprintf (file
,"CheckSum\t\t%08lx\n", i
->CheckSum
);
1953 fprintf (file
,"Subsystem\t\t%08x\n", i
->Subsystem
);
1954 fprintf (file
,"DllCharacteristics\t%08x\n", i
->DllCharacteristics
);
1955 fprintf (file
,"SizeOfStackReserve\t");
1956 fprintf_vma (file
, i
->SizeOfStackReserve
);
1957 fprintf (file
,"\nSizeOfStackCommit\t");
1958 fprintf_vma (file
, i
->SizeOfStackCommit
);
1959 fprintf (file
,"\nSizeOfHeapReserve\t");
1960 fprintf_vma (file
, i
->SizeOfHeapReserve
);
1961 fprintf (file
,"\nSizeOfHeapCommit\t");
1962 fprintf_vma (file
, i
->SizeOfHeapCommit
);
1963 fprintf (file
,"\nLoaderFlags\t\t%08lx\n", i
->LoaderFlags
);
1964 fprintf (file
,"NumberOfRvaAndSizes\t%08lx\n", i
->NumberOfRvaAndSizes
);
1966 fprintf (file
,"\nThe Data Directory\n");
1967 for (j
= 0; j
< IMAGE_NUMBEROF_DIRECTORY_ENTRIES
; j
++)
1969 fprintf (file
, "Entry %1x ", j
);
1970 fprintf_vma (file
, i
->DataDirectory
[j
].VirtualAddress
);
1971 fprintf (file
, " %08lx ", i
->DataDirectory
[j
].Size
);
1972 fprintf (file
, "%s\n", dir_names
[j
]);
1975 pe_print_idata (abfd
, vfile
);
1976 pe_print_edata (abfd
, vfile
);
1977 pe_print_pdata (abfd
, vfile
);
1978 pe_print_reloc (abfd
, vfile
);
1980 if (pe_saved_coff_bfd_print_private_bfd_data
!= NULL
)
1984 return pe_saved_bfd_print_private_bfd_data (abfd
, vfile
);
1995 abfd
->tdata
.pe_obj_data
=
1996 (struct pe_tdata
*) bfd_zalloc (abfd
, sizeof (pe_data_type
));
1998 if (abfd
->tdata
.pe_obj_data
== 0)
2001 pe
= pe_data (abfd
);
2004 pe
->in_reloc_p
= in_reloc_p
;
2008 /* Create the COFF backend specific information. */
2010 pe_mkobject_hook (abfd
, filehdr
, aouthdr
)
2015 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
2018 if (pe_mkobject (abfd
) == false)
2021 pe
= pe_data (abfd
);
2022 pe
->coff
.sym_filepos
= internal_f
->f_symptr
;
2023 /* These members communicate important constants about the symbol
2024 table to GDB's symbol-reading code. These `constants'
2025 unfortunately vary among coff implementations... */
2026 pe
->coff
.local_n_btmask
= N_BTMASK
;
2027 pe
->coff
.local_n_btshft
= N_BTSHFT
;
2028 pe
->coff
.local_n_tmask
= N_TMASK
;
2029 pe
->coff
.local_n_tshift
= N_TSHIFT
;
2030 pe
->coff
.local_symesz
= SYMESZ
;
2031 pe
->coff
.local_auxesz
= AUXESZ
;
2032 pe
->coff
.local_linesz
= LINESZ
;
2034 obj_raw_syment_count (abfd
) =
2035 obj_conv_table_size (abfd
) =
2036 internal_f
->f_nsyms
;
2038 pe
->real_flags
= internal_f
->f_flags
;
2040 if ((internal_f
->f_flags
& F_DLL
) != 0)
2043 #ifdef COFF_IMAGE_WITH_PE
2045 pe
->pe_opthdr
= ((struct internal_aouthdr
*)aouthdr
)->pe
;
2049 if (! coff_arm_bfd_set_private_flags (abfd
, internal_f
->f_flags
))
2050 coff_data (abfd
) ->flags
= 0;
2058 /* Copy any private info we understand from the input bfd
2059 to the output bfd. */
2061 #ifdef coff_bfd_copy_private_bfd_data
2062 static boolean (* pe_saved_coff_bfd_copy_private_bfd_data
)(bfd
*, bfd
*) = coff_bfd_copy_private_bfd_data
;
2063 #undef coff_bfd_copy_private_bfd_data
2065 static boolean (* pe_saved_coff_bfd_copy_private_bfd_data
)(bfd
*, bfd
*) = NULL
;
2067 #define coff_bfd_copy_private_bfd_data pe_bfd_copy_private_bfd_data
2070 pe_bfd_copy_private_bfd_data (ibfd
, obfd
)
2073 /* One day we may try to grok other private data. */
2074 if (ibfd
->xvec
->flavour
!= bfd_target_coff_flavour
2075 || obfd
->xvec
->flavour
!= bfd_target_coff_flavour
)
2078 pe_data (obfd
)->pe_opthdr
= pe_data (ibfd
)->pe_opthdr
;
2079 pe_data (obfd
)->dll
= pe_data (ibfd
)->dll
;
2081 if (pe_saved_coff_bfd_copy_private_bfd_data
)
2082 return pe_saved_coff_bfd_copy_private_bfd_data (ibfd
, obfd
);
2087 #ifdef COFF_IMAGE_WITH_PE
2089 /* Copy private section data. */
2091 #define coff_bfd_copy_private_section_data pe_bfd_copy_private_section_data
2093 static boolean pe_bfd_copy_private_section_data
2094 PARAMS ((bfd
*, asection
*, bfd
*, asection
*));
2097 pe_bfd_copy_private_section_data (ibfd
, isec
, obfd
, osec
)
2103 if (bfd_get_flavour (ibfd
) != bfd_target_coff_flavour
2104 || bfd_get_flavour (obfd
) != bfd_target_coff_flavour
)
2107 if (coff_section_data (ibfd
, isec
) != NULL
2108 && pei_section_data (ibfd
, isec
) != NULL
)
2110 if (coff_section_data (obfd
, osec
) == NULL
)
2113 (PTR
) bfd_zalloc (obfd
, sizeof (struct coff_section_tdata
));
2114 if (osec
->used_by_bfd
== NULL
)
2117 if (pei_section_data (obfd
, osec
) == NULL
)
2119 coff_section_data (obfd
, osec
)->tdata
=
2120 (PTR
) bfd_zalloc (obfd
, sizeof (struct pei_section_tdata
));
2121 if (coff_section_data (obfd
, osec
)->tdata
== NULL
)
2124 pei_section_data (obfd
, osec
)->virt_size
=
2125 pei_section_data (ibfd
, isec
)->virt_size
;