Using non-system compiler to build llvm and llvm-gcc front end

I am attempting to install llvm on CentOS 5.3, which uses gcc-4.1.2 as its system compiler. Since this compiler has reported to behave poorly with llvm, I built gcc-4.2.4 in an insulated directory for use with my llvm installation.

However, I am not sure I am configuring properly. The gcc-4.2.4 installation is in /pkg/bin/gcc-4.2.4. Here is my config line:

…/llvm-2.5/configure --prefix=/pkg/bin/llvm/ CC=/pkg/bin/gcc-4.2.4/bin/gcc CXX=/pkg/bin/gcc-4.2.4/bin/g++ CXXCPP=/pkg/bin/gcc-4.2.4/bin/cpp LDFLAGS=-L /pkg/bin/gcc-4.2.4/lib64/ CXXFLAGS=-I/pkg/bin/gcc-4.2.4/include/c++/4.2.4/ CPPFLAGS=-I/pkg/bin/gcc-4.2.4/include/

I am trying to specify all the appropriate environment variables for using the non-default gcc. However, it is likely that I have made an error or are ommitting some important variable(s).

Then I do “gmake tools-only” (because I have yet to build the llvm-gcc front end). Here is the error:

gmake[1]: Entering directory /pkg/build/llvm/llvm-obj/lib/VMCore' llvm[1]: Building Intrinsics.gen.tmp from Intrinsics.td /pkg/build/llvm/llvm-obj/Release/bin/tblgen: /usr/lib64/libstdc++.so.6: version GLIBCXX_3.4.9’ not found (required by /pkg/build/llvm/llvm-obj/Release/bin/tblgen)
gmake[1]: *** [/pkg/build/llvm/llvm-obj/lib/VMCore/Release/Intrinsics.gen.tmp] Error 1
gmake[1]: Leaving directory `/pkg/build/llvm/llvm-obj/lib/VMCore’
gmake: *** [all] Error 1

So it is looking in /usr/lib64/ for libstdc++.so.6, when in fact I want it to look in /pkg//bin/gcc-4.2.4/lib64/ (which I thought I had specified with the configuration).

Any help would be appreciated.

Thanks,
Scott

Ah, nevermind… just needed to make clean to clear out some of the junk I compiled with gcc-4.1.2. The build completed without error.

I am still having problems getting everything installed. I realized that the successful build of llvm-2.5 had in fact been configured to use the system gcc (4.1.2). However, I was unable to sucessfully build llvm-gcc with gcc 4.1.2.

I went back and attempted to build llvm-2.5 with gcc-4.2.4 (installed in a separate directory from system gcc). However, I got the same build error as before.

Then I went back again to attempt to build llvm-2.5 with the system gcc, and was unable to reproduce a successful build. So something is wrong with my recollection of history.

I think I am just configuring incorrectly. I would like to use the installation of gcc-4.2.4, which is located in /pkg/bin/gcc-4.2.4. Perhaps someone has done something similar and can provide me a working example?

Details:

*** llvm-2.5 configured to use gcc-4.2.4:

$ …/llvm-2.5/configure --prefix=/pkg/bin/llvm/ CC=/pkg/bin/gcc-4.2.4/bin/gcc CXX=/pkg/bin/gcc-4.2.4/bin/g++ CXXCPP=/pkg/bin/gcc-4.2.4/bin/cpp LDFLAGS=-L/pkg/bin/gcc-4.2.4/lib64/ CXXFLAGS=-I/pkg/bin/gcc-4.2.4/include/c++/4.2.4/ CPPFLAGS=-I/pkg/bin/gcc-4.2.4/include/

llvm-2.5 build:

$ make tools-only

error:

make[1]: Entering directory /pkg/build/llvm/llvm-obj/lib/VMCore' llvm[1]: Building Intrinsics.gen.tmp from Intrinsics.td /pkg/build/llvm/llvm-obj/Release/bin/tblgen: /usr/lib64/libstdc++.so.6: version GLIBCXX_3.4.9’ not found (required by /pkg/build/llvm/llvm-obj/Release/bin/tblgen)
make[1]: *** [/pkg/build/llvm/llvm-obj/lib/VMCore/Release/Intrinsics.gen.tmp] Error 1
make[1]: Leaving directory `/pkg/build/llvm/llvm-obj/lib/VMCore’
make: *** [all] Error 1

