Bug 58203 - memset/memcpy are discarded with -flto
Summary: memset/memcpy are discarded with -flto
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: lto (show other bugs)
Version: 4.8.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: link-failure, lto
: 60395 65199 99559 (view as bug list)
Depends on:
Blocks: 65199
  Show dependency treegraph
 
Reported: 2013-08-20 15:27 UTC by kukyakya
Modified: 2022-04-28 10:54 UTC (History)
9 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-12-24 00:00:00


Attachments
Test case (230 bytes, text/plain)
2013-08-20 15:28 UTC, kukyakya
Details

Note You need to log in before you can comment on or make changes to this bug.
Description kukyakya 2013-08-20 15:27:31 UTC
It might be a duplicate of bug 51205 but it's happening again.

[test.cpp]
typedef void (*action_t)(const unsigned char*);

extern "C" void _start(action_t action)
{
  const unsigned char foo[256] = {};

  action(foo);
}

typedef __SIZE_TYPE__ size_t;

extern "C"
void*
//__attribute__((externally_visible)) // Workaround
memset(void* dst, int c, size_t len)
{
  unsigned char * d = (unsigned char*)dst;

  while(len--)
    *d++ = c;

  return dst;
}

[error]
$ arm-none-linux-gnueabi-g++ -fno-exceptions -nostartfiles -static -nostdlib -nodefaultlibs -flto test.cpp -o test
`memset' referenced in section `.text' of /tmp/cc7ooAE0.ltrans0.ltrans.o: defined in discarded section `.text' of /tmp/ccVDnjy6.o (symbol from plugin)
collect2: error: ld returned 1 exit status

[versions]
arm-none-linux-gnueabi-g++ --version : 4.8.1
arm-none-linux-gnueabi-ld --version : 2.23.2
Comment 1 kukyakya 2013-08-20 15:28:34 UTC
Created attachment 30679 [details]
Test case
Comment 2 Jan Hubicka 2016-09-11 10:09:41 UTC
At present the runtime functions are not supposed to be LTOed, because references to them may appear late in the codegen.  I suppose things could work with explicit "used" attribute.
Comment 3 Andrew Pinski 2021-03-12 18:15:21 UTC
*** Bug 99559 has been marked as a duplicate of this bug. ***
Comment 4 Andrew Pinski 2021-12-24 08:26:20 UTC
*** Bug 60395 has been marked as a duplicate of this bug. ***
Comment 5 Andrew Pinski 2021-12-24 12:51:04 UTC
.
Comment 6 Andrew Pinski 2021-12-24 12:51:45 UTC
*** Bug 65199 has been marked as a duplicate of this bug. ***