gcc从源代码构建llvm 3.42时崩溃(使用cmake) [英] gcc crashes while building llvm 3.42 from source (with cmake)

查看:376
本文介绍了gcc从源代码构建llvm 3.42时崩溃(使用cmake)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当试图在ubuntu 17.04上构建llvm / clang 3.42时,
我用configre + make失败,如前所述在这个SO帖子中
我给了cmake这个非常类似的脚本:

 #!/ bin / bash 
# ##############
#DEFINITIONS#
###############
LLVM_SVN = https:// llvm.org/svn/llvm-project
TAG = tags / RELEASE_342 / final

###############
#DIRECTORIES#
###############
BASEDIR = / home / oren / GIT / myLLVMpass

######### ######
#DIRECTORIES#
###############
LLVM_DIR = $ {BASEDIR} /llvm-3.4.2
LLVM_BUILD_DIR = $ {LLVM_DIR} / build
LLVM_SRC_DIR = $ {LLVM_DIR} / llvm
CLANG_SRC_DIR = $ {LLVM_SRC_DIR} / tools / clang
COMPILER_RT_SRC_DIR = $ {LLVM_SRC_DIR} / projects / compiler -rt
LIBCXX_SRC_DIR = $ {LLVM_SRC_DIR} / projects / libcxx

########################## ###############################
#准备llvm,llvm / src和llvm / build目录... #
############################################# ############
mkdir $ {LLVM_DIR}
mkdir $ {LLVM_SRC_DIR}
mkdir $ {LLVM_BUILD_DIR}

### ###############
#获取llvm 3.4.2#
##################
svn co $ {LLVM_SVN} / llvm / $ {TAG} $ {LLVM_SRC_DIR}
svn co $ {LLVM_SVN} / cfe / $ {TAG} $ {CLANG_SRC_DIR}
svn co $ {LLVM_SVN} / compiler-rt / $ {TAG} $ {COMPILER_RT_SRC_DIR}
svn co $ { LLVM_SVN} / libcxx / $ {TAG} $ {LIBCXX_SRC_DIR}

############################# ####
#无需更改...#
############################ #####
rm -rf $ {LLVM_DIR} /。svn
rm -rf $ {CLANG_DIR} /。svn
rm -rf $ {COMPILER_RT_DIR} /。svn
rm -rf $ {LIBCXX_DIR} /。svn

############################### ######################
#进入llvm / build目录和cmake ...#
###### ###############################################
cd $ {LLVM_BUILD_DIR}&& cmake $ {LLVM_SRC_DIR}

###############
#make it !!! #
###############
make -j

我从configure + make试用版中得到了完全不同的错误

  [78%]构建CXX对象lib / Target / ARM / CMakeFiles / LLVMARMCodeGen.dir / Thumb1FrameLowering.cpp.o 
[78%]构建CXX对象lib / Target / ARM / CMakeFiles / LLVMARMCodeGen.dir / ARMTargetObjectFile.cpp .o
[78%]构建CXX对象lib / Target / ARM / CMakeFiles / LLVMARMCodeGen.dir / MLxExpansionPass.cpp.o
[78%]构建CXX对象lib / Target / ARM / CMakeFiles / LLVMARMCodeGen .dir / Thumb2InstrInfo.cpp.o
c ++:内部编译器错误:杀死(程序cc1plus)
请提交一份完整的错误报告,如果适用,请提供预处理源。
请参阅< file:///usr/share/doc/gcc-6/README.Bugs>为说明。
tools / clang / lib / ASTMatchers / Dynamic / CMakeFiles / clangDynamicASTMatchers.dir / build.make:134:recipe for target'tools / clang / lib / ASTMatchers / Dynamic / CMakeFiles / clangDynamicASTMatchers.dir / Registry.cpp。 o'失败
make [2]:*** [tools / clang / lib / ASTMatchers / Dynamic / CMakeFiles / clangDynamicASTMatchers.dir / Registry.cpp.o]错误4
CMakeFiles / Makefile2:15102:配方为目标'tools / clang / lib / ASTMatchers / Dynamic / CMakeFiles / clangDynamicASTMatchers.dir / all'失败
make [1]:*** [tools / clang / lib / ASTMatchers / Dynamic / CMakeFiles / clangDynamicASTMatchers。 dir / all]错误2

