[Android] Use -l:libunwind.a with --rtlib=compiler-rt
authorRyan Prichard <rprichard@google.com>
Wed, 10 Feb 2021 09:25:58 +0000 (01:25 -0800)
committerRyan Prichard <rprichard@google.com>
Thu, 25 Feb 2021 23:40:02 +0000 (15:40 -0800)
commit91f8aacc040f5a458cfc2a10c4039e0028931455
treef270d39762cd9b89509c7407fb2ec3effe0f1642
parentc88fedef2a5d3f4c69cc668984bb93c8889890c2
[Android] Use -l:libunwind.a with --rtlib=compiler-rt

On Android, the unwinder isn't part of the C++ STL and isn't (in older
versions) exported from libc.so. Instead, the driver links the static
unwinder archive implicitly. Currently, the Android NDK implicitly
links libgcc.a to provide both builtins and the unwinder.

To support switching to compiler-rt builtins and libunwind, make
--rtlib=compiler-rt behave the same way on Android, and implicitly pass
-l:libunwind.a to the linker.

Adjust the -ldl logic. For the Android NDK, the unwinder (whether
libgcc.a or libunwind.a) is linked statically and calls a function in
the dynamic loader for finding unwind tables (e.g. dl_iterate_phdr).
On Android, this function is in libc.a for static executables and
libdl.so otherwise, so -ldl is needed. (glibc doesn't need -ldl because
its libc.so exports dl_iterate_phdr.)

Differential Revision: https://reviews.llvm.org/D96403
clang/lib/Driver/ToolChain.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp