Use startswith more for strncmp function calls.
authorMartin Liska <mliska@suse.cz>
Thu, 18 Mar 2021 14:16:54 +0000 (15:16 +0100)
committerMartin Liska <mliska@suse.cz>
Thu, 1 Apr 2021 12:59:04 +0000 (14:59 +0200)
bfd/ChangeLog:

* elf-bfd.h (bfd_section_is_ctf): Use startswith function.
* elf.c (_bfd_elf_make_section_from_shdr): Likewise.
(elf_get_reloc_section): Likewise.
* elf32-arc.c (elf_arc_size_dynamic_sections): Likewise.
* elf32-m32r.c (m32r_elf_section_flags): Likewise.
* elf32-microblaze.c (microblaze_elf_size_dynamic_sections): Likewise.
* elf32-nds32.c (nds32_elf_size_dynamic_sections): Likewise.
(nds32_elf_relocate_section): Likewise.
(nds32_elf_action_discarded): Likewise.
(nds32_elf_check_relocs): Likewise.
(nds32_elf_section_flags): Likewise.
* elf32-or1k.c (or1k_elf_check_relocs): Likewise.
* elf32-ppc.c (ppc_elf_section_from_shdr): Likewise.
* elf32-rx.c (rx_table_find): Likewise.
(rx_table_map): Likewise.
* elf32-spu.c (spu_elf_backend_symbol_processing): Likewise.
(spu_elf_find_overlays): Likewise.
(needs_ovl_stub): Likewise.
(allocate_spuear_stubs): Likewise.
(build_spuear_stubs): Likewise.
(mark_overlay_section): Likewise.
(spu_elf_auto_overlay): Likewise.
(spu_elf_output_symbol_hook): Likewise.
* elf32-tilepro.c (tilepro_elf_size_dynamic_sections): Likewise.
* elf32-xtensa.c (xtensa_property_section_name): Likewise.
* elf64-ppc.c (ppc64_elf_section_flags): Likewise.
(ppc64_elf_relocate_section): Likewise.
* elflink.c (resolve_section): Likewise.
(UNARY_OP): Likewise.
(BINARY_OP_HEAD): Likewise.
(elf_link_input_bfd): Likewise.
* elfnn-riscv.c (riscv_elf_size_dynamic_sections): Likewise.
* elfxx-riscv.c (riscv_parse_subset): Likewise.
* elfxx-tilegx.c (tilegx_elf_size_dynamic_sections): Likewise.
* opncls.c (get_build_id): Likewise.

binutils/ChangeLog:

* dllwrap.c: Use startswith function.
* objcopy.c (is_dwo_section): Likewise.
(handle_remove_section_option): Likewise.
(copy_main): Likewise.
* objdump.c (is_significant_symbol_name): Likewise.

23 files changed:
bfd/ChangeLog
bfd/elf-bfd.h
bfd/elf.c
bfd/elf32-arc.c
bfd/elf32-m32r.c
bfd/elf32-microblaze.c
bfd/elf32-nds32.c
bfd/elf32-or1k.c
bfd/elf32-ppc.c
bfd/elf32-rx.c
bfd/elf32-spu.c
bfd/elf32-tilepro.c
bfd/elf32-xtensa.c
bfd/elf64-ppc.c
bfd/elflink.c
bfd/elfnn-riscv.c
bfd/elfxx-riscv.c
bfd/elfxx-tilegx.c
bfd/opncls.c
binutils/ChangeLog
binutils/dllwrap.c
binutils/objcopy.c
binutils/objdump.c

