libelf: type adjustments Don't needlessly use uint64_t when unsigned suffices. Also don't open code elf_phdr_count() and replace a redundant call to elf_shdr_count(). Signed-off-by: Jan Beulich --- a/xen/common/libelf/libelf-loader.c +++ b/xen/common/libelf/libelf-loader.c @@ -36,7 +36,8 @@ struct elf_sym_header { elf_errorstatus elf_init(struct elf_binary *elf, const char *image_input, size_t size) { ELF_HANDLE_DECL(elf_shdr) shdr; - uint64_t i, count, section, offset, link; + unsigned i, count, section, link; + uint64_t offset; if ( !elf_is_elfbinary(image_input, size) ) { @@ -89,7 +90,7 @@ elf_errorstatus elf_init(struct elf_bina continue; link = elf_uval(elf, shdr, sh_link); - if ( link == SHN_UNDEF || link >= elf_shdr_count(elf) ) + if ( link == SHN_UNDEF || link >= count ) /* out-of-bounds link value. */ break; @@ -443,11 +444,10 @@ do { void elf_parse_binary(struct elf_binary *elf) { ELF_HANDLE_DECL(elf_phdr) phdr; - uint64_t low = -1; - uint64_t high = 0; - uint64_t i, count, paddr, memsz; + uint64_t low = -1, high = 0, paddr, memsz; + unsigned i, count; - count = elf_uval(elf, elf->ehdr, e_phnum); + count = elf_phdr_count(elf); for ( i = 0; i < count; i++ ) { phdr = elf_phdr_by_index(elf, i); @@ -474,7 +474,8 @@ void elf_parse_binary(struct elf_binary elf_errorstatus elf_load_binary(struct elf_binary *elf) { ELF_HANDLE_DECL(elf_phdr) phdr; - uint64_t i, count, paddr, offset, filesz, memsz; + uint64_t paddr, offset, filesz, memsz; + unsigned i, count; elf_ptrval dest; /* * Let bizarre ELFs write the output image up to twice; this @@ -483,7 +484,7 @@ elf_errorstatus elf_load_binary(struct e */ uint64_t remain_allow_copy = (uint64_t)elf->dest_size * 2; - count = elf_uval(elf, elf->ehdr, e_phnum); + count = elf_phdr_count(elf); for ( i = 0; i < count; i++ ) { phdr = elf_phdr_by_index(elf, i); @@ -512,7 +513,7 @@ elf_errorstatus elf_load_binary(struct e remain_allow_copy -= memsz; elf_msg(elf, - "ELF: phdr %" PRIu64 " at %#"ELF_PRPTRVAL" -> %#"ELF_PRPTRVAL"\n", + "ELF: phdr %u at %#"ELF_PRPTRVAL" -> %#"ELF_PRPTRVAL"\n", i, dest, (elf_ptrval)(dest + filesz)); if ( elf_load_image(elf, dest, ELF_IMAGE_BASE(elf) + offset, filesz, memsz) != 0 ) return -1; --- a/xen/common/libelf/libelf-tools.c +++ b/xen/common/libelf/libelf-tools.c @@ -149,10 +149,9 @@ unsigned elf_phdr_count(struct elf_binar ELF_HANDLE_DECL(elf_shdr) elf_shdr_by_name(struct elf_binary *elf, const char *name) { - uint64_t count = elf_shdr_count(elf); + unsigned i, count = elf_shdr_count(elf); ELF_HANDLE_DECL(elf_shdr) shdr; const char *sname; - unsigned i; for ( i = 1; i < count; i++ ) { @@ -169,7 +168,7 @@ ELF_HANDLE_DECL(elf_shdr) elf_shdr_by_na ELF_HANDLE_DECL(elf_shdr) elf_shdr_by_index(struct elf_binary *elf, unsigned index) { - uint64_t count = elf_shdr_count(elf); + unsigned count = elf_shdr_count(elf); elf_ptrval ptr; if ( index >= count ) @@ -183,7 +182,7 @@ ELF_HANDLE_DECL(elf_shdr) elf_shdr_by_in ELF_HANDLE_DECL(elf_phdr) elf_phdr_by_index(struct elf_binary *elf, unsigned index) { - uint64_t count = elf_uval(elf, elf->ehdr, e_phnum); + unsigned count = elf_phdr_count(elf); elf_ptrval ptr; if ( index >= count )