This is the mail archive of the binutils@sources.redhat.com 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]

Do not add sections to a PT_GNU_STACK segment.


Hi Guys,

  I am applying the small patch below to add an extra test to the
  INCLUDE_SECTION_IN_SEGMENT macro in bfd/elf.c.  This test prevents
  sections from being assigned to a PT_GNU_STACK segment, even if it
  would appear that it contains them.  This proved to be a problem
  when stripping an executable containing a stack segment - it would
  have sections assigned to it, and suddenly its start address would
  change to coincide with the first matching section...

Cheers
        Nick

2003-12-11  Nick Clifton  <nickc@redhat.com>

	* elf.c (INCLUDE_SECTION_IN_SEGMENT): Skip PT_GNU_STACK segments.

Index: elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.214
diff -c -3 -p -r1.214 elf.c
*** elf.c	1 Dec 2003 06:28:23 -0000	1.214
--- elf.c	11 Dec 2003 17:57:40 -0000
*************** copy_private_bfd_data (bfd *ibfd, bfd *o
*** 4625,4632 ****
         2. It is an allocated segment,
         3. There is an output section associated with it,
         4. The section has not already been allocated to a previous segment.
!        5. PT_TLS segment includes only SHF_TLS sections.
!        6. SHF_TLS sections are only in PT_TLS or PT_LOAD segments.  */
  #define INCLUDE_SECTION_IN_SEGMENT(section, segment, bed)		\
    ((((segment->p_paddr							\
        ? IS_CONTAINED_BY_LMA (section, segment, segment->p_paddr)	\
--- 4625,4633 ----
         2. It is an allocated 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.
!        6. PT_TLS segment includes only SHF_TLS sections.
!        7. SHF_TLS sections are only in PT_TLS or PT_LOAD segments.  */
  #define INCLUDE_SECTION_IN_SEGMENT(section, segment, bed)		\
    ((((segment->p_paddr							\
        ? IS_CONTAINED_BY_LMA (section, segment, segment->p_paddr)	\
*************** copy_private_bfd_data (bfd *ibfd, bfd *o
*** 4634,4639 ****
--- 4635,4641 ----
       && (section->flags & SEC_ALLOC) != 0)				\
      || IS_COREFILE_NOTE (segment, section))				\
     && section->output_section != NULL					\
+    && segment->p_type != PT_GNU_STACK					\
     && (segment->p_type != PT_TLS					\
         || (section->flags & SEC_THREAD_LOCAL))				\
     && (segment->p_type == PT_LOAD					\
                


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