Skip to content

Commit 02a62b5

Browse files
committed
tools/nolibc: compiler: introduce __nolibc_has_attribute()
Recent compilers support __has_attribute() to check if a certain compiler attribute is supported. Unfortunately we have to first check if __has_attribute is supported in the first place and then if a specific attribute is present. These two checks can't be folded into a single condition as that would lead to errors. Nesting the two conditions like below works, but becomes ugly as soon as #else blocks are used as those need to be duplicated for both levels of #if. #if defined __has_attribute # if __has_attribute (nonnull) # define ATTR_NONNULL __attribute__ ((nonnull)) # endif #endif Introduce a new helper which makes the usage of __has_attribute() nicer and migrate the current user to it. Acked-by: Willy Tarreau <w@1wt.eu> Link: https://lore.kernel.org/r/20240807-nolibc-llvm-v2-4-c20f2f5fc7c2@weissschuh.net Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
1 parent 1daea15 commit 02a62b5

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

tools/include/nolibc/compiler.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@
66
#ifndef _NOLIBC_COMPILER_H
77
#define _NOLIBC_COMPILER_H
88

9+
#if defined(__has_attribute)
10+
# define __nolibc_has_attribute(attr) __has_attribute(attr)
11+
#else
12+
# define __nolibc_has_attribute(attr) 0
13+
#endif
14+
915
#if defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__) || defined(__SSP_EXPLICIT__)
1016

1117
#define _NOLIBC_STACKPROTECTOR
1218

1319
#endif /* defined(__SSP__) ... */
1420

15-
#if defined(__has_attribute)
16-
# if __has_attribute(no_stack_protector)
17-
# define __no_stack_protector __attribute__((no_stack_protector))
18-
# else
19-
# define __no_stack_protector __attribute__((__optimize__("-fno-stack-protector")))
20-
# endif
21+
#if __nolibc_has_attribute(no_stack_protector)
22+
# define __no_stack_protector __attribute__((no_stack_protector))
2123
#else
2224
# define __no_stack_protector __attribute__((__optimize__("-fno-stack-protector")))
23-
#endif /* defined(__has_attribute) */
25+
#endif /* __nolibc_has_attribute(no_stack_protector) */
2426

2527
#endif /* _NOLIBC_COMPILER_H */

0 commit comments

Comments
 (0)