ついにCygwinでClangがリンクできなくなった
lib/libclangFrontend.a(ChainedIncludesSource.cpp.o):ChainedIncludesSource.cpp:(.debug_loclists+0x46): relocation truncated to fit: IMAGE_REL_AMD64_SECREL against `.debug_info'
でかくなりすぎだろ。。まずDWARFの生成を切って勝負かな。。MSのドキュメントによると、リロケーション IMAGE_REL_AMD64_SECREL
の巾は32bitsらしいのでまぁ問題のリロケーションが発生しないように(= .debug_info
が生成されないように = DWARFを生成しないように)すればOKだろう。
The 32-bit offset of the target from the beginning of its section. This is used to support debugging information and static thread local storage.
これで勝負
cmake -G Ninja -DCMAKE_INSTALL_PREFIX=/cygdrive/f/webkit/llvm \
-DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=X86 \
-DLLVM_PARALLEL_LINK_JOBS=1 "-DLLVM_ENABLE_PROJECTS=clang" \
../../proj/llvm-project/llvm
WindowsのDLLは65,636以上のシンボルをエクスポートできない
[1901/2299] Linking CXX shared library bin/cygclang-cpp-14git.dll
FAILED: bin/cygclang-cpp-14git.dll lib/libclang-cpp.dll.a
: && /usr/bin/c++.exe -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wmisleading-indentation -fdiagnostics-color -fno-common -Woverloaded-virtual -fno-strict-aliasing -O3 -DNDEBUG -Wl,-rpath-link,/cygdrive/f/webkit/build/llvm/./lib -Wl,--gc-sections -Wl,-Bsymbolic-functions -shared -Wl,--enable-auto-import -o bin/cygclang-cpp-14git.dll -Wl,--out-implib,lib/libclang-cpp.dll.a -Wl,--major-image-version,14,--minor-image-version,0 @CMakeFiles/clang-cpp.rsp && :
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: error: export ordinal too large: 76294
collect2: error: ld returned 1 exit status
そりゃそうだ。これはML https://lists.llvm.org/pipermail/llvm-dev/2019-June/133204.html でも話題になっていて、MinGWには対策 https://github.com/llvm/llvm-project/commit/3b1d018c0dba45408164f5e69cb400976efa350f が入っている。...当然Cygwinでも必要になる。Cygwinは UNIX
が真なので専用対策が必要。
diff --git a/clang/tools/CMakeLists.txt b/clang/tools/CMakeLists.txt
index b071a776b32a..32022560c6a3 100644
--- a/clang/tools/CMakeLists.txt
+++ b/clang/tools/CMakeLists.txt
@@ -21,7 +21,7 @@ add_clang_subdirectory(clang-rename)
add_clang_subdirectory(clang-refactor)
# For MinGW we only enable shared library if LLVM_LINK_LLVM_DYLIB=ON.
# Without that option resulting library is too close to 2^16 DLL exports limit.
-if(UNIX OR (MINGW AND LLVM_LINK_LLVM_DYLIB))
+if((UNIX AND NOT CYGWIN) OR ((MINGW OR CYGWIN) AND LLVM_LINK_LLVM_DYLIB))
add_clang_subdirectory(clang-shlib)
endif()
... ということは、Cygwinサポートはロクにメンテされてないな。。?
インクルードパスがおかしい
C++コードがビルドできない。デフォルトのインクルードパスが 何故か32bit用 で、これではstdc++が使えない。。
$ ./clang++ -v -E temp.cpp
clang version 14.0.0 (https://github.com/llvm/llvm-project 01b52f77c95c5702d59bc92c684c8183482de094)
Target: x86_64-unknown-windows-cygnus
Thread model: posix
InstalledDir: /cygdrive/f/webkit/llvm/bin/.
(in-process)
"/cygdrive/f/webkit/llvm/bin/clang" -cc1 -triple x86_64-unknown-windows-cygnus -E -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name temp.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -v -fcoverage-compilation-dir=/cygdrive/f/webkit/llvm/bin -resource-dir /cygdrive/f/webkit/llvm/lib/clang/14.0.0 -fdeprecated-macro -fdebug-compilation-dir=/cygdrive/f/webkit/llvm/bin -ferror-limit 19 -fno-use-cxa-atexit -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -o - -x c++ temp.cpp
clang -cc1 version 14.0.0 based upon LLVM 14.0.0git default target x86_64-unknown-cygwin
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-cygwin/4.7.3/include/c++"
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-cygwin/4.7.3/include/c++/i686-pc-cygwin"
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-cygwin/4.7.3/include/c++/backward"
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++"
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/i686-pc-cygwin"
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/backward"
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-cygwin/4.3.4/include/c++"
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-cygwin/4.3.4/include/c++/i686-pc-cygwin"
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-cygwin/4.3.4/include/c++/backward"
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-cygwin/4.3.2/include/c++"
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-cygwin/4.3.2/include/c++/i686-pc-cygwin"
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-cygwin/4.3.2/include/c++/backward"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/cygdrive/f/webkit/llvm/lib/clang/14.0.0/include
/usr/include/w32api
/usr/include
End of search list.
# 1 "temp.cpp"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 409 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "temp.cpp" 2
とりあえず、Cygwin32は死ぬのが確定している(3.4で廃止)ので、gcc + x86_64前提でやってしまう。
diff --git a/clang/lib/Lex/InitHeaderSearch.cpp b/clang/lib/Lex/InitHeaderSearch.cpp
index ec7b1505c7bf..dc0cfa42901d 100644
--- a/clang/lib/Lex/InitHeaderSearch.cpp
+++ b/clang/lib/Lex/InitHeaderSearch.cpp
@@ -401,12 +401,8 @@ void InitHeaderSearch::AddDefaultCPlusPlusIncludePaths(
switch (triple.getEnvironment()) {
default: llvm_unreachable("Include management is handled in the driver.");
case llvm::Triple::Cygnus:
- // Cygwin-1.7
- AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.7.3");
- AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.5.3");
- AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.4");
- // g++-4 / Cygwin-1.5
- AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2");
+ // Recent Cygwin
+ AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "x86_64-pc-cygwin", "11");
break;
}
break;
TLSが使えない
/usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/mutex:699:10: error: thread-local storage is not supported for the current target
extern __thread void* __once_callable;
^
/usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/mutex:700:10: error: thread-local storage is not supported for the current target
extern __thread void (*__once_call)();
^
2 errors generated.
マジでメンテナンスされてないんだな。。
diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index d1b66432e38b..9cfe260e093c 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -858,7 +858,6 @@ public:
CygwinX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
: X86_64TargetInfo(Triple, Opts) {
this->WCharType = TargetInfo::UnsignedShort;
- TLSSupported = false;
}
void getTargetDefines(const LangOptions &Opts,