public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 2/5] Use startswith more for strncmp function calls.
  2021-03-24  8:19                     ` [PATCH 0/5] Start using startswith instead of strncmp Martin Liska
@ 2021-03-18 14:16                       ` Martin Liska
  2021-03-22 11:12                       ` [PATCH 1/5] Replace const_strneq with startswith Martin Liska
                                         ` (4 subsequent siblings)
  5 siblings, 0 replies; 41+ messages in thread
From: Martin Liska @ 2021-03-18 14:16 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 2662 bytes --]


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.
---
 bfd/elf-bfd.h          |  3 ++-
 bfd/elf.c              | 21 ++++++++++-----------
 bfd/elf32-arc.c        |  2 +-
 bfd/elf32-m32r.c       |  4 ++--
 bfd/elf32-microblaze.c |  2 +-
 bfd/elf32-nds32.c      | 13 ++++++-------
 bfd/elf32-or1k.c       |  2 +-
 bfd/elf32-ppc.c        |  6 +++---
 bfd/elf32-rx.c         |  6 +++---
 bfd/elf32-spu.c        | 26 +++++++++++++-------------
 bfd/elf32-tilepro.c    |  2 +-
 bfd/elf32-xtensa.c     |  2 +-
 bfd/elf64-ppc.c        |  6 +++---
 bfd/elflink.c          | 10 +++++-----
 bfd/elfnn-riscv.c      |  2 +-
 bfd/elfxx-riscv.c      |  4 ++--
 bfd/elfxx-tilegx.c     |  2 +-
 bfd/opncls.c           |  2 +-
 binutils/dllwrap.c     |  8 ++++----
 binutils/objcopy.c     | 20 ++++++++++----------
 binutils/objdump.c     |  2 +-
 21 files changed, 72 insertions(+), 73 deletions(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-Use-startswith-more-for-strncmp-function-calls.patch --]
[-- Type: text/x-patch; name="0002-Use-startswith-more-for-strncmp-function-calls.patch", Size: 21614 bytes --]

diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index 04785a814e8..8bac21f2f64 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -26,6 +26,7 @@
 #include "elf/external.h"
 #include "elf/internal.h"
 #include "bfdlink.h"
+#include "str-util.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -3095,7 +3096,7 @@ static inline bfd_boolean
 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
diff --git a/bfd/elf.c b/bfd/elf.c
index 3f9927072ef..e7b8cf174a9 100644
--- 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')
diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c
index df12fd33a10..88f388dfe9b 100644
--- a/bfd/elf32-arc.c
+++ b/bfd/elf32-arc.c
@@ -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;
diff --git a/bfd/elf32-m32r.c b/bfd/elf32-m32r.c
index 95e0c17bc5c..20bba31c733 100644
--- a/bfd/elf32-m32r.c
+++ b/bfd/elf32-m32r.c
@@ -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;
diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
index 1571bbb118a..ef059f1e668 100644
--- a/bfd/elf32-microblaze.c
+++ b/bfd/elf32-microblaze.c
@@ -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)
 	    {
diff --git a/bfd/elf32-nds32.c b/bfd/elf32-nds32.c
index 01d0702255a..d1ebfccd299 100644
--- a/bfd/elf32-nds32.c
+++ b/bfd/elf32-nds32.c
@@ -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;
diff --git a/bfd/elf32-or1k.c b/bfd/elf32-or1k.c
index 82a5b4ac8e2..ac460c2eb09 100644
--- a/bfd/elf32-or1k.c
+++ b/bfd/elf32-or1k.c
@@ -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
diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c
index fe8b6fdb7d1..77a3187e0a2 100644
--- a/bfd/elf32-ppc.c
+++ b/bfd/elf32-ppc.c
@@ -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
diff --git a/bfd/elf32-rx.c b/bfd/elf32-rx.c
index e2f4c9fb34a..b5ad93c0f93 100644
--- a/bfd/elf32-rx.c
+++ b/bfd/elf32-rx.c
@@ -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;
diff --git a/bfd/elf32-spu.c b/bfd/elf32-spu.c
index c31ab98b310..ed83e9c4bb7 100644
--- a/bfd/elf32-spu.c
+++ b/bfd/elf32-spu.c
@@ -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;
 
diff --git a/bfd/elf32-tilepro.c b/bfd/elf32-tilepro.c
index 255235a4eb5..89295ba03e7 100644
--- a/bfd/elf32-tilepro.c
+++ b/bfd/elf32-tilepro.c
@@ -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)
 	    {
diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c
index abc244c04cb..838ee8949e8 100644
--- a/bfd/elf32-xtensa.c
+++ b/bfd/elf32-xtensa.c
@@ -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;
 
diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
index 741f510a28d..c1ef86e0fab 100644
--- a/bfd/elf64-ppc.c
+++ b/bfd/elf64-ppc.c
@@ -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
diff --git a/bfd/elflink.c b/bfd/elflink.c
index c5db406f2b4..e64933e3cb6 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -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 == ':')						\
@@ -11195,10 +11195,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] == '.'))
diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 364d67b6749..ab2b5685050 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -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)
 	    {
diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c
index 966e142be4c..40dc6944bf3 100644
--- a/bfd/elfxx-riscv.c
+++ b/bfd/elfxx-riscv.c
@@ -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;
diff --git a/bfd/elfxx-tilegx.c b/bfd/elfxx-tilegx.c
index 3544a3064f8..f9d8eb69f90 100644
--- a/bfd/elfxx-tilegx.c
+++ b/bfd/elfxx-tilegx.c
@@ -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)
 	    {
diff --git a/bfd/opncls.c b/bfd/opncls.c
index 30ef9fd537d..b912030512b 100644
--- a/bfd/opncls.c
+++ b/bfd/opncls.c
@@ -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))
     {
diff --git a/binutils/dllwrap.c b/binutils/dllwrap.c
index bd65b98fee0..bc7104de004 100644
--- a/binutils/dllwrap.c
+++ b/binutils/dllwrap.c
@@ -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')
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index f5e48e80d08..168d526f462 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -1284,7 +1284,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.  */
@@ -4260,7 +4260,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')
@@ -5874,15 +5874,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;
@@ -5891,23 +5891,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;
diff --git a/binutils/objdump.c b/binutils/objdump.c
index cb5ce5b057c..b541f5e0d9a 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -821,7 +821,7 @@ slurp_dynamic_symtab (bfd *abfd)
 static bfd_boolean
 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.

^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH] [RFC] Come up with startswith function.
@ 2021-03-18 14:20 Martin Liška
  2021-03-18 14:54 ` Tom Tromey
  2021-03-18 18:29 ` Hans-Peter Nilsson
  0 siblings, 2 replies; 41+ messages in thread
From: Martin Liška @ 2021-03-18 14:20 UTC (permalink / raw)
  To: binutils

Hello.

This patch is the same what I suggested for the GCC project:
https://gcc.gnu.org/pipermail/gcc-patches/2021-March/566897.html

In case on binutils, it's hard to find a single header file that
is always used after string.h is included. That's why I for now
use __builtin_* functions.

Is the binutils community interested in the function?
Thanks,
Martin

---
  bfd/elf.c          | 17 ++++++++---------
  binutils/objcopy.c | 18 +++++++++---------
  include/ansidecl.h |  8 ++++++++
  3 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/bfd/elf.c b/bfd/elf.c
index 35c31cf40bf..91f8694ad4f 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -1084,18 +1084,18 @@ _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.linkonce.wi.", 17) == 0
-	      || strncmp (name, ".zdebug", 7) == 0)
+	  if (startswith (name, ".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;
  	}
@@ -1276,8 +1276,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,
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index d58f910f2fa..7c3d28d35cb 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -1284,7 +1284,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.  */
@@ -4260,7 +4260,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')
@@ -5874,13 +5874,13 @@ 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)
  	fatal (_("unknown input EFI target: %s"), input_target);
@@ -5891,23 +5891,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;
diff --git a/include/ansidecl.h b/include/ansidecl.h
index 0515228f325..5d11fd130b0 100644
--- a/include/ansidecl.h
+++ b/include/ansidecl.h
@@ -429,6 +429,14 @@ So instead we use the macro below and test it against specific values.  */
    void operator= (const TYPE &)
  #endif /* __cplusplus >= 201103 */
  
+/* Return 1 if STR string starts with PREFIX.  */
+
+static inline int
+startswith (const char *str, const char *prefix)
+{
+  return __builtin_strncmp (str, prefix, __builtin_strlen (prefix)) == 0;
+}
+
  #ifdef __cplusplus
  }
  #endif
-- 
2.30.2


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] [RFC] Come up with startswith function.
  2021-03-18 14:20 [PATCH] [RFC] Come up with startswith function Martin Liška
@ 2021-03-18 14:54 ` Tom Tromey
  2021-03-18 15:26   ` Martin Liška
  2021-03-18 18:29 ` Hans-Peter Nilsson
  1 sibling, 1 reply; 41+ messages in thread
From: Tom Tromey @ 2021-03-18 14:54 UTC (permalink / raw)
  To: Martin Liška; +Cc: binutils

>>>>> "Martin" == Martin Liška <mliska@suse.cz> writes:

Martin> Is the binutils community interested in the function?

gdb already has one.  Adding one in libiberty is fine with me as long as
it doesn't cause build failures there.

gdb's are in gdbsupport/common-utils.h; it is overloaded to handle
string_view as well.

Tom

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] [RFC] Come up with startswith function.
  2021-03-18 14:54 ` Tom Tromey
@ 2021-03-18 15:26   ` Martin Liška
  2021-03-18 18:00     ` Tom Tromey
  0 siblings, 1 reply; 41+ messages in thread
From: Martin Liška @ 2021-03-18 15:26 UTC (permalink / raw)
  To: Tom Tromey; +Cc: binutils

On 3/18/21 3:54 PM, Tom Tromey wrote:
>>>>>> "Martin" == Martin Liška <mliska@suse.cz> writes:
> 
> Martin> Is the binutils community interested in the function?
> 
> gdb already has one.

Heh, gdb is always using the cutting edge features, like modern C++.

> Adding one in libiberty is fine with me as long as
> it doesn't cause build failures there.

I considered doing that but it has some drawbacks:
- we want to have the implementation in a header file
- one needs '#include <string.h>'
- or it will have to be a macro, but it will have to use '__extension__ ({...' syntax
   as we won't double evaluation of the PREFIX argument

> 
> gdb's are in gdbsupport/common-utils.h; it is overloaded to handle
> string_view as well.

Nice!

Martin

> 
> Tom
> 


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] [RFC] Come up with startswith function.
  2021-03-18 15:26   ` Martin Liška
@ 2021-03-18 18:00     ` Tom Tromey
  0 siblings, 0 replies; 41+ messages in thread
From: Tom Tromey @ 2021-03-18 18:00 UTC (permalink / raw)
  To: Martin Liška; +Cc: Tom Tromey, binutils

>>>>> "Martin" == Martin Liška <mliska@suse.cz> writes:

>> Adding one in libiberty is fine with me as long as
>> it doesn't cause build failures there.

Martin> I considered doing that but it has some drawbacks:

Sorry, I probably should have said "your patch" instead -- that's what I
really meant.  Most or all of gdb includes ansidecl.h, so it would be
good to try the build before landing.

thanks,
Tom

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] [RFC] Come up with startswith function.
  2021-03-18 14:20 [PATCH] [RFC] Come up with startswith function Martin Liška
  2021-03-18 14:54 ` Tom Tromey
@ 2021-03-18 18:29 ` Hans-Peter Nilsson
  2021-03-19  6:37   ` Alan Modra
  1 sibling, 1 reply; 41+ messages in thread
From: Hans-Peter Nilsson @ 2021-03-18 18:29 UTC (permalink / raw)
  To: Martin Liška; +Cc: binutils

On Thu, 18 Mar 2021, Martin Li?ka wrote:

> Hello.
>
> This patch is the same what I suggested for the GCC project:
> https://gcc.gnu.org/pipermail/gcc-patches/2021-March/566897.html
>
> In case on binutils, it's hard to find a single header file that
> is always used after string.h is included. That's why I for now
> use __builtin_* functions.
>
> Is the binutils community interested in the function?

How about instead moving and/or making more use of CONST_STRNEQ
from bfd/bfd-in.h?

brgds, H-P

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] [RFC] Come up with startswith function.
  2021-03-18 18:29 ` Hans-Peter Nilsson
@ 2021-03-19  6:37   ` Alan Modra
  2021-03-19 12:44     ` [PATCH] Add startswith function and use it instead of CONST_STRNEQ Martin Liška
  0 siblings, 1 reply; 41+ messages in thread
From: Alan Modra @ 2021-03-19  6:37 UTC (permalink / raw)
  To: Hans-Peter Nilsson; +Cc: Martin Liška, binutils

On Thu, Mar 18, 2021 at 02:29:26PM -0400, Hans-Peter Nilsson wrote:
> On Thu, 18 Mar 2021, Martin Li?ka wrote:
> 
> > Hello.
> >
> > This patch is the same what I suggested for the GCC project:
> > https://gcc.gnu.org/pipermail/gcc-patches/2021-March/566897.html
> >
> > In case on binutils, it's hard to find a single header file that
> > is always used after string.h is included. That's why I for now
> > use __builtin_* functions.

Use of builtin functions will need at least a __GNUC__ test and
fallback for other compilers, which I guess means you may as well
simply use strncmp and strlen.

> > Is the binutils community interested in the function?
> 
> How about instead moving and/or making more use of CONST_STRNEQ
> from bfd/bfd-in.h?

To me the name CONST_STRNEQ just doesn't parse well.  Maybe I'm just
weird, but I read it as "constant string not equal" which of course is
wrong.  I much prefer startswith as a name.  bfd-in.h ought to work
for an inline startswith too, since every sysdep.h in binutils already
includes string.h, and so too does gas/as.h.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH] Add startswith function and use it instead of CONST_STRNEQ.
  2021-03-19  6:37   ` Alan Modra
@ 2021-03-19 12:44     ` Martin Liška
  2021-03-19 17:55       ` Hans-Peter Nilsson
                         ` (2 more replies)
  0 siblings, 3 replies; 41+ messages in thread
From: Martin Liška @ 2021-03-19 12:44 UTC (permalink / raw)
  To: Alan Modra, Hans-Peter Nilsson; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 1530 bytes --]

On 3/19/21 7:37 AM, Alan Modra wrote:
> On Thu, Mar 18, 2021 at 02:29:26PM -0400, Hans-Peter Nilsson wrote:
>> On Thu, 18 Mar 2021, Martin Li?ka wrote:
>>
>>> Hello.
>>>
>>> This patch is the same what I suggested for the GCC project:
>>> https://gcc.gnu.org/pipermail/gcc-patches/2021-March/566897.html
>>>
>>> In case on binutils, it's hard to find a single header file that
>>> is always used after string.h is included. That's why I for now
>>> use __builtin_* functions.
> 
> Use of builtin functions will need at least a __GNUC__ test and
> fallback for other compilers, which I guess means you may as well
> simply use strncmp and strlen.
> 
>>> Is the binutils community interested in the function?
>>
>> How about instead moving and/or making more use of CONST_STRNEQ
>> from bfd/bfd-in.h?
> 
> To me the name CONST_STRNEQ just doesn't parse well.  Maybe I'm just
> weird, but I read it as "constant string not equal" which of course is
> wrong.  I much prefer startswith as a name.

No, you're not weird! The function name is weird. To be honest, I noticed
the function, but the name was so misleading that I ignored it.

> bfd-in.h ought to work
> for an inline startswith too, since every sysdep.h in binutils already
> includes string.h, and so too does gas/as.h.

Yes, that's a correct location. I tried placing the new function here, but
I didn't notice 'make headers' :)

Anyway, as a first step I'm suggesting to do the renaming and I can carry on
with follow up patches that will use the function more.

Martin


[-- Attachment #2: 0001-Add-startswith-function-and-use-it-instead-of-CONST_.patch --]
[-- Type: text/x-patch, Size: 105026 bytes --]

From 46f736830ec492521c2562e8364c7c0ec317e358 Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Fri, 19 Mar 2021 11:50:26 +0100
Subject: [PATCH 1/2] Add startswith function and use it instead of
 CONST_STRNEQ.

bfd/ChangeLog:

	* bfd-in.h (startswith): Add startswith function.
	(CONST_STRNEQ): Remove.
	* bfd-in2.h (startswith): Regenerate with make headers.
	* (all locations): Replace usage of CONST_STRNEQ with
	startswith.
---
 bfd/archive.c             | 18 ++++++------
 bfd/archive64.c           |  4 +--
 bfd/bfd-in.h              | 18 ++++++------
 bfd/bfd-in2.h             | 18 ++++++------
 bfd/bfd.c                 |  8 +++---
 bfd/coff-stgo32.c         |  4 +--
 bfd/coffcode.h            | 58 +++++++++++++++++++--------------------
 bfd/coffgen.c             | 16 +++++------
 bfd/cofflink.c            | 12 ++++----
 bfd/compress.c            |  4 +--
 bfd/dwarf2.c              |  8 +++---
 bfd/ecoff.c               |  2 +-
 bfd/elf-m10300.c          |  4 +--
 bfd/elf.c                 |  6 ++--
 bfd/elf32-arm.c           | 12 ++++----
 bfd/elf32-bfin.c          |  4 +--
 bfd/elf32-cr16.c          |  4 +--
 bfd/elf32-cris.c          |  4 +--
 bfd/elf32-csky.c          |  2 +-
 bfd/elf32-hppa.c          |  2 +-
 bfd/elf32-iq2000.c        |  6 ++--
 bfd/elf32-lm32.c          |  2 +-
 bfd/elf32-m32r.c          |  2 +-
 bfd/elf32-m68k.c          |  4 +--
 bfd/elf32-metag.c         |  2 +-
 bfd/elf32-msp430.c        |  4 +--
 bfd/elf32-nios2.c         |  2 +-
 bfd/elf32-or1k.c          |  2 +-
 bfd/elf32-ppc.c           |  2 +-
 bfd/elf32-s390.c          |  2 +-
 bfd/elf32-score.c         |  6 ++--
 bfd/elf32-score7.c        |  6 ++--
 bfd/elf32-sh.c            |  2 +-
 bfd/elf32-tic6x.c         |  6 ++--
 bfd/elf32-vax.c           |  4 +--
 bfd/elf32-xtensa.c        | 22 +++++++--------
 bfd/elf64-alpha.c         |  6 ++--
 bfd/elf64-hppa.c          |  4 +--
 bfd/elf64-ia64-vms.c      | 14 +++++-----
 bfd/elf64-mmix.c          |  2 +-
 bfd/elf64-ppc.c           |  2 +-
 bfd/elf64-s390.c          |  2 +-
 bfd/elflink.c             | 14 +++++-----
 bfd/elfnn-aarch64.c       |  2 +-
 bfd/elfnn-ia64.c          | 10 +++----
 bfd/elfxx-mips.c          | 52 +++++++++++++++++------------------
 bfd/elfxx-sparc.c         |  2 +-
 bfd/elfxx-x86.c           |  4 +--
 bfd/hpux-core.c           |  2 +-
 bfd/libcoff.h             |  2 +-
 bfd/linker.c              |  8 +++---
 bfd/mmo.c                 |  2 +-
 bfd/osf-core.c            |  2 +-
 bfd/pef.c                 |  2 +-
 bfd/pei-x86_64.c          |  2 +-
 bfd/som.c                 |  6 ++--
 bfd/wasm-module.c         |  2 +-
 binutils/dlltool.c        |  4 +--
 binutils/emul_aix.c       |  8 +++---
 binutils/objcopy.c        |  2 +-
 binutils/objdump.c        |  2 +-
 binutils/prdbg.c          |  8 +++---
 binutils/readelf.c        |  2 +-
 binutils/stabs.c          | 12 ++++----
 gas/config/tc-i386.c      |  6 ++--
 gas/config/tc-sparc.c     |  4 +--
 gdb/arm-tdep.c            |  6 ++--
 ld/emultempl/aix.em       |  2 +-
 ld/emultempl/beos.em      |  6 ++--
 ld/emultempl/elf.em       | 12 ++++----
 ld/emultempl/pe.em        |  2 +-
 ld/emultempl/pep.em       |  2 +-
 ld/emultempl/xtensaelf.em |  4 +--
 ld/ldctor.c               |  2 +-
 ld/ldelf.c                | 16 +++++------
 ld/ldfile.c               |  2 +-
 ld/ldlang.c               |  2 +-
 ld/ldmain.c               |  6 ++--
 ld/ldwrite.c              |  4 +--
 ld/lexsup.c               |  2 +-
 ld/pe-dll.c               |  4 +--
 opcodes/aarch64-dis.c     | 10 +++----
 opcodes/arc-dis.c         |  2 +-
 opcodes/arm-dis.c         | 14 +++++-----
 opcodes/cris-dis.c        |  8 +++---
 opcodes/h8300-dis.c       |  2 +-
 opcodes/i386-dis.c        | 24 ++++++++--------
 opcodes/ia64-gen.c        | 48 ++++++++++++++++----------------
 opcodes/mips-dis.c        | 18 ++++++------
 opcodes/s390-dis.c        |  6 ++--
 opcodes/wasm32-dis.c      |  4 +--
 91 files changed, 338 insertions(+), 342 deletions(-)

diff --git a/bfd/archive.c b/bfd/archive.c
index 81ef62f1690..2a9ca56b653 100644
--- a/bfd/archive.c
+++ b/bfd/archive.c
@@ -1175,12 +1175,12 @@ bfd_slurp_armap (bfd *abfd)
   if (bfd_seek (abfd, (file_ptr) -16, SEEK_CUR) != 0)
     return FALSE;
 
-  if (CONST_STRNEQ (nextname, "__.SYMDEF       ")
-      || CONST_STRNEQ (nextname, "__.SYMDEF/      ")) /* Old Linux archives.  */
+  if (startswith (nextname, "__.SYMDEF       ")
+      || startswith (nextname, "__.SYMDEF/      ")) /* Old Linux archives.  */
     return do_slurp_bsd_armap (abfd);
-  else if (CONST_STRNEQ (nextname, "/               "))
+  else if (startswith (nextname, "/               "))
     return do_slurp_coff_armap (abfd);
-  else if (CONST_STRNEQ (nextname, "/SYM64/         "))
+  else if (startswith (nextname, "/SYM64/         "))
     {
       /* 64bit (Irix 6) archive.  */
 #ifdef BFD64
@@ -1190,7 +1190,7 @@ bfd_slurp_armap (bfd *abfd)
       return FALSE;
 #endif
     }
-  else if (CONST_STRNEQ (nextname, "#1/20           "))
+  else if (startswith (nextname, "#1/20           "))
     {
       /* Mach-O has a special name for armap when the map is sorted by name.
 	 However because this name has a space it is slightly more difficult
@@ -1206,8 +1206,8 @@ bfd_slurp_armap (bfd *abfd)
       if (bfd_seek (abfd, -(file_ptr) (sizeof (hdr) + 20), SEEK_CUR) != 0)
 	return FALSE;
       extname[20] = 0;
-      if (CONST_STRNEQ (extname, "__.SYMDEF SORTED")
-	  || CONST_STRNEQ (extname, "__.SYMDEF"))
+      if (startswith (extname, "__.SYMDEF SORTED")
+	  || startswith (extname, "__.SYMDEF"))
 	return do_slurp_bsd_armap (abfd);
     }
 
@@ -1246,8 +1246,8 @@ _bfd_slurp_extended_name_table (bfd *abfd)
       if (bfd_seek (abfd, (file_ptr) -16, SEEK_CUR) != 0)
 	return FALSE;
 
-      if (! CONST_STRNEQ (nextname, "ARFILENAMES/    ")
-	  && ! CONST_STRNEQ (nextname, "//              "))
+      if (! startswith (nextname, "ARFILENAMES/    ")
+	  && ! startswith (nextname, "//              "))
 	{
 	  bfd_ardata (abfd)->extended_names = NULL;
 	  bfd_ardata (abfd)->extended_names_size = 0;
diff --git a/bfd/archive64.c b/bfd/archive64.c
index 42e24cd849b..6d76b4d7796 100644
--- a/bfd/archive64.c
+++ b/bfd/archive64.c
@@ -62,10 +62,10 @@ _bfd_archive_64_bit_slurp_armap (bfd *abfd)
     return FALSE;
 
   /* Archives with traditional armaps are still permitted.  */
-  if (CONST_STRNEQ (nextname, "/               "))
+  if (startswith (nextname, "/               "))
     return bfd_slurp_armap (abfd);
 
-  if (! CONST_STRNEQ (nextname, "/SYM64/         "))
+  if (! startswith (nextname, "/SYM64/         "))
     {
       abfd->has_armap = FALSE;
       return TRUE;
diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h
index c9a76731475..17ba6ad9c36 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -56,16 +56,7 @@ extern "C" {
    comma and then the length of the string.  Doing this by hand
    is error prone, so using this macro is safer.  */
 #define STRING_COMMA_LEN(STR) (STR), (sizeof (STR) - 1)
-/* Unfortunately it is not possible to use the STRING_COMMA_LEN macro
-   to create the arguments to another macro, since the preprocessor
-   will mis-count the number of arguments to the outer macro (by not
-   evaluating STRING_COMMA_LEN and so missing the comma).  This is a
-   problem for example when trying to use STRING_COMMA_LEN to build
-   the arguments to the strncmp() macro.  Hence this alternative
-   definition of strncmp is provided here.
-
-   Note - these macros do NOT work if STR2 is not a constant string.  */
-#define CONST_STRNEQ(STR1,STR2) (strncmp ((STR1), (STR2), sizeof (STR2) - 1) == 0)
+
   /* strcpy() can have a similar problem, but since we know we are
      copying a constant string, we can use memcpy which will be faster
      since there is no need to check for a NUL byte inside STR.  We
@@ -73,6 +64,13 @@ extern "C" {
 #define LITMEMCPY(DEST,STR2) memcpy ((DEST), (STR2), sizeof (STR2) - 1)
 #define LITSTRCPY(DEST,STR2) memcpy ((DEST), (STR2), sizeof (STR2))
 
+/* Return 1 if STR string starts with PREFIX.  */
+
+static inline int
+startswith (const char *str, const char *prefix)
+{
+  return __builtin_strncmp (str, prefix, __builtin_strlen (prefix)) == 0;
+}
 
 #define BFD_SUPPORTS_PLUGINS @supports_plugins@
 
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 54c1c9a6b64..b79661d9bd3 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -63,16 +63,7 @@ extern "C" {
    comma and then the length of the string.  Doing this by hand
    is error prone, so using this macro is safer.  */
 #define STRING_COMMA_LEN(STR) (STR), (sizeof (STR) - 1)
-/* Unfortunately it is not possible to use the STRING_COMMA_LEN macro
-   to create the arguments to another macro, since the preprocessor
-   will mis-count the number of arguments to the outer macro (by not
-   evaluating STRING_COMMA_LEN and so missing the comma).  This is a
-   problem for example when trying to use STRING_COMMA_LEN to build
-   the arguments to the strncmp() macro.  Hence this alternative
-   definition of strncmp is provided here.
-
-   Note - these macros do NOT work if STR2 is not a constant string.  */
-#define CONST_STRNEQ(STR1,STR2) (strncmp ((STR1), (STR2), sizeof (STR2) - 1) == 0)
+
   /* strcpy() can have a similar problem, but since we know we are
      copying a constant string, we can use memcpy which will be faster
      since there is no need to check for a NUL byte inside STR.  We
@@ -80,6 +71,13 @@ extern "C" {
 #define LITMEMCPY(DEST,STR2) memcpy ((DEST), (STR2), sizeof (STR2) - 1)
 #define LITSTRCPY(DEST,STR2) memcpy ((DEST), (STR2), sizeof (STR2))
 
+/* Return 1 if STR string starts with PREFIX.  */
+
+static inline int
+startswith (const char *str, const char *prefix)
+{
+  return __builtin_strncmp (str, prefix, __builtin_strlen (prefix)) == 0;
+}
 
 #define BFD_SUPPORTS_PLUGINS @supports_plugins@
 
diff --git a/bfd/bfd.c b/bfd/bfd.c
index 2c620857863..757fa5f2819 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -1746,7 +1746,7 @@ bfd_get_sign_extend_vma (bfd *abfd)
      no place to store this information in the COFF back end.
      Should enough other COFF targets add support for DWARF2,
      a place will have to be found.  Until then, this hack will do.  */
-  if (CONST_STRNEQ (name, "coff-go32")
+  if (startswith (name, "coff-go32")
       || strcmp (name, "pe-i386") == 0
       || strcmp (name, "pei-i386") == 0
       || strcmp (name, "pe-x86-64") == 0
@@ -1757,7 +1757,7 @@ bfd_get_sign_extend_vma (bfd *abfd)
       || strcmp (name, "aix5coff64-rs6000") == 0)
     return 1;
 
-  if (CONST_STRNEQ (name, "mach-o"))
+  if (startswith (name, "mach-o"))
     return 0;
 
   bfd_set_error (bfd_error_wrong_format);
@@ -2660,7 +2660,7 @@ bfd_convert_section_size (bfd *ibfd, sec_ptr isec, bfd *obfd,
     return size;
 
   /* Convert GNU property size.  */
-  if (CONST_STRNEQ (isec->name, NOTE_GNU_PROPERTY_SECTION_NAME))
+  if (startswith (isec->name, NOTE_GNU_PROPERTY_SECTION_NAME))
     return _bfd_elf_convert_gnu_property_size (ibfd, obfd);
 
   /* Do nothing if input file will be decompressed.  */
@@ -2718,7 +2718,7 @@ bfd_convert_section_contents (bfd *ibfd, sec_ptr isec, bfd *obfd,
     return TRUE;
 
   /* Convert GNU properties.  */
-  if (CONST_STRNEQ (isec->name, NOTE_GNU_PROPERTY_SECTION_NAME))
+  if (startswith (isec->name, NOTE_GNU_PROPERTY_SECTION_NAME))
     return _bfd_elf_convert_gnu_properties (ibfd, isec, obfd, ptr,
 					    ptr_size);
 
diff --git a/bfd/coff-stgo32.c b/bfd/coff-stgo32.c
index 7593b62e8e6..8f75eecf4ee 100644
--- a/bfd/coff-stgo32.c
+++ b/bfd/coff-stgo32.c
@@ -176,7 +176,7 @@ go32exe_create_stub (bfd *abfd)
 	  close (f);
 	  goto stub_end;
 	}
-      if (! CONST_STRNEQ (magic, "go32stub"))
+      if (! startswith (magic, "go32stub"))
 	{
 	  close (f);
 	  goto stub_end;
@@ -306,7 +306,7 @@ go32exe_check_format (bfd *abfd)
   header_end = H_GET_16 (abfd, filehdr_dos.e_cparhdr) * 16UL;
   if (go32exe_temp_stub_size < header_end
       || go32exe_temp_stub_size - header_end < sizeof "go32stub" - 1
-      || !CONST_STRNEQ (go32exe_temp_stub + header_end, "go32stub"))
+      || !startswith (go32exe_temp_stub + header_end, "go32stub"))
     goto fail_format;
 
   /* Set origin to where the COFF header starts and seek there.  */
diff --git a/bfd/coffcode.h b/bfd/coffcode.h
index bcd34d469b6..d1ad669a6db 100644
--- a/bfd/coffcode.h
+++ b/bfd/coffcode.h
@@ -527,8 +527,8 @@ sec_to_styp_flags (const char *sec_name, flagword sec_flags)
       styp_flags = STYP_LIT;
 #endif /* _LIT */
     }
-  else if (CONST_STRNEQ (sec_name, DOT_DEBUG)
-	   || CONST_STRNEQ (sec_name, DOT_ZDEBUG))
+  else if (startswith (sec_name, DOT_DEBUG)
+	   || startswith (sec_name, DOT_ZDEBUG))
     {
       /* Handle the XCOFF debug section and DWARF2 debug sections.  */
       if (!sec_name[6])
@@ -536,13 +536,13 @@ sec_to_styp_flags (const char *sec_name, flagword sec_flags)
       else
 	styp_flags = STYP_DEBUG_INFO;
     }
-  else if (CONST_STRNEQ (sec_name, ".stab"))
+  else if (startswith (sec_name, ".stab"))
     {
       styp_flags = STYP_DEBUG_INFO;
     }
 #ifdef COFF_LONG_SECTION_NAMES
-  else if (CONST_STRNEQ (sec_name, GNU_LINKONCE_WI)
-	   || CONST_STRNEQ (sec_name, GNU_LINKONCE_WT))
+  else if (startswith (sec_name, GNU_LINKONCE_WI)
+	   || startswith (sec_name, GNU_LINKONCE_WT))
     {
       styp_flags = STYP_DEBUG_INFO;
     }
@@ -642,13 +642,13 @@ sec_to_styp_flags (const char *sec_name, flagword sec_flags)
   long styp_flags = 0;
   bfd_boolean is_dbg = FALSE;
 
-  if (CONST_STRNEQ (sec_name, DOT_DEBUG)
-      || CONST_STRNEQ (sec_name, DOT_ZDEBUG)
+  if (startswith (sec_name, DOT_DEBUG)
+      || startswith (sec_name, DOT_ZDEBUG)
 #ifdef COFF_LONG_SECTION_NAMES
-      || CONST_STRNEQ (sec_name, GNU_LINKONCE_WI)
-      || CONST_STRNEQ (sec_name, GNU_LINKONCE_WT)
+      || startswith (sec_name, GNU_LINKONCE_WI)
+      || startswith (sec_name, GNU_LINKONCE_WT)
 #endif
-      || CONST_STRNEQ (sec_name, ".stab"))
+      || startswith (sec_name, ".stab"))
     is_dbg = TRUE;
 
   /* caution: there are at least three groups of symbols that have
@@ -843,16 +843,16 @@ styp_to_sec_flags (bfd *abfd,
 #endif
 	sec_flags |= SEC_ALLOC;
     }
-  else if (CONST_STRNEQ (name, DOT_DEBUG)
-	   || CONST_STRNEQ (name, DOT_ZDEBUG)
+  else if (startswith (name, DOT_DEBUG)
+	   || startswith (name, DOT_ZDEBUG)
 #ifdef _COMMENT
 	   || strcmp (name, _COMMENT) == 0
 #endif
 #ifdef COFF_LONG_SECTION_NAMES
-	   || CONST_STRNEQ (name, GNU_LINKONCE_WI)
-	   || CONST_STRNEQ (name, GNU_LINKONCE_WT)
+	   || startswith (name, GNU_LINKONCE_WI)
+	   || startswith (name, GNU_LINKONCE_WT)
 #endif
-	   || CONST_STRNEQ (name, ".stab"))
+	   || startswith (name, ".stab"))
     {
 #ifdef COFF_PAGE_SIZE
       sec_flags |= SEC_DEBUGGING;
@@ -880,8 +880,8 @@ styp_to_sec_flags (bfd *abfd,
 #endif /* STYP_SDATA */
 
   if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
-      && (CONST_STRNEQ (name, ".sbss")
-	  || CONST_STRNEQ (name, ".sdata")))
+      && (startswith (name, ".sbss")
+	  || startswith (name, ".sdata")))
     sec_flags |= SEC_SMALL_DATA;
 
 #if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
@@ -891,7 +891,7 @@ styp_to_sec_flags (bfd *abfd,
      The symbols will be defined as weak, so that multiple definitions
      are permitted.  The GNU linker extension is to actually discard
      all but one of the sections.  */
-  if (CONST_STRNEQ (name, ".gnu.linkonce"))
+  if (startswith (name, ".gnu.linkonce"))
     sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
 #endif
 
@@ -1203,18 +1203,18 @@ styp_to_sec_flags (bfd *abfd,
   bfd_boolean result = TRUE;
   bfd_boolean is_dbg = FALSE;
 
-  if (CONST_STRNEQ (name, DOT_DEBUG)
-      || CONST_STRNEQ (name, DOT_ZDEBUG)
+  if (startswith (name, DOT_DEBUG)
+      || startswith (name, DOT_ZDEBUG)
 #ifdef COFF_LONG_SECTION_NAMES
-      || CONST_STRNEQ (name, GNU_LINKONCE_WI)
-      || CONST_STRNEQ (name, GNU_LINKONCE_WT)
+      || startswith (name, GNU_LINKONCE_WI)
+      || startswith (name, GNU_LINKONCE_WT)
       /* FIXME: These definitions ought to be in a header file.  */
 #define GNU_DEBUGLINK		".gnu_debuglink"
 #define GNU_DEBUGALTLINK	".gnu_debugaltlink"
-      || CONST_STRNEQ (name, GNU_DEBUGLINK)
-      || CONST_STRNEQ (name, GNU_DEBUGALTLINK)
+      || startswith (name, GNU_DEBUGLINK)
+      || startswith (name, GNU_DEBUGALTLINK)
 #endif
-      || CONST_STRNEQ (name, ".stab"))
+      || startswith (name, ".stab"))
     is_dbg = TRUE;
   /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified.  */
   sec_flags = SEC_READONLY;
@@ -1347,8 +1347,8 @@ styp_to_sec_flags (bfd *abfd,
     }
 
   if ((bfd_applicable_section_flags (abfd) & SEC_SMALL_DATA) != 0
-      && (CONST_STRNEQ (name, ".sbss")
-	  || CONST_STRNEQ (name, ".sdata")))
+      && (startswith (name, ".sbss")
+	  || startswith (name, ".sdata")))
     sec_flags |= SEC_SMALL_DATA;
 
 #if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
@@ -1358,7 +1358,7 @@ styp_to_sec_flags (bfd *abfd,
      The symbols will be defined as weak, so that multiple definitions
      are permitted.  The GNU linker extension is to actually discard
      all but one of the sections.  */
-  if (CONST_STRNEQ (name, ".gnu.linkonce"))
+  if (startswith (name, ".gnu.linkonce"))
     sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
 #endif
 
@@ -1679,7 +1679,7 @@ Special entry points for gdb to swap in coff symbol table parts:
 .{* Macro: Returns true if the bfd is a PE executable as opposed to a
 .   PE object file.  *}
 .#define bfd_pei_p(abfd) \
-.  (CONST_STRNEQ ((abfd)->xvec->name, "pei-"))
+.  (startswith ((abfd)->xvec->name, "pei-"))
 */
 
 /* See whether the magic number matches.  */
diff --git a/bfd/coffgen.c b/bfd/coffgen.c
index 526e26c662a..f493978815e 100644
--- a/bfd/coffgen.c
+++ b/bfd/coffgen.c
@@ -2635,7 +2635,7 @@ _bfd_coff_section_already_linked (bfd *abfd,
     key = s_comdat->name;
   else
     {
-      if (CONST_STRNEQ (name, ".gnu.linkonce.")
+      if (startswith (name, ".gnu.linkonce.")
 	  && (key = strchr (name + sizeof (".gnu.linkonce.") - 1, '.')) != NULL)
 	key++;
       else
@@ -2995,10 +2995,10 @@ coff_gc_sweep (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *info)
 	  if ((o->flags & (SEC_DEBUGGING | SEC_LINKER_CREATED)) != 0
 	      || (o->flags & (SEC_ALLOC | SEC_LOAD | SEC_RELOC)) == 0)
 	    o->gc_mark = 1;
-	  else if (CONST_STRNEQ (o->name, ".idata")
-		   || CONST_STRNEQ (o->name, ".pdata")
-		   || CONST_STRNEQ (o->name, ".xdata")
-		   || CONST_STRNEQ (o->name, ".rsrc"))
+	  else if (startswith (o->name, ".idata")
+		   || startswith (o->name, ".pdata")
+		   || startswith (o->name, ".xdata")
+		   || startswith (o->name, ".rsrc"))
 	    o->gc_mark = 1;
 
 	  if (o->gc_mark)
@@ -3109,9 +3109,9 @@ bfd_coff_gc_sections (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *info)
       for (o = sub->sections; o != NULL; o = o->next)
 	{
 	  if (((o->flags & (SEC_EXCLUDE | SEC_KEEP)) == SEC_KEEP
-	       || CONST_STRNEQ (o->name, ".vectors")
-	       || CONST_STRNEQ (o->name, ".ctors")
-	       || CONST_STRNEQ (o->name, ".dtors"))
+	       || startswith (o->name, ".vectors")
+	       || startswith (o->name, ".ctors")
+	       || startswith (o->name, ".dtors"))
 	      && !o->gc_mark)
 	    {
 	      if (!_bfd_coff_gc_mark (info, o, _bfd_coff_gc_mark_hook))
diff --git a/bfd/cofflink.c b/bfd/cofflink.c
index 874354a70d0..05c6fff746c 100644
--- a/bfd/cofflink.c
+++ b/bfd/cofflink.c
@@ -397,7 +397,7 @@ coff_link_add_symbols (bfd *abfd,
 		  || classification == COFF_SYMBOL_PE_SECTION)
 	      && coff_section_data (abfd, section) != NULL
 	      && coff_section_data (abfd, section)->comdat != NULL
-	      && CONST_STRNEQ (name, "??_")
+	      && startswith (name, "??_")
 	      && strcmp (name, coff_section_data (abfd, section)->comdat->name) == 0)
 	    {
 	      if (*sym_hash == NULL)
@@ -546,7 +546,7 @@ coff_link_add_symbols (bfd *abfd,
 	  asection *stab;
 
 	  for (stab = abfd->sections; stab; stab = stab->next)
-	    if (CONST_STRNEQ (stab->name, ".stab")
+	    if (startswith (stab->name, ".stab")
 		&& (!stab->name[5]
 		    || (stab->name[5] == '.' && ISDIGIT (stab->name[6]))))
 	    {
@@ -1274,7 +1274,7 @@ process_embedded_commands (bfd *output_bfd,
 	  s++;
 	  continue;
 	}
-      if (CONST_STRNEQ (s, "-attr"))
+      if (startswith (s, "-attr"))
 	{
 	  char *name;
 	  char *attribs;
@@ -1314,14 +1314,14 @@ process_embedded_commands (bfd *output_bfd,
 		asec->flags |= SEC_READONLY;
 	    }
 	}
-      else if (CONST_STRNEQ (s, "-heap"))
+      else if (startswith (s, "-heap"))
 	s = dores_com (s + 5, output_bfd, 1);
 
-      else if (CONST_STRNEQ (s, "-stack"))
+      else if (startswith (s, "-stack"))
 	s = dores_com (s + 6, output_bfd, 0);
 
       /* GNU extension for aligned commons.  */
-      else if (CONST_STRNEQ (s, "-aligncomm:"))
+      else if (startswith (s, "-aligncomm:"))
 	{
 	  /* Common symbols must be aligned on reading, as it
 	  is too late to do anything here, after they have
diff --git a/bfd/compress.c b/bfd/compress.c
index 2e73c760e75..054ea08bb14 100644
--- a/bfd/compress.c
+++ b/bfd/compress.c
@@ -431,7 +431,7 @@ bfd_is_section_compressed_with_header (bfd *abfd, sec_ptr sec,
       if (compression_header_size == 0)
 	/* In this case, it should be "ZLIB" followed by the uncompressed
 	   section size, 8 bytes in big-endian order.  */
-	compressed = CONST_STRNEQ ((char*) header , "ZLIB");
+	compressed = startswith ((char*) header , "ZLIB");
       else
 	compressed = TRUE;
     }
@@ -536,7 +536,7 @@ bfd_init_section_decompress_status (bfd *abfd, sec_ptr sec)
     {
       /* In this case, it should be "ZLIB" followed by the uncompressed
 	 section size, 8 bytes in big-endian order.  */
-      if (! CONST_STRNEQ ((char*) header, "ZLIB"))
+      if (! startswith ((char*) header, "ZLIB"))
 	{
 	  bfd_set_error (bfd_error_wrong_format);
 	  return FALSE;
diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c
index b42e641aa3b..c491471783d 100644
--- a/bfd/dwarf2.c
+++ b/bfd/dwarf2.c
@@ -4234,7 +4234,7 @@ find_debug_info (bfd *abfd, const struct dwarf_debug_section *debug_sections,
 	}
 
       for (msec = abfd->sections; msec != NULL; msec = msec->next)
-	if (CONST_STRNEQ (msec->name, GNU_LINKONCE_INFO))
+	if (startswith (msec->name, GNU_LINKONCE_INFO))
 	  return msec;
 
       return NULL;
@@ -4250,7 +4250,7 @@ find_debug_info (bfd *abfd, const struct dwarf_debug_section *debug_sections,
       if (look != NULL && strcmp (msec->name, look) == 0)
 	return msec;
 
-      if (CONST_STRNEQ (msec->name, GNU_LINKONCE_INFO))
+      if (startswith (msec->name, GNU_LINKONCE_INFO))
 	return msec;
     }
 
@@ -4375,7 +4375,7 @@ place_sections (bfd *orig_bfd, struct dwarf2_debug *stash)
 	    continue;
 
 	  is_debug_info = (strcmp (sect->name, debug_info_name) == 0
-			   || CONST_STRNEQ (sect->name, GNU_LINKONCE_INFO));
+			   || startswith (sect->name, GNU_LINKONCE_INFO));
 
 	  if (!((sect->flags & SEC_ALLOC) != 0 && abfd == orig_bfd)
 	      && !is_debug_info)
@@ -4419,7 +4419,7 @@ place_sections (bfd *orig_bfd, struct dwarf2_debug *stash)
 		continue;
 
 	      is_debug_info = (strcmp (sect->name, debug_info_name) == 0
-			       || CONST_STRNEQ (sect->name, GNU_LINKONCE_INFO));
+			       || startswith (sect->name, GNU_LINKONCE_INFO));
 
 	      if (!((sect->flags & SEC_ALLOC) != 0 && abfd == orig_bfd)
 		  && !is_debug_info)
diff --git a/bfd/ecoff.c b/bfd/ecoff.c
index 98a00e5da63..dc12b180adb 100644
--- a/bfd/ecoff.c
+++ b/bfd/ecoff.c
@@ -2866,7 +2866,7 @@ _bfd_ecoff_slurp_armap (bfd *abfd)
      bfd_slurp_armap, but that seems inappropriate since no other
      target uses this format.  Instead, we check directly for a COFF
      armap.  */
-  if (CONST_STRNEQ (nextname, "/               "))
+  if (startswith (nextname, "/               "))
     return bfd_slurp_armap (abfd);
 
   /* See if the first element is an armap.  */
diff --git a/bfd/elf-m10300.c b/bfd/elf-m10300.c
index 32aa0be568d..752c1210c27 100644
--- a/bfd/elf-m10300.c
+++ b/bfd/elf-m10300.c
@@ -5070,7 +5070,7 @@ _bfd_mn10300_elf_size_dynamic_sections (bfd * output_bfd,
 	  /* Remember whether there is a PLT.  */
 	  ;
 	}
-      else if (CONST_STRNEQ (name, ".rela"))
+      else if (startswith (name, ".rela"))
 	{
 	  if (s->size != 0)
 	    {
@@ -5084,7 +5084,7 @@ _bfd_mn10300_elf_size_dynamic_sections (bfd * output_bfd,
 	      s->reloc_count = 0;
 	    }
 	}
-      else if (! CONST_STRNEQ (name, ".got")
+      else if (! startswith (name, ".got")
 	       && ! streq (name, ".dynbss"))
 	/* It's not one of our sections, so don't allocate space.  */
 	continue;
diff --git a/bfd/elf.c b/bfd/elf.c
index 35c31cf40bf..ef82b98e9fe 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -1112,7 +1112,7 @@ _bfd_elf_make_section_from_shdr (bfd *abfd,
      The symbols will be defined as weak, so that multiple definitions
      are permitted.  The GNU linker extension is to actually discard
      all but one of the sections.  */
-  if (CONST_STRNEQ (name, ".gnu.linkonce")
+  if (startswith (name, ".gnu.linkonce")
       && elf_next_in_group (newsect) == NULL)
     flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
 
@@ -3941,7 +3941,7 @@ assign_section_numbers (bfd *abfd, struct bfd_link_info *link_info)
 	     string section.  We look for a section with the same name
 	     but without the trailing ``str'', and set its sh_link
 	     field to point to this section.  */
-	  if (CONST_STRNEQ (sec->name, ".stab")
+	  if (startswith (sec->name, ".stab")
 	      && strcmp (sec->name + strlen (sec->name) - 3, "str") == 0)
 	    {
 	      size_t len;
@@ -10189,7 +10189,7 @@ elfcore_grok_win32pstatus (bfd *abfd, Elf_Internal_Note *note)
   if (note->descsz < 4)
     return TRUE;
 
-  if (! CONST_STRNEQ (note->namedata, "win32"))
+  if (! startswith (note->namedata, "win32"))
     return TRUE;
 
   type = bfd_get_32 (abfd, note->descdata);
diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
index d3b412c710a..bf0be0c881e 100644
--- a/bfd/elf32-arm.c
+++ b/bfd/elf32-arm.c
@@ -5961,7 +5961,7 @@ cmse_scan (bfd *input_bfd, struct elf32_arm_link_hash_table *htab,
 	  sym_name = bfd_elf_string_from_elf_section (input_bfd,
 						      symtab_hdr->sh_link,
 						      cmse_sym->st_name);
-	  if (!sym_name || !CONST_STRNEQ (sym_name, CMSE_PREFIX))
+	  if (!sym_name || !startswith (sym_name, CMSE_PREFIX))
 	    continue;
 
 	  /* Special symbol with local binding.  */
@@ -5971,7 +5971,7 @@ cmse_scan (bfd *input_bfd, struct elf32_arm_link_hash_table *htab,
 	{
 	  cmse_hash = elf32_arm_hash_entry (sym_hashes[i - ext_start]);
 	  sym_name = (char *) cmse_hash->root.root.root.string;
-	  if (!CONST_STRNEQ (sym_name, CMSE_PREFIX))
+	  if (!startswith (sym_name, CMSE_PREFIX))
 	    continue;
 
 	  /* Special symbol has incorrect binding or type.  */
@@ -15847,7 +15847,7 @@ elf32_arm_gc_mark_extra_sections (struct bfd_link_info *info,
 
 		  /* Assume it is a special symbol.  If not, cmse_scan will
 		     warn about it and user can do something about it.  */
-		  if (CONST_STRNEQ (cmse_hash->root.root.root.string,
+		  if (startswith (cmse_hash->root.root.root.string,
 				    CMSE_PREFIX))
 		    {
 		      cmse_sec = cmse_hash->root.root.u.def.section;
@@ -16902,7 +16902,7 @@ elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
 	  /* Remember whether there is a PLT.  */
 	  ;
 	}
-      else if (CONST_STRNEQ (name, ".rel"))
+      else if (startswith (name, ".rel"))
 	{
 	  if (s->size != 0)
 	    {
@@ -17564,8 +17564,8 @@ elf32_arm_final_write_processing (bfd *abfd)
 static bfd_boolean
 is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name)
 {
-  return (CONST_STRNEQ (name, ELF_STRING_ARM_unwind)
-	  || CONST_STRNEQ (name, ELF_STRING_ARM_unwind_once));
+  return (startswith (name, ELF_STRING_ARM_unwind)
+	  || startswith (name, ELF_STRING_ARM_unwind_once));
 }
 
 
diff --git a/bfd/elf32-bfin.c b/bfd/elf32-bfin.c
index 401683c5367..a0cb1661b9a 100644
--- a/bfd/elf32-bfin.c
+++ b/bfd/elf32-bfin.c
@@ -5186,7 +5186,7 @@ bfin_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
 
       strip = FALSE;
 
-       if (CONST_STRNEQ (name, ".rela"))
+       if (startswith (name, ".rela"))
 	{
 	  if (s->size == 0)
 	    {
@@ -5210,7 +5210,7 @@ bfin_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
 	      s->reloc_count = 0;
 	    }
 	}
-      else if (! CONST_STRNEQ (name, ".got"))
+      else if (! startswith (name, ".got"))
 	{
 	  /* It's not one of our sections, so don't allocate space.  */
 	  continue;
diff --git a/bfd/elf32-cr16.c b/bfd/elf32-cr16.c
index 9c101cbf9f7..4c327d511ed 100644
--- a/bfd/elf32-cr16.c
+++ b/bfd/elf32-cr16.c
@@ -2439,7 +2439,7 @@ _bfd_cr16_elf_size_dynamic_sections (bfd * output_bfd,
 	  /* Remember whether there is a PLT.  */
 	  ;
 	}
-      else if (CONST_STRNEQ (name, ".rela"))
+      else if (startswith (name, ".rela"))
 	{
 	  if (s->size != 0)
 	    {
@@ -2453,7 +2453,7 @@ _bfd_cr16_elf_size_dynamic_sections (bfd * output_bfd,
 	      s->reloc_count = 0;
 	    }
 	}
-      else if (! CONST_STRNEQ (name, ".got")
+      else if (! startswith (name, ".got")
 	       && strcmp (name, ".dynbss") != 0)
 	/* It's not one of our sections, so don't allocate space.  */
 	continue;
diff --git a/bfd/elf32-cris.c b/bfd/elf32-cris.c
index 0228920e1fd..080f95849b0 100644
--- a/bfd/elf32-cris.c
+++ b/bfd/elf32-cris.c
@@ -3593,7 +3593,7 @@ elf_cris_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 	  s->size += htab->dtpmod_refcount != 0
 	    ? 8 : 0;
 	}
-      else if (CONST_STRNEQ (name, ".rela"))
+      else if (startswith (name, ".rela"))
 	{
 	  if (strcmp (name, ".rela.got") == 0
 	      && htab->dtpmod_refcount != 0
@@ -3612,7 +3612,7 @@ elf_cris_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 	      s->reloc_count = 0;
 	    }
 	}
-      else if (! CONST_STRNEQ (name, ".got")
+      else if (! startswith (name, ".got")
 	       && strcmp (name, ".dynbss") != 0
 	       && s != htab->root.sdynrelro)
 	{
diff --git a/bfd/elf32-csky.c b/bfd/elf32-csky.c
index 0b776e5fd8f..4e6db39cf40 100644
--- a/bfd/elf32-csky.c
+++ b/bfd/elf32-csky.c
@@ -2045,7 +2045,7 @@ csky_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 	  if (htab->elf.hplt != NULL)
 	    strip_section = FALSE;
 	}
-      else if (CONST_STRNEQ (bfd_section_name (s), ".rel") )
+      else if (startswith (bfd_section_name (s), ".rel") )
 	{
 	  if (s->size != 0 )
 	    relocs = TRUE;
diff --git a/bfd/elf32-hppa.c b/bfd/elf32-hppa.c
index e47af49b230..ec354c88ff2 100644
--- a/bfd/elf32-hppa.c
+++ b/bfd/elf32-hppa.c
@@ -2232,7 +2232,7 @@ elf32_hppa_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 	       || sec == htab->etab.sdynbss
 	       || sec == htab->etab.sdynrelro)
 	;
-      else if (CONST_STRNEQ (bfd_section_name (sec), ".rela"))
+      else if (startswith (bfd_section_name (sec), ".rela"))
 	{
 	  if (sec->size != 0)
 	    {
diff --git a/bfd/elf32-iq2000.c b/bfd/elf32-iq2000.c
index e17b0c646ae..b29be24878e 100644
--- a/bfd/elf32-iq2000.c
+++ b/bfd/elf32-iq2000.c
@@ -507,9 +507,9 @@ iq2000_elf_check_relocs (bfd *abfd,
 
 	case R_IQ2000_32:
 	  /* For debug section, change to special harvard-aware relocations.  */
-	  if (CONST_STRNEQ (sec->name, ".debug")
-	      || CONST_STRNEQ (sec->name, ".stab")
-	      || CONST_STRNEQ (sec->name, ".eh_frame"))
+	  if (startswith (sec->name, ".debug")
+	      || startswith (sec->name, ".stab")
+	      || startswith (sec->name, ".eh_frame"))
 	    {
 	      ((Elf_Internal_Rela *) rel)->r_info
 		= ELF32_R_INFO (ELF32_R_SYM (rel->r_info), R_IQ2000_32_DEBUG);
diff --git a/bfd/elf32-lm32.c b/bfd/elf32-lm32.c
index fa0b2fcfff3..9d72150ccc1 100644
--- a/bfd/elf32-lm32.c
+++ b/bfd/elf32-lm32.c
@@ -2020,7 +2020,7 @@ lm32_elf_size_dynamic_sections (bfd *output_bfd,
 	  /* Strip this section if we don't need it; see the
 	     comment below.  */
 	}
-      else if (CONST_STRNEQ (bfd_section_name (s), ".rela"))
+      else if (startswith (bfd_section_name (s), ".rela"))
 	{
 	  if (s->size != 0 && s != htab->root.srelplt)
 	    relocs = TRUE;
diff --git a/bfd/elf32-m32r.c b/bfd/elf32-m32r.c
index e73bbdeeff2..95e0c17bc5c 100644
--- a/bfd/elf32-m32r.c
+++ b/bfd/elf32-m32r.c
@@ -2073,7 +2073,7 @@ m32r_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 	  /* Strip this section if we don't need it; see the
 	     comment below.  */
 	}
-      else if (CONST_STRNEQ (bfd_section_name (s), ".rela"))
+      else if (startswith (bfd_section_name (s), ".rela"))
 	{
 	  if (s->size != 0 && s != htab->srelplt)
 	    relocs = TRUE;
diff --git a/bfd/elf32-m68k.c b/bfd/elf32-m68k.c
index 16aa5918518..f2222d0ed68 100644
--- a/bfd/elf32-m68k.c
+++ b/bfd/elf32-m68k.c
@@ -3171,7 +3171,7 @@ elf_m68k_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 	  /* Remember whether there is a PLT.  */
 	  ;
 	}
-      else if (CONST_STRNEQ (name, ".rela"))
+      else if (startswith (name, ".rela"))
 	{
 	  if (s->size != 0)
 	    {
@@ -3182,7 +3182,7 @@ elf_m68k_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 	      s->reloc_count = 0;
 	    }
 	}
-      else if (! CONST_STRNEQ (name, ".got")
+      else if (! startswith (name, ".got")
 	       && strcmp (name, ".dynbss") != 0)
 	{
 	  /* It's not one of our sections, so don't allocate space.  */
diff --git a/bfd/elf32-metag.c b/bfd/elf32-metag.c
index 65453639768..ac6d37977cc 100644
--- a/bfd/elf32-metag.c
+++ b/bfd/elf32-metag.c
@@ -2847,7 +2847,7 @@ elf_metag_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 	  /* Strip this section if we don't need it; see the
 	     comment below.  */
 	}
-      else if (CONST_STRNEQ (bfd_section_name (s), ".rela"))
+      else if (startswith (bfd_section_name (s), ".rela"))
 	{
 	  if (s->size != 0 && s != htab->etab.srelplt)
 	    relocs = TRUE;
diff --git a/bfd/elf32-msp430.c b/bfd/elf32-msp430.c
index 1aafa844b55..eebe74a6791 100644
--- a/bfd/elf32-msp430.c
+++ b/bfd/elf32-msp430.c
@@ -1855,8 +1855,8 @@ msp430_elf_relax_delete_bytes (bfd * abfd, asection * sec, bfd_vma addr,
 		 the start of the next section.  */
 	      || (isym->st_value == toaddr
 		  && name != NULL
-		  && (CONST_STRNEQ (name, ".Letext")
-		      || CONST_STRNEQ (name, ".LFE")))))
+		  && (startswith (name, ".Letext")
+		      || startswith (name, ".LFE")))))
 	{
 	  if (debug_relocs)
 	    printf ("      adjusting value of local symbol %s from 0x%lx ",
diff --git a/bfd/elf32-nios2.c b/bfd/elf32-nios2.c
index c1727ccac0c..c925bc975e7 100644
--- a/bfd/elf32-nios2.c
+++ b/bfd/elf32-nios2.c
@@ -5825,7 +5825,7 @@ nios2_elf32_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 	 of the dynobj section names depend upon the input files.  */
       name = bfd_section_name (s);
 
-      if (CONST_STRNEQ (name, ".rela"))
+      if (startswith (name, ".rela"))
 	{
 	  if (s->size != 0)
 	    {
diff --git a/bfd/elf32-or1k.c b/bfd/elf32-or1k.c
index 65938e51378..82a5b4ac8e2 100644
--- a/bfd/elf32-or1k.c
+++ b/bfd/elf32-or1k.c
@@ -3034,7 +3034,7 @@ or1k_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 	  /* Strip this section if we don't need it; see the
 	     comment below.  */
 	}
-      else if (CONST_STRNEQ (bfd_section_name (s), ".rela"))
+      else if (startswith (bfd_section_name (s), ".rela"))
 	{
 	  if (s->size != 0 && s != htab->root.srelplt)
 	    relocs = TRUE;
diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c
index 65f59a39d25..fe8b6fdb7d1 100644
--- a/bfd/elf32-ppc.c
+++ b/bfd/elf32-ppc.c
@@ -5812,7 +5812,7 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd,
 	{
 	  strip_section = (s->flags & SEC_KEEP) == 0;
 	}
-      else if (CONST_STRNEQ (bfd_section_name (s), ".rela"))
+      else if (startswith (bfd_section_name (s), ".rela"))
 	{
 	  if (s->size != 0)
 	    {
diff --git a/bfd/elf32-s390.c b/bfd/elf32-s390.c
index 0cc1edb7929..55e61031a04 100644
--- a/bfd/elf32-s390.c
+++ b/bfd/elf32-s390.c
@@ -1919,7 +1919,7 @@ elf_s390_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 	  /* Strip this section if we don't need it; see the
 	     comment below.  */
 	}
-      else if (CONST_STRNEQ (bfd_section_name (s), ".rela"))
+      else if (startswith (bfd_section_name (s), ".rela"))
 	{
 	  if (s->size != 0)
 	    relocs = TRUE;
diff --git a/bfd/elf32-score.c b/bfd/elf32-score.c
index 50c7405c32a..e34169e989f 100644
--- a/bfd/elf32-score.c
+++ b/bfd/elf32-score.c
@@ -3282,7 +3282,7 @@ s3_bfd_score_elf_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *i
 	 of the dynobj section names depend upon the input files.  */
       name = bfd_section_name (s);
 
-      if (CONST_STRNEQ (name, ".rel"))
+      if (startswith (name, ".rel"))
 	{
 	  if (s->size == 0)
 	    {
@@ -3320,7 +3320,7 @@ s3_bfd_score_elf_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *i
 		s->reloc_count = 0;
 	    }
 	}
-      else if (CONST_STRNEQ (name, ".got"))
+      else if (startswith (name, ".got"))
 	{
 	  /* s3_bfd_score_elf_always_size_sections() has already done
 	     most of the work, but some symbols may have been mapped
@@ -3333,7 +3333,7 @@ s3_bfd_score_elf_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *i
 	     of .text section. So put a dummy. XXX  */
 	  s->size += SCORE_FUNCTION_STUB_SIZE;
 	}
-      else if (! CONST_STRNEQ (name, ".init"))
+      else if (! startswith (name, ".init"))
 	{
 	  /* It's not one of our sections, so don't allocate space.  */
 	  continue;
diff --git a/bfd/elf32-score7.c b/bfd/elf32-score7.c
index 2f63ab8cd5b..9e1b7dae0cb 100644
--- a/bfd/elf32-score7.c
+++ b/bfd/elf32-score7.c
@@ -3090,7 +3090,7 @@ s7_bfd_score_elf_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *i
 	 of the dynobj section names depend upon the input files.  */
       name = bfd_section_name (s);
 
-      if (CONST_STRNEQ (name, ".rel"))
+      if (startswith (name, ".rel"))
 	{
 	  if (s->size == 0)
 	    {
@@ -3128,7 +3128,7 @@ s7_bfd_score_elf_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *i
 		s->reloc_count = 0;
 	    }
 	}
-      else if (CONST_STRNEQ (name, ".got"))
+      else if (startswith (name, ".got"))
 	{
 	  /* s7_bfd_score_elf_always_size_sections() has already done
 	     most of the work, but some symbols may have been mapped
@@ -3141,7 +3141,7 @@ s7_bfd_score_elf_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *i
 	     of .text section. So put a dummy. XXX  */
 	  s->size += SCORE_FUNCTION_STUB_SIZE;
 	}
-      else if (! CONST_STRNEQ (name, ".init"))
+      else if (! startswith (name, ".init"))
 	{
 	  /* It's not one of our sections, so don't allocate space.  */
 	  continue;
diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c
index 19375b06a43..10145505c3e 100644
--- a/bfd/elf32-sh.c
+++ b/bfd/elf32-sh.c
@@ -3152,7 +3152,7 @@ sh_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 	  /* Strip this section if we don't need it; see the
 	     comment below.  */
 	}
-      else if (CONST_STRNEQ (bfd_section_name (s), ".rela"))
+      else if (startswith (bfd_section_name (s), ".rela"))
 	{
 	  if (s->size != 0 && s != htab->root.srelplt && s != htab->srelplt2)
 	    relocs = TRUE;
diff --git a/bfd/elf32-tic6x.c b/bfd/elf32-tic6x.c
index 3d0640e12d1..53ec572fab9 100644
--- a/bfd/elf32-tic6x.c
+++ b/bfd/elf32-tic6x.c
@@ -1938,8 +1938,8 @@ elf32_tic6x_gc_mark_extra_sections (struct bfd_link_info *info,
 static bfd_boolean
 is_tic6x_elf_unwind_section_name (const char *name)
 {
-  return (CONST_STRNEQ (name, ELF_STRING_C6000_unwind)
-	  || CONST_STRNEQ (name, ELF_STRING_C6000_unwind_once));
+  return (startswith (name, ELF_STRING_C6000_unwind)
+	  || startswith (name, ELF_STRING_C6000_unwind_once));
 }
 
 
@@ -3284,7 +3284,7 @@ elf32_tic6x_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
 	  if (s == htab->elf.splt && s->size > 0)
 	    s->size = (s->size + 31) & ~(bfd_vma)31;
 	}
-      else if (CONST_STRNEQ (bfd_section_name (s), ".rela"))
+      else if (startswith (bfd_section_name (s), ".rela"))
 	{
 	  if (s->size != 0
 	      && s != htab->elf.srelplt)
diff --git a/bfd/elf32-vax.c b/bfd/elf32-vax.c
index c7fe7f2f600..ff83062a37a 100644
--- a/bfd/elf32-vax.c
+++ b/bfd/elf32-vax.c
@@ -1082,7 +1082,7 @@ elf_vax_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
 	  /* Remember whether there is a PLT.  */
 	  ;
 	}
-      else if (CONST_STRNEQ (name, ".rela"))
+      else if (startswith (name, ".rela"))
 	{
 	  if (s->size != 0)
 	    {
@@ -1094,7 +1094,7 @@ elf_vax_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
 	      s->reloc_count = 0;
 	    }
 	}
-      else if (! CONST_STRNEQ (name, ".got")
+      else if (! startswith (name, ".got")
 	       && strcmp (name, ".dynbss") != 0)
 	{
 	  /* It's not one of our sections, so don't allocate space.  */
diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c
index 6338bc98e82..abc244c04cb 100644
--- a/bfd/elf32-xtensa.c
+++ b/bfd/elf32-xtensa.c
@@ -1691,7 +1691,7 @@ elf_xtensa_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 	 of the dynobj section names depend upon the input files.  */
       name = bfd_section_name (s);
 
-      if (CONST_STRNEQ (name, ".rela"))
+      if (startswith (name, ".rela"))
 	{
 	  if (s->size != 0)
 	    {
@@ -1705,8 +1705,8 @@ elf_xtensa_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 	      s->reloc_count = 0;
 	    }
 	}
-      else if (! CONST_STRNEQ (name, ".plt.")
-	       && ! CONST_STRNEQ (name, ".got.plt.")
+      else if (! startswith (name, ".plt.")
+	       && ! startswith (name, ".got.plt.")
 	       && strcmp (name, ".got") != 0
 	       && strcmp (name, ".plt") != 0
 	       && strcmp (name, ".got.plt") != 0
@@ -11144,8 +11144,8 @@ xtensa_is_property_section (asection *sec)
 static bfd_boolean
 xtensa_is_insntable_section (asection *sec)
 {
-  if (CONST_STRNEQ (sec->name, XTENSA_INSN_SEC_NAME)
-      || CONST_STRNEQ (sec->name, ".gnu.linkonce.x."))
+  if (startswith (sec->name, XTENSA_INSN_SEC_NAME)
+      || startswith (sec->name, ".gnu.linkonce.x."))
     return TRUE;
 
   return FALSE;
@@ -11155,8 +11155,8 @@ xtensa_is_insntable_section (asection *sec)
 static bfd_boolean
 xtensa_is_littable_section (asection *sec)
 {
-  if (CONST_STRNEQ (sec->name, XTENSA_LIT_SEC_NAME)
-      || CONST_STRNEQ (sec->name, ".gnu.linkonce.p."))
+  if (startswith (sec->name, XTENSA_LIT_SEC_NAME)
+      || startswith (sec->name, ".gnu.linkonce.p."))
     return TRUE;
 
   return FALSE;
@@ -11166,8 +11166,8 @@ xtensa_is_littable_section (asection *sec)
 static bfd_boolean
 xtensa_is_proptable_section (asection *sec)
 {
-  if (CONST_STRNEQ (sec->name, XTENSA_PROP_SEC_NAME)
-      || CONST_STRNEQ (sec->name, ".gnu.linkonce.prop."))
+  if (startswith (sec->name, XTENSA_PROP_SEC_NAME)
+      || startswith (sec->name, ".gnu.linkonce.prop."))
     return TRUE;
 
   return FALSE;
@@ -11281,7 +11281,7 @@ xtensa_property_section_name (asection *sec, const char *base_name,
       suffix = sec->name + linkonce_len;
       /* For backward compatibility, replace "t." instead of inserting
 	 the new linkonce_kind (but not for "prop" sections).  */
-      if (CONST_STRNEQ (suffix, "t.") && linkonce_kind[1] == '.')
+      if (startswith (suffix, "t.") && linkonce_kind[1] == '.')
 	suffix += 2;
       strcat (prop_sec_name + linkonce_len, suffix);
     }
@@ -11396,7 +11396,7 @@ xtensa_callback_required_dependence (bfd *abfd,
   /* ".plt*" sections have no explicit relocations but they contain L32R
      instructions that reference the corresponding ".got.plt*" sections.  */
   if ((sec->flags & SEC_LINKER_CREATED) != 0
-      && CONST_STRNEQ (sec->name, ".plt"))
+      && startswith (sec->name, ".plt"))
     {
       asection *sgotplt;
 
diff --git a/bfd/elf64-alpha.c b/bfd/elf64-alpha.c
index 3d214374753..6fffc438fc4 100644
--- a/bfd/elf64-alpha.c
+++ b/bfd/elf64-alpha.c
@@ -2859,7 +2859,7 @@ elf64_alpha_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 	 of the dynobj section names depend upon the input files.  */
       name = bfd_section_name (s);
 
-      if (CONST_STRNEQ (name, ".rela"))
+      if (startswith (name, ".rela"))
 	{
 	  if (s->size != 0)
 	    {
@@ -2873,7 +2873,7 @@ elf64_alpha_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 	      s->reloc_count = 0;
 	    }
 	}
-      else if (! CONST_STRNEQ (name, ".got")
+      else if (! startswith (name, ".got")
 	       && strcmp (name, ".plt") != 0
 	       && strcmp (name, ".dynbss") != 0)
 	{
@@ -2890,7 +2890,7 @@ elf64_alpha_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 	     linker does that before adjust_dynamic_symbol is called, and
 	     it is that function which decides whether anything needs to
 	     go into these sections.  */
-	  if (!CONST_STRNEQ (name, ".got"))
+	  if (!startswith (name, ".got"))
 	    s->flags |= SEC_EXCLUDE;
 	}
       else if ((s->flags & SEC_HAS_CONTENTS) != 0)
diff --git a/bfd/elf64-hppa.c b/bfd/elf64-hppa.c
index 50782fe2c4c..0ce85cced14 100644
--- a/bfd/elf64-hppa.c
+++ b/bfd/elf64-hppa.c
@@ -1754,13 +1754,13 @@ elf64_hppa_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
 	  ;
 	}
       else if (strcmp (name, ".opd") == 0
-	       || CONST_STRNEQ (name, ".dlt")
+	       || startswith (name, ".dlt")
 	       || strcmp (name, ".stub") == 0
 	       || strcmp (name, ".got") == 0)
 	{
 	  /* Strip this section if we don't need it; see the comment below.  */
 	}
-      else if (CONST_STRNEQ (name, ".rela"))
+      else if (startswith (name, ".rela"))
 	{
 	  if (sec->size != 0)
 	    {
diff --git a/bfd/elf64-ia64-vms.c b/bfd/elf64-ia64-vms.c
index b69c9cde7f1..317253fb9a6 100644
--- a/bfd/elf64-ia64-vms.c
+++ b/bfd/elf64-ia64-vms.c
@@ -809,9 +809,9 @@ elf64_ia64_relax_section (bfd *abfd, asection *sec,
 static inline bfd_boolean
 is_unwind_section_name (bfd *abfd ATTRIBUTE_UNUSED, const char *name)
 {
-  return ((CONST_STRNEQ (name, ELF_STRING_ia64_unwind)
-	   && ! CONST_STRNEQ (name, ELF_STRING_ia64_unwind_info))
-	  || CONST_STRNEQ (name, ELF_STRING_ia64_unwind_once));
+  return ((startswith (name, ELF_STRING_ia64_unwind)
+	   && ! startswith (name, ELF_STRING_ia64_unwind_info))
+	  || startswith (name, ELF_STRING_ia64_unwind_once));
 }
 
 
@@ -1847,9 +1847,9 @@ get_reloc_section (bfd *abfd,
   if (srel_name == NULL)
     return NULL;
 
-  BFD_ASSERT ((CONST_STRNEQ (srel_name, ".rela")
+  BFD_ASSERT ((startswith (srel_name, ".rela")
 	       && strcmp (bfd_section_name (sec), srel_name+5) == 0)
-	      || (CONST_STRNEQ (srel_name, ".rel")
+	      || (startswith (srel_name, ".rel")
 		  && strcmp (bfd_section_name (sec), srel_name+4) == 0));
 
   dynobj = ia64_info->root.dynobj;
@@ -2745,7 +2745,7 @@ elf64_ia64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 
 	  if (strcmp (name, ".got.plt") == 0)
 	    strip = FALSE;
-	  else if (CONST_STRNEQ (name, ".rel"))
+	  else if (startswith (name, ".rel"))
 	    {
 	      if (!strip)
 		{
@@ -4387,7 +4387,7 @@ elf64_ia64_object_p (bfd *abfd)
       if (elf_sec_group (sec) == NULL
 	  && ((sec->flags & (SEC_LINK_ONCE | SEC_CODE | SEC_GROUP))
 	      == (SEC_LINK_ONCE | SEC_CODE))
-	  && CONST_STRNEQ (sec->name, ".gnu.linkonce.t."))
+	  && startswith (sec->name, ".gnu.linkonce.t."))
 	{
 	  name = sec->name + 16;
 
diff --git a/bfd/elf64-mmix.c b/bfd/elf64-mmix.c
index f87b26e4929..62365e1e4f7 100644
--- a/bfd/elf64-mmix.c
+++ b/bfd/elf64-mmix.c
@@ -2139,7 +2139,7 @@ mmix_elf_add_symbol_hook (bfd *abfd,
       (*secp)->flags |= SEC_LINKER_CREATED;
     }
   else if ((*namep)[0] == '_' && (*namep)[1] == '_' && (*namep)[2] == '.'
-	   && CONST_STRNEQ (*namep, MMIX_LOC_SECTION_START_SYMBOL_PREFIX))
+	   && startswith (*namep, MMIX_LOC_SECTION_START_SYMBOL_PREFIX))
     {
       /* See if we have another one.  */
       struct bfd_link_hash_entry *h = bfd_link_hash_lookup (info->hash,
diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
index ab0e0d33aac..741f510a28d 100644
--- a/bfd/elf64-ppc.c
+++ b/bfd/elf64-ppc.c
@@ -10226,7 +10226,7 @@ ppc64_elf_size_dynamic_sections (bfd *output_bfd,
 	    /* Not sized yet.  */
 	    continue;
 	}
-      else if (CONST_STRNEQ (s->name, ".rela"))
+      else if (startswith (s->name, ".rela"))
 	{
 	  if (s->size != 0)
 	    {
diff --git a/bfd/elf64-s390.c b/bfd/elf64-s390.c
index 69a011f7c93..01dcefed48e 100644
--- a/bfd/elf64-s390.c
+++ b/bfd/elf64-s390.c
@@ -1873,7 +1873,7 @@ elf_s390_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 	  /* Strip this section if we don't need it; see the
 	     comment below.  */
 	}
-      else if (CONST_STRNEQ (bfd_section_name (s), ".rela"))
+      else if (startswith (bfd_section_name (s), ".rela"))
 	{
 	  if (s->size != 0 && s != htab->elf.srelplt)
 	    relocs = TRUE;
diff --git a/bfd/elflink.c b/bfd/elflink.c
index e1278a5d95e..82b5a8f2e98 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -4129,7 +4129,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
       const char *name;
 
       name = bfd_section_name (s);
-      if (CONST_STRNEQ (name, ".gnu.warning."))
+      if (startswith (name, ".gnu.warning."))
 	{
 	  char *msg;
 	  bfd_size_type sz;
@@ -5693,7 +5693,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
 	  asection *stab;
 
 	  for (stab = abfd->sections; stab; stab = stab->next)
-	    if (CONST_STRNEQ (stab->name, ".stab")
+	    if (startswith (stab->name, ".stab")
 		&& (!stab->name[5] ||
 		    (stab->name[5] == '.' && ISDIGIT (stab->name[6])))
 		&& (stab->flags & SEC_MERGE) == 0
@@ -13668,7 +13668,7 @@ _bfd_elf_gc_mark_extra_sections (struct bfd_link_info *info,
 
 	  if (!debug_frag_seen
 	      && (isec->flags & SEC_DEBUGGING)
-	      && CONST_STRNEQ (isec->name, ".debug_line."))
+	      && startswith (isec->name, ".debug_line."))
 	    debug_frag_seen = TRUE;
 	  else if (strcmp (bfd_section_name (isec),
 			   "__patchable_function_entries") == 0
@@ -13985,7 +13985,7 @@ bfd_elf_parse_eh_frame_entries (bfd *abfd ATTRIBUTE_UNUSED,
 
       for (sec = ibfd->sections; sec; sec = sec->next)
 	{
-	  if (CONST_STRNEQ (bfd_section_name (sec), ".eh_frame_entry")
+	  if (startswith (bfd_section_name (sec), ".eh_frame_entry")
 	      && init_reloc_cookie_rels (&cookie, info, ibfd, sec))
 	    {
 	      _bfd_elf_parse_eh_frame_entry (info, sec, &cookie);
@@ -14692,7 +14692,7 @@ _bfd_elf_section_already_linked (bfd *abfd,
   else
     {
       /* Otherwise we should have a .gnu.linkonce.<type>.<key> section.  */
-      if (CONST_STRNEQ (name, ".gnu.linkonce.")
+      if (startswith (name, ".gnu.linkonce.")
 	  && (key = strchr (name + sizeof (".gnu.linkonce.") - 1, '.')) != NULL)
 	key++;
       else
@@ -14791,10 +14791,10 @@ _bfd_elf_section_already_linked (bfd *abfd,
      `.gnu.linkonce.r.F' section.  The order of sections in a bfd does not
      matter as here were are looking only for cross-bfd sections.  */
 
-  if ((flags & SEC_GROUP) == 0 && CONST_STRNEQ (name, ".gnu.linkonce.r."))
+  if ((flags & SEC_GROUP) == 0 && startswith (name, ".gnu.linkonce.r."))
     for (l = already_linked_list->entry; l != NULL; l = l->next)
       if ((l->sec->flags & SEC_GROUP) == 0
-	  && CONST_STRNEQ (l->sec->name, ".gnu.linkonce.t."))
+	  && startswith (l->sec->name, ".gnu.linkonce.t."))
 	{
 	  if (abfd != l->sec->owner)
 	    sec->output_section = bfd_abs_section_ptr;
diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index 1ec405ef1e0..2fee93aa5f9 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -9047,7 +9047,7 @@ elfNN_aarch64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 	  /* Strip this section if we don't need it; see the
 	     comment below.  */
 	}
-      else if (CONST_STRNEQ (bfd_section_name (s), ".rela"))
+      else if (startswith (bfd_section_name (s), ".rela"))
 	{
 	  if (s->size != 0 && s != htab->root.srelplt)
 	    relocs = TRUE;
diff --git a/bfd/elfnn-ia64.c b/bfd/elfnn-ia64.c
index aaa69c4b2cd..281a8375d51 100644
--- a/bfd/elfnn-ia64.c
+++ b/bfd/elfnn-ia64.c
@@ -893,9 +893,9 @@ is_unwind_section_name (bfd *abfd, const char *name)
       && !strcmp (name, ELF_STRING_ia64_unwind_hdr))
     return FALSE;
 
-  return ((CONST_STRNEQ (name, ELF_STRING_ia64_unwind)
-	   && ! CONST_STRNEQ (name, ELF_STRING_ia64_unwind_info))
-	  || CONST_STRNEQ (name, ELF_STRING_ia64_unwind_once));
+  return ((startswith (name, ELF_STRING_ia64_unwind)
+	   && ! startswith (name, ELF_STRING_ia64_unwind_info))
+	  || startswith (name, ELF_STRING_ia64_unwind_once));
 }
 
 /* Handle an IA-64 specific section when reading an object file.  This
@@ -3161,7 +3161,7 @@ elfNN_ia64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 
 	  if (strcmp (name, ".got.plt") == 0)
 	    strip = FALSE;
-	  else if (CONST_STRNEQ (name, ".rel"))
+	  else if (startswith (name, ".rel"))
 	    {
 	      if (!strip)
 		{
@@ -4859,7 +4859,7 @@ elfNN_ia64_object_p (bfd *abfd)
       if (elf_sec_group (sec) == NULL
 	  && ((sec->flags & (SEC_LINK_ONCE | SEC_CODE | SEC_GROUP))
 	      == (SEC_LINK_ONCE | SEC_CODE))
-	  && CONST_STRNEQ (sec->name, ".gnu.linkonce.t."))
+	  && startswith (sec->name, ".gnu.linkonce.t."))
 	{
 	  name = sec->name + 16;
 
diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
index 86e15b61edf..41abf4954dc 100644
--- a/bfd/elfxx-mips.c
+++ b/bfd/elfxx-mips.c
@@ -1030,9 +1030,9 @@ static bfd *reldyn_sorting_bfd;
 #define CALL_STUB ".mips16.call."
 #define CALL_FP_STUB ".mips16.call.fp."
 
-#define FN_STUB_P(name) CONST_STRNEQ (name, FN_STUB)
-#define CALL_STUB_P(name) CONST_STRNEQ (name, CALL_STUB)
-#define CALL_FP_STUB_P(name) CONST_STRNEQ (name, CALL_FP_STUB)
+#define FN_STUB_P(name) startswith (name, FN_STUB)
+#define CALL_STUB_P(name) startswith (name, CALL_STUB)
+#define CALL_FP_STUB_P(name) startswith (name, CALL_FP_STUB)
 \f
 /* The format of the first PLT entry in an O32 executable.  */
 static const bfd_vma mips_o32_exec_plt0_entry[] =
@@ -7411,7 +7411,7 @@ _bfd_mips_elf_section_from_shdr (bfd *abfd,
 	return FALSE;
       break;
     case SHT_MIPS_GPTAB:
-      if (! CONST_STRNEQ (name, ".gptab."))
+      if (! startswith (name, ".gptab."))
 	return FALSE;
       break;
     case SHT_MIPS_UCODE:
@@ -7434,7 +7434,7 @@ _bfd_mips_elf_section_from_shdr (bfd *abfd,
 	return FALSE;
       break;
     case SHT_MIPS_CONTENT:
-      if (! CONST_STRNEQ (name, ".MIPS.content"))
+      if (! startswith (name, ".MIPS.content"))
 	return FALSE;
       break;
     case SHT_MIPS_OPTIONS:
@@ -7447,8 +7447,8 @@ _bfd_mips_elf_section_from_shdr (bfd *abfd,
       flags = (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_SIZE);
       break;
     case SHT_MIPS_DWARF:
-      if (! CONST_STRNEQ (name, ".debug_")
-	  && ! CONST_STRNEQ (name, ".zdebug_"))
+      if (! startswith (name, ".debug_")
+	  && ! startswith (name, ".zdebug_"))
 	return FALSE;
       break;
     case SHT_MIPS_SYMBOL_LIB:
@@ -7456,8 +7456,8 @@ _bfd_mips_elf_section_from_shdr (bfd *abfd,
 	return FALSE;
       break;
     case SHT_MIPS_EVENTS:
-      if (! CONST_STRNEQ (name, ".MIPS.events")
-	  && ! CONST_STRNEQ (name, ".MIPS.post_rel"))
+      if (! startswith (name, ".MIPS.events")
+	  && ! startswith (name, ".MIPS.post_rel"))
 	return FALSE;
       break;
     case SHT_MIPS_XHASH:
@@ -7594,7 +7594,7 @@ _bfd_mips_elf_fake_sections (bfd *abfd, Elf_Internal_Shdr *hdr, asection *sec)
     }
   else if (strcmp (name, ".conflict") == 0)
     hdr->sh_type = SHT_MIPS_CONFLICT;
-  else if (CONST_STRNEQ (name, ".gptab."))
+  else if (startswith (name, ".gptab."))
     {
       hdr->sh_type = SHT_MIPS_GPTAB;
       hdr->sh_entsize = sizeof (Elf32_External_gptab);
@@ -7651,7 +7651,7 @@ _bfd_mips_elf_fake_sections (bfd *abfd, Elf_Internal_Shdr *hdr, asection *sec)
       hdr->sh_type = SHT_MIPS_IFACE;
       hdr->sh_flags |= SHF_MIPS_NOSTRIP;
     }
-  else if (CONST_STRNEQ (name, ".MIPS.content"))
+  else if (startswith (name, ".MIPS.content"))
     {
       hdr->sh_type = SHT_MIPS_CONTENT;
       hdr->sh_flags |= SHF_MIPS_NOSTRIP;
@@ -7663,20 +7663,20 @@ _bfd_mips_elf_fake_sections (bfd *abfd, Elf_Internal_Shdr *hdr, asection *sec)
       hdr->sh_entsize = 1;
       hdr->sh_flags |= SHF_MIPS_NOSTRIP;
     }
-  else if (CONST_STRNEQ (name, ".MIPS.abiflags"))
+  else if (startswith (name, ".MIPS.abiflags"))
     {
       hdr->sh_type = SHT_MIPS_ABIFLAGS;
       hdr->sh_entsize = sizeof (Elf_External_ABIFlags_v0);
     }
-  else if (CONST_STRNEQ (name, ".debug_")
-	   || CONST_STRNEQ (name, ".zdebug_"))
+  else if (startswith (name, ".debug_")
+	   || startswith (name, ".zdebug_"))
     {
       hdr->sh_type = SHT_MIPS_DWARF;
 
       /* Irix facilities such as libexc expect a single .debug_frame
 	 per executable, the system ones have NOSTRIP set and the linker
 	 doesn't merge sections with different flags so ...  */
-      if (SGI_COMPAT (abfd) && CONST_STRNEQ (name, ".debug_frame"))
+      if (SGI_COMPAT (abfd) && startswith (name, ".debug_frame"))
 	hdr->sh_flags |= SHF_MIPS_NOSTRIP;
     }
   else if (strcmp (name, ".MIPS.symlib") == 0)
@@ -7685,8 +7685,8 @@ _bfd_mips_elf_fake_sections (bfd *abfd, Elf_Internal_Shdr *hdr, asection *sec)
       /* The sh_link and sh_info fields are set in
 	 final_write_processing.  */
     }
-  else if (CONST_STRNEQ (name, ".MIPS.events")
-	   || CONST_STRNEQ (name, ".MIPS.post_rel"))
+  else if (startswith (name, ".MIPS.events")
+	   || startswith (name, ".MIPS.post_rel"))
     {
       hdr->sh_type = SHT_MIPS_EVENTS;
       hdr->sh_flags |= SHF_MIPS_NOSTRIP;
@@ -10007,7 +10007,7 @@ _bfd_mips_elf_size_dynamic_sections (bfd *output_bfd,
       if ((s->flags & SEC_LINKER_CREATED) == 0)
 	continue;
 
-      if (CONST_STRNEQ (name, ".rel"))
+      if (startswith (name, ".rel"))
 	{
 	  if (s->size != 0)
 	    {
@@ -10044,14 +10044,14 @@ _bfd_mips_elf_size_dynamic_sections (bfd *output_bfd,
 	}
       else if (bfd_link_executable (info)
 	       && ! mips_elf_hash_table (info)->use_rld_obj_head
-	       && CONST_STRNEQ (name, ".rld_map"))
+	       && startswith (name, ".rld_map"))
 	{
 	  /* We add a room for __rld_map.  It will be filled in by the
 	     rtld to contain a pointer to the _r_debug structure.  */
 	  s->size += MIPS_ELF_RLD_MAP_SIZE (output_bfd);
 	}
       else if (SGI_COMPAT (output_bfd)
-	       && CONST_STRNEQ (name, ".compact_rel"))
+	       && startswith (name, ".compact_rel"))
 	s->size += mips_elf_hash_table (info)->compact_rel_size;
       else if (s == htab->root.splt)
 	{
@@ -10063,7 +10063,7 @@ _bfd_mips_elf_size_dynamic_sections (bfd *output_bfd,
 	      && s->size > 0)
 	    s->size += 4;
 	}
-      else if (! CONST_STRNEQ (name, ".init")
+      else if (! startswith (name, ".init")
 	       && s != htab->root.sgot
 	       && s != htab->root.sgotplt
 	       && s != htab->sstubs
@@ -12422,7 +12422,7 @@ _bfd_mips_final_write_processing (bfd *abfd)
 	  BFD_ASSERT ((*hdrpp)->bfd_section != NULL);
 	  name = bfd_section_name ((*hdrpp)->bfd_section);
 	  BFD_ASSERT (name != NULL
-		      && CONST_STRNEQ (name, ".gptab."));
+		      && startswith (name, ".gptab."));
 	  sec = bfd_get_section_by_name (abfd, name + sizeof ".gptab" - 1);
 	  BFD_ASSERT (sec != NULL);
 	  (*hdrpp)->sh_info = elf_section_data (sec)->this_idx;
@@ -12432,7 +12432,7 @@ _bfd_mips_final_write_processing (bfd *abfd)
 	  BFD_ASSERT ((*hdrpp)->bfd_section != NULL);
 	  name = bfd_section_name ((*hdrpp)->bfd_section);
 	  BFD_ASSERT (name != NULL
-		      && CONST_STRNEQ (name, ".MIPS.content"));
+		      && startswith (name, ".MIPS.content"));
 	  sec = bfd_get_section_by_name (abfd,
 					 name + sizeof ".MIPS.content" - 1);
 	  BFD_ASSERT (sec != NULL);
@@ -12452,12 +12452,12 @@ _bfd_mips_final_write_processing (bfd *abfd)
 	  BFD_ASSERT ((*hdrpp)->bfd_section != NULL);
 	  name = bfd_section_name ((*hdrpp)->bfd_section);
 	  BFD_ASSERT (name != NULL);
-	  if (CONST_STRNEQ (name, ".MIPS.events"))
+	  if (startswith (name, ".MIPS.events"))
 	    sec = bfd_get_section_by_name (abfd,
 					   name + sizeof ".MIPS.events" - 1);
 	  else
 	    {
-	      BFD_ASSERT (CONST_STRNEQ (name, ".MIPS.post_rel"));
+	      BFD_ASSERT (startswith (name, ".MIPS.post_rel"));
 	      sec = bfd_get_section_by_name (abfd,
 					     (name
 					      + sizeof ".MIPS.post_rel" - 1));
@@ -15085,7 +15085,7 @@ _bfd_mips_elf_final_link (bfd *abfd, struct bfd_link_info *info)
 	  mdebug_sec = o;
 	}
 
-      if (CONST_STRNEQ (o->name, ".gptab."))
+      if (startswith (o->name, ".gptab."))
 	{
 	  const char *subname;
 	  unsigned int c;
diff --git a/bfd/elfxx-sparc.c b/bfd/elfxx-sparc.c
index bbf129c86e3..c498d1cb70b 100644
--- a/bfd/elfxx-sparc.c
+++ b/bfd/elfxx-sparc.c
@@ -2540,7 +2540,7 @@ _bfd_sparc_elf_size_dynamic_sections (bfd *output_bfd,
 	  /* Strip this section if we don't need it; see the
 	     comment below.  */
 	}
-      else if (CONST_STRNEQ (s->name, ".rela"))
+      else if (startswith (s->name, ".rela"))
 	{
 	  if (s->size != 0)
 	    {
diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index 93ad38c5eb0..6ff9fd56ee7 100644
--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -686,13 +686,13 @@ elf_x86_link_hash_table_free (bfd *obfd)
 static bfd_boolean
 elf_i386_is_reloc_section (const char *secname)
 {
-  return CONST_STRNEQ (secname, ".rel");
+  return startswith (secname, ".rel");
 }
 
 static bfd_boolean
 elf_x86_64_is_reloc_section (const char *secname)
 {
-  return CONST_STRNEQ (secname, ".rela");
+  return startswith (secname, ".rela");
 }
 
 /* Create an x86 ELF linker hash table.  */
diff --git a/bfd/hpux-core.c b/bfd/hpux-core.c
index 03d0de33822..d84df68c823 100644
--- a/bfd/hpux-core.c
+++ b/bfd/hpux-core.c
@@ -145,7 +145,7 @@ thread_section_p (bfd *abfd ATTRIBUTE_UNUSED,
 		  asection *sect,
 		  void *obj ATTRIBUTE_UNUSED)
 {
-  return CONST_STRNEQ (sect->name, ".reg/");
+  return startswith (sect->name, ".reg/");
 }
 
 /* this function builds a bfd target if the file is a corefile.
diff --git a/bfd/libcoff.h b/bfd/libcoff.h
index bb9066f5ec5..f2ce3c5e0ca 100644
--- a/bfd/libcoff.h
+++ b/bfd/libcoff.h
@@ -977,7 +977,7 @@ typedef struct
 /* Macro: Returns true if the bfd is a PE executable as opposed to a
    PE object file.  */
 #define bfd_pei_p(abfd) \
-  (CONST_STRNEQ ((abfd)->xvec->name, "pei-"))
+  (startswith ((abfd)->xvec->name, "pei-"))
 #ifdef __cplusplus
 }
 #endif
diff --git a/bfd/linker.c b/bfd/linker.c
index 7e0415cbed2..6f6e6842926 100644
--- a/bfd/linker.c
+++ b/bfd/linker.c
@@ -579,7 +579,7 @@ bfd_wrapped_link_hash_lookup (bfd *abfd,
 #define REAL "__real_"
 
       if (*l == '_'
-	  && CONST_STRNEQ (l, REAL)
+	  && startswith (l, REAL)
 	  && bfd_hash_lookup (info->wrap_hash, l + sizeof REAL - 1,
 			      FALSE, FALSE) != NULL)
 	{
@@ -623,7 +623,7 @@ unwrap_hash_lookup (struct bfd_link_info *info,
       || *l == info->wrap_char)
     ++l;
 
-  if (CONST_STRNEQ (l, WRAP))
+  if (startswith (l, WRAP))
     {
       l += sizeof WRAP - 1;
 
@@ -964,7 +964,7 @@ _bfd_generic_link_add_archive_symbols
 
 	  if (h == NULL
 	      && info->pei386_auto_import
-	      && CONST_STRNEQ (arsym->name, "__imp_"))
+	      && startswith (arsym->name, "__imp_"))
 	    h = bfd_link_hash_lookup (info->hash, arsym->name + 6,
 				      FALSE, FALSE, TRUE);
 	  if (h == NULL)
@@ -1536,7 +1536,7 @@ _bfd_generic_link_add_one_symbol (struct bfd_link_info *info,
 		s = name + 1;
 		while (*s == '_')
 		  ++s;
-		if (s[0] == 'G' && CONST_STRNEQ (s, CONS_PREFIX))
+		if (s[0] == 'G' && startswith (s, CONS_PREFIX))
 		  {
 		    char c;
 
diff --git a/bfd/mmo.c b/bfd/mmo.c
index 4ba62d0bc69..53883a31843 100644
--- a/bfd/mmo.c
+++ b/bfd/mmo.c
@@ -2505,7 +2505,7 @@ mmo_internal_write_section (bfd *abfd, asection *sec)
       bfd_set_error (bfd_error_bad_value);
       return FALSE;
     }
-  else if (CONST_STRNEQ (sec->name, MMIX_OTHER_SPEC_SECTION_PREFIX))
+  else if (startswith (sec->name, MMIX_OTHER_SPEC_SECTION_PREFIX))
     {
       int n = atoi (sec->name + strlen (MMIX_OTHER_SPEC_SECTION_PREFIX));
 
diff --git a/bfd/osf-core.c b/bfd/osf-core.c
index 17cc532396a..999796753f5 100644
--- a/bfd/osf-core.c
+++ b/bfd/osf-core.c
@@ -84,7 +84,7 @@ osf_core_core_file_p (bfd *abfd)
   if (val != sizeof core_header)
     return NULL;
 
-  if (! CONST_STRNEQ (core_header.magic, "Core"))
+  if (! startswith (core_header.magic, "Core"))
     return NULL;
 
   core_hdr (abfd) = (struct osf_core_struct *)
diff --git a/bfd/pef.c b/bfd/pef.c
index 93bc933eec1..c9304115f6d 100644
--- a/bfd/pef.c
+++ b/bfd/pef.c
@@ -219,7 +219,7 @@ bfd_pef_print_symbol (bfd *abfd,
     default:
       bfd_print_symbol_vandf (abfd, (void *) file, symbol);
       fprintf (file, " %-5s %s", symbol->section->name, symbol->name);
-      if (CONST_STRNEQ (symbol->name, "__traceback_"))
+      if (startswith (symbol->name, "__traceback_"))
 	{
 	  unsigned char *buf;
 	  size_t offset = symbol->value + 4;
diff --git a/bfd/pei-x86_64.c b/bfd/pei-x86_64.c
index 6ce808a2c8c..85c0ca2113b 100644
--- a/bfd/pei-x86_64.c
+++ b/bfd/pei-x86_64.c
@@ -835,7 +835,7 @@ static void
 pex64_print_all_pdata_sections (bfd *abfd, asection *pdata, void *arg)
 {
   struct pex64_paps *paps = arg;
-  if (CONST_STRNEQ (pdata->name, ".pdata"))
+  if (startswith (pdata->name, ".pdata"))
     {
       if (pex64_bfd_print_pdata_section (abfd, paps->obj, pdata))
 	paps->pdata_count++;
diff --git a/bfd/som.c b/bfd/som.c
index 872e93341d1..01bcd16cc1e 100644
--- a/bfd/som.c
+++ b/bfd/som.c
@@ -4803,12 +4803,12 @@ som_slurp_symbol_table (bfd *abfd)
 	  && sym->symbol.name[strlen (sym->symbol.name) - 1] == '$'
 	  && !strcmp (sym->symbol.name, sym->symbol.section->name))
 	sym->symbol.flags |= BSF_SECTION_SYM;
-      else if (CONST_STRNEQ (sym->symbol.name, "L$0\002"))
+      else if (startswith (sym->symbol.name, "L$0\002"))
 	{
 	  sym->symbol.flags |= BSF_SECTION_SYM;
 	  sym->symbol.name = sym->symbol.section->name;
 	}
-      else if (CONST_STRNEQ (sym->symbol.name, "L$0\001"))
+      else if (startswith (sym->symbol.name, "L$0\001"))
 	sym->symbol.flags |= BSF_DEBUGGING;
 
       /* Note increment at bottom of loop, since we skip some symbols
@@ -6186,7 +6186,7 @@ som_slurp_armap (bfd *abfd)
     return FALSE;
 
   /* For archives without .o files there is no symbol table.  */
-  if (! CONST_STRNEQ (nextname, "/               "))
+  if (! startswith (nextname, "/               "))
     {
       abfd->has_armap = FALSE;
       return TRUE;
diff --git a/bfd/wasm-module.c b/bfd/wasm-module.c
index a8f65479af9..da9616e3c97 100644
--- a/bfd/wasm-module.c
+++ b/bfd/wasm-module.c
@@ -536,7 +536,7 @@ wasm_compute_custom_section_file_position (bfd *abfd,
   if (idx != 0)
     return;
 
-  if (CONST_STRNEQ (asect->name, WASM_SECTION_PREFIX))
+  if (startswith (asect->name, WASM_SECTION_PREFIX))
     {
       const char *name = asect->name + strlen (WASM_SECTION_PREFIX);
       bfd_size_type payload_len = asect->size;
diff --git a/binutils/dlltool.c b/binutils/dlltool.c
index 3d44a0b9630..ca31df964ef 100644
--- a/binutils/dlltool.c
+++ b/binutils/dlltool.c
@@ -1367,7 +1367,7 @@ scan_drectve_symbols (bfd *abfd)
   while (p < e)
     {
       if (p[0] == '-'
-	  && CONST_STRNEQ (p, "-export:"))
+	  && startswith (p, "-export:"))
 	{
 	  char * name;
 	  char * c;
@@ -1399,7 +1399,7 @@ scan_drectve_symbols (bfd *abfd)
 	      char *tag_start = ++p;
 	      while (p < e && *p != ' ' && *p != '-')
 		p++;
-	      if (CONST_STRNEQ (tag_start, "data"))
+	      if (startswith (tag_start, "data"))
 		flags &= ~BSF_FUNCTION;
 	    }
 
diff --git a/binutils/emul_aix.c b/binutils/emul_aix.c
index 5be8f3891c5..c11c28bd030 100644
--- a/binutils/emul_aix.c
+++ b/binutils/emul_aix.c
@@ -91,25 +91,25 @@ ar_emul_aix_replace (bfd **after_bfd, bfd *new_bfd,
 static bfd_boolean
 ar_emul_aix_parse_arg (char *arg)
 {
-  if (CONST_STRNEQ (arg, "-X32_64"))
+  if (startswith (arg, "-X32_64"))
     {
       big_archive = TRUE;
       X32 = TRUE;
       X64 = TRUE;
     }
-  else if (CONST_STRNEQ (arg, "-X32"))
+  else if (startswith (arg, "-X32"))
     {
       big_archive = TRUE;
       X32 = TRUE;
       X64 = FALSE;
     }
-  else if (CONST_STRNEQ (arg, "-X64"))
+  else if (startswith (arg, "-X64"))
     {
       big_archive = TRUE;
       X32 = FALSE;
       X64 = TRUE;
     }
-  else if (CONST_STRNEQ (arg, "-g"))
+  else if (startswith (arg, "-g"))
     {
       big_archive = FALSE;
       X32 = TRUE;
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index d58f910f2fa..f5e48e80d08 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -1316,7 +1316,7 @@ is_mergeable_note_section (bfd * abfd, asection * sec)
       && elf_section_data (sec)->this_hdr.sh_type == SHT_NOTE
       /* FIXME: We currently only support merging GNU_BUILD_NOTEs.
 	 We should add support for more note types.  */
-      && (CONST_STRNEQ (sec->name, GNU_BUILD_ATTRS_SECTION_NAME)))
+      && (startswith (sec->name, GNU_BUILD_ATTRS_SECTION_NAME)))
     return TRUE;
 
   return FALSE;
diff --git a/binutils/objdump.c b/binutils/objdump.c
index 0aa037384c6..cb5ce5b057c 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -3748,7 +3748,7 @@ dump_dwarf_section (bfd *abfd, asection *section,
   const char *match;
   int i;
 
-  if (CONST_STRNEQ (name, ".gnu.linkonce.wi."))
+  if (startswith (name, ".gnu.linkonce.wi."))
     match = ".debug_info";
   else
     match = name;
diff --git a/binutils/prdbg.c b/binutils/prdbg.c
index a93dccd544d..614d7f918f5 100644
--- a/binutils/prdbg.c
+++ b/binutils/prdbg.c
@@ -937,10 +937,10 @@ pr_method_type (void *p, bfd_boolean domain, int argcount, bfd_boolean varargs)
       domain_type = pop_type (info);
       if (domain_type == NULL)
 	return FALSE;
-      if (CONST_STRNEQ (domain_type, "class ")
+      if (startswith (domain_type, "class ")
 	  && strchr (domain_type + sizeof "class " - 1, ' ') == NULL)
 	domain_type += sizeof "class " - 1;
-      else if (CONST_STRNEQ (domain_type, "union class ")
+      else if (startswith (domain_type, "union class ")
 	       && (strchr (domain_type + sizeof "union class " - 1, ' ')
 		   == NULL))
 	domain_type += sizeof "union class " - 1;
@@ -1349,7 +1349,7 @@ pr_class_baseclass (void *p, bfd_vma bitpos, bfd_boolean is_virtual,
   if (t == NULL)
     return FALSE;
 
-  if (CONST_STRNEQ (t, "class "))
+  if (startswith (t, "class "))
     t += sizeof "class " - 1;
 
   /* Push it back on to take advantage of the prepend_type and
@@ -2238,7 +2238,7 @@ tg_class_baseclass (void *p, bfd_vma bitpos ATTRIBUTE_UNUSED,
   if (t == NULL)
     return FALSE;
 
-  if (CONST_STRNEQ (t, "class "))
+  if (startswith (t, "class "))
     t += sizeof "class " - 1;
 
   /* Push it back on to take advantage of the prepend_type and
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 9e8cd873e47..bcd05dfeda6 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -12707,7 +12707,7 @@ process_lto_symbol_tables (Filedata * filedata)
        i < filedata->file_header.e_shnum;
        i++, section++)
     if (SECTION_NAME_VALID (section)
-	&& CONST_STRNEQ (SECTION_NAME (section), ".gnu.lto_.symtab."))
+	&& startswith (SECTION_NAME (section), ".gnu.lto_.symtab."))
       res &= display_lto_symtab (filedata, section);
 
   return res;
diff --git a/binutils/stabs.c b/binutils/stabs.c
index 90254fdb2a6..5b6842ef04c 100644
--- a/binutils/stabs.c
+++ b/binutils/stabs.c
@@ -1760,12 +1760,12 @@ parse_stab_range_type (void *                dhandle,
 #define ULLHIGH "01777777777777777777777;"
       if (index_type == DEBUG_TYPE_NULL)
 	{
-	  if (CONST_STRNEQ (s2, LLLOW)
-	      && CONST_STRNEQ (s3, LLHIGH))
+	  if (startswith (s2, LLLOW)
+	      && startswith (s3, LLHIGH))
 	    return debug_make_int_type (dhandle, 8, FALSE);
 	  if (! ov2
 	      && n2 == 0
-	      && CONST_STRNEQ (s3, ULLHIGH))
+	      && startswith (s3, ULLHIGH))
 	    return debug_make_int_type (dhandle, 8, TRUE);
 	}
 
@@ -2987,7 +2987,7 @@ parse_stab_argtypes (void *dhandle, struct stab_handle *info,
 				   && (ISDIGIT (argtypes[2])
 				       || argtypes[2] == 'Q'
 				       || argtypes[2] == 't'))
-				  || CONST_STRNEQ (argtypes, "__ct"));
+				  || startswith (argtypes, "__ct"));
 
   is_constructor = (is_full_physname_constructor
 		    || (tagname != NULL
@@ -2995,7 +2995,7 @@ parse_stab_argtypes (void *dhandle, struct stab_handle *info,
   is_destructor = ((argtypes[0] == '_'
 		    && (argtypes[1] == '$' || argtypes[1] == '.')
 		    && argtypes[2] == '_')
-		   || CONST_STRNEQ (argtypes, "__dt"));
+		   || startswith (argtypes, "__dt"));
   is_v3 = argtypes[0] == '_' && argtypes[1] == 'Z';
 
   if (!(is_destructor || is_full_physname_constructor || is_v3))
@@ -3995,7 +3995,7 @@ stab_demangle_function_name (struct stab_demangle_info *minfo,
   *pp = scan + 2;
 
   if (*pp - name >= 5
-	   && CONST_STRNEQ (name, "type")
+	   && startswith (name, "type")
 	   && (name[4] == '$' || name[4] == '.'))
     {
       const char *tem;
diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index 079012267fd..84a3f292656 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -13016,7 +13016,7 @@ md_parse_option (int c, const char *arg)
 
 	list = bfd_target_list ();
 	for (l = list; *l != NULL; l++)
-	  if (CONST_STRNEQ (*l, "elf64-x86-64")
+	  if (startswith (*l, "elf64-x86-64")
 	      || strcmp (*l, "coff-x86-64") == 0
 	      || strcmp (*l, "pe-x86-64") == 0
 	      || strcmp (*l, "pei-x86-64") == 0
@@ -13040,7 +13040,7 @@ md_parse_option (int c, const char *arg)
 
 	  list = bfd_target_list ();
 	  for (l = list; *l != NULL; l++)
-	    if (CONST_STRNEQ (*l, "elf32-x86-64"))
+	    if (startswith (*l, "elf32-x86-64"))
 	      {
 		default_arch = "x86_64:32";
 		break;
@@ -14366,7 +14366,7 @@ x86_64_section_letter (int letter, const char **ptr_msg)
 bfd_vma
 x86_64_section_word (char *str, size_t len)
 {
-  if (len == 5 && flag_code == CODE_64BIT && CONST_STRNEQ (str, "large"))
+  if (len == 5 && flag_code == CODE_64BIT && startswith (str, "large"))
     return SHF_X86_64_LARGE;
 
   return -1;
diff --git a/gas/config/tc-sparc.c b/gas/config/tc-sparc.c
index d526a34489a..61cd27d7239 100644
--- a/gas/config/tc-sparc.c
+++ b/gas/config/tc-sparc.c
@@ -548,12 +548,12 @@ md_parse_option (int c, const char *arg)
 	  {
 	    if (sparc_arch_size == 32)
 	      {
-		if (CONST_STRNEQ (*l, "elf32-sparc"))
+		if (startswith (*l, "elf32-sparc"))
 		  break;
 	      }
 	    else
 	      {
-		if (CONST_STRNEQ (*l, "elf64-sparc"))
+		if (startswith (*l, "elf64-sparc"))
 		  break;
 	      }
 	  }
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 4e2ab32b5ee..23540092e77 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -8535,7 +8535,7 @@ show_disassembly_style_sfunc (struct ui_file *file, int from_tty,
   const char *opt;
 
   FOR_EACH_DISASSEMBLER_OPTION (opt, options)
-    if (CONST_STRNEQ (opt, "reg-names-"))
+    if (startswith (opt, "reg-names-"))
       {
 	style = &opt[strlen ("reg-names-")];
 	len = strcspn (style, ",");
@@ -9575,14 +9575,14 @@ _initialize_arm_tdep ()
     = &disassembler_options_arm ()->options;
   int num_disassembly_styles = 0;
   for (i = 0; disasm_options->name[i] != NULL; i++)
-    if (CONST_STRNEQ (disasm_options->name[i], "reg-names-"))
+    if (startswith (disasm_options->name[i], "reg-names-"))
       num_disassembly_styles++;
 
   /* Initialize the array that will be passed to add_setshow_enum_cmd().  */
   valid_disassembly_styles = XNEWVEC (const char *,
 				      num_disassembly_styles + 1);
   for (i = j = 0; disasm_options->name[i] != NULL; i++)
-    if (CONST_STRNEQ (disasm_options->name[i], "reg-names-"))
+    if (startswith (disasm_options->name[i], "reg-names-"))
       {
 	size_t offset = strlen ("reg-names-");
 	const char *style = disasm_options->name[i];
diff --git a/ld/emultempl/aix.em b/ld/emultempl/aix.em
index e098f2a8850..6fd67b2b7f8 100644
--- a/ld/emultempl/aix.em
+++ b/ld/emultempl/aix.em
@@ -287,7 +287,7 @@ gld${EMULATION_NAME}_parse_args (int argc, char **argv)
   if (indx == 0)
     indx = 1;
 
-  if (indx < argc && CONST_STRNEQ (argv[indx], "-b"))
+  if (indx < argc && startswith (argv[indx], "-b"))
     {
       char *s;
 
diff --git a/ld/emultempl/beos.em b/ld/emultempl/beos.em
index fc43ce14677..d984d3dd198 100644
--- a/ld/emultempl/beos.em
+++ b/ld/emultempl/beos.em
@@ -461,8 +461,8 @@ sort_by_section_name (const void *a, const void *b)
      FIXME stripping images with a .rsrc section still needs to be fixed.  */
   if (i != 0)
     {
-      if ((CONST_STRNEQ (sna, ".stab"))
-	  && (!CONST_STRNEQ (snb, ".stab")))
+      if ((startswith (sna, ".stab"))
+	  && (!startswith (snb, ".stab")))
 	return 1;
     }
   return i;
@@ -536,7 +536,7 @@ sort_sections (lang_statement_union_type *s)
 	    {
 	      /* Is this the .idata section?  */
 	      if (sec->spec.name != NULL
-		  && CONST_STRNEQ (sec->spec.name, ".idata"))
+		  && startswith (sec->spec.name, ".idata"))
 		{
 		  /* Sort the children.  We want to sort any objects in
 		     the same archive.  In order to handle the case of
diff --git a/ld/emultempl/elf.em b/ld/emultempl/elf.em
index 9e7c3d86a9e..986b77e92d9 100644
--- a/ld/emultempl/elf.em
+++ b/ld/emultempl/elf.em
@@ -712,7 +712,7 @@ fragment <<EOF
 	link_info.unresolved_syms_in_objects = RM_IGNORE;
       else if (strcmp (optarg, "muldefs") == 0)
 	link_info.allow_multiple_definition = TRUE;
-      else if (CONST_STRNEQ (optarg, "max-page-size="))
+      else if (startswith (optarg, "max-page-size="))
 	{
 	  char *end;
 
@@ -722,7 +722,7 @@ fragment <<EOF
 	    einfo (_("%F%P: invalid maximum page size \`%s'\n"),
 		   optarg + 14);
 	}
-      else if (CONST_STRNEQ (optarg, "common-page-size="))
+      else if (startswith (optarg, "common-page-size="))
 	{
 	  char *end;
 	  link_info.commonpagesize = strtoul (optarg + 17, &end, 0);
@@ -731,7 +731,7 @@ fragment <<EOF
 	    einfo (_("%F%P: invalid common page size \`%s'\n"),
 		   optarg + 17);
 	}
-      else if (CONST_STRNEQ (optarg, "stack-size="))
+      else if (startswith (optarg, "stack-size="))
 	{
 	  char *end;
 	  link_info.stacksize = strtoul (optarg + 11, &end, 0);
@@ -760,11 +760,11 @@ fragment <<EOF
 	{
 	  link_info.flags_1 |= DF_1_GLOBAUDIT;
 	}
-      else if (CONST_STRNEQ (optarg, "start-stop-gc"))
+      else if (startswith (optarg, "start-stop-gc"))
 	link_info.start_stop_gc = TRUE;
-      else if (CONST_STRNEQ (optarg, "nostart-stop-gc"))
+      else if (startswith (optarg, "nostart-stop-gc"))
 	link_info.start_stop_gc = FALSE;
-      else if (CONST_STRNEQ (optarg, "start-stop-visibility="))
+      else if (startswith (optarg, "start-stop-visibility="))
 	{
 	  if (strcmp (optarg, "start-stop-visibility=default") == 0)
 	    link_info.start_stop_visibility = STV_DEFAULT;
diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em
index 748a6b49412..ea11a02e7c8 100644
--- a/ld/emultempl/pe.em
+++ b/ld/emultempl/pe.em
@@ -1529,7 +1529,7 @@ gld_${EMULATION_NAME}_after_open (void)
 	      {
 		if (strcmp (sec->name, ".idata\$2") == 0)
 		  idata2 = 1;
-		if (CONST_STRNEQ (sec->name, ".idata\$"))
+		if (startswith (sec->name, ".idata\$"))
 		  is_imp = 1;
 		reloc_count += sec->reloc_count;
 	      }
diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em
index ff49c15c002..5f539cb7a3e 100644
--- a/ld/emultempl/pep.em
+++ b/ld/emultempl/pep.em
@@ -1501,7 +1501,7 @@ gld_${EMULATION_NAME}_after_open (void)
 	      {
 		if (strcmp (sec->name, ".idata\$2") == 0)
 		  idata2 = 1;
-		if (CONST_STRNEQ (sec->name, ".idata\$"))
+		if (startswith (sec->name, ".idata\$"))
 		  is_imp = 1;
 		reloc_count += sec->reloc_count;
 	      }
diff --git a/ld/emultempl/xtensaelf.em b/ld/emultempl/xtensaelf.em
index cdab038db7e..2b0fa5af64c 100644
--- a/ld/emultempl/xtensaelf.em
+++ b/ld/emultempl/xtensaelf.em
@@ -262,7 +262,7 @@ replace_instruction_table_sections (bfd *abfd, asection *sec)
       insn_sec_name = INSN_SEC_BASE_NAME;
       prop_sec_name = PROP_SEC_BASE_NAME;
     }
-  else if (CONST_STRNEQ (sec_name, LINKONCE_SEC_OLD_TEXT_BASE_NAME))
+  else if (startswith (sec_name, LINKONCE_SEC_OLD_TEXT_BASE_NAME))
     {
       insn_sec_name = sec_name;
       owned_prop_sec_name = (char *) xmalloc (strlen (sec_name) + 20);
@@ -1320,7 +1320,7 @@ is_inconsistent_linkonce_section (asection *sec)
   /* Check if this is an Xtensa property section or an exception table
      for Tensilica's XCC compiler.  */
   name = sec_name + linkonce_len;
-  if (CONST_STRNEQ (name, "prop."))
+  if (startswith (name, "prop."))
     name = strchr (name + 5, '.') ? strchr (name + 5, '.') + 1 : name + 5;
   else if (name[1] == '.'
 	   && (name[0] == 'p' || name[0] == 'e' || name[0] == 'h'))
diff --git a/ld/ldctor.c b/ld/ldctor.c
index 7ab6f36c46f..841ffe3b1e5 100644
--- a/ld/ldctor.c
+++ b/ld/ldctor.c
@@ -131,7 +131,7 @@ ctor_prio (const char *name)
   while (*name == '_')
     ++name;
 
-  if (!CONST_STRNEQ (name, "GLOBAL_"))
+  if (!startswith (name, "GLOBAL_"))
     return -1;
 
   name += sizeof "GLOBAL_" - 1;
diff --git a/ld/ldelf.c b/ld/ldelf.c
index a733131e51c..94d775db5cd 100644
--- a/ld/ldelf.c
+++ b/ld/ldelf.c
@@ -321,7 +321,7 @@ ldelf_try_needed (struct dt_needed *needed, int force, int is_linux)
 	      struct bfd_link_needed_list *l;
 
 	      for (l = needs; l != NULL; l = l->next)
-		if (CONST_STRNEQ (l->name, "libc.so"))
+		if (startswith (l->name, "libc.so"))
 		  break;
 	      if (l == NULL)
 		{
@@ -837,7 +837,7 @@ ldelf_parse_ld_so_conf (struct ldelf_ld_so_conf *info, const char *filename)
       if (p[0] == '\0')
 	continue;
 
-      if (CONST_STRNEQ (p, "include") && (p[7] == ' ' || p[7] == '\t'))
+      if (startswith (p, "include") && (p[7] == ' ' || p[7] == '\t'))
 	{
 	  char *dir, c;
 	  p += 8;
@@ -1089,7 +1089,7 @@ ldelf_after_open (int use_libpath, int native, int is_linux, int is_freebsd,
 
 	      if (bfd_is_abs_section (s->output_section))
 		continue;
-	      if (CONST_STRNEQ (name, ".eh_frame_entry"))
+	      if (startswith (name, ".eh_frame_entry"))
 		type = COMPACT_EH_HDR;
 	      else if (strcmp (name, ".eh_frame") == 0 && s->size > 8)
 		type = DWARF2_EH_HDR;
@@ -1820,7 +1820,7 @@ output_rel_find (int isdyn, int rela)
        lookup = lookup->next)
     {
       if (lookup->constraint >= 0
-	  && CONST_STRNEQ (lookup->name, ".rel"))
+	  && startswith (lookup->name, ".rel"))
 	{
 	  int lookrela = lookup->name[4] == 'a';
 
@@ -1971,7 +1971,7 @@ ldelf_place_orphan (asection *s, const char *secname, int constraint)
 	  default:
 	    break;
 	  }
-      else if (CONST_STRNEQ (secname, ".rel"))
+      else if (startswith (secname, ".rel"))
 	{
 	  secname = secname[4] == 'a' ? ".rela.dyn" : ".rel.dyn";
 	  isdyn = 1;
@@ -2084,7 +2084,7 @@ ldelf_place_orphan (asection *s, const char *secname, int constraint)
   /* If this is a final link, then always put .gnu.warning.SYMBOL
      sections into the .text section to get them out of the way.  */
   if (bfd_link_executable (&link_info)
-      && CONST_STRNEQ (s->name, ".gnu.warning.")
+      && startswith (s->name, ".gnu.warning.")
       && hold[orphan_text].os != NULL)
     {
       os = hold[orphan_text].os;
@@ -2124,7 +2124,7 @@ ldelf_place_orphan (asection *s, const char *secname, int constraint)
   else if ((flags & SEC_LOAD) != 0
 	   && (elfinput
 	       ? sh_type == SHT_NOTE
-	       : CONST_STRNEQ (secname, ".note")))
+	       : startswith (secname, ".note")))
     place = &hold[orphan_interp];
   else if ((flags & (SEC_LOAD | SEC_HAS_CONTENTS | SEC_THREAD_LOCAL)) == 0)
     place = &hold[orphan_bss];
@@ -2137,7 +2137,7 @@ ldelf_place_orphan (asection *s, const char *secname, int constraint)
   else if ((flags & SEC_LOAD) != 0
 	   && (elfinput
 	       ? sh_type == SHT_RELA || sh_type == SHT_REL
-	       : CONST_STRNEQ (secname, ".rel")))
+	       : startswith (secname, ".rel")))
     place = &hold[orphan_rel];
   else if ((flags & SEC_CODE) == 0)
     place = &hold[orphan_rodata];
diff --git a/ld/ldfile.c b/ld/ldfile.c
index 81cb86d51e2..c428d1487f3 100644
--- a/ld/ldfile.c
+++ b/ld/ldfile.c
@@ -113,7 +113,7 @@ ldfile_add_library_path (const char *name, bfd_boolean cmdline)
      now.  */
   if (name[0] == '=')
     new_dirs->name = concat (ld_sysroot, name + 1, (const char *) NULL);
-  else if (CONST_STRNEQ (name, "$SYSROOT"))
+  else if (startswith (name, "$SYSROOT"))
     new_dirs->name = concat (ld_sysroot, name + strlen ("$SYSROOT"), (const char *) NULL);
   else
     new_dirs->name = xstrdup (name);
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 684e1d23a21..d02a30981c4 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -1186,7 +1186,7 @@ lang_add_input_file (const char *name,
 		     const char *target)
 {
   if (name != NULL
-      && (*name == '=' || CONST_STRNEQ (name, "$SYSROOT")))
+      && (*name == '=' || startswith (name, "$SYSROOT")))
     {
       lang_input_statement_type *ret;
       char *sysrooted_name
diff --git a/ld/ldmain.c b/ld/ldmain.c
index 7a3c02aeaa6..aa52205daf4 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -648,7 +648,7 @@ get_sysroot (int argc, char **argv)
   const char *path = NULL;
 
   for (i = 1; i < argc; i++)
-    if (CONST_STRNEQ (argv[i], "--sysroot="))
+    if (startswith (argv[i], "--sysroot="))
       path = argv[i] + strlen ("--sysroot=");
 
   if (!path)
@@ -681,7 +681,7 @@ get_emulation (int argc, char **argv)
 
   for (i = 1; i < argc; i++)
     {
-      if (CONST_STRNEQ (argv[i], "-m"))
+      if (startswith (argv[i], "-m"))
 	{
 	  if (argv[i][2] == '\0')
 	    {
@@ -935,7 +935,7 @@ add_archive_element (struct bfd_link_info *info,
       h = bfd_link_hash_lookup (info->hash, name, FALSE, FALSE, TRUE);
       if (h == NULL
 	  && info->pei386_auto_import
-	  && CONST_STRNEQ (name, "__imp_"))
+	  && startswith (name, "__imp_"))
 	h = bfd_link_hash_lookup (info->hash, name + 6, FALSE, FALSE, TRUE);
 
       if (h == NULL)
diff --git a/ld/ldwrite.c b/ld/ldwrite.c
index 2db0b63b792..ef1d88c6ce2 100644
--- a/ld/ldwrite.c
+++ b/ld/ldwrite.c
@@ -281,7 +281,7 @@ build_link_order (lang_statement_union_type *statement)
 static bfd_boolean
 unsplittable_name (const char *name)
 {
-  if (CONST_STRNEQ (name, ".stab"))
+  if (startswith (name, ".stab"))
     {
       /* There are several stab like string sections. We pattern match on
 	 ".stab...str"  */
@@ -326,7 +326,7 @@ clone_section (bfd *abfd, asection *s, const char *name, int *count)
     {
       /* Some section names cannot be truncated, as the name is
 	 used to locate some other section.  */
-      if (CONST_STRNEQ (name, ".stab")
+      if (startswith (name, ".stab")
 	  || strcmp (name, "$GDB_SYMBOLS$") == 0)
 	{
 	  einfo (_ ("%F%P: cannot create split section name for %s\n"), name);
diff --git a/ld/lexsup.c b/ld/lexsup.c
index 36492abb405..88eb79e7f69 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -1560,7 +1560,7 @@ parse_args (unsigned argc, char **argv)
 	  link_info.discard = discard_all;
 	  break;
 	case 'Y':
-	  if (CONST_STRNEQ (optarg, "P,"))
+	  if (startswith (optarg, "P,"))
 	    optarg += 2;
 	  free (default_dirlist);
 	  default_dirlist = xstrdup (optarg);
diff --git a/ld/pe-dll.c b/ld/pe-dll.c
index 7aba09cd359..154c6846beb 100644
--- a/ld/pe-dll.c
+++ b/ld/pe-dll.c
@@ -545,7 +545,7 @@ pe_dll_add_excludes (const char *new_excludes, const exclude_type type)
 static bfd_boolean
 is_import (const char* n)
 {
-  return (CONST_STRNEQ (n, "__imp_"));
+  return (startswith (n, "__imp_"));
 }
 
 /* abfd is a bfd containing n (or NULL)
@@ -3531,7 +3531,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
diff --git a/opcodes/aarch64-dis.c b/opcodes/aarch64-dis.c
index 19482f729ab..349d7ea7ec0 100644
--- a/opcodes/aarch64-dis.c
+++ b/opcodes/aarch64-dis.c
@@ -58,32 +58,32 @@ static void
 parse_aarch64_dis_option (const char *option, unsigned int len ATTRIBUTE_UNUSED)
 {
   /* Try to match options that are simple flags */
-  if (CONST_STRNEQ (option, "no-aliases"))
+  if (startswith (option, "no-aliases"))
     {
       no_aliases = 1;
       return;
     }
 
-  if (CONST_STRNEQ (option, "aliases"))
+  if (startswith (option, "aliases"))
     {
       no_aliases = 0;
       return;
     }
 
-  if (CONST_STRNEQ (option, "no-notes"))
+  if (startswith (option, "no-notes"))
     {
       no_notes = 1;
       return;
     }
 
-  if (CONST_STRNEQ (option, "notes"))
+  if (startswith (option, "notes"))
     {
       no_notes = 0;
       return;
     }
 
 #ifdef DEBUG_AARCH64
-  if (CONST_STRNEQ (option, "debug_dump"))
+  if (startswith (option, "debug_dump"))
     {
       debug_dump = 1;
       return;
diff --git a/opcodes/arc-dis.c b/opcodes/arc-dis.c
index 6a6404a1624..0c9b379bd2b 100644
--- a/opcodes/arc-dis.c
+++ b/opcodes/arc-dis.c
@@ -795,7 +795,7 @@ parse_option (const char *option)
       add_to_decodelist (FLOAT, DP);
       add_to_decodelist (FLOAT, CVT);
     }
-  else if (CONST_STRNEQ (option, "hex"))
+  else if (startswith (option, "hex"))
     print_hex = TRUE;
   else
     /* xgettext:c-format */
diff --git a/opcodes/arm-dis.c b/opcodes/arm-dis.c
index f16a5902479..9647d0019db 100644
--- a/opcodes/arm-dis.c
+++ b/opcodes/arm-dis.c
@@ -11600,7 +11600,7 @@ parse_arm_disassembler_options (const char *options)
 
   FOR_EACH_DISASSEMBLER_OPTION (opt, options)
     {
-      if (CONST_STRNEQ (opt, "reg-names-"))
+      if (startswith (opt, "reg-names-"))
 	{
 	  unsigned int i;
 	  for (i = 0; i < NUM_ARM_OPTIONS; i++)
@@ -11615,11 +11615,11 @@ parse_arm_disassembler_options (const char *options)
 	    opcodes_error_handler (_("unrecognised register name set: %s"),
 				   opt);
 	}
-      else if (CONST_STRNEQ (opt, "force-thumb"))
+      else if (startswith (opt, "force-thumb"))
 	force_thumb = 1;
-      else if (CONST_STRNEQ (opt, "no-force-thumb"))
+      else if (startswith (opt, "no-force-thumb"))
 	force_thumb = 0;
-      else if (CONST_STRNEQ (opt, "coproc"))
+      else if (startswith (opt, "coproc"))
 	{
 	  const char *procptr = opt + sizeof ("coproc") - 1;
 	  char *endptr;
@@ -11637,10 +11637,10 @@ parse_arm_disassembler_options (const char *options)
 	      continue;
 	    }
 	  endptr += 1;
-	  if (CONST_STRNEQ (endptr, "generic"))
+	  if (startswith (endptr, "generic"))
 	    cde_coprocs &= ~(1 << coproc_number);
-	  else if (CONST_STRNEQ (endptr, "cde")
-		   || CONST_STRNEQ (endptr, "CDE"))
+	  else if (startswith (endptr, "cde")
+		   || startswith (endptr, "CDE"))
 	    cde_coprocs |= (1 << coproc_number);
 	  else
 	    {
diff --git a/opcodes/cris-dis.c b/opcodes/cris-dis.c
index f4342491315..3f98cb028b5 100644
--- a/opcodes/cris-dis.c
+++ b/opcodes/cris-dis.c
@@ -786,7 +786,7 @@ print_with_operands (const struct cris_opcode *opcodep,
      better way).  */
   if (opcodep->name[0] == 'j')
     {
-      if (CONST_STRNEQ (opcodep->name, "jsr"))
+      if (startswith (opcodep->name, "jsr"))
 	/* It's "jsr" or "jsrc".  */
 	info->insn_type = dis_jsr;
       else
@@ -1360,16 +1360,16 @@ print_with_operands (const struct cris_opcode *opcodep,
      itself or in a "move.d const,rN, sub.d rN,rM"-like sequence.  */
   if (TRACE_CASE && case_offset_counter == 0)
     {
-      if (CONST_STRNEQ (opcodep->name, "sub"))
+      if (startswith (opcodep->name, "sub"))
 	case_offset = last_immediate;
 
       /* It could also be an "add", if there are negative case-values.  */
-      else if (CONST_STRNEQ (opcodep->name, "add"))
+      else if (startswith (opcodep->name, "add"))
 	/* The first case is the negated operand to the add.  */
 	case_offset = -last_immediate;
 
       /* A bound insn will tell us the number of cases.  */
-      else if (CONST_STRNEQ (opcodep->name, "bound"))
+      else if (startswith (opcodep->name, "bound"))
 	no_of_case_offsets = last_immediate + 1;
 
       /* A jump or jsr or branch breaks the chain of insns for a
diff --git a/opcodes/h8300-dis.c b/opcodes/h8300-dis.c
index 4cd8e3cced4..4696235a8db 100644
--- a/opcodes/h8300-dis.c
+++ b/opcodes/h8300-dis.c
@@ -655,7 +655,7 @@ bfd_h8_disassemble (bfd_vma addr, disassemble_info *info, int mach)
 		   regno[1]);
 	  return qi->length;
 	}
-      if (CONST_STRNEQ (q->name, "mova"))
+      if (startswith (q->name, "mova"))
 	{
 	  const op_type *args = q->args.nib;
 
diff --git a/opcodes/i386-dis.c b/opcodes/i386-dis.c
index 4e3304d4a4c..9e5c412fa4a 100644
--- a/opcodes/i386-dis.c
+++ b/opcodes/i386-dis.c
@@ -9413,38 +9413,38 @@ print_insn (bfd_vma pc, disassemble_info *info)
 
   for (p = info->disassembler_options; p != NULL; )
     {
-      if (CONST_STRNEQ (p, "amd64"))
+      if (startswith (p, "amd64"))
 	isa64 = amd64;
-      else if (CONST_STRNEQ (p, "intel64"))
+      else if (startswith (p, "intel64"))
 	isa64 = intel64;
-      else if (CONST_STRNEQ (p, "x86-64"))
+      else if (startswith (p, "x86-64"))
 	{
 	  address_mode = mode_64bit;
 	  priv.orig_sizeflag |= AFLAG | DFLAG;
 	}
-      else if (CONST_STRNEQ (p, "i386"))
+      else if (startswith (p, "i386"))
 	{
 	  address_mode = mode_32bit;
 	  priv.orig_sizeflag |= AFLAG | DFLAG;
 	}
-      else if (CONST_STRNEQ (p, "i8086"))
+      else if (startswith (p, "i8086"))
 	{
 	  address_mode = mode_16bit;
 	  priv.orig_sizeflag &= ~(AFLAG | DFLAG);
 	}
-      else if (CONST_STRNEQ (p, "intel"))
+      else if (startswith (p, "intel"))
 	{
 	  intel_syntax = 1;
-	  if (CONST_STRNEQ (p + 5, "-mnemonic"))
+	  if (startswith (p + 5, "-mnemonic"))
 	    intel_mnemonic = 1;
 	}
-      else if (CONST_STRNEQ (p, "att"))
+      else if (startswith (p, "att"))
 	{
 	  intel_syntax = 0;
-	  if (CONST_STRNEQ (p + 3, "-mnemonic"))
+	  if (startswith (p + 3, "-mnemonic"))
 	    intel_mnemonic = 0;
 	}
-      else if (CONST_STRNEQ (p, "addr"))
+      else if (startswith (p, "addr"))
 	{
 	  if (address_mode == mode_64bit)
 	    {
@@ -9461,14 +9461,14 @@ print_insn (bfd_vma pc, disassemble_info *info)
 		priv.orig_sizeflag |= AFLAG;
 	    }
 	}
-      else if (CONST_STRNEQ (p, "data"))
+      else if (startswith (p, "data"))
 	{
 	  if (p[4] == '1' && p[5] == '6')
 	    priv.orig_sizeflag &= ~DFLAG;
 	  else if (p[4] == '3' && p[5] == '2')
 	    priv.orig_sizeflag |= DFLAG;
 	}
-      else if (CONST_STRNEQ (p, "suffix"))
+      else if (startswith (p, "suffix"))
 	priv.orig_sizeflag |= SUFFIX_ALWAYS;
 
       p = strchr (p, ',');
diff --git a/opcodes/ia64-gen.c b/opcodes/ia64-gen.c
index 7f3f0edd5d3..de409bb2abd 100644
--- a/opcodes/ia64-gen.c
+++ b/opcodes/ia64-gen.c
@@ -467,7 +467,7 @@ fetch_insn_class (const char *full_name, int create)
   int ind;
   int is_class = 0;
 
-  if (CONST_STRNEQ (full_name, "IC:"))
+  if (startswith (full_name, "IC:"))
     {
       name = xstrdup (full_name + 3);
       is_class = 1;
@@ -746,7 +746,7 @@ parse_resource_users (const char *ref, int **usersp, int *nusersp,
          are read.  Only create new classes if it's *not* an insn class,
          or if it's a composite class (which wouldn't necessarily be in the IC
          table).  */
-      if (! CONST_STRNEQ (name, "IC:") || xsect != NULL)
+      if (! startswith (name, "IC:") || xsect != NULL)
         create = 1;
 
       iclass = fetch_insn_class (name, create);
@@ -1039,7 +1039,7 @@ in_iclass (struct ia64_opcode *idesc, struct iclass *ic,
 
   if (ic->comment)
     {
-      if (CONST_STRNEQ (ic->comment, "Format"))
+      if (startswith (ic->comment, "Format"))
         {
           /* Assume that the first format seen is the most restrictive, and
              only keep a later one if it looks like it's more restrictive.  */
@@ -1055,7 +1055,7 @@ in_iclass (struct ia64_opcode *idesc, struct iclass *ic,
           else
             format = ic->comment;
         }
-      else if (CONST_STRNEQ (ic->comment, "Field"))
+      else if (startswith (ic->comment, "Field"))
         {
           if (field)
             warn (_("overlapping field %s->%s\n"),
@@ -1069,7 +1069,7 @@ in_iclass (struct ia64_opcode *idesc, struct iclass *ic,
      instructions.  */
   if (ic->nsubs == 0 && ic->nxsubs == 0)
     {
-      int is_mov = CONST_STRNEQ (idesc->name, "mov");
+      int is_mov = startswith (idesc->name, "mov");
       int plain_mov = strcmp (idesc->name, "mov") == 0;
       int len = strlen(ic->name);
 
@@ -1128,32 +1128,32 @@ in_iclass (struct ia64_opcode *idesc, struct iclass *ic,
 
       if (resolved && format)
         {
-          if (CONST_STRNEQ (idesc->name, "dep")
+          if (startswith (idesc->name, "dep")
                    && strstr (format, "I13") != NULL)
             resolved = idesc->operands[1] == IA64_OPND_IMM8;
-          else if (CONST_STRNEQ (idesc->name, "chk")
+          else if (startswith (idesc->name, "chk")
                    && strstr (format, "M21") != NULL)
             resolved = idesc->operands[0] == IA64_OPND_F2;
-          else if (CONST_STRNEQ (idesc->name, "lfetch"))
+          else if (startswith (idesc->name, "lfetch"))
             resolved = (strstr (format, "M14 M15") != NULL
                         && (idesc->operands[1] == IA64_OPND_R2
                             || idesc->operands[1] == IA64_OPND_IMM9b));
-          else if (CONST_STRNEQ (idesc->name, "br.call")
+          else if (startswith (idesc->name, "br.call")
                    && strstr (format, "B5") != NULL)
             resolved = idesc->operands[1] == IA64_OPND_B2;
-          else if (CONST_STRNEQ (idesc->name, "br.call")
+          else if (startswith (idesc->name, "br.call")
                    && strstr (format, "B3") != NULL)
             resolved = idesc->operands[1] == IA64_OPND_TGT25c;
-          else if (CONST_STRNEQ (idesc->name, "brp")
+          else if (startswith (idesc->name, "brp")
                    && strstr (format, "B7") != NULL)
             resolved = idesc->operands[0] == IA64_OPND_B2;
           else if (strcmp (ic->name, "invala") == 0)
             resolved = strcmp (idesc->name, ic->name) == 0;
-	  else if (CONST_STRNEQ (idesc->name, "st")
+	  else if (startswith (idesc->name, "st")
 		   && (strstr (format, "M5") != NULL
 		       || strstr (format, "M10") != NULL))
 	    resolved = idesc->flags & IA64_OPCODE_POSTINC;
-	  else if (CONST_STRNEQ (idesc->name, "ld")
+	  else if (startswith (idesc->name, "ld")
 		   && (strstr (format, "M2 M3") != NULL
 		       || strstr (format, "M12") != NULL
 		       || strstr (format, "M7 M8") != NULL))
@@ -1166,7 +1166,7 @@ in_iclass (struct ia64_opcode *idesc, struct iclass *ic,
          plain brl matches brl.cond.  */
       if (!resolved
           && (strcmp (idesc->name, "brl") == 0
-              || CONST_STRNEQ (idesc->name, "brl."))
+              || startswith (idesc->name, "brl."))
           && strcmp (ic->name, "brl.cond") == 0)
         {
           resolved = 1;
@@ -1175,7 +1175,7 @@ in_iclass (struct ia64_opcode *idesc, struct iclass *ic,
       /* Misc br variations ('.cond' is optional).  */
       if (!resolved
           && (strcmp (idesc->name, "br") == 0
-              || CONST_STRNEQ (idesc->name, "br."))
+              || startswith (idesc->name, "br."))
           && strcmp (ic->name, "br.cond") == 0)
         {
           if (format)
@@ -1188,7 +1188,7 @@ in_iclass (struct ia64_opcode *idesc, struct iclass *ic,
         }
 
       /* probe variations.  */
-      if (!resolved && CONST_STRNEQ (idesc->name, "probe"))
+      if (!resolved && startswith (idesc->name, "probe"))
         {
           resolved = strcmp (ic->name, "probe") == 0
             && !((strstr (idesc->name, "fault") != NULL)
@@ -1222,7 +1222,7 @@ in_iclass (struct ia64_opcode *idesc, struct iclass *ic,
             }
 
           /* Some variants of mov and mov.[im].  */
-          if (!resolved && CONST_STRNEQ (ic->name, "mov_"))
+          if (!resolved && startswith (ic->name, "mov_"))
 	    resolved = in_iclass_mov_x (idesc, ic, format, field);
         }
 
@@ -1487,13 +1487,13 @@ lookup_specifier (const char *name)
       warn (_("Don't know how to specify # dependency %s\n"),
 	    name);
     }
-  else if (CONST_STRNEQ (name, "AR[FPSR]"))
+  else if (startswith (name, "AR[FPSR]"))
     return IA64_RS_AR_FPSR;
-  else if (CONST_STRNEQ (name, "AR["))
+  else if (startswith (name, "AR["))
     return IA64_RS_ARX;
-  else if (CONST_STRNEQ (name, "CR["))
+  else if (startswith (name, "CR["))
     return IA64_RS_CRX;
-  else if (CONST_STRNEQ (name, "PSR."))
+  else if (startswith (name, "PSR."))
     return IA64_RS_PSR;
   else if (strcmp (name, "InService*") == 0)
     return IA64_RS_INSERVICE;
@@ -2444,7 +2444,7 @@ insert_opcode_dependencies (struct ia64_opcode *opc,
       int j;
 
       if (strcmp (opc->name, "cmp.eq.and") == 0
-          && CONST_STRNEQ (rs->name, "PR%")
+          && startswith (rs->name, "PR%")
           && rs->mode == 1)
         no_class_found = 99;
 
@@ -2455,7 +2455,7 @@ insert_opcode_dependencies (struct ia64_opcode *opc,
           if (in_iclass (opc, ics[rs->regs[j]], NULL, NULL, &ic_note))
             {
               /* We can ignore ic_note 11 for non PR resources.  */
-              if (ic_note == 11 && ! CONST_STRNEQ (rs->name, "PR"))
+              if (ic_note == 11 && ! startswith (rs->name, "PR"))
                 ic_note = 0;
 
               if (ic_note != 0 && rs->regnotes[j] != 0
@@ -2483,7 +2483,7 @@ insert_opcode_dependencies (struct ia64_opcode *opc,
           if (in_iclass (opc, ics[rs->chks[j]], NULL, NULL, &ic_note))
             {
               /* We can ignore ic_note 11 for non PR resources.  */
-              if (ic_note == 11 && ! CONST_STRNEQ (rs->name, "PR"))
+              if (ic_note == 11 && ! startswith (rs->name, "PR"))
                 ic_note = 0;
 
               if (ic_note != 0 && rs->chknotes[j] != 0
diff --git a/opcodes/mips-dis.c b/opcodes/mips-dis.c
index 317ced51204..d1f73b4d9f6 100644
--- a/opcodes/mips-dis.c
+++ b/opcodes/mips-dis.c
@@ -923,7 +923,7 @@ set_default_mips_dis_options (struct disassemble_info *info)
 static bfd_boolean
 parse_mips_ase_option (const char *option)
 {
-  if (CONST_STRNEQ (option, "msa"))
+  if (startswith (option, "msa"))
     {
       mips_ase |= ASE_MSA;
       if ((mips_isa & INSN_ISA_MASK) == ISA_MIPS64R2
@@ -934,7 +934,7 @@ parse_mips_ase_option (const char *option)
       return TRUE;
     }
 
-  if (CONST_STRNEQ (option, "virt"))
+  if (startswith (option, "virt"))
     {
       mips_ase |= ASE_VIRT;
       if (mips_isa & ISA_MIPS64R2
@@ -945,38 +945,38 @@ parse_mips_ase_option (const char *option)
       return TRUE;
     }
 
-  if (CONST_STRNEQ (option, "xpa"))
+  if (startswith (option, "xpa"))
     {
       mips_ase |= ASE_XPA;
       return TRUE;
     }
 
-  if (CONST_STRNEQ (option, "ginv"))
+  if (startswith (option, "ginv"))
     {
       mips_ase |= ASE_GINV;
       return TRUE;
     }
 
-  if (CONST_STRNEQ (option, "loongson-mmi"))
+  if (startswith (option, "loongson-mmi"))
     {
       mips_ase |= ASE_LOONGSON_MMI;
       return TRUE;
     }
 
-  if (CONST_STRNEQ (option, "loongson-cam"))
+  if (startswith (option, "loongson-cam"))
     {
       mips_ase |= ASE_LOONGSON_CAM;
       return TRUE;
     }
   
   /* Put here for match ext2 frist */
-  if (CONST_STRNEQ (option, "loongson-ext2"))
+  if (startswith (option, "loongson-ext2"))
     {
       mips_ase |= ASE_LOONGSON_EXT2;
       return TRUE;
     }
 
-  if (CONST_STRNEQ (option, "loongson-ext"))
+  if (startswith (option, "loongson-ext"))
     {
       mips_ase |= ASE_LOONGSON_EXT;
       return TRUE;
@@ -994,7 +994,7 @@ parse_mips_dis_option (const char *option, unsigned int len)
   const struct mips_arch_choice *chosen_arch;
 
   /* Try to match options that are simple flags */
-  if (CONST_STRNEQ (option, "no-aliases"))
+  if (startswith (option, "no-aliases"))
     {
       no_aliases = 1;
       return;
diff --git a/opcodes/s390-dis.c b/opcodes/s390-dis.c
index 1eb372554da..4708b094560 100644
--- a/opcodes/s390-dis.c
+++ b/opcodes/s390-dis.c
@@ -65,11 +65,11 @@ disassemble_init_s390 (struct disassemble_info *info)
 
   for (p = info->disassembler_options; p != NULL; )
     {
-      if (CONST_STRNEQ (p, "esa"))
+      if (startswith (p, "esa"))
 	current_arch_mask = 1 << S390_OPCODE_ESA;
-      else if (CONST_STRNEQ (p, "zarch"))
+      else if (startswith (p, "zarch"))
 	current_arch_mask = 1 << S390_OPCODE_ZARCH;
-      else if (CONST_STRNEQ (p, "insnlength"))
+      else if (startswith (p, "insnlength"))
 	option_use_insn_len_bits_p = 1;
       else
 	/* xgettext:c-format */
diff --git a/opcodes/wasm32-dis.c b/opcodes/wasm32-dis.c
index 2fe5132e129..69266610ad3 100644
--- a/opcodes/wasm32-dis.c
+++ b/opcodes/wasm32-dis.c
@@ -120,9 +120,9 @@ parse_wasm32_disassembler_options (struct disassemble_info *info,
 
   while (opts != NULL)
     {
-      if (CONST_STRNEQ (opts, "registers"))
+      if (startswith (opts, "registers"))
         private->print_registers = TRUE;
-      else if (CONST_STRNEQ (opts, "globals"))
+      else if (startswith (opts, "globals"))
         private->print_well_known_globals = TRUE;
 
       opts = strchr (opts, ',');
-- 
2.30.2


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ.
  2021-03-19 12:44     ` [PATCH] Add startswith function and use it instead of CONST_STRNEQ Martin Liška
@ 2021-03-19 17:55       ` Hans-Peter Nilsson
  2021-03-20  7:00       ` Alan Modra
  2021-03-21 13:19       ` Alan Modra
  2 siblings, 0 replies; 41+ messages in thread
From: Hans-Peter Nilsson @ 2021-03-19 17:55 UTC (permalink / raw)
  To: Martin Liška; +Cc: Alan Modra, binutils

On Fri, 19 Mar 2021, Martin Li?ka wrote:
> On 3/19/21 7:37 AM, Alan Modra wrote:
> > On Thu, Mar 18, 2021 at 02:29:26PM -0400, Hans-Peter Nilsson wrote:
> > > How about instead moving and/or making more use of CONST_STRNEQ
> > > from bfd/bfd-in.h?
> >
> > To me the name CONST_STRNEQ just doesn't parse well.  Maybe I'm just
> > weird, but I read it as "constant string not equal"

It's not that? :-)

> > which of course is
> > wrong.  I much prefer startswith as a name.
>
> No, you're not weird! The function name is weird. To be honest, I noticed
> the function, but the name was so misleading that I ignored it.
>
> > bfd-in.h ought to work
> > for an inline startswith too, since every sysdep.h in binutils already
> > includes string.h, and so too does gas/as.h.
>
> Yes, that's a correct location. I tried placing the new function here, but
> I didn't notice 'make headers' :)
>
> Anyway, as a first step I'm suggesting to do the renaming and I can carry on
> with follow up patches that will use the function more.

FWIW, I don't mind; I'm not even the author, as obvious from my
comment.  I just had this hunch that "didn't <name withheld> do
something like this some time ago?  Now where *is* that
whatsitsname macro?"

(Maybe CONST_STREQN?  Nah...  I'm out.)

brgds, H-P

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ.
  2021-03-19 12:44     ` [PATCH] Add startswith function and use it instead of CONST_STRNEQ Martin Liška
  2021-03-19 17:55       ` Hans-Peter Nilsson
@ 2021-03-20  7:00       ` Alan Modra
  2021-03-20 18:58         ` Tom Tromey
  2021-03-21 13:19       ` Alan Modra
  2 siblings, 1 reply; 41+ messages in thread
From: Alan Modra @ 2021-03-20  7:00 UTC (permalink / raw)
  To: Martin Liška; +Cc: binutils, gdb-patches

On Fri, Mar 19, 2021 at 01:44:38PM +0100, Martin Liška wrote:
> @@ -73,6 +64,13 @@ extern "C" {
>  #define LITMEMCPY(DEST,STR2) memcpy ((DEST), (STR2), sizeof (STR2) - 1)
>  #define LITSTRCPY(DEST,STR2) memcpy ((DEST), (STR2), sizeof (STR2))
>  
> +/* Return 1 if STR string starts with PREFIX.  */
> +
> +static inline int
> +startswith (const char *str, const char *prefix)
> +{
> +  return __builtin_strncmp (str, prefix, __builtin_strlen (prefix)) == 0;
> +}
>  
>  #define BFD_SUPPORTS_PLUGINS @supports_plugins@
>  

In binutils, we haven't yet made a policy that the project requires
gcc, so builtins can't be used without a fallback.  I tried building
with the following but it runs into a compilation failure in gdb.  I
expect your patch would do the same..

In file included from /home/alan/src/binutils-gdb/gdb/defs.h:37,
                 from /home/alan/src/binutils-gdb/gdb/gdb.c:19:
../bfd/bfd.h:85:1: error: ambiguating new declaration of ‘int startswith(const char*, const char*)’
 startswith (const char *str, const char *prefix)
 ^~~~~~~~~~
In file included from /home/alan/src/binutils-gdb/gdb/../gdbsupport/common-defs.h:125,
                 from /home/alan/src/binutils-gdb/gdb/defs.h:28,
                 from /home/alan/src/binutils-gdb/gdb/gdb.c:19:
/home/alan/src/binutils-gdb/gdb/../gdbsupport/common-utils.h:122:1: note: old declaration ‘bool startswith(const char*, const char*)’
 startswith (const char *string, const char *pattern)
 ^~~~~~~~~~

Forcing gdb to remove their startswith is a bit rude.  Should I use
#ifndef __cplusplus or #ifndef gdb_assert around the bfd version?


bfd/
	* bfd-in.h (startswith): New inline.
	(CONST_STRNEQ): Use startswith.
	* bfd-in2.h: Regenerate.
libctf/
	* ctf-impl.h: Include string.h.

diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h
index c9a7673147..4d99c21d3e 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -65,7 +65,6 @@ extern "C" {
    definition of strncmp is provided here.
 
    Note - these macros do NOT work if STR2 is not a constant string.  */
-#define CONST_STRNEQ(STR1,STR2) (strncmp ((STR1), (STR2), sizeof (STR2) - 1) == 0)
   /* strcpy() can have a similar problem, but since we know we are
      copying a constant string, we can use memcpy which will be faster
      since there is no need to check for a NUL byte inside STR.  We
@@ -73,6 +72,15 @@ extern "C" {
 #define LITMEMCPY(DEST,STR2) memcpy ((DEST), (STR2), sizeof (STR2) - 1)
 #define LITSTRCPY(DEST,STR2) memcpy ((DEST), (STR2), sizeof (STR2))
 
+/* Return 1 if STR string starts with PREFIX.  */
+
+static inline int
+startswith (const char *str, const char *prefix)
+{
+  return strncmp (str, prefix, strlen (prefix)) == 0;
+}
+#define CONST_STRNEQ(STR1,STR2) startswith (STR1, STR2)
+
 
 #define BFD_SUPPORTS_PLUGINS @supports_plugins@
 
diff --git a/libctf/ctf-impl.h b/libctf/ctf-impl.h
index ad4af32e7e..342d2ff23e 100644
--- a/libctf/ctf-impl.h
+++ b/libctf/ctf-impl.h
@@ -32,6 +32,7 @@
 #include <stddef.h>
 #include <stdio.h>
 #include <stdint.h>
+#include <string.h>
 #include <limits.h>
 #include <ctype.h>
 #include <elf.h>


-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ.
  2021-03-20  7:00       ` Alan Modra
@ 2021-03-20 18:58         ` Tom Tromey
  2021-03-21 13:12           ` Alan Modra
  0 siblings, 1 reply; 41+ messages in thread
From: Tom Tromey @ 2021-03-20 18:58 UTC (permalink / raw)
  To: Alan Modra via Binutils; +Cc: Martin Liška, Alan Modra, gdb-patches

>>>>> "Alan" == Alan Modra via Binutils <binutils@sourceware.org> writes:

Alan> Forcing gdb to remove their startswith is a bit rude.

FWIW I think it would be fine, assuming it compiles, considering that
the functions have identical intended semantics.

Tom

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ.
  2021-03-20 18:58         ` Tom Tromey
@ 2021-03-21 13:12           ` Alan Modra
  2021-03-22  2:13             ` Tom Tromey
  2021-03-22  6:57             ` Mike Frysinger
  0 siblings, 2 replies; 41+ messages in thread
From: Alan Modra @ 2021-03-21 13:12 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Alan Modra via Binutils, Martin Liška, gdb-patches

On Sat, Mar 20, 2021 at 12:58:10PM -0600, Tom Tromey wrote:
> >>>>> "Alan" == Alan Modra via Binutils <binutils@sourceware.org> writes:
> 
> Alan> Forcing gdb to remove their startswith is a bit rude.
> 
> FWIW I think it would be fine, assuming it compiles, considering that
> the functions have identical intended semantics.

Yes, the following compiles.  Fortunately all gdb files that include
gdbsupport/common-utils.h also include bfd.h by one means or another.

Committed.

bfd/
	* bfd-in.h (startswith): New inline.
	(CONST_STRNEQ): Use startswith.
	* bfd-in2.h: Regenerate.
gdbsupport/
	* common-utils.h (startswith): Delete version now supplied by bfd.h.
libctf/
	* ctf-impl.h: Include string.h.

diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h
index c9a7673147..453ac48e26 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -65,7 +65,6 @@ extern "C" {
    definition of strncmp is provided here.
 
    Note - these macros do NOT work if STR2 is not a constant string.  */
-#define CONST_STRNEQ(STR1,STR2) (strncmp ((STR1), (STR2), sizeof (STR2) - 1) == 0)
   /* strcpy() can have a similar problem, but since we know we are
      copying a constant string, we can use memcpy which will be faster
      since there is no need to check for a NUL byte inside STR.  We
@@ -564,3 +563,12 @@ struct ecoff_debug_swap;
 struct ecoff_extr;
 struct bfd_link_info;
 struct bfd_link_hash_entry;
+
+/* Return TRUE if the start of STR matches PREFIX, FALSE otherwise.  */
+
+static inline bfd_boolean
+startswith (const char *str, const char *prefix)
+{
+  return strncmp (str, prefix, strlen (prefix)) == 0;
+}
+#define CONST_STRNEQ(STR1,STR2) startswith (STR1, STR2)
diff --git a/gdbsupport/common-utils.h b/gdbsupport/common-utils.h
index 28c08ee976..1de747f186 100644
--- a/gdbsupport/common-utils.h
+++ b/gdbsupport/common-utils.h
@@ -116,16 +116,8 @@ std::string extract_string_maybe_quoted (const char **arg);
 
 extern const char *safe_strerror (int);
 
-/* Return true if the start of STRING matches PATTERN, false otherwise.  */
-
-static inline bool
-startswith (const char *string, const char *pattern)
-{
-  return strncmp (string, pattern, strlen (pattern)) == 0;
-}
-
-/* Version of startswith that takes string_view arguments.  See comment
-   above.  */
+/* Version of startswith that takes string_view arguments.  Return
+   true if the start of STRING matches PATTERN, false otherwise.  */
 
 static inline bool
 startswith (gdb::string_view string, gdb::string_view pattern)
diff --git a/libctf/ctf-impl.h b/libctf/ctf-impl.h
index ad4af32e7e..342d2ff23e 100644
--- a/libctf/ctf-impl.h
+++ b/libctf/ctf-impl.h
@@ -32,6 +32,7 @@
 #include <stddef.h>
 #include <stdio.h>
 #include <stdint.h>
+#include <string.h>
 #include <limits.h>
 #include <ctype.h>
 #include <elf.h>

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ.
  2021-03-19 12:44     ` [PATCH] Add startswith function and use it instead of CONST_STRNEQ Martin Liška
  2021-03-19 17:55       ` Hans-Peter Nilsson
  2021-03-20  7:00       ` Alan Modra
@ 2021-03-21 13:19       ` Alan Modra
  2021-03-22 10:04         ` Martin Liška
  2 siblings, 1 reply; 41+ messages in thread
From: Alan Modra @ 2021-03-21 13:19 UTC (permalink / raw)
  To: Martin Liška; +Cc: binutils

On Fri, Mar 19, 2021 at 01:44:38PM +0100, Martin Liška wrote:
> 	* (all locations): Replace usage of CONST_STRNEQ with
> 	startswith.

This is OK now that the gdb clash is sorted out.  I guess you should
really mention each file changed in ChangeLogs though.  Thanks!

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ.
  2021-03-21 13:12           ` Alan Modra
@ 2021-03-22  2:13             ` Tom Tromey
  2021-03-22 12:06               ` Alan Modra
  2021-03-22  6:57             ` Mike Frysinger
  1 sibling, 1 reply; 41+ messages in thread
From: Tom Tromey @ 2021-03-22  2:13 UTC (permalink / raw)
  To: Alan Modra
  Cc: Tom Tromey, Alan Modra via Binutils, Martin Liška, gdb-patches

Alan> Yes, the following compiles.  Fortunately all gdb files that include
Alan> gdbsupport/common-utils.h also include bfd.h by one means or another.

Sorry, I misunderstood.  I thought the proposal was to put the
function in ansidecl.h.

gdbserver can't generally include bfd.  Maybe it works sometimes, but I
imagine if you do a gdbserver-only build, bfd.h won't even be created.
(At least, it shouldn't be, because gdbserver doesn't require bfd.)

So I think some other approach is needed.  Either ansidecl.h, or a new
header; or rename either the BFD or GDB function and go from there.

I'm happy to implement it if you like.

thanks,
Tom

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ.
  2021-03-21 13:12           ` Alan Modra
  2021-03-22  2:13             ` Tom Tromey
@ 2021-03-22  6:57             ` Mike Frysinger
  1 sibling, 0 replies; 41+ messages in thread
From: Mike Frysinger @ 2021-03-22  6:57 UTC (permalink / raw)
  To: Alan Modra; +Cc: Tom Tromey, Alan Modra via Binutils, gdb-patches

On 21 Mar 2021 23:42, Alan Modra via Binutils wrote:
> On Sat, Mar 20, 2021 at 12:58:10PM -0600, Tom Tromey wrote:
> > >>>>> "Alan" == Alan Modra via Binutils <binutils@sourceware.org> writes:
> > 
> > Alan> Forcing gdb to remove their startswith is a bit rude.
> > 
> > FWIW I think it would be fine, assuming it compiles, considering that
> > the functions have identical intended semantics.
> 
> Yes, the following compiles.  Fortunately all gdb files that include
> gdbsupport/common-utils.h also include bfd.h by one means or another.
> 
> Committed.
> 
> bfd/
> 	* bfd-in.h (startswith): New inline.
> 	(CONST_STRNEQ): Use startswith.
> 	* bfd-in2.h: Regenerate.
> gdbsupport/
> 	* common-utils.h (startswith): Delete version now supplied by bfd.h.
> libctf/
> 	* ctf-impl.h: Include string.h.

putting this in the exported header is problematic.  as you see with the libctf
code, anyone including bfd.h now has to make sure string.h is included first
even if they don't use the header themselves.  this is generally considered bad
form for headers.

along those lines, a bunch of sim ports are broken now as they include bfd.h
but not all happen to include string.h first.
-mike

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ.
  2021-03-21 13:19       ` Alan Modra
@ 2021-03-22 10:04         ` Martin Liška
  0 siblings, 0 replies; 41+ messages in thread
From: Martin Liška @ 2021-03-22 10:04 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

On 3/21/21 2:19 PM, Alan Modra wrote:
> On Fri, Mar 19, 2021 at 01:44:38PM +0100, Martin Liška wrote:
>> 	* (all locations): Replace usage of CONST_STRNEQ with
>> 	startswith.
> 
> This is OK now that the gdb clash is sorted out.  I guess you should
> really mention each file changed in ChangeLogs though.  Thanks!
> 

I've just done that and pushed as 08dedd6631efefbcba63c4dbf60ef97fb615e022.
Thanks for review.

Now I'm going to transform all the strncmp constructs that can use startswith
function.

Martin

^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH 1/5] Replace const_strneq with startswith.
  2021-03-24  8:19                     ` [PATCH 0/5] Start using startswith instead of strncmp Martin Liska
  2021-03-18 14:16                       ` [PATCH 2/5] Use startswith more for strncmp function calls Martin Liska
@ 2021-03-22 11:12                       ` Martin Liska
  2021-03-22 12:33                       ` [PATCH 3/5] Use startswith in gas subfolder Martin Liska
                                         ` (3 subsequent siblings)
  5 siblings, 0 replies; 41+ messages in thread
From: Martin Liska @ 2021-03-22 11:12 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 694 bytes --]


binutils/ChangeLog:

	* dwarf.c (display_debug_lines_raw): Replace const_strneq with
	startswith.
	(display_debug_lines_decoded): Likewise.
	(display_debug_links): Likewise.
	* elfcomm.c (setup_archive): Likewise.
	* elfcomm.h (const_strneq): Likewise.
	* readelf.c (process_section_headers): Likewise.
	(slurp_ia64_unwind_table): Likewise.
	(slurp_hppa_unwind_table): Likewise.
	(decode_arm_unwind): Likewise.
	(display_debug_section): Likewise.
	(process_note): Likewise.
---
 binutils/dwarf.c   |   8 ++--
 binutils/elfcomm.c |   7 ++--
 binutils/elfcomm.h |   1 -
 binutils/readelf.c | 102 ++++++++++++++++++++++-----------------------
 4 files changed, 59 insertions(+), 59 deletions(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Replace-const_strneq-with-startswith.patch --]
[-- Type: text/x-patch; name="0001-Replace-const_strneq-with-startswith.patch", Size: 14365 bytes --]

diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index 74f28f563ce..7ab4785b4a6 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -4500,7 +4500,7 @@ display_debug_lines_raw (struct dwarf_section *  section,
       unsigned char *end_of_sequence;
       int i;
 
-      if (const_strneq (section->name, ".debug_line.")
+      if (startswith (section->name, ".debug_line.")
 	  /* Note: the following does not apply to .debug_line.dwo sections.
 	     These are full debug_line sections.  */
 	  && strcmp (section->name, ".debug_line.dwo") != 0)
@@ -4924,7 +4924,7 @@ display_debug_lines_decoded (struct dwarf_section *  section,
       unsigned char **directory_table = NULL;
       dwarf_vma n_directories = 0;
 
-      if (const_strneq (section->name, ".debug_line.")
+      if (startswith (section->name, ".debug_line.")
 	  /* Note: the following does not apply to .debug_line.dwo sections.
 	     These are full debug_line sections.  */
 	  && strcmp (section->name, ".debug_line.dwo") != 0)
@@ -10031,7 +10031,7 @@ display_debug_links (struct dwarf_section *  section,
 
   printf (_("  Separate debug info file: %s\n"), filename);
 
-  if (const_strneq (section->name, ".gnu_debuglink"))
+  if (startswith (section->name, ".gnu_debuglink"))
     {
       unsigned int          crc32;
       unsigned int          crc_offset;
@@ -10055,7 +10055,7 @@ display_debug_links (struct dwarf_section *  section,
 	  return 0;
 	}
     }
-  else /* const_strneq (section->name, ".gnu_debugaltlink") */
+  else /* startswith (section->name, ".gnu_debugaltlink") */
     {
       const unsigned char * build_id = section->start + filelen + 1;
       bfd_size_type         build_id_len = section->size - (filelen + 1);
diff --git a/binutils/elfcomm.c b/binutils/elfcomm.c
index 5cf4c24360e..c5092c64377 100644
--- a/binutils/elfcomm.c
+++ b/binutils/elfcomm.c
@@ -27,6 +27,7 @@
 
 #include "sysdep.h"
 #include "libiberty.h"
+#include "bfd.h"
 #include "filenames.h"
 #include "aout/ar.h"
 #include "elfcomm.h"
@@ -611,12 +612,12 @@ setup_archive (struct archive_info *arch, const char *file_name,
     }
 
   /* See if this is the archive symbol table.  */
-  if (const_strneq (arch->arhdr.ar_name, "/               "))
+  if (startswith (arch->arhdr.ar_name, "/               "))
     {
       if (! process_archive_index_and_symbols (arch, 4, read_symbols))
 	return 1;
     }
-  else if (const_strneq (arch->arhdr.ar_name, "/SYM64/         "))
+  else if (startswith (arch->arhdr.ar_name, "/SYM64/         "))
     {
       arch->uses_64bit_indices = 1;
       if (! process_archive_index_and_symbols (arch, 8, read_symbols))
@@ -625,7 +626,7 @@ setup_archive (struct archive_info *arch, const char *file_name,
   else if (read_symbols)
     printf (_("%s has no archive index\n"), file_name);
 
-  if (const_strneq (arch->arhdr.ar_name, "//              "))
+  if (startswith (arch->arhdr.ar_name, "//              "))
     {
       /* This is the archive string table holding long member names.  */
       char fmag_save = arch->arhdr.ar_fmag[0];
diff --git a/binutils/elfcomm.h b/binutils/elfcomm.h
index 9754ce1ca09..04e909c2da3 100644
--- a/binutils/elfcomm.h
+++ b/binutils/elfcomm.h
@@ -48,7 +48,6 @@ extern void byte_get_64 (const unsigned char *, elf_vma *, elf_vma *);
 /* This is just a bit of syntatic sugar.  */
 #define streq(a,b)	  (strcmp ((a), (b)) == 0)
 #define strneq(a,b,n)	  (strncmp ((a), (b), (n)) == 0)
-#define const_strneq(a,b) (strncmp ((a), (b), sizeof (b) - 1) == 0)
 
 /* Structure to hold information about an archive file.  */
 
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 7370aa9358a..f638b77e146 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -6589,8 +6589,8 @@ process_section_headers (Filedata * filedata)
 	   || do_debug_str || do_debug_str_offsets || do_debug_loc
 	   || do_debug_ranges
 	   || do_debug_addr || do_debug_cu_index || do_debug_links)
-	  && (const_strneq (name, ".debug_")
-	      || const_strneq (name, ".zdebug_")))
+	  && (startswith (name, ".debug_")
+	      || startswith (name, ".zdebug_")))
 	{
           if (name[1] == 'z')
             name += sizeof (".zdebug_") - 1;
@@ -6598,35 +6598,35 @@ process_section_headers (Filedata * filedata)
             name += sizeof (".debug_") - 1;
 
 	  if (do_debugging
-	      || (do_debug_info     && const_strneq (name, "info"))
-	      || (do_debug_info     && const_strneq (name, "types"))
-	      || (do_debug_abbrevs  && const_strneq (name, "abbrev"))
+	      || (do_debug_info     && startswith (name, "info"))
+	      || (do_debug_info     && startswith (name, "types"))
+	      || (do_debug_abbrevs  && startswith (name, "abbrev"))
 	      || (do_debug_lines    && strcmp (name, "line") == 0)
-	      || (do_debug_lines    && const_strneq (name, "line."))
-	      || (do_debug_pubnames && const_strneq (name, "pubnames"))
-	      || (do_debug_pubtypes && const_strneq (name, "pubtypes"))
-	      || (do_debug_pubnames && const_strneq (name, "gnu_pubnames"))
-	      || (do_debug_pubtypes && const_strneq (name, "gnu_pubtypes"))
-	      || (do_debug_aranges  && const_strneq (name, "aranges"))
-	      || (do_debug_ranges   && const_strneq (name, "ranges"))
-	      || (do_debug_ranges   && const_strneq (name, "rnglists"))
-	      || (do_debug_frames   && const_strneq (name, "frame"))
-	      || (do_debug_macinfo  && const_strneq (name, "macinfo"))
-	      || (do_debug_macinfo  && const_strneq (name, "macro"))
-	      || (do_debug_str      && const_strneq (name, "str"))
-	      || (do_debug_links    && const_strneq (name, "sup"))
-	      || (do_debug_str_offsets && const_strneq (name, "str_offsets"))
-	      || (do_debug_loc      && const_strneq (name, "loc"))
-	      || (do_debug_loc      && const_strneq (name, "loclists"))
-	      || (do_debug_addr     && const_strneq (name, "addr"))
-	      || (do_debug_cu_index && const_strneq (name, "cu_index"))
-	      || (do_debug_cu_index && const_strneq (name, "tu_index"))
+	      || (do_debug_lines    && startswith (name, "line."))
+	      || (do_debug_pubnames && startswith (name, "pubnames"))
+	      || (do_debug_pubtypes && startswith (name, "pubtypes"))
+	      || (do_debug_pubnames && startswith (name, "gnu_pubnames"))
+	      || (do_debug_pubtypes && startswith (name, "gnu_pubtypes"))
+	      || (do_debug_aranges  && startswith (name, "aranges"))
+	      || (do_debug_ranges   && startswith (name, "ranges"))
+	      || (do_debug_ranges   && startswith (name, "rnglists"))
+	      || (do_debug_frames   && startswith (name, "frame"))
+	      || (do_debug_macinfo  && startswith (name, "macinfo"))
+	      || (do_debug_macinfo  && startswith (name, "macro"))
+	      || (do_debug_str      && startswith (name, "str"))
+	      || (do_debug_links    && startswith (name, "sup"))
+	      || (do_debug_str_offsets && startswith (name, "str_offsets"))
+	      || (do_debug_loc      && startswith (name, "loc"))
+	      || (do_debug_loc      && startswith (name, "loclists"))
+	      || (do_debug_addr     && startswith (name, "addr"))
+	      || (do_debug_cu_index && startswith (name, "cu_index"))
+	      || (do_debug_cu_index && startswith (name, "tu_index"))
 	      )
 	    request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
 	}
       /* Linkonce section to be combined with .debug_info at link time.  */
       else if ((do_debugging || do_debug_info)
-	       && const_strneq (name, ".gnu.linkonce.wi."))
+	       && startswith (name, ".gnu.linkonce.wi."))
 	request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
       else if (do_debug_frames && streq (name, ".eh_frame"))
 	request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
@@ -6636,7 +6636,7 @@ process_section_headers (Filedata * filedata)
       /* Trace sections for Itanium VMS.  */
       else if ((do_debugging || do_trace_info || do_trace_abbrevs
                 || do_trace_aranges)
-	       && const_strneq (name, ".trace_"))
+	       && startswith (name, ".trace_"))
 	{
           name += sizeof (".trace_") - 1;
 
@@ -6648,8 +6648,8 @@ process_section_headers (Filedata * filedata)
 	    request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
 	}
       else if ((do_debugging || do_debug_links)
-	       && (const_strneq (name, ".gnu_debuglink")
-		   || const_strneq (name, ".gnu_debugaltlink")))
+	       && (startswith (name, ".gnu_debuglink")
+		   || startswith (name, ".gnu_debugaltlink")))
 	request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
     }
 
@@ -8107,7 +8107,7 @@ slurp_ia64_unwind_table (Filedata *                  filedata,
 	      continue;
 	    }
 
-	  if (! const_strneq (relname, "R_IA64_SEGREL"))
+	  if (! startswith (relname, "R_IA64_SEGREL"))
 	    {
 	      warn (_("Skipping unexpected relocation type: %s\n"), relname);
 	      continue;
@@ -8574,7 +8574,7 @@ slurp_hppa_unwind_table (Filedata *                  filedata,
 	    }
 
 	  /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64.  */
-	  if (! const_strneq (relname, "R_PARISC_SEGREL"))
+	  if (! startswith (relname, "R_PARISC_SEGREL"))
 	    {
 	      warn (_("Skipping unexpected relocation type: %s\n"), relname);
 	      continue;
@@ -9476,10 +9476,10 @@ decode_arm_unwind (Filedata *                 filedata,
 	 encoding, starting with one byte giving the number of
 	 words.  */
       if (procname != NULL
-	  && (const_strneq (procname, "__gcc_personality_v0")
-	      || const_strneq (procname, "__gxx_personality_v0")
-	      || const_strneq (procname, "__gcj_personality_v0")
-	      || const_strneq (procname, "__gnu_objc_personality_v0")))
+	  && (startswith (procname, "__gcc_personality_v0")
+	      || startswith (procname, "__gxx_personality_v0")
+	      || startswith (procname, "__gcj_personality_v0")
+	      || startswith (procname, "__gnu_objc_personality_v0")))
 	{
 	  remaining = 0;
 	  more_words = 1;
@@ -15298,7 +15298,7 @@ malformed note encountered in section %s whilst scanning for build-id note\n"),
       /* Check if this is the build-id note. If so then convert the build-id
          bytes to a hex string.  */
       if (inote.namesz > 0
-          && const_strneq (inote.namedata, "GNU")
+          && startswith (inote.namedata, "GNU")
           && inote.type == NT_GNU_BUILD_ID)
         {
           unsigned long j;
@@ -15426,7 +15426,7 @@ display_debug_section (int shndx, Elf_Internal_Shdr * section, Filedata * fileda
       return FALSE;
     }
 
-  if (const_strneq (name, ".gnu.linkonce.wi."))
+  if (startswith (name, ".gnu.linkonce.wi."))
     name = ".debug_info";
 
   /* See if we know how to display the contents of this section.  */
@@ -15437,7 +15437,7 @@ display_debug_section (int shndx, Elf_Internal_Shdr * section, Filedata * fileda
       struct dwarf_section *           sec = & display->section;
 
       if (streq (sec->uncompressed_name, name)
-	  || (id == line && const_strneq (name, ".debug_line."))
+	  || (id == line && startswith (name, ".debug_line."))
 	  || streq (sec->compressed_name, name))
 	{
 	  bfd_boolean secondary = (section != find_section (filedata, name));
@@ -15445,7 +15445,7 @@ display_debug_section (int shndx, Elf_Internal_Shdr * section, Filedata * fileda
 	  if (secondary)
 	    free_debug_section (id);
 
-	  if (i == line && const_strneq (name, ".debug_line."))
+	  if (i == line && startswith (name, ".debug_line."))
 	    sec->name = name;
 	  else if (streq (sec->uncompressed_name, name))
 	    sec->name = sec->uncompressed_name;
@@ -20430,23 +20430,23 @@ process_note (Elf_Internal_Note *  pnote,
        note type strings.  */
     nt = get_note_type (filedata, pnote->type);
 
-  else if (const_strneq (pnote->namedata, "GNU"))
+  else if (startswith (pnote->namedata, "GNU"))
     /* GNU-specific object file notes.  */
     nt = get_gnu_elf_note_type (pnote->type);
 
-  else if (const_strneq (pnote->namedata, "FreeBSD"))
+  else if (startswith (pnote->namedata, "FreeBSD"))
     /* FreeBSD-specific core file notes.  */
     nt = get_freebsd_elfcore_note_type (filedata, pnote->type);
 
-  else if (const_strneq (pnote->namedata, "NetBSD-CORE"))
+  else if (startswith (pnote->namedata, "NetBSD-CORE"))
     /* NetBSD-specific core file notes.  */
     nt = get_netbsd_elfcore_note_type (filedata, pnote->type);
 
-  else if (const_strneq (pnote->namedata, "NetBSD"))
+  else if (startswith (pnote->namedata, "NetBSD"))
     /* NetBSD-specific core file notes.  */
     return process_netbsd_elf_note (pnote);
 
-  else if (const_strneq (pnote->namedata, "PaX"))
+  else if (startswith (pnote->namedata, "PaX"))
     /* NetBSD-specific core file notes.  */
     return process_netbsd_elf_note (pnote);
 
@@ -20457,11 +20457,11 @@ process_note (Elf_Internal_Note *  pnote,
       name = "SPU";
     }
 
-  else if (const_strneq (pnote->namedata, "IPF/VMS"))
+  else if (startswith (pnote->namedata, "IPF/VMS"))
     /* VMS/ia64-specific file notes.  */
     nt = get_ia64_vms_note_type (pnote->type);
 
-  else if (const_strneq (pnote->namedata, "stapsdt"))
+  else if (startswith (pnote->namedata, "stapsdt"))
     nt = get_stapsdt_note_type (pnote->type);
 
   else
@@ -20471,7 +20471,7 @@ process_note (Elf_Internal_Note *  pnote,
 
   printf ("  ");
 
-  if (((const_strneq (pnote->namedata, "GA")
+  if (((startswith (pnote->namedata, "GA")
 	&& strchr ("*$!+", pnote->namedata[2]) != NULL)
        || strchr ("*$!+", pnote->namedata[0]) != NULL)
       && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN
@@ -20485,15 +20485,15 @@ process_note (Elf_Internal_Note *  pnote,
   else
     printf (" 0x%08lx\t%s\n", pnote->descsz, nt);
 
-  if (const_strneq (pnote->namedata, "IPF/VMS"))
+  if (startswith (pnote->namedata, "IPF/VMS"))
     return print_ia64_vms_note (pnote);
-  else if (const_strneq (pnote->namedata, "GNU"))
+  else if (startswith (pnote->namedata, "GNU"))
     return print_gnu_note (filedata, pnote);
-  else if (const_strneq (pnote->namedata, "stapsdt"))
+  else if (startswith (pnote->namedata, "stapsdt"))
     return print_stapsdt_note (pnote);
-  else if (const_strneq (pnote->namedata, "CORE"))
+  else if (startswith (pnote->namedata, "CORE"))
     return print_core_note (pnote);
-  else if (((const_strneq (pnote->namedata, "GA")
+  else if (((startswith (pnote->namedata, "GA")
 	     && strchr ("*$!+", pnote->namedata[2]) != NULL)
 	    || strchr ("*$!+", pnote->namedata[0]) != NULL)
 	   && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ.
  2021-03-22  2:13             ` Tom Tromey
@ 2021-03-22 12:06               ` Alan Modra
  2021-03-22 16:13                 ` Luis Machado
  2021-03-22 16:42                 ` Martin Liška
  0 siblings, 2 replies; 41+ messages in thread
From: Alan Modra @ 2021-03-22 12:06 UTC (permalink / raw)
  To: Tom Tromey, Mike Frysinger
  Cc: Alan Modra via Binutils, Martin Liška, gdb-patches

On Sun, Mar 21, 2021 at 08:13:06PM -0600, Tom Tromey wrote:
> Alan> Yes, the following compiles.  Fortunately all gdb files that include
> Alan> gdbsupport/common-utils.h also include bfd.h by one means or another.
> 
> Sorry, I misunderstood.  I thought the proposal was to put the
> function in ansidecl.h.
> 
> gdbserver can't generally include bfd.  Maybe it works sometimes, but I
> imagine if you do a gdbserver-only build, bfd.h won't even be created.
> (At least, it shouldn't be, because gdbserver doesn't require bfd.)
> 
> So I think some other approach is needed.  Either ansidecl.h, or a new
> header; or rename either the BFD or GDB function and go from there.

A new header would be best, I think.

> I'm happy to implement it if you like.

Yes, that way you'll get it done properly.  :)  Sorry for the breakage.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH 3/5] Use startswith in gas subfolder.
  2021-03-24  8:19                     ` [PATCH 0/5] Start using startswith instead of strncmp Martin Liska
  2021-03-18 14:16                       ` [PATCH 2/5] Use startswith more for strncmp function calls Martin Liska
  2021-03-22 11:12                       ` [PATCH 1/5] Replace const_strneq with startswith Martin Liska
@ 2021-03-22 12:33                       ` Martin Liska
  2021-03-22 13:56                       ` [PATCH 4/5] Remove strneq macro and use startswith Martin Liska
                                         ` (2 subsequent siblings)
  5 siblings, 0 replies; 41+ messages in thread
From: Martin Liska @ 2021-03-22 12:33 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 7646 bytes --]


gas/ChangeLog:

	* as.c (select_emulation_mode): Use startswith.
	* config/m68k-parse.y: Likewise.
	* config/obj-aout.c (obj_aout_type): Likewise.
	* config/obj-elf.c (elf_common_parse): Likewise.
	(obj_elf_section_type): Likewise.
	(obj_elf_section_word): Likewise.
	(obj_elf_section): Likewise.
	(obj_elf_symver): Likewise.
	(adjust_stab_sections): Likewise.
	* config/obj-evax.c (evax_shorten_name): Likewise.
	* config/obj-macho.c (obj_mach_o_is_frame_section): Likewise.
	* config/tc-aarch64.c (parse_aarch64_imm_float): Likewise.
	(aarch64_parse_features): Likewise.
	(create_register_alias): Likewise.
	(aarch64_data_in_code): Likewise.
	(md_parse_option): Likewise.
	* config/tc-alpha.c (s_alpha_section_word): Likewise.
	(s_alpha_pdesc): Likewise.
	* config/tc-arc.c (tokenize_extregister): Likewise.
	* config/tc-arm.c (create_register_alias): Likewise.
	(create_neon_reg_alias): Likewise.
	(parse_ifimm_zero): Likewise.
	(parse_qfloat_immediate): Likewise.
	(arm_elf_section_type): Likewise.
	(arm_parse_extension): Likewise.
	(aeabi_set_public_attributes): Likewise.
	(s_arm_arch_extension): Likewise.
	(arm_data_in_code): Likewise.
	(start_unwind_section): Likewise.
	* config/tc-avr.c (avr_ldi_expression): Likewise.
	* config/tc-csky.c (is_freglist_legal): Likewise.
	(csky_s_section): Likewise.
	* config/tc-d30v.c (do_assemble): Likewise.
	* config/tc-dlx.c (parse_operand): Likewise.
	* config/tc-epiphany.c (md_assemble): Likewise.
	* config/tc-h8300.c (h8300_elf_section): Likewise.
	(get_operand): Likewise.
	* config/tc-hppa.c (pa_ip): Likewise.
	(pa_level): Likewise.
	(pa_space): Likewise.
	* config/tc-i386.c (i386_mach): Likewise.
	(md_assemble): Likewise.
	(check_VecOperations): Likewise.
	(i386_target_format): Likewise.
	(i386_elf_section_type): Likewise.
	* config/tc-ia64.c (start_unwind_section): Likewise.
	(md_parse_option): Likewise.
	(is_taken_branch): Likewise.
	(idesc->name,): Likewise.
	(note_register_values): Likewise.
	(do_alias): Likewise.
	* config/tc-m32c.c (insn_to_subtype): Likewise.
	* config/tc-m68hc11.c (get_operand): Likewise.
	(md_assemble): Likewise.
	* config/tc-m68k.c (m68k_ip): Likewise.
	(m68k_elf_suffix): Likewise.
	* config/tc-mcore.c (mcore_s_section): Likewise.
	* config/tc-metag.c (parse_get_set): Likewise.
	(md_parse_option): Likewise.
	* config/tc-microblaze.c (parse_imm): Likewise.
	(check_got): Likewise.
	(md_apply_fix): Likewise.
	* config/tc-mips.c (CPU_HAS_MIPS16): Likewise.
	(md_begin): Likewise.
	(s_is_linkonce): Likewise.
	(check_regno): Likewise.
	(match_float_constant): Likewise.
	(classify_vr4120_insn): Likewise.
	(match_insn): Likewise.
	(mips_after_parse_args): Likewise.
	(s_change_sec): Likewise.
	(s_option): Likewise.
	(parse_code_option): Likewise.
	(md_section_align): Likewise.
	(nopic_need_relax): Likewise.
	* config/tc-mmix.c (mmix_handle_mmixal): Likewise.
	* config/tc-mn10300.c (mn10300_fix_adjustable): Likewise.
	(mn10300_end_of_match): Likewise.
	* config/tc-msp430.c (msp430_make_init_symbols): Likewise.
	* config/tc-nds32.c (nds32_parse_option): Likewise.
	* config/tc-nds32.h (md_do_align): Likewise.
	* config/tc-nios2.c (strprefix): Likewise.
	(nios2_special_relocation_p): Likewise.
	(nios2_parse_base_register): Likewise.
	(nios2_cons): Likewise.
	* config/tc-ns32k.c (addr_mode): Likewise.
	* config/tc-pdp11.c (set_option): Likewise.
	(parse_reg): Likewise.
	(parse_ac5): Likewise.
	(parse_op_no_deferred): Likewise.
	(set_cpu_model): Likewise.
	(set_machine_model): Likewise.
	* config/tc-pj.c (md_operand): Likewise.
	* config/tc-ppc.c (ppc_set_cpu): Likewise.
	(ppc_arch): Likewise.
	(ppc_section_type): Likewise.
	* config/tc-s12z.c (tb_reg_rel): Likewise.
	(tb_opr_rel): Likewise.
	* config/tc-s390.c (s390_parse_cpu): Likewise.
	(md_parse_option): Likewise.
	* config/tc-score.c (s3_nopic_need_relax): Likewise.
	(s3_pic_need_relax): Likewise.
	* config/tc-score7.c (s7_nopic_need_relax): Likewise.
	(s7_pic_need_relax): Likewise.
	* config/tc-sh.h (SUB_SEGMENT_ALIGN): Likewise.
	* config/tc-sparc.c (md_parse_option): Likewise.
	(sparc_ip): Likewise.
	(s_reserve): Likewise.
	(s_common): Likewise.
	(s_seg): Likewise.
	(sparc_cons): Likewise.
	* config/tc-tic54x.c (stag_add_field): Likewise.
	(tic54x_endstruct): Likewise.
	* config/tc-tic6x.c (tic6x_start_unwind_section): Likewise.
	* config/tc-v850.c (v850_comm): Likewise.
	(md_begin): Likewise.
	(md_assemble): Likewise.
	* config/tc-vax.c (vax_cons): Likewise.
	* config/tc-wasm32.c (wasm32_leb128): Likewise.
	* config/tc-xstormy16.c (md_operand): Likewise.
	* config/tc-xtensa.c (get_directive): Likewise.
	(xg_instruction_matches_option_term): Likewise.
	(is_unaligned_label): Likewise.
	(cache_literal_section): Likewise.
	* config/xtensa-relax.c (parse_precond): Likewise.
	(parse_option_cond): Likewise.
	(transition_applies): Likewise.
	(wide_branch_opcode): Likewise.
	* dw2gencfi.c: Likewise.
	* dwarf2dbg.c (dwarf2_directive_filename): Likewise.
	* ehopt.c (get_cie_info): Likewise.
	* input-file.c (input_file_open): Likewise.
	* listing.c (listing_newline): Likewise.
	(debugging_pseudo): Likewise.
	* read.c (read_a_source_file): Likewise.
	* write.c (adjust_reloc_syms): Likewise.
	(compress_debug): Likewise.
	(maybe_generate_build_notes): Likewise.
---
 gas/as.c                   |  5 +--
 gas/config/m68k-parse.y    | 18 ++++-----
 gas/config/obj-aout.c      |  4 +-
 gas/config/obj-elf.c       | 40 +++++++++----------
 gas/config/obj-evax.c      |  2 +-
 gas/config/obj-macho.c     |  4 +-
 gas/config/tc-aarch64.c    | 11 +++--
 gas/config/tc-alpha.c      | 30 +++++++-------
 gas/config/tc-arc.c        | 10 ++---
 gas/config/tc-arm.c        | 23 +++++------
 gas/config/tc-avr.c        |  8 ++--
 gas/config/tc-csky.c       |  6 +--
 gas/config/tc-d30v.c       |  2 +-
 gas/config/tc-dlx.c        |  4 +-
 gas/config/tc-epiphany.c   |  4 +-
 gas/config/tc-h8300.c      | 11 +++--
 gas/config/tc-hppa.c       | 26 ++++++------
 gas/config/tc-i386.c       | 12 +++---
 gas/config/tc-ia64.c       | 23 +++++------
 gas/config/tc-m32c.c       |  4 +-
 gas/config/tc-m68hc11.c    | 34 ++++++++--------
 gas/config/tc-m68k.c       | 12 +++---
 gas/config/tc-mcore.c      |  2 +-
 gas/config/tc-metag.c      |  5 +--
 gas/config/tc-microblaze.c | 13 +++---
 gas/config/tc-mips.c       | 61 ++++++++++++++--------------
 gas/config/tc-mmix.c       |  2 +-
 gas/config/tc-mn10300.c    |  4 +-
 gas/config/tc-msp430.c     | 30 +++++++-------
 gas/config/tc-nds32.c      |  2 +-
 gas/config/tc-nds32.h      |  2 +-
 gas/config/tc-nios2.c      | 45 ++++++++++-----------
 gas/config/tc-ns32k.c      | 18 ++++-----
 gas/config/tc-pdp11.c      | 64 ++++++++++++++---------------
 gas/config/tc-pj.c         |  4 +-
 gas/config/tc-ppc.c        | 12 +++---
 gas/config/tc-s12z.c       | 24 +++++------
 gas/config/tc-s390.c       |  4 +-
 gas/config/tc-score.c      |  7 ++--
 gas/config/tc-score7.c     |  7 ++--
 gas/config/tc-sh.h         |  4 +-
 gas/config/tc-sparc.c      | 82 +++++++++++++++++++-------------------
 gas/config/tc-tic54x.c     |  4 +-
 gas/config/tc-tic6x.c      |  3 +-
 gas/config/tc-v850.c       | 26 ++++++------
 gas/config/tc-vax.c        |  2 +-
 gas/config/tc-wasm32.c     |  8 ++--
 gas/config/tc-xstormy16.c  |  2 +-
 gas/config/tc-xtensa.c     | 14 +++----
 gas/config/xtensa-relax.c  | 10 ++---
 gas/dw2gencfi.c            |  7 ++--
 gas/dwarf2dbg.c            |  2 +-
 gas/ehopt.c                |  6 +--
 gas/input-file.c           |  4 +-
 gas/listing.c              | 32 +++++++--------
 gas/read.c                 |  2 +-
 gas/write.c                |  7 ++--
 57 files changed, 398 insertions(+), 416 deletions(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0003-Use-startswith-in-gas-subfolder.patch --]
[-- Type: text/x-patch; name="0003-Use-startswith-in-gas-subfolder.patch", Size: 97068 bytes --]

diff --git a/gas/as.c b/gas/as.c
index caa1c300ae7..933c513ec3d 100644
--- a/gas/as.c
+++ b/gas/as.c
@@ -158,7 +158,7 @@ select_emulation_mode (int argc, char **argv)
   const char *em = NULL;
 
   for (i = 1; i < argc; i++)
-    if (!strncmp ("--em", argv[i], 4))
+    if (startswith (argv[i], "--em"))
       break;
 
   if (i == argc)
@@ -819,8 +819,7 @@ This program has absolutely no warranty.\n"));
 	  /* We end up here for any -gsomething-not-already-a-long-option.
 	     give some useful feedback on not (yet) supported -gdwarfxxx
 	     versions/sections/options.  */
-	  if (strncmp (old_argv[optind - 1], "-gdwarf",
-		       strlen ("-gdwarf")) == 0)
+	  if (startswith (old_argv[optind - 1], "-gdwarf"))
 	    as_fatal (_("unknown DWARF option %s\n"), old_argv[optind - 1]);
 
 	  if (md_debug_format_selector)
diff --git a/gas/config/m68k-parse.y b/gas/config/m68k-parse.y
index 7f30eb87aaa..7528380a378 100644
--- a/gas/config/m68k-parse.y
+++ b/gas/config/m68k-parse.y
@@ -1008,12 +1008,12 @@ yylex (void)
     cp = s - tail;
     if (cp - 7 > str && cp[-7] == '@')
       {
-	if (strncmp (cp - 7, "@TLSLDM", 7) == 0)
+	if (startswith (cp - 7, "@TLSLDM"))
 	  {
 	    yylval.exp.pic_reloc = pic_tls_ldm;
 	    tail += 7;
 	  }
-	else if (strncmp (cp - 7, "@TLSLDO", 7) == 0)
+	else if (startswith (cp - 7, "@TLSLDO"))
 	  {
 	    yylval.exp.pic_reloc = pic_tls_ldo;
 	    tail += 7;
@@ -1021,27 +1021,27 @@ yylex (void)
       }
     else if (cp - 6 > str && cp[-6] == '@')
       {
-	if (strncmp (cp - 6, "@PLTPC", 6) == 0)
+	if (startswith (cp - 6, "@PLTPC"))
 	  {
 	    yylval.exp.pic_reloc = pic_plt_pcrel;
 	    tail += 6;
 	  }
-	else if (strncmp (cp - 6, "@GOTPC", 6) == 0)
+	else if (startswith (cp - 6, "@GOTPC"))
 	  {
 	    yylval.exp.pic_reloc = pic_got_pcrel;
 	    tail += 6;
 	  }
-	else if (strncmp (cp - 6, "@TLSGD", 6) == 0)
+	else if (startswith (cp - 6, "@TLSGD"))
 	  {
 	    yylval.exp.pic_reloc = pic_tls_gd;
 	    tail += 6;
 	  }
-	else if (strncmp (cp - 6, "@TLSIE", 6) == 0)
+	else if (startswith (cp - 6, "@TLSIE"))
 	  {
 	    yylval.exp.pic_reloc = pic_tls_ie;
 	    tail += 6;
 	  }
-	else if (strncmp (cp - 6, "@TLSLE", 6) == 0)
+	else if (startswith (cp - 6, "@TLSLE"))
 	  {
 	    yylval.exp.pic_reloc = pic_tls_le;
 	    tail += 6;
@@ -1049,12 +1049,12 @@ yylex (void)
       }
     else if (cp - 4 > str && cp[-4] == '@')
       {
-	if (strncmp (cp - 4, "@PLT", 4) == 0)
+	if (startswith (cp - 4, "@PLT"))
 	  {
 	    yylval.exp.pic_reloc = pic_plt_off;
 	    tail += 4;
 	  }
-	else if (strncmp (cp - 4, "@GOT", 4) == 0)
+	else if (startswith (cp - 4, "@GOT"))
 	  {
 	    yylval.exp.pic_reloc = pic_got_off;
 	    tail += 4;
diff --git a/gas/config/obj-aout.c b/gas/config/obj-aout.c
index 99f879b8f97..b41820b1b69 100644
--- a/gas/config/obj-aout.c
+++ b/gas/config/obj-aout.c
@@ -210,9 +210,9 @@ obj_aout_type (int ignore ATTRIBUTE_UNUSED)
       if (*input_line_pointer == '@')
 	{
 	  ++input_line_pointer;
-	  if (strncmp (input_line_pointer, "object", 6) == 0)
+	  if (startswith (input_line_pointer, "object"))
 	    S_SET_OTHER (sym, 1);
-	  else if (strncmp (input_line_pointer, "function", 8) == 0)
+	  else if (startswith (input_line_pointer, "function"))
 	    S_SET_OTHER (sym, 2);
 	}
     }
diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c
index 2fb8ccda48b..f60558ee479 100644
--- a/gas/config/obj-elf.c
+++ b/gas/config/obj-elf.c
@@ -324,9 +324,9 @@ elf_common_parse (int ignore ATTRIBUTE_UNUSED, symbolS *symbolP, addressT size)
 	  if (*input_line_pointer == '.')
 	    input_line_pointer++;
 	  /* Some say data, some say bss.  */
-	  if (strncmp (input_line_pointer, "bss\"", 4) == 0)
+	  if (startswith (input_line_pointer, "bss\""))
 	    input_line_pointer += 4;
-	  else if (strncmp (input_line_pointer, "data\"", 5) == 0)
+	  else if (startswith (input_line_pointer, "data\""))
 	    input_line_pointer += 5;
 	  else
 	    {
@@ -949,17 +949,17 @@ obj_elf_parse_section_letters (char *str, size_t len,
 static int
 obj_elf_section_type (char *str, size_t len, bfd_boolean warn)
 {
-  if (len == 8 && strncmp (str, "progbits", 8) == 0)
+  if (len == 8 && startswith (str, "progbits"))
     return SHT_PROGBITS;
-  if (len == 6 && strncmp (str, "nobits", 6) == 0)
+  if (len == 6 && startswith (str, "nobits"))
     return SHT_NOBITS;
-  if (len == 4 && strncmp (str, "note", 4) == 0)
+  if (len == 4 && startswith (str, "note"))
     return SHT_NOTE;
-  if (len == 10 && strncmp (str, "init_array", 10) == 0)
+  if (len == 10 && startswith (str, "init_array"))
     return SHT_INIT_ARRAY;
-  if (len == 10 && strncmp (str, "fini_array", 10) == 0)
+  if (len == 10 && startswith (str, "fini_array"))
     return SHT_FINI_ARRAY;
-  if (len == 13 && strncmp (str, "preinit_array", 13) == 0)
+  if (len == 13 && startswith (str, "preinit_array"))
     return SHT_PREINIT_ARRAY;
 
 #ifdef md_elf_section_type
@@ -991,15 +991,15 @@ obj_elf_section_word (char *str, size_t len, int *type)
 {
   int ret;
 
-  if (len == 5 && strncmp (str, "write", 5) == 0)
+  if (len == 5 && startswith (str, "write"))
     return SHF_WRITE;
-  if (len == 5 && strncmp (str, "alloc", 5) == 0)
+  if (len == 5 && startswith (str, "alloc"))
     return SHF_ALLOC;
-  if (len == 9 && strncmp (str, "execinstr", 9) == 0)
+  if (len == 9 && startswith (str, "execinstr"))
     return SHF_EXECINSTR;
-  if (len == 7 && strncmp (str, "exclude", 7) == 0)
+  if (len == 7 && startswith (str, "exclude"))
     return SHF_EXCLUDE;
-  if (len == 3 && strncmp (str, "tls", 3) == 0)
+  if (len == 3 && startswith (str, "tls"))
     return SHF_TLS;
 
 #ifdef md_elf_section_word
@@ -1291,13 +1291,13 @@ obj_elf_section (int push)
 		{
 		  ++input_line_pointer;
 		  SKIP_WHITESPACE ();
-		  if (strncmp (input_line_pointer, "comdat", 6) == 0)
+		  if (startswith (input_line_pointer, "comdat"))
 		    {
 		      input_line_pointer += 6;
 		      linkonce = 1;
 		    }
 		}
-	      else if (strncmp (name, ".gnu.linkonce", 13) == 0)
+	      else if (startswith (name, ".gnu.linkonce"))
 		linkonce = 1;
 	    }
 	  else if ((attr & SHF_GROUP) != 0)
@@ -1345,7 +1345,7 @@ obj_elf_section (int push)
 
 	      ++input_line_pointer;
 	      SKIP_WHITESPACE ();
-	      if (strncmp (input_line_pointer, "unique", 6) == 0)
+	      if (startswith (input_line_pointer, "unique"))
 		{
 		  input_line_pointer += 6;
 		  SKIP_WHITESPACE ();
@@ -1748,17 +1748,17 @@ obj_elf_symver (int ignore ATTRIBUTE_UNUSED)
 
       ++input_line_pointer;
       SKIP_WHITESPACE ();
-      if (strncmp (input_line_pointer, "local", 5) == 0)
+      if (startswith (input_line_pointer, "local"))
 	{
 	  input_line_pointer += 5;
 	  sy_obj->visibility = visibility_local;
 	}
-      else if (strncmp (input_line_pointer, "hidden", 6) == 0)
+      else if (startswith (input_line_pointer, "hidden"))
 	{
 	  input_line_pointer += 6;
 	  sy_obj->visibility = visibility_hidden;
 	}
-      else if (strncmp (input_line_pointer, "remove", 6) == 0)
+      else if (startswith (input_line_pointer, "remove"))
 	{
 	  input_line_pointer += 6;
 	  sy_obj->visibility = visibility_remove;
@@ -2508,7 +2508,7 @@ adjust_stab_sections (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED)
   char *p;
   int strsz, nsyms;
 
-  if (strncmp (".stab", sec->name, 5))
+  if (!startswith (".stab", sec->name))
     return;
   if (!strcmp ("str", sec->name + strlen (sec->name) - 3))
     return;
diff --git a/gas/config/obj-evax.c b/gas/config/obj-evax.c
index 8763a7c29ac..d39b4896945 100644
--- a/gas/config/obj-evax.c
+++ b/gas/config/obj-evax.c
@@ -239,7 +239,7 @@ evax_shorten_name (char *id)
   prefix [0] = 0;
 
   /* Check for ..xx suffix and save it.  */
-  if (strncmp (&id[len-4], "..", 2) == 0)
+  if (startswith (&id[len-4], ".."))
     {
       suffix_dotdot = len - 4;
       strncpy (suffix, &id[len-4], 4);
diff --git a/gas/config/obj-macho.c b/gas/config/obj-macho.c
index 1380707e3c9..9e7dc19ae50 100644
--- a/gas/config/obj-macho.c
+++ b/gas/config/obj-macho.c
@@ -1907,8 +1907,8 @@ obj_mach_o_is_frame_section (segT sec)
 {
   int l;
   l = strlen (segment_name (sec));
-  if ((l == 9 && strncmp (".eh_frame", segment_name (sec), 9) == 0)
-       || (l == 12 && strncmp (".debug_frame", segment_name (sec), 12) == 0))
+  if ((l == 9 && startswith (".eh_frame", segment_name (sec)))
+       || (l == 12 && startswith (".debug_frame", segment_name (sec))))
     return 1;
   return 0;
 }
diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c
index 6f782d057f8..7323811e49d 100644
--- a/gas/config/tc-aarch64.c
+++ b/gas/config/tc-aarch64.c
@@ -1353,7 +1353,7 @@ create_register_alias (char *newname, char *p)
   /* The input scrubber ensures that whitespace after the mnemonic is
      collapsed to single spaces.  */
   oldname = p;
-  if (strncmp (oldname, " .req ", 6) != 0)
+  if (!startswith (oldname, " .req "))
     return FALSE;
 
   oldname += 6;
@@ -2372,7 +2372,7 @@ parse_aarch64_imm_float (char **ccp, int *immed, bfd_boolean dp_p,
   fpnum = str;
   skip_whitespace (fpnum);
 
-  if (strncmp (fpnum, "0x", 2) == 0)
+  if (startswith (fpnum, "0x"))
     {
       /* Support the hexadecimal representation of the IEEE754 encoding.
 	 Double-precision is expected when DP_P is TRUE, otherwise the
@@ -7253,7 +7253,7 @@ aarch64_frob_section (asection *sec ATTRIBUTE_UNUSED)
 int
 aarch64_data_in_code (void)
 {
-  if (!strncmp (input_line_pointer + 1, "data:", 5))
+  if (startswith (input_line_pointer + 1, "data:"))
     {
       *input_line_pointer = '/';
       input_line_pointer += 5;
@@ -9287,7 +9287,7 @@ aarch64_parse_features (const char *str, const aarch64_feature_set **opt_p,
       else
 	optlen = strlen (str);
 
-      if (optlen >= 2 && strncmp (str, "no", 2) == 0)
+      if (optlen >= 2 && startswith (str, "no"))
 	{
 	  if (adding_value != 0)
 	    adding_value = 0;
@@ -9504,8 +9504,7 @@ md_parse_option (int c, const char *arg)
 	  /* These options are expected to have an argument.  */
 	  if (c == lopt->option[0]
 	      && arg != NULL
-	      && strncmp (arg, lopt->option + 1,
-			  strlen (lopt->option + 1)) == 0)
+	      && startswith (arg, lopt->option + 1))
 	    {
 	      /* If the option is deprecated, tell the user.  */
 	      if (lopt->deprecated != NULL)
diff --git a/gas/config/tc-alpha.c b/gas/config/tc-alpha.c
index 6225f37f6e1..2806a1ac0ed 100644
--- a/gas/config/tc-alpha.c
+++ b/gas/config/tc-alpha.c
@@ -4229,7 +4229,7 @@ s_alpha_section_word (char *str, size_t len)
   int no = 0;
   flagword flag = 0;
 
-  if (len == 5 && strncmp (str, "NO", 2) == 0)
+  if (len == 5 && startswith (str, "NO"))
     {
       no = 1;
       str += 2;
@@ -4238,30 +4238,30 @@ s_alpha_section_word (char *str, size_t len)
 
   if (len == 3)
     {
-      if (strncmp (str, "PIC", 3) == 0)
+      if (startswith (str, "PIC"))
 	flag = EGPS__V_PIC;
-      else if (strncmp (str, "LIB", 3) == 0)
+      else if (startswith (str, "LIB"))
 	flag = EGPS__V_LIB;
-      else if (strncmp (str, "OVR", 3) == 0)
+      else if (startswith (str, "OVR"))
 	flag = EGPS__V_OVR;
-      else if (strncmp (str, "REL", 3) == 0)
+      else if (startswith (str, "REL"))
 	flag = EGPS__V_REL;
-      else if (strncmp (str, "GBL", 3) == 0)
+      else if (startswith (str, "GBL"))
 	flag = EGPS__V_GBL;
-      else if (strncmp (str, "SHR", 3) == 0)
+      else if (startswith (str, "SHR"))
 	flag = EGPS__V_SHR;
-      else if (strncmp (str, "EXE", 3) == 0)
+      else if (startswith (str, "EXE"))
 	flag = EGPS__V_EXE;
-      else if (strncmp (str, "WRT", 3) == 0)
+      else if (startswith (str, "WRT"))
 	flag = EGPS__V_WRT;
-      else if (strncmp (str, "VEC", 3) == 0)
+      else if (startswith (str, "VEC"))
 	flag = EGPS__V_VEC;
-      else if (strncmp (str, "MOD", 3) == 0)
+      else if (startswith (str, "MOD"))
 	{
 	  flag = no ? EGPS__V_NOMOD : EGPS__V_NOMOD << EGPS__V_NO_SHIFT;
 	  no = 0;
 	}
-      else if (strncmp (str, "COM", 3) == 0)
+      else if (startswith (str, "COM"))
 	flag = EGPS__V_COM;
     }
 
@@ -4544,13 +4544,13 @@ s_alpha_pdesc (int ignore ATTRIBUTE_UNUSED)
   SKIP_WHITESPACE ();
   name_end = get_symbol_name (&name);
 
-  if (strncmp (name, "stack", 5) == 0)
+  if (startswith (name, "stack"))
     alpha_evax_proc->pdsckind = PDSC_S_K_KIND_FP_STACK;
 
-  else if (strncmp (name, "reg", 3) == 0)
+  else if (startswith (name, "reg"))
     alpha_evax_proc->pdsckind = PDSC_S_K_KIND_FP_REGISTER;
 
-  else if (strncmp (name, "null", 4) == 0)
+  else if (startswith (name, "null"))
     alpha_evax_proc->pdsckind = PDSC_S_K_KIND_NULL;
 
   else
diff --git a/gas/config/tc-arc.c b/gas/config/tc-arc.c
index 958eada844c..50034547353 100644
--- a/gas/config/tc-arc.c
+++ b/gas/config/tc-arc.c
@@ -4727,17 +4727,17 @@ tokenize_extregister (extRegister_t *ereg, int opertype)
       input_line_pointer++;
       mode = input_line_pointer;
 
-      if (!strncmp (mode, "r|w", 3))
+      if (startswith (mode, "r|w"))
 	{
 	  imode = 0;
 	  input_line_pointer += 3;
 	}
-      else if (!strncmp (mode, "r", 1))
+      else if (startswith (mode, "r"))
 	{
 	  imode = ARC_REGISTER_READONLY;
 	  input_line_pointer += 1;
 	}
-      else if (strncmp (mode, "w", 1))
+      else if (!startswith (mode, "w"))
 	{
 	  as_bad (_("invalid mode"));
 	  ignore_rest_of_line ();
@@ -4765,12 +4765,12 @@ tokenize_extregister (extRegister_t *ereg, int opertype)
 
       input_line_pointer++;
 
-      if (!strncmp (input_line_pointer, "cannot_shortcut", 15))
+      if (startswith (input_line_pointer, "cannot_shortcut"))
 	{
 	  imode |= ARC_REGISTER_NOSHORT_CUT;
 	  input_line_pointer += 15;
 	}
-      else if (strncmp (input_line_pointer, "can_shortcut", 12))
+      else if (!startswith (input_line_pointer, "can_shortcut"))
 	{
 	  as_bad (_("shortcut designator invalid"));
 	  ignore_rest_of_line ();
diff --git a/gas/config/tc-arm.c b/gas/config/tc-arm.c
index e35cdd51901..2baef99ce58 100644
--- a/gas/config/tc-arm.c
+++ b/gas/config/tc-arm.c
@@ -2624,7 +2624,7 @@ create_register_alias (char * newname, char *p)
   /* The input scrubber ensures that whitespace after the mnemonic is
      collapsed to single spaces.  */
   oldname = p;
-  if (strncmp (oldname, " .req ", 6) != 0)
+  if (!startswith (oldname, " .req "))
     return FALSE;
 
   oldname += 6;
@@ -2715,9 +2715,9 @@ create_neon_reg_alias (char *newname, char *p)
 
   nameend = p;
 
-  if (strncmp (p, " .dn ", 5) == 0)
+  if (startswith (p, " .dn "))
     basetype = REG_TYPE_VFD;
-  else if (strncmp (p, " .qn ", 5) == 0)
+  else if (startswith (p, " .qn "))
     basetype = REG_TYPE_NQ;
   else
     return FALSE;
@@ -5401,7 +5401,7 @@ parse_ifimm_zero (char **in)
     ++*in;
 
   /* Accept #0x0 as a synonym for #0.  */
-  if (strncmp (*in, "0x", 2) == 0)
+  if (startswith (*in, "0x"))
     {
       int val;
       if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
@@ -5445,7 +5445,7 @@ parse_qfloat_immediate (char **ccp, int *immed)
   fpnum = str;
   skip_whitespace (fpnum);
 
-  if (strncmp (fpnum, "0x", 2) == 0)
+  if (startswith (fpnum, "0x"))
     return FAIL;
   else
     {
@@ -23727,7 +23727,7 @@ arm_frob_label (symbolS * sym)
 bfd_boolean
 arm_data_in_code (void)
 {
-  if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
+  if (thumb_mode && startswith (input_line_pointer + 1, "data:"))
     {
       *input_line_pointer = '/';
       input_line_pointer += 5;
@@ -27418,7 +27418,7 @@ arm_elf_change_section (void)
 int
 arm_elf_section_type (const char * str, size_t len)
 {
-  if (len == 5 && strncmp (str, "exidx", 5) == 0)
+  if (len == 5 && startswith (str, "exidx"))
     return SHT_ARM_EXIDX;
 
   return -1;
@@ -27588,8 +27588,7 @@ start_unwind_section (const segT text_seg, int idx)
   if (streq (text_name, ".text"))
     text_name = "";
 
-  if (strncmp (text_name, ".gnu.linkonce.t.",
-	       strlen (".gnu.linkonce.t.")) == 0)
+  if (startswith (text_name, ".gnu.linkonce.t."))
     {
       prefix = prefix_once;
       text_name += strlen (".gnu.linkonce.t.");
@@ -32213,7 +32212,7 @@ arm_parse_extension (const char *str, const arm_feature_set *opt_set,
       else
 	len = strlen (str);
 
-      if (len >= 2 && strncmp (str, "no", 2) == 0)
+      if (len >= 2 && startswith (str, "no"))
 	{
 	  if (adding_value != 0)
 	    {
@@ -33007,7 +33006,7 @@ aeabi_set_public_attributes (void)
       char *q;
 
       q = selected_cpu_name;
-      if (strncmp (q, "armv", 4) == 0)
+      if (startswith (q, "armv"))
 	{
 	  int i;
 
@@ -33300,7 +33299,7 @@ s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
   *input_line_pointer = 0;
 
   if (strlen (name) >= 2
-      && strncmp (name, "no", 2) == 0)
+      && startswith (name, "no"))
     {
       adding_value = 0;
       name += 2;
diff --git a/gas/config/tc-avr.c b/gas/config/tc-avr.c
index 1edf8fbd1e5..d3c901b0716 100644
--- a/gas/config/tc-avr.c
+++ b/gas/config/tc-avr.c
@@ -942,10 +942,10 @@ avr_ldi_expression (expressionS *exp)
 
 	      ++str;
 
-	      if (strncmp ("pm(", str, 3) == 0
-                  || strncmp ("gs(",str,3) == 0
-                  || strncmp ("-(gs(",str,5) == 0
-		  || strncmp ("-(pm(", str, 5) == 0)
+	      if (startswith (str, "pm(")
+                  || startswith (str, "gs(")
+                  || startswith (str, "-(gs(")
+		  || startswith (str, "-(pm("))
 		{
 		  if (HAVE_PM_P (mod))
 		    {
diff --git a/gas/config/tc-csky.c b/gas/config/tc-csky.c
index 7a74eabca9c..5af7d8ba5d0 100644
--- a/gas/config/tc-csky.c
+++ b/gas/config/tc-csky.c
@@ -2781,8 +2781,8 @@ is_freglist_legal (char **oper)
   reg2 = reg2 - reg1;
   /* The fldm/fstm in CSKY_ISA_FLOAT_7E60 has 5 bits frz(reg1).  */
   shift = 4;
-  if (strncmp (csky_insn.opcode->mnemonic, "fstm", 4) == 0
-      || strncmp (csky_insn.opcode->mnemonic, "fldm", 4) == 0)
+  if (startswith (csky_insn.opcode->mnemonic, "fstm")
+      || startswith (csky_insn.opcode->mnemonic, "fldm"))
     {
       if ((!(isa_flag & CSKY_ISA_FLOAT_7E60)
 	   && (reg2 > (int)15 || reg1 > 15))
@@ -7758,7 +7758,7 @@ csky_s_section (int ignore)
   while (*ilp != 0 && ISSPACE (*ilp))
     ++ ilp;
 
-  if (strncmp (ilp, ".line", 5) == 0
+  if (startswith (ilp, ".line")
       && (ISSPACE (ilp[5]) || *ilp == '\n' || *ilp == '\r'))
     ;
   else
diff --git a/gas/config/tc-d30v.c b/gas/config/tc-d30v.c
index f97c35f7040..a892dc9d4e4 100644
--- a/gas/config/tc-d30v.c
+++ b/gas/config/tc-d30v.c
@@ -1339,7 +1339,7 @@ do_assemble (char *str,
     opcode->ecc = ECC_AL;
 
   /* CMP and CMPU change their name based on condition codes.  */
-  if (!strncmp (name, "cmp", 3))
+  if (startswith (name, "cmp"))
     {
       int p, i;
       char **d30v_str = (char **) d30v_cc_names;
diff --git a/gas/config/tc-dlx.c b/gas/config/tc-dlx.c
index 1383f895a63..29281177393 100644
--- a/gas/config/tc-dlx.c
+++ b/gas/config/tc-dlx.c
@@ -592,14 +592,14 @@ parse_operand (char *s, expressionS *operandp)
   the_insn.HI = the_insn.LO = 0;
 
   /* Search for %hi and %lo, make a mark and skip it.  */
-  if (strncmp (s, "%hi", 3) == 0)
+  if (startswith (s, "%hi"))
     {
       s += 3;
       the_insn.HI = 1;
     }
   else
     {
-      if (strncmp (s, "%lo", 3) == 0)
+      if (startswith (s, "%lo"))
 	{
 	  s += 3;
 	  the_insn.LO = 1;
diff --git a/gas/config/tc-epiphany.c b/gas/config/tc-epiphany.c
index 641ba14c836..d9dba529266 100644
--- a/gas/config/tc-epiphany.c
+++ b/gas/config/tc-epiphany.c
@@ -529,13 +529,13 @@ md_assemble (char *str)
   int regmask=0, push=0, pop=0;
 
   /* Special-case push/pop instruction macros.  */
-  if (0 == strncmp (str, "push {", 6))
+  if (startswith (str, "push {"))
     {
       char * s = str + 6;
       push = 1;
       pperr = parse_reglist (s, &regmask);
     }
-  else if (0 == strncmp (str, "pop {", 5))
+  else if (startswith (str, "pop {"))
     {
       char * s = str + 5;
       pop = 1;
diff --git a/gas/config/tc-h8300.c b/gas/config/tc-h8300.c
index 9fc69f81c82..ad4dd9a9b96 100644
--- a/gas/config/tc-h8300.c
+++ b/gas/config/tc-h8300.c
@@ -167,8 +167,7 @@ h8300_elf_section (int push)
 
       if (i < 0)
 	for (i = ARRAY_SIZE (known_data_prefixes); i--;)
-	  if (strncmp (name, known_data_prefixes[i],
-		       strlen (known_data_prefixes[i])) == 0)
+	  if (startswith (name, known_data_prefixes[i]))
 	    break;
 
       if (i < 0)
@@ -872,10 +871,10 @@ get_operand (char **ptr, struct h8_op *op, int direction)
       *ptr = parse_exp (src + 1, op);
       return;
     }
-  else if (strncmp (src, "mach", 4) == 0 ||
-	   strncmp (src, "macl", 4) == 0 ||
-	   strncmp (src, "MACH", 4) == 0 ||
-	   strncmp (src, "MACL", 4) == 0)
+  else if (startswith (src, "mach") ||
+	   startswith (src, "macl") ||
+	   startswith (src, "MACH") ||
+	   startswith (src, "MACL"))
     {
       op->reg = TOLOWER (src[3]) == 'l';
       op->mode = MACREG;
diff --git a/gas/config/tc-hppa.c b/gas/config/tc-hppa.c
index f95c107517b..7f7ff628dd2 100644
--- a/gas/config/tc-hppa.c
+++ b/gas/config/tc-hppa.c
@@ -3553,7 +3553,7 @@ pa_ip (char *str)
 		/* Handle load cache hint completer.  */
 		case 'c':
 		  cmpltr = 0;
-		  if (!strncmp (s, ",sl", 3))
+		  if (startswith (s, ",sl"))
 		    {
 		      s += 3;
 		      cmpltr = 2;
@@ -3563,12 +3563,12 @@ pa_ip (char *str)
 		/* Handle store cache hint completer.  */
 		case 'C':
 		  cmpltr = 0;
-		  if (!strncmp (s, ",sl", 3))
+		  if (startswith (s, ",sl"))
 		    {
 		      s += 3;
 		      cmpltr = 2;
 		    }
-		  else if (!strncmp (s, ",bc", 3))
+		  else if (startswith (s, ",bc"))
 		    {
 		      s += 3;
 		      cmpltr = 1;
@@ -3578,7 +3578,7 @@ pa_ip (char *str)
 		/* Handle load and clear cache hint completer.  */
 		case 'd':
 		  cmpltr = 0;
-		  if (!strncmp (s, ",co", 3))
+		  if (startswith (s, ",co"))
 		    {
 		      s += 3;
 		      cmpltr = 1;
@@ -3587,7 +3587,7 @@ pa_ip (char *str)
 
 		/* Handle load ordering completer.  */
 		case 'o':
-		  if (strncmp (s, ",o", 2) != 0)
+		  if (!startswith (s, ",o"))
 		    break;
 		  s += 2;
 		  continue;
@@ -4098,12 +4098,12 @@ pa_ip (char *str)
 			else if (*s == '*')
 			  break;
 
-			if (strncmp (s, "<", 1) == 0)
+			if (startswith (s, "<"))
 			  {
 			    cmpltr = 0;
 			    s++;
 			  }
-			else if (strncmp (s, ">=", 2) == 0)
+			else if (startswith (s, ">="))
 			  {
 			    cmpltr = 1;
 			    s += 2;
@@ -6813,25 +6813,25 @@ pa_level (int unused ATTRIBUTE_UNUSED)
   char *level;
 
   level = input_line_pointer;
-  if (strncmp (level, "1.0", 3) == 0)
+  if (startswith (level, "1.0"))
     {
       input_line_pointer += 3;
       if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 10))
 	as_warn (_("could not set architecture and machine"));
     }
-  else if (strncmp (level, "1.1", 3) == 0)
+  else if (startswith (level, "1.1"))
     {
       input_line_pointer += 3;
       if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 11))
 	as_warn (_("could not set architecture and machine"));
     }
-  else if (strncmp (level, "2.0w", 4) == 0)
+  else if (startswith (level, "2.0w"))
     {
       input_line_pointer += 4;
       if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 25))
 	as_warn (_("could not set architecture and machine"));
     }
-  else if (strncmp (level, "2.0", 3) == 0)
+  else if (startswith (level, "2.0"))
     {
       input_line_pointer += 3;
       if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 20))
@@ -7202,7 +7202,7 @@ pa_space (int unused ATTRIBUTE_UNUSED)
 	 and place them into a subroutine or something similar?  */
       /* FIXME Is this (and the next IF stmt) really right?
 	 What if INPUT_LINE_POINTER points to "$TEXT$FOO"?  */
-      if (strncmp (input_line_pointer, "$TEXT$", 6) == 0)
+      if (startswith (input_line_pointer, "$TEXT$"))
 	{
 	  input_line_pointer += 6;
 	  sd_chain = is_defined_space ("$TEXT$");
@@ -7219,7 +7219,7 @@ pa_space (int unused ATTRIBUTE_UNUSED)
 	  demand_empty_rest_of_line ();
 	  return;
 	}
-      if (strncmp (input_line_pointer, "$PRIVATE$", 9) == 0)
+      if (startswith (input_line_pointer, "$PRIVATE$"))
 	{
 	  input_line_pointer += 9;
 	  sd_chain = is_defined_space ("$PRIVATE$");
diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index b1c7b504629..549c658bc2e 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -3008,7 +3008,7 @@ i386_arch (void)
 unsigned long
 i386_mach (void)
 {
-  if (!strncmp (default_arch, "x86_64", 6))
+  if (startswith (default_arch, "x86_64"))
     {
       if (cpu_arch_isa == PROCESSOR_L1OM)
 	{
@@ -4732,8 +4732,8 @@ md_assemble (char *line)
       && i.operands > 1
       && (strcmp (mnemonic, "bound") != 0)
       && (strcmp (mnemonic, "invlpga") != 0)
-      && (strncmp (mnemonic, "monitor", 7) != 0)
-      && (strncmp (mnemonic, "mwait", 5) != 0)
+      && !startswith (mnemonic, "monitor")
+      && !startswith (mnemonic, "mwait")
       && (strcmp (mnemonic, "tpause") != 0)
       && (strcmp (mnemonic, "umwait") != 0)
       && !(operand_type_check (i.types[0], imm)
@@ -10384,7 +10384,7 @@ check_VecOperations (char *op_string, char *op_end)
 	  op_string++;
 
 	  /* Check broadcasts.  */
-	  if (strncmp (op_string, "1to", 3) == 0)
+	  if (startswith (op_string, "1to"))
 	    {
 	      int bcst_type;
 
@@ -13748,7 +13748,7 @@ md_show_usage (FILE *stream)
 const char *
 i386_target_format (void)
 {
-  if (!strncmp (default_arch, "x86_64", 6))
+  if (startswith (default_arch, "x86_64"))
     {
       update_code_flag (CODE_64BIT, 1);
       if (default_arch[6] == '\0')
@@ -14316,7 +14316,7 @@ i386_elf_section_type (const char *str, size_t len)
 {
   if (flag_code == CODE_64BIT
       && len == sizeof ("unwind") - 1
-      && strncmp (str, "unwind", 6) == 0)
+      && startswith (str, "unwind"))
     return SHT_X86_64_UNWIND;
 
   return -1;
diff --git a/gas/config/tc-ia64.c b/gas/config/tc-ia64.c
index c64c0d5cce2..9b001246cfc 100644
--- a/gas/config/tc-ia64.c
+++ b/gas/config/tc-ia64.c
@@ -3560,7 +3560,7 @@ start_unwind_section (const segT text_seg, int sec_index)
 
   sec_text_name = segment_name (text_seg);
   text_name = sec_text_name;
-  if (strncmp (text_name, "_info", 5) == 0)
+  if (startswith (text_name, "_info"))
     {
       as_bad (_("Illegal section name `%s' (causes unwind section name clash)"),
 	      text_name);
@@ -3573,8 +3573,7 @@ start_unwind_section (const segT text_seg, int sec_index)
   /* Build the unwind section name by appending the (possibly stripped)
      text section name to the unwind prefix.  */
   suffix = text_name;
-  if (strncmp (text_name, ".gnu.linkonce.t.",
-	       sizeof (".gnu.linkonce.t.") - 1) == 0)
+  if (startswith (text_name, ".gnu.linkonce.t."))
     {
       prefix = special_linkonce_name [sec_index - SPECIAL_SECTION_UNWIND];
       suffix += sizeof (".gnu.linkonce.t.") - 1;
@@ -7004,7 +7003,7 @@ md_parse_option (int c, const char *arg)
 	  md.flags |= EF_IA_64_BE;
 	  default_big_endian = 1;
 	}
-      else if (strncmp (arg, "unwind-check=", 13) == 0)
+      else if (startswith (arg, "unwind-check="))
 	{
 	  arg += 13;
 	  if (strcmp (arg, "warning") == 0)
@@ -7014,7 +7013,7 @@ md_parse_option (int c, const char *arg)
 	  else
 	    return 0;
 	}
-      else if (strncmp (arg, "hint.b=", 7) == 0)
+      else if (startswith (arg, "hint.b="))
 	{
 	  arg += 7;
 	  if (strcmp (arg, "ok") == 0)
@@ -7026,7 +7025,7 @@ md_parse_option (int c, const char *arg)
 	  else
 	    return 0;
 	}
-      else if (strncmp (arg, "tune=", 5) == 0)
+      else if (startswith (arg, "tune="))
 	{
 	  arg += 5;
 	  if (strcmp (arg, "itanium1") == 0)
@@ -7074,7 +7073,7 @@ md_parse_option (int c, const char *arg)
 			exit:	branch out from the current context (default)
 			labels:	all labels in context may be branch targets
        */
-      if (strncmp (arg, "indirect=", 9) != 0)
+      if (!startswith (arg, "indirect="))
         return 0;
       break;
 
@@ -8106,7 +8105,7 @@ static int
 is_taken_branch (struct ia64_opcode *idesc)
 {
   return ((is_conditional_branch (idesc) && CURR_SLOT.qp_regno == 0)
-	  || strncmp (idesc->name, "br.ia", 5) == 0);
+	  || startswith (idesc->name, "br.ia"));
 }
 
 /* Return whether the given opcode is an interruption or rfi.  If there's any
@@ -9498,7 +9497,7 @@ dep->name, idesc->name, (rsrc_write?"write":"read"), note)
       /* FIXME we can identify some individual RSE written resources, but RSE
 	 read resources have not yet been completely identified, so for now
 	 treat RSE as a single resource */
-      if (strncmp (idesc->name, "mov", 3) == 0)
+      if (startswith (idesc->name, "mov"))
 	{
 	  if (rsrc_write)
 	    {
@@ -9864,8 +9863,8 @@ note_register_values (struct ia64_opcode *idesc)
     }
   /* After a call, all register values are undefined, except those marked
      as "safe".  */
-  else if (strncmp (idesc->name, "br.call", 6) == 0
-	   || strncmp (idesc->name, "brl.call", 7) == 0)
+  else if (startswith (idesc->name, "br.call")
+	   || startswith (idesc->name, "brl.call"))
     {
       /* FIXME keep GR values which are marked as "safe_across_calls"  */
       clear_register_values ();
@@ -11843,7 +11842,7 @@ do_alias (void **slot, void *arg ATTRIBUTE_UNUSED)
       /* Uses .alias extensively to alias CRTL functions to same with
 	 decc$ prefix. Sometimes function gets optimized away and a
 	 warning results, which should be suppressed.  */
-      if (strncmp (tuple->key, "decc$", 5) != 0)
+      if (!startswith (tuple->key, "decc$"))
 #endif
 	as_warn_where (h->file, h->line,
 		       _("symbol `%s' aliased to `%s' is not used"),
diff --git a/gas/config/tc-m32c.c b/gas/config/tc-m32c.c
index c490278f711..6022e50cb91 100644
--- a/gas/config/tc-m32c.c
+++ b/gas/config/tc-m32c.c
@@ -519,8 +519,8 @@ insn_to_subtype (int inum, const CGEN_INSN *insn)
   unsigned int i;
 
   if (insn
-      && (strncmp (insn->base->mnemonic, "adjnz", 5) == 0
-	  || strncmp (insn->base->mnemonic, "sbjnz", 5) == 0))
+      && (startswith (insn->base->mnemonic, "adjnz")
+	  || startswith (insn->base->mnemonic, "sbjnz")))
     {
       i = 23 + insn->base->bitsize/8 - 3;
       /*printf("mapping %d used for %s\n", i, insn->base->mnemonic);*/
diff --git a/gas/config/tc-m68hc11.c b/gas/config/tc-m68hc11.c
index f0bb7434fd0..c263e27dc5d 100644
--- a/gas/config/tc-m68hc11.c
+++ b/gas/config/tc-m68hc11.c
@@ -1177,19 +1177,19 @@ get_operand (operand *oper, int which, long opmode)
 
       mode = M6811_OP_IMM16;
       p++;
-      if (strncmp (p, "%hi", 3) == 0)
+      if (startswith (p, "%hi"))
 	{
 	  p += 3;
 	  mode |= M6811_OP_HIGH_ADDR;
 	}
-      else if (strncmp (p, "%lo", 3) == 0)
+      else if (startswith (p, "%lo"))
 	{
 	  p += 3;
 	  mode |= M6811_OP_LOW_ADDR;
 	}
       /* %page modifier is used to obtain only the page number
          of the address of a function.  */
-      else if (strncmp (p, "%page", 5) == 0)
+      else if (startswith (p, "%page"))
 	{
 	  p += 5;
 	  mode |= M6811_OP_PAGE_ADDR;
@@ -1200,7 +1200,7 @@ get_operand (operand *oper, int which, long opmode)
          mapped in the 16K window at 0x8000 and the value will be
          within that window (although the function address may not fit
          in 16-bit).  See bfd/elf32-m68hc12.c for the translation.  */
-      else if (strncmp (p, "%addr", 5) == 0)
+      else if (startswith (p, "%addr"))
 	{
 	  p += 5;
 	  mode |= M6811_OP_CALL_ADDR;
@@ -1238,7 +1238,7 @@ get_operand (operand *oper, int which, long opmode)
       return -1;
     }
   /* Handle 68HC12 page specification in 'call foo,%page(bar)'.  */
-  else if ((opmode & M6812_OP_PAGE) && strncmp (p, "%page", 5) == 0)
+  else if ((opmode & M6812_OP_PAGE) && startswith (p, "%page"))
     {
       p += 5;
       mode = M6811_OP_PAGE_ADDR | M6812_OP_PAGE | M6811_OP_IND16;
@@ -2873,7 +2873,7 @@ md_assemble (char *str)
         }
 
       /* Special handling of TFR. */
-      if (strncmp (opc->opcode->name, "tfr",3) == 0)
+      if (startswith (opc->opcode->name, "tfr"))
         {
           /* There must be two operands with a comma. */
           input_line_pointer = skip_whites (input_line_pointer);
@@ -2995,7 +2995,7 @@ md_assemble (char *str)
 	}
 
       /* Special handling of SIF. */
-      if (strncmp (opc->opcode->name, "sif",3) == 0)
+      if (startswith (opc->opcode->name, "sif"))
         {
           /* Either OP_NONE or OP_RS. */
           if (*input_line_pointer != '\n')
@@ -3040,13 +3040,13 @@ md_assemble (char *str)
                   opcode = find (opc, operands, 1);
                   if (opcode)
 		    {
-                      if ((strncmp (opc->opcode->name, "com",3) == 0)
-                          || (strncmp (opc->opcode->name, "neg",3) == 0))
+                      if ((startswith (opc->opcode->name, "com"))
+                          || (startswith (opc->opcode->name, "neg")))
                         /* Special case for com RD as alias for sub RD,R0,RS */
                         /* Special case for neg RD as alias for sub RD,R0,RS */
                         opcode_local.opcode = opcode->opcode
                           | (operands[0].reg1 << 8) | (operands[0].reg1 << 2);
-		      else if (strncmp (opc->opcode->name, "tst",3) == 0)
+		      else if (startswith (opc->opcode->name, "tst"))
                         /* Special case for tst RS alias for sub R0, RS, R0 */
                         opcode_local.opcode = opcode->opcode
                           | (operands[0].reg1 << 5);
@@ -3128,12 +3128,12 @@ md_assemble (char *str)
             {
               input_line_pointer++;
               input_line_pointer = skip_whites (input_line_pointer);
-              if (strncmp (input_line_pointer, "%hi", 3) == 0)
+              if (startswith (input_line_pointer, "%hi"))
                 {
                   input_line_pointer += 3;
                   operands[0].mode = M6811_OP_HIGH_ADDR;
                 }
-              else if (strncmp (input_line_pointer, "%lo", 3) == 0)
+              else if (startswith (input_line_pointer, "%lo"))
                 {
 		  input_line_pointer += 3;
 		  operands[0].mode = M6811_OP_LOW_ADDR;
@@ -3216,9 +3216,9 @@ md_assemble (char *str)
                   opcode = find (opc, operands, 1);
                   if (opcode)
                     {
-                      if ((strncmp (opc->opcode->name, "com",3) == 0)
-			  || (strncmp (opc->opcode->name, "mov",3) == 0)
-			  || (strncmp (opc->opcode->name, "neg",3) == 0))
+                      if ((startswith (opc->opcode->name, "com"))
+			  || (startswith (opc->opcode->name, "mov"))
+			  || (startswith (opc->opcode->name, "neg")))
                         {
                           /* Special cases for:
                              com RD, RS alias for xnor RD,R0,RS
@@ -3227,8 +3227,8 @@ md_assemble (char *str)
                           opcode_local.opcode = opcode->opcode
                             | (operands[0].reg1 << 8) | (operands[1].reg1 << 2);
                         }
-                      else if ((strncmp (opc->opcode->name, "cmp",3) == 0)
-			       || (strncmp (opc->opcode->name, "cpc",3) == 0))
+                      else if ((startswith (opc->opcode->name, "cmp"))
+			       || (startswith (opc->opcode->name, "cpc")))
                         {
                           /* special cases for:
                              cmp RS1, RS2 alias for sub R0, RS1, RS2
diff --git a/gas/config/tc-m68k.c b/gas/config/tc-m68k.c
index 4fd6c45733f..ab40447d215 100644
--- a/gas/config/tc-m68k.c
+++ b/gas/config/tc-m68k.c
@@ -1839,7 +1839,7 @@ m68k_ip (char *instring)
 		case 'B':	/* FOO */
 		  if (opP->mode != ABSL
 		      || (flag_long_jumps
-			  && strncmp (instring, "jbsr", 4) == 0))
+			  && startswith (instring, "jbsr")))
 		    losing++;
 		  break;
 
@@ -2039,8 +2039,8 @@ m68k_ip (char *instring)
 			   || TRUNC (opP->disp.exp.X_add_number) - 1 > 7)
 		    losing++;
 		  else if (! m68k_quick
-			   && (strncmp (instring, "add", 3) == 0
-			       || strncmp (instring, "sub", 3) == 0)
+			   && (startswith (instring, "add")
+			       || startswith (instring, "sub"))
 			   && instring[3] != 'q')
 		    losing++;
 		  break;
@@ -7482,9 +7482,9 @@ md_parse_option (int c, const char *arg)
 #endif
       /* Intentional fall-through.  */
     case 'm':
-      if (!strncmp (arg, "arch=", 5))
+      if (startswith (arg, "arch="))
 	m68k_set_arch (arg + 5, 1, 0);
-      else if (!strncmp (arg, "cpu=", 4))
+      else if (startswith (arg, "cpu="))
 	m68k_set_cpu (arg + 4, 1, 0);
       else if (m68k_set_extension (arg, 0, 1))
 	;
@@ -7861,7 +7861,7 @@ m68k_elf_suffix (char **str_p, expressionS *exp_p)
   *str2 = '\0';
   len = str2 - ident;
 
-  if (strncmp (ident, "TLSLDO", 6) == 0
+  if (startswith (ident, "TLSLDO")
       && len == 6)
     {
       /* Now check for identifier@suffix+constant.  */
diff --git a/gas/config/tc-mcore.c b/gas/config/tc-mcore.c
index bec862bb3af..bfc7c5cb114 100644
--- a/gas/config/tc-mcore.c
+++ b/gas/config/tc-mcore.c
@@ -361,7 +361,7 @@ mcore_s_section (int ignore)
   while (*ilp != 0 && ISSPACE (*ilp))
     ++ ilp;
 
-  if (strncmp (ilp, ".line", 5) == 0
+  if (startswith (ilp, ".line")
       && (ISSPACE (ilp[5]) || *ilp == '\n' || *ilp == '\r'))
     ;
   else
diff --git a/gas/config/tc-metag.c b/gas/config/tc-metag.c
index 25923077795..2a22fe90452 100644
--- a/gas/config/tc-metag.c
+++ b/gas/config/tc-metag.c
@@ -1003,7 +1003,7 @@ parse_get_set (const char *line, metag_insn *insn,
 
   if (is_get)
     {
-      bfd_boolean is_mov = strncmp (template->name, "MOV", 3) == 0;
+      bfd_boolean is_mov = startswith (template->name, "MOV");
 
       l = parse_get (l, regs, &addr, size, is_mov);
 
@@ -5927,8 +5927,7 @@ md_parse_option (int c, const char * arg)
       /* These options are expected to have an argument.  */
       if (c == lopt->option[0]
 	  && arg != NULL
-	  && strncmp (arg, lopt->option + 1,
-		      strlen (lopt->option + 1)) == 0)
+	  && startswith (arg, lopt->option + 1))
 	{
 #if WARN_DEPRECATED
 	      /* If the option is deprecated, tell the user.  */
diff --git a/gas/config/tc-microblaze.c b/gas/config/tc-microblaze.c
index a0f06160759..6b7ecbdee15 100644
--- a/gas/config/tc-microblaze.c
+++ b/gas/config/tc-microblaze.c
@@ -740,7 +740,7 @@ parse_imm (char * s, expressionS * e, offsetT min, offsetT max)
 
   new_pointer = parse_exp (s, e);
 
-  if (!GOT_symbol && ! strncmp (s, GOT_SYMBOL_NAME, 20))
+  if (!GOT_symbol && startswith (s, GOT_SYMBOL_NAME))
     {
       GOT_symbol = symbol_find_or_make (GOT_SYMBOL_NAME);
     }
@@ -785,17 +785,17 @@ check_got (int * got_type, int * got_len)
     if (is_end_of_line[(unsigned char) *atp])
       return NULL;
 
-  if (strncmp (atp + 1, "GOTOFF", 5) == 0)
+  if (startswith (atp + 1, "GOTOFF"))
     {
       *got_len = 6;
       *got_type = IMM_GOTOFF;
     }
-  else if (strncmp (atp + 1, "GOT", 3) == 0)
+  else if (startswith (atp + 1, "GOT"))
     {
       *got_len = 3;
       *got_type = IMM_GOT;
     }
-  else if (strncmp (atp + 1, "PLT", 3) == 0)
+  else if (startswith (atp + 1, "PLT"))
     {
       *got_len = 3;
       *got_type = IMM_PLT;
@@ -2025,9 +2025,8 @@ md_apply_fix (fixS *   fixP,
 	  || (symbol_used_in_reloc_p (fixP->fx_addsy)
 	      && (((bfd_section_flags (S_GET_SEGMENT (fixP->fx_addsy))
 		    & SEC_LINK_ONCE) != 0)
-		  || !strncmp (segment_name (S_GET_SEGMENT (fixP->fx_addsy)),
-			       ".gnu.linkonce",
-			       sizeof (".gnu.linkonce") - 1))))
+		  || startswith (segment_name (S_GET_SEGMENT (fixP->fx_addsy)),
+				 ".gnu.linkonce"))))
 	{
 	  val -= S_GET_VALUE (fixP->fx_addsy);
 	  if (val != 0 && ! fixP->fx_pcrel)
diff --git a/gas/config/tc-mips.c b/gas/config/tc-mips.c
index 538b69710f5..7cb80c69f26 100644
--- a/gas/config/tc-mips.c
+++ b/gas/config/tc-mips.c
@@ -513,8 +513,8 @@ static int mips_32bitmode = 0;
 
 /* Return true if the given CPU supports the MIPS16 ASE.  */
 #define CPU_HAS_MIPS16(cpu)						\
-   (strncmp (TARGET_CPU, "mips16", sizeof ("mips16") - 1) == 0		\
-    || strncmp (TARGET_CANONICAL, "mips-lsi-elf", sizeof ("mips-lsi-elf") - 1) == 0)
+   (startswith (TARGET_CPU, "mips16")					\
+    || startswith (TARGET_CANONICAL, "mips-lsi-elf"))
 
 /* Return true if the given CPU supports the microMIPS ASE.  */
 #define CPU_HAS_MICROMIPS(cpu)	0
@@ -3842,8 +3842,8 @@ md_begin (void)
   /* On a native system other than VxWorks, sections must be aligned
      to 16 byte boundaries.  When configured for an embedded ELF
      target, we don't bother.  */
-  if (strncmp (TARGET_OS, "elf", 3) != 0
-      && strncmp (TARGET_OS, "vxworks", 7) != 0)
+  if (!startswith (TARGET_OS, "elf")
+      && !startswith (TARGET_OS, "vxworks"))
     {
       bfd_set_section_alignment (text_section, 4);
       bfd_set_section_alignment (data_section, 4);
@@ -3865,7 +3865,7 @@ md_begin (void)
        running program can access it.  However, we don't load it
        if we are configured for an embedded target.  */
     flags = SEC_READONLY | SEC_DATA;
-    if (strncmp (TARGET_OS, "elf", 3) != 0)
+    if (!startswith (TARGET_OS, "elf"))
       flags |= SEC_ALLOC | SEC_LOAD;
 
     if (mips_abi != N64_ABI)
@@ -4457,8 +4457,7 @@ s_is_linkonce (symbolS *sym, segT from_seg)
       /* The GNU toolchain uses an extension for ELF: a section
 	 beginning with the magic string .gnu.linkonce is a
 	 linkonce section.  */
-      if (strncmp (segment_name (symseg), ".gnu.linkonce",
-		   sizeof ".gnu.linkonce" - 1) == 0)
+      if (startswith (segment_name (symseg), ".gnu.linkonce"))
 	linkonce = TRUE;
     }
   return linkonce;
@@ -5115,12 +5114,12 @@ check_regno (struct mips_arg_info *arg,
       length = strlen (name);
       if ((regno & 1) != 0
 	  && ((length >= 3 && strcmp (name + length - 3, ".ps") == 0)
-	      || (length >= 5 && strncmp (name + length - 5, "any2", 4) == 0)))
+	      || (length >= 5 && startswith (name + length - 5, "any2"))))
 	as_warn (_("condition code register should be even for %s, was %d"),
 		 name, regno);
 
       if ((regno & 3) != 0
-	  && (length >= 5 && strncmp (name + length - 5, "any4", 4) == 0))
+	  && (length >= 5 && startswith (name + length - 5, "any4")))
 	as_warn (_("condition code register should be 0 or 4 for %s, was %d"),
 		 name, regno);
     }
@@ -6167,7 +6166,7 @@ match_float_constant (struct mips_arg_info *arg, expressionS *imm,
   bfd_set_section_flags (new_seg,
 			 SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA);
   frag_align (length == 4 ? 2 : 3, 0, 0);
-  if (strncmp (TARGET_OS, "elf", 3) != 0)
+  if (!startswith (TARGET_OS, "elf"))
     record_alignment (new_seg, 4);
   else
     record_alignment (new_seg, length == 4 ? 2 : 3);
@@ -6349,13 +6348,13 @@ reg_needs_delay (unsigned int reg)
 static unsigned int
 classify_vr4120_insn (const char *name)
 {
-  if (strncmp (name, "macc", 4) == 0)
+  if (startswith (name, "macc"))
     return FIX_VR4120_MACC;
-  if (strncmp (name, "dmacc", 5) == 0)
+  if (startswith (name, "dmacc"))
     return FIX_VR4120_DMACC;
-  if (strncmp (name, "mult", 4) == 0)
+  if (startswith (name, "mult"))
     return FIX_VR4120_MULT;
-  if (strncmp (name, "dmult", 5) == 0)
+  if (startswith (name, "dmult"))
     return FIX_VR4120_DMULT;
   if (strstr (name, "div"))
     return FIX_VR4120_DIV;
@@ -8295,7 +8294,7 @@ match_insn (struct mips_cl_insn *insn, const struct mips_opcode *opcode,
 	    return TRUE;
 	  clear_insn_error ();
 	  if (arg.dest_regno == arg.last_regno
-	      && strncmp (insn->insn_mo->name, "jalr", 4) == 0)
+	      && startswith (insn->insn_mo->name, "jalr"))
 	    {
 	      if (arg.opnum == 2)
 		set_insn_error
@@ -8305,8 +8304,8 @@ match_insn (struct mips_cl_insn *insn, const struct mips_opcode *opcode,
 		  (0, _("a destination register must be supplied"));
 	    }
 	  else if (arg.last_regno == 31
-		   && (strncmp (insn->insn_mo->name, "bltzal", 6) == 0
-		       || strncmp (insn->insn_mo->name, "bgezal", 6) == 0))
+		   && (startswith (insn->insn_mo->name, "bltzal")
+		       || startswith (insn->insn_mo->name, "bgezal")))
 	    set_insn_error (0, _("the source register must not be $31"));
 	  check_completed_insn (&arg);
 	  return TRUE;
@@ -15251,7 +15250,7 @@ mips_after_parse_args (void)
   const struct mips_cpu_info *tune_info = 0;
 
   /* GP relative stuff not working for PE.  */
-  if (strncmp (TARGET_OS, "pe", 2) == 0)
+  if (startswith (TARGET_OS, "pe"))
     {
       if (g_switch_seen && g_switch_value != 0)
 	as_bad (_("-G not supported in this configuration"));
@@ -16340,7 +16339,7 @@ s_change_sec (int sec)
 			(subsegT) get_absolute_expression ());
       bfd_set_section_flags (seg, (SEC_ALLOC | SEC_LOAD | SEC_READONLY
 				   | SEC_RELOC | SEC_DATA));
-      if (strncmp (TARGET_OS, "elf", 3) != 0)
+      if (!startswith (TARGET_OS, "elf"))
 	record_alignment (seg, 4);
       demand_empty_rest_of_line ();
       break;
@@ -16349,7 +16348,7 @@ s_change_sec (int sec)
       seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
       bfd_set_section_flags (seg, (SEC_ALLOC | SEC_LOAD | SEC_RELOC
 				   | SEC_DATA | SEC_SMALL_DATA));
-      if (strncmp (TARGET_OS, "elf", 3) != 0)
+      if (!startswith (TARGET_OS, "elf"))
 	record_alignment (seg, 4);
       demand_empty_rest_of_line ();
       break;
@@ -16357,7 +16356,7 @@ s_change_sec (int sec)
     case 'B':
       seg = subseg_new (".sbss", (subsegT) get_absolute_expression ());
       bfd_set_section_flags (seg, SEC_ALLOC | SEC_SMALL_DATA);
-      if (strncmp (TARGET_OS, "elf", 3) != 0)
+      if (!startswith (TARGET_OS, "elf"))
 	record_alignment (seg, 4);
       demand_empty_rest_of_line ();
       break;
@@ -16566,7 +16565,7 @@ s_option (int x ATTRIBUTE_UNUSED)
     {
       /* FIXME: What does this mean?  */
     }
-  else if (strncmp (opt, "pic", 3) == 0 && ISDIGIT (opt[3]) && opt[4] == '\0')
+  else if (startswith (opt, "pic") && ISDIGIT (opt[3]) && opt[4] == '\0')
     {
       int i;
 
@@ -16631,7 +16630,7 @@ parse_code_option (char * name)
   bfd_boolean isa_set = FALSE;
   const struct mips_ase *ase;
 
-  if (strncmp (name, "at=", 3) == 0)
+  if (startswith (name, "at="))
     {
       char *s = name + 3;
 
@@ -16688,11 +16687,11 @@ parse_code_option (char * name)
     mips_set_ase (ase, &mips_opts, FALSE);
   else if ((ase = mips_lookup_ase (name)))
     mips_set_ase (ase, &mips_opts, TRUE);
-  else if (strncmp (name, "mips", 4) == 0 || strncmp (name, "arch=", 5) == 0)
+  else if (startswith (name, "mips") || startswith (name, "arch="))
     {
       /* Permit the user to change the ISA and architecture on the fly.
 	 Needless to say, misuse can cause serious problems.  */
-      if (strncmp (name, "arch=", 5) == 0)
+      if (startswith (name, "arch="))
 	{
 	  const struct mips_cpu_info *p;
 
@@ -16707,7 +16706,7 @@ parse_code_option (char * name)
 	      mips_opts.init_ase = p->ase;
 	    }
 	}
-      else if (strncmp (name, "mips", 4) == 0)
+      else if (startswith (name, "mips"))
 	{
 	  const struct mips_cpu_info *p;
 
@@ -17627,7 +17626,7 @@ md_section_align (asection *seg, valueT addr)
      However, Irix 5 may prefer that we align them at least to a 16
      byte boundary.  We don't bother to align the sections if we
      are targeted for an embedded system.  */
-  if (strncmp (TARGET_OS, "elf", 3) == 0)
+  if (startswith (TARGET_OS, "elf"))
     return addr;
   if (align > 4)
     align = 4;
@@ -17695,10 +17694,10 @@ nopic_need_relax (symbolS *sym, int before_relaxing)
 		  && strcmp (segname, ".lit4") != 0);
 	  change = (strcmp (segname, ".sdata") != 0
 		    && strcmp (segname, ".sbss") != 0
-		    && strncmp (segname, ".sdata.", 7) != 0
-		    && strncmp (segname, ".sbss.", 6) != 0
-		    && strncmp (segname, ".gnu.linkonce.sb.", 17) != 0
-		    && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
+		    && !startswith (segname, ".sdata.")
+		    && !startswith (segname, ".sbss.")
+		    && !startswith (segname, ".gnu.linkonce.sb.")
+		    && !startswith (segname, ".gnu.linkonce.s."));
 	}
       return change;
     }
diff --git a/gas/config/tc-mmix.c b/gas/config/tc-mmix.c
index e6efea66d0b..34553c41b47 100644
--- a/gas/config/tc-mmix.c
+++ b/gas/config/tc-mmix.c
@@ -3171,7 +3171,7 @@ mmix_handle_mmixal (void)
     }
   else if (s[0] == 'G'
 	   && s[1] == 'R'
-	   && strncmp (s, "GREG", 4) == 0
+	   && startswith (s, "GREG")
 	   && (ISSPACE (s[4]) || is_end_of_line[(unsigned char) s[4]]))
     {
       input_line_pointer = s + 4;
diff --git a/gas/config/tc-mn10300.c b/gas/config/tc-mn10300.c
index 2f2e956d5a2..f75f3dc3f87 100644
--- a/gas/config/tc-mn10300.c
+++ b/gas/config/tc-mn10300.c
@@ -2427,7 +2427,7 @@ mn10300_fix_adjustable (struct fix *fixp)
   if (! (S_GET_SEGMENT (fixp->fx_addsy)->flags & SEC_MERGE))
     return FALSE;
 
-  if (strncmp (S_GET_SEGMENT (fixp->fx_addsy)->name, ".debug", 6) == 0)
+  if (startswith (S_GET_SEGMENT (fixp->fx_addsy)->name, ".debug"))
     return FALSE;
 
   return TRUE;
@@ -2447,7 +2447,7 @@ mn10300_end_of_match (char *cont, const char *what)
 {
   int len = strlen (what);
 
-  if (strncmp (cont, what, strlen (what)) == 0
+  if (startswith (cont, what)
       && ! is_part_of_name (cont[len]))
     return cont + len;
 
diff --git a/gas/config/tc-msp430.c b/gas/config/tc-msp430.c
index bff7951d6a6..db72237db80 100644
--- a/gas/config/tc-msp430.c
+++ b/gas/config/tc-msp430.c
@@ -1504,16 +1504,16 @@ md_parse_option (int c, const char * arg)
 static void
 msp430_make_init_symbols (const char * name)
 {
-  if (strncmp (name, ".bss", 4) == 0
-      || strncmp (name, ".lower.bss", 10) == 0
-      || strncmp (name, ".either.bss", 11) == 0
-      || strncmp (name, ".gnu.linkonce.b.", 16) == 0)
+  if (startswith (name, ".bss")
+      || startswith (name, ".lower.bss")
+      || startswith (name, ".either.bss")
+      || startswith (name, ".gnu.linkonce.b."))
     (void) symbol_find_or_make ("__crt0_init_bss");
 
-  if (strncmp (name, ".data", 5) == 0
-      || strncmp (name, ".lower.data", 11) == 0
-      || strncmp (name, ".either.data", 12) == 0
-      || strncmp (name, ".gnu.linkonce.d.", 16) == 0)
+  if (startswith (name, ".data")
+      || startswith (name, ".lower.data")
+      || startswith (name, ".either.data")
+      || startswith (name, ".gnu.linkonce.d."))
     (void) symbol_find_or_make ("__crt0_movedata");
   /* Note - data assigned to the .either.data section may end up being
      placed in the .upper.data section if the .lower.data section is
@@ -1521,14 +1521,14 @@ msp430_make_init_symbols (const char * name)
      The linker may create upper or either data sections, even when none exist
      at the moment, so use the value of the data-region flag to determine if
      the symbol is needed.  */
-  if (strncmp (name, ".either.data", 12) == 0
-      || strncmp (name, ".upper.data", 11) == 0
+  if (startswith (name, ".either.data")
+      || startswith (name, ".upper.data")
       || upper_data_region_in_use)
     (void) symbol_find_or_make ("__crt0_move_highdata");
 
   /* See note about .either.data above.  */
-  if (strncmp (name, ".upper.bss", 10) == 0
-      || strncmp (name, ".either.bss", 11) == 0
+  if (startswith (name, ".upper.bss")
+      || startswith (name, ".either.bss")
       || upper_data_region_in_use)
     (void) symbol_find_or_make ("__crt0_init_highbss");
 
@@ -1542,17 +1542,17 @@ msp430_make_init_symbols (const char * name)
      exit() or returning from main.
      __crt0_run_array is required to actually call the functions in the above
      arrays.  */
-  if (strncmp (name, ".init_array", 11) == 0)
+  if (startswith (name, ".init_array"))
     {
       (void) symbol_find_or_make ("__crt0_run_init_array");
       (void) symbol_find_or_make ("__crt0_run_array");
     }
-  else if (strncmp (name, ".preinit_array", 14) == 0)
+  else if (startswith (name, ".preinit_array"))
     {
       (void) symbol_find_or_make ("__crt0_run_preinit_array");
       (void) symbol_find_or_make ("__crt0_run_array");
     }
-  else if (strncmp (name, ".fini_array", 11) == 0)
+  else if (startswith (name, ".fini_array"))
     {
       (void) symbol_find_or_make ("__crt0_run_fini_array");
       (void) symbol_find_or_make ("__crt0_run_array");
diff --git a/gas/config/tc-nds32.c b/gas/config/tc-nds32.c
index 86212e60739..4e0c1ae6249 100644
--- a/gas/config/tc-nds32.c
+++ b/gas/config/tc-nds32.c
@@ -3712,7 +3712,7 @@ nds32_parse_option (int c, const char *arg)
 	  int disable = 0;
 
 	  /* Filter out the Disable option first.  */
-	  if (strncmp (arg, "no-", 3) == 0)
+	  if (startswith (arg, "no-"))
 	    {
 	      disable = 1;
 	      arg += 3;
diff --git a/gas/config/tc-nds32.h b/gas/config/tc-nds32.h
index c806de90c04..249f7dc220d 100644
--- a/gas/config/tc-nds32.h
+++ b/gas/config/tc-nds32.h
@@ -158,7 +158,7 @@ extern void nds32_do_align (int);
 #define md_do_align(N, FILL, LEN, MAX, LABEL)	\
   nds32_pre_do_align (N, FILL, LEN, MAX);	\
   if ((N) > 1 && (subseg_text_p (now_seg)	\
-      || strncmp (now_seg->name, ".gcc_except_table", sizeof(".gcc_except_table") - 1) == 0)) \
+      || startswith (now_seg->name, ".gcc_except_table"))) \
     nds32_do_align (N);				\
   goto LABEL;
 #define md_elf_section_change_hook()		nds32_elf_section_change_hook ()
diff --git a/gas/config/tc-nios2.c b/gas/config/tc-nios2.c
index be4536caa8a..85ed0f0ba7a 100644
--- a/gas/config/tc-nios2.c
+++ b/gas/config/tc-nios2.c
@@ -300,29 +300,24 @@ md_atof (int type, char *litP, int *sizeP)
   return NULL;
 }
 
-/* Return true if STR starts with PREFIX, which should be a string literal.  */
-#define strprefix(STR, PREFIX) \
-  (strncmp ((STR), PREFIX, strlen (PREFIX)) == 0)
-
-
 /* Return true if STR is prefixed with a special relocation operator.  */
 static int
 nios2_special_relocation_p (const char *str)
 {
-  return (strprefix (str, "%lo")
-	  || strprefix (str, "%hi")
-	  || strprefix (str, "%hiadj")
-	  || strprefix (str, "%gprel")
-	  || strprefix (str, "%got")
-	  || strprefix (str, "%call")
-	  || strprefix (str, "%gotoff_lo")
-	  || strprefix (str, "%gotoff_hiadj")
-	  || strprefix (str, "%tls_gd")
-	  || strprefix (str, "%tls_ldm")
-	  || strprefix (str, "%tls_ldo")
-	  || strprefix (str, "%tls_ie")
-	  || strprefix (str, "%tls_le")
-	  || strprefix (str, "%gotoff"));
+  return (startswith (str, "%lo")
+	  || startswith (str, "%hi")
+	  || startswith (str, "%hiadj")
+	  || startswith (str, "%gprel")
+	  || startswith (str, "%got")
+	  || startswith (str, "%call")
+	  || startswith (str, "%gotoff_lo")
+	  || startswith (str, "%gotoff_hiadj")
+	  || startswith (str, "%tls_gd")
+	  || startswith (str, "%tls_ldm")
+	  || startswith (str, "%tls_ldo")
+	  || startswith (str, "%tls_ie")
+	  || startswith (str, "%tls_le")
+	  || startswith (str, "%gotoff"));
 }
 
 
@@ -1678,7 +1673,7 @@ nios2_parse_base_register (char *str, int *direction, int *writeback, int *ret)
   *ret = 0;
 
   /* Check for --.  */
-  if (strncmp (str, "--", 2) == 0)
+  if (startswith (str, "--"))
     {
       str += 2;
       *direction -= 1;
@@ -1705,7 +1700,7 @@ nios2_parse_base_register (char *str, int *direction, int *writeback, int *ret)
     return NULL;
 
   /* Check for ++.  */
-  if (strncmp (str, "++", 2) == 0)
+  if (startswith (str, "++"))
     {
       str += 2;
       *direction += 1;
@@ -1723,12 +1718,12 @@ nios2_parse_base_register (char *str, int *direction, int *writeback, int *ret)
     {
       while (*str == ' ')
 	str++;
-      if (strncmp (str, "writeback", 9) == 0)
+      if (startswith (str, "writeback"))
 	{
 	  *writeback = 1;
 	  str += 9;
 	}
-      else if (strncmp (str, "ret", 3) == 0)
+      else if (startswith (str, "ret"))
 	{
 	  *ret = 1;
 	  str += 3;
@@ -3987,7 +3982,7 @@ nios2_cons (expressionS *exp, int size)
   SKIP_WHITESPACE ();
   if (input_line_pointer[0] == '%')
     {
-      if (strprefix (input_line_pointer + 1, "tls_ldo"))
+      if (startswith (input_line_pointer + 1, "tls_ldo"))
 	{
 	  reloc_name = "%tls_ldo";
 	  if (size != 4)
@@ -3999,7 +3994,7 @@ nios2_cons (expressionS *exp, int size)
 	      explicit_reloc = BFD_RELOC_NIOS2_TLS_DTPREL;
 	    }
 	}
-      else if (strprefix (input_line_pointer + 1, "gotoff"))
+      else if (startswith (input_line_pointer + 1, "gotoff"))
 	{
 	  reloc_name = "%gotoff";
 	  if (size != 4)
diff --git a/gas/config/tc-ns32k.c b/gas/config/tc-ns32k.c
index 82e27861f9b..cf7894afb23 100644
--- a/gas/config/tc-ns32k.c
+++ b/gas/config/tc-ns32k.c
@@ -442,7 +442,7 @@ addr_mode (char *operand,
     case 'e':
       if (str[strl - 1] != ']')
 	{
-	  if ((!strncmp (str, "ext(", 4)) && strl > 7)
+	  if ((startswith (str, "ext(")) && strl > 7)
 	    {				/* external */
 	      addrmodeP->disp[0] = str + 4;
 	      i = 0;
@@ -496,7 +496,7 @@ addr_mode (char *operand,
       /* Fall through.  */
 
     case 3:
-      if (!strncmp (str, "tos", 3))
+      if (startswith (str, "tos"))
 	{
 	  addrmodeP->mode = 23;	/* TopOfStack */
 	  return -1;
@@ -513,11 +513,11 @@ addr_mode (char *operand,
 	{
 	  if (str[strl - 2] == ')')
 	    {
-	      if (!strncmp (&str[strl - 5], "(fp", 3))
+	      if (startswith (&str[strl - 5], "(fp"))
 		mode = 16;		/* Memory Relative.  */
-	      else if (!strncmp (&str[strl - 5], "(sp", 3))
+	      else if (startswith (&str[strl - 5], "(sp"))
 		mode = 17;
-	      else if (!strncmp (&str[strl - 5], "(sb", 3))
+	      else if (startswith (&str[strl - 5], "(sb"))
 		mode = 18;
 
 	      if (mode != DEFAULT)
@@ -568,13 +568,13 @@ addr_mode (char *operand,
 	      /* Fall through.  */
 
 	    default:
-	      if (!strncmp (&str[strl - 4], "(fp", 3))
+	      if (startswith (&str[strl - 4], "(fp"))
 		mode = 24;
-	      else if (!strncmp (&str[strl - 4], "(sp", 3))
+	      else if (startswith (&str[strl - 4], "(sp"))
 		mode = 25;
-	      else if (!strncmp (&str[strl - 4], "(sb", 3))
+	      else if (startswith (&str[strl - 4], "(sb"))
 		mode = 26;
-	      else if (!strncmp (&str[strl - 4], "(pc", 3))
+	      else if (startswith (&str[strl - 4], "(pc"))
 		mode = 27;
 
 	      if (mode != DEFAULT)
diff --git a/gas/config/tc-pdp11.c b/gas/config/tc-pdp11.c
index 2b01fbc5836..fc544ae43a7 100644
--- a/gas/config/tc-pdp11.c
+++ b/gas/config/tc-pdp11.c
@@ -103,7 +103,7 @@ set_option (const char *arg)
       return 1;
     }
 
-  if (strncmp (arg, "no-", 3) == 0)
+  if (startswith (arg, "no-"))
     {
       yes = 0;
       arg += 3;
@@ -143,9 +143,9 @@ set_option (const char *arg)
   else if (strcmp (arg, "mfpt") == 0)
     pdp11_extension[PDP11_MFPT] = yes;
   /* Multiprocessor insns:  */
-  else if (strncmp (arg, "mproc", 5) == 0
+  else if (startswith (arg, "mproc")
 	   /* TSTSET, WRTLCK */
-	   || strncmp (arg, "multiproc", 9) == 0)
+	   || startswith (arg, "multiproc"))
     pdp11_extension[PDP11_MPROC] = yes;
   /* Move from/to proc status.  */
   else if (strcmp (arg, "mxps") == 0)
@@ -355,14 +355,14 @@ parse_reg (char *str, struct pdp11_code *operand)
 	  return str - 1;
 	}
     }
-  else if (strncmp (str, "sp", 2) == 0
-	   || strncmp (str, "SP", 2) == 0)
+  else if (startswith (str, "sp")
+	   || startswith (str, "SP"))
     {
       operand->code = 6;
       str += 2;
     }
-  else if (strncmp (str, "pc", 2) == 0
-	   || strncmp (str, "PC", 2) == 0)
+  else if (startswith (str, "pc")
+	   || startswith (str, "PC"))
     {
       operand->code = 7;
       str += 2;
@@ -386,10 +386,10 @@ static char *
 parse_ac5 (char *str, struct pdp11_code *operand)
 {
   str = skip_whitespace (str);
-  if (strncmp (str, "fr", 2) == 0
-      || strncmp (str, "FR", 2) == 0
-      || strncmp (str, "ac", 2) == 0
-      || strncmp (str, "AC", 2) == 0)
+  if (startswith (str, "fr")
+      || startswith (str, "FR")
+      || startswith (str, "ac")
+      || startswith (str, "AC"))
     {
       str += 2;
       switch (*str)
@@ -522,7 +522,7 @@ parse_op_no_deferred (char *str, struct pdp11_code *operand)
       /* label, d(rn), -(rn)  */
     default:
       {
-	if (strncmp (str, "-(", 2) == 0)	/* -(rn) */
+	if (startswith (str, "-("))	/* -(rn) */
 	  {
 	    str = parse_reg (str + 2, operand);
 	    if (operand->error)
@@ -1117,7 +1117,7 @@ set_cpu_model (const char *arg)
   if (arg[0] == '-')
     arg++;
 
-  if (strncmp (arg, "11", 2) != 0)
+  if (!startswith (arg, "11"))
     return 0;
   arg += 2;
 
@@ -1138,43 +1138,43 @@ set_cpu_model (const char *arg)
   set_option ("no-extensions");
 
   /* KA11 (11/15/20).  */
-  if (strncmp (buf, "a", 1) == 0)
+  if (startswith (buf, "a"))
     return 1; /* No extensions.  */
 
   /* KB11 (11/45/50/55/70).  */
-  else if (strncmp (buf, "b", 1) == 0)
+  else if (startswith (buf, "b"))
     return set_option ("eis") && set_option ("spl");
 
   /* KD11-A (11/35/40).  */
-  else if (strncmp (buf, "da", 2) == 0)
+  else if (startswith (buf, "da"))
     return set_option ("limited-eis");
 
   /* KD11-B (11/05/10).  */
-  else if (strncmp (buf, "db", 2) == 0
+  else if (startswith (buf, "db")
 	   /* KD11-D (11/04).  */
-	   || strncmp (buf, "dd", 2) == 0)
+	   || startswith (buf, "dd"))
     return 1; /* no extensions */
 
   /* KD11-E (11/34).  */
-  else if (strncmp (buf, "de", 2) == 0)
+  else if (startswith (buf, "de"))
     return set_option ("eis") && set_option ("mxps");
 
   /* KD11-F (11/03).  */
-  else if (strncmp (buf, "df", 2) == 0
+  else if (startswith (buf, "df")
 	   /* KD11-H (11/03).  */
-	   || strncmp (buf, "dh", 2) == 0
+	   || startswith (buf, "dh")
 	   /* KD11-Q (11/03).  */
-	   || strncmp (buf, "dq", 2) == 0)
+	   || startswith (buf, "dq"))
     return set_option ("limited-eis") && set_option ("mxps");
 
   /* KD11-K (11/60).  */
-  else if (strncmp (buf, "dk", 2) == 0)
+  else if (startswith (buf, "dk"))
     return set_option ("eis")
       && set_option ("mxps")
       && set_option ("ucode");
 
   /* KD11-Z (11/44).  */
-  else if (strncmp (buf, "dz", 2) == 0)
+  else if (startswith (buf, "dz"))
     return set_option ("csm")
       && set_option ("eis")
       && set_option ("mfpt")
@@ -1182,13 +1182,13 @@ set_cpu_model (const char *arg)
       && set_option ("spl");
 
   /* F11 (11/23/24).  */
-  else if (strncmp (buf, "f", 1) == 0)
+  else if (startswith (buf, "f"))
     return set_option ("eis")
       && set_option ("mfpt")
       && set_option ("mxps");
 
   /* J11 (11/53/73/83/84/93/94).  */
-  else if (strncmp (buf, "j", 1) == 0)
+  else if (startswith (buf, "j"))
     return set_option ("csm")
       && set_option ("eis")
       && set_option ("mfpt")
@@ -1197,7 +1197,7 @@ set_cpu_model (const char *arg)
       && set_option ("spl");
 
   /* T11 (11/21).  */
-  else if (strncmp (buf, "t", 1) == 0)
+  else if (startswith (buf, "t"))
     return set_option ("limited-eis")
       && set_option ("mxps");
 
@@ -1208,16 +1208,16 @@ set_cpu_model (const char *arg)
 static int
 set_machine_model (const char *arg)
 {
-  if (strncmp (arg, "pdp-11/", 7) != 0
-      && strncmp (arg, "pdp11/", 6) != 0
-      && strncmp (arg, "11/", 3) != 0)
+  if (!startswith (arg, "pdp-11/")
+      && !startswith (arg, "pdp11/")
+      && !startswith (arg, "11/"))
     return 0;
 
-  if (strncmp (arg, "pdp", 3) == 0)
+  if (startswith (arg, "pdp"))
     arg += 3;
   if (arg[0] == '-')
     arg++;
-  if (strncmp (arg, "11/", 3) == 0)
+  if (startswith (arg, "11/"))
     arg += 3;
 
   if (strcmp (arg, "03") == 0)
diff --git a/gas/config/tc-pj.c b/gas/config/tc-pj.c
index 4127ffd4d67..72391f6ef1d 100644
--- a/gas/config/tc-pj.c
+++ b/gas/config/tc-pj.c
@@ -58,7 +58,7 @@ const char EXP_CHARS[] = "eE";
 void
 md_operand (expressionS *op)
 {
-  if (strncmp (input_line_pointer, "%hi16", 5) == 0)
+  if (startswith (input_line_pointer, "%hi16"))
     {
       if (pending_reloc)
 	as_bad (_("confusing relocation expressions"));
@@ -67,7 +67,7 @@ md_operand (expressionS *op)
       expression (op);
     }
 
-  if (strncmp (input_line_pointer, "%lo16", 5) == 0)
+  if (startswith (input_line_pointer, "%lo16"))
     {
       if (pending_reloc)
 	as_bad (_("confusing relocation expressions"));
diff --git a/gas/config/tc-ppc.c b/gas/config/tc-ppc.c
index 0c78b93977a..85fe06c1e9d 100644
--- a/gas/config/tc-ppc.c
+++ b/gas/config/tc-ppc.c
@@ -1304,7 +1304,7 @@ is_ppc64_target (const bfd_target *targ, void *data ATTRIBUTE_UNUSED)
     {
 #ifdef OBJ_ELF
     case bfd_target_elf_flavour:
-      return strncmp (targ->name, "elf64-powerpc", 13) == 0;
+      return startswith (targ->name, "elf64-powerpc");
 #endif
 #ifdef OBJ_XCOFF
     case bfd_target_xcoff_flavour:
@@ -1458,14 +1458,14 @@ ppc_set_cpu (void)
 	else
 	  /* The minimum supported cpu for 64-bit little-endian is power8.  */
 	  ppc_cpu |= ppc_parse_cpu (ppc_cpu, &sticky, "power8");
-      else if (strncmp (default_os, "aix", 3) == 0
+      else if (startswith (default_os, "aix")
 	       && default_os[3] >= '4' && default_os[3] <= '9')
 	ppc_cpu |= PPC_OPCODE_COMMON;
-      else if (strncmp (default_os, "aix3", 4) == 0)
+      else if (startswith (default_os, "aix3"))
 	ppc_cpu |= PPC_OPCODE_POWER;
       else if (strcmp (default_cpu, "rs6000") == 0)
 	ppc_cpu |= PPC_OPCODE_POWER;
-      else if (strncmp (default_cpu, "powerpc", 7) == 0)
+      else if (startswith (default_cpu, "powerpc"))
 	ppc_cpu |= PPC_OPCODE_PPC;
       else
 	as_fatal (_("unknown default cpu = %s, os = %s"),
@@ -1492,7 +1492,7 @@ ppc_arch (void)
     {
       if (strcmp (default_cpu, "rs6000") == 0)
 	return bfd_arch_rs6000;
-      else if (strncmp (default_cpu, "powerpc", 7) == 0)
+      else if (startswith (default_cpu, "powerpc"))
 	return bfd_arch_powerpc;
     }
 
@@ -4183,7 +4183,7 @@ ppc_macro (char *str, const struct powerpc_macro *macro)
 int
 ppc_section_type (char *str, size_t len)
 {
-  if (len == 7 && strncmp (str, "ordered", 7) == 0)
+  if (len == 7 && startswith (str, "ordered"))
     return SHT_ORDERED;
 
   return -1;
diff --git a/gas/config/tc-s12z.c b/gas/config/tc-s12z.c
index e9d36bdfae6..1c6eedb3bfc 100644
--- a/gas/config/tc-s12z.c
+++ b/gas/config/tc-s12z.c
@@ -2804,17 +2804,17 @@ tb_reg_rel  (const struct instruction *insn)
   if (reg == REG_Y)
     lb |= 0x01;
 
-  if (0 == strncmp (insn->name + 2, "ne", 2))
+  if (startswith (insn->name + 2, "ne"))
     lb |= 0x00 << 4;
-  else if (0 == strncmp (insn->name + 2, "eq", 2))
+  else if (startswith (insn->name + 2, "eq"))
     lb |= 0x01 << 4;
-  else if (0 == strncmp (insn->name + 2, "pl", 2))
+  else if (startswith (insn->name + 2, "pl"))
     lb |= 0x02 << 4;
-  else if (0 == strncmp (insn->name + 2, "mi", 2))
+  else if (startswith (insn->name + 2, "mi"))
     lb |= 0x03 << 4;
-  else if (0 == strncmp (insn->name + 2, "gt", 2))
+  else if (startswith (insn->name + 2, "gt"))
     lb |= 0x04 << 4;
-  else if (0 == strncmp (insn->name + 2, "le", 2))
+  else if (startswith (insn->name + 2, "le"))
     lb |= 0x05 << 4;
 
   switch (insn->name[0])
@@ -2865,17 +2865,17 @@ tb_opr_rel  (const struct instruction *insn)
 
   uint8_t lb = 0x0C;
 
-  if (0 == strncmp (insn->name + 2, "ne", 2))
+  if (startswith (insn->name + 2, "ne"))
     lb |= 0x00 << 4;
-  else if (0 == strncmp (insn->name + 2, "eq", 2))
+  else if (startswith (insn->name + 2, "eq"))
     lb |= 0x01 << 4;
-  else if (0 == strncmp (insn->name + 2, "pl", 2))
+  else if (startswith (insn->name + 2, "pl"))
     lb |= 0x02 << 4;
-  else if (0 == strncmp (insn->name + 2, "mi", 2))
+  else if (startswith (insn->name + 2, "mi"))
     lb |= 0x03 << 4;
-  else if (0 == strncmp (insn->name + 2, "gt", 2))
+  else if (startswith (insn->name + 2, "gt"))
     lb |= 0x04 << 4;
-  else if (0 == strncmp (insn->name + 2, "le", 2))
+  else if (startswith (insn->name + 2, "le"))
     lb |= 0x05 << 4;
 
   switch (insn->name[0])
diff --git a/gas/config/tc-s390.c b/gas/config/tc-s390.c
index f23d9863d3d..7576a212147 100644
--- a/gas/config/tc-s390.c
+++ b/gas/config/tc-s390.c
@@ -312,7 +312,7 @@ s390_parse_cpu (const char *         arg,
   char *ilp_bak;
 
   icpu = S390_OPCODE_MAXCPU;
-  if (strncmp (arg, "all", 3) == 0 && (arg[3] == 0 || arg[3] == '+'))
+  if (startswith (arg, "all") && (arg[3] == 0 || arg[3] == '+'))
     {
       icpu = S390_OPCODE_MAXCPU - 1;
       arg += 3;
@@ -427,7 +427,7 @@ md_parse_option (int c, const char *arg)
 	  current_mode_mask = 1 << S390_OPCODE_ZARCH;
 	}
 
-      else if (arg != NULL && strncmp (arg, "arch=", 5) == 0)
+      else if (arg != NULL && startswith (arg, "arch="))
 	{
 	  current_cpu = s390_parse_cpu (arg + 5, &current_flags, FALSE);
 	  if (current_cpu == S390_OPCODE_MAXCPU)
diff --git a/gas/config/tc-score.c b/gas/config/tc-score.c
index b48fd7a5d8a..fab14d9a2fd 100644
--- a/gas/config/tc-score.c
+++ b/gas/config/tc-score.c
@@ -4832,8 +4832,8 @@ s3_nopic_need_relax (symbolS * sym, int before_relaxing)
       segname = segment_name (S_GET_SEGMENT (sym));
       return (strcmp (segname, ".sdata") != 0
 	      && strcmp (segname, ".sbss") != 0
-	      && strncmp (segname, ".sdata.", 7) != 0
-	      && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
+	      && !startswith (segname, ".sdata.")
+	      && !startswith (segname, ".gnu.linkonce.s."));
     }
   /* We are not optimizing for the $gp register.  */
   else
@@ -5313,8 +5313,7 @@ s3_pic_need_relax (symbolS *sym, asection *segtype)
       /* The GNU toolchain uses an extension for ELF: a section
 	 beginning with the magic string .gnu.linkonce is a linkonce
 	 section.  */
-      if (strncmp (segment_name (symsec), ".gnu.linkonce",
-		   sizeof ".gnu.linkonce" - 1) == 0)
+      if (startswith (segment_name (symsec), ".gnu.linkonce"))
 	linkonce = TRUE;
     }
 
diff --git a/gas/config/tc-score7.c b/gas/config/tc-score7.c
index b1194b3da00..fb39acf3407 100644
--- a/gas/config/tc-score7.c
+++ b/gas/config/tc-score7.c
@@ -4626,8 +4626,8 @@ s7_nopic_need_relax (symbolS * sym, int before_relaxing)
       segname = segment_name (S_GET_SEGMENT (sym));
       return (strcmp (segname, ".sdata") != 0
 	      && strcmp (segname, ".sbss") != 0
-	      && strncmp (segname, ".sdata.", 7) != 0
-	      && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
+	      && !startswith (segname, ".sdata.")
+	      && !startswith (segname, ".gnu.linkonce.s."));
     }
   /* We are not optimizing for the $gp register.  */
   else
@@ -5195,8 +5195,7 @@ s7_pic_need_relax (symbolS *sym, asection *segtype)
       /* The GNU toolchain uses an extension for ELF: a section
 	  beginning with the magic string .gnu.linkonce is a linkonce
 	  section.  */
-      if (strncmp (segment_name (symsec), ".gnu.linkonce",
-		   sizeof ".gnu.linkonce" - 1) == 0)
+      if (startswith (segment_name (symsec), ".gnu.linkonce"))
 	linkonce = TRUE;
     }
 
diff --git a/gas/config/tc-sh.h b/gas/config/tc-sh.h
index 99a8c33426e..484d7a2d1cb 100644
--- a/gas/config/tc-sh.h
+++ b/gas/config/tc-sh.h
@@ -140,9 +140,9 @@ extern void sh_frob_file (void);
 
 /* We align most sections to a 16 byte boundary.  */
 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN)			\
-  (strncmp (SEG_NAME (SEG), ".stabstr", 8) == 0		\
+  (startswith (SEG_NAME (SEG), ".stabstr")		\
    ? 0							\
-   : ((strncmp (SEG_NAME (SEG), ".stab", 5) == 0	\
+   : ((startswith (SEG_NAME (SEG), ".stab")	\
        || strcmp (SEG_NAME (SEG), ".ctors") == 0	\
        || strcmp (SEG_NAME (SEG), ".dtors") == 0)	\
       ? 2						\
diff --git a/gas/config/tc-sparc.c b/gas/config/tc-sparc.c
index 61cd27d7239..b8723819ade 100644
--- a/gas/config/tc-sparc.c
+++ b/gas/config/tc-sparc.c
@@ -460,13 +460,13 @@ md_parse_option (int c, const char *arg)
       break;
 
     case OPTION_XARCH:
-      if (!strncmp (arg, "v9", 2))
+      if (startswith (arg, "v9"))
 	md_parse_option (OPTION_64, NULL);
       else
 	{
-	  if (!strncmp (arg, "v8", 2)
-	      || !strncmp (arg, "v7", 2)
-	      || !strncmp (arg, "v6", 2)
+	  if (startswith (arg, "v8")
+	      || startswith (arg, "v7")
+	      || startswith (arg, "v6")
 	      || !strcmp (arg, "sparclet")
 	      || !strcmp (arg, "sparclite")
 	      || !strcmp (arg, "sparc86x"))
@@ -1984,7 +1984,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 
 	    case 'M':
 	    case 'm':
-	      if (strncmp (s, "%asr", 4) == 0)
+	      if (startswith (s, "%asr"))
 		{
 		  s += 4;
 
@@ -2131,8 +2131,8 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 		{
 		  ++s;
 		}
-	      if ((strncmp (s, "%icc", 4) == 0)
-                  || (sparc_arch_size == 32 && strncmp (s, "%ncc", 4) == 0))
+	      if ((startswith (s, "%icc"))
+                  || (sparc_arch_size == 32 && startswith (s, "%ncc")))
 		{
 		  s += 4;
 		  continue;
@@ -2144,8 +2144,8 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 		{
 		  ++s;
 		}
-              if ((strncmp (s, "%xcc", 4) == 0)
-                  || (sparc_arch_size == 64 && strncmp (s, "%ncc", 4) == 0))
+              if ((startswith (s, "%xcc"))
+                  || (sparc_arch_size == 64 && startswith (s, "%ncc")))
 		{
 		  s += 4;
 		  continue;
@@ -2157,7 +2157,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 		{
 		  ++s;
 		}
-	      if (strncmp (s, "%fcc0", 5) == 0)
+	      if (startswith (s, "%fcc0"))
 		{
 		  s += 5;
 		  continue;
@@ -2169,7 +2169,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 		{
 		  ++s;
 		}
-	      if (strncmp (s, "%fcc1", 5) == 0)
+	      if (startswith (s, "%fcc1"))
 		{
 		  s += 5;
 		  continue;
@@ -2181,7 +2181,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 		{
 		  ++s;
 		}
-	      if (strncmp (s, "%fcc2", 5) == 0)
+	      if (startswith (s, "%fcc2"))
 		{
 		  s += 5;
 		  continue;
@@ -2193,7 +2193,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 		{
 		  ++s;
 		}
-	      if (strncmp (s, "%fcc3", 5) == 0)
+	      if (startswith (s, "%fcc3"))
 		{
 		  s += 5;
 		  continue;
@@ -2201,7 +2201,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 	      break;
 
 	    case 'P':
-	      if (strncmp (s, "%pc", 3) == 0)
+	      if (startswith (s, "%pc"))
 		{
 		  s += 3;
 		  continue;
@@ -2209,7 +2209,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 	      break;
 
 	    case 'W':
-	      if (strncmp (s, "%tick", 5) == 0)
+	      if (startswith (s, "%tick"))
 		{
 		  s += 5;
 		  continue;
@@ -2316,7 +2316,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 	      break;
 
 	    case 'C':		/* Coprocessor state register.  */
-	      if (strncmp (s, "%csr", 4) == 0)
+	      if (startswith (s, "%csr"))
 		{
 		  s += 4;
 		  continue;
@@ -2635,7 +2635,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 	      }			/* float arg  */
 
 	    case 'F':
-	      if (strncmp (s, "%fsr", 4) == 0)
+	      if (startswith (s, "%fsr"))
 		{
 		  s += 4;
 		  continue;
@@ -2643,7 +2643,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 	      break;
 
 	    case '(':
-	      if (strncmp (s, "%efsr", 5) == 0)
+	      if (startswith (s, "%efsr"))
 		{
 		  s += 5;
 		  continue;
@@ -2980,7 +2980,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 	      }			/* Alternate space.  */
 
 	    case 'p':
-	      if (strncmp (s, "%psr", 4) == 0)
+	      if (startswith (s, "%psr"))
 		{
 		  s += 4;
 		  continue;
@@ -2988,7 +2988,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 	      break;
 
 	    case 'q':		/* Floating point queue.  */
-	      if (strncmp (s, "%fq", 3) == 0)
+	      if (startswith (s, "%fq"))
 		{
 		  s += 3;
 		  continue;
@@ -2996,7 +2996,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 	      break;
 
 	    case 'Q':		/* Coprocessor queue.  */
-	      if (strncmp (s, "%cq", 3) == 0)
+	      if (startswith (s, "%cq"))
 		{
 		  s += 3;
 		  continue;
@@ -3020,7 +3020,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 		  special_case = SPECIAL_CASE_SETX;
 		  continue;
 		}
-	      else if (strncmp (str, "fdiv", 4) == 0)
+	      else if (startswith (str, "fdiv"))
 		{
 		  special_case = SPECIAL_CASE_FDIV;
 		  continue;
@@ -3028,43 +3028,43 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 	      break;
 
 	    case 'o':
-	      if (strncmp (s, "%asi", 4) != 0)
+	      if (!startswith (s, "%asi"))
 		break;
 	      s += 4;
 	      continue;
 
 	    case 's':
-	      if (strncmp (s, "%fprs", 5) != 0)
+	      if (!startswith (s, "%fprs"))
 		break;
 	      s += 5;
 	      continue;
 
 	    case '{':
-	      if (strncmp (s, "%mcdper",7) != 0)
+	      if (!startswith (s, "%mcdper"))
 		break;
 	      s += 7;
 	      continue;
 
             case '&':
-              if (strncmp (s, "%entropy", 8) != 0)
+              if (!startswith (s, "%entropy"))
                 break;
               s += 8;
               continue;
 
 	    case 'E':
-	      if (strncmp (s, "%ccr", 4) != 0)
+	      if (!startswith (s, "%ccr"))
 		break;
 	      s += 4;
 	      continue;
 
 	    case 't':
-	      if (strncmp (s, "%tbr", 4) != 0)
+	      if (!startswith (s, "%tbr"))
 		break;
 	      s += 4;
 	      continue;
 
 	    case 'w':
-	      if (strncmp (s, "%wim", 4) != 0)
+	      if (!startswith (s, "%wim"))
 		break;
 	      s += 4;
 	      continue;
@@ -3112,7 +3112,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 	      }
 
 	    case 'y':
-	      if (strncmp (s, "%y", 2) != 0)
+	      if (!startswith (s, "%y"))
 		break;
 	      s += 2;
 	      continue;
@@ -4138,8 +4138,8 @@ s_reserve (int ignore ATTRIBUTE_UNUSED)
   symbolP = symbol_find_or_make (name);
   *p = c;
 
-  if (strncmp (input_line_pointer, ",\"bss\"", 6) != 0
-      && strncmp (input_line_pointer, ",\".bss\"", 7) != 0)
+  if (!startswith (input_line_pointer, ",\"bss\"")
+      && !startswith (input_line_pointer, ",\".bss\""))
     {
       as_bad (_("bad .reserve segment -- expected BSS segment"));
       return;
@@ -4352,8 +4352,8 @@ s_common (int ignore ATTRIBUTE_UNUSED)
       if (*input_line_pointer == '.')
 	input_line_pointer++;
       /* @@ Some say data, some say bss.  */
-      if (strncmp (input_line_pointer, "bss\"", 4)
-	  && strncmp (input_line_pointer, "data\"", 5))
+      if (!startswith (input_line_pointer, "bss\"")
+	  && !startswith (input_line_pointer, "data\""))
 	{
 	  while (*--input_line_pointer != '"')
 	    ;
@@ -4400,25 +4400,25 @@ static void
 s_seg (int ignore ATTRIBUTE_UNUSED)
 {
 
-  if (strncmp (input_line_pointer, "\"text\"", 6) == 0)
+  if (startswith (input_line_pointer, "\"text\""))
     {
       input_line_pointer += 6;
       s_text (0);
       return;
     }
-  if (strncmp (input_line_pointer, "\"data\"", 6) == 0)
+  if (startswith (input_line_pointer, "\"data\""))
     {
       input_line_pointer += 6;
       s_data (0);
       return;
     }
-  if (strncmp (input_line_pointer, "\"data1\"", 7) == 0)
+  if (startswith (input_line_pointer, "\"data1\""))
     {
       input_line_pointer += 7;
       s_data1 ();
       return;
     }
-  if (strncmp (input_line_pointer, "\"bss\"", 5) == 0)
+  if (startswith (input_line_pointer, "\"bss\""))
     {
       input_line_pointer += 5;
       /* We only support 2 segments -- text and data -- for now, so
@@ -4728,12 +4728,12 @@ sparc_cons (expressionS *exp, int size)
       && input_line_pointer[1] == 'r'
       && input_line_pointer[2] == '_')
     {
-      if (strncmp (input_line_pointer + 3, "disp", 4) == 0)
+      if (startswith (input_line_pointer + 3, "disp"))
 	{
 	  input_line_pointer += 7;
 	  sparc_cons_special_reloc = "disp";
 	}
-      else if (strncmp (input_line_pointer + 3, "plt", 3) == 0)
+      else if (startswith (input_line_pointer + 3, "plt"))
 	{
 	  if (size != 4 && size != 8)
 	    as_bad (_("Illegal operands: %%r_plt in %d-byte data field"), size);
@@ -4743,7 +4743,7 @@ sparc_cons (expressionS *exp, int size)
 	      sparc_cons_special_reloc = "plt";
 	    }
 	}
-      else if (strncmp (input_line_pointer + 3, "tls_dtpoff", 10) == 0)
+      else if (startswith (input_line_pointer + 3, "tls_dtpoff"))
 	{
 	  if (size != 4 && size != 8)
 	    as_bad (_("Illegal operands: %%r_tls_dtpoff in %d-byte data field"), size);
diff --git a/gas/config/tc-tic54x.c b/gas/config/tc-tic54x.c
index da2c755946c..f0eb0b11adb 100644
--- a/gas/config/tc-tic54x.c
+++ b/gas/config/tc-tic54x.c
@@ -609,7 +609,7 @@ stag_add_field (struct stag *parent,
       sf->next = sfield;
     }
   /* Only create a symbol for this field if the parent has no name.  */
-  if (!strncmp (".fake", parent->name, 5))
+  if (startswith (parent->name, ".fake"))
     {
       symbolS *sym = symbol_new (name, absolute_section, &zero_address_frag,
 				 offset);
@@ -705,7 +705,7 @@ tic54x_endstruct (int is_union)
 {
   int size;
   const char *path =
-    !strncmp (current_stag->name, ".fake", 5) ? "" : current_stag->name;
+    startswith (current_stag->name, ".fake") ? "" : current_stag->name;
 
   if (!current_stag || current_stag->is_union != is_union)
     {
diff --git a/gas/config/tc-tic6x.c b/gas/config/tc-tic6x.c
index e2304c58139..0aec66653b7 100644
--- a/gas/config/tc-tic6x.c
+++ b/gas/config/tc-tic6x.c
@@ -4629,8 +4629,7 @@ tic6x_start_unwind_section (const segT text_seg, int idx)
   if (streq (text_name, ".text"))
     text_name = "";
 
-  if (strncmp (text_name, ".gnu.linkonce.t.",
-	       strlen (".gnu.linkonce.t.")) == 0)
+  if (startswith (text_name, ".gnu.linkonce.t."))
     {
       prefix = prefix_once;
       text_name += strlen (".gnu.linkonce.t.");
diff --git a/gas/config/tc-v850.c b/gas/config/tc-v850.c
index d93dfc6e50c..2d92a6e33da 100644
--- a/gas/config/tc-v850.c
+++ b/gas/config/tc-v850.c
@@ -481,8 +481,8 @@ v850_comm (int area)
 	input_line_pointer++;
 
       /* @@ Some say data, some say bss.  */
-      if (strncmp (input_line_pointer, "bss\"", 4)
-	  && strncmp (input_line_pointer, "data\"", 5))
+      if (!startswith (input_line_pointer, "bss\"")
+	  && !startswith (input_line_pointer, "data\""))
 	{
 	  while (*--input_line_pointer != '"')
 	    ;
@@ -1888,7 +1888,7 @@ md_begin (void)
   const char *prev_name = "";
   const struct v850_opcode *op;
 
-  if (strncmp (TARGET_CPU, "v850e3v5", 8) == 0)
+  if (startswith (TARGET_CPU, "v850e3v5"))
     {
       if (machine == -1)
 	machine = bfd_mach_v850e3v5;
@@ -1896,7 +1896,7 @@ md_begin (void)
       if (!processor_mask)
 	SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850E3V5);
     }
-  else if (strncmp (TARGET_CPU, "v850e2v4", 8) == 0)
+  else if (startswith (TARGET_CPU, "v850e2v4"))
     {
       if (machine == -1)
 	machine = bfd_mach_v850e3v5;
@@ -1904,7 +1904,7 @@ md_begin (void)
       if (!processor_mask)
 	SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850E3V5);
     }
-  else if (strncmp (TARGET_CPU, "v850e2v3", 8) == 0)
+  else if (startswith (TARGET_CPU, "v850e2v3"))
     {
       if (machine == -1)
         machine = bfd_mach_v850e2v3;
@@ -1912,7 +1912,7 @@ md_begin (void)
       if (!processor_mask)
         SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850E2V3);
     }
-  else if (strncmp (TARGET_CPU, "v850e2", 6) == 0)
+  else if (startswith (TARGET_CPU, "v850e2"))
     {
       if (machine == -1)
 	machine = bfd_mach_v850e2;
@@ -1920,7 +1920,7 @@ md_begin (void)
       if (!processor_mask)
 	SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850E2);
     }
-  else if (strncmp (TARGET_CPU, "v850e1", 6) == 0)
+  else if (startswith (TARGET_CPU, "v850e1"))
     {
       if (machine == -1)
         machine = bfd_mach_v850e1;
@@ -1928,7 +1928,7 @@ md_begin (void)
       if (!processor_mask)
         SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850E1);
     }
-  else if (strncmp (TARGET_CPU, "v850e", 5) == 0)
+  else if (startswith (TARGET_CPU, "v850e"))
     {
       if (machine == -1)
 	machine = bfd_mach_v850e;
@@ -1936,7 +1936,7 @@ md_begin (void)
       if (!processor_mask)
 	SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850E);
     }
-  else if (strncmp (TARGET_CPU, "v850", 4) == 0)
+  else if (startswith (TARGET_CPU, "v850"))
     {
       if (machine == -1)
 	machine = 0;
@@ -2348,9 +2348,9 @@ md_assemble (char *str)
 
       if (no_stld23)
 	{
-	  if ((strncmp (opcode->name, "st.", 3) == 0
+	  if ((startswith (opcode->name, "st.")
 	       && v850_operands[opcode->operands[1]].bits == 23)
-	      || (strncmp (opcode->name, "ld.", 3) == 0
+	      || (startswith (opcode->name, "ld.")
 		  && v850_operands[opcode->operands[0]].bits == 23))
 	    {
 	      errmsg = _("st/ld offset 23 instruction was disabled .");
@@ -2949,8 +2949,8 @@ md_assemble (char *str)
                      value does not fit into the bits available then create a
                      fake error so that the next ld/st instruction will be
                      selected.  */
-                  if ( (  (strncmp (opcode->name, "st.", 3) == 0)
-		       || (strncmp (opcode->name, "ld.", 3) == 0))
+                  if ( (  (startswith (opcode->name, "st."))
+		       || (startswith (opcode->name, "ld.")))
                       && ex.X_op == O_constant
                       && (ex.X_add_number < (-(1 << (operand->bits - 1)))
 			  || ex.X_add_number > ((1 << (operand->bits - 1)) - 1)))
diff --git a/gas/config/tc-vax.c b/gas/config/tc-vax.c
index 70ea305fe10..f439f1b52dc 100644
--- a/gas/config/tc-vax.c
+++ b/gas/config/tc-vax.c
@@ -3279,7 +3279,7 @@ vax_cons (expressionS *exp, int size)
   save = input_line_pointer;
   if (input_line_pointer[0] == '%')
     {
-      if (strncmp (input_line_pointer + 1, "pcrel", 5) == 0)
+      if (startswith (input_line_pointer + 1, "pcrel"))
 	{
 	  input_line_pointer += 6;
 	  vax_cons_special_reloc = "pcrel";
diff --git a/gas/config/tc-wasm32.c b/gas/config/tc-wasm32.c
index 5fe93776810..03ad400bead 100644
--- a/gas/config/tc-wasm32.c
+++ b/gas/config/tc-wasm32.c
@@ -381,20 +381,20 @@ wasm32_leb128 (char **line, int bits, int sign)
       reloc->u.a.addend = 0;
     }
   /* i32.const fpointer@gotcode */
-  if (strncmp (input_line_pointer, "@gotcode", 8) == 0)
+  if (startswith (input_line_pointer, "@gotcode"))
     {
       gotrel = 1;
       code = 1;
       input_line_pointer += 8;
     }
   /* i32.const data@got */
-  else if (strncmp (input_line_pointer, "@got", 4) == 0)
+  else if (startswith (input_line_pointer, "@got"))
     {
       gotrel = 1;
       input_line_pointer += 4;
     }
   /* call f@plt{__sigchar_FiiiiE} */
-  else if (strncmp (input_line_pointer, "@plt", 4) == 0)
+  else if (startswith (input_line_pointer, "@plt"))
     {
       char *end_of_sig;
 
@@ -402,7 +402,7 @@ wasm32_leb128 (char **line, int bits, int sign)
       code = 1;
       input_line_pointer += 4;
 
-      if (strncmp (input_line_pointer, "{", 1) == 0
+      if (startswith (input_line_pointer, "{")
           && (end_of_sig = strchr (input_line_pointer, '}')))
 	{
 	  char *signature;
diff --git a/gas/config/tc-xstormy16.c b/gas/config/tc-xstormy16.c
index 37cd50a79d0..656eb81d16c 100644
--- a/gas/config/tc-xstormy16.c
+++ b/gas/config/tc-xstormy16.c
@@ -136,7 +136,7 @@ md_operand (expressionS * e)
   if (*input_line_pointer != '@')
     return;
 
-  if (strncmp (input_line_pointer + 1, "fptr", 4) == 0)
+  if (startswith (input_line_pointer + 1, "fptr"))
     {
       input_line_pointer += 5;
       SKIP_WHITESPACE ();
diff --git a/gas/config/tc-xtensa.c b/gas/config/tc-xtensa.c
index cbda45e6f0c..669d0be0300 100644
--- a/gas/config/tc-xtensa.c
+++ b/gas/config/tc-xtensa.c
@@ -1293,7 +1293,7 @@ get_directive (directiveE *directive, bfd_boolean *negated)
   unsigned i;
   const char *directive_string;
 
-  if (strncmp (input_line_pointer, "no-", 3) != 0)
+  if (!startswith (input_line_pointer, "no-"))
     *negated = FALSE;
   else
     {
@@ -1308,12 +1308,12 @@ get_directive (directiveE *directive, bfd_boolean *negated)
      equivalent to .begin [no-]transform.  We should remove it when
      we stop accepting those options.  */
 
-  if (strncmp (input_line_pointer, "generics", strlen ("generics")) == 0)
+  if (startswith (input_line_pointer, "generics"))
     {
       as_warn (_("[no-]generics is deprecated; use [no-]transform instead"));
       directive_string = "transform";
     }
-  else if (strncmp (input_line_pointer, "relax", strlen ("relax")) == 0)
+  else if (startswith (input_line_pointer, "relax"))
     {
       as_warn (_("[no-]relax is deprecated; use [no-]transform instead"));
       directive_string = "transform";
@@ -2893,7 +2893,7 @@ static bfd_boolean
 xg_instruction_matches_option_term (TInsn *insn, const ReqOrOption *option)
 {
   if (strcmp (option->option_name, "realnop") == 0
-      || strncmp (option->option_name, "IsaUse", 6) == 0)
+      || startswith (option->option_name, "IsaUse"))
     {
       /* These conditions were evaluated statically when building the
 	 relaxation table.  There's no need to reevaluate them now.  */
@@ -4552,7 +4552,7 @@ is_unaligned_label (symbolS *sym)
       && (name[fake_size] == 'F'
 	  || name[fake_size] == 'L'
 	  || (name[fake_size] == 'e'
-	      && strncmp ("endfunc", name+fake_size, 7) == 0)))
+	      && startswith (name + fake_size, "endfunc"))))
     return TRUE;
 
   return FALSE;
@@ -11691,11 +11691,11 @@ cache_literal_section (bfd_boolean use_abs_literals)
       size_t len = strlen (text_name);
       if (len >= 5
 	  && (strcmp (text_name + len - 5, ".text") == 0
-	      || strncmp (text_name, ".text", 5) == 0))
+	      || startswith (text_name, ".text")))
 	len -= 5;
 
       name = XNEWVEC (char, len + strlen (base_name) + 1);
-      if (strncmp (text_name, ".text", 5) == 0)
+      if (startswith (text_name, ".text"))
 	{
 	  strcpy (name, base_name);
 	  strcat (name, text_name + 5);
diff --git a/gas/config/xtensa-relax.c b/gas/config/xtensa-relax.c
index 955650b1f19..7c0666193f2 100644
--- a/gas/config/xtensa-relax.c
+++ b/gas/config/xtensa-relax.c
@@ -1282,9 +1282,9 @@ parse_precond (const char *s, precond_e *precond)
   p = skip_white (p);
 
   /* Check for "==" and "!=".  */
-  if (strncmp (p, "==", 2) == 0)
+  if (startswith (p, "=="))
     precond->cmpop = OP_EQUAL;
-  else if (strncmp (p, "!=", 2) == 0)
+  else if (startswith (p, "!="))
     precond->cmpop = OP_NOTEQUAL;
   else
     return FALSE;
@@ -1392,7 +1392,7 @@ parse_option_cond (const char *s, ReqOption *option)
       ReqOrOption *req;
       ReqOrOption **r_p;
 
-      if (strncmp (option_name, "no-", 3) == 0)
+      if (startswith (option_name, "no-"))
 	{
 	  option_name = xstrdup (&option_name[3]);
 	  is_true = FALSE;
@@ -1558,7 +1558,7 @@ transition_applies (insn_pattern *initial_insn,
 	  || req_or_option->next != NULL)
 	continue;
 
-      if (strncmp (req_or_option->option_name, "IsaUse", 6) == 0)
+      if (startswith (req_or_option->option_name, "IsaUse"))
 	{
 	  bfd_boolean option_available = FALSE;
 	  char *option_name = req_or_option->option_name + 6;
@@ -1607,7 +1607,7 @@ wide_branch_opcode (const char *opcode_name,
   xtensa_opcode opcode;
   static char wbr_name_buf[20];
 
-  if (strncmp (opcode_name, "WIDE.", 5) != 0)
+  if (!startswith (opcode_name, "WIDE."))
     return FALSE;
 
   strcpy (wbr_name_buf, opcode_name + 5);
diff --git a/gas/dw2gencfi.c b/gas/dw2gencfi.c
index 1cd30773ca7..420acd7ea9d 100644
--- a/gas/dw2gencfi.c
+++ b/gas/dw2gencfi.c
@@ -1219,14 +1219,13 @@ dot_cfi_sections (int ignored ATTRIBUTE_UNUSED)
 	saved_ilp = input_line_pointer;
 	c = get_symbol_name (& name);
 
-	if (strncmp (name, ".eh_frame", sizeof ".eh_frame") == 0
+	if (startswith (name, ".eh_frame")
 	    && name[9] != '_')
 	  sections |= CFI_EMIT_eh_frame;
-	else if (strncmp (name, ".debug_frame", sizeof ".debug_frame") == 0)
+	else if (startswith (name, ".debug_frame"))
 	  sections |= CFI_EMIT_debug_frame;
 #if SUPPORT_COMPACT_EH
-	else if (strncmp (name, ".eh_frame_entry",
-			  sizeof ".eh_frame_entry") == 0)
+	else if (startswith (name, ".eh_frame_entry"))
 	  {
 	    compact_eh = TRUE;
 	    sections |= CFI_EMIT_eh_frame_compact;
diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
index 85db0bef230..01d6845bbd2 100644
--- a/gas/dwarf2dbg.c
+++ b/gas/dwarf2dbg.c
@@ -1097,7 +1097,7 @@ dwarf2_directive_filename (void)
 	  SKIP_WHITESPACE ();
 	}
 
-      if (strncmp (input_line_pointer, "md5", 3) == 0)
+      if (startswith (input_line_pointer, "md5"))
 	{
 	  input_line_pointer += 3;
 	  SKIP_WHITESPACE ();
diff --git a/gas/ehopt.c b/gas/ehopt.c
index 256932068c8..21f0755b3a4 100644
--- a/gas/ehopt.c
+++ b/gas/ehopt.c
@@ -118,7 +118,7 @@ get_cie_info (struct cie_info *info)
 
   /* First make sure that the CIE Identifier Tag is 0/-1.  */
 
-  if (strncmp (segment_name (now_seg), ".debug_frame", 12) == 0)
+  if (startswith (segment_name (now_seg), ".debug_frame"))
     CIE_id = (char)0xff;
   else
     CIE_id = 0;
@@ -283,10 +283,10 @@ check_eh_frame (expressionS *exp, unsigned int *pnbytes)
 #endif
 
   /* Select the proper section data.  */
-  if (strncmp (segment_name (now_seg), ".eh_frame", 9) == 0
+  if (startswith (segment_name (now_seg), ".eh_frame")
       && segment_name (now_seg)[9] != '_')
     d = &eh_frame_data;
-  else if (strncmp (segment_name (now_seg), ".debug_frame", 12) == 0)
+  else if (startswith (segment_name (now_seg), ".debug_frame"))
     d = &debug_frame_data;
   else
     return 0;
diff --git a/gas/input-file.c b/gas/input-file.c
index aae20a8ca6e..088af7de13d 100644
--- a/gas/input-file.c
+++ b/gas/input-file.c
@@ -171,7 +171,7 @@ input_file_open (const char *filename,
       if (c == 'N')
 	{
 	  if (fgets (buf, sizeof (buf), f_in)
-	      && !strncmp (buf, "O_APP", 5) && ISSPACE (buf[5]))
+	      && startswith (buf, "O_APP") && ISSPACE (buf[5]))
 	    preprocess = 0;
 	  if (!strchr (buf, '\n'))
 	    ungetc ('#', f_in);	/* It was longer.  */
@@ -181,7 +181,7 @@ input_file_open (const char *filename,
       else if (c == 'A')
 	{
 	  if (fgets (buf, sizeof (buf), f_in)
-	      && !strncmp (buf, "PP", 2) && ISSPACE (buf[2]))
+	      && startswith (buf, "PP") && ISSPACE (buf[2]))
 	    preprocess = 1;
 	  if (!strchr (buf, '\n'))
 	    ungetc ('#', f_in);
diff --git a/gas/listing.c b/gas/listing.c
index 02eb245f1eb..72540d2c8f7 100644
--- a/gas/listing.c
+++ b/gas/listing.c
@@ -318,8 +318,8 @@ listing_newline (char *ps)
       const char *segname;
 
       segname = segment_name (now_seg);
-      if (strncmp (segname, ".debug", sizeof ".debug" - 1) == 0
-	  || strncmp (segname, ".line", sizeof ".line" - 1) == 0)
+      if (startswith (segname, ".debug")
+	  || startswith (segname, ".line"))
 	listing_tail->debugging = 1;
     }
 #endif
@@ -433,8 +433,8 @@ listing_newline (char *ps)
       const char *segname;
 
       segname = segment_name (now_seg);
-      if (strncmp (segname, ".debug", sizeof ".debug" - 1) == 0
-	  || strncmp (segname, ".line", sizeof ".line" - 1) == 0)
+      if (startswith (segname, ".debug")
+	  || startswith (segname, ".line"))
 	new_i->debugging = 1;
     }
 #endif
@@ -1160,29 +1160,29 @@ debugging_pseudo (list_info_type *list, const char *line)
 
   line++;
 
-  if (strncmp (line, "def", 3) == 0)
+  if (startswith (line, "def"))
     return 1;
-  if (strncmp (line, "val", 3) == 0)
+  if (startswith (line, "val"))
     return 1;
-  if (strncmp (line, "scl", 3) == 0)
+  if (startswith (line, "scl"))
     return 1;
-  if (strncmp (line, "line", 4) == 0)
+  if (startswith (line, "line"))
     return 1;
-  if (strncmp (line, "endef", 5) == 0)
+  if (startswith (line, "endef"))
     return 1;
-  if (strncmp (line, "ln", 2) == 0)
+  if (startswith (line, "ln"))
     return 1;
-  if (strncmp (line, "type", 4) == 0)
+  if (startswith (line, "type"))
     return 1;
-  if (strncmp (line, "size", 4) == 0)
+  if (startswith (line, "size"))
     return 1;
-  if (strncmp (line, "dim", 3) == 0)
+  if (startswith (line, "dim"))
     return 1;
-  if (strncmp (line, "tag", 3) == 0)
+  if (startswith (line, "tag"))
     return 1;
-  if (strncmp (line, "stabs", 5) == 0)
+  if (startswith (line, "stabs"))
     return 1;
-  if (strncmp (line, "stabn", 5) == 0)
+  if (startswith (line, "stabn"))
     return 1;
 
   return 0;
diff --git a/gas/read.c b/gas/read.c
index 3e760653289..0ead5c7bf59 100644
--- a/gas/read.c
+++ b/gas/read.c
@@ -1322,7 +1322,7 @@ read_a_source_file (const char *name)
 	      char *tmp_buf = 0;
 
 	      s = input_line_pointer;
-	      if (strncmp (s, "APP\n", 4))
+	      if (!startswith (s, "APP\n"))
 		{
 		  /* We ignore it.  */
 		  ignore_rest_of_line ();
diff --git a/gas/write.c b/gas/write.c
index 95922bb25a0..c762cd6e0da 100644
--- a/gas/write.c
+++ b/gas/write.c
@@ -880,8 +880,7 @@ adjust_reloc_syms (bfd *abfd ATTRIBUTE_UNUSED,
 		    /* The GNU toolchain uses an extension for ELF: a
 		       section beginning with the magic string
 		       .gnu.linkonce is a linkonce section.  */
-		    && strncmp (segment_name (symsec), ".gnu.linkonce",
-				sizeof ".gnu.linkonce" - 1) == 0))
+		    && startswith (segment_name (symsec), ".gnu.linkonce")))
 	      continue;
 	  }
 
@@ -1450,7 +1449,7 @@ compress_debug (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED)
     return;
 
   section_name = bfd_section_name (sec);
-  if (strncmp (section_name, ".debug_", 7) != 0)
+  if (!startswith (section_name, ".debug_"))
     return;
 
   strm = compress_init ();
@@ -2039,7 +2038,7 @@ maybe_generate_build_notes (void)
 	/* Skip linkonce sections - we cannot use these section symbols as they may disappear.  */
 	&& (bsym->section->flags & (SEC_CODE | SEC_LINK_ONCE)) == SEC_CODE
 	/* Not all linkonce sections are flagged...  */
-	&& strncmp (S_GET_NAME (sym), ".gnu.linkonce", sizeof ".gnu.linkonce" - 1) != 0)
+	&& !startswith (S_GET_NAME (sym), ".gnu.linkonce"))
       {
 	/* Create a version note.  */
 	frag_now_fix ();

^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH 4/5] Remove strneq macro and use startswith.
  2021-03-24  8:19                     ` [PATCH 0/5] Start using startswith instead of strncmp Martin Liska
                                         ` (2 preceding siblings ...)
  2021-03-22 12:33                       ` [PATCH 3/5] Use startswith in gas subfolder Martin Liska
@ 2021-03-22 13:56                       ` Martin Liska
  2021-03-23  9:02                       ` [PATCH 5/5] Use startswith in gdb subfolder Martin Liska
  2021-04-01  5:21                       ` [PATCH 0/5] Start using startswith instead of strncmp Martin Liška
  5 siblings, 0 replies; 41+ messages in thread
From: Martin Liska @ 2021-03-22 13:56 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 1427 bytes --]


bfd/ChangeLog:

	* ecoff.c (strneq): Remove strneq and use startswith.
	(_bfd_ecoff_slurp_armap): Likewise.

binutils/ChangeLog:

	* elfcomm.h (strneq): Remove strneq and use startswith.
	* readelf.c (ia64_process_unwind): Likewise.
	(process_note): Likewise.

gas/ChangeLog:

	* config/obj-coff.c (strneq): Remove strneq and use startswith.
	(weak_is_altname): Likewise.
	(obj_coff_section): Likewise.
	* config/tc-cr16.c (process_label_constant): Likewise.
	* config/tc-crx.c (strneq): Likewise.

include/ChangeLog:

	* opcode/cr16.h (strneq): Remove strneq and use startswith.

ld/ChangeLog:

	* ldbuildid.c (strneq): Remove strneq and use startswith.
	(validate_build_id_style): Likewise.
	(compute_build_id_size): Likewise.

opcodes/ChangeLog:

	* arm-dis.c (strneq): Remove strneq and use startswith.
	* cr16-dis.c (print_insn_cr16): Likewise.
	* score-dis.c (streq): Likewise.
	(strneq): Likewise.
	* score7-dis.c (strneq): Likewise.
---
 bfd/ecoff.c           |  5 ++---
 binutils/elfcomm.h    |  1 -
 binutils/readelf.c    | 14 +++++++-------
 gas/config/obj-coff.c |  5 ++---
 gas/config/tc-cr16.c  | 26 +++++++++++++-------------
 gas/config/tc-crx.c   |  1 -
 include/opcode/cr16.h |  1 -
 ld/ldbuildid.c        |  7 +++----
 opcodes/arm-dis.c     |  5 -----
 opcodes/cr16-dis.c    |  2 +-
 opcodes/score-dis.c   |  8 --------
 opcodes/score7-dis.c  |  4 ----
 12 files changed, 28 insertions(+), 51 deletions(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0004-Remove-strneq-macro-and-use-startswith.patch --]
[-- Type: text/x-patch; name="0004-Remove-strneq-macro-and-use-startswith.patch", Size: 10583 bytes --]

diff --git a/bfd/ecoff.c b/bfd/ecoff.c
index dc12b180adb..2d288cb90eb 100644
--- a/bfd/ecoff.c
+++ b/bfd/ecoff.c
@@ -46,7 +46,6 @@
 #include "libiberty.h"
 
 #define streq(a, b)	(strcmp ((a), (b)) == 0)
-#define strneq(a, b, n)	(strncmp ((a), (b), (n)) == 0)
 
 \f
 /* This stuff is somewhat copied from coffcode.h.  */
@@ -2870,14 +2869,14 @@ _bfd_ecoff_slurp_armap (bfd *abfd)
     return bfd_slurp_armap (abfd);
 
   /* See if the first element is an armap.  */
-  if (! strneq (nextname, ecoff_backend (abfd)->armap_start, ARMAP_START_LENGTH)
+  if (strncmp (nextname, ecoff_backend (abfd)->armap_start, ARMAP_START_LENGTH) != 0
       || nextname[ARMAP_HEADER_MARKER_INDEX] != ARMAP_MARKER
       || (nextname[ARMAP_HEADER_ENDIAN_INDEX] != ARMAP_BIG_ENDIAN
 	  && nextname[ARMAP_HEADER_ENDIAN_INDEX] != ARMAP_LITTLE_ENDIAN)
       || nextname[ARMAP_OBJECT_MARKER_INDEX] != ARMAP_MARKER
       || (nextname[ARMAP_OBJECT_ENDIAN_INDEX] != ARMAP_BIG_ENDIAN
 	  && nextname[ARMAP_OBJECT_ENDIAN_INDEX] != ARMAP_LITTLE_ENDIAN)
-      || ! strneq (nextname + ARMAP_END_INDEX, ARMAP_END, sizeof ARMAP_END - 1))
+      || strncmp (nextname + ARMAP_END_INDEX, ARMAP_END, sizeof ARMAP_END - 1) != 0)
     {
       abfd->has_armap = FALSE;
       return TRUE;
diff --git a/binutils/elfcomm.h b/binutils/elfcomm.h
index 04e909c2da3..921d42ca425 100644
--- a/binutils/elfcomm.h
+++ b/binutils/elfcomm.h
@@ -47,7 +47,6 @@ extern void byte_get_64 (const unsigned char *, elf_vma *, elf_vma *);
 
 /* This is just a bit of syntatic sugar.  */
 #define streq(a,b)	  (strcmp ((a), (b)) == 0)
-#define strneq(a,b,n)	  (strncmp ((a), (b), (n)) == 0)
 
 /* Structure to hold information about an archive file.  */
 
diff --git a/binutils/readelf.c b/binutils/readelf.c
index f638b77e146..3a6a12aa226 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -8235,8 +8235,8 @@ ia64_process_unwind (Filedata * filedata)
 	    }
 	}
       else if (SECTION_NAME_VALID (unwsec)
-	       && strneq (SECTION_NAME (unwsec),
-			  ELF_STRING_ia64_unwind_once, len))
+	       && startswith (SECTION_NAME (unwsec),
+			      ELF_STRING_ia64_unwind_once))
 	{
 	  /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO.  */
 	  len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
@@ -8245,8 +8245,8 @@ ia64_process_unwind (Filedata * filedata)
 	       i < filedata->file_header.e_shnum;
 	       ++i, ++sec)
 	    if (SECTION_NAME_VALID (sec)
-		&& strneq (SECTION_NAME (sec),
-			   ELF_STRING_ia64_unwind_info_once, len2)
+		&& startswith (SECTION_NAME (sec),
+			       ELF_STRING_ia64_unwind_info_once)
 		&& streq (SECTION_NAME (sec) + len2, suffix))
 	      break;
 	}
@@ -8258,13 +8258,13 @@ ia64_process_unwind (Filedata * filedata)
 	  len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
 	  suffix = "";
 	  if (SECTION_NAME_VALID (unwsec)
-	      && strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind, len))
+	      && startswith (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind))
 	    suffix = SECTION_NAME (unwsec) + len;
 	  for (i = 0, sec = filedata->section_headers;
 	       i < filedata->file_header.e_shnum;
 	       ++i, ++sec)
 	    if (SECTION_NAME_VALID (sec)
-		&& strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info, len2)
+		&& startswith (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info)
 		&& streq (SECTION_NAME (sec) + len2, suffix))
 	      break;
 	}
@@ -20450,7 +20450,7 @@ process_note (Elf_Internal_Note *  pnote,
     /* NetBSD-specific core file notes.  */
     return process_netbsd_elf_note (pnote);
 
-  else if (strneq (pnote->namedata, "SPU/", 4))
+  else if (startswith (pnote->namedata, "SPU/"))
     {
       /* SPU-specific core file notes.  */
       nt = pnote->namedata + 4;
diff --git a/gas/config/obj-coff.c b/gas/config/obj-coff.c
index 05b46995996..65bd2378afd 100644
--- a/gas/config/obj-coff.c
+++ b/gas/config/obj-coff.c
@@ -33,7 +33,6 @@
 #endif
 
 #define streq(a,b)     (strcmp ((a), (b)) == 0)
-#define strneq(a,b,n)  (strncmp ((a), (b), (n)) == 0)
 
 /* I think this is probably always correct.  */
 #ifndef KEEP_RELOC_INFO
@@ -1058,7 +1057,7 @@ obj_coff_val (int ignore ATTRIBUTE_UNUSED)
 static int
 weak_is_altname (const char * name)
 {
-  return strneq (name, weak_altprefix, sizeof (weak_altprefix) - 1);
+  return startswith (name, weak_altprefix);
 }
 
 /* Return the name of the alternate symbol
@@ -1667,7 +1666,7 @@ obj_coff_section (int ignore ATTRIBUTE_UNUSED)
       /* Add SEC_LINK_ONCE and SEC_LINK_DUPLICATES_DISCARD to .gnu.linkonce
          sections so adjust_reloc_syms in write.c will correctly handle
          relocs which refer to non-local symbols in these sections.  */
-      if (strneq (name, ".gnu.linkonce", sizeof (".gnu.linkonce") - 1))
+      if (startswith (name, ".gnu.linkonce"))
 	flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
 #endif
 
diff --git a/gas/config/tc-cr16.c b/gas/config/tc-cr16.c
index 733b08e2b64..1f6b1fe8b6d 100644
--- a/gas/config/tc-cr16.c
+++ b/gas/config/tc-cr16.c
@@ -905,34 +905,34 @@ process_label_constant (char *str, ins * cr16_ins)
       cr16_ins->rtype = BFD_RELOC_NONE;
       relocatable = 1;
 
-      if (strneq (input_line_pointer, "@c", 2))
+      if (startswith (input_line_pointer, "@c"))
 	symbol_with_at = 1;
 
-      if (strneq (input_line_pointer, "@l", 2)
-	  || strneq (input_line_pointer, ":l", 2))
+      if (startswith (input_line_pointer, "@l")
+	  || startswith (input_line_pointer, ":l"))
 	symbol_with_l = 1;
 
-      if (strneq (input_line_pointer, "@m", 2)
-	  || strneq (input_line_pointer, ":m", 2))
+      if (startswith (input_line_pointer, "@m")
+	  || startswith (input_line_pointer, ":m"))
 	symbol_with_m = 1;
 
-      if (strneq (input_line_pointer, "@s", 2)
-	  || strneq (input_line_pointer, ":s", 2))
+      if (startswith (input_line_pointer, "@s")
+	  || startswith (input_line_pointer, ":s"))
 	symbol_with_s = 1;
 
-      if (strneq (input_line_pointer, "@cGOT", 5)
-	  || strneq (input_line_pointer, "@cgot", 5))
+      if (startswith (input_line_pointer, "@cGOT")
+	  || startswith (input_line_pointer, "@cgot"))
 	{
 	  if (GOT_symbol == NULL)
 	    GOT_symbol = symbol_find_or_make (GLOBAL_OFFSET_TABLE_NAME);
 
 	  symbol_with_at_gotc = 1;
 	}
-      else if (strneq (input_line_pointer, "@GOT", 4)
-	       || strneq (input_line_pointer, "@got", 4))
+      else if (startswith (input_line_pointer, "@GOT")
+	       || startswith (input_line_pointer, "@got"))
 	{
-	  if ((strneq (input_line_pointer, "+", 1))
-	      || (strneq (input_line_pointer, "-", 1)))
+	  if ((startswith (input_line_pointer, "+"))
+	      || (startswith (input_line_pointer, "-")))
 	    as_warn (_("GOT bad expression with %s."), input_line_pointer);
 
 	  if (GOT_symbol == NULL)
diff --git a/gas/config/tc-crx.c b/gas/config/tc-crx.c
index 52eebcb7e94..67ed3ad085a 100644
--- a/gas/config/tc-crx.c
+++ b/gas/config/tc-crx.c
@@ -43,7 +43,6 @@
 
 /* Utility macros for string comparison.  */
 #define streq(a, b)           (strcmp (a, b) == 0)
-#define strneq(a, b, c)       (strncmp (a, b, c) == 0)
 
 /* Assign a number NUM, shifted by SHIFT bytes, into a location
    pointed by index BYTE of array 'output_opcode'.  */
diff --git a/include/opcode/cr16.h b/include/opcode/cr16.h
index a96b3374c8a..09e27122a17 100644
--- a/include/opcode/cr16.h
+++ b/include/opcode/cr16.h
@@ -425,7 +425,6 @@ extern const char * cr16_no_op_insn[];
 
 /* Utility macros for string comparison.  */
 #define streq(a, b)           (strcmp (a, b) == 0)
-#define strneq(a, b, c)       (strncmp (a, b, c) == 0)
 
 /* Long long type handling.  */
 /* Replace all appearances of 'long long int' with LONGLONG.  */
diff --git a/ld/ldbuildid.c b/ld/ldbuildid.c
index c55a939ae2f..38a1d9d3b54 100644
--- a/ld/ldbuildid.c
+++ b/ld/ldbuildid.c
@@ -30,13 +30,12 @@
 #endif
 
 #define streq(a,b)     strcmp ((a), (b)) == 0
-#define strneq(a,b,n)  strncmp ((a), (b), (n)) == 0
 
 bfd_boolean
 validate_build_id_style (const char *style)
 {
   if ((streq (style, "md5")) || (streq (style, "sha1"))
-      || (streq (style, "uuid")) || (strneq (style, "0x", 2)))
+      || (streq (style, "uuid")) || (startswith (style, "0x")))
     return TRUE;
 
   return FALSE;
@@ -51,7 +50,7 @@ compute_build_id_size (const char *style)
   if (streq (style, "sha1"))
     return 160 / 8;
 
-  if (strneq (style, "0x", 2))
+  if (startswith (style, "0x"))
     {
       bfd_size_type size = 0;
       /* ID is in string form (hex).  Count the bytes.  */
@@ -156,7 +155,7 @@ generate_build_id (bfd *abfd,
 	      (size_t) size < sizeof (UUID) ? (size_t) size : sizeof (UUID));
 #endif /* __MINGW32__ */
     }
-  else if (strneq (style, "0x", 2))
+  else if (startswith (style, "0x"))
     {
       /* ID is in string form (hex).  Convert to bits.  */
       const char *id = style + 2;
diff --git a/opcodes/arm-dis.c b/opcodes/arm-dis.c
index 9647d0019db..e0455efa0e5 100644
--- a/opcodes/arm-dis.c
+++ b/opcodes/arm-dis.c
@@ -39,11 +39,6 @@
 #include "elf/arm.h"
 #include "mach-o.h"
 
-/* FIXME: Belongs in global header.  */
-#ifndef strneq
-#define strneq(a,b,n)	(strncmp ((a), (b), (n)) == 0)
-#endif
-
 /* Cached mapping symbol state.  */
 enum map_type
 {
diff --git a/opcodes/cr16-dis.c b/opcodes/cr16-dis.c
index d5840cb81f8..ac855523fa9 100644
--- a/opcodes/cr16-dis.c
+++ b/opcodes/cr16-dis.c
@@ -800,7 +800,7 @@ print_insn_cr16 (bfd_vma memaddr, struct disassemble_info *info)
   /* If found, print the instruction's mnemonic and arguments.  */
   if (is_decoded > 0 && (cr16_words[0] != 0 || cr16_words[1] != 0))
     {
-      if (strneq (instruction->mnemonic, "cinv", 4))
+      if (startswith (instruction->mnemonic, "cinv"))
 	info->fprintf_func (info->stream,"%s",
 			    getcinvstring (instruction->mnemonic));
       else
diff --git a/opcodes/score-dis.c b/opcodes/score-dis.c
index d01748c5e44..139184d48f5 100644
--- a/opcodes/score-dis.c
+++ b/opcodes/score-dis.c
@@ -477,14 +477,6 @@ static struct score_opcode score_opcodes[] =
 };
 \f
 
-#ifndef streq
-#define streq(a,b)    (strcmp ((a), (b)) == 0)
-#endif
-
-#ifndef strneq
-#define strneq(a,b,n)    (strncmp ((a), (b), (n)) == 0)
-#endif
-
 #ifndef NUM_ELEM
 #define NUM_ELEM(a)     (sizeof (a) / sizeof (a)[0])
 #endif
diff --git a/opcodes/score7-dis.c b/opcodes/score7-dis.c
index 7207fde4c19..a9eb542529f 100644
--- a/opcodes/score7-dis.c
+++ b/opcodes/score7-dis.c
@@ -37,10 +37,6 @@
 #define streq(a,b)    (strcmp ((a), (b)) == 0)
 #endif
 
-#ifndef strneq
-#define strneq(a,b,n)    (strncmp ((a), (b), (n)) == 0)
-#endif
-
 #ifndef NUM_ELEM
 #define NUM_ELEM(a)     (sizeof (a) / sizeof (a)[0])
 #endif

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ.
  2021-03-22 12:06               ` Alan Modra
@ 2021-03-22 16:13                 ` Luis Machado
  2021-03-22 22:56                   ` Alan Modra
  2021-03-22 16:42                 ` Martin Liška
  1 sibling, 1 reply; 41+ messages in thread
From: Luis Machado @ 2021-03-22 16:13 UTC (permalink / raw)
  To: Alan Modra, Tom Tromey, Mike Frysinger
  Cc: Alan Modra via Binutils, gdb-patches

On 3/22/21 9:06 AM, Alan Modra via Gdb-patches wrote:
> On Sun, Mar 21, 2021 at 08:13:06PM -0600, Tom Tromey wrote:
>> Alan> Yes, the following compiles.  Fortunately all gdb files that include
>> Alan> gdbsupport/common-utils.h also include bfd.h by one means or another.
>>
>> Sorry, I misunderstood.  I thought the proposal was to put the
>> function in ansidecl.h.
>>
>> gdbserver can't generally include bfd.  Maybe it works sometimes, but I
>> imagine if you do a gdbserver-only build, bfd.h won't even be created.
>> (At least, it shouldn't be, because gdbserver doesn't require bfd.)
>>
>> So I think some other approach is needed.  Either ansidecl.h, or a new
>> header; or rename either the BFD or GDB function and go from there.
> 
> A new header would be best, I think.
> 
>> I'm happy to implement it if you like.
> 
> Yes, that way you'll get it done properly.  :)  Sorry for the breakage.
> 

Just FTR, I'm seeing breakage in sim/aarch64 and sim/arm. Both are 
complaining about "-Werror=implicit-function-declaration" regarding 
strncmp and strlen.

Is this the breakage you're talking about? Just so I know what to expect 
when it gets fixed.

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ.
  2021-03-22 12:06               ` Alan Modra
  2021-03-22 16:13                 ` Luis Machado
@ 2021-03-22 16:42                 ` Martin Liška
  2021-03-23  0:02                   ` Alan Modra
  1 sibling, 1 reply; 41+ messages in thread
From: Martin Liška @ 2021-03-22 16:42 UTC (permalink / raw)
  To: Alan Modra, Tom Tromey, Mike Frysinger
  Cc: Alan Modra via Binutils, gdb-patches

On 3/22/21 1:06 PM, Alan Modra wrote:
> On Sun, Mar 21, 2021 at 08:13:06PM -0600, Tom Tromey wrote:
>> Alan> Yes, the following compiles.  Fortunately all gdb files that include
>> Alan> gdbsupport/common-utils.h also include bfd.h by one means or another.
>>
>> Sorry, I misunderstood.  I thought the proposal was to put the
>> function in ansidecl.h.
>>
>> gdbserver can't generally include bfd.  Maybe it works sometimes, but I
>> imagine if you do a gdbserver-only build, bfd.h won't even be created.
>> (At least, it shouldn't be, because gdbserver doesn't require bfd.)
>>
>> So I think some other approach is needed.  Either ansidecl.h, or a new
>> header; or rename either the BFD or GDB function and go from there.
> 
> A new header would be best, I think.
> 
>> I'm happy to implement it if you like.
> 
> Yes, that way you'll get it done properly.  :)  Sorry for the breakage.
> 

Hello.

I feel also responsible for the current compilation problems, I pulled the trigger.

Anyway for the sim failures. What about directly including <string.h> in bfd-in.h?

diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h
index fda9fe0198e..d35e2ece516 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -38,6 +38,7 @@ extern "C" {
  #include "diagnostics.h"
  #include <stdarg.h>
  #include <sys/stat.h>
+#include <string.h>
  
  #if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE)
  #ifndef SABER

Or do I miss something?
Thanks,
Martin

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ.
  2021-03-22 16:13                 ` Luis Machado
@ 2021-03-22 22:56                   ` Alan Modra
  2021-03-25 10:53                     ` Luis Machado
  0 siblings, 1 reply; 41+ messages in thread
From: Alan Modra @ 2021-03-22 22:56 UTC (permalink / raw)
  To: Luis Machado
  Cc: Tom Tromey, Mike Frysinger, Alan Modra via Binutils, gdb-patches

On Mon, Mar 22, 2021 at 01:13:00PM -0300, Luis Machado wrote:
> Just FTR, I'm seeing breakage in sim/aarch64 and sim/arm. Both are
> complaining about "-Werror=implicit-function-declaration" regarding strncmp
> and strlen.
> 
> Is this the breakage you're talking about? Just so I know what to expect
> when it gets fixed.

Yes.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ.
  2021-03-22 16:42                 ` Martin Liška
@ 2021-03-23  0:02                   ` Alan Modra
  2021-03-23  4:49                     ` Mike Frysinger
                                       ` (2 more replies)
  0 siblings, 3 replies; 41+ messages in thread
From: Alan Modra @ 2021-03-23  0:02 UTC (permalink / raw)
  To: Martin Liška
  Cc: Tom Tromey, Mike Frysinger, Alan Modra via Binutils, gdb-patches

On Mon, Mar 22, 2021 at 05:42:50PM +0100, Martin Liška wrote:
> Anyway for the sim failures. What about directly including <string.h> in bfd-in.h?

That would be OK if we didn't care about really old systems.  See for
example the way bfd/sysdep.h includes string.h.

But all of this horrible old code that likely hasn't been tested is
eons should simply disappear.  Instead binutils should be using the
gnulib import already available in the binutils-gdb repository to
support old systems.  I've had that project on my todo list for quite
a while.  We'd be able to include stdint.h and stdbool.h for example,
throwing away bfd_stdint.h and replacing bfd_boolean with bool.

Meanwhile, this is a tidied version of the patch I sent you last
night, Tom.  If you already have one of your own then please ignore
this.

---
Subject: str-util.h

Defining startswith in bfd.h breaks sim targets that don't happen to
include string.h before bfd.h, and since bfd.h is exported, might
break other projects that use bfd.h.

include/
	* str-util.h: New file.
bfd/
	* sysdep.h: Include str-util.h.
	* bfd-in.h (startswith): Delete.
	* bfd-in2.h: Regenerate.
binutils/
	* sysdep.h: Include str-util.h.
gas/
	* as.h: Include str-util.h.
gdbsupport/
	* common-utils.h: Include str-util.h.
ld/
	* sysdep.h: Include str-util.h.
opcodes/
	* sysdep.h: Include str-util.h.

diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h
index fda9fe0198..92391bb6a3 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -554,11 +554,3 @@ struct ecoff_debug_swap;
 struct ecoff_extr;
 struct bfd_link_info;
 struct bfd_link_hash_entry;
-
-/* Return TRUE if the start of STR matches PREFIX, FALSE otherwise.  */
-
-static inline bfd_boolean
-startswith (const char *str, const char *prefix)
-{
-  return strncmp (str, prefix, strlen (prefix)) == 0;
-}
diff --git a/bfd/sysdep.h b/bfd/sysdep.h
index 338d731112..b04847ffc3 100644
--- a/bfd/sysdep.h
+++ b/bfd/sysdep.h
@@ -119,6 +119,8 @@ extern char *strrchr ();
 
 #include "filenames.h"
 
+#include "str-util.h"
+
 #if !HAVE_DECL_FFS
 extern int ffs (int);
 #endif
diff --git a/binutils/sysdep.h b/binutils/sysdep.h
index 183bb01653..022029a3f9 100644
--- a/binutils/sysdep.h
+++ b/binutils/sysdep.h
@@ -78,6 +78,8 @@ extern char *strrchr ();
 
 #include "binary-io.h"
 
+#include "str-util.h"
+
 #if !HAVE_DECL_STPCPY
 extern char *stpcpy (char *, const char *);
 #endif
diff --git a/gas/as.h b/gas/as.h
index d6ac208289..a0346ad062 100644
--- a/gas/as.h
+++ b/gas/as.h
@@ -97,6 +97,8 @@
 /* Define the standard progress macros.  */
 #include "progress.h"
 
+#include "str-util.h"
+
 /* Other stuff from config.h.  */
 #ifdef NEED_DECLARATION_ENVIRON
 extern char **environ;
diff --git a/gdbsupport/common-utils.h b/gdbsupport/common-utils.h
index 1de747f186..65569ffe78 100644
--- a/gdbsupport/common-utils.h
+++ b/gdbsupport/common-utils.h
@@ -45,6 +45,8 @@
 
 #include "gdb_string_view.h"
 
+#include "str-util.h"
+
 /* xmalloc(), xrealloc() and xcalloc() have already been declared in
    "libiberty.h". */
 
diff --git a/include/str-util.h b/include/str-util.h
new file mode 100644
index 0000000000..24aba56563
--- /dev/null
+++ b/include/str-util.h
@@ -0,0 +1,27 @@
+/* String utility functions used by GDB and binutils.
+   Copyright (C) 2021 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef STR_UTIL_H
+#define STR_UTIL_H
+
+/* Return 1 if the start of STR matches PREFIX, 0 otherwise.  */
+
+static inline int
+startswith (const char *str, const char *prefix)
+{
+  return strncmp (str, prefix, strlen (prefix)) == 0;
+}
+#endif
diff --git a/ld/sysdep.h b/ld/sysdep.h
index 206c02c8c5..9e97d2d95b 100644
--- a/ld/sysdep.h
+++ b/ld/sysdep.h
@@ -68,6 +68,8 @@ extern char *strrchr ();
 #include "fopen-same.h"
 #endif
 
+#include "str-util.h"
+
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #else
diff --git a/opcodes/sysdep.h b/opcodes/sysdep.h
index bcac6d851c..a0732861b7 100644
--- a/opcodes/sysdep.h
+++ b/opcodes/sysdep.h
@@ -52,6 +52,8 @@
 #endif
 #endif
 
+#include "str-util.h"
+
 #if !HAVE_DECL_STPCPY
 extern char *stpcpy (char *__dest, const char *__src);
 #endif


-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ.
  2021-03-23  0:02                   ` Alan Modra
@ 2021-03-23  4:49                     ` Mike Frysinger
  2021-03-24  8:19                     ` [PATCH 0/5] Start using startswith instead of strncmp Martin Liska
  2021-03-31 20:18                     ` [PATCH] Add startswith function and use it instead of CONST_STRNEQ Tom Tromey
  2 siblings, 0 replies; 41+ messages in thread
From: Mike Frysinger @ 2021-03-23  4:49 UTC (permalink / raw)
  To: Alan Modra
  Cc: Martin Liška, Tom Tromey, Alan Modra via Binutils, gdb-patches

On 23 Mar 2021 10:32, Alan Modra wrote:
> On Mon, Mar 22, 2021 at 05:42:50PM +0100, Martin Liška wrote:
> > Anyway for the sim failures. What about directly including <string.h> in bfd-in.h?
> 
> That would be OK if we didn't care about really old systems.  See for
> example the way bfd/sysdep.h includes string.h.
> 
> But all of this horrible old code that likely hasn't been tested is
> eons should simply disappear.  Instead binutils should be using the
> gnulib import already available in the binutils-gdb repository to
> support old systems.  I've had that project on my todo list for quite
> a while.  We'd be able to include stdint.h and stdbool.h for example,
> throwing away bfd_stdint.h and replacing bfd_boolean with bool.

i agree with the idea that we've accumulated a lot of cruft that we never
test and it's unclear how many users still rely on it.  for the sim, i've
made C11 a requirement inline with GDB's C++11 requirement.  that means i
can assume <string.h> among other things.

> Meanwhile, this is a tidied version of the patch I sent you last
> night, Tom.  If you already have one of your own then please ignore
> this.

this fixes the sim for me, thanks
-mike

^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH 5/5] Use startswith in gdb subfolder.
  2021-03-24  8:19                     ` [PATCH 0/5] Start using startswith instead of strncmp Martin Liska
                                         ` (3 preceding siblings ...)
  2021-03-22 13:56                       ` [PATCH 4/5] Remove strneq macro and use startswith Martin Liska
@ 2021-03-23  9:02                       ` Martin Liska
  2021-03-31 20:26                         ` Tom Tromey
  2021-04-01  5:21                       ` [PATCH 0/5] Start using startswith instead of strncmp Martin Liška
  5 siblings, 1 reply; 41+ messages in thread
From: Martin Liska @ 2021-03-23  9:02 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 494 bytes --]


ChangeLog:

	* gdb/cp-name-parser.y: Use startswith instead of strncmp.
	* gdb/m2-exp.y: Likewise.
	* gdb/macroexp.c (substitute_args): Likewise.
	* gdb/mi/mi-main.c (command_notifies_uscc_observer): Likewise.
	* gdb/rust-exp.y: Likewise.
---
 gdb/cp-name-parser.y | 68 ++++++++++++++++++++++----------------------
 gdb/m2-exp.y         |  4 +--
 gdb/macroexp.c       |  2 +-
 gdb/mi/mi-main.c     |  8 +++---
 gdb/rust-exp.y       |  2 +-
 5 files changed, 42 insertions(+), 42 deletions(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0005-Use-startswith-in-gdb-subfolder.patch --]
[-- Type: text/x-patch; name="0005-Use-startswith-in-gdb-subfolder.patch", Size: 8492 bytes --]

diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y
index 8514411ebeb..0688e5b085a 100644
--- a/gdb/cp-name-parser.y
+++ b/gdb/cp-name-parser.y
@@ -1511,7 +1511,7 @@ cp_parse_escape (const char **string_ptr)
 }
 
 #define HANDLE_SPECIAL(string, comp)				\
-  if (strncmp (tokstart, string, sizeof (string) - 1) == 0)	\
+  if (startswith (tokstart, string))				\
     {								\
       state->lexptr = tokstart + sizeof (string) - 1;			\
       lvalp->lval = comp;					\
@@ -1592,7 +1592,7 @@ yylex (YYSTYPE *lvalp, cpname_state *state)
       return INT;
 
     case '(':
-      if (strncmp (tokstart, "(anonymous namespace)", 21) == 0)
+      if (startswith (tokstart, "(anonymous namespace)"))
 	{
 	  state->lexptr += 21;
 	  lvalp->comp = state->make_name ("(anonymous namespace)",
@@ -1625,7 +1625,7 @@ yylex (YYSTYPE *lvalp, cpname_state *state)
       HANDLE_TOKEN2 ("->", ARROW);
 
       /* For construction vtables.  This is kind of hokey.  */
-      if (strncmp (tokstart, "-in-", 4) == 0)
+      if (startswith (tokstart, "-in-"))
 	{
 	  state->lexptr += 4;
 	  return CONSTRUCTION_IN;
@@ -1803,20 +1803,20 @@ yylex (YYSTYPE *lvalp, cpname_state *state)
   switch (namelen)
     {
     case 16:
-      if (strncmp (tokstart, "reinterpret_cast", 16) == 0)
+      if (startswith (tokstart, "reinterpret_cast"))
 	return REINTERPRET_CAST;
       break;
     case 12:
-      if (strncmp (tokstart, "construction vtable for ", 24) == 0)
+      if (startswith (tokstart, "construction vtable for "))
 	{
 	  state->lexptr = tokstart + 24;
 	  return CONSTRUCTION_VTABLE;
 	}
-      if (strncmp (tokstart, "dynamic_cast", 12) == 0)
+      if (startswith (tokstart, "dynamic_cast"))
 	return DYNAMIC_CAST;
       break;
     case 11:
-      if (strncmp (tokstart, "static_cast", 11) == 0)
+      if (startswith (tokstart, "static_cast"))
 	return STATIC_CAST;
       break;
     case 9:
@@ -1827,24 +1827,24 @@ yylex (YYSTYPE *lvalp, cpname_state *state)
       HANDLE_SPECIAL ("typeinfo for ", DEMANGLE_COMPONENT_TYPEINFO);
       HANDLE_SPECIAL ("typeinfo fn for ", DEMANGLE_COMPONENT_TYPEINFO_FN);
       HANDLE_SPECIAL ("typeinfo name for ", DEMANGLE_COMPONENT_TYPEINFO_NAME);
-      if (strncmp (tokstart, "operator", 8) == 0)
+      if (startswith (tokstart, "operator"))
 	return OPERATOR;
-      if (strncmp (tokstart, "restrict", 8) == 0)
+      if (startswith (tokstart, "restrict"))
 	return RESTRICT;
-      if (strncmp (tokstart, "unsigned", 8) == 0)
+      if (startswith (tokstart, "unsigned"))
 	return UNSIGNED;
-      if (strncmp (tokstart, "template", 8) == 0)
+      if (startswith (tokstart, "template"))
 	return TEMPLATE;
-      if (strncmp (tokstart, "volatile", 8) == 0)
+      if (startswith (tokstart, "volatile"))
 	return VOLATILE_KEYWORD;
       break;
     case 7:
       HANDLE_SPECIAL ("virtual thunk to ", DEMANGLE_COMPONENT_VIRTUAL_THUNK);
-      if (strncmp (tokstart, "wchar_t", 7) == 0)
+      if (startswith (tokstart, "wchar_t"))
 	return WCHAR_T;
       break;
     case 6:
-      if (strncmp (tokstart, "global constructors keyed to ", 29) == 0)
+      if (startswith (tokstart, "global constructors keyed to "))
 	{
 	  const char *p;
 	  state->lexptr = tokstart + 29;
@@ -1855,7 +1855,7 @@ yylex (YYSTYPE *lvalp, cpname_state *state)
 	  state->lexptr = p;
 	  return DEMANGLER_SPECIAL;
 	}
-      if (strncmp (tokstart, "global destructors keyed to ", 28) == 0)
+      if (startswith (tokstart, "global destructors keyed to "))
 	{
 	  const char *p;
 	  state->lexptr = tokstart + 28;
@@ -1868,52 +1868,52 @@ yylex (YYSTYPE *lvalp, cpname_state *state)
 	}
 
       HANDLE_SPECIAL ("vtable for ", DEMANGLE_COMPONENT_VTABLE);
-      if (strncmp (tokstart, "delete", 6) == 0)
+      if (startswith (tokstart, "delete"))
 	return DELETE;
-      if (strncmp (tokstart, "struct", 6) == 0)
+      if (startswith (tokstart, "struct"))
 	return STRUCT;
-      if (strncmp (tokstart, "signed", 6) == 0)
+      if (startswith (tokstart, "signed"))
 	return SIGNED_KEYWORD;
-      if (strncmp (tokstart, "sizeof", 6) == 0)
+      if (startswith (tokstart, "sizeof"))
 	return SIZEOF;
-      if (strncmp (tokstart, "double", 6) == 0)
+      if (startswith (tokstart, "double"))
 	return DOUBLE_KEYWORD;
       break;
     case 5:
       HANDLE_SPECIAL ("guard variable for ", DEMANGLE_COMPONENT_GUARD);
-      if (strncmp (tokstart, "false", 5) == 0)
+      if (startswith (tokstart, "false"))
 	return FALSEKEYWORD;
-      if (strncmp (tokstart, "class", 5) == 0)
+      if (startswith (tokstart, "class"))
 	return CLASS;
-      if (strncmp (tokstart, "union", 5) == 0)
+      if (startswith (tokstart, "union"))
 	return UNION;
-      if (strncmp (tokstart, "float", 5) == 0)
+      if (startswith (tokstart, "float"))
 	return FLOAT_KEYWORD;
-      if (strncmp (tokstart, "short", 5) == 0)
+      if (startswith (tokstart, "short"))
 	return SHORT;
-      if (strncmp (tokstart, "const", 5) == 0)
+      if (startswith (tokstart, "const"))
 	return CONST_KEYWORD;
       break;
     case 4:
-      if (strncmp (tokstart, "void", 4) == 0)
+      if (startswith (tokstart, "void"))
 	return VOID;
-      if (strncmp (tokstart, "bool", 4) == 0)
+      if (startswith (tokstart, "bool"))
 	return BOOL;
-      if (strncmp (tokstart, "char", 4) == 0)
+      if (startswith (tokstart, "char"))
 	return CHAR;
-      if (strncmp (tokstart, "enum", 4) == 0)
+      if (startswith (tokstart, "enum"))
 	return ENUM;
-      if (strncmp (tokstart, "long", 4) == 0)
+      if (startswith (tokstart, "long"))
 	return LONG;
-      if (strncmp (tokstart, "true", 4) == 0)
+      if (startswith (tokstart, "true"))
 	return TRUEKEYWORD;
       break;
     case 3:
       HANDLE_SPECIAL ("VTT for ", DEMANGLE_COMPONENT_VTT);
       HANDLE_SPECIAL ("non-virtual thunk to ", DEMANGLE_COMPONENT_THUNK);
-      if (strncmp (tokstart, "new", 3) == 0)
+      if (startswith (tokstart, "new"))
 	return NEW;
-      if (strncmp (tokstart, "int", 3) == 0)
+      if (startswith (tokstart, "int"))
 	return INT_KEYWORD;
       break;
     default:
diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y
index 273270a85ce..b19bbeb3fb2 100644
--- a/gdb/m2-exp.y
+++ b/gdb/m2-exp.y
@@ -976,12 +976,12 @@ yylex (void)
     else
     {
        /* Built-in BOOLEAN type.  This is sort of a hack.  */
-       if (strncmp (tokstart, "TRUE", 4) == 0)
+       if (startswith (tokstart, "TRUE"))
        {
 	  yylval.ulval = 1;
 	  return M2_TRUE;
        }
-       else if (strncmp (tokstart, "FALSE", 5) == 0)
+       else if (startswith (tokstart, "FALSE"))
        {
 	  yylval.ulval = 0;
 	  return M2_FALSE;
diff --git a/gdb/macroexp.c b/gdb/macroexp.c
index 84584d4a00e..1ece8d5d5be 100644
--- a/gdb/macroexp.c
+++ b/gdb/macroexp.c
@@ -988,7 +988,7 @@ substitute_args (growable_macro_buffer *dest,
 					&keep_going))
     {
       bool token_is_vaopt = (tok.len == 10
-			     && strncmp (tok.text, "__VA_OPT__", 10) == 0);
+			     && startswith (tok.text, "__VA_OPT__"));
 
       if (vaopt_state > 0)
 	{
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 9a14d78e1e2..c087babd3c6 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1881,8 +1881,8 @@ command_notifies_uscc_observer (struct mi_parse *command)
   if (command->op == CLI_COMMAND)
     {
       /* CLI commands "thread" and "inferior" already send it.  */
-      return (strncmp (command->command, "thread ", 7) == 0
-	      || strncmp (command->command, "inferior ", 9) == 0);
+      return (startswith (command->command, "thread ")
+	      || startswith (command->command, "inferior "));
     }
   else /* MI_COMMAND */
     {
@@ -1890,8 +1890,8 @@ command_notifies_uscc_observer (struct mi_parse *command)
 	  && command->argc > 1)
 	{
 	  /* "thread" and "inferior" again, but through -interpreter-exec.  */
-	  return (strncmp (command->argv[1], "thread ", 7) == 0
-		  || strncmp (command->argv[1], "inferior ", 9) == 0);
+	  return (startswith (command->argv[1], "thread ")
+		  || startswith (command->argv[1], "inferior "));
 	}
 
       else
diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y
index 04003409887..3750af0dc34 100644
--- a/gdb/rust-exp.y
+++ b/gdb/rust-exp.y
@@ -1986,7 +1986,7 @@ munge_name_and_block (const char **name, const struct block **block)
 {
   /* If it is a global reference, skip the current block in favor of
      the static block.  */
-  if (strncmp (*name, "::", 2) == 0)
+  if (startswith (*name, "::"))
     {
       *name += 2;
       *block = block_static_block (*block);

^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH 0/5] Start using startswith instead of strncmp
  2021-03-23  0:02                   ` Alan Modra
  2021-03-23  4:49                     ` Mike Frysinger
@ 2021-03-24  8:19                     ` Martin Liska
  2021-03-18 14:16                       ` [PATCH 2/5] Use startswith more for strncmp function calls Martin Liska
                                         ` (5 more replies)
  2021-03-31 20:18                     ` [PATCH] Add startswith function and use it instead of CONST_STRNEQ Tom Tromey
  2 siblings, 6 replies; 41+ messages in thread
From: Martin Liska @ 2021-03-24  8:19 UTC (permalink / raw)
  To: binutils

Hey.

The patchset continues with replacement of the strncmp where it's used
in startswith context. The patches rely on Alan's patch and I've just
tested all possible targets.

Thoughts?
Thanks,
Martin

Martin Liska (5):
  Replace const_strneq with startswith.
  Use startswith more for strncmp function calls.
  Use startswith in gas subfolder.
  Remove strneq macro and use startswith.
  Use startswith in gdb subfolder.

 bfd/ecoff.c                |   5 +-
 bfd/elf-bfd.h              |   3 +-
 bfd/elf.c                  |  21 ++++---
 bfd/elf32-arc.c            |   2 +-
 bfd/elf32-m32r.c           |   4 +-
 bfd/elf32-microblaze.c     |   2 +-
 bfd/elf32-nds32.c          |  13 ++---
 bfd/elf32-or1k.c           |   2 +-
 bfd/elf32-ppc.c            |   6 +-
 bfd/elf32-rx.c             |   6 +-
 bfd/elf32-spu.c            |  26 ++++-----
 bfd/elf32-tilepro.c        |   2 +-
 bfd/elf32-xtensa.c         |   2 +-
 bfd/elf64-ppc.c            |   6 +-
 bfd/elflink.c              |  10 ++--
 bfd/elfnn-riscv.c          |   2 +-
 bfd/elfxx-riscv.c          |   4 +-
 bfd/elfxx-tilegx.c         |   2 +-
 bfd/opncls.c               |   2 +-
 binutils/dllwrap.c         |   8 +--
 binutils/dwarf.c           |   8 +--
 binutils/elfcomm.c         |   7 ++-
 binutils/elfcomm.h         |   2 -
 binutils/objcopy.c         |  20 +++----
 binutils/objdump.c         |   2 +-
 binutils/readelf.c         | 116 ++++++++++++++++++-------------------
 gas/as.c                   |   5 +-
 gas/config/m68k-parse.y    |  18 +++---
 gas/config/obj-aout.c      |   4 +-
 gas/config/obj-coff.c      |   5 +-
 gas/config/obj-elf.c       |  40 ++++++-------
 gas/config/obj-evax.c      |   2 +-
 gas/config/obj-macho.c     |   4 +-
 gas/config/tc-aarch64.c    |  11 ++--
 gas/config/tc-alpha.c      |  30 +++++-----
 gas/config/tc-arc.c        |  10 ++--
 gas/config/tc-arm.c        |  23 ++++----
 gas/config/tc-avr.c        |   8 +--
 gas/config/tc-cr16.c       |  26 ++++-----
 gas/config/tc-crx.c        |   1 -
 gas/config/tc-csky.c       |   6 +-
 gas/config/tc-d30v.c       |   2 +-
 gas/config/tc-dlx.c        |   4 +-
 gas/config/tc-epiphany.c   |   4 +-
 gas/config/tc-h8300.c      |  11 ++--
 gas/config/tc-hppa.c       |  26 ++++-----
 gas/config/tc-i386.c       |  12 ++--
 gas/config/tc-ia64.c       |  23 ++++----
 gas/config/tc-m32c.c       |   4 +-
 gas/config/tc-m68hc11.c    |  34 +++++------
 gas/config/tc-m68k.c       |  12 ++--
 gas/config/tc-mcore.c      |   2 +-
 gas/config/tc-metag.c      |   5 +-
 gas/config/tc-microblaze.c |  13 ++---
 gas/config/tc-mips.c       |  61 ++++++++++---------
 gas/config/tc-mmix.c       |   2 +-
 gas/config/tc-mn10300.c    |   4 +-
 gas/config/tc-msp430.c     |  30 +++++-----
 gas/config/tc-nds32.c      |   2 +-
 gas/config/tc-nds32.h      |   2 +-
 gas/config/tc-nios2.c      |  45 +++++++-------
 gas/config/tc-ns32k.c      |  18 +++---
 gas/config/tc-pdp11.c      |  64 ++++++++++----------
 gas/config/tc-pj.c         |   4 +-
 gas/config/tc-ppc.c        |  12 ++--
 gas/config/tc-s12z.c       |  24 ++++----
 gas/config/tc-s390.c       |   4 +-
 gas/config/tc-score.c      |   7 +--
 gas/config/tc-score7.c     |   7 +--
 gas/config/tc-sh.h         |   4 +-
 gas/config/tc-sparc.c      |  82 +++++++++++++-------------
 gas/config/tc-tic54x.c     |   4 +-
 gas/config/tc-tic6x.c      |   3 +-
 gas/config/tc-v850.c       |  26 ++++-----
 gas/config/tc-vax.c        |   2 +-
 gas/config/tc-wasm32.c     |   8 +--
 gas/config/tc-xstormy16.c  |   2 +-
 gas/config/tc-xtensa.c     |  14 ++---
 gas/config/xtensa-relax.c  |  10 ++--
 gas/dw2gencfi.c            |   7 +--
 gas/dwarf2dbg.c            |   2 +-
 gas/ehopt.c                |   6 +-
 gas/input-file.c           |   4 +-
 gas/listing.c              |  32 +++++-----
 gas/read.c                 |   2 +-
 gas/write.c                |   7 +--
 gdb/cp-name-parser.y       |  68 +++++++++++-----------
 gdb/m2-exp.y               |   4 +-
 gdb/macroexp.c             |   2 +-
 gdb/mi/mi-main.c           |   8 +--
 gdb/rust-exp.y             |   2 +-
 include/opcode/cr16.h      |   1 -
 ld/ldbuildid.c             |   7 +--
 opcodes/arm-dis.c          |   5 --
 opcodes/cr16-dis.c         |   2 +-
 opcodes/score-dis.c        |   8 ---
 opcodes/score7-dis.c       |   4 --
 97 files changed, 599 insertions(+), 641 deletions(-)

-- 
2.30.2


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ.
  2021-03-22 22:56                   ` Alan Modra
@ 2021-03-25 10:53                     ` Luis Machado
  2021-03-25 11:54                       ` Alan Modra
  0 siblings, 1 reply; 41+ messages in thread
From: Luis Machado @ 2021-03-25 10:53 UTC (permalink / raw)
  To: Alan Modra
  Cc: Tom Tromey, Mike Frysinger, Alan Modra via Binutils, gdb-patches

On 3/22/21 7:56 PM, Alan Modra wrote:
> On Mon, Mar 22, 2021 at 01:13:00PM -0300, Luis Machado wrote:
>> Just FTR, I'm seeing breakage in sim/aarch64 and sim/arm. Both are
>> complaining about "-Werror=implicit-function-declaration" regarding strncmp
>> and strlen.
>>
>> Is this the breakage you're talking about? Just so I know what to expect
>> when it gets fixed.
> 
> Yes.
> 

Thanks. Are there plans to address this or should I come up with a patch?

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ.
  2021-03-25 10:53                     ` Luis Machado
@ 2021-03-25 11:54                       ` Alan Modra
  2021-03-25 12:05                         ` Luis Machado
  2021-03-25 19:47                         ` Luis Machado
  0 siblings, 2 replies; 41+ messages in thread
From: Alan Modra @ 2021-03-25 11:54 UTC (permalink / raw)
  To: Luis Machado
  Cc: Tom Tromey, Mike Frysinger, Alan Modra via Binutils, gdb-patches

On Thu, Mar 25, 2021 at 07:53:04AM -0300, Luis Machado wrote:
> On 3/22/21 7:56 PM, Alan Modra wrote:
> > On Mon, Mar 22, 2021 at 01:13:00PM -0300, Luis Machado wrote:
> > > Just FTR, I'm seeing breakage in sim/aarch64 and sim/arm. Both are
> > > complaining about "-Werror=implicit-function-declaration" regarding strncmp
> > > and strlen.
> > > 
> > > Is this the breakage you're talking about? Just so I know what to expect
> > > when it gets fixed.
> > 
> > Yes.
> > 
> 
> Thanks. Are there plans to address this or should I come up with a patch?

I posted a patch here
https://sourceware.org/pipermail/binutils/2021-March/115863.html
It's been tested with gdb, sim and binutils builds.

Tom offered to solve the problem himself, so I'm waiting on that or
for someone in the gdb camp to review my patch.  Since I messed this
up in the first place by taking a comment by Tom as a go-ahead rather
than first posting a patch for proper review by gdb maintainers, I'm
being a little cautious in committing the above patch.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ.
  2021-03-25 11:54                       ` Alan Modra
@ 2021-03-25 12:05                         ` Luis Machado
  2021-03-25 19:47                         ` Luis Machado
  1 sibling, 0 replies; 41+ messages in thread
From: Luis Machado @ 2021-03-25 12:05 UTC (permalink / raw)
  To: Alan Modra
  Cc: Tom Tromey, Mike Frysinger, Alan Modra via Binutils, gdb-patches

On 3/25/21 8:54 AM, Alan Modra wrote:
> On Thu, Mar 25, 2021 at 07:53:04AM -0300, Luis Machado wrote:
>> On 3/22/21 7:56 PM, Alan Modra wrote:
>>> On Mon, Mar 22, 2021 at 01:13:00PM -0300, Luis Machado wrote:
>>>> Just FTR, I'm seeing breakage in sim/aarch64 and sim/arm. Both are
>>>> complaining about "-Werror=implicit-function-declaration" regarding strncmp
>>>> and strlen.
>>>>
>>>> Is this the breakage you're talking about? Just so I know what to expect
>>>> when it gets fixed.
>>>
>>> Yes.
>>>
>>
>> Thanks. Are there plans to address this or should I come up with a patch?
> 
> I posted a patch here
> https://sourceware.org/pipermail/binutils/2021-March/115863.html
> It's been tested with gdb, sim and binutils builds.
> 
> Tom offered to solve the problem himself, so I'm waiting on that or
> for someone in the gdb camp to review my patch.  Since I messed this
> up in the first place by taking a comment by Tom as a go-ahead rather
> than first posting a patch for proper review by gdb maintainers, I'm
> being a little cautious in committing the above patch.
> 

Ah, I missed that patch. Let me give that a try with the arm/aarch64 
sims and I'll let you know how that works.

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ.
  2021-03-25 11:54                       ` Alan Modra
  2021-03-25 12:05                         ` Luis Machado
@ 2021-03-25 19:47                         ` Luis Machado
  2021-03-25 22:31                           ` Mike Frysinger
  1 sibling, 1 reply; 41+ messages in thread
From: Luis Machado @ 2021-03-25 19:47 UTC (permalink / raw)
  To: Alan Modra
  Cc: Tom Tromey, Mike Frysinger, Alan Modra via Binutils, gdb-patches

Hi,

On 3/25/21 8:54 AM, Alan Modra wrote:
> On Thu, Mar 25, 2021 at 07:53:04AM -0300, Luis Machado wrote:
>> On 3/22/21 7:56 PM, Alan Modra wrote:
>>> On Mon, Mar 22, 2021 at 01:13:00PM -0300, Luis Machado wrote:
>>>> Just FTR, I'm seeing breakage in sim/aarch64 and sim/arm. Both are
>>>> complaining about "-Werror=implicit-function-declaration" regarding strncmp
>>>> and strlen.
>>>>
>>>> Is this the breakage you're talking about? Just so I know what to expect
>>>> when it gets fixed.
>>>
>>> Yes.
>>>
>>
>> Thanks. Are there plans to address this or should I come up with a patch?
> 
> I posted a patch here
> https://sourceware.org/pipermail/binutils/2021-March/115863.html
> It's been tested with gdb, sim and binutils builds.
> 
> Tom offered to solve the problem himself, so I'm waiting on that or
> for someone in the gdb camp to review my patch.  Since I messed this
> up in the first place by taking a comment by Tom as a go-ahead rather
> than first posting a patch for proper review by gdb maintainers, I'm
> being a little cautious in committing the above patch.
> 

I applied the above patch to today's master binutils-gdb and gave 
configure's --enable-targets=all a try, but I ran into the following:

In file included from ../../../repos/binutils-gdb/bfd/archive.c:135:
./bfd.h:568:1: error: redefinition of ‘startswith’
   568 | startswith (const char *str, const char *prefix)
       | ^~~~~~~~~~
In file included from ../../../repos/binutils-gdb/bfd/sysdep.h:122,
                  from ../../../repos/binutils-gdb/bfd/archive.c:134:
../../../repos/binutils-gdb/bfd/../include/str-util.h:23:1: note: 
previous definition of ‘startswith’ was here
    23 | startswith (const char *str, const char *prefix)
       | ^~~~~~~~~~

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ.
  2021-03-25 19:47                         ` Luis Machado
@ 2021-03-25 22:31                           ` Mike Frysinger
  2021-03-26 11:44                             ` Luis Machado
  0 siblings, 1 reply; 41+ messages in thread
From: Mike Frysinger @ 2021-03-25 22:31 UTC (permalink / raw)
  To: Luis Machado; +Cc: Alan Modra, Tom Tromey, Alan Modra via Binutils, gdb-patches

On 25 Mar 2021 16:47, Luis Machado wrote:
> On 3/25/21 8:54 AM, Alan Modra wrote:
> > On Thu, Mar 25, 2021 at 07:53:04AM -0300, Luis Machado wrote:
> >> On 3/22/21 7:56 PM, Alan Modra wrote:
> >>> On Mon, Mar 22, 2021 at 01:13:00PM -0300, Luis Machado wrote:
> >>>> Just FTR, I'm seeing breakage in sim/aarch64 and sim/arm. Both are
> >>>> complaining about "-Werror=implicit-function-declaration" regarding strncmp
> >>>> and strlen.
> >>>>
> >>>> Is this the breakage you're talking about? Just so I know what to expect
> >>>> when it gets fixed.
> >>>
> >>> Yes.
> >>>
> >>
> >> Thanks. Are there plans to address this or should I come up with a patch?
> > 
> > I posted a patch here
> > https://sourceware.org/pipermail/binutils/2021-March/115863.html
> > It's been tested with gdb, sim and binutils builds.
> > 
> > Tom offered to solve the problem himself, so I'm waiting on that or
> > for someone in the gdb camp to review my patch.  Since I messed this
> > up in the first place by taking a comment by Tom as a go-ahead rather
> > than first posting a patch for proper review by gdb maintainers, I'm
> > being a little cautious in committing the above patch.
> > 
> 
> I applied the above patch to today's master binutils-gdb and gave 
> configure's --enable-targets=all a try, but I ran into the following:
> 
> In file included from ../../../repos/binutils-gdb/bfd/archive.c:135:
> ./bfd.h:568:1: error: redefinition of ‘startswith’
>    568 | startswith (const char *str, const char *prefix)
>        | ^~~~~~~~~~
> In file included from ../../../repos/binutils-gdb/bfd/sysdep.h:122,
>                   from ../../../repos/binutils-gdb/bfd/archive.c:134:
> ../../../repos/binutils-gdb/bfd/../include/str-util.h:23:1: note: 
> previous definition of ‘startswith’ was here
>     23 | startswith (const char *str, const char *prefix)
>        | ^~~~~~~~~~

Alan's patch didn't include the regenerated bfd.h inputs, so you'll
have to do that on your side.
-mike

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ.
  2021-03-25 22:31                           ` Mike Frysinger
@ 2021-03-26 11:44                             ` Luis Machado
  2021-03-30 11:58                               ` Luis Machado
  0 siblings, 1 reply; 41+ messages in thread
From: Luis Machado @ 2021-03-26 11:44 UTC (permalink / raw)
  To: Alan Modra, Tom Tromey, Alan Modra via Binutils, gdb-patches

On 3/25/21 7:31 PM, Mike Frysinger wrote:
> On 25 Mar 2021 16:47, Luis Machado wrote:
>> On 3/25/21 8:54 AM, Alan Modra wrote:
>>> On Thu, Mar 25, 2021 at 07:53:04AM -0300, Luis Machado wrote:
>>>> On 3/22/21 7:56 PM, Alan Modra wrote:
>>>>> On Mon, Mar 22, 2021 at 01:13:00PM -0300, Luis Machado wrote:
>>>>>> Just FTR, I'm seeing breakage in sim/aarch64 and sim/arm. Both are
>>>>>> complaining about "-Werror=implicit-function-declaration" regarding strncmp
>>>>>> and strlen.
>>>>>>
>>>>>> Is this the breakage you're talking about? Just so I know what to expect
>>>>>> when it gets fixed.
>>>>>
>>>>> Yes.
>>>>>
>>>>
>>>> Thanks. Are there plans to address this or should I come up with a patch?
>>>
>>> I posted a patch here
>>> https://sourceware.org/pipermail/binutils/2021-March/115863.html
>>> It's been tested with gdb, sim and binutils builds.
>>>
>>> Tom offered to solve the problem himself, so I'm waiting on that or
>>> for someone in the gdb camp to review my patch.  Since I messed this
>>> up in the first place by taking a comment by Tom as a go-ahead rather
>>> than first posting a patch for proper review by gdb maintainers, I'm
>>> being a little cautious in committing the above patch.
>>>
>>
>> I applied the above patch to today's master binutils-gdb and gave
>> configure's --enable-targets=all a try, but I ran into the following:
>>
>> In file included from ../../../repos/binutils-gdb/bfd/archive.c:135:
>> ./bfd.h:568:1: error: redefinition of ‘startswith’
>>     568 | startswith (const char *str, const char *prefix)
>>         | ^~~~~~~~~~
>> In file included from ../../../repos/binutils-gdb/bfd/sysdep.h:122,
>>                    from ../../../repos/binutils-gdb/bfd/archive.c:134:
>> ../../../repos/binutils-gdb/bfd/../include/str-util.h:23:1: note:
>> previous definition of ‘startswith’ was here
>>      23 | startswith (const char *str, const char *prefix)
>>         | ^~~~~~~~~~
> 
> Alan's patch didn't include the regenerated bfd.h inputs, so you'll
> have to do that on your side.
> -mike
> 

Oops. Regenerated now. I gave it a try again and it worked OK.

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ.
  2021-03-26 11:44                             ` Luis Machado
@ 2021-03-30 11:58                               ` Luis Machado
  2021-03-31 13:12                                 ` Martin Liška
  0 siblings, 1 reply; 41+ messages in thread
From: Luis Machado @ 2021-03-30 11:58 UTC (permalink / raw)
  To: Alan Modra, Tom Tromey, Alan Modra via Binutils, gdb-patches
  Cc: Thomas Weißschuh

Hi Alan, Tom,

On 3/26/21 8:44 AM, Luis Machado wrote:
> On 3/25/21 7:31 PM, Mike Frysinger wrote:
>> On 25 Mar 2021 16:47, Luis Machado wrote:
>>> On 3/25/21 8:54 AM, Alan Modra wrote:
>>>> On Thu, Mar 25, 2021 at 07:53:04AM -0300, Luis Machado wrote:
>>>>> On 3/22/21 7:56 PM, Alan Modra wrote:
>>>>>> On Mon, Mar 22, 2021 at 01:13:00PM -0300, Luis Machado wrote:
>>>>>>> Just FTR, I'm seeing breakage in sim/aarch64 and sim/arm. Both are
>>>>>>> complaining about "-Werror=implicit-function-declaration" 
>>>>>>> regarding strncmp
>>>>>>> and strlen.
>>>>>>>
>>>>>>> Is this the breakage you're talking about? Just so I know what to 
>>>>>>> expect
>>>>>>> when it gets fixed.
>>>>>>
>>>>>> Yes.
>>>>>>
>>>>>
>>>>> Thanks. Are there plans to address this or should I come up with a 
>>>>> patch?
>>>>
>>>> I posted a patch here
>>>> https://sourceware.org/pipermail/binutils/2021-March/115863.html
>>>> It's been tested with gdb, sim and binutils builds.
>>>>
>>>> Tom offered to solve the problem himself, so I'm waiting on that or
>>>> for someone in the gdb camp to review my patch.  Since I messed this
>>>> up in the first place by taking a comment by Tom as a go-ahead rather
>>>> than first posting a patch for proper review by gdb maintainers, I'm
>>>> being a little cautious in committing the above patch.
>>>>
>>>
>>> I applied the above patch to today's master binutils-gdb and gave
>>> configure's --enable-targets=all a try, but I ran into the following:
>>>
>>> In file included from ../../../repos/binutils-gdb/bfd/archive.c:135:
>>> ./bfd.h:568:1: error: redefinition of ‘startswith’
>>>     568 | startswith (const char *str, const char *prefix)
>>>         | ^~~~~~~~~~
>>> In file included from ../../../repos/binutils-gdb/bfd/sysdep.h:122,
>>>                    from ../../../repos/binutils-gdb/bfd/archive.c:134:
>>> ../../../repos/binutils-gdb/bfd/../include/str-util.h:23:1: note:
>>> previous definition of ‘startswith’ was here
>>>      23 | startswith (const char *str, const char *prefix)
>>>         | ^~~~~~~~~~
>>
>> Alan's patch didn't include the regenerated bfd.h inputs, so you'll
>> have to do that on your side.
>> -mike
>>
> 
> Oops. Regenerated now. I gave it a try again and it worked OK.

Given this has been broken for a little while, and given Alan's patch 
fixes the problem for arm/aarch64 sims (from what I tested), can we push 
this for now and get it addressed in some other way later, if someone 
wants it?

I think someone's hit this on riscv as well.

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ.
  2021-03-30 11:58                               ` Luis Machado
@ 2021-03-31 13:12                                 ` Martin Liška
  2021-03-31 13:44                                   ` Luis Machado
  0 siblings, 1 reply; 41+ messages in thread
From: Martin Liška @ 2021-03-31 13:12 UTC (permalink / raw)
  To: Luis Machado, Alan Modra, Tom Tromey, Alan Modra via Binutils,
	gdb-patches
  Cc: Thomas Weißschuh

> Given this has been broken for a little while, and given Alan's patch fixes the problem for arm/aarch64 sims (from what I tested), can we push this for now and get it addressed in some other way later, if someone wants it?
> 
> I think someone's hit this on riscv as well.

It's fixed now with Alan's patch:

commit 57ae980e3290c0c1a9fb4a93144cc5b24457f05a
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Mar 31 10:02:08 2021 +1030

     Include string.h in bfd.h and delete LITMEMCPY, LITSTRCPY
     
     This fixes the issue that startswith depends on strncpy being
     declared, and not all projects using bfd.h include string.h before
     bfd.h.  I've also deleted some macros that don't find much use
     anywhere.
     
     bfd/
             * bfd-in.h: Include string.h.
             (LITMEMCPY, LITSTRCPY): Delete.
             * bfd-in2.h: Regenerate.
     binutils/
             * prdbg.c (pr_function_type): Replace LITSTTCPY with strcpy.

Cheers,
Martin

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ.
  2021-03-31 13:12                                 ` Martin Liška
@ 2021-03-31 13:44                                   ` Luis Machado
  0 siblings, 0 replies; 41+ messages in thread
From: Luis Machado @ 2021-03-31 13:44 UTC (permalink / raw)
  To: Martin Liška, Alan Modra, Tom Tromey,
	Alan Modra via Binutils, gdb-patches
  Cc: Thomas Weißschuh

On 3/31/21 10:12 AM, Martin Liška wrote:
>> Given this has been broken for a little while, and given Alan's patch 
>> fixes the problem for arm/aarch64 sims (from what I tested), can we 
>> push this for now and get it addressed in some other way later, if 
>> someone wants it?
>>
>> I think someone's hit this on riscv as well.
> 
> It's fixed now with Alan's patch:
> 
> commit 57ae980e3290c0c1a9fb4a93144cc5b24457f05a
> Author: Alan Modra <amodra@gmail.com>
> Date:   Wed Mar 31 10:02:08 2021 +1030
> 
>      Include string.h in bfd.h and delete LITMEMCPY, LITSTRCPY
>      This fixes the issue that startswith depends on strncpy being
>      declared, and not all projects using bfd.h include string.h before
>      bfd.h.  I've also deleted some macros that don't find much use
>      anywhere.
>      bfd/
>              * bfd-in.h: Include string.h.
>              (LITMEMCPY, LITSTRCPY): Delete.
>              * bfd-in2.h: Regenerate.
>      binutils/
>              * prdbg.c (pr_function_type): Replace LITSTTCPY with strcpy.
> 
> Cheers,
> Martin

Thanks Alan/Martin. I've confirmed the arm/aarch64 sim failures are 
fixed now.

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH] Add startswith function and use it instead of CONST_STRNEQ.
  2021-03-23  0:02                   ` Alan Modra
  2021-03-23  4:49                     ` Mike Frysinger
  2021-03-24  8:19                     ` [PATCH 0/5] Start using startswith instead of strncmp Martin Liska
@ 2021-03-31 20:18                     ` Tom Tromey
  2 siblings, 0 replies; 41+ messages in thread
From: Tom Tromey @ 2021-03-31 20:18 UTC (permalink / raw)
  To: Alan Modra
  Cc: Martin Liška, Tom Tromey, Mike Frysinger,
	Alan Modra via Binutils, gdb-patches

Hi.  I'm sorry about the delay on this.

Alan> But all of this horrible old code that likely hasn't been tested is
Alan> eons should simply disappear.

gdb has this issue to a lesser degree as well, where it checks for
headers that have not been missing in 20 years.  This kind of rot is one
of the downsides of the autoconf approach.

Alan> Instead binutils should be using the
Alan> gnulib import already available in the binutils-gdb repository to
Alan> support old systems.  I've had that project on my todo list for quite
Alan> a while.  We'd be able to include stdint.h and stdbool.h for example,
Alan> throwing away bfd_stdint.h and replacing bfd_boolean with bool.

We've had mixed experiences with gnulib in gdb.  Partly that's because
gdb is in C++; but also partly because gnulib is fairly opinionated
about some things, and if you want to be more flexible, it's difficult.

Anyway, I think it would be a good thing to try.  And, it's relatively
easy now that gnulib has moved to the top-level.  The main difficulty
that I would anticipate is that I think there are some gnulib modules
that can't be used for gdb; but if binutils needed these then we'd be in
a bit of a quandary.

I suppose though that the gnulib model is to patch things upstream and
so we could try to work out problems that way.

Alan> Meanwhile, this is a tidied version of the patch I sent you last
Alan> night, Tom.  If you already have one of your own then please ignore
Alan> this.

This looks good to me.  Thank you.

Alan> +#ifndef STR_UTIL_H
Alan> +#define STR_UTIL_H
Alan> +
Alan> +/* Return 1 if the start of STR matches PREFIX, 0 otherwise.  */
Alan> +
Alan> +static inline int
Alan> +startswith (const char *str, const char *prefix)
Alan> +{
Alan> +  return strncmp (str, prefix, strlen (prefix)) == 0;

In keeping with the above, I tend to think that adding a <string.h>
include in this file would be fine, and unlikely to break the build on
any real system.

If there is one, that would be interesting information.

Here's what gnulib has to say about string.h:

https://www.gnu.org/software/gnulib/manual/html_node/string_002eh.html

... if it were missing anywhere, I suppose I'd expect a bullet point to
that effect.

Tom

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 5/5] Use startswith in gdb subfolder.
  2021-03-23  9:02                       ` [PATCH 5/5] Use startswith in gdb subfolder Martin Liska
@ 2021-03-31 20:26                         ` Tom Tromey
  0 siblings, 0 replies; 41+ messages in thread
From: Tom Tromey @ 2021-03-31 20:26 UTC (permalink / raw)
  To: Martin Liska; +Cc: binutils

>>>>> "Martin" == Martin Liska <mliska@suse.cz> writes:

Martin> ChangeLog:

Martin> 	* gdb/cp-name-parser.y: Use startswith instead of strncmp.
Martin> 	* gdb/m2-exp.y: Likewise.
Martin> 	* gdb/macroexp.c (substitute_args): Likewise.
Martin> 	* gdb/mi/mi-main.c (command_notifies_uscc_observer): Likewise.
Martin> 	* gdb/rust-exp.y: Likewise.

Thank you.  This is ok.

Tom

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 0/5] Start using startswith instead of strncmp
  2021-03-24  8:19                     ` [PATCH 0/5] Start using startswith instead of strncmp Martin Liska
                                         ` (4 preceding siblings ...)
  2021-03-23  9:02                       ` [PATCH 5/5] Use startswith in gdb subfolder Martin Liska
@ 2021-04-01  5:21                       ` Martin Liška
  2021-04-01 12:47                         ` Alan Modra
  5 siblings, 1 reply; 41+ messages in thread
From: Martin Liška @ 2021-04-01  5:21 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 380 bytes --]

On 3/24/21 9:19 AM, Martin Liska wrote:
> Hey.
> 
> The patchset continues with replacement of the strncmp where it's used
> in startswith context. The patches rely on Alan's patch and I've just
> tested all possible targets.

Hello.

I'm sending rebased patches 1-4 after recent boolean changes.
I tested the patches for all targets.

Is it ready to be installed?
Thanks,
Martin

[-- Attachment #2: 0003-Use-startswith-in-gas-subfolder.patch --]
[-- Type: text/x-patch, Size: 104988 bytes --]

From aa79aca07408205e6fee50d1bf9f478dff740078 Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Mon, 22 Mar 2021 13:33:04 +0100
Subject: [PATCH 3/4] Use startswith in gas subfolder.

gas/ChangeLog:

	* as.c (select_emulation_mode): Use startswith.
	* config/m68k-parse.y: Likewise.
	* config/obj-aout.c (obj_aout_type): Likewise.
	* config/obj-elf.c (elf_common_parse): Likewise.
	(obj_elf_section_type): Likewise.
	(obj_elf_section_word): Likewise.
	(obj_elf_section): Likewise.
	(obj_elf_symver): Likewise.
	(adjust_stab_sections): Likewise.
	* config/obj-evax.c (evax_shorten_name): Likewise.
	* config/obj-macho.c (obj_mach_o_is_frame_section): Likewise.
	* config/tc-aarch64.c (parse_aarch64_imm_float): Likewise.
	(aarch64_parse_features): Likewise.
	(create_register_alias): Likewise.
	(aarch64_data_in_code): Likewise.
	(md_parse_option): Likewise.
	* config/tc-alpha.c (s_alpha_section_word): Likewise.
	(s_alpha_pdesc): Likewise.
	* config/tc-arc.c (tokenize_extregister): Likewise.
	* config/tc-arm.c (create_register_alias): Likewise.
	(create_neon_reg_alias): Likewise.
	(parse_ifimm_zero): Likewise.
	(parse_qfloat_immediate): Likewise.
	(arm_elf_section_type): Likewise.
	(arm_parse_extension): Likewise.
	(aeabi_set_public_attributes): Likewise.
	(s_arm_arch_extension): Likewise.
	(arm_data_in_code): Likewise.
	(start_unwind_section): Likewise.
	* config/tc-avr.c (avr_ldi_expression): Likewise.
	* config/tc-csky.c (is_freglist_legal): Likewise.
	(csky_s_section): Likewise.
	* config/tc-d30v.c (do_assemble): Likewise.
	* config/tc-dlx.c (parse_operand): Likewise.
	* config/tc-epiphany.c (md_assemble): Likewise.
	* config/tc-h8300.c (h8300_elf_section): Likewise.
	(get_operand): Likewise.
	* config/tc-hppa.c (pa_ip): Likewise.
	(pa_level): Likewise.
	(pa_space): Likewise.
	* config/tc-i386.c (i386_mach): Likewise.
	(md_assemble): Likewise.
	(check_VecOperations): Likewise.
	(i386_target_format): Likewise.
	(i386_elf_section_type): Likewise.
	* config/tc-ia64.c (start_unwind_section): Likewise.
	(md_parse_option): Likewise.
	(is_taken_branch): Likewise.
	(idesc->name,): Likewise.
	(note_register_values): Likewise.
	(do_alias): Likewise.
	* config/tc-m32c.c (insn_to_subtype): Likewise.
	* config/tc-m68hc11.c (get_operand): Likewise.
	(md_assemble): Likewise.
	* config/tc-m68k.c (m68k_ip): Likewise.
	(m68k_elf_suffix): Likewise.
	* config/tc-mcore.c (mcore_s_section): Likewise.
	* config/tc-metag.c (parse_get_set): Likewise.
	(md_parse_option): Likewise.
	* config/tc-microblaze.c (parse_imm): Likewise.
	(check_got): Likewise.
	(md_apply_fix): Likewise.
	* config/tc-mips.c (CPU_HAS_MIPS16): Likewise.
	(md_begin): Likewise.
	(s_is_linkonce): Likewise.
	(check_regno): Likewise.
	(match_float_constant): Likewise.
	(classify_vr4120_insn): Likewise.
	(match_insn): Likewise.
	(mips_after_parse_args): Likewise.
	(s_change_sec): Likewise.
	(s_option): Likewise.
	(parse_code_option): Likewise.
	(md_section_align): Likewise.
	(nopic_need_relax): Likewise.
	* config/tc-mmix.c (mmix_handle_mmixal): Likewise.
	* config/tc-mn10300.c (mn10300_fix_adjustable): Likewise.
	(mn10300_end_of_match): Likewise.
	* config/tc-msp430.c (msp430_make_init_symbols): Likewise.
	* config/tc-nds32.c (nds32_parse_option): Likewise.
	* config/tc-nds32.h (md_do_align): Likewise.
	* config/tc-nios2.c (strprefix): Likewise.
	(nios2_special_relocation_p): Likewise.
	(nios2_parse_base_register): Likewise.
	(nios2_cons): Likewise.
	* config/tc-ns32k.c (addr_mode): Likewise.
	* config/tc-pdp11.c (set_option): Likewise.
	(parse_reg): Likewise.
	(parse_ac5): Likewise.
	(parse_op_no_deferred): Likewise.
	(set_cpu_model): Likewise.
	(set_machine_model): Likewise.
	* config/tc-pj.c (md_operand): Likewise.
	* config/tc-ppc.c (ppc_set_cpu): Likewise.
	(ppc_arch): Likewise.
	(ppc_section_type): Likewise.
	* config/tc-s12z.c (tb_reg_rel): Likewise.
	(tb_opr_rel): Likewise.
	* config/tc-s390.c (s390_parse_cpu): Likewise.
	(md_parse_option): Likewise.
	* config/tc-score.c (s3_nopic_need_relax): Likewise.
	(s3_pic_need_relax): Likewise.
	* config/tc-score7.c (s7_nopic_need_relax): Likewise.
	(s7_pic_need_relax): Likewise.
	* config/tc-sh.h (SUB_SEGMENT_ALIGN): Likewise.
	* config/tc-sparc.c (md_parse_option): Likewise.
	(sparc_ip): Likewise.
	(s_reserve): Likewise.
	(s_common): Likewise.
	(s_seg): Likewise.
	(sparc_cons): Likewise.
	* config/tc-tic54x.c (stag_add_field): Likewise.
	(tic54x_endstruct): Likewise.
	* config/tc-tic6x.c (tic6x_start_unwind_section): Likewise.
	* config/tc-v850.c (v850_comm): Likewise.
	(md_begin): Likewise.
	(md_assemble): Likewise.
	* config/tc-vax.c (vax_cons): Likewise.
	* config/tc-wasm32.c (wasm32_leb128): Likewise.
	* config/tc-xstormy16.c (md_operand): Likewise.
	* config/tc-xtensa.c (get_directive): Likewise.
	(xg_instruction_matches_option_term): Likewise.
	(is_unaligned_label): Likewise.
	(cache_literal_section): Likewise.
	* config/xtensa-relax.c (parse_precond): Likewise.
	(parse_option_cond): Likewise.
	(transition_applies): Likewise.
	(wide_branch_opcode): Likewise.
	* dw2gencfi.c: Likewise.
	* dwarf2dbg.c (dwarf2_directive_filename): Likewise.
	* ehopt.c (get_cie_info): Likewise.
	* input-file.c (input_file_open): Likewise.
	* listing.c (listing_newline): Likewise.
	(debugging_pseudo): Likewise.
	* read.c (read_a_source_file): Likewise.
	* write.c (adjust_reloc_syms): Likewise.
	(compress_debug): Likewise.
	(maybe_generate_build_notes): Likewise.
---
 gas/as.c                   |  5 +--
 gas/config/m68k-parse.y    | 18 ++++-----
 gas/config/obj-aout.c      |  4 +-
 gas/config/obj-elf.c       | 40 +++++++++----------
 gas/config/obj-evax.c      |  2 +-
 gas/config/obj-macho.c     |  4 +-
 gas/config/tc-aarch64.c    | 11 +++--
 gas/config/tc-alpha.c      | 30 +++++++-------
 gas/config/tc-arc.c        | 10 ++---
 gas/config/tc-arm.c        | 23 +++++------
 gas/config/tc-avr.c        |  8 ++--
 gas/config/tc-csky.c       |  6 +--
 gas/config/tc-d30v.c       |  2 +-
 gas/config/tc-dlx.c        |  4 +-
 gas/config/tc-epiphany.c   |  4 +-
 gas/config/tc-h8300.c      | 11 +++--
 gas/config/tc-hppa.c       | 26 ++++++------
 gas/config/tc-i386.c       | 14 +++----
 gas/config/tc-ia64.c       | 23 +++++------
 gas/config/tc-m32c.c       |  4 +-
 gas/config/tc-m68hc11.c    | 34 ++++++++--------
 gas/config/tc-m68k.c       | 12 +++---
 gas/config/tc-mcore.c      |  2 +-
 gas/config/tc-metag.c      |  5 +--
 gas/config/tc-microblaze.c | 13 +++---
 gas/config/tc-mips.c       | 61 ++++++++++++++--------------
 gas/config/tc-mmix.c       |  2 +-
 gas/config/tc-mn10300.c    |  4 +-
 gas/config/tc-msp430.c     | 30 +++++++-------
 gas/config/tc-nds32.c      |  2 +-
 gas/config/tc-nds32.h      |  2 +-
 gas/config/tc-nios2.c      | 45 ++++++++++-----------
 gas/config/tc-ns32k.c      | 18 ++++-----
 gas/config/tc-pdp11.c      | 64 ++++++++++++++---------------
 gas/config/tc-pj.c         |  4 +-
 gas/config/tc-ppc.c        | 12 +++---
 gas/config/tc-s12z.c       | 24 +++++------
 gas/config/tc-s390.c       |  4 +-
 gas/config/tc-score.c      |  7 ++--
 gas/config/tc-score7.c     |  7 ++--
 gas/config/tc-sh.h         |  4 +-
 gas/config/tc-sparc.c      | 82 +++++++++++++++++++-------------------
 gas/config/tc-tic54x.c     |  4 +-
 gas/config/tc-tic6x.c      |  3 +-
 gas/config/tc-v850.c       | 26 ++++++------
 gas/config/tc-vax.c        |  2 +-
 gas/config/tc-wasm32.c     |  8 ++--
 gas/config/tc-xstormy16.c  |  2 +-
 gas/config/tc-xtensa.c     | 14 +++----
 gas/config/xtensa-relax.c  | 10 ++---
 gas/dw2gencfi.c            |  7 ++--
 gas/dwarf2dbg.c            |  2 +-
 gas/ehopt.c                |  6 +--
 gas/input-file.c           |  4 +-
 gas/listing.c              | 32 +++++++--------
 gas/read.c                 |  2 +-
 gas/write.c                |  7 ++--
 57 files changed, 399 insertions(+), 417 deletions(-)

diff --git a/gas/as.c b/gas/as.c
index d12cb0fbacf..b2684fabe51 100644
--- a/gas/as.c
+++ b/gas/as.c
@@ -158,7 +158,7 @@ select_emulation_mode (int argc, char **argv)
   const char *em = NULL;
 
   for (i = 1; i < argc; i++)
-    if (!strncmp ("--em", argv[i], 4))
+    if (startswith (argv[i], "--em"))
       break;
 
   if (i == argc)
@@ -819,8 +819,7 @@ This program has absolutely no warranty.\n"));
 	  /* We end up here for any -gsomething-not-already-a-long-option.
 	     give some useful feedback on not (yet) supported -gdwarfxxx
 	     versions/sections/options.  */
-	  if (strncmp (old_argv[optind - 1], "-gdwarf",
-		       strlen ("-gdwarf")) == 0)
+	  if (startswith (old_argv[optind - 1], "-gdwarf"))
 	    as_fatal (_("unknown DWARF option %s\n"), old_argv[optind - 1]);
 
 	  if (md_debug_format_selector)
diff --git a/gas/config/m68k-parse.y b/gas/config/m68k-parse.y
index 7f30eb87aaa..7528380a378 100644
--- a/gas/config/m68k-parse.y
+++ b/gas/config/m68k-parse.y
@@ -1008,12 +1008,12 @@ yylex (void)
     cp = s - tail;
     if (cp - 7 > str && cp[-7] == '@')
       {
-	if (strncmp (cp - 7, "@TLSLDM", 7) == 0)
+	if (startswith (cp - 7, "@TLSLDM"))
 	  {
 	    yylval.exp.pic_reloc = pic_tls_ldm;
 	    tail += 7;
 	  }
-	else if (strncmp (cp - 7, "@TLSLDO", 7) == 0)
+	else if (startswith (cp - 7, "@TLSLDO"))
 	  {
 	    yylval.exp.pic_reloc = pic_tls_ldo;
 	    tail += 7;
@@ -1021,27 +1021,27 @@ yylex (void)
       }
     else if (cp - 6 > str && cp[-6] == '@')
       {
-	if (strncmp (cp - 6, "@PLTPC", 6) == 0)
+	if (startswith (cp - 6, "@PLTPC"))
 	  {
 	    yylval.exp.pic_reloc = pic_plt_pcrel;
 	    tail += 6;
 	  }
-	else if (strncmp (cp - 6, "@GOTPC", 6) == 0)
+	else if (startswith (cp - 6, "@GOTPC"))
 	  {
 	    yylval.exp.pic_reloc = pic_got_pcrel;
 	    tail += 6;
 	  }
-	else if (strncmp (cp - 6, "@TLSGD", 6) == 0)
+	else if (startswith (cp - 6, "@TLSGD"))
 	  {
 	    yylval.exp.pic_reloc = pic_tls_gd;
 	    tail += 6;
 	  }
-	else if (strncmp (cp - 6, "@TLSIE", 6) == 0)
+	else if (startswith (cp - 6, "@TLSIE"))
 	  {
 	    yylval.exp.pic_reloc = pic_tls_ie;
 	    tail += 6;
 	  }
-	else if (strncmp (cp - 6, "@TLSLE", 6) == 0)
+	else if (startswith (cp - 6, "@TLSLE"))
 	  {
 	    yylval.exp.pic_reloc = pic_tls_le;
 	    tail += 6;
@@ -1049,12 +1049,12 @@ yylex (void)
       }
     else if (cp - 4 > str && cp[-4] == '@')
       {
-	if (strncmp (cp - 4, "@PLT", 4) == 0)
+	if (startswith (cp - 4, "@PLT"))
 	  {
 	    yylval.exp.pic_reloc = pic_plt_off;
 	    tail += 4;
 	  }
-	else if (strncmp (cp - 4, "@GOT", 4) == 0)
+	else if (startswith (cp - 4, "@GOT"))
 	  {
 	    yylval.exp.pic_reloc = pic_got_off;
 	    tail += 4;
diff --git a/gas/config/obj-aout.c b/gas/config/obj-aout.c
index 99f879b8f97..b41820b1b69 100644
--- a/gas/config/obj-aout.c
+++ b/gas/config/obj-aout.c
@@ -210,9 +210,9 @@ obj_aout_type (int ignore ATTRIBUTE_UNUSED)
       if (*input_line_pointer == '@')
 	{
 	  ++input_line_pointer;
-	  if (strncmp (input_line_pointer, "object", 6) == 0)
+	  if (startswith (input_line_pointer, "object"))
 	    S_SET_OTHER (sym, 1);
-	  else if (strncmp (input_line_pointer, "function", 8) == 0)
+	  else if (startswith (input_line_pointer, "function"))
 	    S_SET_OTHER (sym, 2);
 	}
     }
diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c
index 8e8c6d50c2a..d2b9ee2ff55 100644
--- a/gas/config/obj-elf.c
+++ b/gas/config/obj-elf.c
@@ -324,9 +324,9 @@ elf_common_parse (int ignore ATTRIBUTE_UNUSED, symbolS *symbolP, addressT size)
 	  if (*input_line_pointer == '.')
 	    input_line_pointer++;
 	  /* Some say data, some say bss.  */
-	  if (strncmp (input_line_pointer, "bss\"", 4) == 0)
+	  if (startswith (input_line_pointer, "bss\""))
 	    input_line_pointer += 4;
-	  else if (strncmp (input_line_pointer, "data\"", 5) == 0)
+	  else if (startswith (input_line_pointer, "data\""))
 	    input_line_pointer += 5;
 	  else
 	    {
@@ -949,17 +949,17 @@ obj_elf_parse_section_letters (char *str, size_t len,
 static int
 obj_elf_section_type (char *str, size_t len, bool warn)
 {
-  if (len == 8 && strncmp (str, "progbits", 8) == 0)
+  if (len == 8 && startswith (str, "progbits"))
     return SHT_PROGBITS;
-  if (len == 6 && strncmp (str, "nobits", 6) == 0)
+  if (len == 6 && startswith (str, "nobits"))
     return SHT_NOBITS;
-  if (len == 4 && strncmp (str, "note", 4) == 0)
+  if (len == 4 && startswith (str, "note"))
     return SHT_NOTE;
-  if (len == 10 && strncmp (str, "init_array", 10) == 0)
+  if (len == 10 && startswith (str, "init_array"))
     return SHT_INIT_ARRAY;
-  if (len == 10 && strncmp (str, "fini_array", 10) == 0)
+  if (len == 10 && startswith (str, "fini_array"))
     return SHT_FINI_ARRAY;
-  if (len == 13 && strncmp (str, "preinit_array", 13) == 0)
+  if (len == 13 && startswith (str, "preinit_array"))
     return SHT_PREINIT_ARRAY;
 
 #ifdef md_elf_section_type
@@ -991,15 +991,15 @@ obj_elf_section_word (char *str, size_t len, int *type)
 {
   int ret;
 
-  if (len == 5 && strncmp (str, "write", 5) == 0)
+  if (len == 5 && startswith (str, "write"))
     return SHF_WRITE;
-  if (len == 5 && strncmp (str, "alloc", 5) == 0)
+  if (len == 5 && startswith (str, "alloc"))
     return SHF_ALLOC;
-  if (len == 9 && strncmp (str, "execinstr", 9) == 0)
+  if (len == 9 && startswith (str, "execinstr"))
     return SHF_EXECINSTR;
-  if (len == 7 && strncmp (str, "exclude", 7) == 0)
+  if (len == 7 && startswith (str, "exclude"))
     return SHF_EXCLUDE;
-  if (len == 3 && strncmp (str, "tls", 3) == 0)
+  if (len == 3 && startswith (str, "tls"))
     return SHF_TLS;
 
 #ifdef md_elf_section_word
@@ -1291,13 +1291,13 @@ obj_elf_section (int push)
 		{
 		  ++input_line_pointer;
 		  SKIP_WHITESPACE ();
-		  if (strncmp (input_line_pointer, "comdat", 6) == 0)
+		  if (startswith (input_line_pointer, "comdat"))
 		    {
 		      input_line_pointer += 6;
 		      linkonce = 1;
 		    }
 		}
-	      else if (strncmp (name, ".gnu.linkonce", 13) == 0)
+	      else if (startswith (name, ".gnu.linkonce"))
 		linkonce = 1;
 	    }
 	  else if ((attr & SHF_GROUP) != 0)
@@ -1345,7 +1345,7 @@ obj_elf_section (int push)
 
 	      ++input_line_pointer;
 	      SKIP_WHITESPACE ();
-	      if (strncmp (input_line_pointer, "unique", 6) == 0)
+	      if (startswith (input_line_pointer, "unique"))
 		{
 		  input_line_pointer += 6;
 		  SKIP_WHITESPACE ();
@@ -1748,17 +1748,17 @@ obj_elf_symver (int ignore ATTRIBUTE_UNUSED)
 
       ++input_line_pointer;
       SKIP_WHITESPACE ();
-      if (strncmp (input_line_pointer, "local", 5) == 0)
+      if (startswith (input_line_pointer, "local"))
 	{
 	  input_line_pointer += 5;
 	  sy_obj->visibility = visibility_local;
 	}
-      else if (strncmp (input_line_pointer, "hidden", 6) == 0)
+      else if (startswith (input_line_pointer, "hidden"))
 	{
 	  input_line_pointer += 6;
 	  sy_obj->visibility = visibility_hidden;
 	}
-      else if (strncmp (input_line_pointer, "remove", 6) == 0)
+      else if (startswith (input_line_pointer, "remove"))
 	{
 	  input_line_pointer += 6;
 	  sy_obj->visibility = visibility_remove;
@@ -2508,7 +2508,7 @@ adjust_stab_sections (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED)
   char *p;
   int strsz, nsyms;
 
-  if (strncmp (".stab", sec->name, 5))
+  if (!startswith (".stab", sec->name))
     return;
   if (!strcmp ("str", sec->name + strlen (sec->name) - 3))
     return;
diff --git a/gas/config/obj-evax.c b/gas/config/obj-evax.c
index 8763a7c29ac..d39b4896945 100644
--- a/gas/config/obj-evax.c
+++ b/gas/config/obj-evax.c
@@ -239,7 +239,7 @@ evax_shorten_name (char *id)
   prefix [0] = 0;
 
   /* Check for ..xx suffix and save it.  */
-  if (strncmp (&id[len-4], "..", 2) == 0)
+  if (startswith (&id[len-4], ".."))
     {
       suffix_dotdot = len - 4;
       strncpy (suffix, &id[len-4], 4);
diff --git a/gas/config/obj-macho.c b/gas/config/obj-macho.c
index 1380707e3c9..9e7dc19ae50 100644
--- a/gas/config/obj-macho.c
+++ b/gas/config/obj-macho.c
@@ -1907,8 +1907,8 @@ obj_mach_o_is_frame_section (segT sec)
 {
   int l;
   l = strlen (segment_name (sec));
-  if ((l == 9 && strncmp (".eh_frame", segment_name (sec), 9) == 0)
-       || (l == 12 && strncmp (".debug_frame", segment_name (sec), 12) == 0))
+  if ((l == 9 && startswith (".eh_frame", segment_name (sec)))
+       || (l == 12 && startswith (".debug_frame", segment_name (sec))))
     return 1;
   return 0;
 }
diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c
index fdc14403b34..1870955380f 100644
--- a/gas/config/tc-aarch64.c
+++ b/gas/config/tc-aarch64.c
@@ -1353,7 +1353,7 @@ create_register_alias (char *newname, char *p)
   /* The input scrubber ensures that whitespace after the mnemonic is
      collapsed to single spaces.  */
   oldname = p;
-  if (strncmp (oldname, " .req ", 6) != 0)
+  if (!startswith (oldname, " .req "))
     return false;
 
   oldname += 6;
@@ -2372,7 +2372,7 @@ parse_aarch64_imm_float (char **ccp, int *immed, bool dp_p,
   fpnum = str;
   skip_whitespace (fpnum);
 
-  if (strncmp (fpnum, "0x", 2) == 0)
+  if (startswith (fpnum, "0x"))
     {
       /* Support the hexadecimal representation of the IEEE754 encoding.
 	 Double-precision is expected when DP_P is TRUE, otherwise the
@@ -7253,7 +7253,7 @@ aarch64_frob_section (asection *sec ATTRIBUTE_UNUSED)
 int
 aarch64_data_in_code (void)
 {
-  if (!strncmp (input_line_pointer + 1, "data:", 5))
+  if (startswith (input_line_pointer + 1, "data:"))
     {
       *input_line_pointer = '/';
       input_line_pointer += 5;
@@ -9287,7 +9287,7 @@ aarch64_parse_features (const char *str, const aarch64_feature_set **opt_p,
       else
 	optlen = strlen (str);
 
-      if (optlen >= 2 && strncmp (str, "no", 2) == 0)
+      if (optlen >= 2 && startswith (str, "no"))
 	{
 	  if (adding_value != 0)
 	    adding_value = 0;
@@ -9504,8 +9504,7 @@ md_parse_option (int c, const char *arg)
 	  /* These options are expected to have an argument.  */
 	  if (c == lopt->option[0]
 	      && arg != NULL
-	      && strncmp (arg, lopt->option + 1,
-			  strlen (lopt->option + 1)) == 0)
+	      && startswith (arg, lopt->option + 1))
 	    {
 	      /* If the option is deprecated, tell the user.  */
 	      if (lopt->deprecated != NULL)
diff --git a/gas/config/tc-alpha.c b/gas/config/tc-alpha.c
index 96837559393..ed2e8a98e7e 100644
--- a/gas/config/tc-alpha.c
+++ b/gas/config/tc-alpha.c
@@ -4229,7 +4229,7 @@ s_alpha_section_word (char *str, size_t len)
   int no = 0;
   flagword flag = 0;
 
-  if (len == 5 && strncmp (str, "NO", 2) == 0)
+  if (len == 5 && startswith (str, "NO"))
     {
       no = 1;
       str += 2;
@@ -4238,30 +4238,30 @@ s_alpha_section_word (char *str, size_t len)
 
   if (len == 3)
     {
-      if (strncmp (str, "PIC", 3) == 0)
+      if (startswith (str, "PIC"))
 	flag = EGPS__V_PIC;
-      else if (strncmp (str, "LIB", 3) == 0)
+      else if (startswith (str, "LIB"))
 	flag = EGPS__V_LIB;
-      else if (strncmp (str, "OVR", 3) == 0)
+      else if (startswith (str, "OVR"))
 	flag = EGPS__V_OVR;
-      else if (strncmp (str, "REL", 3) == 0)
+      else if (startswith (str, "REL"))
 	flag = EGPS__V_REL;
-      else if (strncmp (str, "GBL", 3) == 0)
+      else if (startswith (str, "GBL"))
 	flag = EGPS__V_GBL;
-      else if (strncmp (str, "SHR", 3) == 0)
+      else if (startswith (str, "SHR"))
 	flag = EGPS__V_SHR;
-      else if (strncmp (str, "EXE", 3) == 0)
+      else if (startswith (str, "EXE"))
 	flag = EGPS__V_EXE;
-      else if (strncmp (str, "WRT", 3) == 0)
+      else if (startswith (str, "WRT"))
 	flag = EGPS__V_WRT;
-      else if (strncmp (str, "VEC", 3) == 0)
+      else if (startswith (str, "VEC"))
 	flag = EGPS__V_VEC;
-      else if (strncmp (str, "MOD", 3) == 0)
+      else if (startswith (str, "MOD"))
 	{
 	  flag = no ? EGPS__V_NOMOD : EGPS__V_NOMOD << EGPS__V_NO_SHIFT;
 	  no = 0;
 	}
-      else if (strncmp (str, "COM", 3) == 0)
+      else if (startswith (str, "COM"))
 	flag = EGPS__V_COM;
     }
 
@@ -4544,13 +4544,13 @@ s_alpha_pdesc (int ignore ATTRIBUTE_UNUSED)
   SKIP_WHITESPACE ();
   name_end = get_symbol_name (&name);
 
-  if (strncmp (name, "stack", 5) == 0)
+  if (startswith (name, "stack"))
     alpha_evax_proc->pdsckind = PDSC_S_K_KIND_FP_STACK;
 
-  else if (strncmp (name, "reg", 3) == 0)
+  else if (startswith (name, "reg"))
     alpha_evax_proc->pdsckind = PDSC_S_K_KIND_FP_REGISTER;
 
-  else if (strncmp (name, "null", 4) == 0)
+  else if (startswith (name, "null"))
     alpha_evax_proc->pdsckind = PDSC_S_K_KIND_NULL;
 
   else
diff --git a/gas/config/tc-arc.c b/gas/config/tc-arc.c
index 8432c0c294e..3cd33dace48 100644
--- a/gas/config/tc-arc.c
+++ b/gas/config/tc-arc.c
@@ -4723,17 +4723,17 @@ tokenize_extregister (extRegister_t *ereg, int opertype)
       input_line_pointer++;
       mode = input_line_pointer;
 
-      if (!strncmp (mode, "r|w", 3))
+      if (startswith (mode, "r|w"))
 	{
 	  imode = 0;
 	  input_line_pointer += 3;
 	}
-      else if (!strncmp (mode, "r", 1))
+      else if (startswith (mode, "r"))
 	{
 	  imode = ARC_REGISTER_READONLY;
 	  input_line_pointer += 1;
 	}
-      else if (strncmp (mode, "w", 1))
+      else if (!startswith (mode, "w"))
 	{
 	  as_bad (_("invalid mode"));
 	  ignore_rest_of_line ();
@@ -4761,12 +4761,12 @@ tokenize_extregister (extRegister_t *ereg, int opertype)
 
       input_line_pointer++;
 
-      if (!strncmp (input_line_pointer, "cannot_shortcut", 15))
+      if (startswith (input_line_pointer, "cannot_shortcut"))
 	{
 	  imode |= ARC_REGISTER_NOSHORT_CUT;
 	  input_line_pointer += 15;
 	}
-      else if (strncmp (input_line_pointer, "can_shortcut", 12))
+      else if (!startswith (input_line_pointer, "can_shortcut"))
 	{
 	  as_bad (_("shortcut designator invalid"));
 	  ignore_rest_of_line ();
diff --git a/gas/config/tc-arm.c b/gas/config/tc-arm.c
index ed5e9d92ae4..4888c089217 100644
--- a/gas/config/tc-arm.c
+++ b/gas/config/tc-arm.c
@@ -2624,7 +2624,7 @@ create_register_alias (char * newname, char *p)
   /* The input scrubber ensures that whitespace after the mnemonic is
      collapsed to single spaces.  */
   oldname = p;
-  if (strncmp (oldname, " .req ", 6) != 0)
+  if (!startswith (oldname, " .req "))
     return false;
 
   oldname += 6;
@@ -2715,9 +2715,9 @@ create_neon_reg_alias (char *newname, char *p)
 
   nameend = p;
 
-  if (strncmp (p, " .dn ", 5) == 0)
+  if (startswith (p, " .dn "))
     basetype = REG_TYPE_VFD;
-  else if (strncmp (p, " .qn ", 5) == 0)
+  else if (startswith (p, " .qn "))
     basetype = REG_TYPE_NQ;
   else
     return false;
@@ -5401,7 +5401,7 @@ parse_ifimm_zero (char **in)
     ++*in;
 
   /* Accept #0x0 as a synonym for #0.  */
-  if (strncmp (*in, "0x", 2) == 0)
+  if (startswith (*in, "0x"))
     {
       int val;
       if (parse_immediate (in, &val, 0, 0, true) == FAIL)
@@ -5445,7 +5445,7 @@ parse_qfloat_immediate (char **ccp, int *immed)
   fpnum = str;
   skip_whitespace (fpnum);
 
-  if (strncmp (fpnum, "0x", 2) == 0)
+  if (startswith (fpnum, "0x"))
     return FAIL;
   else
     {
@@ -23727,7 +23727,7 @@ arm_frob_label (symbolS * sym)
 bool
 arm_data_in_code (void)
 {
-  if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
+  if (thumb_mode && startswith (input_line_pointer + 1, "data:"))
     {
       *input_line_pointer = '/';
       input_line_pointer += 5;
@@ -27418,7 +27418,7 @@ arm_elf_change_section (void)
 int
 arm_elf_section_type (const char * str, size_t len)
 {
-  if (len == 5 && strncmp (str, "exidx", 5) == 0)
+  if (len == 5 && startswith (str, "exidx"))
     return SHT_ARM_EXIDX;
 
   return -1;
@@ -27588,8 +27588,7 @@ start_unwind_section (const segT text_seg, int idx)
   if (streq (text_name, ".text"))
     text_name = "";
 
-  if (strncmp (text_name, ".gnu.linkonce.t.",
-	       strlen (".gnu.linkonce.t.")) == 0)
+  if (startswith (text_name, ".gnu.linkonce.t."))
     {
       prefix = prefix_once;
       text_name += strlen (".gnu.linkonce.t.");
@@ -32213,7 +32212,7 @@ arm_parse_extension (const char *str, const arm_feature_set *opt_set,
       else
 	len = strlen (str);
 
-      if (len >= 2 && strncmp (str, "no", 2) == 0)
+      if (len >= 2 && startswith (str, "no"))
 	{
 	  if (adding_value != 0)
 	    {
@@ -33007,7 +33006,7 @@ aeabi_set_public_attributes (void)
       char *q;
 
       q = selected_cpu_name;
-      if (strncmp (q, "armv", 4) == 0)
+      if (startswith (q, "armv"))
 	{
 	  int i;
 
@@ -33300,7 +33299,7 @@ s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
   *input_line_pointer = 0;
 
   if (strlen (name) >= 2
-      && strncmp (name, "no", 2) == 0)
+      && startswith (name, "no"))
     {
       adding_value = 0;
       name += 2;
diff --git a/gas/config/tc-avr.c b/gas/config/tc-avr.c
index 7d6bfdea038..397f22d5502 100644
--- a/gas/config/tc-avr.c
+++ b/gas/config/tc-avr.c
@@ -942,10 +942,10 @@ avr_ldi_expression (expressionS *exp)
 
 	      ++str;
 
-	      if (strncmp ("pm(", str, 3) == 0
-                  || strncmp ("gs(",str,3) == 0
-                  || strncmp ("-(gs(",str,5) == 0
-		  || strncmp ("-(pm(", str, 5) == 0)
+	      if (startswith (str, "pm(")
+                  || startswith (str, "gs(")
+                  || startswith (str, "-(gs(")
+		  || startswith (str, "-(pm("))
 		{
 		  if (HAVE_PM_P (mod))
 		    {
diff --git a/gas/config/tc-csky.c b/gas/config/tc-csky.c
index 3069b40b774..35a7252786c 100644
--- a/gas/config/tc-csky.c
+++ b/gas/config/tc-csky.c
@@ -2781,8 +2781,8 @@ is_freglist_legal (char **oper)
   reg2 = reg2 - reg1;
   /* The fldm/fstm in CSKY_ISA_FLOAT_7E60 has 5 bits frz(reg1).  */
   shift = 4;
-  if (strncmp (csky_insn.opcode->mnemonic, "fstm", 4) == 0
-      || strncmp (csky_insn.opcode->mnemonic, "fldm", 4) == 0)
+  if (startswith (csky_insn.opcode->mnemonic, "fstm")
+      || startswith (csky_insn.opcode->mnemonic, "fldm"))
     {
       if ((!(isa_flag & CSKY_ISA_FLOAT_7E60)
 	   && (reg2 > (int)15 || reg1 > 15))
@@ -7758,7 +7758,7 @@ csky_s_section (int ignore)
   while (*ilp != 0 && ISSPACE (*ilp))
     ++ ilp;
 
-  if (strncmp (ilp, ".line", 5) == 0
+  if (startswith (ilp, ".line")
       && (ISSPACE (ilp[5]) || *ilp == '\n' || *ilp == '\r'))
     ;
   else
diff --git a/gas/config/tc-d30v.c b/gas/config/tc-d30v.c
index 23b0b2a5beb..1fb078662fa 100644
--- a/gas/config/tc-d30v.c
+++ b/gas/config/tc-d30v.c
@@ -1339,7 +1339,7 @@ do_assemble (char *str,
     opcode->ecc = ECC_AL;
 
   /* CMP and CMPU change their name based on condition codes.  */
-  if (!strncmp (name, "cmp", 3))
+  if (startswith (name, "cmp"))
     {
       int p, i;
       char **d30v_str = (char **) d30v_cc_names;
diff --git a/gas/config/tc-dlx.c b/gas/config/tc-dlx.c
index 56f576d562d..a8aa2d1bc90 100644
--- a/gas/config/tc-dlx.c
+++ b/gas/config/tc-dlx.c
@@ -592,14 +592,14 @@ parse_operand (char *s, expressionS *operandp)
   the_insn.HI = the_insn.LO = 0;
 
   /* Search for %hi and %lo, make a mark and skip it.  */
-  if (strncmp (s, "%hi", 3) == 0)
+  if (startswith (s, "%hi"))
     {
       s += 3;
       the_insn.HI = 1;
     }
   else
     {
-      if (strncmp (s, "%lo", 3) == 0)
+      if (startswith (s, "%lo"))
 	{
 	  s += 3;
 	  the_insn.LO = 1;
diff --git a/gas/config/tc-epiphany.c b/gas/config/tc-epiphany.c
index d253bc2d49e..eb7a3944d90 100644
--- a/gas/config/tc-epiphany.c
+++ b/gas/config/tc-epiphany.c
@@ -529,13 +529,13 @@ md_assemble (char *str)
   int regmask=0, push=0, pop=0;
 
   /* Special-case push/pop instruction macros.  */
-  if (0 == strncmp (str, "push {", 6))
+  if (startswith (str, "push {"))
     {
       char * s = str + 6;
       push = 1;
       pperr = parse_reglist (s, &regmask);
     }
-  else if (0 == strncmp (str, "pop {", 5))
+  else if (startswith (str, "pop {"))
     {
       char * s = str + 5;
       pop = 1;
diff --git a/gas/config/tc-h8300.c b/gas/config/tc-h8300.c
index b75b9433fde..e1f359aec01 100644
--- a/gas/config/tc-h8300.c
+++ b/gas/config/tc-h8300.c
@@ -167,8 +167,7 @@ h8300_elf_section (int push)
 
       if (i < 0)
 	for (i = ARRAY_SIZE (known_data_prefixes); i--;)
-	  if (strncmp (name, known_data_prefixes[i],
-		       strlen (known_data_prefixes[i])) == 0)
+	  if (startswith (name, known_data_prefixes[i]))
 	    break;
 
       if (i < 0)
@@ -872,10 +871,10 @@ get_operand (char **ptr, struct h8_op *op, int direction)
       *ptr = parse_exp (src + 1, op);
       return;
     }
-  else if (strncmp (src, "mach", 4) == 0 ||
-	   strncmp (src, "macl", 4) == 0 ||
-	   strncmp (src, "MACH", 4) == 0 ||
-	   strncmp (src, "MACL", 4) == 0)
+  else if (startswith (src, "mach") ||
+	   startswith (src, "macl") ||
+	   startswith (src, "MACH") ||
+	   startswith (src, "MACL"))
     {
       op->reg = TOLOWER (src[3]) == 'l';
       op->mode = MACREG;
diff --git a/gas/config/tc-hppa.c b/gas/config/tc-hppa.c
index b90d62221bf..e82c0636ff1 100644
--- a/gas/config/tc-hppa.c
+++ b/gas/config/tc-hppa.c
@@ -3553,7 +3553,7 @@ pa_ip (char *str)
 		/* Handle load cache hint completer.  */
 		case 'c':
 		  cmpltr = 0;
-		  if (!strncmp (s, ",sl", 3))
+		  if (startswith (s, ",sl"))
 		    {
 		      s += 3;
 		      cmpltr = 2;
@@ -3563,12 +3563,12 @@ pa_ip (char *str)
 		/* Handle store cache hint completer.  */
 		case 'C':
 		  cmpltr = 0;
-		  if (!strncmp (s, ",sl", 3))
+		  if (startswith (s, ",sl"))
 		    {
 		      s += 3;
 		      cmpltr = 2;
 		    }
-		  else if (!strncmp (s, ",bc", 3))
+		  else if (startswith (s, ",bc"))
 		    {
 		      s += 3;
 		      cmpltr = 1;
@@ -3578,7 +3578,7 @@ pa_ip (char *str)
 		/* Handle load and clear cache hint completer.  */
 		case 'd':
 		  cmpltr = 0;
-		  if (!strncmp (s, ",co", 3))
+		  if (startswith (s, ",co"))
 		    {
 		      s += 3;
 		      cmpltr = 1;
@@ -3587,7 +3587,7 @@ pa_ip (char *str)
 
 		/* Handle load ordering completer.  */
 		case 'o':
-		  if (strncmp (s, ",o", 2) != 0)
+		  if (!startswith (s, ",o"))
 		    break;
 		  s += 2;
 		  continue;
@@ -4098,12 +4098,12 @@ pa_ip (char *str)
 			else if (*s == '*')
 			  break;
 
-			if (strncmp (s, "<", 1) == 0)
+			if (startswith (s, "<"))
 			  {
 			    cmpltr = 0;
 			    s++;
 			  }
-			else if (strncmp (s, ">=", 2) == 0)
+			else if (startswith (s, ">="))
 			  {
 			    cmpltr = 1;
 			    s += 2;
@@ -6813,25 +6813,25 @@ pa_level (int unused ATTRIBUTE_UNUSED)
   char *level;
 
   level = input_line_pointer;
-  if (strncmp (level, "1.0", 3) == 0)
+  if (startswith (level, "1.0"))
     {
       input_line_pointer += 3;
       if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 10))
 	as_warn (_("could not set architecture and machine"));
     }
-  else if (strncmp (level, "1.1", 3) == 0)
+  else if (startswith (level, "1.1"))
     {
       input_line_pointer += 3;
       if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 11))
 	as_warn (_("could not set architecture and machine"));
     }
-  else if (strncmp (level, "2.0w", 4) == 0)
+  else if (startswith (level, "2.0w"))
     {
       input_line_pointer += 4;
       if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 25))
 	as_warn (_("could not set architecture and machine"));
     }
-  else if (strncmp (level, "2.0", 3) == 0)
+  else if (startswith (level, "2.0"))
     {
       input_line_pointer += 3;
       if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 20))
@@ -7202,7 +7202,7 @@ pa_space (int unused ATTRIBUTE_UNUSED)
 	 and place them into a subroutine or something similar?  */
       /* FIXME Is this (and the next IF stmt) really right?
 	 What if INPUT_LINE_POINTER points to "$TEXT$FOO"?  */
-      if (strncmp (input_line_pointer, "$TEXT$", 6) == 0)
+      if (startswith (input_line_pointer, "$TEXT$"))
 	{
 	  input_line_pointer += 6;
 	  sd_chain = is_defined_space ("$TEXT$");
@@ -7219,7 +7219,7 @@ pa_space (int unused ATTRIBUTE_UNUSED)
 	  demand_empty_rest_of_line ();
 	  return;
 	}
-      if (strncmp (input_line_pointer, "$PRIVATE$", 9) == 0)
+      if (startswith (input_line_pointer, "$PRIVATE$"))
 	{
 	  input_line_pointer += 9;
 	  sd_chain = is_defined_space ("$PRIVATE$");
diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index 8937ddfce1e..235bac075dd 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -3009,7 +3009,7 @@ i386_arch (void)
 unsigned long
 i386_mach (void)
 {
-  if (!strncmp (default_arch, "x86_64", 6))
+  if (startswith (default_arch, "x86_64"))
     {
       if (cpu_arch_isa == PROCESSOR_L1OM)
 	{
@@ -4730,10 +4730,10 @@ md_assemble (char *line)
       && i.operands > 1
       && (strcmp (mnemonic, "bound") != 0)
       && (strncmp (mnemonic, "invlpg", 6) != 0)
-      && (strncmp (mnemonic, "monitor", 7) != 0)
-      && (strncmp (mnemonic, "mwait", 5) != 0)
+      && !startswith (mnemonic, "monitor")
+      && !startswith (mnemonic, "mwait")
       && (strcmp (mnemonic, "pvalidate") != 0)
-      && (strncmp (mnemonic, "rmp", 3) != 0)
+      && !startswith (mnemonic, "rmp")
       && (strcmp (mnemonic, "tpause") != 0)
       && (strcmp (mnemonic, "umwait") != 0)
       && !(operand_type_check (i.types[0], imm)
@@ -10416,7 +10416,7 @@ check_VecOperations (char *op_string, char *op_end)
 	  op_string++;
 
 	  /* Check broadcasts.  */
-	  if (strncmp (op_string, "1to", 3) == 0)
+	  if (startswith (op_string, "1to"))
 	    {
 	      unsigned int bcst_type;
 
@@ -13754,7 +13754,7 @@ md_show_usage (FILE *stream)
 const char *
 i386_target_format (void)
 {
-  if (!strncmp (default_arch, "x86_64", 6))
+  if (startswith (default_arch, "x86_64"))
     {
       update_code_flag (CODE_64BIT, 1);
       if (default_arch[6] == '\0')
@@ -14322,7 +14322,7 @@ i386_elf_section_type (const char *str, size_t len)
 {
   if (flag_code == CODE_64BIT
       && len == sizeof ("unwind") - 1
-      && strncmp (str, "unwind", 6) == 0)
+      && startswith (str, "unwind"))
     return SHT_X86_64_UNWIND;
 
   return -1;
diff --git a/gas/config/tc-ia64.c b/gas/config/tc-ia64.c
index 2da73b0b99b..c1008c2b0bd 100644
--- a/gas/config/tc-ia64.c
+++ b/gas/config/tc-ia64.c
@@ -3560,7 +3560,7 @@ start_unwind_section (const segT text_seg, int sec_index)
 
   sec_text_name = segment_name (text_seg);
   text_name = sec_text_name;
-  if (strncmp (text_name, "_info", 5) == 0)
+  if (startswith (text_name, "_info"))
     {
       as_bad (_("Illegal section name `%s' (causes unwind section name clash)"),
 	      text_name);
@@ -3573,8 +3573,7 @@ start_unwind_section (const segT text_seg, int sec_index)
   /* Build the unwind section name by appending the (possibly stripped)
      text section name to the unwind prefix.  */
   suffix = text_name;
-  if (strncmp (text_name, ".gnu.linkonce.t.",
-	       sizeof (".gnu.linkonce.t.") - 1) == 0)
+  if (startswith (text_name, ".gnu.linkonce.t."))
     {
       prefix = special_linkonce_name [sec_index - SPECIAL_SECTION_UNWIND];
       suffix += sizeof (".gnu.linkonce.t.") - 1;
@@ -7004,7 +7003,7 @@ md_parse_option (int c, const char *arg)
 	  md.flags |= EF_IA_64_BE;
 	  default_big_endian = 1;
 	}
-      else if (strncmp (arg, "unwind-check=", 13) == 0)
+      else if (startswith (arg, "unwind-check="))
 	{
 	  arg += 13;
 	  if (strcmp (arg, "warning") == 0)
@@ -7014,7 +7013,7 @@ md_parse_option (int c, const char *arg)
 	  else
 	    return 0;
 	}
-      else if (strncmp (arg, "hint.b=", 7) == 0)
+      else if (startswith (arg, "hint.b="))
 	{
 	  arg += 7;
 	  if (strcmp (arg, "ok") == 0)
@@ -7026,7 +7025,7 @@ md_parse_option (int c, const char *arg)
 	  else
 	    return 0;
 	}
-      else if (strncmp (arg, "tune=", 5) == 0)
+      else if (startswith (arg, "tune="))
 	{
 	  arg += 5;
 	  if (strcmp (arg, "itanium1") == 0)
@@ -7074,7 +7073,7 @@ md_parse_option (int c, const char *arg)
 			exit:	branch out from the current context (default)
 			labels:	all labels in context may be branch targets
        */
-      if (strncmp (arg, "indirect=", 9) != 0)
+      if (!startswith (arg, "indirect="))
         return 0;
       break;
 
@@ -8106,7 +8105,7 @@ static int
 is_taken_branch (struct ia64_opcode *idesc)
 {
   return ((is_conditional_branch (idesc) && CURR_SLOT.qp_regno == 0)
-	  || strncmp (idesc->name, "br.ia", 5) == 0);
+	  || startswith (idesc->name, "br.ia"));
 }
 
 /* Return whether the given opcode is an interruption or rfi.  If there's any
@@ -9498,7 +9497,7 @@ dep->name, idesc->name, (rsrc_write?"write":"read"), note)
       /* FIXME we can identify some individual RSE written resources, but RSE
 	 read resources have not yet been completely identified, so for now
 	 treat RSE as a single resource */
-      if (strncmp (idesc->name, "mov", 3) == 0)
+      if (startswith (idesc->name, "mov"))
 	{
 	  if (rsrc_write)
 	    {
@@ -9864,8 +9863,8 @@ note_register_values (struct ia64_opcode *idesc)
     }
   /* After a call, all register values are undefined, except those marked
      as "safe".  */
-  else if (strncmp (idesc->name, "br.call", 6) == 0
-	   || strncmp (idesc->name, "brl.call", 7) == 0)
+  else if (startswith (idesc->name, "br.call")
+	   || startswith (idesc->name, "brl.call"))
     {
       /* FIXME keep GR values which are marked as "safe_across_calls"  */
       clear_register_values ();
@@ -11843,7 +11842,7 @@ do_alias (void **slot, void *arg ATTRIBUTE_UNUSED)
       /* Uses .alias extensively to alias CRTL functions to same with
 	 decc$ prefix. Sometimes function gets optimized away and a
 	 warning results, which should be suppressed.  */
-      if (strncmp (tuple->key, "decc$", 5) != 0)
+      if (!startswith (tuple->key, "decc$"))
 #endif
 	as_warn_where (h->file, h->line,
 		       _("symbol `%s' aliased to `%s' is not used"),
diff --git a/gas/config/tc-m32c.c b/gas/config/tc-m32c.c
index 370817e55e0..830886a183e 100644
--- a/gas/config/tc-m32c.c
+++ b/gas/config/tc-m32c.c
@@ -519,8 +519,8 @@ insn_to_subtype (int inum, const CGEN_INSN *insn)
   unsigned int i;
 
   if (insn
-      && (strncmp (insn->base->mnemonic, "adjnz", 5) == 0
-	  || strncmp (insn->base->mnemonic, "sbjnz", 5) == 0))
+      && (startswith (insn->base->mnemonic, "adjnz")
+	  || startswith (insn->base->mnemonic, "sbjnz")))
     {
       i = 23 + insn->base->bitsize/8 - 3;
       /*printf("mapping %d used for %s\n", i, insn->base->mnemonic);*/
diff --git a/gas/config/tc-m68hc11.c b/gas/config/tc-m68hc11.c
index c60e736f36b..b31f5cade67 100644
--- a/gas/config/tc-m68hc11.c
+++ b/gas/config/tc-m68hc11.c
@@ -1177,19 +1177,19 @@ get_operand (operand *oper, int which, long opmode)
 
       mode = M6811_OP_IMM16;
       p++;
-      if (strncmp (p, "%hi", 3) == 0)
+      if (startswith (p, "%hi"))
 	{
 	  p += 3;
 	  mode |= M6811_OP_HIGH_ADDR;
 	}
-      else if (strncmp (p, "%lo", 3) == 0)
+      else if (startswith (p, "%lo"))
 	{
 	  p += 3;
 	  mode |= M6811_OP_LOW_ADDR;
 	}
       /* %page modifier is used to obtain only the page number
          of the address of a function.  */
-      else if (strncmp (p, "%page", 5) == 0)
+      else if (startswith (p, "%page"))
 	{
 	  p += 5;
 	  mode |= M6811_OP_PAGE_ADDR;
@@ -1200,7 +1200,7 @@ get_operand (operand *oper, int which, long opmode)
          mapped in the 16K window at 0x8000 and the value will be
          within that window (although the function address may not fit
          in 16-bit).  See bfd/elf32-m68hc12.c for the translation.  */
-      else if (strncmp (p, "%addr", 5) == 0)
+      else if (startswith (p, "%addr"))
 	{
 	  p += 5;
 	  mode |= M6811_OP_CALL_ADDR;
@@ -1238,7 +1238,7 @@ get_operand (operand *oper, int which, long opmode)
       return -1;
     }
   /* Handle 68HC12 page specification in 'call foo,%page(bar)'.  */
-  else if ((opmode & M6812_OP_PAGE) && strncmp (p, "%page", 5) == 0)
+  else if ((opmode & M6812_OP_PAGE) && startswith (p, "%page"))
     {
       p += 5;
       mode = M6811_OP_PAGE_ADDR | M6812_OP_PAGE | M6811_OP_IND16;
@@ -2873,7 +2873,7 @@ md_assemble (char *str)
         }
 
       /* Special handling of TFR. */
-      if (strncmp (opc->opcode->name, "tfr",3) == 0)
+      if (startswith (opc->opcode->name, "tfr"))
         {
           /* There must be two operands with a comma. */
           input_line_pointer = skip_whites (input_line_pointer);
@@ -2995,7 +2995,7 @@ md_assemble (char *str)
 	}
 
       /* Special handling of SIF. */
-      if (strncmp (opc->opcode->name, "sif",3) == 0)
+      if (startswith (opc->opcode->name, "sif"))
         {
           /* Either OP_NONE or OP_RS. */
           if (*input_line_pointer != '\n')
@@ -3040,13 +3040,13 @@ md_assemble (char *str)
                   opcode = find (opc, operands, 1);
                   if (opcode)
 		    {
-                      if ((strncmp (opc->opcode->name, "com",3) == 0)
-                          || (strncmp (opc->opcode->name, "neg",3) == 0))
+                      if ((startswith (opc->opcode->name, "com"))
+                          || (startswith (opc->opcode->name, "neg")))
                         /* Special case for com RD as alias for sub RD,R0,RS */
                         /* Special case for neg RD as alias for sub RD,R0,RS */
                         opcode_local.opcode = opcode->opcode
                           | (operands[0].reg1 << 8) | (operands[0].reg1 << 2);
-		      else if (strncmp (opc->opcode->name, "tst",3) == 0)
+		      else if (startswith (opc->opcode->name, "tst"))
                         /* Special case for tst RS alias for sub R0, RS, R0 */
                         opcode_local.opcode = opcode->opcode
                           | (operands[0].reg1 << 5);
@@ -3128,12 +3128,12 @@ md_assemble (char *str)
             {
               input_line_pointer++;
               input_line_pointer = skip_whites (input_line_pointer);
-              if (strncmp (input_line_pointer, "%hi", 3) == 0)
+              if (startswith (input_line_pointer, "%hi"))
                 {
                   input_line_pointer += 3;
                   operands[0].mode = M6811_OP_HIGH_ADDR;
                 }
-              else if (strncmp (input_line_pointer, "%lo", 3) == 0)
+              else if (startswith (input_line_pointer, "%lo"))
                 {
 		  input_line_pointer += 3;
 		  operands[0].mode = M6811_OP_LOW_ADDR;
@@ -3216,9 +3216,9 @@ md_assemble (char *str)
                   opcode = find (opc, operands, 1);
                   if (opcode)
                     {
-                      if ((strncmp (opc->opcode->name, "com",3) == 0)
-			  || (strncmp (opc->opcode->name, "mov",3) == 0)
-			  || (strncmp (opc->opcode->name, "neg",3) == 0))
+                      if ((startswith (opc->opcode->name, "com"))
+			  || (startswith (opc->opcode->name, "mov"))
+			  || (startswith (opc->opcode->name, "neg")))
                         {
                           /* Special cases for:
                              com RD, RS alias for xnor RD,R0,RS
@@ -3227,8 +3227,8 @@ md_assemble (char *str)
                           opcode_local.opcode = opcode->opcode
                             | (operands[0].reg1 << 8) | (operands[1].reg1 << 2);
                         }
-                      else if ((strncmp (opc->opcode->name, "cmp",3) == 0)
-			       || (strncmp (opc->opcode->name, "cpc",3) == 0))
+                      else if ((startswith (opc->opcode->name, "cmp"))
+			       || (startswith (opc->opcode->name, "cpc")))
                         {
                           /* special cases for:
                              cmp RS1, RS2 alias for sub R0, RS1, RS2
diff --git a/gas/config/tc-m68k.c b/gas/config/tc-m68k.c
index 4d3987de19b..f503b24a7ed 100644
--- a/gas/config/tc-m68k.c
+++ b/gas/config/tc-m68k.c
@@ -1839,7 +1839,7 @@ m68k_ip (char *instring)
 		case 'B':	/* FOO */
 		  if (opP->mode != ABSL
 		      || (flag_long_jumps
-			  && strncmp (instring, "jbsr", 4) == 0))
+			  && startswith (instring, "jbsr")))
 		    losing++;
 		  break;
 
@@ -2039,8 +2039,8 @@ m68k_ip (char *instring)
 			   || TRUNC (opP->disp.exp.X_add_number) - 1 > 7)
 		    losing++;
 		  else if (! m68k_quick
-			   && (strncmp (instring, "add", 3) == 0
-			       || strncmp (instring, "sub", 3) == 0)
+			   && (startswith (instring, "add")
+			       || startswith (instring, "sub"))
 			   && instring[3] != 'q')
 		    losing++;
 		  break;
@@ -7482,9 +7482,9 @@ md_parse_option (int c, const char *arg)
 #endif
       /* Intentional fall-through.  */
     case 'm':
-      if (!strncmp (arg, "arch=", 5))
+      if (startswith (arg, "arch="))
 	m68k_set_arch (arg + 5, 1, 0);
-      else if (!strncmp (arg, "cpu=", 4))
+      else if (startswith (arg, "cpu="))
 	m68k_set_cpu (arg + 4, 1, 0);
       else if (m68k_set_extension (arg, 0, 1))
 	;
@@ -7861,7 +7861,7 @@ m68k_elf_suffix (char **str_p, expressionS *exp_p)
   *str2 = '\0';
   len = str2 - ident;
 
-  if (strncmp (ident, "TLSLDO", 6) == 0
+  if (startswith (ident, "TLSLDO")
       && len == 6)
     {
       /* Now check for identifier@suffix+constant.  */
diff --git a/gas/config/tc-mcore.c b/gas/config/tc-mcore.c
index d81e0be5b2b..443253f3964 100644
--- a/gas/config/tc-mcore.c
+++ b/gas/config/tc-mcore.c
@@ -361,7 +361,7 @@ mcore_s_section (int ignore)
   while (*ilp != 0 && ISSPACE (*ilp))
     ++ ilp;
 
-  if (strncmp (ilp, ".line", 5) == 0
+  if (startswith (ilp, ".line")
       && (ISSPACE (ilp[5]) || *ilp == '\n' || *ilp == '\r'))
     ;
   else
diff --git a/gas/config/tc-metag.c b/gas/config/tc-metag.c
index 961c11f3b0d..554d4330d33 100644
--- a/gas/config/tc-metag.c
+++ b/gas/config/tc-metag.c
@@ -1003,7 +1003,7 @@ parse_get_set (const char *line, metag_insn *insn,
 
   if (is_get)
     {
-      bool is_mov = strncmp (template->name, "MOV", 3) == 0;
+      bool is_mov = startswith (template->name, "MOV");
 
       l = parse_get (l, regs, &addr, size, is_mov);
 
@@ -5925,8 +5925,7 @@ md_parse_option (int c, const char * arg)
       /* These options are expected to have an argument.  */
       if (c == lopt->option[0]
 	  && arg != NULL
-	  && strncmp (arg, lopt->option + 1,
-		      strlen (lopt->option + 1)) == 0)
+	  && startswith (arg, lopt->option + 1))
 	{
 #if WARN_DEPRECATED
 	      /* If the option is deprecated, tell the user.  */
diff --git a/gas/config/tc-microblaze.c b/gas/config/tc-microblaze.c
index fcac519ca69..9893bc47cfd 100644
--- a/gas/config/tc-microblaze.c
+++ b/gas/config/tc-microblaze.c
@@ -740,7 +740,7 @@ parse_imm (char * s, expressionS * e, offsetT min, offsetT max)
 
   new_pointer = parse_exp (s, e);
 
-  if (!GOT_symbol && ! strncmp (s, GOT_SYMBOL_NAME, 20))
+  if (!GOT_symbol && startswith (s, GOT_SYMBOL_NAME))
     {
       GOT_symbol = symbol_find_or_make (GOT_SYMBOL_NAME);
     }
@@ -785,17 +785,17 @@ check_got (int * got_type, int * got_len)
     if (is_end_of_line[(unsigned char) *atp])
       return NULL;
 
-  if (strncmp (atp + 1, "GOTOFF", 5) == 0)
+  if (startswith (atp + 1, "GOTOFF"))
     {
       *got_len = 6;
       *got_type = IMM_GOTOFF;
     }
-  else if (strncmp (atp + 1, "GOT", 3) == 0)
+  else if (startswith (atp + 1, "GOT"))
     {
       *got_len = 3;
       *got_type = IMM_GOT;
     }
-  else if (strncmp (atp + 1, "PLT", 3) == 0)
+  else if (startswith (atp + 1, "PLT"))
     {
       *got_len = 3;
       *got_type = IMM_PLT;
@@ -2025,9 +2025,8 @@ md_apply_fix (fixS *   fixP,
 	  || (symbol_used_in_reloc_p (fixP->fx_addsy)
 	      && (((bfd_section_flags (S_GET_SEGMENT (fixP->fx_addsy))
 		    & SEC_LINK_ONCE) != 0)
-		  || !strncmp (segment_name (S_GET_SEGMENT (fixP->fx_addsy)),
-			       ".gnu.linkonce",
-			       sizeof (".gnu.linkonce") - 1))))
+		  || startswith (segment_name (S_GET_SEGMENT (fixP->fx_addsy)),
+				 ".gnu.linkonce"))))
 	{
 	  val -= S_GET_VALUE (fixP->fx_addsy);
 	  if (val != 0 && ! fixP->fx_pcrel)
diff --git a/gas/config/tc-mips.c b/gas/config/tc-mips.c
index 8d8cf996396..9151b222a48 100644
--- a/gas/config/tc-mips.c
+++ b/gas/config/tc-mips.c
@@ -513,8 +513,8 @@ static int mips_32bitmode = 0;
 
 /* Return true if the given CPU supports the MIPS16 ASE.  */
 #define CPU_HAS_MIPS16(cpu)						\
-   (strncmp (TARGET_CPU, "mips16", sizeof ("mips16") - 1) == 0		\
-    || strncmp (TARGET_CANONICAL, "mips-lsi-elf", sizeof ("mips-lsi-elf") - 1) == 0)
+   (startswith (TARGET_CPU, "mips16")					\
+    || startswith (TARGET_CANONICAL, "mips-lsi-elf"))
 
 /* Return true if the given CPU supports the microMIPS ASE.  */
 #define CPU_HAS_MICROMIPS(cpu)	0
@@ -3842,8 +3842,8 @@ md_begin (void)
   /* On a native system other than VxWorks, sections must be aligned
      to 16 byte boundaries.  When configured for an embedded ELF
      target, we don't bother.  */
-  if (strncmp (TARGET_OS, "elf", 3) != 0
-      && strncmp (TARGET_OS, "vxworks", 7) != 0)
+  if (!startswith (TARGET_OS, "elf")
+      && !startswith (TARGET_OS, "vxworks"))
     {
       bfd_set_section_alignment (text_section, 4);
       bfd_set_section_alignment (data_section, 4);
@@ -3865,7 +3865,7 @@ md_begin (void)
        running program can access it.  However, we don't load it
        if we are configured for an embedded target.  */
     flags = SEC_READONLY | SEC_DATA;
-    if (strncmp (TARGET_OS, "elf", 3) != 0)
+    if (!startswith (TARGET_OS, "elf"))
       flags |= SEC_ALLOC | SEC_LOAD;
 
     if (mips_abi != N64_ABI)
@@ -4457,8 +4457,7 @@ s_is_linkonce (symbolS *sym, segT from_seg)
       /* The GNU toolchain uses an extension for ELF: a section
 	 beginning with the magic string .gnu.linkonce is a
 	 linkonce section.  */
-      if (strncmp (segment_name (symseg), ".gnu.linkonce",
-		   sizeof ".gnu.linkonce" - 1) == 0)
+      if (startswith (segment_name (symseg), ".gnu.linkonce"))
 	linkonce = true;
     }
   return linkonce;
@@ -5114,12 +5113,12 @@ check_regno (struct mips_arg_info *arg,
       length = strlen (name);
       if ((regno & 1) != 0
 	  && ((length >= 3 && strcmp (name + length - 3, ".ps") == 0)
-	      || (length >= 5 && strncmp (name + length - 5, "any2", 4) == 0)))
+	      || (length >= 5 && startswith (name + length - 5, "any2"))))
 	as_warn (_("condition code register should be even for %s, was %d"),
 		 name, regno);
 
       if ((regno & 3) != 0
-	  && (length >= 5 && strncmp (name + length - 5, "any4", 4) == 0))
+	  && (length >= 5 && startswith (name + length - 5, "any4")))
 	as_warn (_("condition code register should be 0 or 4 for %s, was %d"),
 		 name, regno);
     }
@@ -6166,7 +6165,7 @@ match_float_constant (struct mips_arg_info *arg, expressionS *imm,
   bfd_set_section_flags (new_seg,
 			 SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA);
   frag_align (length == 4 ? 2 : 3, 0, 0);
-  if (strncmp (TARGET_OS, "elf", 3) != 0)
+  if (!startswith (TARGET_OS, "elf"))
     record_alignment (new_seg, 4);
   else
     record_alignment (new_seg, length == 4 ? 2 : 3);
@@ -6348,13 +6347,13 @@ reg_needs_delay (unsigned int reg)
 static unsigned int
 classify_vr4120_insn (const char *name)
 {
-  if (strncmp (name, "macc", 4) == 0)
+  if (startswith (name, "macc"))
     return FIX_VR4120_MACC;
-  if (strncmp (name, "dmacc", 5) == 0)
+  if (startswith (name, "dmacc"))
     return FIX_VR4120_DMACC;
-  if (strncmp (name, "mult", 4) == 0)
+  if (startswith (name, "mult"))
     return FIX_VR4120_MULT;
-  if (strncmp (name, "dmult", 5) == 0)
+  if (startswith (name, "dmult"))
     return FIX_VR4120_DMULT;
   if (strstr (name, "div"))
     return FIX_VR4120_DIV;
@@ -8294,7 +8293,7 @@ match_insn (struct mips_cl_insn *insn, const struct mips_opcode *opcode,
 	    return true;
 	  clear_insn_error ();
 	  if (arg.dest_regno == arg.last_regno
-	      && strncmp (insn->insn_mo->name, "jalr", 4) == 0)
+	      && startswith (insn->insn_mo->name, "jalr"))
 	    {
 	      if (arg.opnum == 2)
 		set_insn_error
@@ -8304,8 +8303,8 @@ match_insn (struct mips_cl_insn *insn, const struct mips_opcode *opcode,
 		  (0, _("a destination register must be supplied"));
 	    }
 	  else if (arg.last_regno == 31
-		   && (strncmp (insn->insn_mo->name, "bltzal", 6) == 0
-		       || strncmp (insn->insn_mo->name, "bgezal", 6) == 0))
+		   && (startswith (insn->insn_mo->name, "bltzal")
+		       || startswith (insn->insn_mo->name, "bgezal")))
 	    set_insn_error (0, _("the source register must not be $31"));
 	  check_completed_insn (&arg);
 	  return true;
@@ -15250,7 +15249,7 @@ mips_after_parse_args (void)
   const struct mips_cpu_info *tune_info = 0;
 
   /* GP relative stuff not working for PE.  */
-  if (strncmp (TARGET_OS, "pe", 2) == 0)
+  if (startswith (TARGET_OS, "pe"))
     {
       if (g_switch_seen && g_switch_value != 0)
 	as_bad (_("-G not supported in this configuration"));
@@ -16339,7 +16338,7 @@ s_change_sec (int sec)
 			(subsegT) get_absolute_expression ());
       bfd_set_section_flags (seg, (SEC_ALLOC | SEC_LOAD | SEC_READONLY
 				   | SEC_RELOC | SEC_DATA));
-      if (strncmp (TARGET_OS, "elf", 3) != 0)
+      if (!startswith (TARGET_OS, "elf"))
 	record_alignment (seg, 4);
       demand_empty_rest_of_line ();
       break;
@@ -16348,7 +16347,7 @@ s_change_sec (int sec)
       seg = subseg_new (".sdata", (subsegT) get_absolute_expression ());
       bfd_set_section_flags (seg, (SEC_ALLOC | SEC_LOAD | SEC_RELOC
 				   | SEC_DATA | SEC_SMALL_DATA));
-      if (strncmp (TARGET_OS, "elf", 3) != 0)
+      if (!startswith (TARGET_OS, "elf"))
 	record_alignment (seg, 4);
       demand_empty_rest_of_line ();
       break;
@@ -16356,7 +16355,7 @@ s_change_sec (int sec)
     case 'B':
       seg = subseg_new (".sbss", (subsegT) get_absolute_expression ());
       bfd_set_section_flags (seg, SEC_ALLOC | SEC_SMALL_DATA);
-      if (strncmp (TARGET_OS, "elf", 3) != 0)
+      if (!startswith (TARGET_OS, "elf"))
 	record_alignment (seg, 4);
       demand_empty_rest_of_line ();
       break;
@@ -16565,7 +16564,7 @@ s_option (int x ATTRIBUTE_UNUSED)
     {
       /* FIXME: What does this mean?  */
     }
-  else if (strncmp (opt, "pic", 3) == 0 && ISDIGIT (opt[3]) && opt[4] == '\0')
+  else if (startswith (opt, "pic") && ISDIGIT (opt[3]) && opt[4] == '\0')
     {
       int i;
 
@@ -16630,7 +16629,7 @@ parse_code_option (char * name)
   bool isa_set = false;
   const struct mips_ase *ase;
 
-  if (strncmp (name, "at=", 3) == 0)
+  if (startswith (name, "at="))
     {
       char *s = name + 3;
 
@@ -16687,11 +16686,11 @@ parse_code_option (char * name)
     mips_set_ase (ase, &mips_opts, false);
   else if ((ase = mips_lookup_ase (name)))
     mips_set_ase (ase, &mips_opts, true);
-  else if (strncmp (name, "mips", 4) == 0 || strncmp (name, "arch=", 5) == 0)
+  else if (startswith (name, "mips") || startswith (name, "arch="))
     {
       /* Permit the user to change the ISA and architecture on the fly.
 	 Needless to say, misuse can cause serious problems.  */
-      if (strncmp (name, "arch=", 5) == 0)
+      if (startswith (name, "arch="))
 	{
 	  const struct mips_cpu_info *p;
 
@@ -16706,7 +16705,7 @@ parse_code_option (char * name)
 	      mips_opts.init_ase = p->ase;
 	    }
 	}
-      else if (strncmp (name, "mips", 4) == 0)
+      else if (startswith (name, "mips"))
 	{
 	  const struct mips_cpu_info *p;
 
@@ -17626,7 +17625,7 @@ md_section_align (asection *seg, valueT addr)
      However, Irix 5 may prefer that we align them at least to a 16
      byte boundary.  We don't bother to align the sections if we
      are targeted for an embedded system.  */
-  if (strncmp (TARGET_OS, "elf", 3) == 0)
+  if (startswith (TARGET_OS, "elf"))
     return addr;
   if (align > 4)
     align = 4;
@@ -17694,10 +17693,10 @@ nopic_need_relax (symbolS *sym, int before_relaxing)
 		  && strcmp (segname, ".lit4") != 0);
 	  change = (strcmp (segname, ".sdata") != 0
 		    && strcmp (segname, ".sbss") != 0
-		    && strncmp (segname, ".sdata.", 7) != 0
-		    && strncmp (segname, ".sbss.", 6) != 0
-		    && strncmp (segname, ".gnu.linkonce.sb.", 17) != 0
-		    && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
+		    && !startswith (segname, ".sdata.")
+		    && !startswith (segname, ".sbss.")
+		    && !startswith (segname, ".gnu.linkonce.sb.")
+		    && !startswith (segname, ".gnu.linkonce.s."));
 	}
       return change;
     }
diff --git a/gas/config/tc-mmix.c b/gas/config/tc-mmix.c
index 495fc5a9889..d51a0198619 100644
--- a/gas/config/tc-mmix.c
+++ b/gas/config/tc-mmix.c
@@ -3171,7 +3171,7 @@ mmix_handle_mmixal (void)
     }
   else if (s[0] == 'G'
 	   && s[1] == 'R'
-	   && strncmp (s, "GREG", 4) == 0
+	   && startswith (s, "GREG")
 	   && (ISSPACE (s[4]) || is_end_of_line[(unsigned char) s[4]]))
     {
       input_line_pointer = s + 4;
diff --git a/gas/config/tc-mn10300.c b/gas/config/tc-mn10300.c
index 37f6733b275..f180e940364 100644
--- a/gas/config/tc-mn10300.c
+++ b/gas/config/tc-mn10300.c
@@ -2427,7 +2427,7 @@ mn10300_fix_adjustable (struct fix *fixp)
   if (! (S_GET_SEGMENT (fixp->fx_addsy)->flags & SEC_MERGE))
     return false;
 
-  if (strncmp (S_GET_SEGMENT (fixp->fx_addsy)->name, ".debug", 6) == 0)
+  if (startswith (S_GET_SEGMENT (fixp->fx_addsy)->name, ".debug"))
     return false;
 
   return true;
@@ -2447,7 +2447,7 @@ mn10300_end_of_match (char *cont, const char *what)
 {
   int len = strlen (what);
 
-  if (strncmp (cont, what, strlen (what)) == 0
+  if (startswith (cont, what)
       && ! is_part_of_name (cont[len]))
     return cont + len;
 
diff --git a/gas/config/tc-msp430.c b/gas/config/tc-msp430.c
index d834c00cd0a..7649ab33cc8 100644
--- a/gas/config/tc-msp430.c
+++ b/gas/config/tc-msp430.c
@@ -1504,16 +1504,16 @@ md_parse_option (int c, const char * arg)
 static void
 msp430_make_init_symbols (const char * name)
 {
-  if (strncmp (name, ".bss", 4) == 0
-      || strncmp (name, ".lower.bss", 10) == 0
-      || strncmp (name, ".either.bss", 11) == 0
-      || strncmp (name, ".gnu.linkonce.b.", 16) == 0)
+  if (startswith (name, ".bss")
+      || startswith (name, ".lower.bss")
+      || startswith (name, ".either.bss")
+      || startswith (name, ".gnu.linkonce.b."))
     (void) symbol_find_or_make ("__crt0_init_bss");
 
-  if (strncmp (name, ".data", 5) == 0
-      || strncmp (name, ".lower.data", 11) == 0
-      || strncmp (name, ".either.data", 12) == 0
-      || strncmp (name, ".gnu.linkonce.d.", 16) == 0)
+  if (startswith (name, ".data")
+      || startswith (name, ".lower.data")
+      || startswith (name, ".either.data")
+      || startswith (name, ".gnu.linkonce.d."))
     (void) symbol_find_or_make ("__crt0_movedata");
   /* Note - data assigned to the .either.data section may end up being
      placed in the .upper.data section if the .lower.data section is
@@ -1521,14 +1521,14 @@ msp430_make_init_symbols (const char * name)
      The linker may create upper or either data sections, even when none exist
      at the moment, so use the value of the data-region flag to determine if
      the symbol is needed.  */
-  if (strncmp (name, ".either.data", 12) == 0
-      || strncmp (name, ".upper.data", 11) == 0
+  if (startswith (name, ".either.data")
+      || startswith (name, ".upper.data")
       || upper_data_region_in_use)
     (void) symbol_find_or_make ("__crt0_move_highdata");
 
   /* See note about .either.data above.  */
-  if (strncmp (name, ".upper.bss", 10) == 0
-      || strncmp (name, ".either.bss", 11) == 0
+  if (startswith (name, ".upper.bss")
+      || startswith (name, ".either.bss")
       || upper_data_region_in_use)
     (void) symbol_find_or_make ("__crt0_init_highbss");
 
@@ -1542,17 +1542,17 @@ msp430_make_init_symbols (const char * name)
      exit() or returning from main.
      __crt0_run_array is required to actually call the functions in the above
      arrays.  */
-  if (strncmp (name, ".init_array", 11) == 0)
+  if (startswith (name, ".init_array"))
     {
       (void) symbol_find_or_make ("__crt0_run_init_array");
       (void) symbol_find_or_make ("__crt0_run_array");
     }
-  else if (strncmp (name, ".preinit_array", 14) == 0)
+  else if (startswith (name, ".preinit_array"))
     {
       (void) symbol_find_or_make ("__crt0_run_preinit_array");
       (void) symbol_find_or_make ("__crt0_run_array");
     }
-  else if (strncmp (name, ".fini_array", 11) == 0)
+  else if (startswith (name, ".fini_array"))
     {
       (void) symbol_find_or_make ("__crt0_run_fini_array");
       (void) symbol_find_or_make ("__crt0_run_array");
diff --git a/gas/config/tc-nds32.c b/gas/config/tc-nds32.c
index 29ef3dfa7f9..e5c0eaf0866 100644
--- a/gas/config/tc-nds32.c
+++ b/gas/config/tc-nds32.c
@@ -3712,7 +3712,7 @@ nds32_parse_option (int c, const char *arg)
 	  int disable = 0;
 
 	  /* Filter out the Disable option first.  */
-	  if (strncmp (arg, "no-", 3) == 0)
+	  if (startswith (arg, "no-"))
 	    {
 	      disable = 1;
 	      arg += 3;
diff --git a/gas/config/tc-nds32.h b/gas/config/tc-nds32.h
index fb4bcacf12c..da7e38c0094 100644
--- a/gas/config/tc-nds32.h
+++ b/gas/config/tc-nds32.h
@@ -158,7 +158,7 @@ extern void nds32_do_align (int);
 #define md_do_align(N, FILL, LEN, MAX, LABEL)	\
   nds32_pre_do_align (N, FILL, LEN, MAX);	\
   if ((N) > 1 && (subseg_text_p (now_seg)	\
-      || strncmp (now_seg->name, ".gcc_except_table", sizeof(".gcc_except_table") - 1) == 0)) \
+      || startswith (now_seg->name, ".gcc_except_table"))) \
     nds32_do_align (N);				\
   goto LABEL;
 #define md_elf_section_change_hook()		nds32_elf_section_change_hook ()
diff --git a/gas/config/tc-nios2.c b/gas/config/tc-nios2.c
index 7e2a3985c29..7eb0649cba3 100644
--- a/gas/config/tc-nios2.c
+++ b/gas/config/tc-nios2.c
@@ -300,29 +300,24 @@ md_atof (int type, char *litP, int *sizeP)
   return NULL;
 }
 
-/* Return true if STR starts with PREFIX, which should be a string literal.  */
-#define strprefix(STR, PREFIX) \
-  (strncmp ((STR), PREFIX, strlen (PREFIX)) == 0)
-
-
 /* Return true if STR is prefixed with a special relocation operator.  */
 static int
 nios2_special_relocation_p (const char *str)
 {
-  return (strprefix (str, "%lo")
-	  || strprefix (str, "%hi")
-	  || strprefix (str, "%hiadj")
-	  || strprefix (str, "%gprel")
-	  || strprefix (str, "%got")
-	  || strprefix (str, "%call")
-	  || strprefix (str, "%gotoff_lo")
-	  || strprefix (str, "%gotoff_hiadj")
-	  || strprefix (str, "%tls_gd")
-	  || strprefix (str, "%tls_ldm")
-	  || strprefix (str, "%tls_ldo")
-	  || strprefix (str, "%tls_ie")
-	  || strprefix (str, "%tls_le")
-	  || strprefix (str, "%gotoff"));
+  return (startswith (str, "%lo")
+	  || startswith (str, "%hi")
+	  || startswith (str, "%hiadj")
+	  || startswith (str, "%gprel")
+	  || startswith (str, "%got")
+	  || startswith (str, "%call")
+	  || startswith (str, "%gotoff_lo")
+	  || startswith (str, "%gotoff_hiadj")
+	  || startswith (str, "%tls_gd")
+	  || startswith (str, "%tls_ldm")
+	  || startswith (str, "%tls_ldo")
+	  || startswith (str, "%tls_ie")
+	  || startswith (str, "%tls_le")
+	  || startswith (str, "%gotoff"));
 }
 
 
@@ -1678,7 +1673,7 @@ nios2_parse_base_register (char *str, int *direction, int *writeback, int *ret)
   *ret = 0;
 
   /* Check for --.  */
-  if (strncmp (str, "--", 2) == 0)
+  if (startswith (str, "--"))
     {
       str += 2;
       *direction -= 1;
@@ -1705,7 +1700,7 @@ nios2_parse_base_register (char *str, int *direction, int *writeback, int *ret)
     return NULL;
 
   /* Check for ++.  */
-  if (strncmp (str, "++", 2) == 0)
+  if (startswith (str, "++"))
     {
       str += 2;
       *direction += 1;
@@ -1723,12 +1718,12 @@ nios2_parse_base_register (char *str, int *direction, int *writeback, int *ret)
     {
       while (*str == ' ')
 	str++;
-      if (strncmp (str, "writeback", 9) == 0)
+      if (startswith (str, "writeback"))
 	{
 	  *writeback = 1;
 	  str += 9;
 	}
-      else if (strncmp (str, "ret", 3) == 0)
+      else if (startswith (str, "ret"))
 	{
 	  *ret = 1;
 	  str += 3;
@@ -3987,7 +3982,7 @@ nios2_cons (expressionS *exp, int size)
   SKIP_WHITESPACE ();
   if (input_line_pointer[0] == '%')
     {
-      if (strprefix (input_line_pointer + 1, "tls_ldo"))
+      if (startswith (input_line_pointer + 1, "tls_ldo"))
 	{
 	  reloc_name = "%tls_ldo";
 	  if (size != 4)
@@ -3999,7 +3994,7 @@ nios2_cons (expressionS *exp, int size)
 	      explicit_reloc = BFD_RELOC_NIOS2_TLS_DTPREL;
 	    }
 	}
-      else if (strprefix (input_line_pointer + 1, "gotoff"))
+      else if (startswith (input_line_pointer + 1, "gotoff"))
 	{
 	  reloc_name = "%gotoff";
 	  if (size != 4)
diff --git a/gas/config/tc-ns32k.c b/gas/config/tc-ns32k.c
index 04d840e2eaf..98fa520b9ba 100644
--- a/gas/config/tc-ns32k.c
+++ b/gas/config/tc-ns32k.c
@@ -442,7 +442,7 @@ addr_mode (char *operand,
     case 'e':
       if (str[strl - 1] != ']')
 	{
-	  if ((!strncmp (str, "ext(", 4)) && strl > 7)
+	  if ((startswith (str, "ext(")) && strl > 7)
 	    {				/* external */
 	      addrmodeP->disp[0] = str + 4;
 	      i = 0;
@@ -496,7 +496,7 @@ addr_mode (char *operand,
       /* Fall through.  */
 
     case 3:
-      if (!strncmp (str, "tos", 3))
+      if (startswith (str, "tos"))
 	{
 	  addrmodeP->mode = 23;	/* TopOfStack */
 	  return -1;
@@ -513,11 +513,11 @@ addr_mode (char *operand,
 	{
 	  if (str[strl - 2] == ')')
 	    {
-	      if (!strncmp (&str[strl - 5], "(fp", 3))
+	      if (startswith (&str[strl - 5], "(fp"))
 		mode = 16;		/* Memory Relative.  */
-	      else if (!strncmp (&str[strl - 5], "(sp", 3))
+	      else if (startswith (&str[strl - 5], "(sp"))
 		mode = 17;
-	      else if (!strncmp (&str[strl - 5], "(sb", 3))
+	      else if (startswith (&str[strl - 5], "(sb"))
 		mode = 18;
 
 	      if (mode != DEFAULT)
@@ -568,13 +568,13 @@ addr_mode (char *operand,
 	      /* Fall through.  */
 
 	    default:
-	      if (!strncmp (&str[strl - 4], "(fp", 3))
+	      if (startswith (&str[strl - 4], "(fp"))
 		mode = 24;
-	      else if (!strncmp (&str[strl - 4], "(sp", 3))
+	      else if (startswith (&str[strl - 4], "(sp"))
 		mode = 25;
-	      else if (!strncmp (&str[strl - 4], "(sb", 3))
+	      else if (startswith (&str[strl - 4], "(sb"))
 		mode = 26;
-	      else if (!strncmp (&str[strl - 4], "(pc", 3))
+	      else if (startswith (&str[strl - 4], "(pc"))
 		mode = 27;
 
 	      if (mode != DEFAULT)
diff --git a/gas/config/tc-pdp11.c b/gas/config/tc-pdp11.c
index 2ce8684487a..b6d3bfeb8cb 100644
--- a/gas/config/tc-pdp11.c
+++ b/gas/config/tc-pdp11.c
@@ -100,7 +100,7 @@ set_option (const char *arg)
       return 1;
     }
 
-  if (strncmp (arg, "no-", 3) == 0)
+  if (startswith (arg, "no-"))
     {
       yes = 0;
       arg += 3;
@@ -140,9 +140,9 @@ set_option (const char *arg)
   else if (strcmp (arg, "mfpt") == 0)
     pdp11_extension[PDP11_MFPT] = yes;
   /* Multiprocessor insns:  */
-  else if (strncmp (arg, "mproc", 5) == 0
+  else if (startswith (arg, "mproc")
 	   /* TSTSET, WRTLCK */
-	   || strncmp (arg, "multiproc", 9) == 0)
+	   || startswith (arg, "multiproc"))
     pdp11_extension[PDP11_MPROC] = yes;
   /* Move from/to proc status.  */
   else if (strcmp (arg, "mxps") == 0)
@@ -352,14 +352,14 @@ parse_reg (char *str, struct pdp11_code *operand)
 	  return str - 1;
 	}
     }
-  else if (strncmp (str, "sp", 2) == 0
-	   || strncmp (str, "SP", 2) == 0)
+  else if (startswith (str, "sp")
+	   || startswith (str, "SP"))
     {
       operand->code = 6;
       str += 2;
     }
-  else if (strncmp (str, "pc", 2) == 0
-	   || strncmp (str, "PC", 2) == 0)
+  else if (startswith (str, "pc")
+	   || startswith (str, "PC"))
     {
       operand->code = 7;
       str += 2;
@@ -383,10 +383,10 @@ static char *
 parse_ac5 (char *str, struct pdp11_code *operand)
 {
   str = skip_whitespace (str);
-  if (strncmp (str, "fr", 2) == 0
-      || strncmp (str, "FR", 2) == 0
-      || strncmp (str, "ac", 2) == 0
-      || strncmp (str, "AC", 2) == 0)
+  if (startswith (str, "fr")
+      || startswith (str, "FR")
+      || startswith (str, "ac")
+      || startswith (str, "AC"))
     {
       str += 2;
       switch (*str)
@@ -519,7 +519,7 @@ parse_op_no_deferred (char *str, struct pdp11_code *operand)
       /* label, d(rn), -(rn)  */
     default:
       {
-	if (strncmp (str, "-(", 2) == 0)	/* -(rn) */
+	if (startswith (str, "-("))	/* -(rn) */
 	  {
 	    str = parse_reg (str + 2, operand);
 	    if (operand->error)
@@ -1114,7 +1114,7 @@ set_cpu_model (const char *arg)
   if (arg[0] == '-')
     arg++;
 
-  if (strncmp (arg, "11", 2) != 0)
+  if (!startswith (arg, "11"))
     return 0;
   arg += 2;
 
@@ -1135,43 +1135,43 @@ set_cpu_model (const char *arg)
   set_option ("no-extensions");
 
   /* KA11 (11/15/20).  */
-  if (strncmp (buf, "a", 1) == 0)
+  if (startswith (buf, "a"))
     return 1; /* No extensions.  */
 
   /* KB11 (11/45/50/55/70).  */
-  else if (strncmp (buf, "b", 1) == 0)
+  else if (startswith (buf, "b"))
     return set_option ("eis") && set_option ("spl");
 
   /* KD11-A (11/35/40).  */
-  else if (strncmp (buf, "da", 2) == 0)
+  else if (startswith (buf, "da"))
     return set_option ("limited-eis");
 
   /* KD11-B (11/05/10).  */
-  else if (strncmp (buf, "db", 2) == 0
+  else if (startswith (buf, "db")
 	   /* KD11-D (11/04).  */
-	   || strncmp (buf, "dd", 2) == 0)
+	   || startswith (buf, "dd"))
     return 1; /* no extensions */
 
   /* KD11-E (11/34).  */
-  else if (strncmp (buf, "de", 2) == 0)
+  else if (startswith (buf, "de"))
     return set_option ("eis") && set_option ("mxps");
 
   /* KD11-F (11/03).  */
-  else if (strncmp (buf, "df", 2) == 0
+  else if (startswith (buf, "df")
 	   /* KD11-H (11/03).  */
-	   || strncmp (buf, "dh", 2) == 0
+	   || startswith (buf, "dh")
 	   /* KD11-Q (11/03).  */
-	   || strncmp (buf, "dq", 2) == 0)
+	   || startswith (buf, "dq"))
     return set_option ("limited-eis") && set_option ("mxps");
 
   /* KD11-K (11/60).  */
-  else if (strncmp (buf, "dk", 2) == 0)
+  else if (startswith (buf, "dk"))
     return set_option ("eis")
       && set_option ("mxps")
       && set_option ("ucode");
 
   /* KD11-Z (11/44).  */
-  else if (strncmp (buf, "dz", 2) == 0)
+  else if (startswith (buf, "dz"))
     return set_option ("csm")
       && set_option ("eis")
       && set_option ("mfpt")
@@ -1179,13 +1179,13 @@ set_cpu_model (const char *arg)
       && set_option ("spl");
 
   /* F11 (11/23/24).  */
-  else if (strncmp (buf, "f", 1) == 0)
+  else if (startswith (buf, "f"))
     return set_option ("eis")
       && set_option ("mfpt")
       && set_option ("mxps");
 
   /* J11 (11/53/73/83/84/93/94).  */
-  else if (strncmp (buf, "j", 1) == 0)
+  else if (startswith (buf, "j"))
     return set_option ("csm")
       && set_option ("eis")
       && set_option ("mfpt")
@@ -1194,7 +1194,7 @@ set_cpu_model (const char *arg)
       && set_option ("spl");
 
   /* T11 (11/21).  */
-  else if (strncmp (buf, "t", 1) == 0)
+  else if (startswith (buf, "t"))
     return set_option ("limited-eis")
       && set_option ("mxps");
 
@@ -1205,16 +1205,16 @@ set_cpu_model (const char *arg)
 static int
 set_machine_model (const char *arg)
 {
-  if (strncmp (arg, "pdp-11/", 7) != 0
-      && strncmp (arg, "pdp11/", 6) != 0
-      && strncmp (arg, "11/", 3) != 0)
+  if (!startswith (arg, "pdp-11/")
+      && !startswith (arg, "pdp11/")
+      && !startswith (arg, "11/"))
     return 0;
 
-  if (strncmp (arg, "pdp", 3) == 0)
+  if (startswith (arg, "pdp"))
     arg += 3;
   if (arg[0] == '-')
     arg++;
-  if (strncmp (arg, "11/", 3) == 0)
+  if (startswith (arg, "11/"))
     arg += 3;
 
   if (strcmp (arg, "03") == 0)
diff --git a/gas/config/tc-pj.c b/gas/config/tc-pj.c
index 4127ffd4d67..72391f6ef1d 100644
--- a/gas/config/tc-pj.c
+++ b/gas/config/tc-pj.c
@@ -58,7 +58,7 @@ const char EXP_CHARS[] = "eE";
 void
 md_operand (expressionS *op)
 {
-  if (strncmp (input_line_pointer, "%hi16", 5) == 0)
+  if (startswith (input_line_pointer, "%hi16"))
     {
       if (pending_reloc)
 	as_bad (_("confusing relocation expressions"));
@@ -67,7 +67,7 @@ md_operand (expressionS *op)
       expression (op);
     }
 
-  if (strncmp (input_line_pointer, "%lo16", 5) == 0)
+  if (startswith (input_line_pointer, "%lo16"))
     {
       if (pending_reloc)
 	as_bad (_("confusing relocation expressions"));
diff --git a/gas/config/tc-ppc.c b/gas/config/tc-ppc.c
index 8d1142c9428..5511e722108 100644
--- a/gas/config/tc-ppc.c
+++ b/gas/config/tc-ppc.c
@@ -1304,7 +1304,7 @@ is_ppc64_target (const bfd_target *targ, void *data ATTRIBUTE_UNUSED)
     {
 #ifdef OBJ_ELF
     case bfd_target_elf_flavour:
-      return strncmp (targ->name, "elf64-powerpc", 13) == 0;
+      return startswith (targ->name, "elf64-powerpc");
 #endif
 #ifdef OBJ_XCOFF
     case bfd_target_xcoff_flavour:
@@ -1458,14 +1458,14 @@ ppc_set_cpu (void)
 	else
 	  /* The minimum supported cpu for 64-bit little-endian is power8.  */
 	  ppc_cpu |= ppc_parse_cpu (ppc_cpu, &sticky, "power8");
-      else if (strncmp (default_os, "aix", 3) == 0
+      else if (startswith (default_os, "aix")
 	       && default_os[3] >= '4' && default_os[3] <= '9')
 	ppc_cpu |= PPC_OPCODE_COMMON;
-      else if (strncmp (default_os, "aix3", 4) == 0)
+      else if (startswith (default_os, "aix3"))
 	ppc_cpu |= PPC_OPCODE_POWER;
       else if (strcmp (default_cpu, "rs6000") == 0)
 	ppc_cpu |= PPC_OPCODE_POWER;
-      else if (strncmp (default_cpu, "powerpc", 7) == 0)
+      else if (startswith (default_cpu, "powerpc"))
 	ppc_cpu |= PPC_OPCODE_PPC;
       else
 	as_fatal (_("unknown default cpu = %s, os = %s"),
@@ -1492,7 +1492,7 @@ ppc_arch (void)
     {
       if (strcmp (default_cpu, "rs6000") == 0)
 	return bfd_arch_rs6000;
-      else if (strncmp (default_cpu, "powerpc", 7) == 0)
+      else if (startswith (default_cpu, "powerpc"))
 	return bfd_arch_powerpc;
     }
 
@@ -4183,7 +4183,7 @@ ppc_macro (char *str, const struct powerpc_macro *macro)
 int
 ppc_section_type (char *str, size_t len)
 {
-  if (len == 7 && strncmp (str, "ordered", 7) == 0)
+  if (len == 7 && startswith (str, "ordered"))
     return SHT_ORDERED;
 
   return -1;
diff --git a/gas/config/tc-s12z.c b/gas/config/tc-s12z.c
index 71d01b97cc6..6ec4d5c63b8 100644
--- a/gas/config/tc-s12z.c
+++ b/gas/config/tc-s12z.c
@@ -2802,17 +2802,17 @@ tb_reg_rel  (const struct instruction *insn)
   if (reg == REG_Y)
     lb |= 0x01;
 
-  if (0 == strncmp (insn->name + 2, "ne", 2))
+  if (startswith (insn->name + 2, "ne"))
     lb |= 0x00 << 4;
-  else if (0 == strncmp (insn->name + 2, "eq", 2))
+  else if (startswith (insn->name + 2, "eq"))
     lb |= 0x01 << 4;
-  else if (0 == strncmp (insn->name + 2, "pl", 2))
+  else if (startswith (insn->name + 2, "pl"))
     lb |= 0x02 << 4;
-  else if (0 == strncmp (insn->name + 2, "mi", 2))
+  else if (startswith (insn->name + 2, "mi"))
     lb |= 0x03 << 4;
-  else if (0 == strncmp (insn->name + 2, "gt", 2))
+  else if (startswith (insn->name + 2, "gt"))
     lb |= 0x04 << 4;
-  else if (0 == strncmp (insn->name + 2, "le", 2))
+  else if (startswith (insn->name + 2, "le"))
     lb |= 0x05 << 4;
 
   switch (insn->name[0])
@@ -2863,17 +2863,17 @@ tb_opr_rel  (const struct instruction *insn)
 
   uint8_t lb = 0x0C;
 
-  if (0 == strncmp (insn->name + 2, "ne", 2))
+  if (startswith (insn->name + 2, "ne"))
     lb |= 0x00 << 4;
-  else if (0 == strncmp (insn->name + 2, "eq", 2))
+  else if (startswith (insn->name + 2, "eq"))
     lb |= 0x01 << 4;
-  else if (0 == strncmp (insn->name + 2, "pl", 2))
+  else if (startswith (insn->name + 2, "pl"))
     lb |= 0x02 << 4;
-  else if (0 == strncmp (insn->name + 2, "mi", 2))
+  else if (startswith (insn->name + 2, "mi"))
     lb |= 0x03 << 4;
-  else if (0 == strncmp (insn->name + 2, "gt", 2))
+  else if (startswith (insn->name + 2, "gt"))
     lb |= 0x04 << 4;
-  else if (0 == strncmp (insn->name + 2, "le", 2))
+  else if (startswith (insn->name + 2, "le"))
     lb |= 0x05 << 4;
 
   switch (insn->name[0])
diff --git a/gas/config/tc-s390.c b/gas/config/tc-s390.c
index 564418e4c1c..0750f253463 100644
--- a/gas/config/tc-s390.c
+++ b/gas/config/tc-s390.c
@@ -312,7 +312,7 @@ s390_parse_cpu (const char *arg,
   char *ilp_bak;
 
   icpu = S390_OPCODE_MAXCPU;
-  if (strncmp (arg, "all", 3) == 0 && (arg[3] == 0 || arg[3] == '+'))
+  if (startswith (arg, "all") && (arg[3] == 0 || arg[3] == '+'))
     {
       icpu = S390_OPCODE_MAXCPU - 1;
       arg += 3;
@@ -427,7 +427,7 @@ md_parse_option (int c, const char *arg)
 	  current_mode_mask = 1 << S390_OPCODE_ZARCH;
 	}
 
-      else if (arg != NULL && strncmp (arg, "arch=", 5) == 0)
+      else if (arg != NULL && startswith (arg, "arch="))
 	{
 	  current_cpu = s390_parse_cpu (arg + 5, &current_flags, false);
 	  if (current_cpu == S390_OPCODE_MAXCPU)
diff --git a/gas/config/tc-score.c b/gas/config/tc-score.c
index 7252e7ad5a4..0deb23ab86c 100644
--- a/gas/config/tc-score.c
+++ b/gas/config/tc-score.c
@@ -4832,8 +4832,8 @@ s3_nopic_need_relax (symbolS * sym, int before_relaxing)
       segname = segment_name (S_GET_SEGMENT (sym));
       return (strcmp (segname, ".sdata") != 0
 	      && strcmp (segname, ".sbss") != 0
-	      && strncmp (segname, ".sdata.", 7) != 0
-	      && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
+	      && !startswith (segname, ".sdata.")
+	      && !startswith (segname, ".gnu.linkonce.s."));
     }
   /* We are not optimizing for the $gp register.  */
   else
@@ -5313,8 +5313,7 @@ s3_pic_need_relax (symbolS *sym, asection *segtype)
       /* The GNU toolchain uses an extension for ELF: a section
 	 beginning with the magic string .gnu.linkonce is a linkonce
 	 section.  */
-      if (strncmp (segment_name (symsec), ".gnu.linkonce",
-		   sizeof ".gnu.linkonce" - 1) == 0)
+      if (startswith (segment_name (symsec), ".gnu.linkonce"))
 	linkonce = true;
     }
 
diff --git a/gas/config/tc-score7.c b/gas/config/tc-score7.c
index 01a1d73771d..2eae1929430 100644
--- a/gas/config/tc-score7.c
+++ b/gas/config/tc-score7.c
@@ -4626,8 +4626,8 @@ s7_nopic_need_relax (symbolS * sym, int before_relaxing)
       segname = segment_name (S_GET_SEGMENT (sym));
       return (strcmp (segname, ".sdata") != 0
 	      && strcmp (segname, ".sbss") != 0
-	      && strncmp (segname, ".sdata.", 7) != 0
-	      && strncmp (segname, ".gnu.linkonce.s.", 16) != 0);
+	      && !startswith (segname, ".sdata.")
+	      && !startswith (segname, ".gnu.linkonce.s."));
     }
   /* We are not optimizing for the $gp register.  */
   else
@@ -5195,8 +5195,7 @@ s7_pic_need_relax (symbolS *sym, asection *segtype)
       /* The GNU toolchain uses an extension for ELF: a section
 	  beginning with the magic string .gnu.linkonce is a linkonce
 	  section.  */
-      if (strncmp (segment_name (symsec), ".gnu.linkonce",
-		   sizeof ".gnu.linkonce" - 1) == 0)
+      if (startswith (segment_name (symsec), ".gnu.linkonce"))
 	linkonce = true;
     }
 
diff --git a/gas/config/tc-sh.h b/gas/config/tc-sh.h
index de36987b2f1..41cc2fa2c2d 100644
--- a/gas/config/tc-sh.h
+++ b/gas/config/tc-sh.h
@@ -140,9 +140,9 @@ extern void sh_frob_file (void);
 
 /* We align most sections to a 16 byte boundary.  */
 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN)			\
-  (strncmp (SEG_NAME (SEG), ".stabstr", 8) == 0		\
+  (startswith (SEG_NAME (SEG), ".stabstr")		\
    ? 0							\
-   : ((strncmp (SEG_NAME (SEG), ".stab", 5) == 0	\
+   : ((startswith (SEG_NAME (SEG), ".stab")	\
        || strcmp (SEG_NAME (SEG), ".ctors") == 0	\
        || strcmp (SEG_NAME (SEG), ".dtors") == 0)	\
       ? 2						\
diff --git a/gas/config/tc-sparc.c b/gas/config/tc-sparc.c
index 61cd27d7239..b8723819ade 100644
--- a/gas/config/tc-sparc.c
+++ b/gas/config/tc-sparc.c
@@ -460,13 +460,13 @@ md_parse_option (int c, const char *arg)
       break;
 
     case OPTION_XARCH:
-      if (!strncmp (arg, "v9", 2))
+      if (startswith (arg, "v9"))
 	md_parse_option (OPTION_64, NULL);
       else
 	{
-	  if (!strncmp (arg, "v8", 2)
-	      || !strncmp (arg, "v7", 2)
-	      || !strncmp (arg, "v6", 2)
+	  if (startswith (arg, "v8")
+	      || startswith (arg, "v7")
+	      || startswith (arg, "v6")
 	      || !strcmp (arg, "sparclet")
 	      || !strcmp (arg, "sparclite")
 	      || !strcmp (arg, "sparc86x"))
@@ -1984,7 +1984,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 
 	    case 'M':
 	    case 'm':
-	      if (strncmp (s, "%asr", 4) == 0)
+	      if (startswith (s, "%asr"))
 		{
 		  s += 4;
 
@@ -2131,8 +2131,8 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 		{
 		  ++s;
 		}
-	      if ((strncmp (s, "%icc", 4) == 0)
-                  || (sparc_arch_size == 32 && strncmp (s, "%ncc", 4) == 0))
+	      if ((startswith (s, "%icc"))
+                  || (sparc_arch_size == 32 && startswith (s, "%ncc")))
 		{
 		  s += 4;
 		  continue;
@@ -2144,8 +2144,8 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 		{
 		  ++s;
 		}
-              if ((strncmp (s, "%xcc", 4) == 0)
-                  || (sparc_arch_size == 64 && strncmp (s, "%ncc", 4) == 0))
+              if ((startswith (s, "%xcc"))
+                  || (sparc_arch_size == 64 && startswith (s, "%ncc")))
 		{
 		  s += 4;
 		  continue;
@@ -2157,7 +2157,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 		{
 		  ++s;
 		}
-	      if (strncmp (s, "%fcc0", 5) == 0)
+	      if (startswith (s, "%fcc0"))
 		{
 		  s += 5;
 		  continue;
@@ -2169,7 +2169,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 		{
 		  ++s;
 		}
-	      if (strncmp (s, "%fcc1", 5) == 0)
+	      if (startswith (s, "%fcc1"))
 		{
 		  s += 5;
 		  continue;
@@ -2181,7 +2181,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 		{
 		  ++s;
 		}
-	      if (strncmp (s, "%fcc2", 5) == 0)
+	      if (startswith (s, "%fcc2"))
 		{
 		  s += 5;
 		  continue;
@@ -2193,7 +2193,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 		{
 		  ++s;
 		}
-	      if (strncmp (s, "%fcc3", 5) == 0)
+	      if (startswith (s, "%fcc3"))
 		{
 		  s += 5;
 		  continue;
@@ -2201,7 +2201,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 	      break;
 
 	    case 'P':
-	      if (strncmp (s, "%pc", 3) == 0)
+	      if (startswith (s, "%pc"))
 		{
 		  s += 3;
 		  continue;
@@ -2209,7 +2209,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 	      break;
 
 	    case 'W':
-	      if (strncmp (s, "%tick", 5) == 0)
+	      if (startswith (s, "%tick"))
 		{
 		  s += 5;
 		  continue;
@@ -2316,7 +2316,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 	      break;
 
 	    case 'C':		/* Coprocessor state register.  */
-	      if (strncmp (s, "%csr", 4) == 0)
+	      if (startswith (s, "%csr"))
 		{
 		  s += 4;
 		  continue;
@@ -2635,7 +2635,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 	      }			/* float arg  */
 
 	    case 'F':
-	      if (strncmp (s, "%fsr", 4) == 0)
+	      if (startswith (s, "%fsr"))
 		{
 		  s += 4;
 		  continue;
@@ -2643,7 +2643,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 	      break;
 
 	    case '(':
-	      if (strncmp (s, "%efsr", 5) == 0)
+	      if (startswith (s, "%efsr"))
 		{
 		  s += 5;
 		  continue;
@@ -2980,7 +2980,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 	      }			/* Alternate space.  */
 
 	    case 'p':
-	      if (strncmp (s, "%psr", 4) == 0)
+	      if (startswith (s, "%psr"))
 		{
 		  s += 4;
 		  continue;
@@ -2988,7 +2988,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 	      break;
 
 	    case 'q':		/* Floating point queue.  */
-	      if (strncmp (s, "%fq", 3) == 0)
+	      if (startswith (s, "%fq"))
 		{
 		  s += 3;
 		  continue;
@@ -2996,7 +2996,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 	      break;
 
 	    case 'Q':		/* Coprocessor queue.  */
-	      if (strncmp (s, "%cq", 3) == 0)
+	      if (startswith (s, "%cq"))
 		{
 		  s += 3;
 		  continue;
@@ -3020,7 +3020,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 		  special_case = SPECIAL_CASE_SETX;
 		  continue;
 		}
-	      else if (strncmp (str, "fdiv", 4) == 0)
+	      else if (startswith (str, "fdiv"))
 		{
 		  special_case = SPECIAL_CASE_FDIV;
 		  continue;
@@ -3028,43 +3028,43 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 	      break;
 
 	    case 'o':
-	      if (strncmp (s, "%asi", 4) != 0)
+	      if (!startswith (s, "%asi"))
 		break;
 	      s += 4;
 	      continue;
 
 	    case 's':
-	      if (strncmp (s, "%fprs", 5) != 0)
+	      if (!startswith (s, "%fprs"))
 		break;
 	      s += 5;
 	      continue;
 
 	    case '{':
-	      if (strncmp (s, "%mcdper",7) != 0)
+	      if (!startswith (s, "%mcdper"))
 		break;
 	      s += 7;
 	      continue;
 
             case '&':
-              if (strncmp (s, "%entropy", 8) != 0)
+              if (!startswith (s, "%entropy"))
                 break;
               s += 8;
               continue;
 
 	    case 'E':
-	      if (strncmp (s, "%ccr", 4) != 0)
+	      if (!startswith (s, "%ccr"))
 		break;
 	      s += 4;
 	      continue;
 
 	    case 't':
-	      if (strncmp (s, "%tbr", 4) != 0)
+	      if (!startswith (s, "%tbr"))
 		break;
 	      s += 4;
 	      continue;
 
 	    case 'w':
-	      if (strncmp (s, "%wim", 4) != 0)
+	      if (!startswith (s, "%wim"))
 		break;
 	      s += 4;
 	      continue;
@@ -3112,7 +3112,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 	      }
 
 	    case 'y':
-	      if (strncmp (s, "%y", 2) != 0)
+	      if (!startswith (s, "%y"))
 		break;
 	      s += 2;
 	      continue;
@@ -4138,8 +4138,8 @@ s_reserve (int ignore ATTRIBUTE_UNUSED)
   symbolP = symbol_find_or_make (name);
   *p = c;
 
-  if (strncmp (input_line_pointer, ",\"bss\"", 6) != 0
-      && strncmp (input_line_pointer, ",\".bss\"", 7) != 0)
+  if (!startswith (input_line_pointer, ",\"bss\"")
+      && !startswith (input_line_pointer, ",\".bss\""))
     {
       as_bad (_("bad .reserve segment -- expected BSS segment"));
       return;
@@ -4352,8 +4352,8 @@ s_common (int ignore ATTRIBUTE_UNUSED)
       if (*input_line_pointer == '.')
 	input_line_pointer++;
       /* @@ Some say data, some say bss.  */
-      if (strncmp (input_line_pointer, "bss\"", 4)
-	  && strncmp (input_line_pointer, "data\"", 5))
+      if (!startswith (input_line_pointer, "bss\"")
+	  && !startswith (input_line_pointer, "data\""))
 	{
 	  while (*--input_line_pointer != '"')
 	    ;
@@ -4400,25 +4400,25 @@ static void
 s_seg (int ignore ATTRIBUTE_UNUSED)
 {
 
-  if (strncmp (input_line_pointer, "\"text\"", 6) == 0)
+  if (startswith (input_line_pointer, "\"text\""))
     {
       input_line_pointer += 6;
       s_text (0);
       return;
     }
-  if (strncmp (input_line_pointer, "\"data\"", 6) == 0)
+  if (startswith (input_line_pointer, "\"data\""))
     {
       input_line_pointer += 6;
       s_data (0);
       return;
     }
-  if (strncmp (input_line_pointer, "\"data1\"", 7) == 0)
+  if (startswith (input_line_pointer, "\"data1\""))
     {
       input_line_pointer += 7;
       s_data1 ();
       return;
     }
-  if (strncmp (input_line_pointer, "\"bss\"", 5) == 0)
+  if (startswith (input_line_pointer, "\"bss\""))
     {
       input_line_pointer += 5;
       /* We only support 2 segments -- text and data -- for now, so
@@ -4728,12 +4728,12 @@ sparc_cons (expressionS *exp, int size)
       && input_line_pointer[1] == 'r'
       && input_line_pointer[2] == '_')
     {
-      if (strncmp (input_line_pointer + 3, "disp", 4) == 0)
+      if (startswith (input_line_pointer + 3, "disp"))
 	{
 	  input_line_pointer += 7;
 	  sparc_cons_special_reloc = "disp";
 	}
-      else if (strncmp (input_line_pointer + 3, "plt", 3) == 0)
+      else if (startswith (input_line_pointer + 3, "plt"))
 	{
 	  if (size != 4 && size != 8)
 	    as_bad (_("Illegal operands: %%r_plt in %d-byte data field"), size);
@@ -4743,7 +4743,7 @@ sparc_cons (expressionS *exp, int size)
 	      sparc_cons_special_reloc = "plt";
 	    }
 	}
-      else if (strncmp (input_line_pointer + 3, "tls_dtpoff", 10) == 0)
+      else if (startswith (input_line_pointer + 3, "tls_dtpoff"))
 	{
 	  if (size != 4 && size != 8)
 	    as_bad (_("Illegal operands: %%r_tls_dtpoff in %d-byte data field"), size);
diff --git a/gas/config/tc-tic54x.c b/gas/config/tc-tic54x.c
index f41cc0534a1..f0ac732b11e 100644
--- a/gas/config/tc-tic54x.c
+++ b/gas/config/tc-tic54x.c
@@ -609,7 +609,7 @@ stag_add_field (struct stag *parent,
       sf->next = sfield;
     }
   /* Only create a symbol for this field if the parent has no name.  */
-  if (!strncmp (".fake", parent->name, 5))
+  if (startswith (parent->name, ".fake"))
     {
       symbolS *sym = symbol_new (name, absolute_section, &zero_address_frag,
 				 offset);
@@ -705,7 +705,7 @@ tic54x_endstruct (int is_union)
 {
   int size;
   const char *path =
-    !strncmp (current_stag->name, ".fake", 5) ? "" : current_stag->name;
+    startswith (current_stag->name, ".fake") ? "" : current_stag->name;
 
   if (!current_stag || current_stag->is_union != is_union)
     {
diff --git a/gas/config/tc-tic6x.c b/gas/config/tc-tic6x.c
index bd72137383c..ff1e37de2af 100644
--- a/gas/config/tc-tic6x.c
+++ b/gas/config/tc-tic6x.c
@@ -4626,8 +4626,7 @@ tic6x_start_unwind_section (const segT text_seg, int idx)
   if (streq (text_name, ".text"))
     text_name = "";
 
-  if (strncmp (text_name, ".gnu.linkonce.t.",
-	       strlen (".gnu.linkonce.t.")) == 0)
+  if (startswith (text_name, ".gnu.linkonce.t."))
     {
       prefix = prefix_once;
       text_name += strlen (".gnu.linkonce.t.");
diff --git a/gas/config/tc-v850.c b/gas/config/tc-v850.c
index 496fd9b1232..5bfebba5643 100644
--- a/gas/config/tc-v850.c
+++ b/gas/config/tc-v850.c
@@ -481,8 +481,8 @@ v850_comm (int area)
 	input_line_pointer++;
 
       /* @@ Some say data, some say bss.  */
-      if (strncmp (input_line_pointer, "bss\"", 4)
-	  && strncmp (input_line_pointer, "data\"", 5))
+      if (!startswith (input_line_pointer, "bss\"")
+	  && !startswith (input_line_pointer, "data\""))
 	{
 	  while (*--input_line_pointer != '"')
 	    ;
@@ -1888,7 +1888,7 @@ md_begin (void)
   const char *prev_name = "";
   const struct v850_opcode *op;
 
-  if (strncmp (TARGET_CPU, "v850e3v5", 8) == 0)
+  if (startswith (TARGET_CPU, "v850e3v5"))
     {
       if (machine == -1)
 	machine = bfd_mach_v850e3v5;
@@ -1896,7 +1896,7 @@ md_begin (void)
       if (!processor_mask)
 	SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850E3V5);
     }
-  else if (strncmp (TARGET_CPU, "v850e2v4", 8) == 0)
+  else if (startswith (TARGET_CPU, "v850e2v4"))
     {
       if (machine == -1)
 	machine = bfd_mach_v850e3v5;
@@ -1904,7 +1904,7 @@ md_begin (void)
       if (!processor_mask)
 	SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850E3V5);
     }
-  else if (strncmp (TARGET_CPU, "v850e2v3", 8) == 0)
+  else if (startswith (TARGET_CPU, "v850e2v3"))
     {
       if (machine == -1)
         machine = bfd_mach_v850e2v3;
@@ -1912,7 +1912,7 @@ md_begin (void)
       if (!processor_mask)
         SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850E2V3);
     }
-  else if (strncmp (TARGET_CPU, "v850e2", 6) == 0)
+  else if (startswith (TARGET_CPU, "v850e2"))
     {
       if (machine == -1)
 	machine = bfd_mach_v850e2;
@@ -1920,7 +1920,7 @@ md_begin (void)
       if (!processor_mask)
 	SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850E2);
     }
-  else if (strncmp (TARGET_CPU, "v850e1", 6) == 0)
+  else if (startswith (TARGET_CPU, "v850e1"))
     {
       if (machine == -1)
         machine = bfd_mach_v850e1;
@@ -1928,7 +1928,7 @@ md_begin (void)
       if (!processor_mask)
         SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850E1);
     }
-  else if (strncmp (TARGET_CPU, "v850e", 5) == 0)
+  else if (startswith (TARGET_CPU, "v850e"))
     {
       if (machine == -1)
 	machine = bfd_mach_v850e;
@@ -1936,7 +1936,7 @@ md_begin (void)
       if (!processor_mask)
 	SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850E);
     }
-  else if (strncmp (TARGET_CPU, "v850", 4) == 0)
+  else if (startswith (TARGET_CPU, "v850"))
     {
       if (machine == -1)
 	machine = 0;
@@ -2348,9 +2348,9 @@ md_assemble (char *str)
 
       if (no_stld23)
 	{
-	  if ((strncmp (opcode->name, "st.", 3) == 0
+	  if ((startswith (opcode->name, "st.")
 	       && v850_operands[opcode->operands[1]].bits == 23)
-	      || (strncmp (opcode->name, "ld.", 3) == 0
+	      || (startswith (opcode->name, "ld.")
 		  && v850_operands[opcode->operands[0]].bits == 23))
 	    {
 	      errmsg = _("st/ld offset 23 instruction was disabled .");
@@ -2949,8 +2949,8 @@ md_assemble (char *str)
                      value does not fit into the bits available then create a
                      fake error so that the next ld/st instruction will be
                      selected.  */
-                  if ( (  (strncmp (opcode->name, "st.", 3) == 0)
-		       || (strncmp (opcode->name, "ld.", 3) == 0))
+                  if ( (  (startswith (opcode->name, "st."))
+		       || (startswith (opcode->name, "ld.")))
                       && ex.X_op == O_constant
                       && (ex.X_add_number < (-(1 << (operand->bits - 1)))
 			  || ex.X_add_number > ((1 << (operand->bits - 1)) - 1)))
diff --git a/gas/config/tc-vax.c b/gas/config/tc-vax.c
index 70ea305fe10..f439f1b52dc 100644
--- a/gas/config/tc-vax.c
+++ b/gas/config/tc-vax.c
@@ -3279,7 +3279,7 @@ vax_cons (expressionS *exp, int size)
   save = input_line_pointer;
   if (input_line_pointer[0] == '%')
     {
-      if (strncmp (input_line_pointer + 1, "pcrel", 5) == 0)
+      if (startswith (input_line_pointer + 1, "pcrel"))
 	{
 	  input_line_pointer += 6;
 	  vax_cons_special_reloc = "pcrel";
diff --git a/gas/config/tc-wasm32.c b/gas/config/tc-wasm32.c
index 6e17b0b115b..00290d7c3ad 100644
--- a/gas/config/tc-wasm32.c
+++ b/gas/config/tc-wasm32.c
@@ -381,20 +381,20 @@ wasm32_leb128 (char **line, int bits, int sign)
       reloc->u.a.addend = 0;
     }
   /* i32.const fpointer@gotcode */
-  if (strncmp (input_line_pointer, "@gotcode", 8) == 0)
+  if (startswith (input_line_pointer, "@gotcode"))
     {
       gotrel = 1;
       code = 1;
       input_line_pointer += 8;
     }
   /* i32.const data@got */
-  else if (strncmp (input_line_pointer, "@got", 4) == 0)
+  else if (startswith (input_line_pointer, "@got"))
     {
       gotrel = 1;
       input_line_pointer += 4;
     }
   /* call f@plt{__sigchar_FiiiiE} */
-  else if (strncmp (input_line_pointer, "@plt", 4) == 0)
+  else if (startswith (input_line_pointer, "@plt"))
     {
       char *end_of_sig;
 
@@ -402,7 +402,7 @@ wasm32_leb128 (char **line, int bits, int sign)
       code = 1;
       input_line_pointer += 4;
 
-      if (strncmp (input_line_pointer, "{", 1) == 0
+      if (startswith (input_line_pointer, "{")
           && (end_of_sig = strchr (input_line_pointer, '}')))
 	{
 	  char *signature;
diff --git a/gas/config/tc-xstormy16.c b/gas/config/tc-xstormy16.c
index 487e981e6a8..3edf384350a 100644
--- a/gas/config/tc-xstormy16.c
+++ b/gas/config/tc-xstormy16.c
@@ -136,7 +136,7 @@ md_operand (expressionS * e)
   if (*input_line_pointer != '@')
     return;
 
-  if (strncmp (input_line_pointer + 1, "fptr", 4) == 0)
+  if (startswith (input_line_pointer + 1, "fptr"))
     {
       input_line_pointer += 5;
       SKIP_WHITESPACE ();
diff --git a/gas/config/tc-xtensa.c b/gas/config/tc-xtensa.c
index 978704e5c84..452d4a757e9 100644
--- a/gas/config/tc-xtensa.c
+++ b/gas/config/tc-xtensa.c
@@ -1293,7 +1293,7 @@ get_directive (directiveE *directive, bool *negated)
   unsigned i;
   const char *directive_string;
 
-  if (strncmp (input_line_pointer, "no-", 3) != 0)
+  if (!startswith (input_line_pointer, "no-"))
     *negated = false;
   else
     {
@@ -1308,12 +1308,12 @@ get_directive (directiveE *directive, bool *negated)
      equivalent to .begin [no-]transform.  We should remove it when
      we stop accepting those options.  */
 
-  if (strncmp (input_line_pointer, "generics", strlen ("generics")) == 0)
+  if (startswith (input_line_pointer, "generics"))
     {
       as_warn (_("[no-]generics is deprecated; use [no-]transform instead"));
       directive_string = "transform";
     }
-  else if (strncmp (input_line_pointer, "relax", strlen ("relax")) == 0)
+  else if (startswith (input_line_pointer, "relax"))
     {
       as_warn (_("[no-]relax is deprecated; use [no-]transform instead"));
       directive_string = "transform";
@@ -2893,7 +2893,7 @@ static bool
 xg_instruction_matches_option_term (TInsn *insn, const ReqOrOption *option)
 {
   if (strcmp (option->option_name, "realnop") == 0
-      || strncmp (option->option_name, "IsaUse", 6) == 0)
+      || startswith (option->option_name, "IsaUse"))
     {
       /* These conditions were evaluated statically when building the
 	 relaxation table.  There's no need to reevaluate them now.  */
@@ -4552,7 +4552,7 @@ is_unaligned_label (symbolS *sym)
       && (name[fake_size] == 'F'
 	  || name[fake_size] == 'L'
 	  || (name[fake_size] == 'e'
-	      && strncmp ("endfunc", name+fake_size, 7) == 0)))
+	      && startswith (name + fake_size, "endfunc"))))
     return true;
 
   return false;
@@ -11690,11 +11690,11 @@ cache_literal_section (bool use_abs_literals)
       size_t len = strlen (text_name);
       if (len >= 5
 	  && (strcmp (text_name + len - 5, ".text") == 0
-	      || strncmp (text_name, ".text", 5) == 0))
+	      || startswith (text_name, ".text")))
 	len -= 5;
 
       name = XNEWVEC (char, len + strlen (base_name) + 1);
-      if (strncmp (text_name, ".text", 5) == 0)
+      if (startswith (text_name, ".text"))
 	{
 	  strcpy (name, base_name);
 	  strcat (name, text_name + 5);
diff --git a/gas/config/xtensa-relax.c b/gas/config/xtensa-relax.c
index 88e29988df7..267d436461a 100644
--- a/gas/config/xtensa-relax.c
+++ b/gas/config/xtensa-relax.c
@@ -1282,9 +1282,9 @@ parse_precond (const char *s, precond_e *precond)
   p = skip_white (p);
 
   /* Check for "==" and "!=".  */
-  if (strncmp (p, "==", 2) == 0)
+  if (startswith (p, "=="))
     precond->cmpop = OP_EQUAL;
-  else if (strncmp (p, "!=", 2) == 0)
+  else if (startswith (p, "!="))
     precond->cmpop = OP_NOTEQUAL;
   else
     return false;
@@ -1392,7 +1392,7 @@ parse_option_cond (const char *s, ReqOption *option)
       ReqOrOption *req;
       ReqOrOption **r_p;
 
-      if (strncmp (option_name, "no-", 3) == 0)
+      if (startswith (option_name, "no-"))
 	{
 	  option_name = xstrdup (&option_name[3]);
 	  is_true = false;
@@ -1558,7 +1558,7 @@ transition_applies (insn_pattern *initial_insn,
 	  || req_or_option->next != NULL)
 	continue;
 
-      if (strncmp (req_or_option->option_name, "IsaUse", 6) == 0)
+      if (startswith (req_or_option->option_name, "IsaUse"))
 	{
 	  bool option_available = false;
 	  char *option_name = req_or_option->option_name + 6;
@@ -1607,7 +1607,7 @@ wide_branch_opcode (const char *opcode_name,
   xtensa_opcode opcode;
   static char wbr_name_buf[20];
 
-  if (strncmp (opcode_name, "WIDE.", 5) != 0)
+  if (!startswith (opcode_name, "WIDE."))
     return false;
 
   strcpy (wbr_name_buf, opcode_name + 5);
diff --git a/gas/dw2gencfi.c b/gas/dw2gencfi.c
index 24dfee9e9c3..84029940b2e 100644
--- a/gas/dw2gencfi.c
+++ b/gas/dw2gencfi.c
@@ -1219,14 +1219,13 @@ dot_cfi_sections (int ignored ATTRIBUTE_UNUSED)
 	saved_ilp = input_line_pointer;
 	c = get_symbol_name (& name);
 
-	if (strncmp (name, ".eh_frame", sizeof ".eh_frame") == 0
+	if (startswith (name, ".eh_frame")
 	    && name[9] != '_')
 	  sections |= CFI_EMIT_eh_frame;
-	else if (strncmp (name, ".debug_frame", sizeof ".debug_frame") == 0)
+	else if (startswith (name, ".debug_frame"))
 	  sections |= CFI_EMIT_debug_frame;
 #if SUPPORT_COMPACT_EH
-	else if (strncmp (name, ".eh_frame_entry",
-			  sizeof ".eh_frame_entry") == 0)
+	else if (startswith (name, ".eh_frame_entry"))
 	  {
 	    compact_eh = true;
 	    sections |= CFI_EMIT_eh_frame_compact;
diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
index 60ed2190548..24c3560f6f4 100644
--- a/gas/dwarf2dbg.c
+++ b/gas/dwarf2dbg.c
@@ -1097,7 +1097,7 @@ dwarf2_directive_filename (void)
 	  SKIP_WHITESPACE ();
 	}
 
-      if (strncmp (input_line_pointer, "md5", 3) == 0)
+      if (startswith (input_line_pointer, "md5"))
 	{
 	  input_line_pointer += 3;
 	  SKIP_WHITESPACE ();
diff --git a/gas/ehopt.c b/gas/ehopt.c
index 256932068c8..21f0755b3a4 100644
--- a/gas/ehopt.c
+++ b/gas/ehopt.c
@@ -118,7 +118,7 @@ get_cie_info (struct cie_info *info)
 
   /* First make sure that the CIE Identifier Tag is 0/-1.  */
 
-  if (strncmp (segment_name (now_seg), ".debug_frame", 12) == 0)
+  if (startswith (segment_name (now_seg), ".debug_frame"))
     CIE_id = (char)0xff;
   else
     CIE_id = 0;
@@ -283,10 +283,10 @@ check_eh_frame (expressionS *exp, unsigned int *pnbytes)
 #endif
 
   /* Select the proper section data.  */
-  if (strncmp (segment_name (now_seg), ".eh_frame", 9) == 0
+  if (startswith (segment_name (now_seg), ".eh_frame")
       && segment_name (now_seg)[9] != '_')
     d = &eh_frame_data;
-  else if (strncmp (segment_name (now_seg), ".debug_frame", 12) == 0)
+  else if (startswith (segment_name (now_seg), ".debug_frame"))
     d = &debug_frame_data;
   else
     return 0;
diff --git a/gas/input-file.c b/gas/input-file.c
index aae20a8ca6e..088af7de13d 100644
--- a/gas/input-file.c
+++ b/gas/input-file.c
@@ -171,7 +171,7 @@ input_file_open (const char *filename,
       if (c == 'N')
 	{
 	  if (fgets (buf, sizeof (buf), f_in)
-	      && !strncmp (buf, "O_APP", 5) && ISSPACE (buf[5]))
+	      && startswith (buf, "O_APP") && ISSPACE (buf[5]))
 	    preprocess = 0;
 	  if (!strchr (buf, '\n'))
 	    ungetc ('#', f_in);	/* It was longer.  */
@@ -181,7 +181,7 @@ input_file_open (const char *filename,
       else if (c == 'A')
 	{
 	  if (fgets (buf, sizeof (buf), f_in)
-	      && !strncmp (buf, "PP", 2) && ISSPACE (buf[2]))
+	      && startswith (buf, "PP") && ISSPACE (buf[2]))
 	    preprocess = 1;
 	  if (!strchr (buf, '\n'))
 	    ungetc ('#', f_in);
diff --git a/gas/listing.c b/gas/listing.c
index 88f0edf3217..eebe21de7cf 100644
--- a/gas/listing.c
+++ b/gas/listing.c
@@ -318,8 +318,8 @@ listing_newline (char *ps)
       const char *segname;
 
       segname = segment_name (now_seg);
-      if (strncmp (segname, ".debug", sizeof ".debug" - 1) == 0
-	  || strncmp (segname, ".line", sizeof ".line" - 1) == 0)
+      if (startswith (segname, ".debug")
+	  || startswith (segname, ".line"))
 	listing_tail->debugging = 1;
     }
 #endif
@@ -433,8 +433,8 @@ listing_newline (char *ps)
       const char *segname;
 
       segname = segment_name (now_seg);
-      if (strncmp (segname, ".debug", sizeof ".debug" - 1) == 0
-	  || strncmp (segname, ".line", sizeof ".line" - 1) == 0)
+      if (startswith (segname, ".debug")
+	  || startswith (segname, ".line"))
 	new_i->debugging = 1;
     }
 #endif
@@ -1160,29 +1160,29 @@ debugging_pseudo (list_info_type *list, const char *line)
 
   line++;
 
-  if (strncmp (line, "def", 3) == 0)
+  if (startswith (line, "def"))
     return 1;
-  if (strncmp (line, "val", 3) == 0)
+  if (startswith (line, "val"))
     return 1;
-  if (strncmp (line, "scl", 3) == 0)
+  if (startswith (line, "scl"))
     return 1;
-  if (strncmp (line, "line", 4) == 0)
+  if (startswith (line, "line"))
     return 1;
-  if (strncmp (line, "endef", 5) == 0)
+  if (startswith (line, "endef"))
     return 1;
-  if (strncmp (line, "ln", 2) == 0)
+  if (startswith (line, "ln"))
     return 1;
-  if (strncmp (line, "type", 4) == 0)
+  if (startswith (line, "type"))
     return 1;
-  if (strncmp (line, "size", 4) == 0)
+  if (startswith (line, "size"))
     return 1;
-  if (strncmp (line, "dim", 3) == 0)
+  if (startswith (line, "dim"))
     return 1;
-  if (strncmp (line, "tag", 3) == 0)
+  if (startswith (line, "tag"))
     return 1;
-  if (strncmp (line, "stabs", 5) == 0)
+  if (startswith (line, "stabs"))
     return 1;
-  if (strncmp (line, "stabn", 5) == 0)
+  if (startswith (line, "stabn"))
     return 1;
 
   return 0;
diff --git a/gas/read.c b/gas/read.c
index dd7b3e6e4a9..670f316b62d 100644
--- a/gas/read.c
+++ b/gas/read.c
@@ -1322,7 +1322,7 @@ read_a_source_file (const char *name)
 	      char *tmp_buf = 0;
 
 	      s = input_line_pointer;
-	      if (strncmp (s, "APP\n", 4))
+	      if (!startswith (s, "APP\n"))
 		{
 		  /* We ignore it.  */
 		  ignore_rest_of_line ();
diff --git a/gas/write.c b/gas/write.c
index acc7c19b53f..c8e6ab4a6cf 100644
--- a/gas/write.c
+++ b/gas/write.c
@@ -880,8 +880,7 @@ adjust_reloc_syms (bfd *abfd ATTRIBUTE_UNUSED,
 		    /* The GNU toolchain uses an extension for ELF: a
 		       section beginning with the magic string
 		       .gnu.linkonce is a linkonce section.  */
-		    && strncmp (segment_name (symsec), ".gnu.linkonce",
-				sizeof ".gnu.linkonce" - 1) == 0))
+		    && startswith (segment_name (symsec), ".gnu.linkonce")))
 	      continue;
 	  }
 
@@ -1450,7 +1449,7 @@ compress_debug (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED)
     return;
 
   section_name = bfd_section_name (sec);
-  if (strncmp (section_name, ".debug_", 7) != 0)
+  if (!startswith (section_name, ".debug_"))
     return;
 
   strm = compress_init ();
@@ -2039,7 +2038,7 @@ maybe_generate_build_notes (void)
 	/* Skip linkonce sections - we cannot use these section symbols as they may disappear.  */
 	&& (bsym->section->flags & (SEC_CODE | SEC_LINK_ONCE)) == SEC_CODE
 	/* Not all linkonce sections are flagged...  */
-	&& strncmp (S_GET_NAME (sym), ".gnu.linkonce", sizeof ".gnu.linkonce" - 1) != 0)
+	&& !startswith (S_GET_NAME (sym), ".gnu.linkonce"))
       {
 	/* Create a version note.  */
 	frag_now_fix ();
-- 
2.30.2


[-- Attachment #3: 0001-Replace-const_strneq-with-startswith.patch --]
[-- Type: text/x-patch, Size: 15268 bytes --]

From 639155da66491d4b84ce0fa86549d66dc6c0f4f7 Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Mon, 22 Mar 2021 12:12:36 +0100
Subject: [PATCH 1/4] Replace const_strneq with startswith.

binutils/ChangeLog:

	* dwarf.c (display_debug_lines_raw): Replace const_strneq with
	startswith.
	(display_debug_lines_decoded): Likewise.
	(display_debug_links): Likewise.
	* elfcomm.c (setup_archive): Likewise.
	* elfcomm.h (const_strneq): Likewise.
	* readelf.c (process_section_headers): Likewise.
	(slurp_ia64_unwind_table): Likewise.
	(slurp_hppa_unwind_table): Likewise.
	(decode_arm_unwind): Likewise.
	(display_debug_section): Likewise.
	(process_note): Likewise.
---
 binutils/dwarf.c   |   8 ++--
 binutils/elfcomm.c |   7 ++--
 binutils/elfcomm.h |   1 -
 binutils/readelf.c | 102 ++++++++++++++++++++++-----------------------
 4 files changed, 59 insertions(+), 59 deletions(-)

diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index a8b65621b19..293d33ec9ac 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -4500,7 +4500,7 @@ display_debug_lines_raw (struct dwarf_section *  section,
       unsigned char *end_of_sequence;
       int i;
 
-      if (const_strneq (section->name, ".debug_line.")
+      if (startswith (section->name, ".debug_line.")
 	  /* Note: the following does not apply to .debug_line.dwo sections.
 	     These are full debug_line sections.  */
 	  && strcmp (section->name, ".debug_line.dwo") != 0)
@@ -4924,7 +4924,7 @@ display_debug_lines_decoded (struct dwarf_section *  section,
       unsigned char **directory_table = NULL;
       dwarf_vma n_directories = 0;
 
-      if (const_strneq (section->name, ".debug_line.")
+      if (startswith (section->name, ".debug_line.")
 	  /* Note: the following does not apply to .debug_line.dwo sections.
 	     These are full debug_line sections.  */
 	  && strcmp (section->name, ".debug_line.dwo") != 0)
@@ -10031,7 +10031,7 @@ display_debug_links (struct dwarf_section *  section,
 
   printf (_("  Separate debug info file: %s\n"), filename);
 
-  if (const_strneq (section->name, ".gnu_debuglink"))
+  if (startswith (section->name, ".gnu_debuglink"))
     {
       unsigned int          crc32;
       unsigned int          crc_offset;
@@ -10055,7 +10055,7 @@ display_debug_links (struct dwarf_section *  section,
 	  return 0;
 	}
     }
-  else /* const_strneq (section->name, ".gnu_debugaltlink") */
+  else /* startswith (section->name, ".gnu_debugaltlink") */
     {
       const unsigned char * build_id = section->start + filelen + 1;
       bfd_size_type         build_id_len = section->size - (filelen + 1);
diff --git a/binutils/elfcomm.c b/binutils/elfcomm.c
index 5cf4c24360e..c5092c64377 100644
--- a/binutils/elfcomm.c
+++ b/binutils/elfcomm.c
@@ -27,6 +27,7 @@
 
 #include "sysdep.h"
 #include "libiberty.h"
+#include "bfd.h"
 #include "filenames.h"
 #include "aout/ar.h"
 #include "elfcomm.h"
@@ -611,12 +612,12 @@ setup_archive (struct archive_info *arch, const char *file_name,
     }
 
   /* See if this is the archive symbol table.  */
-  if (const_strneq (arch->arhdr.ar_name, "/               "))
+  if (startswith (arch->arhdr.ar_name, "/               "))
     {
       if (! process_archive_index_and_symbols (arch, 4, read_symbols))
 	return 1;
     }
-  else if (const_strneq (arch->arhdr.ar_name, "/SYM64/         "))
+  else if (startswith (arch->arhdr.ar_name, "/SYM64/         "))
     {
       arch->uses_64bit_indices = 1;
       if (! process_archive_index_and_symbols (arch, 8, read_symbols))
@@ -625,7 +626,7 @@ setup_archive (struct archive_info *arch, const char *file_name,
   else if (read_symbols)
     printf (_("%s has no archive index\n"), file_name);
 
-  if (const_strneq (arch->arhdr.ar_name, "//              "))
+  if (startswith (arch->arhdr.ar_name, "//              "))
     {
       /* This is the archive string table holding long member names.  */
       char fmag_save = arch->arhdr.ar_fmag[0];
diff --git a/binutils/elfcomm.h b/binutils/elfcomm.h
index 9754ce1ca09..04e909c2da3 100644
--- a/binutils/elfcomm.h
+++ b/binutils/elfcomm.h
@@ -48,7 +48,6 @@ extern void byte_get_64 (const unsigned char *, elf_vma *, elf_vma *);
 /* This is just a bit of syntatic sugar.  */
 #define streq(a,b)	  (strcmp ((a), (b)) == 0)
 #define strneq(a,b,n)	  (strncmp ((a), (b), (n)) == 0)
-#define const_strneq(a,b) (strncmp ((a), (b), sizeof (b) - 1) == 0)
 
 /* Structure to hold information about an archive file.  */
 
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 8ffca057a8a..01fba0b20e6 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -6589,8 +6589,8 @@ process_section_headers (Filedata * filedata)
 	   || do_debug_str || do_debug_str_offsets || do_debug_loc
 	   || do_debug_ranges
 	   || do_debug_addr || do_debug_cu_index || do_debug_links)
-	  && (const_strneq (name, ".debug_")
-	      || const_strneq (name, ".zdebug_")))
+	  && (startswith (name, ".debug_")
+	      || startswith (name, ".zdebug_")))
 	{
           if (name[1] == 'z')
             name += sizeof (".zdebug_") - 1;
@@ -6598,35 +6598,35 @@ process_section_headers (Filedata * filedata)
             name += sizeof (".debug_") - 1;
 
 	  if (do_debugging
-	      || (do_debug_info     && const_strneq (name, "info"))
-	      || (do_debug_info     && const_strneq (name, "types"))
-	      || (do_debug_abbrevs  && const_strneq (name, "abbrev"))
+	      || (do_debug_info     && startswith (name, "info"))
+	      || (do_debug_info     && startswith (name, "types"))
+	      || (do_debug_abbrevs  && startswith (name, "abbrev"))
 	      || (do_debug_lines    && strcmp (name, "line") == 0)
-	      || (do_debug_lines    && const_strneq (name, "line."))
-	      || (do_debug_pubnames && const_strneq (name, "pubnames"))
-	      || (do_debug_pubtypes && const_strneq (name, "pubtypes"))
-	      || (do_debug_pubnames && const_strneq (name, "gnu_pubnames"))
-	      || (do_debug_pubtypes && const_strneq (name, "gnu_pubtypes"))
-	      || (do_debug_aranges  && const_strneq (name, "aranges"))
-	      || (do_debug_ranges   && const_strneq (name, "ranges"))
-	      || (do_debug_ranges   && const_strneq (name, "rnglists"))
-	      || (do_debug_frames   && const_strneq (name, "frame"))
-	      || (do_debug_macinfo  && const_strneq (name, "macinfo"))
-	      || (do_debug_macinfo  && const_strneq (name, "macro"))
-	      || (do_debug_str      && const_strneq (name, "str"))
-	      || (do_debug_links    && const_strneq (name, "sup"))
-	      || (do_debug_str_offsets && const_strneq (name, "str_offsets"))
-	      || (do_debug_loc      && const_strneq (name, "loc"))
-	      || (do_debug_loc      && const_strneq (name, "loclists"))
-	      || (do_debug_addr     && const_strneq (name, "addr"))
-	      || (do_debug_cu_index && const_strneq (name, "cu_index"))
-	      || (do_debug_cu_index && const_strneq (name, "tu_index"))
+	      || (do_debug_lines    && startswith (name, "line."))
+	      || (do_debug_pubnames && startswith (name, "pubnames"))
+	      || (do_debug_pubtypes && startswith (name, "pubtypes"))
+	      || (do_debug_pubnames && startswith (name, "gnu_pubnames"))
+	      || (do_debug_pubtypes && startswith (name, "gnu_pubtypes"))
+	      || (do_debug_aranges  && startswith (name, "aranges"))
+	      || (do_debug_ranges   && startswith (name, "ranges"))
+	      || (do_debug_ranges   && startswith (name, "rnglists"))
+	      || (do_debug_frames   && startswith (name, "frame"))
+	      || (do_debug_macinfo  && startswith (name, "macinfo"))
+	      || (do_debug_macinfo  && startswith (name, "macro"))
+	      || (do_debug_str      && startswith (name, "str"))
+	      || (do_debug_links    && startswith (name, "sup"))
+	      || (do_debug_str_offsets && startswith (name, "str_offsets"))
+	      || (do_debug_loc      && startswith (name, "loc"))
+	      || (do_debug_loc      && startswith (name, "loclists"))
+	      || (do_debug_addr     && startswith (name, "addr"))
+	      || (do_debug_cu_index && startswith (name, "cu_index"))
+	      || (do_debug_cu_index && startswith (name, "tu_index"))
 	      )
 	    request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
 	}
       /* Linkonce section to be combined with .debug_info at link time.  */
       else if ((do_debugging || do_debug_info)
-	       && const_strneq (name, ".gnu.linkonce.wi."))
+	       && startswith (name, ".gnu.linkonce.wi."))
 	request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
       else if (do_debug_frames && streq (name, ".eh_frame"))
 	request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
@@ -6636,7 +6636,7 @@ process_section_headers (Filedata * filedata)
       /* Trace sections for Itanium VMS.  */
       else if ((do_debugging || do_trace_info || do_trace_abbrevs
                 || do_trace_aranges)
-	       && const_strneq (name, ".trace_"))
+	       && startswith (name, ".trace_"))
 	{
           name += sizeof (".trace_") - 1;
 
@@ -6648,8 +6648,8 @@ process_section_headers (Filedata * filedata)
 	    request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
 	}
       else if ((do_debugging || do_debug_links)
-	       && (const_strneq (name, ".gnu_debuglink")
-		   || const_strneq (name, ".gnu_debugaltlink")))
+	       && (startswith (name, ".gnu_debuglink")
+		   || startswith (name, ".gnu_debugaltlink")))
 	request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
     }
 
@@ -8107,7 +8107,7 @@ slurp_ia64_unwind_table (Filedata *                  filedata,
 	      continue;
 	    }
 
-	  if (! const_strneq (relname, "R_IA64_SEGREL"))
+	  if (! startswith (relname, "R_IA64_SEGREL"))
 	    {
 	      warn (_("Skipping unexpected relocation type: %s\n"), relname);
 	      continue;
@@ -8574,7 +8574,7 @@ slurp_hppa_unwind_table (Filedata *                  filedata,
 	    }
 
 	  /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64.  */
-	  if (! const_strneq (relname, "R_PARISC_SEGREL"))
+	  if (! startswith (relname, "R_PARISC_SEGREL"))
 	    {
 	      warn (_("Skipping unexpected relocation type: %s\n"), relname);
 	      continue;
@@ -9476,10 +9476,10 @@ decode_arm_unwind (Filedata *                 filedata,
 	 encoding, starting with one byte giving the number of
 	 words.  */
       if (procname != NULL
-	  && (const_strneq (procname, "__gcc_personality_v0")
-	      || const_strneq (procname, "__gxx_personality_v0")
-	      || const_strneq (procname, "__gcj_personality_v0")
-	      || const_strneq (procname, "__gnu_objc_personality_v0")))
+	  && (startswith (procname, "__gcc_personality_v0")
+	      || startswith (procname, "__gxx_personality_v0")
+	      || startswith (procname, "__gcj_personality_v0")
+	      || startswith (procname, "__gnu_objc_personality_v0")))
 	{
 	  remaining = 0;
 	  more_words = 1;
@@ -15297,7 +15297,7 @@ malformed note encountered in section %s whilst scanning for build-id note\n"),
       /* Check if this is the build-id note. If so then convert the build-id
          bytes to a hex string.  */
       if (inote.namesz > 0
-          && const_strneq (inote.namedata, "GNU")
+          && startswith (inote.namedata, "GNU")
           && inote.type == NT_GNU_BUILD_ID)
         {
           unsigned long j;
@@ -15425,7 +15425,7 @@ display_debug_section (int shndx, Elf_Internal_Shdr * section, Filedata * fileda
       return false;
     }
 
-  if (const_strneq (name, ".gnu.linkonce.wi."))
+  if (startswith (name, ".gnu.linkonce.wi."))
     name = ".debug_info";
 
   /* See if we know how to display the contents of this section.  */
@@ -15436,7 +15436,7 @@ display_debug_section (int shndx, Elf_Internal_Shdr * section, Filedata * fileda
       struct dwarf_section *           sec = & display->section;
 
       if (streq (sec->uncompressed_name, name)
-	  || (id == line && const_strneq (name, ".debug_line."))
+	  || (id == line && startswith (name, ".debug_line."))
 	  || streq (sec->compressed_name, name))
 	{
 	  bool secondary = (section != find_section (filedata, name));
@@ -15444,7 +15444,7 @@ display_debug_section (int shndx, Elf_Internal_Shdr * section, Filedata * fileda
 	  if (secondary)
 	    free_debug_section (id);
 
-	  if (i == line && const_strneq (name, ".debug_line."))
+	  if (i == line && startswith (name, ".debug_line."))
 	    sec->name = name;
 	  else if (streq (sec->uncompressed_name, name))
 	    sec->name = sec->uncompressed_name;
@@ -20429,23 +20429,23 @@ process_note (Elf_Internal_Note *  pnote,
        note type strings.  */
     nt = get_note_type (filedata, pnote->type);
 
-  else if (const_strneq (pnote->namedata, "GNU"))
+  else if (startswith (pnote->namedata, "GNU"))
     /* GNU-specific object file notes.  */
     nt = get_gnu_elf_note_type (pnote->type);
 
-  else if (const_strneq (pnote->namedata, "FreeBSD"))
+  else if (startswith (pnote->namedata, "FreeBSD"))
     /* FreeBSD-specific core file notes.  */
     nt = get_freebsd_elfcore_note_type (filedata, pnote->type);
 
-  else if (const_strneq (pnote->namedata, "NetBSD-CORE"))
+  else if (startswith (pnote->namedata, "NetBSD-CORE"))
     /* NetBSD-specific core file notes.  */
     nt = get_netbsd_elfcore_note_type (filedata, pnote->type);
 
-  else if (const_strneq (pnote->namedata, "NetBSD"))
+  else if (startswith (pnote->namedata, "NetBSD"))
     /* NetBSD-specific core file notes.  */
     return process_netbsd_elf_note (pnote);
 
-  else if (const_strneq (pnote->namedata, "PaX"))
+  else if (startswith (pnote->namedata, "PaX"))
     /* NetBSD-specific core file notes.  */
     return process_netbsd_elf_note (pnote);
 
@@ -20456,11 +20456,11 @@ process_note (Elf_Internal_Note *  pnote,
       name = "SPU";
     }
 
-  else if (const_strneq (pnote->namedata, "IPF/VMS"))
+  else if (startswith (pnote->namedata, "IPF/VMS"))
     /* VMS/ia64-specific file notes.  */
     nt = get_ia64_vms_note_type (pnote->type);
 
-  else if (const_strneq (pnote->namedata, "stapsdt"))
+  else if (startswith (pnote->namedata, "stapsdt"))
     nt = get_stapsdt_note_type (pnote->type);
 
   else
@@ -20470,7 +20470,7 @@ process_note (Elf_Internal_Note *  pnote,
 
   printf ("  ");
 
-  if (((const_strneq (pnote->namedata, "GA")
+  if (((startswith (pnote->namedata, "GA")
 	&& strchr ("*$!+", pnote->namedata[2]) != NULL)
        || strchr ("*$!+", pnote->namedata[0]) != NULL)
       && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN
@@ -20484,15 +20484,15 @@ process_note (Elf_Internal_Note *  pnote,
   else
     printf (" 0x%08lx\t%s\n", pnote->descsz, nt);
 
-  if (const_strneq (pnote->namedata, "IPF/VMS"))
+  if (startswith (pnote->namedata, "IPF/VMS"))
     return print_ia64_vms_note (pnote);
-  else if (const_strneq (pnote->namedata, "GNU"))
+  else if (startswith (pnote->namedata, "GNU"))
     return print_gnu_note (filedata, pnote);
-  else if (const_strneq (pnote->namedata, "stapsdt"))
+  else if (startswith (pnote->namedata, "stapsdt"))
     return print_stapsdt_note (pnote);
-  else if (const_strneq (pnote->namedata, "CORE"))
+  else if (startswith (pnote->namedata, "CORE"))
     return print_core_note (pnote);
-  else if (((const_strneq (pnote->namedata, "GA")
+  else if (((startswith (pnote->namedata, "GA")
 	     && strchr ("*$!+", pnote->namedata[2]) != NULL)
 	    || strchr ("*$!+", pnote->namedata[0]) != NULL)
 	   && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN
-- 
2.30.2


[-- Attachment #4: 0004-Remove-strneq-macro-and-use-startswith.patch --]
[-- Type: text/x-patch, Size: 12221 bytes --]

From fe53efcc8048f643c6e30d968704357933644fe4 Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Mon, 22 Mar 2021 14:56:16 +0100
Subject: [PATCH 4/4] Remove strneq macro and use startswith.

bfd/ChangeLog:

	* ecoff.c (strneq): Remove strneq and use startswith.
	(_bfd_ecoff_slurp_armap): Likewise.

binutils/ChangeLog:

	* elfcomm.h (strneq): Remove strneq and use startswith.
	* readelf.c (ia64_process_unwind): Likewise.
	(process_note): Likewise.

gas/ChangeLog:

	* config/obj-coff.c (strneq): Remove strneq and use startswith.
	(weak_is_altname): Likewise.
	(obj_coff_section): Likewise.
	* config/tc-cr16.c (process_label_constant): Likewise.
	* config/tc-crx.c (strneq): Likewise.

include/ChangeLog:

	* opcode/cr16.h (strneq): Remove strneq and use startswith.

ld/ChangeLog:

	* ldbuildid.c (strneq): Remove strneq and use startswith.
	(validate_build_id_style): Likewise.
	(compute_build_id_size): Likewise.

opcodes/ChangeLog:

	* arm-dis.c (strneq): Remove strneq and use startswith.
	* cr16-dis.c (print_insn_cr16): Likewise.
	* score-dis.c (streq): Likewise.
	(strneq): Likewise.
	* score7-dis.c (strneq): Likewise.
---
 bfd/ecoff.c           |  5 ++---
 binutils/elfcomm.h    |  1 -
 binutils/readelf.c    | 14 +++++++-------
 gas/config/obj-coff.c |  5 ++---
 gas/config/tc-cr16.c  | 26 +++++++++++++-------------
 gas/config/tc-crx.c   |  1 -
 include/opcode/cr16.h |  1 -
 ld/ldbuildid.c        |  7 +++----
 opcodes/arm-dis.c     |  5 -----
 opcodes/cr16-dis.c    |  2 +-
 opcodes/score-dis.c   |  8 --------
 opcodes/score7-dis.c  |  4 ----
 12 files changed, 28 insertions(+), 51 deletions(-)

diff --git a/bfd/ecoff.c b/bfd/ecoff.c
index f09fc1dd0a6..7844a50b39d 100644
--- a/bfd/ecoff.c
+++ b/bfd/ecoff.c
@@ -46,7 +46,6 @@
 #include "libiberty.h"
 
 #define streq(a, b)	(strcmp ((a), (b)) == 0)
-#define strneq(a, b, n)	(strncmp ((a), (b), (n)) == 0)
 
 \f
 /* This stuff is somewhat copied from coffcode.h.  */
@@ -2870,14 +2869,14 @@ _bfd_ecoff_slurp_armap (bfd *abfd)
     return bfd_slurp_armap (abfd);
 
   /* See if the first element is an armap.  */
-  if (! strneq (nextname, ecoff_backend (abfd)->armap_start, ARMAP_START_LENGTH)
+  if (strncmp (nextname, ecoff_backend (abfd)->armap_start, ARMAP_START_LENGTH) != 0
       || nextname[ARMAP_HEADER_MARKER_INDEX] != ARMAP_MARKER
       || (nextname[ARMAP_HEADER_ENDIAN_INDEX] != ARMAP_BIG_ENDIAN
 	  && nextname[ARMAP_HEADER_ENDIAN_INDEX] != ARMAP_LITTLE_ENDIAN)
       || nextname[ARMAP_OBJECT_MARKER_INDEX] != ARMAP_MARKER
       || (nextname[ARMAP_OBJECT_ENDIAN_INDEX] != ARMAP_BIG_ENDIAN
 	  && nextname[ARMAP_OBJECT_ENDIAN_INDEX] != ARMAP_LITTLE_ENDIAN)
-      || ! strneq (nextname + ARMAP_END_INDEX, ARMAP_END, sizeof ARMAP_END - 1))
+      || strncmp (nextname + ARMAP_END_INDEX, ARMAP_END, sizeof ARMAP_END - 1) != 0)
     {
       abfd->has_armap = false;
       return true;
diff --git a/binutils/elfcomm.h b/binutils/elfcomm.h
index 04e909c2da3..921d42ca425 100644
--- a/binutils/elfcomm.h
+++ b/binutils/elfcomm.h
@@ -47,7 +47,6 @@ extern void byte_get_64 (const unsigned char *, elf_vma *, elf_vma *);
 
 /* This is just a bit of syntatic sugar.  */
 #define streq(a,b)	  (strcmp ((a), (b)) == 0)
-#define strneq(a,b,n)	  (strncmp ((a), (b), (n)) == 0)
 
 /* Structure to hold information about an archive file.  */
 
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 01fba0b20e6..5bc59e4c5e2 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -8235,8 +8235,8 @@ ia64_process_unwind (Filedata * filedata)
 	    }
 	}
       else if (SECTION_NAME_VALID (unwsec)
-	       && strneq (SECTION_NAME (unwsec),
-			  ELF_STRING_ia64_unwind_once, len))
+	       && startswith (SECTION_NAME (unwsec),
+			      ELF_STRING_ia64_unwind_once))
 	{
 	  /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO.  */
 	  len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
@@ -8245,8 +8245,8 @@ ia64_process_unwind (Filedata * filedata)
 	       i < filedata->file_header.e_shnum;
 	       ++i, ++sec)
 	    if (SECTION_NAME_VALID (sec)
-		&& strneq (SECTION_NAME (sec),
-			   ELF_STRING_ia64_unwind_info_once, len2)
+		&& startswith (SECTION_NAME (sec),
+			       ELF_STRING_ia64_unwind_info_once)
 		&& streq (SECTION_NAME (sec) + len2, suffix))
 	      break;
 	}
@@ -8258,13 +8258,13 @@ ia64_process_unwind (Filedata * filedata)
 	  len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
 	  suffix = "";
 	  if (SECTION_NAME_VALID (unwsec)
-	      && strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind, len))
+	      && startswith (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind))
 	    suffix = SECTION_NAME (unwsec) + len;
 	  for (i = 0, sec = filedata->section_headers;
 	       i < filedata->file_header.e_shnum;
 	       ++i, ++sec)
 	    if (SECTION_NAME_VALID (sec)
-		&& strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info, len2)
+		&& startswith (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info)
 		&& streq (SECTION_NAME (sec) + len2, suffix))
 	      break;
 	}
@@ -20449,7 +20449,7 @@ process_note (Elf_Internal_Note *  pnote,
     /* NetBSD-specific core file notes.  */
     return process_netbsd_elf_note (pnote);
 
-  else if (strneq (pnote->namedata, "SPU/", 4))
+  else if (startswith (pnote->namedata, "SPU/"))
     {
       /* SPU-specific core file notes.  */
       nt = pnote->namedata + 4;
diff --git a/gas/config/obj-coff.c b/gas/config/obj-coff.c
index 3c008a3ef2d..f3cc3273a4b 100644
--- a/gas/config/obj-coff.c
+++ b/gas/config/obj-coff.c
@@ -33,7 +33,6 @@
 #endif
 
 #define streq(a,b)     (strcmp ((a), (b)) == 0)
-#define strneq(a,b,n)  (strncmp ((a), (b), (n)) == 0)
 
 /* I think this is probably always correct.  */
 #ifndef KEEP_RELOC_INFO
@@ -1058,7 +1057,7 @@ obj_coff_val (int ignore ATTRIBUTE_UNUSED)
 static int
 weak_is_altname (const char * name)
 {
-  return strneq (name, weak_altprefix, sizeof (weak_altprefix) - 1);
+  return startswith (name, weak_altprefix);
 }
 
 /* Return the name of the alternate symbol
@@ -1667,7 +1666,7 @@ obj_coff_section (int ignore ATTRIBUTE_UNUSED)
       /* Add SEC_LINK_ONCE and SEC_LINK_DUPLICATES_DISCARD to .gnu.linkonce
          sections so adjust_reloc_syms in write.c will correctly handle
          relocs which refer to non-local symbols in these sections.  */
-      if (strneq (name, ".gnu.linkonce", sizeof (".gnu.linkonce") - 1))
+      if (startswith (name, ".gnu.linkonce"))
 	flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
 #endif
 
diff --git a/gas/config/tc-cr16.c b/gas/config/tc-cr16.c
index 733b08e2b64..1f6b1fe8b6d 100644
--- a/gas/config/tc-cr16.c
+++ b/gas/config/tc-cr16.c
@@ -905,34 +905,34 @@ process_label_constant (char *str, ins * cr16_ins)
       cr16_ins->rtype = BFD_RELOC_NONE;
       relocatable = 1;
 
-      if (strneq (input_line_pointer, "@c", 2))
+      if (startswith (input_line_pointer, "@c"))
 	symbol_with_at = 1;
 
-      if (strneq (input_line_pointer, "@l", 2)
-	  || strneq (input_line_pointer, ":l", 2))
+      if (startswith (input_line_pointer, "@l")
+	  || startswith (input_line_pointer, ":l"))
 	symbol_with_l = 1;
 
-      if (strneq (input_line_pointer, "@m", 2)
-	  || strneq (input_line_pointer, ":m", 2))
+      if (startswith (input_line_pointer, "@m")
+	  || startswith (input_line_pointer, ":m"))
 	symbol_with_m = 1;
 
-      if (strneq (input_line_pointer, "@s", 2)
-	  || strneq (input_line_pointer, ":s", 2))
+      if (startswith (input_line_pointer, "@s")
+	  || startswith (input_line_pointer, ":s"))
 	symbol_with_s = 1;
 
-      if (strneq (input_line_pointer, "@cGOT", 5)
-	  || strneq (input_line_pointer, "@cgot", 5))
+      if (startswith (input_line_pointer, "@cGOT")
+	  || startswith (input_line_pointer, "@cgot"))
 	{
 	  if (GOT_symbol == NULL)
 	    GOT_symbol = symbol_find_or_make (GLOBAL_OFFSET_TABLE_NAME);
 
 	  symbol_with_at_gotc = 1;
 	}
-      else if (strneq (input_line_pointer, "@GOT", 4)
-	       || strneq (input_line_pointer, "@got", 4))
+      else if (startswith (input_line_pointer, "@GOT")
+	       || startswith (input_line_pointer, "@got"))
 	{
-	  if ((strneq (input_line_pointer, "+", 1))
-	      || (strneq (input_line_pointer, "-", 1)))
+	  if ((startswith (input_line_pointer, "+"))
+	      || (startswith (input_line_pointer, "-")))
 	    as_warn (_("GOT bad expression with %s."), input_line_pointer);
 
 	  if (GOT_symbol == NULL)
diff --git a/gas/config/tc-crx.c b/gas/config/tc-crx.c
index a82acb5fa21..d33a0bf0766 100644
--- a/gas/config/tc-crx.c
+++ b/gas/config/tc-crx.c
@@ -43,7 +43,6 @@
 
 /* Utility macros for string comparison.  */
 #define streq(a, b)           (strcmp (a, b) == 0)
-#define strneq(a, b, c)       (strncmp (a, b, c) == 0)
 
 /* Assign a number NUM, shifted by SHIFT bytes, into a location
    pointed by index BYTE of array 'output_opcode'.  */
diff --git a/include/opcode/cr16.h b/include/opcode/cr16.h
index a96b3374c8a..09e27122a17 100644
--- a/include/opcode/cr16.h
+++ b/include/opcode/cr16.h
@@ -425,7 +425,6 @@ extern const char * cr16_no_op_insn[];
 
 /* Utility macros for string comparison.  */
 #define streq(a, b)           (strcmp (a, b) == 0)
-#define strneq(a, b, c)       (strncmp (a, b, c) == 0)
 
 /* Long long type handling.  */
 /* Replace all appearances of 'long long int' with LONGLONG.  */
diff --git a/ld/ldbuildid.c b/ld/ldbuildid.c
index c0e91bcefc9..0642ec07aa9 100644
--- a/ld/ldbuildid.c
+++ b/ld/ldbuildid.c
@@ -30,13 +30,12 @@
 #endif
 
 #define streq(a,b)     strcmp ((a), (b)) == 0
-#define strneq(a,b,n)  strncmp ((a), (b), (n)) == 0
 
 bool
 validate_build_id_style (const char *style)
 {
   if ((streq (style, "md5")) || (streq (style, "sha1"))
-      || (streq (style, "uuid")) || (strneq (style, "0x", 2)))
+      || (streq (style, "uuid")) || (startswith (style, "0x")))
     return true;
 
   return false;
@@ -51,7 +50,7 @@ compute_build_id_size (const char *style)
   if (streq (style, "sha1"))
     return 160 / 8;
 
-  if (strneq (style, "0x", 2))
+  if (startswith (style, "0x"))
     {
       bfd_size_type size = 0;
       /* ID is in string form (hex).  Count the bytes.  */
@@ -156,7 +155,7 @@ generate_build_id (bfd *abfd,
 	      (size_t) size < sizeof (UUID) ? (size_t) size : sizeof (UUID));
 #endif /* __MINGW32__ */
     }
-  else if (strneq (style, "0x", 2))
+  else if (startswith (style, "0x"))
     {
       /* ID is in string form (hex).  Convert to bits.  */
       const char *id = style + 2;
diff --git a/opcodes/arm-dis.c b/opcodes/arm-dis.c
index 797998722cf..413091983b6 100644
--- a/opcodes/arm-dis.c
+++ b/opcodes/arm-dis.c
@@ -39,11 +39,6 @@
 #include "elf/arm.h"
 #include "mach-o.h"
 
-/* FIXME: Belongs in global header.  */
-#ifndef strneq
-#define strneq(a,b,n)	(strncmp ((a), (b), (n)) == 0)
-#endif
-
 /* Cached mapping symbol state.  */
 enum map_type
 {
diff --git a/opcodes/cr16-dis.c b/opcodes/cr16-dis.c
index d5840cb81f8..ac855523fa9 100644
--- a/opcodes/cr16-dis.c
+++ b/opcodes/cr16-dis.c
@@ -800,7 +800,7 @@ print_insn_cr16 (bfd_vma memaddr, struct disassemble_info *info)
   /* If found, print the instruction's mnemonic and arguments.  */
   if (is_decoded > 0 && (cr16_words[0] != 0 || cr16_words[1] != 0))
     {
-      if (strneq (instruction->mnemonic, "cinv", 4))
+      if (startswith (instruction->mnemonic, "cinv"))
 	info->fprintf_func (info->stream,"%s",
 			    getcinvstring (instruction->mnemonic));
       else
diff --git a/opcodes/score-dis.c b/opcodes/score-dis.c
index c1b9227e8c2..3ec5c6a36eb 100644
--- a/opcodes/score-dis.c
+++ b/opcodes/score-dis.c
@@ -477,14 +477,6 @@ static struct score_opcode score_opcodes[] =
 };
 \f
 
-#ifndef streq
-#define streq(a,b)    (strcmp ((a), (b)) == 0)
-#endif
-
-#ifndef strneq
-#define strneq(a,b,n)    (strncmp ((a), (b), (n)) == 0)
-#endif
-
 #ifndef NUM_ELEM
 #define NUM_ELEM(a)     (sizeof (a) / sizeof (a)[0])
 #endif
diff --git a/opcodes/score7-dis.c b/opcodes/score7-dis.c
index 53873079594..6ffc7f6fa73 100644
--- a/opcodes/score7-dis.c
+++ b/opcodes/score7-dis.c
@@ -37,10 +37,6 @@
 #define streq(a,b)    (strcmp ((a), (b)) == 0)
 #endif
 
-#ifndef strneq
-#define strneq(a,b,n)    (strncmp ((a), (b), (n)) == 0)
-#endif
-
 #ifndef NUM_ELEM
 #define NUM_ELEM(a)     (sizeof (a) / sizeof (a)[0])
 #endif
-- 
2.30.2


[-- Attachment #5: 0002-Use-startswith-more-for-strncmp-function-calls.patch --]
[-- Type: text/x-patch, Size: 24334 bytes --]

From 5cd32c29f6f3104fa77e33cd681fba097d76885e Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Thu, 18 Mar 2021 15:16:54 +0100
Subject: [PATCH 2/4] Use startswith more for strncmp function calls.

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.
---
 bfd/elf-bfd.h          |  2 +-
 bfd/elf.c              | 21 ++++++++++-----------
 bfd/elf32-arc.c        |  2 +-
 bfd/elf32-m32r.c       |  4 ++--
 bfd/elf32-microblaze.c |  2 +-
 bfd/elf32-nds32.c      | 13 ++++++-------
 bfd/elf32-or1k.c       |  2 +-
 bfd/elf32-ppc.c        |  6 +++---
 bfd/elf32-rx.c         |  6 +++---
 bfd/elf32-spu.c        | 26 +++++++++++++-------------
 bfd/elf32-tilepro.c    |  2 +-
 bfd/elf32-xtensa.c     |  2 +-
 bfd/elf64-ppc.c        |  6 +++---
 bfd/elflink.c          | 10 +++++-----
 bfd/elfnn-riscv.c      |  2 +-
 bfd/elfxx-riscv.c      |  4 ++--
 bfd/elfxx-tilegx.c     |  2 +-
 bfd/opncls.c           |  2 +-
 binutils/dllwrap.c     |  8 ++++----
 binutils/objcopy.c     | 20 ++++++++++----------
 binutils/objdump.c     |  2 +-
 21 files changed, 71 insertions(+), 73 deletions(-)

diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index 101c2fdf50d..296b80ad952 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -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
diff --git a/bfd/elf.c b/bfd/elf.c
index 697d1ee7282..276fa14c0dd 100644
--- 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')
diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c
index d201d5a8c46..11a1388acd6 100644
--- a/bfd/elf32-arc.c
+++ b/bfd/elf32-arc.c
@@ -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;
diff --git a/bfd/elf32-m32r.c b/bfd/elf32-m32r.c
index 783632b6518..6a732585f5f 100644
--- a/bfd/elf32-m32r.c
+++ b/bfd/elf32-m32r.c
@@ -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;
diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
index b5868580967..d9c0d93a01a 100644
--- a/bfd/elf32-microblaze.c
+++ b/bfd/elf32-microblaze.c
@@ -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)
 	    {
diff --git a/bfd/elf32-nds32.c b/bfd/elf32-nds32.c
index 31a3ca02925..5eb029524df 100644
--- a/bfd/elf32-nds32.c
+++ b/bfd/elf32-nds32.c
@@ -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;
diff --git a/bfd/elf32-or1k.c b/bfd/elf32-or1k.c
index cd4398da862..013deb406f8 100644
--- a/bfd/elf32-or1k.c
+++ b/bfd/elf32-or1k.c
@@ -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
diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c
index 0ae7e0bcf64..d6ed501245c 100644
--- a/bfd/elf32-ppc.c
+++ b/bfd/elf32-ppc.c
@@ -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
diff --git a/bfd/elf32-rx.c b/bfd/elf32-rx.c
index 95684d4d328..771863590d5 100644
--- a/bfd/elf32-rx.c
+++ b/bfd/elf32-rx.c
@@ -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;
diff --git a/bfd/elf32-spu.c b/bfd/elf32-spu.c
index 5bffc1d8ada..c3ce2c16d80 100644
--- a/bfd/elf32-spu.c
+++ b/bfd/elf32-spu.c
@@ -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;
 
diff --git a/bfd/elf32-tilepro.c b/bfd/elf32-tilepro.c
index cf288b3052b..b0ed7064793 100644
--- a/bfd/elf32-tilepro.c
+++ b/bfd/elf32-tilepro.c
@@ -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)
 	    {
diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c
index 21894d171ac..c1781c7a7d7 100644
--- a/bfd/elf32-xtensa.c
+++ b/bfd/elf32-xtensa.c
@@ -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;
 
diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
index bc8dc4df1a5..c306954dacb 100644
--- a/bfd/elf64-ppc.c
+++ b/bfd/elf64-ppc.c
@@ -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
diff --git a/bfd/elflink.c b/bfd/elflink.c
index ce1407fa2dc..f8d63131680 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -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] == '.'))
diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 51f9d756cd1..b5be929ad1d 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -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)
 	    {
diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c
index a81ebd4d6be..f6a2509d521 100644
--- a/bfd/elfxx-riscv.c
+++ b/bfd/elfxx-riscv.c
@@ -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;
diff --git a/bfd/elfxx-tilegx.c b/bfd/elfxx-tilegx.c
index 28a1a43a96c..a517831a07c 100644
--- a/bfd/elfxx-tilegx.c
+++ b/bfd/elfxx-tilegx.c
@@ -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)
 	    {
diff --git a/bfd/opncls.c b/bfd/opncls.c
index 26faaa6c9a9..74df4c2f518 100644
--- a/bfd/opncls.c
+++ b/bfd/opncls.c
@@ -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))
     {
diff --git a/binutils/dllwrap.c b/binutils/dllwrap.c
index bd65b98fee0..bc7104de004 100644
--- a/binutils/dllwrap.c
+++ b/binutils/dllwrap.c
@@ -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')
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 092bc9e668a..6622adc5e7c 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -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;
diff --git a/binutils/objdump.c b/binutils/objdump.c
index bffd7441eba..cbbec81c026 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -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.
-- 
2.30.2


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 0/5] Start using startswith instead of strncmp
  2021-04-01  5:21                       ` [PATCH 0/5] Start using startswith instead of strncmp Martin Liška
@ 2021-04-01 12:47                         ` Alan Modra
  2021-04-01 13:03                           ` Martin Liška
  0 siblings, 1 reply; 41+ messages in thread
From: Alan Modra @ 2021-04-01 12:47 UTC (permalink / raw)
  To: Martin Liška; +Cc: binutils

On Thu, Apr 01, 2021 at 07:21:32AM +0200, Martin Liška wrote:
> --- a/gas/config/obj-elf.c
> +++ b/gas/config/obj-elf.c
> @@ -2508,7 +2508,7 @@ adjust_stab_sections (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED)
>    char *p;
>    int strsz, nsyms;
>  
> -  if (strncmp (".stab", sec->name, 5))
> +  if (!startswith (".stab", sec->name))
>      return;

I see you caught a number of other cases like this where the args
need swapping.  Please fix this one too.

> --- a/gas/config/obj-macho.c
> +++ b/gas/config/obj-macho.c
> @@ -1907,8 +1907,8 @@ obj_mach_o_is_frame_section (segT sec)
>  {
>    int l;
>    l = strlen (segment_name (sec));
> -  if ((l == 9 && strncmp (".eh_frame", segment_name (sec), 9) == 0)
> -       || (l == 12 && strncmp (".debug_frame", segment_name (sec), 12) == 0))
> +  if ((l == 9 && startswith (".eh_frame", segment_name (sec)))
> +       || (l == 12 && startswith (".debug_frame", segment_name (sec))))

Here too.  OK with those tweaks, thanks!

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 0/5] Start using startswith instead of strncmp
  2021-04-01 12:47                         ` Alan Modra
@ 2021-04-01 13:03                           ` Martin Liška
  0 siblings, 0 replies; 41+ messages in thread
From: Martin Liška @ 2021-04-01 13:03 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

On 4/1/21 2:47 PM, Alan Modra wrote:
> Here too.  OK with those tweaks, thanks!

Thanks for the review! I've just installed the patch set.

Martin

^ permalink raw reply	[flat|nested] 41+ messages in thread

end of thread, other threads:[~2021-04-01 13:03 UTC | newest]

Thread overview: 41+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-18 14:20 [PATCH] [RFC] Come up with startswith function Martin Liška
2021-03-18 14:54 ` Tom Tromey
2021-03-18 15:26   ` Martin Liška
2021-03-18 18:00     ` Tom Tromey
2021-03-18 18:29 ` Hans-Peter Nilsson
2021-03-19  6:37   ` Alan Modra
2021-03-19 12:44     ` [PATCH] Add startswith function and use it instead of CONST_STRNEQ Martin Liška
2021-03-19 17:55       ` Hans-Peter Nilsson
2021-03-20  7:00       ` Alan Modra
2021-03-20 18:58         ` Tom Tromey
2021-03-21 13:12           ` Alan Modra
2021-03-22  2:13             ` Tom Tromey
2021-03-22 12:06               ` Alan Modra
2021-03-22 16:13                 ` Luis Machado
2021-03-22 22:56                   ` Alan Modra
2021-03-25 10:53                     ` Luis Machado
2021-03-25 11:54                       ` Alan Modra
2021-03-25 12:05                         ` Luis Machado
2021-03-25 19:47                         ` Luis Machado
2021-03-25 22:31                           ` Mike Frysinger
2021-03-26 11:44                             ` Luis Machado
2021-03-30 11:58                               ` Luis Machado
2021-03-31 13:12                                 ` Martin Liška
2021-03-31 13:44                                   ` Luis Machado
2021-03-22 16:42                 ` Martin Liška
2021-03-23  0:02                   ` Alan Modra
2021-03-23  4:49                     ` Mike Frysinger
2021-03-24  8:19                     ` [PATCH 0/5] Start using startswith instead of strncmp Martin Liska
2021-03-18 14:16                       ` [PATCH 2/5] Use startswith more for strncmp function calls Martin Liska
2021-03-22 11:12                       ` [PATCH 1/5] Replace const_strneq with startswith Martin Liska
2021-03-22 12:33                       ` [PATCH 3/5] Use startswith in gas subfolder Martin Liska
2021-03-22 13:56                       ` [PATCH 4/5] Remove strneq macro and use startswith Martin Liska
2021-03-23  9:02                       ` [PATCH 5/5] Use startswith in gdb subfolder Martin Liska
2021-03-31 20:26                         ` Tom Tromey
2021-04-01  5:21                       ` [PATCH 0/5] Start using startswith instead of strncmp Martin Liška
2021-04-01 12:47                         ` Alan Modra
2021-04-01 13:03                           ` Martin Liška
2021-03-31 20:18                     ` [PATCH] Add startswith function and use it instead of CONST_STRNEQ Tom Tromey
2021-03-22  6:57             ` Mike Frysinger
2021-03-21 13:19       ` Alan Modra
2021-03-22 10:04         ` Martin Liška

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).