Bug 96657 - [9 Regression] libsupc++.a missing required functions from src/c++98/atomicity.cc when atomic builtins are not supported
Summary: [9 Regression] libsupc++.a missing required functions from src/c++98/atomicit...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 9.3.1
: P2 normal
Target Milestone: 9.5
Assignee: Jonathan Wakely
URL:
Keywords: link-failure
Depends on:
Blocks: 89322
  Show dependency treegraph
 
Reported: 2020-08-17 12:35 UTC by James Hilliard
Modified: 2021-07-22 21:29 UTC (History)
2 users (show)

See Also:
Host:
Target: sparc, arc
Build:
Known to work: 6.5.0
Known to fail: 10.3.0, 8.4.0, 9.3.0
Last reconfirmed: 2020-08-17 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description James Hilliard 2020-08-17 12:35:08 UTC
We've been hitting a bug in buildroot with an application(apcupsd) that links against libsupc++.a directly.

This issue appears to be due to a sparc/arc specific missing symbols bug in libsupc++, we aren't seeing this build error for any other architectures at the moment.

See discussions:
http://lists.busybox.net/pipermail/buildroot/2020-May/282779.html
http://lists.busybox.net/pipermail/buildroot/2020-August/289413.html

Build error http://autobuild.buildroot.org/results/3be/3bedf404de0ea42ee3ba624cded65d310a847af9//build-end.log:

/tmp/instance-0/output-1/host/opt/ext-toolchain/bin/../lib/gcc/sparc-buildroot-linux-uclibc/8.3.0/../../../../sparc-buildroot-linux-uclibc/bin/ld: /tmp/instance-0/output-1/host/opt/ext-toolchain/bin/../lib/gcc/sparc-buildroot-linux-uclibc/8.3.0/../../../../sparc-buildroot-linux-uclibc/lib/libsupc++.a(eh_throw.o): in function `__gxx_exception_cleanup(_Unwind_Reason_Code, _Unwind_Exception*)':
eh_throw.cc:(.text._ZL23__gxx_exception_cleanup19_Unwind_Reason_CodeP17_Unwind_Exception+0x38): undefined reference to `__gnu_cxx::__exchange_and_add(int volatile*, int)'
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:33: apcupsd] Error 1

Based on previous discussions(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70560#c6) it appears this has been broken since r244051 enabled std::exception_ptr for targets without lock-free atomic built-ins.
Comment 1 Jonathan Wakely 2020-08-17 13:28:16 UTC
I think r244051 caused libsupc++.a to depend on libstdc++.so for targets that don't support lock-free atomics for int.
Comment 2 James Hilliard 2020-08-17 13:38:54 UTC
(In reply to Jonathan Wakely from comment #1)
> I think r244051 caused libsupc++.a to depend on libstdc++.so for targets
> that don't support lock-free atomics for int.

Yeah, the current workaround we came up with was to force linking to libstdc++.so, but that's probably not a real fix for the root cause of the issue. I'm assuming the real fix would be to change libsupc++.a so that it includes the missing symbols?
Comment 3 Jonathan Wakely 2020-08-17 13:46:40 UTC
Yes, I think that's what we need to do.
Comment 4 Jonathan Wakely 2021-04-15 11:42:22 UTC
For completeness, here's a testcase which fails on sparc64-unknown-linux-gnu when compiled using gcc -m32 eh.C -lsupc++

#include <exception>

int main()
{
  std::make_exception_ptr(1);
}

/usr/bin/ld: /home/jwakely/gcc/11/lib/gcc/sparc64-unknown-linux-gnu/11.0.1/../../../../lib32/libsupc++.a(eh_ptr.o): in function `__gnu_cxx::__exchange_and_add_dispatch(int*, int)':
/home/jwakely/build/sparc64-unknown-linux-gnu/32/libstdc++-v3/include/ext/atomicity.h:101: undefined reference to `__gnu_cxx::__exchange_and_add(int volatile*, int)'
/usr/bin/ld: /home/jwakely/gcc/11/lib/gcc/sparc64-unknown-linux-gnu/11.0.1/../../../../lib32/libsupc++.a(eh_ptr.o): in function `__gnu_cxx::__atomic_add_dispatch(int*, int)':
/home/jwakely/build/sparc64-unknown-linux-gnu/32/libstdc++-v3/include/ext/atomicity.h:111: undefined reference to `__gnu_cxx::__atomic_add(int volatile*, int)'
/usr/bin/ld: /home/jwakely/gcc/11/lib/gcc/sparc64-unknown-linux-gnu/11.0.1/../../../../lib32/libsupc++.a(eh_ptr.o): in function `__gnu_cxx::__exchange_and_add_dispatch(int*, int)':
/home/jwakely/build/sparc64-unknown-linux-gnu/32/libstdc++-v3/include/ext/atomicity.h:101: undefined reference to `__gnu_cxx::__exchange_and_add(int volatile*, int)'
/usr/bin/ld: /home/jwakely/gcc/11/lib/gcc/sparc64-unknown-linux-gnu/11.0.1/../../../../lib32/libsupc++.a(eh_ptr.o): in function `__gnu_cxx::__atomic_add_dispatch(int*, int)':
/home/jwakely/build/sparc64-unknown-linux-gnu/32/libstdc++-v3/include/ext/atomicity.h:111: undefined reference to `__gnu_cxx::__atomic_add(int volatile*, int)'
/usr/bin/ld: /home/jwakely/gcc/11/lib/gcc/sparc64-unknown-linux-gnu/11.0.1/../../../../lib32/libsupc++.a(eh_throw.o): in function `__gnu_cxx::__exchange_and_add_dispatch(int*, int)':
/home/jwakely/build/sparc64-unknown-linux-gnu/32/libstdc++-v3/include/ext/atomicity.h:101: undefined reference to `__gnu_cxx::__exchange_and_add(int volatile*, int)'
collect2: error: ld returned 1 exit status
Comment 5 CVS Commits 2021-04-15 16:10:22 UTC
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:6c0c7fc6236470a533675cd3cd1ebb1cc3dd112c

commit r11-8198-g6c0c7fc6236470a533675cd3cd1ebb1cc3dd112c
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Apr 14 20:48:54 2021 +0100

    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.
Comment 6 Jonathan Wakely 2021-04-15 16:15:42 UTC
Fixed on trunk. Backports to follow.
Comment 7 Richard Biener 2021-06-01 08:18:22 UTC
GCC 9.4 is being released, retargeting bugs to GCC 9.5.
Comment 8 CVS Commits 2021-07-22 17:05:14 UTC
The releases/gcc-10 branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

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

commit r10-9997-gf2074277aa3ce0848429e34d6149ba26ff3b708e
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Apr 14 20:48:54 2021 +0100

    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.
    
    (cherry picked from commit 6c0c7fc6236470a533675cd3cd1ebb1cc3dd112c)
Comment 9 Jonathan Wakely 2021-07-22 17:06:10 UTC
Also fixed for 10.4 now
Comment 10 CVS Commits 2021-07-22 21:29:08 UTC
The releases/gcc-9 branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

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

commit r9-9640-gba5e10a8c84f56bb2838adb6d1cc9b74741ac4f1
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Apr 14 20:48:54 2021 +0100

    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.
    
    (cherry picked from commit 6c0c7fc6236470a533675cd3cd1ebb1cc3dd112c)
Comment 11 Jonathan Wakely 2021-07-22 21:29:31 UTC
And also fixed for 9.5

The GCC 8.x branch is closed, so it can't be fixed there.