From db344f829d3037e16a5246f17e85d42a06f8e518 Mon Sep 17 00:00:00 2001 From: Steve Chamberlain Date: Tue, 3 Oct 1995 23:44:34 +0000 Subject: [PATCH] Tue Oct 3 16:28:32 1995 steve chamberlain * coffcode.h (coff_bfd_copy_private_symbol_data, coff_bfd_copy_private_section_data, coff_bfd_copy_private_bfd_data): ifdef to allow overrides. * peicode.h (coff_bfd_copy_private_bfd_data): New (pe_bfd_copy_private_bfd_data): New. (coff_swap_scnhdr_in): Swap bss size into the right place. (pe_print_private_bfd_data): Add some newlines. --- bfd/ChangeLog | 10 ++++++ bfd/coffcode.h | 28 ++++++++++++---- bfd/peicode.h | 86 +++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 110 insertions(+), 14 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 8f6da0bdf9a..9e1655cbe9d 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,13 @@ +Tue Oct 3 16:28:32 1995 steve chamberlain + + * coffcode.h (coff_bfd_copy_private_symbol_data, + coff_bfd_copy_private_section_data, + coff_bfd_copy_private_bfd_data): ifdef to allow overrides. + * peicode.h (coff_bfd_copy_private_bfd_data): New + (pe_bfd_copy_private_bfd_data): New. + (coff_swap_scnhdr_in): Swap bss size into the right place. + (pe_print_private_bfd_data): Add some newlines. + Tue Oct 3 11:53:04 1995 Jeff Law (law@hurl) * som.c (setup_sections): Don't die if a space has no subspaces. diff --git a/bfd/coffcode.h b/bfd/coffcode.h index f636c0999f8..d85ae0bdac2 100644 --- a/bfd/coffcode.h +++ b/bfd/coffcode.h @@ -1078,8 +1078,18 @@ coff_set_arch_mach_hook (abfd, filehdr) case U802ROMAGIC: case U802WRMAGIC: case U802TOCMAGIC: +#ifdef POWERMAC + /* PowerPC Macs use the same magic numbers as RS/6000 (because + that's how they were bootstrapped originally), but they are + always PowerPC architecture. */ + arch = bfd_arch_powerpc; + machine = 601; +#else + /* FIXME The architecture and machine can now (as of AIX 4.1) be + identified by looking at fields in the a.out header. */ arch = bfd_arch_rs6000; machine = 6000; +#endif /* POWERMAC */ break; #endif @@ -2839,17 +2849,23 @@ static CONST bfd_coff_backend_data bfd_coff_std_swap_table = #define coff_bfd_free_cached_info _bfd_generic_bfd_free_cached_info #define coff_get_section_contents _bfd_generic_get_section_contents -#define coff_bfd_copy_private_symbol_data \ - _bfd_generic_bfd_copy_private_symbol_data -#define coff_bfd_copy_private_section_data \ - _bfd_generic_bfd_copy_private_section_data +#ifndef coff_bfd_copy_private_symbol_data +#define coff_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data +#endif + +#ifndef coff_bfd_copy_private_section_data +#define coff_bfd_copy_private_section_data _bfd_generic_bfd_copy_private_section_data +#endif + +#ifndef coff_bfd_copy_private_bfd_data #define coff_bfd_copy_private_bfd_data _bfd_generic_bfd_copy_private_bfd_data +#endif + #define coff_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data #define coff_bfd_set_private_flags _bfd_generic_bfd_set_private_flags #ifndef coff_bfd_print_private_bfd_data -#define coff_bfd_print_private_bfd_data \ - _bfd_generic_bfd_print_private_bfd_data +#define coff_bfd_print_private_bfd_data _bfd_generic_bfd_print_private_bfd_data #endif #ifndef coff_bfd_is_local_label diff --git a/bfd/peicode.h b/bfd/peicode.h index ab244e10ec9..af8d48b5002 100644 --- a/bfd/peicode.h +++ b/bfd/peicode.h @@ -235,6 +235,8 @@ coff_swap_filehdr_in (abfd, src, dst) filehdr_dst->f_flags = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_flags); } +#ifdef COFF_IMAGE_WITH_PE + static unsigned int coff_swap_filehdr_out (abfd, in, out) bfd *abfd; @@ -363,7 +365,30 @@ coff_swap_filehdr_out (abfd, in, out) return sizeof(FILHDR); } +#else +static unsigned int +coff_swap_filehdr_out (abfd, in, out) + bfd *abfd; + PTR in; + PTR out; +{ + struct internal_filehdr *filehdr_in = (struct internal_filehdr *)in; + FILHDR *filehdr_out = (FILHDR *)out; + + bfd_h_put_16(abfd, filehdr_in->f_magic, (bfd_byte *) filehdr_out->f_magic); + bfd_h_put_16(abfd, filehdr_in->f_nscns, (bfd_byte *) filehdr_out->f_nscns); + bfd_h_put_32(abfd, filehdr_in->f_timdat, (bfd_byte *) filehdr_out->f_timdat); + PUT_FILEHDR_SYMPTR (abfd, (bfd_vma) filehdr_in->f_symptr, + (bfd_byte *) filehdr_out->f_symptr); + bfd_h_put_32(abfd, filehdr_in->f_nsyms, (bfd_byte *) filehdr_out->f_nsyms); + bfd_h_put_16(abfd, filehdr_in->f_opthdr, (bfd_byte *) filehdr_out->f_opthdr); + bfd_h_put_16(abfd, filehdr_in->f_flags, (bfd_byte *) filehdr_out->f_flags); + + return sizeof(FILHDR); +} + +#endif static void @@ -891,6 +916,11 @@ static void { scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase; } + if (strcmp (scnhdr_int->s_name, _BSS) == 0) + { + scnhdr_int->s_size = scnhdr_int->s_paddr; + scnhdr_int->s_paddr = 0; + } } static unsigned int @@ -950,6 +980,11 @@ coff_swap_scnhdr_out (abfd, in, out) section data is ever generated, we must add IMAGE_SCN_MEM_DISCARDABLE (0x02000000). Also, the resource data should also be read and writable. */ + + /* FIXME: alignment is also encoded in this field, at least on ppc (krk) */ + /* FIXME: even worse, I don't see how to get the original alignment field*/ + /* back... */ + { int flags = scnhdr_int->s_flags; if (strcmp (scnhdr_int->s_name, ".data") == 0 || @@ -966,6 +1001,19 @@ coff_swap_scnhdr_out (abfd, in, out) else if (strcmp (scnhdr_int->s_name, ".rdata") == 0 || strcmp (scnhdr_int->s_name, ".edata") == 0) flags = IMAGE_SCN_MEM_READ | SEC_DATA; + /* ppc-nt additions */ + else if (strcmp (scnhdr_int->s_name, ".pdata") == 0) + flags = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_ALIGN_4BYTES | + IMAGE_SCN_MEM_READ ; + else if (strcmp (scnhdr_int->s_name, ".reldata") == 0) + flags = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_ALIGN_8BYTES | + IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE ; + else if (strcmp (scnhdr_int->s_name, ".ydata") == 0) + flags = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_ALIGN_8BYTES | + IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE ; + else if (strcmp (scnhdr_int->s_name, ".drectve") == 0) + flags = IMAGE_SCN_LNK_INFO | IMAGE_SCN_LNK_REMOVE ; + /* end of ppc-nt additions */ bfd_h_put_32(abfd, flags, (bfd_byte *) scnhdr_ext->s_flags); } @@ -1004,13 +1052,13 @@ pe_print_private_bfd_data (abfd, vfile) int j; pe_data_type *pe = pe_data (abfd); struct internal_extra_pe_aouthdr *i = &pe->pe_opthdr; - fprintf (file,"ImageBase\t\t"); + fprintf (file,"\nImageBase\t\t"); fprintf_vma (file, i->ImageBase); - fprintf (file,"SectionAlignment\t"); + fprintf (file,"\nSectionAlignment\t"); fprintf_vma (file, i->SectionAlignment); - fprintf (file,"FileAlignment\t\t"); + fprintf (file,"\nFileAlignment\t\t"); fprintf_vma (file, i->FileAlignment); - fprintf (file,"MajorOSystemVersion\t%d\n", i->MajorOperatingSystemVersion); + fprintf (file,"\nMajorOSystemVersion\t%d\n", i->MajorOperatingSystemVersion); fprintf (file,"MinorOSystemVersion\t%d\n", i->MinorOperatingSystemVersion); fprintf (file,"MajorImageVersion\t%d\n", i->MajorImageVersion); fprintf (file,"MinorImageVersion\t%d\n", i->MinorImageVersion); @@ -1024,13 +1072,13 @@ pe_print_private_bfd_data (abfd, vfile) fprintf (file,"DllCharacteristics\t%08x\n", i->DllCharacteristics); fprintf (file,"SizeOfStackReserve\t"); fprintf_vma (file, i->SizeOfStackReserve); - fprintf (file,"SizeOfStackCommit\t"); + fprintf (file,"\nSizeOfStackCommit\t"); fprintf_vma (file, i->SizeOfStackCommit); - fprintf (file,"SizeOfHeapReserve\t"); + fprintf (file,"\nSizeOfHeapReserve\t"); fprintf_vma (file, i->SizeOfHeapReserve); - fprintf (file,"SizeOfHeapCommit\t"); + fprintf (file,"\nSizeOfHeapCommit\t"); fprintf_vma (file, i->SizeOfHeapCommit); - fprintf (file,"LoaderFlags\t\t%08lx\n", i->LoaderFlags); + fprintf (file,"\nLoaderFlags\t\t%08lx\n", i->LoaderFlags); fprintf (file,"NumberOfRvaAndSizes\t%08lx\n", i->NumberOfRvaAndSizes); for (j = 0; j < IMAGE_NUMBEROF_DIRECTORY_ENTRIES; j++) @@ -1093,10 +1141,32 @@ pe_mkobject_hook (abfd, filehdr, aouthdr) obj_conv_table_size (abfd) = internal_f->f_nsyms; +#ifdef COFF_IMAGE_WITH_PE pe->pe_opthdr = ((struct internal_aouthdr *)aouthdr)->pe; +#endif + return (PTR) pe; } +/* Copy any private info we understand from the input bfd + to the output bfd. */ + +#define coff_bfd_copy_private_bfd_data pe_bfd_copy_private_bfd_data + +static boolean +pe_bfd_copy_private_bfd_data (ibfd, obfd) + bfd *ibfd, *obfd; +{ + /* One day we may try to grok other private data. */ + if (ibfd->xvec->flavour != bfd_target_coff_flavour + || obfd->xvec->flavour != bfd_target_coff_flavour) + return true; + + pe_data(obfd)->pe_opthdr = pe_data (ibfd)->pe_opthdr; + + return true; +} +