[PATCH] Add support for Tilera TILE-Gx processor.

Jeff Kenton jkenton at tilera.com
Thu Aug 16 17:09:14 UTC 2012


---
 backends/Makefile.am       |   11 ++-
 backends/tilegx_corenote.c |   60 +++++++++++++
 backends/tilegx_init.c     |   58 ++++++++++++
 backends/tilegx_regs.c     |   89 +++++++++++++++++++
 backends/tilegx_reloc.def  |  141 +++++++++++++++++++++++++++++
 backends/tilegx_retval.c   |  161 +++++++++++++++++++++++++++++++++
 backends/tilegx_symbol.c   |   53 +++++++++++
 libebl/eblopenbackend.c    |    1 +
 libelf/elf.h               |  210 +++++++++++++++++++++++++++++++++++++++++++-
 src/elflint.c              |    3 +-
 10 files changed, 782 insertions(+), 5 deletions(-)
 create mode 100644 backends/tilegx_corenote.c
 create mode 100644 backends/tilegx_init.c
 create mode 100644 backends/tilegx_regs.c
 create mode 100644 backends/tilegx_reloc.def
 create mode 100644 backends/tilegx_retval.c
 create mode 100644 backends/tilegx_symbol.c

diff --git a/backends/Makefile.am b/backends/Makefile.am
index 3b34e88..1c866e7 100644
--- a/backends/Makefile.am
+++ b/backends/Makefile.am
@@ -1,6 +1,6 @@
 ## Process this file with automake to create Makefile.in
 ##
-## Copyright (C) 2000-2010 Red Hat, Inc.
+## Copyright (C) 2000-2012 Red Hat, Inc.
 ## This file is part of elfutils.
 ##
 ## This file is free software; you can redistribute it and/or modify
@@ -31,11 +31,11 @@ INCLUDES += -I$(top_srcdir)/libebl -I$(top_srcdir)/libasm \
 	   -I$(top_srcdir)/libelf -I$(top_srcdir)/libdw
 
 
-modules = i386 sh x86_64 ia64 alpha arm sparc ppc ppc64 s390
+modules = i386 sh x86_64 ia64 alpha arm sparc ppc ppc64 s390 tilegx
 libebl_pic = libebl_i386_pic.a libebl_sh_pic.a libebl_x86_64_pic.a \
 	     libebl_ia64_pic.a libebl_alpha_pic.a libebl_arm_pic.a \
 	     libebl_sparc_pic.a libebl_ppc_pic.a libebl_ppc64_pic.a \
-	     libebl_s390_pic.a
+	     libebl_s390_pic.a libebl_tilegx_pic.a
 noinst_LIBRARIES = $(libebl_pic)
 noinst_DATA = $(libebl_pic:_pic.a=.so)
 
@@ -97,6 +97,11 @@ s390_SRCS = s390_init.c s390_symbol.c s390_regs.c s390_retval.c
 libebl_s390_pic_a_SOURCES = $(s390_SRCS)
 am_libebl_s390_pic_a_OBJECTS = $(s390_SRCS:.c=.os)
 
+tilegx_SRCS = tilegx_init.c tilegx_symbol.c tilegx_regs.c \
+              tilegx_retval.c tilegx_corenote.c
+libebl_tilegx_pic_a_SOURCES = $(tilegx_SRCS)
+am_libebl_tilegx_pic_a_OBJECTS = $(tilegx_SRCS:.c=.os)
+
 
 libebl_%.so libebl_%.map: libebl_%_pic.a $(libelf) $(libdw)
 	@rm -f $(@:.so=.map)
