There appears to be some sort of regression with avr-gcc 4.5.0. When compiling a sketch for the atmega1280 everything works except for serial output. The fix is to revert to 4.3.x The issue is documented here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1276727004/15 and http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1250084886 Everything else (that I've tested) works fine. This issue appears to *only* affect the atmega1280 chip. As the atmega328 chip does not exhibit this bug when doing serial output.
Did you read this, before opening the PR? http://gcc.gnu.org/bugs/ Please provide all the required information, otherwise nobody will be able to look at the issue.
* the exact version of GCC; avr-gcc-c++-4.5.0-1.fc13.x86_64 avr-gcc-4.5.0-1.fc13.x86_64 * the system type; Compiled on 2.6.33.5-112.fc13.x86_64 but the target was an atmega1280 * the options given when GCC was configured/built; :avr-g++ -v Using built-in specs. COLLECT_GCC=/usr/bin/avr-g++ COLLECT_LTO_WRAPPER=/usr/libexec/gcc/avr/4.5.0/lto-wrapper Target: avr Configured with: ../gcc-4.5.0/configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --target=avr --enable-languages=c,c++ --disable-nls --disable-libssp --with-system-zlib --enable-version-specific-runtime-libs --with-pkgversion='Fedora 4.5.0-1.fc13' --with-bugurl=https://bugzilla.redhat.com/ Thread model: single gcc version 4.5.0 (Fedora 4.5.0-1.fc13) * the complete command line that triggers the bug; * the compiler output (error messages, warnings, etc.); and * the preprocessed file (*.i*) that triggers the bug, generated by adding -save-temps to the complete compilation command, or, in the case of a bug report for the GNAT front end, a complete set of source files (see below). It's on my machine at home so I'll have to get this information for you at a later time.
Can you also try on a FSF released GCC rather than one that has been modified by the Fedora project?
(In reply to comment #3) > Can you also try on a FSF released GCC rather than one that has been modified > by the Fedora project? That might be harder... I do see from the two forum posts that the bug persists in GCC from Mandrake, OpenSuse, Ubuntu, and Mac OSX. I'll see what I can come up with.
* the complete command line that triggers the bug; avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega1280 -DF_CPU=16000000L -DARDUINO=18 -I/home/bakers/arduino-0018/hardware/arduino/cores/arduino /tmp/build4637782385548929954.tmp/sketch_jun21a.cpp -o/tmp/build4637782385548929954.tmp/sketch_jun21a.cpp.o * the compiler output (error messages, warnings, etc.); and I don't get any? Not sure if this is right, but it appears to compile 100% clean. * the preprocessed file (*.i*) that triggers the bug, generated by adding -save-temps to the complete compilation command, or, in the case of a bug report for the GNAT front end, a complete set of source files (see below). If I add -v -save-temps I do not get any *.i* files created. Perhaps my syntax is wrong? avr-g++ -v -save-temps -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega1280 -DF_CPU=16000000L -DARDUINO=18 -I/home/bakers/arduino-0018/hardware/arduino/cores/arduino /tmp/build4637782385548929954.tmp/sketch_jun21a.cpp -o/tmp/build4637782385548929954.tmp/sketch_jun21a.cpp.o
For the record, the code I'm attempting to compile is extremely simple. Might explain why it compiles so cleanly: ----------------------------------------------------------- void setup() { Serial.begin(9600); } void loop() { Serial.println("Hello world"); delay(1000); }
>*.i* It should have produced a file that ended in .ii .
Here is the full command the arduino ide generates when it compiles code. I just took the last command for sketch_jun21a.cpp.o (my code) and added the -v and -save-temps. avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -mmcu=atmega1280 -DF_CPU=16000000L -DARDUINO=18 -I/home/bakers/arduino-0018/hardware/arduino/cores/arduino /home/bakers/arduino-0018/hardware/arduino/cores/arduino/wiring.c -o/tmp/build4637782385548929954.tmp/wiring.c.o avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -mmcu=atmega1280 -DF_CPU=16000000L -DARDUINO=18 -I/home/bakers/arduino-0018/hardware/arduino/cores/arduino /home/bakers/arduino-0018/hardware/arduino/cores/arduino/wiring_analog.c -o/tmp/build4637782385548929954.tmp/wiring_analog.c.o avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -mmcu=atmega1280 -DF_CPU=16000000L -DARDUINO=18 -I/home/bakers/arduino-0018/hardware/arduino/cores/arduino /home/bakers/arduino-0018/hardware/arduino/cores/arduino/pins_arduino.c -o/tmp/build4637782385548929954.tmp/pins_arduino.c.o avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -mmcu=atmega1280 -DF_CPU=16000000L -DARDUINO=18 -I/home/bakers/arduino-0018/hardware/arduino/cores/arduino /home/bakers/arduino-0018/hardware/arduino/cores/arduino/wiring_shift.c -o/tmp/build4637782385548929954.tmp/wiring_shift.c.o avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -mmcu=atmega1280 -DF_CPU=16000000L -DARDUINO=18 -I/home/bakers/arduino-0018/hardware/arduino/cores/arduino /home/bakers/arduino-0018/hardware/arduino/cores/arduino/wiring_digital.c -o/tmp/build4637782385548929954.tmp/wiring_digital.c.o avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -mmcu=atmega1280 -DF_CPU=16000000L -DARDUINO=18 -I/home/bakers/arduino-0018/hardware/arduino/cores/arduino /home/bakers/arduino-0018/hardware/arduino/cores/arduino/wiring_pulse.c -o/tmp/build4637782385548929954.tmp/wiring_pulse.c.o avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -mmcu=atmega1280 -DF_CPU=16000000L -DARDUINO=18 -I/home/bakers/arduino-0018/hardware/arduino/cores/arduino /home/bakers/arduino-0018/hardware/arduino/cores/arduino/WInterrupts.c -o/tmp/build4637782385548929954.tmp/WInterrupts.c.o avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega1280 -DF_CPU=16000000L -DARDUINO=18 -I/home/bakers/arduino-0018/hardware/arduino/cores/arduino /home/bakers/arduino-0018/hardware/arduino/cores/arduino/HardwareSerial.cpp -o/tmp/build4637782385548929954.tmp/HardwareSerial.cpp.o avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega1280 -DF_CPU=16000000L -DARDUINO=18 -I/home/bakers/arduino-0018/hardware/arduino/cores/arduino /home/bakers/arduino-0018/hardware/arduino/cores/arduino/Print.cpp -o/tmp/build4637782385548929954.tmp/Print.cpp.o avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega1280 -DF_CPU=16000000L -DARDUINO=18 -I/home/bakers/arduino-0018/hardware/arduino/cores/arduino /home/bakers/arduino-0018/hardware/arduino/cores/arduino/WMath.cpp -o/tmp/build4637782385548929954.tmp/WMath.cpp.o avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega1280 -DF_CPU=16000000L -DARDUINO=18 -I/home/bakers/arduino-0018/hardware/arduino/cores/arduino /home/bakers/arduino-0018/hardware/arduino/cores/arduino/main.cpp -o/tmp/build4637782385548929954.tmp/main.cpp.o avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega1280 -DF_CPU=16000000L -DARDUINO=18 -I/home/bakers/arduino-0018/hardware/arduino/cores/arduino /home/bakers/arduino-0018/hardware/arduino/cores/arduino/Tone.cpp -o/tmp/build4637782385548929954.tmp/Tone.cpp.o avr-ar rcs /tmp/build4637782385548929954.tmp/core.a /tmp/build4637782385548929954.tmp/wiring.c.o avr-ar rcs /tmp/build4637782385548929954.tmp/core.a /tmp/build4637782385548929954.tmp/wiring_analog.c.o avr-ar rcs /tmp/build4637782385548929954.tmp/core.a /tmp/build4637782385548929954.tmp/pins_arduino.c.o avr-ar rcs /tmp/build4637782385548929954.tmp/core.a /tmp/build4637782385548929954.tmp/wiring_shift.c.o avr-ar rcs /tmp/build4637782385548929954.tmp/core.a /tmp/build4637782385548929954.tmp/wiring_digital.c.o avr-ar rcs /tmp/build4637782385548929954.tmp/core.a /tmp/build4637782385548929954.tmp/wiring_pulse.c.o avr-ar rcs /tmp/build4637782385548929954.tmp/core.a /tmp/build4637782385548929954.tmp/WInterrupts.c.o avr-ar rcs /tmp/build4637782385548929954.tmp/core.a /tmp/build4637782385548929954.tmp/HardwareSerial.cpp.o avr-ar rcs /tmp/build4637782385548929954.tmp/core.a /tmp/build4637782385548929954.tmp/Print.cpp.o avr-ar rcs /tmp/build4637782385548929954.tmp/core.a /tmp/build4637782385548929954.tmp/WMath.cpp.o avr-ar rcs /tmp/build4637782385548929954.tmp/core.a /tmp/build4637782385548929954.tmp/main.cpp.o avr-ar rcs /tmp/build4637782385548929954.tmp/core.a /tmp/build4637782385548929954.tmp/Tone.cpp.o avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega1280 -DF_CPU=16000000L -DARDUINO=18 -I/home/bakers/arduino-0018/hardware/arduino/cores/arduino /tmp/build4637782385548929954.tmp/sketch_jun21a.cpp -o/tmp/build4637782385548929954.tmp/sketch_jun21a.cpp.o avr-gcc -Os -Wl,--gc-sections -mmcu=atmega1280 -o /tmp/build4637782385548929954.tmp/sketch_jun21a.cpp.elf /tmp/build4637782385548929954.tmp/sketch_jun21a.cpp.o /tmp/build4637782385548929954.tmp/core.a -L/tmp/build4637782385548929954.tmp -lm avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 /tmp/build4637782385548929954.tmp/sketch_jun21a.cpp.elf /tmp/build4637782385548929954.tmp/sketch_jun21a.cpp.eep avr-objcopy -O ihex -R .eeprom /tmp/build4637782385548929954.tmp/sketch_jun21a.cpp.elf /tmp/build4637782385548929954.tmp/sketch_jun21a.cpp.hex I don't get any *.ii files from that though :(
I don't get any different output than Scott, no .ii file, but I have exactly the same problem on Fedora 13 64bit. avrdude-5.10-2.fc13.x86_64 avr-gcc-c++-4.5.0-2.fc13.x86_64 avra-1.2.3-4.fc13.x86_64 avr-gcc-4.5.0-2.fc13.x86_64 avr-binutils-2.20-2.fc13.x86_64 avr-libc-1.6.7-2.fc13.noarch avr-gdb-7.1-1.fc13.x86_64 [root@george george]# avr-g++ -v Using built-in specs. COLLECT_GCC=/usr/bin/avr-g++ COLLECT_LTO_WRAPPER=/usr/libexec/gcc/avr/4.5.0/lto-wrapper Target: avr Configured with: ../gcc-4.5.0/configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --target=avr --enable-languages=c,c++ --disable-nls --disable-libssp --with-system-zlib --enable-version-specific-runtime-libs --with-pkgversion='Fedora 4.5.0-2.fc13' --with-bugurl=https://bugzilla.redhat.com/ Thread model: single gcc version 4.5.0 (Fedora 4.5.0-2.fc13) [root@george george]# If I downgrade to: avr-gcc-c++-4.3.3-2.fc11.x86_64 avr-gcc-4.3.3-2.fc11.x86_64 Everything works fine!
Created attachment 21525 [details] preprocessor output for augi.cpp I have the same problem on Fedora 13, avr-gcc-c++-4.5.1-1.fc13.x86_64 avr-gcc-4.5.1-1.fc13.x86_64 avr-binutils-2.20-2.fc13.x86_64 avr-libc-1.6.7-2.fc13.noarch Using built-in specs. COLLECT_GCC=/usr/bin/avr-g++ COLLECT_LTO_WRAPPER=/usr/libexec/gcc/avr/4.5.1/lto-wrapper Target: avr Configured with: ../gcc-4.5.1/configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --target=avr --enable-languages=c,c++ --disable-nls --disable-libssp --with-system-zlib --enable-version-specific-runtime-libs --with-pkgversion='Fedora 4.5.1-1.fc13' --with-bugurl=https://bugzilla.redhat.com/ Thread model: single gcc version 4.5.1 (Fedora 4.5.1-1.fc13) avr-g++ -c -g -w -v -fno-exceptions -mmcu=atmega1280 -DF_CPU=16000000L augi.cpp -oaugi.cpp.o avr-g++ -g -v -Wall -mmcu=atmega1280 -Wl,-Map,augi.map -o augi.elf augi.cpp.o avr-objcopy -v -j .text -j .data -O ihex augi.elf augi.hex The source file is a simplified version of the arduino sketch of comment#6 (got rid of the arduino specific stuff and the interrupt code), the problem is triggered by the second "Serial" Dummy Object. With avr-g++ 4.5.1, I don't get any output, with avr-gcc-c++-4.3.3-3.fc13.x86_64 & avr-gcc-4.3.3-3.fc13.x86_64 I get a stream of 'A' as expected.
Created attachment 21541 [details] Suggested patch Tested with the example. Not thoroughly tested, though.
See http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=736616 This is (IMO) a bug in the __do_global_ctors in gcc/config/avr/libgcc.S When support for 24-bit flash pointers was added in edit http://gcc.gnu.org/viewcvs?view=revision&revision=143306 R20 was used to hold the extra 8 bits of address. But R20 is NOT preserved by called functions according to the AVR C calling conventions, and indeed the class initialization code ends up using R20 if there are sufficient fields to initialize. The attached patch uses R15 instead, and appears to work, but I'm not sure of the implications... I tried to change the summary, but of course it won't let me. I think this is a more serious problem than the initial problem indicates...
(In reply to comment #12) > See http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=736616 > This is (IMO) a bug in the __do_global_ctors in gcc/config/avr/libgcc.S > When support for 24-bit flash pointers was added in edit > http://gcc.gnu.org/viewcvs?view=revision&revision=143306 > R20 was used to hold the extra 8 bits of address. But R20 is NOT preserved by > called functions according to the AVR C calling conventions, and indeed the > class initialization code ends up using R20 if there are sufficient fields to > initialize. The attached patch uses R15 instead, and appears to work, but I'm > not sure of the implications... > > I tried to change the summary, but of course it won't let me. I think this is > a more serious problem than the initial problem indicates... > Duplicate of bug #45263. Closing this one as a dup, as the test case in bug #45263 is simpler. *** This bug has been marked as a duplicate of 45263 ***