Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* Generic relocation support for BFD. |
8cf3f354 | 2 | Copyright 1998, 1999, 2000, 2003 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) | |
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 | ||
46 | If RELOC_MACROS_GEN_FUNC *is* defined, then instead the | |
47 | following function will be generated: | |
48 | ||
8cf3f354 | 49 | static const char *foo (unsigned long rtype); |
e15e4a63 | 50 | static const char * |
8cf3f354 | 51 | foo (unsigned long rtype) |
252b5132 RH |
52 | { |
53 | switch (rtype) | |
54 | { | |
55 | case 0: return "R_foo_NONE"; | |
56 | case 1: return "R_foo_32"; | |
57 | default: return NULL; | |
58 | } | |
59 | } | |
60 | */ | |
859e1e49 | 61 | |
252b5132 RH |
62 | #ifndef _RELOC_MACROS_H |
63 | #define _RELOC_MACROS_H | |
64 | ||
65 | #ifdef RELOC_MACROS_GEN_FUNC | |
66 | ||
67 | /* This function takes the relocation number and returns the | |
68 | string version name of the name of that relocation. If | |
69 | the relocation is not recognised, NULL is returned. */ | |
70 | ||
71 | #define START_RELOC_NUMBERS(name) \ | |
8cf3f354 | 72 | static const char *name (unsigned long rtype); \ |
252b5132 | 73 | static const char * \ |
8cf3f354 | 74 | name (unsigned long rtype) \ |
252b5132 RH |
75 | { \ |
76 | switch (rtype) \ | |
8cf3f354 | 77 | { |
252b5132 | 78 | |
8cf3f354 AM |
79 | #define RELOC_NUMBER(name, number) \ |
80 | case number: return #name; | |
252b5132 | 81 | |
859e1e49 | 82 | #define FAKE_RELOC(name, number) |
252b5132 | 83 | #define EMPTY_RELOC(name) |
859e1e49 | 84 | |
1b452ec6 | 85 | #define END_RELOC_NUMBERS(name) \ |
252b5132 | 86 | default: return NULL; \ |
8cf3f354 | 87 | } \ |
252b5132 RH |
88 | } |
89 | ||
90 | ||
91 | #else /* Default to generating enum. */ | |
92 | ||
1b452ec6 AM |
93 | #define START_RELOC_NUMBERS(name) enum name { |
94 | #define RELOC_NUMBER(name, number) name = number, | |
95 | #define FAKE_RELOC(name, number) name = number, | |
96 | #define EMPTY_RELOC(name) name, | |
97 | #define END_RELOC_NUMBERS(name) name }; | |
252b5132 RH |
98 | |
99 | #endif | |
100 | ||
101 | #endif /* RELOC_MACROS_H */ |