[cfe-dev] Clang on Windows targeting gcc requirements

Edward Diener eldlistmailingz at tropicsoft.com
Sun Jul 5 23:21:26 PDT 2015


On 7/4/2015 11:29 PM, Yaron Keren wrote:
> clang uses its own *intrin.h files, found in ..\lib\clang\3.7.0\include\
> relative to the bin, which appears before the gcc include directories.
> If you run clang++ -v somefile.cpp you'll see which directory clang
> looks for, it should look something like:
>
> #include <...> search starts here:
>   C:\mingw32\i686-w64-mingw32\include\c++
>   C:\mingw32\i686-w64-mingw32\include\c++\i686-w64-mingw32
>   C:\mingw32\i686-w64-mingw32\include\c++\backward
> * C:\llvm\msvc\RelWithDebInfo\bin\..\lib\clang\3.7.0\include*
>   C:\mingw32\lib\gcc\i686-w64-mingw32\4.9.1\include
>   C:\mingw32\lib\gcc\i686-w64-mingw32\4.9.1\include-fixed
>   C:\mingw32\i686-w64-mingw32\include
>   C:\mingw32\include

Look at line 26 of clang's intrin.h. Clang is actually including the 
mingw/gcc intrin.h instead of using its own as long as its the gcc 
version and not the Windows VC++ version. As mentioned for gcc-4.9 and 
up the mingw/gcc intrin.h file brings in all x86 CPU features. This does 
not negatively affect a gcc compile. I am going to assume that it will 
not negatively affect a clang compile.

I did not understand your comment in the link I found at 
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20141110/118349.html. 
I am assuming that it does not mean that clang will output invalid CPU 
instructions just because the mingw/gcc intrin.h file includes all CPU 
intrinsic features. I also did not understand from your discussion in 
the link why clang continues to tag itself as  version 4.2.1 of gcc but 
that is another matter entirely and has to do no doubt with clang 
internals and matters I don't even pretend to understand. I just want to 
verify that the use of mingw/gcc for gcc version 4.9 and up will not 
cause problems when I define __MINGW_FORCE_SYS_INTRINS to avoid 
compilation errors from the mingw/gcc intrin.h header file.