diff --git a/backends/tilegx_corenote.c b/backends/tilegx_corenote.c
new file mode 100644
index 0000000..bf5b3a1
--- /dev/null
+++ b/backends/tilegx_corenote.c
@@ -0,0 +1,60 @@
+/* TILE-Gx specific core note handling.
+   Copyright (C) 2012 Red Hat, Inc.
+   This file is part of Red Hat elfutils.
+
+   Red Hat elfutils 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; version 2 of the License.
+
+   Red Hat elfutils 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 Red Hat elfutils; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+
+   Red Hat elfutils is an included package of the Open Invention Network.
+   An included package of the Open Invention Network is a package for which
+   Open Invention Network licensees cross-license their patents.  No patent
+   license is granted, either expressly or impliedly, by designation as an
+   included package.  Should you wish to participate in the Open Invention
+   Network licensing program, please visit www.openinventionnetwork.com
+   <http://www.openinventionnetwork.com>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <elf.h>
+#include <inttypes.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <sys/time.h>
+
+#define BACKEND	tilegx_
+#include "libebl_CPU.h"
+
+static const Ebl_Register_Location prstatus_regs[] =
+  {
+    { .offset = 0, .regno = 0, .count = 56, .bits = 64 }, /* r0-r55 */
+    { .offset = 56 * 8, .regno = 64, .count = 1, .bits = 64 } /* pc */
+  };
+#define PRSTATUS_REGS_SIZE	(57 * 8)
+
+#define ULONG			uint64_t
+#define ALIGN_ULONG		8
+#define TYPE_ULONG		ELF_T_XWORD
+#define TYPE_LONG		ELF_T_SXWORD
+#define PID_T			int32_t
+#define	UID_T			uint32_t
+#define	GID_T			uint32_t
+#define ALIGN_PID_T		4
+#define ALIGN_UID_T		4
+#define ALIGN_GID_T		4
+#define TYPE_PID_T		ELF_T_SWORD
+#define TYPE_UID_T		ELF_T_WORD
+#define TYPE_GID_T		ELF_T_WORD
+
+#include "linux-core-note.c"
diff --git a/backends/tilegx_init.c b/backends/tilegx_init.c
new file mode 100644
index 0000000..778e270
--- /dev/null
+++ b/backends/tilegx_init.c
@@ -0,0 +1,58 @@
+/* Initialization of TILE-Gx specific backend library.
+   Copyright (C) 2012 Red Hat, Inc.
+   This file is part of Red Hat elfutils.
+   Written by Ulrich Drepper <drepper at redhat.com>, 2002.
+
+   Red Hat elfutils 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; version 2 of the License.
+
+   Red Hat elfutils 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 Red Hat elfutils; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+
+   Red Hat elfutils is an included package of the Open Invention Network.
+   An included package of the Open Invention Network is a package for which
+   Open Invention Network licensees cross-license their patents.  No patent
+   license is granted, either expressly or impliedly, by designation as an
+   included package.  Should you wish to participate in the Open Invention
+   Network licensing program, please visit www.openinventionnetwork.com
+   <http://www.openinventionnetwork.com>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#define BACKEND		tilegx_
+#define RELOC_PREFIX	R_TILEGX_
+#include "libebl_CPU.h"
+
+/* This defines the common reloc hooks based on tilegx_reloc.def.  */
+#include "common-reloc.c"
+
+const char *
+tilegx_init (elf, machine, eh, ehlen)
+     Elf *elf __attribute__ ((unused));
+     GElf_Half machine __attribute__ ((unused));
+     Ebl *eh;
+     size_t ehlen;
+{
+  /* Check whether the Elf_BH object has a sufficent size.  */
+  if (ehlen < sizeof (Ebl))
+    return NULL;
+
+  /* We handle it.  */
+  eh->name = "TILE-Gx";
+  tilegx_init_reloc (eh);
+  HOOK (eh, reloc_simple_type);
+  HOOK (eh, return_value_location);
+  HOOK (eh, register_info);
+  HOOK (eh, core_note);
+
+  return MODVERSION;
+}
diff --git a/backends/tilegx_regs.c b/backends/tilegx_regs.c
new file mode 100644
index 0000000..4513d4c
--- /dev/null
+++ b/backends/tilegx_regs.c
@@ -0,0 +1,89 @@
+/* Register names and numbers for TILE-Gx DWARF.
+   Copyright (C) 2012 Red Hat, Inc.
+   This file is part of Red Hat elfutils.
+
+   Red Hat elfutils 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; version 2 of the License.
+
+   Red Hat elfutils 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 Red Hat elfutils; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+
+   Red Hat elfutils is an included package of the Open Invention Network.
+   An included package of the Open Invention Network is a package for which
+   Open Invention Network licensees cross-license their patents.  No patent
+   license is granted, either expressly or impliedly, by designation as an
+   included package.  Should you wish to participate in the Open Invention
+   Network licensing program, please visit www.openinventionnetwork.com
+   <http://www.openinventionnetwork.com>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <dwarf.h>
+
+#define BACKEND tilegx_
+#include "libebl_CPU.h"
+
+static const char *const register_names[65] =
+  {
+    "r0",   "r1",   "r2",   "r3",   "r4",   "r5",   "r6",   "r7",
+    "r8",   "r9",   "r10",  "r11",  "r12",  "r13",  "r14",  "r15",
+    "r16",  "r17",  "r18",  "r19",  "r20",  "r21",  "r22",  "r23",
+    "r24",  "r25",  "r26",  "r27",  "r28",  "r29",  "r30",  "r31",
+    "r32",  "r33",  "r34",  "r35",  "r36",  "r37",  "r38",  "r39",
+    "r40",  "r41",  "r42",  "r43",  "r44",  "r45",  "r46",  "r47",
+    "r48",  "r49",  "r50",  "r51",  "r52",  "tp",   "sp",   "lr",
+    "sn",   "idn0", "idn1", "udn0", "udn1", "udn2", "udn3", "zero",
+    "pc"
+  };
+
+
+ssize_t
+tilegx_register_info (Ebl *ebl __attribute__ ((unused)),
+		    int regno, char *name, size_t namelen,
+		    const char **prefix, const char **setname,
+		    int *bits, int *type)
+{
+  if (name == NULL)
+    return 65;
+
+  if (regno < 0 || regno > 64 || namelen < 5)
+    return -1;
+
+  *prefix = "";
+  *setname = "integer";
+  *bits = 64;
+
+  switch (regno)
+    {
+      case 0 ... 52:
+        *type = DW_ATE_signed;
+        break;
+
+      case 53 ... 55:
+      case 64:
+        *type = DW_ATE_address;
+        break;
+
+      case 56 ... 63:
+        *type = DW_ATE_unsigned;
+        break;
+
+      /* Can't happen */
+      default:
+        *setname = NULL;
+        return 0;
+    }
+
+  return stpcpy (name, register_names[regno]) + 1 - name;
+}
diff --git a/backends/tilegx_reloc.def b/backends/tilegx_reloc.def
new file mode 100644
index 0000000..bc63a07
--- /dev/null
+++ b/backends/tilegx_reloc.def
@@ -0,0 +1,141 @@
+/* List the relocation types for tilegx.  -*- C -*-
+   Copyright (C) 2012 Red Hat, Inc.
+   This file is part of Red Hat elfutils.
+
+   Red Hat elfutils 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; version 2 of the License.
+
+   Red Hat elfutils 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 Red Hat elfutils; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+
+   Red Hat elfutils is an included package of the Open Invention Network.
+   An included package of the Open Invention Network is a package for which
+   Open Invention Network licensees cross-license their patents.  No patent
+   license is granted, either expressly or impliedly, by designation as an
+   included package.  Should you wish to participate in the Open Invention
+   Network licensing program, please visit www.openinventionnetwork.com
+   <http://www.openinventionnetwork.com>.  */
+
+/*	    NAME,			REL|EXEC|DYN	*/
+
+RELOC_TYPE (NONE,			0)
+RELOC_TYPE (64,				REL|EXEC|DYN)
+RELOC_TYPE (32,				REL|EXEC|DYN)
+RELOC_TYPE (16,				REL|EXEC|DYN)
+RELOC_TYPE (8,				REL|EXEC|DYN)
+RELOC_TYPE (64_PCREL,			REL)
+RELOC_TYPE (32_PCREL,			REL)
+RELOC_TYPE (16_PCREL,			REL)
+RELOC_TYPE (8_PCREL,			REL)
+RELOC_TYPE (HW0,			REL)
+RELOC_TYPE (HW1,			REL)
+RELOC_TYPE (HW2,			REL)
+RELOC_TYPE (HW3,			REL)
+RELOC_TYPE (HW0_LAST,			REL)
+RELOC_TYPE (HW1_LAST,			REL)
+RELOC_TYPE (HW2_LAST,			REL)
+RELOC_TYPE (COPY,			EXEC)
+RELOC_TYPE (GLOB_DAT,			EXEC|DYN)
+RELOC_TYPE (JMP_SLOT,			EXEC|DYN)
+RELOC_TYPE (RELATIVE,			EXEC|DYN)
+RELOC_TYPE (BROFF_X1,			REL)
+RELOC_TYPE (JUMPOFF_X1,			REL)
+RELOC_TYPE (JUMPOFF_X1_PLT,		REL)
+RELOC_TYPE (IMM8_X0,			REL)
+RELOC_TYPE (IMM8_Y0,			REL)
+RELOC_TYPE (IMM8_X1,			REL)
+RELOC_TYPE (IMM8_Y1,			REL)
+RELOC_TYPE (DEST_IMM8_X1,		REL)
+RELOC_TYPE (MT_IMM14_X1,		REL)
+RELOC_TYPE (MF_IMM14_X1,		REL)
+RELOC_TYPE (MMSTART_X0,			REL)
+RELOC_TYPE (MMEND_X0,			REL)
+RELOC_TYPE (SHAMT_X0,			REL)
+RELOC_TYPE (SHAMT_X1,			REL)
+RELOC_TYPE (SHAMT_Y0,			REL)
+RELOC_TYPE (SHAMT_Y1,			REL)
+RELOC_TYPE (IMM16_X0_HW0,		REL)
+RELOC_TYPE (IMM16_X1_HW0,		REL)
+RELOC_TYPE (IMM16_X0_HW1,		REL)
+RELOC_TYPE (IMM16_X1_HW1,		REL)
+RELOC_TYPE (IMM16_X0_HW2,		REL)
+RELOC_TYPE (IMM16_X1_HW2,		REL)
+RELOC_TYPE (IMM16_X0_HW3,		REL)
+RELOC_TYPE (IMM16_X1_HW3,		REL)
+RELOC_TYPE (IMM16_X0_HW0_LAST,		REL)
+RELOC_TYPE (IMM16_X1_HW0_LAST,		REL)
+RELOC_TYPE (IMM16_X0_HW1_LAST,		REL)
+RELOC_TYPE (IMM16_X1_HW1_LAST,		REL)
+RELOC_TYPE (IMM16_X0_HW2_LAST,		REL)
+RELOC_TYPE (IMM16_X1_HW2_LAST,		REL)
+RELOC_TYPE (IMM16_X0_HW0_PCREL,		REL)
+RELOC_TYPE (IMM16_X1_HW0_PCREL,		REL)
+RELOC_TYPE (IMM16_X0_HW1_PCREL,		REL)
+RELOC_TYPE (IMM16_X1_HW1_PCREL,		REL)
+RELOC_TYPE (IMM16_X0_HW2_PCREL,		REL)
+RELOC_TYPE (IMM16_X1_HW2_PCREL,		REL)
+RELOC_TYPE (IMM16_X0_HW3_PCREL,		REL)
+RELOC_TYPE (IMM16_X1_HW3_PCREL,		REL)
+RELOC_TYPE (IMM16_X0_HW0_LAST_PCREL,	REL)
+RELOC_TYPE (IMM16_X1_HW0_LAST_PCREL,	REL)
+RELOC_TYPE (IMM16_X0_HW1_LAST_PCREL,	REL)
+RELOC_TYPE (IMM16_X1_HW1_LAST_PCREL,	REL)
+RELOC_TYPE (IMM16_X0_HW2_LAST_PCREL,	REL)
+RELOC_TYPE (IMM16_X1_HW2_LAST_PCREL,	REL)
+RELOC_TYPE (IMM16_X0_HW0_GOT,		REL)
+RELOC_TYPE (IMM16_X1_HW0_GOT,		REL)
+RELOC_TYPE (IMM16_X0_HW1_GOT,		REL)
+RELOC_TYPE (IMM16_X1_HW1_GOT,		REL)
+RELOC_TYPE (IMM16_X0_HW2_GOT,		REL)
+RELOC_TYPE (IMM16_X1_HW2_GOT,		REL)
+RELOC_TYPE (IMM16_X0_HW3_GOT,		REL)
+RELOC_TYPE (IMM16_X1_HW3_GOT,		REL)
+RELOC_TYPE (IMM16_X0_HW0_LAST_GOT,	REL)
+RELOC_TYPE (IMM16_X1_HW0_LAST_GOT,	REL)
+RELOC_TYPE (IMM16_X0_HW1_LAST_GOT,	REL)
+RELOC_TYPE (IMM16_X1_HW1_LAST_GOT,	REL)
+RELOC_TYPE (IMM16_X0_HW2_LAST_GOT,	REL)
+RELOC_TYPE (IMM16_X1_HW2_LAST_GOT,	REL)
+RELOC_TYPE (IMM16_X0_HW0_TLS_GD,	REL)
+RELOC_TYPE (IMM16_X1_HW0_TLS_GD,	REL)
+RELOC_TYPE (IMM16_X0_HW1_TLS_GD,	REL)
+RELOC_TYPE (IMM16_X1_HW1_TLS_GD,	REL)
+RELOC_TYPE (IMM16_X0_HW2_TLS_GD,	REL)
+RELOC_TYPE (IMM16_X1_HW2_TLS_GD,	REL)
+RELOC_TYPE (IMM16_X0_HW3_TLS_GD,	REL)
+RELOC_TYPE (IMM16_X1_HW3_TLS_GD,	REL)
+RELOC_TYPE (IMM16_X0_HW0_LAST_TLS_GD,	REL)
+RELOC_TYPE (IMM16_X1_HW0_LAST_TLS_GD,	REL)
+RELOC_TYPE (IMM16_X0_HW1_LAST_TLS_GD,	REL)
+RELOC_TYPE (IMM16_X1_HW1_LAST_TLS_GD,	REL)
+RELOC_TYPE (IMM16_X0_HW2_LAST_TLS_GD,	REL)
+RELOC_TYPE (IMM16_X1_HW2_LAST_TLS_GD,	REL)
+RELOC_TYPE (IMM16_X0_HW0_TLS_IE,	REL)
+RELOC_TYPE (IMM16_X1_HW0_TLS_IE,	REL)
+RELOC_TYPE (IMM16_X0_HW1_TLS_IE,	REL)
+RELOC_TYPE (IMM16_X1_HW1_TLS_IE,	REL)
+RELOC_TYPE (IMM16_X0_HW2_TLS_IE,	REL)
+RELOC_TYPE (IMM16_X1_HW2_TLS_IE,	REL)
+RELOC_TYPE (IMM16_X0_HW3_TLS_IE,	REL)
+RELOC_TYPE (IMM16_X1_HW3_TLS_IE,	REL)
+RELOC_TYPE (IMM16_X0_HW0_LAST_TLS_IE,	REL)
+RELOC_TYPE (IMM16_X1_HW0_LAST_TLS_IE,	REL)
+RELOC_TYPE (IMM16_X0_HW1_LAST_TLS_IE,	REL)
+RELOC_TYPE (IMM16_X1_HW1_LAST_TLS_IE,	REL)
+RELOC_TYPE (IMM16_X0_HW2_LAST_TLS_IE,	REL)
+RELOC_TYPE (IMM16_X1_HW2_LAST_TLS_IE,	REL)
+RELOC_TYPE (TLS_DTPMOD64,		EXEC|DYN)
+RELOC_TYPE (TLS_DTPOFF64,		EXEC|DYN)
+RELOC_TYPE (TLS_TPOFF64,		EXEC|DYN)
+RELOC_TYPE (TLS_DTPMOD32,		EXEC|DYN)
+RELOC_TYPE (TLS_DTPOFF32,		EXEC|DYN)
+RELOC_TYPE (TLS_TPOFF32,		EXEC|DYN)
+RELOC_TYPE (GNU_VTINHERIT,		REL)
+RELOC_TYPE (GNU_VTENTRY,		REL)
diff --git a/backends/tilegx_retval.c b/backends/tilegx_retval.c
new file mode 100644
index 0000000..e717dbf
--- /dev/null
+++ b/backends/tilegx_retval.c
@@ -0,0 +1,161 @@
+/* Function return value location for Linux/TILE-Gx ABI.
+   Copyright (C) 2012 Red Hat, Inc.
+   This file is part of Red Hat elfutils.
+
+   Red Hat elfutils 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; version 2 of the License.
+
+   Red Hat elfutils 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 Red Hat elfutils; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+
+   Red Hat elfutils is an included package of the Open Invention Network.
+   An included package of the Open Invention Network is a package for which
+   Open Invention Network licensees cross-license their patents.  No patent
+   license is granted, either expressly or impliedly, by designation as an
+   included package.  Should you wish to participate in the Open Invention
+   Network licensing program, please visit www.openinventionnetwork.com
+   <http://www.openinventionnetwork.com>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <assert.h>
+#include <dwarf.h>
+
+#define BACKEND tilegx_
+#include "libebl_CPU.h"
+
+
+/* r0.  */
+static const Dwarf_Op loc_intreg[] =
+  {
+    { .atom = DW_OP_reg0 }
+  };
+#define nloc_intreg	1
+
+/* The return value is a structure and is actually stored in stack space
+   passed in a hidden argument by the caller.  But, the compiler
+   helpfully returns the address of that space in r0.  */
+static const Dwarf_Op loc_aggregate[] =
+  {
+    { .atom = DW_OP_breg0, .number = 0 }
+  };
+#define nloc_aggregate 1
+
+int
+tilegx_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
+{
+  /* Start with the function's type, and get the DW_AT_type attribute,
+     which is the type of the return value.  */
+
+  Dwarf_Attribute attr_mem;
+  Dwarf_Attribute *attr = dwarf_attr_integrate (functypedie, DW_AT_type,
+						&attr_mem);
+  if (attr == NULL)
+    /* The function has no return value, like a `void' function in C.  */
+    return 0;
+
+  Dwarf_Die die_mem;
+  Dwarf_Die *typedie = dwarf_formref_die (attr, &die_mem);
+  int tag = dwarf_tag (typedie);
+
+  /* Follow typedefs and qualifiers to get to the actual type.  */
+  while (tag == DW_TAG_typedef
+	 || tag == DW_TAG_const_type || tag == DW_TAG_volatile_type
+	 || tag == DW_TAG_restrict_type || tag == DW_TAG_mutable_type)
+    {
+      attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
+      typedie = dwarf_formref_die (attr, &die_mem);
+      tag = dwarf_tag (typedie);
+    }
+
+  Dwarf_Word size;
+  switch (tag)
+    {
+    case -1:
+      return -1;
+
+    case DW_TAG_subrange_type:
+      if (! dwarf_hasattr_integrate (typedie, DW_AT_byte_size))
+	{
+	  attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
+	  typedie = dwarf_formref_die (attr, &die_mem);
+	  tag = dwarf_tag (typedie);
+	}
+      /* Fall through.  */
+
+    case DW_TAG_base_type:
+    case DW_TAG_enumeration_type:
+    case DW_TAG_pointer_type:
+    case DW_TAG_ptr_to_member_type:
+      if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_byte_size,
+						 &attr_mem), &size) != 0)
+	{
+	  if (tag == DW_TAG_pointer_type || tag == DW_TAG_ptr_to_member_type)
+	    size = 8;
+	  else
+	    return -1;
+	}
+      if (tag == DW_TAG_base_type)
+	{
+	  Dwarf_Word encoding;
+	  if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_encoding,
+						     &attr_mem),
+			       &encoding) != 0)
+	    return -1;
+        }
+
+      /* Small enough structs are passed directly in registers R0 ... R7.  */
+      if (size <= 8)
+	{
+	intreg:
+	  *locp = loc_intreg;
+	  return nloc_intreg;
+	}
+
+      /* Else fall through.  */
+    case DW_TAG_structure_type:
+    case DW_TAG_class_type:
+    case DW_TAG_union_type:
+    aggregate:
+      *locp = loc_aggregate;
+      return nloc_aggregate;
+
+    case DW_TAG_array_type:
+    case DW_TAG_string_type:
+      if (dwarf_aggregate_size (typedie, &size) == 0 && size <= 8)
+	{
+	  if (tag == DW_TAG_array_type)
+	    {
+	      /* Check if it's a character array.  */
+	      attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
+	      typedie = dwarf_formref_die (attr, &die_mem);
+	      tag = dwarf_tag (typedie);
+	      if (tag != DW_TAG_base_type)
+		goto aggregate;
+	      if (dwarf_formudata (dwarf_attr_integrate (typedie,
+							 DW_AT_byte_size,
+							 &attr_mem),
+				   &size) != 0)
+		return -1;
+	      if (size != 1)
+		goto aggregate;
+	    }
+	  goto intreg;
+	}
+      goto aggregate;
+    }
+
+  /* XXX We don't have a good way to return specific errors from ebl calls.
+     This value means we do not understand the type, but it is well-formed
+     DWARF and might be valid.  */
+  return -2;
+}
diff --git a/backends/tilegx_symbol.c b/backends/tilegx_symbol.c
new file mode 100644
index 0000000..7c904f8
--- /dev/null
+++ b/backends/tilegx_symbol.c
@@ -0,0 +1,53 @@
+/* TILEGX-specific symbolic name handling.
+   Copyright (C) 2012 Red Hat, Inc.
+   This file is part of Red Hat elfutils.
+
+   Red Hat elfutils 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; version 2 of the License.
+
+   Red Hat elfutils 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 Red Hat elfutils; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+
+   Red Hat elfutils is an included package of the Open Invention Network.
+   An included package of the Open Invention Network is a package for which
+   Open Invention Network licensees cross-license their patents.  No patent
+   license is granted, either expressly or impliedly, by designation as an
+   included package.  Should you wish to participate in the Open Invention
+   Network licensing program, please visit www.openinventionnetwork.com
+   <http://www.openinventionnetwork.com>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <elf.h>
+#include <stddef.h>
+
+#define BACKEND		tilegx_
+#include "libebl_CPU.h"
+
+/* Check for the simple reloc types.  */
+Elf_Type
+tilegx_reloc_simple_type (Ebl *ebl __attribute__ ((unused)), int type)
+{
+  switch (type)
+    {
+    case R_TILEGX_64:
+      return ELF_T_SXWORD;
+    case R_TILEGX_32:
+      return ELF_T_SWORD;
+    case R_TILEGX_16:
+      return ELF_T_HALF;
+    case R_TILEGX_8:
+      return ELF_T_BYTE;
+    default:
+      return ELF_T_NUM;
+    }
+}
diff --git a/libebl/eblopenbackend.c b/libebl/eblopenbackend.c
index b39ab2e..89e5da5 100644
--- a/libebl/eblopenbackend.c
+++ b/libebl/eblopenbackend.c
@@ -63,6 +63,7 @@ static const struct
   { "x86_64", "elf_x86_64", "x86_64", 6, EM_X86_64, ELFCLASS64, ELFDATA2LSB },
   { "ppc", "elf_ppc", "ppc", 3, EM_PPC, ELFCLASS32, ELFDATA2MSB },
   { "ppc64", "elf_ppc64", "ppc64", 5, EM_PPC64, ELFCLASS64, ELFDATA2MSB },
