public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] Support GLOBAL_REMOVE_IF_UNREFERENCED in GCC5/11
@ 2023-04-28  2:46 JoeX Lu
  2023-04-28  4:46 ` [edk2-devel] " Pedro Falcato
  0 siblings, 1 reply; 7+ messages in thread
From: JoeX Lu @ 2023-04-28  2:46 UTC (permalink / raw)
  To: devel; +Cc: JoeX Lu, Michael D Kinney, Liming Gao, Zhiguang Liu

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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [edk2-devel] [PATCH] Support GLOBAL_REMOVE_IF_UNREFERENCED in GCC5/11
  2023-04-28  2:46 [PATCH] Support GLOBAL_REMOVE_IF_UNREFERENCED in GCC5/11 JoeX Lu
@ 2023-04-28  4:46 ` Pedro Falcato
  2023-04-28  5:53   ` JoeX Lu
  0 siblings, 1 reply; 7+ messages in thread
From: Pedro Falcato @ 2023-04-28  4:46 UTC (permalink / raw)
  To: devel, pen-chunx.lu; +Cc: Michael D Kinney, Liming Gao, Zhiguang Liu

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [edk2-devel] [PATCH] Support GLOBAL_REMOVE_IF_UNREFERENCED in GCC5/11
  2023-04-28  4:46 ` [edk2-devel] " Pedro Falcato
@ 2023-04-28  5:53   ` JoeX Lu
  2023-05-04  6:58     ` 回复: " gaoliming
  0 siblings, 1 reply; 7+ messages in thread
From: JoeX Lu @ 2023-04-28  5:53 UTC (permalink / raw)
  To: Pedro Falcato, devel

[-- Attachment #1: Type: text/plain, Size: 559 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 1289 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* 回复: [edk2-devel] [PATCH] Support GLOBAL_REMOVE_IF_UNREFERENCED in GCC5/11
  2023-04-28  5:53   ` JoeX Lu
@ 2023-05-04  6:58     ` gaoliming
  2023-05-05  0:04       ` [edk2-devel] " JoeX Lu
  0 siblings, 1 reply; 7+ messages in thread
From: gaoliming @ 2023-05-04  6:58 UTC (permalink / raw)
  To: devel, pen-chunx.lu, 'Pedro Falcato'

[-- Attachment #1: Type: text/plain, Size: 1091 bytes --]

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




[-- Attachment #2: Type: text/html, Size: 5481 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [edk2-devel] 回复: [edk2-devel] [PATCH] Support GLOBAL_REMOVE_IF_UNREFERENCED in GCC5/11
  2023-05-04  6:58     ` 回复: " gaoliming
@ 2023-05-05  0:04       ` JoeX Lu
  2023-05-05  3:15         ` 回复: " gaoliming
  0 siblings, 1 reply; 7+ messages in thread
From: JoeX Lu @ 2023-05-05  0:04 UTC (permalink / raw)
  To: gaoliming, devel

[-- Attachment #1: Type: text/plain, Size: 225 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 255 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* 回复: [edk2-devel] 回复: [edk2-devel] [PATCH] Support GLOBAL_REMOVE_IF_UNREFERENCED in GCC5/11
  2023-05-05  0:04       ` [edk2-devel] " JoeX Lu
@ 2023-05-05  3:15         ` gaoliming
  2023-05-05  4:47           ` [edk2-devel] " JoeX Lu
  0 siblings, 1 reply; 7+ messages in thread
From: gaoliming @ 2023-05-05  3:15 UTC (permalink / raw)
  To: 'JoeX Lu', devel

[-- Attachment #1: Type: text/plain, Size: 677 bytes --]

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


[-- Attachment #2: Type: text/html, Size: 3679 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [edk2-devel] 回复: [edk2-devel] 回复: [edk2-devel] [PATCH] Support GLOBAL_REMOVE_IF_UNREFERENCED in GCC5/11
  2023-05-05  3:15         ` 回复: " gaoliming
@ 2023-05-05  4:47           ` JoeX Lu
  0 siblings, 0 replies; 7+ messages in thread
From: JoeX Lu @ 2023-05-05  4:47 UTC (permalink / raw)
  To: gaoliming, devel

[-- Attachment #1: Type: text/plain, Size: 30 bytes --]

OK, thanks for your comment.

[-- Attachment #2: Type: text/html, Size: 30 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-05-05  4:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-28  2:46 [PATCH] Support GLOBAL_REMOVE_IF_UNREFERENCED in GCC5/11 JoeX Lu
2023-04-28  4:46 ` [edk2-devel] " Pedro Falcato
2023-04-28  5:53   ` JoeX Lu
2023-05-04  6:58     ` 回复: " gaoliming
2023-05-05  0:04       ` [edk2-devel] " JoeX Lu
2023-05-05  3:15         ` 回复: " gaoliming
2023-05-05  4:47           ` [edk2-devel] " JoeX Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox