http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55958
Bug #: 55958
Summary: vtable hidden when compiling with
-fvisibility-ms-compat
Classification: Unclassified
Product: gcc
Version: 4.7.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: [email protected]
ReportedBy: [email protected]
Created attachment 29153
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29153
so1.h, so1.cxx, main.cxx, Makefile + compiler --save-temp files. Build with
'make main'
% gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.7/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.7.2-2ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs
--enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.7 --enable-shared --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object
--enable-plugin --enable-objc-gc --enable-targets=all --disable-werror
--with-arch-32=i686 --with-tune=generic --enable-checking=release
--build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 4.7.2 (Ubuntu/Linaro 4.7.2-2ubuntu1)
The vtable for a class with a virtual member function is HIDDEN when source
file is compiled with -fvisibility-ms-compat. If a shared library is created
from the object file, then clients of the shared library cannot construct
objects of the class without getting an undefined symbol for the vtable.
% cat so1.h
#ifdef SO1_SOURCE
# define EXPORT __attribute ((visibility("default")))
#else
# define EXPORT
#endif
class SO1
{
public:
EXPORT virtual void foo();
};
% cat so1.cxx
#define SO1_SOURCE
#include "so1.h"
void SO1::foo() {}
% g++ -c so1.cxx -fvisibility-ms-compat
% eu-readelf -s so1.o | c++filt|grep SO1
14: 00000000 5 FUNC GLOBAL DEFAULT 4 SO1::foo()
15: 00000000 12 OBJECT WEAK HIDDEN 7 vtable for SO1
16: 00000000 8 OBJECT WEAK DEFAULT 9 typeinfo for SO1
18: 00000000 5 OBJECT WEAK DEFAULT 11 typeinfo name for SO1
% g++ -shared -o libso1.so so1.o
% cat main.cxx
#include "so1.h"
int main()
{
SO1 so1;
return 0;
}
% g++ main.cxx -L. -lso1
/tmp/ccLfT7tK.o: In function `SO1::SO1()':
main.cxx:(.text._ZN3SO1C2Ev[_ZN3SO1C5Ev]+0x8): undefined reference to `vtable
for SO1'
collect2: error: ld returned 1 exit status