Patch: Check if -lc is needed for libtool.
H . J . Lu
hjl@valinux.com
Tue Jul 18 11:27:00 GMT 2000
While working on libgcc, I noticed there was a problem with libtool.
The part of the libgcc problem comes from ltmain.sh. Glibc includes
some frame functions from libgcc. Also under Linux, when you use
"gcc -shared " to create the shared library, "-lgcc -lc -lgcc" is
added. There is no need to add -lc for libtool. It also introduces
a problem when used on a C++ shared library, libstdc++.so in libstdc++
v3, since the linker will see those frame functions in libc and won't
include them in libstdc++.so. Since libc.so doesn't have all EH
functions from libgcc, the linker will get the rest from libgcc and
put them in libstdc++.so. Now you have a libstdc++.so which has some
EH functions and also uses some from libc.so. If the EH functions in
libgcc change, compiling libstdc++ won't get those already in libc.so
unless libc.so is recompiled. That is why I didn't see the EH failures
with libstdc++ which doesn't use libtool, but only with libstdc++ v3
which uses libtool. In general, it is not nessary to pass -lc to
"gcc -shared" on Linux. It is only needed for some very old gcc. It
should be trivial to check if -lc is necessary or not:
# gcc -shared -v dummy.c 2>&1 | grep " -lc "
should do the trick. I am enclosing a patch to do that. In case of
libstdc++ v3, it causes the EH problem.
BTW, I have sent a separate patch to libtool.
Thanks.
H.J.
---
2000-07-18 H.J. Lu (hjl@gnu.org)
* ltmain.sh: Add -lc when building shared libary only if
necessary.
* ltconfig: Check if -lc is necessary for building shared
libary. Set build_libtool_need_lc to indicate it.
Index: ltconfig
===================================================================
RCS file: /work/cvs/gnu/egcs/ltconfig,v
retrieving revision 1.1.1.4
diff -u -p -r1.1.1.4 ltconfig
--- ltconfig 1999/07/02 16:38:36 1.1.1.4
+++ ltconfig 2000/07/18 17:57:29
@@ -1940,6 +1940,28 @@ esac
echo "$ac_t$enable_shared" 1>&6
+if test "$enable_shared" = yes; then
+ echo "checking if we need -lc for building shared libraries..." 1>&6
+ need_lc=yes
+ $rm conftest*
+ touch conftest.c
+ if { (eval echo $progname:1948: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>conftest.err; }; then
+ # Append any warnings to the config.log.
+ cat conftest.err 1>&5
+
+ soname=conftest
+ lib=conftest
+ libobjs=conftest.o
+ deplibs=
+ linkopts=-v
+ if { (eval echo $progname:1957: \"$archive_cmds\") 1>&5; (eval $archive_cmds) 2>&1 | grep " -lc " 1>&5 ; }; then
+ need_lc=no
+ fi
+ else
+ cat conftest.err 1>&5
+ fi
+fi
+
# Make sure either enable_shared or enable_static is yes.
test "$enable_shared" = yes || enable_static=yes
@@ -2533,6 +2555,9 @@ SHELL=$LTSHELL
# Whether or not to build shared libraries.
build_libtool_libs=$enable_shared
+
+# Whether or not to add -lc for building shared libraries.
+build_libtool_need_lc=$need_lc
# Whether or not to build static libraries.
build_old_libs=$enable_static
Index: ltmain.sh
===================================================================
RCS file: /work/cvs/gnu/egcs/ltmain.sh,v
retrieving revision 1.1.1.4
diff -u -p -r1.1.1.4 ltmain.sh
--- ltmain.sh 1999/07/02 16:38:36 1.1.1.4
+++ ltmain.sh 2000/07/18 17:54:55
@@ -1703,8 +1703,10 @@ compiler."
# these systems don't actually have a c library (as such)!
;;
*)
- # Add libc to deplibs on all other systems.
- deplibs="$deplibs -lc"
+ # Add libc to deplibs on all other systems if necessary.
+ if test $build_libtool_need_lc = "yes"; then
+ deplibs="$deplibs -lc"
+ fi
;;
esac
fi
More information about the Gcc-patches
mailing list