tpoechtrager / wclang

Cross compile source code easily for Windows with clang on Linux/Unix

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

C++ ABI

Ericson2314 opened this issue · comments

I don't think this enables Clang's recent windows ABI compatibility work, since I still see gcc-style name mangling looking at the outputted file.

If this stems from a different between the mingw and win32 targets, how feasible would it be to make this tool also support using MSVC++ headers / libs?

Well, this tool is meant to be binary compatible with MinGW therefore it uses the GCC C++ abi.

I have experimented a bit with clang and the MSVC++ abi (about 3-4 months ago, used an up-to-date svn version),

but there are/were a few problems:

  • Getting the MSVC libs and headers is an annoying task
  • Microsoft doesn't use the exact file names of headers in their #include's, so lots of includes do not work on case sensitive file systems (which causes a lot of troubles, e.g. you must rename/symlink tons of files)
  • There is no linker available to link MSVC++ abi object files on linux, but there is one in the works: https://github.com/llvm-mirror/lld (didn't link lots of stuff when I tried it the last time with the MSVC++ abi, nevertheless, I think they are making a good progress)
  • Some (C++) code didn't compile (maybe it's fixed/implemented now, don't know)

So I would say it's too early...

If you are still willing in giving it a try, this is the approximate command I used (obviously not fine-tuned):

 clang++ -target i686-pc-win32 -isystem /home/thomas/VC/Include \
  -Wl,/LIBPATH:"/home/thomas/VC/lib" ${1+"$@"} \
  -Wno-deprecated-declarations -Wno-unknown-pragmas -Qunused-arguments`

You may also need to pass -fmsc-version=XXX depending on the MSVC version you want to target,
clang++ -cc1 --help|grep Microsoft may also be some help.

Closing this since it's not really a goal of wclang, but feel free to ask any further questions.

Thanks for the feedback. For some reason, when i invoked clang (installed via windows installer) in MSYS 2 (successor to original msys made a bit in conjunction with mingw-w64), it seemed to use the mingw-w64 header with --target i686-pc-win32 without complaint. This is very weird, as it wouldn't use mingw-w64 stuff on Linux.

GNU ld should work with pe-coff win32 object files, with the exception that it doesn't like the combined .bss and .data sections (ie it doesn't understand sections with RawSize != 0 && VirtualSize > RawSize. I may try to get that fixed upstream if you are interested. Perhaps their are some intricacies with dynamic linking + DLL thought, but it was my understanding that linking was agnostic to C++ concerns.

Thanks for the tip on -fmsc-version=XX. My specific use-case is patching a 10+ year old binaries, so old ABI compatibility will be indispensable.

Are you sure it is using the MinGW headers?

I don't think it would even parse the MinGW headers with the MSVC target. You can check this with -v during compilation.

And yes, the GNU linker may link C object files from MSVC, but I don't think it would accept C++ mangled object files from MSVC or with the MSVC target.

Getting things fixed upstream is always good!