Illegal Instruction [.pio/build/teensy40/src/main.cpp.o] Error 132

Hey, I have been running into this error.

Building in release mode
Compiling .pio/build/teensy40/src/main.cpp.o
Illegal instruction
*** [.pio/build/teensy40/src/main.cpp.o] Error 132

1 Like

Missing information:

  • what operating system and IDE are you running on
  • what is the full platformio.ini
  • what is either the full main.cpp or the most minimal code which can reproduce the problem
  • what version of the Teensy platform and packages (compiler, framework, ā€¦) are you using (start of compilation output)

Hello Max! Jan and I are working on this together. Thanks for the help again.

Info:

  • what operating system and IDE are you running on
    I am trying to move the system you helped me with from a raspberry pi 4 to a raspberry pi zero W. This is PlatformIO Core on a reasperry pi zeroW.

  • what is the full platformio.ini

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:teensy40]
platform = teensy
framework = arduino
board = teensy40 
platform_packages = 
   toolchain-gccarmnoneeabi@https://bintray.com/platformio/tool-packages/download_file?file_path=3579c14-toolchain-gccarmnoneeabi-linux_armv6l-1.90301.200702.tar.gz
   tool-teensy@https://github.com/maxgerhardt/pio-tool-teensy-arm/archive/master.zip
  • what is either the full main.cpp or the most minimal code which can reproduce the problem
    I ran this with the recommended Blink code from the Quickstart as well as our code and the error was the same both times.
  • what version of the Teensy platform and packages (compiler, framework, ā€¦) are you using (start of compilation output)
Processing teensy40 (platform: teensy; framework: arduino; board: teensy40)
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/teensy/teensy40.html
PLATFORM: Teensy (4.11.0) > Teensy 4.0
HARDWARE: IMXRT1062 600MHz, 512KB RAM, 1.94MB Flash
DEBUG: Current (jlink) External (jlink)
PACKAGES: 
 - framework-arduinoteensy 1.153.0 (1.53) 
 - tool-teensy 1.152.200516 (1.52) 
 - toolchain-gccarmnoneeabi 1.90301.200702 (9.3.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 89 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio/build/teensy40/src/main.cpp.o
Illegal instruction
*** [.pio/build/teensy40/src/main.cpp.o] Error 132
=============================================================== [FAILED] Took 24.02 seconds ===============================================================

Here is the rest of the output

Sounds to me like youā€™re trying to run the gcc toolchain compiled for a 32-bit system on a 64-bit operating system. Whatā€™s the output of uname -a on the target system?

1 Like

Linux raspberrypi 5.4.72+ #1356 Thu Oct 22 13:56:00 BST 2020 armv6l GNU/Linux

Okay a armv6l system running toolchain-gccarmnoneeabi-linux_armv6l package seems fine to me at first glance. Please:

  • cd ~/.platformio/pacakges
  • find the correct name of the installed toolchain-gccarmnoneeabi folder. There might be two there ā€“ one called the former and one with a @1.90301.200702 suffix. If that suffixed-folder exist, cd into that, otherwise the one without the suffix.
  • further cd bin/ into it
  • run file ./arm-none-eabi-gcc
  • run ldd ./arm-none-eabi-gcc
  • run ./arm-none-eabi-gcc --version [and post output]
pi@raspberrypi:~/Documents/UploadTest $ cd ~/.platformio/packages/
pi@raspberrypi:~/.platformio/packages $ ls
contrib-piohome  framework-arduinoteensy   toolchain-gccarmnoneeabi@src-12d887f0bbffef90b4646370dd7372ae  tool-teensy
contrib-pysite   toolchain-gccarmnoneeabi  tool-scons
pi@raspberrypi:~/.platformio/packages $ cd toolchain-gccarmnoneeabi@src-12d887f0bbffef90b4646370dd7372ae/
pi@raspberrypi:~/.platformio/packages/toolchain-gccarmnoneeabi@src-12d887f0bbffef90b4646370dd7372ae $ cd bin/
pi@raspberrypi:~/.platformio/packages/toolchain-gccarmnoneeabi@src-12d887f0bbffef90b4646370dd7372ae/bin $ file ./arm-none-eabi-gc
arm-none-eabi-gcc         arm-none-eabi-gcc-ar      arm-none-eabi-gcc-ranlib  arm-none-eabi-gcov-dump   
arm-none-eabi-gcc-9.3.1   arm-none-eabi-gcc-nm      arm-none-eabi-gcov        arm-none-eabi-gcov-tool   
pi@raspberrypi:~/.platformio/packages/toolchain-gccarmnoneeabi@src-12d887f0bbffef90b4646370dd7372ae/bin $ file ./arm-none-eabi-gcc
./arm-none-eabi-gcc: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=e44abfbe3cf82773ba07252dbf98e4904079e6c6, not stripped
pi@raspberrypi:~/.platformio/packages/toolchain-gccarmnoneeabi@src-12d887f0bbffef90b4646370dd7372ae/bin $ ldd ./arm-none-eabi-gcc
	/usr/lib/arm-linux-gnueabihf/libarmmem-${PLATFORM}.so => /usr/lib/arm-linux-gnueabihf/libarmmem-v6l.so (0xb6f47000)
	libiconv.so.2 => /home/pi/.platformio/packages/toolchain-gccarmnoneeabi@src-12d887f0bbffef90b4646370dd7372ae/bin/./libiconv.so.2 (0xb6e56000)
	libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0xb6dc0000)
	libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6c72000)
	/lib/ld-linux-armhf.so.3 (0xb6f5a000)
