1 /* Configuration definitions. 2 Copyright (C) 2008 Red Hat, Inc. 3 This file is part of Red Hat elfutils. 4 5 Red Hat elfutils is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by the 7 Free Software Foundation; version 2 of the License. 8 9 Red Hat elfutils is distributed in the hope that it will be useful, but 10 WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 General Public License for more details. 13 14 You should have received a copy of the GNU General Public License along 15 with Red Hat elfutils; if not, write to the Free Software Foundation, 16 Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA. 17 18 In addition, as a special exception, Red Hat, Inc. gives You the 19 additional right to link the code of Red Hat elfutils with code licensed 20 under an Open Source Initiative certified open source license 21 (http://www.opensource.org/licenses/index.php) and to distribute linked 22 combinations including the two. Non-GPL Code permitted under this 23 exception must only link to the code of Red Hat elfutils through those 24 well defined interfaces identified in the file named EXCEPTION found in 25 the source code files (the "Approved Interfaces"). The files of Non-GPL 26 Code may instantiate templates or use macros or inline functions from 27 the Approved Interfaces without causing the resulting work to be covered 28 by the GNU General Public License. Only Red Hat, Inc. may make changes 29 or additions to the list of Approved Interfaces. Red Hat's grant of 30 this exception is conditioned upon your not adding any new exceptions. 31 If you wish to add a new Approved Interface or exception, please contact 32 Red Hat. You must obey the GNU General Public License in all respects 33 for all of the Red Hat elfutils code and other code used in conjunction 34 with Red Hat elfutils except the Non-GPL Code covered by this exception. 35 If you modify this file, you may extend this exception to your version 36 of the file, but you are not obligated to do so. If you do not wish to 37 provide this exception without modification, you must delete this 38 exception statement from your version and license this file solely under 39 the GPL without exception. 40 41 Red Hat elfutils is an included package of the Open Invention Network. 42 An included package of the Open Invention Network is a package for which 43 Open Invention Network licensees cross-license their patents. No patent 44 license is granted, either expressly or impliedly, by designation as an 45 included package. Should you wish to participate in the Open Invention 46 Network licensing program, please visit www.openinventionnetwork.com 47 <http://www.openinventionnetwork.com>. */ 48 49 #ifdef USE_TLS 50 # include <pthread.h> 51 # include <assert.h> 52 # define tls_key_t __thread void * 53 # define key_create(keyp, freefct) (1) 54 # define getspecific(key) key 55 # define setspecific(key,val) key = val 56 # define once_define(class,name) class struct { } name 57 # define once_execute(name,fct) ((void) &name, (void) (fct)) 58 # define rwlock_define(class,name) class pthread_rwlock_t name 59 # define RWLOCK_CALL(call) \ 60 ({ int _err = pthread_rwlock_ ## call; assert_perror (_err); }) 61 # define rwlock_init(lock) RWLOCK_CALL (init (&lock, NULL)) 62 # define rwlock_fini(lock) RWLOCK_CALL (destroy (&lock)) 63 # define rwlock_rdlock(lock) RWLOCK_CALL (rdlock (&lock)) 64 # define rwlock_wrlock(lock) RWLOCK_CALL (wrlock (&lock)) 65 # define rwlock_unlock(lock) RWLOCK_CALL (unlock (&lock)) 66 #else 67 /* Eventually we will allow multi-threaded applications to use the 68 libraries. Therefore we will add the necessary locking although 69 the macros used expand to nothing for now. */ 70 # define lock_lock(lock) ((void) (lock)) 71 # define rwlock_define(class,name) class int name 72 # define rwlock_init(lock) ((void) (lock)) 73 # define rwlock_fini(lock) ((void) (lock)) 74 # define rwlock_rdlock(lock) ((void) (lock)) 75 # define rwlock_wrlock(lock) ((void) (lock)) 76 # define rwlock_unlock(lock) ((void) (lock)) 77 # define tls_key_t void * 78 # define key_create(keyp, freefct) (1) 79 # define getspecific(key) key 80 # define setspecific(key,val) key = val 81 # define once_define(class,name) class int name 82 # define once_execute(name,fct) \ 83 do { \ 84 if (name == 0) \ 85 fct (); \ 86 name = 1; \ 87 } while (0) 88 #endif /* USE_TLS */ 89 90 /* gettext helper macro. */ 91 #define N_(Str) Str 92 93 /* Compiler-specific definitions. */ 94 #define strong_alias(name, aliasname) \ 95 extern __typeof (name) aliasname __attribute__ ((alias (#name))); 96 97 #ifdef __i386__ 98 # define internal_function __attribute__ ((regparm (3), stdcall)) 99 #else 100 # define internal_function /* nothing */ 101 #endif 102 103 #define internal_strong_alias(name, aliasname) \ 104 extern __typeof (name) aliasname __attribute__ ((alias (#name))) internal_function; 105 106 #define attribute_hidden \ 107 __attribute__ ((visibility ("hidden"))) 108 109 /* Define ALLOW_UNALIGNED if the architecture allows operations on 110 unaligned memory locations. */ 111 #if defined __i386__ || defined __x86_64__ 112 # define ALLOW_UNALIGNED 1 113 #else 114 # define ALLOW_UNALIGNED 0 115 #endif 116 117 #if DEBUGPRED 118 # ifdef __x86_64__ 119 asm (".section predict_data, \"aw\"; .previous\n" 120 ".section predict_line, \"a\"; .previous\n" 121 ".section predict_file, \"a\"; .previous"); 122 # ifndef PIC 123 # define debugpred__(e, E) \ 124 ({ long int _e = !!(e); \ 125 asm volatile (".pushsection predict_data; ..predictcnt%=: .quad 0; .quad 0\n" \ 126 ".section predict_line; .quad %c1\n" \ 127 ".section predict_file; .quad %c2; .popsection\n" \ 128 "addq $1,..predictcnt%=(,%0,8)" \ 129 : : "r" (_e == E), "i" (__LINE__), "i" (__FILE__)); \ 130 __builtin_expect (_e, E); \ 131 }) 132 # endif 133 # elif defined __i386__ 134 asm (".section predict_data, \"aw\"; .previous\n" 135 ".section predict_line, \"a\"; .previous\n" 136 ".section predict_file, \"a\"; .previous"); 137 # ifndef PIC 138 # define debugpred__(e, E) \ 139 ({ long int _e = !!(e); \ 140 asm volatile (".pushsection predict_data; ..predictcnt%=: .long 0; .long 0\n" \ 141 ".section predict_line; .long %c1\n" \ 142 ".section predict_file; .long %c2; .popsection\n" \ 143 "incl ..predictcnt%=(,%0,8)" \ 144 : : "r" (_e == E), "i" (__LINE__), "i" (__FILE__)); \ 145 __builtin_expect (_e, E); \ 146 }) 147 # endif 148 # endif 149 # ifdef debugpred__ 150 # define unlikely(e) debugpred__ (e,0) 151 # define likely(e) debugpred__ (e,1) 152 # endif 153 #endif 154 #ifndef likely 155 # define unlikely(expr) __builtin_expect (!!(expr), 0) 156 # define likely(expr) __builtin_expect (!!(expr), 1) 157 #endif 158 159 #define obstack_calloc(ob, size) \ 160 ({ size_t _s = (size); memset (obstack_alloc (ob, _s), '\0', _s); }) 161 #define obstack_strdup(ob, str) \ 162 ({ const char *_s = (str); obstack_copy0 (ob, _s, strlen (_s)); }) 163 #define obstack_strndup(ob, str, n) \ 164 ({ const char *_s = (str); obstack_copy0 (ob, _s, strnlen (_s, n)); }) 165 166 #if __STDC_VERSION__ >= 199901L 167 # define flexarr_size /* empty */ 168 #else 169 # define flexarr_size 0 170 #endif 171 172 /* Calling conventions. */ 173 #ifdef __i386__ 174 # define CALLING_CONVENTION regparm (3), stdcall 175 # define AND_CALLING_CONVENTION , regparm (3), stdcall 176 #else 177 # define CALLING_CONVENTION 178 # define AND_CALLING_CONVENTION 179 #endif 180 181 /* Avoid PLT entries. */ 182 #ifdef PIC 183 # define INTUSE(name) _INTUSE(name) 184 # define _INTUSE(name) __##name##_internal 185 # define INTDEF(name) _INTDEF(name) 186 # define _INTDEF(name) \ 187 extern __typeof__ (name) __##name##_internal __attribute__ ((alias (#name))); 188 # define INTDECL(name) _INTDECL(name) 189 # define _INTDECL(name) \ 190 extern __typeof__ (name) __##name##_internal attribute_hidden; 191 #else 192 # define INTUSE(name) name 193 # define INTDEF(name) /* empty */ 194 # define INTDECL(name) /* empty */ 195 #endif 196 197 /* This macro is used by the tests conditionalize for standalone building. */ 198 #define ELFUTILS_HEADER(name) <lib##name.h> 199