Loading...
Pages: [1]   Go Down
Author Topic: bug with relaxation on mega2560  (Read 830 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi,
i discovered a bug with mega2560 and ide 1.0.3 (ubuntu 12.10)
compiling a program with a size of ~33kb and adding Serial.x stuff makes the linker throw the following error:

/home/--/arduino-1.0/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../avr/lib/avr6/crtm2560.o: In function `__bad_interrupt':
../../../../crt1/gcrt1.S:193: relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_46' defined in .text section in /home/--/arduino-1.0/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../avr/lib/avr6/crtm2560.o

removing the --relax linker option fixes that (beginning at line 193 in Compiler.java).

furthermore i dont know why exactly relaxation is enabled on mega2560?
from the avr-gcc description:
Code:
Enables linker relaxations. By default, the linker links functions will a full CALL statement,
which is wasteful if two functions are near each other.
Relaxations will do more in the future, but currently (AFAIK) just replace CALL
statements with RCALL where possible to save a few bytes.
but afaik rcall can only jump to regions +-4kib away! the mega2560 has 256kib flash,
im in doubt about the compiler can optimize every call to rcall to within +-4kib limit.
am i overlooking something?

side hint: hard coding such exception seems not the right solution to me (i searched and grepped a long bit).
Logged

Global Moderator
Melbourne, Australia
Offline Offline
Shannon Member
*****
Karma: 226
Posts: 14097
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Is this the same issue?

https://github.com/arduino/Arduino/issues/1071
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

seems so.
i attached a patched version (current git version) of the ide without the --relax parameter at linker stage.
(just copy to /lib path inside the arduino directory)
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 8
Posts: 3532
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here's a link to the issue for which we included the relax compiler argument: https://code.google.com/p/arduino/issues/detail?id=729
Logged

Ayer, Massachusetts, USA
Offline Offline
Edison Member
*
Karma: 28
Posts: 1145
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If the interrupt functions can only be a certain distance from 0, then a way to solve the problem and still use the linker relax, is to create a new section that the linker puts into memory before the normal text section and put the interrupt code into that section, so the linker has a better chance of using the appropriate jump.  Looking at the binutils source (probably a few months old), the avr port has several special sections:

  • .progmem.gcc* and .progmem for code that must be in the lower 64k of progmem
  • .lowtext* for code that must be in the lower 128k of progmem

A quick glance in the 4.7 sources doesn't seem to have a function attribute to put a function into the .progmem or .lowtext sections, but you could use the section attribute to hardwire the function.
« Last Edit: January 02, 2013, 05:13:33 pm by MichaelMeissner » Logged

Pages: [1]   Go Up
Print
 
Jump to: