aboutsummaryrefslogtreecommitdiff
path: root/linker/Android.bp
diff options
context:
space:
mode:
authorDan Willemsen <dwillemsen@google.com>2017-09-18 21:28:14 -0700
committerDan Willemsen <dwillemsen@google.com>2017-09-20 13:59:13 -0700
commit7ccc50d2e48b9d8027a1f382b0408e9c36e56731 (patch)
tree5c0f8742d17baa66596860f88bfe387020b2d864 /linker/Android.bp
parent4326d84d217b40b819729da153f97217ea4ec932 (diff)
downloadbionic-7ccc50d2e48b9d8027a1f382b0408e9c36e56731.tar.gz
Use an embedded linker for host bionic
The linux kernel requires that the ELF interpreter (runtime linker) that's referenced by PT_INTERP be either an absolute path, or a relative path from the current working directory. We'd prefer a relative path from the binary, similarly to how we handle looking up shared libraries, but that's not supported. Instead, extract the LOAD segments from the runtime linker ELF binary and embed them into each host bionic binary, omitting the PT_INTERP declaration. The kernel will treat it as a static binary, and we'll use a special entry point (linker_wrapper) to fix up the arguments passed by the kernel before jumping to the embedded linker. From the linker's point of view, it looks like the kernel loaded the linker like normal. Bug: 31559095 Test: Enable host bionic, build and run libdemangle_test Change-Id: I1753401ef91eecbf0ae3376faca31eec1c53842b
Diffstat (limited to 'linker/Android.bp')
-rw-r--r--linker/Android.bp42
1 files changed, 42 insertions, 0 deletions
diff --git a/linker/Android.bp b/linker/Android.bp
index 5775426a3..9125fd60e 100644
--- a/linker/Android.bp
+++ b/linker/Android.bp
@@ -13,6 +13,48 @@ cc_library_static {
static_libs: ["libasync_safe"],
}
+// This is used for bionic on (host) Linux to bootstrap our linker embedded into
+// a binary.
+//
+// Host bionic binaries do not have a PT_INTERP section, instead this gets
+// embedded as the entry point, and the linker is embedded as ELF sections in
+// each binary. There's a linker script that sets all of that up (generated by
+// extract_linker), and defines the extern symbols used in this file.
+cc_object {
+ name: "linker_wrapper",
+ host_supported: true,
+ device_supported: false,
+ target: {
+ linux_bionic: { enabled: true },
+ linux: { enabled: false },
+ darwin: { enabled: false },
+ },
+
+ cflags: [
+ "-fno-stack-protector",
+ "-Wstrict-overflow=5",
+ "-fvisibility=hidden",
+ "-Wall",
+ "-Wextra",
+ "-Wno-unused",
+ "-Werror",
+ ],
+
+ srcs: [
+ "linker_wrapper.cpp",
+ ],
+ arch: {
+ x86_64: {
+ srcs: ["arch/x86_64/begin.S"],
+ },
+ },
+
+ prefix_symbols: "__dlwrap_",
+
+ // We need to access Bionic private headers in the linker.
+ include_dirs: ["bionic/libc"],
+}
+
cc_binary {
defaults: ["linux_bionic_supported"],
srcs: [