From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5AD1C433EF for ; Wed, 30 Mar 2022 19:23:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241000AbiC3TZd (ORCPT ); Wed, 30 Mar 2022 15:25:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233883AbiC3TZb (ORCPT ); Wed, 30 Mar 2022 15:25:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F9D9E30; Wed, 30 Mar 2022 12:23:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A92DA614ED; Wed, 30 Mar 2022 19:23:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE8C1C340EC; Wed, 30 Mar 2022 19:23:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648668224; bh=qfcOtpUmc3V95SnfNZw0AXpV8o0Dw2lu5IoKH3sZ/qI=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=XV24Srp2S2xWzMRTJVgatiRn+p06buhFMTc4zRn8Sxh6NV1K/TSk9erIS8lDLyg1g PBdRbfIzfNXnStlkFpKUNFP/Kws9/hJLUfw1kSOiA9uHC9eifx5LdddDyQlff/GwAo 1eTCex/FLELjK0a7+LVq1quy9Fi41JlYI/OmQmiwmS7vWt8crH+QuwYDV4M2PJ0bFU FtcP4HA++YcVwocQ/mw2aePDwjI6T29a9mmgvtAYbOKPnuNbA4RNpVrj1DN7lGDXK8 /W4RcU66S0QaVrLCAUNb0aamiog9McfAH09FM/ezJnrkAGXyz58H0u9fBlAtQR+eCf C5peulNcfqGVw== Message-ID: <962cf8bf3544fe3e5d263442bb5ca2e21f25a54b.camel@kernel.org> Subject: Re: [PATCH v2 1/2] selftests/sgx: Use rip relative addressing for encl_stack From: Jarkko Sakkinen To: Reinette Chatre Cc: Shuah Khan , Dave Hansen , Shuah Khan , "open list:INTEL SGX" , "open list:KERNEL SELFTEST FRAMEWORK" , open list Date: Wed, 30 Mar 2022 22:22:43 +0300 In-Reply-To: References: <20220322074313.7444-1-jarkko@kernel.org> <7b7732ec-c7ff-cf92-510f-64c83ed985cd@intel.com> <0031a4f0-75f6-3104-1825-dcc2528f61b0@intel.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.42.4 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sgx@vger.kernel.org On Wed, 2022-03-30 at 22:03 +0300, Jarkko Sakkinen wrote: > On Wed, 2022-03-30 at 10:40 -0700, Reinette Chatre wrote: > > Could you please elaborate how the compiler will fix it up? >=20 > Sure. >=20 > Here's the disassembly of the RBX version: >=20 > [0x000021a9]> pi 1 > lea rax, [rbx + loc.encl_stack] >=20 > Here's the same with s/RBX/RIP/: >=20 > [0x000021a9]> pi 5 > lea rax, loc.encl_stack > Compiler will substitute correct offset relative to the RIP, > well, because it can and it makes sense. >=20 > It is treated differently than other registers, e.g. when > LEA is assembled. >=20 > BR, Jarkko To demonstrate this I did a couple of simple sessions with Rizin (fork/continuation/something of Radare2): jarkko@suppilovahvero ~/Downloads (main)> rizin test_encl.rbx.elf -- Temporally drop the verbosity prefixing the commands with ':' [0x00002000]> aaa [x] Analyze all flags starting with sym. and entry0 (aa) [x] Analyze function calls (aac) [x] Analyze len bytes of instructions for references (aar) [x] Check for classes [x] Type matching analysis for all functions (aaft) [x] Propagate noreturn information [x] Use -AA or aaaa to perform additional experimental analysis. [0x00002000]> /ad lea 0x0000206e # 7: lea rax, [rip + 0xf8b] 0x0000206f # 6: lea eax, [rip + 0xf8b] 0x0000207e # 1: leave 0x000020a1 # 7: lea rcx, [rip + 0xf58] 0x000020a2 # 6: lea ecx, [rip + 0xf58] 0x000020b4 # 1: leave 0x000020ee # 1: leave 0x00002128 # 1: leave 0x00002145 # 7: lea rax, [rip - 0x102] 0x00002146 # 6: lea eax, [rip - 0x102] 0x00002150 # 7: lea rax, [rip - 0xd7] 0x00002151 # 6: lea eax, [rip - 0xd7] 0x0000215b # 7: lea rax, [rip - 0xac] 0x0000215c # 6: lea eax, [rip - 0xac] 0x00002166 # 7: lea rax, [rip - 0x7d] 0x00002167 # 6: lea eax, [rip - 0x7d] 0x00002171 # 7: lea rax, [rip - 0x4e] 0x00002172 # 6: lea eax, [rip - 0x4e] 0x000021a7 # 1: leave 0x000021a9 # 7: lea rax, [rbx + loc.encl_stack] 0x000021aa # 6: lea eax, [rbx + loc.encl_stack] [0x00002000]> s 0x21a9 [0x000021a9]> pi 1 lea rax, [rbx + loc.encl_stack] [0x000021a9]>=20 jarkko@suppilovahvero ~/Downloads (main)> rizin test_encl.elf -- Use V! to enter into the visual panels mode (dwm style) [0x00002000]> aaa [x] Analyze all flags starting with sym. and entry0 (aa) [x] Analyze function calls (aac) [x] Analyze len bytes of instructions for references (aar) [x] Check for classes [x] Type matching analysis for all functions (aaft) [x] Propagate noreturn information [x] Use -AA or aaaa to perform additional experimental analysis. [0x00002000]> /ad lea 0x0000206e # 7: lea rax, [rip + 0xf8b] 0x0000206f # 6: lea eax, [rip + 0xf8b] 0x0000207e # 1: leave 0x000020a1 # 7: lea rcx, [rip + 0xf58] 0x000020a2 # 6: lea ecx, [rip + 0xf58] 0x000020b4 # 1: leave 0x000020ee # 1: leave 0x00002128 # 1: leave 0x00002145 # 7: lea rax, [rip - 0x102] 0x00002146 # 6: lea eax, [rip - 0x102] 0x00002150 # 7: lea rax, [rip - 0xd7] 0x00002151 # 6: lea eax, [rip - 0xd7] 0x0000215b # 7: lea rax, [rip - 0xac] 0x0000215c # 6: lea eax, [rip - 0xac] 0x00002166 # 7: lea rax, [rip - 0x7d] 0x00002167 # 6: lea eax, [rip - 0x7d] 0x00002171 # 7: lea rax, [rip - 0x4e] 0x00002172 # 6: lea eax, [rip - 0x4e] 0x000021a7 # 1: leave 0x000021a9 # 7: lea rax, [rip + 0x5e50] 0x000021aa # 6: lea eax, [rip + 0x5e50] [0x00002000]> s 0x21a9 [0x000021a9]> pi 1 lea rax, loc.encl_stack [0x000021a9]>=20 BR, Jarkko