From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from nwk-aaemail-lapp01.apple.com (nwk-aaemail-lapp01.apple.com [17.151.62.66]) by mx.groups.io with SMTP id smtpd.web12.2017.1572029115620064535 for ; Fri, 25 Oct 2019 11:45:16 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@apple.com header.s=20180706 header.b=w5w0vRA/; spf=pass (domain: apple.com, ip: 17.151.62.66, mailfrom: afish@apple.com) Received: from pps.filterd (nwk-aaemail-lapp01.apple.com [127.0.0.1]) by nwk-aaemail-lapp01.apple.com (8.16.0.27/8.16.0.27) with SMTP id x9PIfXUR007713; Fri, 25 Oct 2019 11:45:14 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apple.com; h=sender : from : message-id : content-type : mime-version : subject : date : in-reply-to : cc : to : references; s=20180706; bh=zX+WXcVVY2V7kfCDesIpgUwNA8iKjt9nGpiB22Prmfg=; b=w5w0vRA/pEeqPab7v4HXEbhqJ11RMKL1yvmDe0k30dJQSGBm3sRBzFl38uN4/q2IGozb V1cAbBMX0NVNMh+ITZFoz/Y6RcfJRk15mxY9SoBuyrfUXQqb4xlsuEMhFfVjzeDBh70v KtX6wC2m92ywwDdN7EfXRe6lzEARl2R7tYv/WlyF9VATb5Ki5BzOSSWf2ZZ1+OdX1D+7 k1Uyg39es+3pjfKT1esl5kMDq8hpt/jSGjwM2fbahz7zitdKh1xgBoQTMLfMP1dpnQm7 8S9BDwRJ1/eu2yO6ARFrym0HYOTopDWVxxz3GsbCg4AprxBLhHNQG25sHkeHSRmYuzxc /w== Received: from mr2-mtap-s01.rno.apple.com (mr2-mtap-s01.rno.apple.com [17.179.226.133]) by nwk-aaemail-lapp01.apple.com with ESMTP id 2vr1e6w8kb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Fri, 25 Oct 2019 11:45:13 -0700 Received: from nwk-mmpp-sz12.apple.com (nwk-mmpp-sz12.apple.com [17.128.115.204]) by mr2-mtap-s01.rno.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) with ESMTPS id <0PZY0098L1FD8Z80@mr2-mtap-s01.rno.apple.com>; Fri, 25 Oct 2019 11:45:13 -0700 (PDT) Received: from process_milters-daemon.nwk-mmpp-sz12.apple.com by nwk-mmpp-sz12.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) id <0PZY009001ARWJ00@nwk-mmpp-sz12.apple.com>; Fri, 25 Oct 2019 11:45:13 -0700 (PDT) X-Va-A: X-Va-T-CD: 7daa14ab80d2839c17f099a8fda5373c X-Va-E-CD: 0b3ad656057f4d390b5c3920634d9433 X-Va-R-CD: ebad80bb98cf8d02fa370c056d39fa63 X-Va-CD: 0 X-Va-ID: f7de8c7f-9912-48b8-ab29-25faed782f3b X-V-A: X-V-T-CD: 7daa14ab80d2839c17f099a8fda5373c X-V-E-CD: 0b3ad656057f4d390b5c3920634d9433 X-V-R-CD: ebad80bb98cf8d02fa370c056d39fa63 X-V-CD: 0 X-V-ID: 4f5a030c-6917-48fa-82fc-6f7a0b089131 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-10-25_09:,, signatures=0 Received: from [17.235.49.133] (unknown [17.235.49.133]) by nwk-mmpp-sz12.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) with ESMTPSA id <0PZY00DIP1FBCEA0@nwk-mmpp-sz12.apple.com>; Fri, 25 Oct 2019 11:45:12 -0700 (PDT) Sender: afish@apple.com From: "Andrew Fish" Message-id: MIME-version: 1.0 (Mac OS X Mail 13.0 \(3594.4.17\)) Subject: Re: [edk2-devel] [Patch v3 10/11] EmulatorPkg: Enable CLANG9 tool chain Date: Fri, 25 Oct 2019 11:45:10 -0700 In-reply-to: <4A89E2EF3DFEDB4C8BFDE51014F606A14E51EC84@SHSMSX104.ccr.corp.intel.com> Cc: "Ni, Ray" , Jordan Justen To: devel@edk2.groups.io, "Gao, Liming" References: <1571295356-11608-1-git-send-email-liming.gao@intel.com> <1571295356-11608-11-git-send-email-liming.gao@intel.com> <734D49CCEBEEF84792F5B80ED585239D5C325BB0@SHSMSX104.ccr.corp.intel.com> <34BE6669-004C-48AD-A09D-FE1A8475ABE0@apple.com> <4A89E2EF3DFEDB4C8BFDE51014F606A14E51EC84@SHSMSX104.ccr.corp.intel.com> X-Mailer: Apple Mail (2.3594.4.17) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-10-25_09:,, signatures=0 Content-type: multipart/alternative; boundary="Apple-Mail=_E8591C3E-2132-4183-8573-1D3DF943C8A8" --Apple-Mail=_E8591C3E-2132-4183-8573-1D3DF943C8A8 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Liming, Sorry I missed this mail. Thanks for the info! I was doing some research i= nto this too and now I think I finally understand. I think the name for the= tool chain really confused me and we should think about changing the name.= = =20 >>From what I understand CLANG9 means produce PE/COFF directly and used the = PDB debugging format. I see from the llvm site that the linker can produce = PDB directly as you mention. This all makes sense to me now as LLVM tries t= o make it easy to be a drop in replacement for VC++ or GCC. So this tool ch= ain is designed to be able to cross build a "Windows App" on a Linux or mac= OS. It also looks like the llvm debugger, lldb, is lagging in its support f= or PDB based debugging.=20 Anyway I think Leif and I agree the toolchain name is very confusing. I'd = rather see it called CLANG9_WIN or CLANG_PDB.=20 > On Oct 18, 2019, at 7:27 AM, Liming Gao wrote: >=20 > Andrew: > Here is the cover letter on CLANG9 introduction. https://edk2.groups.io= /g/devel/message/49157 > > 1) Yes. CLANG9 tool chain is added to directly generate PE/COFF ima= ge (EFI image). > This tool chain uses LLVM clang C compiler and lld linker, generates PE/= COFF > image and PDB compatible debug symbol format. Now, it supports IA32/X64 = Archs. > LLVM clang C compiler and lld linker are the standalone tool set. They d= on=E2=80=99t depend other lib to generate PE/COFF image. > > 2) Yes. CLANG9 is the cross OS tool chain. It can work on Windows/L= inux/Mac host OS. > LLVM LLD linker uses Windows style arguments. I verify CLANG9 for Ovmf32= 64 in Windows/Linux host OS. > On Linux can you source level debug Ovmf?=20 > 3) This patch enables WinHost in Windows. It doesn=E2=80=99t enable = UnixHost. Now, EmulatorPkg with CLANG9 only works on Windows Host. > This patch can make other modules pass build in Windows/Linux/Mac only i= f LLVM9 tool set is installed. > But, the generated image may not work on Linux/Mac. I agree below linker= flags are specific to windows host. > So, I suggest to add the conditional statement of $(WIN_HOST_BUILD) =3D= =3D TRUE for them. > For the EmulatorPkg the Host is a native App for that OS you build on, but= it seems like CLANG9 is targeted to build Windows Apps. I'm not sure but = you might be able to override all the linker commands to build a native app= , or just use the system linker for the Host? I'm not sure how well debugging will work mixing PDB and DWARF symbol form= ats?=20 Thanks, Andrew Fish > !if $(WIN_HOST_BUILD) =3D=3D TRUE > GCC:*_CLANG9_*_DLINK_FLAGS =3D /ALIGN:4096 /FILEALIGN:4096 /SUBSYS= TEM:CONSOLE > GCC:DEBUG_CLANG9_*_DLINK_FLAGS =3D /EXPORT:InitializeDriver=3D$(IMAGE_= ENTRY_POINT) /BASE:0x10000 > GCC:NOOPT_CLANG9_*_DLINK_FLAGS =3D /EXPORT:InitializeDriver=3D$(IMAGE_= ENTRY_POINT) /BASE:0x10000 > !endif > > Thanks > Liming > <>From: afish@apple.com =20 > Sent: Friday, October 18, 2019 1:15 AM > To: Ni, Ray > Cc: Gao, Liming ; devel@edk2.groups.io; Justen, Jo= rdan L > Subject: Re: [Patch v3 10/11] EmulatorPkg: Enable CLANG9 tool chain > > Ray, > > Sorry I'm coming a little late to this and I'm confused. I have some que= stions? > 1) Does CLANG9 imply CLANGPE?=20 > 2) Does CLANGPE work on Linux and macOS? Can you pass the Windows style = arguments to CLANGPE linker on Linux and macOS? > 3) For the EmulatorPkg don't you have the extra requirement that compile= r needs a standard C lib (or platform specific libs) to function? > a) GCC:*_CLANG9_*_DLINK_FLAGS in EmulatorPkg.dsc seems to imply t= he Linux and macOS systems will have a Windows SKD dir and a lot of Windows= DLLs? Does all that come when you install CLANG9 when you install it on Li= nux or macOS? >=20 >=20 > So I guess I'm asking is the linker really the same for CLANG9 on all sy= stems? I guess the answer could be yes, but it seems the C lib for the Host= App is still an App for that OS and is OS dependent?=20 >=20 >=20 > Sorry if I'm missing something fundamental and this is a dumb question.= =20 >=20 >=20 > Thanks, >=20 >=20 > Andrew Fish >=20 > > >=20 >=20 > On Oct 17, 2019, at 12:27 AM, Ni, Ray > wrote: > > Liming, > Emulator is using a generic SEC module. The host specific module is call= ed "Host". > So I prefer to change the macro to "WIN_HOST_BUILD", with this change, R= eviewed-by: Ray Ni > >=20 >=20 > -----Original Message----- > From: Gao, Liming > > Sent: Thursday, October 17, 2019 2:56 PM > To: devel@edk2.groups.io > Cc: Justen, Jordan L >; Andrew Fish > >; Ni, Ray > > Subject: [Patch v3 10/11] EmulatorPkg: Enable CLANG9 tool chain >=20 > BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1603 > 1. Add WIN_SEC_BUILD macro check for CLANG9 tool chain build -p > EmulatorPkg\EmulatorPkg.dsc -a IA32 -DWIN_SEC_BUILD=3DTRUE -t CLANG9 > build -p EmulatorPkg\EmulatorPkg.dsc -a X64 -DWIN_SEC_BUILD=3DTRUE -t > CLANG9 2. Append CLANG CC and LINK flags to generate windows HOST. > 3. Fix WinHost issue to call GetProcessAffinityMask() API. > The input parameter should be UINTN pointer instead of UINT32 pointer. >=20 > Cc: Jordan Justen > > Cc: Andrew Fish > > Cc: Ray Ni > > Signed-off-by: Liming Gao > > --- > EmulatorPkg/Win/Host/WinHost.c | 6 +++--- > EmulatorPkg/EmulatorPkg.dsc | 7 ++++++- > EmulatorPkg/Win/Host/WinHost.inf | 6 ++++++ > 3 files changed, 15 insertions(+), 4 deletions(-) >=20 > diff --git a/EmulatorPkg/Win/Host/WinHost.c > b/EmulatorPkg/Win/Host/WinHost.c index 9aba3c8959..e40ce32548 100644 > --- a/EmulatorPkg/Win/Host/WinHost.c > +++ b/EmulatorPkg/Win/Host/WinHost.c > @@ -356,7 +356,7 @@ Returns: > INTN > EFIAPI > main ( > - IN INTN Argc, > + IN INT Argc, > IN CHAR8 **Argv, > IN CHAR8 **Envp > ) > @@ -391,8 +391,8 @@ Returns: > VOID *SecFile; > CHAR16 *MemorySizeStr; > CHAR16 *FirmwareVolumesStr; > - UINT32 ProcessAffinityMask; > - UINT32 SystemAffinityMask; > + UINTN ProcessAffinityMask; > + UINTN SystemAffinityMask; > INT32 LowBit; >=20 > // > diff --git a/EmulatorPkg/EmulatorPkg.dsc b/EmulatorPkg/EmulatorPkg.dsc > index 20f1187713..72532f5daf 100644 > --- a/EmulatorPkg/EmulatorPkg.dsc > +++ b/EmulatorPkg/EmulatorPkg.dsc > @@ -237,9 +237,10 @@ >=20 > [Components] > !if "IA32" in $(ARCH) || "X64" in $(ARCH) > - !if "MSFT" in $(FAMILY) > + !if "MSFT" in $(FAMILY) || $(WIN_SEC_BUILD) =3D=3D TRUE > ## > # Emulator, OS WIN application > + # CLANG9 is cross OS tool chain. It depends on WIN_SEC_BUILD macro= . > ## > EmulatorPkg/Win/Host/WinHost.inf > !else > @@ -419,7 +420,11 @@ >=20 > MSFT:DEBUG_*_*_CC_FLAGS =3D /Od /Oy- > MSFT:NOOPT_*_*_CC_FLAGS =3D /Od /Oy- > + GCC:DEBUG_CLANG9_*_CC_FLAGS =3D-O0 -Wno-unused-command-line- > argument > + -Wno-incompatible-pointer-types -Wno-enum-conversion > + -Wno-incompatible-pointer-types -Wno-sometimes-uninitialized > + -Wno-constant-conversion -Wno-main-return-type >=20 > MSFT:*_*_*_DLINK_FLAGS =3D /ALIGN:4096 /FILEALIGN:4096 > /SUBSYSTEM:CONSOLE > MSFT:DEBUG_*_*_DLINK_FLAGS =3D > /EXPORT:InitializeDriver=3D$(IMAGE_ENTRY_POINT) /BASE:0x10000 > MSFT:NOOPT_*_*_DLINK_FLAGS =3D > /EXPORT:InitializeDriver=3D$(IMAGE_ENTRY_POINT) /BASE:0x10000 > + GCC:*_CLANG9_*_DLINK_FLAGS =3D /ALIGN:4096 /FILEALIGN:4096 > /SUBSYSTEM:CONSOLE > + GCC:DEBUG_CLANG9_*_DLINK_FLAGS =3D > + /EXPORT:InitializeDriver=3D$(IMAGE_ENTRY_POINT) /BASE:0x10000 > + GCC:NOOPT_CLANG9_*_DLINK_FLAGS =3D > + /EXPORT:InitializeDriver=3D$(IMAGE_ENTRY_POINT) /BASE:0x10000 > diff --git a/EmulatorPkg/Win/Host/WinHost.inf > b/EmulatorPkg/Win/Host/WinHost.inf > index 631d5a6470..1adca10d79 100644 > --- a/EmulatorPkg/Win/Host/WinHost.inf > +++ b/EmulatorPkg/Win/Host/WinHost.inf > @@ -95,3 +95,9 @@ > MSFT:*_VS2017_X64_DLINK_FLAGS =3D > /LIBPATH:"%VCToolsInstallDir%lib\x64" > /LIBPATH:"%UniversalCRTSdkDir%lib\%UCRTVersion%\ucrt\x64" > /LIBPATH:"%WindowsSdkDir%lib\%WindowsSDKLibVersion%\um\x64" > /NOLOGO /SUBSYSTEM:CONSOLE /NODEFAULTLIB /IGNORE:4086 /MAP > /OPT:REF /DEBUG /MACHINE:AMD64 /LTCG Kernel32.lib MSVCRTD.lib > vcruntimed.lib ucrtd.lib Gdi32.lib User32.lib Winmm.lib Advapi32.lib > MSFT:*_*_X64_ASM_FLAGS =3D=3D /nologo /W3 /WX /c /Cx /Zd /W= 0 /Zi > MSFT:*_*_X64_ASMLINK_FLAGS =3D=3D /link /nologo > + > + GCC:*_CLANG9_X64_DLINK_FLAGS =3D=3D > /out:"$(BIN_DIR)\$(BASE_NAME).exe" /base:0x10000000 > /pdb:"$(BIN_DIR)\$(BASE_NAME).pdb" > /LIBPATH:"%UniversalCRTSdkDir%lib\%UCRTVersion%\ucrt\x64" > /LIBPATH:"%WindowsSdkDir%lib\%WindowsSDKLibVersion%\um\x64" > /LIBPATH:"%VCToolsInstallDir%lib\x64" /NOLOGO /SUBSYSTEM:CONSOLE > /NODEFAULTLIB /IGNORE:4086 /OPT:REF /DEBUG /MACHINE:AMD64 > Kernel32.lib MSVCRTD.lib vcruntimed.lib ucrtd.lib Gdi32.lib User32.lib > Winmm.lib Advapi32.lib /lldmap > /EXPORT:InitializeDriver=3D_ModuleEntryPoint > + GCC:*_CLANG9_X64_CC_FLAGS =3D=3D -m64 -g -fshort-wchar > + -fno-strict-aliasing -Wall -c -include AutoGen.h -D > + _CRT_SECURE_NO_WARNINGS -Wnonportable-include-path -D UNICODE > -D > + _CRT_SECURE_NO_DEPRECATE > + > + GCC:*_CLANG9_IA32_DLINK_FLAGS =3D=3D > /out:"$(BIN_DIR)\$(BASE_NAME).exe" /base:0x10000000 > /pdb:"$(BIN_DIR)\$(BASE_NAME).pdb" > /LIBPATH:"%UniversalCRTSdkDir%lib\%UCRTVersion%\ucrt\x86" > /LIBPATH:"%WindowsSdkDir%lib\%WindowsSDKLibVersion%\um\x86" > /LIBPATH:"%VCToolsInstallDir%ib\x86" /NOLOGO /SUBSYSTEM:CONSOLE > /NODEFAULTLIB /IGNORE:4086 /OPT:REF /DEBUG /MACHINE:I386 > Kernel32.lib MSVCRTD.lib vcruntimed.lib ucrtd.lib Gdi32.lib User32.lib > Winmm.lib Advapi32.lib /lldmap > /EXPORT:InitializeDriver=3D_ModuleEntryPoint > + GCC:*_CLANG9_IA32_CC_FLAGS =3D=3D -m32 -g -fshort-wchar > + -fno-strict-aliasing -Wall -c -include AutoGen.h -D > + _CRT_SECURE_NO_WARNINGS -Wnonportable-include-path -D UNICODE > -D > + _CRT_SECURE_NO_DEPRECATE > -- > 2.13.0.windows.1 > > >=20 --Apple-Mail=_E8591C3E-2132-4183-8573-1D3DF943C8A8 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Liming,
Sorry I missed this mail. Thanks for the= info! I was doing some research into this too and now I think I finally un= derstand. I think the name for the tool chain really confused me and we sho= uld think about changing the name. 