pi@raspberrypi:~/.platformio/packages/toolchain-gccarmnoneeabi@src-12d887f0bbffef90b4646370dd7372ae/bin $ ./arm-none-eabi-gcc --version
Segmentation fault
pi@raspberrypi:~/.platformio/packages/toolchain-gccarmnoneeabi@src-12d887f0bbffef90b4646370dd7372ae/bin $ pi@raspberrypi:~/.platformio/packages/toolchain-gccarmnoneeabi@src-12d887f0bbffef90b4646370dd7372ae/bin pi@raspberrypi:~/.platformio/packages/toolchain-gccarmnoneeabi@src-12d887f0bbffef90b4646370dd7372ae/bipi@raspi@raspi@raspi@raspi@pi@raspi@raspberrypi:~/.plapi@raspberrypi:~/.platformio/packages/tpi@raspberrypi:~/.platformio/packpi@raspberrypi:~/.platformipi@raspberrypi:~/.platformio/packages/toolchain-gccarmnoneeabi@src-12d887f0bbffef90b4646370dd7372ae/bin $ 
  • whatā€™s the output of ls -lh /lib/ld-linux-armhf.so.3?
  • execute sudo apt update && sudo apt install libc6-dbg (in reference to here). Then rerun ./arm-none-eabi-gcc --version. Does it still crash?
1 Like
  • whatā€™s the output of ls -lh /lib/ld-linux-armhf.so.3 ?
    lrwxrwxrwx 1 root root 30 May 14 2019 /lib/ld-linux-armhf.so.3 -> arm-linux-gnueabihf/ld-2.28.so
