diff mbox

[RFC] : Adjust the use of 'long' type in dwarf2.h header

Message ID AANLkTimPMPKd=Hfz-1e_aSw_iQsdm2SMK5hwR0sd+tga@mail.gmail.com
State New
Headers show

Commit Message

Kai Tietz Feb. 17, 2011, 2:21 p.m. UTC
Hello,

This patch addresses issues I've seen in binutils about
cross-compilers and dwarf2 display via objdump -W on hosts, which have
sizeof (long) < target's sizeof(void *). Additionally same issue of
course can be seen on LLP64 targets, too.
Those issues are caused by the fact that the dwarf2.h header in
include/ is using unconditionally the type 'unsigned long' for
vma-scalars.

This patch address additionally the binutils' dwarf.(c|h) files and
make them host bitness independent for gcc base toolchains supporting
the 'long long' type.

I've tested the attached patches for gdb, binutils, and gcc on
i686-w64-mingw32, and x86_64-w64-mingw32 cross-toolchains hosted on
cygwin. And I didn't found until now regressions. Later this day I
want to do a regression test for linux64, too.


binutils, gdb, gcc

ChangeLog include/

2011-02-17  Kai Tietz

	* dwarf2.h (dw2_vma_t): New type.
	(dw2_svma_t): New type.
	(DW2_VMA_FMT): New macro specifying
	to be used width-sepecifier for printing
	new types.


ChangeLog binutils/

2011-02-17  Kai Tietz

	* dwarf.c (read_leb128): Use dw2_vma_t instead of
	long type.
	(process_extended_line_op): Use for adr new type
	and print dw2 values via DW2_VMA_FMT.
	(fetch_indirect_string): Adjust offset's type.
	(decode_location_expression): Adjust argument types
	and uvalue type.
	(read_and_display_attr_value): Likewise.
	(read_and_display_attr): Likewise.
	(decode_location_expression): Adjust printf format.
	(process_debug_info): Likewise.
	(display_debug_lines_raw): Likewise.
	(display_debug_lines_decoded): Likewise.
	(display_debug_pubnames): Likewise.
	(display_debug_loc): Likewise.
	(display_debug_aranges): Likewise.
	* dwarf.h: Add include of dwarf2.h header and
	use of dw2_vma_t instead of long types.
	(read_leb128): Adjust return type.
	
	
Regards,
Kai


PS: On gdb there is at the moment in gdb/common part the include-path
to intl for libintl.h missing

Index: src/include/dwarf2.h
===================================================================
--- src.orig/include/dwarf2.h	2011-02-17 12:26:40.000000000 +0100
+++ src/include/dwarf2.h	2011-02-17 12:25:06.183158800 +0100
@@ -47,6 +47,35 @@
 #ifndef _ELF_DWARF2_H
 #define _ELF_DWARF2_H
 
