From patchwork Wed Oct 30 19:31:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guinevere Larsen X-Patchwork-Id: 99846 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CB2E63857C7B for ; Wed, 30 Oct 2024 19:32:20 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 692D53858D33 for ; Wed, 30 Oct 2024 19:31:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 692D53858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 692D53858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730316719; cv=none; b=b7z9UvQo9rAaJymfjvAA/AV6HRAJMzLc4/itK01jkUc9WplnJTWdCu/p25ksSqZyzrcC/GbnI0JHxrXMutHG3DquAhx0jQr+W9jT5bBmCPn/DfLCV3ac831FaV5B4GI0NFdtc94rtJXYrnQQzWTtFE1VQ5pBQ/9Gnx60e0BFROc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730316719; c=relaxed/simple; bh=iZeZdwfmxLxj4IyfSTXH319Ufwtu0TNO633H6hUI89s=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Be/BwxG5Ga3ceAbLkV2VGjHgnifGHP61HaoZ7qQlemPrb3fcDkJd5P0F6H5yM52Q79JiKFzY1CWJesDcKMpYj8r4I6K0KPuZYDTiE5nLFpo8/A6Vd1AWnphUDEmAp0/bE7AoT47gNfwXCDoCw23zgEME4v78Omeqc3YjRFyZ+Yg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730316717; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mhWL6/atdRYoxi16FjbF8d67fccA0XKXYbzr8mfmiBI=; b=EIrnBgVcI4c//4SMJ4QuwxTfGqdOKxXoqmBhvbLYkgBdOlFhss3kSroU4Mg/SzJo7ldKzn WfJDVDQVqqArd6v51h4z+7cSaR3qkOpO633XF4ViUkcFOT5+Aq1r3vDd7TRTtj3HGLQ7L1 xyzcSa52g4LW1qIgMhE9xuPQ7jrJv+Q= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-446-5nbnsu9xMTCf98M_RmhLUg-1; Wed, 30 Oct 2024 15:31:56 -0400 X-MC-Unique: 5nbnsu9xMTCf98M_RmhLUg-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C808D1944AA6 for ; Wed, 30 Oct 2024 19:31:52 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.96.134.39]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 538B8300018D; Wed, 30 Oct 2024 19:31:51 +0000 (UTC) From: Guinevere Larsen To: gdb-patches@sourceware.org Cc: Guinevere Larsen Subject: [PATCH] gdb/testsuite: fix gdb.reverse/i386-avx-reverse.exp with clang Date: Wed, 30 Oct 2024 16:31:23 -0300 Message-ID: <20241030193123.3086112-1-guinevere@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org The test gdb.reverse/i386-avx-reverse.exp was changed by the recent commit: commit 5bf288d5a88ab6d3fa9bd7bd070e624afd264dc6 Author: Guinevere Larsen Date: Fri Jul 26 17:31:14 2024 -0300 gdb/record: support AVX instructions VMOVDQ(U|A) when recording In that commit I added a few calls to the instruction vmovdqa to and from memory addresses. Because my local gcc testing always had aligned pointers, I thought this would always work, but clang (and maybe other compilers) might not do the same, which will cause vmovdqa to segfault, and the test to fail spectacularly. This commit fixes that by adding an if condition, checking for alignment before calling vmovdqa, and if the memory is unaligned, vmovdqu will be used instead, which - at the time of committing - exercises the same code path. --- gdb/testsuite/gdb.reverse/i386-avx-reverse.c | 23 ++++++++++++++++--- .../gdb.reverse/i386-avx-reverse.exp | 10 ++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/gdb/testsuite/gdb.reverse/i386-avx-reverse.c b/gdb/testsuite/gdb.reverse/i386-avx-reverse.c index b36de10ec6f..9ddcf32c011 100644 --- a/gdb/testsuite/gdb.reverse/i386-avx-reverse.c +++ b/gdb/testsuite/gdb.reverse/i386-avx-reverse.c @@ -18,6 +18,11 @@ /* Architecture tests for intel i386 platform. */ #include +#include + +/* Calculation of whether the pointer is aligned to a 32 bit boundary. + This is used to verify that vmovdqa won't seg fault. */ +#define aligned(pointer) (((uintptr_t)(const void *)(pointer)) % 32 == 0) char global_buf0[] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, @@ -91,9 +96,21 @@ vmov_test () asm volatile ("vmovdqu %%ymm0, %0": "=m"(buf1)); /* Operations based on global buffers. */ - /* Global buffers seem to always be aligned, lets sanity check vmovdqa. */ - asm volatile ("vmovdqa %0, %%ymm15": : "m"(global_buf0)); - asm volatile ("vmovdqa %%ymm15, %0": "=m"(global_buf1)); + /* The instruction vmovdqa requires 2 registers, or a register and a + memory pointer aligned to a 32-bit boundary. Since recording this + instruction shares the codepath of vmovdqu, technically both branches + of the if condition test the same code, but should things change in + the future, this test will exercise everything necessary. */ + if (aligned(&global_buf0) && aligned(&global_buf1)) + { + asm volatile ("vmovdqa %0, %%ymm15": : "m"(global_buf0)); + asm volatile ("vmovdqa %%ymm15, %0": "=m"(global_buf1)); + } + else + { + asm volatile ("vmovdqu %0, %%ymm15": : "m"(global_buf0)); + asm volatile ("vmovdqu %%ymm15, %0": "=m"(global_buf1)); + } asm volatile ("vmovdqu %0, %%ymm0": : "m"(global_buf0)); asm volatile ("vmovdqu %%ymm0, %0": "=m"(global_buf1)); diff --git a/gdb/testsuite/gdb.reverse/i386-avx-reverse.exp b/gdb/testsuite/gdb.reverse/i386-avx-reverse.exp index 4aefbcdbab3..f22f52e4f1a 100644 --- a/gdb/testsuite/gdb.reverse/i386-avx-reverse.exp +++ b/gdb/testsuite/gdb.reverse/i386-avx-reverse.exp @@ -157,8 +157,14 @@ if {[record_full_function "vmov"] == true} { test_one_register "vmovdqu" "ymm0" \ "0x3f3e3d3c3b3a39383736353433323130, 0x3f3e3d3c3b3a39383736353433323130" \ "global buffer: " - test_one_memory "vmovdqa" "global_buf1" "0x0 .repeats 32 times" - test_one_register "vmovdqa" "ymm15" "0x0, 0x0" + # The next 2 instructions may be vmovdqa or vmovdqu, depending on whether + # the global pointers ended up aligned to a 32 bit boundary. While + # ideally we'd like to test vmovdqa, it isn't possible to force alignment. + test_one_memory "vmovdq" "global_buf1" "0x0 .repeats 32 times" + test_one_register "vmovdq" "ymm15" "0x0, 0x0" + + # Step over the if clause that checks for memory alignment + gdb_test "reverse-next" ".*" test_one_memory "vmovdqu" "buf1" "0x0 .repeats 32 times" test_one_register "vmovdqu" "ymm0" "0x2726252423222120, 0x0" "local buffer: "