gcc crashes while building llvm 3.42 from source (

2019-08-17 18:47发布

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!

标签: ubuntu gcc llvm
1条回答
霸刀☆藐视天下
2楼-- · 2019-08-17 19:32

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!

查看更多
登录 后发表回答