+#if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
+/* We need here widest integer type so that even for cross scenarios
+   a wide enough integer scalar value is used to hold address vma.
+   Additionally it is necessary here to use for non-LP64 targets the
+   proper integer scalar value to hold an address.  */
+#ifdef __GNUC__
+__extension__
+#endif
+typedef unsigned long long dw2_vma_t;
+#ifdef __GNUC__
+__extension__
+#endif
+typedef signed long long dw2_svma_t;
+
+#ifndef __MINGW32__
+#define DW2_VMA_FMT	"ll"
+#else
+#define DW2_VMA_FMT	"I64"
+#endif
+
+#else
+
+typedef unsigned long dw2_vma_t;
+typedef signed long dw2_svma_t;
+
+#define DW2_VMA_FMT	"l"
+
+#endif
+
 /* Structure found in the .debug_line section.  */
 typedef struct
 {
@@ -63,7 +92,7 @@ DWARF2_External_LineInfo;
 
 typedef struct
 {
-  unsigned long  li_length;
+  dw2_vma_t	 li_length;
   unsigned short li_version;
   unsigned int   li_prologue_length;
   unsigned char  li_min_insn_length;
@@ -87,10 +116,10 @@ DWARF2_External_PubNames;
 
 typedef struct
 {
-  unsigned long  pn_length;
+  dw2_vma_t	 pn_length;
   unsigned short pn_version;
-  unsigned long  pn_offset;
-  unsigned long  pn_size;
+  dw2_vma_t	 pn_offset;
+  dw2_vma_t	 pn_size;
 }
 DWARF2_Internal_PubNames;
 
@@ -106,9 +135,9 @@ DWARF2_External_CompUnit;
 
 typedef struct
 {
-  unsigned long  cu_length;
+  dw2_vma_t	 cu_length;
   unsigned short cu_version;
-  unsigned long  cu_abbrev_offset;
+  dw2_vma_t	 cu_abbrev_offset;
   unsigned char  cu_pointer_size;
 }
 DWARF2_Internal_CompUnit;
@@ -125,9 +154,9 @@ DWARF2_External_ARange;
 
 typedef struct
 {
-  unsigned long  ar_length;
+  dw2_vma_t	 ar_length;
   unsigned short ar_version;
-  unsigned long  ar_info_offset;
+  dw2_vma_t	 ar_info_offset;
   unsigned char  ar_pointer_size;
   unsigned char  ar_segment_size;
 }
Index: gcc/include/dwarf2.h
===================================================================
--- gcc.orig/include/dwarf2.h	2011-01-13 11:59:21.000000000 +0100
+++ gcc/include/dwarf2.h	2011-02-17 14:00:16.175818900 +0100
@@ -47,6 +47,35 @@
 #ifndef _ELF_DWARF2_H
 #define _ELF_DWARF2_H
 
+#if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
+/* We need here widest integer type so that even for cross scenarios
+   a wide enough integer scalar value is used to hold address vma.
+   Additionally it is necessary here to use for non-LP64 targets the
+   proper integer scalar value to hold an address.  */
+#ifdef __GNUC__
+__extension__
+#endif
+typedef unsigned long long dw2_vma_t;
+#ifdef __GNUC__
+__extension__
+#endif
+typedef signed long long dw2_svma_t;
+
+#ifndef __MINGW32__
+#define DW2_VMA_FMT	"ll"
+#else
+#define DW2_VMA_FMT	"I64"
+#endif
+
+#else
+
+typedef unsigned long dw2_vma_t;
+typedef signed long dw2_svma_t;
+
+#define DW2_VMA_FMT	"l"
+
+#endif
+
 /* Structure found in the .debug_line section.  */
 typedef struct
 {
@@ -63,7 +92,7 @@ DWARF2_External_LineInfo;
 
 typedef struct
 {
-  unsigned long  li_length;
+  dw2_vma_t	 li_length;
   unsigned short li_version;
   unsigned int   li_prologue_length;
   unsigned char  li_min_insn_length;
@@ -87,10 +116,10 @@ DWARF2_External_PubNames;
 
 typedef struct
 {
-  unsigned long  pn_length;
+  dw2_vma_t	 pn_length;
   unsigned short pn_version;
-  unsigned long  pn_offset;
-  unsigned long  pn_size;
+  dw2_vma_t	 pn_offset;
+  dw2_vma_t	 pn_size;
 }
 DWARF2_Internal_PubNames;
 
@@ -106,9 +135,9 @@ DWARF2_External_CompUnit;
 
 typedef struct
 {
-  unsigned long  cu_length;
+  dw2_vma_t	 cu_length;
   unsigned short cu_version;
-  unsigned long  cu_abbrev_offset;
+  dw2_vma_t	 cu_abbrev_offset;
   unsigned char  cu_pointer_size;
 }
 DWARF2_Internal_CompUnit;
@@ -125,9 +154,9 @@ DWARF2_External_ARange;
 
 typedef struct
 {
-  unsigned long  ar_length;
+  dw2_vma_t	 ar_length;
   unsigned short ar_version;
-  unsigned long  ar_info_offset;
+  dw2_vma_t	 ar_info_offset;
   unsigned char  ar_pointer_size;
   unsigned char  ar_segment_size;
 }
@@ -754,7 +783,15 @@ enum dwarf_calling_convention
     DW_CC_hi_user = 0xff,
 
     DW_CC_GNU_renesas_sh = 0x40,
-    DW_CC_GNU_borland_fastcall_i386 = 0x41
+    DW_CC_GNU_borland_fastcall_i386 = 0x41,
+
+    /* This DW_CC_ value is not currently generated by any toolchain.  It is
+       used internally to GDB to indicate OpenCL C functions that have been
+       compiled with the IBM XL C for OpenCL compiler and use a non-platform
+       calling convention for passing OpenCL C vector types.  This value may
+       be changed freely as long as it does not conflict with any other DW_CC_
+       value defined here.  */
+    DW_CC_GDB_IBM_OpenCL = 0xff
   };
 
 /* Inline attribute.  */

Comments

Kai Tietz Feb. 17, 2011, 6:58 p.m. UTC | #1
2011/2/17 Kai Tietz <ktietz70@googlemail.com>:
> Hello,
>
> This patch addresses issues I've seen in binutils about
> cross-compilers and dwarf2 display via objdump -W on hosts, which have
> sizeof (long) < target's sizeof(void *). Additionally same issue of
> course can be seen on LLP64 targets, too.
> Those issues are caused by the fact that the dwarf2.h header in
> include/ is using unconditionally the type 'unsigned long' for
> vma-scalars.
>
> This patch address additionally the binutils' dwarf.(c|h) files and
> make them host bitness independent for gcc base toolchains supporting
> the 'long long' type.
>
> I've tested the attached patches for gdb, binutils, and gcc on
> i686-w64-mingw32, and x86_64-w64-mingw32 cross-toolchains hosted on
> cygwin. And I didn't found until now regressions. Later this day I
> want to do a regression test for linux64, too.
>
>
> binutils, gdb, gcc
>
> ChangeLog include/
>
> 2011-02-17  Kai Tietz
>
>        * dwarf2.h (dw2_vma_t): New type.
>        (dw2_svma_t): New type.
>        (DW2_VMA_FMT): New macro specifying
>        to be used width-sepecifier for printing
>        new types.
>
>
> ChangeLog binutils/
>
> 2011-02-17  Kai Tietz
>
>        * dwarf.c (read_leb128): Use dw2_vma_t instead of
>        long type.
>        (process_extended_line_op): Use for adr new type
>        and print dw2 values via DW2_VMA_FMT.
>        (fetch_indirect_string): Adjust offset's type.
>        (decode_location_expression): Adjust argument types
>        and uvalue type.
>        (read_and_display_attr_value): Likewise.
>        (read_and_display_attr): Likewise.
>        (decode_location_expression): Adjust printf format.
>        (process_debug_info): Likewise.
>        (display_debug_lines_raw): Likewise.
>        (display_debug_lines_decoded): Likewise.
>        (display_debug_pubnames): Likewise.
>        (display_debug_loc): Likewise.
>        (display_debug_aranges): Likewise.
>        * dwarf.h: Add include of dwarf2.h header and
>        use of dw2_vma_t instead of long types.
>        (read_leb128): Adjust return type.
>
>
> Regards,
> Kai
>
>
> PS: On gdb there is at the moment in gdb/common part the include-path
> to intl for libintl.h missing
>

I tested those patches for x86_64-pc-linux-gnu too and had no
regressions. Ok for apply, or any comments?

Regards,
Kai
Jakub Jelinek Feb. 17, 2011, 7:02 p.m. UTC | #2
On Thu, Feb 17, 2011 at 07:58:56PM +0100, Kai Tietz wrote:
> 2011/2/17 Kai Tietz <ktietz70@googlemail.com>:
> > This patch addresses issues I've seen in binutils about
> > cross-compilers and dwarf2 display via objdump -W on hosts, which have
> > sizeof (long) < target's sizeof(void *). Additionally same issue of
> > course can be seen on LLP64 targets, too.
> > Those issues are caused by the fact that the dwarf2.h header in
> > include/ is using unconditionally the type 'unsigned long' for
> > vma-scalars.
> >
> > This patch address additionally the binutils' dwarf.(c|h) files and
> > make them host bitness independent for gcc base toolchains supporting
> > the 'long long' type.
> >
> > I've tested the attached patches for gdb, binutils, and gcc on
> > i686-w64-mingw32, and x86_64-w64-mingw32 cross-toolchains hosted on
> > cygwin. And I didn't found until now regressions. Later this day I
> > want to do a regression test for linux64, too.

I'd prefer if we could move those binutils specific internal implementation
details out of the dwarf2.h header, keep it really just for the stuff
defined in the standard, and add a new binutils specific header somewhere
else which would contain binutils specific details.

	Jakub
Kai Tietz Feb. 17, 2011, 7:06 p.m. UTC | #3
2011/2/17 Jakub Jelinek <jakub@redhat.com>:
> On Thu, Feb 17, 2011 at 07:58:56PM +0100, Kai Tietz wrote:
>> 2011/2/17 Kai Tietz <ktietz70@googlemail.com>:
>> > This patch addresses issues I've seen in binutils about
>> > cross-compilers and dwarf2 display via objdump -W on hosts, which have
>> > sizeof (long) < target's sizeof(void *). Additionally same issue of
>> > course can be seen on LLP64 targets, too.
>> > Those issues are caused by the fact that the dwarf2.h header in
>> > include/ is using unconditionally the type 'unsigned long' for
>> > vma-scalars.
>> >
>> > This patch address additionally the binutils' dwarf.(c|h) files and
>> > make them host bitness independent for gcc base toolchains supporting
>> > the 'long long' type.
>> >
>> > I've tested the attached patches for gdb, binutils, and gcc on
>> > i686-w64-mingw32, and x86_64-w64-mingw32 cross-toolchains hosted on
>> > cygwin. And I didn't found until now regressions. Later this day I
>> > want to do a regression test for linux64, too.
>
> I'd prefer if we could move those binutils specific internal implementation
> details out of the dwarf2.h header, keep it really just for the stuff
> defined in the standard, and add a new binutils specific header somewhere
> else which would contain binutils specific details.
>
>        Jakub

Well, so we make dwarf2.h in include just host-specific and isn't able
to cover things for foreign target, like 32-bit host can't use this
header for 64-bit dwarf2 information. I am fine by this, but
nevertheless is then the use of 'unsigned long' type within this
header still an issue. Here should be used instead then 'intptr_t'. As
on LLP64 unsigned long isn't wide-enough.

Regards,
Kai
Jakub Jelinek Feb. 17, 2011, 7:17 p.m. UTC | #4
On Thu, Feb 17, 2011 at 08:06:53PM +0100, Kai Tietz wrote:
> > I'd prefer if we could move those binutils specific internal implementation
> > details out of the dwarf2.h header, keep it really just for the stuff
> > defined in the standard, and add a new binutils specific header somewhere
> > else which would contain binutils specific details.
> 
> Well, so we make dwarf2.h in include just host-specific and isn't able
> to cover things for foreign target, like 32-bit host can't use this
> header for 64-bit dwarf2 information. I am fine by this, but
> nevertheless is then the use of 'unsigned long' type within this
> header still an issue. Here should be used instead then 'intptr_t'. As
> on LLP64 unsigned long isn't wide-enough.

I mean that none of the DWARF2_Internal types should be in the
include/dwarf2.h headers (that's implementation specific stuff),
and the DWARF2_External types are questionable too, to me they look
very much like implementation detail too.  E.g. DWARF2_External_LineInfo
type is dubious, because it might somehow describe version 2 or 3
.debug_line header, but version 4 looks differently, etc.
So IMHO the DWARF2_External stuff should be moved too.
And the guard should be probably renamed from _ELF_DWARF2_H to _DWARF2_H,
I don't see anything ELF specific in the header.

	Jakub
Pierre Muller Feb. 21, 2011, 1:09 p.m. UTC | #5
I was just wondering about all those
  _("Text with some 0x" BFD_VMA_FMT "x\n"), adr);
constructs:
  If we do the translations on a 64-bit unix machine
we will have translations for
"Text with some 0xllx\n" 
but a mingw 64-bit executable will look for
"Text with some 0xI64x\n"
while a 32-bit system will look for
"Text with some 0xlx\n"
and in both cases, no translation will be found.

  Wouldn't it be better to use something similar 
to paddress in src/gdb/utils.c
let's call it dwarf_vma function,
so that we have:
 _("Text with some 0x%s\n"), dwarf_vma (adr));
with a unique "Text with some 0x%s\n"
string that gets internationalized correctly?


Pierre Muller
GDB pascal language maintainer


> -----Message d'origine-----
> De : gdb-owner@sourceware.org [mailto:gdb-owner@sourceware.org] De la
> part de Kai Tietz
> Envoyé : jeudi 17 février 2011 15:22
> À : GCC Patches; Binutils; gdb
> Cc : Jakub Jelinek; Joel Brobecker
> Objet : [RFC patch]: Adjust the use of 'long' type in dwarf2.h header
> 
> Hello,
> 
> This patch addresses issues I've seen in binutils about
> cross-compilers and dwarf2 display via objdump -W on hosts, which have
> sizeof (long) < target's sizeof(void *). Additionally same issue of
> course can be seen on LLP64 targets, too.
> Those issues are caused by the fact that the dwarf2.h header in
> include/ is using unconditionally the type 'unsigned long' for
> vma-scalars.
> 
> This patch address additionally the binutils' dwarf.(c|h) files and
> make them host bitness independent for gcc base toolchains supporting
> the 'long long' type.
> 
> I've tested the attached patches for gdb, binutils, and gcc on
> i686-w64-mingw32, and x86_64-w64-mingw32 cross-toolchains hosted on
> cygwin. And I didn't found until now regressions. Later this day I
> want to do a regression test for linux64, too.
> 
> 
> binutils, gdb, gcc
> 
> ChangeLog include/
> 
> 2011-02-17  Kai Tietz
> 
> 	* dwarf2.h (dw2_vma_t): New type.
> 	(dw2_svma_t): New type.
> 	(DW2_VMA_FMT): New macro specifying
> 	to be used width-sepecifier for printing
> 	new types.
> 
> 
> ChangeLog binutils/
> 
> 2011-02-17  Kai Tietz
> 
> 	* dwarf.c (read_leb128): Use dw2_vma_t instead of
> 	long type.
> 	(process_extended_line_op): Use for adr new type
> 	and print dw2 values via DW2_VMA_FMT.
> 	(fetch_indirect_string): Adjust offset's type.
> 	(decode_location_expression): Adjust argument types
> 	and uvalue type.
> 	(read_and_display_attr_value): Likewise.
> 	(read_and_display_attr): Likewise.
> 	(decode_location_expression): Adjust printf format.
> 	(process_debug_info): Likewise.
> 	(display_debug_lines_raw): Likewise.
> 	(display_debug_lines_decoded): Likewise.
> 	(display_debug_pubnames): Likewise.
> 	(display_debug_loc): Likewise.
> 	(display_debug_aranges): Likewise.
> 	* dwarf.h: Add include of dwarf2.h header and
> 	use of dw2_vma_t instead of long types.
> 	(read_leb128): Adjust return type.
> 
> 
> Regards,
> Kai
> 
> 
> PS: On gdb there is at the moment in gdb/common part the include-path
> to intl for libintl.h missing
Kai Tietz Feb. 21, 2011, 1:26 p.m. UTC | #6
2011/2/21 Pierre Muller <pierre.muller@ics-cnrs.unistra.fr>:
>  I was just wondering about all those
>  _("Text with some 0x" BFD_VMA_FMT "x\n"), adr);
> constructs:
>  If we do the translations on a 64-bit unix machine
> we will have translations for
> "Text with some 0xllx\n"
> but a mingw 64-bit executable will look for
> "Text with some 0xI64x\n"
> while a 32-bit system will look for
> "Text with some 0xlx\n"
> and in both cases, no translation will be found.
>
>  Wouldn't it be better to use something similar
> to paddress in src/gdb/utils.c
> let's call it dwarf_vma function,
> so that we have:
>  _("Text with some 0x%s\n"), dwarf_vma (adr));
> with a unique "Text with some 0x%s\n"
> string that gets internationalized correctly?
>
>
> Pierre Muller
> GDB pascal language maintainer
>
>
>> -----Message d'origine-----
>> De : gdb-owner@sourceware.org [mailto:gdb-owner@sourceware.org] De la
>> part de Kai Tietz
>> Envoyé : jeudi 17 février 2011 15:22
>> À : GCC Patches; Binutils; gdb
>> Cc : Jakub Jelinek; Joel Brobecker
>> Objet : [RFC patch]: Adjust the use of 'long' type in dwarf2.h header
>>
>> Hello,
>>
>> This patch addresses issues I've seen in binutils about
>> cross-compilers and dwarf2 display via objdump -W on hosts, which have
>> sizeof (long) < target's sizeof(void *). Additionally same issue of
>> course can be seen on LLP64 targets, too.
>> Those issues are caused by the fact that the dwarf2.h header in
>> include/ is using unconditionally the type 'unsigned long' for
>> vma-scalars.
>>
>> This patch address additionally the binutils' dwarf.(c|h) files and
>> make them host bitness independent for gcc base toolchains supporting
>> the 'long long' type.
>>
>> I've tested the attached patches for gdb, binutils, and gcc on
>> i686-w64-mingw32, and x86_64-w64-mingw32 cross-toolchains hosted on
>> cygwin. And I didn't found until now regressions. Later this day I
>> want to do a regression test for linux64, too.
>>
>>
>> binutils, gdb, gcc
>>
>> ChangeLog include/
>>
>> 2011-02-17  Kai Tietz
>>
>>       * dwarf2.h (dw2_vma_t): New type.
>>       (dw2_svma_t): New type.
>>       (DW2_VMA_FMT): New macro specifying
>>       to be used width-sepecifier for printing
>>       new types.
>>
>>
>> ChangeLog binutils/
>>
>> 2011-02-17  Kai Tietz
>>
>>       * dwarf.c (read_leb128): Use dw2_vma_t instead of
>>       long type.
>>       (process_extended_line_op): Use for adr new type
>>       and print dw2 values via DW2_VMA_FMT.
>>       (fetch_indirect_string): Adjust offset's type.
>>       (decode_location_expression): Adjust argument types
>>       and uvalue type.
>>       (read_and_display_attr_value): Likewise.
>>       (read_and_display_attr): Likewise.
>>       (decode_location_expression): Adjust printf format.
>>       (process_debug_info): Likewise.
>>       (display_debug_lines_raw): Likewise.
>>       (display_debug_lines_decoded): Likewise.
>>       (display_debug_pubnames): Likewise.
>>       (display_debug_loc): Likewise.
>>       (display_debug_aranges): Likewise.
>>       * dwarf.h: Add include of dwarf2.h header and
>>       use of dw2_vma_t instead of long types.
>>       (read_leb128): Adjust return type.
>>
>>
>> Regards,
>> Kai
>>
>>
>> PS: On gdb there is at the moment in gdb/common part the include-path
>> to intl for libintl.h missing
>
>

