Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mono mkbundle output executable throws: “Error mapping file: No error” #8225

Closed
dns opened this issue Apr 13, 2018 · 14 comments

Comments

@dns
Copy link

@dns dns commented Apr 13, 2018

I wrote simple "hello world" console program in C#, and build it using VS2013 (I also try to build it using mono "csc" but the error is same).

> mkbundle --sdk "C:\Program Files\Mono" --deps -o test.exe ConsoleApplication2.exe
Using runtime: C:\Program Files\Mono\bin\mono
     Assembly: D:\SANDBOX\Silverlight\ConsoleApplication2\ConsoleApplication2\bin\Release\ConsoleApplication2.exe
       Config: D:\SANDBOX\Silverlight\ConsoleApplication2\ConsoleApplication2\bin\Release\ConsoleApplication2.exe.config
     Assembly: C:\Program Files\Mono\lib\mono\4.5\mscorlib.dll
     Assembly: C:\Program Files\Mono\lib\mono\4.5\I18N.West.dll
     Assembly: C:\Program Files\Mono\lib\mono\4.5\I18N.dll
Generated test.exe

The new "test.exe" need mono-2.0-sgen.dll, so I copy it to "C:\Program Files\Mono\bin" and then run test.exe, but the new executable throw a error message to stdout:

> test.exe
Error mapping file: No error

Version Used:

  • Mono 5.12.0.226.x64
  • Win10 (64-bit).
@marek-safar

This comment has been minimized.

Copy link
Member

@marek-safar marek-safar commented Apr 13, 2018

@lateralusX does this look familiar?

@lateralusX

This comment has been minimized.

Copy link
Member

@lateralusX lateralusX commented May 25, 2018

Nothing that I have seen before. This mkbundle execution use the --sdk feature that packages bundles differently into the final binary not using the installed C toolchain. Instead it appends bundles directly to a copy of the mono binary (that in this case is not a static linked version, but depending on mono-2.0-sgen.dll). The error seems to occurs when the runtime tries to load (memory mapping the bundles) the bundles. If this is still an issue I could add it to my list and see if I could repro the problem.

@jaykrell

This comment has been minimized.

Copy link
Collaborator

@jaykrell jaykrell commented May 25, 2018

Get us the .exe to debug?

@jaykrell

This comment has been minimized.

Copy link
Collaborator

@jaykrell jaykrell commented May 25, 2018

Or run it along with sysinternals sysmon or such, watch the file opens for errors, near the end. Is something like what I'd do.

jaykrell added a commit to jaykrell/mono that referenced this issue May 25, 2018
jaykrell added a commit to jaykrell/mono that referenced this issue May 25, 2018
jaykrell added a commit to jaykrell/mono that referenced this issue May 25, 2018
@dns

This comment has been minimized.

Copy link
Author

@dns dns commented May 25, 2018

@jaykrell

This comment has been minimized.

Copy link
Collaborator

@jaykrell jaykrell commented May 25, 2018

Thank you for the repro.
I can't repro rebuilding it, but your build has the problem I saw from code inspection.
mkbundle aligns things to 4k but 64k alignment is needed, per MapViewOfFile documentation.

KERNEL32!MapViewOfFileStub:
00007ffcb3d1a930 48ff2501d80500 jmp qword ptr [KERNEL32!_imp_MapViewOfFile (00007ffcb3d78138)] ds:00007ffcb3d78138={KERNELBASE!MapViewOfFile (00007ffcb25c4a40)}
0:000> r r9
r9=0000000000027000
0:000> gu
Breakpoint 12 hit
KERNELBASE!MapViewOfFile:
00007ffcb25c4a40 4c8bdc mov r11,rsp 0:000> gu mono_2_0_sgen!mono_counters_sample+0x248c24: 00007ffc863df0c0 488bc8 mov rcx,rax
0:000> r rax
rax=0000000000000000
0:000> !gle
LastErrorValue: (Win32) 0x46c (1132) - The base address or the file offset specified does not have the proper alignment.
LastStatusValue: (NTSTATUS) 0xc0000220 - {Mapped View Alignment Incorrect} An attempt was made to map a view of a file, but either the specified base address or the offset into the file were not aligned on the proper allocation granularity.

