forked from Evervolv/android_device_htc_bravo
/
002_bionic-Revert-Revert-Reenable-support-for-non-PIE-executables.patch
122 lines (111 loc) · 4.76 KB
/
002_bionic-Revert-Revert-Reenable-support-for-non-PIE-executables.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
From a4e9f0fac3db156650ca128995e5c052dac77145 Mon Sep 17 00:00:00 2001
From: Michael Bestas <mikeioannina@gmail.com>
Date: Mon, 24 Nov 2014 22:12:22 +0200
Subject: [PATCH] Revert "Revert "Reenable support for non-PIE executables""
* Conditionally revert under TARGET_NEEDS_NON_PIE_SUPPORT flag
This reverts commit 76e289c026f11126fc88841b3019fd5bb419bb67.
[mikeioannina]: Fix 5.1 compatibility
6.0 compatibility fixes by Stefan Berger <s.berger81@gmail.com>
Change-Id: I438b1f9f3dff2503a2dd51acbf2351d57f9e0f0b
---
linker/Android.mk | 4 ++++
linker/linker.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 52 insertions(+), 1 deletion(-)
diff --git a/linker/Android.mk b/linker/Android.mk
index f53276d..5f35b7d 100644
--- a/linker/Android.mk
+++ b/linker/Android.mk
@@ -56,6 +56,10 @@ endif
# We need to access Bionic private headers in the linker.
LOCAL_CFLAGS += -I$(LOCAL_PATH)/../libc/
+ifeq ($(TARGET_NEEDS_NON_PIE_SUPPORT),true)
+ LOCAL_CFLAGS += -DENABLE_NON_PIE_SUPPORT
+endif
+
# we don't want crtbegin.o (because we have begin.o), so unset it
# just for this module
LOCAL_NO_CRT := true
diff --git a/linker/linker.cpp b/linker/linker.cpp
index c81f5d3..8e71648 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -1931,10 +1931,10 @@ bool soinfo::relocate(const VersionTracker& version_tracker, ElfRelIteratorT&& r
const ElfW(Sym)* s = nullptr;
soinfo* lsi = nullptr;
+ const version_info* vi = nullptr;
if (sym != 0) {
sym_name = get_string(symtab_[sym].st_name);
- const version_info* vi = nullptr;
if (!lookup_version_info(version_tracker, sym, sym_name, &vi)) {
return false;
@@ -2240,6 +2240,7 @@ bool soinfo::relocate(const VersionTracker& version_tracker, ElfRelIteratorT&& r
*reinterpret_cast<ElfW(Addr)*>(reloc) += sym_addr - rel->r_offset;
break;
case R_ARM_COPY:
+#ifndef ENABLE_NON_PIE_SUPPORT
/*
* ET_EXEC is not supported so this should not happen.
*
@@ -2251,6 +2252,50 @@ bool soinfo::relocate(const VersionTracker& version_tracker, ElfRelIteratorT&& r
*/
DL_ERR("%s R_ARM_COPY relocations are not supported", get_realpath());
return false;
+#else
+ if ((flags_ & FLAG_EXE) == 0) {
+ /*
+ * http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044d/IHI0044D_aaelf.pdf
+ *
+ * Section 4.6.1.10 "Dynamic relocations"
+ * R_ARM_COPY may only appear in executable objects where e_type is
+ * set to ET_EXEC.
+ *
+ * TODO: FLAG_EXE is set for both ET_DYN and ET_EXEC executables.
+ * We should explicitly disallow ET_DYN executables from having
+ * R_ARM_COPY relocations.
+ */
+ DL_ERR("%s R_ARM_COPY relocations only supported for ET_EXEC", get_realpath());
+ return false;
+ }
+ count_relocation(kRelocCopy);
+ MARK(rel->r_offset);
+ TRACE_TYPE(RELO, "RELO %08x <- %d @ %08x %s", reloc, s->st_size, sym_addr, sym_name);
+ if (reloc == sym_addr) {
+ const ElfW(Sym)* src = nullptr;
+
+ if (!soinfo_do_lookup(NULL, sym_name, vi, &lsi, global_group, local_group, &src)) {
+ DL_ERR("%s R_ARM_COPY relocation source cannot be resolved", get_realpath());
+ return false;
+ }
+ if (lsi->has_DT_SYMBOLIC) {
+ DL_ERR("%s invalid R_ARM_COPY relocation against DT_SYMBOLIC shared "
+ "library %s (built with -Bsymbolic?)", get_realpath(), lsi->soname_);
+ return false;
+ }
+ if (s->st_size < src->st_size) {
+ DL_ERR("%s R_ARM_COPY relocation size mismatch (%d < %d)",
+ get_realpath(), s->st_size, src->st_size);
+ return false;
+ }
+ memcpy(reinterpret_cast<void*>(reloc),
+ reinterpret_cast<void*>(src->st_value + lsi->load_bias), src->st_size);
+ } else {
+ DL_ERR("%s R_ARM_COPY relocation target cannot be resolved", get_realpath());
+ return false;
+ }
+ break;
+#endif
#elif defined(__i386__)
case R_386_32:
count_relocation(kRelocRelative);
@@ -3283,11 +3328,13 @@ static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args, ElfW(
}
si->dynamic = nullptr;
+#ifndef ENABLE_NON_PIE_SUPPORT
ElfW(Ehdr)* elf_hdr = reinterpret_cast<ElfW(Ehdr)*>(si->base);
if (elf_hdr->e_type != ET_DYN) {
__libc_format_fd(2, "error: only position independent executables (PIE) are supported.\n");
exit(EXIT_FAILURE);
}
+#endif
// Use LD_LIBRARY_PATH and LD_PRELOAD (but only if we aren't setuid/setgid).
parse_LD_LIBRARY_PATH(ldpath_env);