这是怎么回事?
非常感谢您的任何帮助,谢谢!

解决方案

您遇到编译器崩溃:

  c ++:内部编译器错误:已杀死(程序cc1plus)
请提交一份完整的错误报告,并附带预处理源。

这基本上是一个编译器错误 - 编译器不应该崩溃,即使面对错误的输入。 p>

有几种方法可以解决这个问题:


  • 你有这种灵活性 - 正在改变编译器的版本,无论是更新到更新的版本还是更改为不同的C ++编译器。



    自从发生崩溃( cc1plus ),我建议更改为 clang ,这是一个很好的选择。 clang与gcc非常兼容,通常可以用作替代品。由于您正在构建LLVM,因此您很可能能够顺利构建clang(因为构建LLVM / clang是clang构建过程不可或缺的部分)。



    不同的编译器为相同的输入而崩溃是非常罕见的,所以使用clang应该有希望。或者,您可以尝试更新的gcc版本,例如 7.2

  • 如果您不是在更改编译器的位置上,您可以尝试通过更改崩溃文件的编译器标志来避免崩溃 - 例如,将优化级别从 -O2 降至 -O0 (通常试图放松帮助编译器成功的场景)。



    为了查明崩溃文件​​,最好从 make 中移除 -j 标志,以便它只用一个编译器进程依次运行,等等崩溃的文件将是编译的最后一个文件,并且不会对哪个文件导致编译器崩溃感到困惑。

  • 改变编译器标志的简单替代方法从命令行是这样做的,使用 optimize 编译指示,它可以让您在源文件本身指定优化标志,从而免除修补bui ld系统(这可能是一个痛苦)。



    优化杂注的GCC语法是: #pragma GCC optimize(string.. 。)



    您可以简单地将编译指示放在源文件的顶部,在包含之后,它会影响所有函数该文件。



    请注意,大多数现代编译器都支持 optimize 编译指示,但它可能不适用于旧编译器(比如GCC 4.8和之前版本)。




总结 - 我的第一个建议是安装clang默认包( apt-get install clang ),并将其指定为 configure 的编译器( CC = clang CXX = clang ++ )。

或者,如果您可以更改LLVM的源代码,喜欢快速修补, #pragma GCC optimize( - O0)可以完成工作。



祝你好运!


While trying to build llvm/clang 3.42 on ubuntu 17.04, I have failed with configre+make as mentioned in this SO post. I gave cmake a shot with this very similar script:

#!/bin/bash
###############
# DEFINITIONS #
###############
LLVM_SVN=https://llvm.org/svn/llvm-project
TAG=tags/RELEASE_342/final

###############
# DIRECTORIES #
###############
BASEDIR=/home/oren/GIT/myLLVMpass

###############
# DIRECTORIES #
###############
LLVM_DIR=${BASEDIR}/llvm-3.4.2
LLVM_BUILD_DIR=${LLVM_DIR}/build
LLVM_SRC_DIR=${LLVM_DIR}/llvm
CLANG_SRC_DIR=${LLVM_SRC_DIR}/tools/clang
COMPILER_RT_SRC_DIR=${LLVM_SRC_DIR}/projects/compiler-rt
LIBCXX_SRC_DIR=${LLVM_SRC_DIR}/projects/libcxx

#########################################################
# Prepare llvm, llvm/src and llvm/build directories ... #
#########################################################
mkdir ${LLVM_DIR}
mkdir ${LLVM_SRC_DIR}
mkdir ${LLVM_BUILD_DIR}

##################
# Get llvm 3.4.2 #
##################
svn co ${LLVM_SVN}/llvm/${TAG}        ${LLVM_SRC_DIR}
svn co ${LLVM_SVN}/cfe/${TAG}         ${CLANG_SRC_DIR}
svn co ${LLVM_SVN}/compiler-rt/${TAG} ${COMPILER_RT_SRC_DIR}
svn co ${LLVM_SVN}/libcxx/${TAG}      ${LIBCXX_SRC_DIR}

