Cleanup linker unwinder integration
The linker shouldn't throw exceptions, but because it links with
libc++_static.a, there are code paths that could throw an exception. On
those code paths, the unwinder needs to lookup EH information for the
linker binary, and the linker had two inconsistent ways of doing this:
* dl_iterate_phdr (for libgcc): dlfcn.cpp defined a linker-internal
version of this API that forwarded to __loader_dl_iterate_phdr
* __gnu_Unwind_Find_exidx (for arm32 libgcc): linker_exidx_static.c was
an old, broken copy of exidx_static.c that used
__exidx_start/__exidx_end symbols. (The file should have used the
addresses of the symbols rather than their contents.)
The linker's data structures might be in an inconsistent state at a point
where exceptions are thrown, so it seems better to limit its unwinder to
just the linker binary's EH info. Rather than forward the dl* EH APIs,
link in the static-binary versions from libc_unwind_static.a. That library
is already part of libc_nomalloc.a, but include it directly with
whole_static_libs so that __gnu_Unwind_Find_exidx is defined when we're
using libgcc on arm32.
Try to link in libunwind_llvm.a into the arm32 linker binary so we're
using the same unwinder as normal arm32 binaries. I'm not sure the library
will appear in the right order, but maybe it doesn't matter given LLD's
unconventional archive linking semantics.
Test: bionic unit tests
Test: "readelf --dyn-syms linker" reports no UNDEF symbols
Test: "readelf -r linker" reports only relative relocations
Bug: none
Change-Id: I5982ec830ba0f15d066536de24f6cd7e9503498b
Merged-In: I5982ec830ba0f15d066536de24f6cd7e9503498b
diff --git a/linker/Android.bp b/linker/Android.bp
index 18f2527..bb9d26d 100644
--- a/linker/Android.bp
+++ b/linker/Android.bp
@@ -96,7 +96,6 @@
name: "linker_sources_arm",
srcs: [
"arch/arm/begin.S",
- "linker_exidx_static.c",
],
}
@@ -233,6 +232,7 @@
arm: {
srcs: [ ":linker_sources_arm" ],
version_script: ":linker_version_script_arm",
+ static_libs: ["libunwind_llvm"],
},
arm64: {
srcs: [":linker_sources_arm64"],
@@ -276,6 +276,17 @@
"liblinker_malloc",
],
+ // Ensure that if the linker needs __gnu_Unwind_Find_exidx, then the linker will have a
+ // definition of the symbol. The linker links against libgcc.a, whose arm32 unwinder has a weak
+ // reference to __gnu_Unwind_Find_exidx, which isn't sufficient to pull in the strong definition
+ // of __gnu_Unwind_Find_exidx from libc. An unresolved weak reference would create a
+ // non-relative dynamic relocation in the linker binary, which complicates linker startup.
+ //
+ // This line should be unnecessary because the linker's dependency on libunwind_llvm.a should
+ // override libgcc.a, but this line provides a simpler guarantee. It can be removed once the
+ // linker stops linking against libgcc.a's arm32 unwinder.
+ whole_static_libs: ["libc_unwind_static"],
+
name: "linker",
symlinks: ["linker_asan"],
recovery_available: true,