Search code examples
assemblyembeddedlinkerarmiar

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


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.


Solution

  • 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?