>
>
>
> 2015-07-05 8:43 GMT+03:00 Edward Diener
> <eldlistmailingz at tropicsoft.com
> <mailto:eldlistmailingz at tropicsoft.com>>:
>
>     On 7/3/2015 10:59 AM, Yaron Keren wrote:
>
>         You only need to have the bin directory in your PATH. clang will
>         find
>         the include and library directory based on the bin directory.
>         There are
>         no fixed paths, you can put in c:\mingw or wherever.
>
>
>     I ran into a problem using mingw-64 and the latest clang. In the
>     mingw-64 intrin.h for gcc-4.9 on up it uses the gcc version number
>     to decide whether to define the macro __MINGW_FORCE_SYS_INTRINS. If
>     this macro is not defined it leads to multiple declarations for
>     __m64 and some other CPU feature typdefs. Its gcc implementation
>     defines __MINGW_FORCE_SYS_INTRINS for gcc-4.9 on up but clang still
>     sets the gcc version number to gcc-4.2.1 so that
>     __MINGW_FORCE_SYS_INTRINS is not automatically defined.
>
>     My workaround for this was to define __MINGW_FORCE_SYS_INTRINS when
>     using clang. This appears to work fine in my tests for clang but
>     then I found a link of yours at
>     http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20141110/118349.html
>     which appears to claim that defining __MINGW_FORCE_SYS_INTRINS
>     forces the use of invalid CPU instructions when compiling with clang
>     but evidently not when compiling with gcc.
>
>     Does merely specifying all the x86-x64 compiler intrinsics, as the
>     intrin.h in gcc-4.9 and up does, cause CPU instruction set problems
>     when compiling with clang ? If so this means that I cannot use clang
>     with gcc-4.9 and up unless I locally change their headers to avoid
>     the problem. I have alerted mingw-64 about the general issue.
>
>
>
>
>         2015-07-03 16:13 GMT+03:00 Edward Diener
>         <eldlistmailingz at tropicsoft.com
>         <mailto:eldlistmailingz at tropicsoft.com>
>         <mailto:eldlistmailingz at tropicsoft.com
>         <mailto:eldlistmailingz at tropicsoft.com>>>:
>
>              On 6/25/2015 2:13 PM, Yaron Keren wrote:
>
>                  See http://reviews.llvm.org/D5268
>         <https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D5268&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=6v0YYUzHFzH7arlP_9zpzG3JiWS0RZk2iJCNknhFq2w&s=MbW9hMCfmYAvYW_gmgoNZDxw2dkTs9GWeBpSpkJ56Cs&e=>
>
>         <https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D5268&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=ecMMp1TUmHLfiiZ_MlnPwTgmGQGZqkJoByqz4GWmOJ8&s=GyhTLhjqmvS-L0bXc8ytxxjhk6AnpKowj6eW2JYk9i4&e=>
>
>         <https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D5268&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=YgSrUuiAhPt76cF_h_LXb8Mg84W8p9nMvUiL3koHKP4&s=aW_6t6KDGfo5hO6NiTn5Hy9afNhzwfkX-BZHT9PtXmk&e=>
>
>
>              I can see that the patch has been applied officially to the
>         latest
>              clang source. It's in the latest code when I update llvm/clang.
>              Thanks very much !
>
>              But how do I use it ?
>
>              Am I supposed to be able to build clang using a mingw-64
>         distro in
>              my PATH ?
>
>              When I compile with clang how do I tell it to use the mingw-64
>              headers and RTL ? Does it matter whether the mingw-64
>         distro is 32
>              bit or 64 bit ?
>
>              Do I need to have the mingw-64 distro at c:\mingw ?
>
>              I am willing to test this for clang and report back results
>         here,
>              since I can easily switch between mingw-64 distros ( 4.8.4,
>         4.9.2,
>              5.1 ) and I test a number of Boost libraries including my
>         own with
>              clang, but I need a little information on how to do it.
>
>
>
>
>                  2015-06-25 10:46 GMT+03:00 Edward Diener
>
>         <eldlistmailingz at tropicsoft.com
>         <mailto:eldlistmailingz at tropicsoft.com>
>
>         <mailto:eldlistmailingz at tropicsoft.com
>         <mailto:eldlistmailingz at tropicsoft.com>>
>
>         <mailto:eldlistmailingz at tropicsoft.com
>         <mailto:eldlistmailingz at tropicsoft.com>
>
>
>         <mailto:eldlistmailingz at tropicsoft.com
>         <mailto:eldlistmailingz at tropicsoft.com>>>>:
>
>
>                       For either the latest clang built from souce on
>         Windows or
>                  a binary
>                       distribution of clang on Windows it appears that clang
>                  expects the
>                       supporting gcc include files and lib files to be
>         in the
>                  hardcoded
>                       directory:
>
>                       c:\mingw
>
>                       and follow the mingw directory structure.
>
>                       1) Can this please be changed in the future so
>         that some
>                  environment
>                       variable ( maybe CLANG_GCC ) can be set to the gcc
>         installation
>                       rather than use a hardcoded path ?
>
>                       2) Can clang be updated to support the mingw-64
>         directory
>                  structure
>                       and not just the mingw directory structure ? The
>         mingw-64
>                  distros
>                       seem now to be the preferred gcc distributions on
>         Windows and
>                       support the latest versions of gcc.
>
>                       Do I need to make these suggestions on the clang bug
>                  tracker for the
>                       suggestions to be seriously considered ?u
>
>
>
>              _______________________________________________
>              cfe-dev mailing list
>         cfe-dev at cs.uiuc.edu
>         <mailto:cfe-dev at cs.uiuc.edu>
>              <mailto:cfe-dev at cs.uiuc.edu
>         <mailto:cfe-dev at cs.uiuc.edu>>
>         http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
>
>
>         _______________________________________________
>         cfe-dev mailing list
>         cfe-dev at cs.uiuc.edu
>         <mailto:cfe-dev at cs.uiuc.edu>
>         http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
>
>     _______________________________________________
>     cfe-dev mailing list
>     cfe-dev at cs.uiuc.edu
>     <mailto:cfe-dev at cs.uiuc.edu>
>     http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>





More information about the cfe-dev mailing list