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 #define attribute_hidden \
72   __attribute__ ((visibility ("hidden")))
73 
74 /* Define ALLOW_UNALIGNED if the architecture allows operations on
75    unaligned memory locations.  */
76 #if defined __i386__ || defined __x86_64__
77 # define ALLOW_UNALIGNED	1
78 #else
79 # define ALLOW_UNALIGNED	0
80 #endif
81 
82 #if DEBUGPRED
83 # ifdef __x86_64__
84 asm (".section predict_data, \"aw\"; .previous\n"
85      ".section predict_line, \"a\"; .previous\n"
86      ".section predict_file, \"a\"; .previous");
87 #  ifndef PIC
88 #   define debugpred__(e, E) \
89   ({ long int _e = !!(e); \
90      asm volatile (".pushsection predict_data; ..predictcnt%=: .quad 0; .quad 0\n" \
91                    ".section predict_line; .quad %c1\n" \
92                    ".section predict_file; .quad %c2; .popsection\n" \
93                    "addq $1,..predictcnt%=(,%0,8)" \
94                    : : "r" (_e == E), "i" (__LINE__), "i" (__FILE__)); \
95     __builtin_expect (_e, E); \
96   })
97 #  endif
98 # elif defined __i386__
99 asm (".section predict_data, \"aw\"; .previous\n"
100      ".section predict_line, \"a\"; .previous\n"
101      ".section predict_file, \"a\"; .previous");
102 #  ifndef PIC
103 #   define debugpred__(e, E) \
104   ({ long int _e = !!(e); \
105      asm volatile (".pushsection predict_data; ..predictcnt%=: .long 0; .long 0\n" \
106                    ".section predict_line; .long %c1\n" \
107                    ".section predict_file; .long %c2; .popsection\n" \
108                    "incl ..predictcnt%=(,%0,8)" \
109                    : : "r" (_e == E), "i" (__LINE__), "i" (__FILE__)); \
110     __builtin_expect (_e, E); \
111   })
112 #  endif
113 # endif
114 # ifdef debugpred__
115 #  define unlikely(e) debugpred__ (e,0)
116 #  define likely(e) debugpred__ (e,1)
117 # endif
118 #endif
119 #ifndef likely
120 # define unlikely(expr) __builtin_expect (!!(expr), 0)
121 # define likely(expr) __builtin_expect (!!(expr), 1)
122 #endif
123 
124 #define obstack_calloc(ob, size) \
125   ({ size_t _s = (size); memset (obstack_alloc (ob, _s), '\0', _s); })
126 #define obstack_strdup(ob, str) \
127   ({ const char *_s = (str); obstack_copy0 (ob, _s, strlen (_s)); })
128 #define obstack_strndup(ob, str, n) \
129   ({ const char *_s = (str); obstack_copy0 (ob, _s, strnlen (_s, n)); })
130 
131 #if __STDC_VERSION__ >= 199901L
132 # define flexarr_size /* empty */
133 #else
134 # define flexarr_size 0
135 #endif
136 
137 /* Calling conventions.  */
138 #ifdef __i386__
139 # define CALLING_CONVENTION regparm (3), stdcall
140 # define AND_CALLING_CONVENTION , regparm (3), stdcall
141 #else
142 # define CALLING_CONVENTION
143 # define AND_CALLING_CONVENTION
144 #endif
145 
146 /* Avoid PLT entries.  */
147 #ifdef PIC
148 # define INTUSE(name) _INTUSE(name)
149 # define _INTUSE(name) __##name##_internal
150 # define INTDEF(name) _INTDEF(name)
151 # define _INTDEF(name) \
152   extern __typeof__ (name) __##name##_internal __attribute__ ((alias (#name)));
153 # define INTDECL(name) _INTDECL(name)
154 # define _INTDECL(name) \
155   extern __typeof__ (name) __##name##_internal attribute_hidden;
156 #else
157 # define INTUSE(name) name
158 # define INTDEF(name) /* empty */
159 # define INTDECL(name) /* empty */
160 #endif
161 
162 /* This macro is used by the tests conditionalize for standalone building.  */
163 #define ELFUTILS_HEADER(name) <lib##name.h>
164 
165 
166 #ifdef SHARED
167 # define OLD_VERSION(name, version) \
168   asm (".globl _compat." #version "." #name "\n" \
169        "_compat." #version "." #name " = " #name "\n" \
170        ".symver _compat." #version "." #name "," #name "@" #version);
171 # define NEW_VERSION(name, version) \
172   asm (".symver " #name "," #name "@@@" #version);
173 # define COMPAT_VERSION_NEWPROTO(name, version, prefix) \
174   asm (".symver _compat." #version "." #name "," #name "@" #version); \
175   __typeof (_compat_##prefix##_##name) _compat_##prefix##_##name \
176     asm ("_compat." #version "." #name);
177 # define COMPAT_VERSION(name, version, prefix) \
178   asm (".symver _compat." #version "." #name "," #name "@" #version); \
179   __typeof (name) _compat_##prefix##_##name asm ("_compat." #version "." #name);
180 #else
181 # define OLD_VERSION(name, version) /* Nothing for static linking.  */
182 # define NEW_VERSION(name, version) /* Nothing for static linking.  */
183 # define COMPAT_VERSION_NEWPROTO(name, version, prefix) \
184   error "should use #ifdef SHARED"
185 # define COMPAT_VERSION(name, version, prefix) error "should use #ifdef SHARED"
186 #endif
187 
188 
189 #endif	/* eu-config.h */
190