From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17235 invoked by alias); 2 Apr 2006 05:27:22 -0000 Received: (qmail 17226 invoked by uid 48); 2 Apr 2006 05:27:20 -0000 Date: Sun, 02 Apr 2006 05:27:00 -0000 Subject: [Bug c++/26984] New: link error with &(typeid(int)) in anonymous namespace X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "rjpeters at klab dot caltech dot edu" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2006-04/txt/msg00052.txt.bz2 List-Id: Using g++ from 4.2.0 daily snapshot 20060401: $ ~/local/gcc-4.2-20060401/bin/g++ -v Using built-in specs. Target: i686-pc-linux-gnu Configured with: /lab/rjpeters/build/gcc-4.2-20060401/configure --enable-languages=c,c++ --prefix=/lab/rjpeters/local/gcc-4.2-20060401 --enable-shared --enable-threads=posix --with-system-zlib --enable-__cxa_atexit Thread model: posix gcc version 4.2.0 20060401 (experimental) I get a linker error when I try to compile and link the following into a shared library. The link error only happens when I use -fpic, and it happens only when I take the address of typeid(int) inside an anonymous namespace; no linker error if I take the address in the global namespace or in a named namespace. $ cat test.C #include void g(const std::type_info&); namespace { // <--- change to 'namespace X' and the error disappears const std::type_info* t = &(typeid(int)); } template struct C { virtual void foo() const { g(typeid(int)); } }; C c; $ ~/local/gcc-4.2-20060401/bin/g++ -c test.C -fpic -o test.o $ ~/local/gcc-4.2-20060401/bin/g++ -shared test.o -o test.so /usr/bin/ld: test.o(.gnu.linkonce.t._ZNK1CIvE3fooEv+0x14): unresolvable relocation against symbol `typeinfo for int@@CXXABI_1.3' /usr/bin/ld: final link failed: Nonrepresentable section on output collect2: ld returned 1 exit status Not entirely sure which part of the toolchain this relates to, but I don't see the error with g++ 3.4.4 or 4.1.0 so I'm guessing there's a chance it's compiler-related. If I compile test.C->test.o both with 3.4.4 and 4.2.0 (20060401), then diff the outputs of 'nm test.o | c++filt', I get this: $ diff nm-3.4.4 nm-4.2 3c3 < 0000003a t global constructors keyed to _ZN35_GLOBAL__N_test.C_DFF67DD7_A20029871tE --- > 0000003c t global constructors keyed to _ZN35_GLOBAL__N_test.C_00000000_CD2145311tE 14a15,16 > 00000000 T __i686.get_pc_thunk.bx > 00000000 T __i686.get_pc_thunk.cx Thanks, Rob -- Summary: link error with &(typeid(int)) in anonymous namespace Product: gcc Version: 4.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: rjpeters at klab dot caltech dot edu GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26984