From b9110a3c4f394a498400b729b866a2f31b0ab851 Mon Sep 17 00:00:00 2001 From: David Edelsohn Date: Thu, 20 Jun 1996 23:59:08 +0000 Subject: [PATCH] * coffcode.h (coff_set_alignment_hook): Change COFF_IMAGE_WITH_PE ifdef to COFF_WITH_PE. (coff_compute_section_file_positions): Likewise. (coff_write_object_contents): Likewise. Delete COFF_OBJ_WITH_PE. * pe-{arm,i386,ppc}.c (COFF_OBJ_WITH_PE): Delete. * peicode.h (pe_bfd_copy_private_bfd_data): Delete ifdef COFF_IMAGE_WITH_PE, always include. --- bfd/ChangeLog | 8 +++++ bfd/coffcode.h | 92 ++++++++++++++++++++++++++++++++++++++++++++++---- bfd/peicode.h | 33 +++++++++++++++--- 3 files changed, 122 insertions(+), 11 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 5a465019d4d..581a7f0678a 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -5,6 +5,14 @@ Thu Jun 20 18:14:25 1996 Ian Lance Taylor Thu Jun 20 11:00:57 1996 Doug Evans + * coffcode.h (coff_set_alignment_hook): Change COFF_IMAGE_WITH_PE + ifdef to COFF_WITH_PE. + (coff_compute_section_file_positions): Likewise. + (coff_write_object_contents): Likewise. Delete COFF_OBJ_WITH_PE. + * pe-{arm,i386,ppc}.c (COFF_OBJ_WITH_PE): Delete. + * peicode.h (pe_bfd_copy_private_bfd_data): Delete ifdef + COFF_IMAGE_WITH_PE, always include. + * peicode.h (coff_swap_scnhdr_out): ".drectve" doesn't have trailing 0. Wed Jun 19 11:37:52 1996 Ian Lance Taylor diff --git a/bfd/coffcode.h b/bfd/coffcode.h index 82447d3660a..af8a49fe417 100644 --- a/bfd/coffcode.h +++ b/bfd/coffcode.h @@ -1110,6 +1110,36 @@ coff_set_alignment_hook (abfd, section, scnhdr) section->alignment_power = 2; } #endif + +#ifdef COFF_WITH_PE + /* In a PE image file, the s_paddr field holds the virtual size of a + section, while the s_size field holds the raw size. */ + if (hdr->s_paddr != 0) + { + if (coff_section_data (abfd, section) == NULL) + { + section->used_by_bfd = + (PTR) bfd_zalloc (abfd, sizeof (struct coff_section_tdata)); + if (section->used_by_bfd == NULL) + { + /* FIXME: Return error. */ + abort (); + } + } + if (pei_section_data (abfd, section) == NULL) + { + coff_section_data (abfd, section)->tdata = + (PTR) bfd_zalloc (abfd, sizeof (struct pei_section_tdata)); + if (coff_section_data (abfd, section)->tdata == NULL) + { + /* FIXME: Return error. */ + abort (); + } + } + pei_section_data (abfd, section)->virt_size = hdr->s_paddr; + } +#endif + } #undef ALIGN_SET #undef ELIFALIGN_SET @@ -1469,6 +1499,17 @@ coff_set_arch_mach_hook (abfd, filehdr) break; #endif +/* start-sanitize-h8s */ +#ifdef H8300SMAGIC + case H8300SMAGIC: + arch = bfd_arch_h8300; + machine = bfd_mach_h8300s; + /* !! FIXME this probably isn't the right place for this */ + abfd->flags |= BFD_IS_RELAXABLE; + break; +#endif + +/* end-sanitize-h8s */ #ifdef SH_ARCH_MAGIC_BIG case SH_ARCH_MAGIC_BIG: case SH_ARCH_MAGIC_LITTLE: @@ -1919,6 +1960,11 @@ coff_set_flags (abfd, magicp, flagsp) case bfd_mach_h8300h: *magicp = H8300HMAGIC; return true; +/* start-sanitize-h8s */ + case bfd_mach_h8300s: + *magicp = H8300SMAGIC; + return true; +/* end-sanitize-h8s */ } break; #endif @@ -2140,10 +2186,33 @@ coff_compute_section_file_positions (abfd) #endif current->filepos = sofar; -#ifdef COFF_IMAGE_WITH_PE - /* With PE we have to pad each section to be a multiple of its page size - too, and remember both sizes. Cooked_size becomes very useful. */ - current->_cooked_size = current->_raw_size; +#ifdef COFF_WITH_PE + /* With PE we have to pad each section to be a multiple of its + page size too, and remember both sizes. */ + + if (coff_section_data (abfd, current) == NULL) + { + current->used_by_bfd = + (PTR) bfd_zalloc (abfd, sizeof (struct coff_section_tdata)); + if (current->used_by_bfd == NULL) + { + /* FIXME: Return error. */ + abort (); + } + } + if (pei_section_data (abfd, current) == NULL) + { + coff_section_data (abfd, current)->tdata = + (PTR) bfd_zalloc (abfd, sizeof (struct pei_section_tdata)); + if (coff_section_data (abfd, current)->tdata == NULL) + { + /* FIXME: Return error. */ + abort (); + } + } + if (pei_section_data (abfd, current)->virt_size == 0) + pei_section_data (abfd, current)->virt_size = current->_raw_size; + current->_raw_size = (current->_raw_size + page_size -1) & -page_size; #endif @@ -2269,6 +2338,7 @@ coff_write_object_contents (abfd) file_ptr sym_base; unsigned long reloc_size = 0; unsigned long lnno_size = 0; + boolean long_section_names; asection *text_sec = NULL; asection *data_sec = NULL; asection *bss_sec = NULL; @@ -2343,6 +2413,7 @@ coff_write_object_contents (abfd) if (bfd_seek (abfd, scn_base, SEEK_SET) != 0) return false; + long_section_names = false; for (current = abfd->sections; current != NULL; current = current->next) @@ -2376,6 +2447,7 @@ coff_write_object_contents (abfd) memset (section.s_name, 0, SCNNMLEN); sprintf (section.s_name, "/%lu", (unsigned long) string_size); string_size += len + 1; + long_section_names = true; } } #endif @@ -2392,7 +2464,12 @@ coff_write_object_contents (abfd) section.s_size = current->_raw_size; #ifdef COFF_WITH_PE - section.s_paddr = current->_cooked_size; + /* Reminder: s_paddr holds the virtual size of the section. */ + if (coff_section_data (abfd, current) != NULL + && pei_section_data (abfd, current) != NULL) + section.s_paddr = pei_section_data (abfd, current)->virt_size; + else + section.s_paddr = 0; #endif /* @@ -2763,7 +2840,10 @@ coff_write_object_contents (abfd) } else { - internal_f.f_symptr = 0; + if (long_section_names) + internal_f.f_symptr = sym_base; + else + internal_f.f_symptr = 0; internal_f.f_flags |= F_LSYMS; } diff --git a/bfd/peicode.h b/bfd/peicode.h index 213c20ce8eb..3a84b235169 100644 --- a/bfd/peicode.h +++ b/bfd/peicode.h @@ -23,7 +23,34 @@ Most of this hacked by Steve Chamberlain, sac@cygnus.com */ - +/* Hey look, some documentation [and in a place you expect to find it]! + + The main reference for the pei format is "Microsoft Portable Executable + and Common Object File Format Specification 4.1". Get it if you need to + do some serious hacking on this code. + + Another reference: + "Peering Inside the PE: A Tour of the Win32 Portable Executable + File Format", MSJ 1994, Volume 9. + + The *sole* difference between the pe format and the pei format is that the + latter has an MSDOS 2.0 .exe header on the front that prints the message + "This app must be run under Windows." (or some such). + (FIXME: Whether that statement is *really* true or not is unknown. + Are there more subtle differences between pe and pei formats? + For now assume there aren't. If you find one, then for God sakes + document it here!) + + The Microsoft docs use the word "image" instead of "executable" because + the former can also refer to a DLL (shared library). Confusion can arise + because the `i' in `pei' also refers to "image". The `pe' format can + also create images (i.e. executables), it's just that to run on a win32 + system you need to use the pei format. + + FIXME: Please add more docs here so the next poor fool that has to hack + on this code has a chance of getting something accomplished without + wasting too much time. +*/ #define coff_bfd_print_private_bfd_data pe_print_private_bfd_data #define coff_mkobject pe_mkobject @@ -1870,8 +1897,6 @@ pe_bfd_copy_private_bfd_data (ibfd, obfd) return true; } -#ifdef COFF_IMAGE_WITH_PE - /* Copy private section data. */ #define coff_bfd_copy_private_section_data pe_bfd_copy_private_section_data @@ -1909,5 +1934,3 @@ pe_bfd_copy_private_section_data (ibfd, isec, obfd, osec) return true; } - -#endif -- 2.30.2