* configure.tgt: Set targ_emul to arm_wince_pe for ARM Windows CE targets.
[deliverable/binutils-gdb.git] / bfd / peXXigen.c
index 652e45c65bf8d4d3c7e7e8bc6fe0c4b606a59b13..70ad6cd71fcae346d845d0222bbb5161446355e8 100644 (file)
@@ -1,6 +1,6 @@
 /* Support for the generic parts of PE/PEI; the common executable parts.
    Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-   2005 Free Software Foundation, Inc.
+   2005, 2006 Free Software Foundation, Inc.
    Written by Cygnus Solutions.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -147,6 +147,7 @@ _bfd_XXi_swap_sym_in (bfd * abfd, void * ext1, void * in1)
          int unused_section_number = 0;
          asection *sec;
          char *name;
+         flagword flags;
 
          for (sec = abfd->sections; sec; sec = sec->next)
            if (unused_section_number <= sec->target_index)
@@ -156,7 +157,8 @@ _bfd_XXi_swap_sym_in (bfd * abfd, void * ext1, void * in1)
          if (name == NULL)
            return;
          strcpy (name, in->n_name);
-         sec = bfd_make_section_anyway (abfd, name);
+         flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_DATA | SEC_LOAD;
+         sec = bfd_make_section_anyway_with_flags (abfd, name, flags);
 
          sec->vma = 0;
          sec->lma = 0;
@@ -169,7 +171,6 @@ _bfd_XXi_swap_sym_in (bfd * abfd, void * ext1, void * in1)
          sec->userdata = NULL;
          sec->next = NULL;
          sec->alignment_power = 2;
-         sec->flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_DATA | SEC_LOAD;
 
          sec->target_index = unused_section_number;
 
@@ -1668,7 +1669,7 @@ static const char * const tbl[] =
   "RESERVED1",
   "MIPS_JMPADDR16",
   "DIR64",
-  "HIGH3ADJ"
+  "HIGH3ADJ",
   "UNKNOWN",   /* MUST be last.  */
 };
 
