From 1547d2f075f141dd9a6d4ce014b8bd3be3686869 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 31 Aug 2021 12:55:09 +0200 Subject: [PATCH 1/2] make: add -ffunction-sections -fdata-sections to LINKFLAGS if LTO=1 --- makefiles/cflags.inc.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefiles/cflags.inc.mk b/makefiles/cflags.inc.mk index 9b8be48546..cf10636edd 100644 --- a/makefiles/cflags.inc.mk +++ b/makefiles/cflags.inc.mk @@ -54,7 +54,7 @@ endif ifeq ($(LTO),1) $(warning Building with Link-Time-Optimizations is currently an experimental feature. Expect broken binaries.) LTOFLAGS = -flto - LINKFLAGS += $(LTOFLAGS) + LINKFLAGS += $(LTOFLAGS) -ffunction-sections -fdata-sections endif # Forbid common symbols to prevent accidental aliasing. From 812b2738452f856490e8e776371c68991cfdc95f Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Wed, 1 Sep 2021 11:26:38 +0200 Subject: [PATCH 2/2] sys/malloc_thread_safe: mark functions "used" Fixes LTO. --- sys/malloc_thread_safe/malloc_wrappers.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sys/malloc_thread_safe/malloc_wrappers.c b/sys/malloc_thread_safe/malloc_wrappers.c index 2fc390e1dc..6eed832b4a 100644 --- a/sys/malloc_thread_safe/malloc_wrappers.c +++ b/sys/malloc_thread_safe/malloc_wrappers.c @@ -26,7 +26,7 @@ extern void *__real_realloc(void *ptr, size_t size); static mutex_t _lock; -void *__wrap_malloc(size_t size) +void __attribute__((used)) *__wrap_malloc(size_t size) { assert(!irq_is_in()); mutex_lock(&_lock); @@ -35,7 +35,7 @@ void *__wrap_malloc(size_t size) return ptr; } -void __wrap_free(void *ptr) +void __attribute__((used)) __wrap_free(void *ptr) { assert(!irq_is_in()); mutex_lock(&_lock); @@ -43,7 +43,7 @@ void __wrap_free(void *ptr) mutex_unlock(&_lock); } -void *__wrap_calloc(size_t nmemb, size_t size) +void * __attribute__((used)) __wrap_calloc(size_t nmemb, size_t size) { /* some c libs don't perform proper overflow check (e.g. newlib < 4.0.0). Hence, we * just implement calloc on top of malloc ourselves. In addition to ensuring proper @@ -61,7 +61,7 @@ void *__wrap_calloc(size_t nmemb, size_t size) return res; } -void *__wrap_realloc(void *ptr, size_t size) +void * __attribute__((used))__wrap_realloc(void *ptr, size_t size) { assert(!irq_is_in()); mutex_lock(&_lock);