[3/5] Use startswith in gas subfolder.

Message ID 7dd6bfd7830d5c6d25faee3230d33faa749518f2.1616573964.git.mliska@suse.cz
State New
Headers show
Series
  • Start using startswith instead of strncmp
Related show

Commit Message

Martin Liška March 22, 2021, 12:33 p.m.
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(-)

Patch

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 ();