<div dir="ltr"><div dir="ltr"><div dir="ltr">Hi,<br><br>I'm trying to use clang on cygwin to compile C++ files but the executable it produces fails to run. I get runtime failures from cygwin:<br><br>    Cygwin runtime failure: a.exe: Invalid relocation.  Offset 0x2fd4bce73 at address 0x1004010e9 doesn't fit into 32 bits<br><br>sample code - proba.cpp:<br><br>    #include <iostream><br>    using namespace std;<br>    <br>    int main(void)<br>    {<br>        cout << "Hello, World!";<br>        return 0;<br>    }<br><br>compiled with:<br><br>    clang++ proba.cpp<br><br>Compilation finishes without any error or warning.<br><br>clang was compiled from sources. I tried the latest release (8.0.0) as well as git version (26.03.2019). Both produces the same error when running its output.<br><br>clang installation procedure was the following:<br><br>    git clone <a href="https://github.com/llvm/llvm-project.git">https://github.com/llvm/llvm-project.git</a><br>    mkdir build<br>    cd build<br>    cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang;compiler-rt;lld;" -DLLVM_TARGETS_TO_BUILD=X86 ../llvm/<br>    make -j4<br>    make install<br><br>cygwin also has a clang package (version 5.0.1) that compiles proba.cpp to a working executable. The reason of not using that is it does not compile SystemC libraries (<a href="https://www.accellera.org/downloads/standards/systemc">https://www.accellera.org/downloads/standards/systemc</a>) correctly. There are few tests that fail during 'make check' in contrast when compiling with gcc (7.4.0) all the tests pass.<br><br>I also noticed that clang drivers that compiled from sources use g++ as the linker while the one comes with the cygwin package uses ld. I also did not manage to force clang 9 to use lld instead of g++. (-fuse-ld=lld is not recognized by g++)<br><br>clang comes with cygwin:<br><br>    $ clang++ -v proba.cpp -o a_clang5.exe<br>    clang version 5.0.1 (tags/RELEASE_501/final)<br>    Target: x86_64-unknown-windows-cygnus<br>    Thread model: posix<br>    InstalledDir: /usr/bin<br>     "/usr/bin/clang-5.0" -cc1 -triple x86_64-unknown-windows-cygnus -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name proba.cpp -mre<br>    location-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -momit-leaf-frame-pointer -v -dwarf-co<br>    lumn-info -debugger-tuning=gdb -resource-dir /usr/lib/clang/5.0.1 -internal-isystem /usr/x86_64-pc-cygwin/include/c++ -internal-isystem /usr/x86_64-pc-cygwin/include/c++/x86_6<br>    4-pc-cygwin -internal-isystem /usr/x86_64-pc-cygwin/include/c++/backward -internal-isystem /usr/x86_64-pc-cygwin/include/c++/7.4.0 -internal-isystem /usr/x86_64-pc-cygwin/incl<br>    ude/c++/7.4.0/x86_64-pc-cygwin -internal-isystem /usr/x86_64-pc-cygwin/include/c++/7.4.0/backward -internal-isystem /usr/include/c++/7.4.0 -internal-isystem /usr/include/c++/7<br>    .4.0/x86_64-pc-cygwin -internal-isystem /usr/include/c++/7.4.0/backward -internal-isystem /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++ -internal-isystem /usr/lib/gcc/x86_64<br>    -pc-cygwin/7.4.0/include/c++/x86_64-pc-cygwin -internal-isystem /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/backward -internal-isystem /usr/local/include -internal-isystem<br>     /usr/lib/clang/5.0.1/include -internal-isystem /usr/x86_64-pc-cygwin/include -internal-isystem /usr/include -internal-isystem /usr/include/w32api -fdeprecated-macro -fdebug-c<br>    ompilation-dir /cygdrive/c/home/peter.gerst/tmp/clang_proba -ferror-limit 19 -fmessage-length 175 -femulated-tls -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics<br>    -show-option -fcolor-diagnostics -o /tmp/proba-e855cb.o -x c++ proba.cpp<br>    clang -cc1 version 5.0.1 based upon LLVM 5.0.1 default target x86_64-unknown-windows-cygnus<br>    ignoring nonexistent directory "/usr/x86_64-pc-cygwin/include/c++"<br>    ignoring nonexistent directory "/usr/x86_64-pc-cygwin/include/c++/x86_64-pc-cygwin"<br>    ignoring nonexistent directory "/usr/x86_64-pc-cygwin/include/c++/backward"<br>    ignoring nonexistent directory "/usr/x86_64-pc-cygwin/include/c++/7.4.0"<br>    ignoring nonexistent directory "/usr/x86_64-pc-cygwin/include/c++/7.4.0/x86_64-pc-cygwin"<br>    ignoring nonexistent directory "/usr/x86_64-pc-cygwin/include/c++/7.4.0/backward"<br>    ignoring nonexistent directory "/usr/include/c++/7.4.0"<br>    ignoring nonexistent directory "/usr/include/c++/7.4.0/x86_64-pc-cygwin"<br>    ignoring nonexistent directory "/usr/include/c++/7.4.0/backward"<br>    ignoring nonexistent directory "/usr/local/include"<br>    ignoring nonexistent directory "/usr/x86_64-pc-cygwin/include"<br>    #include "..." search starts here:<br>    #include <...> search starts here:<br>     /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++<br>     /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/x86_64-pc-cygwin<br>     /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/backward<br>     /usr/lib/clang/5.0.1/include<br>     /usr/include<br>     /usr/include/w32api<br>    End of search list.<br>     "/usr/bin/ld" -m i386pep --wrap _Znwm --wrap _Znam --wrap _ZnwmRKSt9nothrow_t --wrap _ZnamRKSt9nothrow_t --wrap _ZdlPv --wrap _ZdaPv --wrap _ZdlPvRKSt9nothrow_t --wrap _ZdaPv<br>    KSt9nothrow_t -Bdynamic --tsaware -o a_clang5.exe /usr/lib/crt0.o /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/crtbegin.o -L/usr/lib/gcc/x86_64-pc-cygwin/7.4.0 -L/usr/x86_64-pc-cygwin/<br>    lib -L/usr/lib /tmp/proba-e855cb.o -lstdc++ -liconv -lgcc_s -lgcc -lcygwin -ladvapi32 -lshell32 -luser32 -lkernel32 -lgcc_s -lgcc -lcygwin /usr/lib/default-manifest.o /usr/lib<br>    /gcc/x86_64-pc-cygwin/7.4.0/crtend.o<br><br>clang 9 compiled from sources:<br><br>    $ clang++ -v proba.cpp -o a.exe<br>    clang version 9.0.0 (<a href="https://github.com/llvm/llvm-project.git">https://github.com/llvm/llvm-project.git</a> e24441aab03e393d591d9252612e8c0ac557b1c3)<br>    Target: x86_64-unknown-windows-cygnus<br>    Thread model: posix<br>    InstalledDir: /usr/local/bin<br>     "/usr/local/bin/clang-9" -cc1 -triple x86_64-unknown-windows-cygnus -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name proba.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -v -resource-dir /usr/local/lib/clang/9.0.0 -fdeprecated-macro -fdebug-compilation-dir /cygdrive/c/home/peter.gerst/tmp/clang_proba -ferror-limit 19 -fmessage-length 135 -fno-use-cxa-atexit -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/proba-b6bf15.o -x c++ proba.cpp -faddrsig<br>    clang -cc1 version 9.0.0 based upon LLVM 9.0.0svn default target x86_64-unknown-cygwin<br>    #include "..." search starts here:<br>    #include <...> search starts here:<br>     /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++<br>     /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/x86_64-pc-cygwin<br>     /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/backward<br>     /usr/local/include<br>     /usr/local/lib/clang/9.0.0/include<br>     /usr/include/w32api<br>     /usr/include<br>    End of search list.<br>     "/usr/bin/g++" -v -m64 -o a.exe /tmp/proba-b6bf15.o<br>    Using built-in specs.<br>    COLLECT_GCC=/usr/bin/g++<br>    COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/lto-wrapper.exe<br>    Target: x86_64-pc-cygwin<br>    Configured with: /cygdrive/i/szsz/tmpp/gcc/gcc-7.4.0-1.x86_64/src/gcc-7.4.0/configure --srcdir=/cygdrive/i/szsz/tmpp/gcc/gcc-7.4.0-1.x86_64/src/gcc-7.4.0 --prefix=/usr --exec-prefix=/usr --localstatedir=/var --sysconfdir=/etc --docdir=/usr/share/doc/gcc --htmldir=/usr/share/doc/gcc/html -C --build=x86_64-pc-cygwin --host=x86_64-pc-cygwin --target=x86_64-pc-cygwin --without-libiconv-prefix --without-libintl-prefix --libexecdir=/usr/lib --enable-shared --enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs --enable-bootstrap --enable-__cxa_atexit --with-dwarf2 --with-tune=generic --enable-languages=ada,c,c++,fortran,lto,objc,obj-c++ --enable-graphite --enable-threads=posix --enable-libatomic --enable-libcilkrts --enable-libgomp --enable-libitm --enable-libquadmath --enable-libquadmath-support --disable-libssp --enable-libada --disable-symvers --with-gnu-ld --with-gnu-as --with-cloog-include=/usr/include/cloog-isl --without-libiconv-prefix --without-libintl-prefix --with-system-zlib --enable-linker-build-id --with-default-libstdcxx-abi=gcc4-compatible --enable-libstdcxx-filesystem-ts<br>    Thread model: posix<br>    gcc version 7.4.0 (GCC)<br>    COMPILER_PATH=/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/:/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/:/usr/lib/gcc/x86_64-pc-cygwin/:/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/:/usr/lib/gcc/x86_64-pc-cygwin/:/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/../../../../x86_64-pc-cygwin/bin/<br>    LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/:/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/../../../../x86_64-pc-cygwin/lib/../lib/:/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/../../../../x86_64-pc-cygwin/lib/:/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/../../../:/lib/:/usr/lib/<br>    COLLECT_GCC_OPTIONS='-v' '-m64' '-o' 'a.exe' '-shared-libgcc' '-mtune=generic' '-march=x86-64'<br>     /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/collect2.exe -plugin /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/cyglto_plugin.dll -plugin-opt=/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/lto-wrapper.exe -plugin-opt=-fresolution=/tmp/ccM89KcB.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lcygwin -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --build-id -m i386pep --wrap _Znwm --wrap _Znam --wrap _ZdlPv --wrap _ZdaPv --wrap _ZnwmRKSt9nothrow_t --wrap _ZnamRKSt9nothrow_t --wrap _ZdlPvRKSt9nothrow_t --wrap _ZdaPvRKSt9nothrow_t -Bdynamic --dll-search-prefix=cyg --tsaware -o a.exe /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/../../../../lib/crt0.o /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/crtbegin.o -L/usr/lib/gcc/x86_64-pc-cygwin/7.4.0 -L/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/../../../../x86_64-pc-cygwin/lib/../lib -L/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/../../../../x86_64-pc-cygwin/lib -L/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/../../.. /tmp/proba-b6bf15.o -lstdc++ -lgcc_s -lgcc -lcygwin -ladvapi32 -lshell32 -luser32 -lkernel32 -lgcc_s -lgcc /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/../../../../lib/default-manifest.o /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/crtend.o<br>    COLLECT_GCC_OPTIONS='-v' '-m64' '-o' 'a.exe' '-shared-libgcc' '-mtune=generic' '-march=x86-64'<br><br>Compiling and executing the C equivalent of proba.cpp works fine with clang 9. I tried the tests suggested by the documentation (<a href="https://clang.llvm.org/get_started.html">https://clang.llvm.org/get_started.html</a>):<br><br>    clang --help<br>    clang file.c -fsyntax-only<br>    clang file.c -S -emit-llvm -o -<br>    clang file.c -S -emit-llvm -o - -O3<br>    clang file.c -S -O3 -o -<br><br>They seemed to work correctly to me.<br><br>I also tried the following without success<br><br>    clang++ -c proba.cpp -o proba.o<br>    ld.lld proba.o -o proba.exe<br>    ld.lld: error: proba.o: unknown file type<br><br>Does anybody have any idea what could go wrong with the C++ compilation using clang 9 on cygwin?<br><br>Did anybody manage to use lld linker along with clang under cygwin?<br><br>Any hint on how can clang + lld toolchain setup correctly under cygwin will be also appreciated. Thank you!<br><br></div><div>Note:<br></div><div>This issue is also reported on superuser:<br><a href="https://superuser.com/questions/1421240/clang-on-cygwin-fails-to-produce-executable-from-c-source">https://superuser.com/questions/1421240/clang-on-cygwin-fails-to-produce-executable-from-c-source</a><br></div><div dir="ltr"><br><br></div></div></div>