https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89322

            Bug ID: 89322
           Summary: Use of new and -lsupc++ requires -lstdc++ on
                    architectures without atomics
           Product: gcc
           Version: 7.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jifl-bugzilla at jifvik dot org
  Target Milestone: ---

Long-standing behaviour is that if you don't want to link against the behemoth
of full libstdc++, but are still using simple C++ like new and delete, you can
link against libsupc++.

ARM9 and ARM9e (ARM arch v5) at least don't have atomic intrinsics, and
therefore the libstdc++ atomicity support relies on gthread_mutexes. When using
new, the unwinder is always pulled in to the final image (even with nothrow),
and the unwinder has a dependency in
libsupc++/eh_throw.cc:__gxx_exception_cleanup() on an atomic decrement which in
turn causes a dependency on __gnu_cxx::__exchange_and_add() as can be seen
here:

/[...]/bin/../lib/gcc/arm-eabi/7.3.0/../../../../arm-eabi/lib/arm9/nointerwork/libsupc++.a(eh_throw.o):
In function `__gxx_exception_cleanup(_Unwind_Reason_Code,
_Unwind_Control_Block*)':
(.text._ZL23__gxx_exception_cleanup19_Unwind_Reason_CodeP21_Unwind_Control_Block+0x24):
undefined reference to `__gnu_cxx::__exchange_and_add(int volatile*, int)'
collect2: error: ld returned 1 exit status

(This is a toolchain for which an arm9 multilib combo is present).

__exchange_and_add does exist in libstdc++, courtesy of
libstdc++-v3/src/c++98/atomicity.cc. To fix the above error, you need to link
with full -lstdc++, but you shouldn't need to. I guess atomicity related
functions should live in libsupc++, not libstdc++. This doesn't affect more
recent ARM architectures as they have atomic intrinics so there is no
dependency on __gnu_cxx::__exchange_and_add() when wanting to do the atomic
decrement. But it would affect any architecture (ARM or other) which doesn't
have atomic intrinsics.

Personally I can deal with the workaround, but this probably still wants to be
fixed. Some people may not want or have full libstdc++.

Reply via email to