From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14712 invoked by alias); 20 Dec 2007 15:54:29 -0000 Received: (qmail 14703 invoked by uid 22791); 20 Dec 2007 15:54:28 -0000 X-Spam-Check-By: sourceware.org Received: from qmta09.emeryville.ca.mail.comcast.net (HELO QMTA09.emeryville.ca.mail.comcast.net) (76.96.30.96) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 20 Dec 2007 15:54:07 +0000 Received: from OMTA07.emeryville.ca.mail.comcast.net ([76.96.30.59]) by QMTA09.emeryville.ca.mail.comcast.net with comcast id T1401Y00F1GXsucA90MM00; Thu, 20 Dec 2007 15:54:12 +0000 Received: from lucon.org ([24.6.230.138]) by OMTA07.emeryville.ca.mail.comcast.net with comcast id T3uB1Y00A2zoa488T00000; Thu, 20 Dec 2007 15:54:12 +0000 X-Authority-Analysis: v=1.0 c=1 a=5EGyNX0pX0QA:10 a=8-YoNpcAP6S2WbD1hOUA:9 a=cHcTX-epLn7D9kudNIEA:7 a=Y5_XQeUBm4TFbVKqhULWjyGE3J4A:4 a=dGJ0OcVc7YAA:10 a=LY0hPdMaydYA:10 Received: by lucon.org (Postfix, from userid 500) id 5281DF8283; Thu, 20 Dec 2007 07:54:05 -0800 (PST) Date: Thu, 20 Dec 2007 15:54:00 -0000 From: "H.J. Lu" To: binutils@sources.redhat.com Subject: Re: PATCH: PR binutils/5488: strip doesn't handle PT_NOTE segment properly Message-ID: <20071220155403.GA31192@lucon.org> References: <20071220150933.GA11560@lucon.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20071220150933.GA11560@lucon.org> User-Agent: Mutt/1.5.17 (2007-11-01) Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2007-12/txt/msg00120.txt.bz2 On Thu, Dec 20, 2007 at 07:09:33AM -0800, H.J. Lu wrote: > rewrite_elf_program_header don't consider PT_NOTE segment at all. > This patch fixes it. > > Here is the patch with a testcase. H.J. ---- bfd/ 2007-12-20 H.J. Lu 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. ld/testsuite/ 2007-12-20 H.J. Lu PR binutils/5488 * ld-elf/note-2.d: New. * ld-elf/note-2.s: Likewise. * ld-elf/note-2.t: Likewise. --- binutils/bfd/elf.c.note 2007-12-20 05:57:09.000000000 -0800 +++ binutils/bfd/elf.c 2007-12-20 07:50:51.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 --- binutils/ld/testsuite/ld-elf/note-2.d.note 2007-12-20 07:42:48.000000000 -0800 +++ binutils/ld/testsuite/ld-elf/note-2.d 2007-12-20 07:49:47.000000000 -0800 @@ -0,0 +1,15 @@ +#ld: -Tnote-2.t +#objcopy_linked_file: -R .foo +#readelf: -l --wide + +#... +Program Headers: + Type.* + LOAD +0x[0-9a-f]+ .* + NOTE +0x[0-9a-f]+ .* + +#... + Segment Sections... + 00[ \t]+.text * + 01[ \t]+.note * +#pass --- binutils/ld/testsuite/ld-elf/note-2.s.note 2007-12-20 07:42:51.000000000 -0800 +++ binutils/ld/testsuite/ld-elf/note-2.s 2007-12-16 09:51:55.000000000 -0800 @@ -0,0 +1,8 @@ + .globl _entry + .text +_entry: + .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .section .foo,"awx",%progbits + .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .section .note,"",%note + .byte 0 --- binutils/ld/testsuite/ld-elf/note-2.t.note 2007-12-20 07:42:53.000000000 -0800 +++ binutils/ld/testsuite/ld-elf/note-2.t 2007-12-20 07:48:54.000000000 -0800 @@ -0,0 +1,13 @@ +ENTRY(_entry) +PHDRS +{ + data PT_LOAD; + note PT_NOTE; +} +SECTIONS +{ + .text : { *(.text) } :data + .foo : { *(.foo) } :data + .note : { *(.note) } :note + /DISCARD/ : { *(*) } +}