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

Bug#484784: marked as done (gcc-4.3: -O2 -O3 - wrong arguments are passing to inlined body of function)

Your message dated Tue, 24 Jun 2008 08:16:33 +0200
with message-id <20080624061633.GA15210@wavehammer.waldi.eu.org>
and subject line Re: Bug#484784: gcc-4.3: -O2 -O3 - wrong arguments are passing to inlined body of function
has caused the Debian Bug report #484784,
regarding gcc-4.3: -O2 -O3 - wrong arguments are passing to inlined body of function
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact owner@bugs.debian.org

484784: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=484784
Debian Bug Tracking System
Contact owner@bugs.debian.org with problems
--- Begin Message ---
Subject: gcc-4.3: -O2 -O3 - wrong arguments are passing to inlined body of function
Package: gcc-4.3
Version: 4.3.0-5
Severity: important

Consider this simple program:

#define N 100
char array[N];

void inline_asm(int iters) {
	__asm__ volatile (
		"pushal				\n"
		"	xorl %%ebx, %%ebx	\n"
		"0:				\n"
		"	movzbl (%%eax), %%edx	\n"
		"	addl %%edx, %%ebx	\n"
		"	incl %%eax		\n"
		"	decl %%ecx		\n"
		"	jnz  0b			\n"
		"popal				\n"
		: /* no output */
		: "a" (array),
		  "c" (iters)
		: "ebx", "edx"

int main() {
	int n = 100;

	while (n--)

Function inline_asm just add all values from array; all modified/input
registers are listed in __asm__ statement.

When program is compiled without any optimization flag, it works ok.
However if compiled with -O3 or -O3 --- segfaults.  I quickly analyzed
assembly output, and it is clear, that gcc fully inlined procedure,
however in a while loop only address is restored (%eax), but inner loop
counter (%ecx) isn't.  Thus in a second iteration %ecx has value 0, and
loop would execute 0xffffffff times, but segfault appear faster.

When sample program is compiled with -O3 -DPRESERVE_ALL_REGS all is
ok, because pair pushal/popal saves and restores all registers.

	# .. snip ...
	movl	$array, %esi
	pushl	%ebx
	pushl	%ecx
	movl	$100, %ecx	<-- ERROR: ecx is loaded only once
	.p2align 4,,7
	.p2align 3
	movl	%esi, %eax	<-- OK: eax is reloaded in every while-iteration
# 6 "bug.c" 1
	xorl %ebx, %ebx	
	movzbl (%eax), %edx	
	addl %edx, %ebx	
	incl %eax		
	decl %ecx		
	jnz  0b			

# 0 "" 2
	addl	$1, %edi
	cmpl	$100, %edi
	jne	.L4
	# ... snip ...

-- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'stable')
Architecture: i386 (i686)

Kernel: Linux 2.6.25-2-686 (SMP w/2 CPU cores)
Locale: LANG=pl_PL, LC_CTYPE=pl_PL (charmap=ISO-8859-2)
Shell: /bin/sh linked to /bin/bash

Versions of packages gcc-4.3 depends on:
ii  binutils            2.18.1~cvs20080103-6 The GNU assembler, linker and bina
ii  cpp-4.3             4.3.0-5              The GNU C preprocessor
ii  gcc-4.3-base        4.3.0-5              The GNU Compiler Collection (base 
ii  libc6               2.7-12               GNU C Library: Shared libraries
ii  libgcc1             1:4.3.0-5            GCC support library
ii  libgomp1            4.3.0-5              GCC OpenMP (GOMP) support library

Versions of packages gcc-4.3 recommends:
ii  libc6-dev                     2.7-12     GNU C Library: Development Librari

--- End Message ---
--- Begin Message ---
On Sat, Jun 07, 2008 at 10:16:36AM +0200, Bastian Blank wrote:
> No bug. You cheated so the compiler is free to do whatever it wants.



Killing is stupid; useless!
		-- McCoy, "A Private Little War", stardate 4211.8

--- End Message ---

Reply to: