+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
 
 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
 
         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;
        }
 
   /* 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,
 
   /* 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')
 
        {
          /* 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;
 
 {
   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;
 
         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)
            {
 
        {
          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;
                  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);
 
 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);
                  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);
 
 {
   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;
 
                    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
 
   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
 
          name = h->root.root.string;
        }
 
-      if (strncmp (name, "$tableentry$default$", 20) == 0)
+      if (startswith (name, "$tableentry$default$"))
        {
          bfd_vma entry_vma;
          int idx;
   sec = ent->u.def.section;
   abfd = sec->owner;
 
-  if (strncmp (name, "$tablestart$", 12))
+  if (!startswith (name, "$tablestart$"))
     return true;
 
   sec->flags |= SEC_KEEP;
 
   name = ent->root.string;
 
-  if (strncmp (name, "$tablestart$", 12))
+  if (!startswith (name, "$tablestart$"))
     return true;
 
   tname = name + 12;
 
 {
   if (sym->name != NULL
       && sym->section != bfd_abs_section_ptr
-      && strncmp (sym->name, "_EAR_", 5) == 0)
+      && startswith (sym->name, "_EAR_"))
     sym->flags |= BSF_KEEP;
 }
 
             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;
              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;
                  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;
       /* 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;
     }
   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
   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
   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))
     {
                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);
              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);
      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)
          }
        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;
       && (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;
 
 
          /* 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)
            {
 
        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;
 
 
 {
   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;
                  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
 
 
       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));
       /* 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 == ':')                                         \
     }
 
 #define BINARY_OP_HEAD(op)                                     \
-  if (strncmp (sym, #op, strlen (#op)) == 0)                   \
+  if (startswith (sym, #op))                                   \
     {                                                          \
       sym += strlen (#op);                                     \
       if (*sym == ':')                                         \
          /* 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] == '.'))
 
          /* 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)
            {
 
     }
 
   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;
 
          /* 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)
            {
 
   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))
     {
 
+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
 
   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')
 
   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.  */
 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')
 
   /* 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;
 
   /* 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;
 
 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.