@@ -3720,8 +3720,8 @@ nios2_elf32_relocate_section (bfd *output_bfd,
37203720 const char * name = NULL ;
37213721 int r_type ;
37223722 const char * format ;
3723- char msgbuf [ 256 ] ;
3724- const char * msg = ( const char * ) NULL ;
3723+ char * msgbuf = NULL ;
3724+ char * msg = NULL ;
37253725 bfd_boolean unresolved_reloc ;
37263726 bfd_vma off ;
37273727 int use_plt ;
@@ -3820,8 +3820,8 @@ nios2_elf32_relocate_section (bfd *output_bfd,
38203820 reloc_address = 0 ;
38213821
38223822 format = _ ("global pointer relative relocation at address "
3823- "0x%08x when _gp not defined\n" );
3824- sprintf ( msgbuf , format , reloc_address );
3823+ "%#" PRIx64 " when _gp not defined\n" );
3824+ asprintf ( & msgbuf , format , ( uint64_t ) reloc_address );
38253825 msg = msgbuf ;
38263826 r = bfd_reloc_dangerous ;
38273827 }
@@ -3838,13 +3838,22 @@ nios2_elf32_relocate_section (bfd *output_bfd,
38383838 {
38393839 if (h )
38403840 name = h -> root .root .string ;
3841+ else
3842+ {
3843+ name = (bfd_elf_string_from_elf_section
3844+ (input_bfd , symtab_hdr -> sh_link ,
3845+ sym -> st_name ));
3846+ if (name == NULL || * name == '\0' )
3847+ name = bfd_section_name (input_bfd , sec );
3848+ }
38413849 /* xgettext:c-format */
3842- format = _ ("unable to reach %s (at 0x%08x) from the "
3843- "global pointer (at 0x%08x) because the "
3844- "offset (%d) is out of the allowed range, "
3845- "-32678 to 32767\n" );
3846- sprintf (msgbuf , format , name , symbol_address , gp ,
3847- (signed )relocation );
3850+ format = _ ("unable to reach %s (at %#" PRIx64 ") from "
3851+ "the global pointer (at %#" PRIx64 ") "
3852+ "because the offset (%" PRId64 ") is out of "
3853+ "the allowed range, -32678 to 32767\n" );
3854+ asprintf (& msgbuf , format , name ,
3855+ (uint64_t ) symbol_address , (uint64_t ) gp ,
3856+ (int64_t ) relocation );
38483857 msg = msgbuf ;
38493858 r = bfd_reloc_outofrange ;
38503859 }
@@ -4515,6 +4524,8 @@ nios2_elf32_relocate_section (bfd *output_bfd,
45154524 {
45164525 (* info -> callbacks -> warning ) (info , msg , name , input_bfd ,
45174526 input_section , rel -> r_offset );
4527+ if (msgbuf )
4528+ free (msgbuf );
45184529 return FALSE;
45194530 }
45204531 }
0 commit comments