From patchwork Fri May 19 14:06:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 96443 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1262733vqo; Fri, 19 May 2023 07:07:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4DtgnwC7FmO17DbFIg/jjq+cDuboxi5jvcsa4uLgdandS4d0w8DMXGhdEsqwNZqcNfkBlC X-Received: by 2002:a05:6402:1b0f:b0:510:b636:4073 with SMTP id by15-20020a0564021b0f00b00510b6364073mr1699792edb.3.1684505231697; Fri, 19 May 2023 07:07:11 -0700 (PDT) Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id n1-20020aa7c441000000b00504a26aa3f8si2772122edr.422.2023.05.19.07.07.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 May 2023 07:07:11 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=br0ZzjLc; arc=fail (signature failed); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 989523858421 for ; Fri, 19 May 2023 14:07:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 989523858421 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684505228; bh=tTdcunyPN9OjJrhSNtf6LPr6lm1So8N5SekJChVCDzs=; h=Date:Subject:To:Cc:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=br0ZzjLcZPgAumc89AUZfvEe2fwy/c1hLUuM4oVzdsIHLUJPxiyweKEIr2RF5BA9M HyyfY5Tc9WuWYtFGYpcW1QvLH3b9hSQwGAaHSMLdoXEjfZXpeaUJ7gVn2qbvvHvbcV rf+jpeSmUmroiSRo9w5E0HY4yN7dAwcRmaAKHr1Y= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2041.outbound.protection.outlook.com [40.107.104.41]) by sourceware.org (Postfix) with ESMTPS id ECCF23858428 for ; Fri, 19 May 2023 14:07:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ECCF23858428 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LQGabIT4hhz750GYMNLOtCNQG0n9+P4+b7rBvouDCoPCT2FCzxfxip4wh7wW4DL2GXS2sh8j5oDGpBh4dfndryoLk2jbyZ1piIPT1mCTeC2lEOusBDlQpFqKtYspfcsJKPpuog+qqg5hmpGy9OIqV5gCXctnY21T5ysVCQ1P8LCgl1jvAkpLX8VpV77e9wsbzSDT1aY/nelxQGwdTYvgDJxsDqIlun/MeqC8OIjvioLpG1h0ZuPTEN/H1CwF8uo+cDDQNxnDkjUnF/5taBZQk5kohgHWkAqOzN+REL/xkOs2j2vbTUV2zG25wXdkLUg6qiRAu/+srFqGm2hUwgkPbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tTdcunyPN9OjJrhSNtf6LPr6lm1So8N5SekJChVCDzs=; b=aSn6GFmVISqseb8dlgUs7+wFLGhBrdbhtBs9fyKcEuUgFXeN1UjSHmBwvAMf0mvM32H/caxtXTGptTYHSgouv97kMS2ONW2F+joUSi3dKkoxjaVnfROj1L5poi5J/V8crdJRQJsxP3KHlQgVTWLq603edfsWg5BfqMG3kBNc+YNg53Amd45qPzFMv3nUGXebLVG6ta1QHzeGLzVAsT/PqslPk1KDxdlZOiq/U/c2BbARTLIA3Y1Xi6pvwA6nGkNeRXaT6NmUkj4SZOV24qGu1D+y4Chgumg1bhZLYe2s/Uo89tNv4FUtlDETp0+XTXDQViTRxXAyYeZfkDdbAN2tWA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by AM7PR04MB6823.eurprd04.prod.outlook.com (2603:10a6:20b:102::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.21; Fri, 19 May 2023 14:06:59 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::e442:306f:7711:e24c]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::e442:306f:7711:e24c%5]) with mapi id 15.20.6411.021; Fri, 19 May 2023 14:06:59 +0000 Message-ID: <65393035-8006-1a66-deae-70a88ed29077@suse.com> Date: Fri, 19 May 2023 16:06:57 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 Subject: [PATCH 2/3] x86: disassembling over-long insns Content-Language: en-US To: Binutils Cc: "H.J. Lu" References: In-Reply-To: X-ClientProxiedBy: FR0P281CA0095.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a9::12) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|AM7PR04MB6823:EE_ X-MS-Office365-Filtering-Correlation-Id: f3c5ec1e-890e-41cd-d318-08db58724fcf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mrucfTeZ+Vwuv5OEq2K++ozpK8SriihZHLrlVARtd7Pq+l/lmVYcnPDbZPCk24JOzapbMJ76RyrLF8lbISuuMnEDSD519uPky6VUWBlsnEbR9cJ9C4nmOTnOqgAa/FsJ+9WA04GUvIAiJlz/Ph9rRGLqO0jb9gfrjIc+tD4mscu9Sjy7je96uMzLZN8b8eu4FjrRl7CKILxxiDX8o94dVVs1CuB6UVP4b6MURGCH0P+OnGEAuPXoMKoSCmJMgf1a93PuMVbHs5Ve1IlQPSTl7922o/hPnQKTgH5Jvzv4/47VYTBRuRCZT2KHSrgWFCNHS4UPSXu4RyZS5zivkKSeolD/kK5hBVZju/5jnIbIr1XnaSybBn5KSTOeuXQyvf3/ZWTvxbOwroS9e7Bc/pOuBDqqQ43EoFHnuSaNiQF7dHijCnDicyM/7e8BBEHmv2FViiTSNvxWVYFR/BiTf2qtmcy4lP2zukX9c9fecIe1CuFElVbHTL4p0cYmto2U+oNOLEkj4K4cRWkipI0CnMZkQoQEuH0tKDA2qlJifTV+3ucMDn31xwMRVkxNB+ulF+B6rEEp/xBpYF7vkz+kwmF715OalDQkvtuDeOA0YSUXeuVyMiwyUElYrWiQfgdyZF1NyL/v42+1GqC5yIfC6m1mAQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VE1PR04MB6560.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(39850400004)(136003)(346002)(376002)(366004)(396003)(451199021)(478600001)(6486002)(83380400001)(2616005)(6512007)(6506007)(26005)(186003)(2906002)(5660300002)(8676002)(8936002)(36756003)(6916009)(4326008)(38100700002)(66476007)(66556008)(316002)(31696002)(66946007)(86362001)(41300700001)(31686004)(66899021)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?7KH5E4libqNwASq9npfOwqyqObjM?= =?utf-8?q?mcbsvvA4x0ZLEZP4MgYYxasdzLqcJLrZgbKh9gDdqtG7VuZRl5MLBOwLrd+r1WfSZ?= =?utf-8?q?H1++vbh9spNwI06Tcf1/dQIrx8IBS3UV/yKq9g6yOWbDVfsznhuMGAuvQGf9bNSnN?= =?utf-8?q?8eOOtp0e2kIULVX1aJMzfRMpsECx4ccI0lTW+W//njvcYS0VVD8XBtNEvUE1sJjnB?= =?utf-8?q?au14fEPKJ7+TGPx7BTCgTDHTxGqn5GAfyvTRRWyqsV+hLYB67fcTK2mltXgfm/OKR?= =?utf-8?q?nJn4SEVgTCnvAEkOfFMXlYcKQKb7UsXWyG7r+qtEQmWfi13fd5yEW5+acihNrEmaL?= =?utf-8?q?kd+M6DPsgzGC241KYYh4UgPYk007sU7LXDYEo3+PBIuHYAWBzGpaalhBS4cLtmx42?= =?utf-8?q?ivFRjKh5DESE0zlyZ2oodhCKxkFbVGbhV+Orxagc5dSO3+vgQPptaWl8jY9JwRWZr?= =?utf-8?q?+qWQwyA4EVZOxN5/OvC+gx6cqNIgQX5LcCvtDZXXCpCb9vVzJKQ8aoYU91UCzr7Fy?= =?utf-8?q?qARWyg2xSXRRztLkN0qdIvwN5o1ggfNIQkjd+fSu55Hz6OBn3EJgjI2xP8ZQ9JUWK?= =?utf-8?q?7qLIh0wcSHwVGAB8mmrNVvozlv1fbqE2vu94SAjx7CdgOV2BuF85kN/KQZMES8G9s?= =?utf-8?q?rd5/yPECOgYDRJw4i/BUpFE8U7DMKbngi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Org: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: f3c5ec1e-890e-41cd-d318-08db58724fcf X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2023 14:06:59.2861 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 7dFSl8TmHli0HNCpFmlGoJItBOzu18GtfTb6QTASe6PnG3fYiJy3i8SJOBiJ0cXB/vkPDq9ORVAT/+20IFUXJg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR04MB6823 X-Spam-Status: No, score=-3027.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, 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: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jan Beulich via Binutils From: Jan Beulich Reply-To: Jan Beulich Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766331757959929713?= X-GMAIL-MSGID: =?utf-8?q?1766331757959929713?= The present way of dealing with them - misusing MAX_MNEM_SIZE, which has nothing to do with insn length - leads to inconsistent results. Since we allow for up to MAX_CODE_LENGTH - 1 prefix bytes (which then could be followed by another MAX_CODE_LENGTH "normal" insn bytes until we're done decoding), size the_buffer[] accordingly. Move struct dis_private down to be able to use MAX_CODE_LENGTH without moving its #define. While doing this also alter the order to have the potentially large array last. --- Originally I meant to use just MAX_CODE_LENGTH as the buffer size. But that broke the four "long insn" testcases, which I thought might make sense to keep intact. Nevertheless that's certainly another way to get things into consistent shape. It would further allow to drop the check associated with a "Check maximum code length" comment, as then we would never fetch more than this many bytes. Strictly speaking what can come past suffixes is a little less than MAX_CODE_LENGTH: Right now it could be EVEX (4 bytes), opcode (1), ModR/M (<=1), SIB (<=1), displacement (<=4), and immediate (<=4); the 8-byte displacement and 8-byte immediate cases have, respectively, no immediate or no displacement, and hence disp+imm <= 8 in all cases. While this sums up to 15, there are no EVEX insns at present with 32-bit immediate. The longest prefix-less ones currently known are those in the oversized{16,64} gas testcases (sans their prefixes, of course), i.e. 14 bytes. But I think it is better to cover the potential case of EVEX- with-32-bit-immediate case right away. --- a/opcodes/i386-dis.c +++ b/opcodes/i386-dis.c @@ -118,14 +118,6 @@ static void ATTRIBUTE_PRINTF_3 i386_dis_ /* The maximum operand buffer size. */ #define MAX_OPERAND_BUFFER_SIZE 128 -struct dis_private { - /* Points to first byte not fetched. */ - uint8_t *max_fetched; - uint8_t the_buffer[MAX_MNEM_SIZE]; - bfd_vma insn_start; - int orig_sizeflag; -}; - enum address_mode { mode_16bit, @@ -251,6 +243,15 @@ struct instr_info enum x86_64_isa isa64; }; +struct dis_private { + bfd_vma insn_start; + int orig_sizeflag; + + /* Points to first byte not fetched. */ + uint8_t *max_fetched; + uint8_t the_buffer[2 * MAX_CODE_LENGTH - 1]; +}; + /* Mark parts used in the REX prefix. When we are testing for empty prefix (for 8bit register REX extension), just mask it out. Otherwise test for REX bit is excuse for existence of REX @@ -297,7 +298,7 @@ fetch_code (struct disassemble_info *inf if (until <= priv->max_fetched) return true; - if (until <= priv->the_buffer + MAX_MNEM_SIZE) + if (until <= priv->the_buffer + ARRAY_SIZE (priv->the_buffer)) status = (*info->read_memory_func) (start, priv->max_fetched, until - priv->max_fetched,