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: PR binutils/5488: strip doesn't handle PT_NOTE segment properly


rewrite_elf_program_header don't consider PT_NOTE segment at all.
This patch fixes it.


H.J.
----
2007-12-20  H.J. Lu  <hongjiu.lu@intel.com>

	PR binutils/5488
	* elf.c (IS_NOTE): New.
	(IS_COREFILE_NOTE): Use IS_NOTE.
	(IS_SECTION_IN_INPUT_SEGMENT): Use IS_NOTE instead of
	IS_COREFILE_NOTE.

--- bfd/elf.c.note	2007-12-20 05:57:09.000000000 -0800
+++ bfd/elf.c	2007-12-20 07:06:20.000000000 -0800
@@ -5193,15 +5193,22 @@ rewrite_elf_program_header (bfd *ibfd, b
    && (section->lma + SECTION_SIZE (section, segment)			\
        <= SEGMENT_END (segment, base)))
 
-  /* Special case: corefile "NOTE" section containing regs, prpsinfo etc.  */
-#define IS_COREFILE_NOTE(p, s)						\
+  /* Handle PT_NOTE segment.  */
+#define IS_NOTE(p, s)							\
   (p->p_type == PT_NOTE							\
-   && bfd_get_format (ibfd) == bfd_core					\
-   && s->vma == 0 && s->lma == 0					\
+   && elf_section_type (s) == SHT_NOTE					\
    && (bfd_vma) s->filepos >= p->p_offset				\
    && ((bfd_vma) s->filepos + s->size					\
        <= p->p_offset + p->p_filesz))
 
+  /* Special case: corefile "NOTE" section containing regs, prpsinfo
+     etc.  */
+#define IS_COREFILE_NOTE(p, s)						\
+  (IS_NOTE (p, s)							\
+   && bfd_get_format (ibfd) == bfd_core					\
+   && s->vma == 0							\
+   && s->lma == 0)
+
   /* The complicated case when p_vaddr is 0 is to handle the Solaris
      linker, which generates a PT_INTERP section with p_vaddr and
      p_memsz set to 0.  */
@@ -5220,7 +5227,8 @@ rewrite_elf_program_header (bfd *ibfd, b
      A section will be included if:
        1. It is within the address space of the segment -- we use the LMA
 	  if that is set for the segment and the VMA otherwise,
-       2. It is an allocated segment,
+       2. It is an allocated section or a NOTE section in a PT_NOTE
+	  segment.         
        3. There is an output section associated with it,
        4. The section has not already been allocated to a previous segment.
        5. PT_GNU_STACK segments do not include any sections.
@@ -5233,7 +5241,7 @@ rewrite_elf_program_header (bfd *ibfd, b
       ? IS_CONTAINED_BY_LMA (section, segment, segment->p_paddr)	\
       : IS_CONTAINED_BY_VMA (section, segment))				\
      && (section->flags & SEC_ALLOC) != 0)				\
-    || IS_COREFILE_NOTE (segment, section))				\
+    || IS_NOTE (segment, section))					\
    && segment->p_type != PT_GNU_STACK					\
    && (segment->p_type != PT_TLS					\
        || (section->flags & SEC_THREAD_LOCAL))				\
@@ -5767,6 +5775,7 @@ rewrite_elf_program_header (bfd *ibfd, b
 #undef SECTION_SIZE
 #undef IS_CONTAINED_BY_VMA
 #undef IS_CONTAINED_BY_LMA
+#undef IS_NOTE
 #undef IS_COREFILE_NOTE
 #undef IS_SOLARIS_PT_INTERP
 #undef IS_SECTION_IN_INPUT_SEGMENT


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