From tijl@coosemans.org  Wed Apr 18 17:15:30 2012
Return-Path: <tijl@coosemans.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 3A77E106564A
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 18 Apr 2012 17:15:30 +0000 (UTC)
	(envelope-from tijl@coosemans.org)
Received: from mailrelay008.isp.belgacom.be (mailrelay008.isp.belgacom.be [195.238.6.174])
	by mx1.freebsd.org (Postfix) with ESMTP id B72E58FC08
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 18 Apr 2012 17:15:29 +0000 (UTC)
Received: from 84.90-177-91.adsl-dyn.isp.belgacom.be (HELO kalimero.tijl.coosemans.org) ([91.177.90.84])
  by relay.skynet.be with ESMTP; 18 Apr 2012 19:14:19 +0200
Received: from kalimero.tijl.coosemans.org (kalimero.tijl.coosemans.org [127.0.0.1])
	by kalimero.tijl.coosemans.org (8.14.5/8.14.5) with ESMTP id q3IHEIY9026767
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 18 Apr 2012 19:14:18 +0200 (CEST)
	(envelope-from tijl@kalimero.tijl.coosemans.org)
Received: (from tijl@localhost)
	by kalimero.tijl.coosemans.org (8.14.5/8.14.5/Submit) id q3IHEIqN026766;
	Wed, 18 Apr 2012 19:14:18 +0200 (CEST)
	(envelope-from tijl)
Message-Id: <201204181714.q3IHEIqN026766@kalimero.tijl.coosemans.org>
Date: Wed, 18 Apr 2012 19:14:18 +0200 (CEST)
From: Tijl Coosemans <tijl@coosemans.org>
Reply-To: Tijl Coosemans <tijl@coosemans.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: libtool does not respect CC when linking shared library
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         167069
>Category:       ports
>Synopsis:       libtool does not respect CC when linking shared library
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Apr 18 17:20:04 UTC 2012
>Closed-Date:    Wed Apr 18 18:25:38 UTC 2012
>Last-Modified:  Wed Apr 18 18:25:38 UTC 2012
>Originator:     Tijl Coosemans
>Release:        FreeBSD 10.0-CURRENT i386
>Organization:
>Environment:
>Description:
When a port sets USE_AUTOTOOLS=libtool /usr/local/bin/libtool is used
instead of the port's own libtool script as generated by configure.

The problem is that when linking shared libraries libtool will use the
compiler it was configured for, so in case of USE_AUTOTOOLS=libtool it
will use the compiler used when building devel/libtool instead of the
compiler for the port that is being built.

Here's an excerpt from
http://pointyhat.freebsd.org/errorlogs/amd64-9-full-logs/libctl-3.1_1.log

/bin/sh /usr/local/bin/libtool --tag=CC    --mode=compile gcc46 ...
libtool: compile:  gcc46 -DHAVE_CONFIG_H -I. -I.. -I/usr/local/include ...
libtool: compile:  gcc46 -DHAVE_CONFIG_H -I. -I.. -I/usr/local/include ...
mv -f .deps/cintegrator.Tpo .deps/cintegrator.Plo
/bin/sh /usr/local/bin/libtool --tag=CC    --mode=link gcc46  -O2 -pipe ...
libtool: link: cc -shared  -fPIC -DPIC  .libs/ctl.o .libs/subplex.o ...
libtool: link: (cd ".libs" && rm -f "libctl.so" && ln -s "libctl.so.4" ...
libtool: link: (cd ".libs" && rm -f "libctl.so" && ln -s "libctl.so.4" ...
libtool: link: ar cru .libs/libctl.a  ctl.o subplex.o ctl-f77-glue.o ...
libtool: link: ranlib .libs/libctl.a
libtool: link: ( cd ".libs" && rm -f "libctl.la" && ln -s "../libctl.la" ...

The first libtool command (--mode=compile) works. It compiles a
shared and a static version of a C file using gcc46. The second
command (--mode=libtool) is incorrect. It uses cc instead of gcc46
to create the shared library.

This affects ports that set USE_GCC/FORTRAN and users that set CC/CXX to
use clang or a more recent version of gcc. The resulting library may be
linked with the wrong runtime libraries and features such as link time
optimisation don't work.
>How-To-Repeat:
>Fix:
I haven't got a fix, but I've analysed the problem somewhat.

In compile mode libtool uses the compiler given on the command line,
so this always works. Link mode for an executable does the same. Link
mode for a library however executes $archive_cmds, which is defined as:

archive_cmds="\$CC -shared \$pic_flag \$libobjs \$deplibs ...

and CC is set to the compiler used during configure.

Perhaps libtool can be patched to make this mode work like the other
modes. An alternative would be to make USE_AUTOTOOLS=libtool run
libtoolize instead of patching the port to use /usr/local/bin/libtool.
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: bf 
State-Changed-When: Wed Apr 18 18:25:37 UTC 2012 
State-Changed-Why:  
This is a duplicate of ports/155546.  libtool also fails to respect 
other toolchain-related variables, although this is the most 
conspicuous. 

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