[cfe-dev] GCC and Clang produce undefined references to functions with vague linkage

Joe Buck Joe.Buck at synopsys.COM
Thu Jun 28 12:12:16 PDT 2012

On Thu, Jun 28, 2012 at 02:13:47PM -0400, Rafael EspĂ­ndola wrote:
[ problem with visibility for bar::~bar for testcase ]
> $ cat test.h
> struct foo {
>   virtual ~foo();
> };
> struct bar : public foo {
>   virtual void zed();
> };
> $ cat def.cpp
> #include "test.h"
> void bar::zed() {
> }
> $ cat undef.cpp
> #include "test.h"
> void f() {
>   foo *x(new bar);
>   delete x;
> }
> I can see two ways of solving this and would like for both clang and
> gcc to implement the same:
> [1] * Make sure the destructor is emitted everywhere. That is, clang and
> gcc have a bug in producing an undefined reference to _ZN3barD0Ev.
> [2] * Make it clear that the file exporting the vtable has to export the
> symbols used in it. That is, the Itanium c++ abi needs clarification
> and so does gcc's lto plugin (and the llvm patch I am working on).

I think that the second solution wins because it allows for the production
of less object code, and it is consistent with the rationale for the
vtable optimization rule (the vtable is emitted by the file that has the
definition for the first non-inline virtual function; simply do the same
for the auto-generated virtual destructor).  The first solution requires
making one copy per compilation unit and eliminating the duplicates at
link time.

More information about the cfe-dev mailing list