From patchwork Fri Nov 4 10:53:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 15470 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp318528wru; Fri, 4 Nov 2022 03:55:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6MI0OUY+hmQIFXMkniw3tvh/2frZN6J31wSRteXGD4a17qcvoQUgARIB7cCC9s4YHPXKGE X-Received: by 2002:a05:6402:50cf:b0:462:352e:f4a7 with SMTP id h15-20020a05640250cf00b00462352ef4a7mr34329810edb.317.1667559302835; Fri, 04 Nov 2022 03:55:02 -0700 (PDT) Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id b7-20020a056402084700b0045d4b7ad0e4si6180399edz.400.2022.11.04.03.55.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 03:55:02 -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=m6IbbMI3; 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 07C013857C70 for ; Fri, 4 Nov 2022 10:54:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 07C013857C70 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1667559284; bh=TEll+SIR6qsWxiuCdQIbb/1y25xnwWfrLUs6Rdn+PrU=; 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=m6IbbMI3FqvLnRhgSOm453vMuri3Cw+wH6N0m1XszSn/REs8DgG0Iq0lbeobIrVuZ tndg1ggjwa7H2DBrlBWaULm9mWT2GSba9SeOQO796TVRUKKh7Q0BJKYB59LlFpqA6d D7yn/7wBbd7TGrmP4NaSfFXlkHRfqzd0BzqRvog8= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60062.outbound.protection.outlook.com [40.107.6.62]) by sourceware.org (Postfix) with ESMTPS id 1F3403857C7C for ; Fri, 4 Nov 2022 10:53:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1F3403857C7C ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YZPV/qEVJkpimVKuLtj/USa+gmaOIiAJX072qQ30W4s1mDyQS8U10Qvk54X62JTnRHs/wu9dyxmVyiYKtAYDT4GDaE7HVJATmCHjgP0DtST6nab/3T8hJgG4B5FmayGPpiTnbzXwrtLzjMFxzfjjodFXIVoF2gSay1EveV/7r3jFcg8Cl/AkLP8WQacl/paFzX8Qq7OkisojwU7fiuV6iwEAfU3BMlg9bUjopnGHbSvEkyBku9WrvOg5XCEew9fSkRiKzs/wYCkuN4ayTOIXfo/xCuS+vVbEZWfIjPDu7wvbK1zadjwMY98LjPcD72s8m4ZabACG35je6Kku2GukVw== 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=TEll+SIR6qsWxiuCdQIbb/1y25xnwWfrLUs6Rdn+PrU=; b=oEqbCDzTeQ/HVE4IoWvN/qYjpcabZ3oF9UuytkdQ7DU7xlLmJGVj/e0G9rAEpH0elxLF0EpNqdq0Vh57FcO0ibkCMYlhjsoMeaxXY/gd4McZ6PyA6V/jf33jHs6dFxi210+WbzpSJ7X8wE9CgWGOnS2uP8L1JWt+kO/2nDeW6KMNZO3k9hQ2ViG1FsPPoFy+3yHcRAxRBaTDMaddgV2Z4g8RFFQ/YFLu715IIdLexYcY7RAAIFslXk8la0LZ7mZ/oGY6TtKHWb2yzfXA3tZdpG0fVB/mV5D43xWroD3fdc6MjoqM6lIDoM82nLGJx0tqQz2umC0T1mBshAR9BSlO3g== 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 DBAPR04MB7397.eurprd04.prod.outlook.com (2603:10a6:10:1a9::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.20; Fri, 4 Nov 2022 10:53:16 +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.5791.022; Fri, 4 Nov 2022 10:53:16 +0000 Message-ID: <352d1e49-ac9f-ee86-7e9d-74f79744268b@suse.com> Date: Fri, 4 Nov 2022 11:53:14 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: [PATCH v6 5/7] x86: move bad-use-of-TLS-reloc check Content-Language: en-US To: Binutils References: <6d71dc80-91c8-7bc8-c57f-4f771ca59fab@suse.com> In-Reply-To: <6d71dc80-91c8-7bc8-c57f-4f771ca59fab@suse.com> X-ClientProxiedBy: AM6PR05CA0003.eurprd05.prod.outlook.com (2603:10a6:20b:2e::16) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|DBAPR04MB7397:EE_ X-MS-Office365-Filtering-Correlation-Id: f6659512-9263-4cb7-092b-08dabe52c70c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZFmo3+h6pYhx4CFEjKYuvss2h16+30Ip39eePWIeGYt1Uw6oyMUL2K8HfgJwLhy2TN9bPTuJ3VYHNCqY0wztuaZ1Lq+t1iI9t5RuEUsmr0sEHa4skI4vyEZYoR9McSyhON0jQ/m7Lv4thLaBM0ge0zBipX4F0+51exFBfjYTBzK52F8OyOJBYoe3s+l3mY5e+ikURCyLd14fpmQGeFxtt2EblYaCaItvq5J563qs1JQR34rqPC0ogm3POqdb1AudpkudWRDjIh3+ivj/33WHIU76tMANHLWrkzunwQ9sx2ri42OV0i78EV97asuWOZSH29mO98a1k2oB/bvv1KxbXYYrjXPjJ4MGbX+eEQ4vyI6vVhqOYWGWB3tErgCFpjZN+5JgncHjfSeZ0vvt96dF5nDi/Fvq0Wl1sJwv2FJMdTvAp5kbqE+BWQWClgtgS5XF2RVVYr3fRetja+OKX6eSZBOpL5nZ8XvKypNH5GggE1SKWvoW8YXKGU7gSl2ctiVXh8KRMStHaKz1JeyDXxvgXhUNdeMNxgMRu9wOpuSEQRFrsbbtOmRCcq2M3+EPAUgtxa7mD2qPfScgxhaomCjXNTKOac3X/la94dcynN6UlcSdkUQFKvyxAOhmXcyNuRcHa3dSM8JATsud06/+voedSj/WDBW+uOM9hyZAojGRMHRq5O9U3oRHX9p6g6qM2llgd8fiw7gBQc/VpDogt3/ghuGBf2pN5/+dULKoV7O169lETu/hQLJktmXkfdY6rKxjQIaDlcjG91nxGv4T/iiuQ0URnYICB+swvu994YV67XM= 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)(366004)(346002)(136003)(39860400002)(376002)(396003)(451199015)(316002)(478600001)(6512007)(31696002)(86362001)(186003)(6486002)(26005)(6506007)(6916009)(2616005)(36756003)(2906002)(8676002)(8936002)(41300700001)(31686004)(38100700002)(4326008)(5660300002)(66946007)(66476007)(66556008)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?zoSloQ3qDIwO4HcsLJbMrka/NSBX?= =?utf-8?q?PDzVs/wduUnsR8ocIAr6gsh2gU7POja/VkbGH12naECMv3PE6o2pGzSxXg+cr/Wmj?= =?utf-8?q?4863mCu1R6iVZ66Shzp4pI6lxp+klvLjt5hmAQOp2NKBVZbXxVK68MB4yPmq/5Dus?= =?utf-8?q?YYXZGtrgG+qQGWHPjjagymXI6PWkjsSSOhux+d1QLtY2C2GsZ0QtwXqW1o7OyB5u9?= =?utf-8?q?xgYYs4AcAm/dCwabByaAh5hXerdbBG4RSJP+10GzU/DrSvVZr+/CCoHtBpCIUXSAc?= =?utf-8?q?e7KUAHwTd/hV4a5KQSMIZmf4f+z9hlBQv3j+3lvvtONnEoWbtx7IprS2sbcu07Ldx?= =?utf-8?q?eZ9eFHluMtLFsbNK/RIW9ESFB4slbgFhmMnjK5G7ilVWqoZuXoqy0QFdM0HCSCVQd?= =?utf-8?q?8QiqF8hcB6mPivFetKx0D4XXkgJOGCEnBsY9y22JNjeibuRu6uXEPZBfEjmeJ2prN?= =?utf-8?q?cIExxYUHfFRvpenTpk1NOpg6iuje0eh3pUXt5zybvxQMp24MphFGpO7nv1/3kndwR?= =?utf-8?q?BhcrKUkCRForSHuqpTOELWAhAdvWSK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sC3qFFGXETAYxbDL7T85g3hjnGxQD?= =?utf-8?q?e0xegNsxmgRboWMvNf3AUFm0vwUGHKnLY67olUKMmdZV+ZrnFA6aghKtDBg+CJBTQ?= =?utf-8?q?VijgDawn0H9c?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: f6659512-9263-4cb7-092b-08dabe52c70c X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2022 10:53:16.3646 (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: sgG0FKsKv7Hg+jIeVNZpXZZ6FIQG3zyxbGH2F0PNP6Ss4LrKshq31ycK5p38eyOEJN8so7I/o16nIhgPf/8azQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR04MB7397 X-Spam-Status: No, score=-3029.5 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?1748562663859498548?= X-GMAIL-MSGID: =?utf-8?q?1748562663859498548?= 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 @@ -5150,14 +5150,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. */ @@ -6822,26 +6838,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) { @@ -6872,12 +6868,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: