mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2026-09-20 15:21:42 +01:00
Add macros to properly guard clang's thread safety analysis attributes keeping compatibility with GCC, on top of making things more readable. Clang < 19 does not support guarded_by() [0], so do not define the macros in that case. [0] https://github.com/llvm/llvm-project/pull/94216 Signed-off-by: Carlos López <carlos.lopezr4096@gmail.com> Reviewed-by: Anup Patel <anup@brainfault.org> Link: https://lore.kernel.org/r/20260909162322.29778-3-carlos.lopezr4096@gmail.com Signed-off-by: Anup Patel <anup@brainfault.org>
36 lines
1.1 KiB
C
36 lines
1.1 KiB
C
/*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*
|
|
* Copyright (c) 2025 SiFive
|
|
*/
|
|
|
|
#ifndef __SBI_VISIBILITY_H__
|
|
#define __SBI_VISIBILITY_H__
|
|
|
|
#ifndef __DTS__
|
|
/*
|
|
* Declare all global objects with hidden visibility so access is PC-relative
|
|
* instead of going through the GOT.
|
|
*/
|
|
#pragma GCC visibility push(hidden)
|
|
#endif
|
|
|
|
/* Thread Safety Analysis (TSA) annotations for use with clang -Wthread-safety */
|
|
#if defined(__clang__) && __clang_major__ >= 19
|
|
#define TSA_ATTR(x) __attribute__((x))
|
|
#else
|
|
#define TSA_ATTR(x)
|
|
#endif
|
|
|
|
#define CAPABILITY(x) TSA_ATTR(capability(x))
|
|
#define GUARDED_BY(x) TSA_ATTR(guarded_by(x))
|
|
#define PT_GUARDED_BY(x) TSA_ATTR(pt_guarded_by(x))
|
|
#define ACQUIRE(...) TSA_ATTR(acquire_capability(__VA_ARGS__))
|
|
#define RELEASE(...) TSA_ATTR(release_capability(__VA_ARGS__))
|
|
#define MUST_HOLD(...) TSA_ATTR(requires_capability(__VA_ARGS__))
|
|
#define MUST_NOT_HOLD(...) TSA_ATTR(locks_excluded(__VA_ARGS__))
|
|
#define TRY_ACQUIRE(b, ...) TSA_ATTR(try_acquire_capability(b, __VA_ARGS__))
|
|
#define NO_THREAD_SAFETY_ANALYSIS TSA_ATTR(no_thread_safety_analysis)
|
|
|
|
#endif
|