changeset 82:c20dc315a9d4

tiobjd: beginning of reloc handling
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Wed, 26 Mar 2014 06:00:07 +0000
parents 192da19c7506
children 3dfecd91c5b0
files ticoff/Makefile ticoff/filestruct.h ticoff/main.c ticoff/reloc.c
diffstat 4 files changed, 45 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ticoff/Makefile	Wed Mar 26 03:23:20 2014 +0000
+++ b/ticoff/Makefile	Wed Mar 26 06:00:07 2014 +0000
@@ -1,7 +1,7 @@
 CC=	gcc
 CFLAGS=	-O2
 PROG=	tiobjd
-OBJS=	basics.o globals.o lowlevel.o main.o symtab.o tables.o
+OBJS=	basics.o globals.o lowlevel.o main.o reloc.o symtab.o tables.o
 HDRS=	coffconst.h filestruct.h globals.h intstruct.h
 
 all:	${PROG}
--- a/ticoff/filestruct.h	Wed Mar 26 03:23:20 2014 +0000
+++ b/ticoff/filestruct.h	Wed Mar 26 06:00:07 2014 +0000
@@ -37,3 +37,10 @@
 	u_char	e_sclass;
 	u_char	e_numaux;
 };
+
+struct external_reloc {
+  u_char r_vaddr[4];
+  u_char r_symndx[4];
+  u_char r_reserved[2]; /* extended pmad byte for COFF2 */
+  u_char r_type[2];
+};
--- a/ticoff/main.c	Wed Mar 26 03:23:20 2014 +0000
+++ b/ticoff/main.c	Wed Mar 26 06:00:07 2014 +0000
@@ -12,6 +12,7 @@
 extern int cmd_basics();
 extern int cmd_nm();
 extern int cmd_profile();
+extern int cmd_rawrel();
 extern int cmd_sechdr();
 extern int cmd_symtab();
 extern int dump_filehdr_info();
@@ -25,6 +26,7 @@
 	{"hdr", dump_filehdr_info},
 	{"nm", cmd_nm},
 	{"profile", cmd_profile},
+	{"rawrel", cmd_rawrel},
 	{"sechdr", cmd_sechdr},
 	{"symtab", cmd_symtab},
 	{0, 0}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ticoff/reloc.c	Wed Mar 26 06:00:07 2014 +0000
@@ -0,0 +1,35 @@
+/*
+ * Handling of relocation records
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "filestruct.h"
+#include "intstruct.h"
+#include "globals.h"
+
+extern unsigned get_u16(), get_u32();
+
+cmd_rawrel()
+{
+	unsigned n, m;
+	struct internal_scnhdr *sec;
+	struct external_reloc *rel;
+
+	get_int_section_table();
+	for (n = 0; n < nsections; n++) {
+		sec = sections + n;
+		if (!sec->nreloc)
+			continue;
+		printf("%s:\n\n", sec->name);
+		rel = (struct external_reloc *)(filemap + sec->reloc_offset);
+		printf("Location  SymIndex  Rsvd  Type\n");
+		for (m = 0; m < sec->nreloc; m++, rel++)
+			printf("%08X  %08X  %04X  %04X\n",
+				get_u32(rel->r_vaddr), get_u32(rel->r_symndx),
+				get_u16(rel->r_reserved), get_u16(rel->r_type));
+		putchar('\n');
+	}
+	exit(0);
+}