问题
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.
回答1:
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.
回答2:
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?
回答3:
Look in the compiler's documentation. Usually, there is a section about linker command files, which do exactly what you are looking for.
来源:https://stackoverflow.com/questions/1208312/how-to-fix-a-lp002-relocation-failed-with-iar-arm-tools