Pass -lunwind when compiler-rt is used as the runtime library on regular
Linux (non-Android) and an unwinder is needed. This fixes building
C++ programs with '-rtlib=compiler-rt -stdlib=libc++' out-of-the-box,
and linking to compiler-rt when using '-static'. In both cases clang
did not pass any unwinder library so far.
This aims to match the current '-rtlib=libgcc' behavior which includes
the gcc unwinder library (libgcc_s or libgcc_eh) unconditionally.
However, -lunwind is added for C++ only if libc++ is used as
the standard C++ library since libstdc++ implicitly includes
the unwinder. Furthermore, -lunwind is only used for C++ and static
compiler-rt executables to avoid adding unnecessary dependencies for
regular C executables that could make bootstrap harder.
This was originally requested in D25008 by @EricWF in order to remove
the necessity of including -lunwind in the linker script. Most notably,
this allows us to reduce the risk of including two unwinder libraries in
a single linking action (libgcc_s via -rtlib, and libunwind via
the linker script).
The change is limited to Linux platform to avoid accidentally breaking
other platforms. Furthermore, some of them include -lunwind
unconditionally already.