New clang warns about some differences between Elf64_Addr (aka
uint64) and Elf32_Addr (aka uint32) and the format type provided for
these values in the debug output from distrib/common/elfrd_size.c. The
same code is used when compiling both 32 and 64 bit versions, so we used
ptrdiff_t to get size specific formats. New clang warns on this format
specifier:

In file included from elf32.c:3:
./elfrd_size.c:118:29: warning: format specifies type 'unsigned ptrdiff_t'
      (aka 'unsigned long') but the argument has type 'Elf32_Addr'
      (aka 'unsigned int') [-Wformat]

In file included from elf64.c:3:
./elfrd_size.c:118:29: warning: format specifies type 'unsigned ptrdiff_t'
      (aka 'unsigned long') but the argument has type 'Elf64_Addr'
      (aka 'unsigned long long') [-Wformat]

Since these values are actually unsigned integers of width 32/64 bits,
we can use zx to print them, and cast the elements to size_t to quiet
clang.

ok?


Index: distrib/common/elfrd_size.c
===================================================================
RCS file: /cvs/src/distrib/common/elfrd_size.c,v
retrieving revision 1.9
diff -u -p -u -r1.9 elfrd_size.c
--- distrib/common/elfrd_size.c 26 Apr 2018 12:42:50 -0000      1.9
+++ distrib/common/elfrd_size.c 1 Jun 2018 19:58:57 -0000
@@ -114,9 +114,9 @@ ELFNAME(find_rd_root_image)(char *file,
                fprintf(stderr, "segment %d rd_root_size_off = 0x%llx\n", 
segment,
                    rd_root_size_off);
                if ((ph->p_vaddr - ph->p_paddr) != 0)
-                       fprintf(stderr, "root_off v %tx p %tx, diff %tx altered 
%llx\n",
-                           ph->p_vaddr, ph->p_paddr,
-                           (ph->p_vaddr - ph->p_paddr),
+                       fprintf(stderr, "root_off v %zx p %zx, diff %zx altered 
%llx\n",
+                           (size_t)ph->p_vaddr, (size_t)ph->p_paddr,
+                           (size_t)(ph->p_vaddr - ph->p_paddr),
                            rd_root_size_off - (ph->p_vaddr - ph->p_paddr));
                fprintf(stderr, "rd_root_image_off = 0x%llx\n", 
rd_root_image_off);
        }

Reply via email to