* elf64-ppc.c (toc_adjusting_stub_needed): Exit early if section
[deliverable/binutils-gdb.git] / bfd / peXXigen.c
index 7f1a6a3dfe214aba93c81b439688af77de8bac18..f3b3a96d760ec627c60f29c3504466777d367a8d 100644 (file)
@@ -570,8 +570,7 @@ _bfd_XXi_swap_aouthdr_out (abfd, in, out)
   struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
   PEAOUTHDR *aouthdr_out = (PEAOUTHDR *) out;
   bfd_vma sa, fa, ib;
-  IMAGE_DATA_DIRECTORY idata2, idata5;
-
+  IMAGE_DATA_DIRECTORY idata2, idata5, tls;
   
   if (pe->force_minimum_alignment)
     {
@@ -590,6 +589,7 @@ _bfd_XXi_swap_aouthdr_out (abfd, in, out)
 
   idata2 = pe->pe_opthdr.DataDirectory[1];
   idata5 = pe->pe_opthdr.DataDirectory[12];
+  tls = pe->pe_opthdr.DataDirectory[9];
   
   if (aouthdr_in->tsize)
     {
@@ -641,6 +641,7 @@ _bfd_XXi_swap_aouthdr_out (abfd, in, out)
      a final link is going to be performed, it can overwrite them.  */
   extra->DataDirectory[1]  = idata2;
   extra->DataDirectory[12] = idata5;
+  extra->DataDirectory[9] = tls;
 
   if (extra->DataDirectory[1].VirtualAddress == 0)
     /* Until other .idata fixes are made (pending patch), the entry for
@@ -674,7 +675,9 @@ _bfd_XXi_swap_aouthdr_out (abfd, in, out)
           5.0 link.exe) where the file size of the .data segment is
           quite small compared to the virtual size.  Without this
           fix, strip munges the file.  */
-       isize += SA (FA (pei_section_data (abfd, sec)->virt_size));
+       if (coff_section_data (abfd, sec) != NULL
+           && pei_section_data (abfd, sec) != NULL)
+         isize += SA (FA (pei_section_data (abfd, sec)->virt_size));
       }
 
     aouthdr_in->dsize = dsize;
@@ -990,7 +993,11 @@ _bfd_XXi_swap_scnhdr_out (abfd, in, out)
          ret = 0;
        }
 
-      if (scnhdr_int->s_nreloc <= 0xffff)
+      /* Although we could encode 0xffff relocs here, we do not, to be
+         consistent with other parts of bfd. Also it lets us warn, as
+         we should never see 0xffff here w/o having the overflow flag
+         set.  */
+      if (scnhdr_int->s_nreloc < 0xffff)
        H_PUT_16 (abfd, scnhdr_int->s_nreloc, scnhdr_ext->s_nreloc);
       else
        {
@@ -2019,7 +2026,19 @@ _bfd_XXi_final_link_postscript (abfd, pfinfo)
          + h1->root.u.def.section->output_offset)
         - pe_data (abfd)->pe_opthdr.DataDirectory[12].VirtualAddress);      
     }
-  
+
+  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);
+      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....  */
This page took 0.024098 seconds and 4 git commands to generate.