Incrementation bug? WTF? [BROKEN COMPILER - SOLVED]

You might try avoiding the problem by applying good programming practice, and declare hue in the function where it's used (instead of using a global variable):

void loop()
{
   static int hue = 0;

   ...

-j

I just would like to know if it's likely that installing avr-gcc from sources will solve the problem?

@kg4wsv

Thanks, I usually apply good programming practices. I just got my arduino today and was experimenting. It's not like it's some kind of a production code. Besides in a one-file, 50 liner it really doesn't matter if you use global variables.

And working around compiler bugs like this is way more evil than bad programming practices.

I don't know if compiling from source would help, if you've got the time and the patience you could try it. I couldn't get the compiler to compile on Ubuntu and I just gave up.

It could be gcc version or configure switches. I adapted PKGBUILDs from tinyos and compiled latest vanilla binutils (2.21) and gcc (4.5.2) and still the same problem.

If you know anything about compiling gcc-avr tell me if you see something suspicious here:

GCC:

  ../configure --disable-libssp \
               --disable-nls \
               --enable-languages=c,c++ \
               --infodir=/usr/share/info \
               --libdir=/usr/lib \
               --libexecdir=/usr/lib \
               --mandir=/usr/share/man \
               --prefix=/usr \
               --target=avr \
               --with-gnu-as \
               --with-gnu-ld \
               --with-as=/usr/bin/avr-as \
               --with-ld=/usr/bin/avr-ld

binutils:

    ../configure --build=$(../config.guess) \
                 --disable-nls \
                 --enable-install-libbfd \
                 --includedir=/usr/$(../config.guess)/include \
                 --infodir=/usr/share/info \
                 --libdir=/usr/lib \
                 --mandir=/usr/share/man \
                 --prefix=/usr \
                 --target=avr \
                 --disable-werror

Just compiled gcc 4.2.3 and it doesn't support atmega328p. One more try... This time 4.4.5.

--- EDIT --- No luck with 4.4.5 either. I suppose there are some patches or configure switches that fix this issue...

And I almost forgot: Thank you all for help, it's very appreciated.

I'd suggest downgrading to version 4.3.5, and applying the set of patches that Debian currently uses. The patches are here (debian/bsdpatches directory):
http://ftp.de.debian.org/debian/pool/main/g/gcc-avr/gcc-avr_4.3.5-1.tar.gz
(this is just the patches, you'll need to download the GCC 4.3.5 source as well from gcc.gnu.org)

Binutils may also need Debian patches.
http://ftp.de.debian.org/debian/pool/main/b/binutils-avr/binutils-avr_2.20.1-1.tar.gz

GCC and BINUTILS with debian patchset work great.

I prepared arch i686 packages:
http://student.if.uj.edu.pl/Filip.Sobalski/binutils-avr-2.20.1-1-i686.pkg.tar.xz
http://student.if.uj.edu.pl/Filip.Sobalski/gcc-avr-4.3.5-1-i686.pkg.tar.xz

For those who use x86_64 here are the PKGBUILDS:
http://student.if.uj.edu.pl/Filip.Sobalski/binutils-avr-debian.tar.gz
http://student.if.uj.edu.pl/Filip.Sobalski/gcc-avr-debian.tar.gz

Thank you!

Good work, let's see if this helps the people having trouble in the other thread.

The x86_64 PKGBUILDS worked for me on my Virtualbox installation.

I force-installed the Binutils package first, and that was enough to get the linker to output correct code. This suggests the problem is with Binutils rather than GCC. Installing the downgraded GCC as well gave more efficient and shorter code, so it is worth doing both.

I tried the x86_64 packages. Binutils compiled fine, but gcc-avr spit the following error:

checking for suffix of object files... configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details.
make[1]: *** [configure-target-libgcc] Error 1
make[1]: Leaving directory `/home/igor/Misc/ArchBuilds/gcc-avr-debian/src/gcc-4.3.5/build'
make: *** [all] Error 2
    Aborting...
??[igor]??[X201]
??[~/Misc/ArchBuilds/gcc-avr-debian]$

I haven't come across this kind of error before (not really a programmer), but if someone knows what this means, please share!

Thanks for preparing the PKGBUILDS dsh1!
-Igor

igor86:
I tried the x86_64 packages. Binutils compiled fine, but gcc-avr spit the following error:

checking for suffix of object files... configure: error: cannot compute suffix of object files: cannot compile See `config.log' for more details. make[1]: *** [configure-target-libgcc] Error 1 make[1]: Leaving directory `/home/igor/Misc/ArchBuilds/gcc-avr-debian/src/gcc-4.3.5/build' make: *** [all] Error 2    Aborting... ??[igor]??[X201] ??[~/Misc/ArchBuilds/gcc-avr-debian]$

I haven't come across this kind of error before (not really a programmer), but if someone knows what this means, please share!

Thanks for preparing the PKGBUILDS dsh1!
-Igor

Post your config.log please. It will be somewhere in src/gcc-4.3.5

stimmer:
I force-installed the Binutils package first, and that was enough to get the linker to output correct code. This suggests the problem is with Binutils rather than GCC. Installing the downgraded GCC as well gave more efficient and shorter code, so it is worth doing both.

I also had to use force installation. Original Arch packages leave some manpages even if uninstalled, but it shouldn't be a problem.

Thanks for this (I've posted on the other thread started by Igor86 as I have the same problem)

Well I get the same compile error as Igor with the x86_64 debian patched gcc-avr =(

Since Stimmer mentions the problem seems to be in the binutils-avr package I'm looking into whether I can patch my currently installed binutils-avr 2.21-1 rather than downgrade that and gcc-avr. BTW dsh's debian patched binutils for x86_64 compiles fine for me but I can't even force install it because of currently installed gcc-avr 4.5.2-1 dependencies... sigh.

So yeah, googling around with all the useful pointers from these threads... will post if I get anywhere with patching 2.21-1... maybe this is an upstream problem and I'm not sure how/whether to send a bug report to the relevant Arch package maintainers yet but thanks for all the help!

I'll attach the offending config.log too for the compile errors which was in src/gcc-4.3.5/build/avr/avrxmega2/libgcc/config.log (wierd problem config can't compute suffix of object files

config.log (13.9 KB)

When I force-installed binutils I also had to tell it to ignore dependencies.

I can't understand why yours won't compile when mine compiled fine. It could be because my install is very fresh and minimal (I only installed the barest minimum to get the IDE running). Have you tried updating your installed packages to the latest versions? The only other difference was that I was compiling as root, which you shouldn't really do (I was running in a virtual machine so was safe).

If it's any help the package it generated is here:
https://docs.google.com/uc?id=0B5O7TidPmOdzNGYxMGRiNmUtYzFjNC00NGQyLTlhNDYtYmVmODJiMDk3OTlm&export=download&hl=en
(I probably won't keep that download around for long...)

mkpetch:
Thanks for this (I've posted on the other thread started by Igor86 as I have the same problem)

Well I get the same compile error as Igor with the x86_64 debian patched gcc-avr =(

Since Stimmer mentions the problem seems to be in the binutils-avr package I'm looking into whether I can patch my currently installed binutils-avr 2.21-1 rather than downgrade that and gcc-avr. BTW dsh's debian patched binutils for x86_64 compiles fine for me but I can't even force install it because of currently installed gcc-avr 4.5.2-1 dependencies... sigh.

So yeah, googling around with all the useful pointers from these threads... will post if I get anywhere with patching 2.21-1... maybe this is an upstream problem and I'm not sure how/whether to send a bug report to the relevant Arch package maintainers yet but thanks for all the help!

I'll attach the offending config.log too for the compile errors which was in src/gcc-4.3.5/build/avr/avrxmega2/libgcc/config.log (wierd problem config can't compute suffix of object files

This is the problem "Fatal error: unknown MCU: avrxmega2"

I'll look into it further when I find some time.

Yup, force ignore dependencies ie pacman -Udf binutils-avr-2.20.1-1-x86_64.pkg.tar.xz let me try binutils-avr from dsh with the patches applied :blush:

It works! I've compiled and uploaded the Blink sketch without any additional global var declared and the sketch runs fine now. So I guess I don't need the patched gcc-avr for the moment. The problem is narrowed down to the binutils package it seems.

(no luck of course finding patches for binutils-avr 2.21)

Awesome!

I pacman -Udf'ed binutils-avr and the blink sketch works fine now (at least on the Uno)! So, no need for gcc-avr (Arch package works fine), we just need these binutils-avr!

Thanks heaps to everyone who spent time to look into these problems. I'll send a message to the Arch User Repository for the arduino package (the package for x86_64).

-Igor

BTW I just successfully compiled the patched gcc-avr 4.3.5 so dsh your x86_64 PKGBUILD is fine... the binutils must be force installed before building gcc-avr 8)

Still I'm sticking with the official Arch gcc 4.5.2 for now. Very happy to be Arduinoing on Arch thanks to the assistance of this forum!

Has someone reported this bug upstream (to the avr-gcc developers) ?

Regards, PyroPeter

Since the problem was solved by applying Debian patches I am sure the Debian package maintainer will have already reported any bugs to the main GCC / binutils teams. Patches very often aren't applied to the main codebase straight away in case they break something somewhere else.

But the person maintaining Arch avr binutils probably ought to know that there are patches they should be applying.

Did someone inform the Arch maintainer for binutils and gcc-avr?
It will probably work better if we would know which patch exactly solves the problem (I only took a look inside debian's binutils package, it contained about 35 patches)
I would also be interested in the upstream bug reports.

I don't know if this was mentioned already, but the bug only occours in the original GUI included in the arduino package. I had no problems using arduide/arduino-ide.

@dsh: could you upload your packages to the AUR?

Since previous links are dead and some people asked me to upload the PKGBUILDs to AUR...

Here is the link to the PKGBUILDs, it will be up until I find time to finally make a proper homepage:

As far as AUR is concerned, feel free to submit them to AUR in your name. I don't have time to maintain them let alone fix them so they are properly written and adhere to arch guidelines. They are just quick hacks.