Skip to content

Commit

Permalink
GNU: use -Wl,-rpath,<dir> instead of -Wl,-R<dir>
Browse files Browse the repository at this point in the history
The latter is supported in binutils for backwards compatibility, but in
general `-R<path>` is equivalent to `--just-symbols=<path>` when `path`
is a file; only when it's a directory, it's treated as `-rpath=<path>`.

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.
  • Loading branch information
haampie committed Sep 26, 2023
1 parent 5a8ca1b commit a131f83
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
5 changes: 4 additions & 1 deletion distutils/tests/test_unixccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
13 changes: 7 additions & 6 deletions distutils/unixccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit a131f83

Please sign in to comment.