From 598aaa7684fc8ffdbd9a22bef5e321e09ef8a54d Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Sat, 9 Oct 2010 05:52:29 +0000 Subject: [PATCH] Use BYTE_GET_SIGNED on r_addend. 2010-10-08 H.J. Lu * dwarf.c (byte_get_signed): Make it extern. * dwarf.h (byte_get_signed): New. * readelf.c (BYTE_GET_SIGNED): New. (slurp_rela_relocs): Use BYTE_GET_SIGNED on r_addend. (dump_relocations): Properly dump r_addend. --- binutils/ChangeLog | 10 ++++++++++ binutils/dwarf.c | 2 +- binutils/dwarf.h | 1 + binutils/readelf.c | 13 +++++++------ 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 1d9d87592f0..de3d3e9767f 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,13 @@ +2010-10-08 H.J. Lu + + * dwarf.c (byte_get_signed): Make it extern. + + * dwarf.h (byte_get_signed): New. + + * readelf.c (BYTE_GET_SIGNED): New. + (slurp_rela_relocs): Use BYTE_GET_SIGNED on r_addend. + (dump_relocations): Properly dump r_addend. + 2010-10-08 Joseph Myers * nm.c (value_format_64bit): Define appropriately for __MSVCRT__. diff --git a/binutils/dwarf.c b/binutils/dwarf.c index ebe727105ea..60aa7d159d1 100644 --- a/binutils/dwarf.c +++ b/binutils/dwarf.c @@ -163,7 +163,7 @@ byte_get_big_endian (unsigned char *field, int size) } } -static dwarf_vma +dwarf_vma byte_get_signed (unsigned char *field, int size) { dwarf_vma x = byte_get (field, size); diff --git a/binutils/dwarf.h b/binutils/dwarf.h index df90ae0c337..1c47c5efa55 100644 --- a/binutils/dwarf.h +++ b/binutils/dwarf.h @@ -101,6 +101,7 @@ typedef struct debug_info; extern dwarf_vma (*byte_get) (unsigned char *, int); +extern dwarf_vma byte_get_signed (unsigned char *, int); extern dwarf_vma byte_get_little_endian (unsigned char *, int); extern dwarf_vma byte_get_big_endian (unsigned char *, int); diff --git a/binutils/readelf.c b/binutils/readelf.c index b91c5ba7144..1f50ae5ac45 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -272,7 +272,8 @@ static void (* byte_put) (unsigned char *, bfd_vma, int); #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */ -#define BYTE_GET(field) byte_get (field, sizeof (field)) +#define BYTE_GET(field) byte_get (field, sizeof (field)) +#define BYTE_GET_SIGNED(field) byte_get_signed (field, sizeof (field)) #define GET_ELF_SYMBOLS(file, section) \ (is_32bit_elf ? get_32bit_elf_symbols (file, section) \ @@ -734,7 +735,7 @@ slurp_rela_relocs (FILE * file, { relas[i].r_offset = BYTE_GET (erelas[i].r_offset); relas[i].r_info = BYTE_GET (erelas[i].r_info); - relas[i].r_addend = BYTE_GET (erelas[i].r_addend); + relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend); } free (erelas); @@ -764,7 +765,7 @@ slurp_rela_relocs (FILE * file, { relas[i].r_offset = BYTE_GET (erelas[i].r_offset); relas[i].r_info = BYTE_GET (erelas[i].r_info); - relas[i].r_addend = BYTE_GET (erelas[i].r_addend); + relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend); /* The #ifdef BFD64 below is to prevent a compile time warning. We know that if we do not have a 64 bit data @@ -1410,12 +1411,12 @@ dump_relocations (FILE * file, if (is_rela) { - long off = (long) (bfd_signed_vma) rels[i].r_addend; + bfd_signed_vma off = rels[i].r_addend; if (off < 0) - printf (" - %lx", - off); + printf (" - %" BFD_VMA_FMT "x", - off); else - printf (" + %lx", off); + printf (" + %" BFD_VMA_FMT "x", off); } } } -- 2.30.2