string: make memcpy(), memset(), memcmp() and memmove() visible for LTO
authorMarek Behún <marek.behun@nic.cz>
Thu, 20 May 2021 11:23:55 +0000 (13:23 +0200)
committerTom Rini <trini@konsulko.com>
Mon, 24 May 2021 18:21:30 +0000 (14:21 -0400)
commit46c3e29219e445de150e60e371cfec75f6fee524
treebf659babceadbf369d929618f33cfc5d9c63df28
parent6f243e25e6c81a8ab4e98b57fa5b749e0297cac3
string: make memcpy(), memset(), memcmp() and memmove() visible for LTO

It seems that sometimes (happening on ARM64, for example with
turris_mox_defconfig) GCC, when linking with LTO, changes the symbol
names of some functions, for example lib/string.c's memcpy() function to
memcpy.isra.0.

This is a problem however when GCC for a code such as this:
struct some_struct *info = get_some_struct();
struct some struct tmpinfo;
tmpinfo = *info;
emits a call to memcpy() by builtin behaviour, to copy *info to tmpinfo.

This then results in the following linking error:
  .../lz4.c:93: undefined reference to `memcpy'
  .../uuid.c:206: more undefined references to `memcpy' follow

GCC's documentation says this about -nodefaultlibs option:
  The compiler may generate calls to "memcmp", "memset", "memcpy" and
  "memmove".  These entries are usually resolved by entries in libc.
  These entry points should be supplied through some other mechanism
  when this option is specified.

Make these functions visible by using the __used macro to avoid this
error.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>
lib/string.c