From cagney@tpgi.com.au  Sat Nov 22 05:44:23 1997
Received: from random.tpgi.com.au (random.tpgi.com.au [203.12.160.7])
          by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id FAA06102
          for <FreeBSD-gnats-submit@freebsd.org>; Sat, 22 Nov 1997 05:44:22 -0800 (PST)
          (envelope-from cagney@tpgi.com.au)
Received: (from smtpd@localhost)
	by random.tpgi.com.au (8.8.4/8.8.6) id AAA13100
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 23 Nov 1997 00:44:19 +1100 (EST)
Received: from oberon.tpgi.com.au(203.12.160.2), claiming to be "oberon.com.au"
 via SMTP by random.tpgi.com.au, id smtpdAAAa003Cd; Sun Nov 23 00:44:12 1997
Received: from b1.tpgi.com.au by oberon.com.au (SMI-8.6/SMI-SVR4)
	id AAA07042; Sun, 23 Nov 1997 00:44:06 +1100
Received: (from cagney@localhost) by b1.tpgi.com.au (8.8.7/8.7.3) id AAA25765; Sun, 23 Nov 1997 00:44:38 +1100 (EST)
Message-Id: <199711221344.AAA25765@b1.tpgi.com.au>
Date: Sun, 23 Nov 1997 00:44:38 +1100 (EST)
From: Andrew Cagney <cagney@tpgi.com.au>
Reply-To: cagney@tpgi.com.au
To: FreeBSD-gnats-submit@freebsd.org
Subject: <Synopsis of the problem (one line)>
X-Send-Pr-Version: 3.2

>Number:         5126
>Category:       gnu
>Synopsis:       C++ compiler bug (assembly output)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Nov 22 05:50:02 PST 1997
>Closed-Date:    Sat Feb 5 03:01:38 PST 2000
>Last-Modified:  Sat Feb  5 03:02:56 PST 2000
>Originator:     Andrew Cagney
>Release:        FreeBSD 2.2.5-RELEASE i386
>Organization:
>Environment:

	`Virgin 2.2.5' (I've reverted back to 2.1.7 :-)

>Description:

For the program below, when compiled with G++ (-gpic) , produces the
incorrect assembler:

        .type    _d__Fv,@function
_d__Fv:
        pushl %ebp
        movl %esp,%ebp
        pushl %ebx
        call L5
L5:
        popl %ebx
        addl $_GLOBAL_OFFSET_TABLE_+[.-L5],%ebx
        movl _DefaultHash__Fv@GOT(%ebx),%edx
        movl %edx,%eax
        jmp L3
        .align 2,0x90
        jmp L4
        .align 2,0x90
        jmp L3
        .align 2,0x90
L4:
L3:
        movl -4(%ebp),%ebx
        leave
        ret

Notice that it has generated a ``@GOT'' instead of ``@GOTOFF'' for the
reference to the static function DefaultHash (which has been both
declared and defined).

If the declaration is removed, the correct code is generated.  If GCC
is used, the correct code is generated.




>How-To-Repeat:

$ cat test.cc
static void DefaultHash(void);
static void DefaultHash(void) { }
void *
d (void)
{
  return DefaultHash;
}

$ gcc -c -fpic test.cc
/tmp/cc005218.s: Assembler messages:
/tmp/cc005218.s:45: Warning: GOT relocation burb: `_DefaultHash__Fv' should be global

$ cp test.cc test.c
$ gcc -c -fpic test.c 

$ tail +2 test.cc > t.cc
$ cat t.cc
static void DefaultHash(void) { }
void *
d (void)
{
  return DefaultHash;
}

$ gcc -c -fpic t.cc


>Fix:
	
Re-arrange code so that the static declaration isn't needed.

>Release-Note:
>Audit-Trail:

From: hoek@freebsd.org
To: freebsd-gnats-submit@freebsd.org, cagney@tpgi.com.au
Cc:  
Subject: Re: gnu/5126 : C++ compiler bug (assembly output)
Date: Fri, 30 Apr 1999 02:01:24 -0400 (EDT)

 >
 >Notice that it has generated a ``@GOT'' instead of ``@GOTOFF'' for the
 >reference to the static function DefaultHash (which has been both
 >declared and defined).
 
 This appears to be at least fixed in 4-current and egcs --- it generates
 neither.
 
State-Changed-From-To: open->closed 
State-Changed-By: asmodai 
State-Changed-When: Sat Feb 5 03:01:38 PST 2000 
State-Changed-Why:  
A few reasons: 
- I can verify hoek's test results on my own systems 
- the 2.2.x branch is no longer actively maintained/supported 
- we have moved up a few compiler suite versions 
>Unformatted:
