From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 795 invoked by alias); 13 May 2006 01:07:39 -0000 Received: (qmail 780 invoked by uid 22791); 13 May 2006 01:07:38 -0000 X-Spam-Check-By: sourceware.org Received: from smtp102.sbc.mail.mud.yahoo.com (HELO smtp102.sbc.mail.mud.yahoo.com) (68.142.198.201) by sourceware.org (qpsmtpd/0.31) with SMTP; Sat, 13 May 2006 01:07:31 +0000 Received: (qmail 14410 invoked from network); 13 May 2006 00:52:48 -0000 Received: from unknown (HELO lucon.org) (hjjean@sbcglobal.net@71.146.87.95 with login) by smtp102.sbc.mail.mud.yahoo.com with SMTP; 13 May 2006 00:52:47 -0000 Received: by lucon.org (Postfix, from userid 1000) id AC224641A3; Fri, 12 May 2006 17:52:46 -0700 (PDT) Date: Mon, 15 May 2006 02:03:00 -0000 From: "H. J. Lu" To: binutils@sources.redhat.com Cc: richard@codesourcery.com Subject: Re: PATCH: PR ld/2655/2657: Incorrrect padding for .eh_frame section Message-ID: <20060513005246.GA1310@lucon.org> References: <20060512170511.GA30942@lucon.org> <20060512205413.GA32403@lucon.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="YiEDa0DAkWCtVeE4" Content-Disposition: inline In-Reply-To: <20060512205413.GA32403@lucon.org> User-Agent: Mutt/1.4.2.1i Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2006-05/txt/msg00246.txt.bz2 --YiEDa0DAkWCtVeE4 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 961 On Fri, May 12, 2006 at 01:54:13PM -0700, H. J. Lu wrote: > On Fri, May 12, 2006 at 10:05:12AM -0700, H. J. Lu wrote: > > Hi Richard, > > > > Your patch: > > > > http://sourceware.org/ml/binutils/2004-11/msg00226.html > > > > assumes that CIE/FDE are aligned at the pointer size. But it isn't > > necessarily true. See > > > > http://sources.redhat.com/bugzilla/show_bug.cgi?id=2657 > > > > This patch fixes 2 PRs 2655/2657. PR 2655 is a gcc bug > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27576 > > PR 2657 is we don't properly shrink CIE/FDE. > It turns out that _bfd_elf_discard_section_eh_frame will always pad CIE/FDE record to the pointer size boundary since it calls size_of_output_cie_fde to set the CIE/FDE record size. Even if the next .eh_frame section is marked for 4 byte alignment, it always will be aligned at the pointer size. Fixing PR 2657 will also fix PR 2655. I am enclosing an upated patch and 2 testcases for x86-64. H.J. --YiEDa0DAkWCtVeE4 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="bfd-eh-3.patch" Content-length: 860 2006-05-12 H.J. Lu PR ld/2655 PR ld/2657 * elf-eh-frame.c (_bfd_elf_write_section_eh_frame): Properly update CIE/FDE length. --- bfd/elf-eh-frame.c.eh 2006-05-02 06:49:58.000000000 -0700 +++ bfd/elf-eh-frame.c 2006-05-12 17:19:33.000000000 -0700 @@ -1075,12 +1075,12 @@ _bfd_elf_write_section_eh_frame (bfd *ab end = buf + ent->size; new_size = size_of_output_cie_fde (ent, ptr_size); - /* Install the new size, filling the extra bytes with DW_CFA_nops. */ + /* Update the size. It may be shrinked. */ + bfd_put_32 (abfd, new_size - 4, buf); + + /* Filling the extra bytes with DW_CFA_nops. */ if (new_size != ent->size) - { - memset (end, 0, new_size - ent->size); - bfd_put_32 (abfd, new_size - 4, buf); - } + memset (end, 0, new_size - ent->size); if (ent->cie) { --YiEDa0DAkWCtVeE4 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="ld-test-eh-1.patch" Content-length: 3144 2006-05-12 H.J. Lu PR ld/2655 PR ld/2657 * ld-elf/eh1.d: New file. * ld-elf/eh1.s: Likewise. * ld-elf/eh1a.s: Likewise. * ld-elf/eh2.d: Likewise. * ld-elf/eh2a.s: Likewise. --- ld/testsuite/ld-elf/eh1.d.eh 2006-05-12 17:43:02.000000000 -0700 +++ ld/testsuite/ld-elf/eh1.d 2006-05-12 17:15:23.000000000 -0700 @@ -0,0 +1,33 @@ +#source: eh1.s +#source: eh1a.s +#ld: +#readelf: -wf +#target: x86_64-*-* + +The section .eh_frame contains: + +00000000 00000014 00000000 CIE + Version: 1 + Augmentation: "" + Code alignment factor: 1 + Data alignment factor: -8 + Return address column: 16 + + DW_CFA_def_cfa: r7 ofs 8 + DW_CFA_offset: r16 at cfa-8 + DW_CFA_nop + DW_CFA_nop + DW_CFA_nop + DW_CFA_nop + DW_CFA_nop + DW_CFA_nop + +00000018 0000001c 0000001c FDE cie=00000000 pc=004000b0..004000b0 + DW_CFA_advance_loc: 0 to 004000b0 + DW_CFA_def_cfa_offset: 16 + DW_CFA_offset: r6 at cfa-16 + DW_CFA_advance_loc: 0 to 004000b0 + DW_CFA_def_cfa_reg: r6 + +00000038 ZERO terminator + --- ld/testsuite/ld-elf/eh1.s.eh 2006-05-12 17:43:02.000000000 -0700 +++ ld/testsuite/ld-elf/eh1.s 2006-05-12 17:15:46.000000000 -0700 @@ -0,0 +1,47 @@ + .text +.globl _start + .type _start, %function +_start: +.LFB2: +.LCFI0: +.LCFI1: +.LFE2: + .size _start, .-_start + .section .eh_frame,"a",%progbits +.Lframe1: + .long .LECIE1-.LSCIE1 +.LSCIE1: + .long 0x0 + .byte 0x1 + .string "" + .uleb128 0x1 + .sleb128 -8 + .byte 0x10 + .byte 0xc + .uleb128 0x7 + .uleb128 0x8 + .byte 0x90 + .uleb128 0x1 + .align 8 +.LECIE1: +.LSFDE1: + .long .LEFDE1-.LASFDE1 +.LASFDE1: + .long .LASFDE1-.Lframe1 + .quad .LFB2 + .quad .LFE2-.LFB2 + .byte 0x4 + .long .LCFI0-.LFB2 + .byte 0xe + .uleb128 0x10 + .byte 0x86 + .uleb128 0x2 + .byte 0x4 + .long .LCFI1-.LCFI0 + .byte 0xd + .uleb128 0x6 + .byte 0x0 + .byte 0x0 + .byte 0x0 + .byte 0x0 +.LEFDE1: --- ld/testsuite/ld-elf/eh1a.s.eh 2006-05-12 17:43:02.000000000 -0700 +++ ld/testsuite/ld-elf/eh1a.s 2006-05-12 17:17:36.000000000 -0700 @@ -0,0 +1,3 @@ + .section .eh_frame,"a",%progbits + .align 8 + .zero 4 --- ld/testsuite/ld-elf/eh2.d.eh 2006-05-12 17:43:02.000000000 -0700 +++ ld/testsuite/ld-elf/eh2.d 2006-05-12 17:18:35.000000000 -0700 @@ -0,0 +1,33 @@ +#source: eh1.s +#source: eh2a.s +#ld: +#readelf: -wf +#target: x86_64-*-* + +The section .eh_frame contains: + +00000000 00000014 00000000 CIE + Version: 1 + Augmentation: "" + Code alignment factor: 1 + Data alignment factor: -8 + Return address column: 16 + + DW_CFA_def_cfa: r7 ofs 8 + DW_CFA_offset: r16 at cfa-8 + DW_CFA_nop + DW_CFA_nop + DW_CFA_nop + DW_CFA_nop + DW_CFA_nop + DW_CFA_nop + +00000018 0000001c 0000001c FDE cie=00000000 pc=004000b0..004000b0 + DW_CFA_advance_loc: 0 to 004000b0 + DW_CFA_def_cfa_offset: 16 + DW_CFA_offset: r6 at cfa-16 + DW_CFA_advance_loc: 0 to 004000b0 + DW_CFA_def_cfa_reg: r6 + +00000038 ZERO terminator + --- ld/testsuite/ld-elf/eh2a.s.eh 2006-05-12 17:43:02.000000000 -0700 +++ ld/testsuite/ld-elf/eh2a.s 2006-05-12 17:17:42.000000000 -0700 @@ -0,0 +1,3 @@ + .section .eh_frame,"a",%progbits + .align 4 + .zero 4 --YiEDa0DAkWCtVeE4--