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:
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.