public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [RFC] GLOBAL_REMOVE_IF_UNREFERENCED, multiply defined symbols, and MSFT/GCC tool chains.
@ 2017-03-24 12:53 Felix Poludov
  2017-03-24 17:32 ` Ard Biesheuvel
  2017-03-27  4:49 ` Gao, Liming
  0 siblings, 2 replies; 13+ messages in thread
From: Felix Poludov @ 2017-03-24 12:53 UTC (permalink / raw)
  To: edk2-devel@lists.01.org

Trying to add GCC support to projects based on MSFT tool chain, I'm keep stumbling into multiply defined symbol errors reported by GCC linker.
An attempt to understand why the errors are not reported by the Microsoft linker lead me to GLOBAL_REMOVE_IF_UNREFERENCED macro.
The purpose of the macro is to enable link time optimization of global variables.
However, the way it's defined for MSFT tool chain (__declspec(selectany) ) has a side effect of explicitly allowing multiple instances of a symbol defined with GLOBAL_REMOVE_IF_UNREFERENCED.
For a while usage of the macro was the only option to enable global variable optimization.
Starting from VS2013 compiler supports /Gw flag that enables global variable optimization without a special declarator.

I propose to make the following modifications:

1.      Change GLOBAL_REMOVE_IF_UNREFERENCED definition to an empty macro.

Or more specifically, update macro definition in Base.h as follows:

#ifndef GLOBAL_REMOVE_IF_UNREFERENCED

#define GLOBAL_REMOVE_IF_UNREFERENCED

#endif

2.      Update VS2013 and VS2015 compiler flags to add /Gw option

3.      Update compiler flags for older MSFT tool chains to define GLOBAL_REMOVE_IF_UNREFERENCED in a backward compatible manner for targets that enable optimization.

/D GLOBAL_REMOVE_IF_UNREFERENCED =_declspec(selectany)


The advantages of these modifications are:

-        Better detection of on potential errors by breaking the build when symbol is defined more than once.

-        Improved consistency between MSFT and GCC tool chains

-        Improved link time optimization with VS2013 and newer MSFT tool chains.

For example, mGaugeData in MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c is not declared as GLOBAL_REMOVE_IF_UNREFERENCED, so

today performance library is linked with DXE Core even when performance measurements are disabled.

The alternative option is to enable support of multiply defined symbols on GCC tool chain.
One way to do it is by defining the macro as
#define GLOBAL_REMOVE_IF_UNREFERENCED __attribute__((weak))

However, I'm not sure that embracing multiple symbol definitions is a good idea.
For example, see Ard's arguments in this commit comment
https://github.com/tianocore/edk2/commit/214a3b79417f64bf2faae74af42c1b9d23f50dc8

Thanks
Felix

Please consider the environment before printing this email.

The information contained in this message may be confidential and proprietary to American Megatrends, Inc.  This communication is intended to be read only by the individual or entity to whom it is addressed or by their designee. If the reader of this message is not the intended recipient, you are on notice that any distribution of this message, in any form, is strictly prohibited.  Please promptly notify the sender by reply e-mail or by telephone at 770-246-8600, and then delete or destroy all copies of the transmission.


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

end of thread, other threads:[~2017-03-28  6:00 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-24 12:53 [RFC] GLOBAL_REMOVE_IF_UNREFERENCED, multiply defined symbols, and MSFT/GCC tool chains Felix Poludov
2017-03-24 17:32 ` Ard Biesheuvel
2017-03-24 17:57   ` Felix Poludov
2017-03-27  4:49 ` Gao, Liming
2017-03-27 14:58   ` Felix Poludov
2017-03-27 15:35     ` Kinney, Michael D
2017-03-27 15:39       ` Andrew Fish
2017-03-27 15:58       ` Felix Poludov
2017-03-27 16:06         ` Kinney, Michael D
2017-03-27 16:16           ` Felix Poludov
2017-03-27 17:06             ` Kinney, Michael D
2017-03-28  5:01               ` Gao, Liming
2017-03-28  6:00                 ` Kinney, Michael D

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