Closed GoogleCodeExporter closed 8 years ago
Hi, another arducopter team member here.
Here is a patch to the Arduino repository which passes the linker the --relax
flag when building for the atmega2560. I also updated a few things in the
example sketch to be compatible with API changes in the repository for Arduino
1.0.
Original comment by pat@moreproductive.org
on 1 Dec 2011 at 12:45
Attachments:
Thanks for the report. Is there any reason not to apply this flag when
compiling for other processors too? Any potential pitfalls you can imagine /
have run to with it? (This seems like the kind of thing that has potentially
subtle but problematic effects, so I'd like to have a better understanding /
confidence that it won't break stuff before applying it.)
Original comment by dmel...@gmail.com
on 2 Dec 2011 at 10:10
The relax flag instructs the linker it is OK for indirect jumps to use
trampolines to access memory outside the range of a standard jump instruction.
This only comes up on devices with more than 128k of program memory (so, in our
case, only the 2560).
The Avr-libc site has an FAQ on this topic [1]. There are other discussions of
various quality which might help [2] [3].
The linker always calculates static long jumps properly, but without --relax,
fails to resolve a long jump properly when using function pointers. This is an
issue when a C++ vtable is located low in memory in .rodata, but the target
method is in high memory (more than 128k away). In the example sketch, the
extremely large collection of PSTRs separate the vtable from .text by 128k, but
it turns out that the ArduPilot codebase is now large enough that certain
methods end up in high memory.
".rodata._ZTV7AP_VarTIaE+0xc): warning: internal error: out of range error"
So, this cryptic warning really means that the linker discovered the value
needed in the AP_Var class vtable (an array of 16 bit addresses) is larger than
the 16 bits available. I believe that, in addition to giving this warning, the
linker truncates the address to fit in 16 bits, so the result is a virtual
method call will jump to an address 128k below the method location.
To my knowledge, the only undesirable effect of --relax is to slightly expand
code size by adding trampolines. There exists a sentiment that --relax may be
buggy, because bugs have been found in it in the past. However, there aren't
any open bugs related to --relax at the moment at [4] or [5]. We require
--relax to generate correct code for the current ArduPilot trunk.
I hope this helps. Please let me know if you want me to do more research or
testing.
Best
Pat
[1] http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_funcptr_gt128kib
[2] http://old.nabble.com/May-avr-gcc-emit-EIJMP-EICALL--td32641131.html
[3] http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=106714
[4] http://www.nongnu.org/avr-libc/bugs.html
[5] https://savannah.nongnu.org/bugs/?group=avr-libc
Original comment by pat@moreproductive.org
on 2 Dec 2011 at 11:07
Hi, i'm having exactly this problem. However, my skills lies within the field
of System & Control rather than programming in Arduino. How do I use a
patch-file?
Thanks!
Original comment by erica...@gmail.com
on 5 Dec 2011 at 10:44
@erica,
Well..this file has been found which has a compiled Arduino ide which includes the ability to add some compiler linker options to the preferences.txt file. Check out the readme.txt file for instructions.
http://www.mostlysoftware.com/files/ArduinoIDE/
I have no idea who built this code. I scanned it for viruses and didn't find any but no promises.
Original comment by rmackay...@gmail.com
on 5 Dec 2011 at 2:42
Erica,
This is a patch on the Arduino project sources. You would have to follow
instructions here to build the IDE locally:
http://code.google.com/p/arduino/wiki/BuildingArduino
I have distributed a copy of Arduino-0022 with these changes for use by the
ardupilot developers. The file is called 'arduino-0022-relaxpatch.zip'
http://code.google.com/p/ardupilot-mega/downloads/list
Best
Pat
Original comment by pat@moreproductive.org
on 5 Dec 2011 at 4:11
https://github.com/arduino/Arduino/commit/fa4ab4f6ab07117dd95ad284b2b9afff5c81c3
76
Thanks for the comprehensive explanation and links!
This seems a good use case for why we need per-board compiler and linker
options, but hard-coding it seems reasonable for now.
Original comment by dmel...@gmail.com
on 5 Dec 2011 at 10:26
[deleted comment]
I have a problem that appears only with the --relax flag.
Removing it from Arduino Compiler.java source solve my problem.
Here is the error that only appears with the --relax flag:
Arduino: 1.5.4 (Windows 7), Board: "Arduino Mega 2560 or Mega ADK"
c:/users/gregor/desktop/arduino/arduino-1.5.4-r2-windows/arduino-1.5.4/hardware/
tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr6/crtm2560.o: In
function `__vector_default':
(.vectors+0x28): relocation truncated to fit: R_AVR_13_PCREL against symbol
`__vector_10' defined in .text section in
c:/users/gregor/desktop/arduino/arduino-1.5.4-r2-windows/arduino-1.5.4/hardware/
tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr6/crtm2560.o
Original comment by adg...@gmail.com
on 24 Oct 2013 at 6:29
Here is a fix:
http://forum.arduino.cc//index.php?topic=140108.msg1440380#msg1440380
Original comment by adg...@gmail.com
on 24 Oct 2013 at 7:31
Original issue reported on code.google.com by
rmackay...@gmail.com
on 27 Nov 2011 at 6:33Attachments: