http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58082
Bug ID: 58082 Summary: avr-gcc vector table relocation truncation error with -mrelax option Product: gcc Version: unknown Status: UNCONFIRMED Severity: major Priority: P3 Component: other Assignee: unassigned at gcc dot gnu.org Reporter: acmeexhibits at gmail dot com Created attachment 30613 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30613&action=edit pads the space between the vector table and text area to move the rjmp/jmp transition. When the attached code compiles properly, we get this vector table: 00000000 <__vectors>: 0: 0c 94 08 08 jmp 0x1010 ; 0x1010 <__ctors_end> 4: 0c 94 12 08 jmp 0x1024 ; 0x1024 <__bad_interrupt> 8: 0c 94 12 08 jmp 0x1024 ; 0x1024 <__bad_interrupt> c: 0c 94 12 08 jmp 0x1024 ; 0x1024 <__bad_interrupt> 10: 0c 94 12 08 jmp 0x1024 ; 0x1024 <__bad_interrupt> 14: 0c 94 12 08 jmp 0x1024 ; 0x1024 <__bad_interrupt> 18: 0c 94 12 08 jmp 0x1024 ; 0x1024 <__bad_interrupt> 1c: 0c 94 12 08 jmp 0x1024 ; 0x1024 <__bad_interrupt> 20: 0c 94 12 08 jmp 0x1024 ; 0x1024 <__bad_interrupt> 24: ff c7 rjmp .+4094 ; 0x1024 <__bad_interrupt> 26: 00 00 nop 28: fd c7 rjmp .+4090 ; 0x1024 <__bad_interrupt> 2a: 00 00 nop 2c: fb c7 rjmp .+4086 ; 0x1024 <__bad_interrupt> 2e: 00 00 nop I believe the -mrelax option says to use rjmp (relative jumps) when possible, which for the Atmel 2560 chip is +/- 4k. We can see that the jumps for vectors 0 to 8 are too far for a relative jump so the linker/compiler switches to jmp, an absolute jump. For reasons I don't understand, if the __bad_interrupt label is 2 bytes farther away, the linker cannot figure out how to make vector 9 a jmp. Instead it generates the error message: /usr/lib/gcc/avr/4.7.2/../../../avr/lib/avr6/crtm2560.o: In function `__bad_interrupt': ../../../../crt1/gcrt1.S:195: relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_9' defined in .text section in /usr/lib/gcc/avr/4.7.2/../../../avr/lib/avr6/crtm2560.o There are bands where the rjmp/jmp transition works and other bands where it doesn't work. Omitting the -mrelax flag does solve the problem as only jmp instructions are generated. Thankfully, source code that irritates the bug is trivial