avr-gcc bug?

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The toolchain is "AVR 8-bit Toolchain v3.62 – Windows", which I just got from:
https://www.microchip.com/mymicr...

 

#include <stdio.h>
volatile uint8_t vv;
static __attribute__((format(printf, 1, 2)))
     void fatalError(const char* format, ...) {
  va_list args;
  va_start(args, format);
  vprintf(format, args);
  va_end(args);
  while (1);
}
static __attribute__((__noinline__)) void func(void) {
  if (vv)
    fatalError("Error %u %u", vv, vv);
}
int main(void) {
  func();
  fatalError("Error %u", vv);
}
\tmp\avrgcc3.6.2\avr8-gnu-toolchain-win32_x86\bin\avr-gcc -fwhole-program -Wl,--relax,--gc-sections -Os -mmcu=atmega328p -o main.elf main.c
\tmp\avrgcc3.6.2\avr8-gnu-toolchain-win32_x86\bin\avr-objdump -h -S main.elf > main.lst
grep fatalError main.lst | grep -e rjmp -e rcall
  b8:	ff cf       	rjmp	.-2      	; 0xb8 <fatalError+0x18>
  da:	e2 cf       	rjmp	.-60     	; 0xa0 <fatalError>
  f0:	d7 df       	rcall	.-82     	; 0xa0 <fatalError>

So it pushes the fatalError parameters onto the stack, and then either calls it or jumps it. Well, the stack pointer that the fatalError entry is obviously going to be different. So, this whole thing cannot possibly work. (And it doesn't in the rjmp case.)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This does seem to be a linker bug when --relax is used. I was able to replicate it with avr-gcc 5.4.0. What version of avr-gcc does "AVR 8-bit Toolchain v3.62" use?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

\tmp\avrgcc3.6.2\avr8-gnu-toolchain-win32_x86\bin\avr-gcc --version
avr-gcc (AVR_8_bit_GNU_Toolchain_3.6.2_1759) 5.4.0

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Isn't that an 'old' version of GCC?  I think its up to V4.xx or v5.xx now......

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Microchip numbers are different. The latest Microchip seems to be 3.6.2. That is what I tried. But the avr-gcc that comes with Microchip's 3.6.2 is actually 5.4.0.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tried a couple of others.

 

This one is still good:
\WinAVR-20100110\bin\avr-gcc --version
avr-gcc (WinAVR 20100110) 4.3.3
Copyright (C) 2008 Free Software Foundation, Inc.

 

This one is already bad:
\AtmelAvr8V3.4.1\bin\avr-gcc --version
avr-gcc (AVR_8_bit_GNU_Toolchain_3.4.1_798) 4.6.2
Copyright (C) 2011 Free Software Foundation, Inc.