From d40a4f4bc38a1116ff040a01bd80265cfe9e4550 Mon Sep 17 00:00:00 2001 From: Joseph Heenan Date: Sat, 13 Aug 2016 06:51:30 +0000 Subject: [PATCH 1/2] #104 Fix compile failing on raspberry pi 3 When we test if the compiler options work, we didn't test for the possibility of the compiler crashing which unfortunately it does on the raspberry pi 3 - crashing in this case means returning exit code 134 (i.e. SIGABRT). Change the test so that instead of testing for one particular failure, we invert and test for success - treating everything else as failure. --- configure.ac | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index a256f3d4..29e443fd 100644 --- a/configure.ac +++ b/configure.ac @@ -1045,11 +1045,11 @@ rm -f $TMPO rm -f $TMPC -if test "x${TMP}" = "x1" ; then +if test "x${TMP}" = "x0" ; then + echo "CPU optimization: $CPU_OPTIONS" +else CPU_OPTIONS="" echo "No CPU optimizations will be added" -else - echo "CPU optimization: $CPU_OPTIONS" fi else From c7ca2af868b79ece35ed521e9e6d4ed7a8cbcc84 Mon Sep 17 00:00:00 2001 From: Joseph Heenan Date: Sat, 13 Aug 2016 07:22:10 +0000 Subject: [PATCH 2/2] Fix #104 Use optimal compilation options on Raspberry Pi 3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gcc on the raspberry pi 3 crashes when called from our configure script, and even in simpler cases: $ gcc -mcpu=native -march=native *** Error in `gcc': double free or corruption (top): 0x0190dbc0 *** Aborted So we need to add explicit optimisation options if we want to build an optimal binary on the Pi 3. As per: https://www.element14.com/community/community/raspberry-pi/blog/2016/02/29/the-most-comprehensive-raspberry-pi-comparison-benchmark-ever the raspberry pi 3 is an armv8, but cpuinfo incorrectly reports it as an armv7. So we can’t detect the CPU using /proc/cpuinfo. Instead we use /proc/device-tree/model, which explicit has the Raspberry PI type in it, e.g. “Raspberry Pi 3 Model B Rev 1.2”. https://www.raspberrypi.org/forums/viewtopic.php?t=144115&p=952479 lists hopefully correct optimal gcc flags, namely: Some basic options that should be the defaults anyway:- -mfloat-abi=hard -mlittle-endian -munaligned-access (confirmed; these are the defaults) Pi1 -mcpu=arm1176jzf-s -mfpu=vfp Pi2 -mcpu=cortex-a7 -mfpu=neon-vfpv4 Pi3 -mcpu=cortex-a53 -mfpu=neon-fp-armv8 --- configure.ac | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 29e443fd..458735e6 100644 --- a/configure.ac +++ b/configure.ac @@ -845,7 +845,18 @@ if test "${OPTIMIZECPU}" = "yes"; then # Try to autodetect cpu type CPU_NAME="unknown" CPU_TYPE="unknown" -if test -e "/proc/cpuinfo" ; then +if test -e "/proc/device-tree/model"; then + # explicit test for RPI3 as /proc/cpuinfo reports armv7 even though + # it is armv8 + RPI3=`grep "Raspberry Pi 3 Model" /proc/device-tree/model` + if test "x${RPI3}" != "x"; then + CPU_NAME="Raspberry Pi 3" + CPU_TYPE="Raspberry Pi 3" + CPU_OPTIONS="-mcpu=cortex-a53 -mfpu=neon-fp-armv8" + fi +fi + +if test "x${CPU_TYPE}" = "xunknown" && test -e "/proc/cpuinfo" ; then intel[[30]]="-march=i386" intel[[32]]="-march=i386" intel[[34]]="-march=i386"