From patchwork Tue Feb 4 22:19:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 105995 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7285B3858C33 for ; Tue, 4 Feb 2025 22:21:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7285B3858C33 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=cRRetwxd X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-yw1-x1131.google.com (mail-yw1-x1131.google.com [IPv6:2607:f8b0:4864:20::1131]) by sourceware.org (Postfix) with ESMTPS id 51C123858D20 for ; Tue, 4 Feb 2025 22:20:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 51C123858D20 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 51C123858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1738707605; cv=none; b=SOO3ZmWy6df+Izd0HLEc+M94DtzwJlMVgVI4D1tpy2MkqfXb4RP8+ok5im6b9M1XJp+vPHEpyKC52HoqzLKE+00imWb0DBiuT4VT33IH2B8mhjrIemYeJO2Aq+bjD4JQCL+2Ou/B6/pJQTQjr+0aTIpUqMn8jCoplB5WpkonIuw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1738707605; c=relaxed/simple; bh=PTUvcGMYUKJkc8YfBjs7gNcWtSGZHtKT+6Gl1FYcU60=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=aQmOR2Lk/TqtRlTOHwN4zY79HQwfJHqlGqTCI6qUWsf58HrAIub8t4zMo5XMx02e/Y4D9IPUUoODNSl8fphWHCfM+tbnuR4YyZX7hYzXozvr6qAWiuF4Dpm6rtr1HFD7fVNAo7yj6tGAtUKZp/L7PGOXhN50Tt82itjZhSPhfI0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 51C123858D20 Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-6f666c94285so42906287b3.3 for ; Tue, 04 Feb 2025 14:20:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738707604; x=1739312404; darn=sourceware.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=mIXhT54rfT7ellSH1KFveWIKq8x+jU2jY9R7DRqkgic=; b=cRRetwxdU0X3YHPRX+I+9jcbZ2wRNWj0wdxrCPgzH5x8WHdXe0dKiQtzkEzjASG16X sNoQi8fmj5/pprOq2tT2RvWinyq/3MO/2/ThQ233q/hf0mKz3tZmsL7vjwL6FkvLFIh0 EH9bHErgCnRaaNynA416BOxLjwSeGbftNVvTts8mBDDRGyoLGWwh+/dhRW5EeSmkHUPh fkhlyzQFawtruM+FRfu4pABtpHlHfOfO+yFcY3zXfWU5cU8I2UOA6W/sjrttGrnaJZ5O pEUwnVaq9CxutoYzvXs8VtyX6eD+Guf162Kbdrn8i4/WQ9uXBKgsOWJA5uBYy5s21i/x ULdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738707604; x=1739312404; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=mIXhT54rfT7ellSH1KFveWIKq8x+jU2jY9R7DRqkgic=; b=XPsvAlm3K0qrnmDg7RCc29y5px7WYYDGsUZh4lI55AVK2a9MwSBo9T7QW1xOWzfHhy l245FNRDi3dZt3mG9VsiWo9CMKYNTeJQB4c7guuWtBjWrpk8tYG3ZAnwe9HsaGIWUcKH RB0lsqcdA0AVlD7+3A/eD4zW2+MnJKxtwXgODsrn204kuZGvSoHWOQPmO5SYRyxU62Ii 6U9DUGwekrI+0qHbU0W4NMsLqkcICOMYTgM97816199Eo36Xt3fQz4fr6OVcwNr7ryCS 7YZJhAmtogm1IzN/s33OLTO0P9xfU5tRsR9V7NACClt3DtPWSH3eq928ls+bOAhX0AqE nl4w== X-Gm-Message-State: AOJu0YznguY3mhgFV55jMXI9nov+WFlHkdslmAuPYN7EfWFM8rJg+7xH CPS7BbLilEVOEfEvmx79dP37jnVxr4HABINieNxQlcbyTB46DVwBsv70Fj3DgonPN3eqcPcASjn mybBx8mEEhTwJDd8rD7IGnPhwT5RmuKMATMRkVXtgQv0= X-Gm-Gg: ASbGncsAblbR3wWGedMcn0k2tM/RYDNC2bo1oFp9ot6q/3zWy3YiAKrr+TBqwiytS/R cQ5g/4Mwth4EKONvnlxQL3NclS/LPfswlgWkxIErmQsdBFIOfAeIgc9tTGxenAZmW1+QC52c= X-Google-Smtp-Source: AGHT+IGzP7eG6SpXdmBKtxBvEiaJbZSajhOSbThY+lFZOo/EAyMK8gFQADG1tq6rZS9t5Bi3k5QZuQpZBeZ2bb64g2w= X-Received: by 2002:a05:690c:6486:b0:6f6:c97d:e642 with SMTP id 00721157ae682-6f989ee003emr5933037b3.16.1738707604379; Tue, 04 Feb 2025 14:20:04 -0800 (PST) MIME-Version: 1.0 From: "H.J. Lu" Date: Wed, 5 Feb 2025 06:19:28 +0800 X-Gm-Features: AWEUYZmzIWdqY2k0laLrdHOwpQ_gwjCbsbotHlHuxRz8ap7_u2MPse3Fip4GspQ Message-ID: Subject: [PATCH] x86: Disallow GOT memory as vector memory operand To: Binutils , Jan Beulich X-Spam-Status: No, score=-3015.7 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 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~patchwork=sourceware.org@sourceware.org GOT memory is 4-byte for i386 and 8-byte for x86-64. Disallow GOT memory as vector memory operand. PR gas/32624 * config/tc-i386.c (output_disp): Disallow GOT memory as vector memory operand. * testsuite/gas/i386/i386.exp: Run inval-got. * testsuite/gas/i386/inval-got.l: New file. * testsuite/gas/i386/inval-got.s: Likewise. * testsuite/gas/i386/x86-64-inval-got.l: Likewise. * testsuite/gas/i386/x86-64-inval-got.l: Likewise. * testsuite/gas/i386/x86-64.exp: Run x86-64-inval-got. From 4b17304863a821b899597e85d44e82df189884e1 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Wed, 5 Feb 2025 06:13:37 +0800 Subject: [PATCH] x86: Disallow GOT memory as vector memory operand GOT memory is 4-byte for i386 and 8-byte for x86-64. Disallow GOT memory as vector memory operand. PR gas/32624 * config/tc-i386.c (output_disp): Disallow GOT memory as vector memory operand. * testsuite/gas/i386/i386.exp: Run inval-got. * testsuite/gas/i386/inval-got.l: New file. * testsuite/gas/i386/inval-got.s: Likewise. * testsuite/gas/i386/x86-64-inval-got.l: Likewise. * testsuite/gas/i386/x86-64-inval-got.l: Likewise. * testsuite/gas/i386/x86-64.exp: Run x86-64-inval-got. Signed-off-by: H.J. Lu --- gas/config/tc-i386.c | 12 ++++++++++++ gas/testsuite/gas/i386/i386.exp | 1 + gas/testsuite/gas/i386/inval-got.l | 12 ++++++++++++ gas/testsuite/gas/i386/inval-got.s | 3 +++ gas/testsuite/gas/i386/x86-64-inval-got.l | 12 ++++++++++++ gas/testsuite/gas/i386/x86-64-inval-got.s | 3 +++ gas/testsuite/gas/i386/x86-64.exp | 1 + 7 files changed, 44 insertions(+) create mode 100644 gas/testsuite/gas/i386/inval-got.l create mode 100644 gas/testsuite/gas/i386/inval-got.s create mode 100644 gas/testsuite/gas/i386/x86-64-inval-got.l create mode 100644 gas/testsuite/gas/i386/x86-64-inval-got.s diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c index 2b5f07519f9..f276b63956d 100644 --- a/gas/config/tc-i386.c +++ b/gas/config/tc-i386.c @@ -12788,6 +12788,18 @@ output_disp (fragS *insn_start_frag, offsetT insn_start_off) p = frag_more (size); reloc_type = reloc (size, pcrel, sign, i.reloc[n]); + + if (GOT_symbol + && ((reloc_type == BFD_RELOC_386_GOT32 + && !i.tm.operand_types[n].bitfield.dword) + || (reloc_type == BFD_RELOC_32_PCREL + && !i.tm.operand_types[n].bitfield.qword)) + && (i.tm.operand_types[n].bitfield.xmmword + || i.tm.operand_types[n].bitfield.ymmword + || i.tm.operand_types[n].bitfield.zmmword + || i.tm.operand_types[n].bitfield.tmmword)) + as_bad (_("invalid GOT memory operand")); + if (GOT_symbol && GOT_symbol == i.op[n].disps->X_add_symbol && (((reloc_type == BFD_RELOC_32 diff --git a/gas/testsuite/gas/i386/i386.exp b/gas/testsuite/gas/i386/i386.exp index b4d33cc7500..a22e96c77f6 100644 --- a/gas/testsuite/gas/i386/i386.exp +++ b/gas/testsuite/gas/i386/i386.exp @@ -53,6 +53,7 @@ if [gas_32_check] then { run_list_test "general" "-al --listing-lhs-width=2" run_list_test "inval" "-aln" run_list_test "inval-16" "-al" + run_list_test "inval-got" "-al" run_list_test "segment" "-al" run_list_test "inval-seg" "-al" run_list_test "inval-reg" "-al" diff --git a/gas/testsuite/gas/i386/inval-got.l b/gas/testsuite/gas/i386/inval-got.l new file mode 100644 index 00000000000..e6327d9699d --- /dev/null +++ b/gas/testsuite/gas/i386/inval-got.l @@ -0,0 +1,12 @@ +.*: Assembler messages: +.*:3: Error: .* +GAS LISTING .* + + +[ ]*1[ ]+\.text +[ ]*2[ ]+# All the following should be illegal +[ ]*3[ ]+\?\?\?\? 62F27548 vpermb foo@got, %zmm1, %zmm0 +.* Error: invalid GOT memory operand +[ ]*3[ ]+8D050000 + +[ ]*3[ ]+0000 +#pass diff --git a/gas/testsuite/gas/i386/inval-got.s b/gas/testsuite/gas/i386/inval-got.s new file mode 100644 index 00000000000..66c7fcc3b26 --- /dev/null +++ b/gas/testsuite/gas/i386/inval-got.s @@ -0,0 +1,3 @@ + .text +# All the following should be illegal + vpermb foo@got, %zmm1, %zmm0 diff --git a/gas/testsuite/gas/i386/x86-64-inval-got.l b/gas/testsuite/gas/i386/x86-64-inval-got.l new file mode 100644 index 00000000000..0cd11edff97 --- /dev/null +++ b/gas/testsuite/gas/i386/x86-64-inval-got.l @@ -0,0 +1,12 @@ +.*: Assembler messages: +.*:3: Error: .* +GAS LISTING .* + + +[ ]*1[ ]+\.text +[ ]*2[ ]+# All the following should be illegal for x86-64 +[ ]*3[ ]+\?\?\?\? 62F27548 vpermb foo@GOTPCREL\(%rip\), %zmm1, %zmm0 +.* Error: invalid GOT memory operand +[ ]*3[ ]+8D050000 + +[ ]*3[ ]+0000 +#pass diff --git a/gas/testsuite/gas/i386/x86-64-inval-got.s b/gas/testsuite/gas/i386/x86-64-inval-got.s new file mode 100644 index 00000000000..11afb783ed4 --- /dev/null +++ b/gas/testsuite/gas/i386/x86-64-inval-got.s @@ -0,0 +1,3 @@ + .text +# All the following should be illegal for x86-64 + vpermb foo@GOTPCREL(%rip), %zmm1, %zmm0 diff --git a/gas/testsuite/gas/i386/x86-64.exp b/gas/testsuite/gas/i386/x86-64.exp index edacbaa0f20..f1462e36131 100644 --- a/gas/testsuite/gas/i386/x86-64.exp +++ b/gas/testsuite/gas/i386/x86-64.exp @@ -71,6 +71,7 @@ run_dump_test "x86-64-stack" run_dump_test "x86-64-stack-intel" run_dump_test "x86-64-stack-suffix" run_list_test "x86-64-inval" "-al" +run_list_test "x86-64-inval-got" "-al" run_list_test "x86-64-segment" "-al" run_dump_test "x86-64-segovr" run_list_test "x86-64-inval-seg" "-al" -- 2.48.1