From patchwork Fri Feb 17 14:33:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 65186 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 C84AB385C301 for ; Fri, 17 Feb 2023 14:33:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C84AB385C301 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676644439; bh=AV99gInHRJuQTGkUlFtE2szNQzg5wSWFLlcSw0oyUDc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=qW17jfxn8/Ewgzb03n6dkHSUqw/9wS86rEbhu5dCLVYdQVogBOfpMPlBzhxMKCzWk 3yD01uXVper7LgvOQ7eUosz1GnFetwt4U2AoCbVBL7i9YvmzlSmM3GMaMzZzChc8XJ Hnmksa51igj+YSVfvq8xjShTeDJDQFipqiasEP94= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 0F8C4385781F for ; Fri, 17 Feb 2023 14:33:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0F8C4385781F Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4436133AE2 for ; Fri, 17 Feb 2023 14:33:35 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3154E13274 for ; Fri, 17 Feb 2023 14:33:35 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id XYP1Cj+Q72PLIAAAMHmgww (envelope-from ) for ; Fri, 17 Feb 2023 14:33:35 +0000 To: gdb-patches@sourceware.org Subject: [pushed] [gdb/testsuite] Simplify gdb.arch/amd64-disp-step-avx.exp Date: Fri, 17 Feb 2023 15:33:36 +0100 Message-Id: <20230217143336.8011-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" On SLE-11, with glibc 2.11.3, I run into: ... (gdb) PASS: gdb.arch/amd64-disp-step-avx.exp: vex3: \ var128 has expected value after continue^M Continuing.^M ^M Program received signal SIGSEGV, Segmentation fault.^M 0x0000000000400283 in _exit (status=0) at \ ../sysdeps/unix/sysv/linux/_exit.c:33^M 33 ../sysdeps/unix/sysv/linux/_exit.c: No such file or directory.^M (gdb) FAIL: gdb.arch/amd64-disp-step-avx.exp: \ continue until exit at amd64-disp-step-avx ... This is not related to gdb, we get the same result by just running the exec. The problem is that the test-case: - calls glibc's _exit, and - uses -nostartfiles -static, putting the burden for any necessary initialization for calling glibc's _exit on the test-case itself. So, when we get to the second insn in _exit: ... 000000000040acb0 <_exit>: 40acb0: 48 63 d7 movslq %edi,%rdx 40acb3: 64 4c 8b 14 25 00 00 mov %fs:0x0,%r10 ... no glibc-related initialization is done, and we run into the segfault. Adding this (borrowed from __libc_start_main) in _start in the .S file is sufficient to fix it: ... .rept 200 nop + call __pthread_initialize_minimal .endr ... But that already doesn't compile with say glibc 2.31, and regardless I think this sort of fix is too fragile. We could of course fix this by simply not running to exit. But ideally we'd have an exec that doesn't segfault when you just run it. Alternatively, we could hand-code an _exit syscall and bypass glibc all together. But I'd rather fix this in a way that simplifies the test-case. Taking a step back, the -nostartfiles -static was added to address that the xmm registers were not zero at main (which AFAICT is a valid thing to happen). [ The change itself silently broke the test-case, needing further fixing by commit 40310f30a51 ("gdb: make gdb.arch/amd64-disp-step-avx.exp actually test displaced stepping"). ] Instead, simplify things by reverting to the original situation: - no -nostartfiles -static compilation flags, - no _start in the .S file, - use exit instead of _exit in the .S file, and fix the original problem by setting the xmm registers to zero rather than checking that they're zero. Now that we're no longer forcing -static, add nopie to the flags to prevent compilation failure with target board unix/-fPIE/-pie. Tested on x86_64-linux. PR testsuite/30132 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30132 --- gdb/testsuite/gdb.arch/amd64-disp-step-avx.S | 12 ++---------- gdb/testsuite/gdb.arch/amd64-disp-step-avx.exp | 14 ++++---------- 2 files changed, 6 insertions(+), 20 deletions(-) base-commit: 5f497256bee624f0fa470949aa41534093bc5b25 diff --git a/gdb/testsuite/gdb.arch/amd64-disp-step-avx.S b/gdb/testsuite/gdb.arch/amd64-disp-step-avx.S index 0e07ab422db..496b37f6739 100644 --- a/gdb/testsuite/gdb.arch/amd64-disp-step-avx.S +++ b/gdb/testsuite/gdb.arch/amd64-disp-step-avx.S @@ -19,15 +19,7 @@ instructions. */ .text - - .global _start,main -_start: - # The area at _start is used as the displaced stepping buffer. Put - # more than enough nop instructions so that the instructions under test - # below don't conflict with it. - .rept 200 - nop - .endr + .global main main: nop @@ -66,7 +58,7 @@ ro_var: done: mov $0,%rdi - call _exit + call exit hlt /* RIP-relative data for VEX3 test above. */ diff --git a/gdb/testsuite/gdb.arch/amd64-disp-step-avx.exp b/gdb/testsuite/gdb.arch/amd64-disp-step-avx.exp index ef44a248b82..fba9f64d5c5 100644 --- a/gdb/testsuite/gdb.arch/amd64-disp-step-avx.exp +++ b/gdb/testsuite/gdb.arch/amd64-disp-step-avx.exp @@ -22,9 +22,7 @@ require is_x86_64_m64_target have_avx standard_testfile .S -set options [list debug \ - additional_flags=-static \ - additional_flags=-nostartfiles] +set options [list debug nopie] if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} $options] } { return -1 } @@ -103,14 +101,10 @@ proc disp_step_func { func } { # Test a VEX2-encoded RIP-relative instruction. with_test_prefix "vex2" { - # This test writes to the 'xmm0' register. As the test is - # statically linked, we know that the XMM registers should all - # have the default value of 0 at this point in time. We're about - # to run an AVX instruction that will modify $xmm0, but lets first - # confirm that all XMM registers are 0. + # Initialize all XMM registers to 0. for {set i 0 } { $i < 16 } { incr i } { - gdb_test "p /x \$xmm${i}.uint128" " = 0x0" \ - "xmm${i} has expected value before" + gdb_test_no_output "set \$xmm${i}.uint128 = 0" \ + "xmm${i} set to zero" } disp_step_func "test_rip_vex2"