sim: frv: fix up various missing prototype warnings
[binutils-gdb.git] / ld / pe-dll.c
index afcf6fea93e4d8071acc3185d06b89df57844dc6..e7b82ba6ffadf74dc1b9ee71dc13d48336941e51 100644 (file)
@@ -170,7 +170,7 @@ static struct bfd_section *edata_s, *reloc_s;
 static unsigned char *edata_d, *reloc_d;
 static size_t edata_sz, reloc_sz;
 static int runtime_pseudo_relocs_created = 0;
-static bfd_boolean runtime_pseudp_reloc_v2_init = FALSE;
+static bool runtime_pseudp_reloc_v2_init = false;
 
 typedef struct
 {
@@ -186,7 +186,7 @@ typedef struct
   unsigned int imagebase_reloc;
   int pe_arch;
   int bfd_arch;
-  bfd_boolean underscored;
+  bool underscored;
   const autofilter_entry_type* autofilter_symbollist;
 }
 pe_details_type;
@@ -264,9 +264,9 @@ static pe_details_type pe_detail_list[] =
     PE_ARCH_i386,
     bfd_arch_i386,
 #ifdef pe_use_x86_64
-    FALSE,
+    false,
 #else
-    TRUE,
+    true,
 #endif
     autofilter_symbollist_i386
   },
@@ -277,7 +277,7 @@ static pe_details_type pe_detail_list[] =
     3 /* R_IMAGEBASE */,
     PE_ARCH_i386,
     bfd_arch_i386,
-    FALSE,
+    false,
     autofilter_symbollist_i386
   },
 #else
@@ -287,7 +287,7 @@ static pe_details_type pe_detail_list[] =
     7 /* R_IMAGEBASE */,
     PE_ARCH_i386,
     bfd_arch_i386,
-    TRUE,
+    true,
     autofilter_symbollist_i386
   },
 #endif
@@ -297,7 +297,7 @@ static pe_details_type pe_detail_list[] =
     16 /* R_SH_IMAGEBASE */,
     PE_ARCH_sh,
     bfd_arch_sh,
-    TRUE,
+    true,
     autofilter_symbollist_generic
   },
   {
@@ -306,7 +306,7 @@ static pe_details_type pe_detail_list[] =
     34 /* MIPS_R_RVA */,
     PE_ARCH_mips,
     bfd_arch_mips,
-    FALSE,
+    false,
     autofilter_symbollist_generic
   },
   {
@@ -315,7 +315,7 @@ static pe_details_type pe_detail_list[] =
     11 /* ARM_RVA32 */,
     PE_ARCH_arm,
     bfd_arch_arm,
-    TRUE,
+    true,
     autofilter_symbollist_generic
   },
   {
@@ -324,10 +324,10 @@ static pe_details_type pe_detail_list[] =
     2,  /* ARM_RVA32 on Windows CE, see bfd/coff-arm.c.  */
     PE_ARCH_arm_wince,
     bfd_arch_arm,
-    FALSE,
+    false,
     autofilter_symbollist_generic
   },
-  { NULL, NULL, 0, 0, 0, FALSE, NULL }
+  { NULL, NULL, 0, 0, 0, false, NULL }
 };
 
 static const pe_details_type *pe_details;
@@ -439,7 +439,7 @@ pe_dll_id_target (const char *target)
          bfd_get_target_info (target, NULL, NULL, &u, NULL);
        if (u == -1)
          abort ();
-       pe_detail_list[i].underscored = (u != 0 ? TRUE : FALSE);
+       pe_detail_list[i].underscored = u != 0;
        pe_details = pe_detail_list + i;
        pe_leading_underscore = (u != 0 ? 1 : 0);
        return;
@@ -542,10 +542,10 @@ pe_dll_add_excludes (const char *new_excludes, const exclude_type type)
   free (local_copy);
 }
 
-static bfd_boolean
+static bool
 is_import (const char* n)
 {
-  return (CONST_STRNEQ (n, "__imp_"));
+  return (startswith (n, "__imp_"));
 }
 
 /* abfd is a bfd containing n (or NULL)
@@ -674,7 +674,7 @@ process_def_file_and_drectve (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *
   bfd *b;
   struct bfd_section *s;
   def_file_export *e = 0;
-  bfd_boolean resort_needed;
+  bool resort_needed;
 
   if (!pe_def_file)
     pe_def_file = def_file_empty ();
@@ -707,7 +707,7 @@ process_def_file_and_drectve (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *
        {
          struct coff_link_hash_entry *sym_hash;
          sym_hash = coff_link_hash_lookup (coff_hash_table (info),
-                                           ac->symbol_name, FALSE, FALSE, FALSE);
+                                           ac->symbol_name, false, false, false);
          if (sym_hash && sym_hash->root.type == bfd_link_hash_common
              && sym_hash->root.u.c.p->alignment_power < (unsigned) ac->alignment)
            {
@@ -746,7 +746,7 @@ process_def_file_and_drectve (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *
              /* We should export symbols which are either global or not
                 anything at all.  (.bss data is the latter)
                 We should not export undefined symbols.  */
