Subject: bug#27510: On FreeBSD 9.2 and later, shlibpath does not override runpath

From: Emmanuel Thomé <[email-masked]>
Date: Tue, 27 Jun 2017 23:18:14 +0200

Hi,

Since the following change to the FreeBSD dynamic linker (in 2012):

https://github.com/freebsd/freebsd/commit/a78a2e3c36e31109393e2a502b2f8f54f3a7f8d0

the LD_LIBRARY_PATH variable no longer takes precedence over the rpath.
Earliest released versions affected are freebsd 9.2 and dragonfly bsd
9.2.0.

As a result, an installed lib may take precedence over the one in the
source tree.

In order to have the behaviour that existed on freebsd from 4.6 to 9.1,
it seems that the enviroment variable LD_LIBRARY_PATH_RPATH must be set
to 1.

An alternative could be to force the freebsd dynamic linker to emit
DT_RUNPATH instead of DT_RPATH tags by default, using
-Wl,--enable-new-dtags  (the current release, freebsd-11.0 has
ld-2.17.50, dated 2007-07-30: it does not generate new dtags by default).

A third option is to make libtool recognize freebsd and dragonfly bsd
after the commit above as shlibpath_overrides_runpath=no.

All three options provide a cure to the problem I'm facing. I've
implemented the third directly on libtool HEAD (patch attached). This has
the effect that the following test suite items now pass, while they were
failing previously.

 35: binary relinking at install time                FAILED (demo.at:759)
 53: binary relinking at install time                FAILED (depdemo.at:408)
 69: shlibpath_overrides_runpath                     FAILED (shlibpath.at:66)
 86: cwrapper and installed shared libraries         FAILED (cwrapper.at:256)

I'm attaching the tests/testsuite.dir/NNN/testsuite.log files for these
four failing tests on the unpatched libtool.

I don't know which is the "right" fix.

Best regards.

E.
>From 70e520f08773beed6c49c5bf70883cf5c3c69e08 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Emmanuel=20Thom=C3=A9?= <[email-masked]>
Date: Tue, 27 Jun 2017 23:09:23 +0200
Subject: [PATCH] shlibpath_overrides_runpath=no for freebsd 9.2+ and dragonfly
 3.2.0+

LD_LIBRARY_PATH no longer takes precedence over rpath for these releases.

dragonfly bsd commit is 4f0bc915b65fcf5a23214f6d221d65c80be68ad4
---
 m4/libtool.m4 | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/m4/libtool.m4 b/m4/libtool.m4
index 597c6042..7d971b8c 100644
--- a/m4/libtool.m4
+++ b/m4/libtool.m4
@@ -2715,10 +2715,19 @@ freebsd* | dragonfly*)
     shlibpath_overrides_runpath=no
     hardcode_into_libs=yes
     ;;
-  *) # from 4.6 on, and DragonFly
+  freebsd4.[[6-9]] | freebsd4.10 | freebsd4.11 | \
+  freebsd[[5-8]].* | \
+  freebsd9.[[0-1]] | \
+  dragonfly[[1-2]].* | \
+  dragonfly3.0*)
     shlibpath_overrides_runpath=yes
     hardcode_into_libs=yes
     ;;
+  *) # Since FreeBSD 9.2 and DragonFly 3.2.0
+    # In fact, we could also use LD_LIBRARY_PATH_RPATH=1.
+    shlibpath_overrides_runpath=no
+    hardcode_into_libs=yes
+    ;;
   esac
   ;;
 
-- 
2.13.0