Clean up warnings in soslim

Change-Id: I497745fe9701876272fdbe7a946622a40efffdd5
diff --git a/tools/soslim/main.c b/tools/soslim/main.c
index fa5a315..dd8a60b 100644
--- a/tools/soslim/main.c
+++ b/tools/soslim/main.c
@@ -337,7 +337,7 @@
                             section_name = "(undefined)";
                         }
                         /* value size binding type section symname */
-                        PRINT("%-15s %8d: %08llx %08llx %c%c %5d %n%s%n",
+                        PRINT("%-15s %8zd: %08llx %08llx %c%c %5d %n%s%n",
                               file,
                               index,
                               sym->st_value, sym->st_size, bind, type,
diff --git a/tools/soslim/prelink_info.c b/tools/soslim/prelink_info.c
index 36516b1..81d5de3 100644
--- a/tools/soslim/prelink_info.c
+++ b/tools/soslim/prelink_info.c
@@ -14,13 +14,13 @@
 typedef struct {
 	uint32_t mmap_addr;
 	char tag[4]; /* 'P', 'R', 'E', ' ' */
-} prelink_info_t __attribute__((packed));
+} __attribute__((packed)) prelink_info_t;
 
 static inline void set_prelink(long *prelink_addr, 
 							   int elf_little,
 							   prelink_info_t *info)
 {
-    FAILIF(sizeof(prelink_info_t) != 8, "Unexpected sizeof(prelink_info_t) == %d!\n", sizeof(prelink_info_t));
+    FAILIF(sizeof(prelink_info_t) != 8, "Unexpected sizeof(prelink_info_t) == %zd!\n", sizeof(prelink_info_t));
 	if (prelink_addr) {
 		if (!(elf_little ^ is_host_little())) {
 			/* Same endianness */
@@ -35,11 +35,14 @@
 
 int check_prelinked(const char *fname, int elf_little, long *prelink_addr)
 {
-    FAILIF(sizeof(prelink_info_t) != 8, "Unexpected sizeof(prelink_info_t) == %d!\n", sizeof(prelink_info_t));
+    FAILIF(sizeof(prelink_info_t) != 8, "Unexpected sizeof(prelink_info_t) == %zd!\n", sizeof(prelink_info_t));
 	int fd = open(fname, O_RDONLY);
 	FAILIF(fd < 0, "open(%s, O_RDONLY): %s (%d)!\n",
 		   fname, strerror(errno), errno);
 	off_t end = lseek(fd, 0, SEEK_END);
+#ifndef DEBUG
+	(void)end;
+#endif
 
     int nr = sizeof(prelink_info_t);
 
@@ -50,14 +53,14 @@
 		   fd, strerror(errno), errno);
 
 	prelink_info_t info;
-	int num_read = read(fd, &info, nr);
+	ssize_t num_read = read(fd, &info, nr);
 	FAILIF(num_read < 0, 
 		   "read(%d, &info, sizeof(prelink_info_t)): %s (%d)!\n",
 		   fd, strerror(errno), errno);
-	FAILIF(num_read != sizeof(info),
-		   "read(%d, &info, sizeof(prelink_info_t)): did not read %d bytes as "
-		   "expected (read %d)!\n",
-		   fd, sizeof(info), num_read);
+	FAILIF((size_t)num_read != sizeof(info),
+		   "read(%d, &info, sizeof(prelink_info_t)): did not read %zd bytes as "
+		   "expected (read %zd)!\n",
+		   fd, sizeof(info), (size_t)num_read);
 
 	int prelinked = 0;
 	if (!strncmp(info.tag, "PRE ", 4)) {
@@ -70,7 +73,7 @@
 
 void setup_prelink_info(const char *fname, int elf_little, long base)
 {
-    FAILIF(sizeof(prelink_info_t) != 8, "Unexpected sizeof(prelink_info_t) == %d!\n", sizeof(prelink_info_t));
+    FAILIF(sizeof(prelink_info_t) != 8, "Unexpected sizeof(prelink_info_t) == %zd!\n", sizeof(prelink_info_t));
     int fd = open(fname, O_WRONLY);
     FAILIF(fd < 0, 
            "open(%s, O_WRONLY): %s (%d)\n" ,
@@ -93,13 +96,13 @@
     }
     strncpy(info.tag, "PRE ", 4);
 
-    int num_written = write(fd, &info, sizeof(info));
+    ssize_t num_written = write(fd, &info, sizeof(info));
     FAILIF(num_written < 0, 
            "write(%d, &info, sizeof(info)): %s (%d)\n",
            fd, strerror(errno), errno);
-    FAILIF(sizeof(info) != num_written, 
-           "Could not write %d bytes (wrote only %d bytes) as expected!\n",
-           sizeof(info), num_written);
+    FAILIF(sizeof(info) != (size_t)num_written,
+           "Could not write %zd bytes (wrote only %zd bytes) as expected!\n",
+           sizeof(info), (size_t)num_written);
     FAILIF(close(fd) < 0, "close(%d): %s (%d)!\n", fd, strerror(errno), errno);
 }
 
diff --git a/tools/soslim/soslim.c b/tools/soslim/soslim.c
index d32e247..125e29e 100644
--- a/tools/soslim/soslim.c
+++ b/tools/soslim/soslim.c
@@ -42,7 +42,7 @@
     int dynsym_idx = -1; /* index in shdr_info[] of dynamic symbol table
                             section */
 
-    int cnt;	  /* general-purpose counter */
+    unsigned int cnt;	  /* general-purpose counter */
     /* This flag is true when at least one section is dropped or when the
        relative order of sections has changed, so that section indices in
        the resulting file will be different from those in the original. */
@@ -51,7 +51,7 @@
 	size_t idx;	  /* general-purporse section index */
 
 	shdr_info_t *shdr_info = NULL;
-    int shdr_info_len = 0;
+    unsigned int shdr_info_len = 0;
     GElf_Phdr *phdr_info = NULL;
 
 	/* Get the information from the old file. */
@@ -95,7 +95,7 @@
 
 	/* Get the number of sections. */
 	FAILIF_LIBELF(elf_getshnum (elf, &shnum) < 0, elf_getshnum);
-	INFO("Original ELF file has %d sections.\n", shnum);
+	INFO("Original ELF file has %zd sections.\n", shnum);
 
 	/* Allocate the section-header-info buffer.  We allocate one more entry
        for the section-strings section because we regenerate that one and
@@ -104,7 +104,7 @@
        one more section the header.  We just mark the old section for removal
        and create one as the last section.
     */
-	INFO("Allocating section-header info structure (%d) bytes...\n",
+	INFO("Allocating section-header info structure (%zd) bytes...\n",
 		 shnum*sizeof (shdr_info_t));
     shdr_info_len = rebuild_shstrtab ? shnum + 1 : shnum;
 	shdr_info = (shdr_info_t *)CALLOC(shdr_info_len, sizeof (shdr_info_t));
@@ -305,9 +305,9 @@
 
               /* Check the length of the dynamic-symbol filter. */
               FAILIF(sym_filter != NULL &&
-                     num_symbols != symdata->d_size / elsize,
+                     (size_t)num_symbols != symdata->d_size / elsize,
                      "Length of dynsym filter (%d) must equal the number"
-                     " of dynamic symbols (%d)!\n",
+                     " of dynamic symbols (%zd)!\n",
                      num_symbols,
                      symdata->d_size / elsize);
 
@@ -443,14 +443,14 @@
 			shdr_info[cnt].se = ebl_strtabadd (shst, shdr_info[cnt].name, 0);
 
 			INFO("\tsection [%s]  (old offset %lld, old size %lld) will have index %d "
-				 "(was %d).\n",
+				 "(was %zd).\n",
 				 shdr_info[cnt].name,
 				 shdr_info[cnt].old_shdr.sh_offset,
 				 shdr_info[cnt].old_shdr.sh_size,
 				 shdr_info[cnt].idx,
 				 elf_ndxscn(shdr_info[cnt].scn));
 		} else {
-			INFO("\tIgnoring section [%s] (offset %lld, size %lld, index %d), "
+			INFO("\tIgnoring section [%s] (offset %lld, size %lld, index %zd), "
 				 "it will be discarded.\n",
 				 shdr_info[cnt].name,
 				 shdr_info[cnt].shdr.sh_offset,
diff --git a/tools/soslim/symfilter.c b/tools/soslim/symfilter.c
index c21ab2e..b59e68a 100644
--- a/tools/soslim/symfilter.c
+++ b/tools/soslim/symfilter.c
@@ -38,9 +38,9 @@
            strerror(errno),
            errno);
 
-    INFO("Symbol-filter file %s is %ld bytes long...\n", 
+    INFO("Symbol-filter file %s is %zd bytes long...\n",
          name,
-         fsize);
+         (size_t)fsize);
     filter->fsize = fsize;
 
     /* mmap the symbols file */
@@ -48,8 +48,8 @@
                         PROT_READ | PROT_WRITE, MAP_PRIVATE, 
                         filter->fd, 0);
     FAILIF(MAP_FAILED == filter->mmap, 
-           "mmap(NULL, %ld, PROT_READ, MAP_PRIVATE, %d, 0): %s (%d)\n",
-           fsize,
+           "mmap(NULL, %zd, PROT_READ, MAP_PRIVATE, %d, 0): %s (%d)\n",
+           (size_t)fsize,
            filter->fd,
            strerror(errno),
            errno);
@@ -202,6 +202,8 @@
 
 static int match_hash_table_section(Elf *elf, Elf_Scn *sect, void *data)
 {
+    (void)elf; // unused argument
+
     symfilter_t *filter = (symfilter_t *)data;
     Elf32_Shdr *shdr;
 
@@ -224,6 +226,8 @@
 
 static int match_dynsym_section(Elf *elf, Elf_Scn *sect, void *data)
 {
+    (void)elf; // unused argument
+
     symfilter_t *filter = (symfilter_t *)data;
     Elf32_Shdr *shdr;