From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from alexa-out-sd-01.qualcomm.com (alexa-out-sd-01.qualcomm.com [199.106.114.38]) (using TLSv1.2 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECF833207 for ; Wed, 11 May 2022 19:53:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1652298828; x=1683834828; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=tJUoH32r2DhYogH9Td6X47AQDJfM19sTpFtOpSyDiTg=; b=aiAIPoYpcQZQxpZ3R56Sa1iiBOlsfvp70lNOEoNf6Wf0Efmar9kRL2eY D54mhhcCYDwAyVivY3ZygobYRC1n+b/ArxSwPVrrD9tcDUD9UbnamTcp8 eDtwsU1P7+zbkEF+sQ1HWt/Y34SsEA7BfpU0fjpEsrRlbzV9O5eaT2esN 0=; Received: from unknown (HELO ironmsg03-sd.qualcomm.com) ([10.53.140.143]) by alexa-out-sd-01.qualcomm.com with ESMTP; 11 May 2022 12:51:39 -0700 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg03-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2022 12:51:38 -0700 Received: from nalasex01a.na.qualcomm.com (10.47.209.196) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Wed, 11 May 2022 12:51:38 -0700 Received: from [10.110.84.131] (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Wed, 11 May 2022 12:51:37 -0700 Message-ID: <8babc23b-5e24-f662-6c4a-eb1c30e0e6da@quicinc.com> Date: Wed, 11 May 2022 12:51:36 -0700 Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH v4 03/14] modpost: split the section mismatch checks into section-check.c Content-Language: en-US To: Masahiro Yamada , Nick Desaulniers CC: Linux Kbuild mailing list , "Linux Kernel Mailing List" , Nathan Chancellor , Nicolas Schier , Peter Zijlstra , linux-modules , linux-s390 , linuxppc-dev , Ard Biesheuvel , "Sami Tolvanen" , clang-built-linux References: <20220508190631.2386038-1-masahiroy@kernel.org> <20220508190631.2386038-4-masahiroy@kernel.org> From: Jeff Johnson In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01a.na.qualcomm.com (10.47.209.196) On 5/11/2022 12:27 PM, Masahiro Yamada wrote: > On Thu, May 12, 2022 at 3:48 AM Nick Desaulniers > wrote: >> >> On Mon, May 9, 2022 at 11:57 PM Masahiro Yamada wrote: >>> >>>>> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c >>>>> index a78b75f0eeb0..e7e2c70a98f5 100644 >>>>> --- a/scripts/mod/modpost.c >>>>> +++ b/scripts/mod/modpost.c >>>>> @@ -31,7 +31,7 @@ static bool external_module; >>>>> /* Only warn about unresolved symbols */ >>>>> static bool warn_unresolved; >>>>> >>>>> -static int sec_mismatch_count; >>>>> +int sec_mismatch_count; >>>> >>>> ^ this should go in modpost.h if it is to be used in two translation >>>> units, rather than forward declaring it in section-check.c. You did >>>> this for the functions. >>> >>> >>> Sorry, I do not understand. >>> >>> >>> In modpost.h, I put the declaration: >>> >>> extern int sec_mismatch_count; >>> >>> If I moved it to the header without 'extern' >>> I would get multiple definitions. >> >> Yeah, you need to _declare_ it w/ extern in the header, then _define_ >> it in one source file. >> >> That way, if the type ever changes, the sources will agree on type in >> all source files. You will get a redefinition error if the definition >> changes the type of the variable since the last declaration. >> >> What you're doing is forward declaring, which works, and is a common >> pattern for (bloated) C++, but is less type safe than sharing a single >> common declaration between multiple source files via a single common >> shared header. (Sorry I didn't respond before you sent v5) > > Sorry, I still do not understand your suggestion. > > > Could you provide me with a code diff > showing how to do this better? I think you are doing exactly what he's asking for: declare it with extern in the header (modpost.h change) define it in one source file (modpost.c change) 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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4AB63C433F5 for ; Wed, 11 May 2022 23:07:47 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kz9YF60n9z3cdY for ; Thu, 12 May 2022 09:07:45 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=quicinc.com header.i=@quicinc.com header.a=rsa-sha256 header.s=qcdkim header.b=DcSvKcr6; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=quicinc.com (client-ip=199.106.114.39; helo=alexa-out-sd-02.qualcomm.com; envelope-from=quic_jjohnson@quicinc.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=quicinc.com header.i=@quicinc.com header.a=rsa-sha256 header.s=qcdkim header.b=DcSvKcr6; dkim-atps=neutral X-Greylist: delayed 124 seconds by postgrey-1.36 at boromir; Thu, 12 May 2022 05:53:46 AEST Received: from alexa-out-sd-02.qualcomm.com (alexa-out-sd-02.qualcomm.com [199.106.114.39]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Kz5FQ2pdYz2xrc for ; Thu, 12 May 2022 05:53:46 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1652298826; x=1683834826; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=tJUoH32r2DhYogH9Td6X47AQDJfM19sTpFtOpSyDiTg=; b=DcSvKcr6T826MM4GuJSgsAscnhiXY8UBJHld5i4cpc9gUlOGOt1rwJrg KFA6M9h04obYyUfbB0HzZPV/OrHsyd7WWvsnCl2MTkpEzQMRFIGXNVE7V ZNRtGk++XYgnTNSJAsUcveCmiXHveMTAXgQiJF5MbzZN6UkBVZmHQUpqo 8=; Received: from unknown (HELO ironmsg03-sd.qualcomm.com) ([10.53.140.143]) by alexa-out-sd-02.qualcomm.com with ESMTP; 11 May 2022 12:51:38 -0700 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg03-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2022 12:51:38 -0700 Received: from nalasex01a.na.qualcomm.com (10.47.209.196) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Wed, 11 May 2022 12:51:38 -0700 Received: from [10.110.84.131] (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Wed, 11 May 2022 12:51:37 -0700 Message-ID: <8babc23b-5e24-f662-6c4a-eb1c30e0e6da@quicinc.com> Date: Wed, 11 May 2022 12:51:36 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH v4 03/14] modpost: split the section mismatch checks into section-check.c Content-Language: en-US To: Masahiro Yamada , Nick Desaulniers References: <20220508190631.2386038-1-masahiroy@kernel.org> <20220508190631.2386038-4-masahiroy@kernel.org> From: Jeff Johnson In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01a.na.qualcomm.com (10.47.209.196) X-Mailman-Approved-At: Thu, 12 May 2022 09:06:31 +1000 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-s390 , Nicolas Schier , Linux Kbuild mailing list , Peter Zijlstra , clang-built-linux , Linux Kernel Mailing List , Nathan Chancellor , Sami Tolvanen , linuxppc-dev , Ard Biesheuvel , linux-modules Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On 5/11/2022 12:27 PM, Masahiro Yamada wrote: > On Thu, May 12, 2022 at 3:48 AM Nick Desaulniers > wrote: >> >> On Mon, May 9, 2022 at 11:57 PM Masahiro Yamada wrote: >>> >>>>> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c >>>>> index a78b75f0eeb0..e7e2c70a98f5 100644 >>>>> --- a/scripts/mod/modpost.c >>>>> +++ b/scripts/mod/modpost.c >>>>> @@ -31,7 +31,7 @@ static bool external_module; >>>>> /* Only warn about unresolved symbols */ >>>>> static bool warn_unresolved; >>>>> >>>>> -static int sec_mismatch_count; >>>>> +int sec_mismatch_count; >>>> >>>> ^ this should go in modpost.h if it is to be used in two translation >>>> units, rather than forward declaring it in section-check.c. You did >>>> this for the functions. >>> >>> >>> Sorry, I do not understand. >>> >>> >>> In modpost.h, I put the declaration: >>> >>> extern int sec_mismatch_count; >>> >>> If I moved it to the header without 'extern' >>> I would get multiple definitions. >> >> Yeah, you need to _declare_ it w/ extern in the header, then _define_ >> it in one source file. >> >> That way, if the type ever changes, the sources will agree on type in >> all source files. You will get a redefinition error if the definition >> changes the type of the variable since the last declaration. >> >> What you're doing is forward declaring, which works, and is a common >> pattern for (bloated) C++, but is less type safe than sharing a single >> common declaration between multiple source files via a single common >> shared header. (Sorry I didn't respond before you sent v5) > > Sorry, I still do not understand your suggestion. > > > Could you provide me with a code diff > showing how to do this better? I think you are doing exactly what he's asking for: declare it with extern in the header (modpost.h change) define it in one source file (modpost.c change)