xref: /third_party/elfutils/lib/eu-config.h (revision da0c48c4)
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#include <libintl.h>
56/* gettext helper macros.  */
57#define N_(Str) Str
58#define _(Str) dgettext ("elfutils", Str)
59
60/* Compiler-specific definitions.  */
61#define strong_alias(name, aliasname) \
62  extern __typeof (name) aliasname __attribute__ ((alias (#name)));
63
64#ifdef __i386__
65# define internal_function __attribute__ ((regparm (3), stdcall))
66#else
67# define internal_function /* nothing */
68#endif
69
70#define internal_strong_alias(name, aliasname) \
71  extern __typeof (name) aliasname __attribute__ ((alias (#name))) internal_function;
72
73#ifdef HAVE_VISIBILITY
74#define attribute_hidden \
75  __attribute__ ((visibility ("hidden")))
76#else
77#define attribute_hidden /* empty */
78#endif
79
80#ifdef HAVE_GCC_STRUCT
81#define attribute_packed \
82  __attribute__ ((packed, gcc_struct))
83#else
84#define attribute_packed \
85  __attribute__ ((packed))
86#endif
87
88/* Define ALLOW_UNALIGNED if the architecture allows operations on
89   unaligned memory locations.  */
90#define SANITIZE_UNDEFINED 1
91#if (defined __i386__ || defined __x86_64__) && ! CHECK_UNDEFINED
92# define ALLOW_UNALIGNED	1
93#else
94# define ALLOW_UNALIGNED	0
95#endif
96
97#if DEBUGPRED
98# ifdef __x86_64__
99asm (".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%=: .quad 0; .quad 0\n" \
106                   ".section predict_line; .quad %c1\n" \
107                   ".section predict_file; .quad %c2; .popsection\n" \
108                   "addq $1,..predictcnt%=(,%0,8)" \
109                   : : "r" (_e == E), "i" (__LINE__), "i" (__FILE__)); \
110    __builtin_expect (_e, E); \
111  })
112#  endif
113# elif defined __i386__
114asm (".section predict_data, \"aw\"; .previous\n"
115     ".section predict_line, \"a\"; .previous\n"
116     ".section predict_file, \"a\"; .previous");
117#  ifndef PIC
118#   define debugpred__(e, E) \
119  ({ long int _e = !!(e); \
120     asm volatile (".pushsection predict_data; ..predictcnt%=: .long 0; .long 0\n" \
121                   ".section predict_line; .long %c1\n" \
122                   ".section predict_file; .long %c2; .popsection\n" \
123                   "incl ..predictcnt%=(,%0,8)" \
124                   : : "r" (_e == E), "i" (__LINE__), "i" (__FILE__)); \
125    __builtin_expect (_e, E); \
126  })
127#  endif
128# endif
129# ifdef debugpred__
130#  define unlikely(e) debugpred__ (e,0)
131#  define likely(e) debugpred__ (e,1)
132# endif
133#endif
134#ifndef likely
135# define unlikely(expr) __builtin_expect (!!(expr), 0)
136# define likely(expr) __builtin_expect (!!(expr), 1)
137#endif
138
139#define obstack_calloc(ob, size) \
140  ({ size_t _s = (size); memset (obstack_alloc (ob, _s), '\0', _s); })
141#define obstack_strdup(ob, str) \
142  ({ const char *_s = (str); obstack_copy0 (ob, _s, strlen (_s)); })
143#define obstack_strndup(ob, str, n) \
144  ({ const char *_s = (str); obstack_copy0 (ob, _s, strnlen (_s, n)); })
145
146#if __STDC_VERSION__ >= 199901L
147# define flexarr_size /* empty */
148#else
149# define flexarr_size 0
150#endif
151
152/* Calling conventions.  */
153#ifdef __i386__
154# define CALLING_CONVENTION regparm (3), stdcall
155# define AND_CALLING_CONVENTION , regparm (3), stdcall
156#else
157# define CALLING_CONVENTION
158# define AND_CALLING_CONVENTION
159#endif
160
161/* Avoid PLT entries.  */
162#ifdef PIC
163# define INTUSE(name) _INTUSE(name)
164# define _INTUSE(name) __##name##_internal
165# define INTDEF(name) _INTDEF(name)
166# define _INTDEF(name) \
167  extern __typeof__ (name) __##name##_internal __attribute__ ((alias (#name)));
168# define INTDECL(name) _INTDECL(name)
169# define _INTDECL(name) \
170  extern __typeof__ (name) __##name##_internal attribute_hidden;
171#else
172# define INTUSE(name) name
173# define INTDEF(name) /* empty */
174# define INTDECL(name) /* empty */
175#endif
176
177/* This macro is used by the tests conditionalize for standalone building.  */
178#define ELFUTILS_HEADER(name) <lib##name.h>
179
180/* Don't reorder with global asm blocks or optimize away. (Doesn't reliably
181   keep it in the same LTO partition, though; -flto-partition=none may be
182   still needed for some gcc versions < 10.) */
183#ifdef __has_attribute
184# if __has_attribute(no_reorder)
185#  define used_in_asm __attribute__ ((externally_visible, no_reorder))
186# endif
187#endif
188#ifndef used_in_asm
189# define used_in_asm /* empty */
190#endif
191
192#ifdef SYMBOL_VERSIONING
193# define NEW_INTDEF(name) __typeof (name) INTUSE(name) \
194  __attribute__ ((alias ("_new." #name))) attribute_hidden;
195# ifdef __has_attribute
196#  if __has_attribute(symver)
197#   define NEW_VERSION(name, version) \
198  __typeof (name) name __asm__ ("_new." #name) \
199    __attribute__ ((symver (#name "@@" #version)));
200#   define OLD_VERSION(name, version) _OLD_VERSION1(name, __COUNTER__, version)
201#   define _OLD_VERSION1(name, num, version) _OLD_VERSION2(name, num, version)
202#   define _OLD_VERSION2(name, num, version) \
203  __typeof (name) _compat_old##num##_##name \
204    __asm__ ("_compat." #version "." #name) \
205    __attribute__ ((alias ("_new." #name), symver (#name "@" #version)));
206#   define COMPAT_VERSION_NEWPROTO(name, version, prefix) \
207  __typeof (_compat_##prefix##_##name) _compat_##prefix##_##name \
208    __asm__ ("_compat." #version "." #name) \
209    __attribute__ ((symver (#name "@" #version)));
210#   define COMPAT_VERSION(name, version, prefix) \
211  asm (".symver _compat." #version "." #name "," #name "@" #version); \
212  __typeof (name) _compat_##prefix##_##name \
213    __asm__ ("_compat." #version "." #name) \
214    __attribute__ ((symver (#name "@" #version)));
215#  endif
216# endif
217# ifndef NEW_VERSION
218#  define OLD_VERSION(name, version) \
219  asm (".globl _compat." #version "." #name "\n\t" \
220       "_compat." #version "." #name " = _new." #name "\n\t" \
221       ".symver _compat." #version "." #name "," #name "@" #version);
222#  define NEW_VERSION(name, version) \
223  __typeof (name) name __asm__ ("_new." #name) used_in_asm; \
224  asm (".symver _new." #name ", " #name "@@" #version);
225#  define COMPAT_VERSION_NEWPROTO(name, version, prefix) \
226  __typeof (_compat_##prefix##_##name) _compat_##prefix##_##name \
227    __asm__ ("_compat." #version "." #name) used_in_asm; \
228  asm (".symver _compat." #version "." #name ", " #name "@" #version);
229#  define COMPAT_VERSION(name, version, prefix) \
230  __typeof (name) _compat_##prefix##_##name \
231    __asm__ ("_compat." #version "." #name) used_in_asm; \
232  asm (".symver _compat." #version "." #name ", " #name "@" #version);
233# endif
234#else
235# define NEW_INTDEF(name) INTDEF(name)
236# define OLD_VERSION(name, version) /* Nothing for static linking.  */
237# define NEW_VERSION(name, version) /* Nothing for static linking.  */
238# define COMPAT_VERSION_NEWPROTO(name, version, prefix) \
239  error "should use #ifdef SYMBOL_VERSIONING"
240# define COMPAT_VERSION(name, version, prefix) \
241  error "should use #ifdef SYMBOL_VERSIONING"
242#endif
243
244#ifndef FALLTHROUGH
245# ifdef HAVE_FALLTHROUGH
246#  define FALLTHROUGH __attribute__ ((fallthrough))
247# else
248#  define FALLTHROUGH ((void) 0)
249# endif
250#endif
251
252#endif	/* eu-config.h */
253