Code optimised away

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a simple RTOS that loads a few function pointers from FLASH and then runs them when needed. The problem is that using the previous WinAVR release I could compile the code using the -Os option. With the new WinAVR release, using the -Os option results in the code that's loaded into the FLASH table as well as any corresponding functions, being removed.

If I take a look at the .lst file for the module after being compiled, there's no code in it. I would have thought that the compiler would have still compiled the module, generated code and that the linker would have left it out as it didn't appear to the linker that the code was being called directly.

How can I prevent this problem and why does the .lst file not contain anything?

Gavin

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've found a work-around that I can live with I changed the code that places the function pointers into the flash table from:

static const tTaskDescriptor aTasks[] TASK_TABLE =
{
    {TASK_SIGNATURE, 0, &Initialise, 0, TASK_eImmediate},
    {TASK_SIGNATURE, PRIORITY_eMedium, &StartFlashing, OS_2sec, TASK_eScheduleWithDelay}
};

to

const tTaskDescriptor aFlasherTasks[] TASK_TABLE =
{
    {TASK_SIGNATURE, 0, &Initialise, 0, TASK_eImmediate},
    {TASK_SIGNATURE, PRIORITY_eMedium, &StartFlashing, OS_2sec, TASK_eScheduleWithDelay}
};

I guess GCC is now happy that the functions in the module are being used and includes them without a problem.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This may be expected behavior.

The problem here is that, in variable declarations (even constant declarations), "static" means "local to this file". If there isn't anything in the same file that is using these function pointers, then the compiler will spot this an eliminate them.

If this is the case, then your solution (removing the "static" keyword) is the correct one, as it makes the declaration visible program-wide.

Sean.