* [edk2-devel] [PATCH 0/2] UnitTestFrameworkPkg: Fix Google Test components with multiple files @ 2023-11-30 22:42 Pedro Falcato 2023-11-30 22:42 ` [edk2-devel] [PATCH 1/2] " Pedro Falcato 2023-11-30 22:42 ` [edk2-devel] [PATCH 2/2] UnitTestFrameworkPkg/Readme.md: Remove the mention of the gtest main() limitation Pedro Falcato 0 siblings, 2 replies; 11+ messages in thread From: Pedro Falcato @ 2023-11-30 22:42 UTC (permalink / raw) To: devel; +Cc: Pedro Falcato, Michael D Kinney, Michael Kubacki, Sean Brogan Google Test hides test registration in global constructors on global objects. Global constructors are traditionally implemented by placing references to the global constructor's symbol in special sections (traditionally named .ctors or .init_array). These sections are not explicitly referenced by the linker, and libc only looks at special start and end symbols (and calls them). This works fine if you're linking a program manually using gcc a.o b.o c.o -o test_suite but fails miserably when using static libraries (such as what EDK2 does), because traditional static archive symbol resolution rules don't allow for object files to be pulled in to the link if there isn't an undefined symbol reference to that .o elsewhere. Fix it by passing --whole-archive (GCC) and /WHOLEARCHIVE (MSVC). These options force the linker to pull in the entire static library, thus including previously-unreferenced constructors and making sure multi-file gtest EDK2 components work. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4610 Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Michael Kubacki <mikuback@linux.microsoft.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Pedro Falcato (2): UnitTestFrameworkPkg: Fix Google Test components with multiple files UnitTestFrameworkPkg/Readme.md: Remove the mention of the gtest main() limitation UnitTestFrameworkPkg/ReadMe.md | 16 ---------------- .../UnitTestFrameworkPkgHost.dsc.inc | 9 +++++++-- 2 files changed, 7 insertions(+), 18 deletions(-) -- 2.43.0 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111915): https://edk2.groups.io/g/devel/message/111915 Mute This Topic: https://groups.io/mt/102904622/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=- ^ permalink raw reply [flat|nested] 11+ messages in thread
* [edk2-devel] [PATCH 1/2] UnitTestFrameworkPkg: Fix Google Test components with multiple files 2023-11-30 22:42 [edk2-devel] [PATCH 0/2] UnitTestFrameworkPkg: Fix Google Test components with multiple files Pedro Falcato @ 2023-11-30 22:42 ` Pedro Falcato 2023-12-01 17:07 ` Michael Kubacki 2023-11-30 22:42 ` [edk2-devel] [PATCH 2/2] UnitTestFrameworkPkg/Readme.md: Remove the mention of the gtest main() limitation Pedro Falcato 1 sibling, 1 reply; 11+ messages in thread From: Pedro Falcato @ 2023-11-30 22:42 UTC (permalink / raw) To: devel; +Cc: Pedro Falcato, Michael D Kinney, Michael Kubacki, Sean Brogan Google Test hides test registration in global constructors on global objects. Global constructors are traditionally implemented by placing references to the global constructor's symbol in special sections (traditionally named .ctors or .init_array). These sections are not explicitly referenced by the linker, and libc only looks at special start and end symbols (and calls them). This works fine if you're linking a program manually using gcc a.o b.o c.o -o test_suite but fails miserably when using static libraries (such as what EDK2 does), because traditional static archive symbol resolution rules don't allow for object files to be pulled in to the link if there isn't an undefined symbol reference to that .o elsewhere. Fix it by passing --whole-archive (GCC) and /WHOLEARCHIVE (MSVC). These options force the linker to pull in the entire static library, thus including previously-unreferenced constructors and making sure multi-file gtest EDK2 components work. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4610 Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Michael Kubacki <mikuback@linux.microsoft.com> Cc: Sean Brogan <sean.brogan@microsoft.com> --- Note: /WHOLEARCHIVE should work for VS2015 and newer. I haven't been able to test it, so if someone could test on msft it would be much appreciated. Testing is as simple as taking this patch set (https://openfw.io/edk2-devel/20231130024611.67135-1-pedro.falcato@gmail.com/) and removing the #include "TestCheckSum.cpp" in TestBaseLibMain.cpp. If everything worked correctly, you should have 4 tests and not 0. UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc index 5217de31e491..0f11706e7324 100644 --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc @@ -37,7 +37,7 @@ # MSFT # MSFT:*_*_*_CC_FLAGS = /EHsc - MSFT:*_*_*_DLINK_FLAGS == /out:"$(BIN_DIR)\$(MODULE_NAME_GUID).exe" /pdb:"$(BIN_DIR)\$(MODULE_NAME_GUID).pdb" /IGNORE:4001 /NOLOGO /SUBSYSTEM:CONSOLE /DEBUG /STACK:0x40000,0x40000 /NODEFAULTLIB:libcmt.lib libcmtd.lib + MSFT:*_*_*_DLINK_FLAGS == /out:"$(BIN_DIR)\$(MODULE_NAME_GUID).exe" /pdb:"$(BIN_DIR)\$(MODULE_NAME_GUID).pdb" /IGNORE:4001 /NOLOGO /SUBSYSTEM:CONSOLE /DEBUG /STACK:0x40000,0x40000 /NODEFAULTLIB:libcmt.lib libcmtd.lib /WHOLEARCHIVE MSFT:*_*_IA32_DLINK_FLAGS = /MACHINE:I386 MSFT:*_*_X64_DLINK_FLAGS = /MACHINE:AMD64 @@ -56,7 +56,12 @@ # GCC:*_*_IA32_DLINK_FLAGS == -o $(BIN_DIR)/$(MODULE_NAME_GUID) -m32 -no-pie GCC:*_*_X64_DLINK_FLAGS == -o $(BIN_DIR)/$(MODULE_NAME_GUID) -m64 -no-pie - GCC:*_*_*_DLINK2_FLAGS == -lgcov -lpthread -lstdc++ -lm + # + # Surround our static libraries with whole-archive, so constructor-based test registration works properly. + # Note that we need to --no-whole-archive before linking system libraries. + # + GCC:*_*_*_DLINK_FLAGS = -Wl,--whole-archive + GCC:*_*_*_DLINK2_FLAGS == -Wl,--no-whole-archive -lgcov -lpthread -lstdc++ -lm # # Need to do this link via gcc and not ld as the pathing to libraries changes from OS version to OS version -- 2.43.0 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111916): https://edk2.groups.io/g/devel/message/111916 Mute This Topic: https://groups.io/mt/102904623/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=- ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [edk2-devel] [PATCH 1/2] UnitTestFrameworkPkg: Fix Google Test components with multiple files 2023-11-30 22:42 ` [edk2-devel] [PATCH 1/2] " Pedro Falcato @ 2023-12-01 17:07 ` Michael Kubacki 2023-12-01 20:50 ` Pedro Falcato [not found] ` <179CD05BE5E43398.18076@groups.io> 0 siblings, 2 replies; 11+ messages in thread From: Michael Kubacki @ 2023-12-01 17:07 UTC (permalink / raw) To: devel, pedro.falcato; +Cc: Michael D Kinney, Sean Brogan Hi Pedro, Visual Studio NOOPT builds result in linker errors. I combined your patch series with the test instruction change in this PR - https://github.com/tianocore/edk2/pull/5096. You can use a PR to test the VS build. Thanks, Michael On 11/30/2023 5:42 PM, Pedro Falcato wrote: > Google Test hides test registration in global constructors on global > objects. Global constructors are traditionally implemented by placing > references to the global constructor's symbol in special sections > (traditionally named .ctors or .init_array). These sections are not > explicitly referenced by the linker, and libc only looks at special > start and end symbols (and calls them). > > This works fine if you're linking a program manually using > > gcc a.o b.o c.o -o test_suite > > but fails miserably when using static libraries (such as what EDK2 > does), because traditional static archive symbol resolution rules don't > allow for object files to be pulled in to the link if there isn't an > undefined symbol reference to that .o elsewhere. > > Fix it by passing --whole-archive (GCC) and /WHOLEARCHIVE (MSVC). These > options force the linker to pull in the entire static library, thus > including previously-unreferenced constructors and making sure > multi-file gtest EDK2 components work. > > BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4610 > Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com> > Cc: Michael D Kinney <michael.d.kinney@intel.com> > Cc: Michael Kubacki <mikuback@linux.microsoft.com> > Cc: Sean Brogan <sean.brogan@microsoft.com> > --- > Note: /WHOLEARCHIVE should work for VS2015 and newer. I haven't been able to > test it, so if someone could test on msft it would be much appreciated. > Testing is as simple as taking this patch set > (https://openfw.io/edk2-devel/20231130024611.67135-1-pedro.falcato@gmail.com/) > and removing the #include "TestCheckSum.cpp" in TestBaseLibMain.cpp. If everything worked correctly, > you should have 4 tests and not 0. > > UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc > index 5217de31e491..0f11706e7324 100644 > --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc > +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc > @@ -37,7 +37,7 @@ > # MSFT > # > MSFT:*_*_*_CC_FLAGS = /EHsc > - MSFT:*_*_*_DLINK_FLAGS == /out:"$(BIN_DIR)\$(MODULE_NAME_GUID).exe" /pdb:"$(BIN_DIR)\$(MODULE_NAME_GUID).pdb" /IGNORE:4001 /NOLOGO /SUBSYSTEM:CONSOLE /DEBUG /STACK:0x40000,0x40000 /NODEFAULTLIB:libcmt.lib libcmtd.lib > + MSFT:*_*_*_DLINK_FLAGS == /out:"$(BIN_DIR)\$(MODULE_NAME_GUID).exe" /pdb:"$(BIN_DIR)\$(MODULE_NAME_GUID).pdb" /IGNORE:4001 /NOLOGO /SUBSYSTEM:CONSOLE /DEBUG /STACK:0x40000,0x40000 /NODEFAULTLIB:libcmt.lib libcmtd.lib /WHOLEARCHIVE > MSFT:*_*_IA32_DLINK_FLAGS = /MACHINE:I386 > MSFT:*_*_X64_DLINK_FLAGS = /MACHINE:AMD64 > > @@ -56,7 +56,12 @@ > # > GCC:*_*_IA32_DLINK_FLAGS == -o $(BIN_DIR)/$(MODULE_NAME_GUID) -m32 -no-pie > GCC:*_*_X64_DLINK_FLAGS == -o $(BIN_DIR)/$(MODULE_NAME_GUID) -m64 -no-pie > - GCC:*_*_*_DLINK2_FLAGS == -lgcov -lpthread -lstdc++ -lm > + # > + # Surround our static libraries with whole-archive, so constructor-based test registration works properly. > + # Note that we need to --no-whole-archive before linking system libraries. > + # > + GCC:*_*_*_DLINK_FLAGS = -Wl,--whole-archive > + GCC:*_*_*_DLINK2_FLAGS == -Wl,--no-whole-archive -lgcov -lpthread -lstdc++ -lm > > # > # Need to do this link via gcc and not ld as the pathing to libraries changes from OS version to OS version -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111983): https://edk2.groups.io/g/devel/message/111983 Mute This Topic: https://groups.io/mt/102904623/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=- ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [edk2-devel] [PATCH 1/2] UnitTestFrameworkPkg: Fix Google Test components with multiple files 2023-12-01 17:07 ` Michael Kubacki @ 2023-12-01 20:50 ` Pedro Falcato [not found] ` <179CD05BE5E43398.18076@groups.io> 1 sibling, 0 replies; 11+ messages in thread From: Pedro Falcato @ 2023-12-01 20:50 UTC (permalink / raw) To: devel, mikuback; +Cc: Michael D Kinney, Sean Brogan On Fri, Dec 1, 2023 at 5:07 PM Michael Kubacki <mikuback@linux.microsoft.com> wrote: > > Hi Pedro, > > Visual Studio NOOPT builds result in linker errors. I combined your > patch series with the test instruction change in this PR - > https://github.com/tianocore/edk2/pull/5096. > > You can use a PR to test the VS build. Thanks for the heads up, but I ended up booting Windows to expedite the process. So, I noticed from the build logs that libcmtd.lib was having issues doing a /WHOLEARCHIVE link (not unheard of, had the same problems with Linux system libraries). Then I noticed in MSDN: "The /WHOLEARCHIVE option forces the linker to include every object file from either a specified static library, or if no library is specified, from all static libraries specified to the LINK command" Note the "from all static libraries specified to the LINK command". So I noticed libcmtd.lib was being specified manually, and I simply deleted /NODEFAULTLIB:libcmt.lib libcmtd.lib From line 40 of UnitTestFrameworkPkgHost.dsc.inc. So, before I submit a v2 of this, does anyone know why this was added manually? Mike? Note: I tried to add /MTd, but that seems to be a cl.exe option, not link.exe -- Pedro -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111985): https://edk2.groups.io/g/devel/message/111985 Mute This Topic: https://groups.io/mt/102904623/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=- ^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <179CD05BE5E43398.18076@groups.io>]
* Re: [edk2-devel] [PATCH 1/2] UnitTestFrameworkPkg: Fix Google Test components with multiple files [not found] ` <179CD05BE5E43398.18076@groups.io> @ 2023-12-01 20:52 ` Pedro Falcato 2023-12-01 21:28 ` Michael D Kinney 0 siblings, 1 reply; 11+ messages in thread From: Pedro Falcato @ 2023-12-01 20:52 UTC (permalink / raw) To: devel, pedro.falcato; +Cc: mikuback, Michael D Kinney, Sean Brogan On Fri, Dec 1, 2023 at 8:50 PM Pedro Falcato via groups.io <pedro.falcato=gmail.com@groups.io> wrote: > > On Fri, Dec 1, 2023 at 5:07 PM Michael Kubacki > <mikuback@linux.microsoft.com> wrote: > > > > Hi Pedro, > > > > Visual Studio NOOPT builds result in linker errors. I combined your > > patch series with the test instruction change in this PR - > > https://github.com/tianocore/edk2/pull/5096. > > > > You can use a PR to test the VS build. > > Thanks for the heads up, but I ended up booting Windows to expedite the process. > > So, I noticed from the build logs that libcmtd.lib was having issues > doing a /WHOLEARCHIVE link (not unheard of, had the same problems with > Linux system libraries). Then I noticed in MSDN: > "The /WHOLEARCHIVE option forces the linker to include every object > file from either a specified static library, or if no library is > specified, from all static libraries specified to the LINK command" > Note the "from all static libraries specified to the LINK command". So > I noticed libcmtd.lib was being specified manually, and I simply > deleted > > /NODEFAULTLIB:libcmt.lib libcmtd.lib ... Forgot to mention that deleting this line allows the link to complete and /WHOLEARCHIVE has the intended effect. -- Pedro -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111986): https://edk2.groups.io/g/devel/message/111986 Mute This Topic: https://groups.io/mt/102904623/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=- ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [edk2-devel] [PATCH 1/2] UnitTestFrameworkPkg: Fix Google Test components with multiple files 2023-12-01 20:52 ` Pedro Falcato @ 2023-12-01 21:28 ` Michael D Kinney 2023-12-03 0:34 ` Michael D Kinney 0 siblings, 1 reply; 11+ messages in thread From: Michael D Kinney @ 2023-12-01 21:28 UTC (permalink / raw) To: Pedro Falcato, devel@edk2.groups.io Cc: mikuback@linux.microsoft.com, Sean Brogan, Kinney, Michael D Hi Pedro, Thanks for the follow up and debug. I suspect some of those flags were inherited from EmulatorPkg builds and may not apply to GoogeTest builds. I will investigate. Very happy to see a solution for this issue. Mike > -----Original Message----- > From: Pedro Falcato <pedro.falcato@gmail.com> > Sent: Friday, December 1, 2023 12:53 PM > To: devel@edk2.groups.io; pedro.falcato@gmail.com > Cc: mikuback@linux.microsoft.com; Kinney, Michael D > <michael.d.kinney@intel.com>; Sean Brogan <sean.brogan@microsoft.com> > Subject: Re: [edk2-devel] [PATCH 1/2] UnitTestFrameworkPkg: Fix Google Test > components with multiple files > > On Fri, Dec 1, 2023 at 8:50 PM Pedro Falcato via groups.io > <pedro.falcato=gmail.com@groups.io> wrote: > > > > On Fri, Dec 1, 2023 at 5:07 PM Michael Kubacki > > <mikuback@linux.microsoft.com> wrote: > > > > > > Hi Pedro, > > > > > > Visual Studio NOOPT builds result in linker errors. I combined your > > > patch series with the test instruction change in this PR - > > > https://github.com/tianocore/edk2/pull/5096. > > > > > > You can use a PR to test the VS build. > > > > Thanks for the heads up, but I ended up booting Windows to expedite the > process. > > > > So, I noticed from the build logs that libcmtd.lib was having issues > > doing a /WHOLEARCHIVE link (not unheard of, had the same problems with > > Linux system libraries). Then I noticed in MSDN: > > "The /WHOLEARCHIVE option forces the linker to include every object > > file from either a specified static library, or if no library is > > specified, from all static libraries specified to the LINK command" > > Note the "from all static libraries specified to the LINK command". So > > I noticed libcmtd.lib was being specified manually, and I simply > > deleted > > > > /NODEFAULTLIB:libcmt.lib libcmtd.lib > > ... Forgot to mention that deleting this line allows the link to > complete and /WHOLEARCHIVE has the intended effect. > > -- > Pedro -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111988): https://edk2.groups.io/g/devel/message/111988 Mute This Topic: https://groups.io/mt/102904623/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/xyzzy [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=- ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [edk2-devel] [PATCH 1/2] UnitTestFrameworkPkg: Fix Google Test components with multiple files 2023-12-01 21:28 ` Michael D Kinney @ 2023-12-03 0:34 ` Michael D Kinney 2023-12-03 2:37 ` Michael D Kinney 0 siblings, 1 reply; 11+ messages in thread From: Michael D Kinney @ 2023-12-03 0:34 UTC (permalink / raw) To: Pedro Falcato, devel@edk2.groups.io Cc: mikuback@linux.microsoft.com, Sean Brogan, Kinney, Michael D Hi Pedro, I have reviewed the use of /NODEFAULTLIB. It is correct for this flag to be used for FW components to prevent standard application libs from being linked. For any component that links as a Windows application, this flag should not be used. This applies to host based unit tests and to the EmulatorPkg/Host/Win. I have verified that /NODEFAULTLIB can be removed from both of these use cases and only use /NODEFAULTLIB for FW components. With /NODEFAULTLIB removed from UnitTestFrameworkPkgHost.dsc.inc This series is: Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com> I have taken the branch from Michael Kubacki and added this one change to run through EDK II CI and added by Rb tags. https://github.com/tianocore/edk2/pull/5098 Best regards, Mike > -----Original Message----- > From: Kinney, Michael D <michael.d.kinney@intel.com> > Sent: Friday, December 1, 2023 1:29 PM > To: Pedro Falcato <pedro.falcato@gmail.com>; devel@edk2.groups.io > Cc: mikuback@linux.microsoft.com; Sean Brogan <sean.brogan@microsoft.com>; > Kinney, Michael D <michael.d.kinney@intel.com> > Subject: RE: [edk2-devel] [PATCH 1/2] UnitTestFrameworkPkg: Fix Google Test > components with multiple files > > Hi Pedro, > > Thanks for the follow up and debug. > > I suspect some of those flags were inherited from > EmulatorPkg builds and may not apply to GoogeTest > builds. > > I will investigate. > > Very happy to see a solution for this issue. > > Mike > > > -----Original Message----- > > From: Pedro Falcato <pedro.falcato@gmail.com> > > Sent: Friday, December 1, 2023 12:53 PM > > To: devel@edk2.groups.io; pedro.falcato@gmail.com > > Cc: mikuback@linux.microsoft.com; Kinney, Michael D > > <michael.d.kinney@intel.com>; Sean Brogan <sean.brogan@microsoft.com> > > Subject: Re: [edk2-devel] [PATCH 1/2] UnitTestFrameworkPkg: Fix Google > Test > > components with multiple files > > > > On Fri, Dec 1, 2023 at 8:50 PM Pedro Falcato via groups.io > > <pedro.falcato=gmail.com@groups.io> wrote: > > > > > > On Fri, Dec 1, 2023 at 5:07 PM Michael Kubacki > > > <mikuback@linux.microsoft.com> wrote: > > > > > > > > Hi Pedro, > > > > > > > > Visual Studio NOOPT builds result in linker errors. I combined your > > > > patch series with the test instruction change in this PR - > > > > https://github.com/tianocore/edk2/pull/5096. > > > > > > > > You can use a PR to test the VS build. > > > > > > Thanks for the heads up, but I ended up booting Windows to expedite the > > process. > > > > > > So, I noticed from the build logs that libcmtd.lib was having issues > > > doing a /WHOLEARCHIVE link (not unheard of, had the same problems with > > > Linux system libraries). Then I noticed in MSDN: > > > "The /WHOLEARCHIVE option forces the linker to include every object > > > file from either a specified static library, or if no library is > > > specified, from all static libraries specified to the LINK command" > > > Note the "from all static libraries specified to the LINK command". So > > > I noticed libcmtd.lib was being specified manually, and I simply > > > deleted > > > > > > /NODEFAULTLIB:libcmt.lib libcmtd.lib > > > > ... Forgot to mention that deleting this line allows the link to > > complete and /WHOLEARCHIVE has the intended effect. > > > > -- > > Pedro -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111992): https://edk2.groups.io/g/devel/message/111992 Mute This Topic: https://groups.io/mt/102904623/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/xyzzy [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=- ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [edk2-devel] [PATCH 1/2] UnitTestFrameworkPkg: Fix Google Test components with multiple files 2023-12-03 0:34 ` Michael D Kinney @ 2023-12-03 2:37 ` Michael D Kinney 2023-12-03 12:11 ` Pedro Falcato 0 siblings, 1 reply; 11+ messages in thread From: Michael D Kinney @ 2023-12-03 2:37 UTC (permalink / raw) To: Pedro Falcato, devel@edk2.groups.io Cc: mikuback@linux.microsoft.com, Sean Brogan, Kinney, Michael D Merged: https://github.com/tianocore/edk2/pull/5098 > -----Original Message----- > From: Kinney, Michael D <michael.d.kinney@intel.com> > Sent: Saturday, December 2, 2023 4:34 PM > To: Pedro Falcato <pedro.falcato@gmail.com>; devel@edk2.groups.io > Cc: mikuback@linux.microsoft.com; Sean Brogan <sean.brogan@microsoft.com>; > Kinney, Michael D <michael.d.kinney@intel.com> > Subject: RE: [edk2-devel] [PATCH 1/2] UnitTestFrameworkPkg: Fix Google Test > components with multiple files > > Hi Pedro, > > I have reviewed the use of /NODEFAULTLIB. > > It is correct for this flag to be used for FW components > to prevent standard application libs from being linked. > > For any component that links as a Windows application, this > flag should not be used. This applies to host based unit > tests and to the EmulatorPkg/Host/Win. I have verified that > /NODEFAULTLIB can be removed from both of these use cases > and only use /NODEFAULTLIB for FW components. > > With /NODEFAULTLIB removed from UnitTestFrameworkPkgHost.dsc.inc > This series is: > > Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com> > > I have taken the branch from Michael Kubacki and added this > one change to run through EDK II CI and added by Rb tags. > > https://github.com/tianocore/edk2/pull/5098 > > Best regards, > > Mike > > > > > -----Original Message----- > > From: Kinney, Michael D <michael.d.kinney@intel.com> > > Sent: Friday, December 1, 2023 1:29 PM > > To: Pedro Falcato <pedro.falcato@gmail.com>; devel@edk2.groups.io > > Cc: mikuback@linux.microsoft.com; Sean Brogan > <sean.brogan@microsoft.com>; > > Kinney, Michael D <michael.d.kinney@intel.com> > > Subject: RE: [edk2-devel] [PATCH 1/2] UnitTestFrameworkPkg: Fix Google > Test > > components with multiple files > > > > Hi Pedro, > > > > Thanks for the follow up and debug. > > > > I suspect some of those flags were inherited from > > EmulatorPkg builds and may not apply to GoogeTest > > builds. > > > > I will investigate. > > > > Very happy to see a solution for this issue. > > > > Mike > > > > > -----Original Message----- > > > From: Pedro Falcato <pedro.falcato@gmail.com> > > > Sent: Friday, December 1, 2023 12:53 PM > > > To: devel@edk2.groups.io; pedro.falcato@gmail.com > > > Cc: mikuback@linux.microsoft.com; Kinney, Michael D > > > <michael.d.kinney@intel.com>; Sean Brogan <sean.brogan@microsoft.com> > > > Subject: Re: [edk2-devel] [PATCH 1/2] UnitTestFrameworkPkg: Fix Google > > Test > > > components with multiple files > > > > > > On Fri, Dec 1, 2023 at 8:50 PM Pedro Falcato via groups.io > > > <pedro.falcato=gmail.com@groups.io> wrote: > > > > > > > > On Fri, Dec 1, 2023 at 5:07 PM Michael Kubacki > > > > <mikuback@linux.microsoft.com> wrote: > > > > > > > > > > Hi Pedro, > > > > > > > > > > Visual Studio NOOPT builds result in linker errors. I combined your > > > > > patch series with the test instruction change in this PR - > > > > > https://github.com/tianocore/edk2/pull/5096. > > > > > > > > > > You can use a PR to test the VS build. > > > > > > > > Thanks for the heads up, but I ended up booting Windows to expedite > the > > > process. > > > > > > > > So, I noticed from the build logs that libcmtd.lib was having issues > > > > doing a /WHOLEARCHIVE link (not unheard of, had the same problems > with > > > > Linux system libraries). Then I noticed in MSDN: > > > > "The /WHOLEARCHIVE option forces the linker to include every object > > > > file from either a specified static library, or if no library is > > > > specified, from all static libraries specified to the LINK command" > > > > Note the "from all static libraries specified to the LINK command". > So > > > > I noticed libcmtd.lib was being specified manually, and I simply > > > > deleted > > > > > > > > /NODEFAULTLIB:libcmt.lib libcmtd.lib > > > > > > ... Forgot to mention that deleting this line allows the link to > > > complete and /WHOLEARCHIVE has the intended effect. > > > > > > -- > > > Pedro -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111994): https://edk2.groups.io/g/devel/message/111994 Mute This Topic: https://groups.io/mt/102904623/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/xyzzy [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=- ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [edk2-devel] [PATCH 1/2] UnitTestFrameworkPkg: Fix Google Test components with multiple files 2023-12-03 2:37 ` Michael D Kinney @ 2023-12-03 12:11 ` Pedro Falcato 0 siblings, 0 replies; 11+ messages in thread From: Pedro Falcato @ 2023-12-03 12:11 UTC (permalink / raw) To: devel, michael.d.kinney; +Cc: mikuback@linux.microsoft.com, Sean Brogan On Sun, Dec 3, 2023 at 2:37 AM Michael D Kinney <michael.d.kinney@intel.com> wrote: > > Merged: https://github.com/tianocore/edk2/pull/5098 I was going to submit a v2, but thanks for cleaning things up and pushing! -- Pedro -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111995): https://edk2.groups.io/g/devel/message/111995 Mute This Topic: https://groups.io/mt/102904623/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=- ^ permalink raw reply [flat|nested] 11+ messages in thread
* [edk2-devel] [PATCH 2/2] UnitTestFrameworkPkg/Readme.md: Remove the mention of the gtest main() limitation 2023-11-30 22:42 [edk2-devel] [PATCH 0/2] UnitTestFrameworkPkg: Fix Google Test components with multiple files Pedro Falcato 2023-11-30 22:42 ` [edk2-devel] [PATCH 1/2] " Pedro Falcato @ 2023-11-30 22:42 ` Pedro Falcato 2023-12-01 17:10 ` Michael Kubacki 1 sibling, 1 reply; 11+ messages in thread From: Pedro Falcato @ 2023-11-30 22:42 UTC (permalink / raw) To: devel; +Cc: Pedro Falcato, Michael D Kinney, Michael Kubacki, Sean Brogan As of the previous commit, this limitation is no longer a thing. You can now write gtest unit tests with multiple files and no need for any hack such as #include. Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Michael Kubacki <mikuback@linux.microsoft.com> Cc: Sean Brogan <sean.brogan@microsoft.com> --- UnitTestFrameworkPkg/ReadMe.md | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/UnitTestFrameworkPkg/ReadMe.md b/UnitTestFrameworkPkg/ReadMe.md index 7da6a320a7f1..d6a3e0c15a2b 100644 --- a/UnitTestFrameworkPkg/ReadMe.md +++ b/UnitTestFrameworkPkg/ReadMe.md @@ -1096,22 +1096,6 @@ int main(int argc, char* argv[]) { } ``` -However, while GoogleTest does not require test suites or test cases to be -registered, there is still one rule within EDK II that currently needs to be -followed. This rule is that all tests for a given GoogleTest application must -be contained within the same source file that contains the `main()` function -shown above. These tests can be written directly in the file or a `#include` -can be used to add them into the file indirectly. - -The reason for this is due to EDK II taking the host application INF file and -first compiling all of its source files into a static library. This static -library is then linked into the final host application. The problem with this -method is that only the tests in the object file containing the `main()` -function are linked into the final host application. This is because the other -tests are contained in their own object files within the static library and -they have no symbols in them that the final host application depends on, so -those object files are not linked into the final host application. - ### GoogleTest - A Simple Test Case Below is a sample test case from `SampleGoogleTestHost`. -- 2.43.0 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111917): https://edk2.groups.io/g/devel/message/111917 Mute This Topic: https://groups.io/mt/102904624/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=- ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [edk2-devel] [PATCH 2/2] UnitTestFrameworkPkg/Readme.md: Remove the mention of the gtest main() limitation 2023-11-30 22:42 ` [edk2-devel] [PATCH 2/2] UnitTestFrameworkPkg/Readme.md: Remove the mention of the gtest main() limitation Pedro Falcato @ 2023-12-01 17:10 ` Michael Kubacki 0 siblings, 0 replies; 11+ messages in thread From: Michael Kubacki @ 2023-12-01 17:10 UTC (permalink / raw) To: devel, pedro.falcato; +Cc: Michael D Kinney, Sean Brogan Hi Pedro, PatchCheck flagged the subject length: UnitTestFrameworkPkg/Readme.md: Remove the mention of the gtest main() limitation The commit message format is not valid: * First line of commit message (subject line) is too long (81 >= 76). https://github.com/tianocore/tianocore.github.io/wiki/Commit-Message-Format The code passed all checks. I think the following is also clear enough: "UnitTestFrameworkPkg/Readme.md: Remove the gtest main() limitation" Thanks, Michael On 11/30/2023 5:42 PM, Pedro Falcato wrote: > As of the previous commit, this limitation is no longer a thing. > You can now write gtest unit tests with multiple files and no need for > any hack such as #include. > > Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com> > Cc: Michael D Kinney <michael.d.kinney@intel.com> > Cc: Michael Kubacki <mikuback@linux.microsoft.com> > Cc: Sean Brogan <sean.brogan@microsoft.com> > --- > UnitTestFrameworkPkg/ReadMe.md | 16 ---------------- > 1 file changed, 16 deletions(-) > > diff --git a/UnitTestFrameworkPkg/ReadMe.md b/UnitTestFrameworkPkg/ReadMe.md > index 7da6a320a7f1..d6a3e0c15a2b 100644 > --- a/UnitTestFrameworkPkg/ReadMe.md > +++ b/UnitTestFrameworkPkg/ReadMe.md > @@ -1096,22 +1096,6 @@ int main(int argc, char* argv[]) { > } > ``` > > -However, while GoogleTest does not require test suites or test cases to be > -registered, there is still one rule within EDK II that currently needs to be > -followed. This rule is that all tests for a given GoogleTest application must > -be contained within the same source file that contains the `main()` function > -shown above. These tests can be written directly in the file or a `#include` > -can be used to add them into the file indirectly. > - > -The reason for this is due to EDK II taking the host application INF file and > -first compiling all of its source files into a static library. This static > -library is then linked into the final host application. The problem with this > -method is that only the tests in the object file containing the `main()` > -function are linked into the final host application. This is because the other > -tests are contained in their own object files within the static library and > -they have no symbols in them that the final host application depends on, so > -those object files are not linked into the final host application. > - > ### GoogleTest - A Simple Test Case > > Below is a sample test case from `SampleGoogleTestHost`. -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111984): https://edk2.groups.io/g/devel/message/111984 Mute This Topic: https://groups.io/mt/102904624/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=- ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2023-12-03 12:12 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-11-30 22:42 [edk2-devel] [PATCH 0/2] UnitTestFrameworkPkg: Fix Google Test components with multiple files Pedro Falcato 2023-11-30 22:42 ` [edk2-devel] [PATCH 1/2] " Pedro Falcato 2023-12-01 17:07 ` Michael Kubacki 2023-12-01 20:50 ` Pedro Falcato [not found] ` <179CD05BE5E43398.18076@groups.io> 2023-12-01 20:52 ` Pedro Falcato 2023-12-01 21:28 ` Michael D Kinney 2023-12-03 0:34 ` Michael D Kinney 2023-12-03 2:37 ` Michael D Kinney 2023-12-03 12:11 ` Pedro Falcato 2023-11-30 22:42 ` [edk2-devel] [PATCH 2/2] UnitTestFrameworkPkg/Readme.md: Remove the mention of the gtest main() limitation Pedro Falcato 2023-12-01 17:10 ` Michael Kubacki
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox