mirror of
https://github.com/tobast/libunwind-eh_elf.git
synced 2024-12-23 03:53:43 +01:00
ia64: move ia64 specific code out of dwarf
We still need to fixup the callers to pick dwarf_find_unwind_table vs ia64_find_unwind_table in a target dependent way.
This commit is contained in:
parent
bc056ffc9f
commit
9507a9b501
4 changed files with 153 additions and 122 deletions
|
@ -191,7 +191,7 @@ libunwind_la_SOURCES_ia64 = $(libunwind_la_SOURCES_ia64_common) \
|
|||
ia64/Lglobal.c ia64/Linit.c ia64/Linit_local.c ia64/Linit_remote.c \
|
||||
ia64/Linstall_cursor.S ia64/Lis_signal_frame.c ia64/Lparser.c \
|
||||
ia64/Lrbs.c ia64/Lregs.c ia64/Lresume.c ia64/Lscript.c ia64/Lstep.c \
|
||||
ia64/Ltables.c
|
||||
ia64/Ltables.c ia64/Lfind_unwind_tables.c
|
||||
|
||||
# The list of files that go into libunwind-ia64:
|
||||
libunwind_ia64_la_SOURCES_ia64 = $(libunwind_la_SOURCES_ia64_common) \
|
||||
|
@ -200,7 +200,7 @@ libunwind_ia64_la_SOURCES_ia64 = $(libunwind_la_SOURCES_ia64_common) \
|
|||
ia64/Gglobal.c ia64/Ginit.c ia64/Ginit_local.c ia64/Ginit_remote.c \
|
||||
ia64/Ginstall_cursor.S ia64/Gis_signal_frame.c ia64/Gparser.c \
|
||||
ia64/Grbs.c ia64/Gregs.c ia64/Gresume.c ia64/Gscript.c ia64/Gstep.c \
|
||||
ia64/Gtables.c
|
||||
ia64/Gtables.c ia64/Gfind_unwind_tables.c
|
||||
|
||||
# The list of files that go both into libunwind and libunwind-hppa:
|
||||
noinst_HEADERS += hppa/init.h hppa/offsets.h hppa/unwind_i.h
|
||||
|
|
|
@ -31,124 +31,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|||
#include <sys/mman.h>
|
||||
|
||||
#include "libunwind_i.h"
|
||||
|
||||
#if UNW_TARGET_IA64
|
||||
|
||||
#include "elf64.h"
|
||||
|
||||
static unw_word_t
|
||||
find_gp (struct elf_dyn_info *edi, Elf64_Phdr *pdyn, Elf64_Addr load_base)
|
||||
{
|
||||
Elf64_Off soff, str_soff;
|
||||
Elf64_Ehdr *ehdr = edi->ei.image;
|
||||
Elf64_Shdr *shdr;
|
||||
Elf64_Shdr *str_shdr;
|
||||
Elf64_Addr gp = 0;
|
||||
char *strtab;
|
||||
int i;
|
||||
|
||||
if (pdyn)
|
||||
{
|
||||
/* If we have a PT_DYNAMIC program header, fetch the gp-value
|
||||
from the DT_PLTGOT entry. */
|
||||
Elf64_Dyn *dyn = (Elf64_Dyn *) (pdyn->p_offset + (char *) edi->ei.image);
|
||||
for (; dyn->d_tag != DT_NULL; ++dyn)
|
||||
if (dyn->d_tag == DT_PLTGOT)
|
||||
{
|
||||
gp = (Elf64_Addr) dyn->d_un.d_ptr + load_base;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
/* Without a PT_DYAMIC header, lets try to look for a non-empty .opd
|
||||
section. If there is such a section, we know it's full of
|
||||
function descriptors, and we can simply pick up the gp from the
|
||||
second word of the first entry in this table. */
|
||||
|
||||
soff = ehdr->e_shoff;
|
||||
str_soff = soff + (ehdr->e_shstrndx * ehdr->e_shentsize);
|
||||
|
||||
if (soff + ehdr->e_shnum * ehdr->e_shentsize > edi->ei.size)
|
||||
{
|
||||
Debug (1, "section table outside of image? (%lu > %lu)",
|
||||
soff + ehdr->e_shnum * ehdr->e_shentsize,
|
||||
edi->ei.size);
|
||||
goto done;
|
||||
}
|
||||
|
||||
shdr = (Elf64_Shdr *) ((char *) edi->ei.image + soff);
|
||||
str_shdr = (Elf64_Shdr *) ((char *) edi->ei.image + str_soff);
|
||||
strtab = (char *) edi->ei.image + str_shdr->sh_offset;
|
||||
for (i = 0; i < ehdr->e_shnum; ++i)
|
||||
{
|
||||
if (strcmp (strtab + shdr->sh_name, ".opd") == 0
|
||||
&& shdr->sh_size >= 16)
|
||||
{
|
||||
gp = ((Elf64_Addr *) ((char *) edi->ei.image + shdr->sh_offset))[1];
|
||||
goto done;
|
||||
}
|
||||
shdr = (Elf64_Shdr *) (((char *) shdr) + ehdr->e_shentsize);
|
||||
}
|
||||
|
||||
done:
|
||||
Debug (16, "image at %p, gp = %lx\n", edi->ei.image, gp);
|
||||
return gp;
|
||||
}
|
||||
|
||||
int
|
||||
dwarf_find_unwind_table (struct elf_dyn_info *edi, unw_addr_space_t as,
|
||||
char *path, unw_word_t segbase, unw_word_t mapoff,
|
||||
unw_word_t ip)
|
||||
{
|
||||
Elf64_Phdr *phdr, *ptxt = NULL, *punw = NULL, *pdyn = NULL;
|
||||
Elf64_Ehdr *ehdr;
|
||||
int i;
|
||||
|
||||
if (!_Uelf64_valid_object (&edi->ei))
|
||||
return -UNW_ENOINFO;
|
||||
|
||||
ehdr = edi->ei.image;
|
||||
phdr = (Elf64_Phdr *) ((char *) edi->ei.image + ehdr->e_phoff);
|
||||
|
||||
for (i = 0; i < ehdr->e_phnum; ++i)
|
||||
{
|
||||
switch (phdr[i].p_type)
|
||||
{
|
||||
case PT_LOAD:
|
||||
if (phdr[i].p_offset == mapoff)
|
||||
ptxt = phdr + i;
|
||||
break;
|
||||
|
||||
case PT_IA_64_UNWIND:
|
||||
punw = phdr + i;
|
||||
break;
|
||||
|
||||
case PT_DYNAMIC:
|
||||
pdyn = phdr + i;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!ptxt || !punw)
|
||||
return 0;
|
||||
|
||||
edi->di_cache.start_ip = segbase;
|
||||
edi->di_cache.end_ip = edi->di_cache.start_ip + ptxt->p_memsz;
|
||||
edi->di_cache.gp = find_gp (edi, pdyn, segbase - ptxt->p_vaddr);
|
||||
edi->di_cache.format = UNW_INFO_FORMAT_TABLE;
|
||||
edi->di_cache.u.ti.name_ptr = 0;
|
||||
edi->di_cache.u.ti.segbase = segbase;
|
||||
edi->di_cache.u.ti.table_len = punw->p_memsz / sizeof (unw_word_t);
|
||||
edi->di_cache.u.ti.table_data = (unw_word_t *)
|
||||
((char *) edi->ei.image + (punw->p_vaddr - ptxt->p_vaddr));
|
||||
return 1;
|
||||
}
|
||||
|
||||
#elif UNW_TARGET_X86 || UNW_TARGET_X86_64 || UNW_TARGET_HPPA \
|
||||
|| UNW_TARGET_PPC32 || UNW_TARGET_PPC64 || UNW_TARGET_ARM
|
||||
|
||||
#include "dwarf-eh.h"
|
||||
#include "dwarf_i.h"
|
||||
|
||||
|
@ -344,5 +226,3 @@ dwarf_find_unwind_table (struct elf_dyn_info *edi, unw_addr_space_t as,
|
|||
|
||||
return found;
|
||||
}
|
||||
|
||||
#endif /* UNW_TARGET_X86 || UNW_TARGET_X86_64 || UNW_TARGET_HPPA*/
|
||||
|
|
146
src/ia64/Gfind_unwind_table.c
Normal file
146
src/ia64/Gfind_unwind_table.c
Normal file
|
@ -0,0 +1,146 @@
|
|||
/* libunwind - a platform-independent unwind library
|
||||
Copyright (C) 2003-2004 Hewlett-Packard Co
|
||||
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
|
||||
|
||||
This file is part of libunwind.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
#include <elf.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include "libunwind_i.h"
|
||||
|
||||
#if UNW_TARGET_IA64
|
||||
|
||||
#include "elf64.h"
|
||||
|
||||
static unw_word_t
|
||||
find_gp (struct elf_dyn_info *edi, Elf64_Phdr *pdyn, Elf64_Addr load_base)
|
||||
{
|
||||
Elf64_Off soff, str_soff;
|
||||
Elf64_Ehdr *ehdr = edi->ei.image;
|
||||
Elf64_Shdr *shdr;
|
||||
Elf64_Shdr *str_shdr;
|
||||
Elf64_Addr gp = 0;
|
||||
char *strtab;
|
||||
int i;
|
||||
|
||||
if (pdyn)
|
||||
{
|
||||
/* If we have a PT_DYNAMIC program header, fetch the gp-value
|
||||
from the DT_PLTGOT entry. */
|
||||
Elf64_Dyn *dyn = (Elf64_Dyn *) (pdyn->p_offset + (char *) edi->ei.image);
|
||||
for (; dyn->d_tag != DT_NULL; ++dyn)
|
||||
if (dyn->d_tag == DT_PLTGOT)
|
||||
{
|
||||
gp = (Elf64_Addr) dyn->d_un.d_ptr + load_base;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
/* Without a PT_DYAMIC header, lets try to look for a non-empty .opd
|
||||
section. If there is such a section, we know it's full of
|
||||
function descriptors, and we can simply pick up the gp from the
|
||||
second word of the first entry in this table. */
|
||||
|
||||
soff = ehdr->e_shoff;
|
||||
str_soff = soff + (ehdr->e_shstrndx * ehdr->e_shentsize);
|
||||
|
||||
if (soff + ehdr->e_shnum * ehdr->e_shentsize > edi->ei.size)
|
||||
{
|
||||
Debug (1, "section table outside of image? (%lu > %lu)",
|
||||
soff + ehdr->e_shnum * ehdr->e_shentsize,
|
||||
edi->ei.size);
|
||||
goto done;
|
||||
}
|
||||
|
||||
shdr = (Elf64_Shdr *) ((char *) edi->ei.image + soff);
|
||||
str_shdr = (Elf64_Shdr *) ((char *) edi->ei.image + str_soff);
|
||||
strtab = (char *) edi->ei.image + str_shdr->sh_offset;
|
||||
for (i = 0; i < ehdr->e_shnum; ++i)
|
||||
{
|
||||
if (strcmp (strtab + shdr->sh_name, ".opd") == 0
|
||||
&& shdr->sh_size >= 16)
|
||||
{
|
||||
gp = ((Elf64_Addr *) ((char *) edi->ei.image + shdr->sh_offset))[1];
|
||||
goto done;
|
||||
}
|
||||
shdr = (Elf64_Shdr *) (((char *) shdr) + ehdr->e_shentsize);
|
||||
}
|
||||
|
||||
done:
|
||||
Debug (16, "image at %p, gp = %lx\n", edi->ei.image, gp);
|
||||
return gp;
|
||||
}
|
||||
|
||||
int
|
||||
ia64_find_unwind_table (struct elf_dyn_info *edi, unw_addr_space_t as,
|
||||
char *path, unw_word_t segbase, unw_word_t mapoff,
|
||||
unw_word_t ip)
|
||||
{
|
||||
Elf64_Phdr *phdr, *ptxt = NULL, *punw = NULL, *pdyn = NULL;
|
||||
Elf64_Ehdr *ehdr;
|
||||
int i;
|
||||
|
||||
if (!_Uelf64_valid_object (&edi->ei))
|
||||
return -UNW_ENOINFO;
|
||||
|
||||
ehdr = edi->ei.image;
|
||||
phdr = (Elf64_Phdr *) ((char *) edi->ei.image + ehdr->e_phoff);
|
||||
|
||||
for (i = 0; i < ehdr->e_phnum; ++i)
|
||||
{
|
||||
switch (phdr[i].p_type)
|
||||
{
|
||||
case PT_LOAD:
|
||||
if (phdr[i].p_offset == mapoff)
|
||||
ptxt = phdr + i;
|
||||
break;
|
||||
|
||||
case PT_IA_64_UNWIND:
|
||||
punw = phdr + i;
|
||||
break;
|
||||
|
||||
case PT_DYNAMIC:
|
||||
pdyn = phdr + i;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!ptxt || !punw)
|
||||
return 0;
|
||||
|
||||
edi->di_cache.start_ip = segbase;
|
||||
edi->di_cache.end_ip = edi->di_cache.start_ip + ptxt->p_memsz;
|
||||
edi->di_cache.gp = find_gp (edi, pdyn, segbase - ptxt->p_vaddr);
|
||||
edi->di_cache.format = UNW_INFO_FORMAT_TABLE;
|
||||
edi->di_cache.u.ti.name_ptr = 0;
|
||||
edi->di_cache.u.ti.segbase = segbase;
|
||||
edi->di_cache.u.ti.table_len = punw->p_memsz / sizeof (unw_word_t);
|
||||
edi->di_cache.u.ti.table_data = (unw_word_t *)
|
||||
((char *) edi->ei.image + (punw->p_vaddr - ptxt->p_vaddr));
|
||||
return 1;
|
||||
}
|
5
src/ia64/Lfind_unwind_table.c
Normal file
5
src/ia64/Lfind_unwind_table.c
Normal file
|
@ -0,0 +1,5 @@
|
|||
#define UNW_LOCAL_ONLY
|
||||
#include <libunwind.h>
|
||||
#if defined(UNW_LOCAL_ONLY) && !defined(UNW_REMOTE_ONLY)
|
||||
#include "Gfind_unwind_table.c"
|
||||
#endif
|
Loading…
Reference in a new issue