2000-06-06 Michael Snyder <msnyder@seadog.cygnus.com>
[deliverable/binutils-gdb.git] / include / elf / reloc-macros.h
CommitLineData
252b5132 1/* Generic relocation support for BFD.
859e1e49 2 Copyright (C) 1998, 2000 Free Software Foundation, Inc.
252b5132
RH
3
4 This file is part of BFD, the Binary File Descriptor library.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software Foundation,
18 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20/* These macros are used by the various *.h target specific header
21 files to either generate an enum containing all the known relocations
22 for that target, or if RELOC_MACROS_GEN_FUNC is defined, a recognition
23 function is generated instead. (This is used by binutils/readelf.c)
24
25 Given a header file like this:
26
27 START_RELOC_NUMBERS (foo)
28 RELOC_NUMBER (R_foo_NONE, 0)
29 RELOC_NUMBER (R_foo_32, 1)
30 FAKE_RELOC (R_foo_illegal, 2)
31 EMPTY_RELOC (R_foo_max)
32 END_RELOC_NUMBERS
33
34 Then the following will be produced by default (ie if
35 RELOC_MACROS_GEN_FUNC is *not* defined).
36
37 enum foo
38 {
39 foo = -1,
40 R_foo_NONE = 0,
41 R_foo_32 = 1,
42 R_foo_illegal = 2,
43 R_foo_max
44 };
45
46 If RELOC_MACROS_GEN_FUNC *is* defined, then instead the
47 following function will be generated:
48
e15e4a63
NC
49 static const char * foo PARAMS ((unsigned long rtype));
50 static const char *
252b5132
RH
51 foo (rtype)
52 unsigned long rtype;
53 {
54 switch (rtype)
55 {
56 case 0: return "R_foo_NONE";
57 case 1: return "R_foo_32";
58 default: return NULL;
59 }
60 }
61 */
859e1e49 62
252b5132
RH
63#ifndef _RELOC_MACROS_H
64#define _RELOC_MACROS_H
65
66#ifdef RELOC_MACROS_GEN_FUNC
67
68/* This function takes the relocation number and returns the
69 string version name of the name of that relocation. If
70 the relocation is not recognised, NULL is returned. */
71
72#define START_RELOC_NUMBERS(name) \
73static const char * name PARAMS ((unsigned long rtype)); \
74static const char * \
75name (rtype) \
76 unsigned long rtype; \
77{ \
78 switch (rtype) \
79 {
80
859e1e49 81#if defined (__STDC__) || defined (ALMOST_STDC)
252b5132
RH
82#define RELOC_NUMBER(name, number) case number : return #name ;
83#else
84#define RELOC_NUMBER(name, number) case number : return "name" ;
85#endif
86
859e1e49 87#define FAKE_RELOC(name, number)
252b5132 88#define EMPTY_RELOC(name)
859e1e49 89
252b5132
RH
90#define END_RELOC_NUMBERS \
91 default: return NULL; \
92 } \
93}
94
95
96#else /* Default to generating enum. */
97
98/* Some compilers cannot cope with an enum that ends with a trailing
99 comma, so START_RELOC_NUMBERS creates a fake reloc entry, (initialised
100 to -1 so that the first real entry will still default to 0). Further
101 entries then prepend a comma to their definitions, creating a list
102 of enumerator entries that will satisfy these compilers. */
859e1e49 103#if defined (__STDC__) || defined (ALMOST_STDC)
252b5132
RH
104#define START_RELOC_NUMBERS(name) enum name { _##name = -1
105#else
859e1e49 106#define START_RELOC_NUMBERS(name) enum name { _/**/name = -1
252b5132 107#endif
859e1e49 108
252b5132 109#define RELOC_NUMBER(name, number) , name = number
859e1e49
AM
110#define FAKE_RELOC(name, number) , name = number
111#define EMPTY_RELOC(name) , name
252b5132
RH
112#define END_RELOC_NUMBERS };
113
114#endif
115
116#endif /* RELOC_MACROS_H */
This page took 0.049597 seconds and 4 git commands to generate.