Undefined reference to `__dynamic_cast' when compiling with `-fsantize=vptr -static'

Jonathan Wakely jwakely.gcc@gmail.com
Tue Sep 1 07:09:36 GMT 2020


On Tue, 1 Sep 2020 at 07:47, <eddiekuo@andestech.com> wrote:
>
> I compiled the following cpp file with `-fsantize=vptr -static'.
>
> struct A {
>   virtual ~A() {};
> };
>
> int main() { A a; }
>
> There would have the following output error:
> /usr/lib/gcc/x86_64-linux-gnu/7/libubsan.a(ubsan_type_hash_itanium.o): In function `isDerivedFromAtOffset(__cxxabiv1::__class_type_info const*, __cxxabiv1::__class_type_info const*, long)':
> (.text+0x52): undefined reference to `__dynamic_cast'
> (.text+0x5e): undefined reference to `typeinfo for __cxxabiv1::__vmi_class_type_info'
> (.text+0x6b): undefined reference to `__dynamic_cast'
> /usr/lib/gcc/x86_64-linux-gnu/7/libubsan.a(ubsan_type_hash_itanium.o): In function `findBaseAtOffset(__cxxabiv1::__class_type_info const*, long)':
> (.text+0x151): undefined reference to `__dynamic_cast'
> (.text+0x15d): undefined reference to `typeinfo for __cxxabiv1::__vmi_class_type_info'
> (.text+0x16a): undefined reference to `__dynamic_cast'
> /usr/lib/gcc/x86_64-linux-gnu/7/libubsan.a(ubsan_type_hash_itanium.o): In function `__ubsan::checkDynamicType(void*, void*, unsigned long)':
> (.text+0x293): undefined reference to `__dynamic_cast'
>
> There has a same result with gcc11.0.0.
> Is it a correct behavior for C++?

No. The problem is that libubsan requires symbols from libstdc++.so
(or libsupc++.a) but comes after it in the link line:

-lstdc++ -lm -lubsan -ldl -lrt -lpthread -lm --start-group -lgcc
-lgcc_eh -lc --end-group

Please report a bug, https://gcc.gnu./org/bugs/


More information about the Gcc-help mailing list