From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22871 invoked by alias); 11 Feb 2010 12:43:13 -0000 Received: (qmail 22847 invoked by uid 22791); 11 Feb 2010 12:43:12 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 11 Feb 2010 12:43:08 +0000 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o1BCh61S012103 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 11 Feb 2010 07:43:06 -0500 Received: from host0.dyn.jankratochvil.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o1BCh4Hn009298 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 11 Feb 2010 07:43:06 -0500 Received: from host0.dyn.jankratochvil.net (localhost [127.0.0.1]) by host0.dyn.jankratochvil.net (8.14.3/8.14.3) with ESMTP id o1BCh3St009040; Thu, 11 Feb 2010 13:43:03 +0100 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.14.3/8.14.3/Submit) id o1BCh2cw009039; Thu, 11 Feb 2010 13:43:02 +0100 Date: Thu, 11 Feb 2010 12:43:00 -0000 From: Jan Kratochvil To: Andreas Schwab Cc: binutils@sourceware.org, gdb-patches@sourceware.org Subject: Re: [patch] bfd/: bfd_elf_bfd_from_remote_memory 32bit &= 0xffffffff Message-ID: <20100211124302.GA8435@host0.dyn.jankratochvil.net> References: <20100211115730.GA7358@host0.dyn.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-08-17) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-02/txt/msg00285.txt.bz2 On Thu, 11 Feb 2010 13:13:43 +0100, Andreas Schwab wrote: > Jan Kratochvil writes: > > > --- a/bfd/elfcode.h > > +++ b/bfd/elfcode.h > > @@ -1745,6 +1745,8 @@ NAME(_bfd_elf,bfd_from_remote_memory) > > if (!loadbase_set && (i_phdrs[i].p_offset & -i_phdrs[i].p_align) == 0) > > { > > loadbase = ehdr_vma - (i_phdrs[i].p_vaddr & -i_phdrs[i].p_align); > > + if (ELFCLASS == ELFCLASS32) > > + loadbase &= 0xffffffff; > > Some targets use signed addresses. http://sourceware.org/ml/gdb-patches/2006-09/msg00197.html # One caveat: # if addresses are supposed to be sign extended, we should not print out # 64-bit addresses for a 32-bit target just because they're sign # extended. This will show up on MIPS, which sign extends addresses. Thanks for bringing up this larger issue. As this representation is only internal to gdb (bfd) I chose rather to use always the unsigned/zeroed format as it makes its internal handling in tools IMO easier. It does not (or at least does not have to) affect any inferior- or user- visible behavior. If someone casts CORE_ADDR -> LONGEST/ULONGEST then CORE_ADDR should be extended the proper sign/unsigned way from its target width (such as 32->64). This patch is a prerequisite for PIE support on 64bit gdb -> 32bit inferior, commented by Ulrich Weigand in: http://sourceware.org/ml/gdb-patches/2010-01/msg00497.html The full gdb patch (not yet posted) already does explicit handling of target width on any CORE_ADDR in use as an address _displacement_ by ensuring a compilation error otherwise: +/* Wrap CORE_ADDR so that normal math operation are no longer valid on it. Use + the set of functions around addr_add_offset to access it. Direct access to + A is permitted for reading A and setting A to constant like zero or one. */ +typedef struct + { + CORE_ADDR a; + } +addr_offset_t; There should be similar part done for all the CORE_ADDR operations to properly respect target address width. This is currently already broken anyway. Therefore if we either always-zero-extend or target-wise-sign-extend CORE_ADDR should not be a regression. I do not intend to post such full CORE_ADDR fixup (outside of the biarch-PIE functionality) in a near future, though. It may be simpler if CORE_ADDR would be a C++ class with overriden operators. But moving GDB over to C++ has been currently turned down. Thanks, Jan