From what I understand CLANG9 means produce PE/COFF= directly and used the PDB debugging format. I see from the llvm site that = the linker can produce PDB directly as you mention. This all makes sense to= me now as LLVM tries to make it easy to be a drop in replacement for VC++ = or GCC. So this tool chain is designed to be able to cross build a "Windows= App" on a Linux or macOS. It also looks like the llvm debugger, lldb, is l= agging in its support for PDB based debugging. 
<= br class=3D"">

An= yway I think Leif and I agree the toolchain name is very confusing. I'd rat= her see it called CLANG9_WIN or CLANG_PDB. 

On Oct 18, 201= 9, at 7:27 AM, Liming Gao <liming.gao@intel.com> wrote:

Andrew:
 Here is the cover letter on CLANG9 introduction.=  https://edk2.g= roups.io/g/devel/message/49157
 = ;
1)    &n= bsp; Yes. CLANG9 t= ool chain is added to directly generate PE/COFF image (EFI image).
This tool chain uses LLVM clang C compiler and lld linker, generates= PE/COFF
image and PDB compatible debug symbol format. Now, i= t supports IA32/X64 Archs.
LLVM clang C compiler and lld linker are the standal= one tool set. They don=E2=80=99t depend other lib to generate PE/COFF image= .
 
2)   = ;   Yes.= CLANG9 is the cross OS tool chain. It can work on Windows/Linux/Mac host O= S.
L= LVM LLD linker uses Windows style arguments. I verify CLANG9 for Ovmf3264 i= n Windows/Linux host OS.
 

On Linux = can you source level debug Ovmf? 

3)     This patch enables WinHost in Windows. It doesn=E2=80=99t ena= ble UnixHost. Now, EmulatorPkg with CLANG9 only works on Windows Host.
This patch can make other modules pa= ss build in Windows/Linux/Mac only if LLVM9 tool set is installed.
But, the generated image may not work on = Linux/Mac. I agree below linker flags are specific to windows host.
So, I suggest to add the conditional sta= tement of $(WIN_HOST_BUILD) =3D=3D TRUE for them.
 

For the EmulatorPkg the Host is a native = App for that OS you build on, but it seems like CLANG9 is targeted to build= Windows Apps. I'm not sure  but you might be able to override all the= linker commands to build a native app, or just use the system linker for t= he Host?

I'm not = sure how well debugging will work mixing PDB and DWARF symbol formats? = ;

Thanks,

Andrew Fish
<= div>

= !if $(WIN_HOST_BUILD) =3D=3D TRUE
  GCC:*_CLANG9_*_= DLINK_FLAGS     =3D /ALIGN:4096 /FILEALIGN:4096 /SUBSYS= TEM:CONSOLE
<= span lang=3D"EN-US" class=3D"">  GCC:DEBUG_CLANG9_*_DLINK_FLAGS =3D /E= XPORT:InitializeDriver=3D$(IMAGE_ENTRY_POINT) /BASE:0x10000=
  GCC:NOOPT_CLANG9_*_DLINK_FLAGS =3D /EXPORT:InitializeDriver= =3D$(IMAGE_ENTRY_POINT) /BASE:0x10000
