| 1 | /* Support for the generic parts of PE/PEI; the common executable parts.
|
|---|
| 2 | Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
|
|---|
| 3 | Free Software Foundation, Inc.
|
|---|
| 4 | Written by Cygnus Solutions.
|
|---|
| 5 |
|
|---|
| 6 | This file is part of BFD, the Binary File Descriptor library.
|
|---|
| 7 |
|
|---|
| 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.
|
|---|
| 12 |
|
|---|
| 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.
|
|---|
| 17 |
|
|---|
| 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. */
|
|---|
| 21 |
|
|---|
| 22 | /* Most of this hacked by Steve Chamberlain <sac@cygnus.com>.
|
|---|
| 23 |
|
|---|
| 24 | PE/PEI rearrangement (and code added): Donn Terry
|
|---|
| 25 | Softway Systems, Inc. */
|
|---|
| 26 |
|
|---|
| 27 | /* Hey look, some documentation [and in a place you expect to find it]!
|
|---|
| 28 |
|
|---|
| 29 | The main reference for the pei format is "Microsoft Portable Executable
|
|---|
| 30 | and Common Object File Format Specification 4.1". Get it if you need to
|
|---|
| 31 | do some serious hacking on this code.
|
|---|
| 32 |
|
|---|
| 33 | Another reference:
|
|---|
| 34 | "Peering Inside the PE: A Tour of the Win32 Portable Executable
|
|---|
| 35 | File Format", MSJ 1994, Volume 9.
|
|---|
| 36 |
|
|---|
| 37 | The *sole* difference between the pe format and the pei format is that the
|
|---|
| 38 | latter has an MSDOS 2.0 .exe header on the front that prints the message
|
|---|
| 39 | "This app must be run under Windows." (or some such).
|
|---|
| 40 | (FIXME: Whether that statement is *really* true or not is unknown.
|
|---|
| 41 | Are there more subtle differences between pe and pei formats?
|
|---|
| 42 | For now assume there aren't. If you find one, then for God sakes
|
|---|
| 43 | document it here!)
|
|---|
| 44 |
|
|---|
| 45 | The Microsoft docs use the word "image" instead of "executable" because
|
|---|
| 46 | the former can also refer to a DLL (shared library). Confusion can arise
|
|---|
| 47 | because the `i' in `pei' also refers to "image". The `pe' format can
|
|---|
| 48 | also create images (i.e. executables), it's just that to run on a win32
|
|---|
| 49 | system you need to use the pei format.
|
|---|
| 50 |
|
|---|
| 51 | FIXME: Please add more docs here so the next poor fool that has to hack
|
|---|
| 52 | on this code has a chance of getting something accomplished without
|
|---|
| 53 | wasting too much time. */
|
|---|
| 54 |
|
|---|
| 55 | /* This expands into COFF_WITH_pe or COFF_WITH_pep depending on whether
|
|---|
| 56 | we're compiling for straight PE or PE+. */
|
|---|
| 57 | #define COFF_WITH_XX
|
|---|
| 58 |
|
|---|
| 59 | #include "bfd.h"
|
|---|
| 60 | #include "sysdep.h"
|
|---|
| 61 | #include "libbfd.h"
|
|---|
| 62 | #include "coff/internal.h"
|
|---|
| 63 |
|
|---|
| 64 | /* NOTE: it's strange to be including an architecture specific header
|
|---|
| 65 | in what's supposed to be general (to PE/PEI) code. However, that's
|
|---|
| 66 | where the definitions are, and they don't vary per architecture
|
|---|
| 67 | within PE/PEI, so we get them from there. FIXME: The lack of
|
|---|
| 68 | variance is an assumption which may prove to be incorrect if new
|
|---|
| 69 | PE/PEI targets are created. */
|
|---|
| 70 | #ifdef COFF_WITH_pep
|
|---|
| 71 | # include "coff/ia64.h"
|
|---|
| 72 | #else
|
|---|
| 73 | # include "coff/i386.h"
|
|---|
| 74 | #endif
|
|---|
| 75 |
|
|---|
| 76 | #include "coff/pe.h"
|
|---|
| 77 | #include "libcoff.h"
|
|---|
| 78 | #include "libpei.h"
|
|---|
| 79 |
|
|---|
| 80 | #ifdef COFF_WITH_pep
|
|---|
| 81 | # undef AOUTSZ
|
|---|
| 82 | # define AOUTSZ PEPAOUTSZ
|
|---|
| 83 | # define PEAOUTHDR PEPAOUTHDR
|
|---|
| 84 | #endif
|
|---|
| 85 |
|
|---|
| 86 | /* FIXME: This file has various tests of POWERPC_LE_PE. Those tests
|
|---|
| 87 | worked when the code was in peicode.h, but no longer work now that
|
|---|
| 88 | the code is in peigen.c. PowerPC NT is said to be dead. If
|
|---|
| 89 | anybody wants to revive the code, you will have to figure out how
|
|---|
| 90 | to handle those issues. */
|
|---|
| 91 |
|
|---|
| 92 | static void add_data_entry
|
|---|
| 93 | PARAMS ((bfd *, struct internal_extra_pe_aouthdr *, int, char *, bfd_vma));
|
|---|
| 94 | static bfd_boolean pe_print_pdata PARAMS ((bfd *, PTR));
|
|---|
| 95 | static bfd_boolean pe_print_reloc PARAMS ((bfd *, PTR));
|
|---|
| 96 | static bfd_boolean pe_print_idata PARAMS ((bfd *, PTR));
|
|---|
| 97 | static bfd_boolean pe_print_edata PARAMS ((bfd *, PTR));
|
|---|
| 98 | |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 | void
|
|---|
| 102 | _bfd_XXi_swap_sym_in (abfd, ext1, in1)
|
|---|
| 103 | bfd *abfd;
|
|---|
| 104 | PTR ext1;
|
|---|
| 105 | PTR in1;
|
|---|
| 106 | {
|
|---|
| 107 | SYMENT *ext = (SYMENT *) ext1;
|
|---|
| 108 | struct internal_syment *in = (struct internal_syment *) in1;
|
|---|
| 109 |
|
|---|
| 110 | if (ext->e.e_name[0] == 0)
|
|---|
| 111 | {
|
|---|
| 112 | in->_n._n_n._n_zeroes = 0;
|
|---|
| 113 | in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset);
|
|---|
| 114 | }
|
|---|
| 115 | else
|
|---|
| 116 | memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN);
|
|---|
| 117 |
|
|---|
| 118 | in->n_value = H_GET_32 (abfd, ext->e_value);
|
|---|
| 119 | in->n_scnum = H_GET_16 (abfd, ext->e_scnum);
|
|---|
| 120 |
|
|---|
| 121 | if (sizeof (ext->e_type) == 2)
|
|---|
| 122 | in->n_type = H_GET_16 (abfd, ext->e_type);
|
|---|
| 123 | else
|
|---|
| 124 | in->n_type = H_GET_32 (abfd, ext->e_type);
|
|---|
| 125 |
|
|---|
| 126 | in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
|
|---|
| 127 | in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
|
|---|
| 128 |
|
|---|
| 129 | #ifndef STRICT_PE_FORMAT
|
|---|
| 130 | /* This is for Gnu-created DLLs. */
|
|---|
| 131 |
|
|---|
| 132 | /* The section symbols for the .idata$ sections have class 0x68
|
|---|
| 133 | (C_SECTION), which MS documentation indicates is a section
|
|---|
| 134 | symbol. Unfortunately, the value field in the symbol is simply a
|
|---|
| 135 | copy of the .idata section's flags rather than something useful.
|
|---|
| 136 | When these symbols are encountered, change the value to 0 so that
|
|---|
| 137 | they will be handled somewhat correctly in the bfd code. */
|
|---|
| 138 | if (in->n_sclass == C_SECTION)
|
|---|
| 139 | {
|
|---|
| 140 | in->n_value = 0x0;
|
|---|
| 141 |
|
|---|
| 142 | #if 0
|
|---|
| 143 | /* FIXME: This is clearly wrong. The problem seems to be that
|
|---|
| 144 | undefined C_SECTION symbols appear in the first object of a
|
|---|
| 145 | MS generated .lib file, and the symbols are not defined
|
|---|
| 146 | anywhere. */
|
|---|
| 147 | in->n_scnum = 1;
|
|---|
| 148 |
|
|---|
| 149 | /* I have tried setting the class to 3 and using the following
|
|---|
| 150 | to set the section number. This will put the address of the
|
|---|
| 151 | pointer to the string kernel32.dll at addresses 0 and 0x10
|
|---|
| 152 | off start of idata section which is not correct. */
|
|---|
| 153 | #if 0
|
|---|
| 154 | if (strcmp (in->_n._n_name, ".idata$4") == 0)
|
|---|
| 155 | in->n_scnum = 3;
|
|---|
| 156 | else
|
|---|
| 157 | in->n_scnum = 2;
|
|---|
| 158 | #endif
|
|---|
| 159 | #else
|
|---|
| 160 | /* Create synthetic empty sections as needed. DJ */
|
|---|
| 161 | if (in->n_scnum == 0)
|
|---|
| 162 | {
|
|---|
| 163 | asection *sec;
|
|---|
| 164 |
|
|---|
| 165 | for (sec = abfd->sections; sec; sec = sec->next)
|
|---|
| 166 | {
|
|---|
| 167 | if (strcmp (sec->name, in->n_name) == 0)
|
|---|
| 168 | {
|
|---|
| 169 | in->n_scnum = sec->target_index;
|
|---|
| 170 | break;
|
|---|
| 171 | }
|
|---|
| 172 | }
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | if (in->n_scnum == 0)
|
|---|
| 176 | {
|
|---|
| 177 | int unused_section_number = 0;
|
|---|
| 178 | asection *sec;
|
|---|
| 179 | char *name;
|
|---|
| 180 |
|
|---|
| 181 | for (sec = abfd->sections; sec; sec = sec->next)
|
|---|
| 182 | if (unused_section_number <= sec->target_index)
|
|---|
| 183 | unused_section_number = sec->target_index + 1;
|
|---|
| 184 |
|
|---|
| 185 | name = bfd_alloc (abfd, (bfd_size_type) strlen (in->n_name) + 10);
|
|---|
| 186 | if (name == NULL)
|
|---|
| 187 | return;
|
|---|
| 188 | strcpy (name, in->n_name);
|
|---|
| 189 | sec = bfd_make_section_anyway (abfd, name);
|
|---|
| 190 |
|
|---|
| 191 | sec->vma = 0;
|
|---|
| 192 | sec->lma = 0;
|
|---|
| 193 | sec->_cooked_size = 0;
|
|---|
| 194 | sec->_raw_size = 0;
|
|---|
| 195 | sec->filepos = 0;
|
|---|
| 196 | sec->rel_filepos = 0;
|
|---|
| 197 | sec->reloc_count = 0;
|
|---|
| 198 | sec->line_filepos = 0;
|
|---|
| 199 | sec->lineno_count = 0;
|
|---|
| 200 | sec->userdata = NULL;
|
|---|
| 201 | sec->next = (asection *) NULL;
|
|---|
| 202 | sec->flags = 0;
|
|---|
| 203 | sec->alignment_power = 2;
|
|---|
| 204 | sec->flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_DATA | SEC_LOAD;
|
|---|
| 205 |
|
|---|
| 206 | sec->target_index = unused_section_number;
|
|---|
| 207 |
|
|---|
| 208 | in->n_scnum = unused_section_number;
|
|---|
| 209 | }
|
|---|
| 210 | in->n_sclass = C_STAT;
|
|---|
| 211 | #endif
|
|---|
| 212 | }
|
|---|
| 213 | #endif
|
|---|
| 214 |
|
|---|
| 215 | #ifdef coff_swap_sym_in_hook
|
|---|
| 216 | /* This won't work in peigen.c, but since it's for PPC PE, it's not
|
|---|
| 217 | worth fixing. */
|
|---|
| 218 | coff_swap_sym_in_hook (abfd, ext1, in1);
|
|---|
| 219 | #endif
|
|---|
| 220 | }
|
|---|
| 221 |
|
|---|
| 222 | unsigned int
|
|---|
| 223 | _bfd_XXi_swap_sym_out (abfd, inp, extp)
|
|---|
| 224 | bfd *abfd;
|
|---|
| 225 | PTR inp;
|
|---|
| 226 | PTR extp;
|
|---|
| 227 | {
|
|---|
| 228 | struct internal_syment *in = (struct internal_syment *) inp;
|
|---|
| 229 | SYMENT *ext = (SYMENT *) extp;
|
|---|
| 230 |
|
|---|
| 231 | if (in->_n._n_name[0] == 0)
|
|---|
| 232 | {
|
|---|
| 233 | H_PUT_32 (abfd, 0, ext->e.e.e_zeroes);
|
|---|
| 234 | H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e.e.e_offset);
|
|---|
| 235 | }
|
|---|
| 236 | else
|
|---|
| 237 | memcpy (ext->e.e_name, in->_n._n_name, SYMNMLEN);
|
|---|
| 238 |
|
|---|
| 239 | H_PUT_32 (abfd, in->n_value, ext->e_value);
|
|---|
| 240 | H_PUT_16 (abfd, in->n_scnum, ext->e_scnum);
|
|---|
| 241 |
|
|---|
| 242 | if (sizeof (ext->e_type) == 2)
|
|---|
| 243 | H_PUT_16 (abfd, in->n_type, ext->e_type);
|
|---|
| 244 | else
|
|---|
| 245 | H_PUT_32 (abfd, in->n_type, ext->e_type);
|
|---|
| 246 |
|
|---|
| 247 | H_PUT_8 (abfd, in->n_sclass, ext->e_sclass);
|
|---|
| 248 | H_PUT_8 (abfd, in->n_numaux, ext->e_numaux);
|
|---|
| 249 |
|
|---|
| 250 | return SYMESZ;
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | void
|
|---|
| 254 | _bfd_XXi_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1)
|
|---|
| 255 | bfd *abfd;
|
|---|
| 256 | PTR ext1;
|
|---|
| 257 | int type;
|
|---|
| 258 | int class;
|
|---|
| 259 | int indx ATTRIBUTE_UNUSED;
|
|---|
| 260 | int numaux ATTRIBUTE_UNUSED;
|
|---|
| 261 | PTR in1;
|
|---|
| 262 | {
|
|---|
| 263 | AUXENT *ext = (AUXENT *) ext1;
|
|---|
| 264 | union internal_auxent *in = (union internal_auxent *) in1;
|
|---|
| 265 |
|
|---|
| 266 | switch (class)
|
|---|
| 267 | {
|
|---|
| 268 | case C_FILE:
|
|---|
| 269 | if (ext->x_file.x_fname[0] == 0)
|
|---|
| 270 | {
|
|---|
| 271 | in->x_file.x_n.x_zeroes = 0;
|
|---|
| 272 | in->x_file.x_n.x_offset = H_GET_32 (abfd, ext->x_file.x_n.x_offset);
|
|---|
| 273 | }
|
|---|
| 274 | else
|
|---|
| 275 | memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
|
|---|
| 276 | return;
|
|---|
| 277 |
|
|---|
| 278 | case C_STAT:
|
|---|
| 279 | case C_LEAFSTAT:
|
|---|
| 280 | case C_HIDDEN:
|
|---|
| 281 | if (type == T_NULL)
|
|---|
| 282 | {
|
|---|
| 283 | in->x_scn.x_scnlen = GET_SCN_SCNLEN (abfd, ext);
|
|---|
| 284 | in->x_scn.x_nreloc = GET_SCN_NRELOC (abfd, ext);
|
|---|
| 285 | in->x_scn.x_nlinno = GET_SCN_NLINNO (abfd, ext);
|
|---|
| 286 | in->x_scn.x_checksum = H_GET_32 (abfd, ext->x_scn.x_checksum);
|
|---|
| 287 | in->x_scn.x_associated = H_GET_16 (abfd, ext->x_scn.x_associated);
|
|---|
| 288 | in->x_scn.x_comdat = H_GET_8 (abfd, ext->x_scn.x_comdat);
|
|---|
| 289 | return;
|
|---|
| 290 | }
|
|---|
| 291 | break;
|
|---|
| 292 | }
|
|---|
| 293 |
|
|---|
| 294 | in->x_sym.x_tagndx.l = H_GET_32 (abfd, ext->x_sym.x_tagndx);
|
|---|
| 295 | in->x_sym.x_tvndx = H_GET_16 (abfd, ext->x_sym.x_tvndx);
|
|---|
| 296 |
|
|---|
| 297 | if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
|
|---|
| 298 | {
|
|---|
| 299 | in->x_sym.x_fcnary.x_fcn.x_lnnoptr = GET_FCN_LNNOPTR (abfd, ext);
|
|---|
| 300 | in->x_sym.x_fcnary.x_fcn.x_endndx.l = GET_FCN_ENDNDX (abfd, ext);
|
|---|
| 301 | }
|
|---|
| 302 | else
|
|---|
| 303 | {
|
|---|
| 304 | in->x_sym.x_fcnary.x_ary.x_dimen[0] =
|
|---|
| 305 | H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
|
|---|
| 306 | in->x_sym.x_fcnary.x_ary.x_dimen[1] =
|
|---|
| 307 | H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
|
|---|
| 308 | in->x_sym.x_fcnary.x_ary.x_dimen[2] =
|
|---|
| 309 | H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
|
|---|
| 310 | in->x_sym.x_fcnary.x_ary.x_dimen[3] =
|
|---|
| 311 | H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
|
|---|
| 312 | }
|
|---|
| 313 |
|
|---|
| 314 | if (ISFCN (type))
|
|---|
| 315 | {
|
|---|
| 316 | in->x_sym.x_misc.x_fsize = H_GET_32 (abfd, ext->x_sym.x_misc.x_fsize);
|
|---|
| 317 | }
|
|---|
| 318 | else
|
|---|
| 319 | {
|
|---|
| 320 | in->x_sym.x_misc.x_lnsz.x_lnno = GET_LNSZ_LNNO (abfd, ext);
|
|---|
| 321 | in->x_sym.x_misc.x_lnsz.x_size = GET_LNSZ_SIZE (abfd, ext);
|
|---|
| 322 | }
|
|---|
| 323 | }
|
|---|
| 324 |
|
|---|
| 325 | unsigned int
|
|---|
| 326 | _bfd_XXi_swap_aux_out (abfd, inp, type, class, indx, numaux, extp)
|
|---|
| 327 | bfd *abfd;
|
|---|
| 328 | PTR inp;
|
|---|
| 329 | int type;
|
|---|
| 330 | int class;
|
|---|
| 331 | int indx ATTRIBUTE_UNUSED;
|
|---|
| 332 | int numaux ATTRIBUTE_UNUSED;
|
|---|
| 333 | PTR extp;
|
|---|
| 334 | {
|
|---|
| 335 | union internal_auxent *in = (union internal_auxent *) inp;
|
|---|
| 336 | AUXENT *ext = (AUXENT *) extp;
|
|---|
| 337 |
|
|---|
| 338 | memset ((PTR) ext, 0, AUXESZ);
|
|---|
| 339 | switch (class)
|
|---|
| 340 | {
|
|---|
| 341 | case C_FILE:
|
|---|
| 342 | if (in->x_file.x_fname[0] == 0)
|
|---|
| 343 | {
|
|---|
| 344 | H_PUT_32 (abfd, 0, ext->x_file.x_n.x_zeroes);
|
|---|
| 345 | H_PUT_32 (abfd, in->x_file.x_n.x_offset, ext->x_file.x_n.x_offset);
|
|---|
| 346 | }
|
|---|
| 347 | else
|
|---|
| 348 | memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
|
|---|
| 349 |
|
|---|
| 350 | return AUXESZ;
|
|---|
| 351 |
|
|---|
| 352 | case C_STAT:
|
|---|
| 353 | case C_LEAFSTAT:
|
|---|
| 354 | case C_HIDDEN:
|
|---|
| 355 | if (type == T_NULL)
|
|---|
| 356 | {
|
|---|
| 357 | PUT_SCN_SCNLEN (abfd, in->x_scn.x_scnlen, ext);
|
|---|
| 358 | PUT_SCN_NRELOC (abfd, in->x_scn.x_nreloc, ext);
|
|---|
| 359 | PUT_SCN_NLINNO (abfd, in->x_scn.x_nlinno, ext);
|
|---|
| 360 | H_PUT_32 (abfd, in->x_scn.x_checksum, ext->x_scn.x_checksum);
|
|---|
| 361 | H_PUT_16 (abfd, in->x_scn.x_associated, ext->x_scn.x_associated);
|
|---|
| 362 | H_PUT_8 (abfd, in->x_scn.x_comdat, ext->x_scn.x_comdat);
|
|---|
| 363 | return AUXESZ;
|
|---|
| 364 | }
|
|---|
| 365 | break;
|
|---|
| 366 | }
|
|---|
| 367 |
|
|---|
| 368 | H_PUT_32 (abfd, in->x_sym.x_tagndx.l, ext->x_sym.x_tagndx);
|
|---|
| 369 | H_PUT_16 (abfd, in->x_sym.x_tvndx, ext->x_sym.x_tvndx);
|
|---|
| 370 |
|
|---|
| 371 | if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
|
|---|
| 372 | {
|
|---|
| 373 | PUT_FCN_LNNOPTR (abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr, ext);
|
|---|
| 374 | PUT_FCN_ENDNDX (abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l, ext);
|
|---|
| 375 | }
|
|---|
| 376 | else
|
|---|
| 377 | {
|
|---|
| 378 | H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0],
|
|---|
| 379 | ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
|
|---|
| 380 | H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1],
|
|---|
| 381 | ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
|
|---|
| 382 | H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2],
|
|---|
| 383 | ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
|
|---|
| 384 | H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3],
|
|---|
| 385 | ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
|
|---|
| 386 | }
|
|---|
| 387 |
|
|---|
| 388 | if (ISFCN (type))
|
|---|
| 389 | H_PUT_32 (abfd, in->x_sym.x_misc.x_fsize, ext->x_sym.x_misc.x_fsize);
|
|---|
| 390 | else
|
|---|
| 391 | {
|
|---|
| 392 | PUT_LNSZ_LNNO (abfd, in->x_sym.x_misc.x_lnsz.x_lnno, ext);
|
|---|
| 393 | PUT_LNSZ_SIZE (abfd, in->x_sym.x_misc.x_lnsz.x_size, ext);
|
|---|
| 394 | }
|
|---|
| 395 |
|
|---|
| 396 | return AUXESZ;
|
|---|
| 397 | }
|
|---|
| 398 |
|
|---|
| 399 | void
|
|---|
| 400 | _bfd_XXi_swap_lineno_in (abfd, ext1, in1)
|
|---|
| 401 | bfd *abfd;
|
|---|
| 402 | PTR ext1;
|
|---|
| 403 | PTR in1;
|
|---|
| 404 | {
|
|---|
| 405 | LINENO *ext = (LINENO *) ext1;
|
|---|
| 406 | struct internal_lineno *in = (struct internal_lineno *) in1;
|
|---|
| 407 |
|
|---|
| 408 | in->l_addr.l_symndx = H_GET_32 (abfd, ext->l_addr.l_symndx);
|
|---|
| 409 | in->l_lnno = GET_LINENO_LNNO (abfd, ext);
|
|---|
| 410 | }
|
|---|
| 411 |
|
|---|
| 412 | unsigned int
|
|---|
| 413 | _bfd_XXi_swap_lineno_out (abfd, inp, outp)
|
|---|
| 414 | bfd *abfd;
|
|---|
| 415 | PTR inp;
|
|---|
| 416 | PTR outp;
|
|---|
| 417 | {
|
|---|
| 418 | struct internal_lineno *in = (struct internal_lineno *) inp;
|
|---|
| 419 | struct external_lineno *ext = (struct external_lineno *) outp;
|
|---|
| 420 | H_PUT_32 (abfd, in->l_addr.l_symndx, ext->l_addr.l_symndx);
|
|---|
| 421 |
|
|---|
| 422 | PUT_LINENO_LNNO (abfd, in->l_lnno, ext);
|
|---|
| 423 | return LINESZ;
|
|---|
| 424 | }
|
|---|
| 425 |
|
|---|
| 426 | void
|
|---|
| 427 | _bfd_XXi_swap_aouthdr_in (abfd, aouthdr_ext1, aouthdr_int1)
|
|---|
| 428 | bfd *abfd;
|
|---|
| 429 | PTR aouthdr_ext1;
|
|---|
| 430 | PTR aouthdr_int1;
|
|---|
| 431 | {
|
|---|
| 432 | struct internal_extra_pe_aouthdr *a;
|
|---|
| 433 | PEAOUTHDR *src = (PEAOUTHDR *) (aouthdr_ext1);
|
|---|
| 434 | AOUTHDR *aouthdr_ext = (AOUTHDR *) aouthdr_ext1;
|
|---|
| 435 | struct internal_aouthdr *aouthdr_int = (struct internal_aouthdr *)aouthdr_int1;
|
|---|
| 436 |
|
|---|
| 437 | aouthdr_int->magic = H_GET_16 (abfd, aouthdr_ext->magic);
|
|---|
| 438 | aouthdr_int->vstamp = H_GET_16 (abfd, aouthdr_ext->vstamp);
|
|---|
| 439 | aouthdr_int->tsize = GET_AOUTHDR_TSIZE (abfd, aouthdr_ext->tsize);
|
|---|
| 440 | aouthdr_int->dsize = GET_AOUTHDR_DSIZE (abfd, aouthdr_ext->dsize);
|
|---|
| 441 | aouthdr_int->bsize = GET_AOUTHDR_BSIZE (abfd, aouthdr_ext->bsize);
|
|---|
| 442 | aouthdr_int->entry = GET_AOUTHDR_ENTRY (abfd, aouthdr_ext->entry);
|
|---|
| 443 | aouthdr_int->text_start =
|
|---|
| 444 | GET_AOUTHDR_TEXT_START (abfd, aouthdr_ext->text_start);
|
|---|
| 445 | #ifndef COFF_WITH_pep
|
|---|
| 446 | /* PE32+ does not have data_start member! */
|
|---|
| 447 | aouthdr_int->data_start =
|
|---|
| 448 | GET_AOUTHDR_DATA_START (abfd, aouthdr_ext->data_start);
|
|---|
| 449 | #endif
|
|---|
| 450 |
|
|---|
| 451 | a = &aouthdr_int->pe;
|
|---|
| 452 | a->ImageBase = GET_OPTHDR_IMAGE_BASE (abfd, src->ImageBase);
|
|---|
| 453 | a->SectionAlignment = H_GET_32 (abfd, src->SectionAlignment);
|
|---|
| 454 | a->FileAlignment = H_GET_32 (abfd, src->FileAlignment);
|
|---|
| 455 | a->MajorOperatingSystemVersion =
|
|---|
| 456 | H_GET_16 (abfd, src->MajorOperatingSystemVersion);
|
|---|
| 457 | a->MinorOperatingSystemVersion =
|
|---|
| 458 | H_GET_16 (abfd, src->MinorOperatingSystemVersion);
|
|---|
| 459 | a->MajorImageVersion = H_GET_16 (abfd, src->MajorImageVersion);
|
|---|
| 460 | a->MinorImageVersion = H_GET_16 (abfd, src->MinorImageVersion);
|
|---|
| 461 | a->MajorSubsystemVersion = H_GET_16 (abfd, src->MajorSubsystemVersion);
|
|---|
| 462 | a->MinorSubsystemVersion = H_GET_16 (abfd, src->MinorSubsystemVersion);
|
|---|
| 463 | a->Reserved1 = H_GET_32 (abfd, src->Reserved1);
|
|---|
| 464 | a->SizeOfImage = H_GET_32 (abfd, src->SizeOfImage);
|
|---|
| 465 | a->SizeOfHeaders = H_GET_32 (abfd, src->SizeOfHeaders);
|
|---|
| 466 | a->CheckSum = H_GET_32 (abfd, src->CheckSum);
|
|---|
| 467 | a->Subsystem = H_GET_16 (abfd, src->Subsystem);
|
|---|
| 468 | a->DllCharacteristics = H_GET_16 (abfd, src->DllCharacteristics);
|
|---|
| 469 | a->SizeOfStackReserve =
|
|---|
| 470 | GET_OPTHDR_SIZE_OF_STACK_RESERVE (abfd, src->SizeOfStackReserve);
|
|---|
| 471 | a->SizeOfStackCommit =
|
|---|
| 472 | GET_OPTHDR_SIZE_OF_STACK_COMMIT (abfd, src->SizeOfStackCommit);
|
|---|
| 473 | a->SizeOfHeapReserve =
|
|---|
| 474 | GET_OPTHDR_SIZE_OF_HEAP_RESERVE (abfd, src->SizeOfHeapReserve);
|
|---|
| 475 | a->SizeOfHeapCommit =
|
|---|
| 476 | GET_OPTHDR_SIZE_OF_HEAP_COMMIT (abfd, src->SizeOfHeapCommit);
|
|---|
| 477 | a->LoaderFlags = H_GET_32 (abfd, src->LoaderFlags);
|
|---|
| 478 | a->NumberOfRvaAndSizes = H_GET_32 (abfd, src->NumberOfRvaAndSizes);
|
|---|
| 479 |
|
|---|
| 480 | {
|
|---|
| 481 | int idx;
|
|---|
| 482 |
|
|---|
| 483 | for (idx = 0; idx < 16; idx++)
|
|---|
| 484 | {
|
|---|
| 485 | /* If data directory is empty, rva also should be 0. */
|
|---|
| 486 | int size =
|
|---|
| 487 | H_GET_32 (abfd, src->DataDirectory[idx][1]);
|
|---|
| 488 | a->DataDirectory[idx].Size = size;
|
|---|
| 489 |
|
|---|
| 490 | if (size)
|
|---|
| 491 | a->DataDirectory[idx].VirtualAddress =
|
|---|
| 492 | H_GET_32 (abfd, src->DataDirectory[idx][0]);
|
|---|
| 493 | else
|
|---|
| 494 | a->DataDirectory[idx].VirtualAddress = 0;
|
|---|
| 495 | }
|
|---|
| 496 | }
|
|---|
| 497 |
|
|---|
| 498 | if (aouthdr_int->entry)
|
|---|
| 499 | {
|
|---|
| 500 | aouthdr_int->entry += a->ImageBase;
|
|---|
| 501 | #ifndef COFF_WITH_pep
|
|---|
| 502 | aouthdr_int->entry &= 0xffffffff;
|
|---|
| 503 | #endif
|
|---|
| 504 | }
|
|---|
| 505 |
|
|---|
| 506 | if (aouthdr_int->tsize)
|
|---|
| 507 | {
|
|---|
| 508 | aouthdr_int->text_start += a->ImageBase;
|
|---|
| 509 | #ifndef COFF_WITH_pep
|
|---|
| 510 | aouthdr_int->text_start &= 0xffffffff;
|
|---|
| 511 | #endif
|
|---|
| 512 | }
|
|---|
| 513 |
|
|---|
| 514 | #ifndef COFF_WITH_pep
|
|---|
| 515 | /* PE32+ does not have data_start member! */
|
|---|
| 516 | if (aouthdr_int->dsize)
|
|---|
| 517 | {
|
|---|
| 518 | aouthdr_int->data_start += a->ImageBase;
|
|---|
| 519 | aouthdr_int->data_start &= 0xffffffff;
|
|---|
| 520 | }
|
|---|
| 521 | #endif
|
|---|
| 522 |
|
|---|
| 523 | #ifdef POWERPC_LE_PE
|
|---|
| 524 | /* These three fields are normally set up by ppc_relocate_section.
|
|---|
| 525 | In the case of reading a file in, we can pick them up from the
|
|---|
| 526 | DataDirectory. */
|
|---|
| 527 | first_thunk_address = a->DataDirectory[12].VirtualAddress;
|
|---|
| 528 | thunk_size = a->DataDirectory[12].Size;
|
|---|
| 529 | import_table_size = a->DataDirectory[1].Size;
|
|---|
| 530 | #endif
|
|---|
| 531 | }
|
|---|
| 532 |
|
|---|
| 533 | /* A support function for below. */
|
|---|
| 534 |
|
|---|
| 535 | static void
|
|---|
| 536 | add_data_entry (abfd, aout, idx, name, base)
|
|---|
| 537 | bfd *abfd;
|
|---|
| 538 | struct internal_extra_pe_aouthdr *aout;
|
|---|
| 539 | int idx;
|
|---|
| 540 | char *name;
|
|---|
| 541 | bfd_vma base;
|
|---|
| 542 | {
|
|---|
| 543 | asection *sec = bfd_get_section_by_name (abfd, name);
|
|---|
| 544 |
|
|---|
| 545 | /* Add import directory information if it exists. */
|
|---|
| 546 | if ((sec != NULL)
|
|---|
| 547 | && (coff_section_data (abfd, sec) != NULL)
|
|---|
| 548 | && (pei_section_data (abfd, sec) != NULL))
|
|---|
| 549 | {
|
|---|
| 550 | /* If data directory is empty, rva also should be 0. */
|
|---|
| 551 | int size = pei_section_data (abfd, sec)->virt_size;
|
|---|
| 552 | aout->DataDirectory[idx].Size = size;
|
|---|
| 553 |
|
|---|
| 554 | if (size)
|
|---|
| 555 | {
|
|---|
| 556 | aout->DataDirectory[idx].VirtualAddress =
|
|---|
| 557 | (sec->vma - base) & 0xffffffff;
|
|---|
| 558 | sec->flags |= SEC_DATA;
|
|---|
| 559 | }
|
|---|
| 560 | }
|
|---|
| 561 | }
|
|---|
| 562 |
|
|---|
| 563 | unsigned int
|
|---|
| 564 | _bfd_XXi_swap_aouthdr_out (abfd, in, out)
|
|---|
| 565 | bfd *abfd;
|
|---|
| 566 | PTR in;
|
|---|
| 567 | PTR out;
|
|---|
| 568 | {
|
|---|
| 569 | struct internal_aouthdr *aouthdr_in = (struct internal_aouthdr *) in;
|
|---|
| 570 | pe_data_type *pe = pe_data (abfd);
|
|---|
| 571 | struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
|
|---|
| 572 | PEAOUTHDR *aouthdr_out = (PEAOUTHDR *) out;
|
|---|
| 573 | bfd_vma sa, fa, ib;
|
|---|
| 574 | IMAGE_DATA_DIRECTORY idata2, idata5;
|
|---|
| 575 |
|
|---|
| 576 |
|
|---|
| 577 | if (pe->force_minimum_alignment)
|
|---|
| 578 | {
|
|---|
| 579 | if (!extra->FileAlignment)
|
|---|
| 580 | extra->FileAlignment = PE_DEF_FILE_ALIGNMENT;
|
|---|
| 581 | if (!extra->SectionAlignment)
|
|---|
| 582 | extra->SectionAlignment = PE_DEF_SECTION_ALIGNMENT;
|
|---|
| 583 | }
|
|---|
| 584 |
|
|---|
| 585 | if (extra->Subsystem == IMAGE_SUBSYSTEM_UNKNOWN)
|
|---|
| 586 | extra->Subsystem = pe->target_subsystem;
|
|---|
| 587 |
|
|---|
| 588 | sa = extra->SectionAlignment;
|
|---|
| 589 | fa = extra->FileAlignment;
|
|---|
| 590 | ib = extra->ImageBase;
|
|---|
| 591 |
|
|---|
| 592 | idata2 = pe->pe_opthdr.DataDirectory[1];
|
|---|
| 593 | idata5 = pe->pe_opthdr.DataDirectory[12];
|
|---|
| 594 |
|
|---|
| 595 | if (aouthdr_in->tsize)
|
|---|
| 596 | {
|
|---|
| 597 | aouthdr_in->text_start -= ib;
|
|---|
| 598 | #ifndef COFF_WITH_pep
|
|---|
| 599 | aouthdr_in->text_start &= 0xffffffff;
|
|---|
| 600 | #endif
|
|---|
| 601 | }
|
|---|
| 602 |
|
|---|
| 603 | if (aouthdr_in->dsize)
|
|---|
| 604 | {
|
|---|
| 605 | aouthdr_in->data_start -= ib;
|
|---|
| 606 | #ifndef COFF_WITH_pep
|
|---|
| 607 | aouthdr_in->data_start &= 0xffffffff;
|
|---|
| 608 | #endif
|
|---|
| 609 | }
|
|---|
| 610 |
|
|---|
| 611 | if (aouthdr_in->entry)
|
|---|
| 612 | {
|
|---|
| 613 | aouthdr_in->entry -= ib;
|
|---|
| 614 | #ifndef COFF_WITH_pep
|
|---|
| 615 | aouthdr_in->entry &= 0xffffffff;
|
|---|
| 616 | #endif
|
|---|
| 617 | }
|
|---|
| 618 |
|
|---|
| 619 | #define FA(x) (((x) + fa -1 ) & (- fa))
|
|---|
| 620 | #define SA(x) (((x) + sa -1 ) & (- sa))
|
|---|
| 621 |
|
|---|
| 622 | /* We like to have the sizes aligned. */
|
|---|
| 623 | aouthdr_in->bsize = FA (aouthdr_in->bsize);
|
|---|
| 624 |
|
|---|
| 625 | extra->NumberOfRvaAndSizes = IMAGE_NUMBEROF_DIRECTORY_ENTRIES;
|
|---|
| 626 |
|
|---|
| 627 | /* First null out all data directory entries. */
|
|---|
| 628 | memset (extra->DataDirectory, 0, sizeof (extra->DataDirectory));
|
|---|
| 629 |
|
|---|
| 630 | add_data_entry (abfd, extra, 0, ".edata", ib);
|
|---|
| 631 | add_data_entry (abfd, extra, 2, ".rsrc", ib);
|
|---|
| 632 | add_data_entry (abfd, extra, 3, ".pdata", ib);
|
|---|
| 633 |
|
|---|
| 634 | /* In theory we do not need to call add_data_entry for .idata$2 or
|
|---|
| 635 | .idata$5. It will be done in bfd_coff_final_link where all the
|
|---|
| 636 | required information is available. If however, we are not going
|
|---|
| 637 | to perform a final link, eg because we have been invoked by objcopy
|
|---|
| 638 | or strip, then we need to make sure that these Data Directory
|
|---|
| 639 | entries are initialised properly.
|
|---|
| 640 |
|
|---|
| 641 | So - we copy the input values into the output values, and then, if
|
|---|
| 642 | a final link is going to be performed, it can overwrite them. */
|
|---|
| 643 | extra->DataDirectory[1] = idata2;
|
|---|
| 644 | extra->DataDirectory[12] = idata5;
|
|---|
| 645 |
|
|---|
| 646 | if (extra->DataDirectory[1].VirtualAddress == 0)
|
|---|
| 647 | /* Until other .idata fixes are made (pending patch), the entry for
|
|---|
| 648 | .idata is needed for backwards compatability. FIXME. */
|
|---|
| 649 | add_data_entry (abfd, extra, 1, ".idata", ib);
|
|---|
| 650 |
|
|---|
| 651 | /* For some reason, the virtual size (which is what's set by
|
|---|
| 652 | add_data_entry) for .reloc is not the same as the size recorded
|
|---|
| 653 | in this slot by MSVC; it doesn't seem to cause problems (so far),
|
|---|
| 654 | but since it's the best we've got, use it. It does do the right
|
|---|
| 655 | thing for .pdata. */
|
|---|
| 656 | if (pe->has_reloc_section)
|
|---|
| 657 | add_data_entry (abfd, extra, 5, ".reloc", ib);
|
|---|
| 658 |
|
|---|
| 659 | {
|
|---|
| 660 | asection *sec;
|
|---|
| 661 | bfd_vma dsize = 0;
|
|---|
| 662 | bfd_vma isize = SA(abfd->sections->filepos);
|
|---|
| 663 | bfd_vma tsize = 0;
|
|---|
| 664 |
|
|---|
| 665 | for (sec = abfd->sections; sec; sec = sec->next)
|
|---|
| 666 | {
|
|---|
| 667 | int rounded = FA(sec->_raw_size);
|
|---|
| 668 |
|
|---|
| 669 | if (sec->flags & SEC_DATA)
|
|---|
| 670 | dsize += rounded;
|
|---|
| 671 | if (sec->flags & SEC_CODE)
|
|---|
| 672 | tsize += rounded;
|
|---|
| 673 | /* The image size is the total VIRTUAL size (which is what is
|
|---|
| 674 | in the virt_size field). Files have been seen (from MSVC
|
|---|
| 675 | 5.0 link.exe) where the file size of the .data segment is
|
|---|
| 676 | quite small compared to the virtual size. Without this
|
|---|
| 677 | fix, strip munges the file. */
|
|---|
| 678 | isize += SA (FA (pei_section_data (abfd, sec)->virt_size));
|
|---|
| 679 | }
|
|---|
| 680 |
|
|---|
| 681 | aouthdr_in->dsize = dsize;
|
|---|
| 682 | aouthdr_in->tsize = tsize;
|
|---|
| 683 | extra->SizeOfImage = isize;
|
|---|
| 684 | }
|
|---|
| 685 |
|
|---|
| 686 | extra->SizeOfHeaders = abfd->sections->filepos;
|
|---|
| 687 | H_PUT_16 (abfd, aouthdr_in->magic, aouthdr_out->standard.magic);
|
|---|
| 688 |
|
|---|
| 689 | #define LINKER_VERSION 256 /* That is, 2.56 */
|
|---|
| 690 |
|
|---|
| 691 | /* This piece of magic sets the "linker version" field to
|
|---|
| 692 | LINKER_VERSION. */
|
|---|
| 693 | H_PUT_16 (abfd, (LINKER_VERSION / 100 + (LINKER_VERSION % 100) * 256),
|
|---|
| 694 | aouthdr_out->standard.vstamp);
|
|---|
| 695 |
|
|---|
| 696 | PUT_AOUTHDR_TSIZE (abfd, aouthdr_in->tsize, aouthdr_out->standard.tsize);
|
|---|
| 697 | PUT_AOUTHDR_DSIZE (abfd, aouthdr_in->dsize, aouthdr_out->standard.dsize);
|
|---|
| 698 | PUT_AOUTHDR_BSIZE (abfd, aouthdr_in->bsize, aouthdr_out->standard.bsize);
|
|---|
| 699 | PUT_AOUTHDR_ENTRY (abfd, aouthdr_in->entry, aouthdr_out->standard.entry);
|
|---|
| 700 | PUT_AOUTHDR_TEXT_START (abfd, aouthdr_in->text_start,
|
|---|
| 701 | aouthdr_out->standard.text_start);
|
|---|
| 702 |
|
|---|
| 703 | #ifndef COFF_WITH_pep
|
|---|
| 704 | /* PE32+ does not have data_start member! */
|
|---|
| 705 | PUT_AOUTHDR_DATA_START (abfd, aouthdr_in->data_start,
|
|---|
| 706 | aouthdr_out->standard.data_start);
|
|---|
| 707 | #endif
|
|---|
| 708 |
|
|---|
| 709 | PUT_OPTHDR_IMAGE_BASE (abfd, extra->ImageBase, aouthdr_out->ImageBase);
|
|---|
| 710 | H_PUT_32 (abfd, extra->SectionAlignment, aouthdr_out->SectionAlignment);
|
|---|
| 711 | H_PUT_32 (abfd, extra->FileAlignment, aouthdr_out->FileAlignment);
|
|---|
| 712 | H_PUT_16 (abfd, extra->MajorOperatingSystemVersion,
|
|---|
| 713 | aouthdr_out->MajorOperatingSystemVersion);
|
|---|
| 714 | H_PUT_16 (abfd, extra->MinorOperatingSystemVersion,
|
|---|
| 715 | aouthdr_out->MinorOperatingSystemVersion);
|
|---|
| 716 | H_PUT_16 (abfd, extra->MajorImageVersion, aouthdr_out->MajorImageVersion);
|
|---|
| 717 | H_PUT_16 (abfd, extra->MinorImageVersion, aouthdr_out->MinorImageVersion);
|
|---|
| 718 | H_PUT_16 (abfd, extra->MajorSubsystemVersion,
|
|---|
| 719 | aouthdr_out->MajorSubsystemVersion);
|
|---|
| 720 | H_PUT_16 (abfd, extra->MinorSubsystemVersion,
|
|---|
| 721 | aouthdr_out->MinorSubsystemVersion);
|
|---|
| 722 | H_PUT_32 (abfd, extra->Reserved1, aouthdr_out->Reserved1);
|
|---|
| 723 | H_PUT_32 (abfd, extra->SizeOfImage, aouthdr_out->SizeOfImage);
|
|---|
| 724 | H_PUT_32 (abfd, extra->SizeOfHeaders, aouthdr_out->SizeOfHeaders);
|
|---|
| 725 | H_PUT_32 (abfd, extra->CheckSum, aouthdr_out->CheckSum);
|
|---|
| 726 | H_PUT_16 (abfd, extra->Subsystem, aouthdr_out->Subsystem);
|
|---|
| 727 | H_PUT_16 (abfd, extra->DllCharacteristics, aouthdr_out->DllCharacteristics);
|
|---|
| 728 | PUT_OPTHDR_SIZE_OF_STACK_RESERVE (abfd, extra->SizeOfStackReserve,
|
|---|
| 729 | aouthdr_out->SizeOfStackReserve);
|
|---|
| 730 | PUT_OPTHDR_SIZE_OF_STACK_COMMIT (abfd, extra->SizeOfStackCommit,
|
|---|
| 731 | aouthdr_out->SizeOfStackCommit);
|
|---|
| 732 | PUT_OPTHDR_SIZE_OF_HEAP_RESERVE (abfd, extra->SizeOfHeapReserve,
|
|---|
| 733 | aouthdr_out->SizeOfHeapReserve);
|
|---|
| 734 | PUT_OPTHDR_SIZE_OF_HEAP_COMMIT (abfd, extra->SizeOfHeapCommit,
|
|---|
| 735 | aouthdr_out->SizeOfHeapCommit);
|
|---|
| 736 | H_PUT_32 (abfd, extra->LoaderFlags, aouthdr_out->LoaderFlags);
|
|---|
| 737 | H_PUT_32 (abfd, extra->NumberOfRvaAndSizes,
|
|---|
| 738 | aouthdr_out->NumberOfRvaAndSizes);
|
|---|
| 739 | {
|
|---|
| 740 | int idx;
|
|---|
| 741 |
|
|---|
| 742 | for (idx = 0; idx < 16; idx++)
|
|---|
| 743 | {
|
|---|
| 744 | H_PUT_32 (abfd, extra->DataDirectory[idx].VirtualAddress,
|
|---|
| 745 | aouthdr_out->DataDirectory[idx][0]);
|
|---|
| 746 | H_PUT_32 (abfd, extra->DataDirectory[idx].Size,
|
|---|
| 747 | aouthdr_out->DataDirectory[idx][1]);
|
|---|
| 748 | }
|
|---|
| 749 | }
|
|---|
| 750 |
|
|---|
| 751 | return AOUTSZ;
|
|---|
| 752 | }
|
|---|
| 753 |
|
|---|
| 754 | unsigned int
|
|---|
| 755 | _bfd_XXi_only_swap_filehdr_out (abfd, in, out)
|
|---|
| 756 | bfd *abfd;
|
|---|
| 757 | PTR in;
|
|---|
| 758 | PTR out;
|
|---|
| 759 | {
|
|---|
| 760 | int idx;
|
|---|
| 761 | struct internal_filehdr *filehdr_in = (struct internal_filehdr *) in;
|
|---|
| 762 | struct external_PEI_filehdr *filehdr_out = (struct external_PEI_filehdr *) out;
|
|---|
| 763 |
|
|---|
| 764 | if (pe_data (abfd)->has_reloc_section)
|
|---|
| 765 | filehdr_in->f_flags &= ~F_RELFLG;
|
|---|
| 766 |
|
|---|
| 767 | if (pe_data (abfd)->dll)
|
|---|
| 768 | filehdr_in->f_flags |= F_DLL;
|
|---|
| 769 |
|
|---|
| 770 | filehdr_in->pe.e_magic = DOSMAGIC;
|
|---|
| 771 | filehdr_in->pe.e_cblp = 0x90;
|
|---|
| 772 | filehdr_in->pe.e_cp = 0x3;
|
|---|
| 773 | filehdr_in->pe.e_crlc = 0x0;
|
|---|
| 774 | filehdr_in->pe.e_cparhdr = 0x4;
|
|---|
| 775 | filehdr_in->pe.e_minalloc = 0x0;
|
|---|
| 776 | filehdr_in->pe.e_maxalloc = 0xffff;
|
|---|
| 777 | filehdr_in->pe.e_ss = 0x0;
|
|---|
| 778 | filehdr_in->pe.e_sp = 0xb8;
|
|---|
| 779 | filehdr_in->pe.e_csum = 0x0;
|
|---|
| 780 | filehdr_in->pe.e_ip = 0x0;
|
|---|
| 781 | filehdr_in->pe.e_cs = 0x0;
|
|---|
| 782 | filehdr_in->pe.e_lfarlc = 0x40;
|
|---|
| 783 | filehdr_in->pe.e_ovno = 0x0;
|
|---|
| 784 |
|
|---|
| 785 | for (idx = 0; idx < 4; idx++)
|
|---|
| 786 | filehdr_in->pe.e_res[idx] = 0x0;
|
|---|
| 787 |
|
|---|
| 788 | filehdr_in->pe.e_oemid = 0x0;
|
|---|
| 789 | filehdr_in->pe.e_oeminfo = 0x0;
|
|---|
| 790 |
|
|---|
| 791 | for (idx = 0; idx < 10; idx++)
|
|---|
| 792 | filehdr_in->pe.e_res2[idx] = 0x0;
|
|---|
| 793 |
|
|---|
| 794 | filehdr_in->pe.e_lfanew = 0x80;
|
|---|
| 795 |
|
|---|
| 796 | /* This next collection of data are mostly just characters. It
|
|---|
| 797 | appears to be constant within the headers put on NT exes. */
|
|---|
| 798 | filehdr_in->pe.dos_message[0] = 0x0eba1f0e;
|
|---|
| 799 | filehdr_in->pe.dos_message[1] = 0xcd09b400;
|
|---|
| 800 | filehdr_in->pe.dos_message[2] = 0x4c01b821;
|
|---|
| 801 | filehdr_in->pe.dos_message[3] = 0x685421cd;
|
|---|
| 802 | filehdr_in->pe.dos_message[4] = 0x70207369;
|
|---|
| 803 | filehdr_in->pe.dos_message[5] = 0x72676f72;
|
|---|
| 804 | filehdr_in->pe.dos_message[6] = 0x63206d61;
|
|---|
| 805 | filehdr_in->pe.dos_message[7] = 0x6f6e6e61;
|
|---|
| 806 | filehdr_in->pe.dos_message[8] = 0x65622074;
|
|---|
| 807 | filehdr_in->pe.dos_message[9] = 0x6e757220;
|
|---|
| 808 | filehdr_in->pe.dos_message[10] = 0x206e6920;
|
|---|
| 809 | filehdr_in->pe.dos_message[11] = 0x20534f44;
|
|---|
| 810 | filehdr_in->pe.dos_message[12] = 0x65646f6d;
|
|---|
| 811 | filehdr_in->pe.dos_message[13] = 0x0a0d0d2e;
|
|---|
| 812 | filehdr_in->pe.dos_message[14] = 0x24;
|
|---|
| 813 | filehdr_in->pe.dos_message[15] = 0x0;
|
|---|
| 814 | filehdr_in->pe.nt_signature = NT_SIGNATURE;
|
|---|
| 815 |
|
|---|
| 816 | H_PUT_16 (abfd, filehdr_in->f_magic, filehdr_out->f_magic);
|
|---|
| 817 | H_PUT_16 (abfd, filehdr_in->f_nscns, filehdr_out->f_nscns);
|
|---|
| 818 |
|
|---|
| 819 | H_PUT_32 (abfd, time (0), filehdr_out->f_timdat);
|
|---|
| 820 | PUT_FILEHDR_SYMPTR (abfd, filehdr_in->f_symptr,
|
|---|
| 821 | filehdr_out->f_symptr);
|
|---|
| 822 | H_PUT_32 (abfd, filehdr_in->f_nsyms, filehdr_out->f_nsyms);
|
|---|
| 823 | H_PUT_16 (abfd, filehdr_in->f_opthdr, filehdr_out->f_opthdr);
|
|---|
| 824 | H_PUT_16 (abfd, filehdr_in->f_flags, filehdr_out->f_flags);
|
|---|
| 825 |
|
|---|
| 826 | /* Put in extra dos header stuff. This data remains essentially
|
|---|
| 827 | constant, it just has to be tacked on to the beginning of all exes
|
|---|
| 828 | for NT. */
|
|---|
| 829 | H_PUT_16 (abfd, filehdr_in->pe.e_magic, filehdr_out->e_magic);
|
|---|
| 830 | H_PUT_16 (abfd, filehdr_in->pe.e_cblp, filehdr_out->e_cblp);
|
|---|
| 831 | H_PUT_16 (abfd, filehdr_in->pe.e_cp, filehdr_out->e_cp);
|
|---|
| 832 | H_PUT_16 (abfd, filehdr_in->pe.e_crlc, filehdr_out->e_crlc);
|
|---|
| 833 | H_PUT_16 (abfd, filehdr_in->pe.e_cparhdr, filehdr_out->e_cparhdr);
|
|---|
| 834 | H_PUT_16 (abfd, filehdr_in->pe.e_minalloc, filehdr_out->e_minalloc);
|
|---|
| 835 | H_PUT_16 (abfd, filehdr_in->pe.e_maxalloc, filehdr_out->e_maxalloc);
|
|---|
| 836 | H_PUT_16 (abfd, filehdr_in->pe.e_ss, filehdr_out->e_ss);
|
|---|
| 837 | H_PUT_16 (abfd, filehdr_in->pe.e_sp, filehdr_out->e_sp);
|
|---|
| 838 | H_PUT_16 (abfd, filehdr_in->pe.e_csum, filehdr_out->e_csum);
|
|---|
| 839 | H_PUT_16 (abfd, filehdr_in->pe.e_ip, filehdr_out->e_ip);
|
|---|
| 840 | H_PUT_16 (abfd, filehdr_in->pe.e_cs, filehdr_out->e_cs);
|
|---|
| 841 | H_PUT_16 (abfd, filehdr_in->pe.e_lfarlc, filehdr_out->e_lfarlc);
|
|---|
| 842 | H_PUT_16 (abfd, filehdr_in->pe.e_ovno, filehdr_out->e_ovno);
|
|---|
| 843 |
|
|---|
| 844 | for (idx = 0; idx < 4; idx++)
|
|---|
| 845 | H_PUT_16 (abfd, filehdr_in->pe.e_res[idx], filehdr_out->e_res[idx]);
|
|---|
| 846 |
|
|---|
| 847 | H_PUT_16 (abfd, filehdr_in->pe.e_oemid, filehdr_out->e_oemid);
|
|---|
| 848 | H_PUT_16 (abfd, filehdr_in->pe.e_oeminfo, filehdr_out->e_oeminfo);
|
|---|
| 849 |
|
|---|
| 850 | for (idx = 0; idx < 10; idx++)
|
|---|
| 851 | H_PUT_16 (abfd, filehdr_in->pe.e_res2[idx], filehdr_out->e_res2[idx]);
|
|---|
| 852 |
|
|---|
| 853 | H_PUT_32 (abfd, filehdr_in->pe.e_lfanew, filehdr_out->e_lfanew);
|
|---|
| 854 |
|
|---|
| 855 | for (idx = 0; idx < 16; idx++)
|
|---|
| 856 | H_PUT_32 (abfd, filehdr_in->pe.dos_message[idx],
|
|---|
| 857 | filehdr_out->dos_message[idx]);
|
|---|
| 858 |
|
|---|
| 859 | /* Also put in the NT signature. */
|
|---|
| 860 | H_PUT_32 (abfd, filehdr_in->pe.nt_signature, filehdr_out->nt_signature);
|
|---|
| 861 |
|
|---|
| 862 | return FILHSZ;
|
|---|
| 863 | }
|
|---|
| 864 |
|
|---|
| 865 | unsigned int
|
|---|
| 866 | _bfd_XX_only_swap_filehdr_out (abfd, in, out)
|
|---|
| 867 | bfd *abfd;
|
|---|
| 868 | PTR in;
|
|---|
| 869 | PTR out;
|
|---|
| 870 | {
|
|---|
| 871 | struct internal_filehdr *filehdr_in = (struct internal_filehdr *) in;
|
|---|
| 872 | FILHDR *filehdr_out = (FILHDR *) out;
|
|---|
| 873 |
|
|---|
| 874 | H_PUT_16 (abfd, filehdr_in->f_magic, filehdr_out->f_magic);
|
|---|
| 875 | H_PUT_16 (abfd, filehdr_in->f_nscns, filehdr_out->f_nscns);
|
|---|
| 876 | H_PUT_32 (abfd, filehdr_in->f_timdat, filehdr_out->f_timdat);
|
|---|
| 877 | PUT_FILEHDR_SYMPTR (abfd, filehdr_in->f_symptr, filehdr_out->f_symptr);
|
|---|
| 878 | H_PUT_32 (abfd, filehdr_in->f_nsyms, filehdr_out->f_nsyms);
|
|---|
| 879 | H_PUT_16 (abfd, filehdr_in->f_opthdr, filehdr_out->f_opthdr);
|
|---|
| 880 | H_PUT_16 (abfd, filehdr_in->f_flags, filehdr_out->f_flags);
|
|---|
| 881 |
|
|---|
| 882 | return FILHSZ;
|
|---|
| 883 | }
|
|---|
| 884 |
|
|---|
| 885 | unsigned int
|
|---|
| 886 | _bfd_XXi_swap_scnhdr_out (abfd, in, out)
|
|---|
| 887 | bfd *abfd;
|
|---|
| 888 | PTR in;
|
|---|
| 889 | PTR out;
|
|---|
| 890 | {
|
|---|
| 891 | struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
|
|---|
| 892 | SCNHDR *scnhdr_ext = (SCNHDR *) out;
|
|---|
| 893 | unsigned int ret = SCNHSZ;
|
|---|
| 894 | bfd_vma ps;
|
|---|
| 895 | bfd_vma ss;
|
|---|
| 896 |
|
|---|
| 897 | memcpy (scnhdr_ext->s_name, scnhdr_int->s_name, sizeof (scnhdr_int->s_name));
|
|---|
| 898 |
|
|---|
| 899 | PUT_SCNHDR_VADDR (abfd,
|
|---|
| 900 | ((scnhdr_int->s_vaddr
|
|---|
| 901 | - pe_data (abfd)->pe_opthdr.ImageBase)
|
|---|
| 902 | & 0xffffffff),
|
|---|
| 903 | scnhdr_ext->s_vaddr);
|
|---|
| 904 |
|
|---|
| 905 | /* NT wants the size data to be rounded up to the next
|
|---|
| 906 | NT_FILE_ALIGNMENT, but zero if it has no content (as in .bss,
|
|---|
| 907 | sometimes). */
|
|---|
| 908 | if ((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0)
|
|---|
| 909 | {
|
|---|
| 910 | if (bfd_pe_executable_p (abfd))
|
|---|
| 911 | {
|
|---|
| 912 | ps = scnhdr_int->s_size;
|
|---|
| 913 | ss = 0;
|
|---|
| 914 | }
|
|---|
| 915 | else
|
|---|
| 916 | {
|
|---|
| 917 | ps = 0;
|
|---|
| 918 | ss = scnhdr_int->s_size;
|
|---|
| 919 | }
|
|---|
| 920 | }
|
|---|
| 921 | else
|
|---|
| 922 | {
|
|---|
| 923 | if (bfd_pe_executable_p (abfd))
|
|---|
| 924 | ps = scnhdr_int->s_paddr;
|
|---|
| 925 | else
|
|---|
| 926 | ps = 0;
|
|---|
| 927 |
|
|---|
| 928 | ss = scnhdr_int->s_size;
|
|---|
| 929 | }
|
|---|
| 930 |
|
|---|
| 931 | PUT_SCNHDR_SIZE (abfd, ss,
|
|---|
| 932 | scnhdr_ext->s_size);
|
|---|
| 933 |
|
|---|
| 934 | /* s_paddr in PE is really the virtual size. */
|
|---|
| 935 | PUT_SCNHDR_PADDR (abfd, ps, scnhdr_ext->s_paddr);
|
|---|
| 936 |
|
|---|
| 937 | PUT_SCNHDR_SCNPTR (abfd, scnhdr_int->s_scnptr,
|
|---|
| 938 | scnhdr_ext->s_scnptr);
|
|---|
| 939 | PUT_SCNHDR_RELPTR (abfd, scnhdr_int->s_relptr,
|
|---|
| 940 | scnhdr_ext->s_relptr);
|
|---|
| 941 | PUT_SCNHDR_LNNOPTR (abfd, scnhdr_int->s_lnnoptr,
|
|---|
| 942 | scnhdr_ext->s_lnnoptr);
|
|---|
| 943 |
|
|---|
| 944 | /* Extra flags must be set when dealing with NT. All sections should also
|
|---|
| 945 | have the IMAGE_SCN_MEM_READ (0x40000000) flag set. In addition, the
|
|---|
| 946 | .text section must have IMAGE_SCN_MEM_EXECUTE (0x20000000) and the data
|
|---|
| 947 | sections (.idata, .data, .bss, .CRT) must have IMAGE_SCN_MEM_WRITE set
|
|---|
| 948 | (this is especially important when dealing with the .idata section since
|
|---|
| 949 | the addresses for routines from .dlls must be overwritten). If .reloc
|
|---|
| 950 | section data is ever generated, we must add IMAGE_SCN_MEM_DISCARDABLE
|
|---|
| 951 | (0x02000000). Also, the resource data should also be read and
|
|---|
| 952 | writable. */
|
|---|
| 953 |
|
|---|
| 954 | /* FIXME: alignment is also encoded in this field, at least on ppc (krk) */
|
|---|
| 955 | /* FIXME: even worse, I don't see how to get the original alignment field*/
|
|---|
| 956 | /* back... */
|
|---|
| 957 |
|
|---|
| 958 | {
|
|---|
| 959 | int flags = scnhdr_int->s_flags;
|
|---|
| 960 |
|
|---|
| 961 | H_PUT_32 (abfd, flags, scnhdr_ext->s_flags);
|
|---|
| 962 | }
|
|---|
| 963 |
|
|---|
| 964 | if (coff_data (abfd)->link_info
|
|---|
| 965 | && ! coff_data (abfd)->link_info->relocateable
|
|---|
| 966 | && ! coff_data (abfd)->link_info->shared
|
|---|
| 967 | && strcmp (scnhdr_int->s_name, ".text") == 0)
|
|---|
| 968 | {
|
|---|
| 969 | /* By inference from looking at MS output, the 32 bit field
|
|---|
| 970 | which is the combintion of the number_of_relocs and
|
|---|
| 971 | number_of_linenos is used for the line number count in
|
|---|
| 972 | executables. A 16-bit field won't do for cc1. The MS
|
|---|
| 973 | document says that the number of relocs is zero for
|
|---|
| 974 | executables, but the 17-th bit has been observed to be there.
|
|---|
| 975 | Overflow is not an issue: a 4G-line program will overflow a
|
|---|
| 976 | bunch of other fields long before this! */
|
|---|
| 977 | H_PUT_16 (abfd, (scnhdr_int->s_nlnno & 0xffff), scnhdr_ext->s_nlnno);
|
|---|
| 978 | H_PUT_16 (abfd, (scnhdr_int->s_nlnno >> 16), scnhdr_ext->s_nreloc);
|
|---|
| 979 | }
|
|---|
| 980 | else
|
|---|
| 981 | {
|
|---|
| 982 | if (scnhdr_int->s_nlnno <= 0xffff)
|
|---|
| 983 | H_PUT_16 (abfd, scnhdr_int->s_nlnno, scnhdr_ext->s_nlnno);
|
|---|
| 984 | else
|
|---|
| 985 | {
|
|---|
| 986 | (*_bfd_error_handler) (_("%s: line number overflow: 0x%lx > 0xffff"),
|
|---|
| 987 | bfd_get_filename (abfd),
|
|---|
| 988 | scnhdr_int->s_nlnno);
|
|---|
| 989 | bfd_set_error (bfd_error_file_truncated);
|
|---|
| 990 | H_PUT_16 (abfd, 0xffff, scnhdr_ext->s_nlnno);
|
|---|
| 991 | ret = 0;
|
|---|
| 992 | }
|
|---|
| 993 |
|
|---|
| 994 | if (scnhdr_int->s_nreloc <= 0xffff)
|
|---|
| 995 | H_PUT_16 (abfd, scnhdr_int->s_nreloc, scnhdr_ext->s_nreloc);
|
|---|
| 996 | else
|
|---|
| 997 | {
|
|---|
| 998 | /* PE can deal with large #s of relocs, but not here. */
|
|---|
| 999 | H_PUT_16 (abfd, 0xffff, scnhdr_ext->s_nreloc);
|
|---|
| 1000 | scnhdr_int->s_flags |= IMAGE_SCN_LNK_NRELOC_OVFL;
|
|---|
| 1001 | H_PUT_32 (abfd, scnhdr_int->s_flags, scnhdr_ext->s_flags);
|
|---|
| 1002 | #if 0
|
|---|
| 1003 | (*_bfd_error_handler) (_("%s: reloc overflow 1: 0x%lx > 0xffff"),
|
|---|
| 1004 | bfd_get_filename (abfd),
|
|---|
| 1005 | scnhdr_int->s_nreloc);
|
|---|
| 1006 | bfd_set_error (bfd_error_file_truncated);
|
|---|
| 1007 | H_PUT_16 (abfd, 0xffff, scnhdr_ext->s_nreloc);
|
|---|
| 1008 | ret = 0;
|
|---|
| 1009 | #endif
|
|---|
| 1010 | }
|
|---|
| 1011 | }
|
|---|
| 1012 | return ret;
|
|---|
| 1013 | }
|
|---|
| 1014 |
|
|---|
| 1015 | static char * dir_names[IMAGE_NUMBEROF_DIRECTORY_ENTRIES] =
|
|---|
| 1016 | {
|
|---|
| 1017 | N_("Export Directory [.edata (or where ever we found it)]"),
|
|---|
| 1018 | N_("Import Directory [parts of .idata]"),
|
|---|
| 1019 | N_("Resource Directory [.rsrc]"),
|
|---|
| 1020 | N_("Exception Directory [.pdata]"),
|
|---|
| 1021 | N_("Security Directory"),
|
|---|
| 1022 | N_("Base Relocation Directory [.reloc]"),
|
|---|
| 1023 | N_("Debug Directory"),
|
|---|
| 1024 | N_("Description Directory"),
|
|---|
| 1025 | N_("Special Directory"),
|
|---|
| 1026 | N_("Thread Storage Directory [.tls]"),
|
|---|
| 1027 | N_("Load Configuration Directory"),
|
|---|
| 1028 | N_("Bound Import Directory"),
|
|---|
| 1029 | N_("Import Address Table Directory"),
|
|---|
| 1030 | N_("Delay Import Directory"),
|
|---|
| 1031 | N_("Reserved"),
|
|---|
| 1032 | N_("Reserved")
|
|---|
| 1033 | };
|
|---|
| 1034 |
|
|---|
| 1035 | #ifdef POWERPC_LE_PE
|
|---|
| 1036 | /* The code for the PPC really falls in the "architecture dependent"
|
|---|
| 1037 | category. However, it's not clear that anyone will ever care, so
|
|---|
| 1038 | we're ignoring the issue for now; if/when PPC matters, some of this
|
|---|
| 1039 | may need to go into peicode.h, or arguments passed to enable the
|
|---|
| 1040 | PPC- specific code. */
|
|---|
| 1041 | #endif
|
|---|
| 1042 |
|
|---|
| 1043 | static bfd_boolean
|
|---|
| 1044 | pe_print_idata (abfd, vfile)
|
|---|
| 1045 | bfd *abfd;
|
|---|
| 1046 | PTR vfile;
|
|---|
| 1047 | {
|
|---|
| 1048 | FILE *file = (FILE *) vfile;
|
|---|
| 1049 | bfd_byte *data;
|
|---|
| 1050 | asection *section;
|
|---|
| 1051 | bfd_signed_vma adj;
|
|---|
| 1052 |
|
|---|
| 1053 | #ifdef POWERPC_LE_PE
|
|---|
| 1054 | asection *rel_section = bfd_get_section_by_name (abfd, ".reldata");
|
|---|
| 1055 | #endif
|
|---|
| 1056 |
|
|---|
| 1057 | bfd_size_type datasize = 0;
|
|---|
| 1058 | bfd_size_type dataoff;
|
|---|
| 1059 | bfd_size_type i;
|
|---|
| 1060 | bfd_size_type amt;
|
|---|
| 1061 | int onaline = 20;
|
|---|
| 1062 |
|
|---|
| 1063 | pe_data_type *pe = pe_data (abfd);
|
|---|
| 1064 | struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
|
|---|
| 1065 |
|
|---|
| 1066 | bfd_vma addr;
|
|---|
| 1067 |
|
|---|
| 1068 | addr = extra->DataDirectory[1].VirtualAddress;
|
|---|
| 1069 |
|
|---|
| 1070 | if (addr == 0 && extra->DataDirectory[1].Size == 0)
|
|---|
| 1071 | {
|
|---|
| 1072 | /* Maybe the extra header isn't there. Look for the section. */
|
|---|
| 1073 | section = bfd_get_section_by_name (abfd, ".idata");
|
|---|
| 1074 | if (section == NULL)
|
|---|
| 1075 | return TRUE;
|
|---|
| 1076 |
|
|---|
| 1077 | addr = section->vma;
|
|---|
| 1078 | datasize = bfd_section_size (abfd, section);
|
|---|
| 1079 | if (datasize == 0)
|
|---|
| 1080 | return TRUE;
|
|---|
| 1081 | }
|
|---|
| 1082 | else
|
|---|
| 1083 | {
|
|---|
| 1084 | addr += extra->ImageBase;
|
|---|
| 1085 | for (section = abfd->sections; section != NULL; section = section->next)
|
|---|
| 1086 | {
|
|---|
| 1087 | datasize = bfd_section_size (abfd, section);
|
|---|
| 1088 | if (addr >= section->vma && addr < section->vma + datasize)
|
|---|
| 1089 | break;
|
|---|
| 1090 | }
|
|---|
| 1091 |
|
|---|
| 1092 | if (section == NULL)
|
|---|
| 1093 | {
|
|---|
| 1094 | fprintf (file,
|
|---|
| 1095 | _("\nThere is an import table, but the section containing it could not be found\n"));
|
|---|
| 1096 | return TRUE;
|
|---|
| 1097 | }
|
|---|
| 1098 | }
|
|---|
| 1099 |
|
|---|
| 1100 | fprintf (file, _("\nThere is an import table in %s at 0x%lx\n"),
|
|---|
| 1101 | section->name, (unsigned long) addr);
|
|---|
| 1102 |
|
|---|
| 1103 | dataoff = addr - section->vma;
|
|---|
| 1104 | datasize -= dataoff;
|
|---|
| 1105 |
|
|---|
| 1106 | #ifdef POWERPC_LE_PE
|
|---|
| 1107 | if (rel_section != 0 && bfd_section_size (abfd, rel_section) != 0)
|
|---|
| 1108 | {
|
|---|
| 1109 | /* The toc address can be found by taking the starting address,
|
|---|
| 1110 | which on the PPC locates a function descriptor. The
|
|---|
| 1111 | descriptor consists of the function code starting address
|
|---|
| 1112 | followed by the address of the toc. The starting address we
|
|---|
| 1113 | get from the bfd, and the descriptor is supposed to be in the
|
|---|
| 1114 | .reldata section. */
|
|---|
| 1115 |
|
|---|
| 1116 | bfd_vma loadable_toc_address;
|
|---|
| 1117 | bfd_vma toc_address;
|
|---|
| 1118 | bfd_vma start_address;
|
|---|
| 1119 | bfd_byte *data = 0;
|
|---|
| 1120 | int offset;
|
|---|
| 1121 |
|
|---|
| 1122 | amt = bfd_section_size (abfd, rel_section);
|
|---|
| 1123 | data = (bfd_byte *) bfd_malloc (amt);
|
|---|
| 1124 | if (data == NULL && amt != 0)
|
|---|
| 1125 | return FALSE;
|
|---|
| 1126 |
|
|---|
| 1127 | bfd_get_section_contents (abfd, rel_section, (PTR) data, (bfd_vma) 0,
|
|---|
| 1128 | amt);
|
|---|
| 1129 |
|
|---|
| 1130 | offset = abfd->start_address - rel_section->vma;
|
|---|
| 1131 |
|
|---|
| 1132 | start_address = bfd_get_32 (abfd, data + offset);
|
|---|
| 1133 | loadable_toc_address = bfd_get_32 (abfd, data + offset + 4);
|
|---|
| 1134 | toc_address = loadable_toc_address - 32768;
|
|---|
| 1135 |
|
|---|
| 1136 | fprintf (file,
|
|---|
| 1137 | _("\nFunction descriptor located at the start address: %04lx\n"),
|
|---|
| 1138 | (unsigned long int) (abfd->start_address));
|
|---|
| 1139 | fprintf (file,
|
|---|
| 1140 | _("\tcode-base %08lx toc (loadable/actual) %08lx/%08lx\n"),
|
|---|
| 1141 | start_address, loadable_toc_address, toc_address);
|
|---|
| 1142 | }
|
|---|
| 1143 | else
|
|---|
| 1144 | {
|
|---|
| 1145 | fprintf (file,
|
|---|
| 1146 | _("\nNo reldata section! Function descriptor not decoded.\n"));
|
|---|
| 1147 | }
|
|---|
| 1148 | #endif
|
|---|
| 1149 |
|
|---|
| 1150 | fprintf (file,
|
|---|
| 1151 | _("\nThe Import Tables (interpreted %s section contents)\n"),
|
|---|
| 1152 | section->name);
|
|---|
| 1153 | fprintf (file,
|
|---|
| 1154 | _("\
|
|---|
| 1155 | vma: Hint Time Forward DLL First\n\
|
|---|
| 1156 | Table Stamp Chain Name Thunk\n"));
|
|---|
| 1157 |
|
|---|
| 1158 | amt = dataoff + datasize;
|
|---|
| 1159 | data = (bfd_byte *) bfd_malloc (amt);
|
|---|
| 1160 | if (data == NULL)
|
|---|
| 1161 | return FALSE;
|
|---|
| 1162 |
|
|---|
| 1163 | /* Read the whole section. Some of the fields might be before dataoff. */
|
|---|
| 1164 | if (! bfd_get_section_contents (abfd, section, (PTR) data, (bfd_vma) 0, amt))
|
|---|
| 1165 | return FALSE;
|
|---|
| 1166 |
|
|---|
| 1167 | adj = section->vma - extra->ImageBase;
|
|---|
| 1168 |
|
|---|
| 1169 | /* Print all image import descriptors. */
|
|---|
| 1170 | for (i = 0; i < datasize; i += onaline)
|
|---|
| 1171 | {
|
|---|
| 1172 | bfd_vma hint_addr;
|
|---|
| 1173 | bfd_vma time_stamp;
|
|---|
| 1174 | bfd_vma forward_chain;
|
|---|
| 1175 | bfd_vma dll_name;
|
|---|
| 1176 | bfd_vma first_thunk;
|
|---|
| 1177 | int idx = 0;
|
|---|
| 1178 | bfd_size_type j;
|
|---|
| 1179 | char *dll;
|
|---|
| 1180 |
|
|---|
| 1181 | /* Print (i + extra->DataDirectory[1].VirtualAddress). */
|
|---|
| 1182 | fprintf (file, " %08lx\t", (unsigned long) (i + adj + dataoff));
|
|---|
| 1183 | #if 0
|
|---|
| 1184 | if (i + 20 > datasize)
|
|---|
| 1185 | /* Check stuff. */
|
|---|
| 1186 | ;
|
|---|
| 1187 | #endif
|
|---|
| 1188 | hint_addr = bfd_get_32 (abfd, data + i + dataoff);
|
|---|
| 1189 | time_stamp = bfd_get_32 (abfd, data + i + 4 + dataoff);
|
|---|
| 1190 | forward_chain = bfd_get_32 (abfd, data + i + 8 + dataoff);
|
|---|
| 1191 | dll_name = bfd_get_32 (abfd, data + i + 12 + dataoff);
|
|---|
| 1192 | first_thunk = bfd_get_32 (abfd, data + i + 16 + dataoff);
|
|---|
| 1193 |
|
|---|
| 1194 | fprintf (file, "%08lx %08lx %08lx %08lx %08lx\n",
|
|---|
| 1195 | (unsigned long) hint_addr,
|
|---|
| 1196 | (unsigned long) time_stamp,
|
|---|
| 1197 | (unsigned long) forward_chain,
|
|---|
| 1198 | (unsigned long) dll_name,
|
|---|
| 1199 | (unsigned long) first_thunk);
|
|---|
| 1200 |
|
|---|
| 1201 | if (hint_addr == 0 && first_thunk == 0)
|
|---|
| 1202 | break;
|
|---|
| 1203 |
|
|---|
| 1204 | dll = (char *) data + dll_name - adj;
|
|---|
| 1205 | fprintf (file, _("\n\tDLL Name: %s\n"), dll);
|
|---|
| 1206 |
|
|---|
| 1207 | if (hint_addr != 0)
|
|---|
| 1208 | {
|
|---|
| 1209 | bfd_byte *ft_data;
|
|---|
| 1210 | asection *ft_section;
|
|---|
| 1211 | bfd_vma ft_addr;
|
|---|
| 1212 | bfd_size_type ft_datasize;
|
|---|
| 1213 | int ft_idx;
|
|---|
| 1214 | int ft_allocated = 0;
|
|---|
| 1215 |
|
|---|
| 1216 | fprintf (file, _("\tvma: Hint/Ord Member-Name Bound-To\n"));
|
|---|
| 1217 |
|
|---|
| 1218 | idx = hint_addr - adj;
|
|---|
| 1219 |
|
|---|
| 1220 | ft_addr = first_thunk + extra->ImageBase;
|
|---|
| 1221 | ft_data = data;
|
|---|
| 1222 | ft_idx = first_thunk - adj;
|
|---|
| 1223 | ft_allocated = 0;
|
|---|
| 1224 |
|
|---|
| 1225 | if (first_thunk != hint_addr)
|
|---|
| 1226 | {
|
|---|
| 1227 | /* Find the section which contains the first thunk. */
|
|---|
| 1228 | for (ft_section = abfd->sections;
|
|---|
| 1229 | ft_section != NULL;
|
|---|
| 1230 | ft_section = ft_section->next)
|
|---|
| 1231 | {
|
|---|
| 1232 | ft_datasize = bfd_section_size (abfd, ft_section);
|
|---|
| 1233 | if (ft_addr >= ft_section->vma
|
|---|
| 1234 | && ft_addr < ft_section->vma + ft_datasize)
|
|---|
| 1235 | break;
|
|---|
| 1236 | }
|
|---|
| 1237 |
|
|---|
| 1238 | if (ft_section == NULL)
|
|---|
| 1239 | {
|
|---|
| 1240 | fprintf (file,
|
|---|
| 1241 | _("\nThere is a first thunk, but the section containing it could not be found\n"));
|
|---|
| 1242 | continue;
|
|---|
| 1243 | }
|
|---|
| 1244 |
|
|---|
| 1245 | /* Now check to see if this section is the same as our current
|
|---|
| 1246 | section. If it is not then we will have to load its data in. */
|
|---|
| 1247 | if (ft_section == section)
|
|---|
| 1248 | {
|
|---|
| 1249 | ft_data = data;
|
|---|
| 1250 | ft_idx = first_thunk - adj;
|
|---|
| 1251 | }
|
|---|
| 1252 | else
|
|---|
| 1253 | {
|
|---|
| 1254 | ft_idx = first_thunk - (ft_section->vma - extra->ImageBase);
|
|---|
| 1255 | ft_data = (bfd_byte *) bfd_malloc (datasize);
|
|---|
| 1256 | if (ft_data == NULL)
|
|---|
| 1257 | continue;
|
|---|
| 1258 |
|
|---|
| 1259 | /* Read datasize bfd_bytes starting at offset ft_idx. */
|
|---|
| 1260 | if (! bfd_get_section_contents (abfd, ft_section,
|
|---|
| 1261 | (PTR) ft_data,
|
|---|
| 1262 | (bfd_vma) ft_idx,
|
|---|
| 1263 | datasize))
|
|---|
| 1264 | {
|
|---|
| 1265 | free (ft_data);
|
|---|
| 1266 | continue;
|
|---|
| 1267 | }
|
|---|
| 1268 |
|
|---|
| 1269 | ft_idx = 0;
|
|---|
| 1270 | ft_allocated = 1;
|
|---|
| 1271 | }
|
|---|
| 1272 | }
|
|---|
| 1273 |
|
|---|
| 1274 | /* Print HintName vector entries. */
|
|---|
| 1275 | for (j = 0; j < datasize; j += 4)
|
|---|
| 1276 | {
|
|---|
| 1277 | unsigned long member = bfd_get_32 (abfd, data + idx + j);
|
|---|
| 1278 |
|
|---|
| 1279 | /* Print single IMAGE_IMPORT_BY_NAME vector. */
|
|---|
| 1280 | if (member == 0)
|
|---|
| 1281 | break;
|
|---|
| 1282 |
|
|---|
| 1283 | if (member & 0x80000000)
|
|---|
| 1284 | fprintf (file, "\t%04lx\t %4lu <none>",
|
|---|
| 1285 | member, member & 0x7fffffff);
|
|---|
| 1286 | else
|
|---|
| 1287 | {
|
|---|
| 1288 | int ordinal;
|
|---|
| 1289 | char *member_name;
|
|---|
| 1290 |
|
|---|
| 1291 | ordinal = bfd_get_16 (abfd, data + member - adj);
|
|---|
| 1292 | member_name = (char *) data + member - adj + 2;
|
|---|
| 1293 | fprintf (file, "\t%04lx\t %4d %s",
|
|---|
| 1294 | member, ordinal, member_name);
|
|---|
| 1295 | }
|
|---|
| 1296 |
|
|---|
| 1297 | /* If the time stamp is not zero, the import address
|
|---|
| 1298 | table holds actual addresses. */
|
|---|
| 1299 | if (time_stamp != 0
|
|---|
| 1300 | && first_thunk != 0
|
|---|
| 1301 | && first_thunk != hint_addr)
|
|---|
| 1302 | fprintf (file, "\t%04lx",
|
|---|
| 1303 | (long) bfd_get_32 (abfd, ft_data + ft_idx + j));
|
|---|
| 1304 |
|
|---|
| 1305 | fprintf (file, "\n");
|
|---|
| 1306 | }
|
|---|
| 1307 |
|
|---|
| 1308 | if (ft_allocated)
|
|---|
| 1309 | free (ft_data);
|
|---|
| 1310 | }
|
|---|
| 1311 |
|
|---|
| 1312 | fprintf (file, "\n");
|
|---|
| 1313 | }
|
|---|
| 1314 |
|
|---|
| 1315 | free (data);
|
|---|
| 1316 |
|
|---|
| 1317 | return TRUE;
|
|---|
| 1318 | }
|
|---|
| 1319 |
|
|---|
| 1320 | static bfd_boolean
|
|---|
| 1321 | pe_print_edata (abfd, vfile)
|
|---|
| 1322 | bfd *abfd;
|
|---|
| 1323 | PTR vfile;
|
|---|
| 1324 | {
|
|---|
| 1325 | FILE *file = (FILE *) vfile;
|
|---|
| 1326 | bfd_byte *data;
|
|---|
| 1327 | asection *section;
|
|---|
| 1328 | bfd_size_type datasize = 0;
|
|---|
| 1329 | bfd_size_type dataoff;
|
|---|
| 1330 | bfd_size_type i;
|
|---|
| 1331 | bfd_signed_vma adj;
|
|---|
| 1332 | struct EDT_type
|
|---|
| 1333 | {
|
|---|
| 1334 | long export_flags; /* reserved - should be zero */
|
|---|
| 1335 | long time_stamp;
|
|---|
| 1336 | short major_ver;
|
|---|
| 1337 | short minor_ver;
|
|---|
| 1338 | bfd_vma name; /* rva - relative to image base */
|
|---|
| 1339 | long base; /* ordinal base */
|
|---|
| 1340 | unsigned long num_functions;/* Number in the export address table */
|
|---|
| 1341 | unsigned long num_names; /* Number in the name pointer table */
|
|---|
| 1342 | bfd_vma eat_addr; /* rva to the export address table */
|
|---|
| 1343 | bfd_vma npt_addr; /* rva to the Export Name Pointer Table */
|
|---|
| 1344 | bfd_vma ot_addr; /* rva to the Ordinal Table */
|
|---|
| 1345 | } edt;
|
|---|
| 1346 |
|
|---|
| 1347 | pe_data_type *pe = pe_data (abfd);
|
|---|
| 1348 | struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
|
|---|
| 1349 |
|
|---|
| 1350 | bfd_vma addr;
|
|---|
| 1351 |
|
|---|
| 1352 | addr = extra->DataDirectory[0].VirtualAddress;
|
|---|
| 1353 |
|
|---|
| 1354 | if (addr == 0 && extra->DataDirectory[0].Size == 0)
|
|---|
| 1355 | {
|
|---|
| 1356 | /* Maybe the extra header isn't there. Look for the section. */
|
|---|
| 1357 | section = bfd_get_section_by_name (abfd, ".edata");
|
|---|
| 1358 | if (section == NULL)
|
|---|
| 1359 | return TRUE;
|
|---|
| 1360 |
|
|---|
| 1361 | addr = section->vma;
|
|---|
| 1362 | datasize = bfd_section_size (abfd, section);
|
|---|
| 1363 | if (datasize == 0)
|
|---|
| 1364 | return TRUE;
|
|---|
| 1365 | }
|
|---|
| 1366 | else
|
|---|
| 1367 | {
|
|---|
| 1368 | addr += extra->ImageBase;
|
|---|
| 1369 |
|
|---|
| 1370 | for (section = abfd->sections; section != NULL; section = section->next)
|
|---|
| 1371 | {
|
|---|
| 1372 | datasize = bfd_section_size (abfd, section);
|
|---|
| 1373 |
|
|---|
| 1374 | if (addr >= section->vma && addr < section->vma + datasize)
|
|---|
| 1375 | break;
|
|---|
| 1376 | }
|
|---|
| 1377 |
|
|---|
| 1378 | if (section == NULL)
|
|---|
| 1379 | {
|
|---|
| 1380 | fprintf (file,
|
|---|
| 1381 | _("\nThere is an export table, but the section containing it could not be found\n"));
|
|---|
| 1382 | return TRUE;
|
|---|
| 1383 | }
|
|---|
| 1384 | }
|
|---|
| 1385 |
|
|---|
| 1386 | fprintf (file, _("\nThere is an export table in %s at 0x%lx\n"),
|
|---|
| 1387 | section->name, (unsigned long) addr);
|
|---|
| 1388 |
|
|---|
| 1389 | dataoff = addr - section->vma;
|
|---|
| 1390 | datasize -= dataoff;
|
|---|
| 1391 |
|
|---|
| 1392 | data = (bfd_byte *) bfd_malloc (datasize);
|
|---|
| 1393 | if (data == NULL)
|
|---|
| 1394 | return FALSE;
|
|---|
| 1395 |
|
|---|
| 1396 | if (! bfd_get_section_contents (abfd, section, (PTR) data,
|
|---|
| 1397 | (file_ptr) dataoff, datasize))
|
|---|
| 1398 | return FALSE;
|
|---|
| 1399 |
|
|---|
| 1400 | /* Go get Export Directory Table. */
|
|---|
| 1401 | edt.export_flags = bfd_get_32 (abfd, data + 0);
|
|---|
| 1402 | edt.time_stamp = bfd_get_32 (abfd, data + 4);
|
|---|
| 1403 | edt.major_ver = bfd_get_16 (abfd, data + 8);
|
|---|
| 1404 | edt.minor_ver = bfd_get_16 (abfd, data + 10);
|
|---|
| 1405 | edt.name = bfd_get_32 (abfd, data + 12);
|
|---|
| 1406 | edt.base = bfd_get_32 (abfd, data + 16);
|
|---|
| 1407 | edt.num_functions = bfd_get_32 (abfd, data + 20);
|
|---|
| 1408 | edt.num_names = bfd_get_32 (abfd, data + 24);
|
|---|
| 1409 | edt.eat_addr = bfd_get_32 (abfd, data + 28);
|
|---|
| 1410 | edt.npt_addr = bfd_get_32 (abfd, data + 32);
|
|---|
| 1411 | edt.ot_addr = bfd_get_32 (abfd, data + 36);
|
|---|
| 1412 |
|
|---|
| 1413 | adj = section->vma - extra->ImageBase + dataoff;
|
|---|
| 1414 |
|
|---|
| 1415 | /* Dump the EDT first. */
|
|---|
| 1416 | fprintf (file,
|
|---|
| 1417 | _("\nThe Export Tables (interpreted %s section contents)\n\n"),
|
|---|
| 1418 | section->name);
|
|---|
| 1419 |
|
|---|
| 1420 | fprintf (file,
|
|---|
| 1421 | _("Export Flags \t\t\t%lx\n"), (unsigned long) edt.export_flags);
|
|---|
| 1422 |
|
|---|
| 1423 | fprintf (file,
|
|---|
| 1424 | _("Time/Date stamp \t\t%lx\n"), (unsigned long) edt.time_stamp);
|
|---|
| 1425 |
|
|---|
| 1426 | fprintf (file,
|
|---|
| 1427 | _("Major/Minor \t\t\t%d/%d\n"), edt.major_ver, edt.minor_ver);
|
|---|
| 1428 |
|
|---|
| 1429 | fprintf (file,
|
|---|
| 1430 | _("Name \t\t\t\t"));
|
|---|
| 1431 | fprintf_vma (file, edt.name);
|
|---|
| 1432 | fprintf (file,
|
|---|
| 1433 | " %s\n", data + edt.name - adj);
|
|---|
| 1434 |
|
|---|
| 1435 | fprintf (file,
|
|---|
| 1436 | _("Ordinal Base \t\t\t%ld\n"), edt.base);
|
|---|
| 1437 |
|
|---|
| 1438 | fprintf (file,
|
|---|
| 1439 | _("Number in:\n"));
|
|---|
| 1440 |
|
|---|
| 1441 | fprintf (file,
|
|---|
| 1442 | _("\tExport Address Table \t\t%08lx\n"),
|
|---|
| 1443 | edt.num_functions);
|
|---|
| 1444 |
|
|---|
| 1445 | fprintf (file,
|
|---|
| 1446 | _("\t[Name Pointer/Ordinal] Table\t%08lx\n"), edt.num_names);
|
|---|
| 1447 |
|
|---|
| 1448 | fprintf (file,
|
|---|
| 1449 | _("Table Addresses\n"));
|
|---|
| 1450 |
|
|---|
| 1451 | fprintf (file,
|
|---|
| 1452 | _("\tExport Address Table \t\t"));
|
|---|
| 1453 | fprintf_vma (file, edt.eat_addr);
|
|---|
| 1454 | fprintf (file, "\n");
|
|---|
| 1455 |
|
|---|
| 1456 | fprintf (file,
|
|---|
| 1457 | _("\tName Pointer Table \t\t"));
|
|---|
| 1458 | fprintf_vma (file, edt.npt_addr);
|
|---|
| 1459 | fprintf (file, "\n");
|
|---|
| 1460 |
|
|---|
| 1461 | fprintf (file,
|
|---|
| 1462 | _("\tOrdinal Table \t\t\t"));
|
|---|
| 1463 | fprintf_vma (file, edt.ot_addr);
|
|---|
| 1464 | fprintf (file, "\n");
|
|---|
| 1465 |
|
|---|
| 1466 | /* The next table to find is the Export Address Table. It's basically
|
|---|
| 1467 | a list of pointers that either locate a function in this dll, or
|
|---|
| 1468 | forward the call to another dll. Something like:
|
|---|
| 1469 | typedef union
|
|---|
| 1470 | {
|
|---|
| 1471 | long export_rva;
|
|---|
| 1472 | long forwarder_rva;
|
|---|
| 1473 | } export_address_table_entry;
|
|---|
| 1474 | */
|
|---|
| 1475 |
|
|---|
| 1476 | fprintf (file,
|
|---|
| 1477 | _("\nExport Address Table -- Ordinal Base %ld\n"),
|
|---|
| 1478 | edt.base);
|
|---|
| 1479 |
|
|---|
| 1480 | for (i = 0; i < edt.num_functions; ++i)
|
|---|
| 1481 | {
|
|---|
| 1482 | bfd_vma eat_member = bfd_get_32 (abfd,
|
|---|
| 1483 | data + edt.eat_addr + (i * 4) - adj);
|
|---|
| 1484 | if (eat_member == 0)
|
|---|
| 1485 | continue;
|
|---|
| 1486 |
|
|---|
| 1487 | if (eat_member - adj <= datasize)
|
|---|
| 1488 | {
|
|---|
| 1489 | /* This rva is to a name (forwarding function) in our section. */
|
|---|
| 1490 | /* Should locate a function descriptor. */
|
|---|
| 1491 | fprintf (file,
|
|---|
| 1492 | "\t[%4ld] +base[%4ld] %04lx %s -- %s\n",
|
|---|
| 1493 | (long) i,
|
|---|
| 1494 | (long) (i + edt.base),
|
|---|
| 1495 | (unsigned long) eat_member,
|
|---|
| 1496 | _("Forwarder RVA"),
|
|---|
| 1497 | data + eat_member - adj);
|
|---|
| 1498 | }
|
|---|
| 1499 | else
|
|---|
| 1500 | {
|
|---|
| 1501 | /* Should locate a function descriptor in the reldata section. */
|
|---|
| 1502 | fprintf (file,
|
|---|
| 1503 | "\t[%4ld] +base[%4ld] %04lx %s\n",
|
|---|
| 1504 | (long) i,
|
|---|
| 1505 | (long) (i + edt.base),
|
|---|
| 1506 | (unsigned long) eat_member,
|
|---|
| 1507 | _("Export RVA"));
|
|---|
| 1508 | }
|
|---|
| 1509 | }
|
|---|
| 1510 |
|
|---|
| 1511 | /* The Export Name Pointer Table is paired with the Export Ordinal Table. */
|
|---|
| 1512 | /* Dump them in parallel for clarity. */
|
|---|
| 1513 | fprintf (file,
|
|---|
| 1514 | _("\n[Ordinal/Name Pointer] Table\n"));
|
|---|
| 1515 |
|
|---|
| 1516 | for (i = 0; i < edt.num_names; ++i)
|
|---|
| 1517 | {
|
|---|
| 1518 | bfd_vma name_ptr = bfd_get_32 (abfd,
|
|---|
| 1519 | data +
|
|---|
| 1520 | edt.npt_addr
|
|---|
| 1521 | + (i*4) - adj);
|
|---|
| 1522 |
|
|---|
| 1523 | char *name = (char *) data + name_ptr - adj;
|
|---|
| 1524 |
|
|---|
| 1525 | bfd_vma ord = bfd_get_16 (abfd,
|
|---|
| 1526 | data +
|
|---|
| 1527 | edt.ot_addr
|
|---|
| 1528 | + (i*2) - adj);
|
|---|
| 1529 | fprintf (file,
|
|---|
| 1530 | "\t[%4ld] %s\n", (long) ord, name);
|
|---|
| 1531 | }
|
|---|
| 1532 |
|
|---|
| 1533 | free (data);
|
|---|
| 1534 |
|
|---|
| 1535 | return TRUE;
|
|---|
| 1536 | }
|
|---|
| 1537 |
|
|---|
| 1538 | /* This really is architecture dependent. On IA-64, a .pdata entry
|
|---|
| 1539 | consists of three dwords containing relative virtual addresses that
|
|---|
| 1540 | specify the start and end address of the code range the entry
|
|---|
| 1541 | covers and the address of the corresponding unwind info data. */
|
|---|
| 1542 |
|
|---|
| 1543 | static bfd_boolean
|
|---|
| 1544 | pe_print_pdata (abfd, vfile)
|
|---|
| 1545 | bfd *abfd;
|
|---|
| 1546 | PTR vfile;
|
|---|
| 1547 | {
|
|---|
| 1548 | #ifdef COFF_WITH_pep
|
|---|
| 1549 | # define PDATA_ROW_SIZE (3*8)
|
|---|
| 1550 | #else
|
|---|
| 1551 | # define PDATA_ROW_SIZE (5*4)
|
|---|
| 1552 | #endif
|
|---|
| 1553 | FILE *file = (FILE *) vfile;
|
|---|
| 1554 | bfd_byte *data = 0;
|
|---|
| 1555 | asection *section = bfd_get_section_by_name (abfd, ".pdata");
|
|---|
| 1556 | bfd_size_type datasize = 0;
|
|---|
| 1557 | bfd_size_type i;
|
|---|
| 1558 | bfd_size_type start, stop;
|
|---|
| 1559 | int onaline = PDATA_ROW_SIZE;
|
|---|
| 1560 |
|
|---|
| 1561 | if (section == NULL
|
|---|
| 1562 | || coff_section_data (abfd, section) == NULL
|
|---|
| 1563 | || pei_section_data (abfd, section) == NULL)
|
|---|
| 1564 | return TRUE;
|
|---|
| 1565 |
|
|---|
| 1566 | stop = pei_section_data (abfd, section)->virt_size;
|
|---|
| 1567 | if ((stop % onaline) != 0)
|
|---|
| 1568 | fprintf (file,
|
|---|
| 1569 | _("Warning, .pdata section size (%ld) is not a multiple of %d\n"),
|
|---|
| 1570 | (long) stop, onaline);
|
|---|
| 1571 |
|
|---|
| 1572 | fprintf (file,
|
|---|
| 1573 | _("\nThe Function Table (interpreted .pdata section contents)\n"));
|
|---|
| 1574 | #ifdef COFF_WITH_pep
|
|---|
| 1575 | fprintf (file,
|
|---|
| 1576 | _(" vma:\t\t\tBegin Address End Address Unwind Info\n"));
|
|---|
| 1577 | #else
|
|---|
| 1578 | fprintf (file, _("\
|
|---|
| 1579 | vma:\t\tBegin End EH EH PrologEnd Exception\n\
|
|---|
| 1580 | \t\tAddress Address Handler Data Address Mask\n"));
|
|---|
| 1581 | #endif
|
|---|
| 1582 |
|
|---|
| 1583 | datasize = bfd_section_size (abfd, section);
|
|---|
| 1584 | if (datasize == 0)
|
|---|
| 1585 | return TRUE;
|
|---|
| 1586 |
|
|---|
| 1587 | data = (bfd_byte *) bfd_malloc (datasize);
|
|---|
| 1588 | if (data == NULL && datasize != 0)
|
|---|
| 1589 | return FALSE;
|
|---|
| 1590 |
|
|---|
| 1591 | bfd_get_section_contents (abfd, section, (PTR) data, (bfd_vma) 0,
|
|---|
| 1592 | datasize);
|
|---|
| 1593 |
|
|---|
| 1594 | start = 0;
|
|---|
| 1595 |
|
|---|
| 1596 | for (i = start; i < stop; i += onaline)
|
|---|
| 1597 | {
|
|---|
| 1598 | bfd_vma begin_addr;
|
|---|
| 1599 | bfd_vma end_addr;
|
|---|
| 1600 | bfd_vma eh_handler;
|
|---|
| 1601 | bfd_vma eh_data;
|
|---|
| 1602 | bfd_vma prolog_end_addr;
|
|---|
| 1603 | int em_data;
|
|---|
| 1604 |
|
|---|
| 1605 | if (i + PDATA_ROW_SIZE > stop)
|
|---|
| 1606 | break;
|
|---|
| 1607 |
|
|---|
| 1608 | begin_addr = GET_PDATA_ENTRY (abfd, data + i );
|
|---|
| 1609 | end_addr = GET_PDATA_ENTRY (abfd, data + i + 4);
|
|---|
| 1610 | eh_handler = GET_PDATA_ENTRY (abfd, data + i + 8);
|
|---|
| 1611 | eh_data = GET_PDATA_ENTRY (abfd, data + i + 12);
|
|---|
| 1612 | prolog_end_addr = GET_PDATA_ENTRY (abfd, data + i + 16);
|
|---|
| 1613 |
|
|---|
| 1614 | if (begin_addr == 0 && end_addr == 0 && eh_handler == 0
|
|---|
| 1615 | && eh_data == 0 && prolog_end_addr == 0)
|
|---|
| 1616 | /* We are probably into the padding of the section now. */
|
|---|
| 1617 | break;
|
|---|
| 1618 |
|
|---|
| 1619 | em_data = ((eh_handler & 0x1) << 2) | (prolog_end_addr & 0x3);
|
|---|
| 1620 | eh_handler &= ~(bfd_vma) 0x3;
|
|---|
| 1621 | prolog_end_addr &= ~(bfd_vma) 0x3;
|
|---|
| 1622 |
|
|---|
| 1623 | fputc (' ', file);
|
|---|
| 1624 | fprintf_vma (file, i + section->vma); fputc ('\t', file);
|
|---|
| 1625 | fprintf_vma (file, begin_addr); fputc (' ', file);
|
|---|
| 1626 | fprintf_vma (file, end_addr); fputc (' ', file);
|
|---|
| 1627 | fprintf_vma (file, eh_handler);
|
|---|
| 1628 | #ifndef COFF_WITH_pep
|
|---|
| 1629 | fputc (' ', file);
|
|---|
| 1630 | fprintf_vma (file, eh_data); fputc (' ', file);
|
|---|
| 1631 | fprintf_vma (file, prolog_end_addr);
|
|---|
| 1632 | fprintf (file, " %x", em_data);
|
|---|
| 1633 | #endif
|
|---|
| 1634 |
|
|---|
| 1635 | #ifdef POWERPC_LE_PE
|
|---|
| 1636 | if (eh_handler == 0 && eh_data != 0)
|
|---|
| 1637 | {
|
|---|
| 1638 | /* Special bits here, although the meaning may be a little
|
|---|
| 1639 | mysterious. The only one I know for sure is 0x03. */
|
|---|
| 1640 | /* Code Significance */
|
|---|
| 1641 | /* 0x00 None */
|
|---|
| 1642 | /* 0x01 Register Save Millicode */
|
|---|
| 1643 | /* 0x02 Register Restore Millicode */
|
|---|
| 1644 | /* 0x03 Glue Code Sequence */
|
|---|
| 1645 | switch (eh_data)
|
|---|
| 1646 | {
|
|---|
| 1647 | case 0x01:
|
|---|
| 1648 | fprintf (file, _(" Register save millicode"));
|
|---|
| 1649 | break;
|
|---|
| 1650 | case 0x02:
|
|---|
| 1651 | fprintf (file, _(" Register restore millicode"));
|
|---|
| 1652 | break;
|
|---|
| 1653 | case 0x03:
|
|---|
| 1654 | fprintf (file, _(" Glue code sequence"));
|
|---|
| 1655 | break;
|
|---|
| 1656 | default:
|
|---|
| 1657 | break;
|
|---|
| 1658 | }
|
|---|
| 1659 | }
|
|---|
| 1660 | #endif
|
|---|
| 1661 | fprintf (file, "\n");
|
|---|
| 1662 | }
|
|---|
| 1663 |
|
|---|
| 1664 | free (data);
|
|---|
| 1665 |
|
|---|
| 1666 | return TRUE;
|
|---|
| 1667 | }
|
|---|
| 1668 |
|
|---|
| 1669 | #define IMAGE_REL_BASED_HIGHADJ 4
|
|---|
| 1670 | static const char * const tbl[] =
|
|---|
| 1671 | {
|
|---|
| 1672 | "ABSOLUTE",
|
|---|
| 1673 | "HIGH",
|
|---|
| 1674 | "LOW",
|
|---|
| 1675 | "HIGHLOW",
|
|---|
| 1676 | "HIGHADJ",
|
|---|
| 1677 | "MIPS_JMPADDR",
|
|---|
| 1678 | "SECTION",
|
|---|
| 1679 | "REL32",
|
|---|
| 1680 | "RESERVED1",
|
|---|
| 1681 | "MIPS_JMPADDR16",
|
|---|
| 1682 | "DIR64",
|
|---|
| 1683 | "HIGH3ADJ"
|
|---|
| 1684 | "UNKNOWN", /* MUST be last */
|
|---|
| 1685 | };
|
|---|
| 1686 |
|
|---|
| 1687 | static bfd_boolean
|
|---|
| 1688 | pe_print_reloc (abfd, vfile)
|
|---|
| 1689 | bfd *abfd;
|
|---|
| 1690 | PTR vfile;
|
|---|
| 1691 | {
|
|---|
| 1692 | FILE *file = (FILE *) vfile;
|
|---|
| 1693 | bfd_byte *data = 0;
|
|---|
| 1694 | asection *section = bfd_get_section_by_name (abfd, ".reloc");
|
|---|
| 1695 | bfd_size_type datasize;
|
|---|
| 1696 | bfd_size_type i;
|
|---|
| 1697 | bfd_size_type start, stop;
|
|---|
| 1698 |
|
|---|
| 1699 | if (section == NULL)
|
|---|
| 1700 | return TRUE;
|
|---|
| 1701 |
|
|---|
| 1702 | if (bfd_section_size (abfd, section) == 0)
|
|---|
| 1703 | return TRUE;
|
|---|
| 1704 |
|
|---|
| 1705 | fprintf (file,
|
|---|
| 1706 | _("\n\nPE File Base Relocations (interpreted .reloc section contents)\n"));
|
|---|
| 1707 |
|
|---|
| 1708 | datasize = bfd_section_size (abfd, section);
|
|---|
| 1709 | data = (bfd_byte *) bfd_malloc (datasize);
|
|---|
| 1710 | if (data == NULL && datasize != 0)
|
|---|
| 1711 | return FALSE;
|
|---|
| 1712 |
|
|---|
| 1713 | bfd_get_section_contents (abfd, section, (PTR) data, (bfd_vma) 0,
|
|---|
| 1714 | datasize);
|
|---|
| 1715 |
|
|---|
| 1716 | start = 0;
|
|---|
| 1717 |
|
|---|
| 1718 | stop = bfd_section_size (abfd, section);
|
|---|
| 1719 |
|
|---|
| 1720 | for (i = start; i < stop;)
|
|---|
| 1721 | {
|
|---|
| 1722 | int j;
|
|---|
| 1723 | bfd_vma virtual_address;
|
|---|
| 1724 | long number, size;
|
|---|
| 1725 |
|
|---|
| 1726 | /* The .reloc section is a sequence of blocks, with a header consisting
|
|---|
| 1727 | of two 32 bit quantities, followed by a number of 16 bit entries. */
|
|---|
| 1728 | virtual_address = bfd_get_32 (abfd, data+i);
|
|---|
| 1729 | size = bfd_get_32 (abfd, data+i+4);
|
|---|
| 1730 | number = (size - 8) / 2;
|
|---|
| 1731 |
|
|---|
| 1732 | if (size == 0)
|
|---|
| 1733 | break;
|
|---|
| 1734 |
|
|---|
| 1735 | fprintf (file,
|
|---|
| 1736 | _("\nVirtual Address: %08lx Chunk size %ld (0x%lx) Number of fixups %ld\n"),
|
|---|
| 1737 | (unsigned long) virtual_address, size, size, number);
|
|---|
| 1738 |
|
|---|
| 1739 | for (j = 0; j < number; ++j)
|
|---|
| 1740 | {
|
|---|
| 1741 | unsigned short e = bfd_get_16 (abfd, data + i + 8 + j * 2);
|
|---|
| 1742 | unsigned int t = (e & 0xF000) >> 12;
|
|---|
| 1743 | int off = e & 0x0FFF;
|
|---|
| 1744 |
|
|---|
| 1745 | if (t >= sizeof (tbl) / sizeof (tbl[0]))
|
|---|
| 1746 | t = (sizeof (tbl) / sizeof (tbl[0])) - 1;
|
|---|
| 1747 |
|
|---|
| 1748 | fprintf (file,
|
|---|
| 1749 | _("\treloc %4d offset %4x [%4lx] %s"),
|
|---|
| 1750 | j, off, (long) (off + virtual_address), tbl[t]);
|
|---|
| 1751 |
|
|---|
| 1752 | /* HIGHADJ takes an argument, - the next record *is* the
|
|---|
| 1753 | low 16 bits of addend. */
|
|---|
| 1754 | if (t == IMAGE_REL_BASED_HIGHADJ)
|
|---|
| 1755 | {
|
|---|
| 1756 | fprintf (file, " (%4x)",
|
|---|
| 1757 | ((unsigned int)
|
|---|
| 1758 | bfd_get_16 (abfd, data + i + 8 + j * 2 + 2)));
|
|---|
| 1759 | j++;
|
|---|
| 1760 | }
|
|---|
| 1761 |
|
|---|
| 1762 | fprintf (file, "\n");
|
|---|
| 1763 | }
|
|---|
| 1764 |
|
|---|
| 1765 | i += size;
|
|---|
| 1766 | }
|
|---|
| 1767 |
|
|---|
| 1768 | free (data);
|
|---|
| 1769 |
|
|---|
| 1770 | return TRUE;
|
|---|
| 1771 | }
|
|---|
| 1772 |
|
|---|
| 1773 | /* Print out the program headers. */
|
|---|
| 1774 |
|
|---|
| 1775 | bfd_boolean
|
|---|
| 1776 | _bfd_XX_print_private_bfd_data_common (abfd, vfile)
|
|---|
| 1777 | bfd *abfd;
|
|---|
| 1778 | PTR vfile;
|
|---|
| 1779 | {
|
|---|
| 1780 | FILE *file = (FILE *) vfile;
|
|---|
| 1781 | int j;
|
|---|
| 1782 | pe_data_type *pe = pe_data (abfd);
|
|---|
| 1783 | struct internal_extra_pe_aouthdr *i = &pe->pe_opthdr;
|
|---|
| 1784 | const char *subsystem_name = NULL;
|
|---|
| 1785 |
|
|---|
| 1786 | /* The MS dumpbin program reportedly ands with 0xff0f before
|
|---|
| 1787 | printing the characteristics field. Not sure why. No reason to
|
|---|
| 1788 | emulate it here. */
|
|---|
| 1789 | fprintf (file, _("\nCharacteristics 0x%x\n"), pe->real_flags);
|
|---|
| 1790 | #undef PF
|
|---|
| 1791 | #define PF(x, y) if (pe->real_flags & x) { fprintf (file, "\t%s\n", y); }
|
|---|
| 1792 | PF (F_RELFLG, "relocations stripped");
|
|---|
| 1793 | PF (F_EXEC, "executable");
|
|---|
| 1794 | PF (F_LNNO, "line numbers stripped");
|
|---|
| 1795 | PF (F_LSYMS, "symbols stripped");
|
|---|
| 1796 | PF (0x80, "little endian");
|
|---|
| 1797 | PF (F_AR32WR, "32 bit words");
|
|---|
| 1798 | PF (0x200, "debugging information removed");
|
|---|
| 1799 | PF (0x1000, "system file");
|
|---|
| 1800 | PF (F_DLL, "DLL");
|
|---|
| 1801 | PF (0x8000, "big endian");
|
|---|
| 1802 | #undef PF
|
|---|
| 1803 |
|
|---|
| 1804 | /* ctime implies '\n'. */
|
|---|
| 1805 | {
|
|---|
| 1806 | time_t t = pe->coff.timestamp;
|
|---|
| 1807 | fprintf (file, "\nTime/Date\t\t%s", ctime (&t));
|
|---|
| 1808 | }
|
|---|
| 1809 | fprintf (file, "\nImageBase\t\t");
|
|---|
| 1810 | fprintf_vma (file, i->ImageBase);
|
|---|
| 1811 | fprintf (file, "\nSectionAlignment\t");
|
|---|
| 1812 | fprintf_vma (file, i->SectionAlignment);
|
|---|
| 1813 | fprintf (file, "\nFileAlignment\t\t");
|
|---|
| 1814 | fprintf_vma (file, i->FileAlignment);
|
|---|
| 1815 | fprintf (file, "\nMajorOSystemVersion\t%d\n", i->MajorOperatingSystemVersion);
|
|---|
| 1816 | fprintf (file, "MinorOSystemVersion\t%d\n", i->MinorOperatingSystemVersion);
|
|---|
| 1817 | fprintf (file, "MajorImageVersion\t%d\n", i->MajorImageVersion);
|
|---|
| 1818 | fprintf (file, "MinorImageVersion\t%d\n", i->MinorImageVersion);
|
|---|
| 1819 | fprintf (file, "MajorSubsystemVersion\t%d\n", i->MajorSubsystemVersion);
|
|---|
| 1820 | fprintf (file, "MinorSubsystemVersion\t%d\n", i->MinorSubsystemVersion);
|
|---|
| 1821 | fprintf (file, "Win32Version\t\t%08lx\n", i->Reserved1);
|
|---|
| 1822 | fprintf (file, "SizeOfImage\t\t%08lx\n", i->SizeOfImage);
|
|---|
| 1823 | fprintf (file, "SizeOfHeaders\t\t%08lx\n", i->SizeOfHeaders);
|
|---|
| 1824 | fprintf (file, "CheckSum\t\t%08lx\n", i->CheckSum);
|
|---|
| 1825 |
|
|---|
| 1826 | switch (i->Subsystem)
|
|---|
| 1827 | {
|
|---|
| 1828 | case IMAGE_SUBSYSTEM_UNKNOWN:
|
|---|
| 1829 | subsystem_name = "unspecified";
|
|---|
| 1830 | break;
|
|---|
| 1831 | case IMAGE_SUBSYSTEM_NATIVE:
|
|---|
| 1832 | subsystem_name = "NT native";
|
|---|
| 1833 | break;
|
|---|
| 1834 | case IMAGE_SUBSYSTEM_WINDOWS_GUI:
|
|---|
| 1835 | subsystem_name = "Windows GUI";
|
|---|
| 1836 | break;
|
|---|
| 1837 | case IMAGE_SUBSYSTEM_WINDOWS_CUI:
|
|---|
| 1838 | subsystem_name = "Windows CUI";
|
|---|
| 1839 | break;
|
|---|
| 1840 | case IMAGE_SUBSYSTEM_POSIX_CUI:
|
|---|
| 1841 | subsystem_name = "POSIX CUI";
|
|---|
| 1842 | break;
|
|---|
| 1843 | case IMAGE_SUBSYSTEM_WINDOWS_CE_GUI:
|
|---|
| 1844 | subsystem_name = "Wince CUI";
|
|---|
| 1845 | break;
|
|---|
| 1846 | case IMAGE_SUBSYSTEM_EFI_APPLICATION:
|
|---|
| 1847 | subsystem_name = "EFI application";
|
|---|
| 1848 | break;
|
|---|
| 1849 | case IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER:
|
|---|
| 1850 | subsystem_name = "EFI boot service driver";
|
|---|
| 1851 | break;
|
|---|
| 1852 | case IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER:
|
|---|
| 1853 | subsystem_name = "EFI runtime driver";
|
|---|
| 1854 | break;
|
|---|
| 1855 | }
|
|---|
| 1856 |
|
|---|
| 1857 | fprintf (file, "Subsystem\t\t%08x", i->Subsystem);
|
|---|
| 1858 | if (subsystem_name)
|
|---|
| 1859 | fprintf (file, "\t(%s)", subsystem_name);
|
|---|
| 1860 | fprintf (file, "\nDllCharacteristics\t%08x\n", i->DllCharacteristics);
|
|---|
| 1861 | fprintf (file, "SizeOfStackReserve\t");
|
|---|
| 1862 | fprintf_vma (file, i->SizeOfStackReserve);
|
|---|
| 1863 | fprintf (file, "\nSizeOfStackCommit\t");
|
|---|
| 1864 | fprintf_vma (file, i->SizeOfStackCommit);
|
|---|
| 1865 | fprintf (file, "\nSizeOfHeapReserve\t");
|
|---|
| 1866 | fprintf_vma (file, i->SizeOfHeapReserve);
|
|---|
| 1867 | fprintf (file, "\nSizeOfHeapCommit\t");
|
|---|
| 1868 | fprintf_vma (file, i->SizeOfHeapCommit);
|
|---|
| 1869 | fprintf (file, "\nLoaderFlags\t\t%08lx\n", i->LoaderFlags);
|
|---|
| 1870 | fprintf (file, "NumberOfRvaAndSizes\t%08lx\n", i->NumberOfRvaAndSizes);
|
|---|
| 1871 |
|
|---|
| 1872 | fprintf (file, "\nThe Data Directory\n");
|
|---|
| 1873 | for (j = 0; j < IMAGE_NUMBEROF_DIRECTORY_ENTRIES; j++)
|
|---|
| 1874 | {
|
|---|
| 1875 | fprintf (file, "Entry %1x ", j);
|
|---|
| 1876 | fprintf_vma (file, i->DataDirectory[j].VirtualAddress);
|
|---|
| 1877 | fprintf (file, " %08lx ", i->DataDirectory[j].Size);
|
|---|
| 1878 | fprintf (file, "%s\n", dir_names[j]);
|
|---|
| 1879 | }
|
|---|
| 1880 |
|
|---|
| 1881 | pe_print_idata (abfd, vfile);
|
|---|
| 1882 | pe_print_edata (abfd, vfile);
|
|---|
| 1883 | pe_print_pdata (abfd, vfile);
|
|---|
| 1884 | pe_print_reloc (abfd, vfile);
|
|---|
| 1885 |
|
|---|
| 1886 | return TRUE;
|
|---|
| 1887 | }
|
|---|
| 1888 |
|
|---|
| 1889 | /* Copy any private info we understand from the input bfd
|
|---|
| 1890 | to the output bfd. */
|
|---|
| 1891 |
|
|---|
| 1892 | bfd_boolean
|
|---|
| 1893 | _bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd)
|
|---|
| 1894 | bfd *ibfd, *obfd;
|
|---|
| 1895 | {
|
|---|
| 1896 | /* One day we may try to grok other private data. */
|
|---|
| 1897 | if (ibfd->xvec->flavour != bfd_target_coff_flavour
|
|---|
| 1898 | || obfd->xvec->flavour != bfd_target_coff_flavour)
|
|---|
| 1899 | return TRUE;
|
|---|
| 1900 |
|
|---|
| 1901 | pe_data (obfd)->pe_opthdr = pe_data (ibfd)->pe_opthdr;
|
|---|
| 1902 | pe_data (obfd)->dll = pe_data (ibfd)->dll;
|
|---|
| 1903 |
|
|---|
| 1904 | /* For strip: if we removed .reloc, we'll make a real mess of things
|
|---|
| 1905 | if we don't remove this entry as well. */
|
|---|
| 1906 | if (! pe_data (obfd)->has_reloc_section)
|
|---|
| 1907 | {
|
|---|
| 1908 | pe_data (obfd)->pe_opthdr.DataDirectory[5].VirtualAddress = 0;
|
|---|
| 1909 | pe_data (obfd)->pe_opthdr.DataDirectory[5].Size = 0;
|
|---|
| 1910 | }
|
|---|
| 1911 | return TRUE;
|
|---|
| 1912 | }
|
|---|
| 1913 |
|
|---|
| 1914 | /* Copy private section data. */
|
|---|
| 1915 |
|
|---|
| 1916 | bfd_boolean
|
|---|
| 1917 | _bfd_XX_bfd_copy_private_section_data (ibfd, isec, obfd, osec)
|
|---|
| 1918 | bfd *ibfd;
|
|---|
| 1919 | asection *isec;
|
|---|
| 1920 | bfd *obfd;
|
|---|
| 1921 | asection *osec;
|
|---|
| 1922 | {
|
|---|
| 1923 | if (bfd_get_flavour (ibfd) != bfd_target_coff_flavour
|
|---|
| 1924 | || bfd_get_flavour (obfd) != bfd_target_coff_flavour)
|
|---|
| 1925 | return TRUE;
|
|---|
| 1926 |
|
|---|
| 1927 | if (coff_section_data (ibfd, isec) != NULL
|
|---|
| 1928 | && pei_section_data (ibfd, isec) != NULL)
|
|---|
| 1929 | {
|
|---|
| 1930 | if (coff_section_data (obfd, osec) == NULL)
|
|---|
| 1931 | {
|
|---|
| 1932 | bfd_size_type amt = sizeof (struct coff_section_tdata);
|
|---|
| 1933 | osec->used_by_bfd = (PTR) bfd_zalloc (obfd, amt);
|
|---|
| 1934 | if (osec->used_by_bfd == NULL)
|
|---|
| 1935 | return FALSE;
|
|---|
| 1936 | }
|
|---|
| 1937 |
|
|---|
| 1938 | if (pei_section_data (obfd, osec) == NULL)
|
|---|
| 1939 | {
|
|---|
| 1940 | bfd_size_type amt = sizeof (struct pei_section_tdata);
|
|---|
| 1941 | coff_section_data (obfd, osec)->tdata = (PTR) bfd_zalloc (obfd, amt);
|
|---|
| 1942 | if (coff_section_data (obfd, osec)->tdata == NULL)
|
|---|
| 1943 | return FALSE;
|
|---|
| 1944 | }
|
|---|
| 1945 |
|
|---|
| 1946 | pei_section_data (obfd, osec)->virt_size =
|
|---|
| 1947 | pei_section_data (ibfd, isec)->virt_size;
|
|---|
| 1948 | pei_section_data (obfd, osec)->pe_flags =
|
|---|
| 1949 | pei_section_data (ibfd, isec)->pe_flags;
|
|---|
| 1950 | }
|
|---|
| 1951 |
|
|---|
| 1952 | return TRUE;
|
|---|
| 1953 | }
|
|---|
| 1954 |
|
|---|
| 1955 | void
|
|---|
| 1956 | _bfd_XX_get_symbol_info (abfd, symbol, ret)
|
|---|
| 1957 | bfd *abfd;
|
|---|
| 1958 | asymbol *symbol;
|
|---|
| 1959 | symbol_info *ret;
|
|---|
| 1960 | {
|
|---|
| 1961 | coff_get_symbol_info (abfd, symbol, ret);
|
|---|
| 1962 | #if 0 /* This code no longer appears to be necessary.
|
|---|
| 1963 | ImageBase has already been added in by coff_swap_scnhdr_in. */
|
|---|
| 1964 | if (pe_data (abfd) != NULL
|
|---|
| 1965 | && ((symbol->flags & BSF_DEBUGGING) == 0
|
|---|
| 1966 | || (symbol->flags & BSF_DEBUGGING_RELOC) != 0)
|
|---|
| 1967 | && ! bfd_is_abs_section (symbol->section))
|
|---|
| 1968 | ret->value += pe_data (abfd)->pe_opthdr.ImageBase;
|
|---|
| 1969 | #endif
|
|---|
| 1970 | }
|
|---|
| 1971 |
|
|---|
| 1972 | /* Handle the .idata section and other things that need symbol table
|
|---|
| 1973 | access. */
|
|---|
| 1974 |
|
|---|
| 1975 | bfd_boolean
|
|---|
| 1976 | _bfd_XXi_final_link_postscript (abfd, pfinfo)
|
|---|
| 1977 | bfd *abfd;
|
|---|
| 1978 | struct coff_final_link_info *pfinfo;
|
|---|
| 1979 | {
|
|---|
| 1980 | struct coff_link_hash_entry *h1;
|
|---|
| 1981 | struct bfd_link_info *info = pfinfo->info;
|
|---|
| 1982 |
|
|---|
| 1983 | /* There are a few fields that need to be filled in now while we
|
|---|
| 1984 | have symbol table access.
|
|---|
| 1985 |
|
|---|
| 1986 | The .idata subsections aren't directly available as sections, but
|
|---|
| 1987 | they are in the symbol table, so get them from there. */
|
|---|
| 1988 |
|
|---|
| 1989 | /* The import directory. This is the address of .idata$2, with size
|
|---|
| 1990 | of .idata$2 + .idata$3. */
|
|---|
| 1991 | h1 = coff_link_hash_lookup (coff_hash_table (info),
|
|---|
| 1992 | ".idata$2", FALSE, FALSE, TRUE);
|
|---|
| 1993 | if (h1 != NULL)
|
|---|
| 1994 | {
|
|---|
| 1995 | pe_data (abfd)->pe_opthdr.DataDirectory[1].VirtualAddress =
|
|---|
| 1996 | (h1->root.u.def.value
|
|---|
| 1997 | + h1->root.u.def.section->output_section->vma
|
|---|
| 1998 | + h1->root.u.def.section->output_offset);
|
|---|
| 1999 | h1 = coff_link_hash_lookup (coff_hash_table (info),
|
|---|
| 2000 | ".idata$4", FALSE, FALSE, TRUE);
|
|---|
| 2001 | pe_data (abfd)->pe_opthdr.DataDirectory[1].Size =
|
|---|
| 2002 | ((h1->root.u.def.value
|
|---|
| 2003 | + h1->root.u.def.section->output_section->vma
|
|---|
| 2004 | + h1->root.u.def.section->output_offset)
|
|---|
| 2005 | - pe_data (abfd)->pe_opthdr.DataDirectory[1].VirtualAddress);
|
|---|
| 2006 |
|
|---|
| 2007 | /* The import address table. This is the size/address of
|
|---|
| 2008 | .idata$5. */
|
|---|
| 2009 | h1 = coff_link_hash_lookup (coff_hash_table (info),
|
|---|
| 2010 | ".idata$5", FALSE, FALSE, TRUE);
|
|---|
| 2011 | pe_data (abfd)->pe_opthdr.DataDirectory[12].VirtualAddress =
|
|---|
| 2012 | (h1->root.u.def.value
|
|---|
| 2013 | + h1->root.u.def.section->output_section->vma
|
|---|
| 2014 | + h1->root.u.def.section->output_offset);
|
|---|
| 2015 | h1 = coff_link_hash_lookup (coff_hash_table (info),
|
|---|
| 2016 | ".idata$6", FALSE, FALSE, TRUE);
|
|---|
| 2017 | pe_data (abfd)->pe_opthdr.DataDirectory[12].Size =
|
|---|
| 2018 | ((h1->root.u.def.value
|
|---|
| 2019 | + h1->root.u.def.section->output_section->vma
|
|---|
| 2020 | + h1->root.u.def.section->output_offset)
|
|---|
| 2021 | - pe_data (abfd)->pe_opthdr.DataDirectory[12].VirtualAddress);
|
|---|
| 2022 | }
|
|---|
| 2023 |
|
|---|
| 2024 | /* If we couldn't find idata$2, we either have an excessively
|
|---|
| 2025 | trivial program or are in DEEP trouble; we have to assume trivial
|
|---|
| 2026 | program.... */
|
|---|
| 2027 | return TRUE;
|
|---|
| 2028 | }
|
|---|