From 36dd637fc46dfe4c8707e049c8284c906ee8ca18 Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Wed, 22 Jul 1998 23:27:31 +0000 Subject: [PATCH] Reloc macros tidied up. i386 and v850 reloc macros added. New file created to contain reloc macros: reloc-macros.h --- include/elf/ChangeLog | 27 ++++++++++ include/elf/arm.h | 7 +-- include/elf/mips.h | 7 +-- include/elf/mn10300.h | 9 +--- include/elf/ppc.h | 11 ++-- include/elf/reloc-macros.h | 103 +++++++++++++++++++++++++++++++++++++ include/elf/sparc.h | 7 +-- 7 files changed, 138 insertions(+), 33 deletions(-) create mode 100644 include/elf/reloc-macros.h diff --git a/include/elf/ChangeLog b/include/elf/ChangeLog index 3c217d44257..4b63478f4a8 100644 --- a/include/elf/ChangeLog +++ b/include/elf/ChangeLog @@ -1,3 +1,28 @@ +Wed Jul 22 16:22:11 1998 Nick Clifton + + * reloc-macros.h: New file. Provides relocation macros: + START_RELOC_NUMBERS, RELOC_NUMBER, FAKE_RELOC, EMPTY_RELOC and + END_RELOC_NUMBERS used by other elf header files. + + * alpha.h: Use reloc-macros.h. + * arc.h: Use reloc-macros.h. + * arm.h: Use reloc-macros.h. + * d10v.h: Use reloc-macros.h. +start-sanitize-d30v + * d30v.h: Use reloc-macros.h. +end-sanitize-d30v + * hppa.h: Use reloc-macros.h. + * i386.h: Use reloc-macros.h. + * m32r.h: Use reloc-macros.h. + * m68k.h: Use reloc-macros.h. + * mips.h: Use reloc-macros.h. + * mn10200.h: Use reloc-macros.h. + * mn10300.h: Use reloc-macros.h. + * ppc.h: Use reloc-macros.h. + * sh.h: Use reloc-macros.h. + * sparc.h: Use reloc-macros.h. + * v850.h: Use reloc-macros.h. + 1998-07-22 13:07 Ulrich Drepper * mn10300.h: Rewrite relocation definition using macros. @@ -6,7 +31,9 @@ * alpha.h: Likewise. * arm.h: Likewise. * d10v.h: Likewise. +start-sanitize-d30v * d30v.h: Likewise. +end-sanitize-d30v * m32r.h: Likewise. * m68k.h: Likewise. * mn10200.h: Likewise. diff --git a/include/elf/arm.h b/include/elf/arm.h index a71feaa7aab..7f13a71a9d5 100644 --- a/include/elf/arm.h +++ b/include/elf/arm.h @@ -20,12 +20,7 @@ #ifndef _ELF_ARM_H #define _ELF_ARM_H -/* Unless otherwise told we define an enum with the relocation entries. */ -#ifndef START_RELOC_NUMBERS -# define START_RELOC_NUMBERS(name) enum name { -# define RELOC_NUMBER(name, number) name = number , -# define END_RELOC_NUMBERS }; -#endif +#include "elf/reloc-macros.h" /* Relocation types. */ START_RELOC_NUMBERS (elf_arm_reloc_type) diff --git a/include/elf/mips.h b/include/elf/mips.h index 0c023dbb711..62ae632a6d6 100644 --- a/include/elf/mips.h +++ b/include/elf/mips.h @@ -27,12 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _ELF_MIPS_H #define _ELF_MIPS_H -/* Unless otherwise told we define an enum with the relocation entries. */ -#ifndef START_RELOC_NUMBERS -# define START_RELOC_NUMBERS(name) enum name { -# define RELOC_NUMBER(name, number) name = number , -# define END_RELOC_NUMBERS }; -#endif +#include "elf/reloc-macros.h" /* Relocation types. */ START_RELOC_NUMBERS (elf_mips_reloc_type) diff --git a/include/elf/mn10300.h b/include/elf/mn10300.h index 1d64c40ca0a..79db776530e 100644 --- a/include/elf/mn10300.h +++ b/include/elf/mn10300.h @@ -22,12 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _ELF_MN10300_H #define _ELF_MN10300_H -/* Unless otherwise told we define an enum with the relocation entries. */ -#ifndef START_RELOC_NUMBERS -# define START_RELOC_NUMBERS(name) enum name { -# define RELOC_NUMBER(name, number) name = number , -# define END_RELOC_NUMBERS }; -#endif +#include "elf/reloc-macros.h" /* Relocations. */ START_RELOC_NUMBERS (elf_mn10300_reloc_type) @@ -40,7 +35,7 @@ START_RELOC_NUMBERS (elf_mn10300_reloc_type) RELOC_NUMBER (R_MN10300_PCREL8, 6) RELOC_NUMBER (R_MN10300_GNU_VTINHERIT, 7) RELOC_NUMBER (R_MN10300_GNU_VTENTRY, 8) - RELOC_NUMBER (R_MN10300_MAX, 9) + EMPTY_RELOC (R_MN10300_MAX) END_RELOC_NUMBERS /* Machine variant if we know it. This field was invented at Cygnus, diff --git a/include/elf/ppc.h b/include/elf/ppc.h index c577fdb1d89..557ba372a07 100644 --- a/include/elf/ppc.h +++ b/include/elf/ppc.h @@ -27,15 +27,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _ELF_PPC_H #define _ELF_PPC_H -/* Unless otherwise told we define an enum with the relocation entries. */ -#ifndef START_RELOC_NUMBERS -# define START_RELOC_NUMBERS(name) enum name { -# define RELOC_NUMBER(name, number) name = number , -# define END_RELOC_NUMBERS }; -#endif +#include "elf/reloc-macros.h" /* Relocations. */ -START_RELOC_NUMBERS (elf_ppc_reloc_type) +START_RELOC_NUMBERS (ppc_reloc_type) RELOC_NUMBER (R_PPC_NONE, 0) RELOC_NUMBER (R_PPC_ADDR32, 1) RELOC_NUMBER (R_PPC_ADDR24, 2) @@ -101,7 +96,7 @@ START_RELOC_NUMBERS (elf_ppc_reloc_type) that may still be in object files. */ RELOC_NUMBER (R_PPC_TOC16, 255) - RELOC_NUMBER (R_PPC_max, 256) + EMPTY_RELOC (R_PPC_max) END_RELOC_NUMBERS diff --git a/include/elf/reloc-macros.h b/include/elf/reloc-macros.h new file mode 100644 index 00000000000..646dbe50cc8 --- /dev/null +++ b/include/elf/reloc-macros.h @@ -0,0 +1,103 @@ +/* Generic relocation support for BFD. + Copyright (C) 1998 Free Software Foundation, Inc. + + This file is part of BFD, the Binary File Descriptor library. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +/* These macros are used by the various elf/*.h target specific header + files to either generate an enum containing all the known relocations + for that target, or if RELOC_MACROS_GEN_FUNC is defined, a recognition + function is generated instead. (This is used by binutils/readelf.c) + + Given a header file like this: + + START_RELOC_NUMBERS (foo) + RELOC_NUMBER (R_foo_NONE, 0) + RELOC_NUMBER (R_foo_32, 1) + FAKE_RELOC (R_foo_illegal, 2) + EMPTY_RELOC (R_foo_max) + END_RELOC_NUMBERS + + Then the following will be produced by default (ie if + RELOC_MACROS_GEN_FUNC is *not* defined). + + enum foo { + R_foo_NONE = 0, + R_foo_32 = 1, + R_foo_illegal = 2, + R_foo_max + }; + + If RELOC_MACROS_GEN_FUNC *is* defined, then instead the + following function will be generated: + + static char * foo PARAMS ((unsigned long rtype)); + static char * + foo (rtype) + unsigned long rtype; + { + switch (rtype) + { + case 0: return "R_foo_NONE"; + case 1: return "R_foo_32"; + default: return NULL; + } + } + */ + +#ifndef _RELOC_MACROS_H +#define _RELOC_MACROS_H + +#ifdef RELOC_MACROS_GEN_FUNC + +/* This function takes the relocation number and returns the + string version name of the name of that relocation. If + the relocation is not recognised, NULL is returned. */ + +#define START_RELOC_NUMBERS(name) \ +static const char * name PARAMS ((unsigned long rtype)); \ +static const char * \ +name (rtype) \ + unsigned long rtype; \ +{ \ + switch (rtype) \ + { + +#ifdef __STDC__ +#define RELOC_NUMBER(name, number) case number : return #name ; +#else +#define RELOC_NUMBER(name, number) case number : return "name" ; +#endif + +#define FAKE_RELOC(name, number) +#define EMPTY_RELOC(name) + +#define END_RELOC_NUMBERS default: return NULL; \ + } \ + } + + +#else /* default to generating enum */ + +#define START_RELOC_NUMBERS(name) enum name { +#define RELOC_NUMBER(name, number) name = number , +#define FAKE_RELOC(name, number) name = number , +#define EMPTY_RELOC(name) name , +#define END_RELOC_NUMBERS }; + +#endif + +#endif /* RELOC_MACROS_H */ diff --git a/include/elf/sparc.h b/include/elf/sparc.h index 91c71e6b5a2..f33314ac3eb 100644 --- a/include/elf/sparc.h +++ b/include/elf/sparc.h @@ -55,12 +55,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #define STT_REGISTER 13 /* global reg reserved to app. */ -/* Unless otherwise told we define an enum with the relocation entries. */ -#ifndef START_RELOC_NUMBERS -# define START_RELOC_NUMBERS(name) enum name { -# define RELOC_NUMBER(name, number) name = number , -# define END_RELOC_NUMBERS }; -#endif +#include "elf/reloc-macros.h" /* Relocation types. */ START_RELOC_NUMBERS (elf_sparc_reloc_type) -- 2.30.2