Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame^] | 1 | From: Mark Wielaard <mjw@redhat.com> |
| 2 | Date: Sun, 15 Jun 2014 11:30:35 +0200 |
| 3 | Subject: libebl: Add sym_func_value hook. |
| 4 | |
| 5 | The ARM EABI says that the zero bit of function symbol st_value indicates |
| 6 | whether the symbol points to a THUMB or ARM function. Add a new ebl hook |
| 7 | to adjust the st_value in such a case so that we get the actual value that |
| 8 | the symbol points to. It isn't easily possible to reuse the existing |
| 9 | resolve_sym_value for this purpose, so we end up with another hook that |
| 10 | can be used from dwfl_module_getsym and elflint. |
| 11 | |
| 12 | Rebase arm_func_value.patch from 0.159 to 0.160 |
| 13 | Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com> |
| 14 | --- |
| 15 | backends/arm_init.c | 1 + |
| 16 | backends/arm_symbol.c | 8 ++++++++ |
| 17 | libdwfl/dwfl_module_getsym.c | 2 +- |
| 18 | libebl/Makefile.am | 3 ++- |
| 19 | libebl/ebl-hooks.h | 3 +++ |
| 20 | libebl/eblsymfuncval.c | 43 ++++++++++++++++++++++++++++++++++++++++++ |
| 21 | libebl/libebl.h | 11 +++++++++++ |
| 22 | 7 files changed, 69 insertions(+), 2 deletions(-) |
| 23 | |
| 24 | diff --git a/backends/arm_init.c b/backends/arm_init.c |
| 25 | index 7171186..9f03630 100644 |
| 26 | --- a/backends/arm_init.c |
| 27 | +++ b/backends/arm_init.c |
| 28 | @@ -78,6 +78,7 @@ arm_init (elf, machine, eh, ehlen) |
| 29 | eh->return_value_location = arm_return_value_location_hard; |
| 30 | HOOK (eh, abi_cfi); |
| 31 | HOOK (eh, check_reloc_target_type); |
| 32 | + HOOK (eh, sym_func_value); |
| 33 | HOOK (eh, symbol_type_name); |
| 34 | |
| 35 | /* We only unwind the core integer registers. */ |
| 36 | diff --git a/backends/arm_symbol.c b/backends/arm_symbol.c |
| 37 | index da4a50a..ccea03b 100644 |
| 38 | --- a/backends/arm_symbol.c |
| 39 | +++ b/backends/arm_symbol.c |
| 40 | @@ -130,6 +130,14 @@ arm_check_reloc_target_type (Ebl *ebl __attribute__ ((unused)), Elf64_Word sh_ty |
| 41 | return sh_type == SHT_ARM_EXIDX; |
| 42 | } |
| 43 | |
| 44 | +/* ARM EABI says that the low bit indicates whether the function |
| 45 | + symbol value is a THUMB function or not. Mask it off. */ |
| 46 | +GElf_Addr |
| 47 | +arm_sym_func_value (Ebl *ebl __attribute__ ((unused)), GElf_Addr val) |
| 48 | +{ |
| 49 | + return val & ~(GElf_Addr)1; |
| 50 | +} |
| 51 | + |
| 52 | const char * |
| 53 | arm_symbol_type_name (int type, |
| 54 | char *buf __attribute__ ((unused)), |
| 55 | diff --git a/libdwfl/dwfl_module_getsym.c b/libdwfl/dwfl_module_getsym.c |
| 56 | index 42d2b67..fb192d7 100644 |
| 57 | --- a/libdwfl/dwfl_module_getsym.c |
| 58 | +++ b/libdwfl/dwfl_module_getsym.c |
| 59 | @@ -119,7 +119,7 @@ __libdwfl_getsym (Dwfl_Module *mod, int ndx, GElf_Sym *sym, GElf_Addr *addr, |
| 60 | descriptors). */ |
| 61 | |
| 62 | char *ident; |
| 63 | - GElf_Addr st_value = sym->st_value & ebl_func_addr_mask (mod->ebl); |
| 64 | + GElf_Addr st_value = ebl_sym_func_value (mod->ebl, sym->st_value); |
| 65 | *resolved = false; |
| 66 | if (! adjust_st_value && mod->e_type != ET_REL && alloc |
| 67 | && (GELF_ST_TYPE (sym->st_info) == STT_FUNC |
| 68 | diff --git a/libebl/Makefile.am b/libebl/Makefile.am |
| 69 | index ec4477b..889c21b 100644 |
| 70 | --- a/libebl/Makefile.am |
| 71 | +++ b/libebl/Makefile.am |
| 72 | @@ -55,7 +55,8 @@ gen_SOURCES = eblopenbackend.c eblclosebackend.c eblstrtab.c \ |
| 73 | eblsysvhashentrysize.c eblauxvinfo.c eblcheckobjattr.c \ |
| 74 | ebl_check_special_section.c ebl_syscall_abi.c eblabicfi.c \ |
| 75 | eblstother.c eblinitreg.c ebldwarftoregno.c eblnormalizepc.c \ |
| 76 | - eblunwind.c eblresolvesym.c eblcheckreloctargettype.c |
| 77 | + eblunwind.c eblresolvesym.c eblcheckreloctargettype.c \ |
| 78 | + eblsymfuncval.c |
| 79 | |
| 80 | libebl_a_SOURCES = $(gen_SOURCES) |
| 81 | |
| 82 | diff --git a/libebl/ebl-hooks.h b/libebl/ebl-hooks.h |
| 83 | index 2e31446..9df945d 100644 |
| 84 | --- a/libebl/ebl-hooks.h |
| 85 | +++ b/libebl/ebl-hooks.h |
| 86 | @@ -191,5 +191,8 @@ bool EBLHOOK(unwind) (Ebl *ebl, Dwarf_Addr pc, ebl_tid_registers_t *setfunc, |
| 87 | (e.g. function descriptor resolving) */ |
| 88 | bool EBLHOOK(resolve_sym_value) (Ebl *ebl, GElf_Addr *addr); |
| 89 | |
| 90 | +/* Returns the real value of a symbol function address or offset. */ |
| 91 | +GElf_Addr EBLHOOK(sym_func_value) (Ebl *ebl, GElf_Addr val); |
| 92 | + |
| 93 | /* Destructor for ELF backend handle. */ |
| 94 | void EBLHOOK(destr) (struct ebl *); |
| 95 | diff --git a/libebl/eblsymfuncval.c b/libebl/eblsymfuncval.c |
| 96 | new file mode 100644 |
| 97 | index 0000000..c0b322f |
| 98 | --- /dev/null |
| 99 | +++ b/libebl/eblsymfuncval.c |
| 100 | @@ -0,0 +1,43 @@ |
| 101 | +/* Turn a symbol function value into a real function address or offset. |
| 102 | + Copyright (C) 2014 Red Hat, Inc. |
| 103 | + This file is part of elfutils. |
| 104 | + |
| 105 | + This file is free software; you can redistribute it and/or modify |
| 106 | + it under the terms of either |
| 107 | + |
| 108 | + * the GNU Lesser General Public License as published by the Free |
| 109 | + Software Foundation; either version 3 of the License, or (at |
| 110 | + your option) any later version |
| 111 | + |
| 112 | + or |
| 113 | + |
| 114 | + * the GNU General Public License as published by the Free |
| 115 | + Software Foundation; either version 2 of the License, or (at |
| 116 | + your option) any later version |
| 117 | + |
| 118 | + or both in parallel, as here. |
| 119 | + |
| 120 | + elfutils is distributed in the hope that it will be useful, but |
| 121 | + WITHOUT ANY WARRANTY; without even the implied warranty of |
| 122 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 123 | + General Public License for more details. |
| 124 | + |
| 125 | + You should have received copies of the GNU General Public License and |
| 126 | + the GNU Lesser General Public License along with this program. If |
| 127 | + not, see <http://www.gnu.org/licenses/>. */ |
| 128 | + |
| 129 | +#ifdef HAVE_CONFIG_H |
| 130 | +# include <config.h> |
| 131 | +#endif |
| 132 | + |
| 133 | +#include <libeblP.h> |
| 134 | +#include <assert.h> |
| 135 | + |
| 136 | +GElf_Addr |
| 137 | +ebl_sym_func_value (Ebl *ebl, GElf_Addr val) |
| 138 | +{ |
| 139 | + if (ebl == NULL || ebl->sym_func_value == NULL) |
| 140 | + return val; |
| 141 | + |
| 142 | + return ebl->sym_func_value (ebl, val); |
| 143 | +} |
| 144 | diff --git a/libebl/libebl.h b/libebl/libebl.h |
| 145 | index 7dbf460..96c076b 100644 |
| 146 | --- a/libebl/libebl.h |
| 147 | +++ b/libebl/libebl.h |
| 148 | @@ -472,6 +472,17 @@ extern bool ebl_unwind (Ebl *ebl, Dwarf_Addr pc, ebl_tid_registers_t *setfunc, |
| 149 | extern bool ebl_resolve_sym_value (Ebl *ebl, GElf_Addr *addr) |
| 150 | __nonnull_attribute__ (2); |
| 151 | |
| 152 | +/* Returns the real value of a symbol function address or offset |
| 153 | + (e.g. when the st_value contains some flag bits that need to be |
| 154 | + masked off). This is different from ebl_resolve_sym_value which |
| 155 | + only works for actual symbol addresses (in non-ET_REL files) that |
| 156 | + might resolve to an address in a different section. |
| 157 | + ebl_sym_func_value is called to turn the given value into the a |
| 158 | + real address or offset (the original value might not be a real |
| 159 | + address). This works for both ET_REL when the value is a section |
| 160 | + offset or ET_EXEC or ET_DYN symbol values, which are addresses. */ |
| 161 | +extern GElf_Addr ebl_sym_func_value (Ebl *ebl, GElf_Addr val); |
| 162 | + |
| 163 | #ifdef __cplusplus |
| 164 | } |
| 165 | #endif |