shithub: scc

Download patch

ref: ddd03ea3045bd6d12db62662695479317a44cbe0
parent: 620dc383f44dc5d3057809993b834223720aae91
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Nov 27 15:31:05 EST 2017

[objdump] Add printrelocs()

This function prints all the relocations of the object file.

--- a/objdump/main.c
+++ b/objdump/main.c
@@ -122,6 +122,33 @@
 	return 0;
 }
 
+static int
+printrelocs(struct myrohdr *hdr, FILE *fp)
+{
+	size_t n, i;
+	struct myrorel rel;
+
+	puts("relocs:");
+	n = hdr->relsize / MYROREL_SIZ;
+	for (i = 0; i < n; ++i) {
+		if (rdmyrorel(fp, &rel) < 0)
+			return -1;
+		printf("\tid: %lu\n"
+		       "\tflags: %x\n"
+		       "\tsize: %u\n"
+		       "\tnbits: %u\n"
+		       "\tshift: %u\n"
+		       "\toffset: %llu\n",
+		       rel.id,
+		       rel.flags,
+		       rel.size,
+		       rel.nbits,
+		       rel.shift,
+		       rel.offset);
+	}
+	return 0;
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -140,7 +167,8 @@
 			goto wrong_file;
 		if (hdr.strsize > SIZE_MAX ||
 		    hdr.secsize > SIZE_MAX / MYROSECT_SIZ ||
-		    hdr.symsize > SIZE_MAX / MYROSYM_SIZ) {
+		    hdr.symsize > SIZE_MAX / MYROSYM_SIZ  ||
+		    hdr.relsize > SIZE_MAX / MYROREL_SIZ) {
 			goto overflow;
 		}
 		strsiz = hdr.strsize;
@@ -157,6 +185,8 @@
 		if (printsections(&hdr, fp) < 0)
 			goto wrong_file;
 		if (printsymbols(&hdr, fp) < 0)
+			goto wrong_file;
+		if (printrelocs(&hdr, fp) < 0)
 			goto wrong_file;
 
 		goto close_file;