Hit:1 http://archive.raspberrypi.org/debian buster InRelease
Get:2 http://raspbian.raspberrypi.org/raspbian buster InRelease [15.0 kB]
Fetched 15.0 kB in 3s (5,091 B/s)          
Reading package lists... Done
Building dependency tree       
Reading state information... Done
All packages are up to date.
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libc6-dbg is already the newest version (2.28-10+rpi1).
libc6-dbg set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
pi@raspberrypi:~ $ cd ~/.platformio/pacakges
-bash: cd: /home/pi/.platformio/pacakges: No such file or directory
pi@raspberrypi:~ $ ls
Bookshelf  Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos
pi@raspberrypi:~ $ cd ~/.platformio/pacakges
-bash: cd: /home/pi/.platformio/pacakges: No such file or directory
pi@raspberrypi:~ $ cd .platformio/packages/
pi@raspberrypi:~/.platformio/packages $ ls
contrib-piohome  framework-arduinoteensy   toolchain-gccarmnoneeabi@src-12d887f0bbffef90b4646370dd7372ae  tool-teensy
contrib-pysite   toolchain-gccarmnoneeabi  tool-scons
pi@raspberrypi:~/.platformio/packages $ cd toolchain-gccarmnoneeabi@src-12d887f0bbffef90b4646370dd7372ae/
pi@raspberrypi:~/.platformio/packages/toolchain-gccarmnoneeabi@src-12d887f0bbffef90b4646370dd7372ae $ cd bin/
pi@raspberrypi:~/.platformio/packages/toolchain-gccarmnoneeabi@src-12d887f0bbffef90b4646370dd7372ae/bin $ file ./arm-none-eabi-gcc
./arm-none-eabi-gcc: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=e44abfbe3cf82773ba07252dbf98e4904079e6c6, not stripped
pi@raspberrypi:~/.platformio/packages/toolchain-gccarmnoneeabi@src-12d887f0bbffef90b4646370dd7372ae/bin $ ldd ./arm-none-eabi-gcc
	/usr/lib/arm-linux-gnueabihf/libarmmem-${PLATFORM}.so => /usr/lib/arm-linux-gnueabihf/libarmmem-v6l.so (0xb6f82000)
	libiconv.so.2 => /home/pi/.platformio/packages/toolchain-gccarmnoneeabi@src-12d887f0bbffef90b4646370dd7372ae/bin/./libiconv.so.2 (0xb6e91000)
	libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0xb6dfb000)
	libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6cad000)
	/lib/ld-linux-armhf.so.3 (0xb6f95000)
pi@raspberrypi:~/.platformio/packages/toolchain-gccarmnoneeabi@src-12d887f0bbffef90b4646370dd7372ae/bin $ ./arm-none-eabi-gcc --version
Segmentation fault

For some reason the binary obtained from the toolchain-gccarmnoneeabi-linux_armv6l is not executable on the Pi Zero Wā€¦ Either some other package is missing (Iā€™ve read about libc6-armhf-cross but yoā€™re already running in a armhf system, no reason to have a cross libraryā€¦), or the binary wasnā€™t built for ARMv6l and contains some instructions that donā€™t exist for ARMv6l. In that case the compiler would have to be recompiled on the target system and repackage. Iā€™ll investigate on my Pi Zero W.

1 Like

if this helps at all, I ran through the steps and did ./arm-none-eabi-gcc --version on the normal toolchain-gccarmnoneeabi and this was the result:

arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 5.4.1 20160919 (release) [ARM/embedded-5-branch revision 240496]
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

pi@raspberrypi:~/.platformio/packages/toolchain-gccarmnoneeabi/bin $ 

I tried a few things that were suggested in another thread such as using an older version of teensy with this .ini


[env:teensy40]
platform = teensy@4.4.0
framework = arduino
board = teensy40 
platform_packages = 
   toolchain-gccarmnoneeabi@https://bintray.com/platformio/tool-packages/download_file?file_path=3579c14-toolchain-gccarmnoneeabi-linux_armv6l-1.90301.200702.tar.gz
   tool-teensy@https://github.com/maxgerhardt/pio-tool-teensy-arm/archive/master.zip

But unfortunately it didnā€™t change anything, and I still had the same error. I also looked into trying a different toolchain-gccarmnoneeabi but it didnā€™t work either, at this point Iā€™m at a loss. Thanks!

Iā€™ve setup my Raspberry Pi Zero W succesfully with the latest Raspbian Lite image. I can observe the exact same error as you regarding the illegal instruction. Sadly, running gdb on the arm-none-eabi-gcc doesnā€™t reveal any insights as to whatā€™s going on inside, it just crashes at a very early stage.

So Iā€™ve decided itā€™s best to compile the needed GCC version (9.3.1 or similiar) on the Raspbi Zero W by following these steps

  • sudo apt update && sudo apt dist-upgrade
  • sudo apt install python3 python3-pip
  • sudo -H pip3 install platformio
  • sudo nano /etc/dphys-swapfile
    • ā†’ edit swapfile size to be 500MB in case local RAM runs out; reboot pi
  • download from gcc-arm-none-eabi-9-2020-q2-update-src.tar.bz2 Downloads | GNU Arm Embedded Toolchain Downloads ā€“ Arm Developer
  • extract on raspberry pi (wget + tar xfā€¦)
  • Then I follow the how-to-build-toolchain.pdf for compile instructions.
  • Installing build dependencies
