From 0bb1e949e2c8dde6533b21b8d3dbb2b8a7facc64 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 12 Mar 2020 09:17:23 -0700 Subject: [PATCH 1/4] run_unittests: Use skip_if_not_language for linker tests A couple used checks for specific compiler binaries, but those might not be accurate for cross compiling. All the languages other than C and C++ (which we basically always assume we have) should have a skip_if_not_lang check. --- run_unittests.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/run_unittests.py b/run_unittests.py index f867f1c35..725906bcb 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -4990,6 +4990,7 @@ class WindowsTests(BasePlatformTests): def test_link_environment_variable_optlink(self): self._check_ld('optlink', 'c', 'optlink') + @skip_if_not_language('rust') def test_link_environment_variable_rust(self): self._check_ld('link', 'rust', 'link') @@ -6342,20 +6343,22 @@ c = ['{0}'] def test_ld_environment_variable_lld(self): self._check_ld('ld.lld', 'lld', 'c', 'ld.lld') - @skipIfNoExecutable('rustc') + @skip_if_not_language('rust') def test_ld_environment_variable_rust(self): self._check_ld('ld.gold', 'gold', 'rust', 'ld.gold') def test_ld_environment_variable_cpp(self): self._check_ld('ld.gold', 'gold', 'cpp', 'ld.gold') + @skip_if_not_language('objc') def test_ld_environment_variable_objc(self): self._check_ld('ld.gold', 'gold', 'objc', 'ld.gold') + @skip_if_not_language('objcpp') def test_ld_environment_variable_objcpp(self): self._check_ld('ld.gold', 'gold', 'objcpp', 'ld.gold') - @skipIfNoExecutable('gfortran') + @skip_if_not_language('fortran') def test_ld_environment_variable_fortran(self): self._check_ld('ld.gold', 'gold', 'fortran', 'ld.gold') From 2ac480a0bdd20537cb01c188f248ced4f171b406 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 12 Mar 2020 09:24:10 -0700 Subject: [PATCH 2/4] unittests: Add tests for overriding D linker language --- run_unittests.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/run_unittests.py b/run_unittests.py index 725906bcb..ee6ec7ec4 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -4994,6 +4994,14 @@ class WindowsTests(BasePlatformTests): def test_link_environment_variable_rust(self): self._check_ld('link', 'rust', 'link') + @skip_if_not_language('d') + def test_link_environment_variable_d(self): + env = get_fake_env() + comp = getattr(env, 'detect_d_compiler')(MachineChoice.HOST) + if comp.id == 'dmd': + raise unittest.SkipTest('meson cannot reliably make DMD use a different linker.') + self._check_ld('lld-link', 'd', 'lld-link') + def test_pefile_checksum(self): try: import pefile @@ -6362,6 +6370,12 @@ c = ['{0}'] def test_ld_environment_variable_fortran(self): self._check_ld('ld.gold', 'gold', 'fortran', 'ld.gold') + @skip_if_not_language('d') + def test_ld_environment_variable_d(self): + # At least for me, ldc defaults to gold, and gdc defaults to bfd, so + # let's pick lld, which isn't the default for either (currently) + self._check_ld('ld.lld', 'lld', 'd', 'ld.lld') + def compute_sha256(self, filename): with open(filename, 'rb') as f: return hashlib.sha256(f.read()).hexdigest() From 9c9dcbb1a836efacb44ac5effc0556ac4dd7fc1a Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 11 Mar 2020 16:50:44 -0700 Subject: [PATCH 3/4] compilers/d: Support linker selection with gdc This should have worked before, but the inheritance order was backwards, so we got the DCompiler before the GnuCompiler, and the base Compiler methods overrode the Gnu methods. --- mesonbuild/compilers/d.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py index 9a46a4ef6..eb3a0f39b 100644 --- a/mesonbuild/compilers/d.py +++ b/mesonbuild/compilers/d.py @@ -627,7 +627,7 @@ class DCompiler(Compiler): return ' '.join(self.exelist) -class GnuDCompiler(DCompiler, GnuCompiler): +class GnuDCompiler(GnuCompiler, DCompiler): # we mostly want DCompiler, but that gives us the Compiler.LINKER_PREFIX instead LINKER_PREFIX = GnuCompiler.LINKER_PREFIX From 20f8e472212d8aa11fdf073a4e04da65f3d702d5 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 12 Mar 2020 09:27:43 -0700 Subject: [PATCH 4/4] docs: Update documentation for GDC linker overriding --- docs/markdown/snippets/ldc_linker_override.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/markdown/snippets/ldc_linker_override.md b/docs/markdown/snippets/ldc_linker_override.md index fa124bab7..2eab9584f 100644 --- a/docs/markdown/snippets/ldc_linker_override.md +++ b/docs/markdown/snippets/ldc_linker_override.md @@ -1,5 +1,7 @@ -## Support for overiding the linker with ldc +## Support for overiding the linker with ldc and gdc -LDC (the llvm D compiler) now honors D_LD linker variable (or d_ld in the cross -file) and is able to pick differnt linkers. ld.bfd, ld.gold, ld.lld, ld64, -link, and lld-link are currently supported. +LDC (the llvm D compiler) and GDC (The Gnu D Compiler) now honor D_LD linker +variable (or d_ld in the cross file) and is able to pick differnt linkers. + +GDC supports all of the same values as GCC, LDC supports ld.bfd, ld.gold, +ld.lld, ld64, link, and lld-link.