Browse Source

Revert "Add `-Wl,-rpath-link` for secondary dependencies"

This reverts commit 7b9c348102.

Closes #6027.
Jussi Pakkanen 1 month ago
parent
commit
2a73517e08

+ 5
- 48
mesonbuild/dependencies/base.py View File

@@ -33,7 +33,6 @@ from .. import mesonlib
33 33
 from ..compilers import clib_langs
34 34
 from ..environment import BinaryTable, Environment, MachineInfo
35 35
 from ..cmake import CMakeExecutor, CMakeTraceParser, CMakeException
36
-from ..linkers import GnuLikeDynamicLinkerMixin
37 36
 from ..mesonlib import MachineChoice, MesonException, OrderedSet, PerMachine
38 37
 from ..mesonlib import Popen_safe, version_compare_many, version_compare, listify, stringlistify, extract_as_list, split_args
39 38
 from ..mesonlib import Version, LibType
@@ -748,18 +747,16 @@ class PkgConfigDependency(ExternalDependency):
748 747
                                       (self.name, err))
749 748
         self.compile_args = self._convert_mingw_paths(self._split_args(out))
750 749
 
751
-    def _search_libs(self, out, out_raw, out_all):
750
+    def _search_libs(self, out, out_raw):
752 751
         '''
753 752
         @out: PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 pkg-config --libs
754 753
         @out_raw: pkg-config --libs
755
-        @out_all: pkg-config --libs --static
756 754
 
757 755
         We always look for the file ourselves instead of depending on the
758 756
         compiler to find it with -lfoo or foo.lib (if possible) because:
759 757
         1. We want to be able to select static or shared
760 758
         2. We need the full path of the library to calculate RPATH values
761 759
         3. De-dup of libraries is easier when we have absolute paths
762
-        4. We need to find the directories in which secondary dependencies reside
763 760
 
764 761
         Libraries that are provided by the toolchain or are not found by
765 762
         find_library() will be added with -L -l pairs.
@@ -793,18 +790,6 @@ class PkgConfigDependency(ExternalDependency):
793 790
                 continue
794 791
             if arg.startswith('-L') and arg[2:] not in prefix_libpaths:
795 792
                 system_libpaths.add(arg[2:])
796
-        # collect all secondary library paths
797
-        secondary_libpaths = OrderedSet()
798
-        all_args = self._convert_mingw_paths(shlex.split(out_all))
799
-        for arg in all_args:
800
-            if arg.startswith('-L') and not arg.startswith(('-L-l', '-L-L')):
801
-                path = arg[2:]
802
-                if not os.path.isabs(path):
803
-                    # Resolve the path as a compiler in the build directory would
804
-                    path = os.path.join(self.env.get_build_dir(), path)
805
-                if path not in prefix_libpaths and path not in system_libpaths:
806
-                    secondary_libpaths.add(path)
807
-
808 793
         # Use this re-ordered path list for library resolution
809 794
         libpaths = list(prefix_libpaths) + list(system_libpaths)
810 795
         # Track -lfoo libraries to avoid duplicate work
@@ -812,12 +797,8 @@ class PkgConfigDependency(ExternalDependency):
812 797
         # Track not-found libraries to know whether to add library paths
813 798
         libs_notfound = []
814 799
         libtype = LibType.STATIC if self.static else LibType.PREFER_SHARED
815
-        # Generate link arguments for this library, by
816
-        # first appending secondary link arguments for ld
800
+        # Generate link arguments for this library
817 801
         link_args = []
818
-        if self.clib_compiler and self.clib_compiler.linker and isinstance(self.clib_compiler.linker, GnuLikeDynamicLinkerMixin):
819
-            link_args = ['-Wl,-rpath-link,' + p for p in secondary_libpaths]
820
-
821 802
         for lib in full_args:
822 803
             if lib.startswith(('-L-l', '-L-L')):
823 804
                 # These are D language arguments, add them as-is
@@ -887,26 +868,6 @@ class PkgConfigDependency(ExternalDependency):
887 868
         libcmd = [self.name, '--libs']
888 869
         if self.static:
889 870
             libcmd.append('--static')
890
-        # We need to find *all* secondary dependencies of a library
891
-        #
892
-        # Say we have libA.so, located in /non/standard/dir1/, and
893
-        # libB.so, located in /non/standard/dir2/, which links to
894
-        # libA.so. Now when linking exeC to libB.so, the linker will
895
-        # walk the complete symbol tree to determine that all undefined
896
-        # symbols can be resolved. Because libA.so lives in a directory
897
-        # not known to the linker by default, you will get errors like
898
-        #
899
-        #   ld: warning: libA.so, needed by /non/standard/dir2/libB.so,
900
-        #       not found (try using -rpath or -rpath-link)
901
-        #   ld: /non/standard/dir2/libB.so: undefined reference to `foo()'
902
-        #
903
-        # To solve this, we load the -L paths of *all* dependencies, by
904
-        # relying on --static to provide us with a complete picture. All
905
-        # -L paths that are found via a --static lookup but that are not
906
-        # contained in the normal lookup have to originate from secondary
907
-        # dependencies. See also:
908
-        #   http://www.kaizou.org/2015/01/linux-libraries/
909
-        libcmd_all = [self.name, '--libs', '--static']
910 871
         # Force pkg-config to output -L fields even if they are system
911 872
         # paths so we can do manual searching with cc.find_library() later.
912 873
         env = os.environ.copy()
@@ -920,13 +881,9 @@ class PkgConfigDependency(ExternalDependency):
920 881
         # gnome.generate_gir + gnome.gtkdoc which need -L -l arguments.
921 882
         ret, out_raw, err_raw = self._call_pkgbin(libcmd)
922 883
         if ret != 0:
923
-            raise DependencyException('Could not generate libs for %s:\n%s\n' %
924
-                                      (self.name, err_raw))
925
-        ret, out_all, err_all = self._call_pkgbin(libcmd_all)
926
-        if ret != 0:
927
-            mlog.warning('Could not determine complete list of dependencies for %s:\n%s\n' %
928
-                         (self.name, err_all))
929
-        self.link_args, self.raw_link_args = self._search_libs(out, out_raw, out_all)
884
+            raise DependencyException('Could not generate libs for %s:\n\n%s' %
885
+                                      (self.name, out_raw))
886
+        self.link_args, self.raw_link_args = self._search_libs(out, out_raw)
930 887
 
931 888
     def get_pkgconfig_variable(self, variable_name, kwargs):
932 889
         options = ['--variable=' + variable_name, self.name]

+ 0
- 39
run_unittests.py View File

@@ -5465,45 +5465,6 @@ class LinuxlikeTests(BasePlatformTests):
5465 5465
                       override_envvars={'PKG_CONFIG_PATH': pkg_dir})
5466 5466
             self.build()
5467 5467
 
5468
-    @skipIfNoPkgconfig
5469
-    def test_pkgconfig_secondary_dependencies(self):
5470
-        '''
5471
-        Check that Meson gets -Wl,-rpath-link right for secondary dependencies
5472
-
5473
-        This test requires at least two libraries, as -Wl,-rpath-link is only
5474
-        required for dependencies of dependencies (i.e. secondary dependencies).
5475
-        '''
5476
-        with tempfile.TemporaryDirectory() as tempdirname:
5477
-            testdirbase = os.path.join(self.unit_test_dir, '67 rpath-link secondary')
5478
-
5479
-            # build libA
5480
-            testdirlibA = os.path.join(testdirbase, 'libA')
5481
-            testlibAprefix = os.path.join(tempdirname, 'libAprefix')
5482
-            self.init(testdirlibA, extra_args=['--prefix=' + testlibAprefix,
5483
-                                               '--libdir=lib',
5484
-                                               '--default-library=shared'], default_args=False)
5485
-            self.build()
5486
-            self.install(use_destdir=False)
5487
-
5488
-            # build libB (uses libA)
5489
-            pkg_dir = [os.path.join(testlibAprefix, 'lib/pkgconfig')]
5490
-            self.new_builddir()
5491
-            testdirlibB = os.path.join(testdirbase, 'libB')
5492
-            testlibBprefix = os.path.join(tempdirname, 'libBprefix')
5493
-            self.init(testdirlibB, extra_args=['--prefix=' + testlibBprefix,
5494
-                                               '--libdir=lib',
5495
-                                               '--default-library=shared'], default_args=False,
5496
-                      override_envvars={'PKG_CONFIG_PATH': ':'.join(pkg_dir)})
5497
-            self.build()
5498
-            self.install(use_destdir=False)
5499
-
5500
-            # build executable (uses libB, secondary dependency on libA)
5501
-            pkg_dir.append(os.path.join(testlibBprefix, 'lib/pkgconfig'))
5502
-            self.new_builddir()
5503
-            self.init(os.path.join(testdirbase, 'app'),
5504
-                      override_envvars={'PKG_CONFIG_PATH': ':'.join(pkg_dir)})
5505
-            self.build()
5506
-
5507 5468
     @skipIfNoPkgconfig
5508 5469
     def test_static_archive_stripping(self):
5509 5470
         '''