!endif
 
Thanks<= /div>
Liming
From: afish@apple.c= om <afish@apple.com> 
Sent: Frida= y, October 18, 2019 1:15 AM
To: Ni, Ray <
ray.ni@intel.com>
Cc: Gao, Liming &l= t;liming.gao@intel.com>; devel@edk2.group= s.io; Justen, Jordan L <jordan.l.justen@intel.com>
S= ubject: Re: [Patch v3= 10/11] EmulatorPkg: Enable CLANG9 tool chain
<= /div>
 
Ray,
 
Sorry I'm coming a little late to = this and I'm confused. I have some questions?<= /div>
1) Does CLANG9 imply CLANGPE?&= nbsp;
2) Does CL= ANGPE work on Linux and macOS? Can you pass the Windows style arguments to = CLANGPE linker on Linux and macOS?
3) For the EmulatorPkg d= on't you have the extra requirement that compiler needs a standard C lib (o= r platform specific libs) to function?
       a) GCC:*_CLANG9_*_DLINK_FLAGS in EmulatorPkg.dsc seems to = imply the Linux and macOS systems will have a Windows SKD dir and a lot of = Windows DLLs? Does all that come when you install CLANG9 when you install i= t on Linux or macOS?=


<= span lang=3D"EN-US" class=3D"">
So I guess I'm asking is the linker really the same for CLANG9 on = all systems? I guess the answer could be yes, but it seems the C lib for th= e Host App is still an App for that OS and is OS dependent? 


