GCC & IAR handling of literal pools

David Leach

Here are my notes on literal pools I was referring to in the F2F today. Because the code generation for Thumb has restrictions on the size of literals an instruction can encode the compiler leverages literal pools generated in the .text area to store the larger literal values. If a file has a number of accesses to a literal value it can reference a common pool entry instead of having one on each code block reference. Depending on the code the .text size difference between GCC and IAR was measurable and meaningful. Not anything you can do from a code perspective but an interesting difference between GCC and IAR tool chains



Literal Pools


The ARM tool chain uses literal pools to hold constant 32-bit literal values that are to be loaded into registers. These literal pools are placed in generated assembly code to allow access by the LDR instruction. The offset can be:


·         less than 4KB in ARM or 32-bit Thumb code in either direction

·         forward and less than 1KB in 16-bit Thumb LDR instruction.




Locality of the assembly code to the literal pool will affect the number of pools generated. If a large C file has multiple references to a constant value that is placed in the literal pool the number of pools generated to support this constant value depends on the offset range to the various literal pools. If the instruction can't reach the pool a new one is generated to address the problem


Unfortunately, the GCC compiler tools will always place the literal pool immediately following the function that references it. The compiler chain does not attempt to optimize the generation of literal pools so the result is a literal pool after every routine and if multiple routines in a file reference the same literal value the GCC compiler will duplicate that value in a literal pool after every function.


The IAR tool chain takes a larger scope view and will create a single literal pool at the bottom of the file which removes the need for multiple literal pools that may exist in a file. [N.B.: Even though there is a single literal pool in a file even IAR will generate multiple instances of the same value. Not sure why but it doesn't go as badly as GCC does with one per routine.]






David Leach


NXP Semiconductors

phone: +

Email: david.leach@...



Join tsc@lists.zephyrproject.org to automatically receive all group messages.