Bug 160149

Summary: libtool doesn't pass -fprofile-generate to the linker
Product: [Fedora] Fedora Reporter: David Juran <djuran>
Component: libtoolAssignee: Alexandre Oliva <aoliva>
Status: CLOSED NOTABUG QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 3CC: goeran
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2005-06-23 17:29:17 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description David Juran 2005-06-11 21:03:22 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050513 Fedora/1.0.4-1.3.1 Firefox/1.0.4

Description of problem:
When instrumenting a shared library for gathering profile information with the -fprofile-generate flag to gcc, the flag must be given _both_ at compile and link time. However when linking a shared library using libtool, libtool strips away this flag.

my foo.c only contains the lines
void foo() {
}


Version-Release number of selected component (if applicable):
libtool-1.5.6-4.FC3.2

How reproducible:
Always

Steps to Reproduce:
1.[david@trollet profile]$ libtool --mode=compile gcc -c -o foo.lo -fprofile-generate foo.c
 gcc -c -fprofile-generate foo.c  -fPIC -DPIC -o .libs/foo.o
 gcc -c -fprofile-generate foo.c -o foo.o >/dev/null 2>&1


So far, so good

2. [david@trollet profile]$ libtool --mode=link gcc  -fprofile-generate -o libfoo.la -rpath /usr/lib foo.lo
rm -fr  .libs/libfoo.a .libs/libfoo.la .libs/libfoo.lai .libs/libfoo.so .libs/libfoo.so.0 .libs/libfoo.so.0.0.0
gcc -shared  .libs/foo.o   -Wl,-soname -Wl,libfoo.so.0 -o .libs/libfoo.so.0.0.0
(cd .libs && rm -f libfoo.so.0 && ln -s libfoo.so.0.0.0 libfoo.so.0)
(cd .libs && rm -f libfoo.so && ln -s libfoo.so.0.0.0 libfoo.so)
ar cru .libs/libfoo.a  foo.o
ranlib .libs/libfoo.a
creating libfoo.la
(cd .libs && rm -f libfoo.la && ln -s ../libfoo.la libfoo.la)

Here, do note how the line starting with 'gcc -shared' is missing the -fprofile-generate flag which will cause the profiling run to fail.
  

Additional info:

Comment 1 Alexandre Oliva 2005-06-23 17:27:11 UTC
Flags that must be passed to the compiler driver at link time must be prefixed
by -XCClinker, according to the libtool manual.  Bear in mind that libtool isn't
required to use the CC driver to link archives.  In fact, it won't even run a
linker if requested to create a static library, and on some platforms creating a
shared library runs the linker directly.  I'm afraid this is by design.