From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 801B43858D28 for ; Fri, 17 Nov 2023 20:09:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 801B43858D28 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 801B43858D28 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1700251784; cv=pass; b=fbyzuQqktJswcR3dYlh2Ahce75DipEpRE+tHW7+MKoe9LqvgLiZJ7D7uRGU9o+qkOHGqCK1IWI9w+KgJ7vcMOHVGvcJ/HfJnusaN9nKxNrYL7QH5R8kQc+PjKB1mnHWpsaPOCoYeYL8AL+xUcprorqUDSpDxH1Fu5iltBU+DgGg= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1700251784; c=relaxed/simple; bh=X0gaEdLeWdcvr7T38Wp/8g5eJsiDxufU4KizyCYlZ6I=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:Subject:To:From: MIME-Version; b=DNN3s8eGkYxxqM43Pfm0KjuMzRuYedJa6RCnX5alsergKAuKOz06/Qq4v+/2syqywEtwHG0DEdMhR5nDkIYrfidnn4vV1EWTq5/sRyqgY9dyKAK2oO4ruXOn1wgN2rcxDrGGWYskyyfaXdHLyQM7M0ZQlPN35IXSCl+acGkMje0= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AHINwr1016716; Fri, 17 Nov 2023 20:09:42 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=VF6XQaaMUJwj+dFOP+7cFISOPAmySuuqDm1jC9xUJj8=; b=xeT5tAHV+XXrz8hQkwCFgq5ORQTZIG39IAVtUOVXh7IaywJupa2miA4Y0Q3qaIU3Gm7X I4Fotft7UeCdg7nFCmSMaQEXpnF0iPFJA9GzT+aBkJHBB6OjCBMXDQW+xmHO75hs6a8n okBhQ/KEQ3Qqs4yJKPjG0lO1Yy2LUJEbAHktv8aYu8Xian19wsQqJbL8hGzI9ZKdsJG/ NRSNSyHr+NC7D7Uo+EvJWF4p0ZtmAI0mPt5omVOltMJbeB/ysqi4EBoeHvqyg+exE5me Rs5a1ZF44WRwlBwlJoVGGRexrAGiYZkdzLwQUbCA8ge3XeshMgGI+SZJWgigG/qeOD4x IQ== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ua2qde1r4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Nov 2023 20:09:41 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 3AHInlmV038533; Fri, 17 Nov 2023 20:09:41 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2101.outbound.protection.outlook.com [104.47.58.101]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3uaxj7trvh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Nov 2023 20:09:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YI00Fnt1mOHkuUCr2N5i+u86IUbnBow6cLEJkFwPGu+JXEtM/stGKMhhX2+baifZ/TiQvssioa5e8ifjEd+Uz+54rp4jrGdTPYhBNogbDlSbNx//LwhTHj810FuvggV3owhS1M7sIlps5ZeGZzWfy7sp6Xz4MK8rffgdpmC4oWP2BRYG8U1an1l1jmOBK1w5WkvEycNgZmTNgeT9K0+LIAD61hSQiGmash8NvoT0xNcXmoZIpuU94O2pq+oWVTMAfMPui4k7f6RDWoDyX+FkgE91CkG5GjffahyxBZFWAzOSeH/ekDLCFDRe2yJViATdDYOSAOFZ0i+euOhlxc2v9Q== 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=VF6XQaaMUJwj+dFOP+7cFISOPAmySuuqDm1jC9xUJj8=; b=kfsHhxdchuixJSI7Jx4khEYslaYWaf3cS9GgCcmV2p8WZJ2UunvyxXa2ItSdZ7KYACFfsFJ2Pfp+Ohmb46imCquQfynybvP8OBq0fHrAI62DRn8XAn7vImsZunULoivXQRYw02RMtlu7DtWF8hSjiMn6PNzkgzsHAn9IyQ50WIp0t77DIor2X6dl6qXKJwAzFRd0xjIWWMhpvKvkcQ4+cDaCPGjLMzHJvSsNxC0iyoy4zgfc6RGKvHh1DcZJA1aAq87GMdcZzmLDLuG1r8xSmxpqBqVeCMuSg4eZHOjY2yJ3qBm+2L+TrXGe2TacWpphW6zuInfFTbgGw+T7MM4l4g== 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=VF6XQaaMUJwj+dFOP+7cFISOPAmySuuqDm1jC9xUJj8=; b=tXTcvpGEoiolbrKIuJeagQvx3n3uaExfN94Dbl4Q1EwBHBWhPLy9sQJORSa1nT+J+quv6z6XTabUXYBwDXT4/NoF7P/RYaPqUylR9JdNiqSOpDvgt0KbUWWyWKuScJkMsv9D/ImDfS1uX2zp3xwh6lpU6LIZNBg4M/4tlQr4FCE= Received: from MN2PR10MB3213.namprd10.prod.outlook.com (2603:10b6:208:131::33) by MN2PR10MB4239.namprd10.prod.outlook.com (2603:10b6:208:1d5::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.23; Fri, 17 Nov 2023 20:09:38 +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 20:09:38 +0000 Message-ID: <6e00c2b6-a561-41dd-8701-e13627d9c57f@oracle.com> Date: Fri, 17 Nov 2023 12:09: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> From: David Faust In-Reply-To: <87edgo6uvr.fsf@oracle.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: BL0PR02CA0132.namprd02.prod.outlook.com (2603:10b6:208:35::37) To MN2PR10MB3213.namprd10.prod.outlook.com (2603:10b6:208:131::33) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB3213:EE_|MN2PR10MB4239:EE_ X-MS-Office365-Filtering-Correlation-Id: 89af828d-b1ef-494f-0d10-08dbe7a920a2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jRKY967kL8+fru+kthKucjsp/3Ut4wCBTNyiyC7aj1OPboQK1YH2xQbberHGeZf5+LZTKC3MDnpf/DntZNVu3KkemMimtOppTG72xZYtPCG0fh+A1iXxNhAhhF4ZUbu7wFyt+499w8WYehTmUaCR+bdwIA85cGtpSEUQNmBqeWg7esm4Ox4zK6Z0ctvMkNCBfch9IPpaAH3uaaHizLIzaHakjuGF3zlyqhVTgpVhNpcAHH+kcGgZA03Nc+qz7x6oDlQnCpxUmERJoul+BGS8qDLOwGEL6WQSM3+9JxMqJ7l9HlKmpTt3J9zd0hGrCj0W1EEzC5g6HoQdOMm+0cKgYY0xdecR2Jg7aba0woenbrxOw3sGT/4+FLn9n7kv/sTW2e5gmMj0Id6GUtmkLvYr4l3Ed+yQdQ8AdDzT9fFbXvjSP4fa0MGTFCKKGbYtfSh1qHybZzNIhBgBwug3HB5gdiUzl+60FOWW+QlfS+sdn5yNz9MOqzU9pdX8HukKNz9JjCv2iM54/bxwfwiq5WTmfHNirYmQOvd0blXSQq7LfcuHbYT5VoYDWJqlMcQO0ZC6uCyptfzrhYqpJuOWDxlilFW6rf5OAFolj/ye/+jC2OtvklBEMQUbA7h7LynDKzNbE1h7cL83oOh5s4jjjxstPA== 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)(366004)(376002)(39860400002)(136003)(346002)(396003)(230922051799003)(64100799003)(1800799009)(186009)(451199024)(26005)(6506007)(4326008)(6862004)(8676002)(5660300002)(44832011)(8936002)(30864003)(2616005)(2906002)(66476007)(53546011)(31696002)(86362001)(66556008)(66946007)(31686004)(37006003)(6636002)(38100700002)(316002)(478600001)(6512007)(6486002)(966005)(36756003)(41300700001)(83380400001)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?OTBIZTFxVEkxM2ZiS0IxRzBmdG5EeHgzTDA2aXZJcktBZVhzSkpCVjV3RWZ1?= =?utf-8?B?ZGlDemUva1B4NndiTXFTUWc1Q2xMT2p5cEVwVkNyOEorWlU2Rk00ajh1OXZq?= =?utf-8?B?dktpVXpVRWNBVS9CaDRBeldRY1Z4THlsT01xWE8wN1REOXIrWlczQ2NQd1dh?= =?utf-8?B?MGFFWlM2NVNBNXo1MEMxVmZtQk5oS0lINjFyUWE2K3piNTlLb29sci9GeW9k?= =?utf-8?B?aDlTOUJzVmJiN1RFNWYxWUQ4OThxT0tkaWlIWUFXeDlpa1RmSk91dld1Q2Nn?= =?utf-8?B?YmlEbGgrajhrQm5HZWlQcWNFTFlvaDhYVDUrZ3RSL0p4UVpzUVFwblJxYnZB?= =?utf-8?B?clVab21KcExFTHN3WWJHbS8vZndOdFpZRUNQZitqcnpJMm9ycjZNU09TU2Uw?= =?utf-8?B?VGp1MjNwSzB2aWxkODM4cTNFM1kxSGVuZDZvQVJhTFl2TkdzYVZKclpkbVJz?= =?utf-8?B?dldEaDk0NFAzTWtvZTgvMXpLU3RDRkVQVnNXdTlUNVVmcElWOXI0Z1ppd3Y2?= =?utf-8?B?VUZtcUtTc0hPVFF5ZThSRitFL1lOdFY3SElGQ0wrOVorQ0lxQXl5Z05oT2lH?= =?utf-8?B?d3pRYkYyV1E4a0RaWkpaNUYxN2JaeDV1c0lLTFdQbExWODhIVWlOKytCRUNP?= =?utf-8?B?dmd6ZVpnOThodFNEVXphZ2pVUE9qM2luQ0w0QmpXOUtwRldLYmt3OVFld1Mw?= =?utf-8?B?RjFnUEN6STYzb0VMd3BHb3BSSFNUTlRzYk9OdWpGQ0JnaH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5ssnmOorkxcLo6npa3tdi98KHnXSXTDF83brDnVIR9OeTO/bDl0JSoB+3tl9ps7TBE1Os7YJ2uxI8Kxo7QBWy/znwCgQuY5x7v0oy2OgQ42abwUJHbPtcxpEt6X75EpKM0wIJzj9KHHPP2CrhjEF1eqd0eCM+Y6cvc/xgn+9+ETPwMq2OanGjqUQgEiH3QDHaYSqMrxRbKTUnF42FUJnjy18adSt3063hhqEIk+tQVRYf8b3hsIFwBGH+d0U/yvCfza22oJH3SB+t8/3j+X3t+u4qSMOAZIyxg3mDES6LP7UYCEkZJxzrjrmOhkfJqu5rcQXMzhHfCgpvV9FTHWFAkiYhtJyCiOIsKkGdj7zVE7pZFOT/DYPeuizL8jp091f8rc6/o= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 89af828d-b1ef-494f-0d10-08dbe7a920a2 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB3213.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Nov 2023 20:09:38.7859 (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: C5W4syX8pXniun3uWAqtJ+R16YLqyU0h58u9R0Ga2sf6s4mQmOQTrvZVMXiGVF69r3aid7xeP0d2KOXg2N7Wpg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB4239 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_19,2023-11-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 adultscore=0 mlxlogscore=999 mlxscore=0 malwarescore=0 phishscore=0 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311170152 X-Proofpoint-ORIG-GUID: t6YxZ6E7HQGw22wdXPQxHTTpPBG7u6Rh X-Proofpoint-GUID: t6YxZ6E7HQGw22wdXPQxHTTpPBG7u6Rh 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 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. > >> + >> + 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 >> }