AVR: Relocation truncated to fit

1.2k views Asked by At

I'm new to this community, in that I've never before created an account and asked a question, but I use this site all the time to solve my programming woes. So thank you! This time, though, I could not find another question matching my exact needs. If this is a repeat, I apologize.

I am on elementary OS 0.2 (Luna), a derivative of Ubuntu 12.04. I am using the avr-gcc library to compile a program for an ATmega32u4 microprocessor. I've compiled this program several times as I developed it, but until now I had not received this error. I'm pasting it below.

/usr/lib/gcc/avr/4.5.3/../../../avr/lib/avr5/libc.a(log.o):../../../libm/fplib/log.S:100: relocation truncated to fit: R_AVR_13_PCREL against symbol `__addsf3' defined in .text section in /usr/lib/gcc/avr/4.5.3/avr5/libgcc.a(_addsub_sf.o)
/usr/lib/gcc/avr/4.5.3/../../../avr/lib/avr5/libc.a(modf.o):../../../libm/fplib/modf.S:90: relocation truncated to fit: R_AVR_13_PCREL against symbol `__subsf3' defined in .text section in /usr/lib/gcc/avr/4.5.3/avr5/libgcc.a(_addsub_sf.o)
collect2: ld returned 1 exit status
make: *** [main.elf] Error 1

In short, I have no clue what this refers to. My program contains a multitude of files, so I can't exactly post the whole thing here; instead, I would be interested in a generalized answer to the following questions:

  1. What is a "relocation truncated to fit" error? I've read that it has to do with accessing memory that's too far away, but how does that actually happen within my C program?
  2. What is R_AVR_13_PCREL? It seems to be inherent to the avr-gcc library; what aspect of my program might refer to such a variable?
  3. The only general C header I'm including is math.h; the other files are my own. I know there is a funky flag for math.h that should be placed in the Makefile; I believe it is -lm. But I've tried this to no avail.

Thank you very much, everyone. I appreciate the help of this community.

1

There are 1 answers

0
Sam Hartman On

See this for a discussion of the relocated to fit error. I've never worked with avr, but from the relocation type r_avr_13_pcrel, I'd guess that it means that your instruction has a 13-bit address relative to the program counter. That means that the data (presumably that you're calling log on) nedes to be no more than 13-bits away from the log code. 13 bits is only 8192 bytes.
So, something you're trying to take the address of is more than 8 kb away from the instruction where it's used. Unfortunately, the instruction in question is within libm, not your code, so it may be more tricky to fix. Also, note that since it's PC-relative, you probably only have 4096 bytes, because you have a sign bit so you can reference locations both before and after the address.

So, this is probably related to code size of your executable.