mirror of
https://github.com/tobast/libunwind-eh_elf.git
synced 2024-11-26 17:17:39 +01:00
Enclose ia64-specific code by UNW_TARGET_IA64.
Adjust for the fact that the image info is now tracked by "struct elf_image". (elf64_valid_object): Delete (it's now in elfxx.c. (_UPTi_find_uwnind_table): Don't mmap the image here. (get_unwind_info): Use tdep_get_elf_image() to obtain the ELF image. (Logical change 1.45)
This commit is contained in:
parent
d0e021d85b
commit
12d13835f9
1 changed files with 35 additions and 63 deletions
|
@ -32,11 +32,15 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||||
|
|
||||||
#include "_UPT_internal.h"
|
#include "_UPT_internal.h"
|
||||||
|
|
||||||
|
#if UNW_TARGET_IA64
|
||||||
|
|
||||||
|
#include "elf64.h"
|
||||||
|
|
||||||
static unw_word_t
|
static unw_word_t
|
||||||
find_gp (struct UPT_info *ui, Elf64_Phdr *pdyn, Elf64_Addr load_base)
|
find_gp (struct UPT_info *ui, Elf64_Phdr *pdyn, Elf64_Addr load_base)
|
||||||
{
|
{
|
||||||
Elf64_Off soff, str_soff;
|
Elf64_Off soff, str_soff;
|
||||||
Elf64_Ehdr *ehdr = ui->image;
|
Elf64_Ehdr *ehdr = ui->ei.image;
|
||||||
Elf64_Shdr *shdr;
|
Elf64_Shdr *shdr;
|
||||||
Elf64_Shdr *str_shdr;
|
Elf64_Shdr *str_shdr;
|
||||||
Elf64_Addr gp = 0;
|
Elf64_Addr gp = 0;
|
||||||
|
@ -47,7 +51,7 @@ find_gp (struct UPT_info *ui, Elf64_Phdr *pdyn, Elf64_Addr load_base)
|
||||||
{
|
{
|
||||||
/* If we have a PT_DYNAMIC program header, fetch the gp-value
|
/* If we have a PT_DYNAMIC program header, fetch the gp-value
|
||||||
from the DT_PLTGOT entry. */
|
from the DT_PLTGOT entry. */
|
||||||
Elf64_Dyn *dyn = (Elf64_Dyn *) (pdyn->p_offset + ui->image);
|
Elf64_Dyn *dyn = (Elf64_Dyn *) (pdyn->p_offset + ui->ei.image);
|
||||||
for (; dyn->d_tag != DT_NULL; ++dyn)
|
for (; dyn->d_tag != DT_NULL; ++dyn)
|
||||||
if (dyn->d_tag == DT_PLTGOT)
|
if (dyn->d_tag == DT_PLTGOT)
|
||||||
{
|
{
|
||||||
|
@ -64,78 +68,46 @@ find_gp (struct UPT_info *ui, Elf64_Phdr *pdyn, Elf64_Addr load_base)
|
||||||
soff = ehdr->e_shoff;
|
soff = ehdr->e_shoff;
|
||||||
str_soff = soff + (ehdr->e_shstrndx * ehdr->e_shentsize);
|
str_soff = soff + (ehdr->e_shstrndx * ehdr->e_shentsize);
|
||||||
|
|
||||||
if (soff + ehdr->e_shnum * ehdr->e_shentsize > ui->image_size)
|
if (soff + ehdr->e_shnum * ehdr->e_shentsize > ui->ei.size)
|
||||||
{
|
{
|
||||||
debug (1, "%s: section table outside of image? (%lu > %lu)", __FUNCTION__,
|
debug (1, "%s: section table outside of image? (%lu > %lu)",
|
||||||
soff + ehdr->e_shnum * ehdr->e_shentsize, ui->image_size);
|
__FUNCTION__, soff + ehdr->e_shnum * ehdr->e_shentsize,
|
||||||
|
ui->ei.size);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
shdr = (Elf64_Shdr *) ((char *) ui->image + soff);
|
shdr = (Elf64_Shdr *) ((char *) ui->ei.image + soff);
|
||||||
str_shdr = (Elf64_Shdr *) ((char *) ui->image + str_soff);
|
str_shdr = (Elf64_Shdr *) ((char *) ui->ei.image + str_soff);
|
||||||
strtab = (char *) ui->image + str_shdr->sh_offset;
|
strtab = (char *) ui->ei.image + str_shdr->sh_offset;
|
||||||
for (i = 0; i < ehdr->e_shnum; ++i)
|
for (i = 0; i < ehdr->e_shnum; ++i)
|
||||||
{
|
{
|
||||||
if (strcmp (strtab + shdr->sh_name, ".opd") == 0
|
if (strcmp (strtab + shdr->sh_name, ".opd") == 0
|
||||||
&& shdr->sh_size >= 16)
|
&& shdr->sh_size >= 16)
|
||||||
{
|
{
|
||||||
gp = ((Elf64_Addr *) (ui->image + shdr->sh_offset))[1];
|
gp = ((Elf64_Addr *) (ui->ei.image + shdr->sh_offset))[1];
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
shdr = (Elf64_Shdr *) (((char *) shdr) + ehdr->e_shentsize);
|
shdr = (Elf64_Shdr *) (((char *) shdr) + ehdr->e_shentsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
debug (100, "%s: image at %lx, gp = %lx\n", ui->image, gp);
|
debug (100, "%s: image at %p, gp = %lx\n", __FUNCTION__, ui->ei.image, gp);
|
||||||
return gp;
|
return gp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
|
||||||
elf64_valid_object (struct UPT_info *ui)
|
|
||||||
{
|
|
||||||
return memcmp (ui->image, ELFMAG, SELFMAG) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
HIDDEN unw_dyn_info_t *
|
HIDDEN unw_dyn_info_t *
|
||||||
_UPTi_find_unwind_table (struct UPT_info *ui, unw_addr_space_t as,
|
_UPTi_find_unwind_table (struct UPT_info *ui, unw_addr_space_t as,
|
||||||
char *path, unw_word_t segbase, unw_word_t mapoff)
|
char *path, unw_word_t segbase, unw_word_t mapoff)
|
||||||
{
|
{
|
||||||
Elf64_Phdr *phdr, *ptxt = NULL, *punw = NULL, *pdyn = NULL;
|
Elf64_Phdr *phdr, *ptxt = NULL, *punw = NULL, *pdyn = NULL;
|
||||||
struct stat stat;
|
|
||||||
Elf64_Ehdr *ehdr;
|
Elf64_Ehdr *ehdr;
|
||||||
int fd, i;
|
int i;
|
||||||
|
|
||||||
if (ui->image)
|
if (!_Uelf64_valid_object (&ui->ei))
|
||||||
{
|
|
||||||
munmap (ui->image, ui->image_size);
|
|
||||||
ui->image = NULL;
|
|
||||||
ui->image_size = 0;
|
|
||||||
|
|
||||||
/* invalidate the cache: */
|
|
||||||
ui->di_cache.start_ip = ui->di_cache.end_ip = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
fd = open (path, O_RDONLY);
|
|
||||||
if (fd < 0)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (fstat (fd, &stat) < 0)
|
ehdr = ui->ei.image;
|
||||||
{
|
phdr = (Elf64_Phdr *) ((char *) ui->ei.image + ehdr->e_phoff);
|
||||||
close (fd);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ui->image_size = stat.st_size;
|
|
||||||
ui->image = mmap (NULL, ui->image_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
|
||||||
close (fd);
|
|
||||||
if (ui->image == MAP_FAILED)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (!elf64_valid_object (ui))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
ehdr = ui->image;
|
|
||||||
phdr = (Elf64_Phdr *) ((char *) ui->image + ehdr->e_phoff);
|
|
||||||
|
|
||||||
for (i = 0; i < ehdr->e_phnum; ++i)
|
for (i = 0; i < ehdr->e_phnum; ++i)
|
||||||
{
|
{
|
||||||
|
@ -169,26 +141,24 @@ _UPTi_find_unwind_table (struct UPT_info *ui, unw_addr_space_t as,
|
||||||
ui->di_cache.u.ti.segbase = segbase;
|
ui->di_cache.u.ti.segbase = segbase;
|
||||||
ui->di_cache.u.ti.table_len = punw->p_memsz / sizeof (unw_word_t);
|
ui->di_cache.u.ti.table_len = punw->p_memsz / sizeof (unw_word_t);
|
||||||
ui->di_cache.u.ti.table_data = (unw_word_t *)
|
ui->di_cache.u.ti.table_data = (unw_word_t *)
|
||||||
((char *) ui->image + (punw->p_vaddr - ptxt->p_vaddr));
|
((char *) ui->ei.image + (punw->p_vaddr - ptxt->p_vaddr));
|
||||||
return &ui->di_cache;
|
return &ui->di_cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* UNW_TARGET_IA64 */
|
||||||
|
|
||||||
static unw_dyn_info_t *
|
static unw_dyn_info_t *
|
||||||
get_unwind_info (struct UPT_info *ui, unw_addr_space_t as,
|
get_unwind_info (struct UPT_info *ui, unw_addr_space_t as,
|
||||||
unw_word_t ip, unw_proc_info_t *pi,
|
unw_word_t ip, unw_proc_info_t *pi,
|
||||||
int need_unwind_info)
|
int need_unwind_info)
|
||||||
{
|
{
|
||||||
unsigned long segbase, hi, mapoff;
|
unsigned long segbase, mapoff;
|
||||||
struct map_iterator mi;
|
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
|
|
||||||
#if UNW_TARGET_IA64
|
#if UNW_TARGET_IA64
|
||||||
if (!ui->ktab.start_ip)
|
if (!ui->ktab.start_ip && _Uia64_get_kernel_table (&ui->ktab) < 0)
|
||||||
{
|
return NULL;
|
||||||
int ret = _Uia64_get_kernel_table (&ui->ktab);
|
|
||||||
if (ret < 0)
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (ip >= ui->ktab.start_ip && ip < ui->ktab.end_ip)
|
if (ip >= ui->ktab.start_ip && ip < ui->ktab.end_ip)
|
||||||
return &ui->ktab;
|
return &ui->ktab;
|
||||||
#endif
|
#endif
|
||||||
|
@ -196,15 +166,17 @@ get_unwind_info (struct UPT_info *ui, unw_addr_space_t as,
|
||||||
if (ip >= ui->di_cache.start_ip && ip < ui->di_cache.end_ip)
|
if (ip >= ui->di_cache.start_ip && ip < ui->di_cache.end_ip)
|
||||||
return &ui->di_cache;
|
return &ui->di_cache;
|
||||||
|
|
||||||
maps_init (&mi, ui->pid);
|
if (ui->ei.image)
|
||||||
while (maps_next (&mi, &segbase, &hi, &mapoff, path))
|
|
||||||
{
|
{
|
||||||
if (ip >= segbase && ip < hi)
|
munmap (ui->ei.image, ui->ei.size);
|
||||||
break;
|
ui->ei.image = NULL;
|
||||||
}
|
ui->ei.size = 0;
|
||||||
maps_close (&mi);
|
|
||||||
|
|
||||||
if (ip < segbase || ip >= hi)
|
/* invalidate the cache: */
|
||||||
|
ui->di_cache.start_ip = ui->di_cache.end_ip = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tdep_get_elf_image (&ui->ei, ui->pid, ip, &segbase, &mapoff) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return _UPTi_find_unwind_table (ui, as, path, segbase, mapoff);
|
return _UPTi_find_unwind_table (ui, as, path, segbase, mapoff);
|
||||||
|
|
Loading…
Reference in a new issue