From patchwork Fri Aug 11 18:52:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jose E. Marchesi" X-Patchwork-Id: 134640 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp1291646vqi; Fri, 11 Aug 2023 11:54:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF8rPf4U9xYuEWKGGNzW5FlbTEtvKtV78nmFkubOtB+WGFQtzQOmXr9KAFZe+PmoX05rsYH X-Received: by 2002:a2e:9f4f:0:b0:2b4:7f66:8c92 with SMTP id v15-20020a2e9f4f000000b002b47f668c92mr2279949ljk.31.1691780042202; Fri, 11 Aug 2023 11:54:02 -0700 (PDT) Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id g6-20020a17090613c600b009926007b7dasi3656610ejc.126.2023.08.11.11.54.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 11:54:02 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.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=@gcc.gnu.org header.s=default header.b=XacEmWy2; arc=fail (signature failed); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 90AEC385C423 for ; Fri, 11 Aug 2023 18:53:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 90AEC385C423 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691780023; bh=m00pb+s1wC7I3kRqad8Sk0C88GDj4nS2AOGcwUfFFOU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=XacEmWy2N5ab9UA4C5yL2t/oMUTxAFYgMpYPQOto3MRv91Ex1cRp0pp754rrjjNvX Nu0ky+NzSuxja/Y6ZgoiVlGzBc+LkrRe7RpQwbwtRRLiAF7b1z/THzcfjpqtsTGuS+ EJXKHZ02FqOIGYG/gW2PnbRLHolU4HSJJW6bPxt0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 8A8FF3858D20 for ; Fri, 11 Aug 2023 18:52:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8A8FF3858D20 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37BDODFb001105 for ; Fri, 11 Aug 2023 18:52:57 GMT Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3sd8y5hpqg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 11 Aug 2023 18:52:57 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 37BI7d25003105 for ; Fri, 11 Aug 2023 18:52:55 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2169.outbound.protection.outlook.com [104.47.56.169]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3s9cvafke3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 11 Aug 2023 18:52:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XgepacfdKoYOway49G2dBGPjrVzPRjAJ7pPtvzcl+guLQ5INu51WFJkdXOX/pnABpDsvqVylDCrXaBGPSLpQKsuZtkhHW9Ajh+XnO8lkm/YD7DPVXgyFWi808lZnZnX56TU1HFar4C1hljfixehxAdWBMCk0tFEwXUo+na7YbN4RFHwl0E0/7M0RKYXkU5cro1t/O7IGsYeCbct/65Ov9oKsWklKkEj04YPhf8Ydxk254/nA+rDdSGgLuu+MRfBfjqk3wDZ/Mgo6E8m3UzYN2OEdNwcUmQApUNkHs95E+9DhpfD234ejffaSDbW5fwjIb64tYcJhKPVZZLCvWBtwNg== 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=m00pb+s1wC7I3kRqad8Sk0C88GDj4nS2AOGcwUfFFOU=; b=NqyTSCthDNQEnvqjyCVIRA7XQQsbP5v2WBUmqUrf2XaOhp6zYx9kt6+LltyiF1Et/ku3NGNAaESt0tkCzyE+qSLnCY3WRjXOCbf8MLseuU5J3t1KqZf+QZrAV1RaqX9ho2Y5YZAq63YTKM5gR9yh2Tr5R0AkoOqHoN8l/fjKj6S3TPFi9JgLu1B8VmwZAXnk6Sd2C1Q1dcxLSo5irEAkAWv6aMoeVZJ8p4GjkIMUjp5m91WeMi318Esqoxe0NkgUIedQ8elthAX94EoA3yM/Q5cnwQk7zyfSTRI6ElNKQQKTvfnVrrPmLJJ3ds3r5Zu9HfcrRl1S6BndmeNbdjpE2g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none Received: from BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) by CH3PR10MB7573.namprd10.prod.outlook.com (2603:10b6:610:178::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.20; Fri, 11 Aug 2023 18:52:53 +0000 Received: from BYAPR10MB2888.namprd10.prod.outlook.com ([fe80::991c:237e:165e:1af]) by BYAPR10MB2888.namprd10.prod.outlook.com ([fe80::991c:237e:165e:1af%3]) with mapi id 15.20.6652.028; Fri, 11 Aug 2023 18:52:53 +0000 To: gcc-patches@gcc.gnu.org Subject: [COMMITTED] bpf: allow exceeding max num of args in BPF when always_inline Date: Fri, 11 Aug 2023 20:52:47 +0200 Message-Id: <20230811185247.5228-1-jose.marchesi@oracle.com> X-Mailer: git-send-email 2.30.2 X-ClientProxiedBy: AM0PR06CA0134.eurprd06.prod.outlook.com (2603:10a6:208:ab::39) To BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB2888:EE_|CH3PR10MB7573:EE_ X-MS-Office365-Filtering-Correlation-Id: 3e99a954-d32c-4556-d863-08db9a9c2ae6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NtmWmPnlzlJmMy6/7ICKgQWQybVtExaUwUYee7syv6JPZscRmIdF9u6OSwmzPgkEg50LhC9A7y5oAO88XNFjYCW/ETnDlCLHAbgl4EgSwbfqtr4R4J4RvYFjbWkVnkujPMcQSumQIb7wJaZ+3R1PUZiiP6tk4LZ4/Yj6EDNW/GknKTu3F2S3pZxESx4pgEaNvoq+N9O2+hCMPDJeWtqEjsIc0udwJS6s7NurcgnxFTdIDcEGxW8Nt3i+XnK58EbwYhxvm9BVS/NbhBNZfgBaeU5LGtcLFDztX98X9kbf8dmxGv2MdzGLkQTc3GNUq4vWZCQ2nOKbhxP4AiPE0vnjyJxCfmSF7WqmO4I8Syqn8xiDl+3tUIm6VoAc6aTDoWjJr7oNbe8CPeBKLKF/o7yl1h9cgkNe0rW67ilGyj7BoEqc3Sk7QHx+JWlj7biB9ibWYumecgCLOnXZApv2NdRSW+kz8peVdlln9bVbkp27zc/YVKmPIqVzuawtNe1UdmsztjEzGYnn1ZA0Oe4FFpLpRY7X+rbMKMlG60sEOhrp5qfiBDOuUoQ5Ys8oMRAPa1aDi4WtK9F8CpS/7FlW204ArQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2888.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(376002)(39860400002)(136003)(366004)(346002)(396003)(451199021)(186006)(1800799006)(6512007)(6486002)(478600001)(6666004)(83380400001)(1076003)(6506007)(26005)(2616005)(2906002)(5660300002)(66476007)(66946007)(66556008)(6916009)(316002)(41300700001)(8676002)(8936002)(86362001)(36756003)(38100700002)(84970400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: KevL0sg/yhNCVPDXCcf+bI5CIk07N8T1WVt5StOAPyKBOtPVUCQ9euWfCogZZWk+/3n8E9zvifKrF5VoaBVZKzajaWgVixc6Y/ZQAXSrJTtR0lMBcldja73GMTTHZyo3OEM3ZlziAJkSYHsPL1AqNPqIi0iUXbyL/GvIaDvd/n57Bc2SmBGOJjZ3fPPlDJZdRcgZEQF/0gKRTQihUW8G3oUdx/qKica8ytcWa26BoCVtobWBiT9PSq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Eg0frAtojEFGv4j6IFP6isGBc/J0Zla1NsAELA X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3e99a954-d32c-4556-d863-08db9a9c2ae6 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2888.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Aug 2023 18:52:52.9909 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 4WBqDdEaZQM2l0S9PJHpKlONic08hrV701zdSQ/BUPCH+X1lgcCsQlD7VCnXdA0pI+bLTDj22JRfCWVpWE9zHmSa+wutVjLD+j4K2jFjKZY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR10MB7573 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-08-11_10,2023-08-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=935 bulkscore=0 adultscore=0 mlxscore=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2308110172 X-Proofpoint-GUID: 1sHjh2lvFSjVPPTHHRF0-lw-O2oTIFD7 X-Proofpoint-ORIG-GUID: 1sHjh2lvFSjVPPTHHRF0-lw-O2oTIFD7 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "Jose E. Marchesi via Gcc-patches" From: "Jose E. Marchesi" Reply-To: "Jose E. Marchesi" Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773959949226446151 X-GMAIL-MSGID: 1773959949226446151 BPF currently limits the number of registers used to pass arguments to functions to five registers. There is a check for this at function expansion time. However, if a function is guaranteed to be always inlined (and its body never generated) by virtue of the always_inline attribute, it can "receive" any number of arguments. Tested in host x86_64-linux-gnu and target bpf-unknown-none. gcc/ChangeLog * config/bpf/bpf.cc (bpf_function_arg_advance): Do not complain about too many arguments if function is always inlined. gcc/testsuite/ChangeLog * gcc.target/bpf/diag-funargs-inline-1.c: New test. * gcc.target/bpf/diag-funargs.c: Adapt test. --- gcc/config/bpf/bpf.cc | 9 +++++++- .../gcc.target/bpf/diag-funargs-inline-1.c | 21 +++++++++++++++++++ gcc/testsuite/gcc.target/bpf/diag-funargs.c | 8 ++++++- 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/bpf/diag-funargs-inline-1.c diff --git a/gcc/config/bpf/bpf.cc b/gcc/config/bpf/bpf.cc index 33218b3a818..d27a971d0af 100644 --- a/gcc/config/bpf/bpf.cc +++ b/gcc/config/bpf/bpf.cc @@ -732,7 +732,14 @@ bpf_function_arg_advance (cumulative_args_t ca, unsigned num_words = CEIL (num_bytes, UNITS_PER_WORD); if (*cum <= 5 && *cum + num_words > 5) - error ("too many function arguments for eBPF"); + { + /* Too many arguments for BPF. However, if the function is + gonna be inline for sure, we let it pass. Otherwise, issue + an error. */ + if (!lookup_attribute ("always_inline", + DECL_ATTRIBUTES (cfun->decl))) + error ("too many function arguments for eBPF"); + } *cum += num_words; } diff --git a/gcc/testsuite/gcc.target/bpf/diag-funargs-inline-1.c b/gcc/testsuite/gcc.target/bpf/diag-funargs-inline-1.c new file mode 100644 index 00000000000..e917ef1294e --- /dev/null +++ b/gcc/testsuite/gcc.target/bpf/diag-funargs-inline-1.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "" } */ + +inline int __attribute__ ((always_inline)) +foo (int a1, + int a2, + int a3, + int a4, + int a5, + int a6) +{ + return a1 + a2 + a3 + a4 + a5 + a6; +} + +int +bar (int i1, int i2, int i3, int i4, int i5) +{ + return foo (i1, i2, i3, i4, i5, 10); +} + +/* { dg-final { scan-assembler-not "call\t.*" } } */ diff --git a/gcc/testsuite/gcc.target/bpf/diag-funargs.c b/gcc/testsuite/gcc.target/bpf/diag-funargs.c index d4e9c0683f2..42b5f05b67c 100644 --- a/gcc/testsuite/gcc.target/bpf/diag-funargs.c +++ b/gcc/testsuite/gcc.target/bpf/diag-funargs.c @@ -11,5 +11,11 @@ foo (int a1, /* { dg-error "too many function arguments" } */ int a5, int a6) { - return a6; + return a1 + a2 + a3 + a4 + a5 + a6; +} + +int +bar (int i1, int i2, int i3, int i4, int i5) +{ + return foo (i1, i2, i3, i4, i5, 10); }