+  { "tilegx", "elf_tilegx", "tilegx", 6, EM_TILEGX, ELFCLASS64, ELFDATA2LSB },
   // XXX class and machine fields need to be filled in for all archs.
   { "sh", "elf_sh", "sh", 2, EM_SH, 0, 0 },
   { "arm", "ebl_arm", "arm", 3, EM_ARM, 0, 0 },
diff --git a/libelf/elf.h b/libelf/elf.h
index a9558a3..30705da 100644
--- a/libelf/elf.h
+++ b/libelf/elf.h
@@ -250,7 +250,10 @@ typedef struct
 #define EM_OPENRISC	92		/* OpenRISC 32-bit embedded processor */
 #define EM_ARC_A5	93		/* ARC Cores Tangent-A5 */
 #define EM_XTENSA	94		/* Tensilica Xtensa Architecture */
-#define EM_NUM		95
+#define EM_TILE64	187		/* Tilera TILE64 */
+#define EM_TILEPRO	188		/* Tilera TILEPro */
+#define EM_TILEGX	191		/* Tilera TILE-Gx */
+#define EM_NUM		192
 
 /* If it is necessary to assign new unofficial EM_* values, please
    pick large random numbers (0x8523, 0xa7f2, etc.) to minimize the
@@ -2794,6 +2797,211 @@ typedef Elf32_Addr Elf32_Conflict;
 #define R_M32R_NUM		256	/* Keep this the last entry. */
 
 
