From d768a76ab21f01fe34119d79d5b4b580d9fe564f Mon Sep 17 00:00:00 2001 From: Andrei Alexeyev Date: Tue, 10 Sep 2019 15:44:53 +0300 Subject: [PATCH] Workaround for mingw-llvm linker (lld) misdetection llvm-mingw uses a wrapper script to inject (among other things) a -target argument into the clang command, which breaks -Wl,--version. This confuses Meson into thinking the linker is some unknown version of Apple ld, which breaks builds. This patch makes it detect and recover from the issue. Fixes #5910 --- mesonbuild/environment.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index bd80fbe10..b3885b6ed 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -14,6 +14,7 @@ import os, platform, re, sys, shutil, subprocess, typing import tempfile +import shlex from . import coredata from .linkers import ArLinker, ArmarLinker, VisualStudioLinker, DLinker, CcrxLinker, IntelVisualStudioLinker @@ -708,6 +709,22 @@ class Environment: v = search_version(o) if o.startswith('LLD'): linker = LLVMDynamicLinker(compiler, for_machine, 'lld', prefix, version=v) # type: DynamicLinker + elif e.startswith('lld-link: '): + # Toolchain wrapper got in the way; this happens with e.g. https://github.com/mstorsjo/llvm-mingw + # Let's try to extract the linker invocation command to grab the version. + + _, o, e = Popen_safe(compiler + check_args + ['-v']) + + try: + linker_cmd = re.match(r'.*\n(.*?)\nlld-link: ', e, re.DOTALL).group(1) + linker_cmd = shlex.split(linker_cmd)[0] + except (AttributeError, IndexError, ValueError): + pass + else: + _, o, e = Popen_safe([linker_cmd, '--version']) + v = search_version(o) + + linker = LLVMDynamicLinker(compiler, for_machine, 'lld', prefix, version=v) # first is for apple clang, second is for real gcc elif e.endswith('(use -v to see invocation)\n') or 'macosx_version' in e: if isinstance(prefix, str):