From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59E6EC433EF for ; Fri, 13 May 2022 02:04:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376445AbiEMCEj (ORCPT ); Thu, 12 May 2022 22:04:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229734AbiEMCEh (ORCPT ); Thu, 12 May 2022 22:04:37 -0400 Received: from mail.nfschina.com (unknown [IPv6:2400:dd01:100f:2:72e2:84ff:fe10:5f45]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CEAFD28B84D; Thu, 12 May 2022 19:04:35 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id 871701E80C82; Fri, 13 May 2022 09:58:54 +0800 (CST) X-Virus-Scanned: amavisd-new at test.com Received: from mail.nfschina.com ([127.0.0.1]) by localhost (mail.nfschina.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Wm2H41FLJxlA; Fri, 13 May 2022 09:58:51 +0800 (CST) Received: from [172.30.21.106] (unknown [180.167.10.98]) (Authenticated sender: liqiong@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id 007621E80C80; Fri, 13 May 2022 09:58:50 +0800 (CST) Subject: Re: [PATCH 1/2] kernel/bpf: change "char *" string form to "char []" To: Daniel Borkmann , Martin KaFai Lau , Song Liu Cc: Yonghong Song , Andrii Nakryiko , Alexei Starovoitov , John Fastabend , KP Singh , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, hukun@nfschina.com, qixu@nfschina.com, yuzhe@nfschina.com, renyu@nfschina.com References: <20220512142814.26705-1-liqiong@nfschina.com> <223f19c0-70a7-3b1f-6166-22d494b62b6e@nfschina.com> <92cc4844-5815-c3b0-63be-2e54dc36e1d9@iogearbox.net> From: liqiong Message-ID: <6af0b0fe-daf3-5310-2f13-e411a80bdde8@nfschina.com> Date: Fri, 13 May 2022 10:04:30 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <92cc4844-5815-c3b0-63be-2e54dc36e1d9@iogearbox.net> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2022年05月13日 04:59, Daniel Borkmann 写道: > On 5/12/22 7:08 PM, liqiong wrote: >> 在 2022年05月12日 23:16, Yonghong Song 写道: >>> >>> On 5/12/22 7:28 AM, liqiong wrote: >>>> The string form of "char []" declares a single variable. It is better >>>> than "char *" which creates two variables. >>> >>> Could you explain in details about why it is better in generated codes? >>> It is not clear to me why your patch is better than the original code. >> >> The string form of "char *" creates two variables in the final assembly output, >> a static string, and a char pointer to the static string. Use "objdump -S -D *.o", >> can find out the static string occurring at "Contents of section .rodata". > > There are ~360 instances of this type in the tree from a quick grep, do you > plan to convert all them ? Hi daniel, I have fixed all the string form in kernel tree, summited two patches. Have searched the kernel tree by "grep -nHre char.*\*.*=.*\"", and checked all the "char *foo = "bar" " string form, only five instances are needed to fix in bpf direcotry (2 files) and trace directory (2 files). In most cases, need a char pointer anyway, just like this: [const] char *foo = "bar"; if (xxx) foo = "blash"; In this situation, can't change "char *foo" to "char foo[]". This work was published in "KernelJanitors/Todo". So, I fixed. Thanks. > > Thanks, > Daniel