-             bfd_boolean would_export
+             bool would_export
                = (symbols[j]->section != bfd_und_section_ptr
                   && ((symbols[j]->flags & BSF_GLOBAL)
                       || (symbols[j]->flags == 0)));
@@ -768,7 +768,7 @@ process_def_file_and_drectve (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *
                    sprintf (name, "%s%s", "__imp_", sn);
 
                    blhe = bfd_link_hash_lookup (info->hash, name,
-                                                FALSE, FALSE, FALSE);
+                                                false, false, false);
                    free (name);
 
                    if (blhe && blhe->type == bfd_link_hash_defined)
@@ -801,7 +801,7 @@ process_def_file_and_drectve (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *
   if (NE == 0)
     return;
 
-  resort_needed = FALSE;
+  resort_needed = false;
 
   /* Canonicalize the export list.  */
   if (pe_dll_kill_ats)
@@ -826,7 +826,7 @@ process_def_file_and_drectve (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *
                einfo (_("%X%P: cannot export %s: invalid export name\n"),
                       pe_def_file->exports[i].name);
              pe_def_file->exports[i].name = tmp;
-             resort_needed = TRUE;
+             resort_needed = true;
            }
        }
     }
@@ -937,7 +937,7 @@ process_def_file_and_drectve (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *
 
       blhe = bfd_link_hash_lookup (info->hash,
                                   name,
-                                  FALSE, FALSE, TRUE);
+                                  false, false, true);
 
       if (blhe
          && (blhe->type == bfd_link_hash_defined
@@ -1186,7 +1186,7 @@ fill_exported_offsets (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *info)
 
       blhe = bfd_link_hash_lookup (info->hash,
                                   name,
-                                  FALSE, FALSE, TRUE);
+                                  false, false, true);
 
       if (blhe && blhe->type == bfd_link_hash_defined)
        exported_symbol_offsets[i] = blhe->u.def.value;
@@ -1342,7 +1342,7 @@ pe_walk_relocs (struct bfd_link_info *info,
              /* Warning: the callback needs to be passed NAME directly.  */
              if (import_hash)
                {
-                 if (bfd_hash_lookup (import_hash, sym->name, FALSE, FALSE))
+                 if (bfd_hash_lookup (import_hash, sym->name, false, false))
                    {
                      strcpy (name, sym->name);
                      cb (relocs[i], s, name, symname);
@@ -1423,7 +1423,7 @@ pe_find_data_imports (const char *symhead,
        if (sym && sym->type == bfd_link_hash_defined)
          {
            if (import_hash)
-             bfd_hash_lookup (import_hash, undef->root.string, TRUE, FALSE);
+             bfd_hash_lookup (import_hash, undef->root.string, true, false);
            else
              {
                bfd *b = sym->u.def.section->owner;
@@ -1471,7 +1471,7 @@ pe_find_data_imports (const char *symhead,
 
            if (link_info.pei386_auto_import == -1)
              {
-               static bfd_boolean warned = FALSE;
+               static bool warned = false;
 
                info_msg (_("Info: resolving %s by linking to %s "
                            "(auto-import)\n"), name, impname);
@@ -1484,7 +1484,7 @@ pe_find_data_imports (const char *symhead,
                             "command line; this should work unless it "
                             "involves constant data structures referencing "
                             "symbols from auto-imported DLLs\n"));
-                   warned = TRUE;
+                   warned = true;
                  }
              }
          }
@@ -1516,7 +1516,7 @@ generate_reloc (bfd *abfd, struct bfd_link_info *info)
   bfd *b;
   struct bfd_section *s;
 
-  if (reloc_s == NULL)
+  if (reloc_s == NULL || reloc_s->output_section == bfd_abs_section_ptr)
     return;
   total_relocs = 0;
   for (b = info->input_bfds; b; b = b->link.next)
@@ -1581,7 +1581,7 @@ generate_reloc (bfd *abfd, struct bfd_link_info *info)
                  struct bfd_symbol *sym = *relocs[i]->sym_ptr_ptr;
                  const struct bfd_link_hash_entry *blhe
                    = bfd_wrapped_link_hash_lookup (abfd, info, sym->name,
-                                                   FALSE, FALSE, FALSE);
+                                                   false, false, false);
 
                  /* Don't create relocs for undefined weak symbols.  */
                  if (sym->flags == BSF_WEAK)
@@ -1627,6 +1627,15 @@ generate_reloc (bfd *abfd, struct bfd_link_info *info)
                  reloc_data[total_relocs].vma = sec_vma + relocs[i]->address;
                  reloc_data[total_relocs].idx = total_relocs;
 
+                 /* Since we're only about to determine .reloc's size,
+                    subsequent output section VMA calculations will shift up
+                    sections at this or higher addresses.  Relocations for
+                    such sections would hence end up not being correct.  */
+                 if (reloc_data[total_relocs].vma
+                     >= reloc_s->output_section->vma)
+                   einfo (_("%P: base relocation for section `%s' above "
+                            ".reloc section\n"), s->output_section->name);
+
 #define BITS_AND_SHIFT(bits, shift) (bits * 1000 | shift)
 
                  switch BITS_AND_SHIFT (relocs[i]->howto->bitsize,
@@ -1752,9 +1761,6 @@ generate_reloc (bfd *abfd, struct bfd_link_info *info)
 
   if (page_ptr != (bfd_vma) -1)
     bfd_put_32 (abfd, reloc_sz - page_ptr, reloc_d + page_ptr + 4);
-
-  while (reloc_sz < reloc_s->size)
-    reloc_d[reloc_sz++] = 0;
 }
 
 /* Given the exiting def_file structure, print out a .DEF file that
@@ -2274,7 +2280,7 @@ static const unsigned char jmp_arm_bytes[] =
 
 
 static bfd *
-make_one (def_file_export *exp, bfd *parent, bfd_boolean include_jmp_stub)
+make_one (def_file_export *exp, bfd *parent, bool include_jmp_stub)
 {
   asection *tx, *id7, *id5, *id4, *id6;
   unsigned char *td = NULL, *d7, *d5, *d4, *d6 = NULL;
@@ -2555,7 +2561,7 @@ make_import_fixup_mark (arelent *rel, char *name)
   bh = NULL;
   bfd_coff_link_add_one_symbol (&link_info, abfd, fixup_name, BSF_GLOBAL,
                                current_sec, /* sym->section, */
-                               rel->address, NULL, TRUE, FALSE, &bh);
+                               rel->address, NULL, true, false, &bh);
 
   return bh->root.string;
 }
@@ -2667,7 +2673,7 @@ make_runtime_pseudo_reloc (const char *name ATTRIBUTE_UNUSED,
       if (!runtime_pseudp_reloc_v2_init)
        {
          size += 12;
-         runtime_pseudp_reloc_v2_init = TRUE;
+         runtime_pseudp_reloc_v2_init = true;
        }
 
       quick_symbol (abfd, "__imp_", name, "", UNDSEC, BSF_GLOBAL, 0);
@@ -2777,7 +2783,7 @@ pe_create_import_fixup (arelent *rel, asection *s, bfd_vma addend, char *name,
          add_bfd_to_link (b, bfd_get_filename (b), &link_info);
 
          /* If we ever use autoimport, we have to cast text section writable.  */
-         config.text_read_only = FALSE;
+         config.text_read_only = false;
          link_info.output_bfd->flags &= ~WP_TEXT;
        }
 
@@ -2929,7 +2935,7 @@ pe_dll_generate_implib (def_file *def, const char *impfilename, struct bfd_link_
        struct coff_link_hash_entry *h;
 
        h = coff_link_hash_lookup (coff_hash_table (info), internal,
-                                  FALSE, FALSE, FALSE);
+                                  false, false, false);
        if (h != NULL
            /* If the symbol is hidden and undefined then it
               has been swept up by garbage collection.  */
@@ -2946,7 +2952,7 @@ pe_dll_generate_implib (def_file *def, const char *impfilename, struct bfd_link_
            sprintf (name, "_%s", internal);
 
            h = coff_link_hash_lookup (coff_hash_table (info), name,
-                                      FALSE, FALSE, FALSE);
+                                      false, false, false);
            free (name);
 
            if (h != NULL
@@ -3027,7 +3033,7 @@ pe_find_cdecl_alias_match (struct bfd_link_info *linfo, char *name)
 
   if (kv)
     {
-      h = bfd_link_hash_lookup (linfo->hash, kv->oname, FALSE, FALSE, FALSE);
+      h = bfd_link_hash_lookup (linfo->hash, kv->oname, false, false, false);
       if (h->type == bfd_link_hash_undefined)
        goto return_h;
     }
@@ -3042,13 +3048,15 @@ pe_find_cdecl_alias_match (struct bfd_link_info *linfo, char *name)
          if (pe_details->underscored)
            lname[0] = '_';
          else
-           strcpy (lname, lname + 1);
+           /* Use memmove rather than strcpy as that
+              can handle overlapping buffers.  */
+           memmove (lname, lname + 1, strlen (lname));
          key.key = lname;
          kv = bsearch (&key, udef_table, undef_count,
                        sizeof (struct key_value), undef_sort_cmp);
          if (kv)
            {
-             h = bfd_link_hash_lookup (linfo->hash, kv->oname, FALSE, FALSE, FALSE);
+             h = bfd_link_hash_lookup (linfo->hash, kv->oname, false, false, false);
              if (h->type == bfd_link_hash_undefined)
                goto return_h;
            }
@@ -3060,7 +3068,7 @@ pe_find_cdecl_alias_match (struct bfd_link_info *linfo, char *name)
                    sizeof (struct key_value), undef_sort_cmp);
       if (kv)
        {
-         h = bfd_link_hash_lookup (linfo->hash, kv->oname, FALSE, FALSE, FALSE);
+         h = bfd_link_hash_lookup (linfo->hash, kv->oname, false, false, false);
          if (h->type == bfd_link_hash_undefined)
            goto return_h;
        }
@@ -3074,7 +3082,7 @@ pe_find_cdecl_alias_match (struct bfd_link_info *linfo, char *name)
 
   if (kv)
     {
-      h = bfd_link_hash_lookup (linfo->hash, kv->oname, FALSE, FALSE, FALSE);
+      h = bfd_link_hash_lookup (linfo->hash, kv->oname, false, false, false);
       if (h->type == bfd_link_hash_undefined)
        goto return_h;
     }
@@ -3093,7 +3101,7 @@ pe_find_cdecl_alias_match (struct bfd_link_info *linfo, char *name)
 
   if (kv)
     {
-      h = bfd_link_hash_lookup (linfo->hash, kv->oname, FALSE, FALSE, FALSE);
+      h = bfd_link_hash_lookup (linfo->hash, kv->oname, false, false, false);
       if (h->type == bfd_link_hash_undefined)
        goto return_h;
     }
@@ -3105,16 +3113,16 @@ pe_find_cdecl_alias_match (struct bfd_link_info *linfo, char *name)
   return h;
 }
 
-static bfd_boolean
+static bool
 pe_undef_count (struct bfd_link_hash_entry *h ATTRIBUTE_UNUSED,
                void *inf ATTRIBUTE_UNUSED)
 {
   if (h->type == bfd_link_hash_undefined)
     undef_count++;
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 pe_undef_fill (struct bfd_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
 {
   if (h->type == bfd_link_hash_undefined)
@@ -3129,7 +3137,7 @@ pe_undef_fill (struct bfd_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
       udef_table[undef_count].oname = h->root.string;
       undef_count++;
     }
-  return TRUE;
+  return true;
 }
 
 static void
@@ -3205,12 +3213,12 @@ pe_process_import_defs (bfd *output_bfd, struct bfd_link_info *linfo)
          /* See if we need this import.  */
          size_t len = strlen (imp[i].internal_name);
          char *name = xmalloc (len + 2 + 6);
-         bfd_boolean include_jmp_stub = FALSE;
-         bfd_boolean is_cdecl = FALSE;
-         bfd_boolean is_undef = FALSE;
+         bool include_jmp_stub = false;
+         bool is_cdecl = false;
+         bool is_undef = false;
 
          if (!lead_at && strchr (imp[i].internal_name, '@') == NULL)
-             is_cdecl = TRUE;
+             is_cdecl = true;
 
          if (lead_at)
            sprintf (name, "%s", imp[i].internal_name);
@@ -3218,7 +3226,7 @@ pe_process_import_defs (bfd *output_bfd, struct bfd_link_info *linfo)
            sprintf (name, "%s%s",U (""), imp[i].internal_name);
 
          blhe = bfd_link_hash_lookup (linfo->hash, name,
-                                      FALSE, FALSE, FALSE);
+                                      false, false, false);
 
          /* Include the jump stub for <sym> only if the <sym>
             is undefined.  */
@@ -3231,13 +3239,13 @@ pe_process_import_defs (bfd *output_bfd, struct bfd_link_info *linfo)
                         imp[i].internal_name);
 
              blhe = bfd_link_hash_lookup (linfo->hash, name,
-                                          FALSE, FALSE, FALSE);
+                                          false, false, false);
              if (blhe)
                is_undef = (blhe->type == bfd_link_hash_undefined);
            }
          else
            {
-             include_jmp_stub = TRUE;
+             include_jmp_stub = true;
              is_undef = (blhe->type == bfd_link_hash_undefined);
            }
 
