From patchwork Wed Apr 26 13:29:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guinevere Larsen X-Patchwork-Id: 68311 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 0F62A3858C2C for ; Wed, 26 Apr 2023 13:29:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0F62A3858C2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682515791; bh=BipIhYR4JEQVeSD2HAbdk6jYM05IqVg/J4jKVdFlRcg=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=jdY47S1zJzuXxGcz88dGXNTC0lK/CS1QJSLStl0f34zhAy8mmnAjibjvXZTDf2e6L xUAWQEK0kY3y0lXVATPO7NwCbKpqBKxUa2xVRQa2IQJyUj1xresZfQaCJjNq10j7eD Pa+/U/rkwBJc9GJjtsPDVFP+avjq1bCfDCiafg7E= 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 ESMTPS id 3A6DB3858C53 for ; Wed, 26 Apr 2023 13:29:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3A6DB3858C53 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-216-nUo79qZjPHekkxK9ItdrdQ-1; Wed, 26 Apr 2023 09:29:27 -0400 X-MC-Unique: nUo79qZjPHekkxK9ItdrdQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 43C9E85A588 for ; Wed, 26 Apr 2023 13:29:27 +0000 (UTC) Received: from fedora.. (unknown [10.43.2.191]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C646C492C13; Wed, 26 Apr 2023 13:29:26 +0000 (UTC) To: gdb-patches@sourceware.org Cc: Bruno Larsen Subject: [PATCH] gdb/testsuite: change hardcoded assembly in gdb.arch/disp-step-insn-reloc.exp Date: Wed, 26 Apr 2023 15:29:16 +0200 Message-Id: <20230426132916.1988539-1-blarsen@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 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_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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: Bruno Larsen via Gdb-patches From: Guinevere Larsen Reply-To: Bruno Larsen Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" When testing gdb.arch.disp-step-insn-reloc.exp with clang in an x86_64 machine, the compiled test case would segfault when returning from the function can_relocate_call, with a suggestion of a broken stack. The example assembly in the commment was the following: f: MOV $1, %[ok] JMP end set_point0: CALL f ; tracepoint here. end: And the segmentation fault happening at the final "ret" instruction of the original function. This suggests that gcc's compilation process would realize that no ret instruction ever happened after that call and doesn't save the return address, while clang's process wouldn't. Looking at the generated instructions, we can indeed see a difference: clang's version: e8 f1 ff ff ff call 11a4 gcc's version: e8 f4 ff ff ff call 401125 Notice the difference on the second byte. Changing the assembly to use "ret" instead of "JMP end" does not change the behavior of the program and guarantees a compiler independent behavior. This commit does just that. --- gdb/testsuite/gdb.arch/insn-reloc.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/gdb/testsuite/gdb.arch/insn-reloc.c b/gdb/testsuite/gdb.arch/insn-reloc.c index f687c2c5631..365e6180057 100644 --- a/gdb/testsuite/gdb.arch/insn-reloc.c +++ b/gdb/testsuite/gdb.arch/insn-reloc.c @@ -49,10 +49,9 @@ fail (void) JMP set_point0 f: MOV $1, %[ok] - JMP end + RET set_point0: CALL f ; tracepoint here. - end: */ @@ -65,10 +64,9 @@ can_relocate_call (void) " jmp " SYMBOL (set_point0) "\n" "0:\n" " mov $1, %[ok]\n" - " jmp 1f\n" + " ret\n" SYMBOL (set_point0) ":\n" " call 0b\n" - "1:\n" : [ok] "=r" (ok)); if (ok == 1)