build: fix ordering problems with lib-provided and internal RPATHs
authorMichael Adam <obnox@samba.org>
Wed, 16 Oct 2013 13:17:18 +0000 (15:17 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 24 Oct 2013 22:55:14 +0000 (11:55 +1300)
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.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
buildtools/wafadmin/Tools/config_c.py

index a32d8aaf1ae956f59f91a9709a3d0c4bef32d593..d0bc61773625576cec1d0b1eec2635086d04c2e7 100644 (file)
@@ -73,6 +73,19 @@ def parse_flags(line, uselib, env):
                        app('CCFLAGS_' + uselib, x)
                        app('CXXFLAGS_' + uselib, x)
                        app('LINKFLAGS_' + uselib, x)
+               #
+               # 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.
+               #
+               elif x.startswith('-Wl,-R'):
+                       app('RPATH_' + uselib, x[6:])
+               elif x.startswith('-Wl,-rpath,'):
+                       app('RPATH_' + uselib, x[11:])
                elif x.startswith('-Wl'):
                        app('LINKFLAGS_' + uselib, x)
                elif x.startswith('-m') or x.startswith('-f'):