Yes, I saw this too and it is a thorn here. But the issue about a
transformation function (like dwarf_vma) is that we have memory leaks
- as this function is to be used on some printf's more then once - as
static buffer would be overriden. Well printfs can be splitted into
smaller parts, but this then would make localization even harder.

Maybe it would be better here to remove those localizations?

Regards,
Kai
Pierre Muller Feb. 21, 2011, 1:45 p.m. UTC | #7
> Yes, I saw this too and it is a thorn here. But the issue about a
> transformation function (like dwarf_vma) is that we have memory leaks
> - as this function is to be used on some printf's more then once - as
> static buffer would be overriden. Well printfs can be splitted into
> smaller parts, but this then would make localization even harder.

 In GDB code, this is solved in utils.c source by the use of the
get_cell function, which rotates over 16 char arrays of size 50 each
currently, in dwarf.c 4 arrays of 16 char (as long as longest address is
64-bit)
for this dwarf_vma function would probably be enough, no?


Pierre Muller
GDB pascal language maintainer
Kai Tietz Feb. 21, 2011, 2:30 p.m. UTC | #8
2011/2/21 Pierre Muller <pierre.muller@ics-cnrs.unistra.fr>:
>> Yes, I saw this too and it is a thorn here. But the issue about a
>> transformation function (like dwarf_vma) is that we have memory leaks
>> - as this function is to be used on some printf's more then once - as
>> static buffer would be overriden. Well printfs can be splitted into
>> smaller parts, but this then would make localization even harder.
>
>  In GDB code, this is solved in utils.c source by the use of the
> get_cell function, which rotates over 16 char arrays of size 50 each
> currently, in dwarf.c 4 arrays of 16 char (as long as longest address is
> 64-bit)
> for this dwarf_vma function would probably be enough, no?
>
>
> Pierre Muller
> GDB pascal language maintainer

