This is the mail archive of the binutils-cvs@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Support %Lx, %Lu, %Ld in _bfd_error_handler format


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

commit 76cfced5addbd827652688a13f9cfa02afce51a5
Author: Alan Modra <amodra@gmail.com>
Date:   Mon Jul 3 21:59:45 2017 +0930

    Support %Lx, %Lu, %Ld in _bfd_error_handler format
    
    One way to print 64-bit bfd_vma or bfd_size_type values on 32-bit
    hosts is to cast the value to long long and use the 'll' modifier in
    printf format strings.  However, that's awkward because we also
    support the Microsoft C library printf that uses 'I64' as a modifier
    instead, and having variants of translated strings would not endear us
    to the translation project.  So, rewrite the 'll' modifier in
    _doprint for Microsoft.  Even with that capability it's not so nice
    for 32-bit code to need casts to long long, so this patch makes 'L' a
    modifier for bfd_vma rather than an alias for 'll'.
    
    I've then used the new 'L' modifier to fix selected format strings.
    
    	* bfd.c (_doprnt): Rewrite "ll" and "L" modifiers to "I64" for
    	__MSVCRT__.  Support "L" modifier for bfd_vma.  Formatting.
    	* elf.c (setup_group): Use "Lx" to print sh_size.
    	(_bfd_elf_setup_sections): Remove unnecessary cast and print
    	unknown section type in hex.
    	(copy_special_section_fields): Style fix.
    	(bfd_section_from_shdr): Correct format for sh_link.  Use a
    	common error message for all the variants of unrecognized
    	section types.
    	(assign_file_positions_for_load_sections): Use "Lx" for lma
    	adjust error message.
    	(assign_file_positions_for_non_load_sections): Formatting.
    	(rewrite_elf_program_header): Formatting.  Use "Lx" for
    	bfd_vma values in error messages.
    	* elfcode.h (elf_slurp_reloc_table_from_section): Cast
    	ELF_R_SYM value to type expected by format.
    	* elflink.c (elf_link_read_relocs_from_section): Use "Lx"
    	in error messages.
    	(elf_link_add_object_symbols): Use "Lu" for symbol sizes.
    	(elf_link_input_bfd): Use "Lx" for r_info.
    	(bfd_elf_gc_record_vtinherit): Use "Lx" for offset.

Diff:
---
 bfd/ChangeLog | 24 ++++++++++++++++++++++++
 bfd/bfd.c     | 24 +++++++++++++++++++++---
 bfd/elf.c     | 54 ++++++++++++++++++++++++++----------------------------
 bfd/elfcode.h |  2 +-
 bfd/elflink.c | 24 ++++++++++--------------
 5 files changed, 82 insertions(+), 46 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 74cb0c9..523610f 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,29 @@
 2017-07-03  Alan Modra  <amodra@gmail.com>
 
+	* bfd.c (_doprnt): Rewrite "ll" and "L" modifiers to "I64" for
+	__MSVCRT__.  Support "L" modifier for bfd_vma.  Formatting.
+	* elf.c (setup_group): Use "Lx" to print sh_size.
+	(_bfd_elf_setup_sections): Remove unnecessary cast and print
+	unknown section type in hex.
+	(copy_special_section_fields): Style fix.
+	(bfd_section_from_shdr): Correct format for sh_link.  Use a
+	common error message for all the variants of unrecognized
+	section types.
+	(assign_file_positions_for_load_sections): Use "Lx" for lma
+	adjust error message.
+	(assign_file_positions_for_non_load_sections): Formatting.
+	(rewrite_elf_program_header): Formatting.  Use "Lx" for
+	bfd_vma values in error messages.
+	* elfcode.h (elf_slurp_reloc_table_from_section): Cast
+	ELF_R_SYM value to type expected by format.
+	* elflink.c (elf_link_read_relocs_from_section): Use "Lx"
+	in error messages.
+	(elf_link_add_object_symbols): Use "Lu" for symbol sizes.
+	(elf_link_input_bfd): Use "Lx" for r_info.
+	(bfd_elf_gc_record_vtinherit): Use "Lx" for offset.
+
+2017-07-03  Alan Modra  <amodra@gmail.com>
+
 	* bfd.c (bfd_scan_vma): Don't use long long unless HAVE_LONG_LONG.
 	* coff-rs6000.c (FMT20): Handle hosts with 64-bit long and
 	Microsoft C library variant of long long format specifier.
