Back to index

cell-binutils  2.17cvs20070401
reloc-macros.h
Go to the documentation of this file.
00001 /* Generic relocation support for BFD.
00002    Copyright 1998, 1999, 2000, 2003 Free Software Foundation, Inc.
00003 
00004    This file is part of BFD, the Binary File Descriptor library.
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software Foundation,
00018    Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00019 
00020 /* These macros are used by the various *.h target specific header
00021    files to either generate an enum containing all the known relocations
00022    for that target, or if RELOC_MACROS_GEN_FUNC is defined, a recognition
00023    function is generated instead.  (This is used by binutils/readelf.c)
00024 
00025    Given a header file like this:
00026 
00027        START_RELOC_NUMBERS (foo)
00028            RELOC_NUMBER (R_foo_NONE,    0)
00029            RELOC_NUMBER (R_foo_32,      1)
00030            EMPTY_RELOC  (R_foo_good)
00031            FAKE_RELOC   (R_foo_illegal, 9)
00032        END_RELOC_NUMBERS (R_foo_count)
00033 
00034    Then the following will be produced by default (ie if
00035    RELOC_MACROS_GEN_FUNC is *not* defined).
00036 
00037        enum foo
00038        {
00039          R_foo_NONE = 0,
00040          R_foo_32 = 1,
00041          R_foo_good,
00042          R_foo_illegal = 9,
00043          R_foo_count
00044        };
00045 
00046    If RELOC_MACROS_GEN_FUNC *is* defined, then instead the
00047    following function will be generated:
00048 
00049        static const char *foo (unsigned long rtype);
00050        static const char *
00051        foo (unsigned long rtype)
00052        {
00053           switch (rtype)
00054           {
00055           case 0: return "R_foo_NONE";
00056           case 1: return "R_foo_32";
00057           default: return NULL;
00058           }
00059        }
00060    */
00061 
00062 #ifndef _RELOC_MACROS_H
00063 #define _RELOC_MACROS_H
00064 
00065 #ifdef RELOC_MACROS_GEN_FUNC
00066 
00067 /* This function takes the relocation number and returns the
00068    string version name of the name of that relocation.  If
00069    the relocation is not recognised, NULL is returned.  */
00070 
00071 #define START_RELOC_NUMBERS(name)                              \
00072 static const char *name (unsigned long rtype);                 \
00073 static const char *                                     \
00074 name (unsigned long rtype)                              \
00075 {                                                       \
00076   switch (rtype)                                        \
00077     {
00078 
00079 #define RELOC_NUMBER(name, number) \
00080     case number: return #name;
00081 
00082 #define FAKE_RELOC(name, number)
00083 #define EMPTY_RELOC(name)
00084 
00085 #define END_RELOC_NUMBERS(name)    \
00086     default: return NULL;   \
00087     }                       \
00088 }
00089 
00090 
00091 #else /* Default to generating enum.  */
00092 
00093 #define START_RELOC_NUMBERS(name)   enum name {
00094 #define RELOC_NUMBER(name, number)  name = number,
00095 #define FAKE_RELOC(name, number)    name = number,
00096 #define EMPTY_RELOC(name)           name,
00097 #define END_RELOC_NUMBERS(name)     name };
00098 
00099 #endif
00100 
00101 #endif /* _RELOC_MACROS_H */