Skip to content

Commit

Permalink
Fix linking when cross-compiling and a windows resource is first object
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jon-turney committed Jan 5, 2019
1 parent 818c161 commit a223b20
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
9 changes: 8 additions & 1 deletion mesonbuild/compilers/c.py
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,13 @@ def __init__(self, exelist, version, is_cross, exe_wrap, target):
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):
Expand Down Expand Up @@ -1378,7 +1385,7 @@ def get_linker_always_args(self):
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]
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ def detect_static_linker(self, compiler):
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:
Expand Down
9 changes: 7 additions & 2 deletions mesonbuild/linkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ def can_linker_accept_rsp(self):
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[:]
Expand All @@ -39,7 +40,11 @@ def get_buildtype_linker_args(self, buildtype):
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 []
Expand Down

0 comments on commit a223b20

Please sign in to comment.