+/* TILEPro relocations. */
+#define R_TILEPRO_NONE               0
+#define R_TILEPRO_32                 1
+#define R_TILEPRO_16                 2
+#define R_TILEPRO_8                  3
+#define R_TILEPRO_32_PCREL           4
+#define R_TILEPRO_16_PCREL           5
+#define R_TILEPRO_8_PCREL            6
+#define R_TILEPRO_LO16               7
+#define R_TILEPRO_HI16               8
+#define R_TILEPRO_HA16               9
+#define R_TILEPRO_COPY               10
+#define R_TILEPRO_GLOB_DAT           11
+#define R_TILEPRO_JMP_SLOT           12
+#define R_TILEPRO_RELATIVE           13
+#define R_TILEPRO_BROFF_X1           14
+#define R_TILEPRO_JOFFLONG_X1        15
+#define R_TILEPRO_JOFFLONG_X1_PLT    16
+#define R_TILEPRO_IMM8_X0            17
+#define R_TILEPRO_IMM8_Y0            18
+#define R_TILEPRO_IMM8_X1            19
+#define R_TILEPRO_IMM8_Y1            20
+#define R_TILEPRO_MT_IMM15_X1        21
+#define R_TILEPRO_MF_IMM15_X1        22
+#define R_TILEPRO_IMM16_X0           23
+#define R_TILEPRO_IMM16_X1           24
+#define R_TILEPRO_IMM16_X0_LO        25
+#define R_TILEPRO_IMM16_X1_LO        26
+#define R_TILEPRO_IMM16_X0_HI        27
+#define R_TILEPRO_IMM16_X1_HI        28
+#define R_TILEPRO_IMM16_X0_HA        29
+#define R_TILEPRO_IMM16_X1_HA        30
+#define R_TILEPRO_IMM16_X0_PCREL     31
+#define R_TILEPRO_IMM16_X1_PCREL     32
+#define R_TILEPRO_IMM16_X0_LO_PCREL  33
+#define R_TILEPRO_IMM16_X1_LO_PCREL  34
+#define R_TILEPRO_IMM16_X0_HI_PCREL  35
+#define R_TILEPRO_IMM16_X1_HI_PCREL  36
+#define R_TILEPRO_IMM16_X0_HA_PCREL  37
+#define R_TILEPRO_IMM16_X1_HA_PCREL  38
+#define R_TILEPRO_IMM16_X0_GOT       39
+#define R_TILEPRO_IMM16_X1_GOT       40
+#define R_TILEPRO_IMM16_X0_GOT_LO    41
+#define R_TILEPRO_IMM16_X1_GOT_LO    42
+#define R_TILEPRO_IMM16_X0_GOT_HI    43
+#define R_TILEPRO_IMM16_X1_GOT_HI    44
+#define R_TILEPRO_IMM16_X0_GOT_HA    45
+#define R_TILEPRO_IMM16_X1_GOT_HA    46
+#define R_TILEPRO_MMSTART_X0         47
+#define R_TILEPRO_MMEND_X0           48
+#define R_TILEPRO_MMSTART_X1         49
+#define R_TILEPRO_MMEND_X1           50
+#define R_TILEPRO_SHAMT_X0           51
+#define R_TILEPRO_SHAMT_X1           52
+#define R_TILEPRO_SHAMT_Y0           53
+#define R_TILEPRO_SHAMT_Y1           54
+#define R_TILEPRO_DEST_IMM8_X1       55
+/* Relocs 56-65 are currently not defined.  */
+#define R_TILEPRO_IMM16_X0_TLS_GD    66
+#define R_TILEPRO_IMM16_X1_TLS_GD    67
+#define R_TILEPRO_IMM16_X0_TLS_GD_LO 68
+#define R_TILEPRO_IMM16_X1_TLS_GD_LO 69
+#define R_TILEPRO_IMM16_X0_TLS_GD_HI 70
+#define R_TILEPRO_IMM16_X1_TLS_GD_HI 71
+#define R_TILEPRO_IMM16_X0_TLS_GD_HA 72
+#define R_TILEPRO_IMM16_X1_TLS_GD_HA 73
+#define R_TILEPRO_IMM16_X0_TLS_IE    74
+#define R_TILEPRO_IMM16_X1_TLS_IE    75
+#define R_TILEPRO_IMM16_X0_TLS_IE_LO 76
+#define R_TILEPRO_IMM16_X1_TLS_IE_LO 77
+#define R_TILEPRO_IMM16_X0_TLS_IE_HI 78
+#define R_TILEPRO_IMM16_X1_TLS_IE_HI 79
+#define R_TILEPRO_IMM16_X0_TLS_IE_HA 80
+#define R_TILEPRO_IMM16_X1_TLS_IE_HA 81
+#define R_TILEPRO_TLS_DTPMOD32       82
+#define R_TILEPRO_TLS_DTPOFF32       83
+#define R_TILEPRO_TLS_TPOFF32        84
+
+
+#define R_TILEPRO_GNU_VTINHERIT      128
+#define R_TILEPRO_GNU_VTENTRY        129
+
+#define R_TILEPRO_NUM                130
+
+
+/* TILE-Gx relocations. */
+#define R_TILEGX_NONE                      0
+#define R_TILEGX_64                        1
+#define R_TILEGX_32                        2
+#define R_TILEGX_16                        3
+#define R_TILEGX_8                         4
+#define R_TILEGX_64_PCREL                  5
+#define R_TILEGX_32_PCREL                  6
+#define R_TILEGX_16_PCREL                  7
+#define R_TILEGX_8_PCREL                   8
+#define R_TILEGX_HW0                       9
+#define R_TILEGX_HW1                       10
+#define R_TILEGX_HW2                       11
+#define R_TILEGX_HW3                       12
+#define R_TILEGX_HW0_LAST                  13
+#define R_TILEGX_HW1_LAST                  14
+#define R_TILEGX_HW2_LAST                  15
+#define R_TILEGX_COPY                      16
+#define R_TILEGX_GLOB_DAT                  17
+#define R_TILEGX_JMP_SLOT                  18
+#define R_TILEGX_RELATIVE                  19
+#define R_TILEGX_BROFF_X1                  20
+#define R_TILEGX_JUMPOFF_X1                21
+#define R_TILEGX_JUMPOFF_X1_PLT            22
+#define R_TILEGX_IMM8_X0                   23
+#define R_TILEGX_IMM8_Y0                   24
+#define R_TILEGX_IMM8_X1                   25
+#define R_TILEGX_IMM8_Y1                   26
+#define R_TILEGX_DEST_IMM8_X1              27
+#define R_TILEGX_MT_IMM14_X1               28
+#define R_TILEGX_MF_IMM14_X1               29
+#define R_TILEGX_MMSTART_X0                30
+#define R_TILEGX_MMEND_X0                  31
+#define R_TILEGX_SHAMT_X0                  32
+#define R_TILEGX_SHAMT_X1                  33
+#define R_TILEGX_SHAMT_Y0                  34
+#define R_TILEGX_SHAMT_Y1                  35
+#define R_TILEGX_IMM16_X0_HW0              36
+#define R_TILEGX_IMM16_X1_HW0              37
+#define R_TILEGX_IMM16_X0_HW1              38
+#define R_TILEGX_IMM16_X1_HW1              39
+#define R_TILEGX_IMM16_X0_HW2              40
+#define R_TILEGX_IMM16_X1_HW2              41
+#define R_TILEGX_IMM16_X0_HW3              42
+#define R_TILEGX_IMM16_X1_HW3              43
+#define R_TILEGX_IMM16_X0_HW0_LAST         44
+#define R_TILEGX_IMM16_X1_HW0_LAST         45
+#define R_TILEGX_IMM16_X0_HW1_LAST         46
+#define R_TILEGX_IMM16_X1_HW1_LAST         47
+#define R_TILEGX_IMM16_X0_HW2_LAST         48
+#define R_TILEGX_IMM16_X1_HW2_LAST         49
+#define R_TILEGX_IMM16_X0_HW0_PCREL        50
+#define R_TILEGX_IMM16_X1_HW0_PCREL        51
+#define R_TILEGX_IMM16_X0_HW1_PCREL        52
+#define R_TILEGX_IMM16_X1_HW1_PCREL        53
+#define R_TILEGX_IMM16_X0_HW2_PCREL        54
+#define R_TILEGX_IMM16_X1_HW2_PCREL        55
+#define R_TILEGX_IMM16_X0_HW3_PCREL        56
+#define R_TILEGX_IMM16_X1_HW3_PCREL        57
+#define R_TILEGX_IMM16_X0_HW0_LAST_PCREL   58
+#define R_TILEGX_IMM16_X1_HW0_LAST_PCREL   59
+#define R_TILEGX_IMM16_X0_HW1_LAST_PCREL   60
+#define R_TILEGX_IMM16_X1_HW1_LAST_PCREL   61
+#define R_TILEGX_IMM16_X0_HW2_LAST_PCREL   62
+#define R_TILEGX_IMM16_X1_HW2_LAST_PCREL   63
+#define R_TILEGX_IMM16_X0_HW0_GOT          64
+#define R_TILEGX_IMM16_X1_HW0_GOT          65
+#define R_TILEGX_IMM16_X0_HW1_GOT          66
+#define R_TILEGX_IMM16_X1_HW1_GOT          67
+#define R_TILEGX_IMM16_X0_HW2_GOT          68
+#define R_TILEGX_IMM16_X1_HW2_GOT          69
+#define R_TILEGX_IMM16_X0_HW3_GOT          70
+#define R_TILEGX_IMM16_X1_HW3_GOT          71
+#define R_TILEGX_IMM16_X0_HW0_LAST_GOT     72
+#define R_TILEGX_IMM16_X1_HW0_LAST_GOT     73
+#define R_TILEGX_IMM16_X0_HW1_LAST_GOT     74
+#define R_TILEGX_IMM16_X1_HW1_LAST_GOT     75
+#define R_TILEGX_IMM16_X0_HW2_LAST_GOT     76
+#define R_TILEGX_IMM16_X1_HW2_LAST_GOT     77
+#define R_TILEGX_IMM16_X0_HW0_TLS_GD       78
+#define R_TILEGX_IMM16_X1_HW0_TLS_GD       79
+#define R_TILEGX_IMM16_X0_HW1_TLS_GD       80
+#define R_TILEGX_IMM16_X1_HW1_TLS_GD       81
+#define R_TILEGX_IMM16_X0_HW2_TLS_GD       82
+#define R_TILEGX_IMM16_X1_HW2_TLS_GD       83
+#define R_TILEGX_IMM16_X0_HW3_TLS_GD       84
+#define R_TILEGX_IMM16_X1_HW3_TLS_GD       85
+#define R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD  86
+#define R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD  87
+#define R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD  88
+#define R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD  89
+#define R_TILEGX_IMM16_X0_HW2_LAST_TLS_GD  90
+#define R_TILEGX_IMM16_X1_HW2_LAST_TLS_GD  91
+#define R_TILEGX_IMM16_X0_HW0_TLS_IE       92
+#define R_TILEGX_IMM16_X1_HW0_TLS_IE       93
+#define R_TILEGX_IMM16_X0_HW1_TLS_IE       94
+#define R_TILEGX_IMM16_X1_HW1_TLS_IE       95
+#define R_TILEGX_IMM16_X0_HW2_TLS_IE       96
+#define R_TILEGX_IMM16_X1_HW2_TLS_IE       97
+#define R_TILEGX_IMM16_X0_HW3_TLS_IE       98
+#define R_TILEGX_IMM16_X1_HW3_TLS_IE       99
+#define R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE  100
+#define R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE  101
+#define R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE  102
+#define R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE  103
+#define R_TILEGX_IMM16_X0_HW2_LAST_TLS_IE  104
+#define R_TILEGX_IMM16_X1_HW2_LAST_TLS_IE  105
+#define R_TILEGX_TLS_DTPMOD64              106
+#define R_TILEGX_TLS_DTPOFF64              107
+#define R_TILEGX_TLS_TPOFF64               108
+#define R_TILEGX_TLS_DTPMOD32              109
+#define R_TILEGX_TLS_DTPOFF32              110
+#define R_TILEGX_TLS_TPOFF32               111
+
+#define R_TILEGX_GNU_VTINHERIT             128
+#define R_TILEGX_GNU_VTENTRY               129
+
+#define R_TILEGX_NUM                       130
+
+
 __END_DECLS
 
 #endif	/* elf.h */
diff --git a/src/elflint.c b/src/elflint.c
index 1ff2809..4084987 100644
--- a/src/elflint.c
+++ b/src/elflint.c
@@ -330,7 +330,8 @@ static const int valid_e_machine[] =
     EM_68HC16, EM_68HC11, EM_68HC08, EM_68HC05, EM_SVX, EM_ST19, EM_VAX,
     EM_CRIS, EM_JAVELIN, EM_FIREPATH, EM_ZSP, EM_MMIX, EM_HUANY, EM_PRISM,
     EM_AVR, EM_FR30, EM_D10V, EM_D30V, EM_V850, EM_M32R, EM_MN10300,
-    EM_MN10200, EM_PJ, EM_OPENRISC, EM_ARC_A5, EM_XTENSA, EM_ALPHA
+    EM_MN10200, EM_PJ, EM_OPENRISC, EM_ARC_A5, EM_XTENSA, EM_ALPHA,
+    EM_TILEGX, EM_TILEPRO
   };
 #define nvalid_e_machine \
   (sizeof (valid_e_machine) / sizeof (valid_e_machine[0]))
-- 
1.7.10.3


--------------080209010800050204040907--


More information about the elfutils-devel mailing list