*** llvm-2.5 configured to use default gcc (4.1.2):

$ …/llvm-2.5/configure --prefix=/pkg/bin/llvm/

llvm-2.5 build:

$ make tools-only

error (something like):

X86ISelDAGToDAG.cpp internal compiler error: Segmentation fault

Scott,
did you try a simple

$ …/llvm-2.5/configure --prefix=/pkg/bin/llvm/ CC=/pkg/bin/gcc-4.2.4/bin/gcc CXX=/pkg/bin/gcc-4.2.4/bin/g++

This is how I use to configure for non-system gcc 4.3.2 and it works well. The right headers are included automatically
from the correct directory, and besides that I think that none of the std libraries is linked statically I guess it would
pick the right ones as well. Just make sure to load the right shared libs on runtime.

Regards, Christian

Hi,

$ ../llvm-2.5/configure --prefix=/pkg/bin/llvm/
CC=/pkg/bin/gcc-4.2.4/bin/gcc CXX=/pkg/bin/gcc-4.2.4/bin/g++
CXXCPP=/pkg/bin/gcc-4.2.4/bin/cpp LDFLAGS=-L/pkg/bin/gcc-4.2.4/lib64/
CXXFLAGS=-I/pkg/bin/gcc-4.2.4/include/c++/4.2.4/
CPPFLAGS=-I/pkg/bin/gcc-4.2.4/include/

how about:

export PATH=/pkg/bin/:$PATH
../llvm-2.5/configure --prefix=/pkg/bin/llvm/

instead?

Ciao,

Duncan.

Thanks for the suggestions. It looks like Duncan's suggestion got me a
step closer, but I still can't build llvm-gcc...

did you try a simple

$ ../llvm-2.5/configure --prefix=/pkg/bin/llvm/
CC=/pkg/bin/gcc-4.2.4/bin/gcc CXX=/pkg/bin/gcc-4.2.4/bin/g++

Tried that, same error.

how about:

export PATH=/pkg/bin/:$PATH
../llvm-2.5/configure --prefix=/pkg/bin/llvm/

instead?

I did that, and then "make tools-only" -- which resulted in a
successful build of llvm-2.5. Then I went to build llvm-gcc:

../llvm-gcc4.2-2.5.source/configure
--prefix=/pkg/build/llvm/llvm-gcc/install --program-prefix=llvm-
--enable-llvm=/pkg/build/llvm/llvm-obj/ --enable-languages=c,c++

make LLVM_VERSION_INFO=2.5

and I get this error (which, according to
[LLVMbugs] [Bug 3710] llvm-gcc fails to build: Assertion `Cost == C && " Cost exceeds InlineCost precision"' failed might
mean I am using a bad version of gcc)...

/pkg/build/llvm/llvm-gcc/obj/./gcc/xgcc
-B/pkg/build/llvm/llvm-gcc/obj/./gcc/
-B/pkg/build/llvm/llvm-gcc/install/x86_64-unknown-linux-gnu/bin/
-B/pkg/build/llvm/llvm-gcc/install/x86_64-unknown-linux-gnu/lib/
-isystem /pkg/build/llvm/llvm-gcc/install/x86_64-unknown-linux-gnu/include
-isystem /pkg/build/llvm/llvm-gcc/install/x86_64-unknown-linux-gnu/sys-include
-O2 -O2 -g -O2 -DIN_GCC -W -Wall -Wwrite-strings
-Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition
-isystem ./include -fPIC -g -DHAVE_GTHR_DEFAULT -DIN_LIBGCC2
-D__GCC_FLOAT_NOT_NEEDED -I. -I. -I../../llvm-gcc4.2-2.5.source/gcc
-I../../llvm-gcc4.2-2.5.source/gcc/.
-I../../llvm-gcc4.2-2.5.source/gcc/../include
-I../../llvm-gcc4.2-2.5.source/gcc/../libcpp/include
-I../../llvm-gcc4.2-2.5.source/gcc/../libdecnumber -I../libdecnumber
-I/pkg/build/llvm/llvm-obj//include -I/pkg/build/llvm/llvm-2.5/include
-DL_gcov -c ../../llvm-gcc4.2-2.5.source/gcc/libgcov.c -o
libgcc/./_gcov.o
cc1: /pkg/build/llvm/llvm-2.5/include/llvm/Transforms/Utils/InlineCost.h:44:
llvm::InlineCost::InlineCost(int, int): Assertion `Cost == C && "Cost
exceeds InlineCost precision"' failed.
../../llvm-gcc4.2-2.5.source/gcc/libgcov.c:644: internal compiler error: Aborted

So I tried this config for llvm-gcc:

$ ../llvm-gcc4.2-2.5.source/configure
--prefix=/pkg/build/llvm/llvm-gcc/install --program-prefix=llvm-
--enable-llvm=/pkg/build/llvm/llvm-obj/ --enable-languages=c,c++
CC=/pkg/bin/gcc-4.2.4/bin/gcc CXX=/pkg/bin/gcc-4.2.4/bin/g++

but got:

configure: warning: CC=/pkg/bin/gcc-4.2.4/bin/gcc: invalid host type
configure: warning: CXX=/pkg/bin/gcc-4.2.4/bin/g++: invalid host type
configure: error: can only configure for one host and one target at a time

How do I tell llvm-gcc config to use the right version of gcc?
/pkg/bin/ is in my path thanks to the suggestion from Duncan.

$ echo $PATH
/pkg/bin/:/usr/lib64/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/user_homes/sricketts/bin

Hi,

cc1: /pkg/build/llvm/llvm-2.5/include/llvm/Transforms/Utils/InlineCost.h:44:
llvm::InlineCost::InlineCost(int, int): Assertion `Cost == C && "Cost
exceeds InlineCost precision"' failed.
../../llvm-gcc4.2-2.5.source/gcc/libgcov.c:644: internal compiler error: Aborted

this is indeed a miscompilation by your system compiler. However so many
compilers miscompiled this that a workaround was committed to svn. So you
may want to check out llvm and llvm-gcc from svn. Alternatively, maybe
the patch applies to llvm 2.5 too. I've attached it.

Ciao,

Duncan.

r69515.diff (2.62 KB)

I will try the latest from svn... but quick follow up question: If it
looks like a miscompilation by my system compiler (gcc 4.1.2), why
wasn't gcc-4.2.4 used? Did I make a mistake in configuration? Maybe I
am misunderstanding the build process.

Scott

Hi Scott,

r69597.diff (2.33 KB)

Thanks, I am making some progress. The latest from svn (for llvm and
llvm-gcc) built successfully. I built everything without adjusting the
PATH, so I guess I used gcc 4.1.2.

However, I then went back to attempt a build with ENABLE_OPTIMIZED=1
(this is just a test installation, once I get things working I will be
installing on another machine with the same OS). The optimized build
of llvm failed:

make[1]: Entering directory `/pkg/build/llvm-svn2/llvm-obj/lib/VMCore'
llvm[1]: Building Intrinsics.gen.tmp from Intrinsics.td
llvm[1]: Compiling AsmWriter.cpp for Release build
llvm[1]: Compiling Attributes.cpp for Release build
llvm[1]: Compiling AutoUpgrade.cpp for Release build
llvm[1]: Compiling BasicBlock.cpp for Release build
llvm[1]: Compiling ConstantFold.cpp for Release build
llvm[1]: Compiling Constants.cpp for Release build
llvm[1]: Compiling Core.cpp for Release build
llvm[1]: Compiling Dominators.cpp for Release build
llvm[1]: Compiling Function.cpp for Release build
g++: Internal error: Segmentation fault (program cc1plus)

So then I did make clean. No big deal, I can live without the
optimized build. But originally I just built with "make tools-only"
because I had not yet built llvm-gcc. But now I have a built version
of llvm-gcc, so I re-configured with:

../llvm/configure --prefix=/pkg/bin/llvm
--with-llvmgccdir=/pkg/build/llvm-svn2/install/

and then did "make" in the llvm-obj directory. But this build failed:

make[2]: Entering directory `/pkg/build/llvm-svn2/llvm-obj/tools/bugpoint'
llvm[2]: Compiling BugDriver.cpp for Debug build
llvm[2]: Compiling CrashDebugger.cpp for Debug build
llvm[2]: Compiling ExecutionDriver.cpp for Debug build
llvm[2]: Compiling ExtractFunction.cpp for Debug build
llvm[2]: Compiling FindBugs.cpp for Debug build
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:
In member function ‘std::basic_ostream<_CharT, _Traits>&
std::basic_ostream<_CharT, _Traits>::operator<<(double)’:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:374:
internal compiler error: Segmentation fault

Now I am thoroughly confused. Can someone check my installation
process? Here is what I think I am supposed to do:

1) configure llvm without pointing to llvm-gcc, "make tools-only"
2) configure llvm-gcc pointing to the llvm build from step (1)
3) re-configure llvm to point to llvm-gcc from step (2), "make"

FYI, I tried the first patch Duncan sent (applied to llvm-2.5), which
did not fix the problem. I have not yet tried the second patch. I am
assuming that checking out the latest from svn is at least as good?

Scott

Hello, Scott

Thanks, I am making some progress. The latest from svn (for llvm and
llvm-gcc) built successfully. I built everything without adjusting the
PATH, so I guess I used gcc 4.1.2.

Even if you'll succeed, most probably LLVM will be miscompiled. gcc
4.1.2 is known buggy: http://llvm.org/docs/GettingStarted.html#brokengcc

Yes, so I have read -- which is why I initially installed gcc-4.2.4.
My original post was looking for help on how to use gcc-4.2.4. Some
suggestions were made, but I was not able to get everything built. It
seems that despite attempting to configure with everything pointing to
gcc-4.2.4 (and not the system gcc 4.1.2), at some point in the build,
something would look for a file or use a file from the system gcc
4.1.2.

I would love to get this built using gcc-4.2.4, but I think I could
use some help. If someone could point me to the relevant config
variables, I might be able to debug this.

Hello, Scott

Yes, so I have read -- which is why I initially installed gcc-4.2.4.
My original post was looking for help on how to use gcc-4.2.4. Some
suggestions were made, but I was not able to get everything built. It
seems that despite attempting to configure with everything pointing to
gcc-4.2.4 (and not the system gcc 4.1.2), at some point in the build,
something would look for a file or use a file from the system gcc
4.1.2.

That's correct. Since you have everything linked as shared libraries
system dynamic linker will pick the shared library installed in the
default library location. Most probably you will need to edit
/etc/ld.so.conf and put the gcc 4.2.4 library path there *before*
system compiler one and rerun "ldconfig" (from root)....

Unfortunately I still have yet to successfully install llvm.

That's correct. Since you have everything linked as shared libraries
system dynamic linker will pick the shared library installed in the
default library location. Most probably you will need to edit
/etc/ld.so.conf and put the gcc 4.2.4 library path there *before*
system compiler one and rerun "ldconfig" (from root)....

I added the gcc 4.2.4 library paths to /etc/ld.so.conf, then ran
ldconfig. Then I:

configured llvm:

$ ../llvm/configure --prefix=/pkg/bin/llvm

built llvm:

$ make -j15

configured llvm-gcc:

$ ../llvm-gcc/configure --prefix=/pkg/build/llvm/install
--program-prefix=llvm- --enable-llvm=/pkg/build/llvm/llvm-obj
--enable-languages=c,c++

attempted to build llvm-gcc:

$ make -j15
...
cc1: /pkg/build/llvm/llvm/lib/Analysis/ScalarEvolution.cpp:511:
bool<unnamed>::SCEVComplexityCompare::operator()(const llvm::SCEV*,
const llvm::SCEV*) const: Assertion `0 && "Unknown SCEV kind!"'
failed.
../../llvm-gcc/libdecnumber/decNumber.c:5591: internal compiler error: Aborted

This is all with llvm and llvm-gcc source from svn. I have tried
gcc-4.2.4 and gcc-4.3.2. ENABLE_OPTIMIZED=1 only seems to work with
gcc-4.3.2.

Here is the error when I try to build llvm with gcc-4.2.4 with
ENABLE_OPTIMIZED=1:

`.gnu.linkonce.t._ZNK4llvm16DAGTypeLegalizer13getTypeActionENS_3MVTE'
referenced in section
`.gnu.linkonce.r._ZNK4llvm16DAGTypeLegalizer13getTypeActionENS_3MVTE'
of /pkg/build/llvm/llvm-obj/Release/lib/libLLVMSelectionDAG.a(LegalizeVectorTypes.o):
defined in discarded section
`.gnu.linkonce.t._ZNK4llvm16DAGTypeLegalizer13getTypeActionENS_3MVTE'
of /pkg/build/llvm/llvm-obj/Release/lib/libLLVMSelectionDAG.a(LegalizeVectorTypes.o)
collect2: ld returned 1 exit status
make[2]: *** [/pkg/build/llvm/llvm-obj/Release/lib/libLTO.so] Error 1
make[2]: Leaving directory `/pkg/build/llvm/llvm-obj/tools/lto'

I have also tried installing with the llvm-gcc binary for RHEL4 (even
though I am running Centos 5). However, "make check" returned a bunch
of unexpected failures.

Any suggestions?

Thanks,
Scott

Hi,

$ make -j15

do you really have 15 CPUs? If not, this will most
likely just slow things down.

cc1: /pkg/build/llvm/llvm/lib/Analysis/ScalarEvolution.cpp:511:
bool<unnamed>::SCEVComplexityCompare::operator()(const llvm::SCEV*,
const llvm::SCEV*) const: Assertion `0 && "Unknown SCEV kind!"'
failed.
../../llvm-gcc/libdecnumber/decNumber.c:5591: internal compiler error: Aborted

This is all with llvm and llvm-gcc source from svn.

Since the SCEV code is changing rapidly at the moment, it may be that you
had the bad luck to update to a broken revision.

Here is the error when I try to build llvm with gcc-4.2.4 with
ENABLE_OPTIMIZED=1:

`.gnu.linkonce.t._ZNK4llvm16DAGTypeLegalizer13getTypeActionENS_3MVTE'
referenced in section
`.gnu.linkonce.r._ZNK4llvm16DAGTypeLegalizer13getTypeActionENS_3MVTE'
of /pkg/build/llvm/llvm-obj/Release/lib/libLLVMSelectionDAG.a(LegalizeVectorTypes.o):
defined in discarded section
`.gnu.linkonce.t._ZNK4llvm16DAGTypeLegalizer13getTypeActionENS_3MVTE'
of /pkg/build/llvm/llvm-obj/Release/lib/libLLVMSelectionDAG.a(LegalizeVectorTypes.o)
collect2: ld returned 1 exit status
make[2]: *** [/pkg/build/llvm/llvm-obj/Release/lib/libLTO.so] Error 1
make[2]: Leaving directory `/pkg/build/llvm/llvm-obj/tools/lto'

This looks like a clear bug in your system tools: note how it complains
that a certain section is referenced by itself, and that this is a problem
because it is being discarded, d'oh! There's not much we can do about this
kind of thing.

I have also tried installing with the llvm-gcc binary for RHEL4 (even
though I am running Centos 5). However, "make check" returned a bunch
of unexpected failures.

If you want llvm from svn, then you should use llvm-gcc from svn too.

Ciao,

Duncan.

$ make -j15

do you really have 15 CPUs? If not, this will most
likely just slow things down.

I have 8 CPUs. I started with -j8 and turned the knob up a bit. It
seemed to run faster, so I stuck with j15. I guess there might be some
context switching when threads are blocking on memory or IO. I could
be imagining the speedups though because of some sort of placebo
effect.

cc1: /pkg/build/llvm/llvm/lib/Analysis/ScalarEvolution.cpp:511:
bool<unnamed>::SCEVComplexityCompare::operator()(const llvm::SCEV*,
const llvm::SCEV*) const: Assertion `0 && "Unknown SCEV kind!"'
failed.
../../llvm-gcc/libdecnumber/decNumber.c:5591: internal compiler error: Aborted

This is all with llvm and llvm-gcc source from svn.

Since the SCEV code is changing rapidly at the moment, it may be that you
had the bad luck to update to a broken revision.

Release 2.5 was giving me problems (see older posts on this thread). I
will see if updating my current revision helps.

This looks like a clear bug in your system tools: note how it complains
that a certain section is referenced by itself, and that this is a problem
because it is being discarded, d'oh! There's not much we can do about this
kind of thing.

OK, not quite sure what this means about my system tools. Is there
something I should be concerned about?

I have also tried installing with the llvm-gcc binary for RHEL4 (even
though I am running Centos 5). However, "make check" returned a bunch
of unexpected failures.

If you want llvm from svn, then you should use llvm-gcc from svn too.

Yes, I assumed so. I was just getting frustrated with not being able
to build the svn llvm-gcc, so I tried the binary.

Ciao,

Duncan.

Thanks for your help.

Hi,

OK, not quite sure what this means about my system tools. Is there
something I should be concerned about?

it seems that a bug in your system tools happens to be tickled by
LLVM. We can't do much about the fact that your system doesn't
work properly, though if enough people see a problem we do sometimes
try to tweak LLVM so it avoids triggering the bug. If you don't
have problems when building other programs then I guess there isn't
much to be concerned about!

Ciao,

Duncan.

OK, updated from svn (revision 71457) and got a successful
installation. For the record:

1) Installed gcc 4.3.2 in /pkg/bin/gcc-4.3.2 (to insulate it from the
system compiler)
2) Added /pkg/bin/gcc-4.3.2/bin to my PATH
3) Added /pkg/bin/gcc-4.3.2/lib and /pkg/bin/gcc-4.3.2/lib64 to
/etc/ld.so.conf and ran ldconfig
4) More or less followed README.LLVM:

Configure llvm:
$ ../configure --prefix=/pkg/bin/llvm

Build llvm:
$ make -j10

Configure llvm-gcc:
$ ../llvm-gcc/configure --prefix=/pkg/build/llvm-svn-updated/install
--program-prefix=llvm-
--enable-llvm=/pkg/build/llvm-svn-updated/llvm-obj
--enable-languages=c,c++

Build llvm-gcc:
$ make -j10

Install (run make install in object directories for both llvm and llvm-gcc)

"make check" in llvm-obj fails one of the tests unexpectedly if I
build with ENABLE_OPTIMIZED=1. It looks for some file in Debug and
doesn't find it (LLVMHello.so).

Thanks to Duncan, Anton, and Christian for helping me through this.

Scott