Design, Build, Test, Iterate

Global constructor bug in GCC 4.5.1

I’ve recently returned to programming my Seeeduino Mega (ATmega1280) for my tricopter. Yesterday I discovered that every time I included serial code in the sketch, the sketch seemed to freeze as if it was not running the loop(). After several hours, I identified the source of the bug to be in the gcc-avr compiler that Linux uses. Note that this bug does not affect the ATmega328p of the Duemilanove.

I am compiling and uploading sketches from the command line (another small adventure I will post about later) with Arduino 0018 on 64-bit Arch Linux.

This blog post explains the bug pretty well. Until an official patch comes out, there are two workarounds: downgrade to GCC 4.3.3 or make the proposed patch. I tried installing the 4.3.3 version from archived sources but ran into other bugs that did not let me compile.

This GCC Bugzilla report describes the patch with proper line numbers. After building the patched source and installing the package, I was able to compile and upload fully-functioning ATmega1280 sketches.

Here is the compiled package for 64-bit Arch Linux.



Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>