(XC16) What does the “PSV section '.const' exceeds 32K bytes” error mean?

How can I allocate more than 32K of const data in program memory?

The total size of a Program Space Visibility (PSV) type section cannot exceed 32 K because PSV pages cannot cross a PSV page boundary. With the default const-in-code memory model, the compiler will place all const qualified variables into a PSV type section named .const. Other PSV type sections can be created using the space(psv) attribute.

This error most often occurs with the const qualified objects, as the compiler will normally allocate space(psv) attributed variables into their own section, which will allow the linker to not overfill the PSV page.

The large objects placed in Flash using space(psv) might also trigger this error. Please remember that there are size limitations on objects that the compiler can handle, for instance, the maximum array size is 32 K.

To resolve this link error, consider placing some larger const qualified objects into a compiler managed PSV section instead. For example,

could be placed into a compiler managed PSV section using the following declaration:

A related error message indicates that the compiler cannot allocate memory, even though there appears to be enough memory available. This can occur when there is not enough memory left within a page boundary. The prog memory space does not have the restriction that memory must fit within a PSV page boundary. Placing objects in a prog space gives the toolchain more flexibility but is less efficient than space(psv). The same declaration above could be allocated:

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.