]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
PR binutils/12467
authorNick Clifton <nickc@redhat.com>
Tue, 8 Feb 2011 09:40:05 +0000 (09:40 +0000)
committerNick Clifton <nickc@redhat.com>
Tue, 8 Feb 2011 09:40:05 +0000 (09:40 +0000)
* readelf.c (process_program_headers): Issue a warning if there
are no program headers but the file header has a non-zero program
header offset.
(process_section_headers): Issue a warning if there are no section
headers but the file header has a non-zero section header offset.
(process_section_groups): Reword the no section message so that it
can be distinguished from the one issued by process_section_headers.

* elf.c (assign_file_positions_for_load_sections): Set the program
header offset and entry size to zero if there are no program
headers.

bfd/ChangeLog
bfd/elf.c
binutils/ChangeLog
binutils/readelf.c

index 8a6c44f13c32ab1d8d74c1076aadb45b7ec0b807..9935a841f5f2300f98f3f594d10432d1a3b9ec6c 100644 (file)
@@ -1,3 +1,10 @@
+2011-02-08  Nick Clifton  <nickc@redhat.com>
+
+       PR binutils/12467
+       * elf.c (assign_file_positions_for_load_sections): Set the program
+       header offset and entry size to zero if there are no program
+       headers.
+
 2011-02-08  Alan Modra  <amodra@gmail.com>
 
        * elf64-ppc.c (ppc64_elf_edit_toc): Don't segfault on NULL
index 257cc8c9ebf7a6f4461ea312ff9c8be09c4ef9e4..c77dcedc569fd165ece14e02b9e456b52a96d549 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -4334,8 +4334,18 @@ assign_file_positions_for_load_sections (bfd *abfd,
        header_pad = m->header_size;
     }
 
-  elf_elfheader (abfd)->e_phoff = bed->s->sizeof_ehdr;
-  elf_elfheader (abfd)->e_phentsize = bed->s->sizeof_phdr;
+  if (alloc)
+    {
+      elf_elfheader (abfd)->e_phoff = bed->s->sizeof_ehdr;
+      elf_elfheader (abfd)->e_phentsize = bed->s->sizeof_phdr;
+    }
+  else
+    {
+      /* PR binutils/12467.  */
+      elf_elfheader (abfd)->e_phoff = 0;
+      elf_elfheader (abfd)->e_phentsize = 0;
+    }
+  
   elf_elfheader (abfd)->e_phnum = alloc;
 
   if (elf_tdata (abfd)->program_header_size == (bfd_size_type) -1)
index bab475674818003a97d679a0e71e2bf914aa87c5..4a72f3dac819b68df97fe7b27cd95ca78a85c414 100644 (file)
@@ -1,3 +1,14 @@
+2011-02-08  Nick Clifton  <nickc@redhat.com>
+
+       PR binutils/12467
+       * readelf.c (process_program_headers): Issue a warning if there
+       are no program headers but the file header has a non-zero program
+       header offset.
+       (process_section_headers): Issue a warning if there are no section
+       headers but the file header has a non-zero section header offset.
+       (process_section_groups): Reword the no section message so that it
+       can be distinguished from the one issued by process_section_headers.
+
 2011-01-26  Jan Kratochvil  <jan.kratochvil@redhat.com>
            Doug Evans  <dje@google.com>
 
index af1a00208f2e7f47c83cdffb6e7cee646506705e..0607d897fd8131c31277d0a3c52d0930092aa173 100644 (file)
@@ -3638,7 +3638,11 @@ process_program_headers (FILE * file)
 
   if (elf_header.e_phnum == 0)
     {
-      if (do_segments)
+      /* PR binutils/12467.  */
+      if (elf_header.e_phoff != 0)
+       warn (_("possibly corrupt ELF header - it has a non-zero program"
+               " header offset, but no program headers"));
+      else if (do_segments)
        printf (_("\nThere are no program headers in this file.\n"));
       return 0;
     }
@@ -4377,7 +4381,11 @@ process_section_headers (FILE * file)
 
   if (elf_header.e_shnum == 0)
     {
-      if (do_sections)
+      /* PR binutils/12467.  */
+      if (elf_header.e_shoff != 0)
+       warn (_("possibly corrupt ELF file header - it has a non-zero"
+               " section header offset, but no section headers\n"));
+      else if (do_sections)
        printf (_("\nThere are no sections in this file.\n"));
 
       return 1;
@@ -4860,7 +4868,7 @@ process_section_groups (FILE * file)
   if (elf_header.e_shnum == 0)
     {
       if (do_section_groups)
-       printf (_("\nThere are no sections in this file.\n"));
+       printf (_("\nThere are no sections to group in this file.\n"));
 
       return 1;
     }