Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
2/*
3 * NOLIBC compiler support header
4 * Copyright (C) 2023 Thomas Weißschuh <linux@weissschuh.net>
5 */
6#ifndef _NOLIBC_COMPILER_H
7#define _NOLIBC_COMPILER_H
8
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
15#if defined(__has_feature)
16# define __nolibc_has_feature(feature) __has_feature(feature)
17#else
18# define __nolibc_has_feature(feature) 0
19#endif
20
21#define __nolibc_aligned(alignment) __attribute__((aligned(alignment)))
22#define __nolibc_aligned_as(type) __nolibc_aligned(__alignof__(type))
23
24#if __nolibc_has_attribute(naked)
25# define __nolibc_entrypoint __attribute__((naked))
26# define __nolibc_entrypoint_epilogue()
27#else
28# define __nolibc_entrypoint __attribute__((optimize("Os", "omit-frame-pointer")))
29# define __nolibc_entrypoint_epilogue() __builtin_unreachable()
30#endif /* __nolibc_has_attribute(naked) */
31
32#if defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__) || defined(__SSP_EXPLICIT__)
33
34#define _NOLIBC_STACKPROTECTOR
35
36#endif /* defined(__SSP__) ... */
37
38#if __nolibc_has_attribute(no_stack_protector)
39# define __no_stack_protector __attribute__((no_stack_protector))
40#else
41# define __no_stack_protector __attribute__((__optimize__("-fno-stack-protector")))
42#endif /* __nolibc_has_attribute(no_stack_protector) */
43
44#if __nolibc_has_attribute(__fallthrough__)
45# define __nolibc_fallthrough do { } while (0); __attribute__((__fallthrough__))
46#else
47# define __nolibc_fallthrough do { } while (0)
48#endif /* __nolibc_has_attribute(fallthrough) */
49
50#endif /* _NOLIBC_COMPILER_H */