{"id":838,"date":"2018-07-02T11:59:30","date_gmt":"2018-07-02T09:59:30","guid":{"rendered":"http:\/\/raytec.org\/wordpress\/?p=838"},"modified":"2018-07-02T12:04:27","modified_gmt":"2018-07-02T10:04:27","slug":"compile-gcc-8-1-for-raspberry-pi-3","status":"publish","type":"post","link":"http:\/\/raytec.org\/wordpress\/2018\/07\/02\/compile-gcc-8-1-for-raspberry-pi-3\/","title":{"rendered":"Compile GCC-8.1 for Raspberry PI 3"},"content":{"rendered":"<p>The British company <a href=\"https:\/\/en.wikipedia.org\/wiki\/Arm_Holdings\">Arm Holdings<\/a> licences the ARM Central Processing Unit (CPU) design to manufacturers such as Samsung, Apple and Broadcom for their own chip-design, which may include further functionalities into the design.<br \/>\nSince March 2018 the Raspberry PI 3B+ is available. It features a Broadcom BCM2837B0 SOC (System-on-Chip), containing an <a href=\"https:\/\/en.wikipedia.org\/wiki\/ARM_Cortex-A53\">Cortex-A53<\/a> CPU. This CPU abides to the <a href=\"https:\/\/en.wikipedia.org\/wiki\/List_of_ARM_microarchitectures\">ARMv8.0-A<\/a> instruction set.<\/p>\n<p>The ARMv8.0-A instruction set has made previously optional functionality now mandatory. One of the biggest differences relate to the floating-point unit (FPU). Previously to make up for a missing FPU, the operating system (OS) had to provide a Software FPU, in short soft-fpu.<br \/>\nOperating Systems such as Raspbian Linux based on the rather conservative Debian Linux distribution ships with gcc-6.3.0 as default compiler, which does not know about the intricacies of the ARMv8 architecture. In fact, it assumes, it compiles for ARMv6!<br \/>\nTo verify, compile a simple C code using the base gcc-6 using the command-line<br \/>\n<code>gcc -march=native -S -fverbose-asm -mprint-tune-info -o stub.S stub.c<\/code><br \/>\nIn the assembler dump <code>stub.S<\/code> You&#8217;ll find the inherent options passed (due to <code>-fverbose-asm<\/code>) including <code>-march=armv6<\/code>, <code>-mfloat-abi=hard<\/code> (which is good) and <code>-mfpu=vfp<\/code> (which is not so good).<\/p>\n<p>The information to provide is based on the above Wiki-pages and on output generated from <code>cat \/proc\/cpuinfo<\/code>:<br \/>\n<code><br \/>\n...<br \/>\nFeatures: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva divt vfpd32 lpae evtstrm crc32<br \/>\n...<br \/>\n<\/code><br \/>\nReading the Linux source code in file <code>arch\/arm\/kernel\/setup.c<\/code> these include Advanced Single-Instruction Multiple Data (SIMD) instructions called NEON (neon) with 32 64-Bit registers (vfpd32) include cyclic-redundancy check instructions (crc32) but not the crypto extension (such as aes, sha1, sha2).<\/p>\n<p>Now we want to compile an up-to-date gcc-8.1.0 on Raspberry PI, to make best usage of the instruction set and the Cortex-A53&#8217;s units.<br \/>\nThere are already websites\/blogs documenting how to <a href=\"https:\/\/solarianprogrammer.com\/2017\/12\/07\/raspberry-pi-raspbian-compiling-gcc\/\">compile gcc-8.1.0<\/a>, however, they fail to address the issues mentioned above.<br \/>\nI found that configuring gcc with the following options provides good results:<br \/>\n<code>SOURCE_DIR_OF_GCC\/configure --program-suffix=-8.1 --with-arch=armv8-a+simd+crc --with-float=hard --build=arm-linux-gnueabihf --enable-languages=c,c++,fortran,lto --disable-multilib --enable-checking=release<\/code><\/p>\n<p>These are the differences in the configuration with regard to the above Blog:<\/p>\n<ul>\n<li>Use a shorter suffix, so the new compiler will be automatically available in path <code>\/usr\/local\/bin<\/code> as <code>gcc-8.1<\/code>, <code>g++-8.1<\/code> and <code>gfortran-8.1<\/code> now including Link Time Optimizations (lto)<\/li>\n<li>Properly set the architecture of the processor: it is an ARMv-8.0-A architecture, which does have SIMD and CRC instructions.<\/li>\n<li>Includes link-time optimizations (lto) to C, C++ and Fortran.<\/li>\n<li>Does limited checking on the compiler (reducing memory footprint).<\/li>\n<li>Only sets the build-information, so that necessary libraries are found in <code>\/usr\/lib\/arm-linux-gnueabihf<\/code>, but does not set cross-compiling flags such as <code>--target<\/code>.<\/li>\n<\/ul>\n<p>After having installed this compiler, we may compile OpenCV and friends using updated compiler flags:<br \/>\n<code>ccmake SOURCE_TO_OPENCV -DCMAKE_C_COMPILER=gcc-8.1 -DCMAKE_CXX_COMPILER=g++-8.1 -DCMAKE_CXX_FLAGS=\"-march=armv8-a+simd+crc -mfpu=auto -mtune=cortex-a53\" -DCMAKE_C_FLAGS=\"-march=armv8-a+simd+crc -mfpu=auto -mtune=cortex-a53\" ... <\/code>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The British company Arm Holdings licences the ARM Central Processing Unit (CPU) design to manufacturers such as Samsung, Apple and Broadcom for their own chip-design, which may include further functionalities into the design. Since March 2018 the Raspberry PI 3B+ &hellip; <a href=\"http:\/\/raytec.org\/wordpress\/2018\/07\/02\/compile-gcc-8-1-for-raspberry-pi-3\/\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[13,14,12],"class_list":["post-838","post","type-post","status-publish","format-standard","hentry","category-allgemein","tag-arm","tag-raspberry-pi","tag-tec"],"_links":{"self":[{"href":"http:\/\/raytec.org\/wordpress\/wp-json\/wp\/v2\/posts\/838","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/raytec.org\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/raytec.org\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/raytec.org\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/raytec.org\/wordpress\/wp-json\/wp\/v2\/comments?post=838"}],"version-history":[{"count":3,"href":"http:\/\/raytec.org\/wordpress\/wp-json\/wp\/v2\/posts\/838\/revisions"}],"predecessor-version":[{"id":841,"href":"http:\/\/raytec.org\/wordpress\/wp-json\/wp\/v2\/posts\/838\/revisions\/841"}],"wp:attachment":[{"href":"http:\/\/raytec.org\/wordpress\/wp-json\/wp\/v2\/media?parent=838"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/raytec.org\/wordpress\/wp-json\/wp\/v2\/categories?post=838"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/raytec.org\/wordpress\/wp-json\/wp\/v2\/tags?post=838"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}