All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Wessel <jason.wessel@windriver.com>
To: <linux-kernel@vger.kernel.org>
Cc: <mingo@redhat.com>, <masami.hiramatsu.pt@hitachi.com>,
	<rusty@rustcorp.com.au>
Subject: [RFC PATCH 4/8] readelf: Fix dumping a 64 bit elf file on a 32 bit host
Date: Fri, 20 Apr 2012 16:29:50 -0500	[thread overview]
Message-ID: <1334957394-12086-5-git-send-email-jason.wessel@windriver.com> (raw)
In-Reply-To: <1334957394-12086-1-git-send-email-jason.wessel@windriver.com>

We want a 32bit or 64bit host to be able to process a 32bit or 64bit
elf file.  On a 32 bit host reading a 64 bit elf file, the set address
function in process_extended_line_op() was using the correct word size
but the storage variable was not properly sized.  The simple fix is to
just use bfd_vma.

After changing the size of the address, all the printf statements
needed to change to using the correctly typed format string on a 64 vs
32 bit host.

Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
---
 scripts/readelf.c |   18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/scripts/readelf.c b/scripts/readelf.c
index 228de30..a21fcf7 100644
--- a/scripts/readelf.c
+++ b/scripts/readelf.c
@@ -64,10 +64,12 @@
 typedef unsigned long long bfd_vma;
 typedef unsigned long long bfd_size_type;
 typedef long long bfd_signed_vma;
+#define LSTR "0x%llx"
 #else
 typedef unsigned long bfd_vma;
 typedef unsigned long bfd_size_type;
 typedef long bfd_signed_vma;
+#define LSTR "0x%lx"
 #endif
 typedef bfd_signed_vma file_ptr;
 
@@ -971,7 +973,7 @@ read_leb128 (data, length_return, sign)
 
 typedef struct State_Machine_Registers
 {
-  unsigned long address;
+  bfd_vma address;
   unsigned int file;
   unsigned int line;
   unsigned int column;
@@ -1011,7 +1013,7 @@ process_extended_line_op (data, is_stmt, pointer_size)
   int bytes_read;
   unsigned int len;
   unsigned char *name;
-  unsigned long adr;
+  bfd_vma adr;
   unsigned long val;
 
   len = read_leb128 (data, & bytes_read, 0);
@@ -1040,7 +1042,7 @@ process_extended_line_op (data, is_stmt, pointer_size)
     case DW_LNE_set_address:
       adr = byte_get (data, pointer_size);
 	  if (!do_quiet)
-		printf ("set Address to 0x%lx\n", adr);
+		printf ("set Address to " LSTR "\n", adr);
       state_machine_regs.address = adr;
       break;
 
@@ -1315,7 +1317,7 @@ display_debug_lines (section, start, file)
 	      adv      = (op_code / info.li_line_range) * info.li_min_insn_length;
 	      state_machine_regs.address += adv;
 	      if (!do_quiet)
-	        printf ("  Special opcode %d: advance Address by %d to 0x%lx",
+	        printf ("  Special opcode %d: advance Address by %d to " LSTR,
 		      op_code, adv, state_machine_regs.address);
 	      adv = (op_code % info.li_line_range) + info.li_line_base;
 	      state_machine_regs.line += adv;
@@ -1323,7 +1325,7 @@ display_debug_lines (section, start, file)
 	        printf (" and Line by %d to %d\n",
 		      adv, state_machine_regs.line);
 	      if (do_quiet)
-		printf("%s:%u 0x%lx\n", ftable[state_machine_regs.file - 1],
+		printf("%s:%u " LSTR "\n", ftable[state_machine_regs.file - 1],
 state_machine_regs.line, state_machine_regs.address);
 	    }
 	  else switch (op_code)
@@ -1343,7 +1345,7 @@ state_machine_regs.line, state_machine_regs.address);
 	      data += bytes_read;
 	      state_machine_regs.address += adv;
 	      if (!do_quiet)
-	        printf ("  Advance PC by %d to %lx\n", adv,
+	        printf ("  Advance PC by %d to " LSTR "\n", adv,
 		      state_machine_regs.address);
 	      break;
 
@@ -1392,7 +1394,7 @@ state_machine_regs.line, state_machine_regs.address);
 		     * info.li_min_insn_length);
 	      state_machine_regs.address += adv;
 	      if (!do_quiet)
-	        printf ("  Advance PC by constant %d to 0x%lx\n", adv,
+	        printf ("  Advance PC by constant %d to " LSTR "\n", adv,
 		      state_machine_regs.address);
 	      break;
 
@@ -1401,7 +1403,7 @@ state_machine_regs.line, state_machine_regs.address);
 	      data += 2;
 	      state_machine_regs.address += adv;
 	      if (!do_quiet)
-	        printf ("  Advance PC by fixed size amount %d to 0x%lx\n",
+	        printf ("  Advance PC by fixed size amount %d to " LSTR "\n",
 		      adv, state_machine_regs.address);
 	      break;
 
-- 
1.7.10


  parent reply	other threads:[~2012-04-20 21:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-20 21:29 [RFC PATCH 0/8] backtrace/oops with source/line information Jason Wessel
2012-04-20 21:29 ` [RFC PATCH 1/8] readelf: check in a direct copy of readelf.c from binutils 2.14 Jason Wessel
2012-04-20 21:29 ` [RFC PATCH 2/8] readelf: remove code unrelated to .debug_line section processing Jason Wessel
2012-04-20 21:29 ` [RFC PATCH 3/8] readelf: emit simple to parse line .debug_line data Jason Wessel
2012-04-20 21:29 ` Jason Wessel [this message]
2012-04-20 21:29 ` [RFC PATCH 5/8] kallsyms: convert the kallsyms storage to store the type separately Jason Wessel
2012-04-20 21:29 ` [RFC PATCH 6/8] kallsyms: Add kallsyms kallsyms_line_loc_lookup and print function Jason Wessel
2012-04-20 21:29 ` [RFC PATCH 7/8] modules: decode .debug_line sections if provided by insmod Jason Wessel
2012-04-20 21:29 ` [RFC PATCH 8/8] kallsyms,modules: add module_address_line_lookup() to kallsyms_line_loc_lookup() Jason Wessel
2012-04-23 11:44 ` [RFC PATCH 0/8] backtrace/oops with source/line information Masami Hiramatsu
2012-04-23 12:04   ` Jason Wessel
2012-04-27  5:54     ` Masami Hiramatsu
2012-04-27  6:48 ` Cong Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1334957394-12086-5-git-send-email-jason.wessel@windriver.com \
    --to=jason.wessel@windriver.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=mingo@redhat.com \
    --cc=rusty@rustcorp.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.