bug with relaxation on mega2560

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.