summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorPatrick Georgi <pgeorgi@google.com>2021-06-14 22:00:12 +0200
committerCommit Bot <commit-bot@chromium.org>2021-06-17 09:55:02 +0000
commitace3777e8929c59ba68b23755830dae054f2e5f7 (patch)
tree98a412011f891e5d2ce58bccefcb6a9c74e9efb7 /common
parent12cb573e33cacd1b8ec5804477b3139265708cf9 (diff)
downloadchrome-ec-ace3777e8929c59ba68b23755830dae054f2e5f7.tar.gz
common/util: Annotate basic memory functions as used
If memcpy/memset/memcmp/memmove aren't used early enough in link time optimization, it's possible that the linker already discarded them only to complain about missing symbols later-on because some late optimization stage added references to them. To deal with that, we could either disable lto for util.o or just mark these 4 functions as "used". Since they're inevitably used _somewhere_ in the code, the latter doesn't have any impact on binary size. See discussion at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58203 BUG=none BRANCH=none TEST=one class of error less with gcc 11 Signed-off-by: Patrick Georgi <pgeorgi@google.com> Change-Id: I2e0c60c5ca461d32a28dca8df7b33abb709b441f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2959918 Reviewed-by: Edward Hill <ecgh@chromium.org> Tested-by: Patrick Georgi <pgeorgi@chromium.org> Commit-Queue: Patrick Georgi <pgeorgi@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/util.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/common/util.c b/common/util.c
index 8e965273a5..152c8370d0 100644
--- a/common/util.c
+++ b/common/util.c
@@ -249,6 +249,7 @@ __stdlib_compat int parse_bool(const char *s, int *dest)
return 0;
}
+__attribute__((used))
__stdlib_compat int memcmp(const void *s1, const void *s2, size_t len)
{
const char *sa = s1;
@@ -285,6 +286,7 @@ int safe_memcmp(const void *s1, const void *s2, size_t size)
}
#if !(__has_feature(address_sanitizer) || __has_feature(memory_sanitizer))
+__attribute__((used))
__stdlib_compat void *memcpy(void *dest, const void *src, size_t len)
{
char *d = (char *)dest;
@@ -331,6 +333,7 @@ __stdlib_compat void *memcpy(void *dest, const void *src, size_t len)
#if !(__has_feature(address_sanitizer) || __has_feature(memory_sanitizer))
+__attribute__((used))
__stdlib_compat __visible void *memset(void *dest, int c, size_t len)
{
char *d = (char *)dest;
@@ -371,6 +374,7 @@ __stdlib_compat __visible void *memset(void *dest, int c, size_t len)
#if !(__has_feature(address_sanitizer) || __has_feature(memory_sanitizer))
+__attribute__((used))
__stdlib_compat void *memmove(void *dest, const void *src, size_t len)
{
if ((uintptr_t)dest <= (uintptr_t)src ||