1 /* Support for the generic parts of PE/PEI; the common executable parts.
2 Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
4 Written by Cygnus Solutions.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 /* Most of this hacked by Steve Chamberlain <sac@cygnus.com>.
24 PE/PEI rearrangement (and code added): Donn Terry
28 /* Hey look, some documentation [and in a place you expect to find it]!
30 The main reference for the pei format is "Microsoft Portable Executable
31 and Common Object File Format Specification 4.1". Get it if you need to
32 do some serious hacking on this code.
35 "Peering Inside the PE: A Tour of the Win32 Portable Executable
36 File Format", MSJ 1994, Volume 9.
38 The *sole* difference between the pe format and the pei format is that the
39 latter has an MSDOS 2.0 .exe header on the front that prints the message
40 "This app must be run under Windows." (or some such).
41 (FIXME: Whether that statement is *really* true or not is unknown.
42 Are there more subtle differences between pe and pei formats?
43 For now assume there aren't. If you find one, then for God sakes
46 The Microsoft docs use the word "image" instead of "executable" because
47 the former can also refer to a DLL (shared library). Confusion can arise
48 because the `i' in `pei' also refers to "image". The `pe' format can
49 also create images (i.e. executables), it's just that to run on a win32
50 system you need to use the pei format.
52 FIXME: Please add more docs here so the next poor fool that has to hack
53 on this code has a chance of getting something accomplished without
54 wasting too much time.
57 /* This expands into COFF_WITH_pe or COFF_WITH_pep depending on whether
58 we're compiling for straight PE or PE+. */
64 #include "coff/internal.h"
66 /* NOTE: it's strange to be including an architecture specific header
67 in what's supposed to be general (to PE/PEI) code. However, that's
68 where the definitions are, and they don't vary per architecture
69 within PE/PEI, so we get them from there. FIXME: The lack of
70 variance is an assumption which may prove to be incorrect if new
71 PE/PEI targets are created. */
73 # include "coff/ia64.h"
75 # include "coff/i386.h"
84 # define AOUTSZ PEPAOUTSZ
85 # define PEAOUTHDR PEPAOUTHDR
88 /* FIXME: This file has various tests of POWERPC_LE_PE. Those tests
89 worked when the code was in peicode.h, but no longer work now that
90 the code is in peigen.c. PowerPC NT is said to be dead. If
91 anybody wants to revive the code, you will have to figure out how
92 to handle those issues. */
94 static void add_data_entry
95 PARAMS ((bfd
*, struct internal_extra_pe_aouthdr
*, int, char *, bfd_vma
));
96 static boolean pe_print_pdata
PARAMS ((bfd
*, PTR
));
97 static boolean pe_print_reloc
PARAMS ((bfd
*, PTR
));
98 static boolean pe_print_idata
PARAMS ((bfd
*, PTR
));
99 static boolean pe_print_edata
PARAMS ((bfd
*, PTR
));
103 _bfd_XXi_swap_sym_in (abfd
, ext1
, in1
)
108 SYMENT
*ext
= (SYMENT
*) ext1
;
109 struct internal_syment
*in
= (struct internal_syment
*) in1
;
111 if (ext
->e
.e_name
[0] == 0)
113 in
->_n
._n_n
._n_zeroes
= 0;
114 in
->_n
._n_n
._n_offset
=
115 bfd_h_get_32 (abfd
, (bfd_byte
*) ext
->e
.e
.e_offset
);
118 memcpy (in
->_n
._n_name
, ext
->e
.e_name
, SYMNMLEN
);
120 in
->n_value
= bfd_h_get_32 (abfd
, (bfd_byte
*) ext
->e_value
);
121 in
->n_scnum
= bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->e_scnum
);
123 if (sizeof (ext
->e_type
) == 2)
124 in
->n_type
= bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->e_type
);
126 in
->n_type
= bfd_h_get_32 (abfd
, (bfd_byte
*) ext
->e_type
);
128 in
->n_sclass
= bfd_h_get_8 (abfd
, ext
->e_sclass
);
129 in
->n_numaux
= bfd_h_get_8 (abfd
, ext
->e_numaux
);
131 #ifndef STRICT_PE_FORMAT
132 /* This is for Gnu-created DLLs. */
134 /* The section symbols for the .idata$ sections have class 0x68
135 (C_SECTION), which MS documentation indicates is a section
136 symbol. Unfortunately, the value field in the symbol is simply a
137 copy of the .idata section's flags rather than something useful.
138 When these symbols are encountered, change the value to 0 so that
139 they will be handled somewhat correctly in the bfd code. */
140 if (in
->n_sclass
== C_SECTION
)
145 /* FIXME: This is clearly wrong. The problem seems to be that
146 undefined C_SECTION symbols appear in the first object of a
147 MS generated .lib file, and the symbols are not defined
151 /* I have tried setting the class to 3 and using the following
152 to set the section number. This will put the address of the
153 pointer to the string kernel32.dll at addresses 0 and 0x10
154 off start of idata section which is not correct. */
156 if (strcmp (in
->_n
._n_name
, ".idata$4") == 0)
162 /* Create synthetic empty sections as needed. DJ */
163 if (in
->n_scnum
== 0)
167 for (sec
= abfd
->sections
; sec
; sec
= sec
->next
)
169 if (strcmp (sec
->name
, in
->n_name
) == 0)
171 in
->n_scnum
= sec
->target_index
;
177 if (in
->n_scnum
== 0)
179 int unused_section_number
= 0;
183 for (sec
= abfd
->sections
; sec
; sec
= sec
->next
)
184 if (unused_section_number
<= sec
->target_index
)
185 unused_section_number
= sec
->target_index
+ 1;
187 name
= bfd_alloc (abfd
, strlen (in
->n_name
) + 10);
190 strcpy (name
, in
->n_name
);
191 sec
= bfd_make_section_anyway (abfd
, name
);
195 sec
->_cooked_size
= 0;
198 sec
->rel_filepos
= 0;
199 sec
->reloc_count
= 0;
200 sec
->line_filepos
= 0;
201 sec
->lineno_count
= 0;
202 sec
->userdata
= NULL
;
203 sec
->next
= (asection
*) NULL
;
205 sec
->alignment_power
= 2;
206 sec
->flags
= SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_DATA
| SEC_LOAD
;
208 sec
->target_index
= unused_section_number
;
210 in
->n_scnum
= unused_section_number
;
212 in
->n_sclass
= C_STAT
;
217 #ifdef coff_swap_sym_in_hook
218 /* This won't work in peigen.c, but since it's for PPC PE, it's not
220 coff_swap_sym_in_hook (abfd
, ext1
, in1
);
225 _bfd_XXi_swap_sym_out (abfd
, inp
, extp
)
230 struct internal_syment
*in
= (struct internal_syment
*) inp
;
231 SYMENT
*ext
= (SYMENT
*) extp
;
233 if (in
->_n
._n_name
[0] == 0)
235 bfd_h_put_32 (abfd
, 0, (bfd_byte
*) ext
->e
.e
.e_zeroes
);
236 bfd_h_put_32 (abfd
, in
->_n
._n_n
._n_offset
, (bfd_byte
*) ext
->e
.e
.e_offset
);
239 memcpy (ext
->e
.e_name
, in
->_n
._n_name
, SYMNMLEN
);
241 bfd_h_put_32 (abfd
, in
->n_value
, (bfd_byte
*) ext
->e_value
);
242 bfd_h_put_16 (abfd
, in
->n_scnum
, (bfd_byte
*) ext
->e_scnum
);
244 if (sizeof (ext
->e_type
) == 2)
245 bfd_h_put_16 (abfd
, in
->n_type
, (bfd_byte
*) ext
->e_type
);
247 bfd_h_put_32 (abfd
, in
->n_type
, (bfd_byte
*) ext
->e_type
);
249 bfd_h_put_8 (abfd
, in
->n_sclass
, ext
->e_sclass
);
250 bfd_h_put_8 (abfd
, in
->n_numaux
, ext
->e_numaux
);
256 _bfd_XXi_swap_aux_in (abfd
, ext1
, type
, class, indx
, numaux
, in1
)
261 int indx ATTRIBUTE_UNUSED
;
262 int numaux ATTRIBUTE_UNUSED
;
265 AUXENT
*ext
= (AUXENT
*) ext1
;
266 union internal_auxent
*in
= (union internal_auxent
*) in1
;
271 if (ext
->x_file
.x_fname
[0] == 0)
273 in
->x_file
.x_n
.x_zeroes
= 0;
274 in
->x_file
.x_n
.x_offset
=
275 bfd_h_get_32 (abfd
, (bfd_byte
*) ext
->x_file
.x_n
.x_offset
);
278 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_fname
, FILNMLEN
);
286 in
->x_scn
.x_scnlen
= GET_SCN_SCNLEN (abfd
, ext
);
287 in
->x_scn
.x_nreloc
= GET_SCN_NRELOC (abfd
, ext
);
288 in
->x_scn
.x_nlinno
= GET_SCN_NLINNO (abfd
, ext
);
289 in
->x_scn
.x_checksum
=
290 bfd_h_get_32 (abfd
, (bfd_byte
*) ext
->x_scn
.x_checksum
);
291 in
->x_scn
.x_associated
=
292 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_scn
.x_associated
);
294 bfd_h_get_8 (abfd
, (bfd_byte
*) ext
->x_scn
.x_comdat
);
300 in
->x_sym
.x_tagndx
.l
= bfd_h_get_32 (abfd
, (bfd_byte
*) ext
->x_sym
.x_tagndx
);
301 in
->x_sym
.x_tvndx
= bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_tvndx
);
303 if (class == C_BLOCK
|| class == C_FCN
|| ISFCN (type
) || ISTAG (class))
305 in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
= GET_FCN_LNNOPTR (abfd
, ext
);
306 in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
= GET_FCN_ENDNDX (abfd
, ext
);
310 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0] =
311 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
312 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1] =
313 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
314 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2] =
315 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
316 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3] =
317 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
322 in
->x_sym
.x_misc
.x_fsize
=
323 bfd_h_get_32 (abfd
, (bfd_byte
*) ext
->x_sym
.x_misc
.x_fsize
);
327 in
->x_sym
.x_misc
.x_lnsz
.x_lnno
= GET_LNSZ_LNNO (abfd
, ext
);
328 in
->x_sym
.x_misc
.x_lnsz
.x_size
= GET_LNSZ_SIZE (abfd
, ext
);
333 _bfd_XXi_swap_aux_out (abfd
, inp
, type
, class, indx
, numaux
, extp
)
338 int indx ATTRIBUTE_UNUSED
;
339 int numaux ATTRIBUTE_UNUSED
;
342 union internal_auxent
*in
= (union internal_auxent
*) inp
;
343 AUXENT
*ext
= (AUXENT
*) extp
;
345 memset ((PTR
) ext
, 0, AUXESZ
);
349 if (in
->x_file
.x_fname
[0] == 0)
351 bfd_h_put_32 (abfd
, 0, (bfd_byte
*) ext
->x_file
.x_n
.x_zeroes
);
353 in
->x_file
.x_n
.x_offset
,
354 (bfd_byte
*) ext
->x_file
.x_n
.x_offset
);
357 memcpy (ext
->x_file
.x_fname
, in
->x_file
.x_fname
, FILNMLEN
);
366 PUT_SCN_SCNLEN (abfd
, in
->x_scn
.x_scnlen
, ext
);
367 PUT_SCN_NRELOC (abfd
, in
->x_scn
.x_nreloc
, ext
);
368 PUT_SCN_NLINNO (abfd
, in
->x_scn
.x_nlinno
, ext
);
369 bfd_h_put_32 (abfd
, in
->x_scn
.x_checksum
,
370 (bfd_byte
*) ext
->x_scn
.x_checksum
);
371 bfd_h_put_16 (abfd
, in
->x_scn
.x_associated
,
372 (bfd_byte
*) ext
->x_scn
.x_associated
);
373 bfd_h_put_8 (abfd
, in
->x_scn
.x_comdat
,
374 (bfd_byte
*) ext
->x_scn
.x_comdat
);
380 bfd_h_put_32 (abfd
, in
->x_sym
.x_tagndx
.l
, (bfd_byte
*) ext
->x_sym
.x_tagndx
);
381 bfd_h_put_16 (abfd
, in
->x_sym
.x_tvndx
, (bfd_byte
*) ext
->x_sym
.x_tvndx
);
383 if (class == C_BLOCK
|| class == C_FCN
|| ISFCN (type
) || ISTAG (class))
385 PUT_FCN_LNNOPTR (abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
, ext
);
386 PUT_FCN_ENDNDX (abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
, ext
);
390 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0],
391 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
392 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1],
393 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
394 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2],
395 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
396 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3],
397 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
401 bfd_h_put_32 (abfd
, in
->x_sym
.x_misc
.x_fsize
,
402 (bfd_byte
*) ext
->x_sym
.x_misc
.x_fsize
);
405 PUT_LNSZ_LNNO (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_lnno
, ext
);
406 PUT_LNSZ_SIZE (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_size
, ext
);
413 _bfd_XXi_swap_lineno_in (abfd
, ext1
, in1
)
418 LINENO
*ext
= (LINENO
*) ext1
;
419 struct internal_lineno
*in
= (struct internal_lineno
*) in1
;
421 in
->l_addr
.l_symndx
= bfd_h_get_32 (abfd
, (bfd_byte
*) ext
->l_addr
.l_symndx
);
422 in
->l_lnno
= GET_LINENO_LNNO (abfd
, ext
);
426 _bfd_XXi_swap_lineno_out (abfd
, inp
, outp
)
431 struct internal_lineno
*in
= (struct internal_lineno
*) inp
;
432 struct external_lineno
*ext
= (struct external_lineno
*) outp
;
433 bfd_h_put_32 (abfd
, in
->l_addr
.l_symndx
, (bfd_byte
*)
434 ext
->l_addr
.l_symndx
);
436 PUT_LINENO_LNNO (abfd
, in
->l_lnno
, ext
);
441 _bfd_XXi_swap_aouthdr_in (abfd
, aouthdr_ext1
, aouthdr_int1
)
446 struct internal_extra_pe_aouthdr
*a
;
447 PEAOUTHDR
*src
= (PEAOUTHDR
*) (aouthdr_ext1
);
448 AOUTHDR
*aouthdr_ext
= (AOUTHDR
*) aouthdr_ext1
;
449 struct internal_aouthdr
*aouthdr_int
= (struct internal_aouthdr
*)aouthdr_int1
;
451 aouthdr_int
->magic
= bfd_h_get_16 (abfd
, (bfd_byte
*) aouthdr_ext
->magic
);
452 aouthdr_int
->vstamp
= bfd_h_get_16 (abfd
, (bfd_byte
*) aouthdr_ext
->vstamp
);
454 GET_AOUTHDR_TSIZE (abfd
, (bfd_byte
*) aouthdr_ext
->tsize
);
456 GET_AOUTHDR_DSIZE (abfd
, (bfd_byte
*) aouthdr_ext
->dsize
);
458 GET_AOUTHDR_BSIZE (abfd
, (bfd_byte
*) aouthdr_ext
->bsize
);
460 GET_AOUTHDR_ENTRY (abfd
, (bfd_byte
*) aouthdr_ext
->entry
);
461 aouthdr_int
->text_start
=
462 GET_AOUTHDR_TEXT_START (abfd
, (bfd_byte
*) aouthdr_ext
->text_start
);
463 #ifndef COFF_WITH_pep
464 /* PE32+ does not have data_start member! */
465 aouthdr_int
->data_start
=
466 GET_AOUTHDR_DATA_START (abfd
, (bfd_byte
*) aouthdr_ext
->data_start
);
469 a
= &aouthdr_int
->pe
;
470 a
->ImageBase
= GET_OPTHDR_IMAGE_BASE (abfd
, (bfd_byte
*) src
->ImageBase
);
471 a
->SectionAlignment
= bfd_h_get_32 (abfd
, (bfd_byte
*) src
->SectionAlignment
);
472 a
->FileAlignment
= bfd_h_get_32 (abfd
, (bfd_byte
*) src
->FileAlignment
);
473 a
->MajorOperatingSystemVersion
=
474 bfd_h_get_16 (abfd
, (bfd_byte
*) src
->MajorOperatingSystemVersion
);
475 a
->MinorOperatingSystemVersion
=
476 bfd_h_get_16 (abfd
, (bfd_byte
*) src
->MinorOperatingSystemVersion
);
477 a
->MajorImageVersion
= bfd_h_get_16 (abfd
, (bfd_byte
*) src
->MajorImageVersion
);
478 a
->MinorImageVersion
= bfd_h_get_16 (abfd
, (bfd_byte
*) src
->MinorImageVersion
);
479 a
->MajorSubsystemVersion
= bfd_h_get_16 (abfd
, (bfd_byte
*) src
->MajorSubsystemVersion
);
480 a
->MinorSubsystemVersion
= bfd_h_get_16 (abfd
, (bfd_byte
*) src
->MinorSubsystemVersion
);
481 a
->Reserved1
= bfd_h_get_32 (abfd
, (bfd_byte
*) src
->Reserved1
);
482 a
->SizeOfImage
= bfd_h_get_32 (abfd
, (bfd_byte
*) src
->SizeOfImage
);
483 a
->SizeOfHeaders
= bfd_h_get_32 (abfd
, (bfd_byte
*) src
->SizeOfHeaders
);
484 a
->CheckSum
= bfd_h_get_32 (abfd
, (bfd_byte
*) src
->CheckSum
);
485 a
->Subsystem
= bfd_h_get_16 (abfd
, (bfd_byte
*) src
->Subsystem
);
486 a
->DllCharacteristics
= bfd_h_get_16 (abfd
, (bfd_byte
*) src
->DllCharacteristics
);
487 a
->SizeOfStackReserve
= GET_OPTHDR_SIZE_OF_STACK_RESERVE (abfd
, (bfd_byte
*) src
->SizeOfStackReserve
);
488 a
->SizeOfStackCommit
= GET_OPTHDR_SIZE_OF_STACK_COMMIT (abfd
, (bfd_byte
*) src
->SizeOfStackCommit
);
489 a
->SizeOfHeapReserve
= GET_OPTHDR_SIZE_OF_HEAP_RESERVE (abfd
, (bfd_byte
*) src
->SizeOfHeapReserve
);
490 a
->SizeOfHeapCommit
= GET_OPTHDR_SIZE_OF_HEAP_COMMIT (abfd
, (bfd_byte
*) src
->SizeOfHeapCommit
);
491 a
->LoaderFlags
= bfd_h_get_32 (abfd
, (bfd_byte
*) src
->LoaderFlags
);
492 a
->NumberOfRvaAndSizes
= bfd_h_get_32 (abfd
, (bfd_byte
*) src
->NumberOfRvaAndSizes
);
497 for (idx
= 0; idx
< 16; idx
++)
499 /* If data directory is empty, rva also should be 0. */
501 bfd_h_get_32 (abfd
, (bfd_byte
*) src
->DataDirectory
[idx
][1]);
502 a
->DataDirectory
[idx
].Size
= size
;
505 a
->DataDirectory
[idx
].VirtualAddress
=
506 bfd_h_get_32 (abfd
, (bfd_byte
*) src
->DataDirectory
[idx
][0]);
508 a
->DataDirectory
[idx
].VirtualAddress
= 0;
512 if (aouthdr_int
->entry
)
514 aouthdr_int
->entry
+= a
->ImageBase
;
515 #ifndef COFF_WITH_pep
516 aouthdr_int
->entry
&= 0xffffffff;
520 if (aouthdr_int
->tsize
)
522 aouthdr_int
->text_start
+= a
->ImageBase
;
523 #ifndef COFF_WITH_pep
524 aouthdr_int
->text_start
&= 0xffffffff;
528 #ifndef COFF_WITH_pep
529 /* PE32+ does not have data_start member! */
530 if (aouthdr_int
->dsize
)
532 aouthdr_int
->data_start
+= a
->ImageBase
;
533 aouthdr_int
->data_start
&= 0xffffffff;
538 /* These three fields are normally set up by ppc_relocate_section.
539 In the case of reading a file in, we can pick them up from the
541 first_thunk_address
= a
->DataDirectory
[12].VirtualAddress
;
542 thunk_size
= a
->DataDirectory
[12].Size
;
543 import_table_size
= a
->DataDirectory
[1].Size
;
547 /* A support function for below. */
550 add_data_entry (abfd
, aout
, idx
, name
, base
)
552 struct internal_extra_pe_aouthdr
*aout
;
557 asection
*sec
= bfd_get_section_by_name (abfd
, name
);
559 /* Add import directory information if it exists. */
561 && (coff_section_data (abfd
, sec
) != NULL
)
562 && (pei_section_data (abfd
, sec
) != NULL
))
564 /* If data directory is empty, rva also should be 0. */
565 int size
= pei_section_data (abfd
, sec
)->virt_size
;
566 aout
->DataDirectory
[idx
].Size
= size
;
570 aout
->DataDirectory
[idx
].VirtualAddress
=
571 (sec
->vma
- base
) & 0xffffffff;
572 sec
->flags
|= SEC_DATA
;
578 _bfd_XXi_swap_aouthdr_out (abfd
, in
, out
)
583 struct internal_aouthdr
*aouthdr_in
= (struct internal_aouthdr
*) in
;
584 pe_data_type
*pe
= pe_data (abfd
);
585 struct internal_extra_pe_aouthdr
*extra
= &pe
->pe_opthdr
;
586 PEAOUTHDR
*aouthdr_out
= (PEAOUTHDR
*) out
;
589 if (pe
->force_minimum_alignment
)
591 if (!extra
->FileAlignment
)
592 extra
->FileAlignment
= PE_DEF_FILE_ALIGNMENT
;
593 if (!extra
->SectionAlignment
)
594 extra
->SectionAlignment
= PE_DEF_SECTION_ALIGNMENT
;
597 if (extra
->Subsystem
== IMAGE_SUBSYSTEM_UNKNOWN
)
598 extra
->Subsystem
= pe
->target_subsystem
;
600 sa
= extra
->SectionAlignment
;
601 fa
= extra
->FileAlignment
;
602 ib
= extra
->ImageBase
;
604 if (aouthdr_in
->tsize
)
606 aouthdr_in
->text_start
-= ib
;
607 #ifndef COFF_WITH_pep
608 aouthdr_in
->text_start
&= 0xffffffff;
612 if (aouthdr_in
->dsize
)
614 aouthdr_in
->data_start
-= ib
;
615 #ifndef COFF_WITH_pep
616 aouthdr_in
->data_start
&= 0xffffffff;
620 if (aouthdr_in
->entry
)
622 aouthdr_in
->entry
-= ib
;
623 #ifndef COFF_WITH_pep
624 aouthdr_in
->entry
&= 0xffffffff;
628 #define FA(x) (((x) + fa -1 ) & (- fa))
629 #define SA(x) (((x) + sa -1 ) & (- sa))
631 /* We like to have the sizes aligned. */
633 aouthdr_in
->bsize
= FA (aouthdr_in
->bsize
);
635 extra
->NumberOfRvaAndSizes
= IMAGE_NUMBEROF_DIRECTORY_ENTRIES
;
637 /* first null out all data directory entries .. */
638 memset (extra
->DataDirectory
, sizeof (extra
->DataDirectory
), 0);
640 add_data_entry (abfd
, extra
, 0, ".edata", ib
);
642 /* Don't call add_data_entry for .idata$2 or .idata$5. It's done in
643 bfd_coff_final_link where all the required information is
646 /* However, until other .idata fixes are made (pending patch), the
647 entry for .idata is needed for backwards compatability. FIXME. */
648 add_data_entry (abfd
, extra
, 1, ".idata", ib
);
650 add_data_entry (abfd
, extra
, 2, ".rsrc", ib
);
652 add_data_entry (abfd
, extra
, 3, ".pdata", ib
);
654 /* For some reason, the virtual size (which is what's set by
655 add_data_entry) for .reloc is not the same as the size recorded
656 in this slot by MSVC; it doesn't seem to cause problems (so far),
657 but since it's the best we've got, use it. It does do the right
659 if (pe
->has_reloc_section
)
660 add_data_entry (abfd
, extra
, 5, ".reloc", ib
);
665 bfd_vma isize
= SA(abfd
->sections
->filepos
);
668 for (sec
= abfd
->sections
; sec
; sec
= sec
->next
)
670 int rounded
= FA(sec
->_raw_size
);
672 if (sec
->flags
& SEC_DATA
)
674 if (sec
->flags
& SEC_CODE
)
676 /* The image size is the total VIRTUAL size (which is what is
677 in the virt_size field). Files have been seen (from MSVC
678 5.0 link.exe) where the file size of the .data segment is
679 quite small compared to the virtual size. Without this
680 fix, strip munges the file. */
681 isize
+= SA (FA (pei_section_data (abfd
, sec
)->virt_size
));
684 aouthdr_in
->dsize
= dsize
;
685 aouthdr_in
->tsize
= tsize
;
686 extra
->SizeOfImage
= isize
;
689 extra
->SizeOfHeaders
= abfd
->sections
->filepos
;
690 bfd_h_put_16 (abfd
, aouthdr_in
->magic
, (bfd_byte
*) aouthdr_out
->standard
.magic
);
692 #define LINKER_VERSION 256 /* That is, 2.56 */
694 /* This piece of magic sets the "linker version" field to
697 LINKER_VERSION
/ 100 + (LINKER_VERSION
% 100) * 256,
698 (bfd_byte
*) aouthdr_out
->standard
.vstamp
);
700 PUT_AOUTHDR_TSIZE (abfd
, aouthdr_in
->tsize
, (bfd_byte
*) aouthdr_out
->standard
.tsize
);
701 PUT_AOUTHDR_DSIZE (abfd
, aouthdr_in
->dsize
, (bfd_byte
*) aouthdr_out
->standard
.dsize
);
702 PUT_AOUTHDR_BSIZE (abfd
, aouthdr_in
->bsize
, (bfd_byte
*) aouthdr_out
->standard
.bsize
);
703 PUT_AOUTHDR_ENTRY (abfd
, aouthdr_in
->entry
, (bfd_byte
*) aouthdr_out
->standard
.entry
);
704 PUT_AOUTHDR_TEXT_START (abfd
, aouthdr_in
->text_start
,
705 (bfd_byte
*) aouthdr_out
->standard
.text_start
);
707 #ifndef COFF_WITH_pep
708 /* PE32+ does not have data_start member! */
709 PUT_AOUTHDR_DATA_START (abfd
, aouthdr_in
->data_start
,
710 (bfd_byte
*) aouthdr_out
->standard
.data_start
);
713 PUT_OPTHDR_IMAGE_BASE (abfd
, extra
->ImageBase
,
714 (bfd_byte
*) aouthdr_out
->ImageBase
);
715 bfd_h_put_32 (abfd
, extra
->SectionAlignment
,
716 (bfd_byte
*) aouthdr_out
->SectionAlignment
);
717 bfd_h_put_32 (abfd
, extra
->FileAlignment
,
718 (bfd_byte
*) aouthdr_out
->FileAlignment
);
719 bfd_h_put_16 (abfd
, extra
->MajorOperatingSystemVersion
,
720 (bfd_byte
*) aouthdr_out
->MajorOperatingSystemVersion
);
721 bfd_h_put_16 (abfd
, extra
->MinorOperatingSystemVersion
,
722 (bfd_byte
*) aouthdr_out
->MinorOperatingSystemVersion
);
723 bfd_h_put_16 (abfd
, extra
->MajorImageVersion
,
724 (bfd_byte
*) aouthdr_out
->MajorImageVersion
);
725 bfd_h_put_16 (abfd
, extra
->MinorImageVersion
,
726 (bfd_byte
*) aouthdr_out
->MinorImageVersion
);
727 bfd_h_put_16 (abfd
, extra
->MajorSubsystemVersion
,
728 (bfd_byte
*) aouthdr_out
->MajorSubsystemVersion
);
729 bfd_h_put_16 (abfd
, extra
->MinorSubsystemVersion
,
730 (bfd_byte
*) aouthdr_out
->MinorSubsystemVersion
);
731 bfd_h_put_32 (abfd
, extra
->Reserved1
,
732 (bfd_byte
*) aouthdr_out
->Reserved1
);
733 bfd_h_put_32 (abfd
, extra
->SizeOfImage
,
734 (bfd_byte
*) aouthdr_out
->SizeOfImage
);
735 bfd_h_put_32 (abfd
, extra
->SizeOfHeaders
,
736 (bfd_byte
*) aouthdr_out
->SizeOfHeaders
);
737 bfd_h_put_32 (abfd
, extra
->CheckSum
,
738 (bfd_byte
*) aouthdr_out
->CheckSum
);
739 bfd_h_put_16 (abfd
, extra
->Subsystem
,
740 (bfd_byte
*) aouthdr_out
->Subsystem
);
741 bfd_h_put_16 (abfd
, extra
->DllCharacteristics
,
742 (bfd_byte
*) aouthdr_out
->DllCharacteristics
);
743 PUT_OPTHDR_SIZE_OF_STACK_RESERVE (abfd
, extra
->SizeOfStackReserve
,
744 (bfd_byte
*) aouthdr_out
->SizeOfStackReserve
);
745 PUT_OPTHDR_SIZE_OF_STACK_COMMIT (abfd
, extra
->SizeOfStackCommit
,
746 (bfd_byte
*) aouthdr_out
->SizeOfStackCommit
);
747 PUT_OPTHDR_SIZE_OF_HEAP_RESERVE (abfd
, extra
->SizeOfHeapReserve
,
748 (bfd_byte
*) aouthdr_out
->SizeOfHeapReserve
);
749 PUT_OPTHDR_SIZE_OF_HEAP_COMMIT (abfd
, extra
->SizeOfHeapCommit
,
750 (bfd_byte
*) aouthdr_out
->SizeOfHeapCommit
);
751 bfd_h_put_32 (abfd
, extra
->LoaderFlags
,
752 (bfd_byte
*) aouthdr_out
->LoaderFlags
);
753 bfd_h_put_32 (abfd
, extra
->NumberOfRvaAndSizes
,
754 (bfd_byte
*) aouthdr_out
->NumberOfRvaAndSizes
);
758 for (idx
= 0; idx
< 16; idx
++)
760 bfd_h_put_32 (abfd
, extra
->DataDirectory
[idx
].VirtualAddress
,
761 (bfd_byte
*) aouthdr_out
->DataDirectory
[idx
][0]);
762 bfd_h_put_32 (abfd
, extra
->DataDirectory
[idx
].Size
,
763 (bfd_byte
*) aouthdr_out
->DataDirectory
[idx
][1]);
771 _bfd_XXi_only_swap_filehdr_out (abfd
, in
, out
)
777 struct internal_filehdr
*filehdr_in
= (struct internal_filehdr
*) in
;
778 struct external_PEI_filehdr
*filehdr_out
= (struct external_PEI_filehdr
*) out
;
780 if (pe_data (abfd
)->has_reloc_section
)
781 filehdr_in
->f_flags
&= ~F_RELFLG
;
783 if (pe_data (abfd
)->dll
)
784 filehdr_in
->f_flags
|= F_DLL
;
786 filehdr_in
->pe
.e_magic
= DOSMAGIC
;
787 filehdr_in
->pe
.e_cblp
= 0x90;
788 filehdr_in
->pe
.e_cp
= 0x3;
789 filehdr_in
->pe
.e_crlc
= 0x0;
790 filehdr_in
->pe
.e_cparhdr
= 0x4;
791 filehdr_in
->pe
.e_minalloc
= 0x0;
792 filehdr_in
->pe
.e_maxalloc
= 0xffff;
793 filehdr_in
->pe
.e_ss
= 0x0;
794 filehdr_in
->pe
.e_sp
= 0xb8;
795 filehdr_in
->pe
.e_csum
= 0x0;
796 filehdr_in
->pe
.e_ip
= 0x0;
797 filehdr_in
->pe
.e_cs
= 0x0;
798 filehdr_in
->pe
.e_lfarlc
= 0x40;
799 filehdr_in
->pe
.e_ovno
= 0x0;
801 for (idx
= 0; idx
< 4; idx
++)
802 filehdr_in
->pe
.e_res
[idx
] = 0x0;
804 filehdr_in
->pe
.e_oemid
= 0x0;
805 filehdr_in
->pe
.e_oeminfo
= 0x0;
807 for (idx
= 0; idx
< 10; idx
++)
808 filehdr_in
->pe
.e_res2
[idx
] = 0x0;
810 filehdr_in
->pe
.e_lfanew
= 0x80;
812 /* This next collection of data are mostly just characters. It
813 appears to be constant within the headers put on NT exes. */
814 filehdr_in
->pe
.dos_message
[0] = 0x0eba1f0e;
815 filehdr_in
->pe
.dos_message
[1] = 0xcd09b400;
816 filehdr_in
->pe
.dos_message
[2] = 0x4c01b821;
817 filehdr_in
->pe
.dos_message
[3] = 0x685421cd;
818 filehdr_in
->pe
.dos_message
[4] = 0x70207369;
819 filehdr_in
->pe
.dos_message
[5] = 0x72676f72;
820 filehdr_in
->pe
.dos_message
[6] = 0x63206d61;
821 filehdr_in
->pe
.dos_message
[7] = 0x6f6e6e61;
822 filehdr_in
->pe
.dos_message
[8] = 0x65622074;
823 filehdr_in
->pe
.dos_message
[9] = 0x6e757220;
824 filehdr_in
->pe
.dos_message
[10] = 0x206e6920;
825 filehdr_in
->pe
.dos_message
[11] = 0x20534f44;
826 filehdr_in
->pe
.dos_message
[12] = 0x65646f6d;
827 filehdr_in
->pe
.dos_message
[13] = 0x0a0d0d2e;
828 filehdr_in
->pe
.dos_message
[14] = 0x24;
829 filehdr_in
->pe
.dos_message
[15] = 0x0;
830 filehdr_in
->pe
.nt_signature
= NT_SIGNATURE
;
832 bfd_h_put_16 (abfd
, filehdr_in
->f_magic
, (bfd_byte
*) filehdr_out
->f_magic
);
833 bfd_h_put_16 (abfd
, filehdr_in
->f_nscns
, (bfd_byte
*) filehdr_out
->f_nscns
);
835 bfd_h_put_32 (abfd
, time (0), (bfd_byte
*) filehdr_out
->f_timdat
);
836 PUT_FILEHDR_SYMPTR (abfd
, (bfd_vma
) filehdr_in
->f_symptr
,
837 (bfd_byte
*) filehdr_out
->f_symptr
);
838 bfd_h_put_32 (abfd
, filehdr_in
->f_nsyms
, (bfd_byte
*) filehdr_out
->f_nsyms
);
839 bfd_h_put_16 (abfd
, filehdr_in
->f_opthdr
, (bfd_byte
*) filehdr_out
->f_opthdr
);
840 bfd_h_put_16 (abfd
, filehdr_in
->f_flags
, (bfd_byte
*) filehdr_out
->f_flags
);
842 /* Put in extra dos header stuff. This data remains essentially
843 constant, it just has to be tacked on to the beginning of all exes
845 bfd_h_put_16 (abfd
, filehdr_in
->pe
.e_magic
, (bfd_byte
*) filehdr_out
->e_magic
);
846 bfd_h_put_16 (abfd
, filehdr_in
->pe
.e_cblp
, (bfd_byte
*) filehdr_out
->e_cblp
);
847 bfd_h_put_16 (abfd
, filehdr_in
->pe
.e_cp
, (bfd_byte
*) filehdr_out
->e_cp
);
848 bfd_h_put_16 (abfd
, filehdr_in
->pe
.e_crlc
, (bfd_byte
*) filehdr_out
->e_crlc
);
849 bfd_h_put_16 (abfd
, filehdr_in
->pe
.e_cparhdr
,
850 (bfd_byte
*) filehdr_out
->e_cparhdr
);
851 bfd_h_put_16 (abfd
, filehdr_in
->pe
.e_minalloc
,
852 (bfd_byte
*) filehdr_out
->e_minalloc
);
853 bfd_h_put_16 (abfd
, filehdr_in
->pe
.e_maxalloc
,
854 (bfd_byte
*) filehdr_out
->e_maxalloc
);
855 bfd_h_put_16 (abfd
, filehdr_in
->pe
.e_ss
, (bfd_byte
*) filehdr_out
->e_ss
);
856 bfd_h_put_16 (abfd
, filehdr_in
->pe
.e_sp
, (bfd_byte
*) filehdr_out
->e_sp
);
857 bfd_h_put_16 (abfd
, filehdr_in
->pe
.e_csum
, (bfd_byte
*) filehdr_out
->e_csum
);
858 bfd_h_put_16 (abfd
, filehdr_in
->pe
.e_ip
, (bfd_byte
*) filehdr_out
->e_ip
);
859 bfd_h_put_16 (abfd
, filehdr_in
->pe
.e_cs
, (bfd_byte
*) filehdr_out
->e_cs
);
860 bfd_h_put_16 (abfd
, filehdr_in
->pe
.e_lfarlc
, (bfd_byte
*) filehdr_out
->e_lfarlc
);
861 bfd_h_put_16 (abfd
, filehdr_in
->pe
.e_ovno
, (bfd_byte
*) filehdr_out
->e_ovno
);
863 for (idx
= 0; idx
< 4; idx
++)
864 bfd_h_put_16 (abfd
, filehdr_in
->pe
.e_res
[idx
],
865 (bfd_byte
*) filehdr_out
->e_res
[idx
]);
867 bfd_h_put_16 (abfd
, filehdr_in
->pe
.e_oemid
, (bfd_byte
*) filehdr_out
->e_oemid
);
868 bfd_h_put_16 (abfd
, filehdr_in
->pe
.e_oeminfo
,
869 (bfd_byte
*) filehdr_out
->e_oeminfo
);
871 for (idx
= 0; idx
< 10; idx
++)
872 bfd_h_put_16 (abfd
, filehdr_in
->pe
.e_res2
[idx
],
873 (bfd_byte
*) filehdr_out
->e_res2
[idx
]);
875 bfd_h_put_32 (abfd
, filehdr_in
->pe
.e_lfanew
, (bfd_byte
*) filehdr_out
->e_lfanew
);
877 for (idx
= 0; idx
< 16; idx
++)
878 bfd_h_put_32 (abfd
, filehdr_in
->pe
.dos_message
[idx
],
879 (bfd_byte
*) filehdr_out
->dos_message
[idx
]);
881 /* Also put in the NT signature. */
882 bfd_h_put_32 (abfd
, filehdr_in
->pe
.nt_signature
,
883 (bfd_byte
*) filehdr_out
->nt_signature
);
889 _bfd_XX_only_swap_filehdr_out (abfd
, in
, out
)
894 struct internal_filehdr
*filehdr_in
= (struct internal_filehdr
*) in
;
895 FILHDR
*filehdr_out
= (FILHDR
*) out
;
897 bfd_h_put_16 (abfd
, filehdr_in
->f_magic
, (bfd_byte
*) filehdr_out
->f_magic
);
898 bfd_h_put_16 (abfd
, filehdr_in
->f_nscns
, (bfd_byte
*) filehdr_out
->f_nscns
);
899 bfd_h_put_32 (abfd
, filehdr_in
->f_timdat
, (bfd_byte
*) filehdr_out
->f_timdat
);
900 PUT_FILEHDR_SYMPTR (abfd
, (bfd_vma
) filehdr_in
->f_symptr
,
901 (bfd_byte
*) filehdr_out
->f_symptr
);
902 bfd_h_put_32 (abfd
, filehdr_in
->f_nsyms
, (bfd_byte
*) filehdr_out
->f_nsyms
);
903 bfd_h_put_16 (abfd
, filehdr_in
->f_opthdr
, (bfd_byte
*) filehdr_out
->f_opthdr
);
904 bfd_h_put_16 (abfd
, filehdr_in
->f_flags
, (bfd_byte
*) filehdr_out
->f_flags
);
910 _bfd_XXi_swap_scnhdr_out (abfd
, in
, out
)
915 struct internal_scnhdr
*scnhdr_int
= (struct internal_scnhdr
*) in
;
916 SCNHDR
*scnhdr_ext
= (SCNHDR
*) out
;
917 unsigned int ret
= SCNHSZ
;
921 memcpy (scnhdr_ext
->s_name
, scnhdr_int
->s_name
, sizeof (scnhdr_int
->s_name
));
923 PUT_SCNHDR_VADDR (abfd
,
924 ((scnhdr_int
->s_vaddr
925 - pe_data (abfd
)->pe_opthdr
.ImageBase
)
927 (bfd_byte
*) scnhdr_ext
->s_vaddr
);
929 /* NT wants the size data to be rounded up to the next
930 NT_FILE_ALIGNMENT, but zero if it has no content (as in .bss,
932 if ((scnhdr_int
->s_flags
& IMAGE_SCN_CNT_UNINITIALIZED_DATA
) != 0)
934 ps
= scnhdr_int
->s_size
;
939 ps
= scnhdr_int
->s_paddr
;
940 ss
= scnhdr_int
->s_size
;
943 PUT_SCNHDR_SIZE (abfd
, ss
,
944 (bfd_byte
*) scnhdr_ext
->s_size
);
946 /* s_paddr in PE is really the virtual size. */
947 PUT_SCNHDR_PADDR (abfd
, ps
, (bfd_byte
*) scnhdr_ext
->s_paddr
);
949 PUT_SCNHDR_SCNPTR (abfd
, scnhdr_int
->s_scnptr
,
950 (bfd_byte
*) scnhdr_ext
->s_scnptr
);
951 PUT_SCNHDR_RELPTR (abfd
, scnhdr_int
->s_relptr
,
952 (bfd_byte
*) scnhdr_ext
->s_relptr
);
953 PUT_SCNHDR_LNNOPTR (abfd
, scnhdr_int
->s_lnnoptr
,
954 (bfd_byte
*) scnhdr_ext
->s_lnnoptr
);
956 /* Extra flags must be set when dealing with NT. All sections should also
957 have the IMAGE_SCN_MEM_READ (0x40000000) flag set. In addition, the
958 .text section must have IMAGE_SCN_MEM_EXECUTE (0x20000000) and the data
959 sections (.idata, .data, .bss, .CRT) must have IMAGE_SCN_MEM_WRITE set
960 (this is especially important when dealing with the .idata section since
961 the addresses for routines from .dlls must be overwritten). If .reloc
962 section data is ever generated, we must add IMAGE_SCN_MEM_DISCARDABLE
963 (0x02000000). Also, the resource data should also be read and
966 /* FIXME: alignment is also encoded in this field, at least on ppc (krk) */
967 /* FIXME: even worse, I don't see how to get the original alignment field*/
971 int flags
= scnhdr_int
->s_flags
;
973 bfd_h_put_32 (abfd
, flags
, (bfd_byte
*) scnhdr_ext
->s_flags
);
976 if (coff_data (abfd
)->link_info
977 && ! coff_data (abfd
)->link_info
->relocateable
978 && ! coff_data (abfd
)->link_info
->shared
979 && strcmp (scnhdr_int
->s_name
, ".text") == 0)
981 /* By inference from looking at MS output, the 32 bit field
982 which is the combintion of the number_of_relocs and
983 number_of_linenos is used for the line number count in
984 executables. A 16-bit field won't do for cc1. The MS
985 document says that the number of relocs is zero for
986 executables, but the 17-th bit has been observed to be there.
987 Overflow is not an issue: a 4G-line program will overflow a
988 bunch of other fields long before this! */
989 bfd_h_put_16 (abfd
, scnhdr_int
->s_nlnno
& 0xffff,
990 (bfd_byte
*) scnhdr_ext
->s_nlnno
);
991 bfd_h_put_16 (abfd
, scnhdr_int
->s_nlnno
>> 16,
992 (bfd_byte
*) scnhdr_ext
->s_nreloc
);
996 if (scnhdr_int
->s_nlnno
<= 0xffff)
997 bfd_h_put_16 (abfd
, scnhdr_int
->s_nlnno
,
998 (bfd_byte
*) scnhdr_ext
->s_nlnno
);
1001 (*_bfd_error_handler
) (_("%s: line number overflow: 0x%lx > 0xffff"),
1002 bfd_get_filename (abfd
),
1003 scnhdr_int
->s_nlnno
);
1004 bfd_set_error (bfd_error_file_truncated
);
1005 bfd_h_put_16 (abfd
, 0xffff, (bfd_byte
*) scnhdr_ext
->s_nlnno
);
1009 if (scnhdr_int
->s_nreloc
<= 0xffff)
1010 bfd_h_put_16 (abfd
, scnhdr_int
->s_nreloc
,
1011 (bfd_byte
*) scnhdr_ext
->s_nreloc
);
1014 /* PE can deal with large #s of relocs, but not here. */
1015 bfd_h_put_16 (abfd
, 0xffff, (bfd_byte
*) scnhdr_ext
->s_nreloc
);
1016 scnhdr_int
->s_flags
|= IMAGE_SCN_LNK_NRELOC_OVFL
;
1017 bfd_h_put_32 (abfd
, scnhdr_int
->s_flags
,
1018 (bfd_byte
*) scnhdr_ext
->s_flags
);
1020 (*_bfd_error_handler
) (_("%s: reloc overflow 1: 0x%lx > 0xffff"),
1021 bfd_get_filename (abfd
),
1022 scnhdr_int
->s_nreloc
);
1023 bfd_set_error (bfd_error_file_truncated
);
1024 bfd_h_put_16 (abfd
, 0xffff, (bfd_byte
*) scnhdr_ext
->s_nreloc
);
1032 static char * dir_names
[IMAGE_NUMBEROF_DIRECTORY_ENTRIES
] =
1034 N_("Export Directory [.edata (or where ever we found it)]"),
1035 N_("Import Directory [parts of .idata]"),
1036 N_("Resource Directory [.rsrc]"),
1037 N_("Exception Directory [.pdata]"),
1038 N_("Security Directory"),
1039 N_("Base Relocation Directory [.reloc]"),
1040 N_("Debug Directory"),
1041 N_("Description Directory"),
1042 N_("Special Directory"),
1043 N_("Thread Storage Directory [.tls]"),
1044 N_("Load Configuration Directory"),
1045 N_("Bound Import Directory"),
1046 N_("Import Address Table Directory"),
1047 N_("Delay Import Directory"),
1052 #ifdef POWERPC_LE_PE
1053 /* The code for the PPC really falls in the "architecture dependent"
1054 category. However, it's not clear that anyone will ever care, so
1055 we're ignoring the issue for now; if/when PPC matters, some of this
1056 may need to go into peicode.h, or arguments passed to enable the
1057 PPC- specific code. */
1061 pe_print_idata (abfd
, vfile
)
1065 FILE *file
= (FILE *) vfile
;
1070 #ifdef POWERPC_LE_PE
1071 asection
*rel_section
= bfd_get_section_by_name (abfd
, ".reldata");
1074 bfd_size_type datasize
= 0;
1075 bfd_size_type dataoff
;
1079 pe_data_type
*pe
= pe_data (abfd
);
1080 struct internal_extra_pe_aouthdr
*extra
= &pe
->pe_opthdr
;
1084 addr
= extra
->DataDirectory
[1].VirtualAddress
;
1086 if (addr
== 0 && extra
->DataDirectory
[1].Size
== 0)
1088 /* Maybe the extra header isn't there. Look for the section. */
1089 section
= bfd_get_section_by_name (abfd
, ".idata");
1090 if (section
== NULL
)
1093 addr
= section
->vma
;
1094 datasize
= bfd_section_size (abfd
, section
);
1100 addr
+= extra
->ImageBase
;
1101 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
1103 datasize
= bfd_section_size (abfd
, section
);
1104 if (addr
>= section
->vma
&& addr
< section
->vma
+ datasize
)
1108 if (section
== NULL
)
1111 _("\nThere is an import table, but the section containing it could not be found\n"));
1116 fprintf (file
, _("\nThere is an import table in %s at 0x%lx\n"),
1117 section
->name
, (unsigned long) addr
);
1119 dataoff
= addr
- section
->vma
;
1120 datasize
-= dataoff
;
1122 #ifdef POWERPC_LE_PE
1123 if (rel_section
!= 0 && bfd_section_size (abfd
, rel_section
) != 0)
1125 /* The toc address can be found by taking the starting address,
1126 which on the PPC locates a function descriptor. The
1127 descriptor consists of the function code starting address
1128 followed by the address of the toc. The starting address we
1129 get from the bfd, and the descriptor is supposed to be in the
1130 .reldata section. */
1132 bfd_vma loadable_toc_address
;
1133 bfd_vma toc_address
;
1134 bfd_vma start_address
;
1138 data
= (bfd_byte
*) bfd_malloc ((size_t) bfd_section_size (abfd
,
1140 if (data
== NULL
&& bfd_section_size (abfd
, rel_section
) != 0)
1143 bfd_get_section_contents (abfd
,
1146 bfd_section_size (abfd
, rel_section
));
1148 offset
= abfd
->start_address
- rel_section
->vma
;
1150 start_address
= bfd_get_32 (abfd
, data
+ offset
);
1151 loadable_toc_address
= bfd_get_32 (abfd
, data
+ offset
+ 4);
1152 toc_address
= loadable_toc_address
- 32768;
1155 _("\nFunction descriptor located at the start address: %04lx\n"),
1156 (unsigned long int) (abfd
->start_address
));
1158 _("\tcode-base %08lx toc (loadable/actual) %08lx/%08lx\n"),
1159 start_address
, loadable_toc_address
, toc_address
);
1164 _("\nNo reldata section! Function descriptor not decoded.\n"));
1169 _("\nThe Import Tables (interpreted %s section contents)\n"),
1172 _(" vma: Hint Time Forward DLL First\n"));
1174 _(" Table Stamp Chain Name Thunk\n"));
1176 data
= (bfd_byte
*) bfd_malloc (dataoff
+ datasize
);
1180 /* Read the whole section. Some of the fields might be before dataoff. */
1181 if (! bfd_get_section_contents (abfd
, section
, (PTR
) data
,
1182 0, dataoff
+ datasize
))
1185 adj
= section
->vma
- extra
->ImageBase
;
1187 for (i
= 0; i
< datasize
; i
+= onaline
)
1191 bfd_vma forward_chain
;
1193 bfd_vma first_thunk
;
1198 /* print (i + extra->DataDirectory[1].VirtualAddress) */
1199 fprintf (file
, " %08lx\t", (unsigned long) (i
+ adj
+ dataoff
));
1201 if (i
+ 20 > datasize
)
1205 hint_addr
= bfd_get_32 (abfd
, data
+ i
+ dataoff
);
1206 time_stamp
= bfd_get_32 (abfd
, data
+ i
+ 4 + dataoff
);
1207 forward_chain
= bfd_get_32 (abfd
, data
+ i
+ 8 + dataoff
);
1208 dll_name
= bfd_get_32 (abfd
, data
+ i
+ 12 + dataoff
);
1209 first_thunk
= bfd_get_32 (abfd
, data
+ i
+ 16 + dataoff
);
1211 fprintf (file
, "%08lx %08lx %08lx %08lx %08lx\n",
1212 (unsigned long) hint_addr
,
1213 (unsigned long) time_stamp
,
1214 (unsigned long) forward_chain
,
1215 (unsigned long) dll_name
,
1216 (unsigned long) first_thunk
);
1218 if (hint_addr
== 0 && first_thunk
== 0)
1221 dll
= (char *) data
+ dll_name
- adj
;
1222 fprintf (file
, _("\n\tDLL Name: %s\n"), dll
);
1226 fprintf (file
, _("\tvma: Hint/Ord Member-Name\n"));
1228 idx
= hint_addr
- adj
;
1230 for (j
= 0; j
< datasize
; j
+= 4)
1232 unsigned long member
= bfd_get_32 (abfd
, data
+ idx
+ j
);
1236 if (member
& 0x80000000)
1237 fprintf (file
, "\t%04lx\t %4lu", member
,
1238 member
& 0x7fffffff);
1244 ordinal
= bfd_get_16 (abfd
, data
+ member
- adj
);
1245 member_name
= (char *) data
+ member
- adj
+ 2;
1246 fprintf (file
, "\t%04lx\t %4d %s",
1247 member
, ordinal
, member_name
);
1250 /* If the time stamp is not zero, the import address
1251 table holds actual addresses. */
1254 && first_thunk
!= hint_addr
)
1255 fprintf (file
, "\t%04lx",
1256 (long) bfd_get_32 (abfd
, data
+ first_thunk
- adj
+ j
));
1258 fprintf (file
, "\n");
1262 if (hint_addr
!= first_thunk
&& time_stamp
== 0)
1267 idx2
= first_thunk
- adj
;
1269 for (j
= 0; j
< datasize
; j
+= 4)
1273 bfd_vma hint_member
= 0;
1277 hint_member
= bfd_get_32 (abfd
, data
+ idx
+ j
);
1278 iat_member
= bfd_get_32 (abfd
, data
+ idx2
+ j
);
1280 if (hint_addr
== 0 && iat_member
== 0)
1283 if (hint_addr
== 0 || hint_member
!= iat_member
)
1288 _("\tThe Import Address Table (difference found)\n"));
1289 fprintf (file
, _("\tvma: Hint/Ord Member-Name\n"));
1293 if (iat_member
== 0)
1295 _("\t>>> Ran out of IAT members!\n"));
1298 ordinal
= bfd_get_16 (abfd
, data
+ iat_member
- adj
);
1299 member_name
= (char *) data
+ iat_member
- adj
+ 2;
1300 fprintf (file
, "\t%04lx\t %4d %s\n",
1301 (unsigned long) iat_member
,
1307 if (hint_addr
!= 0 && hint_member
== 0)
1313 _("\tThe Import Address Table is identical\n"));
1316 fprintf (file
, "\n");
1325 pe_print_edata (abfd
, vfile
)
1329 FILE *file
= (FILE *) vfile
;
1332 bfd_size_type datasize
= 0;
1333 bfd_size_type dataoff
;
1338 long export_flags
; /* reserved - should be zero */
1342 bfd_vma name
; /* rva - relative to image base */
1343 long base
; /* ordinal base */
1344 unsigned long num_functions
;/* Number in the export address table */
1345 unsigned long num_names
; /* Number in the name pointer table */
1346 bfd_vma eat_addr
; /* rva to the export address table */
1347 bfd_vma npt_addr
; /* rva to the Export Name Pointer Table */
1348 bfd_vma ot_addr
; /* rva to the Ordinal Table */
1351 pe_data_type
*pe
= pe_data (abfd
);
1352 struct internal_extra_pe_aouthdr
*extra
= &pe
->pe_opthdr
;
1356 addr
= extra
->DataDirectory
[0].VirtualAddress
;
1358 if (addr
== 0 && extra
->DataDirectory
[0].Size
== 0)
1360 /* Maybe the extra header isn't there. Look for the section. */
1361 section
= bfd_get_section_by_name (abfd
, ".edata");
1362 if (section
== NULL
)
1365 addr
= section
->vma
;
1366 datasize
= bfd_section_size (abfd
, section
);
1372 addr
+= extra
->ImageBase
;
1374 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
1376 datasize
= bfd_section_size (abfd
, section
);
1378 if (addr
>= section
->vma
&& addr
< section
->vma
+ datasize
)
1382 if (section
== NULL
)
1385 _("\nThere is an export table, but the section containing it could not be found\n"));
1390 fprintf (file
, _("\nThere is an export table in %s at 0x%lx\n"),
1391 section
->name
, (unsigned long) addr
);
1393 dataoff
= addr
- section
->vma
;
1394 datasize
-= dataoff
;
1396 data
= (bfd_byte
*) bfd_malloc (datasize
);
1400 if (! bfd_get_section_contents (abfd
, section
, (PTR
) data
, dataoff
,
1404 /* Go get Export Directory Table. */
1405 edt
.export_flags
= bfd_get_32 (abfd
, data
+ 0);
1406 edt
.time_stamp
= bfd_get_32 (abfd
, data
+ 4);
1407 edt
.major_ver
= bfd_get_16 (abfd
, data
+ 8);
1408 edt
.minor_ver
= bfd_get_16 (abfd
, data
+ 10);
1409 edt
.name
= bfd_get_32 (abfd
, data
+ 12);
1410 edt
.base
= bfd_get_32 (abfd
, data
+ 16);
1411 edt
.num_functions
= bfd_get_32 (abfd
, data
+ 20);
1412 edt
.num_names
= bfd_get_32 (abfd
, data
+ 24);
1413 edt
.eat_addr
= bfd_get_32 (abfd
, data
+ 28);
1414 edt
.npt_addr
= bfd_get_32 (abfd
, data
+ 32);
1415 edt
.ot_addr
= bfd_get_32 (abfd
, data
+ 36);
1417 adj
= section
->vma
- extra
->ImageBase
+ dataoff
;
1419 /* Dump the EDT first. */
1421 _("\nThe Export Tables (interpreted %s section contents)\n\n"),
1425 _("Export Flags \t\t\t%lx\n"), (unsigned long) edt
.export_flags
);
1428 _("Time/Date stamp \t\t%lx\n"), (unsigned long) edt
.time_stamp
);
1431 _("Major/Minor \t\t\t%d/%d\n"), edt
.major_ver
, edt
.minor_ver
);
1434 _("Name \t\t\t\t"));
1435 fprintf_vma (file
, edt
.name
);
1437 " %s\n", data
+ edt
.name
- adj
);
1440 _("Ordinal Base \t\t\t%ld\n"), edt
.base
);
1446 _("\tExport Address Table \t\t%08lx\n"),
1450 _("\t[Name Pointer/Ordinal] Table\t%08lx\n"), edt
.num_names
);
1453 _("Table Addresses\n"));
1456 _("\tExport Address Table \t\t"));
1457 fprintf_vma (file
, edt
.eat_addr
);
1458 fprintf (file
, "\n");
1461 _("\tName Pointer Table \t\t"));
1462 fprintf_vma (file
, edt
.npt_addr
);
1463 fprintf (file
, "\n");
1466 _("\tOrdinal Table \t\t\t"));
1467 fprintf_vma (file
, edt
.ot_addr
);
1468 fprintf (file
, "\n");
1470 /* The next table to find is the Export Address Table. It's basically
1471 a list of pointers that either locate a function in this dll, or
1472 forward the call to another dll. Something like:
1477 } export_address_table_entry;
1481 _("\nExport Address Table -- Ordinal Base %ld\n"),
1484 for (i
= 0; i
< edt
.num_functions
; ++i
)
1486 bfd_vma eat_member
= bfd_get_32 (abfd
,
1487 data
+ edt
.eat_addr
+ (i
* 4) - adj
);
1488 if (eat_member
== 0)
1491 if (eat_member
- adj
<= datasize
)
1493 /* This rva is to a name (forwarding function) in our section. */
1494 /* Should locate a function descriptor. */
1496 "\t[%4ld] +base[%4ld] %04lx %s -- %s\n",
1498 (long) (i
+ edt
.base
),
1499 (unsigned long) eat_member
,
1501 data
+ eat_member
- adj
);
1505 /* Should locate a function descriptor in the reldata section. */
1507 "\t[%4ld] +base[%4ld] %04lx %s\n",
1509 (long) (i
+ edt
.base
),
1510 (unsigned long) eat_member
,
1515 /* The Export Name Pointer Table is paired with the Export Ordinal Table. */
1516 /* Dump them in parallel for clarity. */
1518 _("\n[Ordinal/Name Pointer] Table\n"));
1520 for (i
= 0; i
< edt
.num_names
; ++i
)
1522 bfd_vma name_ptr
= bfd_get_32 (abfd
,
1527 char *name
= (char *) data
+ name_ptr
- adj
;
1529 bfd_vma ord
= bfd_get_16 (abfd
,
1534 "\t[%4ld] %s\n", (long) ord
, name
);
1542 /* This really is architecture dependent. On IA-64, a .pdata entry
1543 consists of three dwords containing relative virtual addresses that
1544 specify the start and end address of the code range the entry
1545 covers and the address of the corresponding unwind info data. */
1548 pe_print_pdata (abfd
, vfile
)
1552 #ifdef COFF_WITH_pep
1553 # define PDATA_ROW_SIZE (3*8)
1555 # define PDATA_ROW_SIZE (5*4)
1557 FILE *file
= (FILE *) vfile
;
1559 asection
*section
= bfd_get_section_by_name (abfd
, ".pdata");
1560 bfd_size_type datasize
= 0;
1562 bfd_size_type start
, stop
;
1563 int onaline
= PDATA_ROW_SIZE
;
1566 || coff_section_data (abfd
, section
) == NULL
1567 || pei_section_data (abfd
, section
) == NULL
)
1570 stop
= pei_section_data (abfd
, section
)->virt_size
;
1571 if ((stop
% onaline
) != 0)
1573 _("Warning, .pdata section size (%ld) is not a multiple of %d\n"),
1574 (long) stop
, onaline
);
1577 _("\nThe Function Table (interpreted .pdata section contents)\n"));
1578 #ifdef COFF_WITH_pep
1580 _(" vma:\t\t\tBegin Address End Address Unwind Info\n"));
1583 _(" vma:\t\tBegin End EH EH PrologEnd Exception\n"));
1585 _(" \t\tAddress Address Handler Data Address Mask\n"));
1588 if (bfd_section_size (abfd
, section
) == 0)
1591 data
= (bfd_byte
*) bfd_malloc ((size_t) bfd_section_size (abfd
, section
));
1592 datasize
= bfd_section_size (abfd
, section
);
1593 if (data
== NULL
&& datasize
!= 0)
1596 bfd_get_section_contents (abfd
,
1599 bfd_section_size (abfd
, section
));
1603 for (i
= start
; i
< stop
; i
+= onaline
)
1609 bfd_vma prolog_end_addr
;
1612 if (i
+ PDATA_ROW_SIZE
> stop
)
1615 begin_addr
= GET_PDATA_ENTRY (abfd
, data
+ i
);
1616 end_addr
= GET_PDATA_ENTRY (abfd
, data
+ i
+ 4);
1617 eh_handler
= GET_PDATA_ENTRY (abfd
, data
+ i
+ 8);
1618 eh_data
= GET_PDATA_ENTRY (abfd
, data
+ i
+ 12);
1619 prolog_end_addr
= GET_PDATA_ENTRY (abfd
, data
+ i
+ 16);
1621 if (begin_addr
== 0 && end_addr
== 0 && eh_handler
== 0
1622 && eh_data
== 0 && prolog_end_addr
== 0)
1623 /* We are probably into the padding of the section now. */
1626 em_data
= ((eh_handler
& 0x1) << 2) | (prolog_end_addr
& 0x3);
1627 eh_handler
&= ~(bfd_vma
) 0x3;
1628 prolog_end_addr
&= ~(bfd_vma
) 0x3;
1631 fprintf_vma (file
, i
+ section
->vma
); fputc ('\t', file
);
1632 fprintf_vma (file
, begin_addr
); fputc (' ', file
);
1633 fprintf_vma (file
, end_addr
); fputc (' ', file
);
1634 fprintf_vma (file
, eh_handler
);
1635 #ifndef COFF_WITH_pep
1637 fprintf_vma (file
, eh_data
); fputc (' ', file
);
1638 fprintf_vma (file
, prolog_end_addr
);
1639 fprintf (file
, " %x", em_data
);
1642 #ifdef POWERPC_LE_PE
1643 if (eh_handler
== 0 && eh_data
!= 0)
1645 /* Special bits here, although the meaning may be a little
1646 mysterious. The only one I know for sure is 0x03. */
1647 /* Code Significance */
1649 /* 0x01 Register Save Millicode */
1650 /* 0x02 Register Restore Millicode */
1651 /* 0x03 Glue Code Sequence */
1655 fprintf (file
, _(" Register save millicode"));
1658 fprintf (file
, _(" Register restore millicode"));
1661 fprintf (file
, _(" Glue code sequence"));
1668 fprintf (file
, "\n");
1676 #define IMAGE_REL_BASED_HIGHADJ 4
1677 static const char * const tbl
[] =
1691 "UNKNOWN", /* MUST be last */
1695 pe_print_reloc (abfd
, vfile
)
1699 FILE *file
= (FILE *) vfile
;
1701 asection
*section
= bfd_get_section_by_name (abfd
, ".reloc");
1702 bfd_size_type datasize
= 0;
1704 bfd_size_type start
, stop
;
1706 if (section
== NULL
)
1709 if (bfd_section_size (abfd
, section
) == 0)
1713 _("\n\nPE File Base Relocations (interpreted .reloc section contents)\n"));
1715 data
= (bfd_byte
*) bfd_malloc ((size_t) bfd_section_size (abfd
, section
));
1716 datasize
= bfd_section_size (abfd
, section
);
1717 if (data
== NULL
&& datasize
!= 0)
1720 bfd_get_section_contents (abfd
,
1723 bfd_section_size (abfd
, section
));
1727 stop
= bfd_section_size (abfd
, section
);
1729 for (i
= start
; i
< stop
;)
1732 bfd_vma virtual_address
;
1735 /* The .reloc section is a sequence of blocks, with a header consisting
1736 of two 32 bit quantities, followed by a number of 16 bit entries. */
1737 virtual_address
= bfd_get_32 (abfd
, data
+i
);
1738 size
= bfd_get_32 (abfd
, data
+i
+4);
1739 number
= (size
- 8) / 2;
1745 _("\nVirtual Address: %08lx Chunk size %ld (0x%lx) Number of fixups %ld\n"),
1746 (unsigned long) virtual_address
, size
, size
, number
);
1748 for (j
= 0; j
< number
; ++j
)
1750 unsigned short e
= bfd_get_16 (abfd
, data
+ i
+ 8 + j
* 2);
1751 unsigned int t
= (e
& 0xF000) >> 12;
1752 int off
= e
& 0x0FFF;
1754 if (t
>= sizeof (tbl
) / sizeof (tbl
[0]))
1755 t
= (sizeof (tbl
) / sizeof (tbl
[0])) - 1;
1758 _("\treloc %4d offset %4x [%4lx] %s"),
1759 j
, off
, (long) (off
+ virtual_address
), tbl
[t
]);
1761 /* HIGHADJ takes an argument, - the next record *is* the
1762 low 16 bits of addend. */
1763 if (t
== IMAGE_REL_BASED_HIGHADJ
)
1765 fprintf (file
, " (%4x)",
1767 bfd_get_16 (abfd
, data
+ i
+ 8 + j
* 2 + 2)));
1771 fprintf (file
, "\n");
1782 /* Print out the program headers. */
1785 _bfd_XX_print_private_bfd_data_common (abfd
, vfile
)
1789 FILE *file
= (FILE *) vfile
;
1791 pe_data_type
*pe
= pe_data (abfd
);
1792 struct internal_extra_pe_aouthdr
*i
= &pe
->pe_opthdr
;
1793 const char *subsystem_name
= NULL
;
1795 /* The MS dumpbin program reportedly ands with 0xff0f before
1796 printing the characteristics field. Not sure why. No reason to
1798 fprintf (file
, _("\nCharacteristics 0x%x\n"), pe
->real_flags
);
1800 #define PF(x, y) if (pe->real_flags & x) { fprintf (file, "\t%s\n", y); }
1801 PF (F_RELFLG
, "relocations stripped");
1802 PF (F_EXEC
, "executable");
1803 PF (F_LNNO
, "line numbers stripped");
1804 PF (F_LSYMS
, "symbols stripped");
1805 PF (0x80, "little endian");
1806 PF (F_AR32WR
, "32 bit words");
1807 PF (0x200, "debugging information removed");
1808 PF (0x1000, "system file");
1810 PF (0x8000, "big endian");
1813 /* ctime implies '\n'. */
1814 fprintf (file
, "\nTime/Date\t\t%s", ctime (&pe
->coff
.timestamp
));
1815 fprintf (file
, "\nImageBase\t\t");
1816 fprintf_vma (file
, i
->ImageBase
);
1817 fprintf (file
, "\nSectionAlignment\t");
1818 fprintf_vma (file
, i
->SectionAlignment
);
1819 fprintf (file
, "\nFileAlignment\t\t");
1820 fprintf_vma (file
, i
->FileAlignment
);
1821 fprintf (file
, "\nMajorOSystemVersion\t%d\n", i
->MajorOperatingSystemVersion
);
1822 fprintf (file
, "MinorOSystemVersion\t%d\n", i
->MinorOperatingSystemVersion
);
1823 fprintf (file
, "MajorImageVersion\t%d\n", i
->MajorImageVersion
);
1824 fprintf (file
, "MinorImageVersion\t%d\n", i
->MinorImageVersion
);
1825 fprintf (file
, "MajorSubsystemVersion\t%d\n", i
->MajorSubsystemVersion
);
1826 fprintf (file
, "MinorSubsystemVersion\t%d\n", i
->MinorSubsystemVersion
);
1827 fprintf (file
, "Win32Version\t\t%08lx\n", i
->Reserved1
);
1828 fprintf (file
, "SizeOfImage\t\t%08lx\n", i
->SizeOfImage
);
1829 fprintf (file
, "SizeOfHeaders\t\t%08lx\n", i
->SizeOfHeaders
);
1830 fprintf (file
, "CheckSum\t\t%08lx\n", i
->CheckSum
);
1832 switch (i
->Subsystem
)
1834 case IMAGE_SUBSYSTEM_UNKNOWN
:
1835 subsystem_name
= "unspecified";
1837 case IMAGE_SUBSYSTEM_NATIVE
:
1838 subsystem_name
= "NT native";
1840 case IMAGE_SUBSYSTEM_WINDOWS_GUI
:
1841 subsystem_name
= "Windows GUI";
1843 case IMAGE_SUBSYSTEM_WINDOWS_CUI
:
1844 subsystem_name
= "Windows CUI";
1846 case IMAGE_SUBSYSTEM_POSIX_CUI
:
1847 subsystem_name
= "POSIX CUI";
1849 case IMAGE_SUBSYSTEM_WINDOWS_CE_GUI
:
1850 subsystem_name
= "Wince CUI";
1852 case IMAGE_SUBSYSTEM_EFI_APPLICATION
:
1853 subsystem_name
= "EFI application";
1855 case IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER
:
1856 subsystem_name
= "EFI boot service driver";
1858 case IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER
:
1859 subsystem_name
= "EFI runtime driver";
1863 fprintf (file
, "Subsystem\t\t%08x", i
->Subsystem
);
1865 fprintf (file
, "\t(%s)", subsystem_name
);
1866 fprintf (file
, "\nDllCharacteristics\t%08x\n", i
->DllCharacteristics
);
1867 fprintf (file
, "SizeOfStackReserve\t");
1868 fprintf_vma (file
, i
->SizeOfStackReserve
);
1869 fprintf (file
, "\nSizeOfStackCommit\t");
1870 fprintf_vma (file
, i
->SizeOfStackCommit
);
1871 fprintf (file
, "\nSizeOfHeapReserve\t");
1872 fprintf_vma (file
, i
->SizeOfHeapReserve
);
1873 fprintf (file
, "\nSizeOfHeapCommit\t");
1874 fprintf_vma (file
, i
->SizeOfHeapCommit
);
1875 fprintf (file
, "\nLoaderFlags\t\t%08lx\n", i
->LoaderFlags
);
1876 fprintf (file
, "NumberOfRvaAndSizes\t%08lx\n", i
->NumberOfRvaAndSizes
);
1878 fprintf (file
, "\nThe Data Directory\n");
1879 for (j
= 0; j
< IMAGE_NUMBEROF_DIRECTORY_ENTRIES
; j
++)
1881 fprintf (file
, "Entry %1x ", j
);
1882 fprintf_vma (file
, i
->DataDirectory
[j
].VirtualAddress
);
1883 fprintf (file
, " %08lx ", i
->DataDirectory
[j
].Size
);
1884 fprintf (file
, "%s\n", dir_names
[j
]);
1887 pe_print_idata (abfd
, vfile
);
1888 pe_print_edata (abfd
, vfile
);
1889 pe_print_pdata (abfd
, vfile
);
1890 pe_print_reloc (abfd
, vfile
);
1895 /* Copy any private info we understand from the input bfd
1896 to the output bfd. */
1899 _bfd_XX_bfd_copy_private_bfd_data_common (ibfd
, obfd
)
1902 /* One day we may try to grok other private data. */
1903 if (ibfd
->xvec
->flavour
!= bfd_target_coff_flavour
1904 || obfd
->xvec
->flavour
!= bfd_target_coff_flavour
)
1907 pe_data (obfd
)->pe_opthdr
= pe_data (ibfd
)->pe_opthdr
;
1908 pe_data (obfd
)->dll
= pe_data (ibfd
)->dll
;
1910 /* For strip: if we removed .reloc, we'll make a real mess of things
1911 if we don't remove this entry as well. */
1912 if (! pe_data (obfd
)->has_reloc_section
)
1914 pe_data (obfd
)->pe_opthdr
.DataDirectory
[5].VirtualAddress
= 0;
1915 pe_data (obfd
)->pe_opthdr
.DataDirectory
[5].Size
= 0;
1920 /* Copy private section data. */
1923 _bfd_XX_bfd_copy_private_section_data (ibfd
, isec
, obfd
, osec
)
1929 if (bfd_get_flavour (ibfd
) != bfd_target_coff_flavour
1930 || bfd_get_flavour (obfd
) != bfd_target_coff_flavour
)
1933 if (coff_section_data (ibfd
, isec
) != NULL
1934 && pei_section_data (ibfd
, isec
) != NULL
)
1936 if (coff_section_data (obfd
, osec
) == NULL
)
1939 (PTR
) bfd_zalloc (obfd
, sizeof (struct coff_section_tdata
));
1940 if (osec
->used_by_bfd
== NULL
)
1944 if (pei_section_data (obfd
, osec
) == NULL
)
1946 coff_section_data (obfd
, osec
)->tdata
=
1947 (PTR
) bfd_zalloc (obfd
, sizeof (struct pei_section_tdata
));
1948 if (coff_section_data (obfd
, osec
)->tdata
== NULL
)
1952 pei_section_data (obfd
, osec
)->virt_size
=
1953 pei_section_data (ibfd
, isec
)->virt_size
;
1954 pei_section_data (obfd
, osec
)->pe_flags
=
1955 pei_section_data (ibfd
, isec
)->pe_flags
;
1962 _bfd_XX_get_symbol_info (abfd
, symbol
, ret
)
1967 coff_get_symbol_info (abfd
, symbol
, ret
);
1968 #if 0 /* This code no longer appears to be necessary.
1969 ImageBase has already been added in by coff_swap_scnhdr_in. */
1970 if (pe_data (abfd
) != NULL
1971 && ((symbol
->flags
& BSF_DEBUGGING
) == 0
1972 || (symbol
->flags
& BSF_DEBUGGING_RELOC
) != 0)
1973 && ! bfd_is_abs_section (symbol
->section
))
1974 ret
->value
+= pe_data (abfd
)->pe_opthdr
.ImageBase
;
1978 /* Handle the .idata section and other things that need symbol table
1982 _bfd_XXi_final_link_postscript (abfd
, pfinfo
)
1984 struct coff_final_link_info
*pfinfo
;
1986 struct coff_link_hash_entry
*h1
;
1987 struct bfd_link_info
*info
= pfinfo
->info
;
1989 /* There are a few fields that need to be filled in now while we
1990 have symbol table access.
1992 The .idata subsections aren't directly available as sections, but
1993 they are in the symbol table, so get them from there. */
1995 /* The import directory. This is the address of .idata$2, with size
1996 of .idata$2 + .idata$3. */
1997 h1
= coff_link_hash_lookup (coff_hash_table (info
),
1998 ".idata$2", false, false, true);
2001 pe_data (abfd
)->pe_opthdr
.DataDirectory
[1].VirtualAddress
=
2002 (h1
->root
.u
.def
.value
2003 + h1
->root
.u
.def
.section
->output_section
->vma
2004 + h1
->root
.u
.def
.section
->output_offset
);
2005 h1
= coff_link_hash_lookup (coff_hash_table (info
),
2006 ".idata$4", false, false, true);
2007 pe_data (abfd
)->pe_opthdr
.DataDirectory
[1].Size
=
2008 ((h1
->root
.u
.def
.value
2009 + h1
->root
.u
.def
.section
->output_section
->vma
2010 + h1
->root
.u
.def
.section
->output_offset
)
2011 - pe_data (abfd
)->pe_opthdr
.DataDirectory
[1].VirtualAddress
);
2013 /* The import address table. This is the size/address of
2015 h1
= coff_link_hash_lookup (coff_hash_table (info
),
2016 ".idata$5", false, false, true);
2017 pe_data (abfd
)->pe_opthdr
.DataDirectory
[12].VirtualAddress
=
2018 (h1
->root
.u
.def
.value
2019 + h1
->root
.u
.def
.section
->output_section
->vma
2020 + h1
->root
.u
.def
.section
->output_offset
);
2021 h1
= coff_link_hash_lookup (coff_hash_table (info
),
2022 ".idata$6", false, false, true);
2023 pe_data (abfd
)->pe_opthdr
.DataDirectory
[12].Size
=
2024 ((h1
->root
.u
.def
.value
2025 + h1
->root
.u
.def
.section
->output_section
->vma
2026 + h1
->root
.u
.def
.section
->output_offset
)
2027 - pe_data (abfd
)->pe_opthdr
.DataDirectory
[12].VirtualAddress
);
2030 /* If we couldn't find idata$2, we either have an excessively
2031 trivial program or are in DEEP trouble; we have to assume trivial