1

I am trying to compile this inline code for armv4t chip,

asm ("LDR   R2, =a1");

gcc replies that

invalid literal constant: pool needs to be closer

I tried to move a1 near the function, but still the same error.

How to fix this error?

wxie
  • 513
  • 7
  • 10
  • `a1` is a register name; can you try another label to see if it works? Did you mean a label or the value `0xa1`? You can use, `asm("ldr r2,=a1\nb 1f\n .ltorg\n 1:\n")` which should always work but usually you don't need this. – artless noise Apr 20 '16 at 12:35
  • Since you are using gcc, how about using extended asm and listing a1 as an input? – David Wohlferd Apr 21 '16 at 02:30

1 Answers1

2

Just stolen from the ARM site (http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0041c/Babbfdih.html):

The offset from the pc to the value in the literal pool must be less than 4KB. You are responsible for ensuring that there is a literal pool within range. See LTORG directive for more information.

so possibly the variable a1 is defined somewhere outside of this 4k, this is what the assembler sees as invalid so it generates the error message.

There is a lot more info at http://www.freertos.org/FreeRTOS_Support_Forum_Archive/February_2006/freertos_ARM_Error_invalid_literal_constant_pool_nee_1448037.html and ARM + gcc: don't use one big .rodata section

Some other sources (http://www.mikrocontroller.net/topic/68111 - German) suggest that the flag -ffunction-sections should be added to the compiler.

Community
  • 1
  • 1
Ferenc Deak
  • 34,348
  • 17
  • 99
  • 167
  • Thanks all for help. Adding -ffunction-sections flags works for me so far, but .ltorg does not work. – wxie Apr 21 '16 at 03:04