Sorry if I'm missing = something fundamental and this is a dumb question. 


Thanks,


Andrew Fish

 
 


On Oct 17, 2019, at 12:27 AM, Ni,= Ray <ray.ni@intel.com> wrote:
 
<= div class=3D"">
= Liming,
Emulator is using a generic SEC module. The host spec= ific module is called "Host".
So I prefer to change the macro= to "WIN_HOST_BUILD", with this change, Reviewed-by: Ray Ni <ray.ni@intel.com>


-----Original Message-----
From: Gao, = Liming <liming.gao@intel.com>
Sent: Thursday, October 17, 2019 2:56 PM
To: deve= l@edk2.groups.io
Cc: Justen, Jordan L <jordan.l.justen@intel.com>; Andrew Fish
<afish@apple.com>; Ni, Ray <ray.ni@intel.com>
Subject: [Patc= h v3 10/11] EmulatorPkg: Enable CLANG9 tool chain

BZ: https://bugzilla.tianocore.org/sho= w_bug.cgi?id=3D1603
1. Add WIN_SEC_BUILD macro check for = CLANG9 tool chain build -p
EmulatorPkg\EmulatorPkg.dsc -a IA3= 2 -DWIN_SEC_BUILD=3DTRUE -t CLANG9
build -p EmulatorPkg\Emula= torPkg.dsc -a X64 -DWIN_SEC_BUILD=3DTRUE -t
CLANG9 2. Append = CLANG CC and LINK flags to generate windows HOST.
3. Fix WinH= ost issue to call GetProcessAffinityMask() API.
  T= he input parameter should be UINTN pointer instead of UINT32 pointer.

Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Andrew Fish <= afish@apple.com>
Cc: Ray Ni &l= t;ray.ni@intel.com>
Signed-of= f-by: Liming Gao <liming.gao@intel.com&= gt;
---
EmulatorPkg/Win/Host/WinHost.c  &n= bsp;| 6 +++---
EmulatorPkg/EmulatorPkg.dsc    =   | 7 ++++++-
EmulatorPkg/Win/Host/WinHost.inf | 6 = ++++++
3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/EmulatorPkg/Win/Host/WinHost.c
b/EmulatorPkg/Win/Host/WinHost.c index 9aba3c8959..e40ce32548 10064= 4
--- a/EmulatorPkg/Win/Host/WinHost.c
+++ b/Em= ulatorPkg/Win/Host/WinHost.c
@@ -356,7 +356,7 @@ Returns:
INTN
EFIAPI
main (
- &= nbsp;IN  INTN  Argc,
+  IN  INT  Arg= c,
  IN  CHAR8 **Argv,
 &nb= sp;IN  CHAR8 **Envp
  )
