[edk2-devel] [PATCH] Support GLOBAL_REMOVE_IF_UNREFERENCED in GCC5/11

JoeX Lu posted 1 patch 1 year ago
Failed in applying to current master (apply log)
MdePkg/Include/Base.h | 4 ++++
1 file changed, 4 insertions(+)
[edk2-devel] [PATCH] Support GLOBAL_REMOVE_IF_UNREFERENCED in GCC5/11
Posted by JoeX Lu 1 year ago
CC: Michael D Kinney <michael.d.kinney@intel.com>
CC: Liming Gao <gaoliming@byosoft.com.cn>
CC: Zhiguang Liu <zhiguang.liu@intel.com>
Signed-off-by: JoeX Lu <pen-chunx.lu@intel.com>
---
 MdePkg/Include/Base.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h
index 6597e441a6..951fce43ee 100644
--- a/MdePkg/Include/Base.h
+++ b/MdePkg/Include/Base.h
@@ -45,8 +45,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 ///  to it after all compiler and linker optimizations have been performed.
 ///
 ///
+#if defined (__GNUC__)
+#define GLOBAL_REMOVE_IF_UNREFERENCED __attribute__((unused))
+#else
 #define GLOBAL_REMOVE_IF_UNREFERENCED
 #endif
+#endif
 
 //
 // Should be used in combination with NORETURN to avoid 'noreturn' returns
-- 
2.31.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#103732): https://edk2.groups.io/g/devel/message/103732
Mute This Topic: https://groups.io/mt/98551348/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH] Support GLOBAL_REMOVE_IF_UNREFERENCED in GCC5/11
Posted by Pedro Falcato 1 year ago
On Fri, Apr 28, 2023 at 3:47 AM JoeX Lu <pen-chunx.lu@intel.com> wrote:
>
> CC: Michael D Kinney <michael.d.kinney@intel.com>
> CC: Liming Gao <gaoliming@byosoft.com.cn>
> CC: Zhiguang Liu <zhiguang.liu@intel.com>
> Signed-off-by: JoeX Lu <pen-chunx.lu@intel.com>
> ---
>  MdePkg/Include/Base.h | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h
> index 6597e441a6..951fce43ee 100644
> --- a/MdePkg/Include/Base.h
> +++ b/MdePkg/Include/Base.h
> @@ -45,8 +45,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
>  ///  to it after all compiler and linker optimizations have been performed.
>  ///
>  ///
> +#if defined (__GNUC__)
> +#define GLOBAL_REMOVE_IF_UNREFERENCED __attribute__((unused))

According to GCC and LLVM docs, unused does not affect codegen nor
linking, and only silences unused variable/member/function warnings
(-Wunused).
So this is not the attribute you want. This is only doable using LTO
or static, and LTO already does GLOBAL_REMOVE_IF_UNREFERENCED by
default (to *keep* unreferenced symbols, __attribute__((used)) *does*
work).

Note that it also does the right thing if it's a static variable and
it can verify that the current TU will not use it
(https://godbolt.org/z/GsP1TPb39).

-- 
Pedro


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#103747): https://edk2.groups.io/g/devel/message/103747
Mute This Topic: https://groups.io/mt/98551348/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH] Support GLOBAL_REMOVE_IF_UNREFERENCED in GCC5/11
Posted by JoeX Lu 1 year ago
Hi Pedro,
Thanks for your comment.

I hope this attribute can silent Wunused in GCC build.

Because it will be nice to declaim GLOBAL_REMOVE_IF_UNREFERENCED before unusd variable than #ifdef

example1:

#ifdef (UNUSED_CONDITION)

static Boolean samplvariable; // which will be triggered the Wunused warning message in GCC

#endif

example2:

GLOBAL_REMOVE_IF_UNREFERENCED static Boolean samplvariable; // which will be triggered the Wunused warning message in GCC

I think example2 will be better than example1.

Best Regards,

Joe Lu


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#103753): https://edk2.groups.io/g/devel/message/103753
Mute This Topic: https://groups.io/mt/98551348/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


回复: [edk2-devel] [PATCH] Support GLOBAL_REMOVE_IF_UNREFERENCED in GCC5/11
Posted by gaoliming via groups.io 1 year ago
Joe:

 Can you clarify your usage about GLOBAL_REMOVE_IF_UNREFERENCED? With this change, the warning of unused variable will not be reported if the unused variable with this attribute. Is it right?

 

Thanks

Liming

发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 JoeX Lu
发送时间: 2023年4月28日 13:54
收件人: Pedro Falcato <pedro.falcato@gmail.com>; devel@edk2.groups.io
主题: Re: [edk2-devel] [PATCH] Support GLOBAL_REMOVE_IF_UNREFERENCED in GCC5/11

 

Hi Pedro,
  Thanks for your comment.

  I hope this attribute can silent Wunused in GCC build.

  Because it will be nice to declaim GLOBAL_REMOVE_IF_UNREFERENCED before unusd variable than #ifdef

 example1:

 

#ifdef (UNUSED_CONDITION)

  static Boolean samplvariable;  // which will be triggered the Wunused warning message in GCC

#endif

example2:

  GLOBAL_REMOVE_IF_UNREFERENCED  static Boolean samplvariable; // which will be triggered the Wunused warning message in GCC

  I think example2 will be better than example1.

 

Best Regards,

Joe Lu





-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#103970): https://edk2.groups.io/g/devel/message/103970
Mute This Topic: https://groups.io/mt/98679176/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] 回复: [edk2-devel] [PATCH] Support GLOBAL_REMOVE_IF_UNREFERENCED in GCC5/11
Posted by JoeX Lu 1 year ago
Hi Liming,
For question1: We might declaim some variables/functions only used in DEBUG mode and those are necessary variables/functions for debugging but will trigger warning message in RELEASE build.

For question2: Yes


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#104047): https://edk2.groups.io/g/devel/message/104047
Mute This Topic: https://groups.io/mt/98679176/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


回复: [edk2-devel] 回复: [edk2-devel] [PATCH] Support GLOBAL_REMOVE_IF_UNREFERENCED in GCC5/11
Posted by gaoliming via groups.io 1 year ago
Joe:

 Such warning message in RELEASE build is expected. I suggest to disable them by compiler option.  If so, we don’t need to modify source code. 

 

Thanks

Liming

发件人: JoeX Lu <pen-chunx.lu@intel.com> 
发送时间: 2023年5月5日 8:04
收件人: gaoliming <gaoliming@byosoft.com.cn>; devel@edk2.groups.io
主题: Re: [edk2-devel] 回复: [edk2-devel] [PATCH] Support GLOBAL_REMOVE_IF_UNREFERENCED in GCC5/11

 

Hi Liming,
  For question1: We might declaim some variables/functions only used in DEBUG mode and those are necessary variables/functions for debugging but will trigger warning message in RELEASE build.

  For question2: Yes



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#104085): https://edk2.groups.io/g/devel/message/104085
Mute This Topic: https://groups.io/mt/98698470/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] 回复: [edk2-devel] 回复: [edk2-devel] [PATCH] Support GLOBAL_REMOVE_IF_UNREFERENCED in GCC5/11
Posted by JoeX Lu 1 year ago
OK, thanks for your comment.


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#104090): https://edk2.groups.io/g/devel/message/104090
Mute This Topic: https://groups.io/mt/98698470/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-