public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: eddiekuo@andestech.com
Cc: gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: Undefined reference to `__dynamic_cast' when compiling with `-fsantize=vptr -static'
Date: Tue, 1 Sep 2020 08:09:36 +0100	[thread overview]
Message-ID: <CAH6eHdR10eSLAbXcNHgwEQ_Wxc9Tcn+4RmrQK6j6F76LW7bkaQ@mail.gmail.com> (raw)
In-Reply-To: <E7F8EF44EEEB2548962311D5B2E882F30114598A@ATCPCS16.andestech.com>

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/

      reply	other threads:[~2020-09-01  7:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-01  6:45 eddiekuo
2020-09-01  7:09 ` Jonathan Wakely [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAH6eHdR10eSLAbXcNHgwEQ_Wxc9Tcn+4RmrQK6j6F76LW7bkaQ@mail.gmail.com \
    --to=jwakely.gcc@gmail.com \
    --cc=eddiekuo@andestech.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).