+ 0
- 4
test cases/unit/67 rpath-link secondary/app/app.c View File

@@ -1,4 +0,0 @@
1
-#include <stdio.h>
2
-#include <libb.h>
3
-
4
-int main() { printf("The answer is: %d\n", libB_func()); }

+ 0
- 5
test cases/unit/67 rpath-link secondary/app/meson.build View File

@@ -1,5 +0,0 @@
1
-project('app', ['c'])
2
-
3
-b = dependency('test-b')
4
-
5
-executable('app', 'app.c', dependencies : [b])

+ 0
- 1
test cases/unit/67 rpath-link secondary/libA/liba.c View File

@@ -1 +0,0 @@
1
-int libA_func() { return 42; }

+ 0
- 1
test cases/unit/67 rpath-link secondary/libA/liba.h View File

@@ -1 +0,0 @@
1
-int libA_func();

+ 0
- 14
test cases/unit/67 rpath-link secondary/libA/meson.build View File

@@ -1,14 +0,0 @@
1
-project('lib', ['c'])
2
-
3
-a = library('test-a', 'liba.c', install: true)
4
-
5
-install_headers(files('liba.h'))
6
-
7
-import('pkgconfig').generate(
8
-    a,
9
-    version: '0.0',
10
-    description: 'test library',
11
-    filebase: 'test-a',
12
-    name: 'test library',
13
-    subdirs: ['.']
14
-)

+ 0
- 3
test cases/unit/67 rpath-link secondary/libB/libb.c View File

@@ -1,3 +0,0 @@
1
-#include <liba.h>
2
-
3
-int libB_func() { return libA_func(); }

+ 0
- 1
test cases/unit/67 rpath-link secondary/libB/libb.h View File

@@ -1 +0,0 @@
1
-int libB_func();

+ 0
- 16
test cases/unit/67 rpath-link secondary/libB/meson.build View File

@@ -1,16 +0,0 @@
1
-project('lib', ['c'])
2
-
3
-libA_dep = dependency('test-a')
4
-
5
-b = library('test-b', 'libb.c', install: true, dependencies : libA_dep)
6
-
7
-install_headers(files('libb.h'))
8
-
9
-import('pkgconfig').generate(
10
-    b,
11
-    version: '0.0',
12
-    description: 'test library',
13
-    filebase: 'test-b',
14
-    name: 'test library',
15
-    subdirs: ['.']
16
-)

Loading…
Cancel
Save