apt-get -f install -y \
build-essential \
autoconf \
autogen \
bison \
dejagnu \
flex \
flip \
gawk \
git \
gperf \
gzip \
nsis \
openssh-client \
p7zip-full \
perl \
python-dev \
libisl-dev \
scons \
tcl \
texinfo \
tofrodos \
wget \
zip \
texlive \
texlive-extra-utils \
libncurses5-dev
  • And finally starting the build process (while ignoring Win32 build)
./install-sources.sh --skip_steps=mingw32
./build-prerequisites.sh --skip_steps=mingw32
./build-toolchain.sh --skip_steps=mingw32
  • As the PDF says

Once the build completes you can find the binary and source tarballs in ā€˜pkgā€™ along with the md5 checksum.

Now Iā€™m just waiting to see whether these steps go through; as itā€™s currently in the build-prerequisites.sh . I fear that my 16GB SD card is too small for that or that the compilation will take up so much RAM that it will be swapping to SD card all the time, making compilation extremely slow. Building GCC even on a normal x86_64 laptop costs 45 minutes from my memory, and that Pi isā€¦ dramatically slower that that laptop. Iā€™m expecting this to take time in the range of 4-8 hours.

So Iā€™ll see how that works out and upgrade my SD card if space runs out, or if RAM runs out then too Iā€™ll have to somehow get a cross-compiler for the Raspberry Pi Zero W; Just a matter of time.

Once arm-none-eabi-gcc is compiled and executable on the Pi itā€™s just a matter of copying the build output and creating a new toolchain-gccarmnoneabi package as Iā€™ve done for other the other pacakages (GitHub - maxgerhardt/toolchain-riscv-macos: Short test for an updated PlatformIO RISCV toolchain for MacOS, GitHub - maxgerhardt/pio-tool-teensy-arm) and referencing that new package in platform_packages.

1 Like

So the ./build-prerequisites.sh --skip_steps=mingw32 actually went through and I still have 8.3GB available on the SD card. Now doing the ./build-toolchain.sh --skip_steps=mingw32 and crossing my fingers.

Update: Itā€™s still buildingā€¦ 10 hours laterā€¦ letting it run overnight now. Seems to be compiling its standard library for ARM now.

Update 2: Aaaand it seems Iā€™ve run out of diskspace. Compilation terminated when compiling libm.

/home/pi/compiling_gcc/gcc-arm-none-eabi-9-2020-q2-update/src/newlib/newlib/libm/math/el_hypot.c:18:1: fatal error: error writing to /tmp/ccKwfh0l.s: Read-only file system
   18 | }
      | ^

Iā€™ll see if I can salvage the intermediate build result or have to redo this at least 24 hour procedure with a bigger SD card. Just needs time.

Due to the reason above, this project is currently on hold until my 128GB microSD card arrives on monday. I have no further microSD card other than 16GB ones (which now has a corrupted ext4 filesystem after having been hopelessly overwritten) so I canā€™t complete the compile process. This process seems to have gone through if it wasnā€™t for a lack of space though, so if you have a bigger card yourself, you can try the above steps yourself in parallel to me.

1 Like

Hello!
Do you want to send me your Venmo and I will reimburse you for the larger size SD card? We really appreciate what youā€™re doing, and donā€™t want you to spend your own money helping us on this!

Thanks, see PM. Now Iā€™m up and running with a 128GB microSD card again for the second and hopefully successful run :slight_smile:.

Update: Some 24 hour later and itā€™s compiling its newlib standard-C library using arm-none-eabi-gcc. Still going strongā€¦

Update: All standard libraries have been compiled and itā€™s now doing the final GCC compiler pass.

Update wednesday morning: still doing the final compiler passā€¦

