From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1314 invoked by alias); 18 Feb 2010 10:18:43 -0000 Received: (qmail 1305 invoked by uid 22791); 18 Feb 2010 10:18:42 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from sibelius.xs4all.nl (HELO glazunov.sibelius.xs4all.nl) (83.163.83.176) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 18 Feb 2010 10:18:38 +0000 Received: from glazunov.sibelius.xs4all.nl (kettenis@localhost [127.0.0.1]) by glazunov.sibelius.xs4all.nl (8.14.3/8.14.3) with ESMTP id o1IAHFuw027561; Thu, 18 Feb 2010 11:17:15 +0100 (CET) Received: (from kettenis@localhost) by glazunov.sibelius.xs4all.nl (8.14.3/8.14.3/Submit) id o1IAHDdS030942; Thu, 18 Feb 2010 11:17:14 +0100 (CET) Date: Thu, 18 Feb 2010 10:18:00 -0000 Message-Id: <201002181017.o1IAHDdS030942@glazunov.sibelius.xs4all.nl> From: Mark Kettenis To: dan@codesourcery.com CC: gdb@sourceware.org In-reply-to: <20100218044416.GA19485@caradoc.them.org> (message from Daniel Jacobowitz on Wed, 17 Feb 2010 23:44:19 -0500) Subject: Re: CORE_ADDR representation References: <20100218044416.GA19485@caradoc.them.org> Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2010-02/txt/msg00121.txt.bz2 > Date: Wed, 17 Feb 2010 23:44:19 -0500 > From: Daniel Jacobowitz > > This comes up again and again, and has at least three times in the > past month with Jan's PIE patches. Is it time for us to have opaque > arithmetic on target addresses? I'm no terribly excited by having opaque arithmetic. I fear that it will make the code significantly harder to read :(. > My latest problem: > > struct section_addr_info * > build_section_addr_info_from_objfile (const struct objfile *objfile) > { > ... > CORE_ADDR mask = CORE_ADDR_MAX; > > if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT)) > mask = ((CORE_ADDR) 1 << addr_bit) - 1; > ... > sap->other[i].addr = (bfd_get_section_vma (objfile->obfd, sec) > + objfile->section_offsets->offsets[i]) & mask; > > This truncates the high bits. MIPS sign-extends pointers, even > internally in CORE_ADDR, and this results in separate debug info files > for MIPS executables being relocated off to la-la land. I had to add > this awful thing: > > if (bfd_get_sign_extend_vma (objfile->obfd) > && addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT) > && (sap->other[i].addr & ((CORE_ADDR) 1 << (addr_bit - 1))) != 0) > sap->other[i].addr |= ~mask; > > Which I'm not really proposing for inclusion, well, unless no one has > a better idea; sepdebug.exp on mips-elf currently fails without this. Perhaps we should introduce a function to "normalize" addresses (mask off high-bits or sign extend) that we call in places that need it? It'd be a no-op for a N-bit debugger debugging an N-bit target, so you'd be able to call it unconditionally. That should clear away quite a bit of clutter. > For instance, should we always internally sign-extend CORE_ADDR? > Always internally zero-extend? Having it vary by target has been a > recurring problem. The problem is that BFD may still give you sign-extended addresses. So you'd have to normalize them before sticking them into a CORE_ADDR.