This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
PATCH: Add bfd_sprintf_vma/bfd_fprintf_vma
- To: "Maciej W. Rozycki" <macro at ds2 dot pg dot gda dot pl>
- Subject: PATCH: Add bfd_sprintf_vma/bfd_fprintf_vma
- From: "H . J . Lu" <hjl at lucon dot org>
- Date: Wed, 8 Aug 2001 15:06:31 -0700
- Cc: binutils at sourceware dot cygnus dot com
> On Wed, Aug 08, 2001 at 10:11:29AM +0200, Maciej W. Rozycki wrote:
> >
> > Sign-extension is fine. I think what you really want is to truncate
> > addresses in the output of certain programs such as nm and objdump to 32
> > bits if the output BFD is elf32-*mips. It's on my to-do list for some
> > time, but don't hold your breath (i.e. feel free to do it yourself ;-) ).
>
Here is the first step to implement it. After it is checked in, I will
replace as many sprintf_vma/fprintf_vma with _sprintf_vma/bfd_fprintf_vma
as I can to fix it. Any comments?
Thanks.
H.J.
----
2001-08-08 H.J. Lu <hjl@gnu.org>
* bfd-in.h (bfd_sprintf_vma): New prototype.
(bfd_fprintf_vma): Likewise.
(bfd_elf_sprintf_vma): Likewise.
(bfd_elf_fprintf_vma): Likewise.
(bfd_printf_vma): New. Defined with bfd_fprintf_vma.
* bfd.c (bfd_sprintf_vma): New. Defined.
(bfd_fprintf_vma): Likewise.
* elf.c (bfd_elf_sprintf_vma): New. Defined.
(bfd_elf_fprintf_vma): Likewise.
Index: bfd-in.h
===================================================================
RCS file: /work/cvs/gnu/binutils/bfd/bfd-in.h,v
retrieving revision 1.25
diff -u -p -r1.25 bfd-in.h
--- bfd-in.h 2001/06/19 17:57:39 1.25
+++ bfd-in.h 2001/08/08 21:56:25
@@ -183,7 +183,13 @@ typedef unsigned long bfd_size_type;
#endif /* not BFD64 */
+extern void bfd_sprintf_vma PARAMS ((bfd *, char *, bfd_vma));
+extern void bfd_fprintf_vma PARAMS ((bfd *, PTR, bfd_vma));
+extern void bfd_elf_sprintf_vma PARAMS ((bfd *, char *, bfd_vma));
+extern void bfd_elf_fprintf_vma PARAMS ((bfd *, PTR, bfd_vma));
+
#define printf_vma(x) fprintf_vma(stdout,x)
+#define bfd_printf_vma(abfd,x) bfd_fprintf_vma (abfd,stdout,x)
typedef unsigned int flagword; /* 32 bits of flags */
typedef unsigned char bfd_byte;
Index: bfd.c
===================================================================
RCS file: /work/cvs/gnu/binutils/bfd/bfd.c,v
retrieving revision 1.1.1.11
diff -u -p -r1.1.1.11 bfd.c
--- bfd.c 2001/07/03 16:39:26 1.1.1.11
+++ bfd.c 2001/08/08 21:56:26
@@ -1250,3 +1250,25 @@ bfd_record_phdr (abfd, type, flags_valid
return true;
}
+
+void
+bfd_sprintf_vma (abfd, buf, value)
+ bfd *abfd;
+ char *buf;
+ bfd_vma value;
+{
+ if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+ return bfd_elf_sprintf_vma (abfd, buf, value);
+ sprintf_vma (buf, value);
+}
+
+void
+bfd_fprintf_vma (abfd, stream, value)
+ bfd *abfd;
+ PTR stream;
+ bfd_vma value;
+{
+ if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+ return bfd_elf_fprintf_vma (abfd, stream, value);
+ fprintf_vma ((FILE *) stream, value);
+}
Index: elf.c
===================================================================
RCS file: /work/cvs/gnu/binutils/bfd/elf.c,v
retrieving revision 1.58
diff -u -p -r1.58 elf.c
--- elf.c 2001/08/03 15:55:46 1.58
+++ elf.c 2001/08/08 21:56:26
@@ -5986,3 +5986,53 @@ bfd_get_elf_phdrs (abfd, phdrs)
return num_phdrs;
}
+
+void
+bfd_elf_sprintf_vma (abfd, buf, value)
+ bfd *abfd;
+ char *buf;
+ bfd_vma value;
+{
+ Elf_Internal_Ehdr *i_ehdrp; /* Elf file header, internal form */
+
+ i_ehdrp = elf_elfheader (abfd);
+ if (i_ehdrp == NULL)
+ sprintf_vma (buf, value);
+ else
+ {
+ if (i_ehdrp->e_ident[EI_CLASS] == ELFCLASS64)
+#if BFD_HOST_64BIT_LONG
+ sprintf (buf, "%016lx", value);
+#else
+ sprintf (buf, "%08lx%08lx", _bfd_int64_high (value),
+ _bfd_int64_low (value));
+#endif
+ else
+ sprintf (buf, "%08lx", (long) value);
+ }
+}
+
+void
+bfd_elf_fprintf_vma (abfd, stream, value)
+ bfd *abfd;
+ PTR stream;
+ bfd_vma value;
+{
+ Elf_Internal_Ehdr *i_ehdrp; /* Elf file header, internal form */
+
+ i_ehdrp = elf_elfheader (abfd);
+ if (i_ehdrp == NULL)
+ fprintf_vma ((FILE *) stream, value);
+ else
+ {
+ if (i_ehdrp->e_ident[EI_CLASS] == ELFCLASS64)
+#if BFD_HOST_64BIT_LONG
+ fprintf ((FILE *) stream, "%016lx", value);
+#else
+ fprintf ((FILE *) stream, "%08lx%08lx",
+ _bfd_int64_high (value), _bfd_int64_low (value));
+#endif
+ else
+ fprintf ((FILE *) stream, "%08lx", (long) value);
+ }
+}