From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3393 invoked by alias); 25 Aug 2006 02:24:10 -0000 Received: (qmail 3294 invoked by uid 22791); 25 Aug 2006 02:24:04 -0000 X-Spam-Check-By: sourceware.org Received: from ip-85-160-209-229.eurotel.cz (HELO host0.dyn.jankratochvil.net) (85.160.209.229) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 25 Aug 2006 02:23:59 +0000 Received: from host0.dyn.jankratochvil.net (localhost [127.0.0.1]) by host0.dyn.jankratochvil.net (8.13.7/8.13.7) with ESMTP id k7P2Nuhs001264 for ; Fri, 25 Aug 2006 04:23:58 +0200 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.13.7/8.13.7/Submit) id k7P2DBga032452 for gdb-patches@sourceware.org; Fri, 25 Aug 2006 04:13:11 +0200 Date: Fri, 25 Aug 2006 13:43:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: RFC: Ignore TLS symbols for non-TLS programs Message-ID: <20060825021311.GB30225@host0.dyn.jankratochvil.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="ABTtc+pdwF7KHXCz" Content-Disposition: inline User-Agent: Mutt/1.4.2.1i X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2006-08/txt/msg00189.txt.bz2 --ABTtc+pdwF7KHXCz Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 978 Hi, https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=185337 currently for trivia nonthreaded helloworld with no debug info up to -ggdb2 you will get: (gdb) p errno Cannot access memory at address 0x8 * with -ggdb3 "errno" gets resolved as _macro_ and the resulting "(*__errno_location ())" expression is always fine. * with -ggdb2 and less "errno" in fact does not exist anywhere as it was compiled to "(*__errno_location ())" and the macro definition is not present. Unfortunately gdb will find the TLS symbol and it will try to access it but as the program has been compiled without -lpthread the TLS base register (%gs on i386) is not setup and it will result in: Cannot access memory at address 0x8 IMO the right way is to ignore TLS symbols for inferiors without activated threading. Patch attached. Also attached suggestion patch how to deal with the most common "errno" symbol for the most common under-ggdb3 compiled programs. Regards, Jan --ABTtc+pdwF7KHXCz Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="gdb-6.5-bz185337-tls-ignore-symbols-without-startup.patch" Content-length: 4378 Index: gdb/minsyms.c =================================================================== RCS file: /cvs/src/src/gdb/minsyms.c,v retrieving revision 1.46 diff -u -p -r1.46 minsyms.c --- gdb/minsyms.c 19 Jul 2006 02:17:23 -0000 1.46 +++ gdb/minsyms.c 25 Aug 2006 01:42:27 -0000 @@ -50,6 +50,7 @@ #include "demangle.h" #include "value.h" #include "cp-abi.h" +#include "target.h" /* Accumulate the minimal symbols for each objfile in bunches of BUNCH_SIZE. At the end, copy them all into one newly allocated location on an objfile's @@ -202,10 +203,18 @@ lookup_minimal_symbol (const char *name, you want to test the linkage names with strcmp, do that. If you want to test the natural names with strcmp_iw, use SYMBOL_MATCHES_NATURAL_NAME. */ - if (strcmp (DEPRECATED_SYMBOL_NAME (msymbol), (name)) == 0 + if ((strcmp (DEPRECATED_SYMBOL_NAME (msymbol), (name)) == 0 || (SYMBOL_DEMANGLED_NAME (msymbol) != NULL && strcmp_iw (SYMBOL_DEMANGLED_NAME (msymbol), (name)) == 0)) + /* Ignore TLS based symbols if inferior does not run in + threaded mode. + https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=185337 + Otherwise we would resolve glibc TLS `errno' even for + nonthreaded programs without any TLS base set. */ + && ((SYMBOL_BFD_SECTION (msymbol)->flags + & SEC_THREAD_LOCAL) == 0 + || target_get_thread_local_address_p())) { switch (MSYMBOL_TYPE (msymbol)) { Index: gdb/testsuite/gdb.threads/tls-nopthread.c =================================================================== RCS file: gdb/testsuite/gdb.threads/tls-nopthread.c diff -N gdb/testsuite/gdb.threads/tls-nopthread.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gdb/testsuite/gdb.threads/tls-nopthread.c 25 Aug 2006 01:42:52 -0000 @@ -0,0 +1,10 @@ +/* Test accessing TLS based variable without -lpthread / TLS setup. */ + +#include + +__thread int thread_local = 42; + +int main(void) +{ + return 0; +} Index: gdb/testsuite/gdb.threads/tls-nopthread.exp =================================================================== RCS file: gdb/testsuite/gdb.threads/tls-nopthread.exp diff -N gdb/testsuite/gdb.threads/tls-nopthread.exp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gdb/testsuite/gdb.threads/tls-nopthread.exp 25 Aug 2006 01:42:52 -0000 @@ -0,0 +1,56 @@ +# tls.exp -- Expect script to test thread-local storage without TLS setup +# Copyright (C) 2006 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +# Please email any bugs, comments, and/or additions to this file to: +# bug-gdb@prep.ai.mit.edu + +set testfile tls-nopthread +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} + +if [istarget "*-*-linux"] then { + set target_cflags "-D_MIT_POSIX_THREADS" +} else { + set target_cflags "" +} + +if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable []] != "" } { + return -1 +} + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir + +gdb_load ${binfile} +if ![runto_main] then { + fail "Can't run to main" + return 0 +} + +# formerly no debug: Cannot access memory at address 0x0 +# formerly with debug: Cannot find thread-local variables on this target +# patched no debug: Address of symbol "thread_local" is unknown. +# OR No symbol table is loaded. Use the "file" command. +# patched with debug: Cannot find thread-local variables on this target +gdb_test "p thread_local" {.*Address of symbol "thread_local" is unknown..*|.*No symbol table is loaded. Use the "file" command..*} "thread local storage" + +# Done! +# +gdb_exit + +return 0 --ABTtc+pdwF7KHXCz Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="gdb-6.5-bz185337-missing-errno-suggestion.patch" Content-length: 923 Index: gdb/c-exp.y =================================================================== RCS file: /cvs/src/src/gdb/c-exp.y,v retrieving revision 1.35 diff -u -p -r1.35 c-exp.y --- gdb/c-exp.y 2 Aug 2006 03:13:20 -0000 1.35 +++ gdb/c-exp.y 25 Aug 2006 01:42:21 -0000 @@ -719,8 +719,13 @@ variable: name_not_typename else if (!have_full_symbols () && !have_partial_symbols ()) error ("No symbol table is loaded. Use the \"file\" command."); else - error ("No symbol \"%s\" in current context.", - copy_name ($1.stoken)); + { + /* https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=185337 */ + if (strcmp (arg, "errno") == 0) + warning ("You should use symbol \"(*__errno_location ())\" or" + " compile the program with `gcc -ggdb3' or `gcc -pthread'."); + error ("No symbol \"%s\" in current context.", arg); + } } } ; --ABTtc+pdwF7KHXCz--