Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
EmbeddedMan opened this issue Oct 15, 2015 · 1 comment
Open

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

EmbeddedMan opened this issue Oct 15, 2015 · 1 comment

Comments

@EmbeddedMan
Copy link
Member

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 added a commit to EmbeddedMan/chipKIT32-MAX that referenced this issue Oct 15, 2015
@EmbeddedMan
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant