public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/autopar_devel] c++: Make references to __cxa_pure_virtual weak.
@ 2020-08-22 21:06 Giuliano Belinassi
  0 siblings, 0 replies; only message in thread
From: Giuliano Belinassi @ 2020-08-22 21:06 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:fc4257339da0950c13c9e6308aa7a089571bff48

commit fc4257339da0950c13c9e6308aa7a089571bff48
Author: Jason Merrill <jason@redhat.com>
Date:   Mon May 11 14:05:46 2020 -0400

    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.

Diff:
---
 gcc/cp/ChangeLog                         |  5 +++++
 gcc/cp/decl.c                            |  3 +++
 gcc/testsuite/g++.dg/abi/pure-virtual1.C | 21 +++++++++++++++++++++
 3 files changed, 29 insertions(+)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 1fdc3880fff..2cc9b8deb15 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index dea1ba07c0e..1b6a5672334 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -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 ();
diff --git a/gcc/testsuite/g++.dg/abi/pure-virtual1.C b/gcc/testsuite/g++.dg/abi/pure-virtual1.C
new file mode 100644
index 00000000000..823328ea951
--- /dev/null
+++ b/gcc/testsuite/g++.dg/abi/pure-virtual1.C
@@ -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;
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-08-22 21:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-22 21:06 [gcc/devel/autopar_devel] c++: Make references to __cxa_pure_virtual weak Giuliano Belinassi

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).