From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21897 invoked by alias); 28 Dec 2004 13:15:21 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 21797 invoked from network); 28 Dec 2004 13:15:13 -0000 Received: from unknown (HELO NUTMEG.CAM.ARTIMI.COM) (217.40.111.177) by sourceware.org with SMTP; 28 Dec 2004 13:15:13 -0000 Received: from mace ([192.168.1.25]) by NUTMEG.CAM.ARTIMI.COM with Microsoft SMTPSVC(6.0.3790.211); Tue, 28 Dec 2004 13:13:15 +0000 From: "Dave Korn" To: "'H. J. Lu'" , Cc: "'GDB'" Subject: RE: PATCH: Fix read_leb128 in readelf for 64bit host Date: Tue, 28 Dec 2004 14:57:00 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit In-Reply-To: <20041227190130.GA21178@lucon.org> Message-ID: X-OriginalArrivalTime: 28 Dec 2004 13:13:15.0031 (UTC) FILETIME=[FD54E270:01C4ECDE] X-SW-Source: 2004-12/txt/msg00449.txt.bz2 > -----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....