#################################
# No changes will be needed ... #
#################################
rm -rf ${LLVM_DIR}/.svn
rm -rf ${CLANG_DIR}/.svn
rm -rf ${COMPILER_RT_DIR}/.svn
rm -rf ${LIBCXX_DIR}/.svn

#####################################################
# Get inside the llvm/build directory and cmake ... #
#####################################################
cd ${LLVM_BUILD_DIR} && cmake ${LLVM_SRC_DIR}

###############
# make it !!! #
###############
make -j

I got a totally different error from the configure+make trial:

[ 78%] Building CXX object lib/Target/ARM/CMakeFiles/LLVMARMCodeGen.dir/Thumb1FrameLowering.cpp.o
[ 78%] Building CXX object lib/Target/ARM/CMakeFiles/LLVMARMCodeGen.dir/ARMTargetObjectFile.cpp.o
[ 78%] Building CXX object lib/Target/ARM/CMakeFiles/LLVMARMCodeGen.dir/MLxExpansionPass.cpp.o
[ 78%] Building CXX object lib/Target/ARM/CMakeFiles/LLVMARMCodeGen.dir/Thumb2InstrInfo.cpp.o
c++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report, with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-6/README.Bugs> for instructions.
tools/clang/lib/ASTMatchers/Dynamic/CMakeFiles/clangDynamicASTMatchers.dir/build.make:134: recipe for target 'tools/clang/lib/ASTMatchers/Dynamic/CMakeFiles/clangDynamicASTMatchers.dir/Registry.cpp.o' failed
make[2]: *** [tools/clang/lib/ASTMatchers/Dynamic/CMakeFiles/clangDynamicASTMatchers.dir/Registry.cpp.o] Error 4
CMakeFiles/Makefile2:15102: recipe for target 'tools/clang/lib/ASTMatchers/Dynamic/CMakeFiles/clangDynamicASTMatchers.dir/all' failed
make[1]: *** [tools/clang/lib/ASTMatchers/Dynamic/CMakeFiles/clangDynamicASTMatchers.dir/all] Error 2

What is going on here? Any help is very much appreciated, thanks!

解决方案

You're facing a compiler crash:

c++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report, with preprocessed source if appropriate.

This is basically a compiler bug - compilers should never crash, even when faced with erroneous input.

The are several ways to tackle this:

  • One option - if you have that flexibility - is changing the compiler version, whether updating to a more recent version, or changing to a different C++ compiler altogether.

    Since the crash occured building with gcc (cc1plus), I would suggest changing to clang, which is a very good alternative. clang is very highly compatible to gcc, and usually could be used as a drop in replacement. Since you are building LLVM, it's very likely you'll be able to build with clang smoothly (as building LLVM/clang is integral to clang's build process).

    The chance of different compilers crashing for the same input is very rare, so using clang should hopefully do. Alternatively, you could try a more recent gcc version, such as 7.2.

  • If you are not in position for changing compilers, you could try walking around the crash, by changing the compiler flags of the crashing file - for example, lowering the optimization level from -O2 to -O0 (generally trying to relax the scenario for helping the compiler to succeed).

    For pinpointing the crashing file, it's better to remove the -j flag from make, so that it will run sequentually with only one compiler process, and so the crashing file would be the last one that's compiled, and there's no confusion about which file caused the compiler crash.

  • A quick an easy alternative for altering compiler flags from the command line is, doing so using the optimize pragma, which lets you specify optimization flags in the source file itself, thus freeing you from patching the build system (which could be a pain).

    The GCC syntax for the optimize pragma is: #pragma GCC optimize ("string" ...).

    You could simply place the pragma at the top of your source file, after the includes, and it will affect all functions in that file.

    Note the optimize pragma is supported by most modern compilers, but it may not be available with old compilers (such as GCC 4.8 and prior).

To summarize - my first recommendation would be to install clang from the default package (apt-get install clang), and specify it as the compiler to configure (CC=clang and CXX=clang++).
Alternatively, if you're OK with changing LLVM's source code and prefer a quick and dirty fix, #pragma GCC optimize("-O0") may get the job done.

Good luck!

这篇关于gcc从源代码构建llvm 3.42时崩溃(使用cmake)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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