1 /* Support for the generic parts of PE/PEI; the common executable parts.
2 Copyright 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
3 Written by Cygnus Solutions.
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,
25 PE/PEI rearrangement (and code added): Donn Terry
29 /* Hey look, some documentation [and in a place you expect to find it]!
31 The main reference for the pei format is "Microsoft Portable Executable
32 and Common Object File Format Specification 4.1". Get it if you need to
33 do some serious hacking on this code.
36 "Peering Inside the PE: A Tour of the Win32 Portable Executable
37 File Format", MSJ 1994, Volume 9.
39 The *sole* difference between the pe format and the pei format is that the
40 latter has an MSDOS 2.0 .exe header on the front that prints the message
41 "This app must be run under Windows." (or some such).
42 (FIXME: Whether that statement is *really* true or not is unknown.
43 Are there more subtle differences between pe and pei formats?
44 For now assume there aren't. If you find one, then for God sakes
47 The Microsoft docs use the word "image" instead of "executable" because
48 the former can also refer to a DLL (shared library). Confusion can arise
49 because the `i' in `pei' also refers to "image". The `pe' format can
50 also create images (i.e. executables), it's just that to run on a win32
51 system you need to use the pei format.
53 FIXME: Please add more docs here so the next poor fool that has to hack
54 on this code has a chance of getting something accomplished without
55 wasting too much time.
61 #include "coff/internal.h"
63 /* NOTE: it's strange to be including an architecture specific header
64 in what's supposed to be general (to PE/PEI) code. However, that's
65 where the definitions are, and they don't vary per architecture
66 within PE/PEI, so we get them from there. FIXME: The lack of
67 variance is an assumption which may prove to be incorrect if new
68 PE/PEI targets are created. */
69 #include "coff/i386.h"
75 /* FIXME: This file has various tests of POWERPC_LE_PE. Those tests
76 worked when the code was in peicode.h, but no longer work now that
77 the code is in peigen.c. PowerPC NT is said to be dead. If
78 anybody wants to revive the code, you will have to figure out how
79 to handle those issues. */
81 static void add_data_entry
82 PARAMS ((bfd
*, struct internal_extra_pe_aouthdr
*, int, char *, bfd_vma
));
83 static boolean pe_print_pdata
PARAMS ((bfd
*, PTR
));
84 static boolean pe_print_reloc
PARAMS ((bfd
*, PTR
));
86 /**********************************************************************/
89 _bfd_pei_swap_sym_in (abfd
, ext1
, in1
)
94 SYMENT
*ext
= (SYMENT
*)ext1
;
95 struct internal_syment
*in
= (struct internal_syment
*)in1
;
97 if( ext
->e
.e_name
[0] == 0) {
98 in
->_n
._n_n
._n_zeroes
= 0;
99 in
->_n
._n_n
._n_offset
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->e
.e
.e_offset
);
102 memcpy(in
->_n
._n_name
, ext
->e
.e_name
, SYMNMLEN
);
105 in
->n_value
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->e_value
);
106 in
->n_scnum
= bfd_h_get_16(abfd
, (bfd_byte
*) ext
->e_scnum
);
107 if (sizeof(ext
->e_type
) == 2){
108 in
->n_type
= bfd_h_get_16(abfd
, (bfd_byte
*) ext
->e_type
);
111 in
->n_type
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->e_type
);
113 in
->n_sclass
= bfd_h_get_8(abfd
, ext
->e_sclass
);
114 in
->n_numaux
= bfd_h_get_8(abfd
, ext
->e_numaux
);
116 #ifndef STRICT_PE_FORMAT
117 /* This is for Gnu-created DLLs */
119 /* The section symbols for the .idata$ sections have class 0x68
120 (C_SECTION), which MS documentation indicates is a section
121 symbol. Unfortunately, the value field in the symbol is simply a
122 copy of the .idata section's flags rather than something useful.
123 When these symbols are encountered, change the value to 0 so that
124 they will be handled somewhat correctly in the bfd code. */
125 if (in
->n_sclass
== C_SECTION
)
130 /* FIXME: This is clearly wrong. The problem seems to be that
131 undefined C_SECTION symbols appear in the first object of a
132 MS generated .lib file, and the symbols are not defined
136 /* I have tried setting the class to 3 and using the following
137 to set the section number. This will put the address of the
138 pointer to the string kernel32.dll at addresses 0 and 0x10
139 off start of idata section which is not correct */
140 /* if (strcmp (in->_n._n_name, ".idata$4") == 0) */
141 /* in->n_scnum = 3; */
143 /* in->n_scnum = 2; */
145 /* Create synthetic empty sections as needed. DJ */
146 if (in
->n_scnum
== 0)
149 for (sec
=abfd
->sections
; sec
; sec
=sec
->next
)
151 if (strcmp (sec
->name
, in
->n_name
) == 0)
153 in
->n_scnum
= sec
->target_index
;
158 if (in
->n_scnum
== 0)
160 int unused_section_number
= 0;
163 for (sec
=abfd
->sections
; sec
; sec
=sec
->next
)
164 if (unused_section_number
<= sec
->target_index
)
165 unused_section_number
= sec
->target_index
+1;
167 name
= bfd_alloc (abfd
, strlen (in
->n_name
) + 10);
170 strcpy (name
, in
->n_name
);
171 sec
= bfd_make_section_anyway (abfd
, name
);
175 sec
->_cooked_size
= 0;
178 sec
->rel_filepos
= 0;
179 sec
->reloc_count
= 0;
180 sec
->line_filepos
= 0;
181 sec
->lineno_count
= 0;
182 sec
->userdata
= NULL
;
183 sec
->next
= (asection
*) NULL
;
185 sec
->alignment_power
= 2;
186 sec
->flags
= SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_DATA
| SEC_LOAD
;
188 sec
->target_index
= unused_section_number
;
190 in
->n_scnum
= unused_section_number
;
192 in
->n_sclass
= C_STAT
;
197 #ifdef coff_swap_sym_in_hook
198 /* This won't work in peigen.c, but since it's for PPC PE, it's not
200 coff_swap_sym_in_hook(abfd
, ext1
, in1
);
205 _bfd_pei_swap_sym_out (abfd
, inp
, extp
)
210 struct internal_syment
*in
= (struct internal_syment
*)inp
;
211 SYMENT
*ext
=(SYMENT
*)extp
;
212 if(in
->_n
._n_name
[0] == 0) {
213 bfd_h_put_32(abfd
, 0, (bfd_byte
*) ext
->e
.e
.e_zeroes
);
214 bfd_h_put_32(abfd
, in
->_n
._n_n
._n_offset
, (bfd_byte
*) ext
->e
.e
.e_offset
);
217 memcpy(ext
->e
.e_name
, in
->_n
._n_name
, SYMNMLEN
);
220 bfd_h_put_32(abfd
, in
->n_value
, (bfd_byte
*) ext
->e_value
);
221 bfd_h_put_16(abfd
, in
->n_scnum
, (bfd_byte
*) ext
->e_scnum
);
222 if (sizeof(ext
->e_type
) == 2)
224 bfd_h_put_16(abfd
, in
->n_type
, (bfd_byte
*) ext
->e_type
);
228 bfd_h_put_32(abfd
, in
->n_type
, (bfd_byte
*) ext
->e_type
);
230 bfd_h_put_8(abfd
, in
->n_sclass
, ext
->e_sclass
);
231 bfd_h_put_8(abfd
, in
->n_numaux
, ext
->e_numaux
);
237 _bfd_pei_swap_aux_in (abfd
, ext1
, type
, class, indx
, numaux
, in1
)
242 int indx ATTRIBUTE_UNUSED
;
243 int numaux ATTRIBUTE_UNUSED
;
246 AUXENT
*ext
= (AUXENT
*)ext1
;
247 union internal_auxent
*in
= (union internal_auxent
*)in1
;
251 if (ext
->x_file
.x_fname
[0] == 0) {
252 in
->x_file
.x_n
.x_zeroes
= 0;
253 in
->x_file
.x_n
.x_offset
=
254 bfd_h_get_32(abfd
, (bfd_byte
*) ext
->x_file
.x_n
.x_offset
);
256 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_fname
, FILNMLEN
);
264 if (type
== T_NULL
) {
265 in
->x_scn
.x_scnlen
= GET_SCN_SCNLEN(abfd
, ext
);
266 in
->x_scn
.x_nreloc
= GET_SCN_NRELOC(abfd
, ext
);
267 in
->x_scn
.x_nlinno
= GET_SCN_NLINNO(abfd
, ext
);
268 in
->x_scn
.x_checksum
= bfd_h_get_32 (abfd
,
269 (bfd_byte
*) ext
->x_scn
.x_checksum
);
270 in
->x_scn
.x_associated
=
271 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_scn
.x_associated
);
272 in
->x_scn
.x_comdat
= bfd_h_get_8 (abfd
,
273 (bfd_byte
*) ext
->x_scn
.x_comdat
);
279 in
->x_sym
.x_tagndx
.l
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->x_sym
.x_tagndx
);
280 in
->x_sym
.x_tvndx
= bfd_h_get_16(abfd
, (bfd_byte
*) ext
->x_sym
.x_tvndx
);
282 if (class == C_BLOCK
|| class == C_FCN
|| ISFCN (type
) || ISTAG (class))
284 in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
= GET_FCN_LNNOPTR (abfd
, ext
);
285 in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
= GET_FCN_ENDNDX (abfd
, ext
);
289 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0] =
290 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
291 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1] =
292 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
293 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2] =
294 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
295 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3] =
296 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
300 in
->x_sym
.x_misc
.x_fsize
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->x_sym
.x_misc
.x_fsize
);
303 in
->x_sym
.x_misc
.x_lnsz
.x_lnno
= GET_LNSZ_LNNO(abfd
, ext
);
304 in
->x_sym
.x_misc
.x_lnsz
.x_size
= GET_LNSZ_SIZE(abfd
, ext
);
309 _bfd_pei_swap_aux_out (abfd
, inp
, type
, class, indx
, numaux
, extp
)
314 int indx ATTRIBUTE_UNUSED
;
315 int numaux ATTRIBUTE_UNUSED
;
318 union internal_auxent
*in
= (union internal_auxent
*)inp
;
319 AUXENT
*ext
= (AUXENT
*)extp
;
321 memset((PTR
)ext
, 0, AUXESZ
);
324 if (in
->x_file
.x_fname
[0] == 0) {
325 bfd_h_put_32(abfd
, 0, (bfd_byte
*) ext
->x_file
.x_n
.x_zeroes
);
327 in
->x_file
.x_n
.x_offset
,
328 (bfd_byte
*) ext
->x_file
.x_n
.x_offset
);
331 memcpy (ext
->x_file
.x_fname
, in
->x_file
.x_fname
, FILNMLEN
);
339 if (type
== T_NULL
) {
340 PUT_SCN_SCNLEN(abfd
, in
->x_scn
.x_scnlen
, ext
);
341 PUT_SCN_NRELOC(abfd
, in
->x_scn
.x_nreloc
, ext
);
342 PUT_SCN_NLINNO(abfd
, in
->x_scn
.x_nlinno
, ext
);
343 bfd_h_put_32 (abfd
, in
->x_scn
.x_checksum
,
344 (bfd_byte
*) ext
->x_scn
.x_checksum
);
345 bfd_h_put_16 (abfd
, in
->x_scn
.x_associated
,
346 (bfd_byte
*) ext
->x_scn
.x_associated
);
347 bfd_h_put_8 (abfd
, in
->x_scn
.x_comdat
,
348 (bfd_byte
*) ext
->x_scn
.x_comdat
);
354 bfd_h_put_32(abfd
, in
->x_sym
.x_tagndx
.l
, (bfd_byte
*) ext
->x_sym
.x_tagndx
);
355 bfd_h_put_16(abfd
, in
->x_sym
.x_tvndx
, (bfd_byte
*) ext
->x_sym
.x_tvndx
);
357 if (class == C_BLOCK
|| class == C_FCN
|| ISFCN (type
) || ISTAG (class))
359 PUT_FCN_LNNOPTR(abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
, ext
);
360 PUT_FCN_ENDNDX(abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
, ext
);
364 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0],
365 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
366 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1],
367 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
368 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2],
369 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
370 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3],
371 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
375 bfd_h_put_32 (abfd
, in
->x_sym
.x_misc
.x_fsize
,
376 (bfd_byte
*) ext
->x_sym
.x_misc
.x_fsize
);
379 PUT_LNSZ_LNNO (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_lnno
, ext
);
380 PUT_LNSZ_SIZE (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_size
, ext
);
387 _bfd_pei_swap_lineno_in (abfd
, ext1
, in1
)
392 LINENO
*ext
= (LINENO
*)ext1
;
393 struct internal_lineno
*in
= (struct internal_lineno
*)in1
;
395 in
->l_addr
.l_symndx
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->l_addr
.l_symndx
);
396 in
->l_lnno
= GET_LINENO_LNNO(abfd
, ext
);
400 _bfd_pei_swap_lineno_out (abfd
, inp
, outp
)
405 struct internal_lineno
*in
= (struct internal_lineno
*)inp
;
406 struct external_lineno
*ext
= (struct external_lineno
*)outp
;
407 bfd_h_put_32(abfd
, in
->l_addr
.l_symndx
, (bfd_byte
*)
408 ext
->l_addr
.l_symndx
);
410 PUT_LINENO_LNNO (abfd
, in
->l_lnno
, ext
);
415 _bfd_pei_swap_aouthdr_in (abfd
, aouthdr_ext1
, aouthdr_int1
)
420 struct internal_extra_pe_aouthdr
*a
;
421 PEAOUTHDR
*src
= (PEAOUTHDR
*)(aouthdr_ext1
);
422 AOUTHDR
*aouthdr_ext
= (AOUTHDR
*) aouthdr_ext1
;
423 struct internal_aouthdr
*aouthdr_int
= (struct internal_aouthdr
*)aouthdr_int1
;
425 aouthdr_int
->magic
= bfd_h_get_16(abfd
, (bfd_byte
*) aouthdr_ext
->magic
);
426 aouthdr_int
->vstamp
= bfd_h_get_16(abfd
, (bfd_byte
*) aouthdr_ext
->vstamp
);
428 GET_AOUTHDR_TSIZE (abfd
, (bfd_byte
*) aouthdr_ext
->tsize
);
430 GET_AOUTHDR_DSIZE (abfd
, (bfd_byte
*) aouthdr_ext
->dsize
);
432 GET_AOUTHDR_BSIZE (abfd
, (bfd_byte
*) aouthdr_ext
->bsize
);
434 GET_AOUTHDR_ENTRY (abfd
, (bfd_byte
*) aouthdr_ext
->entry
);
435 aouthdr_int
->text_start
=
436 GET_AOUTHDR_TEXT_START (abfd
, (bfd_byte
*) aouthdr_ext
->text_start
);
437 #ifndef COFF_WITH_PEP64
438 /* PE32+ does not have data_start member! */
439 aouthdr_int
->data_start
=
440 GET_AOUTHDR_DATA_START (abfd
, (bfd_byte
*) aouthdr_ext
->data_start
);
443 a
= &aouthdr_int
->pe
;
444 a
->ImageBase
= GET_OPTHDR_IMAGE_BASE (abfd
, (bfd_byte
*)src
->ImageBase
);
445 a
->SectionAlignment
= bfd_h_get_32 (abfd
, (bfd_byte
*)src
->SectionAlignment
);
446 a
->FileAlignment
= bfd_h_get_32 (abfd
, (bfd_byte
*)src
->FileAlignment
);
447 a
->MajorOperatingSystemVersion
=
448 bfd_h_get_16 (abfd
, (bfd_byte
*)src
->MajorOperatingSystemVersion
);
449 a
->MinorOperatingSystemVersion
=
450 bfd_h_get_16 (abfd
, (bfd_byte
*)src
->MinorOperatingSystemVersion
);
451 a
->MajorImageVersion
= bfd_h_get_16 (abfd
, (bfd_byte
*)src
->MajorImageVersion
);
452 a
->MinorImageVersion
= bfd_h_get_16 (abfd
, (bfd_byte
*)src
->MinorImageVersion
);
453 a
->MajorSubsystemVersion
= bfd_h_get_16 (abfd
, (bfd_byte
*)src
->MajorSubsystemVersion
);
454 a
->MinorSubsystemVersion
= bfd_h_get_16 (abfd
, (bfd_byte
*)src
->MinorSubsystemVersion
);
455 a
->Reserved1
= bfd_h_get_32 (abfd
, (bfd_byte
*)src
->Reserved1
);
456 a
->SizeOfImage
= bfd_h_get_32 (abfd
, (bfd_byte
*)src
->SizeOfImage
);
457 a
->SizeOfHeaders
= bfd_h_get_32 (abfd
, (bfd_byte
*)src
->SizeOfHeaders
);
458 a
->CheckSum
= bfd_h_get_32 (abfd
, (bfd_byte
*)src
->CheckSum
);
459 a
->Subsystem
= bfd_h_get_16 (abfd
, (bfd_byte
*)src
->Subsystem
);
460 a
->DllCharacteristics
= bfd_h_get_16 (abfd
, (bfd_byte
*)src
->DllCharacteristics
);
461 a
->SizeOfStackReserve
= GET_OPTHDR_SIZE_OF_STACK_RESERVE (abfd
, (bfd_byte
*)src
->SizeOfStackReserve
);
462 a
->SizeOfStackCommit
= GET_OPTHDR_SIZE_OF_STACK_COMMIT (abfd
, (bfd_byte
*)src
->SizeOfStackCommit
);
463 a
->SizeOfHeapReserve
= GET_OPTHDR_SIZE_OF_HEAP_RESERVE (abfd
, (bfd_byte
*)src
->SizeOfHeapReserve
);
464 a
->SizeOfHeapCommit
= GET_OPTHDR_SIZE_OF_HEAP_COMMIT (abfd
, (bfd_byte
*)src
->SizeOfHeapCommit
);
465 a
->LoaderFlags
= bfd_h_get_32 (abfd
, (bfd_byte
*)src
->LoaderFlags
);
466 a
->NumberOfRvaAndSizes
= bfd_h_get_32 (abfd
, (bfd_byte
*)src
->NumberOfRvaAndSizes
);
470 for (idx
=0; idx
< 16; idx
++)
472 a
->DataDirectory
[idx
].VirtualAddress
=
473 bfd_h_get_32 (abfd
, (bfd_byte
*)src
->DataDirectory
[idx
][0]);
474 a
->DataDirectory
[idx
].Size
=
475 bfd_h_get_32 (abfd
, (bfd_byte
*)src
->DataDirectory
[idx
][1]);
479 if (aouthdr_int
->entry
)
481 aouthdr_int
->entry
+= a
->ImageBase
;
482 #ifndef COFF_WITH_PEP64
483 aouthdr_int
->entry
&= 0xffffffff;
486 if (aouthdr_int
->tsize
)
488 aouthdr_int
->text_start
+= a
->ImageBase
;
489 #ifndef COFF_WITH_PEP64
490 aouthdr_int
->text_start
&= 0xffffffff;
493 #ifndef COFF_WITH_PEP64
494 /* PE32+ does not have data_start member! */
495 if (aouthdr_int
->dsize
)
497 aouthdr_int
->data_start
+= a
->ImageBase
;
498 aouthdr_int
->data_start
&= 0xffffffff;
503 /* These three fields are normally set up by ppc_relocate_section.
504 In the case of reading a file in, we can pick them up from the
506 first_thunk_address
= a
->DataDirectory
[12].VirtualAddress
;
507 thunk_size
= a
->DataDirectory
[12].Size
;
508 import_table_size
= a
->DataDirectory
[1].Size
;
513 /* A support function for below. */
516 add_data_entry (abfd
, aout
, idx
, name
, base
)
518 struct internal_extra_pe_aouthdr
*aout
;
523 asection
*sec
= bfd_get_section_by_name (abfd
, name
);
525 /* add import directory information if it exists */
527 && (coff_section_data (abfd
, sec
) != NULL
)
528 && (pei_section_data (abfd
, sec
) != NULL
))
530 aout
->DataDirectory
[idx
].VirtualAddress
= (sec
->vma
- base
) & 0xffffffff;
531 aout
->DataDirectory
[idx
].Size
= pei_section_data (abfd
, sec
)->virt_size
;
532 sec
->flags
|= SEC_DATA
;
537 _bfd_pei_swap_aouthdr_out (abfd
, in
, out
)
542 struct internal_aouthdr
*aouthdr_in
= (struct internal_aouthdr
*)in
;
543 struct internal_extra_pe_aouthdr
*extra
= &pe_data (abfd
)->pe_opthdr
;
544 PEAOUTHDR
*aouthdr_out
= (PEAOUTHDR
*)out
;
547 /* The following definitely is required for EFI applications.
548 Perhaps it's needed for other PEI targets as well, but I don't
549 know that for a fact, so we play it safe here and tweak the
550 alignments only if PEI_FORCE_MINIMUM_ALIGNMENT is
552 #ifdef PEI_FORCE_MINIMUM_ALIGNMENT
553 if (!extra
->FileAlignment
)
554 extra
->FileAlignment
= PE_DEF_FILE_ALIGNMENT
;
555 if (!extra
->SectionAlignment
)
556 extra
->SectionAlignment
= PE_DEF_SECTION_ALIGNMENT
;
559 #ifdef PEI_DEFAULT_TARGET_SUBSYSTEM
560 if (extra
->Subsystem
== IMAGE_SUBSYSTEM_UNKNOWN
)
561 extra
->Subsystem
= PEI_DEFAULT_TARGET_SUBSYSTEM
;
564 sa
= extra
->SectionAlignment
;
565 fa
= extra
->FileAlignment
;
566 ib
= extra
->ImageBase
;
568 if (aouthdr_in
->tsize
)
570 aouthdr_in
->text_start
-= ib
;
571 aouthdr_in
->text_start
&= 0xffffffff;
573 if (aouthdr_in
->dsize
)
575 aouthdr_in
->data_start
-= ib
;
576 aouthdr_in
->data_start
&= 0xffffffff;
578 if (aouthdr_in
->entry
)
580 aouthdr_in
->entry
-= ib
;
581 aouthdr_in
->entry
&= 0xffffffff;
584 #define FA(x) (((x) + fa -1 ) & (- fa))
585 #define SA(x) (((x) + sa -1 ) & (- sa))
587 /* We like to have the sizes aligned */
589 aouthdr_in
->bsize
= FA (aouthdr_in
->bsize
);
592 extra
->NumberOfRvaAndSizes
= IMAGE_NUMBEROF_DIRECTORY_ENTRIES
;
594 /* first null out all data directory entries .. */
595 memset (extra
->DataDirectory
, sizeof (extra
->DataDirectory
), 0);
597 add_data_entry (abfd
, extra
, 0, ".edata", ib
);
599 /* Don't call add_data_entry for .idata$2 or .idata$5. It's done in
600 bfd_coff_final_link where all the required information is
603 /* However, until other .idata fixes are made (pending patch), the
604 entry for .idata is needed for backwards compatability. FIXME. */
605 add_data_entry (abfd
, extra
, 1, ".idata" , ib
);
607 add_data_entry (abfd
, extra
, 2, ".rsrc" , ib
);
609 add_data_entry (abfd
, extra
, 3, ".pdata", ib
);
611 /* For some reason, the virtual size (which is what's set by
612 add_data_entry) for .reloc is not the same as the size recorded
613 in this slot by MSVC; it doesn't seem to cause problems (so far),
614 but since it's the best we've got, use it. It does do the right
616 if (pe_data (abfd
)->has_reloc_section
)
617 add_data_entry (abfd
, extra
, 5, ".reloc", ib
);
622 bfd_vma isize
= SA(abfd
->sections
->filepos
);
625 for (sec
= abfd
->sections
; sec
; sec
= sec
->next
)
627 int rounded
= FA(sec
->_raw_size
);
629 if (sec
->flags
& SEC_DATA
)
631 if (sec
->flags
& SEC_CODE
)
633 /* The image size is the total VIRTUAL size (which is what is
634 in the virt_size field). Files have been seen (from MSVC
635 5.0 link.exe) where the file size of the .data segment is
636 quite small compared to the virtual size. Without this
637 fix, strip munges the file. */
638 isize
+= SA (FA (pei_section_data (abfd
, sec
)->virt_size
));
641 aouthdr_in
->dsize
= dsize
;
642 aouthdr_in
->tsize
= tsize
;
643 extra
->SizeOfImage
= isize
;
646 extra
->SizeOfHeaders
= abfd
->sections
->filepos
;
647 bfd_h_put_16(abfd
, aouthdr_in
->magic
, (bfd_byte
*) aouthdr_out
->standard
.magic
);
649 #define LINKER_VERSION 256 /* That is, 2.56 */
651 /* This piece of magic sets the "linker version" field to
654 LINKER_VERSION
/ 100 + (LINKER_VERSION
% 100) * 256,
655 (bfd_byte
*) aouthdr_out
->standard
.vstamp
);
657 PUT_AOUTHDR_TSIZE (abfd
, aouthdr_in
->tsize
, (bfd_byte
*) aouthdr_out
->standard
.tsize
);
658 PUT_AOUTHDR_DSIZE (abfd
, aouthdr_in
->dsize
, (bfd_byte
*) aouthdr_out
->standard
.dsize
);
659 PUT_AOUTHDR_BSIZE (abfd
, aouthdr_in
->bsize
, (bfd_byte
*) aouthdr_out
->standard
.bsize
);
660 PUT_AOUTHDR_ENTRY (abfd
, aouthdr_in
->entry
, (bfd_byte
*) aouthdr_out
->standard
.entry
);
661 PUT_AOUTHDR_TEXT_START (abfd
, aouthdr_in
->text_start
,
662 (bfd_byte
*) aouthdr_out
->standard
.text_start
);
664 #ifndef COFF_WITH_PEP64
665 /* PE32+ does not have data_start member! */
666 PUT_AOUTHDR_DATA_START (abfd
, aouthdr_in
->data_start
,
667 (bfd_byte
*) aouthdr_out
->standard
.data_start
);
670 PUT_OPTHDR_IMAGE_BASE (abfd
, extra
->ImageBase
,
671 (bfd_byte
*) aouthdr_out
->ImageBase
);
672 bfd_h_put_32 (abfd
, extra
->SectionAlignment
,
673 (bfd_byte
*) aouthdr_out
->SectionAlignment
);
674 bfd_h_put_32 (abfd
, extra
->FileAlignment
,
675 (bfd_byte
*) aouthdr_out
->FileAlignment
);
676 bfd_h_put_16 (abfd
, extra
->MajorOperatingSystemVersion
,
677 (bfd_byte
*) aouthdr_out
->MajorOperatingSystemVersion
);
678 bfd_h_put_16 (abfd
, extra
->MinorOperatingSystemVersion
,
679 (bfd_byte
*) aouthdr_out
->MinorOperatingSystemVersion
);
680 bfd_h_put_16 (abfd
, extra
->MajorImageVersion
,
681 (bfd_byte
*) aouthdr_out
->MajorImageVersion
);
682 bfd_h_put_16 (abfd
, extra
->MinorImageVersion
,
683 (bfd_byte
*) aouthdr_out
->MinorImageVersion
);
684 bfd_h_put_16 (abfd
, extra
->MajorSubsystemVersion
,
685 (bfd_byte
*) aouthdr_out
->MajorSubsystemVersion
);
686 bfd_h_put_16 (abfd
, extra
->MinorSubsystemVersion
,
687 (bfd_byte
*) aouthdr_out
->MinorSubsystemVersion
);
688 bfd_h_put_32 (abfd
, extra
->Reserved1
,
689 (bfd_byte
*) aouthdr_out
->Reserved1
);
690 bfd_h_put_32 (abfd
, extra
->SizeOfImage
,
691 (bfd_byte
*) aouthdr_out
->SizeOfImage
);
692 bfd_h_put_32 (abfd
, extra
->SizeOfHeaders
,
693 (bfd_byte
*) aouthdr_out
->SizeOfHeaders
);
694 bfd_h_put_32 (abfd
, extra
->CheckSum
,
695 (bfd_byte
*) aouthdr_out
->CheckSum
);
696 bfd_h_put_16 (abfd
, extra
->Subsystem
,
697 (bfd_byte
*) aouthdr_out
->Subsystem
);
698 bfd_h_put_16 (abfd
, extra
->DllCharacteristics
,
699 (bfd_byte
*) aouthdr_out
->DllCharacteristics
);
700 PUT_OPTHDR_SIZE_OF_STACK_RESERVE (abfd
, extra
->SizeOfStackReserve
,
701 (bfd_byte
*) aouthdr_out
->SizeOfStackReserve
);
702 PUT_OPTHDR_SIZE_OF_STACK_COMMIT (abfd
, extra
->SizeOfStackCommit
,
703 (bfd_byte
*) aouthdr_out
->SizeOfStackCommit
);
704 PUT_OPTHDR_SIZE_OF_HEAP_RESERVE (abfd
, extra
->SizeOfHeapReserve
,
705 (bfd_byte
*) aouthdr_out
->SizeOfHeapReserve
);
706 PUT_OPTHDR_SIZE_OF_HEAP_COMMIT (abfd
, extra
->SizeOfHeapCommit
,
707 (bfd_byte
*) aouthdr_out
->SizeOfHeapCommit
);
708 bfd_h_put_32 (abfd
, extra
->LoaderFlags
,
709 (bfd_byte
*) aouthdr_out
->LoaderFlags
);
710 bfd_h_put_32 (abfd
, extra
->NumberOfRvaAndSizes
,
711 (bfd_byte
*) aouthdr_out
->NumberOfRvaAndSizes
);
714 for (idx
=0; idx
< 16; idx
++)
716 bfd_h_put_32 (abfd
, extra
->DataDirectory
[idx
].VirtualAddress
,
717 (bfd_byte
*) aouthdr_out
->DataDirectory
[idx
][0]);
718 bfd_h_put_32 (abfd
, extra
->DataDirectory
[idx
].Size
,
719 (bfd_byte
*) aouthdr_out
->DataDirectory
[idx
][1]);
727 _bfd_pei_only_swap_filehdr_out (abfd
, in
, out
)
733 struct internal_filehdr
*filehdr_in
= (struct internal_filehdr
*)in
;
734 struct external_PEI_filehdr
*filehdr_out
= (struct external_PEI_filehdr
*)out
;
736 if (pe_data (abfd
)->has_reloc_section
)
737 filehdr_in
->f_flags
&= ~F_RELFLG
;
739 if (pe_data (abfd
)->dll
)
740 filehdr_in
->f_flags
|= F_DLL
;
742 filehdr_in
->pe
.e_magic
= DOSMAGIC
;
743 filehdr_in
->pe
.e_cblp
= 0x90;
744 filehdr_in
->pe
.e_cp
= 0x3;
745 filehdr_in
->pe
.e_crlc
= 0x0;
746 filehdr_in
->pe
.e_cparhdr
= 0x4;
747 filehdr_in
->pe
.e_minalloc
= 0x0;
748 filehdr_in
->pe
.e_maxalloc
= 0xffff;
749 filehdr_in
->pe
.e_ss
= 0x0;
750 filehdr_in
->pe
.e_sp
= 0xb8;
751 filehdr_in
->pe
.e_csum
= 0x0;
752 filehdr_in
->pe
.e_ip
= 0x0;
753 filehdr_in
->pe
.e_cs
= 0x0;
754 filehdr_in
->pe
.e_lfarlc
= 0x40;
755 filehdr_in
->pe
.e_ovno
= 0x0;
757 for (idx
=0; idx
< 4; idx
++)
758 filehdr_in
->pe
.e_res
[idx
] = 0x0;
760 filehdr_in
->pe
.e_oemid
= 0x0;
761 filehdr_in
->pe
.e_oeminfo
= 0x0;
763 for (idx
=0; idx
< 10; idx
++)
764 filehdr_in
->pe
.e_res2
[idx
] = 0x0;
766 filehdr_in
->pe
.e_lfanew
= 0x80;
768 /* this next collection of data are mostly just characters. It appears
769 to be constant within the headers put on NT exes */
770 filehdr_in
->pe
.dos_message
[0] = 0x0eba1f0e;
771 filehdr_in
->pe
.dos_message
[1] = 0xcd09b400;
772 filehdr_in
->pe
.dos_message
[2] = 0x4c01b821;
773 filehdr_in
->pe
.dos_message
[3] = 0x685421cd;
774 filehdr_in
->pe
.dos_message
[4] = 0x70207369;
775 filehdr_in
->pe
.dos_message
[5] = 0x72676f72;
776 filehdr_in
->pe
.dos_message
[6] = 0x63206d61;
777 filehdr_in
->pe
.dos_message
[7] = 0x6f6e6e61;
778 filehdr_in
->pe
.dos_message
[8] = 0x65622074;
779 filehdr_in
->pe
.dos_message
[9] = 0x6e757220;
780 filehdr_in
->pe
.dos_message
[10] = 0x206e6920;
781 filehdr_in
->pe
.dos_message
[11] = 0x20534f44;
782 filehdr_in
->pe
.dos_message
[12] = 0x65646f6d;
783 filehdr_in
->pe
.dos_message
[13] = 0x0a0d0d2e;
784 filehdr_in
->pe
.dos_message
[14] = 0x24;
785 filehdr_in
->pe
.dos_message
[15] = 0x0;
786 filehdr_in
->pe
.nt_signature
= NT_SIGNATURE
;
790 bfd_h_put_16(abfd
, filehdr_in
->f_magic
, (bfd_byte
*) filehdr_out
->f_magic
);
791 bfd_h_put_16(abfd
, filehdr_in
->f_nscns
, (bfd_byte
*) filehdr_out
->f_nscns
);
793 bfd_h_put_32(abfd
, time (0), (bfd_byte
*) filehdr_out
->f_timdat
);
794 PUT_FILEHDR_SYMPTR (abfd
, (bfd_vma
) filehdr_in
->f_symptr
,
795 (bfd_byte
*) filehdr_out
->f_symptr
);
796 bfd_h_put_32(abfd
, filehdr_in
->f_nsyms
, (bfd_byte
*) filehdr_out
->f_nsyms
);
797 bfd_h_put_16(abfd
, filehdr_in
->f_opthdr
, (bfd_byte
*) filehdr_out
->f_opthdr
);
798 bfd_h_put_16(abfd
, filehdr_in
->f_flags
, (bfd_byte
*) filehdr_out
->f_flags
);
800 /* put in extra dos header stuff. This data remains essentially
801 constant, it just has to be tacked on to the beginning of all exes
803 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_magic
, (bfd_byte
*) filehdr_out
->e_magic
);
804 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_cblp
, (bfd_byte
*) filehdr_out
->e_cblp
);
805 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_cp
, (bfd_byte
*) filehdr_out
->e_cp
);
806 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_crlc
, (bfd_byte
*) filehdr_out
->e_crlc
);
807 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_cparhdr
,
808 (bfd_byte
*) filehdr_out
->e_cparhdr
);
809 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_minalloc
,
810 (bfd_byte
*) filehdr_out
->e_minalloc
);
811 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_maxalloc
,
812 (bfd_byte
*) filehdr_out
->e_maxalloc
);
813 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_ss
, (bfd_byte
*) filehdr_out
->e_ss
);
814 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_sp
, (bfd_byte
*) filehdr_out
->e_sp
);
815 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_csum
, (bfd_byte
*) filehdr_out
->e_csum
);
816 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_ip
, (bfd_byte
*) filehdr_out
->e_ip
);
817 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_cs
, (bfd_byte
*) filehdr_out
->e_cs
);
818 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_lfarlc
, (bfd_byte
*) filehdr_out
->e_lfarlc
);
819 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_ovno
, (bfd_byte
*) filehdr_out
->e_ovno
);
822 for (idx
=0; idx
< 4; idx
++)
823 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_res
[idx
],
824 (bfd_byte
*) filehdr_out
->e_res
[idx
]);
826 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_oemid
, (bfd_byte
*) filehdr_out
->e_oemid
);
827 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_oeminfo
,
828 (bfd_byte
*) filehdr_out
->e_oeminfo
);
831 for (idx
=0; idx
< 10; idx
++)
832 bfd_h_put_16(abfd
, filehdr_in
->pe
.e_res2
[idx
],
833 (bfd_byte
*) filehdr_out
->e_res2
[idx
]);
835 bfd_h_put_32(abfd
, filehdr_in
->pe
.e_lfanew
, (bfd_byte
*) filehdr_out
->e_lfanew
);
839 for (idx
=0; idx
< 16; idx
++)
840 bfd_h_put_32(abfd
, filehdr_in
->pe
.dos_message
[idx
],
841 (bfd_byte
*) filehdr_out
->dos_message
[idx
]);
844 /* also put in the NT signature */
845 bfd_h_put_32(abfd
, filehdr_in
->pe
.nt_signature
,
846 (bfd_byte
*) filehdr_out
->nt_signature
);
855 _bfd_pe_only_swap_filehdr_out (abfd
, in
, out
)
860 struct internal_filehdr
*filehdr_in
= (struct internal_filehdr
*)in
;
861 FILHDR
*filehdr_out
= (FILHDR
*)out
;
863 bfd_h_put_16(abfd
, filehdr_in
->f_magic
, (bfd_byte
*) filehdr_out
->f_magic
);
864 bfd_h_put_16(abfd
, filehdr_in
->f_nscns
, (bfd_byte
*) filehdr_out
->f_nscns
);
865 bfd_h_put_32(abfd
, filehdr_in
->f_timdat
, (bfd_byte
*) filehdr_out
->f_timdat
);
866 PUT_FILEHDR_SYMPTR (abfd
, (bfd_vma
) filehdr_in
->f_symptr
,
867 (bfd_byte
*) filehdr_out
->f_symptr
);
868 bfd_h_put_32(abfd
, filehdr_in
->f_nsyms
, (bfd_byte
*) filehdr_out
->f_nsyms
);
869 bfd_h_put_16(abfd
, filehdr_in
->f_opthdr
, (bfd_byte
*) filehdr_out
->f_opthdr
);
870 bfd_h_put_16(abfd
, filehdr_in
->f_flags
, (bfd_byte
*) filehdr_out
->f_flags
);
876 _bfd_pei_swap_scnhdr_out (abfd
, in
, out
)
881 struct internal_scnhdr
*scnhdr_int
= (struct internal_scnhdr
*)in
;
882 SCNHDR
*scnhdr_ext
= (SCNHDR
*)out
;
883 unsigned int ret
= SCNHSZ
;
887 memcpy(scnhdr_ext
->s_name
, scnhdr_int
->s_name
, sizeof(scnhdr_int
->s_name
));
889 PUT_SCNHDR_VADDR (abfd
,
890 ((scnhdr_int
->s_vaddr
891 - pe_data(abfd
)->pe_opthdr
.ImageBase
)
893 (bfd_byte
*) scnhdr_ext
->s_vaddr
);
895 /* NT wants the size data to be rounded up to the next
896 NT_FILE_ALIGNMENT, but zero if it has no content (as in .bss,
899 if ((scnhdr_int
->s_flags
& IMAGE_SCN_CNT_UNINITIALIZED_DATA
) != 0)
901 ps
= scnhdr_int
->s_size
;
906 ps
= scnhdr_int
->s_paddr
;
907 ss
= scnhdr_int
->s_size
;
910 PUT_SCNHDR_SIZE (abfd
, ss
,
911 (bfd_byte
*) scnhdr_ext
->s_size
);
914 /* s_paddr in PE is really the virtual size. */
915 PUT_SCNHDR_PADDR (abfd
, ps
, (bfd_byte
*) scnhdr_ext
->s_paddr
);
917 PUT_SCNHDR_SCNPTR (abfd
, scnhdr_int
->s_scnptr
,
918 (bfd_byte
*) scnhdr_ext
->s_scnptr
);
919 PUT_SCNHDR_RELPTR (abfd
, scnhdr_int
->s_relptr
,
920 (bfd_byte
*) scnhdr_ext
->s_relptr
);
921 PUT_SCNHDR_LNNOPTR (abfd
, scnhdr_int
->s_lnnoptr
,
922 (bfd_byte
*) scnhdr_ext
->s_lnnoptr
);
924 /* Extra flags must be set when dealing with NT. All sections should also
925 have the IMAGE_SCN_MEM_READ (0x40000000) flag set. In addition, the
926 .text section must have IMAGE_SCN_MEM_EXECUTE (0x20000000) and the data
927 sections (.idata, .data, .bss, .CRT) must have IMAGE_SCN_MEM_WRITE set
928 (this is especially important when dealing with the .idata section since
929 the addresses for routines from .dlls must be overwritten). If .reloc
930 section data is ever generated, we must add IMAGE_SCN_MEM_DISCARDABLE
931 (0x02000000). Also, the resource data should also be read and
934 /* FIXME: alignment is also encoded in this field, at least on ppc (krk) */
935 /* FIXME: even worse, I don't see how to get the original alignment field*/
939 int flags
= scnhdr_int
->s_flags
;
940 bfd_h_put_32(abfd
, flags
, (bfd_byte
*) scnhdr_ext
->s_flags
);
943 if (coff_data (abfd
)->link_info
944 && ! coff_data (abfd
)->link_info
->relocateable
945 && ! coff_data (abfd
)->link_info
->shared
946 && strcmp (scnhdr_int
->s_name
, ".text") == 0)
948 /* By inference from looking at MS output, the 32 bit field
949 which is the combintion of the number_of_relocs and
950 number_of_linenos is used for the line number count in
951 executables. A 16-bit field won't do for cc1. The MS
952 document says that the number of relocs is zero for
953 executables, but the 17-th bit has been observed to be there.
954 Overflow is not an issue: a 4G-line program will overflow a
955 bunch of other fields long before this! */
956 bfd_h_put_16 (abfd
, scnhdr_int
->s_nlnno
& 0xffff,
957 (bfd_byte
*) scnhdr_ext
->s_nlnno
);
958 bfd_h_put_16 (abfd
, scnhdr_int
->s_nlnno
>> 16,
959 (bfd_byte
*) scnhdr_ext
->s_nreloc
);
963 if (scnhdr_int
->s_nlnno
<= 0xffff)
964 bfd_h_put_16 (abfd
, scnhdr_int
->s_nlnno
,
965 (bfd_byte
*) scnhdr_ext
->s_nlnno
);
968 (*_bfd_error_handler
) (_("%s: line number overflow: 0x%lx > 0xffff"),
969 bfd_get_filename (abfd
),
970 scnhdr_int
->s_nlnno
);
971 bfd_set_error (bfd_error_file_truncated
);
972 bfd_h_put_16 (abfd
, 0xffff, (bfd_byte
*) scnhdr_ext
->s_nlnno
);
975 if (scnhdr_int
->s_nreloc
<= 0xffff)
976 bfd_h_put_16 (abfd
, scnhdr_int
->s_nreloc
,
977 (bfd_byte
*) scnhdr_ext
->s_nreloc
);
980 (*_bfd_error_handler
) (_("%s: reloc overflow: 0x%lx > 0xffff"),
981 bfd_get_filename (abfd
),
982 scnhdr_int
->s_nreloc
);
983 bfd_set_error (bfd_error_file_truncated
);
984 bfd_h_put_16 (abfd
, 0xffff, (bfd_byte
*) scnhdr_ext
->s_nreloc
);
991 static char * dir_names
[IMAGE_NUMBEROF_DIRECTORY_ENTRIES
] =
993 N_ ("Export Directory [.edata (or where ever we found it)]"),
994 N_ ("Import Directory [parts of .idata]"),
995 N_ ("Resource Directory [.rsrc]"),
996 N_ ("Exception Directory [.pdata]"),
997 N_ ("Security Directory"),
998 N_ ("Base Relocation Directory [.reloc]"),
999 N_ ("Debug Directory"),
1000 N_ ("Description Directory"),
1001 N_ ("Special Directory"),
1002 N_ ("Thread Storage Directory [.tls]"),
1003 N_ ("Load Configuration Directory"),
1004 N_ ("Bound Import Directory"),
1005 N_ ("Import Address Table Directory"),
1006 N_ ("Delay Import Directory"),
1011 /**********************************************************************/
1012 #ifdef POWERPC_LE_PE
1013 /* The code for the PPC really falls in the "architecture dependent"
1014 category. However, it's not clear that anyone will ever care, so
1015 we're ignoring the issue for now; if/when PPC matters, some of this
1016 may need to go into peicode.h, or arguments passed to enable the
1017 PPC- specific code. */
1020 /**********************************************************************/
1022 pe_print_idata (abfd
, vfile
)
1026 FILE *file
= (FILE *) vfile
;
1031 #ifdef POWERPC_LE_PE
1032 asection
*rel_section
= bfd_get_section_by_name (abfd
, ".reldata");
1035 bfd_size_type datasize
;
1036 bfd_size_type dataoff
;
1037 bfd_size_type secsize
;
1041 pe_data_type
*pe
= pe_data (abfd
);
1042 struct internal_extra_pe_aouthdr
*extra
= &pe
->pe_opthdr
;
1046 addr
= extra
->DataDirectory
[1].VirtualAddress
;
1047 datasize
= extra
->DataDirectory
[1].Size
;
1049 if (addr
== 0 || datasize
== 0)
1052 addr
+= extra
->ImageBase
;
1054 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
1056 if (addr
>= section
->vma
1057 && addr
< section
->vma
+ bfd_section_size(abfd
,section
))
1061 if (section
== NULL
)
1064 _("\nThere is an import table, but the section containing it could not be found\n"));
1068 fprintf (file
, _("\nThere is an import table in %s at 0x%lx\n"),
1069 section
->name
, (unsigned long) addr
);
1071 dataoff
= addr
- section
->vma
;
1073 #ifdef POWERPC_LE_PE
1074 if (rel_section
!= 0 && bfd_section_size (abfd
, rel_section
) != 0)
1076 /* The toc address can be found by taking the starting address,
1077 which on the PPC locates a function descriptor. The
1078 descriptor consists of the function code starting address
1079 followed by the address of the toc. The starting address we
1080 get from the bfd, and the descriptor is supposed to be in the
1081 .reldata section. */
1083 bfd_vma loadable_toc_address
;
1084 bfd_vma toc_address
;
1085 bfd_vma start_address
;
1089 data
= (bfd_byte
*) bfd_malloc ((size_t) bfd_section_size (abfd
,
1091 if (data
== NULL
&& bfd_section_size (abfd
, rel_section
) != 0)
1094 bfd_get_section_contents (abfd
,
1097 bfd_section_size (abfd
, rel_section
));
1099 offset
= abfd
->start_address
- rel_section
->vma
;
1101 start_address
= bfd_get_32(abfd
, data
+offset
);
1102 loadable_toc_address
= bfd_get_32(abfd
, data
+offset
+4);
1103 toc_address
= loadable_toc_address
- 32768;
1106 _("\nFunction descriptor located at the start address: %04lx\n"),
1107 (unsigned long int) (abfd
->start_address
));
1109 _("\tcode-base %08lx toc (loadable/actual) %08lx/%08lx\n"),
1110 start_address
, loadable_toc_address
, toc_address
);
1115 _("\nNo reldata section! Function descriptor not decoded.\n"));
1120 _("\nThe Import Tables (interpreted %s section contents)\n"),
1123 _(" vma: Hint Time Forward DLL First\n"));
1125 _(" Table Stamp Chain Name Thunk\n"));
1127 secsize
= bfd_section_size (abfd
, section
);
1128 data
= (bfd_byte
*) bfd_malloc (secsize
);
1129 if (data
== NULL
&& secsize
!= 0)
1132 if (! bfd_get_section_contents (abfd
, section
, (PTR
) data
, 0, secsize
))
1135 adj
= section
->vma
- extra
->ImageBase
;
1137 for (i
= 0; i
< datasize
; i
+= onaline
)
1141 bfd_vma forward_chain
;
1143 bfd_vma first_thunk
;
1148 /* print (i + extra->DataDirectory[1].VirtualAddress) */
1149 fprintf (file
, " %08lx\t", (unsigned long) (i
+ adj
+ dataoff
));
1151 if (i
+ 20 > datasize
)
1157 hint_addr
= bfd_get_32 (abfd
, data
+ i
+ dataoff
);
1158 time_stamp
= bfd_get_32 (abfd
, data
+ i
+ 4 + dataoff
);
1159 forward_chain
= bfd_get_32 (abfd
, data
+ i
+ 8 + dataoff
);
1160 dll_name
= bfd_get_32 (abfd
, data
+ i
+ 12 + dataoff
);
1161 first_thunk
= bfd_get_32 (abfd
, data
+ i
+ 16 + dataoff
);
1163 fprintf (file
, "%08lx %08lx %08lx %08lx %08lx\n",
1170 if (hint_addr
== 0 && first_thunk
== 0)
1173 dll
= (char *) data
+ dll_name
- adj
;
1174 fprintf(file
, _("\n\tDLL Name: %s\n"), dll
);
1178 fprintf (file
, _("\tvma: Hint/Ord Member-Name\n"));
1180 idx
= hint_addr
- adj
;
1182 for (j
= 0; j
< datasize
; j
+= 4)
1184 unsigned long member
= bfd_get_32 (abfd
, data
+ idx
+ j
);
1188 if (member
& 0x80000000)
1189 fprintf (file
, "\t%04lx\t %4lu", member
,
1190 member
& 0x7fffffff);
1196 ordinal
= bfd_get_16 (abfd
, data
+ member
- adj
);
1197 member_name
= (char *) data
+ member
- adj
+ 2;
1198 fprintf (file
, "\t%04lx\t %4d %s",
1199 member
, ordinal
, member_name
);
1202 /* If the time stamp is not zero, the import address
1203 table holds actual addresses. */
1206 && first_thunk
!= hint_addr
)
1207 fprintf (file
, "\t%04lx",
1208 bfd_get_32 (abfd
, data
+ first_thunk
- adj
+ j
));
1210 fprintf (file
, "\n");
1214 if (hint_addr
!= first_thunk
&& time_stamp
== 0)
1219 idx2
= first_thunk
- adj
;
1221 for (j
= 0; j
< datasize
; j
+= 4)
1225 bfd_vma hint_member
= 0;
1229 hint_member
= bfd_get_32 (abfd
, data
+ idx
+ j
);
1230 iat_member
= bfd_get_32 (abfd
, data
+ idx2
+ j
);
1232 if (hint_addr
== 0 && iat_member
== 0)
1235 if (hint_addr
== 0 || hint_member
!= iat_member
)
1240 _("\tThe Import Address Table (difference found)\n"));
1241 fprintf(file
, _("\tvma: Hint/Ord Member-Name\n"));
1244 if (iat_member
== 0)
1247 _("\t>>> Ran out of IAT members!\n"));
1251 ordinal
= bfd_get_16(abfd
,
1252 data
+ iat_member
- adj
);
1253 member_name
= (char *) data
+ iat_member
- adj
+ 2;
1254 fprintf(file
, "\t%04lx\t %4d %s\n",
1255 iat_member
, ordinal
, member_name
);
1259 if (hint_addr
!= 0 && hint_member
== 0)
1265 _("\tThe Import Address Table is identical\n"));
1269 fprintf(file
, "\n");
1279 pe_print_edata (abfd
, vfile
)
1283 FILE *file
= (FILE *) vfile
;
1287 bfd_size_type datasize
;
1288 bfd_size_type dataoff
;
1294 long export_flags
; /* reserved - should be zero */
1298 bfd_vma name
; /* rva - relative to image base */
1299 long base
; /* ordinal base */
1300 unsigned long num_functions
; /* Number in the export address table */
1301 unsigned long num_names
; /* Number in the name pointer table */
1302 bfd_vma eat_addr
; /* rva to the export address table */
1303 bfd_vma npt_addr
; /* rva to the Export Name Pointer Table */
1304 bfd_vma ot_addr
; /* rva to the Ordinal Table */
1307 pe_data_type
*pe
= pe_data (abfd
);
1308 struct internal_extra_pe_aouthdr
*extra
= &pe
->pe_opthdr
;
1312 addr
= extra
->DataDirectory
[0].VirtualAddress
;
1313 datasize
= extra
->DataDirectory
[0].Size
;
1315 if (addr
== 0 || datasize
== 0)
1318 addr
+= extra
->ImageBase
;
1319 for (section
= abfd
->sections
; section
!= NULL
; section
= section
->next
)
1321 if (addr
>= section
->vma
1322 && addr
< section
->vma
+ bfd_section_size (abfd
, section
))
1326 if (section
== NULL
)
1329 _("\nThere is an export table, but the section containing it could not be found\n"));
1333 fprintf (file
, _("\nThere is an export table in %s at 0x%lx\n"),
1334 section
->name
, (unsigned long) addr
);
1336 dataoff
= addr
- section
->vma
;
1338 data
= (bfd_byte
*) bfd_malloc (datasize
);
1342 if (! bfd_get_section_contents (abfd
, section
, (PTR
) data
, dataoff
,
1346 /* Go get Export Directory Table */
1347 edt
.export_flags
= bfd_get_32(abfd
, data
+0);
1348 edt
.time_stamp
= bfd_get_32(abfd
, data
+4);
1349 edt
.major_ver
= bfd_get_16(abfd
, data
+8);
1350 edt
.minor_ver
= bfd_get_16(abfd
, data
+10);
1351 edt
.name
= bfd_get_32(abfd
, data
+12);
1352 edt
.base
= bfd_get_32(abfd
, data
+16);
1353 edt
.num_functions
= bfd_get_32(abfd
, data
+20);
1354 edt
.num_names
= bfd_get_32(abfd
, data
+24);
1355 edt
.eat_addr
= bfd_get_32(abfd
, data
+28);
1356 edt
.npt_addr
= bfd_get_32(abfd
, data
+32);
1357 edt
.ot_addr
= bfd_get_32(abfd
, data
+36);
1359 adj
= section
->vma
- extra
->ImageBase
+ dataoff
;
1361 /* Dump the EDT first first */
1363 _("\nThe Export Tables (interpreted %s section contents)\n\n"),
1367 _("Export Flags \t\t\t%lx\n"), (unsigned long) edt
.export_flags
);
1370 _("Time/Date stamp \t\t%lx\n"), (unsigned long) edt
.time_stamp
);
1373 _("Major/Minor \t\t\t%d/%d\n"), edt
.major_ver
, edt
.minor_ver
);
1376 _("Name \t\t\t\t"));
1377 fprintf_vma (file
, edt
.name
);
1379 " %s\n", data
+ edt
.name
- adj
);
1382 _("Ordinal Base \t\t\t%ld\n"), edt
.base
);
1388 _("\tExport Address Table \t\t%08lx\n"),
1392 _("\t[Name Pointer/Ordinal] Table\t%08lx\n"), edt
.num_names
);
1395 _("Table Addresses\n"));
1398 _("\tExport Address Table \t\t"));
1399 fprintf_vma (file
, edt
.eat_addr
);
1400 fprintf (file
, "\n");
1403 _("\tName Pointer Table \t\t"));
1404 fprintf_vma (file
, edt
.npt_addr
);
1405 fprintf (file
, "\n");
1408 _("\tOrdinal Table \t\t\t"));
1409 fprintf_vma (file
, edt
.ot_addr
);
1410 fprintf (file
, "\n");
1413 /* The next table to find is the Export Address Table. It's basically
1414 a list of pointers that either locate a function in this dll, or
1415 forward the call to another dll. Something like:
1420 } export_address_table_entry;
1424 _("\nExport Address Table -- Ordinal Base %ld\n"),
1427 for (i
= 0; i
< edt
.num_functions
; ++i
)
1429 bfd_vma eat_member
= bfd_get_32 (abfd
,
1430 data
+ edt
.eat_addr
+ (i
* 4) - adj
);
1431 bfd_vma eat_actual
= eat_member
;
1432 bfd_vma edata_start
= bfd_get_section_vma (abfd
, section
);
1433 bfd_vma edata_end
= edata_start
+ datasize
;
1435 if (eat_member
== 0)
1438 if (edata_start
< eat_actual
&& eat_actual
< edata_end
)
1440 /* this rva is to a name (forwarding function) in our section */
1441 /* Should locate a function descriptor */
1443 "\t[%4ld] +base[%4ld] %04lx %s -- %s\n",
1444 (long) i
, (long) (i
+ edt
.base
), eat_member
,
1445 _("Forwarder RVA"), data
+ eat_member
- adj
);
1449 /* Should locate a function descriptor in the reldata section */
1451 "\t[%4ld] +base[%4ld] %04lx %s\n",
1452 (long) i
, (long) (i
+ edt
.base
), eat_member
,
1457 /* The Export Name Pointer Table is paired with the Export Ordinal Table */
1458 /* Dump them in parallel for clarity */
1460 _("\n[Ordinal/Name Pointer] Table\n"));
1462 for (i
= 0; i
< edt
.num_names
; ++i
)
1464 bfd_vma name_ptr
= bfd_get_32(abfd
,
1469 char *name
= (char *) data
+ name_ptr
- adj
;
1471 bfd_vma ord
= bfd_get_16(abfd
,
1476 "\t[%4ld] %s\n", (long) ord
, name
);
1485 /* This really is architecture dependent. On IA-64, a .pdata entry
1486 consists of three dwords containing relative virtual addresses that
1487 specify the start and end address of the code range the entry
1488 covers and the address of the corresponding unwind info data. */
1490 pe_print_pdata (abfd
, vfile
)
1494 #ifdef COFF_WITH_PEP64
1495 # define PDATA_ROW_SIZE (3*8)
1497 # define PDATA_ROW_SIZE (5*4)
1499 FILE *file
= (FILE *) vfile
;
1501 asection
*section
= bfd_get_section_by_name (abfd
, ".pdata");
1502 bfd_size_type datasize
= 0;
1504 bfd_size_type start
, stop
;
1505 int onaline
= PDATA_ROW_SIZE
;
1508 || coff_section_data (abfd
, section
) == NULL
1509 || pei_section_data (abfd
, section
) == NULL
)
1512 stop
= pei_section_data (abfd
, section
)->virt_size
;
1513 if ((stop
% onaline
) != 0)
1514 fprintf (file
, _("Warning, .pdata section size (%ld) is not a multiple of %d\n"),
1515 (long)stop
, onaline
);
1518 _("\nThe Function Table (interpreted .pdata section contents)\n"));
1519 #ifdef COFF_WITH_PEP64
1521 _(" vma:\t\t\tBegin Address End Address Unwind Info\n"));
1524 _(" vma:\t\tBegin End EH EH PrologEnd Exception\n"));
1526 _(" \t\tAddress Address Handler Data Address Mask\n"));
1529 if (bfd_section_size (abfd
, section
) == 0)
1532 data
= (bfd_byte
*) bfd_malloc ((size_t) bfd_section_size (abfd
, section
));
1533 datasize
= bfd_section_size (abfd
, section
);
1534 if (data
== NULL
&& datasize
!= 0)
1537 bfd_get_section_contents (abfd
,
1540 bfd_section_size (abfd
, section
));
1544 for (i
= start
; i
< stop
; i
+= onaline
)
1550 bfd_vma prolog_end_addr
;
1553 if (i
+ PDATA_ROW_SIZE
> stop
)
1556 begin_addr
= GET_PDATA_ENTRY(abfd
, data
+i
);
1557 end_addr
= GET_PDATA_ENTRY(abfd
, data
+i
+4);
1558 eh_handler
= GET_PDATA_ENTRY(abfd
, data
+i
+8);
1559 eh_data
= GET_PDATA_ENTRY(abfd
, data
+i
+12);
1560 prolog_end_addr
= GET_PDATA_ENTRY(abfd
, data
+i
+16);
1562 if (begin_addr
== 0 && end_addr
== 0 && eh_handler
== 0
1563 && eh_data
== 0 && prolog_end_addr
== 0)
1565 /* We are probably into the padding of the section now. */
1569 em_data
= ((eh_handler
& 0x1) << 2) | (prolog_end_addr
& 0x3);
1570 eh_handler
&= ~ (bfd_vma
) 0x3;
1571 prolog_end_addr
&= ~ (bfd_vma
) 0x3;
1574 fprintf_vma (file
, i
+ section
->vma
); fputc ('\t', file
);
1575 fprintf_vma (file
, begin_addr
); fputc (' ', file
);
1576 fprintf_vma (file
, end_addr
); fputc (' ', file
);
1577 fprintf_vma (file
, eh_handler
);
1578 #ifndef COFF_WITH_PEP64
1580 fprintf_vma (file
, eh_data
); fputc (' ', file
);
1581 fprintf_vma (file
, prolog_end_addr
);
1582 fprintf (file
, " %x", em_data
);
1585 #ifdef POWERPC_LE_PE
1586 if (eh_handler
== 0 && eh_data
!= 0)
1588 /* Special bits here, although the meaning may */
1589 /* be a little mysterious. The only one I know */
1590 /* for sure is 0x03. */
1591 /* Code Significance */
1593 /* 0x01 Register Save Millicode */
1594 /* 0x02 Register Restore Millicode */
1595 /* 0x03 Glue Code Sequence */
1599 fprintf(file
, _(" Register save millicode"));
1602 fprintf(file
, _(" Register restore millicode"));
1605 fprintf(file
, _(" Glue code sequence"));
1612 fprintf(file
, "\n");
1620 #define IMAGE_REL_BASED_HIGHADJ 4
1621 static const char * const tbl
[] =
1635 "UNKNOWN", /* MUST be last */
1639 pe_print_reloc (abfd
, vfile
)
1643 FILE *file
= (FILE *) vfile
;
1645 asection
*section
= bfd_get_section_by_name (abfd
, ".reloc");
1646 bfd_size_type datasize
= 0;
1648 bfd_size_type start
, stop
;
1650 if (section
== NULL
)
1653 if (bfd_section_size (abfd
, section
) == 0)
1657 _("\n\nPE File Base Relocations (interpreted .reloc section contents)\n"));
1659 data
= (bfd_byte
*) bfd_malloc ((size_t) bfd_section_size (abfd
, section
));
1660 datasize
= bfd_section_size (abfd
, section
);
1661 if (data
== NULL
&& datasize
!= 0)
1664 bfd_get_section_contents (abfd
,
1667 bfd_section_size (abfd
, section
));
1671 stop
= bfd_section_size (abfd
, section
);
1673 for (i
= start
; i
< stop
;)
1676 bfd_vma virtual_address
;
1679 /* The .reloc section is a sequence of blocks, with a header consisting
1680 of two 32 bit quantities, followed by a number of 16 bit entries */
1682 virtual_address
= bfd_get_32(abfd
, data
+i
);
1683 size
= bfd_get_32(abfd
, data
+i
+4);
1684 number
= (size
- 8) / 2;
1692 _("\nVirtual Address: %08lx Chunk size %ld (0x%lx) Number of fixups %ld\n"),
1693 virtual_address
, size
, size
, number
);
1695 for (j
= 0; j
< number
; ++j
)
1697 unsigned short e
= bfd_get_16 (abfd
, data
+ i
+ 8 + j
* 2);
1698 unsigned int t
= (e
& 0xF000) >> 12;
1699 int off
= e
& 0x0FFF;
1701 if (t
>= sizeof (tbl
) / sizeof (tbl
[0]))
1702 t
= (sizeof (tbl
) / sizeof (tbl
[0])) - 1;
1705 _("\treloc %4d offset %4x [%4lx] %s"),
1706 j
, off
, (long) (off
+ virtual_address
), tbl
[t
]);
1708 /* HIGHADJ takes an argument, - the next record *is* the
1709 low 16 bits of addend. */
1710 if (t
== IMAGE_REL_BASED_HIGHADJ
)
1712 fprintf (file
, " (%4x)",
1714 bfd_get_16 (abfd
, data
+ i
+ 8 + j
* 2 + 2)));
1718 fprintf (file
, "\n");
1728 /* Print out the program headers. */
1731 _bfd_pe_print_private_bfd_data_common (abfd
, vfile
)
1735 FILE *file
= (FILE *) vfile
;
1737 pe_data_type
*pe
= pe_data (abfd
);
1738 struct internal_extra_pe_aouthdr
*i
= &pe
->pe_opthdr
;
1739 const char *subsystem_name
= NULL
;
1741 /* The MS dumpbin program reportedly ands with 0xff0f before
1742 printing the characteristics field. Not sure why. No reason to
1744 fprintf (file
, _("\nCharacteristics 0x%x\n"), pe
->real_flags
);
1746 #define PF(x, y) if (pe->real_flags & x) { fprintf (file, "\t%s\n", y); }
1747 PF (F_RELFLG
, "relocations stripped");
1748 PF (F_EXEC
, "executable");
1749 PF (F_LNNO
, "line numbers stripped");
1750 PF (F_LSYMS
, "symbols stripped");
1751 PF (0x80, "little endian");
1752 PF (F_AR32WR
, "32 bit words");
1753 PF (0x200, "debugging information removed");
1754 PF (0x1000, "system file");
1756 PF (0x8000, "big endian");
1759 /* ctime implies '\n'. */
1760 fprintf (file
, "\nTime/Date\t\t%s", ctime (&pe
->coff
.timestamp
));
1761 fprintf (file
,"\nImageBase\t\t");
1762 fprintf_vma (file
, i
->ImageBase
);
1763 fprintf (file
,"\nSectionAlignment\t");
1764 fprintf_vma (file
, i
->SectionAlignment
);
1765 fprintf (file
,"\nFileAlignment\t\t");
1766 fprintf_vma (file
, i
->FileAlignment
);
1767 fprintf (file
,"\nMajorOSystemVersion\t%d\n", i
->MajorOperatingSystemVersion
);
1768 fprintf (file
,"MinorOSystemVersion\t%d\n", i
->MinorOperatingSystemVersion
);
1769 fprintf (file
,"MajorImageVersion\t%d\n", i
->MajorImageVersion
);
1770 fprintf (file
,"MinorImageVersion\t%d\n", i
->MinorImageVersion
);
1771 fprintf (file
,"MajorSubsystemVersion\t%d\n", i
->MajorSubsystemVersion
);
1772 fprintf (file
,"MinorSubsystemVersion\t%d\n", i
->MinorSubsystemVersion
);
1773 fprintf (file
,"Win32Version\t\t%08lx\n", i
->Reserved1
);
1774 fprintf (file
,"SizeOfImage\t\t%08lx\n", i
->SizeOfImage
);
1775 fprintf (file
,"SizeOfHeaders\t\t%08lx\n", i
->SizeOfHeaders
);
1776 fprintf (file
,"CheckSum\t\t%08lx\n", i
->CheckSum
);
1777 switch (i
->Subsystem
)
1779 case IMAGE_SUBSYSTEM_UNKNOWN
:
1780 subsystem_name
= "unspecified";
1782 case IMAGE_SUBSYSTEM_NATIVE
:
1783 subsystem_name
= "NT native";
1785 case IMAGE_SUBSYSTEM_WINDOWS_GUI
:
1786 subsystem_name
= "Windows GUI";
1788 case IMAGE_SUBSYSTEM_WINDOWS_CUI
:
1789 subsystem_name
= "Windows CUI";
1791 case IMAGE_SUBSYSTEM_POSIX_CUI
:
1792 subsystem_name
= "POSIX CUI";
1794 case IMAGE_SUBSYSTEM_WINDOWS_CE_GUI
:
1795 subsystem_name
= "Wince CUI";
1797 case IMAGE_SUBSYSTEM_EFI_APPLICATION
:
1798 subsystem_name
= "EFI application";
1800 case IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER
:
1801 subsystem_name
= "EFI boot service driver";
1803 case IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER
:
1804 subsystem_name
= "EFI runtime driver";
1807 fprintf (file
,"Subsystem\t\t%08x", i
->Subsystem
);
1809 fprintf (file
, "\t(%s)", subsystem_name
);
1810 fprintf (file
,"\nDllCharacteristics\t%08x\n", i
->DllCharacteristics
);
1811 fprintf (file
,"SizeOfStackReserve\t");
1812 fprintf_vma (file
, i
->SizeOfStackReserve
);
1813 fprintf (file
,"\nSizeOfStackCommit\t");
1814 fprintf_vma (file
, i
->SizeOfStackCommit
);
1815 fprintf (file
,"\nSizeOfHeapReserve\t");
1816 fprintf_vma (file
, i
->SizeOfHeapReserve
);
1817 fprintf (file
,"\nSizeOfHeapCommit\t");
1818 fprintf_vma (file
, i
->SizeOfHeapCommit
);
1819 fprintf (file
,"\nLoaderFlags\t\t%08lx\n", i
->LoaderFlags
);
1820 fprintf (file
,"NumberOfRvaAndSizes\t%08lx\n", i
->NumberOfRvaAndSizes
);
1822 fprintf (file
,"\nThe Data Directory\n");
1823 for (j
= 0; j
< IMAGE_NUMBEROF_DIRECTORY_ENTRIES
; j
++)
1825 fprintf (file
, "Entry %1x ", j
);
1826 fprintf_vma (file
, i
->DataDirectory
[j
].VirtualAddress
);
1827 fprintf (file
, " %08lx ", i
->DataDirectory
[j
].Size
);
1828 fprintf (file
, "%s\n", dir_names
[j
]);
1831 pe_print_idata (abfd
, vfile
);
1832 pe_print_edata (abfd
, vfile
);
1833 pe_print_pdata (abfd
, vfile
);
1834 pe_print_reloc (abfd
, vfile
);
1839 /* Copy any private info we understand from the input bfd
1840 to the output bfd. */
1843 _bfd_pe_bfd_copy_private_bfd_data_common (ibfd
, obfd
)
1846 /* One day we may try to grok other private data. */
1847 if (ibfd
->xvec
->flavour
!= bfd_target_coff_flavour
1848 || obfd
->xvec
->flavour
!= bfd_target_coff_flavour
)
1851 pe_data (obfd
)->pe_opthdr
= pe_data (ibfd
)->pe_opthdr
;
1852 pe_data (obfd
)->dll
= pe_data (ibfd
)->dll
;
1854 /* for strip: if we removed .reloc, we'll make a real mess of things
1855 if we don't remove this entry as well. */
1856 if (! pe_data (obfd
)->has_reloc_section
)
1858 pe_data(obfd
)->pe_opthdr
.DataDirectory
[5].VirtualAddress
= 0;
1859 pe_data(obfd
)->pe_opthdr
.DataDirectory
[5].Size
= 0;
1864 /* Copy private section data. */
1866 _bfd_pe_bfd_copy_private_section_data (ibfd
, isec
, obfd
, osec
)
1872 if (bfd_get_flavour (ibfd
) != bfd_target_coff_flavour
1873 || bfd_get_flavour (obfd
) != bfd_target_coff_flavour
)
1876 if (coff_section_data (ibfd
, isec
) != NULL
1877 && pei_section_data (ibfd
, isec
) != NULL
)
1879 if (coff_section_data (obfd
, osec
) == NULL
)
1882 (PTR
) bfd_zalloc (obfd
, sizeof (struct coff_section_tdata
));
1883 if (osec
->used_by_bfd
== NULL
)
1886 if (pei_section_data (obfd
, osec
) == NULL
)
1888 coff_section_data (obfd
, osec
)->tdata
=
1889 (PTR
) bfd_zalloc (obfd
, sizeof (struct pei_section_tdata
));
1890 if (coff_section_data (obfd
, osec
)->tdata
== NULL
)
1893 pei_section_data (obfd
, osec
)->virt_size
=
1894 pei_section_data (ibfd
, isec
)->virt_size
;
1895 pei_section_data (obfd
, osec
)->pe_flags
=
1896 pei_section_data (ibfd
, isec
)->pe_flags
;
1903 _bfd_pe_get_symbol_info (abfd
, symbol
, ret
)
1908 coff_get_symbol_info (abfd
, symbol
, ret
);
1910 if (pe_data (abfd
) != NULL
1911 && ((symbol
->flags
& BSF_DEBUGGING
) == 0
1912 || (symbol
->flags
& BSF_DEBUGGING_RELOC
) != 0)
1913 && ! bfd_is_abs_section (symbol
->section
))
1914 ret
->value
+= pe_data (abfd
)->pe_opthdr
.ImageBase
;
1917 /* Handle the .idata section and other things that need symbol table
1921 _bfd_pei_final_link_postscript (abfd
, pfinfo
)
1923 struct coff_final_link_info
*pfinfo
;
1925 struct coff_link_hash_entry
*h1
;
1926 struct bfd_link_info
*info
= pfinfo
->info
;
1928 /* There are a few fields that need to be filled in now while we
1929 have symbol table access.
1931 The .idata subsections aren't directly available as sections, but
1932 they are in the symbol table, so get them from there. */
1934 /* The import directory. This is the address of .idata$2, with size
1935 of .idata$2 + .idata$3. */
1936 h1
= coff_link_hash_lookup (coff_hash_table (info
),
1937 ".idata$2", false, false, true);
1940 pe_data(abfd
)->pe_opthdr
.DataDirectory
[1].VirtualAddress
=
1941 (h1
->root
.u
.def
.value
1942 + h1
->root
.u
.def
.section
->output_section
->vma
1943 + h1
->root
.u
.def
.section
->output_offset
);
1944 h1
= coff_link_hash_lookup (coff_hash_table (info
),
1945 ".idata$4", false, false, true);
1946 pe_data (abfd
)->pe_opthdr
.DataDirectory
[1].Size
=
1947 ((h1
->root
.u
.def
.value
1948 + h1
->root
.u
.def
.section
->output_section
->vma
1949 + h1
->root
.u
.def
.section
->output_offset
)
1950 - pe_data(abfd
)->pe_opthdr
.DataDirectory
[1].VirtualAddress
);
1952 /* The import address table. This is the size/address of
1954 h1
= coff_link_hash_lookup (coff_hash_table (info
),
1955 ".idata$5", false, false, true);
1956 pe_data (abfd
)->pe_opthdr
.DataDirectory
[12].VirtualAddress
=
1957 (h1
->root
.u
.def
.value
1958 + h1
->root
.u
.def
.section
->output_section
->vma
1959 + h1
->root
.u
.def
.section
->output_offset
);
1960 h1
= coff_link_hash_lookup (coff_hash_table (info
),
1961 ".idata$6", false, false, true);
1962 pe_data (abfd
)->pe_opthdr
.DataDirectory
[12].Size
=
1963 ((h1
->root
.u
.def
.value
1964 + h1
->root
.u
.def
.section
->output_section
->vma
1965 + h1
->root
.u
.def
.section
->output_offset
)
1966 - pe_data(abfd
)->pe_opthdr
.DataDirectory
[12].VirtualAddress
);
1969 /* If we couldn't find idata$2, we either have an excessively
1970 trivial program or are in DEEP trouble; we have to assume trivial