<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:DengXian;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"\@等线";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.apple-converted-space
        {mso-style-name:apple-converted-space;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Vitaly:<o:p></o:p></p>
<p class="MsoNormal">  We also find _MSC_VER is defined in Windows, but not in Linux. Your analysis explains it. When use i686-unknown-windows-gnu option, __GNUC__ macro will be defined. If so, we don’t need to append the check for defined (__clang__) in Base.h.
 And, this change can remove -fno-ms-extensions and -fms-compatibility option. Then, CLANGPDB can keep the same behavior in Windows/Linux/MacOs host OS.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">#if defined (__GNUC__) || defined (__clang__)<o:p></o:p></p>
<p class="MsoNormal"><span style="font-family:Wingdings">è</span><o:p></o:p></p>
<p class="MsoNormal">#if defined (__GNUC__)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks<o:p></o:p></p>
<p class="MsoNormal">Liming<o:p></o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> devel@edk2.groups.io <devel@edk2.groups.io> <b>
On Behalf Of </b>Vitaly Cheptsov via Groups.Io<br>
<b>Sent:</b> Thursday, February 6, 2020 8:17 AM<br>
<b>To:</b> Gao, Liming <liming.gao@intel.com><br>
<b>Cc:</b> devel@edk2.groups.io; Marvin Häuser <marvin.haeuser@outlook.com>; Laszlo Ersek <lersek@redhat.com>; Kinney, Michael D <michael.d.kinney@intel.com><br>
<b>Subject:</b> Re: [edk2-devel] [PATCH 0/1] Use _MSC_VER to determine MSVC compiler<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">Liming,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">We performed the initial exploration of CLANGPDB toolchain issue on our end and believe we can suggest a solid solution.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">In addition to all the issues I mentioned in the BZ[1] there are several more.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">1. CLANGPDB uses -target x86_64-unknown-windows, and this basically means different behaviour for Windows and other operating systems:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">- On Windows it will "attach" to installed Visual Studio and will gather the parameters from this installation, i.e. it will define _MSC_VER to installed Visual Studio version. For example, for me it is implicitly passing -fms-compatibility-version=19.16.27026
 and setting full triple to x86_64-unknown-windows-msvc19.16.27026.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">- On Mac and Linux it will obviously not find Visual Studio, and as a result the full triple will be x86_64-unknown-windows-msvc with _MSC_VER macro not <span style="color:black">being</span> defined.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">There basically is no control to it except -U_MSC_VER, which is ugly, as different include directories, other defines will still happen between installations.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">2. EDK II relies on UINT32_MAX being a valid value for enum. This is not the case in the specification, as it requires enum to be either INT32 or UINT32:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Element of a standard ANSI C enum type declaration. Type INT32.or UINT32. ANSI C does not define the size of sign of an enum so they should never be used in structures. ANSI C integer promotion rules make INT32 or UINT32 interchangeable
 when passed as an argument to a function.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">However, since I am not positive that no existing code relies on this, it is best to preserve the current behaviour. Supporting this is valid for GNU flavour or as a Microsoft Extension. Disabling -fms-compatibility will result in a compile
 error for enums having 0xFFFFFFFF values, like in Base.h.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">All in all, we believe that CLANGPDB simply has an overlook in the -target argument due to a misconsideration of the clang triple implementation. Normally for target only 3 words are provided, but for Windows it is crucial to have 4, as
 there are different drivers with different automatics. To resolve the problem, we should use GNU targets i686-unknown-windows-gnu and x86_64-unknown-windows-gnu. <span style="color:black">This is basically the only and the least hurtful solution, as using
 MSVC mode will define _MSC_EXTENSIONS, which already breaks many places and will require a heavy codebase refactoring, and randomly define _MSC_VER and use Visual Studio headers and configuration, which makes reproducible builds on different operating systems
 questionable if not impossible.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black"><br>
<br>
</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">I will submit another patch that will replace this one later this week. In addition to GNU targets I additionally pass -nostdlib and -nostdlibinc so that a freestanding target is used and only builtin headers are accessible (like stdint.h,
 stddef.h, and stdbool.h). This is not required but an extra safety measure. Our initial validation of the changes found no issues with our projects. We also performed building of most common EDK II packages like CryptoPkg, MdePkg, and MdeModulePkg. While the
 change is fairly minor, I will still request others to perform a brief check of their packages in case they want to use CLANGPDB. For a quick test I include the diff of the patch beforehand.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Best wishes,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Vitaly<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">[1] <a href="https://bugzilla.tianocore.org/show_bug.cgi?id=2397">https://bugzilla.tianocore.org/show_bug.cgi?id=2397</a><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">4 февр. 2020 г., в 09:56, Gao, Liming <<a href="mailto:liming.gao@intel.com">liming.gao@intel.com</a>> написал(а):<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">Vitaly:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  Yes. I think we should have better solution in OpenSSL to support EDK2 usage. But, this is a long term solution. For now, I will try the solution to remove -fms-compatibility option in CLANGPDB tool chain.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Thanks<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Liming<o:p></o:p></p>