@@ -1949,6 +1950,7 @@ _bfd_XXi_final_link_postscript (bfd * abfd, struct coff_final_link_info *pfinfo)
 {
   struct coff_link_hash_entry *h1;
   struct bfd_link_info *info = pfinfo->info;
+  bfd_boolean result = TRUE;
 
   /* There are a few fields that need to be filled in now while we
      have symbol table access.
@@ -1962,49 +1964,103 @@ _bfd_XXi_final_link_postscript (bfd * abfd, struct coff_final_link_info *pfinfo)
                              ".idata$2", FALSE, FALSE, TRUE);
   if (h1 != NULL)
     {
-      pe_data (abfd)->pe_opthdr.DataDirectory[1].VirtualAddress =
-       (h1->root.u.def.value
-        + h1->root.u.def.section->output_section->vma
-        + h1->root.u.def.section->output_offset);
+      /* PR ld/2729: We cannot rely upon all the output sections having been 
+        created properly, so check before referencing them.  Issue a warning
+        message for any sections tht could not be found.  */
+      if (h1->root.u.def.section != NULL
+         && h1->root.u.def.section->output_section != NULL)
+       pe_data (abfd)->pe_opthdr.DataDirectory[1].VirtualAddress =
+         (h1->root.u.def.value
+          + h1->root.u.def.section->output_section->vma
+          + h1->root.u.def.section->output_offset);
+      else
+       {
+         _bfd_error_handler
+           (_("%B: unable to fill in DataDictionary[1] because .idata$2 is missing"), 
+            abfd);
+         result = FALSE;
+       }
+
       h1 = coff_link_hash_lookup (coff_hash_table (info),
                                  ".idata$4", FALSE, FALSE, TRUE);
-      pe_data (abfd)->pe_opthdr.DataDirectory[1].Size =
-       ((h1->root.u.def.value
-         + h1->root.u.def.section->output_section->vma
-         + h1->root.u.def.section->output_offset)
-        - pe_data (abfd)->pe_opthdr.DataDirectory[1].VirtualAddress);
+      if (h1 != NULL
+         && h1->root.u.def.section != NULL
+         && h1->root.u.def.section->output_section != NULL)
+       pe_data (abfd)->pe_opthdr.DataDirectory[1].Size =
+         ((h1->root.u.def.value
+           + h1->root.u.def.section->output_section->vma
+           + h1->root.u.def.section->output_offset)
+          - pe_data (abfd)->pe_opthdr.DataDirectory[1].VirtualAddress);
+      else
+       {
+         _bfd_error_handler
+           (_("%B: unable to fill in DataDictionary[1] because .idata$4 is missing"), 
+            abfd);
+         result = FALSE;
+       }
 
       /* The import address table.  This is the size/address of
          .idata$5.  */
       h1 = coff_link_hash_lookup (coff_hash_table (info),
                                  ".idata$5", FALSE, FALSE, TRUE);
-      pe_data (abfd)->pe_opthdr.DataDirectory[12].VirtualAddress =
-       (h1->root.u.def.value
-        + h1->root.u.def.section->output_section->vma
-        + h1->root.u.def.section->output_offset);
+      if (h1 != NULL
+         && h1->root.u.def.section != NULL
+         && h1->root.u.def.section->output_section != NULL)
+       pe_data (abfd)->pe_opthdr.DataDirectory[12].VirtualAddress =
+         (h1->root.u.def.value
+          + h1->root.u.def.section->output_section->vma
+          + h1->root.u.def.section->output_offset);
+      else
+       {
+         _bfd_error_handler
+           (_("%B: unable to fill in DataDictionary[12] because .idata$5 is missing"), 
+            abfd);
+         result = FALSE;
+       }
+
       h1 = coff_link_hash_lookup (coff_hash_table (info),
                                  ".idata$6", FALSE, FALSE, TRUE);
-      pe_data (abfd)->pe_opthdr.DataDirectory[12].Size =
-       ((h1->root.u.def.value
-         + h1->root.u.def.section->output_section->vma
-         + h1->root.u.def.section->output_offset)
-        - pe_data (abfd)->pe_opthdr.DataDirectory[12].VirtualAddress);      
+      if (h1 != NULL
+         && h1->root.u.def.section != NULL
+         && h1->root.u.def.section->output_section != NULL)
+       pe_data (abfd)->pe_opthdr.DataDirectory[12].Size =
+         ((h1->root.u.def.value
+           + h1->root.u.def.section->output_section->vma
+           + h1->root.u.def.section->output_offset)
+          - pe_data (abfd)->pe_opthdr.DataDirectory[12].VirtualAddress);      
+      else
+       {
+         _bfd_error_handler
+           (_("%B: unable to fill in DataDictionary[12] because .idata$6 is missing"), 
+            abfd);
+         result = FALSE;
+       }
     }
 
   h1 = coff_link_hash_lookup (coff_hash_table (info),
                              "__tls_used", FALSE, FALSE, TRUE);
   if (h1 != NULL)
     {
-      pe_data (abfd)->pe_opthdr.DataDirectory[9].VirtualAddress =
-       (h1->root.u.def.value
-        + h1->root.u.def.section->output_section->vma
-        + h1->root.u.def.section->output_offset
-        - pe_data (abfd)->pe_opthdr.ImageBase);
+      if (h1->root.u.def.section != NULL
+         && h1->root.u.def.section->output_section != NULL)
+       pe_data (abfd)->pe_opthdr.DataDirectory[9].VirtualAddress =
+         (h1->root.u.def.value
+          + h1->root.u.def.section->output_section->vma
+          + h1->root.u.def.section->output_offset
+          - pe_data (abfd)->pe_opthdr.ImageBase);
+      else
+       {
+         _bfd_error_handler
+           (_("%B: unable to fill in DataDictionary[9] because __tls_used is missing"), 
+            abfd);
+         result = FALSE;
+       }
+
       pe_data (abfd)->pe_opthdr.DataDirectory[9].Size = 0x18;
     }
 
   /* If we couldn't find idata$2, we either have an excessively
      trivial program or are in DEEP trouble; we have to assume trivial
      program....  */
-  return TRUE;
+  return result;
 }
This page took 0.028505 seconds and 4 git commands to generate.