diff --git a/bfd/bfd.c b/bfd/bfd.c
index 9c0175f..b6cdf3f 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -612,7 +612,9 @@ CODE_FRAGMENT
 static const char *_bfd_error_program_name;
 
 /* This macro and _doprnt taken from libiberty _doprnt.c, tidied a
-   little and extended to handle '%A' and '%B'.  */
+   little and extended to handle '%A' and '%B'.  'L' as a modifer for
+   integer formats is used for bfd_vma and bfd_size_type args, which
+   vary in size depending on BFD configuration.  */
 
 #define PRINT_TYPE(TYPE) \
   do								\
@@ -721,6 +723,12 @@ _doprnt (FILE *stream, const char *format, va_list ap)
 		  PRINT_TYPE (int);
 		else
 		  {
+		    /* L modifier for bfd_vma or bfd_size_type may be
+		       either long long or long.  */
+		    if ((BFD_ARCH_SIZE < 64 || BFD_HOST_64BIT_LONG)
+			&& sptr[-2] == 'L')
+		      wide_width = 1;
+
 		    switch (wide_width)
 		      {
 		      case 0:
@@ -731,7 +739,17 @@ _doprnt (FILE *stream, const char *format, va_list ap)
 			break;
 		      case 2:
 		      default:
-#if defined(__GNUC__) || defined(HAVE_LONG_LONG)
+#if defined (__GNUC__) || defined (HAVE_LONG_LONG)
+# if defined (__MSVCRT__)
+			sptr--;
+			while (sptr[-1] == 'L' || sptr[-1] == 'l')
+			  sptr--;
+			*sptr++ = 'I';
+			*sptr++ = '6';
+			*sptr++ = '4';
+			*sptr++ = ptr[-1];
+			*sptr = '\0';
+# endif
 			PRINT_TYPE (long long);
 #else
 			/* Fake it and hope for the best.  */
@@ -752,7 +770,7 @@ _doprnt (FILE *stream, const char *format, va_list ap)
 		  PRINT_TYPE (double);
 		else
 		  {
-#if defined(__GNUC__) || defined(HAVE_LONG_DOUBLE)
+#if defined (__GNUC__) || defined (HAVE_LONG_DOUBLE)
 		    PRINT_TYPE (long double);
 #else
 		    /* Fake it and hope for the best.  */
diff --git a/bfd/elf.c b/bfd/elf.c
index 9fec4b5..063a6e4 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -658,7 +658,7 @@ setup_group (bfd *abfd, Elf_Internal_Shdr *hdr, asection *newsect)
 		      _bfd_error_handler
 			/* xgettext:c-format */
 			(_("%B: corrupt size field in group section"
-			   " header: 0x%lx"), abfd, shdr->sh_size);
+			   " header: %#Lx"), abfd, shdr->sh_size);
 		      bfd_set_error (bfd_error_bad_value);
 		      -- num_group;
 		      continue;
@@ -673,7 +673,7 @@ setup_group (bfd *abfd, Elf_Internal_Shdr *hdr, asection *newsect)
 		      _bfd_error_handler
 			/* xgettext:c-format */
 			(_("%B: invalid size field in group section"
-			   " header: 0x%lx"), abfd, shdr->sh_size);
+			   " header: %#Lx"), abfd, shdr->sh_size);
 		      bfd_set_error (bfd_error_bad_value);
 		      -- num_group;
 		      /* PR 17510: If the group contents are even
@@ -911,9 +911,9 @@ _bfd_elf_setup_sections (bfd *abfd)
 	    /* There are some unknown sections in the group.  */
 	    _bfd_error_handler
 	      /* xgettext:c-format */
