The -G num option puts the global and static items less than or equal to num bytes into the small data or bss section, instead of the normal data or bss section. This allows the data to be accessed using a single instruction. This option controls the gp-relative addressing threshold. However, gp-relative addressing is limited to 64 KB of small data.
The default number value of -G is 8. This means that data objects that are 8 bytes or smaller go into the small data or bss section and can be accessed more efficiently. The error small-data section exceeds 64KB; lower small-data size limit (see option -G) means that the data variables that are 8 bytes or smaller exceed 64 KB.
To prevent this error, reduce the number of variables that get allocated in the small data section. This can be done by reducing the -G value. In MPLAB® X IDE, under File>Project properties>XC32>Global Options, select ’Use GP relative addressing threshold’ and enter the value 4 (or any other value less than 8). This will pass the option -G 4 to the compiler, and only the objects 4 bytes or smaller will go into the small data section.
You may also disable small-data using -G0 but, this comes with size performance degradation.
If reducing the value to 4 doesn't resolve the error, you may need to explicitly place some variables into a named section using the section attribute.
E.g.,
int attribute((section("mysection"))) foo;
Placing a variable into a named section prevents it from going into the small-data section. This can also be done for variables that are not accessed frequently.
Or, allocate large data in .data/.bss.
E.g.,
unsigned int my_array[2000] attribute((section(“.data")));