wafsamba: fix ordering problems with lib-provided and internal RPATHs
authorStefan Metzmacher <metze@samba.org>
Thu, 18 Dec 2014 17:09:15 +0000 (18:09 +0100)
committerMichael Adam <obnox@samba.org>
Mon, 22 Dec 2014 08:51:46 +0000 (09:51 +0100)
When a library or system (like cups) provides an RPATH,
e.g. with -Wl,-R or -Wl,-rpath, this was added by waf
to the LINKFLAGS, wich was later prepended to our RPATH.
But if the path by chance contains an older version of
one of our internal libraries like talloc, this would lead
to linking the too old talloc into our binaries.

This has been observed on, e.g., FreeBSD, but it is a general
problem.

This patch fixes the problem by specially parsing the RPATH
linker options from the pkg-config(, cups-config, ....) output
and putting the paths into the RPATH_<lib> container, which
is then later correctly appended to our internal RPATH.

This is a better fix than commit 64f5e24100a764ec198cab9a8d2c43fa86e7027c
as it touches wafsamba only. We can revert
64f5e24100a764ec198cab9a8d2c43fa86e7027c in the following commit.

Bug: https://bugzilla.samba.org/show_bug.cgi?id=10548

Signed-off-by: Stefan Metzmacher <metze@samba.org>
buildtools/wafsamba/samba_conftests.py

index ec98ba0d7eea550aa95aee37aa8d9f8283b1db43..f94b0b7ca8ce628dcec3cdc725d59b05ae5a0c3b 100644 (file)
@@ -4,6 +4,7 @@
 import os, shutil, re
 import Build, Configure, Utils
 from Configure import conf
+import config_c
 from samba_utils import *
 
 
@@ -506,3 +507,37 @@ def CHECK_XSLTPROC_MANPAGES(conf):
     if not conf.CONFIG_SET('XSLTPROC_MANPAGES'):
         print "A local copy of the docbook.xsl wasn't found on your system" \
               " consider installing package like docbook-xsl"
+
+
+waf_config_c_parse_flags = config_c.parse_flags;
+def samba_config_c_parse_flags(line, uselib, env):
+    waf_config_c_parse_flags(line, uselib, env)
+
+    try:
+        linkflags = env['LINKFLAGS_' + uselib]
+    except KeyError:
+        linkflags = []
+    for x in linkflags:
+        #
+        # NOTE on special treatment of -Wl,-R and -Wl,-rpath:
+        #
+        # It is important to not put a library provided RPATH
+        # into the LINKFLAGS but in the RPATH instead, since
+        # the provided LINKFLAGS get prepended to our own internal
+        # RPATH later, and hence can potentially lead to linking
+        # in too old versions of our internal libs.
+        #
+        if x.startswith('-Wl,-R,'):
+            rpath = x[7:]
+        elif x.startswith('-Wl,-R'):
+            rpath = x[6:]
+        elif x.startswith('-Wl,-rpath,'):
+            rpath = x[11:]
+        else:
+            continue
+
+        env.append_value('RPATH_' + uselib, rpath)
+        linkflags.remove(x)
+
+    return
+config_c.parse_flags = samba_config_c_parse_flags