@@ -391,= 8 +391,8 @@ Returns:
  VOID     = ;            &n= bsp;*SecFile;
  CHAR16     &nbs= p;          *MemorySizeSt= r;
  CHAR16       &nb= sp;        *FirmwareVolumesStr;
-  UINT32         &= nbsp;      ProcessAffinityMask;
-  UINT32           = ;     SystemAffinityMask;
+  UI= NTN             = ;    ProcessAffinityMask;
+  UINTN &= nbsp;           &nbs= p;   SystemAffinityMask;
  INT32 &nb= sp;            =    LowBit;

  //
diff --git a/EmulatorPkg/EmulatorPkg.dsc b/EmulatorPkg/EmulatorPkg= .dsc
index 20f1187713..72532f5daf 100644
--- a/= EmulatorPkg/EmulatorPkg.dsc
+++ b/EmulatorPkg/EmulatorPkg.dsc=
@@ -237,9 +237,10 @@

[Component= s]
!if "IA32" in $(ARCH) || "X64" in $(ARCH)
- =  !if "MSFT" in $(FAMILY)
+  !if "MSFT" in $(FAMILY)= || $(WIN_SEC_BUILD) =3D=3D TRUE
    ##    #  Emulator, OS WIN application+    #  CLANG9 is cross OS tool chain. It = depends on WIN_SEC_BUILD macro.
    ##    EmulatorPkg/Win/Host/WinHost.inf
  !else
