This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

gcc miscompiles its sources (boehm-gc)


Hi!
gcc-3.1 (yesterday's CVS) has an optimization bug, which prevents static linking on Linux for 
executables produced by gcj (see http://gcc.gnu.org/ml/java/2001-10/msg00077.html)

In boehm-gc/mark_rts.c I changed the first if statement inside the function
GC_exclude_static_roots to look like this:

void GC_exclude_static_roots(start, finish)
GC_PTR start;
GC_PTR finish;
{
    struct exclusion * next;
    size_t next_index, i;

    if (0 == GC_excl_table_entries) {
	next = 0;
    } else {
	next = GC_next_exclusion(start);
        printf("GC_excl_table = %p next = %p, diff = %i\n",
                                GC_excl_table, next, next - GC_excl_table);
    }
    ...

The assembly code produced by  
gcc -O -S -I include mark_rts.c reads like that:

.globl GC_exclude_static_roots
	.type	GC_exclude_static_roots,@function
GC_exclude_static_roots:
	pushl	%ebp
	movl	%esp, %ebp
	pushl	%edi
	pushl	%esi
	pushl	%ebx
	subl	$28, %esp
	movl	12(%ebp), %edi
	movl	$0, %ebx
	cmpl	$0, GC_excl_table_entries
	je	.L227
	movl	8(%ebp), %eax
	movl	%eax, (%esp)              # %eax = start
	call	GC_next_exclusion         # next = GC_next_exclusion(%eax);
	movl	%eax, %ebx                # %ebx = next
	movl	stdout, %eax        
	movl	%eax, (%esp)              #  (%esp)  = stdout
	movl	$.LC6, 4(%esp)            #  4(%esp) = "GC_excl_table = %p next = %p, diff = %i\n"
	movl	$GC_arrays+42608, 8(%esp) #  8(%esp) = GC_excl_table (= $GC_arrays+42608)
	movl	%ebx, 12(%esp)            # 12(%esp) = next ( = %ebx )
	movl	%ebx, %eax                # %eax     = next ( = %ebx )
	subl	$GC_arrays-42608, %eax    # %eax    -= $GC_arrays-42608 which should instead be GC_excl_table = $GC_arrays+42608
	sarl	$3, %eax                  # %eax    /= 8 ( = sizeof(struct exclusion))
	movl	%eax, 16(%esp)            # 16(%esp) = diff ( = %eax )
	call	fprintf
        ....

So the error is the generation of
subl    $GC_arrays-42608, %eax
instead of
subl    $GC_arrays+42608, %eax

Now i am at the end with my knowledge.
Someone with deeper understanding has to look into that.
It would be nice, if this bug would be removed soon, so i could check, if
static linking works at all using gcj.

$ gcc -v
Reading specs from /sw/gcc-3.1/lib/gcc-lib/i686-pc-linux-gnu/3.1/specs
Configured with: ../gcc-3.1/configure --prefix=/sw/gcc-3.1 --enable-languages=c++,f77,java --enable-threads=posix
Thread model: posix
gcc version 3.1 20011017 (experimental)

Thanks a lot,
Martin.

-- 
The early bird catches the worm. If you want something else for       
breakfast, get up later.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]