summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlois Wohlschlager <alois1@gmx-topmail.de>2025-07-28 18:59:01 +0200
committerEli Schwartz <eschwartz93@gmail.com>2025-11-11 23:06:40 -0500
commit38786d8ac98f53a074008971da8fa328b64806f6 (patch)
tree80461e1f568edf5746d89b6dc95eb8dcca692c1f
parent1401b1d2bfe090750b52137dc57ca59ad00ca69b (diff)
downloadmeson-38786d8ac98f53a074008971da8fa328b64806f6.tar.gz
compilers: support prelinking with Clang
Clang supports prelinking using the same `-r` flag as GCC. There has been prior art in [1], which stalled at the time due to Clang inappropriately trying (and failing) to link libgcc_s. This issue does not occur any more with versions 14 and higher. [1] https://github.com/mesonbuild/meson/pull/8883
-rw-r--r--mesonbuild/compilers/mixins/clang.py5
-rw-r--r--unittests/linuxliketests.py7
2 files changed, 7 insertions, 5 deletions
diff --git a/mesonbuild/compilers/mixins/clang.py b/mesonbuild/compilers/mixins/clang.py
index cb7d66107..2c1e326bd 100644
--- a/mesonbuild/compilers/mixins/clang.py
+++ b/mesonbuild/compilers/mixins/clang.py
@@ -208,6 +208,11 @@ class ClangCompiler(GnuLikeCompiler):
# error.
return ['-Werror=attributes']
+ def get_prelink_args(self, prelink_name: str, obj_list: T.List[str]) -> T.Tuple[T.List[str], T.List[str]]:
+ if not mesonlib.version_compare(self.version, '>=14'):
+ raise mesonlib.MesonException('prelinking requires clang >=14')
+ return [prelink_name], ['-r', '-o', prelink_name] + obj_list
+
def get_coverage_link_args(self) -> T.List[str]:
return ['--coverage']
diff --git a/unittests/linuxliketests.py b/unittests/linuxliketests.py
index c9ba37118..60069acb5 100644
--- a/unittests/linuxliketests.py
+++ b/unittests/linuxliketests.py
@@ -1759,16 +1759,13 @@ class LinuxlikeTests(BasePlatformTests):
self.assertNotIn('-lfoo', content)
def test_prelinking(self):
- # Prelinking currently only works on recently new GNU toolchains.
- # Skip everything else. When support for other toolchains is added,
- # remove limitations as necessary.
- if 'clang' in os.environ.get('CC', 'dummy') and not is_osx():
- raise SkipTest('Prelinking not supported with Clang.')
testdir = os.path.join(self.unit_test_dir, '86 prelinking')
env = get_fake_env(testdir, self.builddir, self.prefix)
cc = detect_c_compiler(env, MachineChoice.HOST)
if cc.id == "gcc" and not version_compare(cc.version, '>=9'):
raise SkipTest('Prelinking not supported with gcc 8 or older.')
+ if cc.id == 'clang' and not version_compare(cc.version, '>=14'):
+ raise SkipTest('Prelinking not supported with Clang 13 or older.')
self.init(testdir)
self.build()
outlib = os.path.join(self.builddir, 'libprelinked.a')