Brian Silverman | 8649792 | 2018-02-10 19:28:39 -0500 | [diff] [blame] | 1 | /* Configuration definitions. |
| 2 | Copyright (C) 2008, 2009 Red Hat, Inc. |
| 3 | This file is part of elfutils. |
| 4 | |
| 5 | This file is free software; you can redistribute it and/or modify |
| 6 | it under the terms of either |
| 7 | |
| 8 | * the GNU Lesser General Public License as published by the Free |
| 9 | Software Foundation; either version 3 of the License, or (at |
| 10 | your option) any later version |
| 11 | |
| 12 | or |
| 13 | |
| 14 | * the GNU General Public License as published by the Free |
| 15 | Software Foundation; either version 2 of the License, or (at |
| 16 | your option) any later version |
| 17 | |
| 18 | or both in parallel, as here. |
| 19 | |
| 20 | elfutils is distributed in the hope that it will be useful, but |
| 21 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 23 | General Public License for more details. |
| 24 | |
| 25 | You should have received copies of the GNU General Public License and |
| 26 | the GNU Lesser General Public License along with this program. If |
| 27 | not, see <http://www.gnu.org/licenses/>. */ |
| 28 | |
| 29 | #ifndef EU_CONFIG_H |
| 30 | #define EU_CONFIG_H 1 |
| 31 | |
| 32 | #ifdef USE_LOCKS |
| 33 | # include <pthread.h> |
| 34 | # include <assert.h> |
| 35 | # define rwlock_define(class,name) class pthread_rwlock_t name |
| 36 | # define RWLOCK_CALL(call) \ |
| 37 | ({ int _err = pthread_rwlock_ ## call; assert_perror (_err); }) |
| 38 | # define rwlock_init(lock) RWLOCK_CALL (init (&lock, NULL)) |
| 39 | # define rwlock_fini(lock) RWLOCK_CALL (destroy (&lock)) |
| 40 | # define rwlock_rdlock(lock) RWLOCK_CALL (rdlock (&lock)) |
| 41 | # define rwlock_wrlock(lock) RWLOCK_CALL (wrlock (&lock)) |
| 42 | # define rwlock_unlock(lock) RWLOCK_CALL (unlock (&lock)) |
| 43 | #else |
| 44 | /* Eventually we will allow multi-threaded applications to use the |
| 45 | libraries. Therefore we will add the necessary locking although |
| 46 | the macros used expand to nothing for now. */ |
| 47 | # define rwlock_define(class,name) class int name |
| 48 | # define rwlock_init(lock) ((void) (lock)) |
| 49 | # define rwlock_fini(lock) ((void) (lock)) |
| 50 | # define rwlock_rdlock(lock) ((void) (lock)) |
| 51 | # define rwlock_wrlock(lock) ((void) (lock)) |
| 52 | # define rwlock_unlock(lock) ((void) (lock)) |
| 53 | #endif /* USE_LOCKS */ |
| 54 | |
| 55 | /* gettext helper macro. */ |
| 56 | #define N_(Str) Str |
| 57 | |
| 58 | /* Compiler-specific definitions. */ |
| 59 | #define strong_alias(name, aliasname) \ |
| 60 | extern __typeof (name) aliasname __attribute__ ((alias (#name))); |
| 61 | |
| 62 | #ifdef __i386__ |
| 63 | # define internal_function __attribute__ ((regparm (3), stdcall)) |
| 64 | #else |
| 65 | # define internal_function /* nothing */ |
| 66 | #endif |
| 67 | |
| 68 | #define internal_strong_alias(name, aliasname) \ |
| 69 | extern __typeof (name) aliasname __attribute__ ((alias (#name))) internal_function; |
| 70 | |
| 71 | #ifdef HAVE_VISIBILITY |
| 72 | #define attribute_hidden \ |
| 73 | __attribute__ ((visibility ("hidden"))) |
| 74 | #else |
| 75 | #define attribute_hidden /* empty */ |
| 76 | #endif |
| 77 | |
| 78 | #ifdef HAVE_GCC_STRUCT |
| 79 | #define attribute_packed \ |
| 80 | __attribute__ ((packed, gcc_struct)) |
| 81 | #else |
| 82 | #define attribute_packed \ |
| 83 | __attribute__ ((packed)) |
| 84 | #endif |
| 85 | |
| 86 | /* Define ALLOW_UNALIGNED if the architecture allows operations on |
| 87 | unaligned memory locations. */ |
| 88 | #define SANITIZE_UNDEFINED 1 |
| 89 | #if (defined __i386__ || defined __x86_64__) && ! CHECK_UNDEFINED |
| 90 | # define ALLOW_UNALIGNED 1 |
| 91 | #else |
| 92 | # define ALLOW_UNALIGNED 0 |
| 93 | #endif |
| 94 | |
| 95 | #if DEBUGPRED |
| 96 | # ifdef __x86_64__ |
| 97 | asm (".section predict_data, \"aw\"; .previous\n" |
| 98 | ".section predict_line, \"a\"; .previous\n" |
| 99 | ".section predict_file, \"a\"; .previous"); |
| 100 | # ifndef PIC |
| 101 | # define debugpred__(e, E) \ |
| 102 | ({ long int _e = !!(e); \ |
| 103 | asm volatile (".pushsection predict_data; ..predictcnt%=: .quad 0; .quad 0\n" \ |
| 104 | ".section predict_line; .quad %c1\n" \ |
| 105 | ".section predict_file; .quad %c2; .popsection\n" \ |
| 106 | "addq $1,..predictcnt%=(,%0,8)" \ |
| 107 | : : "r" (_e == E), "i" (__LINE__), "i" (__FILE__)); \ |
| 108 | __builtin_expect (_e, E); \ |
| 109 | }) |
| 110 | # endif |
| 111 | # elif defined __i386__ |
| 112 | asm (".section predict_data, \"aw\"; .previous\n" |
| 113 | ".section predict_line, \"a\"; .previous\n" |
| 114 | ".section predict_file, \"a\"; .previous"); |
| 115 | # ifndef PIC |
| 116 | # define debugpred__(e, E) \ |
| 117 | ({ long int _e = !!(e); \ |
| 118 | asm volatile (".pushsection predict_data; ..predictcnt%=: .long 0; .long 0\n" \ |
| 119 | ".section predict_line; .long %c1\n" \ |
| 120 | ".section predict_file; .long %c2; .popsection\n" \ |
| 121 | "incl ..predictcnt%=(,%0,8)" \ |
| 122 | : : "r" (_e == E), "i" (__LINE__), "i" (__FILE__)); \ |
| 123 | __builtin_expect (_e, E); \ |
| 124 | }) |
| 125 | # endif |
| 126 | # endif |
| 127 | # ifdef debugpred__ |
| 128 | # define unlikely(e) debugpred__ (e,0) |
| 129 | # define likely(e) debugpred__ (e,1) |
| 130 | # endif |
| 131 | #endif |
| 132 | #ifndef likely |
| 133 | # define unlikely(expr) __builtin_expect (!!(expr), 0) |
| 134 | # define likely(expr) __builtin_expect (!!(expr), 1) |
| 135 | #endif |
| 136 | |
| 137 | #define obstack_calloc(ob, size) \ |
| 138 | ({ size_t _s = (size); memset (obstack_alloc (ob, _s), '\0', _s); }) |
| 139 | #define obstack_strdup(ob, str) \ |
| 140 | ({ const char *_s = (str); obstack_copy0 (ob, _s, strlen (_s)); }) |
| 141 | #define obstack_strndup(ob, str, n) \ |
| 142 | ({ const char *_s = (str); obstack_copy0 (ob, _s, strnlen (_s, n)); }) |
| 143 | |
| 144 | #if __STDC_VERSION__ >= 199901L |
| 145 | # define flexarr_size /* empty */ |
| 146 | #else |
| 147 | # define flexarr_size 0 |
| 148 | #endif |
| 149 | |
| 150 | /* Calling conventions. */ |
| 151 | #ifdef __i386__ |
| 152 | # define CALLING_CONVENTION regparm (3), stdcall |
| 153 | # define AND_CALLING_CONVENTION , regparm (3), stdcall |
| 154 | #else |
| 155 | # define CALLING_CONVENTION |
| 156 | # define AND_CALLING_CONVENTION |
| 157 | #endif |
| 158 | |
| 159 | /* Avoid PLT entries. */ |
| 160 | #ifdef PIC |
| 161 | # define INTUSE(name) _INTUSE(name) |
| 162 | # define _INTUSE(name) __##name##_internal |
| 163 | # define INTDEF(name) _INTDEF(name) |
| 164 | # define _INTDEF(name) \ |
| 165 | extern __typeof__ (name) __##name##_internal __attribute__ ((alias (#name))); |
| 166 | # define INTDECL(name) _INTDECL(name) |
| 167 | # define _INTDECL(name) \ |
| 168 | extern __typeof__ (name) __##name##_internal attribute_hidden; |
| 169 | #else |
| 170 | # define INTUSE(name) name |
| 171 | # define INTDEF(name) /* empty */ |
| 172 | # define INTDECL(name) /* empty */ |
| 173 | #endif |
| 174 | |
| 175 | /* This macro is used by the tests conditionalize for standalone building. */ |
| 176 | #define ELFUTILS_HEADER(name) <lib##name.h> |
| 177 | |
| 178 | |
| 179 | #ifdef SYMBOL_VERSIONING |
| 180 | # define OLD_VERSION(name, version) \ |
| 181 | asm (".globl _compat." #version "." #name "\n" \ |
| 182 | "_compat." #version "." #name " = " #name "\n" \ |
| 183 | ".symver _compat." #version "." #name "," #name "@" #version); |
| 184 | # define NEW_VERSION(name, version) \ |
| 185 | asm (".symver " #name "," #name "@@@" #version); |
| 186 | # define COMPAT_VERSION_NEWPROTO(name, version, prefix) \ |
| 187 | asm (".symver _compat." #version "." #name "," #name "@" #version); \ |
| 188 | __typeof (_compat_##prefix##_##name) _compat_##prefix##_##name \ |
| 189 | asm ("_compat." #version "." #name); |
| 190 | # define COMPAT_VERSION(name, version, prefix) \ |
| 191 | asm (".symver _compat." #version "." #name "," #name "@" #version); \ |
| 192 | __typeof (name) _compat_##prefix##_##name asm ("_compat." #version "." #name); |
| 193 | #else |
| 194 | # define OLD_VERSION(name, version) /* Nothing for static linking. */ |
| 195 | # define NEW_VERSION(name, version) /* Nothing for static linking. */ |
| 196 | # define COMPAT_VERSION_NEWPROTO(name, version, prefix) \ |
| 197 | error "should use #ifdef SYMBOL_VERSIONING" |
| 198 | # define COMPAT_VERSION(name, version, prefix) error "should use #ifdef SYMBOL_VERSIONING" |
| 199 | #endif |
| 200 | |
| 201 | #ifndef FALLTHROUGH |
| 202 | # ifdef HAVE_FALLTHROUGH |
| 203 | # define FALLTHROUGH __attribute__ ((fallthrough)) |
| 204 | # else |
| 205 | # define FALLTHROUGH ((void) 0) |
| 206 | # endif |
| 207 | #endif |
| 208 | |
| 209 | #endif /* eu-config.h */ |