diff mbox

[lto-plugin] : Fix pr 50616

Message ID CAEwic4bN9EJPXUa_KuSbvxCuB_w9J=TLWO5Fvi9pZgfCNhFoOA@mail.gmail.com
State New
Headers show

Commit Message

Kai Tietz Feb. 20, 2012, 10:59 p.m. UTC
Hi,

this patch replaces use of "llx" for printf/scanf by inttypes.h
PRIxMAX/SCNxMAX macros.  If those macros aren't present it defines
them as default to "llx".

ChangeLog

2012-02-20  Kai Tietz  <ktietz@redhat.com>

        PR lto/50616
        * lto-plugin.c (PRIxMAX,SCNxMAX): Use inttypes.h header if
present, otherwise define them
        as "llx".

Tested for i686-w64-mingw32, x86_64-w64-mingw32, and
x86_64-unknown-linux-gnu.  Ok for apply?

Regards,
Kai

Comments

Richard Biener Feb. 21, 2012, 9:28 a.m. UTC | #1
On Mon, Feb 20, 2012 at 11:59 PM, Kai Tietz <ktietz70@googlemail.com> wrote:
> Hi,
>
> this patch replaces use of "llx" for printf/scanf by inttypes.h
> PRIxMAX/SCNxMAX macros.  If those macros aren't present it defines
> them as default to "llx".

Bootstrapped and tested on ... ?

Ok.

Thanks,
Richard.

