From patchwork Wed Oct 5 07:25:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 1717 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp475087wrs; Wed, 5 Oct 2022 00:26:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Db0+UrchdX6ddBVteLgQ9HNxcq1ZIa3GkY46VYIQFcDBmPIFtQddkF3tC+GEkSakhXqPr X-Received: by 2002:a17:907:c24:b0:78d:1167:32f7 with SMTP id ga36-20020a1709070c2400b0078d116732f7mr5782274ejc.739.1664954773356; Wed, 05 Oct 2022 00:26:13 -0700 (PDT) Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id j3-20020aa7c0c3000000b00458cf31627bsi7975720edp.266.2022.10.05.00.26.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Oct 2022 00:26:13 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=B8ZN+MdI; arc=fail (signature failed); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 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 6AC743858C50 for ; Wed, 5 Oct 2022 07:26:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6AC743858C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664954768; bh=WtqvlVgHTRvg38hx+/4SL/WXtVZp6twty8guhxOPlkQ=; 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=B8ZN+MdI29inmubLfMRPKS7B1qEtImHcPRyg/NC2N2dC9VQRGBLJ1vS7bTTHZTvhy 23iHFPr0z4nd90LiJEaPPPq+RhinyBkxKYZN4dwuFO1YqwjH3M9Na8Zaxav4zWytWm JoAV1cDfCHFjEP+4jkB/XqqytXnqphUuWvUeTtVo= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2048.outbound.protection.outlook.com [40.107.22.48]) by sourceware.org (Postfix) with ESMTPS id 5B7EB3857C4A for ; Wed, 5 Oct 2022 07:26:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5B7EB3857C4A ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HFiObY6kg3e4X1BghJ6oo0tpu3MUrSybGSj3VCwUoQXCs2ugHDSsFSZbM61tVF/uYtZqWtaddi55/WLNP2eayCyyZ17y0BwWkyNN1RmJmfJmeivfQ43sROASugtB08arB637jpdW0Zw2Ev0DSaZe9vuBLD6DjuWgc0qAvy48HFs+UcVxZChil2K9Q10VXKaLQmpaP7FxcIZr9UtPzpSA6tLIVEx896uvFk50NendxPIpMVjTwP9W0tedaEJDv1Lp48pg6jJJ4boDgMlQ5nVSfYAixEqozZVt92UTdiPOQGgtL0ATQBojEEZXyKZ2BO4TGVQSin98J59I8/kySs+Erw== 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=WtqvlVgHTRvg38hx+/4SL/WXtVZp6twty8guhxOPlkQ=; b=EuE+cHcP2LuA/uhu1AQQC93zQ4X/qbe5LXcFpzLGk0HDKIc0iRVL5I8YvtcaYEqDq8QbnOYLGDzlhZCUEMLfjM9bHKMOHyd2arLy4Iw8iW2FlFCw6tEwQBc1cbB0+RBPvLx2N5Y/OyrffbI+FCPqVnEmVG7wqlT6ZJqQLoYyh9tfcV9DKEixjLUGS1vCIm7VDVkhRU4FKIp7Kg34yhOoMKEwaO1jjqSWWgXjh43MlWmiu/ZrqOv25/8qU1gVjgkg/WloY77EqNAUzEXEMxR7Fau/YF2jqCeVf1yv5Wi421xIV2TYcnoBAf+NxTAxdX47wuO14xSN6vfYf1+NTrwiDg== 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 AS8PR04MB7751.eurprd04.prod.outlook.com (2603:10a6:20b:2a2::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.32; Wed, 5 Oct 2022 07:25:58 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2459:15ae:e6cb:218a]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2459:15ae:e6cb:218a%7]) with mapi id 15.20.5676.031; Wed, 5 Oct 2022 07:25:58 +0000 Message-ID: Date: Wed, 5 Oct 2022 09:25:57 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 Subject: [PATCH v3 7/7] x86: move bad-use-of-TLS-reloc check Content-Language: en-US To: Binutils References: <20e2773a-2e47-869b-1900-709f8ad4cd6b@suse.com> In-Reply-To: <20e2773a-2e47-869b-1900-709f8ad4cd6b@suse.com> X-ClientProxiedBy: FR3P281CA0017.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1d::20) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|AS8PR04MB7751:EE_ X-MS-Office365-Filtering-Correlation-Id: 4851b0fb-1cd3-424f-1041-08daa6a2d8e3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1t/gBHqMV2mMDH0UvHH3kwP/fnJK+g0z6PnharcCd1ge3iedUxC0AieRhBztaN+V3nzItKqxE5QqElTyiaamNs8Qo7/qC0KEN2RfRU2ETGzeFSyGId1skuxIT5qhn/dyczgRs6k0BcOD6a6HIU3nq6ikmcU4XVMP18Un9FERLMpAT2rgdpe6qbK6zkEOeWo9KoU/TyMvK+3QuA3kEdcJss7qSpCryzfy/n4/XVa3zU0bqrAiV9IJLV7km1JytZA8xIARH3ltFJiX5ZesABtrc7Zgx80inMACAGyg4UJFpbqGnbGqVoW4vzu4eBv2R9Je+c5+2XkSV08ezXZmGivdBz04JP7lI1ymw3ZwsGcsw7KPUzMv8Dl4q+LGW7Tmb3ABa56AxH8ikt2gXJPCqPMJfcfHujphEufb8OUeoaCcZNj5i/iaAo2d7ZipfbGGuZQsdk3sg4G/4oWGpa6xc/Eq10fBNWM9qVwyRm2y06o713h0bxBvx5p752+GjlsDjW9RvaTykzzGBYoN5oNJE4OO/42C/DtMwxGMBueScD/2c1B6jF2qCI7PMSva3HWQGqMycmOkIbmfxh/3feRKb2+aazrrBdeXvfZ66ZLb6lzryDDdHT90IWXSCRl0GSYdIXUFrVYgDJUImhkJt9sQYCEvvSyXgaU12k8aHMhkbwth0bYl25QaynykJr278OiLpfS9SoncF5Oc2FpdjXKXhAzWtSX38NIU6PmiL6dtZTj2FSSlb85RdNKzYxUWYSTnmbdxb+3VaxDzYL1BMFhy15W0Qbk1rQuLAqZ/BQwPEodtMJc= 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)(376002)(136003)(346002)(366004)(396003)(39860400002)(451199015)(31686004)(36756003)(31696002)(2906002)(5660300002)(2616005)(38100700002)(186003)(6506007)(6512007)(6486002)(478600001)(26005)(66946007)(66476007)(4326008)(316002)(86362001)(8676002)(66556008)(41300700001)(8936002)(6916009)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?qFrMvCXnEC2D2B4N9BRY8I4/KYzJ?= =?utf-8?q?riKPCwQZrgdE7gqWE05WaXsuMykZZjKxNqQe2xpe2rPgdwlFpaHxssgoNBanuUKxj?= =?utf-8?q?NtNLkB9n5yfvuZQrAdT8YbeZqVo9TEdQyawQICY0nqoD6Lbb0tuKwE5zFli+uCHTc?= =?utf-8?q?uTzJK3n3DgDkvqP63lfFyURE7HwCbPy84xeXJKbjtOSPX4eP1hOKBA7yiRtiFdYJk?= =?utf-8?q?39FXBRDZRIRnurLbats+cyJjQ/Hl1MeYaQmNBmZySXWp/MbejD30k+y7XHeZtt7wK?= =?utf-8?q?PYNrP7GvISn4FAnQAE0MPhYN6qHja1gOpYoF//Nd2+yzKmMXaPLvBEOd6qVW1Lw/N?= =?utf-8?q?Le5xos1GyGNnnSjVM1ObqLQr52PYRQKAsg5u2Dp550u0INW6ALzsCDxOt7404sgxi?= =?utf-8?q?7qGmTmkCYgy+j6Ij7Way9g4kRyU4G9ZHY4WnGHDsJe9cFjoZOX+caXI0uOiQYGe9P?= =?utf-8?q?Vo+jPTNedkehY3RrsbzPLKrDUkHs3gTH9/lTV80mKo+gzQA3JlZEasyF/5oQRe+2d?= =?utf-8?q?cSsqqhIrdEyUPE+oIjdUMPDD8s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Am/9mjWOsgfBLeSAnQfAZ4Zge7QLbq95vKzSc3aD?= =?utf-8?q?kYaNL9hHefWU7vHCuBrR+2Q0huAigsMR37bjzKR1Jn8HDQAShHIl4sOMkSrkxbDW7?= =?utf-8?q?xCQkrradlAuB?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4851b0fb-1cd3-424f-1041-08daa6a2d8e3 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Oct 2022 07:25:58.1112 (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: u5lULYvnpzcj1FCx4/iHZQ7GBHXtt2ib5BoH0TZt8TtJgEWo1no8ikf3mpip6zw/nKavm5opK3zmkWShm56K/Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB7751 X-Spam-Status: No, score=-3029.9 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?1745831616152735526?= X-GMAIL-MSGID: =?utf-8?q?1745831616152735526?= 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 @@ -5119,14 +5119,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. */ @@ -6767,26 +6783,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) { @@ -6817,12 +6813,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: