From kde-core-devel Sun Nov 21 23:23:10 2004 From: Thiago Macieira Date: Sun, 21 Nov 2004 23:23:10 +0000 To: kde-core-devel Subject: Fwd: Re: Fix for --as-needed Message-Id: <200411212123.16974.thiago.macieira () kdemail ! net> X-MARC-Message: https://marc.info/?l=kde-core-devel&m=110107943726977 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--nextPart2998814.rm0SLTuQJl" --nextPart2998814.rm0SLTuQJl Content-Type: multipart/mixed; boundary="Boundary-01=_eNSoBGRPiXHUigQ" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-01=_eNSoBGRPiXHUigQ Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hello, I've come up with a patch for the problems people were having with=20 =2D-as-needed.=20 Description of the problem: =2D meinproc uses libkio =2D libkio uses libkdeui =2D meinproc does not use libkdeui directly When linking meinproc, libtool builds the whole dependency list, so that=20 both libkdeui and libkio are listed. In special, note that since libkdeui=20 is a dependency of libkio, it comes first. The linker then links meinproc and, without --as-needed, adds to the=20 file's header: NEEDED libkdeui.so.4 NEEDED libkio.so.4 With that, libkdeui is loaded first. When meinproc is used before the=20 libraries are installed, libtool relinks the program and add=20 $(builddir)/kdeui/.libs to the executable's RPATH. When the program is=20 then run, the correct version of libkdeui is found. What happened when --as-needed got introduced is that, since meinproc=20 doesn't use libkdeui directly, the linker does not add the NEEDED symbol=20 to the program's header. Therefore, libkdeui is loaded only because=20 libkio uses it.=20 The problem in that case is that meinproc's RPATH does *not* influence the= =20 search path for libkdeui. What's worse, libkio.so.4's RPATH cannot be=20 overriden. My solution consists in: 1) adding the --enable-new-dtags flag to the linker, if supported. This=20 makes GNU ld emit RUNPATH directives as well as RPATH. The consequence is=20 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.=20 (In truth, it probably doesn't have to relink, but I didn't want to make=20 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=20 =2D-enable-new-dtags is present as well The patch is attached. Tests here and with a guin...err... "test subject"=20 show it solves the problem. It changes kde-common/admin/acinclude.m4.in,=20 so I can't commit. Someone please review, test and commit if acceptable. =2D--------- ---------- Subject: Re: Fix for --as-needed Date: Dom 21 Nov 2004 20:19 =46rom: Mauricio Bahamonde To: Thiago Macieira Thiago, Your patch seems to succesfully correct the problem, it worked fine here. You should commit. Thanks a lot for all your help. Greetings, =2D- Mauricio Bahamonde =2D------------------------------------------------------ =2D-=20 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 --Boundary-01=_eNSoBGRPiXHUigQ Content-Type: text/x-diff; charset="utf-8"; name="as_needed-fix.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="as_needed-fix.diff" Index: admin/acinclude.m4.in =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/kde/kde-common/admin/acinclude.m4.in,v retrieving revision 2.481 diff -u -3 -p -r2.481 acinclude.m4.in =2D-- 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=3D"-L$x_libraries" fi all_includes=3D"$X_INCLUDES" =2Dall_libraries=3D"$X_LDFLAGS $LDFLAGS_AS_NEEDED" +all_libraries=3D"$X_LDFLAGS $LDFLAGS_AS_NEEDED $LDFLAGS_NEW_DTAGS" =20 # Check for libraries that X11R6 Xt/Xaw programs need. ac_save_LDFLAGS=3D"$LDFLAGS" @@ -1691,12 +1691,23 @@ AC_DEFUN([KDE_CHECK_CLOSURE], AC_SUBST(KDE_NO_UNDEFINED) ]) =20 +dnl Check if the linker supports --enable-new-dtags +AC_DEFUN([KDE_CHECK_NEW_DTAGS], +[ + LDFLAGS_NEW_DTAGS=3D"" + KDE_CHECK_COMPILER_FLAG([Wl,--enable-new-dtags], + [LDFLAGS_NEW_DTAGS=3D"-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 t= he linker]), =2D kde_use_as_needed=3D$enableval, kde_use_as_needed=3Dyes) + kde_use_as_needed=3D$enableval, kde_use_as_needed=3D$kde_cv_prog_cxx_Wl= ___enable_new_dtags) =20 LDFLAGS_AS_NEEDED=3D"" if test "x$kde_use_as_needed" =3D "xyes"; then Index: admin/ltmain.sh =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/kde/kde-common/admin/ltmain.sh,v retrieving revision 1.65 diff -u -3 -p -r1.65 ltmain.sh =2D-- 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 " ;; =20 =2D *-*-freebsd* ) + *) # Need to set LD_LIBRARY_PATH, to the value already # computed within libtool. $echo >> $output "\ LD_LIBRARY_PATH=3D\"$rpath\" exec \$progdir/\$program \${1+\"\$@\"} " ;; =2D *) =2D $echo >> $output "\ =2D exec \$progdir/\$program \${1+\"\$@\"} =2D" =2D ;; esac $echo >> $output "\ \$echo \"\$0: cannot exec \$program \${1+\"\$@\"}\" --Boundary-01=_eNSoBGRPiXHUigQ-- --nextPart2998814.rm0SLTuQJl Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.6 (GNU/Linux) iD8DBQBBoSNkM/XwBW70U1gRAidYAJ9N4Yp8DPckyb7XZRwXZB0oc6PqCACgqOyd COmPPW5vmY6MGAZdEOST8AM= =2s/8 -----END PGP SIGNATURE----- --nextPart2998814.rm0SLTuQJl--