Hello LLVM-DEV!
Recently I think I found a bug in llvm’s CMakeLists.(I use llvm 3.1svn and Clang 3.1) I follow the normal way to try to compile an application that utilize both clang and llvm: I ./autogen.sh it, ./configure it and make it. But the make fails. At last I found out the failure is because that the Makefile’s CXXFLAGS does not contain -fno-rtti option which is needed by the compilation.
The “configure” file of the application use llvm-config --cxxflags to assign to the CXXFLAGS. But Although I see that, under my platform, almost all the the files inside LLVM and Clang are compiled with -fno-rtti, the llvm-config --cxxflags does not give the correct flags that those files are compiled. The following are something I thought is valuable to mention here:
As I probe the CMAKE_CXX_FLAGS of some of the CMakeLists.txt, I found there is a “baseline” of this variable, mine is “-fPIC -fvisibility-inlines-hidden”. It means, no matter how a single CMakeLists.txt changes CMAKE_CXX_FLAGS, it will remain the same when it goes into another CMakeLists.txt.
Inside the llvm-config’s source folder, the CMakeLists.txt shows how its --cxxflags is set:
set(CXX_FLGS “${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${uppercase_
CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}”)
…
COMMAND echo s!@LLVM_CXXFLAGS@!${CXX_FLGS}! >> ${SEDSCRIPT_OBJPATH}
and my LLVM_DEFINITIONS is:
-D_GNU_SOURCE -Wall -W -Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
I also use “make VERBOSE=1” to check how llvm and clang is compiled. I see clearly that they are both compiled with -fno-rtti.
So, at least under my system, when using cmake to configure the project, no matter how the files are compiled, llvm-config --cxxflags will be the same. It is: -fPIC -fvisibility-inlines-hidden -D_GNU_SOURCE -Wall -W -Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS. It is determined by the “baseline” of CMAKE_CXX_FLAGS and LLVM_DEFINITIONS.
Is this probably a problem?
Jun-qi Deng <dengjunqi06323011@gmail.com> writes:
Recently I think I found a bug in llvm's CMakeLists.(I use llvm 3.1svn and
Clang 3.1) I follow the normal way to try to compile an application that
utilize both clang and llvm: I ./autogen.sh it, ./configure it and make it.
But the make fails. At last I found out the failure is because that the
Makefile's CXXFLAGS does not contain -fno-rtti option which is needed by
the compilation.
Is it? In my experience, it isn't. Please show the relevant command
generated by your makefile and the associated error message(s).
RTTI is an on/off option that changes per LLVM library, so setting
-fno-rtti for using LLVM makes no sense. VMCore and Support have -frtti
while most of the rest have -fno-rtti. The switch is decided on
cmake/modules/LLVMProcessSources.cmake depending on the value of
LLVM_REQUIRES_RTTI.
[snip]
Recently I think I found a bug in llvm’s CMakeLists.(I use llvm 3.1svn and
Clang 3.1) I follow the normal way to try to compile an application that
utilize both clang and llvm: I ./autogen.sh it, ./configure it and make it.
But the make fails. At last I found out the failure is because that the
Makefile’s CXXFLAGS does not contain -fno-rtti option which is needed by
the compilation.
Is it? In my experience, it isn’t. Please show the relevant command
generated by your makefile and the associated error message(s).
RTTI is an on/off option that changes per LLVM library, so setting
-fno-rtti for using LLVM makes no sense. VMCore and Support have -frtti
while most of the rest have -fno-rtti. The switch is decided on
cmake/modules/LLVMProcessSources.cmake depending on the value of
LLVM_REQUIRES_RTTI.
Hello! I’m sorry, because I’ve already solved the build problem with the mentioned app manually, now it’s not very convenient for me to reproduce the error for the moment. I agree that “RTTI is an on/off option”. But I think the point of the problem I mentioned here is: some applications that depend on llvm and clang use llvm-config to configure their Makefile, while the llvm-config cannot provide the correct information they need. And this is what actually happened under my platform.
Regards,
TangKK
Jun-qi Deng <dengjunqi06323011@gmail.com> writes:
Is it? In my experience, it isn't. Please show the relevant command
generated by your makefile and the associated error message(s).
RTTI is an on/off option that changes per LLVM library, so setting
-fno-rtti for using LLVM makes no sense. VMCore and Support have -frtti
while most of the rest have -fno-rtti. The switch is decided on
cmake/modules/LLVMProcessSources.cmake depending on the value of
LLVM_REQUIRES_RTTI.
Hello! I'm sorry, because I've already solved the build problem with the
mentioned app manually, now it's not very convenient for me to reproduce
the error for the moment. I agree that "RTTI is an on/off option". But I
think the point of the problem I mentioned here is: some applications that
depend on llvm and clang use llvm-config to configure their Makefile, while
the llvm-config cannot provide the correct information they need. And this
is what actually happened under my platform.
If you read again my post, you'll see that I doubt that the absence of
-fno-rtti on the output of llvm-config is the problem. Using -fno-rtti
is an internal decision taken while building LLVM and it makes no sense
to impose it on third party code. In short: LLVM does not require
-fno-rtti from the projects that link to it.
Most likely, you were experiencing link problems on *your* code that
were resolved by using -fno-rtti. But as you are not interested on
investigating the issue, we'll never know for sure.
I got your point. Thank you, and I’d like to provide the relative message now. But firstly, what do you mean by the “relevant command generated by your makefile”? What I can tell you now is:
The Error Message:
make[3]: Entering directory /home/tang.kk/ppcg/ppcg/isl/interface' CXXLD extract_interface extract_interface.o:(.data.rel.ro._ZTI13MyASTConsumer[typeinfo for MyASTConsumer]+0x10): undefined reference to
typeinfo for clang::ASTConsumer’
collect2: ld returned 1 exit status
make[3]: *** [extract_interface] Error 1
make[3]: Leaving directory /home/tang.kk/ppcg/ppcg/isl/interface' make[2]: *** [all-recursive] Error 1 make[2]: Leaving directory
/home/tang.kk/ppcg/ppcg/isl’
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/tang.kk/ppcg/ppcg/isl’
make: *** [all-recursive] Error 1
The “make V=1” is:
tang.kk@linux-eda-0:~/ppcg/ppcg> make V=1
Making all in isl
make[1]: Entering directory /home/tang.kk/ppcg/ppcg/isl' make all-recursive make[2]: Entering directory
/home/tang.kk/ppcg/ppcg/isl’
Making all in .
make[3]: Entering directory /home/tang.kk/ppcg/ppcg/isl' make[3]: Leaving directory
/home/tang.kk/ppcg/ppcg/isl’
Making all in interface
make[3]: Entering directory `/home/tang.kk/ppcg/ppcg/isl/interface’
/bin/sh …/libtool --tag=CXX --mode=link g++ -I/home/tang.kk/work/llvm-install/include -fPIC -fvisibility-inlines-hidden -D_GNU_SOURCE -Wall -W -Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -g -O2 -save-temps -L/home/tang.kk/work/llvm-install/lib -ldl -lpthread -o extract_interface python.o extract_interface.o -lclangFrontend -lclangSerialization -lclangParse -lclangSema -lclangAnalysis -lclangAST -lclangLex -lclangBasic -lclangDriver -lLLVMAnalysis -lLLVMTarget -lLLVMMC -lLLVMObject -lLLVMCore -lLLVMSupport -L/home/tang.kk/work/llvm-install/lib -ldl -lpthread
libtool: link: g++ -I/home/tang.kk/work/llvm-install/include -fPIC -fvisibility-inlines-hidden -D_GNU_SOURCE -Wall -W -Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -g -O2 -save-temps -o extract_interface python.o extract_interface.o -L/home/tang.kk/work/llvm-install/lib -lclangFrontend -lclangSerialization -lclangParse -lclangSema -lclangAnalysis -lclangAST -lclangLex -lclangBasic -lclangDriver -lLLVMAnalysis -lLLVMTarget -lLLVMMC -lLLVMObject -lLLVMCore -lLLVMSupport -ldl -lpthread
extract_interface.o:(.data.rel.ro._ZTI13MyASTConsumer[typeinfo for MyASTConsumer]+0x10): undefined reference to `typeinfo for clang::ASTConsumer’
collect2: ld returned 1 exit status
make[3]: *** [extract_interface] Error 1
make[3]: Leaving directory `/home/tang.kk/ppcg/ppcg/isl/interface’
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/home/tang.kk/ppcg/ppcg/isl’
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/tang.kk/ppcg/ppcg/isl’
make: *** [all-recursive] Error 1
And my llvm-config --cxxflags is:
-fPIC -fvisibility-inlines-hidden -D_GNU_SOURCE -Wall -W -Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
Best Regards,
TangKK
Jun-qi Deng <dengjunqi06323011@gmail.com> writes:
I got your point. Thank you, and I'd like to provide the relative message
now. But firstly, what do you mean by the "relevant command generated by
your makefile"? What I can tell you now is:
The Error Message:
make[3]: Entering directory `/home/tang.kk/ppcg/ppcg/isl/interface'
CXXLD extract_interface
extract_interface.o:(.data.rel.ro._ZTI13MyASTConsumer[typeinfo for
MyASTConsumer]+0x10): undefined reference to `typeinfo for
clang::ASTConsumer'
collect2: ld returned 1 exit status
[snip]
So you define a class MyAstConsumer that derives from clang::ASTConsumer
and then the link fails because the typinfo for MyAstConsumer can not
reference the typeinfo of clang::ASTConsumer, because the latter is
undefined as a consecuence of building Clang with -fno-rtti.
In this case the right thing is to apply -fno-rtti to the specific
source file that defines MyAstConsumer.
Please note that deriving from a Clang/LLVM class is not something that
all projects do. The typical compiler that uses LLVM as a backend does
not need to derive from LLVM classes at all. Imposing -fno-rtti on those
projects most likely would cause breakage on user's code.
2012/3/14 =?utf-8?Q?=C3=93scar_Fuentes?= <ofv@wanadoo.es>
Jun-qi Deng <dengjunqi06323011@gmail.com> writes:
I got your point. Thank you, and I’d like to provide the relative message
now. But firstly, what do you mean by the “relevant command generated by
your makefile”? What I can tell you now is:
The Error Message:
make[3]: Entering directory /home/tang.kk/ppcg/ppcg/isl/interface' CXXLD extract_interface extract_interface.o:(.data.rel.ro._ZTI13MyASTConsumer[typeinfo for MyASTConsumer]+0x10): undefined reference to
typeinfo for
clang::ASTConsumer’
collect2: ld returned 1 exit status
[snip]
So you define a class MyAstConsumer that derives from clang::ASTConsumer
and then the link fails because the typinfo for MyAstConsumer can not
reference the typeinfo of clang::ASTConsumer, because the latter is
undefined as a consecuence of building Clang with -fno-rtti.
Oh, I got it! Thank you very much! It helps me a lot.
In this case the right thing is to apply -fno-rtti to the specific
source file that defines MyAstConsumer.
Please note that deriving from a Clang/LLVM class is not something that
all projects do. The typical compiler that uses LLVM as a backend does
not need to derive from LLVM classes at all. Imposing -fno-rtti on those
projects most likely would cause breakage on user’s code.
Best Regards!
TangKK