public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: snyder@fnal.gov To: gcc-gnats@gcc.gnu.org Subject: c++/7320: g++ 3.2 relocation problem Date: Mon, 15 Jul 2002 16:46:00 -0000 [thread overview] Message-ID: <200207152335.g6FNZ5k28193@karma.fnal.gov> (raw) >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 <nathan@codesourcery.com> * 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<xatomic*> (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:
next reply other threads:[~2002-07-15 23:46 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-07-15 16:46 snyder [this message] 2002-07-16 1:44 nathan 2002-09-13 7:29 nathan
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=200207152335.g6FNZ5k28193@karma.fnal.gov \ --to=snyder@fnal.gov \ --cc=gcc-gnats@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).