从源代码构建的 llvm 3.42 在 Ubuntu 17.04 上失败



我有一个从源代码构建llvm/clang 3.42的脚本(使用配置+制作(。它在 ubuntu 14.04.5 LTS 上运行流畅。当我升级到 ubuntu 17.04 时,构建失败。

下面是构建脚本:

svn co https://llvm.org/svn/llvm-project/llvm/tags/RELEASE_342/final llvm
svn co https://llvm.org/svn/llvm-project/cfe/tags/RELEASE_342/final llvm/tools/clang
svn co https://llvm.org/svn/llvm-project/compiler-rt/tags/RELEASE_342/final llvm/projects/compiler-rt
svn co https://llvm.org/svn/llvm-project/libcxx/tags/RELEASE_342/final llvm/projects/libcxx
rm -rf llvm/.svn
rm -rf llvm/tools/clang/.svn
rm -rf llvm/projects/compiler-rt/.svn
rm -rf llvm/projects/libcxx/.svn
cd llvm
./configure 
--enable-optimized 
--disable-assertions 
--enable-targets=host 
--with-python="/usr/bin/python2"
make -j `nproc`

以下是我得到的错误(TLDR:malloc,calloc,reallocfree的定义问题(

/usr/include/malloc.h:38:14: error: declaration conflicts with target of using declaration already in scope
extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
             ^
/usr/include/stdlib.h:427:14: note: target of using declaration
extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
             ^
/usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3./stdlib.h:65:12: note: using declaration
using std::malloc;
           ^
In file included from /home/oren/GIT/LatestKlee/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc:47:
/usr/include/malloc.h:41:14: error: declaration conflicts with target of using declaration already in
  scope
extern void *calloc (size_t __nmemb, size_t __size)
             ^
/usr/include/stdlib.h:429:14: note: target of using declaration
extern void *calloc (size_t __nmemb, size_t __size)
             ^
/usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/stdlib.h:59:12: note: using declaration
using std::calloc;
           ^
In file included from /home/oren/GIT/LatestKlee/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc:47:
/usr/include/malloc.h:49:14: error: declaration conflicts with target of using declaration already in
  scope
extern void *realloc (void *__ptr, size_t __size)
             ^
/usr/include/stdlib.h:441:14: note: target of using declaration
extern void *realloc (void *__ptr, size_t __size)
             ^
/usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/stdlib.h:73:12: note: using declaration
using std::realloc;
           ^
In file included from /home/oren/GIT/LatestKlee/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc:47:
/usr/include/malloc.h:53:13: error: declaration conflicts with target of using declaration already in
  scope
extern void free (void *__ptr) __THROW;
            ^
/usr/include/stdlib.h:444:13: note: target of using declaration
extern void free (void *__ptr) __THROW;
            ^
/usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/stdlib.h:61:12: note: using declaration
using std::free;
           ^
COMPILE:   clang_linux/tsan-x86_64/x86_64: /home/oren/GIT/LatestKlee/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cc
4 errors generated.
Makefile:267: recipe for target '/home/oren/GIT/LatestKlee/llvm/tools/clang/runtime/compiler-rt/clang_linux/tsan-x86_64/x86_64/SubDir.lib__tsan__rtl/tsan_platform_linux.o' failed
make[5]: *** [/home/oren/GIT/LatestKlee/llvm/tools/clang/runtime/compiler-rt/clang_linux/tsan-x86_64/x86_64/SubDir.lib__tsan__rtl/tsan_platform_linux.o] Error 1

ubuntu 17.04 附带的默认 gcc 版本是 6.3。也许这是 gcc 6.3 使用的默认C++方言的问题?非常感谢任何帮助,谢谢!

这似乎是LLVM 3.4.2 tsan(线程清理器(无法使用GCC 6.x构建的问题,如前所述:

https://aur.archlinux.org/packages/clang34-analyzer-split

似乎包含stdlib.hmalloc.h是相互矛盾的,因为两者都定义了malloc和朋友。

这个问题可能只在tsan中操纵,所以如果tsan对你的LLVM构建没有帮助(这很有可能(,并且您希望坚持使用系统gcc来构建LLVM,你可以考虑完全禁用tsan

如果您正在运行 CMake 构建(如此处所示(,您可以通过注释第 29 行(llvm/projects/compiler-rt/lib/CMakeLists.txt

(:
if (CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT ANDROID)  
  add_subdirectory(tsan) # comment out this line

如果您被迫坚持使用configure版本,我最好的猜测是删除 llvm/projects/compiler-rt/make/clang_linux.mktsan-x86_64 目标,第 63 行:

Configs += full-x86_64 profile-x86_64 san-x86_64 asan-x86_64 --> tsan-x86_64 <-- 

我在 Ubuntu 16.10 上遇到了同样的问题。它具有默认的 gcc 6.2。你需要指示LLVM构建系统使用gcc 4.9。另外,我建议您完全删除GCC6。

$ sudo apt-get remove g++-6 gcc-6 cpp
$ sudo apt-get install gcc-4.9 g++4.9
$ export CC=/usr/bin/gcc-4.9
$ export CXX=/usr/bin/g++-4.9
$ export CPP=/usr/bin/cpp-4.9
$ ./configure
$ make

也许您将需要:

$ sudo ln -s /usr/bin/cpp-4.9 /usr/bin/cpp

最新更新