[PATCH] Scale DW_CFA_advance_loc[124] output values

Jakub Jelinek jakub@redhat.com
Wed Nov 19 14:47:00 GMT 2008


On Tue, Nov 18, 2008 at 11:25:15AM -0500, John David Anglin wrote:
> > Yeah, seems ehopt.c is broken in many places too, at least in
> > check_eh_frame, eh_frame_estimate_size_before_relax and
> > eh_frame_convert_frag.  Fortunately gcc was always using code
> > alignment factor 1, so it didn't matter.
> 
> I'm thinking the optimization in check_eh_frame is only valid when
> the code alignment factor is 1.  That's the only time the advance
> can be represented as a difference of symbols.

The optimization is valid for any code alignment factor, just it behaves
incorrectly ATM for factor > 1.
Consider following 2 testcases, which should IMHO result in identical
readelf -wf dump if ignoring the Code alignment factor difference in the
CIE dump.  If the 2 nops are taken out from each of the sources, then
the dump is almost the same, just the second testcase has a missed
optimization - uses DW_CFA_advance_loc1 instead of DW_CFA_advance_loc,
where the latter is more compact.  With the nops ehopt.c actually screws
up the .eh_frame, as instead of DW_CFA_advance_loc 4 uses DW_CFA_advance_loc
1, so all following spots are 12 bytes apart from where they should be.

	Jakub
-------------- next part --------------
	.file	"t.c"
	.section	".text"
	.align 2
	.globl _Z3fooi
	.type	_Z3fooi, @function
_Z3fooi:
.LFB0:
	 # basic block 2
	mflr 0
.LCFI0:
	stwu 1,-64(1)
.LCFI1:
	stw 20,16(1)
.LCFI2:
	mr 20,3
	stw 21,20(1)
	nop
	nop
.LCFI3:
	li 21,10
	stw 22,24(1)
.LCFI4:
	li 22,9
	stw 23,28(1)
.LCFI5:
	li 23,8
	stw 24,32(1)
.LCFI6:
	li 24,7
	stw 25,36(1)
.LCFI7:
	li 25,6
	stw 26,40(1)
.LCFI8:
	li 26,5
	stw 27,44(1)
.LCFI9:
	li 27,4
	stw 28,48(1)
.LCFI10:
	li 28,3
	stw 29,52(1)
.LCFI11:
	li 29,2
	stw 0,68(1)
.LCFI12:
	bl _Z3barv
	add 29,29,28
	lwz 0,68(1)
	add 29,29,20
	lwz 28,48(1)
	add 29,29,27
	mtlr 0
	add 29,29,26
	lwz 20,16(1)
	add 29,29,25
	lwz 26,40(1)
	add 29,29,24
	lwz 25,36(1)
	add 29,29,23
	lwz 24,32(1)
	add 29,29,22
	lwz 23,28(1)
	add 3,29,21
	lwz 22,24(1)
	lwz 21,20(1)
	lwz 27,44(1)
	lwz 29,52(1)
	addi 1,1,64
	blr
.LFE0:
	.size	_Z3fooi, .-_Z3fooi
#APP
	.section	.eh_frame,"a",@progbits
.Lframe1:
	.4byte	.LECIE1-.LSCIE1	 # Length of Common Information Entry
.LSCIE1:
	.4byte	0x0	 # CIE Identifier Tag
	.byte	0x1	 # CIE Version
	.globl __gxx_personality_v0
	.ascii "zP\0"	 # CIE Augmentation
	.uleb128 0x1	 # CIE Code Alignment Factor
	.sleb128 -4	 # CIE Data Alignment Factor
	.byte	0x41	 # CIE RA Column
	.uleb128 0x5	 # Augmentation size
	.byte	0x0	 # Personality (absolute)
	.4byte	__gxx_personality_v0
	.byte	0xc	 # DW_CFA_def_cfa
	.uleb128 0x1
	.uleb128 0x0
	.align 2
.LECIE1:
.LSFDE1:
	.4byte	.LEFDE1-.LASFDE1	 # FDE Length
