From: Mark Wielaard Date: Mon, 2 Sep 2013 14:46:50 +0000 (+0200) Subject: backends: Hook abi_cfi for arm. X-Git-Tag: elfutils-0.157~18 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=92e47d616d15beec31c406ce254e639faa8fac2b;p=thirdparty%2Felfutils.git backends: Hook abi_cfi for arm. New arm_abi_cfi that defines initial CFA, rules for callee-saved regs, including VFP ones and return register. Note the DWARF abi extension for ARM says that "registers intentionally unused" should also be initialized as if by DW_CFA_same_value. The example given is "an integer-only function might be included in one executable file for targets with VFP and another for targets without". We don't currently do this yet. See the DWARF and calling convention documents: DWARF for the ARM Architecture ABI r2.09 http://infocenter.arm.com/help/topic/com.arm.doc.ihi0040b/IHI0040B_aadwarf.pdf Procedure Call Standard for the ARM Architecture ABI r2.09 http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042e/IHI0042E_aapcs.pdf Also adds addrcfi arm testcase. Signed-off-by: Mark Wielaard --- diff --git a/backends/ChangeLog b/backends/ChangeLog index 48b1b7b9d..3409010da 100644 --- a/backends/ChangeLog +++ b/backends/ChangeLog @@ -1,3 +1,9 @@ +2013-08-29 Mark Wielaard + + * Makefile.am (arm_SRCS): Add arm_cfi.c. + * arm_cfi.c: New file. + * arm_init.c (arm_init): Initialize abi_cfi. + 2013-08-27 Jan Kratochvil * Makefile.am (ppc_SRCS, ppc64_SRCS): Add ppc_cfi.c. diff --git a/backends/Makefile.am b/backends/Makefile.am index ec022b02c..557ed879f 100644 --- a/backends/Makefile.am +++ b/backends/Makefile.am @@ -75,7 +75,7 @@ libebl_alpha_pic_a_SOURCES = $(alpha_SRCS) am_libebl_alpha_pic_a_OBJECTS = $(alpha_SRCS:.c=.os) arm_SRCS = arm_init.c arm_symbol.c arm_regs.c arm_corenote.c \ - arm_auxv.c arm_attrs.c arm_retval.c + arm_auxv.c arm_attrs.c arm_retval.c arm_cfi.c libebl_arm_pic_a_SOURCES = $(arm_SRCS) am_libebl_arm_pic_a_OBJECTS = $(arm_SRCS:.c=.os) diff --git a/backends/arm_cfi.c b/backends/arm_cfi.c new file mode 100644 index 000000000..e0cc44bf6 --- /dev/null +++ b/backends/arm_cfi.c @@ -0,0 +1,87 @@ +/* arm ABI-specified defaults for DWARF CFI. + Copyright (C) 2013 Red Hat, Inc. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of either + + * the GNU Lesser General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at + your option) any later version + + or + + * the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at + your option) any later version + + or both in parallel, as here. + + 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 copies of the GNU General Public License and + the GNU Lesser General Public License along with this program. If + not, see . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#define BACKEND arm_ +#include "libebl_CPU.h" + + +/* ABI-specified state of DWARF CFI based on: + + "DWARF for the ARM Architecture ABI r2.09" +http://infocenter.arm.com/help/topic/com.arm.doc.ihi0040b/IHI0040B_aadwarf.pdf + + "Procedure Call Standard for the ARM Architecture ABI r2.09" +http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042e/IHI0042E_aapcs.pdf +*/ + +int +arm_abi_cfi (Ebl *ebl __attribute__ ((unused)), Dwarf_CIE *abi_info) +{ + static const uint8_t abi_cfi[] = + { + /* The initial Canonical Frame Address is the value of the + Stack Pointer (r13) as setup in the previous frame. */ + DW_CFA_def_cfa, ULEB128_7 (13), ULEB128_7 (0), + +#define SV(n) DW_CFA_same_value, ULEB128_7 (n) + /* Callee-saved regs r4-r8, r10, r11. */ + SV (4), SV (5), SV (6), SV (7), SV (8), SV (10), SV (11), + + /* The link register contains the return address setup by caller. */ + SV (14), + DW_CFA_register, ULEB128_7 (15), ULEB128_7 (14), /* pc = lr */ +#undef SV + + /* VFP S16-S31/D8-D15/Q4-Q7 are callee saved. + And uleb128 encoded with two bytes. */ +#define ULEB128_8_2(x) ((x & 0x7f) | 0x80), 0x02 +#define SV(n) DW_CFA_same_value, ULEB128_8_2 (n) + SV (264), SV (265), SV (266), SV (267), + SV (268), SV (269), SV (270), SV (271), + + /* XXX Note: registers intentionally unused by the program, + for example as a consequence of the procedure call standard + should be initialized as if by DW_CFA_same_value. */ + }; +#undef ULEB128_8_2 +#undef SV + + abi_info->initial_instructions = abi_cfi; + abi_info->initial_instructions_end = &abi_cfi[sizeof abi_cfi]; + abi_info->data_alignment_factor = 4; + + abi_info->return_address_register = 15; /* pc. */ + + return 0; +} diff --git a/backends/arm_init.c b/backends/arm_init.c index 38bd4eb47..cf661cea6 100644 --- a/backends/arm_init.c +++ b/backends/arm_init.c @@ -1,5 +1,5 @@ /* Initialization of Arm specific backend library. - Copyright (C) 2002, 2005, 2009 Red Hat, Inc. + Copyright (C) 2002, 2005, 2009, 2013 Red Hat, Inc. This file is part of elfutils. Written by Ulrich Drepper , 2002. @@ -62,6 +62,7 @@ arm_init (elf, machine, eh, ehlen) HOOK (eh, auxv_info); HOOK (eh, check_object_attribute); HOOK (eh, return_value_location); + HOOK (eh, abi_cfi); return MODVERSION; } diff --git a/tests/ChangeLog b/tests/ChangeLog index 5871f9d0f..b11f27bd4 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,9 @@ +2013-08-29 Mark Wielaard + + * run-addrcfi.sh: Add case for EM_ARM. + * testfilearm.bz2: New testfile. + * Makefile.am (EXTRA_DIST): Add testfilesarm.bz2. + 2013-08-28 Mark Wielaard * addrcfi.c (handle_cfi): Handle .debug_frame or .eh_frame diff --git a/tests/Makefile.am b/tests/Makefile.am index 8e4f88afb..251ebc4af 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -204,7 +204,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ test-core.exec.bz2 run-addr2line-test.sh \ run-addr2line-i-test.sh testfile-inlines.bz2 \ testfileppc32.bz2 testfileppc64.bz2 \ - testfiles390.bz2 testfiles390x.bz2 + testfiles390.bz2 testfiles390x.bz2 \ + testfilearm.bz2 if USE_VALGRIND valgrind_cmd='valgrind -q --trace-children=yes --error-exitcode=1 --run-libc-freeres=no' diff --git a/tests/run-addrcfi.sh b/tests/run-addrcfi.sh index adf8d8b38..70e85ed7c 100755 --- a/tests/run-addrcfi.sh +++ b/tests/run-addrcfi.sh @@ -2496,3 +2496,79 @@ testrun_compare ${abs_builddir}/addrcfi -e testfiles390x 0x0000000080000510 <<\E control reg65 (%pswa): undefined handle_cfi no CFI (.debug_frame): no error EOF + +# EM_ARM (function bar 0x00008510) +# Note. Only in .debug_frame, the .eh_frame is actually empty. +# Same as s390 and ppc above. +testfiles testfilearm +testrun_compare ${abs_builddir}/addrcfi -e testfilearm 0x00008510 <<\EOF +dwarf_cfi_addrframe (.eh_frame): no matching address range +.debug_frame has 0x8510 => [0x8510, 0x8524): + return address in reg14 + CFA location expression: bregx(13) + integer reg0 (r0): undefined + integer reg1 (r1): undefined + integer reg2 (r2): undefined + integer reg3 (r3): undefined + integer reg4 (r4): same_value + integer reg5 (r5): same_value + integer reg6 (r6): same_value + integer reg7 (r7): same_value + integer reg8 (r8): same_value + integer reg9 (r9): undefined + integer reg10 (r10): same_value + integer reg11 (r11): same_value + integer reg12 (r12): undefined + integer reg13 (sp): undefined + integer reg14 (lr): same_value + integer reg15 (pc): location expression: regx(14) + FPA reg16 (f0): undefined + FPA reg17 (f1): undefined + FPA reg18 (f2): undefined + FPA reg19 (f3): undefined + FPA reg20 (f4): undefined + FPA reg21 (f5): undefined + FPA reg22 (f6): undefined + FPA reg23 (f7): undefined + FPA reg96 (f0): undefined + FPA reg97 (f1): undefined + FPA reg98 (f2): undefined + FPA reg99 (f3): undefined + FPA reg100 (f4): undefined + FPA reg101 (f5): undefined + FPA reg102 (f6): undefined + FPA reg103 (f7): undefined + integer reg128 (spsr): undefined + VFP reg256 (d0): undefined + VFP reg257 (d1): undefined + VFP reg258 (d2): undefined + VFP reg259 (d3): undefined + VFP reg260 (d4): undefined + VFP reg261 (d5): undefined + VFP reg262 (d6): undefined + VFP reg263 (d7): undefined + VFP reg264 (d8): same_value + VFP reg265 (d9): same_value + VFP reg266 (d10): same_value + VFP reg267 (d11): same_value + VFP reg268 (d12): same_value + VFP reg269 (d13): same_value + VFP reg270 (d14): same_value + VFP reg271 (d15): same_value + VFP reg272 (d16): undefined + VFP reg273 (d17): undefined + VFP reg274 (d18): undefined + VFP reg275 (d19): undefined + VFP reg276 (d20): undefined + VFP reg277 (d21): undefined + VFP reg278 (d22): undefined + VFP reg279 (d23): undefined + VFP reg280 (d24): undefined + VFP reg281 (d25): undefined + VFP reg282 (d26): undefined + VFP reg283 (d27): undefined + VFP reg284 (d28): undefined + VFP reg285 (d29): undefined + VFP reg286 (d30): undefined + VFP reg287 (d31): undefined +EOF diff --git a/tests/testfilearm.bz2 b/tests/testfilearm.bz2 new file mode 100755 index 000000000..d6cd090e3 Binary files /dev/null and b/tests/testfilearm.bz2 differ