weidai11 / cryptopp

free C++ class library of cryptographic schemes
https://cryptopp.com
Other
4.82k stars 1.49k forks source link

Unable to link using MSYS2 Clang64 toolchain #1241

Closed ghost closed 12 months ago

abdes commented 12 months ago

If this may help: https://blog.conan.io/2022/10/13/Different-flavors-Clang-compiler-Windows.html

NOTE: Currently, we only include the x64dll.asm and x64masm.asm if MSVC is defined. That is not the case if the compiler is Msys2 Clang.

When exactly are these 2 files expected to be included in the source list?

noloader commented 12 months ago

I can't duplicate this. When I build with g++ in the default environment everything is Ok. The library compiles, links and executes its self tests Ok.

When using the default compiler in the CLANG64 environment, it is g++ and everything is Ok. The library compiles, links and executes its self tests Ok.

msys2-clang64

When I attempt to build with CLANG64 using CXX=clang64++, I get a file not found (the compiler) and the build fails. What compiler name are you using besides g++?

noloader commented 12 months ago

Just the default g++ name is what I’m using.

Ok, thanks.

In CLANG64 this points to clang++.

I'm seeing different results for the CLANG64 environment:

$ command -v g++
/usr/bin/g++

$ ls -Al $(command -v g++)
-rwxr-xr-x 4 Jeffrey Walton None 1637882 Sep 14 04:43 /usr/bin/g++

$ g++ --version
g++ (GCC) 13.2.0

Do you have the clang64 compiler toolchain installed?

I don't know. Do you know what its called or the package name?

I tried running make with CXX=clang64++, but it fails with a "file not found".


I run pacman -Syu when I open a MSYS2 prompt to update all packages. Maybe you need the latest packages, too?

noloader commented 12 months ago

In MSYS2 you can install the toolchain

So this is what I have installed:

$ pacman -Q | grep -E 'clang|gcc|g\+\+'
clang 11.0.0-5
gcc 13.2.0-2
gcc-libs 13.2.0-2
mingw-w64-x86_64-gcc 13.2.0-2
mingw-w64-x86_64-gcc-ada 13.2.0-2
mingw-w64-x86_64-gcc-fortran 13.2.0-2
mingw-w64-x86_64-gcc-libgfortran 13.2.0-2
mingw-w64-x86_64-gcc-libs 13.2.0-2
mingw-w64-x86_64-gcc-objc 13.2.0-2
mingw-w64-x86_64-libgccjit 13.2.0-2

If its missing a package, then please tell me what it is.

I am guessing you are in the CLANG64 environment

Yes. I do a Start -> MSYS2 -> CLANG64 in this case, since we are talking about Clang64.

msys2-environment

but using the toolchain installed from a different environment

Yeah, so I don't know about this. Naively, it seems like the environments should keep themselves separated from one another. Otherwise, what's the point of providing different environments?

noloader commented 12 months ago

The clang64 environment packages should all start with ‘mingw-w64-clang-x86_64’, e.g. ‘mingw-w64-clang-x86_64-clang’.

Ok, thanks. It looks like I can install yet another Clang on this machine:

$ pacman -S mingw-w64-clang-x86_64-clang
resolving dependencies...
looking for conflicting packages...

Packages (19) mingw-w64-clang-x86_64-compiler-rt-17.0.1-1
              mingw-w64-clang-x86_64-crt-git-11.0.0.r198.g93ca95b32-1
              mingw-w64-clang-x86_64-expat-2.5.0-1  mingw-w64-clang-x86_64-gettext-0.21.1-2
              mingw-w64-clang-x86_64-headers-git-11.0.0.r198.g93ca95b32-1
              mingw-w64-clang-x86_64-libc++-17.0.1-1  mingw-w64-clang-x86_64-libffi-3.4.4-1
              mingw-w64-clang-x86_64-libiconv-1.17-3  mingw-w64-clang-x86_64-libunwind-17.0.1-1
              mingw-w64-clang-x86_64-libwinpthread-git-11.0.0.r198.g93ca95b32-1
              mingw-w64-clang-x86_64-libxml2-2.11.5-1  mingw-w64-clang-x86_64-lld-17.0.1-1
              mingw-w64-clang-x86_64-llvm-17.0.1-1  mingw-w64-clang-x86_64-llvm-libs-17.0.1-1
              mingw-w64-clang-x86_64-winpthreads-git-11.0.0.r198.g93ca95b32-1
              mingw-w64-clang-x86_64-xz-5.4.4-1  mingw-w64-clang-x86_64-zlib-1.3-1
              mingw-w64-clang-x86_64-zstd-1.5.5-1  mingw-w64-clang-x86_64-clang-17.0.1-1

Total Download Size:    156.35 MiB
Total Installed Size:  1103.49 MiB

:: Proceed with installation? [Y/n] Y

Do you know what the compiler name is? I'm still getting a "command not found":

$ mingw-w64-clang-x86_64-clang++ --version
-bash: mingw-w64-clang-x86_64-clang++: command not found
noloader commented 12 months ago

Also if it helps, I'm not sure if the inclusion of CPUID64 and XGETBV64 in this environment is intentional or not, but I don't see the file they come from x64dll.asm referenced at all in the GNUmakefile.

Clang is supposed to get into the code path located at https://github.com/weidai11/cryptopp/blob/master/cpu.cpp#L434. It is not supposed to get into the code path for CPUID64 and XGETBV64.

But we've been dealing with Clang's crap for years. It pretends to be other compilers, and then it causes all sorts of problems, like this.

noloader commented 12 months ago

Wouldn't it be just because of this? https://github.com/weidai11/cryptopp/blob/master/config_cpu.h#L206

So that is supposed to be for the version of Clang that Microsoft distributes as part of their Build Tools and Visual Studio and their SDKs. It is not supposed to be for MSYS/MinGW/Cygwin.

I think the problem starts further back, sometime around https://github.com/weidai11/cryptopp/blob/master/config_ver.h#L55.

Maybe we need another Clang differentiator, like CRYPTOPP_MSYS_CLANG_VERSION. This way, we can partition Clang on the Microsoft flavors and the MSYS flavors.

noloader commented 12 months ago

@Steveice10,

Give Commit 19f0e3aa1e63 a try. It tested good for me under MSYS2's CLANG64 environment.

I'm afraid to close this issue because I know how much trouble Clang is...