.LASFDE1:
	.4byte	.LASFDE1-.Lframe1	 # FDE CIE offset
	.4byte	.LFB0	 # FDE initial location
	.4byte	.LFE0-.LFB0	 # FDE address range
	.uleb128 0x0	 # Augmentation size
	.byte	0x4	 # DW_CFA_advance_loc4
	.4byte	.LCFI1-.LFB0
	.byte	0xe	 # DW_CFA_def_cfa_offset
	.uleb128 0x40
	.byte	0x4	 # DW_CFA_advance_loc4
	.4byte	.LCFI2-.LCFI1
	.byte	0x94	 # DW_CFA_offset, column 0x14
	.uleb128 0xc
	.byte	0x9	 # DW_CFA_register
	.uleb128 0x41
	.uleb128 0x0
	.byte	0x4	 # DW_CFA_advance_loc4
	.4byte	.LCFI3-.LCFI2
	.byte	0x95	 # DW_CFA_offset, column 0x15
	.uleb128 0xb
	.byte	0x4	 # DW_CFA_advance_loc4
	.4byte	.LCFI4-.LCFI3
	.byte	0x96	 # DW_CFA_offset, column 0x16
	.uleb128 0xa
	.byte	0x4	 # DW_CFA_advance_loc4
	.4byte	.LCFI5-.LCFI4
	.byte	0x97	 # DW_CFA_offset, column 0x17
	.uleb128 0x9
	.byte	0x4	 # DW_CFA_advance_loc4
	.4byte	.LCFI6-.LCFI5
	.byte	0x98	 # DW_CFA_offset, column 0x18
	.uleb128 0x8
	.byte	0x4	 # DW_CFA_advance_loc4
	.4byte	.LCFI7-.LCFI6
	.byte	0x99	 # DW_CFA_offset, column 0x19
	.uleb128 0x7
	.byte	0x4	 # DW_CFA_advance_loc4
	.4byte	.LCFI8-.LCFI7
	.byte	0x9a	 # DW_CFA_offset, column 0x1a
	.uleb128 0x6
	.byte	0x4	 # DW_CFA_advance_loc4
	.4byte	.LCFI9-.LCFI8
	.byte	0x9b	 # DW_CFA_offset, column 0x1b
	.uleb128 0x5
	.byte	0x4	 # DW_CFA_advance_loc4
	.4byte	.LCFI10-.LCFI9
	.byte	0x9c	 # DW_CFA_offset, column 0x1c
	.uleb128 0x4
	.byte	0x4	 # DW_CFA_advance_loc4
	.4byte	.LCFI11-.LCFI10
	.byte	0x9d	 # DW_CFA_offset, column 0x1d
	.uleb128 0x3
	.byte	0x4	 # DW_CFA_advance_loc4
	.4byte	.LCFI12-.LCFI11
	.byte	0x11	 # DW_CFA_offset_extended_sf
	.uleb128 0x41
	.sleb128 -1
	.align 2
.LEFDE1:
#NO_APP
	.ident	"GCC: (GNU) 4.4.0 20081119 (experimental)"
	.section	.note.GNU-stack,"",@progbits
-------------- next part --------------
	.file	"t.c"
	.section	".text"
	.align 2
	.globl _Z3fooi
	.type	_Z3fooi, @function
_Z3fooi:
.LFB0:
	 # basic block 2
	mflr 0
.LCFI0:
	stwu 1,-64(1)
.LCFI1:
	stw 20,16(1)
.LCFI2:
	mr 20,3
	stw 21,20(1)
	nop
	nop
.LCFI3:
	li 21,10
	stw 22,24(1)
.LCFI4:
	li 22,9
	stw 23,28(1)
.LCFI5:
	li 23,8
	stw 24,32(1)
.LCFI6:
	li 24,7
	stw 25,36(1)
.LCFI7:
	li 25,6
	stw 26,40(1)
.LCFI8:
	li 26,5
	stw 27,44(1)
.LCFI9:
	li 27,4
	stw 28,48(1)
.LCFI10:
	li 28,3
	stw 29,52(1)
.LCFI11:
	li 29,2
	stw 0,68(1)
.LCFI12:
	bl _Z3barv
	add 29,29,28
	lwz 0,68(1)
	add 29,29,20
	lwz 28,48(1)
	add 29,29,27
	mtlr 0
	add 29,29,26
	lwz 20,16(1)
	add 29,29,25
	lwz 26,40(1)
	add 29,29,24
	lwz 25,36(1)
	add 29,29,23
	lwz 24,32(1)
	add 29,29,22
	lwz 23,28(1)
	add 3,29,21
	lwz 22,24(1)
	lwz 21,20(1)
	lwz 27,44(1)
	lwz 29,52(1)
	addi 1,1,64
	blr