-	      (_("%B: unknown [%d] section `%s' in group [%A]"),
+	      (_("%B: unknown type [%#x] section `%s' in group [%A]"),
 	       abfd,
-	       (unsigned int) idx->shdr->sh_type,
+	       idx->shdr->sh_type,
 	       bfd_elf_string_from_elf_section (abfd,
 						(elf_elfheader (abfd)
 						 ->e_shstrndx),
@@ -1368,7 +1368,7 @@ copy_special_section_fields (const bfd *ibfd,
       /* See PR 20931 for a reproducer.  */
       if (iheader->sh_link >= elf_numsections (ibfd))
 	{
-	  (* _bfd_error_handler)
+	  _bfd_error_handler
 	    /* xgettext:c-format */
 	    (_("%B: Invalid sh_link field (%d) in section number %d"),
 	     ibfd, iheader->sh_link, secnum);
@@ -1384,7 +1384,7 @@ copy_special_section_fields (const bfd *ibfd,
       else
 	/* FIXME: Should we install iheader->sh_link
 	   if we could not find a match ?  */
-	(* _bfd_error_handler)
+	_bfd_error_handler
 	  /* xgettext:c-format */
 	  (_("%B: Failed to find link section for section %d"), obfd, secnum);
     }
@@ -1411,7 +1411,7 @@ copy_special_section_fields (const bfd *ibfd,
 	  changed = TRUE;
 	}
       else
-	(* _bfd_error_handler)
+	_bfd_error_handler
 	  /* xgettext:c-format */
 	  (_("%B: Failed to find info section for section %d"), obfd, secnum);
     }
@@ -2301,7 +2301,7 @@ bfd_section_from_shdr (bfd *abfd, unsigned int shindex)
 	  {
 	    _bfd_error_handler
 	      /* xgettext:c-format */
-	      (_("%B: invalid link %lu for reloc section %s (index %u)"),
+	      (_("%B: invalid link %u for reloc section %s (index %u)"),
 	       abfd, hdr->sh_link, name, shindex);
 	    ret = _bfd_elf_make_section_from_shdr (abfd, hdr, name,
 						   shindex);
@@ -2460,9 +2460,8 @@ bfd_section_from_shdr (bfd *abfd, unsigned int shindex)
 	       for applications?  */
 	    _bfd_error_handler
 	      /* xgettext:c-format */
-	      (_("%B: don't know how to handle allocated, application "
-		 "specific section `%s' [0x%8x]"),
-	       abfd, name, hdr->sh_type);
+	      (_("%B: unknown type [%#x] section `%s'"),
+	       abfd, hdr->sh_type, name);
 	  else
 	    {
 	      /* Allow sections reserved for applications.  */
@@ -2476,9 +2475,8 @@ bfd_section_from_shdr (bfd *abfd, unsigned int shindex)
 	/* FIXME: We should handle this section.  */
 	_bfd_error_handler
 	  /* xgettext:c-format */
-	  (_("%B: don't know how to handle processor specific section "
-	     "`%s' [0x%8x]"),
-	   abfd, name, hdr->sh_type);
+	  (_("%B: unknown type [%#x] section `%s'"),
+	   abfd, hdr->sh_type, name);
       else if (hdr->sh_type >= SHT_LOOS && hdr->sh_type <= SHT_HIOS)
 	{
 	  /* Unrecognised OS-specific sections.  */
@@ -2488,9 +2486,8 @@ bfd_section_from_shdr (bfd *abfd, unsigned int shindex)
 	       be rejected with an error message.  */
 	    _bfd_error_handler
 	      /* xgettext:c-format */
-	      (_("%B: don't know how to handle OS specific section "
-		 "`%s' [0x%8x]"),
-	       abfd, name, hdr->sh_type);
+	      (_("%B: unknown type [%#x] section `%s'"),
+	       abfd, hdr->sh_type, name);
 	  else
 	    {
 	      /* Otherwise it should be processed.  */
@@ -2502,8 +2499,8 @@ bfd_section_from_shdr (bfd *abfd, unsigned int shindex)
 	/* FIXME: We should handle this section.  */
 	_bfd_error_handler
 	  /* xgettext:c-format */
-	  (_("%B: don't know how to handle section `%s' [0x%8x]"),
-	   abfd, name, hdr->sh_type);
+	  (_("%B: unknown type [%#x] section `%s'"),
+	   abfd, hdr->sh_type, name);
 
       goto fail;
     }
@@ -5514,8 +5511,8 @@ assign_file_positions_for_load_sections (bfd *abfd,
 		{
 		  _bfd_error_handler
 		    /* xgettext:c-format */
-		    (_("%B: section %A lma %#lx adjusted to %#lx"), abfd, sec,
-		     (unsigned long) s_start, (unsigned long) p_end);
+		    (_("%B: section %A lma %#Lx adjusted to %#Lx"),
+		     abfd, sec, s_start, p_end);
 		  adjust = 0;
 		  sec->lma = p_end;
 		}
@@ -5897,8 +5894,9 @@ assign_file_positions_for_non_load_sections (bfd *abfd,
 		{
 		  /* PR 17512: file: 2195325e.  */
 		  _bfd_error_handler
-		    (_("%B: error: non-load segment %d includes file header and/or program header"),
-		     abfd, (int)(p - phdrs));
+		    (_("%B: error: non-load segment %d includes file header "
+		       "and/or program header"),
+		     abfd, (int) (p - phdrs));
 		  return FALSE;
 		}
 
@@ -6760,8 +6758,8 @@ rewrite_elf_program_header (bfd *ibfd, bfd *obfd)
 	  if (segment->p_type == PT_LOAD
 	      && (segment->p_filesz > 0 || segment->p_memsz == 0))
 	    /* xgettext:c-format */
-	    _bfd_error_handler (_("\
-%B: warning: Empty loadable segment detected at vaddr=0x%.8x, is this intentional ?"),
+	    _bfd_error_handler (_("%B: warning: Empty loadable segment detected"
+				  " at vaddr=%#Lx, is this intentional?"),
 				ibfd, segment->p_vaddr);
 
 	  map->count = 0;
@@ -7374,9 +7372,9 @@ rewrite:
 	    /* PR 17512: file: f17299af.  */
 	    if (segment->p_align > (bfd_vma) 1 << ((sizeof (bfd_vma) * 8) - 2))
 	      /* xgettext:c-format */
-	      _bfd_error_handler (_("\
-%B: warning: segment alignment of 0x%llx is too large"),
-				  ibfd, (long long) segment->p_align);
+	      _bfd_error_handler (_("%B: warning: segment alignment of %#Lx"
+				    " is too large"),
+				  ibfd, segment->p_align);
 	    else
 	      maxpagesize = segment->p_align;
 	  }
diff --git a/bfd/elfcode.h b/bfd/elfcode.h
index ef097f7..cbc534f 100644
--- a/bfd/elfcode.h
+++ b/bfd/elfcode.h
@@ -1446,7 +1446,7 @@ elf_slurp_reloc_table_from_section (bfd *abfd,
 	  _bfd_error_handler
 	    /* xgettext:c-format */
 	    (_("%B(%A): relocation %d has invalid symbol index %ld"),
-	     abfd, asect, i, ELF_R_SYM (rela.r_info));
+	     abfd, asect, i, (long) ELF_R_SYM (rela.r_info));
 	  relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
 	}
       else
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 471e8ad..bb1a30a 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -2394,8 +2394,8 @@ elf_link_read_relocs_from_section (bfd *abfd,
 	    {
 	      _bfd_error_handler
 		/* xgettext:c-format */
-		(_("%B: bad reloc symbol index (0x%lx >= 0x%lx)"
-		   " for offset 0x%lx in section `%A'"),
+		(_("%B: bad reloc symbol index (%#lx >= %#lx)"
+		   " for offset %#Lx in section `%A'"),
 		 abfd, (unsigned long) r_symndx, (unsigned long) nsyms,
 		 irela->r_offset, sec);
 	      bfd_set_error (bfd_error_bad_value);
@@ -2406,8 +2406,8 @@ elf_link_read_relocs_from_section (bfd *abfd,
 	{
 	  _bfd_error_handler
 	    /* xgettext:c-format */
-	    (_("%B: non-zero symbol index (0x%lx)"
-	       " for offset 0x%lx in section `%A'"
+	    (_("%B: non-zero symbol index (%#lx)"
+	       " for offset %#Lx in section `%A'"
 	       " when the object file has no symbol table"),
 	     abfd, (unsigned long) r_symndx, (unsigned long) nsyms,
 	     irela->r_offset, sec);
@@ -4752,9 +4752,8 @@ error_free_dyn:
 		_bfd_error_handler
 		  /* xgettext:c-format */
 		  (_("Warning: size of symbol `%s' changed"
-		     " from %lu in %B to %lu in %B"),
-		   name, (unsigned long) h->size, old_bfd,
-		   (unsigned long) isym->st_size, abfd);
+		     " from %Lu in %B to %Lu in %B"),
+		   name, h->size, old_bfd, isym->st_size, abfd);
 
 	      h->size = isym->st_size;
 	    }
@@ -10477,14 +10476,11 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
 		     we do not seg fault.  */
 		  if (h == NULL)
 		    {
-		      char buffer [32];
-
-		      sprintf_vma (buffer, rel->r_info);
 		      _bfd_error_handler
 			/* xgettext:c-format */
-			(_("error: %B contains a reloc (0x%s) for section %A "
+			(_("error: %B contains a reloc (%#Lx) for section %A "
 			   "that references a non-existent global symbol"),
-			 input_bfd, buffer, o);
+			 input_bfd, rel->r_info, o);
 		      bfd_set_error (bfd_error_bad_value);
 		      return FALSE;
 		    }
@@ -13422,8 +13418,8 @@ bfd_elf_gc_record_vtinherit (bfd *abfd,
     }
 
   /* xgettext:c-format */
-  _bfd_error_handler (_("%B: %A+%lu: No symbol found for INHERIT"),
-		      abfd, sec, (unsigned long) offset);
+  _bfd_error_handler (_("%B: %A+%#Lx: No symbol found for INHERIT"),
+		      abfd, sec, offset);
   bfd_set_error (bfd_error_invalid_operation);
   return FALSE;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]