Previously this was incorrectly assumed to be an ULEB128. Hilarity ensued.
This appears to be the case in both DWARF 3, DWARF 4, and LSB 5. --- src/readelf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/readelf.c b/src/readelf.c index 5f6e4ed..7c3237f 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -4971,7 +4971,7 @@ print_cfa_program (const unsigned char *readp, const unsigned char *const endp, case DW_CFA_set_loc: if ((uint64_t) (endp - readp) < 1) goto invalid; - get_uleb128 (op1, readp, endp); + op1 = read_addr_unaligned_inc (ptr_size, dbg, readp); op1 += vma_base; printf (" set_loc %" PRIu64 "\n", op1 * code_align); break;
On 11/25/2015 08:00 AM, Ben Gamari wrote:
Previously this was incorrectly assumed to be an ULEB128. Hilarity ensued.
Is the error visible in any testcase? Or can you add a test?
This appears to be the case in both DWARF 3, DWARF 4, and LSB 5.
src/readelf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/readelf.c b/src/readelf.c index 5f6e4ed..7c3237f 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -4971,7 +4971,7 @@ print_cfa_program (const unsigned char *readp, const unsigned char *const endp, case DW_CFA_set_loc: if ((uint64_t) (endp - readp) < 1) goto invalid;
get_uleb128 (op1, readp, endp);
op1 = read_addr_unaligned_inc (ptr_size, dbg, readp); op1 += vma_base; printf (" set_loc %" PRIu64 "\n", op1 * code_align); break;
Josh Stone jistone@redhat.com writes:
On 11/25/2015 08:00 AM, Ben Gamari wrote:
Previously this was incorrectly assumed to be an ULEB128. Hilarity ensued.
Is the error visible in any testcase? Or can you add a test?
I didn't see any effect on any existing tests. New test coming.
Cheers,
- Ben
This was derived from the following testsuite extract from output from the Glasgow Haskell Compiler,
.section .text _c2JJ: nop _c2JP: nop _c2K0: nop _c2KN: nop _c2KZ: nop _c2L3: nop .La2_r2HX_info_end: nop a2_r2HX_info: nop .LMain.ffiTest_info_end: nop Main.ffiTest_info: nop .Lsat_s2Ip_info_end: nop sat_s2Ip_info: nop
.section .debug_frame,"",@progbits .Lsection_frame: _n2PT: .long .Ln2PT_end-.Ln2PT_start .Ln2PT_start: .long -1 .byte 3 .asciz "S" .byte 1 .byte 120 .byte 16 .byte 12 .byte 6 .byte 0 .byte 144 .byte 0 .byte 8 .byte 7 .byte 20 .byte 6 .byte 0 .align 8 .Ln2PT_end: .long .La2_r2HX_info_fde_end-.La2_r2HX_info_fde .La2_r2HX_info_fde: .long _n2PT .quad a2_r2HX_info-1 .quad .La2_r2HX_info_end-a2_r2HX_info+1 .byte 1 .quad _c2JJ .byte 14 .byte 16 .byte 1 .quad _c2JP .byte 14 .byte 0 .byte 1 .quad _c2K0-1 .byte 14 .byte 8 .align 8 .La2_r2HX_info_fde_end: .long .LMain.ffiTest_info_fde_end-.LMain.ffiTest_info_fde .LMain.ffiTest_info_fde: .long _n2PT .quad Main.ffiTest_info-1 .quad .LMain.ffiTest_info_end-Main.ffiTest_info+1 .align 8 .LMain.ffiTest_info_fde_end: .long .Lsat_s2Ip_info_fde_end-.Lsat_s2Ip_info_fde .Lsat_s2Ip_info_fde: .long _n2PT .quad sat_s2Ip_info-1 .quad .Lsat_s2Ip_info_end-sat_s2Ip_info+1 .byte 1 .quad _c2KN .byte 14 .byte 8 .byte 1 .quad _c2KZ .byte 14 .byte 0 .byte 1 .quad _c2L3 .byte 14 .byte 8 .align 8 .Lsat_s2Ip_info_fde_end: --- tests/Makefile.am | 3 +- tests/run-readelf-test5.sh | 88 +++++++++++++++++++++++++++++++++++++++++++++ tests/testfile72 | Bin 0 -> 2640 bytes 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100755 tests/run-readelf-test5.sh create mode 100644 tests/testfile72
diff --git a/tests/Makefile.am b/tests/Makefile.am index e04707c..1220a20 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -88,7 +88,8 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \ run-find-prologues.sh run-allregs.sh run-addrcfi.sh \ run-nm-self.sh run-readelf-self.sh \ run-readelf-test1.sh run-readelf-test2.sh run-readelf-test3.sh \ - run-readelf-test4.sh run-readelf-twofiles.sh \ + run-readelf-test4.sh run-readelf-test5.sh \ + run-readelf-twofiles.sh \ run-readelf-macro.sh run-readelf-loc.sh \ run-readelf-aranges.sh run-readelf-line.sh \ run-native-test.sh run-bug1-test.sh \ diff --git a/tests/run-readelf-test5.sh b/tests/run-readelf-test5.sh new file mode 100755 index 0000000..9cf1ebf --- /dev/null +++ b/tests/run-readelf-test5.sh @@ -0,0 +1,88 @@ +#! /bin/sh +# Copyright (C) 2007 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 the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# 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 this program. If not, see http://www.gnu.org/licenses/. + +. $srcdir/test-subr.sh + +testfiles testfile72 + +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=frames testfile72 <<\EOF + +DWARF section [ 4] '.debug_frame' at offset 0x50: + + [ 0] CIE length=20 + CIE_id: 18446744073709551615 + version: 3 + augmentation: "S" + code_alignment_factor: 1 + data_alignment_factor: -8 + return_address_register: 16 + + Program: + def_cfa r6 (rbp) at offset 0 + offset r16 (rip) at cfa+0 + same_value r7 (rsp) + val_offset 6 at offset 0 + + [ 18] FDE length=60 cie=[ 0] + CIE_pointer: 0 + initial_location: .text+0x0000000000000006 <_c2L3+0x1> + address_range: 0 + + Program: + set_loc 0x0 + def_cfa_offset 16 + set_loc 0x1 + def_cfa_offset 0 + set_loc 0x1 + def_cfa_offset 8 + nop + nop + nop + nop + nop + nop + nop + + [ 58] FDE length=20 cie=[ 0] + CIE_pointer: 0 + initial_location: .text+0x0000000000000008 <a2_r2HX_info+0x1> + address_range: 0 + + Program: + + [ 70] FDE length=60 cie=[ 0] + CIE_pointer: 0 + initial_location: .text+0x000000000000000a <Main.ffiTest_info+0x1> + address_range: 0 + + Program: + set_loc 0x3 + def_cfa_offset 8 + set_loc 0x4 + def_cfa_offset 0 + set_loc 0x5 + def_cfa_offset 8 + nop + nop + nop + nop + nop + nop + nop +EOF + +exit 0 diff --git a/tests/testfile72 b/tests/testfile72 new file mode 100644 index 0000000000000000000000000000000000000000..02c3c4da544c88dc8d79d348c7801ce3ffa1a4b6 GIT binary patch literal 2640 zcmbW3&rcIk5XWb`T8cs~!a;+H)r9DQY+;QzB_;kq5U>$Uh%qT!*+P?2NOv*yr17K| z!@;{(kNgQ9{WJVOJm}1OGy7vGn)pcHoA-G$^L>5ucFVg*tB(tg1JWE=fOIAlpixZi zx-siefpIv_G{RH(`Hjup0B2AcE5b39My85z&%~VW60LG2HPaoGOB_OZhqZs_E&Vm` zeN0+_Y3v>6S9u(Ja~K%oz+T6TtmbGzw5M*St>B>hvPnS8sgO9+Xp+<p4&z!lIIM-; z_EFsFMzuJM;s}=3UsM-2s=nvn_2$8O?@U0YIN@A&+|qPurZjmzo5|R-*xSv>$yk@M zQ=SaG=<R+Sw7`qvz8&|(io-z+-cAq);I*O%ynfgXyq&OhwA*a=gZ(f^x}9Dgbb9Rr z3^(pUtJM$R<ottv(Ay390MFW;;ci;*oS)0zGzW3w;-7A|$VsV_<q>0Hp%P+^app;3 zd3}<(R=CRi9Q(;|ow=^m40Ee5-T*%H(G(f$A@hrh)6@m63h><co#xg*e>aS)$#X%> z+~`8);m)kMFl0B)*Z#^1P~V{b>741;P5+Ym)jJUQ&A$I+t7&e?TF~iv?RIAqZ@eW@ z5H}-#`OwaqJ-@LD*I1W!Xlr9Zl{wXqKC;t!#d(^%XT)FXzNGwxzhbU+x0Sz~XncnM zK>5o_e^OlT)fdI3l3x{<dv#lJo+jr(dKG~<%KL!$M23rxoR2JBVMDmY%Xw3tOX7^< zS$Q%p|7DstF-D56B&o9@`w}j7l=%%bh{-t%Ull`*I{p@}Q?36up6;d2Ns<lfu$|Z; z>E&Jtm_>u`LR|olANhh*Ie8g5A&HmzJwP^0U*IC=lR^6~;KDHdZ+sC&hxDmNT7MIn z&WQ*X8LrVJ)3on1TpOnUo%Odlmh?$m>(jc<i3mP3)c;3lU;4e$jN(ri&e0^(<T()3 zLu1(ft9+p)p7u{~SG|9FR`uOO1V35-15Gkb@0I5IH;vr)82;b@dY0+8PV3X}(lGrw N`cl}o?2z<Y{|`Qng6#kR
literal 0 HcmV?d00001
Ben Gamari ben@smart-cactus.org writes:
This was derived from the following testsuite extract from output from the Glasgow Haskell Compiler,
Is there any value in including the original assembler source here? If so, is there a better place than the commit message?
Cheers,
- Ben
On Wed, 2015-11-25 at 23:39 +0100, Ben Gamari wrote:
Ben Gamari ben@smart-cactus.org writes:
This was derived from the following testsuite extract from output from the Glasgow Haskell Compiler,
Is there any value in including the original assembler source here? If so, is there a better place than the commit message?
Please put it in the new run-readelf-test5.sh file as a comment just before the testfiles testfile72 line. That makes it easy for someone looking at that test to know how to regenerate the testfile if they want to.
Thanks,
Mark
On Wed, 2015-11-25 at 17:00 +0100, Ben Gamari wrote:
Previously this was incorrectly assumed to be an ULEB128. Hilarity ensued.
This appears to be the case in both DWARF 3, DWARF 4, and LSB 5.
Nice catch. Interestingly we seem to handle this correctly in cfi.c, but not eu-readelf. But note that DWARF and the LSB eh_frame extension are slightly different. For DWARF .debug_frame this is indeed a "plain" address and your read_addr_unaligned_inc call is correct. But for LSB .eh_frame addresses are "encoded" and you should call read_encoded using the fde_encoding. It looks like fde_encoding isn't passed to print_cfa_program, so we should probably pass it from print_debug_frame_section.
It appears that there is no testfile which uses DW_CFA_set_loc. If you happen to have one that would be nice to add.
Do you want to combine this with the other patch for printing set_loc? Could you add a ChangeLog entry and Signed-off-by line for your patch as described in the CONTRIBUTING document: https://git.fedorahosted.org/cgit/elfutils.git/plain/CONTRIBUTING
Thanks,
Mark
Mark Wielaard mjw@redhat.com writes:
On Wed, 2015-11-25 at 17:00 +0100, Ben Gamari wrote:
Previously this was incorrectly assumed to be an ULEB128. Hilarity ensued.
This appears to be the case in both DWARF 3, DWARF 4, and LSB 5.
Nice catch. Interestingly we seem to handle this correctly in cfi.c, but not eu-readelf. But note that DWARF and the LSB eh_frame extension are slightly different. For DWARF .debug_frame this is indeed a "plain" address and your read_addr_unaligned_inc call is correct. But for LSB .eh_frame addresses are "encoded" and you should call read_encoded using the fde_encoding. It looks like fde_encoding isn't passed to print_cfa_program, so we should probably pass it from print_debug_frame_section.
It appears that there is no testfile which uses DW_CFA_set_loc. If you happen to have one that would be nice to add.
Do you want to combine this with the other patch for printing set_loc? Could you add a ChangeLog entry and Signed-off-by line for your patch as described in the CONTRIBUTING document: https://git.fedorahosted.org/cgit/elfutils.git/plain/CONTRIBUTING
Oops, sorry about that. I can combine all three of these patches.
Also, I haven't forgotten about the local backtrace support. Your patch nearly works but I've been under a bit of deadline pressure so I've not had much time to commit to the elfutils side of things.
Cheers,
- Ben
elfutils-devel@lists.fedorahosted.org