http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51205

             Bug #: 51205
           Summary: -flto discards memset/memcpy when only referenced by
                    g++ generated code
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: bruck.mich...@googlemail.com


When LTO encounters a call to memset (or memcpy) that was auto-generated by g++
it does not register that dependency and incorrectly throws away instances of
memset/memcpy if they are not referenced elsewhere by the program.

*** command line:
arm-elf-gcc -nostartfiles -static -nostdlib -nodefaultlibs -flto
-fwhole-program test.cpp -o test

*** error:
`memset' referenced in section `.text' of /tmp/cc7Mshjq.ltrans0.ltrans.o:
defined in discarded section `.text' of /tmp/ccBgVaJK.o (symbol from plugin)
collect2: ld returned 1 exit status

*** test.cpp:

typedef void (*action_t)(const unsigned char *);

extern "C" void _start(action_t action)
{
    // this creates a call to memset() in g++
    const unsigned char foo[256] = {};

    action(foo);
}

#include <stddef.h>

// uncomment for workaround:

// extern "C" void * memset(void * dst, int c, size_t length) 
// __attribute__((externally_visible));



extern "C" void * memset(void * dst, int c, size_t length)
{
    unsigned char * _dst = (unsigned char *)dst;

    while (length--)
    *_dst = c;
}

Reply via email to