Building clang on Raspberry Pi2

The raspberry Pi2 is an armv7a chip (Cortex-A7), the first stage builds fine with the native g++ (if not a little slowly at 10+ hours), but it crashes at some point with this command line:

Program arguments: /home/ben/development/llvm/3.6.0/rc2/Phase2/Release/llvmCore-3.6.0-rc2.install/bin/clang -cc1 -triple armv7-unknown-linux-gnueabihf -emit-obj -disable-free -disable-llvm-verifier -main-file-name APFloat.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -fuse-init-array -target-cpu cortex-a8 -target-abi aapcs-linux -mfloat-abi hard -target-linker-version 2.24.90.20141023 -dwarf-column-info -ffunction-sections -fdata-sections -coverage-file

But it's a Cortex-A7, not A8, how do I convince the test-release.sh or build scripts to make Phase1 clang target Cortex A7 for Phase2? (with vfpv4-d16)

Whilst we're at it, I'm not convinced that the Pi2 would make a great cross-compilation machine, so is it possible to reduce the enabled targets? "X86 Sparc PowerPC ARM AArch64 Mips XCore MSP430 CppBackend NVPTX Hexagon SystemZ R600"

Thanks,

Ben

Hi Ben,

What sort of error are you getting? Isn't APFloat.cpp the first source file that's being compiled by the newly built clang?

Trimming targets is easy. I had to do it when I built clang for ARM in the early days beucase the statis bild got too big. You can limit set code generators used in the configure line with -"-enable-targets=arm".

A 10 hour build. Why not just cross build it?

-Rich

The raspberry Pi2 is an armv7a chip (Cortex-A7), the first stage
builds fine with the native g++ (if not a little slowly at 10+ hours),
but it crashes at some point with this command line:

Program arguments:
/home/ben/development/llvm/3.6.0/rc2/Phase2/Release/llvmCore-3.6.0-rc2.install/bin/clang
-cc1 -triple armv7-unknown-linux-gnueabihf -emit-obj -disable-free
-disable-llvm-verifier -main-file-name APFloat.cpp -mrelocation-model
pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose
-mconstructor-aliases -fuse-init-array -target-cpu cortex-a8
-target-abi aapcs-linux -mfloat-abi hard -target-linker-version
2.24.90.20141023 -dwarf-column-info -ffunction-sections
-fdata-sections -coverage-file

But it's a Cortex-A7, not A8, how do I convince the test-release.sh or
build scripts to make Phase1 clang target Cortex A7 for Phase2? (with
vfpv4-d16)

Whilst we're at it, I'm not convinced that the Pi2 would make a great
cross-compilation machine, so is it possible to reduce the enabled
targets? "X86 Sparc PowerPC ARM AArch64 Mips XCore MSP430 CppBackend
NVPTX Hexagon SystemZ R600"

Hi Ben,

What sort of error are you getting? Isn't APFloat.cpp the first source
file that's being compiled by the newly built clang?

All sorts of errors, the binary is not compatible with the system, but bus error and spitting out crash dumps (where it packages the cpp and build file) are typical.

Trimming targets is easy. I had to do it when I built clang for ARM in
the early days beucase the statis bild got too big. You can limit set
code generators used in the configure line with -"-enable-targets=arm".

Thanks, I'm not sure if I can pass that through test-release.sh, but perhaps I can modify that script.

A 10 hour build. Why not just cross build it?

That was just the first phase of 3 :stuck_out_tongue: I'm just trying to see what the Pi2 is capable of, but I also thought it would be easier to convince the build to run correctly on the native machine.

Ben

Ben,

My son bought me a Raspberry Pi for Christmas. I've been itching to try my cross compiled pre-built clang binaries on it. (http://ellcc.org/blog/?page_id=20295). I hope to soon.

-Rich

