From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11267 invoked by alias); 14 May 2012 17:05:09 -0000 Received: (qmail 11222 invoked by uid 22791); 14 May 2012 17:05:03 -0000 X-SWARE-Spam-Status: No, hits=-6.1 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_BJ,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 14 May 2012 17:04:39 +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 q4EH4QnL021291 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 14 May 2012 13:04:26 -0400 Received: from host2.jankratochvil.net (ovpn-116-17.ams2.redhat.com [10.36.116.17]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q4EH4MFd025351 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Mon, 14 May 2012 13:04:25 -0400 Date: Mon, 14 May 2012 17:05:00 -0000 From: Jan Kratochvil To: Joel Brobecker Cc: Tom Tromey , gdb-patches@sourceware.org Subject: Re: Regression for gdb.fortran/library-module.exp [Re: [RFA] choose symbol from given block's objfile first.] Message-ID: <20120514170422.GA13856@host2.jankratochvil.net> References: <1336430581-11262-1-git-send-email-brobecker@adacore.com> <874nrqvbeh.fsf@fleche.redhat.com> <20120509190529.GI15555@adacore.com> <20120511072606.GA25458@host2.jankratochvil.net> <20120514143927.GB10253@adacore.com> <20120514145151.GA30451@host2.jankratochvil.net> <20120514150552.GH10253@adacore.com> <20120514151447.GA31010@host2.jankratochvil.net> <20120514165637.GK10253@adacore.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20120514165637.GK10253@adacore.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 X-SW-Source: 2012-05/txt/msg00522.txt.bz2 On Mon, 14 May 2012 18:56:37 +0200, Joel Brobecker wrote: > So this is another example of copy-relocation? No, this was just overriding library's symbol by executable's symbol. $ main executable's has now just 'extern int x;' echo -e '#include \nint x=1;void f(void){printf("lib:%d\\n",x);}'|gcc -x c -fPIC -Wall -shared -o var.so -;echo -e '#include \nextern int x;extern void f(void);int main(void){printf("main:%d\\n",x);f();return 0;}'|gcc ./var.so -x c -Wall -o var -;./var main:1 lib:1 $ readelf -Wr var Offset Info Type Symbol's Value Symbol's Name + Addend 0000000000600a40 0000000700000005 R_X86_64_COPY 0000000000600a40 x + 0 This is copy-relocation because the variable must be in the main executable but at the same time it must be initialized from the library's value. > When you say this is perfectly defined, this looks horrifying to me. It > feels like you can break a shared library's code that way... If library does not want to get its data overriden it should use -fvisibility=hidden and properly mark any really exported variables by "__attribute__ ((visibility("default")))". See man gcc for -fvisibility. Exporting any variables from shared libraries should be rather avoided anyway as it is generally expensive, because compiler has to ensure &variable has the same address from any module. That -fvisibility=hidden is not default is just unfortunately backward compatibility. The default -fvisibility=default is needlessly expensive. glibc does these tricks with visibilities. Regards, Jan