1 /* Copyright (C) 2000, 2001, 2003, 2009 Free Software Foundation, Inc.
2 Contributed by Richard Henderson <rth@cygnus.com>.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
25 /* Locate the FDE entry for a given address, using glibc ld.so routines
26 to avoid register/deregister calls at DSO load/unload. */
35 #include "unwind-ia64.h"
37 #if __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 2) \
38 || (__GLIBC__ == 2 && __GLIBC_MINOR__ == 2 && !defined(DT_CONFIG))
39 # error You need GLIBC 2.2.4 or later on IA-64 Linux
42 struct unw_ia64_callback_data
45 unsigned long *segment_base
;
47 struct unw_table_entry
*ret
;
51 _Unwind_IteratePhdrCallback (struct dl_phdr_info
*info
, size_t size
, void *ptr
)
53 struct unw_ia64_callback_data
*data
= (struct unw_ia64_callback_data
*) ptr
;
54 const Elf64_Phdr
*phdr
, *p_unwind
, *p_dynamic
;
56 Elf64_Addr load_base
, seg_base
;
57 struct unw_table_entry
*f_base
, *f
;
60 /* Make sure struct dl_phdr_info is at least as big as we need. */
61 if (size
< offsetof (struct dl_phdr_info
, dlpi_phnum
)
62 + sizeof (info
->dlpi_phnum
))
66 phdr
= info
->dlpi_phdr
;
67 load_base
= info
->dlpi_addr
;
70 seg_base
= ~(Elf64_Addr
) 0;
72 /* See if PC falls into one of the loaded segments. Find the unwind
73 segment at the same time. */
74 for (n
= info
->dlpi_phnum
; --n
>= 0; phdr
++)
76 if (phdr
->p_type
== PT_LOAD
)
78 Elf64_Addr vaddr
= phdr
->p_vaddr
+ load_base
;
79 if (data
->pc
>= vaddr
&& data
->pc
< vaddr
+ phdr
->p_memsz
)
84 else if (phdr
->p_type
== PT_IA_64_UNWIND
)
86 else if (phdr
->p_type
== PT_DYNAMIC
)
89 if (!match
|| !p_unwind
)
92 /* Search for the FDE within the unwind segment. */
94 f_base
= (struct unw_table_entry
*) (p_unwind
->p_vaddr
+ load_base
);
96 hi
= p_unwind
->p_memsz
/ sizeof (struct unw_table_entry
);
100 size_t mid
= (lo
+ hi
) / 2;
103 if (data
->pc
< f
->start_offset
+ seg_base
)
105 else if (data
->pc
>= f
->end_offset
+ seg_base
)
110 /* No need to search for further libraries when we know pc is contained
115 *data
->segment_base
= seg_base
;
121 /* For dynamically linked executables and shared libraries,
122 DT_PLTGOT is the gp value for that object. */
123 Elf64_Dyn
*dyn
= (Elf64_Dyn
*)(p_dynamic
->p_vaddr
+ load_base
);
124 for (; dyn
->d_tag
!= DT_NULL
; dyn
++)
125 if (dyn
->d_tag
== DT_PLTGOT
)
127 /* On IA-64, _DYNAMIC is writable and GLIBC has relocated it. */
128 *data
->gp
= dyn
->d_un
.d_ptr
;
134 /* Otherwise this is a static executable with no _DYNAMIC.
135 The gp is constant program-wide. */
136 register unsigned long gp
__asm__("gp");
143 /* Return a pointer to the unwind table entry for the function
146 struct unw_table_entry
*
147 _Unwind_FindTableEntry (void *pc
, unsigned long *segment_base
,
149 struct unw_table_entry
*ent ATTRIBUTE_UNUSED
)
151 struct unw_ia64_callback_data data
;
153 data
.pc
= (Elf64_Addr
) pc
;
154 data
.segment_base
= segment_base
;
158 if (dl_iterate_phdr (_Unwind_IteratePhdrCallback
, &data
) < 0)