mingw-w64 support

Hi,

I am interested in helping Clang work with/on/for the mingw-w64 runtime. I understand LLVM/Clang works on i686-pc-mingw32, but there probably needs to be some/“a lot” of work done for mingw-w64.

Where should I start (other than cmake && make and see where I get)?

Thanks,

Ruben

2010/10/10 Ruben Van Boxem <vanboxem.ruben@gmail.com>

Hi,

I am interested in helping Clang work with/on/for the mingw-w64 runtime. I understand LLVM/Clang works on i686-pc-mingw32, but there probably needs to be some/“a lot” of work done for mingw-w64.

Where should I start (other than cmake && make and see where I get)?

Thanks,

Ruben

After applying attached patches, I proceeded to build with mingw-w64 GCC 4.5.
Three problems up to now:

  1. CMake detects platform as i686-pc-mingw32, while my compiler is very clearly x86_64-w64-mingw32.
  2. Build at 55%, tblgen.exe crashes. The build then freezes (kill and restart, it skips and fails at the error below)
  3. At 56%, build fails at an undeclared symbol: “SelectCode”. This is probably due to number 2

I have no idea what tblgen.exe is supposed to do or why it crashes. How should I proceed?

Thanks!

Ruben

DynamicLibrary.inc.diff (1.11 KB)

Win32.h.diff (445 Bytes)

Hello Ruben,

I am interested in helping Clang work with/on/for the mingw-w64 runtime. I
understand LLVM/Clang works on i686-pc-mingw32, but there probably needs to
be some/"a lot" of work done for mingw-w64.
Where should I start (other than cmake && make and see where I get)?

It really depends on which part you'll want to work - "with" or "on".
The latter should more or less work, at least almost all win64 ABI was
already implemented.
As for "with" - this means that you'll need to (probably) dig & fix
miscompilations / bugs introduced by your gcc.

1. CMake detects platform as i686-pc-mingw32, while my compiler is very
clearly x86_64-w64-mingw32.

Ok, sounds like cmake bug.

2. Build at 55%, tblgen.exe crashes. The build then freezes (kill and
restart, it skips and fails at the error below)
3. At 56%, build fails at an undeclared symbol: "SelectCode". This is
probably due to number 2
I have no idea what tblgen.exe is supposed to do or why it crashes. How
should I proceed?

Sounds like a gcc bug. The ideal solution will be for you to find
what's causing such problem and file a PR in gcc's bugzilla.

Ruben Van Boxem <vanboxem.ruben@gmail.com>
writes:

[snip]

Three problems up to now:
1. CMake detects platform as i686-pc-mingw32, while my compiler is very
clearly x86_64-w64-mingw32.

I committed a tentative fix for this.

[snip]

2010/10/13 Anton Korobeynikov <anton@korobeynikov.info>

  1. CMake detects platform as i686-pc-mingw32, while my compiler is very
    clearly x86_64-w64-mingw32.

Ok, sounds like cmake bug.

  1. Build at 55%, tblgen.exe crashes. The build then freezes (kill and
    restart, it skips and fails at the error below)
  2. At 56%, build fails at an undeclared symbol: “SelectCode”. This is
    probably due to number 2
    I have no idea what tblgen.exe is supposed to do or why it crashes. How
    should I proceed?

Sounds like a gcc bug. The ideal solution will be for you to find
what’s causing such problem and file a PR in gcc’s bugzilla.


With best regards, Anton Korobeynikov
Faculty of Mathematics and Mechanics, Saint Petersburg State University

The gdb stacktrace on the tblgen command that crashes is below:

#0 0x000000000048eb84 in FactorNodes(llvm::OwningPtrllvm::Matcher&) ()

… (998 times the same!)

#997 0x000000000048ec1a in FactorNodes(llvm::OwningPtrllvm::Matcher&) ()

#998 0x0000000000490283 in llvm::OptimizeMatcher(llvm::Matcher*, llvm::CodeGenDAGPatterns const&) ()

#999 0x0000000000480f48 in llvm::DAGISelEmitter::run(llvm::raw_ostream&) ()

#1000 0x0000000000523928 in main ()

Should I enable debug info (how?) or is this as complete as it gets?