</div>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<div>
<p class="MsoNormal"><b>From:</b><span class="apple-converted-space"> </span>vit9696 <<a href="mailto:vit9696@protonmail.com">vit9696@protonmail.com</a>><span class="apple-converted-space"> </span><br>
<b>Sent:</b><span class="apple-converted-space"> </span>Monday, February 3, 2020 7:29 PM<br>
<b>To:</b><span class="apple-converted-space"> </span>Gao, Liming <<a href="mailto:liming.gao@intel.com">liming.gao@intel.com</a>>;
<a href="mailto:devel@edk2.groups.io">devel@edk2.groups.io</a>; Marvin Häuser <<a href="mailto:marvin.haeuser@outlook.com">marvin.haeuser@outlook.com</a>><br>
<b>Subject:</b><span class="apple-converted-space"> </span>RE: [edk2-devel] [PATCH 0/1] Use _MSC_VER to determine MSVC compiler<o:p></o:p></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">Liming,<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal">I believe it is reasonable to fix OpenSSL, but most likely it is faster to address EDK II code at first. In future we should still stick to _MSC_VER, but for now just ensuring that any toolchain by MSVC does not define _MSC_EXTENSIONS should
 work too.<o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">I believe that -fms-compatibility option is not needed for CLANGPDB, as CLANGPDB is literally using clang, and that worked fine before in CLANG38 and XCODE5. We may still have to update some preprocessor conditions to include __clang__
 near __GNUC__ if __GNUC__ is left undefined even when we remove -fms-compatibility, but that sounds fine for me.<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">We will investigate that on our own and submit a new patch, but help from other parties is strongly appreciated. We mostly use XCODE5 and are not well aware of other platforms.<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">Best wishes,<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">Vitaly<o:p></o:p></p>
</div>
</div>
<div>
<div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal">On Mon, Feb 3, 2020 at 11:00, Gao, Liming <<a href="mailto:liming.gao@intel.com"><span style="color:purple">liming.gao@intel.com</span></a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal" style="margin-bottom:12.0pt">Vitaly:<br>
This change will cause CryptoPkg openssl build failure, because OpensslLib.inf undefines _MSC_VER macro to make sure openssl source code be built in edk2 project without using MS VS functions.<br>
<br>
Now, I have no good solution to fix this issue. One way is to use defined(_MSC_EXTENSIONS) && !defined(__clang__), another way is to investigate whether we can remove -fms-compatibility option in CLANGPDB.<br>
<br>
Thanks<br>
Liming<br>
> -----Original Message-----<br>
> From:<span class="apple-converted-space"> </span><a href="mailto:devel@edk2.groups.io"><span style="color:purple">devel@edk2.groups.io</span></a><span class="apple-converted-space"> </span><<a href="mailto:devel@edk2.groups.io"><span style="color:purple">devel@edk2.groups.io</span></a>>
 On Behalf Of Vitaly Cheptsov via Groups.Io<br>
> Sent: Saturday, February 1, 2020 5:17 AM<br>
> To:<span class="apple-converted-space"> </span><a href="mailto:devel@edk2.groups.io"><span style="color:purple">devel@edk2.groups.io</span></a><br>
> Subject: [edk2-devel] [PATCH 0/1] Use _MSC_VER to determine MSVC compiler<br>
><br>
> Patch details are explained in<span class="apple-converted-space"> </span><a href="https://bugzilla.tianocore.org/show_bug.cgi?id=2397"><span style="color:purple">https://bugzilla.tianocore.org/show_bug.cgi?id=2397</span></a>.<br>
> We request this to be merged in edk2-stable202002.<br>
><br>
> Vitaly Cheptsov (1):<br>
> MdePkg: Use _MSC_VER to determine MSVC compiler<br>
><br>
> MdePkg/Include/AArch64/ProcessorBind.h | 2 +-<br>
> MdePkg/Include/Arm/ProcessorBind.h | 8 ++++----<br>
> MdePkg/Include/Base.h | 10 +++++-----<br>
> MdePkg/Include/Ia32/ProcessorBind.h | 6 +++---<br>
> MdePkg/Include/X64/ProcessorBind.h | 6 +++---<br>
> 5 files changed, 16 insertions(+), 16 deletions(-)<br>
><br>
> --<br>
> 2.21.1 (Apple Git-122.3)<br>
><br>
><br>
> -=-=-=-=-=-=<br>
> <a href="http://Groups.io">Groups.io</a> Links: You receive all messages sent to this group.<br>
><br>
> View/Reply Online (#53623):<span class="apple-converted-space"> </span><a href="https://edk2.groups.io/g/devel/message/53623"><span style="color:purple">https://edk2.groups.io/g/devel/message/53623</span></a><br>
> Mute This Topic:<span class="apple-converted-space"> </span><a href="https://groups.io/mt/70882954/1759384"><span style="color:purple">https://groups.io/mt/70882954/1759384</span></a><br>
> Group Owner:<span class="apple-converted-space"> </span><a href="mailto:devel+owner@edk2.groups.io"><span style="color:purple">devel+owner@edk2.groups.io</span></a><br>
> Unsubscribe:<span class="apple-converted-space"> </span><a href="https://edk2.groups.io/g/devel/unsub"><span style="color:purple">https://edk2.groups.io/g/devel/unsub</span></a><span class="apple-converted-space"> </span>[<a href="mailto:liming.gao@intel.com">liming.gao@intel.com</a>]<br>
> -=-=-=-=-=-=<o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"></o:p></span></p>
</div>
</div>
</body>
</html>

<div width="1" style="color:white;clear:both">_._,_._,_</div>
<hr>
Groups.io Links:<p>


You receive all messages sent to this group.



<p>

<a target="_blank" href="https://edk2.groups.io/g/devel/message/53846">View/Reply Online (#53846)</a> |


  


|


  
    <a target="_blank" href="https://groups.io/mt/70882954/1813853">Mute This Topic</a>
  

| <a href="https://edk2.groups.io/g/devel/post">New Topic</a><br>



<br>

<a href="https://edk2.groups.io/g/devel/editsub/1813853">Your Subscription</a> |
<a href="mailto:devel+owner@edk2.groups.io">Contact Group Owner</a> |

<a href="https://edk2.groups.io/g/devel/unsub">Unsubscribe</a>

 [edk2-devel-archive@redhat.com]<br>
<div width="1" style="color:white;clear:both">_._,_._,_</div>