From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6273 invoked by alias); 12 Oct 2005 14:13:22 -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 6052 invoked by uid 22791); 12 Oct 2005 14:13:18 -0000 Received: from cantor.suse.de (HELO mx1.suse.de) (195.135.220.2) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Wed, 12 Oct 2005 14:13:18 +0000 Received: from Relay1.suse.de (mail2.suse.de [195.135.221.8]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.suse.de (Postfix) with ESMTP id EFE94DE30 for ; Wed, 12 Oct 2005 16:13:15 +0200 (CEST) From: Andreas Schwab To: gdb-patches@sources.redhat.com Subject: Broken cast in linux-thread-db X-Yow: I put aside my copy of ``BOWLING WORLD'' and think about GUN CONTROL legislation.. Date: Wed, 12 Oct 2005 14:13:00 -0000 Message-ID: User-Agent: Gnus/5.110003 (No Gnus v0.3) Emacs/22.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-SW-Source: 2005-10/txt/msg00104.txt.bz2 Casting a pointer to CORE_ADDR results in implementation defined behaviour when the latter is wider than a pointer. The implementation's behaviour might be to sign extend which is not what we want here. Tested on i386-suse-linux with --enable-64-bit-bfd. Andreas. 2005-10-12 Andreas Schwab * linux-thread-db.c (enable_thread_event): Cast pointer to uintptr_t to avoid implementation defined behaviour. (thread_db_get_thread_local_address): Likewise. --- gdb/linux-thread-db.c.~1.10.~ 2005-09-12 11:04:57.000000000 +0200 +++ gdb/linux-thread-db.c 2005-10-12 15:16:06.000000000 +0200 @@ -505,9 +505,13 @@ enable_thread_event (td_thragent_t *thre return err; /* Set up the breakpoint. */ - (*bp) = gdbarch_convert_from_func_ptr_addr (current_gdbarch, - (CORE_ADDR) notify.u.bptaddr, - ¤t_target); + (*bp) = (gdbarch_convert_from_func_ptr_addr + (current_gdbarch, + /* Don't cast directly to CORE_ADDR, which may be wider than a + pointer and results in implementation defined + behaviour. */ + (uintptr_t) notify.u.bptaddr, + ¤t_target)); create_thread_event_breakpoint ((*bp)); return TD_OK; @@ -1277,7 +1281,10 @@ thread_db_get_thread_local_address (ptid (("%s")), thread_db_err_str (err)); /* Cast assuming host == target. Joy. */ - return (CORE_ADDR) address; + /* Don't cast directly to CORE_ADDR, which may be wider than a + pointer and results in implementation defined behaviour. GCC + would sign extend the value which is not what we want here. */ + return (uintptr_t) address; } if (target_beneath->to_get_thread_local_address) -- Andreas Schwab, SuSE Labs, schwab@suse.de SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."