From a223b20bb60c7c643d3d4e9581101e5f54522c57 Mon Sep 17 00:00:00 2001 From: Jon Turney Date: Sat, 5 Jan 2019 15:18:17 +0000 Subject: [PATCH] Fix linking when cross-compiling and a windows resource is first object It appears that LIB/LINK default to the host architecture if they can't guess it from the first object. With the MSVC toolchain, resource files are (usually) compiled to an arch-neutral .res format. Always explicitly provide a '/MACHINE:' argument to avoid it guessing incorrectly when cross-compiling. --- mesonbuild/compilers/c.py | 9 ++++++++- mesonbuild/environment.py | 2 +- mesonbuild/linkers.py | 9 +++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index 46f41819d..a1694d190 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -1302,6 +1302,13 @@ class VisualStudioCCompiler(CCompiler): self.base_options = ['b_pch', 'b_ndebug', 'b_vscrt'] # FIXME add lto, pgo and the like self.target = target self.is_64 = ('x64' in target) or ('x86_64' in target) + # do some canonicalization of target machine + if 'x86_64' in target: + self.machine = 'x64' + elif '86' in target: + self.machine = 'x86' + else: + self.machine = target # Override CCompiler.get_always_args def get_always_args(self): @@ -1378,7 +1385,7 @@ class VisualStudioCCompiler(CCompiler): return ['/nologo'] def get_linker_output_args(self, outputname): - return ['/OUT:' + outputname] + return ['/MACHINE:' + self.machine, '/OUT:' + outputname] def get_linker_search_args(self, dirname): return ['/LIBPATH:' + dirname] diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index 71f75f906..f0fa1daf5 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -1050,7 +1050,7 @@ class Environment: popen_exceptions[' '.join(linker + [arg])] = e continue if '/OUT:' in out.upper() or '/OUT:' in err.upper(): - return VisualStudioLinker(linker) + return VisualStudioLinker(linker, getattr(compiler, 'machine', None)) if p.returncode == 0 and ('armar' in linker or 'armar.exe' in linker): return ArmarLinker(linker) if 'DMD32 D Compiler' in out or 'DMD64 D Compiler' in out: diff --git a/mesonbuild/linkers.py b/mesonbuild/linkers.py index 543251462..c6302bfc4 100644 --- a/mesonbuild/linkers.py +++ b/mesonbuild/linkers.py @@ -26,8 +26,9 @@ class StaticLinker: class VisualStudioLinker(StaticLinker): always_args = ['/NOLOGO'] - def __init__(self, exelist): + def __init__(self, exelist, machine): self.exelist = exelist + self.machine = machine def get_exelist(self): return self.exelist[:] @@ -39,7 +40,11 @@ class VisualStudioLinker(StaticLinker): return [] def get_output_args(self, target): - return ['/OUT:' + target] + args = [] + if self.machine: + args += ['/MACHINE:' + self.machine] + args += ['/OUT:' + target] + return args def get_coverage_link_args(self): return []