From 0f6329bd7fcc8952aed5a386617d12529771415d Mon Sep 17 00:00:00 2001 From: Ravi Bangoria Date: Fri, 14 Jul 2017 13:26:27 +0530 Subject: [PATCH] binutils/objdump: Fix disassemble for huge elf sections When elf section size is beyond unsigned int max value, objdump fails to disassemble from that section. Ex on PowerPC, $ objdump -h /proc/kcore Idx Name Size VMA 4 load2 100000000 c000000000000000 Here, size of load2 section is 0x100000000. Also note that, 0xc00.... address range is kernel space for PowerPC. Now let's try to disassemble do_sys_open() using /proc/kcore. $ cat /proc/kallsyms | grep -A1 -w do_sys_open c00000000036c000 T do_sys_open c00000000036c2d0 T SyS_open Before patch: $ objdump -d --start-address=0xc00000000036c000 --stop-address=0xc00000000036c2d0 /proc/kcore /proc/kcore: file format elf64-powerpcle Disassembly of section load2: c00000000036c000 : c00000000036c000: Address 0xc00000000036c000 is out of bounds. Fix this by changing type of 'buffer_length' from unsigned int to size_t. After patch: $ objdump -d --start-address=0xc00000000036c000 --stop-address=0xc00000000036c2d0 /proc/kcore /proc/kcore: file format elf64-powerpcle Disassembly of section load2: c00000000036c000 : c00000000036c000: fc 00 4c 3c addis r2,r12,252 c00000000036c004: 00 53 42 38 addi r2,r2,21248 c00000000036c008: a6 02 08 7c mflr r0 include/ * dis-asm.h (struct disassemble_info): Change type of buffer_length field to size_t. opcodes/ * dis-buf.c (buffer_read_memory): Change type of end_addr_offset, max_addr_offset and octets variables to size_t. --- include/ChangeLog | 5 +++++ include/dis-asm.h | 2 +- opcodes/ChangeLog | 5 +++++ opcodes/dis-buf.c | 6 +++--- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/ChangeLog b/include/ChangeLog index a726f0d9a0..3203836ce8 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,8 @@ +2017-07-14 Ravi Bangoria + + * dis-asm.h (struct disassemble_info): Change type of buffer_length + field to size_t. + 2017-07-07 John Baldwin * elf/common.h (NT_FREEBSD_PTLWPINFO): Define. diff --git a/include/dis-asm.h b/include/dis-asm.h index 9b4251405e..4ff8bc95ab 100644 --- a/include/dis-asm.h +++ b/include/dis-asm.h @@ -158,7 +158,7 @@ typedef struct disassemble_info /* These are for buffer_read_memory. */ bfd_byte *buffer; bfd_vma buffer_vma; - unsigned int buffer_length; + size_t buffer_length; /* This variable may be set by the instruction decoder. It suggests the number of bytes objdump should display on a single line. If diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog index 855ac35efa..caeeee7fb9 100644 --- a/opcodes/ChangeLog +++ b/opcodes/ChangeLog @@ -1,3 +1,8 @@ +2017-07-14 Ravi Bangoria + + * dis-buf.c (buffer_read_memory): Change type of end_addr_offset, + max_addr_offset and octets variables to size_t. + 2017-07-12 Alan Modra * po/da.po: Update from translationproject.org/latest/opcodes/. diff --git a/opcodes/dis-buf.c b/opcodes/dis-buf.c index 061bc441a3..fd495bb014 100644 --- a/opcodes/dis-buf.c +++ b/opcodes/dis-buf.c @@ -32,9 +32,9 @@ buffer_read_memory (bfd_vma memaddr, struct disassemble_info *info) { unsigned int opb = info->octets_per_byte; - unsigned int end_addr_offset = length / opb; - unsigned int max_addr_offset = info->buffer_length / opb; - unsigned int octets = (memaddr - info->buffer_vma) * opb; + size_t end_addr_offset = length / opb; + size_t max_addr_offset = info->buffer_length / opb; + size_t octets = (memaddr - info->buffer_vma) * opb; if (memaddr < info->buffer_vma || memaddr - info->buffer_vma > max_addr_offset -- 2.34.1