[PATCH] Fix libstdc++ build on macOS

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] Fix libstdc++ build on macOS

Strager Neds
Bootstrap-building libstdc++ on macOS Sierra 10.12.6
(x86_64-apple-darwin16.7.0) fails with the following linker error:

    Undefined symbols for architecture x86_64:
      "__ZSt15__alloc_on_copyISaIcEEvRT_RKS1_", referenced from:
          __ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6assignERKS4_
in libstdc++.a(string-inst.o)
      "__ZSt15__alloc_on_moveISaIcEEvRT_S2_", referenced from:
          __ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEaSEOS4_
in libstdc++.a(string-inst.o)
      "__ZSt15__alloc_on_swapISaIcEEvRT_S2_", referenced from:
          __ZN9__gnu_cxx14__alloc_traitsISaIcEcE10_S_on_swapERS1_S3_
in libstdc++.a(string-inst.o)
    ld: symbol(s) not found for architecture x86_64
    collect2: error: ld returned 1 exit status

These errors are caused by -fno-implicit-templates.
std::__alloc_on_copy is not marked inline, so its use in
std::basic_string::assign does not cause code for the the template to
be generated.

Mark the function templates inline so -fno-implicit-templates does not
affect them. This fixes the linker errors on my machine (and possibly
        on other targets, too).

Testing: Bootstrap on macOS x86_64-apple-darwin16.7.0 with
--disable-multilib --enable-checking=release --enable-languages=c,c++.
I did not run 'make check'; I only verified that 'make' and 'make
install' succeeded, and that 'gcc --version' on the installed copy
succeeded.

2019-11-13  Matthew Glazar <[hidden email]>

* libstdc++-v3/include/bits/alloc_traits.h (__alloc_on_copy)
(__alloc_on_move, __alloc_on_swap): Mark inline.


diff --git a/libstdc++-v3/include/bits/alloc_traits.h
b/libstdc++-v3/include/bits/alloc_traits.h
index 55211ac1d72..6ad02df16f7 100644
--- a/libstdc++-v3/include/bits/alloc_traits.h
+++ b/libstdc++-v3/include/bits/alloc_traits.h
@@ -566,7 +566,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif

   template<typename _Alloc>
-    _GLIBCXX14_CONSTEXPR void
+    _GLIBCXX14_CONSTEXPR inline void
     __alloc_on_copy(_Alloc& __one, const _Alloc& __two)
     {
       typedef allocator_traits<_Alloc> __traits;
@@ -580,7 +580,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     }

   template<typename _Alloc>
-    constexpr _Alloc
+    constexpr inline _Alloc
     __alloc_on_copy(const _Alloc& __a)
     {
       typedef allocator_traits<_Alloc> __traits;
@@ -598,7 +598,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif

   template<typename _Alloc>
-    _GLIBCXX14_CONSTEXPR void
+    _GLIBCXX14_CONSTEXPR inline void
     __alloc_on_move(_Alloc& __one, _Alloc& __two)
     {
       typedef allocator_traits<_Alloc> __traits;
@@ -625,7 +625,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif

   template<typename _Alloc>
-    _GLIBCXX14_CONSTEXPR void
+    _GLIBCXX14_CONSTEXPR inline void
     __alloc_on_swap(_Alloc& __one, _Alloc& __two)
     {
       typedef allocator_traits<_Alloc> __traits;