clang 4.0无法在Ubuntu 17.04上构建clang 3.42 [英] clang 4.0 fails to build clang 3.42 on ubuntu 17.04

查看:132
本文介绍了clang 4.0无法在Ubuntu 17.04上构建clang 3.42的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经发布了使用gcc6.3构建llvm 3.42的失败此处.我分别发布clang 4.0的失败 从源代码构建llvm 3.42,因为它们是一些不同的开发人员社区.这是我使用的脚本:

I have posted my failures of building llvm 3.42 with gcc6.3 here and here. I am posting separately the failure of clang 4.0 to build llvm 3.42 from source as these are somewhat different developers communities. Here is the script I've used:

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

CC=clang CXX=clang++ ./configure \
--enable-optimized \
--disable-assertions \
--enable-targets=host \
--with-python="/usr/bin/python2"

make -j `nproc`

这是我得到的错误:

[ 17%] Linking CXX executable ../../bin/yaml-bench
../../lib/libLLVMSupport.a(Allocator.cpp.o): In function `llvm::BumpPtrAllocator::Allocate(unsigned long, unsigned long)':
/home/oren/GIT/myLLVMpass/llvm-3.4.2/llvm/lib/Support/Allocator.cpp:(.text+0x377): undefined reference to `__msan_allocated_memory'
/home/oren/GIT/myLLVMpass/llvm-3.4.2/llvm/lib/Support/Allocator.cpp:(.text+0x40b): undefined reference to `__msan_allocated_memory'
/home/oren/GIT/myLLVMpass/llvm-3.4.2/llvm/lib/Support/Allocator.cpp:(.text+0x453): undefined reference to `__msan_allocated_memory'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
utils/not/CMakeFiles/not.dir/build.make:95: recipe for target 'bin/not' failed

(添加@valiano的建议后) 仍然有错误,这是终端输出:

(after adding @valiano's suggestion) There are still errors, here is the terminal output:

In file included from /home/oren/GIT/LatestKlee/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc:47:
/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.0/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
   ASSEMBLE:  clang_linux/tsan-x86_64/x86_64: /home/oren/GIT/LatestKlee/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_rtl_amd64.S
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;
           ^
4 errors generated.

有什么办法吗?预先感谢!

Is there any way out of this? thanks in advance!

推荐答案

这似乎与LLVM 3.4.2源代码和内存清理程序标头有关.

That seems to be an issue with LLVM 3.4.2 source code and memory sanitizer headers.

简而言之,您需要修补两个源文件lib/Support/Allocator.cpplib/Target/X86/X86JITInfo.cpp,以删除功能__msan_allocated_memory__msan_unpoison的用法:

In short, you'll need to patch two source files, lib/Support/Allocator.cpp and lib/Target/X86/X86JITInfo.cpp, for removing usages of the functions__msan_allocated_memory and __msan_unpoison:

sed -i 's/__msan_unpoison/\/\/__msan_unpoison/' ./llvm/lib/Target/X86/X86JITInfo.cpp
sed -i 's/__msan_allocated_memory/\/\/__msan_allocated_memory/' llvm/lib/Support/Allocator.cpp

这些函数调用仅适用于带有内存清理工具的LLVM构建,否则不需要.

These function calls are only there for LLVM builds with memory sanitizer instrumentation, and otherwise not needed.

有了此修补程序,您应该能够使用clang 4.0构建LLVM/clang 3.4.2,而不会出现更多问题.

With this patch, you should be able to build LLVM/clang 3.4.2 with clang 4.0 with no further issues.

发生这种情况的原因:

这些功能属于内存清理程序,它们是从LLVM代码中调用的,假设LLVM是使用内存清理程序工具(-fsanitize=memory)构建的,否则,它们将被禁用(如果未定义).

These functions are of the memory sanitizer and they're called from LLVM code assuming that LLVM is built with memory sanitizer instrumentation (-fsanitize=memory), and otherwise, they are disabled (ifdef'd out).

相关标头代码位于 include/llvm/Support/Compiler.h :

The relevant header code is in include/llvm/Support/Compiler.h:

/// \macro LLVM_MEMORY_SANITIZER_BUILD
/// \brief Whether LLVM itself is built with MemorySanitizer instrumentation.
#if __has_feature(memory_sanitizer)
# define LLVM_MEMORY_SANITIZER_BUILD 1
# include <sanitizer/msan_interface.h>
#else
# define LLVM_MEMORY_SANITIZER_BUILD 0
# define __msan_allocated_memory(p, size)
# define __msan_unpoison(p, size)
#endif

由于某种原因,即使在构建时未启用内存清理程序(也许__has_feature(memory_sanitizer)宏的切换被破坏),也选择了第一个if子句,而不是第二个if子句.

From some reason, the first if clause is chosen, instead of the second one, even though the build is made without memory sanitizer enabled (perhaps the toggling of __has_feature(memory_sanitizer) macro is broken).

请参见此处有关此问题的其他报告.

See here additional reports regarding this issue.

修改:

要解决以下由于malloc重新声明而导致无法构建tsan的问题,您可以考虑从LLVM构建中省略tsan,如

For solving the following issue of tsan failing to build due to malloc redeclarations, you may consider omitting tsan from your LLVM build, as described here.

这篇关于clang 4.0无法在Ubuntu 17.04上构建clang 3.42的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