17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 2605c24214SIgor Kozhukhov /* 2705c24214SIgor Kozhukhov * Copyright 2015 EveryCity Ltd. All rights reserved. 283b442230SJordan Paige Hendricks * Copyright 2019 Joyent, Inc. 2905c24214SIgor Kozhukhov */ 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #ifndef _SYS_CCOMPILE_H 327c478bd9Sstevel@tonic-gate #define _SYS_CCOMPILE_H 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate /* 357c478bd9Sstevel@tonic-gate * This file contains definitions designed to enable different compilers 367c478bd9Sstevel@tonic-gate * to be used harmoniously on Solaris systems. 377c478bd9Sstevel@tonic-gate */ 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #ifdef __cplusplus 407c478bd9Sstevel@tonic-gate extern "C" { 417c478bd9Sstevel@tonic-gate #endif 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate /* 447c478bd9Sstevel@tonic-gate * Allow for version tests for compiler bugs and features. 457c478bd9Sstevel@tonic-gate */ 467c478bd9Sstevel@tonic-gate #if defined(__GNUC__) 477c478bd9Sstevel@tonic-gate #define __GNUC_VERSION \ 487c478bd9Sstevel@tonic-gate (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) 497c478bd9Sstevel@tonic-gate #else 507c478bd9Sstevel@tonic-gate #define __GNUC_VERSION 0 517c478bd9Sstevel@tonic-gate #endif 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate #if defined(__ATTRIBUTE_IMPLEMENTED) || defined(__GNUC__) 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate /* 567c478bd9Sstevel@tonic-gate * analogous to lint's PRINTFLIKEn 577c478bd9Sstevel@tonic-gate */ 587c478bd9Sstevel@tonic-gate #define __sun_attr___PRINTFLIKE__(__n) \ 597c478bd9Sstevel@tonic-gate __attribute__((__format__(printf, __n, (__n)+1))) 607c478bd9Sstevel@tonic-gate #define __sun_attr___VPRINTFLIKE__(__n) \ 617c478bd9Sstevel@tonic-gate __attribute__((__format__(printf, __n, 0))) 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate /* 647c478bd9Sstevel@tonic-gate * Handle the kernel printf routines that can take '%b' too 657c478bd9Sstevel@tonic-gate */ 667c478bd9Sstevel@tonic-gate #if __GNUC_VERSION < 30402 677c478bd9Sstevel@tonic-gate /* 687c478bd9Sstevel@tonic-gate * XX64 at least this doesn't work correctly yet with 3.4.1 anyway! 697c478bd9Sstevel@tonic-gate */ 707c478bd9Sstevel@tonic-gate #define __sun_attr___KPRINTFLIKE__ __sun_attr___PRINTFLIKE__ 717c478bd9Sstevel@tonic-gate #define __sun_attr___KVPRINTFLIKE__ __sun_attr___VPRINTFLIKE__ 727c478bd9Sstevel@tonic-gate #else 737c478bd9Sstevel@tonic-gate #define __sun_attr___KPRINTFLIKE__(__n) \ 747c478bd9Sstevel@tonic-gate __attribute__((__format__(cmn_err, __n, (__n)+1))) 757c478bd9Sstevel@tonic-gate #define __sun_attr___KVPRINTFLIKE__(__n) \ 767c478bd9Sstevel@tonic-gate __attribute__((__format__(cmn_err, __n, 0))) 777c478bd9Sstevel@tonic-gate #endif 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate /* 807c478bd9Sstevel@tonic-gate * This one's pretty obvious -- the function never returns 817c478bd9Sstevel@tonic-gate */ 827c478bd9Sstevel@tonic-gate #define __sun_attr___noreturn__ __attribute__((__noreturn__)) 837c478bd9Sstevel@tonic-gate 846b7143d7SRichard Lowe /* 856b7143d7SRichard Lowe * The function is 'extern inline' and expects GNU C89 behaviour, not C99 866b7143d7SRichard Lowe * behaviour. 876b7143d7SRichard Lowe * 886b7143d7SRichard Lowe * Should only be used on 'extern inline' definitions for GCC. 896b7143d7SRichard Lowe */ 906a3e8e86SRichard Lowe #if __GNUC_VERSION >= 40200 916b7143d7SRichard Lowe #define __sun_attr___gnu_inline__ __attribute__((__gnu_inline__)) 926b7143d7SRichard Lowe #else 936b7143d7SRichard Lowe #define __sun_attr___gnu_inline__ 946b7143d7SRichard Lowe #endif 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate /* 976a3e8e86SRichard Lowe * The function has control flow such that it may return multiple times (in 986a3e8e86SRichard Lowe * the manner of setjmp or vfork) 996a3e8e86SRichard Lowe */ 1006a3e8e86SRichard Lowe #if __GNUC_VERSION >= 40100 1016a3e8e86SRichard Lowe #define __sun_attr___returns_twice__ __attribute__((__returns_twice__)) 1026a3e8e86SRichard Lowe #else 1036a3e8e86SRichard Lowe #define __sun_attr___returns_twice__ 1046a3e8e86SRichard Lowe #endif 1056a3e8e86SRichard Lowe 1066a3e8e86SRichard Lowe /* 1077c478bd9Sstevel@tonic-gate * This is an appropriate label for functions that do not 1087c478bd9Sstevel@tonic-gate * modify their arguments, e.g. strlen() 1097c478bd9Sstevel@tonic-gate */ 1107c478bd9Sstevel@tonic-gate #define __sun_attr___pure__ __attribute__((__pure__)) 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate /* 1137c478bd9Sstevel@tonic-gate * This is a stronger form of __pure__. Can be used for functions 1147c478bd9Sstevel@tonic-gate * that do not modify their arguments and don't depend on global 1157c478bd9Sstevel@tonic-gate * memory. 1167c478bd9Sstevel@tonic-gate */ 1177c478bd9Sstevel@tonic-gate #define __sun_attr___const__ __attribute__((__const__)) 1187c478bd9Sstevel@tonic-gate 1195f82aa32SToomas Soome #if __GNUC_VERSION >= 20700 1205f82aa32SToomas Soome #define __aligned(x) __attribute__((__aligned__(x))) 12105c24214SIgor Kozhukhov /* 12205c24214SIgor Kozhukhov * This attribute, attached to a variable, means that the variable is meant to 12305c24214SIgor Kozhukhov * be possibly unused. GCC will not produce a warning for this variable. 12405c24214SIgor Kozhukhov */ 12505c24214SIgor Kozhukhov #define __sun_attr___unused__ __attribute__((__unused__)) 12605c24214SIgor Kozhukhov #endif 12705c24214SIgor Kozhukhov 1287c478bd9Sstevel@tonic-gate #define ___sun_attr_inner(__a) __sun_attr_##__a 1297c478bd9Sstevel@tonic-gate #define __sun_attr__(__a) ___sun_attr_inner __a 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate #else /* __ATTRIBUTE_IMPLEMENTED || __GNUC__ */ 1327c478bd9Sstevel@tonic-gate 1335f82aa32SToomas Soome #define __aligned(x) 1347c478bd9Sstevel@tonic-gate #define __sun_attr__(__a) 1355f82aa32SToomas Soome #define __sun_attr___unused__ 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate #endif /* __ATTRIBUTE_IMPLEMENTED || __GNUC__ */ 1387c478bd9Sstevel@tonic-gate 1393b442230SJordan Paige Hendricks #if __GNUC_VERSION >= 40100 1403b442230SJordan Paige Hendricks #define __sentinel(__n) __attribute__((__sentinel__(__n))) 1413b442230SJordan Paige Hendricks #else 1423b442230SJordan Paige Hendricks #define __sentinel(__n) 1433b442230SJordan Paige Hendricks #endif 1443b442230SJordan Paige Hendricks 1457c478bd9Sstevel@tonic-gate /* 1467c478bd9Sstevel@tonic-gate * Shorthand versions for readability 1477c478bd9Sstevel@tonic-gate */ 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate #define __PRINTFLIKE(__n) __sun_attr__((__PRINTFLIKE__(__n))) 1507c478bd9Sstevel@tonic-gate #define __VPRINTFLIKE(__n) __sun_attr__((__VPRINTFLIKE__(__n))) 1517c478bd9Sstevel@tonic-gate #define __KPRINTFLIKE(__n) __sun_attr__((__KPRINTFLIKE__(__n))) 1527c478bd9Sstevel@tonic-gate #define __KVPRINTFLIKE(__n) __sun_attr__((__KVPRINTFLIKE__(__n))) 1537c478bd9Sstevel@tonic-gate #define __NORETURN __sun_attr__((__noreturn__)) 1546b7143d7SRichard Lowe #define __GNU_INLINE __inline__ __sun_attr__((__gnu_inline__)) 1556a3e8e86SRichard Lowe #define __RETURNS_TWICE __sun_attr__((__returns_twice__)) 1567c478bd9Sstevel@tonic-gate #define __CONST __sun_attr__((__const__)) 1577c478bd9Sstevel@tonic-gate #define __PURE __sun_attr__((__pure__)) 1585f82aa32SToomas Soome #define __packed __attribute__((__packed__)) 15990ce8b93SToomas Soome #define __section(x) __attribute__((__section__(x))) 160c81a25e9SToomas Soome #define __unused __sun_attr__((__unused__)) 161*6de0af11SToomas Soome #ifdef DEBUG 162*6de0af11SToomas Soome /* We want to discover unused variables in DEBUG build. */ 163*6de0af11SToomas Soome #define __maybe_unused 164*6de0af11SToomas Soome #else 165*6de0af11SToomas Soome /* 166*6de0af11SToomas Soome * In release build, disable warnings about variables 167*6de0af11SToomas Soome * which are used only for debugging. 168*6de0af11SToomas Soome */ 169*6de0af11SToomas Soome #define __maybe_unused __sun_attr__((__unused__)) 170*6de0af11SToomas Soome #endif 17190ce8b93SToomas Soome #define __used __attribute__((__used__)) 17290ce8b93SToomas Soome #define __weak_symbol __attribute__((__weak__)) 1736a817834SRobert Mustacchi #define __HIDDEN __attribute__((visibility("hidden"))) 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1767c478bd9Sstevel@tonic-gate } 1777c478bd9Sstevel@tonic-gate #endif 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate #endif /* _SYS_CCOMPILE_H */ 180