From patchwork Tue Oct 25 07:27:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 10542 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp858335wru; Tue, 25 Oct 2022 00:29:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4MWLC+Wq0Xhn6OB60dQQ5Nkvf9U+NEoqHpHCok9AzkHKMxRWmh+Ei+a7bUruo7V0vTDgFH X-Received: by 2002:a05:6402:524e:b0:461:fa05:aff8 with SMTP id t14-20020a056402524e00b00461fa05aff8mr4265784edd.283.1666682940968; Tue, 25 Oct 2022 00:29:00 -0700 (PDT) Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id b13-20020a056402350d00b00459fc3fcf3csi2091025edd.102.2022.10.25.00.29.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 00:29:00 -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=NISL1Irg; 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 613523857B81 for ; Tue, 25 Oct 2022 07:28:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 613523857B81 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666682930; bh=SLBNqnEyXQJihwWPUKC/uBDm9D3Wk08ThguCdanHfyI=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=NISL1Irg9CFFyDAhXWxKKXfKo9P+pR1wg8PPebbFlDBJnnWmLxTGri764a4hcUzlX p3fbBpH/AxZ7h6Exhne2lLZnrVFziDiCWodKmaR4O+LCfj2mtTPNkxobellmhjZ9VZ jxt8iXB19B6Xlb17m7XCLbTMX8Ld6UWKRN7fm41c= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2061.outbound.protection.outlook.com [40.107.247.61]) by sourceware.org (Postfix) with ESMTPS id 897413857402 for ; Tue, 25 Oct 2022 07:27:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 897413857402 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IlB/fsI4U8YcgRi/LKjAiuT4ZhRMSLHQRqsIek81z1ZeaXnedDeOsBzyS1m/hIdHM3Vk4rxrnmQHZSUD+lyTSOtHemZcMuktNPkz9RfCgvH3SIuCLq8dxYGGjUUT/vSA07gctyDyYIzq4tmYT1FZKFYk4HrpfNQV981Ndkq65Y28uAT6eeOitbiHqJhUBNxBuZxEsSnFfh1IKzAjPBshF8jXLXX9Lrnczdr4rHn1nTSlgUnLPnEjI/OwAMO7GTWMSqC3bwg9/bxq8/HAUA2wH/qgn4OWmgisfVcBGgQXhdpn/Hm3G1ksIGVUH381L0fxpE8YK6FsEeNmLwIfcoMfmg== 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=SLBNqnEyXQJihwWPUKC/uBDm9D3Wk08ThguCdanHfyI=; b=lNOsLqFBS756UTC4qTkz2iUMPwGNgZqu1pDRAmGzZzxIGWuPjsV+wcnGWhoMscl2RuSe1BAwrOiSdVkb9uOUxiN/uz2/k/lLGamv3XqZ0cr15TvwKcs1djQql6bB/lHV8jTx5wDpYy3KiJEzTHOZUPCSEHyu+ShAB3ThuX16UBjZcqFg0DSUFVBUNsGQdFZzDgBGyp4Ln759KFBBtckJlbzvyUbW3jMJa/5YKK9wI/Gl/KpzrlaEdC/VusqUPGSbQz5lkrYKy6Zug+nFrymzSphJ06BBsnynjLxB/Bj1z+jcK1Reb77ydIBkjMUtHuk3DlMVnYv+K2haPm49gZBMFw== 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 PA4PR04MB7933.eurprd04.prod.outlook.com (2603:10a6:102:b9::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.21; Tue, 25 Oct 2022 07:27:37 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::4da2:ea8b:e71e:b8d8]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::4da2:ea8b:e71e:b8d8%4]) with mapi id 15.20.5746.021; Tue, 25 Oct 2022 07:27:37 +0000 Message-ID: <2e2f7841-de4e-b5de-e8d9-a47a6a4113c8@suse.com> Date: Tue, 25 Oct 2022 09:27:35 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.4.0 Subject: [PATCH v5 6/8] x86: move bad-use-of-TLS-reloc check Content-Language: en-US To: Binutils References: In-Reply-To: X-ClientProxiedBy: FR3P281CA0127.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:94::13) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|PA4PR04MB7933:EE_ X-MS-Office365-Filtering-Correlation-Id: 53b4bb81-06ec-4cb8-ee83-08dab65a640a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YDlBwaVJcm07Eiy5yM0p2Bx/HxBd1jK8fJ3JVRUh4kBmvUQ7km8fAn1OpJRQM2Vm+AG3slalm213B1lclei6HI6neInZSSD4LdTOtECmhIFJ9Am6DSo1D4GstYQaO0Va3W3jCxW/PONkPaxJI33Bhre4XLffGiGghgZG1cIsg9T1FZrTaYw7Kaeul5+RtdKP5ZgFBQU4GG0LKysAtfS+HUBOTev8wHJHL2WEqB5UIGhQNtRqnlFu3kxpzobxCXga55360LkRT9/uTtm7GVDS2XvC+xnsahFQ4fpUSed2HTp1P8qncjacb0YQD0CHcpqqdd1YMY4+WzQKcrg0SGW1Jegyz0RoYCllrlS8cdaYQCElwQWCLTBYFLiHYi6O6EdHm/TuVyd13VO4mGTeL3QPDymEL9lwonwXAZ1REaoM0NxS10OZJIGQ3kayGARMmiY1/oMjh9N5VpSuXiXDvugH6BLwbwATNe6B3huAEBZClg78wcC3BzTellAdge0RbwRY7gyeGZ011THEh0yMUmAX564ZLnav0pZ8Ta8MF9PrPeccEG09Oq7XMpeZBOPSKdSP+zjMdG6tvwEZe7LoOuyR3Lbx786Ne30gRjTVhuiw7W72qfZuMU6Kmyj9hMWZjTYHMQhN5xy7cahXKrzxnXC6unbCS2iZQMyrcoYFwC4zTXuu/YPAqXRHwGWRkmESCNljVqNeG4pVGzLbQhVqxiplySwgTFviNMkdWSkKXuULD3qb/up4aYQQ4qj9FQAxszuhoAE9yU0MPfyuqveNQJA/S2tFrghOnV2sy61cjMvLWQs= 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:(13230022)(39860400002)(396003)(136003)(366004)(376002)(346002)(451199015)(86362001)(316002)(38100700002)(31696002)(6916009)(6512007)(66476007)(41300700001)(26005)(186003)(2616005)(8936002)(5660300002)(2906002)(8676002)(4326008)(66556008)(66946007)(6506007)(36756003)(6486002)(31686004)(478600001)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?CULhXEW4ePsrM4fD2vwwd72/DHXP?= =?utf-8?q?fnHDYH0q4+d3ebYV5Zp0Prl7n5tlqHItuZwU+/jq9h4fk6CC4255waTW+XC4pq2sI?= =?utf-8?q?t5o8P5UzLZepRpoNjdQbCKuddOM5Kwx/8Di1+uGXlfngmmuaeUtuminVXX4SY1YNX?= =?utf-8?q?CDg5IJdJgE8d0amqaACBjbNixGU6WgpQiAn3X1vgdBVK0agG4hEG/FxH9kNVBzSGv?= =?utf-8?q?gz3K0W1JeQDy15Bgbav4DxHD56bPOkQ8MEgzKjxOz/++xlOsVJMSfHIhxiwXLfw9U?= =?utf-8?q?0bgL7JUyiTm/WXWoIa8Zu1MS7qsbvwPaURFnTMIs46Jii7XpYqa56u7l1t1F4VEVF?= =?utf-8?q?JuPguZ2BSlkNV3azDrdLKxU2VRc3KoTMHf/kCY+j1U8gXfmEeoo0uvu1ysTaZwmVr?= =?utf-8?q?m8TPc5FHSGizf6UQk8MBrecFFuVtOv84WCQdVwz+O0uJuigkUydCfrbQL3DqHtlIK?= =?utf-8?q?nt7MLozCJC2AQisG1sVlesz9P1b3LPc0y7wsHBSfkJnCXUbIDoHIFzu7F8YUz2ora?= =?utf-8?q?3alnkeFmxHZ0dS8nDlvwpHk7yQuIA124v1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R10ALhitgGnG7fcTNhE5zMDWEzRi8ny?= =?utf-8?q?ty2Z5Z89sg/B48KtMQZZ4ROujaEO/ygwvxOC2Uu/TWDvsyOmfZYMFHV/Tx/AOumm4?= =?utf-8?q?Mc9yEodNAjSn?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 53b4bb81-06ec-4cb8-ee83-08dab65a640a X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2022 07:27:37.0283 (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: mE1W9+68NL82jz/IHU9puBqQaj+owNdISyOp4lZHJq+e1W1K7oH/xDnqd985FPxFBG4ggjfyHJTpliZNSQ6Ipg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB7933 X-Spam-Status: No, score=-3029.6 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_PASS, 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: 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?1747643731925861777?= X-GMAIL-MSGID: =?utf-8?q?1747643731925861777?= Having it in match_template() is unhelpful. Neither does looking for the next template to possibly match make any sense in that case, nor is the resulting diagnostic making clear what the problem is. While moving the check, also generalize it to include all SIMD and VEX- encoded insns. This way an existing conditional can be re-used in md_assemble(). Note though that this still leaves a lof of insns which are also wrong to use with these relocations. Further fold the remaining check (BFD_RELOC_386_GOT32) with the XRELEASE related one a few lines down. This again allows re-using an existing conditional. --- Is the set of relocations enumerated here actually complete? --- v2: New. --- a/gas/config/tc-i386.c +++ b/gas/config/tc-i386.c @@ -5118,14 +5118,30 @@ md_assemble (char *line) return; } - /* Check for data size prefix on VEX/XOP/EVEX encoded and SIMD insns. */ - if (i.prefix[DATA_PREFIX] - && (is_any_vex_encoding (&i.tm) - || i.tm.operand_types[i.imm_operands].bitfield.class >= RegMMX - || i.tm.operand_types[i.imm_operands + 1].bitfield.class >= RegMMX)) + if (is_any_vex_encoding (&i.tm) + || i.tm.operand_types[i.imm_operands].bitfield.class >= RegMMX + || i.tm.operand_types[i.imm_operands + 1].bitfield.class >= RegMMX) { - as_bad (_("data size prefix invalid with `%s'"), i.tm.name); - return; + /* Check for data size prefix on VEX/XOP/EVEX encoded and SIMD insns. */ + if (i.prefix[DATA_PREFIX]) + { + as_bad (_("data size prefix invalid with `%s'"), i.tm.name); + return; + } + + /* Don't allow e.g. KMOV in TLS code sequences. */ + for (j = i.imm_operands; j < i.operands; ++j) + switch (i.reloc[j]) + { + case BFD_RELOC_386_TLS_GOTIE: + case BFD_RELOC_386_TLS_LE_32: + case BFD_RELOC_X86_64_GOTTPOFF: + case BFD_RELOC_X86_64_TLSLD: + as_bad (_("TLS relocation cannot be used with `%s'"), i.tm.name); + return; + default: + break; + } } /* Check if HLE prefix is OK. */ @@ -6785,26 +6801,6 @@ match_template (char mnem_suffix) } } - switch (i.reloc[0]) - { - case BFD_RELOC_386_GOT32: - /* Force 0x8b encoding for "mov foo@GOT, %eax". */ - if (t->base_opcode == 0xa0 - && t->opcode_modifier.opcodespace == SPACE_BASE) - continue; - break; - case BFD_RELOC_386_TLS_GOTIE: - case BFD_RELOC_386_TLS_LE_32: - case BFD_RELOC_X86_64_GOTTPOFF: - case BFD_RELOC_X86_64_TLSLD: - /* Don't allow KMOV in TLS code sequences. */ - if (t->opcode_modifier.vex) - continue; - break; - default: - break; - } - /* We check register size if needed. */ if (t->opcode_modifier.checkregsize) { @@ -6835,12 +6831,19 @@ match_template (char mnem_suffix) && i.types[1].bitfield.instance == Accum && i.types[1].bitfield.dword) continue; - /* xrelease mov %eax, is another special case. It must not - match the accumulator-only encoding of mov. */ - if (i.hle_prefix - && t->base_opcode == 0xa0 + + if (t->base_opcode == MOV_AX_DISP32 && t->opcode_modifier.opcodespace == SPACE_BASE) - continue; + { + /* Force 0x8b encoding for "mov foo@GOT, %eax". */ + if (i.reloc[0] == BFD_RELOC_386_GOT32) + continue; + + /* xrelease mov %eax, is another special case. It must not + match the accumulator-only encoding of mov. */ + if (i.hle_prefix) + continue; + } /* Fall through. */ case 3: