]> git.proxmox.com Git - qemu.git/blame - compiler.h
fix live migration
[qemu.git] / compiler.h
CommitLineData
5c026320
LC
1/* public domain */
2
3#ifndef COMPILER_H
4#define COMPILER_H
5
6#include "config-host.h"
7
f8b72754
SW
8/*----------------------------------------------------------------------------
9| The macro QEMU_GNUC_PREREQ tests for minimum version of the GNU C compiler.
10| The code is a copy of SOFTFLOAT_GNUC_PREREQ, see softfloat-macros.h.
11*----------------------------------------------------------------------------*/
12#if defined(__GNUC__) && defined(__GNUC_MINOR__)
13# define QEMU_GNUC_PREREQ(maj, min) \
14 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
15#else
16# define QEMU_GNUC_PREREQ(maj, min) 0
17#endif
18
5c026320 19#define QEMU_NORETURN __attribute__ ((__noreturn__))
f8b72754 20
87751797 21#if QEMU_GNUC_PREREQ(3, 4)
5c026320
LC
22#define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
23#else
24#define QEMU_WARN_UNUSED_RESULT
25#endif
26
0f7fdd34
SW
27#if defined(_WIN32)
28# define QEMU_PACKED __attribute__((gcc_struct, packed))
29#else
30# define QEMU_PACKED __attribute__((packed))
31#endif
32
ea8f978f
DXW
33#define cat(x,y) x ## y
34#define cat2(x,y) cat(x,y)
5c026320 35#define QEMU_BUILD_BUG_ON(x) \
ea8f978f 36 typedef char cat2(qemu_build_bug_on__,__LINE__)[(x)?-1:1];
5c026320
LC
37
38#if defined __GNUC__
f8b72754 39# if !QEMU_GNUC_PREREQ(4, 4)
5c026320
LC
40 /* gcc versions before 4.4.x don't support gnu_printf, so use printf. */
41# define GCC_ATTR __attribute__((__unused__, format(printf, 1, 2)))
42# define GCC_FMT_ATTR(n, m) __attribute__((format(printf, n, m)))
43# else
44 /* Use gnu_printf when supported (qemu uses standard format strings). */
45# define GCC_ATTR __attribute__((__unused__, format(gnu_printf, 1, 2)))
46# define GCC_FMT_ATTR(n, m) __attribute__((format(gnu_printf, n, m)))
95df51a4
SW
47# if defined(_WIN32)
48 /* Map __printf__ to __gnu_printf__ because we want standard format strings
49 * even when MinGW or GLib include files use __printf__. */
50# define __printf__ __gnu_printf__
51# endif
5c026320 52# endif
1f001dc7
PB
53# if defined(__APPLE__)
54# define QEMU_WEAK_ALIAS(newname, oldname) \
55 static typeof(oldname) weak_##newname __attribute__((unused, weakref(#oldname)))
56# define QEMU_WEAK_REF(newname, oldname) (weak_##newname ? weak_##newname : oldname)
57# else
58# define QEMU_WEAK_ALIAS(newname, oldname) \
67d223be 59 typeof(oldname) newname __attribute__((weak, alias (#oldname)))
1f001dc7
PB
60# define QEMU_WEAK_REF(newname, oldname) newname
61# endif
5c026320
LC
62#else
63#define GCC_ATTR /**/
64#define GCC_FMT_ATTR(n, m)
67d223be
PB
65#define QEMU_WEAK_ALIAS(newname, oldname) \
66 _Pragma("weak " #newname "=" #oldname)
5c026320
LC
67#endif
68
69#endif /* COMPILER_H */