public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* PATCH: Fix read_leb128 in readelf for 64bit host
@ 2004-12-26  0:42 H. J. Lu
  2004-12-27 19:01 ` H. J. Lu
  0 siblings, 1 reply; 5+ messages in thread
From: H. J. Lu @ 2004-12-26  0:42 UTC (permalink / raw)
  To: binutils

read_leb128 in readelf assumes long == int == 32bit. It doesn't work
with 64bit host. Does this patch look right?


H.J.
---
2004-12-25  H.J. Lu  <hongjiu.lu@intel.com>

	* readelf.c (read_leb128): Support 64bit host.

--- binutils/readelf.c.leb	2004-12-10 14:20:22.000000000 -0800
+++ binutils/readelf.c	2004-12-25 16:16:54.615198445 -0800
@@ -6933,7 +6933,7 @@ read_leb128 (unsigned char *data, int *l
 {
   unsigned long int result = 0;
   unsigned int num_read = 0;
-  int shift = 0;
+  unsigned int shift = 0;
   unsigned char byte;
 
   do
@@ -6951,8 +6951,8 @@ read_leb128 (unsigned char *data, int *l
   if (length_return != NULL)
     *length_return = num_read;
 
-  if (sign && (shift < 32) && (byte & 0x40))
-    result |= -1 << shift;
+  if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
+    result |= -1L << shift;
 
   return result;
 }

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: Fix read_leb128 in readelf for 64bit host
  2004-12-26  0:42 PATCH: Fix read_leb128 in readelf for 64bit host H. J. Lu
@ 2004-12-27 19:01 ` H. J. Lu
  2004-12-28 13:15   ` Dave Korn
  0 siblings, 1 reply; 5+ messages in thread
From: H. J. Lu @ 2004-12-27 19:01 UTC (permalink / raw)
  To: binutils; +Cc: GDB

[-- Attachment #1: Type: text/plain, Size: 1261 bytes --]

On Sat, Dec 25, 2004 at 04:42:29PM -0800, H. J. Lu wrote:
> read_leb128 in readelf assumes long == int == 32bit. It doesn't work
> with 64bit host. Does this patch look right?
> 
> 

I am going to check in this patch. Gdb 6.3 has the same problem. I
am enclosing a patch here.


H.J.
----
2004-12-27  H.J. Lu  <hongjiu.lu@intel.com>

	* readelf.c (read_leb128): Support 64bit host.

--- binutils/readelf.c.leb	2004-12-10 14:20:22.000000000 -0800
+++ binutils/readelf.c	2004-12-27 10:49:33.689234088 -0800
@@ -6933,7 +6933,7 @@ read_leb128 (unsigned char *data, int *l
 {
   unsigned long int result = 0;
   unsigned int num_read = 0;
-  int shift = 0;
+  unsigned int shift = 0;
   unsigned char byte;
 
   do
@@ -6941,7 +6941,7 @@ read_leb128 (unsigned char *data, int *l
       byte = *data++;
       num_read++;
 
-      result |= (byte & 0x7f) << shift;
+      result |= ((unsigned long int) (byte & 0x7f)) << shift;
 
       shift += 7;
 
@@ -6951,8 +6951,8 @@ read_leb128 (unsigned char *data, int *l
   if (length_return != NULL)
     *length_return = num_read;
 
-  if (sign && (shift < 32) && (byte & 0x40))
-    result |= -1 << shift;
+  if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
+    result |= -1L << shift;
 
   return result;
 }


[-- Attachment #2: gdb-leb128-1.patch --]
[-- Type: text/plain, Size: 639 bytes --]

2004-12-27  H.J. Lu  <hongjiu.lu@intel.com>

	* dwarf2read.c (read_signed_leb128): Support 64bit host.

--- gdb/dwarf2read.c.leb	2004-12-21 14:24:06.000000000 -0800
+++ gdb/dwarf2read.c	2004-12-27 10:55:02.912450066 -0800
@@ -6098,7 +6098,7 @@ read_signed_leb128 (bfd *abfd, char *buf
 
   result = 0;
   shift = 0;
-  size = 32;
+  size = 8 * sizeof (result);
   num_read = 0;
   i = 0;
   while (1)
@@ -6115,7 +6115,7 @@ read_signed_leb128 (bfd *abfd, char *buf
     }
   if ((shift < size) && (byte & 0x40))
     {
-      result |= -(1 << shift);
+      result |= -(1L << shift);
     }
   *bytes_read_ptr = num_read;
   return result;

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: PATCH: Fix read_leb128 in readelf for 64bit host
  2004-12-27 19:01 ` H. J. Lu
