[committed] libstdc++: Move atomic functions to libsupc++ [PR 96657]

Jonathan Wakely jwakely@redhat.com
Thu Apr 15 16:10:53 GMT 2021


The changes for PR libstdc++/64735 mean that libsupc++ function might
now depend on the __exchange_and_add and __atomic_add functions defined
in config/cpu/*/atomicity.h which is not compiled into libsupc++. This
causes a link failure for some targets when trying to use libsupc++
without the rest of libstdc++.

This patch simply moves the definitions of those functions into
libsupc++ so that they are available there.

libstdc++-v3/ChangeLog:

	PR libstdc++/96657
	* libsupc++/Makefile.am: Add atomicity.cc here.
	* src/c++98/Makefile.am: Remove it from here.
	* libsupc++/Makefile.in: Regenerate.
	* src/c++98/Makefile.in: Regenerate.
	* testsuite/18_support/exception_ptr/96657.cc: New test.

Tested powerpc64le-linux and sparc64-linux (-m32/-m64).

Committed to trunk.

-------------- next part --------------
commit 6c0c7fc6236470a533675cd3cd1ebb1cc3dd112c
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Apr 14 20:48:54 2021

    libstdc++: Move atomic functions to libsupc++ [PR 96657]
    
    The changes for PR libstdc++/64735 mean that libsupc++ function might
    now depend on the __exchange_and_add and __atomic_add functions defined
    in config/cpu/*/atomicity.h which is not compiled into libsupc++. This
    causes a link failure for some targets when trying to use libsupc++
    without the rest of libstdc++.
    
    This patch simply moves the definitions of those functions into
    libsupc++ so that they are available there.
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/96657
            * libsupc++/Makefile.am: Add atomicity.cc here.
            * src/c++98/Makefile.am: Remove it from here.
            * libsupc++/Makefile.in: Regenerate.
            * src/c++98/Makefile.in: Regenerate.
            * testsuite/18_support/exception_ptr/96657.cc: New test.

diff --git a/libstdc++-v3/libsupc++/Makefile.am b/libstdc++-v3/libsupc++/Makefile.am
index 3563a3b421d..10ac4bb0124 100644
--- a/libstdc++-v3/libsupc++/Makefile.am
+++ b/libstdc++-v3/libsupc++/Makefile.am
@@ -48,6 +48,7 @@ sources = \
 	array_type_info.cc \
 	atexit_arm.cc \
 	atexit_thread.cc \
+	atomicity.cc \
 	bad_alloc.cc \
 	bad_array_length.cc \
 	bad_array_new.cc \
@@ -127,6 +128,9 @@ cp-demangle.lo: cp-demangle.c
 cp-demangle.o: cp-demangle.c
 	$(C_COMPILE) -DIN_GLIBCPP_V3 -Wno-error -c $<
 
+atomicity_file = ${glibcxx_srcdir}/$(ATOMICITY_SRCDIR)/atomicity.h
+atomicity.cc: ${atomicity_file}
+	$(LN_S) ${atomicity_file} ./atomicity.cc || true
 
 # AM_CXXFLAGS needs to be in each subdirectory so that it can be
 # modified in a per-library or per-sub-library way.  Need to manually
diff --git a/libstdc++-v3/src/c++98/Makefile.am b/libstdc++-v3/src/c++98/Makefile.am
index 2a9fc1b5f5d..0fa6ab95fb4 100644
--- a/libstdc++-v3/src/c++98/Makefile.am
+++ b/libstdc++-v3/src/c++98/Makefile.am
@@ -39,7 +39,6 @@ endif
 # particular host.
 host_sources = \
 	$(cow_string_host_sources) \
-	atomicity.cc \
 	codecvt_members.cc \
 	collate_members.cc \
 	messages_members.cc \
@@ -65,10 +64,6 @@ numeric_members.cc: ${glibcxx_srcdir}/$(CNUMERIC_CC)
 time_members.cc: ${glibcxx_srcdir}/$(CTIME_CC)
 	$(LN_S) ${glibcxx_srcdir}/$(CTIME_CC) . || true
 
-atomicity_file = ${glibcxx_srcdir}/$(ATOMICITY_SRCDIR)/atomicity.h
-atomicity.cc: ${atomicity_file}
-	$(LN_S) ${atomicity_file} ./atomicity.cc || true
-
 if ENABLE_DUAL_ABI
 collate_members_cow.cc: ${glibcxx_srcdir}/$(CCOLLATE_CC)
 	$(LN_S) ${glibcxx_srcdir}/$(CCOLLATE_CC) ./$@ || true
diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/96657.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/96657.cc
new file mode 100644
index 00000000000..61572668385
--- /dev/null
+++ b/libstdc++-v3/testsuite/18_support/exception_ptr/96657.cc
@@ -0,0 +1,17 @@
+// { dg-options "-nodefaultlibs -lsupc++ -lgcc_s -lc" { target sparc*-*-linux-gnu } }
+// { dg-do link { target c++11 } }
+
+#include <exception>
+
+void
+test01()
+{
+  // PR libstdc++/96657 undefined references in libsupc++
+  std::make_exception_ptr(1);
+}
+
+int
+main()
+{
+  test01();
+}


More information about the Libstdc++ mailing list