[0/5] Start using startswith instead of strncmp

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

Message

Martin Liška March 24, 2021, 8:19 a.m.
Hey.

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

Thoughts?
Thanks,
Martin

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

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

-- 
2.30.2

Comments

Martin Liška April 1, 2021, 5:21 a.m. | #1
On 3/24/21 9:19 AM, Martin Liska wrote:
> Hey.

> 

> The patchset continues with replacement of the strncmp where it's used

> in startswith context. The patches rely on Alan's patch and I've just

> tested all possible targets.


Hello.

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

Is it ready to be installed?
Thanks,
Martin
From aa79aca07408205e6fee50d1bf9f478dff740078 Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>

Date: Mon, 22 Mar 2021 13:33:04 +0100
Subject: [PATCH 3/4] Use startswith in gas subfolder.

gas/ChangeLog:

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

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

Date: Mon, 22 Mar 2021 12:12:36 +0100
Subject: [PATCH 1/4] Replace const_strneq with startswith.

binutils/ChangeLog:

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

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

Date: Mon, 22 Mar 2021 14:56:16 +0100
Subject: [PATCH 4/4] Remove strneq macro and use startswith.

bfd/ChangeLog:

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

binutils/ChangeLog:

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

gas/ChangeLog:

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

include/ChangeLog:

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

ld/ChangeLog:

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

opcodes/ChangeLog:

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

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

Date: Thu, 18 Mar 2021 15:16:54 +0100
Subject: [PATCH 2/4] Use startswith more for strncmp function calls.

bfd/ChangeLog:

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

binutils/ChangeLog:

	* dllwrap.c: Use startswith function.
	* objcopy.c (is_dwo_section): Likewise.
	(handle_remove_section_option): Likewise.
	(copy_main): Likewise.
	* objdump.c (is_significant_symbol_name): Likewise.
---
 bfd/elf-bfd.h          |  2 +-
 bfd/elf.c              | 21 ++++++++++-----------
 bfd/elf32-arc.c        |  2 +-
 bfd/elf32-m32r.c       |  4 ++--
 bfd/elf32-microblaze.c |  2 +-
 bfd/elf32-nds32.c      | 13 ++++++-------
 bfd/elf32-or1k.c       |  2 +-
 bfd/elf32-ppc.c        |  6 +++---
 bfd/elf32-rx.c         |  6 +++---
 bfd/elf32-spu.c        | 26 +++++++++++++-------------
 bfd/elf32-tilepro.c    |  2 +-
 bfd/elf32-xtensa.c     |  2 +-
 bfd/elf64-ppc.c        |  6 +++---
 bfd/elflink.c          | 10 +++++-----
 bfd/elfnn-riscv.c      |  2 +-
 bfd/elfxx-riscv.c      |  4 ++--
 bfd/elfxx-tilegx.c     |  2 +-
 bfd/opncls.c           |  2 +-
 binutils/dllwrap.c     |  8 ++++----
 binutils/objcopy.c     | 20 ++++++++++----------
 binutils/objdump.c     |  2 +-
 21 files changed, 71 insertions(+), 73 deletions(-)

diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index 101c2fdf50d..296b80ad952 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -3093,7 +3093,7 @@ static inline bool
 bfd_section_is_ctf (const asection *sec)
 {
   const char *name = bfd_section_name (sec);
-  return strncmp (name, ".ctf", 4) == 0 && (name[4] == 0 || name[4] == '.');
+  return startswith (name, ".ctf") && (name[4] == 0 || name[4] == '.');
 }
 
 #ifdef __cplusplus
diff --git a/bfd/elf.c b/bfd/elf.c
index 697d1ee7282..276fa14c0dd 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -1084,19 +1084,19 @@ _bfd_elf_make_section_from_shdr (bfd *abfd,
 	 not any sort of flag.  Their SEC_ALLOC bits are cleared.  */
       if (name [0] == '.')
 	{
-	  if (strncmp (name, ".debug", 6) == 0
-	      || strncmp (name, ".gnu.debuglto_.debug_", 21) == 0
-	      || strncmp (name, ".gnu.linkonce.wi.", 17) == 0
-	      || strncmp (name, ".zdebug", 7) == 0)
+	  if (startswith (name, ".debug")
+	      || startswith (name, ".gnu.debuglto_.debug_")
+	      || startswith (name, ".gnu.linkonce.wi.")
+	      || startswith (name, ".zdebug"))
 	    flags |= SEC_DEBUGGING | SEC_ELF_OCTETS;
-	  else if (strncmp (name, GNU_BUILD_ATTRS_SECTION_NAME, 21) == 0
-		   || strncmp (name, ".note.gnu", 9) == 0)
+	  else if (startswith (name, GNU_BUILD_ATTRS_SECTION_NAME)
+		   || startswith (name, ".note.gnu"))
 	    {
 	      flags |= SEC_ELF_OCTETS;
 	      opb = 1;
 	    }
-	  else if (strncmp (name, ".line", 5) == 0
-		   || strncmp (name, ".stab", 5) == 0
+	  else if (startswith (name, ".line")
+		   || startswith (name, ".stab")
 		   || strcmp (name, ".gdb_index") == 0)
 	    flags |= SEC_DEBUGGING;
 	}
@@ -1277,8 +1277,7 @@ _bfd_elf_make_section_from_shdr (bfd *abfd,
 
   /* GCC uses .gnu.lto_.lto.<some_hash> as a LTO bytecode information
      section.  */
-  const char *lto_section_name = ".gnu.lto_.lto.";
-  if (strncmp (name, lto_section_name, strlen (lto_section_name)) == 0)
+  if (startswith (name, ".gnu.lto_.lto."))
     {
       struct lto_section lsection;
       if (bfd_get_section_contents (abfd, newsect, &lsection, 0,
@@ -3677,7 +3676,7 @@ elf_get_reloc_section (asection *reloc_sec)
 
   /* We look up the section the relocs apply to by name.  */
   name = reloc_sec->name;
-  if (strncmp (name, ".rel", 4) != 0)
+  if (!startswith (name, ".rel"))
     return NULL;
   name += 4;
   if (type == SHT_RELA && *name++ != 'a')
diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c
index d201d5a8c46..11a1388acd6 100644
--- a/bfd/elf32-arc.c
+++ b/bfd/elf32-arc.c
@@ -2759,7 +2759,7 @@ elf_arc_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 	{
 	  /* Strip this section if we don't need it.  */
 	}
-      else if (strncmp (s->name, ".rela", 5) == 0)
+      else if (startswith (s->name, ".rela"))
 	{
 	  if (s->size != 0 && s != htab->srelplt)
 	    relocs_exist = true;
diff --git a/bfd/elf32-m32r.c b/bfd/elf32-m32r.c
index 783632b6518..6a732585f5f 100644
--- a/bfd/elf32-m32r.c
+++ b/bfd/elf32-m32r.c
@@ -3615,8 +3615,8 @@ m32r_elf_section_flags (const Elf_Internal_Shdr *hdr)
 {
   const char *name = hdr->bfd_section->name;
 
-  if (strncmp (name, ".sbss", 5) == 0
-      || strncmp (name, ".sdata", 6) == 0)
+  if (startswith (name, ".sbss")
+      || startswith (name, ".sdata"))
     hdr->bfd_section->flags |= SEC_SMALL_DATA;
 
   return true;
diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
index b5868580967..d9c0d93a01a 100644
--- a/bfd/elf32-microblaze.c
+++ b/bfd/elf32-microblaze.c
@@ -3050,7 +3050,7 @@ microblaze_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 	 of the dynobj section names depend upon the input files.  */
       name = bfd_section_name (s);
 
-      if (strncmp (name, ".rela", 5) == 0)
+      if (startswith (name, ".rela"))
 	{
 	  if (s->size == 0)
 	    {
diff --git a/bfd/elf32-nds32.c b/bfd/elf32-nds32.c
index 31a3ca02925..5eb029524df 100644
--- a/bfd/elf32-nds32.c
+++ b/bfd/elf32-nds32.c
@@ -4439,7 +4439,7 @@ nds32_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 	{
 	  got_size += s->size;
 	}
-      else if (strncmp (bfd_section_name (s), ".rela", 5) == 0)
+      else if (startswith (bfd_section_name (s), ".rela"))
 	{
 	  if (s->size != 0 && s != elf_hash_table (info)->srelplt)
 	    relocs = true;
@@ -5426,7 +5426,7 @@ nds32_elf_relocate_section (bfd *		   output_bfd ATTRIBUTE_UNUSED,
 		  if (name == NULL)
 		    return false;
 
-		  BFD_ASSERT (strncmp (name, ".rela", 5) == 0
+		  BFD_ASSERT (startswith (name, ".rela")
 			      && strcmp (bfd_section_name (input_section),
 					 name + 5) == 0);
 
@@ -6870,8 +6870,7 @@ static unsigned int
 nds32_elf_action_discarded (asection *sec)
 {
 
-  if (strncmp
-      (".gcc_except_table", sec->name, sizeof (".gcc_except_table") - 1) == 0)
+  if (startswith (sec->name, ".gcc_except_table"))
     return 0;
 
   return _bfd_elf_default_action_discarded (sec);
@@ -7239,7 +7238,7 @@ nds32_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
 		  if (name == NULL)
 		    return false;
 
-		  BFD_ASSERT (strncmp (name, ".rela", 5) == 0
+		  BFD_ASSERT (startswith (name, ".rela")
 			      && strcmp (bfd_section_name (sec),
 					 name + 5) == 0);
 
@@ -12450,8 +12449,8 @@ nds32_elf_section_flags (const Elf_Internal_Shdr *hdr)
 {
   const char *name = hdr->bfd_section->name;
 
-  if (strncmp (name, ".sbss", 5) == 0
-      || strncmp (name, ".sdata", 6) == 0)
+  if (startswith (name, ".sbss")
+      || startswith (name, ".sdata"))
     hdr->bfd_section->flags |= SEC_SMALL_DATA;
 
   return true;
diff --git a/bfd/elf32-or1k.c b/bfd/elf32-or1k.c
index cd4398da862..013deb406f8 100644
--- a/bfd/elf32-or1k.c
+++ b/bfd/elf32-or1k.c
@@ -2110,7 +2110,7 @@ or1k_elf_check_relocs (bfd *abfd,
 		    if (name == NULL)
 		      return false;
 
-		    if (strncmp (name, ".rela", 5) != 0
+		    if (!startswith (name, ".rela")
 			|| strcmp (bfd_section_name (sec), name + 5) != 0)
 		      {
 			_bfd_error_handler
diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c
index 0ae7e0bcf64..d6ed501245c 100644
--- a/bfd/elf32-ppc.c
+++ b/bfd/elf32-ppc.c
@@ -1338,10 +1338,10 @@ ppc_elf_section_from_shdr (bfd *abfd,
   if (hdr->sh_type == SHT_ORDERED)
     flags |= SEC_SORT_ENTRIES;
 
-  if (strncmp (name, ".PPC.EMB", 8) == 0)
+  if (startswith (name, ".PPC.EMB"))
     name += 8;
-  if (strncmp (name, ".sbss", 5) == 0
-      || strncmp (name, ".sdata", 6) == 0)
+  if (startswith (name, ".sbss")
+      || startswith (name, ".sdata"))
     flags |= SEC_SMALL_DATA;
 
   return (flags == 0
diff --git a/bfd/elf32-rx.c b/bfd/elf32-rx.c
index 95684d4d328..771863590d5 100644
--- a/bfd/elf32-rx.c
+++ b/bfd/elf32-rx.c
@@ -557,7 +557,7 @@ rx_elf_relocate_section
 	  name = h->root.root.string;
 	}
 
-      if (strncmp (name, "$tableentry$default$", 20) == 0)
+      if (startswith (name, "$tableentry$default$"))
 	{
 	  bfd_vma entry_vma;
 	  int idx;
@@ -3759,7 +3759,7 @@ rx_table_find (struct bfd_hash_entry *vent, void *vinfo)
   sec = ent->u.def.section;
   abfd = sec->owner;
 
-  if (strncmp (name, "$tablestart$", 12))
+  if (!startswith (name, "$tablestart$"))
     return true;
 
   sec->flags |= SEC_KEEP;
@@ -3895,7 +3895,7 @@ rx_table_map (struct bfd_hash_entry *vent, void *vinfo)
 
   name = ent->root.string;
 
-  if (strncmp (name, "$tablestart$", 12))
+  if (!startswith (name, "$tablestart$"))
     return true;
 
   tname = name + 12;
diff --git a/bfd/elf32-spu.c b/bfd/elf32-spu.c
index 5bffc1d8ada..c3ce2c16d80 100644
--- a/bfd/elf32-spu.c
+++ b/bfd/elf32-spu.c
@@ -307,7 +307,7 @@ spu_elf_backend_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, asymbol *sym)
 {
   if (sym->name != NULL
       && sym->section != bfd_abs_section_ptr
-      && strncmp (sym->name, "_EAR_", 5) == 0)
+      && startswith (sym->name, "_EAR_"))
     sym->flags |= BSF_KEEP;
 }
 
@@ -725,7 +725,7 @@ spu_elf_find_overlays (struct bfd_link_info *info)
 	     an overlay, in the sense that it might be loaded in
 	     by the overlay manager, but rather the initial
 	     section contents for the overlay buffer.  */
-	  if (strncmp (s->name, ".ovl.init", 9) != 0)
+	  if (!startswith (s->name, ".ovl.init"))
 	    {
 	      num_buf = ((s->vma - vma_start) >> htab->line_size_log2) + 1;
 	      set_id = (num_buf == prev_buf)? set_id + 1 : 0;
@@ -785,7 +785,7 @@ spu_elf_find_overlays (struct bfd_link_info *info)
 	      if (spu_elf_section_data (s0)->u.o.ovl_index == 0)
 		{
 		  ++num_buf;
-		  if (strncmp (s0->name, ".ovl.init", 9) != 0)
+		  if (!startswith (s0->name, ".ovl.init"))
 		    {
 		      alloc_sec[ovl_index] = s0;
 		      spu_elf_section_data (s0)->u.o.ovl_index = ++ovl_index;
@@ -794,7 +794,7 @@ spu_elf_find_overlays (struct bfd_link_info *info)
 		  else
 		    ovl_end = s->vma + s->size;
 		}
-	      if (strncmp (s->name, ".ovl.init", 9) != 0)
+	      if (!startswith (s->name, ".ovl.init"))
 		{
 		  alloc_sec[ovl_index] = s;
 		  spu_elf_section_data (s)->u.o.ovl_index = ++ovl_index;
@@ -970,7 +970,7 @@ needs_ovl_stub (struct elf_link_hash_entry *h,
       /* setjmp always goes via an overlay stub, because then the return
 	 and hence the longjmp goes via __ovly_return.  That magically
 	 makes setjmp/longjmp between overlays work.  */
-      if (strncmp (h->root.root.string, "setjmp", 6) == 0
+      if (startswith (h->root.root.string, "setjmp")
 	  && (h->root.root.string[6] == '\0' || h->root.root.string[6] == '@'))
 	ret = call_ovl_stub;
     }
@@ -1496,7 +1496,7 @@ allocate_spuear_stubs (struct elf_link_hash_entry *h, void *inf)
   if ((h->root.type == bfd_link_hash_defined
        || h->root.type == bfd_link_hash_defweak)
       && h->def_regular
-      && strncmp (h->root.root.string, "_SPUEAR_", 8) == 0
+      && startswith (h->root.root.string, "_SPUEAR_")
       && (sym_sec = h->root.u.def.section) != NULL
       && sym_sec->output_section != bfd_abs_section_ptr
       && spu_elf_section_data (sym_sec->output_section) != NULL
@@ -1521,7 +1521,7 @@ build_spuear_stubs (struct elf_link_hash_entry *h, void *inf)
   if ((h->root.type == bfd_link_hash_defined
        || h->root.type == bfd_link_hash_defweak)
       && h->def_regular
-      && strncmp (h->root.root.string, "_SPUEAR_", 8) == 0
+      && startswith (h->root.root.string, "_SPUEAR_")
       && (sym_sec = h->root.u.def.section) != NULL
       && sym_sec->output_section != bfd_abs_section_ptr
       && spu_elf_section_data (sym_sec->output_section) != NULL
@@ -3455,7 +3455,7 @@ mark_overlay_section (struct function_info *fun,
   if (!fun->sec->linker_mark
       && (htab->params->ovly_flavour != ovly_soft_icache
 	  || htab->params->non_ia_text
-	  || strncmp (fun->sec->name, ".text.ia.", 9) == 0
+	  || startswith (fun->sec->name, ".text.ia.")
 	  || strcmp (fun->sec->name, ".init") == 0
 	  || strcmp (fun->sec->name, ".fini") == 0))
     {
@@ -3483,7 +3483,7 @@ mark_overlay_section (struct function_info *fun,
 		return false;
 	      memcpy (name, ".rodata", sizeof (".rodata"));
 	    }
-	  else if (strncmp (fun->sec->name, ".text.", 6) == 0)
+	  else if (startswith (fun->sec->name, ".text."))
 	    {
 	      size_t len = strlen (fun->sec->name);
 	      name = bfd_malloc (len + 3);
@@ -3492,7 +3492,7 @@ mark_overlay_section (struct function_info *fun,
 	      memcpy (name, ".rodata", sizeof (".rodata"));
 	      memcpy (name + 7, fun->sec->name + 5, len - 4);
 	    }
-	  else if (strncmp (fun->sec->name, ".gnu.linkonce.t.", 16) == 0)
+	  else if (startswith (fun->sec->name, ".gnu.linkonce.t."))
 	    {
 	      size_t len = strlen (fun->sec->name) + 1;
 	      name = bfd_malloc (len);
@@ -3583,7 +3583,7 @@ mark_overlay_section (struct function_info *fun,
      a stack!  Also, don't mark .ovl.init as an overlay.  */
   if (fun->lo + fun->sec->output_offset + fun->sec->output_section->vma
       == info->output_bfd->start_address
-      || strncmp (fun->sec->output_section->name, ".ovl.init", 9) == 0)
+      || startswith (fun->sec->output_section->name, ".ovl.init"))
     {
       fun->sec->linker_mark = 0;
       if (fun->rodata != NULL)
@@ -4317,7 +4317,7 @@ spu_elf_auto_overlay (struct bfd_link_info *info)
 	  }
 	else if ((sec->flags & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)
 		 && sec->output_section->owner == info->output_bfd
-		 && strncmp (sec->output_section->name, ".ovl.init", 9) == 0)
+		 && startswith (sec->output_section->name, ".ovl.init"))
 	  fixed_size -= sec->size;
       if (count != old_count)
 	bfd_arr[bfd_count++] = ibfd;
@@ -5156,7 +5156,7 @@ spu_elf_output_symbol_hook (struct bfd_link_info *info,
       && (h->root.type == bfd_link_hash_defined
 	  || h->root.type == bfd_link_hash_defweak)
       && h->def_regular
-      && strncmp (h->root.root.string, "_SPUEAR_", 8) == 0)
+      && startswith (h->root.root.string, "_SPUEAR_"))
     {
       struct got_entry *g;
 
diff --git a/bfd/elf32-tilepro.c b/bfd/elf32-tilepro.c
index cf288b3052b..b0ed7064793 100644
--- a/bfd/elf32-tilepro.c
+++ b/bfd/elf32-tilepro.c
@@ -2332,7 +2332,7 @@ tilepro_elf_size_dynamic_sections (bfd *output_bfd,
 	  /* Strip this section if we don't need it; see the
 	     comment below.  */
 	}
-      else if (strncmp (s->name, ".rela", 5) == 0)
+      else if (startswith (s->name, ".rela"))
 	{
 	  if (s->size != 0)
 	    {
diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c
index 21894d171ac..c1781c7a7d7 100644
--- a/bfd/elf32-xtensa.c
+++ b/bfd/elf32-xtensa.c
@@ -11260,7 +11260,7 @@ xtensa_property_section_name (asection *sec, const char *base_name,
 	suffix = 0;
       prop_sec_name = xtensa_add_names (base_name, suffix);
     }
-  else if (strncmp (sec->name, ".gnu.linkonce.", linkonce_len) == 0)
+  else if (startswith (sec->name, ".gnu.linkonce."))
     {
       char *linkonce_kind = 0;
 
diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
index bc8dc4df1a5..c306954dacb 100644
--- a/bfd/elf64-ppc.c
+++ b/bfd/elf64-ppc.c
@@ -2042,8 +2042,8 @@ ppc64_elf_section_flags (const Elf_Internal_Shdr *hdr)
 {
   const char *name = hdr->bfd_section->name;
 
-  if (strncmp (name, ".sbss", 5) == 0
-      || strncmp (name, ".sdata", 6) == 0)
+  if (startswith (name, ".sbss")
+      || startswith (name, ".sdata"))
     hdr->bfd_section->flags |= SEC_SMALL_DATA;
 
   return true;
@@ -15873,7 +15873,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
 		  if (*name == '.')
 		    ++name;
 
-		  if (strncmp (name, "__libc_start_main", 17) == 0
+		  if (startswith (name, "__libc_start_main")
 		      && (name[17] == 0 || name[17] == '@'))
 		    {
 		      /* Allow crt1 branch to go via a toc adjusting
diff --git a/bfd/elflink.c b/bfd/elflink.c
index ce1407fa2dc..f8d63131680 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -8719,7 +8719,7 @@ resolve_section (const char *name,
 
       if (strncmp (curr->name, name, len) == 0)
 	{
-	  if (strncmp (".end", name + len, 4) == 0)
+	  if (startswith (name + len, ".end"))
 	    {
 	      *result = (curr->vma
 			 + curr->size / bfd_octets_per_byte (abfd, curr));
@@ -8832,7 +8832,7 @@ eval_symbol (bfd_vma *result,
       /* All that remains are operators.  */
 
 #define UNARY_OP(op)						\
-  if (strncmp (sym, #op, strlen (#op)) == 0)			\
+  if (startswith (sym, #op))					\
     {								\
       sym += strlen (#op);					\
       if (*sym == ':')						\
@@ -8849,7 +8849,7 @@ eval_symbol (bfd_vma *result,
     }
 
 #define BINARY_OP_HEAD(op)					\
-  if (strncmp (sym, #op, strlen (#op)) == 0)			\
+  if (startswith (sym, #op))					\
     {								\
       sym += strlen (#op);					\
       if (*sym == ':')						\
@@ -11196,10 +11196,10 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
 	  /* We need to reverse-copy input .ctors/.dtors sections if
 	     they are placed in .init_array/.finit_array for output.  */
 	  if (o->size > address_size
-	      && ((strncmp (o->name, ".ctors", 6) == 0
+	      && ((startswith (o->name, ".ctors")
 		   && strcmp (o->output_section->name,
 			      ".init_array") == 0)
-		  || (strncmp (o->name, ".dtors", 6) == 0
+		  || (startswith (o->name, ".dtors")
 		      && strcmp (o->output_section->name,
 				 ".fini_array") == 0))
 	      && (o->name[6] == 0 || o->name[6] == '.'))
diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 51f9d756cd1..b5be929ad1d 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -1515,7 +1515,7 @@ riscv_elf_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
 	  /* Strip this section if we don't need it; see the
 	     comment below.  */
 	}
-      else if (strncmp (s->name, ".rela", 5) == 0)
+      else if (startswith (s->name, ".rela"))
 	{
 	  if (s->size != 0)
 	    {
diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c
index a81ebd4d6be..f6a2509d521 100644
--- a/bfd/elfxx-riscv.c
+++ b/bfd/elfxx-riscv.c
@@ -1802,12 +1802,12 @@ riscv_parse_subset (riscv_parse_subset_t *rps,
     }
 
   p = arch;
-  if (strncmp (p, "rv32", 4) == 0)
+  if (startswith (p, "rv32"))
     {
       *rps->xlen = 32;
       p += 4;
     }
-  else if (strncmp (p, "rv64", 4) == 0)
+  else if (startswith (p, "rv64"))
     {
       *rps->xlen = 64;
       p += 4;
diff --git a/bfd/elfxx-tilegx.c b/bfd/elfxx-tilegx.c
index 28a1a43a96c..a517831a07c 100644
--- a/bfd/elfxx-tilegx.c
+++ b/bfd/elfxx-tilegx.c
@@ -2578,7 +2578,7 @@ tilegx_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 	  /* Strip this section if we don't need it; see the
 	     comment below.  */
 	}
-      else if (strncmp (s->name, ".rela", 5) == 0)
+      else if (startswith (s->name, ".rela"))
 	{
 	  if (s->size != 0)
 	    {
diff --git a/bfd/opncls.c b/bfd/opncls.c
index 26faaa6c9a9..74df4c2f518 100644
--- a/bfd/opncls.c
+++ b/bfd/opncls.c
@@ -1904,7 +1904,7 @@ get_build_id (bfd *abfd)
   if (inote.descsz <= 0
       || inote.type != NT_GNU_BUILD_ID
       || inote.namesz != 4 /* sizeof "GNU"  */
-      || strncmp (inote.namedata, "GNU", 4) != 0
+      || !startswith (inote.namedata, "GNU")
       || inote.descsz > 0x7ffffffe
       || size < (12 + BFD_ALIGN (inote.namesz, 4) + inote.descsz))
     {
diff --git a/binutils/dllwrap.c b/binutils/dllwrap.c
index bd65b98fee0..bc7104de004 100644
--- a/binutils/dllwrap.c
+++ b/binutils/dllwrap.c
@@ -840,11 +840,11 @@ Creating one, but that may not be what you want"));
   else
     which_target = UNKNOWN_TARGET;
 
-  if (! strncmp (target, "arm", 3))
+  if (startswith (target, "arm"))
     which_cpu = ARM_CPU;
-  else if (!strncmp (target, "x86_64", 6)
-	   || !strncmp (target, "athlon64", 8)
-	   || !strncmp (target, "amd64", 5))
+  else if (startswith (target, "x86_64")
+	   || startswith (target, "athlon64")
+	   || startswith (target, "amd64"))
     which_cpu = X64_CPU;
   else if (target[0] == 'i' && (target[1] >= '3' && target[1] <= '6')
 	   && target[2] == '8' && target[3] == '6')
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 092bc9e668a..6622adc5e7c 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -1285,7 +1285,7 @@ is_dwo_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
   if (len < 5)
     return false;
 
-  return strncmp (name + len - 4, ".dwo", 4) == 0;
+  return startswith (name + len - 4, ".dwo");
 }
 
 /* Return TRUE if section SEC is in the update list.  */
@@ -4261,7 +4261,7 @@ static void
 handle_remove_section_option (const char *section_pattern)
 {
   find_section_list (section_pattern, true, SECTION_CONTEXT_REMOVE);
-  if (strncmp (section_pattern, ".rel", 4) == 0)
+  if (startswith (section_pattern, ".rel"))
     {
       section_pattern += 4;
       if (*section_pattern == 'a')
@@ -5875,15 +5875,15 @@ copy_main (int argc, char *argv[])
 
   /* Convert input EFI target to PEI target.  */
   if (input_target != NULL
-      && strncmp (input_target, "efi-", 4) == 0)
+      && startswith (input_target, "efi-"))
     {
       char *efi;
 
       efi = xstrdup (output_target + 4);
-      if (strncmp (efi, "bsdrv-", 6) == 0
-	  || strncmp (efi, "rtdrv-", 6) == 0)
+      if (startswith (efi, "bsdrv-")
+	  || startswith (efi, "rtdrv-"))
 	efi += 2;
-      else if (strncmp (efi, "app-", 4) != 0)
+      else if (!startswith (efi, "app-"))
 	fatal (_("unknown input EFI target: %s"), input_target);
 
       input_target = efi;
@@ -5892,23 +5892,23 @@ copy_main (int argc, char *argv[])
 
   /* Convert output EFI target to PEI target.  */
   if (output_target != NULL
-      && strncmp (output_target, "efi-", 4) == 0)
+      && startswith (output_target, "efi-"))
     {
       char *efi;
 
       efi = xstrdup (output_target + 4);
-      if (strncmp (efi, "app-", 4) == 0)
+      if (startswith (efi, "app-"))
 	{
 	  if (pe_subsystem == -1)
 	    pe_subsystem = IMAGE_SUBSYSTEM_EFI_APPLICATION;
 	}
-      else if (strncmp (efi, "bsdrv-", 6) == 0)
+      else if (startswith (efi, "bsdrv-"))
 	{
 	  if (pe_subsystem == -1)
 	    pe_subsystem = IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER;
 	  efi += 2;
 	}
-      else if (strncmp (efi, "rtdrv-", 6) == 0)
+      else if (startswith (efi, "rtdrv-"))
 	{
 	  if (pe_subsystem == -1)
 	    pe_subsystem = IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER;
diff --git a/binutils/objdump.c b/binutils/objdump.c
index bffd7441eba..cbbec81c026 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -821,7 +821,7 @@ slurp_dynamic_symtab (bfd *abfd)
 static bool
 is_significant_symbol_name (const char * name)
 {
-  return strncmp (name, ".plt", 4) == 0 || strcmp (name, ".got") == 0;
+  return startswith (name, ".plt") || startswith (name, ".got");
 }
 
 /* Filter out (in place) symbols that are useless for disassembly.
-- 
2.30.2
H.J. Lu via Binutils April 1, 2021, 12:47 p.m. | #2
On Thu, Apr 01, 2021 at 07:21:32AM +0200, Martin Liška wrote:
> --- a/gas/config/obj-elf.c

> +++ b/gas/config/obj-elf.c

> @@ -2508,7 +2508,7 @@ adjust_stab_sections (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED)

>    char *p;

>    int strsz, nsyms;

>  

> -  if (strncmp (".stab", sec->name, 5))

> +  if (!startswith (".stab", sec->name))

>      return;


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

> --- a/gas/config/obj-macho.c

> +++ b/gas/config/obj-macho.c

> @@ -1907,8 +1907,8 @@ obj_mach_o_is_frame_section (segT sec)

>  {

>    int l;

>    l = strlen (segment_name (sec));

> -  if ((l == 9 && strncmp (".eh_frame", segment_name (sec), 9) == 0)

> -       || (l == 12 && strncmp (".debug_frame", segment_name (sec), 12) == 0))

> +  if ((l == 9 && startswith (".eh_frame", segment_name (sec)))

> +       || (l == 12 && startswith (".debug_frame", segment_name (sec))))


Here too.  OK with those tweaks, thanks!

-- 
Alan Modra
Australia Development Lab, IBM
Martin Liška April 1, 2021, 1:03 p.m. | #3
On 4/1/21 2:47 PM, Alan Modra wrote:
> Here too.  OK with those tweaks, thanks!


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

Martin