【问题标题】:clang 4.0 fails to build clang 3.42 on ubuntu 17.04clang 4.0 无法在 ubuntu 17.04 上构建 clang 3.42
【发布时间】:2018-01-10 13:43:27
【问题描述】:

我已经发布了我使用 gcc6.3 here 构建 llvm 3.42 的失败 和here。我单独发布clang 4.0的失败 从源代码构建 llvm 3.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.9 以来一直如此(请参阅releases.llvm.org/3.8.0/docs/BuildingLLVMWithAutotools.html)。我认为如果您使用 CMake 构建(我意识到那是您的起点),您将有更好的机会正确自定义/修复构建,并且也有更好的机会获得帮助。无论如何,autotools LLVM 构建是不可持续的,如果您选择(或宿主项目选择)在某个时候更新 LLVM 版本,则需要将构建迁移到 CMake。

标签: ubuntu linker clang llvm


【解决方案1】:

这似乎是 LLVM 3.4.2 源代码和内存清理程序标头的问题。

简而言之,您需要修补两个源文件,lib/Support/Allocator.cpplib/Target/X86/X86JITInfo.cpp,以删除函数__msan_allocated_memory__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 构建,否则不需要。

有了这个补丁,您应该能够使用 clang 4.0 构建 LLVM/clang 3.4.2 而不会出现其他问题。

发生这种情况的原因:

这些函数属于内存清理器,它们是从 LLVM 代码调用的,假设 LLVM 是使用内存清理器工具 (-fsanitize=memory) 构建的,否则它们会被禁用(ifdef'd out)。

相关标头代码在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

出于某种原因,选择了第一个 if 子句,而不是第二个,即使构建是在没有启用内存清理程序的情况下进行的(可能__has_feature(memory_sanitizer) 宏的切换被破坏了)。

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

编辑

为了解决以下由于malloc 重新声明而导致tsan 构建失败的问题,您可以考虑在LLVM 构建中省略tsan,如here 所述。

【讨论】:

  • 还有编译错误,关于 malloc、calloc、realloc 和 free ......还有其他想法吗?谢谢!
  • @OrenIshShalom 这可能是一个不同的问题,可能与 GCC 6.3 标头有关。我猜它和stackoverflow.com/questions/48146921/…一样?无论如何,我会尝试用我的本地设置重现它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多