@@ -419,7 +420,11 @@
=
  MSFT:DEBUG_*_*_CC_FLAGS =3D /Od /Oy-
  MSFT:NOOPT_*_*_CC_FLAGS =3D /Od /Oy-
+  G= CC:DEBUG_CLANG9_*_CC_FLAGS =3D-O0 -Wno-unused-command-line-
a= rgument
+ -Wno-incompatible-pointer-types -Wno-enum-conversio= n
+ -Wno-incompatible-pointer-types -Wno-sometimes-uninitiali= zed
+ -Wno-constant-conversion -Wno-main-return-type

  MSFT:*_*_*_DLINK_FLAGS    =  =3D /ALIGN:4096 /FILEALIGN:4096
/SUBSYSTEM:CONSOLE
  MSFT:DEBUG_*_*_DLINK_FLAGS =3D
/EXPORT:= InitializeDriver=3D$(IMAGE_ENTRY_POINT) /BASE:0x10000
 &= nbsp;MSFT:NOOPT_*_*_DLINK_FLAGS =3D
/EXPORT:InitializeDriver= =3D$(IMAGE_ENTRY_POINT) /BASE:0x10000
+  GCC:*_CLANG9_*= _DLINK_FLAGS     =3D /ALIGN:4096 /FILEALIGN:4096
/SUBSYSTEM:CONSOLE
+  GCC:DEBUG_CLANG9_*_DLINK_F= LAGS =3D
+ /EXPORT:InitializeDriver=3D$(IMAGE_ENTRY_POINT) /B= ASE:0x10000
+ GCC:NOOPT_CLANG9_*_DLINK_FLAGS =3D
+ /EXPORT:InitializeDriver=3D$(IMAGE_ENTRY_POINT) /BASE:0x10000
diff --git a/EmulatorPkg/Win/Host/WinHost.inf
b/Emulat= orPkg/Win/Host/WinHost.inf
index 631d5a6470..1adca10d79 10064= 4
--- a/EmulatorPkg/Win/Host/WinHost.inf
+++ b/= EmulatorPkg/Win/Host/WinHost.inf
@@ -95,3 +95,9 @@
  MSFT:*_VS2017_X64_DLINK_FLAGS     &n= bsp;=3D
