[io-layer] Correctly detect a PE32+ assembly as managed when starting process
commitdca5ff953f24cf6d88f5977f5c45032938d5cb32
authorAlexander Köplinger <alex.koeplinger@outlook.com>
Mon, 10 Oct 2016 11:28:43 +0000 (10 13:28 +0200)
committerAlexander Köplinger <alex.koeplinger@outlook.com>
Tue, 11 Oct 2016 15:28:37 +0000 (11 17:28 +0200)
tree73a9b765f56d1622967e0a802ce5661c62472f61
parent8594aa3456cebb8a33ff27a4c756d694e555b975
[io-layer] Correctly detect a PE32+ assembly as managed when starting process

We weren't checking whether a PE file is in PE32 or PE32+ format,
causing us to use the PE32 offsets on the newer format as well.

This means that using Process.Start() on a managed assembly didn't
always work when a PE32+ file was in play. Such a file is created
when targeting x64 e.g. via the -platform:x64 csc.exe/mcs option.

The reason why we probably didn't notice until now is that in an
assembly produced by mcs there happens to be some data at the PE32
CLR header offset even in a PE32+ file, causing the check to "work".

This doesn't apply to csc.exe/roslyn though and so we couldn't
execute those assemblies via Process.Start() even though they're
perfectly managed. Since the .NET Core project.json toolchain
produces x64-targeted assemblies by default more people ran into
the issue trying to run those on Mono: https://github.com/cake-build/cake/issues/1247

Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=44937

PE/COFF spec at https://msdn.microsoft.com/en-us/library/windows/desktop/ms680547(v=vs.85).aspx

(cherry picked from commit 68bcbb4b77477133a1715a63ee1faaa85b600779)
mono/io-layer/processes.c