cbfstool: Clean up in preparation for adding new files

This enables more warnings on the cbfstool codebase and fixes the
issues that surface as a result. A memory leak that used to occur
when compressing files with lzma is also found and fixed.
Finally, there are several fixes for the Makefile:
 - Its autodependencies used to be broken because the target for
   the .dependencies file was misnamed; this meant that Make
   didn't know how to rebuild the file, and so would silently
   skip the step of updating it before including it.
 - The ability to build to a custom output directory by defining
   the obj variable had bitrotted.
 - The default value of the obj variable was causing implicit
   rules not to apply when specifying a file as a target without
   providing a custom value for obj.
 - Add a distclean target for removing the .dependencies file.

BUG=chromium:461875
TEST=Build an image with cbfstool both before and after.
BRANCH=None

Change-Id: I951919d63443f2b053c2e67c1ac9872abc0a43ca
Signed-off-by: Sol Boucher <solb@chromium.org>
Original-Commit-Id: 49293443b4e565ca48d284e9a66f80c9c213975d
Original-Change-Id: Ia7350c2c3306905984cfa711d5fc4631f0b43d5b
Original-Signed-off-by: Sol Boucher <solb@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/257340
Original-Reviewed-by: Julius Werner <jwerner@chromium.org>
Original-Reviewed-by: Stefan Reinauer <reinauer@chromium.org>
Reviewed-on: http://review.coreboot.org/9937
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
diff --git a/util/cbfstool/rmodule.c b/util/cbfstool/rmodule.c
index 23eb25f..fa175db 100644
--- a/util/cbfstool/rmodule.c
+++ b/util/cbfstool/rmodule.c
@@ -15,6 +15,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
  */
 
+#include <inttypes.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -28,9 +29,9 @@
 struct arch_ops {
 	int arch;
 	/* Determine if relocation is a valid type for the architecture. */
-	int (*valid_type)(struct rmod_context *ctx, Elf64_Rela *rel);
+	int (*valid_type)(Elf64_Rela *rel);
 	/* Determine if relocation should be emitted. */
-	int (*should_emit)(struct rmod_context *ctx, Elf64_Rela *rel);
+	int (*should_emit)(Elf64_Rela *rel);
 };
 
 struct rmod_context {
@@ -62,7 +63,7 @@
 /*
  * Architecture specific support operations.
  */
-static int valid_reloc_386(struct rmod_context *ctx, Elf64_Rela *rel)
+static int valid_reloc_386(Elf64_Rela *rel)
 {
 	int type;
 
@@ -72,7 +73,7 @@
 	return (type == R_386_32 || type == R_386_PC32);
 }
 
-static int should_emit_386(struct rmod_context *ctx, Elf64_Rela *rel)
+static int should_emit_386(Elf64_Rela *rel)
 {
 	int type;
 
@@ -82,7 +83,7 @@
 	return (type == R_386_32);
 }
 
-static int valid_reloc_arm(struct rmod_context *ctx, Elf64_Rela *rel)
+static int valid_reloc_arm(Elf64_Rela *rel)
 {
 	int type;
 
@@ -94,7 +95,7 @@
 		type == R_ARM_CALL || type == R_ARM_JUMP24);
 }
 
-static int should_emit_arm(struct rmod_context *ctx, Elf64_Rela *rel)
+static int should_emit_arm(Elf64_Rela *rel)
 {
 	int type;
 
@@ -104,7 +105,7 @@
 	return (type == R_ARM_ABS32);
 }
 
-static int valid_reloc_aarch64(struct rmod_context *ctx, Elf64_Rela *rel)
+static int valid_reloc_aarch64(Elf64_Rela *rel)
 {
 	int type;
 
@@ -122,7 +123,7 @@
 		type == R_AARCH64_ADR_PREL_LO21);
 }
 
-static int should_emit_aarch64(struct rmod_context *ctx, Elf64_Rela *rel)
+static int should_emit_aarch64(Elf64_Rela *rel)
 {
 	int type;
 
@@ -176,13 +177,13 @@
 		for (j = 0; j < nrelocs; j++) {
 			Elf64_Rela *r = &relocs[j];
 
-			if (!ctx->ops->valid_type(ctx, r)) {
+			if (!ctx->ops->valid_type(r)) {
 				ERROR("Invalid reloc type: %u\n",
 				      (unsigned int)ELF64_R_TYPE(r->r_info));
 				return -1;
 			}
 
-			if (ctx->ops->should_emit(ctx, r)) {
+			if (ctx->ops->should_emit(r)) {
 				int n = ctx->nrelocs;
 				if (do_emit)
 					ctx->emitted_relocs[n] = r->r_offset;
@@ -306,7 +307,7 @@
 
 static int collect_relocations(struct rmod_context *ctx)
 {
-	int nrelocs;
+	Elf64_Xword nrelocs;
 
 	/*
 	 * The relocs array in the pelf should only contain relocations that
@@ -317,7 +318,7 @@
 		return -1;
 
 	nrelocs = ctx->nrelocs;
-	INFO("%d relocations to be emitted.\n", nrelocs);
+	INFO("%" PRIu64 " relocations to be emitted.\n", nrelocs);
 	if (!nrelocs)
 		return 0;
 
@@ -457,7 +458,6 @@
 write_elf(const struct rmod_context *ctx, const struct buffer *in,
           struct buffer *out)
 {
-	int i;
 	int ret;
 	int bit64;
 	size_t loc;
@@ -556,7 +556,7 @@
 	ctx->xdr->put32(&rmod_header, 0);
 
 	/* Write the relocations. */
-	for (i = 0; i < ctx->nrelocs; i++) {
+	for (unsigned i = 0; i < ctx->nrelocs; i++) {
 		if (bit64)
 			ctx->xdr->put64(&relocs, ctx->emitted_relocs[i]);
 		else