This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Fix generate note type to SHT_NOTE


Hi,

GDB gcore command (an artifical core file generator) generates core files with
the note section unrecognized by elfutils readelf (eu-readelf).
Bugreported by Phil Muldoon.

Fix is to change the current generated "note0" section type SHT_PROGBITS into
its proper type SHT_NOTE.  Kernel omits the sections table there at all.

Checked on the testsuites of binutils-2.18.50.0.3 multiarch and gdb-CVS x86_64.


Regards,
Jan


Kernel core files:
	There are no sections in this file.

	Program Headers:
	  Type           Offset             VirtAddr           PhysAddr
	                 FileSiz            MemSiz              Flags  Align
	  NOTE           0x00000000000003c0 0x0000000000000000 0x0000000000000000
	                 0x0000000000000324 0x0000000000000000         0
	  LOAD           0x0000000000001000 0x0000000000400000 0x0000000000000000
	                 0x0000000000001000 0x0000000000001000  R E    1000
	...

Former GDB gcore files:
	Section Headers:
	  [Nr] Name              Type             Address           Offset
	       Size              EntSize          Flags  Link  Info  Align
	  [ 0]                   NULL             0000000000000000  00000000
	       0000000000000000  0000000000000000           0     0     0
	  [ 1] note0             PROGBITS         0000000000000000  00000388
	       0000000000000538  0000000000000000   A       0     0     1
	  [ 2] load              NOBITS           0000000000400000  000008c0
	       0000000000001000  0000000000000000  AX       0     0     1
	...
	Program Headers:
	  Type           Offset             VirtAddr           PhysAddr
	                 FileSiz            MemSiz              Flags  Align
	  NOTE           0x0000000000000388 0x0000000000000000 0x0000000000000000
	                 0x0000000000000538 0x0000000000000000  R      1
	  LOAD           0x00000000000008c0 0x0000000000400000 0x0000000000000000
	                 0x0000000000000000 0x0000000000001000  R E    1
	...

elfutils parser:
	handle_notes (Ebl *ebl, GElf_Ehdr *ehdr)
	{
	  /* If we have section headers, just look for SHT_NOTE sections.
	     In a debuginfo file, the program headers are not reliable.  */
	...
	}

Proposed GDB gcore files (fixed elfutils readelf):
	Section Headers:
	  [Nr] Name              Type             Address           Offset
	       Size              EntSize          Flags  Link  Info  Align
	  [ 0]                   NULL             0000000000000000  00000000
	       0000000000000000  0000000000000000           0     0     0
	  [ 1] note0             NOTE             0000000000000000  00000388
	-----------------------> ^^^^
	       0000000000000538  0000000000000000   A       0     0     1
	  [ 2] load              NOBITS           0000000000400000  000008c0
	       0000000000001000  0000000000000000  AX       0     0     1
	...
	Program Headers:
	  Type           Offset             VirtAddr           PhysAddr
	                 FileSiz            MemSiz              Flags  Align
	  NOTE           0x0000000000000388 0x0000000000000000 0x0000000000000000
	                 0x0000000000000538 0x0000000000000000  R      1
	  LOAD           0x00000000000008c0 0x0000000000400000 0x0000000000000000
	                 0x0000000000000000 0x0000000000001000  R E    1
	...
2008-02-16  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* elf.c (assign_file_positions_for_load_sections): Set the type of
	PT_NOTE sections to SHT_NOTE.

--- bfd/elf.c	15 Feb 2008 08:27:18 -0000	1.433
+++ bfd/elf.c	16 Feb 2008 18:47:29 -0000
@@ -4284,6 +4284,10 @@ assign_file_positions_for_load_sections 
 	  bfd_set_error (bfd_error_bad_value);
 	  return FALSE;
 	}
+      /* Set the note section type to SHT_NOTE.  */
+      else if (p->p_type == PT_NOTE)
+	for (i = 0; i < m->count; i++)
+	  elf_section_type (m->sections[i]) = SHT_NOTE;
 
       p->p_offset = 0;
       p->p_filesz = 0;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]