Add readahead cache to gdb's vFile:pread
[binutils-gdb.git] / bfd / peXXigen.c
index a7e9f04efebfc8702e5ab9a9c29d04ae3ebe5435..a1baaef5c20e8532873809ba870ab84dbd633223 100644 (file)
@@ -65,6 +65,9 @@
 #ifdef HAVE_WCHAR_H
 #include <wchar.h>
 #endif
+#ifdef HAVE_WCTYPE_H
+#include <wctype.h>
+#endif
 
 /* NOTE: it's strange to be including an architecture specific header
    in what's supposed to be general (to PE/PEI) code.  However, that's
@@ -1057,8 +1060,8 @@ _bfd_XXi_swap_scnhdr_out (bfd * abfd, void * in, void * out)
   }
 
   if (coff_data (abfd)->link_info
-      && ! coff_data (abfd)->link_info->relocatable
-      && ! coff_data (abfd)->link_info->shared
+      && ! bfd_link_relocatable (coff_data (abfd)->link_info)
+      && ! bfd_link_pic (coff_data (abfd)->link_info)
       && strcmp (scnhdr_int->s_name, ".text") == 0)
     {
       /* By inference from looking at MS output, the 32 bit field
@@ -1137,7 +1140,7 @@ _bfd_XXi_swap_debugdir_out (bfd * abfd, void * inp, void * extp)
   return sizeof (struct external_IMAGE_DEBUG_DIRECTORY);
 }
 
-static CODEVIEW_INFO *
+CODEVIEW_INFO *
 _bfd_XXi_slurp_codeview_record (bfd * abfd, file_ptr where, unsigned long length, CODEVIEW_INFO *cvinfo)
 {
   char buffer[256+1];
@@ -2563,7 +2566,7 @@ rsrc_print_section (bfd * abfd, void * vfile)
   if (regions.resource_start != NULL)
     fprintf (file, " Resources start at offset: %#03x\n",
             (int) (regions.resource_start - regions.section_start));
-  
+
   free (regions.section_start);
   return TRUE;
 }
@@ -2952,7 +2955,7 @@ _bfd_XX_bfd_copy_private_bfd_data_common (bfd * ibfd, bfd * obfd)
          if (ope->pe_opthdr.DataDirectory[PE_DEBUG_DATA].Size + (addr - section->vma)
              > bfd_get_section_size (section))
            {
-             _bfd_error_handler (_("%A: Data Directory size (%lx) exceeds space left in section (%lx)"),
+             _bfd_error_handler (_("%B: Data Directory size (%lx) exceeds space left in section (%lx)"),
                                  obfd, ope->pe_opthdr.DataDirectory[PE_DEBUG_DATA].Size,
                                  bfd_get_section_size (section) - (addr - section->vma));
              return FALSE;
@@ -2988,7 +2991,7 @@ _bfd_XX_bfd_copy_private_bfd_data_common (bfd * ibfd, bfd * obfd)
         }
       else if (section)
        {
-         _bfd_error_handler (_("%A: Failed to read debug data section"), obfd);
+         _bfd_error_handler (_("%B: Failed to read debug data section"), obfd);
          return FALSE;
        }
     }
@@ -3467,7 +3470,7 @@ rsrc_compute_region_sizes (rsrc_directory * dir)
       sizeof_tables_and_entries += 8;
 
       sizeof_strings += (entry->name_id.name.len + 1) * 2;
-         
+
       if (entry->is_dir)
        rsrc_compute_region_sizes (entry->value.directory);
       else
@@ -3537,7 +3540,11 @@ rsrc_write_directory (rsrc_write_data * data,
    putting its 'ucs4_t' representation in *PUC.  */
 
 static unsigned int
+#if defined HAVE_WCTYPE_H
+u16_mbtouc (wint_t * puc, const unsigned short * s, unsigned int n)
+#else
 u16_mbtouc (wchar_t * puc, const unsigned short * s, unsigned int n)
+#endif
 {
   unsigned short c = * s;
 
@@ -3609,20 +3616,34 @@ rsrc_cmp (bfd_boolean is_name, rsrc_entry * a, rsrc_entry * b)
 #elif defined HAVE_WCHAR_H
   {
     unsigned int  i;
+
     res = 0;
     for (i = min (alen, blen); i--; astring += 2, bstring += 2)
       {
+#if defined HAVE_WCTYPE_H
+       wint_t awc;
+       wint_t bwc;
+#else
        wchar_t awc;
        wchar_t bwc;
+#endif
 
-       /* Convert UTF-16 unicode characters into wchar_t characters so
-          that we can then perform a case insensitive comparison.  */
-       int Alen = u16_mbtouc (& awc, (const unsigned short *) astring, 2);
-       int Blen = u16_mbtouc (& bwc, (const unsigned short *) bstring, 2);
+       /* Convert UTF-16 unicode characters into wchar_t characters
+          so that we can then perform a case insensitive comparison.  */
+       unsigned int Alen = u16_mbtouc (& awc, (const unsigned short *) astring, 2);
+       unsigned int Blen = u16_mbtouc (& bwc, (const unsigned short *) bstring, 2);
 
        if (Alen != Blen)
          return Alen - Blen;
+
+#ifdef HAVE_WCTYPE_H
+       awc = towlower (awc);
+       bwc = towlower (bwc);
+
+       res = awc - bwc;
+#else
        res = wcsncasecmp (& awc, & bwc, 1);
+#endif
        if (res)
          break;
       }
@@ -4139,7 +4160,8 @@ rsrc_process_section (bfd * abfd,
     {
       asection * rsrc_sec = bfd_get_section_by_name (input, ".rsrc");
 
-      if (rsrc_sec != NULL)
+      /* PR 18372 - skip discarded .rsrc sections.  */
+      if (rsrc_sec != NULL && !discarded_section (rsrc_sec))
        {
          if (num_input_rsrc == max_num_input_rsrc)
            {