* Re: readelf doesn't support ELF64 on 32bit host
@ 1999-12-03 7:17 Nick Clifton
1999-12-04 14:41 ` H . J . Lu
0 siblings, 1 reply; 8+ messages in thread
From: Nick Clifton @ 1999-12-03 7:17 UTC (permalink / raw)
To: ian, hjl, rth; +Cc: binutils
Hi Guys,
What do you think of this version of the patch to provide readelf
with the ability to display the contenst of the 64bit ELF file on a
32 bit host? I think this patch is ready for application. It now
covers most of the places where bfd_vma's were being treated as
unsigned longs, (and any others that are left over can be handled by
future patches). It implements a new function to print a bfd_vma
value, and it reformts the output for ELF64 files to cope with the
larger numbers.
OK to apply ?
Cheers
Nick
1999-12-03 Nick Clifton <nickc@cygnus.com>
* readelf.c (enum print_mode): New type.
(print_vma): New function.
(dump_relocations): Use print_vma to display bfd_vma values.
(process_file_header): Use print_vma to display bfd_vma values.
(process_program_headers): Use print_vma to display bfd_vma values.
(process_section_headers): Use print_vma to display bfd_vma values.
(dynamic_segment_parisc_val): Use print_vma to display bfd_vma values.
(process_dynamic_segment): Use print_vma to display bfd_vma values.
(process_symbol_table): Use print_vma to display bfd_vma values.
(process_mips_specific): Use print_vma to display bfd_vma values.
Index: readelf.c
===================================================================
RCS file: /cvs/binutils/binutils/binutils/readelf.c,v
retrieving revision 1.29
diff -p -r1.29 readelf.c
*** readelf.c 1999/11/25 11:08:25 1.29
--- readelf.c 1999/12/03 15:13:17
*************** static const char * get_osabi_name
*** 201,207 ****
static int guess_is_rela PARAMS ((unsigned long));
static char * get_note_type PARAMS ((unsigned int));
static int process_note PARAMS ((Elf32_Internal_Note *));
! static int process_corefile_note_segment PARAMS ((FILE *, unsigned long, unsigned long));
static int process_corefile_note_segments PARAMS ((FILE *));
static int process_corefile_contents PARAMS ((FILE *));
--- 201,207 ----
static int guess_is_rela PARAMS ((unsigned long));
static char * get_note_type PARAMS ((unsigned int));
static int process_note PARAMS ((Elf32_Internal_Note *));
! static int process_corefile_note_segment PARAMS ((FILE *, bfd_vma, bfd_vma));
static int process_corefile_note_segments PARAMS ((FILE *));
static int process_corefile_contents PARAMS ((FILE *));
*************** byte_get_little_endian (field, size)
*** 378,383 ****
--- 378,474 ----
}
}
+ /* Print a VMA value. */
+ typedef enum print_mode
+ {
+ HEX,
+ DEC,
+ DEC_5,
+ UNSIGNED,
+ PREFIX_HEX,
+ FULL_HEX,
+ LONG_HEX
+ }
+ print_mode;
+
+ static void print_vma PARAMS ((bfd_vma, print_mode));
+
+ static void
+ print_vma (vma, mode)
+ bfd_vma vma;
+ print_mode mode;
+ {
+ #ifdef BFD64
+ if (is_32bit_elf)
+ #endif
+ {
+ switch (mode)
+ {
+ case FULL_HEX: printf ("0x"); /* drop through */
+ case LONG_HEX: printf ("%08.8lx", vma); break;
+ case PREFIX_HEX: printf ("0x"); /* drop through */
+ case HEX: printf ("%lx", vma); break;
+ case DEC: printf ("%ld", vma); break;
+ case DEC_5: printf ("%5ld", vma); break;
+ case UNSIGNED: printf ("%lu", vma); break;
+ }
+ }
+ #ifdef BFD64
+ else
+ {
+ switch (mode)
+ {
+ case FULL_HEX:
+ printf ("0x");
+ /* drop through */
+
+ case LONG_HEX:
+ printf_vma (vma);
+ break;
+
+ case PREFIX_HEX:
+ printf ("0x");
+ /* drop through */
+
+ case HEX:
+ #if BFD_HOST_64BIT_LONG
+ printf ("%lx", vma);
+ #else
+ if (_bfd_int64_high (vma))
+ printf ("%lx%lx", _bfd_int64_high (vma), _bfd_int64_low (vma));
+ else
+ printf ("%lx", _bfd_int64_low (vma));
+ #endif
+ break;
+
+ case DEC:
+ if (_bfd_int64_high (vma))
+ /* ugg */
+ printf ("++%ld", _bfd_int64_low (vma));
+ else
+ printf ("%ld", _bfd_int64_low (vma));
+ break;
+
+ case DEC_5:
+ if (_bfd_int64_high (vma))
+ /* ugg */
+ printf ("++%ld", _bfd_int64_low (vma));
+ else
+ printf ("%5ld", _bfd_int64_low (vma));
+ break;
+
+ case UNSIGNED:
+ if (_bfd_int64_high (vma))
+ /* ugg */
+ printf ("++%lu", _bfd_int64_low (vma));
+ else
+ printf ("%lu", _bfd_int64_low (vma));
+ break;
+ }
+ }
+ #endif
+ }
+
static bfd_vma
byte_get_big_endian (field, size)
unsigned char * field;
*************** dump_relocations (file, rel_offset, rel_
*** 772,778 ****
psym = symtab + symtab_index;
! printf (" %08lx ", (unsigned long) psym->st_value);
if (psym->st_name == 0)
printf ("%-25.25s",
--- 863,871 ----
psym = symtab + symtab_index;
! printf (" ");
! print_vma (psym->st_value, LONG_HEX);
! printf (" ");
if (psym->st_name == 0)
printf ("%-25.25s",
*************** dump_relocations (file, rel_offset, rel_
*** 788,794 ****
}
}
else if (is_rela)
! printf ("%34c%lx", ' ', (unsigned long) relas[i].r_addend);
if (elf_header.e_machine == EM_SPARCV9
&& !strcmp (rtype, "R_SPARC_OLO10"))
--- 881,890 ----
}
}
else if (is_rela)
! {
! printf ("%*c", is_32bit_elf ? 34 : 26, ' ');
! print_vma (relas[i].r_addend, LONG_HEX);
! }
if (elf_header.e_machine == EM_SPARCV9
&& !strcmp (rtype, "R_SPARC_OLO10"))
*************** process_file_header ()
*** 1828,1839 ****
get_machine_name (elf_header.e_machine));
printf (_(" Version: 0x%lx\n"),
(unsigned long) elf_header.e_version);
! printf (_(" Entry point address: 0x%lx\n"),
! (unsigned long) elf_header.e_entry);
! printf (_(" Start of program headers: %ld (bytes into file)\n"),
! (long) elf_header.e_phoff);
! printf (_(" Start of section headers: %ld (bytes into file)\n"),
! (long) elf_header.e_shoff);
printf (_(" Flags: 0x%lx%s\n"),
(unsigned long) elf_header.e_flags,
get_machine_flags (elf_header.e_flags, elf_header.e_machine));
--- 1924,1938 ----
get_machine_name (elf_header.e_machine));
printf (_(" Version: 0x%lx\n"),
(unsigned long) elf_header.e_version);
!
! printf (_(" Entry point address: "));
! print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
! printf (_("\n Start of program headers: "));
! print_vma ((bfd_vma) elf_header.e_phoff, DEC);
! printf (_(" (bytes into file)\n Start of section headers: "));
! print_vma ((bfd_vma) elf_header.e_shoff, DEC);
! printf (_(" (bytes into file)\n"));
!
printf (_(" Flags: 0x%lx%s\n"),
(unsigned long) elf_header.e_flags,
get_machine_flags (elf_header.e_flags, elf_header.e_machine));
*************** process_program_headers (file)
*** 1938,1947 ****
if (do_segments && !do_header)
{
! printf (_("\nElf file is %s\n"), get_file_type (elf_header.e_type));
! printf (_("Entry point 0x%lx\n"), (unsigned long) elf_header.e_entry);
! printf (_("There are %d program headers, starting at offset %lx:\n"),
! elf_header.e_phnum, (unsigned long) elf_header.e_phoff);
}
program_headers = (Elf_Internal_Phdr *) malloc
--- 2037,2049 ----
if (do_segments && !do_header)
{
! printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
! printf (_("Entry point "));
! print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
! printf (_("\nThere are %d program headers, starting at offset "),
! elf_header.e_phnum);
! print_vma ((bfd_vma) elf_header.e_phoff, DEC);
! printf ("\n");
}
program_headers = (Elf_Internal_Phdr *) malloc
*************** process_program_headers (file)
*** 1968,1975 ****
{
printf
(_("\nProgram Header%s:\n"), elf_header.e_phnum > 1 ? "s" : "");
! printf
! (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
}
loadaddr = -1;
--- 2070,2086 ----
{
printf
(_("\nProgram Header%s:\n"), elf_header.e_phnum > 1 ? "s" : "");
!
! if (is_32bit_elf)
! printf
! (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
! else
! {
! printf
! (_(" Type Offset VirtAddr PhysAddr\n"));
! printf
! (_(" FileSiz MemSiz Flags Align\n"));
! }
}
loadaddr = -1;
*************** process_program_headers (file)
*** 1983,1998 ****
if (do_segments)
{
printf (" %-14.14s ", get_segment_type (segment->p_type));
! printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
! printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
! printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
! printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
! printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
! printf ("%c%c%c ",
! (segment->p_flags & PF_R ? 'R' : ' '),
! (segment->p_flags & PF_W ? 'W' : ' '),
! (segment->p_flags & PF_X ? 'E' : ' '));
! printf ("%#lx", (unsigned long) segment->p_align);
}
switch (segment->p_type)
--- 2094,2130 ----
if (do_segments)
{
printf (" %-14.14s ", get_segment_type (segment->p_type));
!
! if (is_32bit_elf)
! {
! printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
! printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
! printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
! printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
! printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
! printf ("%c%c%c ",
! (segment->p_flags & PF_R ? 'R' : ' '),
! (segment->p_flags & PF_W ? 'W' : ' '),
! (segment->p_flags & PF_X ? 'E' : ' '));
! printf ("%#lx", (unsigned long) segment->p_align);
! }
! else
! {
! print_vma (segment->p_offset, FULL_HEX);
! putchar (' ');
! print_vma (segment->p_vaddr, FULL_HEX);
! putchar (' ');
! print_vma (segment->p_paddr, FULL_HEX);
! printf ("\n ");
! print_vma (segment->p_filesz, FULL_HEX);
! putchar (' ');
! print_vma (segment->p_memsz, FULL_HEX);
! printf (" %c%c%c ",
! (segment->p_flags & PF_R ? 'R' : ' '),
! (segment->p_flags & PF_W ? 'W' : ' '),
! (segment->p_flags & PF_X ? 'E' : ' '));
! print_vma (segment->p_align, HEX);
! }
}
switch (segment->p_type)
*************** process_program_headers (file)
*** 2012,2018 ****
break;
case PT_INTERP:
! if (fseek (file, segment->p_offset, SEEK_SET))
error (_("Unable to find program interpreter name\n"));
else
{
--- 2144,2150 ----
break;
case PT_INTERP:
! if (fseek (file, (long) segment->p_offset, SEEK_SET))
error (_("Unable to find program interpreter name\n"));
else
{
*************** process_section_headers (file)
*** 2343,2350 ****
return 1;
printf (_("\nSection Header%s:\n"), elf_header.e_shnum > 1 ? "s" : "");
! printf
! (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
for (i = 0, section = section_headers;
i < elf_header.e_shnum;
--- 2475,2488 ----
return 1;
printf (_("\nSection Header%s:\n"), elf_header.e_shnum > 1 ? "s" : "");
! if (is_32bit_elf)
! printf
! (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
! else
! {
! printf (_(" [Nr] Name Type Address Offset\n"));
! printf (_(" Size EntSize Flags Link Info Align\n"));
! }
for (i = 0, section = section_headers;
i < elf_header.e_shnum;
*************** process_section_headers (file)
*** 2355,2373 ****
SECTION_NAME (section),
get_section_type_name (section->sh_type));
! printf ( "%8.8lx %6.6lx %6.6lx %2.2lx",
! (unsigned long) section->sh_addr,
! (unsigned long) section->sh_offset,
! (unsigned long) section->sh_size,
! (unsigned long) section->sh_entsize);
!
! printf (" %c%c%c %2ld %3lx %ld\n",
! (section->sh_flags & SHF_WRITE ? 'W' : ' '),
! (section->sh_flags & SHF_ALLOC ? 'A' : ' '),
! (section->sh_flags & SHF_EXECINSTR ? 'X' : ' '),
! (unsigned long) section->sh_link,
! (unsigned long) section->sh_info,
! (unsigned long) section->sh_addralign);
}
return 1;
--- 2493,2535 ----
SECTION_NAME (section),
get_section_type_name (section->sh_type));
! if (is_32bit_elf)
! {
! print_vma (section->sh_addr, LONG_HEX);
!
! printf ( " %6.6lx %6.6lx %2.2lx",
! (unsigned long) section->sh_offset,
! (unsigned long) section->sh_size,
! (unsigned long) section->sh_entsize);
!
! printf (" %c%c%c %2ld %3lx %ld\n",
! (section->sh_flags & SHF_WRITE ? 'W' : ' '),
! (section->sh_flags & SHF_ALLOC ? 'A' : ' '),
! (section->sh_flags & SHF_EXECINSTR ? 'X' : ' '),
! (unsigned long) section->sh_link,
! (unsigned long) section->sh_info,
! (unsigned long) section->sh_addralign);
! }
! else
! {
! putchar (' ');
! print_vma (section->sh_addr, LONG_HEX);
! printf (" %08.8lx", section->sh_offset);
! printf ("\n ");
! print_vma (section->sh_size, LONG_HEX);
! printf (" ");
! print_vma (section->sh_entsize, LONG_HEX);
!
! printf (" %c%c%c",
! (section->sh_flags & SHF_WRITE ? 'W' : ' '),
! (section->sh_flags & SHF_ALLOC ? 'A' : ' '),
! (section->sh_flags & SHF_EXECINSTR ? 'X' : ' '));
!
! printf (" %2ld %3lx %ld\n",
! (unsigned long) section->sh_link,
! (unsigned long) section->sh_info,
! (unsigned long) section->sh_addralign);
! }
}
return 1;
*************** dynamic_segment_parisc_val (entry)
*** 2601,2607 ****
};
int first = 1;
int cnt;
! long int val = entry->d_un.d_val;
for (cnt = 0; cnt < sizeof (flags) / sizeof (flags[0]); ++cnt)
if (val & flags[cnt].bit)
--- 2763,2769 ----
};
int first = 1;
int cnt;
! bfd_vma val = entry->d_un.d_val;
for (cnt = 0; cnt < sizeof (flags) / sizeof (flags[0]); ++cnt)
if (val & flags[cnt].bit)
*************** dynamic_segment_parisc_val (entry)
*** 2613,2625 ****
val ^= flags[cnt].bit;
}
if (val != 0 || first)
! printf ("%s%#lx", first ? "" : " ", val);
! puts ("");
}
break;
default:
! printf ("%#lx\n", (long) entry->d_un.d_ptr);
}
}
--- 2775,2791 ----
val ^= flags[cnt].bit;
}
if (val != 0 || first)
! {
! if (! first)
! putchar (' ');
! print_vma (val, HEX);
! }
}
break;
default:
! print_vma (entry->d_un.d_ptr, PREFIX_HEX);
! break;
}
}
*************** process_dynamic_segment (file)
*** 2866,2876 ****
i++, entry ++)
{
if (do_dynamic)
! printf (_(" 0x%-8.8lx (%s)%*s"),
! (unsigned long) entry->d_tag,
! get_dynamic_type (entry->d_tag),
! 27 - strlen (get_dynamic_type (entry->d_tag)),
! " ");
switch (entry->d_tag)
{
--- 3032,3045 ----
i++, entry ++)
{
if (do_dynamic)
! {
! putchar (' ');
! print_vma (entry->d_tag, FULL_HEX);
! printf (" (%s)%*s",
! get_dynamic_type (entry->d_tag),
! (is_32bit_elf ? 27 : 19) - strlen (get_dynamic_type (entry->d_tag)),
! " ");
! }
switch (entry->d_tag)
{
*************** process_dynamic_segment (file)
*** 2886,2892 ****
if (dynamic_strings)
printf (": [%s]\n", dynamic_strings + entry->d_un.d_val);
else
! printf (": %#lx\n", (long) entry->d_un.d_val);
}
break;
--- 3055,3065 ----
if (dynamic_strings)
printf (": [%s]\n", dynamic_strings + entry->d_un.d_val);
else
! {
! printf (": ");
! print_vma (entry->d_un.d_val, PREFIX_HEX);
! putchar ('\n');
! }
}
break;
*************** process_dynamic_segment (file)
*** 3047,3072 ****
case DT_NEEDED:
printf (_("Shared library: [%s]"), name);
! if (strcmp (name, program_interpreter))
! printf ("\n");
! else
! printf (_(" program interpreter\n"));
break;
case DT_SONAME:
! printf (_("Library soname: [%s]\n"), name);
break;
case DT_RPATH:
! printf (_("Library rpath: [%s]\n"), name);
break;
default:
! printf ("%#lx\n", (long) entry->d_un.d_val);
}
}
else
! printf ("%#lx\n", (long) entry->d_un.d_val);
}
break;
--- 3220,3246 ----
case DT_NEEDED:
printf (_("Shared library: [%s]"), name);
! if (strcmp (name, program_interpreter) == 0)
! printf (_(" program interpreter"));
break;
case DT_SONAME:
! printf (_("Library soname: [%s]"), name);
break;
case DT_RPATH:
! printf (_("Library rpath: [%s]"), name);
break;
default:
! print_vma (entry->d_un.d_val, PREFIX_HEX);
! break;
}
}
else
! print_vma (entry->d_un.d_val, PREFIX_HEX);
!
! putchar ('\n');
}
break;
*************** process_dynamic_segment (file)
*** 3083,3089 ****
case DT_INIT_ARRAYSZ:
case DT_FINI_ARRAYSZ:
if (do_dynamic)
! printf ("%lu (bytes)\n", (unsigned long) entry->d_un.d_val);
break;
case DT_VERDEFNUM:
--- 3257,3266 ----
case DT_INIT_ARRAYSZ:
case DT_FINI_ARRAYSZ:
if (do_dynamic)
! {
! print_vma (entry->d_un.d_val, UNSIGNED);
! printf (" (bytes)\n");
! }
break;
case DT_VERDEFNUM:
*************** process_dynamic_segment (file)
*** 3091,3097 ****
case DT_RELACOUNT:
case DT_RELCOUNT:
if (do_dynamic)
! printf ("%lu\n", (unsigned long) entry->d_un.d_val);
break;
case DT_SYMINSZ:
--- 3268,3277 ----
case DT_RELACOUNT:
case DT_RELCOUNT:
if (do_dynamic)
! {
! print_vma (entry->d_un.d_val, UNSIGNED);
! putchar ('\n');
! }
break;
case DT_SYMINSZ:
*************** process_dynamic_segment (file)
*** 3115,3121 ****
}
}
! printf ("%#lx\n", (long) entry->d_un.d_val);
}
break;
--- 3295,3302 ----
}
}
! print_vma (entry->d_un.d_val, PREFIX_HEX);
! putchar ('\n');
}
break;
*************** process_dynamic_segment (file)
*** 3140,3146 ****
dynamic_segment_parisc_val (entry);
break;
default:
! printf ("%#lx\n", (long) entry->d_un.d_ptr);
}
}
break;
--- 3321,3328 ----
dynamic_segment_parisc_val (entry);
break;
default:
! print_vma (entry->d_un.d_val, PREFIX_HEX);
! putchar ('\n');
}
}
break;
*************** process_symbol_table (file)
*** 3844,3866 ****
int si;
printf (_("\nSymbol table for image:\n"));
! printf (_(" Num Buc: Value Size Type Bind Ot Ndx Name\n"));
for (hn = 0; hn < nbuckets; hn++)
{
if (! buckets [hn])
continue;
! for (si = buckets [hn]; si; si = chains [si])
{
Elf_Internal_Sym * psym;
psym = dynamic_symbols + si;
! printf (" %3d %3d: %8lx %5ld %6s %6s %2d ",
! si, hn,
! (unsigned long) psym->st_value,
! (unsigned long) psym->st_size,
get_symbol_type (ELF_ST_TYPE (psym->st_info)),
get_symbol_binding (ELF_ST_BIND (psym->st_info)),
psym->st_other);
--- 4026,4053 ----
int si;
printf (_("\nSymbol table for image:\n"));
! if (is_32bit_elf)
! printf (_(" Num Buc: Value Size Type Bind Ot Ndx Name\n"));
! else
! printf (_(" Num Buc: Value Size Type Bind Ot Ndx Name\n"));
for (hn = 0; hn < nbuckets; hn++)
{
if (! buckets [hn])
continue;
! for (si = buckets [hn]; si < nchains && si > 0; si = chains [si])
{
Elf_Internal_Sym * psym;
psym = dynamic_symbols + si;
! printf (" %3d %3d: ", si, hn);
! print_vma (psym->st_value, LONG_HEX);
! putchar (' ' );
! print_vma (psym->st_size, DEC_5);
!
! printf (" %6s %6s %2d ",
get_symbol_type (ELF_ST_TYPE (psym->st_info)),
get_symbol_binding (ELF_ST_BIND (psym->st_info)),
psym->st_other);
*************** process_symbol_table (file)
*** 3892,3899 ****
printf (_("\nSymbol table '%s' contains %lu entries:\n"),
SECTION_NAME (section),
(unsigned long) (section->sh_size / section->sh_entsize));
! fputs (_(" Num: Value Size Type Bind Ot Ndx Name\n"),
! stdout);
symtab = GET_ELF_SYMBOLS (file, section->sh_offset,
section->sh_size / section->sh_entsize);
--- 4079,4088 ----
printf (_("\nSymbol table '%s' contains %lu entries:\n"),
SECTION_NAME (section),
(unsigned long) (section->sh_size / section->sh_entsize));
! if (is_32bit_elf)
! printf (_(" Num: Value Size Type Bind Ot Ndx Name\n"));
! else
! printf (_(" Num: Value Size Type Bind Ot Ndx Name\n"));
symtab = GET_ELF_SYMBOLS (file, section->sh_offset,
section->sh_size / section->sh_entsize);
*************** process_symbol_table (file)
*** 3916,3925 ****
si < section->sh_size / section->sh_entsize;
si ++, psym ++)
{
! printf (" %3d: %8lx %5ld %-7s %-6s %2d ",
! si,
! (unsigned long) psym->st_value,
! (unsigned long) psym->st_size,
get_symbol_type (ELF_ST_TYPE (psym->st_info)),
get_symbol_binding (ELF_ST_BIND (psym->st_info)),
psym->st_other);
--- 4105,4115 ----
si < section->sh_size / section->sh_entsize;
si ++, psym ++)
{
! printf (" %3d: ", si);
! print_vma (psym->st_value, LONG_HEX);
! putchar (' ');
! print_vma (psym->st_size, DEC_5);
! printf (" %-7s %-6s %2d ",
get_symbol_type (ELF_ST_TYPE (psym->st_info)),
get_symbol_binding (ELF_ST_BIND (psym->st_info)),
psym->st_other);
*************** process_symbol_table (file)
*** 4090,4100 ****
if (! buckets [hn])
continue;
! for (si = buckets[hn]; si; si = chains[si])
{
! ++nsyms;
if (maxlength < ++lengths[hn])
! ++maxlength;
}
}
--- 4280,4290 ----
if (! buckets [hn])
continue;
! for (si = buckets[hn]; si > 0 && si < nchains; si = chains[si])
{
! ++ nsyms;
if (maxlength < ++lengths[hn])
! ++ maxlength;
}
}
*************** process_mips_specific (file)
*** 6570,6581 ****
{
Elf_Internal_Sym * psym = &dynamic_symbols[iconf[cnt]];
! printf ("%5u: %8lu %#10lx %s\n",
! cnt, iconf[cnt], (unsigned long) psym->st_value,
! dynamic_strings + psym->st_name);
}
-
free (iconf);
}
--- 6760,6770 ----
{
Elf_Internal_Sym * psym = &dynamic_symbols[iconf[cnt]];
! printf ("%5u: %8lu ", cnt, iconf[cnt]);
! print_vma (psym->st_value, FULL_HEX);
! printf (" %s\n", dynamic_strings + psym->st_name);
}
free (iconf);
}
*************** process_note (pnote)
*** 6624,6631 ****
static int
process_corefile_note_segment (file, offset, length)
FILE * file;
! unsigned long offset;
! unsigned long length;
{
Elf_External_Note * pnotes;
Elf_External_Note * external;
--- 6813,6820 ----
static int
process_corefile_note_segment (file, offset, length)
FILE * file;
! bfd_vma offset;
! bfd_vma length;
{
Elf_External_Note * pnotes;
Elf_External_Note * external;
*************** process_corefile_note_segments (file)
*** 6726,6733 ****
{
if (segment->p_type == PT_NOTE)
res &= process_corefile_note_segment (file,
! (unsigned long)segment->p_offset,
! (unsigned long)segment->p_filesz);
}
free (program_headers);
--- 6915,6922 ----
{
if (segment->p_type == PT_NOTE)
res &= process_corefile_note_segment (file,
! (bfd_vma)segment->p_offset,
! (bfd_vma)segment->p_filesz);
}
free (program_headers);
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: readelf doesn't support ELF64 on 32bit host
1999-12-03 7:17 readelf doesn't support ELF64 on 32bit host Nick Clifton
@ 1999-12-04 14:41 ` H . J . Lu
0 siblings, 0 replies; 8+ messages in thread
From: H . J . Lu @ 1999-12-04 14:41 UTC (permalink / raw)
To: Nick Clifton; +Cc: ian, rth, binutils
On Fri, Dec 03, 1999 at 03:17:12PM +0000, Nick Clifton wrote:
> Hi Guys,
>
> What do you think of this version of the patch to provide readelf
> with the ability to display the contenst of the 64bit ELF file on a
> 32 bit host? I think this patch is ready for application. It now
> covers most of the places where bfd_vma's were being treated as
> unsigned longs, (and any others that are left over can be handled by
> future patches). It implements a new function to print a bfd_vma
> value, and it reformts the output for ELF64 files to cope with the
> larger numbers.
>
> OK to apply ?
>
I like this patch. Here is a small patch for compiler warnings.
Also it supports up to 999999 symbols from 999 symbols.
Thanks.
H.J.
---
--- readelf.c.nick Sat Dec 4 14:15:54 1999
+++ readelf.c Sat Dec 4 14:29:23 1999
@@ -405,12 +405,12 @@ print_vma (vma, mode)
switch (mode)
{
case FULL_HEX: printf ("0x"); /* drop through */
- case LONG_HEX: printf ("%08.8lx", vma); break;
+ case LONG_HEX: printf ("%8.8lx", (unsigned long) vma); break;
case PREFIX_HEX: printf ("0x"); /* drop through */
- case HEX: printf ("%lx", vma); break;
- case DEC: printf ("%ld", vma); break;
- case DEC_5: printf ("%5ld", vma); break;
- case UNSIGNED: printf ("%lu", vma); break;
+ case HEX: printf ("%lx", (unsigned long) vma); break;
+ case DEC: printf ("%ld", (unsigned long) vma); break;
+ case DEC_5: printf ("%5ld", (unsigned long) vma); break;
+ case UNSIGNED: printf ("%lu", (unsigned long) vma); break;
}
}
#ifdef BFD64
@@ -2503,7 +2503,7 @@ process_section_headers (file)
{
putchar (' ');
print_vma (section->sh_addr, LONG_HEX);
- printf (" %08.8lx", section->sh_offset);
+ printf (" %8.8lx", section->sh_offset);
printf ("\n ");
print_vma (section->sh_size, LONG_HEX);
printf (" ");
@@ -2751,7 +2751,7 @@ dynamic_segment_parisc_val (entry)
{ DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" }
};
int first = 1;
- int cnt;
+ size_t cnt;
bfd_vma val = entry->d_un.d_val;
for (cnt = 0; cnt < sizeof (flags) / sizeof (flags[0]); ++cnt)
@@ -3970,7 +3970,7 @@ process_symbol_table (file)
char nb [4];
char nc [4];
int nbuckets = 0;
- int nchains;
+ int nchains = 0;
int * buckets = NULL;
int * chains = NULL;
@@ -4069,9 +4069,9 @@ process_symbol_table (file)
SECTION_NAME (section),
(unsigned long) (section->sh_size / section->sh_entsize));
if (is_32bit_elf)
- printf (_(" Num: Value Size Type Bind Ot Ndx Name\n"));
+ printf (_(" Num: Value Size Type Bind Ot Ndx Name\n"));
else
- printf (_(" Num: Value Size Type Bind Ot Ndx Name\n"));
+ printf (_(" Num: Value Size Type Bind Ot Ndx Name\n"));
symtab = GET_ELF_SYMBOLS (file, section->sh_offset,
section->sh_size / section->sh_entsize);
@@ -4094,7 +4094,7 @@ process_symbol_table (file)
si < section->sh_size / section->sh_entsize;
si ++, psym ++)
{
- printf (" %3d: ", si);
+ printf ("%6d: ", si);
print_vma (psym->st_value, LONG_HEX);
putchar (' ');
print_vma (psym->st_size, DEC_5);
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: readelf doesn't support ELF64 on 32bit host
@ 1999-12-07 13:25 Nick Clifton
0 siblings, 0 replies; 8+ messages in thread
From: Nick Clifton @ 1999-12-07 13:25 UTC (permalink / raw)
To: binutils
Hi Guys,
I have now applied this patch to the sources (together with HJ's
fixes).
Cheers
Nick
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: readelf doesn't support ELF64 on 32bit host
1999-12-02 10:20 Nick Clifton
@ 1999-12-02 10:25 ` Ian Lance Taylor
0 siblings, 0 replies; 8+ messages in thread
From: Ian Lance Taylor @ 1999-12-02 10:25 UTC (permalink / raw)
To: nickc; +Cc: hjl, rth, binutils
Date: Thu, 2 Dec 1999 18:20:06 GMT
From: Nick Clifton <nickc@cygnus.com>
+ /* Define a macro to print out hex values. */
+ #if BFD_ARCH_SIZE >= 64
+ #define PRINT_32BIT_DEC "%ld"
+ #define PRINT_64BIT_DEC "%ld"
+ #define PRINT_32BIT_HEX "0x%lx"
+ #define PRINT_64BIT_HEX "0x%lx"
+ #define PRINT_FULL_64BIT_HEX "0x%16.16lx"
+ #else
+ #define PRINT_32BIT_DEC "%ld"
+ #define PRINT_64BIT_DEC "%lld"
+ #define PRINT_32BIT_HEX "0x%lx"
+ #define PRINT_64BIT_HEX "0x%llx"
+ #define PRINT_FULL_64BIT_HEX "0x%16.16llx"
+ #endif
+
+ #define PRINT_ADDRESS (is_32bit_elf ? PRINT_32BIT_HEX : PRINT_64BIT_HEX)
+ #define PRINT_OFFSET (is_32bit_elf ? PRINT_32BIT_DEC : PRINT_64BIT_DEC)
If BFD_ARCH_SIZE == 64, it's not correct to assume that %lx will print
a bfd_vma value. You should use [fs]printf_vma instead.
Ian
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: readelf doesn't support ELF64 on 32bit host
@ 1999-12-02 10:20 Nick Clifton
1999-12-02 10:25 ` Ian Lance Taylor
0 siblings, 1 reply; 8+ messages in thread
From: Nick Clifton @ 1999-12-02 10:20 UTC (permalink / raw)
To: hjl, rth; +Cc: binutils
Hi Guys,
OK I have started to work on fixing this. Below is a patch that
starts the work off. So far all that has been fixed is the
displaying of the file header and the program headers.
I am posting this patch in case anyone wants to make any suggestions
or comments on the way I am putting in the support for displaying 64
bit ELF files.
After applying this patch the output for 'readelf -l' on a simple
64 bit hello world executable looks like this:
------------------------------------------------------------------------
Elf file type is EXEC (Executable file)
Entry point 0x120000380
There are 6 program headers, starting at offset 64
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
PHDR 0x0000000000000040 0x0000000120000040 0x0000000120000040
0x0000000000000150 0x0000000000000150 R E 0x8
INTERP 0x0000000000000190 0x0000000120000190 0x0000000120000190
0x0000000000000013 0x0000000000000013 R 0x1
[Requesting program interpreter: /lib/ld-linux.so.2]
LOAD 0x0000000000000000 0x0000000120000000 0x0000000120000000
0x0000000000000515 0x0000000000000515 R E 0x10000
LOAD 0x0000000000000515 0x0000000120100515 0x0000000120100515
0x00000000000001f3 0x00000000000001f3 RWE 0x10000
DYNAMIC 0x00000000000005c8 0x00000001201005c8 0x00000001201005c8
0x0000000000000140 0x0000000000000140 RW 0x8
NOTE 0x00000000000001b0 0x00000001200001b0 0x00000001200001b0
0x0000000000000020 0x0000000000000020 R 0x10
Section to Segment mapping:
Segment Sections...
00
01 .interp
02 .interp .note.ABI-tag .hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.plt .init .text .fini .rodata
03 .ctors .dtors .plt .got .dynamic
04 .dynamic
05 .note.ABI-tag
-------------------------------------------------------------------------
Cheers
Nick
Index: readelf.c
===================================================================
RCS file: /cvs/binutils/binutils/binutils/readelf.c,v
retrieving revision 1.29
diff -p -r1.29 readelf.c
*** readelf.c 1999/11/25 11:08:25 1.29
--- readelf.c 1999/12/02 18:15:57
***************
*** 37,42 ****
--- 37,60 ----
#include "bfd.h"
+ /* Define a macro to print out hex values. */
+ #if BFD_ARCH_SIZE >= 64
+ #define PRINT_32BIT_DEC "%ld"
+ #define PRINT_64BIT_DEC "%ld"
+ #define PRINT_32BIT_HEX "0x%lx"
+ #define PRINT_64BIT_HEX "0x%lx"
+ #define PRINT_FULL_64BIT_HEX "0x%16.16lx"
+ #else
+ #define PRINT_32BIT_DEC "%ld"
+ #define PRINT_64BIT_DEC "%lld"
+ #define PRINT_32BIT_HEX "0x%lx"
+ #define PRINT_64BIT_HEX "0x%llx"
+ #define PRINT_FULL_64BIT_HEX "0x%16.16llx"
+ #endif
+
+ #define PRINT_ADDRESS (is_32bit_elf ? PRINT_32BIT_HEX : PRINT_64BIT_HEX)
+ #define PRINT_OFFSET (is_32bit_elf ? PRINT_32BIT_DEC : PRINT_64BIT_DEC)
+
#include "elf/common.h"
#include "elf/external.h"
#include "elf/internal.h"
*************** process_file_header ()
*** 1828,1839 ****
get_machine_name (elf_header.e_machine));
printf (_(" Version: 0x%lx\n"),
(unsigned long) elf_header.e_version);
! printf (_(" Entry point address: 0x%lx\n"),
! (unsigned long) elf_header.e_entry);
! printf (_(" Start of program headers: %ld (bytes into file)\n"),
! (long) elf_header.e_phoff);
! printf (_(" Start of section headers: %ld (bytes into file)\n"),
! (long) elf_header.e_shoff);
printf (_(" Flags: 0x%lx%s\n"),
(unsigned long) elf_header.e_flags,
get_machine_flags (elf_header.e_flags, elf_header.e_machine));
--- 1846,1860 ----
get_machine_name (elf_header.e_machine));
printf (_(" Version: 0x%lx\n"),
(unsigned long) elf_header.e_version);
!
! printf (_(" Entry point address: "));
! printf (PRINT_ADDRESS, (bfd_vma) elf_header.e_entry);
! printf (_("\n Start of program headers: "));
! printf (PRINT_OFFSET, (bfd_vma) elf_header.e_phoff);
! printf (_(" (bytes into file)\n Start of section headers: "));
! printf (PRINT_OFFSET, (bfd_vma) elf_header.e_shoff);
! printf (_(" (bytes into file)\n"));
!
printf (_(" Flags: 0x%lx%s\n"),
(unsigned long) elf_header.e_flags,
get_machine_flags (elf_header.e_flags, elf_header.e_machine));
*************** process_program_headers (file)
*** 1938,1947 ****
if (do_segments && !do_header)
{
! printf (_("\nElf file is %s\n"), get_file_type (elf_header.e_type));
! printf (_("Entry point 0x%lx\n"), (unsigned long) elf_header.e_entry);
! printf (_("There are %d program headers, starting at offset %lx:\n"),
! elf_header.e_phnum, (unsigned long) elf_header.e_phoff);
}
program_headers = (Elf_Internal_Phdr *) malloc
--- 1959,1971 ----
if (do_segments && !do_header)
{
! printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
! printf (_("Entry point "));
! printf (PRINT_ADDRESS, (bfd_vma) elf_header.e_entry);
! printf (_("\nThere are %d program headers, starting at offset "),
! elf_header.e_phnum);
! printf (PRINT_OFFSET, (bfd_vma) elf_header.e_phoff);
! printf ("\n");
}
program_headers = (Elf_Internal_Phdr *) malloc
*************** process_program_headers (file)
*** 1968,1975 ****
{
printf
(_("\nProgram Header%s:\n"), elf_header.e_phnum > 1 ? "s" : "");
! printf
! (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
}
loadaddr = -1;
--- 1992,2008 ----
{
printf
(_("\nProgram Header%s:\n"), elf_header.e_phnum > 1 ? "s" : "");
!
! if (is_32bit_elf)
! printf
! (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
! else
! {
! printf
! (_(" Type Offset VirtAddr PhysAddr\n"));
! printf
! (_(" FileSiz MemSiz Flags Align\n"));
! }
}
loadaddr = -1;
*************** process_program_headers (file)
*** 1983,1998 ****
if (do_segments)
{
printf (" %-14.14s ", get_segment_type (segment->p_type));
! printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
! printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
! printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
! printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
! printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
! printf ("%c%c%c ",
! (segment->p_flags & PF_R ? 'R' : ' '),
! (segment->p_flags & PF_W ? 'W' : ' '),
! (segment->p_flags & PF_X ? 'E' : ' '));
! printf ("%#lx", (unsigned long) segment->p_align);
}
switch (segment->p_type)
--- 2016,2052 ----
if (do_segments)
{
printf (" %-14.14s ", get_segment_type (segment->p_type));
!
! if (is_32bit_elf)
! {
! printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
! printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
! printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
! printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
! printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
! printf ("%c%c%c ",
! (segment->p_flags & PF_R ? 'R' : ' '),
! (segment->p_flags & PF_W ? 'W' : ' '),
! (segment->p_flags & PF_X ? 'E' : ' '));
! printf ("%#lx", (unsigned long) segment->p_align);
! }
! else
! {
! printf (PRINT_FULL_64BIT_HEX, segment->p_offset);
! putchar (' ');
! printf (PRINT_FULL_64BIT_HEX, segment->p_vaddr);
! putchar (' ');
! printf (PRINT_FULL_64BIT_HEX, segment->p_paddr);
! printf ("\n ");
! printf (PRINT_FULL_64BIT_HEX, segment->p_filesz);
! putchar (' ');
! printf (PRINT_FULL_64BIT_HEX, segment->p_memsz);
! printf (" %c%c%c ",
! (segment->p_flags & PF_R ? 'R' : ' '),
! (segment->p_flags & PF_W ? 'W' : ' '),
! (segment->p_flags & PF_X ? 'E' : ' '));
! printf (PRINT_64BIT_HEX, segment->p_align);
! }
}
switch (segment->p_type)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: readelf doesn't support ELF64 on 32bit host
1999-12-01 9:32 H.J. Lu
@ 1999-12-01 13:04 ` Geoff Keating
0 siblings, 0 replies; 8+ messages in thread
From: Geoff Keating @ 1999-12-01 13:04 UTC (permalink / raw)
To: hjl; +Cc: rth, binutils
> Date: Wed, 1 Dec 1999 09:30:54 -0800 (PST)
> Cc: binutils@sourceware.cygnus.com
> From: hjl@valinux.com (H.J. Lu)
> readelf doesn't support ELF64 on 32bit host. All 64bit values are
> truncated to 32 bit. I am trying to fix it. But it happens all over
> the place. I am afraid I may make many mistakes. Am I the only one
> who is interested in 64 bit support for readelf on 32bit host?
You mean that if you say
./configure --target=sparc64-unknown-elf
on, say, i386-linux, then readelf does not work?
That would be bad. Since I'm fairly sure that I've tried this and run
'make check' and nothing terrible happened, can you write a testcase
to show the problem? That way people will notice.
--
- Geoffrey Keating <geoffk@cygnus.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: readelf doesn't support ELF64 on 32bit host
@ 1999-12-01 9:40 Nick Clifton
0 siblings, 0 replies; 8+ messages in thread
From: Nick Clifton @ 1999-12-01 9:40 UTC (permalink / raw)
To: hjl; +Cc: rth, binutils
Hi H.J.
: readelf doesn't support ELF64 on 32bit host. All 64bit values are
: truncated to 32 bit. I am trying to fix it. But it happens all over
: the place. I am afraid I may make many mistakes. Am I the only one
: who is interested in 64 bit support for readelf on 32bit host?
This is supposed to work - provided that your host compiler is GCC.
Did you see this comment at the start of the readelf sources ?
#if __GNUC__ >= 2
/* Define BFD64 here, even if our default architecture is 32 bit ELF
as this will allow us to read in and parse 64bit and 32bit ELF files.
Only do this if we belive that the compiler can support a 64 bit
data type. For now we only rely on GCC being able to do this. */
#define BFD64
#endif
Cheers
Nick
^ permalink raw reply [flat|nested] 8+ messages in thread
* readelf doesn't support ELF64 on 32bit host
@ 1999-12-01 9:32 H.J. Lu
1999-12-01 13:04 ` Geoff Keating
0 siblings, 1 reply; 8+ messages in thread
From: H.J. Lu @ 1999-12-01 9:32 UTC (permalink / raw)
To: rth; +Cc: binutils
Hi,
readelf doesn't support ELF64 on 32bit host. All 64bit values are
truncated to 32 bit. I am trying to fix it. But it happens all over
the place. I am afraid I may make many mistakes. Am I the only one
who is interested in 64 bit support for readelf on 32bit host?
--
H.J. Lu (hjl@gnu.org)
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~1999-12-07 13:25 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-12-03 7:17 readelf doesn't support ELF64 on 32bit host Nick Clifton
1999-12-04 14:41 ` H . J . Lu
-- strict thread matches above, loose matches on Subject: below --
1999-12-07 13:25 Nick Clifton
1999-12-02 10:20 Nick Clifton
1999-12-02 10:25 ` Ian Lance Taylor
1999-12-01 9:40 Nick Clifton
1999-12-01 9:32 H.J. Lu
1999-12-01 13:04 ` Geoff Keating
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).