avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] Link Time Optimization vs __builtin_unreachable() and .si


From: Bob Paddock
Subject: [avr-gcc-list] Link Time Optimization vs __builtin_unreachable() and .signature?
Date: Mon, 18 Jun 2012 10:26:23 -0400

With the release of GCC 4.7.1 I wanted to give Link Time Optimization
a try.  I'm using this version:
http://sourceforge.net/projects/mobilechessboar/files/avr-gcc%20snapshots%20(Win32)

Part is Xmega128A1.

Adding -flto and -flto-report:

CFLAGS += -flto
CFLAGS += -flto-report

LDFLAGS += -flto
LDFLAGS += -flto-report

Reduced the project code size by a mind boggling ~52K.  Would be nice,
alas it is not, traced the problem to this:

void reset_hardware( void )  __attribute__ ((__noreturn__)); /* Force
a system reset.  We only return from this function by a hardware reset
*/

/* Force a Hardware Reset: */
void reset_hardware( void )
{
  CCPWrite( &RST.CTRL, RST_SWRST_bm );
  __builtin_unreachable();
}

With LTO all the code after __builtin_unreachable(); is gone, breaking
the project.

Replacing  __builtin_unreachable():

void reset_hardware( void )
{
  CCPWrite( &RST.CTRL, RST_SWRST_bm );

  for(;;)
    ;
}

then LTO reduces the code by a more realistic 775 bytes.

A question I have is why do I have to add either
__builtin_unreachable(); or the empty for(;;) to suppress the
'noreturn function does return' warning message, when the function is declare
__noreturn__?  Seems GCC and I don't agree on the usage of 'noreturn'
as marking the function that it will indeed never return.

Also LTO is incompatible with:

#include <avr/signature.h> /* Place the chip's signature into the .elf
output file.  Simply including this file does the work.  Must only
appear in the project *once* */

%.elf: $(OBJ)
        $(OBJDUMP) -s -j .signature $(OBJDIR)/$@

LTO has removed .signature, resulting in avr-objdump giving an error
about .signature not being found.

Is there a way to mark .signature as precious at the source level?
Adding -flto to all source files but one complicates the Makefile.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]