chipKIT32 / chipKIT32-MAX

Multi-platform IDE derived version from Arduino 0022 for the chipKit.
http://chipkit.net
Other
108 stars 76 forks source link

Add -ftoplevel-reorder to c and c++ compile options #617

Open EmbeddedMan opened 9 years ago

EmbeddedMan commented 9 years ago

This is due to an issue we had with compiling the bootloader. We want the compiler to always try and remove as many unused things as possible, so we want this on the command line.

Here is Jason K's reply:

Rathish figured this one out. You probably know that for XC32 v1.40 we upgraded from GCC 4.5.2 to GCC 4.8.3. This newer GCC version features an option "-fno-toplevel-reorder".

-fno-toplevel-reorder Do not reorder top-level functions, variables, and asm statements. Output them in the same order that they appear in the input file. When this option is used, unreferenced static variables are not removed. This option is intended to support existing code that relies on a particular ordering. For new code, it is better to use attributes when possible.

Our internal testing showed that a few customer applications relied on some variables being allocated in the same order that they appear in the source code, causing customer applications to "break". We decided to disable this option by default so we had some time to educate customers that they should not rely on ordering without using an attribute to enforce it. This has the side effect of causing unused static variables to not be removed. We plan to re-enable this option by default at some point in the future.

In the boot-loader project, there are 2 unused static arrays present in usb.c.

define DEVICE_DESCRIPTOR_SIZE 18

define CONFIGURATION_DESCRIPTOR_SIZE 128

static byte descriptor[DEVICE_DESCRIPTOR_SIZE]; static byte configuration[CONFIGURATION_DESCRIPTOR_SIZE];

When compiled with XC32 v1.40, the above unused static array variables are not removed. This adds to the size of the bss section, and linker fails with the error. /opt/microchip/xc32/v1.40/bin/bin/gcc/pic32mx/4.8.3/../../../../bin/xc32-ld Error: Not enough memory for stack (1040 bytes needed, 1000 bytes available) collect2: error: ld returned 255 exit status

To get the bootloader project compile successfully, we can add the option “–ftoplevel-reorder” to the compiler or remove the above unused variables.

EmbeddedMan commented 9 years ago

This issue should now be fixed. It should be verified.