This is the mail archive of the
binutils@sourceware.cygnus.com
mailing list for the binutils project.
Re: readelf doesn't support ELF64 on 32bit host
- To: hjl at valinux dot com, rth at cygnus dot com
- Subject: Re: readelf doesn't support ELF64 on 32bit host
- From: Nick Clifton <nickc at cygnus dot com>
- Date: Thu, 2 Dec 1999 18:20:06 GMT
- Cc: binutils at sourceware dot cygnus dot com
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)