[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Fwd: Re: Fix for --as-needed
From: Thiago Macieira <thiago.macieira () kdemail ! net>
Date: 2004-11-21 23:23:10
Message-ID: 200411212123.16974.thiago.macieira () kdemail ! net
[Download RAW message or body]
[Attachment #2 (multipart/mixed)]
Hello,
I've come up with a patch for the problems people were having with
--as-needed.
Description of the problem:
- meinproc uses libkio
- libkio uses libkdeui
- meinproc does not use libkdeui directly
When linking meinproc, libtool builds the whole dependency list, so that
both libkdeui and libkio are listed. In special, note that since libkdeui
is a dependency of libkio, it comes first.
The linker then links meinproc and, without --as-needed, adds to the
file's header:
NEEDED libkdeui.so.4
NEEDED libkio.so.4
With that, libkdeui is loaded first. When meinproc is used before the
libraries are installed, libtool relinks the program and add
$(builddir)/kdeui/.libs to the executable's RPATH. When the program is
then run, the correct version of libkdeui is found.
What happened when --as-needed got introduced is that, since meinproc
doesn't use libkdeui directly, the linker does not add the NEEDED symbol
to the program's header. Therefore, libkdeui is loaded only because
libkio uses it.
The problem in that case is that meinproc's RPATH does *not* influence the
search path for libkdeui. What's worse, libkio.so.4's RPATH cannot be
overriden.
My solution consists in:
1) adding the --enable-new-dtags flag to the linker, if supported. This
makes GNU ld emit RUNPATH directives as well as RPATH. The consequence is
twofold:
a) RPATH is ignored
b) RUNPATH is overrideable by LD_LIBRARY_PATH at run-time
2) making libtool's stub script use LD_LIBRARY_PATH as well as relinking.
(In truth, it probably doesn't have to relink, but I didn't want to make
such an intrusive change)
These two changes make the correct library be loaded.
3) make the --as-needed flag usage default to yes only if
--enable-new-dtags is present as well
The patch is attached. Tests here and with a guin...err... "test subject"
show it solves the problem. It changes kde-common/admin/acinclude.m4.in,
so I can't commit. Someone please review, test and commit if acceptable.
---------- ----------
Subject: Re: Fix for --as-needed
Date: Dom 21 Nov 2004 20:19
From: Mauricio Bahamonde <elkrammer@vtr.net>
To: Thiago Macieira <thiago@macieira.info>
Thiago,
Your patch seems to succesfully correct the problem, it worked fine
here. You should commit.
Thanks a lot for all your help.
Greetings,
--
Mauricio Bahamonde
<elkrammer@vtr.net>
-------------------------------------------------------
--
Thiago Macieira - Registered Linux user #65028
thiago (AT) macieira (DOT) info
ICQ UIN: 1967141 PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
["as_needed-fix.diff" (text/x-diff)]
Index: admin/acinclude.m4.in
===================================================================
RCS file: /home/kde/kde-common/admin/acinclude.m4.in,v
retrieving revision 2.481
diff -u -3 -p -r2.481 acinclude.m4.in
--- admin/acinclude.m4.in 19 Nov 2004 12:35:59 -0000 2.481
+++ admin/acinclude.m4.in 21 Nov 2004 19:17:55 -0000
@@ -979,7 +979,7 @@ if test -z "$kde_x_libraries" || test "x
X_LDFLAGS="-L$x_libraries"
fi
all_includes="$X_INCLUDES"
-all_libraries="$X_LDFLAGS $LDFLAGS_AS_NEEDED"
+all_libraries="$X_LDFLAGS $LDFLAGS_AS_NEEDED $LDFLAGS_NEW_DTAGS"
# Check for libraries that X11R6 Xt/Xaw programs need.
ac_save_LDFLAGS="$LDFLAGS"
@@ -1691,12 +1691,23 @@ AC_DEFUN([KDE_CHECK_CLOSURE],
AC_SUBST(KDE_NO_UNDEFINED)
])
+dnl Check if the linker supports --enable-new-dtags
+AC_DEFUN([KDE_CHECK_NEW_DTAGS],
+[
+ LDFLAGS_NEW_DTAGS=""
+ KDE_CHECK_COMPILER_FLAG([Wl,--enable-new-dtags],
+ [LDFLAGS_NEW_DTAGS="-Wl,--enable-new-dtags"],)
+ AC_SUBST(LDFLAGS_NEW_DTAGS)
+])
+
dnl Check for the linker if it supports --as-needed
AC_DEFUN([KDE_CHECK_AS_NEEDED],
[
+ KDE_CHECK_NEW_DTAGS
+
AC_ARG_ENABLE(as_needed,
AC_HELP_STRING([--disable-as-needed],[disable the --as-needed flag for the linker]),
- kde_use_as_needed=$enableval, kde_use_as_needed=yes)
+ kde_use_as_needed=$enableval, kde_use_as_needed=$kde_cv_prog_cxx_Wl___enable_new_dtags)
LDFLAGS_AS_NEEDED=""
if test "x$kde_use_as_needed" = "xyes"; then
Index: admin/ltmain.sh
===================================================================
RCS file: /home/kde/kde-common/admin/ltmain.sh,v
retrieving revision 1.65
diff -u -3 -p -r1.65 ltmain.sh
--- admin/ltmain.sh 15 Jun 2004 16:47:06 -0000 1.65
+++ admin/ltmain.sh 21 Nov 2004 19:17:57 -0000
@@ -4896,18 +4896,13 @@ else
"
;;
- *-*-freebsd* )
+ *)
# Need to set LD_LIBRARY_PATH, to the value already
# computed within libtool.
$echo >> $output "\
LD_LIBRARY_PATH=\"$rpath\" exec \$progdir/\$program \${1+\"\$@\"}
"
;;
- *)
- $echo >> $output "\
- exec \$progdir/\$program \${1+\"\$@\"}
-"
- ;;
esac
$echo >> $output "\
\$echo \"\$0: cannot exec \$program \${1+\"\$@\"}\"
[Attachment #6 (application/pgp-signature)]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic