merge in mnc-release history after reset to mnc-dev
diff --git a/libc/arch-arm/arm.mk b/libc/arch-arm/arm.mk
index 6ef81bb..d72a160 100644
--- a/libc/arch-arm/arm.mk
+++ b/libc/arch-arm/arm.mk
@@ -39,7 +39,6 @@
arch-arm/bionic/__bionic_clone.S \
arch-arm/bionic/_exit_with_stack_teardown.S \
arch-arm/bionic/libgcc_compat.c \
- arch-arm/bionic/libgcc_protect_unwind.c \
arch-arm/bionic/__restore.S \
arch-arm/bionic/setjmp.S \
arch-arm/bionic/syscall.S \
diff --git a/libc/arch-arm/bionic/libgcc_protect_unwind.c b/libc/arch-arm/bionic/libgcc_protect_unwind.c
deleted file mode 100644
index 6d758fc..0000000
--- a/libc/arch-arm/bionic/libgcc_protect_unwind.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-// TODO: This file should go away once unwinder migration to libc++.so is complete.
-
-extern char _Unwind_Backtrace __attribute((visibility("protected")));
-extern char __gnu_Unwind_Find_exidx __attribute((visibility("protected")));
-extern char __gnu_Unwind_Restore_VFP_D __attribute((visibility("protected")));
-extern char __gnu_Unwind_Restore_VFP __attribute((visibility("protected")));
-extern char __gnu_Unwind_Restore_VFP_D_16_to_31 __attribute((visibility("protected")));
-extern char __gnu_Unwind_Restore_WMMXD __attribute((visibility("protected")));
-extern char __gnu_Unwind_Restore_WMMXC __attribute((visibility("protected")));
-extern char _Unwind_GetCFA __attribute((visibility("protected")));
-extern char __gnu_Unwind_RaiseException __attribute((visibility("protected")));
-extern char __gnu_Unwind_ForcedUnwind __attribute((visibility("protected")));
-extern char __gnu_Unwind_Resume __attribute((visibility("protected")));
-extern char __gnu_Unwind_Resume_or_Rethrow __attribute((visibility("protected")));
-extern char _Unwind_Complete __attribute((visibility("protected")));
-extern char _Unwind_DeleteException __attribute((visibility("protected")));
-extern char _Unwind_VRS_Get __attribute((visibility("protected")));
-extern char _Unwind_VRS_Set __attribute((visibility("protected")));
-extern char __gnu_Unwind_Backtrace __attribute((visibility("protected")));
-extern char _Unwind_VRS_Pop __attribute((visibility("protected")));
-extern char __gnu_Unwind_Save_VFP_D __attribute((visibility("protected")));
-extern char __gnu_Unwind_Save_VFP __attribute((visibility("protected")));
-extern char __gnu_Unwind_Save_VFP_D_16_to_31 __attribute((visibility("protected")));
-extern char __gnu_Unwind_Save_WMMXD __attribute((visibility("protected")));
-extern char __gnu_Unwind_Save_WMMXC __attribute((visibility("protected")));
-extern char ___Unwind_RaiseException __attribute((visibility("protected")));
-extern char _Unwind_RaiseException __attribute((visibility("protected")));
-extern char ___Unwind_Resume __attribute((visibility("protected")));
-extern char _Unwind_Resume __attribute((visibility("protected")));
-extern char ___Unwind_Resume_or_Rethrow __attribute((visibility("protected")));
-extern char _Unwind_Resume_or_Rethrow __attribute((visibility("protected")));
-extern char ___Unwind_ForcedUnwind __attribute((visibility("protected")));
-extern char _Unwind_ForcedUnwind __attribute((visibility("protected")));
-extern char ___Unwind_Backtrace __attribute((visibility("protected")));
-extern char _Unwind_GetRegionStart __attribute((visibility("protected")));
-extern char _Unwind_GetLanguageSpecificData __attribute((visibility("protected")));
-extern char _Unwind_GetDataRelBase __attribute((visibility("protected")));
-extern char _Unwind_GetTextRelBase __attribute((visibility("protected")));
-
-void* __bionic_libgcc_unwind_symbols[] = {
- &_Unwind_Backtrace,
- &__gnu_Unwind_Find_exidx,
- &__gnu_Unwind_Restore_VFP_D,
- &__gnu_Unwind_Restore_VFP,
- &__gnu_Unwind_Restore_VFP_D_16_to_31,
- &__gnu_Unwind_Restore_WMMXD,
- &__gnu_Unwind_Restore_WMMXC,
- &_Unwind_GetCFA,
- &__gnu_Unwind_RaiseException,
- &__gnu_Unwind_ForcedUnwind,
- &__gnu_Unwind_Resume,
- &__gnu_Unwind_Resume_or_Rethrow,
- &_Unwind_Complete,
- &_Unwind_DeleteException,
- &_Unwind_VRS_Get,
- &_Unwind_VRS_Set,
- &__gnu_Unwind_Backtrace,
- &_Unwind_VRS_Pop,
- &__gnu_Unwind_Save_VFP_D,
- &__gnu_Unwind_Save_VFP,
- &__gnu_Unwind_Save_VFP_D_16_to_31,
- &__gnu_Unwind_Save_WMMXD,
- &__gnu_Unwind_Save_WMMXC,
- &___Unwind_RaiseException,
- &_Unwind_RaiseException,
- &___Unwind_Resume,
- &_Unwind_Resume,
- &___Unwind_Resume_or_Rethrow,
- &_Unwind_Resume_or_Rethrow,
- &___Unwind_ForcedUnwind,
- &_Unwind_ForcedUnwind,
- &___Unwind_Backtrace,
- &_Unwind_GetRegionStart,
- &_Unwind_GetLanguageSpecificData,
- &_Unwind_GetDataRelBase,
- &_Unwind_GetTextRelBase,
-};
diff --git a/libc/bionic/debug_mapinfo.cpp b/libc/bionic/debug_mapinfo.cpp
index 698ab6b..de72cb2 100644
--- a/libc/bionic/debug_mapinfo.cpp
+++ b/libc/bionic/debug_mapinfo.cpp
@@ -27,6 +27,7 @@
*/
#include <ctype.h>
+#include <elf.h>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
@@ -35,14 +36,22 @@
#include "debug_mapinfo.h"
#include "malloc_debug_disable.h"
+#if defined(__LP64__)
+#define Elf_W(x) Elf64_##x
+#else
+#define Elf_W(x) Elf32_##x
+#endif
+
// Format of /proc/<PID>/maps:
// 6f000000-6f01e000 rwxp 00000000 00:0c 16389419 /system/lib/libcomposer.so
static mapinfo_t* parse_maps_line(char* line) {
uintptr_t start;
uintptr_t end;
+ uintptr_t offset;
+ char permissions[4];
int name_pos;
- if (sscanf(line, "%" PRIxPTR "-%" PRIxPTR " %*4s %*x %*x:%*x %*d%n", &start,
- &end, &name_pos) < 2) {
+ if (sscanf(line, "%" PRIxPTR "-%" PRIxPTR " %4s %" PRIxPTR " %*x:%*x %*d%n", &start,
+ &end, permissions, &offset, &name_pos) < 2) {
return NULL;
}
@@ -59,6 +68,14 @@
if (mi) {
mi->start = start;
mi->end = end;
+ mi->offset = offset;
+ if (permissions[0] != 'r') {
+ // Any unreadable map will just get a zero load base.
+ mi->load_base = 0;
+ mi->load_base_read = true;
+ } else {
+ mi->load_base_read = false;
+ }
memcpy(mi->name, name, name_len);
mi->name[name_len] = '\0';
}
@@ -95,11 +112,58 @@
}
}
+template<typename T>
+static inline bool get_val(mapinfo_t* mi, uintptr_t addr, T* store) {
+ if (addr < mi->start || addr + sizeof(T) > mi->end) {
+ return false;
+ }
+ // Make sure the address is aligned properly.
+ if (addr & (sizeof(T)-1)) {
+ return false;
+ }
+ *store = *reinterpret_cast<T*>(addr);
+ return true;
+}
+
+__LIBC_HIDDEN__ void mapinfo_read_loadbase(mapinfo_t* mi) {
+ mi->load_base = 0;
+ mi->load_base_read = true;
+ uintptr_t addr = mi->start;
+ Elf_W(Ehdr) ehdr;
+ if (!get_val<Elf_W(Half)>(mi, addr + offsetof(Elf_W(Ehdr), e_phnum), &ehdr.e_phnum)) {
+ return;
+ }
+ if (!get_val<Elf_W(Off)>(mi, addr + offsetof(Elf_W(Ehdr), e_phoff), &ehdr.e_phoff)) {
+ return;
+ }
+ addr += ehdr.e_phoff;
+ for (size_t i = 0; i < ehdr.e_phnum; i++) {
+ Elf_W(Phdr) phdr;
+ if (!get_val<Elf_W(Word)>(mi, addr + offsetof(Elf_W(Phdr), p_type), &phdr.p_type)) {
+ return;
+ }
+ if (!get_val<Elf_W(Off)>(mi, addr + offsetof(Elf_W(Phdr), p_offset), &phdr.p_offset)) {
+ return;
+ }
+ if (phdr.p_type == PT_LOAD && phdr.p_offset == mi->offset) {
+ if (!get_val<Elf_W(Addr)>(mi, addr + offsetof(Elf_W(Phdr), p_vaddr), &phdr.p_vaddr)) {
+ return;
+ }
+ mi->load_base = phdr.p_vaddr;
+ return;
+ }
+ addr += sizeof(phdr);
+ }
+}
+
// Find the containing map info for the PC.
__LIBC_HIDDEN__ const mapinfo_t* mapinfo_find(mapinfo_t* mi, uintptr_t pc, uintptr_t* rel_pc) {
for (; mi != NULL; mi = mi->next) {
if ((pc >= mi->start) && (pc < mi->end)) {
- *rel_pc = pc - mi->start;
+ if (!mi->load_base_read) {
+ mapinfo_read_loadbase(mi);
+ }
+ *rel_pc = pc - mi->start + mi->load_base;
return mi;
}
}
diff --git a/libc/bionic/debug_mapinfo.h b/libc/bionic/debug_mapinfo.h
index 926b377..af7d05d 100644
--- a/libc/bionic/debug_mapinfo.h
+++ b/libc/bionic/debug_mapinfo.h
@@ -35,6 +35,9 @@
struct mapinfo_t* next;
uintptr_t start;
uintptr_t end;
+ uintptr_t offset;
+ uintptr_t load_base;
+ bool load_base_read;
char name[];
};
diff --git a/tests/Android.mk b/tests/Android.mk
index 84d3426..cd60668 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -402,7 +402,7 @@
LOCAL_CXX = $(LOCAL_PATH)/file-check-cxx \
$(HOST_OUT_EXECUTABLES)/FileCheck \
- $($(LOCAL_2ND_ARCH_VAR_PREFIX)CXX_BARE) \
+ $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_CXX) \
GCC \
LOCAL_CLANG := false