From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30859 invoked by alias); 19 Aug 2008 17:02:48 -0000 Received: (qmail 30849 invoked by uid 22791); 19 Aug 2008 17:02:47 -0000 X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.33.17) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 19 Aug 2008 17:01:30 +0000 Received: from wpaz21.hot.corp.google.com (wpaz21.hot.corp.google.com [172.24.198.85]) by smtp-out.google.com with ESMTP id m7JH1At4029721; Tue, 19 Aug 2008 18:01:11 +0100 Received: from localhost.localdomain.google.com (dhcp-172-18-118-203.corp.google.com [172.18.118.203]) (authenticated bits=0) by wpaz21.hot.corp.google.com with ESMTP id m7JH18v3018589 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 19 Aug 2008 10:01:10 -0700 To: Arindam Cc: gcc-help@gcc.gnu.org Subject: Re: Restricting symbol binding within shared object References: From: Ian Lance Taylor Date: Tue, 19 Aug 2008 18:49:00 -0000 In-Reply-To: (Arindam's message of "Tue\, 19 Aug 2008 21\:07\:12 +0530") Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2008-08/txt/msg00179.txt.bz2 Arindam writes: > I have two shared libraries linked to an executable. The executable > calls two functions - say bar1() in one shared lib and bar2() in > another. It so happens that both bar1 and bar2 internally call a > function say foo(). There is a different version of foo defined in > each shared object with same signature but different internal > implementation. It so happens that when both shared libs are linked to > my executable, both bar1 and bar2's calls resolve to the foo defined > in shared object 1. I am trying to figure out a way to resolve each > call "locally" within the shared object. I tried the -Bsymbolic switch > for the linker but it did not work - perhaps because this is C++ code, > although the functions in question are declared with C linkage (extern > "C"). -Bsymbolic should have worked. Note that you have to use it when linking the shared libraries. With a newer version of gcc you can use visibility attributes. That is probably your best approach here. http://gcc.gnu.org/onlinedocs/gcc-4.3.0/gcc/Function-Attributes.html#Function-Attributes search for visibility ("visibility_type") Ian