40a472d6d4ba6ae0bce647ee74de88ff479b5c3a
[lttng-modules.git] / include / wrapper / compiler.h
1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
2 *
3 * wrapper/compiler.h
4 *
5 * Copyright (C) 2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 */
7
8 #ifndef _LTTNG_WRAPPER_COMPILER_H
9 #define _LTTNG_WRAPPER_COMPILER_H
10
11 #include <linux/compiler.h>
12 #include <lttng/kernel-version.h>
13
14 /*
15 * Don't allow compiling with buggy compiler.
16 */
17
18 #ifdef GCC_VERSION
19
20 /*
21 * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58854
22 */
23 # ifdef __ARMEL__
24 # if GCC_VERSION >= 40800 && GCC_VERSION <= 40802
25 # error Your gcc version produces clobbered frame accesses
26 # endif
27 # endif
28
29 /*
30 * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63293
31 */
32 # ifdef __aarch64__
33 # if GCC_VERSION < 50100
34 # error Your gcc version performs unsafe access to deallocated stack
35 # endif
36 # endif
37
38 #endif
39
40 /*
41 * READ/WRITE_ONCE were introduced in kernel 3.19 and ACCESS_ONCE
42 * was removed in 4.15. Prefer READ/WRITE but fallback to ACCESS
43 * when they are not available.
44 */
45 #ifndef READ_ONCE
46 # define READ_ONCE(x) ACCESS_ONCE(x)
47 #endif
48
49 #ifndef WRITE_ONCE
50 # define WRITE_ONCE(x, val) ({ ACCESS_ONCE(x) = val; })
51 #endif
52
53 /*
54 * In v4.15 a smp read barrier was added to READ_ONCE to replace
55 * lockless_dereference(), replicate this behavior on prior kernels
56 * and remove calls to smp_read_barrier_depends which was dropped
57 * in v5.9.
58 */
59 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,15,0))
60 #define LTTNG_READ_ONCE(x) READ_ONCE(x)
61 #else
62 #define LTTNG_READ_ONCE(x) \
63 ({ \
64 typeof(x) __val = READ_ONCE(x); \
65 smp_read_barrier_depends(); \
66 __val; \
67 })
68 #endif
69
70 #define __LTTNG_COMPOUND_LITERAL(type, ...) (type[]) { __VA_ARGS__ }
71
72 #endif /* _LTTNG_WRAPPER_COMPILER_H */
This page took 0.030087 seconds and 3 git commands to generate.