diff options
author | Roland McGrath <roland@redhat.com> | 2009-06-24 17:41:40 -0700 |
---|---|---|
committer | Roland McGrath <roland@redhat.com> | 2009-07-08 15:15:52 -0700 |
commit | 3c84db3b4b610bf636c4363abb6d3dac5ae020f9 (patch) | |
tree | e0af0c5a7f27a3f06a66353a3da9bec0bd7bd32f /libebl | |
parent | fe8b42e6131b74829fe31d15f31349cade566a59 (diff) | |
download | elfutils-3c84db3b4b610bf636c4363abb6d3dac5ae020f9.tar.gz |
CFI support: lookup by PC and translate into DWARF location per register
Diffstat (limited to 'libebl')
-rw-r--r-- | libebl/ChangeLog | 9 | ||||
-rw-r--r-- | libebl/Makefile.am | 4 | ||||
-rw-r--r-- | libebl/ebl-hooks.h | 4 | ||||
-rw-r--r-- | libebl/eblabicfi.c | 63 | ||||
-rw-r--r-- | libebl/eblopenbackend.c | 11 | ||||
-rw-r--r-- | libebl/libebl.h | 34 | ||||
-rw-r--r-- | libebl/libeblP.h | 8 |
7 files changed, 127 insertions, 6 deletions
diff --git a/libebl/ChangeLog b/libebl/ChangeLog index 12e94f42..837a4d16 100644 --- a/libebl/ChangeLog +++ b/libebl/ChangeLog @@ -1,3 +1,12 @@ +2009-07-08 Roland McGrath <roland@redhat.com> + + * ebl-hooks.h: Add abi_cfi hook. + * eblopenbackend.c (default_abi_cfi): New function. + (fill_defaults): Add initializer. + * eblabicfi.c: New file. + * Makefile.am (gen_SOURCES): Add it. + * libebl.h: Declare ebl_abi_cfi. + 2009-07-08 Ulrich Drepper <drepper@redhat.com> * eblsymbolbindingname.c (ebl_symbol_binding_name): Handle diff --git a/libebl/Makefile.am b/libebl/Makefile.am index c4e4a076..a95e66d6 100644 --- a/libebl/Makefile.am +++ b/libebl/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to create Makefile.in ## -## Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007,2008 Red Hat, Inc. +## Copyright (C) 2000-2009 Red Hat, Inc. ## This file is part of Red Hat elfutils. ## ## Red Hat elfutils is free software; you can redistribute it and/or modify @@ -59,7 +59,7 @@ gen_SOURCES = eblopenbackend.c eblclosebackend.c eblstrtab.c \ ebl_check_special_symbol.c eblbsspltp.c eblretval.c \ eblreginfo.c eblnonerelocp.c eblrelativerelocp.c \ eblsysvhashentrysize.c eblauxvinfo.c eblcheckobjattr.c \ - ebl_check_special_section.c ebl_syscall_abi.c + ebl_check_special_section.c ebl_syscall_abi.c eblabicfi.c libebl_a_SOURCES = $(gen_SOURCES) diff --git a/libebl/ebl-hooks.h b/libebl/ebl-hooks.h index 2db1e208..d483f2a3 100644 --- a/libebl/ebl-hooks.h +++ b/libebl/ebl-hooks.h @@ -1,5 +1,5 @@ /* Backend hook signatures internal interface for libebl. - Copyright (C) 2000,2001,2002,2004,2005,2006,2007,2008 Red Hat, Inc. + Copyright (C) 2000-2009 Red Hat, Inc. This file is part of Red Hat elfutils. Red Hat elfutils is free software; you can redistribute it and/or modify @@ -167,6 +167,8 @@ int EBLHOOK(disasm) (const uint8_t **startp, const uint8_t *end, GElf_Addr addr, const char *fmt, DisasmOutputCB_t outcb, DisasmGetSymCB_t symcb, void *outcbarg, void *symcbarg); +/* Supply the machine-specific state of CFI before CIE initial programs. */ +int EBLHOOK(abi_cfi) (Ebl *ebl, Dwarf_CIE *abi_info); /* Destructor for ELF backend handle. */ void EBLHOOK(destr) (struct ebl *); diff --git a/libebl/eblabicfi.c b/libebl/eblabicfi.c new file mode 100644 index 00000000..221e83fc --- /dev/null +++ b/libebl/eblabicfi.c @@ -0,0 +1,63 @@ +/* Return ABI-specific DWARF CFI details. + Copyright (C) 2009 Red Hat, Inc. + This file is part of Red Hat elfutils. + + Red Hat elfutils is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by the + Free Software Foundation; version 2 of the License. + + Red Hat elfutils is distributed in the hope that it will be useful, 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. + + You should have received a copy of the GNU General Public License along + with Red Hat elfutils; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA. + + In addition, as a special exception, Red Hat, Inc. gives You the + additional right to link the code of Red Hat elfutils with code licensed + under any Open Source Initiative certified open source license + (http://www.opensource.org/licenses/index.php) which requires the + distribution of source code with any binary distribution and to + distribute linked combinations of the two. Non-GPL Code permitted under + this exception must only link to the code of Red Hat elfutils through + those well defined interfaces identified in the file named EXCEPTION + found in the source code files (the "Approved Interfaces"). The files + of Non-GPL Code may instantiate templates or use macros or inline + functions from the Approved Interfaces without causing the resulting + work to be covered by the GNU General Public License. Only Red Hat, + Inc. may make changes or additions to the list of Approved Interfaces. + Red Hat's grant of this exception is conditioned upon your not adding + any new exceptions. If you wish to add a new Approved Interface or + exception, please contact Red Hat. You must obey the GNU General Public + License in all respects for all of the Red Hat elfutils code and other + code used in conjunction with Red Hat elfutils except the Non-GPL Code + covered by this exception. If you modify this file, you may extend this + exception to your version of the file, but you are not obligated to do + so. If you do not wish to provide this exception without modification, + you must delete this exception statement from your version and license + this file solely under the GPL without exception. + + Red Hat elfutils is an included package of the Open Invention Network. + An included package of the Open Invention Network is a package for which + Open Invention Network licensees cross-license their patents. No patent + license is granted, either expressly or impliedly, by designation as an + included package. Should you wish to participate in the Open Invention + Network licensing program, please visit www.openinventionnetwork.com + <http://www.openinventionnetwork.com>. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <libeblP.h> + + +int +ebl_abi_cfi (ebl, abi_info) + Ebl *ebl; + Dwarf_CIE *abi_info; +{ + return ebl == NULL ? -1 : ebl->abi_cfi (ebl, abi_info); +} diff --git a/libebl/eblopenbackend.c b/libebl/eblopenbackend.c index 8cf42189..cb17f03f 100644 --- a/libebl/eblopenbackend.c +++ b/libebl/eblopenbackend.c @@ -1,5 +1,5 @@ /* Generate ELF backend handle. - Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007,2008 Red Hat, Inc. + Copyright (C) 2000-2009 Red Hat, Inc. This file is part of Red Hat elfutils. Red Hat elfutils is free software; you can redistribute it and/or modify @@ -218,6 +218,7 @@ static bool default_check_object_attribute (Ebl *ebl, const char *vendor, int tag, uint64_t value, const char **tag_name, const char **value_name); +static int default_abi_cfi (Ebl *ebl, Dwarf_CIE *abi_info); static void @@ -258,6 +259,7 @@ fill_defaults (Ebl *result) result->syscall_abi = default_syscall_abi; result->check_object_attribute = default_check_object_attribute; result->disasm = NULL; + result->abi_cfi = default_abi_cfi; result->destr = default_destr; result->sysvhash_entrysize = sizeof (Elf32_Word); } @@ -746,3 +748,10 @@ default_check_object_attribute (Ebl *ebl __attribute__ ((unused)), *value_name = NULL; return false; } + +static int +default_abi_cfi (Ebl *ebl __attribute__ ((unused)), + Dwarf_CIE *abi_info __attribute__ ((unused))) +{ + return 0; +} diff --git a/libebl/libebl.h b/libebl/libebl.h index 50258690..1a56b966 100644 --- a/libebl/libebl.h +++ b/libebl/libebl.h @@ -1,5 +1,5 @@ /* Interface for libebl. - Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008 Red Hat, Inc. + Copyright (C) 2000, 2001-2009 Red Hat, Inc. This file is part of Red Hat elfutils. Red Hat elfutils is free software; you can redistribute it and/or modify @@ -256,6 +256,38 @@ extern ssize_t ebl_register_info (Ebl *ebl, extern int ebl_syscall_abi (Ebl *ebl, int *sp, int *pc, int *callno, int args[6]); +/* Supply the ABI-specified state of DWARF CFI before CIE initial programs. + + The DWARF 3.0 spec says that the default initial states of all registers + are "undefined", unless otherwise specified by the machine/compiler ABI. + + This default is wrong for every machine with the CFI generated by GCC. + The EH unwinder does not really distinguish "same_value" and "undefined", + since it doesn't matter for unwinding (in either case there is no change + to make for that register). GCC generates CFI that says nothing at all + about registers it hasn't spilled somewhere. For our unwinder to give + the true story, the backend must supply an initial state that uses + "same_value" rules for all the callee-saves registers. + + This can fill in the initial_instructions, initial_instructions_end + members of *ABI_INFO to point at a CFI instruction stream to process + before each CIE's initial instructions. It should set the + data_alignment_factor member if it affects the initial instructions. + + As a shorthand for some common cases, for this instruction stream + we overload some CFI instructions that cannot be used in a CIE: + + DW_CFA_restore -- Change default rule for all unmentioned + registers from undefined to same_value. + + This function can also fill in ABI_INFO->return_address_register with the + DWARF register number that identifies the actual PC in machine state. + If there is no canonical DWARF register number with that meaning, it's + left unchanged (callers usually initialize with (Dwarf_Word) -1). + This value is not used by CFI per se. */ +extern int ebl_abi_cfi (Ebl *ebl, Dwarf_CIE *abi_info) + __nonnull_attribute__ (2); + /* ELF string table handling. */ struct Ebl_Strtab; struct Ebl_Strent; diff --git a/libebl/libeblP.h b/libebl/libeblP.h index 7bfa650f..32a43728 100644 --- a/libebl/libeblP.h +++ b/libebl/libeblP.h @@ -1,5 +1,5 @@ /* Internal definitions for interface for libebl. - Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006 Red Hat, Inc. + Copyright (C) 2000-2009 Red Hat, Inc. This file is part of Red Hat elfutils. Red Hat elfutils is free software; you can redistribute it and/or modify @@ -94,4 +94,10 @@ typedef const char *(*ebl_bhinit_t) (Elf *, GElf_Half, Ebl *, size_t); #undef _ #define _(Str) dgettext ("elfutils", Str) + +/* LEB128 constant helper macros. */ +#define ULEB128_7(x) (BUILD_BUG_ON_ZERO ((x) >= (1U << 7)) + (x)) + +#define BUILD_BUG_ON_ZERO(x) (sizeof (char [(x) ? -1 : 1]) - 1) + #endif /* libeblP.h */ |