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

"framework native references" not compiling #5183

Closed
softlion opened this issue Nov 27, 2018 · 11 comments
Closed

"framework native references" not compiling #5183

softlion opened this issue Nov 27, 2018 · 11 comments
Assignees
Labels
Milestone

Comments

@softlion
Copy link

@softlion softlion commented Nov 27, 2018

When adding a "framework native references" in VS2017 and building with a mac, the intermediate xcode build fails with: .../mtouch-cache/pinvokes.m:180:69: error: 'objc_msgSend_stret' is unavailable: not available in arm64

Steps to Reproduce

  1. Create an iOS project
  2. Add a "framework native references", which is a folder containing C/C++ headers and a kind of binary file without extension
  3. Set its properties: IsC++: true, SmartLink: true
  4. Build the project from VS2017 with a mac connected

Expected Behavior

Builds fine

Actual Behavior

Fails to build

Environment

Xamarin iOS SDK 12.2.1.10
VS2017 15.9.2

Build Logs

3>  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang  -framework Foundation -weak_framework CFNetwork -Xlinker -rpath -Xlinker @executable_path /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.10/SDKs/MonoTouch.iphoneos.sdk/usr/lib/libxamarin-debug.dylib /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.10/SDKs/MonoTouch.iphoneos.sdk/usr/lib/libmonosgen-2.0.dylib -stdlib=libc++ -lz -gdwarf-2 -I/Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.10/SDKs/MonoTouch.iphoneos.sdk/usr/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk -Qunused-arguments -miphoneos-version-min=12.0 -arch arm64 -shared -liconv -install_name @rpath/libpinvokes.dylib -fapplication-extension -o /Volumes/Ursa/Users/minimac2/Library/Caches/Xamarin/mtbs/builds/Air.iOS/e664f4b58bd933733e069046d1c84d07/obj/iPhone/Debug/mtouch-cache/arm64/libpinvokes.dylib -x objective-c++ -DDEBUG /Volumes/Ursa/Users/minimac2/Library/Caches/Xamarin/mtbs/builds/Air.iOS/e664f4b58bd933733e069046d1c84d07/obj/iPhone/Debug/mtouch-cache/pinvokes.m (TaskId:243)
3>  /Volumes/Ursa/Users/minimac2/Library/Caches/Xamarin/mtbs/builds/Air.iOS/e664f4b58bd933733e069046d1c84d07/obj/iPhone/Debug/mtouch-cache/pinvokes.m:180:69: error: 'objc_msgSend_stret' is unavailable: not available in arm64 (TaskId:243)
3>                          return ((func_xamarin_pinvoke_wrapper_CGSize_objc_msgSend_stret) objc_msgSend_stret) (receiver, selector); (TaskId:243)
3>                                                                                           ^  (TaskId:243)
3>  /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk/usr/include/objc/message.h:133:1: note: 'objc_msgSend_stret' has been explicitly marked unavailable here (TaskId:243)
3>  objc_msgSend_stret(id _Nullable self, SEL _Nonnull op, ...) (TaskId:243)
3>  ^  (TaskId:243)
3>  /Volumes/Ursa/Users/minimac2/Library/Caches/Xamarin/mtbs/builds/Air.iOS/e664f4b58bd933733e069046d1c84d07/obj/iPhone/Debug/mtouch-cache/pinvokes.m:194:74: error: 'objc_msgSendSuper_stret' is unavailable: not available in arm64 (TaskId:243)
3>                          return ((func_xamarin_pinvoke_wrapper_CGSize_objc_msgSendSuper_stret) objc_msgSendSuper_stret) (receiver, selector); (TaskId:243)
3>                                                                                                ^  (TaskId:243)
3>  /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk/usr/include/objc/message.h:143:1: note: 'objc_msgSendSuper_stret' has been explicitly marked unavailable here (TaskId:243)
3>  objc_msgSendSuper_stret(struct objc_super * _Nonnull super, (TaskId:243)
3>  ^  (TaskId:243)

...

error MT4002: Failed to compile the generated code for P/Invoke methods. Please file a bug report at http://bugzilla.xamarin.com

The pinvokes.m file contains offending code like this:

	// EntryPoint: objc_msgSend_stret
	// Managed method: ObjCRuntime.Messaging.CGSize_objc_msgSend_stret
	// Signature: CGSize objc_msgSend_stret (CGSize*, void *, void *)
	typedef CGSize(*func_xamarin_pinvoke_wrapper_CGSize_objc_msgSend_stret) (void * receiver, void * selector);
	CGSize
	xamarin_pinvoke_wrapper_CGSize_objc_msgSend_stret (void * receiver, void * selector)
	{
		@try {
			return ((func_xamarin_pinvoke_wrapper_CGSize_objc_msgSend_stret) objc_msgSend_stret) (receiver, selector);
		} @catch (NSException *exc) {
			xamarin_process_nsexception (exc);
		}
	}

Have i done something wrong or is it a bug ?
I've checked doc for objc_msgSend_stret and it does not seem to be obsolete.

@VincentDondain

This comment has been minimized.

Copy link
Contributor

@VincentDondain VincentDondain commented Nov 27, 2018

Thank you for your feedback!

For us to investigate this further, could you please provide your full build logs, crash reports (if any), test case (very important to reproduce) and all your version information.

To get full build logs just set the log verbosity to diagnostic at the following locations:

  • On Visual Studio for Mac: Preferences > Projects > Build
  • On Visual Studio for Windows: Tools > Options > Projects and Solutions > Build and Run

On Visual Studio for Windows you also want to add -v -v -v -v to the mtouch additional arguments by right-clicking the project in the solution explorer and selecting Properties.

Note: this is done automatically on Visual Studio for Mac when the log verbosity is set to diagnostic.

The easiest way to get exact version information:

  • On Visual Studio for Mac: "Visual Studio" menu, "About Visual Studio" item, "Show Details" button.
  • On Visual Studio for Windows: "Help menu", "About Microsoft Visual Studio" item.

Then copy/paste the version information (you can use the "Copy Information" button).

We look forward to hearing from you!

@VincentDondain VincentDondain added this to the Future milestone Nov 27, 2018
@softlion

This comment has been minimized.

Copy link
Author

@softlion softlion commented Nov 28, 2018

Hi Vincent, i've added the informations that are necessary. The installed version of Visual Basic is not what's important here. Nor the other build logs, as they are standard build logs. If you know the build steps of your product, you should recognize at which step it generates the pinvokes.m file.

Btw version and build log here

The test case is in the "steps to reproduce" section. Or i misunderstand what a test case is.

What's important is the messages in the log extract:
'objc_msgSend_stret' is unavailable: not available in arm64

This means this objectivec method is not available in arm64. It is used in the xamarin generated file "pinvokes.m".
The question is, why is xamarin generating 32bits arm code instead of 64bits arm64 code.

My VS settings for this project are "ios 12+" / device specific builds enabled / supported architecture arm64 only / don't link / sdk default (xcode 10.1) / deploy to simulator

Note that there is an old bug in Xamarin, in the ResolveNativeReference task, where it is unable to find its own folder (Could not resolve reference). Extract from logs:

3>Using "ResolveNativeReference" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
3>Task "ResolveNativeReference" (TaskId:169)
3>  Task Parameter:
3>      NativeReferences=
3>          Native References/CompanySPx.framework
3>                  ForceLoad=False
3>                  IsCxx=True
3>                  Kind=Framework
3>                  NeedsGccExceptionHandling=True
3>                  SmartLink=True (TaskId:169)
3>  Task Parameter:AdditionalSearchPaths=bin\iPhone\Debug\ (TaskId:169)
3>  Attempting to resolve reference "Native References/CompanySPx.framework" on path(s): (TaskId:169)
3>      bin\iPhone\Debug\ (TaskId:169)
3>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2006,5): warning MSB3341: Could not resolve reference "Native References/CompanySPx.framework". If this reference is required by your code, you may get compilation errors.
3>Done executing task "ResolveNativeReference". (TaskId:169)
3>Done building target "ResolveNativeReferences" in project "AirApp.iOS.csproj".: (TargetId:260)
@mandel-macaque

This comment has been minimized.

Copy link
Contributor

@mandel-macaque mandel-macaque commented Nov 29, 2018

@softlion I was taking a look at this issue and I noticed that there was a small issue with the link to the gist, I suppose you mean that the version info is THIS gist. Am I correct?

The logs from the mac in that gist do look a little funny. Is gist doing weird things?

I am going to try and reproduce and look closer into the issue. Are you using a specific c++ lib that is publicly accessible that I could use?

@softlion

This comment has been minimized.

Copy link
Author

@softlion softlion commented Dec 1, 2018

@mandel-macaque yes its this gist. I did not put the log from the mac. Do you need them ?

I am going to try and reproduce and look closer into the issue. Are you using a specific c++ lib that is publicly accessible that I could use?

Well no, its not public. Btw i could send the whole project to you in private. Could the problem be linked to the ResolveNativeReference warning that i reported above ?

I will try using VS Mac instead of VS Windows.

@rolfbjarne

This comment has been minimized.

Copy link
Member

@rolfbjarne rolfbjarne commented Dec 5, 2018

I ran into this myself, so I can repro:

  • Open tests/tests.sln
  • Select the monotouch-test project, and the Debug64 device configuration.
  • Add --marshal-objectivec-exceptions=throwmanaged to the additional mtouch arguments.
  • Build

I'll have a look at this.

@rolfbjarne rolfbjarne added bug macOS iOS and removed need-info labels Dec 5, 2018
@rolfbjarne rolfbjarne self-assigned this Dec 5, 2018
@softlion

This comment has been minimized.

Copy link
Author

@softlion softlion commented Dec 6, 2018

You are right, i used "--marshal-managed-exceptions=throwobjectivecexception --marshal-objectivec-exceptions=throwmanagedexception"

Any news ?

@rolfbjarne

This comment has been minimized.

Copy link
Member

@rolfbjarne rolfbjarne commented Dec 7, 2018

You are right, i used "--marshal-managed-exceptions=throwobjectivecexception --marshal-objectivec-exceptions=throwmanagedexception"

Don't use --marshal-objectivec-exceptions for now.

Any news ?

Not yet.

@softlion

This comment has been minimized.

Copy link
Author

@softlion softlion commented Dec 7, 2018

It compiles fine now. if i use ForceLoad=true, GCC false,, C++ true, smart link true, and not other flags (i removed -- flags). But maybe it's linked away because of smart link.

@softlion

This comment has been minimized.

Copy link
Author

@softlion softlion commented Dec 7, 2018

Btw do you know how to reference a C++ ios project in VS ? It seems not supported (error:

---------------------------
Microsoft Visual Studio
---------------------------
A reference to 'App.AppLib.Native.iOS' could not be added. An assembly must have a 'dll' or 'exe' extension in order to be referenced.
---------------------------
OK   
---------------------------

@VincentDondain

This comment has been minimized.

Copy link
Contributor

@VincentDondain VincentDondain commented Dec 7, 2018

@softlion for that last question see my answer here: #5216 (comment). If @rolfbjarne has anything else to add to it let's discuss in the other issue (:

@softlion

This comment has been minimized.

Copy link
Author

@softlion softlion commented Dec 20, 2018

Ok so, it works fine with the above options. And it's not possible to reference an iOS C project from a xamarin ios project. For Android, you can, and it is working fine. Except you can not generate all ABI targets in the same build config.

rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Dec 20, 2018
…e wrappers for objc_msgSend*_stret on arm64. Fixes xamarin#5183.

objc_msgSend*_stret doesn't exist on arm64, so trying to call these functions
in our generated P/Invoke wrappers will result in a clang error:

    [...]/pinvokes.m:180:69: error: 'objc_msgSend_stret' is unavailable: not available in arm64 (TaskId:243)

So instead generate a call to throw an EntryPointNotFoundException (which is
exactly what would happen if we didn't generate the P/Invoke wrapper).

Fixes xamarin#5183.
rolfbjarne added a commit that referenced this issue Dec 20, 2018
…e wrappers for objc_msgSend*_stret on arm64. Fixes #5183. (#5312)

objc_msgSend*_stret doesn't exist on arm64, so trying to call these functions
in our generated P/Invoke wrappers will result in a clang error:

    [...]/pinvokes.m:180:69: error: 'objc_msgSend_stret' is unavailable: not available in arm64 (TaskId:243)

So instead generate a call to throw an EntryPointNotFoundException (which is
exactly what would happen if we didn't generate the P/Invoke wrapper).

Fixes #5183.
monojenkins added a commit to monojenkins/xamarin-macios that referenced this issue Dec 20, 2018
…e wrappers for objc_msgSend*_stret on arm64. Fixes xamarin#5183.

objc_msgSend*_stret doesn't exist on arm64, so trying to call these functions
in our generated P/Invoke wrappers will result in a clang error:

    [...]/pinvokes.m:180:69: error: 'objc_msgSend_stret' is unavailable: not available in arm64 (TaskId:243)

So instead generate a call to throw an EntryPointNotFoundException (which is
exactly what would happen if we didn't generate the P/Invoke wrapper).

Fixes xamarin#5183.
rolfbjarne added a commit that referenced this issue Dec 21, 2018
…e wrappers for objc_msgSend*_stret on arm64. Fixes #5183. (#5315)

objc_msgSend*_stret doesn't exist on arm64, so trying to call these functions
in our generated P/Invoke wrappers will result in a clang error:

    [...]/pinvokes.m:180:69: error: 'objc_msgSend_stret' is unavailable: not available in arm64 (TaskId:243)

So instead generate a call to throw an EntryPointNotFoundException (which is
exactly what would happen if we didn't generate the P/Invoke wrapper).

Fixes #5183.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.