On Thu, 5 Dec 2019 03:20:19 -0500
Jeffrey Walton <noloa...@gmail.com> wrote:

> On Thu, Dec 5, 2019 at 3:08 AM Niels Möller <ni...@lysator.liu.se> wrote:
> > ...
> >
> > Does OpenBSBs runtime linker look in /usr/local/lib by default? The
> > configure script also supports --with-lib-path=/usr/local/lib, which
> > will add a -L flag and in addition attempt to guess the proper
> > -R/-Wl,-rpath flags.
> 
> The runtime linker is configured to use /usr/local/lib. However,
> compile and link requires explicit -I /usr/local/include and -L
> /usr/local/lib to find things.
> 
> (Based on my testing of DragonFly, FreeBSD, OpenBSD and NetBSD. I
> don't recall what Debian's kFreeBSD does).
> 
> Jeff

Each BSD has its own runtime linker.  I believe that OpenBSD ld.so(1)
looks in /usr/local/lib by default, but NetBSD ld.elf_so(1) doesn't
look there.

For OpenBSD, ldconfig(8) sets the runtime path.  It always looks in
/usr/lib, but /etc/rc tells ldconfig to also look in /usr/X11R6/lib
and /usr/local/lib.  I can get the path from ldconfig:

# OpenBSD
$ ldconfig -r | grep directories
        search directories: /usr/lib:/usr/X11R6/lib:/usr/local/lib

NetBSD allows /etc/ld.so.conf to add directories to the runtime path,
but my NetBSD install has no ld.so.conf, so the default path has only
/usr/lib.  Some executables have RPATH to look in /usr/X11R7/lib or
/usr/pkg/lib.  (My install has no /usr/local.)

For example, OpenBSD's xterm(1) doesn't need RPATH, but NetBSD's
xterm(1) needs RPATH with /usr/X11R7/lib.

# OpenBSD
$ readelf -d /usr/X11R6/bin/xterm | grep -E 'NEED|PATH'            
 0x00000001 (NEEDED)                     Shared library: [libXaw.so.15.0]
 0x00000001 (NEEDED)                     Shared library: [libXpm.so.9.0]
 0x00000001 (NEEDED)                     Shared library: [libXt.so.11.0]
 ...
 0x00000001 (NEEDED)                     Shared library: [libc.so.96.0]

# NetBSD
$ readelf -d /usr/X11R7/bin/xterm | grep -E 'NEED|PATH'
 0x00000001 (NEEDED)                     Shared library: [libXft.so.3]
 0x00000001 (NEEDED)                     Shared library: [libfontconfig.so.2]
 0x00000001 (NEEDED)                     Shared library: [libfreetype.so.18]
 ...
 0x00000001 (NEEDED)                     Shared library: [libc.so.12]
 0x0000000f (RPATH)                      Library rpath: [/usr/X11R7/lib]

If I don't set RPATH, I can't use /usr/X11R7/lib in NetBSD:

# OpenBSD
$ gcc -o code code.c -L/usr/X11R6/lib -lX11
...
$ ./code
It works!

# NetBSD
$ gcc -o code code.c -L/usr/X11R7/lib -lX11
$ ./code
Shared object "libX11.so.7" not found
$ gcc -o code code.c -L/usr/X11R7/lib -lX11 -R/usr/X11R7/lib
$ ./code
It works!

The NEEDED values on OpenBSD have an extra number: [libc.so.96.0]
instead of just [libc.so.96].  This is because OpenBSD has its different
version rule.

Other systems require M == X in
  SONAME libwhat.so.M    for  NEEDED libwhat.so.X
OpenBSD requires M == X && N >= Y in
  SONAME libwhat.so.M.N  for  NEEDED libwhat.so.X.Y
  https://www.openbsd.org/faq/ports/specialtopics.html#SharedLibs

Other systems have symbolic links:

# NetBSD
$ cd /usr/X11R7/lib
$ ls -l libX11.so*
lrwxr-xr-x  1 root  wheel       13 Jul 17  2018 libX11.so -> libX11.so.7.0
lrwxr-xr-x  1 root  wheel       13 Jul 17  2018 libX11.so.7 -> libX11.so.7.0
-r--r--r--  1 root  wheel  1273908 Jul 17  2018 libX11.so.7.0

OpenBSD doesn't have these links.  The compile-time ld(1) and run-time
ld.so(1) look for libraries named [libwhat.so.X.Y].

Nettle doesn't know OpenBSD's version rule.  My git checkout of Nettle,
configured for OpenBSD, wants to install [libnettle.so.7.0] with
symlinks from [libnettle.so] and [libnettle.so.7], where the SONAME is
[libnettle.so.7].  To obey the version rule, it should install
[libnettle.so.7.0] without symlinks, and the SONAME should also be
[libnettle.so.7.0].  I didn't fix my git checkout to obey the version
rule, because I didn't need to.

I know one other quirk: some build tools (but not Nettle's) use
$ORIGIN in the runtime path.  DragonFly and OpenBSD need a compiler
flag "cc -Wl,-z,origin" to enable $ORIGIN, but other systems don't
need this flag.
  https://github.com/mesonbuild/meson/pull/3530/files

This mail is too long; I stop now.  --George
_______________________________________________
nettle-bugs mailing list
nettle-bugs@lists.lysator.liu.se
http://lists.lysator.liu.se/mailman/listinfo/nettle-bugs

Reply via email to