Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 5 Feb 2002 18:27:32 +0200
From:      Ruslan Ermilov <ru@FreeBSD.ORG>
To:        "David O'Brien" <obrien@FreeBSD.ORG>, Bruce Evans <bde@FreeBSD.ORG>
Cc:        current@FreeBSD.ORG, alpha@FreeBSD.ORG, Mark Murray <markm@FreeBSD.ORG>
Subject:   [PATCH] ld(1) and shared libraries dependencies (was: Re: alpha cross-compiler hosed)
Message-ID:  <20020205182731.A57843@sunbay.com>
In-Reply-To: <20020125105058.C57703@sunbay.com>
References:  <20020125105058.C57703@sunbay.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--tKW2IUtsqtDRztdT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Fri, Jan 25, 2002 at 10:50:58AM +0200, Ruslan Ermilov wrote:
> Hi!
> 
> Some background first.
> 
> I am currently working on cleaning up the "false dependencies"
> issue for secure/.  The attached patch p1 fixes this.  This is
> done by moving the false dependencies from secure/ utilities
> directly to libssh.so.  This also requires a slight re-ordering
> in `libraries' target of Makefile.inc1, which is done by the
> attached patch p2.
> 
> So far it's OK.  Now the problem.  I was testing these patches
> on an i386 -CURRENT box that does nightly "make world"s for
> both i386 and alpha.  i386 world built OK, alpha cross-world
> broke trying to link secure/libexec/sftp-server as follows:
> 
> : Script started on Fri Jan 25 10:09:41 2002
> : --------------------------------------------------------------
> : >>> Building everything..
> : --------------------------------------------------------------
> : cd /usr/src; MAKEOBJDIRPREFIX=/usr/obj/alpha  MACHINE_ARCH=alpha  MACHINE=alpha  COMPILER_PATH=/usr/obj/alpha/usr/src/i386/usr/libexec:/usr/obj/alpha/usr/src/i386/usr/bin  LIBRARY_PATH=/usr/obj/alpha/usr/src/i386/usr/lib:/usr/obj/alpha/usr/src/i386/usr/lib  OBJFORMAT_PATH=/usr/obj/alpha/usr/src/i386/usr/libexec  CINCLUDES="-nostdinc"  CXXINCLUDES="-nostdinc++"  PERL5LIB=/usr/obj/alpha/usr/src/i386/usr/libdata/perl/5.6.0  GROFF_BIN_PATH=/usr/obj/alpha/usr/src/i386/usr/bin  GROFF_FONT_PATH=/usr/obj/alpha/usr/src/i386/usr/share/groff_font  GROFF_TMAC_PATH=/usr/obj/alpha/usr/src/i386/usr/share/tmac  DESTDIR=/usr/obj/alpha/usr/src/i386  INSTALL="sh /usr/src/tools/install.sh"  PATH=/usr/obj/alpha/usr/src/i386/usr/sbin:/usr/obj/alpha/usr/src/i386/usr/bin:/usr/obj/alpha/usr/src/i386/usr/games:/sbin:/bin:/usr/sbin:/usr/bin make -f Makefile.inc1 all
> : ===> secure/libexec/sftp-server
> : cc -O -pipe -nostdinc -mcpu=ev4 -DNO_IDEA   -I/usr/obj/alpha/usr/src/i386/usr/include   -o sftp-server sftp-server.o sftp-common.o  -lssh -lcrypto
> : /usr/obj/alpha/usr/src/i386/usr/libexec/elf/ld: warning: libz.so.2, needed by /usr/obj/alpha/usr/src/i386/usr/lib/libssh.so, not found (try using -rpath or -rpath-link)
> : /usr/obj/alpha/usr/src/i386/usr/lib/libssh.so: undefined reference to `deflate'
> : /usr/obj/alpha/usr/src/i386/usr/lib/libssh.so: undefined reference to `inflate'
> : /usr/obj/alpha/usr/src/i386/usr/lib/libssh.so: undefined reference to `inflateInit_'
> : /usr/obj/alpha/usr/src/i386/usr/lib/libssh.so: undefined reference to `deflateInit_'
> : /usr/obj/alpha/usr/src/i386/usr/lib/libssh.so: undefined reference to `inflateEnd'
> : /usr/obj/alpha/usr/src/i386/usr/lib/libssh.so: undefined reference to `deflateEnd'
> : *** Error code 1
> : 
> : Stop in /usr/src/secure/libexec/sftp-server.
> : *** Error code 1
> : 
> : Script done on Fri Jan 25 10:09:42 2002
> 
> The ld(1) error message above says (formatted by fmt(1)):
> 
> : /usr/obj/alpha/usr/src/i386/usr/libexec/elf/ld: warning: libz.so.2,
> : needed by /usr/obj/alpha/usr/src/i386/usr/lib/libssh.so, not found
> : (try using -rpath or -rpath-link)
> 
> But the library _is_ there, and it was built even earlier than libssh:
> 
> : # cd /usr/obj/alpha/usr/src/i386/usr/lib
> : # ls -l libssh.so* libz.so*
> : lrwxr-xr-x  1 root  wheel      11 Jan 25 06:19 libssh.so -> libssh.so.2
> : -rwxr-xr-x  1 root  wheel  295859 Jan 25 06:19 libssh.so.2
> : lrwxr-xr-x  1 root  wheel       9 Jan 25 06:34 libz.so -> libz.so.2
> : -rwxr-xr-x  1 root  wheel   80017 Jan 25 06:11 libz.so.2
> 
> Now about the bug.  Here's the interesting output from both i386 and
> alpha versions of cross-compiler built tonight:
> 
> : # /usr/obj/usr/src/i386/usr/bin/gcc -print-search-dirs
> : install: /usr/obj/usr/src/i386/usr/libexec/(null)
> : programs: /usr/obj/usr/src/i386/usr/libexec/elf/:/usr/obj/usr/src/i386/usr/libexec/
> : libraries: /usr/obj/usr/src/i386/usr/libexec/:/usr/obj/usr/src/i386/usr/lib/
> : # /usr/obj/alpha/usr/src/i386/usr/bin/gcc -print-search-dirs
> : install: /usr/obj/alpha/usr/src/i386/usr/libexec/(null)
> : programs: /usr/obj/alpha/usr/src/i386/usr/libexec/elf/
> : libraries:
> 
> Note the empty "libraries:" for the alpha version.  I think this
> is the bug.
> 
I was wrong.  The actual bug was worse and somewhat different.

> I will see if I can fix this bug myself, but I thought David could
> fix it quicker than me.  :-)
> 
When using ELF (information taken from ld.info) one shared library
may require another (see the -rpath-link option to ld(1)).  When
linking with the shared libraries is requested, the -L paths are
ignored when searching for dependant, and only ${LD_LIBRARY_PATH},
-rpath-link, or SEARCH_DIR (from ldscript) are used, as documented
in contrib/binutils/ld/emultempl/elf32.em (the latter produces
e${EMULATION_NAME}.c in ${.OBJDIR}).  Specifically:

: We need to find this file and include the symbol table.  We
: want to search for the file in the same way that the dynamic
: linker will search.  That means that we want to use
: rpath_link, rpath, then the environment variable
: LD_LIBRARY_PATH (native only), then the DT_RPATH/DT_RUNPATH
: entries (native only), then the linker script LIB_SEARCH_DIRS.
: We do not search using the -L arguments.

The LIB_SEARCH_DIRS above corresponds to ldscript's SEARCH_DIR
path, and was hardcoded in gnu/usr.bin/binutils/ld/Makefile.${arch}
to /usr/lib.  The attached patch p.ld fixes this long-standing bug.

There was an assorted bug in Makefile, where ${DESTDIR} was bogusly
prepended to SCRIPTDIR.  This is not anymore a problem in -CURRENT,
where DESTDIR="" in XMAKE (see Makefile.inc1).  This is worse in
-STABLE:

# strings /usr/libexec/elf/ld | grep -w obj
/usr/obj/STABLE/usr/src/i386/usr/libdata

I'm not sure about the consequences.  I think they are null, as it
seems we don't actually use /usr/libdata/ldscripts, as they are
hardcoded directly into ld(1).  Am I right?

I'd like to personally thank Mr. truss(1) for helping me fix this
bug.

Mark, now nothing prevents the attached patch p.secure from being
committed except your long silence to my review request.  :-)


Cheers,
-- 
Ruslan Ermilov		Sysadmin and DBA,
ru@sunbay.com		Sunbay Software AG,
ru@FreeBSD.org		FreeBSD committer,
+380.652.512.251	Simferopol, Ukraine

http://www.FreeBSD.org	The Power To Serve
http://www.oracle.com	Enabling The Information Age

--tKW2IUtsqtDRztdT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="p.ld"

Index: Makefile
===================================================================
RCS file: /home/ncvs/src/gnu/usr.bin/binutils/ld/Makefile,v
retrieving revision 1.19
diff -u -r1.19 Makefile
--- Makefile	2002/01/27 22:47:22	1.19
+++ Makefile	2002/02/05 15:53:02
@@ -18,7 +18,7 @@
 	ln -sf ${.CURDIR}/../../../../include/${.TARGET} .
 .endif
 
-CFLAGS+= -DSCRIPTDIR=\"${DESTDIR}/usr/libdata\"
+CFLAGS+= -DSCRIPTDIR=\"${TOOLS_PREFIX}/usr/libdata\"
 CFLAGS+= -DBFD_VERSION_STRING=\"${VERSION}\"
 CFLAGS+= -I${SRCDIR}/ld -I${SRCDIR}/bfd
 NOSHARED?= yes
Index: Makefile.alpha
===================================================================
RCS file: /home/ncvs/src/gnu/usr.bin/binutils/ld/Makefile.alpha,v
retrieving revision 1.13
diff -u -r1.13 Makefile.alpha
--- Makefile.alpha	2001/10/14 02:13:55	1.13
+++ Makefile.alpha	2002/02/05 15:53:02
@@ -6,7 +6,7 @@
 HOST=	${TARGET_TUPLE}
 CFLAGS+= -DDEFAULT_EMULATION=\"elf64alpha\"
 CFLAGS+= -DTARGET=\"${TARGET_TUPLE}\"
-_alpha_path=	\"/usr/lib\"
+_alpha_path=	\"${TOOLS_PREFIX}/usr/lib\"
 .else
 _alpha_path=	\"/usr/cross/alpha-freebsd/usr/lib\"
 .endif
Index: Makefile.i386
===================================================================
RCS file: /home/ncvs/src/gnu/usr.bin/binutils/ld/Makefile.i386,v
retrieving revision 1.14
diff -u -r1.14 Makefile.i386
--- Makefile.i386	2001/10/14 02:13:55	1.14
+++ Makefile.i386	2002/02/05 15:53:02
@@ -6,7 +6,7 @@
 HOST=	${TARGET_TUPLE}
 CFLAGS+= -DDEFAULT_EMULATION=\"elf_i386\"
 CFLAGS+= -DTARGET=\"${TARGET_TUPLE}\"
-_i386_path=	\"/usr/lib\"
+_i386_path=	\"${TOOLS_PREFIX}/usr/lib\"
 .else
 _i386_path=	\"/usr/cross/i386-freebsd/usr/lib\"
 .endif
Index: Makefile.ia64
===================================================================
RCS file: /home/ncvs/src/gnu/usr.bin/binutils/ld/Makefile.ia64,v
retrieving revision 1.1
diff -u -r1.1 Makefile.ia64
--- Makefile.ia64	2001/10/15 02:12:08	1.1
+++ Makefile.ia64	2002/02/05 15:53:02
@@ -6,7 +6,7 @@
 HOST=	${TARGET_TUPLE}	# do what?? how does this work for a cross-build??
 CFLAGS+= -DDEFAULT_EMULATION=\"elf64_ia64\"
 CFLAGS+= -DTARGET=\"${TARGET_TUPLE}\"
-_ia64_path=	\"/usr/lib\"
+_ia64_path=	\"${TOOLS_PREFIX}/usr/lib\"
 .else
 _ia64_path=	\"/usr/cross/ia64-freebsd/usr/lib\"
 .endif
Index: Makefile.m68k
===================================================================
RCS file: /home/ncvs/src/gnu/usr.bin/binutils/ld/Makefile.m68k,v
retrieving revision 1.5
diff -u -r1.5 Makefile.m68k
--- Makefile.m68k	2001/10/14 01:57:19	1.5
+++ Makefile.m68k	2002/02/05 15:53:02
@@ -4,7 +4,7 @@
 HOST=	m68k-unknown-freebsd
 CFLAGS+= -DDEFAULT_EMULATION=\"elf_m68k\"
 CFLAGS+= -DTARGET=\"m68k-unknown-freebsd\"
-_m68k_path=	\"/usr/lib\"
+_m68k_path=	\"${TOOLS_PREFIX}/usr/lib\"
 .else
 _m68k_path=	\"/usr/cross/m68k-freebsd/usr/lib\"
 .endif
Index: Makefile.powerpc
===================================================================
RCS file: /home/ncvs/src/gnu/usr.bin/binutils/ld/Makefile.powerpc,v
retrieving revision 1.7
diff -u -r1.7 Makefile.powerpc
--- Makefile.powerpc	2001/10/14 02:13:55	1.7
+++ Makefile.powerpc	2002/02/05 15:53:02
@@ -6,7 +6,7 @@
 HOST=	${TARGET_TUPLE}
 CFLAGS+= -DDEFAULT_EMULATION=\"elf_powerpc\"
 CFLAGS+= -DTARGET=\"${TARGET_TUPLE}\"
-_powerpc_path=	\"/usr/lib\"
+_powerpc_path=	\"${TOOLS_PREFIX}/usr/lib\"
 .else
 _powerpc_path=	\"/usr/cross/powerpc-freebsd/usr/lib\"
 .endif
Index: Makefile.sparc64
===================================================================
RCS file: /home/ncvs/src/gnu/usr.bin/binutils/ld/Makefile.sparc64,v
retrieving revision 1.7
diff -u -r1.7 Makefile.sparc64
--- Makefile.sparc64	2001/10/14 02:13:55	1.7
+++ Makefile.sparc64	2002/02/05 15:53:02
@@ -6,7 +6,7 @@
 HOST=	${TARGET_TUPLE}
 CFLAGS+= -DDEFAULT_EMULATION=\"elf32_sparc\"
 CFLAGS+= -DTARGET=\"${TARGET_TUPLE}\"
-_sparc_path=	\"/usr/lib\"
+_sparc_path=	\"${TOOLS_PREFIX}/usr/lib\"
 .else
 _sparc_path=	\"/usr/cross/sparc-freebsd/usr/lib\"
 .endif

--tKW2IUtsqtDRztdT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="p.secure"

Index: Makefile.inc1
===================================================================
RCS file: /home/ncvs/src/Makefile.inc1,v
retrieving revision 1.235
diff -u -r1.235 Makefile.inc1
--- Makefile.inc1	2001/12/28 11:53:18	1.235
+++ Makefile.inc1	2002/02/05 16:10:23
@@ -731,6 +731,7 @@
 #	  librpcsvc libtacplus libutil libz libssh
 # libradius: libmd
 # libreadline: libncurses
+# libssh: libcrypto libz
 # libstc++: msun
 # libtacplus: libmd
 #
@@ -740,7 +741,7 @@
 # kerberosIV/lib kerberos5/lib: lib/libcrypt
 # lib/libpam: secure/lib/libcrypto kerberosIV/lib/libkrb \
 #             secure/lib/libssh lib/libz
-# secure/lib: lib/libmd
+# secure/lib: secure/lib/libcrypto lib/libmd lib/libz
 #
 .if exists(${.CURDIR}/lib/csu/${MACHINE_ARCH}.pcc)
 _csu=	lib/csu/${MACHINE_ARCH}.pcc
@@ -750,8 +751,11 @@
 _csu=	lib/csu/${MACHINE_ARCH}
 .endif
 
-.if !defined(NOSECURE) && !defined(NOCRYPT)
+.if exists(${.CURDIR}/secure) && !defined(NOCRYPT) && !defined(NOSECURE)
 _secure_lib=	secure/lib
+.if exists(${.CURDIR}/secure/lib/libcrypto)
+_libcrypto=	secure/lib/libcrypto
+.endif
 .endif
 
 .if !defined(NOCRYPT) && defined(MAKE_KERBEROS4)
@@ -772,10 +776,10 @@
 
 libraries:
 .for _lib in ${_csu} gnu/lib/csu gnu/lib/libgcc lib/libmd lib/libcrypt \
-    ${_secure_lib} ${_kerberosIV_lib} \
+    lib/libz ${_libcrypto} ${_secure_lib} ${_kerberosIV_lib} \
     ${_kerberos5_lib} lib/libcom_err lib/libkvm lib/msun lib/libncurses \
     lib/libopie lib/libradius lib/librpcsvc lib/libsbuf lib/libtacplus \
-    lib/libutil lib/libz lib gnu/lib ${_libperl} usr.bin/lex/lib ${_libkeycap}
+    lib/libutil lib gnu/lib ${_libperl} usr.bin/lex/lib ${_libkeycap}
 .if exists(${.CURDIR}/${_lib})
 	cd ${.CURDIR}/${_lib}; \
 		${MAKE} depend; \
Index: secure/lib/libssh/Makefile
===================================================================
RCS file: /home/ncvs/src/secure/lib/libssh/Makefile,v
retrieving revision 1.12
diff -u -r1.12 Makefile
--- secure/lib/libssh/Makefile	2002/01/23 15:54:09	1.12
+++ secure/lib/libssh/Makefile	2002/02/05 16:10:23
@@ -24,6 +24,9 @@
 CFLAGS+= -DKRB5
 .endif # MAKE_KERBEROS5
 
+DPADD=	${LIBCRYPTO} ${LIBZ}
+LDADD=	-lcrypto -lz
+
 .include <bsd.lib.mk>
 
 .PATH:	${SSHDIR} ${SSHDIR}/lib
Index: secure/libexec/sftp-server/Makefile
===================================================================
RCS file: /home/ncvs/src/secure/libexec/sftp-server/Makefile,v
retrieving revision 1.4
diff -u -r1.4 Makefile
--- secure/libexec/sftp-server/Makefile	2002/01/23 15:54:09	1.4
+++ secure/libexec/sftp-server/Makefile	2002/02/05 16:10:23
@@ -5,8 +5,8 @@
 SRCS=   sftp-server.c sftp-common.c
 MAN=	sftp-server.8
 
-LDADD+=	-lssh -lcrypto -lz
-DPADD+=	${LIBSSH} ${LIBCRYPTO} ${LIBZ}
+LDADD+=	-lssh -lcrypto
+DPADD+=	${LIBSSH} ${LIBCRYPTO}
 
 .include <bsd.prog.mk>
 
Index: secure/usr.bin/scp/Makefile
===================================================================
RCS file: /home/ncvs/src/secure/usr.bin/scp/Makefile,v
retrieving revision 1.6
diff -u -r1.6 Makefile
--- secure/usr.bin/scp/Makefile	2002/01/23 15:54:10	1.6
+++ secure/usr.bin/scp/Makefile	2002/02/05 16:10:23
@@ -4,8 +4,8 @@
 PROG=	scp
 SRCS=	scp.c scp-common.c
 
-LDADD+=	-lssh -lcrypto -lutil -lz
-DPADD+=	${LIBSSH} ${LIBCRYPTO} ${LIBUTIL} ${LIBZ}
+DPADD=	${LIBSSH}
+LDADD=	-lssh
 
 .include <bsd.prog.mk>
 
Index: secure/usr.bin/sftp/Makefile
===================================================================
RCS file: /home/ncvs/src/secure/usr.bin/sftp/Makefile,v
retrieving revision 1.2
diff -u -r1.2 Makefile
--- secure/usr.bin/sftp/Makefile	2002/01/23 15:54:10	1.2
+++ secure/usr.bin/sftp/Makefile	2002/02/05 16:10:23
@@ -4,8 +4,8 @@
 PROG=	sftp
 SRCS=   sftp.c sftp-client.c sftp-int.c sftp-common.c sftp-glob.c scp-common.c
 
-LDADD+=	-lssh -lcrypto -lz
-DPADD+=	${LIBSSH} ${LIBCRYPTO} ${LIBZ}
+LDADD=	-lssh -lcrypto
+DPADD=	${LIBSSH} ${LIBCRYPTO}
 
 .include <bsd.prog.mk>
 
Index: secure/usr.bin/ssh-add/Makefile
===================================================================
RCS file: /home/ncvs/src/secure/usr.bin/ssh-add/Makefile,v
retrieving revision 1.6
diff -u -r1.6 Makefile
--- secure/usr.bin/ssh-add/Makefile	2002/01/23 15:54:14	1.6
+++ secure/usr.bin/ssh-add/Makefile	2002/02/05 16:10:23
@@ -4,8 +4,8 @@
 PROG=	ssh-add
 SRCS=	ssh-add.c
 
-LDADD+=	-lssh -lcrypto -lz
-DPADD+= ${LIBSSH} ${LIBCRYPTO} ${LIBZ}
+LDADD+=	-lssh -lcrypto
+DPADD+= ${LIBSSH} ${LIBCRYPTO}
 
 .include <bsd.prog.mk>
 
Index: secure/usr.bin/ssh-agent/Makefile
===================================================================
RCS file: /home/ncvs/src/secure/usr.bin/ssh-agent/Makefile,v
retrieving revision 1.6
diff -u -r1.6 Makefile
--- secure/usr.bin/ssh-agent/Makefile	2002/01/23 15:54:14	1.6
+++ secure/usr.bin/ssh-agent/Makefile	2002/02/05 16:10:23
@@ -4,8 +4,8 @@
 PROG=	ssh-agent
 SRCS=	ssh-agent.c
 
-LDADD+=	-lssh -lcrypto -lz
-DPADD+=	${LIBSSH} ${LIBCRYPTO} ${LIBZ}
+LDADD+=	-lssh -lcrypto
+DPADD+=	${LIBSSH} ${LIBCRYPTO}
 
 .include <bsd.prog.mk>
 
Index: secure/usr.bin/ssh-keygen/Makefile
===================================================================
RCS file: /home/ncvs/src/secure/usr.bin/ssh-keygen/Makefile,v
retrieving revision 1.7
diff -u -r1.7 Makefile
--- secure/usr.bin/ssh-keygen/Makefile	2002/01/23 15:54:17	1.7
+++ secure/usr.bin/ssh-keygen/Makefile	2002/02/05 16:10:23
@@ -4,8 +4,8 @@
 PROG=	ssh-keygen
 SRCS=	ssh-keygen.c
 
-LDADD+=	-lssh -lcrypto -lz
-DPADD+=	${LIBSSH} ${LIBCRYPTO} ${LIBZ}
+LDADD+=	-lssh -lcrypto
+DPADD+=	${LIBSSH} ${LIBCRYPTO}
 
 .include <bsd.prog.mk>
 
Index: secure/usr.bin/ssh-keyscan/Makefile
===================================================================
RCS file: /home/ncvs/src/secure/usr.bin/ssh-keyscan/Makefile,v
retrieving revision 1.2
diff -u -r1.2 Makefile
--- secure/usr.bin/ssh-keyscan/Makefile	2002/01/23 15:54:17	1.2
+++ secure/usr.bin/ssh-keyscan/Makefile	2002/02/05 16:10:23
@@ -4,8 +4,8 @@
 PROG=	ssh-keyscan
 SRCS=	ssh-keyscan.c
 
-LDADD+=	-lssh -lcrypto -lz
-DPADD+=	${LIBSSH} ${LIBCRYPTO} ${LIBZ}
+LDADD+=	-lssh -lcrypto
+DPADD+=	${LIBSSH} ${LIBCRYPTO}
 
 .include <bsd.prog.mk>
 

--tKW2IUtsqtDRztdT--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-alpha" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020205182731.A57843>