From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20811 invoked by alias); 7 Jan 2013 10:31:39 -0000 Received: (qmail 20495 invoked by uid 48); 7 Jan 2013 10:31:20 -0000 From: "gauryogesh.nsit at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/55872] Crash issue with RTLD_DEEPBIND usage with stdc++ library Date: Mon, 07 Jan 2013 10:31:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: gauryogesh.nsit at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2013-01/txt/msg00464.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55872 --- Comment #4 from Yogesh Gaur 2013-01-07 10:31:19 UTC --- Hello, Actually issue is combination of copy_relocation plus RTLD_DEEPBIND flag. If I didn't give -fPIE flag while compiling my executable and pass RTLD_DEEPBIND flag while opening library using dlopen(), then result is un-expected. I checked similar issue exist on gcc also: ------------------------------Source Code ----------------------------- $ cat main.c #include extern int alpha; int main() { char const * const name = "./lib1.so"; void * handle = dlopen(name, RTLD_NOW | RTLD_LOCAL | RTLD_DEEPBIND); typedef void (*library_function_type)(); library_function_type func1 = dlsym(handle, "func1"); alpha = 10; (*func1)(); func2(); dlclose(handle); return 0; } $ cat lib1.c #include extern int alpha; void func1(){ printf("lib1: Addr=%p, value=%d\n", &alpha, alpha); } $ cat lib2.c #include int alpha; void func2(){ printf("lib2: Addr=%p, value=%d\n", &alpha, alpha); } -------------------------------- END ---------------------------------- Compilation command and output: gcc -shared -fPIC lib2.c -o lib2.so gcc -shared -fPIC lib1.c lib2.so -o lib1.so gcc -ldl main.c lib2.so -o a.out LD_LIBRARY_PATH=$PWD ./a.out lib1: Addr=0x7f5a39663028, value=0 lib2: Addr=0x601038, value=10 ========================================= Thus for same symbol, alpha, we get two addresses values. If I remove RTLD_DEEPBIND while opening library, I didn't get this issue: lib1: Addr=0x601038, value=10 lib2: Addr=0x601038, value=10 Reason for this also I know that in case of RTLD_DEEPBIND scope of search for lib1.so is its internal library first and then only global library's being searched. I want to know that apart from usage of -fPIE flag at compilation time did any-other solution exist for this issue? As using -fPIE has it's own side-affect. -- Regards, Yogesh Gaur.