am 4a4ba40e: Update all mapoff checks to check against 0.
* commit '4a4ba40ed815be9307ac64023565d5b22c7fdf39':
Update all mapoff checks to check against 0.
diff --git a/include/dwarf.h b/include/dwarf.h
index 3665e00..72804d2 100644
--- a/include/dwarf.h
+++ b/include/dwarf.h
@@ -411,8 +411,7 @@
/* ANDROID support update. */
extern int dwarf_find_unwind_table (struct elf_dyn_info *edi, struct elf_image *ei,
unw_addr_space_t as, char *path,
- unw_word_t segbase, unw_word_t mapoff,
- unw_word_t ip);
+ unw_word_t segbase, unw_word_t ip);
/* End of ANDROID update. */
extern void dwarf_put_unwind_info (unw_addr_space_t as,
unw_proc_info_t *pi, void *arg);
diff --git a/include/tdep-aarch64/libunwind_i.h b/include/tdep-aarch64/libunwind_i.h
index 0690b1b..62a5b58 100644
--- a/include/tdep-aarch64/libunwind_i.h
+++ b/include/tdep-aarch64/libunwind_i.h
@@ -304,8 +304,7 @@
/* ANDROID support update. */
extern int tdep_get_elf_image (unw_addr_space_t as, struct elf_image *ei,
pid_t pid, unw_word_t ip,
- unsigned long *segbase, unsigned long *mapoff,
- char **path, void *as_arg);
+ unsigned long *segbase, char **path, void *as_arg);
/* End of ANDROID update. */
extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg,
unw_word_t *valp, int write);
diff --git a/include/tdep-arm/libunwind_i.h b/include/tdep-arm/libunwind_i.h
index d782cc4..fc2bd0d 100644
--- a/include/tdep-arm/libunwind_i.h
+++ b/include/tdep-arm/libunwind_i.h
@@ -297,8 +297,7 @@
/* ANDROID support update. */
extern int tdep_get_elf_image (unw_addr_space_t as, struct elf_image *ei,
pid_t pid, unw_word_t ip,
- unsigned long *segbase, unsigned long *mapoff,
- char **path, void *as_arg);
+ unsigned long *segbase, char **path, void *as_arg);
/* End of ANDROID update. */
extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg,
unw_word_t *valp, int write);
diff --git a/include/tdep-mips/libunwind_i.h b/include/tdep-mips/libunwind_i.h
index 41cc83f..de3918d 100644
--- a/include/tdep-mips/libunwind_i.h
+++ b/include/tdep-mips/libunwind_i.h
@@ -343,8 +343,7 @@
/* ANDROID support update. */
extern int tdep_get_elf_image (unw_addr_space_t as, struct elf_image *ei,
pid_t pid, unw_word_t ip,
- unsigned long *segbase, unsigned long *mapoff,
- char **path, void *as_arg);
+ unsigned long *segbase, char **path, void *as_arg);
/* End of ANDROID update. */
extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg,
unw_word_t *valp, int write);
diff --git a/include/tdep-x86/libunwind_i.h b/include/tdep-x86/libunwind_i.h
index f87bd71..e532441 100644
--- a/include/tdep-x86/libunwind_i.h
+++ b/include/tdep-x86/libunwind_i.h
@@ -291,8 +291,7 @@
/* ANDROID support update. */
extern int tdep_get_elf_image (unw_addr_space_t as, struct elf_image *ei,
pid_t pid, unw_word_t ip,
- unsigned long *segbase, unsigned long *mapoff,
- char **path, void *as_arg);
+ unsigned long *segbase, char **path, void *as_arg);
/* End of ANDROID update. */
extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg,
unw_word_t *valp, int write);
diff --git a/include/tdep-x86_64/libunwind_i.h b/include/tdep-x86_64/libunwind_i.h
index 184989e..1be9363 100644
--- a/include/tdep-x86_64/libunwind_i.h
+++ b/include/tdep-x86_64/libunwind_i.h
@@ -237,8 +237,7 @@
/* ANDROID support update. */
extern int tdep_get_elf_image (unw_addr_space_t as, struct elf_image *ei,
pid_t pid, unw_word_t ip,
- unsigned long *segbase, unsigned long *mapoff,
- char **path, void *as_arg);
+ unsigned long *segbase, char **path, void *as_arg);
/* End of ANDROID update. */
extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg,
unw_word_t *valp, int write);
diff --git a/src/Los-common.c b/src/Los-common.c
index 6341545..e8e2171 100644
--- a/src/Los-common.c
+++ b/src/Los-common.c
@@ -164,7 +164,7 @@
PROTECTED int
local_get_elf_image (unw_addr_space_t as, struct elf_image *ei, unw_word_t ip,
- unsigned long *segbase, unsigned long *mapoff, char **path, void *as_arg)
+ unsigned long *segbase, char **path, void *as_arg)
{
struct map_info *map;
intrmask_t saved_mask;
@@ -186,7 +186,6 @@
{
*ei = map->ei;
*segbase = map->start;
- *mapoff = map->offset;
if (path != NULL)
{
if (map->path)
diff --git a/src/dwarf/Gfind_unwind_table.c b/src/dwarf/Gfind_unwind_table.c
index 9de3ad5..1703cef 100644
--- a/src/dwarf/Gfind_unwind_table.c
+++ b/src/dwarf/Gfind_unwind_table.c
@@ -125,7 +125,7 @@
static bool dwarf_find_unwind_table_memory (
struct elf_dyn_info *edi, struct elf_image *ei, unw_addr_space_t as, char *path,
- unw_word_t segbase, unw_word_t mapoff, unw_word_t ip) {
+ unw_word_t segbase, unw_word_t ip) {
Elf_W(Ehdr) ehdr;
GET_EHDR_FIELD(ei, &ehdr, e_phoff, false);
GET_EHDR_FIELD(ei, &ehdr, e_phnum, false);
@@ -157,7 +157,13 @@
}
GET_PHDR_FIELD(ei, offset, &phdr, p_offset);
- if (phdr.p_offset == mapoff) {
+ /* Always use zero as the map offset to match. The dlopen of a shared
+ * library from an APK will result in a non-zero offset so it won't
+ * match anything and cause unwinds to fail. There is no case where
+ * the ANDROID linker will create an executable map that has a non-zero
+ * map offset.
+ */
+ if (phdr.p_offset == 0) {
txt_phdr_offset = offset;
txt_pvaddr = phdr.p_vaddr;
}
@@ -238,7 +244,7 @@
int
dwarf_find_unwind_table (struct elf_dyn_info *edi, struct elf_image *ei,
unw_addr_space_t as, char *path,
- unw_word_t segbase, unw_word_t mapoff, unw_word_t ip)
+ unw_word_t segbase, unw_word_t ip)
{
Elf_W(Phdr) *phdr, *ptxt = NULL, *peh_hdr = NULL, *pdyn = NULL;
unw_word_t addr, eh_frame_start, fde_count, load_base;
@@ -263,7 +269,7 @@
return -UNW_ENOINFO;
if (!ei->mapped) {
- if (dwarf_find_unwind_table_memory (edi, ei, as, path, segbase, mapoff, ip)) {
+ if (dwarf_find_unwind_table_memory (edi, ei, as, path, segbase, ip)) {
return 1;
}
return -UNW_ENOINFO;
@@ -285,7 +291,13 @@
if (phdr[i].p_vaddr + phdr[i].p_memsz > end_ip)
end_ip = phdr[i].p_vaddr + phdr[i].p_memsz;
- if (phdr[i].p_offset == mapoff)
+ /* Always use zero as the map offset to match. The dlopen of a shared
+ * library from an APK will result in a non-zero offset so it won't
+ * match anything and cause unwinds to fail. There is no case where
+ * the ANDROID linker will create an executable map that has a non-zero
+ * map offset.
+ */
+ if (phdr[i].p_offset == 0)
ptxt = phdr + i;
#if 0
diff --git a/src/elfxx.c b/src/elfxx.c
index 6676d0c..50d5266 100644
--- a/src/elfxx.c
+++ b/src/elfxx.c
@@ -245,8 +245,7 @@
}
static bool elf_w (get_load_offset_memory) (
- struct elf_image* ei, unsigned long segbase, unsigned long mapoff,
- Elf_W(Ehdr)* ehdr, Elf_W(Addr)* load_offset) {
+ struct elf_image* ei, unsigned long segbase, Elf_W(Ehdr)* ehdr, Elf_W(Addr)* load_offset) {
GET_EHDR_FIELD(ei, ehdr, e_phoff, true);
GET_EHDR_FIELD(ei, ehdr, e_phnum, true);
@@ -257,7 +256,13 @@
GET_PHDR_FIELD(ei, offset, &phdr, p_type);
if (phdr.p_type == PT_LOAD) {
GET_PHDR_FIELD(ei, offset, &phdr, p_offset);
- if (phdr.p_offset == mapoff) {
+ /* Always use zero as the map offset to match. The dlopen of a shared
+ * library from an APK will result in a non-zero offset so it won't
+ * match anything and cause unwinds to fail. There is no case where
+ * the ANDROID linker will create an executable map that has a non-zero
+ * map offset.
+ */
+ if (phdr.p_offset == 0) {
GET_PHDR_FIELD(ei, offset, &phdr, p_vaddr);
*load_offset = segbase - phdr.p_vaddr;
return true;
@@ -387,13 +392,19 @@
}
static bool elf_w (get_load_offset_mapped) (
- struct elf_image *ei, unsigned long segbase, unsigned long mapoff, Elf_W(Addr)* load_offset) {
+ struct elf_image *ei, unsigned long segbase, Elf_W(Addr)* load_offset) {
Elf_W(Ehdr) *ehdr = ei->u.mapped.image;
Elf_W(Phdr) *phdr = (Elf_W(Phdr) *) ((char *) ei->u.mapped.image + ehdr->e_phoff);
int i;
for (i = 0; i < ehdr->e_phnum; ++i) {
- if (phdr[i].p_type == PT_LOAD && phdr[i].p_offset == mapoff) {
+ /* Always use zero as the map offset to match. The dlopen of a shared
+ * library from an APK will result in a non-zero offset so it won't
+ * match anything and cause unwinds to fail. There is no case where
+ * the ANDROID linker will create an executable map that has a non-zero
+ * map offset.
+ */
+ if (phdr[i].p_type == PT_LOAD && phdr[i].p_offset == 0) {
*load_offset = segbase - phdr[i].p_vaddr;
return true;
}
@@ -425,12 +436,11 @@
}
static bool elf_w (get_load_offset) (
- struct elf_image* ei, unsigned long segbase, unsigned long mapoff,
- Elf_W(Ehdr)* ehdr, Elf_W(Addr)* load_offset) {
+ struct elf_image* ei, unsigned long segbase, Elf_W(Ehdr)* ehdr, Elf_W(Addr)* load_offset) {
if (ei->mapped) {
- return elf_w (get_load_offset_mapped) (ei, segbase, mapoff, load_offset);
+ return elf_w (get_load_offset_mapped) (ei, segbase, load_offset);
} else {
- return elf_w (get_load_offset_memory) (ei, segbase, mapoff, ehdr, load_offset);
+ return elf_w (get_load_offset_memory) (ei, segbase, ehdr, load_offset);
}
}
@@ -551,12 +561,12 @@
// Find the ELF image that contains IP and return the procedure name from
// the symbol table that matches the IP.
HIDDEN bool elf_w (get_proc_name_in_image) (
- unw_addr_space_t as, struct elf_image* ei, unsigned long segbase, unsigned long mapoff,
+ unw_addr_space_t as, struct elf_image* ei, unsigned long segbase,
unw_word_t ip, char* buf, size_t buf_len, unw_word_t* offp) {
Elf_W(Ehdr) ehdr;
memset(&ehdr, 0, sizeof(ehdr));
Elf_W(Addr) load_offset;
- if (!elf_w (get_load_offset) (ei, segbase, mapoff, &ehdr, &load_offset)) {
+ if (!elf_w (get_load_offset) (ei, segbase, &ehdr, &load_offset)) {
return false;
}
@@ -568,7 +578,7 @@
// the MiniDebugInfo.
struct elf_image mdi;
if (elf_w (extract_minidebuginfo) (ei, &mdi, &ehdr)) {
- if (!elf_w (get_load_offset) (&mdi, segbase, mapoff, &ehdr, &load_offset)) {
+ if (!elf_w (get_load_offset) (&mdi, segbase, &ehdr, &load_offset)) {
return false;
}
if (elf_w (lookup_symbol) (as, ip, &mdi, load_offset, buf, buf_len, offp, &ehdr)) {
@@ -583,17 +593,17 @@
HIDDEN bool elf_w (get_proc_name) (
unw_addr_space_t as, pid_t pid, unw_word_t ip, char* buf, size_t buf_len,
unw_word_t* offp, void* as_arg) {
- unsigned long segbase, mapoff;
+ unsigned long segbase;
struct elf_image ei;
- if (tdep_get_elf_image(as, &ei, pid, ip, &segbase, &mapoff, NULL, as_arg) < 0) {
+ if (tdep_get_elf_image(as, &ei, pid, ip, &segbase, NULL, as_arg) < 0) {
return false;
}
- return elf_w (get_proc_name_in_image) (as, &ei, segbase, mapoff, ip, buf, buf_len, offp);
+ return elf_w (get_proc_name_in_image) (as, &ei, segbase, ip, buf, buf_len, offp);
}
-HIDDEN bool elf_w (get_load_base) (struct elf_image* ei, unw_word_t mapoff, unw_word_t* load_base) {
+HIDDEN bool elf_w (get_load_base) (struct elf_image* ei, unw_word_t* load_base) {
if (!ei->valid) {
return false;
}
@@ -603,7 +613,13 @@
Elf_W(Phdr)* phdr = (Elf_W(Phdr)*) ((char*) ei->u.mapped.image + ehdr->e_phoff);
int i;
for (i = 0; i < ehdr->e_phnum; ++i) {
- if (phdr[i].p_type == PT_LOAD && phdr[i].p_offset == mapoff) {
+ /* Always use zero as the map offset to match. The dlopen of a shared
+ * library from an APK will result in a non-zero offset so it won't
+ * match anything and cause unwinds to fail. There is no case where
+ * the ANDROID linker will create an executable map that has a non-zero
+ * map offset.
+ */
+ if (phdr[i].p_type == PT_LOAD && phdr[i].p_offset == 0) {
*load_base = phdr[i].p_vaddr;
return true;
}
@@ -619,7 +635,13 @@
Elf_W(Phdr) phdr;
GET_PHDR_FIELD(ei, offset, &phdr, p_type);
GET_PHDR_FIELD(ei, offset, &phdr, p_offset);
- if (phdr.p_type == PT_LOAD && phdr.p_offset == mapoff) {
+ /* Always use zero as the map offset to match. The dlopen of a shared
+ * library from an APK will result in a non-zero offset so it won't
+ * match anything and cause unwinds to fail. There is no case where
+ * the ANDROID linker will create an executable map that has a non-zero
+ * map offset.
+ */
+ if (phdr.p_type == PT_LOAD && phdr.p_offset == 0) {
GET_PHDR_FIELD(ei, offset, &phdr, p_vaddr);
*load_base = phdr.p_vaddr;
return true;
diff --git a/src/elfxx.h b/src/elfxx.h
index e0343b4..9c5e699 100644
--- a/src/elfxx.h
+++ b/src/elfxx.h
@@ -76,9 +76,9 @@
extern bool elf_w (get_proc_name_in_image) (
unw_addr_space_t as, struct elf_image* ei, unsigned long segbase,
- unsigned long mapoff, unw_word_t ip, char* buf, size_t buf_len, unw_word_t* offp);
+ unw_word_t ip, char* buf, size_t buf_len, unw_word_t* offp);
-extern bool elf_w (get_load_base) (struct elf_image* ei, unw_word_t mapoff, unw_word_t* load_base);
+extern bool elf_w (get_load_base) (struct elf_image* ei, unw_word_t* load_base);
extern size_t elf_w (memory_read) (
struct elf_image* ei, unw_word_t addr, uint8_t* buffer, size_t bytes, bool string_read);
@@ -166,7 +166,7 @@
}
}
unw_word_t load_base;
- if (map->ei.valid && elf_w (get_load_base) (&map->ei, map->offset, &load_base)) {
+ if (map->ei.valid && elf_w (get_load_base) (&map->ei, &load_base)) {
map->load_base = load_base;
}
}
diff --git a/src/os-common.c b/src/os-common.c
index 8f32af9..6b23e9b 100644
--- a/src/os-common.c
+++ b/src/os-common.c
@@ -27,19 +27,17 @@
#include "map_info.h"
extern int local_get_elf_image (unw_addr_space_t as, struct elf_image *,
- unw_word_t, unsigned long *, unsigned long *,
- char **, void *);
+ unw_word_t, unsigned long *, char **, void *);
PROTECTED int
tdep_get_elf_image (unw_addr_space_t as, struct elf_image *ei,
- pid_t pid, unw_word_t ip,
- unsigned long *segbase, unsigned long *mapoff, char **path,
- void *as_arg)
+ pid_t pid, unw_word_t ip, unsigned long *segbase,
+ char **path, void *as_arg)
{
struct map_info *map;
if (pid == getpid())
- return local_get_elf_image (as, ei, ip, segbase, mapoff, path, as_arg);
+ return local_get_elf_image (as, ei, ip, segbase, path, as_arg);
map = map_find_from_addr (as->map_list, ip);
if (!map)
@@ -50,7 +48,6 @@
*ei = map->ei;
*segbase = map->start;
- *mapoff = map->offset;
if (path != NULL)
{
*path = strdup (map->path);
diff --git a/src/os-linux.c b/src/os-linux.c
index f65c98a..eac3f04 100644
--- a/src/os-linux.c
+++ b/src/os-linux.c
@@ -86,7 +86,7 @@
&& elf_map_image (&ei, cur_map->path))
{
unw_word_t load_base;
- if (elf_w (get_load_base) (&ei, offset, &load_base))
+ if (elf_w (get_load_base) (&ei, &load_base))
cur_map->load_base = load_base;
munmap (ei.u.mapped.image, ei.u.mapped.size);
}
@@ -127,7 +127,7 @@
ei.u.memory.as_arg = as_arg;
ei.valid = elf_w (valid_object_memory) (&ei);
unw_word_t load_base;
- if (ei.valid && elf_w (get_load_base) (&ei, cur_map->offset, &load_base))
+ if (ei.valid && elf_w (get_load_base) (&ei, &load_base))
cur_map->load_base = load_base;
}
}
diff --git a/src/ptrace/_UPT_find_proc_info.c b/src/ptrace/_UPT_find_proc_info.c
index acaa5f9..bbd800e 100644
--- a/src/ptrace/_UPT_find_proc_info.c
+++ b/src/ptrace/_UPT_find_proc_info.c
@@ -63,10 +63,10 @@
invalidate_edi(edi);
/* ANDROID support update. */
- if (tdep_get_elf_image (as, &ei, pid, ip, &segbase, &mapoff, &path, as_arg) < 0)
+ if (tdep_get_elf_image (as, &ei, pid, ip, &segbase, &path, as_arg) < 0)
return -UNW_ENOINFO;
- ret = tdep_find_unwind_table (edi, &ei, as, path, segbase, mapoff, ip);
+ ret = tdep_find_unwind_table (edi, &ei, as, path, segbase, ip);
free(path);
if (ret < 0)
return ret;