[patch] bfd: Core files with p_filesz < p_memsz (build-id)

Jan Kratochvil jan.kratochvil@redhat.com
Sun Jul 29 18:32:00 GMT 2007


On Sat, 28 Jul 2007 22:16:04 +0200, Roland McGrath wrote:
> Are you sure that changing _bfd_elf_make_section_from_phdr is the right way
> to fix gdb?
> 
> It is in a certain sense accurate to split the one segment into two
> sections, a leading SEC_LOAD one and a trailing one without SEC_LOAD.

The core files with `p_filesz == 0' were working before.
_bfd_elf_make_section_from_phdr() can create the sections as two parts, with
the second problematic one emulating the former `p_filesz == 0' core segments.
No new memory structure layout was introduced.  [attached]

Another issue would be changing the sections layout as currently the original
p_memsz is still lost.  Going to post later an add-on incompatible change using
SEC_NEVER_LOAD so that the p_memsz is retained for the bfd library applications
+ across objcopy.


> What does your change do to e.g. objcopy on a core file?

(the previous version was stripping the `load1b' part), thanks for finding it.



Best Regards,
Jan


Patched bfd version with the new `p_filesz == 4096' kernel core file:
	CVS HEAD gdb `info files':
		0x0000000000400000 - 0x0000000000401000 is load1a
		0x0000000000401000 - 0x0000000000401000 is load1b
		0x00000000006b1000 - 0x00000000006bb000 is load2
	objcopy:
	Section Headers:
	[Nr] Name                 Type         Addr             Off      Size     ES Flags Lk Inf Al
	[ 5] load1a               PROGBITS     0000000000400000 00001000 00001000  0 AX     0   0 4096
	[ 6] load1b               PROGBITS     0000000000401000 00002000 00000000  0 AX     0   0 4096
	[ 7] load2                PROGBITS     00000000006b1000 00002000 0000a000  0 WA     0   0 4096

Former bfd version with the former `p_filesz == 0' kernel core file:
	CVS HEAD gdb `info files':
		0x0000000000400000 - 0x0000000000400000 is load1
		0x00000000006b1000 - 0x00000000006bb000 is load2
	objcopy:
	Section Headers:
	[ 5] load1                PROGBITS     0000000000400000 00001000 00000000  0 AX     0   0 4096
	[ 6] load2                PROGBITS     00000000006b1000 00001000 0000a000  0 WA     0   0 4096
-------------- next part --------------
2007-07-29  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* bfd/elf.c (_bfd_elf_new_section_hook): New comment for ET_CORE files
	with p_filesz shorter than p_memsz.  Behave for such split sections in
	a backward compatible way for both its parts.

--- bfd/elf.c	26 Jul 2007 18:15:46 -0000	1.401
+++ bfd/elf.c	29 Jul 2007 13:46:21 -0000
@@ -2225,6 +2225,9 @@ _bfd_elf_new_section_hook (bfd *abfd, as
    by the difference between the two sizes.  In effect, the segment is split
    into it's initialized and uninitialized parts.
 
+   This notion does not apply in ET_CORE files, where a shorter p_filesz means
+   that the data is not available in the dump.
+
  */
 
 bfd_boolean
@@ -2286,10 +2289,20 @@ _bfd_elf_make_section_from_phdr (bfd *ab
 	return FALSE;
       newsect->vma = hdr->p_vaddr + hdr->p_filesz;
       newsect->lma = hdr->p_paddr + hdr->p_filesz;
-      newsect->size = hdr->p_memsz - hdr->p_filesz;
+      if (abfd->format != bfd_core)
+	newsect->size = hdr->p_memsz - hdr->p_filesz;
+      else
+        {
+	  newsect->size = 0;
+	  newsect->filepos = hdr->p_offset;
+	  newsect->flags |= SEC_HAS_CONTENTS;
+	  newsect->alignment_power = bfd_log2 (hdr->p_align);
+	}
       if (hdr->p_type == PT_LOAD)
 	{
 	  newsect->flags |= SEC_ALLOC;
+	  if (abfd->format == bfd_core)
+	    newsect->flags |= SEC_LOAD;
 	  if (hdr->p_flags & PF_X)
 	    newsect->flags |= SEC_CODE;
 	}


More information about the Binutils mailing list