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