How to fix a "[Lp002]: relocation failed with IAR ARM tools?

By : florin
Source: Stackoverflow.com
Question!

I created a small module in assembler for ARM, to be linked together with my bare-metal embedded application. Sometimes when I'm rebuilding the application, I get a "Error[Lp002]: relocation failed: valued out of range or illegal". What is even more puzzling is that I'm getting the error after commenting out some code in a C module.

The IAR manual is vague about 're-ordering the section or the code.' But looking at the assembler files generated by the compiler from my .c files, I see no difference between their section declaration and mine. I actually started my code by stubbing it out in C then taking over the assembled file.

By : florin


Answers

I have found what caused the problem, and how to implement an acceptable workaround. In my assembler source I had a data section and a code section, and the linker was placing them too far apart. I have now moved my variables to the code section (which was placed in RAM anyway because it needed to be running in interrupt context while I was writing to the internal flash) and now I get it to link properly.

This is the question that remains: how to tell the linker to place certain section close to one another?

By : florin


Look in the compiler's documentation. Usually, there is a section about linker command files, which do exactly what you are looking for.

By : swegi


Whenever I get some mysterious linker/compiler error, I do a Rebuild All. About half the time it fixes it. My guess is that some module should have been recompiled, but didn't.

Good luck.

By : Robert


This video can help you solving your question :)
By: admin