Clang4.0无法在ubuntu 17.04上构建Clang3.42

Clang4.0无法在ubuntu 17.04上构建Clang3.42,ubuntu,linker,clang,llvm,Ubuntu,Linker,Clang,Llvm,我已经发布了用gcc6.3构建llvm 3.42的失败 和。我单独发布了Clang4.0的失败 从源代码构建LLVM3.42,因为它们是一些不同的开发人员社区。以下是我使用的脚本: 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

我已经发布了用gcc6.3构建llvm 3.42的失败 和。我单独发布了Clang4.0的失败 从源代码构建LLVM3.42,因为它们是一些不同的开发人员社区。以下是我使用的脚本:

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的建议后) 仍然存在错误,以下是终端输出:

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.

有办法解决这个问题吗?提前谢谢

这似乎是LLVM 3.4.2源代码和内存消毒器头的问题

简而言之,您需要修补两个源文件,
lib/Support/Allocator.cpp
lib/Target/X86/X86JITInfo.cpp
,以删除函数
\u msan\u allocated\u memory
的用法:

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构建,否则不需要

使用此修补程序,您应该能够使用Clang4.0构建LLVM/Clang3.4.2,而不会出现其他问题

发生这种情况的原因:

这些函数是内存消毒器的函数,它们是从LLVM代码调用的,假设LLVM是使用内存消毒器工具构建的(
-fsanize=memory
),否则,它们将被禁用(ifdef'd out)

相关标题代码位于:

//\macro LLVM\u内存\u消毒液\u构建
///\简述LLVM本身是否使用MemorySinitizer工具构建。
#如果\uuu具有\u功能(内存\u消毒剂)
#定义LLVM\u内存\u消毒器\u构建1
#包括
#否则
#定义LLVM\u内存\u消毒器\u生成0
#定义分配的内存(p,大小)
#定义(p,大小)
#恩迪夫
出于某种原因,选择了第一个if子句,而不是第二个if子句,即使生成时未启用内存清理器(可能是
\u的切换有\u功能(内存清理器)
宏被破坏)

请参阅有关此问题的其他报告

编辑


<>为了解决下面的问题:<代码> TSAN <代码>由于<代码> MALLC/<代码>重新声明而无法建立,您可以考虑从LLVM构建中省略<代码> TSAN <代码>。不过,我有一个建议。LLVM autotools构建长期以来一直被弃用,自3.9版以来一直如此(请参阅)。我认为,如果您使用CMake构建,您有更好的机会正确定制/修复构建,也有更好的机会获得帮助(我知道这就是您的起点)。autotools LLVM构建无论如何都是不可持续的,如果您选择(或宿主项目选择)在某个时间点更新LLVM版本,则需要将构建迁移到CMake。关于malloc、calloc、realloc和free,仍然存在编译错误。。。还有其他想法吗?谢谢@这可能是另一个问题,可能与GCC 6.3标题有关。我想和你一样吧?无论如何,我会尝试用我的本地设置复制它。
/// \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