From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id EE68AD8108C for ; Fri, 1 Dec 2023 17:07:35 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=Cd/+uHvX09OFQriTFOKNEzjLPPZWhQYLR2OcGfzsSL4=; c=relaxed/simple; d=groups.io; h=DKIM-Filter:Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References:From:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1701450454; v=1; b=dQkJGDXzJJ4ZM6esMMrAF+ETmd7tOq5suo4gSolA8RV/7lxJwfnL8ZC2o94iUlR5gjcQiZTX ditOCvHQrEXHLFlE+Ztb7RCraet5H7xXzcE7FTqL5aCGXFqSN2pKdoDPwKhJUCiinBVQplV/xAD o3KHBjz6IlUNJ+ouFdpriKJ8= X-Received: by 127.0.0.2 with SMTP id qDkAYY7687511xkSQoo5vjdI; Fri, 01 Dec 2023 09:07:34 -0800 X-Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web11.5078.1701450453807848234 for ; Fri, 01 Dec 2023 09:07:33 -0800 X-Received: from [192.168.4.22] (unknown [47.201.241.198]) by linux.microsoft.com (Postfix) with ESMTPSA id 5122120B74C0; Fri, 1 Dec 2023 09:07:32 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 5122120B74C0 Message-ID: <3a8ceb26-6fe9-4a1a-96d2-e74f7b3e7baf@linux.microsoft.com> Date: Fri, 1 Dec 2023 12:07:30 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [edk2-devel] [PATCH 1/2] UnitTestFrameworkPkg: Fix Google Test components with multiple files To: devel@edk2.groups.io, pedro.falcato@gmail.com Cc: Michael D Kinney , Sean Brogan References: <20231130224214.86027-1-pedro.falcato@gmail.com> <20231130224214.86027-2-pedro.falcato@gmail.com> From: "Michael Kubacki" In-Reply-To: <20231130224214.86027-2-pedro.falcato@gmail.com> Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,mikuback@linux.microsoft.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: cyOIogEpgS6VhQusJgbIM9iAx7686176AA= Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=dQkJGDXz; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=linux.microsoft.com (policy=none) Hi Pedro, Visual Studio NOOPT builds result in linker errors. I combined your=20 patch series with the test instruction change in this PR -=20 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). >=20 > This works fine if you're linking a program manually using >=20 > gcc a.o b.o c.o -o test_suite >=20 > 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. >=20 > 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. >=20 > BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4610 > Signed-off-by: Pedro Falcato > Cc: Michael D Kinney > Cc: Michael Kubacki > Cc: Sean Brogan > --- > Note: /WHOLEARCHIVE should work for VS2015 and newer. I haven't been ab= le to > test it, so if someone could test on msft it would be much apprec= iated. > Testing is as simple as taking this patch set > (https://openfw.io/edk2-devel/20231130024611.67135-1-pedro.falcato@gmai= l.com/) > and removing the #include "TestCheckSum.cpp" in TestBaseLibMain.cpp. If= everything worked correctly, > you should have 4 tests and not 0. >=20 > UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) >=20 > diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc b/Unit= TestFrameworkPkg/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 =3D /EHsc > - MSFT:*_*_*_DLINK_FLAGS =3D=3D /out:"$(BIN_DIR)\$(MODULE_NAM= E_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 =3D=3D /out:"$(BIN_DIR)\$(MODULE_NAM= E_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 =3D /MACHINE:I386 > MSFT:*_*_X64_DLINK_FLAGS =3D /MACHINE:AMD64 > =20 > @@ -56,7 +56,12 @@ > # > GCC:*_*_IA32_DLINK_FLAGS =3D=3D -o $(BIN_DIR)/$(MODULE_NAME_GUID) -m3= 2 -no-pie > GCC:*_*_X64_DLINK_FLAGS =3D=3D -o $(BIN_DIR)/$(MODULE_NAME_GUID) -m6= 4 -no-pie > - GCC:*_*_*_DLINK2_FLAGS =3D=3D -lgcov -lpthread -lstdc++ -lm > + # > + # Surround our static libraries with whole-archive, so constructor-bas= ed test registration works properly. > + # Note that we need to --no-whole-archive before linking system librar= ies. > + # > + GCC:*_*_*_DLINK_FLAGS =3D -Wl,--whole-archive > + GCC:*_*_*_DLINK2_FLAGS =3D=3D -Wl,--no-whole-archive -lgcov -lpthrea= d -lstdc++ -lm > =20 > # > # Need to do this link via gcc and not ld as the pathing to libraries= changes from OS version to OS version -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- 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] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-