From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 B20BC3858D35 for ; Tue, 23 May 2023 08:37:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B20BC3858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684831024; 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: in-reply-to:in-reply-to:references:references; bh=BoyHbfjCpqGVF4h6qvVM0EDNlWDgpwTRAPRl0QTan5s=; b=fDSAxhlC0lbR6SgDB5QSE1uNPTKbDTTwCSVNB32OqVH7fx95noqq7Lbd49SJioBxDRT/IJ Bhc40QQF185W41NkeQNXLYbTadlRjevpNQj6FnGi3KV1ULqaZdYS814V+OSo/2oneW7RON 37DuGp5gDTKcM9Gu5G7GznvWp8RoxH4= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-670-uTQiPx8cM9qeZVIsFVmVJw-1; Tue, 23 May 2023 04:37:02 -0400 X-MC-Unique: uTQiPx8cM9qeZVIsFVmVJw-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-3f518f2900eso44980715e9.2 for ; Tue, 23 May 2023 01:37:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684831021; x=1687423021; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BoyHbfjCpqGVF4h6qvVM0EDNlWDgpwTRAPRl0QTan5s=; b=eunV1CidWeeiNnig2b4bDY2FZtoiAyTuLPUbzmPgVbiSJVzvsiDKfUaRSu1cNAhBtw yPN+miTI8H2VmgACY4RNyM9iBvVuCULTgMzHrXVZjqHLLx7W5xqfPuyPuLVdsRM2P5Z5 +vU1f/DWV88DCXBY/5WTqZT3/TvMyZ+yujDki8aW5x+JZiywVrFvvk7rUjK6+jbkqneU ADCNg/Avr3kcelj5IoG4wI3B10MLfm8CJyMXSE9ScNHKB+OtKtHy/JqRALULQVEJn0wH D6mK1JylYj1O+PZNP8pND+Dth2yXUgd/jdhcm0+RKGFFbLENzuGzMqIWHjDVRrCSF6Nz s3BQ== X-Gm-Message-State: AC+VfDxeXCZQVDjoMklxX7xVGhSVj145xuMMjbdQEACgyt/Uvi/ds9HL rk9r3BwO3Eb6DvC8LGgCTZnwN9fv/0ZvjfoD1SdcaLAYDo8oXE7jTFqo6Hq+xqMPXer0HmlxS2F 0MiqcpK+tIRgcs9fP1rcwgg== X-Received: by 2002:a7b:cb91:0:b0:3f6:1a9:b9db with SMTP id m17-20020a7bcb91000000b003f601a9b9dbmr5669126wmi.21.1684831021690; Tue, 23 May 2023 01:37:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ51IXTe0PM3OhgiqHuhMQuyeQYFPOUEwkHjb81Z4CFd18Qo8uiY19tgwBvVTmAtvrUzVT87Bw== X-Received: by 2002:a7b:cb91:0:b0:3f6:1a9:b9db with SMTP id m17-20020a7bcb91000000b003f601a9b9dbmr5669112wmi.21.1684831021325; Tue, 23 May 2023 01:37:01 -0700 (PDT) Received: from localhost (11.72.115.87.dyn.plus.net. [87.115.72.11]) by smtp.gmail.com with ESMTPSA id m5-20020a7bca45000000b003f60e143d38sm328265wml.11.2023.05.23.01.37.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 01:37:00 -0700 (PDT) From: Andrew Burgess To: Bruno Larsen , gdb-patches@sourceware.org Cc: Bruno Larsen Subject: Re: [PATCH v2] gdb/testsuite: change hardcoded assembly in gdb.arch/disp-step-insn-reloc.exp In-Reply-To: <20230522104623.214121-1-blarsen@redhat.com> References: <20230426132916.1988539-1-blarsen@redhat.com> <20230522104623.214121-1-blarsen@redhat.com> Date: Tue, 23 May 2023 09:36:59 +0100 Message-ID: <87a5xv8mvo.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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 List-Id: Bruno Larsen writes: > 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 > can_relocate_call. Looking at the disassembled version of the later > half of the important function, we see: > > Clang version (f starting at 11a4): > 00000000000011ae : > 11ae: e8 f1 ff ff ff callq 11a4 > 11b3: 89 45 fc mov %eax,-0x4(%rbp) > 11b6: 83 7d fc 01 cmpl $0x1,-0x4(%rbp) > 11ba: 0f 85 0a 00 00 00 jne 11ca > 11c0: e8 5b 00 00 00 callq 1220 > 11c5: e9 05 00 00 00 jmpq 11cf > 11ca: e8 61 00 00 00 callq 1230 > 11cf: 48 83 c4 10 add $0x10,%rsp > 11d3: 5d pop %rbp > 11d4: c3 retq > 11d5: 66 66 2e 0f 1f 84 00 data16 nopw %cs:0x0(%rax,%rax,1) > 11dc: 00 00 00 00 > > gcc version (f starting at 401125): > 000000000040112c : > 40112c: e8 f4 ff ff ff callq 401125 > 401131: 89 45 fc mov %eax,-0x4(%rbp) > 401134: 83 7d fc 01 cmpl $0x1,-0x4(%rbp) > 401138: 75 07 jne 401141 > 40113a: e8 c7 ff ff ff callq 401106 > 40113f: eb 05 jmp 401146 > 401141: e8 c7 ff ff ff callq 40110d > 401146: 90 nop > 401147: c9 leaveq > 401148: c3 retq > > The epilogue of set_point0 (11cf for clang, 401146 for gcc) is the main > difference: GCC's version uses the leaveq instruction, which resets rsp > based on rbp, while clang adds the same constant to rsp that it > subtracted in the prologue. Clang fails because the return address that > is added by the "call f" instruction isn't accounted for. > > This commit fixes that by adding a return instruction to f, which leaves > the rsp as the compilers would expect. Looks great. Thanks for updating the commit message. Approved-By: Andrew Burgess Thanks, Andrew > --- > 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) > -- > 2.40.1