From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4345 invoked by alias); 27 Dec 2004 19:01:42 -0000 Mailing-List: contact binutils-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sources.redhat.com Received: (qmail 4199 invoked from network); 27 Dec 2004 19:01:31 -0000 Received: from unknown (HELO sccrmhc12.comcast.net) (204.127.202.56) by sourceware.org with SMTP; 27 Dec 2004 19:01:31 -0000 Received: from lucon.org ([24.6.212.230]) by comcast.net (sccrmhc12) with ESMTP id <20041227190130012007uvsne>; Mon, 27 Dec 2004 19:01:30 +0000 Received: by lucon.org (Postfix, from userid 1000) id 2E495640F4; Mon, 27 Dec 2004 11:01:30 -0800 (PST) Date: Mon, 27 Dec 2004 19:01:00 -0000 From: "H. J. Lu" To: binutils@sources.redhat.com Cc: GDB Subject: Re: PATCH: Fix read_leb128 in readelf for 64bit host Message-ID: <20041227190130.GA21178@lucon.org> References: <20041226004229.GA6483@lucon.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="17pEHd4RhPHOinZp" Content-Disposition: inline In-Reply-To: <20041226004229.GA6483@lucon.org> User-Agent: Mutt/1.4.1i X-SW-Source: 2004-12/txt/msg00312.txt.bz2 --17pEHd4RhPHOinZp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1261 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 * 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; } --17pEHd4RhPHOinZp Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="gdb-leb128-1.patch" Content-length: 639 2004-12-27 H.J. Lu * 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; --17pEHd4RhPHOinZp--