From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 4fxSH5fXfmqLEiUAWB0awg (envelope-from ) for ; Fri, 14 Aug 2026 04:53:43 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=rIM6tcLD; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 6F9371E033; Fri, 14 Aug 2026 04:53:43 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 73FC01E033 for ; Fri, 14 Aug 2026 04:53:39 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D47804BA79A1 for ; Fri, 14 Aug 2026 08:53:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D47804BA79A1 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=rIM6tcLD Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by sourceware.org (Postfix) with ESMTPS id 27BFC4BA23DD for ; Fri, 14 Aug 2026 08:53:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 27BFC4BA23DD Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 27BFC4BA23DD Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::630 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786697590; cv=none; b=AaQEGihQtY2+0CjyAx9FFNLe8HQxrkkrIJxyK0bRaF4ve5TJTnlA5aduRhUnE2yyRVfUICgq/ZEaKghRkpRXgRomD6roozdOUHYW5eAVdw8rU1jrM9YaH5Pn0GSCu8rO9OuJfuogvzHfFruhV+/6KVXwq6RkeF9r7b42w3tae3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786697590; c=relaxed/simple; bh=Ru2UGZRDaoobi7lBjfB7/ix9OzQo01KR+eCmdrAGMrw=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=RtvBr5/O3Bm1svltA6h3h653wUL4+SsgDP0vFD7JUsy7Nre1CLf3L9yxXJgkp/ElFC+BYUUtgtBx75TsOY8q93OkMlJZ1Q+cCfsKbLPobSvJXRNbyjFHIVwhbTSHIq7KL3n7oyLq+QfS2jEoYI0q9sj4f0cFUpehy1PnHSqWE6g= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=rIM6tcLD DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 27BFC4BA23DD Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-2cad68425a7so730465ad.1 for ; Fri, 14 Aug 2026 01:53:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786697589; x=1787302389; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=CKScQTcRlh8Y6fKlxxHQaKOFMJ6230bMGuU97BBkfC4=; b=rIM6tcLD6OwbtsxXwD8od17Vwn5KuT9oaLLMWYdBTJJQIWbrbsiTWuuFyKuZ7qfLgF Wq8s3T3bVwV/vKK/+w7obBeYldBlz4WbII+sM0D0UwNLOV9BoZuBaLEMef51ddSBq0r4 RKzm+qOON/LGlBTEJQT8ylwycTah4W7WdMSHv4LmSdL4jTJJGyzW5JMK9BxhuWbu7xS8 2ohpqipVfsfqZes3WWgvtypQfeHaRgxGVS114MC9VDDcnJeooIAXBxCk+jmEcVQY5npt aDrUicyjMkzH8heLsKxMNXl52xZUQWwmvCMyIzI2/9TJsIkn8LIYm4IcguOLJwwPPHVL 0EtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786697589; x=1787302389; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=CKScQTcRlh8Y6fKlxxHQaKOFMJ6230bMGuU97BBkfC4=; b=MrdrSzAF4CYEtJRajz9zkGGjygSUw5xk7HzrMOyJ1uZgzGOXegdoUFfaT/0DOIxRuF CHXN3dKBSSrtZEYoOuFDB2eMyvHsSD5NdDgMc6K6OLdIKyg5e8mdGtoxPYMoyenCaSLs Jpa/AcuC329SR5K4sG2Re3lCS0ggXIU//mgh4DWPTrlJ1rJIZYOJVHVfwJLvrZ0ru++2 Q999+uP3+jM+0lP1uFWljftKkKRBcf3jHCMnJORVeo/DXzCTsnbH6T+GS/b5Hns1SfY9 hhsT87q4cjo2TUrkaUEjk+0uSfHMKRZiLO+7ccllMZBaPsCru+Wkie/deRUPGRBQl4rE ntrg== X-Gm-Message-State: AOJu0Yyd/rrWPCvPYb4OztjbavIVmImdNK+Z7NSm8jS1GbRwj0r86VjJ 1KIwF32GXsynW+GM7Dl5BqTFlLtMlajqSxOvTc98eKyNZ7ytg+lZP6epwplPUZdk X-Gm-Gg: AR+sD10K0DaJQSWmo/igHnqb8ClHQ2j3ea8EuiVv5B3/gG2qweRcWhP5cYQFE/I3yyh VjLA7LNi7Yzt+I5GLsWDu/hqaiYg3vj6QvCM5Yg3CNmNXGFNov6XGys3R4YA086CbzU+ZrIiCWI sJg3q45os5lp6ZwLNObei2t0SkSsOZ57DYAEpmnBaTyUVTb1SNEDxWtmB05sdZavxFUqWVEefpR yC6uzfeQ5dP8dTpn6QBVbnA0rbCI75yfoc0cvrOf4+gHGcQRCQpHZzaffRt6v/fsP5onPHhT1x0 ztaK2HCqT8hmAEFSdP3VgmxsizE/vtye5qdhhlEqw7qbgsv3g4w33hDsEIA/C+FyiDHVUtRt9LS ORk6w+FtBRre0Xk1Z0DeWXC0RdETq/c1LNNfphugyrEGEUkjcOXnKbmbzfI9/VPt3UQtkjRvwf+ QaWVG0LeUfUTNfe0nr1jJbjqMCBaU4w4qicYy3P5gkK6rhF81NJ9o/09GaaCgC/1t0Q6T5O+heD qXWpAGFlUsesYsOQOXenapxVpWDNUGgZkew8dlKwv0xHzaDjOdDJg== X-Received: by 2002:a17:903:1b2b:b0:2ca:de3:15eb with SMTP id d9443c01a7336-2d3b0739429mr33851055ad.0.1786697589087; Fri, 14 Aug 2026 01:53:09 -0700 (PDT) Received: from poweredge.r760.114.212.189.32.r760.114.212.189.32 ([155.254.126.227]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-320ea7fe465sm1975980eec.25.2026.08.14.01.53.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2026 01:53:08 -0700 (PDT) From: Jielun Wu To: gdb-patches@sourceware.org Subject: [PATCH] gdb: Check DW_OP_deref_type size against type Date: Fri, 14 Aug 2026 16:53:03 +0800 Message-Id: <20260814085303.2561156-1-firmiana402@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org DWARF v5 requires the explicit size operand of DW_OP_deref_type to match the size of the referenced base type. The evaluator currently passes both sizes to dwarf_expr_context::deref without validating the encoding, and the generic dereference helper accepts the mismatch by zero-extending the bytes read from memory. Reject a mismatch after resolving the base type. Add a DWARF assembler test covering both DW_OP_deref_type and DW_OP_GNU_deref_type. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34277 Signed-off-by: Jielun Wu --- gdb/dwarf2/expr.c | 3 + .../gdb.dwarf2/dw2-deref-type-size.exp | 78 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 gdb/testsuite/gdb.dwarf2/dw2-deref-type-size.exp diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c index 3a6b8f58199..ff23fb3e891 100644 --- a/gdb/dwarf2/expr.c +++ b/gdb/dwarf2/expr.c @@ -2027,6 +2027,9 @@ dwarf_expr_context::execute_stack_op (gdb::array_view expr) op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset); cu_offset type_die_cu_off = (cu_offset) uoffset; type = get_base_type (type_die_cu_off); + if (type->length () != addr_size) + error (_("DW_OP_deref_type has different sizes for type and " + "data")); } else type = address_type; diff --git a/gdb/testsuite/gdb.dwarf2/dw2-deref-type-size.exp b/gdb/testsuite/gdb.dwarf2/dw2-deref-type-size.exp new file mode 100644 index 00000000000..52eae9e9eae --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-deref-type-size.exp @@ -0,0 +1,78 @@ +# Copyright 2026 Free Software Foundation, Inc. + +# This program 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. +# +# This program 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 . + +# Test that DW_OP_deref_type rejects an explicit dereference size that +# differs from the size of the referenced base type. + +load_lib dwarf.exp + +require dwarf2_support + +standard_testfile main.c -dw.S + +set asm_file [standard_output_file $srcfile2] + +Dwarf::assemble $asm_file { + cu {version 5} { + compile_unit {} { + declare_labels uint64_label + + uint64_label: base_type { + DW_AT_name "uint64_t" + DW_AT_encoding @DW_ATE_unsigned + DW_AT_byte_size 8 DW_FORM_sdata + } + + foreach {var op} { + bad_deref_type DW_OP_deref_type + bad_gnu_deref_type DW_OP_GNU_deref_type + } { + DW_TAG_variable { + DW_AT_name $var + DW_AT_type :$uint64_label + DW_AT_external 1 DW_FORM_flag + DW_AT_location { + variable _constants + variable _cu_label + + DW_OP_addr main_label + _op .byte $_constants($op) $op + _op .byte 4 "dereference size" + _op .uleb128 "$uint64_label - $_cu_label" \ + "base type DIE offset" + DW_OP_stack_value + } SPECIAL_expr + } + } + } + } +} + +if {[prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $asm_file] nodebug]} { + return +} + +if {![runto_main]} { + return +} + +foreach_with_prefix var { + bad_deref_type + bad_gnu_deref_type +} { + gdb_test "print $var" \ + "DW_OP_deref_type has different sizes for type and data" +} -- 2.34.1