From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) by sourceware.org (Postfix) with ESMTPS id 2156B3865C2D for ; Tue, 1 Sep 2020 07:09:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2156B3865C2D Received: by mail-il1-x12a.google.com with SMTP id t4so324162iln.1 for ; Tue, 01 Sep 2020 00:09:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=HqSUeGqn5+tAG/jTLRi/ILZ5fSvKVq1PKDnvHWpvGsU=; b=JzDxFQHzEk41yHT4FzdBe5ZUCKc4Xf26hX1LdU+/SHxnFYWfgNrnDOFp1UsOLkENyt K/p0riWkMzcMC27RwuWgSmHCch4pUsiZKGUEb3y0cnJ6umGCr12pNtnYxYtz61HRozP3 Y7O/YKkB6zxJogWC86KuBZvrLpmhg45ceIb/njaVwa81z7E2G6FLmRePhrzW/9aLhonb Xb6IjuPG2SwL1+dF50MKyEWG6OJW6B1we70fE9eUJaRuJ05CehD8Gb5GOe9bUqmB2Jmn OsGweZcK7z1IEfegM0H5YvMTEfowEDERs3SsNXXlZtdOuTJWA4zoENv9rznMtJyrAlps dwNA== X-Gm-Message-State: AOAM530kBDKV31/saCMb8CM724vXNmtFjNlTKJVB1ve0Og+nmqnB2TUP gEelpAB+77GKujNPu9xu1KBnVK87lxn/CAbqw2QF2m0gbTSQXA== X-Google-Smtp-Source: ABdhPJy/LhIJrp8DhOnH269juqXO+zAG7jdjxlidEOJHqyBkZydRF/82PTi8guYNr7xiRt0hFhRUvmov5YhrRVZadxo= X-Received: by 2002:a92:aa47:: with SMTP id j68mr214187ili.134.1598944187557; Tue, 01 Sep 2020 00:09:47 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Tue, 1 Sep 2020 08:09:36 +0100 Message-ID: Subject: Re: Undefined reference to `__dynamic_cast' when compiling with `-fsantize=vptr -static' To: eddiekuo@andestech.com Cc: gcc-help Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Sep 2020 07:09:49 -0000 On Tue, 1 Sep 2020 at 07:47, 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/