Question

I have been able to build LLVM 2.6 (the llvm-2.6.tar.gz package) using MinGW GCC 3.4.5. I haven't tested properly, but it seems to work.

The trouble is, I have libraries of my own which don't build using GCC3, but which work fine in GCC4 (template issues). I believe the first official GCC4 version for MinGW is GCC 4.4.0.

EDIT

Decluttered - everything useful in the "tried this tried that" info is now in the answer.

EDIT

Most of this question/answer is redundant with LLVM 2.7 - the standard configure, make routine works fine in MinGW with no hacks or workarounds.

Was it helpful?

Solution

If at first you don't succeed...

I can now build LLVM 2.6 using MinGW GCC 4.4.0, and it isn't too hard once you know how. I still cannot run the DejaGNU tests, though at first sight that shouldn't be that hard - most likely I'll need the CygWin packages for dejagnu and expect. I also haven't built llvm-gcc yet.

Before the step-by-step, here are the three problems...


Problem 1...

Attempting to build llvm using the standard build instructions fails with the following compiler error in Signals.cpp (win32/Program.inc)

llvm[1]: Compiling Signals.cpp for Release build
In file included from Signals.cpp:33:
Win32/Signals.inc: In function 'LONG LLVMUnhandledExceptionFilter(_EXCEPTION_POINTERS*)':
Win32/Signals.inc:234: error: exception handling disabled, use -fexceptions to enable

The workaround is to use "make -k -fexceptions" - answer found in the pure language documentation.


Problem 2...

Even with the first workaround, the following compiler error occurs...

ExternalFunctions.cpp: In function 'bool ffiInvoke(void (*)(), llvm::Function*, const std::vector<llvm::GenericValue, std::allocator<llvm::GenericValue> >&, const llvm::TargetData*, llvm::GenericValue&)':
ExternalFunctions.cpp:207: error: 'alloca' was not declared in this scope

It seems that an option is being specified which disables the "alloca" built-in.

The workaround is to edit the problem file

C:\llvm-2.6\lib\ExecutionEngine\Interpreter\ExternalFunctions.cpp

Just after the "#include <string>" line, insert...

#define alloca __builtin_alloca


Problem 3...

Even with the compilation errors fixed, the example programs won't run. The run-time errors are...

Assertion failed: errorcode == 0, file RWMutex.cpp, line 87

This relates to the use of the pthreads library, in the following lines of RWMutex.cpp

86:   // Initialize the rwlock
87:   errorcode = pthread_rwlock_init(rwlock, &attr);
88:   assert(errorcode == 0);

The basic issue is that pthreads support is included in MinGW GCC, and included in the builds of AFAICT all the GCC4 variants - including the unofficial TDM builds, as well as including MinGW GCC 4.4.0. This was not included with MinGW GCC 3.4.5, which is why LLVM builds fine with default options on that compiler. Using 4.4.0, the LLVM configure script detects the pthreads support and uses it - but the pthreads-w32 library used seems not to be fully compatible.

One workaround is to delete the following files from mingw gcc 4.4.0 as suggested in http://markmail.org/message/d7zw2zjq7svevsci - yes, I know I previously said they weren't there, but I had my folder layout confused...

  • mingw32\include\pthread.h
  • mingw32\include\sched.h
  • mingw32\include\semaphore.h
  • mingw32\lib\libpthread.a

It is better, though, to simply tell the configure script to disable threads...

./configure --disable-threads


So, the steps are...

First, install the following MinGW and MSYS packages...

  • binutils-2.20-1-mingw32-bin.tar.gz
  • mingwrt-3.17-mingw32-dev.tar.gz
  • mingwrt-3.17-mingw32-dll.tar.gz
  • w32api-3.14-mingw32-dev.tar.gz
  • gcc-full-4.4.0-mingw32-bin-2.tar.lzma
  • make-3.81-20090914-mingw32-bin.tar.gz
  • tcltk-8.4.1-1.exe
  • MSYS-1.0.11.exe
  • msysDTK-1.0.1.exe
  • bash-3.1.17-2-msys-1.0.11-bin.tar.lzma
  • bison-2.4.1-1-msys-1.0.11-bin.tar.lzma
  • flex-2.5.35-1-msys-1.0.11-bin.tar.lzma
  • libregex-0.12-1-msys-1.0.11-dll-0.tar.lzma

This package list may be more than needed - in particular tcl tk is only needed for the DejaGNU tests, which I haven't got working yet.

Make sure that the \bin folder of your MinGW install is on the PATH (Control Panel, System, Advanced, Environment Variables).

Extract llvm-2.6.tar.gz

Edit the file C:\llvm-2.6\lib\ExecutionEngine\Interpreter\ExternalFunctions.cpp, and just after the line "#include <string>", add the line

#define alloca __builtin_alloca

Start an MSYS command prompt, and run...

cd /c/llvm-2.6
./configure --disable-threads
make -k CXXFLAGS=-fexceptions

I'm assuming you extracted llvm to c:\llvm-2.6

Handy hint - try "./configure --help"

Consider the --enable-targets=host-only and --enable-doxygen configure script options in particular.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top