This is the mail archive of the binutils@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]

Re: Support %Lx, %Lu, %Ld in _bfd_error_handler format


On Mon, Jul 3, 2017 at 5:38 AM, Alan Modra <amodra@gmail.com> wrote:
> 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 --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;
> +

This is incomplete and breaks 32-bit bfd_vma.  I am checking in

diff --git a/bfd/bfd.c b/bfd/bfd.c
index b6cdf3f..a119ac4 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -727,7 +727,10 @@ _doprnt (FILE *stream, const char *format, va_list ap)
             either long long or long.  */
          if ((BFD_ARCH_SIZE < 64 || BFD_HOST_64BIT_LONG)
         && sptr[-2] == 'L')
-           wide_width = 1;
+           {
+        wide_width = 1;
+        sptr[-2] = 'l';
+           }

          switch (wide_width)

to fix it.

-- 
H.J.


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