From ae4221d7c27786eb790a96d65a78cb0fb7d79fcf Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Thu, 9 Aug 2001 16:00:21 +0000 Subject: [PATCH] 2001-08-09 H.J. Lu * 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-in2.h: Regenerated. * bfd.c (bfd_sprintf_vma): New. Defined. (bfd_fprintf_vma): Likewise. * elf.c (bfd_elf_sprintf_vma): New. Defined. (bfd_elf_fprintf_vma): Likewise. --- bfd/ChangeLog | 15 +++++++++++++++ bfd/bfd-in.h | 6 ++++++ bfd/bfd-in2.h | 6 ++++++ bfd/bfd.c | 22 ++++++++++++++++++++++ bfd/elf.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 100 insertions(+) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index bbc1169cae6..046f0881f7b 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,18 @@ +2001-08-09 H.J. Lu + + * 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-in2.h: Regenerated. + + * bfd.c (bfd_sprintf_vma): New. Defined. + (bfd_fprintf_vma): Likewise. + + * elf.c (bfd_elf_sprintf_vma): New. Defined. + (bfd_elf_fprintf_vma): Likewise. + 2001-08-09 Alan Modra * coff-rs6000.c: Add missing prototypes. diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h index a22ddaf97f8..146aac2050c 100644 --- a/bfd/bfd-in.h +++ b/bfd/bfd-in.h @@ -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; diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 5cac1dded92..ee45a95197b 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -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; diff --git a/bfd/bfd.c b/bfd/bfd.c index 6c3272a8770..c663d0ecd72 100644 --- a/bfd/bfd.c +++ b/bfd/bfd.c @@ -1262,3 +1262,25 @@ bfd_record_phdr (abfd, type, flags_valid, flags, at_valid, at, 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); +} diff --git a/bfd/elf.c b/bfd/elf.c index 60e70b6f9cc..746b210d291 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -5994,3 +5994,54 @@ 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", (unsigned long) (value & 0xffffffff)); + } +} + +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", + (unsigned long) (value & 0xffffffff)); + } +} -- 2.30.2