From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.efficios.com (mail.efficios.com [167.114.26.124]) by sourceware.org (Postfix) with ESMTPS id B83A03858D28 for ; Thu, 18 Aug 2022 17:34:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B83A03858D28 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 4E294395494; Thu, 18 Aug 2022 13:34:20 -0400 (EDT) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id z5etMIeiC18c; Thu, 18 Aug 2022 13:34:19 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 785AB395490; Thu, 18 Aug 2022 13:34:19 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 785AB395490 X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id cPXhKfI34Bu0; Thu, 18 Aug 2022 13:34:19 -0400 (EDT) Received: from [172.16.0.95] (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) by mail.efficios.com (Postfix) with ESMTPSA id 4F71E39548F; Thu, 18 Aug 2022 13:34:19 -0400 (EDT) Message-ID: Date: Thu, 18 Aug 2022 13:34:18 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v3] gdb: call check_typedef at beginning of dwarf_expr_context::fetch_result Content-Language: fr To: Luis Machado , Simon Marchi , gdb-patches@sourceware.org References: <20220728153340.4052079-1-simon.marchi@efficios.com> <5ed77384-970f-3e97-0e66-bce2acd28f9a@polymtl.ca> <5bc46c80-545a-a530-8379-b1deb860075d@arm.com> From: Simon Marchi In-Reply-To: <5bc46c80-545a-a530-8379-b1deb860075d@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3033.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Aug 2022 17:34:22 -0000 On 8/18/22 12:51, Luis Machado wrote: > On 8/18/22 17:16, Simon Marchi via Gdb-patches wrote: >> On 7/28/22 11:33, Simon Marchi wrote: >>> From: Simon Marchi >>> >>> New in this version: >>> >>> - add architecture check in test >>> - add aarch64 version of the .S >>> >>> Bug 29374 shows this crash: >>> >>> $ ./gdb -nx --data-directory=data-directory -q -batch -ex "catch throw" -ex r -ex bt a.out >>> ... >>> /home/simark/src/binutils-gdb/gdb/../gdbsupport/array-view.h:217: internal-error: copy: Assertion `dest.size () == src.size ()' failed. >>> >>> The backtrace is: >>> >>> #0 internal_error (file=0x5555606504c0 "/home/simark/src/binutils-gdb/gdb/../gdbsupport/array-view.h", line=217, fmt=0x55556064b700 "%s: Assertion `%s' failed.") at /home/simark/src/binutils-gdb/gdbsupport/errors.cc:51 >>> #1 0x000055555d41c0bb in gdb::copy (src=..., dest=...) at /home/simark/src/binutils-gdb/gdb/../gdbsupport/array-view.h:217 >>> #2 0x000055555deef28c in dwarf_expr_context::fetch_result (this=0x7fffffffb830, type=0x621007a86830, subobj_type=0x621007a86830, subobj_offset=0, as_lval=false) at /home/simark/src/binutils-gdb/gdb/dwarf2/expr.c:1040 >>> #3 0x000055555def0015 in dwarf_expr_context::evaluate (this=0x7fffffffb830, addr=0x62f00004313e "0", len=1, as_lval=false, per_cu=0x60b000069550, frame=0x621007c9e910, addr_info=0x0, type=0x621007a86830, subobj_type=0x621007a86830, subobj_offset=0) at /home/simark/src/binutils-gdb/gdb/dwarf2/expr.c:1091 >>> #4 0x000055555e084327 in dwarf2_evaluate_loc_desc_full (type=0x621007a86830, frame=0x621007c9e910, data=0x62f00004313e "0", size=1, per_cu=0x60b000069550, per_objfile=0x613000006080, subobj_type=0x621007a86830, subobj_byte_offset=0, as_lval=false) at /home/simark/src/binutils-gdb/gdb/dwarf2/loc.c:1485 >>> #5 0x000055555e0849e2 in dwarf2_evaluate_loc_desc (type=0x621007a86830, frame=0x621007c9e910, data=0x62f00004313e "0", size=1, per_cu=0x60b000069550, per_objfile=0x613000006080, as_lval=false) at /home/simark/src/binutils-gdb/gdb/dwarf2/loc.c:1529 >>> #6 0x000055555e0828c6 in dwarf_entry_parameter_to_value (parameter=0x621007a96e58, deref_size=0x0, type=0x621007a86830, caller_frame=0x621007c9e910, per_cu=0x60b000069550, per_objfile=0x613000006080) at /home/simark/src/binutils-gdb/gdb/dwarf2/loc.c:1235 >>> #7 0x000055555e082f55 in value_of_dwarf_reg_entry (type=0x621007a86890, frame=0x621007acc510, kind=CALL_SITE_PARAMETER_DWARF_REG, kind_u=...) at /home/simark/src/binutils-gdb/gdb/dwarf2/loc.c:1332 >>> #8 0x000055555e083449 in value_of_dwarf_block_entry (type=0x621007a86890, frame=0x621007acc510, block=0x61e000033568 "T\004\205\001\240\004\004\243\001T\237\004\240\004\261\004\001T\004\261\004\304\005\004\243\001T\237\004\304\005\310\005\001T\004\310\005\311\005\004\243\001T\237", block_len=1) at /home/simark/src/binutils-gdb/gdb/dwarf2/loc.c:1365 >>> #9 0x000055555e094d40 in loclist_read_variable_at_entry (symbol=0x621007a99bd0, frame=0x621007acc510) at /home/simark/src/binutils-gdb/gdb/dwarf2/loc.c:3889 >>> #10 0x000055555f5192e0 in read_frame_arg (fp_opts=..., sym=0x621007a99bd0, frame=0x621007acc510, argp=0x7fffffffbf20, entryargp=0x7fffffffbf60) at /home/simark/src/binutils-gdb/gdb/stack.c:559 >>> #11 0x000055555f51c352 in print_frame_args (fp_opts=..., func=0x621007a99ad0, frame=0x621007acc510, num=-1, stream=0x6030000bad90) at /home/simark/src/binutils-gdb/gdb/stack.c:887 >>> #12 0x000055555f521919 in print_frame (fp_opts=..., frame=0x621007acc510, print_level=1, print_what=LOCATION, print_args=1, sal=...) at /home/simark/src/binutils-gdb/gdb/stack.c:1390 >>> #13 0x000055555f51f22e in print_frame_info (fp_opts=..., frame=0x621007acc510, print_level=1, print_what=LOCATION, print_args=1, set_current_sal=0) at /home/simark/src/binutils-gdb/gdb/stack.c:1116 >>> #14 0x000055555f526c6d in backtrace_command_1 (fp_opts=..., bt_opts=..., count_exp=0x0, from_tty=0) at /home/simark/src/binutils-gdb/gdb/stack.c:2079 >>> #15 0x000055555f527ae5 in backtrace_command (arg=0x0, from_tty=0) at /home/simark/src/binutils-gdb/gdb/stack.c:2198 >>> >>> The problem is that the type that gets passed down to >>> dwarf_expr_context::fetch_result (the type of a variable of which we're >>> trying to read the entry value) is a typedef whose size has never been >>> computed yet (check_typedef has never been called on it). As we get in >>> the DWARF_VALUE_STACK case (line 1028 of dwarf2/expr.c), the `len` >>> variable is therefore set to 0, instead of the actual type length. We >>> then call allocate_value on subobj_type, which does call check_typedef, >>> so the length of the typedef gets filled in at that point. We end up >>> passing to the copy function a source array view of length 0 and a >>> target array view of length 4, and the assertion fails. >>> >>> Fix this by calling check_typedef on both type and subobj_type at the >>> beginning of fetch_result. >>> >>> I tried writing a test for this using the DWARF assembler, but I haven't >>> succeeded. It's possible that we need to get into this specific code >>> path (value_of_dwarf_reg_entry and all) to manage to get to >>> dwarf_expr_context::fetch_result with a typedef type that has never been >>> resolved. In all my attempts, the typedef would always be resolved >>> already, so the bug wouldn't show up. >>> >>> As a fallback, I made a gdb.dwarf2 test with compiler-generated .S >>> files. I don't particularly like those, but I think it's better than no >>> test. The .cpp source code is the smallest reproducer I am able to make >>> from the reproducer given in the bug (thanks to Pedro for suggestions on >>> how to minimize it further than I had). Since I tested on both amd64 >>> and aarch64, I added versions of the test for these two architectures. >>> >>> Change-Id: I182733ad08e34df40d8bcc47af72c482fabf4900 >>> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29374 >>> --- >>> gdb/dwarf2/expr.c | 5 + >>> .../gdb.dwarf2/entry-value-typedef-aarch64.S | 12885 +++++++++++++ >>> .../gdb.dwarf2/entry-value-typedef-amd64.S | 15545 ++++++++++++++++ >>> .../gdb.dwarf2/entry-value-typedef.cpp | 36 + >>> .../gdb.dwarf2/entry-value-typedef.exp | 45 + >>> 5 files changed, 28516 insertions(+) >>> create mode 100644 gdb/testsuite/gdb.dwarf2/entry-value-typedef-aarch64.S >>> create mode 100644 gdb/testsuite/gdb.dwarf2/entry-value-typedef-amd64.S >>> create mode 100644 gdb/testsuite/gdb.dwarf2/entry-value-typedef.cpp >>> create mode 100644 gdb/testsuite/gdb.dwarf2/entry-value-typedef.exp >> >> I pushed this patch. >> >> Simon > > It seems newer compilers on aarch64 (g++ 9.4.0 or 11.2.0) don't like this test. They complain with: > > gdb compile failed, /usr/bin/ld: /tmp/cc0vjoZT.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZNSsD1Ev@@GLIBCXX_3.4' which may bin > d externally can not be used when making a shared object; recompile with -fPIC > /usr/bin/ld: /tmp/cc0vjoZT.o(.text+0x38): unresolvable R_AARCH64_ADR_PREL_PG_HI21 relocation against symbol `_ZNSsD1Ev@@GLIBCXX_3.4' > /usr/bin/ld: final link failed: bad value > > So the test doesn't run properly. Is is that the old compiler I used (g++ 4.8 on Ubuntu 14.04, on the compile farm) generated non-position-independent code, but the linker of the newer toolchains try to build a position-independent executable? If so, we can re-generate the assembly files with -fPIE, and it should work, right? I'll give this a try, I have access to an AArch64 machine with Debian 11 & g++ 10.2.1. Simon