@migueldeicaza you want to align all platforms on 64k or just Windows?

jaykrell added a commit to jaykrell/mono that referenced this issue May 25, 2018
jaykrell added a commit to jaykrell/mono that referenced this issue May 25, 2018
Consider doing this only for Windows.
@jaykrell

This comment has been minimized.

Copy link
Collaborator

@jaykrell jaykrell commented May 25, 2018

Here is how you debug this btw:
xcopy debuggers to bin (or elsewhere)

\bin\amd64\cdb foo.exe
!dlls
see .exe entry point
bp on that
g
bm kern*!*mapviewoffile*   (bm is break on match and accepts wildcards; ! 
  separate module from function)
g
look at parameters: first four are rcx rdx r8 r9 and r9 is what you want
gu  (go up i.e. go till return)
r rax to see return value
!gle for getlasterror
jaykrell added a commit to jaykrell/mono that referenced this issue Jun 4, 2018
jaykrell added a commit to jaykrell/mono that referenced this issue Jun 8, 2018
Consider doing this only for Windows.
jaykrell added a commit that referenced this issue Jul 10, 2018
* Better error reporting in mkbundle, i.e. #8225

* Combine desktop and UWP mmap implementation.
@elitest

This comment has been minimized.

Copy link

@elitest elitest commented Aug 2, 2018

@jaykrell Is this fix available in the nightlies? Or is the only way to get this is to build from master. Seems still present in nightlies, but those might be built from the release branch. Is it possible to download an artifact from a recent jenkins build?

@jaykrell

This comment has been minimized.

Copy link
Collaborator

@jaykrell jaykrell commented Aug 2, 2018

The fix was never approved.

@jaykrell

This comment has been minimized.

Copy link
Collaborator

@jaykrell jaykrell commented Aug 2, 2018

@elitest

This comment has been minimized.

Copy link

@elitest elitest commented Aug 2, 2018

Thanks. That is unfortunate. I will keep an eye on it, it the mean time I'll try my hand at compiling your branch. I haven't had luck with compiling so far.

@jaykrell

This comment has been minimized.

Copy link
Collaborator

@jaykrell jaykrell commented Aug 2, 2018

Can you try nightlies though, and check for a better error message?

@elitest

This comment has been minimized.

Copy link

@elitest elitest commented Aug 3, 2018

I'm AFK for a week. Next time I have a windows computer accessible I'll give it a shot.

migueldeicaza added a commit that referenced this issue Sep 3, 2018
* Fix mkbundle alignment to work with Windows. See #8225.
Consider doing this only for Windows.

* Align only first file at 64K, the rest the previous 4K.

* Ensure strings are nul terminated, if alignment doesn't handle it.
StringPairs already are.

* Save 30K on average on Unix, for an entire bundle (not per file within, but the entire bundle).

* Probe runtime for for MZ signature to determine if target
is Windows. "Style" is about host.
EgorBo added a commit to EgorBo/mono that referenced this issue Sep 10, 2018
* Fix mkbundle alignment to work with Windows. See mono#8225.
Consider doing this only for Windows.

* Align only first file at 64K, the rest the previous 4K.

* Ensure strings are nul terminated, if alignment doesn't handle it.
StringPairs already are.

* Save 30K on average on Unix, for an entire bundle (not per file within, but the entire bundle).

* Probe runtime for for MZ signature to determine if target
is Windows. "Style" is about host.
@lateralusX

This comment has been minimized.

Copy link
Member

@lateralusX lateralusX commented Feb 6, 2019

Looks like the PR fixing this issue was merged in September #8884, closing this issue.

@lateralusX lateralusX closed this Feb 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.