@@ -3245,7 +3253,7 @@ pe_process_import_defs (bfd *output_bfd, struct bfd_link_info *linfo)
            {
              sprintf (name, "%s%s",U (""), imp[i].internal_name);
              blhe = pe_find_cdecl_alias_match (linfo, name);
-             include_jmp_stub = TRUE;
+             include_jmp_stub = true;
              if (blhe)
                is_undef = (blhe->type == bfd_link_hash_undefined);
            }
@@ -3324,7 +3332,7 @@ pe_as32 (void *ptr)
   return b[0] + (b[1] << 8) + (b[2] << 16) + ((unsigned) b[3] << 24);
 }
 
-bfd_boolean
+bool
 pe_implied_import_dll (const char *filename)
 {
   bfd *dll;
@@ -3351,7 +3359,7 @@ pe_implied_import_dll (const char *filename)
   if (!dll)
     {
       einfo (_("%X%P: open %s: %E\n"), filename);
-      return FALSE;
+      return false;
     }
 
   track_dependency_files (filename);
@@ -3360,7 +3368,7 @@ pe_implied_import_dll (const char *filename)
   if (!bfd_check_format (dll, bfd_object))
     {
       einfo (_("%X%P: %s: this doesn't appear to be a DLL\n"), filename);
-      return FALSE;
+      return false;
     }
 
   /* Get pe_header, optional header and numbers of directory entries.  */
@@ -3374,7 +3382,7 @@ pe_implied_import_dll (const char *filename)
 
   /* No import or export directory entry.  */
   if (num_entries < 1)
-    return FALSE;
+    return false;
 
 #ifdef pe_use_x86_64
   export_rva  = pe_get32 (dll, opthdr_ofs + 96 + 4 * 4);
@@ -3386,7 +3394,7 @@ pe_implied_import_dll (const char *filename)
 
   /* No export table - nothing to export.  */
   if (export_size == 0)
-    return FALSE;
+    return false;
 
   nsections = pe_get16 (dll, pe_header_offset + 4 + 2);
   secptr = (pe_header_offset + 4 + 20 +
@@ -3483,7 +3491,7 @@ pe_implied_import_dll (const char *filename)
     {
       if (pe_dll_extra_pe_debug)
        printf ("%s is already loaded\n", dllname);
-      return TRUE;
+      return true;
     }
 
   /* This is an optimized version of the insertion loop, which avoids lots of
@@ -3517,7 +3525,7 @@ pe_implied_import_dll (const char *filename)
                    (unsigned long) func_rva, is_data ? "(data)" : "");
        }
 
-      return TRUE;
+      return true;
     }
 
   /* Iterate through the list of symbols.  */
@@ -3532,7 +3540,7 @@ pe_implied_import_dll (const char *filename)
 
       /* Skip unwanted symbols, which are
         exported in buggy auto-import releases.  */
-      if (! CONST_STRNEQ (erva + name_rva, "__nm_"))
+      if (! startswith (erva + name_rva, "__nm_"))
        {
          int is_dup = 0;
          /* is_data is true if the address is in the data, rdata or bss
@@ -3555,7 +3563,7 @@ pe_implied_import_dll (const char *filename)
        }
     }
 
-  return TRUE;
+  return true;
 }
 
 void
@@ -3632,7 +3640,7 @@ pe_exe_fill_sections (bfd *abfd, struct bfd_link_info *info)
 
       /* Resize the sections.  */
       lang_reset_memory_regions ();
-      lang_size_sections (NULL, TRUE);
+      lang_size_sections (NULL, true);
 
       /* Redo special stuff.  */
       ldemul_after_allocation ();
@@ -3644,7 +3652,7 @@ pe_exe_fill_sections (bfd *abfd, struct bfd_link_info *info)
     reloc_s->contents = reloc_d;
 }
 
-bfd_boolean
+bool
 pe_bfd_is_dll (bfd *abfd)
 {
   return (bfd_get_format (abfd) == bfd_object