Yes, this sounds ok. I think maximum here are right now 3 dwarf_vma
prints within one printf. So it should be ok. I'll add here such a
rotating function. I don't assume we need here to handle
multi-threading, so rotation code can be pretty simple.

Kai
diff mbox

Patch

Index: src/binutils/dwarf.c
===================================================================
--- src.orig/binutils/dwarf.c	2011-02-17 11:00:34.000000000 +0100
+++ src/binutils/dwarf.c	2011-02-17 14:30:11.291550300 +0100
@@ -123,10 +123,10 @@  print_dwarf_vma (dwarf_vma val, unsigned
   fputs (buff + (byte_size == 4 ? 8 : 0), stdout);
 }
 
-unsigned long int
+dw2_vma_t
 read_leb128 (unsigned char *data, unsigned int *length_return, int sign)
 {
-  unsigned long int result = 0;
+  dw2_vma_t result = 0;
   unsigned int num_read = 0;
   unsigned int shift = 0;
   unsigned char byte;
@@ -136,7 +136,7 @@  read_leb128 (unsigned char *data, unsign
       byte = *data++;
       num_read++;
 
-      result |= ((unsigned long int) (byte & 0x7f)) << shift;
+      result |= ((dw2_vma_t) (byte & 0x7f)) << shift;
 
       shift += 7;
 
@@ -193,7 +193,7 @@  process_extended_line_op (unsigned char 
   unsigned int bytes_read;
   unsigned int len;
   unsigned char *name;
-  unsigned long adr;
+  dw2_vma_t adr;
 
   len = read_leb128 (data, & bytes_read, 0);
   data += bytes_read;
@@ -218,7 +218,7 @@  process_extended_line_op (unsigned char 
 
     case DW_LNE_set_address:
       adr = byte_get (data, len - bytes_read - 1);
-      printf (_("set Address to 0x%lx\n"), adr);
+      printf (_("set Address to 0x%" DW2_VMA_FMT "x\n"), adr);
       state_machine_regs.address = adr;
       state_machine_regs.op_index = 0;
       break;
@@ -230,16 +230,17 @@  process_extended_line_op (unsigned char 
       printf ("   %d\t", ++state_machine_regs.last_file_entry);
       name = data;
       data += strlen ((char *) data) + 1;
-      printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
+      printf ("%" DW2_VMA_FMT "u\t", read_leb128 (data, & bytes_read, 0));
       data += bytes_read;
-      printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
+      printf ("%" DW2_VMA_FMT "u\t",
+	      read_leb128 (data, & bytes_read, 0));
       data += bytes_read;
-      printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
+      printf ("%" DW2_VMA_FMT "u\t", read_leb128 (data, & bytes_read, 0));
       printf ("%s\n\n", name);
       break;
 
     case DW_LNE_set_discriminator:
-      printf (_("set Discriminator to %lu\n"),
+      printf (_("set Discriminator to %" DW2_VMA_FMT "u\n"),
               read_leb128 (data, & bytes_read, 0));
       break;
 
@@ -291,7 +292,7 @@  process_extended_line_op (unsigned char 
 }
 
 static const char *
-fetch_indirect_string (unsigned long offset)
+fetch_indirect_string (dw2_vma_t offset)
 {
   struct dwarf_section *section = &debug_displays [str].section;
 
@@ -302,7 +303,7 @@  fetch_indirect_string (unsigned long off
   offset -= section->address;
   if (offset > section->size)
     {
-      warn (_("DW_FORM_strp offset too big: %lx\n"), offset);
+      warn (_("DW_FORM_strp offset too big: %lx\n"), (long) offset);
       return _("<offset is too big>");
     }
 
@@ -605,13 +606,13 @@  decode_location_expression (unsigned cha
 			    unsigned int pointer_size,
 			    unsigned int offset_size,
 			    int dwarf_version,
-			    unsigned long length,
-			    unsigned long cu_offset,
+			    dw2_vma_t length,
+			    dw2_vma_t cu_offset,
 			    struct dwarf_section * section)
 {
   unsigned op;
   unsigned int bytes_read;
-  unsigned long uvalue;
+  dw2_vma_t uvalue;
   unsigned char *end = data + length;
   int need_frame_base = 0;
 
@@ -662,11 +663,13 @@  decode_location_expression (unsigned cha
 	  data += 8;
 	  break;
 	case DW_OP_constu:
-	  printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0));
+	  printf ("DW_OP_constu: %" DW2_VMA_FMT "u",
+		  read_leb128 (data, &bytes_read, 0));
 	  data += bytes_read;
 	  break;
 	case DW_OP_consts:
-	  printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1));
+	  printf ("DW_OP_consts: %" DW2_VMA_FMT "d",
+		  read_leb128 (data, &bytes_read, 1));
 	  data += bytes_read;
 	  break;
 	case DW_OP_dup:
@@ -721,7 +724,7 @@  decode_location_expression (unsigned cha
 	  printf ("DW_OP_plus");
 	  break;
 	case DW_OP_plus_uconst:
-	  printf ("DW_OP_plus_uconst: %lu",
+	  printf ("DW_OP_plus_uconst: %" DW2_VMA_FMT "u",
 		  read_leb128 (data, &bytes_read, 0));
 	  data += bytes_read;
 	  break;
@@ -867,7 +870,8 @@  decode_location_expression (unsigned cha
 	case DW_OP_breg29:
 	case DW_OP_breg30:
 	case DW_OP_breg31:
-	  printf ("DW_OP_breg%d (%s): %ld", op - DW_OP_breg0,
+	  printf ("DW_OP_breg%d (%s): %" DW2_VMA_FMT "d",
+		  op - DW_OP_breg0,
 		  regname (op - DW_OP_breg0, 1),
 		  read_leb128 (data, &bytes_read, 1));
 	  data += bytes_read;
@@ -876,22 +880,26 @@  decode_location_expression (unsigned cha
 	case DW_OP_regx:
 	  uvalue = read_leb128 (data, &bytes_read, 0);
 	  data += bytes_read;
-	  printf ("DW_OP_regx: %lu (%s)", uvalue, regname (uvalue, 1));
+	  printf ("DW_OP_regx: %" DW2_VMA_FMT "u (%s)",
+		  uvalue, regname (uvalue, 1));
 	  break;
 	case DW_OP_fbreg:
 	  need_frame_base = 1;
-	  printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1));
+	  printf ("DW_OP_fbreg: %" DW2_VMA_FMT "d",
+		  read_leb128 (data, &bytes_read, 1));
 	  data += bytes_read;
 	  break;
 	case DW_OP_bregx:
 	  uvalue = read_leb128 (data, &bytes_read, 0);
 	  data += bytes_read;
-	  printf ("DW_OP_bregx: %lu (%s) %ld", uvalue, regname (uvalue, 1),
+	  printf ("DW_OP_bregx: %" DW2_VMA_FMT "u (%s) %" DW2_VMA_FMT "d",
+		  uvalue, regname (uvalue, 1),
 		  read_leb128 (data, &bytes_read, 1));
 	  data += bytes_read;
 	  break;
 	case DW_OP_piece:
-	  printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0));
+	  printf ("DW_OP_piece: %" DW2_VMA_FMT "u",
+		  read_leb128 (data, &bytes_read, 0));
 	  data += bytes_read;
 	  break;
 	case DW_OP_deref_size:
@@ -911,13 +919,15 @@  decode_location_expression (unsigned cha
 	case DW_OP_call2:
 	  /* XXX: Strictly speaking for 64-bit DWARF3 files
 	     this ought to be an 8-byte wide computation.  */
-	  printf ("DW_OP_call2: <0x%lx>", (long) byte_get (data, 2) + cu_offset);
+	  printf ("DW_OP_call2: <0x%" DW2_VMA_FMT "x>",
+		  (dw2_svma_t) byte_get (data, 2) + cu_offset);
 	  data += 2;
 	  break;
 	case DW_OP_call4:
 	  /* XXX: Strictly speaking for 64-bit DWARF3 files
 	     this ought to be an 8-byte wide computation.  */
-	  printf ("DW_OP_call4: <0x%lx>", (long) byte_get (data, 4) + cu_offset);
+	  printf ("DW_OP_call4: <0x%" DW2_VMA_FMT "x>",
+		  (dw2_svma_t) byte_get (data, 4) + cu_offset);
 	  data += 4;
 	  break;
 	case DW_OP_call_ref:
@@ -950,9 +960,11 @@  decode_location_expression (unsigned cha
 	  break;
 	case DW_OP_bit_piece:
 	  printf ("DW_OP_bit_piece: ");
-	  printf ("size: %lu ", read_leb128 (data, &bytes_read, 0));
+	  printf ("size: %" DW2_VMA_FMT "u ",
+		  read_leb128 (data, &bytes_read, 0));
 	  data += bytes_read;
-	  printf ("offset: %lu ", read_leb128 (data, &bytes_read, 0));
+	  printf ("offset: %" DW2_VMA_FMT "u ",
+		  read_leb128 (data, &bytes_read, 0));
 	  data += bytes_read;
 	  break;
 
@@ -1001,16 +1013,20 @@  decode_location_expression (unsigned cha
 	    }
 	  if (dwarf_version == 2)
 	    {
-	      printf ("DW_OP_GNU_implicit_pointer: <0x%lx> %ld",
-		      (long) byte_get (data, pointer_size),
-		      read_leb128 (data + pointer_size, &bytes_read, 1));
+	      printf ("DW_OP_GNU_implicit_pointer: "
+		      "<0x%" DW2_VMA_FMT "x> %" DW2_VMA_FMT "d",
+		      (dw2_vma_t) byte_get (data, pointer_size),
+		      (dw2_svma_t) read_leb128 (data + pointer_size,
+						&bytes_read, 1));
 	      data += pointer_size + bytes_read;
 	    }
 	  else
 	    {
-	      printf ("DW_OP_GNU_implicit_pointer: <0x%lx> %ld",
-		      (long) byte_get (data, offset_size),
-		      read_leb128 (data + offset_size, &bytes_read, 1));
+	      printf ("DW_OP_GNU_implicit_pointer: "
+		      "<0x%" DW2_VMA_FMT "x> %" DW2_VMA_FMT "d",
+		      (dw2_vma_t) byte_get (data, offset_size),
+		      (dw2_svma_t) read_leb128 (data + offset_size,
+						&bytes_read, 1));
 	      data += offset_size + bytes_read;
 	    }
 	  break;
@@ -1072,15 +1088,15 @@  static unsigned char *
 read_and_display_attr_value (unsigned long attribute,
 			     unsigned long form,
 			     unsigned char * data,
-			     unsigned long cu_offset,
-			     unsigned long pointer_size,
-			     unsigned long offset_size,
+			     dw2_vma_t cu_offset,
+			     dw2_vma_t pointer_size,
+			     dw2_vma_t offset_size,
 			     int dwarf_version,
 			     debug_info * debug_info_p,
 			     int do_loc,
 			     struct dwarf_section * section)
 {
-  unsigned long uvalue = 0;
+  dw2_vma_t uvalue = 0;
   unsigned char *block_start = NULL;
   unsigned char * orig_data = data;
   unsigned int bytes_read;
@@ -1167,7 +1183,7 @@  read_and_display_attr_value (unsigned lo
     {
     case DW_FORM_ref_addr:
       if (!do_loc)
-	printf (" <0x%lx>", uvalue);
+	printf (" <0x%" DW2_VMA_FMT "x>", uvalue);
       break;
 
     case DW_FORM_ref1:
@@ -1175,14 +1191,14 @@  read_and_display_attr_value (unsigned lo
     case DW_FORM_ref4:
     case DW_FORM_ref_udata:
       if (!do_loc)
-	printf (" <0x%lx>", uvalue + cu_offset);
+	printf (" <0x%" DW2_VMA_FMT "x>", uvalue + cu_offset);
       break;
 
     case DW_FORM_data4:
     case DW_FORM_addr:
     case DW_FORM_sec_offset:
       if (!do_loc)
-	printf (" 0x%lx", uvalue);
+	printf (" 0x%" DW2_VMA_FMT "x", uvalue);
       break;
 
     case DW_FORM_flag_present:
@@ -1192,7 +1208,7 @@  read_and_display_attr_value (unsigned lo
     case DW_FORM_sdata:
     case DW_FORM_udata:
       if (!do_loc)
-	printf (" %ld", uvalue);
+	printf (" %" DW2_VMA_FMT "d", uvalue);
       break;
 
     case DW_FORM_ref8:
@@ -1200,7 +1216,7 @@  read_and_display_attr_value (unsigned lo
       if (!do_loc)
 	{
 	  uvalue = byte_get (data, 4);
-	  printf (" 0x%lx", uvalue);
+	  printf (" 0x%" DW2_VMA_FMT "x", uvalue);
 	  printf (" 0x%lx", (unsigned long) byte_get (data + 4, 4));
 	}
       if ((do_loc || do_debug_loc || do_debug_ranges)
@@ -1209,7 +1225,7 @@  read_and_display_attr_value (unsigned lo
 	  if (sizeof (uvalue) == 8)
 	    uvalue = byte_get (data, 8);
 	  else
-	    error (_("DW_FORM_data8 is unsupported when sizeof (unsigned long) != 8\n"));
+	    error (_("DW_FORM_data8 is unsupported when sizeof (dw2_vma_t) != 8\n"));
 	}
       data += 8;
       break;
@@ -1259,7 +1275,7 @@  read_and_display_attr_value (unsigned lo
 
     case DW_FORM_strp:
       if (!do_loc)
-	printf (_(" (indirect string, offset: 0x%lx): %s"),
+	printf (_(" (indirect string, offset: 0x%" DW2_VMA_FMT "x): %s"),
 		uvalue, fetch_indirect_string (uvalue));
       break;
 
@@ -1313,7 +1329,7 @@  read_and_display_attr_value (unsigned lo
 	      if (lmax == 0 || num >= lmax)
 		{
 		  lmax += 1024;
-		  debug_info_p->loc_offsets = (long unsigned int *)
+		  debug_info_p->loc_offsets = (dw2_vma_t *)
                       xcrealloc (debug_info_p->loc_offsets,
 				 lmax, sizeof (*debug_info_p->loc_offsets));
 		  debug_info_p->have_frame_base = (int *)
@@ -1344,7 +1360,7 @@  read_and_display_attr_value (unsigned lo
 	      if (lmax == 0 || num >= lmax)
 		{
 		  lmax += 1024;
-		  debug_info_p->range_lists = (long unsigned int *)
+		  debug_info_p->range_lists = (dw2_vma_t *)
                       xcrealloc (debug_info_p->range_lists,
 				 lmax, sizeof (*debug_info_p->range_lists));
 		  debug_info_p->max_range_lists = lmax;
@@ -1383,7 +1399,8 @@  read_and_display_attr_value (unsigned lo
 	  printf (_("(declared as inline and inlined)"));
 	  break;
 	default:
-	  printf (_("  (Unknown inline attribute value: %lx)"), uvalue);
+	  printf (_("  (Unknown inline attribute value: %" DW2_VMA_FMT "x)"),
+	  	  uvalue);
 	  break;
 	}
       break;
@@ -1421,9 +1438,9 @@  read_and_display_attr_value (unsigned lo
 	case DW_LANG_Upc:		printf ("(Unified Parallel C)"); break;
 	default:
 	  if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
-	    printf ("(implementation defined: %lx)", uvalue);
+	    printf ("(implementation defined: %" DW2_VMA_FMT "x)", uvalue);
 	  else
-	    printf ("(Unknown: %lx)", uvalue);
+	    printf ("(Unknown: %" DW2_VMA_FMT "x)", uvalue);
 	  break;
 	}
       break;
@@ -1584,7 +1601,7 @@  read_and_display_attr_value (unsigned lo
 	  uvalue += cu_offset;
 
 	if (uvalue >= section->size)
-	  warn (_("Offset %lx used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
+	  warn (_("Offset %" DW2_VMA_FMT "x used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
 		uvalue, (unsigned long) (orig_data - section->start));
 	else
 	  {
@@ -1786,9 +1803,9 @@  static unsigned char *
 read_and_display_attr (unsigned long attribute,
 		       unsigned long form,
 		       unsigned char * data,
-		       unsigned long cu_offset,
-		       unsigned long pointer_size,
-		       unsigned long offset_size,
+		       dw2_vma_t cu_offset,
+		       dw2_vma_t pointer_size,
+		       dw2_vma_t offset_size,
 		       int dwarf_version,
 		       debug_info * debug_info_p,
 		       int do_loc,
@@ -1900,7 +1917,7 @@  process_debug_info (struct dwarf_section
       unsigned char *hdrptr;
       unsigned char *tags;
       int level;
-      unsigned long cu_offset;
+      dw2_vma_t cu_offset;
       int offset_size;
       int initial_length_size;
       unsigned char signature[8] = { 0 };
@@ -1970,11 +1987,13 @@  process_debug_info (struct dwarf_section
 
       if (!do_loc)
 	{
-	  printf (_("  Compilation Unit @ offset 0x%lx:\n"), cu_offset);
-	  printf (_("   Length:        0x%lx (%s)\n"), compunit.cu_length,
+	  printf (_("  Compilation Unit @ offset 0x%" DW2_VMA_FMT "x:\n"), cu_offset);
+	  printf (_("   Length:        0x%" DW2_VMA_FMT "x (%s)\n"),
+		  compunit.cu_length,
 		  initial_length_size == 8 ? "64-bit" : "32-bit");
 	  printf (_("   Version:       %d\n"), compunit.cu_version);
-	  printf (_("   Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
+	  printf (_("   Abbrev Offset: %" DW2_VMA_FMT "d\n"),
+		  compunit.cu_abbrev_offset);
 	  printf (_("   Pointer Size:  %d\n"), compunit.cu_pointer_size);
 	  if (do_types)
 	    {
@@ -1990,7 +2009,9 @@  process_debug_info (struct dwarf_section
       if (cu_offset + compunit.cu_length + initial_length_size
 	  > section->size)
 	{
-	  warn (_("Debug info is corrupted, length of CU at %lx extends beyond end of section (length = %lx)\n"),
+	  warn (_("Debug info is corrupted, length of CU at %"
+	  	  DW2_VMA_FMT "x extends beyond end of section (length = %"
+	  	  DW2_VMA_FMT "x)\n"),
 		cu_offset, compunit.cu_length);
 	  break;
 	}
@@ -2001,7 +2022,8 @@  process_debug_info (struct dwarf_section
 	  && compunit.cu_version != 3
 	  && compunit.cu_version != 4)
 	{
-	  warn (_("CU at offset %lx contains corrupt or unsupported version number: %d.\n"),
+	  warn (_("CU at offset %" DW2_VMA_FMT "x contains corrupt or "
+		  "unsupported version number: %d.\n"),
 		cu_offset, compunit.cu_version);
 	  continue;
 	}
@@ -2268,7 +2290,7 @@  display_debug_lines_raw (struct dwarf_se
       linfo.li_line_base >>= 24;
 
       printf (_("  Offset:                      0x%lx\n"), hdroff);
-      printf (_("  Length:                      %ld\n"), linfo.li_length);
+      printf (_("  Length:                      %ld\n"), (long) linfo.li_length);
       printf (_("  DWARF Version:               %d\n"), linfo.li_version);
       printf (_("  Prologue Length:             %d\n"), linfo.li_prologue_length);
       printf (_("  Minimum Instruction Length:  %d\n"), linfo.li_min_insn_length);
@@ -2329,11 +2351,14 @@  display_debug_lines_raw (struct dwarf_se
 
 	      data += strlen ((char *) data) + 1;
 
-	      printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
+	      printf ("%" DW2_VMA_FMT "u\t",
+		      read_leb128 (data, & bytes_read, 0));
 	      data += bytes_read;
-	      printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
+	      printf ("%" DW2_VMA_FMT "u\t",
+		      read_leb128 (data, & bytes_read, 0));
 	      data += bytes_read;
-	      printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
+	      printf ("%" DW2_VMA_FMT "u\t",
+		      read_leb128 (data, & bytes_read, 0));
 	      data += bytes_read;
 	      printf ("%s\n", name);
 	    }
@@ -2505,7 +2530,8 @@  display_debug_lines_raw (struct dwarf_se
 
 	      for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
 		{
-		  printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0),
+		  printf ("0x%" DW2_VMA_FMT "x%s",
+			  read_leb128 (data, &bytes_read, 0),
 			  i == 1 ? "" : ", ");
 		  data += bytes_read;
 		}
@@ -2918,7 +2944,8 @@  display_debug_lines_decoded (struct dwar
 
               for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
                 {
-                  printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0),
+                  printf ("0x%" DW2_VMA_FMT "x%s",
+			  read_leb128 (data, &bytes_read, 0),
                           i == 1 ? "" : ", ");
                   data += bytes_read;
                 }
@@ -3076,7 +3103,7 @@  display_debug_pubnames (struct dwarf_sec
 	  && num_debug_info_entries > 0
 	  && find_debug_info_for_offset (names.pn_offset) == NULL)
 	warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
-	      names.pn_offset, section->name);
+	      (unsigned long) names.pn_offset, section->name);
 
       names.pn_size = byte_get (data, offset_size);
       data += offset_size;
@@ -3097,13 +3124,13 @@  display_debug_pubnames (struct dwarf_sec
 	}
 
       printf (_("  Length:                              %ld\n"),
-	      names.pn_length);
+	      (long) names.pn_length);
       printf (_("  Version:                             %d\n"),
 	      names.pn_version);
       printf (_("  Offset into .debug_info section:     0x%lx\n"),
-	      names.pn_offset);
+	      (unsigned long) names.pn_offset);
       printf (_("  Size of area in .debug_info section: %ld\n"),
-	      names.pn_size);
+	      (long) names.pn_size);
 
       printf (_("\n    Offset\tName\n"));
 
@@ -3323,7 +3350,7 @@  display_debug_loc (struct dwarf_section 
   /* DWARF sections under Mach-O have non-zero addresses.  */
   if (debug_information [first].num_loc_offsets > 0
       && debug_information [first].loc_offsets [0] != section->address)
-    warn (_("Location lists in %s section start at 0x%lx\n"),
+    warn (_("Location lists in %s section start at 0x%" DW2_VMA_FMT "x\n"),
 	  section->name, debug_information [first].loc_offsets [0]);
 
   printf (_("Contents of the %s section:\n\n"), section->name);
@@ -3596,7 +3623,7 @@  display_debug_aranges (struct dwarf_sect
 	  && num_debug_info_entries > 0
 	  && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
 	warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
-	      arange.ar_info_offset, section->name);
+	      (unsigned long) arange.ar_info_offset, section->name);
 
       arange.ar_pointer_size = byte_get (hdrptr, 1);
       hdrptr += 1;
@@ -3610,9 +3637,11 @@  display_debug_aranges (struct dwarf_sect
 	  break;
 	}
 
-      printf (_("  Length:                   %ld\n"), arange.ar_length);
+      printf (_("  Length:                   %ld\n"),
+	      (long) arange.ar_length);
       printf (_("  Version:                  %d\n"), arange.ar_version);
-      printf (_("  Offset into .debug_info:  0x%lx\n"), arange.ar_info_offset);
+      printf (_("  Offset into .debug_info:  0x%lx\n"),
+	      (unsigned long) arange.ar_info_offset);
       printf (_("  Pointer Size:             %d\n"), arange.ar_pointer_size);
       printf (_("  Segment Size:             %d\n"), arange.ar_segment_size);
 
Index: src/binutils/dwarf.h
===================================================================
--- src.orig/binutils/dwarf.h	2011-02-17 11:00:34.000000000 +0100
+++ src/binutils/dwarf.h	2011-02-17 11:18:37.972034400 +0100
@@ -19,6 +19,8 @@ 
    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
    MA 02110-1301, USA.  */
 
+#include "dwarf2.h"
+
 typedef unsigned HOST_WIDEST_INT dwarf_vma;
 typedef unsigned HOST_WIDEST_INT dwarf_size_type;
 
@@ -79,15 +81,15 @@  typedef struct
   unsigned int   pointer_size;
   unsigned int   offset_size;
   int            dwarf_version;
-  unsigned long  cu_offset;
-  unsigned long	 base_address;
+  dw2_vma_t	 cu_offset;
+  dw2_vma_t	 base_address;
   /* This is an array of offsets to the location list table.  */
-  unsigned long *loc_offsets;
+  dw2_vma_t	*loc_offsets;
   int		*have_frame_base;
   unsigned int   num_loc_offsets;
   unsigned int   max_loc_offsets;
   /* List of .debug_ranges offsets seen in this .debug_info.  */
-  unsigned long *range_lists;
+  dw2_vma_t	*range_lists;
   unsigned int   num_range_lists;
   unsigned int   max_range_lists;
 }
@@ -131,5 +133,5 @@  void *cmalloc (size_t, size_t);
 void *xcmalloc (size_t, size_t);
 void *xcrealloc (void *, size_t, size_t);
 
-unsigned long int read_leb128 (unsigned char *data,
-			       unsigned int *length_return, int sign);
+dw2_vma_t read_leb128 (unsigned char *data,
+		       unsigned int *length_return, int sign);
Index: src/include/dwarf2.h
===================================================================
--- src.orig/include/dwarf2.h	2011-02-17 11:00:34.000000000 +0100
+++ src/include/dwarf2.h	2011-02-17 12:22:16.839408800 +0100
@@ -47,6 +47,35 @@ 
 #ifndef _ELF_DWARF2_H
 #define _ELF_DWARF2_H
 
+#if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
+/* We need here widest integer type so that even for cross scenarios
+   a wide enough integer scalar value is used to hold address vma.
+   Additionally it is necessary here to use for non-LP64 targets the
+   proper integer scalar value to hold an address.  */
+#ifdef __GNUC__
+__extension__
+#endif
+typedef unsigned long long dw2_vma_t;
+#ifdef __GNUC__
+__extension__
+#endif
+typedef signed long long dw2_svma_t;
+
+#ifndef __MINGW32__
+#define DW2_VMA_FMT	"ll"
+#else
+#define DW2_VMA_FMT	"I64"
+#endif
+
+#else
+
+typedef unsigned long dw2_vma_t;
+typedef signed long dw2_svma_t;
+
+#define DW2_VMA_FMT	"l"
+
+#endif
+
 /* Structure found in the .debug_line section.  */
 typedef struct
 {
@@ -63,7 +92,7 @@  DWARF2_External_LineInfo;
 
 typedef struct
 {
-  unsigned long  li_length;
+  dw2_vma_t	 li_length;
   unsigned short li_version;
   unsigned int   li_prologue_length;
   unsigned char  li_min_insn_length;
@@ -87,10 +116,10 @@  DWARF2_External_PubNames;
 
 typedef struct
 {
-  unsigned long  pn_length;
+  dw2_vma_t	 pn_length;
   unsigned short pn_version;
-  unsigned long  pn_offset;
-  unsigned long  pn_size;
+  dw2_vma_t	 pn_offset;
+  dw2_vma_t	 pn_size;
 }
 DWARF2_Internal_PubNames;
 
@@ -106,9 +135,9 @@  DWARF2_External_CompUnit;
 
 typedef struct
 {
-  unsigned long  cu_length;
+  dw2_vma_t	 cu_length;
   unsigned short cu_version;
-  unsigned long  cu_abbrev_offset;
+  dw2_vma_t	 cu_abbrev_offset;
   unsigned char  cu_pointer_size;
 }
 DWARF2_Internal_CompUnit;
@@ -125,9 +154,9 @@  DWARF2_External_ARange;
 
 typedef struct
 {
-  unsigned long  ar_length;
+  dw2_vma_t	 ar_length;
   unsigned short ar_version;
-  unsigned long  ar_info_offset;
+  dw2_vma_t	 ar_info_offset;
   unsigned char  ar_pointer_size;
   unsigned char  ar_segment_size;
 }