arduino / ArduinoCore-avr

The Official Arduino AVR core
https://www.arduino.cc
1.22k stars 1.04k forks source link

64k problems: trampolines not enabled #176

Open WestfW opened 10 years ago

WestfW commented 10 years ago

My understanding is that pointers to functions (which are used somewhat commonly in C++?) are done on AVRs with more than 64k memory by having the 16bit pointers point to "trampolines", which are essentially long jumps placed into the first 64k of memory. So things that call functions via a pointer are always directed at one of these trampolines (via 16bit pointer), and the trampoline jumps to the actual function which can be anywhere in the ~256k of flash space (on a mega2560.)

Unfortunately, to enable this, you are supposed to provide the "-mrelax" option to the gcc compiler, and something similar to the linker, and the current Arduino IDEs don't do that.

This may be fixed or different in the new (1.5.7) avr-gcc toolchain.

matthijskooijman commented 10 years ago

Do you happen to have a test sketch that displays this problem? If so, I can see if it is still broken with the latest toolchain.

WestfW commented 10 years ago

No; actually, I noticed the missing -relax when debugging problems that turned out to be due to https://github.com/arduino/Arduino/issues/2226 It looks like 1.0.5 includes --relax for the link, but not for the compiles. I'm having troubles coming up with code that generates any trampolines at all :-( I'll keep hunting. (Also, this is likely to be masked by https://github.com/arduino/Arduino/issues/1067 which prevents global constructors past 64k (128k?) from working.)

On the bright side, this is apparently only a problem with chips that have more than 128k of memory, since avr-gcc uses word addresses for pointers to code.