Skip to content

Commit

Permalink
linkers: Fix RSP syntax for linkers invoked with clang
Browse files Browse the repository at this point in the history
Fixes: mesonbuild#8981
Fixes: 2be074b
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
  • Loading branch information
kasper93 authored and eli-schwartz committed Aug 7, 2024
1 parent 3702b4b commit 43b80e0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
15 changes: 12 additions & 3 deletions mesonbuild/linkers/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from __future__ import annotations

from .base import RSPFileSyntax
from .. import mlog
from ..mesonlib import (
EnvironmentException,
Expand Down Expand Up @@ -40,6 +41,11 @@ def guess_win_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty
from . import linkers
env.coredata.add_lang_args(comp_class.language, comp_class, for_machine, env)

if invoked_directly or comp_class.get_argument_syntax() == 'msvc':
rsp_syntax = RSPFileSyntax.MSVC
else:
rsp_syntax = RSPFileSyntax.GCC

# Explicitly pass logo here so that we can get the version of link.exe
if not use_linker_prefix or comp_class.LINKER_PREFIX is None:
check_args = ['/logo', '--version']
Expand Down Expand Up @@ -71,7 +77,8 @@ def guess_win_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty
elif not invoked_directly:
return linkers.ClangClDynamicLinker(
for_machine, override, exelist=compiler, prefix=comp_class.LINKER_PREFIX,
version=search_version(o), direct=False, machine=None)
version=search_version(o), direct=False, machine=None,
rsp_syntax=rsp_syntax)

if value is not None and invoked_directly:
compiler = value
Expand All @@ -82,7 +89,8 @@ def guess_win_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty
return linkers.ClangClDynamicLinker(
for_machine, [],
prefix=comp_class.LINKER_PREFIX if use_linker_prefix else [],
exelist=compiler, version=search_version(o), direct=invoked_directly)
exelist=compiler, version=search_version(o), direct=invoked_directly,
rsp_syntax=rsp_syntax)
elif 'OPTLINK' in o:
# Optlink's stdout *may* begin with a \r character.
return linkers.OptlinkDynamicLinker(compiler, for_machine, version=search_version(o))
Expand All @@ -97,7 +105,8 @@ def guess_win_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty
return linkers.MSVCDynamicLinker(
for_machine, [], machine=target, exelist=compiler,
prefix=comp_class.LINKER_PREFIX if use_linker_prefix else [],
version=search_version(out), direct=invoked_directly)
version=search_version(out), direct=invoked_directly,
rsp_syntax=rsp_syntax)
elif 'GNU coreutils' in o:
import shutil
fullpath = shutil.which(compiler[0])
Expand Down
16 changes: 10 additions & 6 deletions mesonbuild/linkers/linkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1274,11 +1274,13 @@ def _apply_prefix(self, arg: T.Union[str, T.List[str]]) -> T.List[str]: ...

def __init__(self, exelist: T.List[str], for_machine: mesonlib.MachineChoice,
prefix_arg: T.Union[str, T.List[str]], always_args: T.List[str], *,
version: str = 'unknown version', direct: bool = True, machine: str = 'x86'):
version: str = 'unknown version', direct: bool = True, machine: str = 'x86',
rsp_syntax: RSPFileSyntax = RSPFileSyntax.MSVC):
# There's no way I can find to make mypy understand what's going on here
super().__init__(exelist, for_machine, prefix_arg, always_args, version=version)
self.machine = machine
self.direct = direct
self.rsp_syntax = rsp_syntax

def invoked_by_compiler(self) -> bool:
return not self.direct
Expand Down Expand Up @@ -1322,7 +1324,7 @@ def import_library_args(self, implibname: str) -> T.List[str]:
return self._apply_prefix(['/IMPLIB:' + implibname])

def rsp_file_syntax(self) -> RSPFileSyntax:
return RSPFileSyntax.MSVC
return self.rsp_syntax


class MSVCDynamicLinker(VisualStudioLikeLinkerMixin, DynamicLinker):
Expand All @@ -1335,9 +1337,10 @@ def __init__(self, for_machine: mesonlib.MachineChoice, always_args: T.List[str]
exelist: T.Optional[T.List[str]] = None,
prefix: T.Union[str, T.List[str]] = '',
machine: str = 'x86', version: str = 'unknown version',
direct: bool = True):
direct: bool = True, rsp_syntax: RSPFileSyntax = RSPFileSyntax.MSVC):
super().__init__(exelist or ['link.exe'], for_machine,
prefix, always_args, machine=machine, version=version, direct=direct)
prefix, always_args, machine=machine, version=version, direct=direct,
rsp_syntax=rsp_syntax)

def get_always_args(self) -> T.List[str]:
return self._apply_prefix(['/release']) + super().get_always_args()
Expand All @@ -1359,9 +1362,10 @@ def __init__(self, for_machine: mesonlib.MachineChoice, always_args: T.List[str]
exelist: T.Optional[T.List[str]] = None,
prefix: T.Union[str, T.List[str]] = '',
machine: str = 'x86', version: str = 'unknown version',
direct: bool = True):
direct: bool = True, rsp_syntax: RSPFileSyntax = RSPFileSyntax.MSVC):
super().__init__(exelist or ['lld-link.exe'], for_machine,
prefix, always_args, machine=machine, version=version, direct=direct)
prefix, always_args, machine=machine, version=version, direct=direct,
rsp_syntax=rsp_syntax)

def get_output_args(self, outputname: str) -> T.List[str]:
# If we're being driven indirectly by clang just skip /MACHINE
Expand Down

0 comments on commit 43b80e0

Please sign in to comment.