2022-01-03 10:42:10 +01:00
|
|
|
/* Copyright (C) 2000-2022 Free Software Foundation, Inc.
|
2000-10-04 05:08:50 +02:00
|
|
|
Contributed by Richard Henderson <rth@cygnus.com>.
|
|
|
|
|
fde-glibc.c, [...]: It's GCC, not GNU CC.
* config/ia64/fde-glibc.c, config/ia64/freebsd.h,
config/ia64/hpux.h, config/ia64/hpux_longdouble.h,
config/ia64/ia64-c.c, config/ia64/ia64-modes.def,
config/ia64/ia64-protos.h, config/ia64/ia64.c,
config/ia64/ia64.h, config/ia64/ia64.md,
config/ia64/itanium1.md, config/ia64/itanium2.md,
config/ia64/quadlib.c, config/ia64/unwind-ia64.c,
config/ia64/unwind-ia64.h: It's GCC, not GNU CC.
From-SVN: r64313
2003-03-13 19:26:30 +01:00
|
|
|
This file is part of GCC.
|
2000-10-04 05:08:50 +02:00
|
|
|
|
fde-glibc.c, [...]: It's GCC, not GNU CC.
* config/ia64/fde-glibc.c, config/ia64/freebsd.h,
config/ia64/hpux.h, config/ia64/hpux_longdouble.h,
config/ia64/ia64-c.c, config/ia64/ia64-modes.def,
config/ia64/ia64-protos.h, config/ia64/ia64.c,
config/ia64/ia64.h, config/ia64/ia64.md,
config/ia64/itanium1.md, config/ia64/itanium2.md,
config/ia64/quadlib.c, config/ia64/unwind-ia64.c,
config/ia64/unwind-ia64.h: It's GCC, not GNU CC.
From-SVN: r64313
2003-03-13 19:26:30 +01:00
|
|
|
GCC is free software; you can redistribute it and/or modify
|
2000-10-04 05:08:50 +02:00
|
|
|
it under the terms of the GNU General Public License as published by
|
2009-04-09 17:00:19 +02:00
|
|
|
the Free Software Foundation; either version 3, or (at your option)
|
2000-10-04 05:08:50 +02:00
|
|
|
any later version.
|
|
|
|
|
fde-glibc.c, [...]: It's GCC, not GNU CC.
* config/ia64/fde-glibc.c, config/ia64/freebsd.h,
config/ia64/hpux.h, config/ia64/hpux_longdouble.h,
config/ia64/ia64-c.c, config/ia64/ia64-modes.def,
config/ia64/ia64-protos.h, config/ia64/ia64.c,
config/ia64/ia64.h, config/ia64/ia64.md,
config/ia64/itanium1.md, config/ia64/itanium2.md,
config/ia64/quadlib.c, config/ia64/unwind-ia64.c,
config/ia64/unwind-ia64.h: It's GCC, not GNU CC.
From-SVN: r64313
2003-03-13 19:26:30 +01:00
|
|
|
GCC is distributed in the hope that it will be useful,
|
2000-10-04 05:08:50 +02:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2009-04-09 17:00:19 +02:00
|
|
|
Under Section 7 of GPL version 3, you are granted additional
|
|
|
|
permissions described in the GCC Runtime Library Exception, version
|
|
|
|
3.1, as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License and
|
|
|
|
a copy of the GCC Runtime Library Exception along with this program;
|
|
|
|
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
2000-10-04 05:08:50 +02:00
|
|
|
|
|
|
|
/* Locate the FDE entry for a given address, using glibc ld.so routines
|
|
|
|
to avoid register/deregister calls at DSO load/unload. */
|
|
|
|
|
2001-08-09 18:22:23 +02:00
|
|
|
#ifndef _GNU_SOURCE
|
2003-11-02 18:35:20 +01:00
|
|
|
#define _GNU_SOURCE 1
|
2001-08-09 18:22:23 +02:00
|
|
|
#endif
|
|
|
|
#include "config.h"
|
|
|
|
#include <stddef.h>
|
2000-10-04 05:08:50 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <link.h>
|
2001-05-12 08:03:20 +02:00
|
|
|
#include "unwind-ia64.h"
|
2000-10-04 05:08:50 +02:00
|
|
|
|
2001-08-09 18:22:23 +02:00
|
|
|
#if __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 2) \
|
|
|
|
|| (__GLIBC__ == 2 && __GLIBC_MINOR__ == 2 && !defined(DT_CONFIG))
|
|
|
|
# error You need GLIBC 2.2.4 or later on IA-64 Linux
|
|
|
|
#endif
|
2000-10-04 05:08:50 +02:00
|
|
|
|
2001-08-09 18:22:23 +02:00
|
|
|
struct unw_ia64_callback_data
|
|
|
|
{
|
|
|
|
Elf64_Addr pc;
|
|
|
|
unsigned long *segment_base;
|
|
|
|
unsigned long *gp;
|
|
|
|
struct unw_table_entry *ret;
|
|
|
|
};
|
2000-10-04 05:08:50 +02:00
|
|
|
|
2001-08-09 18:22:23 +02:00
|
|
|
static int
|
|
|
|
_Unwind_IteratePhdrCallback (struct dl_phdr_info *info, size_t size, void *ptr)
|
2000-10-04 05:08:50 +02:00
|
|
|
{
|
2001-08-09 18:22:23 +02:00
|
|
|
struct unw_ia64_callback_data *data = (struct unw_ia64_callback_data *) ptr;
|
|
|
|
const Elf64_Phdr *phdr, *p_unwind, *p_dynamic;
|
2000-10-04 05:08:50 +02:00
|
|
|
long n, match;
|
|
|
|
Elf64_Addr load_base, seg_base;
|
2001-05-12 08:03:20 +02:00
|
|
|
struct unw_table_entry *f_base, *f;
|
2000-11-08 02:59:35 +01:00
|
|
|
size_t lo, hi;
|
2000-10-04 05:08:50 +02:00
|
|
|
|
2001-08-09 18:22:23 +02:00
|
|
|
/* Make sure struct dl_phdr_info is at least as big as we need. */
|
|
|
|
if (size < offsetof (struct dl_phdr_info, dlpi_phnum)
|
|
|
|
+ sizeof (info->dlpi_phnum))
|
|
|
|
return -1;
|
2000-10-04 05:08:50 +02:00
|
|
|
|
|
|
|
match = 0;
|
2001-08-09 18:22:23 +02:00
|
|
|
phdr = info->dlpi_phdr;
|
|
|
|
load_base = info->dlpi_addr;
|
2000-10-04 05:08:50 +02:00
|
|
|
p_unwind = NULL;
|
2001-05-12 08:03:20 +02:00
|
|
|
p_dynamic = NULL;
|
2001-08-09 18:22:23 +02:00
|
|
|
seg_base = ~(Elf64_Addr) 0;
|
2000-10-04 05:08:50 +02:00
|
|
|
|
|
|
|
/* See if PC falls into one of the loaded segments. Find the unwind
|
|
|
|
segment at the same time. */
|
2001-08-09 18:22:23 +02:00
|
|
|
for (n = info->dlpi_phnum; --n >= 0; phdr++)
|
2000-10-04 05:08:50 +02:00
|
|
|
{
|
|
|
|
if (phdr->p_type == PT_LOAD)
|
|
|
|
{
|
|
|
|
Elf64_Addr vaddr = phdr->p_vaddr + load_base;
|
2001-08-09 18:22:23 +02:00
|
|
|
if (data->pc >= vaddr && data->pc < vaddr + phdr->p_memsz)
|
2000-10-04 05:08:50 +02:00
|
|
|
match = 1;
|
2001-08-09 18:22:23 +02:00
|
|
|
if (vaddr < seg_base)
|
|
|
|
seg_base = vaddr;
|
2000-10-04 05:08:50 +02:00
|
|
|
}
|
|
|
|
else if (phdr->p_type == PT_IA_64_UNWIND)
|
|
|
|
p_unwind = phdr;
|
2001-05-12 08:03:20 +02:00
|
|
|
else if (phdr->p_type == PT_DYNAMIC)
|
|
|
|
p_dynamic = phdr;
|
2000-10-04 05:08:50 +02:00
|
|
|
}
|
|
|
|
if (!match || !p_unwind)
|
2001-08-09 18:22:23 +02:00
|
|
|
return 0;
|
2000-10-04 05:08:50 +02:00
|
|
|
|
|
|
|
/* Search for the FDE within the unwind segment. */
|
|
|
|
|
2001-05-12 08:03:20 +02:00
|
|
|
f_base = (struct unw_table_entry *) (p_unwind->p_vaddr + load_base);
|
2000-11-08 02:59:35 +01:00
|
|
|
lo = 0;
|
2001-05-12 08:03:20 +02:00
|
|
|
hi = p_unwind->p_memsz / sizeof (struct unw_table_entry);
|
2000-11-08 02:59:35 +01:00
|
|
|
|
|
|
|
while (lo < hi)
|
|
|
|
{
|
|
|
|
size_t mid = (lo + hi) / 2;
|
|
|
|
|
2001-05-12 08:03:20 +02:00
|
|
|
f = f_base + mid;
|
2001-08-09 18:22:23 +02:00
|
|
|
if (data->pc < f->start_offset + seg_base)
|
2000-11-08 02:59:35 +01:00
|
|
|
hi = mid;
|
2001-08-09 18:22:23 +02:00
|
|
|
else if (data->pc >= f->end_offset + seg_base)
|
2000-11-08 02:59:35 +01:00
|
|
|
lo = mid + 1;
|
|
|
|
else
|
2001-05-12 08:03:20 +02:00
|
|
|
goto found;
|
2000-11-08 02:59:35 +01:00
|
|
|
}
|
configure.in: Check for ld.
* configure.in: Check for ld.
(HAVE_LD_EH_FRAME_HDR): Define if ld supports --eh-frame-hdr option.
* configure, config.in: Rebuilt.
* config.gcc: Add crtbeginT.o to extra_parts where needed.
* config/t-linux (LIB2ADDEH, LIB2ADDEHDEP): Use unwind-dw2-fde-glibc
frame unwinding on Linux.
* config/t-linux-gnulibc1 (LIB2ADDEH, LIB2ADDEHDEP): Use unwind-dw2-fde
frame unwinding.
* config/linux.h (STARTFILE_SPEC): Use crtbeginT.o for -static.
(LINK_EH_SPEC): Define.
* config/i386/gnu.h (STARTFILE_SPEC): Use crtbeginT.o for -static.
* config/ia64/linux.h (STARTFILE_SPEC, LINK_EH_SPEC): Define.
* config/ia64/fde-glibc.c (_Unwind_IteratePhdrCallback): Don't
iterate further if pc falls into current library, but fde was not
found.
* config/sparc/linux.h (STARTFILE_SPEC): Use crtbeginT.o for -static
if using glibc.
(LINK_EH_SPEC): Define.
* config/sparc/linux64.h (STARTFILE_SPEC32, STARTFILE_SPEC64):
Use crtbeginT.o for -static.
(LINK_EH_SPEC): Define.
* config/sparc/t-linux64 (EXTRA_MULTILIB_PARTS): Add crtbeginT.o.
* Makefile.in (crtbeginT.o): Add rule.
* gcc.c (init_gcc_specs): For -static-libgcc, use -lgcc -lgcc_eh.
If neither -static-libgcc nor -shared-libgcc is passed and -shared,
use -lgcc if LINK_EH_SPEC is defined and -lgcc_s -lgcc if not.
If none of the above switches are passed, use -lgcc -lgcc_eh.
(init_spec): If LINK_EH_SPEC is defined, prepend it to link_spec.
* mklibgcc.in: Don't include LIB2ADDEH objects into libgcc.a if
creating libgcc_s.so, put them into separate libgcc_eh.a instead.
* unwind-dw2-fde.c: Don't include any headers if this file
is included from other .c file.
* unwind-dw2-fde-glibc.c: New file.
* crtstuff.c (USE_PT_GNU_EH_FRAME, USE_EH_FRAME_REGISTRY): Define.
Use it instead of EH_FRAME_SECTION_NAME where appropriate.
From-SVN: r48039
2001-12-15 12:49:18 +01:00
|
|
|
/* No need to search for further libraries when we know pc is contained
|
|
|
|
in this library. */
|
|
|
|
return 1;
|
2001-05-12 08:03:20 +02:00
|
|
|
|
|
|
|
found:
|
2001-08-09 18:22:23 +02:00
|
|
|
*data->segment_base = seg_base;
|
|
|
|
*data->gp = 0;
|
|
|
|
data->ret = f;
|
2001-05-12 08:03:20 +02:00
|
|
|
|
|
|
|
if (p_dynamic)
|
|
|
|
{
|
2003-01-26 21:15:36 +01:00
|
|
|
/* For dynamically linked executables and shared libraries,
|
2001-05-12 08:03:20 +02:00
|
|
|
DT_PLTGOT is the gp value for that object. */
|
|
|
|
Elf64_Dyn *dyn = (Elf64_Dyn *)(p_dynamic->p_vaddr + load_base);
|
|
|
|
for (; dyn->d_tag != DT_NULL ; dyn++)
|
|
|
|
if (dyn->d_tag == DT_PLTGOT)
|
|
|
|
{
|
2001-08-09 18:22:23 +02:00
|
|
|
/* On IA-64, _DYNAMIC is writable and GLIBC has relocated it. */
|
|
|
|
*data->gp = dyn->d_un.d_ptr;
|
2001-05-12 08:03:20 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Otherwise this is a static executable with no _DYNAMIC.
|
|
|
|
The gp is constant program-wide. */
|
|
|
|
register unsigned long gp __asm__("gp");
|
2001-08-09 18:22:23 +02:00
|
|
|
*data->gp = gp;
|
2001-05-12 08:03:20 +02:00
|
|
|
}
|
|
|
|
|
2001-08-09 18:22:23 +02:00
|
|
|
return 1;
|
2000-10-04 05:08:50 +02:00
|
|
|
}
|
|
|
|
|
2001-05-12 08:03:20 +02:00
|
|
|
/* Return a pointer to the unwind table entry for the function
|
|
|
|
containing PC. */
|
|
|
|
|
|
|
|
struct unw_table_entry *
|
unwind-ia64.h: Declare unw_word and unw_sword.
2012-03-26 Tristan Gingold <gingold@adacore.com>
* config/ia64/unwind-ia64.h: Declare unw_word and unw_sword.
(unw_table_entry): Use unw_word instead of unsigned long.
(_Unwind_FindTableEntry): Likewise.
* config/ia64/fde-glibc.c (_Unwind_FindTableEntry): Likewise.
* config/ia64/fde-vms.c (vms_unwtable_entry): Likewise.
(_Unwind_FindTableEntry): Likewise.
* config/ia64/unwind-ia64.c (unw_reg_info, unw_reg_state)
(unw_labeled_state, unw_state_record, unw_stack, _Uwind_Context)
(set_reg, alloc_spill_area, finish_prologue, ia64_rse_slot_num)
(ia64_rse_is_rnat_slot, ia64_rse_rnat_addr, ia64_rse_num_regs)
(ia64_rse_skip_regs, ia64_copy_rbs, unw_access_gr)
(uw_frame_state_for, uw_update_reg_address, uw_update_context)
(uw_init_context_1, uw_install_context): Likewise.
(unw_word): Move to unwind-ia64.h
From-SVN: r185852
2012-03-27 11:50:10 +02:00
|
|
|
_Unwind_FindTableEntry (void *pc, unw_word *segment_base, unw_word *gp,
|
2009-08-14 22:56:31 +02:00
|
|
|
struct unw_table_entry *ent ATTRIBUTE_UNUSED)
|
2000-10-04 05:08:50 +02:00
|
|
|
{
|
2001-08-09 18:22:23 +02:00
|
|
|
struct unw_ia64_callback_data data;
|
2000-10-04 05:08:50 +02:00
|
|
|
|
2001-08-09 18:22:23 +02:00
|
|
|
data.pc = (Elf64_Addr) pc;
|
|
|
|
data.segment_base = segment_base;
|
|
|
|
data.gp = gp;
|
|
|
|
data.ret = NULL;
|
2000-10-04 05:08:50 +02:00
|
|
|
|
2001-08-09 18:22:23 +02:00
|
|
|
if (dl_iterate_phdr (_Unwind_IteratePhdrCallback, &data) < 0)
|
|
|
|
return NULL;
|
2000-10-04 05:08:50 +02:00
|
|
|
|
2001-08-09 18:22:23 +02:00
|
|
|
return data.ret;
|
2000-10-04 05:08:50 +02:00
|
|
|
}
|