/LIBPATH:"%VCToolsInstallDir%lib\x64"
/= LIBPATH:"%UniversalCRTSdkDir%lib\%UCRTVersion%\ucrt\x64"
/LIB= PATH:"%WindowsSdkDir%lib\%WindowsSDKLibVersion%\um\x64"
/NOLO= GO /SUBSYSTEM:CONSOLE /NODEFAULTLIB /IGNORE:4086 /MAP
/OPT:RE= F /DEBUG /MACHINE:AMD64 /LTCG Kernel32.lib MSVCRTD.lib
vcrunt= imed.lib ucrtd.lib Gdi32.lib User32.lib Winmm.lib Advapi32.lib
  MSFT:*_*_X64_ASM_FLAGS       &n= bsp;    =3D=3D /nologo /W3 /WX /c /Cx /Zd /W0 /Zi
  MSFT:*_*_X64_ASMLINK_FLAGS     &nb= sp;  =3D=3D /link /nologo
+
+  G= CC:*_CLANG9_X64_DLINK_FLAGS =3D=3D
/out:"$(BIN_DIR)\$(BASE_NA= ME).exe" /base:0x10000000
/pdb:"$(BIN_DIR)\$(BASE_NAME).pdb"<= br class=3D"">/LIBPATH:"%UniversalCRTSdkDir%lib\%UCRTVersion%\ucrt\x64"
/LIBPATH:"%WindowsSdkDir%lib\%WindowsSDKLibVersion%\um\x64"
/LIBPATH:"%VCToolsInstallDir%lib\x64"   /NOLOGO /SUBSYS= TEM:CONSOLE
/NODEFAULTLIB /IGNORE:4086  /OPT:REF /DEBUG = /MACHINE:AMD64
Kernel32.lib MSVCRTD.lib vcruntimed.lib ucrtd.= lib Gdi32.lib User32.lib
Winmm.lib Advapi32.lib /lldmap
/EXPORT:InitializeDriver=3D_ModuleEntryPoint
+  = ;GCC:*_CLANG9_X64_CC_FLAGS =3D=3D -m64 -g -fshort-wchar
+ -fn= o-strict-aliasing -Wall -c -include AutoGen.h -D
+ _CRT_SECUR= E_NO_WARNINGS -Wnonportable-include-path  -D UNICODE
-D<= br class=3D"">+ _CRT_SECURE_NO_DEPRECATE
+
+ &n= bsp;GCC:*_CLANG9_IA32_DLINK_FLAGS =3D=3D
/out:"$(BIN_DIR)\$(B= ASE_NAME).exe" /base:0x10000000
/pdb:"$(BIN_DIR)\$(BASE_NAME)= .pdb"
/LIBPATH:"%UniversalCRTSdkDir%lib\%UCRTVersion%\ucrt\x8= 6"
/LIBPATH:"%WindowsSdkDir%lib\%WindowsSDKLibVersion%\um\x86= "
/LIBPATH:"%VCToolsInstallDir%ib\x86"   /NOLOGO /S= UBSYSTEM:CONSOLE
/NODEFAULTLIB /IGNORE:4086  /OPT:REF /D= EBUG /MACHINE:I386
Kernel32.lib MSVCRTD.lib vcruntimed.lib uc= rtd.lib Gdi32.lib User32.lib
Winmm.lib Advapi32.lib /lldmap/EXPORT:InitializeDriver=3D_ModuleEntryPoint
+ &= nbsp;GCC:*_CLANG9_IA32_CC_FLAGS =3D=3D -m32 -g -fshort-wchar
= + -fno-strict-aliasing -Wall -c -include AutoGen.h -D
+ _CRT_= SECURE_NO_WARNINGS -Wnonportable-include-path  -D UNICODE
-D
+ _CRT_SECURE_NO_DEPRECATE
--
2.13.0.windows.1
 
 
<= /div>
--Apple-Mail=_E8591C3E-2132-4183-8573-1D3DF943C8A8--