[ 
https://issues.apache.org/jira/browse/STDCXX-262?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12530605
 ] 

Martin Sebor commented on STDCXX-262:
-------------------------------------

Here's an analysis of what's going on in stdcxx:

1, On Mac OS X, gcc 4.0.1 doesn't generate a vtable for class E in the test 
case below (which is as expected given that the class dtor isn't defined) but 
it does so for class D (which is not expected because this dtor also isn't 
defined), even though there is no "real" difference between the two classes 
other than the order in which the members are declared.

2. We declare members of std::exception, std::bad_exception, and std::bad_alloc 
in the same order as those in class D below, i.e., the dtor comes before the 
other virtual member function. Since we also define some virtual members of 
these classes (based on the results of config tests which determine that some 
members are not defined in libsupc++), the vtable for each is generated in the 
object file where the other members are defined. Since the vtable for all these 
classes also exists in libsupc++ (that's where the virtual dtor and what() are 
defined), we end up with two vtables for each class.

3. Given the above, we should be able to work around the problem by reversing 
the declaration order of the virtual dtor and the other virtual member (what()) 
so as to trick the compiler into not generating the vtable in our objects.

$ cat t.cpp && uname -srp && gcc -dumpversion && gcc -c t.cpp && nm t.o | 
c++filt | grep "S vtable"
struct B {
    virtual ~B ();
    virtual void foo ();
};

struct D: B {
    virtual void foo ();
    virtual ~D ();
};

struct E: B {
    virtual ~E ();
    virtual void foo ();
};

void D::foo () { }
void E::foo () { }

Darwin 8.7.1 i386
4.0.1
00000020 S vtable for D

> [gcc 4.0.1/Mac OS X 10.4.6 Tiger] multiple vtable definitions for 
> bad_exception and bad_alloc
> ---------------------------------------------------------------------------------------------
>
>                 Key: STDCXX-262
>                 URL: https://issues.apache.org/jira/browse/STDCXX-262
>             Project: C++ Standard Library
>          Issue Type: Bug
>          Components: Build
>    Affects Versions: 4.1.3
>         Environment: Darwin machine.local 8.7.1 Darwin Kernel Version 8.7.1: 
> Wed Jun  7 16:19:56 PDT 2006; root:xnu-792.9.72.obj~2/RELEASE_I386 i386 i386
>            Reporter: Eric Lemings
>            Assignee: Martin Sebor
>            Priority: Critical
>             Fix For: 4.2
>
>
> machine:~/Work user$ svn co 
> http://svn.apache.org/repos/asf/incubator/stdcxx/trunk stdcxx
> A    stdcxx/generate.bat
> A    stdcxx/LICENSE.txt
> A    stdcxx/tests
> A    stdcxx/tests/tr1.util
> ...
> A    stdcxx/examples/manual/time_put.cpp
> A    stdcxx/examples/manual/moneyget.cpp
> A    stdcxx/examples/manual/except.cpp
> A    stdcxx/examples/manual/memfunc.cpp
> Checked out revision 423638.
> machine:~/Work user$ cd stdcxx
> machine:~/Work/stdcxx user$ make BUILDDIR="~/Build" 
> BUILDMODE="debug,shared,pthreads"
> creating BUILDDIR=/Users/user/Build/stdcxx
> generating /Users/user/Build/stdcxx/makefile.in from 
> /Users/user/Work/stdcxx/etc/config/gcc.config
> make config
> configuring for gcc-4.0.1 on darwin-8.7.1-i386
> checking if the compiler is sane                   ok (invoked with gcc)
> checking if the linker is sane                     ok (invoked with gcc)
> checking system architecture                       ILP32 little endian
> ...
> gcc -c -I/Users/user/Work/stdcxx/include/ansi -D_RWSTDDEBUG    
> -D_RWSTD_USE_CONFIG -I/Users/user/Work/stdcxx/include 
> -I/Users/user/Build/stdcxx/include  -pedantic -nostdinc++ -g  -W -Wall 
> -Wcast-qual -Winline -Wshadow -Wwrite-strings -Wno-long-long -Wcast-align  
> -fPIC /Users/user/Work/stdcxx/src/wctype.cpp
> gcc      assert.o atomic-cxx.o bitset.o catalog.o codecvt.o collate.o ctype.o 
> ctype_bits.o exception.o export.o facet.o file.o instance.o ios.o ios_bits.o 
> iostore.o iostream.o iso2022.o limits.o limits_bits.o locale_bits.o 
> locale_body.o locale_classic.o locale_combine.o locale_core.o locale_eq.o 
> locale_global.o locale_name.o memattr.o memory.o messages.o num_get.o 
> num_put.o punct.o random.o setlocale.o string.o strstream.o strtol.o 
> ti_collate.o ti_filebuf.o ti_insert_dbl.o ti_insert_int.o ti_insert_ptr.o 
> ti_ios.o ti_istream.o ti_messages.o ti_money_get.o ti_money_put.o 
> ti_moneypunct.o ti_num_get.o ti_num_put.o ti_numpunct.o ti_ostream.o 
> ti_streambuf.o ti_string.o ti_stringbuf.o ti_time_get.o ti_time_put.o 
> ti_wcollate.o ti_wfilebuf.o ti_winsert_dbl.o ti_winsert_int.o 
> ti_winsert_ptr.o ti_wios.o ti_wistream.o ti_wmessages.o ti_wmoney_get.o 
> ti_wmoney_put.o ti_wmoneypunct.o ti_wnum_get.o ti_wnum_put.o ti_wnumpunct.o 
> ti_wostream.o ti_wstreambuf.o ti_wstring.o ti_wstringbuf.o ti_wtime_get.o 
> ti_wtime_put.o time_get.o time_put.o tmpbuf.o typeinfo.o valarray.o vecbool.o 
> version.o wcodecvt.o wctype.o -lsupc++ -lgcc_eh -o 
> /Users/user/Build/stdcxx/lib/libstd.dylib.4.2.0 
> /usr/bin/ld: multiple definitions of symbol vtable for std::bad_exception
> exception.o definition of vtable for std::bad_exceptionin section 
> (__DATA,__const)
> /usr/lib/gcc/i686-apple-darwin8/4.0.1/../../../libsupc++.a(eh_exception.o) 
> private external definition of vtable for std::bad_exceptionin section 
> (__DATA,__const)
> /usr/bin/ld: multiple definitions of symbol vtable for std::bad_alloc
> memory.o definition of vtable for std::bad_allocin section (__DATA,__const)
> /usr/lib/gcc/i686-apple-darwin8/4.0.1/../../../libsupc++.a(new_handler.o) 
> private external definition of vtable for std::bad_allocin section 
> (__DATA,__const)
> collect2: ld returned 1 exit status
> make[2]: *** [/Users/user/Build/stdcxx/lib/libstd.dylib] Error 1
> make[1]: *** [lib] Error 2
> make: *** [libstd] Error 2

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to