且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Ubuntu 17.04上,从源代码生成llvm 3.42失败

更新时间:2023-11-10 18:06:34

这似乎是LLVM 3.4.2的一个问题 tsan (Thread Sanitizer)无法使用GCC 6.x构建,正如之前报道的那样: https://aur.archlinux.org/packages/clang34-analyzer-split



它似乎包含 stdlib.h malloc.h 是冲突的,因为都定义 malloc 和朋友。



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



如果您正在运行CMake版本这里),你可以通过评论 llvm / projects / compiler-rt / lib / CMakeLists.txt
$ b

  if(CMAKE_SYSTEM_NAME匹配LinuxAND NOTROID)
add_subdirectory(tsan)#注释掉这一行

如果你不得不坚持 configure build,我***的猜测是删除中的 tsan-x86_64 目标> llvm / projects / compiler -rt / make / clang_linux.mk ,第63行:

  Configs + = full-x86_64配置文件-x86_64 san-x86_64 asan-x86_64  - > tsan-x86_64   


I have a script that builds llvm/clang 3.42 from source (with configure+make). It runs smooth on ubuntu 14.04.5 LTS. When I upgraded to ubuntu 17.04, the build fails.

Here is the building script:

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`

Here are the errors I get (TLDR: problems with definitions of malloc, calloc, realloc and free)

/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

The default gcc version shipped with ubuntu 17.04 is 6.3. Maybe this is an issue of default C++ dialect used by gcc 6.3? Any help is very much appreciated, thanks!

That seems to be an issue with LLVM 3.4.2tsan (Thread Sanitizer) failing to build with GCC 6.x, as previously reported here:

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

It seems the inclusion of stdlib.h and malloc.h is conflicting, since both define malloc and friends.

It's possible that this issue only manifets in tsan, so if tsan is not instrumental to your LLVM build (which is very likely), and you wish to stick with the system gcc for building LLVM, you may consider disabling tsan completely.

If you're running a CMake build (as in here), you can do so by commenting line 29 of llvm/projects/compiler-rt/lib/CMakeLists.txt:

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

If you're forced to stick to the configure build, my best guess would be removing the tsan-x86_64 target in llvm/projects/compiler-rt/make/clang_linux.mk, line 63:

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