https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80963
Bug ID: 80963 Summary: UBSAN false positive with visibility=hidden Product: gcc Version: 7.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: sanitizer Assignee: unassigned at gcc dot gnu.org Reporter: jengelh at inai dot de CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org, jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at gcc dot gnu.org Target Milestone: --- $ cat lib.h struct Archive { virtual void foo() = 0; }; __attribute__((visibility("default"))) Archive *factory(); $ cat libimpl.cpp #include "lib.h" struct ArchiveImpl : Archive { void foo(); }; void ArchiveImpl::foo() {} Archive *factory() { return new ArchiveImpl; } $ cat main.cpp #include "lib.h" int main(void) { factory()->foo(); } $ make g++ -fPIC -o libimpl.so -shared libimpl.cpp -fvisibility=hidden -Wall -fsanitize=undefined -lubsan g++ -o main main.cpp ./libimpl.so -fvisibility=hidden -Wall -fsanitize=undefined -lubsan $ ./main main.cpp:3:16: runtime error: member call on address 0x000000dcfc20 which does not point to an object of type 'Archive' 0x000000dcfc20: note: object is of type 'ArchiveImpl' 00 00 00 00 88 ed 59 dc 84 7f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 21 00 00 00 ^~~~~~~~~~~~~~~~~~~~~~~ vptr for 'ArchiveImpl' The symbol table of main or libimpl.so do not appear to change when removing/adding -fvisiblity=hidden (no added/removed symbols, just address changes), so I wonder what exactly it is that UBSAN is trying to look up and not finding. $ g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-suse-linux/7/lto-wrapper OFFLOAD_TARGET_NAMES=hsa:nvptx-none Target: x86_64-suse-linux Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,ada,go --enable-offload-targets=hsa,nvptx-none=/usr/nvptx-none, --without-cuda-driver --enable-checking=release --disable-werror --with-gxx-include-dir=/usr/include/c++/7 --enable-ssp --disable-libssp --disable-libvtv --disable-libcc1 --enable-plugin --with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --enable-version-specific-runtime-libs --with-gcc-major-version-only --enable-linker-build-id --enable-linux-futex --enable-gnu-indirect-function --program-suffix=-7 --without-system-libunwind --enable-multilib --with-arch-32=x86-64 --with-tune=generic --build=x86_64-suse-linux --host=x86_64-suse-linux Thread model: posix gcc version 7.1.1 20170530 [gcc-7-branch revision 248621] (SUSE Linux)