From nobody@FreeBSD.org  Thu Sep 25 20:50:44 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 1E18E106568B
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 25 Sep 2008 20:50:44 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 0D8918FC15
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 25 Sep 2008 20:50:44 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id m8PKohQc095843
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 25 Sep 2008 20:50:43 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id m8PKohFr095842;
	Thu, 25 Sep 2008 20:50:43 GMT
	(envelope-from nobody)
Message-Id: <200809252050.m8PKohFr095842@www.freebsd.org>
Date: Thu, 25 Sep 2008 20:50:43 GMT
From: Jonathan Briggs <zlynx@acm.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: GCC will not build shared libraries with -fprofile-generate on amd64
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         127640
>Category:       amd64
>Synopsis:       [amd64] gcc(1) will not build shared libraries with -fprofile-generate on amd64
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    linimon
>State:          feedback
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Sep 25 21:00:03 UTC 2008
>Closed-Date:    
>Last-Modified:  Tue Nov 12 02:49:45 UTC 2013
>Originator:     Jonathan Briggs
>Release:        7.0-RELEASE
>Organization:
>Environment:
FreeBSD freebsd64 7.0-RELEASE FreeBSD 7.0-RELEASE #0: Sun Feb 24 10:35:36 UTC 2008     root@driscoll.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  amd64

>Description:
I was porting a specialized database library to FreeBSD and the build failed with this error:

/usr/bin/ld: /usr/lib/libgcov.a(_gcov_merge_add.o): relocation R_X86_64_32 can not be used when making a shared object; recompile with -fPIC
/usr/lib/libgcov.a: could not read symbols: Bad value

The library uses -fprofile-generate, runs a test set, then rebuilds with -fprofile-use.  It's worth a few ms per lookup.

Also, this builds very well on i386 FreeBSD 7.0 and on many varieties of Linux and their GCC builds (Debian ia64, Gentoo amd64, CentOS 5.2, Fedora 5, 8, 9).

I can work around the problem by just not doing a profile build.
>How-To-Repeat:
Put the following in a shell script:

#!/bin/sh
cat <<EOF |
#include <stdio.h>

int counter(int count)
{
	int i;

	for(i=0; i<count; i++) {
		printf("loop %d\n", i);
	}
	return i;
}
EOF
gcc -O2 -shared -fprofile-generate -fPIC -o t1.so -x c -

>Fix:


>Release-Note:
>Audit-Trail:

From: John Baldwin <jhb@freebsd.org>
To: freebsd-amd64@freebsd.org
Cc: Jonathan Briggs <zlynx@acm.org>, freebsd-gnats-submit@freebsd.org
Subject: Re: amd64/127640: GCC will not build shared libraries with -fprofile-generate on amd64
Date: Fri, 26 Sep 2008 10:01:43 -0400
 
 What if you add -fPIC as the message suggests?
 
 -- 
 John Baldwin

From: Bruce Cran <bruce@cran.org.uk>
To: bug-followup@FreeBSD.org, zlynx@acm.org
Cc:  
Subject: Re: amd64/127640: GCC will not build shared libraries with
 -fprofile-generate on amd64
Date: Thu, 25 Dec 2008 21:03:37 +0000

 I think the problem isn't that the application isn't being built with
 -fPIC, but that libgcov.a hasn't been built with it.  Running a 'make'
 in /usr/src/gnu/lib/libgcov shows libgcov.c being built without that
 flag, despite the following being present in the Makefile:
 
 $(OBJS_T}: libgcov.c
 	${CC} -c ${CFLAGS} -DL${.PREFIX} -o ${.TARGET} ${.ALLSRC:M*.c}
 
 .if !defined(NO_PIC)
 ${OBJS_S}: libgcov.c
 	${CC} -c ${PICFLAG} ${CFLAGS} -DL${.PREFIX} -o ${.TARGET}
 ${.ALLSRC:M*.c}
 .endif
 
 --
 Bruce Cran

From: Andriy Gapon <avg@freebsd.org>
To: bug-followup@freebsd.org, zlynx@acm.org, John Baldwin <jhb@freebsd.org>,
        Bruce Cran <brucec@freebsd.org>
Cc:  
Subject: Re: amd64/127640: [amd64] gcc(1) will not build shared libraries
 with -fprofile-generate on amd64
Date: Sun, 05 Dec 2010 15:57:36 +0200

 What's the status of this situation?
 Is the originator interested in pursuing it further? (The PR is 2+ years old
 after all).
 
 -- 
 Andriy Gapon

From: Zan Lynx <zlynx@acm.org>
To: bug-followup@FreeBSD.org, zlynx@acm.org
Cc:  
Subject: Re: amd64/127640: [amd64] gcc(1) will not build shared libraries
 with -fprofile-generate on amd64
Date: Sun, 05 Dec 2010 13:22:06 -0700

 The test script should reveal if this is still a problem.
 
 If it doesn't work then it is still broken.
 
 Leaving it broken will mean slower binaries for software which can make
 use of profile guided optimization.
 
 To fix it or not is up to the FreeBSD team.

From: Darren Pilgrim <list_freebsd@bluerosetech.com>
To: bug-followup@FreeBSD.org, zlynx@acm.org
Cc:  
Subject: Re: amd64/127640: [amd64] gcc(1) will not build shared libraries
 with -fprofile-generate on amd64
Date: Mon, 11 Nov 2013 08:48:27 -0800

 It appears this is no longer broken.  The provided shell script compiles 
 without error on 9.1-RELEASE-p6 and 8.3-RELEASE-p6.
 
 
State-Changed-From-To: open->feedback 
State-Changed-By: linimon 
State-Changed-When: Tue Nov 12 02:49:02 UTC 2013 
State-Changed-Why:  
To submitter: there is a claim that this is fixed.  Do you agree? 


Responsible-Changed-From-To: freebsd-amd64->linimon 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Tue Nov 12 02:49:02 UTC 2013 
Responsible-Changed-Why:  

http://www.freebsd.org/cgi/query-pr.cgi?pr=127640 
>Unformatted:
