TCF Agent: add support for SPARC V8 relocations

Signed-off-by: Daniel Cederman <cederman@gaisler.com>
diff --git a/agent/machine/sparc/tcf/dwarfreloc-mdep.h b/agent/machine/sparc/tcf/dwarfreloc-mdep.h
new file mode 100644
index 0000000..fa6b61d
--- /dev/null
+++ b/agent/machine/sparc/tcf/dwarfreloc-mdep.h
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Cobham Gaisler and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v1.0 which accompany this distribution.
+ * The Eclipse Public License is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ * You may elect to redistribute this code under either of these licenses.
+ *
+ * Contributors:
+ *     Cobham Gaisler - initial API and implementation
+ *******************************************************************************/
+
+/*
+ * This module provides CPU specific ELF definitions for SPARC.
+ */
+
+#define R_SPARC_NONE      0
+#define R_SPARC_32        3
+#define R_SPARC_UA32     23
+
+static void elf_relocate(void) {
+    if (relocs->type == SHT_REL && reloc_type != R_SPARC_NONE) {
+        U4_T x = *(U4_T *)((char *)section->data + reloc_offset);
+        if (section->file->type != ET_REL)
+            str_exception(ERR_INV_FORMAT, "Invalid relocation record");
+        if (section->file->byte_swap) SWAP(x);
+        assert(reloc_addend == 0);
+        reloc_addend = x;
+    }
+    switch (reloc_type) {
+    case R_SPARC_NONE:
+        *destination_section = NULL;
+        break;
+    case R_SPARC_32:
+    case R_SPARC_UA32:
+        if (data_size < 4)
+            str_exception(ERR_INV_FORMAT, "Invalid relocation record");
+        *(U4_T *)data_buf = (U4_T)(sym_value + reloc_addend);
+        break;
+    default:
+        str_exception(ERR_INV_FORMAT, "Unsupported relocation type");
+    }
+}
diff --git a/agent/tcf/services/dwarfreloc-ext.h b/agent/tcf/services/dwarfreloc-ext.h
index 36f74bb..697f810 100644
--- a/agent/tcf/services/dwarfreloc-ext.h
+++ b/agent/tcf/services/dwarfreloc-ext.h
@@ -42,6 +42,10 @@
 #include <machine/microblaze/tcf/dwarfreloc-mdep.h>
 #undef elf_relocate
 
+#define elf_relocate elf_relocate_sparc
+#include <machine/sparc/tcf/dwarfreloc-mdep.h>
+#undef elf_relocate
+
 static ElfRelocateFunc elf_relocate_funcs[] = {
     { EM_386,       elf_relocate_i386 },
     { EM_X86_64,    elf_relocate_x86_64 },
@@ -50,5 +54,6 @@
     { EM_PPC,       elf_relocate_powerpc },
     { EM_PPC64,     elf_relocate_ppc64 },
     { EM_MICROBLAZE, elf_relocate_microblaze },
+    { EM_SPARC,     elf_relocate_sparc },
     { EM_NONE, NULL }
 };