My plan is to be able to replace GCC completely by Clang. So I need:

  1. to compile Clang
  2. show it how to use the mingw-w64 runtime (and compile this runtime with clang)
  3. test the bejeezus out of it :slight_smile:

1 is a work in progress, I’m trying a GCC 4.4 build now, it wouldn’t surprise me that 4.5 is the cause of this crash. Once I have a working Clang for Win64 this will be a non-issue of course (I would use clang to build clang).
I have absolutely no idea how to set up 2 and 3. Any help/guidance is much appreciated. With GCC, it’s pretty much:

  • build deps (gmp, mpc, mpfr)
  • build gcc c compiler
  • use new compiler to build mingw-w64 runtime
  • use new mingw-w64 runtime to build full GCC (C++, etc)

How would this go with Clang?

Thanks for helping me help you help me help mingw-w64!

Ruben

PS: thank you for the CMake patch. It works (as far as I can tell) Does it do anything except change the printed triplet? (like ABI choosing, defines…)

2010/10/14 Ruben Van Boxem <vanboxem.ruben@gmail.com>

2010/10/13 Anton Korobeynikov <anton@korobeynikov.info>

  1. CMake detects platform as i686-pc-mingw32, while my compiler is very
    clearly x86_64-w64-mingw32.

Ok, sounds like cmake bug.

  1. Build at 55%, tblgen.exe crashes. The build then freezes (kill and
    restart, it skips and fails at the error below)
  2. At 56%, build fails at an undeclared symbol: “SelectCode”. This is
    probably due to number 2
    I have no idea what tblgen.exe is supposed to do or why it crashes. How
    should I proceed?

Sounds like a gcc bug. The ideal solution will be for you to find
what’s causing such problem and file a PR in gcc’s bugzilla.


With best regards, Anton Korobeynikov
Faculty of Mathematics and Mechanics, Saint Petersburg State University

The gdb stacktrace on the tblgen command that crashes is below:

#0 0x000000000048eb84 in FactorNodes(llvm::OwningPtrllvm::Matcher&) ()

… (998 times the same!)

#997 0x000000000048ec1a in FactorNodes(llvm::OwningPtrllvm::Matcher&) ()

#998 0x0000000000490283 in llvm::OptimizeMatcher(llvm::Matcher*, llvm::CodeGenDAGPatterns const&) ()

#999 0x0000000000480f48 in llvm::DAGISelEmitter::run(llvm::raw_ostream&) ()

#1000 0x0000000000523928 in main ()

Should I enable debug info (how?) or is this as complete as it gets?

My plan is to be able to replace GCC completely by Clang. So I need:

  1. to compile Clang
  2. show it how to use the mingw-w64 runtime (and compile this runtime with clang)
  3. test the bejeezus out of it :slight_smile:

1 is a work in progress, I’m trying a GCC 4.4 build now, it wouldn’t surprise me that 4.5 is the cause of this crash. Once I have a working Clang for Win64 this will be a non-issue of course (I would use clang to build clang).
I have absolutely no idea how to set up 2 and 3. Any help/guidance is much appreciated. With GCC, it’s pretty much:

  • build deps (gmp, mpc, mpfr)
  • build gcc c compiler
  • use new compiler to build mingw-w64 runtime
  • use new mingw-w64 runtime to build full GCC (C++, etc)

How would this go with Clang?

Thanks for helping me help you help me help mingw-w64!

Ruben

PS: thank you for the CMake patch. It works (as far as I can tell) Does it do anything except change the printed triplet? (like ABI choosing, defines…)

An idea just popped into my mind: why not use MSVC to compile Clang, and compile the mingw-w64 runtime with that Clang compiler, and recompile clang with clang? This would require me to have some details on steps 2 and 3 from above though.

Ruben

PS: so this is what I mean:

  1. build MSVC Clang x64 running on MS runtime
  2. build mingw-w64 runtime with Clang x64
  3. build Clang x64 based on mingw-w64 runtime from 2 (how do I do this??)

[snip]

PS: thank you for the CMake patch. It works (as far as I can tell) Does it
do anything except change the printed triplet? (like ABI choosing,
defines...)

AFAIK the triplet determines the ABI (at least the data layout is chosen
depending on it.) Anton knows more than me about this topic.