Skip to content

Commit cece1a7

Browse files
bonzinifreakboy3742
authored andcommitted
linkers: pass system to DynamicLinker.__init__ for Darwin linkers
Apple linkers need to use different arguments on macOS and iOS-like platforms. Pass the system to the constructor so that it can be examined. Co-authored-by: Russell Keith-Magee <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 48fc3ec commit cece1a7

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

mesonbuild/compilers/detect.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1122,8 +1122,8 @@ def detect_rust_compiler(env: 'Environment', for_machine: MachineChoice) -> Rust
11221122
version=cc.linker.version, **extra_args) # type: ignore
11231123
else:
11241124
linker = type(cc.linker)(compiler, for_machine, cc.LINKER_PREFIX,
1125-
always_args=always_args, version=cc.linker.version,
1126-
**extra_args)
1125+
always_args=always_args, system=cc.linker.system,
1126+
version=cc.linker.version, **extra_args)
11271127
elif 'link' in override[0]:
11281128
linker = guess_win_linker(env,
11291129
override, cls, version, for_machine, use_linker_prefix=False)

mesonbuild/linkers/detect.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def guess_nix_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty
131131
env.coredata.add_lang_args(comp_class.language, comp_class, for_machine, env)
132132
extra_args = extra_args or []
133133

134+
system = env.machines[for_machine].system
134135
ldflags = env.coredata.get_external_link_args(for_machine, comp_class.language)
135136
extra_args += comp_class._unix_args_to_native(ldflags, env.machines[for_machine])
136137

@@ -164,7 +165,7 @@ def guess_nix_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty
164165
lld_cls = linkers.LLVMDynamicLinker
165166

166167
linker = lld_cls(
167-
compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v)
168+
compiler, for_machine, comp_class.LINKER_PREFIX, override, system=system, version=v)
168169
elif 'Snapdragon' in e and 'LLVM' in e:
169170
linker = linkers.QualcommLLVMDynamicLinker(
170171
compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v)
@@ -222,7 +223,10 @@ def guess_nix_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty
222223
elif 'xtools-' in o.split('\n', maxsplit=1)[0]:
223224
xtools = o.split(' ', maxsplit=1)[0]
224225
v = xtools.split('-', maxsplit=2)[1]
225-
linker = linkers.AppleDynamicLinker(compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v)
226+
linker = linkers.AppleDynamicLinker(
227+
compiler, for_machine, comp_class.LINKER_PREFIX, override,
228+
system=system, version=v
229+
)
226230
# detect linker on MacOS - must be after other platforms because the
227231
# "(use -v to see invocation)" will match clang on other platforms,
228232
# but the rest of the checks will fail and call __failed_to_detect_linker.
@@ -241,7 +245,10 @@ def guess_nix_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty
241245
break
242246
else:
243247
__failed_to_detect_linker(compiler, check_args, o, e)
244-
linker = linkers.AppleDynamicLinker(compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v)
248+
linker = linkers.AppleDynamicLinker(
249+
compiler, for_machine, comp_class.LINKER_PREFIX, override,
250+
system=system, version=v
251+
)
245252
else:
246253
__failed_to_detect_linker(compiler, check_args, o, e)
247254
return linker

mesonbuild/linkers/linkers.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,11 @@ def _apply_prefix(self, arg: T.Union[str, T.List[str]]) -> T.List[str]:
141141

142142
def __init__(self, exelist: T.List[str],
143143
for_machine: mesonlib.MachineChoice, prefix_arg: T.Union[str, T.List[str]],
144-
always_args: T.List[str], *, version: str = 'unknown version'):
144+
always_args: T.List[str], *, system: str = 'unknown system',
145+
version: str = 'unknown version'):
145146
self.exelist = exelist
146147
self.for_machine = for_machine
148+
self.system = system
147149
self.version = version
148150
self.prefix_arg = prefix_arg
149151
self.always_args = always_args

0 commit comments

Comments
 (0)