[binutils-gdb] MIPS/BFD: Initialize `error_message' in `_bfd_mips_elf_orphan_shr16_reloc'

Maciej W. Rozycki macro@sourceware.org
Thu Jan 15 00:39:38 GMT 2026


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d9001d36830805cfc09993ecede99f0dfd6fd3fb

commit d9001d36830805cfc09993ecede99f0dfd6fd3fb
Author: Maciej W. Rozycki <macro@orcam.me.uk>
Date:   Thu Jan 15 00:37:35 2026 +0000

    MIPS/BFD: Initialize `error_message' in `_bfd_mips_elf_orphan_shr16_reloc'
    
    There is no value assigned in `_bfd_mips_elf_generic_reloc' via the
    `error_message' parameter and consequently the original `error_message'
    variable in `_bfd_mips_elf_orphan_shr16_reloc' remains uninitialized in
    the error case, which newer versions of GCC can correctly diagnose:
    
    In function '_bfd_mips_elf_orphan_shr16_reloc',
        inlined from 'mips_elf_free_hi16_list' at ../../binutils-gdb/bfd/elfxx-mips.c:13309:12:
    ../../binutils-gdb/bfd/elfxx-mips.c:13281:5: error: 'error_message' may be used uninitialized [-Werror=maybe-uninitialized]
    13281 |     _bfd_link_reloc_status_error (abfd, info, hi->input_section,
          |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    13282 |                                   &hi->rel, error_message, r);
          |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../../binutils-gdb/bfd/elfxx-mips.c: In function 'mips_elf_free_hi16_list':
    ../../binutils-gdb/bfd/elfxx-mips.c:13255:9: note: 'error_message' declared here
    13255 |   char *error_message;
          |         ^~~~~~~~~~~~~
    cc1: all warnings being treated as errors
    
    Fix the problem by preinitializing the variable to NULL as at other
    places.

Diff:
---
 bfd/elfxx-mips.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
index 97e6e65d5f1..6d38e492dfc 100644
--- a/bfd/elfxx-mips.c
+++ b/bfd/elfxx-mips.c
@@ -13253,8 +13253,8 @@ _bfd_mips_elf_orphan_shr16_reloc (bfd *abfd, asection *sec,
 {
   asymbol *symbol = *hi->rel.sym_ptr_ptr;
   const char *name = hi->rel.howto->name;
+  char *error_message = NULL;
   bfd_reloc_status_type r;
-  char *error_message;
 
   r = _bfd_mips_elf_shr16_reloc (abfd, &hi->rel, symbol, hi->data,
 				 sec, hi->output_bfd, &error_message);


More information about the Binutils-cvs mailing list