Re: Authoritative answer wanted: "-g -O1" vs. "-O1"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 06/18/2013 03:25 AM, Chung-Ju Wu wrote:
2013/6/18 Ian Lance Taylor<iant@xxxxxxxxxx>:
On Mon, Jun 17, 2013 at 10:21 PM, Gene Smith<gds@xxxxxxxxxxxxx>  wrote:
Is this difference expected? Should -g cause changes in the actual code
generated and not just add debug symbols to the elf? Possibly it is related
to the optimization level? I have not checked to see if the results differ
with higher or lower levels than -O1.

I have seen several opinions regarding this but no authoritative answer. The
gcc manual also does not really answer this.

If the only change in the command line options is whether you use -g,
you should get exactly the same code.  Any difference in code
generation is a bug.  Please try to file a bug report according to the
guidelines at http://gcc.gnu.org/bugs/ .  Thanks.

Ian

Hi, Gene,

I also suggest to check assembly code sequence by having '-S'
compilation option instead of using objdump to the binary.
So that the influence of assembler/linker can be ruled out.


Best regards,
jasonwucj


Yes, just removing the -g does affect the assembly as seen using -S gcc flag. However, it appears to be the same difference I see with objdump on the full elf. Here is a small example of the difference when calling the same c++ function looking at the -S assembly file output. The directives differ as expected but there are definitely some added or different assembly lines between the two. These type of small differences are throughout all project assembly output files.

w/o -g:

_ZN20MyFunc29guppieSortBoxNumbersEv:
	@ args = 0, pretend = 0, frame = 168
	@ frame_needed = 0, uses_anonymous_args = 0
	push	{r4, r5, r6, r7, r8, r9, sl, fp, lr}
	sub	sp, sp, #196
	str	r0, [sp, #24]
	ldrh	r2, [r0, #6]
	ldr	r3, .L85
	umull	r1, r3, r3, r2
	lsr	r3, r3, #2
	str	r3, [sp, #28]
	cmp	r3, #9
	bhi	.L76
	mov	r3, #0
	mov	r2, r3
:
:

w/ -g:

_ZN20MyFunc29guppieSortBoxNumbersEv:
.LFB42:
	.loc 1 1062 0
	.cfi_startproc
	@ args = 0, pretend = 0, frame = 176
	@ frame_needed = 0, uses_anonymous_args = 0
.LVL63:
	push	{r4, r5, r6, r7, r8, r9, sl, fp, lr}
.LCFI8:
	.cfi_def_cfa_offset 36
	sub	sp, sp, #204
.LCFI9:
	.cfi_def_cfa_offset 240
	mov	r9, r0
	.cfi_offset 14, -4
	.cfi_offset 11, -8
	.cfi_offset 10, -12
	.cfi_offset 9, -16
	.cfi_offset 8, -20
	.cfi_offset 7, -24
	.cfi_offset 6, -28
	.cfi_offset 5, -32
	.cfi_offset 4, -36
.LBB33:
	.loc 1 1063 0
	ldrh	r2, [r0, #6]
	ldr	r3, .L82
	umull	r1, r3, r3, r2
	lsr	r3, r3, #2
	str	r3, [sp, #28]
.LVL64:
	.loc 1 1065 0
	cmp	r3, #9
	bhi	.L76
	mov	r3, #0
.LBB34:
	.loc 1 1075 0
	mov	r2, r3
:
:







[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux