From patchwork Thu Apr 10 11:49:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kratochvil X-Patchwork-Id: 470 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx22.g.dreamhost.com (mx2.sub5.homie.mail.dreamhost.com [208.113.200.128]) by wilcox.dreamhost.com (Postfix) with ESMTP id C4C4036005B for ; Thu, 10 Apr 2014 04:49:10 -0700 (PDT) Received: by homiemail-mx22.g.dreamhost.com (Postfix, from userid 14314964) id 66BE451F500B; Thu, 10 Apr 2014 04:49:10 -0700 (PDT) X-Original-To: gdb@patchwork.siddhesh.in Delivered-To: x14314964@homiemail-mx22.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx22.g.dreamhost.com (Postfix) with ESMTPS id 3C41A51F5007 for ; Thu, 10 Apr 2014 04:49:10 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:mime-version :content-type; q=dns; s=default; b=ZDRn+rrqHvkwSotY94AD4IQEFbvbm nPfPaTmOINX0IHUlCDBbdE0o20sio4pq7KNd/s7DvqLpcz5rYg+AFrYfzXlthH5B KrQj2bGq0IBMHXNs28hRYOw7quS0iyVNlpCEkGs5+bsKFtfEEN5AJ+UfSzc798A2 eSPhiALE37ltcQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:mime-version :content-type; s=default; bh=PS55hC82zFPU2BhzElf7CCTTg40=; b=CKh kpmq15S1IBo2JD5jKKhuyhVPVhyvJQfYl2SIfxnBtHiEq4aPk8EaEF9fWGn32PoG aCp1vTg9QEsJ6pcWxMoak3SLl2VStaIsliCd6Xk5oN+3MbX2+9bEw3Ys8kVhdlFT ZAMrojXewm7L3ZotgjukVZfSofVNmb4oqjszMlmc= Received: (qmail 23797 invoked by alias); 10 Apr 2014 11:49:08 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 23775 invoked by uid 89); 10 Apr 2014 11:49:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.3 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 10 Apr 2014 11:49:06 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s3ABn530011407 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 10 Apr 2014 07:49:05 -0400 Received: from host2.jankratochvil.net (ovpn-116-23.ams2.redhat.com [10.36.116.23]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s3ABn1vc025136 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO) for ; Thu, 10 Apr 2014 07:49:04 -0400 Date: Thu, 10 Apr 2014 13:49:01 +0200 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: [patch] Fix gdbserver qGetTLSAddr for x86_64 -m32 Message-ID: <20140410114901.GA16411@host2.jankratochvil.net> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes X-DH-Original-To: gdb@patchwork.siddhesh.in Hi, gdbserver makes libthread_db to access uninitialized memory. Surprisingly it does not harm normally, even -fsanitize=address works with current gdbserver. I have found just valgrind detects it as a very first warning for gdbserver: Syscall param ptrace(addr) contains uninitialised byte(s) at 0x3721EECEBE: ptrace (ptrace.c:45) by 0x436EE5: ps_get_thread_area (linux-x86-low.c:252) by 0x5559D02: __td_ta_lookup_th_unique (td_ta_map_lwp2thr.c:157) by 0x5559EC3: td_ta_map_lwp2thr (td_ta_map_lwp2thr.c:207) by 0x43F87D: find_one_thread (thread-db.c:281) by 0x440038: thread_db_get_tls_address (thread-db.c:505) by 0x40F6D0: handle_query (server.c:2004) by 0x4124CF: process_serial_event (server.c:3445) by 0x4136B6: handle_serial_event (server.c:3889) by 0x419571: handle_file_event (event-loop.c:434) by 0x418D38: process_event (event-loop.c:189) by 0x419AB7: start_event_loop (event-loop.c:552) Reproducible with: cd gdb/testsuite g++ -o gdb.threads/tls gdb.threads/tls{,2}.c -m32 -pthread ../gdbserver/gdbserver :1234 gdb.threads/tls ../gdb -batch gdb.threads/tls -ex 'target remote :1234' -ex 'b spin' -ex c -ex 'p a_thread_local' It is more easily reproducible even without valgrind using s/0x00/0xff/ in the attached patch. It will then turn the output of reproducer above: $1 = 0 -> Cannot find thread-local storage for Thread 29044, executable file .../gdb/testsuite/gdb.threads/tls: Remote target failed to process qGetTLSAddr request Thanks, Jan gdb/gdbserver/ 2014-04-10 Jan Kratochvil Fix gdbserver qGetTLSAddr for x86_64 -m32. * linux-x86-low.c (X86_64_USER_REGS): New. (x86_fill_gregset): Call memset for BUF first in x86_64 -m32 case. diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c index 33b5f26..1156e58 100644 --- a/gdb/gdbserver/linux-x86-low.c +++ b/gdb/gdbserver/linux-x86-low.c @@ -185,6 +185,7 @@ static const int x86_64_regmap[] = }; #define X86_64_NUM_REGS (sizeof (x86_64_regmap) / sizeof (x86_64_regmap[0])) +#define X86_64_USER_REGS (GS + 1) #else /* ! __x86_64__ */ @@ -343,6 +344,10 @@ x86_fill_gregset (struct regcache *regcache, void *buf) collect_register (regcache, i, ((char *) buf) + x86_64_regmap[i]); return; } + + /* 32-bit inferior registers need to be zero-extended. + Callers would read uninitialized memory otherwise. */ + memset (buf, 0x00, X86_64_USER_REGS * 8); #endif for (i = 0; i < I386_NUM_REGS; i++)