From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 32A823858D28 for ; Fri, 17 Nov 2023 20:27:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 32A823858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 32A823858D28 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1700252861; cv=pass; b=JTsbnoUXhHLVLmGb/QAMJ7Sd9Jck7mLWmkeqndwzRy2dbaoK1Qn6AO5rhu5Ex/m9RcVsMg4w0AMNAHVSPRW4sFTJplS/Z+uJ1FsCIdPVjWzNBFHAvFZ+BIofDUBstCUsbvC0L5xxszIdBSJU8pmajBNnv7XBi1MwuHBYNUHET9c= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1700252861; c=relaxed/simple; bh=yo62VLQV10q0KmqUHzwTYNKfokRLS/riU6MVUwVfblQ=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=LMaw4wyWcauaVvGcJ23oFSZ0xyDUSq6vLlmEankreI/iz7tqLrCrobi55GY3ThO5J7OhGqLJK+jNG/v7XeHFFU0PR1MfFaHsf7PMLgBNSKiOwBQMeHJCmAgeU75+AztGCDItPa36cA5Zg5M8VxPWZnr4oY/p83A9Ut7EGKB3ME4= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AHIQ4Dg014203; Fri, 17 Nov 2023 20:27:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : in-reply-to : references : date : message-id : content-type : mime-version; s=corp-2023-03-30; bh=AhEMQeXsdHkvbJIy8lNYB3Co7HUTRPTTpEys1umQMp8=; b=DSzcskvVZwuQ/IluXfY2GFC+s5QAYeqa97VuT6arpFzQ1bf41yPyrs9psENvKvHLoCZr FMmJhoiLbnOl1UXKZEFjTVIIZYwvCNWzFuF9VW0+oVo3TNA/RUOzN23cNGmvC+oqCGIf 540sgjeRAej2kqKNfgidLaN8uDZMMqwphi9XBZeZRgApJF0OCmR+tf6KhXEqCBwpmUpJ txBrSc1/Or94ktrmh6L2v4QPJBSQWQUExXOm9wztyvTouGhVf3zyk/aBaTyHJ+jT5YK2 Eb/BdxIVuBHtVF9syZVwnsvewCFJ1eAEOgR/+DLPyPSc8AySUfJVon/J6VWSNmnbiM+t dA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ua2n3p28w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Nov 2023 20:27:37 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 3AHIgXkS015624; Fri, 17 Nov 2023 20:27:37 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2169.outbound.protection.outlook.com [104.47.55.169]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3uaxq2u0gt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Nov 2023 20:27:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YjDm/mZRIksiAERzuHWLr96XjRsVwigU7L1X0hIv9z4MJvL7NdYSdeC/1lGhBGROa6+M/R5qdhT1RzxMUX/adQka4andzG35suu2mCeegq8tYkTBagt/oXPUMz/SPWbywhxIb+aNC6n+FWMWzaT71a5+c7A5mT9XJ4WDFB8lKT7raWXlq9yDYk00nXX0vT5MO51kEdlindqb9HdemdhjeMnOC0aVkOyyiTiPJyLBl1fy8o+deQKX/QHdig3gdFPBuEkll+DMLU8fuBePYPRlzSDp/5C2SjSOFKsOFWQBy8f+eeJc5pg1zbnbKo4FQfHbnw/V9bX5ot8DyeXEMky/jA== 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=AhEMQeXsdHkvbJIy8lNYB3Co7HUTRPTTpEys1umQMp8=; b=Yj+1sxp3mzWUx8R2pgHtz/YXJivAHzVy/rmZlRNM3Hd1RmutHAaipal6zxYD8Fir8f4TBa4CazD9WoPlf56EKcZah2kcDErLfleQEs3PrrxxocsKi7eRxbiP9qHQXI9fph5jf1jdpLx57CkamaeY7pRGiz1Ec0sa/sw9yWc1c1Mg1qOQcBne7jGbTA2QtP/QxILBoYCIvk5O+AkZtFsl7zl1v3Uw9NGLgHyu3GDAsHOvsP43PQj8HzZgq4B55BTQKGSSgiTEjmSRi4zcmpJBCb+pnImCOJQKc+jHkVEhYNbZrPp9nzInw9g++znINlateV7otkaXevPpjq5Id2Lejg== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AhEMQeXsdHkvbJIy8lNYB3Co7HUTRPTTpEys1umQMp8=; b=tWYZyb0ES1dDuGKcKhYfzCiwVRmM1iUoW3esr5umeRR1tJxzYRSpYAlzwnLhvt62hhBtWozHgb2dmfvaiaLR10wStp9NkN81WqTBiyUID2n9gQ96q53IgRzdBJFf1G4S7E7A62RPD/mCDjPQ05oUC8ZzACqArKUxCaaeGdtdi2I= Received: from BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) by SJ0PR10MB4496.namprd10.prod.outlook.com (2603:10b6:a03:2d5::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.18; Fri, 17 Nov 2023 20:27:34 +0000 Received: from BYAPR10MB2888.namprd10.prod.outlook.com ([fe80::ba16:f585:1052:a61c]) by BYAPR10MB2888.namprd10.prod.outlook.com ([fe80::ba16:f585:1052:a61c%4]) with mapi id 15.20.7002.021; Fri, 17 Nov 2023 20:27:34 +0000 From: "Jose E. Marchesi" To: David Faust Cc: binutils@sourceware.org, jbeulich@suse.com Subject: Re: [PATCH v2] bpf: avoid creating wrong symbols while parsing In-Reply-To: <6e00c2b6-a561-41dd-8701-e13627d9c57f@oracle.com> (David Faust's message of "Fri, 17 Nov 2023 12:09:36 -0800") References: <20231117185428.10823-1-david.faust@oracle.com> <87edgo6uvr.fsf@oracle.com> <6e00c2b6-a561-41dd-8701-e13627d9c57f@oracle.com> Date: Fri, 17 Nov 2023 21:27:30 +0100 Message-ID: <877cmg6s7h.fsf@oracle.com> User-Agent: Gnus/5.13 (Gnus v5.13) Content-Type: text/plain X-ClientProxiedBy: LO2P265CA0139.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9f::31) To BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB2888:EE_|SJ0PR10MB4496:EE_ X-MS-Office365-Filtering-Correlation-Id: 6dd46c0f-965e-4eac-9aa9-08dbe7aba1d9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +vODTvRGKe+Kr58+lQ2b/TMuYNGYixi9ixvK2jA2doBnVMtrVnhReSiVMfdA9h6stPA6gBnC0JJMMiiTVLKkRuczahAp/Muw2hgLn2bP+UjQ+T98UDFqXP5+BmPOcccmbcvE0cpVgEfLxyv4vXiRO7HodGIyJG7zQoTYXSegs+397o5s7Z4N3GYvXF+G9B6dqP/kVGLKvwnSmh4tDMwA1X+ImvVE9ZKuRpx6u319bowfOmiPE0T5g/W6m5A8PIrxl1AE1lK4LPnF6XeyI4Q6cEFKEh+fWv+OQ20QGyIpgVhrLl108l4S+T3XSckPufyRjvK84s9qrLmS9ax2i5bPRRTjJ/MUijvPi6o+NK7Dxzc0dwpeibdTbs69/iAKNOPtQoQPWINuwmAUPgdC5gWJiBIteRI6fbuQqtvO+z4ZS26jWCAX/FJCA0qDUNZYNPIsOwfqcgGIjXGTgdMOPhKzav5B4bQDn+Brhm5MHT6Junpp6idlaiYhYGXfmMkqu5OAoKkCKfilV2+Gy5+CqjgdS8yeGiKjgiYEinVDLwAgC/A= 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:(13230031)(136003)(376002)(396003)(346002)(366004)(39860400002)(230922051799003)(1800799009)(64100799003)(451199024)(186009)(6486002)(966005)(2906002)(478600001)(86362001)(6506007)(6512007)(53546011)(2616005)(6666004)(5660300002)(316002)(6636002)(37006003)(66946007)(66476007)(8676002)(66556008)(4326008)(6862004)(8936002)(38100700002)(83380400001)(41300700001)(26005)(30864003)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?0ZLVzejIRJdix3Nt0p0lpeHWSbx2ikxYyiXVCp9M85Tdh1sM40pmA2RXzOrk?= =?us-ascii?Q?LhaKuwsI4ExbYfwYyhngXk9/A7wwVMolTPL2Je0OpURwerxcZ4mTJBSLZbS7?= =?us-ascii?Q?TSolRgmsQYMmayjYzBTZude/afhaQxEKM0PxoCCvBnMxIEUCSd6i+Yc599CX?= =?us-ascii?Q?k1sor1mQhdV6WYQ/VrTXJ3SHZ4dBgLIiMJBaVIRRYRo9K+QomZqCvhdywwsv?= =?us-ascii?Q?lFejrwIpx6zhZhm1yaZmFaNP9X5HaHnMhXHlYqiWvsmuc12kL7bsegQAwAxe?= =?us-ascii?Q?vdG4mBsFGkglZmtq2iQo5b1MJ+AID/oDwgN3mS/fCKBxbRXkxqj5pt/iYTPl?= =?us-ascii?Q?LdTvRbS02MjrrJ7GezWSTclqNZYSjXsZ4pdPPPkQIRSP18Zdnxkiy1WIuPp7?= =?us-ascii?Q?w81NK0MzNpru1XpQMkkGaa6Vo9uvsYKlYmo0Iqbs0NqL1zG01tk9HjOjlxvo?= =?us-ascii?Q?63H9Lo3BaFw0u8LWlYIt3TJbQsB2lMrqYn1AnlEPoM8M4bHJAjCmvuMtde0g?= =?us-ascii?Q?daGudiD+sMqdrH+Pj2kwPuHwxHBa9H+1T90p/w99k2/pH5ZApBXR5RgYuCNk?= =?us-ascii?Q?+nRWSgcnQ4X1PllOubo1q6x4p+6dtrw0DnlMjOHY2sSYtr2PS+V5LhQFA92S?= =?us-ascii?Q?QZW23Enn0FUkmlfNuqOHyDvF9o+oj/RMDzra3zVz+KJzheT7cHyDl87kR+jW?= =?us-ascii?Q?ZPHh5hCUTEc07HzFnM3VfQKhhCtE2tz3jq8P3rMU7+OulYAEq/SyhWSPMh8f?= =?us-ascii?Q?54h02c3eW0TeD3PxAIQILFL4HYBuvU9eUZHJcwnEH2td6+mSOpxckutJVnP1?= =?us-ascii?Q?PG5kt7eHPrlr+OhxZL8hLPP75QO/Ree4c7k3xsuOO3woZpmBYRm2Q7qFPVas?= =?us-ascii?Q?QIf4ZtJ1PW9WJkr5uLS0GZ3JBi2StKW58hc/7wwtLYZmxmIcPHgiryGmk7+e?= =?us-ascii?Q?NSZ4fEFF5E+673OZhIgsAEJ4qPwbvhqnGVg/zRVokwNutpp3TkWORIMWPhNZ?= =?us-ascii?Q?0NCPNIkj/6/IITR68aQi8nr5PRPCEhREtVqNGC7zbWa0H1rdbG5rBKYrL6DF?= =?us-ascii?Q?4vCKtG/eVQ71wRhFz584EQMppgoPnTbI2XOrAFR0h+tmteLZnOqHDc6xAQIl?= =?us-ascii?Q?MhLwpG7dlGY24PyNTCLX7DixrypicOt0a7pv7q8U8QJbok4rZ7yjY9GCKwn3?= =?us-ascii?Q?cNxtwuVm+mB80Corj4BqqfZRCM3P81vShux83xiwN5OlHyQFMQuMXbTcl87M?= =?us-ascii?Q?0LQsJILphS5j7FhR6HS5PPOxx2njRS2ipfsdbVUo/ugUhLGdczJBPJ9NRU1Z?= =?us-ascii?Q?miIJX9ih12Ii9NDoDBIe1qQzANerIwnhJb/xJH6QRmWpGGPCCKtzKEeBb/3c?= =?us-ascii?Q?fRJSUNbt18FRhKzx1geFeIJF6CCbP3xlid2u4KwG9ygyenoeFmjkHlN4ZJWZ?= =?us-ascii?Q?7+hWH2/3wcfbCBdxkDwAsQMaHmcKygrJizaPh19zN8r9hN/DyDad9rR/e+Fw?= =?us-ascii?Q?mvPQoq7w44K48RslFvWuz043D5CUKv4yJHKY6oy3Pqd6LH6EpWCs947/v71Z?= =?us-ascii?Q?UbQriPsMRN1nK42H/xEbP242DMrlBacspe3yDwLG1nfw6/B7Mi9st+9i0C8K?= =?us-ascii?Q?IQ=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: v4gdd0fRPKjsIpTfv8kVJg18pN0aIduCkhSbodZtNiaHr35mbQB2JLsDRHjUVUa/8Y5cC7iad3SFBjk7yAFqXM6FMZ3mpVthq/beGQUlms4VzjOq4BQtsSykHp4unP5U93YZOzECExEvDZgeIMRpw8Qw/xQNO8X4f4B8GfqHJv2fri2mN0LY3rJC8ogLDNnJEGSrryAxPMqojeV4yCaMWH8FVrOGlcTerSIAfgVhuivhmQVqQDu0LUSlqhyUUngR7ep7xgdKJRpk+FHQcYxm1Jezxso7SZC/VeuRwA9uySJE+faMGWRc1OPh0iA2wlGxSlayMmqi+UYm+2n9WLc9pBkXe07mIEMWUEWGzr2vY8G/9L5mygC39Caa1oq5vocpnxMqxlJdQ/1KNeSRMt6KwukaL8majgVOwTSMF1JTFZzUlOmP/HGPLZejGCJEr8h9/+OzrkzSGaBkyNZlWyetqNvKPpVXouLeNLm0bfqlXRdBMDzx4ZAYUpGAC+4g4FUxlYge/TOPJ0T59ugQtdZK0N7Zlu9n+BoxzInt2NAg0SwNj7CJLwtm0lMF40fbo9xWF9SKYmrgt+D7v7Lq46hvh+O6BeFAKMhpdBmjfmqY32YO7HEsvRIEA3Zpm9hmyjodFNJWWX/EskyIXbRdPNt309vCL+zYPt9l8w+h0HJQohN2x5DOhp2h25A7pGJwL5zHS5iGer/gATDG0BihVu61Yr9DkKd86s/bmvcnF2Z1L9eRi7FhjYDflWxBGPlJJ/75anFXnHuGByxRhTDpGjOjeEoJKzlP+R0O32Aha2mdizM= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6dd46c0f-965e-4eac-9aa9-08dbe7aba1d9 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2888.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Nov 2023 20:27:34.6053 (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: 0yChJoenVbomDa0DzfPr9U1a4WpX9nAC3xcOXNMgzfYLvFpp7P5YxBDwHMDcJ3tSdtf2GAFZDaHfD0qzHyT0ghdot72FYaCwXULIiHpVXAo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4496 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-17_20,2023-11-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 adultscore=0 phishscore=0 mlxscore=0 bulkscore=0 spamscore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311170153 X-Proofpoint-GUID: 4Sz9nfOZ0nMzMgMYwsKeSiof224TdEQm X-Proofpoint-ORIG-GUID: 4Sz9nfOZ0nMzMgMYwsKeSiof224TdEQm X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 List-Id: > On 11/17/23 11:29, Jose E. Marchesi wrote: >> >> Hi David. >> >>> [ WAS: gas,bpf: cleanup bad symbols created while parsing >>> v1: https://sourceware.org/pipermail/binutils/2023-November/130556.html >>> >>> Changes from v1: >>> - Rewrite patch to avoid inserting wrong symbols in the first place, >>> rather than insert, remove, re-insert dance. >>> Suggested by Jan Beulich. ] >>> >>> To support the "pseudo-C" asm dialect in BPF, the BPF parser must often >>> attempt multiple different templates for a single instruction. In some >>> cases this can cause the parser to incorrectly parse part of the >>> instruction opcode as an expression, which leads to the creation of a >>> new undefined symbol. >>> >>> Once the parser recognizes the error, the expression is discarded and it >>> tries again with a new instruction template. However, symbols created >>> during the process are added to the symbol table and are not removed >>> even if the expression is discarded. >>> >>> This is a problem for BPF: generally the assembled object will be loaded >>> directly to the Linux kernel, without being linked. These erroneous >>> parser-created symbols are rejected by the kernel BPF loader, and the >>> entire object is refused. >>> >>> This patch remedies the issue by tentatively creating symbols while >>> parsing instruction operands, and storing them in a temporary list >>> rather than immediately inserting them into the symbol table. Later, >>> after the parser is sure that it has correctly parsed the instruction, >>> those symbols are committed to the real symbol table. >>> >>> This approach is modeled directly after Jan Beulich's patch for RISC-V: >>> >>> commit 7a29ee290307087e1749ce610207e93a15d0b78d >>> RISC-V: adjust logic to avoid register name symbols >>> >>> Many thanks to Jan for recognizing the problem as similar, and pointing >>> me to that patch. >>> >>> Tested on x86_64-linux-gnu host for bpf-unknown-none target. >>> >>> gas/ >>> >>> * config/tc-bpf.c (parsing_insn_operands): New. >>> (parse_expression): Set it here. >>> (deferred_sym_rootP, deferred_sym_lastP): New. >>> (orphan_sym_rootP, orphan_sym_lastP): New. >>> (bpf_parse_name): New. >>> (parse_error): Clear deferred symbol list on error. >>> (md_assemble): Clear parsing_insn_operands. Commit deferred >>> symbols to symbol table on successful parse. >>> * config/tc-bpf.h (md_parse_name): Define to... >>> (bpf_parse_name): ...this. New prototype. >>> * testsuite/gas/bpf/asm-extra-sym-1.s: New test source. >>> * testsuite/gas/bpf/asm-extra-sym-1.d: New test. >>> * testsuite/gas/bpf/bpf.exp: Run new test. >>> --- >>> gas/config/tc-bpf.c | 92 +++++++++++++++++++++++++ >>> gas/config/tc-bpf.h | 4 ++ >>> gas/testsuite/gas/bpf/asm-extra-sym-1.d | 7 ++ >>> gas/testsuite/gas/bpf/asm-extra-sym-1.s | 1 + >>> gas/testsuite/gas/bpf/bpf.exp | 3 + >>> 5 files changed, 107 insertions(+) >>> create mode 100644 gas/testsuite/gas/bpf/asm-extra-sym-1.d >>> create mode 100644 gas/testsuite/gas/bpf/asm-extra-sym-1.s >>> >>> diff --git a/gas/config/tc-bpf.c b/gas/config/tc-bpf.c >>> index fd4144a354b..3122f80804a 100644 >>> --- a/gas/config/tc-bpf.c >>> +++ b/gas/config/tc-bpf.c >>> @@ -1223,6 +1223,7 @@ add_relaxed_insn (struct bpf_insn *insn, expressionS *exp) >>> See md_operand below to see how exp_parse_failed is used. */ >>> >>> static int exp_parse_failed = 0; >>> +static bool parsing_insn_operands = false; >>> >>> static char * >>> parse_expression (char *s, expressionS *exp) >>> @@ -1230,6 +1231,9 @@ parse_expression (char *s, expressionS *exp) >>> char *saved_input_line_pointer = input_line_pointer; >>> char *saved_s = s; >>> >>> + /* Wake up bpf_parse_name before the call to expression (). */ >>> + parsing_insn_operands = true; >>> + >>> exp_parse_failed = 0; >>> input_line_pointer = s; >>> expression (exp); >>> @@ -1251,6 +1255,71 @@ parse_expression (char *s, expressionS *exp) >>> return s; >>> } >>> >>> +/* Symbols created by this parse, but not yet committed to the real >>> + symbol table. */ >>> +static symbolS *deferred_sym_rootP; >>> +static symbolS *deferred_sym_lastP; >>> + >>> +/* Symbols discarded by a previous parse. Symbols cannot easily be freed >>> + after creation, so try to recycle. */ >>> +static symbolS *orphan_sym_rootP; >>> +static symbolS *orphan_sym_lastP; >>> + >>> +/* Implement md_parse_name hook. Handles any symbol found in an expression. >>> + This allows us to tentatively create symbols, before we know for sure >>> + whether the parser is using the correct template for an instruction. >>> + If we end up keeping the instruction, the deferred symbols are committed >>> + to the real symbol table. This approach is modeled after the riscv port. */ >>> + >>> +bool >>> +bpf_parse_name (const char *name, expressionS *exp, enum expr_mode mode) >>> +{ >>> + symbolS *sym; >>> + >>> + /* If we aren't currently parsing an instruction, don't do anything. >>> + This prevents tampering with operands to directives. */ >>> + if (!parsing_insn_operands) >>> + return false; >>> + >>> + gas_assert (mode == expr_normal); >>> + >>> + if (symbol_find (name) != NULL) >>> + return false; >> >> Is this check correct? >> >> I see that expr.c:operand calls symbol_find_or_make right after calling >> md_parse_name (if the later is defined) and actually installs the >> resulting symbol in expressionP even if it was already defined. That is >> not done if md_parse_name returns `false'. > > Hmm, I think you may have the logic in operand () flipped. > If md_parse_name returns 'false' then symbol_find_or_make is called; > if it returns 'true' then the 'break' is hit: > > #ifdef md_parse_name > ... > if (md_parse_name (name, expressionP, mode, &c)) > { > restore_line_pointer (c); > break; > } > #endif > symbolP = symbol_find_or_make (name); > ... > > That is what we want to happen - if the symbol_find in parse_name > returns non-NULL, then we know a real symbol already exists for the > name we are looking at, and we should use it. In that case, > md_parse_name returns false, so operand () calls symbol_find_or_make, > which finds the extant symbol and installs it in the expression. Perfect then. Please apply. Thanks! > >> >>> + >>> + for (sym = deferred_sym_rootP; sym; sym = symbol_next (sym)) >>> + if (strcmp (name, S_GET_NAME (sym)) == 0) >>> + break; >>> + >>> + /* Tentatively create a symbol. */ >>> + if (!sym) >>> + { >>> + /* See if we can reuse a symbol discarded by a previous parse. >>> + This may be quite common, for example when trying multiple templates >>> + for an instruction with the first reference to a valid symbol. */ >>> + for (sym = orphan_sym_rootP; sym; sym = symbol_next (sym)) >>> + if (strcmp (name, S_GET_NAME (sym)) == 0) >>> + { >>> + symbol_remove (sym, &orphan_sym_rootP, &orphan_sym_lastP); >>> + break; >>> + } >>> + >>> + if (!sym) >>> + sym = symbol_create (name, undefined_section, &zero_address_frag, 0); >>> + >>> + /* Add symbol to the deferred list. If we commit to the isntruction, >>> + then the symbol will be inserted into to the real symbol table at >>> + that point (in md_assemble). */ >>> + symbol_append (sym, deferred_sym_lastP, &deferred_sym_rootP, >>> + &deferred_sym_lastP); >>> + } >>> + >>> + exp->X_op = O_symbol; >>> + exp->X_add_symbol = sym; >>> + exp->X_add_number = 0; >>> + >>> + return true; >>> +} >>> + >>> /* Parse a BPF register name and return the corresponding register >>> number. Return NULL in case of parse error, or a pointer to the >>> first character in S that is not part of the register name. */ >>> @@ -1317,6 +1386,16 @@ parse_error (int length, const char *fmt, ...) >>> va_end (args); >>> partial_match_length = length; >>> } >>> + >>> + /* Discard deferred symbols from the failed parse. They may potentially >>> + be reused in the future from the orphan list. */ >>> + while (deferred_sym_rootP) >>> + { >>> + symbolS *sym = deferred_sym_rootP; >>> + symbol_remove (sym, &deferred_sym_rootP, &deferred_sym_lastP); >>> + symbol_append (sym, orphan_sym_lastP, &orphan_sym_rootP, >>> + &orphan_sym_lastP); >>> + } >>> } >>> >>> /* Assemble a machine instruction in STR and emit the frags/bytes it >>> @@ -1606,6 +1685,10 @@ md_assemble (char *str ATTRIBUTE_UNUSED) >>> } >>> } >>> >>> + /* Mark that we are no longer parsing an instruction, bpf_parse_name does >>> + not interfere with symbols in e.g. assembler directives. */ >>> + parsing_insn_operands = false; >>> + >>> if (opcode == NULL) >>> { >>> as_bad (_("unrecognized instruction `%s'"), str); >>> @@ -1622,6 +1705,15 @@ md_assemble (char *str ATTRIBUTE_UNUSED) >>> >>> #undef PARSE_ERROR >>> >>> + /* Commit any symbols created while parsing the instruction. */ >>> + while (deferred_sym_rootP) >>> + { >>> + symbolS *sym = deferred_sym_rootP; >>> + symbol_remove (sym, &deferred_sym_rootP, &deferred_sym_lastP); >>> + symbol_append (sym, symbol_lastP, &symbol_rootP, &symbol_lastP); >>> + symbol_table_insert (sym); >>> + } >>> + >>> /* Generate the frags and fixups for the parsed instruction. */ >>> if (do_relax && isa_spec >= BPF_V4 && insn.is_relaxable) >>> { >>> diff --git a/gas/config/tc-bpf.h b/gas/config/tc-bpf.h >>> index 9fb71eddd14..06096ef5926 100644 >>> --- a/gas/config/tc-bpf.h >>> +++ b/gas/config/tc-bpf.h >>> @@ -51,6 +51,10 @@ >>> a jump to offset 0 means jump to the next instruction. */ >>> #define md_single_noop_insn "ja 0" >>> >>> +#define md_parse_name(name, exp, mode, c) \ >>> + bpf_parse_name (name, exp, mode) >>> +bool bpf_parse_name (const char *, struct expressionS *, enum expr_mode); >>> + >>> #define TC_EQUAL_IN_INSN(c, s) bpf_tc_equal_in_insn ((c), (s)) >>> extern bool bpf_tc_equal_in_insn (int, char *); >>> >>> diff --git a/gas/testsuite/gas/bpf/asm-extra-sym-1.d b/gas/testsuite/gas/bpf/asm-extra-sym-1.d >>> new file mode 100644 >>> index 00000000000..113750dd3fd >>> --- /dev/null >>> +++ b/gas/testsuite/gas/bpf/asm-extra-sym-1.d >>> @@ -0,0 +1,7 @@ >>> +#as: -EL -mdialect=pseudoc >>> +#nm: --numeric-sort >>> +#source: asm-extra-sym-1.s >>> +#name: BPF pseudoc no extra symbols 1 >>> + >>> +# Note: there should be no output from nm. >>> +# Previously a bug in the BPF parser created an UND '*' symbol. >>> diff --git a/gas/testsuite/gas/bpf/asm-extra-sym-1.s b/gas/testsuite/gas/bpf/asm-extra-sym-1.s >>> new file mode 100644 >>> index 00000000000..2cfa605a259 >>> --- /dev/null >>> +++ b/gas/testsuite/gas/bpf/asm-extra-sym-1.s >>> @@ -0,0 +1 @@ >>> + r2 = *(u32*)(r1 + 8) >>> diff --git a/gas/testsuite/gas/bpf/bpf.exp b/gas/testsuite/gas/bpf/bpf.exp >>> index 80f5a1dbc2d..fcbeccd8ecd 100644 >>> --- a/gas/testsuite/gas/bpf/bpf.exp >>> +++ b/gas/testsuite/gas/bpf/bpf.exp >>> @@ -72,4 +72,7 @@ if {[istarget bpf*-*-*]} { >>> run_dump_test disp16-overflow-relax >>> run_dump_test disp32-overflow >>> run_dump_test imm32-overflow >>> + >>> + # Test that parser does not create undefined symbols >>> + run_dump_test asm-extra-sym-1 >>> }