.LFE0:
	.size	_Z3fooi, .-_Z3fooi
#APP
	.section	.eh_frame,"a",@progbits
.Lframe1:
	.4byte	.LECIE1-.LSCIE1	 # Length of Common Information Entry
.LSCIE1:
	.4byte	0x0	 # CIE Identifier Tag
	.byte	0x1	 # CIE Version
	.globl __gxx_personality_v0
	.ascii "zP\0"	 # CIE Augmentation
	.uleb128 0x4	 # CIE Code Alignment Factor
	.sleb128 -4	 # CIE Data Alignment Factor
	.byte	0x41	 # CIE RA Column
	.uleb128 0x5	 # Augmentation size
	.byte	0x0	 # Personality (absolute)
	.4byte	__gxx_personality_v0
	.byte	0xc	 # DW_CFA_def_cfa
	.uleb128 0x1
	.uleb128 0x0
	.align 2
.LECIE1:
.LSFDE1:
	.4byte	.LEFDE1-.LASFDE1	 # FDE Length
.LASFDE1:
	.4byte	.LASFDE1-.Lframe1	 # FDE CIE offset
	.4byte	.LFB0	 # FDE initial location
	.4byte	.LFE0-.LFB0	 # FDE address range
	.uleb128 0x0	 # Augmentation size
	.byte	0x4	 # DW_CFA_advance_loc4
	.4byte	(.LCFI1-.LFB0)/4
	.byte	0xe	 # DW_CFA_def_cfa_offset
	.uleb128 0x40
	.byte	0x4	 # DW_CFA_advance_loc4
	.4byte	(.LCFI2-.LCFI1)/4
	.byte	0x94	 # DW_CFA_offset, column 0x14
	.uleb128 0xc
	.byte	0x9	 # DW_CFA_register
	.uleb128 0x41
	.uleb128 0x0
	.byte	0x4	 # DW_CFA_advance_loc4
	.4byte	(.LCFI3-.LCFI2)/4
	.byte	0x95	 # DW_CFA_offset, column 0x15
	.uleb128 0xb
	.byte	0x4	 # DW_CFA_advance_loc4
	.4byte	(.LCFI4-.LCFI3)/4
	.byte	0x96	 # DW_CFA_offset, column 0x16
	.uleb128 0xa
	.byte	0x4	 # DW_CFA_advance_loc4
	.4byte	(.LCFI5-.LCFI4)/4
	.byte	0x97	 # DW_CFA_offset, column 0x17
	.uleb128 0x9
	.byte	0x4	 # DW_CFA_advance_loc4
	.4byte	(.LCFI6-.LCFI5)/4
	.byte	0x98	 # DW_CFA_offset, column 0x18
	.uleb128 0x8
	.byte	0x4	 # DW_CFA_advance_loc4
	.4byte	(.LCFI7-.LCFI6)/4
	.byte	0x99	 # DW_CFA_offset, column 0x19
	.uleb128 0x7
	.byte	0x4	 # DW_CFA_advance_loc4
	.4byte	(.LCFI8-.LCFI7)/4
	.byte	0x9a	 # DW_CFA_offset, column 0x1a
	.uleb128 0x6
	.byte	0x4	 # DW_CFA_advance_loc4
	.4byte	(.LCFI9-.LCFI8)/4
	.byte	0x9b	 # DW_CFA_offset, column 0x1b
	.uleb128 0x5
	.byte	0x4	 # DW_CFA_advance_loc4
	.4byte	(.LCFI10-.LCFI9)/4
	.byte	0x9c	 # DW_CFA_offset, column 0x1c
	.uleb128 0x4
	.byte	0x4	 # DW_CFA_advance_loc4
	.4byte	(.LCFI11-.LCFI10)/4
	.byte	0x9d	 # DW_CFA_offset, column 0x1d
	.uleb128 0x3
	.byte	0x4	 # DW_CFA_advance_loc4
	.4byte	(.LCFI12-.LCFI11)/4
	.byte	0x11	 # DW_CFA_offset_extended_sf
	.uleb128 0x41
	.sleb128 -1
	.align 2
.LEFDE1:
#NO_APP
	.ident	"GCC: (GNU) 4.4.0 20081119 (experimental)"
	.section	.note.GNU-stack,"",@progbits


More information about the Binutils mailing list