Blame include/elf/reloc-macros.h

Packit bbfece
/* Generic relocation support for BFD.
Packit bbfece
   Copyright (C) 1998-2018 Free Software Foundation, Inc.
Packit bbfece
Packit bbfece
   This file is part of BFD, the Binary File Descriptor library.
Packit bbfece
Packit bbfece
   This program is free software; you can redistribute it and/or modify
Packit bbfece
   it under the terms of the GNU General Public License as published by
Packit bbfece
   the Free Software Foundation; either version 3 of the License, or
Packit bbfece
   (at your option) any later version.
Packit bbfece
Packit bbfece
   This program is distributed in the hope that it will be useful,
Packit bbfece
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit bbfece
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit bbfece
   GNU General Public License for more details.
Packit bbfece
Packit bbfece
   You should have received a copy of the GNU General Public License
Packit bbfece
   along with this program; if not, write to the Free Software Foundation,
Packit bbfece
   Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
Packit bbfece
Packit bbfece
/* These macros are used by the various *.h target specific header
Packit bbfece
   files to either generate an enum containing all the known relocations
Packit bbfece
   for that target, or if RELOC_MACROS_GEN_FUNC is defined, a recognition
Packit bbfece
   function is generated instead.  (This is used by binutils/readelf.c)
Packit bbfece
Packit bbfece
   Given a header file like this:
Packit bbfece
Packit bbfece
   	START_RELOC_NUMBERS (foo)
Packit bbfece
   	    RELOC_NUMBER (R_foo_NONE,    0)
Packit bbfece
   	    RELOC_NUMBER (R_foo_32,      1)
Packit bbfece
   	    EMPTY_RELOC  (R_foo_good)
Packit bbfece
   	    FAKE_RELOC   (R_foo_illegal, 9)
Packit bbfece
   	END_RELOC_NUMBERS (R_foo_count)
Packit bbfece
Packit bbfece
   Then the following will be produced by default (ie if
Packit bbfece
   RELOC_MACROS_GEN_FUNC is *not* defined).
Packit bbfece
Packit bbfece
   	enum foo
Packit bbfece
	{
Packit bbfece
   	  R_foo_NONE = 0,
Packit bbfece
   	  R_foo_32 = 1,
Packit bbfece
	  R_foo_good,
Packit bbfece
   	  R_foo_illegal = 9,
Packit bbfece
   	  R_foo_count
Packit bbfece
   	};
Packit bbfece
Packit bbfece
   Note: The value of the symbol defined in the END_RELOC_NUMBERS
Packit bbfece
   macro (R_foo_count in the case of the example above) will be
Packit bbfece
   set to the value of the whichever *_RELOC macro precedes it plus
Packit bbfece
   one.  Therefore if you intend to use the symbol as a sentinel for
Packit bbfece
   the highest valid macro value you should make sure that the
Packit bbfece
   preceding *_RELOC macro is the highest valid number.  ie a
Packit bbfece
   declaration like this:
Packit bbfece
Packit bbfece
   	START_RELOC_NUMBERS (foo)
Packit bbfece
   	    RELOC_NUMBER (R_foo_NONE,    0)
Packit bbfece
   	    RELOC_NUMBER (R_foo_32,      1)
Packit bbfece
   	    FAKE_RELOC   (R_foo_illegal, 9)
Packit bbfece
   	    FAKE_RELOC   (R_foo_synonym, 0)
Packit bbfece
   	END_RELOC_NUMBERS (R_foo_count)
Packit bbfece
Packit bbfece
   will result in R_foo_count having a value of 1 (R_foo_synonym + 1)
Packit bbfece
   rather than 10 or 2 as might be expected.
Packit bbfece
Packit bbfece
   Alternatively you can assign a value to END_RELOC_NUMBERS symbol
Packit bbfece
   explicitly, like this:
Packit bbfece
Packit bbfece
   	START_RELOC_NUMBERS (foo)
Packit bbfece
   	    RELOC_NUMBER (R_foo_NONE,    0)
Packit bbfece
   	    RELOC_NUMBER (R_foo_32,      1)
Packit bbfece
   	    FAKE_RELOC   (R_foo_illegal, 9)
Packit bbfece
   	    FAKE_RELOC   (R_foo_synonym, 0)
Packit bbfece
   	END_RELOC_NUMBERS (R_foo_count = 2)
Packit bbfece
Packit bbfece
   If RELOC_MACROS_GEN_FUNC *is* defined, then instead the
Packit bbfece
   following function will be generated:
Packit bbfece
Packit bbfece
   	static const char *foo (unsigned long rtype);
Packit bbfece
   	static const char *
Packit bbfece
   	foo (unsigned long rtype)
Packit bbfece
   	{
Packit bbfece
   	   switch (rtype)
Packit bbfece
   	   {
Packit bbfece
   	   case 0: return "R_foo_NONE";
Packit bbfece
   	   case 1: return "R_foo_32";
Packit bbfece
   	   default: return NULL;
Packit bbfece
   	   }
Packit bbfece
   	}
Packit bbfece
   */
Packit bbfece
Packit bbfece
#ifndef _RELOC_MACROS_H
Packit bbfece
#define _RELOC_MACROS_H
Packit bbfece
Packit bbfece
#ifdef RELOC_MACROS_GEN_FUNC
Packit bbfece
Packit bbfece
/* This function takes the relocation number and returns the
Packit bbfece
   string version name of the name of that relocation.  If
Packit bbfece
   the relocation is not recognised, NULL is returned.  */
Packit bbfece
Packit bbfece
#define START_RELOC_NUMBERS(name)   				\
Packit bbfece
static const char *name (unsigned long rtype);			\
Packit bbfece
static const char *						\
Packit bbfece
name (unsigned long rtype)					\
Packit bbfece
{								\
Packit bbfece
  switch (rtype)						\
Packit bbfece
    {
Packit bbfece
Packit bbfece
#define RELOC_NUMBER(name, number) \
Packit bbfece
    case number: return #name;
Packit bbfece
Packit bbfece
#define FAKE_RELOC(name, number)
Packit bbfece
#define EMPTY_RELOC(name)
Packit bbfece
Packit bbfece
#define END_RELOC_NUMBERS(name)	\
Packit bbfece
    default: return NULL;	\
Packit bbfece
    }				\
Packit bbfece
}
Packit bbfece
Packit bbfece
Packit bbfece
#else /* Default to generating enum.  */
Packit bbfece
Packit bbfece
#define START_RELOC_NUMBERS(name)   enum name {
Packit bbfece
#define RELOC_NUMBER(name, number)  name = number,
Packit bbfece
#define FAKE_RELOC(name, number)    name = number,
Packit bbfece
#define EMPTY_RELOC(name)           name,
Packit bbfece
#define END_RELOC_NUMBERS(name)     name };
Packit bbfece
Packit bbfece
#endif
Packit bbfece
Packit bbfece
#endif /* _RELOC_MACROS_H */