bloomberg / clangmetatool

A framework for reusing code in Clang tools
https://bloomberg.github.io/clangmetatool/
Apache License 2.0
119 stars 25 forks source link

skeleton fails to compile with clang ToT #36

Closed LegalizeAdulthood closed 5 years ago

LegalizeAdulthood commented 5 years ago

Describe the bug Attempting to build the skeleton results in a link error.

To Reproduce

  1. git clone https://github.com/llvm-mirror/llvm.git @ a10a70238ace1093cad3adeb94814b422bd1b5c1
  2. cd llvm/tools
  3. git clone https://github.com/llvm-mirror/clang.git @ 6ed0749151866894a67a3e7eefdc1f3a547daa0e
  4. cd clang/tools
  5. git clone https://github.com/llvm-mirror/clang-tools-extra.git @ d0fd727a5aa3776e4d49061de933772cf7d26c4c
  6. Build clang and install to local dir
  7. git clone https://github.com/bloomberg/clangmetatool.git @ 398a4788e8e6ede5fe1f6800310fe4510a46e7c0
  8. Build clangmetatool and install to local dir (same as clang)
  9. Copy skeleton to new git repository and change tool name in CMakeLists.txt
  10. Configure with CMake; no problems
  11. Build and get link error
$ make -j40
Scanning dependencies of target mock-api-tool
[ 50%] Building CXX object CMakeFiles/mock-api-tool.dir/src/main.cpp.o
[100%] Linking CXX executable mock-api-tool
CMakeFiles/mock-api-tool.dir/src/main.cpp.o:(.rodata._ZTIN13clangmetatool15MetaToolFactoryINS_8MetaToolI6MyToolEEEE[_ZTIN13clangmetatool15MetaToolFactoryINS_8MetaToolI6MyToolEEEE]+0x10): undefined reference to `typeinfo for clang::tooling::FrontendActionFactory'
CMakeFiles/mock-api-tool.dir/src/main.cpp.o:(.rodata._ZTIN13clangmetatool8MetaToolI6MyToolEE[_ZTIN13clangmetatool8MetaToolI6MyToolEE]+0x10): undefined reference to `typeinfo for clang::ASTFrontendAction'
collect2: error: ld returned 1 exit status
CMakeFiles/mock-api-tool.dir/build.make:122: recipe for target 'mock-api-tool' failed
make[2]: *** [mock-api-tool] Error 1
CMakeFiles/Makefile2:131: recipe for target 'CMakeFiles/mock-api-tool.dir/all' failed
make[1]: *** [CMakeFiles/mock-api-tool.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

Expected behavior Skeleton should compile and link without errors before any original modifications are made.

Environment (please complete the following information):

ruoso commented 5 years ago

It seems you're mixing rtti-enabled and rtti-disabled code. Can you take a look at the steps taken from the .travis.clang8.Dockerfile and see if it works for you?

LegalizeAdulthood commented 5 years ago

clang-7 and clang-8 packages aren't available for me through apt...

ruoso commented 5 years ago

The travis file is using from a prebuilt release out of the main repo...

LegalizeAdulthood commented 5 years ago

My build steps for the skeleton are the same as yours except my Clang_DIR and clangmetatool_DIR values are local directories not system directories.

LegalizeAdulthood commented 5 years ago

Unfortunately this is a shared machine, I can't just globally change the C++ compiler like that.

ruoso commented 5 years ago

Ok, I'll get someone to try and reproduce your problem on our end... I suspect there's something wrong going on in the llvm and clang configurations that is leaving you with an rtti-disabled build.

ruoso commented 5 years ago

Can you confirm the version of ubuntu that you're using? (you listed the kernel version and a package version, and it seems to be 16.04, but I just want to be sure).

LegalizeAdulthood commented 5 years ago
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.4 LTS
Release:        16.04
Codename:       xenial
LegalizeAdulthood commented 5 years ago

I looked through the imported target definitions created in the config files and while they define link dependencies and clangmetatool defines a target interface include directory setting, I'm not seeing any other properties being set, so if compilation switches need to be propagated from imported targets to clients, that's not happening.

envp commented 5 years ago

@LegalizeAdulthood I'm trying to reproduce this, what was the command line you used for building and configuring clang?

LegalizeAdulthood commented 5 years ago

Nothing custom, just cmake -G "Unix Makefiles" ../llvm where my directory structure looks like:

clang/llvm - source clang/build - build directory

dbeer1 commented 5 years ago

I think the issue is that you are not setting -DLLVM_ENABLE_RTTI=1 when running cmake. Most distros set this and I guess rtti is turned off explicitly by llvm/clang if not set.

Can you use cmake -DLLVM_ENABLE_RTTI=1 to configure llvm/clang?

dbeer1 commented 5 years ago

See for example the debian source package (which ubuntu's llvm package is based on too): https://salsa.debian.org/pkg-llvm-team/llvm-toolchain/blob/8/debian/rules#L395

dbeer1 commented 5 years ago

Sorry, edited above, the correct flag is -DLLVM_ENABLE_RTTI=1

dbeer1 commented 5 years ago

We could possibly support this either way by using the LLVM cmake modules: https://github.com/llvm-mirror/llvm/blob/release_80/cmake/modules/AddLLVM.cmake#L30

dbeer1 commented 5 years ago

I put in #39 which should handle this automatically, can you please try building using that branch @LegalizeAdulthood ?