From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10580 invoked by alias); 15 Jul 2002 23:46:03 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 10538 invoked by uid 71); 15 Jul 2002 23:46:01 -0000 Resent-Date: 15 Jul 2002 23:46:01 -0000 Resent-Message-ID: <20020715234601.10534.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-To: nobody@gcc.gnu.org Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, snyder@fnal.gov Received: (qmail 9695 invoked from network); 15 Jul 2002 23:38:36 -0000 Received: from unknown (HELO karma.fnal.gov) (131.225.227.85) by sources.redhat.com with SMTP; 15 Jul 2002 23:38:36 -0000 Received: (from sss@localhost) by karma.fnal.gov (8.11.6/8.11.6) id g6FNZ5k28193; Mon, 15 Jul 2002 18:35:05 -0500 Message-Id: <200207152335.g6FNZ5k28193@karma.fnal.gov> Date: Mon, 15 Jul 2002 16:46:00 -0000 From: snyder@fnal.gov Reply-To: snyder@fnal.gov To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: 3.113 Subject: c++/7320: g++ 3.2 relocation problem X-SW-Source: 2002-07/txt/msg00472.txt.bz2 List-Id: >Number: 7320 >Category: c++ >Synopsis: g++ 3.2 relocation problem >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: wrong-code >Submitter-Id: net >Arrival-Date: Mon Jul 15 16:46:00 PDT 2002 >Closed-Date: >Last-Modified: >Originator: scott snyder >Release: 3.2 20020715 (experimental) >Organization: >Environment: System: Linux karma 2.4.9-13 #1 Tue Oct 30 20:11:04 EST 2001 i686 unknown Architecture: i686 host: i686-pc-linux-gnu build: i686-pc-linux-gnu target: i686-pc-linux-gnu configured with: ../egcs/configure --prefix=/usr/local/egcs --enable-threads=posix --enable-long-long --enable-languages=c,c++,f77 : (reconfigured) : (reconfigured) : (reconfigured) : (reconfigured) : (reconfigured) : (reconfigured) : (reconfigured) : (reconfigured) : (reconfigured) >Description: In recent versions of gcc, i've been having difficulties building shared libraries. Sometimes, when i try to use a type from the library in a dynamic_cast, i get a link warning about an unresolved relocation, and the dynamic_cast fails at run time --- it looks like in the call to the dynamic_cast, the argument that is supposed to be the typeinfo for the destination gets pointed at the beginning of the shared library from which it comes. To be complete, i should mention that the as and ld versions i'm using are as follows: GNU assembler 2.12.90.0.14 20020627 GNU ld version 2.12.90.0.14 20020627 I have seen the same problem with different binutils versions, though. An example (consisting of three source files) is below. Here's how i build it: $ g++ -fPIC -c y4.cc $ g++ -fPIC -shared -o yy.so y4.o $ g++ -g -fPIC y3.cc -o y3 yy.so /usr/local/egcs/bin/ld: /tmp/ccqQJ3Fn.o(.text+0x41): unresolvable relocation against symbol `typeinfo for xtype' /usr/local/egcs/bin/ld: /tmp/ccqQJ3Fn.o(.text+0x4b): unresolvable relocation against symbol `typeinfo for xatomic' $ Note the relocation errors for the typeinfo objects. It then crashes if i try to run it: $ ./y3 Segmentation fault $ Older versions of gcc (from about a month ago) do not show this behavior. By a binary search, i found the change which introduced this problem: 2002-06-30 Nathan Sidwell * cp-tree.h (CPTI_TINFO_DECL_TYPE): Replace with ... (CPTI_TYPE_INFO_PTR_TYPE): ... this. (tinfo_decl_type): Replace with ... (type_info_ptr_type): ... this. (import_export_tinfo): Declare. (tinfo_decl_p): Rename to ... (unemitted_tinfo_decl_p): ... this. * decl2.c (import_export_decl): Break out tinfo handling into ... (import_export_tinfo): ... here. New function. (finish_file): Adjust. * rtti.c (TINFO_REAL_NAME): New macro. (init_rtti_processing): Create the tinfo types. (get_tinfo_decl_dynamic): Use type_info_ptr_type, get_tinfo_ptr. (get_tinfo_decl): Adjust. (get_tinfo_ptr): New function. (get_type_id): Use it. (tinfo_base_init): Create vtable decl here, if it doesn't exist. (ptr_initializer): Use get_tinfo_ptr. (ptm_initializer): Likewise. (synthesize_tinfo_var): Break into ... (get_pseudo_ti_init): ... this. Just create the initializer. (get_pseudo_ti_desc): .. and this. (create_real_tinfo_var): Remove. (create_pseudo_type_info): Don't create the vtable decl here. (get_vmi_pseudo_type_info): Remove. (create_tinfo_types): Adjust. (tinfo_decl_p): Rename to ... (unemitted_tinfo_decl_p): ... here. Adjust. (emit_tinfo_decl): Adjust. Create the initializer. I found that if i make this change, the problem goes away. This is probably not the correct fix, though. Index: rtti.c =================================================================== RCS file: /cvs/gcc/egcs/gcc/cp/rtti.c,v retrieving revision 1.138 diff -u -p -r1.138 rtti.c --- rtti.c 5 Jul 2002 10:40:47 -0000 1.138 +++ rtti.c 15 Jul 2002 23:31:47 -0000 @@ -342,6 +342,7 @@ get_tinfo_decl (type) TREE_STATIC (d) = 1; DECL_EXTERNAL (d) = 1; SET_DECL_ASSEMBLER_NAME (d, name); + DECL_COMDAT (d) = 1; cp_finish_decl (d, NULL_TREE, NULL_TREE, 0); pushdecl_top_level (d); >How-To-Repeat: - y3.cc -------------------------------------------------------- #include "y.hh" extern "C" int printf (...); int main () { xtype* p = get_atomic_type (); xatomic* pp = dynamic_cast (p); printf ("%x\n", pp); return 0; } - y4.cc -------------------------------------------------------- #include "y.hh" xatomic* get_atomic_type () { return new xatomic (); } xatomic::~xatomic () {} xtype::~xtype () {} - y.hh --------------------------------------------------------- #ifndef Y_HH #define Y_HH struct xtype { virtual ~xtype (); }; struct xatomic : public xtype { ~xatomic (); }; xatomic* get_atomic_type (); #endif ---------------------------------------------------------------- >Fix: >Release-Note: >Audit-Trail: >Unformatted: