From patchwork Thu Feb 1 22:47:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 195495 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp72871dyc; Thu, 1 Feb 2024 14:48:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IHxfC8RYsniWTJv/L3cUDU0P5A0H6AU3ojDEn9unriywrKZCMBgUXbDRu5ZOPir/3s9+GzV X-Received: by 2002:ad4:5747:0:b0:68c:3df8:735e with SMTP id q7-20020ad45747000000b0068c3df8735emr193355qvx.63.1706827682639; Thu, 01 Feb 2024 14:48:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706827682; cv=pass; d=google.com; s=arc-20160816; b=wfWwbYND8dINzHlAqkQWRUT2eGNZ8sAKwvlvwxTuR9eEwjFRB5x6zsck2wUMA3bDA+ sLA7K7Ucm8LqU0ikU58+850ipUVscSZo1blDgRL4xBEpI3pey8LISNPgJtrLM5cItiQ9 nlpSvujv1jH6lxB3vXa+WdY6qvVwqrKMXI7Bk2GB7/nPACiDgFKvCm7T/26VKWRm/Y5Y 5u1fCyfoKWJuJpvawZHnd7VDEqrIs1iHRepSRHvRj8Z/912dqJB5QFgXF8+mITqu7yJQ 9heHvf31QVpX/Igg9iqaqxOctjPrQmO2i0K2nrAnVl4hcB7FH8WcoNJ2pAEeRgfXeNSS Mmng== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=TbXzJNSoez7obzZbUYE251WnozeyTbkB+a0+vSxFTwg=; fh=BlE+xZ+sYWebOL04y/1RiJMMGWevNDlWgo1zaTMlqCE=; b=z7tUxcX9h5O4w31zhz+N1SaQm4pZSMYpfaPS2sFqjJQMV5iTiFNePjvqQnJcKRIBdE swun9uhVXwgo8DFHER4ijcY+TTMbCBnRe4/t4LLwF+Rbwi9KRL0fzCbs28QjnB/ttYBl 00Zp92ZdsK3vv2u0L+sCWIQI8W2s+fba5ppSAWkgAAUnr+jPnr5CwB2TG2qBvS481Nyk ASD0vmTMaPZ3xPZ3foV65FuE7O2IzQRBkioE92m5QBvfkFFZi04mbN2CHND5Ta8G5EQ1 Pc5nRfiVyz3FuefbPklni0p/J9M6piNaNLZAU1TmHGFfncc837B+Yb+9NiKpHidqpxXl Ehtw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=laUPQBES; arc=pass (i=1); 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=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=1; AJvYcCVFeo8v0cmtfOJofu+qG+yv/bWh4NEq4962z+ziKbT/q8XS5qNVnN+0MuqmKrAKtV2NC5+yIKHpGy3Z/syvbBW3Nyik3A== Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id t5-20020a05621405c500b0068c5ca1a0a0si588908qvz.111.2024.02.01.14.48.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 14:48:02 -0800 (PST) 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=@gmail.com header.s=20230601 header.b=laUPQBES; arc=pass (i=1); 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 55A25385841D for ; Thu, 1 Feb 2024 22:48:02 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by sourceware.org (Postfix) with ESMTPS id 2326B3858D33 for ; Thu, 1 Feb 2024 22:47:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2326B3858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2326B3858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::534 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706827674; cv=none; b=fKTgtdLfpP82abzlXnqPwecm5+UyOC6WL+VBNfcQ9tUaT2MJcxrJE6bIRpr+Aa0AxA54v9HpkE7FazbbPAokYW2A2bwRmW+iTUUc8iCNeQeCbXXqh3zdG/L8sNErI6hn3iFLuUhSqZgM93/uVQtdV46IcHsrtRKOMP8ByGn1qcw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706827674; c=relaxed/simple; bh=99DMxUEQM9Lzm+Es47rIc/Cb1w0XbZ1zWtwQLlGNHHY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ieHIioBJKxDc+0l1qZCQreQFMThtgTIZTUhnOtTInllk7C1GYmPdXFtc/H+8VuKinMkaU9FYi9XpwUUEdb8ZOrhQyImSDGcVGmyWp/a5xC7aW34Xh0AH76F7X+/3R1fMZc2t6VVCDXy+tvdIDO8AkyNgwIkD+jOiFDagXrwPVIg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-5cddc5455aeso1357810a12.1 for ; Thu, 01 Feb 2024 14:47:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706827671; x=1707432471; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=TbXzJNSoez7obzZbUYE251WnozeyTbkB+a0+vSxFTwg=; b=laUPQBES6GyBQtfg4ESoAxW/CVcJ1T+LKPL+4oDkujiAzM/T4Nq3rhfFIIQAAv/Lqq ikMa5c8HZnK52Z/wm3vvwBDUFLLR7CXbR4VZjqf0+phY/SqqmuMJU/Ok/JubOTRl0msn FQu457yJ4YkQ3w8armgIxNa4WwjDxruYF1ENVa4lSTCRkfYMTQgUxdvsx1Ez+VL5C8+E TTe7rvFVYYyxXoByv+UExz2/UtmWRDgE4AVMC/du5CDO+GZLOmxC96pqOzEFFcRjBoaf UP1koCljSAR//of0B3esZnJYsN2/e9SkWLc8Z1QKy1Tjmd7CGOBiSSBqruN0kXxOs8ra W/xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706827671; x=1707432471; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TbXzJNSoez7obzZbUYE251WnozeyTbkB+a0+vSxFTwg=; b=oTjx92CUzjpY13ETG+XzgXWN8ysr+YWoX2nr9ptvBaFC/YDOZl6MJRc8VlRxSt5qFm eZp3OIiztK1waeDjQvZJlTzEKlbtcH9ROpDyJD4JyeDDQoHTp8ZEyN6kJwSbXqzybItF YYpsY0NbDweh8hceFabyW26tUBPpObp7Q+0Gl1MrXx79USeYcYwW5fp5wqBDZOapmecT 0K+TrU8hwEwe45FFeafD/eh/LD3Q5uNxM57JkjvfQhzH0RR7UHMBZkXjXlW7iAkJa2Ip MiKqlbS/1iSMboZ/iL5Y9SlDmxQQlynHGDIdB0VP1C0KV+/+hqKbas5l7kV6YCSrhXBd PW8w== X-Gm-Message-State: AOJu0Yw6lXHdWgRNgfpn2DwwLx/2cKE+yg1bG1EaFhlqLKjGICwk+UAo 1+RBgtIhfdqJ4dDiJZdlc/cZ+VNINpDBtzaF+G+6L0JeTxorDzeHruUtrLNE X-Received: by 2002:a17:90a:fd0f:b0:28c:fb86:23ce with SMTP id cv15-20020a17090afd0f00b0028cfb8623cemr422582pjb.44.1706827670948; Thu, 01 Feb 2024 14:47:50 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.56.169.51]) by smtp.gmail.com with ESMTPSA id i18-20020a17090acf9200b00295f71da63dsm3387155pju.53.2024.02.01.14.47.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 14:47:50 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id 583E6740270; Thu, 1 Feb 2024 14:47:49 -0800 (PST) From: "H.J. Lu" To: binutils@sourceware.org Cc: wwwhhhyyy333@gmail.com Subject: [PATCH] x86: Disallow APX instruction with length > 15 bytes Date: Thu, 1 Feb 2024 14:47:49 -0800 Message-ID: <20240201224749.214439-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-3023.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789738544270512886 X-GMAIL-MSGID: 1789738544270512886 It is a hard error when an APX instruction length exceeds the limit of 15 bytes: [hjl@gnu-cfl-3 pr31323]$ cat z.s addq $0xe0, %fs:0, %rdx [hjl@gnu-cfl-3 pr31323]$ as -o z.o z.s z.s: Assembler messages: z.s:1: Warning: instruction length of 16 bytes exceeds the limit of 15 [hjl@gnu-cfl-3 pr31323]$ objdump -dw z.o z.o: file format elf64-x86-64 Disassembly of section .text: 0000000000000000 <.text>: 0: 64 62 f4 ec 18 81 04 25 00 00 00 00 e0 00 00 (bad) ... [hjl@gnu-cfl-3 pr31323]$ We should issue an error when APX instruction length exceeds the limit of 15 bytes. PR gas/31323 * config/tc-i386.c (output_insn): Issue an error when APX instruction length exceeds the limit of 15 bytes. * testsuite/gas/i386/x86-64-apx-inval.l: New file. * testsuite/gas/i386/x86-64-apx-inval.s: Likewise. --- gas/config/tc-i386.c | 10 ++++++++-- gas/testsuite/gas/i386/x86-64-apx-inval.l | 3 +++ gas/testsuite/gas/i386/x86-64-apx-inval.s | 4 ++++ gas/testsuite/gas/i386/x86-64.exp | 1 + 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 gas/testsuite/gas/i386/x86-64-apx-inval.l create mode 100644 gas/testsuite/gas/i386/x86-64-apx-inval.s diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c index 3c64057fd67..d1e522d3637 100644 --- a/gas/config/tc-i386.c +++ b/gas/config/tc-i386.c @@ -11772,8 +11772,14 @@ output_insn (const struct last_insn *last_insn) { j = encoding_length (insn_start_frag, insn_start_off, frag_more (0)); if (j > 15) - as_warn (_("instruction length of %u bytes exceeds the limit of 15"), - j); + { + if (i.tm.cpu.bitfield.cpuapx_f) + as_bad (_("instruction length of %u bytes exceeds the limit of 15"), + j); + else + as_warn (_("instruction length of %u bytes exceeds the limit of 15"), + j); + } else if (fragP) { /* NB: Don't add prefix with GOTPC relocation since diff --git a/gas/testsuite/gas/i386/x86-64-apx-inval.l b/gas/testsuite/gas/i386/x86-64-apx-inval.l new file mode 100644 index 00000000000..6c1a346fcbf --- /dev/null +++ b/gas/testsuite/gas/i386/x86-64-apx-inval.l @@ -0,0 +1,3 @@ +.*: Assembler messages: +.*:3: Error: instruction length of 16 bytes exceeds the limit of 15 +.*:4: Error: instruction length of 16 bytes exceeds the limit of 15 diff --git a/gas/testsuite/gas/i386/x86-64-apx-inval.s b/gas/testsuite/gas/i386/x86-64-apx-inval.s new file mode 100644 index 00000000000..bb57817bc8a --- /dev/null +++ b/gas/testsuite/gas/i386/x86-64-apx-inval.s @@ -0,0 +1,4 @@ +# Check illegal 64bit APX_F instructions + .text + addq $0xe0, %fs:0, %rdx + xorq $0xe0, foo(%eax,%edx), %rdx diff --git a/gas/testsuite/gas/i386/x86-64.exp b/gas/testsuite/gas/i386/x86-64.exp index 6932ba97a4d..b77e8c10029 100644 --- a/gas/testsuite/gas/i386/x86-64.exp +++ b/gas/testsuite/gas/i386/x86-64.exp @@ -371,6 +371,7 @@ run_dump_test "x86-64-avx512f-rcigrne-intel" run_dump_test "x86-64-avx512f-rcigrne" run_dump_test "x86-64-avx512f-rcigru-intel" run_dump_test "x86-64-avx512f-rcigru" +run_list_test "x86-64-apx-inval" run_list_test "x86-64-apx-egpr-inval" run_dump_test "x86-64-apx-evex-promoted-bad" run_list_test "x86-64-apx-egpr-promote-inval" "-al"