bfd: Output error for linker --fatal-warnings option

Message ID 20240125201102.1998061-1-hjl.tools@gmail.com
State Dropped
Headers
Series bfd: Output error for linker --fatal-warnings option |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 fail Testing failed
linaro-tcwg-bot/tcwg_binutils_check--master-arm fail Testing failed

Commit Message

H.J. Lu Jan. 25, 2024, 8:11 p.m. UTC
  Update _bfd_error_handler to output the warning prefix, which is default
to "warning".  Add %%w to _bfd_doprnt to output "error", instead of
"warning", when --fatal-warnings is used.  Update bfd_set_error_handler
to allow linker to set the warning prefix to "error" for --fatal-warnings.

bfd/

	* archive.c (_bfd_write_archive_contents): Pass %%w, instead of
	"warning", to _bfd_error_handler.
	* binary.c (binary_set_section_contents): Likewise.
	* coff-arm.c (coff_arm_relocate_section): Likewise.
	(coff_arm_merge_private_bfd_data): Likewise.
	(_bfd_coff_arm_set_private_flags): Likewise.
	(coff_arm_copy_private_bfd_data): Likewise.
	* coff-go32.c (_bfd_go32_swap_scnhdr_out): Likewise.
	* coff-mcore.c (coff_mcore_relocate_section): Likewise.
	* coff-sh.c (sh_relax_section): Likewise.
	* coff-tic30.c (reloc_processing): Likewise.
	* coff-tic4x.c (tic4x_reloc_processing): Likewise.
	* coff-tic54x.c (tic54x_reloc_processing): Likewise.
	* coff-z80.c (reloc_processing): Likewise.
	* coff-z8k.c (reloc_processing): Likewise.
	* coffcode.h (fill_comdat_hash): Likewise.
	(handle_COMDAT): Likewise.
	(styp_to_sec_flags): Likewise.
	(coff_set_alignment_hook): Likewise.
	(coff_write_object_contents): Likewise.
	(coff_slurp_line_table): Likewise.
	(coff_classify_symbol): Likewise.
	(coff_slurp_reloc_table): Likewise.
	* coffgen.c (coff_write_symbols): Likewise.
	(bfd_coff_gc_sections): Likewise.
	* cofflink.c (coff_link_add_symbols): Likewise.
	(_bfd_coff_write_global_sym): Likewise.
	* coffswap.h (coff_swap_scnhdr_out): Likewise.
	* cpu-arm.c (bfd_arm_update_notes): Likewise.
	* cpu-m68k.c (bfd_m68k_compatible): Likewise.
	* ecoff.c (_bfd_ecoff_slurp_symbol_table): Likewise.
	* elf-properties.c (_bfd_elf_parse_gnu_properties): Likewise.
	* elf-s390-common.c (elf_s390_merge_obj_attributes): Likewise.
	* elf.c (bfd_section_from_shdr): Likewise.
	(elf_fake_sections): Likewise.
	(assign_file_positions_for_non_load_sections): Likewise.
	(assign_file_positions_except_relocs): Likewise.
	(rewrite_elf_program_header): Likewise.
	(copy_private_bfd_data): Likewise.
	(elfcore_grok_win32pstatus): Likewise.
	* elf32-arc.c (arc_elf_merge_attributes): Likewise.
	(arc_elf_object_p): Likewise.
	(elf_arc_relocate_section): Likewise.
	(elf32_arc_obj_attrs_handle_unknown): Likewise.
	* elf32-arm.c (arm_type_of_stub): Likewise.
	(bfd_elf32_arm_set_vfp11_fix): Likewise.
	(bfd_elf32_arm_set_stm32l4xx_fix): Likewise.
	(elf32_thumb_to_arm_stub): Likewise.
	(elf32_arm_create_thumb_stub): Likewise.
	(elf32_arm_populate_plt_entry): Likewise.
	(elf32_arm_final_link_relocate): Likewise.
	(elf32_arm_set_private_flags): Likewise.
	(elf32_arm_copy_private_bfd_data): Likewise.
	(elf32_arm_obj_attrs_handle_unknown): Likewise.
	(elf32_arm_merge_eabi_attributes): Likewise.
	(elf32_arm_merge_private_bfd_data): Likewise.
	* elf32-bfin.c (bfinfdpic_relocate_section): Likewise.
	* elf32-csky.c (csky_find_arch_with_eflag): Likewise.
	(csky_find_arch_with_name): Likewise.
	(elf32_csky_merge_attributes): Likewise.
	(csky_elf_merge_private_bfd_data): Likewise.
	* elf32-msp430.c (elf32_msp430_obj_attrs_handle_unknown):
	Likewise.
	* elf32-nds32.c (nds32_elf_relocate_section): Likewise.
	(nds32_elf_merge_private_bfd_data): Likewise.
	(relax_range_measurement): Likewise.
	* elf32-ppc.c (ppc_elf_begin_write_processing): Likewise.
	(ppc_elf_tls_optimize): Likewise.
	* elf32-rl78.c (rl78_elf_relocate_section): Likewise.
	* elf32-rx.c (rx_elf_relocate_section): Likewise.
	* elf32-score.c (s3_elf32_score_merge_private_bfd_data):
	Likewise.
	* elf32-score7.c (s7_elf32_score_merge_private_bfd_data):
	Likewise.
	* elf32-sh.c (sh_elf_relax_section): Likewise.
	* elf32-spu.c (needs_ovl_stub): Likewise.
	* elf32-tic6x.c (elf32_tic6x_final_link): Likewise.
	(elf32_tic6x_obj_attrs_handle_unknown): Likewise.
	(elf32_tic6x_merge_attributes): Likewise.
	* elf32-v850.c (v850_elf_relax_section): Likewise.
	* elf32-vax.c (elf_vax_check_relocs): Likewise.
	* elf64-alpha.c (elf64_alpha_relax_got_load): Likewise.
	(elf64_alpha_relax_with_lituse): Likewise.
	* elf64-ia64-vms.c (elf64_vms_link_add_object_symbols): Likewise.
	* elf64-ppc.c (ppc64_elf_reloc_name_lookup): Likewise.
	(ppc64_elf_tls_setup): Likewise.
	(ppc64_elf_tls_optimize): Likewise.
	(ppc64_elf_size_dynamic_sections): Likewise.
	* elfcode.h (elf_swap_shdr_in): Likewise.
	(elf_object_p): Likewise.
	* elfcore.h (elf_core_file_p): Likewise.
	* elflink.c (_bfd_elf_adjust_dynamic_symbol): Likewise.
	(bfd_elf_size_dynamic_sections): Likewise.
	(bfd_elf_final_link): Likewise.
	(bfd_elf_gc_sections): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_merge_gnu_properties): Likewise.
	* elfnn-loongarch.c (loongarch_reloc_is_fatal): Likewise.
	* elfnn-riscv.c (riscv_make_plt_header): Likewise.
	(riscv_make_plt_entry): Likewise.
	(riscv_elf_relocate_section): Likewise.
	(riscv_merge_attributes): Likewise.
	* elfxx-aarch64.c (_bfd_aarch64_elf_resolve_relocation):
	Likewise.
	(_bfd_aarch64_elf_link_setup_gnu_properties): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_section_processing): Likewise.
	(_bfd_mips_elf_section_from_shdr): Likewise.
	(_bfd_mips_elf_check_relocs): Likewise.
	(mips_elf_merge_obj_e_flags): Likewise.
	(mips_elf_merge_obj_attributes): Likewise.
	(_bfd_mips_elf_merge_private_bfd_data): Likewise.
	* mmo.c (mmo_write_symbols_and_terminator): Likewise.
	* xcofflink.c (xcoff_build_ldsym): Likewise.
	* bfd.c (warning_prefix): New.
	(_bfd_doprnt): Initialize warning_prefix to _("warning").  Print
	warning_prefix for %%w.
	(bfd_set_error_handler): Add a const char * argument to set
	warning_prefix if it isn't NULL.
	(_bfd_set_error_handler_caching): Pass NULL to
	bfd_set_error_handler.
	* format.c (bfd_check_format_matches): Likewise.
	* bfd-in2.h: Regenerated.

ld/

	* ldlang.c (lang_check): Pass NULL to bfd_set_error_handler.
	* ldmain.c (main): Pass _("error") or NULL to
	bfd_set_error_handler, depending on if --fatal-warnings is used.
	* testsuite/ld-elf/fatal-warnings-5.d: New file.
	* testsuite/ld-scripts/defined.exp: Run defined7.
	* testsuite/ld-scripts/defined7.d: New file.
---
 bfd/archive.c                          |  2 +-
 bfd/bfd-in2.h                          |  3 +-
 bfd/bfd.c                              | 34 +++++++++++++++-----
 bfd/binary.c                           |  2 +-
 bfd/coff-arm.c                         | 14 ++++----
 bfd/coff-go32.c                        |  2 +-
 bfd/coff-mcore.c                       |  2 +-
 bfd/coff-sh.c                          | 14 ++++----
 bfd/coff-tic30.c                       |  2 +-
 bfd/coff-tic4x.c                       |  2 +-
 bfd/coff-tic54x.c                      |  2 +-
 bfd/coff-z80.c                         |  2 +-
 bfd/coff-z8k.c                         |  2 +-
 bfd/coffcode.h                         | 26 +++++++--------
 bfd/coffgen.c                          |  7 ++--
 bfd/cofflink.c                         |  6 ++--
 bfd/coffswap.h                         |  2 +-
 bfd/cpu-arm.c                          |  2 +-
 bfd/cpu-m68k.c                         |  2 +-
 bfd/ecoff.c                            |  2 +-
 bfd/elf-properties.c                   | 10 +++---
 bfd/elf-s390-common.c                  |  6 ++--
 bfd/elf.c                              | 24 +++++++-------
 bfd/elf32-arc.c                        |  8 ++---
 bfd/elf32-arm.c                        | 44 +++++++++++++-------------
 bfd/elf32-bfin.c                       |  2 +-
 bfd/elf32-csky.c                       |  8 ++---
 bfd/elf32-msp430.c                     |  2 +-
 bfd/elf32-nds32.c                      | 18 +++++------
 bfd/elf32-ppc.c                        |  4 +--
 bfd/elf32-rl78.c                       |  2 +-
 bfd/elf32-rx.c                         |  6 ++--
 bfd/elf32-score.c                      |  2 +-
 bfd/elf32-score7.c                     |  2 +-
 bfd/elf32-sh.c                         | 14 ++++----
 bfd/elf32-spu.c                        |  2 +-
 bfd/elf32-tic6x.c                      | 10 +++---
 bfd/elf32-v850.c                       | 14 ++++----
 bfd/elf32-vax.c                        |  8 ++---
 bfd/elf64-alpha.c                      |  4 +--
 bfd/elf64-ia64-vms.c                   |  8 ++---
 bfd/elf64-ppc.c                        | 10 +++---
 bfd/elfcode.h                          |  6 ++--
 bfd/elfcore.h                          |  2 +-
 bfd/elflink.c                          | 26 +++++++--------
 bfd/elfnn-aarch64.c                    |  4 +--
 bfd/elfnn-loongarch.c                  |  2 +-
 bfd/elfnn-riscv.c                      | 10 +++---
 bfd/elfxx-aarch64.c                    |  4 +--
 bfd/elfxx-mips.c                       | 34 ++++++++++----------
 bfd/format.c                           |  7 ++--
 bfd/mmo.c                              |  2 +-
 bfd/xcofflink.c                        |  2 +-
 ld/ldlang.c                            |  4 +--
 ld/ldmain.c                            |  5 ++-
 ld/testsuite/ld-elf/fatal-warnings-5.d |  6 ++++
 ld/testsuite/ld-scripts/defined.exp    |  1 +
 ld/testsuite/ld-scripts/defined7.d     |  3 ++
 58 files changed, 245 insertions(+), 211 deletions(-)
 create mode 100644 ld/testsuite/ld-elf/fatal-warnings-5.d
 create mode 100644 ld/testsuite/ld-scripts/defined7.d
  

Patch

diff --git a/bfd/archive.c b/bfd/archive.c
index 9f3fbce9bc9..16c465261c6 100644
--- a/bfd/archive.c
+++ b/bfd/archive.c
@@ -2291,7 +2291,7 @@  _bfd_write_archive_contents (bfd *arch)
 	  if (bfd_update_armap_timestamp (arch))
 	    break;
 	  _bfd_error_handler
-	    (_("warning: writing archive was slow: rewriting timestamp"));
+	    (_("%%w: writing archive was slow: rewriting timestamp"));
 	}
       while (++tries < 6);
     }
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 581d8fe0b3e..0ca7db6ba5f 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -2559,7 +2559,8 @@  typedef void (*bfd_error_handler_type) (const char *, va_list);
 
 void _bfd_error_handler (const char *fmt, ...) ATTRIBUTE_PRINTF_1;
 
-bfd_error_handler_type bfd_set_error_handler (bfd_error_handler_type);
+bfd_error_handler_type bfd_set_error_handler
+   (bfd_error_handler_type, const char *);
 
 void bfd_set_error_program_name (const char *);
 
diff --git a/bfd/bfd.c b/bfd/bfd.c
index 0776145af52..e65b1522d71 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -964,6 +964,9 @@  CODE_FRAGMENT
 
 static const char *_bfd_error_program_name;
 
+/* warning: or error:  */
+static const char *warning_prefix = NULL;
+
 /* Support for positional parameters.  */
 
 union _bfd_doprnt_args
@@ -1011,6 +1014,9 @@  _bfd_doprnt (print_func print, void *stream, const char *format,
   int total_printed = 0;
   unsigned int arg_count = 0;
 
+  if (warning_prefix == NULL)
+    warning_prefix = _("warning");
+
   while (*ptr != '\0')
     {
       int result;
@@ -1027,9 +1033,18 @@  _bfd_doprnt (print_func print, void *stream, const char *format,
 	}
       else if (ptr[1] == '%')
 	{
-	  fputc ('%', stream);
-	  result = 1;
-	  ptr += 2;
+	  if (ptr[2] == 'w')
+	    {
+	      /* Print warning_prefix for %%w.  */
+	      result = print (stream, "%s", warning_prefix);
+	      ptr += 3;
+	    }
+	  else
+	    {
+	      fputc ('%', stream);
+	      result = 1;
+	      ptr += 2;
+	    }
 	}
       else
 	{
@@ -1575,20 +1590,23 @@  FUNCTION
 	bfd_set_error_handler
 
 SYNOPSIS
-	bfd_error_handler_type bfd_set_error_handler (bfd_error_handler_type);
+	bfd_error_handler_type bfd_set_error_handler
+	  (bfd_error_handler_type, const char *);
 
 DESCRIPTION
-	Set the BFD error handler function.  Returns the previous
-	function.
+	Set the BFD error handler function and the warning prefix.
+	Returns the previous function.
 */
 
 bfd_error_handler_type
-bfd_set_error_handler (bfd_error_handler_type pnew)
+bfd_set_error_handler (bfd_error_handler_type pnew, const char *prefix)
 {
   bfd_error_handler_type pold;
 
   pold = _bfd_error_internal;
   _bfd_error_internal = pnew;
+  if (prefix != NULL)
+    warning_prefix = prefix;
   return pold;
 }
 
@@ -1608,7 +1626,7 @@  bfd_error_handler_type
 _bfd_set_error_handler_caching (bfd *abfd)
 {
   error_handler_bfd = abfd;
-  return bfd_set_error_handler (error_handler_sprintf);
+  return bfd_set_error_handler (error_handler_sprintf, NULL);
 }
 
 /*
diff --git a/bfd/binary.c b/bfd/binary.c
index a99d5d8f587..cef70e24993 100644
--- a/bfd/binary.c
+++ b/bfd/binary.c
@@ -274,7 +274,7 @@  binary_set_section_contents (bfd *abfd,
 	  if (s->filepos < 0)
 	    _bfd_error_handler
 	      /* xgettext:c-format */
-	      (_("warning: writing section `%pA' at huge (ie negative) "
+	      (_("%%w: writing section `%pA' at huge (ie negative) "
 		 "file offset"),
 	       s);
 	}
diff --git a/bfd/coff-arm.c b/bfd/coff-arm.c
index d4d129f7d47..a92e85040f4 100644
--- a/bfd/coff-arm.c
+++ b/bfd/coff-arm.c
@@ -1369,7 +1369,7 @@  coff_arm_relocate_section (bfd *output_bfd,
 			      && ! INTERWORK_FLAG (h_sec->owner))
 			    _bfd_error_handler
 			      /* xgettext:c-format */
-			      (_("%pB(%s): warning: interworking not enabled; "
+			      (_("%pB(%s): %%w: interworking not enabled; "
 				 "first occurrence: %pB: arm call to thumb"),
 			       h_sec->owner, name, input_bfd);
 
@@ -1459,7 +1459,7 @@  coff_arm_relocate_section (bfd *output_bfd,
 			      && ! globals->support_old_code)
 			    _bfd_error_handler
 			      /* xgettext:c-format */
-			      (_("%pB(%s): warning: interworking not enabled; "
+			      (_("%pB(%s): %%w: interworking not enabled; "
 				 "first occurrence: %pB: thumb call to arm; "
 				 "consider relinking with --support-old-code "
 				 "enabled"),
@@ -2277,13 +2277,13 @@  coff_arm_merge_private_bfd_data (bfd * ibfd, struct bfd_link_info *info)
 	    {
 	      if (INTERWORK_FLAG (ibfd))
 		/* xgettext: c-format */
-		_bfd_error_handler (_("warning: %pB supports interworking, "
+		_bfd_error_handler (_("%%w: %pB supports interworking, "
 				      "whereas %pB does not"),
 				    ibfd, obfd);
 	      else
 		/* xgettext: c-format */
 		_bfd_error_handler
-		  (_("warning: %pB does not support interworking, "
+		  (_("%%w: %pB does not support interworking, "
 		     "whereas %pB does"),
 		   ibfd, obfd);
 	    }
@@ -2374,10 +2374,10 @@  _bfd_coff_arm_set_private_flags (bfd * abfd, flagword flags)
   if (INTERWORK_SET (abfd) && (INTERWORK_FLAG (abfd) != flag))
     {
       if (flag)
-	_bfd_error_handler (_("warning: not setting interworking flag of %pB since it has already been specified as non-interworking"),
+	_bfd_error_handler (_("%%w: not setting interworking flag of %pB since it has already been specified as non-interworking"),
 			    abfd);
       else
-	_bfd_error_handler (_("warning: clearing the interworking flag of %pB due to outside request"),
+	_bfd_error_handler (_("%%w: clearing the interworking flag of %pB due to outside request"),
 			    abfd);
       flag = 0;
     }
@@ -2435,7 +2435,7 @@  coff_arm_copy_private_bfd_data (bfd * src, bfd * dest)
 		{
 		  /* xgettext:c-format */
 		  _bfd_error_handler
-		    (_("warning: clearing the interworking flag of %pB "
+		    (_("%%w: clearing the interworking flag of %pB "
 		       "because non-interworking code in %pB has been "
 		       "linked with it"),
 		     dest, src);
diff --git a/bfd/coff-go32.c b/bfd/coff-go32.c
index 278d1441073..0668221bd10 100644
--- a/bfd/coff-go32.c
+++ b/bfd/coff-go32.c
@@ -164,7 +164,7 @@  _bfd_go32_swap_scnhdr_out (bfd * abfd, void * in, void * out)
 	  buf[sizeof (scnhdr_int->s_name)] = '\0';
 	  _bfd_error_handler
 	    /* xgettext:c-format */
-	    (_("%pB: warning: %s: line number overflow: 0x%lx > 0xffff"),
+	    (_("%pB: %%w: %s: line number overflow: 0x%lx > 0xffff"),
 	     abfd, buf, scnhdr_int->s_nlnno);
 	  bfd_set_error (bfd_error_file_truncated);
 	  PUT_SCNHDR_NLNNO (abfd, 0xffff, scnhdr_ext->s_nlnno);
diff --git a/bfd/coff-mcore.c b/bfd/coff-mcore.c
index 23d1e640159..aff9ffdcdcf 100644
--- a/bfd/coff-mcore.c
+++ b/bfd/coff-mcore.c
@@ -483,7 +483,7 @@  coff_mcore_relocate_section (bfd * output_bfd,
 	case IMAGE_REL_MCORE_ABSOLUTE:
 	  _bfd_error_handler
 	    /* xgettext: c-format */
-	    (_("warning: unsupported reloc %s <file %pB, section %pA>\n"
+	    (_("%%w: unsupported reloc %s <file %pB, section %pA>\n"
 	       "sym %ld (%s), r_vaddr %" PRId64 " (%#" PRIx64 ")"),
 	     howto->name, input_bfd, input_section,
 	     rel->r_symndx, my_name, (int64_t) rel->r_vaddr,
diff --git a/bfd/coff-sh.c b/bfd/coff-sh.c
index b37a80a2a54..ce9100ae925 100644
--- a/bfd/coff-sh.c
+++ b/bfd/coff-sh.c
@@ -778,7 +778,7 @@  sh_relax_section (bfd *abfd,
 	{
 	  /* xgettext: c-format */
 	  _bfd_error_handler
-	    (_("%pB: %#" PRIx64 ": warning: bad R_SH_USES offset"),
+	    (_("%pB: %#" PRIx64 ": %%w: bad R_SH_USES offset"),
 	     abfd, (uint64_t) irel->r_vaddr);
 	  continue;
 	}
@@ -789,7 +789,7 @@  sh_relax_section (bfd *abfd,
 	{
 	  _bfd_error_handler
 	    /* xgettext: c-format */
-	    (_("%pB: %#" PRIx64 ": warning: R_SH_USES points to unrecognized insn %#x"),
+	    (_("%pB: %#" PRIx64 ": %%w: R_SH_USES points to unrecognized insn %#x"),
 	     abfd, (uint64_t) irel->r_vaddr, insn);
 	  continue;
 	}
@@ -807,7 +807,7 @@  sh_relax_section (bfd *abfd,
 	{
 	  _bfd_error_handler
 	    /* xgettext: c-format */
-	    (_("%pB: %#" PRIx64 ": warning: bad R_SH_USES load offset"),
+	    (_("%pB: %#" PRIx64 ": %%w: bad R_SH_USES load offset"),
 	     abfd, (uint64_t) irel->r_vaddr);
 	  continue;
 	}
@@ -832,7 +832,7 @@  sh_relax_section (bfd *abfd,
 	{
 	  _bfd_error_handler
 	    /* xgettext: c-format */
-	    (_("%pB: %#" PRIx64 ": warning: could not find expected reloc"),
+	    (_("%pB: %#" PRIx64 ": %%w: could not find expected reloc"),
 	     abfd, (uint64_t) paddr);
 	  continue;
 	}
@@ -849,7 +849,7 @@  sh_relax_section (bfd *abfd,
 	{
 	  _bfd_error_handler
 	    /* xgettext: c-format */
-	    (_("%pB: %#" PRIx64 ": warning: symbol in unexpected section"),
+	    (_("%pB: %#" PRIx64 ": %%w: symbol in unexpected section"),
 	     abfd, (uint64_t) paddr);
 	  continue;
 	}
@@ -970,7 +970,7 @@  sh_relax_section (bfd *abfd,
 	{
 	  _bfd_error_handler
 	    /* xgettext: c-format */
-	    (_("%pB: %#" PRIx64 ": warning: could not find expected COUNT reloc"),
+	    (_("%pB: %#" PRIx64 ": %%w: could not find expected COUNT reloc"),
 	     abfd, (uint64_t) paddr);
 	  continue;
 	}
@@ -980,7 +980,7 @@  sh_relax_section (bfd *abfd,
       if (irelcount->r_offset == 0)
 	{
 	  /* xgettext: c-format */
-	  _bfd_error_handler (_("%pB: %#" PRIx64 ": warning: bad count"),
+	  _bfd_error_handler (_("%pB: %#" PRIx64 ": %%w: bad count"),
 			      abfd, (uint64_t) paddr);
 	  continue;
 	}
diff --git a/bfd/coff-tic30.c b/bfd/coff-tic30.c
index deca0a48feb..6cb6737b371 100644
--- a/bfd/coff-tic30.c
+++ b/bfd/coff-tic30.c
@@ -169,7 +169,7 @@  reloc_processing (arelent *relent,
     {
       _bfd_error_handler
 	/* xgettext:c-format */
-	(_("%pB: warning: illegal symbol index %ld in relocs"),
+	(_("%pB: %%w: illegal symbol index %ld in relocs"),
 	 abfd, reloc->r_symndx);
       relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
     }
diff --git a/bfd/coff-tic4x.c b/bfd/coff-tic4x.c
index 8d70b465724..809c9c69fb3 100644
--- a/bfd/coff-tic4x.c
+++ b/bfd/coff-tic4x.c
@@ -225,7 +225,7 @@  tic4x_reloc_processing (arelent *relent,
 	{
 	  _bfd_error_handler
 	    /* xgettext: c-format */
-	    (_("%pB: warning: illegal symbol index %ld in relocs"),
+	    (_("%pB: %%w: illegal symbol index %ld in relocs"),
 	     abfd, reloc->r_symndx);
 	  relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
 	  ptr = NULL;
diff --git a/bfd/coff-tic54x.c b/bfd/coff-tic54x.c
index 424a3b13654..821518cf11b 100644
--- a/bfd/coff-tic54x.c
+++ b/bfd/coff-tic54x.c
@@ -335,7 +335,7 @@  tic54x_reloc_processing (arelent *relent,
 	{
 	  _bfd_error_handler
 	    /* xgettext: c-format */
-	    (_("%pB: warning: illegal symbol index %ld in relocs"),
+	    (_("%pB: %%w: illegal symbol index %ld in relocs"),
 	     abfd, reloc->r_symndx);
 	  relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
 	  ptr = NULL;
diff --git a/bfd/coff-z80.c b/bfd/coff-z80.c
index fd33b5a758f..c8f49c3b4b3 100644
--- a/bfd/coff-z80.c
+++ b/bfd/coff-z80.c
@@ -322,7 +322,7 @@  reloc_processing (arelent *relent,
     {
       _bfd_error_handler
 	/* xgettext:c-format */
-	(_("%pB: warning: illegal symbol index %ld in relocs"),
+	(_("%pB: %%w: illegal symbol index %ld in relocs"),
 	 abfd, reloc->r_symndx);
       relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
     }
diff --git a/bfd/coff-z8k.c b/bfd/coff-z8k.c
index 0b4e3b63aaf..c0c59dc87fe 100644
--- a/bfd/coff-z8k.c
+++ b/bfd/coff-z8k.c
@@ -185,7 +185,7 @@  reloc_processing (arelent *relent,
     {
       _bfd_error_handler
 	/* xgettext:c-format */
-	(_("%pB: warning: illegal symbol index %ld in relocs"),
+	(_("%pB: %%w: illegal symbol index %ld in relocs"),
 	 abfd, reloc->r_symndx);
       relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
     }
diff --git a/bfd/coffcode.h b/bfd/coffcode.h
index 4170b630b4d..264544aa556 100644
--- a/bfd/coffcode.h
+++ b/bfd/coffcode.h
@@ -973,7 +973,7 @@  fill_comdat_hash (bfd *abfd)
 	      if (esym + isym.n_numaux * bfd_coff_symesz (abfd) >= esymend)
 		{
 		  /* xgettext:c-format */
-		  _bfd_error_handler (_("%pB: warning: no symbol for"
+		  _bfd_error_handler (_("%pB: %%w: no symbol for"
 					" section '%s' found"),
 				      abfd, symname);
 		  continue;
@@ -1156,7 +1156,7 @@  handle_COMDAT (bfd *abfd, flagword *sec_flags, const char *name,
 
       if (isym.n_sclass == C_STAT && strcmp (name, found->symname) != 0)
 	/* xgettext:c-format */
-	_bfd_error_handler (_("%pB: warning: COMDAT symbol '%s'"
+	_bfd_error_handler (_("%pB: %%w: COMDAT symbol '%s'"
 			      " does not match section name '%s'"),
 			    abfd, found->symname, name);
 
@@ -1264,7 +1264,7 @@  styp_to_sec_flags (bfd *abfd,
 	     variable as this will allow some .sys files generate by
 	     other toolchains to be processed.  See bugzilla issue 196.  */
 	  /* xgettext:c-format */
-	  _bfd_error_handler (_("%pB: warning: ignoring section flag"
+	  _bfd_error_handler (_("%pB: %%w: ignoring section flag"
 				" %s in section %s"),
 			      abfd, "IMAGE_SCN_MEM_NOT_PAGED", name);
 	  break;
@@ -1960,7 +1960,7 @@  coff_set_alignment_hook (bfd * abfd ATTRIBUTE_UNUSED,
     }
   else if (hdr->s_nreloc == 0xffff)
     _bfd_error_handler
-      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
+      (_("%pB: %%w: claims to have 0xffff relocs, without overflow"),
        abfd);
 }
 #undef ALIGN_SET
@@ -2025,7 +2025,7 @@  coff_set_alignment_hook (bfd * abfd, asection * section, void * scnhdr)
     }
   else if (hdr->s_nreloc == 0xffff)
     _bfd_error_handler
-      (_("%pB: warning: claims to have 0xffff relocs, without overflow"),
+      (_("%pB: %%w: claims to have 0xffff relocs, without overflow"),
        abfd);
 }
 
@@ -3789,7 +3789,7 @@  coff_write_object_contents (bfd * abfd)
 	  _bfd_error_handler
 	    /* xgettext:c-format */
 	    (_("%pB:%s section %s: alignment 2**%u not representable"),
-	     abfd, warn ? " warning:" : "", current->name,
+	     abfd, warn ? " %%w:" : "", current->name,
 	     current->alignment_power);
 	  if (!warn)
 	    {
@@ -4529,7 +4529,7 @@  coff_slurp_line_table (bfd *abfd, asection *asect)
   if (native_lineno == NULL)
     {
       _bfd_error_handler
-	(_("%pB: warning: line number table read failed"), abfd);
+	(_("%pB: %%w: line number table read failed"), abfd);
       return false;
     }
 
@@ -4575,7 +4575,7 @@  coff_slurp_line_table (bfd *abfd, asection *asect)
 	    {
 	      _bfd_error_handler
 		/* xgettext:c-format */
-		(_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
+		(_("%pB: %%w: illegal symbol index 0x%lx in line number entry %d"),
 		 abfd, symndx, counter);
 	      cache_ptr->line_number = -1;
 	      ret = false;
@@ -4589,7 +4589,7 @@  coff_slurp_line_table (bfd *abfd, asection *asect)
 	    {
 	      _bfd_error_handler
 		/* xgettext:c-format */
-		(_("%pB: warning: illegal symbol index 0x%lx in line number entry %d"),
+		(_("%pB: %%w: illegal symbol index 0x%lx in line number entry %d"),
 		 abfd, symndx, counter);
 	      cache_ptr->line_number = -1;
 	      ret = false;
@@ -4603,7 +4603,7 @@  coff_slurp_line_table (bfd *abfd, asection *asect)
 	    {
 	      _bfd_error_handler
 		/* xgettext:c-format */
-		(_("%pB: warning: illegal symbol in line number entry %d"),
+		(_("%pB: %%w: illegal symbol in line number entry %d"),
 		 abfd, counter);
 	      cache_ptr->line_number = -1;
 	      ret = false;
@@ -4616,7 +4616,7 @@  coff_slurp_line_table (bfd *abfd, asection *asect)
 	  if (sym->lineno != NULL)
 	    _bfd_error_handler
 	      /* xgettext:c-format */
-	      (_("%pB: warning: duplicate line number information for `%s'"),
+	      (_("%pB: %%w: duplicate line number information for `%s'"),
 	       abfd, bfd_asymbol_name (&sym->symbol));
 
 	  sym->lineno = cache_ptr;
@@ -5180,7 +5180,7 @@  coff_classify_symbol (bfd *abfd,
 
       _bfd_error_handler
 	/* xgettext:c-format */
-	(_("warning: %pB: local symbol `%s' has no section"),
+	(_("%%w: %pB: local symbol `%s' has no section"),
 	 abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
     }
 
@@ -5311,7 +5311,7 @@  coff_slurp_reloc_table (bfd * abfd, sec_ptr asect, asymbol ** symbols)
 	    {
 	      _bfd_error_handler
 		/* xgettext:c-format */
-		(_("%pB: warning: illegal symbol index %ld in relocs"),
+		(_("%pB: %%w: illegal symbol index %ld in relocs"),
 		 abfd, dst.r_symndx);
 	      cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
 	      ptr = NULL;
diff --git a/bfd/coffgen.c b/bfd/coffgen.c
index cc1c655738b..1e7dc2b5f14 100644
--- a/bfd/coffgen.c
+++ b/bfd/coffgen.c
@@ -1424,11 +1424,12 @@  coff_write_symbols (bfd *abfd)
 		 Error messages can be generated when we are processing a local
 		 symbol which has no associated section and we do not have to
 		 worry about this, all we need to know is that it is local.  */
-	      current_error_handler = bfd_set_error_handler (null_error_handler);
+	      current_error_handler
+		= bfd_set_error_handler (null_error_handler, NULL);
 	      BFD_ASSERT (c_symbol->native->is_sym);
 	      sym_class = bfd_coff_classify_symbol (abfd,
 						    &c_symbol->native->u.syment);
-	      (void) bfd_set_error_handler (current_error_handler);
+	      (void) bfd_set_error_handler (current_error_handler, NULL);
 
 	      n_sclass = &c_symbol->native->u.syment.n_sclass;
 
@@ -3212,7 +3213,7 @@  bfd_coff_gc_sections (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *info)
   if (!bed->can_gc_sections
       || !is_coff_hash_table (info->hash))
     {
-      _bfd_error_handler(_("warning: gc-sections option ignored"));
+      _bfd_error_handler(_("%%w: gc-sections option ignored"));
       return true;
     }
 #endif
diff --git a/bfd/cofflink.c b/bfd/cofflink.c
index 4a91d5a1833..581375c7fbc 100644
--- a/bfd/cofflink.c
+++ b/bfd/cofflink.c
@@ -395,7 +395,7 @@  coff_link_add_symbols (bfd *abfd,
 		      && (*sym_hash)->root.type != bfd_link_hash_undefined
 		      && (*sym_hash)->root.type != bfd_link_hash_undefweak)
 		    _bfd_error_handler
-		      (_("warning: symbol `%s' is both section and non-section"),
+		      (_("%%w: symbol `%s' is both section and non-section"),
 		       name);
 
 		  addit = false;
@@ -500,7 +500,7 @@  coff_link_add_symbols (bfd *abfd,
 				   || BTYPE (sym.n_type) == T_NULL)))
 			_bfd_error_handler
 			  /* xgettext: c-format */
-			  (_("warning: type of symbol `%s' changed"
+			  (_("%%w: type of symbol `%s' changed"
 			     " from %d to %d in %pB"),
 			   name, (*sym_hash)->type, sym.n_type, abfd);
 
@@ -2721,7 +2721,7 @@  _bfd_coff_write_global_sym (struct bfd_hash_entry *bh, void *data)
 		      || bfd_link_relocatable (flaginfo->info)))
 		_bfd_error_handler
 		  /* xgettext: c-format */
-		  (_("%pB: warning: %pA: line number overflow: %#x > 0xffff"),
+		  (_("%pB: %%w: %pA: line number overflow: %#x > 0xffff"),
 		   output_bfd, sec, sec->lineno_count);
 
 	      auxp->x_scn.x_nreloc = sec->reloc_count;
diff --git a/bfd/coffswap.h b/bfd/coffswap.h
index eafdbbb078d..5ac3624f6cd 100644
--- a/bfd/coffswap.h
+++ b/bfd/coffswap.h
@@ -809,7 +809,7 @@  coff_swap_scnhdr_out (bfd * abfd, void * in, void * out)
       buf[sizeof (scnhdr_int->s_name)] = '\0';
       _bfd_error_handler
 	/* xgettext:c-format */
-	(_("%pB: warning: %s: line number overflow: 0x%lx > 0xffff"),
+	(_("%pB: %%w: %s: line number overflow: 0x%lx > 0xffff"),
 	 abfd, buf, scnhdr_int->s_nlnno);
       PUT_SCNHDR_NLNNO (abfd, 0xffff, scnhdr_ext->s_nlnno);
     }
diff --git a/bfd/cpu-arm.c b/bfd/cpu-arm.c
index 12a5b770593..caa90b4e2a4 100644
--- a/bfd/cpu-arm.c
+++ b/bfd/cpu-arm.c
@@ -466,7 +466,7 @@  bfd_arm_update_notes (bfd *abfd, const char *note_section)
 	{
 	  _bfd_error_handler
 	    /* xgettext: c-format */
-	    (_("warning: unable to update contents of %s section in %pB"),
+	    (_("%%w: unable to update contents of %s section in %pB"),
 	     note_section, abfd);
 	  goto FAIL;
 	}
diff --git a/bfd/cpu-m68k.c b/bfd/cpu-m68k.c
index 2626b712ba3..3498e0bde44 100644
--- a/bfd/cpu-m68k.c
+++ b/bfd/cpu-m68k.c
@@ -260,7 +260,7 @@  bfd_m68k_compatible (const bfd_arch_info_type *a,
 	  if (!cpu32_fido_mix_warning)
 	    {
 	      cpu32_fido_mix_warning = 1;
-	      _bfd_error_handler ("warning: linking CPU32 objects with fido objects");
+	      _bfd_error_handler ("%%w: linking CPU32 objects with fido objects");
 	    }
 	  return bfd_lookup_arch (a->arch,
 				  bfd_m68k_features_to_mach (fido_a | m68881));
diff --git a/bfd/ecoff.c b/bfd/ecoff.c
index 533ff1900c0..5586ca93531 100644
--- a/bfd/ecoff.c
+++ b/bfd/ecoff.c
@@ -1013,7 +1013,7 @@  _bfd_ecoff_slurp_symbol_table (bfd *abfd)
       abfd->symcount = internal_ptr - internal;
       _bfd_error_handler
 	/* xgettext:c-format */
-	(_("%pB: warning: isymMax (%ld) is greater than ifdMax (%ld)"),
+	(_("%pB: %%w: isymMax (%ld) is greater than ifdMax (%ld)"),
 	 abfd, ecoff_data (abfd)->debug_info.symbolic_header.isymMax,
 	 ecoff_data (abfd)->debug_info.symbolic_header.ifdMax);
     }
diff --git a/bfd/elf-properties.c b/bfd/elf-properties.c
index ee8bd37f2bd..3554fecaac5 100644
--- a/bfd/elf-properties.c
+++ b/bfd/elf-properties.c
@@ -88,7 +88,7 @@  _bfd_elf_parse_gnu_properties (bfd *abfd, Elf_Internal_Note *note)
     {
     bad_size:
       _bfd_error_handler
-	(_("warning: %pB: corrupt GNU_PROPERTY_TYPE (%ld) size: %#lx"),
+	(_("%%w: %pB: corrupt GNU_PROPERTY_TYPE (%ld) size: %#lx"),
 	 abfd, note->type, note->descsz);
       return false;
     }
@@ -109,7 +109,7 @@  _bfd_elf_parse_gnu_properties (bfd *abfd, Elf_Internal_Note *note)
       if (datasz > (size_t) (ptr_end - ptr))
 	{
 	  _bfd_error_handler
-	    (_("warning: %pB: corrupt GNU_PROPERTY_TYPE (%ld) type (0x%x) datasz: 0x%x"),
+	    (_("%%w: %pB: corrupt GNU_PROPERTY_TYPE (%ld) type (0x%x) datasz: 0x%x"),
 	     abfd, note->type, type, datasz);
 	  /* Clear all properties.  */
 	  elf_properties (abfd) = NULL;
@@ -148,7 +148,7 @@  _bfd_elf_parse_gnu_properties (bfd *abfd, Elf_Internal_Note *note)
 	      if (datasz != align_size)
 		{
 		  _bfd_error_handler
-		    (_("warning: %pB: corrupt stack size: 0x%x"),
+		    (_("%%w: %pB: corrupt stack size: 0x%x"),
 		     abfd, datasz);
 		  /* Clear all properties.  */
 		  elf_properties (abfd) = NULL;
@@ -166,7 +166,7 @@  _bfd_elf_parse_gnu_properties (bfd *abfd, Elf_Internal_Note *note)
 	      if (datasz != 0)
 		{
 		  _bfd_error_handler
-		    (_("warning: %pB: corrupt no copy on protected size: 0x%x"),
+		    (_("%%w: %pB: corrupt no copy on protected size: 0x%x"),
 		     abfd, datasz);
 		  /* Clear all properties.  */
 		  elf_properties (abfd) = NULL;
@@ -211,7 +211,7 @@  _bfd_elf_parse_gnu_properties (bfd *abfd, Elf_Internal_Note *note)
 	}
 
       _bfd_error_handler
-	(_("warning: %pB: unsupported GNU_PROPERTY_TYPE (%ld) type: 0x%x"),
+	(_("%%w: %pB: unsupported GNU_PROPERTY_TYPE (%ld) type: 0x%x"),
 	 abfd, note->type, type);
 
     next:
diff --git a/bfd/elf-s390-common.c b/bfd/elf-s390-common.c
index 721f5d8b449..f49db2a574f 100644
--- a/bfd/elf-s390-common.c
+++ b/bfd/elf-s390-common.c
@@ -345,12 +345,12 @@  elf_s390_merge_obj_attributes (bfd *ibfd, struct bfd_link_info *info)
   if (in_attr->i > 2)
     _bfd_error_handler
       /* xgettext:c-format */
-      (_("warning: %pB uses unknown vector ABI %d"), ibfd,
+      (_("%%w: %pB uses unknown vector ABI %d"), ibfd,
        in_attr->i);
   else if (out_attr->i > 2)
     _bfd_error_handler
       /* xgettext:c-format */
-      (_("warning: %pB uses unknown vector ABI %d"), obfd,
+      (_("%%w: %pB uses unknown vector ABI %d"), obfd,
        out_attr->i);
   else if (in_attr->i != out_attr->i)
     {
@@ -362,7 +362,7 @@  elf_s390_merge_obj_attributes (bfd *ibfd, struct bfd_link_info *info)
 
 	  _bfd_error_handler
 	    /* xgettext:c-format */
-	    (_("warning: %pB uses vector %s ABI, %pB uses %s ABI"),
+	    (_("%%w: %pB uses vector %s ABI, %pB uses %s ABI"),
 	     ibfd, abi_str[in_attr->i], obfd, abi_str[out_attr->i]);
 	}
       if (in_attr->i > out_attr->i)
diff --git a/bfd/elf.c b/bfd/elf.c
index 88c75ae3ce0..95bea6df535 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -2611,7 +2611,7 @@  bfd_section_from_shdr (bfd *abfd, unsigned int shindex)
   if (elf_tdata (abfd)->being_created[shindex])
     {
       _bfd_error_handler
-	(_("%pB: warning: loop in section dependencies detected"), abfd);
+	(_("%pB: %%w: loop in section dependencies detected"), abfd);
       return false;
     }
   elf_tdata (abfd)->being_created[shindex] = true;
@@ -2718,7 +2718,7 @@  bfd_section_from_shdr (bfd *abfd, unsigned int shindex)
 	{
 	  _bfd_error_handler
 	    /* xgettext:c-format */
-	    (_("%pB: warning: multiple symbol tables detected"
+	    (_("%pB: %%w: multiple symbol tables detected"
 	       " - ignoring the table in section %u"),
 	     abfd, shindex);
 	  goto success;
@@ -2803,7 +2803,7 @@  bfd_section_from_shdr (bfd *abfd, unsigned int shindex)
 	{
 	  _bfd_error_handler
 	    /* xgettext:c-format */
-	    (_("%pB: warning: multiple dynamic symbol tables detected"
+	    (_("%pB: %%w: multiple dynamic symbol tables detected"
 	       " - ignoring the table in section %u"),
 	     abfd, shindex);
 	  goto success;
@@ -2979,7 +2979,7 @@  bfd_section_from_shdr (bfd *abfd, unsigned int shindex)
 	      {
 		_bfd_error_handler
 		  /* xgettext:c-format */
-		  (_("%pB: warning: secondary relocation section '%s' "
+		  (_("%pB: %%w: secondary relocation section '%s' "
 		     "for section %pA found - ignoring"),
 		   abfd, name, target_sect);
 	      }
@@ -3802,7 +3802,7 @@  elf_fake_sections (bfd *abfd, asection *asect, void *fsarg)
 	 non-bss input sections to bss output sections, or emit data
 	 to a bss output section via a linker script.  */
       _bfd_error_handler
-	(_("warning: section `%pA' type changed to PROGBITS"), asect);
+	(_("%%w: section `%pA' type changed to PROGBITS"), asect);
       this_hdr->sh_type = sh_type;
     }
 
@@ -6717,7 +6717,7 @@  assign_file_positions_for_non_load_sections (bfd *abfd,
 	      && ! is_debuginfo_file (abfd))
 	    _bfd_error_handler
 	      /* xgettext:c-format */
-	      (_("%pB: warning: allocated section `%s' not in segment"),
+	      (_("%pB: %%w: allocated section `%s' not in segment"),
 	       abfd,
 	       (hdr->bfd_section == NULL
 		? "*unknown*"
@@ -6852,7 +6852,7 @@  assign_file_positions_for_non_load_sections (bfd *abfd,
 	    {
 	      if (link_info != NULL)
 		_bfd_error_handler
-		  (_("%pB: warning: unable to allocate any sections"
+		  (_("%pB: %%w: unable to allocate any sections"
 		     " to PT_GNU_RELRO segment"),
 		   abfd);
 	      memset (p, 0, sizeof *p);
@@ -7038,7 +7038,7 @@  error: %pB has a TLS segment with execute permission"),
 		    }
 
 		  _bfd_error_handler (_("\
-warning: %pB has a TLS segment with execute permission"),
+%%w: %pB has a TLS segment with execute permission"),
 				      abfd);
 		  if (warned_rwx)
 		    break;
@@ -7059,7 +7059,7 @@  error: %pB has a LOAD segment with RWX permissions"),
 		    }
 
 		  _bfd_error_handler (_("\
-warning: %pB has a LOAD segment with RWX permissions"),
+%%w: %pB has a LOAD segment with RWX permissions"),
 				      abfd);
 		  if (warned_tls)
 		    break;
@@ -7829,7 +7829,7 @@  rewrite_elf_program_header (bfd *ibfd, bfd *obfd, bfd_vma maxpagesize)
 	      && (segment->p_filesz > 0 || segment->p_memsz == 0))
 	    /* xgettext:c-format */
 	    _bfd_error_handler
-	      (_("%pB: warning: empty loadable segment detected"
+	      (_("%pB: %%w: empty loadable segment detected"
 		 " at vaddr=%#" PRIx64 ", is this intentional?"),
 	       ibfd, (uint64_t) segment->p_vaddr);
 
@@ -8489,7 +8489,7 @@  copy_private_bfd_data (bfd *ibfd, bfd *obfd)
 	    /* PR 17512: file: f17299af.  */
 	    if (segment->p_align > (bfd_vma) 1 << ((sizeof (bfd_vma) * 8) - 2))
 	      /* xgettext:c-format */
-	      _bfd_error_handler (_("%pB: warning: segment alignment of %#"
+	      _bfd_error_handler (_("%pB: %%w: segment alignment of %#"
 				    PRIx64 " is too large"),
 				  ibfd, (uint64_t) segment->p_align);
 	    else
@@ -11076,7 +11076,7 @@  elfcore_grok_win32pstatus (bfd *abfd, Elf_Internal_Note *note)
 
   if (note->descsz < size_check[type - 1].min_size)
     {
-      _bfd_error_handler (_("%pB: warning: win32pstatus %s of size %lu bytes"
+      _bfd_error_handler (_("%pB: %%w: win32pstatus %s of size %lu bytes"
 			    " is too small"),
 			  abfd, size_check[type - 1].type_name, note->descsz);
       return true;
diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c
index 1061e54e9d7..ca2b3bd654e 100644
--- a/bfd/elf32-arc.c
+++ b/bfd/elf32-arc.c
@@ -639,7 +639,7 @@  arc_elf_merge_attributes (bfd *ibfd, struct bfd_link_info *info)
 	      /* It's sometimes ok to mix different configs, so this is only
 		 a warning.  */
 	      _bfd_error_handler
-		(_("warning: %pB: conflicting platform configuration "
+		(_("%%w: %pB: conflicting platform configuration "
 		   "%s with %s"), ibfd,
 		 tagval[in_attr[i].i],
 		 tagval[out_attr[i].i]);
@@ -1030,7 +1030,7 @@  arc_elf_object_p (bfd * abfd)
       else
 	{
 	  _bfd_error_handler
-	    (_("warning: unset or old architecture flags; "
+	    (_("%%w: unset or old architecture flags; "
 	       "use default machine"));
 	}
     }
@@ -1919,7 +1919,7 @@  elf_arc_relocate_section (bfd *			  output_bfd,
 
 	case bfd_reloc_other:
 	  /* xgettext:c-format */
-	  msg = _("%pB(%pA): warning: unaligned access to symbol '%s' in the small data area");
+	  msg = _("%pB(%pA): %%w: unaligned access to symbol '%s' in the small data area");
 	  break;
 
 	case bfd_reloc_outofrange:
@@ -2928,7 +2928,7 @@  elf32_arc_obj_attrs_handle_unknown (bfd *abfd, int tag)
   else
     {
       _bfd_error_handler
-	(_("warning: %pB: unknown ARC object attribute %d"),
+	(_("%%w: %pB: unknown ARC object attribute %d"),
 	 abfd, tag);
       return true;
     }
diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
index 4ad7c3542a7..66f16d32e53 100644
--- a/bfd/elf32-arm.c
+++ b/bfd/elf32-arm.c
@@ -4343,7 +4343,7 @@  arm_type_of_stub (struct bfd_link_info *info,
 		{
 		  if (input_sec->flags & SEC_ELF_PURECODE)
 		    _bfd_error_handler
-		      (_("%pB(%pA): warning: long branch veneers used in"
+		      (_("%pB(%pA): %%w: long branch veneers used in"
 			 " section with SHF_ARM_PURECODE section"
 			 " attribute is only supported for M-profile"
 			 " targets that implement the movw instruction"),
@@ -4377,7 +4377,7 @@  arm_type_of_stub (struct bfd_link_info *info,
 		    {
 		      if (input_sec->flags & SEC_ELF_PURECODE)
 			_bfd_error_handler
-			  (_("%pB(%pA): warning: long branch veneers used in"
+			  (_("%pB(%pA): %%w: long branch veneers used in"
 			     " section with SHF_ARM_PURECODE section"
 			     " attribute is only supported for M-profile"
 			     " targets that implement the movw instruction"),
@@ -4396,7 +4396,7 @@  arm_type_of_stub (struct bfd_link_info *info,
 	    {
 	      if (input_sec->flags & SEC_ELF_PURECODE)
 		_bfd_error_handler
-		  (_("%pB(%pA): warning: long branch veneers used in"
+		  (_("%pB(%pA): %%w: long branch veneers used in"
 		     " section with SHF_ARM_PURECODE section"
 		     " attribute is only supported" " for M-profile"
 		     " targets that implement the movw instruction"),
@@ -4408,7 +4408,7 @@  arm_type_of_stub (struct bfd_link_info *info,
 		  && !INTERWORK_FLAG (sym_sec->owner))
 		{
 		  _bfd_error_handler
-		    (_("%pB(%s): warning: interworking not enabled;"
+		    (_("%pB(%s): %%w: interworking not enabled;"
 		       " first occurrence: %pB: %s call to %s"),
 		     sym_sec->owner, name, input_bfd, "Thumb", "ARM");
 		}
@@ -4448,7 +4448,7 @@  arm_type_of_stub (struct bfd_link_info *info,
     {
       if (input_sec->flags & SEC_ELF_PURECODE)
 	_bfd_error_handler
-	  (_("%pB(%pA): warning: long branch veneers used in"
+	  (_("%pB(%pA): %%w: long branch veneers used in"
 	     " section with SHF_ARM_PURECODE section"
 	     " attribute is only supported for M-profile"
 	     " targets that implement the movw instruction"),
@@ -4462,7 +4462,7 @@  arm_type_of_stub (struct bfd_link_info *info,
 	      && !INTERWORK_FLAG (sym_sec->owner))
 	    {
 	      _bfd_error_handler
-		(_("%pB(%s): warning: interworking not enabled;"
+		(_("%pB(%s): %%w: interworking not enabled;"
 		   " first occurrence: %pB: %s call to %s"),
 		 sym_sec->owner, name, input_bfd, "ARM", "Thumb");
 	    }
@@ -8093,7 +8093,7 @@  bfd_elf32_arm_set_vfp11_fix (bfd *obfd, struct bfd_link_info *link_info)
 
 	default:
 	  /* Give a warning, but do as the user requests anyway.  */
-	  _bfd_error_handler (_("%pB: warning: selected VFP11 erratum "
+	  _bfd_error_handler (_("%pB: %%w: selected VFP11 erratum "
 	    "workaround is not necessary for target architecture"), obfd);
 	}
     }
@@ -8120,7 +8120,7 @@  bfd_elf32_arm_set_stm32l4xx_fix (bfd *obfd, struct bfd_link_info *link_info)
       if (globals->stm32l4xx_fix != BFD_ARM_STM32L4XX_FIX_NONE)
 	/* Give a warning, but do as the user requests anyway.  */
 	_bfd_error_handler
-	  (_("%pB: warning: selected STM32L4XX erratum "
+	  (_("%pB: %%w: selected STM32L4XX erratum "
 	     "workaround is not necessary for target architecture"), obfd);
     }
 }
@@ -9160,7 +9160,7 @@  elf32_thumb_to_arm_stub (struct bfd_link_info * info,
 	  && !INTERWORK_FLAG (sym_sec->owner))
 	{
 	  _bfd_error_handler
-	    (_("%pB(%s): warning: interworking not enabled;"
+	    (_("%pB(%s): %%w: interworking not enabled;"
 	       " first occurrence: %pB: %s call to %s"),
 	     sym_sec->owner, name, input_bfd, "Thumb", "ARM");
 
@@ -9250,7 +9250,7 @@  elf32_arm_create_thumb_stub (struct bfd_link_info * info,
 	  && !INTERWORK_FLAG (sym_sec->owner))
 	{
 	  _bfd_error_handler
-	    (_("%pB(%s): warning: interworking not enabled;"
+	    (_("%pB(%s): %%w: interworking not enabled;"
 	       " first occurrence: %pB: %s call to %s"),
 	     sym_sec->owner, name, input_bfd, "ARM", "Thumb");
 	}
@@ -9837,7 +9837,7 @@  elf32_arm_populate_plt_entry (bfd *output_bfd, struct bfd_link_info *info,
 	{
 	  /* FIXME: We ought to be able to generate thumb-1 PLT
 	     instructions...  */
-	  _bfd_error_handler (_("%pB: warning: thumb-1 mode PLT generation not currently supported"),
+	  _bfd_error_handler (_("%pB: %%w: thumb-1 mode PLT generation not currently supported"),
 			      output_bfd);
 	  return false;
 	}
@@ -10646,7 +10646,7 @@  elf32_arm_final_link_relocate (reloc_howto_type *	    howto,
 		 instruction instead ?  */
 	      if (branch_type != ST_BRANCH_TO_THUMB)
 		_bfd_error_handler
-		  (_("\%pB: warning: %s BLX instruction targets"
+		  (_("\%pB: %%w: %s BLX instruction targets"
 		     " %s function '%s'"),
 		   input_bfd, "ARM",
 		   "ARM", h ? h->root.root.string : "(local)");
@@ -11063,7 +11063,7 @@  elf32_arm_final_link_relocate (reloc_howto_type *	    howto,
 	       instruction instead ?  */
 	    if (branch_type == ST_BRANCH_TO_THUMB)
 	      _bfd_error_handler
-		(_("%pB: warning: %s BLX instruction targets"
+		(_("%pB: %%w: %s BLX instruction targets"
 		   " %s function '%s'"),
 		 input_bfd, "Thumb",
 		 "Thumb", h ? h->root.root.string : "(local)");
@@ -13919,11 +13919,11 @@  elf32_arm_set_private_flags (bfd *abfd, flagword flags)
 	{
 	  if (flags & EF_ARM_INTERWORK)
 	    _bfd_error_handler
-	      (_("warning: not setting interworking flag of %pB since it has already been specified as non-interworking"),
+	      (_("%%w: not setting interworking flag of %pB since it has already been specified as non-interworking"),
 	       abfd);
 	  else
 	    _bfd_error_handler
-	      (_("warning: clearing the interworking flag of %pB due to outside request"),
+	      (_("%%w: clearing the interworking flag of %pB due to outside request"),
 	       abfd);
 	}
     }
@@ -13968,7 +13968,7 @@  elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
 	{
 	  if (out_flags & EF_ARM_INTERWORK)
 	    _bfd_error_handler
-	      (_("warning: clearing the interworking flag of %pB because non-interworking code in %pB has been linked with it"),
+	      (_("%%w: clearing the interworking flag of %pB because non-interworking code in %pB has been linked with it"),
 	       obfd, ibfd);
 
 	  in_flags &= ~EF_ARM_INTERWORK;
@@ -14063,7 +14063,7 @@  elf32_arm_obj_attrs_handle_unknown (bfd *abfd, int tag)
   else
     {
       _bfd_error_handler
-	(_("warning: %pB: unknown EABI object attribute %d"),
+	(_("%%w: %pB: unknown EABI object attribute %d"),
 	 abfd, tag);
       return true;
     }
@@ -14905,7 +14905,7 @@  elf32_arm_merge_eabi_attributes (bfd *ibfd, struct bfd_link_info *info)
 	      /* It's sometimes ok to mix different configs, so this is only
 		 a warning.  */
 	      _bfd_error_handler
-		(_("warning: %pB: conflicting platform configuration"), ibfd);
+		(_("%%w: %pB: conflicting platform configuration"), ibfd);
 	    }
 	  break;
 	case Tag_ABI_PCS_R9_use:
@@ -14939,7 +14939,7 @@  elf32_arm_merge_eabi_attributes (bfd *ibfd, struct bfd_link_info *info)
 	      && !elf_arm_tdata (obfd)->no_wchar_size_warning)
 	    {
 	      _bfd_error_handler
-		(_("warning: %pB uses %u-byte wchar_t yet the output is to use %u-byte wchar_t; use of wchar_t values across objects may fail"),
+		(_("%%w: %pB uses %u-byte wchar_t yet the output is to use %u-byte wchar_t; use of wchar_t values across objects may fail"),
 		 ibfd, in_attr[i].i, out_attr[i].i);
 	    }
 	  else if (in_attr[i].i && !out_attr[i].i)
@@ -14970,7 +14970,7 @@  elf32_arm_merge_eabi_attributes (bfd *ibfd, struct bfd_link_info *info)
 		    ? aeabi_enum_names[out_attr[i].i]
 		    : "<unknown>";
 		  _bfd_error_handler
-		    (_("warning: %pB uses %s enums yet the output is to use %s enums; use of enum values across objects may fail"),
+		    (_("%%w: %pB uses %s enums yet the output is to use %s enums; use of enum values across objects may fail"),
 		     ibfd, in_name, out_name);
 		}
 	    }
@@ -20836,13 +20836,13 @@  elf32_arm_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
 	  if (in_flags & EF_ARM_INTERWORK)
 	    {
 	      _bfd_error_handler
-		(_("warning: %pB supports interworking, whereas %pB does not"),
+		(_("%%w: %pB supports interworking, whereas %pB does not"),
 		 ibfd, obfd);
 	    }
 	  else
 	    {
 	      _bfd_error_handler
-		(_("warning: %pB does not support interworking, whereas %pB does"),
+		(_("%%w: %pB does not support interworking, whereas %pB does"),
 		 ibfd, obfd);
 	    }
 	}
diff --git a/bfd/elf32-bfin.c b/bfd/elf32-bfin.c
index 78402526520..d2ceae83764 100644
--- a/bfd/elf32-bfin.c
+++ b/bfd/elf32-bfin.c
@@ -3043,7 +3043,7 @@  bfinfdpic_relocate_section (bfd * output_bfd,
 	      (info,
 	       bfd_link_pic (info)
 	       ? _("relocations between different segments are not supported")
-	       : _("warning: relocation references a different segment"),
+	       : _("%%w: relocation references a different segment"),
 	       name, input_bfd, input_section, rel->r_offset);
 	  if (!silence_segment_error && bfd_link_pic (info))
 	    return false;
diff --git a/bfd/elf32-csky.c b/bfd/elf32-csky.c
index 9479705d37e..682e3cf826f 100644
--- a/bfd/elf32-csky.c
+++ b/bfd/elf32-csky.c
@@ -2827,7 +2827,7 @@  csky_find_arch_with_eflag (const unsigned long arch_eflag)
       break;
   if (csky_arch == NULL)
     {
-      _bfd_error_handler (_("warning: unrecognized arch eflag '%#lx'"),
+      _bfd_error_handler (_("%%w: unrecognized arch eflag '%#lx'"),
 			   arch_eflag);
       bfd_set_error (bfd_error_wrong_format);
     }
@@ -2850,7 +2850,7 @@  csky_find_arch_with_name (const char *name)
     }
   if (csky_arch == NULL)
     {
-      msg = _("warning: unrecognised arch name '%#x'");
+      msg = _("%%w: unrecognised arch name '%#x'");
       (*_bfd_error_handler) (msg, name);
       bfd_set_error (bfd_error_wrong_format);
     }
@@ -2928,7 +2928,7 @@  elf32_csky_merge_attributes (bfd *ibfd, struct bfd_link_info *info)
 
 		  if (new_arch->do_warning || old_arch->do_warning)
 		    {
-		      msg = _("warning: file %pB's arch flag %s conflict "
+		      msg = _("%%w: file %pB's arch flag %s conflict "
 			      "with target %s,set target arch flag to %s");
 		      (*_bfd_error_handler) (msg, ibfd,  new_arch->name,
 					     old_arch->name,
@@ -3089,7 +3089,7 @@  csky_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
 		{
 		  _bfd_error_handler
 		    /* xgettext:c-format */
-		    (_("warning: file %pB's arch flag %s conflicts with "
+		    (_("%%w: file %pB's arch flag %s conflicts with "
 		       "target ck%s, using %s"),
 		     ibfd, new_arch->name, old_arch->name,
 		     newest_arch->name);
diff --git a/bfd/elf32-msp430.c b/bfd/elf32-msp430.c
index 66f0f7d6387..77b8d9cb92d 100644
--- a/bfd/elf32-msp430.c
+++ b/bfd/elf32-msp430.c
@@ -2670,7 +2670,7 @@  elf32_msp430_obj_attrs_handle_unknown (bfd *abfd, int tag)
 {
   _bfd_error_handler
     /* xgettext:c-format */
-    (_("warning: %pB: unknown MSPABI object attribute %d"),
+    (_("%%w: %pB: unknown MSPABI object attribute %d"),
      abfd, tag);
   return true;
 }
diff --git a/bfd/elf32-nds32.c b/bfd/elf32-nds32.c
index f8a6836d599..5cd8a57e7ec 100644
--- a/bfd/elf32-nds32.c
+++ b/bfd/elf32-nds32.c
@@ -5178,7 +5178,7 @@  nds32_elf_relocate_section (bfd *		   output_bfd ATTRIBUTE_UNUSED,
 		  if (!bfd_link_pie (info))
 		    {
 		      _bfd_error_handler
-			("%pB: warning: _FP_BASE_ setting insns relaxation failed.",
+			("%pB: %%w: _FP_BASE_ setting insns relaxation failed.",
 			 input_bfd);
 		    }
 		  relocation = fpbase_addr;
@@ -5570,7 +5570,7 @@  nds32_elf_relocate_section (bfd *		   output_bfd ATTRIBUTE_UNUSED,
 	  if (bfd_link_pic (info))
 	    {
 	      _bfd_error_handler
-		(_("%pB: warning: %s unsupported in shared mode"),
+		(_("%pB: %%w: %s unsupported in shared mode"),
 		 input_bfd, "R_NDS32_25_ABS_RELA");
 	      return false;
 	    }
@@ -5696,7 +5696,7 @@  nds32_elf_relocate_section (bfd *		   output_bfd ATTRIBUTE_UNUSED,
 	    {
 	      /* Incorrect alignment.  */
 	      _bfd_error_handler
-		(_("%pB: warning: unaligned access to GOT entry"), input_bfd);
+		(_("%pB: %%w: unaligned access to GOT entry"), input_bfd);
 	      ret = false;
 	      r = bfd_reloc_dangerous;
 	      goto check_reloc;
@@ -5737,7 +5737,7 @@  nds32_elf_relocate_section (bfd *		   output_bfd ATTRIBUTE_UNUSED,
 	  if (r != bfd_reloc_ok)
 	    {
 	      _bfd_error_handler
-		(_("%pB: warning: relocate SDA_BASE failed"), input_bfd);
+		(_("%pB: %%w: relocate SDA_BASE failed"), input_bfd);
 	      ret = false;
 	      goto check_reloc;
 	    }
@@ -5759,7 +5759,7 @@  nds32_elf_relocate_section (bfd *		   output_bfd ATTRIBUTE_UNUSED,
 	      /* Incorrect alignment.  */
 	      _bfd_error_handler
 		/* xgettext:c-format */
-		(_("%pB(%pA): warning: unaligned small data access"
+		(_("%pB(%pA): %%w: unaligned small data access"
 		   " of type %d"),
 		 input_bfd, input_section, r_type);
 	      ret = false;
@@ -6733,7 +6733,7 @@  nds32_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
   if (bfd_little_endian (ibfd) != bfd_little_endian (obfd))
     {
       _bfd_error_handler
-	(_("%pB: warning: endian mismatch with previous modules"), ibfd);
+	(_("%pB: %%w: endian mismatch with previous modules"), ibfd);
 
       bfd_set_error (bfd_error_bad_value);
       return false;
@@ -6747,7 +6747,7 @@  nds32_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
       if (in_version == E_NDS32_ELF_VER_1_2)
 	{
 	  _bfd_error_handler
-	    (_("%pB: warning: older version of object file encountered, "
+	    (_("%pB: %%w: older version of object file encountered, "
 	       "please recompile with current tool chain"), ibfd);
 	}
 
@@ -6872,7 +6872,7 @@  nds32_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
 	  if (in_version != out_version)
 	    _bfd_error_handler
 	      /* xgettext:c-format */
-	      (_("%pB: warning: incompatible elf-versions %s and %s"),
+	      (_("%pB: %%w: incompatible elf-versions %s and %s"),
 	       ibfd, nds32_elfver_strtab[out_version],
 	       nds32_elfver_strtab[in_version]);
 
@@ -9619,7 +9619,7 @@  relax_range_measurement (bfd *abfd, struct bfd_link_info *link_info)
 
 static const char * unrecognized_reloc_msg =
   /* xgettext:c-format */
-  N_("%pB: warning: %s points to unrecognized reloc at %#" PRIx64);
+  N_("%pB: %%w: %s points to unrecognized reloc at %#" PRIx64);
 
 /* Relax LONGCALL1 relocation for nds32_elf_relax_section.  */
 
diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c
index e6dd7abdf96..1c832911dc4 100644
--- a/bfd/elf32-ppc.c
+++ b/bfd/elf32-ppc.c
@@ -1686,7 +1686,7 @@  ppc_elf_begin_write_processing (bfd *abfd, struct bfd_link_info *link_info)
 	{
 	  ibfd = abfd;
 	  /* xgettext:c-format */
-	  error_message = _("warning: unable to set size of %s section in %pB");
+	  error_message = _("%%w: unable to set size of %s section in %pB");
 	}
     }
 
@@ -4605,7 +4605,7 @@  ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED,
 			    {
 			      /* xgettext:c-format */
 			      info->callbacks->minfo
-				(_("%H: warning: %s unexpected insn %#x.\n"),
+				(_("%H: %%w: %s unexpected insn %#x.\n"),
 				 ibfd, sec, off, "R_PPC_TPREL16_HA", insn);
 			      htab->do_tls_opt = 0;
 			    }
diff --git a/bfd/elf32-rl78.c b/bfd/elf32-rl78.c
index 8e8fd8b31e1..8be72302044 100644
--- a/bfd/elf32-rl78.c
+++ b/bfd/elf32-rl78.c
@@ -1066,7 +1066,7 @@  rl78_elf_relocate_section
 		relocation = 0;
 		if (h->root.type != bfd_link_hash_undefweak)
 		  _bfd_error_handler
-		    (_("warning: RL78_SYM reloc with an unknown symbol"));
+		    (_("%%w: RL78_SYM reloc with an unknown symbol"));
 	      }
 	    (void) rl78_compute_complex_reloc (r_type, relocation, input_section,
 					       &r, &error_message);
diff --git a/bfd/elf32-rx.c b/bfd/elf32-rx.c
index db1ab777d3f..d16f37e67e8 100644
--- a/bfd/elf32-rx.c
+++ b/bfd/elf32-rx.c
@@ -697,7 +697,7 @@  rx_elf_relocate_section
 #define WARN_REDHAT(type) \
   /* xgettext:c-format */					\
   _bfd_error_handler						\
-    (_("%pB:%pA: warning: deprecated Red Hat reloc "		\
+    (_("%pB:%pA: %%w: deprecated Red Hat reloc "		\
        "%s detected against: %s"),				\
      input_bfd, input_section, #type, name)
 
@@ -1301,7 +1301,7 @@  rx_elf_relocate_section
 			       + rel->r_addend);
 	      else
 		_bfd_error_handler
-		  (_("warning: RX_SYM reloc with an unknown symbol"));
+		  (_("%%w: RX_SYM reloc with an unknown symbol"));
 	    }
 	  break;
 
@@ -1483,7 +1483,7 @@  rx_elf_relocate_section
 
 	    case bfd_reloc_other:
 	      /* xgettext:c-format */
-	      msg = _("%pB(%pA): warning: unaligned access to symbol '%s' in the small data area");
+	      msg = _("%pB(%pA): %%w: unaligned access to symbol '%s' in the small data area");
 	      break;
 
 	    case bfd_reloc_outofrange:
diff --git a/bfd/elf32-score.c b/bfd/elf32-score.c
index 448aba87c86..c994770a7d3 100644
--- a/bfd/elf32-score.c
+++ b/bfd/elf32-score.c
@@ -4038,7 +4038,7 @@  s3_elf32_score_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
 
   if (((in_flags & EF_SCORE_PIC) != 0) != ((out_flags & EF_SCORE_PIC) != 0))
     _bfd_error_handler
-      (_("%pB: warning: linking PIC files with non-PIC files"), ibfd);
+      (_("%pB: %%w: linking PIC files with non-PIC files"), ibfd);
 
   /* FIXME: Maybe dependency fix compatibility should be checked here.  */
 
diff --git a/bfd/elf32-score7.c b/bfd/elf32-score7.c
index c20fa7a3eca..155e8c7e675 100644
--- a/bfd/elf32-score7.c
+++ b/bfd/elf32-score7.c
@@ -3845,7 +3845,7 @@  s7_elf32_score_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
 
   if (((in_flags & EF_SCORE_PIC) != 0) != ((out_flags & EF_SCORE_PIC) != 0))
     {
-      _bfd_error_handler (_("%pB: warning: linking PIC files with non-PIC files"), ibfd);
+      _bfd_error_handler (_("%pB: %%w: linking PIC files with non-PIC files"), ibfd);
     }
 
   /* Maybe dependency fix compatibility should be checked here.  */
diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c
index 77bcaea7bdf..37dc07a442b 100644
--- a/bfd/elf32-sh.c
+++ b/bfd/elf32-sh.c
@@ -518,7 +518,7 @@  sh_elf_relax_section (bfd *abfd, asection *sec,
 	{
 	  /* xgettext:c-format */
 	  _bfd_error_handler
-	    (_("%pB: %#" PRIx64 ": warning: bad R_SH_USES offset"),
+	    (_("%pB: %#" PRIx64 ": %%w: bad R_SH_USES offset"),
 	     abfd, (uint64_t) irel->r_offset);
 	  continue;
 	}
@@ -530,7 +530,7 @@  sh_elf_relax_section (bfd *abfd, asection *sec,
 	{
 	  _bfd_error_handler
 	    /* xgettext:c-format */
-	    (_("%pB: %#" PRIx64 ": warning: "
+	    (_("%pB: %#" PRIx64 ": %%w: "
 	       "R_SH_USES points to unrecognized insn 0x%x"),
 	     abfd, (uint64_t) irel->r_offset, insn);
 	  continue;
@@ -549,7 +549,7 @@  sh_elf_relax_section (bfd *abfd, asection *sec,
 	{
 	  _bfd_error_handler
 	    /* xgettext:c-format */
-	    (_("%pB: %#" PRIx64 ": warning: bad R_SH_USES load offset"),
+	    (_("%pB: %#" PRIx64 ": %%w: bad R_SH_USES load offset"),
 	     abfd, (uint64_t) irel->r_offset);
 	  continue;
 	}
@@ -565,7 +565,7 @@  sh_elf_relax_section (bfd *abfd, asection *sec,
 	{
 	  _bfd_error_handler
 	    /* xgettext:c-format */
-	    (_("%pB: %#" PRIx64 ": warning: could not find expected reloc"),
+	    (_("%pB: %#" PRIx64 ": %%w: could not find expected reloc"),
 	     abfd, (uint64_t) paddr);
 	  continue;
 	}
@@ -594,7 +594,7 @@  sh_elf_relax_section (bfd *abfd, asection *sec,
 	    {
 	      _bfd_error_handler
 		/* xgettext:c-format */
-		(_("%pB: %#" PRIx64 ": warning: symbol in unexpected section"),
+		(_("%pB: %#" PRIx64 ": %%w: symbol in unexpected section"),
 		 abfd, (uint64_t) paddr);
 	      continue;
 	    }
@@ -724,7 +724,7 @@  sh_elf_relax_section (bfd *abfd, asection *sec,
 	{
 	  _bfd_error_handler
 	    /* xgettext:c-format */
-	    (_("%pB: %#" PRIx64 ": warning: "
+	    (_("%pB: %#" PRIx64 ": %%w: "
 	       "could not find expected COUNT reloc"),
 	     abfd, (uint64_t) paddr);
 	  continue;
@@ -735,7 +735,7 @@  sh_elf_relax_section (bfd *abfd, asection *sec,
       if (irelcount->r_addend == 0)
 	{
 	  /* xgettext:c-format */
-	  _bfd_error_handler (_("%pB: %#" PRIx64 ": warning: bad count"),
+	  _bfd_error_handler (_("%pB: %#" PRIx64 ": %%w: bad count"),
 			      abfd, (uint64_t) paddr);
 	  continue;
 	}
diff --git a/bfd/elf32-spu.c b/bfd/elf32-spu.c
index d960c34021a..939546c0084 100644
--- a/bfd/elf32-spu.c
+++ b/bfd/elf32-spu.c
@@ -1029,7 +1029,7 @@  needs_ovl_stub (struct elf_link_hash_entry *h,
 		}
 	      _bfd_error_handler
 		/* xgettext:c-format */
-		(_("warning: call to non-function symbol %s defined in %pB"),
+		(_("%%w: call to non-function symbol %s defined in %pB"),
 		 sym_name, sym_sec->owner);
 
 	    }
diff --git a/bfd/elf32-tic6x.c b/bfd/elf32-tic6x.c
index afd8e0d2aff..838c603efdf 100644
--- a/bfd/elf32-tic6x.c
+++ b/bfd/elf32-tic6x.c
@@ -1585,12 +1585,12 @@  elf32_tic6x_final_link (bfd *abfd, struct bfd_link_info *info)
       out_attr = elf_known_obj_attributes_proc (abfd);
       if (out_attr[Tag_ABI_PIC].i == 0)
 	{
-	  _bfd_error_handler (_("warning: generating a shared library "
+	  _bfd_error_handler (_("%%w: generating a shared library "
 				"containing non-PIC code"));
 	}
       if (out_attr[Tag_ABI_PID].i == 0)
 	{
-	  _bfd_error_handler (_("warning: generating a shared library "
+	  _bfd_error_handler (_("%%w: generating a shared library "
 				"containing non-PID code"));
 	}
     }
@@ -3504,7 +3504,7 @@  elf32_tic6x_obj_attrs_handle_unknown (bfd *abfd, int tag)
     {
       _bfd_error_handler
 	/* xgettext:c-format */
-	(_("%pB: warning: unknown EABI object attribute %d"),
+	(_("%pB: %%w: unknown EABI object attribute %d"),
 	 abfd, tag);
       return true;
     }
@@ -3708,7 +3708,7 @@  elf32_tic6x_merge_attributes (bfd *ibfd, struct bfd_link_info *info)
 	    {
 	      _bfd_error_handler
 		/* xgettext:c-format */
-		(_("warning: %pB and %pB differ in wchar_t size"), obfd, ibfd);
+		(_("%%w: %pB and %pB differ in wchar_t size"), obfd, ibfd);
 	    }
 	  break;
 
@@ -3727,7 +3727,7 @@  elf32_tic6x_merge_attributes (bfd *ibfd, struct bfd_link_info *info)
 	    {
 	      _bfd_error_handler
 		/* xgettext:c-format */
-		(_("warning: %pB and %pB differ in whether code is "
+		(_("%%w: %pB and %pB differ in whether code is "
 		   "compiled for DSBT"),
 		 obfd, ibfd);
 	    }
diff --git a/bfd/elf32-v850.c b/bfd/elf32-v850.c
index 85cbcbc3505..c5c9b558ac1 100644
--- a/bfd/elf32-v850.c
+++ b/bfd/elf32-v850.c
@@ -3589,7 +3589,7 @@  v850_elf_relax_section (bfd *abfd,
 		{
 		  _bfd_error_handler
 		    /* xgettext:c-format */
-		    (_("%pB: %#" PRIx64 ": warning: %s points to "
+		    (_("%pB: %#" PRIx64 ": %%w: %s points to "
 		       "unrecognized insns"),
 		     abfd, (uint64_t) irel->r_offset, "R_V850_LONGCALL");
 		  continue;
@@ -3599,7 +3599,7 @@  v850_elf_relax_section (bfd *abfd,
 		{
 		  _bfd_error_handler
 		    /* xgettext:c-format */
-		    (_("%pB: %#" PRIx64 ": warning: %s points to "
+		    (_("%pB: %#" PRIx64 ": %%w: %s points to "
 		       "unrecognized insn %#x"),
 		     abfd,
 		     (uint64_t) (irel->r_offset + no_match),
@@ -3645,7 +3645,7 @@  v850_elf_relax_section (bfd *abfd,
 		{
 		  _bfd_error_handler
 		    /* xgettext:c-format */
-		    (_("%pB: %#" PRIx64 ": warning: %s points to "
+		    (_("%pB: %#" PRIx64 ": %%w: %s points to "
 		       "unrecognized reloc"),
 		     abfd, (uint64_t) irel->r_offset, "R_V850_LONGCALL");
 
@@ -3685,7 +3685,7 @@  v850_elf_relax_section (bfd *abfd,
 		{
 		  _bfd_error_handler
 		    /* xgettext:c-format */
-		    (_("%pB: %#" PRIx64 ": warning: %s points to "
+		    (_("%pB: %#" PRIx64 ": %%w: %s points to "
 		       "unrecognized reloc %#" PRIx64),
 		     abfd, (uint64_t) irel->r_offset, "R_V850_LONGCALL",
 		     (uint64_t) irelcall->r_offset);
@@ -3828,7 +3828,7 @@  v850_elf_relax_section (bfd *abfd,
 		{
 		  _bfd_error_handler
 		    /* xgettext:c-format */
-		    (_("%pB: %#" PRIx64 ": warning: %s points to "
+		    (_("%pB: %#" PRIx64 ": %%w: %s points to "
 		       "unrecognized insns"),
 		     abfd, (uint64_t) irel->r_offset, "R_V850_LONGJUMP");
 		  continue;
@@ -3838,7 +3838,7 @@  v850_elf_relax_section (bfd *abfd,
 		{
 		  _bfd_error_handler
 		    /* xgettext:c-format */
-		    (_("%pB: %#" PRIx64 ": warning: %s points to "
+		    (_("%pB: %#" PRIx64 ": %%w: %s points to "
 		       "unrecognized insn %#x"),
 		     abfd,
 		     (uint64_t) (irel->r_offset + no_match),
@@ -3873,7 +3873,7 @@  v850_elf_relax_section (bfd *abfd,
 		{
 		  _bfd_error_handler
 		    /* xgettext:c-format */
-		    (_("%pB: %#" PRIx64 ": warning: %s points to "
+		    (_("%pB: %#" PRIx64 ": %%w: %s points to "
 		       "unrecognized reloc"),
 		     abfd, (uint64_t) irel->r_offset, "R_V850_LONGJUMP");
 		  continue;
diff --git a/bfd/elf32-vax.c b/bfd/elf32-vax.c
index 4422dc995aa..8d1c1bb0af8 100644
--- a/bfd/elf32-vax.c
+++ b/bfd/elf32-vax.c
@@ -628,7 +628,7 @@  elf_vax_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
 		  if (eh->got_addend != (bfd_vma) rel->r_addend)
 		    _bfd_error_handler
 		      /* xgettext:c-format */
-		      (_("%pB: warning: GOT addend of %" PRId64 " to `%s' does"
+		      (_("%pB: %%w: GOT addend of %" PRId64 " to `%s' does"
 			 " not match previous GOT addend of %" PRId64),
 			 abfd, (int64_t) rel->r_addend, h->root.root.string,
 			 (int64_t) eh->got_addend);
@@ -1385,7 +1385,7 @@  elf_vax_relocate_section (bfd *output_bfd,
 	  else if (rel->r_addend != 0)
 	    _bfd_error_handler
 	      /* xgettext:c-format */
-	      (_("%pB: warning: PLT addend of %" PRId64 " to `%s'"
+	      (_("%pB: %%w: PLT addend of %" PRId64 " to `%s'"
 		 " from %pA section ignored"),
 	       input_bfd, (int64_t) rel->r_addend, h->root.root.string,
 	       input_section);
@@ -1511,14 +1511,14 @@  elf_vax_relocate_section (bfd *output_bfd,
 		  if (h != NULL)
 		    _bfd_error_handler
 		      /* xgettext:c-format */
-		      (_("%pB: warning: %s relocation against symbol `%s'"
+		      (_("%pB: %%w: %s relocation against symbol `%s'"
 			 " from %pA section"),
 		      input_bfd, howto->name, h->root.root.string,
 		      input_section);
 		  else
 		    _bfd_error_handler
 		      /* xgettext:c-format */
-		      (_("%pB: warning: %s relocation to %#" PRIx64
+		      (_("%pB: %%w: %s relocation to %#" PRIx64
 			 " from %pA section"),
 		      input_bfd, howto->name, (uint64_t) outrel.r_addend,
 		      input_section);
diff --git a/bfd/elf64-alpha.c b/bfd/elf64-alpha.c
index ce50291cd3f..c8de64eb282 100644
--- a/bfd/elf64-alpha.c
+++ b/bfd/elf64-alpha.c
@@ -2972,7 +2972,7 @@  elf64_alpha_relax_got_load (struct alpha_relax_info *info, bfd_vma symval,
       reloc_howto_type *howto = elf64_alpha_howto_table + r_type;
       _bfd_error_handler
 	/* xgettext:c-format */
-	(_("%pB: %pA+%#" PRIx64 ": warning: "
+	(_("%pB: %pA+%#" PRIx64 ": %%w: "
 	   "%s relocation against unexpected insn"),
 	 info->abfd, info->sec, (uint64_t) irel->r_offset, howto->name);
       return true;
@@ -3167,7 +3167,7 @@  elf64_alpha_relax_with_lituse (struct alpha_relax_info *info,
     {
       _bfd_error_handler
 	/* xgettext:c-format */
-	(_("%pB: %pA+%#" PRIx64 ": warning: "
+	(_("%pB: %pA+%#" PRIx64 ": %%w: "
 	   "%s relocation against unexpected insn"),
 	 abfd, info->sec, (uint64_t) irel->r_offset, "LITERAL");
       return true;
diff --git a/bfd/elf64-ia64-vms.c b/bfd/elf64-ia64-vms.c
index 2f37e90cc15..feb4b4fbf61 100644
--- a/bfd/elf64-ia64-vms.c
+++ b/bfd/elf64-ia64-vms.c
@@ -5147,14 +5147,14 @@  elf64_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
 		  if (normal_bfd == NULL)
 		    _bfd_error_handler
 		      /* xgettext:c-format */
-		      (_("warning: alignment %u of common symbol `%s' in %pB"
+		      (_("%%w: alignment %u of common symbol `%s' in %pB"
 			 " is greater than the alignment (%u) of its section %pA"),
 		       1 << common_align, name, common_bfd,
 		       1 << normal_align, h->root.u.def.section);
 		  else
 		    _bfd_error_handler
 		      /* xgettext:c-format */
-		      (_("warning: alignment %u of symbol `%s' in %pB"
+		      (_("%%w: alignment %u of symbol `%s' in %pB"
 			 " is smaller than %u in %pB"),
 		       1 << normal_align, name, normal_bfd,
 		       1 << common_align, common_bfd);
@@ -5170,7 +5170,7 @@  elf64_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
 		  && ! size_change_ok)
 		_bfd_error_handler
 		  /* xgettext:c-format */
-		  (_("warning: size of symbol `%s' changed"
+		  (_("%%w: size of symbol `%s' changed"
 		     " from %" PRIu64 " in %pB to %" PRIu64 " in %pB"),
 		   name, (uint64_t) h->size, old_bfd,
 		   (uint64_t) isym->st_size, abfd);
@@ -5197,7 +5197,7 @@  elf64_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
 		  if (h->type != STT_NOTYPE && ! type_change_ok)
 		    _bfd_error_handler
 		      /* xgettext:c-format */
-		      (_("warning: type of symbol `%s' changed"
+		      (_("%%w: type of symbol `%s' changed"
 			 " from %d to %d in %pB"),
 		       name, h->type, type, abfd);
 
diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
index cf68124ec12..ffaf626a7d1 100644
--- a/bfd/elf64-ppc.c
+++ b/bfd/elf64-ppc.c
@@ -1358,7 +1358,7 @@  ppc64_elf_reloc_name_lookup (bfd *abfd, const char *r_name)
   for (i = 0; i < ARRAY_SIZE (compat_map); i++)
     if (strcasecmp (compat_map[i][0], r_name) == 0)
       {
-	_bfd_error_handler (_("warning: %s should be used rather than %s"),
+	_bfd_error_handler (_("%%w: %s should be used rather than %s"),
 			    compat_map[i][1], compat_map[i][0]);
 	return ppc64_elf_reloc_name_lookup (abfd, compat_map[i][1]);
       }
@@ -7974,7 +7974,7 @@  ppc64_elf_tls_setup (struct bfd_link_info *info)
 	 __glink_PLTresolve save of r2 is incompatible with code
 	 making tail calls, because the tail call might go via the
 	 resolver and thus overwrite the proper saved r2.  */
-      _bfd_error_handler (_("warning: --plt-localentry is incompatible with "
+      _bfd_error_handler (_("%%w: --plt-localentry is incompatible with "
 			    "power10 pc-relative code"));
       htab->params->plt_localentry0 = 0;
     }
@@ -7982,7 +7982,7 @@  ppc64_elf_tls_setup (struct bfd_link_info *info)
       && elf_link_hash_lookup (&htab->elf, "GLIBC_2.26",
 			       false, false, false) == NULL)
     _bfd_error_handler
-      (_("warning: --plt-localentry is especially dangerous without "
+      (_("%%w: --plt-localentry is especially dangerous without "
 	 "ld.so support to detect ABI violations"));
 
   tga = elf_link_hash_lookup (&htab->elf, ".__tls_get_addr",
@@ -8504,7 +8504,7 @@  ppc64_elf_tls_optimize (struct bfd_link_info *info)
 			    {
 			      /* xgettext:c-format */
 			      info->callbacks->minfo
-				(_("%H: warning: %s unexpected insn %#x.\n"),
+				(_("%H: %%w: %s unexpected insn %#x.\n"),
 				 ibfd, sec, off, "R_PPC64_TPREL16_HA", insn);
 			      htab->do_tls_opt = 0;
 			    }
@@ -10522,7 +10522,7 @@  ppc64_elf_size_dynamic_sections (bfd *output_bfd,
 	}
 
       if (bfd_is_abs_section (s->output_section))
-	_bfd_error_handler (_("warning: discarding dynamic section %s"),
+	_bfd_error_handler (_("%%w: discarding dynamic section %s"),
 			    s->name);
 
       if ((s->flags & SEC_HAS_CONTENTS) == 0)
diff --git a/bfd/elfcode.h b/bfd/elfcode.h
index 1e0784611bc..fc363550d9b 100644
--- a/bfd/elfcode.h
+++ b/bfd/elfcode.h
@@ -339,7 +339,7 @@  elf_swap_shdr_in (bfd *abfd,
 	      || dst->sh_size > filesize - dst->sh_offset)
 	  && !abfd->read_only)
 	{
-	  _bfd_error_handler (_("warning: %pB has a section "
+	  _bfd_error_handler (_("%%w: %pB has a section "
 				"extending past end of file"), abfd);
 	  abfd->read_only = 1;
 	}
@@ -787,7 +787,7 @@  elf_object_p (bfd *abfd)
 	  if (!abfd->read_only)
 	    {
 	      _bfd_error_handler
-		(_("warning: %pB has a corrupt string table index"), abfd);
+		(_("%%w: %pB has a corrupt string table index"), abfd);
 	      abfd->read_only = 1;
 	    }
 	}
@@ -835,7 +835,7 @@  elf_object_p (bfd *abfd)
 	      i_phdr->p_align &= -i_phdr->p_align;
 	      if (!abfd->read_only)
 		{
-		  _bfd_error_handler (_("warning: %pB has a program header "
+		  _bfd_error_handler (_("%%w: %pB has a program header "
 					"with invalid alignment"), abfd);
 		  abfd->read_only = 1;
 		}
diff --git a/bfd/elfcore.h b/bfd/elfcore.h
index 3f81145392a..04285843cd3 100644
--- a/bfd/elfcore.h
+++ b/bfd/elfcore.h
@@ -277,7 +277,7 @@  elf_core_file_p (bfd *abfd)
 	      && (p->p_offset >= filesize
 		  || p->p_filesz > filesize - p->p_offset))
 	    {
-	      _bfd_error_handler (_("warning: %pB has a segment "
+	      _bfd_error_handler (_("%%w: %pB has a segment "
 				    "extending past end of file"), abfd);
 	      abfd->read_only = 1;
 	      break;
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 35c1c7e01e0..03c87d24786 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -3266,7 +3266,7 @@  _bfd_elf_adjust_dynamic_symbol (struct elf_link_hash_entry *h, void *data)
       && h->type == STT_NOTYPE
       && !h->needs_plt)
     _bfd_error_handler
-      (_("warning: type and size of dynamic symbol `%s' are not defined"),
+      (_("%%w: type and size of dynamic symbol `%s' are not defined"),
        h->root.root.string);
 
   if (! (*bed->elf_backend_adjust_dynamic_symbol) (eif->info, h))
@@ -5335,21 +5335,21 @@  elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
 		  if (normal_bfd == NULL)
 		    _bfd_error_handler
 		      /* xgettext:c-format */
-		      (_("warning: alignment %u of common symbol `%s' in %pB is"
+		      (_("%%w: alignment %u of common symbol `%s' in %pB is"
 			 " greater than the alignment (%u) of its section %pA"),
 		       1 << common_align, name, common_bfd,
 		       1 << normal_align, h->root.u.def.section);
 		  else
 		    _bfd_error_handler
 		      /* xgettext:c-format */
-		      (_("warning: alignment %u of normal symbol `%s' in %pB"
+		      (_("%%w: alignment %u of normal symbol `%s' in %pB"
 			 " is smaller than %u used by the common definition in %pB"),
 		       1 << normal_align, name, normal_bfd,
 		       1 << common_align, common_bfd);
 
 		  /* PR 30499: make sure that users understand that this warning is serious.  */
 		  _bfd_error_handler
-		    (_("warning: NOTE: alignment discrepancies can cause real problems.  Investigation is advised."));
+		    (_("%%w: NOTE: alignment discrepancies can cause real problems.  Investigation is advised."));
 		}
 	    }
 
@@ -5364,14 +5364,14 @@  elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
 		{
 		  _bfd_error_handler
 		    /* xgettext:c-format */
-		    (_("warning: size of symbol `%s' changed"
+		    (_("%%w: size of symbol `%s' changed"
 		       " from %" PRIu64 " in %pB to %" PRIu64 " in %pB"),
 		     name, (uint64_t) h->size, old_bfd,
 		     (uint64_t) isym->st_size, abfd);
 
 		  /* PR 30499: make sure that users understand that this warning is serious.  */
 		  _bfd_error_handler
-		    (_("warning: NOTE: size discrepancies can cause real problems.  Investigation is advised."));
+		    (_("%%w: NOTE: size discrepancies can cause real problems.  Investigation is advised."));
 		}
 
 	      h->size = isym->st_size;
@@ -5404,7 +5404,7 @@  elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
 		  if (h->type != STT_NOTYPE && ! type_change_ok)
 		    /* xgettext:c-format */
 		    _bfd_error_handler
-		      (_("warning: type of symbol `%s' changed"
+		      (_("%%w: type of symbol `%s' changed"
 			 " from %d to %d in %pB"),
 		       name, h->type, type, abfd);
 
@@ -7185,7 +7185,7 @@  error: creating an executable stack because of -z execstack command line option"
 
 	  _bfd_error_handler
 	    (_("\
-warning: enabling an executable stack because of -z execstack command line option"));
+%%w: enabling an executable stack because of -z execstack command line option"));
 	}
 
       elf_stack_flags (output_bfd) = PF_R | PF_W | PF_X;
@@ -7253,7 +7253,7 @@  error: %s: is triggering the generation of an executable stack (because it has a
 			}
 
 		      _bfd_error_handler (_("\
-warning: %s: requires executable stack (because the .note.GNU-stack section is executable)"),
+%%w: %s: requires executable stack (because the .note.GNU-stack section is executable)"),
 		       bfd_get_filename (noteobj));
 		    }
 		  else if (emptyobj)
@@ -7267,7 +7267,7 @@  error: %s: is triggering the generation of an executable stack because it does n
 			}
 
 		      _bfd_error_handler (_("\
-warning: %s: missing .note.GNU-stack section implies executable stack"),
+%%w: %s: missing .note.GNU-stack section implies executable stack"),
 					  bfd_get_filename (emptyobj));
 		      _bfd_error_handler (_("\
 NOTE: This behaviour is deprecated and will be removed in a future version of the linker"));
@@ -13327,7 +13327,7 @@  bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
 		}
 	      if (o->size == 0)
 		_bfd_error_handler
-		  (_("warning: %s section has zero size"), name);
+		  (_("%%w: %s section has zero size"), name);
 	      dyn.d_un.d_val = o->size;
 	      break;
 
@@ -13375,7 +13375,7 @@  bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
 	      if (elf_section_data (o->output_section)->this_hdr.sh_type == SHT_NOTE)
 		{
 		  _bfd_error_handler
-		    (_("warning: section '%s' is being made into a note"), name);
+		    (_("%%w: section '%s' is being made into a note"), name);
 		  bfd_set_error (bfd_error_nonrepresentable_section);
 		  goto error_return;
 		}
@@ -14386,7 +14386,7 @@  bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
   if (!bed->can_gc_sections
       || !is_elf_hash_table (info->hash))
     {
-      _bfd_error_handler(_("warning: gc-sections option ignored"));
+      _bfd_error_handler(_("%%w: gc-sections option ignored"));
       return true;
     }
 
diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index 109517db4aa..39fd126c2a4 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -10228,14 +10228,14 @@  elfNN_aarch64_merge_gnu_properties (struct bfd_link_info *info,
       if ((aprop && !(aprop->u.number & GNU_PROPERTY_AARCH64_FEATURE_1_BTI))
 	   || !aprop)
 	{
-	  _bfd_error_handler (_("%pB: warning: BTI turned on by -z force-bti when "
+	  _bfd_error_handler (_("%pB: %%w: BTI turned on by -z force-bti when "
 				"all inputs do not have BTI in NOTE section."),
 			      abfd);
 	}
       if ((bprop && !(bprop->u.number & GNU_PROPERTY_AARCH64_FEATURE_1_BTI))
 	   || !bprop)
 	{
-	  _bfd_error_handler (_("%pB: warning: BTI turned on by -z force-bti when "
+	  _bfd_error_handler (_("%pB: %%w: BTI turned on by -z force-bti when "
 				"all inputs do not have BTI in NOTE section."),
 			      bbfd);
 	}
diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
index b2caa5fc3e1..2354f2010bf 100644
--- a/bfd/elfnn-loongarch.c
+++ b/bfd/elfnn-loongarch.c
@@ -2445,7 +2445,7 @@  loongarch_reloc_is_fatal (struct bfd_link_info *info,
 			     is_undefweak ? "[undefweak] " : "", name, msg);
       break;
     case bfd_reloc_dangerous:
-      info->callbacks->info ("%pB(%pA+0x%v): warning: %s against %s`%s':\n%s\n",
+      info->callbacks->info ("%pB(%pA+0x%v): %%w: %s against %s`%s':\n%s\n",
 			     input_bfd, input_section, rel->r_offset,
 			     howto->name,
 			     is_undefweak ? "[undefweak] " : "", name, msg);
diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 8b27e3b8d6a..4ca9da26984 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -323,7 +323,7 @@  riscv_make_plt_header (bfd *output_bfd, bfd_vma gotplt_addr, bfd_vma addr,
   /* RVE has no t3 register, so this won't work, and is not supported.  */
   if (elf_elfheader (output_bfd)->e_flags & EF_RISCV_RVE)
     {
-      _bfd_error_handler (_("%pB: warning: RVE PLT generation not supported"),
+      _bfd_error_handler (_("%pB: %%w: RVE PLT generation not supported"),
 			  output_bfd);
       return false;
     }
@@ -358,7 +358,7 @@  riscv_make_plt_entry (bfd *output_bfd, bfd_vma got, bfd_vma addr,
   /* RVE has no t3 register, so this won't work, and is not supported.  */
   if (elf_elfheader (output_bfd)->e_flags & EF_RISCV_RVE)
     {
-      _bfd_error_handler (_("%pB: warning: RVE PLT generation not supported"),
+      _bfd_error_handler (_("%pB: %%w: RVE PLT generation not supported"),
 			  output_bfd);
       return false;
     }
@@ -2546,7 +2546,7 @@  riscv_elf_relocate_section (bfd *output_bfd,
 		 warnings/errors in assembler.  */
 	      if (htab->params->check_uleb128
 		  && rel->r_addend != 0)
-		_bfd_error_handler (_("%pB: warning: R_RISCV_SUB_ULEB128 with"
+		_bfd_error_handler (_("%pB: %%w: R_RISCV_SUB_ULEB128 with"
 				      " non-zero addend, please rebuild by"
 				      " binutils 2.42 or up"), input_bfd);
 	    }
@@ -3939,7 +3939,7 @@  riscv_merge_attributes (bfd *ibfd, struct bfd_link_info *info)
 		     && in_priv_spec != out_priv_spec)
 	      {
 		_bfd_error_handler
-		  (_("warning: %pB use privileged spec version %u.%u.%u but "
+		  (_("%%w: %pB use privileged spec version %u.%u.%u but "
 		     "the output use version %u.%u.%u"),
 		   ibfd,
 		   in_attr[Tag_a].i,
@@ -3956,7 +3956,7 @@  riscv_merge_attributes (bfd *ibfd, struct bfd_link_info *info)
 		    || out_priv_spec == PRIV_SPEC_CLASS_1P9P1)
 		  {
 		    _bfd_error_handler
-		      (_("warning: privileged spec version 1.9.1 can not be "
+		      (_("%%w: privileged spec version 1.9.1 can not be "
 			 "linked with other spec versions"));
 		  }
 
diff --git a/bfd/elfxx-aarch64.c b/bfd/elfxx-aarch64.c
index d1279adc2e4..15a099e9314 100644
--- a/bfd/elfxx-aarch64.c
+++ b/bfd/elfxx-aarch64.c
@@ -474,7 +474,7 @@  _bfd_aarch64_elf_resolve_relocation (bfd *input_bfd,
 	 case we choose to emit 0.  */
       if (weak_undef_p && tls_reloc)
 	{
-	  _bfd_error_handler (_("%pB: warning: Weak TLS is implementation "
+	  _bfd_error_handler (_("%pB: %%w: Weak TLS is implementation "
 				"defined and may not work as expected"),
 				input_bfd);
 	  value = place;
@@ -735,7 +735,7 @@  _bfd_aarch64_elf_link_setup_gnu_properties (struct bfd_link_info *info,
 				    4);
       if (gnu_prop & GNU_PROPERTY_AARCH64_FEATURE_1_BTI
 	  && !(prop->u.number & GNU_PROPERTY_AARCH64_FEATURE_1_BTI))
-	    _bfd_error_handler (_("%pB: warning: BTI turned on by -z force-bti "
+	    _bfd_error_handler (_("%pB: %%w: BTI turned on by -z force-bti "
 				  "when all inputs do not have BTI in NOTE "
 				  "section."), ebfd);
       prop->u.number |= gnu_prop;
diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
index 69dd71419ff..46a030aee28 100644
--- a/bfd/elfxx-mips.c
+++ b/bfd/elfxx-mips.c
@@ -7391,7 +7391,7 @@  _bfd_mips_elf_section_processing (bfd *abfd, Elf_Internal_Shdr *hdr)
 	    {
 	      _bfd_error_handler
 		/* xgettext:c-format */
-		(_("%pB: warning: bad `%s' option size %u smaller than"
+		(_("%pB: %%w: bad `%s' option size %u smaller than"
 		   " its header"),
 		abfd, MIPS_ELF_OPTIONS_SECTION_NAME (abfd), intopt.size);
 	      break;
@@ -7627,7 +7627,7 @@  _bfd_mips_elf_section_from_shdr (bfd *abfd,
 	    bad_opt:
 	      _bfd_error_handler
 		/* xgettext:c-format */
-		(_("%pB: warning: truncated `%s' option"),
+		(_("%pB: %%w: truncated `%s' option"),
 		 abfd, MIPS_ELF_OPTIONS_SECTION_NAME (abfd));
 	      break;
 	    }
@@ -8451,7 +8451,7 @@  _bfd_mips_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
 	{
 	  _bfd_error_handler
 	    /* xgettext:c-format */
-	    (_("%pB: warning: cannot determine the target function for"
+	    (_("%pB: %%w: cannot determine the target function for"
 	       " stub section `%s'"),
 	     abfd, name);
 	  bfd_set_error (bfd_error_bad_value);
@@ -8577,7 +8577,7 @@  _bfd_mips_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
 	{
 	  _bfd_error_handler
 	    /* xgettext:c-format */
-	    (_("%pB: warning: cannot determine the target function for"
+	    (_("%pB: %%w: cannot determine the target function for"
 	       " stub section `%s'"),
 	     abfd, name);
 	  bfd_set_error (bfd_error_bad_value);
@@ -15543,7 +15543,7 @@  mips_elf_merge_obj_e_flags (bfd *ibfd, struct bfd_link_info *info)
       != ((old_flags & (EF_MIPS_PIC | EF_MIPS_CPIC)) != 0))
     {
       _bfd_error_handler
-	(_("%pB: warning: linking abicalls files with non-abicalls files"),
+	(_("%pB: %%w: linking abicalls files with non-abicalls files"),
 	 ibfd);
       ok = true;
     }
@@ -15775,19 +15775,19 @@  mips_elf_merge_obj_attributes (bfd *ibfd, struct bfd_link_info *info)
 	  if (!out_string && !in_string)
 	    /* xgettext:c-format */
 	    _bfd_error_handler
-	      (_("warning: %pB uses unknown floating point ABI %d "
+	      (_("%%w: %pB uses unknown floating point ABI %d "
 		 "(set by %pB), %pB uses unknown floating point ABI %d"),
 	       obfd, out_fp, abi_fp_bfd, ibfd, in_fp);
 	  else if (!out_string)
 	    _bfd_error_handler
 	      /* xgettext:c-format */
-	      (_("warning: %pB uses unknown floating point ABI %d "
+	      (_("%%w: %pB uses unknown floating point ABI %d "
 		 "(set by %pB), %pB uses %s"),
 	       obfd, out_fp, abi_fp_bfd, ibfd, in_string);
 	  else if (!in_string)
 	    _bfd_error_handler
 	      /* xgettext:c-format */
-	      (_("warning: %pB uses %s (set by %pB), "
+	      (_("%%w: %pB uses %s (set by %pB), "
 		 "%pB uses unknown floating point ABI %d"),
 	       obfd, out_string, abi_fp_bfd, ibfd, in_fp);
 	  else
@@ -15801,7 +15801,7 @@  mips_elf_merge_obj_attributes (bfd *ibfd, struct bfd_link_info *info)
 		in_string = "-mhard-float";
 	      _bfd_error_handler
 		/* xgettext:c-format */
-		(_("warning: %pB uses %s (set by %pB), %pB uses %s"),
+		(_("%%w: %pB uses %s (set by %pB), %pB uses %s"),
 		 obfd, out_string, abi_fp_bfd, ibfd, in_string);
 	    }
 	}
@@ -15820,7 +15820,7 @@  mips_elf_merge_obj_attributes (bfd *ibfd, struct bfd_link_info *info)
 	  case Val_GNU_MIPS_ABI_MSA_128:
 	    _bfd_error_handler
 	      /* xgettext:c-format */
-	      (_("warning: %pB uses %s (set by %pB), "
+	      (_("%%w: %pB uses %s (set by %pB), "
 		 "%pB uses unknown MSA ABI %d"),
 	       obfd, "-mmsa", abi_msa_bfd,
 	       ibfd, in_attr[Tag_GNU_MIPS_ABI_MSA].i);
@@ -15832,7 +15832,7 @@  mips_elf_merge_obj_attributes (bfd *ibfd, struct bfd_link_info *info)
 	      case Val_GNU_MIPS_ABI_MSA_128:
 		_bfd_error_handler
 		  /* xgettext:c-format */
-		  (_("warning: %pB uses unknown MSA ABI %d "
+		  (_("%%w: %pB uses unknown MSA ABI %d "
 		     "(set by %pB), %pB uses %s"),
 		     obfd, out_attr[Tag_GNU_MIPS_ABI_MSA].i,
 		   abi_msa_bfd, ibfd, "-mmsa");
@@ -15841,7 +15841,7 @@  mips_elf_merge_obj_attributes (bfd *ibfd, struct bfd_link_info *info)
 	      default:
 		_bfd_error_handler
 		  /* xgettext:c-format */
-		  (_("warning: %pB uses unknown MSA ABI %d "
+		  (_("%%w: %pB uses unknown MSA ABI %d "
 		     "(set by %pB), %pB uses unknown MSA ABI %d"),
 		   obfd, out_attr[Tag_GNU_MIPS_ABI_MSA].i,
 		   abi_msa_bfd, ibfd, in_attr[Tag_GNU_MIPS_ABI_MSA].i);
@@ -15970,27 +15970,27 @@  _bfd_mips_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
       if (LEVEL_REV (in_abiflags.isa_level, in_abiflags.isa_rev)
 	  < LEVEL_REV (abiflags.isa_level, abiflags.isa_rev))
 	_bfd_error_handler
-	  (_("%pB: warning: inconsistent ISA between e_flags and "
+	  (_("%pB: %%w: inconsistent ISA between e_flags and "
 	     ".MIPS.abiflags"), ibfd);
       if (abiflags.fp_abi != Val_GNU_MIPS_ABI_FP_ANY
 	  && in_abiflags.fp_abi != abiflags.fp_abi)
 	_bfd_error_handler
-	  (_("%pB: warning: inconsistent FP ABI between .gnu.attributes and "
+	  (_("%pB: %%w: inconsistent FP ABI between .gnu.attributes and "
 	     ".MIPS.abiflags"), ibfd);
       if ((in_abiflags.ases & abiflags.ases) != abiflags.ases)
 	_bfd_error_handler
-	  (_("%pB: warning: inconsistent ASEs between e_flags and "
+	  (_("%pB: %%w: inconsistent ASEs between e_flags and "
 	     ".MIPS.abiflags"), ibfd);
       /* The isa_ext is allowed to be an extension of what can be inferred
 	 from e_flags.  */
       if (!mips_mach_extends_p (bfd_mips_isa_ext_mach (abiflags.isa_ext),
 				bfd_mips_isa_ext_mach (in_abiflags.isa_ext)))
 	_bfd_error_handler
-	  (_("%pB: warning: inconsistent ISA extensions between e_flags and "
+	  (_("%pB: %%w: inconsistent ISA extensions between e_flags and "
 	     ".MIPS.abiflags"), ibfd);
       if (in_abiflags.flags2 != 0)
 	_bfd_error_handler
-	  (_("%pB: warning: unexpected flag in the flags2 field of "
+	  (_("%pB: %%w: unexpected flag in the flags2 field of "
 	     ".MIPS.abiflags (0x%lx)"), ibfd,
 	   in_abiflags.flags2);
     }
diff --git a/bfd/format.c b/bfd/format.c
index 47c3e9ba35a..adf289f95b2 100644
--- a/bfd/format.c
+++ b/bfd/format.c
@@ -353,7 +353,8 @@  bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
   /* Don't report errors on recursive calls checking the first element
      of an archive.  */
   if (in_check_format)
-    orig_error_handler = bfd_set_error_handler (null_error_handler);
+    orig_error_handler = bfd_set_error_handler (null_error_handler,
+						NULL);
   else
     orig_error_handler = _bfd_set_error_handler_caching (abfd);
   ++in_check_format;
@@ -598,7 +599,7 @@  bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
       if (preserve_match.marker != NULL)
 	bfd_preserve_finish (abfd, &preserve_match);
       bfd_preserve_finish (abfd, &preserve);
-      bfd_set_error_handler (orig_error_handler);
+      bfd_set_error_handler (orig_error_handler, NULL);
 
       struct per_xvec_message **list = _bfd_per_xvec_warn (abfd->xvec, 0);
       if (*list)
@@ -650,7 +651,7 @@  bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
   if (preserve_match.marker != NULL)
     bfd_preserve_finish (abfd, &preserve_match);
   bfd_preserve_restore (abfd, &preserve);
-  bfd_set_error_handler (orig_error_handler);
+  bfd_set_error_handler (orig_error_handler, NULL);
   struct per_xvec_message **list = _bfd_per_xvec_warn (NULL, 0);
   struct per_xvec_message **one = NULL;
   for (size_t i = 0; i < _bfd_target_vector_entries + 1; i++)
diff --git a/bfd/mmo.c b/bfd/mmo.c
index 485a1c3ca33..9526df58d75 100644
--- a/bfd/mmo.c
+++ b/bfd/mmo.c
@@ -3111,7 +3111,7 @@  mmo_write_symbols_and_terminator (bfd *abfd)
 
       _bfd_error_handler
 	/* xgettext:c-format */
-	(_("%pB: warning: symbol table too large for mmo, larger than 65535"
+	(_("%pB: %%w: symbol table too large for mmo, larger than 65535"
 	   " 32-bit words: %d.  Only `Main' will be emitted.\n"),
 	 abfd, trie_len);
 
diff --git a/bfd/xcofflink.c b/bfd/xcofflink.c
index 6ef9abcd883..e814f031605 100644
--- a/bfd/xcofflink.c
+++ b/bfd/xcofflink.c
@@ -3499,7 +3499,7 @@  xcoff_build_ldsym (struct xcoff_loader_info *ldinfo,
       && (h->flags & XCOFF_WAS_UNDEFINED) != 0)
     {
       _bfd_error_handler
-	(_("warning: attempt to export undefined symbol `%s'"),
+	(_("%%w: attempt to export undefined symbol `%s'"),
 	 h->root.root.string);
       return true;
     }
diff --git a/ld/ldlang.c b/ld/ldlang.c
index ea85ffd704b..7feab507153 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -7266,7 +7266,7 @@  lang_check (void)
 	     bfd_merge_private_bfd_data, since it may set up
 	     information which is needed in the output file.  */
 	  if (!command_line.warn_mismatch)
-	    pfn = bfd_set_error_handler (ignore_bfd_errors);
+	    pfn = bfd_set_error_handler (ignore_bfd_errors, NULL);
 	  if (!bfd_merge_private_bfd_data (input_bfd, &link_info))
 	    {
 	      if (command_line.warn_mismatch)
@@ -7274,7 +7274,7 @@  lang_check (void)
 			 " of file %pB\n"), input_bfd);
 	    }
 	  if (!command_line.warn_mismatch)
-	    bfd_set_error_handler (pfn);
+	    bfd_set_error_handler (pfn, NULL);
 	}
     }
 }
diff --git a/ld/ldmain.c b/ld/ldmain.c
index 6e4cb767033..82ae00b2cb4 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -275,7 +275,10 @@  main (int argc, char **argv)
   default_bfd_assert_handler = bfd_set_assert_handler (ld_bfd_assert_handler);
 
   /* Also hook the bfd error/warning handler for --fatal-warnings.  */
-  default_bfd_error_handler = bfd_set_error_handler (ld_bfd_error_handler);
+  default_bfd_error_handler
+    = bfd_set_error_handler (ld_bfd_error_handler,
+			     (config.fatal_warnings
+			      ? _("error") : NULL));
 
   xatexit (ld_cleanup);
 
diff --git a/ld/testsuite/ld-elf/fatal-warnings-5.d b/ld/testsuite/ld-elf/fatal-warnings-5.d
new file mode 100644
index 00000000000..dbee94fc9b6
--- /dev/null
+++ b/ld/testsuite/ld-elf/fatal-warnings-5.d
@@ -0,0 +1,6 @@ 
+#source: start.s
+#source: symbol1ref.s
+#source: symbol1w.s
+#ld: -T group.ld --no-warn-rwx-segments --fatal-warnings
+#error: ^[^\n]*\): error: witty one-liner$
+#xfail: [is_generic]
diff --git a/ld/testsuite/ld-scripts/defined.exp b/ld/testsuite/ld-scripts/defined.exp
index bc1ed082d25..7182de4103b 100644
--- a/ld/testsuite/ld-scripts/defined.exp
+++ b/ld/testsuite/ld-scripts/defined.exp
@@ -67,6 +67,7 @@  run_dump_test "defined3"
 run_dump_test "defined4"
 if ![is_aout_format] {
     run_dump_test "defined5"
+    run_dump_test "defined7"
 }
 if [is_elf_format] {
     run_dump_test "defined6"
diff --git a/ld/testsuite/ld-scripts/defined7.d b/ld/testsuite/ld-scripts/defined7.d
new file mode 100644
index 00000000000..f5400d712d5
--- /dev/null
+++ b/ld/testsuite/ld-scripts/defined7.d
@@ -0,0 +1,3 @@ 
+#source: defined5.s
+#ld: -Tdefined5.t --no-error-rwx-segments --fatal-warnings
+#error: .*: error: multiple definition of `defined'.*