From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id XxaeFxPy9WpecQYAWB0awg (envelope-from ) for ; Thu, 12 Nov 2026 12:06:27 -0500 Received: by simark.ca (Postfix, from userid 112) id 48B381E0BC; Thu, 12 Nov 2026 12:06:27 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::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 339411E087 for ; Thu, 12 Nov 2026 12:06:26 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 253444BA2E14 for ; Thu, 12 Nov 2026 17:06:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 253444BA2E14 Received: from zmcc-4-mx.zmailcloud.com (zmcc-4-mx.zmailcloud.com [34.203.170.87]) by sourceware.org (Postfix) with ESMTPS id E59114BA2E07 for ; Thu, 12 Nov 2026 17:05:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E59114BA2E07 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=symas.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=symas.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E59114BA2E07 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=34.203.170.87 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1794503159; cv=none; b=kimdlqH9s6Ec3XHSV3aSsBVTjpPbDhswNBPyBihTATkk1LU9wiLg3Ptdj6BFPcLkyVPlj7WPOMLtGEs/HdYmteCt+cI+gKqXAi2Q6FqErrsCkdWbToz0DSDpiz6SH4nQRQJ6MiChggJ62Ki1PibcQB2SpS8Tgj5Fxe8RBd7Vzvw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1794503159; c=relaxed/simple; bh=18PusjlNszhVf5397W26l7FMuvTf5NMNPb5X21ZA8ko=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=DPIUW6DuhWK8HJVBmlHnFYmUjLdQgXTWLMUFu+B6dDEZnBb5YYciLIDnSP4hphZkfw7UQBRP16mu/yiY7m9tteu4N5PXBmb3l+OtQw2Zt4FwiKPwNZqsGuyEX8UIb/h344NI/snCqn4qISHAQNJMlP8CMN2CCrZCaUTTxvDtQsE= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E59114BA2E07 Received: from zmcc-3.zmailcloud.com (ec2-3-15-255-223.us-east-2.compute.amazonaws.com [3.15.255.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by zmcc-4-mx.zmailcloud.com (Postfix) with ESMTPS id A4E787834B2F; Thu, 12 Nov 2026 11:05:58 -0600 (CST) Received: from zmcc-3.zmailcloud.com (localhost [127.0.0.1]) by zmcc-3-mta-1.zmailcloud.com (Postfix) with ESMTPS id 8F6D8104F251; Thu, 12 Nov 2026 11:05:58 -0600 (CST) Received: from localhost (localhost [127.0.0.1]) by zmcc-3-mta-1.zmailcloud.com (Postfix) with ESMTP id 78121106B0D5; Thu, 12 Nov 2026 11:05:58 -0600 (CST) Received: from zmcc-3.zmailcloud.com ([127.0.0.1]) by localhost (zmcc-3-mta-1.zmailcloud.com [127.0.0.1]) (amavis, port 10026) with ESMTP id 5Jk1p2g_tDAo; Thu, 12 Nov 2026 11:05:58 -0600 (CST) Received: from zmcc-3-mailbox-1.zmailcloud.com (zmcc-3-mailbox-1.zmailcloud.com [172.31.18.168]) by zmcc-3-mta-1.zmailcloud.com (Postfix) with ESMTP id 514CB104F251; Thu, 12 Nov 2026 11:05:58 -0600 (CST) From: Robert Dubner To: "Rohr, Stephan" , References: <20261111174247.3382098-1-rdubner@symas.com> <20261111174247.3382098-6-rdubner@symas.com> In-Reply-To: Subject: RE: [PATCH v4 5/5] gdb: Avoid oversized shifts when writing floating-point fields Thread-Topic: [PATCH v4 5/5] gdb: Avoid oversized shifts when writing floating-point fields Date: Thu, 12 Nov 2026 11:05:58 -0600 (CST) Message-ID: <011701dd72c8$169fa5d0$43def170$@symas.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 16.0 X-Mailer: Zimbra 10.1.21_GA_4899 (Zimbra-ZCO/1951 (10.0.26200 en-US) P6244 T6b10 R838) Content-Language: en-us Thread-Index: AQGFsgdpYhu/3tRoUdOINuZGmzzcigIH7X8jAV8lfJi3vvK5sA== X-Zimbra-Message-Verification: hash=SHA256; guid=ZWFiNDA5MGFkMDdlZjUxOGY4MmY4ZWE3ZmEzMjdlZjUwMjI0ZmMzOWZlMDZjYTcyYTBiZDMzZDE3YzljY2I4ZQ== 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 > -----Original Message----- > From: Rohr, Stephan > Sent: Thursday, November 12, 2026 04:48 > To: Robert Dubner ; gdb-patches@sourceware.org > Subject: RE: [PATCH v4 5/5] gdb: Avoid oversized shifts when writing > floating-point fields > > Hi Robert, > > thanks for the patch. A few comments, see below. > > The patch is new in this series and wasn't posted before? I actually thought I had posted it before. As we have worked through this here, I have been forced to focus on multiple unrelated things and I have gotten confused more than once. > > Please don't carry the "Reviewed-By" from one patch to a new > patch when sending a new version of the series. > > Thanks > Stephan > > Reviewed-By: Rohr, Stephan > > > -----Original Message----- > > From: Robert Dubner > > Sent: Wednesday, 11 November 2026 18:43 > > To: gdb-patches@sourceware.org > > Cc: Rohr, Stephan > > Subject: [PATCH v4 5/5] gdb: Avoid oversized shifts when writing > > floating- > > point fields > > > > put_field can write fields wider than unsigned long, such as the > > 112-bit binary128 fraction field used when encoding infinities and > > NaNs. Its loop can shift stuff_to_put by its width or more, which is > > undefined even when the value is zero. > > > > Use zero once the shift reaches the width of unsigned long. Apply > > the guarded value to both full-byte and partial-byte writes, > > preserving the existing neighboring-bit masks. > > > > Add unit tests in target-float.c covering wide fields, alignment, > > both byte orders, neighboring bits, buffer guards, and binary128 > > infinity and NaN encodings. > > > > Reviewed-By: Rohr, Stephan > > --- > > gdb/target-float.c | 102 > > +++++++++++++++++++++++++++++++++++++++++++-- > > 1 file changed, 99 insertions(+), 3 deletions(-) > > > > diff --git a/gdb/target-float.c b/gdb/target-float.c > > index fc0b7931860..068310932f0 100644 > > --- a/gdb/target-float.c > > +++ b/gdb/target-float.c > > @@ -245,6 +245,7 @@ put_field (unsigned char *data, enum > > floatformat_byteorders order, > > { > > unsigned int cur_byte; > > int cur_bitshift; > > + constexpr int value_bits = sizeof (stuff_to_put) * > > FLOATFORMAT_CHAR_BIT; > > > > /* Caller must byte-swap words before calling this routine. */ > > gdb_assert (order == floatformat_little || order == floatformat_big); > > @@ -282,17 +283,21 @@ put_field (unsigned char *data, enum > > floatformat_byteorders order, > > /* Move towards the most significant part of the field. */ > > while (cur_bitshift < len) > > { > > + /* Fields such as a binary128 fraction can be wider than > > STUFF_TO_PUT. > > + Zero-extend rather than shifting by the width of unsigned long or > > + more. */ > > + unsigned long shifted > > + = cur_bitshift < value_bits ? stuff_to_put >> cur_bitshift : 0; > > if (len - cur_bitshift < FLOATFORMAT_CHAR_BIT) > > { > > /* This is the last byte. Make sure we don't OR in extra high-order > > bits when STUFF_TO_PUT violates the LEN restriction. */ > > unsigned int mask = (1U << (len - cur_bitshift)) - 1; > > *(data + cur_byte) &= ~mask; > > - *(data + cur_byte) |= (stuff_to_put >> cur_bitshift) & mask; > > + *(data + cur_byte) |= shifted & mask; > > } > > else > > - *(data + cur_byte) = ((stuff_to_put >> cur_bitshift) > > - & ((1 << FLOATFORMAT_CHAR_BIT) - 1)); > > + *(data + cur_byte) = shifted & ((1 << FLOATFORMAT_CHAR_BIT) - 1); > > cur_bitshift += FLOATFORMAT_CHAR_BIT; > > if (order == floatformat_little) > > ++cur_byte; > > @@ -2927,6 +2932,93 @@ signed_zero_test () > > } > > } > > > > +/* Check zero extension when a field is wider than unsigned long. > > Build > > + expected bytes with arbitrary-precision integer operations, > > independently > > + of put_field and get_field, and preserve neighboring bits and > > guards. */ > > + > > +static void > > +put_field_wide_test () > > +{ > > + constexpr unsigned int value_bits > > + = sizeof (unsigned long) * FLOATFORMAT_CHAR_BIT; > > + struct test_case > > + { > > + unsigned int start; > > + unsigned int len; > > + }; > > + const test_case tests[] = > > + { > > + {0, 128}, > > + {16, 112}, /* The binary128 fraction field. */ > > + {15, 112}, > > + {12, 113}, > > + {8, value_bits}, > > + {7, value_bits}, > > + {7, value_bits + 1}, > > + {0, value_bits + 8} > > + }; > > + > > + for (auto order : {floatformat_big, floatformat_little}) > > + for (const test_case &test : tests) > > + for (unsigned long value : {0UL, 1UL, 0xa5UL, ~0UL, > > + 1UL << (value_bits - 1)}) > > + for (gdb_byte initial : {0x00, 0xa5, 0xff}) > > + { > > + gdb_byte data[18]; > > + memset (data, initial, sizeof (data)); > > + data[0] = 0x3c; > > + data[17] = 0xc3; > > + std::vector expected (16, initial); > > + bfd_endian byte_order = order == floatformat_big > > + ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; > > Nit: this is not correctly indented. Also, it is missing parathesis. The > continuation > should start at the next line. > > > + unsigned int shift = 128 - test.start - test.len; > > + gdb_mpz image; > > + image.read (expected, byte_order, true); > > + gdb_mpz mask = ((gdb_mpz (1) << test.len) - gdb_mpz (1)) << shift; > > + mask.complement (); > > + image = (image & mask) | (gdb_mpz (value) << shift); > > + image.write (expected, byte_order, true); > > + > > + put_field (data + 1, order, 128, test.start, test.len, value); > > + SELF_CHECK (data[0] == 0x3c); > > + SELF_CHECK (std::equal (expected.begin (), expected.end (), > > + data + 1)); > > + SELF_CHECK (data[17] == 0xc3); > > + } > > +} > > + > > +/* The MPFR encoder writes a complete binary128 fraction for infinities > > and > > + NaNs. Exercise that caller as well as the field writer itself. */ > > + > > +static void > > +wide_special_test () > > +{ > > + mpfr_float_ops ops; > > + type_allocator alloc (get_current_arch ()); > > + for (const floatformat *fmt : {&floatformat_ieee_quad_big, > > + &floatformat_ieee_quad_little}) > > + { > > + const floatformat *pair[] = {fmt, fmt}; > > Patch 2/5 introduced "subnormal_type (const floatformat *fmt)". As this > patch > comes after this, we can use it here, too. > > > + type *ftype = init_float_type (alloc, -1, "selftest_quad", pair, > > + BFD_ENDIAN_BIG); > > + bfd_endian order = fmt->byteorder == floatformat_big > > + ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; > > Nit: same here. > > > + for (const char *text : {"inf", "-inf", "nan"}) > > + { > > + gdb_mpz bits = gdb_mpz (0x7fff) << 112; > > + if (text[0] == '-') > > + bits = bits | (gdb_mpz (1) << 127); > > + else if (text[0] == 'n') > > + bits += 1; > > + std::vector expected (16); > > + bits.write (expected, order, true); > > + std::vector actual (16, 0xa5); > > + SELF_CHECK (ops.from_string (actual.data (), ftype, text)); > > + SELF_CHECK (actual == expected); > > + } > > + } > > +} > > + > > } /* namespace selftests */ > > #endif /* GDB_SELF_TEST */ > > > > @@ -2937,6 +3029,10 @@ INIT_GDB_FILE (target_float) > > selftests::put_field_test); > > selftests::register_test ("target-float-signed-zero", > > selftests::signed_zero_test); > > + selftests::register_test ("target-float-put-field-wide", > > + selftests::put_field_wide_test); > > + selftests::register_test ("target-float-wide-specials", > > + selftests::wide_special_test); > > selftests::register_test ("target-float-subnormal", > > selftests::subnormal_test); > > selftests::register_test ("target-float-subnormal-rounding", > > -- > > 2.34.1 > > ________________________________________ > Intel Deutschland GmbH > > Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany > > Tel: +49 (89) 99143-0 > > www.intel.de > > Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran > Sitaraman > > Chairperson of the Supervisory Board: Sonja Pierer > > Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB > 186928 > > This e-mail and any attachments may contain confidential material for > the sole use of the intended recipient(s). Any review or distribution > by others is strictly prohibited. If you are not the intended > recipient, please contact the sender and delete all copies.