Cortex-A7 is actually newer (and has more features) than Cortex-A8
(don't ask), so having A8 as the minimum is still ok.

Also, I believe the Pi2 is VFPv4-D32, not VFPv4-D16, but that's
irrelevant to your problem.

Can you share the error message, too? APFloat is, indeed, the first
file to be compiled, so as Richard said, the error is probably because
the binaries you created on Phase2 are broken.

cheers,
--renato

But it's a Cortex-A7, not A8, how do I convince the test-release.sh or build
scripts to make Phase1 clang target Cortex A7 for Phase2? (with vfpv4-d16)

Cortex-A7 is actually newer (and has more features) than Cortex-A8
(don't ask), so having A8 as the minimum is still ok.

OK, fair point, but I would like detection to get it right. I wonder if I should update config.guess / config.sub? I never understood autotools.

Also, I believe the Pi2 is VFPv4-D32, not VFPv4-D16, but that's
irrelevant to your problem.

Hmm, not sure where I thought I saw it was -D16.

Can you share the error message, too? APFloat is, indeed, the first
file to be compiled, so as Richard said, the error is probably because
the binaries you created on Phase2 are broken.

OK, so I'm now building RC3 using the Phase1 of RC2 (because clang is significantly faster than gcc)

Phase1:
# Compiling llvm 3.6.0-rc3 Release
# make -j 4 VERBOSE=1
llvm[0]: Constructing LLVMBuild project information.
/usr/bin/python /home/ben/development/llvm/3.6.0/rc3/llvm.src/utils/llvm-build/llvm-build \
   --native-target "ARM" \
   --enable-targets "X86 Sparc PowerPC ARM AArch64 Mips XCore MSP430 CppBackend NVPTX Hexagon SystemZ R600" \
   --enable-optional-components "" \
   --write-library-table /home/ben/development/llvm/3.6.0/rc3/Phase1/Release/llvmCore-3.6.0-rc3.obj/tools/llvm-config/LibraryDependencies.inc \
   --write-make-fragment /home/ben/development/llvm/3.6.0/rc3/Phase1/Release/llvmCore-3.6.0-rc3.obj/Makefile.llvmbuild \
   --write-cmake-fragment /home/ben/development/llvm/3.6.0/rc3/Phase1/Release/llvmCore-3.6.0-rc3.obj/LLVMBuild.cmake \
   --write-cmake-exports-fragment /home/ben/development/llvm/3.6.0/rc3/Phase1/Release/llvmCore-3.6.0-rc3.obj/cmake/modules/LLVMBuildExports.cmake
for dir in lib/Support lib/TableGen utils lib/IR lib tools/llvm-config tools docs cmake unittests; do \
   if ([ ! -f $dir/Makefile ] || \
       command test $dir/Makefile -ot /home/ben/development/llvm/3.6.0/rc3/llvm.src/$dir/Makefile ); then \
/home/ben/development/llvm/3.6.0/rc3/llvm.src/autoconf/mkinstalldirs $dir; \
     /bin/cp /home/ben/development/llvm/3.6.0/rc3/llvm.src/$dir/Makefile $dir/Makefile; \
   fi; \
   (make -C $dir all ) || exit 1; \
done
make[1]: Entering directory '/home/ben/development/llvm/3.6.0/rc3/Phase1/Release/llvmCore-3.6.0-rc3.obj/lib/Support'
/home/ben/development/llvm/3.6.0/rc3/llvm.src/autoconf/mkinstalldirs /home/ben/development/llvm/3.6.0/rc3/Phase1/Release/llvmCore-3.6.0-rc3.obj/lib/Support/Release > /dev/null
/home/ben/development/llvm/3.6.0/rc3/llvm.src/autoconf/mkinstalldirs /home/ben/development/llvm/3.6.0/rc3/Phase1/Release/llvmCore-3.6.0-rc3.obj/lib/Support/Release/./ > /dev/null
echo 'Created.' > /home/ben/development/llvm/3.6.0/rc3/Phase1/Release/llvmCore-3.6.0-rc3.obj/lib/Support/Release/.dir
echo 'Created.' > /home/ben/development/llvm/3.6.0/rc3/Phase1/Release/llvmCore-3.6.0-rc3.obj/lib/Support/Release/.//.dir
/home/ben/development/llvm/3.6.0/rc3/llvm.src/autoconf/mkinstalldirs /home/ben/development/llvm/3.6.0/rc3/Phase1/Release/llvmCore-3.6.0-rc3.obj/Release/lib > /dev/null
llvm[1]: Compiling APFloat.cpp for Release build
if /home/ben/development/llvm/3.6.0/clang-3.6-rc2/bin/clang++ -I/home/ben/development/llvm/3.6.0/rc3/Phase1/Release/llvmCore-3.6.0-rc3.obj/include -I/home/ben/development/llvm/3.6.0/rc3/Phase1/Release/llvmCore-3.6.0-rc3.obj/lib/Support -I/home/ben/development/llvm/3.6.0/rc3/llvm.src/include -I/home/ben/development/llvm/3.6.0/rc3/llvm.src/lib/Support -DNDEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -O3 -fomit-frame-pointer -std=c++11 -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -fPIC -ffunction-sections -fdata-sections -Wcast-qual -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcovered-switch-default -Wno-uninitialized -Wno-missing-field-initializers -Wno-comment -c -MMD -MP -MF "/home/ben/development/llvm/3.6.0/rc3/Phase1/Release/llvmCore-3.6.0-rc3.obj/lib/Support/Release/APFloat.d.tmp" -MT "/home/ben/development/llvm/3.6.0/rc3/Phase1/Release/llvmCore-3.6.0-rc3.obj/lib/Support/Release/APFloat.o" -MT "/home/ben/development/llvm/3.6.0/rc3/Phase1/Release/llvmCore-3.6.0-rc3.obj/lib/Support/Release/APFloat.d" /home/ben/development/llvm/3.6.0/rc3/llvm.src/lib/Support/APFloat.cpp -o /home/ben/development/llvm/3.6.0/rc3/Phase1/Release/llvmCore-3.6.0-rc3.obj/lib/Support/Release/APFloat.o ; \

Phase2:
# Compiling llvm 3.6.0-rc3 Release
# make -j 4 VERBOSE=1
llvm[0]: Constructing LLVMBuild project information.
/usr/bin/python /home/ben/development/llvm/3.6.0/rc3/llvm.src/utils/llvm-build/llvm-build \
   --native-target "ARM" \
   --enable-targets "X86 Sparc PowerPC ARM AArch64 Mips XCore MSP430 CppBackend NVPTX Hexagon SystemZ R600" \
   --enable-optional-components "" \
   --write-library-table /home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/tools/llvm-config/LibraryDependencies.inc \
   --write-make-fragment /home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/Makefile.llvmbuild \
   --write-cmake-fragment /home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/LLVMBuild.cmake \
   --write-cmake-exports-fragment /home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/cmake/modules/LLVMBuildExports.cmake
for dir in lib/Support lib/TableGen utils lib/IR lib tools/llvm-config tools docs cmake unittests; do \
   if ([ ! -f $dir/Makefile ] || \
       command test $dir/Makefile -ot /home/ben/development/llvm/3.6.0/rc3/llvm.src/$dir/Makefile ); then \
/home/ben/development/llvm/3.6.0/rc3/llvm.src/autoconf/mkinstalldirs $dir; \
     /bin/cp /home/ben/development/llvm/3.6.0/rc3/llvm.src/$dir/Makefile $dir/Makefile; \
   fi; \
   (make -C $dir all ) || exit 1; \
done
make[1]: Entering directory '/home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/lib/Support'
/home/ben/development/llvm/3.6.0/rc3/llvm.src/autoconf/mkinstalldirs /home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/lib/Support/Release > /dev/null
/home/ben/development/llvm/3.6.0/rc3/llvm.src/autoconf/mkinstalldirs /home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/lib/Support/Release/./ > /dev/null
echo 'Created.' > /home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/lib/Support/Release/.dir
echo 'Created.' > /home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/lib/Support/Release/.//.dir
/home/ben/development/llvm/3.6.0/rc3/llvm.src/autoconf/mkinstalldirs /home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/Release/lib > /dev/null
llvm[1]: Compiling APFloat.cpp for Release build
if /home/ben/development/llvm/3.6.0/rc3/Phase1/Release/llvmCore-3.6.0-rc3.install/bin/clang++ -I/home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/include -I/home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/lib/Support -I/home/ben/development/llvm/3.6.0/rc3/llvm.src/include -I/home/ben/development/llvm/3.6.0/rc3/llvm.src/lib/Support -DNDEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -O3 -fomit-frame-pointer -std=c++11 -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -fPIC -ffunction-sections -fdata-sections -Wcast-qual -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcovered-switch-default -Wno-uninitialized -Wno-missing-field-initializers -Wno-comment -c -MMD -MP -MF "/home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/lib/Support/Release/APFloat.d.tmp" -MT "/home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/lib/Support/Release/APFloat.o" -MT "/home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/lib/Support/Release/APFloat.d" /home/ben/development/llvm/3.6.0/rc3/llvm.src/lib/Support/APFloat.cpp -o /home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/lib/Support/Release/APFloat.o ; \
         then /bin/mv -f "/home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/lib/Support/Release/APFloat.d.tmp" "/home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/lib/Support/Release/APFloat.d"; else /bin/rm "/home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/lib/Support/Release/APFloat.d.tmp"; exit 1; fi

Failure:
Stack dump:
0. Program arguments: /home/ben/development/llvm/3.6.0/rc3/Phase1/Release/llvmCore-3.6.0-rc3.install/bin/clang -cc1 -triple armv7-unknown-linux-gnueabihf -emit-obj -disable-free -disable-llvm-verifier -main-file-name APFloat.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -fuse-init-array -target-cpu cortex-a8 -target-abi aapcs-linux -mfloat-abi hard -target-linker-version 2.24.90.20141023 -dwarf-column-info -ffunction-sections -fdata-sections -coverage-file /home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/lib/Support/Release/APFloat.o -resource-dir /home/ben/development/llvm/3.6.0/rc3/Phase1/Release/llvmCore-3.6.0-rc3.install/bin/../lib/clang/3.6.0 -dependency-file /home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/lib/Support/Release/APFloat.d.tmp -MP -MT /home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/lib/Support/Release/APFloat.o -MT /home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/lib/Support/Release/APFloat.d -D NDEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/include -I /home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/lib/Support -I /home/ben/development/llvm/3.6.0/rc3/llvm.src/include -I /home/ben/development/llvm/3.6.0/rc3/llvm.src/lib/Support -internal-isystem /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../../include/c++/4.9 -internal-isystem /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../../include/arm-linux-gnueabihf/c++/4.9 -internal-isystem /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../../include/arm-linux-gnueabihf/c++/4.9 -internal-isystem /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../../include/c++/4.9/backward -internal-isystem /usr/local/include -internal-isystem /home/ben/development/llvm/3.6.0/rc3/Phase1/Release/llvmCore-3.6.0-rc3.install/bin/../lib/clang/3.6.0/include -internal-externc-isystem /usr/include/arm-linux-gnueabihf -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wcast-qual -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcovered-switch-default -Wno-uninitialized -Wno-missing-field-initializers -Wno-comment -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/lib/Support -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -mstackrealign -fno-rtti -fno-signed-char -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -o /home/ben/development/llvm/3.6.0/rc3/Phase2/Release/llvmCore-3.6.0-rc3.obj/lib/Support/Release/APFloat.o -x c++ /home/ben/development/llvm/3.6.0/rc3/llvm.src/lib/Support/APFloat.cpp
1. /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../../include/c++/4.9/bits/ptr_traits.h:77:25: at annotation token
2. /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../../include/c++/4.9/bits/ptr_traits.h:37:1: parsing namespace 'std'
3. /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../../include/c++/4.9/bits/ptr_traits.h:73:5: parsing struct/union/class body '__ptrtr_rebind_helper'
clang: error: unable to execute command: Bus error
clang: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 3.6.0 (tags/RELEASE_360/rc3)
Target: armv7-unknown-linux-gnueabihf
Thread model: posix
clang: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and associated run script.
clang: note: diagnostic msg: