Bug 52443 - Cannot codesign binaries created with mkbundle on Mono 4.8.0 (483) on OSX
Summary: Cannot codesign binaries created with mkbundle on Mono 4.8.0 (483) on OSX
Alias: None
Product: Tools
Classification: Mono
Component: mkbundle ()
Version: 4.8.0 (C9)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2017-02-10 13:11 UTC by Robin G
Modified: 2017-09-04 21:33 UTC (History)
4 users (show)

Is this bug a regression?: Yes
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 52443 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Robin G 2017-02-10 13:11:50 UTC
On 4.6.2 and previous versions it was possible to use the OSX codesign tool to sign binaries created with mkbundle. In 4.8.0 (RC Refresh build codesign fails to process these binaries.

To repro:

If you do not already have a code signing certificate, create a test signing certificate as described here : https://developer.apple.com/library/content/documentation/Security/Conceptual/CodeSigningGuide/Procedures/Procedures.html

$ mono --version
Mono JIT compiler version 4.8.0 (mono-4.8.0-branch/ba7f169 Fri Feb  3 13:34:24 EST 2017)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           normal
	SIGSEGV:       altstack
	Notification:  kqueue
	Architecture:  x86
	Disabled:      none
	Misc:          softdebug 
	LLVM:          yes(3.6.0svn-mono-master/8b1520c)
	GC:            sgen

# Any .NET executable will do to demonstrated this problem
$ cp /Library/Frameworks/Mono.framework/Versions/4.8.0/lib/mono/4.5/cert-sync.exe .

# --cross default used as a workaround to error message about one of the i18n assemblies not being found
$ mkbundle --static --cross default cert-sync.exe
Using runtime: /Library/Frameworks/Mono.framework/Versions/4.8.0/bin/mono
     Assembly: /Users/robin/tmp/cert-sync.exe
     Assembly: /Library/Frameworks/Mono.framework/Versions/4.8.0/lib/mono/4.5/I18N.West.dll
     Assembly: /Library/Frameworks/Mono.framework/Versions/4.8.0/lib/mono/4.5/I18N.dll
Generated a.out

$ ls -l
total 10224
-rwxr-xr-x  1 robin  staff  5210252 10 Feb 12:01 a.out
-rwxr-xr-x  1 robin  staff    16896 10 Feb 12:01 cert-sync.exe

# use the name of your signing cert
$ codesign -s '<signingcert>' --force -v   a.out
a.out: main executable failed strict validation

# --no-strict still fails but gives a more informative error message
$ codesign -s '<signingcert>' --force -v --no-strict  a.out
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate: the __LINKEDIT segment does not cover the end of the file (can't be processed) in: /Users/robin/tmp/a.out
a.out: the codesign_allocate helper tool cannot be found or used

[Note - the --static option to mkbundle seems to have no effect in this version of mono - the binary produced is the same size with or without that option - will raise a separate bug]

There is some discussion online of similar issues caused by appending data to the executable binary, for example with pyInstaller - https://github.com/pyinstaller/pyinstaller/wiki/Recipe-OSX-Code-Signing and Qt - https://bugreports.qt.io/browse/QTIFW-153
Comment 1 Robin G 2017-02-13 09:33:40 UTC

The failure to sign looks to be a result of using the '--cross default' workaround to avoid the problem with 'ERROR: Couldn't load one or more of the i18n assemblies.' 

The use of '--cross default' appears to be a bad idea for working around this issue which is actually caused by the main mono SDK path not being added to the link_paths list in mkbundle by default. 

It looks like this can be added manually using -L or using the --sdk or --runtime options, but if none of those options are set then the link_paths list only contains '.' and bundling fails. 

So I think that the underlying issue is that there is no default sdk path selection in mkbundle in 4.8.0. If that is by design then the error message printed should be clear that the user must use --sdk or --runtime or -L to set the SDK path.

There may also be a real issue with the inability to sign when using --cross default, but there seems to be an acceptable workaround for this of not using --cross default
Comment 2 Robin G 2017-02-13 11:40:57 UTC

mkbundle with the --sdk option (and --static) creates a binary that cannot be signed (just like --cross default)

mkbundle with the -L option (and --static) creates a binary that can be signed.
Comment 3 Rodrigo Kumpera 2017-02-13 21:21:31 UTC
Hi Miguel,

This looks related to your changes to mkbundle.