1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 /* 27 * Copyright 2015 EveryCity Ltd. All rights reserved. 28 * Copyright 2019 Joyent, Inc. 29 * Copyright 2026 Edgecast Cloud LLC. 30 */ 31 32 #ifndef _SYS_CCOMPILE_H 33 #define _SYS_CCOMPILE_H 34 35 /* 36 * This file contains definitions designed to enable different compilers 37 * to be used harmoniously on Solaris systems. 38 */ 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 /* 45 * Allow for version tests for compiler bugs and features. 46 */ 47 #if defined(__GNUC__) 48 #define __GNUC_VERSION \ 49 (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) 50 #else 51 #define __GNUC_VERSION 0 52 #endif 53 54 #if defined(__ATTRIBUTE_IMPLEMENTED) || defined(__GNUC__) 55 56 /* 57 * analogous to lint's PRINTFLIKEn 58 */ 59 #define __sun_attr___PRINTFLIKE__(__n) \ 60 __attribute__((__format__(printf, __n, (__n)+1))) 61 #define __sun_attr___VPRINTFLIKE__(__n) \ 62 __attribute__((__format__(printf, __n, 0))) 63 64 #define __FORMAT_ARG(__n) __attribute__((format_arg(__n))) 65 66 /* 67 * Handle the kernel printf routines that can take '%b' too 68 */ 69 #if __GNUC_VERSION < 30402 70 /* 71 * XX64 at least this doesn't work correctly yet with 3.4.1 anyway! 72 */ 73 #define __sun_attr___KPRINTFLIKE__ __sun_attr___PRINTFLIKE__ 74 #define __sun_attr___KVPRINTFLIKE__ __sun_attr___VPRINTFLIKE__ 75 #else 76 #define __sun_attr___KPRINTFLIKE__(__n) \ 77 __attribute__((__format__(cmn_err, __n, (__n)+1))) 78 #define __sun_attr___KVPRINTFLIKE__(__n) \ 79 __attribute__((__format__(cmn_err, __n, 0))) 80 #endif 81 82 /* 83 * This one's pretty obvious -- the function never returns 84 */ 85 #define __sun_attr___noreturn__ __attribute__((__noreturn__)) 86 87 /* 88 * The function is 'extern inline' and expects GNU C89 behaviour, not C99 89 * behaviour. 90 * 91 * Should only be used on 'extern inline' definitions for GCC. 92 */ 93 #if __GNUC_VERSION >= 40200 94 #define __sun_attr___gnu_inline__ __attribute__((__gnu_inline__)) 95 #else 96 #define __sun_attr___gnu_inline__ 97 #endif 98 99 /* 100 * The function has control flow such that it may return multiple times (in 101 * the manner of setjmp or vfork) 102 */ 103 #if __GNUC_VERSION >= 40100 104 #define __sun_attr___returns_twice__ __attribute__((__returns_twice__)) 105 #else 106 #define __sun_attr___returns_twice__ 107 #endif 108 109 /* 110 * This is an appropriate label for functions that do not 111 * modify their arguments, e.g. strlen() 112 */ 113 #define __sun_attr___pure__ __attribute__((__pure__)) 114 115 /* 116 * This is a stronger form of __pure__. Can be used for functions 117 * that do not modify their arguments and don't depend on global 118 * memory. 119 */ 120 #define __sun_attr___const__ __attribute__((__const__)) 121 122 #if __GNUC_VERSION >= 20700 123 #define __aligned(x) __attribute__((__aligned__(x))) 124 /* 125 * This attribute, attached to a variable, means that the variable is meant to 126 * be possibly unused. GCC will not produce a warning for this variable. 127 */ 128 #define __sun_attr___unused__ __attribute__((__unused__)) 129 #endif 130 131 #define ___sun_attr_inner(__a) __sun_attr_##__a 132 #define __sun_attr__(__a) ___sun_attr_inner __a 133 134 #else /* __ATTRIBUTE_IMPLEMENTED || __GNUC__ */ 135 136 #define __aligned(x) 137 #define __sun_attr__(__a) 138 #define __sun_attr___unused__ 139 #define __FORMAT_ARG(__n) 140 141 #endif /* __ATTRIBUTE_IMPLEMENTED || __GNUC__ */ 142 143 #if __GNUC_VERSION >= 40100 144 #define __sentinel(__n) __attribute__((__sentinel__(__n))) 145 #else 146 #define __sentinel(__n) 147 #endif 148 149 /* 150 * Shorthand versions for readability 151 */ 152 153 #define __PRINTFLIKE(__n) __sun_attr__((__PRINTFLIKE__(__n))) 154 #define __VPRINTFLIKE(__n) __sun_attr__((__VPRINTFLIKE__(__n))) 155 #define __KPRINTFLIKE(__n) __sun_attr__((__KPRINTFLIKE__(__n))) 156 #define __KVPRINTFLIKE(__n) __sun_attr__((__KVPRINTFLIKE__(__n))) 157 #define __NORETURN __sun_attr__((__noreturn__)) 158 #define __GNU_INLINE __inline__ __sun_attr__((__gnu_inline__)) 159 #define __RETURNS_TWICE __sun_attr__((__returns_twice__)) 160 #define __CONST __sun_attr__((__const__)) 161 #define __PURE __sun_attr__((__pure__)) 162 #define __packed __attribute__((__packed__)) 163 #define __section(x) __attribute__((__section__(x))) 164 #define __unused __sun_attr__((__unused__)) 165 #ifdef DEBUG 166 /* We want to discover unused variables in DEBUG build. */ 167 #define __maybe_unused 168 #else 169 /* 170 * In release build, disable warnings about variables 171 * which are used only for debugging. 172 */ 173 #define __maybe_unused __sun_attr__((__unused__)) 174 #endif 175 #define __used __attribute__((__used__)) 176 #define __weak_symbol __attribute__((__weak__)) 177 #define __HIDDEN __attribute__((visibility("hidden"))) 178 #define __cacheline_aligned __aligned(_CACHE_LINE_SIZE) 179 180 #if defined(__has_attribute) 181 #if __has_attribute(__nonstring__) 182 /* To silence warnings about null terminator not fitting into an array. */ 183 #define __nonstring __attribute__((__nonstring__)) 184 #endif 185 #endif /* __has_attribute */ 186 187 #if !defined(__nonstring) 188 #define __nonstring 189 #endif 190 191 #ifdef __cplusplus 192 } 193 #endif 194 195 #endif /* _SYS_CCOMPILE_H */ 196