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 348AF3858D20 for ; Fri, 17 Nov 2023 21:41:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 348AF3858D20 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 348AF3858D20 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=1700257306; cv=pass; b=tF0ipFWaPmMlKKFQb2rqch3ngZFx+5LfyucD5UOjeSY6T1YWO3rjSXckDiLQG95CsLHCc2yd5PcApqGoG11x85h+pGfrN5cABubty1dGFsDLKoUdL3SYpmUcMhTIMvGZ0J2xGpuiEyU4DYAhyzMsYcPRecd8iDu9X+mTapiTD8M= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1700257306; c=relaxed/simple; bh=gSaVF78xfxhZwJjgPsibInM8eK/CQcbhHjwYASTQpd8=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:Subject:To:From: MIME-Version; b=LS7oiESX2E6i2NXp0kTl89VmP7r9gCSt9Yj0uwccdRB5B7RqQtfUSazZY0XJ5RND8l4+GtVEIrCLaFl5hb9l4iWJCysTVO8xSpLLI4wpAqYpffiMOIV5lSpEQ6E1skzNKGDkqE1a2p3IE6pf1qxfO703DQJKO4Lugpqgl0pCT8M= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AHL1AeJ018990; Fri, 17 Nov 2023 21:41:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=message-id : date : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding : mime-version; s=corp-2023-03-30; bh=9BMBhBlvmIycmVfmIIWPGJyccH7AJEq/JO4rjep8VMM=; b=AU1XsvgQrhjwWPVufozfnrEomyRHLdL5H1k/44AZKyiHUC/6Is3w/a05lyCF9Wph2MQu d7HczULPeYFgo6lCwBDiSllNfC3ax0VW25cjUevnPqVTPiHTtKYcOHUDQeIU6p1r1b+0 P6/2wy8uWIIz7mtxBKuBXgoF61NR7IdCQ21XdiA+bmwXqi1IjkOOwcETBDOsTDiervAN CYa5vnUv8Nz5aTuEo6M8QlYKXJn6wlVq9oSWyRyCo3EceQbwwiAGbTxh+XpxeqFbbkaF ZWU6BRqpQkneFfa8Vou0JMckhmWOYDY2w6Zqt2JM7AhicmGv13lac8DtFUK3/wlILq6p iw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ua2m2pc70-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Nov 2023 21:41:42 +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 3AHKieLj015665; Fri, 17 Nov 2023 21:41:42 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam04lp2168.outbound.protection.outlook.com [104.47.73.168]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3uaxq2wq21-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Nov 2023 21:41:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AS4Vk5Q/0N7qhTGLF2MYVzEJRQPJwbzljLSeze1xklI7rPZpA/LSsnK2gTDUQkmj/FbCOpZpdNjWf8i+y2rKhEb0bVreDKeDuzPjOSD5777u+IrG2ezQ1JQiiS/CdHbwsX3dt2h1i6ySgquw+kqY2XpnpXcTy9dWhn4fVmB14MJje+AkQ2Q/UAh/O7ZvYcYdTEmRA27RO9xvsn1pPF7ZprYTT1bHy/gTt4kkMcljY/J7/R+xlDvvLVCj+GdBj57KejdBobwbmBqogc6ufw1za3bHC4z5hwlePghoId52uvtMB4+kmHB1RbsinxTReiCbZ9baRhLBvfE5hrRZyPkdaA== 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=9BMBhBlvmIycmVfmIIWPGJyccH7AJEq/JO4rjep8VMM=; b=TWoft5wiSeFLhzqzrHFQ06ajychblUwOHyUo/MclXseEHRidiqWduU1PegGfdyBi1iQ1bkETGdHNTjruyxcBrdLZSPTH0CxhKUe3nFZH+YOq2Iq4/Yo1pJ2M4nxC8XNwXMu1oj4z1D7UkZZ0a6RvEnj/UvDLjN8pO50j4A416DQw5Cr2EphLExK860pRP7QGqbwy78wrF+RjIeg3CA9zREVuEPd4h9MoQs6hSqXRSDuW/rFLqR456FA7DEdgbbAsDH1q+UYfoZB/yIs/QJN2wIq7XcqgYGDinjFecZYjvhsdAaTpj29QvW49Ox/8rnpCke1wL9yfIGPZtL6EmpXnaQ== 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=9BMBhBlvmIycmVfmIIWPGJyccH7AJEq/JO4rjep8VMM=; b=Ui3qJR+V3OhVYXn78nfbwN/xxiHdP3ui2MDD090bzWbd/4Gp3Zj6YdVp8sf+Gpm1DCRieN36BGchVia31MyOKz3Zi1uKX3vtAcq5VXyXnc3yZSUwdVM9k4HknCQGa1PTNPQ0m848h2U5MftaCRU/gtnA2F8mh0a/lrvdisqDoPs= Received: from MN2PR10MB3213.namprd10.prod.outlook.com (2603:10b6:208:131::33) by SN7PR10MB6473.namprd10.prod.outlook.com (2603:10b6:806:2a0::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.28; Fri, 17 Nov 2023 21:41:39 +0000 Received: from MN2PR10MB3213.namprd10.prod.outlook.com ([fe80::d8:db85:8025:ed64]) by MN2PR10MB3213.namprd10.prod.outlook.com ([fe80::d8:db85:8025:ed64%7]) with mapi id 15.20.7002.022; Fri, 17 Nov 2023 21:41:39 +0000 Message-ID: <495d481c-4ad3-48f7-a0e9-1ab7d0697708@oracle.com> Date: Fri, 17 Nov 2023 13:41:36 -0800 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] bpf: avoid creating wrong symbols while parsing Content-Language: en-US To: "Jose E. Marchesi" Cc: binutils@sourceware.org, jbeulich@suse.com References: <20231117185428.10823-1-david.faust@oracle.com> <87edgo6uvr.fsf@oracle.com> <6e00c2b6-a561-41dd-8701-e13627d9c57f@oracle.com> <877cmg6s7h.fsf@oracle.com> From: David Faust In-Reply-To: <877cmg6s7h.fsf@oracle.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: PH8PR15CA0004.namprd15.prod.outlook.com (2603:10b6:510:2d2::15) To MN2PR10MB3213.namprd10.prod.outlook.com (2603:10b6:208:131::33) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB3213:EE_|SN7PR10MB6473:EE_ X-MS-Office365-Filtering-Correlation-Id: 696d704b-0f6b-49d5-c170-08dbe7b5fb57 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ceJcgvOzfRFbBF88xX1etoWeqhPT39ge3TCVgBkdzEzUK8CSLsuon8tKuUcNq56+i/6cn/aY6AuX8MLUF4K0h9fH4Zr9Q/07UqOE61C+/KSfsGS3OSiKIfX9k48+OD3riRrzqSS/k3kvjD6psGLQsL8972WovdqZ0fwvVNyhOkRiLeoJ7vtPFvF50no19V2HvtLx5YupJJDTuGPBLovKx2Y017FBHPQfAMIXOOL5Fyys10HxPuCDBF/UJg99Z1NWeJ0u3vzLu2Px5b3Uo5A69ToXc4NImRrJTTtbGyshUleehmQt5uivE/s8ciqARRTGWn6SRklYkGh4PrYYb9dxKQ5AyjRAkb+ne0oq66po7m4MuiilfjV/ywmVeSKX6Ibi4GKOTzEYzvIZCt5ATNDINRkCTKZoHr7UKCLI2LhIDPvJBpXV4RsQ008/pVB5zt0H4kOz9JFy/Pgey4ys/lXwOKXrlcOmodAZLQS5hucTfW4Wp9lJeM8GOE/9DvjcAAyzrlm/4igW9upLNuoSfKskkFSGmWAJURlmxTDjqd0Zzy+xbrml1tKJpdRwYQVKEPtC3zvFqRUCkStOdWgnASd9QBzkwjMxcB+xZHepBbyGm+BMPuZj8TtzIGWb23QUhGIjZ88EjOGQQ5ufSIlwFXgE6Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR10MB3213.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(376002)(136003)(346002)(39860400002)(366004)(230922051799003)(1800799009)(64100799003)(186009)(451199024)(5660300002)(38100700002)(86362001)(41300700001)(2906002)(31696002)(30864003)(36756003)(83380400001)(53546011)(2616005)(37006003)(66946007)(478600001)(31686004)(26005)(6512007)(66476007)(6636002)(6666004)(6486002)(66556008)(316002)(8936002)(44832011)(6862004)(966005)(6506007)(4326008)(8676002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?SnQwbDNQRE1jbnZ5SGhtNFpMVTdzVVJ1NXJkc1dOUlpjdFFMQmlQSkQ1Zkx4?= =?utf-8?B?K2dIb1lMeXV2WkNwS3RldDdZVjd0SEVVUHlybU5iM1owbGl6Y3kyVE5zQTFN?= =?utf-8?B?SUtXR1ZiZE9uZHBPaGNsS1V2d1hYbEdUK3kyWE5WaTZFdFNvTDlkcFluRDk3?= =?utf-8?B?RHNmVlo4K0hGbjVqTTZDQTJaRWkvb3hYOVVLMVprdnd3dC9tS1ZOek8xcDJp?= =?utf-8?B?WWtaTEVXSjR5V3RYa25hcFAxanBGcE5HU0NZQXU4MzRqMXZIdFN2YU91M2gr?= =?utf-8?B?eUppUnU4dDBYd0pEZzRUNjgxNU1RTkV4RVZYcVhHa214SFd5QzZmS2hCb2Z5?= =?utf-8?B?a3M2Zm16NzVpV1NVWG9GMHExS1dhdTY2ZE5OYUk3SmJhMER4OHkzLy9FWDc2?= =?utf-8?B?QkVwWERhYmNWN0dKSnA5T0dXeU5QcHlzOEZreTl2T1QzZVY4RjNxVENkVU4v?= =?utf-8?B?L2xLNUYrdU1aZXZKa3RHRkZlVVdsN205SHBqNFl2T0cvNmZPTHdUOGtiV2x6?= =?utf-8?B?SFZJVHpqZ3drSnNVdVhVeTQrWkZqdTBKTXhTWTNkUTVELytzQmNlQ1hsYzRh?= =?utf-8?B?UmVrS08wQytZN2tpTEdKZGlBSGZHNFlBcDZKUEJuVWxQTmFhT2tTcDE0eUUr?= =?utf-8?B?VHdPa2tSckhxSE5HS1RyY3pvTVhRODF3RitSYm94dm85RVNXVm1zQ0tJa0Jr?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cQtWcbJ9vyYmQ3VRaWP/V0JzpxByTlGMlr3lOvcsIG5mzBLPGwznLh1Jr3V42v3UT6FANrjH60iaht4oTmKDE1xAFWJj5Mb9kjsvn9zVubhgsSuPYy5H4EugyU3ZaWJ/LDkSqRYT6XlCe3Hf6nVbqKNlimkIbdXotB8oK8s/vNhMPWJVL2RJ8EL14as1+IGdbacnNKpfGWnjsSjqYKol+Cd9WCwo0ZzDI/a/6ooY9vxLUxSA22KU2EhvMsFpDZ+Z+giEvPz0sbRpglWRPsgqGKx8Fs/czD1KgzAFCbrq49c96QYwMkqI8A+CDwQAtTYPXt42vn18PBz1LtX4iBvJZv1yOhKzMpMBO/UQZZ5mB2lCiGfm3Y9bz3p2K8DUTnzJwK5mEjVJCiqcR6zUx6P2s6M7X1wWw+wv6pZEIR1uwHx0n1osWcxmtfMnPOwSCfq/AabHYpPkpgsNp83OWuQcZSZ6Y= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 696d704b-0f6b-49d5-c170-08dbe7b5fb57 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB3213.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Nov 2023 21:41:39.6633 (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: oyfjupuNROgfTUoqRIx3oy6UTTIfH1zTUk4TJpi6WMR9ZoRGGJ6CdWsZeYwKbau+7W99EaWv/l+wGqgSTBkrvw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR10MB6473 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_21,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-2311170162 X-Proofpoint-GUID: KpPVXuz0dDCEecAVSAYHXWx0b_ou1ERh X-Proofpoint-ORIG-GUID: KpPVXuz0dDCEecAVSAYHXWx0b_ou1ERh X-Spam-Status: No, score=-13.3 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 12:27, Jose E. Marchesi wrote: > >> 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! Pushed, 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 >>>> }