index e12c559c137092df69c795afa95a869217ecec9e..aa62c92213acd3c181efce99286f68abff490e31 100644 (file)
@@ -1,3 +1,41 @@
+2021-04-01  Martin Liska  <mliska@suse.cz>
+
+       * elf-bfd.h (bfd_section_is_ctf): Use startswith function.
+       * elf.c (_bfd_elf_make_section_from_shdr): Likewise.
+       (elf_get_reloc_section): Likewise.
+       * elf32-arc.c (elf_arc_size_dynamic_sections): Likewise.
+       * elf32-m32r.c (m32r_elf_section_flags): Likewise.
+       * elf32-microblaze.c (microblaze_elf_size_dynamic_sections): Likewise.
+       * elf32-nds32.c (nds32_elf_size_dynamic_sections): Likewise.
+       (nds32_elf_relocate_section): Likewise.
+       (nds32_elf_action_discarded): Likewise.
+       (nds32_elf_check_relocs): Likewise.
+       (nds32_elf_section_flags): Likewise.
+       * elf32-or1k.c (or1k_elf_check_relocs): Likewise.
+       * elf32-ppc.c (ppc_elf_section_from_shdr): Likewise.
+       * elf32-rx.c (rx_table_find): Likewise.
+       (rx_table_map): Likewise.
+       * elf32-spu.c (spu_elf_backend_symbol_processing): Likewise.
+       (spu_elf_find_overlays): Likewise.
+       (needs_ovl_stub): Likewise.
+       (allocate_spuear_stubs): Likewise.
+       (build_spuear_stubs): Likewise.
+       (mark_overlay_section): Likewise.
+       (spu_elf_auto_overlay): Likewise.
+       (spu_elf_output_symbol_hook): Likewise.
+       * elf32-tilepro.c (tilepro_elf_size_dynamic_sections): Likewise.
+       * elf32-xtensa.c (xtensa_property_section_name): Likewise.
+       * elf64-ppc.c (ppc64_elf_section_flags): Likewise.
+       (ppc64_elf_relocate_section): Likewise.
+       * elflink.c (resolve_section): Likewise.
+       (UNARY_OP): Likewise.
+       (BINARY_OP_HEAD): Likewise.
+       (elf_link_input_bfd): Likewise.
+       * elfnn-riscv.c (riscv_elf_size_dynamic_sections): Likewise.
+       * elfxx-riscv.c (riscv_parse_subset): Likewise.
+       * elfxx-tilegx.c (tilegx_elf_size_dynamic_sections): Likewise.
+       * opncls.c (get_build_id): Likewise.
+
 2021-03-31  Alan Modra  <amodra@gmail.com>
 
        PR 27671
index 101c2fdf50d040eb95db841254e0b5794a8e541e..296b80ad95228e4934afa280ba60da531f9801da 100644 (file)
@@ -3093,7 +3093,7 @@ static inline bool
 bfd_section_is_ctf (const asection *sec)
 {
   const char *name = bfd_section_name (sec);
-  return strncmp (name, ".ctf", 4) == 0 && (name[4] == 0 || name[4] == '.');
+  return startswith (name, ".ctf") && (name[4] == 0 || name[4] == '.');
 }
 
 #ifdef __cplusplus
index 697d1ee72820b21c1d586d3fac3bf04fa9ac1643..276fa14c0dda8288ee477ae3a9b538f2c5261db6 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -1084,19 +1084,19 @@ _bfd_elf_make_section_from_shdr (bfd *abfd,
         not any sort of flag.  Their SEC_ALLOC bits are cleared.  */
       if (name [0] == '.')
        {
-         if (strncmp (name, ".debug", 6) == 0
-             || strncmp (name, ".gnu.debuglto_.debug_", 21) == 0
-             || strncmp (name, ".gnu.linkonce.wi.", 17) == 0
-             || strncmp (name, ".zdebug", 7) == 0)
+         if (startswith (name, ".debug")
+             || startswith (name, ".gnu.debuglto_.debug_")
+             || startswith (name, ".gnu.linkonce.wi.")
+             || startswith (name, ".zdebug"))
            flags |= SEC_DEBUGGING | SEC_ELF_OCTETS;
-         else if (strncmp (name, GNU_BUILD_ATTRS_SECTION_NAME, 21) == 0
-                  || strncmp (name, ".note.gnu", 9) == 0)
+         else if (startswith (name, GNU_BUILD_ATTRS_SECTION_NAME)
+                  || startswith (name, ".note.gnu"))
            {
              flags |= SEC_ELF_OCTETS;
              opb = 1;
            }
-         else if (strncmp (name, ".line", 5) == 0
-                  || strncmp (name, ".stab", 5) == 0
+         else if (startswith (name, ".line")
+                  || startswith (name, ".stab")
                   || strcmp (name, ".gdb_index") == 0)
            flags |= SEC_DEBUGGING;
        }
@@ -1277,8 +1277,7 @@ _bfd_elf_make_section_from_shdr (bfd *abfd,
 
   /* GCC uses .gnu.lto_.lto.<some_hash> as a LTO bytecode information
      section.  */
-  const char *lto_section_name = ".gnu.lto_.lto.";
-  if (strncmp (name, lto_section_name, strlen (lto_section_name)) == 0)
+  if (startswith (name, ".gnu.lto_.lto."))
     {
       struct lto_section lsection;
       if (bfd_get_section_contents (abfd, newsect, &lsection, 0,
@@ -3677,7 +3676,7 @@ elf_get_reloc_section (asection *reloc_sec)
 
   /* We look up the section the relocs apply to by name.  */
   name = reloc_sec->name;
-  if (strncmp (name, ".rel", 4) != 0)
+  if (!startswith (name, ".rel"))
     return NULL;
   name += 4;
   if (type == SHT_RELA && *name++ != 'a')
index d201d5a8c46a8ce3bf6c7c62da4ee4f5c66b9502..11a1388acd6b59669f7ae46c1ab1a1e01f4146e7 100644 (file)
@@ -2759,7 +2759,7 @@ elf_arc_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
        {
          /* Strip this section if we don't need it.  */
        }
-      else if (strncmp (s->name, ".rela", 5) == 0)
+      else if (startswith (s->name, ".rela"))
        {
          if (s->size != 0 && s != htab->srelplt)
            relocs_exist = true;
index 783632b65186dcd5f1d8b8988075d8954520c8eb..6a732585f5f42bcd9926182e1ab7a8edafde9d77 100644 (file)
@@ -3615,8 +3615,8 @@ m32r_elf_section_flags (const Elf_Internal_Shdr *hdr)
 {
   const char *name = hdr->bfd_section->name;
 
-  if (strncmp (name, ".sbss", 5) == 0
-      || strncmp (name, ".sdata", 6) == 0)
+  if (startswith (name, ".sbss")
+      || startswith (name, ".sdata"))
     hdr->bfd_section->flags |= SEC_SMALL_DATA;
 
   return true;
index b5868580967483fee78d1157f0159d5a4e2085ac..d9c0d93a01a60e2c462a50e1269966760c989360 100644 (file)
@@ -3050,7 +3050,7 @@ microblaze_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
         of the dynobj section names depend upon the input files.  */
       name = bfd_section_name (s);
 
-      if (strncmp (name, ".rela", 5) == 0)
+      if (startswith (name, ".rela"))
        {
          if (s->size == 0)
            {
index 31a3ca02925a04fd64c3f0f909a0052c8aa539d0..5eb029524df201af777c28a3732b0161168b5f8b 100644 (file)
@@ -4439,7 +4439,7 @@ nds32_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
        {
          got_size += s->size;
        }
-      else if (strncmp (bfd_section_name (s), ".rela", 5) == 0)
+      else if (startswith (bfd_section_name (s), ".rela"))
        {
          if (s->size != 0 && s != elf_hash_table (info)->srelplt)
            relocs = true;
@@ -5426,7 +5426,7 @@ nds32_elf_relocate_section (bfd *            output_bfd ATTRIBUTE_UNUSED,
                  if (name == NULL)
                    return false;
 
-                 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
+                 BFD_ASSERT (startswith (name, ".rela")
                              && strcmp (bfd_section_name (input_section),
                                         name + 5) == 0);
 
@@ -6870,8 +6870,7 @@ static unsigned int
 nds32_elf_action_discarded (asection *sec)
 {
 
-  if (strncmp
-      (".gcc_except_table", sec->name, sizeof (".gcc_except_table") - 1) == 0)
+  if (startswith (sec->name, ".gcc_except_table"))
     return 0;
 
   return _bfd_elf_default_action_discarded (sec);
@@ -7239,7 +7238,7 @@ nds32_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
                  if (name == NULL)
                    return false;
 
-                 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
+                 BFD_ASSERT (startswith (name, ".rela")
                              && strcmp (bfd_section_name (sec),
                                         name + 5) == 0);
 
@@ -12450,8 +12449,8 @@ nds32_elf_section_flags (const Elf_Internal_Shdr *hdr)
 {
   const char *name = hdr->bfd_section->name;
 
-  if (strncmp (name, ".sbss", 5) == 0
-      || strncmp (name, ".sdata", 6) == 0)
+  if (startswith (name, ".sbss")
+      || startswith (name, ".sdata"))
     hdr->bfd_section->flags |= SEC_SMALL_DATA;
 
   return true;
index cd4398da86246e264d69dae89f6369fecefe3ac5..013deb406f89ed347b28d61ab9df230ed7726f6a 100644 (file)
@@ -2110,7 +2110,7 @@ or1k_elf_check_relocs (bfd *abfd,
                    if (name == NULL)
                      return false;
 
-                   if (strncmp (name, ".rela", 5) != 0
+                   if (!startswith (name, ".rela")
                        || strcmp (bfd_section_name (sec), name + 5) != 0)
                      {
                        _bfd_error_handler
index 0ae7e0bcf6495423059add314000b44d0703ac41..d6ed501245cd537a4ddb2137c6163cf827bf6a50 100644 (file)
@@ -1338,10 +1338,10 @@ ppc_elf_section_from_shdr (bfd *abfd,
   if (hdr->sh_type == SHT_ORDERED)
     flags |= SEC_SORT_ENTRIES;
 
-  if (strncmp (name, ".PPC.EMB", 8) == 0)
+  if (startswith (name, ".PPC.EMB"))
     name += 8;
-  if (strncmp (name, ".sbss", 5) == 0
-      || strncmp (name, ".sdata", 6) == 0)
+  if (startswith (name, ".sbss")
+      || startswith (name, ".sdata"))
     flags |= SEC_SMALL_DATA;
 
   return (flags == 0
index 95684d4d328b6357caebc69a532941390815d810..771863590d5a39f2923df7a0292eefa82bdd0325 100644 (file)
@@ -557,7 +557,7 @@ rx_elf_relocate_section
          name = h->root.root.string;
        }
 
-      if (strncmp (name, "$tableentry$default$", 20) == 0)
+      if (startswith (name, "$tableentry$default$"))
        {
          bfd_vma entry_vma;
          int idx;
@@ -3759,7 +3759,7 @@ rx_table_find (struct bfd_hash_entry *vent, void *vinfo)
   sec = ent->u.def.section;
   abfd = sec->owner;
 
-  if (strncmp (name, "$tablestart$", 12))
+  if (!startswith (name, "$tablestart$"))
     return true;
 
   sec->flags |= SEC_KEEP;
@@ -3895,7 +3895,7 @@ rx_table_map (struct bfd_hash_entry *vent, void *vinfo)
 
   name = ent->root.string;
 
-  if (strncmp (name, "$tablestart$", 12))
+  if (!startswith (name, "$tablestart$"))
     return true;
 
   tname = name + 12;
index 5bffc1d8ada43b3f62255a417d0a0ca9ba4b83f5..c3ce2c16d8063ccc6f008e910adc1fe0ac9b983f 100644 (file)
@@ -307,7 +307,7 @@ spu_elf_backend_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, asymbol *sym)
 {
   if (sym->name != NULL
       && sym->section != bfd_abs_section_ptr
-      && strncmp (sym->name, "_EAR_", 5) == 0)
+      && startswith (sym->name, "_EAR_"))
     sym->flags |= BSF_KEEP;
 }
 
@@ -725,7 +725,7 @@ spu_elf_find_overlays (struct bfd_link_info *info)
             an overlay, in the sense that it might be loaded in
             by the overlay manager, but rather the initial
             section contents for the overlay buffer.  */
-         if (strncmp (s->name, ".ovl.init", 9) != 0)
+         if (!startswith (s->name, ".ovl.init"))
            {
              num_buf = ((s->vma - vma_start) >> htab->line_size_log2) + 1;
              set_id = (num_buf == prev_buf)? set_id + 1 : 0;
@@ -785,7 +785,7 @@ spu_elf_find_overlays (struct bfd_link_info *info)
              if (spu_elf_section_data (s0)->u.o.ovl_index == 0)
                {
                  ++num_buf;
-                 if (strncmp (s0->name, ".ovl.init", 9) != 0)
+                 if (!startswith (s0->name, ".ovl.init"))
                    {
                      alloc_sec[ovl_index] = s0;
                      spu_elf_section_data (s0)->u.o.ovl_index = ++ovl_index;
@@ -794,7 +794,7 @@ spu_elf_find_overlays (struct bfd_link_info *info)
                  else
                    ovl_end = s->vma + s->size;
                }
-             if (strncmp (s->name, ".ovl.init", 9) != 0)
+             if (!startswith (s->name, ".ovl.init"))
                {
                  alloc_sec[ovl_index] = s;
                  spu_elf_section_data (s)->u.o.ovl_index = ++ovl_index;
@@ -970,7 +970,7 @@ needs_ovl_stub (struct elf_link_hash_entry *h,
       /* setjmp always goes via an overlay stub, because then the return
         and hence the longjmp goes via __ovly_return.  That magically
         makes setjmp/longjmp between overlays work.  */
-      if (strncmp (h->root.root.string, "setjmp", 6) == 0
+      if (startswith (h->root.root.string, "setjmp")
          && (h->root.root.string[6] == '\0' || h->root.root.string[6] == '@'))
        ret = call_ovl_stub;
     }
@@ -1496,7 +1496,7 @@ allocate_spuear_stubs (struct elf_link_hash_entry *h, void *inf)
   if ((h->root.type == bfd_link_hash_defined
        || h->root.type == bfd_link_hash_defweak)
       && h->def_regular
-      && strncmp (h->root.root.string, "_SPUEAR_", 8) == 0
+      && startswith (h->root.root.string, "_SPUEAR_")
       && (sym_sec = h->root.u.def.section) != NULL
       && sym_sec->output_section != bfd_abs_section_ptr
       && spu_elf_section_data (sym_sec->output_section) != NULL
@@ -1521,7 +1521,7 @@ build_spuear_stubs (struct elf_link_hash_entry *h, void *inf)
   if ((h->root.type == bfd_link_hash_defined
        || h->root.type == bfd_link_hash_defweak)
       && h->def_regular
-      && strncmp (h->root.root.string, "_SPUEAR_", 8) == 0
+      && startswith (h->root.root.string, "_SPUEAR_")
       && (sym_sec = h->root.u.def.section) != NULL
       && sym_sec->output_section != bfd_abs_section_ptr
       && spu_elf_section_data (sym_sec->output_section) != NULL
@@ -3455,7 +3455,7 @@ mark_overlay_section (struct function_info *fun,
   if (!fun->sec->linker_mark
       && (htab->params->ovly_flavour != ovly_soft_icache
          || htab->params->non_ia_text
-         || strncmp (fun->sec->name, ".text.ia.", 9) == 0
+         || startswith (fun->sec->name, ".text.ia.")
          || strcmp (fun->sec->name, ".init") == 0
          || strcmp (fun->sec->name, ".fini") == 0))
     {
@@ -3483,7 +3483,7 @@ mark_overlay_section (struct function_info *fun,
                return false;
              memcpy (name, ".rodata", sizeof (".rodata"));
            }
-         else if (strncmp (fun->sec->name, ".text.", 6) == 0)
+         else if (startswith (fun->sec->name, ".text."))
            {
              size_t len = strlen (fun->sec->name);
              name = bfd_malloc (len + 3);
@@ -3492,7 +3492,7 @@ mark_overlay_section (struct function_info *fun,
              memcpy (name, ".rodata", sizeof (".rodata"));
              memcpy (name + 7, fun->sec->name + 5, len - 4);
            }
-         else if (strncmp (fun->sec->name, ".gnu.linkonce.t.", 16) == 0)
+         else if (startswith (fun->sec->name, ".gnu.linkonce.t."))
            {
              size_t len = strlen (fun->sec->name) + 1;
              name = bfd_malloc (len);
@@ -3583,7 +3583,7 @@ mark_overlay_section (struct function_info *fun,
      a stack!  Also, don't mark .ovl.init as an overlay.  */
   if (fun->lo + fun->sec->output_offset + fun->sec->output_section->vma
       == info->output_bfd->start_address
-      || strncmp (fun->sec->output_section->name, ".ovl.init", 9) == 0)
+      || startswith (fun->sec->output_section->name, ".ovl.init"))
     {
       fun->sec->linker_mark = 0;
       if (fun->rodata != NULL)
@@ -4317,7 +4317,7 @@ spu_elf_auto_overlay (struct bfd_link_info *info)
          }
        else if ((sec->flags & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)
                 && sec->output_section->owner == info->output_bfd
-                && strncmp (sec->output_section->name, ".ovl.init", 9) == 0)
+                && startswith (sec->output_section->name, ".ovl.init"))
          fixed_size -= sec->size;
       if (count != old_count)
        bfd_arr[bfd_count++] = ibfd;
@@ -5156,7 +5156,7 @@ spu_elf_output_symbol_hook (struct bfd_link_info *info,
       && (h->root.type == bfd_link_hash_defined
          || h->root.type == bfd_link_hash_defweak)
       && h->def_regular
-      && strncmp (h->root.root.string, "_SPUEAR_", 8) == 0)
+      && startswith (h->root.root.string, "_SPUEAR_"))
     {
       struct got_entry *g;
 
index cf288b3052befdb8fade478b9e609b693f7e81eb..b0ed70647938abe6beeedda00adb8fa91fe7cf33 100644 (file)
@@ -2332,7 +2332,7 @@ tilepro_elf_size_dynamic_sections (bfd *output_bfd,
          /* Strip this section if we don't need it; see the
             comment below.  */
        }
-      else if (strncmp (s->name, ".rela", 5) == 0)
+      else if (startswith (s->name, ".rela"))
        {
          if (s->size != 0)
            {
index 21894d171aca1c818465e0909781d6dfa08778c8..c1781c7a7d77755283d888d7649d05e52a727819 100644 (file)
@@ -11260,7 +11260,7 @@ xtensa_property_section_name (asection *sec, const char *base_name,
        suffix = 0;
       prop_sec_name = xtensa_add_names (base_name, suffix);
     }
-  else if (strncmp (sec->name, ".gnu.linkonce.", linkonce_len) == 0)
+  else if (startswith (sec->name, ".gnu.linkonce."))
     {
       char *linkonce_kind = 0;
 
index bc8dc4df1a5a3c9e5a43af14e054d5bbc2ddf4b3..c306954dacb7240a97bd20cb0bb6aacd07e1e8d8 100644 (file)
@@ -2042,8 +2042,8 @@ ppc64_elf_section_flags (const Elf_Internal_Shdr *hdr)
 {
   const char *name = hdr->bfd_section->name;
 
-  if (strncmp (name, ".sbss", 5) == 0
-      || strncmp (name, ".sdata", 6) == 0)
+  if (startswith (name, ".sbss")
+      || startswith (name, ".sdata"))
     hdr->bfd_section->flags |= SEC_SMALL_DATA;
 
   return true;
@@ -15873,7 +15873,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
                  if (*name == '.')
                    ++name;
 
-                 if (strncmp (name, "__libc_start_main", 17) == 0
+                 if (startswith (name, "__libc_start_main")
                      && (name[17] == 0 || name[17] == '@'))
                    {
                      /* Allow crt1 branch to go via a toc adjusting
index ce1407fa2dcc1b2192b383d1fa322fe60ec2c8ad..f8d6313168003ba58a08b46bc645e5bfd50f22a4 100644 (file)
@@ -8719,7 +8719,7 @@ resolve_section (const char *name,
 
       if (strncmp (curr->name, name, len) == 0)
        {
-         if (strncmp (".end", name + len, 4) == 0)
+         if (startswith (name + len, ".end"))
            {
              *result = (curr->vma
                         + curr->size / bfd_octets_per_byte (abfd, curr));
@@ -8832,7 +8832,7 @@ eval_symbol (bfd_vma *result,
       /* All that remains are operators.  */
 
 #define UNARY_OP(op)                                           \
-  if (strncmp (sym, #op, strlen (#op)) == 0)                   \
+  if (startswith (sym, #op))                                   \
     {                                                          \
       sym += strlen (#op);                                     \
       if (*sym == ':')                                         \
@@ -8849,7 +8849,7 @@ eval_symbol (bfd_vma *result,
     }
 
 #define BINARY_OP_HEAD(op)                                     \
-  if (strncmp (sym, #op, strlen (#op)) == 0)                   \
+  if (startswith (sym, #op))                                   \
     {                                                          \
       sym += strlen (#op);                                     \
       if (*sym == ':')                                         \
@@ -11196,10 +11196,10 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
          /* We need to reverse-copy input .ctors/.dtors sections if
             they are placed in .init_array/.finit_array for output.  */
          if (o->size > address_size
-             && ((strncmp (o->name, ".ctors", 6) == 0
+             && ((startswith (o->name, ".ctors")
                   && strcmp (o->output_section->name,
                              ".init_array") == 0)
-                 || (strncmp (o->name, ".dtors", 6) == 0
+                 || (startswith (o->name, ".dtors")
                      && strcmp (o->output_section->name,
                                 ".fini_array") == 0))
              && (o->name[6] == 0 || o->name[6] == '.'))
index 51f9d756cd183ce5831d196f67f353564302e97c..b5be929ad1d387d40d43cba8699b18428625e8e5 100644 (file)
@@ -1515,7 +1515,7 @@ riscv_elf_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
          /* Strip this section if we don't need it; see the
             comment below.  */
        }
-      else if (strncmp (s->name, ".rela", 5) == 0)
+      else if (startswith (s->name, ".rela"))
        {
          if (s->size != 0)
            {
index a81ebd4d6beb6b8371e38be0bb516a3cec56106d..f6a2509d521513a1d096ace5789d4795d34209b7 100644 (file)
@@ -1802,12 +1802,12 @@ riscv_parse_subset (riscv_parse_subset_t *rps,
     }
 
   p = arch;
-  if (strncmp (p, "rv32", 4) == 0)
+  if (startswith (p, "rv32"))
     {
       *rps->xlen = 32;
       p += 4;
     }
-  else if (strncmp (p, "rv64", 4) == 0)
+  else if (startswith (p, "rv64"))
     {
       *rps->xlen = 64;
       p += 4;
index 28a1a43a96cbcd9ffa3d9e113c66cdbb22a41190..a517831a07c8009e9cbf465622533fa2deed9333 100644 (file)
@@ -2578,7 +2578,7 @@ tilegx_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
          /* Strip this section if we don't need it; see the
             comment below.  */
        }
-      else if (strncmp (s->name, ".rela", 5) == 0)
+      else if (startswith (s->name, ".rela"))
        {
          if (s->size != 0)
            {
index 26faaa6c9a95a901427ab74e81adfbddc0d6978c..74df4c2f5183cc82570165b2bdc731decd8b1b33 100644 (file)
@@ -1904,7 +1904,7 @@ get_build_id (bfd *abfd)
   if (inote.descsz <= 0
       || inote.type != NT_GNU_BUILD_ID
       || inote.namesz != 4 /* sizeof "GNU"  */
-      || strncmp (inote.namedata, "GNU", 4) != 0
+      || !startswith (inote.namedata, "GNU")
       || inote.descsz > 0x7ffffffe
       || size < (12 + BFD_ALIGN (inote.namesz, 4) + inote.descsz))
     {
index 125ac81103b2dabe571d750cbcafe44fd166abe6..1ffbdf8fc72e71fcaa2a572fd9c0330e06c469c2 100644 (file)
@@ -1,3 +1,11 @@
+2021-04-01  Martin Liska  <mliska@suse.cz>
+
+       * dllwrap.c: Use startswith function.
+       * objcopy.c (is_dwo_section): Likewise.
+       (handle_remove_section_option): Likewise.
+       (copy_main): Likewise.
+       * objdump.c (is_significant_symbol_name): Likewise.
+
 2021-04-01  Martin Liska  <mliska@suse.cz>
 
        * dwarf.c (display_debug_lines_raw): Replace const_strneq with
index bd65b98fee09ca24ef57bb382ca927b8ddd63ee5..bc7104de004b9858faf7d7d440f4ee13def1dd89 100644 (file)
@@ -840,11 +840,11 @@ Creating one, but that may not be what you want"));
   else
     which_target = UNKNOWN_TARGET;
 
-  if (! strncmp (target, "arm", 3))
+  if (startswith (target, "arm"))
     which_cpu = ARM_CPU;
-  else if (!strncmp (target, "x86_64", 6)
-          || !strncmp (target, "athlon64", 8)
-          || !strncmp (target, "amd64", 5))
+  else if (startswith (target, "x86_64")
+          || startswith (target, "athlon64")
+          || startswith (target, "amd64"))
     which_cpu = X64_CPU;
   else if (target[0] == 'i' && (target[1] >= '3' && target[1] <= '6')
           && target[2] == '8' && target[3] == '6')
index 092bc9e668a007e9c21b2e8e6caf7e5a54bc9eba..6622adc5e7c3aca75bb492a06bda19d76c6d6c01 100644 (file)
@@ -1285,7 +1285,7 @@ is_dwo_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
   if (len < 5)
     return false;
 
-  return strncmp (name + len - 4, ".dwo", 4) == 0;
+  return startswith (name + len - 4, ".dwo");
 }
 
 /* Return TRUE if section SEC is in the update list.  */
@@ -4261,7 +4261,7 @@ static void
 handle_remove_section_option (const char *section_pattern)
 {
   find_section_list (section_pattern, true, SECTION_CONTEXT_REMOVE);
-  if (strncmp (section_pattern, ".rel", 4) == 0)
+  if (startswith (section_pattern, ".rel"))
     {
       section_pattern += 4;
       if (*section_pattern == 'a')
@@ -5875,15 +5875,15 @@ copy_main (int argc, char *argv[])
 
   /* Convert input EFI target to PEI target.  */
   if (input_target != NULL
-      && strncmp (input_target, "efi-", 4) == 0)
+      && startswith (input_target, "efi-"))
     {
       char *efi;
 
       efi = xstrdup (output_target + 4);
-      if (strncmp (efi, "bsdrv-", 6) == 0
-         || strncmp (efi, "rtdrv-", 6) == 0)
+      if (startswith (efi, "bsdrv-")
+         || startswith (efi, "rtdrv-"))
        efi += 2;
-      else if (strncmp (efi, "app-", 4) != 0)
+      else if (!startswith (efi, "app-"))
        fatal (_("unknown input EFI target: %s"), input_target);
 
       input_target = efi;
@@ -5892,23 +5892,23 @@ copy_main (int argc, char *argv[])
 
   /* Convert output EFI target to PEI target.  */
   if (output_target != NULL
-      && strncmp (output_target, "efi-", 4) == 0)
+      && startswith (output_target, "efi-"))
     {
       char *efi;
 
       efi = xstrdup (output_target + 4);
-      if (strncmp (efi, "app-", 4) == 0)
+      if (startswith (efi, "app-"))
        {
          if (pe_subsystem == -1)
            pe_subsystem = IMAGE_SUBSYSTEM_EFI_APPLICATION;
        }
-      else if (strncmp (efi, "bsdrv-", 6) == 0)
+      else if (startswith (efi, "bsdrv-"))
        {
          if (pe_subsystem == -1)
            pe_subsystem = IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER;
          efi += 2;
        }
-      else if (strncmp (efi, "rtdrv-", 6) == 0)
+      else if (startswith (efi, "rtdrv-"))
        {
          if (pe_subsystem == -1)
            pe_subsystem = IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER;
index bffd7441eba6a2df61d2be566f760eb9ecfdd45b..cbbec81c026a16d041aeed12d5b9a813cc4ff77a 100644 (file)
@@ -821,7 +821,7 @@ slurp_dynamic_symtab (bfd *abfd)
 static bool
 is_significant_symbol_name (const char * name)
 {
-  return strncmp (name, ".plt", 4) == 0 || strcmp (name, ".got") == 0;
+  return startswith (name, ".plt") || startswith (name, ".got");
 }
 
 /* Filter out (in place) symbols that are useless for disassembly.
This page took 0.05885 seconds and 4 git commands to generate.