c++: Make references to __cxa_pure_virtual weak.
If a program has no other dependencies on libstdc++, we shouldn't require it just for __cxa_pure_virtual, which is only there to give a prettier diagnostic before crashing the program; resolving the reference to NULL will also crash, just without the diagnostic. gcc/cp/ChangeLog 2020-05-11 Jason Merrill <jason@redhat.com> * decl.c (cxx_init_decl_processing): Call declare_weak for __cxa_pure_virtual.
This commit is contained in:
parent
e5ccab839a
commit
aa2c978400
@ -1,3 +1,8 @@
|
||||
2020-05-11 Jason Merrill <jason@redhat.com>
|
||||
|
||||
* decl.c (cxx_init_decl_processing): Call declare_weak for
|
||||
__cxa_pure_virtual.
|
||||
|
||||
2020-05-11 Jason Merrill <jason@redhat.com>
|
||||
|
||||
* pt.c (instantiate_class_template_1): Call tsubst_expr for
|
||||
|
@ -4544,6 +4544,9 @@ cxx_init_decl_processing (void)
|
||||
abort_fndecl
|
||||
= build_library_fn_ptr ("__cxa_pure_virtual", void_ftype,
|
||||
ECF_NORETURN | ECF_NOTHROW | ECF_COLD);
|
||||
if (flag_weak)
|
||||
/* If no definition is available, resolve references to NULL. */
|
||||
declare_weak (abort_fndecl);
|
||||
|
||||
/* Perform other language dependent initializations. */
|
||||
init_class_processing ();
|
||||
|
21
gcc/testsuite/g++.dg/abi/pure-virtual1.C
Normal file
21
gcc/testsuite/g++.dg/abi/pure-virtual1.C
Normal file
@ -0,0 +1,21 @@
|
||||
// Test that we don't need libsupc++ just for __cxa_pure_virtual.
|
||||
// { dg-do link }
|
||||
// { dg-require-weak }
|
||||
// { dg-additional-options "-fno-rtti -nodefaultlibs -lc" }
|
||||
|
||||
struct A
|
||||
{
|
||||
int i;
|
||||
virtual void f() = 0;
|
||||
A(): i(0) {}
|
||||
};
|
||||
|
||||
struct B: A
|
||||
{
|
||||
virtual void f() {}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
B b;
|
||||
}
|
Loading…
Reference in New Issue
Block a user