From a131f83e2967514e2973fb36f2ca64e3ac8efc3c Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Tue, 26 Sep 2023 11:23:08 +0200 Subject: [PATCH 1/3] GNU: use -Wl,-rpath, instead of -Wl,-R The latter is supported in binutils for backwards compatibility, but in general `-R` is equivalent to `--just-symbols=` when `path` is a file; only when it's a directory, it's treated as `-rpath=`. Better avoid that ambiguity and use `-rpath`. Also split `-Wl,--enable-new-dtags` and `-Wl,-rpath,...` into two separate arguments, which is more common, and more likely to be parsed correctly by compiler wrappers. This commit does not attempt to add `--enable-new-dtags` to other linkers than binutils ld/gold that support the flag. --- distutils/tests/test_unixccompiler.py | 5 ++++- distutils/unixccompiler.py | 13 +++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/distutils/tests/test_unixccompiler.py b/distutils/tests/test_unixccompiler.py index a0184424..23b4eb5a 100644 --- a/distutils/tests/test_unixccompiler.py +++ b/distutils/tests/test_unixccompiler.py @@ -186,7 +186,10 @@ def gcv(v): return 'yes' sysconfig.get_config_var = gcv - assert self.cc.rpath_foo() == '-Wl,--enable-new-dtags,-R/foo' + assert self.cc.rpath_foo() == [ + '-Wl,--enable-new-dtags', + '-Wl,-rpath,/foo' + ] # non-GCC GNULD sys.platform = 'bar' diff --git a/distutils/unixccompiler.py b/distutils/unixccompiler.py index 6ca2332a..d5c24596 100644 --- a/distutils/unixccompiler.py +++ b/distutils/unixccompiler.py @@ -311,13 +311,14 @@ def runtime_library_dir_option(self, dir): "-L" + dir, ] - # For all compilers, `-Wl` is the presumed way to - # pass a compiler option to the linker and `-R` is - # the way to pass an RPATH. + # For all compilers, `-Wl` is the presumed way to pass a + # compiler option to the linker if sysconfig.get_config_var("GNULD") == "yes": - # GNU ld needs an extra option to get a RUNPATH - # instead of just an RPATH. - return "-Wl,--enable-new-dtags,-R" + dir + return [ + # Force RUNPATH instead of RPATH + "-Wl,--enable-new-dtags", + "-Wl,-rpath," + dir + ] else: return "-Wl,-R" + dir From 0136c373d4be1a7cfee4683d77d659a7a5dff832 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 13 Feb 2024 11:01:51 -0500 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=91=B9=20Feed=20the=20hobgoblins=20(d?= =?UTF-8?q?elint).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- distutils/tests/test_unixccompiler.py | 2 +- distutils/unixccompiler.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/distutils/tests/test_unixccompiler.py b/distutils/tests/test_unixccompiler.py index e8c34ce6..62efce43 100644 --- a/distutils/tests/test_unixccompiler.py +++ b/distutils/tests/test_unixccompiler.py @@ -189,7 +189,7 @@ def gcv(v): sysconfig.get_config_var = gcv assert self.cc.rpath_foo() == [ '-Wl,--enable-new-dtags', - '-Wl,-rpath,/foo' + '-Wl,-rpath,/foo', ] # non-GCC GNULD diff --git a/distutils/unixccompiler.py b/distutils/unixccompiler.py index b676a6a8..d749fe25 100644 --- a/distutils/unixccompiler.py +++ b/distutils/unixccompiler.py @@ -316,7 +316,7 @@ def runtime_library_dir_option(self, dir): return [ # Force RUNPATH instead of RPATH "-Wl,--enable-new-dtags", - "-Wl,-rpath," + dir + "-Wl,-rpath," + dir, ] else: return "-Wl,-R" + dir From 91cb3279ec9c17d00c5d8b823aa8f3b65bd9f76e Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 13 Feb 2024 13:15:51 -0500 Subject: [PATCH 3/3] Update more tests to match the new expectation. --- distutils/tests/test_unixccompiler.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/distutils/tests/test_unixccompiler.py b/distutils/tests/test_unixccompiler.py index 62efce43..a313da3e 100644 --- a/distutils/tests/test_unixccompiler.py +++ b/distutils/tests/test_unixccompiler.py @@ -153,7 +153,10 @@ def gcv(v): return 'yes' sysconfig.get_config_var = gcv - assert self.cc.rpath_foo() == '-Wl,--enable-new-dtags,-R/foo' + assert self.cc.rpath_foo() == [ + '-Wl,--enable-new-dtags', + '-Wl,-rpath,/foo', + ] def gcv(v): if v == 'CC': @@ -162,7 +165,10 @@ def gcv(v): return 'yes' sysconfig.get_config_var = gcv - assert self.cc.rpath_foo() == '-Wl,--enable-new-dtags,-R/foo' + assert self.cc.rpath_foo() == [ + '-Wl,--enable-new-dtags', + '-Wl,-rpath,/foo', + ] # GCC non-GNULD sys.platform = 'bar' @@ -202,7 +208,10 @@ def gcv(v): return 'yes' sysconfig.get_config_var = gcv - assert self.cc.rpath_foo() == '-Wl,--enable-new-dtags,-R/foo' + assert self.cc.rpath_foo() == [ + '-Wl,--enable-new-dtags', + '-Wl,-rpath,/foo', + ] # non-GCC non-GNULD sys.platform = 'bar'