source: rtems-tools/rtemstoolkit/elftoolchain/common/_elftc.h @ b0b9366

5
Last change on this file since b0b9366 was feafa6f, checked in by Joel Sherrill <joel@…>, on 04/30/18 at 23:08:12

_elftc.h: Make compile on Cygwin

  • Property mode set to 100644
File size: 13.5 KB
Line 
1/*-
2 * Copyright (c) 2009 Joseph Koshy
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $Id: _elftc.h 3446 2016-05-03 01:31:17Z emaste $
27 */
28
29/**
30 ** Miscellaneous definitions needed by multiple components.
31 **/
32
33#ifndef _ELFTC_H
34#define _ELFTC_H
35
36#ifndef NULL
37#define NULL    ((void *) 0)
38#endif
39
40#ifndef offsetof
41#define offsetof(T, M)          ((int) &((T*) 0) -> M)
42#endif
43
44/* --QUEUE-MACROS-- [[ */
45
46/*
47 * Supply macros missing from <sys/queue.h>
48 */
49
50/*
51 * Copyright (c) 1991, 1993
52 *      The Regents of the University of California.  All rights reserved.
53 *
54 * Redistribution and use in source and binary forms, with or without
55 * modification, are permitted provided that the following conditions
56 * are met:
57 * 1. Redistributions of source code must retain the above copyright
58 *    notice, this list of conditions and the following disclaimer.
59 * 2. Redistributions in binary form must reproduce the above copyright
60 *    notice, this list of conditions and the following disclaimer in the
61 *    documentation and/or other materials provided with the distribution.
62 * 3. Neither the name of the University nor the names of its contributors
63 *    may be used to endorse or promote products derived from this software
64 *    without specific prior written permission.
65 *
66 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
67 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
68 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
69 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
70 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
71 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
72 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
73 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
74 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
75 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
76 * SUCH DAMAGE.
77 */
78
79#ifndef LIST_FOREACH_SAFE
80#define LIST_FOREACH_SAFE(var, head, field, tvar)               \
81        for ((var) = LIST_FIRST((head));                        \
82            (var) && ((tvar) = LIST_NEXT((var), field), 1);     \
83            (var) = (tvar))
84#endif
85
86#ifndef SLIST_FOREACH_SAFE
87#define SLIST_FOREACH_SAFE(var, head, field, tvar)              \
88        for ((var) = SLIST_FIRST((head));                       \
89            (var) && ((tvar) = SLIST_NEXT((var), field), 1);    \
90            (var) = (tvar))
91#endif
92
93#ifndef STAILQ_CONCAT
94#define STAILQ_CONCAT(head1, head2) do {                        \
95        if (!STAILQ_EMPTY((head2))) {                           \
96                *(head1)->stqh_last = (head2)->stqh_first;      \
97                (head1)->stqh_last = (head2)->stqh_last;        \
98                STAILQ_INIT((head2));                           \
99        }                                                       \
100} while (/*CONSTCOND*/0)
101#endif
102
103#ifndef STAILQ_EMPTY
104#define STAILQ_EMPTY(head)      ((head)->stqh_first == NULL)
105#endif
106
107#ifndef STAILQ_ENTRY
108#define STAILQ_ENTRY(type)                                      \
109struct {                                                        \
110        struct type *stqe_next; /* next element */              \
111}
112#endif
113
114#ifndef STAILQ_FIRST
115#define STAILQ_FIRST(head)      ((head)->stqh_first)
116#endif
117
118#ifndef STAILQ_HEAD
119#define STAILQ_HEAD(name, type)                                 \
120struct name {                                                   \
121        struct type *stqh_first; /* first element */            \
122        struct type **stqh_last; /* addr of last next element */ \
123}
124#endif
125
126#ifndef STAILQ_HEAD_INITIALIZER
127#define STAILQ_HEAD_INITIALIZER(head)                           \
128        { NULL, &(head).stqh_first }
129#endif
130
131#ifndef STAILQ_FOREACH
132#define STAILQ_FOREACH(var, head, field)                        \
133        for ((var) = ((head)->stqh_first);                      \
134                (var);                                          \
135                (var) = ((var)->field.stqe_next))
136#endif
137
138#ifndef STAILQ_FOREACH_SAFE
139#define STAILQ_FOREACH_SAFE(var, head, field, tvar)             \
140       for ((var) = STAILQ_FIRST((head));                       \
141            (var) && ((tvar) = STAILQ_NEXT((var), field), 1);   \
142            (var) = (tvar))
143#endif
144
145#ifndef STAILQ_INIT
146#define STAILQ_INIT(head) do {                                  \
147        (head)->stqh_first = NULL;                              \
148        (head)->stqh_last = &(head)->stqh_first;                \
149} while (/*CONSTCOND*/0)
150#endif
151
152#ifndef STAILQ_INSERT_HEAD
153#define STAILQ_INSERT_HEAD(head, elm, field) do {                       \
154        if (((elm)->field.stqe_next = (head)->stqh_first) == NULL)      \
155                (head)->stqh_last = &(elm)->field.stqe_next;            \
156        (head)->stqh_first = (elm);                                     \
157} while (/*CONSTCOND*/0)
158#endif
159
160#ifndef STAILQ_INSERT_TAIL
161#define STAILQ_INSERT_TAIL(head, elm, field) do {                       \
162        (elm)->field.stqe_next = NULL;                                  \
163        *(head)->stqh_last = (elm);                                     \
164        (head)->stqh_last = &(elm)->field.stqe_next;                    \
165} while (/*CONSTCOND*/0)
166#endif
167
168#ifndef STAILQ_INSERT_AFTER
169#define STAILQ_INSERT_AFTER(head, listelm, elm, field) do {             \
170        if (((elm)->field.stqe_next = (listelm)->field.stqe_next) == NULL)\
171                (head)->stqh_last = &(elm)->field.stqe_next;            \
172        (listelm)->field.stqe_next = (elm);                             \
173} while (/*CONSTCOND*/0)
174#endif
175
176#ifndef STAILQ_LAST
177#define STAILQ_LAST(head, type, field)                                  \
178        (STAILQ_EMPTY((head)) ?                                 \
179            NULL : ((struct type *)(void *)                             \
180            ((char *)((head)->stqh_last) - offsetof(struct type, field))))
181#endif
182
183#ifndef STAILQ_NEXT
184#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
185#endif
186
187#ifndef STAILQ_REMOVE
188#define STAILQ_REMOVE(head, elm, type, field) do {                      \
189        if ((head)->stqh_first == (elm)) {                              \
190                STAILQ_REMOVE_HEAD((head), field);                      \
191        } else {                                                        \
192                struct type *curelm = (head)->stqh_first;               \
193                while (curelm->field.stqe_next != (elm))                \
194                        curelm = curelm->field.stqe_next;               \
195                if ((curelm->field.stqe_next =                          \
196                        curelm->field.stqe_next->field.stqe_next) == NULL) \
197                            (head)->stqh_last = &(curelm)->field.stqe_next; \
198        }                                                               \
199} while (/*CONSTCOND*/0)
200#endif
201
202#ifndef STAILQ_REMOVE_HEAD
203#define STAILQ_REMOVE_HEAD(head, field) do {                            \
204        if (((head)->stqh_first = (head)->stqh_first->field.stqe_next) == \
205            NULL)                                                       \
206                (head)->stqh_last = &(head)->stqh_first;                \
207} while (/*CONSTCOND*/0)
208#endif
209
210/*
211 * The STAILQ_SORT macro is adapted from Simon Tatham's O(n*log(n))
212 * mergesort algorithm.
213 */
214#ifndef STAILQ_SORT
215#define STAILQ_SORT(head, type, field, cmp) do {                        \
216        STAILQ_HEAD(, type) _la, _lb;                                   \
217        struct type *_p, *_q, *_e;                                      \
218        int _i, _sz, _nmerges, _psz, _qsz;                              \
219                                                                        \
220        _sz = 1;                                                        \
221        do {                                                            \
222                _nmerges = 0;                                           \
223                STAILQ_INIT(&_lb);                                      \
224                while (!STAILQ_EMPTY((head))) {                         \
225                        _nmerges++;                                     \
226                        STAILQ_INIT(&_la);                              \
227                        _psz = 0;                                       \
228                        for (_i = 0; _i < _sz && !STAILQ_EMPTY((head)); \
229                             _i++) {                                    \
230                                _e = STAILQ_FIRST((head));              \
231                                if (_e == NULL)                         \
232                                        break;                          \
233                                _psz++;                                 \
234                                STAILQ_REMOVE_HEAD((head), field);      \
235                                STAILQ_INSERT_TAIL(&_la, _e, field);    \
236                        }                                               \
237                        _p = STAILQ_FIRST(&_la);                        \
238                        _qsz = _sz;                                     \
239                        _q = STAILQ_FIRST((head));                      \
240                        while (_psz > 0 || (_qsz > 0 && _q != NULL)) {  \
241                                if (_psz == 0) {                        \
242                                        _e = _q;                        \
243                                        _q = STAILQ_NEXT(_q, field);    \
244                                        STAILQ_REMOVE_HEAD((head),      \
245                                            field);                     \
246                                        _qsz--;                         \
247                                } else if (_qsz == 0 || _q == NULL) {   \
248                                        _e = _p;                        \
249                                        _p = STAILQ_NEXT(_p, field);    \
250                                        STAILQ_REMOVE_HEAD(&_la, field);\
251                                        _psz--;                         \
252                                } else if (cmp(_p, _q) <= 0) {          \
253                                        _e = _p;                        \
254                                        _p = STAILQ_NEXT(_p, field);    \
255                                        STAILQ_REMOVE_HEAD(&_la, field);\
256                                        _psz--;                         \
257                                } else {                                \
258                                        _e = _q;                        \
259                                        _q = STAILQ_NEXT(_q, field);    \
260                                        STAILQ_REMOVE_HEAD((head),      \
261                                            field);                     \
262                                        _qsz--;                         \
263                                }                                       \
264                                STAILQ_INSERT_TAIL(&_lb, _e, field);    \
265                        }                                               \
266                }                                                       \
267                (head)->stqh_first = _lb.stqh_first;                    \
268                (head)->stqh_last = _lb.stqh_last;                      \
269                _sz *= 2;                                               \
270        } while (_nmerges > 1);                                         \
271} while (/*CONSTCOND*/0)
272#endif
273
274#ifndef TAILQ_FOREACH_SAFE
275#define TAILQ_FOREACH_SAFE(var, head, field, tvar)                      \
276        for ((var) = TAILQ_FIRST((head));                               \
277            (var) && ((tvar) = TAILQ_NEXT((var), field), 1);            \
278            (var) = (tvar))
279#endif
280
281/* ]] --QUEUE-MACROS-- */
282
283/*
284 * VCS Ids.
285 */
286
287#ifndef ELFTC_VCSID
288
289#if defined(__DragonFly__)
290#define ELFTC_VCSID(ID)         __RCSID(ID)
291#endif
292
293#if defined(__FreeBSD__)
294#define ELFTC_VCSID(ID)         __FBSDID(ID)
295#endif
296
297#if defined(__APPLE__) || defined(__GLIBC__) || defined(__GNU__) || \
298    defined(__linux__)
299#if defined(__GNUC__)
300#define ELFTC_VCSID(ID)         __asm__(".ident\t\"" ID "\"")
301#else
302#define ELFTC_VCSID(ID)         /**/
303#endif
304#endif
305
306#if defined(__minix)
307#if defined(__GNUC__)
308#define ELFTC_VCSID(ID)         __asm__(".ident\t\"" ID "\"")
309#else
310#define ELFTC_VCSID(ID)         /**/
311#endif  /* __GNU__ */
312#endif
313
314#if defined(__NetBSD__)
315#define ELFTC_VCSID(ID)         __RCSID(ID)
316#endif
317
318#if defined(__OpenBSD__)
319#if defined(__GNUC__)
320#define ELFTC_VCSID(ID)         __asm__(".ident\t\"" ID "\"")
321#else
322#define ELFTC_VCSID(ID)         /**/
323#endif  /* __GNUC__ */
324#endif
325
326#ifndef ELFTC_VCSID
327#define ELFTC_VCSID(ID)         /**/
328#endif
329
330#endif  /* ELFTC_VCSID */
331
332/*
333 * Provide an equivalent for getprogname(3).
334 */
335
336#ifndef ELFTC_GETPROGNAME
337
338#if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) || \
339    defined(__minix) || defined(__NetBSD__)
340
341#include <stdlib.h>
342
343#define ELFTC_GETPROGNAME()     getprogname()
344
345#endif  /* __DragonFly__ || __FreeBSD__ || __minix || __NetBSD__ */
346
347
348#if defined(__GLIBC__) || defined(__linux__)
349#ifndef _GNU_SOURCE
350/*
351 * GLIBC based systems have a global 'char *' pointer referencing
352 * the executable's name.
353 */
354extern const char *program_invocation_short_name;
355#endif  /* !_GNU_SOURCE */
356
357#define ELFTC_GETPROGNAME()     program_invocation_short_name
358
359#endif  /* __GLIBC__ || __linux__ */
360
361
362#if defined(__OpenBSD__)
363
364extern const char *__progname;
365
366#define ELFTC_GETPROGNAME()     __progname
367
368#endif  /* __OpenBSD__ */
369
370#ifndef ELFTC_GETPROGNAME
371#define ELFTC_GETPROGNAME() "no_progname"
372#endif
373
374#endif  /* ELFTC_GETPROGNAME */
375
376
377/**
378 ** Per-OS configuration.
379 **/
380
381#if defined(__APPLE__)
382
383#include <libkern/OSByteOrder.h>
384#define htobe32(x)      OSSwapHostToBigInt32(x)
385#define roundup2        roundup
386
387#define ELFTC_BYTE_ORDER                        _BYTE_ORDER
388#define ELFTC_BYTE_ORDER_LITTLE_ENDIAN          _LITTLE_ENDIAN
389#define ELFTC_BYTE_ORDER_BIG_ENDIAN             _BIG_ENDIAN
390
391#define ELFTC_HAVE_MMAP                         1
392#define ELFTC_HAVE_STRMODE                      1
393
394#define ELFTC_NEED_BYTEORDER_EXTENSIONS         1
395#endif /* __APPLE__ */
396
397
398#if defined(__DragonFly__)
399
400#include <osreldate.h>
401#include <sys/endian.h>
402
403#define ELFTC_BYTE_ORDER                        _BYTE_ORDER
404#define ELFTC_BYTE_ORDER_LITTLE_ENDIAN          _LITTLE_ENDIAN
405#define ELFTC_BYTE_ORDER_BIG_ENDIAN             _BIG_ENDIAN
406
407#define ELFTC_HAVE_MMAP                         1
408
409#endif
410
411#if defined(__GLIBC__) || defined(__linux__)
412
413#include <endian.h>
414
415#define ELFTC_BYTE_ORDER                        __BYTE_ORDER
416#define ELFTC_BYTE_ORDER_LITTLE_ENDIAN          __LITTLE_ENDIAN
417#define ELFTC_BYTE_ORDER_BIG_ENDIAN             __BIG_ENDIAN
418
419#define ELFTC_HAVE_MMAP                         1
420
421/*
422 * Debian GNU/Linux and Debian GNU/kFreeBSD do not have strmode(3).
423 */
424#define ELFTC_HAVE_STRMODE                      0
425
426/* Whether we need to supply {be,le}32dec. */
427#define ELFTC_NEED_BYTEORDER_EXTENSIONS         1
428
429#define roundup2        roundup
430
431#endif  /* __GLIBC__ || __linux__ */
432
433
434#if defined(__FreeBSD__)
435
436#include <osreldate.h>
437#include <sys/endian.h>
438
439#define ELFTC_BYTE_ORDER                        _BYTE_ORDER
440#define ELFTC_BYTE_ORDER_LITTLE_ENDIAN          _LITTLE_ENDIAN
441#define ELFTC_BYTE_ORDER_BIG_ENDIAN             _BIG_ENDIAN
442
443#define ELFTC_HAVE_MMAP                         1
444#define ELFTC_HAVE_STRMODE                      1
445#if __FreeBSD_version <= 900000
446#define ELFTC_BROKEN_YY_NO_INPUT                1
447#endif
448#endif  /* __FreeBSD__ */
449
450
451#if defined(__minix)
452#define ELFTC_HAVE_MMAP                         0
453#endif  /* __minix */
454
455
456#if defined(__NetBSD__)
457
458#include <sys/param.h>
459#include <sys/endian.h>
460
461#define ELFTC_BYTE_ORDER                        _BYTE_ORDER
462#define ELFTC_BYTE_ORDER_LITTLE_ENDIAN          _LITTLE_ENDIAN
463#define ELFTC_BYTE_ORDER_BIG_ENDIAN             _BIG_ENDIAN
464
465#define ELFTC_HAVE_MMAP                         1
466#define ELFTC_HAVE_STRMODE                      1
467#if __NetBSD_Version__ <= 599002100
468/* from src/doc/CHANGES: flex(1): Import flex-2.5.35 [christos 20091025] */
469/* and 5.99.21 was from Wed Oct 21 21:28:36 2009 UTC */
470#  define ELFTC_BROKEN_YY_NO_INPUT              1
471#endif
472#endif  /* __NetBSD __ */
473
474
475#if defined(__OpenBSD__)
476
477#include <sys/param.h>
478#include <sys/endian.h>
479
480#define ELFTC_BYTE_ORDER                        _BYTE_ORDER
481#define ELFTC_BYTE_ORDER_LITTLE_ENDIAN          _LITTLE_ENDIAN
482#define ELFTC_BYTE_ORDER_BIG_ENDIAN             _BIG_ENDIAN
483
484#define ELFTC_HAVE_MMAP                         1
485#define ELFTC_HAVE_STRMODE                      1
486
487#define ELFTC_NEED_BYTEORDER_EXTENSIONS         1
488#define roundup2        roundup
489
490#endif  /* __OpenBSD__ */
491
492#if defined(__WIN32__) || defined(__CYGWIN__)
493
494#if defined(__CYGWIN__)
495#include <endian.h>
496#else /* __CYGWIN */
497#include <winsock2.h>
498#define htobe32(x)      (x)
499#endif /* __WIN32__ */
500
501#include <sys/param.h>
502
503#define ELFTC_BYTE_ORDER                        _BYTE_ORDER
504#define ELFTC_BYTE_ORDER_LITTLE_ENDIAN          _LITTLE_ENDIAN
505#define ELFTC_BYTE_ORDER_BIG_ENDIAN             _BIG_ENDIAN
506
507#define ELFTC_HAVE_MMAP                         1
508
509#endif  /* __WIN32__ || __CYGWIN__ */
510
511#endif  /* _ELFTC_H */
Note: See TracBrowser for help on using the repository browser.