]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - include/elf/reloc-macros.h
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / include / elf / reloc-macros.h
CommitLineData
252b5132 1/* Generic relocation support for BFD.
250d07de 2 Copyright (C) 1998-2021 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
e4e42b45 8 the Free Software Foundation; either version 3 of the License, or
252b5132
RH
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,
e172dbf8 18 Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
252b5132
RH
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)
1b452ec6
AM
30 EMPTY_RELOC (R_foo_good)
31 FAKE_RELOC (R_foo_illegal, 9)
32 END_RELOC_NUMBERS (R_foo_count)
252b5132
RH
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 {
252b5132
RH
39 R_foo_NONE = 0,
40 R_foo_32 = 1,
1b452ec6
AM
41 R_foo_good,
42 R_foo_illegal = 9,
43 R_foo_count
252b5132
RH
44 };
45
7c90103b
NC
46 Note: The value of the symbol defined in the END_RELOC_NUMBERS
47 macro (R_foo_count in the case of the example above) will be
cc643b88 48 set to the value of the whichever *_RELOC macro precedes it plus
7c90103b
NC
49 one. Therefore if you intend to use the symbol as a sentinel for
50 the highest valid macro value you should make sure that the
cc643b88 51 preceding *_RELOC macro is the highest valid number. ie a
7c90103b
NC
52 declaration like this:
53
54 START_RELOC_NUMBERS (foo)
55 RELOC_NUMBER (R_foo_NONE, 0)
56 RELOC_NUMBER (R_foo_32, 1)
57 FAKE_RELOC (R_foo_illegal, 9)
58 FAKE_RELOC (R_foo_synonym, 0)
59 END_RELOC_NUMBERS (R_foo_count)
60
61 will result in R_foo_count having a value of 1 (R_foo_synonym + 1)
62 rather than 10 or 2 as might be expected.
63
64 Alternatively you can assign a value to END_RELOC_NUMBERS symbol
65 explicitly, like this:
66
67 START_RELOC_NUMBERS (foo)
68 RELOC_NUMBER (R_foo_NONE, 0)
69 RELOC_NUMBER (R_foo_32, 1)
70 FAKE_RELOC (R_foo_illegal, 9)
71 FAKE_RELOC (R_foo_synonym, 0)
72 END_RELOC_NUMBERS (R_foo_count = 2)
73
252b5132
RH
74 If RELOC_MACROS_GEN_FUNC *is* defined, then instead the
75 following function will be generated:
76
8cf3f354 77 static const char *foo (unsigned long rtype);
e15e4a63 78 static const char *
8cf3f354 79 foo (unsigned long rtype)
252b5132
RH
80 {
81 switch (rtype)
82 {
83 case 0: return "R_foo_NONE";
84 case 1: return "R_foo_32";
85 default: return NULL;
86 }
87 }
88 */
859e1e49 89
252b5132
RH
90#ifndef _RELOC_MACROS_H
91#define _RELOC_MACROS_H
92
93#ifdef RELOC_MACROS_GEN_FUNC
94
95/* This function takes the relocation number and returns the
96 string version name of the name of that relocation. If
97 the relocation is not recognised, NULL is returned. */
98
99#define START_RELOC_NUMBERS(name) \
8cf3f354 100static const char *name (unsigned long rtype); \
252b5132 101static const char * \
8cf3f354 102name (unsigned long rtype) \
252b5132
RH
103{ \
104 switch (rtype) \
8cf3f354 105 {
252b5132 106
8cf3f354
AM
107#define RELOC_NUMBER(name, number) \
108 case number: return #name;
252b5132 109
859e1e49 110#define FAKE_RELOC(name, number)
252b5132 111#define EMPTY_RELOC(name)
859e1e49 112
1b452ec6 113#define END_RELOC_NUMBERS(name) \
252b5132 114 default: return NULL; \
8cf3f354 115 } \
252b5132
RH
116}
117
118
119#else /* Default to generating enum. */
120
1b452ec6
AM
121#define START_RELOC_NUMBERS(name) enum name {
122#define RELOC_NUMBER(name, number) name = number,
123#define FAKE_RELOC(name, number) name = number,
124#define EMPTY_RELOC(name) name,
125#define END_RELOC_NUMBERS(name) name };
252b5132
RH
126
127#endif
128
63646b7a 129#endif /* _RELOC_MACROS_H */