> ChangeLog
>
> 2012-02-20  Kai Tietz  <ktietz@redhat.com>
>
>        PR lto/50616
>        * lto-plugin.c (PRIxMAX,SCNxMAX): Use inttypes.h header if
> present, otherwise define them
>        as "llx".
>
> Tested for i686-w64-mingw32, x86_64-w64-mingw32, and
> x86_64-unknown-linux-gnu.  Ok for apply?
>
> Regards,
> Kai
>
> Index: lto-plugin.c
> ===================================================================
> --- lto-plugin.c        (revision 184414)
> +++ lto-plugin.c        (working copy)
> @@ -38,6 +38,9 @@
>  #if HAVE_STDINT_H
>  #include <stdint.h>
>  #endif
> +#if HAVE_INTTYPES_H
> +#include <inttypes.h>
> +#endif
>  #include <assert.h>
>  #include <string.h>
>  #include <stdlib.h>
> @@ -62,6 +65,14 @@
>  #include "simple-object.h"
>  #include "plugin-api.h"
>
> +#ifndef PRIxMAX
> +#define PRIxMAX "llx"
> +#endif
> +
> +#ifndef SCNxMAX
> +#define SCNxMAX "llx"
> +#endif
> +
>  /* Handle opening elf files on hosts, such as Windows, that may use
>    text file handling that will break binary access.  */
>  #ifndef O_BINARY
> @@ -360,7 +371,7 @@
>
>       assert (resolution != LDPR_UNKNOWN);
>
> -      fprintf (f, "%u %llx %s %s\n",
> +      fprintf (f, "%u %" PRIxMAX " %s %s\n",
>                (unsigned int) slot, symtab->aux[j].id,
>               lto_resolution_str[resolution],
>               symtab->syms[j].name);
> @@ -816,7 +827,7 @@
>
>   s = strrchr (name, '.');
>   if (s)
> -    sscanf (s, ".%llx", &obj->out->id);
> +    sscanf (s, ".%" SCNxMAX, &obj->out->id);
>   secdata = xmalloc (length);
>   offset += obj->file->offset;
>   if (offset != lseek (obj->file->fd, offset, SEEK_SET)
Kai Tietz Feb. 21, 2012, 9:47 a.m. UTC | #2
2012/2/21 Richard Guenther <richard.guenther@gmail.com>:
> On Mon, Feb 20, 2012 at 11:59 PM, Kai Tietz <ktietz70@googlemail.com> wrote:
>> Hi,
>>
>> this patch replaces use of "llx" for printf/scanf by inttypes.h
>> PRIxMAX/SCNxMAX macros.  If those macros aren't present it defines
>> them as default to "llx".
>
> Bootstrapped and tested on ... ?
>
> Ok.
>
> Thanks,
> Richard.
>
>> ChangeLog
>>
>> 2012-02-20  Kai Tietz  <ktietz@redhat.com>
>>
>>        PR lto/50616
>>        * lto-plugin.c (PRIxMAX,SCNxMAX): Use inttypes.h header if
>> present, otherwise define them
>>        as "llx".
>>
>> Tested for i686-w64-mingw32, x86_64-w64-mingw32, and
>> x86_64-unknown-linux-gnu.  Ok for apply?
>>
>> Regards,
>> Kai
>>
>> Index: lto-plugin.c
>> ===================================================================
>> --- lto-plugin.c        (revision 184414)
>> +++ lto-plugin.c        (working copy)
>> @@ -38,6 +38,9 @@
>>  #if HAVE_STDINT_H
>>  #include <stdint.h>
>>  #endif
>> +#if HAVE_INTTYPES_H
>> +#include <inttypes.h>
>> +#endif
>>  #include <assert.h>
>>  #include <string.h>
>>  #include <stdlib.h>
>> @@ -62,6 +65,14 @@
>>  #include "simple-object.h"
>>  #include "plugin-api.h"
>>
>> +#ifndef PRIxMAX
>> +#define PRIxMAX "llx"
>> +#endif
>> +
>> +#ifndef SCNxMAX
>> +#define SCNxMAX "llx"
>> +#endif
>> +
>>  /* Handle opening elf files on hosts, such as Windows, that may use
>>    text file handling that will break binary access.  */
>>  #ifndef O_BINARY
>> @@ -360,7 +371,7 @@
>>
>>       assert (resolution != LDPR_UNKNOWN);
>>
>> -      fprintf (f, "%u %llx %s %s\n",
>> +      fprintf (f, "%u %" PRIxMAX " %s %s\n",
>>                (unsigned int) slot, symtab->aux[j].id,
>>               lto_resolution_str[resolution],
>>               symtab->syms[j].name);
>> @@ -816,7 +827,7 @@
>>
>>   s = strrchr (name, '.');
>>   if (s)
>> -    sscanf (s, ".%llx", &obj->out->id);
>> +    sscanf (s, ".%" SCNxMAX, &obj->out->id);
>>   secdata = xmalloc (length);
>>   offset += obj->file->offset;
>>   if (offset != lseek (obj->file->fd, offset, SEEK_SET)

Hmm, no.  On x86_64 linux PRIxMAX is still defined as "lx", which
would lead to printf-failures.  So inttypes.h is no good approach.  I
will come up with an alternative patch for this.

Regards,
Kai
diff mbox

Patch

Index: lto-plugin.c
===================================================================
--- lto-plugin.c        (revision 184414)
+++ lto-plugin.c        (working copy)
@@ -38,6 +38,9 @@ 
 #if HAVE_STDINT_H
 #include <stdint.h>
 #endif
+#if HAVE_INTTYPES_H
+#include <inttypes.h>
+#endif
 #include <assert.h>
 #include <string.h>
 #include <stdlib.h>
@@ -62,6 +65,14 @@ 
 #include "simple-object.h"
 #include "plugin-api.h"

+#ifndef PRIxMAX
+#define PRIxMAX "llx"
+#endif
+
+#ifndef SCNxMAX
+#define SCNxMAX "llx"
+#endif
+
 /* Handle opening elf files on hosts, such as Windows, that may use
    text file handling that will break binary access.  */
 #ifndef O_BINARY
@@ -360,7 +371,7 @@ 

       assert (resolution != LDPR_UNKNOWN);

-      fprintf (f, "%u %llx %s %s\n",
+      fprintf (f, "%u %" PRIxMAX " %s %s\n",
                (unsigned int) slot, symtab->aux[j].id,
               lto_resolution_str[resolution],
               symtab->syms[j].name);
@@ -816,7 +827,7 @@ 

   s = strrchr (name, '.');
   if (s)
-    sscanf (s, ".%llx", &obj->out->id);
+    sscanf (s, ".%" SCNxMAX, &obj->out->id);
   secdata = xmalloc (length);
   offset += obj->file->offset;
   if (offset != lseek (obj->file->fd, offset, SEEK_SET)