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

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

The total size of a PSV (Program Space Visibility) type section cannot exceed 32K 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 32K.

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 tool chain more flexibility but is less efficient that space(psv). The same declaration above could be allocated:

© 2017 Microchip Technology, Inc.
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.