Subject: pkg/14353: libtool builds incorrect C++ shared libraries
To: None <gnats-bugs@gnats.netbsd.org>
From: None <witek@pd37.warszawa.sdi.tpnet.pl>
List: netbsd-bugs
Date: 10/25/2001 07:57:48
>Number:         14353
>Category:       pkg
>Synopsis:       libtool builds incorrect C++ shared libraries
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    pkg-manager
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Thu Oct 25 07:59:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Witold J. Wnuk
>Release:        1.5Y
>Organization:
>Environment:
NetBSD tamjee.wnuk.eu.org 1.5Y NetBSD 1.5Y (TAMJEE) #32: Wed Oct 24 10:51:25 CEST 2001     witek@tamjee.wnuk.eu.org:/usr/src/sys/arch/i386/compile/TAMJEE i386
>Description:
It is possible that this problem manifests itself only with -current.

ltcf-cxx.sh (libtool configuring script) uses following command to check how cc invokes linker (and which default libraries, objects or paths it uses)

output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | egrep "\-L"'

However, at least with -current:

> cc -shared -v conftest.o
Using builtin specs.
gcc version 2.95.3 20010315 (release)
 /usr/libexec/collect2 -m elf_i386 -shared /usr/lib/crtbeginS.o conftest.o /usr/lib/crtendS.o

Obviously, there is no -L.

>How-To-Repeat:
Kompile ;-) KDE2 and watch some programs (eg. knotify, kcmshell) mysteriously crash. This is because libtool will invoke c++ -shared -nostdlib without including /usr/lib/crtbeginS.o which will result with global objects being not initialized in the library.

Inspect installed /usr/pkg/bin/libtool, checking second definition of
predep_objects. Correcty it should read "/usr/lib/crtbeginS.o" and not "". Same with postdep_objects.


>Fix:
I propose looking for conftest.$objext instead of -L. It will probably work on all other platforms and so should be submited to libtool authors.

The line would read:
output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | egrep "\-L"'


Patch to /usr/pkgsrc/devel/libtool/patches/patch-ag:

---- CUT ----
diff -u patches/patch-ag.orig patches/patch-ag
--- patches/patch-ag.orig       Thu Oct 25 16:05:34 2001
+++ patches/patch-ag    Thu Oct 25 16:05:37 2001
@@ -2,6 +2,15 @@

 --- ltcf-cxx.sh.orig   Wed May 23 05:05:06 2001
 +++ ltcf-cxx.sh
+@@ -106,7 +106,7 @@
+   # Commands to make compiler produce verbose output that lists
+   # what "hidden" libraries, object files and flags are used when
+   # linking a shared library.
+-  output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | egrep "\-L"'
++  output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | egrep conftest.$objext'
+
+ else
+   with_gcc=no
 @@ -383,7 +383,23 @@
      esac
      ;;

>Release-Note:
>Audit-Trail:
>Unformatted: