This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 4/5] sparc: fix the extraction of relocation IDs from r_type fields.


This patch adds support for a RELOC_TYPE_ID transform macros that
backends can use before including common-reloc.c.  The sparc backend
uses this in order to extract the relocation IDs from r_type fields.
In this target the most significative 24 bits of r_type are used to
store an additional addend in some relocation types.

Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
---
 backends/ChangeLog      |  8 ++++++++
 backends/common-reloc.c | 15 ++++++++++++++-
 backends/sparc_init.c   |  5 +++++
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/backends/ChangeLog b/backends/ChangeLog
index 3fdc0fd..8bc3ef0 100644
--- a/backends/ChangeLog
+++ b/backends/ChangeLog
@@ -1,5 +1,13 @@
 2015-10-02  Jose E. Marchesi  <jose.marchesi@oracle.com>
 
+	* sparc_init.c (RELOC_TYPE_ID): Defined.
+	* common-reloc.c (reloc_type_name): Apply target-specific
+	relocation ID extractors if defined.
+	(reloc_type_check): Likewise.
+	(reloc_valid_use): Likewise.
+
+2015-10-02  Jose E. Marchesi  <jose.marchesi@oracle.com>
+
 	* sparc_reloc.def: Added relocation types WDISP10, JMP_IREL and
 	IRELATIVE.
 
diff --git a/backends/common-reloc.c b/backends/common-reloc.c
index 2667ec4..3317b6c 100644
--- a/backends/common-reloc.c
+++ b/backends/common-reloc.c
@@ -87,6 +87,10 @@ EBLHOOK(reloc_type_name) (int reloc,
 			  char *buf __attribute__ ((unused)),
 			  size_t len __attribute__ ((unused)))
 {
+#ifdef RELOC_TYPE_ID
+  reloc = RELOC_TYPE_ID (reloc);
+#endif
+
   if (reloc >= 0 && reloc < nreloc && EBLHOOK(reloc_nameidx)[reloc] != 0)
     return &reloc_namestr[EBLHOOK(reloc_nameidx)[reloc]];
   return NULL;
@@ -95,19 +99,28 @@ EBLHOOK(reloc_type_name) (int reloc,
 bool
 EBLHOOK(reloc_type_check) (int reloc)
 {
+#ifdef RELOC_TYPE_ID
+  reloc = RELOC_TYPE_ID (reloc);
+#endif
+
   return reloc >= 0 && reloc < nreloc && EBLHOOK(reloc_nameidx)[reloc] != 0;
 }
 
 bool
 EBLHOOK(reloc_valid_use) (Elf *elf, int reloc)
 {
-  uint8_t uses = EBLHOOK(reloc_valid)[reloc];
+  uint8_t uses;
 
   GElf_Ehdr ehdr_mem;
   GElf_Ehdr *ehdr = gelf_getehdr (elf, &ehdr_mem);
   assert (ehdr != NULL);
   uint8_t type = ehdr->e_type;
 
+#ifdef RELOC_TYPE_ID
+  reloc = RELOC_TYPE_ID (reloc);
+#endif
+
+  uses = EBLHOOK(reloc_valid)[reloc];
   return type > ET_NONE && type < ET_CORE && (uses & (1 << (type - 1)));
 }
 
diff --git a/backends/sparc_init.c b/backends/sparc_init.c
index d3c2009..f8a7cfb 100644
--- a/backends/sparc_init.c
+++ b/backends/sparc_init.c
@@ -34,6 +34,11 @@
 #define RELOC_PREFIX	R_SPARC_
 #include "libebl_CPU.h"
 
+/* In SPARC some relocations use the most significative 24 bits of the
+   r_type field to encode a secondary addend.  Make sure the routines
+   in common-reloc.c acknowledge this.  */
+#define RELOC_TYPE_ID(type) ((type) & 0xff)
+
 /* This defines the common reloc hooks based on sparc_reloc.def.  */
 #include "common-reloc.c"
 
-- 
2.3.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]