From d486bd3cfe0b4bbdcbc08be2fa325f876046243a Mon Sep 17 00:00:00 2001 From: Jiafei Pan Date: Tue, 20 Sep 2022 15:48:28 +0800 Subject: [PATCH] lib: libc: newlib: make sure retargetable locking is enabled in toolchain Add build assert to make sure _RETARGETABLE_LOCKING is enabled in toolchain, When _RETARGETABLE_LOCKING is enabled, "_LOCK_T" is "__lock" pointer type, otherwise "_LOCK_T" is "int" type, so there will be the following compile warnings when toolchain doesn't enable _RETARGETABLE_LOCKING: zephyr/lib/libc/newlib/libc-hooks.c:416:13: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] 416 | k_sem_take((struct k_sem *)lock, K_FOREVER); | ^ zephyr/lib/libc/newlib/libc-hooks.c: In function '__retarget_lock_acquire _recursive': zephyr/lib/libc/newlib/libc-hooks.c:423:15: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] 423 | k_mutex_lock((struct k_mutex *)lock, K_FOREVER); | ^ ... Signed-off-by: Jiafei Pan --- lib/libc/newlib/libc-hooks.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/libc/newlib/libc-hooks.c b/lib/libc/newlib/libc-hooks.c index cdfd237ab82..92c49c122e9 100644 --- a/lib/libc/newlib/libc-hooks.c +++ b/lib/libc/newlib/libc-hooks.c @@ -305,6 +305,10 @@ void *_sbrk(intptr_t count) __weak FUNC_ALIAS(_sbrk, sbrk, void *); #ifdef CONFIG_MULTITHREADING + +/* Make sure _RETARGETABLE_LOCKING is enabled in toolchain */ +BUILD_ASSERT(IS_ENABLED(_RETARGETABLE_LOCKING), "Retargetable locking must be enabled"); + /* * Newlib Retargetable Locking Interface Implementation *