cancel
Showing results for 
Search instead for 
Did you mean: 

STM32f070xB generating Error[Lp002]: relocation failed: value out of range or illegal

Priyadarshini Solanki
Associate II
Posted on January 12, 2018 at 10:23

I am using ♯STM32f070xB, In my program, I am trying to access registers (i.e. assembly code). My assembly code has branching instruction, which trying to branch to the function defined in another source file (.c).

Now the problem is, Branching instruction is generation error: [Lp002]: relocation failed: value out of range or illegal

What can be the possible reason behind and how I can resolve this.

#cortex-m0 #source-file #core-self-test #assembly-language #stm32f070 #stm32f0
6 REPLIES 6
Posted on January 13, 2018 at 17:42

Doesn't it suggest the relative branch target is too far away?

Not using IAR, but this should work

; Jump to function foo()

  EXTERN foo

  ldr r0, =foo

  bx r0

; Call bar()

  EXTERN bar

  bl bar

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on January 16, 2018 at 04:42

 ,

 ,

Thanks for your response.

I have done the same. which generates the error of relocation failed.

extern Fun

Test1:

 , , ,,Call ,Fun()

 ,  ,MOVS R0, ♯ 0x00

 ,

 , , ,BNE Fun

Error[Lp002]: relocation failed: value out of range or illegal: 0x306

 ,

Kind : R_ARM_THM_JUMP8[0x67]

 ,

Location: 0x080000c4

 ,

'

Test1

' + 0x4

 ,

Module: assembly.o

 ,

Section: 6 (.text)

 ,

Offset: 0x4

 ,

Target : 0x080003cf

 ,

'Fun'

 ,

Module: source.o

 ,

Section: 8 (.text)

 ,

Offset: 0x13

If relative branch target is too far away, How can I make the address close enough?

Posted on January 16, 2018 at 10:16

I'm not using IAR, review the documentation for a NEAR/FAR version of the branch

Or as suggested load the address into a register and BX Rx

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on January 16, 2018 at 10:53

I have to branch to the function only if the status flag gets affected, So 

load the address into a register and branch will not work for me.

I am trying to get IAR documentation for a NEAR/FAR version of the branch.

Any further help is appreciated.

Posted on January 16, 2018 at 11:20

It will work, you will just need to code the logic differently. 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on January 17, 2018 at 05:53

Thanks for your suggestion, It worked for me.

extern Fun

 label1:

   Bx   Rx

Test1:

   ;Call Fun()

   MOVS Ry, &sharp0x00

   LDR Rx, =Fun

   BNE label1