• Forum
  • Lounge
  • Does anyone know the magic incantation t

 
Does anyone know the magic incantation to compile LLVM 32-bit?

Pages: 12
I'm tired of playing internet jungle.

I can't get cmake to make me makefiles that make a 32-bit LLVM on my 64-bit OS.

Windows 7
CMake 3.3.0-rc4
TDM GCC w64 5.1.0
Python 2.7.10

I'm about to write thunk exes just to get the "-m32" flag to pass to all the GCC processes.
Or just temporarily alias g++.
Tried that. The configure script goes out of its way to verify the gcc/g++ commands are, in fact, executable files located on disk somewhere.
Yes oh yes oh yes!

With cmake-gui add the following STRING values:

    CMAKE_C_FLAGS                -m32
    CMAKE_CXX_FLAGS              -m32
    CMAKE_EXE_LINKER_FLAGS       -m32
    CMAKE_STATIC_LINKER_FLAGS    -m32

and if you are making shared libraries,

    CMAKE_SHARED_LINKER_FLAGS    -m32

(If you are using cmake from the command-line, you'll have to use -DCMAKE_C_FLAGS=-m32 method.)

Then you get purty 32-bit stuff on yer 64-bit OS. Yay!

[edit] See below for more information. [/edit]
Last edited on
Last time I tried compiling LLVM/clang on Windows it was a nightmare. The binaries I got after weeks of research kinda worked, but only kinda. Has it gotten better?
Not really.

The compilation process works as I list it above, but I can't figure out how to make it work for "Release" build.

So... I have to go in and manually strip debug information from the resulting executables and library.a files -- which isn't too hard, actually:

C:\Users\Michael\Programming\LLVM\llvm-build32\bin> for %F in (*.exe) do strip %F

C:\Users\Michael\Programming\LLVM\llvm-build32\bin> strip LTO.dll

C:\Users\Michael\Programming\LLVM\llvm-build32\lib> for %F in (*.a) do strip --strip-debug %F

After that it's just a matter of manual install.

And I still have to get the test suite to work. Fun.
Crap. llvm-config builds with hard-coded directories. LLVM doesn't compile in-source, so I've got to have two directories in their final, live-forever positions just to use it?

That's more than a brain fart to go that horribly wrong.
The debug binaries are super slow, I don't think stripping debug info changes debug code flow. You should really try to build release if you can - it's worth it to not wait several minutes for a hello world to compile.

By the way, I think I was never able to get LLVM to build, but a mailing list side comment told me that if you just put clang where it should be in the LLVM structure, you can start the build from the clang folder and build clang without building LLVM and it will work.
Last edited on
The only problem is I don't care about Clang. I want LLVM. LOL.

And until I figure out how to build the Release builds, I'm pretty much stuck...
I just realized LLVM 3.6.2 is available for Windows on the LLVM downloads page, is that not what you need?
Built with MSVC. Will that work with TDM-GCC-w64? (I don't want any magic surprises!)
Well, I thought I had stumbled upon the correct solution. Since the static libraries are assembled by ar(1), the -m32 flag is incorrect. The CMAKE_STATIC_LINKER_FLAGS and CMAKE_SHARED_LINKER_FLAGS should have a string value of "--target=pe-i386".

It was working swimmingly until it tried to link opt.exe, and stopped with:
C:\TDM-GCC-64\bin\g++.exe  -m32 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=gnu++11 -O2 -DNDEBUG -m32  -m32 -m32 -Wl,--whole-archive CMakeFiles\opt.dir/objects.a -Wl,--no-whole-archive  -o ..\..\bin\opt.exe  -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles\opt.dir\linklibs.rsp
../../lib/libLLVMSupport.a(DynamicLibrary.cpp.obj):DynamicLibrary.cpp:(.text+0xaea): undefined reference to `__alloca'
../../lib/libLLVMSupport.a(DynamicLibrary.cpp.obj):DynamicLibrary.cpp:(.text+0xb0a): undefined reference to `___chkstk'
../../lib/libLLVMSupport.a(DynamicLibrary.cpp.obj):DynamicLibrary.cpp:(.text+0xb2e): undefined reference to `___chkstk_ms'
collect2.exe: error: ld returned 1 exit status

Foo.


I can't fix that one.
Just be glad you're not running into out of memory problems. I could never build LLVM because one of the things it had to link exhausted all my RAM every time.
You could build in an x86 VM. Bit of overkill, but if nothing else will do...
Last edited on
Heh, yeah, I've been considering installing my old XP into my VirtualBox as a 32-bit OS... but LLVM is supposed to have some issues on XP, so...
There's also the Windows 10 preview ISO, though I don't know how much more RAM you'll have left for the actual compilation.
The chkstk and alloca problems seem to be a known bug in TDM GCC, supposedly fixed sometime before the current release.

I'm currently pruning my system of old tools and updating to the most recent versions.
At which point I'll recompile ICU and Boost, and then try again for LLVM.
ALRIGHT, so...

I've taken this opportunity to clean up my system somewhat. I've upgraded (deleted and installed the latest version of):

- TDM-GCC-w64 (5.1.0-2)
- CMake (3.3.0)
- ICU (55.1)
- Boost (1.58.0)

(I swear I'm going to write a series of articles about how to do all this...)

and I am right now ATM compiling LLVM. So far, so good (I'm at 10%)...

The magic trick is that the libraries are created using ar(3), so "-m32" is an inappropriate tag to pass to it. You need to provide an appropriate "--target", which in this case is "pe-i386".

To set it up, you need to follow several important setup steps.
First, I have downloaded LLVM's source and put it in a convenient directory.

Next, you need the following in your path:
- CMake
- Python27 (not 3.x)
- TDM-GCC-w64
C:\Users\Michael\Programming\LLVM> path C:\PROGRA~2\CMake\bin;C:\Python27;C:\TCM-GCC-64\bin;%PATH%
(Note that PROGRA~2 is the "Program Files (x86)" folder.)

Then you need to extract LLVM's source and configure.
C:\Users\Michael\Programming\LLVM> 7z x llvm-3.6.2.src.tar.xz
C:\Users\Michael\Programming\LLVM> 7z x llvm-3.6.2.src.tar
C:\Users\Michael\Programming\LLVM> md llvm-build32
C:\Users\Michael\Programming\LLVM> cd llvm-build32
C:\Users\Michael\Programming\LLVM\llvm-build32> cmake-gui ..\llvm-3.6.2.src

Once you have CMake's GUI up, press the "Configure" button and select the second option down to choose "gcc" and "g++" as your compilers. Once that's done, wait for the first configure pass to finish.

Click the "Advanced" checkbox.

Modify the following, case-sensitive:
1
2
3
4
5
6
7
8
9
CMAKE_BUILD_TYPE
CMAKE_CXX_FLAGS
CMAKE_C_FLAGS
CMAKE_EXE_LINKER_FLAGS
CMAKE_EXE_LINKER_FLAGS_RELEASE
CMAKE_SHARED_LINKER_FLAGS
CMAKE_SHARED_LINKER_FLAGS_RELEASE
CMAKE_STATIC_LINKER_FLAGS
CMAKE_STATIC_LINKER_FLAGS_RELEASE
Release
-m32
-m32
--target=pe-i386
--target=pe-i386
--target=pe-i386
--target=pe-i386
--target=pe-i386
--target=pe-i386

I've also enabled the following boolean values by putting a little check mark in the box:
1
2
LLVM_ENABLE_EH
LLVM_ENABLE_RTTI

A couple of other things you may wish to have checked:
1
2
LLVM_ENABLE_THREADS
LLVM_ENABLE_ZLIB

Click the "Configure" button again and wait for it to finish.
Then click the "Generate" button.

After that, close CMake-GUI and at the command line (which you should still have open!) type everyone's favorite invocation:

C:\Users\Michael\Programming\LLVM\llvm-build32> mingw32-make


Then sit back and cross your fingers. I'm at 32% now... I'll post back on the success (or failure) of the current build.


[update]
[ 89%] Linking CXX executable ..\..\bin\opt.exe
../../lib/libLLVMSupport.a(DynamicLibrary.cpp.obj):DynamicLibrary.cpp:(.text+0xb40): undefined reference to `__alloca'
../../lib/libLLVMSupport.a(DynamicLibrary.cpp.obj):DynamicLibrary.cpp:(.text+0xb60): undefined reference to `___chkstk'
../../lib/libLLVMSupport.a(DynamicLibrary.cpp.obj):DynamicLibrary.cpp:(.text+0xb84): undefined reference to `___chkstk_ms'

Fooey.
Last edited on
Have you tried compiling LLVM using Visual Studio? I think that's how they're making the Windows releases.
Yeah, but then all I would need is to download the binary release.
Pages: 12