public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* gcc miscompiles its sources (boehm-gc)
@ 2001-10-18  1:31 Martin Kahlert
  2001-10-18  2:22 ` Martin Kahlert
  2001-10-18 16:31 ` Tom Tromey
  0 siblings, 2 replies; 5+ messages in thread
From: Martin Kahlert @ 2001-10-18  1:31 UTC (permalink / raw)
  To: gcc; +Cc: java

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: gcc miscompiles its sources (boehm-gc)
  2001-10-18  1:31 gcc miscompiles its sources (boehm-gc) Martin Kahlert
@ 2001-10-18  2:22 ` Martin Kahlert
  2001-10-18 16:31 ` Tom Tromey
  1 sibling, 0 replies; 5+ messages in thread
From: Martin Kahlert @ 2001-10-18  2:22 UTC (permalink / raw)
  To: gcc

Sorry to reply to my own message, but i finally found a small testcase
(i filed a gnats report, but i do not know whether it came through).
Here it is:

$ cat t.c
#include <stdio.h>

struct exclusion
{
 int a1;
 int array[5];
} Table;

int *f(int start)
{
 return Table.array + start;
}

int main(int argc, char *argv[])
{
 int *next;

 if ( argc == 2 )
     next = f(atoi(argv[1]));
 else
     next = f(0);

 printf("next = %p, Table.array = %p, diff = %d\n",
         next, Table.array, next-Table.array);

 return 0;
}

$ gcc -O -o t t.c
$ ./t
next = 0x8049710, Table.array = 0x8049710, diff = 2

seems to be wrong a bit.

Bye,
Martin.

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: gcc miscompiles its sources (boehm-gc)
  2001-10-18  1:31 gcc miscompiles its sources (boehm-gc) Martin Kahlert
  2001-10-18  2:22 ` Martin Kahlert
@ 2001-10-18 16:31 ` Tom Tromey
  2001-10-18 16:38   ` Alexandre Petit-Bianco
  1 sibling, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2001-10-18 16:31 UTC (permalink / raw)
  To: martin.kahlert; +Cc: gcc, java

>>>>> "Martin" == Martin Kahlert <martin.kahlert@infineon.com> writes:

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

Could you resubmit this as a gcc PR?

Tom

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: gcc miscompiles its sources (boehm-gc)
  2001-10-18 16:31 ` Tom Tromey
@ 2001-10-18 16:38   ` Alexandre Petit-Bianco
  2001-10-19  3:08     ` Jakub Jelinek
  0 siblings, 1 reply; 5+ messages in thread
From: Alexandre Petit-Bianco @ 2001-10-18 16:38 UTC (permalink / raw)
  To: tromey; +Cc: martin.kahlert, gcc, java

Tom Tromey writes:

> Could you resubmit this as a gcc PR?

It's already c/4607, I believe. 

./A

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: gcc miscompiles its sources (boehm-gc)
  2001-10-18 16:38   ` Alexandre Petit-Bianco
@ 2001-10-19  3:08     ` Jakub Jelinek
  0 siblings, 0 replies; 5+ messages in thread
From: Jakub Jelinek @ 2001-10-19  3:08 UTC (permalink / raw)
  To: Alexandre Petit-Bianco; +Cc: tromey, martin.kahlert, gcc

On Thu, Oct 18, 2001 at 04:38:00PM -0700, Alexandre Petit-Bianco wrote:
> 
> Tom Tromey writes:
> 
> > Could you resubmit this as a gcc PR?
> 
> It's already c/4607, I believe. 

I'm debugging this simplify-rtx.c bug ATM...

	Jakub

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2001-10-19  3:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-18  1:31 gcc miscompiles its sources (boehm-gc) Martin Kahlert
2001-10-18  2:22 ` Martin Kahlert
2001-10-18 16:31 ` Tom Tromey
2001-10-18 16:38   ` Alexandre Petit-Bianco
2001-10-19  3:08     ` Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).