From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 126029 invoked by alias); 5 Feb 2019 20:06:49 -0000 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 Received: (qmail 126021 invoked by uid 89); 5 Feb 2019 20:06:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 05 Feb 2019 20:06:46 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id x15K6em2015893 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 5 Feb 2019 15:06:45 -0500 Received: by simark.ca (Postfix, from userid 112) id 55B711E882; Tue, 5 Feb 2019 15:06:40 -0500 (EST) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id E1C3F1E4B5; Tue, 5 Feb 2019 15:06:37 -0500 (EST) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=_f46a64788f127b17f02721710fe56dea" Date: Tue, 05 Feb 2019 20:06:00 -0000 From: Simon Marchi To: John Baldwin Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 3/9] Handle TLS variable lookups when using separate debug object files. In-Reply-To: References: <6f24b813adb0155b499d6e2265a6f15a2db4e6ca.1548180889.git.jhb@FreeBSD.org> <27bfe45d3ccba5f52d2e3632da417000@polymtl.ca> Message-ID: X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.6 X-IsSubscribed: yes X-SW-Source: 2019-02/txt/msg00028.txt.bz2 --=_f46a64788f127b17f02721710fe56dea Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed Content-length: 3797 On 2019-02-04 15:02, John Baldwin wrote: > On 2/2/19 7:52 AM, Simon Marchi wrote: >> On 2019-01-22 13:42, John Baldwin wrote: >>> The object files stored in the shared object list are the original >>> object files, not the separate debug object files. However, when >>> resolving a TLS variable, the variable is resolved against a separate >>> debug object file if it exists. In this case, >>> svr4_fetch_objfile_link_map was failing to find the link map entry >>> since the debug object file is not in its internal list, only the >>> original object file. >> >> Does this solve an existing issue, or an issue that would come up with >> the following patches? > > I only noticed while working on these patches, but I believe it is a > generic issue. I tried to reproduce on a Linux box by compiling a > small > library with separate debug symbols and a program that linked against > it > and running it under gdb, but TLS variables didn't work for me even > without > separate debug symbols in my testing. :( > > $ cat foo.c > #include "foo.h" > > static __thread int foo_id; > > void > set_foo_id(int id) > { > foo_id = id; > } > > int > get_foo_id(void) > { > return foo_id; > } > $ cat foo.h > void set_foo_id(int id); > int get_foo_id(void); > $ cat main.c > #include > > #include "foo.h" > > int > main(void) > { > > set_foo_id(47); > printf("foo id = %d\n", get_foo_id()); > return (0); > } > $ cc -g -fPIC -shared foo.c -o libfoo.so.full > $ objcopy --only-keep-debug libfoo.so.full libfoo.so.debug > $ objcopy --strip-debug --add-gnu-debuglink=libfoo.so.debug > libfoo.so.full libfoo.so > $ cc -g main.c -o foo -lfoo -L. > $ gdb foo > GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git > ... > (gdb) start > Temporary breakpoint 1 at 0x7ae: file main.c, line 9. > Starting program: /home/john/tls_lib/foo > > Temporary breakpoint 1, main () at main.c:9 > 9 set_foo_id(47); > (gdb) p foo_id > Cannot find thread-local storage for process 3970, shared library > libfoo.so: > Cannot find thread-local variables on this target > > Then tried it without separate debug file, but that didn't work either: > > $ cc -g -fPIC -shared foo.c -o libfoo.so > $ gdb foo > GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git > ... > (gdb) start > Temporary breakpoint 1 at 0x7ae: file main.c, line 9. > Starting program: /home/john/tls_lib/foo > > Temporary breakpoint 1, main () at main.c:9 > 9 set_foo_id(47); > (gdb) p foo_id > Cannot find thread-local storage for process 3982, shared library > libfoo.so: > Cannot find thread-local variables on this target > (gdb) n > 10 printf("foo id = %d\n", get_foo_id()); > (gdb) > foo id = 47 > 11 return (0); > (gdb) p foo_id > Cannot find thread-local storage for process 3982, shared library > libfoo.so: > Cannot find thread-local variables on this target > > I would have expected the second case to work and the first to fail and > for > the patch to fix the first case. I did a similar test and hit the same message. I figured it's because you need to build with -pthread. With -pthread, GDB manages to print the value in both cases (with and without separate debug info). That's why I ended up asking you this question, I thought that maybe I just hadn't reproduced the issue correctly. I have attached my test case (so we don't have to rewrite the same test over and over), which you can easily build with and without debug info (see the Makefile). Does it trigger the problem on FreeBSD? Does it work for you in both cases on Linux, like it does for me? Now that I take a look, there might be the gdb.threads/tls-shared.exp test that does the exact same thing. But there doesn't seem to be a board file to test with separate debug files out of the box... Simon --=_f46a64788f127b17f02721710fe56dea Content-Transfer-Encoding: base64 Content-Type: application/x-gzip; name=shared-lib-tls-test.tgz Content-Disposition: attachment; filename=shared-lib-tls-test.tgz; size=690 Content-length: 936 H4sIAGvoWVwAA+2W30/bMBDH81r/FSdgUivhzvnVSHTdxDaGKm2AYNNekKqQ OK1HiEviTkIT//ucuDQZLeMlKpp2n5fWd2c7vsv3nGIW5jymqbiiKi2o4oV6 bbUM0wS+bzF3wBzftpgd+NpU2ZdYtus5A3fg2b62254bOBb4bT/IJhaFCnMA i9+EohDZk3F8UfC82MYTbZViQ/2/hNc8ESlva4+ywAPPe6r+tnau6s+Yo/06 LrCAtfUAf+M/r/8uXHAFSoINicyh4PMwDxWHmF8tpiCyRJKLo7PD88OvR5OP R++/HU/GJ59O4d0IGCFhmh6AzlsG+v1JpOwXkpBybKx92bB3plEEVJrwpZd+ 7gNNdQDQ7+k+pfk8VLPR5d7e6fn4eHwCdK5mOQ9js2hfLpeNlotFyyHQqQv0 lDXiV/seQPlbb79yADWvvvHXU0XCb6G7191w6t6+3SMdefUjkvM7oFRm6R29 5nxOTbbqtVf/+pWnOalQuVib0AwI45hOs4UJSUV2PXq0WmMaz2KRkA6pzmCO WienGtW5Sc7GHxoZIlHKw+yAdPIb7XuoiEnGnyVdO81Lv7NIe2zq/0ZV7e3x TP9nDnOX/d8PmKe/E2zfGzjY/7fBrsiidBFzeFOoWMj+7C0hK9tOKfvZDiEi U1UL7v6UIu6RX4SAvirURPsnIu56QW+oLfNcxyXdchaIGEbwKr7MdvZhWkf2 qsCcq0WeQZfp0T22k5dkk/6ri6PFPZ7Xv1/r3/FK/bsOQ/1vg3Wt63woEcFk Yr4U9DegAqPeISGl/klD+aXTdARYBmnZl5H3pmk0pP/QOlbyf1gUO8AL8pT+ Zy3u8Zz+mR/U+ner+991PdT/NihVCeuCHpbqhcfqHaJSEQRBEARBEARBEARB EARB/hV+AxSWuPYAKAAA --=_f46a64788f127b17f02721710fe56dea--