[LLVMdev] llvm-gcc4 & mingw32

Henrik Bach henrik_bach_llvm at hotmail.com
Wed May 10 18:13:06 PDT 2006

Thanks Anton. Nice Job.


>From: Anton Korobeynikov Date: Thu, 11 May 2006 01:17:24 +0400
>Hello, Everyone.
>This is just brief description on building llvm-gcc4 with mingw32.
>It's definitely non error-free and contains many "hacks", which should
>be eliminated in the future.
>1. Prerequisites
>We're building in the folowing configuration:
>1.1 GCC 3.4.5:
>gcc -v
>Reading specs from f:/research/mingw/bin/../lib/gcc/mingw32/3.4.5/specs
>Configured with: ../gcc-3.4.5/configure --with-gcc --with-gnu-ld 
>--with-gnu-as -
>-host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads 
>--disable-nls --
>enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry 
>ed --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x 
>ble-java-gc=boehm --disable-libgcj-debug --enable-interpreter 
>hronization --enable-libstdcxx-debug
>Thread model: win32
>gcc version 3.4.5 (mingw special)
>1.2 binutils 2.16.91 (20060119):
>ld --version
>GNU ld version 2.16.91 20060119
>Copyright 2005 Free Software Foundation, Inc.
>This program is free software; you may redistribute it under the terms of
>the GNU General Public License.  This program has absolutely no warranty.
>(both taken from mingw32 site)
>1.3 Flex & bison taken from gnuwin32 site:
>flex --version
>flex.EXE version 2.5.4
>bison --version
>bison (GNU Bison) 2.1
>Written by Robert Corbett and Richard Stallman.
>Copyright (C) 2005 Free Software Foundation, Inc.
>This is free software; see the source for copying conditions.  There is NO
>1.4 llvm-gcc4 snapshot named 2006-05-08-llvm-gcc-4.tar.gz
>1.5 Patches to LLVM source code and GCC source code (attached).
>2. LLVM itself
>We're using MSYS shell for main compilation. Also, we're using
>objdir!=srcdir directory structure (the root is actually f:/tmp/llvm):
>            /gccbuild
>            /gccsrc
>            /install
>            /src
>LLVM sources goes to src, GCC sources goes to gccsrc. We're using
>build dir to build LLVM and gccbuild dir to build GCC.
>2.1 Switch do /build directory and configure LLVM:
>   $ ../src/configure --enable-jit --enable-optimized 
>2.2. Than make it:
>   $ make tools-only LIBS="-lpsapi -limagehlp"
>   I had 1 ICE while compiling 
>   Everything was fixed, when I lowered optimization switch to -O2 and
>   rebuild that file by hand.
>3. GCC
>We're using cygwin shell, as msys isn't able to handle GCC's auto*
>machinery well. We're needing just folowing packages installed:
>alternatives ash base-files base-passwd bash bzip2 clear coreutils
>crypt cygutils cygwin cygwin-doc diffutils editrights expat findutils
>gawk gdbm grep groff gzip less libbz2_1 libcharset1 libdb4.2 libdb4.3
>libgdbm libgdbm-devel libgdbm3 libgdbm4 libiconv libiconv2 libintl libintl1
>libintl2 libintl3 libncurses5 libncurses6 libncurses7 libncurses8 libpcre0
>libpopt0 libreadline4 libreadline5 libreadline6 login m4 make man mktemp
>ncurses openssl openssl097 perl python run sed tar tcltk termcap terminfo
>texinfo unzip which zip zlib
>(much of them, except make & perl are installed by default)
>3.1 Black magic starts here....
>Mount your drive to cygwin. So, inside shell my disk f: is looking
>like directory /f
>Much of autotools is using pwd command to extract current path.
>Unfortunately, it's in form: /drive/path, but we wants it to be:
>drive:/path. In order to do that, rename cygwin's pwd.exe located in
>the /bin directory into pwd_real.exe and create file named "pwd" with
>the folowing content (place it also in the /bin directory):
>cygpath -m `pwd_real`
>Copy that file into "my_pwd"
>Start cygwin. Be sure, that no msys tools (sh.exe, make.exe, etc) is
>staying in your path.
>export PWDCMD
>3.2 Go to gccbuild directory and configure gcc:
>$ ../gccsrc/configure --host=mingw32                  \
>                       --target=mingw32                \
>                       --prefix=f:/tmp/llvm/install    \
>                       --enable-threads --disable-nls  \
>                       --enable-languages=c,c++        \
>                       --disable-win32-registry        \
>                       --disable-shared                \
>                       --enable-sjlj-exceptions        \
>                       --enable-llvm=f:/tmp/llvm/build \
>                       --program-prefix=llvm-
>3.3 Make it!
>$ make CFLAGS="-O2 -fomit-frame-pointer" CXXFLAGS="-mthreads 
>-fno-omit-frame-pointer -O2"
>3.4 Take a cup of coffee....
>3.5 libstdc++ black magic
>After some time you'll see error message from ar.exe complaining, that
>It cannot create libstdc++.a file due to invalid path of form
>/drive/path. Goto to gccbuild/mingw32libstdc++-v3 directory. Open file
>libtool and replace all "`pwd" to "`my_pwd" and rerun make (you might
>also do that just monitoring libtool creation and do this hack on-fly,
>while libstdc++ is configuring).
>You'll have error message about inline assembler in the atomicity.cc
>(located in the gccbuild/mingw32/libstdc++-v3/src), feel free to comment
>the entire loop there, since current version of llvm-gcc4 doesn't
>support any exceptions yet. This should be definitely fixed in the
>future. BTW, another patch (to gthr-win32.c) was supplied also to
>overcome inline assembler handling bugs (both containing "lock xchg"
>3.6 libiberty issues
>You might also find, that cc1 crashed compiling md5.c from libiberty.
>This is due to some weird bug in Select_add routine from
>X86GenDAGISel.inc. I don't know the reason, seems to be some stack
>overflow or something like this. I'm investigating this problem.
>Funny, that some other file with SHA implementation also causes such
>crash ;) Maybe this is due to be amount of ariphmetical operations
>3.7 You've done it!
>$ make install
>4. LLVM: rebuilding
>Configure LLVM again (inside msys!) with
>$ ../src/configure --enable-jit --enable-optimized 
>--prefix=f:/tmp/llvm/build --with-llvmgccdir=f:/tmp/llvm/install
>and make it as usual...
>5. Congratulations: you've done it!
>With best regards,
>  Anton                          mailto:asl at math.spbu.ru
>Thursday, May 11, 2006 12:37:17 AM
>Faculty of Mathematics & Mechanics, Saint-Petersburg State University

><< llvm.diff >>

><< gcc.diff >>

>LLVM Developers mailing list
>LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu

Ta' på udsalg året rundt på MSN Shopping:  http://shopping.msn.dk  - her 
finder du altid de bedste priser

More information about the llvm-dev mailing list