Update wednesday evening: stillā€¦freakingā€¦compiling. itā€™s now compiling libstdc++ and friends in possible combinations for C++ language versions, ARM architectures (v7M, ARMv7E-M, ARMv8, ā€¦) and soft,softfp,hard floating point support. Jeez.

Update thursday morning: STILL compiling. Itā€™s somehow back to compiling gcc.

Update friday, 5am: Itā€™s now building the size optimized (libx_s.a) versions of all its standard libraries, for all ARM archs, FloatingPoint variants and C++ language versions. This got to be most punishing compilation Iā€™ve ever done. Even when I compiled the entire Linux kernel for a MIPS32 device, it only cost 8 hours.

Update friday, 11am: Still compiling libstdc++-v3, this time in the armv8-m.main+fp architecture and float abi hard.

Update friday, 8pm: GCC compilation has finished and itā€™s now compiling GDB and other smaller tools. The end of the tunnel is near.

1 Like

hahahahah, I am actually enjoying this saga, but looking forward to being able to use it even more! Let me know if you need anything else to move things along

1 Like

Noooooooo

rm -rf *.aux *.cp *.cps *.fn *.ky *.log *.pdf *.pg *.toc *.tp *.vr
+2020-11-20:19:42:11 (./build-toolchain.sh:591): make
texi2pdf How-to-build-toolchain.texi
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2019/dev/Debian) (preloaded format=pdfetex)
 restricted \write18 enabled.
entering extended mode
(./How-to-build-toolchain.texi (/usr/share/texmf/tex/texinfo/texinfo.tex
Loading texinfo [version 2018-01-09.11]: pdf, fonts, markup, glyphs,
page headings, tables, conditionals, indexing, sectioning, toc, environments,
defuns, macros, cross references, insertions, localization, formatting,
and turning on texinfo input format.)
(/home/pi/compiling_gcc/gcc-arm-none-eabi-9-2020-q2-update/build-native/build-m
anual/version.texi) [1{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}]
[2] [-1] (Preface) Cross reference values unknown; you must run TeX again.
Chapter 1 [1] [2] [3] [4] Chapter 2 [5]
./How-to-build-toolchain.texi:234: epsf.tex not found, images will be ignored.
@image ...f.tex not found, images will be ignored}
                                                  @global @warnednoepsftrue ...
<argument> ... @image {macos_mojave_about,,,,.png}
                                                  @unskip @hfil
@centersub ...enalty @fi @line {@kern @leftskip #1
                                                  @kern @rightskip }
@\center ...{@hfil @ignorespaces #1@unskip @hfil }
                                                  @let @centersub @relax
l.234 @center @image{macos_mojave_about,,,,.png}

?
./How-to-build-toolchain.texi:234: Emergency stop.
@image ...f.tex not found, images will be ignored}
                                                  @global @warnednoepsftrue ...
<argument> ... @image {macos_mojave_about,,,,.png}
                                                  @unskip @hfil
@centersub ...enalty @fi @line {@kern @leftskip #1
                                                  @kern @rightskip }
@\center ...{@hfil @ignorespaces #1@unskip @hfil }
                                                  @let @centersub @relax
l.234 @center @image{macos_mojave_about,,,,.png}

./How-to-build-toolchain.texi:234:  ==> Fatal error occurred, no output PDF fil
e produced!
Transcript written on How-to-build-toolchain.log.
/usr/bin/texi2dvi: pdfetex exited with bad status, quitting.
make: *** [Makefile:10: How-to-build-toolchain.pdf] Error 1
pi@raspberrypi:~/compiling_gcc/gcc-arm-none-eabi-9-2020-q2-update $ 

It freaking stopped on converting the ā€œHow to build toolchainā€ manualā€¦ Ugh, gotta find a way to skip that check and keep all the previously compiled data without recompiling.

ITā€™S A FREAKING KNOWN BUG AGJGHJKDHGHGHGKHKJGFH Bug #1854471 ā€œ9-2019-q4 toolchain compilation from sources failā€ : Bugs : GNU Arm Embedded Toolchain

Looks like Iā€™m able to continue the build after installing the missing undocumented dependency and with a modified build-toolchain.sh which skips over the already done parts without removing the already done work.

1 Like