@ 2004-12-28 13:15   ` Dave Korn
  2004-12-28 14:57     ` Daniel Jacobowitz
  0 siblings, 1 reply; 5+ messages in thread
From: Dave Korn @ 2004-12-28 13:15 UTC (permalink / raw)
  To: 'H. J. Lu', binutils; +Cc: 'GDB'

> -----Original Message-----
> From: binutils-owner On Behalf Of H. J. Lu
> Sent: 27 December 2004 19:02

> On Sat, Dec 25, 2004 at 04:42:29PM -0800, H. J. Lu wrote:
> > read_leb128 in readelf assumes long == int == 32bit. It doesn't work
> > with 64bit host. Does this patch look right?
> > 
> > 
> 
> I am going to check in this patch. Gdb 6.3 has the same problem. I
> am enclosing a patch here.

> --- binutils/readelf.c.leb	2004-12-10 14:20:22.000000000 -0800
> +++ binutils/readelf.c	2004-12-27 10:49:33.689234088 -0800
> @@ -6933,7 +6933,7 @@ read_leb128 (unsigned char *data, int *l
>  {
>    unsigned long int result = 0;
>    unsigned int num_read = 0;
> -  int shift = 0;
> +  unsigned int shift = 0;
>    unsigned char byte;
>  
>    do
> @@ -6941,7 +6941,7 @@ read_leb128 (unsigned char *data, int *l
>        byte = *data++;
>        num_read++;
>  
> -      result |= (byte & 0x7f) << shift;
> +      result |= ((unsigned long int) (byte & 0x7f)) << shift;
>  
>        shift += 7;
>  
> @@ -6951,8 +6951,8 @@ read_leb128 (unsigned char *data, int *l
>    if (length_return != NULL)
>      *length_return = num_read;
>  
> -  if (sign && (shift < 32) && (byte & 0x40))
> -    result |= -1 << shift;
> +  if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
> +    result |= -1L << shift;
>  
>    return result;
>  }
> 

  IIRC the C spec says shift amounts >=32 are undefined behaviour, even in the
presence of larger integer types.  Is shift ever going to be >= 32 for 64 bit
hosts in these functions?  (I suspect it will).  If so, the shift must be
decomposed into two smaller shifts, no?

    cheers, 
      DaveK
-- 
Can't think of a witty .sigline today....

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: Fix read_leb128 in readelf for 64bit host
  2004-12-28 13:15   ` Dave Korn
@ 2004-12-28 14:57     ` Daniel Jacobowitz
  2004-12-28 20:48       ` Dave Korn
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Jacobowitz @ 2004-12-28 14:57 UTC (permalink / raw)
  To: Dave Korn; +Cc: 'H. J. Lu', binutils, 'GDB'

On Tue, Dec 28, 2004 at 01:13:14PM -0000, Dave Korn wrote:
>   IIRC

You don't :-)  C99 6.5.7#3...

> the C spec says shift amounts >=32 are undefined behaviour, even in the
> presence of larger integer types.

-- 
Daniel Jacobowitz

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: PATCH: Fix read_leb128 in readelf for 64bit host
  2004-12-28 14:57     ` Daniel Jacobowitz
@ 2004-12-28 20:48       ` Dave Korn
  0 siblings, 0 replies; 5+ messages in thread
From: Dave Korn @ 2004-12-28 20:48 UTC (permalink / raw)
  To: 'Daniel Jacobowitz'; +Cc: 'H. J. Lu', binutils, 'GDB'

> -----Original Message-----
> From: Daniel Jacobowitz  
> Sent: 28 December 2004 14:57
> To: Dave Korn
> Cc: 'H. J. Lu'; binutils@sources.redhat.com; 'GDB'
> Subject: Re: PATCH: Fix read_leb128 in readelf for 64bit host
> 
> On Tue, Dec 28, 2004 at 01:13:14PM -0000, Dave Korn wrote:
> >   IIRC
> 
> You don't :-)  C99 6.5.7#3...
 

  Jolly good then!


    cheers, 
      DaveK
-- 
Can't think of a witty .sigline today....

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-12-28 20:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-26  0:42 PATCH: Fix read_leb128 in readelf for 64bit host H. J. Lu
2004-12-27 19:01 ` H. J. Lu
2004-12-28 13:15   ` Dave Korn
2004-12-28 14:57     ` Daniel Jacobowitz
2004-12-28 20:48       ` Dave Korn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).