Uniquefy gdb.base/catch-syscall.exp test names.
[deliverable/binutils-gdb.git] / bfd / peXXigen.c
index a5b7f68b902d91229dcd820fbc09993955f29a97..d0f7a96e1f96d6defed8ac6c3c941db092040c55 100644 (file)
@@ -461,7 +461,7 @@ _bfd_XXi_swap_aouthdr_in (bfd * abfd,
   {
     int idx;
 
-    for (idx = 0; idx < 16; idx++)
+    for (idx = 0; idx < a->NumberOfRvaAndSizes; idx++)
       {
         /* If data directory is empty, rva also should be 0.  */
        int size =
@@ -591,9 +591,6 @@ _bfd_XXi_swap_aouthdr_out (bfd * abfd, void * in, void * out)
 
   extra->NumberOfRvaAndSizes = IMAGE_NUMBEROF_DIRECTORY_ENTRIES;
 
-  /* First null out all data directory entries.  */
-  memset (extra->DataDirectory, 0, sizeof (extra->DataDirectory));
-
   add_data_entry (abfd, extra, 0, ".edata", ib);
   add_data_entry (abfd, extra, 2, ".rsrc", ib);
   add_data_entry (abfd, extra, 3, ".pdata", ib);
@@ -2418,7 +2415,9 @@ _bfd_XXi_final_link_postscript (bfd * abfd, struct coff_final_link_info *pfinfo)
     }
 
   h1 = coff_link_hash_lookup (coff_hash_table (info),
-                             "__tls_used", FALSE, FALSE, TRUE);
+                             (bfd_get_symbol_leading_char(abfd) != 0
+                              ? "__tls_used" : "_tls_used"),
+                             FALSE, FALSE, TRUE);
   if (h1 != NULL)
     {
       if ((h1->root.type == bfd_link_hash_defined
@@ -2437,8 +2436,15 @@ _bfd_XXi_final_link_postscript (bfd * abfd, struct coff_final_link_info *pfinfo)
             abfd);
          result = FALSE;
        }
-
+     /* According to PECOFF sepcifications by Microsoft version 8.2
+       the TLS data directory consists of 4 pointers, followed
+       by two 4-byte integer. This implies that the total size
+       is different for 32-bit and 64-bit executables.  */
+#if !defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64)
       pe_data (abfd)->pe_opthdr.DataDirectory[PE_TLS_TABLE].Size = 0x18;
+#else
+      pe_data (abfd)->pe_opthdr.DataDirectory[PE_TLS_TABLE].Size = 0x28;
+#endif
     }
 
 /* If there is a .pdata section and we have linked pdata finally, we
@@ -2449,15 +2455,23 @@ _bfd_XXi_final_link_postscript (bfd * abfd, struct coff_final_link_info *pfinfo)
 
     if (sec)
       {
-       bfd_size_type x = sec->rawsize ? sec->rawsize : sec->size;
+       bfd_size_type x = sec->rawsize;
+       bfd_byte *tmp_data = NULL;
+
+       if (x)
+         tmp_data = bfd_malloc (x);
 
-       if (x && bfd_get_section_contents (abfd, sec, pfinfo->contents, 0, x))
+       if (tmp_data != NULL)
          {
-           qsort (pfinfo->contents,
-                  (size_t) ((sec->size <x ? sec->size : x) / 12),
-                  12, sort_x64_pdata);
-           bfd_set_section_contents (pfinfo->output_bfd, sec,
-                                     pfinfo->contents, 0, x);
+           if (bfd_get_section_contents (abfd, sec, tmp_data, 0, x))
+             {
+               qsort (tmp_data,
+                      (size_t) (x / 12),
+                      12, sort_x64_pdata);
+               bfd_set_section_contents (pfinfo->output_bfd, sec,
+                                         tmp_data, 0, x);
+             }
+           free (tmp_data);
          }
       }
   }
This page took 0.024372 seconds and 4 git commands to generate.