1
votes

There is a project which successfully compiled linked and run on the device. But after telling the linker that it should put the part of the application code to the ROM memory, instead of SDRAM, I am getting the following error at the linking step:

Error[Lp002]: relocation failed: value out of range or illegal: 0x60000545 Kind : R_ARM_PREL31[0x2a] Location: 0xa0000030 Module: I:\Project\Debug\Obj\fileOper.o Section: 128 (.ARM.exidx) Offset: 0x0 Target : 0x00000574 "SECTION_FILEOP_87" Module: I:\Project\Debug\Obj\fileOper.o Section: 104 (SECTION_FILEOP) Offset: 0x4f4

I have read the C/C++ guide from IAR. But it doesn't provide well enough explanations regarding this error. So even reading the manual I can't get the reason of this error. Can anybody help to resolve this problem? Actually the IAR C/C++ developers guide says:

For each instruction that cannot be relocated correctly, ILINK will generate a relocation error. This can occur for instructions where the target is out of reach or is of an incompatible type, or for many other reasons. Then it provides the error as an example which is different than in my case.

EDIT 1: I have created the small project which reproduce the same errors and it consists of fileOper.cpp and main.cpp files only.

The ICF file used to tell linker how to put sections to memory:

define symbol intvec_start = 0x10000000;

/-Memory Regions-/

/-FLASH ROM-/

define symbol FLASH_ROM_start = 0x00000000;

define symbol FLASH_ROM_end = 0x0007FFFF;

/*Internal RAM*/

define symbol RAM_start = 0x10000000;

define symbol RAM_end = 0x10017FFF;

/*SDRAM*/

define symbol SDRAM_start = 0xA0000000;

define symbol SDRAM_end = 0xA1FFFFFF;

/-Sizes-/

define symbol size_stack = 0x4000;

define symbol size_heap = 0x2000;

define memory mem with size = 4G;

define region FLASH_region = mem:[from FLASH_ROM_start to FLASH_ROM_end];

define region RAM_region = mem:[from RAM_start to RAM_end];

define region SDRAM_region = mem:[from SDRAM_start to SDRAM_end];

define block CSTACK with alignment = 8, size = size_stack { };

define block HEAP with alignment = 8, size = size_heap { };

initialize by copy with packing = zeros { readwrite };

do not initialize { section .noinit };

place at address mem: intvec_start { section .intvec };

place at start of FLASH_region { readonly section .cstartup };

place in RAM_region { block CSTACK };

place in SDRAM_region { readonly }

except {readonly section FILEOP };

place in SDRAM_region { readwrite };

place in SDRAM_region { block HEAP};

place in FLASH_region { readonly section FILEOP };

fileOper.cpp: I have changed it, but it still reproduce the same error.

#include "fileOperbug.h"
#include <string>

char *fgets( char *str, int num, std::string *stream ) {

  char *pointer = 0;
  return pointer;
}

std::string *fopen(const char *name, const char *mode) {
  std::string *str = new std::string();
  str->assign("");
  return str;
}
1
Does the accepted answer of this stackoverflow question help: [How to fix a "[Lp002]: relocation failed with IAR ARM tools?][1] [1]: stackoverflow.com/questions/1208312/…Habi
I have already seen this. It doesn't help. The reason is different, but the error is the same.maximus
Can you post the details of the change(s) you made to tell the linker it should put part of the application code to ROM? Maybe you can also post the relevant parts of fileOper.c?Michael Burr
@MichaelBurr I have updated the question. The fileOper.cpp file was marked as FILEOP section.maximus

1 Answers

2
votes

I have resolved the problem. While using IAR Embedded workbench: Project options -> C/C++ Compiler -> Language 1 tab. There at the "C++ dialect" there was a checkbox named "with exceptions" at it was checked. The error at linking stage happens when "with exceptions" checkbox is checked. All code that uses exceptions must be loaded to ROM. Otherwise the "with exceptions" should be unchecked.