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
: rpa